Function: localOnlyCollectionOptions()#
function localOnlyCollectionOptions<TExplicit, TSchema, TFallback, TKey>(config): object
Defined in: packages/db/src/local-only.ts:137
Creates Local-only collection options for use with a standard Collection
This is an in-memory collection that doesn't sync with external sources but uses a loopback sync config that immediately "syncs" all optimistic changes to the collection, making them permanent. Perfect for local-only data that doesn't need persistence or external synchronization.
Type Parameters#
• TExplicit = unknown
The explicit type of items in the collection (highest priority)
• TSchema extends StandardSchemaV1<unknown, unknown> = 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
Parameters#
config#
LocalOnlyCollectionConfig<TExplicit, TSchema, TFallback, TKey>
Configuration options for the Local-only collection
Returns#
object
Collection options with utilities (currently empty but follows the pattern)
gcTime#
gcTime: number = 0;
getKey()#
getKey: (item) => TKey;
Parameters#
item#
ResolveType<TExplicit, TSchema, TFallback>
Returns#
TKey
id?#
optional id: string;
Standard Collection configuration properties
onDelete()#
onDelete: (params) => Promise<any> = wrappedOnDelete;
Wrapper for onDelete handler that also confirms the transaction immediately
Parameters#
params#
DeleteMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>
Returns#
Promise<any>
onInsert()#
onInsert: (params) => Promise<any> = wrappedOnInsert;
Create wrapper handlers that call user handlers first, then confirm transactions Wraps the user's onInsert handler to also confirm the transaction immediately
Parameters#
params#
InsertMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>
Returns#
Promise<any>
onUpdate()#
onUpdate: (params) => Promise<any> = wrappedOnUpdate;
Wrapper for onUpdate handler that also confirms the transaction immediately
Parameters#
params#
UpdateMutationFnParams<ResolveType<TExplicit, TSchema, TFallback>, TKey, LocalOnlyCollectionUtils>
Returns#
Promise<any>
schema?#
optional schema: TSchema;
startSync#
startSync: boolean = true;
sync#
sync: SyncConfig<ResolveType<TExplicit, TSchema, TFallback>, TKey> = syncResult.sync;
utils#
utils: LocalOnlyCollectionUtils;
Examples#
// Basic local-only collection
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
})
)
// Local-only collection with initial data
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
initialData: [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
],
})
)
// Local-only collection with mutation handlers
const collection = createCollection(
localOnlyCollectionOptions({
getKey: (item) => item.id,
onInsert: async ({ transaction }) => {
console.log('Item inserted:', transaction.mutations[0].modified)
// Custom logic after insert
},
})
)