@rotorsoft/act 1.23.26 → 1.23.28

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