@rotorsoft/act 1.33.8 → 1.33.10

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
@@ -40,7 +40,7 @@
40
40
 
41
41
 
42
42
 
43
- var _chunkO6QIJQRNcjs = require('./chunk-O6QIJQRN.cjs');
43
+ var _chunk6J2QWD4Qcjs = require('./chunk-6J2QWD4Q.cjs');
44
44
 
45
45
 
46
46
 
@@ -74,20 +74,20 @@ var _chunk7AHW7FCNcjs = require('./chunk-7AHW7FCN.cjs');
74
74
 
75
75
  // src/signals.ts
76
76
  process.once("SIGINT", async (arg) => {
77
- _chunkO6QIJQRNcjs.log.call(void 0, ).info(arg, "SIGINT");
78
- await _chunkO6QIJQRNcjs.disposeAndExit.call(void 0, "EXIT");
77
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).info(arg, "SIGINT");
78
+ await _chunk6J2QWD4Qcjs.disposeAndExit.call(void 0, "EXIT");
79
79
  });
80
80
  process.once("SIGTERM", async (arg) => {
81
- _chunkO6QIJQRNcjs.log.call(void 0, ).info(arg, "SIGTERM");
82
- await _chunkO6QIJQRNcjs.disposeAndExit.call(void 0, "EXIT");
81
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).info(arg, "SIGTERM");
82
+ await _chunk6J2QWD4Qcjs.disposeAndExit.call(void 0, "EXIT");
83
83
  });
84
84
  process.once("uncaughtException", async (arg) => {
85
- _chunkO6QIJQRNcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
86
- await _chunkO6QIJQRNcjs.disposeAndExit.call(void 0, "ERROR");
85
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
86
+ await _chunk6J2QWD4Qcjs.disposeAndExit.call(void 0, "ERROR");
87
87
  });
88
88
  process.once("unhandledRejection", async (arg) => {
89
- _chunkO6QIJQRNcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
90
- await _chunkO6QIJQRNcjs.disposeAndExit.call(void 0, "ERROR");
89
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
90
+ await _chunk6J2QWD4Qcjs.disposeAndExit.call(void 0, "ERROR");
91
91
  });
92
92
 
93
93
  // src/act.ts
@@ -922,7 +922,7 @@ async function run_windowed_closes(windowed, deps, skipped) {
922
922
  if (!await windowed_prune_pending(t.stream, t.before, max_id))
923
923
  return void 0;
924
924
  if (t.archive) await t.archive();
925
- const result = await _chunkO6QIJQRNcjs.store.call(void 0, ).truncate([
925
+ const result = await _chunk6J2QWD4Qcjs.store.call(void 0, ).truncate([
926
926
  { stream: t.stream, before: t.before, max_id }
927
927
  ]);
928
928
  return result.get(t.stream);
@@ -935,7 +935,7 @@ async function run_windowed_closes(windowed, deps, skipped) {
935
935
  async function windowed_prune_pending(stream, before, max_id) {
936
936
  let boundary_id;
937
937
  let min_id;
938
- await _chunkO6QIJQRNcjs.store.call(void 0, ).query(
938
+ await _chunk6J2QWD4Qcjs.store.call(void 0, ).query(
939
939
  (event) => {
940
940
  if (min_id === void 0 || event.id < min_id) min_id = event.id;
941
941
  if (event.name === _chunk7AHW7FCNcjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
@@ -949,7 +949,7 @@ async function probe_min_watermarks(streams, page_size, checkpoint) {
949
949
  const min_at = /* @__PURE__ */ new Map();
950
950
  const matches = source_matcher();
951
951
  await walk_streams(
952
- _chunkO6QIJQRNcjs.store.call(void 0, ),
952
+ _chunk6J2QWD4Qcjs.store.call(void 0, ),
953
953
  (position) => {
954
954
  const pending = position.correlated_at === void 0 || position.at < position.correlated_at;
955
955
  const cap = pending ? position.at : Math.max(position.at, checkpoint);
@@ -977,13 +977,13 @@ function source_matcher() {
977
977
  };
978
978
  }
979
979
  async function scan_stream_heads(streams) {
980
- const stats = await _chunkO6QIJQRNcjs.store.call(void 0, ).query_stats(streams, {
980
+ const stats = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_stats(streams, {
981
981
  exclude: [_chunk7AHW7FCNcjs.SNAP_EVENT]
982
982
  });
983
- const domain_heads = await _chunkO6QIJQRNcjs.store.call(void 0, ).query_stats(streams, {
983
+ const domain_heads = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_stats(streams, {
984
984
  exclude: [_chunk7AHW7FCNcjs.SNAP_EVENT, _chunk7AHW7FCNcjs.TOMBSTONE_EVENT]
985
985
  });
986
- const true_heads = await _chunkO6QIJQRNcjs.store.call(void 0, ).query_stats(streams, {});
986
+ const true_heads = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_stats(streams, {});
987
987
  const out = /* @__PURE__ */ new Map();
988
988
  for (const [stream, { head }] of domain_heads) {
989
989
  const marker_head = _optionalChain([stats, 'access', _45 => _45.get, 'call', _46 => _46(stream), 'optionalAccess', _47 => _47.head]);
@@ -1011,7 +1011,7 @@ async function partition_by_safety(stream_info, reactive, skipped, page_size, ca
1011
1011
  const matches = source_matcher();
1012
1012
  const targets = [...stream_info.keys()];
1013
1013
  await walk_streams(
1014
- _chunkO6QIJQRNcjs.store.call(void 0, ),
1014
+ _chunk6J2QWD4Qcjs.store.call(void 0, ),
1015
1015
  (position) => {
1016
1016
  const has_work = position.correlated_at !== void 0 && position.at < position.correlated_at;
1017
1017
  if (!has_work) return;
@@ -1077,7 +1077,7 @@ async function run_archive_callbacks(guarded, target_map) {
1077
1077
  }
1078
1078
  }
1079
1079
  async function heads_still_guarded(guarded, guard_events, skipped) {
1080
- const heads = await _chunkO6QIJQRNcjs.store.call(void 0, ).query_stats(guarded, {});
1080
+ const heads = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_stats(guarded, {});
1081
1081
  return guarded.filter((stream) => {
1082
1082
  if (_optionalChain([heads, 'access', _55 => _55.get, 'call', _56 => _56(stream), 'optionalAccess', _57 => _57.head, 'access', _58 => _58.id]) === guard_events.get(stream).id)
1083
1083
  return true;
@@ -1100,13 +1100,13 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
1100
1100
  }
1101
1101
  };
1102
1102
  });
1103
- const truncated = await _chunkO6QIJQRNcjs.store.call(void 0, ).truncate(trunc_targets);
1103
+ const truncated = await _chunk6J2QWD4Qcjs.store.call(void 0, ).truncate(trunc_targets);
1104
1104
  await Promise.all(
1105
1105
  guarded.map(async (stream) => {
1106
1106
  const entry = truncated.get(stream);
1107
1107
  const state2 = seed_states.get(stream);
1108
1108
  if (state2 && entry) {
1109
- await _chunkO6QIJQRNcjs.cache.call(void 0, ).set(stream, {
1109
+ await _chunk6J2QWD4Qcjs.cache.call(void 0, ).set(stream, {
1110
1110
  stream,
1111
1111
  state: state2,
1112
1112
  version: entry.committed.version,
@@ -1115,7 +1115,7 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
1115
1115
  snaps: 1
1116
1116
  });
1117
1117
  } else {
1118
- await _chunkO6QIJQRNcjs.cache.call(void 0, ).invalidate(stream);
1118
+ await _chunk6J2QWD4Qcjs.cache.call(void 0, ).invalidate(stream);
1119
1119
  }
1120
1120
  })
1121
1121
  );
@@ -1129,7 +1129,7 @@ var _crypto = require('crypto');
1129
1129
  function report_once(seen, key, message) {
1130
1130
  if (seen.has(key)) return;
1131
1131
  seen.add(key);
1132
- _chunkO6QIJQRNcjs.log.call(void 0, ).error(new Error(message));
1132
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).error(new Error(message));
1133
1133
  }
1134
1134
 
1135
1135
  // src/internal/correlate-cycle.ts
@@ -1162,21 +1162,27 @@ var CorrelateCycle = (_class3 = class {
1162
1162
 
1163
1163
  /** Local expiry of the held lease (0 = none); stale only costs a duplicate scan. */
1164
1164
  __init6() {this._lease_until = 0}
1165
- /** Raised by a commit or notification, lowered by a short page. Starts armed. */
1166
- __init7() {this._armed = true}
1165
+ /**
1166
+ * Armed while `_raised` (bumped by a commit or notification) is ahead of
1167
+ * `_lowered` (the raise count the last short page saw). Starts armed.
1168
+ */
1169
+ __init7() {this._raised = 1}
1170
+ __init8() {this._lowered = 0}
1171
+ /** Counts releases, so a lease reply that lands after one is dropped. */
1172
+ __init9() {this._releases = 0}
1167
1173
 
1168
1174
  // Bounded by `maxSubscribedStreams`; static records live apart so eviction
1169
1175
  // never drops their +Infinity floor.
1170
1176
 
1171
- __init8() {this._static_subscriptions = /* @__PURE__ */ new Map()}
1172
- __init9() {this._patterns = new (0, _chunkO6QIJQRNcjs.LruMap)(PATTERN_CACHE_SIZE)}
1177
+ __init10() {this._static_subscriptions = /* @__PURE__ */ new Map()}
1178
+ __init11() {this._patterns = new (0, _chunk6J2QWD4Qcjs.LruMap)(PATTERN_CACHE_SIZE)}
1173
1179
 
1174
1180
 
1175
1181
 
1176
1182
 
1177
1183
 
1178
1184
  /** Report-once keys; per instance because `internal/` holds no module state. */
1179
- __init10() {this._reported = /* @__PURE__ */ new Set()}
1185
+ __init12() {this._reported = /* @__PURE__ */ new Set()}
1180
1186
  constructor({
1181
1187
  registry,
1182
1188
  static_targets,
@@ -1185,9 +1191,9 @@ var CorrelateCycle = (_class3 = class {
1185
1191
  declared_lanes,
1186
1192
  shard,
1187
1193
  on_init
1188
- }) {;_class3.prototype.__init3.call(this);_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);
1194
+ }) {;_class3.prototype.__init3.call(this);_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);_class3.prototype.__init11.call(this);_class3.prototype.__init12.call(this);
1189
1195
  this._key = shard ? `${registry_key(registry.events)}:${[...shard].sort().join(",")}` : registry_key(registry.events);
1190
- this._dynamic_subscriptions = new (0, _chunkO6QIJQRNcjs.LruMap)(max_subscribed_streams);
1196
+ this._dynamic_subscriptions = new (0, _chunk6J2QWD4Qcjs.LruMap)(max_subscribed_streams);
1191
1197
  this._registry = registry;
1192
1198
  this._declared_lanes = declared_lanes;
1193
1199
  this._static_targets = static_targets;
@@ -1199,7 +1205,7 @@ var CorrelateCycle = (_class3 = class {
1199
1205
  }
1200
1206
  /** A commit (local or remote) may have produced uncorrelated events. */
1201
1207
  arm() {
1202
- this._armed = true;
1208
+ this._raised++;
1203
1209
  }
1204
1210
  async init() {
1205
1211
  if (this._initialized) return;
@@ -1233,7 +1239,7 @@ var CorrelateCycle = (_class3 = class {
1233
1239
  this._checkpoint = -1;
1234
1240
  this._dynamic_subscriptions.clear();
1235
1241
  this._static_subscriptions.clear();
1236
- this._armed = true;
1242
+ this._raised++;
1237
1243
  }
1238
1244
  /** Forget dynamic targets whose rows a full close deleted, so they re-subscribe. */
1239
1245
  forget_subscribed(streams) {
@@ -1242,7 +1248,7 @@ var CorrelateCycle = (_class3 = class {
1242
1248
  /** Would the target's own `fetch` (filtered by `source`) return this event? */
1243
1249
  _in_fetch_window(source, stream) {
1244
1250
  if (source === void 0 || source === stream) return true;
1245
- if (_chunkO6QIJQRNcjs.is_literal_source.call(void 0, source)) return false;
1251
+ if (_chunk6J2QWD4Qcjs.is_literal_source.call(void 0, source)) return false;
1246
1252
  let pattern = this._patterns.get(source);
1247
1253
  if (!pattern) {
1248
1254
  pattern = new RegExp(source);
@@ -1253,22 +1259,26 @@ var CorrelateCycle = (_class3 = class {
1253
1259
  /** Scan past the checkpoint, subscribe new targets and raise their work marks. */
1254
1260
  async correlate(query = { after: -1, limit: 10 }, lease = false) {
1255
1261
  await this.init();
1256
- if (!this._armed)
1262
+ if (this._raised === this._lowered)
1257
1263
  return {
1258
1264
  subscribed: 0,
1259
1265
  last_id: this._checkpoint,
1260
1266
  marked: 0,
1261
1267
  scanned: false
1262
1268
  };
1269
+ const raised = this._raised;
1263
1270
  const now = Date.now();
1264
1271
  if (lease && now >= this._lease_until - CORRELATION_LEASE_MS / 2) {
1272
+ const releases = this._releases;
1265
1273
  const { correlating } = await this._cd.subscribe([], void 0, {
1266
1274
  key: this._key,
1267
1275
  by: this._by,
1268
1276
  millis: CORRELATION_LEASE_MS
1269
1277
  });
1270
- this._lease_until = correlating ? now + CORRELATION_LEASE_MS : 0;
1271
- if (correlating === false)
1278
+ const released = this._releases !== releases;
1279
+ if (!released)
1280
+ this._lease_until = correlating ? now + CORRELATION_LEASE_MS : 0;
1281
+ if (correlating === false || released)
1272
1282
  return {
1273
1283
  subscribed: 0,
1274
1284
  last_id: this._checkpoint,
@@ -1280,7 +1290,7 @@ var CorrelateCycle = (_class3 = class {
1280
1290
  const correlated = /* @__PURE__ */ new Map();
1281
1291
  let last_id = after;
1282
1292
  let stopped = false;
1283
- const found = await _chunkO6QIJQRNcjs.store.call(void 0, ).query(
1293
+ const found = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query(
1284
1294
  (event) => {
1285
1295
  if (stopped) return;
1286
1296
  const register = this._registry.events[event.name];
@@ -1389,7 +1399,7 @@ var CorrelateCycle = (_class3 = class {
1389
1399
  return { subscribed, last_id, marked, scanned: true };
1390
1400
  }
1391
1401
  this._checkpoint = last_id;
1392
- this._armed = stopped || found === query.limit;
1402
+ if (!stopped && found !== query.limit) this._lowered = raised;
1393
1403
  return { subscribed: 0, last_id, marked: 0, scanned: true };
1394
1404
  }
1395
1405
  /**
@@ -1402,7 +1412,7 @@ var CorrelateCycle = (_class3 = class {
1402
1412
  await Promise.all(
1403
1413
  missed.map(async ([stream, entry]) => {
1404
1414
  let row;
1405
- await _chunkO6QIJQRNcjs.store.call(void 0, ).query_streams(
1415
+ await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_streams(
1406
1416
  (position) => {
1407
1417
  row = position;
1408
1418
  },
@@ -1435,13 +1445,14 @@ var CorrelateCycle = (_class3 = class {
1435
1445
  async release_correlation() {
1436
1446
  try {
1437
1447
  this._lease_until = 0;
1448
+ this._releases++;
1438
1449
  await this._cd.subscribe([], void 0, {
1439
1450
  key: this._key,
1440
1451
  by: this._by,
1441
1452
  millis: 0
1442
1453
  });
1443
1454
  } catch (error) {
1444
- _chunkO6QIJQRNcjs.log.call(void 0, ).warn(
1455
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).warn(
1445
1456
  `Could not hand back the correlation lease during shutdown; it expires on its own within ${CORRELATION_LEASE_MS}ms and correlation resumes normally after that. On a single-writer store this usually means another connection holds the database. Cause: ${String(error)}`
1446
1457
  );
1447
1458
  }
@@ -1503,14 +1514,14 @@ function compute_backoff_delay(retry, opts) {
1503
1514
  // src/internal/defer-timer.ts
1504
1515
  var MAX_TIMER_DELAY_MS = 2147483647;
1505
1516
  var DeferTimer = (_class4 = class {
1506
- __init11() {this._due = /* @__PURE__ */ new Map()}
1517
+ __init13() {this._due = /* @__PURE__ */ new Map()}
1507
1518
 
1508
1519
 
1509
1520
  /**
1510
1521
  * @param on_wake - invoked once each time the earliest due-time elapses.
1511
1522
  * The consumer re-schedules for whatever is still parked.
1512
1523
  */
1513
- constructor(on_wake) {;_class4.prototype.__init11.call(this);
1524
+ constructor(on_wake) {;_class4.prototype.__init13.call(this);
1514
1525
  this._on_wake = on_wake;
1515
1526
  }
1516
1527
  /** Number of currently parked streams. */
@@ -1594,14 +1605,14 @@ function compute_lag_lead_ratio(handled, lagging, leading) {
1594
1605
  }
1595
1606
 
1596
1607
  // src/internal/drain-ops.ts
1597
- var claim = (lagging, leading, by, millis, lane) => _chunkO6QIJQRNcjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
1608
+ var claim = (lagging, leading, by, millis, lane) => _chunk6J2QWD4Qcjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
1598
1609
  async function fetch(leased, eventLimit) {
1599
1610
  return Promise.all(
1600
1611
  leased.map(async ({ stream, source, at, lagging }) => {
1601
1612
  const events = [];
1602
- const stream_exact = source !== void 0 && _chunkO6QIJQRNcjs.is_literal_source.call(void 0, source) ? true : void 0;
1613
+ const stream_exact = source !== void 0 && _chunk6J2QWD4Qcjs.is_literal_source.call(void 0, source) ? true : void 0;
1603
1614
  try {
1604
- await _chunkO6QIJQRNcjs.store.call(void 0, ).query((e) => events.push(e), {
1615
+ await _chunk6J2QWD4Qcjs.store.call(void 0, ).query((e) => events.push(e), {
1605
1616
  stream: source,
1606
1617
  stream_exact,
1607
1618
  after: at,
@@ -1621,30 +1632,30 @@ async function fetch(leased, eventLimit) {
1621
1632
  })
1622
1633
  );
1623
1634
  }
1624
- var ack = (leases) => _chunkO6QIJQRNcjs.store.call(void 0, ).ack(leases);
1625
- var block = (leases) => _chunkO6QIJQRNcjs.store.call(void 0, ).block(leases);
1626
- var subscribe = (streams, correlated_at, correlator) => _chunkO6QIJQRNcjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
1635
+ var ack = (leases) => _chunk6J2QWD4Qcjs.store.call(void 0, ).ack(leases);
1636
+ var block = (leases) => _chunk6J2QWD4Qcjs.store.call(void 0, ).block(leases);
1637
+ var subscribe = (streams, correlated_at, correlator) => _chunk6J2QWD4Qcjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
1627
1638
 
1628
1639
  // src/internal/event-sourcing.ts
1629
1640
  var _actpatch = require('@rotorsoft/act-patch');
1630
1641
  var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
1631
1642
  var validating_patch = (me, state2, partial, event) => {
1632
1643
  const next = _actpatch.patch.call(void 0, state2, partial);
1633
- return _chunkO6QIJQRNcjs.validate.call(void 0,
1644
+ return _chunk6J2QWD4Qcjs.validate.call(void 0,
1634
1645
  `${me.name}.${String(event.name)}#${event.id}`,
1635
1646
  next,
1636
1647
  me.state
1637
1648
  );
1638
1649
  };
1639
1650
  var DEFAULT_BATCH = 500;
1640
- var cache_put = (stream, entry) => _chunkO6QIJQRNcjs.cache.call(void 0, ).set(stream, entry).catch(
1641
- (err) => _chunkO6QIJQRNcjs.log.call(void 0, ).warn(
1651
+ var cache_put = (stream, entry) => _chunk6J2QWD4Qcjs.cache.call(void 0, ).set(stream, entry).catch(
1652
+ (err) => _chunk6J2QWD4Qcjs.log.call(void 0, ).warn(
1642
1653
  err,
1643
1654
  "cache set skipped; the next load re-folds from the store"
1644
1655
  )
1645
1656
  );
1646
- var cache_drop = (stream) => _chunkO6QIJQRNcjs.cache.call(void 0, ).invalidate(stream).catch(
1647
- (err) => _chunkO6QIJQRNcjs.log.call(void 0, ).warn(
1657
+ var cache_drop = (stream) => _chunk6J2QWD4Qcjs.cache.call(void 0, ).invalidate(stream).catch(
1658
+ (err) => _chunk6J2QWD4Qcjs.log.call(void 0, ).warn(
1648
1659
  err,
1649
1660
  "cache invalidate skipped; a stale checkpoint re-folds from its event_id"
1650
1661
  )
@@ -1652,7 +1663,7 @@ var cache_drop = (stream) => _chunkO6QIJQRNcjs.cache.call(void 0, ).invalidate(s
1652
1663
  async function snap(snapshot) {
1653
1664
  const { id, stream, name, meta, version } = snapshot.event;
1654
1665
  try {
1655
- const [committed] = await _chunkO6QIJQRNcjs.store.call(void 0, ).commit(
1666
+ const [committed] = await _chunk6J2QWD4Qcjs.store.call(void 0, ).commit(
1656
1667
  stream,
1657
1668
  [{ name: _chunk7AHW7FCNcjs.SNAP_EVENT, data: snapshot.state }],
1658
1669
  {
@@ -1665,14 +1676,14 @@ async function snap(snapshot) {
1665
1676
  return committed;
1666
1677
  } catch (error) {
1667
1678
  const reason = error instanceof Error ? error.message : String(error);
1668
- _chunkO6QIJQRNcjs.log.call(void 0, ).warn(
1679
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).warn(
1669
1680
  `Snapshot write failed on stream "${stream}": ${reason} \u2014 cold starts will replay full history until snapshots succeed.`
1670
1681
  );
1671
1682
  }
1672
1683
  }
1673
1684
  async function tombstone(stream, expectedVersion, correlation) {
1674
1685
  try {
1675
- const [committed] = await _chunkO6QIJQRNcjs.store.call(void 0, ).commit(
1686
+ const [committed] = await _chunk6J2QWD4Qcjs.store.call(void 0, ).commit(
1676
1687
  stream,
1677
1688
  [{ name: _chunk7AHW7FCNcjs.TOMBSTONE_EVENT, data: {} }],
1678
1689
  { correlation, causation: {} },
@@ -1805,14 +1816,14 @@ async function scan(source, opts = {}, callback) {
1805
1816
  async function load(me, target, callback, patch_fn = bare_patch) {
1806
1817
  const { stream, actor, asOf } = target;
1807
1818
  const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
1808
- const cached = time_travel ? void 0 : await _chunkO6QIJQRNcjs.cache.call(void 0, ).get(stream);
1819
+ const cached = time_travel ? void 0 : await _chunk6J2QWD4Qcjs.cache.call(void 0, ).get(stream);
1809
1820
  const cache_hit = !!cached;
1810
1821
  let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _72 => _72.state]), () => ( (me.init ? me.init() : {})));
1811
1822
  let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _73 => _73.patches]), () => ( 0));
1812
1823
  let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _74 => _74.snaps]), () => ( 0));
1813
1824
  let replayed = 0;
1814
1825
  let event;
1815
- await _chunkO6QIJQRNcjs.store.call(void 0, ).query(
1826
+ await _chunk6J2QWD4Qcjs.store.call(void 0, ).query(
1816
1827
  (raw) => {
1817
1828
  event = me.view(raw, actor);
1818
1829
  if (event.name === _chunk7AHW7FCNcjs.SNAP_EVENT) {
@@ -1825,7 +1836,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1825
1836
  patches++;
1826
1837
  replayed++;
1827
1838
  } else if (event.name !== _chunk7AHW7FCNcjs.TOMBSTONE_EVENT) {
1828
- _chunkO6QIJQRNcjs.log.call(void 0, ).warn(
1839
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).warn(
1829
1840
  `Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
1830
1841
  );
1831
1842
  }
@@ -1877,7 +1888,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1877
1888
  if (!stream) throw new Error("Missing target stream");
1878
1889
  const reactingTo = _optionalChain([options, 'optionalAccess', _81 => _81.reactingTo]);
1879
1890
  const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _82 => _82.correlator]), () => ( default_correlator));
1880
- const validated = _chunkO6QIJQRNcjs.validate.call(void 0, action2, payload, me.actions[action2]);
1891
+ const validated = _chunk6J2QWD4Qcjs.validate.call(void 0, action2, payload, me.actions[action2]);
1881
1892
  const opts = _optionalChain([me, 'access', _83 => _83.options, 'optionalAccess', _84 => _84[action2]]);
1882
1893
  const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.maxRetries]), () => ( 0));
1883
1894
  for (let attempt = 0; ; attempt++) {
@@ -1912,7 +1923,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1912
1923
  const tuples = Array.isArray(result[0]) ? result : [result];
1913
1924
  const valid = tuples.map(([name, data]) => ({
1914
1925
  name,
1915
- data: _chunkO6QIJQRNcjs.validate.call(void 0, name, data, me.events[name])
1926
+ data: _chunk6J2QWD4Qcjs.validate.call(void 0, name, data, me.events[name])
1916
1927
  }));
1917
1928
  const emitted = valid.map((e) => me.message(e));
1918
1929
  const meta = {
@@ -1937,7 +1948,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1937
1948
  };
1938
1949
  let committed;
1939
1950
  try {
1940
- committed = await _chunkO6QIJQRNcjs.store.call(void 0, ).commit(
1951
+ committed = await _chunk6J2QWD4Qcjs.store.call(void 0, ).commit(
1941
1952
  stream,
1942
1953
  emitted,
1943
1954
  meta,
@@ -1990,14 +2001,14 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1990
2001
  if (attempt >= max_retries) throw error;
1991
2002
  if (_optionalChain([opts, 'optionalAccess', _94 => _94.backoff])) {
1992
2003
  const delay_ms = compute_backoff_delay(attempt, opts.backoff);
1993
- if (delay_ms > 0) await _chunkO6QIJQRNcjs.sleep.call(void 0, delay_ms);
2004
+ if (delay_ms > 0) await _chunk6J2QWD4Qcjs.sleep.call(void 0, delay_ms);
1994
2005
  }
1995
2006
  }
1996
2007
  }
1997
2008
  }
1998
2009
 
1999
2010
  // src/internal/tracing.ts
2000
- var PRETTY = _chunkO6QIJQRNcjs.config.call(void 0, ).env !== "production";
2011
+ var PRETTY = _chunk6J2QWD4Qcjs.config.call(void 0, ).env !== "production";
2001
2012
  var C_BLUE = "\x1B[38;5;39m";
2002
2013
  var C_ORANGE = "\x1B[38;5;208m";
2003
2014
  var C_GREEN = "\x1B[38;5;42m";
@@ -2183,7 +2194,7 @@ function budget_exhausted(lease, options, store_failing) {
2183
2194
  if (store_failing || !_optionalChain([options, 'optionalAccess', _104 => _104.blockOnError]) || lease.retry <= options.maxRetries)
2184
2195
  return void 0;
2185
2196
  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.`;
2186
- _chunkO6QIJQRNcjs.log.call(void 0, ).error(error);
2197
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).error(error);
2187
2198
  return { lease, handled: 0, acked_at: lease.at, error, block: true };
2188
2199
  }
2189
2200
  function fetch_failure_policy(registry) {
@@ -2205,7 +2216,7 @@ function finalize(lease, handled, at, error, options, logger, failed_at) {
2205
2216
  logger.error(
2206
2217
  non_retryable ? `Blocking ${lease.stream} on non-retryable error.` : `Blocking ${lease.stream} after ${lease.retry} retries.`
2207
2218
  );
2208
- const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunkO6QIJQRNcjs.DEFAULT_BACKOFF)));
2219
+ const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunk6J2QWD4Qcjs.DEFAULT_BACKOFF)));
2209
2220
  return {
2210
2221
  lease,
2211
2222
  handled,
@@ -2334,7 +2345,7 @@ async function run_drain_cycle(deps, cycle) {
2334
2345
  const acked = await ops.ack(submitted);
2335
2346
  const expected = submitted.filter((l) => l.due === void 0).length;
2336
2347
  if (acked.length < expected)
2337
- _chunkO6QIJQRNcjs.log.call(void 0, ).warn(
2348
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).warn(
2338
2349
  `drain: ${expected - acked.length} of ${expected} acks were dropped \u2014 the lease was taken by another worker mid-handler. That work will be redelivered (at-least-once), but persistent drops mean leaseMillis is too short for this handler.`
2339
2350
  );
2340
2351
  const closeable = handled.filter((h) => h.close !== void 0).map((h) => h.close);
@@ -2348,8 +2359,14 @@ var EMPTY_DRAIN = {
2348
2359
  };
2349
2360
  var RETRY = "";
2350
2361
  var DrainController = (_class5 = class {
2351
- __init12() {this._armed = false}
2352
- __init13() {this._ratio = 0.5}
2362
+ /**
2363
+ * Armed while `_raised` is ahead of `_lowered` (the raise count the last
2364
+ * empty claim saw), so a claim never lowers over a raise that landed
2365
+ * during it.
2366
+ */
2367
+ __init14() {this._raised = 0}
2368
+ __init15() {this._lowered = 0}
2369
+ __init16() {this._ratio = 0.5}
2353
2370
  /**
2354
2371
  * Local wake at the earliest parked (backoff or defer) visit, or at the
2355
2372
  * lease expiry after a failed pass (the {@link RETRY} key); the schedule
@@ -2357,24 +2374,24 @@ var DrainController = (_class5 = class {
2357
2374
  * drains until a pass leases nothing or the controller stops, and an entry
2358
2375
  * stays until handled or until a later pass claims nothing.
2359
2376
  */
2360
- __init14() {this._defer = new DeferTimer(() => {
2361
- this._armed = true;
2377
+ __init17() {this._defer = new DeferTimer(() => {
2378
+ this.arm();
2362
2379
  void this._deps.run_scoped(async () => {
2363
2380
  while ((await this.drain()).leased.length > 0) ;
2364
2381
  });
2365
2382
  })}
2366
2383
 
2367
- __init15() {this._misrouted = /* @__PURE__ */ new Set()}
2368
- __init16() {this._stopped = false}
2384
+ __init18() {this._misrouted = /* @__PURE__ */ new Set()}
2385
+ __init19() {this._stopped = false}
2369
2386
  /** Never rejects; graceful shutdown waits on it. */
2370
2387
 
2371
2388
 
2372
2389
 
2373
- constructor(deps) {;_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);_class5.prototype.__init14.call(this);_class5.prototype.__init15.call(this);_class5.prototype.__init16.call(this);
2390
+ constructor(deps) {;_class5.prototype.__init14.call(this);_class5.prototype.__init15.call(this);_class5.prototype.__init16.call(this);_class5.prototype.__init17.call(this);_class5.prototype.__init18.call(this);_class5.prototype.__init19.call(this);
2374
2391
  this._deps = deps;
2375
2392
  }
2376
2393
  arm() {
2377
- this._armed = true;
2394
+ this._raised++;
2378
2395
  }
2379
2396
  /** Cold start: re-seed a persisted `deferred_at` into the local wake. */
2380
2397
  seed_defer(stream, at) {
@@ -2382,7 +2399,7 @@ var DrainController = (_class5 = class {
2382
2399
  this._defer.schedule();
2383
2400
  }
2384
2401
  get armed() {
2385
- return this._armed;
2402
+ return this._raised !== this._lowered;
2386
2403
  }
2387
2404
  get inflight() {
2388
2405
  return this._inflight;
@@ -2399,7 +2416,7 @@ var DrainController = (_class5 = class {
2399
2416
  if (this._worker || this._stopped) return;
2400
2417
  const run = this._deps.run_scoped;
2401
2418
  const tick = async () => {
2402
- if (this._armed) await run(() => this.drain());
2419
+ if (this.armed) await run(() => this.drain());
2403
2420
  if (this._stopped) return;
2404
2421
  this._worker = setTimeout(tick, cycleMs);
2405
2422
  this._worker.unref();
@@ -2416,12 +2433,12 @@ var DrainController = (_class5 = class {
2416
2433
  this._defer.stop();
2417
2434
  }
2418
2435
  async drain(options = {}) {
2419
- if (!this._armed || this._stopped || this._inflight)
2436
+ if (!this.armed || this._stopped || this._inflight)
2420
2437
  return EMPTY_DRAIN;
2421
2438
  const d = _nullishCoalesce(this._deps.defaults, () => ( {}));
2422
- const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunkO6QIJQRNcjs.DEFAULT_STREAM_LIMIT));
2423
- const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkO6QIJQRNcjs.DEFAULT_EVENT_LIMIT));
2424
- const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkO6QIJQRNcjs.DEFAULT_LEASE_MILLIS));
2439
+ const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunk6J2QWD4Qcjs.DEFAULT_STREAM_LIMIT));
2440
+ const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunk6J2QWD4Qcjs.DEFAULT_EVENT_LIMIT));
2441
+ const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunk6J2QWD4Qcjs.DEFAULT_LEASE_MILLIS));
2425
2442
  if (this._deps.breaker.state(Date.now()) === "open")
2426
2443
  return EMPTY_DRAIN;
2427
2444
  try {
@@ -2431,6 +2448,7 @@ var DrainController = (_class5 = class {
2431
2448
  const lagging = Math.ceil(streamLimit * this._ratio);
2432
2449
  const leading = streamLimit - lagging;
2433
2450
  const started = Date.now();
2451
+ const raised = this._raised;
2434
2452
  const cycle = await run_drain_cycle(this._deps, {
2435
2453
  lagging,
2436
2454
  leading,
@@ -2442,7 +2460,7 @@ var DrainController = (_class5 = class {
2442
2460
  if (!cycle) {
2443
2461
  this._defer.prune(started);
2444
2462
  this._deps.breaker.passed();
2445
- this._armed = false;
2463
+ this._lowered = raised;
2446
2464
  return EMPTY_DRAIN;
2447
2465
  }
2448
2466
  const { leased, fetched, handled, acked, blocked, closeable } = cycle;
@@ -2787,24 +2805,24 @@ function build_handle_batch(logger) {
2787
2805
 
2788
2806
  // src/internal/settle.ts
2789
2807
  var SettleLoop = (_class6 = class {
2790
- __init17() {this._timer = void 0}
2808
+ __init20() {this._timer = void 0}
2791
2809
  /**
2792
2810
  * The cycle in flight, set while one runs. Shutdown waits for it
2793
2811
  * (`stop()` cancels scheduling only). Never rejects.
2794
2812
  */
2795
2813
 
2796
2814
  /** A wake-up arrived while a cycle ran: run one more pass after it. */
2797
- __init18() {this._pending = false}
2815
+ __init21() {this._pending = false}
2798
2816
  /** The last caller's options, used by the next pass. */
2799
- __init19() {this._next = void 0}
2817
+ __init22() {this._next = void 0}
2800
2818
  /** When the scheduled pass fires (epoch ms). */
2801
- __init20() {this._due = 0}
2819
+ __init23() {this._due = 0}
2802
2820
  /** Set at shutdown: nothing schedules again. */
2803
- __init21() {this._stopped = false}
2821
+ __init24() {this._stopped = false}
2804
2822
 
2805
2823
  /** Debounce window applied when the caller doesn't override via `SettleOptions.debounceMs`. */
2806
2824
 
2807
- constructor(deps, default_debounce_ms) {;_class6.prototype.__init17.call(this);_class6.prototype.__init18.call(this);_class6.prototype.__init19.call(this);_class6.prototype.__init20.call(this);_class6.prototype.__init21.call(this);
2825
+ constructor(deps, default_debounce_ms) {;_class6.prototype.__init20.call(this);_class6.prototype.__init21.call(this);_class6.prototype.__init22.call(this);_class6.prototype.__init23.call(this);_class6.prototype.__init24.call(this);
2808
2826
  this._deps = deps;
2809
2827
  this._default_debounce_ms = default_debounce_ms;
2810
2828
  }
@@ -2908,7 +2926,7 @@ function validate_only_lanes(options, lanes) {
2908
2926
  );
2909
2927
  }
2910
2928
  var Act = (_class7 = class {
2911
- __init22() {this._emitter = new (0, _events2.default)()}
2929
+ __init25() {this._emitter = new (0, _events2.default)()}
2912
2930
 
2913
2931
 
2914
2932
 
@@ -2984,14 +3002,14 @@ var Act = (_class7 = class {
2984
3002
  /** Lanes to arm per event; `"all"` when a dynamic resolver hides the lane. */
2985
3003
 
2986
3004
 
2987
- __init23() {this._logger = _chunkO6QIJQRNcjs.log.call(void 0, )}
3005
+ __init26() {this._logger = _chunk6J2QWD4Qcjs.log.call(void 0, )}
2988
3006
  /** This Act's ports: its own bag, or the singleton adapters. */
2989
3007
 
2990
3008
  /** Runs a body so internal `store()`/`cache()` calls resolve to `_ports`. */
2991
3009
 
2992
3010
 
2993
3011
 
2994
- __init24() {this._close_lock = new CloseLock()}
3012
+ __init27() {this._close_lock = new CloseLock()}
2995
3013
  /** Every lane a controller can exist for: `"default"` plus each declared one. */
2996
3014
 
2997
3015
  /** Drain lanes declared via `.withLane(...)`. Implicit default not included. */
@@ -2999,16 +3017,16 @@ var Act = (_class7 = class {
2999
3017
  return this._lanes;
3000
3018
  }
3001
3019
  /** Use the {@link act} builder rather than constructing directly. */
3002
- constructor(registry, states = /* @__PURE__ */ new Map(), batch_handlers = /* @__PURE__ */ new Map(), options = {}, lanes = [], patch_fn = bare_patch) {;_class7.prototype.__init22.call(this);_class7.prototype.__init23.call(this);_class7.prototype.__init24.call(this);
3020
+ constructor(registry, states = /* @__PURE__ */ new Map(), batch_handlers = /* @__PURE__ */ new Map(), options = {}, lanes = [], patch_fn = bare_patch) {;_class7.prototype.__init25.call(this);_class7.prototype.__init26.call(this);_class7.prototype.__init27.call(this);
3003
3021
  this.registry = registry;
3004
3022
  this._states = states;
3005
3023
  this._batch_handlers = batch_handlers;
3006
3024
  this._lanes = lanes;
3007
3025
  this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
3008
3026
  validate_only_lanes(options, lanes);
3009
- this._ports = _nullishCoalesce(options.scoped, () => ( _chunkO6QIJQRNcjs.default_scope.call(void 0, )));
3027
+ this._ports = _nullishCoalesce(options.scoped, () => ( _chunk6J2QWD4Qcjs.default_scope.call(void 0, )));
3010
3028
  const ports = this._ports;
3011
- this._scoped = _chunkO6QIJQRNcjs.make_run_scoped.call(void 0, {
3029
+ this._scoped = _chunk6J2QWD4Qcjs.make_run_scoped.call(void 0, {
3012
3030
  // Getters, not a spread: the singletons resolve lazily, so a later
3013
3031
  // `store(...)` / `cache(...)` still takes effect.
3014
3032
  get store() {
@@ -3018,14 +3036,14 @@ var Act = (_class7 = class {
3018
3036
  return ports.cache;
3019
3037
  },
3020
3038
  // Parsed per build, so a bad window throws on every build.
3021
- autoclose_window: _chunkO6QIJQRNcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
3039
+ autoclose_window: _chunk6J2QWD4Qcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
3022
3040
  });
3023
3041
  this._correlator = _nullishCoalesce(options.correlator, () => ( default_correlator));
3024
3042
  this._es = build_es(this._logger, this._correlator, patch_fn);
3025
3043
  this._cd = build_drain(this._logger);
3026
3044
  const handle = build_handle({
3027
3045
  logger: this._logger,
3028
- reaction_scope: _chunkO6QIJQRNcjs.make_reaction_scope.call(void 0, {
3046
+ reaction_scope: _chunk6J2QWD4Qcjs.make_reaction_scope.call(void 0, {
3029
3047
  do: this.do.bind(this),
3030
3048
  load: this.load.bind(this),
3031
3049
  query: this.query.bind(this),
@@ -3055,12 +3073,12 @@ var Act = (_class7 = class {
3055
3073
  this._ports.store,
3056
3074
  options.listen !== false
3057
3075
  );
3058
- _chunkO6QIJQRNcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
3076
+ _chunk6J2QWD4Qcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
3059
3077
  }
3060
3078
  /** Shared by drain, settle and autoclose; bad knobs throw at build. */
3061
3079
  _build_breaker(options) {
3062
3080
  return new CircuitBreaker(
3063
- _chunkO6QIJQRNcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
3081
+ _chunk6J2QWD4Qcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
3064
3082
  {
3065
3083
  on_error: (error, circuit) => this._emit_error(error, circuit),
3066
3084
  // When the cooldown elapses, settle once: its scan or claim is the
@@ -3129,7 +3147,7 @@ var Act = (_class7 = class {
3129
3147
  /** Audit deps, built after the controllers so the lane set is final. */
3130
3148
  _build_audit_deps() {
3131
3149
  return {
3132
- store: _chunkO6QIJQRNcjs.store,
3150
+ store: _chunk6J2QWD4Qcjs.store,
3133
3151
  event_to_state: this._event_to_state,
3134
3152
  // Declared lanes, not this process's controllers: a lane another
3135
3153
  // worker drains is not `unknown-lane`.
@@ -3158,7 +3176,7 @@ var Act = (_class7 = class {
3158
3176
  /** Cold start: an idle deferred stream still fires on time after a restart. */
3159
3177
  async _seed_persisted_defers() {
3160
3178
  const now = Date.now();
3161
- await walk_streams(_chunkO6QIJQRNcjs.store.call(void 0, ), (pos) => {
3179
+ await walk_streams(_chunk6J2QWD4Qcjs.store.call(void 0, ), (pos) => {
3162
3180
  if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
3163
3181
  const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
3164
3182
  _optionalChain([controller, 'optionalAccess', _126 => _126.seed_defer, 'call', _127 => _127(pos.stream, pos.deferred_at)]);
@@ -3198,7 +3216,7 @@ var Act = (_class7 = class {
3198
3216
  */
3199
3217
  shutdown(options) {
3200
3218
  if (!this._shutdown_promise) {
3201
- _chunkO6QIJQRNcjs.resolveShutdownConfig.call(void 0, options);
3219
+ _chunk6J2QWD4Qcjs.resolveShutdownConfig.call(void 0, options);
3202
3220
  this._shutdown_promise = (async () => {
3203
3221
  this.stop_correlations();
3204
3222
  this._settle.stop(true);
@@ -3218,10 +3236,10 @@ var Act = (_class7 = class {
3218
3236
  * default for none or 0, and for a running settle), capped.
3219
3237
  */
3220
3238
  _derive_grace_ms(running, settling) {
3221
- let max = settling ? _chunkO6QIJQRNcjs.DEFAULT_LEASE_MILLIS : 0;
3239
+ let max = settling ? _chunk6J2QWD4Qcjs.DEFAULT_LEASE_MILLIS : 0;
3222
3240
  for (const c of running)
3223
- max = Math.max(max, c.lease_millis || _chunkO6QIJQRNcjs.DEFAULT_LEASE_MILLIS);
3224
- return Math.min(max, _chunkO6QIJQRNcjs.MAX_SHUTDOWN_GRACE_MS);
3241
+ max = Math.max(max, c.lease_millis || _chunk6J2QWD4Qcjs.DEFAULT_LEASE_MILLIS);
3242
+ return Math.min(max, _chunk6J2QWD4Qcjs.MAX_SHUTDOWN_GRACE_MS);
3225
3243
  }
3226
3244
  async _await_inflight(grace_ms) {
3227
3245
  const running = [...this._drain_controllers.values()].filter(
@@ -3301,7 +3319,7 @@ var Act = (_class7 = class {
3301
3319
  * @see {@link ValidationError}, {@link InvariantError}, {@link ConcurrencyError}
3302
3320
  */
3303
3321
  async do(action2, target, payload, options) {
3304
- const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _129 => _129.reactingTo]), () => ( _chunkO6QIJQRNcjs.current_reacting.call(void 0, )));
3322
+ const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _129 => _129.reactingTo]), () => ( _chunk6J2QWD4Qcjs.current_reacting.call(void 0, )));
3305
3323
  const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _130 => _130.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3306
3324
  return this._scoped(async () => {
3307
3325
  const snapshots = await this._es.action(
@@ -3362,7 +3380,7 @@ var Act = (_class7 = class {
3362
3380
  return this._scoped(async () => {
3363
3381
  let first;
3364
3382
  let last;
3365
- const count = await _chunkO6QIJQRNcjs.store.call(void 0, ).query((e) => {
3383
+ const count = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query((e) => {
3366
3384
  const gated = this.registry.query_gate(e.name)(e);
3367
3385
  if (!first) first = gated;
3368
3386
  last = gated;
@@ -3392,7 +3410,7 @@ var Act = (_class7 = class {
3392
3410
  async query_array(query) {
3393
3411
  return this._scoped(async () => {
3394
3412
  const events = [];
3395
- await _chunkO6QIJQRNcjs.store.call(void 0, ).query((e) => {
3413
+ await _chunk6J2QWD4Qcjs.store.call(void 0, ).query((e) => {
3396
3414
  events.push(this.registry.query_gate(e.name)(e));
3397
3415
  }, query);
3398
3416
  return events;
@@ -3412,14 +3430,14 @@ var Act = (_class7 = class {
3412
3430
  */
3413
3431
  async forget(stream) {
3414
3432
  return this._scoped(async () => {
3415
- const s = _chunkO6QIJQRNcjs.store.call(void 0, );
3433
+ const s = _chunk6J2QWD4Qcjs.store.call(void 0, );
3416
3434
  if (!s.forget_pii) {
3417
3435
  throw new Error(
3418
3436
  `Store does not implement forget_pii \u2014 adapter cannot comply with sensitive-data erasure. Use an adapter that declares pii_isolation: true (e.g. @rotorsoft/act on the in-memory store).`
3419
3437
  );
3420
3438
  }
3421
3439
  const eventCount = await s.forget_pii(stream);
3422
- await _chunkO6QIJQRNcjs.cache.call(void 0, ).invalidate(stream);
3440
+ await _chunk6J2QWD4Qcjs.cache.call(void 0, ).invalidate(stream);
3423
3441
  if (eventCount > 0) {
3424
3442
  this.emit("forgotten", { stream, at: /* @__PURE__ */ new Date(), eventCount });
3425
3443
  }
@@ -3453,7 +3471,7 @@ var Act = (_class7 = class {
3453
3471
  * @see {@link correlate} for dynamic stream discovery
3454
3472
  */
3455
3473
  async drain(options = {}) {
3456
- _chunkO6QIJQRNcjs.resolveDrainConfig.call(void 0, options);
3474
+ _chunk6J2QWD4Qcjs.resolveDrainConfig.call(void 0, options);
3457
3475
  if (!this._drain)
3458
3476
  return { fetched: [], leased: [], acked: [], blocked: [] };
3459
3477
  return this._scoped(() => this._drain_all(options));
@@ -3636,7 +3654,7 @@ var Act = (_class7 = class {
3636
3654
  */
3637
3655
  async reset(input) {
3638
3656
  return this._scoped(async () => {
3639
- const count = await _chunkO6QIJQRNcjs.store.call(void 0, ).reset(input);
3657
+ const count = await _chunk6J2QWD4Qcjs.store.call(void 0, ).reset(input);
3640
3658
  for (const handler of this._batch_handlers.values())
3641
3659
  _optionalChain([handler, 'access', _137 => _137[FOLD_RESET], 'optionalCall', _138 => _138()]);
3642
3660
  if (count > 0) {
@@ -3672,7 +3690,7 @@ var Act = (_class7 = class {
3672
3690
  */
3673
3691
  async unblock(input) {
3674
3692
  return this._scoped(async () => {
3675
- const count = await _chunkO6QIJQRNcjs.store.call(void 0, ).unblock(input);
3693
+ const count = await _chunk6J2QWD4Qcjs.store.call(void 0, ).unblock(input);
3676
3694
  if (count > 0) {
3677
3695
  this._wake();
3678
3696
  }
@@ -3721,7 +3739,7 @@ var Act = (_class7 = class {
3721
3739
  return { ...partial, duration_ms: Date.now() - started };
3722
3740
  }
3723
3741
  const target = _nullishCoalesce(sink, () => ( (() => {
3724
- const s = _chunkO6QIJQRNcjs.store.call(void 0, );
3742
+ const s = _chunk6J2QWD4Qcjs.store.call(void 0, );
3725
3743
  if (!s.restore) throw new Error("adapter has no restore capability");
3726
3744
  return s;
3727
3745
  })()));
@@ -3766,7 +3784,7 @@ var Act = (_class7 = class {
3766
3784
  async blocked_streams(options) {
3767
3785
  return this._scoped(async () => {
3768
3786
  const positions = [];
3769
- await _chunkO6QIJQRNcjs.store.call(void 0, ).query_streams(
3787
+ await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_streams(
3770
3788
  (p) => {
3771
3789
  positions.push(p);
3772
3790
  },
@@ -3818,7 +3836,7 @@ var Act = (_class7 = class {
3818
3836
  * @see {@link Store.prioritize} for the underlying primitive
3819
3837
  */
3820
3838
  async prioritize(filter, priority) {
3821
- return this._scoped(() => _chunkO6QIJQRNcjs.store.call(void 0, ).prioritize(filter, priority));
3839
+ return this._scoped(() => _chunk6J2QWD4Qcjs.store.call(void 0, ).prioritize(filter, priority));
3822
3840
  }
3823
3841
  /** Shared by `close()` and reaction-requested closes. */
3824
3842
  async _run_close(targets) {
@@ -3900,7 +3918,7 @@ var Act = (_class7 = class {
3900
3918
  * @see {@link correlate} for manual correlation
3901
3919
  */
3902
3920
  settle(options) {
3903
- _chunkO6QIJQRNcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
3921
+ _chunk6J2QWD4Qcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
3904
3922
  this._schedule(options);
3905
3923
  }
3906
3924
  }, _class7);
@@ -4056,13 +4074,13 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
4056
4074
  }),
4057
4075
  // Never block on autoclose: a transient query/store error should retry,
4058
4076
  // not quarantine the synthetic stream.
4059
- options: { blockOnError: false, maxRetries: _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES },
4077
+ options: { blockOnError: false, maxRetries: _chunk6J2QWD4Qcjs.DEFAULT_MAX_RETRIES },
4060
4078
  handler: async (event) => {
4061
4079
  const aggregate = event.stream;
4062
4080
  const window = read_window();
4063
4081
  if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
4064
4082
  throw new (0, _chunk7AHW7FCNcjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
4065
- const stats = await _chunkO6QIJQRNcjs.store.call(void 0, ).query_stats([aggregate], {
4083
+ const stats = await _chunk6J2QWD4Qcjs.store.call(void 0, ).query_stats([aggregate], {
4066
4084
  count: true,
4067
4085
  tail: keep_days !== void 0 ? true : void 0,
4068
4086
  exclude: [_chunk7AHW7FCNcjs.TOMBSTONE_EVENT, _chunk7AHW7FCNcjs.SNAP_EVENT]
@@ -4300,7 +4318,7 @@ var _this_ = ({ stream }) => ({
4300
4318
 
4301
4319
  // src/builders/builder-utils.ts
4302
4320
  function register_lane(config2, lanes) {
4303
- _chunkO6QIJQRNcjs.resolveLaneConfig.call(void 0, config2);
4321
+ _chunk6J2QWD4Qcjs.resolveLaneConfig.call(void 0, config2);
4304
4322
  if (config2.name === _chunk7AHW7FCNcjs.DEFAULT_LANE)
4305
4323
  throw new Error(`Lane "${_chunk7AHW7FCNcjs.DEFAULT_LANE}" is reserved`);
4306
4324
  const existing = lanes.find((l) => l.name === config2.name);
@@ -4344,9 +4362,9 @@ function reaction_on(event, events, builder) {
4344
4362
  // Validate the whole bag at the declaration site so a bad
4345
4363
  // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
4346
4364
  // not a NaN gate on the first retry.
4347
- options: _chunkO6QIJQRNcjs.resolveReactionConfig.call(void 0, {
4348
- blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _153 => _153.blockOnError]), () => ( _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR)),
4349
- maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _154 => _154.maxRetries]), () => ( _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES)),
4365
+ options: _chunk6J2QWD4Qcjs.resolveReactionConfig.call(void 0, {
4366
+ blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _153 => _153.blockOnError]), () => ( _chunk6J2QWD4Qcjs.DEFAULT_BLOCK_ON_ERROR)),
4367
+ maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _154 => _154.maxRetries]), () => ( _chunk6J2QWD4Qcjs.DEFAULT_MAX_RETRIES)),
4350
4368
  backoff: _optionalChain([options, 'optionalAccess', _155 => _155.backoff])
4351
4369
  })
4352
4370
  };
@@ -4648,7 +4666,7 @@ function act() {
4648
4666
  const list = deprecation_summary.map(
4649
4667
  (d) => `"${d.deprecated}" (current: "${d.current}", state: "${d.state_name}")`
4650
4668
  ).join(", ");
4651
- _chunkO6QIJQRNcjs.log.call(void 0, ).info(
4669
+ _chunk6J2QWD4Qcjs.log.call(void 0, ).info(
4652
4670
  `Act registered ${deprecation_summary.length} deprecated event(s): ${list}. These are legacy versions kept for the read path. Consider truncating closed streams via app.close() when feasible to reduce historical event load. See docs/docs/architecture/event-schema-evolution.md.`
4653
4671
  );
4654
4672
  }
@@ -4690,7 +4708,7 @@ function act() {
4690
4708
  return reaction_on(event, registry.events, builder);
4691
4709
  },
4692
4710
  build: (options) => {
4693
- _chunkO6QIJQRNcjs.resolveActConfig.call(void 0, options);
4711
+ _chunk6J2QWD4Qcjs.resolveActConfig.call(void 0, options);
4694
4712
  const patch_fn = _optionalChain([options, 'optionalAccess', _167 => _167.validateFoldedState]) === true ? validating_patch : bare_patch;
4695
4713
  if (!_built) {
4696
4714
  for (const proj of pending_projections) add_projection(proj);
@@ -4742,7 +4760,7 @@ function act() {
4742
4760
  synthesize_autoclose_reactions(
4743
4761
  registry,
4744
4762
  states,
4745
- _chunkO6QIJQRNcjs.current_autoclose_window
4763
+ _chunk6J2QWD4Qcjs.current_autoclose_window
4746
4764
  );
4747
4765
  Object.freeze(registry.actions);
4748
4766
  Object.freeze(registry.events);
@@ -4791,8 +4809,8 @@ function _projection(target) {
4791
4809
  handler,
4792
4810
  resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
4793
4811
  options: {
4794
- blockOnError: _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR,
4795
- maxRetries: _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES
4812
+ blockOnError: _chunk6J2QWD4Qcjs.DEFAULT_BLOCK_ON_ERROR,
4813
+ maxRetries: _chunk6J2QWD4Qcjs.DEFAULT_MAX_RETRIES
4796
4814
  }
4797
4815
  }),
4798
4816
  widened
@@ -4833,7 +4851,7 @@ function _projection(target) {
4833
4851
  throw new Error(
4834
4852
  `Projection "${target}" .of() partials must share one state name \u2014 got "${name}" and "${partial.name}"`
4835
4853
  );
4836
- const config2 = _chunkO6QIJQRNcjs.resolveFoldConfig.call(void 0, options);
4854
+ const config2 = _chunk6J2QWD4Qcjs.resolveFoldConfig.call(void 0, options);
4837
4855
  const fold_events = {};
4838
4856
  for (const partial of partials)
4839
4857
  for (const [event_name, schema] of Object.entries(partial.events)) {
@@ -4851,8 +4869,8 @@ function _projection(target) {
4851
4869
  handler: noop,
4852
4870
  resolver: { target },
4853
4871
  options: {
4854
- blockOnError: _chunkO6QIJQRNcjs.DEFAULT_BLOCK_ON_ERROR,
4855
- maxRetries: _chunkO6QIJQRNcjs.DEFAULT_MAX_RETRIES
4872
+ blockOnError: _chunk6J2QWD4Qcjs.DEFAULT_BLOCK_ON_ERROR,
4873
+ maxRetries: _chunk6J2QWD4Qcjs.DEFAULT_MAX_RETRIES
4856
4874
  }
4857
4875
  }
4858
4876
  ]
@@ -4968,7 +4986,7 @@ function action_builder(state2) {
4968
4986
  throw new Error(`Duplicate action "${action2}"`);
4969
4987
  internal.actions[action2] = schema;
4970
4988
  if (options) {
4971
- _chunkO6QIJQRNcjs.resolveActionConfig.call(void 0, options);
4989
+ _chunk6J2QWD4Qcjs.resolveActionConfig.call(void 0, options);
4972
4990
  internal.options ??= {};
4973
4991
  internal.options[action2] = options;
4974
4992
  }
@@ -5257,5 +5275,5 @@ function write_line(writer, line) {
5257
5275
 
5258
5276
 
5259
5277
 
5260
- exports.Act = Act; exports.ActorSchema = _chunk7AHW7FCNcjs.ActorSchema; exports.CausationEventSchema = _chunk7AHW7FCNcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunk7AHW7FCNcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunk7AHW7FCNcjs.ConcurrencyError; exports.ConsoleLogger = _chunkO6QIJQRNcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunk7AHW7FCNcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunk7AHW7FCNcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunk7AHW7FCNcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunk7AHW7FCNcjs.DeferSignal; exports.Environments = _chunk7AHW7FCNcjs.Environments; exports.Errors = _chunk7AHW7FCNcjs.Errors; exports.EventMetaSchema = _chunk7AHW7FCNcjs.EventMetaSchema; exports.ExitCodes = _chunk7AHW7FCNcjs.ExitCodes; exports.InMemoryCache = _chunkO6QIJQRNcjs.InMemoryCache; exports.InMemoryStore = _chunkO6QIJQRNcjs.InMemoryStore; exports.InvariantError = _chunk7AHW7FCNcjs.InvariantError; exports.LogLevels = _chunk7AHW7FCNcjs.LogLevels; exports.NonRetryableError = _chunk7AHW7FCNcjs.NonRetryableError; exports.PackageSchema = _chunkO6QIJQRNcjs.PackageSchema; exports.QuerySchema = _chunk7AHW7FCNcjs.QuerySchema; exports.REDACTED = _chunk7AHW7FCNcjs.REDACTED; exports.SHREDDED = _chunk7AHW7FCNcjs.SHREDDED; exports.SNAP_EVENT = _chunk7AHW7FCNcjs.SNAP_EVENT; exports.StoreError = _chunk7AHW7FCNcjs.StoreError; exports.StreamClosedError = _chunk7AHW7FCNcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunk7AHW7FCNcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunk7AHW7FCNcjs.TargetSchema; exports.ValidationError = _chunk7AHW7FCNcjs.ValidationError; exports.ZodEmpty = _chunk7AHW7FCNcjs.ZodEmpty; exports.act = act; exports.cache = _chunkO6QIJQRNcjs.cache; exports.config = _chunkO6QIJQRNcjs.config; exports.dateReviver = _chunkO6QIJQRNcjs.dateReviver; exports.default_scope = _chunkO6QIJQRNcjs.default_scope; exports.dispose = _chunkO6QIJQRNcjs.dispose; exports.disposeAndExit = _chunkO6QIJQRNcjs.disposeAndExit; exports.extend = _chunkO6QIJQRNcjs.extend; exports.is_literal_source = _chunkO6QIJQRNcjs.is_literal_source; exports.log = _chunkO6QIJQRNcjs.log; exports.pii_fields = _chunk7AHW7FCNcjs.pii_fields; exports.port = _chunkO6QIJQRNcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkO6QIJQRNcjs.resolveAutocloseConfig2; exports.sensitive = _chunk7AHW7FCNcjs.sensitive; exports.sleep = _chunkO6QIJQRNcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkO6QIJQRNcjs.store; exports.validate = _chunkO6QIJQRNcjs.validate;
5278
+ exports.Act = Act; exports.ActorSchema = _chunk7AHW7FCNcjs.ActorSchema; exports.CausationEventSchema = _chunk7AHW7FCNcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunk7AHW7FCNcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunk7AHW7FCNcjs.ConcurrencyError; exports.ConsoleLogger = _chunk6J2QWD4Qcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunk7AHW7FCNcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunk7AHW7FCNcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunk7AHW7FCNcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunk7AHW7FCNcjs.DeferSignal; exports.Environments = _chunk7AHW7FCNcjs.Environments; exports.Errors = _chunk7AHW7FCNcjs.Errors; exports.EventMetaSchema = _chunk7AHW7FCNcjs.EventMetaSchema; exports.ExitCodes = _chunk7AHW7FCNcjs.ExitCodes; exports.InMemoryCache = _chunk6J2QWD4Qcjs.InMemoryCache; exports.InMemoryStore = _chunk6J2QWD4Qcjs.InMemoryStore; exports.InvariantError = _chunk7AHW7FCNcjs.InvariantError; exports.LogLevels = _chunk7AHW7FCNcjs.LogLevels; exports.NonRetryableError = _chunk7AHW7FCNcjs.NonRetryableError; exports.PackageSchema = _chunk6J2QWD4Qcjs.PackageSchema; exports.QuerySchema = _chunk7AHW7FCNcjs.QuerySchema; exports.REDACTED = _chunk7AHW7FCNcjs.REDACTED; exports.SHREDDED = _chunk7AHW7FCNcjs.SHREDDED; exports.SNAP_EVENT = _chunk7AHW7FCNcjs.SNAP_EVENT; exports.StoreError = _chunk7AHW7FCNcjs.StoreError; exports.StreamClosedError = _chunk7AHW7FCNcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunk7AHW7FCNcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunk7AHW7FCNcjs.TargetSchema; exports.ValidationError = _chunk7AHW7FCNcjs.ValidationError; exports.ZodEmpty = _chunk7AHW7FCNcjs.ZodEmpty; exports.act = act; exports.cache = _chunk6J2QWD4Qcjs.cache; exports.config = _chunk6J2QWD4Qcjs.config; exports.dateReviver = _chunk6J2QWD4Qcjs.dateReviver; exports.default_scope = _chunk6J2QWD4Qcjs.default_scope; exports.dispose = _chunk6J2QWD4Qcjs.dispose; exports.disposeAndExit = _chunk6J2QWD4Qcjs.disposeAndExit; exports.extend = _chunk6J2QWD4Qcjs.extend; exports.is_literal_source = _chunk6J2QWD4Qcjs.is_literal_source; exports.log = _chunk6J2QWD4Qcjs.log; exports.pii_fields = _chunk7AHW7FCNcjs.pii_fields; exports.port = _chunk6J2QWD4Qcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunk6J2QWD4Qcjs.resolveAutocloseConfig2; exports.sensitive = _chunk7AHW7FCNcjs.sensitive; exports.sleep = _chunk6J2QWD4Qcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunk6J2QWD4Qcjs.store; exports.validate = _chunk6J2QWD4Qcjs.validate;
5261
5279
  //# sourceMappingURL=index.cjs.map