UNPKG

@tanstack/db

Version:

A reactive client store for building super fast apps on sync

519 lines (518 loc) 18 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); class TanStackDBError extends Error { constructor(message) { super(message); this.name = `TanStackDBError`; } } class NonRetriableError extends TanStackDBError { constructor(message) { super(message); this.name = `NonRetriableError`; } } class SchemaValidationError extends TanStackDBError { constructor(type, issues, message) { const defaultMessage = `${type === `insert` ? `Insert` : `Update`} validation failed: ${issues.map((issue) => ` - ${issue.message} - path: ${issue.path}`).join(``)}`; super(message || defaultMessage); this.name = `SchemaValidationError`; this.type = type; this.issues = issues; } } class CollectionConfigurationError extends TanStackDBError { constructor(message) { super(message); this.name = `CollectionConfigurationError`; } } class CollectionRequiresConfigError extends CollectionConfigurationError { constructor() { super(`Collection requires a config`); } } class CollectionRequiresSyncConfigError extends CollectionConfigurationError { constructor() { super(`Collection requires a sync config`); } } class InvalidSchemaError extends CollectionConfigurationError { constructor() { super(`Schema must implement the standard-schema interface`); } } class SchemaMustBeSynchronousError extends CollectionConfigurationError { constructor() { super(`Schema validation must be synchronous`); } } class CollectionStateError extends TanStackDBError { constructor(message) { super(message); this.name = `CollectionStateError`; } } class CollectionInErrorStateError extends CollectionStateError { constructor(operation, collectionId) { super( `Cannot perform ${operation} on collection "${collectionId}" - collection is in error state. Try calling cleanup() and restarting the collection.` ); } } class InvalidCollectionStatusTransitionError extends CollectionStateError { constructor(from, to, collectionId) { super( `Invalid collection status transition from "${from}" to "${to}" for collection "${collectionId}"` ); } } class CollectionIsInErrorStateError extends CollectionStateError { constructor() { super(`Collection is in error state`); } } class NegativeActiveSubscribersError extends CollectionStateError { constructor() { super(`Active subscribers count is negative - this should never happen`); } } class CollectionOperationError extends TanStackDBError { constructor(message) { super(message); this.name = `CollectionOperationError`; } } class UndefinedKeyError extends CollectionOperationError { constructor(item) { super( `An object was created without a defined key: ${JSON.stringify(item)}` ); } } class DuplicateKeyError extends CollectionOperationError { constructor(key) { super( `Cannot insert document with ID "${key}" because it already exists in the collection` ); } } class DuplicateKeySyncError extends CollectionOperationError { constructor(key, collectionId) { super( `Cannot insert document with key "${key}" from sync because it already exists in the collection "${collectionId}"` ); } } class MissingUpdateArgumentError extends CollectionOperationError { constructor() { super(`The first argument to update is missing`); } } class NoKeysPassedToUpdateError extends CollectionOperationError { constructor() { super(`No keys were passed to update`); } } class UpdateKeyNotFoundError extends CollectionOperationError { constructor(key) { super( `The key "${key}" was passed to update but an object for this key was not found in the collection` ); } } class KeyUpdateNotAllowedError extends CollectionOperationError { constructor(originalKey, newKey) { super( `Updating the key of an item is not allowed. Original key: "${originalKey}", Attempted new key: "${newKey}". Please delete the old item and create a new one if a key change is necessary.` ); } } class NoKeysPassedToDeleteError extends CollectionOperationError { constructor() { super(`No keys were passed to delete`); } } class DeleteKeyNotFoundError extends CollectionOperationError { constructor(key) { super( `Collection.delete was called with key '${key}' but there is no item in the collection with this key` ); } } class MissingHandlerError extends TanStackDBError { constructor(message) { super(message); this.name = `MissingHandlerError`; } } class MissingInsertHandlerError extends MissingHandlerError { constructor() { super( `Collection.insert called directly (not within an explicit transaction) but no 'onInsert' handler is configured.` ); } } class MissingUpdateHandlerError extends MissingHandlerError { constructor() { super( `Collection.update called directly (not within an explicit transaction) but no 'onUpdate' handler is configured.` ); } } class MissingDeleteHandlerError extends MissingHandlerError { constructor() { super( `Collection.delete called directly (not within an explicit transaction) but no 'onDelete' handler is configured.` ); } } class TransactionError extends TanStackDBError { constructor(message) { super(message); this.name = `TransactionError`; } } class MissingMutationFunctionError extends TransactionError { constructor() { super(`mutationFn is required when creating a transaction`); } } class TransactionNotPendingMutateError extends TransactionError { constructor() { super( `You can no longer call .mutate() as the transaction is no longer pending` ); } } class TransactionAlreadyCompletedRollbackError extends TransactionError { constructor() { super( `You can no longer call .rollback() as the transaction is already completed` ); } } class TransactionNotPendingCommitError extends TransactionError { constructor() { super( `You can no longer call .commit() as the transaction is no longer pending` ); } } class NoPendingSyncTransactionWriteError extends TransactionError { constructor() { super(`No pending sync transaction to write to`); } } class SyncTransactionAlreadyCommittedWriteError extends TransactionError { constructor() { super( `The pending sync transaction is already committed, you can't still write to it.` ); } } class NoPendingSyncTransactionCommitError extends TransactionError { constructor() { super(`No pending sync transaction to commit`); } } class SyncTransactionAlreadyCommittedError extends TransactionError { constructor() { super( `The pending sync transaction is already committed, you can't commit it again.` ); } } class QueryBuilderError extends TanStackDBError { constructor(message) { super(message); this.name = `QueryBuilderError`; } } class OnlyOneSourceAllowedError extends QueryBuilderError { constructor(context) { super(`Only one source is allowed in the ${context}`); } } class SubQueryMustHaveFromClauseError extends QueryBuilderError { constructor(context) { super(`A sub query passed to a ${context} must have a from clause itself`); } } class InvalidSourceError extends QueryBuilderError { constructor() { super(`Invalid source`); } } class JoinConditionMustBeEqualityError extends QueryBuilderError { constructor() { super(`Join condition must be an equality expression`); } } class QueryMustHaveFromClauseError extends QueryBuilderError { constructor() { super(`Query must have a from clause`); } } class QueryCompilationError extends TanStackDBError { constructor(message) { super(message); this.name = `QueryCompilationError`; } } class DistinctRequiresSelectError extends QueryCompilationError { constructor() { super(`DISTINCT requires a SELECT clause.`); } } class HavingRequiresGroupByError extends QueryCompilationError { constructor() { super(`HAVING clause requires GROUP BY clause`); } } class LimitOffsetRequireOrderByError extends QueryCompilationError { constructor() { super( `LIMIT and OFFSET require an ORDER BY clause to ensure deterministic results` ); } } class CollectionInputNotFoundError extends QueryCompilationError { constructor(collectionId) { super(`Input for collection "${collectionId}" not found in inputs map`); } } class UnsupportedFromTypeError extends QueryCompilationError { constructor(type) { super(`Unsupported FROM type: ${type}`); } } class UnknownExpressionTypeError extends QueryCompilationError { constructor(type) { super(`Unknown expression type: ${type}`); } } class EmptyReferencePathError extends QueryCompilationError { constructor() { super(`Reference path cannot be empty`); } } class UnknownFunctionError extends QueryCompilationError { constructor(functionName) { super(`Unknown function: ${functionName}`); } } class JoinError extends TanStackDBError { constructor(message) { super(message); this.name = `JoinError`; } } class UnsupportedJoinTypeError extends JoinError { constructor(joinType) { super(`Unsupported join type: ${joinType}`); } } class InvalidJoinConditionSameTableError extends JoinError { constructor(tableAlias) { super( `Invalid join condition: both expressions refer to the same table "${tableAlias}"` ); } } class InvalidJoinConditionTableMismatchError extends JoinError { constructor(mainTableAlias, joinedTableAlias) { super( `Invalid join condition: expressions must reference table aliases "${mainTableAlias}" and "${joinedTableAlias}"` ); } } class InvalidJoinConditionWrongTablesError extends JoinError { constructor(leftTableAlias, rightTableAlias, mainTableAlias, joinedTableAlias) { super( `Invalid join condition: expressions reference tables "${leftTableAlias}" and "${rightTableAlias}" but join is between "${mainTableAlias}" and "${joinedTableAlias}"` ); } } class UnsupportedJoinSourceTypeError extends JoinError { constructor(type) { super(`Unsupported join source type: ${type}`); } } class GroupByError extends TanStackDBError { constructor(message) { super(message); this.name = `GroupByError`; } } class NonAggregateExpressionNotInGroupByError extends GroupByError { constructor(alias) { super( `Non-aggregate expression '${alias}' in SELECT must also appear in GROUP BY clause` ); } } class UnsupportedAggregateFunctionError extends GroupByError { constructor(functionName) { super(`Unsupported aggregate function: ${functionName}`); } } class AggregateFunctionNotInSelectError extends GroupByError { constructor(functionName) { super( `Aggregate function in HAVING clause must also be in SELECT clause: ${functionName}` ); } } class UnknownHavingExpressionTypeError extends GroupByError { constructor(type) { super(`Unknown expression type in HAVING clause: ${type}`); } } class StorageError extends TanStackDBError { constructor(message) { super(message); this.name = `StorageError`; } } class SerializationError extends StorageError { constructor(operation, originalError) { super( `Cannot ${operation} item because it cannot be JSON serialized: ${originalError}` ); } } class LocalStorageCollectionError extends StorageError { constructor(message) { super(message); this.name = `LocalStorageCollectionError`; } } class StorageKeyRequiredError extends LocalStorageCollectionError { constructor() { super(`[LocalStorageCollection] storageKey must be provided.`); } } class NoStorageAvailableError extends LocalStorageCollectionError { constructor() { super( `[LocalStorageCollection] No storage available. Please provide a storage option or ensure window.localStorage is available.` ); } } class NoStorageEventApiError extends LocalStorageCollectionError { constructor() { super( `[LocalStorageCollection] No storage event API available. Please provide a storageEventApi option or ensure window is available.` ); } } class InvalidStorageDataFormatError extends LocalStorageCollectionError { constructor(storageKey, key) { super( `[LocalStorageCollection] Invalid data format in storage key "${storageKey}" for key "${key}".` ); } } class InvalidStorageObjectFormatError extends LocalStorageCollectionError { constructor(storageKey) { super( `[LocalStorageCollection] Invalid data format in storage key "${storageKey}". Expected object format.` ); } } class SyncCleanupError extends TanStackDBError { constructor(collectionId, error) { const message = error instanceof Error ? error.message : String(error); super( `Collection "${collectionId}" sync cleanup function threw an error: ${message}` ); this.name = `SyncCleanupError`; } } class QueryOptimizerError extends TanStackDBError { constructor(message) { super(message); this.name = `QueryOptimizerError`; } } class CannotCombineEmptyExpressionListError extends QueryOptimizerError { constructor() { super(`Cannot combine empty expression list`); } } exports.AggregateFunctionNotInSelectError = AggregateFunctionNotInSelectError; exports.CannotCombineEmptyExpressionListError = CannotCombineEmptyExpressionListError; exports.CollectionConfigurationError = CollectionConfigurationError; exports.CollectionInErrorStateError = CollectionInErrorStateError; exports.CollectionInputNotFoundError = CollectionInputNotFoundError; exports.CollectionIsInErrorStateError = CollectionIsInErrorStateError; exports.CollectionOperationError = CollectionOperationError; exports.CollectionRequiresConfigError = CollectionRequiresConfigError; exports.CollectionRequiresSyncConfigError = CollectionRequiresSyncConfigError; exports.CollectionStateError = CollectionStateError; exports.DeleteKeyNotFoundError = DeleteKeyNotFoundError; exports.DistinctRequiresSelectError = DistinctRequiresSelectError; exports.DuplicateKeyError = DuplicateKeyError; exports.DuplicateKeySyncError = DuplicateKeySyncError; exports.EmptyReferencePathError = EmptyReferencePathError; exports.GroupByError = GroupByError; exports.HavingRequiresGroupByError = HavingRequiresGroupByError; exports.InvalidCollectionStatusTransitionError = InvalidCollectionStatusTransitionError; exports.InvalidJoinConditionSameTableError = InvalidJoinConditionSameTableError; exports.InvalidJoinConditionTableMismatchError = InvalidJoinConditionTableMismatchError; exports.InvalidJoinConditionWrongTablesError = InvalidJoinConditionWrongTablesError; exports.InvalidSchemaError = InvalidSchemaError; exports.InvalidSourceError = InvalidSourceError; exports.InvalidStorageDataFormatError = InvalidStorageDataFormatError; exports.InvalidStorageObjectFormatError = InvalidStorageObjectFormatError; exports.JoinConditionMustBeEqualityError = JoinConditionMustBeEqualityError; exports.JoinError = JoinError; exports.KeyUpdateNotAllowedError = KeyUpdateNotAllowedError; exports.LimitOffsetRequireOrderByError = LimitOffsetRequireOrderByError; exports.LocalStorageCollectionError = LocalStorageCollectionError; exports.MissingDeleteHandlerError = MissingDeleteHandlerError; exports.MissingHandlerError = MissingHandlerError; exports.MissingInsertHandlerError = MissingInsertHandlerError; exports.MissingMutationFunctionError = MissingMutationFunctionError; exports.MissingUpdateArgumentError = MissingUpdateArgumentError; exports.MissingUpdateHandlerError = MissingUpdateHandlerError; exports.NegativeActiveSubscribersError = NegativeActiveSubscribersError; exports.NoKeysPassedToDeleteError = NoKeysPassedToDeleteError; exports.NoKeysPassedToUpdateError = NoKeysPassedToUpdateError; exports.NoPendingSyncTransactionCommitError = NoPendingSyncTransactionCommitError; exports.NoPendingSyncTransactionWriteError = NoPendingSyncTransactionWriteError; exports.NoStorageAvailableError = NoStorageAvailableError; exports.NoStorageEventApiError = NoStorageEventApiError; exports.NonAggregateExpressionNotInGroupByError = NonAggregateExpressionNotInGroupByError; exports.NonRetriableError = NonRetriableError; exports.OnlyOneSourceAllowedError = OnlyOneSourceAllowedError; exports.QueryBuilderError = QueryBuilderError; exports.QueryCompilationError = QueryCompilationError; exports.QueryMustHaveFromClauseError = QueryMustHaveFromClauseError; exports.QueryOptimizerError = QueryOptimizerError; exports.SchemaMustBeSynchronousError = SchemaMustBeSynchronousError; exports.SchemaValidationError = SchemaValidationError; exports.SerializationError = SerializationError; exports.StorageError = StorageError; exports.StorageKeyRequiredError = StorageKeyRequiredError; exports.SubQueryMustHaveFromClauseError = SubQueryMustHaveFromClauseError; exports.SyncCleanupError = SyncCleanupError; exports.SyncTransactionAlreadyCommittedError = SyncTransactionAlreadyCommittedError; exports.SyncTransactionAlreadyCommittedWriteError = SyncTransactionAlreadyCommittedWriteError; exports.TanStackDBError = TanStackDBError; exports.TransactionAlreadyCompletedRollbackError = TransactionAlreadyCompletedRollbackError; exports.TransactionError = TransactionError; exports.TransactionNotPendingCommitError = TransactionNotPendingCommitError; exports.TransactionNotPendingMutateError = TransactionNotPendingMutateError; exports.UndefinedKeyError = UndefinedKeyError; exports.UnknownExpressionTypeError = UnknownExpressionTypeError; exports.UnknownFunctionError = UnknownFunctionError; exports.UnknownHavingExpressionTypeError = UnknownHavingExpressionTypeError; exports.UnsupportedAggregateFunctionError = UnsupportedAggregateFunctionError; exports.UnsupportedFromTypeError = UnsupportedFromTypeError; exports.UnsupportedJoinSourceTypeError = UnsupportedJoinSourceTypeError; exports.UnsupportedJoinTypeError = UnsupportedJoinTypeError; exports.UpdateKeyNotFoundError = UpdateKeyNotFoundError; //# sourceMappingURL=errors.cjs.map