@firtoz/drizzle-indexeddb 0.5.1 → 0.6.1
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 +21 -2
- package/README.md +2 -2
- package/package.json +7 -7
- package/src/collections/indexeddb-collection.ts +15 -34
- package/src/context/DrizzleIndexedDBProvider.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/proxy/idb-proxy-client.ts +3 -7
- package/src/proxy/idb-proxy-server.ts +1 -1
- package/src/proxy/idb-proxy-types.ts +1 -1
- package/src/proxy/idb-sync-adapter.ts +1 -1
- package/src/proxy/index.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @firtoz/drizzle-indexeddb
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2725815`](https://github.com/firtoz/fullstack-toolkit/commit/27258158dd318b34b44ed77b88b2ac9b2b4b6a3d) Thanks [@firtoz](https://github.com/firtoz)! - Updated @tanstack/db peer dependency to >=0.5.23 for compatibility with latest versions
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`2725815`](https://github.com/firtoz/fullstack-toolkit/commit/27258158dd318b34b44ed77b88b2ac9b2b4b6a3d)]:
|
|
10
|
+
- @firtoz/drizzle-utils@0.3.2
|
|
11
|
+
|
|
12
|
+
## 0.6.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [`a08a986`](https://github.com/firtoz/fullstack-toolkit/commit/a08a986cc5161b20c9c875328e49565c15417ffc) Thanks [@firtoz](https://github.com/firtoz)! - Slight refactor
|
|
17
|
+
|
|
18
|
+
- Renamed `createProxyDbCreator` to `createProxyIDbCreator` for consistency across the codebase.
|
|
19
|
+
- Updated server sync message type from `sync:clear` to `sync:truncate` to better reflect its functionality.
|
|
20
|
+
- Adjusted related documentation and test cases to align with these changes.
|
|
21
|
+
|
|
3
22
|
## 0.5.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -61,12 +80,12 @@
|
|
|
61
80
|
- **`IDBProxyServer`** - Server that manages database lifecycle, migrations, and broadcasts mutations to connected clients
|
|
62
81
|
- **`IDBProxyClient`** - Client implementing `IDBDatabaseLike`, routing operations through a transport layer
|
|
63
82
|
- **`createMultiClientTransport()`** - In-memory transport for testing N clients connected to one server
|
|
64
|
-
- **`
|
|
83
|
+
- **`createProxyIDbCreator()`** - Factory to create `dbCreator` for `DrizzleIndexedDBProvider`
|
|
65
84
|
- **`createCollectionSyncHandler()`** - Adapter connecting proxy sync messages to collection's external sync
|
|
66
85
|
|
|
67
86
|
**Real-time Multi-Client Sync**:
|
|
68
87
|
|
|
69
|
-
- Server broadcasts `sync:add`, `sync:put`, `sync:delete`, `sync:
|
|
88
|
+
- Server broadcasts `sync:add`, `sync:put`, `sync:delete`, `sync:truncate` messages to all clients (excluding initiator)
|
|
70
89
|
- All mutations automatically sync across connected clients
|
|
71
90
|
|
|
72
91
|
**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
|
-
|
|
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 =
|
|
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.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "IndexedDB migrations powered by Drizzle ORM",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"module": "./src/index.ts",
|
|
@@ -68,23 +68,23 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@firtoz/drizzle-utils": ">=0.3.
|
|
72
|
-
"@tanstack/db": ">=0.5.
|
|
71
|
+
"@firtoz/drizzle-utils": ">=0.3.2",
|
|
72
|
+
"@tanstack/db": ">=0.5.23",
|
|
73
73
|
"drizzle-orm": ">=0.45.1",
|
|
74
74
|
"drizzle-valibot": ">=0.4.0",
|
|
75
75
|
"react": ">=19.2.3",
|
|
76
76
|
"valibot": ">=1.0.0"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@firtoz/drizzle-utils": "^0.3.
|
|
80
|
-
"@tanstack/db": "^0.5.
|
|
81
|
-
"@types/react": "^19.2.
|
|
79
|
+
"@firtoz/drizzle-utils": "^0.3.2",
|
|
80
|
+
"@tanstack/db": "^0.5.23",
|
|
81
|
+
"@types/react": "^19.2.8",
|
|
82
82
|
"drizzle-orm": "^0.45.1",
|
|
83
83
|
"drizzle-valibot": "^0.4.2",
|
|
84
84
|
"react": "^19.2.3",
|
|
85
85
|
"valibot": "^1.2.0"
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"citty": "^0.
|
|
88
|
+
"citty": "^0.2.0"
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -352,7 +352,7 @@ export function indexedDBCollectionOptions<const TTable extends Table>(
|
|
|
352
352
|
|
|
353
353
|
// Create backend-specific implementation
|
|
354
354
|
const backend: SyncBackend<TTable> = {
|
|
355
|
-
initialLoad: async (
|
|
355
|
+
initialLoad: async () => {
|
|
356
356
|
const db = config.indexedDBRef.current;
|
|
357
357
|
if (!db) {
|
|
358
358
|
throw new Error("Database not ready");
|
|
@@ -362,12 +362,9 @@ export function indexedDBCollectionOptions<const TTable extends Table>(
|
|
|
362
362
|
|
|
363
363
|
const items = await db.getAll<IndexedDBSyncItem>(config.storeName);
|
|
364
364
|
|
|
365
|
-
|
|
366
|
-
write(item as unknown as InferSchemaOutput<SelectSchema<TTable>>);
|
|
367
|
-
}
|
|
365
|
+
return items as unknown as InferSchemaOutput<SelectSchema<TTable>>[];
|
|
368
366
|
},
|
|
369
|
-
|
|
370
|
-
loadSubset: async (options, write) => {
|
|
367
|
+
loadSubset: async (options) => {
|
|
371
368
|
const db = config.indexedDBRef.current;
|
|
372
369
|
if (!db) {
|
|
373
370
|
throw new Error("Database not ready");
|
|
@@ -462,37 +459,19 @@ export function indexedDBCollectionOptions<const TTable extends Table>(
|
|
|
462
459
|
items = items.slice(0, options.limit);
|
|
463
460
|
}
|
|
464
461
|
|
|
465
|
-
|
|
466
|
-
write(item as unknown as InferSchemaOutput<SelectSchema<TTable>>);
|
|
467
|
-
}
|
|
462
|
+
return items as unknown as InferSchemaOutput<SelectSchema<TTable>>[];
|
|
468
463
|
},
|
|
469
464
|
|
|
470
|
-
handleInsert: async (
|
|
465
|
+
handleInsert: async (itemsToInsert) => {
|
|
471
466
|
const db = config.indexedDBRef.current;
|
|
472
467
|
if (!db) {
|
|
473
468
|
throw new Error("Database not ready");
|
|
474
469
|
}
|
|
475
470
|
|
|
476
|
-
|
|
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
|
-
}
|
|
486
|
-
|
|
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
|
-
}
|
|
471
|
+
// Add all items in a single batch operation
|
|
472
|
+
await db.add(config.storeName, itemsToInsert);
|
|
494
473
|
|
|
495
|
-
return
|
|
474
|
+
return itemsToInsert;
|
|
496
475
|
},
|
|
497
476
|
|
|
498
477
|
handleUpdate: async (mutations) => {
|
|
@@ -565,13 +544,15 @@ export function indexedDBCollectionOptions<const TTable extends Table>(
|
|
|
565
544
|
// For non-eager sync modes, still discover indexes before marking ready
|
|
566
545
|
const wrappedBackend: SyncBackend<TTable> = {
|
|
567
546
|
...backend,
|
|
568
|
-
initialLoad: async (
|
|
547
|
+
initialLoad: async () => {
|
|
569
548
|
if (config.syncMode === "eager" || !config.syncMode) {
|
|
570
|
-
await backend.initialLoad(
|
|
571
|
-
} else {
|
|
572
|
-
// For non-eager sync modes, still discover indexes but don't load data
|
|
573
|
-
await discoverIndexesOnce();
|
|
549
|
+
return await backend.initialLoad();
|
|
574
550
|
}
|
|
551
|
+
|
|
552
|
+
// For non-eager sync modes, still discover indexes but don't load data
|
|
553
|
+
await discoverIndexesOnce();
|
|
554
|
+
|
|
555
|
+
return [];
|
|
575
556
|
},
|
|
576
557
|
};
|
|
577
558
|
|
package/src/index.ts
CHANGED
|
@@ -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 =
|
|
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
|
|
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) {
|