@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.
- package/README.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +2 -1
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapter.d.ts +85 -0
- package/dist/@types/adapter.d.ts.map +1 -0
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/builders/builder-utils.d.ts.map +1 -1
- package/dist/@types/config.d.ts +3 -9
- package/dist/@types/config.d.ts.map +1 -1
- package/dist/@types/deprecated.d.ts +57 -0
- package/dist/@types/deprecated.d.ts.map +1 -0
- package/dist/@types/index.d.ts +12 -9
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/@types/internal/autoclose-reaction.d.ts.map +1 -1
- package/dist/@types/internal/close-cycle.d.ts.map +1 -1
- package/dist/@types/internal/config.d.ts +8 -0
- package/dist/@types/internal/config.d.ts.map +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/drain-ops.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +1 -3
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/scoped.d.ts +1 -1
- package/dist/@types/sensitive.d.ts +6 -2
- package/dist/@types/sensitive.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +2 -2
- package/dist/@types/types/index.d.ts +1 -1
- package/dist/@types/types/index.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +7 -3
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/@types/types/reaction.d.ts +2 -1
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/@types/types/schemas.d.ts +1 -1
- package/dist/@types/types/schemas.d.ts.map +1 -1
- package/dist/@types/utils.d.ts +0 -105
- package/dist/@types/utils.d.ts.map +1 -1
- package/dist/adapter.cjs +20 -0
- package/dist/adapter.cjs.map +1 -0
- package/dist/adapter.js +20 -0
- package/dist/adapter.js.map +1 -0
- package/dist/{chunk-VD4BLAY4.cjs → chunk-7VYSJIXD.cjs} +7 -3
- package/dist/chunk-7VYSJIXD.cjs.map +1 -0
- package/dist/{chunk-XW4EAUS6.cjs → chunk-LN3OP4OL.cjs} +202 -252
- package/dist/chunk-LN3OP4OL.cjs.map +1 -0
- package/dist/chunk-PZQXTGWF.cjs +62 -0
- package/dist/chunk-PZQXTGWF.cjs.map +1 -0
- package/dist/{chunk-3JULRYQO.js → chunk-QPVUARKL.js} +177 -227
- package/dist/chunk-QPVUARKL.js.map +1 -0
- package/dist/chunk-UXDNSZAD.js +62 -0
- package/dist/chunk-UXDNSZAD.js.map +1 -0
- package/dist/{chunk-ESFICIG2.js → chunk-W3PHEA5Q.js} +6 -2
- package/dist/chunk-W3PHEA5Q.js.map +1 -0
- package/dist/index.cjs +292 -237
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +105 -50
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +5 -4
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +3 -2
- package/dist/test/index.js.map +1 -1
- package/dist/types/index.cjs +6 -2
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +7 -3
- package/package.json +6 -1
- package/dist/chunk-3JULRYQO.js.map +0 -1
- package/dist/chunk-ESFICIG2.js.map +0 -1
- package/dist/chunk-VD4BLAY4.cjs.map +0 -1
- package/dist/chunk-XW4EAUS6.cjs.map +0 -1
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
checkAppends,
|
|
3
|
+
checkVersion,
|
|
4
|
+
fairSlots,
|
|
5
|
+
seedEvent
|
|
6
|
+
} from "./chunk-UXDNSZAD.js";
|
|
7
|
+
import {
|
|
3
8
|
DEFAULT_LANE,
|
|
9
|
+
DEFAULT_QUERY_STREAMS_LIMIT,
|
|
4
10
|
Environments,
|
|
5
11
|
LogLevels,
|
|
6
12
|
SNAP_EVENT,
|
|
7
|
-
TOMBSTONE_EVENT,
|
|
8
13
|
ValidationError
|
|
9
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-W3PHEA5Q.js";
|
|
10
15
|
|
|
11
16
|
// src/adapters/console-logger.ts
|
|
12
17
|
var LEVEL_VALUES = {
|
|
@@ -207,148 +212,6 @@ var InMemoryCache = class {
|
|
|
207
212
|
import * as fs from "fs";
|
|
208
213
|
import { z as z2 } from "zod";
|
|
209
214
|
|
|
210
|
-
// src/internal/config.ts
|
|
211
|
-
import { z } from "zod";
|
|
212
|
-
var BackoffOptionsSchema = z.object({
|
|
213
|
-
strategy: z.enum(["fixed", "linear", "exponential"]),
|
|
214
|
-
baseMs: z.number().min(0),
|
|
215
|
-
maxMs: z.number().gt(0).optional(),
|
|
216
|
-
jitter: z.boolean().optional()
|
|
217
|
-
});
|
|
218
|
-
var DEFAULT_BACKOFF = {
|
|
219
|
-
strategy: "fixed",
|
|
220
|
-
baseMs: 1e4
|
|
221
|
-
};
|
|
222
|
-
var DEFAULT_MAX_RETRIES = 3;
|
|
223
|
-
var DEFAULT_BLOCK_ON_ERROR = true;
|
|
224
|
-
var ReactionOptionsSchema = z.object({
|
|
225
|
-
blockOnError: z.boolean(),
|
|
226
|
-
maxRetries: z.number().int().min(0),
|
|
227
|
-
backoff: BackoffOptionsSchema.optional()
|
|
228
|
-
});
|
|
229
|
-
function resolveReactionConfig(options) {
|
|
230
|
-
return ReactionOptionsSchema.parse(options);
|
|
231
|
-
}
|
|
232
|
-
var ActionOptionsSchema = z.object({
|
|
233
|
-
maxRetries: z.number().int().min(0).optional(),
|
|
234
|
-
backoff: BackoffOptionsSchema.optional()
|
|
235
|
-
});
|
|
236
|
-
function resolveActionConfig(options) {
|
|
237
|
-
return ActionOptionsSchema.parse(options);
|
|
238
|
-
}
|
|
239
|
-
var LaneConfigSchema = z.object({
|
|
240
|
-
name: z.string().min(1),
|
|
241
|
-
leaseMillis: z.number().min(0).optional(),
|
|
242
|
-
streamLimit: z.number().int().min(0).optional(),
|
|
243
|
-
cycleMs: z.number().min(0).optional()
|
|
244
|
-
});
|
|
245
|
-
function resolveLaneConfig(options) {
|
|
246
|
-
LaneConfigSchema.parse(options);
|
|
247
|
-
return options;
|
|
248
|
-
}
|
|
249
|
-
var DEFAULT_STREAM_LIMIT = 10;
|
|
250
|
-
var DEFAULT_EVENT_LIMIT = 10;
|
|
251
|
-
var DEFAULT_LEASE_MILLIS = 1e4;
|
|
252
|
-
var DrainOptionsSchema = z.object({
|
|
253
|
-
streamLimit: z.number().int().min(0).optional(),
|
|
254
|
-
eventLimit: z.number().int().min(0).optional(),
|
|
255
|
-
leaseMillis: z.number().min(0).optional()
|
|
256
|
-
});
|
|
257
|
-
function resolveDrainConfig(options) {
|
|
258
|
-
if (options === void 0) return void 0;
|
|
259
|
-
DrainOptionsSchema.parse(options);
|
|
260
|
-
return options;
|
|
261
|
-
}
|
|
262
|
-
var SettleOptionsSchema = DrainOptionsSchema.extend({
|
|
263
|
-
debounceMs: z.number().min(0).optional(),
|
|
264
|
-
// `maxPasses` defaults to Infinity (no cap) when omitted; a present value is
|
|
265
|
-
// a non-negative integer — `0` is legal and means "run no passes".
|
|
266
|
-
//
|
|
267
|
-
// `Infinity` is accepted explicitly. It is the documented default
|
|
268
|
-
// (`Act.settle`'s doc-comment and `SettleOptions.maxPasses` both name it),
|
|
269
|
-
// and `settle.ts` destructures `maxPasses = Infinity`, so the one value the
|
|
270
|
-
// docs advertise was the one value `z.number().int()` refused — Zod 4
|
|
271
|
-
// rejects `±Infinity`, and an integer check cannot pass it either. Wrapper
|
|
272
|
-
// code normalizing an optional cap (`maxPasses: opts.maxPasses ?? Infinity`)
|
|
273
|
-
// is the natural way to hit it. Accepting it also honors this module's own
|
|
274
|
-
// rule that a value which works today is never newly rejected.
|
|
275
|
-
maxPasses: z.union([z.number().int().min(0), z.literal(Number.POSITIVE_INFINITY)]).optional()
|
|
276
|
-
}).loose();
|
|
277
|
-
function resolveSettleConfig(options) {
|
|
278
|
-
if (options === void 0) return void 0;
|
|
279
|
-
SettleOptionsSchema.parse(options);
|
|
280
|
-
return options;
|
|
281
|
-
}
|
|
282
|
-
var MAX_SHUTDOWN_GRACE_MS = 3e4;
|
|
283
|
-
var ShutdownOptionsSchema = z.object({
|
|
284
|
-
// `0` is legal and is exactly today's behavior: stop scheduling and
|
|
285
|
-
// return without waiting.
|
|
286
|
-
graceMs: z.number().min(0).optional()
|
|
287
|
-
}).loose();
|
|
288
|
-
function resolveShutdownConfig(options) {
|
|
289
|
-
if (options === void 0) return void 0;
|
|
290
|
-
ShutdownOptionsSchema.parse(options);
|
|
291
|
-
return options;
|
|
292
|
-
}
|
|
293
|
-
var ActOptionsSchema = z.object({
|
|
294
|
-
maxSubscribedStreams: z.number().int().min(1).optional(),
|
|
295
|
-
settleDebounceMs: z.number().int().min(0).optional(),
|
|
296
|
-
autoSettle: z.boolean().optional()
|
|
297
|
-
}).loose();
|
|
298
|
-
function resolveActConfig(options) {
|
|
299
|
-
if (options === void 0) return void 0;
|
|
300
|
-
ActOptionsSchema.parse(options);
|
|
301
|
-
return options;
|
|
302
|
-
}
|
|
303
|
-
var DEFAULT_AUTOCLOSE_WINDOW_TZ = "UTC";
|
|
304
|
-
function is_valid_time_zone(tz) {
|
|
305
|
-
try {
|
|
306
|
-
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
307
|
-
return true;
|
|
308
|
-
} catch {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
var AutocloseWindowSchema = z.object({
|
|
313
|
-
start: z.number().int().min(0).max(23, { message: "autocloseWindow.start must be an hour in [0, 23]" }),
|
|
314
|
-
end: z.number().int().min(0).max(23, { message: "autocloseWindow.end must be an hour in [0, 23]" }),
|
|
315
|
-
timeZone: z.string().refine(is_valid_time_zone, {
|
|
316
|
-
message: "autocloseWindow.timeZone must be a valid IANA time zone"
|
|
317
|
-
}).default(DEFAULT_AUTOCLOSE_WINDOW_TZ)
|
|
318
|
-
}).refine((w) => w.start !== w.end, {
|
|
319
|
-
message: "autocloseWindow.start and end must differ \u2014 an empty window disables autoclose"
|
|
320
|
-
});
|
|
321
|
-
var AutocloseOptionsSchema = z.object({
|
|
322
|
-
autocloseWindow: AutocloseWindowSchema.optional()
|
|
323
|
-
});
|
|
324
|
-
function resolveAutocloseConfig(options) {
|
|
325
|
-
return AutocloseOptionsSchema.parse({
|
|
326
|
-
autocloseWindow: options?.autocloseWindow
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
var DEFAULT_CIRCUIT_FAILURE_THRESHOLD = 5;
|
|
330
|
-
var DEFAULT_CIRCUIT_COOLDOWN_MS = 3e4;
|
|
331
|
-
var CircuitBreakerOptionsSchema = z.object({
|
|
332
|
-
failureThreshold: z.number().int().min(1).default(DEFAULT_CIRCUIT_FAILURE_THRESHOLD),
|
|
333
|
-
cooldownMs: z.number().int().min(100).max(36e5).default(DEFAULT_CIRCUIT_COOLDOWN_MS)
|
|
334
|
-
});
|
|
335
|
-
var resolveCircuitBreakerConfig = (options) => CircuitBreakerOptionsSchema.parse(options ?? {});
|
|
336
|
-
var DEFAULT_FOLD_FLUSH_EVERY = 1e3;
|
|
337
|
-
var DEFAULT_MAX_CACHED_STATES = 1e4;
|
|
338
|
-
var FoldOptionsSchema = z.object({
|
|
339
|
-
flushEvery: z.number().int().min(1).default(DEFAULT_FOLD_FLUSH_EVERY),
|
|
340
|
-
maxCachedStates: z.number().int().min(1).default(DEFAULT_MAX_CACHED_STATES)
|
|
341
|
-
});
|
|
342
|
-
function resolveFoldConfig(options) {
|
|
343
|
-
return FoldOptionsSchema.parse(options);
|
|
344
|
-
}
|
|
345
|
-
function check_store(store3) {
|
|
346
|
-
if (store3.commit.length === 4)
|
|
347
|
-
throw new Error(
|
|
348
|
-
"This store's commit takes (stream, msgs, meta, expectedVersion), the shape before @rotorsoft/act 2.0. Upgrade it, and every @rotorsoft/act-* package, together: https://rotorsoft.github.io/act-root/docs/guides/migrating-to-2.x"
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
215
|
// src/utils.ts
|
|
353
216
|
import { prettifyError, ZodError } from "zod";
|
|
354
217
|
var validate = (target, payload, schema) => {
|
|
@@ -361,60 +224,9 @@ var validate = (target, payload, schema) => {
|
|
|
361
224
|
throw new ValidationError(target, payload, error);
|
|
362
225
|
}
|
|
363
226
|
};
|
|
364
|
-
var extend = (source, schema, target) => {
|
|
365
|
-
const value = validate("config", source, schema);
|
|
366
|
-
return { ...target, ...value };
|
|
367
|
-
};
|
|
368
227
|
async function sleep(ms) {
|
|
369
228
|
return new Promise((resolve) => setTimeout(resolve, ms ?? config().sleepMs));
|
|
370
229
|
}
|
|
371
|
-
function is_literal_source(source, target) {
|
|
372
|
-
return source === target || !source.startsWith("^") && !source.endsWith("$");
|
|
373
|
-
}
|
|
374
|
-
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])?$/;
|
|
375
|
-
var dateReviver = (_key, value) => typeof value === "string" && ISO_8601.test(value) ? new Date(value) : value;
|
|
376
|
-
function check_appends(appends) {
|
|
377
|
-
const seen = /* @__PURE__ */ new Set();
|
|
378
|
-
for (const { stream, msgs } of appends) {
|
|
379
|
-
if (!msgs.length)
|
|
380
|
-
throw new Error(`commit: the append to "${stream}" has no events`);
|
|
381
|
-
if (seen.has(stream))
|
|
382
|
-
throw new Error(`commit: stream "${stream}" is named twice`);
|
|
383
|
-
seen.add(stream);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
function concurrency_error(append, head) {
|
|
387
|
-
return new ConcurrencyError(
|
|
388
|
-
append.stream,
|
|
389
|
-
head,
|
|
390
|
-
append.msgs,
|
|
391
|
-
append.expectedVersion ?? -1
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
function throw_if_stale(append, head) {
|
|
395
|
-
if (typeof append.expectedVersion === "number" && head !== append.expectedVersion)
|
|
396
|
-
throw concurrency_error(append, head);
|
|
397
|
-
}
|
|
398
|
-
function seed_event(snapshot, meta) {
|
|
399
|
-
return {
|
|
400
|
-
name: snapshot !== void 0 ? SNAP_EVENT : TOMBSTONE_EVENT,
|
|
401
|
-
data: snapshot ?? {},
|
|
402
|
-
meta: meta ?? { correlation: "", causation: {} }
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function fair_slots(lagging) {
|
|
406
|
-
return lagging >= 2 ? Math.max(1, Math.floor(lagging / 4)) : 0;
|
|
407
|
-
}
|
|
408
|
-
function notification_of(raw) {
|
|
409
|
-
if (!raw || typeof raw !== "object") return void 0;
|
|
410
|
-
const { stream, events } = raw;
|
|
411
|
-
if (typeof stream !== "string" || !Array.isArray(events)) return void 0;
|
|
412
|
-
const kept = events.filter(
|
|
413
|
-
(e) => !!e && typeof e === "object" && typeof e.id === "number" && typeof e.name === "string"
|
|
414
|
-
);
|
|
415
|
-
return kept.length ? { stream, events: kept.map(({ id, name }) => ({ id, name })) } : void 0;
|
|
416
|
-
}
|
|
417
|
-
var DEFAULT_QUERY_STREAMS_LIMIT = 100;
|
|
418
230
|
|
|
419
231
|
// src/adapters/in-memory-store.ts
|
|
420
232
|
var InMemoryStream = class {
|
|
@@ -667,9 +479,9 @@ var InMemoryStore = class {
|
|
|
667
479
|
}
|
|
668
480
|
async commit(appends, meta) {
|
|
669
481
|
await sleep();
|
|
670
|
-
|
|
482
|
+
checkAppends(appends);
|
|
671
483
|
for (const append of appends)
|
|
672
|
-
|
|
484
|
+
checkVersion(append, this._stream_versions.get(append.stream) ?? -1);
|
|
673
485
|
const created = /* @__PURE__ */ new Date();
|
|
674
486
|
return appends.flatMap(({ stream, msgs }) => {
|
|
675
487
|
let version = this._stream_versions.get(stream) ?? -1;
|
|
@@ -697,7 +509,7 @@ var InMemoryStore = class {
|
|
|
697
509
|
const available = [...this._streams.values()].filter(
|
|
698
510
|
(s) => s.is_available && has_work(s) && (lane === void 0 || s.lane === lane)
|
|
699
511
|
);
|
|
700
|
-
const fair =
|
|
512
|
+
const fair = fairSlots(lagging);
|
|
701
513
|
const by_priority = [...available].sort(
|
|
702
514
|
(a, b) => b.priority - a.priority || a.at - b.at
|
|
703
515
|
);
|
|
@@ -964,7 +776,7 @@ var InMemoryStore = class {
|
|
|
964
776
|
stream,
|
|
965
777
|
version: 0,
|
|
966
778
|
created: /* @__PURE__ */ new Date(),
|
|
967
|
-
...
|
|
779
|
+
...seedEvent(snapshot, meta)
|
|
968
780
|
};
|
|
969
781
|
this._events.push(event);
|
|
970
782
|
this._stream_versions.set(stream, 0);
|
|
@@ -1044,6 +856,155 @@ var run_disposers = async () => {
|
|
|
1044
856
|
}
|
|
1045
857
|
};
|
|
1046
858
|
|
|
859
|
+
// src/internal/config.ts
|
|
860
|
+
import { z } from "zod";
|
|
861
|
+
var BackoffOptionsSchema = z.object({
|
|
862
|
+
strategy: z.enum(["fixed", "linear", "exponential"]),
|
|
863
|
+
baseMs: z.number().min(0),
|
|
864
|
+
maxMs: z.number().gt(0).optional(),
|
|
865
|
+
jitter: z.boolean().optional()
|
|
866
|
+
});
|
|
867
|
+
var DEFAULT_BACKOFF = {
|
|
868
|
+
strategy: "fixed",
|
|
869
|
+
baseMs: 1e4
|
|
870
|
+
};
|
|
871
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
872
|
+
var DEFAULT_BLOCK_ON_ERROR = true;
|
|
873
|
+
var ReactionOptionsSchema = z.object({
|
|
874
|
+
blockOnError: z.boolean(),
|
|
875
|
+
maxRetries: z.number().int().min(0),
|
|
876
|
+
backoff: BackoffOptionsSchema.optional()
|
|
877
|
+
});
|
|
878
|
+
function resolveReactionConfig(options) {
|
|
879
|
+
return ReactionOptionsSchema.parse(options);
|
|
880
|
+
}
|
|
881
|
+
var TargetOptionsSchema = z.object({ priority: z.int32().optional() });
|
|
882
|
+
function resolveTargetConfig(options) {
|
|
883
|
+
TargetOptionsSchema.parse(options);
|
|
884
|
+
}
|
|
885
|
+
function is_valid_target(options) {
|
|
886
|
+
return TargetOptionsSchema.safeParse(options).success;
|
|
887
|
+
}
|
|
888
|
+
var ActionOptionsSchema = z.object({
|
|
889
|
+
maxRetries: z.number().int().min(0).optional(),
|
|
890
|
+
backoff: BackoffOptionsSchema.optional()
|
|
891
|
+
});
|
|
892
|
+
function resolveActionConfig(options) {
|
|
893
|
+
return ActionOptionsSchema.parse(options);
|
|
894
|
+
}
|
|
895
|
+
var LaneConfigSchema = z.object({
|
|
896
|
+
name: z.string().min(1),
|
|
897
|
+
leaseMillis: z.number().min(0).optional(),
|
|
898
|
+
streamLimit: z.number().int().min(0).optional(),
|
|
899
|
+
cycleMs: z.number().min(0).optional()
|
|
900
|
+
});
|
|
901
|
+
function resolveLaneConfig(options) {
|
|
902
|
+
LaneConfigSchema.parse(options);
|
|
903
|
+
return options;
|
|
904
|
+
}
|
|
905
|
+
var DEFAULT_STREAM_LIMIT = 10;
|
|
906
|
+
var DEFAULT_EVENT_LIMIT = 10;
|
|
907
|
+
var DEFAULT_LEASE_MILLIS = 1e4;
|
|
908
|
+
var DrainOptionsSchema = z.object({
|
|
909
|
+
streamLimit: z.number().int().min(0).optional(),
|
|
910
|
+
eventLimit: z.number().int().min(0).optional(),
|
|
911
|
+
leaseMillis: z.number().min(0).optional()
|
|
912
|
+
});
|
|
913
|
+
function resolveDrainConfig(options) {
|
|
914
|
+
if (options === void 0) return void 0;
|
|
915
|
+
DrainOptionsSchema.parse(options);
|
|
916
|
+
return options;
|
|
917
|
+
}
|
|
918
|
+
var SettleOptionsSchema = DrainOptionsSchema.extend({
|
|
919
|
+
debounceMs: z.number().min(0).optional(),
|
|
920
|
+
// `maxPasses` defaults to Infinity (no cap) when omitted; a present value is
|
|
921
|
+
// a non-negative integer — `0` is legal and means "run no passes".
|
|
922
|
+
//
|
|
923
|
+
// `Infinity` is accepted explicitly. It is the documented default
|
|
924
|
+
// (`Act.settle`'s doc-comment and `SettleOptions.maxPasses` both name it),
|
|
925
|
+
// and `settle.ts` destructures `maxPasses = Infinity`, so the one value the
|
|
926
|
+
// docs advertise was the one value `z.number().int()` refused — Zod 4
|
|
927
|
+
// rejects `±Infinity`, and an integer check cannot pass it either. Wrapper
|
|
928
|
+
// code normalizing an optional cap (`maxPasses: opts.maxPasses ?? Infinity`)
|
|
929
|
+
// is the natural way to hit it. Accepting it also honors this module's own
|
|
930
|
+
// rule that a value which works today is never newly rejected.
|
|
931
|
+
maxPasses: z.union([z.number().int().min(0), z.literal(Number.POSITIVE_INFINITY)]).optional()
|
|
932
|
+
}).loose();
|
|
933
|
+
function resolveSettleConfig(options) {
|
|
934
|
+
if (options === void 0) return void 0;
|
|
935
|
+
SettleOptionsSchema.parse(options);
|
|
936
|
+
return options;
|
|
937
|
+
}
|
|
938
|
+
var MAX_SHUTDOWN_GRACE_MS = 3e4;
|
|
939
|
+
var ShutdownOptionsSchema = z.object({
|
|
940
|
+
// `0` is legal and is exactly today's behavior: stop scheduling and
|
|
941
|
+
// return without waiting.
|
|
942
|
+
graceMs: z.number().min(0).optional()
|
|
943
|
+
}).loose();
|
|
944
|
+
function resolveShutdownConfig(options) {
|
|
945
|
+
if (options === void 0) return void 0;
|
|
946
|
+
ShutdownOptionsSchema.parse(options);
|
|
947
|
+
return options;
|
|
948
|
+
}
|
|
949
|
+
var ActOptionsSchema = z.object({
|
|
950
|
+
maxSubscribedStreams: z.number().int().min(1).optional(),
|
|
951
|
+
settleDebounceMs: z.number().int().min(0).optional(),
|
|
952
|
+
autoSettle: z.boolean().optional()
|
|
953
|
+
}).loose();
|
|
954
|
+
function resolveActConfig(options) {
|
|
955
|
+
if (options === void 0) return void 0;
|
|
956
|
+
ActOptionsSchema.parse(options);
|
|
957
|
+
return options;
|
|
958
|
+
}
|
|
959
|
+
var DEFAULT_AUTOCLOSE_WINDOW_TZ = "UTC";
|
|
960
|
+
function is_valid_time_zone(tz) {
|
|
961
|
+
try {
|
|
962
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
963
|
+
return true;
|
|
964
|
+
} catch {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
var AutocloseWindowSchema = z.object({
|
|
969
|
+
start: z.number().int().min(0).max(23, { message: "autocloseWindow.start must be an hour in [0, 23]" }),
|
|
970
|
+
end: z.number().int().min(0).max(23, { message: "autocloseWindow.end must be an hour in [0, 23]" }),
|
|
971
|
+
timeZone: z.string().refine(is_valid_time_zone, {
|
|
972
|
+
message: "autocloseWindow.timeZone must be a valid IANA time zone"
|
|
973
|
+
}).default(DEFAULT_AUTOCLOSE_WINDOW_TZ)
|
|
974
|
+
}).refine((w) => w.start !== w.end, {
|
|
975
|
+
message: "autocloseWindow.start and end must differ \u2014 an empty window disables autoclose"
|
|
976
|
+
});
|
|
977
|
+
var AutocloseOptionsSchema = z.object({
|
|
978
|
+
autocloseWindow: AutocloseWindowSchema.optional()
|
|
979
|
+
});
|
|
980
|
+
function resolveAutocloseConfig(options) {
|
|
981
|
+
return AutocloseOptionsSchema.parse({
|
|
982
|
+
autocloseWindow: options?.autocloseWindow
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
var DEFAULT_CIRCUIT_FAILURE_THRESHOLD = 5;
|
|
986
|
+
var DEFAULT_CIRCUIT_COOLDOWN_MS = 3e4;
|
|
987
|
+
var CircuitBreakerOptionsSchema = z.object({
|
|
988
|
+
failureThreshold: z.number().int().min(1).default(DEFAULT_CIRCUIT_FAILURE_THRESHOLD),
|
|
989
|
+
cooldownMs: z.number().int().min(100).max(36e5).default(DEFAULT_CIRCUIT_COOLDOWN_MS)
|
|
990
|
+
});
|
|
991
|
+
var resolveCircuitBreakerConfig = (options) => CircuitBreakerOptionsSchema.parse(options ?? {});
|
|
992
|
+
var DEFAULT_FOLD_FLUSH_EVERY = 1e3;
|
|
993
|
+
var DEFAULT_MAX_CACHED_STATES = 1e4;
|
|
994
|
+
var FoldOptionsSchema = z.object({
|
|
995
|
+
flushEvery: z.number().int().min(1).default(DEFAULT_FOLD_FLUSH_EVERY),
|
|
996
|
+
maxCachedStates: z.number().int().min(1).default(DEFAULT_MAX_CACHED_STATES)
|
|
997
|
+
});
|
|
998
|
+
function resolveFoldConfig(options) {
|
|
999
|
+
return FoldOptionsSchema.parse(options);
|
|
1000
|
+
}
|
|
1001
|
+
function check_store(store3) {
|
|
1002
|
+
if (store3.commit.length === 4)
|
|
1003
|
+
throw new Error(
|
|
1004
|
+
"This store's commit takes (stream, msgs, meta, expectedVersion), the shape before @rotorsoft/act 2.0. Upgrade it, and every @rotorsoft/act-* package, together: https://rotorsoft.github.io/act-root/docs/guides/migrating-to-2.x"
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1047
1008
|
// src/scoped.ts
|
|
1048
1009
|
import { AsyncLocalStorage } from "async_hooks";
|
|
1049
1010
|
var scoped = new AsyncLocalStorage();
|
|
@@ -1106,7 +1067,7 @@ var _cache = port(function cache(adapter) {
|
|
|
1106
1067
|
var cache2 = ((adapter) => {
|
|
1107
1068
|
return current_ports()?.cache ?? _cache(adapter);
|
|
1108
1069
|
});
|
|
1109
|
-
var
|
|
1070
|
+
var unscoped_ports = () => DEFAULT_SCOPE;
|
|
1110
1071
|
var DEFAULT_SCOPE = {
|
|
1111
1072
|
get store() {
|
|
1112
1073
|
return _store();
|
|
@@ -1136,7 +1097,7 @@ function dispose(disposer) {
|
|
|
1136
1097
|
}
|
|
1137
1098
|
|
|
1138
1099
|
// src/config.ts
|
|
1139
|
-
var
|
|
1100
|
+
var package_schema = z2.object({
|
|
1140
1101
|
name: z2.string().min(1),
|
|
1141
1102
|
version: z2.string().min(1),
|
|
1142
1103
|
description: z2.string().min(1).optional(),
|
|
@@ -1156,7 +1117,7 @@ var get_package = () => {
|
|
|
1156
1117
|
name: FALLBACK_PACKAGE.name,
|
|
1157
1118
|
version: FALLBACK_PACKAGE.version
|
|
1158
1119
|
};
|
|
1159
|
-
for (const [key, schema] of Object.entries(
|
|
1120
|
+
for (const [key, schema] of Object.entries(package_schema.shape)) {
|
|
1160
1121
|
const field = schema.safeParse(raw?.[key]);
|
|
1161
1122
|
if (field.success && field.data !== void 0) pkg2[key] = field.data;
|
|
1162
1123
|
}
|
|
@@ -1167,7 +1128,7 @@ var get_package = () => {
|
|
|
1167
1128
|
}
|
|
1168
1129
|
};
|
|
1169
1130
|
var pkg_load_error;
|
|
1170
|
-
var BaseSchema =
|
|
1131
|
+
var BaseSchema = package_schema.extend({
|
|
1171
1132
|
env: z2.enum(Environments),
|
|
1172
1133
|
logLevel: z2.enum(LogLevels),
|
|
1173
1134
|
logSingleLine: z2.boolean(),
|
|
@@ -1182,7 +1143,8 @@ var pkg = get_package();
|
|
|
1182
1143
|
var _validated;
|
|
1183
1144
|
var config = () => {
|
|
1184
1145
|
if (!_validated) {
|
|
1185
|
-
_validated =
|
|
1146
|
+
_validated = validate(
|
|
1147
|
+
"config",
|
|
1186
1148
|
{ ...pkg, env, logLevel, logSingleLine, sleepMs },
|
|
1187
1149
|
BaseSchema
|
|
1188
1150
|
);
|
|
@@ -1196,18 +1158,23 @@ var config = () => {
|
|
|
1196
1158
|
}
|
|
1197
1159
|
return _validated;
|
|
1198
1160
|
};
|
|
1199
|
-
function resolveAutocloseConfig2(options) {
|
|
1200
|
-
return resolveAutocloseConfig(options);
|
|
1201
|
-
}
|
|
1202
1161
|
|
|
1203
1162
|
export {
|
|
1204
1163
|
ConsoleLogger,
|
|
1205
1164
|
LruMap,
|
|
1206
1165
|
InMemoryCache,
|
|
1166
|
+
package_schema,
|
|
1167
|
+
config,
|
|
1168
|
+
validate,
|
|
1169
|
+
sleep,
|
|
1170
|
+
InMemoryStore,
|
|
1171
|
+
register_weak_disposer,
|
|
1207
1172
|
DEFAULT_BACKOFF,
|
|
1208
1173
|
DEFAULT_MAX_RETRIES,
|
|
1209
1174
|
DEFAULT_BLOCK_ON_ERROR,
|
|
1210
1175
|
resolveReactionConfig,
|
|
1176
|
+
resolveTargetConfig,
|
|
1177
|
+
is_valid_target,
|
|
1211
1178
|
resolveActionConfig,
|
|
1212
1179
|
resolveLaneConfig,
|
|
1213
1180
|
DEFAULT_STREAM_LIMIT,
|
|
@@ -1222,23 +1189,6 @@ export {
|
|
|
1222
1189
|
resolveCircuitBreakerConfig,
|
|
1223
1190
|
resolveFoldConfig,
|
|
1224
1191
|
check_store,
|
|
1225
|
-
PackageSchema,
|
|
1226
|
-
config,
|
|
1227
|
-
resolveAutocloseConfig2,
|
|
1228
|
-
validate,
|
|
1229
|
-
extend,
|
|
1230
|
-
sleep,
|
|
1231
|
-
is_literal_source,
|
|
1232
|
-
dateReviver,
|
|
1233
|
-
check_appends,
|
|
1234
|
-
concurrency_error,
|
|
1235
|
-
throw_if_stale,
|
|
1236
|
-
seed_event,
|
|
1237
|
-
fair_slots,
|
|
1238
|
-
notification_of,
|
|
1239
|
-
DEFAULT_QUERY_STREAMS_LIMIT,
|
|
1240
|
-
InMemoryStore,
|
|
1241
|
-
register_weak_disposer,
|
|
1242
1192
|
make_run_scoped,
|
|
1243
1193
|
current_autoclose_window,
|
|
1244
1194
|
current_reacting,
|
|
@@ -1247,8 +1197,8 @@ export {
|
|
|
1247
1197
|
log,
|
|
1248
1198
|
store2 as store,
|
|
1249
1199
|
cache2 as cache,
|
|
1250
|
-
|
|
1200
|
+
unscoped_ports,
|
|
1251
1201
|
disposeAndExit,
|
|
1252
1202
|
dispose
|
|
1253
1203
|
};
|
|
1254
|
-
//# sourceMappingURL=chunk-
|
|
1204
|
+
//# sourceMappingURL=chunk-QPVUARKL.js.map
|