Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

localonlycollectionconfig.md

172 lines4.3 KB

Interface: LocalOnlyCollectionConfig<TExplicit, TSchema, TFallback, TKey>

Defined in: packages/db/src/local-only.ts:27

Configuration interface for Local-only collection options

Remarks

Type resolution follows a priority order:

  1. If you provide an explicit type via generic parameter, it will be used
  2. If no explicit type is provided but a schema is, the schema's output type will be inferred
  3. If neither explicit type nor schema is provided, the fallback type will be used

You should provide EITHER an explicit type OR a schema, but not both, as they would conflict.

Type Parameters

• TExplicit = unknown

The explicit type of items in the collection (highest priority)

• TSchema extends StandardSchemaV1 = never

The schema type for validation and type inference (second priority)

• TFallback extends Record<string, unknown> = Record<string, unknown>

The fallback type if no explicit or schema type is provided

• TKey extends string | number = string | number

The type of the key returned by getKey

Properties

getKey()

getKey: (item) => TKey;

Defined in: packages/db/src/local-only.ts:38

Parameters

item

ResolveType<TExplicit, TSchema, TFallback>

Returns

TKey


id?

optional id: string;

Defined in: packages/db/src/local-only.ts:36

Standard Collection configuration properties


initialData?

optional initialData: ResolveType<TExplicit, TSchema, TFallback>[];

Defined in: packages/db/src/local-only.ts:44

Optional initial data to populate the collection with on creation This data will be applied during the initial sync process


onDelete()?

optional onDelete: (params) => Promise<any>;

Defined in: packages/db/src/local-only.ts:77

Optional asynchronous handler function called after a delete operation

Parameters

params

DeleteMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>

Object containing transaction and collection information

Returns

Promise<any>

Promise resolving to any value


onInsert()?

optional onInsert: (params) => Promise<any>;

Defined in: packages/db/src/local-only.ts:51

Optional asynchronous handler function called after an insert operation

Parameters

params

InsertMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>

Object containing transaction and collection information

Returns

Promise<any>

Promise resolving to any value


onUpdate()?

optional onUpdate: (params) => Promise<any>;

Defined in: packages/db/src/local-only.ts:64

Optional asynchronous handler function called after an update operation

Parameters

params

UpdateMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>

Object containing transaction and collection information

Returns

Promise<any>

Promise resolving to any value


schema?

optional schema: TSchema;

Defined in: packages/db/src/local-only.ts:37