@rotorsoft/act 1.32.12 → 1.32.13

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
@@ -26,7 +26,7 @@ import {
26
26
  sleep,
27
27
  store,
28
28
  validate
29
- } from "./chunk-UVFP2BQ3.js";
29
+ } from "./chunk-FLAGQMWE.js";
30
30
  import {
31
31
  ActorSchema,
32
32
  CausationEventSchema,
@@ -851,6 +851,151 @@ var CloseSignal = class extends Error {
851
851
  }
852
852
  };
853
853
 
854
+ // src/internal/config.ts
855
+ import { z as z2 } from "zod";
856
+ var BackoffOptionsSchema = z2.object({
857
+ strategy: z2.enum(["fixed", "linear", "exponential"]),
858
+ baseMs: z2.number().min(0),
859
+ maxMs: z2.number().gt(0).optional(),
860
+ jitter: z2.boolean().optional()
861
+ });
862
+ var DEFAULT_MAX_RETRIES = 3;
863
+ var DEFAULT_BLOCK_ON_ERROR = true;
864
+ var ReactionOptionsSchema = z2.object({
865
+ blockOnError: z2.boolean(),
866
+ maxRetries: z2.number().int().min(0),
867
+ backoff: BackoffOptionsSchema.optional()
868
+ });
869
+ function resolveReactionConfig(options) {
870
+ return ReactionOptionsSchema.parse(options);
871
+ }
872
+ var ActionOptionsSchema = z2.object({
873
+ maxRetries: z2.number().int().min(0).optional(),
874
+ backoff: BackoffOptionsSchema.optional()
875
+ });
876
+ function resolveActionConfig(options) {
877
+ return ActionOptionsSchema.parse(options);
878
+ }
879
+ var LaneConfigSchema = z2.object({
880
+ name: z2.string().min(1),
881
+ leaseMillis: z2.number().min(0).optional(),
882
+ streamLimit: z2.number().int().min(0).optional(),
883
+ cycleMs: z2.number().min(0).optional()
884
+ });
885
+ function resolveLaneConfig(options) {
886
+ LaneConfigSchema.parse(options);
887
+ return options;
888
+ }
889
+ var DEFAULT_STREAM_LIMIT = 10;
890
+ var DEFAULT_EVENT_LIMIT = 10;
891
+ var DEFAULT_LEASE_MILLIS = 1e4;
892
+ var DEFAULT_SETTLE_DEBOUNCE_MS = 10;
893
+ var DEFAULT_MAX_SUBSCRIBED_STREAMS = 1e3;
894
+ var DrainOptionsSchema = z2.object({
895
+ streamLimit: z2.number().int().min(0).optional(),
896
+ eventLimit: z2.number().int().min(0).optional(),
897
+ leaseMillis: z2.number().min(0).optional()
898
+ });
899
+ function resolveDrainConfig(options) {
900
+ if (options === void 0) return void 0;
901
+ DrainOptionsSchema.parse(options);
902
+ return options;
903
+ }
904
+ var SettleOptionsSchema = DrainOptionsSchema.extend({
905
+ debounceMs: z2.number().min(0).optional(),
906
+ // `maxPasses` defaults to Infinity (no cap) when omitted; a present value is
907
+ // a non-negative integer — `0` is legal and means "run no passes".
908
+ //
909
+ // `Infinity` is accepted explicitly. It is the documented default
910
+ // (`Act.settle`'s doc-comment and `SettleOptions.maxPasses` both name it),
911
+ // and `settle.ts` destructures `maxPasses = Infinity`, so the one value the
912
+ // docs advertise was the one value `z.number().int()` refused — Zod 4
913
+ // rejects `±Infinity`, and an integer check cannot pass it either. Wrapper
914
+ // code normalizing an optional cap (`maxPasses: opts.maxPasses ?? Infinity`)
915
+ // is the natural way to hit it. Accepting it also honors this module's own
916
+ // rule that a value which works today is never newly rejected (#1711).
917
+ maxPasses: z2.union([z2.number().int().min(0), z2.literal(Number.POSITIVE_INFINITY)]).optional()
918
+ }).loose();
919
+ function resolveSettleConfig(options) {
920
+ if (options === void 0) return void 0;
921
+ SettleOptionsSchema.parse(options);
922
+ return options;
923
+ }
924
+ var MAX_SHUTDOWN_GRACE_MS = 3e4;
925
+ var DEFAULT_SHUTDOWN_GRACE_MS = DEFAULT_LEASE_MILLIS;
926
+ var ShutdownOptionsSchema = z2.object({
927
+ // `0` is legal and is exactly today's behavior: stop scheduling and
928
+ // return without waiting.
929
+ graceMs: z2.number().min(0).optional()
930
+ }).loose();
931
+ function resolveShutdownConfig(options) {
932
+ if (options === void 0) return void 0;
933
+ ShutdownOptionsSchema.parse(options);
934
+ return options;
935
+ }
936
+ var ActOptionsSchema = z2.object({
937
+ maxSubscribedStreams: z2.number().int().min(1).optional(),
938
+ settleDebounceMs: z2.number().int().min(0).optional()
939
+ }).loose();
940
+ function resolveActConfig(options) {
941
+ if (options === void 0) return void 0;
942
+ ActOptionsSchema.parse(options);
943
+ return options;
944
+ }
945
+ var DEFAULT_AUTOCLOSE_CYCLE_MINUTES = 720;
946
+ var DEFAULT_CLOSE_BATCH_SIZE = 64;
947
+ var DEFAULT_CLOSE_YIELD_MS = 0;
948
+ var DEFAULT_AUTOCLOSE_WINDOW_TZ = "UTC";
949
+ function is_valid_time_zone(tz) {
950
+ try {
951
+ new Intl.DateTimeFormat("en-US", { timeZone: tz });
952
+ return true;
953
+ } catch {
954
+ return false;
955
+ }
956
+ }
957
+ var AutocloseWindowSchema = z2.object({
958
+ start: z2.number().int().min(0).max(23, { message: "autocloseWindow.start must be an hour in [0, 23]" }),
959
+ end: z2.number().int().min(0).max(23, { message: "autocloseWindow.end must be an hour in [0, 23]" }),
960
+ timeZone: z2.string().refine(is_valid_time_zone, {
961
+ message: "autocloseWindow.timeZone must be a valid IANA time zone"
962
+ }).default(DEFAULT_AUTOCLOSE_WINDOW_TZ)
963
+ }).refine((w) => w.start !== w.end, {
964
+ message: "autocloseWindow.start and end must differ \u2014 an empty window disables autoclose"
965
+ });
966
+ var AutocloseOptionsSchema = z2.object({
967
+ autocloseCycleMinutes: z2.number().int().min(1).max(1440).default(DEFAULT_AUTOCLOSE_CYCLE_MINUTES),
968
+ closeBatchSize: z2.number().int().min(1).max(1024).default(DEFAULT_CLOSE_BATCH_SIZE),
969
+ closeYieldMs: z2.number().min(0).max(1e3).default(DEFAULT_CLOSE_YIELD_MS),
970
+ closeOnError: z2.boolean().default(false),
971
+ autocloseWindow: AutocloseWindowSchema.optional()
972
+ });
973
+ function resolveAutocloseConfig(options) {
974
+ return AutocloseOptionsSchema.parse({
975
+ autocloseCycleMinutes: options?.autocloseCycleMinutes,
976
+ closeBatchSize: options?.closeBatchSize,
977
+ closeYieldMs: options?.closeYieldMs,
978
+ closeOnError: options?.closeOnError,
979
+ autocloseWindow: options?.autocloseWindow
980
+ });
981
+ }
982
+ var DEFAULT_CIRCUIT_FAILURE_THRESHOLD = 5;
983
+ var DEFAULT_CIRCUIT_COOLDOWN_MS = 3e4;
984
+ var CircuitBreakerOptionsSchema = z2.object({
985
+ failureThreshold: z2.number().int().min(1).default(DEFAULT_CIRCUIT_FAILURE_THRESHOLD),
986
+ cooldownMs: z2.number().int().min(100).max(36e5).default(DEFAULT_CIRCUIT_COOLDOWN_MS)
987
+ });
988
+ var resolveCircuitBreakerConfig = (options) => CircuitBreakerOptionsSchema.parse(options ?? {});
989
+ var DEFAULT_FOLD_FLUSH_EVERY = 1e3;
990
+ var DEFAULT_MAX_CACHED_STATES = 1e4;
991
+ var FoldOptionsSchema = z2.object({
992
+ flushEvery: z2.number().int().min(1).default(DEFAULT_FOLD_FLUSH_EVERY),
993
+ maxCachedStates: z2.number().int().min(1).default(DEFAULT_MAX_CACHED_STATES)
994
+ });
995
+ function resolveFoldConfig(options) {
996
+ return FoldOptionsSchema.parse(options);
997
+ }
998
+
854
999
  // src/internal/defer-signal.ts
855
1000
  var DeferSignal = class extends Error {
856
1001
  /**
@@ -887,7 +1032,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
887
1032
  }),
888
1033
  // Never block on autoclose: a transient query/store error should retry,
889
1034
  // not quarantine the synthetic stream.
890
- options: { blockOnError: false, maxRetries: 3 },
1035
+ options: { blockOnError: false, maxRetries: DEFAULT_MAX_RETRIES },
891
1036
  handler: async (event) => {
892
1037
  const aggregate = event.stream;
893
1038
  const window = read_window();
@@ -1374,144 +1519,6 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
1374
1519
  return truncated;
1375
1520
  }
1376
1521
 
1377
- // src/internal/config.ts
1378
- import { z as z2 } from "zod";
1379
- var BackoffOptionsSchema = z2.object({
1380
- strategy: z2.enum(["fixed", "linear", "exponential"]),
1381
- baseMs: z2.number().min(0),
1382
- maxMs: z2.number().gt(0).optional(),
1383
- jitter: z2.boolean().optional()
1384
- });
1385
- var ReactionOptionsSchema = z2.object({
1386
- blockOnError: z2.boolean(),
1387
- maxRetries: z2.number().int().min(0),
1388
- backoff: BackoffOptionsSchema.optional()
1389
- });
1390
- function resolveReactionConfig(options) {
1391
- return ReactionOptionsSchema.parse(options);
1392
- }
1393
- var ActionOptionsSchema = z2.object({
1394
- maxRetries: z2.number().int().min(0).optional(),
1395
- backoff: BackoffOptionsSchema.optional()
1396
- });
1397
- function resolveActionConfig(options) {
1398
- return ActionOptionsSchema.parse(options);
1399
- }
1400
- var LaneConfigSchema = z2.object({
1401
- name: z2.string().min(1),
1402
- leaseMillis: z2.number().min(0).optional(),
1403
- streamLimit: z2.number().int().min(0).optional(),
1404
- cycleMs: z2.number().min(0).optional()
1405
- });
1406
- function resolveLaneConfig(options) {
1407
- LaneConfigSchema.parse(options);
1408
- return options;
1409
- }
1410
- var DrainOptionsSchema = z2.object({
1411
- streamLimit: z2.number().int().min(0).optional(),
1412
- eventLimit: z2.number().int().min(0).optional(),
1413
- leaseMillis: z2.number().min(0).optional()
1414
- });
1415
- function resolveDrainConfig(options) {
1416
- if (options === void 0) return void 0;
1417
- DrainOptionsSchema.parse(options);
1418
- return options;
1419
- }
1420
- var SettleOptionsSchema = DrainOptionsSchema.extend({
1421
- debounceMs: z2.number().min(0).optional(),
1422
- // `maxPasses` defaults to Infinity (no cap) when omitted; a present value is
1423
- // a non-negative integer — `0` is legal and means "run no passes".
1424
- //
1425
- // `Infinity` is accepted explicitly. It is the documented default
1426
- // (`Act.settle`'s doc-comment and `SettleOptions.maxPasses` both name it),
1427
- // and `settle.ts` destructures `maxPasses = Infinity`, so the one value the
1428
- // docs advertise was the one value `z.number().int()` refused — Zod 4
1429
- // rejects `±Infinity`, and an integer check cannot pass it either. Wrapper
1430
- // code normalizing an optional cap (`maxPasses: opts.maxPasses ?? Infinity`)
1431
- // is the natural way to hit it. Accepting it also honors this module's own
1432
- // rule that a value which works today is never newly rejected (#1711).
1433
- maxPasses: z2.union([z2.number().int().min(0), z2.literal(Number.POSITIVE_INFINITY)]).optional()
1434
- }).loose();
1435
- function resolveSettleConfig(options) {
1436
- if (options === void 0) return void 0;
1437
- SettleOptionsSchema.parse(options);
1438
- return options;
1439
- }
1440
- var MAX_SHUTDOWN_GRACE_MS = 3e4;
1441
- var DEFAULT_SHUTDOWN_GRACE_MS = 1e4;
1442
- var ShutdownOptionsSchema = z2.object({
1443
- // `0` is legal and is exactly today's behavior: stop scheduling and
1444
- // return without waiting.
1445
- graceMs: z2.number().min(0).optional()
1446
- }).loose();
1447
- function resolveShutdownConfig(options) {
1448
- if (options === void 0) return void 0;
1449
- ShutdownOptionsSchema.parse(options);
1450
- return options;
1451
- }
1452
- var ActOptionsSchema = z2.object({
1453
- maxSubscribedStreams: z2.number().int().min(1).optional(),
1454
- settleDebounceMs: z2.number().int().min(0).optional()
1455
- }).loose();
1456
- function resolveActConfig(options) {
1457
- if (options === void 0) return void 0;
1458
- ActOptionsSchema.parse(options);
1459
- return options;
1460
- }
1461
- var DEFAULT_AUTOCLOSE_CYCLE_MINUTES = 720;
1462
- var DEFAULT_CLOSE_BATCH_SIZE = 64;
1463
- var DEFAULT_CLOSE_YIELD_MS = 0;
1464
- var DEFAULT_AUTOCLOSE_WINDOW_TZ = "UTC";
1465
- function is_valid_time_zone(tz) {
1466
- try {
1467
- new Intl.DateTimeFormat("en-US", { timeZone: tz });
1468
- return true;
1469
- } catch {
1470
- return false;
1471
- }
1472
- }
1473
- var AutocloseWindowSchema = z2.object({
1474
- start: z2.number().int().min(0).max(23, { message: "autocloseWindow.start must be an hour in [0, 23]" }),
1475
- end: z2.number().int().min(0).max(23, { message: "autocloseWindow.end must be an hour in [0, 23]" }),
1476
- timeZone: z2.string().refine(is_valid_time_zone, {
1477
- message: "autocloseWindow.timeZone must be a valid IANA time zone"
1478
- }).default(DEFAULT_AUTOCLOSE_WINDOW_TZ)
1479
- }).refine((w) => w.start !== w.end, {
1480
- message: "autocloseWindow.start and end must differ \u2014 an empty window disables autoclose"
1481
- });
1482
- var AutocloseOptionsSchema = z2.object({
1483
- autocloseCycleMinutes: z2.number().int().min(1).max(1440).default(DEFAULT_AUTOCLOSE_CYCLE_MINUTES),
1484
- closeBatchSize: z2.number().int().min(1).max(1024).default(DEFAULT_CLOSE_BATCH_SIZE),
1485
- closeYieldMs: z2.number().min(0).max(1e3).default(DEFAULT_CLOSE_YIELD_MS),
1486
- closeOnError: z2.boolean().default(false),
1487
- autocloseWindow: AutocloseWindowSchema.optional()
1488
- });
1489
- function resolveAutocloseConfig(options) {
1490
- return AutocloseOptionsSchema.parse({
1491
- autocloseCycleMinutes: options?.autocloseCycleMinutes,
1492
- closeBatchSize: options?.closeBatchSize,
1493
- closeYieldMs: options?.closeYieldMs,
1494
- closeOnError: options?.closeOnError,
1495
- autocloseWindow: options?.autocloseWindow
1496
- });
1497
- }
1498
- var DEFAULT_CIRCUIT_FAILURE_THRESHOLD = 5;
1499
- var DEFAULT_CIRCUIT_COOLDOWN_MS = 3e4;
1500
- var CircuitBreakerOptionsSchema = z2.object({
1501
- failureThreshold: z2.number().int().min(1).default(DEFAULT_CIRCUIT_FAILURE_THRESHOLD),
1502
- cooldownMs: z2.number().int().min(100).max(36e5).default(DEFAULT_CIRCUIT_COOLDOWN_MS)
1503
- });
1504
- var resolveCircuitBreakerConfig = (options) => CircuitBreakerOptionsSchema.parse(options ?? {});
1505
- var DEFAULT_FOLD_FLUSH_EVERY = 1e3;
1506
- var DEFAULT_MAX_CACHED_STATES = 1e4;
1507
- var FoldOptionsSchema = z2.object({
1508
- flushEvery: z2.number().int().min(1).default(DEFAULT_FOLD_FLUSH_EVERY),
1509
- maxCachedStates: z2.number().int().min(1).default(DEFAULT_MAX_CACHED_STATES)
1510
- });
1511
- function resolveFoldConfig(options) {
1512
- return FoldOptionsSchema.parse(options);
1513
- }
1514
-
1515
1522
  // src/internal/correlate-cycle.ts
1516
1523
  import { createHash, randomUUID } from "crypto";
1517
1524
 
@@ -3039,9 +3046,9 @@ var DrainController = class {
3039
3046
  if (this._deps.breaker.state(Date.now()) === "open")
3040
3047
  return EMPTY_DRAIN;
3041
3048
  const d = this._deps.defaults ?? {};
3042
- const streamLimit = d.streamLimit ?? options.streamLimit ?? 10;
3043
- const eventLimit = d.eventLimit ?? options.eventLimit ?? 10;
3044
- const leaseMillis = d.leaseMillis ?? options.leaseMillis ?? 1e4;
3049
+ const streamLimit = d.streamLimit ?? options.streamLimit ?? DEFAULT_STREAM_LIMIT;
3050
+ const eventLimit = d.eventLimit ?? options.eventLimit ?? DEFAULT_EVENT_LIMIT;
3051
+ const leaseMillis = d.leaseMillis ?? options.leaseMillis ?? DEFAULT_LEASE_MILLIS;
3045
3052
  try {
3046
3053
  this._locked = true;
3047
3054
  this._inflight = new Promise((done) => {
@@ -3415,10 +3422,8 @@ function build_handle_batch(logger) {
3415
3422
  }
3416
3423
 
3417
3424
  // src/act.ts
3418
- var DEFAULT_MAX_SUBSCRIBED_STREAMS = 1e3;
3419
3425
  var CLOSE_CATCH_UP_LIMIT = 1e3;
3420
3426
  var CLOSE_CATCH_UP_PASSES = 20;
3421
- var DEFAULT_SETTLE_DEBOUNCE_MS = 10;
3422
3427
  function validate_only_lanes(options, lanes) {
3423
3428
  if (!options.onlyLanes || options.onlyLanes.length === 0) return;
3424
3429
  const declared = /* @__PURE__ */ new Set(["default", ...lanes.map((l) => l.name)]);
@@ -5159,8 +5164,8 @@ function reaction_on(event, events, builder) {
5159
5164
  // `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
5160
5165
  // not a NaN gate on the first retry.
5161
5166
  options: resolveReactionConfig({
5162
- blockOnError: options?.blockOnError ?? true,
5163
- maxRetries: options?.maxRetries ?? 3,
5167
+ blockOnError: options?.blockOnError ?? DEFAULT_BLOCK_ON_ERROR,
5168
+ maxRetries: options?.maxRetries ?? DEFAULT_MAX_RETRIES,
5164
5169
  backoff: options?.backoff
5165
5170
  })
5166
5171
  };
@@ -5551,8 +5556,8 @@ function _projection(target) {
5551
5556
  handler,
5552
5557
  resolver: default_resolver ?? _this_,
5553
5558
  options: {
5554
- blockOnError: true,
5555
- maxRetries: 3
5559
+ blockOnError: DEFAULT_BLOCK_ON_ERROR,
5560
+ maxRetries: DEFAULT_MAX_RETRIES
5556
5561
  }
5557
5562
  };
5558
5563
  const register = events[event];
@@ -5625,7 +5630,10 @@ function _projection(target) {
5625
5630
  {
5626
5631
  handler: noop,
5627
5632
  resolver: { target },
5628
- options: { blockOnError: true, maxRetries: 3 }
5633
+ options: {
5634
+ blockOnError: DEFAULT_BLOCK_ON_ERROR,
5635
+ maxRetries: DEFAULT_MAX_RETRIES
5636
+ }
5629
5637
  }
5630
5638
  ]
5631
5639
  ])