@firtoz/drizzle-indexeddb 0.5.1 → 0.6.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,15 @@
1
1
  # @firtoz/drizzle-indexeddb
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`a08a986`](https://github.com/firtoz/fullstack-toolkit/commit/a08a986cc5161b20c9c875328e49565c15417ffc) Thanks [@firtoz](https://github.com/firtoz)! - Slight refactor
8
+
9
+ - Renamed `createProxyDbCreator` to `createProxyIDbCreator` for consistency across the codebase.
10
+ - Updated server sync message type from `sync:clear` to `sync:truncate` to better reflect its functionality.
11
+ - Adjusted related documentation and test cases to align with these changes.
12
+
3
13
  ## 0.5.1
4
14
 
5
15
  ### Patch Changes
@@ -61,12 +71,12 @@
61
71
  - **`IDBProxyServer`** - Server that manages database lifecycle, migrations, and broadcasts mutations to connected clients
62
72
  - **`IDBProxyClient`** - Client implementing `IDBDatabaseLike`, routing operations through a transport layer
63
73
  - **`createMultiClientTransport()`** - In-memory transport for testing N clients connected to one server
64
- - **`createProxyDbCreator()`** - Factory to create `dbCreator` for `DrizzleIndexedDBProvider`
74
+ - **`createProxyIDbCreator()`** - Factory to create `dbCreator` for `DrizzleIndexedDBProvider`
65
75
  - **`createCollectionSyncHandler()`** - Adapter connecting proxy sync messages to collection's external sync
66
76
 
67
77
  **Real-time Multi-Client Sync**:
68
78
 
69
- - Server broadcasts `sync:add`, `sync:put`, `sync:delete`, `sync:clear` messages to all clients (excluding initiator)
79
+ - Server broadcasts `sync:add`, `sync:put`, `sync:delete`, `sync:truncate` messages to all clients (excluding initiator)
70
80
  - All mutations automatically sync across connected clients
71
81
 
72
82
  **Provider Enhancements**:
package/README.md CHANGED
@@ -460,7 +460,7 @@ For scenarios where IndexedDB needs to be accessed over a messaging layer (e.g.,
460
460
  import {
461
461
  createMultiClientTransport,
462
462
  createProxyServer,
463
- createProxyDbCreator,
463
+ createProxyIDbCreator,
464
464
  migrateIndexedDBWithFunctions,
465
465
  DrizzleIndexedDBProvider,
466
466
  } from "@firtoz/drizzle-indexeddb";
@@ -478,7 +478,7 @@ const server = createProxyServer({
478
478
 
479
479
  // Create client
480
480
  const clientTransport = createClientTransport();
481
- const dbCreator = createProxyDbCreator(clientTransport);
481
+ const dbCreator = createProxyIDbCreator(clientTransport);
482
482
 
483
483
  // Use with React provider
484
484
  function App() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firtoz/drizzle-indexeddb",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "IndexedDB migrations powered by Drizzle ORM",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@firtoz/drizzle-utils": ">=0.3.1",
72
- "@tanstack/db": ">=0.5.15",
72
+ "@tanstack/db": ">=0.5.16",
73
73
  "drizzle-orm": ">=0.45.1",
74
74
  "drizzle-valibot": ">=0.4.0",
75
75
  "react": ">=19.2.3",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@firtoz/drizzle-utils": "^0.3.1",
80
- "@tanstack/db": "^0.5.15",
80
+ "@tanstack/db": "^0.5.16",
81
81
  "@types/react": "^19.2.7",
82
82
  "drizzle-orm": "^0.45.1",
83
83
  "drizzle-valibot": "^0.4.2",
@@ -467,32 +467,16 @@ export function indexedDBCollectionOptions<const TTable extends Table>(
467
467
  }
468
468
  },
469
469
 
470
- handleInsert: async (mutations) => {
470
+ handleInsert: async (itemsToInsert) => {
471
471
  const db = config.indexedDBRef.current;
472
472
  if (!db) {
473
473
  throw new Error("Database not ready");
474
474
  }
475
475
 
476
- const results: Array<InferSchemaOutput<SelectSchema<TTable>>> = [];
477
-
478
- try {
479
- const itemsToInsert: IndexedDBSyncItem[] = [];
480
-
481
- for (const mutation of mutations) {
482
- const itemToInsert = mutation.modified;
483
- results.push(itemToInsert);
484
- itemsToInsert.push(itemToInsert as IndexedDBSyncItem);
485
- }
476
+ // Add all items in a single batch operation
477
+ await db.add(config.storeName, itemsToInsert);
486
478
 
487
- // Add all items in a single batch operation
488
- await db.add(config.storeName, itemsToInsert);
489
- } catch (error) {
490
- // Clear results on error so nothing gets written to reactive store
491
- results.length = 0;
492
- throw error;
493
- }
494
-
495
- return results;
479
+ return itemsToInsert;
496
480
  },
497
481
 
498
482
  handleUpdate: async (mutations) => {
@@ -280,7 +280,7 @@ export function DrizzleIndexedDBProvider<
280
280
  items: message.keys.map((key) => ({ id: key })),
281
281
  });
282
282
  break;
283
- case "sync:clear":
283
+ case "sync:truncate":
284
284
  pushExternalSync({
285
285
  type: "truncate",
286
286
  });
package/src/index.ts CHANGED
@@ -76,7 +76,7 @@ export {
76
76
  createMultiClientTransport,
77
77
  // Client
78
78
  IDBProxyClient,
79
- createProxyDbCreator,
79
+ createProxyIDbCreator,
80
80
  type SyncHandler,
81
81
  // Server
82
82
  IDBProxyServer,
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  IDBDatabaseLike,
3
3
  IDBCreator,
4
- IDBOpenOptions,
5
4
  IndexInfo,
6
5
  CreateStoreOptions,
7
6
  CreateIndexOptions,
@@ -294,13 +293,13 @@ export class IDBProxyClient implements IDBDatabaseLike {
294
293
  * @param onSync Optional handler called when any sync message is received
295
294
  *
296
295
  * @example
297
- * const dbCreator = createProxyDbCreator(transport, (msg) => {
296
+ * const dbCreator = createProxyIDbCreator(transport, (msg) => {
298
297
  * console.log('Sync:', msg.type, msg.storeName);
299
298
  * });
300
299
  *
301
300
  * <DrizzleIndexedDBProvider dbCreator={dbCreator} ... />
302
301
  */
303
- export function createProxyDbCreator(
302
+ export function createProxyIDbCreator(
304
303
  transport: IDBProxyClientTransport,
305
304
  onSync?: SyncHandler,
306
305
  ): IDBCreator {
@@ -308,10 +307,7 @@ export function createProxyDbCreator(
308
307
  const clientCache = new Map<string, IDBProxyClient>();
309
308
  const connectingCache = new Map<string, Promise<IDBProxyClient>>();
310
309
 
311
- return async (
312
- name: string,
313
- _options?: IDBOpenOptions,
314
- ): Promise<IDBDatabaseLike> => {
310
+ return async (name: string): Promise<IDBDatabaseLike> => {
315
311
  // Return cached client if already connected
316
312
  const cached = clientCache.get(name);
317
313
  if (cached) {
@@ -224,7 +224,7 @@ export class IDBProxyServer {
224
224
  // Broadcast to other clients
225
225
  this.options.transport.broadcast(
226
226
  {
227
- type: "sync:clear",
227
+ type: "sync:truncate",
228
228
  dbName: request.dbName,
229
229
  storeName: request.storeName,
230
230
  },
@@ -59,7 +59,7 @@ export type IDBProxySyncMessage = {
59
59
  | { type: "sync:add"; items: unknown[] }
60
60
  | { type: "sync:put"; items: unknown[] }
61
61
  | { type: "sync:delete"; keys: IDBValidKey[] }
62
- | { type: "sync:clear" }
62
+ | { type: "sync:truncate" }
63
63
  );
64
64
 
65
65
  /**
@@ -65,7 +65,7 @@ export function createCollectionSyncHandler<T = unknown>(
65
65
  });
66
66
  break;
67
67
 
68
- case "sync:clear":
68
+ case "sync:truncate":
69
69
  pushExternalSync({
70
70
  type: "truncate",
71
71
  });
@@ -19,7 +19,7 @@ export {
19
19
  // Proxy client
20
20
  export {
21
21
  IDBProxyClient,
22
- createProxyDbCreator,
22
+ createProxyIDbCreator,
23
23
  type SyncHandler,
24
24
  } from "./idb-proxy-client";
25
25