@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/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-XsB8HrvX.cjs';
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-3gbnIINY.js';
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
@@ -6,7 +6,7 @@ import {
6
6
  SqliteQueryContext,
7
7
  SyncAction,
8
8
  createLocalId
9
- } from "./chunk-YAAFAS64.js";
9
+ } from "./chunk-PCA4XM2N.js";
10
10
  import "./chunk-SQB6E7V2.js";
11
11
  export {
12
12
  Dync,
@@ -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
- delete: (id: any) => Promise<void>;
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' | 'delete';
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
- Delete = "delete"
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
- delete: (id: any) => Promise<void>;
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' | 'delete';
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
- Delete = "delete"
128
+ Remove = "remove"
129
129
  }
130
130
  interface PendingChange {
131
131
  action: SyncAction;
@@ -79,7 +79,7 @@ function orderFor(a) {
79
79
  return 1;
80
80
  case "update" /* Update */:
81
81
  return 2;
82
- case "delete" /* Delete */:
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 === "delete" /* Delete */) {
185
+ if (queueItem.action === "remove" /* Remove */) {
186
186
  return Promise.resolve();
187
187
  }
188
188
  queueItem.version += 1;
189
- if (action === "delete" /* Delete */) {
190
- queueItem.action = "delete" /* Delete */;
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 === "delete" /* Delete */ || hasChanges) {
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: "delete" /* Delete */,
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: "delete" /* Delete */,
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: "delete" /* Delete */,
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 === "delete" /* Delete */).map((p) => p.id)
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-delete tableName=${tableName} id=${remote.id}`);
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:delete tableName=${tableName} id=${remote.id}`);
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 handleDeleteSuccess(change, ctx) {
826
+ async function handleRemoveSuccess(change, ctx) {
827
827
  const { tableName, localId, id } = change;
828
- ctx.logger.debug(`[dync] push:delete:success tableName=${tableName} localId=${localId} id=${id}`);
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 */ : "delete" /* Delete */;
849
+ const nextAction = wasChanged ? "update" /* Update */ : "remove" /* Remove */;
850
850
  await ctx.state.updatePendingChange(tableName, localId, nextAction, serverResult.id);
851
- if (nextAction === "delete" /* Delete */) return;
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 "delete" /* Delete */:
876
+ case "remove" /* Remove */:
877
877
  if (!id) {
878
- ctx.logger.warn(`[dync] push:delete:no-id tableName=${tableName} localId=${localId}`);
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.delete(id);
883
- await handleDeleteSuccess(change, ctx);
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" : "delete",
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 === "delete" /* Delete */ ? void 0 : change.changes
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 "delete" /* Delete */:
1021
- await handleDeleteSuccess(change, ctx);
1020
+ case "remove" /* Remove */:
1021
+ handleRemoveSuccess(change, ctx);
1022
1022
  break;
1023
1023
  case "update" /* Update */:
1024
- await handleUpdateSuccess(change, ctx);
1024
+ handleUpdateSuccess(change, ctx);
1025
1025
  break;
1026
1026
  case "create" /* Create */: {
1027
1027
  const serverResult = { id: result.id };