@rotorsoft/act 1.1.0 → 1.2.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +44 -1
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/in-memory-store.d.ts +9 -12
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts +17 -1
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/internal/index.d.ts +1 -0
- package/dist/@types/internal/index.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +77 -0
- package/dist/@types/types/action.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +43 -122
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/{chunk-TN4XS7WE.js → chunk-J6NDEEXC.js} +16 -52
- package/dist/chunk-J6NDEEXC.js.map +1 -0
- package/dist/index.cjs +130 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +116 -1
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +15 -51
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-TN4XS7WE.js.map +0 -1
package/dist/test/index.cjs
CHANGED
|
@@ -4939,23 +4939,19 @@ var InMemoryStore = class {
|
|
|
4939
4939
|
return result;
|
|
4940
4940
|
}
|
|
4941
4941
|
/**
|
|
4942
|
-
* Atomically rebuild the store
|
|
4942
|
+
* Atomically wipe-and-rebuild the store under an in-process snapshot.
|
|
4943
4943
|
*
|
|
4944
|
-
* Captures every index state up front, clears it, then
|
|
4945
|
-
*
|
|
4946
|
-
* the
|
|
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
|
|
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.
|
|
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(
|
|
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
|
-
|
|
4972
|
-
for await (const row of source) {
|
|
4966
|
+
await driver(async (event) => {
|
|
4973
4967
|
const id = this._events.length;
|
|
4974
|
-
const
|
|
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
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
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
|
-
|
|
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;
|