@anfenn/dync 1.0.24 → 1.0.26
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 +10 -6
- package/dist/{dexie-DRLMKLl5.d.ts → dexie-B1FuZqDB.d.ts} +1 -1
- package/dist/{dexie-BqktVP7s.d.cts → dexie-DtgGGM68.d.cts} +1 -1
- package/dist/dexie.d.cts +1 -1
- package/dist/dexie.d.ts +1 -1
- package/dist/index.cjs +6 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +87 -3
- package/dist/index.d.ts +87 -3
- package/dist/index.js +3831 -10
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +36 -1729
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +65 -31
- package/dist/react/index.d.ts +65 -31
- package/dist/react/index.js +31 -41
- package/dist/react/index.js.map +1 -1
- package/dist/{index.shared-D-fB8Odd.d.ts → types-B1Vn8_DF.d.ts} +4 -85
- package/dist/{index.shared-DHuT0l_t.d.cts → types-BgGGLrE9.d.cts} +4 -85
- package/package.json +1 -1
- package/src/index.shared.ts +7 -1
- package/src/react/index.ts +3 -2
- package/src/react/types.ts +6 -0
- package/src/react/useLiveQuery.ts +97 -0
- package/src/react/useSyncState.ts +45 -0
- package/src/types.ts +2 -1
- package/dist/chunk-QA2TX54K.js +0 -3835
- package/dist/chunk-QA2TX54K.js.map +0 -1
- package/src/react/useDync.ts +0 -156
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@anfenn/dync)
|
|
4
4
|
|
|
5
|
-
A complete
|
|
5
|
+
A complete Typescript offline-first data layer with sync engine for any local storage (IndexedDB, Sqlite, etc.), and any backend (Restful, GraphQL, Supabase, etc.) in a Website, PWA, CapacitorJs, React Native, or Electron app.
|
|
6
6
|
|
|
7
7
|
Start with a Website or PWA using IndexedDB, sync with your existing REST API, and later ship native apps with encrypted SQLite - without changing a line of code.
|
|
8
8
|
|
|
@@ -48,7 +48,7 @@ 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 =
|
|
51
|
+
const db = new Dync(
|
|
52
52
|
...,
|
|
53
53
|
{
|
|
54
54
|
// Only add an entry here for tables that should be synced
|
|
@@ -60,13 +60,14 @@ 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
|
+
...,
|
|
63
64
|
);
|
|
64
65
|
```
|
|
65
66
|
|
|
66
67
|
- Option 2: Batch sync to remote /push & /pull endpoints:
|
|
67
68
|
|
|
68
69
|
```ts
|
|
69
|
-
const db =
|
|
70
|
+
const db = new Dync(
|
|
70
71
|
...,
|
|
71
72
|
{
|
|
72
73
|
syncTables: ['items'], // Only add tables to this array that should be synced
|
|
@@ -86,6 +87,7 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
86
87
|
return res.json();
|
|
87
88
|
},
|
|
88
89
|
},
|
|
90
|
+
...,
|
|
89
91
|
);
|
|
90
92
|
```
|
|
91
93
|
|
|
@@ -94,7 +96,7 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
94
96
|
- Full conflict resolution: `local-wins`, `remote-wins` or with `try-shallow-merge` the user can resolve with:
|
|
95
97
|
|
|
96
98
|
```ts
|
|
97
|
-
const
|
|
99
|
+
const syncState = useSyncState(db);
|
|
98
100
|
syncState.conflicts; // Record<localId, Conflict>
|
|
99
101
|
db.sync.resolveConflict(localId, true);
|
|
100
102
|
```
|
|
@@ -107,11 +109,12 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
107
109
|
|
|
108
110
|
```ts
|
|
109
111
|
useLiveQuery(
|
|
110
|
-
|
|
112
|
+
db,
|
|
113
|
+
async () => {
|
|
111
114
|
const items = await db.items.toArray(); // toArray() executes the query
|
|
112
115
|
setTodos(items);
|
|
113
116
|
},
|
|
114
|
-
[], // Re-run when variables change
|
|
117
|
+
[], // Re-run when variables change (None defined)
|
|
115
118
|
['items'], // Re-run when tables change
|
|
116
119
|
);
|
|
117
120
|
```
|
|
@@ -124,6 +127,7 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
124
127
|
|
|
125
128
|
- Full IndexedDB & SQL unified query language:
|
|
126
129
|
- Using IndexedDB functions or raw SQL will always be more expressive independently
|
|
130
|
+
- When required, best performance will always come from native api
|
|
127
131
|
- No need to learn another api when you might only need one storage type
|
|
128
132
|
- Would greatly increase complexity of this library
|
|
129
133
|
|
|
@@ -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,
|
|
443
|
+
export { DexieQueryContext as D, MemoryQueryContext as M, type StorageAdapter as S, type TableSchemaDefinition as T, SqliteQueryContext as a, type StorageTable as b, MemoryAdapter as c, SQLiteAdapter 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,
|
|
443
|
+
export { DexieQueryContext as D, MemoryQueryContext as M, type StorageAdapter as S, type TableSchemaDefinition as T, SqliteQueryContext as a, type StorageTable as b, MemoryAdapter as c, SQLiteAdapter as d, DexieAdapter as e };
|
package/dist/dexie.d.cts
CHANGED
package/dist/dexie.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1340,6 +1340,10 @@ var DyncBase = class {
|
|
|
1340
1340
|
this.state = new StateManager({
|
|
1341
1341
|
storageAdapter: this.adapter
|
|
1342
1342
|
});
|
|
1343
|
+
Object.defineProperty(this.sync, "state", {
|
|
1344
|
+
get: () => this.getSyncState(),
|
|
1345
|
+
enumerable: true
|
|
1346
|
+
});
|
|
1343
1347
|
const driverInfo = "driverType" in this.adapter ? ` (Driver: ${this.adapter.driverType})` : "";
|
|
1344
1348
|
this.logger.debug(`[dync] Initialized with ${this.adapter.type}${driverInfo}`);
|
|
1345
1349
|
}
|
|
@@ -1714,7 +1718,8 @@ var DyncBase = class {
|
|
|
1714
1718
|
sync = {
|
|
1715
1719
|
enable: this.enableSync.bind(this),
|
|
1716
1720
|
startFirstLoad: this.startFirstLoad.bind(this),
|
|
1717
|
-
|
|
1721
|
+
state: void 0,
|
|
1722
|
+
// getter in constructor
|
|
1718
1723
|
resolveConflict: this.resolveConflict.bind(this),
|
|
1719
1724
|
onStateChange: this.onSyncStateChange.bind(this),
|
|
1720
1725
|
onMutation: this.onMutation.bind(this)
|