@rotorsoft/act 1.23.26 → 1.23.27

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.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  sleep,
21
21
  store,
22
22
  validate
23
- } from "./chunk-ORKHOSH2.js";
23
+ } from "./chunk-UEZ7T2SX.js";
24
24
  import {
25
25
  ActorSchema,
26
26
  CausationEventSchema,
@@ -166,7 +166,10 @@ async function* audit(deps, categories, options = {}) {
166
166
  const need_streams = passes.some((p) => p.on_stream !== void 0);
167
167
  const need_events = passes.some((p) => p.on_event !== void 0);
168
168
  if (need_stats) {
169
- const stats = await deps.store().query_stats({}, { count: true, names: true });
169
+ const stats = await deps.store().query_stats(
170
+ {},
171
+ { count: true, names: true, exclude: [SNAP_EVENT] }
172
+ );
170
173
  for (const [stream, s] of stats) {
171
174
  for (const p of passes) p.on_stat?.(stream, s);
172
175
  }
@@ -306,23 +309,38 @@ var make_close_candidate_pass = (deps, options) => {
306
309
  };
307
310
  var make_restart_candidate_pass = (deps, options) => {
308
311
  const threshold = options.thresholds?.restart_min ?? DEFAULTS.restart_min;
312
+ const candidates = [];
309
313
  const findings = [];
310
314
  return {
311
315
  category: "restart-candidate",
312
- on_stat(stream, { head, count, names }) {
316
+ on_stat(stream, { head, count }) {
313
317
  if (count < threshold) return;
314
318
  const head_name = String(head.name);
315
319
  if (head_name.startsWith("__")) return;
316
320
  if (!restart_is_supported(deps, head_name)) return;
317
- findings.push({
318
- category: "restart-candidate",
319
- stream,
320
- count,
321
- // names map is sparse — `__snapshot__` key absent when the
322
- // stream has never been snapshotted (a common case for the
323
- // restart-candidate signal).
324
- snaps: names.__snapshot__ ?? 0
325
- });
321
+ candidates.push({ stream, count });
322
+ },
323
+ async finalize(deps2) {
324
+ for (const { stream, count } of candidates) {
325
+ let snaps = 0;
326
+ await deps2.store().query(
327
+ () => {
328
+ snaps++;
329
+ },
330
+ {
331
+ stream,
332
+ stream_exact: true,
333
+ names: [SNAP_EVENT],
334
+ with_snaps: true
335
+ }
336
+ );
337
+ findings.push({
338
+ category: "restart-candidate",
339
+ stream,
340
+ count,
341
+ snaps
342
+ });
343
+ }
326
344
  },
327
345
  drain: () => findings
328
346
  };
@@ -377,34 +395,33 @@ var make_snapshot_drift_pass = (deps, options) => {
377
395
  const findings = [];
378
396
  return {
379
397
  category: "snapshot-drift",
380
- on_stat(stream, { head, count, names }) {
398
+ on_stat(stream, { head, count }) {
381
399
  if (!restart_is_supported(deps, String(head.name))) return;
382
400
  if (count < drift_min) return;
383
401
  candidates.push({
384
402
  stream,
385
- total: count,
386
- snaps: names.__snapshot__ ?? 0
403
+ total: count
387
404
  });
388
405
  },
389
406
  async finalize(deps2) {
390
- for (const { stream, total, snaps } of candidates) {
407
+ for (const { stream, total } of candidates) {
391
408
  let events_since_snap = total;
392
409
  let snap_at;
393
- if (snaps > 0) {
394
- const collected = [];
395
- await deps2.store().query(
396
- (e) => {
397
- collected.push({ id: e.id });
398
- },
399
- {
400
- stream,
401
- stream_exact: true,
402
- names: ["__snapshot__"],
403
- backward: true,
404
- limit: 1,
405
- with_snaps: true
406
- }
407
- );
410
+ const collected = [];
411
+ await deps2.store().query(
412
+ (e) => {
413
+ collected.push({ id: e.id });
414
+ },
415
+ {
416
+ stream,
417
+ stream_exact: true,
418
+ names: ["__snapshot__"],
419
+ backward: true,
420
+ limit: 1,
421
+ with_snaps: true
422
+ }
423
+ );
424
+ if (collected.length > 0) {
408
425
  snap_at = collected[0].id;
409
426
  let after = 0;
410
427
  await deps2.store().query(
@@ -4346,8 +4363,35 @@ function act() {
4346
4363
  const pending_projections = [];
4347
4364
  const fold_projections = [];
4348
4365
  const batch_handlers = /* @__PURE__ */ new Map();
4366
+ const fold_specs = [];
4349
4367
  const lanes = [];
4350
4368
  let _built = false;
4369
+ const pii_wrap = (original) => async (events, stream) => {
4370
+ const stripped = events.map((e) => {
4371
+ const f = _sf.get(e.name);
4372
+ return f ? pii_strip(e, f) : e;
4373
+ });
4374
+ return original(stripped, stream);
4375
+ };
4376
+ const make_batch_handlers = (patch_fn) => {
4377
+ const handlers = new Map(batch_handlers);
4378
+ for (const spec of fold_specs) {
4379
+ handlers.set(
4380
+ spec.target,
4381
+ pii_wrap(
4382
+ make_fold_handler(
4383
+ spec.merged,
4384
+ spec.flush,
4385
+ spec.config,
4386
+ patch_fn,
4387
+ // Head loads strip sensitive keys like the warm path (#1320).
4388
+ (event_name) => _sf.get(event_name) ?? []
4389
+ )
4390
+ )
4391
+ );
4392
+ }
4393
+ return handlers;
4394
+ };
4351
4395
  const finalize_deprecations = () => {
4352
4396
  const deprecation_summary = [];
4353
4397
  for (const state2 of states.values()) {
@@ -4443,19 +4487,12 @@ function act() {
4443
4487
  throw new Error(
4444
4488
  `State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
4445
4489
  );
4446
- batch_handlers.set(
4447
- proj.target,
4448
- make_fold_handler(
4449
- merged,
4450
- fold.flush,
4451
- fold.config,
4452
- patch_fn,
4453
- // Head loads strip sensitive keys like the warm path (#1320).
4454
- // `_sf` is populated in the events pass below; read lazily at
4455
- // fold time, by when the map is complete.
4456
- (event_name) => _sf.get(event_name) ?? []
4457
- )
4458
- );
4490
+ fold_specs.push({
4491
+ target: proj.target,
4492
+ merged,
4493
+ flush: fold.flush,
4494
+ config: fold.config
4495
+ });
4459
4496
  }
4460
4497
  finalize_deprecations();
4461
4498
  validate_lane_references(registry, lanes);
@@ -4506,14 +4543,7 @@ function act() {
4506
4543
  };
4507
4544
  }
4508
4545
  for (const [target, original] of batch_handlers) {
4509
- const wrapped = async (events, stream) => {
4510
- const stripped = events.map((e) => {
4511
- const f = _sf.get(e.name);
4512
- return f ? pii_strip(e, f) : e;
4513
- });
4514
- return original(stripped, stream);
4515
- };
4516
- batch_handlers.set(target, wrapped);
4546
+ batch_handlers.set(target, pii_wrap(original));
4517
4547
  }
4518
4548
  synthesize_autoclose_reactions(
4519
4549
  registry,
@@ -4528,7 +4558,7 @@ function act() {
4528
4558
  return new Act(
4529
4559
  registry,
4530
4560
  states,
4531
- batch_handlers,
4561
+ make_batch_handlers(patch_fn),
4532
4562
  options,
4533
4563
  lanes,
4534
4564
  patch_fn