@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 +12 -2
- package/README.md +2 -2
- package/package.json +3 -3
- package/src/collections/indexeddb-collection.ts +4 -20
- 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,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
|
-
- **`
|
|
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:
|
|
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
|
-
|
|
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.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.
|
|
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.
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
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) => {
|
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) {
|