@rotorsoft/act 1.34.2 → 1.34.3

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/index.js CHANGED
@@ -1911,32 +1911,25 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1911
1911
  if (snapshot.event?.name === TOMBSTONE_EVENT)
1912
1912
  throw new StreamClosedError(stream);
1913
1913
  const expected = expectedVersion ?? (snapshot.version >= 0 ? snapshot.version : void 0);
1914
- if (me.given) {
1915
- const invariants = me.given[action2] || [];
1916
- invariants.forEach(({ valid: valid2, description }) => {
1917
- if (!valid2(snapshot.state, actor))
1918
- throw new InvariantError(
1919
- action2,
1920
- validated,
1921
- target,
1922
- snapshot,
1923
- description
1924
- );
1925
- });
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
- }
1914
+ for (const { valid: valid2, description } of me.given?.[action2] ?? [])
1915
+ if (!valid2(snapshot.state, actor))
1916
+ throw new InvariantError(
1917
+ action2,
1918
+ validated,
1919
+ target,
1920
+ snapshot,
1921
+ description
1922
+ );
1923
+ for (const { holds, description } of me.requires?.[action2] ?? [])
1924
+ if (!holds(validated, snapshot.state, actor))
1925
+ throw new InvariantError(
1926
+ action2,
1927
+ validated,
1928
+ target,
1929
+ snapshot,
1930
+ description,
1931
+ "precondition"
1932
+ );
1940
1933
  const result = me.on[action2](validated, snapshot, target);
1941
1934
  if (!result) return [snapshot];
1942
1935
  if (Array.isArray(result) && result.length === 0) {
@@ -5019,13 +5012,11 @@ function action_builder(state2) {
5019
5012
  internal.options[action2] = options;
5020
5013
  }
5021
5014
  function given(rules) {
5022
- internal.given ??= {};
5023
- internal.given[action2] = rules;
5015
+ (internal.given ??= {})[action2] = rules;
5024
5016
  return { requires, emit };
5025
5017
  }
5026
5018
  function requires(rules) {
5027
- internal.requires ??= {};
5028
- internal.requires[action2] = rules;
5019
+ (internal.requires ??= {})[action2] = rules;
5029
5020
  return { emit };
5030
5021
  }
5031
5022
  function emit(handler) {