@anfenn/dync 1.0.26 → 1.0.27
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/README.md +7 -11
- package/dist/{dexie-B1FuZqDB.d.ts → dexie-BFPA0JU2.d.ts} +1 -1
- package/dist/{dexie-DtgGGM68.d.cts → dexie-T9m1mP1h.d.cts} +1 -1
- package/dist/dexie.d.cts +1 -1
- package/dist/dexie.d.ts +1 -1
- package/dist/index.cjs +38 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -24
- package/dist/index.d.ts +28 -24
- package/dist/index.js +38 -6
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/{types-B1Vn8_DF.d.ts → types-BLw25Wlc.d.ts} +35 -3
- package/dist/{types-BgGGLrE9.d.cts → types-yJuzCcux.d.cts} +35 -3
- package/package.json +1 -1
- package/src/index.native.ts +1 -0
- package/src/index.shared.ts +46 -39
- package/src/index.ts +1 -0
- package/src/types.ts +35 -2
package/README.md
CHANGED
|
@@ -48,9 +48,9 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
48
48
|
- Option 1: Map remote api CRUD urls to a local collection:
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
const db = new Dync(
|
|
51
|
+
const db = new Dync({
|
|
52
52
|
...,
|
|
53
|
-
{
|
|
53
|
+
sync: {
|
|
54
54
|
// Only add an entry here for tables that should be synced
|
|
55
55
|
// Pseudocode here, see examples for working code
|
|
56
56
|
items: {
|
|
@@ -60,16 +60,15 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
60
60
|
list: (since) => fetch(`/api/items?since=${since}`),
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
|
-
|
|
64
|
-
);
|
|
63
|
+
});
|
|
65
64
|
```
|
|
66
65
|
|
|
67
66
|
- Option 2: Batch sync to remote /push & /pull endpoints:
|
|
68
67
|
|
|
69
68
|
```ts
|
|
70
|
-
const db = new Dync(
|
|
69
|
+
const db = new Dync({
|
|
71
70
|
...,
|
|
72
|
-
{
|
|
71
|
+
sync: {
|
|
73
72
|
syncTables: ['items'], // Only add tables to this array that should be synced
|
|
74
73
|
push: async (changes) => {
|
|
75
74
|
const res = await fetch('/api/sync/push', {
|
|
@@ -80,15 +79,12 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
80
79
|
return res.json();
|
|
81
80
|
},
|
|
82
81
|
pull: async (since) => {
|
|
83
|
-
const params = new URLSearchParams(
|
|
84
|
-
Object.entries(since).map(([table, date]) => [table, date.toISOString()])
|
|
85
|
-
);
|
|
82
|
+
const params = new URLSearchParams(Object.entries(since).map(([table, date]) => [table, date.toISOString()]));
|
|
86
83
|
const res = await fetch(`/api/sync/pull?${params}`);
|
|
87
84
|
return res.json();
|
|
88
85
|
},
|
|
89
86
|
},
|
|
90
|
-
|
|
91
|
-
);
|
|
87
|
+
});
|
|
92
88
|
```
|
|
93
89
|
|
|
94
90
|
See [examples/shared/api.ts](examples/shared/api.ts) for a fully documented example of these two options.
|
|
@@ -440,4 +440,4 @@ declare class DexieAdapter implements StorageAdapter {
|
|
|
440
440
|
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
export { DexieQueryContext as D, MemoryQueryContext as M,
|
|
443
|
+
export { DexieQueryContext as D, MemoryQueryContext as M, SqliteQueryContext as S, type TableSchemaDefinition as T, type StorageTable as a, MemoryAdapter as b, SQLiteAdapter as c, type StorageAdapter as d, DexieAdapter as e };
|
|
@@ -440,4 +440,4 @@ declare class DexieAdapter implements StorageAdapter {
|
|
|
440
440
|
transaction<T>(mode: TransactionMode, tableNames: string[], callback: (context: StorageTransactionContext) => Promise<T>): Promise<T>;
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
export { DexieQueryContext as D, MemoryQueryContext as M,
|
|
443
|
+
export { DexieQueryContext as D, MemoryQueryContext as M, SqliteQueryContext as S, type TableSchemaDefinition as T, type StorageTable as a, MemoryAdapter as b, SQLiteAdapter as c, type StorageAdapter as d, DexieAdapter as e };
|
package/dist/dexie.d.cts
CHANGED
package/dist/dexie.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1317,13 +1317,35 @@ var DyncBase = class {
|
|
|
1317
1317
|
mutationsDuringSync = false;
|
|
1318
1318
|
state;
|
|
1319
1319
|
name;
|
|
1320
|
-
|
|
1321
|
-
|
|
1320
|
+
/**
|
|
1321
|
+
* Create a new Dync instance.
|
|
1322
|
+
*
|
|
1323
|
+
* @example Per-table sync mode
|
|
1324
|
+
* ```ts
|
|
1325
|
+
* const db = new Dync<Store>({
|
|
1326
|
+
* databaseName: 'my-app',
|
|
1327
|
+
* storageAdapter: new SQLiteAdapter(driver),
|
|
1328
|
+
* sync: { todos: todoSyncApi },
|
|
1329
|
+
* });
|
|
1330
|
+
* ```
|
|
1331
|
+
*
|
|
1332
|
+
* @example Batch sync mode
|
|
1333
|
+
* ```ts
|
|
1334
|
+
* const db = new Dync<Store>({
|
|
1335
|
+
* databaseName: 'my-app',
|
|
1336
|
+
* storageAdapter: new SQLiteAdapter(driver),
|
|
1337
|
+
* sync: { syncTables: ['todos'], push, pull },
|
|
1338
|
+
* });
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
constructor(config) {
|
|
1342
|
+
const { databaseName, storageAdapter, sync: syncConfig, options } = config;
|
|
1343
|
+
const isBatchMode = typeof syncConfig.push === "function" && typeof syncConfig.pull === "function";
|
|
1322
1344
|
if (isBatchMode) {
|
|
1323
|
-
this.batchSync =
|
|
1345
|
+
this.batchSync = syncConfig;
|
|
1324
1346
|
this.syncedTables = new Set(this.batchSync.syncTables);
|
|
1325
1347
|
} else {
|
|
1326
|
-
this.syncApis =
|
|
1348
|
+
this.syncApis = syncConfig;
|
|
1327
1349
|
this.syncedTables = new Set(Object.keys(this.syncApis));
|
|
1328
1350
|
}
|
|
1329
1351
|
this.adapter = storageAdapter;
|
|
@@ -1387,6 +1409,17 @@ var DyncBase = class {
|
|
|
1387
1409
|
storesDefined = true;
|
|
1388
1410
|
self.adapter.defineSchema(versionNumber, fullSchema, schemaOptions);
|
|
1389
1411
|
self.setupEnhancedTables(Object.keys(schema));
|
|
1412
|
+
for (const tableName of Object.keys(schema)) {
|
|
1413
|
+
if (!(tableName in self)) {
|
|
1414
|
+
Object.defineProperty(self, tableName, {
|
|
1415
|
+
get() {
|
|
1416
|
+
return self.table(tableName);
|
|
1417
|
+
},
|
|
1418
|
+
enumerable: true,
|
|
1419
|
+
configurable: false
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1390
1423
|
return builder;
|
|
1391
1424
|
},
|
|
1392
1425
|
sqlite(configure) {
|
|
@@ -1725,8 +1758,7 @@ var DyncBase = class {
|
|
|
1725
1758
|
onMutation: this.onMutation.bind(this)
|
|
1726
1759
|
};
|
|
1727
1760
|
};
|
|
1728
|
-
var
|
|
1729
|
-
var Dync = DyncConstructor;
|
|
1761
|
+
var Dync = DyncBase;
|
|
1730
1762
|
|
|
1731
1763
|
// src/storage/memory/MemoryQueryContext.ts
|
|
1732
1764
|
var MemoryQueryContext = class {
|