@rotorsoft/act 2.1.11 → 2.1.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/README.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +1 -0
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/internal/defer-config.d.ts +2 -3
- package/dist/@types/internal/defer-config.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +0 -5
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +1 -1
- package/dist/adapter.cjs +3 -3
- package/dist/adapter.js +2 -2
- package/dist/{chunk-BQUOIHOR.js → chunk-FYI7O7W6.js} +38 -6
- package/dist/{chunk-BQUOIHOR.js.map → chunk-FYI7O7W6.js.map} +1 -1
- package/dist/{chunk-RV34EYSN.js → chunk-MWLATJDX.js} +11 -3
- package/dist/{chunk-RV34EYSN.js.map → chunk-MWLATJDX.js.map} +1 -1
- package/dist/{chunk-N74AN6L5.cjs → chunk-OW67FBYO.cjs} +83 -55
- package/dist/chunk-OW67FBYO.cjs.map +1 -0
- package/dist/{chunk-SC6TY4P2.cjs → chunk-PDMLWC77.cjs} +12 -4
- package/dist/chunk-PDMLWC77.cjs.map +1 -0
- package/dist/{chunk-ZTHGF62O.cjs → chunk-QSXWCJ2U.cjs} +40 -8
- package/dist/chunk-QSXWCJ2U.cjs.map +1 -0
- package/dist/{chunk-Y2ISPWQL.js → chunk-R5PT4AYJ.js} +70 -42
- package/dist/{chunk-Y2ISPWQL.js.map → chunk-R5PT4AYJ.js.map} +1 -1
- package/dist/index.cjs +514 -367
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +333 -186
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +13 -9
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +11 -7
- package/dist/test/index.js.map +1 -1
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-N74AN6L5.cjs.map +0 -1
- package/dist/chunk-SC6TY4P2.cjs.map +0 -1
- package/dist/chunk-ZTHGF62O.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
store,
|
|
28
28
|
unscoped_ports,
|
|
29
29
|
validate
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-R5PT4AYJ.js";
|
|
31
31
|
import {
|
|
32
32
|
checkAppends,
|
|
33
33
|
checkVersion,
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
isStreamName,
|
|
37
37
|
parseNotification,
|
|
38
38
|
seedEvent
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-MWLATJDX.js";
|
|
40
40
|
import {
|
|
41
41
|
ActorSchema,
|
|
42
42
|
CausationEventSchema,
|
|
@@ -64,6 +64,7 @@ import {
|
|
|
64
64
|
TargetSchema,
|
|
65
65
|
ValidationError,
|
|
66
66
|
ZodEmpty,
|
|
67
|
+
__name,
|
|
67
68
|
def_of,
|
|
68
69
|
inner_of,
|
|
69
70
|
output_of,
|
|
@@ -71,7 +72,7 @@ import {
|
|
|
71
72
|
pii_schemas,
|
|
72
73
|
sensitive,
|
|
73
74
|
sensitiveFields
|
|
74
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-FYI7O7W6.js";
|
|
75
76
|
|
|
76
77
|
// src/signals.ts
|
|
77
78
|
process.once("SIGINT", async (arg) => {
|
|
@@ -83,10 +84,12 @@ process.once("SIGTERM", async (arg) => {
|
|
|
83
84
|
await disposeAndExit("EXIT");
|
|
84
85
|
});
|
|
85
86
|
process.once("uncaughtException", async (arg) => {
|
|
87
|
+
process.exitCode = 1;
|
|
86
88
|
log().error(arg, "Uncaught Exception");
|
|
87
89
|
await disposeAndExit("ERROR");
|
|
88
90
|
});
|
|
89
91
|
process.once("unhandledRejection", async (arg) => {
|
|
92
|
+
process.exitCode = 1;
|
|
90
93
|
log().error(arg, "Unhandled Rejection");
|
|
91
94
|
await disposeAndExit("ERROR");
|
|
92
95
|
});
|
|
@@ -104,6 +107,7 @@ function parse(name) {
|
|
|
104
107
|
}
|
|
105
108
|
return { base: name, version: 1 };
|
|
106
109
|
}
|
|
110
|
+
__name(parse, "parse");
|
|
107
111
|
function deprecated_event_names(names) {
|
|
108
112
|
const groups = /* @__PURE__ */ new Map();
|
|
109
113
|
for (const name of names) {
|
|
@@ -129,6 +133,7 @@ function deprecated_event_names(names) {
|
|
|
129
133
|
}
|
|
130
134
|
return deprecated;
|
|
131
135
|
}
|
|
136
|
+
__name(deprecated_event_names, "deprecated_event_names");
|
|
132
137
|
function current_version_of(deprecated_name, all_names) {
|
|
133
138
|
const target = parse(deprecated_name);
|
|
134
139
|
let highest;
|
|
@@ -139,6 +144,7 @@ function current_version_of(deprecated_name, all_names) {
|
|
|
139
144
|
}
|
|
140
145
|
return highest && highest.version > target.version ? highest.name : void 0;
|
|
141
146
|
}
|
|
147
|
+
__name(current_version_of, "current_version_of");
|
|
142
148
|
|
|
143
149
|
// src/internal/walk-streams.ts
|
|
144
150
|
var DEFAULT_STREAM_PAGE = 500;
|
|
@@ -160,6 +166,7 @@ async function walk_streams(store2, callback, query) {
|
|
|
160
166
|
after = last;
|
|
161
167
|
}
|
|
162
168
|
}
|
|
169
|
+
__name(walk_streams, "walk_streams");
|
|
163
170
|
|
|
164
171
|
// src/internal/audit.ts
|
|
165
172
|
var DEFAULTS = {
|
|
@@ -224,6 +231,7 @@ async function* audit(deps, categories, options = {}) {
|
|
|
224
231
|
for (const f of p.drain()) yield f;
|
|
225
232
|
}
|
|
226
233
|
}
|
|
234
|
+
__name(audit, "audit");
|
|
227
235
|
async function scan_events_resiliently(deps, query, on_event, on_unreadable) {
|
|
228
236
|
let cursor = query?.after;
|
|
229
237
|
let remaining = query?.limit;
|
|
@@ -259,7 +267,8 @@ async function scan_events_resiliently(deps, query, on_event, on_unreadable) {
|
|
|
259
267
|
}
|
|
260
268
|
}
|
|
261
269
|
}
|
|
262
|
-
|
|
270
|
+
__name(scan_events_resiliently, "scan_events_resiliently");
|
|
271
|
+
var make_schema_pass = /* @__PURE__ */ __name((deps) => {
|
|
263
272
|
const findings = [];
|
|
264
273
|
return {
|
|
265
274
|
category: "schema",
|
|
@@ -302,10 +311,10 @@ var make_schema_pass = (deps) => {
|
|
|
302
311
|
});
|
|
303
312
|
}
|
|
304
313
|
},
|
|
305
|
-
drain: () => findings
|
|
314
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
306
315
|
};
|
|
307
|
-
};
|
|
308
|
-
var classify_deprecated_by_state = (deps) => {
|
|
316
|
+
}, "make_schema_pass");
|
|
317
|
+
var classify_deprecated_by_state = /* @__PURE__ */ __name((deps) => {
|
|
309
318
|
const names_by_state = /* @__PURE__ */ new Map();
|
|
310
319
|
for (const [name, state2] of deps.event_to_state) {
|
|
311
320
|
let set = names_by_state.get(state2);
|
|
@@ -322,8 +331,8 @@ var classify_deprecated_by_state = (deps) => {
|
|
|
322
331
|
}
|
|
323
332
|
}
|
|
324
333
|
return deprecated_to_current;
|
|
325
|
-
};
|
|
326
|
-
var make_deprecated_load_pass = (deps, options) => {
|
|
334
|
+
}, "classify_deprecated_by_state");
|
|
335
|
+
var make_deprecated_load_pass = /* @__PURE__ */ __name((deps, options) => {
|
|
327
336
|
const share_min = options.thresholds?.deprecated_min ?? DEFAULTS.deprecated_min;
|
|
328
337
|
const totals = /* @__PURE__ */ new Map();
|
|
329
338
|
const per_stream = /* @__PURE__ */ new Map();
|
|
@@ -362,8 +371,8 @@ var make_deprecated_load_pass = (deps, options) => {
|
|
|
362
371
|
return findings;
|
|
363
372
|
}
|
|
364
373
|
};
|
|
365
|
-
};
|
|
366
|
-
var make_close_candidate_pass = (deps, options) => {
|
|
374
|
+
}, "make_deprecated_load_pass");
|
|
375
|
+
var make_close_candidate_pass = /* @__PURE__ */ __name((deps, options) => {
|
|
367
376
|
const idle_days = options.thresholds?.idle_days ?? DEFAULTS.idle_days;
|
|
368
377
|
const terminal_events = new Set(options.thresholds?.terminal_events ?? []);
|
|
369
378
|
const idle_cutoff = Date.now() - idle_days * 24 * 60 * 60 * 1e3;
|
|
@@ -386,10 +395,10 @@ var make_close_candidate_pass = (deps, options) => {
|
|
|
386
395
|
restart_supported: restart_is_supported(deps, head_name)
|
|
387
396
|
});
|
|
388
397
|
},
|
|
389
|
-
drain: () => findings
|
|
398
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
390
399
|
};
|
|
391
|
-
};
|
|
392
|
-
var make_restart_candidate_pass = (deps, options) => {
|
|
400
|
+
}, "make_close_candidate_pass");
|
|
401
|
+
var make_restart_candidate_pass = /* @__PURE__ */ __name((deps, options) => {
|
|
393
402
|
const threshold = options.thresholds?.restart_min ?? DEFAULTS.restart_min;
|
|
394
403
|
const candidates = [];
|
|
395
404
|
const findings = [];
|
|
@@ -426,10 +435,10 @@ var make_restart_candidate_pass = (deps, options) => {
|
|
|
426
435
|
});
|
|
427
436
|
}
|
|
428
437
|
},
|
|
429
|
-
drain: () => findings
|
|
438
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
430
439
|
};
|
|
431
|
-
};
|
|
432
|
-
var make_reaction_health_pass = (_deps, options) => {
|
|
440
|
+
}, "make_restart_candidate_pass");
|
|
441
|
+
var make_reaction_health_pass = /* @__PURE__ */ __name((_deps, options) => {
|
|
433
442
|
const near_block = options.thresholds?.near_block ?? DEFAULTS.near_block;
|
|
434
443
|
const stuck_minutes = options.thresholds?.stuck_minutes ?? DEFAULTS.stuck_minutes;
|
|
435
444
|
const stuck_cutoff = Date.now() - stuck_minutes * 60 * 1e3;
|
|
@@ -470,10 +479,10 @@ var make_reaction_health_pass = (_deps, options) => {
|
|
|
470
479
|
});
|
|
471
480
|
}
|
|
472
481
|
},
|
|
473
|
-
drain: () => findings
|
|
482
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
474
483
|
};
|
|
475
|
-
};
|
|
476
|
-
var make_snapshot_drift_pass = (deps, options) => {
|
|
484
|
+
}, "make_reaction_health_pass");
|
|
485
|
+
var make_snapshot_drift_pass = /* @__PURE__ */ __name((deps, options) => {
|
|
477
486
|
const drift_min = options.thresholds?.drift_min ?? DEFAULTS.drift_min;
|
|
478
487
|
const candidates = [];
|
|
479
488
|
const findings = [];
|
|
@@ -525,10 +534,10 @@ var make_snapshot_drift_pass = (deps, options) => {
|
|
|
525
534
|
});
|
|
526
535
|
}
|
|
527
536
|
},
|
|
528
|
-
drain: () => findings
|
|
537
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
529
538
|
};
|
|
530
|
-
};
|
|
531
|
-
var make_routing_health_pass = (deps) => {
|
|
539
|
+
}, "make_snapshot_drift_pass");
|
|
540
|
+
var make_routing_health_pass = /* @__PURE__ */ __name((deps) => {
|
|
532
541
|
const findings = [];
|
|
533
542
|
const seen_event_names = /* @__PURE__ */ new Set();
|
|
534
543
|
return {
|
|
@@ -560,10 +569,10 @@ var make_routing_health_pass = (deps) => {
|
|
|
560
569
|
}
|
|
561
570
|
return Promise.resolve();
|
|
562
571
|
},
|
|
563
|
-
drain: () => findings
|
|
572
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
564
573
|
};
|
|
565
|
-
};
|
|
566
|
-
var make_correlation_gaps_pass = () => {
|
|
574
|
+
}, "make_routing_health_pass");
|
|
575
|
+
var make_correlation_gaps_pass = /* @__PURE__ */ __name(() => {
|
|
567
576
|
const seen_ids = /* @__PURE__ */ new Set();
|
|
568
577
|
const checks = [];
|
|
569
578
|
return {
|
|
@@ -591,8 +600,8 @@ var make_correlation_gaps_pass = () => {
|
|
|
591
600
|
return findings;
|
|
592
601
|
}
|
|
593
602
|
};
|
|
594
|
-
};
|
|
595
|
-
var make_clock_anomalies_pass = () => {
|
|
603
|
+
}, "make_correlation_gaps_pass");
|
|
604
|
+
var make_clock_anomalies_pass = /* @__PURE__ */ __name(() => {
|
|
596
605
|
const findings = [];
|
|
597
606
|
const last_per_stream = /* @__PURE__ */ new Map();
|
|
598
607
|
return {
|
|
@@ -618,13 +627,14 @@ var make_clock_anomalies_pass = () => {
|
|
|
618
627
|
}
|
|
619
628
|
last_per_stream.set(e.stream, created);
|
|
620
629
|
},
|
|
621
|
-
drain: () => findings
|
|
630
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
622
631
|
};
|
|
623
|
-
};
|
|
632
|
+
}, "make_clock_anomalies_pass");
|
|
624
633
|
function restart_is_supported(deps, head_event_name) {
|
|
625
634
|
const state2 = deps.event_to_state.get(head_event_name);
|
|
626
635
|
return state2?.snap !== void 0;
|
|
627
636
|
}
|
|
637
|
+
__name(restart_is_supported, "restart_is_supported");
|
|
628
638
|
function make_unreadable_events_pass() {
|
|
629
639
|
const findings = [];
|
|
630
640
|
return {
|
|
@@ -638,9 +648,10 @@ function make_unreadable_events_pass() {
|
|
|
638
648
|
error
|
|
639
649
|
});
|
|
640
650
|
},
|
|
641
|
-
drain: () => findings
|
|
651
|
+
drain: /* @__PURE__ */ __name(() => findings, "drain")
|
|
642
652
|
};
|
|
643
653
|
}
|
|
654
|
+
__name(make_unreadable_events_pass, "make_unreadable_events_pass");
|
|
644
655
|
var PASS_FACTORIES = {
|
|
645
656
|
schema: make_schema_pass,
|
|
646
657
|
"deprecated-load": make_deprecated_load_pass,
|
|
@@ -656,6 +667,9 @@ var PASS_FACTORIES = {
|
|
|
656
667
|
|
|
657
668
|
// src/internal/circuit-breaker.ts
|
|
658
669
|
var CircuitBreaker = class {
|
|
670
|
+
static {
|
|
671
|
+
__name(this, "CircuitBreaker");
|
|
672
|
+
}
|
|
659
673
|
_failures = 0;
|
|
660
674
|
_opened_at;
|
|
661
675
|
_wake;
|
|
@@ -747,7 +761,7 @@ var CircuitBreaker = class {
|
|
|
747
761
|
|
|
748
762
|
// src/internal/classify.ts
|
|
749
763
|
var ALL_LANES = /* @__PURE__ */ Symbol("act/all-lanes");
|
|
750
|
-
var describe_source = (source) => source === void 0 ? "no source (every stream)" : `"${source}"
|
|
764
|
+
var describe_source = /* @__PURE__ */ __name((source) => source === void 0 ? "no source (every stream)" : `"${source}"`, "describe_source");
|
|
751
765
|
function classify_registry(registry, states) {
|
|
752
766
|
const statics = /* @__PURE__ */ new Map();
|
|
753
767
|
const target_lanes = /* @__PURE__ */ new Map();
|
|
@@ -798,33 +812,41 @@ function classify_registry(registry, states) {
|
|
|
798
812
|
event_to_lanes
|
|
799
813
|
};
|
|
800
814
|
}
|
|
815
|
+
__name(classify_registry, "classify_registry");
|
|
801
816
|
|
|
802
817
|
// src/internal/autoclose-policy.ts
|
|
803
818
|
var DAY_MS = 864e5;
|
|
804
819
|
function days_after(date, days) {
|
|
805
820
|
return new Date(date.getTime() + days * DAY_MS);
|
|
806
821
|
}
|
|
822
|
+
__name(days_after, "days_after");
|
|
807
823
|
function days_before_now(days) {
|
|
808
824
|
return new Date(Date.now() - days * DAY_MS);
|
|
809
825
|
}
|
|
826
|
+
__name(days_before_now, "days_before_now");
|
|
810
827
|
function compile_after(after) {
|
|
811
828
|
return (_stream, head) => days_after(head.created, after.days) <= /* @__PURE__ */ new Date();
|
|
812
829
|
}
|
|
830
|
+
__name(compile_after, "compile_after");
|
|
813
831
|
function compile_is(is) {
|
|
814
832
|
const set = new Set(typeof is === "string" ? [is] : is);
|
|
815
833
|
return (_stream, head) => set.has(head.name);
|
|
816
834
|
}
|
|
835
|
+
__name(compile_is, "compile_is");
|
|
817
836
|
function compile_reaches(reaches) {
|
|
818
837
|
return (_stream, _head, count) => count >= reaches;
|
|
819
838
|
}
|
|
839
|
+
__name(compile_reaches, "compile_reaches");
|
|
820
840
|
function policy_after_windows(options) {
|
|
821
841
|
const parsed = check("autoclose_policy", options);
|
|
822
842
|
return [parsed.after, parsed.or?.after].flatMap((w) => w ? [w.days] : []);
|
|
823
843
|
}
|
|
844
|
+
__name(policy_after_windows, "policy_after_windows");
|
|
824
845
|
function policy_keep_days(options) {
|
|
825
846
|
const parsed = check("autoclose_policy", options);
|
|
826
847
|
return parsed.keep?.days;
|
|
827
848
|
}
|
|
849
|
+
__name(policy_keep_days, "policy_keep_days");
|
|
828
850
|
function compile_autoclose_policy(options) {
|
|
829
851
|
const parsed = check("autoclose_policy", options);
|
|
830
852
|
const and_preds = [];
|
|
@@ -847,6 +869,7 @@ function compile_autoclose_policy(options) {
|
|
|
847
869
|
return false;
|
|
848
870
|
};
|
|
849
871
|
}
|
|
872
|
+
__name(compile_autoclose_policy, "compile_autoclose_policy");
|
|
850
873
|
|
|
851
874
|
// src/internal/autoclose-window.ts
|
|
852
875
|
function hour_in_zone(now, timeZone) {
|
|
@@ -857,20 +880,24 @@ function hour_in_zone(now, timeZone) {
|
|
|
857
880
|
}).formatToParts(now);
|
|
858
881
|
return Number(parts.find((p) => p.type === "hour")?.value);
|
|
859
882
|
}
|
|
883
|
+
__name(hour_in_zone, "hour_in_zone");
|
|
860
884
|
function hour_in_range(hour, start, end) {
|
|
861
885
|
return start < end ? hour >= start && hour < end : hour >= start || hour < end;
|
|
862
886
|
}
|
|
887
|
+
__name(hour_in_range, "hour_in_range");
|
|
863
888
|
function is_dst_gap_open(now, timeZone, start) {
|
|
864
889
|
const hour = hour_in_zone(now, timeZone);
|
|
865
890
|
if (hour <= start) return false;
|
|
866
891
|
const prev = hour_in_zone(new Date(now.getTime() - 36e5), timeZone);
|
|
867
892
|
return prev === start - 1 && hour === start + 1;
|
|
868
893
|
}
|
|
894
|
+
__name(is_dst_gap_open, "is_dst_gap_open");
|
|
869
895
|
function in_autoclose_window(window, now) {
|
|
870
896
|
if (!window) return true;
|
|
871
897
|
const hour = hour_in_zone(now, window.timeZone);
|
|
872
898
|
return hour_in_range(hour, window.start, window.end) || is_dst_gap_open(now, window.timeZone, window.start);
|
|
873
899
|
}
|
|
900
|
+
__name(in_autoclose_window, "in_autoclose_window");
|
|
874
901
|
function next_window_open(window, now) {
|
|
875
902
|
const start_ms = now.getTime();
|
|
876
903
|
for (let h = 0; h <= 48; h++) {
|
|
@@ -885,26 +912,30 @@ function next_window_open(window, now) {
|
|
|
885
912
|
}
|
|
886
913
|
return new Date(start_ms + 864e5);
|
|
887
914
|
}
|
|
915
|
+
__name(next_window_open, "next_window_open");
|
|
888
916
|
|
|
889
917
|
// src/internal/defer-config.ts
|
|
890
918
|
function duration_ms(d) {
|
|
891
919
|
return (d.days ?? 0) * 864e5 + (d.hours ?? 0) * 36e5 + (d.minutes ?? 0) * 6e4;
|
|
892
920
|
}
|
|
921
|
+
__name(duration_ms, "duration_ms");
|
|
893
922
|
function resolve_defer_at(when, event) {
|
|
894
923
|
const parsed = check("defer", when);
|
|
895
924
|
if (parsed.after) return event.created.getTime() + duration_ms(parsed.after);
|
|
896
925
|
return parsed.at.getTime();
|
|
897
926
|
}
|
|
927
|
+
__name(resolve_defer_at, "resolve_defer_at");
|
|
898
928
|
function make_deferred(handler, schedule) {
|
|
899
929
|
const call = handler;
|
|
900
|
-
const deferred = async (event, stream, app) => {
|
|
930
|
+
const deferred = /* @__PURE__ */ __name(async (event, stream, app) => {
|
|
901
931
|
const when = typeof schedule === "function" ? schedule(event) : schedule;
|
|
902
932
|
if (Date.now() < resolve_defer_at(when, event)) throw new DeferSignal(when);
|
|
903
933
|
return call(event, stream, app);
|
|
904
|
-
};
|
|
934
|
+
}, "deferred");
|
|
905
935
|
Object.defineProperty(deferred, "name", { value: handler.name });
|
|
906
936
|
return deferred;
|
|
907
937
|
}
|
|
938
|
+
__name(make_deferred, "make_deferred");
|
|
908
939
|
|
|
909
940
|
// src/internal/drain-cycle.ts
|
|
910
941
|
import { randomUUID } from "crypto";
|
|
@@ -933,10 +964,14 @@ function compute_backoff_delay(retry, opts) {
|
|
|
933
964
|
if (opts.jitter) delay = delay * (0.5 + Math.random());
|
|
934
965
|
return Math.max(0, Math.floor(delay));
|
|
935
966
|
}
|
|
967
|
+
__name(compute_backoff_delay, "compute_backoff_delay");
|
|
936
968
|
|
|
937
969
|
// src/internal/defer-timer.ts
|
|
938
970
|
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
939
971
|
var DeferTimer = class {
|
|
972
|
+
static {
|
|
973
|
+
__name(this, "DeferTimer");
|
|
974
|
+
}
|
|
940
975
|
_due = /* @__PURE__ */ new Map();
|
|
941
976
|
_timer;
|
|
942
977
|
_on_wake;
|
|
@@ -1026,6 +1061,7 @@ function compute_lag_lead_ratio(handled, lagging, leading) {
|
|
|
1026
1061
|
if (total === 0) return RATIO_DEFAULT;
|
|
1027
1062
|
return Math.max(RATIO_MIN, Math.min(RATIO_MAX, lagging_avg / total));
|
|
1028
1063
|
}
|
|
1064
|
+
__name(compute_lag_lead_ratio, "compute_lag_lead_ratio");
|
|
1029
1065
|
|
|
1030
1066
|
// src/internal/report-once.ts
|
|
1031
1067
|
function report_once(seen, key, message) {
|
|
@@ -1033,6 +1069,7 @@ function report_once(seen, key, message) {
|
|
|
1033
1069
|
seen.add(key);
|
|
1034
1070
|
log().error(new Error(message));
|
|
1035
1071
|
}
|
|
1072
|
+
__name(report_once, "report_once");
|
|
1036
1073
|
|
|
1037
1074
|
// src/internal/correlation-id.ts
|
|
1038
1075
|
import { randomInt } from "crypto";
|
|
@@ -1042,13 +1079,14 @@ var SEG_SPACE = BASE ** SEG_WIDTH;
|
|
|
1042
1079
|
function seg(n) {
|
|
1043
1080
|
return n.toString(BASE).padStart(SEG_WIDTH, "0");
|
|
1044
1081
|
}
|
|
1045
|
-
|
|
1082
|
+
__name(seg, "seg");
|
|
1083
|
+
var default_correlator = /* @__PURE__ */ __name(({ state: state2, action: action2 }) => {
|
|
1046
1084
|
const s = state2.slice(0, SEG_WIDTH).toLowerCase();
|
|
1047
1085
|
const a = action2.slice(0, SEG_WIDTH).toLowerCase();
|
|
1048
1086
|
const ts = seg(Date.now() % SEG_SPACE);
|
|
1049
1087
|
const rnd = seg(randomInt(SEG_SPACE));
|
|
1050
1088
|
return `${s}-${a}-${ts}${rnd}`;
|
|
1051
|
-
};
|
|
1089
|
+
}, "default_correlator");
|
|
1052
1090
|
function close_correlation(correlator, actor) {
|
|
1053
1091
|
return correlator({
|
|
1054
1092
|
state: "$close",
|
|
@@ -1057,9 +1095,10 @@ function close_correlation(correlator, actor) {
|
|
|
1057
1095
|
actor
|
|
1058
1096
|
});
|
|
1059
1097
|
}
|
|
1098
|
+
__name(close_correlation, "close_correlation");
|
|
1060
1099
|
|
|
1061
1100
|
// src/internal/drain-ops.ts
|
|
1062
|
-
var claim = (lagging, leading, by, millis, lane) => store().claim(lagging, leading, by, millis, lane);
|
|
1101
|
+
var claim = /* @__PURE__ */ __name((lagging, leading, by, millis, lane) => store().claim(lagging, leading, by, millis, lane), "claim");
|
|
1063
1102
|
async function fetch(leased, eventLimit) {
|
|
1064
1103
|
return Promise.all(
|
|
1065
1104
|
leased.map(async ({ stream, source, at, lagging }) => {
|
|
@@ -1086,9 +1125,10 @@ async function fetch(leased, eventLimit) {
|
|
|
1086
1125
|
})
|
|
1087
1126
|
);
|
|
1088
1127
|
}
|
|
1089
|
-
|
|
1090
|
-
var
|
|
1091
|
-
var
|
|
1128
|
+
__name(fetch, "fetch");
|
|
1129
|
+
var ack = /* @__PURE__ */ __name((leases) => store().ack(leases), "ack");
|
|
1130
|
+
var block = /* @__PURE__ */ __name((leases) => store().block(leases), "block");
|
|
1131
|
+
var subscribe = /* @__PURE__ */ __name((streams, correlated_at, correlator) => store().subscribe(streams, correlated_at, correlator), "subscribe");
|
|
1092
1132
|
|
|
1093
1133
|
// src/internal/event-sourcing.ts
|
|
1094
1134
|
import { patch } from "@rotorsoft/act-patch";
|
|
@@ -1111,12 +1151,13 @@ function variant_schema(schema, walk) {
|
|
|
1111
1151
|
}
|
|
1112
1152
|
return { schema: z.looseObject(next), dated };
|
|
1113
1153
|
}
|
|
1154
|
+
__name(variant_schema, "variant_schema");
|
|
1114
1155
|
function date_reviver_schema(schema) {
|
|
1115
1156
|
let recursive = false;
|
|
1116
|
-
const pass = (tie) => {
|
|
1157
|
+
const pass = /* @__PURE__ */ __name((tie) => {
|
|
1117
1158
|
const done = /* @__PURE__ */ new Map();
|
|
1118
1159
|
const active = /* @__PURE__ */ new Set();
|
|
1119
|
-
const walk = (node) => {
|
|
1160
|
+
const walk = /* @__PURE__ */ __name((node) => {
|
|
1120
1161
|
if (done.has(node)) return done.get(node);
|
|
1121
1162
|
if (active.has(node)) {
|
|
1122
1163
|
recursive = true;
|
|
@@ -1127,16 +1168,17 @@ function date_reviver_schema(schema) {
|
|
|
1127
1168
|
active.delete(node);
|
|
1128
1169
|
done.set(node, result);
|
|
1129
1170
|
return result;
|
|
1130
|
-
};
|
|
1171
|
+
}, "walk");
|
|
1131
1172
|
return walk(schema);
|
|
1132
|
-
};
|
|
1173
|
+
}, "pass");
|
|
1133
1174
|
const first = pass(false);
|
|
1134
1175
|
return first && recursive ? pass(true) : first;
|
|
1135
1176
|
}
|
|
1177
|
+
__name(date_reviver_schema, "date_reviver_schema");
|
|
1136
1178
|
function build(schema, walk) {
|
|
1137
1179
|
const def = def_of(schema);
|
|
1138
1180
|
if (!def) return void 0;
|
|
1139
|
-
const inner = () => walk(def.innerType);
|
|
1181
|
+
const inner = /* @__PURE__ */ __name(() => walk(def.innerType), "inner");
|
|
1140
1182
|
switch (def.type) {
|
|
1141
1183
|
case "date":
|
|
1142
1184
|
return z.coerce.date();
|
|
@@ -1183,14 +1225,15 @@ function build(schema, walk) {
|
|
|
1183
1225
|
return inner_of(def) ? inner() : void 0;
|
|
1184
1226
|
}
|
|
1185
1227
|
}
|
|
1228
|
+
__name(build, "build");
|
|
1186
1229
|
|
|
1187
1230
|
// src/internal/event-sourcing.ts
|
|
1188
|
-
var bare_patch = (_me, state2, partial) => patch(state2, partial);
|
|
1189
|
-
var value_at = (value, path) => path.reduce(
|
|
1231
|
+
var bare_patch = /* @__PURE__ */ __name((_me, state2, partial) => patch(state2, partial), "bare_patch");
|
|
1232
|
+
var value_at = /* @__PURE__ */ __name((value, path) => path.reduce(
|
|
1190
1233
|
(at, key) => at?.[key],
|
|
1191
1234
|
value
|
|
1192
|
-
);
|
|
1193
|
-
var check_invariants = (target, state2, schema, pii_aware) => {
|
|
1235
|
+
), "value_at");
|
|
1236
|
+
var check_invariants = /* @__PURE__ */ __name((target, state2, schema, pii_aware) => {
|
|
1194
1237
|
let result;
|
|
1195
1238
|
try {
|
|
1196
1239
|
result = schema.safeParse(state2);
|
|
@@ -1208,20 +1251,20 @@ var check_invariants = (target, state2, schema, pii_aware) => {
|
|
|
1208
1251
|
state2,
|
|
1209
1252
|
prettifyError(new ZodError(issues))
|
|
1210
1253
|
);
|
|
1211
|
-
};
|
|
1254
|
+
}, "check_invariants");
|
|
1212
1255
|
var DEFAULT_BATCH = 500;
|
|
1213
|
-
var cache_put = (stream, entry) => cache().set(stream, entry).catch(
|
|
1256
|
+
var cache_put = /* @__PURE__ */ __name((stream, entry) => cache().set(stream, entry).catch(
|
|
1214
1257
|
(err) => log().warn(
|
|
1215
1258
|
err,
|
|
1216
1259
|
"cache set skipped; the next load re-folds from the store"
|
|
1217
1260
|
)
|
|
1218
|
-
);
|
|
1219
|
-
var cache_drop = (stream) => cache().invalidate(stream).catch(
|
|
1261
|
+
), "cache_put");
|
|
1262
|
+
var cache_drop = /* @__PURE__ */ __name((stream) => cache().invalidate(stream).catch(
|
|
1220
1263
|
(err) => log().warn(
|
|
1221
1264
|
err,
|
|
1222
1265
|
"cache invalidate skipped; a stale checkpoint re-folds from its event_id"
|
|
1223
1266
|
)
|
|
1224
|
-
);
|
|
1267
|
+
), "cache_drop");
|
|
1225
1268
|
async function snap(snapshot) {
|
|
1226
1269
|
const { id, stream, name, meta, version } = snapshot.event;
|
|
1227
1270
|
try {
|
|
@@ -1247,6 +1290,7 @@ async function snap(snapshot) {
|
|
|
1247
1290
|
);
|
|
1248
1291
|
}
|
|
1249
1292
|
}
|
|
1293
|
+
__name(snap, "snap");
|
|
1250
1294
|
async function tombstone(stream, expectedVersion, correlation) {
|
|
1251
1295
|
try {
|
|
1252
1296
|
const [committed] = await store().commit(
|
|
@@ -1265,12 +1309,14 @@ async function tombstone(stream, expectedVersion, correlation) {
|
|
|
1265
1309
|
throw error;
|
|
1266
1310
|
}
|
|
1267
1311
|
}
|
|
1312
|
+
__name(tombstone, "tombstone");
|
|
1268
1313
|
function is_valid(event) {
|
|
1269
1314
|
if (event.version < 0) return false;
|
|
1270
1315
|
if (!(event.created instanceof Date) || Number.isNaN(event.created.getTime()))
|
|
1271
1316
|
return false;
|
|
1272
1317
|
return true;
|
|
1273
1318
|
}
|
|
1319
|
+
__name(is_valid, "is_valid");
|
|
1274
1320
|
async function scan(source, opts = {}, callback) {
|
|
1275
1321
|
const {
|
|
1276
1322
|
drop_snapshots = false,
|
|
@@ -1402,6 +1448,7 @@ async function scan(source, opts = {}, callback) {
|
|
|
1402
1448
|
}
|
|
1403
1449
|
};
|
|
1404
1450
|
}
|
|
1451
|
+
__name(scan, "scan");
|
|
1405
1452
|
async function load(me, target, callback, patch_fn = bare_patch) {
|
|
1406
1453
|
const { stream, actor, asOf } = target;
|
|
1407
1454
|
const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
|
|
@@ -1478,6 +1525,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1478
1525
|
replayed
|
|
1479
1526
|
};
|
|
1480
1527
|
}
|
|
1528
|
+
__name(load, "load");
|
|
1481
1529
|
async function load_others(loads, payload, own, actor, patch_fn, refuse) {
|
|
1482
1530
|
const streams = loads.map((l) => l.target(payload, own.state));
|
|
1483
1531
|
streams.forEach((stream, i) => {
|
|
@@ -1510,6 +1558,7 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
|
|
|
1510
1558
|
})
|
|
1511
1559
|
);
|
|
1512
1560
|
}
|
|
1561
|
+
__name(load_others, "load_others");
|
|
1513
1562
|
async function action(me, action2, target, payload, options, patch_fn = bare_patch) {
|
|
1514
1563
|
const { stream, expectedVersion, actor } = target;
|
|
1515
1564
|
if (!stream) throw new Error("Missing target stream");
|
|
@@ -1695,6 +1744,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1695
1744
|
}
|
|
1696
1745
|
}
|
|
1697
1746
|
}
|
|
1747
|
+
__name(action, "action");
|
|
1698
1748
|
|
|
1699
1749
|
// src/internal/tracing.ts
|
|
1700
1750
|
var PRETTY = config().env !== "production";
|
|
@@ -1706,32 +1756,32 @@ var C_DRAIN = "\x1B[38;5;244m";
|
|
|
1706
1756
|
var C_HIT = "\x1B[38;5;82m";
|
|
1707
1757
|
var C_MISS = "\x1B[38;5;220m";
|
|
1708
1758
|
var C_RESET = "\x1B[0m";
|
|
1709
|
-
var es_caption = (caption, color, body) => PRETTY ? `${color}${body}${C_RESET}` : `${caption}: ${body}
|
|
1759
|
+
var es_caption = /* @__PURE__ */ __name((caption, color, body) => PRETTY ? `${color}${body}${C_RESET}` : `${caption}: ${body}`, "es_caption");
|
|
1710
1760
|
var C_LANE = "\x1B[38;5;183m";
|
|
1711
1761
|
var C_DIM = "\x1B[38;5;240m";
|
|
1712
1762
|
var C_ERR = "\x1B[38;5;196m";
|
|
1713
1763
|
var C_STREAM = "\x1B[38;5;226m";
|
|
1714
|
-
var dim = (text) => PRETTY ? `${C_DIM}${text}${C_RESET}` : text;
|
|
1715
|
-
var hue = (color, text) => PRETTY ? `${color}${text}${C_RESET}` : text;
|
|
1716
|
-
var drain_caption = (caption, lane) => {
|
|
1764
|
+
var dim = /* @__PURE__ */ __name((text) => PRETTY ? `${C_DIM}${text}${C_RESET}` : text, "dim");
|
|
1765
|
+
var hue = /* @__PURE__ */ __name((color, text) => PRETTY ? `${color}${text}${C_RESET}` : text, "hue");
|
|
1766
|
+
var drain_caption = /* @__PURE__ */ __name((caption, lane) => {
|
|
1717
1767
|
const show_lane = lane && lane !== "default";
|
|
1718
1768
|
if (PRETTY) {
|
|
1719
1769
|
const tag = `${C_DRAIN}>> ${caption}${C_RESET}`;
|
|
1720
1770
|
return show_lane ? `${tag} ${C_LANE}${lane}${C_RESET}` : tag;
|
|
1721
1771
|
}
|
|
1722
1772
|
return show_lane ? `>> ${caption} ${lane}` : `>> ${caption}`;
|
|
1723
|
-
};
|
|
1724
|
-
var cache_marker = (hit) => {
|
|
1773
|
+
}, "drain_caption");
|
|
1774
|
+
var cache_marker = /* @__PURE__ */ __name((hit) => {
|
|
1725
1775
|
const word = hit ? "hit" : "miss";
|
|
1726
1776
|
if (!PRETTY) return word;
|
|
1727
1777
|
return `${hit ? C_HIT : C_MISS}${word}${C_RESET}${C_GREEN}`;
|
|
1728
|
-
};
|
|
1729
|
-
var stats_marker = (version, replayed, snaps, patches) => {
|
|
1778
|
+
}, "cache_marker");
|
|
1779
|
+
var stats_marker = /* @__PURE__ */ __name((version, replayed, snaps, patches) => {
|
|
1730
1780
|
const text = `v=${version} replayed=${replayed} snaps=${snaps} patches=${patches}`;
|
|
1731
1781
|
if (!PRETTY) return text;
|
|
1732
1782
|
return `${C_DRAIN}${text}${C_RESET}${C_GREEN}`;
|
|
1733
|
-
};
|
|
1734
|
-
var as_of_marker = (asOf) => {
|
|
1783
|
+
}, "stats_marker");
|
|
1784
|
+
var as_of_marker = /* @__PURE__ */ __name((asOf) => {
|
|
1735
1785
|
if (!asOf) return "";
|
|
1736
1786
|
const parts = [];
|
|
1737
1787
|
if (asOf.before !== void 0) parts.push(`before=${asOf.before}`);
|
|
@@ -1741,23 +1791,23 @@ var as_of_marker = (asOf) => {
|
|
|
1741
1791
|
parts.push(`created_after=${asOf.created_after.toISOString()}`);
|
|
1742
1792
|
if (asOf.limit !== void 0) parts.push(`limit=${asOf.limit}`);
|
|
1743
1793
|
return parts.length ? ` (as-of ${parts.join(" ")})` : " (as-of)";
|
|
1744
|
-
};
|
|
1745
|
-
var traced = (inner, exit, entry) => (async (...args) => {
|
|
1794
|
+
}, "as_of_marker");
|
|
1795
|
+
var traced = /* @__PURE__ */ __name((inner, exit, entry) => (async (...args) => {
|
|
1746
1796
|
entry?.(...args);
|
|
1747
1797
|
const result = await inner(...args);
|
|
1748
1798
|
exit?.(result, ...args);
|
|
1749
1799
|
return result;
|
|
1750
|
-
});
|
|
1800
|
+
}), "traced");
|
|
1751
1801
|
function build_es(logger, correlator = default_correlator, patch_fn = bare_patch) {
|
|
1752
|
-
const bound_action = (me, action_name, target, payload, options) => action(
|
|
1802
|
+
const bound_action = /* @__PURE__ */ __name((me, action_name, target, payload, options) => action(
|
|
1753
1803
|
me,
|
|
1754
1804
|
action_name,
|
|
1755
1805
|
target,
|
|
1756
1806
|
payload,
|
|
1757
1807
|
{ ...options, correlator: options?.correlator ?? correlator },
|
|
1758
1808
|
patch_fn
|
|
1759
|
-
);
|
|
1760
|
-
const bound_load = (me, target, callback) => load(me, target, callback, patch_fn);
|
|
1809
|
+
), "bound_action");
|
|
1810
|
+
const bound_load = /* @__PURE__ */ __name((me, target, callback) => load(me, target, callback, patch_fn), "bound_load");
|
|
1761
1811
|
if (logger.level !== "trace") {
|
|
1762
1812
|
return {
|
|
1763
1813
|
snap,
|
|
@@ -1819,6 +1869,7 @@ function build_es(logger, correlator = default_correlator, patch_fn = bare_patch
|
|
|
1819
1869
|
})
|
|
1820
1870
|
};
|
|
1821
1871
|
}
|
|
1872
|
+
__name(build_es, "build_es");
|
|
1822
1873
|
function build_drain(logger) {
|
|
1823
1874
|
return {
|
|
1824
1875
|
claim,
|
|
@@ -1838,6 +1889,7 @@ function build_drain(logger) {
|
|
|
1838
1889
|
})
|
|
1839
1890
|
};
|
|
1840
1891
|
}
|
|
1892
|
+
__name(build_drain, "build_drain");
|
|
1841
1893
|
function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
1842
1894
|
if (logger.level !== "trace" || !leased.length) return;
|
|
1843
1895
|
const lane = leased[0]?.lane;
|
|
@@ -1875,6 +1927,7 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
1875
1927
|
}).join(", ");
|
|
1876
1928
|
logger.trace(`${drain_caption("drained", lane)} ${detail}`);
|
|
1877
1929
|
}
|
|
1930
|
+
__name(trace_cycle, "trace_cycle");
|
|
1878
1931
|
|
|
1879
1932
|
// src/internal/drain-cycle.ts
|
|
1880
1933
|
function budget_exhausted(lease, options, store_failing) {
|
|
@@ -1884,6 +1937,7 @@ function budget_exhausted(lease, options, store_failing) {
|
|
|
1884
1937
|
log().error(error);
|
|
1885
1938
|
return { lease, handled: 0, acked_at: lease.at, error, block: true };
|
|
1886
1939
|
}
|
|
1940
|
+
__name(budget_exhausted, "budget_exhausted");
|
|
1887
1941
|
function fetch_failure_policy(registry) {
|
|
1888
1942
|
let blockOnError = true;
|
|
1889
1943
|
let maxRetries = 0;
|
|
@@ -1894,6 +1948,7 @@ function fetch_failure_policy(registry) {
|
|
|
1894
1948
|
}
|
|
1895
1949
|
return { blockOnError, maxRetries };
|
|
1896
1950
|
}
|
|
1951
|
+
__name(fetch_failure_policy, "fetch_failure_policy");
|
|
1897
1952
|
function finalize(lease, handled, at, error, options, logger, failed_at) {
|
|
1898
1953
|
if (!error) return { lease, handled, acked_at: at };
|
|
1899
1954
|
logger.error(error);
|
|
@@ -1914,6 +1969,7 @@ function finalize(lease, handled, at, error, options, logger, failed_at) {
|
|
|
1914
1969
|
failed_at
|
|
1915
1970
|
};
|
|
1916
1971
|
}
|
|
1972
|
+
__name(finalize, "finalize");
|
|
1917
1973
|
function warn_misrouted(seen, stream, handler, event) {
|
|
1918
1974
|
report_once(
|
|
1919
1975
|
seen,
|
|
@@ -1921,6 +1977,7 @@ function warn_misrouted(seen, stream, handler, event) {
|
|
|
1921
1977
|
`Reaction "${handler}" on "${event}" resolved to target "${stream}", which a projection already serves. A target is served by one batch handler or one state projection, so this reaction can never run \u2014 and delivering to it would hand the projection an aggregate from another stream. Skipping it. The equivalent static \`.to({ target })\` is rejected at build; a dynamic resolver's target is only knowable here.`
|
|
1922
1978
|
);
|
|
1923
1979
|
}
|
|
1980
|
+
__name(warn_misrouted, "warn_misrouted");
|
|
1924
1981
|
async function run_drain_cycle(deps, cycle) {
|
|
1925
1982
|
const { ops, registry, batch_handlers, handle, handle_batch, lane } = deps;
|
|
1926
1983
|
const {
|
|
@@ -2037,6 +2094,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
2037
2094
|
const closeable = handled.filter((h) => h.close !== void 0).map((h) => h.close);
|
|
2038
2095
|
return { leased, fetched, handled, acked, blocked, closeable };
|
|
2039
2096
|
}
|
|
2097
|
+
__name(run_drain_cycle, "run_drain_cycle");
|
|
2040
2098
|
var EMPTY_DRAIN = {
|
|
2041
2099
|
fetched: [],
|
|
2042
2100
|
leased: [],
|
|
@@ -2051,8 +2109,12 @@ function merge_drains(drains) {
|
|
|
2051
2109
|
blocked: drains.flatMap((d) => d.blocked)
|
|
2052
2110
|
};
|
|
2053
2111
|
}
|
|
2112
|
+
__name(merge_drains, "merge_drains");
|
|
2054
2113
|
var RETRY = "";
|
|
2055
2114
|
var DrainController = class {
|
|
2115
|
+
static {
|
|
2116
|
+
__name(this, "DrainController");
|
|
2117
|
+
}
|
|
2056
2118
|
// Armed while `_raised` is ahead of `_lowered` (the raise count the last
|
|
2057
2119
|
// empty claim saw), so a claim never lowers over a raise that landed
|
|
2058
2120
|
// during it.
|
|
@@ -2106,12 +2168,12 @@ var DrainController = class {
|
|
|
2106
2168
|
*/
|
|
2107
2169
|
start(cycleMs) {
|
|
2108
2170
|
const run = this._deps.run_scoped;
|
|
2109
|
-
const tick = async () => {
|
|
2171
|
+
const tick = /* @__PURE__ */ __name(async () => {
|
|
2110
2172
|
if (this.armed) await run(() => this.drain());
|
|
2111
2173
|
if (this._stopped) return;
|
|
2112
2174
|
this._worker = setTimeout(tick, cycleMs);
|
|
2113
2175
|
this._worker.unref();
|
|
2114
|
-
};
|
|
2176
|
+
}, "tick");
|
|
2115
2177
|
this._worker = setTimeout(tick, cycleMs);
|
|
2116
2178
|
this._worker.unref();
|
|
2117
2179
|
}
|
|
@@ -2189,6 +2251,9 @@ var DrainController = class {
|
|
|
2189
2251
|
|
|
2190
2252
|
// src/internal/reaction-dispatch.ts
|
|
2191
2253
|
var CloseSignal = class extends Error {
|
|
2254
|
+
static {
|
|
2255
|
+
__name(this, "CloseSignal");
|
|
2256
|
+
}
|
|
2192
2257
|
/**
|
|
2193
2258
|
* Stream to close. Omitted → the reaction's own lease stream (a self-close).
|
|
2194
2259
|
* The synthesized autoclose reaction sets it to the aggregate stream, since
|
|
@@ -2304,6 +2369,7 @@ function build_handle(deps) {
|
|
|
2304
2369
|
return finalize(lease, handled, at, void 0, payloads[0].options, logger);
|
|
2305
2370
|
};
|
|
2306
2371
|
}
|
|
2372
|
+
__name(build_handle, "build_handle");
|
|
2307
2373
|
function build_handle_batch(logger) {
|
|
2308
2374
|
return async (lease, payloads, batchHandler) => {
|
|
2309
2375
|
const stream = lease.stream;
|
|
@@ -2332,6 +2398,7 @@ function build_handle_batch(logger) {
|
|
|
2332
2398
|
}
|
|
2333
2399
|
};
|
|
2334
2400
|
}
|
|
2401
|
+
__name(build_handle_batch, "build_handle_batch");
|
|
2335
2402
|
|
|
2336
2403
|
// src/internal/autoclose-reaction.ts
|
|
2337
2404
|
var AUTOCLOSE_TARGET_PREFIX = "__autoclose__:";
|
|
@@ -2352,14 +2419,14 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2352
2419
|
// An anchored stream name would read as a pattern, and a store may refuse
|
|
2353
2420
|
// it at subscribe, stopping every reaction. Such a stream has no
|
|
2354
2421
|
// autoclose: `app.close` still closes it.
|
|
2355
|
-
resolver: (e) => isStreamName(e.stream) ? {
|
|
2422
|
+
resolver: /* @__PURE__ */ __name((e) => isStreamName(e.stream) ? {
|
|
2356
2423
|
target: `${AUTOCLOSE_TARGET_PREFIX}${e.stream}`,
|
|
2357
2424
|
source: e.stream
|
|
2358
|
-
} : void 0,
|
|
2425
|
+
} : void 0, "resolver"),
|
|
2359
2426
|
// Never block on autoclose: a transient query/store error should retry,
|
|
2360
2427
|
// not quarantine the synthetic stream.
|
|
2361
2428
|
options: { blockOnError: false, maxRetries: DEFAULT_MAX_RETRIES },
|
|
2362
|
-
handler: async (event) => {
|
|
2429
|
+
handler: /* @__PURE__ */ __name(async (event) => {
|
|
2363
2430
|
const aggregate = event.stream;
|
|
2364
2431
|
const window = read_window();
|
|
2365
2432
|
if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
|
|
@@ -2406,7 +2473,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2406
2473
|
const future = dues.map((d) => d.getTime()).filter((t) => t > Date.now());
|
|
2407
2474
|
if (future.length)
|
|
2408
2475
|
throw new DeferSignal({ at: new Date(Math.min(...future)) });
|
|
2409
|
-
}
|
|
2476
|
+
}, "handler")
|
|
2410
2477
|
};
|
|
2411
2478
|
const key = `__autoclose_${st.name}`;
|
|
2412
2479
|
for (const event_name of Object.keys(st.events)) {
|
|
@@ -2417,6 +2484,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2417
2484
|
}
|
|
2418
2485
|
}
|
|
2419
2486
|
}
|
|
2487
|
+
__name(synthesize_autoclose_reactions, "synthesize_autoclose_reactions");
|
|
2420
2488
|
|
|
2421
2489
|
// src/internal/close-cycle.ts
|
|
2422
2490
|
var CLOSE_CATCH_UP_LIMIT = 1e3;
|
|
@@ -2430,16 +2498,20 @@ async function catch_up_correlation(cursor, correlate, until) {
|
|
|
2430
2498
|
}
|
|
2431
2499
|
return cursor.checkpoint;
|
|
2432
2500
|
}
|
|
2501
|
+
__name(catch_up_correlation, "catch_up_correlation");
|
|
2433
2502
|
var CloseLock = class {
|
|
2503
|
+
static {
|
|
2504
|
+
__name(this, "CloseLock");
|
|
2505
|
+
}
|
|
2434
2506
|
_tails = /* @__PURE__ */ new Map();
|
|
2435
2507
|
/** Run `work` after every earlier close of `stream` has settled. */
|
|
2436
2508
|
run(stream, work) {
|
|
2437
2509
|
const prev = this._tails.get(stream) ?? Promise.resolve();
|
|
2438
2510
|
const next = prev.then(work, work);
|
|
2439
2511
|
this._tails.set(stream, next);
|
|
2440
|
-
const cleanup = () => {
|
|
2512
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
2441
2513
|
if (this._tails.get(stream) === next) this._tails.delete(stream);
|
|
2442
|
-
};
|
|
2514
|
+
}, "cleanup");
|
|
2443
2515
|
next.then(cleanup, cleanup);
|
|
2444
2516
|
return next;
|
|
2445
2517
|
}
|
|
@@ -2470,6 +2542,7 @@ async function run_close_cycle(targets, deps) {
|
|
|
2470
2542
|
for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
|
|
2471
2543
|
return { truncated, skipped };
|
|
2472
2544
|
}
|
|
2545
|
+
__name(run_close_cycle, "run_close_cycle");
|
|
2473
2546
|
function with_stream_locks(streams, deps, work) {
|
|
2474
2547
|
const with_lock = deps.with_stream_lock ?? ((_stream, w) => w());
|
|
2475
2548
|
return [...streams].sort().reduceRight(
|
|
@@ -2477,6 +2550,7 @@ function with_stream_locks(streams, deps, work) {
|
|
|
2477
2550
|
work
|
|
2478
2551
|
)();
|
|
2479
2552
|
}
|
|
2553
|
+
__name(with_stream_locks, "with_stream_locks");
|
|
2480
2554
|
async function run_full_closes(full, target_map, deps, skipped) {
|
|
2481
2555
|
const none = /* @__PURE__ */ new Map();
|
|
2482
2556
|
const streams = full.map((t) => t.stream);
|
|
@@ -2532,6 +2606,7 @@ async function run_full_closes(full, target_map, deps, skipped) {
|
|
|
2532
2606
|
deps.correlation
|
|
2533
2607
|
);
|
|
2534
2608
|
}
|
|
2609
|
+
__name(run_full_closes, "run_full_closes");
|
|
2535
2610
|
async function run_windowed_closes(windowed, deps, skipped) {
|
|
2536
2611
|
const checkpoint = deps.reactive ? await deps.catch_up_correlation(Number.MAX_SAFE_INTEGER) : -1;
|
|
2537
2612
|
const min_at = deps.reactive ? await probe_min_watermarks(
|
|
@@ -2557,6 +2632,7 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
2557
2632
|
}
|
|
2558
2633
|
return truncated;
|
|
2559
2634
|
}
|
|
2635
|
+
__name(run_windowed_closes, "run_windowed_closes");
|
|
2560
2636
|
async function windowed_prune_pending(stream, before, max_id) {
|
|
2561
2637
|
let boundary_id;
|
|
2562
2638
|
let min_id;
|
|
@@ -2570,6 +2646,7 @@ async function windowed_prune_pending(stream, before, max_id) {
|
|
|
2570
2646
|
);
|
|
2571
2647
|
return boundary_id !== void 0 && min_id < boundary_id;
|
|
2572
2648
|
}
|
|
2649
|
+
__name(windowed_prune_pending, "windowed_prune_pending");
|
|
2573
2650
|
async function probe_min_watermarks(streams, page_size, checkpoint) {
|
|
2574
2651
|
const min_at = /* @__PURE__ */ new Map();
|
|
2575
2652
|
const matches = source_matcher();
|
|
@@ -2589,6 +2666,7 @@ async function probe_min_watermarks(streams, page_size, checkpoint) {
|
|
|
2589
2666
|
);
|
|
2590
2667
|
return min_at;
|
|
2591
2668
|
}
|
|
2669
|
+
__name(probe_min_watermarks, "probe_min_watermarks");
|
|
2592
2670
|
function source_matcher() {
|
|
2593
2671
|
const compiled = /* @__PURE__ */ new Map();
|
|
2594
2672
|
return (source, target, stream) => {
|
|
@@ -2602,6 +2680,7 @@ function source_matcher() {
|
|
|
2602
2680
|
return re.test(stream);
|
|
2603
2681
|
};
|
|
2604
2682
|
}
|
|
2683
|
+
__name(source_matcher, "source_matcher");
|
|
2605
2684
|
async function scan_stream_heads(streams) {
|
|
2606
2685
|
const stats = await store().query_stats(streams, {
|
|
2607
2686
|
exclude: [SNAP_EVENT]
|
|
@@ -2623,6 +2702,7 @@ async function scan_stream_heads(streams) {
|
|
|
2623
2702
|
}
|
|
2624
2703
|
return out;
|
|
2625
2704
|
}
|
|
2705
|
+
__name(scan_stream_heads, "scan_stream_heads");
|
|
2626
2706
|
async function partition_by_safety(stream_info, reactive, skipped, page_size, catch_up_correlation2) {
|
|
2627
2707
|
if (!reactive) return [...stream_info.keys()];
|
|
2628
2708
|
let needed = -1;
|
|
@@ -2656,6 +2736,7 @@ async function partition_by_safety(stream_info, reactive, skipped, page_size, ca
|
|
|
2656
2736
|
}
|
|
2657
2737
|
return safe;
|
|
2658
2738
|
}
|
|
2739
|
+
__name(partition_by_safety, "partition_by_safety");
|
|
2659
2740
|
async function guard_with_tombstones(safe, stream_info, correlation, tombstone2, skipped) {
|
|
2660
2741
|
const guarded = [];
|
|
2661
2742
|
const guard_events = /* @__PURE__ */ new Map();
|
|
@@ -2678,6 +2759,7 @@ async function guard_with_tombstones(safe, stream_info, correlation, tombstone2,
|
|
|
2678
2759
|
);
|
|
2679
2760
|
return { guarded, guard_events };
|
|
2680
2761
|
}
|
|
2762
|
+
__name(guard_with_tombstones, "guard_with_tombstones");
|
|
2681
2763
|
async function load_restart_seeds(guarded, target_map, stream_info, event_to_state, load2, logger) {
|
|
2682
2764
|
const seed_states = /* @__PURE__ */ new Map();
|
|
2683
2765
|
await Promise.all(
|
|
@@ -2696,12 +2778,14 @@ async function load_restart_seeds(guarded, target_map, stream_info, event_to_sta
|
|
|
2696
2778
|
);
|
|
2697
2779
|
return seed_states;
|
|
2698
2780
|
}
|
|
2781
|
+
__name(load_restart_seeds, "load_restart_seeds");
|
|
2699
2782
|
async function run_archive_callbacks(guarded, target_map) {
|
|
2700
2783
|
for (const stream of guarded) {
|
|
2701
2784
|
const archive_fn = target_map.get(stream)?.archive;
|
|
2702
2785
|
if (archive_fn) await archive_fn();
|
|
2703
2786
|
}
|
|
2704
2787
|
}
|
|
2788
|
+
__name(run_archive_callbacks, "run_archive_callbacks");
|
|
2705
2789
|
async function heads_still_guarded(guarded, guard_events, skipped) {
|
|
2706
2790
|
const heads = await store().query_stats(guarded, {});
|
|
2707
2791
|
return guarded.filter((stream) => {
|
|
@@ -2711,6 +2795,7 @@ async function heads_still_guarded(guarded, guard_events, skipped) {
|
|
|
2711
2795
|
return false;
|
|
2712
2796
|
});
|
|
2713
2797
|
}
|
|
2798
|
+
__name(heads_still_guarded, "heads_still_guarded");
|
|
2714
2799
|
async function truncate_and_warm_cache(guarded, seed_states, guard_events, correlation) {
|
|
2715
2800
|
const trunc_targets = guarded.map((stream) => {
|
|
2716
2801
|
const snapshot = seed_states.get(stream);
|
|
@@ -2747,15 +2832,16 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
2747
2832
|
);
|
|
2748
2833
|
return truncated;
|
|
2749
2834
|
}
|
|
2835
|
+
__name(truncate_and_warm_cache, "truncate_and_warm_cache");
|
|
2750
2836
|
|
|
2751
2837
|
// src/internal/correlate-cycle.ts
|
|
2752
2838
|
import { createHash, randomUUID as randomUUID2 } from "crypto";
|
|
2753
2839
|
var COLD_START_BACK_SCAN = 1e4;
|
|
2754
2840
|
var CORRELATION_LEASE_MS = 5e3;
|
|
2755
|
-
var registry_key = (events) => {
|
|
2841
|
+
var registry_key = /* @__PURE__ */ __name((events) => {
|
|
2756
2842
|
const shape = Object.keys(events).filter((name) => events[name].reactions.size > 0).sort().map((name) => [name, [...events[name].reactions.keys()].sort()]);
|
|
2757
2843
|
return createHash("sha256").update(JSON.stringify(shape)).digest("hex").slice(0, 32);
|
|
2758
|
-
};
|
|
2844
|
+
}, "registry_key");
|
|
2759
2845
|
var PATTERN_CACHE_SIZE = 32;
|
|
2760
2846
|
function report_undeclared_lane(seen, handler, target, lane, declared) {
|
|
2761
2847
|
report_once(
|
|
@@ -2764,6 +2850,7 @@ function report_undeclared_lane(seen, handler, target, lane, declared) {
|
|
|
2764
2850
|
`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.`
|
|
2765
2851
|
);
|
|
2766
2852
|
}
|
|
2853
|
+
__name(report_undeclared_lane, "report_undeclared_lane");
|
|
2767
2854
|
function report_bad_priority(seen, handler, target, priority) {
|
|
2768
2855
|
report_once(
|
|
2769
2856
|
seen,
|
|
@@ -2771,6 +2858,7 @@ function report_bad_priority(seen, handler, target, priority) {
|
|
|
2771
2858
|
`Reaction "${handler}" resolved priority ${String(priority)} for target "${target}", which isn't a 32-bit integer. Running it at priority 0 instead. The equivalent static \`.to({ priority })\` is rejected at build; a dynamic resolver's priority is only knowable here.`
|
|
2772
2859
|
);
|
|
2773
2860
|
}
|
|
2861
|
+
__name(report_bad_priority, "report_bad_priority");
|
|
2774
2862
|
function report_lane_conflict(seen, handler, target, kept, dropped) {
|
|
2775
2863
|
report_once(
|
|
2776
2864
|
seen,
|
|
@@ -2778,7 +2866,11 @@ function report_lane_conflict(seen, handler, target, kept, dropped) {
|
|
|
2778
2866
|
`Reaction "${handler}" resolved lane "${dropped}" for a stream already on "${kept}" \u2014 for example "${target}". These are conflicting lane assignments from two dynamic resolutions at equal priority. Keeping "${kept}", the lane it was first discovered on \u2014 re-laning a live stream would move it out from under a worker holding its lease. The reaction resolving "${dropped}" runs inside the "${kept}" lane's budget, and a process restricted to "${dropped}" via onlyLanes never runs it. The equivalent static declaration is rejected at build; align the resolvers, or split the target.`
|
|
2779
2867
|
);
|
|
2780
2868
|
}
|
|
2869
|
+
__name(report_lane_conflict, "report_lane_conflict");
|
|
2781
2870
|
var CorrelateCycle = class {
|
|
2871
|
+
static {
|
|
2872
|
+
__name(this, "CorrelateCycle");
|
|
2873
|
+
}
|
|
2782
2874
|
_checkpoint = -1;
|
|
2783
2875
|
// Lease holder id; per instance, so a restart never inherits a stale claim.
|
|
2784
2876
|
_by = randomUUID2();
|
|
@@ -2898,10 +2990,10 @@ var CorrelateCycle = class {
|
|
|
2898
2990
|
async _scan(limit, lease) {
|
|
2899
2991
|
await this._init();
|
|
2900
2992
|
const epoch = this._epoch;
|
|
2901
|
-
const idle = () => ({
|
|
2993
|
+
const idle = /* @__PURE__ */ __name(() => ({
|
|
2902
2994
|
kind: "idle",
|
|
2903
2995
|
last_id: this._checkpoint
|
|
2904
|
-
});
|
|
2996
|
+
}), "idle");
|
|
2905
2997
|
if (this._raised === this._lowered) return idle();
|
|
2906
2998
|
const raised = this._raised;
|
|
2907
2999
|
const now = Date.now();
|
|
@@ -3109,6 +3201,7 @@ function pii_split(emitted, fields) {
|
|
|
3109
3201
|
}
|
|
3110
3202
|
return { name: emitted.name, data, pii };
|
|
3111
3203
|
}
|
|
3204
|
+
__name(pii_split, "pii_split");
|
|
3112
3205
|
function pii_gate(event, fields, predicate, actor) {
|
|
3113
3206
|
const data = event.data;
|
|
3114
3207
|
const { pii, ...rest } = event;
|
|
@@ -3128,10 +3221,12 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
3128
3221
|
for (const f of fields) redacted[f] = REDACTED;
|
|
3129
3222
|
return { ...rest, data: redacted };
|
|
3130
3223
|
}
|
|
3131
|
-
|
|
3224
|
+
__name(pii_gate, "pii_gate");
|
|
3225
|
+
var IDENTITY_GATE = /* @__PURE__ */ __name((event) => event, "IDENTITY_GATE");
|
|
3132
3226
|
function make_gate(fields, predicate) {
|
|
3133
3227
|
return (event, actor) => pii_gate(event, fields, predicate, actor);
|
|
3134
3228
|
}
|
|
3229
|
+
__name(make_gate, "make_gate");
|
|
3135
3230
|
function pii_strip(event, fields) {
|
|
3136
3231
|
const data = event.data;
|
|
3137
3232
|
const stripped = {};
|
|
@@ -3144,21 +3239,22 @@ function pii_strip(event, fields) {
|
|
|
3144
3239
|
data: stripped
|
|
3145
3240
|
};
|
|
3146
3241
|
}
|
|
3242
|
+
__name(pii_strip, "pii_strip");
|
|
3147
3243
|
|
|
3148
3244
|
// src/internal/projection-fold.ts
|
|
3149
3245
|
var FOLD_RESET = /* @__PURE__ */ Symbol("act.fold.reset");
|
|
3150
3246
|
function make_fold_handler(me, flush, config2, sensitive_fields) {
|
|
3151
3247
|
const load_me = {
|
|
3152
3248
|
...me,
|
|
3153
|
-
view: (raw, actor) => {
|
|
3249
|
+
view: /* @__PURE__ */ __name((raw, actor) => {
|
|
3154
3250
|
const viewed = me.view(raw, actor);
|
|
3155
3251
|
const fields = sensitive_fields(viewed.name);
|
|
3156
3252
|
return fields.length ? pii_strip(viewed, fields) : viewed;
|
|
3157
|
-
}
|
|
3253
|
+
}, "view")
|
|
3158
3254
|
};
|
|
3159
3255
|
const cache2 = /* @__PURE__ */ new Map();
|
|
3160
|
-
const row = ({ dirty: _, ...row2 }) => row2;
|
|
3161
|
-
const flush_dirty = async () => {
|
|
3256
|
+
const row = /* @__PURE__ */ __name(({ dirty: _, ...row2 }) => row2, "row");
|
|
3257
|
+
const flush_dirty = /* @__PURE__ */ __name(async () => {
|
|
3162
3258
|
const rows = [];
|
|
3163
3259
|
const flushed = [];
|
|
3164
3260
|
for (const f of cache2.values())
|
|
@@ -3169,8 +3265,8 @@ function make_fold_handler(me, flush, config2, sensitive_fields) {
|
|
|
3169
3265
|
if (rows.length === 0) return;
|
|
3170
3266
|
await flush(rows);
|
|
3171
3267
|
for (const f of flushed) f.dirty = false;
|
|
3172
|
-
};
|
|
3173
|
-
const first_sight = async (stream) => {
|
|
3268
|
+
}, "flush_dirty");
|
|
3269
|
+
const first_sight = /* @__PURE__ */ __name(async (stream) => {
|
|
3174
3270
|
if (cache2.size >= config2.maxCachedStates) {
|
|
3175
3271
|
const oldest = cache2.keys().next().value;
|
|
3176
3272
|
const evictee = cache2.get(oldest);
|
|
@@ -3189,8 +3285,8 @@ function make_fold_handler(me, flush, config2, sensitive_fields) {
|
|
|
3189
3285
|
};
|
|
3190
3286
|
cache2.set(stream, seated);
|
|
3191
3287
|
return seated;
|
|
3192
|
-
};
|
|
3193
|
-
const handler = async (events) => {
|
|
3288
|
+
}, "first_sight");
|
|
3289
|
+
const handler = /* @__PURE__ */ __name(async (events) => {
|
|
3194
3290
|
let folded_since_flush = 0;
|
|
3195
3291
|
for (const event of events) {
|
|
3196
3292
|
const stream = event.stream;
|
|
@@ -3227,13 +3323,17 @@ function make_fold_handler(me, flush, config2, sensitive_fields) {
|
|
|
3227
3323
|
}
|
|
3228
3324
|
}
|
|
3229
3325
|
await flush_dirty();
|
|
3230
|
-
};
|
|
3231
|
-
Object.defineProperty(handler, FOLD_RESET, { value: () => cache2.clear() });
|
|
3326
|
+
}, "handler");
|
|
3327
|
+
Object.defineProperty(handler, FOLD_RESET, { value: /* @__PURE__ */ __name(() => cache2.clear(), "value") });
|
|
3232
3328
|
return handler;
|
|
3233
3329
|
}
|
|
3330
|
+
__name(make_fold_handler, "make_fold_handler");
|
|
3234
3331
|
|
|
3235
3332
|
// src/internal/settle.ts
|
|
3236
3333
|
var SettleLoop = class {
|
|
3334
|
+
static {
|
|
3335
|
+
__name(this, "SettleLoop");
|
|
3336
|
+
}
|
|
3237
3337
|
_timer = void 0;
|
|
3238
3338
|
// The cycle in flight, set while one runs. Shutdown waits for it
|
|
3239
3339
|
// (`stop()` cancels scheduling only). Never rejects.
|
|
@@ -3334,6 +3434,9 @@ var SettleLoop = class {
|
|
|
3334
3434
|
|
|
3335
3435
|
// src/act.ts
|
|
3336
3436
|
var Act = class {
|
|
3437
|
+
static {
|
|
3438
|
+
__name(this, "Act");
|
|
3439
|
+
}
|
|
3337
3440
|
_emitter = new EventEmitter();
|
|
3338
3441
|
_breaker;
|
|
3339
3442
|
_drain;
|
|
@@ -3506,10 +3609,10 @@ var Act = class {
|
|
|
3506
3609
|
return new CircuitBreaker(
|
|
3507
3610
|
check("circuit_breaker", options.circuitBreaker ?? {}),
|
|
3508
3611
|
{
|
|
3509
|
-
on_error: (error, circuit) => this._emit_error(error, circuit),
|
|
3612
|
+
on_error: /* @__PURE__ */ __name((error, circuit) => this._emit_error(error, circuit), "on_error"),
|
|
3510
3613
|
// When the cooldown elapses, settle once: its scan or claim is the
|
|
3511
3614
|
// half-open probe that closes or re-opens the breaker.
|
|
3512
|
-
on_retry: () => this._schedule()
|
|
3615
|
+
on_retry: /* @__PURE__ */ __name(() => this._schedule(), "on_retry")
|
|
3513
3616
|
}
|
|
3514
3617
|
);
|
|
3515
3618
|
}
|
|
@@ -3529,12 +3632,12 @@ var Act = class {
|
|
|
3529
3632
|
batch_handlers: this._batch_handlers,
|
|
3530
3633
|
handle,
|
|
3531
3634
|
handle_batch,
|
|
3532
|
-
on_acked: (acked) => this.emit("acked", acked),
|
|
3533
|
-
on_blocked: (blocked) => this.emit("blocked", blocked),
|
|
3635
|
+
on_acked: /* @__PURE__ */ __name((acked) => this.emit("acked", acked), "on_acked"),
|
|
3636
|
+
on_blocked: /* @__PURE__ */ __name((blocked) => this.emit("blocked", blocked), "on_blocked"),
|
|
3534
3637
|
// Reaction-requested close: the same machinery as `app.close`.
|
|
3535
3638
|
// A store failure reaches the breaker; anything else (the archive
|
|
3536
3639
|
// callback is app code) is logged here, never counted.
|
|
3537
|
-
on_close: async (targets) => {
|
|
3640
|
+
on_close: /* @__PURE__ */ __name(async (targets) => {
|
|
3538
3641
|
try {
|
|
3539
3642
|
await this._run_close(targets);
|
|
3540
3643
|
} catch (error) {
|
|
@@ -3544,7 +3647,7 @@ var Act = class {
|
|
|
3544
3647
|
`Reaction-requested close of ${targets.map((t) => `"${t.stream}"`).join(", ")} failed; the policy retries it (a full close the next day, a prune on the stream's next commit), or close it now with app.close(...) once the cause is fixed.`
|
|
3545
3648
|
);
|
|
3546
3649
|
}
|
|
3547
|
-
},
|
|
3650
|
+
}, "on_close"),
|
|
3548
3651
|
breaker: this._breaker,
|
|
3549
3652
|
run_scoped: this._scoped,
|
|
3550
3653
|
lane: single_default_lane ? void 0 : name,
|
|
@@ -3592,10 +3695,10 @@ var Act = class {
|
|
|
3592
3695
|
// Built after the controllers, so their keys are the active lanes.
|
|
3593
3696
|
shard: this._drain_controllers.size < this._declared_lanes.length ? [...this._drain_controllers.keys()] : void 0,
|
|
3594
3697
|
// Only reached on a draining app: writer-only ones never correlate.
|
|
3595
|
-
on_init: async () => {
|
|
3698
|
+
on_init: /* @__PURE__ */ __name(async () => {
|
|
3596
3699
|
this._arm_all();
|
|
3597
3700
|
await this._seed_persisted_defers();
|
|
3598
|
-
}
|
|
3701
|
+
}, "on_init")
|
|
3599
3702
|
});
|
|
3600
3703
|
}
|
|
3601
3704
|
// Cold start: an idle deferred stream still fires on time after a restart.
|
|
@@ -3610,11 +3713,11 @@ var Act = class {
|
|
|
3610
3713
|
_build_settle(options) {
|
|
3611
3714
|
return new SettleLoop(
|
|
3612
3715
|
{
|
|
3613
|
-
correlate: (q) => this._correlate_pass(q.limit ?? this._poll_limit ?? 100, true),
|
|
3716
|
+
correlate: /* @__PURE__ */ __name((q) => this._correlate_pass(q.limit ?? this._poll_limit ?? 100, true), "correlate"),
|
|
3614
3717
|
// `settle()` validated the options, and `_schedule` skips writer-only
|
|
3615
3718
|
// instances, so the loop drains through the internal path.
|
|
3616
|
-
drain: (o) => this._scoped(() => this._drain_all(o)),
|
|
3617
|
-
on_settled: (drain) => this.emit("settled", drain),
|
|
3719
|
+
drain: /* @__PURE__ */ __name((o) => this._scoped(() => this._drain_all(o)), "drain"),
|
|
3720
|
+
on_settled: /* @__PURE__ */ __name((drain) => this.emit("settled", drain), "on_settled"),
|
|
3618
3721
|
breaker: this._breaker
|
|
3619
3722
|
},
|
|
3620
3723
|
options.settleDebounceMs ?? DEFAULT_SETTLE_DEBOUNCE_MS
|
|
@@ -4056,6 +4159,13 @@ var Act = class {
|
|
|
4056
4159
|
stop_settling() {
|
|
4057
4160
|
this._settle.stop();
|
|
4058
4161
|
}
|
|
4162
|
+
// Drop every fold cache before a replay, or a warm cache would re-flush
|
|
4163
|
+
// stale rows. Cleared for all targets: resolving a filter costs a query,
|
|
4164
|
+
// and an extra clear costs one head load per stream.
|
|
4165
|
+
_reset_folds() {
|
|
4166
|
+
for (const handler of this._batch_handlers.values())
|
|
4167
|
+
handler[FOLD_RESET]?.();
|
|
4168
|
+
}
|
|
4059
4169
|
/**
|
|
4060
4170
|
* Reset reaction stream watermarks and settle them, replaying their
|
|
4061
4171
|
* events through their reactions.
|
|
@@ -4084,8 +4194,7 @@ var Act = class {
|
|
|
4084
4194
|
async reset(input) {
|
|
4085
4195
|
return this._scoped(async () => {
|
|
4086
4196
|
const count = await store().reset(input);
|
|
4087
|
-
|
|
4088
|
-
handler[FOLD_RESET]?.();
|
|
4197
|
+
this._reset_folds();
|
|
4089
4198
|
if (count > 0) {
|
|
4090
4199
|
this._wake();
|
|
4091
4200
|
}
|
|
@@ -4182,15 +4291,16 @@ var Act = class {
|
|
|
4182
4291
|
let kept = 0;
|
|
4183
4292
|
let migrated = 0;
|
|
4184
4293
|
let dropped = { closed_streams: 0, snapshots: 0 };
|
|
4185
|
-
const run = () => target.restore(async (callback) => {
|
|
4294
|
+
const run = /* @__PURE__ */ __name(() => target.restore(async (callback) => {
|
|
4186
4295
|
const partial = await scan(source, opts, callback);
|
|
4187
4296
|
kept = partial.kept;
|
|
4188
4297
|
migrated = partial.migrated;
|
|
4189
4298
|
dropped = partial.dropped;
|
|
4190
|
-
});
|
|
4299
|
+
}), "run");
|
|
4191
4300
|
if (sink) await run();
|
|
4192
4301
|
else {
|
|
4193
4302
|
await this._correlate.restart(run);
|
|
4303
|
+
this._reset_folds();
|
|
4194
4304
|
this._wake();
|
|
4195
4305
|
}
|
|
4196
4306
|
return { kept, migrated, dropped, duration_ms: Date.now() - started };
|
|
@@ -4283,18 +4393,18 @@ var Act = class {
|
|
|
4283
4393
|
const close_actor = { id: "$close", name: "close" };
|
|
4284
4394
|
const result = await run_close_cycle(targets, {
|
|
4285
4395
|
reactive: this._reactive,
|
|
4286
|
-
catch_up_correlation: (until) => catch_up_correlation(
|
|
4396
|
+
catch_up_correlation: /* @__PURE__ */ __name((until) => catch_up_correlation(
|
|
4287
4397
|
this._correlate,
|
|
4288
4398
|
(limit) => this.correlate({ limit }),
|
|
4289
4399
|
until
|
|
4290
|
-
),
|
|
4400
|
+
), "catch_up_correlation"),
|
|
4291
4401
|
event_to_state: this._event_to_state,
|
|
4292
4402
|
load: this._es.load,
|
|
4293
4403
|
tombstone: this._es.tombstone,
|
|
4294
4404
|
logger: this._logger,
|
|
4295
4405
|
correlation: close_correlation(this._correlator, close_actor),
|
|
4296
|
-
with_stream_lock: (stream, work) => this._close_lock.run(stream, work),
|
|
4297
|
-
forget_subscribed: (streams) => this._correlate.forget_subscribed(streams)
|
|
4406
|
+
with_stream_lock: /* @__PURE__ */ __name((stream, work) => this._close_lock.run(stream, work), "with_stream_lock"),
|
|
4407
|
+
forget_subscribed: /* @__PURE__ */ __name((streams) => this._correlate.forget_subscribed(streams), "forget_subscribed")
|
|
4298
4408
|
});
|
|
4299
4409
|
this.emit("closed", result);
|
|
4300
4410
|
return result;
|
|
@@ -4369,6 +4479,7 @@ function base_type_name(schema) {
|
|
|
4369
4479
|
def = def_of(inner);
|
|
4370
4480
|
return def.type === "array" ? `array of ${base_type_name(def.element)}` : def.type;
|
|
4371
4481
|
}
|
|
4482
|
+
__name(base_type_name, "base_type_name");
|
|
4372
4483
|
function merge_schemas(existing, incoming, state_name) {
|
|
4373
4484
|
if (existing === incoming) return existing;
|
|
4374
4485
|
const existing_object = as_object(existing, "existing", state_name);
|
|
@@ -4388,15 +4499,18 @@ function merge_schemas(existing, incoming, state_name) {
|
|
|
4388
4499
|
}
|
|
4389
4500
|
return existing_object.extend(incoming_shape);
|
|
4390
4501
|
}
|
|
4502
|
+
__name(merge_schemas, "merge_schemas");
|
|
4391
4503
|
function as_object(schema, side, state_name) {
|
|
4392
4504
|
if (schema instanceof ZodObject) return schema;
|
|
4393
4505
|
throw new Error(
|
|
4394
4506
|
`Cannot merge state schemas for "${state_name}": the ${side} partial's schema is a ${schema.constructor.name}, not a z.object. Partials of the same state are merged by extending their shapes, so declare every partial's state as a plain z.object({ ... }).`
|
|
4395
4507
|
);
|
|
4396
4508
|
}
|
|
4509
|
+
__name(as_object, "as_object");
|
|
4397
4510
|
function merge_inits(existing, incoming) {
|
|
4398
4511
|
return () => ({ ...existing(), ...incoming() });
|
|
4399
4512
|
}
|
|
4513
|
+
__name(merge_inits, "merge_inits");
|
|
4400
4514
|
function register_state(state2, states, actions, events) {
|
|
4401
4515
|
const existing = states.get(state2.name);
|
|
4402
4516
|
if (existing) {
|
|
@@ -4405,6 +4519,7 @@ function register_state(state2, states, actions, events) {
|
|
|
4405
4519
|
register_new_state(state2, states, actions, events);
|
|
4406
4520
|
}
|
|
4407
4521
|
}
|
|
4522
|
+
__name(register_state, "register_state");
|
|
4408
4523
|
function register_new_state(state2, states, actions, events) {
|
|
4409
4524
|
states.set(state2.name, state2);
|
|
4410
4525
|
for (const name of Object.keys(state2.actions)) {
|
|
@@ -4416,11 +4531,13 @@ function register_new_state(state2, states, actions, events) {
|
|
|
4416
4531
|
events[name] = { schema: state2.events[name], reactions: /* @__PURE__ */ new Map() };
|
|
4417
4532
|
}
|
|
4418
4533
|
}
|
|
4534
|
+
__name(register_new_state, "register_new_state");
|
|
4419
4535
|
function pick_declared(existing, incoming, what, state_name) {
|
|
4420
4536
|
if (existing && incoming && existing !== incoming)
|
|
4421
4537
|
throw new Error(`Duplicate ${what} for state "${state_name}"`);
|
|
4422
4538
|
return incoming ?? existing;
|
|
4423
4539
|
}
|
|
4540
|
+
__name(pick_declared, "pick_declared");
|
|
4424
4541
|
function autoclose_of(existing, state2) {
|
|
4425
4542
|
pick_declared(
|
|
4426
4543
|
existing.autoclose,
|
|
@@ -4436,6 +4553,7 @@ function autoclose_of(existing, state2) {
|
|
|
4436
4553
|
autoclose_keep_days: owner.autoclose_keep_days
|
|
4437
4554
|
};
|
|
4438
4555
|
}
|
|
4556
|
+
__name(autoclose_of, "autoclose_of");
|
|
4439
4557
|
function merge_into_existing(state2, existing, states, actions, events) {
|
|
4440
4558
|
for (const name of Object.keys(state2.actions)) {
|
|
4441
4559
|
if (existing.on[name] === state2.on[name]) continue;
|
|
@@ -4491,6 +4609,7 @@ function merge_into_existing(state2, existing, states, actions, events) {
|
|
|
4491
4609
|
events[name] = { schema: state2.events[name], reactions: /* @__PURE__ */ new Map() };
|
|
4492
4610
|
}
|
|
4493
4611
|
}
|
|
4612
|
+
__name(merge_into_existing, "merge_into_existing");
|
|
4494
4613
|
function merge_patches(existing, incoming, state_name) {
|
|
4495
4614
|
const merged = { ...existing };
|
|
4496
4615
|
for (const name of Object.keys(incoming)) {
|
|
@@ -4513,6 +4632,7 @@ function merge_patches(existing, incoming, state_name) {
|
|
|
4513
4632
|
}
|
|
4514
4633
|
return merged;
|
|
4515
4634
|
}
|
|
4635
|
+
__name(merge_patches, "merge_patches");
|
|
4516
4636
|
function merge_event_register(target, source) {
|
|
4517
4637
|
for (const [event_name, source_reg] of Object.entries(source)) {
|
|
4518
4638
|
const target_reg = target[event_name];
|
|
@@ -4527,6 +4647,7 @@ function merge_event_register(target, source) {
|
|
|
4527
4647
|
}
|
|
4528
4648
|
}
|
|
4529
4649
|
}
|
|
4650
|
+
__name(merge_event_register, "merge_event_register");
|
|
4530
4651
|
function merge_projection(proj, events) {
|
|
4531
4652
|
for (const event_name of Object.keys(proj.events)) {
|
|
4532
4653
|
const proj_register = proj.events[event_name];
|
|
@@ -4546,10 +4667,11 @@ function merge_projection(proj, events) {
|
|
|
4546
4667
|
}
|
|
4547
4668
|
}
|
|
4548
4669
|
}
|
|
4549
|
-
|
|
4670
|
+
__name(merge_projection, "merge_projection");
|
|
4671
|
+
var _this_ = /* @__PURE__ */ __name(({ stream }) => ({
|
|
4550
4672
|
source: stream,
|
|
4551
4673
|
target: stream
|
|
4552
|
-
});
|
|
4674
|
+
}), "_this_");
|
|
4553
4675
|
|
|
4554
4676
|
// src/builders/builder-utils.ts
|
|
4555
4677
|
function register_lane(config2, lanes) {
|
|
@@ -4563,6 +4685,7 @@ function register_lane(config2, lanes) {
|
|
|
4563
4685
|
`Lane "${config2.name}" was already declared with a different config`
|
|
4564
4686
|
);
|
|
4565
4687
|
}
|
|
4688
|
+
__name(register_lane, "register_lane");
|
|
4566
4689
|
function add_reaction(events, event, name, kind, make, builder) {
|
|
4567
4690
|
if (!name)
|
|
4568
4691
|
throw new Error(
|
|
@@ -4583,8 +4706,9 @@ function add_reaction(events, event, name, kind, make, builder) {
|
|
|
4583
4706
|
}
|
|
4584
4707
|
});
|
|
4585
4708
|
}
|
|
4709
|
+
__name(add_reaction, "add_reaction");
|
|
4586
4710
|
function reaction_on(event, events, builder) {
|
|
4587
|
-
const register = (handler, options, schedule) => add_reaction(
|
|
4711
|
+
const register = /* @__PURE__ */ __name((handler, options, schedule) => add_reaction(
|
|
4588
4712
|
events,
|
|
4589
4713
|
event,
|
|
4590
4714
|
handler.name,
|
|
@@ -4606,14 +4730,15 @@ function reaction_on(event, events, builder) {
|
|
|
4606
4730
|
};
|
|
4607
4731
|
},
|
|
4608
4732
|
builder
|
|
4609
|
-
);
|
|
4733
|
+
), "register");
|
|
4610
4734
|
return {
|
|
4611
|
-
do: (handler, options) => register(handler, options),
|
|
4612
|
-
defer: (schedule) => ({
|
|
4613
|
-
do: (handler, options) => register(handler, options, schedule)
|
|
4614
|
-
})
|
|
4735
|
+
do: /* @__PURE__ */ __name((handler, options) => register(handler, options), "do"),
|
|
4736
|
+
defer: /* @__PURE__ */ __name((schedule) => ({
|
|
4737
|
+
do: /* @__PURE__ */ __name((handler, options) => register(handler, options, schedule), "do")
|
|
4738
|
+
}), "defer")
|
|
4615
4739
|
};
|
|
4616
4740
|
}
|
|
4741
|
+
__name(reaction_on, "reaction_on");
|
|
4617
4742
|
|
|
4618
4743
|
// src/builders/event-builder.ts
|
|
4619
4744
|
import { z as z2 } from "zod";
|
|
@@ -4625,10 +4750,10 @@ function event_tags(schema) {
|
|
|
4625
4750
|
if (dates) pii_dates[key] = dates.optional();
|
|
4626
4751
|
}
|
|
4627
4752
|
const data_reviver_schema = date_reviver_schema(schema);
|
|
4628
|
-
const revive = (schema2) => (data) => {
|
|
4753
|
+
const revive = /* @__PURE__ */ __name((schema2) => (data) => {
|
|
4629
4754
|
const revived = schema2.safeParse(data);
|
|
4630
4755
|
return revived.success ? revived.data : data;
|
|
4631
|
-
};
|
|
4756
|
+
}, "revive");
|
|
4632
4757
|
const dated_pii = Object.keys(pii_dates).length > 0;
|
|
4633
4758
|
return {
|
|
4634
4759
|
sensitive: pii,
|
|
@@ -4636,6 +4761,7 @@ function event_tags(schema) {
|
|
|
4636
4761
|
pii_date_reviver: dated_pii ? revive(z2.looseObject(pii_dates)) : void 0
|
|
4637
4762
|
};
|
|
4638
4763
|
}
|
|
4764
|
+
__name(event_tags, "event_tags");
|
|
4639
4765
|
function make_event_reader(tags, disclosure, predicate = null) {
|
|
4640
4766
|
const { date_reviver, pii_date_reviver } = tags;
|
|
4641
4767
|
const sensitive2 = Object.keys(tags.sensitive);
|
|
@@ -4655,6 +4781,7 @@ function make_event_reader(tags, disclosure, predicate = null) {
|
|
|
4655
4781
|
);
|
|
4656
4782
|
});
|
|
4657
4783
|
}
|
|
4784
|
+
__name(make_event_reader, "make_event_reader");
|
|
4658
4785
|
function build_events(registry, states, lanes, owners) {
|
|
4659
4786
|
const declared = /* @__PURE__ */ new Set([DEFAULT_LANE, ...lanes.map((l) => l.name)]);
|
|
4660
4787
|
const lane_errors = [];
|
|
@@ -4689,7 +4816,7 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4689
4816
|
handler_readers.set(event_name, handler_reader);
|
|
4690
4817
|
for (const [name, reaction] of def.reactions) {
|
|
4691
4818
|
const inner = reaction.handler;
|
|
4692
|
-
const wrapped = (evt, stream, app) => inner(handler_reader(evt), stream, app);
|
|
4819
|
+
const wrapped = /* @__PURE__ */ __name((evt, stream, app) => inner(handler_reader(evt), stream, app), "wrapped");
|
|
4693
4820
|
Object.defineProperty(wrapped, "name", { value: inner.name });
|
|
4694
4821
|
reaction.handler = wrapped;
|
|
4695
4822
|
def.reactions.set(name, reaction);
|
|
@@ -4738,10 +4865,12 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4738
4865
|
const advisory = advised.size > 0 ? `Act has ${advised.size} sensitive field(s) whose type isn't a string: ${[...advised].join(", ")}. A caller who may not see one reads "[REDACTED]" or "[SHREDDED]" there instead, which its type doesn't allow. Declare sensitive fields as strings. See docs/docs/guides/sensitive-data.md.` : void 0;
|
|
4739
4866
|
return { sensitive: sensitive2, advisory, query_readers, handler_readers };
|
|
4740
4867
|
}
|
|
4868
|
+
__name(build_events, "build_events");
|
|
4741
4869
|
function reads_as_string(schema) {
|
|
4742
4870
|
const type = def_of(output_of(schema))?.type;
|
|
4743
4871
|
return type === "string" || type === "transform";
|
|
4744
4872
|
}
|
|
4873
|
+
__name(reads_as_string, "reads_as_string");
|
|
4745
4874
|
|
|
4746
4875
|
// src/builders/act-builder.ts
|
|
4747
4876
|
function register_batch_handler(proj, batch_handlers) {
|
|
@@ -4754,6 +4883,7 @@ function register_batch_handler(proj, batch_handlers) {
|
|
|
4754
4883
|
}
|
|
4755
4884
|
batch_handlers.set(proj.target, proj.batchHandler);
|
|
4756
4885
|
}
|
|
4886
|
+
__name(register_batch_handler, "register_batch_handler");
|
|
4757
4887
|
function act() {
|
|
4758
4888
|
const states = /* @__PURE__ */ new Map();
|
|
4759
4889
|
const _sf = /* @__PURE__ */ new Map();
|
|
@@ -4767,44 +4897,44 @@ function act() {
|
|
|
4767
4897
|
const registry = {
|
|
4768
4898
|
actions: {},
|
|
4769
4899
|
events: {},
|
|
4770
|
-
sensitive_fields: (event_name) => _sf.get(event_name) ?? [],
|
|
4771
|
-
query_gate: (event_name) => _qg.get(event_name) ?? IDENTITY_GATE,
|
|
4772
|
-
disclosure_predicate: (state_name) => _dp.get(state_name) ?? null,
|
|
4773
|
-
deprecated_events: (state_name) => _de.get(state_name) ?? EMPTY_DEPRECATED,
|
|
4774
|
-
autoclose_policy: (state_name) => _ac.get(state_name) ?? null,
|
|
4775
|
-
autoclose_archiver: (state_name) => _aa.get(state_name) ?? null
|
|
4900
|
+
sensitive_fields: /* @__PURE__ */ __name((event_name) => _sf.get(event_name) ?? [], "sensitive_fields"),
|
|
4901
|
+
query_gate: /* @__PURE__ */ __name((event_name) => _qg.get(event_name) ?? IDENTITY_GATE, "query_gate"),
|
|
4902
|
+
disclosure_predicate: /* @__PURE__ */ __name((state_name) => _dp.get(state_name) ?? null, "disclosure_predicate"),
|
|
4903
|
+
deprecated_events: /* @__PURE__ */ __name((state_name) => _de.get(state_name) ?? EMPTY_DEPRECATED, "deprecated_events"),
|
|
4904
|
+
autoclose_policy: /* @__PURE__ */ __name((state_name) => _ac.get(state_name) ?? null, "autoclose_policy"),
|
|
4905
|
+
autoclose_archiver: /* @__PURE__ */ __name((state_name) => _aa.get(state_name) ?? null, "autoclose_archiver")
|
|
4776
4906
|
};
|
|
4777
4907
|
const pending_projections = [];
|
|
4778
4908
|
const projection_reactions = /* @__PURE__ */ new Set();
|
|
4779
|
-
const record_projection_reactions = (proj) => {
|
|
4909
|
+
const record_projection_reactions = /* @__PURE__ */ __name((proj) => {
|
|
4780
4910
|
if (!proj.batchHandler && !proj.fold) return;
|
|
4781
4911
|
for (const register of Object.values(
|
|
4782
4912
|
proj.events
|
|
4783
4913
|
))
|
|
4784
4914
|
for (const reaction of register.reactions.values())
|
|
4785
4915
|
projection_reactions.add(reaction);
|
|
4786
|
-
};
|
|
4916
|
+
}, "record_projection_reactions");
|
|
4787
4917
|
const fold_projections = [];
|
|
4788
4918
|
const batch_handlers = /* @__PURE__ */ new Map();
|
|
4789
|
-
const add_projection = (proj) => {
|
|
4919
|
+
const add_projection = /* @__PURE__ */ __name((proj) => {
|
|
4790
4920
|
record_projection_reactions(proj);
|
|
4791
4921
|
merge_projection(proj, registry.events);
|
|
4792
4922
|
register_batch_handler(proj, batch_handlers);
|
|
4793
4923
|
if (proj.fold) fold_projections.push(proj);
|
|
4794
|
-
};
|
|
4924
|
+
}, "add_projection");
|
|
4795
4925
|
const fold_specs = [];
|
|
4796
4926
|
const lanes = [];
|
|
4797
4927
|
let _built = false;
|
|
4798
|
-
const read_wrap = (original) => {
|
|
4799
|
-
const wrapped = async (events, stream) => {
|
|
4928
|
+
const read_wrap = /* @__PURE__ */ __name((original) => {
|
|
4929
|
+
const wrapped = /* @__PURE__ */ __name(async (events, stream) => {
|
|
4800
4930
|
const read = events.map((e) => _hr.get(e.name)?.(e) ?? e);
|
|
4801
4931
|
return original(read, stream);
|
|
4802
|
-
};
|
|
4932
|
+
}, "wrapped");
|
|
4803
4933
|
const reset = original[FOLD_RESET];
|
|
4804
4934
|
if (reset) Object.defineProperty(wrapped, FOLD_RESET, { value: reset });
|
|
4805
4935
|
return wrapped;
|
|
4806
|
-
};
|
|
4807
|
-
const make_batch_handlers = () => {
|
|
4936
|
+
}, "read_wrap");
|
|
4937
|
+
const make_batch_handlers = /* @__PURE__ */ __name(() => {
|
|
4808
4938
|
const handlers = new Map(batch_handlers);
|
|
4809
4939
|
for (const spec of fold_specs) {
|
|
4810
4940
|
handlers.set(
|
|
@@ -4821,8 +4951,8 @@ function act() {
|
|
|
4821
4951
|
);
|
|
4822
4952
|
}
|
|
4823
4953
|
return handlers;
|
|
4824
|
-
};
|
|
4825
|
-
const finalize_deprecations = () => {
|
|
4954
|
+
}, "make_batch_handlers");
|
|
4955
|
+
const finalize_deprecations = /* @__PURE__ */ __name(() => {
|
|
4826
4956
|
const deprecation_summary = [];
|
|
4827
4957
|
for (const state2 of states.values()) {
|
|
4828
4958
|
const event_names = Object.keys(state2.events);
|
|
@@ -4855,19 +4985,19 @@ function act() {
|
|
|
4855
4985
|
`Act registered ${deprecation_summary.length} deprecated event(s): ${list}. These are legacy versions kept for the read path. Consider truncating closed streams via app.close() when feasible to reduce historical event load. See docs/docs/architecture/event-schema-evolution.md.`
|
|
4856
4986
|
);
|
|
4857
4987
|
}
|
|
4858
|
-
};
|
|
4859
|
-
const closed = (method) => {
|
|
4988
|
+
}, "finalize_deprecations");
|
|
4989
|
+
const closed = /* @__PURE__ */ __name((method) => {
|
|
4860
4990
|
throw new Error(
|
|
4861
4991
|
`act().${method}() was called after build(); the registry is already classified. Register everything before build() \u2014 build() itself may be called repeatedly (e.g. once per tenant with ActOptions.scoped).`
|
|
4862
4992
|
);
|
|
4863
|
-
};
|
|
4993
|
+
}, "closed");
|
|
4864
4994
|
const builder = {
|
|
4865
|
-
withState: (state2) => {
|
|
4995
|
+
withState: /* @__PURE__ */ __name((state2) => {
|
|
4866
4996
|
if (_built) closed("withState");
|
|
4867
4997
|
register_state(state2, states, registry.actions, registry.events);
|
|
4868
4998
|
return builder;
|
|
4869
|
-
},
|
|
4870
|
-
withSlice: (input) => {
|
|
4999
|
+
}, "withState"),
|
|
5000
|
+
withSlice: /* @__PURE__ */ __name((input) => {
|
|
4871
5001
|
if (_built) closed("withSlice");
|
|
4872
5002
|
for (const s of input.states.values()) {
|
|
4873
5003
|
register_state(s, states, registry.actions, registry.events);
|
|
@@ -4876,23 +5006,23 @@ function act() {
|
|
|
4876
5006
|
pending_projections.push(...input.projections);
|
|
4877
5007
|
for (const lane of input.lanes) register_lane(lane, lanes);
|
|
4878
5008
|
return builder;
|
|
4879
|
-
},
|
|
4880
|
-
withProjection: (proj) => {
|
|
5009
|
+
}, "withSlice"),
|
|
5010
|
+
withProjection: /* @__PURE__ */ __name((proj) => {
|
|
4881
5011
|
if (_built) closed("withProjection");
|
|
4882
5012
|
add_projection(proj);
|
|
4883
5013
|
return builder;
|
|
4884
|
-
},
|
|
4885
|
-
withActor: () => builder,
|
|
4886
|
-
withLane: (config2) => {
|
|
5014
|
+
}, "withProjection"),
|
|
5015
|
+
withActor: /* @__PURE__ */ __name(() => builder, "withActor"),
|
|
5016
|
+
withLane: /* @__PURE__ */ __name((config2) => {
|
|
4887
5017
|
if (_built) closed("withLane");
|
|
4888
5018
|
register_lane(config2, lanes);
|
|
4889
5019
|
return builder;
|
|
4890
|
-
},
|
|
4891
|
-
on: (event) => {
|
|
5020
|
+
}, "withLane"),
|
|
5021
|
+
on: /* @__PURE__ */ __name((event) => {
|
|
4892
5022
|
if (_built) closed("on");
|
|
4893
5023
|
return reaction_on(event, registry.events, builder);
|
|
4894
|
-
},
|
|
4895
|
-
build: (options) => {
|
|
5024
|
+
}, "on"),
|
|
5025
|
+
build: /* @__PURE__ */ __name((options) => {
|
|
4896
5026
|
check("act", options ?? {});
|
|
4897
5027
|
if (!_built) {
|
|
4898
5028
|
for (const proj of pending_projections) add_projection(proj);
|
|
@@ -4991,18 +5121,19 @@ function act() {
|
|
|
4991
5121
|
options,
|
|
4992
5122
|
lanes
|
|
4993
5123
|
);
|
|
4994
|
-
},
|
|
5124
|
+
}, "build"),
|
|
4995
5125
|
events: registry.events
|
|
4996
5126
|
};
|
|
4997
5127
|
return builder;
|
|
4998
5128
|
}
|
|
5129
|
+
__name(act, "act");
|
|
4999
5130
|
|
|
5000
5131
|
// src/builders/projection-builder.ts
|
|
5001
5132
|
function _projection(target) {
|
|
5002
5133
|
const events = {};
|
|
5003
5134
|
const default_resolver = typeof target === "string" ? { target } : void 0;
|
|
5004
5135
|
const base = {
|
|
5005
|
-
on: (entry) => {
|
|
5136
|
+
on: /* @__PURE__ */ __name((entry) => {
|
|
5006
5137
|
const keys = Object.keys(entry);
|
|
5007
5138
|
if (keys.length !== 1) throw new Error(".on() requires exactly one key");
|
|
5008
5139
|
const event = keys[0];
|
|
@@ -5014,7 +5145,7 @@ function _projection(target) {
|
|
|
5014
5145
|
};
|
|
5015
5146
|
}
|
|
5016
5147
|
return {
|
|
5017
|
-
do: (handler) => {
|
|
5148
|
+
do: /* @__PURE__ */ __name((handler) => {
|
|
5018
5149
|
const widened = base;
|
|
5019
5150
|
return add_reaction(
|
|
5020
5151
|
events,
|
|
@@ -5031,32 +5162,32 @@ function _projection(target) {
|
|
|
5031
5162
|
}),
|
|
5032
5163
|
widened
|
|
5033
5164
|
);
|
|
5034
|
-
}
|
|
5165
|
+
}, "do")
|
|
5035
5166
|
};
|
|
5036
|
-
},
|
|
5037
|
-
build: () => ({
|
|
5167
|
+
}, "on"),
|
|
5168
|
+
build: /* @__PURE__ */ __name(() => ({
|
|
5038
5169
|
_tag: "Projection",
|
|
5039
5170
|
events,
|
|
5040
5171
|
...target !== void 0 && { target }
|
|
5041
|
-
}),
|
|
5172
|
+
}), "build"),
|
|
5042
5173
|
events
|
|
5043
5174
|
};
|
|
5044
5175
|
if (typeof target === "string") {
|
|
5045
5176
|
return Object.assign(base, {
|
|
5046
|
-
batch: (handler) => ({
|
|
5047
|
-
build: () => ({
|
|
5177
|
+
batch: /* @__PURE__ */ __name((handler) => ({
|
|
5178
|
+
build: /* @__PURE__ */ __name(() => ({
|
|
5048
5179
|
_tag: "Projection",
|
|
5049
5180
|
events,
|
|
5050
5181
|
target,
|
|
5051
5182
|
batchHandler: handler
|
|
5052
|
-
})
|
|
5053
|
-
}),
|
|
5054
|
-
of: (...args) => {
|
|
5183
|
+
}), "build")
|
|
5184
|
+
}), "batch"),
|
|
5185
|
+
of: /* @__PURE__ */ __name((...args) => {
|
|
5055
5186
|
if (Object.keys(events).length > 0)
|
|
5056
5187
|
throw new Error(
|
|
5057
5188
|
`Projection "${target}" mixes .of() with .on() handlers \u2014 a projection either folds a state or declares handlers, never both`
|
|
5058
5189
|
);
|
|
5059
|
-
const is_state = (a) => !!a && typeof a.init === "function";
|
|
5190
|
+
const is_state = /* @__PURE__ */ __name((a) => !!a && typeof a.init === "function", "is_state");
|
|
5060
5191
|
const partials = args.filter(is_state);
|
|
5061
5192
|
const options = args.find((a) => !is_state(a)) ?? {};
|
|
5062
5193
|
if (partials.length === 0)
|
|
@@ -5094,23 +5225,25 @@ function _projection(target) {
|
|
|
5094
5225
|
};
|
|
5095
5226
|
}
|
|
5096
5227
|
return {
|
|
5097
|
-
flush: (handler) => ({
|
|
5098
|
-
build: () => ({
|
|
5228
|
+
flush: /* @__PURE__ */ __name((handler) => ({
|
|
5229
|
+
build: /* @__PURE__ */ __name(() => ({
|
|
5099
5230
|
_tag: "Projection",
|
|
5100
5231
|
events: fold_events,
|
|
5101
5232
|
target,
|
|
5102
5233
|
fold: { name, flush: handler, config: config2 }
|
|
5103
|
-
})
|
|
5104
|
-
})
|
|
5234
|
+
}), "build")
|
|
5235
|
+
}), "flush")
|
|
5105
5236
|
};
|
|
5106
|
-
}
|
|
5237
|
+
}, "of")
|
|
5107
5238
|
});
|
|
5108
5239
|
}
|
|
5109
5240
|
return base;
|
|
5110
5241
|
}
|
|
5242
|
+
__name(_projection, "_projection");
|
|
5111
5243
|
function projection(target) {
|
|
5112
5244
|
return _projection(target);
|
|
5113
5245
|
}
|
|
5246
|
+
__name(projection, "projection");
|
|
5114
5247
|
|
|
5115
5248
|
// src/builders/slice-builder.ts
|
|
5116
5249
|
function slice() {
|
|
@@ -5120,30 +5253,31 @@ function slice() {
|
|
|
5120
5253
|
const projections = [];
|
|
5121
5254
|
const lanes = [];
|
|
5122
5255
|
const builder = {
|
|
5123
|
-
withState: (state2) => {
|
|
5256
|
+
withState: /* @__PURE__ */ __name((state2) => {
|
|
5124
5257
|
register_state(state2, states, actions, events);
|
|
5125
5258
|
return builder;
|
|
5126
|
-
},
|
|
5127
|
-
withProjection: (proj) => {
|
|
5259
|
+
}, "withState"),
|
|
5260
|
+
withProjection: /* @__PURE__ */ __name((proj) => {
|
|
5128
5261
|
projections.push(proj);
|
|
5129
5262
|
return builder;
|
|
5130
|
-
},
|
|
5131
|
-
withLane: (config2) => {
|
|
5263
|
+
}, "withProjection"),
|
|
5264
|
+
withLane: /* @__PURE__ */ __name((config2) => {
|
|
5132
5265
|
register_lane(config2, lanes);
|
|
5133
5266
|
return builder;
|
|
5134
|
-
},
|
|
5135
|
-
on: (event) => reaction_on(event, events, builder),
|
|
5136
|
-
build: () => ({
|
|
5267
|
+
}, "withLane"),
|
|
5268
|
+
on: /* @__PURE__ */ __name((event) => reaction_on(event, events, builder), "on"),
|
|
5269
|
+
build: /* @__PURE__ */ __name(() => ({
|
|
5137
5270
|
_tag: "Slice",
|
|
5138
5271
|
states,
|
|
5139
5272
|
events,
|
|
5140
5273
|
projections,
|
|
5141
5274
|
lanes
|
|
5142
|
-
}),
|
|
5275
|
+
}), "build"),
|
|
5143
5276
|
events
|
|
5144
5277
|
};
|
|
5145
5278
|
return builder;
|
|
5146
5279
|
}
|
|
5280
|
+
__name(slice, "slice");
|
|
5147
5281
|
|
|
5148
5282
|
// src/builders/state-builder.ts
|
|
5149
5283
|
function state(entry) {
|
|
@@ -5175,8 +5309,8 @@ function state(entry) {
|
|
|
5175
5309
|
// `act().build()` flips both on states with `sensitive(...)`
|
|
5176
5310
|
// events to bake in the gate / split and gate the cache write.
|
|
5177
5311
|
pii_aware: false,
|
|
5178
|
-
view: (event) => event,
|
|
5179
|
-
message: (validated) => validated
|
|
5312
|
+
view: /* @__PURE__ */ __name((event) => event, "view"),
|
|
5313
|
+
message: /* @__PURE__ */ __name((validated) => validated, "message")
|
|
5180
5314
|
};
|
|
5181
5315
|
const builder = action_builder(internal);
|
|
5182
5316
|
return Object.assign(builder, {
|
|
@@ -5190,6 +5324,7 @@ function state(entry) {
|
|
|
5190
5324
|
}
|
|
5191
5325
|
};
|
|
5192
5326
|
}
|
|
5327
|
+
__name(state, "state");
|
|
5193
5328
|
function action_builder(state2) {
|
|
5194
5329
|
const internal = state2;
|
|
5195
5330
|
const builder = {
|
|
@@ -5226,10 +5361,12 @@ function action_builder(state2) {
|
|
|
5226
5361
|
(internal.loads ??= {})[action2] = loads;
|
|
5227
5362
|
return { loads: load2, requires, emit };
|
|
5228
5363
|
}
|
|
5364
|
+
__name(load2, "load");
|
|
5229
5365
|
function requires(rules) {
|
|
5230
5366
|
(internal.requires ??= {})[action2] = rules;
|
|
5231
5367
|
return { emit };
|
|
5232
5368
|
}
|
|
5369
|
+
__name(requires, "requires");
|
|
5233
5370
|
function emit(handler) {
|
|
5234
5371
|
if (typeof handler === "string") {
|
|
5235
5372
|
const event_name = handler;
|
|
@@ -5245,6 +5382,7 @@ function action_builder(state2) {
|
|
|
5245
5382
|
}
|
|
5246
5383
|
return builder;
|
|
5247
5384
|
}
|
|
5385
|
+
__name(emit, "emit");
|
|
5248
5386
|
return { loads: load2, requires, emit };
|
|
5249
5387
|
},
|
|
5250
5388
|
snap(snap2) {
|
|
@@ -5295,6 +5433,7 @@ function action_builder(state2) {
|
|
|
5295
5433
|
};
|
|
5296
5434
|
return builder;
|
|
5297
5435
|
}
|
|
5436
|
+
__name(action_builder, "action_builder");
|
|
5298
5437
|
|
|
5299
5438
|
// src/csv.ts
|
|
5300
5439
|
import { createReadStream, createWriteStream } from "fs";
|
|
@@ -5309,6 +5448,9 @@ var CSV_COLUMNS = [
|
|
|
5309
5448
|
"meta"
|
|
5310
5449
|
];
|
|
5311
5450
|
var CsvFile = class {
|
|
5451
|
+
static {
|
|
5452
|
+
__name(this, "CsvFile");
|
|
5453
|
+
}
|
|
5312
5454
|
path;
|
|
5313
5455
|
blob;
|
|
5314
5456
|
constructor(options) {
|
|
@@ -5402,6 +5544,7 @@ async function* linesFromFile(path) {
|
|
|
5402
5544
|
stream.close();
|
|
5403
5545
|
}
|
|
5404
5546
|
}
|
|
5547
|
+
__name(linesFromFile, "linesFromFile");
|
|
5405
5548
|
async function* linesFromBlob(blob) {
|
|
5406
5549
|
let start = 0;
|
|
5407
5550
|
while (start < blob.length) {
|
|
@@ -5412,6 +5555,7 @@ async function* linesFromBlob(blob) {
|
|
|
5412
5555
|
await Promise.resolve();
|
|
5413
5556
|
}
|
|
5414
5557
|
}
|
|
5558
|
+
__name(linesFromBlob, "linesFromBlob");
|
|
5415
5559
|
function parse_csv_line(line) {
|
|
5416
5560
|
const fields = [];
|
|
5417
5561
|
let i = 0;
|
|
@@ -5445,10 +5589,12 @@ function parse_csv_line(line) {
|
|
|
5445
5589
|
}
|
|
5446
5590
|
return fields;
|
|
5447
5591
|
}
|
|
5592
|
+
__name(parse_csv_line, "parse_csv_line");
|
|
5448
5593
|
function csv_escape(value) {
|
|
5449
5594
|
if (/[",\n\r]/.test(value)) return `"${value.replace(/"/g, '""')}"`;
|
|
5450
5595
|
return value;
|
|
5451
5596
|
}
|
|
5597
|
+
__name(csv_escape, "csv_escape");
|
|
5452
5598
|
function write_line(writer, line) {
|
|
5453
5599
|
return new Promise((resolve, reject) => {
|
|
5454
5600
|
writer.write(`${line}
|
|
@@ -5458,6 +5604,7 @@ function write_line(writer, line) {
|
|
|
5458
5604
|
});
|
|
5459
5605
|
});
|
|
5460
5606
|
}
|
|
5607
|
+
__name(write_line, "write_line");
|
|
5461
5608
|
|
|
5462
5609
|
// src/deprecated.ts
|
|
5463
5610
|
var check_appends = checkAppends;
|
|
@@ -5482,9 +5629,9 @@ var DEFAULT_MAX_SUBSCRIBED_STREAMS2 = DEFAULT_MAX_SUBSCRIBED_STREAMS;
|
|
|
5482
5629
|
var DEFAULT_SETTLE_DEBOUNCE_MS2 = DEFAULT_SETTLE_DEBOUNCE_MS;
|
|
5483
5630
|
var PackageSchema = package_schema;
|
|
5484
5631
|
var default_scope = unscoped_ports;
|
|
5485
|
-
var extend = (source, schema, target) => ({ ...target, ...validate("config", source, schema) });
|
|
5632
|
+
var extend = /* @__PURE__ */ __name((source, schema, target) => ({ ...target, ...validate("config", source, schema) }), "extend");
|
|
5486
5633
|
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])?$/;
|
|
5487
|
-
var dateReviver = (_key, value) => typeof value === "string" && ISO_8601.test(value) ? new Date(value) : value;
|
|
5634
|
+
var dateReviver = /* @__PURE__ */ __name((_key, value) => typeof value === "string" && ISO_8601.test(value) ? new Date(value) : value, "dateReviver");
|
|
5488
5635
|
export {
|
|
5489
5636
|
Act,
|
|
5490
5637
|
ActorSchema2 as ActorSchema,
|