@anfenn/dync 1.0.4 → 1.0.6
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-PCA4XM2N.js → chunk-YAAFAS64.js} +26 -26
- package/dist/chunk-YAAFAS64.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-Byhq6TyU.d.ts → index.shared-3gbnIINY.d.ts} +3 -3
- package/dist/{index.shared-DsDBNWlz.d.cts → index.shared-XsB8HrvX.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-PCA4XM2N.js.map +0 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ And see how Dync compares to the alternatives [below](#hasnt-this-already-been-d
|
|
|
56
56
|
items: {
|
|
57
57
|
add: (item) => fetch('/api/items'),
|
|
58
58
|
update: (id, changes) => fetch(`/api/items/${id}`),
|
|
59
|
-
|
|
59
|
+
delete: (id) => fetch(`/api/items/${id}`),
|
|
60
60
|
list: (since) => fetch(`/api/items?since=${since}`),
|
|
61
61
|
},
|
|
62
62
|
},
|
|
@@ -24,7 +24,7 @@ var UPDATED_AT = "updated_at";
|
|
|
24
24
|
var SyncAction = /* @__PURE__ */ ((SyncAction2) => {
|
|
25
25
|
SyncAction2["Create"] = "create";
|
|
26
26
|
SyncAction2["Update"] = "update";
|
|
27
|
-
SyncAction2["
|
|
27
|
+
SyncAction2["Delete"] = "delete";
|
|
28
28
|
return SyncAction2;
|
|
29
29
|
})(SyncAction || {});
|
|
30
30
|
|
|
@@ -56,7 +56,7 @@ function orderFor(a) {
|
|
|
56
56
|
return 1;
|
|
57
57
|
case "update" /* Update */:
|
|
58
58
|
return 2;
|
|
59
|
-
case "
|
|
59
|
+
case "delete" /* Delete */:
|
|
60
60
|
return 3;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -159,17 +159,17 @@ var StateManager = class {
|
|
|
159
159
|
const hasChanges = Object.keys(omittedChanges || {}).length > 0;
|
|
160
160
|
const action = change.action;
|
|
161
161
|
if (queueItem) {
|
|
162
|
-
if (queueItem.action === "
|
|
162
|
+
if (queueItem.action === "delete" /* Delete */) {
|
|
163
163
|
return Promise.resolve();
|
|
164
164
|
}
|
|
165
165
|
queueItem.version += 1;
|
|
166
|
-
if (action === "
|
|
167
|
-
queueItem.action = "
|
|
166
|
+
if (action === "delete" /* Delete */) {
|
|
167
|
+
queueItem.action = "delete" /* Delete */;
|
|
168
168
|
} else if (hasChanges) {
|
|
169
169
|
queueItem.changes = { ...queueItem.changes, ...omittedChanges };
|
|
170
170
|
queueItem.after = { ...queueItem.after, ...omittedAfter };
|
|
171
171
|
}
|
|
172
|
-
} else if (action === "
|
|
172
|
+
} else if (action === "delete" /* Delete */ || hasChanges) {
|
|
173
173
|
next.pendingChanges = [...next.pendingChanges];
|
|
174
174
|
next.pendingChanges.push({
|
|
175
175
|
action,
|
|
@@ -467,7 +467,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
467
467
|
if (record) {
|
|
468
468
|
deletedLocalId = record._localId;
|
|
469
469
|
await state.addPendingChange({
|
|
470
|
-
action: "
|
|
470
|
+
action: "delete" /* Delete */,
|
|
471
471
|
tableName,
|
|
472
472
|
localId: record._localId,
|
|
473
473
|
id: record.id,
|
|
@@ -602,7 +602,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
602
602
|
if (record) {
|
|
603
603
|
deletedLocalIds.push(record._localId);
|
|
604
604
|
await state.addPendingChange({
|
|
605
|
-
action: "
|
|
605
|
+
action: "delete" /* Delete */,
|
|
606
606
|
tableName,
|
|
607
607
|
localId: record._localId,
|
|
608
608
|
id: record.id,
|
|
@@ -626,7 +626,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
626
626
|
if (record._localId) {
|
|
627
627
|
deletedLocalIds.push(record._localId);
|
|
628
628
|
await state.addPendingChange({
|
|
629
|
-
action: "
|
|
629
|
+
action: "delete" /* Delete */,
|
|
630
630
|
tableName,
|
|
631
631
|
localId: record._localId,
|
|
632
632
|
id: record.id,
|
|
@@ -759,20 +759,20 @@ async function processPullData(tableName, serverData, since, ctx) {
|
|
|
759
759
|
await ctx.withTransaction("rw", [tableName, DYNC_STATE_TABLE], async (tables) => {
|
|
760
760
|
const txTable = tables[tableName];
|
|
761
761
|
const pendingRemovalById = new Set(
|
|
762
|
-
ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "
|
|
762
|
+
ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "delete" /* Delete */).map((p) => p.id)
|
|
763
763
|
);
|
|
764
764
|
for (const remote of serverData) {
|
|
765
765
|
const remoteUpdated = new Date(remote.updated_at);
|
|
766
766
|
if (remoteUpdated > newest) newest = remoteUpdated;
|
|
767
767
|
if (pendingRemovalById.has(remote.id)) {
|
|
768
|
-
ctx.logger.debug(`[dync] pull:skip-pending-
|
|
768
|
+
ctx.logger.debug(`[dync] pull:skip-pending-delete tableName=${tableName} id=${remote.id}`);
|
|
769
769
|
continue;
|
|
770
770
|
}
|
|
771
771
|
const localItem = await txTable.where("id").equals(remote.id).first();
|
|
772
772
|
if (remote.deleted) {
|
|
773
773
|
if (localItem) {
|
|
774
774
|
await txTable.raw.delete(localItem._localId);
|
|
775
|
-
ctx.logger.debug(`[dync] pull:
|
|
775
|
+
ctx.logger.debug(`[dync] pull:delete tableName=${tableName} id=${remote.id}`);
|
|
776
776
|
hasChanges = true;
|
|
777
777
|
}
|
|
778
778
|
continue;
|
|
@@ -800,9 +800,9 @@ async function processPullData(tableName, serverData, since, ctx) {
|
|
|
800
800
|
}
|
|
801
801
|
|
|
802
802
|
// src/core/pushOperations.ts
|
|
803
|
-
async function
|
|
803
|
+
async function handleDeleteSuccess(change, ctx) {
|
|
804
804
|
const { tableName, localId, id } = change;
|
|
805
|
-
ctx.logger.debug(`[dync] push:
|
|
805
|
+
ctx.logger.debug(`[dync] push:delete:success tableName=${tableName} localId=${localId} id=${id}`);
|
|
806
806
|
await ctx.state.removePendingChange(localId, tableName);
|
|
807
807
|
}
|
|
808
808
|
async function handleUpdateSuccess(change, ctx) {
|
|
@@ -823,9 +823,9 @@ async function handleCreateSuccess(change, serverResult, ctx) {
|
|
|
823
823
|
if (wasChanged && ctx.state.samePendingVersion(tableName, localId, version)) {
|
|
824
824
|
await ctx.state.removePendingChange(localId, tableName);
|
|
825
825
|
} else {
|
|
826
|
-
const nextAction = wasChanged ? "update" /* Update */ : "
|
|
826
|
+
const nextAction = wasChanged ? "update" /* Update */ : "delete" /* Delete */;
|
|
827
827
|
await ctx.state.updatePendingChange(tableName, localId, nextAction, serverResult.id);
|
|
828
|
-
if (nextAction === "
|
|
828
|
+
if (nextAction === "delete" /* Delete */) return;
|
|
829
829
|
}
|
|
830
830
|
});
|
|
831
831
|
const finalItem = { ...changes, ...serverResult, _localId: localId };
|
|
@@ -850,14 +850,14 @@ async function pushOne(change, ctx) {
|
|
|
850
850
|
ctx.logger.debug(`[dync] push:attempt action=${change.action} tableName=${change.tableName} localId=${change.localId}`);
|
|
851
851
|
const { action, tableName, localId, id, changes, after } = change;
|
|
852
852
|
switch (action) {
|
|
853
|
-
case "
|
|
853
|
+
case "delete" /* Delete */:
|
|
854
854
|
if (!id) {
|
|
855
|
-
ctx.logger.warn(`[dync] push:
|
|
855
|
+
ctx.logger.warn(`[dync] push:delete:no-id tableName=${tableName} localId=${localId}`);
|
|
856
856
|
await ctx.state.removePendingChange(localId, tableName);
|
|
857
857
|
return;
|
|
858
858
|
}
|
|
859
|
-
await api.
|
|
860
|
-
await
|
|
859
|
+
await api.delete(id);
|
|
860
|
+
await handleDeleteSuccess(change, ctx);
|
|
861
861
|
break;
|
|
862
862
|
case "update" /* Update */: {
|
|
863
863
|
if (ctx.state.hasConflicts(localId)) {
|
|
@@ -953,10 +953,10 @@ async function pushAllBatch(ctx) {
|
|
|
953
953
|
}
|
|
954
954
|
const payloads = changesToPush.map((change) => ({
|
|
955
955
|
table: change.tableName,
|
|
956
|
-
action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "
|
|
956
|
+
action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "delete",
|
|
957
957
|
localId: change.localId,
|
|
958
958
|
id: change.id,
|
|
959
|
-
data: change.action === "
|
|
959
|
+
data: change.action === "delete" /* Delete */ ? void 0 : change.changes
|
|
960
960
|
}));
|
|
961
961
|
ctx.logger.debug(`[dync] push:batch:start count=${payloads.length}`);
|
|
962
962
|
const results = await ctx.batchSync.push(payloads);
|
|
@@ -994,11 +994,11 @@ async function processBatchPushResult(change, result, ctx) {
|
|
|
994
994
|
return;
|
|
995
995
|
}
|
|
996
996
|
switch (action) {
|
|
997
|
-
case "
|
|
998
|
-
|
|
997
|
+
case "delete" /* Delete */:
|
|
998
|
+
await handleDeleteSuccess(change, ctx);
|
|
999
999
|
break;
|
|
1000
1000
|
case "update" /* Update */:
|
|
1001
|
-
handleUpdateSuccess(change, ctx);
|
|
1001
|
+
await handleUpdateSuccess(change, ctx);
|
|
1002
1002
|
break;
|
|
1003
1003
|
case "create" /* Create */: {
|
|
1004
1004
|
const serverResult = { id: result.id };
|
|
@@ -3881,4 +3881,4 @@ export {
|
|
|
3881
3881
|
SqliteQueryContext,
|
|
3882
3882
|
SQLiteAdapter2 as SQLiteAdapter
|
|
3883
3883
|
};
|
|
3884
|
-
//# sourceMappingURL=chunk-
|
|
3884
|
+
//# sourceMappingURL=chunk-YAAFAS64.js.map
|