@rotorsoft/act 1.1.0 → 1.3.0

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.
@@ -4502,7 +4502,7 @@ var InMemoryStore = class {
4502
4502
  continue;
4503
4503
  if (query.after && e.id <= query.after) break;
4504
4504
  if (query.created_after && e.created <= query.created_after) break;
4505
- callback(e);
4505
+ await Promise.resolve(callback(e));
4506
4506
  count++;
4507
4507
  if (query?.limit && count >= query.limit) break;
4508
4508
  }
@@ -4514,7 +4514,7 @@ var InMemoryStore = class {
4514
4514
  if (query?.created_after && e.created <= query.created_after) continue;
4515
4515
  if (query?.before && e.id >= query.before) break;
4516
4516
  if (query?.created_before && e.created >= query.created_before) break;
4517
- callback(e);
4517
+ await Promise.resolve(callback(e));
4518
4518
  count++;
4519
4519
  if (query?.limit && count >= query.limit) break;
4520
4520
  }
@@ -4939,23 +4939,19 @@ var InMemoryStore = class {
4939
4939
  return result;
4940
4940
  }
4941
4941
  /**
4942
- * Atomically rebuild the store from a stream of {@link RestoreRow}.
4942
+ * Atomically wipe-and-rebuild the store under an in-process snapshot.
4943
4943
  *
4944
- * Captures every index state up front, clears it, then iterates the
4945
- * source. Any throw mid-iteration restores the snapshot, leaving
4946
- * the store byte-for-byte unchanged from the operator's
4947
- * perspective.
4944
+ * Captures every index state up front, clears it, then hands the
4945
+ * orchestrator a per-event insert `callback` via the driver. Any
4946
+ * throw inside the driver restores the snapshot, leaving the store
4947
+ * byte-for-byte unchanged from the operator's perspective.
4948
4948
  *
4949
- * `id`s are reassigned `0..N-1` as rows arrive (matching the
4949
+ * `id`s are reassigned `0..N-1` as events arrive (matching the
4950
4950
  * adapter's commit-id convention — InMemory uses `_events.length`).
4951
- * `created` is preserved verbatim from the source. Causation
4952
- * references in `meta.causation.event.id` are remapped via the
4953
- * `old → new` table that's built as rows land — references to ids
4954
- * not in the source pass through unchanged.
4951
+ * `created` is preserved verbatim from the source.
4955
4952
  */
4956
- async restore(source, _opts = {}) {
4953
+ async restore(driver) {
4957
4954
  await sleep();
4958
- const started = Date.now();
4959
4955
  const prevEvents = this._events;
4960
4956
  const prevStreams = this._streams;
4961
4957
  const prevStreamVersions = this._streamVersions;
@@ -4966,50 +4962,18 @@ var InMemoryStore = class {
4966
4962
  this._streamVersions = /* @__PURE__ */ new Map();
4967
4963
  this._maxEventIdByStream = /* @__PURE__ */ new Map();
4968
4964
  this._maxNonSnapEventId = -1;
4969
- const idMap = /* @__PURE__ */ new Map();
4970
4965
  try {
4971
- let kept = 0;
4972
- for await (const row of source) {
4966
+ await driver(async (event) => {
4973
4967
  const id = this._events.length;
4974
- const created = row.created instanceof Date ? row.created : new Date(row.created);
4975
- let meta = row.meta;
4976
- const causedBy = meta.causation.event?.id;
4977
- if (causedBy !== void 0) {
4978
- const remapped = idMap.get(causedBy);
4979
- if (remapped !== void 0 && remapped !== causedBy) {
4980
- meta = {
4981
- ...meta,
4982
- causation: {
4983
- ...meta.causation,
4984
- event: { ...meta.causation.event, id: remapped }
4985
- }
4986
- };
4987
- }
4988
- }
4989
- const committed = {
4990
- id,
4991
- stream: row.stream,
4992
- version: row.version,
4993
- created,
4994
- name: row.name,
4995
- data: row.data,
4996
- meta
4997
- };
4968
+ const committed = { ...event, id };
4998
4969
  this._events.push(committed);
4999
- idMap.set(row.id, id);
5000
- this._streamVersions.set(row.stream, row.version);
5001
- if (row.name !== SNAP_EVENT) {
5002
- this._maxEventIdByStream.set(row.stream, id);
4970
+ this._streamVersions.set(event.stream, event.version);
4971
+ if (event.name !== SNAP_EVENT) {
4972
+ this._maxEventIdByStream.set(event.stream, id);
5003
4973
  this._maxNonSnapEventId = id;
5004
4974
  }
5005
- kept++;
5006
- }
5007
- return {
5008
- kept,
5009
- duration_ms: Date.now() - started,
5010
- dropped: { closed_streams: 0, snapshots: 0, empty_streams: 0 },
5011
- dry_run: false
5012
- };
4975
+ return id;
4976
+ });
5013
4977
  } catch (err) {
5014
4978
  this._events = prevEvents;
5015
4979
  this._streams = prevStreams;