@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 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
- delete: (id) => fetch(`/api/items/${id}`),
59
+ remove: (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["Delete"] = "delete";
27
+ SyncAction2["Remove"] = "remove";
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 "delete" /* Delete */:
59
+ case "remove" /* Remove */:
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 === "delete" /* Delete */) {
162
+ if (queueItem.action === "remove" /* Remove */) {
163
163
  return Promise.resolve();
164
164
  }
165
165
  queueItem.version += 1;
166
- if (action === "delete" /* Delete */) {
167
- queueItem.action = "delete" /* Delete */;
166
+ if (action === "remove" /* Remove */) {
167
+ queueItem.action = "remove" /* Remove */;
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 === "delete" /* Delete */ || hasChanges) {
172
+ } else if (action === "remove" /* Remove */ || 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: "delete" /* Delete */,
470
+ action: "remove" /* Remove */,
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: "delete" /* Delete */,
605
+ action: "remove" /* Remove */,
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: "delete" /* Delete */,
629
+ action: "remove" /* Remove */,
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 === "delete" /* Delete */).map((p) => p.id)
762
+ ctx.state.getState().pendingChanges.filter((p) => p.tableName === tableName && p.action === "remove" /* Remove */).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-delete tableName=${tableName} id=${remote.id}`);
768
+ ctx.logger.debug(`[dync] pull:skip-pending-remove 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:delete tableName=${tableName} id=${remote.id}`);
775
+ ctx.logger.debug(`[dync] pull:remove 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 handleDeleteSuccess(change, ctx) {
803
+ async function handleRemoveSuccess(change, ctx) {
804
804
  const { tableName, localId, id } = change;
805
- ctx.logger.debug(`[dync] push:delete:success tableName=${tableName} localId=${localId} id=${id}`);
805
+ ctx.logger.debug(`[dync] push:remove: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 */ : "delete" /* Delete */;
826
+ const nextAction = wasChanged ? "update" /* Update */ : "remove" /* Remove */;
827
827
  await ctx.state.updatePendingChange(tableName, localId, nextAction, serverResult.id);
828
- if (nextAction === "delete" /* Delete */) return;
828
+ if (nextAction === "remove" /* Remove */) 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 "delete" /* Delete */:
853
+ case "remove" /* Remove */:
854
854
  if (!id) {
855
- ctx.logger.warn(`[dync] push:delete:no-id tableName=${tableName} localId=${localId}`);
855
+ ctx.logger.warn(`[dync] push:remove:no-id tableName=${tableName} localId=${localId}`);
856
856
  await ctx.state.removePendingChange(localId, tableName);
857
857
  return;
858
858
  }
859
- await api.delete(id);
860
- await handleDeleteSuccess(change, ctx);
859
+ await api.remove(id);
860
+ await handleRemoveSuccess(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" : "delete",
956
+ action: change.action === "create" /* Create */ ? "add" : change.action === "update" /* Update */ ? "update" : "remove",
957
957
  localId: change.localId,
958
958
  id: change.id,
959
- data: change.action === "delete" /* Delete */ ? void 0 : change.changes
959
+ data: change.action === "remove" /* Remove */ ? 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 "delete" /* Delete */:
998
- await handleDeleteSuccess(change, ctx);
997
+ case "remove" /* Remove */:
998
+ handleRemoveSuccess(change, ctx);
999
999
  break;
1000
1000
  case "update" /* Update */:
1001
- await handleUpdateSuccess(change, ctx);
1001
+ 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-YAAFAS64.js.map
3884
+ //# sourceMappingURL=chunk-PCA4XM2N.js.map