@anfenn/dync 1.0.5 → 1.0.7
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 +1 -1
- package/dist/{chunk-YAAFAS64.js → chunk-PCA4XM2N.js} +26 -26
- package/dist/chunk-PCA4XM2N.js.map +1 -0
- package/dist/index.cjs +25 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{index.shared-3gbnIINY.d.ts → index.shared-Byhq6TyU.d.ts} +3 -3
- package/dist/{index.shared-XsB8HrvX.d.cts → index.shared-DsDBNWlz.d.cts} +3 -3
- package/dist/react/index.cjs +24 -24
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/dist/wa-sqlite.cjs +2 -2
- package/dist/wa-sqlite.cjs.map +1 -1
- package/dist/wa-sqlite.d.cts +2 -2
- package/dist/wa-sqlite.d.ts +2 -2
- package/dist/wa-sqlite.js +2 -2
- package/dist/wa-sqlite.js.map +1 -1
- package/package.json +33 -2
- package/src/core/StateManager.ts +4 -4
- package/src/core/pullOperations.ts +3 -3
- package/src/core/pushOperations.ts +13 -13
- package/src/core/tableEnhancers.ts +3 -3
- package/src/helpers.ts +1 -1
- package/src/storage/sqlite/drivers/WaSqliteDriver.ts +6 -6
- package/src/types.ts +4 -4
- package/dist/chunk-YAAFAS64.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AfterRemoteAddCallback, a as ApiFunctions, d as BatchFirstLoadResult, b as BatchPushPayload, c as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, D as Dync, F as FirstLoadProgress, e as FirstLoadProgressCallback, f as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, g as MutationEvent, S as SyncAction, h as SyncOptions, i as SyncState, j as SyncedRecord, T as TableMap } from './index.shared-
|
|
1
|
+
export { A as AfterRemoteAddCallback, a as ApiFunctions, d as BatchFirstLoadResult, b as BatchPushPayload, c as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, D as Dync, F as FirstLoadProgress, e as FirstLoadProgressCallback, f as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, g as MutationEvent, S as SyncAction, h as SyncOptions, i as SyncState, j as SyncedRecord, T as TableMap } from './index.shared-DsDBNWlz.cjs';
|
|
2
2
|
export { M as MemoryAdapter, a as MemoryQueryContext, S as SQLiteAdapter, b as SqliteQueryContext, c as StorageAdapter } from './dexie-1_xyU5MV.cjs';
|
|
3
3
|
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-CSbIAfu2.cjs';
|
|
4
4
|
import 'dexie';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AfterRemoteAddCallback, a as ApiFunctions, d as BatchFirstLoadResult, b as BatchPushPayload, c as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, D as Dync, F as FirstLoadProgress, e as FirstLoadProgressCallback, f as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, g as MutationEvent, S as SyncAction, h as SyncOptions, i as SyncState, j as SyncedRecord, T as TableMap } from './index.shared-
|
|
1
|
+
export { A as AfterRemoteAddCallback, a as ApiFunctions, d as BatchFirstLoadResult, b as BatchPushPayload, c as BatchPushResult, B as BatchSync, C as ConflictResolutionStrategy, D as Dync, F as FirstLoadProgress, e as FirstLoadProgressCallback, f as MissingRemoteRecordDuringUpdateCallback, M as MissingRemoteRecordStrategy, g as MutationEvent, S as SyncAction, h as SyncOptions, i as SyncState, j as SyncedRecord, T as TableMap } from './index.shared-Byhq6TyU.js';
|
|
2
2
|
export { M as MemoryAdapter, a as MemoryQueryContext, S as SQLiteAdapter, b as SqliteQueryContext, c as StorageAdapter } from './dexie-ChZ0o0Sz.js';
|
|
3
3
|
export { S as SQLiteDatabaseDriver, b as SQLiteQueryResult, a as SQLiteRunResult } from './types-CSbIAfu2.js';
|
|
4
4
|
import 'dexie';
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ interface SyncedRecord {
|
|
|
18
18
|
interface ApiFunctions {
|
|
19
19
|
add: (item: any) => Promise<any | undefined>;
|
|
20
20
|
update: (id: any, changes: any, item: any) => Promise<boolean>;
|
|
21
|
-
|
|
21
|
+
remove: (id: any) => Promise<void>;
|
|
22
22
|
list: (lastUpdatedAt: Date) => Promise<any[]>;
|
|
23
23
|
firstLoad?: (lastId: any) => Promise<any[]>;
|
|
24
24
|
}
|
|
@@ -27,7 +27,7 @@ interface ApiFunctions {
|
|
|
27
27
|
*/
|
|
28
28
|
interface BatchPushPayload {
|
|
29
29
|
table: string;
|
|
30
|
-
action: 'add' | 'update' | '
|
|
30
|
+
action: 'add' | 'update' | 'remove';
|
|
31
31
|
localId: string;
|
|
32
32
|
id?: any;
|
|
33
33
|
data?: any;
|
|
@@ -125,7 +125,7 @@ interface SyncState extends PersistedSyncState {
|
|
|
125
125
|
declare enum SyncAction {
|
|
126
126
|
Create = "create",
|
|
127
127
|
Update = "update",
|
|
128
|
-
|
|
128
|
+
Remove = "remove"
|
|
129
129
|
}
|
|
130
130
|
interface PendingChange {
|
|
131
131
|
action: SyncAction;
|
|
@@ -18,7 +18,7 @@ interface SyncedRecord {
|
|
|
18
18
|
interface ApiFunctions {
|
|
19
19
|
add: (item: any) => Promise<any | undefined>;
|
|
20
20
|
update: (id: any, changes: any, item: any) => Promise<boolean>;
|
|
21
|
-
|
|
21
|
+
remove: (id: any) => Promise<void>;
|
|
22
22
|
list: (lastUpdatedAt: Date) => Promise<any[]>;
|
|
23
23
|
firstLoad?: (lastId: any) => Promise<any[]>;
|
|
24
24
|
}
|
|
@@ -27,7 +27,7 @@ interface ApiFunctions {
|
|
|
27
27
|
*/
|
|
28
28
|
interface BatchPushPayload {
|
|
29
29
|
table: string;
|
|
30
|
-
action: 'add' | 'update' | '
|
|
30
|
+
action: 'add' | 'update' | 'remove';
|
|
31
31
|
localId: string;
|
|
32
32
|
id?: any;
|
|
33
33
|
data?: any;
|
|
@@ -125,7 +125,7 @@ interface SyncState extends PersistedSyncState {
|
|
|
125
125
|
declare enum SyncAction {
|
|
126
126
|
Create = "create",
|
|
127
127
|
Update = "update",
|
|
128
|
-
|
|
128
|
+
Remove = "remove"
|
|
129
129
|
}
|
|
130
130
|
interface PendingChange {
|
|
131
131
|
action: SyncAction;
|
package/dist/react/index.cjs
CHANGED
|
@@ -79,7 +79,7 @@ function orderFor(a) {
|
|
|
79
79
|
return 1;
|
|
80
80
|
case "update" /* Update */:
|
|
81
81
|
return 2;
|
|
82
|
-
case "
|
|
82
|
+
case "remove" /* Remove */:
|
|
83
83
|
return 3;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -182,17 +182,17 @@ var StateManager = class {
|
|
|
182
182
|
const hasChanges = Object.keys(omittedChanges || {}).length > 0;
|
|
183
183
|
const action = change.action;
|
|
184
184
|
if (queueItem) {
|
|
185
|
-
if (queueItem.action === "
|
|
185
|
+
if (queueItem.action === "remove" /* Remove */) {
|
|
186
186
|
return Promise.resolve();
|
|
187
187
|
}
|
|
188
188
|
queueItem.version += 1;
|
|
189
|
-
if (action === "
|
|
190
|
-
queueItem.action = "
|
|
189
|
+
if (action === "remove" /* Remove */) {
|
|
190
|
+
queueItem.action = "remove" /* Remove */;
|
|
191
191
|
} else if (hasChanges) {
|
|
192
192
|
queueItem.changes = { ...queueItem.changes, ...omittedChanges };
|
|
193
193
|
queueItem.after = { ...queueItem.after, ...omittedAfter };
|
|
194
194
|
}
|
|
195
|
-
} else if (action === "
|
|
195
|
+
} else if (action === "remove" /* Remove */ || hasChanges) {
|
|
196
196
|
next.pendingChanges = [...next.pendingChanges];
|
|
197
197
|
next.pendingChanges.push({
|
|
198
198
|
action,
|
|
@@ -490,7 +490,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
490
490
|
if (record) {
|
|
491
491
|
deletedLocalId = record._localId;
|
|
492
492
|
await state.addPendingChange({
|
|
493
|
-
action: "
|
|
493
|
+
action: "remove" /* Remove */,
|
|
494
494
|
tableName,
|
|
495
495
|
localId: record._localId,
|
|
496
496
|
id: record.id,
|
|
@@ -625,7 +625,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
625
625
|
if (record) {
|
|
626
626
|
deletedLocalIds.push(record._localId);
|
|
627
627
|
await state.addPendingChange({
|
|
628
|
-
action: "
|
|
628
|
+
action: "remove" /* Remove */,
|
|
629
629
|
tableName,
|
|
630
630
|
localId: record._localId,
|
|
631
631
|
id: record.id,
|
|
@@ -649,7 +649,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
649
649
|
if (record._localId) {
|
|
650
650
|
deletedLocalIds.push(record._localId);
|
|
651
651
|
await state.addPendingChange({
|
|
652
|
-
action: "
|
|
652
|
+
action: "remove" /* Remove */,
|
|
653
653
|
tableName,
|
|
654
654
|
localId: record._localId,
|
|
655
655
|
id: record.id,
|
|
@@ -782,20 +782,20 @@ async function processPullData(tableName, serverData, since, ctx) {
|
|
|
782
782
|
await ctx.withTransaction("rw", [tableName, DYNC_STATE_TABLE], async (tables) => {
|
|
783
783
|
const txTable = tables[tableName];
|
|
784
784
|
const pendingRemovalById = new Set(
|
|
785
|
-
ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "
|
|
785
|
+
ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "remove" /* Remove */).map((p) => p.id)
|
|
786
786
|
);
|
|
787
787
|
for (const remote of serverData) {
|
|
788
788
|
const remoteUpdated = new Date(remote.updated_at);
|
|
789
789
|
if (remoteUpdated > newest) newest = remoteUpdated;
|
|
790
790
|
if (pendingRemovalById.has(remote.id)) {
|
|
791
|
-
ctx.logger.debug(`[dync] pull:skip-pending-
|
|
791
|
+
ctx.logger.debug(`[dync] pull:skip-pending-remove tableName=${tableName} id=${remote.id}`);
|
|
792
792
|
continue;
|
|
793
793
|
}
|
|
794
794
|
const localItem = await txTable.where("id").equals(remote.id).first();
|
|
795
795
|
if (remote.deleted) {
|
|
796
796
|
if (localItem) {
|
|
797
797
|
await txTable.raw.delete(localItem._localId);
|
|
798
|
-
ctx.logger.debug(`[dync] pull:
|
|
798
|
+
ctx.logger.debug(`[dync] pull:remove tableName=${tableName} id=${remote.id}`);
|
|
799
799
|
hasChanges = true;
|
|
800
800
|
}
|
|
801
801
|
continue;
|
|
@@ -823,9 +823,9 @@ async function processPullData(tableName, serverData, since, ctx) {
|
|
|
823
823
|
}
|
|
824
824
|
|
|
825
825
|
// src/core/pushOperations.ts
|
|
826
|
-
async function
|
|
826
|
+
async function handleRemoveSuccess(change, ctx) {
|
|
827
827
|
const { tableName, localId, id } = change;
|
|
828
|
-
ctx.logger.debug(`[dync] push:
|
|
828
|
+
ctx.logger.debug(`[dync] push:remove:success tableName=${tableName} localId=${localId} id=${id}`);
|
|
829
829
|
await ctx.state.removePendingChange(localId, tableName);
|
|
830
830
|
}
|
|
831
831
|
async function handleUpdateSuccess(change, ctx) {
|
|
@@ -846,9 +846,9 @@ async function handleCreateSuccess(change, serverResult, ctx) {
|
|
|
846
846
|
if (wasChanged && ctx.state.samePendingVersion(tableName, localId, version)) {
|
|
847
847
|
await ctx.state.removePendingChange(localId, tableName);
|
|
848
848
|
} else {
|
|
849
|
-
const nextAction = wasChanged ? "update" /* Update */ : "
|
|
849
|
+
const nextAction = wasChanged ? "update" /* Update */ : "remove" /* Remove */;
|
|
850
850
|
await ctx.state.updatePendingChange(tableName, localId, nextAction, serverResult.id);
|
|
851
|
-
if (nextAction === "
|
|
851
|
+
if (nextAction === "remove" /* Remove */) return;
|
|
852
852
|
}
|
|
853
853
|
});
|
|
854
854
|
const finalItem = { ...changes, ...serverResult, _localId: localId };
|
|
@@ -873,14 +873,14 @@ async function pushOne(change, ctx) {
|
|
|
873
873
|
ctx.logger.debug(`[dync] push:attempt action=${change.action} tableName=${change.tableName} localId=${change.localId}`);
|
|
874
874
|
const { action, tableName, localId, id, changes, after } = change;
|
|
875
875
|
switch (action) {
|
|
876
|
-
case "
|
|
876
|
+
case "remove" /* Remove */:
|
|
877
877
|
if (!id) {
|
|
878
|
-
ctx.logger.warn(`[dync] push:
|
|
878
|
+
ctx.logger.warn(`[dync] push:remove:no-id tableName=${tableName} localId=${localId}`);
|
|
879
879
|
await ctx.state.removePendingChange(localId, tableName);
|
|
880
880
|
return;
|
|
881
881
|
}
|
|
882
|
-
await api.
|
|
883
|
-
await
|
|
882
|
+
await api.remove(id);
|
|
883
|
+
await handleRemoveSuccess(change, ctx);
|
|
884
884
|
break;
|
|
885
885
|
case "update" /* Update */: {
|
|
886
886
|
if (ctx.state.hasConflicts(localId)) {
|
|
@@ -976,10 +976,10 @@ async function pushAllBatch(ctx) {
|
|
|
976
976
|
}
|
|
977
977
|
const payloads = changesToPush.map((change) => ({
|
|
978
978
|
table: change.tableName,
|
|
979
|
-
action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "
|
|
979
|
+
action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "remove",
|
|
980
980
|
localId: change.localId,
|
|
981
981
|
id: change.id,
|
|
982
|
-
data: change.action === "
|
|
982
|
+
data: change.action === "remove" /* Remove */ ? void 0 : change.changes
|
|
983
983
|
}));
|
|
984
984
|
ctx.logger.debug(`[dync] push:batch:start count=${payloads.length}`);
|
|
985
985
|
const results = await ctx.batchSync.push(payloads);
|
|
@@ -1017,11 +1017,11 @@ async function processBatchPushResult(change, result, ctx) {
|
|
|
1017
1017
|
return;
|
|
1018
1018
|
}
|
|
1019
1019
|
switch (action) {
|
|
1020
|
-
case "
|
|
1021
|
-
|
|
1020
|
+
case "remove" /* Remove */:
|
|
1021
|
+
handleRemoveSuccess(change, ctx);
|
|
1022
1022
|
break;
|
|
1023
1023
|
case "update" /* Update */:
|
|
1024
|
-
|
|
1024
|
+
handleUpdateSuccess(change, ctx);
|
|
1025
1025
|
break;
|
|
1026
1026
|
case "create" /* Create */: {
|
|
1027
1027
|
const serverResult = { id: result.id };
|