@rotorsoft/act 1.32.1 → 1.32.3

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
@@ -1487,20 +1487,16 @@ var InMemoryStore = class {
1487
1487
  if (drop.size) this._events = this._events.filter((e) => !drop.has(e.id));
1488
1488
  }
1489
1489
  const full = targets.filter((t) => t.before === void 0);
1490
- const deleted_counts = /* @__PURE__ */ new Map();
1491
- const stream_set = new Set(full.map((t) => t.stream));
1492
- for (const e of this._events) {
1493
- if (stream_set.has(e.stream)) {
1494
- deleted_counts.set(e.stream, (deleted_counts.get(e.stream) ?? 0) + 1);
1495
- }
1496
- }
1497
- this._events = this._events.filter((e) => !stream_set.has(e.stream));
1498
- for (const stream of stream_set) {
1490
+ for (const { stream, snapshot, meta } of full) {
1491
+ let deleted = 0;
1492
+ this._events = this._events.filter((e) => {
1493
+ if (e.stream !== stream) return true;
1494
+ deleted++;
1495
+ return false;
1496
+ });
1499
1497
  this._stream_versions.delete(stream);
1500
1498
  this._max_event_id_by_stream.delete(stream);
1501
1499
  this._pii.delete(stream);
1502
- }
1503
- for (const { stream, snapshot, meta } of full) {
1504
1500
  const event = {
1505
1501
  id: this._next_id++,
1506
1502
  stream,
@@ -1515,10 +1511,7 @@ var InMemoryStore = class {
1515
1511
  if (event.name !== SNAP_EVENT) {
1516
1512
  this._max_event_id_by_stream.set(stream, event.id);
1517
1513
  }
1518
- result.set(stream, {
1519
- deleted: deleted_counts.get(stream) ?? 0,
1520
- committed: event
1521
- });
1514
+ result.set(stream, { deleted, committed: event });
1522
1515
  }
1523
1516
  let max = -1;
1524
1517
  for (const id of this._max_event_id_by_stream.values())
@@ -3048,7 +3041,16 @@ var SettleOptionsSchema = DrainOptionsSchema.extend({
3048
3041
  debounceMs: import_zod6.z.number().min(0).optional(),
3049
3042
  // `maxPasses` defaults to Infinity (no cap) when omitted; a present value is
3050
3043
  // a non-negative integer — `0` is legal and means "run no passes".
3051
- maxPasses: import_zod6.z.number().int().min(0).optional()
3044
+ //
3045
+ // `Infinity` is accepted explicitly. It is the documented default
3046
+ // (`Act.settle`'s doc-comment and `SettleOptions.maxPasses` both name it),
3047
+ // and `settle.ts` destructures `maxPasses = Infinity`, so the one value the
3048
+ // docs advertise was the one value `z.number().int()` refused — Zod 4
3049
+ // rejects `±Infinity`, and an integer check cannot pass it either. Wrapper
3050
+ // code normalizing an optional cap (`maxPasses: opts.maxPasses ?? Infinity`)
3051
+ // is the natural way to hit it. Accepting it also honors this module's own
3052
+ // rule that a value which works today is never newly rejected (#1711).
3053
+ maxPasses: import_zod6.z.union([import_zod6.z.number().int().min(0), import_zod6.z.literal(Number.POSITIVE_INFINITY)]).optional()
3052
3054
  }).loose();
3053
3055
  function resolveSettleConfig(options) {
3054
3056
  if (options === void 0) return void 0;
@@ -7036,12 +7038,19 @@ function act() {
7036
7038
  );
7037
7039
  }
7038
7040
  };
7041
+ const closed = (method) => {
7042
+ throw new Error(
7043
+ `act().${method}() was called after build(); the registry is already classified. Register everything before build() \u2014 build() itself may be called repeatedly (e.g. once per tenant with ActOptions.scoped).`
7044
+ );
7045
+ };
7039
7046
  const builder = {
7040
7047
  withState: (state2) => {
7048
+ if (_built) closed("withState");
7041
7049
  register_state(state2, states, registry.actions, registry.events);
7042
7050
  return builder;
7043
7051
  },
7044
7052
  withSlice: (input) => {
7053
+ if (_built) closed("withSlice");
7045
7054
  for (const s of input.states.values()) {
7046
7055
  register_state(s, states, registry.actions, registry.events);
7047
7056
  }
@@ -7062,6 +7071,7 @@ function act() {
7062
7071
  return builder;
7063
7072
  },
7064
7073
  withProjection: (proj) => {
7074
+ if (_built) closed("withProjection");
7065
7075
  record_projection_reactions(proj);
7066
7076
  merge_projection(proj, registry.events);
7067
7077
  register_batch_handler(proj, batch_handlers);
@@ -7071,10 +7081,14 @@ function act() {
7071
7081
  },
7072
7082
  withActor: () => builder,
7073
7083
  withLane: (config2) => {
7084
+ if (_built) closed("withLane");
7074
7085
  register_lane(resolveLaneConfig(config2), lanes);
7075
7086
  return builder;
7076
7087
  },
7077
- on: (event) => reaction_on(event, registry.events, builder),
7088
+ on: (event) => {
7089
+ if (_built) closed("on");
7090
+ return reaction_on(event, registry.events, builder);
7091
+ },
7078
7092
  build: (options) => {
7079
7093
  resolveActConfig(options);
7080
7094
  const patch_fn = options?.validateFoldedState === true ? validating_patch : bare_patch;