@rotorsoft/act 1.33.12 → 1.33.14

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 _chunkP3B7HVFDcjs = require('./chunk-P3B7HVFD.cjs');
43
+ var _chunkU54EW4DXcjs = require('./chunk-U54EW4DX.cjs');
44
44
 
45
45
 
46
46
 
@@ -70,24 +70,24 @@ var _chunkP3B7HVFDcjs = require('./chunk-P3B7HVFD.cjs');
70
70
 
71
71
 
72
72
 
73
- var _chunkAVXVMZ4Bcjs = require('./chunk-AVXVMZ4B.cjs');
73
+ var _chunkPMS6BMIUcjs = require('./chunk-PMS6BMIU.cjs');
74
74
 
75
75
  // src/signals.ts
76
76
  process.once("SIGINT", async (arg) => {
77
- _chunkP3B7HVFDcjs.log.call(void 0, ).info(arg, "SIGINT");
78
- await _chunkP3B7HVFDcjs.disposeAndExit.call(void 0, "EXIT");
77
+ _chunkU54EW4DXcjs.log.call(void 0, ).info(arg, "SIGINT");
78
+ await _chunkU54EW4DXcjs.disposeAndExit.call(void 0, "EXIT");
79
79
  });
80
80
  process.once("SIGTERM", async (arg) => {
81
- _chunkP3B7HVFDcjs.log.call(void 0, ).info(arg, "SIGTERM");
82
- await _chunkP3B7HVFDcjs.disposeAndExit.call(void 0, "EXIT");
81
+ _chunkU54EW4DXcjs.log.call(void 0, ).info(arg, "SIGTERM");
82
+ await _chunkU54EW4DXcjs.disposeAndExit.call(void 0, "EXIT");
83
83
  });
84
84
  process.once("uncaughtException", async (arg) => {
85
- _chunkP3B7HVFDcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
86
- await _chunkP3B7HVFDcjs.disposeAndExit.call(void 0, "ERROR");
85
+ _chunkU54EW4DXcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
86
+ await _chunkU54EW4DXcjs.disposeAndExit.call(void 0, "ERROR");
87
87
  });
88
88
  process.once("unhandledRejection", async (arg) => {
89
- _chunkP3B7HVFDcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
90
- await _chunkP3B7HVFDcjs.disposeAndExit.call(void 0, "ERROR");
89
+ _chunkU54EW4DXcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
90
+ await _chunkU54EW4DXcjs.disposeAndExit.call(void 0, "ERROR");
91
91
  });
92
92
 
93
93
  // src/act.ts
@@ -195,7 +195,7 @@ async function* audit(deps, categories, options = {}) {
195
195
  if (need_stats) {
196
196
  const stats = await deps.store().query_stats(
197
197
  {},
198
- { count: true, names: true, exclude: [_chunkAVXVMZ4Bcjs.SNAP_EVENT] }
198
+ { count: true, names: true, exclude: [_chunkPMS6BMIUcjs.SNAP_EVENT] }
199
199
  );
200
200
  for (const [stream, s] of stats) {
201
201
  for (const p of passes) _optionalChain([p, 'access', _4 => _4.on_stat, 'optionalCall', _5 => _5(stream, s)]);
@@ -277,7 +277,7 @@ var make_schema_pass = (deps) => {
277
277
  return;
278
278
  }
279
279
  const schema = state2.events[name];
280
- const sensitive2 = _chunkAVXVMZ4Bcjs.pii_fields.call(void 0, schema);
280
+ const sensitive2 = _chunkPMS6BMIUcjs.pii_fields.call(void 0, schema);
281
281
  let parse_schema = schema;
282
282
  if (sensitive2.length > 0) {
283
283
  const omitter = schema.omit;
@@ -411,7 +411,7 @@ var make_restart_candidate_pass = (deps, options) => {
411
411
  {
412
412
  stream,
413
413
  stream_exact: true,
414
- names: [_chunkAVXVMZ4Bcjs.SNAP_EVENT],
414
+ names: [_chunkPMS6BMIUcjs.SNAP_EVENT],
415
415
  with_snaps: true
416
416
  }
417
417
  );
@@ -840,7 +840,7 @@ async function run_close_cycle(targets, deps) {
840
840
  deps,
841
841
  () => run_full_closes(full, target_map, deps, skipped)
842
842
  );
843
- const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT).map(([stream]) => stream);
843
+ const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkPMS6BMIUcjs.TOMBSTONE_EVENT).map(([stream]) => stream);
844
844
  if (retired.length) _optionalChain([deps, 'access', _42 => _42.forget_subscribed, 'optionalCall', _43 => _43(retired)]);
845
845
  for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
846
846
  return { truncated, skipped };
@@ -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 _chunkP3B7HVFDcjs.store.call(void 0, ).truncate([
925
+ const result = await _chunkU54EW4DXcjs.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,10 +935,10 @@ 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 _chunkP3B7HVFDcjs.store.call(void 0, ).query(
938
+ await _chunkU54EW4DXcjs.store.call(void 0, ).query(
939
939
  (event) => {
940
940
  if (min_id === void 0 || event.id < min_id) min_id = event.id;
941
- if (event.name === _chunkAVXVMZ4Bcjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
941
+ if (event.name === _chunkPMS6BMIUcjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
942
942
  boundary_id = event.id;
943
943
  },
944
944
  { stream, stream_exact: true, with_snaps: true, after: -1 }
@@ -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
- _chunkP3B7HVFDcjs.store.call(void 0, ),
952
+ _chunkU54EW4DXcjs.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,17 +977,17 @@ function source_matcher() {
977
977
  };
978
978
  }
979
979
  async function scan_stream_heads(streams) {
980
- const stats = await _chunkP3B7HVFDcjs.store.call(void 0, ).query_stats(streams, {
981
- exclude: [_chunkAVXVMZ4Bcjs.SNAP_EVENT]
980
+ const stats = await _chunkU54EW4DXcjs.store.call(void 0, ).query_stats(streams, {
981
+ exclude: [_chunkPMS6BMIUcjs.SNAP_EVENT]
982
982
  });
983
- const domain_heads = await _chunkP3B7HVFDcjs.store.call(void 0, ).query_stats(streams, {
984
- exclude: [_chunkAVXVMZ4Bcjs.SNAP_EVENT, _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT]
983
+ const domain_heads = await _chunkU54EW4DXcjs.store.call(void 0, ).query_stats(streams, {
984
+ exclude: [_chunkPMS6BMIUcjs.SNAP_EVENT, _chunkPMS6BMIUcjs.TOMBSTONE_EVENT]
985
985
  });
986
- const true_heads = await _chunkP3B7HVFDcjs.store.call(void 0, ).query_stats(streams, {});
986
+ const true_heads = await _chunkU54EW4DXcjs.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]);
990
- const interrupted = _optionalChain([marker_head, 'optionalAccess', _48 => _48.name]) === _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT;
990
+ const interrupted = _optionalChain([marker_head, 'optionalAccess', _48 => _48.name]) === _chunkPMS6BMIUcjs.TOMBSTONE_EVENT;
991
991
  out.set(stream, {
992
992
  max_id: head.id,
993
993
  version: true_heads.get(stream).head.version,
@@ -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
- _chunkP3B7HVFDcjs.store.call(void 0, ),
1014
+ _chunkU54EW4DXcjs.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 _chunkP3B7HVFDcjs.store.call(void 0, ).query_stats(guarded, {});
1080
+ const heads = await _chunkU54EW4DXcjs.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;
@@ -1095,18 +1095,18 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
1095
1095
  meta: {
1096
1096
  correlation,
1097
1097
  causation: {
1098
- event: { id: guard.id, name: _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT, stream: guard.stream }
1098
+ event: { id: guard.id, name: _chunkPMS6BMIUcjs.TOMBSTONE_EVENT, stream: guard.stream }
1099
1099
  }
1100
1100
  }
1101
1101
  };
1102
1102
  });
1103
- const truncated = await _chunkP3B7HVFDcjs.store.call(void 0, ).truncate(trunc_targets);
1103
+ const truncated = await _chunkU54EW4DXcjs.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 _chunkP3B7HVFDcjs.cache.call(void 0, ).set(stream, {
1109
+ await _chunkU54EW4DXcjs.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 _chunkP3B7HVFDcjs.cache.call(void 0, ).invalidate(stream);
1118
+ await _chunkU54EW4DXcjs.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
- _chunkP3B7HVFDcjs.log.call(void 0, ).error(new Error(message));
1132
+ _chunkU54EW4DXcjs.log.call(void 0, ).error(new Error(message));
1133
1133
  }
1134
1134
 
1135
1135
  // src/internal/correlate-cycle.ts
@@ -1156,36 +1156,35 @@ function report_lane_conflict(seen, handler, target, kept, dropped) {
1156
1156
  }
1157
1157
  var CorrelateCycle = (_class3 = class {
1158
1158
  __init3() {this._checkpoint = -1}
1159
- __init4() {this._initialized = false}
1160
1159
  /** Lease holder id; per instance, so a restart never inherits a stale claim. */
1161
- __init5() {this._by = _crypto.randomUUID.call(void 0, )}
1160
+ __init4() {this._by = _crypto.randomUUID.call(void 0, )}
1162
1161
 
1163
1162
  /** Local expiry of the held lease (0 = none); stale only costs a duplicate scan. */
1164
- __init6() {this._lease_until = 0}
1163
+ __init5() {this._lease_until = 0}
1165
1164
  /**
1166
1165
  * Armed while `_raised` (bumped by a commit or notification) is ahead of
1167
1166
  * `_lowered` (the raise count the last short page saw). Starts armed.
1168
1167
  */
1169
- __init7() {this._raised = 1}
1170
- __init8() {this._lowered = 0}
1168
+ __init6() {this._raised = 1}
1169
+ __init7() {this._lowered = 0}
1171
1170
  /**
1172
1171
  * Bumped by a release (shutdown) and a restart (restore), so a scan or
1173
1172
  * lease reply that was out across one writes nothing.
1174
1173
  */
1175
- __init9() {this._epoch = 0}
1174
+ __init8() {this._epoch = 0}
1176
1175
 
1177
1176
  // Bounded by `maxSubscribedStreams`; static records live apart so eviction
1178
1177
  // never drops their +Infinity floor.
1179
1178
 
1180
- __init10() {this._static_subscriptions = /* @__PURE__ */ new Map()}
1181
- __init11() {this._patterns = new (0, _chunkP3B7HVFDcjs.LruMap)(PATTERN_CACHE_SIZE)}
1179
+ __init9() {this._static_subscriptions = /* @__PURE__ */ new Map()}
1180
+ __init10() {this._patterns = new (0, _chunkU54EW4DXcjs.LruMap)(PATTERN_CACHE_SIZE)}
1182
1181
 
1183
1182
 
1184
1183
 
1185
1184
 
1186
1185
 
1187
1186
  /** Report-once keys; per instance because `internal/` holds no module state. */
1188
- __init12() {this._reported = /* @__PURE__ */ new Set()}
1187
+ __init11() {this._reported = /* @__PURE__ */ new Set()}
1189
1188
  constructor({
1190
1189
  registry,
1191
1190
  static_targets,
@@ -1194,9 +1193,9 @@ var CorrelateCycle = (_class3 = class {
1194
1193
  declared_lanes,
1195
1194
  shard,
1196
1195
  on_init
1197
- }) {;_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);
1196
+ }) {;_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);
1198
1197
  this._key = shard ? `${registry_key(registry.events)}:${[...shard].sort().join(",")}` : registry_key(registry.events);
1199
- this._dynamic_subscriptions = new (0, _chunkP3B7HVFDcjs.LruMap)(max_subscribed_streams);
1198
+ this._dynamic_subscriptions = new (0, _chunkU54EW4DXcjs.LruMap)(max_subscribed_streams);
1200
1199
  this._registry = registry;
1201
1200
  this._declared_lanes = declared_lanes;
1202
1201
  this._static_targets = static_targets;
@@ -1210,16 +1209,12 @@ var CorrelateCycle = (_class3 = class {
1210
1209
  arm() {
1211
1210
  this._raised++;
1212
1211
  }
1213
- async init() {
1214
- if (this._initialized) return;
1215
- if (!this._init_promise) {
1216
- this._init_promise = this._run_init().catch((error) => {
1217
- this._init_promise = void 0;
1218
- throw error;
1219
- });
1220
- }
1212
+ async _init() {
1213
+ this._init_promise ??= this._run_init().catch((error) => {
1214
+ this._init_promise = void 0;
1215
+ throw error;
1216
+ });
1221
1217
  await this._init_promise;
1222
- this._initialized = true;
1223
1218
  }
1224
1219
  async _run_init() {
1225
1220
  const { watermark, correlated_at } = await this._cd.subscribe([
@@ -1237,7 +1232,6 @@ var CorrelateCycle = (_class3 = class {
1237
1232
  }
1238
1233
  /** After `restore` replaced the log: forget everything and cold-start again. */
1239
1234
  restart() {
1240
- this._initialized = false;
1241
1235
  this._init_promise = void 0;
1242
1236
  this._checkpoint = -1;
1243
1237
  this._dynamic_subscriptions.clear();
@@ -1252,7 +1246,7 @@ var CorrelateCycle = (_class3 = class {
1252
1246
  /** Would the target's own `fetch` (filtered by `source`) return this event? */
1253
1247
  _in_fetch_window(source, stream) {
1254
1248
  if (source === void 0 || source === stream) return true;
1255
- if (_chunkP3B7HVFDcjs.is_literal_source.call(void 0, source)) return false;
1249
+ if (_chunkU54EW4DXcjs.is_literal_source.call(void 0, source)) return false;
1256
1250
  let pattern = this._patterns.get(source);
1257
1251
  if (!pattern) {
1258
1252
  pattern = new RegExp(source);
@@ -1261,14 +1255,12 @@ var CorrelateCycle = (_class3 = class {
1261
1255
  return pattern.test(stream);
1262
1256
  }
1263
1257
  /** Scan past the checkpoint, subscribe new targets and raise their work marks. */
1264
- async correlate(query = { after: -1, limit: 10 }, lease = false) {
1265
- await this.init();
1258
+ async correlate(query, lease = false) {
1259
+ await this._init();
1266
1260
  const epoch = this._epoch;
1267
1261
  const idle = () => ({
1268
- subscribed: 0,
1269
- last_id: this._checkpoint,
1270
- marked: 0,
1271
- scanned: false
1262
+ kind: "idle",
1263
+ last_id: this._checkpoint
1272
1264
  });
1273
1265
  if (this._raised === this._lowered) return idle();
1274
1266
  const raised = this._raised;
@@ -1287,7 +1279,7 @@ var CorrelateCycle = (_class3 = class {
1287
1279
  const correlated = /* @__PURE__ */ new Map();
1288
1280
  let last_id = after;
1289
1281
  let stopped = false;
1290
- const found = await _chunkP3B7HVFDcjs.store.call(void 0, ).query(
1282
+ const found = await _chunkU54EW4DXcjs.store.call(void 0, ).query(
1291
1283
  (event) => {
1292
1284
  if (stopped) return;
1293
1285
  const register = this._registry.events[event.name];
@@ -1331,9 +1323,9 @@ var CorrelateCycle = (_class3 = class {
1331
1323
  correlated_at: void 0
1332
1324
  };
1333
1325
  const seen_in_scan = correlated.has(resolved.target);
1334
- const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _61 => _61.lane])), () => ( _chunkAVXVMZ4Bcjs.DEFAULT_LANE));
1326
+ const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _61 => _61.lane])), () => ( _chunkPMS6BMIUcjs.DEFAULT_LANE));
1335
1327
  const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _62 => _62.priority]);
1336
- const resolved_lane = _nullishCoalesce(lane, () => ( _chunkAVXVMZ4Bcjs.DEFAULT_LANE));
1328
+ const resolved_lane = _nullishCoalesce(lane, () => ( _chunkPMS6BMIUcjs.DEFAULT_LANE));
1337
1329
  if (held_priority === priority && held_lane !== resolved_lane)
1338
1330
  report_lane_conflict(
1339
1331
  this._reported,
@@ -1360,6 +1352,7 @@ var CorrelateCycle = (_class3 = class {
1360
1352
  { ...query, after, with_pii: false }
1361
1353
  );
1362
1354
  if (this._declared_lanes.size > 1) await this._recall(correlated);
1355
+ const read = last_id > after;
1363
1356
  if (this._epoch !== epoch) return idle();
1364
1357
  const streams = [];
1365
1358
  for (const [stream, entry] of correlated) {
@@ -1393,11 +1386,11 @@ var CorrelateCycle = (_class3 = class {
1393
1386
  lane
1394
1387
  });
1395
1388
  }
1396
- return { subscribed, last_id, marked, scanned: true };
1389
+ return { kind: "scanned", last_id, subscribed, marked, read };
1397
1390
  }
1398
1391
  this._checkpoint = last_id;
1399
1392
  if (!stopped && found !== query.limit) this._lowered = raised;
1400
- return { subscribed: 0, last_id, marked: 0, scanned: true };
1393
+ return { kind: "scanned", last_id, subscribed: 0, marked: 0, read };
1401
1394
  }
1402
1395
  /**
1403
1396
  * Read the row of each target this scan had no record of (new or evicted),
@@ -1409,7 +1402,7 @@ var CorrelateCycle = (_class3 = class {
1409
1402
  await Promise.all(
1410
1403
  missed.map(async ([stream, entry]) => {
1411
1404
  let row;
1412
- await _chunkP3B7HVFDcjs.store.call(void 0, ).query_streams(
1405
+ await _chunkU54EW4DXcjs.store.call(void 0, ).query_streams(
1413
1406
  (position) => {
1414
1407
  row = position;
1415
1408
  },
@@ -1422,8 +1415,8 @@ var CorrelateCycle = (_class3 = class {
1422
1415
  lane: row.lane
1423
1416
  });
1424
1417
  if (entry.priority > row.priority) return;
1425
- const held_lane = _nullishCoalesce(row.lane, () => ( _chunkAVXVMZ4Bcjs.DEFAULT_LANE));
1426
- const resolved_lane = _nullishCoalesce(entry.lane, () => ( _chunkAVXVMZ4Bcjs.DEFAULT_LANE));
1418
+ const held_lane = _nullishCoalesce(row.lane, () => ( _chunkPMS6BMIUcjs.DEFAULT_LANE));
1419
+ const resolved_lane = _nullishCoalesce(entry.lane, () => ( _chunkPMS6BMIUcjs.DEFAULT_LANE));
1427
1420
  if (entry.priority === row.priority && held_lane !== resolved_lane)
1428
1421
  report_lane_conflict(
1429
1422
  this._reported,
@@ -1449,7 +1442,7 @@ var CorrelateCycle = (_class3 = class {
1449
1442
  millis: 0
1450
1443
  });
1451
1444
  } catch (error) {
1452
- _chunkP3B7HVFDcjs.log.call(void 0, ).warn(
1445
+ _chunkU54EW4DXcjs.log.call(void 0, ).warn(
1453
1446
  `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)}`
1454
1447
  );
1455
1448
  }
@@ -1511,14 +1504,14 @@ function compute_backoff_delay(retry, opts) {
1511
1504
  // src/internal/defer-timer.ts
1512
1505
  var MAX_TIMER_DELAY_MS = 2147483647;
1513
1506
  var DeferTimer = (_class4 = class {
1514
- __init13() {this._due = /* @__PURE__ */ new Map()}
1507
+ __init12() {this._due = /* @__PURE__ */ new Map()}
1515
1508
 
1516
1509
 
1517
1510
  /**
1518
1511
  * @param on_wake - invoked once each time the earliest due-time elapses.
1519
1512
  * The consumer re-schedules for whatever is still parked.
1520
1513
  */
1521
- constructor(on_wake) {;_class4.prototype.__init13.call(this);
1514
+ constructor(on_wake) {;_class4.prototype.__init12.call(this);
1522
1515
  this._on_wake = on_wake;
1523
1516
  }
1524
1517
  /** Number of currently parked streams. */
@@ -1602,14 +1595,14 @@ function compute_lag_lead_ratio(handled, lagging, leading) {
1602
1595
  }
1603
1596
 
1604
1597
  // src/internal/drain-ops.ts
1605
- var claim = (lagging, leading, by, millis, lane) => _chunkP3B7HVFDcjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
1598
+ var claim = (lagging, leading, by, millis, lane) => _chunkU54EW4DXcjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
1606
1599
  async function fetch(leased, eventLimit) {
1607
1600
  return Promise.all(
1608
1601
  leased.map(async ({ stream, source, at, lagging }) => {
1609
1602
  const events = [];
1610
- const stream_exact = source !== void 0 && _chunkP3B7HVFDcjs.is_literal_source.call(void 0, source) ? true : void 0;
1603
+ const stream_exact = source !== void 0 && _chunkU54EW4DXcjs.is_literal_source.call(void 0, source) ? true : void 0;
1611
1604
  try {
1612
- await _chunkP3B7HVFDcjs.store.call(void 0, ).query((e) => events.push(e), {
1605
+ await _chunkU54EW4DXcjs.store.call(void 0, ).query((e) => events.push(e), {
1613
1606
  stream: source,
1614
1607
  stream_exact,
1615
1608
  after: at,
@@ -1629,30 +1622,30 @@ async function fetch(leased, eventLimit) {
1629
1622
  })
1630
1623
  );
1631
1624
  }
1632
- var ack = (leases) => _chunkP3B7HVFDcjs.store.call(void 0, ).ack(leases);
1633
- var block = (leases) => _chunkP3B7HVFDcjs.store.call(void 0, ).block(leases);
1634
- var subscribe = (streams, correlated_at, correlator) => _chunkP3B7HVFDcjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
1625
+ var ack = (leases) => _chunkU54EW4DXcjs.store.call(void 0, ).ack(leases);
1626
+ var block = (leases) => _chunkU54EW4DXcjs.store.call(void 0, ).block(leases);
1627
+ var subscribe = (streams, correlated_at, correlator) => _chunkU54EW4DXcjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
1635
1628
 
1636
1629
  // src/internal/event-sourcing.ts
1637
1630
  var _actpatch = require('@rotorsoft/act-patch');
1638
1631
  var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
1639
1632
  var validating_patch = (me, state2, partial, event) => {
1640
1633
  const next = _actpatch.patch.call(void 0, state2, partial);
1641
- return _chunkP3B7HVFDcjs.validate.call(void 0,
1634
+ return _chunkU54EW4DXcjs.validate.call(void 0,
1642
1635
  `${me.name}.${String(event.name)}#${event.id}`,
1643
1636
  next,
1644
1637
  me.state
1645
1638
  );
1646
1639
  };
1647
1640
  var DEFAULT_BATCH = 500;
1648
- var cache_put = (stream, entry) => _chunkP3B7HVFDcjs.cache.call(void 0, ).set(stream, entry).catch(
1649
- (err) => _chunkP3B7HVFDcjs.log.call(void 0, ).warn(
1641
+ var cache_put = (stream, entry) => _chunkU54EW4DXcjs.cache.call(void 0, ).set(stream, entry).catch(
1642
+ (err) => _chunkU54EW4DXcjs.log.call(void 0, ).warn(
1650
1643
  err,
1651
1644
  "cache set skipped; the next load re-folds from the store"
1652
1645
  )
1653
1646
  );
1654
- var cache_drop = (stream) => _chunkP3B7HVFDcjs.cache.call(void 0, ).invalidate(stream).catch(
1655
- (err) => _chunkP3B7HVFDcjs.log.call(void 0, ).warn(
1647
+ var cache_drop = (stream) => _chunkU54EW4DXcjs.cache.call(void 0, ).invalidate(stream).catch(
1648
+ (err) => _chunkU54EW4DXcjs.log.call(void 0, ).warn(
1656
1649
  err,
1657
1650
  "cache invalidate skipped; a stale checkpoint re-folds from its event_id"
1658
1651
  )
@@ -1660,9 +1653,9 @@ var cache_drop = (stream) => _chunkP3B7HVFDcjs.cache.call(void 0, ).invalidate(s
1660
1653
  async function snap(snapshot) {
1661
1654
  const { id, stream, name, meta, version } = snapshot.event;
1662
1655
  try {
1663
- const [committed] = await _chunkP3B7HVFDcjs.store.call(void 0, ).commit(
1656
+ const [committed] = await _chunkU54EW4DXcjs.store.call(void 0, ).commit(
1664
1657
  stream,
1665
- [{ name: _chunkAVXVMZ4Bcjs.SNAP_EVENT, data: snapshot.state }],
1658
+ [{ name: _chunkPMS6BMIUcjs.SNAP_EVENT, data: snapshot.state }],
1666
1659
  {
1667
1660
  correlation: meta.correlation,
1668
1661
  causation: { event: { id, name, stream } }
@@ -1673,22 +1666,22 @@ async function snap(snapshot) {
1673
1666
  return committed;
1674
1667
  } catch (error) {
1675
1668
  const reason = error instanceof Error ? error.message : String(error);
1676
- _chunkP3B7HVFDcjs.log.call(void 0, ).warn(
1669
+ _chunkU54EW4DXcjs.log.call(void 0, ).warn(
1677
1670
  `Snapshot write failed on stream "${stream}": ${reason} \u2014 cold starts will replay full history until snapshots succeed.`
1678
1671
  );
1679
1672
  }
1680
1673
  }
1681
1674
  async function tombstone(stream, expectedVersion, correlation) {
1682
1675
  try {
1683
- const [committed] = await _chunkP3B7HVFDcjs.store.call(void 0, ).commit(
1676
+ const [committed] = await _chunkU54EW4DXcjs.store.call(void 0, ).commit(
1684
1677
  stream,
1685
- [{ name: _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT, data: {} }],
1678
+ [{ name: _chunkPMS6BMIUcjs.TOMBSTONE_EVENT, data: {} }],
1686
1679
  { correlation, causation: {} },
1687
1680
  expectedVersion
1688
1681
  );
1689
1682
  return committed;
1690
1683
  } catch (error) {
1691
- if (error instanceof _chunkAVXVMZ4Bcjs.ConcurrencyError) return void 0;
1684
+ if (error instanceof _chunkPMS6BMIUcjs.ConcurrencyError) return void 0;
1692
1685
  throw error;
1693
1686
  }
1694
1687
  }
@@ -1718,9 +1711,9 @@ async function scan(source, opts = {}, callback) {
1718
1711
  if (drop_closed_streams) {
1719
1712
  await source.query(
1720
1713
  (e) => {
1721
- if (e.name === _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT) closed_streams.add(e.stream);
1714
+ if (e.name === _chunkPMS6BMIUcjs.TOMBSTONE_EVENT) closed_streams.add(e.stream);
1722
1715
  },
1723
- { names: [_chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT] }
1716
+ { names: [_chunkPMS6BMIUcjs.TOMBSTONE_EVENT] }
1724
1717
  );
1725
1718
  }
1726
1719
  let max_id;
@@ -1742,11 +1735,11 @@ async function scan(source, opts = {}, callback) {
1742
1735
  if (!is_valid(event))
1743
1736
  throw new Error(`Invalid event at index ${processed}`);
1744
1737
  if (on_progress) on_progress({ processed, id: event.id, max_id });
1745
- if (drop_snapshots && event.name === _chunkAVXVMZ4Bcjs.SNAP_EVENT) {
1738
+ if (drop_snapshots && event.name === _chunkPMS6BMIUcjs.SNAP_EVENT) {
1746
1739
  dropped_snaps++;
1747
1740
  return;
1748
1741
  }
1749
- if (closed_streams.has(event.stream) && event.name !== _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT) {
1742
+ if (closed_streams.has(event.stream) && event.name !== _chunkPMS6BMIUcjs.TOMBSTONE_EVENT) {
1750
1743
  dropped_closed++;
1751
1744
  return;
1752
1745
  }
@@ -1813,17 +1806,17 @@ async function scan(source, opts = {}, callback) {
1813
1806
  async function load(me, target, callback, patch_fn = bare_patch) {
1814
1807
  const { stream, actor, asOf } = target;
1815
1808
  const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
1816
- const cached = time_travel ? void 0 : await _chunkP3B7HVFDcjs.cache.call(void 0, ).get(stream);
1809
+ const cached = time_travel ? void 0 : await _chunkU54EW4DXcjs.cache.call(void 0, ).get(stream);
1817
1810
  const cache_hit = !!cached;
1818
1811
  let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _72 => _72.state]), () => ( (me.init ? me.init() : {})));
1819
1812
  let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _73 => _73.patches]), () => ( 0));
1820
1813
  let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _74 => _74.snaps]), () => ( 0));
1821
1814
  let replayed = 0;
1822
1815
  let event;
1823
- await _chunkP3B7HVFDcjs.store.call(void 0, ).query(
1816
+ await _chunkU54EW4DXcjs.store.call(void 0, ).query(
1824
1817
  (raw) => {
1825
1818
  event = me.view(raw, actor);
1826
- if (event.name === _chunkAVXVMZ4Bcjs.SNAP_EVENT) {
1819
+ if (event.name === _chunkPMS6BMIUcjs.SNAP_EVENT) {
1827
1820
  state2 = event.data;
1828
1821
  snaps++;
1829
1822
  patches = 0;
@@ -1832,8 +1825,8 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1832
1825
  state2 = patch_fn(me, state2, me.patch[event.name](event, state2), event);
1833
1826
  patches++;
1834
1827
  replayed++;
1835
- } else if (event.name !== _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT) {
1836
- _chunkP3B7HVFDcjs.log.call(void 0, ).warn(
1828
+ } else if (event.name !== _chunkPMS6BMIUcjs.TOMBSTONE_EVENT) {
1829
+ _chunkU54EW4DXcjs.log.call(void 0, ).warn(
1837
1830
  `Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
1838
1831
  );
1839
1832
  }
@@ -1857,7 +1850,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
1857
1850
  ...cached ? { after: cached.event_id, with_snaps: true } : { ...time_travel ? {} : { with_snaps: true }, ...asOf }
1858
1851
  }
1859
1852
  );
1860
- const head_is_tombstone = _optionalChain([event, 'optionalAccess', _76 => _76.name]) === _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT;
1853
+ const head_is_tombstone = _optionalChain([event, 'optionalAccess', _76 => _76.name]) === _chunkPMS6BMIUcjs.TOMBSTONE_EVENT;
1861
1854
  if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
1862
1855
  await cache_put(stream, {
1863
1856
  stream,
@@ -1885,7 +1878,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1885
1878
  if (!stream) throw new Error("Missing target stream");
1886
1879
  const reactingTo = _optionalChain([options, 'optionalAccess', _81 => _81.reactingTo]);
1887
1880
  const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _82 => _82.correlator]), () => ( default_correlator));
1888
- const validated = _chunkP3B7HVFDcjs.validate.call(void 0, action2, payload, me.actions[action2]);
1881
+ const validated = _chunkU54EW4DXcjs.validate.call(void 0, action2, payload, me.actions[action2]);
1889
1882
  const opts = _optionalChain([me, 'access', _83 => _83.options, 'optionalAccess', _84 => _84[action2]]);
1890
1883
  const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.maxRetries]), () => ( 0));
1891
1884
  for (let attempt = 0; ; attempt++) {
@@ -1896,14 +1889,14 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1896
1889
  void 0,
1897
1890
  patch_fn
1898
1891
  );
1899
- if (_optionalChain([snapshot, 'access', _86 => _86.event, 'optionalAccess', _87 => _87.name]) === _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT)
1900
- throw new (0, _chunkAVXVMZ4Bcjs.StreamClosedError)(stream);
1892
+ if (_optionalChain([snapshot, 'access', _86 => _86.event, 'optionalAccess', _87 => _87.name]) === _chunkPMS6BMIUcjs.TOMBSTONE_EVENT)
1893
+ throw new (0, _chunkPMS6BMIUcjs.StreamClosedError)(stream);
1901
1894
  const expected = _nullishCoalesce(expectedVersion, () => ( (snapshot.version >= 0 ? snapshot.version : void 0)));
1902
1895
  if (me.given) {
1903
1896
  const invariants = me.given[action2] || [];
1904
1897
  invariants.forEach(({ valid: valid2, description }) => {
1905
1898
  if (!valid2(snapshot.state, actor))
1906
- throw new (0, _chunkAVXVMZ4Bcjs.InvariantError)(
1899
+ throw new (0, _chunkPMS6BMIUcjs.InvariantError)(
1907
1900
  action2,
1908
1901
  validated,
1909
1902
  target,
@@ -1920,7 +1913,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1920
1913
  const tuples = Array.isArray(result[0]) ? result : [result];
1921
1914
  const valid = tuples.map(([name, data]) => ({
1922
1915
  name,
1923
- data: _chunkP3B7HVFDcjs.validate.call(void 0, name, data, me.events[name])
1916
+ data: _chunkU54EW4DXcjs.validate.call(void 0, name, data, me.events[name])
1924
1917
  }));
1925
1918
  const emitted = valid.map((e) => me.message(e));
1926
1919
  const meta = {
@@ -1945,7 +1938,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1945
1938
  };
1946
1939
  let committed;
1947
1940
  try {
1948
- committed = await _chunkP3B7HVFDcjs.store.call(void 0, ).commit(
1941
+ committed = await _chunkU54EW4DXcjs.store.call(void 0, ).commit(
1949
1942
  stream,
1950
1943
  emitted,
1951
1944
  meta,
@@ -1954,7 +1947,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1954
1947
  reactingTo ? expectedVersion : expected
1955
1948
  );
1956
1949
  } catch (error) {
1957
- if (error instanceof _chunkAVXVMZ4Bcjs.ConcurrencyError) void cache_drop(stream);
1950
+ if (error instanceof _chunkPMS6BMIUcjs.ConcurrencyError) void cache_drop(stream);
1958
1951
  throw error;
1959
1952
  }
1960
1953
  let { state: state2, patches } = snapshot;
@@ -1993,19 +1986,19 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
1993
1986
  }
1994
1987
  return snapshots;
1995
1988
  } catch (error) {
1996
- if (!(error instanceof _chunkAVXVMZ4Bcjs.ConcurrencyError)) throw error;
1989
+ if (!(error instanceof _chunkPMS6BMIUcjs.ConcurrencyError)) throw error;
1997
1990
  if (expectedVersion !== void 0) throw error;
1998
1991
  if (attempt >= max_retries) throw error;
1999
1992
  if (_optionalChain([opts, 'optionalAccess', _94 => _94.backoff])) {
2000
1993
  const delay_ms = compute_backoff_delay(attempt, opts.backoff);
2001
- if (delay_ms > 0) await _chunkP3B7HVFDcjs.sleep.call(void 0, delay_ms);
1994
+ if (delay_ms > 0) await _chunkU54EW4DXcjs.sleep.call(void 0, delay_ms);
2002
1995
  }
2003
1996
  }
2004
1997
  }
2005
1998
  }
2006
1999
 
2007
2000
  // src/internal/tracing.ts
2008
- var PRETTY = _chunkP3B7HVFDcjs.config.call(void 0, ).env !== "production";
2001
+ var PRETTY = _chunkU54EW4DXcjs.config.call(void 0, ).env !== "production";
2009
2002
  var C_BLUE = "\x1B[38;5;39m";
2010
2003
  var C_ORANGE = "\x1B[38;5;208m";
2011
2004
  var C_GREEN = "\x1B[38;5;42m";
@@ -2191,7 +2184,7 @@ function budget_exhausted(lease, options, store_failing) {
2191
2184
  if (store_failing || !_optionalChain([options, 'optionalAccess', _104 => _104.blockOnError]) || lease.retry <= options.maxRetries)
2192
2185
  return void 0;
2193
2186
  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.`;
2194
- _chunkP3B7HVFDcjs.log.call(void 0, ).error(error);
2187
+ _chunkU54EW4DXcjs.log.call(void 0, ).error(error);
2195
2188
  return { lease, handled: 0, acked_at: lease.at, error, block: true };
2196
2189
  }
2197
2190
  function fetch_failure_policy(registry) {
@@ -2207,13 +2200,13 @@ function fetch_failure_policy(registry) {
2207
2200
  function finalize(lease, handled, at, error, options, logger, failed_at) {
2208
2201
  if (!error) return { lease, handled, acked_at: at };
2209
2202
  logger.error(error);
2210
- const non_retryable = error instanceof _chunkAVXVMZ4Bcjs.NonRetryableError;
2203
+ const non_retryable = error instanceof _chunkPMS6BMIUcjs.NonRetryableError;
2211
2204
  const block2 = options.blockOnError && (non_retryable || lease.retry >= options.maxRetries);
2212
2205
  if (block2)
2213
2206
  logger.error(
2214
2207
  non_retryable ? `Blocking ${lease.stream} on non-retryable error.` : `Blocking ${lease.stream} after ${lease.retry} retries.`
2215
2208
  );
2216
- const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunkP3B7HVFDcjs.DEFAULT_BACKOFF)));
2209
+ const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunkU54EW4DXcjs.DEFAULT_BACKOFF)));
2217
2210
  return {
2218
2211
  lease,
2219
2212
  handled,
@@ -2342,7 +2335,7 @@ async function run_drain_cycle(deps, cycle) {
2342
2335
  const acked = await ops.ack(submitted);
2343
2336
  const expected = submitted.filter((l) => l.due === void 0).length;
2344
2337
  if (acked.length < expected)
2345
- _chunkP3B7HVFDcjs.log.call(void 0, ).warn(
2338
+ _chunkU54EW4DXcjs.log.call(void 0, ).warn(
2346
2339
  `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.`
2347
2340
  );
2348
2341
  const closeable = handled.filter((h) => h.close !== void 0).map((h) => h.close);
@@ -2354,6 +2347,14 @@ var EMPTY_DRAIN = {
2354
2347
  acked: [],
2355
2348
  blocked: []
2356
2349
  };
2350
+ function merge_drains(drains) {
2351
+ return {
2352
+ fetched: drains.flatMap((d) => d.fetched),
2353
+ leased: drains.flatMap((d) => d.leased),
2354
+ acked: drains.flatMap((d) => d.acked),
2355
+ blocked: drains.flatMap((d) => d.blocked)
2356
+ };
2357
+ }
2357
2358
  var RETRY = "";
2358
2359
  var DrainController = (_class5 = class {
2359
2360
  /**
@@ -2361,9 +2362,9 @@ var DrainController = (_class5 = class {
2361
2362
  * empty claim saw), so a claim never lowers over a raise that landed
2362
2363
  * during it.
2363
2364
  */
2364
- __init14() {this._raised = 0}
2365
- __init15() {this._lowered = 0}
2366
- __init16() {this._ratio = 0.5}
2365
+ __init13() {this._raised = 0}
2366
+ __init14() {this._lowered = 0}
2367
+ __init15() {this._ratio = 0.5}
2367
2368
  /**
2368
2369
  * Local wake at the earliest parked (backoff or defer) visit, or at the
2369
2370
  * lease expiry after a failed pass (the {@link RETRY} key); the schedule
@@ -2371,20 +2372,19 @@ var DrainController = (_class5 = class {
2371
2372
  * drains until a pass leases nothing or the controller stops, and an entry
2372
2373
  * stays until handled or until a later pass claims nothing.
2373
2374
  */
2374
- __init17() {this._defer = new DeferTimer(() => {
2375
+ __init16() {this._defer = new DeferTimer(() => {
2375
2376
  this.arm();
2376
2377
  void this._deps.run_scoped(async () => {
2377
2378
  while ((await this.drain()).leased.length > 0) ;
2378
2379
  });
2379
2380
  })}
2380
2381
 
2381
- __init18() {this._misrouted = /* @__PURE__ */ new Set()}
2382
- __init19() {this._stopped = false}
2383
- /** Never rejects; graceful shutdown waits on it. */
2384
-
2382
+ __init17() {this._misrouted = /* @__PURE__ */ new Set()}
2383
+ __init18() {this._stopped = false}
2384
+ /** The pass in flight. Never rejects; graceful shutdown waits on it. */
2385
2385
 
2386
2386
 
2387
- 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);
2387
+ constructor(deps) {;_class5.prototype.__init13.call(this);_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);
2388
2388
  this._deps = deps;
2389
2389
  }
2390
2390
  arm() {
@@ -2433,15 +2433,22 @@ var DrainController = (_class5 = class {
2433
2433
  if (!this.armed || this._stopped || this._inflight)
2434
2434
  return EMPTY_DRAIN;
2435
2435
  const d = _nullishCoalesce(this._deps.defaults, () => ( {}));
2436
- const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunkP3B7HVFDcjs.DEFAULT_STREAM_LIMIT));
2437
- const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkP3B7HVFDcjs.DEFAULT_EVENT_LIMIT));
2438
- const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkP3B7HVFDcjs.DEFAULT_LEASE_MILLIS));
2436
+ const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunkU54EW4DXcjs.DEFAULT_STREAM_LIMIT));
2437
+ const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkU54EW4DXcjs.DEFAULT_EVENT_LIMIT));
2438
+ const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkU54EW4DXcjs.DEFAULT_LEASE_MILLIS));
2439
2439
  if (this._deps.breaker.state(Date.now()) === "open")
2440
2440
  return EMPTY_DRAIN;
2441
+ const pass = this._pass(streamLimit, eventLimit, leaseMillis).finally(
2442
+ () => {
2443
+ this._inflight = void 0;
2444
+ }
2445
+ );
2446
+ this._inflight = pass;
2447
+ return pass;
2448
+ }
2449
+ /** One claim → fetch → handle → ack pass. Never throws. */
2450
+ async _pass(streamLimit, eventLimit, leaseMillis) {
2441
2451
  try {
2442
- this._inflight = new Promise((done) => {
2443
- this._inflight_done = done;
2444
- });
2445
2452
  const lagging = Math.ceil(streamLimit * this._ratio);
2446
2453
  const leading = streamLimit - lagging;
2447
2454
  const started = Date.now();
@@ -2482,9 +2489,6 @@ var DrainController = (_class5 = class {
2482
2489
  return EMPTY_DRAIN;
2483
2490
  } finally {
2484
2491
  if (!this._stopped) this._defer.schedule();
2485
- this._inflight = void 0;
2486
- _optionalChain([this, 'access', _118 => _118._inflight_done, 'optionalCall', _119 => _119()]);
2487
- this._inflight_done = void 0;
2488
2492
  }
2489
2493
  }
2490
2494
  }, _class5);
@@ -2506,7 +2510,7 @@ function pii_gate(event, fields, predicate, actor) {
2506
2510
  const { pii, ...rest } = event;
2507
2511
  if (pii == null) {
2508
2512
  const shredded = { ...data };
2509
- for (const f of fields) shredded[f] = _chunkAVXVMZ4Bcjs.SHREDDED;
2513
+ for (const f of fields) shredded[f] = _chunkPMS6BMIUcjs.SHREDDED;
2510
2514
  return { ...rest, data: shredded };
2511
2515
  }
2512
2516
  const allowed = !!actor && !!predicate && predicate(event, actor);
@@ -2517,7 +2521,7 @@ function pii_gate(event, fields, predicate, actor) {
2517
2521
  };
2518
2522
  }
2519
2523
  const redacted = { ...data };
2520
- for (const f of fields) redacted[f] = _chunkAVXVMZ4Bcjs.REDACTED;
2524
+ for (const f of fields) redacted[f] = _chunkPMS6BMIUcjs.REDACTED;
2521
2525
  return { ...rest, data: redacted };
2522
2526
  }
2523
2527
  var IDENTITY_GATE = (event) => event;
@@ -2654,7 +2658,7 @@ function make_deferred(handler, schedule) {
2654
2658
  const call = handler;
2655
2659
  const deferred = async (event, stream, app) => {
2656
2660
  const when = typeof schedule === "function" ? schedule(event) : schedule;
2657
- if (Date.now() < resolve_defer_at(when, event)) throw new (0, _chunkAVXVMZ4Bcjs.DeferSignal)(when);
2661
+ if (Date.now() < resolve_defer_at(when, event)) throw new (0, _chunkPMS6BMIUcjs.DeferSignal)(when);
2658
2662
  return call(event, stream, app);
2659
2663
  };
2660
2664
  Object.defineProperty(deferred, "name", { value: handler.name });
@@ -2690,10 +2694,10 @@ var CloseSignal = class extends Error {
2690
2694
  constructor(opts) {
2691
2695
  super("reaction requested close");
2692
2696
  this.name = "CloseSignal";
2693
- this.stream = _optionalChain([opts, 'optionalAccess', _120 => _120.stream]);
2694
- this.archive = _optionalChain([opts, 'optionalAccess', _121 => _121.archive]);
2695
- this.at = _optionalChain([opts, 'optionalAccess', _122 => _122.at]);
2696
- this.before = _optionalChain([opts, 'optionalAccess', _123 => _123.before]);
2697
+ this.stream = _optionalChain([opts, 'optionalAccess', _118 => _118.stream]);
2698
+ this.archive = _optionalChain([opts, 'optionalAccess', _119 => _119.archive]);
2699
+ this.at = _optionalChain([opts, 'optionalAccess', _120 => _120.at]);
2700
+ this.before = _optionalChain([opts, 'optionalAccess', _121 => _121.before]);
2697
2701
  }
2698
2702
  };
2699
2703
  function build_handle(deps) {
@@ -2723,7 +2727,7 @@ function build_handle(deps) {
2723
2727
  handled++;
2724
2728
  }
2725
2729
  } catch (error) {
2726
- if (error instanceof _chunkAVXVMZ4Bcjs.DeferSignal) {
2730
+ if (error instanceof _chunkPMS6BMIUcjs.DeferSignal) {
2727
2731
  let defer;
2728
2732
  try {
2729
2733
  defer = resolve_defer_at(error.when, event);
@@ -2802,24 +2806,24 @@ function build_handle_batch(logger) {
2802
2806
 
2803
2807
  // src/internal/settle.ts
2804
2808
  var SettleLoop = (_class6 = class {
2805
- __init20() {this._timer = void 0}
2809
+ __init19() {this._timer = void 0}
2806
2810
  /**
2807
2811
  * The cycle in flight, set while one runs. Shutdown waits for it
2808
2812
  * (`stop()` cancels scheduling only). Never rejects.
2809
2813
  */
2810
2814
 
2811
2815
  /** A wake-up arrived while a cycle ran: run one more pass after it. */
2812
- __init21() {this._pending = false}
2816
+ __init20() {this._pending = false}
2813
2817
  /** The last caller's options, used by the next pass. */
2814
- __init22() {this._next = void 0}
2818
+ __init21() {this._next = void 0}
2815
2819
  /** When the scheduled pass fires (epoch ms). */
2816
- __init23() {this._due = 0}
2820
+ __init22() {this._due = 0}
2817
2821
  /** Set at shutdown: nothing schedules again. */
2818
- __init24() {this._stopped = false}
2822
+ __init23() {this._stopped = false}
2819
2823
 
2820
2824
  /** Debounce window applied when the caller doesn't override via `SettleOptions.debounceMs`. */
2821
2825
 
2822
- 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);
2826
+ constructor(deps, default_debounce_ms) {;_class6.prototype.__init19.call(this);_class6.prototype.__init20.call(this);_class6.prototype.__init21.call(this);_class6.prototype.__init22.call(this);_class6.prototype.__init23.call(this);
2823
2827
  this._deps = deps;
2824
2828
  this._default_debounce_ms = default_debounce_ms;
2825
2829
  }
@@ -2841,7 +2845,7 @@ var SettleLoop = (_class6 = class {
2841
2845
  this._pending = true;
2842
2846
  return;
2843
2847
  }
2844
- const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _124 => _124.debounceMs]), () => ( this._default_debounce_ms));
2848
+ const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _122 => _122.debounceMs]), () => ( this._default_debounce_ms));
2845
2849
  const due = Date.now() + delay;
2846
2850
  if (this._timer) {
2847
2851
  if (due >= this._due) return;
@@ -2852,32 +2856,24 @@ var SettleLoop = (_class6 = class {
2852
2856
  this._timer = void 0;
2853
2857
  const {
2854
2858
  debounceMs: _,
2855
- correlate: correlate_query = {},
2859
+ // Every pass scans from correlation's own checkpoint.
2860
+ correlate: { after: _after, ...correlate_query } = {},
2856
2861
  maxPasses = Infinity,
2857
2862
  ...drain_options
2858
2863
  } = _nullishCoalesce(this._next, () => ( {}));
2859
2864
  this._next = void 0;
2860
2865
  this._inflight = (async () => {
2861
- await this._deps.init();
2862
- let settled_drain;
2866
+ const passes = [];
2863
2867
  for (let i = 0; i < maxPasses && !this._stopped; i++) {
2864
- const after_before = this._deps.checkpoint();
2865
- const { subscribed, last_id, scanned } = await this._deps.correlate({
2866
- ...correlate_query,
2867
- after: after_before
2868
- });
2868
+ const pass = await this._deps.correlate(correlate_query);
2869
+ const scanned = pass.kind === "scanned";
2869
2870
  if (scanned) this._deps.breaker.passed();
2870
2871
  const drain = await this._deps.drain(drain_options);
2871
- settled_drain = settled_drain ? {
2872
- fetched: [...settled_drain.fetched, ...drain.fetched],
2873
- leased: [...settled_drain.leased, ...drain.leased],
2874
- acked: [...settled_drain.acked, ...drain.acked],
2875
- blocked: [...settled_drain.blocked, ...drain.blocked]
2876
- } : drain;
2877
- const made_progress = subscribed > 0 || drain.leased.length > 0 || last_id > after_before;
2872
+ passes.push(drain);
2873
+ const made_progress = drain.leased.length > 0 || scanned && (pass.subscribed > 0 || pass.read);
2878
2874
  if (!made_progress) break;
2879
2875
  }
2880
- if (settled_drain) this._deps.on_settled(settled_drain);
2876
+ if (passes.length) this._deps.on_settled(merge_drains(passes));
2881
2877
  })().catch((err) => {
2882
2878
  this._deps.breaker.failed(Date.now(), err);
2883
2879
  }).finally(() => {
@@ -2923,7 +2919,7 @@ function validate_only_lanes(options, lanes) {
2923
2919
  );
2924
2920
  }
2925
2921
  var Act = (_class7 = class {
2926
- __init25() {this._emitter = new (0, _events2.default)()}
2922
+ __init24() {this._emitter = new (0, _events2.default)()}
2927
2923
 
2928
2924
 
2929
2925
 
@@ -2999,14 +2995,14 @@ var Act = (_class7 = class {
2999
2995
  /** Lanes to arm per event; `"all"` when a dynamic resolver hides the lane. */
3000
2996
 
3001
2997
 
3002
- __init26() {this._logger = _chunkP3B7HVFDcjs.log.call(void 0, )}
2998
+ __init25() {this._logger = _chunkU54EW4DXcjs.log.call(void 0, )}
3003
2999
  /** This Act's ports: its own bag, or the singleton adapters. */
3004
3000
 
3005
3001
  /** Runs a body so internal `store()`/`cache()` calls resolve to `_ports`. */
3006
3002
 
3007
3003
 
3008
3004
 
3009
- __init27() {this._close_lock = new CloseLock()}
3005
+ __init26() {this._close_lock = new CloseLock()}
3010
3006
  /** Every lane a controller can exist for: `"default"` plus each declared one. */
3011
3007
 
3012
3008
  /** Drain lanes declared via `.withLane(...)`. Implicit default not included. */
@@ -3014,16 +3010,16 @@ var Act = (_class7 = class {
3014
3010
  return this._lanes;
3015
3011
  }
3016
3012
  /** Use the {@link act} builder rather than constructing directly. */
3017
- 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);
3013
+ constructor(registry, states = /* @__PURE__ */ new Map(), batch_handlers = /* @__PURE__ */ new Map(), options = {}, lanes = [], patch_fn = bare_patch) {;_class7.prototype.__init24.call(this);_class7.prototype.__init25.call(this);_class7.prototype.__init26.call(this);
3018
3014
  this.registry = registry;
3019
3015
  this._states = states;
3020
3016
  this._batch_handlers = batch_handlers;
3021
3017
  this._lanes = lanes;
3022
3018
  this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
3023
3019
  validate_only_lanes(options, lanes);
3024
- this._ports = _nullishCoalesce(options.scoped, () => ( _chunkP3B7HVFDcjs.default_scope.call(void 0, )));
3020
+ this._ports = _nullishCoalesce(options.scoped, () => ( _chunkU54EW4DXcjs.default_scope.call(void 0, )));
3025
3021
  const ports = this._ports;
3026
- this._scoped = _chunkP3B7HVFDcjs.make_run_scoped.call(void 0, {
3022
+ this._scoped = _chunkU54EW4DXcjs.make_run_scoped.call(void 0, {
3027
3023
  // Getters, not a spread: the singletons resolve lazily, so a later
3028
3024
  // `store(...)` / `cache(...)` still takes effect.
3029
3025
  get store() {
@@ -3033,14 +3029,14 @@ var Act = (_class7 = class {
3033
3029
  return ports.cache;
3034
3030
  },
3035
3031
  // Parsed per build, so a bad window throws on every build.
3036
- autoclose_window: _chunkP3B7HVFDcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
3032
+ autoclose_window: _chunkU54EW4DXcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
3037
3033
  });
3038
3034
  this._correlator = _nullishCoalesce(options.correlator, () => ( default_correlator));
3039
3035
  this._es = build_es(this._logger, this._correlator, patch_fn);
3040
3036
  this._cd = build_drain(this._logger);
3041
3037
  const handle = build_handle({
3042
3038
  logger: this._logger,
3043
- reaction_scope: _chunkP3B7HVFDcjs.make_reaction_scope.call(void 0, {
3039
+ reaction_scope: _chunkU54EW4DXcjs.make_reaction_scope.call(void 0, {
3044
3040
  do: this.do.bind(this),
3045
3041
  load: this.load.bind(this),
3046
3042
  query: this.query.bind(this),
@@ -3070,12 +3066,12 @@ var Act = (_class7 = class {
3070
3066
  this._ports.store,
3071
3067
  options.listen !== false
3072
3068
  );
3073
- _chunkP3B7HVFDcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
3069
+ _chunkU54EW4DXcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
3074
3070
  }
3075
3071
  /** Shared by drain, settle and autoclose; bad knobs throw at build. */
3076
3072
  _build_breaker(options) {
3077
3073
  return new CircuitBreaker(
3078
- _chunkP3B7HVFDcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
3074
+ _chunkU54EW4DXcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
3079
3075
  {
3080
3076
  on_error: (error, circuit) => this._emit_error(error, circuit),
3081
3077
  // When the cooldown elapses, settle once: its scan or claim is the
@@ -3109,7 +3105,7 @@ var Act = (_class7 = class {
3109
3105
  try {
3110
3106
  await this._run_close(targets);
3111
3107
  } catch (error) {
3112
- if (error instanceof _chunkAVXVMZ4Bcjs.StoreError) throw error;
3108
+ if (error instanceof _chunkPMS6BMIUcjs.StoreError) throw error;
3113
3109
  this._logger.error(
3114
3110
  error,
3115
3111
  `Reaction-requested close of ${targets.map((t) => `"${t.stream}"`).join(", ")} failed and was not retried; close it with app.close(...) once the cause is fixed.`
@@ -3124,7 +3120,7 @@ var Act = (_class7 = class {
3124
3120
  leaseMillis: cfg.leaseMillis
3125
3121
  }
3126
3122
  });
3127
- if (_optionalChain([cfg, 'optionalAccess', _125 => _125.cycleMs]) !== void 0 && options.drain !== false)
3123
+ if (_optionalChain([cfg, 'optionalAccess', _123 => _123.cycleMs]) !== void 0 && options.drain !== false)
3128
3124
  controller.start(cfg.cycleMs);
3129
3125
  controllers.set(name, controller);
3130
3126
  }
@@ -3144,7 +3140,7 @@ var Act = (_class7 = class {
3144
3140
  /** Audit deps, built after the controllers so the lane set is final. */
3145
3141
  _build_audit_deps() {
3146
3142
  return {
3147
- store: _chunkP3B7HVFDcjs.store,
3143
+ store: _chunkU54EW4DXcjs.store,
3148
3144
  event_to_state: this._event_to_state,
3149
3145
  // Declared lanes, not this process's controllers: a lane another
3150
3146
  // worker drains is not `unknown-lane`.
@@ -3157,7 +3153,7 @@ var Act = (_class7 = class {
3157
3153
  registry: this.registry,
3158
3154
  static_targets: classification.static_targets,
3159
3155
  cd: this._cd,
3160
- max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => ( _chunkAVXVMZ4Bcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS)),
3156
+ max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => ( _chunkPMS6BMIUcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS)),
3161
3157
  // Declared lanes (not active ones): a lane another process claims is
3162
3158
  // still a valid destination.
3163
3159
  declared_lanes: new Set(this._declared_lanes),
@@ -3173,18 +3169,16 @@ var Act = (_class7 = class {
3173
3169
  /** Cold start: an idle deferred stream still fires on time after a restart. */
3174
3170
  async _seed_persisted_defers() {
3175
3171
  const now = Date.now();
3176
- await walk_streams(_chunkP3B7HVFDcjs.store.call(void 0, ), (pos) => {
3172
+ await walk_streams(_chunkU54EW4DXcjs.store.call(void 0, ), (pos) => {
3177
3173
  if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
3178
3174
  const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
3179
- _optionalChain([controller, 'optionalAccess', _126 => _126.seed_defer, 'call', _127 => _127(pos.stream, pos.deferred_at)]);
3175
+ _optionalChain([controller, 'optionalAccess', _124 => _124.seed_defer, 'call', _125 => _125(pos.stream, pos.deferred_at)]);
3180
3176
  });
3181
3177
  }
3182
3178
  _build_settle(options) {
3183
3179
  return new SettleLoop(
3184
3180
  {
3185
- init: () => this._scoped(() => this._correlate.init()),
3186
- checkpoint: () => this._correlate.checkpoint,
3187
- correlate: (q) => this._correlate_scanned(
3181
+ correlate: (q) => this._correlate_pass(
3188
3182
  { ...q, limit: _nullishCoalesce(_nullishCoalesce(q.limit, () => ( this._poll_limit)), () => ( 100)) },
3189
3183
  true
3190
3184
  ),
@@ -3194,7 +3188,7 @@ var Act = (_class7 = class {
3194
3188
  on_settled: (drain) => this.emit("settled", drain),
3195
3189
  breaker: this._breaker
3196
3190
  },
3197
- _nullishCoalesce(options.settleDebounceMs, () => ( _chunkAVXVMZ4Bcjs.DEFAULT_SETTLE_DEBOUNCE_MS))
3191
+ _nullishCoalesce(options.settleDebounceMs, () => ( _chunkPMS6BMIUcjs.DEFAULT_SETTLE_DEBOUNCE_MS))
3198
3192
  );
3199
3193
  }
3200
3194
 
@@ -3214,7 +3208,7 @@ var Act = (_class7 = class {
3214
3208
  */
3215
3209
  shutdown(options) {
3216
3210
  if (!this._shutdown_promise) {
3217
- _chunkP3B7HVFDcjs.resolveShutdownConfig.call(void 0, options);
3211
+ _chunkU54EW4DXcjs.resolveShutdownConfig.call(void 0, options);
3218
3212
  this._shutdown_promise = (async () => {
3219
3213
  this.stop_correlations();
3220
3214
  this._settle.stop(true);
@@ -3222,7 +3216,7 @@ var Act = (_class7 = class {
3222
3216
  for (const c of this._drain_controllers.values()) c.stop();
3223
3217
  const disposer = await this._notify_disposer;
3224
3218
  if (disposer) await disposer();
3225
- await this._await_inflight(_optionalChain([options, 'optionalAccess', _128 => _128.graceMs]));
3219
+ await this._await_inflight(_optionalChain([options, 'optionalAccess', _126 => _126.graceMs]));
3226
3220
  await this._scoped(() => this._correlate.release_correlation());
3227
3221
  this._emitter.removeAllListeners();
3228
3222
  })();
@@ -3234,10 +3228,10 @@ var Act = (_class7 = class {
3234
3228
  * default for none or 0, and for a running settle), capped.
3235
3229
  */
3236
3230
  _derive_grace_ms(running, settling) {
3237
- let max = settling ? _chunkP3B7HVFDcjs.DEFAULT_LEASE_MILLIS : 0;
3231
+ let max = settling ? _chunkU54EW4DXcjs.DEFAULT_LEASE_MILLIS : 0;
3238
3232
  for (const c of running)
3239
- max = Math.max(max, c.lease_millis || _chunkP3B7HVFDcjs.DEFAULT_LEASE_MILLIS);
3240
- return Math.min(max, _chunkP3B7HVFDcjs.MAX_SHUTDOWN_GRACE_MS);
3233
+ max = Math.max(max, c.lease_millis || _chunkU54EW4DXcjs.DEFAULT_LEASE_MILLIS);
3234
+ return Math.min(max, _chunkU54EW4DXcjs.MAX_SHUTDOWN_GRACE_MS);
3241
3235
  }
3242
3236
  async _await_inflight(grace_ms) {
3243
3237
  const running = [...this._drain_controllers.values()].filter(
@@ -3247,15 +3241,16 @@ var Act = (_class7 = class {
3247
3241
  if (running.length === 0 && !settling) return;
3248
3242
  const grace = _nullishCoalesce(grace_ms, () => ( this._derive_grace_ms(running, !!settling)));
3249
3243
  if (grace <= 0) return;
3250
- const inflight = running.map((c) => c.inflight);
3251
- if (settling) inflight.push(settling);
3252
3244
  let timer;
3253
3245
  const budget = new Promise((resolve) => {
3254
3246
  timer = setTimeout(resolve, grace);
3255
3247
  timer.unref();
3256
3248
  });
3257
3249
  try {
3258
- await Promise.race([Promise.all(inflight), budget]);
3250
+ await Promise.race([
3251
+ Promise.all([...running.map((c) => c.inflight), settling]),
3252
+ budget
3253
+ ]);
3259
3254
  } finally {
3260
3255
  clearTimeout(timer);
3261
3256
  }
@@ -3317,8 +3312,8 @@ var Act = (_class7 = class {
3317
3312
  * @see {@link ValidationError}, {@link InvariantError}, {@link ConcurrencyError}
3318
3313
  */
3319
3314
  async do(action2, target, payload, options) {
3320
- const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _129 => _129.reactingTo]), () => ( _chunkP3B7HVFDcjs.current_reacting.call(void 0, )));
3321
- const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _130 => _130.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3315
+ const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.reactingTo]), () => ( _chunkU54EW4DXcjs.current_reacting.call(void 0, )));
3316
+ const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _128 => _128.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
3322
3317
  return this._scoped(async () => {
3323
3318
  const snapshots = await this._es.action(
3324
3319
  this.registry.actions[action2],
@@ -3378,11 +3373,11 @@ var Act = (_class7 = class {
3378
3373
  return this._scoped(async () => {
3379
3374
  let first;
3380
3375
  let last;
3381
- const count = await _chunkP3B7HVFDcjs.store.call(void 0, ).query((e) => {
3376
+ const count = await _chunkU54EW4DXcjs.store.call(void 0, ).query((e) => {
3382
3377
  const gated = this.registry.query_gate(e.name)(e);
3383
3378
  if (!first) first = gated;
3384
3379
  last = gated;
3385
- _optionalChain([callback, 'optionalCall', _131 => _131(gated)]);
3380
+ _optionalChain([callback, 'optionalCall', _129 => _129(gated)]);
3386
3381
  }, query);
3387
3382
  return { first, last, count };
3388
3383
  });
@@ -3408,7 +3403,7 @@ var Act = (_class7 = class {
3408
3403
  async query_array(query) {
3409
3404
  return this._scoped(async () => {
3410
3405
  const events = [];
3411
- await _chunkP3B7HVFDcjs.store.call(void 0, ).query((e) => {
3406
+ await _chunkU54EW4DXcjs.store.call(void 0, ).query((e) => {
3412
3407
  events.push(this.registry.query_gate(e.name)(e));
3413
3408
  }, query);
3414
3409
  return events;
@@ -3428,14 +3423,14 @@ var Act = (_class7 = class {
3428
3423
  */
3429
3424
  async forget(stream) {
3430
3425
  return this._scoped(async () => {
3431
- const s = _chunkP3B7HVFDcjs.store.call(void 0, );
3426
+ const s = _chunkU54EW4DXcjs.store.call(void 0, );
3432
3427
  if (!s.forget_pii) {
3433
3428
  throw new Error(
3434
3429
  `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).`
3435
3430
  );
3436
3431
  }
3437
3432
  const eventCount = await s.forget_pii(stream);
3438
- await _chunkP3B7HVFDcjs.cache.call(void 0, ).invalidate(stream);
3433
+ await _chunkU54EW4DXcjs.cache.call(void 0, ).invalidate(stream);
3439
3434
  if (eventCount > 0) {
3440
3435
  this.emit("forgotten", { stream, at: /* @__PURE__ */ new Date(), eventCount });
3441
3436
  }
@@ -3469,7 +3464,7 @@ var Act = (_class7 = class {
3469
3464
  * @see {@link correlate} for dynamic stream discovery
3470
3465
  */
3471
3466
  async drain(options = {}) {
3472
- _chunkP3B7HVFDcjs.resolveDrainConfig.call(void 0, options);
3467
+ _chunkU54EW4DXcjs.resolveDrainConfig.call(void 0, options);
3473
3468
  if (!this._drain)
3474
3469
  return { fetched: [], leased: [], acked: [], blocked: [] };
3475
3470
  return this._scoped(() => this._drain_all(options));
@@ -3509,32 +3504,25 @@ var Act = (_class7 = class {
3509
3504
  }
3510
3505
  if (to_arm.size === 0) return false;
3511
3506
  this._correlate.arm();
3512
- for (const lane of to_arm) _optionalChain([this, 'access', _132 => _132._drain_controllers, 'access', _133 => _133.get, 'call', _134 => _134(lane), 'optionalAccess', _135 => _135.arm, 'call', _136 => _136()]);
3507
+ for (const lane of to_arm) _optionalChain([this, 'access', _130 => _130._drain_controllers, 'access', _131 => _131.get, 'call', _132 => _132(lane), 'optionalAccess', _133 => _133.arm, 'call', _134 => _134()]);
3513
3508
  return true;
3514
3509
  }
3515
3510
  /** In parallel, so a slow lane never holds up a fast one. */
3516
3511
  async _drain_all(options) {
3517
- const results = await Promise.all(
3518
- [...this._drain_controllers.values()].map((c) => c.drain(options))
3512
+ const merged = merge_drains(
3513
+ await Promise.all(
3514
+ [...this._drain_controllers.values()].map((c) => c.drain(options))
3515
+ )
3519
3516
  );
3520
- const fetched = [];
3521
- const leased = [];
3522
- const acked = [];
3523
- const blocked = [];
3524
- for (const r of results) {
3525
- fetched.push(
3526
- ...r.fetched.map((f) => ({
3527
- ...f,
3528
- events: f.events.map(
3529
- (e) => this.registry.query_gate(e.name)(e)
3530
- )
3531
- }))
3532
- );
3533
- leased.push(...r.leased);
3534
- acked.push(...r.acked);
3535
- blocked.push(...r.blocked);
3536
- }
3537
- return { fetched, leased, acked, blocked };
3517
+ return {
3518
+ ...merged,
3519
+ fetched: merged.fetched.map((f) => ({
3520
+ ...f,
3521
+ events: f.events.map(
3522
+ (e) => this.registry.query_gate(e.name)(e)
3523
+ )
3524
+ }))
3525
+ };
3538
3526
  }
3539
3527
  /**
3540
3528
  * Scans committed events from the correlation checkpoint, subscribes the
@@ -3553,16 +3541,20 @@ var Act = (_class7 = class {
3553
3541
  * @see {@link start_correlations} for automatic periodic correlation
3554
3542
  */
3555
3543
  async correlate(query = { after: -1, limit: 10 }) {
3556
- const { subscribed, last_id } = await this._correlate_scanned(query);
3557
- return { subscribed, last_id };
3544
+ const pass = await this._correlate_pass(query);
3545
+ return {
3546
+ subscribed: pass.kind === "scanned" ? pass.subscribed : 0,
3547
+ last_id: pass.last_id
3548
+ };
3558
3549
  }
3559
- /** `correlate` plus `scanned`, which settle needs for the breaker. */
3560
- async _correlate_scanned(query, lease = false) {
3561
- if (!this._drain) return { subscribed: 0, last_id: -1, scanned: false };
3550
+ /** One correlate pass; arms every lane when it found work. */
3551
+ async _correlate_pass(query, lease = false) {
3552
+ if (!this._drain) return { kind: "idle", last_id: -1 };
3562
3553
  return this._scoped(async () => {
3563
- const { subscribed, last_id, marked, scanned } = await this._correlate.correlate(query, lease);
3564
- if (subscribed > 0 || marked > 0) this._arm_all();
3565
- return { subscribed, last_id, scanned };
3554
+ const pass = await this._correlate.correlate(query, lease);
3555
+ if (pass.kind === "scanned" && (pass.subscribed > 0 || pass.marked > 0))
3556
+ this._arm_all();
3557
+ return pass;
3566
3558
  });
3567
3559
  }
3568
3560
  /**
@@ -3652,9 +3644,9 @@ var Act = (_class7 = class {
3652
3644
  */
3653
3645
  async reset(input) {
3654
3646
  return this._scoped(async () => {
3655
- const count = await _chunkP3B7HVFDcjs.store.call(void 0, ).reset(input);
3647
+ const count = await _chunkU54EW4DXcjs.store.call(void 0, ).reset(input);
3656
3648
  for (const handler of this._batch_handlers.values())
3657
- _optionalChain([handler, 'access', _137 => _137[FOLD_RESET], 'optionalCall', _138 => _138()]);
3649
+ _optionalChain([handler, 'access', _135 => _135[FOLD_RESET], 'optionalCall', _136 => _136()]);
3658
3650
  if (count > 0) {
3659
3651
  this._wake();
3660
3652
  }
@@ -3688,7 +3680,7 @@ var Act = (_class7 = class {
3688
3680
  */
3689
3681
  async unblock(input) {
3690
3682
  return this._scoped(async () => {
3691
- const count = await _chunkP3B7HVFDcjs.store.call(void 0, ).unblock(input);
3683
+ const count = await _chunkU54EW4DXcjs.store.call(void 0, ).unblock(input);
3692
3684
  if (count > 0) {
3693
3685
  this._wake();
3694
3686
  }
@@ -3737,7 +3729,7 @@ var Act = (_class7 = class {
3737
3729
  return { ...partial, duration_ms: Date.now() - started };
3738
3730
  }
3739
3731
  const target = _nullishCoalesce(sink, () => ( (() => {
3740
- const s = _chunkP3B7HVFDcjs.store.call(void 0, );
3732
+ const s = _chunkU54EW4DXcjs.store.call(void 0, );
3741
3733
  if (!s.restore) throw new Error("adapter has no restore capability");
3742
3734
  return s;
3743
3735
  })()));
@@ -3782,11 +3774,11 @@ var Act = (_class7 = class {
3782
3774
  async blocked_streams(options) {
3783
3775
  return this._scoped(async () => {
3784
3776
  const positions = [];
3785
- await _chunkP3B7HVFDcjs.store.call(void 0, ).query_streams(
3777
+ await _chunkU54EW4DXcjs.store.call(void 0, ).query_streams(
3786
3778
  (p) => {
3787
3779
  positions.push(p);
3788
3780
  },
3789
- { blocked: true, after: _optionalChain([options, 'optionalAccess', _139 => _139.after]), limit: _optionalChain([options, 'optionalAccess', _140 => _140.limit]) }
3781
+ { blocked: true, after: _optionalChain([options, 'optionalAccess', _137 => _137.after]), limit: _optionalChain([options, 'optionalAccess', _138 => _138.limit]) }
3790
3782
  );
3791
3783
  return positions;
3792
3784
  });
@@ -3834,7 +3826,7 @@ var Act = (_class7 = class {
3834
3826
  * @see {@link Store.prioritize} for the underlying primitive
3835
3827
  */
3836
3828
  async prioritize(filter, priority) {
3837
- return this._scoped(() => _chunkP3B7HVFDcjs.store.call(void 0, ).prioritize(filter, priority));
3829
+ return this._scoped(() => _chunkU54EW4DXcjs.store.call(void 0, ).prioritize(filter, priority));
3838
3830
  }
3839
3831
  /** Shared by `close()` and reaction-requested closes. */
3840
3832
  async _run_close(targets) {
@@ -3914,7 +3906,7 @@ var Act = (_class7 = class {
3914
3906
  * @see {@link correlate} for manual correlation
3915
3907
  */
3916
3908
  settle(options) {
3917
- _chunkP3B7HVFDcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
3909
+ _chunkU54EW4DXcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
3918
3910
  this._schedule(options);
3919
3911
  }
3920
3912
  }, _class7);
@@ -3980,12 +3972,12 @@ function policy_min_after_days(options) {
3980
3972
  const parsed = AutoclosePolicySchema.parse(options);
3981
3973
  const windows = [];
3982
3974
  if (parsed.after) windows.push(parsed.after.days);
3983
- if (_optionalChain([parsed, 'access', _141 => _141.or, 'optionalAccess', _142 => _142.after])) windows.push(parsed.or.after.days);
3975
+ if (_optionalChain([parsed, 'access', _139 => _139.or, 'optionalAccess', _140 => _140.after])) windows.push(parsed.or.after.days);
3984
3976
  return windows.length ? Math.min(...windows) : void 0;
3985
3977
  }
3986
3978
  function policy_keep_days(options) {
3987
3979
  const parsed = AutoclosePolicySchema.parse(options);
3988
- return _optionalChain([parsed, 'access', _143 => _143.keep, 'optionalAccess', _144 => _144.days]);
3980
+ return _optionalChain([parsed, 'access', _141 => _141.keep, 'optionalAccess', _142 => _142.days]);
3989
3981
  }
3990
3982
  function compile_autoclose_policy(options) {
3991
3983
  const parsed = AutoclosePolicySchema.parse(options);
@@ -4017,7 +4009,7 @@ function hour_in_zone(now, timeZone) {
4017
4009
  hour: "2-digit",
4018
4010
  hourCycle: "h23"
4019
4011
  }).formatToParts(now);
4020
- return Number(_optionalChain([parts, 'access', _145 => _145.find, 'call', _146 => _146((p) => p.type === "hour"), 'optionalAccess', _147 => _147.value]));
4012
+ return Number(_optionalChain([parts, 'access', _143 => _143.find, 'call', _144 => _144((p) => p.type === "hour"), 'optionalAccess', _145 => _145.value]));
4021
4013
  }
4022
4014
  function hour_in_range(hour, start, end) {
4023
4015
  return start < end ? hour >= start && hour < end : hour >= start || hour < end;
@@ -4070,16 +4062,16 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
4070
4062
  }),
4071
4063
  // Never block on autoclose: a transient query/store error should retry,
4072
4064
  // not quarantine the synthetic stream.
4073
- options: { blockOnError: false, maxRetries: _chunkP3B7HVFDcjs.DEFAULT_MAX_RETRIES },
4065
+ options: { blockOnError: false, maxRetries: _chunkU54EW4DXcjs.DEFAULT_MAX_RETRIES },
4074
4066
  handler: async (event) => {
4075
4067
  const aggregate = event.stream;
4076
4068
  const window = read_window();
4077
4069
  if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
4078
- throw new (0, _chunkAVXVMZ4Bcjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
4079
- const stats = await _chunkP3B7HVFDcjs.store.call(void 0, ).query_stats([aggregate], {
4070
+ throw new (0, _chunkPMS6BMIUcjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
4071
+ const stats = await _chunkU54EW4DXcjs.store.call(void 0, ).query_stats([aggregate], {
4080
4072
  count: true,
4081
4073
  tail: keep_days !== void 0 ? true : void 0,
4082
- exclude: [_chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT, _chunkAVXVMZ4Bcjs.SNAP_EVENT]
4074
+ exclude: [_chunkPMS6BMIUcjs.TOMBSTONE_EVENT, _chunkPMS6BMIUcjs.SNAP_EVENT]
4083
4075
  });
4084
4076
  const entry = stats.get(aggregate);
4085
4077
  if (!entry) return;
@@ -4110,12 +4102,12 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
4110
4102
  dues.push(days_after(entry.tail.created, keep_days));
4111
4103
  const future = dues.map((d) => d.getTime()).filter((t) => t > Date.now());
4112
4104
  if (future.length)
4113
- throw new (0, _chunkAVXVMZ4Bcjs.DeferSignal)({ at: new Date(Math.min(...future)) });
4105
+ throw new (0, _chunkPMS6BMIUcjs.DeferSignal)({ at: new Date(Math.min(...future)) });
4114
4106
  }
4115
4107
  };
4116
4108
  const key = `__autoclose_${st.name}`;
4117
4109
  for (const event_name of Object.keys(st.events)) {
4118
- _optionalChain([registry, 'access', _148 => _148.events, 'access', _149 => _149[event_name], 'optionalAccess', _150 => _150.reactions, 'access', _151 => _151.set, 'call', _152 => _152(
4110
+ _optionalChain([registry, 'access', _146 => _146.events, 'access', _147 => _147[event_name], 'optionalAccess', _148 => _148.reactions, 'access', _149 => _149.set, 'call', _150 => _150(
4119
4111
  key,
4120
4112
  reaction
4121
4113
  )]);
@@ -4314,9 +4306,9 @@ var _this_ = ({ stream }) => ({
4314
4306
 
4315
4307
  // src/builders/builder-utils.ts
4316
4308
  function register_lane(config2, lanes) {
4317
- _chunkP3B7HVFDcjs.resolveLaneConfig.call(void 0, config2);
4318
- if (config2.name === _chunkAVXVMZ4Bcjs.DEFAULT_LANE)
4319
- throw new Error(`Lane "${_chunkAVXVMZ4Bcjs.DEFAULT_LANE}" is reserved`);
4309
+ _chunkU54EW4DXcjs.resolveLaneConfig.call(void 0, config2);
4310
+ if (config2.name === _chunkPMS6BMIUcjs.DEFAULT_LANE)
4311
+ throw new Error(`Lane "${_chunkPMS6BMIUcjs.DEFAULT_LANE}" is reserved`);
4320
4312
  const existing = lanes.find((l) => l.name === config2.name);
4321
4313
  if (!existing) return void lanes.push(config2);
4322
4314
  if (existing.leaseMillis !== config2.leaseMillis || existing.streamLimit !== config2.streamLimit || existing.cycleMs !== config2.cycleMs)
@@ -4358,10 +4350,10 @@ function reaction_on(event, events, builder) {
4358
4350
  // Validate the whole bag at the declaration site so a bad
4359
4351
  // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
4360
4352
  // not a NaN gate on the first retry.
4361
- options: _chunkP3B7HVFDcjs.resolveReactionConfig.call(void 0, {
4362
- blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _153 => _153.blockOnError]), () => ( _chunkP3B7HVFDcjs.DEFAULT_BLOCK_ON_ERROR)),
4363
- maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _154 => _154.maxRetries]), () => ( _chunkP3B7HVFDcjs.DEFAULT_MAX_RETRIES)),
4364
- backoff: _optionalChain([options, 'optionalAccess', _155 => _155.backoff])
4353
+ options: _chunkU54EW4DXcjs.resolveReactionConfig.call(void 0, {
4354
+ blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _151 => _151.blockOnError]), () => ( _chunkU54EW4DXcjs.DEFAULT_BLOCK_ON_ERROR)),
4355
+ maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _152 => _152.maxRetries]), () => ( _chunkU54EW4DXcjs.DEFAULT_MAX_RETRIES)),
4356
+ backoff: _optionalChain([options, 'optionalAccess', _153 => _153.backoff])
4365
4357
  })
4366
4358
  };
4367
4359
  },
@@ -4380,9 +4372,9 @@ function reaction_on(event, events, builder) {
4380
4372
 
4381
4373
  // src/internal/date-reviver.ts
4382
4374
 
4383
- var def_of = (schema) => _nullishCoalesce(_optionalChain([schema, 'access', _156 => _156._zod, 'optionalAccess', _157 => _157.def]), () => ( schema.def));
4375
+ var def_of = (schema) => _nullishCoalesce(_optionalChain([schema, 'access', _154 => _154._zod, 'optionalAccess', _155 => _155.def]), () => ( schema.def));
4384
4376
  function variant_schema(schema) {
4385
- const shape = _optionalChain([def_of, 'call', _158 => _158(schema), 'optionalAccess', _159 => _159.shape]);
4377
+ const shape = _optionalChain([def_of, 'call', _156 => _156(schema), 'optionalAccess', _157 => _157.shape]);
4386
4378
  if (!shape) {
4387
4379
  const dates = date_reviver_schema(schema);
4388
4380
  return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
@@ -4430,7 +4422,7 @@ function date_reviver_schema(schema) {
4430
4422
  return variants.some((v) => v.dated) ? _zod2.z.union(variants.map((v) => v.schema)) : void 0;
4431
4423
  }
4432
4424
  case "nullable":
4433
- return _optionalChain([inner, 'call', _160 => _160(), 'optionalAccess', _161 => _161.nullable, 'call', _162 => _162()]);
4425
+ return _optionalChain([inner, 'call', _158 => _158(), 'optionalAccess', _159 => _159.nullable, 'call', _160 => _160()]);
4434
4426
  case "optional":
4435
4427
  case "nonoptional":
4436
4428
  case "readonly":
@@ -4445,7 +4437,7 @@ function date_reviver_schema(schema) {
4445
4437
 
4446
4438
  // src/builders/event-builder.ts
4447
4439
  function event_tags(schema) {
4448
- const pii = _chunkAVXVMZ4Bcjs.pii_schemas.call(void 0, schema);
4440
+ const pii = _chunkPMS6BMIUcjs.pii_schemas.call(void 0, schema);
4449
4441
  const pii_dates = {};
4450
4442
  for (const [key, field] of Object.entries(pii)) {
4451
4443
  const dates = date_reviver_schema(field);
@@ -4482,7 +4474,7 @@ function make_event_reader(tags, disclosure, predicate = null) {
4482
4474
  });
4483
4475
  }
4484
4476
  function build_events(registry, states, lanes, owners) {
4485
- const declared = /* @__PURE__ */ new Set([_chunkAVXVMZ4Bcjs.DEFAULT_LANE, ...lanes.map((l) => l.name)]);
4477
+ const declared = /* @__PURE__ */ new Set([_chunkPMS6BMIUcjs.DEFAULT_LANE, ...lanes.map((l) => l.name)]);
4486
4478
  const lane_errors = [];
4487
4479
  const tags = /* @__PURE__ */ new Map();
4488
4480
  const sensitive2 = /* @__PURE__ */ new Map();
@@ -4546,7 +4538,7 @@ function build_events(registry, states, lanes, owners) {
4546
4538
  if (reader) readers.set(event_name, reader);
4547
4539
  }
4548
4540
  const snap2 = make_event_reader(event_tags(state2.state), "redact", null);
4549
- if (snap2) readers.set(_chunkAVXVMZ4Bcjs.SNAP_EVENT, snap2);
4541
+ if (snap2) readers.set(_chunkPMS6BMIUcjs.SNAP_EVENT, snap2);
4550
4542
  if (readers.size === 0) continue;
4551
4543
  state2.view = (event, actor) => (_nullishCoalesce(readers.get(event.name), () => ( IDENTITY_GATE)))(event, actor);
4552
4544
  }
@@ -4607,7 +4599,7 @@ function act() {
4607
4599
  let _built = false;
4608
4600
  const read_wrap = (original) => {
4609
4601
  const wrapped = async (events, stream) => {
4610
- const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _163 => _163.get, 'call', _164 => _164(e.name), 'optionalCall', _165 => _165(e)]), () => ( e)));
4602
+ const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _161 => _161.get, 'call', _162 => _162(e.name), 'optionalCall', _163 => _163(e)]), () => ( e)));
4611
4603
  return original(read, stream);
4612
4604
  };
4613
4605
  const reset = original[FOLD_RESET];
@@ -4649,7 +4641,7 @@ function act() {
4649
4641
  });
4650
4642
  }
4651
4643
  for (const [action_name, handler] of Object.entries(state2.on)) {
4652
- const static_target = _optionalChain([handler, 'optionalAccess', _166 => _166._static_emit]);
4644
+ const static_target = _optionalChain([handler, 'optionalAccess', _164 => _164._static_emit]);
4653
4645
  if (static_target && deprecated.has(static_target)) {
4654
4646
  const current = current_version_of(static_target, event_names);
4655
4647
  throw new Error(
@@ -4662,7 +4654,7 @@ function act() {
4662
4654
  const list = deprecation_summary.map(
4663
4655
  (d) => `"${d.deprecated}" (current: "${d.current}", state: "${d.state_name}")`
4664
4656
  ).join(", ");
4665
- _chunkP3B7HVFDcjs.log.call(void 0, ).info(
4657
+ _chunkU54EW4DXcjs.log.call(void 0, ).info(
4666
4658
  `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.`
4667
4659
  );
4668
4660
  }
@@ -4704,8 +4696,8 @@ function act() {
4704
4696
  return reaction_on(event, registry.events, builder);
4705
4697
  },
4706
4698
  build: (options) => {
4707
- _chunkP3B7HVFDcjs.resolveActConfig.call(void 0, options);
4708
- const patch_fn = _optionalChain([options, 'optionalAccess', _167 => _167.validateFoldedState]) === true ? validating_patch : bare_patch;
4699
+ _chunkU54EW4DXcjs.resolveActConfig.call(void 0, options);
4700
+ const patch_fn = _optionalChain([options, 'optionalAccess', _165 => _165.validateFoldedState]) === true ? validating_patch : bare_patch;
4709
4701
  if (!_built) {
4710
4702
  for (const proj of pending_projections) add_projection(proj);
4711
4703
  for (const proj of fold_projections) {
@@ -4723,7 +4715,7 @@ function act() {
4723
4715
  `State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
4724
4716
  );
4725
4717
  const claimed = fold_specs.find((s) => s.target === proj.target);
4726
- if (_optionalChain([claimed, 'optionalAccess', _168 => _168.projection]) === proj) continue;
4718
+ if (_optionalChain([claimed, 'optionalAccess', _166 => _166.projection]) === proj) continue;
4727
4719
  if (batch_handlers.has(proj.target) || claimed)
4728
4720
  throw new Error(
4729
4721
  `Duplicate projection target "${proj.target}" \u2014 a target is served by one batch handler or one state projection, never both`
@@ -4756,7 +4748,7 @@ function act() {
4756
4748
  synthesize_autoclose_reactions(
4757
4749
  registry,
4758
4750
  states,
4759
- _chunkP3B7HVFDcjs.current_autoclose_window
4751
+ _chunkU54EW4DXcjs.current_autoclose_window
4760
4752
  );
4761
4753
  Object.freeze(registry.actions);
4762
4754
  Object.freeze(registry.events);
@@ -4805,8 +4797,8 @@ function _projection(target) {
4805
4797
  handler,
4806
4798
  resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
4807
4799
  options: {
4808
- blockOnError: _chunkP3B7HVFDcjs.DEFAULT_BLOCK_ON_ERROR,
4809
- maxRetries: _chunkP3B7HVFDcjs.DEFAULT_MAX_RETRIES
4800
+ blockOnError: _chunkU54EW4DXcjs.DEFAULT_BLOCK_ON_ERROR,
4801
+ maxRetries: _chunkU54EW4DXcjs.DEFAULT_MAX_RETRIES
4810
4802
  }
4811
4803
  }),
4812
4804
  widened
@@ -4847,7 +4839,7 @@ function _projection(target) {
4847
4839
  throw new Error(
4848
4840
  `Projection "${target}" .of() partials must share one state name \u2014 got "${name}" and "${partial.name}"`
4849
4841
  );
4850
- const config2 = _chunkP3B7HVFDcjs.resolveFoldConfig.call(void 0, options);
4842
+ const config2 = _chunkU54EW4DXcjs.resolveFoldConfig.call(void 0, options);
4851
4843
  const fold_events = {};
4852
4844
  for (const partial of partials)
4853
4845
  for (const [event_name, schema] of Object.entries(partial.events)) {
@@ -4865,8 +4857,8 @@ function _projection(target) {
4865
4857
  handler: noop,
4866
4858
  resolver: { target },
4867
4859
  options: {
4868
- blockOnError: _chunkP3B7HVFDcjs.DEFAULT_BLOCK_ON_ERROR,
4869
- maxRetries: _chunkP3B7HVFDcjs.DEFAULT_MAX_RETRIES
4860
+ blockOnError: _chunkU54EW4DXcjs.DEFAULT_BLOCK_ON_ERROR,
4861
+ maxRetries: _chunkU54EW4DXcjs.DEFAULT_MAX_RETRIES
4870
4862
  }
4871
4863
  }
4872
4864
  ]
@@ -4982,7 +4974,7 @@ function action_builder(state2) {
4982
4974
  throw new Error(`Duplicate action "${action2}"`);
4983
4975
  internal.actions[action2] = schema;
4984
4976
  if (options) {
4985
- _chunkP3B7HVFDcjs.resolveActionConfig.call(void 0, options);
4977
+ _chunkU54EW4DXcjs.resolveActionConfig.call(void 0, options);
4986
4978
  internal.options ??= {};
4987
4979
  internal.options[action2] = options;
4988
4980
  }
@@ -5271,5 +5263,5 @@ function write_line(writer, line) {
5271
5263
 
5272
5264
 
5273
5265
 
5274
- exports.Act = Act; exports.ActorSchema = _chunkAVXVMZ4Bcjs.ActorSchema; exports.CausationEventSchema = _chunkAVXVMZ4Bcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkAVXVMZ4Bcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkAVXVMZ4Bcjs.ConcurrencyError; exports.ConsoleLogger = _chunkP3B7HVFDcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunkAVXVMZ4Bcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunkAVXVMZ4Bcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunkAVXVMZ4Bcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunkAVXVMZ4Bcjs.DeferSignal; exports.Environments = _chunkAVXVMZ4Bcjs.Environments; exports.Errors = _chunkAVXVMZ4Bcjs.Errors; exports.EventMetaSchema = _chunkAVXVMZ4Bcjs.EventMetaSchema; exports.ExitCodes = _chunkAVXVMZ4Bcjs.ExitCodes; exports.InMemoryCache = _chunkP3B7HVFDcjs.InMemoryCache; exports.InMemoryStore = _chunkP3B7HVFDcjs.InMemoryStore; exports.InvariantError = _chunkAVXVMZ4Bcjs.InvariantError; exports.LogLevels = _chunkAVXVMZ4Bcjs.LogLevels; exports.NonRetryableError = _chunkAVXVMZ4Bcjs.NonRetryableError; exports.PackageSchema = _chunkP3B7HVFDcjs.PackageSchema; exports.QuerySchema = _chunkAVXVMZ4Bcjs.QuerySchema; exports.REDACTED = _chunkAVXVMZ4Bcjs.REDACTED; exports.SHREDDED = _chunkAVXVMZ4Bcjs.SHREDDED; exports.SNAP_EVENT = _chunkAVXVMZ4Bcjs.SNAP_EVENT; exports.StoreError = _chunkAVXVMZ4Bcjs.StoreError; exports.StreamClosedError = _chunkAVXVMZ4Bcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunkAVXVMZ4Bcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunkAVXVMZ4Bcjs.TargetSchema; exports.ValidationError = _chunkAVXVMZ4Bcjs.ValidationError; exports.ZodEmpty = _chunkAVXVMZ4Bcjs.ZodEmpty; exports.act = act; exports.cache = _chunkP3B7HVFDcjs.cache; exports.config = _chunkP3B7HVFDcjs.config; exports.dateReviver = _chunkP3B7HVFDcjs.dateReviver; exports.default_scope = _chunkP3B7HVFDcjs.default_scope; exports.dispose = _chunkP3B7HVFDcjs.dispose; exports.disposeAndExit = _chunkP3B7HVFDcjs.disposeAndExit; exports.extend = _chunkP3B7HVFDcjs.extend; exports.is_literal_source = _chunkP3B7HVFDcjs.is_literal_source; exports.log = _chunkP3B7HVFDcjs.log; exports.pii_fields = _chunkAVXVMZ4Bcjs.pii_fields; exports.port = _chunkP3B7HVFDcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkP3B7HVFDcjs.resolveAutocloseConfig2; exports.sensitive = _chunkAVXVMZ4Bcjs.sensitive; exports.sleep = _chunkP3B7HVFDcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkP3B7HVFDcjs.store; exports.validate = _chunkP3B7HVFDcjs.validate;
5266
+ exports.Act = Act; exports.ActorSchema = _chunkPMS6BMIUcjs.ActorSchema; exports.CausationEventSchema = _chunkPMS6BMIUcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkPMS6BMIUcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkPMS6BMIUcjs.ConcurrencyError; exports.ConsoleLogger = _chunkU54EW4DXcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunkPMS6BMIUcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunkPMS6BMIUcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunkPMS6BMIUcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunkPMS6BMIUcjs.DeferSignal; exports.Environments = _chunkPMS6BMIUcjs.Environments; exports.Errors = _chunkPMS6BMIUcjs.Errors; exports.EventMetaSchema = _chunkPMS6BMIUcjs.EventMetaSchema; exports.ExitCodes = _chunkPMS6BMIUcjs.ExitCodes; exports.InMemoryCache = _chunkU54EW4DXcjs.InMemoryCache; exports.InMemoryStore = _chunkU54EW4DXcjs.InMemoryStore; exports.InvariantError = _chunkPMS6BMIUcjs.InvariantError; exports.LogLevels = _chunkPMS6BMIUcjs.LogLevels; exports.NonRetryableError = _chunkPMS6BMIUcjs.NonRetryableError; exports.PackageSchema = _chunkU54EW4DXcjs.PackageSchema; exports.QuerySchema = _chunkPMS6BMIUcjs.QuerySchema; exports.REDACTED = _chunkPMS6BMIUcjs.REDACTED; exports.SHREDDED = _chunkPMS6BMIUcjs.SHREDDED; exports.SNAP_EVENT = _chunkPMS6BMIUcjs.SNAP_EVENT; exports.StoreError = _chunkPMS6BMIUcjs.StoreError; exports.StreamClosedError = _chunkPMS6BMIUcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunkPMS6BMIUcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunkPMS6BMIUcjs.TargetSchema; exports.ValidationError = _chunkPMS6BMIUcjs.ValidationError; exports.ZodEmpty = _chunkPMS6BMIUcjs.ZodEmpty; exports.act = act; exports.cache = _chunkU54EW4DXcjs.cache; exports.config = _chunkU54EW4DXcjs.config; exports.dateReviver = _chunkU54EW4DXcjs.dateReviver; exports.default_scope = _chunkU54EW4DXcjs.default_scope; exports.dispose = _chunkU54EW4DXcjs.dispose; exports.disposeAndExit = _chunkU54EW4DXcjs.disposeAndExit; exports.extend = _chunkU54EW4DXcjs.extend; exports.is_literal_source = _chunkU54EW4DXcjs.is_literal_source; exports.log = _chunkU54EW4DXcjs.log; exports.pii_fields = _chunkPMS6BMIUcjs.pii_fields; exports.port = _chunkU54EW4DXcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkU54EW4DXcjs.resolveAutocloseConfig2; exports.sensitive = _chunkPMS6BMIUcjs.sensitive; exports.sleep = _chunkU54EW4DXcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkU54EW4DXcjs.store; exports.validate = _chunkU54EW4DXcjs.validate;
5275
5267
  //# sourceMappingURL=index.cjs.map