@firtoz/drizzle-indexeddb 3.0.1 → 4.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @firtoz/drizzle-indexeddb
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#64](https://github.com/firtoz/fullstack-toolkit/pull/64) [`556555a`](https://github.com/firtoz/fullstack-toolkit/commit/556555a2e09030a8658be8c07b5881e72be64b2f) Thanks [@firtoz](https://github.com/firtoz)! - **`@firtoz/drizzle-utils`:** Export `DrizzleSqliteTableCollection`; extend `BaseSyncConfig` / `createCollectionConfig` for typed `getSyncPersistKey` and `getKey` as `IdOf<TTable>`; avoid executing `syncableTable` default functions during table definition for Worker/DO globals; export collection helper types for Drizzle-backed TanStack collections.
8
+
9
+ **`@firtoz/drizzle-indexeddb` (major):** `deferLocalPersistence`, `handleBatchPut`, and related collection options; `receiveSync` persistence aligned with generic sync and partial-sync traffic; remove debug ingest usage. **Breaking** alongside the `@firtoz/drizzle-utils` sync/collection typing changes above (including `DrizzleSqliteTableCollection` and `BaseSyncConfig` expectations).
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`556555a`](https://github.com/firtoz/fullstack-toolkit/commit/556555a2e09030a8658be8c07b5881e72be64b2f), [`556555a`](https://github.com/firtoz/fullstack-toolkit/commit/556555a2e09030a8658be8c07b5881e72be64b2f), [`556555a`](https://github.com/firtoz/fullstack-toolkit/commit/556555a2e09030a8658be8c07b5881e72be64b2f), [`f90479f`](https://github.com/firtoz/fullstack-toolkit/commit/f90479f263e932b39269aecce4f54dbbb7cdce3e)]:
14
+ - @firtoz/db-helpers@2.1.0
15
+ - @firtoz/drizzle-utils@1.2.0
16
+ - @firtoz/idb-collections@0.2.2
17
+
3
18
  ## 3.0.1
4
19
 
5
20
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/drizzle-indexeddb",
3
- "version": "3.0.1",
3
+ "version": "4.0.0",
4
4
  "description": "IndexedDB migrations powered by Drizzle ORM",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -39,7 +39,7 @@
39
39
  "CHANGELOG.md"
40
40
  ],
41
41
  "scripts": {
42
- "typecheck": "tsc --noEmit -p ./tsconfig.json",
42
+ "typecheck": "tsgo --noEmit -p ./tsconfig.json",
43
43
  "lint": "biome check --write src",
44
44
  "lint:ci": "biome ci src",
45
45
  "format": "biome format src --write"
@@ -68,25 +68,25 @@
68
68
  "access": "public"
69
69
  },
70
70
  "peerDependencies": {
71
- "@firtoz/drizzle-utils": ">=1.1.0",
72
- "@tanstack/db": ">=0.5.33",
73
- "drizzle-orm": ">=0.45.1",
71
+ "@firtoz/drizzle-utils": ">=1.2.0",
72
+ "@tanstack/db": ">=0.6.1",
73
+ "drizzle-orm": ">=0.45.2",
74
74
  "drizzle-valibot": ">=0.4.0",
75
75
  "react": ">=19.2.4",
76
76
  "valibot": ">=1.3.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@firtoz/drizzle-utils": "^1.1.0",
80
- "@tanstack/db": "^0.5.33",
79
+ "@firtoz/drizzle-utils": "^1.2.0",
80
+ "@tanstack/db": "^0.6.1",
81
81
  "@types/react": "^19.2.14",
82
- "drizzle-orm": "^0.45.1",
82
+ "drizzle-orm": "^0.45.2",
83
83
  "drizzle-valibot": "^0.4.2",
84
84
  "react": "^19.2.4",
85
85
  "valibot": "^1.3.1"
86
86
  },
87
87
  "dependencies": {
88
- "@firtoz/db-helpers": "^2.0.0",
89
- "@firtoz/idb-collections": "^0.2.1",
88
+ "@firtoz/db-helpers": "^2.1.0",
89
+ "@firtoz/idb-collections": "^0.2.2",
90
90
  "@firtoz/maybe-error": "^1.5.2",
91
91
  "citty": "^0.2.1"
92
92
  }
@@ -65,6 +65,11 @@ export interface DrizzleIndexedDBCollectionConfig<TTable extends Table> {
65
65
  * Enable debug logging for index discovery and query optimization
66
66
  */
67
67
  debug?: boolean;
68
+ /**
69
+ * When set, local mutations confirm TanStack sync immediately and persist to IndexedDB on a
70
+ * coalesced timer (`createGenericSyncFunction` in `@firtoz/db-helpers`).
71
+ */
72
+ deferLocalPersistence?: boolean | { flushIntervalMs?: number };
68
73
  }
69
74
 
70
75
  export type DrizzleIndexedDBCollectionConfigResult<TTable extends Table> = Omit<
@@ -284,6 +289,21 @@ export function drizzleIndexedDBCollectionOptions<const TTable extends Table>(
284
289
  return results;
285
290
  },
286
291
 
292
+ handleBatchPut: async (itemsToPut) => {
293
+ const db = config.indexedDBRef.current;
294
+ if (!db) {
295
+ throw new Error("Database not ready");
296
+ }
297
+ const now = new Date();
298
+ const rows = (itemsToPut as unknown as DrizzleIndexedDBSyncItem[]).map(
299
+ (row) => ({
300
+ ...row,
301
+ updatedAt: now,
302
+ }),
303
+ );
304
+ await db.put(config.storeName, rows);
305
+ },
306
+
287
307
  handleDelete: async (mutations) => {
288
308
  const db = config.indexedDBRef.current;
289
309
 
@@ -320,11 +340,18 @@ export function drizzleIndexedDBCollectionOptions<const TTable extends Table>(
320
340
  },
321
341
  };
322
342
 
343
+ type TItem = InferSchemaOutput<SelectSchema<TTable>>;
344
+ const getKey = createGetKeyFunction<TTable>();
345
+
323
346
  const baseSyncConfig: BaseSyncConfig<TTable> = {
324
347
  table,
325
348
  readyPromise: config.readyPromise,
326
349
  syncMode: config.syncMode,
327
350
  debug: config.debug,
351
+ getSyncPersistKey: (item: TItem) => String(getKey(item)),
352
+ ...(config.deferLocalPersistence !== undefined
353
+ ? { deferLocalPersistence: config.deferLocalPersistence }
354
+ : {}),
328
355
  };
329
356
 
330
357
  const syncResult = createSyncFunction(baseSyncConfig, wrappedBackend);
@@ -333,7 +360,7 @@ export function drizzleIndexedDBCollectionOptions<const TTable extends Table>(
333
360
 
334
361
  return createCollectionConfig({
335
362
  schema,
336
- getKey: createGetKeyFunction<TTable>(),
363
+ getKey,
337
364
  syncResult,
338
365
  syncMode: config.syncMode,
339
366
  });