@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
package/dist/test/index.cjs
CHANGED
|
@@ -3998,7 +3998,7 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
3998
3998
|
this._pretty = pretty;
|
|
3999
3999
|
this.level = level;
|
|
4000
4000
|
const threshold = LEVEL_VALUES[level] ?? 30;
|
|
4001
|
-
const write = pretty ? this.
|
|
4001
|
+
const write = pretty ? this._pretty_write.bind(this, bindings) : this._json_write.bind(this, bindings);
|
|
4002
4002
|
this.fatal = write.bind(this, "fatal", 60);
|
|
4003
4003
|
this.error = threshold <= 50 ? write.bind(this, "error", 50) : noop;
|
|
4004
4004
|
this.warn = threshold <= 40 ? write.bind(this, "warn", 40) : noop;
|
|
@@ -4017,24 +4017,24 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
4017
4017
|
bindings
|
|
4018
4018
|
});
|
|
4019
4019
|
}
|
|
4020
|
-
|
|
4020
|
+
_json_write(bindings, level, _num, obj_or_msg, msg) {
|
|
4021
4021
|
let obj;
|
|
4022
4022
|
let message;
|
|
4023
|
-
if (typeof
|
|
4024
|
-
message =
|
|
4023
|
+
if (typeof obj_or_msg === "string") {
|
|
4024
|
+
message = obj_or_msg;
|
|
4025
4025
|
obj = {};
|
|
4026
|
-
} else if (
|
|
4027
|
-
message = msg ??
|
|
4026
|
+
} else if (obj_or_msg instanceof Error) {
|
|
4027
|
+
message = msg ?? obj_or_msg.message;
|
|
4028
4028
|
obj = {
|
|
4029
|
-
error: { message:
|
|
4030
|
-
stack:
|
|
4029
|
+
error: { message: obj_or_msg.message, name: obj_or_msg.name },
|
|
4030
|
+
stack: obj_or_msg.stack
|
|
4031
4031
|
};
|
|
4032
|
-
} else if (
|
|
4032
|
+
} else if (obj_or_msg !== null && typeof obj_or_msg === "object") {
|
|
4033
4033
|
message = msg;
|
|
4034
|
-
obj = { ...
|
|
4034
|
+
obj = { ...obj_or_msg };
|
|
4035
4035
|
} else {
|
|
4036
4036
|
message = msg;
|
|
4037
|
-
obj = { value:
|
|
4037
|
+
obj = { value: obj_or_msg };
|
|
4038
4038
|
}
|
|
4039
4039
|
const entry = Object.assign({ level, time: Date.now() }, bindings, obj);
|
|
4040
4040
|
if (message) entry.msg = message;
|
|
@@ -4051,29 +4051,29 @@ var ConsoleLogger = class _ConsoleLogger {
|
|
|
4051
4051
|
}
|
|
4052
4052
|
process.stdout.write(line + "\n");
|
|
4053
4053
|
}
|
|
4054
|
-
|
|
4054
|
+
_pretty_write(bindings, level, _num, obj_or_msg, msg) {
|
|
4055
4055
|
const color = LEVEL_COLORS[level];
|
|
4056
4056
|
const tag = `${color}${level.toUpperCase().padEnd(5)}${RESET}`;
|
|
4057
4057
|
const ts = (/* @__PURE__ */ new Date()).toISOString().slice(11, 23);
|
|
4058
4058
|
let message;
|
|
4059
4059
|
let data;
|
|
4060
|
-
if (typeof
|
|
4061
|
-
message =
|
|
4062
|
-
} else if (
|
|
4063
|
-
message = msg ??
|
|
4064
|
-
data =
|
|
4060
|
+
if (typeof obj_or_msg === "string") {
|
|
4061
|
+
message = obj_or_msg;
|
|
4062
|
+
} else if (obj_or_msg instanceof Error) {
|
|
4063
|
+
message = msg ?? obj_or_msg.message;
|
|
4064
|
+
data = obj_or_msg.stack;
|
|
4065
4065
|
} else {
|
|
4066
4066
|
message = msg ?? "";
|
|
4067
|
-
if (
|
|
4067
|
+
if (obj_or_msg !== void 0 && obj_or_msg !== null) {
|
|
4068
4068
|
try {
|
|
4069
|
-
data = JSON.stringify(
|
|
4069
|
+
data = JSON.stringify(obj_or_msg);
|
|
4070
4070
|
} catch {
|
|
4071
4071
|
data = "[unserializable]";
|
|
4072
4072
|
}
|
|
4073
4073
|
}
|
|
4074
4074
|
}
|
|
4075
|
-
const
|
|
4076
|
-
const parts = [ts, tag, message, data,
|
|
4075
|
+
const bind_str = bindings && Object.keys(bindings).length ? ` ${JSON.stringify(bindings)}` : "";
|
|
4076
|
+
const parts = [ts, tag, message, data, bind_str].filter(Boolean);
|
|
4077
4077
|
process.stdout.write(parts.join(" ") + "\n");
|
|
4078
4078
|
}
|
|
4079
4079
|
};
|
|
@@ -4229,16 +4229,16 @@ var FALLBACK_PACKAGE = {
|
|
|
4229
4229
|
version: "0.0.0-fallback",
|
|
4230
4230
|
description: "Synthetic fallback \u2014 package.json could not be loaded"
|
|
4231
4231
|
};
|
|
4232
|
-
var
|
|
4232
|
+
var get_package = () => {
|
|
4233
4233
|
try {
|
|
4234
4234
|
const raw = fs.readFileSync("package.json");
|
|
4235
4235
|
return JSON.parse(raw.toString());
|
|
4236
4236
|
} catch (err) {
|
|
4237
|
-
|
|
4237
|
+
pkg_load_error = err;
|
|
4238
4238
|
return FALLBACK_PACKAGE;
|
|
4239
4239
|
}
|
|
4240
4240
|
};
|
|
4241
|
-
var
|
|
4241
|
+
var pkg_load_error;
|
|
4242
4242
|
var BaseSchema = PackageSchema.extend({
|
|
4243
4243
|
env: import_zod4.z.enum(Environments),
|
|
4244
4244
|
logLevel: import_zod4.z.enum(LogLevels),
|
|
@@ -4250,7 +4250,7 @@ var env = NODE_ENV || "development";
|
|
|
4250
4250
|
var logLevel = LOG_LEVEL || (NODE_ENV === "test" ? "fatal" : NODE_ENV === "production" ? "info" : "trace");
|
|
4251
4251
|
var logSingleLine = (LOG_SINGLE_LINE || "true") === "true";
|
|
4252
4252
|
var sleepMs = parseInt(NODE_ENV === "test" ? "0" : SLEEP_MS ?? "100", 10);
|
|
4253
|
-
var pkg =
|
|
4253
|
+
var pkg = get_package();
|
|
4254
4254
|
var _validated;
|
|
4255
4255
|
var config = () => {
|
|
4256
4256
|
if (!_validated) {
|
|
@@ -4258,12 +4258,12 @@ var config = () => {
|
|
|
4258
4258
|
{ ...pkg, env, logLevel, logSingleLine, sleepMs },
|
|
4259
4259
|
BaseSchema
|
|
4260
4260
|
);
|
|
4261
|
-
if (
|
|
4262
|
-
const msg =
|
|
4261
|
+
if (pkg_load_error) {
|
|
4262
|
+
const msg = pkg_load_error instanceof Error ? pkg_load_error.message : typeof pkg_load_error === "string" ? pkg_load_error : "unknown error";
|
|
4263
4263
|
log().warn(
|
|
4264
4264
|
`[act] Could not read package.json (${msg}); using synthetic name="${FALLBACK_PACKAGE.name}" version="${FALLBACK_PACKAGE.version}".`
|
|
4265
4265
|
);
|
|
4266
|
-
|
|
4266
|
+
pkg_load_error = void 0;
|
|
4267
4267
|
}
|
|
4268
4268
|
}
|
|
4269
4269
|
return _validated;
|
|
@@ -4331,14 +4331,14 @@ var InMemoryStream = class {
|
|
|
4331
4331
|
* Bump the priority via {@link subscribe}: keeps the maximum across
|
|
4332
4332
|
* reactions so the highest-priority registrant wins.
|
|
4333
4333
|
*/
|
|
4334
|
-
|
|
4334
|
+
bump_priority(priority) {
|
|
4335
4335
|
if (priority > this._priority) this._priority = priority;
|
|
4336
4336
|
}
|
|
4337
4337
|
/**
|
|
4338
4338
|
* Set the priority outright via {@link prioritize}: operator
|
|
4339
4339
|
* runtime override that ignores the build-time `max()` invariant.
|
|
4340
4340
|
*/
|
|
4341
|
-
|
|
4341
|
+
set_priority(priority) {
|
|
4342
4342
|
this._priority = priority;
|
|
4343
4343
|
}
|
|
4344
4344
|
get is_available() {
|
|
@@ -4460,28 +4460,28 @@ var InMemoryStore = class {
|
|
|
4460
4460
|
// stored stream positions and other metadata
|
|
4461
4461
|
_streams = /* @__PURE__ */ new Map();
|
|
4462
4462
|
// last committed version per stream — O(1) replacement for filter-on-commit
|
|
4463
|
-
|
|
4463
|
+
_stream_versions = /* @__PURE__ */ new Map();
|
|
4464
4464
|
// max non-snapshot event id per stream — drives the source-pattern probe in claim()
|
|
4465
4465
|
// without scanning the full event log.
|
|
4466
|
-
|
|
4466
|
+
_max_event_id_by_stream = /* @__PURE__ */ new Map();
|
|
4467
4467
|
// global max non-snapshot event id — fast pre-check for source-less streams in claim()
|
|
4468
|
-
|
|
4468
|
+
_max_non_snap_event_id = -1;
|
|
4469
4469
|
// stream → (event_id → cloned sensitive payload). Two-level so `forget_pii`
|
|
4470
4470
|
// is O(1) — drop the inner Map for the stream and the wipe is done — mirroring
|
|
4471
4471
|
// the `DELETE WHERE stream = ?` scope that durable adapters get from their
|
|
4472
4472
|
// stream index. Entries exist only for events committed with a non-null
|
|
4473
4473
|
// `pii` field; absence means "no PII" (returned as `null` on load).
|
|
4474
4474
|
_pii = /* @__PURE__ */ new Map();
|
|
4475
|
-
|
|
4475
|
+
_reset_indexes() {
|
|
4476
4476
|
this._events.length = 0;
|
|
4477
|
-
this.
|
|
4478
|
-
this.
|
|
4479
|
-
this.
|
|
4477
|
+
this._stream_versions.clear();
|
|
4478
|
+
this._max_event_id_by_stream.clear();
|
|
4479
|
+
this._max_non_snap_event_id = -1;
|
|
4480
4480
|
this._pii.clear();
|
|
4481
4481
|
}
|
|
4482
4482
|
// Attach the isolated PII payload (or null) to an event before handing it to
|
|
4483
4483
|
// a caller. Allocation-free for events without PII — by far the common case.
|
|
4484
|
-
|
|
4484
|
+
_with_pii(e) {
|
|
4485
4485
|
const pii = this._pii.get(e.stream)?.get(e.id);
|
|
4486
4486
|
return pii ? { ...e, pii } : e;
|
|
4487
4487
|
}
|
|
@@ -4491,7 +4491,7 @@ var InMemoryStore = class {
|
|
|
4491
4491
|
*/
|
|
4492
4492
|
async dispose() {
|
|
4493
4493
|
await sleep();
|
|
4494
|
-
this.
|
|
4494
|
+
this._reset_indexes();
|
|
4495
4495
|
}
|
|
4496
4496
|
/**
|
|
4497
4497
|
* Seed the store with initial data (no-op for in-memory).
|
|
@@ -4506,7 +4506,7 @@ var InMemoryStore = class {
|
|
|
4506
4506
|
*/
|
|
4507
4507
|
async drop() {
|
|
4508
4508
|
await sleep();
|
|
4509
|
-
this.
|
|
4509
|
+
this._reset_indexes();
|
|
4510
4510
|
this._streams = /* @__PURE__ */ new Map();
|
|
4511
4511
|
}
|
|
4512
4512
|
in_query(query, e) {
|
|
@@ -4540,7 +4540,7 @@ var InMemoryStore = class {
|
|
|
4540
4540
|
if (query.after && e.id <= query.after) break;
|
|
4541
4541
|
if (query.created_after && e.created <= query.created_after) break;
|
|
4542
4542
|
await Promise.resolve(
|
|
4543
|
-
callback(this.
|
|
4543
|
+
callback(this._with_pii(e))
|
|
4544
4544
|
);
|
|
4545
4545
|
count++;
|
|
4546
4546
|
if (query?.limit && count >= query.limit) break;
|
|
@@ -4554,7 +4554,7 @@ var InMemoryStore = class {
|
|
|
4554
4554
|
if (query?.before && e.id >= query.before) break;
|
|
4555
4555
|
if (query?.created_before && e.created >= query.created_before) break;
|
|
4556
4556
|
await Promise.resolve(
|
|
4557
|
-
callback(this.
|
|
4557
|
+
callback(this._with_pii(e))
|
|
4558
4558
|
);
|
|
4559
4559
|
count++;
|
|
4560
4560
|
if (query?.limit && count >= query.limit) break;
|
|
@@ -4573,17 +4573,17 @@ var InMemoryStore = class {
|
|
|
4573
4573
|
*/
|
|
4574
4574
|
async commit(stream, msgs, meta, expectedVersion) {
|
|
4575
4575
|
await sleep();
|
|
4576
|
-
const
|
|
4577
|
-
if (typeof expectedVersion === "number" &&
|
|
4576
|
+
const current_version = this._stream_versions.get(stream) ?? -1;
|
|
4577
|
+
if (typeof expectedVersion === "number" && current_version !== expectedVersion) {
|
|
4578
4578
|
throw new ConcurrencyError(
|
|
4579
4579
|
stream,
|
|
4580
|
-
|
|
4580
|
+
current_version,
|
|
4581
4581
|
msgs,
|
|
4582
4582
|
expectedVersion
|
|
4583
4583
|
);
|
|
4584
4584
|
}
|
|
4585
|
-
let version =
|
|
4586
|
-
let
|
|
4585
|
+
let version = current_version + 1;
|
|
4586
|
+
let last_non_snap_id = -1;
|
|
4587
4587
|
const committed = msgs.map(({ name, data, pii }) => {
|
|
4588
4588
|
const c = {
|
|
4589
4589
|
id: this._events.length,
|
|
@@ -4596,21 +4596,21 @@ var InMemoryStore = class {
|
|
|
4596
4596
|
};
|
|
4597
4597
|
this._events.push(c);
|
|
4598
4598
|
if (pii != null) {
|
|
4599
|
-
let
|
|
4600
|
-
if (!
|
|
4601
|
-
|
|
4602
|
-
this._pii.set(stream,
|
|
4599
|
+
let per_stream = this._pii.get(stream);
|
|
4600
|
+
if (!per_stream) {
|
|
4601
|
+
per_stream = /* @__PURE__ */ new Map();
|
|
4602
|
+
this._pii.set(stream, per_stream);
|
|
4603
4603
|
}
|
|
4604
|
-
|
|
4604
|
+
per_stream.set(c.id, structuredClone(pii));
|
|
4605
4605
|
}
|
|
4606
|
-
if (name !== SNAP_EVENT)
|
|
4606
|
+
if (name !== SNAP_EVENT) last_non_snap_id = c.id;
|
|
4607
4607
|
version++;
|
|
4608
|
-
return this.
|
|
4608
|
+
return this._with_pii(c);
|
|
4609
4609
|
});
|
|
4610
|
-
this.
|
|
4611
|
-
if (
|
|
4612
|
-
this.
|
|
4613
|
-
this.
|
|
4610
|
+
this._stream_versions.set(stream, version - 1);
|
|
4611
|
+
if (last_non_snap_id >= 0) {
|
|
4612
|
+
this._max_event_id_by_stream.set(stream, last_non_snap_id);
|
|
4613
|
+
this._max_non_snap_event_id = last_non_snap_id;
|
|
4614
4614
|
}
|
|
4615
4615
|
return committed;
|
|
4616
4616
|
}
|
|
@@ -4625,26 +4625,26 @@ var InMemoryStore = class {
|
|
|
4625
4625
|
*/
|
|
4626
4626
|
async claim(lagging, leading, by, millis, lane) {
|
|
4627
4627
|
await sleep();
|
|
4628
|
-
const
|
|
4629
|
-
const
|
|
4630
|
-
let re =
|
|
4628
|
+
const source_regex = /* @__PURE__ */ new Map();
|
|
4629
|
+
const get_regex = (source) => {
|
|
4630
|
+
let re = source_regex.get(source);
|
|
4631
4631
|
if (!re) {
|
|
4632
4632
|
re = new RegExp(source);
|
|
4633
|
-
|
|
4633
|
+
source_regex.set(source, re);
|
|
4634
4634
|
}
|
|
4635
4635
|
return re;
|
|
4636
4636
|
};
|
|
4637
|
-
const
|
|
4637
|
+
const has_work = (s) => {
|
|
4638
4638
|
if (s.at < 0) return true;
|
|
4639
|
-
if (!s.source) return s.at < this.
|
|
4640
|
-
const re =
|
|
4641
|
-
for (const [
|
|
4642
|
-
if (maxId > s.at && re.test(
|
|
4639
|
+
if (!s.source) return s.at < this._max_non_snap_event_id;
|
|
4640
|
+
const re = get_regex(s.source);
|
|
4641
|
+
for (const [stream_name, maxId] of this._max_event_id_by_stream) {
|
|
4642
|
+
if (maxId > s.at && re.test(stream_name)) return true;
|
|
4643
4643
|
}
|
|
4644
4644
|
return false;
|
|
4645
4645
|
};
|
|
4646
4646
|
const available = [...this._streams.values()].filter(
|
|
4647
|
-
(s) => s.is_available &&
|
|
4647
|
+
(s) => s.is_available && has_work(s) && (lane === void 0 || s.lane === lane)
|
|
4648
4648
|
);
|
|
4649
4649
|
const lag = available.sort((a, b2) => b2.priority - a.priority || a.at - b2.at).slice(0, lagging).map((s) => ({
|
|
4650
4650
|
stream: s.stream,
|
|
@@ -4688,7 +4688,7 @@ var InMemoryStore = class {
|
|
|
4688
4688
|
} of streams) {
|
|
4689
4689
|
const existing = this._streams.get(stream);
|
|
4690
4690
|
if (existing) {
|
|
4691
|
-
existing.
|
|
4691
|
+
existing.bump_priority(priority);
|
|
4692
4692
|
existing.lane = lane;
|
|
4693
4693
|
} else {
|
|
4694
4694
|
this._streams.set(
|
|
@@ -4726,17 +4726,17 @@ var InMemoryStore = class {
|
|
|
4726
4726
|
* cached in the closure so callers can apply it across the streams
|
|
4727
4727
|
* map without re-compiling per iteration.
|
|
4728
4728
|
*/
|
|
4729
|
-
|
|
4730
|
-
const
|
|
4731
|
-
const
|
|
4729
|
+
_filter_predicate(filter) {
|
|
4730
|
+
const stream_re = filter.stream && !filter.stream_exact ? new RegExp(filter.stream) : void 0;
|
|
4731
|
+
const source_re = filter.source && !filter.source_exact ? new RegExp(filter.source) : void 0;
|
|
4732
4732
|
return (s) => {
|
|
4733
4733
|
if (filter.stream !== void 0) {
|
|
4734
|
-
if (filter.stream_exact ? s.stream !== filter.stream : !
|
|
4734
|
+
if (filter.stream_exact ? s.stream !== filter.stream : !stream_re.test(s.stream))
|
|
4735
4735
|
return false;
|
|
4736
4736
|
}
|
|
4737
4737
|
if (filter.source !== void 0) {
|
|
4738
4738
|
if (s.source === void 0) return false;
|
|
4739
|
-
if (filter.source_exact ? s.source !== filter.source : !
|
|
4739
|
+
if (filter.source_exact ? s.source !== filter.source : !source_re.test(s.source))
|
|
4740
4740
|
return false;
|
|
4741
4741
|
}
|
|
4742
4742
|
if (filter.blocked !== void 0 && s.blocked !== filter.blocked)
|
|
@@ -4765,7 +4765,7 @@ var InMemoryStore = class {
|
|
|
4765
4765
|
}
|
|
4766
4766
|
}
|
|
4767
4767
|
} else {
|
|
4768
|
-
const matches = this.
|
|
4768
|
+
const matches = this._filter_predicate(input);
|
|
4769
4769
|
for (const s of this._streams.values()) {
|
|
4770
4770
|
if (matches(s)) {
|
|
4771
4771
|
s.reset();
|
|
@@ -4810,7 +4810,7 @@ var InMemoryStore = class {
|
|
|
4810
4810
|
if (s?.unblock()) count++;
|
|
4811
4811
|
}
|
|
4812
4812
|
} else {
|
|
4813
|
-
const matches = this.
|
|
4813
|
+
const matches = this._filter_predicate({ ...input, blocked: true });
|
|
4814
4814
|
for (const s of this._streams.values()) {
|
|
4815
4815
|
if (matches(s) && s.unblock()) count++;
|
|
4816
4816
|
}
|
|
@@ -4828,12 +4828,12 @@ var InMemoryStore = class {
|
|
|
4828
4828
|
*/
|
|
4829
4829
|
async prioritize(filter, priority) {
|
|
4830
4830
|
await sleep();
|
|
4831
|
-
const matches = this.
|
|
4831
|
+
const matches = this._filter_predicate(filter);
|
|
4832
4832
|
let count = 0;
|
|
4833
4833
|
for (const s of this._streams.values()) {
|
|
4834
4834
|
if (!matches(s)) continue;
|
|
4835
4835
|
if (s.priority !== priority) {
|
|
4836
|
-
s.
|
|
4836
|
+
s.set_priority(priority);
|
|
4837
4837
|
count++;
|
|
4838
4838
|
}
|
|
4839
4839
|
}
|
|
@@ -4849,8 +4849,8 @@ var InMemoryStore = class {
|
|
|
4849
4849
|
const limit = query?.limit ?? 100;
|
|
4850
4850
|
const after = query?.after;
|
|
4851
4851
|
const blocked = query?.blocked;
|
|
4852
|
-
const
|
|
4853
|
-
const
|
|
4852
|
+
const stream_re = query?.stream && !query.stream_exact ? new RegExp(query.stream) : void 0;
|
|
4853
|
+
const source_re = query?.source && !query.source_exact ? new RegExp(query.source) : void 0;
|
|
4854
4854
|
const sorted = [...this._streams.values()].sort(
|
|
4855
4855
|
(a, b2) => a.stream.localeCompare(b2.stream)
|
|
4856
4856
|
);
|
|
@@ -4858,12 +4858,12 @@ var InMemoryStore = class {
|
|
|
4858
4858
|
for (const s of sorted) {
|
|
4859
4859
|
if (after !== void 0 && s.stream <= after) continue;
|
|
4860
4860
|
if (query?.stream !== void 0) {
|
|
4861
|
-
if (query.stream_exact ? s.stream !== query.stream : !
|
|
4861
|
+
if (query.stream_exact ? s.stream !== query.stream : !stream_re.test(s.stream))
|
|
4862
4862
|
continue;
|
|
4863
4863
|
}
|
|
4864
4864
|
if (query?.source !== void 0) {
|
|
4865
4865
|
if (s.source === void 0) continue;
|
|
4866
|
-
if (query.source_exact ? s.source !== query.source : !
|
|
4866
|
+
if (query.source_exact ? s.source !== query.source : !source_re.test(s.source))
|
|
4867
4867
|
continue;
|
|
4868
4868
|
}
|
|
4869
4869
|
if (blocked !== void 0 && s.blocked !== blocked) continue;
|
|
@@ -4904,44 +4904,44 @@ var InMemoryStore = class {
|
|
|
4904
4904
|
async query_stats(input, options) {
|
|
4905
4905
|
await sleep();
|
|
4906
4906
|
const exclude = new Set(options?.exclude ?? []);
|
|
4907
|
-
const
|
|
4908
|
-
const
|
|
4909
|
-
const
|
|
4907
|
+
const want_tail = options?.tail ?? false;
|
|
4908
|
+
const want_count = options?.count ?? false;
|
|
4909
|
+
const want_names = options?.names ?? false;
|
|
4910
4910
|
const before = options?.before;
|
|
4911
|
-
const
|
|
4911
|
+
const array_targets = Array.isArray(input) ? new Set(input) : null;
|
|
4912
4912
|
const filter = Array.isArray(input) ? null : input;
|
|
4913
|
-
const
|
|
4914
|
-
const
|
|
4915
|
-
const
|
|
4916
|
-
const cached =
|
|
4913
|
+
const stream_re = filter?.stream && !filter.stream_exact ? new RegExp(filter.stream) : void 0;
|
|
4914
|
+
const scope_cache = /* @__PURE__ */ new Map();
|
|
4915
|
+
const in_scope = (stream) => {
|
|
4916
|
+
const cached = scope_cache.get(stream);
|
|
4917
4917
|
if (cached !== void 0) return cached;
|
|
4918
4918
|
let ok = true;
|
|
4919
|
-
if (
|
|
4920
|
-
ok =
|
|
4919
|
+
if (array_targets) {
|
|
4920
|
+
ok = array_targets.has(stream);
|
|
4921
4921
|
} else if (filter?.stream !== void 0) {
|
|
4922
4922
|
ok = filter.stream_exact ? stream === filter.stream : (
|
|
4923
|
-
// biome-ignore lint/style/noNonNullAssertion:
|
|
4924
|
-
|
|
4923
|
+
// biome-ignore lint/style/noNonNullAssertion: stream_re set when stream is regex
|
|
4924
|
+
stream_re.test(stream)
|
|
4925
4925
|
);
|
|
4926
4926
|
}
|
|
4927
|
-
|
|
4927
|
+
scope_cache.set(stream, ok);
|
|
4928
4928
|
return ok;
|
|
4929
4929
|
};
|
|
4930
4930
|
const acc = /* @__PURE__ */ new Map();
|
|
4931
4931
|
for (const e of this._events) {
|
|
4932
4932
|
if (before !== void 0 && e.id >= before) continue;
|
|
4933
|
-
if (!
|
|
4933
|
+
if (!in_scope(e.stream)) continue;
|
|
4934
4934
|
if (exclude.has(e.name)) continue;
|
|
4935
4935
|
let a = acc.get(e.stream);
|
|
4936
4936
|
if (!a) {
|
|
4937
4937
|
a = { head: e, count: 0 };
|
|
4938
|
-
if (
|
|
4939
|
-
if (
|
|
4938
|
+
if (want_tail) a.tail = e;
|
|
4939
|
+
if (want_names) a.names = {};
|
|
4940
4940
|
acc.set(e.stream, a);
|
|
4941
4941
|
}
|
|
4942
4942
|
a.head = e;
|
|
4943
4943
|
a.count++;
|
|
4944
|
-
if (
|
|
4944
|
+
if (want_names) {
|
|
4945
4945
|
const n = String(e.name);
|
|
4946
4946
|
a.names[n] = (a.names[n] ?? 0) + 1;
|
|
4947
4947
|
}
|
|
@@ -4949,9 +4949,9 @@ var InMemoryStore = class {
|
|
|
4949
4949
|
const out = /* @__PURE__ */ new Map();
|
|
4950
4950
|
for (const [stream, a] of acc) {
|
|
4951
4951
|
const stats = { head: a.head };
|
|
4952
|
-
if (
|
|
4953
|
-
if (
|
|
4954
|
-
if (
|
|
4952
|
+
if (want_tail) stats.tail = a.tail;
|
|
4953
|
+
if (want_count) stats.count = a.count;
|
|
4954
|
+
if (want_names) stats.names = a.names;
|
|
4955
4955
|
out.set(stream, stats);
|
|
4956
4956
|
}
|
|
4957
4957
|
return out;
|
|
@@ -4963,18 +4963,18 @@ var InMemoryStore = class {
|
|
|
4963
4963
|
*/
|
|
4964
4964
|
async truncate(targets) {
|
|
4965
4965
|
await sleep();
|
|
4966
|
-
const
|
|
4967
|
-
const
|
|
4966
|
+
const deleted_counts = /* @__PURE__ */ new Map();
|
|
4967
|
+
const stream_set = new Set(targets.map((t) => t.stream));
|
|
4968
4968
|
for (const e of this._events) {
|
|
4969
|
-
if (
|
|
4970
|
-
|
|
4969
|
+
if (stream_set.has(e.stream)) {
|
|
4970
|
+
deleted_counts.set(e.stream, (deleted_counts.get(e.stream) ?? 0) + 1);
|
|
4971
4971
|
}
|
|
4972
4972
|
}
|
|
4973
|
-
this._events = this._events.filter((e) => !
|
|
4974
|
-
for (const stream of
|
|
4973
|
+
this._events = this._events.filter((e) => !stream_set.has(e.stream));
|
|
4974
|
+
for (const stream of stream_set) {
|
|
4975
4975
|
this._streams.delete(stream);
|
|
4976
|
-
this.
|
|
4977
|
-
this.
|
|
4976
|
+
this._stream_versions.delete(stream);
|
|
4977
|
+
this._max_event_id_by_stream.delete(stream);
|
|
4978
4978
|
}
|
|
4979
4979
|
const result = /* @__PURE__ */ new Map();
|
|
4980
4980
|
for (const { stream, snapshot, meta } of targets) {
|
|
@@ -4988,18 +4988,19 @@ var InMemoryStore = class {
|
|
|
4988
4988
|
meta: meta ?? { correlation: "", causation: {} }
|
|
4989
4989
|
};
|
|
4990
4990
|
this._events.push(event);
|
|
4991
|
-
this.
|
|
4991
|
+
this._stream_versions.set(stream, 0);
|
|
4992
4992
|
if (event.name !== SNAP_EVENT) {
|
|
4993
|
-
this.
|
|
4993
|
+
this._max_event_id_by_stream.set(stream, event.id);
|
|
4994
4994
|
}
|
|
4995
4995
|
result.set(stream, {
|
|
4996
|
-
deleted:
|
|
4996
|
+
deleted: deleted_counts.get(stream) ?? 0,
|
|
4997
4997
|
committed: event
|
|
4998
4998
|
});
|
|
4999
4999
|
}
|
|
5000
5000
|
let max = -1;
|
|
5001
|
-
for (const id of this.
|
|
5002
|
-
|
|
5001
|
+
for (const id of this._max_event_id_by_stream.values())
|
|
5002
|
+
if (id > max) max = id;
|
|
5003
|
+
this._max_non_snap_event_id = max;
|
|
5003
5004
|
return result;
|
|
5004
5005
|
}
|
|
5005
5006
|
/**
|
|
@@ -5016,34 +5017,34 @@ var InMemoryStore = class {
|
|
|
5016
5017
|
*/
|
|
5017
5018
|
async restore(driver) {
|
|
5018
5019
|
await sleep();
|
|
5019
|
-
const
|
|
5020
|
-
const
|
|
5021
|
-
const
|
|
5022
|
-
const
|
|
5023
|
-
const
|
|
5020
|
+
const prev_events = this._events;
|
|
5021
|
+
const prev_streams = this._streams;
|
|
5022
|
+
const prev_stream_versions = this._stream_versions;
|
|
5023
|
+
const prev_max_event_id_by_stream = this._max_event_id_by_stream;
|
|
5024
|
+
const prev_max_non_snap_event_id = this._max_non_snap_event_id;
|
|
5024
5025
|
this._events = [];
|
|
5025
5026
|
this._streams = /* @__PURE__ */ new Map();
|
|
5026
|
-
this.
|
|
5027
|
-
this.
|
|
5028
|
-
this.
|
|
5027
|
+
this._stream_versions = /* @__PURE__ */ new Map();
|
|
5028
|
+
this._max_event_id_by_stream = /* @__PURE__ */ new Map();
|
|
5029
|
+
this._max_non_snap_event_id = -1;
|
|
5029
5030
|
try {
|
|
5030
5031
|
await driver(async (event) => {
|
|
5031
5032
|
const id = this._events.length;
|
|
5032
5033
|
const committed = { ...event, id };
|
|
5033
5034
|
this._events.push(committed);
|
|
5034
|
-
this.
|
|
5035
|
+
this._stream_versions.set(event.stream, event.version);
|
|
5035
5036
|
if (event.name !== SNAP_EVENT) {
|
|
5036
|
-
this.
|
|
5037
|
-
this.
|
|
5037
|
+
this._max_event_id_by_stream.set(event.stream, id);
|
|
5038
|
+
this._max_non_snap_event_id = id;
|
|
5038
5039
|
}
|
|
5039
5040
|
return id;
|
|
5040
5041
|
});
|
|
5041
5042
|
} catch (err) {
|
|
5042
|
-
this._events =
|
|
5043
|
-
this._streams =
|
|
5044
|
-
this.
|
|
5045
|
-
this.
|
|
5046
|
-
this.
|
|
5043
|
+
this._events = prev_events;
|
|
5044
|
+
this._streams = prev_streams;
|
|
5045
|
+
this._stream_versions = prev_stream_versions;
|
|
5046
|
+
this._max_event_id_by_stream = prev_max_event_id_by_stream;
|
|
5047
|
+
this._max_non_snap_event_id = prev_max_non_snap_event_id;
|
|
5047
5048
|
throw err;
|
|
5048
5049
|
}
|
|
5049
5050
|
}
|