@rotorsoft/act 2.0.5 → 2.1.1

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.
Files changed (69) hide show
  1. package/README.md +1 -1
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/act.d.ts +2 -1
  4. package/dist/@types/act.d.ts.map +1 -1
  5. package/dist/@types/adapter.d.ts +85 -0
  6. package/dist/@types/adapter.d.ts.map +1 -0
  7. package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
  8. package/dist/@types/builders/builder-utils.d.ts.map +1 -1
  9. package/dist/@types/config.d.ts +3 -9
  10. package/dist/@types/config.d.ts.map +1 -1
  11. package/dist/@types/deprecated.d.ts +57 -0
  12. package/dist/@types/deprecated.d.ts.map +1 -0
  13. package/dist/@types/index.d.ts +12 -9
  14. package/dist/@types/index.d.ts.map +1 -1
  15. package/dist/@types/internal/autoclose-reaction.d.ts.map +1 -1
  16. package/dist/@types/internal/close-cycle.d.ts.map +1 -1
  17. package/dist/@types/internal/config.d.ts +8 -0
  18. package/dist/@types/internal/config.d.ts.map +1 -1
  19. package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
  20. package/dist/@types/internal/drain-ops.d.ts.map +1 -1
  21. package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
  22. package/dist/@types/ports.d.ts +1 -3
  23. package/dist/@types/ports.d.ts.map +1 -1
  24. package/dist/@types/scoped.d.ts +1 -1
  25. package/dist/@types/sensitive.d.ts +6 -2
  26. package/dist/@types/sensitive.d.ts.map +1 -1
  27. package/dist/@types/types/action.d.ts +2 -2
  28. package/dist/@types/types/index.d.ts +1 -1
  29. package/dist/@types/types/index.d.ts.map +1 -1
  30. package/dist/@types/types/ports.d.ts +7 -3
  31. package/dist/@types/types/ports.d.ts.map +1 -1
  32. package/dist/@types/types/reaction.d.ts +2 -1
  33. package/dist/@types/types/reaction.d.ts.map +1 -1
  34. package/dist/@types/types/schemas.d.ts +1 -1
  35. package/dist/@types/types/schemas.d.ts.map +1 -1
  36. package/dist/@types/utils.d.ts +0 -105
  37. package/dist/@types/utils.d.ts.map +1 -1
  38. package/dist/adapter.cjs +20 -0
  39. package/dist/adapter.cjs.map +1 -0
  40. package/dist/adapter.js +20 -0
  41. package/dist/adapter.js.map +1 -0
  42. package/dist/{chunk-VD4BLAY4.cjs → chunk-7VYSJIXD.cjs} +7 -3
  43. package/dist/chunk-7VYSJIXD.cjs.map +1 -0
  44. package/dist/{chunk-XW4EAUS6.cjs → chunk-LN3OP4OL.cjs} +202 -252
  45. package/dist/chunk-LN3OP4OL.cjs.map +1 -0
  46. package/dist/chunk-PZQXTGWF.cjs +62 -0
  47. package/dist/chunk-PZQXTGWF.cjs.map +1 -0
  48. package/dist/{chunk-3JULRYQO.js → chunk-QPVUARKL.js} +177 -227
  49. package/dist/chunk-QPVUARKL.js.map +1 -0
  50. package/dist/chunk-UXDNSZAD.js +62 -0
  51. package/dist/chunk-UXDNSZAD.js.map +1 -0
  52. package/dist/{chunk-ESFICIG2.js → chunk-W3PHEA5Q.js} +6 -2
  53. package/dist/chunk-W3PHEA5Q.js.map +1 -0
  54. package/dist/index.cjs +292 -237
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.js +105 -50
  57. package/dist/index.js.map +1 -1
  58. package/dist/test/index.cjs +5 -4
  59. package/dist/test/index.cjs.map +1 -1
  60. package/dist/test/index.js +3 -2
  61. package/dist/test/index.js.map +1 -1
  62. package/dist/types/index.cjs +6 -2
  63. package/dist/types/index.cjs.map +1 -1
  64. package/dist/types/index.js +7 -3
  65. package/package.json +6 -1
  66. package/dist/chunk-3JULRYQO.js.map +0 -1
  67. package/dist/chunk-ESFICIG2.js.map +0 -1
  68. package/dist/chunk-VD4BLAY4.cjs.map +0 -1
  69. package/dist/chunk-XW4EAUS6.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -5,37 +5,28 @@ import {
5
5
  DEFAULT_EVENT_LIMIT,
6
6
  DEFAULT_LEASE_MILLIS,
7
7
  DEFAULT_MAX_RETRIES,
8
- DEFAULT_QUERY_STREAMS_LIMIT,
9
8
  DEFAULT_STREAM_LIMIT,
10
9
  InMemoryCache,
11
10
  InMemoryStore,
12
11
  LruMap,
13
12
  MAX_SHUTDOWN_GRACE_MS,
14
- PackageSchema,
15
13
  cache,
16
- check_appends,
17
14
  check_store,
18
- concurrency_error,
19
15
  config,
20
16
  current_autoclose_window,
21
17
  current_reacting,
22
- dateReviver,
23
- default_scope,
24
18
  dispose,
25
19
  disposeAndExit,
26
- extend,
27
- fair_slots,
28
- is_literal_source,
20
+ is_valid_target,
29
21
  log,
30
22
  make_reaction_scope,
31
23
  make_run_scoped,
32
- notification_of,
24
+ package_schema,
33
25
  port,
34
26
  register_weak_disposer,
35
27
  resolveActConfig,
36
28
  resolveActionConfig,
37
29
  resolveAutocloseConfig,
38
- resolveAutocloseConfig2,
39
30
  resolveCircuitBreakerConfig,
40
31
  resolveDrainConfig,
41
32
  resolveFoldConfig,
@@ -43,12 +34,21 @@ import {
43
34
  resolveReactionConfig,
44
35
  resolveSettleConfig,
45
36
  resolveShutdownConfig,
46
- seed_event,
37
+ resolveTargetConfig,
47
38
  sleep,
48
39
  store,
49
- throw_if_stale,
40
+ unscoped_ports,
50
41
  validate
51
- } from "./chunk-3JULRYQO.js";
42
+ } from "./chunk-QPVUARKL.js";
43
+ import {
44
+ checkAppends,
45
+ checkVersion,
46
+ concurrencyError,
47
+ fairSlots,
48
+ isStreamName,
49
+ parseNotification,
50
+ seedEvent
51
+ } from "./chunk-UXDNSZAD.js";
52
52
  import {
53
53
  ActorSchema,
54
54
  CausationEventSchema,
@@ -56,6 +56,7 @@ import {
56
56
  ConcurrencyError,
57
57
  DEFAULT_LANE,
58
58
  DEFAULT_MAX_SUBSCRIBED_STREAMS,
59
+ DEFAULT_QUERY_STREAMS_LIMIT,
59
60
  DEFAULT_SETTLE_DEBOUNCE_MS,
60
61
  DeferSignal,
61
62
  Environments,
@@ -80,8 +81,9 @@ import {
80
81
  output_of,
81
82
  pii_fields,
82
83
  pii_schemas,
83
- sensitive
84
- } from "./chunk-ESFICIG2.js";
84
+ sensitive,
85
+ sensitiveFields
86
+ } from "./chunk-W3PHEA5Q.js";
85
87
 
86
88
  // src/signals.ts
87
89
  process.once("SIGINT", async (arg) => {
@@ -288,7 +290,7 @@ var make_schema_pass = (deps) => {
288
290
  return;
289
291
  }
290
292
  const schema = state2.events[name];
291
- const sensitive2 = pii_fields(schema);
293
+ const sensitive2 = sensitiveFields(schema);
292
294
  let parse_schema = schema;
293
295
  if (sensitive2.length > 0) {
294
296
  const omitter = schema.omit;
@@ -1130,7 +1132,7 @@ async function fetch(leased, eventLimit) {
1130
1132
  return Promise.all(
1131
1133
  leased.map(async ({ stream, source, at, lagging }) => {
1132
1134
  const events = [];
1133
- const stream_exact = source !== void 0 && is_literal_source(source, stream) ? true : void 0;
1135
+ const stream_exact = source !== void 0 && isStreamName(source, stream) ? true : void 0;
1134
1136
  try {
1135
1137
  await store().query((e) => events.push(e), {
1136
1138
  stream: source,
@@ -1320,24 +1322,29 @@ async function scan(source, opts = {}, callback) {
1320
1322
  return;
1321
1323
  }
1322
1324
  let remapped = migrated;
1323
- const caused_by = migrated.meta.causation.event?.id;
1324
- if (caused_by !== void 0) {
1325
- const new_caused_by = id_map.get(caused_by);
1326
- if (new_caused_by !== void 0 && new_caused_by !== caused_by) {
1327
- remapped = {
1328
- ...migrated,
1329
- meta: {
1330
- ...migrated.meta,
1331
- causation: {
1332
- ...migrated.meta.causation,
1325
+ const { action: action2, event: cause } = migrated.meta.causation;
1326
+ if (cause || stream_rename && action2) {
1327
+ remapped = {
1328
+ ...migrated,
1329
+ meta: {
1330
+ ...migrated.meta,
1331
+ causation: {
1332
+ ...migrated.meta.causation,
1333
+ ...action2 && stream_rename && {
1334
+ action: { ...action2, stream: stream_rename(action2.stream) }
1335
+ },
1336
+ ...cause && {
1333
1337
  event: {
1334
- ...migrated.meta.causation.event,
1335
- id: new_caused_by
1338
+ ...cause,
1339
+ // A cause missing from the source has no id in the new
1340
+ // log; its old id would name another event there.
1341
+ id: id_map.get(cause.id) ?? -1,
1342
+ stream: stream_rename ? stream_rename(cause.stream) : cause.stream
1336
1343
  }
1337
1344
  }
1338
1345
  }
1339
- };
1340
- }
1346
+ }
1347
+ };
1341
1348
  }
1342
1349
  const new_id = await callback(remapped);
1343
1350
  id_map.set(event.id, new_id);
@@ -2307,7 +2314,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
2307
2314
  // An anchored stream name would read as a pattern, and a store may refuse
2308
2315
  // it at subscribe, stopping every reaction. Such a stream has no
2309
2316
  // autoclose: `app.close` still closes it.
2310
- resolver: (e) => is_literal_source(e.stream) ? {
2317
+ resolver: (e) => isStreamName(e.stream) ? {
2311
2318
  target: `${AUTOCLOSE_TARGET_PREFIX}${e.stream}`,
2312
2319
  source: e.stream
2313
2320
  } : void 0,
@@ -2546,7 +2553,7 @@ function source_matcher() {
2546
2553
  const compiled = /* @__PURE__ */ new Map();
2547
2554
  return (source, target, stream) => {
2548
2555
  if (!source) return true;
2549
- if (is_literal_source(source, target)) return source === stream;
2556
+ if (isStreamName(source, target)) return source === stream;
2550
2557
  let re = compiled.get(source);
2551
2558
  if (!re) {
2552
2559
  re = new RegExp(source);
@@ -2717,6 +2724,13 @@ function report_undeclared_lane(seen, handler, target, lane, declared) {
2717
2724
  `Reaction "${handler}" resolved onto undeclared lane "${lane}" \u2014 for example target "${target}". Declared lanes: ${[...declared].map((l) => `"${l}"`).join(", ")}. No controller claims it, so the stream would never drain \u2014 running it on "default" instead. The equivalent static \`.to({ lane })\` is rejected at build; a dynamic resolver's lane is only knowable here.`
2718
2725
  );
2719
2726
  }
2727
+ function report_bad_priority(seen, handler, target, priority) {
2728
+ report_once(
2729
+ seen,
2730
+ `priority|${handler}|${String(priority)}`,
2731
+ `Reaction "${handler}" resolved priority ${String(priority)} for target "${target}", which isn't a 32-bit integer. Skipping that event for this reaction; other reactions keep running. The equivalent static \`.to({ priority })\` is rejected at build; a dynamic resolver's priority is only knowable here.`
2732
+ );
2733
+ }
2720
2734
  function report_lane_conflict(seen, handler, target, kept, dropped) {
2721
2735
  report_once(
2722
2736
  seen,
@@ -2822,7 +2836,7 @@ var CorrelateCycle = class {
2822
2836
  // Would the target's own `fetch` (filtered by `source`) return this event?
2823
2837
  _in_fetch_window(source, stream) {
2824
2838
  if (source === void 0 || source === stream) return true;
2825
- if (is_literal_source(source)) return false;
2839
+ if (isStreamName(source)) return false;
2826
2840
  let pattern = this._patterns.get(source);
2827
2841
  if (!pattern) {
2828
2842
  pattern = new RegExp(source);
@@ -2884,6 +2898,15 @@ var CorrelateCycle = class {
2884
2898
  return;
2885
2899
  }
2886
2900
  if (!resolved) continue;
2901
+ if (!is_valid_target(resolved)) {
2902
+ report_bad_priority(
2903
+ this._reported,
2904
+ reaction.handler.name,
2905
+ resolved.target,
2906
+ resolved.priority
2907
+ );
2908
+ continue;
2909
+ }
2887
2910
  let lane = resolved.lane;
2888
2911
  if (lane !== void 0 && !this._declared_lanes.has(lane)) {
2889
2912
  report_undeclared_lane(
@@ -3385,7 +3408,7 @@ var Act = class {
3385
3408
  this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
3386
3409
  validate_only_lanes(options.onlyLanes, this._declared_lanes);
3387
3410
  if (options.scoped) check_store(options.scoped.store);
3388
- this._ports = options.scoped ?? default_scope();
3411
+ this._ports = options.scoped ?? unscoped_ports();
3389
3412
  const ports = this._ports;
3390
3413
  this._scoped = make_run_scoped({
3391
3414
  // Getters, not a spread: the singletons resolve lazily, so a later
@@ -4200,8 +4223,9 @@ var Act = class {
4200
4223
  * registered stream.**
4201
4224
  *
4202
4225
  * @param filter - Selection criteria (regex by default, like {@link query}).
4203
- * @param priority - New priority value. Set as-is — no clamp.
4226
+ * @param priority - New priority value, a 32-bit integer. Set as-is — no clamp.
4204
4227
  * @returns Count of streams whose priority changed.
4228
+ * @throws ZodError when `priority` isn't a 32-bit integer.
4205
4229
  *
4206
4230
  * @example Boost a specific projection mid-replay
4207
4231
  * ```typescript
@@ -4211,6 +4235,7 @@ var Act = class {
4211
4235
  * @see {@link Store.prioritize} for the underlying primitive
4212
4236
  */
4213
4237
  async prioritize(filter, priority) {
4238
+ resolveTargetConfig({ priority });
4214
4239
  return this._scoped(() => store().prioritize(filter, priority));
4215
4240
  }
4216
4241
  // Shared by `close()` and reaction-requested closes.
@@ -4512,6 +4537,7 @@ function add_reaction(events, event, name, kind, make, builder) {
4512
4537
  events[event].reactions.set(name, reaction);
4513
4538
  return Object.assign(builder, {
4514
4539
  to(resolver) {
4540
+ if (typeof resolver === "object") resolveTargetConfig(resolver);
4515
4541
  reaction.resolver = typeof resolver === "string" ? { target: resolver } : resolver;
4516
4542
  return builder;
4517
4543
  }
@@ -5486,37 +5512,65 @@ function write_line(writer, line) {
5486
5512
  });
5487
5513
  });
5488
5514
  }
5515
+
5516
+ // src/deprecated.ts
5517
+ var check_appends = checkAppends;
5518
+ var throw_if_stale = checkVersion;
5519
+ var concurrency_error = concurrencyError;
5520
+ var seed_event = seedEvent;
5521
+ var fair_slots = fairSlots;
5522
+ var is_literal_source = isStreamName;
5523
+ var notification_of = parseNotification;
5524
+ var DEFAULT_QUERY_STREAMS_LIMIT2 = DEFAULT_QUERY_STREAMS_LIMIT;
5525
+ var ActorSchema2 = ActorSchema;
5526
+ var TargetSchema2 = TargetSchema;
5527
+ var EventMetaSchema2 = EventMetaSchema;
5528
+ var CausationEventSchema2 = CausationEventSchema;
5529
+ var CommittedMetaSchema2 = CommittedMetaSchema;
5530
+ var QuerySchema2 = QuerySchema;
5531
+ var Environments2 = Environments;
5532
+ var LogLevels2 = LogLevels;
5533
+ var ExitCodes2 = ExitCodes;
5534
+ var DEFAULT_LANE2 = DEFAULT_LANE;
5535
+ var DEFAULT_MAX_SUBSCRIBED_STREAMS2 = DEFAULT_MAX_SUBSCRIBED_STREAMS;
5536
+ var DEFAULT_SETTLE_DEBOUNCE_MS2 = DEFAULT_SETTLE_DEBOUNCE_MS;
5537
+ var PackageSchema = package_schema;
5538
+ var default_scope = unscoped_ports;
5539
+ var resolveAutocloseConfig2 = resolveAutocloseConfig;
5540
+ var extend = (source, schema, target) => ({ ...target, ...validate("config", source, schema) });
5541
+ var ISO_8601 = /^(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\.\d+)?(Z|[+-][0-2][0-9]:[0-5][0-9])?$/;
5542
+ var dateReviver = (_key, value) => typeof value === "string" && ISO_8601.test(value) ? new Date(value) : value;
5489
5543
  export {
5490
5544
  Act,
5491
- ActorSchema,
5492
- CausationEventSchema,
5493
- CommittedMetaSchema,
5545
+ ActorSchema2 as ActorSchema,
5546
+ CausationEventSchema2 as CausationEventSchema,
5547
+ CommittedMetaSchema2 as CommittedMetaSchema,
5494
5548
  ConcurrencyError,
5495
5549
  ConsoleLogger,
5496
5550
  CsvFile,
5497
- DEFAULT_LANE,
5498
- DEFAULT_MAX_SUBSCRIBED_STREAMS,
5499
- DEFAULT_QUERY_STREAMS_LIMIT,
5500
- DEFAULT_SETTLE_DEBOUNCE_MS,
5551
+ DEFAULT_LANE2 as DEFAULT_LANE,
5552
+ DEFAULT_MAX_SUBSCRIBED_STREAMS2 as DEFAULT_MAX_SUBSCRIBED_STREAMS,
5553
+ DEFAULT_QUERY_STREAMS_LIMIT2 as DEFAULT_QUERY_STREAMS_LIMIT,
5554
+ DEFAULT_SETTLE_DEBOUNCE_MS2 as DEFAULT_SETTLE_DEBOUNCE_MS,
5501
5555
  DeferSignal,
5502
- Environments,
5556
+ Environments2 as Environments,
5503
5557
  Errors,
5504
- EventMetaSchema,
5505
- ExitCodes,
5558
+ EventMetaSchema2 as EventMetaSchema,
5559
+ ExitCodes2 as ExitCodes,
5506
5560
  InMemoryCache,
5507
5561
  InMemoryStore,
5508
- LogLevels,
5562
+ LogLevels2 as LogLevels,
5509
5563
  NonRetryableError,
5510
5564
  PackageSchema,
5511
5565
  PreconditionError,
5512
- QuerySchema,
5566
+ QuerySchema2 as QuerySchema,
5513
5567
  REDACTED,
5514
5568
  SHREDDED,
5515
5569
  SNAP_EVENT,
5516
5570
  StoreError,
5517
5571
  StreamClosedError,
5518
5572
  TOMBSTONE_EVENT,
5519
- TargetSchema,
5573
+ TargetSchema2 as TargetSchema,
5520
5574
  ValidationError,
5521
5575
  ZodEmpty,
5522
5576
  act,
@@ -5539,6 +5593,7 @@ export {
5539
5593
  resolveAutocloseConfig2 as resolveAutocloseConfig,
5540
5594
  seed_event,
5541
5595
  sensitive,
5596
+ sensitiveFields,
5542
5597
  sleep,
5543
5598
  slice,
5544
5599
  state,