@rotorsoft/act 2.1.4 → 2.1.5

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.cjs CHANGED
@@ -1161,9 +1161,101 @@ var subscribe = (streams, correlated_at, correlator) => _chunkQWYMR7ZPcjs.store.
1161
1161
  // src/internal/event-sourcing.ts
1162
1162
  var _actpatch = require('@rotorsoft/act-patch');
1163
1163
 
1164
+
1165
+ // src/internal/date-reviver.ts
1166
+
1167
+ function variant_schema(schema, walk) {
1168
+ const shape = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, schema), 'optionalAccess', _50 => _50.shape]);
1169
+ if (!shape) {
1170
+ const dates = walk(schema);
1171
+ return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
1172
+ }
1173
+ const next = {};
1174
+ let dated = false;
1175
+ for (const [key, field] of Object.entries(shape)) {
1176
+ const dates = walk(field);
1177
+ if (dates) dated = true;
1178
+ next[key] = (_nullishCoalesce(dates, () => ( field))).optional();
1179
+ }
1180
+ return { schema: _zod.z.looseObject(next), dated };
1181
+ }
1182
+ function date_reviver_schema(schema) {
1183
+ let recursive = false;
1184
+ const pass = (tie) => {
1185
+ const done = /* @__PURE__ */ new Map();
1186
+ const active = /* @__PURE__ */ new Set();
1187
+ const walk = (node) => {
1188
+ if (done.has(node)) return done.get(node);
1189
+ if (active.has(node)) {
1190
+ recursive = true;
1191
+ return tie ? _zod.z.lazy(() => done.get(node)) : void 0;
1192
+ }
1193
+ active.add(node);
1194
+ const result = build(node, walk);
1195
+ active.delete(node);
1196
+ done.set(node, result);
1197
+ return result;
1198
+ };
1199
+ return walk(schema);
1200
+ };
1201
+ const first = pass(false);
1202
+ return first && recursive ? pass(true) : first;
1203
+ }
1204
+ function build(schema, walk) {
1205
+ const def = _chunkQFYPSI6Pcjs.def_of.call(void 0, schema);
1206
+ if (!def) return void 0;
1207
+ const inner = () => walk(def.innerType);
1208
+ switch (def.type) {
1209
+ case "date":
1210
+ return _zod.z.coerce.date();
1211
+ case "object": {
1212
+ const shape = def.shape;
1213
+ if (!shape) return void 0;
1214
+ const dated = {};
1215
+ for (const [key, field] of Object.entries(shape)) {
1216
+ const dates = walk(field);
1217
+ if (dates) dated[key] = dates.optional();
1218
+ }
1219
+ return Object.keys(dated).length ? _zod.z.looseObject(dated) : void 0;
1220
+ }
1221
+ case "array": {
1222
+ const element = walk(def.element);
1223
+ return element && _zod.z.array(element);
1224
+ }
1225
+ case "tuple": {
1226
+ const items = def.items.map((i) => walk(i));
1227
+ return items.some(Boolean) ? _zod.z.tuple(items.map((i) => _nullishCoalesce(i, () => ( _zod.z.unknown())))) : void 0;
1228
+ }
1229
+ case "record": {
1230
+ const value = walk(def.valueType);
1231
+ return value && _zod.z.record(_zod.z.string(), value);
1232
+ }
1233
+ case "union": {
1234
+ const variants = def.options.map(
1235
+ (o) => variant_schema(o, walk)
1236
+ );
1237
+ return variants.some((v) => v.dated) ? _zod.z.union(variants.map((v) => v.schema)) : void 0;
1238
+ }
1239
+ case "nullable":
1240
+ return _optionalChain([inner, 'call', _51 => _51(), 'optionalAccess', _52 => _52.nullable, 'call', _53 => _53()]);
1241
+ case "pipe":
1242
+ return walk(def.out);
1243
+ case "lazy":
1244
+ return walk(def.getter());
1245
+ case "intersection": {
1246
+ const left = walk(def.left);
1247
+ const right = walk(def.right);
1248
+ return left && right ? left.pipe(right) : _nullishCoalesce(left, () => ( right));
1249
+ }
1250
+ default:
1251
+ return _chunkQFYPSI6Pcjs.inner_of.call(void 0, def) ? inner() : void 0;
1252
+ }
1253
+ }
1254
+
1255
+ // src/internal/event-sourcing.ts
1164
1256
  var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
1165
1257
  var value_at = (value, path) => path.reduce(
1166
- (at, key) => _optionalChain([at, 'optionalAccess', _50 => _50[key]]),
1258
+ (at, key) => _optionalChain([at, 'optionalAccess', _54 => _54[key]]),
1167
1259
  value
1168
1260
  );
1169
1261
  var check_invariants = (target, state2, schema, pii_aware) => {
@@ -1264,6 +1356,12 @@ async function scan(source, opts = {}, callback) {
1264
1356
  let processed = 0;
1265
1357
  let at;
1266
1358
  const started = /* @__PURE__ */ new Set();
1359
+ const migration_dates = new Map(
1360
+ Object.entries(_nullishCoalesce(event_migrations, () => ( {}))).map(([name, { from_schema }]) => [
1361
+ name,
1362
+ date_reviver_schema(from_schema)
1363
+ ])
1364
+ );
1267
1365
  const closed_streams = /* @__PURE__ */ new Set();
1268
1366
  if (drop_closed_streams) {
1269
1367
  await source.query(
@@ -1304,9 +1402,12 @@ async function scan(source, opts = {}, callback) {
1304
1402
  return;
1305
1403
  }
1306
1404
  let migrated = event;
1307
- const migration = _optionalChain([event_migrations, 'optionalAccess', _51 => _51[event.name]]);
1405
+ const migration = _optionalChain([event_migrations, 'optionalAccess', _55 => _55[event.name]]);
1308
1406
  if (migration) {
1309
- const old_data = migration.from_schema.parse(event.data);
1407
+ const revived = _optionalChain([migration_dates, 'access', _56 => _56.get, 'call', _57 => _57(event.name), 'optionalAccess', _58 => _58.safeParse, 'call', _59 => _59(event.data)]);
1408
+ const old_data = migration.from_schema.parse(
1409
+ _optionalChain([revived, 'optionalAccess', _60 => _60.success]) ? revived.data : event.data
1410
+ );
1310
1411
  const new_data = migration.migrate(old_data);
1311
1412
  migration.to_schema.parse(new_data);
1312
1413
  migrated = {
@@ -1343,6 +1444,7 @@ async function scan(source, opts = {}, callback) {
1343
1444
  // A cause missing from the source has no id in the new
1344
1445
  // log; its old id would name another event there.
1345
1446
  id: _nullishCoalesce(id_map.get(cause.id), () => ( -1)),
1447
+ name: _nullishCoalesce(_optionalChain([event_migrations, 'optionalAccess', _61 => _61[cause.name], 'optionalAccess', _62 => _62.to]), () => ( cause.name)),
1346
1448
  stream: stream_rename ? stream_rename(cause.stream) : cause.stream
1347
1449
  }
1348
1450
  }
@@ -1374,9 +1476,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1374
1476
  const seeded = time_travel && asOf.limit === void 0 && !asOf.created_after;
1375
1477
  const cached = time_travel ? void 0 : await _chunkQWYMR7ZPcjs.cache.call(void 0, ).get(stream);
1376
1478
  const cache_hit = !!cached;
1377
- let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _52 => _52.state]), () => ( (me.init ? me.init() : {})));
1378
- let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _53 => _53.patches]), () => ( 0));
1379
- let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _54 => _54.snaps]), () => ( 0));
1479
+ let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _63 => _63.state]), () => ( (me.init ? me.init() : {})));
1480
+ let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _64 => _64.patches]), () => ( 0));
1481
+ let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _65 => _65.snaps]), () => ( 0));
1380
1482
  let replayed = 0;
1381
1483
  let event;
1382
1484
  await _chunkQWYMR7ZPcjs.store.call(void 0, ).query(
@@ -1397,7 +1499,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1397
1499
  `Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
1398
1500
  );
1399
1501
  }
1400
- _optionalChain([callback, 'optionalCall', _55 => _55({
1502
+ _optionalChain([callback, 'optionalCall', _66 => _66({
1401
1503
  event,
1402
1504
  state: state2,
1403
1505
  version: event.version,
@@ -1421,7 +1523,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1421
1523
  ) : time_travel ? asOf : { with_snaps: true }
1422
1524
  }
1423
1525
  );
1424
- const head_is_tombstone = _optionalChain([event, 'optionalAccess', _56 => _56.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT;
1526
+ const head_is_tombstone = _optionalChain([event, 'optionalAccess', _67 => _67.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT;
1425
1527
  if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
1426
1528
  await cache_put(stream, {
1427
1529
  stream,
@@ -1435,9 +1537,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1435
1537
  return {
1436
1538
  event,
1437
1539
  state: state2,
1438
- version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _57 => _57.version]), () => ( _optionalChain([cached, 'optionalAccess', _58 => _58.version]))), () => ( -1)),
1540
+ version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _68 => _68.version]), () => ( _optionalChain([cached, 'optionalAccess', _69 => _69.version]))), () => ( -1)),
1439
1541
  // Captured with `state`, so consumers never race a separate cache lookup.
1440
- id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _59 => _59.id]), () => ( _optionalChain([cached, 'optionalAccess', _60 => _60.event_id]))), () => ( -1)),
1542
+ id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _70 => _70.id]), () => ( _optionalChain([cached, 'optionalAccess', _71 => _71.event_id]))), () => ( -1)),
1441
1543
  patches,
1442
1544
  snaps,
1443
1545
  cache_hit,
@@ -1464,7 +1566,7 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
1464
1566
  void 0,
1465
1567
  patch_fn
1466
1568
  );
1467
- if (_optionalChain([snapshot, 'access', _61 => _61.event, 'optionalAccess', _62 => _62.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT)
1569
+ if (_optionalChain([snapshot, 'access', _72 => _72.event, 'optionalAccess', _73 => _73.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT)
1468
1570
  throw new (0, _chunkQFYPSI6Pcjs.StreamClosedError)(stream);
1469
1571
  return {
1470
1572
  state: l.state,
@@ -1479,12 +1581,12 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
1479
1581
  async function action(me, action2, target, payload, options, patch_fn = bare_patch) {
1480
1582
  const { stream, expectedVersion, actor } = target;
1481
1583
  if (!stream) throw new Error("Missing target stream");
1482
- const reactingTo = _optionalChain([options, 'optionalAccess', _63 => _63.reactingTo]);
1483
- const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _64 => _64.correlator]), () => ( default_correlator));
1584
+ const reactingTo = _optionalChain([options, 'optionalAccess', _74 => _74.reactingTo]);
1585
+ const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.correlator]), () => ( default_correlator));
1484
1586
  const validated = _chunkQWYMR7ZPcjs.validate.call(void 0, action2, payload, me.actions[action2]);
1485
- const opts = _optionalChain([me, 'access', _65 => _65.options, 'optionalAccess', _66 => _66[action2]]);
1486
- const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _67 => _67.maxRetries]), () => ( 0));
1487
- const loads = _nullishCoalesce(_optionalChain([me, 'access', _68 => _68.loads, 'optionalAccess', _69 => _69[action2]]), () => ( []));
1587
+ const opts = _optionalChain([me, 'access', _76 => _76.options, 'optionalAccess', _77 => _77[action2]]);
1588
+ const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _78 => _78.maxRetries]), () => ( 0));
1589
+ const loads = _nullishCoalesce(_optionalChain([me, 'access', _79 => _79.loads, 'optionalAccess', _80 => _80[action2]]), () => ( []));
1488
1590
  for (let attempt = 0; ; attempt++) {
1489
1591
  try {
1490
1592
  const snapshot = await load(
@@ -1493,7 +1595,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1493
1595
  void 0,
1494
1596
  patch_fn
1495
1597
  );
1496
- if (_optionalChain([snapshot, 'access', _70 => _70.event, 'optionalAccess', _71 => _71.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT)
1598
+ if (_optionalChain([snapshot, 'access', _81 => _81.event, 'optionalAccess', _82 => _82.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT)
1497
1599
  throw new (0, _chunkQFYPSI6Pcjs.StreamClosedError)(stream);
1498
1600
  const own = {
1499
1601
  state: me,
@@ -1517,9 +1619,9 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1517
1619
  )
1518
1620
  ) : [];
1519
1621
  const loaded = Object.fromEntries(
1520
- others.map((p, i) => [loads[i].name, _optionalChain([p, 'optionalAccess', _72 => _72.snapshot, 'access', _73 => _73.state])])
1622
+ others.map((p, i) => [loads[i].name, _optionalChain([p, 'optionalAccess', _83 => _83.snapshot, 'access', _84 => _84.state])])
1521
1623
  );
1522
- for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _74 => _74.requires, 'optionalAccess', _75 => _75[action2]]), () => ( [])))
1624
+ for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _85 => _85.requires, 'optionalAccess', _86 => _86[action2]]), () => ( [])))
1523
1625
  if (!holds(validated, snapshot.state, actor, loaded))
1524
1626
  throw new (0, _chunkQFYPSI6Pcjs.PreconditionError)(
1525
1627
  action2,
@@ -1551,10 +1653,10 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1551
1653
  `Action "${action2}" appends only to the streams it loads; it must append an event to its own stream too`
1552
1654
  );
1553
1655
  const appends = [own, ...others].filter(
1554
- (p) => !!_optionalChain([p, 'optionalAccess', _76 => _76.events, 'access', _77 => _77.length])
1656
+ (p) => !!_optionalChain([p, 'optionalAccess', _87 => _87.events, 'access', _88 => _88.length])
1555
1657
  );
1556
1658
  const meta = {
1557
- correlation: _optionalChain([reactingTo, 'optionalAccess', _78 => _78.meta, 'access', _79 => _79.correlation]) || correlator({
1659
+ correlation: _optionalChain([reactingTo, 'optionalAccess', _89 => _89.meta, 'access', _90 => _90.correlation]) || correlator({
1558
1660
  action: action2,
1559
1661
  state: me.name,
1560
1662
  stream,
@@ -1632,13 +1734,13 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1632
1734
  };
1633
1735
  });
1634
1736
  const last = appended.at(-1);
1635
- const snap_event = _optionalChain([owner, 'access', _80 => _80.snap, 'optionalCall', _81 => _81(last)]) ? await snap(last) : void 0;
1737
+ const snap_event = _optionalChain([owner, 'access', _91 => _91.snap, 'optionalCall', _92 => _92(last)]) ? await snap(last) : void 0;
1636
1738
  if (!owner.pii_aware)
1637
1739
  void cache_put(append.stream, {
1638
1740
  stream: append.stream,
1639
1741
  state: last.state,
1640
- version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _82 => _82.version]), () => ( last.event.version)),
1641
- event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _83 => _83.id]), () => ( last.event.id)),
1742
+ version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _93 => _93.version]), () => ( last.event.version)),
1743
+ event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _94 => _94.id]), () => ( last.event.id)),
1642
1744
  patches: snap_event ? 0 : last.patches,
1643
1745
  snaps: snap_event ? last.snaps + 1 : last.snaps
1644
1746
  });
@@ -1654,7 +1756,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1654
1756
  if (!(error instanceof _chunkQFYPSI6Pcjs.ConcurrencyError)) throw error;
1655
1757
  if (expectedVersion !== void 0 && error.stream === stream) throw error;
1656
1758
  if (attempt >= max_retries) throw error;
1657
- if (_optionalChain([opts, 'optionalAccess', _84 => _84.backoff])) {
1759
+ if (_optionalChain([opts, 'optionalAccess', _95 => _95.backoff])) {
1658
1760
  const delay_ms = compute_backoff_delay(attempt, opts.backoff);
1659
1761
  if (delay_ms > 0) await _chunkQWYMR7ZPcjs.sleep.call(void 0, delay_ms);
1660
1762
  }
@@ -1709,9 +1811,9 @@ var as_of_marker = (asOf) => {
1709
1811
  return parts.length ? ` (as-of ${parts.join(" ")})` : " (as-of)";
1710
1812
  };
1711
1813
  var traced = (inner, exit, entry) => (async (...args) => {
1712
- _optionalChain([entry, 'optionalCall', _85 => _85(...args)]);
1814
+ _optionalChain([entry, 'optionalCall', _96 => _96(...args)]);
1713
1815
  const result = await inner(...args);
1714
- _optionalChain([exit, 'optionalCall', _86 => _86(result, ...args)]);
1816
+ _optionalChain([exit, 'optionalCall', _97 => _97(result, ...args)]);
1715
1817
  return result;
1716
1818
  });
1717
1819
  function build_es(logger, correlator = default_correlator, patch_fn = bare_patch) {
@@ -1720,7 +1822,7 @@ function build_es(logger, correlator = default_correlator, patch_fn = bare_patch
1720
1822
  action_name,
1721
1823
  target,
1722
1824
  payload,
1723
- { ...options, correlator: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _87 => _87.correlator]), () => ( correlator)) },
1825
+ { ...options, correlator: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _98 => _98.correlator]), () => ( correlator)) },
1724
1826
  patch_fn
1725
1827
  );
1726
1828
  const bound_load = (me, target, callback) => load(me, target, callback, patch_fn);
@@ -1794,7 +1896,7 @@ function build_drain(logger) {
1794
1896
  subscribe: logger.level !== "trace" ? subscribe : traced(subscribe, (result, streams) => {
1795
1897
  if (!result.subscribed) return;
1796
1898
  const lanes = new Set(streams.map((s) => _nullishCoalesce(s.lane, () => ( "default"))));
1797
- const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _88 => _88[0], 'optionalAccess', _89 => _89.lane]) : void 0;
1899
+ const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _99 => _99[0], 'optionalAccess', _100 => _100.lane]) : void 0;
1798
1900
  const data = streams.map(
1799
1901
  ({ stream, lane }) => uniform_lane || !lane || lane === "default" ? hue(C_STREAM, stream) : `${hue(C_STREAM, stream)}${dim(`[${lane}]`)}`
1800
1902
  ).join(" ");
@@ -1806,7 +1908,7 @@ function build_drain(logger) {
1806
1908
  }
1807
1909
  function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
1808
1910
  if (logger.level !== "trace" || !leased.length) return;
1809
- const lane = _optionalChain([leased, 'access', _90 => _90[0], 'optionalAccess', _91 => _91.lane]);
1911
+ const lane = _optionalChain([leased, 'access', _101 => _101[0], 'optionalAccess', _102 => _102.lane]);
1810
1912
  const fetch_by_stream = new Map(fetched.map((f) => [f.stream, f]));
1811
1913
  const acked_by_stream = new Map(acked.map((a) => [a.stream, a.at]));
1812
1914
  const blocked_by_stream = new Map(blocked.map((b) => [b.stream, b.error]));
@@ -1815,8 +1917,8 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
1815
1917
  );
1816
1918
  const detail = leased.map(({ stream, at, retry }) => {
1817
1919
  const f = fetch_by_stream.get(stream);
1818
- const key = _optionalChain([f, 'optionalAccess', _92 => _92.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
1819
- const events = _optionalChain([f, 'optionalAccess', _93 => _93.events, 'access', _94 => _94.length]) ? ` ${dim(
1920
+ const key = _optionalChain([f, 'optionalAccess', _103 => _103.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
1921
+ const events = _optionalChain([f, 'optionalAccess', _104 => _104.events, 'access', _105 => _105.length]) ? ` ${dim(
1820
1922
  `[${f.events.map(({ id, name }) => `#${id} ${String(name)}`).join(", ")}]`
1821
1923
  )}` : "";
1822
1924
  const acked_at = acked_by_stream.get(stream);
@@ -1844,7 +1946,7 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
1844
1946
 
1845
1947
  // src/internal/drain-cycle.ts
1846
1948
  function budget_exhausted(lease, options, store_failing) {
1847
- if (store_failing || !_optionalChain([options, 'optionalAccess', _95 => _95.blockOnError]) || lease.retry <= options.maxRetries)
1949
+ if (store_failing || !_optionalChain([options, 'optionalAccess', _106 => _106.blockOnError]) || lease.retry <= options.maxRetries)
1848
1950
  return void 0;
1849
1951
  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.`;
1850
1952
  _chunkQWYMR7ZPcjs.log.call(void 0, ).error(error);
@@ -1908,7 +2010,7 @@ async function run_drain_cycle(deps, cycle) {
1908
2010
  const fetched = await ops.fetch(leased, eventLimit);
1909
2011
  const fetch_map = /* @__PURE__ */ new Map();
1910
2012
  const fetch_window_at = fetched.reduce(
1911
- (max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _96 => _96.at, 'call', _97 => _97(-1), 'optionalAccess', _98 => _98.id]) || at),
2013
+ (max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _107 => _107.at, 'call', _108 => _108(-1), 'optionalAccess', _109 => _109.id]) || at),
1912
2014
  0
1913
2015
  );
1914
2016
  for (const f of fetched) {
@@ -1972,11 +2074,11 @@ async function run_drain_cycle(deps, cycle) {
1972
2074
  deps.logger
1973
2075
  )
1974
2076
  );
1975
- const at = _optionalChain([entry, 'access', _99 => _99.fetch, 'access', _100 => _100.events, 'access', _101 => _101.at, 'call', _102 => _102(-1), 'optionalAccess', _103 => _103.id]) || fetch_window_at;
2077
+ const at = _optionalChain([entry, 'access', _110 => _110.fetch, 'access', _111 => _111.events, 'access', _112 => _112.at, 'call', _113 => _113(-1), 'optionalAccess', _114 => _114.id]) || fetch_window_at;
1976
2078
  const { payloads } = entry;
1977
2079
  const exhausted = budget_exhausted(
1978
2080
  lease,
1979
- _optionalChain([payloads, 'access', _104 => _104[0], 'optionalAccess', _105 => _105.options]),
2081
+ _optionalChain([payloads, 'access', _115 => _115[0], 'optionalAccess', _116 => _116.options]),
1980
2082
  store_failing
1981
2083
  );
1982
2084
  if (exhausted) return Promise.resolve(exhausted);
@@ -2061,7 +2163,7 @@ var DrainController = (_class3 = class {
2061
2163
  }
2062
2164
  /** This lane's configured lease, or `undefined`; the shutdown grace basis. */
2063
2165
  get lease_millis() {
2064
- return _optionalChain([this, 'access', _106 => _106._deps, 'access', _107 => _107.defaults, 'optionalAccess', _108 => _108.leaseMillis]);
2166
+ return _optionalChain([this, 'access', _117 => _117._deps, 'access', _118 => _118.defaults, 'optionalAccess', _119 => _119.leaseMillis]);
2065
2167
  }
2066
2168
  get lane() {
2067
2169
  return this._deps.lane;
@@ -2187,11 +2289,11 @@ var CloseSignal = class extends Error {
2187
2289
  constructor(opts) {
2188
2290
  super("reaction requested close");
2189
2291
  this.name = "CloseSignal";
2190
- this.stream = _optionalChain([opts, 'optionalAccess', _109 => _109.stream]);
2191
- this.archive = _optionalChain([opts, 'optionalAccess', _110 => _110.archive]);
2192
- this.at = _optionalChain([opts, 'optionalAccess', _111 => _111.at]);
2193
- this.before = _optionalChain([opts, 'optionalAccess', _112 => _112.before]);
2194
- this.defer = _optionalChain([opts, 'optionalAccess', _113 => _113.defer]);
2292
+ this.stream = _optionalChain([opts, 'optionalAccess', _120 => _120.stream]);
2293
+ this.archive = _optionalChain([opts, 'optionalAccess', _121 => _121.archive]);
2294
+ this.at = _optionalChain([opts, 'optionalAccess', _122 => _122.at]);
2295
+ this.before = _optionalChain([opts, 'optionalAccess', _123 => _123.before]);
2296
+ this.defer = _optionalChain([opts, 'optionalAccess', _124 => _124.defer]);
2195
2297
  }
2196
2298
  };
2197
2299
  function build_handle(deps) {
@@ -2245,7 +2347,7 @@ function build_handle(deps) {
2245
2347
  // Advance to the live head the handler evaluated against (when
2246
2348
  // provided) so the close-cycle guard sees this reaction caught up.
2247
2349
  acked_at: _nullishCoalesce(error.at, () => ( event.id)),
2248
- defer: _optionalChain([error, 'access', _114 => _114.defer, 'optionalAccess', _115 => _115.getTime, 'call', _116 => _116()]),
2350
+ defer: _optionalChain([error, 'access', _125 => _125.defer, 'optionalAccess', _126 => _126.getTime, 'call', _127 => _127()]),
2249
2351
  // Close the signalled stream (the autoclose reaction's aggregate,
2250
2352
  // which differs from its synthetic lease stream); a self-closing
2251
2353
  // user reaction omits it and closes its own lease stream. A
@@ -2376,7 +2478,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
2376
2478
  };
2377
2479
  const key = `__autoclose_${st.name}`;
2378
2480
  for (const event_name of Object.keys(st.events)) {
2379
- _optionalChain([registry, 'access', _117 => _117.events, 'access', _118 => _118[event_name], 'optionalAccess', _119 => _119.reactions, 'access', _120 => _120.set, 'call', _121 => _121(
2481
+ _optionalChain([registry, 'access', _128 => _128.events, 'access', _129 => _129[event_name], 'optionalAccess', _130 => _130.reactions, 'access', _131 => _131.set, 'call', _132 => _132(
2380
2482
  key,
2381
2483
  reaction
2382
2484
  )]);
@@ -2432,7 +2534,7 @@ async function run_close_cycle(targets, deps) {
2432
2534
  () => run_full_closes(full, target_map, deps, skipped)
2433
2535
  );
2434
2536
  const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT).map(([stream]) => stream);
2435
- if (retired.length) _optionalChain([deps, 'access', _122 => _122.forget_subscribed, 'optionalCall', _123 => _123(retired)]);
2537
+ if (retired.length) _optionalChain([deps, 'access', _133 => _133.forget_subscribed, 'optionalCall', _134 => _134(retired)]);
2436
2538
  for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
2437
2539
  return { truncated, skipped };
2438
2540
  }
@@ -2452,7 +2554,7 @@ async function run_full_closes(full, target_map, deps, skipped) {
2452
2554
  const info = stream_info.get(target.stream);
2453
2555
  if (!info) continue;
2454
2556
  const owner = deps.event_to_state.get(info.last_event_name);
2455
- if (_optionalChain([owner, 'optionalAccess', _124 => _124.pii_aware])) {
2557
+ if (_optionalChain([owner, 'optionalAccess', _135 => _135.pii_aware])) {
2456
2558
  deps.logger.error(
2457
2559
  `Refusing to close "${target.stream}" with restart: state "${owner.name}" carries sensitive fields, so a restart seed would persist redacted values while deleting the originals. Close it without restart to retire the stream, or leave it open.`
2458
2560
  );
@@ -2578,8 +2680,8 @@ async function scan_stream_heads(streams) {
2578
2680
  const true_heads = await _chunkQWYMR7ZPcjs.store.call(void 0, ).query_stats(streams, {});
2579
2681
  const out = /* @__PURE__ */ new Map();
2580
2682
  for (const [stream, { head }] of domain_heads) {
2581
- const marker_head = _optionalChain([stats, 'access', _125 => _125.get, 'call', _126 => _126(stream), 'optionalAccess', _127 => _127.head]);
2582
- const interrupted = _optionalChain([marker_head, 'optionalAccess', _128 => _128.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT;
2683
+ const marker_head = _optionalChain([stats, 'access', _136 => _136.get, 'call', _137 => _137(stream), 'optionalAccess', _138 => _138.head]);
2684
+ const interrupted = _optionalChain([marker_head, 'optionalAccess', _139 => _139.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT;
2583
2685
  out.set(stream, {
2584
2686
  max_id: head.id,
2585
2687
  version: true_heads.get(stream).head.version,
@@ -2647,7 +2749,7 @@ async function guard_with_tombstones(safe, stream_info, correlation, tombstone2,
2647
2749
  async function load_restart_seeds(guarded, target_map, stream_info, event_to_state, load2, logger) {
2648
2750
  const seed_states = /* @__PURE__ */ new Map();
2649
2751
  await Promise.all(
2650
- guarded.filter((s) => _optionalChain([target_map, 'access', _129 => _129.get, 'call', _130 => _130(s), 'optionalAccess', _131 => _131.restart])).map(async (stream) => {
2752
+ guarded.filter((s) => _optionalChain([target_map, 'access', _140 => _140.get, 'call', _141 => _141(s), 'optionalAccess', _142 => _142.restart])).map(async (stream) => {
2651
2753
  const last_event_name = stream_info.get(stream).last_event_name;
2652
2754
  const owner_state = event_to_state.get(last_event_name);
2653
2755
  if (!owner_state) {
@@ -2664,14 +2766,14 @@ async function load_restart_seeds(guarded, target_map, stream_info, event_to_sta
2664
2766
  }
2665
2767
  async function run_archive_callbacks(guarded, target_map) {
2666
2768
  for (const stream of guarded) {
2667
- const archive_fn = _optionalChain([target_map, 'access', _132 => _132.get, 'call', _133 => _133(stream), 'optionalAccess', _134 => _134.archive]);
2769
+ const archive_fn = _optionalChain([target_map, 'access', _143 => _143.get, 'call', _144 => _144(stream), 'optionalAccess', _145 => _145.archive]);
2668
2770
  if (archive_fn) await archive_fn();
2669
2771
  }
2670
2772
  }
2671
2773
  async function heads_still_guarded(guarded, guard_events, skipped) {
2672
2774
  const heads = await _chunkQWYMR7ZPcjs.store.call(void 0, ).query_stats(guarded, {});
2673
2775
  return guarded.filter((stream) => {
2674
- if (_optionalChain([heads, 'access', _135 => _135.get, 'call', _136 => _136(stream), 'optionalAccess', _137 => _137.head, 'access', _138 => _138.id]) === guard_events.get(stream).id)
2776
+ if (_optionalChain([heads, 'access', _146 => _146.get, 'call', _147 => _147(stream), 'optionalAccess', _148 => _148.head, 'access', _149 => _149.id]) === guard_events.get(stream).id)
2675
2777
  return true;
2676
2778
  skipped.push(stream);
2677
2779
  return false;
@@ -2816,7 +2918,7 @@ var CorrelateCycle = (_class5 = class {
2816
2918
  lane
2817
2919
  });
2818
2920
  }
2819
- await _optionalChain([this, 'access', _139 => _139._on_init, 'optionalCall', _140 => _140()]);
2921
+ await _optionalChain([this, 'access', _150 => _150._on_init, 'optionalCall', _151 => _151()]);
2820
2922
  }
2821
2923
  /**
2822
2924
  * Replace the log with no pass in flight, then cold-start: a pass that
@@ -2939,8 +3041,8 @@ var CorrelateCycle = (_class5 = class {
2939
3041
  correlated_at: void 0
2940
3042
  };
2941
3043
  const seen_in_scan = correlated.has(resolved.target);
2942
- const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _141 => _141.lane])), () => ( _chunkQFYPSI6Pcjs.DEFAULT_LANE));
2943
- const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _142 => _142.priority]);
3044
+ const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _152 => _152.lane])), () => ( _chunkQFYPSI6Pcjs.DEFAULT_LANE));
3045
+ const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _153 => _153.priority]);
2944
3046
  const resolved_lane = _nullishCoalesce(lane, () => ( _chunkQFYPSI6Pcjs.DEFAULT_LANE));
2945
3047
  if (held_priority === priority && held_lane !== resolved_lane)
2946
3048
  report_lane_conflict(
@@ -2995,7 +3097,7 @@ var CorrelateCycle = (_class5 = class {
2995
3097
  ).length;
2996
3098
  this._checkpoint = last_id;
2997
3099
  for (const { stream, priority, lane } of streams) {
2998
- if (_optionalChain([correlated, 'access', _143 => _143.get, 'call', _144 => _144(stream), 'optionalAccess', _145 => _145.upgraded]))
3100
+ if (_optionalChain([correlated, 'access', _154 => _154.get, 'call', _155 => _155(stream), 'optionalAccess', _156 => _156.upgraded]))
2999
3101
  this._dynamic_subscriptions.set(stream, {
3000
3102
  priority,
3001
3103
  lane
@@ -3234,7 +3336,7 @@ var SettleLoop = (_class6 = class {
3234
3336
  this._pending = true;
3235
3337
  return;
3236
3338
  }
3237
- const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _146 => _146.debounceMs]), () => ( this._default_debounce_ms));
3339
+ const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _157 => _157.debounceMs]), () => ( this._default_debounce_ms));
3238
3340
  const due = Date.now() + delay;
3239
3341
  if (this._timer) {
3240
3342
  if (due >= this._due) return;
@@ -3480,7 +3582,7 @@ var Act = (_class7 = class {
3480
3582
  // Apps that declare no lanes pass no lane filter to `claim`.
3481
3583
  _build_drain_controllers(options, lanes, handle, handle_batch) {
3482
3584
  const all_lanes = this._declared_lanes;
3483
- const only_set = _optionalChain([options, 'access', _147 => _147.onlyLanes, 'optionalAccess', _148 => _148.length]) ? new Set(options.onlyLanes) : void 0;
3585
+ const only_set = _optionalChain([options, 'access', _158 => _158.onlyLanes, 'optionalAccess', _159 => _159.length]) ? new Set(options.onlyLanes) : void 0;
3484
3586
  const active_lanes = only_set ? all_lanes.filter((n) => only_set.has(n)) : all_lanes;
3485
3587
  const single_default_lane = lanes.length === 0;
3486
3588
  const controllers = /* @__PURE__ */ new Map();
@@ -3517,7 +3619,7 @@ var Act = (_class7 = class {
3517
3619
  leaseMillis: cfg.leaseMillis
3518
3620
  }
3519
3621
  });
3520
- if (_optionalChain([cfg, 'optionalAccess', _149 => _149.cycleMs]) !== void 0 && this._drain)
3622
+ if (_optionalChain([cfg, 'optionalAccess', _160 => _160.cycleMs]) !== void 0 && this._drain)
3521
3623
  controller.start(cfg.cycleMs);
3522
3624
  controllers.set(name, controller);
3523
3625
  }
@@ -3568,7 +3670,7 @@ var Act = (_class7 = class {
3568
3670
  await walk_streams(_chunkQWYMR7ZPcjs.store.call(void 0, ), (pos) => {
3569
3671
  if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
3570
3672
  const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
3571
- _optionalChain([controller, 'optionalAccess', _150 => _150.seed_defer, 'call', _151 => _151(pos.stream, pos.deferred_at)]);
3673
+ _optionalChain([controller, 'optionalAccess', _161 => _161.seed_defer, 'call', _162 => _162(pos.stream, pos.deferred_at)]);
3572
3674
  });
3573
3675
  }
3574
3676
  _build_settle(options) {
@@ -3609,7 +3711,7 @@ var Act = (_class7 = class {
3609
3711
  for (const c of this._drain_controllers.values()) c.stop();
3610
3712
  const disposer = await this._notify_disposer;
3611
3713
  if (disposer) await disposer();
3612
- await this._await_inflight(_optionalChain([options, 'optionalAccess', _152 => _152.graceMs]));
3714
+ await this._await_inflight(_optionalChain([options, 'optionalAccess', _163 => _163.graceMs]));
3613
3715
  await this._scoped(() => this._correlate.release_correlation());
3614
3716
  this._emitter.removeAllListeners();
3615
3717
  })();
@@ -3706,8 +3808,8 @@ var Act = (_class7 = class {
3706
3808
  * @see {@link ValidationError}, {@link PreconditionError}, {@link ConcurrencyError}
3707
3809
  */
3708
3810
  async do(action2, target, payload, options) {
3709
- const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _153 => _153.reactingTo]), () => ( _chunkQWYMR7ZPcjs.current_reacting.call(void 0, )));
3710
- const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _154 => _154.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3811
+ const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _164 => _164.reactingTo]), () => ( _chunkQWYMR7ZPcjs.current_reacting.call(void 0, )));
3812
+ const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _165 => _165.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3711
3813
  return this._scoped(async () => {
3712
3814
  const snapshots = await this._es.action(
3713
3815
  this.registry.actions[action2],
@@ -3784,7 +3886,7 @@ var Act = (_class7 = class {
3784
3886
  const gated = this.registry.query_gate(e.name)(e);
3785
3887
  if (!first) first = gated;
3786
3888
  last = gated;
3787
- _optionalChain([callback, 'optionalCall', _155 => _155(gated)]);
3889
+ _optionalChain([callback, 'optionalCall', _166 => _166(gated)]);
3788
3890
  }, query);
3789
3891
  return { first, last, count };
3790
3892
  });
@@ -3905,7 +4007,7 @@ var Act = (_class7 = class {
3905
4007
  }
3906
4008
  if (to_arm.size === 0) return false;
3907
4009
  this._correlate.arm();
3908
- for (const lane of to_arm) _optionalChain([this, 'access', _156 => _156._drain_controllers, 'access', _157 => _157.get, 'call', _158 => _158(lane), 'optionalAccess', _159 => _159.arm, 'call', _160 => _160()]);
4010
+ for (const lane of to_arm) _optionalChain([this, 'access', _167 => _167._drain_controllers, 'access', _168 => _168.get, 'call', _169 => _169(lane), 'optionalAccess', _170 => _170.arm, 'call', _171 => _171()]);
3909
4011
  return true;
3910
4012
  }
3911
4013
  // In parallel, so a slow lane never holds up a fast one.
@@ -4049,7 +4151,7 @@ var Act = (_class7 = class {
4049
4151
  return this._scoped(async () => {
4050
4152
  const count = await _chunkQWYMR7ZPcjs.store.call(void 0, ).reset(input);
4051
4153
  for (const handler of this._batch_handlers.values())
4052
- _optionalChain([handler, 'access', _161 => _161[FOLD_RESET], 'optionalCall', _162 => _162()]);
4154
+ _optionalChain([handler, 'access', _172 => _172[FOLD_RESET], 'optionalCall', _173 => _173()]);
4053
4155
  if (count > 0) {
4054
4156
  this._wake();
4055
4157
  }
@@ -4188,7 +4290,7 @@ var Act = (_class7 = class {
4188
4290
  (p) => {
4189
4291
  positions.push(p);
4190
4292
  },
4191
- { blocked: true, after: _optionalChain([options, 'optionalAccess', _163 => _163.after]), limit: _optionalChain([options, 'optionalAccess', _164 => _164.limit]) }
4293
+ { blocked: true, after: _optionalChain([options, 'optionalAccess', _174 => _174.after]), limit: _optionalChain([options, 'optionalAccess', _175 => _175.limit]) }
4192
4294
  );
4193
4295
  return positions;
4194
4296
  });
@@ -4561,9 +4663,9 @@ function reaction_on(event, events, builder) {
4561
4663
  // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
4562
4664
  // not a NaN gate on the first retry.
4563
4665
  options: _chunkQWYMR7ZPcjs.resolveReactionConfig.call(void 0, {
4564
- blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _165 => _165.blockOnError]), () => ( _chunkQWYMR7ZPcjs.DEFAULT_BLOCK_ON_ERROR)),
4565
- maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _166 => _166.maxRetries]), () => ( _chunkQWYMR7ZPcjs.DEFAULT_MAX_RETRIES)),
4566
- backoff: _optionalChain([options, 'optionalAccess', _167 => _167.backoff])
4666
+ blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _176 => _176.blockOnError]), () => ( _chunkQWYMR7ZPcjs.DEFAULT_BLOCK_ON_ERROR)),
4667
+ maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _177 => _177.maxRetries]), () => ( _chunkQWYMR7ZPcjs.DEFAULT_MAX_RETRIES)),
4668
+ backoff: _optionalChain([options, 'optionalAccess', _178 => _178.backoff])
4567
4669
  })
4568
4670
  };
4569
4671
  },
@@ -4579,98 +4681,6 @@ function reaction_on(event, events, builder) {
4579
4681
 
4580
4682
  // src/builders/event-builder.ts
4581
4683
 
4582
-
4583
- // src/internal/date-reviver.ts
4584
-
4585
- function variant_schema(schema, walk) {
4586
- const shape = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, schema), 'optionalAccess', _168 => _168.shape]);
4587
- if (!shape) {
4588
- const dates = walk(schema);
4589
- return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
4590
- }
4591
- const next = {};
4592
- let dated = false;
4593
- for (const [key, field] of Object.entries(shape)) {
4594
- const dates = walk(field);
4595
- if (dates) dated = true;
4596
- next[key] = (_nullishCoalesce(dates, () => ( field))).optional();
4597
- }
4598
- return { schema: _zod.z.looseObject(next), dated };
4599
- }
4600
- function date_reviver_schema(schema) {
4601
- let recursive = false;
4602
- const pass = (tie) => {
4603
- const done = /* @__PURE__ */ new Map();
4604
- const active = /* @__PURE__ */ new Set();
4605
- const walk = (node) => {
4606
- if (done.has(node)) return done.get(node);
4607
- if (active.has(node)) {
4608
- recursive = true;
4609
- return tie ? _zod.z.lazy(() => done.get(node)) : void 0;
4610
- }
4611
- active.add(node);
4612
- const result = build(node, walk);
4613
- active.delete(node);
4614
- done.set(node, result);
4615
- return result;
4616
- };
4617
- return walk(schema);
4618
- };
4619
- const first = pass(false);
4620
- return first && recursive ? pass(true) : first;
4621
- }
4622
- function build(schema, walk) {
4623
- const def = _chunkQFYPSI6Pcjs.def_of.call(void 0, schema);
4624
- if (!def) return void 0;
4625
- const inner = () => walk(def.innerType);
4626
- switch (def.type) {
4627
- case "date":
4628
- return _zod.z.coerce.date();
4629
- case "object": {
4630
- const shape = def.shape;
4631
- if (!shape) return void 0;
4632
- const dated = {};
4633
- for (const [key, field] of Object.entries(shape)) {
4634
- const dates = walk(field);
4635
- if (dates) dated[key] = dates.optional();
4636
- }
4637
- return Object.keys(dated).length ? _zod.z.looseObject(dated) : void 0;
4638
- }
4639
- case "array": {
4640
- const element = walk(def.element);
4641
- return element && _zod.z.array(element);
4642
- }
4643
- case "tuple": {
4644
- const items = def.items.map((i) => walk(i));
4645
- return items.some(Boolean) ? _zod.z.tuple(items.map((i) => _nullishCoalesce(i, () => ( _zod.z.unknown())))) : void 0;
4646
- }
4647
- case "record": {
4648
- const value = walk(def.valueType);
4649
- return value && _zod.z.record(_zod.z.string(), value);
4650
- }
4651
- case "union": {
4652
- const variants = def.options.map(
4653
- (o) => variant_schema(o, walk)
4654
- );
4655
- return variants.some((v) => v.dated) ? _zod.z.union(variants.map((v) => v.schema)) : void 0;
4656
- }
4657
- case "nullable":
4658
- return _optionalChain([inner, 'call', _169 => _169(), 'optionalAccess', _170 => _170.nullable, 'call', _171 => _171()]);
4659
- case "pipe":
4660
- return walk(def.out);
4661
- case "lazy":
4662
- return walk(def.getter());
4663
- case "intersection": {
4664
- const left = walk(def.left);
4665
- const right = walk(def.right);
4666
- return left && right ? left.pipe(right) : _nullishCoalesce(left, () => ( right));
4667
- }
4668
- default:
4669
- return _chunkQFYPSI6Pcjs.inner_of.call(void 0, def) ? inner() : void 0;
4670
- }
4671
- }
4672
-
4673
- // src/builders/event-builder.ts
4674
4684
  function event_tags(schema) {
4675
4685
  const pii = _chunkQFYPSI6Pcjs.pii_schemas.call(void 0, schema);
4676
4686
  const pii_dates = {};
@@ -4793,7 +4803,7 @@ function build_events(registry, states, lanes, owners) {
4793
4803
  return { sensitive: sensitive2, advisory, query_readers, handler_readers };
4794
4804
  }
4795
4805
  function reads_as_string(schema) {
4796
- const type = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, _chunkQFYPSI6Pcjs.output_of.call(void 0, schema)), 'optionalAccess', _172 => _172.type]);
4806
+ const type = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, _chunkQFYPSI6Pcjs.output_of.call(void 0, schema)), 'optionalAccess', _179 => _179.type]);
4797
4807
  return type === "string" || type === "transform";
4798
4808
  }
4799
4809
 
@@ -4851,7 +4861,7 @@ function act() {
4851
4861
  let _built = false;
4852
4862
  const read_wrap = (original) => {
4853
4863
  const wrapped = async (events, stream) => {
4854
- const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _173 => _173.get, 'call', _174 => _174(e.name), 'optionalCall', _175 => _175(e)]), () => ( e)));
4864
+ const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _180 => _180.get, 'call', _181 => _181(e.name), 'optionalCall', _182 => _182(e)]), () => ( e)));
4855
4865
  return original(read, stream);
4856
4866
  };
4857
4867
  const reset = original[FOLD_RESET];
@@ -4892,7 +4902,7 @@ function act() {
4892
4902
  });
4893
4903
  }
4894
4904
  for (const [action_name, handler] of Object.entries(state2.on)) {
4895
- const static_target = _optionalChain([handler, 'optionalAccess', _176 => _176._static_emit]);
4905
+ const static_target = _optionalChain([handler, 'optionalAccess', _183 => _183._static_emit]);
4896
4906
  if (static_target && deprecated.has(static_target)) {
4897
4907
  const current = current_version_of(static_target, event_names);
4898
4908
  throw new Error(
@@ -4965,7 +4975,7 @@ function act() {
4965
4975
  `State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
4966
4976
  );
4967
4977
  const claimed = fold_specs.find((s) => s.target === proj.target);
4968
- if (_optionalChain([claimed, 'optionalAccess', _177 => _177.projection]) === proj) continue;
4978
+ if (_optionalChain([claimed, 'optionalAccess', _184 => _184.projection]) === proj) continue;
4969
4979
  if (batch_handlers.has(proj.target) || claimed)
4970
4980
  throw new Error(
4971
4981
  `Duplicate projection target "${proj.target}" \u2014 a target is served by one batch handler or one state projection, never both`
@@ -4999,7 +5009,7 @@ function act() {
4999
5009
  `Action "${action2}" loads "${l.state.name}", which is not registered \u2014 add it via withState/withSlice before build()`
5000
5010
  );
5001
5011
  const deprecated = l.events.find(
5002
- (e) => _optionalChain([_de, 'access', _178 => _178.get, 'call', _179 => _179(registered.name), 'optionalAccess', _180 => _180.has, 'call', _181 => _181(e)])
5012
+ (e) => _optionalChain([_de, 'access', _185 => _185.get, 'call', _186 => _186(registered.name), 'optionalAccess', _187 => _187.has, 'call', _188 => _188(e)])
5003
5013
  );
5004
5014
  if (deprecated)
5005
5015
  throw new Error(