@anfenn/dync 1.0.4 → 1.0.5
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 +1 -1
- 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/dist/index.cjs
CHANGED
|
@@ -56,7 +56,7 @@ var UPDATED_AT = "updated_at";
|
|
|
56
56
|
var SyncAction = /* @__PURE__ */ ((SyncAction2) => {
|
|
57
57
|
SyncAction2["Create"] = "create";
|
|
58
58
|
SyncAction2["Update"] = "update";
|
|
59
|
-
SyncAction2["
|
|
59
|
+
SyncAction2["Delete"] = "delete";
|
|
60
60
|
return SyncAction2;
|
|
61
61
|
})(SyncAction || {});
|
|
62
62
|
|
|
@@ -88,7 +88,7 @@ function orderFor(a) {
|
|
|
88
88
|
return 1;
|
|
89
89
|
case "update" /* Update */:
|
|
90
90
|
return 2;
|
|
91
|
-
case "
|
|
91
|
+
case "delete" /* Delete */:
|
|
92
92
|
return 3;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -191,17 +191,17 @@ var StateManager = class {
|
|
|
191
191
|
const hasChanges = Object.keys(omittedChanges || {}).length > 0;
|
|
192
192
|
const action = change.action;
|
|
193
193
|
if (queueItem) {
|
|
194
|
-
if (queueItem.action === "
|
|
194
|
+
if (queueItem.action === "delete" /* Delete */) {
|
|
195
195
|
return Promise.resolve();
|
|
196
196
|
}
|
|
197
197
|
queueItem.version += 1;
|
|
198
|
-
if (action === "
|
|
199
|
-
queueItem.action = "
|
|
198
|
+
if (action === "delete" /* Delete */) {
|
|
199
|
+
queueItem.action = "delete" /* Delete */;
|
|
200
200
|
} else if (hasChanges) {
|
|
201
201
|
queueItem.changes = { ...queueItem.changes, ...omittedChanges };
|
|
202
202
|
queueItem.after = { ...queueItem.after, ...omittedAfter };
|
|
203
203
|
}
|
|
204
|
-
} else if (action === "
|
|
204
|
+
} else if (action === "delete" /* Delete */ || hasChanges) {
|
|
205
205
|
next.pendingChanges = [...next.pendingChanges];
|
|
206
206
|
next.pendingChanges.push({
|
|
207
207
|
action,
|
|
@@ -499,7 +499,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
499
499
|
if (record) {
|
|
500
500
|
deletedLocalId = record._localId;
|
|
501
501
|
await state.addPendingChange({
|
|
502
|
-
action: "
|
|
502
|
+
action: "delete" /* Delete */,
|
|
503
503
|
tableName,
|
|
504
504
|
localId: record._localId,
|
|
505
505
|
id: record.id,
|
|
@@ -634,7 +634,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
634
634
|
if (record) {
|
|
635
635
|
deletedLocalIds.push(record._localId);
|
|
636
636
|
await state.addPendingChange({
|
|
637
|
-
action: "
|
|
637
|
+
action: "delete" /* Delete */,
|
|
638
638
|
tableName,
|
|
639
639
|
localId: record._localId,
|
|
640
640
|
id: record.id,
|
|
@@ -658,7 +658,7 @@ function enhanceSyncTable({ table, tableName, withTransaction, state, enhancedTa
|
|
|
658
658
|
if (record._localId) {
|
|
659
659
|
deletedLocalIds.push(record._localId);
|
|
660
660
|
await state.addPendingChange({
|
|
661
|
-
action: "
|
|
661
|
+
action: "delete" /* Delete */,
|
|
662
662
|
tableName,
|
|
663
663
|
localId: record._localId,
|
|
664
664
|
id: record.id,
|
|
@@ -791,20 +791,20 @@ async function processPullData(tableName, serverData, since, ctx) {
|
|
|
791
791
|
await ctx.withTransaction("rw", [tableName, DYNC_STATE_TABLE], async (tables) => {
|
|
792
792
|
const txTable = tables[tableName];
|
|
793
793
|
const pendingRemovalById = new Set(
|
|
794
|
-
ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "
|
|
794
|
+
ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "delete" /* Delete */).map((p) => p.id)
|
|
795
795
|
);
|
|
796
796
|
for (const remote of serverData) {
|
|
797
797
|
const remoteUpdated = new Date(remote.updated_at);
|
|
798
798
|
if (remoteUpdated > newest) newest = remoteUpdated;
|
|
799
799
|
if (pendingRemovalById.has(remote.id)) {
|
|
800
|
-
ctx.logger.debug(`[dync] pull:skip-pending-
|
|
800
|
+
ctx.logger.debug(`[dync] pull:skip-pending-delete tableName=${tableName} id=${remote.id}`);
|
|
801
801
|
continue;
|
|
802
802
|
}
|
|
803
803
|
const localItem = await txTable.where("id").equals(remote.id).first();
|
|
804
804
|
if (remote.deleted) {
|
|
805
805
|
if (localItem) {
|
|
806
806
|
await txTable.raw.delete(localItem._localId);
|
|
807
|
-
ctx.logger.debug(`[dync] pull:
|
|
807
|
+
ctx.logger.debug(`[dync] pull:delete tableName=${tableName} id=${remote.id}`);
|
|
808
808
|
hasChanges = true;
|
|
809
809
|
}
|
|
810
810
|
continue;
|
|
@@ -832,9 +832,9 @@ async function processPullData(tableName, serverData, since, ctx) {
|
|
|
832
832
|
}
|
|
833
833
|
|
|
834
834
|
// src/core/pushOperations.ts
|
|
835
|
-
async function
|
|
835
|
+
async function handleDeleteSuccess(change, ctx) {
|
|
836
836
|
const { tableName, localId, id } = change;
|
|
837
|
-
ctx.logger.debug(`[dync] push:
|
|
837
|
+
ctx.logger.debug(`[dync] push:delete:success tableName=${tableName} localId=${localId} id=${id}`);
|
|
838
838
|
await ctx.state.removePendingChange(localId, tableName);
|
|
839
839
|
}
|
|
840
840
|
async function handleUpdateSuccess(change, ctx) {
|
|
@@ -855,9 +855,9 @@ async function handleCreateSuccess(change, serverResult, ctx) {
|
|
|
855
855
|
if (wasChanged && ctx.state.samePendingVersion(tableName, localId, version)) {
|
|
856
856
|
await ctx.state.removePendingChange(localId, tableName);
|
|
857
857
|
} else {
|
|
858
|
-
const nextAction = wasChanged ? "update" /* Update */ : "
|
|
858
|
+
const nextAction = wasChanged ? "update" /* Update */ : "delete" /* Delete */;
|
|
859
859
|
await ctx.state.updatePendingChange(tableName, localId, nextAction, serverResult.id);
|
|
860
|
-
if (nextAction === "
|
|
860
|
+
if (nextAction === "delete" /* Delete */) return;
|
|
861
861
|
}
|
|
862
862
|
});
|
|
863
863
|
const finalItem = { ...changes, ...serverResult, _localId: localId };
|
|
@@ -882,14 +882,14 @@ async function pushOne(change, ctx) {
|
|
|
882
882
|
ctx.logger.debug(`[dync] push:attempt action=${change.action} tableName=${change.tableName} localId=${change.localId}`);
|
|
883
883
|
const { action, tableName, localId, id, changes, after } = change;
|
|
884
884
|
switch (action) {
|
|
885
|
-
case "
|
|
885
|
+
case "delete" /* Delete */:
|
|
886
886
|
if (!id) {
|
|
887
|
-
ctx.logger.warn(`[dync] push:
|
|
887
|
+
ctx.logger.warn(`[dync] push:delete:no-id tableName=${tableName} localId=${localId}`);
|
|
888
888
|
await ctx.state.removePendingChange(localId, tableName);
|
|
889
889
|
return;
|
|
890
890
|
}
|
|
891
|
-
await api.
|
|
892
|
-
await
|
|
891
|
+
await api.delete(id);
|
|
892
|
+
await handleDeleteSuccess(change, ctx);
|
|
893
893
|
break;
|
|
894
894
|
case "update" /* Update */: {
|
|
895
895
|
if (ctx.state.hasConflicts(localId)) {
|
|
@@ -985,10 +985,10 @@ async function pushAllBatch(ctx) {
|
|
|
985
985
|
}
|
|
986
986
|
const payloads = changesToPush.map((change) => ({
|
|
987
987
|
table: change.tableName,
|
|
988
|
-
action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "
|
|
988
|
+
action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "delete",
|
|
989
989
|
localId: change.localId,
|
|
990
990
|
id: change.id,
|
|
991
|
-
data: change.action === "
|
|
991
|
+
data: change.action === "delete" /* Delete */ ? void 0 : change.changes
|
|
992
992
|
}));
|
|
993
993
|
ctx.logger.debug(`[dync] push:batch:start count=${payloads.length}`);
|
|
994
994
|
const results = await ctx.batchSync.push(payloads);
|
|
@@ -1026,11 +1026,11 @@ async function processBatchPushResult(change, result, ctx) {
|
|
|
1026
1026
|
return;
|
|
1027
1027
|
}
|
|
1028
1028
|
switch (action) {
|
|
1029
|
-
case "
|
|
1030
|
-
|
|
1029
|
+
case "delete" /* Delete */:
|
|
1030
|
+
await handleDeleteSuccess(change, ctx);
|
|
1031
1031
|
break;
|
|
1032
1032
|
case "update" /* Update */:
|
|
1033
|
-
handleUpdateSuccess(change, ctx);
|
|
1033
|
+
await handleUpdateSuccess(change, ctx);
|
|
1034
1034
|
break;
|
|
1035
1035
|
case "create" /* Create */: {
|
|
1036
1036
|
const serverResult = { id: result.id };
|