@rotorsoft/act 1.32.7 → 1.32.9

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
@@ -1540,6 +1540,12 @@ var InMemoryStore = class {
1540
1540
  const prev_max_event_id_by_stream = this._max_event_id_by_stream;
1541
1541
  const prev_max_non_snap_event_id = this._max_non_snap_event_id;
1542
1542
  const prev_pii = this._pii;
1543
+ const prev_correlated_at = this._correlated_at;
1544
+ const prev_correlators = new Map(
1545
+ [...this._correlators].map(([k, v]) => [k, { ...v }])
1546
+ );
1547
+ this._correlated_at = -1;
1548
+ for (const c of this._correlators.values()) c.at = -1;
1543
1549
  this._events = [];
1544
1550
  this._next_id = 0;
1545
1551
  this._streams = /* @__PURE__ */ new Map();
@@ -1576,6 +1582,8 @@ var InMemoryStore = class {
1576
1582
  this._max_event_id_by_stream = prev_max_event_id_by_stream;
1577
1583
  this._max_non_snap_event_id = prev_max_non_snap_event_id;
1578
1584
  this._pii = prev_pii;
1585
+ this._correlated_at = prev_correlated_at;
1586
+ this._correlators = prev_correlators;
1579
1587
  throw err;
1580
1588
  }
1581
1589
  }
@@ -3392,6 +3400,24 @@ var CorrelateCycle = class {
3392
3400
  * `_static_subscriptions`, which this never touches, so they stay pinned
3393
3401
  * at +Infinity and the dynamic path never re-opens them.
3394
3402
  */
3403
+ /**
3404
+ * Start correlation over after the event log was replaced wholesale
3405
+ * (`restore`). The restored log is renumbered from the start and its
3406
+ * subscription rows are gone, so the in-memory scan position and both
3407
+ * subscription records describe a log that no longer exists. Dropping them
3408
+ * and the init latch makes the next pass run cold-start again: static
3409
+ * targets are re-subscribed, the checkpoint is re-read from the store
3410
+ * (which `restore` reset), and dynamic targets are rediscovered by the
3411
+ * scan (#1772).
3412
+ */
3413
+ restart() {
3414
+ this._initialized = false;
3415
+ this._init_promise = void 0;
3416
+ this._checkpoint = -1;
3417
+ this._dynamic_subscriptions.clear();
3418
+ this._static_subscriptions.clear();
3419
+ this._armed = true;
3420
+ }
3395
3421
  forget_subscribed(streams) {
3396
3422
  for (const stream of streams) this._dynamic_subscriptions.delete(stream);
3397
3423
  }
@@ -4481,6 +4507,16 @@ function budget_exhausted(lease, options, store_failing) {
4481
4507
  log().error(error);
4482
4508
  return { lease, handled: 0, acked_at: lease.at, error, block: true };
4483
4509
  }
4510
+ function fetch_failure_policy(registry) {
4511
+ let blockOnError = true;
4512
+ let maxRetries = 0;
4513
+ for (const register of Object.values(registry.events))
4514
+ for (const reaction of register.reactions.values()) {
4515
+ blockOnError &&= reaction.options.blockOnError;
4516
+ maxRetries = Math.max(maxRetries, reaction.options.maxRetries);
4517
+ }
4518
+ return { blockOnError, maxRetries };
4519
+ }
4484
4520
  function warn_misrouted(seen, stream, handler, event) {
4485
4521
  report_once(
4486
4522
  seen,
@@ -4531,11 +4567,14 @@ async function run_drain_cycle(ops, registry, batch_handlers, misrouted, store_f
4531
4567
  if (entry.fetch.error !== void 0) {
4532
4568
  const error = `Fetch failed for ${lease.stream}: ${entry.fetch.error}`;
4533
4569
  log().error(error);
4570
+ const policy = fetch_failure_policy(registry);
4571
+ const block2 = !store_failing && policy.blockOnError && lease.retry >= policy.maxRetries;
4534
4572
  const failed = {
4535
4573
  lease,
4536
4574
  handled: 0,
4537
4575
  acked_at: lease.at,
4538
- error
4576
+ error,
4577
+ ...block2 ? { block: true } : {}
4539
4578
  };
4540
4579
  return Promise.resolve(failed);
4541
4580
  }
@@ -6333,6 +6372,10 @@ var Act = class {
6333
6372
  migrated = partial.migrated;
6334
6373
  dropped = partial.dropped;
6335
6374
  });
6375
+ if (!sink) {
6376
+ this._correlate.restart();
6377
+ this._arm_all();
6378
+ }
6336
6379
  return { kept, migrated, dropped, duration_ms: Date.now() - started };
6337
6380
  });
6338
6381
  }
@@ -7002,6 +7045,7 @@ function act() {
7002
7045
  const pending_projections = [];
7003
7046
  const projection_reactions = /* @__PURE__ */ new Set();
7004
7047
  const record_projection_reactions = (proj) => {
7048
+ if (!proj.batchHandler && !proj.fold) return;
7005
7049
  for (const register of Object.values(
7006
7050
  proj.events
7007
7051
  ))