@rotorsoft/act 1.35.0 → 1.35.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"event-sourcing.d.ts","sourceRoot":"","sources":["../../../src/internal/event-sourcing.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,KAAK,EAEV,SAAS,EACT,SAAS,EAGT,WAAW,EACX,UAAU,EACV,OAAO,EACP,WAAW,EACX,UAAU,EACV,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,mBAAmB,CAAC;AAM3B,0EAA0E;AAC1E,eAAO,MAAM,UAAU,EAAE,OACc,CAAC;AAmBxC,uEAAuE;AACvE,KAAK,WAAW,GAAG,CACjB,MAAM,SAAS,MAAM,EACrB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EACxB,IAAI,SAAS,MAAM,QAAQ,EAE3B,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EACpC,MAAM,EAAE,IAAI,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EACjC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,KACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AAE1C,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,OAAO,SAAS,CAAC;CAC7B;AA2BD,0FAA0F;AAC1F,wBAAsB,IAAI,CAAC,MAAM,SAAS,MAAM,EAAE,OAAO,SAAS,OAAO,EACvE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,OAAO,CAAC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CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EACjC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,EAC5B,QAAQ,GAAE,OAAoB,GAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAwLtC"}
package/dist/index.cjs CHANGED
@@ -1650,10 +1650,28 @@ var subscribe = (streams, correlated_at, correlator) => _chunkBNTVE7RQcjs.store.
1650
1650
  var _actpatch = require('@rotorsoft/act-patch');
1651
1651
  var _zod2 = require('zod');
1652
1652
  var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
1653
- var check_invariants = (target, state2, schema) => {
1654
- const result = schema.safeParse(state2);
1655
- if (!result.success)
1656
- throw new (0, _chunkL66OOP2Fcjs.ValidationError)(target, state2, _zod2.prettifyError.call(void 0, result.error));
1653
+ var value_at = (value, path) => path.reduce(
1654
+ (at, key) => _optionalChain([at, 'optionalAccess', _67 => _67[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 (0, _chunkL66OOP2Fcjs.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 !== _chunkL66OOP2Fcjs.REDACTED && value !== _chunkL66OOP2Fcjs.SHREDDED;
1668
+ }) : result.error.issues;
1669
+ if (issues.length)
1670
+ throw new (0, _chunkL66OOP2Fcjs.ValidationError)(
1671
+ target,
1672
+ state2,
1673
+ _zod2.prettifyError.call(void 0, new (0, _zod2.ZodError)(issues))
1674
+ );
1657
1675
  };
1658
1676
  var DEFAULT_BATCH = 500;
1659
1677
  var cache_put = (stream, entry) => _chunkBNTVE7RQcjs.cache.call(void 0, ).set(stream, entry).catch(
@@ -1762,7 +1780,7 @@ async function scan(source, opts = {}, callback) {
1762
1780
  return;
1763
1781
  }
1764
1782
  let migrated = event;
1765
- const migration = _optionalChain([event_migrations, 'optionalAccess', _67 => _67[event.name]]);
1783
+ const migration = _optionalChain([event_migrations, 'optionalAccess', _68 => _68[event.name]]);
1766
1784
  if (migration) {
1767
1785
  const old_data = migration.from_schema.parse(event.data);
1768
1786
  const new_data = migration.migrate(old_data);
@@ -1784,7 +1802,7 @@ async function scan(source, opts = {}, callback) {
1784
1802
  return;
1785
1803
  }
1786
1804
  let remapped = migrated;
1787
- const caused_by = _optionalChain([migrated, 'access', _68 => _68.meta, 'access', _69 => _69.causation, 'access', _70 => _70.event, 'optionalAccess', _71 => _71.id]);
1805
+ const caused_by = _optionalChain([migrated, 'access', _69 => _69.meta, 'access', _70 => _70.causation, 'access', _71 => _71.event, 'optionalAccess', _72 => _72.id]);
1788
1806
  if (caused_by !== void 0) {
1789
1807
  const new_caused_by = id_map.get(caused_by);
1790
1808
  if (new_caused_by !== void 0 && new_caused_by !== caused_by) {
@@ -1826,9 +1844,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1826
1844
  const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
1827
1845
  const cached = time_travel ? void 0 : await _chunkBNTVE7RQcjs.cache.call(void 0, ).get(stream);
1828
1846
  const cache_hit = !!cached;
1829
- let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _72 => _72.state]), () => ( (me.init ? me.init() : {})));
1830
- let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _73 => _73.patches]), () => ( 0));
1831
- let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _74 => _74.snaps]), () => ( 0));
1847
+ let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _73 => _73.state]), () => ( (me.init ? me.init() : {})));
1848
+ let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _74 => _74.patches]), () => ( 0));
1849
+ let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _75 => _75.snaps]), () => ( 0));
1832
1850
  let replayed = 0;
1833
1851
  let event;
1834
1852
  await _chunkBNTVE7RQcjs.store.call(void 0, ).query(
@@ -1848,7 +1866,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1848
1866
  `Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
1849
1867
  );
1850
1868
  }
1851
- _optionalChain([callback, 'optionalCall', _75 => _75({
1869
+ _optionalChain([callback, 'optionalCall', _76 => _76({
1852
1870
  event,
1853
1871
  state: state2,
1854
1872
  version: event.version,
@@ -1868,7 +1886,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1868
1886
  ...cached ? { after: cached.event_id, with_snaps: true } : { ...time_travel ? {} : { with_snaps: true }, ...asOf }
1869
1887
  }
1870
1888
  );
1871
- const head_is_tombstone = _optionalChain([event, 'optionalAccess', _76 => _76.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT;
1889
+ const head_is_tombstone = _optionalChain([event, 'optionalAccess', _77 => _77.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT;
1872
1890
  if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
1873
1891
  await cache_put(stream, {
1874
1892
  stream,
@@ -1882,9 +1900,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1882
1900
  return {
1883
1901
  event,
1884
1902
  state: state2,
1885
- version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _77 => _77.version]), () => ( _optionalChain([cached, 'optionalAccess', _78 => _78.version]))), () => ( -1)),
1903
+ version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _78 => _78.version]), () => ( _optionalChain([cached, 'optionalAccess', _79 => _79.version]))), () => ( -1)),
1886
1904
  // Captured with `state`, so consumers never race a separate cache lookup.
1887
- id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _79 => _79.id]), () => ( _optionalChain([cached, 'optionalAccess', _80 => _80.event_id]))), () => ( -1)),
1905
+ id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _80 => _80.id]), () => ( _optionalChain([cached, 'optionalAccess', _81 => _81.event_id]))), () => ( -1)),
1888
1906
  patches,
1889
1907
  snaps,
1890
1908
  cache_hit,
@@ -1894,11 +1912,11 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1894
1912
  async function action(me, action2, target, payload, options, patch_fn = bare_patch) {
1895
1913
  const { stream, expectedVersion, actor } = target;
1896
1914
  if (!stream) throw new Error("Missing target stream");
1897
- const reactingTo = _optionalChain([options, 'optionalAccess', _81 => _81.reactingTo]);
1898
- const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _82 => _82.correlator]), () => ( default_correlator));
1915
+ const reactingTo = _optionalChain([options, 'optionalAccess', _82 => _82.reactingTo]);
1916
+ const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _83 => _83.correlator]), () => ( default_correlator));
1899
1917
  const validated = _chunkBNTVE7RQcjs.validate.call(void 0, action2, payload, me.actions[action2]);
1900
- const opts = _optionalChain([me, 'access', _83 => _83.options, 'optionalAccess', _84 => _84[action2]]);
1901
- const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.maxRetries]), () => ( 0));
1918
+ const opts = _optionalChain([me, 'access', _84 => _84.options, 'optionalAccess', _85 => _85[action2]]);
1919
+ const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _86 => _86.maxRetries]), () => ( 0));
1902
1920
  for (let attempt = 0; ; attempt++) {
1903
1921
  try {
1904
1922
  const snapshot = await load(
@@ -1907,10 +1925,10 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1907
1925
  void 0,
1908
1926
  patch_fn
1909
1927
  );
1910
- if (_optionalChain([snapshot, 'access', _86 => _86.event, 'optionalAccess', _87 => _87.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT)
1928
+ if (_optionalChain([snapshot, 'access', _87 => _87.event, 'optionalAccess', _88 => _88.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT)
1911
1929
  throw new (0, _chunkL66OOP2Fcjs.StreamClosedError)(stream);
1912
1930
  const expected = _nullishCoalesce(expectedVersion, () => ( (snapshot.version >= 0 ? snapshot.version : void 0)));
1913
- for (const { valid, description } of _nullishCoalesce(_optionalChain([me, 'access', _88 => _88.given, 'optionalAccess', _89 => _89[action2]]), () => ( [])))
1931
+ for (const { valid, description } of _nullishCoalesce(_optionalChain([me, 'access', _89 => _89.given, 'optionalAccess', _90 => _90[action2]]), () => ( [])))
1914
1932
  if (!valid(snapshot.state, actor))
1915
1933
  throw new (0, _chunkL66OOP2Fcjs.InvariantError)(
1916
1934
  action2,
@@ -1919,7 +1937,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1919
1937
  snapshot,
1920
1938
  description
1921
1939
  );
1922
- for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _90 => _90.requires, 'optionalAccess', _91 => _91[action2]]), () => ( [])))
1940
+ for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _91 => _91.requires, 'optionalAccess', _92 => _92[action2]]), () => ( [])))
1923
1941
  if (!holds(validated, snapshot.state, actor))
1924
1942
  throw new (0, _chunkL66OOP2Fcjs.PreconditionError)(
1925
1943
  action2,
@@ -1938,7 +1956,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1938
1956
  }));
1939
1957
  const emitted = events.map((e) => me.message(e));
1940
1958
  const meta = {
1941
- correlation: _optionalChain([reactingTo, 'optionalAccess', _92 => _92.meta, 'access', _93 => _93.correlation]) || correlator({
1959
+ correlation: _optionalChain([reactingTo, 'optionalAccess', _93 => _93.meta, 'access', _94 => _94.correlation]) || correlator({
1942
1960
  action: action2,
1943
1961
  state: me.name,
1944
1962
  stream,
@@ -1973,7 +1991,12 @@ 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(`${me.name}.${action2}`, state2, me.state);
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
2002
  committed = await _chunkBNTVE7RQcjs.store.call(void 0, ).commit(
@@ -2001,15 +2024,15 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
2001
2024
  }));
2002
2025
  const last = snapshots.at(-1);
2003
2026
  const contiguous = committed[0].version === snapshot.version + 1;
2004
- const snapped = contiguous && _optionalChain([me, 'access', _94 => _94.snap, 'optionalCall', _95 => _95(last)]);
2027
+ const snapped = contiguous && _optionalChain([me, 'access', _95 => _95.snap, 'optionalCall', _96 => _96(last)]);
2005
2028
  const snap_event = snapped ? await snap(last) : void 0;
2006
2029
  if (!me.pii_aware) {
2007
2030
  if (contiguous)
2008
2031
  void cache_put(stream, {
2009
2032
  stream,
2010
2033
  state: last.state,
2011
- version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _96 => _96.version]), () => ( last.event.version)),
2012
- event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _97 => _97.id]), () => ( last.event.id)),
2034
+ version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _97 => _97.version]), () => ( last.event.version)),
2035
+ event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _98 => _98.id]), () => ( last.event.id)),
2013
2036
  patches: snap_event ? 0 : last.patches,
2014
2037
  snaps: snap_event ? last.snaps + 1 : last.snaps
2015
2038
  });
@@ -2020,7 +2043,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
2020
2043
  if (!(error instanceof _chunkL66OOP2Fcjs.ConcurrencyError)) throw error;
2021
2044
  if (expectedVersion !== void 0) throw error;
2022
2045
  if (attempt >= max_retries) throw error;
2023
- if (_optionalChain([opts, 'optionalAccess', _98 => _98.backoff])) {
2046
+ if (_optionalChain([opts, 'optionalAccess', _99 => _99.backoff])) {
2024
2047
  const delay_ms = compute_backoff_delay(attempt, opts.backoff);
2025
2048
  if (delay_ms > 0) await _chunkBNTVE7RQcjs.sleep.call(void 0, delay_ms);
2026
2049
  }
@@ -2075,9 +2098,9 @@ var as_of_marker = (asOf) => {
2075
2098
  return parts.length ? ` (as-of ${parts.join(" ")})` : " (as-of)";
2076
2099
  };
2077
2100
  var traced = (inner, exit, entry) => (async (...args) => {
2078
- _optionalChain([entry, 'optionalCall', _99 => _99(...args)]);
2101
+ _optionalChain([entry, 'optionalCall', _100 => _100(...args)]);
2079
2102
  const result = await inner(...args);
2080
- _optionalChain([exit, 'optionalCall', _100 => _100(result, ...args)]);
2103
+ _optionalChain([exit, 'optionalCall', _101 => _101(result, ...args)]);
2081
2104
  return result;
2082
2105
  });
2083
2106
  function build_es(logger, correlator = default_correlator, patch_fn = bare_patch) {
@@ -2162,7 +2185,7 @@ function build_drain(logger) {
2162
2185
  subscribe: logger.level !== "trace" ? subscribe : traced(subscribe, (result, streams) => {
2163
2186
  if (!result.subscribed) return;
2164
2187
  const lanes = new Set(streams.map((s) => _nullishCoalesce(s.lane, () => ( "default"))));
2165
- const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _101 => _101[0], 'optionalAccess', _102 => _102.lane]) : void 0;
2188
+ const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _102 => _102[0], 'optionalAccess', _103 => _103.lane]) : void 0;
2166
2189
  const data = streams.map(
2167
2190
  ({ stream, lane }) => uniform_lane || !lane || lane === "default" ? hue(C_STREAM, stream) : `${hue(C_STREAM, stream)}${dim(`[${lane}]`)}`
2168
2191
  ).join(" ");
@@ -2174,7 +2197,7 @@ function build_drain(logger) {
2174
2197
  }
2175
2198
  function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
2176
2199
  if (logger.level !== "trace" || !leased.length) return;
2177
- const lane = _optionalChain([leased, 'access', _103 => _103[0], 'optionalAccess', _104 => _104.lane]);
2200
+ const lane = _optionalChain([leased, 'access', _104 => _104[0], 'optionalAccess', _105 => _105.lane]);
2178
2201
  const fetch_by_stream = new Map(fetched.map((f) => [f.stream, f]));
2179
2202
  const acked_by_stream = new Map(acked.map((a) => [a.stream, a.at]));
2180
2203
  const blocked_by_stream = new Map(blocked.map((b) => [b.stream, b.error]));
@@ -2183,8 +2206,8 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
2183
2206
  );
2184
2207
  const detail = leased.map(({ stream, at, retry }) => {
2185
2208
  const f = fetch_by_stream.get(stream);
2186
- const key = _optionalChain([f, 'optionalAccess', _105 => _105.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
2187
- const events = _optionalChain([f, 'optionalAccess', _106 => _106.events, 'access', _107 => _107.length]) ? ` ${dim(
2209
+ const key = _optionalChain([f, 'optionalAccess', _106 => _106.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
2210
+ const events = _optionalChain([f, 'optionalAccess', _107 => _107.events, 'access', _108 => _108.length]) ? ` ${dim(
2188
2211
  `[${f.events.map(({ id, name }) => `#${id} ${String(name)}`).join(", ")}]`
2189
2212
  )}` : "";
2190
2213
  const acked_at = acked_by_stream.get(stream);
@@ -2212,7 +2235,7 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
2212
2235
 
2213
2236
  // src/internal/drain-cycle.ts
2214
2237
  function budget_exhausted(lease, options, store_failing) {
2215
- if (store_failing || !_optionalChain([options, 'optionalAccess', _108 => _108.blockOnError]) || lease.retry <= options.maxRetries)
2238
+ if (store_failing || !_optionalChain([options, 'optionalAccess', _109 => _109.blockOnError]) || lease.retry <= options.maxRetries)
2216
2239
  return void 0;
2217
2240
  const error = `Blocking ${lease.stream} after ${lease.retry} claims with no acknowledged progress \u2014 the retry budget (${options.maxRetries}) was spent without the handler ever reporting an error. That means every attempt lost its lease before it could ack: move the reaction to a lane whose leaseMillis covers the handler, then unblock the stream.`;
2218
2241
  _chunkBNTVE7RQcjs.log.call(void 0, ).error(error);
@@ -2276,7 +2299,7 @@ async function run_drain_cycle(deps, cycle) {
2276
2299
  const fetched = await ops.fetch(leased, eventLimit);
2277
2300
  const fetch_map = /* @__PURE__ */ new Map();
2278
2301
  const fetch_window_at = fetched.reduce(
2279
- (max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _109 => _109.at, 'call', _110 => _110(-1), 'optionalAccess', _111 => _111.id]) || at),
2302
+ (max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _110 => _110.at, 'call', _111 => _111(-1), 'optionalAccess', _112 => _112.id]) || at),
2280
2303
  0
2281
2304
  );
2282
2305
  for (const f of fetched) {
@@ -2340,11 +2363,11 @@ async function run_drain_cycle(deps, cycle) {
2340
2363
  deps.logger
2341
2364
  )
2342
2365
  );
2343
- const at = _optionalChain([entry, 'access', _112 => _112.fetch, 'access', _113 => _113.events, 'access', _114 => _114.at, 'call', _115 => _115(-1), 'optionalAccess', _116 => _116.id]) || fetch_window_at;
2366
+ const at = _optionalChain([entry, 'access', _113 => _113.fetch, 'access', _114 => _114.events, 'access', _115 => _115.at, 'call', _116 => _116(-1), 'optionalAccess', _117 => _117.id]) || fetch_window_at;
2344
2367
  const { payloads } = entry;
2345
2368
  const exhausted = budget_exhausted(
2346
2369
  lease,
2347
- _optionalChain([payloads, 'access', _117 => _117[0], 'optionalAccess', _118 => _118.options]),
2370
+ _optionalChain([payloads, 'access', _118 => _118[0], 'optionalAccess', _119 => _119.options]),
2348
2371
  store_failing
2349
2372
  );
2350
2373
  if (exhausted) return Promise.resolve(exhausted);
@@ -2433,7 +2456,7 @@ var DrainController = (_class5 = class {
2433
2456
  }
2434
2457
  /** This lane's configured lease, or `undefined`; the shutdown grace basis. */
2435
2458
  get lease_millis() {
2436
- return _optionalChain([this, 'access', _119 => _119._deps, 'access', _120 => _120.defaults, 'optionalAccess', _121 => _121.leaseMillis]);
2459
+ return _optionalChain([this, 'access', _120 => _120._deps, 'access', _121 => _121.defaults, 'optionalAccess', _122 => _122.leaseMillis]);
2437
2460
  }
2438
2461
  get lane() {
2439
2462
  return this._deps.lane;
@@ -2726,10 +2749,10 @@ var CloseSignal = class extends Error {
2726
2749
  constructor(opts) {
2727
2750
  super("reaction requested close");
2728
2751
  this.name = "CloseSignal";
2729
- this.stream = _optionalChain([opts, 'optionalAccess', _122 => _122.stream]);
2730
- this.archive = _optionalChain([opts, 'optionalAccess', _123 => _123.archive]);
2731
- this.at = _optionalChain([opts, 'optionalAccess', _124 => _124.at]);
2732
- this.before = _optionalChain([opts, 'optionalAccess', _125 => _125.before]);
2752
+ this.stream = _optionalChain([opts, 'optionalAccess', _123 => _123.stream]);
2753
+ this.archive = _optionalChain([opts, 'optionalAccess', _124 => _124.archive]);
2754
+ this.at = _optionalChain([opts, 'optionalAccess', _125 => _125.at]);
2755
+ this.before = _optionalChain([opts, 'optionalAccess', _126 => _126.before]);
2733
2756
  }
2734
2757
  };
2735
2758
  function build_handle(deps) {
@@ -2876,7 +2899,7 @@ var SettleLoop = (_class6 = class {
2876
2899
  this._pending = true;
2877
2900
  return;
2878
2901
  }
2879
- const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _126 => _126.debounceMs]), () => ( this._default_debounce_ms));
2902
+ const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.debounceMs]), () => ( this._default_debounce_ms));
2880
2903
  const due = Date.now() + delay;
2881
2904
  if (this._timer) {
2882
2905
  if (due >= this._due) return;
@@ -3111,7 +3134,7 @@ var Act = (_class7 = class {
3111
3134
  /** Apps that declare no lanes pass no lane filter to `claim`. */
3112
3135
  _build_drain_controllers(options, lanes, handle, handle_batch) {
3113
3136
  const all_lanes = this._declared_lanes;
3114
- const only_set = _optionalChain([options, 'access', _127 => _127.onlyLanes, 'optionalAccess', _128 => _128.length]) ? new Set(options.onlyLanes) : void 0;
3137
+ const only_set = _optionalChain([options, 'access', _128 => _128.onlyLanes, 'optionalAccess', _129 => _129.length]) ? new Set(options.onlyLanes) : void 0;
3115
3138
  const active_lanes = only_set ? all_lanes.filter((n) => only_set.has(n)) : all_lanes;
3116
3139
  const single_default_lane = lanes.length === 0;
3117
3140
  const controllers = /* @__PURE__ */ new Map();
@@ -3148,7 +3171,7 @@ var Act = (_class7 = class {
3148
3171
  leaseMillis: cfg.leaseMillis
3149
3172
  }
3150
3173
  });
3151
- if (_optionalChain([cfg, 'optionalAccess', _129 => _129.cycleMs]) !== void 0 && this._drain)
3174
+ if (_optionalChain([cfg, 'optionalAccess', _130 => _130.cycleMs]) !== void 0 && this._drain)
3152
3175
  controller.start(cfg.cycleMs);
3153
3176
  controllers.set(name, controller);
3154
3177
  }
@@ -3199,7 +3222,7 @@ var Act = (_class7 = class {
3199
3222
  await walk_streams(_chunkBNTVE7RQcjs.store.call(void 0, ), (pos) => {
3200
3223
  if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
3201
3224
  const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
3202
- _optionalChain([controller, 'optionalAccess', _130 => _130.seed_defer, 'call', _131 => _131(pos.stream, pos.deferred_at)]);
3225
+ _optionalChain([controller, 'optionalAccess', _131 => _131.seed_defer, 'call', _132 => _132(pos.stream, pos.deferred_at)]);
3203
3226
  });
3204
3227
  }
3205
3228
  _build_settle(options) {
@@ -3240,7 +3263,7 @@ var Act = (_class7 = class {
3240
3263
  for (const c of this._drain_controllers.values()) c.stop();
3241
3264
  const disposer = await this._notify_disposer;
3242
3265
  if (disposer) await disposer();
3243
- await this._await_inflight(_optionalChain([options, 'optionalAccess', _132 => _132.graceMs]));
3266
+ await this._await_inflight(_optionalChain([options, 'optionalAccess', _133 => _133.graceMs]));
3244
3267
  await this._scoped(() => this._correlate.release_correlation());
3245
3268
  this._emitter.removeAllListeners();
3246
3269
  })();
@@ -3338,8 +3361,8 @@ var Act = (_class7 = class {
3338
3361
  * @see {@link ValidationError}, {@link PreconditionError}, {@link ConcurrencyError}
3339
3362
  */
3340
3363
  async do(action2, target, payload, options) {
3341
- const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _133 => _133.reactingTo]), () => ( _chunkBNTVE7RQcjs.current_reacting.call(void 0, )));
3342
- const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _134 => _134.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3364
+ const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _134 => _134.reactingTo]), () => ( _chunkBNTVE7RQcjs.current_reacting.call(void 0, )));
3365
+ const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _135 => _135.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3343
3366
  return this._scoped(async () => {
3344
3367
  const snapshots = await this._es.action(
3345
3368
  this.registry.actions[action2],
@@ -3403,7 +3426,7 @@ var Act = (_class7 = class {
3403
3426
  const gated = this.registry.query_gate(e.name)(e);
3404
3427
  if (!first) first = gated;
3405
3428
  last = gated;
3406
- _optionalChain([callback, 'optionalCall', _135 => _135(gated)]);
3429
+ _optionalChain([callback, 'optionalCall', _136 => _136(gated)]);
3407
3430
  }, query);
3408
3431
  return { first, last, count };
3409
3432
  });
@@ -3530,7 +3553,7 @@ var Act = (_class7 = class {
3530
3553
  }
3531
3554
  if (to_arm.size === 0) return false;
3532
3555
  this._correlate.arm();
3533
- for (const lane of to_arm) _optionalChain([this, 'access', _136 => _136._drain_controllers, 'access', _137 => _137.get, 'call', _138 => _138(lane), 'optionalAccess', _139 => _139.arm, 'call', _140 => _140()]);
3556
+ for (const lane of to_arm) _optionalChain([this, 'access', _137 => _137._drain_controllers, 'access', _138 => _138.get, 'call', _139 => _139(lane), 'optionalAccess', _140 => _140.arm, 'call', _141 => _141()]);
3534
3557
  return true;
3535
3558
  }
3536
3559
  /** In parallel, so a slow lane never holds up a fast one. */
@@ -3674,7 +3697,7 @@ var Act = (_class7 = class {
3674
3697
  return this._scoped(async () => {
3675
3698
  const count = await _chunkBNTVE7RQcjs.store.call(void 0, ).reset(input);
3676
3699
  for (const handler of this._batch_handlers.values())
3677
- _optionalChain([handler, 'access', _141 => _141[FOLD_RESET], 'optionalCall', _142 => _142()]);
3700
+ _optionalChain([handler, 'access', _142 => _142[FOLD_RESET], 'optionalCall', _143 => _143()]);
3678
3701
  if (count > 0) {
3679
3702
  this._wake();
3680
3703
  }
@@ -3813,7 +3836,7 @@ var Act = (_class7 = class {
3813
3836
  (p) => {
3814
3837
  positions.push(p);
3815
3838
  },
3816
- { blocked: true, after: _optionalChain([options, 'optionalAccess', _143 => _143.after]), limit: _optionalChain([options, 'optionalAccess', _144 => _144.limit]) }
3839
+ { blocked: true, after: _optionalChain([options, 'optionalAccess', _144 => _144.after]), limit: _optionalChain([options, 'optionalAccess', _145 => _145.limit]) }
3817
3840
  );
3818
3841
  return positions;
3819
3842
  });
@@ -4007,12 +4030,12 @@ function policy_min_after_days(options) {
4007
4030
  const parsed = AutoclosePolicySchema.parse(options);
4008
4031
  const windows = [];
4009
4032
  if (parsed.after) windows.push(parsed.after.days);
4010
- if (_optionalChain([parsed, 'access', _145 => _145.or, 'optionalAccess', _146 => _146.after])) windows.push(parsed.or.after.days);
4033
+ if (_optionalChain([parsed, 'access', _146 => _146.or, 'optionalAccess', _147 => _147.after])) windows.push(parsed.or.after.days);
4011
4034
  return windows.length ? Math.min(...windows) : void 0;
4012
4035
  }
4013
4036
  function policy_keep_days(options) {
4014
4037
  const parsed = AutoclosePolicySchema.parse(options);
4015
- return _optionalChain([parsed, 'access', _147 => _147.keep, 'optionalAccess', _148 => _148.days]);
4038
+ return _optionalChain([parsed, 'access', _148 => _148.keep, 'optionalAccess', _149 => _149.days]);
4016
4039
  }
4017
4040
  function compile_autoclose_policy(options) {
4018
4041
  const parsed = AutoclosePolicySchema.parse(options);
@@ -4044,7 +4067,7 @@ function hour_in_zone(now, timeZone) {
4044
4067
  hour: "2-digit",
4045
4068
  hourCycle: "h23"
4046
4069
  }).formatToParts(now);
4047
- return Number(_optionalChain([parts, 'access', _149 => _149.find, 'call', _150 => _150((p) => p.type === "hour"), 'optionalAccess', _151 => _151.value]));
4070
+ return Number(_optionalChain([parts, 'access', _150 => _150.find, 'call', _151 => _151((p) => p.type === "hour"), 'optionalAccess', _152 => _152.value]));
4048
4071
  }
4049
4072
  function hour_in_range(hour, start, end) {
4050
4073
  return start < end ? hour >= start && hour < end : hour >= start || hour < end;
@@ -4142,7 +4165,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
4142
4165
  };
4143
4166
  const key = `__autoclose_${st.name}`;
4144
4167
  for (const event_name of Object.keys(st.events)) {
4145
- _optionalChain([registry, 'access', _152 => _152.events, 'access', _153 => _153[event_name], 'optionalAccess', _154 => _154.reactions, 'access', _155 => _155.set, 'call', _156 => _156(
4168
+ _optionalChain([registry, 'access', _153 => _153.events, 'access', _154 => _154[event_name], 'optionalAccess', _155 => _155.reactions, 'access', _156 => _156.set, 'call', _157 => _157(
4146
4169
  key,
4147
4170
  reaction
4148
4171
  )]);
@@ -4387,9 +4410,9 @@ function reaction_on(event, events, builder) {
4387
4410
  // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
4388
4411
  // not a NaN gate on the first retry.
4389
4412
  options: _chunkBNTVE7RQcjs.resolveReactionConfig.call(void 0, {
4390
- blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _157 => _157.blockOnError]), () => ( _chunkBNTVE7RQcjs.DEFAULT_BLOCK_ON_ERROR)),
4391
- maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _158 => _158.maxRetries]), () => ( _chunkBNTVE7RQcjs.DEFAULT_MAX_RETRIES)),
4392
- backoff: _optionalChain([options, 'optionalAccess', _159 => _159.backoff])
4413
+ blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _158 => _158.blockOnError]), () => ( _chunkBNTVE7RQcjs.DEFAULT_BLOCK_ON_ERROR)),
4414
+ maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _159 => _159.maxRetries]), () => ( _chunkBNTVE7RQcjs.DEFAULT_MAX_RETRIES)),
4415
+ backoff: _optionalChain([options, 'optionalAccess', _160 => _160.backoff])
4393
4416
  })
4394
4417
  };
4395
4418
  },
@@ -4408,9 +4431,9 @@ function reaction_on(event, events, builder) {
4408
4431
 
4409
4432
  // src/internal/date-reviver.ts
4410
4433
 
4411
- var def_of = (schema) => _nullishCoalesce(_optionalChain([schema, 'access', _160 => _160._zod, 'optionalAccess', _161 => _161.def]), () => ( schema.def));
4434
+ var def_of = (schema) => _nullishCoalesce(_optionalChain([schema, 'access', _161 => _161._zod, 'optionalAccess', _162 => _162.def]), () => ( schema.def));
4412
4435
  function variant_schema(schema) {
4413
- const shape = _optionalChain([def_of, 'call', _162 => _162(schema), 'optionalAccess', _163 => _163.shape]);
4436
+ const shape = _optionalChain([def_of, 'call', _163 => _163(schema), 'optionalAccess', _164 => _164.shape]);
4414
4437
  if (!shape) {
4415
4438
  const dates = date_reviver_schema(schema);
4416
4439
  return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
@@ -4458,7 +4481,7 @@ function date_reviver_schema(schema) {
4458
4481
  return variants.some((v) => v.dated) ? _zod2.z.union(variants.map((v) => v.schema)) : void 0;
4459
4482
  }
4460
4483
  case "nullable":
4461
- return _optionalChain([inner, 'call', _164 => _164(), 'optionalAccess', _165 => _165.nullable, 'call', _166 => _166()]);
4484
+ return _optionalChain([inner, 'call', _165 => _165(), 'optionalAccess', _166 => _166.nullable, 'call', _167 => _167()]);
4462
4485
  case "optional":
4463
4486
  case "nonoptional":
4464
4487
  case "readonly":
@@ -4635,7 +4658,7 @@ function act() {
4635
4658
  let _built = false;
4636
4659
  const read_wrap = (original) => {
4637
4660
  const wrapped = async (events, stream) => {
4638
- const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _167 => _167.get, 'call', _168 => _168(e.name), 'optionalCall', _169 => _169(e)]), () => ( e)));
4661
+ const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _168 => _168.get, 'call', _169 => _169(e.name), 'optionalCall', _170 => _170(e)]), () => ( e)));
4639
4662
  return original(read, stream);
4640
4663
  };
4641
4664
  const reset = original[FOLD_RESET];
@@ -4677,7 +4700,7 @@ function act() {
4677
4700
  });
4678
4701
  }
4679
4702
  for (const [action_name, handler] of Object.entries(state2.on)) {
4680
- const static_target = _optionalChain([handler, 'optionalAccess', _170 => _170._static_emit]);
4703
+ const static_target = _optionalChain([handler, 'optionalAccess', _171 => _171._static_emit]);
4681
4704
  if (static_target && deprecated.has(static_target)) {
4682
4705
  const current = current_version_of(static_target, event_names);
4683
4706
  throw new Error(
@@ -4750,7 +4773,7 @@ function act() {
4750
4773
  `State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
4751
4774
  );
4752
4775
  const claimed = fold_specs.find((s) => s.target === proj.target);
4753
- if (_optionalChain([claimed, 'optionalAccess', _171 => _171.projection]) === proj) continue;
4776
+ if (_optionalChain([claimed, 'optionalAccess', _172 => _172.projection]) === proj) continue;
4754
4777
  if (batch_handlers.has(proj.target) || claimed)
4755
4778
  throw new Error(
4756
4779
  `Duplicate projection target "${proj.target}" \u2014 a target is served by one batch handler or one state projection, never both`