@rotorsoft/act 1.33.20 → 1.34.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/builders/merge.d.ts.map +1 -1
- package/dist/@types/builders/state-builder.d.ts +1 -1
- package/dist/@types/builders/state-builder.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +28 -0
- package/dist/@types/types/action.d.ts.map +1 -1
- package/dist/@types/types/builders.d.ts +113 -25
- package/dist/@types/types/builders.d.ts.map +1 -1
- package/dist/@types/types/errors.d.ts +13 -6
- package/dist/@types/types/errors.d.ts.map +1 -1
- package/dist/{chunk-5Z53Y7SG.js → chunk-5F2TQ4PT.js} +2 -2
- package/dist/{chunk-HEHGZHHA.js → chunk-BKCNU6FF.js} +10 -5
- package/dist/chunk-BKCNU6FF.js.map +1 -0
- package/dist/{chunk-GEUBNZ3B.cjs → chunk-BTLM7SW4.cjs} +13 -13
- package/dist/{chunk-GEUBNZ3B.cjs.map → chunk-BTLM7SW4.cjs.map} +1 -1
- package/dist/{chunk-DVYTKZD5.cjs → chunk-RF5MV72K.cjs} +10 -5
- package/dist/chunk-RF5MV72K.cjs.map +1 -0
- package/dist/index.cjs +161 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -3
- 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-DVYTKZD5.cjs.map +0 -1
- package/dist/chunk-HEHGZHHA.js.map +0 -1
- /package/dist/{chunk-5Z53Y7SG.js.map → chunk-5F2TQ4PT.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-5F2TQ4PT.js";
|
|
44
44
|
import {
|
|
45
45
|
ActorSchema,
|
|
46
46
|
CausationEventSchema,
|
|
@@ -70,7 +70,7 @@ import {
|
|
|
70
70
|
pii_fields,
|
|
71
71
|
pii_schemas,
|
|
72
72
|
sensitive
|
|
73
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-BKCNU6FF.js";
|
|
74
74
|
|
|
75
75
|
// src/signals.ts
|
|
76
76
|
process.once("SIGINT", async (arg) => {
|
|
@@ -1924,6 +1924,19 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1924
1924
|
);
|
|
1925
1925
|
});
|
|
1926
1926
|
}
|
|
1927
|
+
if (me.requires) {
|
|
1928
|
+
const preconditions = me.requires[action2] || [];
|
|
1929
|
+
for (const { holds, description } of preconditions)
|
|
1930
|
+
if (!holds(validated, snapshot.state, actor))
|
|
1931
|
+
throw new InvariantError(
|
|
1932
|
+
action2,
|
|
1933
|
+
validated,
|
|
1934
|
+
target,
|
|
1935
|
+
snapshot,
|
|
1936
|
+
description,
|
|
1937
|
+
"precondition"
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1927
1940
|
const result = me.on[action2](validated, snapshot, target);
|
|
1928
1941
|
if (!result) return [snapshot];
|
|
1929
1942
|
if (Array.isArray(result) && result.length === 0) {
|
|
@@ -4239,6 +4252,7 @@ function merge_into_existing(state2, existing, states, actions, events) {
|
|
|
4239
4252
|
patch: merged_patch,
|
|
4240
4253
|
on: { ...existing.on, ...state2.on },
|
|
4241
4254
|
given: { ...existing.given, ...state2.given },
|
|
4255
|
+
requires: { ...existing.requires, ...state2.requires },
|
|
4242
4256
|
snap: pick_declared(existing.snap, state2.snap, "snap strategy", state2.name),
|
|
4243
4257
|
// Per-action retry policy is keyed by action name, so the two partials'
|
|
4244
4258
|
// maps combine. Left `undefined` when neither declared one, so the
|
|
@@ -5006,6 +5020,11 @@ function action_builder(state2) {
|
|
|
5006
5020
|
function given(rules) {
|
|
5007
5021
|
internal.given ??= {};
|
|
5008
5022
|
internal.given[action2] = rules;
|
|
5023
|
+
return { requires, emit };
|
|
5024
|
+
}
|
|
5025
|
+
function requires(rules) {
|
|
5026
|
+
internal.requires ??= {};
|
|
5027
|
+
internal.requires[action2] = rules;
|
|
5009
5028
|
return { emit };
|
|
5010
5029
|
}
|
|
5011
5030
|
function emit(handler) {
|
|
@@ -5023,7 +5042,7 @@ function action_builder(state2) {
|
|
|
5023
5042
|
}
|
|
5024
5043
|
return builder;
|
|
5025
5044
|
}
|
|
5026
|
-
return { given, emit };
|
|
5045
|
+
return { given, requires, emit };
|
|
5027
5046
|
},
|
|
5028
5047
|
snap(snap2) {
|
|
5029
5048
|
internal.snap = snap2;
|