@rotorsoft/act 1.35.0 → 1.35.2
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/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +3 -2
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/{chunk-L66OOP2F.cjs → chunk-4KDMNSPJ.cjs} +1 -1
- package/dist/chunk-4KDMNSPJ.cjs.map +1 -0
- package/dist/{chunk-BNTVE7RQ.cjs → chunk-F2YAA4SE.cjs} +13 -13
- package/dist/{chunk-BNTVE7RQ.cjs.map → chunk-F2YAA4SE.cjs.map} +1 -1
- package/dist/{chunk-DH2HW5XJ.js → chunk-H2QN755D.js} +1 -1
- package/dist/chunk-H2QN755D.js.map +1 -0
- package/dist/{chunk-MHPUVTMX.js → chunk-SVVVS6GA.js} +2 -2
- package/dist/index.cjs +232 -221
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -32
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +4 -4
- package/dist/test/index.js +2 -2
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-DH2HW5XJ.js.map +0 -1
- package/dist/chunk-L66OOP2F.cjs.map +0 -1
- /package/dist/{chunk-MHPUVTMX.js.map → chunk-SVVVS6GA.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
sleep,
|
|
41
41
|
store,
|
|
42
42
|
validate
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-SVVVS6GA.js";
|
|
44
44
|
import {
|
|
45
45
|
ActorSchema,
|
|
46
46
|
CausationEventSchema,
|
|
@@ -71,7 +71,7 @@ import {
|
|
|
71
71
|
pii_fields,
|
|
72
72
|
pii_schemas,
|
|
73
73
|
sensitive
|
|
74
|
-
} from "./chunk-
|
|
74
|
+
} from "./chunk-H2QN755D.js";
|
|
75
75
|
|
|
76
76
|
// src/signals.ts
|
|
77
77
|
process.once("SIGINT", async (arg) => {
|
|
@@ -1648,12 +1648,30 @@ var subscribe = (streams, correlated_at, correlator) => store().subscribe(stream
|
|
|
1648
1648
|
|
|
1649
1649
|
// src/internal/event-sourcing.ts
|
|
1650
1650
|
import { patch } from "@rotorsoft/act-patch";
|
|
1651
|
-
import { prettifyError } from "zod";
|
|
1651
|
+
import { prettifyError, ZodError } from "zod";
|
|
1652
1652
|
var bare_patch = (_me, state2, partial) => patch(state2, partial);
|
|
1653
|
-
var
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1653
|
+
var value_at = (value, path) => path.reduce(
|
|
1654
|
+
(at, key) => at?.[key],
|
|
1655
|
+
value
|
|
1656
|
+
);
|
|
1657
|
+
var check_invariants = (target, state2, schema, pii_aware) => {
|
|
1658
|
+
let result;
|
|
1659
|
+
try {
|
|
1660
|
+
result = schema.safeParse(state2);
|
|
1661
|
+
} catch (error) {
|
|
1662
|
+
throw new ValidationError(target, state2, error);
|
|
1663
|
+
}
|
|
1664
|
+
if (result.success) return;
|
|
1665
|
+
const issues = pii_aware ? result.error.issues.filter((issue) => {
|
|
1666
|
+
const value = value_at(state2, issue.path);
|
|
1667
|
+
return value !== REDACTED && value !== SHREDDED;
|
|
1668
|
+
}) : result.error.issues;
|
|
1669
|
+
if (issues.length)
|
|
1670
|
+
throw new ValidationError(
|
|
1671
|
+
target,
|
|
1672
|
+
state2,
|
|
1673
|
+
prettifyError(new ZodError(issues))
|
|
1674
|
+
);
|
|
1657
1675
|
};
|
|
1658
1676
|
var DEFAULT_BATCH = 500;
|
|
1659
1677
|
var cache_put = (stream, entry) => cache().set(stream, entry).catch(
|
|
@@ -1909,7 +1927,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1909
1927
|
);
|
|
1910
1928
|
if (snapshot.event?.name === TOMBSTONE_EVENT)
|
|
1911
1929
|
throw new StreamClosedError(stream);
|
|
1912
|
-
const expected = expectedVersion ??
|
|
1930
|
+
const expected = expectedVersion ?? snapshot.version;
|
|
1913
1931
|
for (const { valid, description } of me.given?.[action2] ?? [])
|
|
1914
1932
|
if (!valid(snapshot.state, actor))
|
|
1915
1933
|
throw new InvariantError(
|
|
@@ -1973,17 +1991,15 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1973
1991
|
patches++;
|
|
1974
1992
|
return { state: state2, patch: patch2, patches };
|
|
1975
1993
|
});
|
|
1976
|
-
check_invariants(
|
|
1994
|
+
check_invariants(
|
|
1995
|
+
`${me.name}.${action2}`,
|
|
1996
|
+
state2,
|
|
1997
|
+
me.state,
|
|
1998
|
+
me.pii_aware
|
|
1999
|
+
);
|
|
1977
2000
|
let committed;
|
|
1978
2001
|
try {
|
|
1979
|
-
committed = await store().commit(
|
|
1980
|
-
stream,
|
|
1981
|
-
emitted,
|
|
1982
|
-
meta,
|
|
1983
|
-
// Reactions skip the inferred version guard (leases already
|
|
1984
|
-
// serialize them); an explicit expectedVersion is still honored.
|
|
1985
|
-
reactingTo ? expectedVersion : expected
|
|
1986
|
-
);
|
|
2002
|
+
committed = await store().commit(stream, emitted, meta, expected);
|
|
1987
2003
|
} catch (error) {
|
|
1988
2004
|
if (error instanceof ConcurrencyError) void cache_drop(stream);
|
|
1989
2005
|
throw error;
|
|
@@ -2000,21 +2016,16 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
2000
2016
|
replayed: snapshot.replayed
|
|
2001
2017
|
}));
|
|
2002
2018
|
const last = snapshots.at(-1);
|
|
2003
|
-
const
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
patches: snap_event ? 0 : last.patches,
|
|
2014
|
-
snaps: snap_event ? last.snaps + 1 : last.snaps
|
|
2015
|
-
});
|
|
2016
|
-
else void cache_drop(stream);
|
|
2017
|
-
}
|
|
2019
|
+
const snap_event = me.snap?.(last) ? await snap(last) : void 0;
|
|
2020
|
+
if (!me.pii_aware)
|
|
2021
|
+
void cache_put(stream, {
|
|
2022
|
+
stream,
|
|
2023
|
+
state: last.state,
|
|
2024
|
+
version: snap_event?.version ?? last.event.version,
|
|
2025
|
+
event_id: snap_event?.id ?? last.event.id,
|
|
2026
|
+
patches: snap_event ? 0 : last.patches,
|
|
2027
|
+
snaps: snap_event ? last.snaps + 1 : last.snaps
|
|
2028
|
+
});
|
|
2018
2029
|
return snapshots;
|
|
2019
2030
|
} catch (error) {
|
|
2020
2031
|
if (!(error instanceof ConcurrencyError)) throw error;
|