@rotorsoft/act 1.10.0 → 1.10.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/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +12 -12
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/console-logger.d.ts +2 -2
- package/dist/@types/adapters/console-logger.d.ts.map +1 -1
- package/dist/@types/adapters/in-memory-store.d.ts +6 -6
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/builders/state-builder.d.ts +2 -2
- package/dist/@types/builders/state-builder.d.ts.map +1 -1
- package/dist/@types/internal/audit.d.ts +4 -4
- package/dist/@types/internal/audit.d.ts.map +1 -1
- package/dist/@types/internal/backoff.d.ts +1 -1
- package/dist/@types/internal/backoff.d.ts.map +1 -1
- package/dist/@types/internal/build-classify.d.ts +11 -11
- package/dist/@types/internal/build-classify.d.ts.map +1 -1
- package/dist/@types/internal/close-cycle.d.ts +3 -3
- package/dist/@types/internal/close-cycle.d.ts.map +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts +4 -4
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/correlator.d.ts +2 -2
- package/dist/@types/internal/correlator.d.ts.map +1 -1
- package/dist/@types/internal/drain-cycle.d.ts +20 -20
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
- package/dist/@types/internal/drain-ratio.d.ts +1 -1
- package/dist/@types/internal/drain-ratio.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts +2 -2
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/internal/event-versions.d.ts +2 -2
- package/dist/@types/internal/event-versions.d.ts.map +1 -1
- package/dist/@types/internal/index.d.ts +7 -7
- package/dist/@types/internal/index.d.ts.map +1 -1
- package/dist/@types/internal/merge.d.ts +3 -3
- package/dist/@types/internal/merge.d.ts.map +1 -1
- package/dist/@types/internal/reactions.d.ts +6 -6
- package/dist/@types/internal/reactions.d.ts.map +1 -1
- package/dist/@types/internal/sensitive.d.ts +2 -2
- package/dist/@types/internal/settle.d.ts +3 -3
- package/dist/@types/internal/settle.d.ts.map +1 -1
- package/dist/@types/internal/tracing.d.ts +5 -5
- package/dist/@types/internal/tracing.d.ts.map +1 -1
- package/dist/{chunk-3ZTFNAY7.js → chunk-3Z2HU726.js} +134 -133
- package/dist/chunk-3Z2HU726.js.map +1 -0
- package/dist/{chunk-XSBT63QX.js → chunk-BY5JPOZR.js} +1 -1
- package/dist/{chunk-XSBT63QX.js.map → chunk-BY5JPOZR.js.map} +1 -1
- package/dist/index.cjs +558 -552
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +428 -423
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +132 -131
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +2 -2
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-3ZTFNAY7.js.map +0 -1
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
Environments,
|
|
4
4
|
LogLevels,
|
|
5
5
|
ValidationError
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BY5JPOZR.js";
|
|
7
7
|
|
|
8
8
|
// src/adapters/console-logger.ts
|
|
9
9
|
var LEVEL_VALUES = {
|
|
@@ -49,7 +49,7 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
49
49
|
this._pretty = pretty;
|
|
50
50
|
this.level = level;
|
|
51
51
|
const threshold = LEVEL_VALUES[level] ?? 30;
|
|
52
|
-
const write = pretty ? this.
|
|
52
|
+
const write = pretty ? this._pretty_write.bind(this, bindings) : this._json_write.bind(this, bindings);
|
|
53
53
|
this.fatal = write.bind(this, "fatal", 60);
|
|
54
54
|
this.error = threshold <= 50 ? write.bind(this, "error", 50) : noop;
|
|
55
55
|
this.warn = threshold <= 40 ? write.bind(this, "warn", 40) : noop;
|
|
@@ -68,24 +68,24 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
68
68
|
bindings
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
_json_write(bindings, level, _num, obj_or_msg, msg) {
|
|
72
72
|
let obj;
|
|
73
73
|
let message;
|
|
74
|
-
if (typeof
|
|
75
|
-
message =
|
|
74
|
+
if (typeof obj_or_msg === "string") {
|
|
75
|
+
message = obj_or_msg;
|
|
76
76
|
obj = {};
|
|
77
|
-
} else if (
|
|
78
|
-
message = msg ??
|
|
77
|
+
} else if (obj_or_msg instanceof Error) {
|
|
78
|
+
message = msg ?? obj_or_msg.message;
|
|
79
79
|
obj = {
|
|
80
|
-
error: { message:
|
|
81
|
-
stack:
|
|
80
|
+
error: { message: obj_or_msg.message, name: obj_or_msg.name },
|
|
81
|
+
stack: obj_or_msg.stack
|
|
82
82
|
};
|
|
83
|
-
} else if (
|
|
83
|
+
} else if (obj_or_msg !== null && typeof obj_or_msg === "object") {
|
|
84
84
|
message = msg;
|
|
85
|
-
obj = { ...
|
|
85
|
+
obj = { ...obj_or_msg };
|
|
86
86
|
} else {
|
|
87
87
|
message = msg;
|
|
88
|
-
obj = { value:
|
|
88
|
+
obj = { value: obj_or_msg };
|
|
89
89
|
}
|
|
90
90
|
const entry = Object.assign({ level, time: Date.now() }, bindings, obj);
|
|
91
91
|
if (message) entry.msg = message;
|
|
@@ -102,29 +102,29 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
102
102
|
}
|
|
103
103
|
process.stdout.write(line + "\n");
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
_pretty_write(bindings, level, _num, obj_or_msg, msg) {
|
|
106
106
|
const color = LEVEL_COLORS[level];
|
|
107
107
|
const tag = `${color}${level.toUpperCase().padEnd(5)}${RESET}`;
|
|
108
108
|
const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
|
|
109
109
|
let message;
|
|
110
110
|
let data;
|
|
111
|
-
if (typeof
|
|
112
|
-
message =
|
|
113
|
-
} else if (
|
|
114
|
-
message = msg ??
|
|
115
|
-
data =
|
|
111
|
+
if (typeof obj_or_msg === "string") {
|
|
112
|
+
message = obj_or_msg;
|
|
113
|
+
} else if (obj_or_msg instanceof Error) {
|
|
114
|
+
message = msg ?? obj_or_msg.message;
|
|
115
|
+
data = obj_or_msg.stack;
|
|
116
116
|
} else {
|
|
117
117
|
message = msg ?? "";
|
|
118
|
-
if (
|
|
118
|
+
if (obj_or_msg !== void 0 && obj_or_msg !== null) {
|
|
119
119
|
try {
|
|
120
|
-
data = JSON.stringify(
|
|
120
|
+
data = JSON.stringify(obj_or_msg);
|
|
121
121
|
} catch {
|
|
122
122
|
data = "[unserializable]";
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
const
|
|
127
|
-
const parts = [ts, tag, message, data,
|
|
126
|
+
const bind_str = bindings && Object.keys(bindings).length ? ` ${JSON.stringify(bindings)}` : "";
|
|
127
|
+
const parts = [ts, tag, message, data, bind_str].filter(Boolean);
|
|
128
128
|
process.stdout.write(parts.join(" ") + "\n");
|
|
129
129
|
}
|
|
130
130
|
};
|
|
@@ -280,14 +280,14 @@ var InMemoryStream = class {
|
|
|
280
280
|
* Bump the priority via {@link subscribe}: keeps the maximum across
|
|
281
281
|
* reactions so the highest-priority registrant wins.
|
|
282
282
|
*/
|
|
283
|
-
|
|
283
|
+
bump_priority(priority) {
|
|
284
284
|
if (priority > this._priority) this._priority = priority;
|
|
285
285
|
}
|
|
286
286
|
/**
|
|
287
287
|
* Set the priority outright via {@link prioritize}: operator
|
|
288
288
|
* runtime override that ignores the build-time `max()` invariant.
|
|
289
289
|
*/
|
|
290
|
-
|
|
290
|
+
set_priority(priority) {
|
|
291
291
|
this._priority = priority;
|
|
292
292
|
}
|
|
293
293
|
get is_available() {
|
|
@@ -409,28 +409,28 @@ var InMemoryStore = class {
|
|
|
409
409
|
// stored stream positions and other metadata
|
|
410
410
|
_streams = /* @__PURE__ */ new Map();
|
|
411
411
|
// last committed version per stream — O(1) replacement for filter-on-commit
|
|
412
|
-
|
|
412
|
+
_stream_versions = /* @__PURE__ */ new Map();
|
|
413
413
|
// max non-snapshot event id per stream — drives the source-pattern probe in claim()
|
|
414
414
|
// without scanning the full event log.
|
|
415
|
-
|
|
415
|
+
_max_event_id_by_stream = /* @__PURE__ */ new Map();
|
|
416
416
|
// global max non-snapshot event id — fast pre-check for source-less streams in claim()
|
|
417
|
-
|
|
417
|
+
_max_non_snap_event_id = -1;
|
|
418
418
|
// stream → (event_id → cloned sensitive payload). Two-level so `forget_pii`
|
|
419
419
|
// is O(1) — drop the inner Map for the stream and the wipe is done — mirroring
|
|
420
420
|
// the `DELETE WHERE stream = ?` scope that durable adapters get from their
|
|
421
421
|
// stream index. Entries exist only for events committed with a non-null
|
|
422
422
|
// `pii` field; absence means "no PII" (returned as `null` on load).
|
|
423
423
|
_pii = /* @__PURE__ */ new Map();
|
|
424
|
-
|
|
424
|
+
_reset_indexes() {
|
|
425
425
|
this._events.length = 0;
|
|
426
|
-
this.
|
|
427
|
-
this.
|
|
428
|
-
this.
|
|
426
|
+
this._stream_versions.clear();
|
|
427
|
+
this._max_event_id_by_stream.clear();
|
|
428
|
+
this._max_non_snap_event_id = -1;
|
|
429
429
|
this._pii.clear();
|
|
430
430
|
}
|
|
431
431
|
// Attach the isolated PII payload (or null) to an event before handing it to
|
|
432
432
|
// a caller. Allocation-free for events without PII — by far the common case.
|
|
433
|
-
|
|
433
|
+
_with_pii(e) {
|
|
434
434
|
const pii = this._pii.get(e.stream)?.get(e.id);
|
|
435
435
|
return pii ? { ...e, pii } : e;
|
|
436
436
|
}
|
|
@@ -440,7 +440,7 @@ var InMemoryStore = class {
|
|
|
440
440
|
*/
|
|
441
441
|
async dispose() {
|
|
442
442
|
await sleep();
|
|
443
|
-
this.
|
|
443
|
+
this._reset_indexes();
|
|
444
444
|
}
|
|
445
445
|
/**
|
|
446
446
|
* Seed the store with initial data (no-op for in-memory).
|
|
@@ -455,7 +455,7 @@ var InMemoryStore = class {
|
|
|
455
455
|
*/
|
|
456
456
|
async drop() {
|
|
457
457
|
await sleep();
|
|
458
|
-
this.
|
|
458
|
+
this._reset_indexes();
|
|
459
459
|
this._streams = /* @__PURE__ */ new Map();
|
|
460
460
|
}
|
|
461
461
|
in_query(query, e) {
|
|
@@ -489,7 +489,7 @@ var InMemoryStore = class {
|
|
|
489
489
|
if (query.after && e.id <= query.after) break;
|
|
490
490
|
if (query.created_after && e.created <= query.created_after) break;
|
|
491
491
|
await Promise.resolve(
|
|
492
|
-
callback(this.
|
|
492
|
+
callback(this._with_pii(e))
|
|
493
493
|
);
|
|
494
494
|
count++;
|
|
495
495
|
if (query?.limit && count >= query.limit) break;
|
|
@@ -503,7 +503,7 @@ var InMemoryStore = class {
|
|
|
503
503
|
if (query?.before && e.id >= query.before) break;
|
|
504
504
|
if (query?.created_before && e.created >= query.created_before) break;
|
|
505
505
|
await Promise.resolve(
|
|
506
|
-
callback(this.
|
|
506
|
+
callback(this._with_pii(e))
|
|
507
507
|
);
|
|
508
508
|
count++;
|
|
509
509
|
if (query?.limit && count >= query.limit) break;
|
|
@@ -522,17 +522,17 @@ var InMemoryStore = class {
|
|
|
522
522
|
*/
|
|
523
523
|
async commit(stream, msgs, meta, expectedVersion) {
|
|
524
524
|
await sleep();
|
|
525
|
-
const
|
|
526
|
-
if (typeof expectedVersion === "number" &&
|
|
525
|
+
const current_version = this._stream_versions.get(stream) ?? -1;
|
|
526
|
+
if (typeof expectedVersion === "number" && current_version !== expectedVersion) {
|
|
527
527
|
throw new ConcurrencyError(
|
|
528
528
|
stream,
|
|
529
|
-
|
|
529
|
+
current_version,
|
|
530
530
|
msgs,
|
|
531
531
|
expectedVersion
|
|
532
532
|
);
|
|
533
533
|
}
|
|
534
|
-
let version =
|
|
535
|
-
let
|
|
534
|
+
let version = current_version + 1;
|
|
535
|
+
let last_non_snap_id = -1;
|
|
536
536
|
const committed = msgs.map(({ name, data, pii }) => {
|
|
537
537
|
const c = {
|
|
538
538
|
id: this._events.length,
|
|
@@ -545,21 +545,21 @@ var InMemoryStore = class {
|
|
|
545
545
|
};
|
|
546
546
|
this._events.push(c);
|
|
547
547
|
if (pii != null) {
|
|
548
|
-
let
|
|
549
|
-
if (!
|
|
550
|
-
|
|
551
|
-
this._pii.set(stream,
|
|
548
|
+
let per_stream = this._pii.get(stream);
|
|
549
|
+
if (!per_stream) {
|
|
550
|
+
per_stream = /* @__PURE__ */ new Map();
|
|
551
|
+
this._pii.set(stream, per_stream);
|
|
552
552
|
}
|
|
553
|
-
|
|
553
|
+
per_stream.set(c.id, structuredClone(pii));
|
|
554
554
|
}
|
|
555
|
-
if (name !== SNAP_EVENT)
|
|
555
|
+
if (name !== SNAP_EVENT) last_non_snap_id = c.id;
|
|
556
556
|
version++;
|
|
557
|
-
return this.
|
|
557
|
+
return this._with_pii(c);
|
|
558
558
|
});
|
|
559
|
-
this.
|
|
560
|
-
if (
|
|
561
|
-
this.
|
|
562
|
-
this.
|
|
559
|
+
this._stream_versions.set(stream, version - 1);
|
|
560
|
+
if (last_non_snap_id >= 0) {
|
|
561
|
+
this._max_event_id_by_stream.set(stream, last_non_snap_id);
|
|
562
|
+
this._max_non_snap_event_id = last_non_snap_id;
|
|
563
563
|
}
|
|
564
564
|
return committed;
|
|
565
565
|
}
|
|
@@ -574,26 +574,26 @@ var InMemoryStore = class {
|
|
|
574
574
|
*/
|
|
575
575
|
async claim(lagging, leading, by, millis, lane) {
|
|
576
576
|
await sleep();
|
|
577
|
-
const
|
|
578
|
-
const
|
|
579
|
-
let re =
|
|
577
|
+
const source_regex = /* @__PURE__ */ new Map();
|
|
578
|
+
const get_regex = (source) => {
|
|
579
|
+
let re = source_regex.get(source);
|
|
580
580
|
if (!re) {
|
|
581
581
|
re = new RegExp(source);
|
|
582
|
-
|
|
582
|
+
source_regex.set(source, re);
|
|
583
583
|
}
|
|
584
584
|
return re;
|
|
585
585
|
};
|
|
586
|
-
const
|
|
586
|
+
const has_work = (s) => {
|
|
587
587
|
if (s.at < 0) return true;
|
|
588
|
-
if (!s.source) return s.at < this.
|
|
589
|
-
const re =
|
|
590
|
-
for (const [
|
|
591
|
-
if (maxId > s.at && re.test(
|
|
588
|
+
if (!s.source) return s.at < this._max_non_snap_event_id;
|
|
589
|
+
const re = get_regex(s.source);
|
|
590
|
+
for (const [stream_name, maxId] of this._max_event_id_by_stream) {
|
|
591
|
+
if (maxId > s.at && re.test(stream_name)) return true;
|
|
592
592
|
}
|
|
593
593
|
return false;
|
|
594
594
|
};
|
|
595
595
|
const available = [...this._streams.values()].filter(
|
|
596
|
-
(s) => s.is_available &&
|
|
596
|
+
(s) => s.is_available && has_work(s) && (lane === void 0 || s.lane === lane)
|
|
597
597
|
);
|
|
598
598
|
const lag = available.sort((a, b) => b.priority - a.priority || a.at - b.at).slice(0, lagging).map((s) => ({
|
|
599
599
|
stream: s.stream,
|
|
@@ -637,7 +637,7 @@ var InMemoryStore = class {
|
|
|
637
637
|
} of streams) {
|
|
638
638
|
const existing = this._streams.get(stream);
|
|
639
639
|
if (existing) {
|
|
640
|
-
existing.
|
|
640
|
+
existing.bump_priority(priority);
|
|
641
641
|
existing.lane = lane;
|
|
642
642
|
} else {
|
|
643
643
|
this._streams.set(
|
|
@@ -675,17 +675,17 @@ var InMemoryStore = class {
|
|
|
675
675
|
* cached in the closure so callers can apply it across the streams
|
|
676
676
|
* map without re-compiling per iteration.
|
|
677
677
|
*/
|
|
678
|
-
|
|
679
|
-
const
|
|
680
|
-
const
|
|
678
|
+
_filter_predicate(filter) {
|
|
679
|
+
const stream_re = filter.stream && !filter.stream_exact ? new RegExp(filter.stream) : void 0;
|
|
680
|
+
const source_re = filter.source && !filter.source_exact ? new RegExp(filter.source) : void 0;
|
|
681
681
|
return (s) => {
|
|
682
682
|
if (filter.stream !== void 0) {
|
|
683
|
-
if (filter.stream_exact ? s.stream !== filter.stream : !
|
|
683
|
+
if (filter.stream_exact ? s.stream !== filter.stream : !stream_re.test(s.stream))
|
|
684
684
|
return false;
|
|
685
685
|
}
|
|
686
686
|
if (filter.source !== void 0) {
|
|
687
687
|
if (s.source === void 0) return false;
|
|
688
|
-
if (filter.source_exact ? s.source !== filter.source : !
|
|
688
|
+
if (filter.source_exact ? s.source !== filter.source : !source_re.test(s.source))
|
|
689
689
|
return false;
|
|
690
690
|
}
|
|
691
691
|
if (filter.blocked !== void 0 && s.blocked !== filter.blocked)
|
|
@@ -714,7 +714,7 @@ var InMemoryStore = class {
|
|
|
714
714
|
}
|
|
715
715
|
}
|
|
716
716
|
} else {
|
|
717
|
-
const matches = this.
|
|
717
|
+
const matches = this._filter_predicate(input);
|
|
718
718
|
for (const s of this._streams.values()) {
|
|
719
719
|
if (matches(s)) {
|
|
720
720
|
s.reset();
|
|
@@ -759,7 +759,7 @@ var InMemoryStore = class {
|
|
|
759
759
|
if (s?.unblock()) count++;
|
|
760
760
|
}
|
|
761
761
|
} else {
|
|
762
|
-
const matches = this.
|
|
762
|
+
const matches = this._filter_predicate({ ...input, blocked: true });
|
|
763
763
|
for (const s of this._streams.values()) {
|
|
764
764
|
if (matches(s) && s.unblock()) count++;
|
|
765
765
|
}
|
|
@@ -777,12 +777,12 @@ var InMemoryStore = class {
|
|
|
777
777
|
*/
|
|
778
778
|
async prioritize(filter, priority) {
|
|
779
779
|
await sleep();
|
|
780
|
-
const matches = this.
|
|
780
|
+
const matches = this._filter_predicate(filter);
|
|
781
781
|
let count = 0;
|
|
782
782
|
for (const s of this._streams.values()) {
|
|
783
783
|
if (!matches(s)) continue;
|
|
784
784
|
if (s.priority !== priority) {
|
|
785
|
-
s.
|
|
785
|
+
s.set_priority(priority);
|
|
786
786
|
count++;
|
|
787
787
|
}
|
|
788
788
|
}
|
|
@@ -798,8 +798,8 @@ var InMemoryStore = class {
|
|
|
798
798
|
const limit = query?.limit ?? 100;
|
|
799
799
|
const after = query?.after;
|
|
800
800
|
const blocked = query?.blocked;
|
|
801
|
-
const
|
|
802
|
-
const
|
|
801
|
+
const stream_re = query?.stream && !query.stream_exact ? new RegExp(query.stream) : void 0;
|
|
802
|
+
const source_re = query?.source && !query.source_exact ? new RegExp(query.source) : void 0;
|
|
803
803
|
const sorted = [...this._streams.values()].sort(
|
|
804
804
|
(a, b) => a.stream.localeCompare(b.stream)
|
|
805
805
|
);
|
|
@@ -807,12 +807,12 @@ var InMemoryStore = class {
|
|
|
807
807
|
for (const s of sorted) {
|
|
808
808
|
if (after !== void 0 && s.stream <= after) continue;
|
|
809
809
|
if (query?.stream !== void 0) {
|
|
810
|
-
if (query.stream_exact ? s.stream !== query.stream : !
|
|
810
|
+
if (query.stream_exact ? s.stream !== query.stream : !stream_re.test(s.stream))
|
|
811
811
|
continue;
|
|
812
812
|
}
|
|
813
813
|
if (query?.source !== void 0) {
|
|
814
814
|
if (s.source === void 0) continue;
|
|
815
|
-
if (query.source_exact ? s.source !== query.source : !
|
|
815
|
+
if (query.source_exact ? s.source !== query.source : !source_re.test(s.source))
|
|
816
816
|
continue;
|
|
817
817
|
}
|
|
818
818
|
if (blocked !== void 0 && s.blocked !== blocked) continue;
|
|
@@ -853,44 +853,44 @@ var InMemoryStore = class {
|
|
|
853
853
|
async query_stats(input, options) {
|
|
854
854
|
await sleep();
|
|
855
855
|
const exclude = new Set(options?.exclude ?? []);
|
|
856
|
-
const
|
|
857
|
-
const
|
|
858
|
-
const
|
|
856
|
+
const want_tail = options?.tail ?? false;
|
|
857
|
+
const want_count = options?.count ?? false;
|
|
858
|
+
const want_names = options?.names ?? false;
|
|
859
859
|
const before = options?.before;
|
|
860
|
-
const
|
|
860
|
+
const array_targets = Array.isArray(input) ? new Set(input) : null;
|
|
861
861
|
const filter = Array.isArray(input) ? null : input;
|
|
862
|
-
const
|
|
863
|
-
const
|
|
864
|
-
const
|
|
865
|
-
const cached =
|
|
862
|
+
const stream_re = filter?.stream && !filter.stream_exact ? new RegExp(filter.stream) : void 0;
|
|
863
|
+
const scope_cache = /* @__PURE__ */ new Map();
|
|
864
|
+
const in_scope = (stream) => {
|
|
865
|
+
const cached = scope_cache.get(stream);
|
|
866
866
|
if (cached !== void 0) return cached;
|
|
867
867
|
let ok = true;
|
|
868
|
-
if (
|
|
869
|
-
ok =
|
|
868
|
+
if (array_targets) {
|
|
869
|
+
ok = array_targets.has(stream);
|
|
870
870
|
} else if (filter?.stream !== void 0) {
|
|
871
871
|
ok = filter.stream_exact ? stream === filter.stream : (
|
|
872
|
-
// biome-ignore lint/style/noNonNullAssertion:
|
|
873
|
-
|
|
872
|
+
// biome-ignore lint/style/noNonNullAssertion: stream_re set when stream is regex
|
|
873
|
+
stream_re.test(stream)
|
|
874
874
|
);
|
|
875
875
|
}
|
|
876
|
-
|
|
876
|
+
scope_cache.set(stream, ok);
|
|
877
877
|
return ok;
|
|
878
878
|
};
|
|
879
879
|
const acc = /* @__PURE__ */ new Map();
|
|
880
880
|
for (const e of this._events) {
|
|
881
881
|
if (before !== void 0 && e.id >= before) continue;
|
|
882
|
-
if (!
|
|
882
|
+
if (!in_scope(e.stream)) continue;
|
|
883
883
|
if (exclude.has(e.name)) continue;
|
|
884
884
|
let a = acc.get(e.stream);
|
|
885
885
|
if (!a) {
|
|
886
886
|
a = { head: e, count: 0 };
|
|
887
|
-
if (
|
|
888
|
-
if (
|
|
887
|
+
if (want_tail) a.tail = e;
|
|
888
|
+
if (want_names) a.names = {};
|
|
889
889
|
acc.set(e.stream, a);
|
|
890
890
|
}
|
|
891
891
|
a.head = e;
|
|
892
892
|
a.count++;
|
|
893
|
-
if (
|
|
893
|
+
if (want_names) {
|
|
894
894
|
const n = String(e.name);
|
|
895
895
|
a.names[n] = (a.names[n] ?? 0) + 1;
|
|
896
896
|
}
|
|
@@ -898,9 +898,9 @@ var InMemoryStore = class {
|
|
|
898
898
|
const out = /* @__PURE__ */ new Map();
|
|
899
899
|
for (const [stream, a] of acc) {
|
|
900
900
|
const stats = { head: a.head };
|
|
901
|
-
if (
|
|
902
|
-
if (
|
|
903
|
-
if (
|
|
901
|
+
if (want_tail) stats.tail = a.tail;
|
|
902
|
+
if (want_count) stats.count = a.count;
|
|
903
|
+
if (want_names) stats.names = a.names;
|
|
904
904
|
out.set(stream, stats);
|
|
905
905
|
}
|
|
906
906
|
return out;
|
|
@@ -912,18 +912,18 @@ var InMemoryStore = class {
|
|
|
912
912
|
*/
|
|
913
913
|
async truncate(targets) {
|
|
914
914
|
await sleep();
|
|
915
|
-
const
|
|
916
|
-
const
|
|
915
|
+
const deleted_counts = /* @__PURE__ */ new Map();
|
|
916
|
+
const stream_set = new Set(targets.map((t) => t.stream));
|
|
917
917
|
for (const e of this._events) {
|
|
918
|
-
if (
|
|
919
|
-
|
|
918
|
+
if (stream_set.has(e.stream)) {
|
|
919
|
+
deleted_counts.set(e.stream, (deleted_counts.get(e.stream) ?? 0) + 1);
|
|
920
920
|
}
|
|
921
921
|
}
|
|
922
|
-
this._events = this._events.filter((e) => !
|
|
923
|
-
for (const stream of
|
|
922
|
+
this._events = this._events.filter((e) => !stream_set.has(e.stream));
|
|
923
|
+
for (const stream of stream_set) {
|
|
924
924
|
this._streams.delete(stream);
|
|
925
|
-
this.
|
|
926
|
-
this.
|
|
925
|
+
this._stream_versions.delete(stream);
|
|
926
|
+
this._max_event_id_by_stream.delete(stream);
|
|
927
927
|
}
|
|
928
928
|
const result = /* @__PURE__ */ new Map();
|
|
929
929
|
for (const { stream, snapshot, meta } of targets) {
|
|
@@ -937,18 +937,19 @@ var InMemoryStore = class {
|
|
|
937
937
|
meta: meta ?? { correlation: "", causation: {} }
|
|
938
938
|
};
|
|
939
939
|
this._events.push(event);
|
|
940
|
-
this.
|
|
940
|
+
this._stream_versions.set(stream, 0);
|
|
941
941
|
if (event.name !== SNAP_EVENT) {
|
|
942
|
-
this.
|
|
942
|
+
this._max_event_id_by_stream.set(stream, event.id);
|
|
943
943
|
}
|
|
944
944
|
result.set(stream, {
|
|
945
|
-
deleted:
|
|
945
|
+
deleted: deleted_counts.get(stream) ?? 0,
|
|
946
946
|
committed: event
|
|
947
947
|
});
|
|
948
948
|
}
|
|
949
949
|
let max = -1;
|
|
950
|
-
for (const id of this.
|
|
951
|
-
|
|
950
|
+
for (const id of this._max_event_id_by_stream.values())
|
|
951
|
+
if (id > max) max = id;
|
|
952
|
+
this._max_non_snap_event_id = max;
|
|
952
953
|
return result;
|
|
953
954
|
}
|
|
954
955
|
/**
|
|
@@ -965,34 +966,34 @@ var InMemoryStore = class {
|
|
|
965
966
|
*/
|
|
966
967
|
async restore(driver) {
|
|
967
968
|
await sleep();
|
|
968
|
-
const
|
|
969
|
-
const
|
|
970
|
-
const
|
|
971
|
-
const
|
|
972
|
-
const
|
|
969
|
+
const prev_events = this._events;
|
|
970
|
+
const prev_streams = this._streams;
|
|
971
|
+
const prev_stream_versions = this._stream_versions;
|
|
972
|
+
const prev_max_event_id_by_stream = this._max_event_id_by_stream;
|
|
973
|
+
const prev_max_non_snap_event_id = this._max_non_snap_event_id;
|
|
973
974
|
this._events = [];
|
|
974
975
|
this._streams = /* @__PURE__ */ new Map();
|
|
975
|
-
this.
|
|
976
|
-
this.
|
|
977
|
-
this.
|
|
976
|
+
this._stream_versions = /* @__PURE__ */ new Map();
|
|
977
|
+
this._max_event_id_by_stream = /* @__PURE__ */ new Map();
|
|
978
|
+
this._max_non_snap_event_id = -1;
|
|
978
979
|
try {
|
|
979
980
|
await driver(async (event) => {
|
|
980
981
|
const id = this._events.length;
|
|
981
982
|
const committed = { ...event, id };
|
|
982
983
|
this._events.push(committed);
|
|
983
|
-
this.
|
|
984
|
+
this._stream_versions.set(event.stream, event.version);
|
|
984
985
|
if (event.name !== SNAP_EVENT) {
|
|
985
|
-
this.
|
|
986
|
-
this.
|
|
986
|
+
this._max_event_id_by_stream.set(event.stream, id);
|
|
987
|
+
this._max_non_snap_event_id = id;
|
|
987
988
|
}
|
|
988
989
|
return id;
|
|
989
990
|
});
|
|
990
991
|
} catch (err) {
|
|
991
|
-
this._events =
|
|
992
|
-
this._streams =
|
|
993
|
-
this.
|
|
994
|
-
this.
|
|
995
|
-
this.
|
|
992
|
+
this._events = prev_events;
|
|
993
|
+
this._streams = prev_streams;
|
|
994
|
+
this._stream_versions = prev_stream_versions;
|
|
995
|
+
this._max_event_id_by_stream = prev_max_event_id_by_stream;
|
|
996
|
+
this._max_non_snap_event_id = prev_max_non_snap_event_id;
|
|
996
997
|
throw err;
|
|
997
998
|
}
|
|
998
999
|
}
|
|
@@ -1071,16 +1072,16 @@ var FALLBACK_PACKAGE = {
|
|
|
1071
1072
|
version: "0.0.0-fallback",
|
|
1072
1073
|
description: "Synthetic fallback \u2014 package.json could not be loaded"
|
|
1073
1074
|
};
|
|
1074
|
-
var
|
|
1075
|
+
var get_package = () => {
|
|
1075
1076
|
try {
|
|
1076
1077
|
const raw = fs.readFileSync("package.json");
|
|
1077
1078
|
return JSON.parse(raw.toString());
|
|
1078
1079
|
} catch (err) {
|
|
1079
|
-
|
|
1080
|
+
pkg_load_error = err;
|
|
1080
1081
|
return FALLBACK_PACKAGE;
|
|
1081
1082
|
}
|
|
1082
1083
|
};
|
|
1083
|
-
var
|
|
1084
|
+
var pkg_load_error;
|
|
1084
1085
|
var BaseSchema = PackageSchema.extend({
|
|
1085
1086
|
env: z.enum(Environments),
|
|
1086
1087
|
logLevel: z.enum(LogLevels),
|
|
@@ -1092,7 +1093,7 @@ var env = NODE_ENV || "development";
|
|
|
1092
1093
|
var logLevel = LOG_LEVEL || (NODE_ENV === "test" ? "fatal" : NODE_ENV === "production" ? "info" : "trace");
|
|
1093
1094
|
var logSingleLine = (LOG_SINGLE_LINE || "true") === "true";
|
|
1094
1095
|
var sleepMs = parseInt(NODE_ENV === "test" ? "0" : SLEEP_MS ?? "100", 10);
|
|
1095
|
-
var pkg =
|
|
1096
|
+
var pkg = get_package();
|
|
1096
1097
|
var _validated;
|
|
1097
1098
|
var config = () => {
|
|
1098
1099
|
if (!_validated) {
|
|
@@ -1100,12 +1101,12 @@ var config = () => {
|
|
|
1100
1101
|
{ ...pkg, env, logLevel, logSingleLine, sleepMs },
|
|
1101
1102
|
BaseSchema
|
|
1102
1103
|
);
|
|
1103
|
-
if (
|
|
1104
|
-
const msg =
|
|
1104
|
+
if (pkg_load_error) {
|
|
1105
|
+
const msg = pkg_load_error instanceof Error ? pkg_load_error.message : typeof pkg_load_error === "string" ? pkg_load_error : "unknown error";
|
|
1105
1106
|
log().warn(
|
|
1106
1107
|
`[act] Could not read package.json (${msg}); using synthetic name="${FALLBACK_PACKAGE.name}" version="${FALLBACK_PACKAGE.version}".`
|
|
1107
1108
|
);
|
|
1108
|
-
|
|
1109
|
+
pkg_load_error = void 0;
|
|
1109
1110
|
}
|
|
1110
1111
|
}
|
|
1111
1112
|
return _validated;
|
|
@@ -1133,4 +1134,4 @@ export {
|
|
|
1133
1134
|
TOMBSTONE_EVENT,
|
|
1134
1135
|
DEFAULT_LANE
|
|
1135
1136
|
};
|
|
1136
|
-
//# sourceMappingURL=chunk-
|
|
1137
|
+
//# sourceMappingURL=chunk-3Z2HU726.js.map
|