@rotorsoft/act 1.34.1 → 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
@@ -40,7 +40,7 @@ import {
40
40
  sleep,
41
41
  store,
42
42
  validate
43
- } from "./chunk-5F2TQ4PT.js";
43
+ } from "./chunk-IEM2NS6J.js";
44
44
  import {
45
45
  ActorSchema,
46
46
  CausationEventSchema,
@@ -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) {
@@ -3561,8 +3554,9 @@ var Act = class {
3561
3554
  * the event), and marks their work so the next drain can claim it.
3562
3555
  *
3563
3556
  * @param query - Only `limit` is used: the most events the pass reads
3564
- * (default 10). The scan always starts at the correlation checkpoint,
3565
- * which every reaction shares, so filters and `after` are ignored.
3557
+ * (10 when the query has none; `0` reads everything). The scan always
3558
+ * starts at the correlation checkpoint, which every reaction shares, so
3559
+ * filters and `after` are ignored.
3566
3560
  * @returns The number of newly subscribed streams and the last scanned event id
3567
3561
  *
3568
3562
  * @example Manual correlation
@@ -3572,8 +3566,8 @@ var Act = class {
3572
3566
  *
3573
3567
  * @see {@link start_correlations} for automatic periodic correlation
3574
3568
  */
3575
- async correlate(query = { limit: 10 }) {
3576
- const pass = await this._correlate_pass(query);
3569
+ async correlate(query = {}) {
3570
+ const pass = await this._correlate_pass({ limit: query.limit ?? 10 });
3577
3571
  return {
3578
3572
  subscribed: pass.kind === "scanned" ? pass.subscribed : 0,
3579
3573
  last_id: pass.last_id
@@ -4230,7 +4224,7 @@ function autoclose_of(existing, state2) {
4230
4224
  }
4231
4225
  function merge_into_existing(state2, existing, states, actions, events) {
4232
4226
  for (const name of Object.keys(state2.actions)) {
4233
- if (existing.actions[name] === state2.actions[name]) continue;
4227
+ if (existing.on[name] === state2.on[name]) continue;
4234
4228
  if (actions[name]) throw new Error(`Duplicate action "${name}"`);
4235
4229
  }
4236
4230
  for (const name of Object.keys(state2.events)) {
@@ -5018,13 +5012,11 @@ function action_builder(state2) {
5018
5012
  internal.options[action2] = options;
5019
5013
  }
5020
5014
  function given(rules) {
5021
- internal.given ??= {};
5022
- internal.given[action2] = rules;
5015
+ (internal.given ??= {})[action2] = rules;
5023
5016
  return { requires, emit };
5024
5017
  }
5025
5018
  function requires(rules) {
5026
- internal.requires ??= {};
5027
- internal.requires[action2] = rules;
5019
+ (internal.requires ??= {})[action2] = rules;
5028
5020
  return { emit };
5029
5021
  }
5030
5022
  function emit(handler) {