@firtoz/idb-collections 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/idb-collections",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "IndexedDB collection utilities for TanStack DB — key-value adapter, query optimization",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -18,7 +18,7 @@
18
18
  "README.md"
19
19
  ],
20
20
  "scripts": {
21
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
21
+ "typecheck": "tsgo --noEmit -p ./tsconfig.json",
22
22
  "test": "bun test",
23
23
  "lint": "biome check --write src",
24
24
  "lint:ci": "biome ci src",
@@ -51,15 +51,15 @@
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@standard-schema/spec": ">=1.1.0",
54
- "@tanstack/db": ">=0.5.33"
54
+ "@tanstack/db": ">=0.6.3"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@standard-schema/spec": "^1.1.0",
58
- "@tanstack/db": "^0.5.33",
58
+ "@tanstack/db": "^0.6.4",
59
59
  "bun-types": "^1.3.11",
60
60
  "zod": "^4.3.6"
61
61
  },
62
62
  "dependencies": {
63
- "@firtoz/db-helpers": "^2.0.0"
63
+ "@firtoz/db-helpers": "^2.1.1"
64
64
  }
65
65
  }
@@ -60,7 +60,12 @@ function defaultGetKey<TSchema extends StandardSchemaV1>(
60
60
 
61
61
  export function keyvalCollectionOptions<TSchema extends StandardSchemaV1>(
62
62
  config: KeyValCollectionConfig<TSchema>,
63
- ): CollectionConfig<InferSchemaOutput<TSchema>, string, TSchema> & {
63
+ ): CollectionConfig<
64
+ InferSchemaOutput<TSchema>,
65
+ string,
66
+ TSchema,
67
+ KeyValUtils<InferSchemaOutput<TSchema>>
68
+ > & {
64
69
  utils: KeyValUtils<InferSchemaOutput<TSchema>>;
65
70
  schema: TSchema;
66
71
  } {
@@ -209,10 +214,11 @@ export function keyvalCollectionOptions<TSchema extends StandardSchemaV1>(
209
214
  },
210
215
  };
211
216
 
212
- const baseSyncConfig: GenericBaseSyncConfig = {
217
+ const baseSyncConfig: GenericBaseSyncConfig<TItem> = {
213
218
  readyPromise,
214
219
  syncMode: config.syncMode,
215
220
  debug: config.debug,
221
+ getSyncPersistKey: getKey,
216
222
  };
217
223
 
218
224
  const syncResult: GenericSyncFunctionResult<TItem> =
@@ -223,6 +229,34 @@ export function keyvalCollectionOptions<TSchema extends StandardSchemaV1>(
223
229
  getKey,
224
230
  syncResult,
225
231
  syncMode: config.syncMode,
232
+ onInsert: async (params) => {
233
+ await syncResult.onInsert?.(params);
234
+ const writes: SyncMessage<TItem, string>[] =
235
+ params.transaction.mutations.map((mutation) => ({
236
+ type: "insert",
237
+ value: mutation.modified,
238
+ }));
239
+ config.onBroadcast?.(writes);
240
+ },
241
+ onUpdate: async (params) => {
242
+ await syncResult.onUpdate?.(params);
243
+ const writes: SyncMessage<TItem, string>[] =
244
+ params.transaction.mutations.map((mutation) => ({
245
+ type: "update",
246
+ value: mutation.modified,
247
+ previousValue: mutation.original,
248
+ }));
249
+ config.onBroadcast?.(writes);
250
+ },
251
+ onDelete: async (params) => {
252
+ await syncResult.onDelete?.(params);
253
+ const writes: SyncMessage<TItem, string>[] =
254
+ params.transaction.mutations.map((mutation) => ({
255
+ type: "delete",
256
+ key: mutation.key,
257
+ }));
258
+ config.onBroadcast?.(writes);
259
+ },
226
260
  });
227
261
  }
228
262