@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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@anfenn/dync.svg)](https://www.npmjs.com/package/@anfenn/dync)
4
4
 
5
- A complete React 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.
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 = makeDync(
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 = makeDync(
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 { syncState, db } = useDync();
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
- async (db) => {
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, MemoryAdapter as M, SQLiteAdapter as S, type TableSchemaDefinition as T, MemoryQueryContext as a, SqliteQueryContext as b, type StorageAdapter as c, type StorageTable as d, DexieAdapter as e };
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, MemoryAdapter as M, SQLiteAdapter as S, type TableSchemaDefinition as T, MemoryQueryContext as a, SqliteQueryContext as b, type StorageAdapter as c, type StorageTable as d, DexieAdapter as e };
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
@@ -1,3 +1,3 @@
1
- export { e as DexieAdapter, D as DexieQueryContext, c as StorageAdapter } from './dexie-BqktVP7s.cjs';
1
+ export { e as DexieAdapter, D as DexieQueryContext, S as StorageAdapter } from './dexie-DtgGGM68.cjs';
2
2
  import 'dexie';
3
3
  import './types-CSbIAfu2.cjs';
package/dist/dexie.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { e as DexieAdapter, D as DexieQueryContext, c as StorageAdapter } from './dexie-DRLMKLl5.js';
1
+ export { e as DexieAdapter, D as DexieQueryContext, S as StorageAdapter } from './dexie-B1FuZqDB.js';
2
2
  import 'dexie';
3
3
  import './types-CSbIAfu2.js';
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
- getState: this.getSyncState.bind(this),
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)