@anfenn/dync 1.0.6 → 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/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["Delete"] = "delete";
59
+ SyncAction2["Remove"] = "remove";
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 "delete" /* Delete */:
91
+ case "remove" /* Remove */:
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 === "delete" /* Delete */) {
194
+ if (queueItem.action === "remove" /* Remove */) {
195
195
  return Promise.resolve();
196
196
  }
197
197
  queueItem.version += 1;
198
- if (action === "delete" /* Delete */) {
199
- queueItem.action = "delete" /* Delete */;
198
+ if (action === "remove" /* Remove */) {
199
+ queueItem.action = "remove" /* Remove */;
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 === "delete" /* Delete */ || hasChanges) {
204
+ } else if (action === "remove" /* Remove */ || 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: "delete" /* Delete */,
502
+ action: "remove" /* Remove */,
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: "delete" /* Delete */,
637
+ action: "remove" /* Remove */,
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: "delete" /* Delete */,
661
+ action: "remove" /* Remove */,
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 === "delete" /* Delete */).map((p) => p.id)
794
+ ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "remove" /* Remove */).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-delete tableName=${tableName} id=${remote.id}`);
800
+ ctx.logger.debug(`[dync] pull:skip-pending-remove 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:delete tableName=${tableName} id=${remote.id}`);
807
+ ctx.logger.debug(`[dync] pull:remove 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 handleDeleteSuccess(change, ctx) {
835
+ async function handleRemoveSuccess(change, ctx) {
836
836
  const { tableName, localId, id } = change;
837
- ctx.logger.debug(`[dync] push:delete:success tableName=${tableName} localId=${localId} id=${id}`);
837
+ ctx.logger.debug(`[dync] push:remove: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 */ : "delete" /* Delete */;
858
+ const nextAction = wasChanged ? "update" /* Update */ : "remove" /* Remove */;
859
859
  await ctx.state.updatePendingChange(tableName, localId, nextAction, serverResult.id);
860
- if (nextAction === "delete" /* Delete */) return;
860
+ if (nextAction === "remove" /* Remove */) 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 "delete" /* Delete */:
885
+ case "remove" /* Remove */:
886
886
  if (!id) {
887
- ctx.logger.warn(`[dync] push:delete:no-id tableName=${tableName} localId=${localId}`);
887
+ ctx.logger.warn(`[dync] push:remove:no-id tableName=${tableName} localId=${localId}`);
888
888
  await ctx.state.removePendingChange(localId, tableName);
889
889
  return;
890
890
  }
891
- await api.delete(id);
892
- await handleDeleteSuccess(change, ctx);
891
+ await api.remove(id);
892
+ await handleRemoveSuccess(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" : "delete",
988
+ action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "remove",
989
989
  localId: change.localId,
990
990
  id: change.id,
991
- data: change.action === "delete" /* Delete */ ? void 0 : change.changes
991
+ data: change.action === "remove" /* Remove */ ? 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 "delete" /* Delete */:
1030
- await handleDeleteSuccess(change, ctx);
1029
+ case "remove" /* Remove */:
1030
+ handleRemoveSuccess(change, ctx);
1031
1031
  break;
1032
1032
  case "update" /* Update */:
1033
- await handleUpdateSuccess(change, ctx);
1033
+ handleUpdateSuccess(change, ctx);
1034
1034
  break;
1035
1035
  case "create" /* Create */: {
1036
1036
  const serverResult = { id: result.id };