diff --git a/.changeset/all-meals-follow.md b/.changeset/all-meals-follow.md new file mode 100644 index 000000000..22237a818 --- /dev/null +++ b/.changeset/all-meals-follow.md @@ -0,0 +1,5 @@ +--- +"@tanstack/db": patch +--- + +Add optional compareOptions to collection configuration. diff --git a/docs/reference/classes/CollectionImpl.md b/docs/reference/classes/CollectionImpl.md index 216db731a..365ba0651 100644 --- a/docs/reference/classes/CollectionImpl.md +++ b/docs/reference/classes/CollectionImpl.md @@ -5,7 +5,7 @@ title: CollectionImpl # Class: CollectionImpl\ -Defined in: [packages/db/src/collection/index.ts:202](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L202) +Defined in: [packages/db/src/collection/index.ts:203](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L203) ## Extended by @@ -42,7 +42,7 @@ Defined in: [packages/db/src/collection/index.ts:202](https://github.com/TanStac new CollectionImpl(config): CollectionImpl; ``` -Defined in: [packages/db/src/collection/index.ts:239](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L239) +Defined in: [packages/db/src/collection/index.ts:242](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L242) Creates a new Collection instance @@ -70,7 +70,7 @@ Error if sync config is missing _lifecycle: CollectionLifecycleManager; ``` -Defined in: [packages/db/src/collection/index.ts:219](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L219) +Defined in: [packages/db/src/collection/index.ts:220](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L220) *** @@ -80,7 +80,7 @@ Defined in: [packages/db/src/collection/index.ts:219](https://github.com/TanStac _state: CollectionStateManager; ``` -Defined in: [packages/db/src/collection/index.ts:231](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L231) +Defined in: [packages/db/src/collection/index.ts:232](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L232) *** @@ -90,7 +90,7 @@ Defined in: [packages/db/src/collection/index.ts:231](https://github.com/TanStac _sync: CollectionSyncManager; ``` -Defined in: [packages/db/src/collection/index.ts:220](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L220) +Defined in: [packages/db/src/collection/index.ts:221](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L221) *** @@ -100,7 +100,7 @@ Defined in: [packages/db/src/collection/index.ts:220](https://github.com/TanStac config: CollectionConfig; ``` -Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L210) +Defined in: [packages/db/src/collection/index.ts:211](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L211) *** @@ -110,7 +110,7 @@ Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStac id: string; ``` -Defined in: [packages/db/src/collection/index.ts:209](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L209) +Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L210) *** @@ -120,10 +120,26 @@ Defined in: [packages/db/src/collection/index.ts:209](https://github.com/TanStac utils: Record = {}; ``` -Defined in: [packages/db/src/collection/index.ts:214](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L214) +Defined in: [packages/db/src/collection/index.ts:215](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L215) ## Accessors +### compareOptions + +#### Get Signature + +```ts +get compareOptions(): StringCollationConfig; +``` + +Defined in: [packages/db/src/collection/index.ts:516](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L516) + +##### Returns + +[`StringCollationConfig`](../../type-aliases/StringCollationConfig.md) + +*** + ### indexes #### Get Signature @@ -132,7 +148,7 @@ Defined in: [packages/db/src/collection/index.ts:214](https://github.com/TanStac get indexes(): Map>; ``` -Defined in: [packages/db/src/collection/index.ts:496](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L496) +Defined in: [packages/db/src/collection/index.ts:501](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L501) Get resolved indexes for query optimization @@ -150,7 +166,7 @@ Get resolved indexes for query optimization get isLoadingSubset(): boolean; ``` -Defined in: [packages/db/src/collection/index.ts:362](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L362) +Defined in: [packages/db/src/collection/index.ts:367](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L367) Check if the collection is currently loading more data @@ -170,7 +186,7 @@ true if the collection has pending load more operations, false otherwise get size(): number; ``` -Defined in: [packages/db/src/collection/index.ts:399](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L399) +Defined in: [packages/db/src/collection/index.ts:404](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L404) Get the current size of the collection (cached) @@ -188,7 +204,7 @@ Get the current size of the collection (cached) get state(): Map; ``` -Defined in: [packages/db/src/collection/index.ts:683](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L683) +Defined in: [packages/db/src/collection/index.ts:693](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L693) Gets the current state of the collection as a Map @@ -224,7 +240,7 @@ Map containing all items in the collection, with keys as identifiers get status(): CollectionStatus; ``` -Defined in: [packages/db/src/collection/index.ts:317](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L317) +Defined in: [packages/db/src/collection/index.ts:322](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L322) Gets the current status of the collection @@ -242,7 +258,7 @@ Gets the current status of the collection get subscriberCount(): number; ``` -Defined in: [packages/db/src/collection/index.ts:324](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L324) +Defined in: [packages/db/src/collection/index.ts:329](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L329) Get the number of subscribers to the collection @@ -260,7 +276,7 @@ Get the number of subscribers to the collection get toArray(): TOutput[]; ``` -Defined in: [packages/db/src/collection/index.ts:712](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L712) +Defined in: [packages/db/src/collection/index.ts:722](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L722) Gets the current state of the collection as an Array @@ -278,7 +294,7 @@ An Array containing all items in the collection iterator: IterableIterator<[TKey, TOutput]>; ``` -Defined in: [packages/db/src/collection/index.ts:427](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L427) +Defined in: [packages/db/src/collection/index.ts:432](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L432) Get all entries (virtual derived state) @@ -294,7 +310,7 @@ Get all entries (virtual derived state) cleanup(): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:846](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L846) +Defined in: [packages/db/src/collection/index.ts:856](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L856) Clean up the collection by stopping sync and clearing data This can be called manually or automatically by garbage collection @@ -311,7 +327,7 @@ This can be called manually or automatically by garbage collection createIndex(indexCallback, config): IndexProxy; ``` -Defined in: [packages/db/src/collection/index.ts:486](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L486) +Defined in: [packages/db/src/collection/index.ts:491](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L491) Creates an index on a collection for faster queries. Indexes significantly improve query performance by allowing constant time lookups @@ -381,7 +397,7 @@ currentStateAsChanges(options): | ChangeMessage[]; ``` -Defined in: [packages/db/src/collection/index.ts:750](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L750) +Defined in: [packages/db/src/collection/index.ts:760](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L760) Returns the current state of the collection as an array of changes @@ -425,7 +441,7 @@ const activeChanges = collection.currentStateAsChanges({ delete(keys, config?): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:660](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L660) +Defined in: [packages/db/src/collection/index.ts:670](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L670) Deletes one or more items from the collection @@ -488,7 +504,7 @@ try { entries(): IterableIterator<[TKey, TOutput]>; ``` -Defined in: [packages/db/src/collection/index.ts:420](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L420) +Defined in: [packages/db/src/collection/index.ts:425](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L425) Get all entries (virtual derived state) @@ -504,7 +520,7 @@ Get all entries (virtual derived state) forEach(callbackfn): void; ``` -Defined in: [packages/db/src/collection/index.ts:434](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L434) +Defined in: [packages/db/src/collection/index.ts:439](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L439) Execute a callback for each entry in the collection @@ -526,7 +542,7 @@ Execute a callback for each entry in the collection get(key): TOutput | undefined; ``` -Defined in: [packages/db/src/collection/index.ts:385](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L385) +Defined in: [packages/db/src/collection/index.ts:390](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L390) Get the current value for a key (virtual derived state) @@ -548,7 +564,7 @@ Get the current value for a key (virtual derived state) getKeyFromItem(item): TKey; ``` -Defined in: [packages/db/src/collection/index.ts:449](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L449) +Defined in: [packages/db/src/collection/index.ts:454](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L454) #### Parameters @@ -568,7 +584,7 @@ Defined in: [packages/db/src/collection/index.ts:449](https://github.com/TanStac has(key): boolean; ``` -Defined in: [packages/db/src/collection/index.ts:392](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L392) +Defined in: [packages/db/src/collection/index.ts:397](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L397) Check if a key exists in the collection (virtual derived state) @@ -592,7 +608,7 @@ insert(data, config?): | Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:547](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L547) +Defined in: [packages/db/src/collection/index.ts:557](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L557) Inserts one or more items into the collection @@ -663,7 +679,7 @@ try { isReady(): boolean; ``` -Defined in: [packages/db/src/collection/index.ts:354](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L354) +Defined in: [packages/db/src/collection/index.ts:359](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L359) Check if the collection is ready for use Returns true if the collection has been marked as ready by its sync implementation @@ -693,7 +709,7 @@ if (collection.isReady()) { keys(): IterableIterator; ``` -Defined in: [packages/db/src/collection/index.ts:406](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L406) +Defined in: [packages/db/src/collection/index.ts:411](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L411) Get all keys (virtual derived state) @@ -709,7 +725,7 @@ Get all keys (virtual derived state) map(callbackfn): U[]; ``` -Defined in: [packages/db/src/collection/index.ts:443](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L443) +Defined in: [packages/db/src/collection/index.ts:448](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L448) Create a new array with the results of calling a function for each entry in the collection @@ -737,7 +753,7 @@ Create a new array with the results of calling a function for each entry in the off(event, callback): void; ``` -Defined in: [packages/db/src/collection/index.ts:825](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L825) +Defined in: [packages/db/src/collection/index.ts:835](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L835) Unsubscribe from a collection event @@ -777,7 +793,7 @@ Unsubscribe from a collection event on(event, callback): () => void; ``` -Defined in: [packages/db/src/collection/index.ts:805](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L805) +Defined in: [packages/db/src/collection/index.ts:815](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L815) Subscribe to a collection event @@ -823,7 +839,7 @@ Subscribe to a collection event once(event, callback): () => void; ``` -Defined in: [packages/db/src/collection/index.ts:815](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L815) +Defined in: [packages/db/src/collection/index.ts:825](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L825) Subscribe to a collection event once @@ -869,7 +885,7 @@ Subscribe to a collection event once onFirstReady(callback): void; ``` -Defined in: [packages/db/src/collection/index.ts:338](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L338) +Defined in: [packages/db/src/collection/index.ts:343](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L343) Register a callback to be executed when the collection first becomes ready Useful for preloading collections @@ -903,7 +919,7 @@ collection.onFirstReady(() => { preload(): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:378](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L378) +Defined in: [packages/db/src/collection/index.ts:383](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L383) Preload the collection data by starting sync if not already started Multiple concurrent calls will share the same promise @@ -920,7 +936,7 @@ Multiple concurrent calls will share the same promise startSyncImmediate(): void; ``` -Defined in: [packages/db/src/collection/index.ts:370](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L370) +Defined in: [packages/db/src/collection/index.ts:375](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L375) Start sync immediately - internal method for compiled queries This bypasses lazy loading for special cases like live query results @@ -937,7 +953,7 @@ This bypasses lazy loading for special cases like live query results stateWhenReady(): Promise>; ``` -Defined in: [packages/db/src/collection/index.ts:697](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L697) +Defined in: [packages/db/src/collection/index.ts:707](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L707) Gets the current state of the collection as a Map, but only resolves when data is available Waits for the first sync commit to complete before resolving @@ -956,7 +972,7 @@ Promise that resolves to a Map containing all items in the collection subscribeChanges(callback, options): CollectionSubscription; ``` -Defined in: [packages/db/src/collection/index.ts:795](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L795) +Defined in: [packages/db/src/collection/index.ts:805](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L805) Subscribe to changes in the collection @@ -1028,7 +1044,7 @@ const subscription = collection.subscribeChanges((changes) => { toArrayWhenReady(): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:722](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L722) +Defined in: [packages/db/src/collection/index.ts:732](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L732) Gets the current state of the collection as an Array, but only resolves when data is available Waits for the first sync commit to complete before resolving @@ -1049,7 +1065,7 @@ Promise that resolves to an Array containing all items in the collection update(key, callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:592](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L592) +Defined in: [packages/db/src/collection/index.ts:602](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L602) Updates one or more items in the collection using a callback function @@ -1120,7 +1136,7 @@ update( callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:598](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L598) +Defined in: [packages/db/src/collection/index.ts:608](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L608) Updates one or more items in the collection using a callback function @@ -1194,7 +1210,7 @@ try { update(id, callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:605](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L605) +Defined in: [packages/db/src/collection/index.ts:615](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L615) Updates one or more items in the collection using a callback function @@ -1265,7 +1281,7 @@ update( callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:611](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L611) +Defined in: [packages/db/src/collection/index.ts:621](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L621) Updates one or more items in the collection using a callback function @@ -1342,7 +1358,7 @@ validateData( key?): TOutput; ``` -Defined in: [packages/db/src/collection/index.ts:503](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L503) +Defined in: [packages/db/src/collection/index.ts:508](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L508) Validates the data against the schema @@ -1372,7 +1388,7 @@ Validates the data against the schema values(): IterableIterator; ``` -Defined in: [packages/db/src/collection/index.ts:413](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L413) +Defined in: [packages/db/src/collection/index.ts:418](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L418) Get all values (virtual derived state) @@ -1388,7 +1404,7 @@ Get all values (virtual derived state) waitFor(event, timeout?): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:835](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L835) +Defined in: [packages/db/src/collection/index.ts:845](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L845) Wait for a collection event diff --git a/docs/reference/functions/createCollection.md b/docs/reference/functions/createCollection.md index 1404c7300..6e039a885 100644 --- a/docs/reference/functions/createCollection.md +++ b/docs/reference/functions/createCollection.md @@ -11,7 +11,7 @@ title: createCollection function createCollection(options): Collection, TKey, TUtils, T, InferSchemaInput> & NonSingleResult; ``` -Defined in: [packages/db/src/collection/index.ts:130](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L130) +Defined in: [packages/db/src/collection/index.ts:131](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L131) Creates a new Collection instance with the given configuration @@ -120,7 +120,7 @@ const todos = createCollection({ function createCollection(options): Collection, TKey, TUtils, T, InferSchemaInput> & SingleResult; ``` -Defined in: [packages/db/src/collection/index.ts:143](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L143) +Defined in: [packages/db/src/collection/index.ts:144](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L144) Creates a new Collection instance with the given configuration @@ -229,7 +229,7 @@ const todos = createCollection({ function createCollection(options): Collection & NonSingleResult; ``` -Defined in: [packages/db/src/collection/index.ts:157](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L157) +Defined in: [packages/db/src/collection/index.ts:158](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L158) Creates a new Collection instance with the given configuration @@ -338,7 +338,7 @@ const todos = createCollection({ function createCollection(options): Collection & SingleResult; ``` -Defined in: [packages/db/src/collection/index.ts:170](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L170) +Defined in: [packages/db/src/collection/index.ts:171](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L171) Creates a new Collection instance with the given configuration diff --git a/docs/reference/index.md b/docs/reference/index.md index 9fbdabea9..dbe51248d 100644 --- a/docs/reference/index.md +++ b/docs/reference/index.md @@ -110,6 +110,7 @@ title: "@tanstack/db" - [ChangeMessage](../interfaces/ChangeMessage.md) - [Collection](../interfaces/Collection.md) - [CollectionConfig](../interfaces/CollectionConfig.md) +- [CollectionLike](../interfaces/CollectionLike.md) - [Context](../interfaces/Context.md) - [CreateOptimisticActionsOptions](../interfaces/CreateOptimisticActionsOptions.md) - [CurrentStateAsChangesOptions](../interfaces/CurrentStateAsChangesOptions.md) @@ -193,6 +194,7 @@ title: "@tanstack/db" - [StorageEventApi](../type-aliases/StorageEventApi.md) - [Strategy](../type-aliases/Strategy.md) - [StrategyOptions](../type-aliases/StrategyOptions.md) +- [StringCollationConfig](../type-aliases/StringCollationConfig.md) - [SubscriptionEvents](../type-aliases/SubscriptionEvents.md) - [SubscriptionStatus](../type-aliases/SubscriptionStatus.md) - [SyncConfigRes](../type-aliases/SyncConfigRes.md) diff --git a/docs/reference/interfaces/BaseCollectionConfig.md b/docs/reference/interfaces/BaseCollectionConfig.md index 15da7ae5a..862d8819d 100644 --- a/docs/reference/interfaces/BaseCollectionConfig.md +++ b/docs/reference/interfaces/BaseCollectionConfig.md @@ -5,7 +5,7 @@ title: BaseCollectionConfig # Interface: BaseCollectionConfig\ -Defined in: [packages/db/src/types.ts:385](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L385) +Defined in: [packages/db/src/types.ts:416](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L416) ## Extended by @@ -42,7 +42,7 @@ Defined in: [packages/db/src/types.ts:385](https://github.com/TanStack/db/blob/m optional autoIndex: "eager" | "off"; ``` -Defined in: [packages/db/src/types.ts:434](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L434) +Defined in: [packages/db/src/types.ts:465](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L465) Auto-indexing mode for the collection. When enabled, indexes will be automatically created for simple where expressions. @@ -66,7 +66,7 @@ When enabled, indexes will be automatically created for simple where expressions optional compare: (x, y) => number; ``` -Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) +Defined in: [packages/db/src/types.ts:476](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L476) Optional function to compare two items. This is used to order the items in the collection. @@ -100,13 +100,28 @@ compare: (x, y) => x.createdAt.getTime() - y.createdAt.getTime() *** +### defaultStringCollation? + +```ts +optional defaultStringCollation: StringCollationConfig; +``` + +Defined in: [packages/db/src/types.ts:622](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L622) + +Specifies how to compare data in the collection. +This should be configured to match data ordering on the backend. +E.g., when using the Electric DB collection these options + should match the database's collation settings. + +*** + ### gcTime? ```ts optional gcTime: number; ``` -Defined in: [packages/db/src/types.ts:414](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L414) +Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) Time in milliseconds after which the collection will be garbage collected when it has no active subscribers. Defaults to 5 minutes (300000ms). @@ -119,7 +134,7 @@ when it has no active subscribers. Defaults to 5 minutes (300000ms). getKey: (item) => TKey; ``` -Defined in: [packages/db/src/types.ts:409](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L409) +Defined in: [packages/db/src/types.ts:440](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L440) Function to extract the ID from an object This is required for update/delete operations which now only accept IDs @@ -153,7 +168,7 @@ getKey: (item) => item.uuid optional id: string; ``` -Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L398) +Defined in: [packages/db/src/types.ts:429](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L429) *** @@ -163,7 +178,7 @@ Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/m optional onDelete: DeleteMutationFn; ``` -Defined in: [packages/db/src/types.ts:583](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L583) +Defined in: [packages/db/src/types.ts:614](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L614) Optional asynchronous handler function called before a delete operation @@ -227,7 +242,7 @@ onDelete: async ({ transaction, collection }) => { optional onInsert: InsertMutationFn; ``` -Defined in: [packages/db/src/types.ts:496](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L496) +Defined in: [packages/db/src/types.ts:527](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L527) Optional asynchronous handler function called before an insert operation @@ -290,7 +305,7 @@ onInsert: async ({ transaction, collection }) => { optional onUpdate: UpdateMutationFn; ``` -Defined in: [packages/db/src/types.ts:540](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L540) +Defined in: [packages/db/src/types.ts:571](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L571) Optional asynchronous handler function called before an update operation @@ -354,7 +369,7 @@ onUpdate: async ({ transaction, collection }) => { optional schema: TSchema; ``` -Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L399) +Defined in: [packages/db/src/types.ts:430](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L430) *** @@ -364,7 +379,7 @@ Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/m optional startSync: boolean; ``` -Defined in: [packages/db/src/types.ts:425](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L425) +Defined in: [packages/db/src/types.ts:456](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L456) Whether to eagerly start syncing on collection creation. When true, syncing begins immediately. When false, syncing starts when the first subscriber attaches. @@ -387,7 +402,7 @@ false optional syncMode: SyncMode; ``` -Defined in: [packages/db/src/types.ts:454](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L454) +Defined in: [packages/db/src/types.ts:485](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L485) The mode of sync to use for the collection. @@ -409,4 +424,4 @@ The exact implementation of the sync mode is up to the sync implementation. optional utils: TUtils; ``` -Defined in: [packages/db/src/types.ts:585](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L585) +Defined in: [packages/db/src/types.ts:624](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L624) diff --git a/docs/reference/interfaces/ChangeMessage.md b/docs/reference/interfaces/ChangeMessage.md index 81c59300d..91c256af8 100644 --- a/docs/reference/interfaces/ChangeMessage.md +++ b/docs/reference/interfaces/ChangeMessage.md @@ -5,7 +5,7 @@ title: ChangeMessage # Interface: ChangeMessage\ -Defined in: [packages/db/src/types.ts:261](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L261) +Defined in: [packages/db/src/types.ts:292](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L292) ## Extended by @@ -29,7 +29,7 @@ Defined in: [packages/db/src/types.ts:261](https://github.com/TanStack/db/blob/m key: TKey; ``` -Defined in: [packages/db/src/types.ts:265](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L265) +Defined in: [packages/db/src/types.ts:296](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L296) *** @@ -39,7 +39,7 @@ Defined in: [packages/db/src/types.ts:265](https://github.com/TanStack/db/blob/m optional metadata: Record; ``` -Defined in: [packages/db/src/types.ts:269](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L269) +Defined in: [packages/db/src/types.ts:300](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L300) *** @@ -49,7 +49,7 @@ Defined in: [packages/db/src/types.ts:269](https://github.com/TanStack/db/blob/m optional previousValue: T; ``` -Defined in: [packages/db/src/types.ts:267](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L267) +Defined in: [packages/db/src/types.ts:298](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L298) *** @@ -59,7 +59,7 @@ Defined in: [packages/db/src/types.ts:267](https://github.com/TanStack/db/blob/m type: OperationType; ``` -Defined in: [packages/db/src/types.ts:268](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L268) +Defined in: [packages/db/src/types.ts:299](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L299) *** @@ -69,4 +69,4 @@ Defined in: [packages/db/src/types.ts:268](https://github.com/TanStack/db/blob/m value: T; ``` -Defined in: [packages/db/src/types.ts:266](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L266) +Defined in: [packages/db/src/types.ts:297](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L297) diff --git a/docs/reference/interfaces/Collection.md b/docs/reference/interfaces/Collection.md index c2badec06..bd28ab080 100644 --- a/docs/reference/interfaces/Collection.md +++ b/docs/reference/interfaces/Collection.md @@ -5,7 +5,7 @@ title: Collection # Interface: Collection\ -Defined in: [packages/db/src/collection/index.ts:47](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L47) +Defined in: [packages/db/src/collection/index.ts:48](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L48) Enhanced Collection interface that includes both data type T and utilities TUtils @@ -51,7 +51,7 @@ The type for insert operations (can be different from T for schemas with default _lifecycle: CollectionLifecycleManager; ``` -Defined in: [packages/db/src/collection/index.ts:219](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L219) +Defined in: [packages/db/src/collection/index.ts:220](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L220) #### Inherited from @@ -65,7 +65,7 @@ Defined in: [packages/db/src/collection/index.ts:219](https://github.com/TanStac _state: CollectionStateManager; ``` -Defined in: [packages/db/src/collection/index.ts:231](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L231) +Defined in: [packages/db/src/collection/index.ts:232](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L232) #### Inherited from @@ -79,7 +79,7 @@ Defined in: [packages/db/src/collection/index.ts:231](https://github.com/TanStac _sync: CollectionSyncManager; ``` -Defined in: [packages/db/src/collection/index.ts:220](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L220) +Defined in: [packages/db/src/collection/index.ts:221](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L221) #### Inherited from @@ -93,7 +93,7 @@ Defined in: [packages/db/src/collection/index.ts:220](https://github.com/TanStac config: CollectionConfig; ``` -Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L210) +Defined in: [packages/db/src/collection/index.ts:211](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L211) #### Inherited from @@ -107,7 +107,7 @@ Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStac id: string; ``` -Defined in: [packages/db/src/collection/index.ts:209](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L209) +Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L210) #### Inherited from @@ -121,7 +121,7 @@ Defined in: [packages/db/src/collection/index.ts:209](https://github.com/TanStac readonly optional singleResult: true; ``` -Defined in: [packages/db/src/collection/index.ts:55](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L55) +Defined in: [packages/db/src/collection/index.ts:56](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L56) *** @@ -131,7 +131,7 @@ Defined in: [packages/db/src/collection/index.ts:55](https://github.com/TanStack readonly utils: TUtils; ``` -Defined in: [packages/db/src/collection/index.ts:54](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L54) +Defined in: [packages/db/src/collection/index.ts:55](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L55) #### Overrides @@ -139,6 +139,26 @@ Defined in: [packages/db/src/collection/index.ts:54](https://github.com/TanStack ## Accessors +### compareOptions + +#### Get Signature + +```ts +get compareOptions(): StringCollationConfig; +``` + +Defined in: [packages/db/src/collection/index.ts:516](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L516) + +##### Returns + +[`StringCollationConfig`](../../type-aliases/StringCollationConfig.md) + +#### Inherited from + +[`CollectionImpl`](../../classes/CollectionImpl.md).[`compareOptions`](../../classes/CollectionImpl.md#compareoptions) + +*** + ### indexes #### Get Signature @@ -147,7 +167,7 @@ Defined in: [packages/db/src/collection/index.ts:54](https://github.com/TanStack get indexes(): Map>; ``` -Defined in: [packages/db/src/collection/index.ts:496](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L496) +Defined in: [packages/db/src/collection/index.ts:501](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L501) Get resolved indexes for query optimization @@ -169,7 +189,7 @@ Get resolved indexes for query optimization get isLoadingSubset(): boolean; ``` -Defined in: [packages/db/src/collection/index.ts:362](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L362) +Defined in: [packages/db/src/collection/index.ts:367](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L367) Check if the collection is currently loading more data @@ -193,7 +213,7 @@ true if the collection has pending load more operations, false otherwise get size(): number; ``` -Defined in: [packages/db/src/collection/index.ts:399](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L399) +Defined in: [packages/db/src/collection/index.ts:404](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L404) Get the current size of the collection (cached) @@ -215,7 +235,7 @@ Get the current size of the collection (cached) get state(): Map; ``` -Defined in: [packages/db/src/collection/index.ts:683](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L683) +Defined in: [packages/db/src/collection/index.ts:693](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L693) Gets the current state of the collection as a Map @@ -255,7 +275,7 @@ Map containing all items in the collection, with keys as identifiers get status(): CollectionStatus; ``` -Defined in: [packages/db/src/collection/index.ts:317](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L317) +Defined in: [packages/db/src/collection/index.ts:322](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L322) Gets the current status of the collection @@ -277,7 +297,7 @@ Gets the current status of the collection get subscriberCount(): number; ``` -Defined in: [packages/db/src/collection/index.ts:324](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L324) +Defined in: [packages/db/src/collection/index.ts:329](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L329) Get the number of subscribers to the collection @@ -299,7 +319,7 @@ Get the number of subscribers to the collection get toArray(): TOutput[]; ``` -Defined in: [packages/db/src/collection/index.ts:712](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L712) +Defined in: [packages/db/src/collection/index.ts:722](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L722) Gets the current state of the collection as an Array @@ -321,7 +341,7 @@ An Array containing all items in the collection iterator: IterableIterator<[TKey, T]>; ``` -Defined in: [packages/db/src/collection/index.ts:427](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L427) +Defined in: [packages/db/src/collection/index.ts:432](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L432) Get all entries (virtual derived state) @@ -341,7 +361,7 @@ Get all entries (virtual derived state) cleanup(): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:846](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L846) +Defined in: [packages/db/src/collection/index.ts:856](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L856) Clean up the collection by stopping sync and clearing data This can be called manually or automatically by garbage collection @@ -362,7 +382,7 @@ This can be called manually or automatically by garbage collection createIndex(indexCallback, config): IndexProxy; ``` -Defined in: [packages/db/src/collection/index.ts:486](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L486) +Defined in: [packages/db/src/collection/index.ts:491](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L491) Creates an index on a collection for faster queries. Indexes significantly improve query performance by allowing constant time lookups @@ -436,7 +456,7 @@ currentStateAsChanges(options): | ChangeMessage[]; ``` -Defined in: [packages/db/src/collection/index.ts:750](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L750) +Defined in: [packages/db/src/collection/index.ts:760](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L760) Returns the current state of the collection as an array of changes @@ -484,7 +504,7 @@ const activeChanges = collection.currentStateAsChanges({ delete(keys, config?): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:660](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L660) +Defined in: [packages/db/src/collection/index.ts:670](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L670) Deletes one or more items from the collection @@ -551,7 +571,7 @@ try { entries(): IterableIterator<[TKey, T]>; ``` -Defined in: [packages/db/src/collection/index.ts:420](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L420) +Defined in: [packages/db/src/collection/index.ts:425](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L425) Get all entries (virtual derived state) @@ -571,7 +591,7 @@ Get all entries (virtual derived state) forEach(callbackfn): void; ``` -Defined in: [packages/db/src/collection/index.ts:434](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L434) +Defined in: [packages/db/src/collection/index.ts:439](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L439) Execute a callback for each entry in the collection @@ -597,7 +617,7 @@ Execute a callback for each entry in the collection get(key): T | undefined; ``` -Defined in: [packages/db/src/collection/index.ts:385](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L385) +Defined in: [packages/db/src/collection/index.ts:390](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L390) Get the current value for a key (virtual derived state) @@ -623,7 +643,7 @@ Get the current value for a key (virtual derived state) getKeyFromItem(item): TKey; ``` -Defined in: [packages/db/src/collection/index.ts:449](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L449) +Defined in: [packages/db/src/collection/index.ts:454](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L454) #### Parameters @@ -647,7 +667,7 @@ Defined in: [packages/db/src/collection/index.ts:449](https://github.com/TanStac has(key): boolean; ``` -Defined in: [packages/db/src/collection/index.ts:392](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L392) +Defined in: [packages/db/src/collection/index.ts:397](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L397) Check if a key exists in the collection (virtual derived state) @@ -675,7 +695,7 @@ insert(data, config?): | Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:547](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L547) +Defined in: [packages/db/src/collection/index.ts:557](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L557) Inserts one or more items into the collection @@ -750,7 +770,7 @@ try { isReady(): boolean; ``` -Defined in: [packages/db/src/collection/index.ts:354](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L354) +Defined in: [packages/db/src/collection/index.ts:359](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L359) Check if the collection is ready for use Returns true if the collection has been marked as ready by its sync implementation @@ -784,7 +804,7 @@ if (collection.isReady()) { keys(): IterableIterator; ``` -Defined in: [packages/db/src/collection/index.ts:406](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L406) +Defined in: [packages/db/src/collection/index.ts:411](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L411) Get all keys (virtual derived state) @@ -804,7 +824,7 @@ Get all keys (virtual derived state) map(callbackfn): U[]; ``` -Defined in: [packages/db/src/collection/index.ts:443](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L443) +Defined in: [packages/db/src/collection/index.ts:448](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L448) Create a new array with the results of calling a function for each entry in the collection @@ -836,7 +856,7 @@ Create a new array with the results of calling a function for each entry in the off(event, callback): void; ``` -Defined in: [packages/db/src/collection/index.ts:825](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L825) +Defined in: [packages/db/src/collection/index.ts:835](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L835) Unsubscribe from a collection event @@ -880,7 +900,7 @@ Unsubscribe from a collection event on(event, callback): () => void; ``` -Defined in: [packages/db/src/collection/index.ts:805](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L805) +Defined in: [packages/db/src/collection/index.ts:815](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L815) Subscribe to a collection event @@ -930,7 +950,7 @@ Subscribe to a collection event once(event, callback): () => void; ``` -Defined in: [packages/db/src/collection/index.ts:815](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L815) +Defined in: [packages/db/src/collection/index.ts:825](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L825) Subscribe to a collection event once @@ -980,7 +1000,7 @@ Subscribe to a collection event once onFirstReady(callback): void; ``` -Defined in: [packages/db/src/collection/index.ts:338](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L338) +Defined in: [packages/db/src/collection/index.ts:343](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L343) Register a callback to be executed when the collection first becomes ready Useful for preloading collections @@ -1018,7 +1038,7 @@ collection.onFirstReady(() => { preload(): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:378](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L378) +Defined in: [packages/db/src/collection/index.ts:383](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L383) Preload the collection data by starting sync if not already started Multiple concurrent calls will share the same promise @@ -1039,7 +1059,7 @@ Multiple concurrent calls will share the same promise startSyncImmediate(): void; ``` -Defined in: [packages/db/src/collection/index.ts:370](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L370) +Defined in: [packages/db/src/collection/index.ts:375](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L375) Start sync immediately - internal method for compiled queries This bypasses lazy loading for special cases like live query results @@ -1060,7 +1080,7 @@ This bypasses lazy loading for special cases like live query results stateWhenReady(): Promise>; ``` -Defined in: [packages/db/src/collection/index.ts:697](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L697) +Defined in: [packages/db/src/collection/index.ts:707](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L707) Gets the current state of the collection as a Map, but only resolves when data is available Waits for the first sync commit to complete before resolving @@ -1083,7 +1103,7 @@ Promise that resolves to a Map containing all items in the collection subscribeChanges(callback, options): CollectionSubscription; ``` -Defined in: [packages/db/src/collection/index.ts:795](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L795) +Defined in: [packages/db/src/collection/index.ts:805](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L805) Subscribe to changes in the collection @@ -1159,7 +1179,7 @@ const subscription = collection.subscribeChanges((changes) => { toArrayWhenReady(): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:722](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L722) +Defined in: [packages/db/src/collection/index.ts:732](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L732) Gets the current state of the collection as an Array, but only resolves when data is available Waits for the first sync commit to complete before resolving @@ -1184,7 +1204,7 @@ Promise that resolves to an Array containing all items in the collection update(key, callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:592](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L592) +Defined in: [packages/db/src/collection/index.ts:602](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L602) Updates one or more items in the collection using a callback function @@ -1259,7 +1279,7 @@ update( callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:598](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L598) +Defined in: [packages/db/src/collection/index.ts:608](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L608) Updates one or more items in the collection using a callback function @@ -1337,7 +1357,7 @@ try { update(id, callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:605](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L605) +Defined in: [packages/db/src/collection/index.ts:615](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L615) Updates one or more items in the collection using a callback function @@ -1412,7 +1432,7 @@ update( callback): Transaction; ``` -Defined in: [packages/db/src/collection/index.ts:611](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L611) +Defined in: [packages/db/src/collection/index.ts:621](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L621) Updates one or more items in the collection using a callback function @@ -1493,7 +1513,7 @@ validateData( key?): T; ``` -Defined in: [packages/db/src/collection/index.ts:503](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L503) +Defined in: [packages/db/src/collection/index.ts:508](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L508) Validates the data against the schema @@ -1527,7 +1547,7 @@ Validates the data against the schema values(): IterableIterator; ``` -Defined in: [packages/db/src/collection/index.ts:413](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L413) +Defined in: [packages/db/src/collection/index.ts:418](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L418) Get all values (virtual derived state) @@ -1547,7 +1567,7 @@ Get all values (virtual derived state) waitFor(event, timeout?): Promise; ``` -Defined in: [packages/db/src/collection/index.ts:835](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L835) +Defined in: [packages/db/src/collection/index.ts:845](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L845) Wait for a collection event diff --git a/docs/reference/interfaces/CollectionConfig.md b/docs/reference/interfaces/CollectionConfig.md index 78702c4d3..f08dbf1d1 100644 --- a/docs/reference/interfaces/CollectionConfig.md +++ b/docs/reference/interfaces/CollectionConfig.md @@ -5,7 +5,7 @@ title: CollectionConfig # Interface: CollectionConfig\ -Defined in: [packages/db/src/types.ts:588](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L588) +Defined in: [packages/db/src/types.ts:627](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L627) ## Extends @@ -37,7 +37,7 @@ Defined in: [packages/db/src/types.ts:588](https://github.com/TanStack/db/blob/m optional autoIndex: "eager" | "off"; ``` -Defined in: [packages/db/src/types.ts:434](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L434) +Defined in: [packages/db/src/types.ts:465](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L465) Auto-indexing mode for the collection. When enabled, indexes will be automatically created for simple where expressions. @@ -65,7 +65,7 @@ When enabled, indexes will be automatically created for simple where expressions optional compare: (x, y) => number; ``` -Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) +Defined in: [packages/db/src/types.ts:476](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L476) Optional function to compare two items. This is used to order the items in the collection. @@ -103,13 +103,32 @@ compare: (x, y) => x.createdAt.getTime() - y.createdAt.getTime() *** +### defaultStringCollation? + +```ts +optional defaultStringCollation: StringCollationConfig; +``` + +Defined in: [packages/db/src/types.ts:622](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L622) + +Specifies how to compare data in the collection. +This should be configured to match data ordering on the backend. +E.g., when using the Electric DB collection these options + should match the database's collation settings. + +#### Inherited from + +[`BaseCollectionConfig`](../BaseCollectionConfig.md).[`defaultStringCollation`](../BaseCollectionConfig.md#defaultstringcollation) + +*** + ### gcTime? ```ts optional gcTime: number; ``` -Defined in: [packages/db/src/types.ts:414](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L414) +Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) Time in milliseconds after which the collection will be garbage collected when it has no active subscribers. Defaults to 5 minutes (300000ms). @@ -126,7 +145,7 @@ when it has no active subscribers. Defaults to 5 minutes (300000ms). getKey: (item) => TKey; ``` -Defined in: [packages/db/src/types.ts:409](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L409) +Defined in: [packages/db/src/types.ts:440](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L440) Function to extract the ID from an object This is required for update/delete operations which now only accept IDs @@ -164,7 +183,7 @@ getKey: (item) => item.uuid optional id: string; ``` -Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L398) +Defined in: [packages/db/src/types.ts:429](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L429) #### Inherited from @@ -178,7 +197,7 @@ Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/m optional onDelete: DeleteMutationFn; ``` -Defined in: [packages/db/src/types.ts:583](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L583) +Defined in: [packages/db/src/types.ts:614](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L614) Optional asynchronous handler function called before a delete operation @@ -246,7 +265,7 @@ onDelete: async ({ transaction, collection }) => { optional onInsert: InsertMutationFn; ``` -Defined in: [packages/db/src/types.ts:496](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L496) +Defined in: [packages/db/src/types.ts:527](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L527) Optional asynchronous handler function called before an insert operation @@ -313,7 +332,7 @@ onInsert: async ({ transaction, collection }) => { optional onUpdate: UpdateMutationFn; ``` -Defined in: [packages/db/src/types.ts:540](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L540) +Defined in: [packages/db/src/types.ts:571](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L571) Optional asynchronous handler function called before an update operation @@ -381,7 +400,7 @@ onUpdate: async ({ transaction, collection }) => { optional schema: TSchema; ``` -Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L399) +Defined in: [packages/db/src/types.ts:430](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L430) #### Inherited from @@ -395,7 +414,7 @@ Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/m optional startSync: boolean; ``` -Defined in: [packages/db/src/types.ts:425](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L425) +Defined in: [packages/db/src/types.ts:456](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L456) Whether to eagerly start syncing on collection creation. When true, syncing begins immediately. When false, syncing starts when the first subscriber attaches. @@ -422,7 +441,7 @@ false sync: SyncConfig; ``` -Defined in: [packages/db/src/types.ts:594](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L594) +Defined in: [packages/db/src/types.ts:633](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L633) *** @@ -432,7 +451,7 @@ Defined in: [packages/db/src/types.ts:594](https://github.com/TanStack/db/blob/m optional syncMode: SyncMode; ``` -Defined in: [packages/db/src/types.ts:454](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L454) +Defined in: [packages/db/src/types.ts:485](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L485) The mode of sync to use for the collection. @@ -458,7 +477,7 @@ The exact implementation of the sync mode is up to the sync implementation. optional utils: TUtils; ``` -Defined in: [packages/db/src/types.ts:585](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L585) +Defined in: [packages/db/src/types.ts:624](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L624) #### Inherited from diff --git a/docs/reference/interfaces/CollectionLike.md b/docs/reference/interfaces/CollectionLike.md new file mode 100644 index 000000000..fd9f7575b --- /dev/null +++ b/docs/reference/interfaces/CollectionLike.md @@ -0,0 +1,147 @@ +--- +id: CollectionLike +title: CollectionLike +--- + +# Interface: CollectionLike\ + +Defined in: [packages/db/src/types.ts:12](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L12) + +Interface for a collection-like object that provides the necessary methods +for the change events system to work + +## Extends + +- `Pick`\<[`Collection`](../Collection.md)\<`T`, `TKey`\>, `"get"` \| `"has"` \| `"entries"` \| `"indexes"` \| `"id"` \| `"compareOptions"`\> + +## Type Parameters + +### T + +`T` *extends* `object` = `Record`\<`string`, `unknown`\> + +### TKey + +`TKey` *extends* `string` \| `number` = `string` \| `number` + +## Properties + +### compareOptions + +```ts +compareOptions: StringCollationConfig; +``` + +Defined in: [packages/db/src/collection/index.ts:516](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L516) + +#### Inherited from + +[`CollectionImpl`](../../classes/CollectionImpl.md).[`compareOptions`](../../classes/CollectionImpl.md#compareoptions) + +*** + +### id + +```ts +id: string; +``` + +Defined in: [packages/db/src/collection/index.ts:210](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L210) + +#### Inherited from + +[`CollectionImpl`](../../classes/CollectionImpl.md).[`id`](../../classes/CollectionImpl.md#id) + +*** + +### indexes + +```ts +indexes: Map>; +``` + +Defined in: [packages/db/src/collection/index.ts:501](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L501) + +#### Inherited from + +```ts +Pick.indexes +``` + +## Methods + +### entries() + +```ts +entries(): IterableIterator<[TKey, T]>; +``` + +Defined in: [packages/db/src/collection/index.ts:425](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L425) + +Get all entries (virtual derived state) + +#### Returns + +`IterableIterator`\<\[`TKey`, `T`\]\> + +#### Inherited from + +```ts +Pick.entries +``` + +*** + +### get() + +```ts +get(key): T | undefined; +``` + +Defined in: [packages/db/src/collection/index.ts:390](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L390) + +Get the current value for a key (virtual derived state) + +#### Parameters + +##### key + +`TKey` + +#### Returns + +`T` \| `undefined` + +#### Inherited from + +```ts +Pick.get +``` + +*** + +### has() + +```ts +has(key): boolean; +``` + +Defined in: [packages/db/src/collection/index.ts:397](https://github.com/TanStack/db/blob/main/packages/db/src/collection/index.ts#L397) + +Check if a key exists in the collection (virtual derived state) + +#### Parameters + +##### key + +`TKey` + +#### Returns + +`boolean` + +#### Inherited from + +```ts +Pick.has +``` diff --git a/docs/reference/interfaces/CreateOptimisticActionsOptions.md b/docs/reference/interfaces/CreateOptimisticActionsOptions.md index 48ae64848..a7256f738 100644 --- a/docs/reference/interfaces/CreateOptimisticActionsOptions.md +++ b/docs/reference/interfaces/CreateOptimisticActionsOptions.md @@ -5,7 +5,7 @@ title: CreateOptimisticActionsOptions # Interface: CreateOptimisticActionsOptions\ -Defined in: [packages/db/src/types.ts:128](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L128) +Defined in: [packages/db/src/types.ts:159](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L159) Options for the createOptimisticAction helper @@ -31,7 +31,7 @@ Options for the createOptimisticAction helper optional autoCommit: boolean; ``` -Defined in: [packages/db/src/types.ts:119](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L119) +Defined in: [packages/db/src/types.ts:150](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L150) #### Inherited from @@ -45,7 +45,7 @@ Defined in: [packages/db/src/types.ts:119](https://github.com/TanStack/db/blob/m optional id: string; ``` -Defined in: [packages/db/src/types.ts:117](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L117) +Defined in: [packages/db/src/types.ts:148](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L148) Unique identifier for the transaction @@ -63,7 +63,7 @@ Omit.id optional metadata: Record; ``` -Defined in: [packages/db/src/types.ts:122](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L122) +Defined in: [packages/db/src/types.ts:153](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L153) Custom metadata to associate with the transaction @@ -81,7 +81,7 @@ Omit.metadata mutationFn: (vars, params) => Promise; ``` -Defined in: [packages/db/src/types.ts:135](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L135) +Defined in: [packages/db/src/types.ts:166](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L166) Function to execute the mutation on the server @@ -107,7 +107,7 @@ Function to execute the mutation on the server onMutate: (vars) => void; ``` -Defined in: [packages/db/src/types.ts:133](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L133) +Defined in: [packages/db/src/types.ts:164](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L164) Function to apply optimistic updates locally before the mutation completes diff --git a/docs/reference/interfaces/CurrentStateAsChangesOptions.md b/docs/reference/interfaces/CurrentStateAsChangesOptions.md index d54d5107b..f7526d9bb 100644 --- a/docs/reference/interfaces/CurrentStateAsChangesOptions.md +++ b/docs/reference/interfaces/CurrentStateAsChangesOptions.md @@ -5,7 +5,7 @@ title: CurrentStateAsChangesOptions # Interface: CurrentStateAsChangesOptions -Defined in: [packages/db/src/types.ts:678](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L678) +Defined in: [packages/db/src/types.ts:717](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L717) Options for getting current state as changes @@ -17,7 +17,7 @@ Options for getting current state as changes optional limit: number; ``` -Defined in: [packages/db/src/types.ts:682](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L682) +Defined in: [packages/db/src/types.ts:721](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L721) *** @@ -27,7 +27,7 @@ Defined in: [packages/db/src/types.ts:682](https://github.com/TanStack/db/blob/m optional optimizedOnly: boolean; ``` -Defined in: [packages/db/src/types.ts:683](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L683) +Defined in: [packages/db/src/types.ts:722](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L722) *** @@ -37,7 +37,7 @@ Defined in: [packages/db/src/types.ts:683](https://github.com/TanStack/db/blob/m optional orderBy: OrderBy; ``` -Defined in: [packages/db/src/types.ts:681](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L681) +Defined in: [packages/db/src/types.ts:720](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L720) *** @@ -47,6 +47,6 @@ Defined in: [packages/db/src/types.ts:681](https://github.com/TanStack/db/blob/m optional where: BasicExpression; ``` -Defined in: [packages/db/src/types.ts:680](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L680) +Defined in: [packages/db/src/types.ts:719](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L719) Pre-compiled expression for filtering the current state diff --git a/docs/reference/interfaces/InsertConfig.md b/docs/reference/interfaces/InsertConfig.md index 79b7fbda3..e28d179e9 100644 --- a/docs/reference/interfaces/InsertConfig.md +++ b/docs/reference/interfaces/InsertConfig.md @@ -5,7 +5,7 @@ title: InsertConfig # Interface: InsertConfig -Defined in: [packages/db/src/types.ts:303](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L303) +Defined in: [packages/db/src/types.ts:334](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L334) ## Properties @@ -15,7 +15,7 @@ Defined in: [packages/db/src/types.ts:303](https://github.com/TanStack/db/blob/m optional metadata: Record; ``` -Defined in: [packages/db/src/types.ts:304](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L304) +Defined in: [packages/db/src/types.ts:335](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L335) *** @@ -25,6 +25,6 @@ Defined in: [packages/db/src/types.ts:304](https://github.com/TanStack/db/blob/m optional optimistic: boolean; ``` -Defined in: [packages/db/src/types.ts:306](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L306) +Defined in: [packages/db/src/types.ts:337](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L337) Whether to apply optimistic updates immediately. Defaults to true. diff --git a/docs/reference/interfaces/LiveQueryCollectionConfig.md b/docs/reference/interfaces/LiveQueryCollectionConfig.md index ce7da1c8e..1c3a8ed77 100644 --- a/docs/reference/interfaces/LiveQueryCollectionConfig.md +++ b/docs/reference/interfaces/LiveQueryCollectionConfig.md @@ -5,7 +5,7 @@ title: LiveQueryCollectionConfig # Interface: LiveQueryCollectionConfig\ -Defined in: [packages/db/src/query/live/types.ts:49](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L49) +Defined in: [packages/db/src/query/live/types.ts:53](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L53) Configuration interface for live query collection options @@ -43,13 +43,26 @@ const config: LiveQueryCollectionConfig = { ## Properties +### defaultStringCollation? + +```ts +optional defaultStringCollation: StringCollationConfig; +``` + +Defined in: [packages/db/src/query/live/types.ts:107](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L107) + +Optional compare options for string sorting. +If provided, these will be used instead of inheriting from the FROM collection. + +*** + ### gcTime? ```ts optional gcTime: number; ``` -Defined in: [packages/db/src/query/live/types.ts:92](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L92) +Defined in: [packages/db/src/query/live/types.ts:96](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L96) GC time for the collection @@ -61,7 +74,7 @@ GC time for the collection optional getKey: (item) => string | number; ``` -Defined in: [packages/db/src/query/live/types.ts:70](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L70) +Defined in: [packages/db/src/query/live/types.ts:74](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L74) Function to extract the key from result items If not provided, defaults to using the key from the D2 stream @@ -84,7 +97,7 @@ If not provided, defaults to using the key from the D2 stream optional id: string; ``` -Defined in: [packages/db/src/query/live/types.ts:57](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L57) +Defined in: [packages/db/src/query/live/types.ts:61](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L61) Unique identifier for the collection If not provided, defaults to `live-query-${number}` with auto-incrementing number @@ -97,7 +110,7 @@ If not provided, defaults to `live-query-${number}` with auto-incrementing numbe optional onDelete: DeleteMutationFn; ``` -Defined in: [packages/db/src/query/live/types.ts:82](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L82) +Defined in: [packages/db/src/query/live/types.ts:86](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L86) *** @@ -107,7 +120,7 @@ Defined in: [packages/db/src/query/live/types.ts:82](https://github.com/TanStack optional onInsert: InsertMutationFn; ``` -Defined in: [packages/db/src/query/live/types.ts:80](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L80) +Defined in: [packages/db/src/query/live/types.ts:84](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L84) Optional mutation handlers @@ -119,7 +132,7 @@ Optional mutation handlers optional onUpdate: UpdateMutationFn; ``` -Defined in: [packages/db/src/query/live/types.ts:81](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L81) +Defined in: [packages/db/src/query/live/types.ts:85](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L85) *** @@ -131,7 +144,7 @@ query: | (q) => QueryBuilder; ``` -Defined in: [packages/db/src/query/live/types.ts:62](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L62) +Defined in: [packages/db/src/query/live/types.ts:66](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L66) Query builder function that defines the live query @@ -143,7 +156,7 @@ Query builder function that defines the live query optional schema: undefined; ``` -Defined in: [packages/db/src/query/live/types.ts:75](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L75) +Defined in: [packages/db/src/query/live/types.ts:79](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L79) Optional schema for validation @@ -155,7 +168,7 @@ Optional schema for validation optional singleResult: true; ``` -Defined in: [packages/db/src/query/live/types.ts:97](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L97) +Defined in: [packages/db/src/query/live/types.ts:101](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L101) If enabled the collection will return a single object instead of an array @@ -167,6 +180,6 @@ If enabled the collection will return a single object instead of an array optional startSync: boolean; ``` -Defined in: [packages/db/src/query/live/types.ts:87](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L87) +Defined in: [packages/db/src/query/live/types.ts:91](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/types.ts#L91) Start sync / the query immediately diff --git a/docs/reference/interfaces/LocalOnlyCollectionConfig.md b/docs/reference/interfaces/LocalOnlyCollectionConfig.md index d34d42f52..bb212c602 100644 --- a/docs/reference/interfaces/LocalOnlyCollectionConfig.md +++ b/docs/reference/interfaces/LocalOnlyCollectionConfig.md @@ -41,7 +41,7 @@ The type of the key returned by `getKey` optional autoIndex: "eager" | "off"; ``` -Defined in: [packages/db/src/types.ts:434](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L434) +Defined in: [packages/db/src/types.ts:465](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L465) Auto-indexing mode for the collection. When enabled, indexes will be automatically created for simple where expressions. @@ -69,7 +69,7 @@ When enabled, indexes will be automatically created for simple where expressions optional compare: (x, y) => number; ``` -Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) +Defined in: [packages/db/src/types.ts:476](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L476) Optional function to compare two items. This is used to order the items in the collection. @@ -109,13 +109,34 @@ Omit.compare *** +### defaultStringCollation? + +```ts +optional defaultStringCollation: StringCollationConfig; +``` + +Defined in: [packages/db/src/types.ts:622](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L622) + +Specifies how to compare data in the collection. +This should be configured to match data ordering on the backend. +E.g., when using the Electric DB collection these options + should match the database's collation settings. + +#### Inherited from + +```ts +Omit.defaultStringCollation +``` + +*** + ### getKey() ```ts getKey: (item) => TKey; ``` -Defined in: [packages/db/src/types.ts:409](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L409) +Defined in: [packages/db/src/types.ts:440](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L440) Function to extract the ID from an object This is required for update/delete operations which now only accept IDs @@ -155,7 +176,7 @@ Omit.getKey optional id: string; ``` -Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L398) +Defined in: [packages/db/src/types.ts:429](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L429) #### Inherited from @@ -182,7 +203,7 @@ This data will be applied during the initial sync process optional onDelete: DeleteMutationFn; ``` -Defined in: [packages/db/src/types.ts:583](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L583) +Defined in: [packages/db/src/types.ts:614](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L614) Optional asynchronous handler function called before a delete operation @@ -252,7 +273,7 @@ Omit.onDelete optional onInsert: InsertMutationFn; ``` -Defined in: [packages/db/src/types.ts:496](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L496) +Defined in: [packages/db/src/types.ts:527](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L527) Optional asynchronous handler function called before an insert operation @@ -321,7 +342,7 @@ Omit.onInsert optional onUpdate: UpdateMutationFn; ``` -Defined in: [packages/db/src/types.ts:540](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L540) +Defined in: [packages/db/src/types.ts:571](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L571) Optional asynchronous handler function called before an update operation @@ -391,7 +412,7 @@ Omit.onUpdate optional schema: TSchema; ``` -Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L399) +Defined in: [packages/db/src/types.ts:430](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L430) #### Inherited from @@ -407,7 +428,7 @@ Omit.schema optional syncMode: SyncMode; ``` -Defined in: [packages/db/src/types.ts:454](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L454) +Defined in: [packages/db/src/types.ts:485](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L485) The mode of sync to use for the collection. @@ -433,7 +454,7 @@ The exact implementation of the sync mode is up to the sync implementation. optional utils: LocalOnlyCollectionUtils; ``` -Defined in: [packages/db/src/types.ts:585](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L585) +Defined in: [packages/db/src/types.ts:624](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L624) #### Inherited from diff --git a/docs/reference/interfaces/LocalStorageCollectionConfig.md b/docs/reference/interfaces/LocalStorageCollectionConfig.md index 52909c7f4..adfecd035 100644 --- a/docs/reference/interfaces/LocalStorageCollectionConfig.md +++ b/docs/reference/interfaces/LocalStorageCollectionConfig.md @@ -41,7 +41,7 @@ The type of the key returned by `getKey` optional autoIndex: "eager" | "off"; ``` -Defined in: [packages/db/src/types.ts:434](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L434) +Defined in: [packages/db/src/types.ts:465](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L465) Auto-indexing mode for the collection. When enabled, indexes will be automatically created for simple where expressions. @@ -69,7 +69,7 @@ When enabled, indexes will be automatically created for simple where expressions optional compare: (x, y) => number; ``` -Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) +Defined in: [packages/db/src/types.ts:476](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L476) Optional function to compare two items. This is used to order the items in the collection. @@ -107,13 +107,32 @@ compare: (x, y) => x.createdAt.getTime() - y.createdAt.getTime() *** +### defaultStringCollation? + +```ts +optional defaultStringCollation: StringCollationConfig; +``` + +Defined in: [packages/db/src/types.ts:622](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L622) + +Specifies how to compare data in the collection. +This should be configured to match data ordering on the backend. +E.g., when using the Electric DB collection these options + should match the database's collation settings. + +#### Inherited from + +[`BaseCollectionConfig`](../BaseCollectionConfig.md).[`defaultStringCollation`](../BaseCollectionConfig.md#defaultstringcollation) + +*** + ### gcTime? ```ts optional gcTime: number; ``` -Defined in: [packages/db/src/types.ts:414](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L414) +Defined in: [packages/db/src/types.ts:445](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L445) Time in milliseconds after which the collection will be garbage collected when it has no active subscribers. Defaults to 5 minutes (300000ms). @@ -130,7 +149,7 @@ when it has no active subscribers. Defaults to 5 minutes (300000ms). getKey: (item) => TKey; ``` -Defined in: [packages/db/src/types.ts:409](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L409) +Defined in: [packages/db/src/types.ts:440](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L440) Function to extract the ID from an object This is required for update/delete operations which now only accept IDs @@ -168,7 +187,7 @@ getKey: (item) => item.uuid optional id: string; ``` -Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L398) +Defined in: [packages/db/src/types.ts:429](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L429) #### Inherited from @@ -182,7 +201,7 @@ Defined in: [packages/db/src/types.ts:398](https://github.com/TanStack/db/blob/m optional onDelete: DeleteMutationFn; ``` -Defined in: [packages/db/src/types.ts:583](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L583) +Defined in: [packages/db/src/types.ts:614](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L614) Optional asynchronous handler function called before a delete operation @@ -250,7 +269,7 @@ onDelete: async ({ transaction, collection }) => { optional onInsert: InsertMutationFn; ``` -Defined in: [packages/db/src/types.ts:496](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L496) +Defined in: [packages/db/src/types.ts:527](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L527) Optional asynchronous handler function called before an insert operation @@ -317,7 +336,7 @@ onInsert: async ({ transaction, collection }) => { optional onUpdate: UpdateMutationFn; ``` -Defined in: [packages/db/src/types.ts:540](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L540) +Defined in: [packages/db/src/types.ts:571](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L571) Optional asynchronous handler function called before an update operation @@ -398,7 +417,7 @@ Defaults to JSON optional schema: TSchema; ``` -Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L399) +Defined in: [packages/db/src/types.ts:430](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L430) #### Inherited from @@ -412,7 +431,7 @@ Defined in: [packages/db/src/types.ts:399](https://github.com/TanStack/db/blob/m optional startSync: boolean; ``` -Defined in: [packages/db/src/types.ts:425](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L425) +Defined in: [packages/db/src/types.ts:456](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L456) Whether to eagerly start syncing on collection creation. When true, syncing begins immediately. When false, syncing starts when the first subscriber attaches. @@ -477,7 +496,7 @@ The key to use for storing the collection data in localStorage/sessionStorage optional syncMode: SyncMode; ``` -Defined in: [packages/db/src/types.ts:454](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L454) +Defined in: [packages/db/src/types.ts:485](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L485) The mode of sync to use for the collection. @@ -503,7 +522,7 @@ The exact implementation of the sync mode is up to the sync implementation. optional utils: UtilsRecord; ``` -Defined in: [packages/db/src/types.ts:585](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L585) +Defined in: [packages/db/src/types.ts:624](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L624) #### Inherited from diff --git a/docs/reference/interfaces/OperationConfig.md b/docs/reference/interfaces/OperationConfig.md index e5c2774da..b75a2e0ed 100644 --- a/docs/reference/interfaces/OperationConfig.md +++ b/docs/reference/interfaces/OperationConfig.md @@ -5,7 +5,7 @@ title: OperationConfig # Interface: OperationConfig -Defined in: [packages/db/src/types.ts:297](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L297) +Defined in: [packages/db/src/types.ts:328](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L328) ## Properties @@ -15,7 +15,7 @@ Defined in: [packages/db/src/types.ts:297](https://github.com/TanStack/db/blob/m optional metadata: Record; ``` -Defined in: [packages/db/src/types.ts:298](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L298) +Defined in: [packages/db/src/types.ts:329](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L329) *** @@ -25,6 +25,6 @@ Defined in: [packages/db/src/types.ts:298](https://github.com/TanStack/db/blob/m optional optimistic: boolean; ``` -Defined in: [packages/db/src/types.ts:300](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L300) +Defined in: [packages/db/src/types.ts:331](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L331) Whether to apply optimistic updates immediately. Defaults to true. diff --git a/docs/reference/interfaces/OptimisticChangeMessage.md b/docs/reference/interfaces/OptimisticChangeMessage.md index f0a365281..e1acaeebc 100644 --- a/docs/reference/interfaces/OptimisticChangeMessage.md +++ b/docs/reference/interfaces/OptimisticChangeMessage.md @@ -5,7 +5,7 @@ title: OptimisticChangeMessage # Interface: OptimisticChangeMessage\ -Defined in: [packages/db/src/types.ts:272](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L272) +Defined in: [packages/db/src/types.ts:303](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L303) ## Extends @@ -25,7 +25,7 @@ Defined in: [packages/db/src/types.ts:272](https://github.com/TanStack/db/blob/m optional isActive: boolean; ``` -Defined in: [packages/db/src/types.ts:276](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L276) +Defined in: [packages/db/src/types.ts:307](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L307) *** @@ -35,7 +35,7 @@ Defined in: [packages/db/src/types.ts:276](https://github.com/TanStack/db/blob/m key: string | number; ``` -Defined in: [packages/db/src/types.ts:265](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L265) +Defined in: [packages/db/src/types.ts:296](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L296) #### Inherited from @@ -49,7 +49,7 @@ Defined in: [packages/db/src/types.ts:265](https://github.com/TanStack/db/blob/m optional metadata: Record; ``` -Defined in: [packages/db/src/types.ts:269](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L269) +Defined in: [packages/db/src/types.ts:300](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L300) #### Inherited from @@ -63,7 +63,7 @@ Defined in: [packages/db/src/types.ts:269](https://github.com/TanStack/db/blob/m optional previousValue: T; ``` -Defined in: [packages/db/src/types.ts:267](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L267) +Defined in: [packages/db/src/types.ts:298](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L298) #### Inherited from @@ -77,7 +77,7 @@ Defined in: [packages/db/src/types.ts:267](https://github.com/TanStack/db/blob/m type: OperationType; ``` -Defined in: [packages/db/src/types.ts:268](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L268) +Defined in: [packages/db/src/types.ts:299](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L299) #### Inherited from @@ -91,7 +91,7 @@ Defined in: [packages/db/src/types.ts:268](https://github.com/TanStack/db/blob/m value: T; ``` -Defined in: [packages/db/src/types.ts:266](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L266) +Defined in: [packages/db/src/types.ts:297](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L297) #### Inherited from diff --git a/docs/reference/interfaces/PendingMutation.md b/docs/reference/interfaces/PendingMutation.md index 909f848f6..2a5264f25 100644 --- a/docs/reference/interfaces/PendingMutation.md +++ b/docs/reference/interfaces/PendingMutation.md @@ -5,7 +5,7 @@ title: PendingMutation # Interface: PendingMutation\ -Defined in: [packages/db/src/types.ts:57](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L57) +Defined in: [packages/db/src/types.ts:88](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L88) Represents a pending mutation within a transaction Contains information about the original and modified data, as well as metadata @@ -32,7 +32,7 @@ Contains information about the original and modified data, as well as metadata changes: ResolveTransactionChanges; ``` -Defined in: [packages/db/src/types.ts:74](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L74) +Defined in: [packages/db/src/types.ts:105](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L105) *** @@ -42,7 +42,7 @@ Defined in: [packages/db/src/types.ts:74](https://github.com/TanStack/db/blob/ma collection: TCollection; ``` -Defined in: [packages/db/src/types.ts:85](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L85) +Defined in: [packages/db/src/types.ts:116](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L116) *** @@ -52,7 +52,7 @@ Defined in: [packages/db/src/types.ts:85](https://github.com/TanStack/db/blob/ma createdAt: Date; ``` -Defined in: [packages/db/src/types.ts:83](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L83) +Defined in: [packages/db/src/types.ts:114](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L114) *** @@ -62,7 +62,7 @@ Defined in: [packages/db/src/types.ts:83](https://github.com/TanStack/db/blob/ma globalKey: string; ``` -Defined in: [packages/db/src/types.ts:75](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L75) +Defined in: [packages/db/src/types.ts:106](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L106) *** @@ -72,7 +72,7 @@ Defined in: [packages/db/src/types.ts:75](https://github.com/TanStack/db/blob/ma key: any; ``` -Defined in: [packages/db/src/types.ts:77](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L77) +Defined in: [packages/db/src/types.ts:108](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L108) *** @@ -82,7 +82,7 @@ Defined in: [packages/db/src/types.ts:77](https://github.com/TanStack/db/blob/ma metadata: unknown; ``` -Defined in: [packages/db/src/types.ts:79](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L79) +Defined in: [packages/db/src/types.ts:110](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L110) *** @@ -92,7 +92,7 @@ Defined in: [packages/db/src/types.ts:79](https://github.com/TanStack/db/blob/ma modified: T; ``` -Defined in: [packages/db/src/types.ts:72](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L72) +Defined in: [packages/db/src/types.ts:103](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L103) *** @@ -102,7 +102,7 @@ Defined in: [packages/db/src/types.ts:72](https://github.com/TanStack/db/blob/ma mutationId: string; ``` -Defined in: [packages/db/src/types.ts:68](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L68) +Defined in: [packages/db/src/types.ts:99](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L99) *** @@ -112,7 +112,7 @@ Defined in: [packages/db/src/types.ts:68](https://github.com/TanStack/db/blob/ma optimistic: boolean; ``` -Defined in: [packages/db/src/types.ts:82](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L82) +Defined in: [packages/db/src/types.ts:113](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L113) Whether this mutation should be applied optimistically (defaults to true) @@ -124,7 +124,7 @@ Whether this mutation should be applied optimistically (defaults to true) original: TOperation extends "insert" ? object : T; ``` -Defined in: [packages/db/src/types.ts:70](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L70) +Defined in: [packages/db/src/types.ts:101](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L101) *** @@ -134,7 +134,7 @@ Defined in: [packages/db/src/types.ts:70](https://github.com/TanStack/db/blob/ma syncMetadata: Record; ``` -Defined in: [packages/db/src/types.ts:80](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L80) +Defined in: [packages/db/src/types.ts:111](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L111) *** @@ -144,7 +144,7 @@ Defined in: [packages/db/src/types.ts:80](https://github.com/TanStack/db/blob/ma type: TOperation; ``` -Defined in: [packages/db/src/types.ts:78](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L78) +Defined in: [packages/db/src/types.ts:109](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L109) *** @@ -154,4 +154,4 @@ Defined in: [packages/db/src/types.ts:78](https://github.com/TanStack/db/blob/ma updatedAt: Date; ``` -Defined in: [packages/db/src/types.ts:84](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L84) +Defined in: [packages/db/src/types.ts:115](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L115) diff --git a/docs/reference/interfaces/SubscribeChangesOptions.md b/docs/reference/interfaces/SubscribeChangesOptions.md index c453c9b5c..704e5308d 100644 --- a/docs/reference/interfaces/SubscribeChangesOptions.md +++ b/docs/reference/interfaces/SubscribeChangesOptions.md @@ -5,7 +5,7 @@ title: SubscribeChangesOptions # Interface: SubscribeChangesOptions -Defined in: [packages/db/src/types.ts:662](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L662) +Defined in: [packages/db/src/types.ts:701](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L701) Options for subscribing to collection changes @@ -17,7 +17,7 @@ Options for subscribing to collection changes optional includeInitialState: boolean; ``` -Defined in: [packages/db/src/types.ts:664](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L664) +Defined in: [packages/db/src/types.ts:703](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L703) Whether to include the current state as initial changes @@ -29,6 +29,6 @@ Whether to include the current state as initial changes optional whereExpression: BasicExpression; ``` -Defined in: [packages/db/src/types.ts:666](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L666) +Defined in: [packages/db/src/types.ts:705](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L705) Pre-compiled expression for filtering changes diff --git a/docs/reference/interfaces/SubscribeChangesSnapshotOptions.md b/docs/reference/interfaces/SubscribeChangesSnapshotOptions.md index b0eb573f6..60d5cbefb 100644 --- a/docs/reference/interfaces/SubscribeChangesSnapshotOptions.md +++ b/docs/reference/interfaces/SubscribeChangesSnapshotOptions.md @@ -5,7 +5,7 @@ title: SubscribeChangesSnapshotOptions # Interface: SubscribeChangesSnapshotOptions -Defined in: [packages/db/src/types.ts:669](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L669) +Defined in: [packages/db/src/types.ts:708](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L708) ## Extends @@ -19,7 +19,7 @@ Defined in: [packages/db/src/types.ts:669](https://github.com/TanStack/db/blob/m optional limit: number; ``` -Defined in: [packages/db/src/types.ts:672](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L672) +Defined in: [packages/db/src/types.ts:711](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L711) *** @@ -29,7 +29,7 @@ Defined in: [packages/db/src/types.ts:672](https://github.com/TanStack/db/blob/m optional orderBy: OrderBy; ``` -Defined in: [packages/db/src/types.ts:671](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L671) +Defined in: [packages/db/src/types.ts:710](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L710) *** @@ -39,7 +39,7 @@ Defined in: [packages/db/src/types.ts:671](https://github.com/TanStack/db/blob/m optional whereExpression: BasicExpression; ``` -Defined in: [packages/db/src/types.ts:666](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L666) +Defined in: [packages/db/src/types.ts:705](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L705) Pre-compiled expression for filtering changes diff --git a/docs/reference/interfaces/Subscription.md b/docs/reference/interfaces/Subscription.md index 5af5857aa..a021fd198 100644 --- a/docs/reference/interfaces/Subscription.md +++ b/docs/reference/interfaces/Subscription.md @@ -5,7 +5,7 @@ title: Subscription # Interface: Subscription -Defined in: [packages/db/src/types.ts:201](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L201) +Defined in: [packages/db/src/types.ts:232](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L232) Public interface for a collection subscription Used by sync implementations to track subscription lifecycle @@ -22,7 +22,7 @@ Used by sync implementations to track subscription lifecycle readonly status: SubscriptionStatus; ``` -Defined in: [packages/db/src/types.ts:203](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L203) +Defined in: [packages/db/src/types.ts:234](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L234) Current status of the subscription diff --git a/docs/reference/interfaces/SubscriptionStatusChangeEvent.md b/docs/reference/interfaces/SubscriptionStatusChangeEvent.md index ecdc7fa48..4422c2f61 100644 --- a/docs/reference/interfaces/SubscriptionStatusChangeEvent.md +++ b/docs/reference/interfaces/SubscriptionStatusChangeEvent.md @@ -5,7 +5,7 @@ title: SubscriptionStatusChangeEvent # Interface: SubscriptionStatusChangeEvent -Defined in: [packages/db/src/types.ts:162](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L162) +Defined in: [packages/db/src/types.ts:193](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L193) Event emitted when subscription status changes @@ -17,7 +17,7 @@ Event emitted when subscription status changes previousStatus: SubscriptionStatus; ``` -Defined in: [packages/db/src/types.ts:165](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L165) +Defined in: [packages/db/src/types.ts:196](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L196) *** @@ -27,7 +27,7 @@ Defined in: [packages/db/src/types.ts:165](https://github.com/TanStack/db/blob/m status: SubscriptionStatus; ``` -Defined in: [packages/db/src/types.ts:166](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L166) +Defined in: [packages/db/src/types.ts:197](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L197) *** @@ -37,7 +37,7 @@ Defined in: [packages/db/src/types.ts:166](https://github.com/TanStack/db/blob/m subscription: Subscription; ``` -Defined in: [packages/db/src/types.ts:164](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L164) +Defined in: [packages/db/src/types.ts:195](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L195) *** @@ -47,4 +47,4 @@ Defined in: [packages/db/src/types.ts:164](https://github.com/TanStack/db/blob/m type: "status:change"; ``` -Defined in: [packages/db/src/types.ts:163](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L163) +Defined in: [packages/db/src/types.ts:194](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L194) diff --git a/docs/reference/interfaces/SubscriptionStatusEvent.md b/docs/reference/interfaces/SubscriptionStatusEvent.md index e36ea1dab..a62f43aaa 100644 --- a/docs/reference/interfaces/SubscriptionStatusEvent.md +++ b/docs/reference/interfaces/SubscriptionStatusEvent.md @@ -5,7 +5,7 @@ title: SubscriptionStatusEvent # Interface: SubscriptionStatusEvent\ -Defined in: [packages/db/src/types.ts:172](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L172) +Defined in: [packages/db/src/types.ts:203](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L203) Event emitted when subscription status changes to a specific status @@ -23,7 +23,7 @@ Event emitted when subscription status changes to a specific status previousStatus: SubscriptionStatus; ``` -Defined in: [packages/db/src/types.ts:175](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L175) +Defined in: [packages/db/src/types.ts:206](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L206) *** @@ -33,7 +33,7 @@ Defined in: [packages/db/src/types.ts:175](https://github.com/TanStack/db/blob/m status: T; ``` -Defined in: [packages/db/src/types.ts:176](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L176) +Defined in: [packages/db/src/types.ts:207](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L207) *** @@ -43,7 +43,7 @@ Defined in: [packages/db/src/types.ts:176](https://github.com/TanStack/db/blob/m subscription: Subscription; ``` -Defined in: [packages/db/src/types.ts:174](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L174) +Defined in: [packages/db/src/types.ts:205](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L205) *** @@ -53,4 +53,4 @@ Defined in: [packages/db/src/types.ts:174](https://github.com/TanStack/db/blob/m type: `status:${T}`; ``` -Defined in: [packages/db/src/types.ts:173](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L173) +Defined in: [packages/db/src/types.ts:204](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L204) diff --git a/docs/reference/interfaces/SubscriptionUnsubscribedEvent.md b/docs/reference/interfaces/SubscriptionUnsubscribedEvent.md index 12e3dae67..8d3ea205c 100644 --- a/docs/reference/interfaces/SubscriptionUnsubscribedEvent.md +++ b/docs/reference/interfaces/SubscriptionUnsubscribedEvent.md @@ -5,7 +5,7 @@ title: SubscriptionUnsubscribedEvent # Interface: SubscriptionUnsubscribedEvent -Defined in: [packages/db/src/types.ts:182](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L182) +Defined in: [packages/db/src/types.ts:213](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L213) Event emitted when subscription is unsubscribed @@ -17,7 +17,7 @@ Event emitted when subscription is unsubscribed subscription: Subscription; ``` -Defined in: [packages/db/src/types.ts:184](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L184) +Defined in: [packages/db/src/types.ts:215](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L215) *** @@ -27,4 +27,4 @@ Defined in: [packages/db/src/types.ts:184](https://github.com/TanStack/db/blob/m type: "unsubscribed"; ``` -Defined in: [packages/db/src/types.ts:183](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L183) +Defined in: [packages/db/src/types.ts:214](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L214) diff --git a/docs/reference/interfaces/SyncConfig.md b/docs/reference/interfaces/SyncConfig.md index 3db6db853..633b2e55f 100644 --- a/docs/reference/interfaces/SyncConfig.md +++ b/docs/reference/interfaces/SyncConfig.md @@ -5,7 +5,7 @@ title: SyncConfig # Interface: SyncConfig\ -Defined in: [packages/db/src/types.ts:232](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L232) +Defined in: [packages/db/src/types.ts:263](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L263) ## Type Parameters @@ -25,7 +25,7 @@ Defined in: [packages/db/src/types.ts:232](https://github.com/TanStack/db/blob/m optional getSyncMetadata: () => Record; ``` -Defined in: [packages/db/src/types.ts:249](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L249) +Defined in: [packages/db/src/types.ts:280](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L280) Get the sync metadata for insert operations @@ -43,7 +43,7 @@ Record containing relation information optional rowUpdateMode: "full" | "partial"; ``` -Defined in: [packages/db/src/types.ts:258](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L258) +Defined in: [packages/db/src/types.ts:289](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L289) The row update mode used to sync to the collection. @@ -67,7 +67,7 @@ sync: (params) => | SyncConfigRes; ``` -Defined in: [packages/db/src/types.ts:236](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L236) +Defined in: [packages/db/src/types.ts:267](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L267) #### Parameters diff --git a/docs/reference/interfaces/TransactionConfig.md b/docs/reference/interfaces/TransactionConfig.md index 062f78947..542212386 100644 --- a/docs/reference/interfaces/TransactionConfig.md +++ b/docs/reference/interfaces/TransactionConfig.md @@ -5,7 +5,7 @@ title: TransactionConfig # Interface: TransactionConfig\ -Defined in: [packages/db/src/types.ts:115](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L115) +Defined in: [packages/db/src/types.ts:146](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L146) ## Type Parameters @@ -21,7 +21,7 @@ Defined in: [packages/db/src/types.ts:115](https://github.com/TanStack/db/blob/m optional autoCommit: boolean; ``` -Defined in: [packages/db/src/types.ts:119](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L119) +Defined in: [packages/db/src/types.ts:150](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L150) *** @@ -31,7 +31,7 @@ Defined in: [packages/db/src/types.ts:119](https://github.com/TanStack/db/blob/m optional id: string; ``` -Defined in: [packages/db/src/types.ts:117](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L117) +Defined in: [packages/db/src/types.ts:148](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L148) Unique identifier for the transaction @@ -43,7 +43,7 @@ Unique identifier for the transaction optional metadata: Record; ``` -Defined in: [packages/db/src/types.ts:122](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L122) +Defined in: [packages/db/src/types.ts:153](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L153) Custom metadata to associate with the transaction @@ -55,4 +55,4 @@ Custom metadata to associate with the transaction mutationFn: MutationFn; ``` -Defined in: [packages/db/src/types.ts:120](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L120) +Defined in: [packages/db/src/types.ts:151](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L151) diff --git a/docs/reference/type-aliases/ChangeListener.md b/docs/reference/type-aliases/ChangeListener.md index 7fb302ac4..d65158cb8 100644 --- a/docs/reference/type-aliases/ChangeListener.md +++ b/docs/reference/type-aliases/ChangeListener.md @@ -9,7 +9,7 @@ title: ChangeListener type ChangeListener = (changes) => void; ``` -Defined in: [packages/db/src/types.ts:717](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L717) +Defined in: [packages/db/src/types.ts:756](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L756) Function type for listening to collection changes diff --git a/docs/reference/type-aliases/ChangesPayload.md b/docs/reference/type-aliases/ChangesPayload.md index 92f1f161c..b516e1ead 100644 --- a/docs/reference/type-aliases/ChangesPayload.md +++ b/docs/reference/type-aliases/ChangesPayload.md @@ -9,7 +9,7 @@ title: ChangesPayload type ChangesPayload = ChangeMessage[]; ``` -Defined in: [packages/db/src/types.ts:620](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L620) +Defined in: [packages/db/src/types.ts:659](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L659) ## Type Parameters diff --git a/docs/reference/type-aliases/CleanupFn.md b/docs/reference/type-aliases/CleanupFn.md index 71ba43416..d2bbb31de 100644 --- a/docs/reference/type-aliases/CleanupFn.md +++ b/docs/reference/type-aliases/CleanupFn.md @@ -9,7 +9,7 @@ title: CleanupFn type CleanupFn = () => void; ``` -Defined in: [packages/db/src/types.ts:226](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L226) +Defined in: [packages/db/src/types.ts:257](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L257) ## Returns diff --git a/docs/reference/type-aliases/CollectionConfigSingleRowOption.md b/docs/reference/type-aliases/CollectionConfigSingleRowOption.md index c498f5aec..353c751fa 100644 --- a/docs/reference/type-aliases/CollectionConfigSingleRowOption.md +++ b/docs/reference/type-aliases/CollectionConfigSingleRowOption.md @@ -9,7 +9,7 @@ title: CollectionConfigSingleRowOption type CollectionConfigSingleRowOption = CollectionConfig & MaybeSingleResult; ``` -Defined in: [packages/db/src/types.ts:613](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L613) +Defined in: [packages/db/src/types.ts:652](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L652) ## Type Parameters diff --git a/docs/reference/type-aliases/CollectionStatus.md b/docs/reference/type-aliases/CollectionStatus.md index d4d9e4443..fc603cc50 100644 --- a/docs/reference/type-aliases/CollectionStatus.md +++ b/docs/reference/type-aliases/CollectionStatus.md @@ -9,7 +9,7 @@ title: CollectionStatus type CollectionStatus = "idle" | "loading" | "ready" | "error" | "cleaned-up"; ``` -Defined in: [packages/db/src/types.ts:371](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L371) +Defined in: [packages/db/src/types.ts:402](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L402) Collection status values for lifecycle management diff --git a/docs/reference/type-aliases/DeleteMutationFn.md b/docs/reference/type-aliases/DeleteMutationFn.md index ef9da1116..d80634faa 100644 --- a/docs/reference/type-aliases/DeleteMutationFn.md +++ b/docs/reference/type-aliases/DeleteMutationFn.md @@ -9,7 +9,7 @@ title: DeleteMutationFn type DeleteMutationFn = (params) => Promise; ``` -Defined in: [packages/db/src/types.ts:349](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L349) +Defined in: [packages/db/src/types.ts:380](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L380) ## Type Parameters diff --git a/docs/reference/type-aliases/DeleteMutationFnParams.md b/docs/reference/type-aliases/DeleteMutationFnParams.md index 949b12bd3..66c6c56c2 100644 --- a/docs/reference/type-aliases/DeleteMutationFnParams.md +++ b/docs/reference/type-aliases/DeleteMutationFnParams.md @@ -9,7 +9,7 @@ title: DeleteMutationFnParams type DeleteMutationFnParams = object; ``` -Defined in: [packages/db/src/types.ts:326](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L326) +Defined in: [packages/db/src/types.ts:357](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L357) ## Type Parameters @@ -33,7 +33,7 @@ Defined in: [packages/db/src/types.ts:326](https://github.com/TanStack/db/blob/m collection: Collection; ``` -Defined in: [packages/db/src/types.ts:332](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L332) +Defined in: [packages/db/src/types.ts:363](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L363) *** @@ -43,4 +43,4 @@ Defined in: [packages/db/src/types.ts:332](https://github.com/TanStack/db/blob/m transaction: TransactionWithMutations; ``` -Defined in: [packages/db/src/types.ts:331](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L331) +Defined in: [packages/db/src/types.ts:362](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L362) diff --git a/docs/reference/type-aliases/Fn.md b/docs/reference/type-aliases/Fn.md index 208899f6b..d4cc38176 100644 --- a/docs/reference/type-aliases/Fn.md +++ b/docs/reference/type-aliases/Fn.md @@ -9,7 +9,7 @@ title: Fn type Fn = (...args) => any; ``` -Defined in: [packages/db/src/types.ts:35](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L35) +Defined in: [packages/db/src/types.ts:66](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L66) Represents a utility function that can be attached to a collection diff --git a/docs/reference/type-aliases/GetResult.md b/docs/reference/type-aliases/GetResult.md index 390412903..9b1c25965 100644 --- a/docs/reference/type-aliases/GetResult.md +++ b/docs/reference/type-aliases/GetResult.md @@ -9,7 +9,7 @@ title: GetResult type GetResult = Prettify; ``` -Defined in: [packages/db/src/query/builder/types.ts:661](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L661) +Defined in: [packages/db/src/query/builder/types.ts:639](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L639) GetResult - Determines the final result type of a query diff --git a/docs/reference/type-aliases/InferResultType.md b/docs/reference/type-aliases/InferResultType.md index cb1dceaa3..abb1426de 100644 --- a/docs/reference/type-aliases/InferResultType.md +++ b/docs/reference/type-aliases/InferResultType.md @@ -9,7 +9,7 @@ title: InferResultType type InferResultType = TContext extends SingleResult ? GetResult | undefined : GetResult[]; ``` -Defined in: [packages/db/src/query/builder/types.ts:631](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L631) +Defined in: [packages/db/src/query/builder/types.ts:609](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L609) Utility type to infer the query result size (single row or an array) diff --git a/docs/reference/type-aliases/InferSchemaInput.md b/docs/reference/type-aliases/InferSchemaInput.md index 57dc50542..e209e5475 100644 --- a/docs/reference/type-aliases/InferSchemaInput.md +++ b/docs/reference/type-aliases/InferSchemaInput.md @@ -9,7 +9,7 @@ title: InferSchemaInput type InferSchemaInput = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput extends object ? StandardSchemaV1.InferInput : Record : Record; ``` -Defined in: [packages/db/src/types.ts:24](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L24) +Defined in: [packages/db/src/types.ts:55](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L55) **`Internal`** diff --git a/docs/reference/type-aliases/InferSchemaOutput.md b/docs/reference/type-aliases/InferSchemaOutput.md index 5bb8ccc91..9069db64b 100644 --- a/docs/reference/type-aliases/InferSchemaOutput.md +++ b/docs/reference/type-aliases/InferSchemaOutput.md @@ -9,7 +9,7 @@ title: InferSchemaOutput type InferSchemaOutput = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput extends object ? StandardSchemaV1.InferOutput : Record : Record; ``` -Defined in: [packages/db/src/types.ts:13](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L13) +Defined in: [packages/db/src/types.ts:44](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L44) **`Internal`** diff --git a/docs/reference/type-aliases/InputRow.md b/docs/reference/type-aliases/InputRow.md index 950b9af2f..aa24c47f9 100644 --- a/docs/reference/type-aliases/InputRow.md +++ b/docs/reference/type-aliases/InputRow.md @@ -9,6 +9,6 @@ title: InputRow type InputRow = [unknown, Record]; ``` -Defined in: [packages/db/src/types.ts:627](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L627) +Defined in: [packages/db/src/types.ts:666](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L666) An input row from a collection diff --git a/docs/reference/type-aliases/InsertMutationFn.md b/docs/reference/type-aliases/InsertMutationFn.md index 62c812d71..2f1e6b7b3 100644 --- a/docs/reference/type-aliases/InsertMutationFn.md +++ b/docs/reference/type-aliases/InsertMutationFn.md @@ -9,7 +9,7 @@ title: InsertMutationFn type InsertMutationFn = (params) => Promise; ``` -Defined in: [packages/db/src/types.ts:335](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L335) +Defined in: [packages/db/src/types.ts:366](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L366) ## Type Parameters diff --git a/docs/reference/type-aliases/InsertMutationFnParams.md b/docs/reference/type-aliases/InsertMutationFnParams.md index e17032a45..10debb9a3 100644 --- a/docs/reference/type-aliases/InsertMutationFnParams.md +++ b/docs/reference/type-aliases/InsertMutationFnParams.md @@ -9,7 +9,7 @@ title: InsertMutationFnParams type InsertMutationFnParams = object; ``` -Defined in: [packages/db/src/types.ts:318](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L318) +Defined in: [packages/db/src/types.ts:349](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L349) ## Type Parameters @@ -33,7 +33,7 @@ Defined in: [packages/db/src/types.ts:318](https://github.com/TanStack/db/blob/m collection: Collection; ``` -Defined in: [packages/db/src/types.ts:324](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L324) +Defined in: [packages/db/src/types.ts:355](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L355) *** @@ -43,4 +43,4 @@ Defined in: [packages/db/src/types.ts:324](https://github.com/TanStack/db/blob/m transaction: TransactionWithMutations; ``` -Defined in: [packages/db/src/types.ts:323](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L323) +Defined in: [packages/db/src/types.ts:354](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L354) diff --git a/docs/reference/type-aliases/KeyedNamespacedRow.md b/docs/reference/type-aliases/KeyedNamespacedRow.md index 01348ec06..68997d9f6 100644 --- a/docs/reference/type-aliases/KeyedNamespacedRow.md +++ b/docs/reference/type-aliases/KeyedNamespacedRow.md @@ -9,7 +9,7 @@ title: KeyedNamespacedRow type KeyedNamespacedRow = [unknown, NamespacedRow]; ``` -Defined in: [packages/db/src/types.ts:650](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L650) +Defined in: [packages/db/src/types.ts:689](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L689) A keyed namespaced row is a row with a key and a namespaced row This is the main representation of a row in a query pipeline diff --git a/docs/reference/type-aliases/KeyedStream.md b/docs/reference/type-aliases/KeyedStream.md index a979f48f5..0ace8b650 100644 --- a/docs/reference/type-aliases/KeyedStream.md +++ b/docs/reference/type-aliases/KeyedStream.md @@ -9,7 +9,7 @@ title: KeyedStream type KeyedStream = IStreamBuilder; ``` -Defined in: [packages/db/src/types.ts:633](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L633) +Defined in: [packages/db/src/types.ts:672](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L672) A keyed stream is a stream of rows This is used as the inputs from a collection to a query diff --git a/docs/reference/type-aliases/LiveQueryCollectionUtils.md b/docs/reference/type-aliases/LiveQueryCollectionUtils.md index f9dc2690d..30a506df6 100644 --- a/docs/reference/type-aliases/LiveQueryCollectionUtils.md +++ b/docs/reference/type-aliases/LiveQueryCollectionUtils.md @@ -9,7 +9,7 @@ title: LiveQueryCollectionUtils type LiveQueryCollectionUtils = UtilsRecord & object; ``` -Defined in: [packages/db/src/query/live/collection-config-builder.ts:36](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/collection-config-builder.ts#L36) +Defined in: [packages/db/src/query/live/collection-config-builder.ts:37](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/collection-config-builder.ts#L37) ## Type Declaration diff --git a/docs/reference/type-aliases/LoadSubsetFn.md b/docs/reference/type-aliases/LoadSubsetFn.md index 672b10849..d35f81e4b 100644 --- a/docs/reference/type-aliases/LoadSubsetFn.md +++ b/docs/reference/type-aliases/LoadSubsetFn.md @@ -9,7 +9,7 @@ title: LoadSubsetFn type LoadSubsetFn = (options) => true | Promise; ``` -Defined in: [packages/db/src/types.ts:224](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L224) +Defined in: [packages/db/src/types.ts:255](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L255) ## Parameters diff --git a/docs/reference/type-aliases/LoadSubsetOptions.md b/docs/reference/type-aliases/LoadSubsetOptions.md index 68130510e..91d48ed11 100644 --- a/docs/reference/type-aliases/LoadSubsetOptions.md +++ b/docs/reference/type-aliases/LoadSubsetOptions.md @@ -9,7 +9,7 @@ title: LoadSubsetOptions type LoadSubsetOptions = object; ``` -Defined in: [packages/db/src/types.ts:206](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L206) +Defined in: [packages/db/src/types.ts:237](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L237) ## Properties @@ -19,7 +19,7 @@ Defined in: [packages/db/src/types.ts:206](https://github.com/TanStack/db/blob/m optional limit: number; ``` -Defined in: [packages/db/src/types.ts:212](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L212) +Defined in: [packages/db/src/types.ts:243](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L243) The limit of the data to load @@ -31,7 +31,7 @@ The limit of the data to load optional orderBy: OrderBy; ``` -Defined in: [packages/db/src/types.ts:210](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L210) +Defined in: [packages/db/src/types.ts:241](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L241) The order by clause to sort the data @@ -43,7 +43,7 @@ The order by clause to sort the data optional subscription: Subscription; ``` -Defined in: [packages/db/src/types.ts:221](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L221) +Defined in: [packages/db/src/types.ts:252](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L252) The subscription that triggered the load. Advanced sync implementations can use this for: @@ -63,6 +63,6 @@ Available when called from CollectionSubscription, may be undefined for direct c optional where: BasicExpression; ``` -Defined in: [packages/db/src/types.ts:208](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L208) +Defined in: [packages/db/src/types.ts:239](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L239) The where expression to filter the data diff --git a/docs/reference/type-aliases/MaybeSingleResult.md b/docs/reference/type-aliases/MaybeSingleResult.md index 7760f69d5..ca1d94fb3 100644 --- a/docs/reference/type-aliases/MaybeSingleResult.md +++ b/docs/reference/type-aliases/MaybeSingleResult.md @@ -9,7 +9,7 @@ title: MaybeSingleResult type MaybeSingleResult = object; ``` -Defined in: [packages/db/src/types.ts:605](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L605) +Defined in: [packages/db/src/types.ts:644](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L644) ## Properties @@ -19,6 +19,6 @@ Defined in: [packages/db/src/types.ts:605](https://github.com/TanStack/db/blob/m optional singleResult: true; ``` -Defined in: [packages/db/src/types.ts:609](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L609) +Defined in: [packages/db/src/types.ts:648](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L648) If enabled the collection will return a single object instead of an array diff --git a/docs/reference/type-aliases/MutationFn.md b/docs/reference/type-aliases/MutationFn.md index 3e5d48e9e..146de19e0 100644 --- a/docs/reference/type-aliases/MutationFn.md +++ b/docs/reference/type-aliases/MutationFn.md @@ -9,7 +9,7 @@ title: MutationFn type MutationFn = (params) => Promise; ``` -Defined in: [packages/db/src/types.ts:95](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L95) +Defined in: [packages/db/src/types.ts:126](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L126) ## Type Parameters diff --git a/docs/reference/type-aliases/MutationFnParams.md b/docs/reference/type-aliases/MutationFnParams.md index ed423fdbf..e7b51681f 100644 --- a/docs/reference/type-aliases/MutationFnParams.md +++ b/docs/reference/type-aliases/MutationFnParams.md @@ -9,7 +9,7 @@ title: MutationFnParams type MutationFnParams = object; ``` -Defined in: [packages/db/src/types.ts:91](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L91) +Defined in: [packages/db/src/types.ts:122](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L122) Configuration options for creating a new transaction @@ -27,4 +27,4 @@ Configuration options for creating a new transaction transaction: TransactionWithMutations; ``` -Defined in: [packages/db/src/types.ts:92](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L92) +Defined in: [packages/db/src/types.ts:123](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L123) diff --git a/docs/reference/type-aliases/NamespacedAndKeyedStream.md b/docs/reference/type-aliases/NamespacedAndKeyedStream.md index c6aa2fb4d..16c58168b 100644 --- a/docs/reference/type-aliases/NamespacedAndKeyedStream.md +++ b/docs/reference/type-aliases/NamespacedAndKeyedStream.md @@ -9,7 +9,7 @@ title: NamespacedAndKeyedStream type NamespacedAndKeyedStream = IStreamBuilder; ``` -Defined in: [packages/db/src/types.ts:657](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L657) +Defined in: [packages/db/src/types.ts:696](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L696) A namespaced and keyed stream is a stream of rows This is used throughout a query pipeline and as the output from a query without diff --git a/docs/reference/type-aliases/NamespacedRow.md b/docs/reference/type-aliases/NamespacedRow.md index 6dceb7967..1d8326a35 100644 --- a/docs/reference/type-aliases/NamespacedRow.md +++ b/docs/reference/type-aliases/NamespacedRow.md @@ -9,6 +9,6 @@ title: NamespacedRow type NamespacedRow = Record>; ``` -Defined in: [packages/db/src/types.ts:644](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L644) +Defined in: [packages/db/src/types.ts:683](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L683) A namespaced row is a row withing a pipeline that had each table wrapped in its alias diff --git a/docs/reference/type-aliases/NonEmptyArray.md b/docs/reference/type-aliases/NonEmptyArray.md index 85f886519..563202223 100644 --- a/docs/reference/type-aliases/NonEmptyArray.md +++ b/docs/reference/type-aliases/NonEmptyArray.md @@ -9,7 +9,7 @@ title: NonEmptyArray type NonEmptyArray = [T, ...T[]]; ``` -Defined in: [packages/db/src/types.ts:102](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L102) +Defined in: [packages/db/src/types.ts:133](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L133) Represents a non-empty array (at least one element) diff --git a/docs/reference/type-aliases/NonSingleResult.md b/docs/reference/type-aliases/NonSingleResult.md index 18472c3c5..cfba546f5 100644 --- a/docs/reference/type-aliases/NonSingleResult.md +++ b/docs/reference/type-aliases/NonSingleResult.md @@ -9,7 +9,7 @@ title: NonSingleResult type NonSingleResult = object; ``` -Defined in: [packages/db/src/types.ts:601](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L601) +Defined in: [packages/db/src/types.ts:640](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L640) ## Properties @@ -19,4 +19,4 @@ Defined in: [packages/db/src/types.ts:601](https://github.com/TanStack/db/blob/m optional singleResult: never; ``` -Defined in: [packages/db/src/types.ts:602](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L602) +Defined in: [packages/db/src/types.ts:641](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L641) diff --git a/docs/reference/type-aliases/OperationType.md b/docs/reference/type-aliases/OperationType.md index 43893ca58..a8c37d55a 100644 --- a/docs/reference/type-aliases/OperationType.md +++ b/docs/reference/type-aliases/OperationType.md @@ -9,4 +9,4 @@ title: OperationType type OperationType = "insert" | "update" | "delete"; ``` -Defined in: [packages/db/src/types.ts:152](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L152) +Defined in: [packages/db/src/types.ts:183](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L183) diff --git a/docs/reference/type-aliases/Ref.md b/docs/reference/type-aliases/Ref.md index 1340dc750..3e54d7780 100644 --- a/docs/reference/type-aliases/Ref.md +++ b/docs/reference/type-aliases/Ref.md @@ -9,7 +9,7 @@ title: Ref type Ref = { [K in keyof T]: IsNonExactOptional extends true ? IsNonExactNullable extends true ? IsPlainObject> extends true ? Ref> | undefined : RefLeaf> | undefined : IsPlainObject> extends true ? Ref> | undefined : RefLeaf> | undefined : IsNonExactNullable extends true ? IsPlainObject> extends true ? Ref> | null : RefLeaf> | null : IsPlainObject extends true ? Ref : RefLeaf } & RefLeaf; ``` -Defined in: [packages/db/src/query/builder/types.ts:493](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L493) +Defined in: [packages/db/src/query/builder/types.ts:471](https://github.com/TanStack/db/blob/main/packages/db/src/query/builder/types.ts#L471) Ref - The user-facing ref interface for the query builder diff --git a/docs/reference/type-aliases/ResolveTransactionChanges.md b/docs/reference/type-aliases/ResolveTransactionChanges.md index cbf36e6f8..d8349caab 100644 --- a/docs/reference/type-aliases/ResolveTransactionChanges.md +++ b/docs/reference/type-aliases/ResolveTransactionChanges.md @@ -9,7 +9,7 @@ title: ResolveTransactionChanges type ResolveTransactionChanges = TOperation extends "delete" ? T : Partial; ``` -Defined in: [packages/db/src/types.ts:48](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L48) +Defined in: [packages/db/src/types.ts:79](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L79) ## Type Parameters diff --git a/docs/reference/type-aliases/ResultStream.md b/docs/reference/type-aliases/ResultStream.md index f61b629ac..2eafdb685 100644 --- a/docs/reference/type-aliases/ResultStream.md +++ b/docs/reference/type-aliases/ResultStream.md @@ -9,7 +9,7 @@ title: ResultStream type ResultStream = IStreamBuilder<[unknown, [any, string | undefined]]>; ``` -Defined in: [packages/db/src/types.ts:639](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L639) +Defined in: [packages/db/src/types.ts:678](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L678) Result stream type representing the output of compiled queries Always returns [key, [result, orderByIndex]] where orderByIndex is undefined for unordered queries diff --git a/docs/reference/type-aliases/Row.md b/docs/reference/type-aliases/Row.md index 4473d7712..837e903e9 100644 --- a/docs/reference/type-aliases/Row.md +++ b/docs/reference/type-aliases/Row.md @@ -9,7 +9,7 @@ title: Row type Row = Record>; ``` -Defined in: [packages/db/src/types.ts:150](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L150) +Defined in: [packages/db/src/types.ts:181](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L181) ## Type Parameters diff --git a/docs/reference/type-aliases/SingleResult.md b/docs/reference/type-aliases/SingleResult.md index 5d7a47e42..75981ce55 100644 --- a/docs/reference/type-aliases/SingleResult.md +++ b/docs/reference/type-aliases/SingleResult.md @@ -9,7 +9,7 @@ title: SingleResult type SingleResult = object; ``` -Defined in: [packages/db/src/types.ts:597](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L597) +Defined in: [packages/db/src/types.ts:636](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L636) ## Properties @@ -19,4 +19,4 @@ Defined in: [packages/db/src/types.ts:597](https://github.com/TanStack/db/blob/m singleResult: true; ``` -Defined in: [packages/db/src/types.ts:598](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L598) +Defined in: [packages/db/src/types.ts:637](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L637) diff --git a/docs/reference/type-aliases/StandardSchema.md b/docs/reference/type-aliases/StandardSchema.md index fcdf7607c..34417b624 100644 --- a/docs/reference/type-aliases/StandardSchema.md +++ b/docs/reference/type-aliases/StandardSchema.md @@ -9,7 +9,7 @@ title: StandardSchema type StandardSchema = StandardSchemaV1 & object; ``` -Defined in: [packages/db/src/types.ts:283](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L283) +Defined in: [packages/db/src/types.ts:314](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L314) The Standard Schema interface. This follows the standard-schema specification: https://github.com/standard-schema/standard-schema diff --git a/docs/reference/type-aliases/StandardSchemaAlias.md b/docs/reference/type-aliases/StandardSchemaAlias.md index 7551f9bdb..e12d92243 100644 --- a/docs/reference/type-aliases/StandardSchemaAlias.md +++ b/docs/reference/type-aliases/StandardSchemaAlias.md @@ -9,7 +9,7 @@ title: StandardSchemaAlias type StandardSchemaAlias = StandardSchema; ``` -Defined in: [packages/db/src/types.ts:295](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L295) +Defined in: [packages/db/src/types.ts:326](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L326) Type alias for StandardSchema diff --git a/docs/reference/type-aliases/StringCollationConfig.md b/docs/reference/type-aliases/StringCollationConfig.md new file mode 100644 index 000000000..9ca2c7b15 --- /dev/null +++ b/docs/reference/type-aliases/StringCollationConfig.md @@ -0,0 +1,28 @@ +--- +id: StringCollationConfig +title: StringCollationConfig +--- + +# Type Alias: StringCollationConfig + +```ts +type StringCollationConfig = + | { + stringSort?: "lexical"; +} + | { + locale?: string; + localeOptions?: object; + stringSort?: "locale"; +}; +``` + +Defined in: [packages/db/src/types.ts:29](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L29) + +StringSortOpts - Options for string sorting behavior + +This discriminated union allows for two types of string sorting: +- **Lexical**: Simple character-by-character comparison (default) +- **Locale**: Locale-aware sorting with optional customization + +The union ensures that locale options are only available when locale sorting is selected. diff --git a/docs/reference/type-aliases/SubscriptionEvents.md b/docs/reference/type-aliases/SubscriptionEvents.md index 224829d18..5bfbad031 100644 --- a/docs/reference/type-aliases/SubscriptionEvents.md +++ b/docs/reference/type-aliases/SubscriptionEvents.md @@ -9,7 +9,7 @@ title: SubscriptionEvents type SubscriptionEvents = object; ``` -Defined in: [packages/db/src/types.ts:190](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L190) +Defined in: [packages/db/src/types.ts:221](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L221) All subscription events @@ -21,7 +21,7 @@ All subscription events status:change: SubscriptionStatusChangeEvent; ``` -Defined in: [packages/db/src/types.ts:191](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L191) +Defined in: [packages/db/src/types.ts:222](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L222) *** @@ -31,7 +31,7 @@ Defined in: [packages/db/src/types.ts:191](https://github.com/TanStack/db/blob/m status:loadingSubset: SubscriptionStatusEvent<"loadingSubset">; ``` -Defined in: [packages/db/src/types.ts:193](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L193) +Defined in: [packages/db/src/types.ts:224](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L224) *** @@ -41,7 +41,7 @@ Defined in: [packages/db/src/types.ts:193](https://github.com/TanStack/db/blob/m status:ready: SubscriptionStatusEvent<"ready">; ``` -Defined in: [packages/db/src/types.ts:192](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L192) +Defined in: [packages/db/src/types.ts:223](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L223) *** @@ -51,4 +51,4 @@ Defined in: [packages/db/src/types.ts:192](https://github.com/TanStack/db/blob/m unsubscribed: SubscriptionUnsubscribedEvent; ``` -Defined in: [packages/db/src/types.ts:194](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L194) +Defined in: [packages/db/src/types.ts:225](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L225) diff --git a/docs/reference/type-aliases/SubscriptionStatus.md b/docs/reference/type-aliases/SubscriptionStatus.md index 179b3e5dc..0ec757e27 100644 --- a/docs/reference/type-aliases/SubscriptionStatus.md +++ b/docs/reference/type-aliases/SubscriptionStatus.md @@ -9,6 +9,6 @@ title: SubscriptionStatus type SubscriptionStatus = "ready" | "loadingSubset"; ``` -Defined in: [packages/db/src/types.ts:157](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L157) +Defined in: [packages/db/src/types.ts:188](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L188) Subscription status values diff --git a/docs/reference/type-aliases/SyncConfigRes.md b/docs/reference/type-aliases/SyncConfigRes.md index 87c58dbce..2cf63c380 100644 --- a/docs/reference/type-aliases/SyncConfigRes.md +++ b/docs/reference/type-aliases/SyncConfigRes.md @@ -9,7 +9,7 @@ title: SyncConfigRes type SyncConfigRes = object; ``` -Defined in: [packages/db/src/types.ts:228](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L228) +Defined in: [packages/db/src/types.ts:259](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L259) ## Properties @@ -19,7 +19,7 @@ Defined in: [packages/db/src/types.ts:228](https://github.com/TanStack/db/blob/m optional cleanup: CleanupFn; ``` -Defined in: [packages/db/src/types.ts:229](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L229) +Defined in: [packages/db/src/types.ts:260](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L260) *** @@ -29,4 +29,4 @@ Defined in: [packages/db/src/types.ts:229](https://github.com/TanStack/db/blob/m optional loadSubset: LoadSubsetFn; ``` -Defined in: [packages/db/src/types.ts:230](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L230) +Defined in: [packages/db/src/types.ts:261](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L261) diff --git a/docs/reference/type-aliases/SyncMode.md b/docs/reference/type-aliases/SyncMode.md index 1f9614a96..4715f1866 100644 --- a/docs/reference/type-aliases/SyncMode.md +++ b/docs/reference/type-aliases/SyncMode.md @@ -9,4 +9,4 @@ title: SyncMode type SyncMode = "eager" | "on-demand"; ``` -Defined in: [packages/db/src/types.ts:383](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L383) +Defined in: [packages/db/src/types.ts:414](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L414) diff --git a/docs/reference/type-aliases/TransactionState.md b/docs/reference/type-aliases/TransactionState.md index 9fb9ed6b2..7f3c41897 100644 --- a/docs/reference/type-aliases/TransactionState.md +++ b/docs/reference/type-aliases/TransactionState.md @@ -9,4 +9,4 @@ title: TransactionState type TransactionState = "pending" | "persisting" | "completed" | "failed"; ``` -Defined in: [packages/db/src/types.ts:30](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L30) +Defined in: [packages/db/src/types.ts:61](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L61) diff --git a/docs/reference/type-aliases/TransactionWithMutations.md b/docs/reference/type-aliases/TransactionWithMutations.md index f442f136d..adea0ae5d 100644 --- a/docs/reference/type-aliases/TransactionWithMutations.md +++ b/docs/reference/type-aliases/TransactionWithMutations.md @@ -9,7 +9,7 @@ title: TransactionWithMutations type TransactionWithMutations = Transaction & object; ``` -Defined in: [packages/db/src/types.ts:108](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L108) +Defined in: [packages/db/src/types.ts:139](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L139) Utility type for a Transaction with at least one mutation This is used internally by the Transaction.commit method diff --git a/docs/reference/type-aliases/UpdateMutationFn.md b/docs/reference/type-aliases/UpdateMutationFn.md index f58d1c6f4..8fa98ca8d 100644 --- a/docs/reference/type-aliases/UpdateMutationFn.md +++ b/docs/reference/type-aliases/UpdateMutationFn.md @@ -9,7 +9,7 @@ title: UpdateMutationFn type UpdateMutationFn = (params) => Promise; ``` -Defined in: [packages/db/src/types.ts:342](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L342) +Defined in: [packages/db/src/types.ts:373](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L373) ## Type Parameters diff --git a/docs/reference/type-aliases/UpdateMutationFnParams.md b/docs/reference/type-aliases/UpdateMutationFnParams.md index 9fafe2e43..1f7513ed2 100644 --- a/docs/reference/type-aliases/UpdateMutationFnParams.md +++ b/docs/reference/type-aliases/UpdateMutationFnParams.md @@ -9,7 +9,7 @@ title: UpdateMutationFnParams type UpdateMutationFnParams = object; ``` -Defined in: [packages/db/src/types.ts:309](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L309) +Defined in: [packages/db/src/types.ts:340](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L340) ## Type Parameters @@ -33,7 +33,7 @@ Defined in: [packages/db/src/types.ts:309](https://github.com/TanStack/db/blob/m collection: Collection; ``` -Defined in: [packages/db/src/types.ts:315](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L315) +Defined in: [packages/db/src/types.ts:346](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L346) *** @@ -43,4 +43,4 @@ Defined in: [packages/db/src/types.ts:315](https://github.com/TanStack/db/blob/m transaction: TransactionWithMutations; ``` -Defined in: [packages/db/src/types.ts:314](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L314) +Defined in: [packages/db/src/types.ts:345](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L345) diff --git a/docs/reference/type-aliases/UtilsRecord.md b/docs/reference/type-aliases/UtilsRecord.md index 9b694c349..0d4e8a3ef 100644 --- a/docs/reference/type-aliases/UtilsRecord.md +++ b/docs/reference/type-aliases/UtilsRecord.md @@ -9,6 +9,6 @@ title: UtilsRecord type UtilsRecord = Record; ``` -Defined in: [packages/db/src/types.ts:40](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L40) +Defined in: [packages/db/src/types.ts:71](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L71) A record of utility functions that can be attached to a collection diff --git a/docs/reference/type-aliases/WritableDeep.md b/docs/reference/type-aliases/WritableDeep.md index 342aea753..6acc5731e 100644 --- a/docs/reference/type-aliases/WritableDeep.md +++ b/docs/reference/type-aliases/WritableDeep.md @@ -9,7 +9,7 @@ title: WritableDeep type WritableDeep = T extends BuiltIns ? T : T extends (...arguments_) => unknown ? object extends WritableObjectDeep ? T : HasMultipleCallSignatures extends true ? T : (...arguments_) => ReturnType & WritableObjectDeep : T extends ReadonlyMap ? WritableMapDeep : T extends ReadonlySet ? WritableSetDeep : T extends ReadonlyArray ? WritableArrayDeep : T extends object ? WritableObjectDeep : unknown; ``` -Defined in: [packages/db/src/types.ts:777](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L777) +Defined in: [packages/db/src/types.ts:816](https://github.com/TanStack/db/blob/main/packages/db/src/types.ts#L816) ## Type Parameters diff --git a/packages/db/src/collection/change-events.ts b/packages/db/src/collection/change-events.ts index 10c05ae71..a6d5e0c0a 100644 --- a/packages/db/src/collection/change-events.ts +++ b/packages/db/src/collection/change-events.ts @@ -9,27 +9,17 @@ import { } from "../utils/index-optimization.js" import { ensureIndexForField } from "../indexes/auto-index.js" import { makeComparator } from "../utils/comparison.js" +import { buildCompareOptions } from "../query/compiler/order-by" import type { ChangeMessage, + CollectionLike, CurrentStateAsChangesOptions, SubscribeChangesOptions, } from "../types" -import type { Collection, CollectionImpl } from "./index.js" +import type { CollectionImpl } from "./index.js" import type { SingleRowRefProxy } from "../query/builder/ref-proxy" import type { BasicExpression, OrderBy } from "../query/ir.js" -/** - * Interface for a collection-like object that provides the necessary methods - * for the change events system to work - */ -export interface CollectionLike< - T extends object = Record, - TKey extends string | number = string | number, -> extends Pick< - Collection, - `get` | `has` | `entries` | `indexes` | `id` - > {} - /** * Returns the current state of the collection as an array of changes * @param collection - The collection to get changes from @@ -140,7 +130,7 @@ export function currentStateAsChanges< // Try to optimize the query using indexes const optimizationResult = optimizeExpressionWithIndexes( expression, - collection.indexes + collection ) if (optimizationResult.canOptimize) { @@ -326,21 +316,18 @@ function getOrderedKeys( if (orderByExpression.type === `ref`) { const propRef = orderByExpression const fieldPath = propRef.path + const compareOpts = buildCompareOptions(clause, collection) // Ensure index exists for this field ensureIndexForField( fieldPath[0]!, fieldPath, collection as CollectionImpl, - clause.compareOptions + compareOpts ) // Find the index - const index = findIndexForField( - collection.indexes, - fieldPath, - clause.compareOptions - ) + const index = findIndexForField(collection, fieldPath, compareOpts) if (index && index.supports(`gt`)) { // Use index optimization diff --git a/packages/db/src/collection/index.ts b/packages/db/src/collection/index.ts index 5a4ab3c07..0bbed191d 100644 --- a/packages/db/src/collection/index.ts +++ b/packages/db/src/collection/index.ts @@ -27,6 +27,7 @@ import type { NonSingleResult, OperationConfig, SingleResult, + StringCollationConfig, SubscribeChangesOptions, Transaction as TransactionType, UtilsRecord, @@ -230,6 +231,8 @@ export class CollectionImpl< // and for debugging public _state: CollectionStateManager + private comparisonOpts: StringCollationConfig + /** * Creates a new Collection instance * @@ -267,6 +270,8 @@ export class CollectionImpl< this._state = new CollectionStateManager(config) this._sync = new CollectionSyncManager(config, this.id) + this.comparisonOpts = buildCompareOptionsFromConfig(config) + this._changes.setDeps({ collection: this, // Required for passing to CollectionSubscription lifecycle: this._lifecycle, @@ -508,6 +513,11 @@ export class CollectionImpl< return this._mutations.validateData(data, type, key) } + get compareOptions(): StringCollationConfig { + // return a copy such that no one can mutate the internal comparison object + return { ...this.comparisonOpts } + } + /** * Inserts one or more items into the collection * @param items - Single item or array of items to insert @@ -848,3 +858,21 @@ export class CollectionImpl< return Promise.resolve() } } + +function buildCompareOptionsFromConfig( + config: CollectionConfig +): StringCollationConfig { + if (config.defaultStringCollation) { + const options = config.defaultStringCollation + return { + stringSort: options.stringSort ?? `locale`, + locale: options.stringSort === `locale` ? options.locale : undefined, + localeOptions: + options.stringSort === `locale` ? options.localeOptions : undefined, + } + } else { + return { + stringSort: `locale`, + } + } +} diff --git a/packages/db/src/indexes/auto-index.ts b/packages/db/src/indexes/auto-index.ts index 56c352b51..491053af0 100644 --- a/packages/db/src/indexes/auto-index.ts +++ b/packages/db/src/indexes/auto-index.ts @@ -24,18 +24,22 @@ export function ensureIndexForField< fieldName: string, fieldPath: Array, collection: CollectionImpl, - compareOptions: CompareOptions = DEFAULT_COMPARE_OPTIONS, + compareOptions?: CompareOptions, compareFn?: (a: any, b: any) => number ) { if (!shouldAutoIndex(collection)) { return } + const compareOpts = compareOptions ?? { + ...DEFAULT_COMPARE_OPTIONS, + ...collection.compareOptions, + } + // Check if we already have an index for this field const existingIndex = Array.from(collection.indexes.values()).find( (index) => - index.matchesField(fieldPath) && - index.matchesCompareOptions(compareOptions) + index.matchesField(fieldPath) && index.matchesCompareOptions(compareOpts) ) if (existingIndex) { @@ -57,7 +61,7 @@ export function ensureIndexForField< { name: `auto:${fieldPath.join(`.`)}`, indexType: BTreeIndex, - options: compareFn ? { compareFn, compareOptions } : {}, + options: compareFn ? { compareFn, compareOptions: compareOpts } : {}, } ) } catch (error) { diff --git a/packages/db/src/query/builder/index.ts b/packages/db/src/query/builder/index.ts index f6b52e5ed..bd8b95178 100644 --- a/packages/db/src/query/builder/index.ts +++ b/packages/db/src/query/builder/index.ts @@ -469,11 +469,11 @@ export class BaseQueryBuilder { const opts: CompareOptions = typeof options === `string` - ? { direction: options, nulls: `first`, stringSort: `locale` } + ? { direction: options, nulls: `first` } : { direction: options.direction ?? `asc`, nulls: options.nulls ?? `first`, - stringSort: options.stringSort ?? `locale`, + stringSort: options.stringSort, locale: options.stringSort === `locale` ? options.locale : undefined, localeOptions: diff --git a/packages/db/src/query/builder/types.ts b/packages/db/src/query/builder/types.ts index de01f4be5..2af33b14f 100644 --- a/packages/db/src/query/builder/types.ts +++ b/packages/db/src/query/builder/types.ts @@ -1,5 +1,5 @@ import type { CollectionImpl } from "../../collection/index.js" -import type { SingleResult } from "../../types.js" +import type { SingleResult, StringCollationConfig } from "../../types.js" import type { Aggregate, BasicExpression, @@ -303,26 +303,7 @@ export type OrderByCallback = ( export type OrderByOptions = { direction?: OrderByDirection nulls?: `first` | `last` -} & StringSortOpts - -/** - * StringSortOpts - Options for string sorting behavior - * - * This discriminated union allows for two types of string sorting: - * - **Lexical**: Simple character-by-character comparison (default) - * - **Locale**: Locale-aware sorting with optional customization - * - * The union ensures that locale options are only available when locale sorting is selected. - */ -export type StringSortOpts = - | { - stringSort?: `lexical` - } - | { - stringSort?: `locale` - locale?: string - localeOptions?: object - } +} & StringCollationConfig /** * CompareOptions - Final resolved options for comparison operations @@ -331,12 +312,9 @@ export type StringSortOpts = * to their concrete values. Unlike OrderByOptions, all fields are required * since defaults have been applied. */ -export type CompareOptions = { +export type CompareOptions = StringCollationConfig & { direction: OrderByDirection nulls: `first` | `last` - stringSort: `lexical` | `locale` - locale?: string - localeOptions?: object } /** diff --git a/packages/db/src/query/compiler/order-by.ts b/packages/db/src/query/compiler/order-by.ts index 6156ae2ce..355f922bf 100644 --- a/packages/db/src/query/compiler/order-by.ts +++ b/packages/db/src/query/compiler/order-by.ts @@ -5,10 +5,15 @@ import { ensureIndexForField } from "../../indexes/auto-index.js" import { findIndexForField } from "../../utils/index-optimization.js" import { compileExpression } from "./evaluators.js" import { replaceAggregatesByRefs } from "./group-by.js" +import type { CompareOptions } from "../builder/types.js" import type { WindowOptions } from "./types.js" import type { CompiledSingleRowExpression } from "./evaluators.js" import type { OrderBy, OrderByClause, QueryIR, Select } from "../ir.js" -import type { NamespacedAndKeyedStream, NamespacedRow } from "../../types.js" +import type { + CollectionLike, + NamespacedAndKeyedStream, + NamespacedRow, +} from "../../types.js" import type { IStreamBuilder, KeyValue } from "@tanstack/db-ivm" import type { IndexInterface } from "../../indexes/base-index.js" import type { Collection } from "../../collection/index.js" @@ -50,9 +55,10 @@ export function processOrderBy( selectClause, `__select_results` ) + return { compiledExpression: compileExpression(clauseWithoutAggregates), - compareOptions: clause.compareOptions, + compareOptions: buildCompareOptions(clause, collection), } }) @@ -87,7 +93,7 @@ export function processOrderBy( const arrayA = a as Array const arrayB = b as Array for (let i = 0; i < orderByClause.length; i++) { - const clause = orderByClause[i]! + const clause = compiledOrderBy[i]! const compareFn = makeComparator(clause.compareOptions) const result = compareFn(arrayA[i], arrayB[i]) if (result !== 0) { @@ -99,7 +105,7 @@ export function processOrderBy( // Single property comparison if (orderByClause.length === 1) { - const clause = orderByClause[0]! + const clause = compiledOrderBy[0]! const compareFn = makeComparator(clause.compareOptions) return compareFn(a, b) } @@ -127,12 +133,13 @@ export function processOrderBy( const followRefCollection = followRefResult.collection const fieldName = followRefResult.path[0] + const compareOpts = buildCompareOptions(clause, followRefCollection) if (fieldName) { ensureIndexForField( fieldName, followRefResult.path, followRefCollection, - clause.compareOptions, + compareOpts, compare ) } @@ -153,9 +160,9 @@ export function processOrderBy( const index: IndexInterface | undefined = findIndexForField( - followRefCollection.indexes, + followRefCollection, followRefResult.path, - clause.compareOptions + compareOpts ) if (index && index.supports(`gt`)) { @@ -217,3 +224,22 @@ export function processOrderBy( // orderByWithFractionalIndex returns [key, [value, index]] - we keep this format ) } + +/** + * Builds a comparison configuration object that uses the values provided in the orderBy clause. + * If no string sort configuration is provided it defaults to the collection's string sort configuration. + */ +export function buildCompareOptions( + clause: OrderByClause, + collection: CollectionLike +): CompareOptions { + if (clause.compareOptions.stringSort !== undefined) { + return clause.compareOptions + } + + return { + ...collection.compareOptions, + direction: clause.compareOptions.direction, + nulls: clause.compareOptions.nulls, + } +} diff --git a/packages/db/src/query/live/collection-config-builder.ts b/packages/db/src/query/live/collection-config-builder.ts index eef3241dc..2757f9630 100644 --- a/packages/db/src/query/live/collection-config-builder.ts +++ b/packages/db/src/query/live/collection-config-builder.ts @@ -19,6 +19,7 @@ import type { CollectionConfigSingleRowOption, KeyedStream, ResultStream, + StringCollationConfig, SyncConfig, UtilsRecord, } from "../../types.js" @@ -81,6 +82,7 @@ export class CollectionConfigBuilder< private readonly orderByIndices = new WeakMap() private readonly compare?: (val1: TResult, val2: TResult) => number + private readonly compareOptions?: StringCollationConfig private isGraphRunning = false private runCount = 0 @@ -168,6 +170,11 @@ export class CollectionConfigBuilder< this.compare = createOrderByComparator(this.orderByIndices) } + // Use explicitly provided compareOptions if available, otherwise inherit from FROM collection + this.compareOptions = + this.config.defaultStringCollation ?? + extractCollectionFromSource(this.query).compareOptions + // Compile the base pipeline once initially // This is done to ensure that any errors are thrown immediately and synchronously this.compileBasePipeline() @@ -183,6 +190,7 @@ export class CollectionConfigBuilder< ((item) => this.resultKeys.get(item) as string | number), sync: this.getSyncConfig(), compare: this.compare, + defaultStringCollation: this.compareOptions, gcTime: this.config.gcTime || 5000, // 5 seconds by default for live queries schema: this.config.schema, onInsert: this.config.onInsert, @@ -926,6 +934,25 @@ function extractCollectionsFromQuery( return collections } +/** + * Helper function to extract the collection that is referenced in the query's FROM clause. + * The FROM clause may refer directly to a collection or indirectly to a subquery. + */ +function extractCollectionFromSource(query: any): Collection { + const from = query.from + + if (from.type === `collectionRef`) { + return from.collection + } else if (from.type === `queryRef`) { + // Recursively extract from subquery + return extractCollectionFromSource(from.query) + } + + throw new Error( + `Failed to extract collection. Invalid FROM clause: ${JSON.stringify(query)}` + ) +} + /** * Extracts all aliases used for each collection across the entire query tree. * diff --git a/packages/db/src/query/live/types.ts b/packages/db/src/query/live/types.ts index 3149b3a66..74c84a05f 100644 --- a/packages/db/src/query/live/types.ts +++ b/packages/db/src/query/live/types.ts @@ -1,5 +1,9 @@ import type { D2, RootStreamBuilder } from "@tanstack/db-ivm" -import type { CollectionConfig, ResultStream } from "../../types.js" +import type { + CollectionConfig, + ResultStream, + StringCollationConfig, +} from "../../types.js" import type { InitialQueryBuilder, QueryBuilder } from "../builder/index.js" import type { Context, GetResult } from "../builder/types.js" @@ -95,4 +99,10 @@ export interface LiveQueryCollectionConfig< * If enabled the collection will return a single object instead of an array */ singleResult?: true + + /** + * Optional compare options for string sorting. + * If provided, these will be used instead of inheriting from the FROM collection. + */ + defaultStringCollation?: StringCollationConfig } diff --git a/packages/db/src/types.ts b/packages/db/src/types.ts index 73c1fc4fe..2f9d2fb40 100644 --- a/packages/db/src/types.ts +++ b/packages/db/src/types.ts @@ -5,6 +5,37 @@ import type { Transaction } from "./transactions" import type { BasicExpression, OrderBy } from "./query/ir.js" import type { EventEmitter } from "./event-emitter.js" +/** + * Interface for a collection-like object that provides the necessary methods + * for the change events system to work + */ +export interface CollectionLike< + T extends object = Record, + TKey extends string | number = string | number, +> extends Pick< + Collection, + `get` | `has` | `entries` | `indexes` | `id` | `compareOptions` + > {} + +/** + * StringSortOpts - Options for string sorting behavior + * + * This discriminated union allows for two types of string sorting: + * - **Lexical**: Simple character-by-character comparison (default) + * - **Locale**: Locale-aware sorting with optional customization + * + * The union ensures that locale options are only available when locale sorting is selected. + */ +export type StringCollationConfig = + | { + stringSort?: `lexical` + } + | { + stringSort?: `locale` + locale?: string + localeOptions?: object + } + /** * Helper type to extract the output type from a standard schema * @@ -582,6 +613,14 @@ export interface BaseCollectionConfig< */ onDelete?: DeleteMutationFn + /** + * Specifies how to compare data in the collection. + * This should be configured to match data ordering on the backend. + * E.g., when using the Electric DB collection these options + * should match the database's collation settings. + */ + defaultStringCollation?: StringCollationConfig + utils?: TUtils } diff --git a/packages/db/src/utils/index-optimization.ts b/packages/db/src/utils/index-optimization.ts index 77c8861ed..a42b5086c 100644 --- a/packages/db/src/utils/index-optimization.ts +++ b/packages/db/src/utils/index-optimization.ts @@ -18,12 +18,9 @@ import { DEFAULT_COMPARE_OPTIONS } from "../utils.js" import { ReverseIndex } from "../indexes/reverse-index.js" import type { CompareOptions } from "../query/builder/types.js" -import type { - BaseIndex, - IndexInterface, - IndexOperation, -} from "../indexes/base-index.js" +import type { IndexInterface, IndexOperation } from "../indexes/base-index.js" import type { BasicExpression } from "../query/ir.js" +import type { CollectionLike } from "../types.js" /** * Result of index-based query optimization @@ -37,16 +34,21 @@ export interface OptimizationResult { * Finds an index that matches a given field path */ export function findIndexForField( - indexes: Map>, + collection: CollectionLike, fieldPath: Array, - compareOptions: CompareOptions = DEFAULT_COMPARE_OPTIONS + compareOptions?: CompareOptions ): IndexInterface | undefined { - for (const index of indexes.values()) { + const compareOpts = compareOptions ?? { + ...DEFAULT_COMPARE_OPTIONS, + ...collection.compareOptions, + } + + for (const index of collection.indexes.values()) { if ( index.matchesField(fieldPath) && - index.matchesCompareOptions(compareOptions) + index.matchesCompareOptions(compareOpts) ) { - if (!index.matchesDirection(compareOptions.direction)) { + if (!index.matchesDirection(compareOpts.direction)) { return new ReverseIndex(index) } return index @@ -91,19 +93,22 @@ export function unionSets(sets: Array>): Set { /** * Optimizes a query expression using available indexes to find matching keys */ -export function optimizeExpressionWithIndexes( +export function optimizeExpressionWithIndexes< + T extends object, + TKey extends string | number, +>( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { - return optimizeQueryRecursive(expression, indexes) + return optimizeQueryRecursive(expression, collection) } /** * Recursively optimizes query expressions */ -function optimizeQueryRecursive( +function optimizeQueryRecursive( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { if (expression.type === `func`) { switch (expression.name) { @@ -112,16 +117,16 @@ function optimizeQueryRecursive( case `gte`: case `lt`: case `lte`: - return optimizeSimpleComparison(expression, indexes) + return optimizeSimpleComparison(expression, collection) case `and`: - return optimizeAndExpression(expression, indexes) + return optimizeAndExpression(expression, collection) case `or`: - return optimizeOrExpression(expression, indexes) + return optimizeOrExpression(expression, collection) case `in`: - return optimizeInArrayExpression(expression, indexes) + return optimizeInArrayExpression(expression, collection) } } @@ -131,10 +136,10 @@ function optimizeQueryRecursive( /** * Checks if an expression can be optimized */ -export function canOptimizeExpression( - expression: BasicExpression, - indexes: Map> -): boolean { +export function canOptimizeExpression< + T extends object, + TKey extends string | number, +>(expression: BasicExpression, collection: CollectionLike): boolean { if (expression.type === `func`) { switch (expression.name) { case `eq`: @@ -142,16 +147,16 @@ export function canOptimizeExpression( case `gte`: case `lt`: case `lte`: - return canOptimizeSimpleComparison(expression, indexes) + return canOptimizeSimpleComparison(expression, collection) case `and`: - return canOptimizeAndExpression(expression, indexes) + return canOptimizeAndExpression(expression, collection) case `or`: - return canOptimizeOrExpression(expression, indexes) + return canOptimizeOrExpression(expression, collection) case `in`: - return canOptimizeInArrayExpression(expression, indexes) + return canOptimizeInArrayExpression(expression, collection) } } @@ -162,9 +167,12 @@ export function canOptimizeExpression( * Optimizes compound range queries on the same field * Example: WHERE age > 5 AND age < 10 */ -function optimizeCompoundRangeQuery( +function optimizeCompoundRangeQuery< + T extends object, + TKey extends string | number, +>( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { if (expression.type !== `func` || expression.args.length < 2) { return { canOptimize: false, matchingKeys: new Set() } @@ -236,7 +244,7 @@ function optimizeCompoundRangeQuery( for (const [fieldKey, operations] of fieldOperations) { if (operations.length >= 2) { const fieldPath = fieldKey.split(`.`) - const index = findIndexForField(indexes, fieldPath) + const index = findIndexForField(collection, fieldPath) if (index && index.supports(`gt`) && index.supports(`lt`)) { // Build range query options @@ -292,9 +300,12 @@ function optimizeCompoundRangeQuery( /** * Optimizes simple comparison expressions (eq, gt, gte, lt, lte) */ -function optimizeSimpleComparison( +function optimizeSimpleComparison< + T extends object, + TKey extends string | number, +>( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { if (expression.type !== `func` || expression.args.length !== 2) { return { canOptimize: false, matchingKeys: new Set() } @@ -337,7 +348,7 @@ function optimizeSimpleComparison( if (fieldArg && valueArg) { const fieldPath = (fieldArg as any).path - const index = findIndexForField(indexes, fieldPath) + const index = findIndexForField(collection, fieldPath) if (index) { const queryValue = (valueArg as any).value @@ -361,10 +372,10 @@ function optimizeSimpleComparison( /** * Checks if a simple comparison can be optimized */ -function canOptimizeSimpleComparison( - expression: BasicExpression, - indexes: Map> -): boolean { +function canOptimizeSimpleComparison< + T extends object, + TKey extends string | number, +>(expression: BasicExpression, collection: CollectionLike): boolean { if (expression.type !== `func` || expression.args.length !== 2) { return false } @@ -382,7 +393,7 @@ function canOptimizeSimpleComparison( } if (fieldPath) { - const index = findIndexForField(indexes, fieldPath) + const index = findIndexForField(collection, fieldPath) return index !== undefined } @@ -392,16 +403,16 @@ function canOptimizeSimpleComparison( /** * Optimizes AND expressions */ -function optimizeAndExpression( +function optimizeAndExpression( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { if (expression.type !== `func` || expression.args.length < 2) { return { canOptimize: false, matchingKeys: new Set() } } // First, try to optimize compound range queries on the same field - const compoundRangeResult = optimizeCompoundRangeQuery(expression, indexes) + const compoundRangeResult = optimizeCompoundRangeQuery(expression, collection) if (compoundRangeResult.canOptimize) { return compoundRangeResult } @@ -410,7 +421,7 @@ function optimizeAndExpression( // Try to optimize each part, keep the optimizable ones for (const arg of expression.args) { - const result = optimizeQueryRecursive(arg, indexes) + const result = optimizeQueryRecursive(arg, collection) if (result.canOptimize) { results.push(result) } @@ -429,24 +440,24 @@ function optimizeAndExpression( /** * Checks if an AND expression can be optimized */ -function canOptimizeAndExpression( - expression: BasicExpression, - indexes: Map> -): boolean { +function canOptimizeAndExpression< + T extends object, + TKey extends string | number, +>(expression: BasicExpression, collection: CollectionLike): boolean { if (expression.type !== `func` || expression.args.length < 2) { return false } // If any argument can be optimized, we can gain some speedup - return expression.args.some((arg) => canOptimizeExpression(arg, indexes)) + return expression.args.some((arg) => canOptimizeExpression(arg, collection)) } /** * Optimizes OR expressions */ -function optimizeOrExpression( +function optimizeOrExpression( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { if (expression.type !== `func` || expression.args.length < 2) { return { canOptimize: false, matchingKeys: new Set() } @@ -456,7 +467,7 @@ function optimizeOrExpression( // Try to optimize each part, keep the optimizable ones for (const arg of expression.args) { - const result = optimizeQueryRecursive(arg, indexes) + const result = optimizeQueryRecursive(arg, collection) if (result.canOptimize) { results.push(result) } @@ -475,24 +486,27 @@ function optimizeOrExpression( /** * Checks if an OR expression can be optimized */ -function canOptimizeOrExpression( - expression: BasicExpression, - indexes: Map> -): boolean { +function canOptimizeOrExpression< + T extends object, + TKey extends string | number, +>(expression: BasicExpression, collection: CollectionLike): boolean { if (expression.type !== `func` || expression.args.length < 2) { return false } // If any argument can be optimized, we can gain some speedup - return expression.args.some((arg) => canOptimizeExpression(arg, indexes)) + return expression.args.some((arg) => canOptimizeExpression(arg, collection)) } /** * Optimizes IN array expressions */ -function optimizeInArrayExpression( +function optimizeInArrayExpression< + T extends object, + TKey extends string | number, +>( expression: BasicExpression, - indexes: Map> + collection: CollectionLike ): OptimizationResult { if (expression.type !== `func` || expression.args.length !== 2) { return { canOptimize: false, matchingKeys: new Set() } @@ -508,7 +522,7 @@ function optimizeInArrayExpression( ) { const fieldPath = (fieldArg as any).path const values = (arrayArg as any).value - const index = findIndexForField(indexes, fieldPath) + const index = findIndexForField(collection, fieldPath) if (index) { // Check if the index supports IN operation @@ -535,10 +549,10 @@ function optimizeInArrayExpression( /** * Checks if an IN array expression can be optimized */ -function canOptimizeInArrayExpression( - expression: BasicExpression, - indexes: Map> -): boolean { +function canOptimizeInArrayExpression< + T extends object, + TKey extends string | number, +>(expression: BasicExpression, collection: CollectionLike): boolean { if (expression.type !== `func` || expression.args.length !== 2) { return false } @@ -552,7 +566,7 @@ function canOptimizeInArrayExpression( Array.isArray((arrayArg as any).value) ) { const fieldPath = (fieldArg as any).path - const index = findIndexForField(indexes, fieldPath) + const index = findIndexForField(collection, fieldPath) return index !== undefined } diff --git a/packages/db/tests/query/builder/order-by.test.ts b/packages/db/tests/query/builder/order-by.test.ts index 378371d9e..51f7c075a 100644 --- a/packages/db/tests/query/builder/order-by.test.ts +++ b/packages/db/tests/query/builder/order-by.test.ts @@ -40,7 +40,7 @@ describe(`QueryBuilder.orderBy`, () => { ]) expect(builtQuery.orderBy![0]!.compareOptions.direction).toBe(`asc`) expect(builtQuery.orderBy![0]!.compareOptions.nulls).toBe(`first`) - expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBe(`locale`) + expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBeUndefined() }) it(`supports descending order`, () => { @@ -62,7 +62,7 @@ describe(`QueryBuilder.orderBy`, () => { ]) expect(builtQuery.orderBy![0]!.compareOptions.direction).toBe(`desc`) expect(builtQuery.orderBy![0]!.compareOptions.nulls).toBe(`first`) - expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBe(`locale`) + expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBeUndefined() }) it(`supports ascending order explicitly`, () => { @@ -94,7 +94,7 @@ describe(`QueryBuilder.orderBy`, () => { expect(builtQuery.orderBy).toHaveLength(1) expect(builtQuery.orderBy![0]!.compareOptions.direction).toBe(`asc`) expect(builtQuery.orderBy![0]!.compareOptions.nulls).toBe(`last`) - expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBe(`locale`) + expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBeUndefined() }) it(`supports stringSort`, () => { @@ -136,7 +136,7 @@ describe(`QueryBuilder.orderBy`, () => { expect(builtQuery.orderBy).toBeDefined() expect(builtQuery.orderBy).toHaveLength(1) expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBe(`locale`) - expect(builtQuery.orderBy![0]!.compareOptions.locale).toBe(`de-DE`) + expect((builtQuery.orderBy![0]!.compareOptions as any).locale).toBe(`de-DE`) expect(builtQuery.orderBy![0]!.compareOptions.nulls).toBe(`first`) expect(builtQuery.orderBy![0]!.compareOptions.direction).toBe(`asc`) }) @@ -160,8 +160,10 @@ describe(`QueryBuilder.orderBy`, () => { expect(builtQuery.orderBy).toBeDefined() expect(builtQuery.orderBy).toHaveLength(1) expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBe(`locale`) - expect(builtQuery.orderBy![0]!.compareOptions.locale).toBe(`de-DE`) - expect(builtQuery.orderBy![0]!.compareOptions.localeOptions).toEqual({ + expect((builtQuery.orderBy![0]!.compareOptions as any).locale).toBe(`de-DE`) + expect( + (builtQuery.orderBy![0]!.compareOptions as any).localeOptions + ).toEqual({ sensitivity: `base`, }) expect(builtQuery.orderBy![0]!.compareOptions.nulls).toBe(`first`) @@ -202,7 +204,7 @@ describe(`QueryBuilder.orderBy`, () => { expect(orderByClause.expression.type).toBeDefined() expect(orderByClause.compareOptions.direction).toBe(`asc`) expect(orderByClause.compareOptions.nulls).toBe(`first`) - expect(orderByClause.compareOptions.stringSort).toBe(`locale`) + expect(orderByClause.compareOptions.stringSort).toBeUndefined() }) it(`can be combined with other clauses`, () => { @@ -241,14 +243,14 @@ describe(`QueryBuilder.orderBy`, () => { ]) expect(builtQuery.orderBy![0]!.compareOptions.direction).toBe(`asc`) expect(builtQuery.orderBy![0]!.compareOptions.nulls).toBe(`first`) - expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBe(`locale`) + expect(builtQuery.orderBy![0]!.compareOptions.stringSort).toBeUndefined() expect((builtQuery.orderBy![1]!.expression as any).path).toEqual([ `employees`, `salary`, ]) expect(builtQuery.orderBy![1]!.compareOptions.direction).toBe(`desc`) expect(builtQuery.orderBy![1]!.compareOptions.nulls).toBe(`first`) - expect(builtQuery.orderBy![1]!.compareOptions.stringSort).toBe(`locale`) + expect(builtQuery.orderBy![1]!.compareOptions.stringSort).toBeUndefined() }) it(`supports limit and offset with order by`, () => { diff --git a/packages/db/tests/query/live-query-collection.test.ts b/packages/db/tests/query/live-query-collection.test.ts index 87f407f2c..4dac1b2f1 100644 --- a/packages/db/tests/query/live-query-collection.test.ts +++ b/packages/db/tests/query/live-query-collection.test.ts @@ -100,6 +100,139 @@ describe(`createLiveQueryCollection`, () => { expect(activeUsers2.size).toBe(2) }) + describe(`compareOptions inheritance`, () => { + it(`should inherit compareOptions from FROM collection`, async () => { + // Create a collection with non-default compareOptions + const sourceCollection = createCollection( + mockSyncCollectionOptions({ + id: `source-with-lexical`, + getKey: (user) => user.id, + initialData: sampleUsers, + defaultStringCollation: { + stringSort: `lexical`, + }, + }) + ) + + // Create a live query collection from the source collection + const liveQuery = createLiveQueryCollection((q) => + q.from({ user: sourceCollection }) + ) + + // The live query should inherit the compareOptions from the source collection + expect(liveQuery.compareOptions).toEqual({ + stringSort: `lexical`, + }) + expect(sourceCollection.compareOptions).toEqual({ + stringSort: `lexical`, + }) + }) + + it(`should inherit compareOptions from FROM collection via subquery`, async () => { + // Create a collection with non-default compareOptions + const sourceCollection = createCollection( + mockSyncCollectionOptions({ + id: `source-with-locale`, + getKey: (user) => user.id, + initialData: sampleUsers, + defaultStringCollation: { + stringSort: `locale`, + locale: `de-DE`, + }, + }) + ) + + // Create a live query collection with a subquery + const liveQuery = createLiveQueryCollection((q) => { + // Build the subquery first + const filteredUsers = q + .from({ user: sourceCollection }) + .where(({ user }) => eq(user.active, true)) + + // Use the subquery in the main query + return q.from({ filteredUser: filteredUsers }) + }) + + // The live query should inherit the compareOptions from the source collection + // (which is the FROM collection of the subquery) + expect(liveQuery.compareOptions).toEqual({ + stringSort: `locale`, + locale: `de-DE`, + }) + expect(sourceCollection.compareOptions).toEqual({ + stringSort: `locale`, + locale: `de-DE`, + }) + }) + + it(`should use default compareOptions when FROM collection has no compareOptions`, async () => { + // Create a collection without compareOptions (uses defaults) + const sourceCollection = createCollection( + mockSyncCollectionOptions({ + id: `source-with-defaults`, + getKey: (user) => user.id, + initialData: sampleUsers, + // No compareOptions specified - uses defaults + }) + ) + + // Create a live query collection with a subquery + const liveQuery = createLiveQueryCollection((q) => { + // Build the subquery first + const filteredUsers = q + .from({ user: sourceCollection }) + .where(({ user }) => eq(user.active, true)) + + // Use the subquery in the main query + return q.from({ filteredUser: filteredUsers }) + }) + + // The live query should use default compareOptions (locale) + // when the source collection doesn't specify compareOptions + expect(liveQuery.compareOptions).toEqual({ + stringSort: `locale`, + }) + expect(sourceCollection.compareOptions).toEqual({ + stringSort: `locale`, + }) + }) + + it(`should use explicitly provided compareOptions instead of inheriting from FROM collection`, async () => { + // Create a collection with non-default compareOptions + const sourceCollection = createCollection( + mockSyncCollectionOptions({ + id: `source-with-lexical`, + getKey: (user) => user.id, + initialData: sampleUsers, + defaultStringCollation: { + stringSort: `lexical`, + }, + }) + ) + + // Create a live query collection with explicitly provided compareOptions + // that differ from the source collection's compareOptions + const liveQuery = createLiveQueryCollection({ + query: (q) => q.from({ user: sourceCollection }), + defaultStringCollation: { + stringSort: `locale`, + locale: `en-US`, + }, + }) + + // The live query should use the explicitly provided compareOptions, + // not the inherited ones from the source collection + expect(liveQuery.compareOptions).toEqual({ + stringSort: `locale`, + locale: `en-US`, + }) + // The source collection should still have its original compareOptions + expect(sourceCollection.compareOptions).toEqual({ + stringSort: `lexical`, + }) + }) + }) + it(`should call markReady when source collection returns empty array`, async () => { // Create an empty source collection using the mock sync options const emptyUsersCollection = createCollection( diff --git a/packages/db/tests/query/order-by.test.ts b/packages/db/tests/query/order-by.test.ts index f0cdf8307..2e568ebca 100644 --- a/packages/db/tests/query/order-by.test.ts +++ b/packages/db/tests/query/order-by.test.ts @@ -2226,6 +2226,161 @@ describe(`Query2 OrderBy Compiler`, () => { createOrderByTests(`eager`) }) +describe(`OrderBy with collection-level StringSortOpts`, () => { + type StringItem = { + id: number + name: string + } + + const stringItemsData: Array = [ + { id: 1, name: `Charlie` }, + { id: 2, name: `alice` }, + { id: 3, name: `bob` }, + ] + + it(`should use collection's compareOptions when query doesn't specify stringSort`, async () => { + // Create collection with lexical string sorting as default + const collectionWithLexical = createCollection( + mockSyncCollectionOptions({ + id: `test-lexical-collection`, + getKey: (item) => item.id, + initialData: stringItemsData, + defaultStringCollation: { + stringSort: `lexical`, + }, + }) + ) + + // Query without specifying stringSort should use collection's lexical default + const lexicalQuery = createLiveQueryCollection((q) => + q + .from({ items: collectionWithLexical }) + .orderBy(({ items }) => items.name, `asc`) + .select(({ items }) => ({ + id: items.id, + name: items.name, + })) + ) + await lexicalQuery.preload() + + // In lexical comparison, uppercase letters come before lowercase letters + const lexicalResults = Array.from(lexicalQuery.values()) + expect(lexicalResults.map((r) => r.name)).toEqual([ + `Charlie`, + `alice`, + `bob`, + ]) + }) + + it(`should override collection's compareOptions when query specifies stringSort`, async () => { + // Create collection with lexical string sorting as default + const collectionWithLexical = createCollection( + mockSyncCollectionOptions({ + id: `test-lexical-collection-override`, + getKey: (item) => item.id, + initialData: stringItemsData, + defaultStringCollation: { + stringSort: `lexical`, + }, + }) + ) + + // Query with explicit locale stringSort should override collection's lexical default + const localeQuery = createLiveQueryCollection((q) => + q + .from({ items: collectionWithLexical }) + .orderBy(({ items }) => items.name, { + direction: `asc`, + stringSort: `locale`, + locale: `en-US`, + }) + .select(({ items }) => ({ + id: items.id, + name: items.name, + })) + ) + await localeQuery.preload() + + // In locale comparison, case-insensitive sorting puts lowercase first + const localeResults = Array.from(localeQuery.values()) + expect(localeResults.map((r) => r.name)).toEqual([ + `alice`, + `bob`, + `Charlie`, + ]) + }) + + it(`should use collection default and allow query overrides`, async () => { + // Create collection with lexical string sorting as default + const collectionWithLexical = createCollection( + mockSyncCollectionOptions({ + id: `test-lexical-collection-sequence`, + getKey: (item) => item.id, + initialData: stringItemsData, + defaultStringCollation: { + stringSort: `lexical`, + }, + }) + ) + + // First query without specifying stringSort should use collection's lexical default + const firstQuery = createLiveQueryCollection((q) => + q + .from({ items: collectionWithLexical }) + .orderBy(({ items }) => items.name, `asc`) + .select(({ items }) => ({ + id: items.id, + name: items.name, + })) + ) + await firstQuery.preload() + + // In lexical comparison, uppercase letters come before lowercase letters + const firstResults = Array.from(firstQuery.values()) + expect(firstResults.map((r) => r.name)).toEqual([`Charlie`, `alice`, `bob`]) + + // Second query with explicit locale stringSort should override collection's lexical default + const secondQuery = createLiveQueryCollection((q) => + q + .from({ items: collectionWithLexical }) + .orderBy(({ items }) => items.name, { + direction: `asc`, + stringSort: `locale`, + locale: `en-US`, + }) + .select(({ items }) => ({ + id: items.id, + name: items.name, + })) + ) + await secondQuery.preload() + + // Should use locale sorting (case-insensitive) for this query + const secondResults = Array.from(secondQuery.values()) + expect(secondResults.map((r) => r.name)).toEqual([ + `alice`, + `bob`, + `Charlie`, + ]) + + // Third query without specifying stringSort should use collection's lexical default again + const thirdQuery = createLiveQueryCollection((q) => + q + .from({ items: collectionWithLexical }) + .orderBy(({ items }) => items.name, `desc`) + .select(({ items }) => ({ + id: items.id, + name: items.name, + })) + ) + await thirdQuery.preload() + + // Should revert back to lexical sorting (collection default) + const thirdResults = Array.from(thirdQuery.values()) + expect(thirdResults.map((r) => r.name)).toEqual([`bob`, `alice`, `Charlie`]) + }) +}) + describe(`OrderBy with collection alias conflicts`, () => { type EmailSchema = { email: string diff --git a/packages/db/tests/utils.ts b/packages/db/tests/utils.ts index 98909b22f..26dad9c22 100644 --- a/packages/db/tests/utils.ts +++ b/packages/db/tests/utils.ts @@ -2,6 +2,7 @@ import { expect } from "vitest" import type { CollectionConfig, MutationFnParams, + StringCollationConfig, SyncConfig, } from "../src/index.js" @@ -179,6 +180,7 @@ type MockSyncCollectionConfig> = { autoIndex?: `off` | `eager` sync?: SyncConfig syncMode?: `eager` | `on-demand` + defaultStringCollation?: StringCollationConfig } export function mockSyncCollectionOptions<