@absolutejs/sync 1.7.6 → 1.7.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.
@@ -45,6 +45,28 @@ export type MutationActions = {
45
45
  delete: (table: string, row: unknown) => Promise<void>;
46
46
  /** Escape hatch: emit a change you persisted yourself (no writer call). */
47
47
  change: <T>(collection: string, change: RowChange<T>) => Promise<void>;
48
+ /**
49
+ * Wall-clock timestamp the handler should use instead of `Date.now()`.
50
+ * Returns a `number` (ms since epoch).
51
+ *
52
+ * Why an injected clock? Two forward-looking reasons:
53
+ *
54
+ * 1. **Replay / rebase determinism.** When the engine re-runs a
55
+ * mutation against an updated state (Replicache-style mutator
56
+ * replay), `actions.now()` returns the ORIGINAL call's timestamp
57
+ * instead of the current wall clock. `Date.now()` would silently
58
+ * diverge between client-optimistic and server-canonical runs;
59
+ * `actions.now()` doesn't.
60
+ *
61
+ * 2. **Test determinism.** Test harnesses can pin time by passing a
62
+ * custom `now()` through {@link MutationActions} — the handler
63
+ * observes whatever the test wants.
64
+ *
65
+ * If the engine doesn't override it (the common case today), it just
66
+ * returns `Date.now()`. Use it everywhere you'd reach for
67
+ * `Date.now()` inside a mutation handler.
68
+ */
69
+ now: () => number;
48
70
  };
49
71
  export type MutationHandler<Args, Ctx, Result> = (args: Args, ctx: Ctx, actions: MutationActions) => Promise<Result> | Result;
50
72
  export type MutationDefinition<Args = unknown, Ctx = CollectionContext, Result = unknown> = {
package/dist/index.js CHANGED
@@ -737,7 +737,8 @@ var wrap = (source) => `
737
737
  insert: (table, data) => __dispatch(__callId, 'insert', table, data),
738
738
  update: (table, data) => __dispatch(__callId, 'update', table, data),
739
739
  delete: (table, row) => __dispatch(__callId, 'delete', table, row),
740
- change: (collection, change) => __dispatch(__callId, 'change', collection, change)
740
+ change: (collection, change) => __dispatch(__callId, 'change', collection, change),
741
+ now: () => __dispatch(__callId, 'now')
741
742
  };
742
743
  return userFn(args, ctx, actions);
743
744
  }
@@ -764,6 +765,8 @@ var compile = async (source, config) => {
764
765
  return a.delete(rest[0], rest[1]);
765
766
  case "change":
766
767
  return a.change(rest[0], rest[1]);
768
+ case "now":
769
+ return a.now();
767
770
  default:
768
771
  throw new Error(`unknown sandbox action op: ${String(op)}`);
769
772
  }
@@ -1286,7 +1289,8 @@ var createSyncEngine = (options = {}) => {
1286
1289
  }
1287
1290
  await writerFor(table).delete(row, ctx, tx);
1288
1291
  buffered.push({ table, change: { op: "delete", row } });
1289
- }
1292
+ },
1293
+ now: () => Date.now()
1290
1294
  };
1291
1295
  return { actions, buffered };
1292
1296
  };
@@ -2370,5 +2374,5 @@ export {
2370
2374
  createPresenceHub
2371
2375
  };
2372
2376
 
2373
- //# debugId=9570274420A04D4164756E2164756E21
2377
+ //# debugId=0583BD887ED853F264756E2164756E21
2374
2378
  //# sourceMappingURL=index.js.map