@rotorsoft/act 1.33.16 → 1.33.18
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 +9 -2
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/in-memory-store.d.ts +1 -2
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts +11 -4
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/drain-cycle.d.ts +4 -1
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
- package/dist/@types/internal/settle.d.ts.map +1 -1
- package/dist/@types/types/reaction.d.ts +4 -2
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/{chunk-E5H3NRCT.js → chunk-3OTABSIB.js} +29 -38
- package/dist/chunk-3OTABSIB.js.map +1 -0
- package/dist/{chunk-PMS6BMIU.cjs → chunk-N7K4FQEM.cjs} +1 -1
- package/dist/{chunk-PMS6BMIU.cjs.map → chunk-N7K4FQEM.cjs.map} +1 -1
- package/dist/{chunk-EN2KFJ7W.cjs → chunk-OYR5RIFE.cjs} +45 -54
- package/dist/chunk-OYR5RIFE.cjs.map +1 -0
- package/dist/{chunk-CAL4XEVN.js → chunk-SD7SW47Z.js} +1 -1
- package/dist/{chunk-CAL4XEVN.js.map → chunk-SD7SW47Z.js.map} +1 -1
- package/dist/index.cjs +212 -183
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +52 -23
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +4 -4
- package/dist/test/index.js +2 -2
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-E5H3NRCT.js.map +0 -1
- package/dist/chunk-EN2KFJ7W.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
var
|
|
43
|
+
var _chunkOYR5RIFEcjs = require('./chunk-OYR5RIFE.cjs');
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
@@ -70,24 +70,24 @@ var _chunkEN2KFJ7Wcjs = require('./chunk-EN2KFJ7W.cjs');
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
var
|
|
73
|
+
var _chunkN7K4FQEMcjs = require('./chunk-N7K4FQEM.cjs');
|
|
74
74
|
|
|
75
75
|
// src/signals.ts
|
|
76
76
|
process.once("SIGINT", async (arg) => {
|
|
77
|
-
|
|
78
|
-
await
|
|
77
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).info(arg, "SIGINT");
|
|
78
|
+
await _chunkOYR5RIFEcjs.disposeAndExit.call(void 0, "EXIT");
|
|
79
79
|
});
|
|
80
80
|
process.once("SIGTERM", async (arg) => {
|
|
81
|
-
|
|
82
|
-
await
|
|
81
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).info(arg, "SIGTERM");
|
|
82
|
+
await _chunkOYR5RIFEcjs.disposeAndExit.call(void 0, "EXIT");
|
|
83
83
|
});
|
|
84
84
|
process.once("uncaughtException", async (arg) => {
|
|
85
|
-
|
|
86
|
-
await
|
|
85
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
|
|
86
|
+
await _chunkOYR5RIFEcjs.disposeAndExit.call(void 0, "ERROR");
|
|
87
87
|
});
|
|
88
88
|
process.once("unhandledRejection", async (arg) => {
|
|
89
|
-
|
|
90
|
-
await
|
|
89
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
|
|
90
|
+
await _chunkOYR5RIFEcjs.disposeAndExit.call(void 0, "ERROR");
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
// src/act.ts
|
|
@@ -195,7 +195,7 @@ async function* audit(deps, categories, options = {}) {
|
|
|
195
195
|
if (need_stats) {
|
|
196
196
|
const stats = await deps.store().query_stats(
|
|
197
197
|
{},
|
|
198
|
-
{ count: true, names: true, exclude: [
|
|
198
|
+
{ count: true, names: true, exclude: [_chunkN7K4FQEMcjs.SNAP_EVENT] }
|
|
199
199
|
);
|
|
200
200
|
for (const [stream, s] of stats) {
|
|
201
201
|
for (const p of passes) _optionalChain([p, 'access', _4 => _4.on_stat, 'optionalCall', _5 => _5(stream, s)]);
|
|
@@ -277,7 +277,7 @@ var make_schema_pass = (deps) => {
|
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
279
|
const schema = state2.events[name];
|
|
280
|
-
const sensitive2 =
|
|
280
|
+
const sensitive2 = _chunkN7K4FQEMcjs.pii_fields.call(void 0, schema);
|
|
281
281
|
let parse_schema = schema;
|
|
282
282
|
if (sensitive2.length > 0) {
|
|
283
283
|
const omitter = schema.omit;
|
|
@@ -411,7 +411,7 @@ var make_restart_candidate_pass = (deps, options) => {
|
|
|
411
411
|
{
|
|
412
412
|
stream,
|
|
413
413
|
stream_exact: true,
|
|
414
|
-
names: [
|
|
414
|
+
names: [_chunkN7K4FQEMcjs.SNAP_EVENT],
|
|
415
415
|
with_snaps: true
|
|
416
416
|
}
|
|
417
417
|
);
|
|
@@ -840,7 +840,7 @@ async function run_close_cycle(targets, deps) {
|
|
|
840
840
|
deps,
|
|
841
841
|
() => run_full_closes(full, target_map, deps, skipped)
|
|
842
842
|
);
|
|
843
|
-
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name ===
|
|
843
|
+
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkN7K4FQEMcjs.TOMBSTONE_EVENT).map(([stream]) => stream);
|
|
844
844
|
if (retired.length) _optionalChain([deps, 'access', _42 => _42.forget_subscribed, 'optionalCall', _43 => _43(retired)]);
|
|
845
845
|
for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
|
|
846
846
|
return { truncated, skipped };
|
|
@@ -922,7 +922,7 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
922
922
|
if (!await windowed_prune_pending(t.stream, t.before, max_id))
|
|
923
923
|
return void 0;
|
|
924
924
|
if (t.archive) await t.archive();
|
|
925
|
-
const result = await
|
|
925
|
+
const result = await _chunkOYR5RIFEcjs.store.call(void 0, ).truncate([
|
|
926
926
|
{ stream: t.stream, before: t.before, max_id }
|
|
927
927
|
]);
|
|
928
928
|
return result.get(t.stream);
|
|
@@ -935,10 +935,10 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
935
935
|
async function windowed_prune_pending(stream, before, max_id) {
|
|
936
936
|
let boundary_id;
|
|
937
937
|
let min_id;
|
|
938
|
-
await
|
|
938
|
+
await _chunkOYR5RIFEcjs.store.call(void 0, ).query(
|
|
939
939
|
(event) => {
|
|
940
940
|
if (min_id === void 0 || event.id < min_id) min_id = event.id;
|
|
941
|
-
if (event.name ===
|
|
941
|
+
if (event.name === _chunkN7K4FQEMcjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
|
|
942
942
|
boundary_id = event.id;
|
|
943
943
|
},
|
|
944
944
|
{ stream, stream_exact: true, with_snaps: true, after: -1 }
|
|
@@ -949,7 +949,7 @@ async function probe_min_watermarks(streams, page_size, checkpoint) {
|
|
|
949
949
|
const min_at = /* @__PURE__ */ new Map();
|
|
950
950
|
const matches = source_matcher();
|
|
951
951
|
await walk_streams(
|
|
952
|
-
|
|
952
|
+
_chunkOYR5RIFEcjs.store.call(void 0, ),
|
|
953
953
|
(position) => {
|
|
954
954
|
const pending = position.correlated_at === void 0 || position.at < position.correlated_at;
|
|
955
955
|
const cap = pending ? position.at : Math.max(position.at, checkpoint);
|
|
@@ -977,17 +977,17 @@ function source_matcher() {
|
|
|
977
977
|
};
|
|
978
978
|
}
|
|
979
979
|
async function scan_stream_heads(streams) {
|
|
980
|
-
const stats = await
|
|
981
|
-
exclude: [
|
|
980
|
+
const stats = await _chunkOYR5RIFEcjs.store.call(void 0, ).query_stats(streams, {
|
|
981
|
+
exclude: [_chunkN7K4FQEMcjs.SNAP_EVENT]
|
|
982
982
|
});
|
|
983
|
-
const domain_heads = await
|
|
984
|
-
exclude: [
|
|
983
|
+
const domain_heads = await _chunkOYR5RIFEcjs.store.call(void 0, ).query_stats(streams, {
|
|
984
|
+
exclude: [_chunkN7K4FQEMcjs.SNAP_EVENT, _chunkN7K4FQEMcjs.TOMBSTONE_EVENT]
|
|
985
985
|
});
|
|
986
|
-
const true_heads = await
|
|
986
|
+
const true_heads = await _chunkOYR5RIFEcjs.store.call(void 0, ).query_stats(streams, {});
|
|
987
987
|
const out = /* @__PURE__ */ new Map();
|
|
988
988
|
for (const [stream, { head }] of domain_heads) {
|
|
989
989
|
const marker_head = _optionalChain([stats, 'access', _45 => _45.get, 'call', _46 => _46(stream), 'optionalAccess', _47 => _47.head]);
|
|
990
|
-
const interrupted = _optionalChain([marker_head, 'optionalAccess', _48 => _48.name]) ===
|
|
990
|
+
const interrupted = _optionalChain([marker_head, 'optionalAccess', _48 => _48.name]) === _chunkN7K4FQEMcjs.TOMBSTONE_EVENT;
|
|
991
991
|
out.set(stream, {
|
|
992
992
|
max_id: head.id,
|
|
993
993
|
version: true_heads.get(stream).head.version,
|
|
@@ -1011,7 +1011,7 @@ async function partition_by_safety(stream_info, reactive, skipped, page_size, ca
|
|
|
1011
1011
|
const matches = source_matcher();
|
|
1012
1012
|
const targets = [...stream_info.keys()];
|
|
1013
1013
|
await walk_streams(
|
|
1014
|
-
|
|
1014
|
+
_chunkOYR5RIFEcjs.store.call(void 0, ),
|
|
1015
1015
|
(position) => {
|
|
1016
1016
|
const has_work = position.correlated_at !== void 0 && position.at < position.correlated_at;
|
|
1017
1017
|
if (!has_work) return;
|
|
@@ -1077,7 +1077,7 @@ async function run_archive_callbacks(guarded, target_map) {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
1079
|
async function heads_still_guarded(guarded, guard_events, skipped) {
|
|
1080
|
-
const heads = await
|
|
1080
|
+
const heads = await _chunkOYR5RIFEcjs.store.call(void 0, ).query_stats(guarded, {});
|
|
1081
1081
|
return guarded.filter((stream) => {
|
|
1082
1082
|
if (_optionalChain([heads, 'access', _55 => _55.get, 'call', _56 => _56(stream), 'optionalAccess', _57 => _57.head, 'access', _58 => _58.id]) === guard_events.get(stream).id)
|
|
1083
1083
|
return true;
|
|
@@ -1095,18 +1095,18 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
1095
1095
|
meta: {
|
|
1096
1096
|
correlation,
|
|
1097
1097
|
causation: {
|
|
1098
|
-
event: { id: guard.id, name:
|
|
1098
|
+
event: { id: guard.id, name: _chunkN7K4FQEMcjs.TOMBSTONE_EVENT, stream: guard.stream }
|
|
1099
1099
|
}
|
|
1100
1100
|
}
|
|
1101
1101
|
};
|
|
1102
1102
|
});
|
|
1103
|
-
const truncated = await
|
|
1103
|
+
const truncated = await _chunkOYR5RIFEcjs.store.call(void 0, ).truncate(trunc_targets);
|
|
1104
1104
|
await Promise.all(
|
|
1105
1105
|
guarded.map(async (stream) => {
|
|
1106
1106
|
const entry = truncated.get(stream);
|
|
1107
1107
|
const state2 = seed_states.get(stream);
|
|
1108
1108
|
if (state2 && entry) {
|
|
1109
|
-
await
|
|
1109
|
+
await _chunkOYR5RIFEcjs.cache.call(void 0, ).set(stream, {
|
|
1110
1110
|
stream,
|
|
1111
1111
|
state: state2,
|
|
1112
1112
|
version: entry.committed.version,
|
|
@@ -1115,7 +1115,7 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
1115
1115
|
snaps: 1
|
|
1116
1116
|
});
|
|
1117
1117
|
} else {
|
|
1118
|
-
await
|
|
1118
|
+
await _chunkOYR5RIFEcjs.cache.call(void 0, ).invalidate(stream);
|
|
1119
1119
|
}
|
|
1120
1120
|
})
|
|
1121
1121
|
);
|
|
@@ -1129,7 +1129,7 @@ var _crypto = require('crypto');
|
|
|
1129
1129
|
function report_once(seen, key, message) {
|
|
1130
1130
|
if (seen.has(key)) return;
|
|
1131
1131
|
seen.add(key);
|
|
1132
|
-
|
|
1132
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).error(new Error(message));
|
|
1133
1133
|
}
|
|
1134
1134
|
|
|
1135
1135
|
// src/internal/correlate-cycle.ts
|
|
@@ -1168,23 +1168,26 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1168
1168
|
__init6() {this._raised = 1}
|
|
1169
1169
|
__init7() {this._lowered = 0}
|
|
1170
1170
|
/**
|
|
1171
|
-
* Bumped by a release (shutdown)
|
|
1172
|
-
*
|
|
1171
|
+
* Bumped by a release (shutdown), so a scan or lease reply that was out
|
|
1172
|
+
* across one writes nothing.
|
|
1173
1173
|
*/
|
|
1174
1174
|
__init8() {this._epoch = 0}
|
|
1175
|
+
/** Passes in flight: a restore waits for them, and refuses new ones. */
|
|
1176
|
+
__init9() {this._passes = /* @__PURE__ */ new Set()}
|
|
1177
|
+
__init10() {this._restoring = false}
|
|
1175
1178
|
|
|
1176
1179
|
// Bounded by `maxSubscribedStreams`; static records live apart so eviction
|
|
1177
1180
|
// never drops their +Infinity floor.
|
|
1178
1181
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1182
|
+
__init11() {this._static_subscriptions = /* @__PURE__ */ new Map()}
|
|
1183
|
+
__init12() {this._patterns = new (0, _chunkOYR5RIFEcjs.LruMap)(PATTERN_CACHE_SIZE)}
|
|
1181
1184
|
|
|
1182
1185
|
|
|
1183
1186
|
|
|
1184
1187
|
|
|
1185
1188
|
|
|
1186
1189
|
/** Report-once keys; per instance because `internal/` holds no module state. */
|
|
1187
|
-
|
|
1190
|
+
__init13() {this._reported = /* @__PURE__ */ new Set()}
|
|
1188
1191
|
constructor({
|
|
1189
1192
|
registry,
|
|
1190
1193
|
static_targets,
|
|
@@ -1193,9 +1196,9 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1193
1196
|
declared_lanes,
|
|
1194
1197
|
shard,
|
|
1195
1198
|
on_init
|
|
1196
|
-
}) {;_class3.prototype.__init3.call(this);_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);_class3.prototype.__init11.call(this);
|
|
1199
|
+
}) {;_class3.prototype.__init3.call(this);_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);_class3.prototype.__init6.call(this);_class3.prototype.__init7.call(this);_class3.prototype.__init8.call(this);_class3.prototype.__init9.call(this);_class3.prototype.__init10.call(this);_class3.prototype.__init11.call(this);_class3.prototype.__init12.call(this);_class3.prototype.__init13.call(this);
|
|
1197
1200
|
this._key = shard ? `${registry_key(registry.events)}:${[...shard].sort().join(",")}` : registry_key(registry.events);
|
|
1198
|
-
this._dynamic_subscriptions = new (0,
|
|
1201
|
+
this._dynamic_subscriptions = new (0, _chunkOYR5RIFEcjs.LruMap)(max_subscribed_streams);
|
|
1199
1202
|
this._registry = registry;
|
|
1200
1203
|
this._declared_lanes = declared_lanes;
|
|
1201
1204
|
this._static_targets = static_targets;
|
|
@@ -1230,14 +1233,22 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1230
1233
|
}
|
|
1231
1234
|
await _optionalChain([this, 'access', _59 => _59._on_init, 'optionalCall', _60 => _60()]);
|
|
1232
1235
|
}
|
|
1233
|
-
/**
|
|
1234
|
-
|
|
1236
|
+
/**
|
|
1237
|
+
* Replace the log with no pass in flight, then cold-start: a pass that
|
|
1238
|
+
* read the old log writes before the restore, never into the new one.
|
|
1239
|
+
*/
|
|
1240
|
+
async restart(restore) {
|
|
1241
|
+
this._restoring = true;
|
|
1242
|
+
try {
|
|
1243
|
+
await Promise.allSettled(this._passes);
|
|
1244
|
+
await restore();
|
|
1245
|
+
} finally {
|
|
1246
|
+
this._restoring = false;
|
|
1247
|
+
}
|
|
1235
1248
|
this._init_promise = void 0;
|
|
1236
1249
|
this._checkpoint = -1;
|
|
1237
1250
|
this._dynamic_subscriptions.clear();
|
|
1238
1251
|
this._static_subscriptions.clear();
|
|
1239
|
-
this._raised++;
|
|
1240
|
-
this._epoch++;
|
|
1241
1252
|
}
|
|
1242
1253
|
/** Forget dynamic targets whose rows a full close deleted, so they re-subscribe. */
|
|
1243
1254
|
forget_subscribed(streams) {
|
|
@@ -1246,7 +1257,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1246
1257
|
/** Would the target's own `fetch` (filtered by `source`) return this event? */
|
|
1247
1258
|
_in_fetch_window(source, stream) {
|
|
1248
1259
|
if (source === void 0 || source === stream) return true;
|
|
1249
|
-
if (
|
|
1260
|
+
if (_chunkOYR5RIFEcjs.is_literal_source.call(void 0, source)) return false;
|
|
1250
1261
|
let pattern = this._patterns.get(source);
|
|
1251
1262
|
if (!pattern) {
|
|
1252
1263
|
pattern = new RegExp(source);
|
|
@@ -1256,6 +1267,16 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1256
1267
|
}
|
|
1257
1268
|
/** Scan past the checkpoint, subscribe new targets and raise their work marks. */
|
|
1258
1269
|
async correlate(query, lease = false) {
|
|
1270
|
+
if (this._restoring) return { kind: "idle", last_id: this._checkpoint };
|
|
1271
|
+
const pass = this._scan(query, lease);
|
|
1272
|
+
this._passes.add(pass);
|
|
1273
|
+
try {
|
|
1274
|
+
return await pass;
|
|
1275
|
+
} finally {
|
|
1276
|
+
this._passes.delete(pass);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
async _scan(query, lease) {
|
|
1259
1280
|
await this._init();
|
|
1260
1281
|
const epoch = this._epoch;
|
|
1261
1282
|
const idle = () => ({
|
|
@@ -1275,11 +1296,11 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1275
1296
|
this._lease_until = correlating ? now + CORRELATION_LEASE_MS : 0;
|
|
1276
1297
|
if (correlating === false) return idle();
|
|
1277
1298
|
}
|
|
1278
|
-
const after =
|
|
1299
|
+
const after = this._checkpoint;
|
|
1279
1300
|
const correlated = /* @__PURE__ */ new Map();
|
|
1280
1301
|
let last_id = after;
|
|
1281
1302
|
let stopped = false;
|
|
1282
|
-
const found = await
|
|
1303
|
+
const found = await _chunkOYR5RIFEcjs.store.call(void 0, ).query(
|
|
1283
1304
|
(event) => {
|
|
1284
1305
|
if (stopped) return;
|
|
1285
1306
|
const register = this._registry.events[event.name];
|
|
@@ -1323,9 +1344,9 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1323
1344
|
correlated_at: void 0
|
|
1324
1345
|
};
|
|
1325
1346
|
const seen_in_scan = correlated.has(resolved.target);
|
|
1326
|
-
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _61 => _61.lane])), () => (
|
|
1347
|
+
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _61 => _61.lane])), () => ( _chunkN7K4FQEMcjs.DEFAULT_LANE));
|
|
1327
1348
|
const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _62 => _62.priority]);
|
|
1328
|
-
const resolved_lane = _nullishCoalesce(lane, () => (
|
|
1349
|
+
const resolved_lane = _nullishCoalesce(lane, () => ( _chunkN7K4FQEMcjs.DEFAULT_LANE));
|
|
1329
1350
|
if (held_priority === priority && held_lane !== resolved_lane)
|
|
1330
1351
|
report_lane_conflict(
|
|
1331
1352
|
this._reported,
|
|
@@ -1349,7 +1370,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1349
1370
|
},
|
|
1350
1371
|
// Resolvers see `pii: null`: correlate runs actor-less, and one
|
|
1351
1372
|
// undecryptable row would otherwise stop every stream's reactions.
|
|
1352
|
-
{
|
|
1373
|
+
{ after, limit: query.limit, with_pii: false }
|
|
1353
1374
|
);
|
|
1354
1375
|
if (this._declared_lanes.size > 1) await this._recall(correlated);
|
|
1355
1376
|
const read = last_id > after;
|
|
@@ -1402,7 +1423,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1402
1423
|
await Promise.all(
|
|
1403
1424
|
missed.map(async ([stream, entry]) => {
|
|
1404
1425
|
let row;
|
|
1405
|
-
await
|
|
1426
|
+
await _chunkOYR5RIFEcjs.store.call(void 0, ).query_streams(
|
|
1406
1427
|
(position) => {
|
|
1407
1428
|
row = position;
|
|
1408
1429
|
},
|
|
@@ -1415,8 +1436,8 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1415
1436
|
lane: row.lane
|
|
1416
1437
|
});
|
|
1417
1438
|
if (entry.priority > row.priority) return;
|
|
1418
|
-
const held_lane = _nullishCoalesce(row.lane, () => (
|
|
1419
|
-
const resolved_lane = _nullishCoalesce(entry.lane, () => (
|
|
1439
|
+
const held_lane = _nullishCoalesce(row.lane, () => ( _chunkN7K4FQEMcjs.DEFAULT_LANE));
|
|
1440
|
+
const resolved_lane = _nullishCoalesce(entry.lane, () => ( _chunkN7K4FQEMcjs.DEFAULT_LANE));
|
|
1420
1441
|
if (entry.priority === row.priority && held_lane !== resolved_lane)
|
|
1421
1442
|
report_lane_conflict(
|
|
1422
1443
|
this._reported,
|
|
@@ -1442,7 +1463,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1442
1463
|
millis: 0
|
|
1443
1464
|
});
|
|
1444
1465
|
} catch (error) {
|
|
1445
|
-
|
|
1466
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).warn(
|
|
1446
1467
|
`Could not hand back the correlation lease during shutdown; it expires on its own within ${CORRELATION_LEASE_MS}ms and correlation resumes normally after that. On a single-writer store this usually means another connection holds the database. Cause: ${String(error)}`
|
|
1447
1468
|
);
|
|
1448
1469
|
}
|
|
@@ -1504,14 +1525,14 @@ function compute_backoff_delay(retry, opts) {
|
|
|
1504
1525
|
// src/internal/defer-timer.ts
|
|
1505
1526
|
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
1506
1527
|
var DeferTimer = (_class4 = class {
|
|
1507
|
-
|
|
1528
|
+
__init14() {this._due = /* @__PURE__ */ new Map()}
|
|
1508
1529
|
|
|
1509
1530
|
|
|
1510
1531
|
/**
|
|
1511
1532
|
* @param on_wake - invoked once each time the earliest due-time elapses.
|
|
1512
1533
|
* The consumer re-schedules for whatever is still parked.
|
|
1513
1534
|
*/
|
|
1514
|
-
constructor(on_wake) {;_class4.prototype.
|
|
1535
|
+
constructor(on_wake) {;_class4.prototype.__init14.call(this);
|
|
1515
1536
|
this._on_wake = on_wake;
|
|
1516
1537
|
}
|
|
1517
1538
|
/** Number of currently parked streams. */
|
|
@@ -1595,14 +1616,14 @@ function compute_lag_lead_ratio(handled, lagging, leading) {
|
|
|
1595
1616
|
}
|
|
1596
1617
|
|
|
1597
1618
|
// src/internal/drain-ops.ts
|
|
1598
|
-
var claim = (lagging, leading, by, millis, lane) =>
|
|
1619
|
+
var claim = (lagging, leading, by, millis, lane) => _chunkOYR5RIFEcjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
|
|
1599
1620
|
async function fetch(leased, eventLimit) {
|
|
1600
1621
|
return Promise.all(
|
|
1601
1622
|
leased.map(async ({ stream, source, at, lagging }) => {
|
|
1602
1623
|
const events = [];
|
|
1603
|
-
const stream_exact = source !== void 0 &&
|
|
1624
|
+
const stream_exact = source !== void 0 && _chunkOYR5RIFEcjs.is_literal_source.call(void 0, source) ? true : void 0;
|
|
1604
1625
|
try {
|
|
1605
|
-
await
|
|
1626
|
+
await _chunkOYR5RIFEcjs.store.call(void 0, ).query((e) => events.push(e), {
|
|
1606
1627
|
stream: source,
|
|
1607
1628
|
stream_exact,
|
|
1608
1629
|
after: at,
|
|
@@ -1622,30 +1643,30 @@ async function fetch(leased, eventLimit) {
|
|
|
1622
1643
|
})
|
|
1623
1644
|
);
|
|
1624
1645
|
}
|
|
1625
|
-
var ack = (leases) =>
|
|
1626
|
-
var block = (leases) =>
|
|
1627
|
-
var subscribe = (streams, correlated_at, correlator) =>
|
|
1646
|
+
var ack = (leases) => _chunkOYR5RIFEcjs.store.call(void 0, ).ack(leases);
|
|
1647
|
+
var block = (leases) => _chunkOYR5RIFEcjs.store.call(void 0, ).block(leases);
|
|
1648
|
+
var subscribe = (streams, correlated_at, correlator) => _chunkOYR5RIFEcjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
|
|
1628
1649
|
|
|
1629
1650
|
// src/internal/event-sourcing.ts
|
|
1630
1651
|
var _actpatch = require('@rotorsoft/act-patch');
|
|
1631
1652
|
var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
|
|
1632
1653
|
var validating_patch = (me, state2, partial, event) => {
|
|
1633
1654
|
const next = _actpatch.patch.call(void 0, state2, partial);
|
|
1634
|
-
return
|
|
1655
|
+
return _chunkOYR5RIFEcjs.validate.call(void 0,
|
|
1635
1656
|
`${me.name}.${String(event.name)}#${event.id}`,
|
|
1636
1657
|
next,
|
|
1637
1658
|
me.state
|
|
1638
1659
|
);
|
|
1639
1660
|
};
|
|
1640
1661
|
var DEFAULT_BATCH = 500;
|
|
1641
|
-
var cache_put = (stream, entry) =>
|
|
1642
|
-
(err) =>
|
|
1662
|
+
var cache_put = (stream, entry) => _chunkOYR5RIFEcjs.cache.call(void 0, ).set(stream, entry).catch(
|
|
1663
|
+
(err) => _chunkOYR5RIFEcjs.log.call(void 0, ).warn(
|
|
1643
1664
|
err,
|
|
1644
1665
|
"cache set skipped; the next load re-folds from the store"
|
|
1645
1666
|
)
|
|
1646
1667
|
);
|
|
1647
|
-
var cache_drop = (stream) =>
|
|
1648
|
-
(err) =>
|
|
1668
|
+
var cache_drop = (stream) => _chunkOYR5RIFEcjs.cache.call(void 0, ).invalidate(stream).catch(
|
|
1669
|
+
(err) => _chunkOYR5RIFEcjs.log.call(void 0, ).warn(
|
|
1649
1670
|
err,
|
|
1650
1671
|
"cache invalidate skipped; a stale checkpoint re-folds from its event_id"
|
|
1651
1672
|
)
|
|
@@ -1653,9 +1674,9 @@ var cache_drop = (stream) => _chunkEN2KFJ7Wcjs.cache.call(void 0, ).invalidate(s
|
|
|
1653
1674
|
async function snap(snapshot) {
|
|
1654
1675
|
const { id, stream, name, meta, version } = snapshot.event;
|
|
1655
1676
|
try {
|
|
1656
|
-
const [committed] = await
|
|
1677
|
+
const [committed] = await _chunkOYR5RIFEcjs.store.call(void 0, ).commit(
|
|
1657
1678
|
stream,
|
|
1658
|
-
[{ name:
|
|
1679
|
+
[{ name: _chunkN7K4FQEMcjs.SNAP_EVENT, data: snapshot.state }],
|
|
1659
1680
|
{
|
|
1660
1681
|
correlation: meta.correlation,
|
|
1661
1682
|
causation: { event: { id, name, stream } }
|
|
@@ -1666,22 +1687,22 @@ async function snap(snapshot) {
|
|
|
1666
1687
|
return committed;
|
|
1667
1688
|
} catch (error) {
|
|
1668
1689
|
const reason = error instanceof Error ? error.message : String(error);
|
|
1669
|
-
|
|
1690
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).warn(
|
|
1670
1691
|
`Snapshot write failed on stream "${stream}": ${reason} \u2014 cold starts will replay full history until snapshots succeed.`
|
|
1671
1692
|
);
|
|
1672
1693
|
}
|
|
1673
1694
|
}
|
|
1674
1695
|
async function tombstone(stream, expectedVersion, correlation) {
|
|
1675
1696
|
try {
|
|
1676
|
-
const [committed] = await
|
|
1697
|
+
const [committed] = await _chunkOYR5RIFEcjs.store.call(void 0, ).commit(
|
|
1677
1698
|
stream,
|
|
1678
|
-
[{ name:
|
|
1699
|
+
[{ name: _chunkN7K4FQEMcjs.TOMBSTONE_EVENT, data: {} }],
|
|
1679
1700
|
{ correlation, causation: {} },
|
|
1680
1701
|
expectedVersion
|
|
1681
1702
|
);
|
|
1682
1703
|
return committed;
|
|
1683
1704
|
} catch (error) {
|
|
1684
|
-
if (error instanceof
|
|
1705
|
+
if (error instanceof _chunkN7K4FQEMcjs.ConcurrencyError) return void 0;
|
|
1685
1706
|
throw error;
|
|
1686
1707
|
}
|
|
1687
1708
|
}
|
|
@@ -1711,9 +1732,9 @@ async function scan(source, opts = {}, callback) {
|
|
|
1711
1732
|
if (drop_closed_streams) {
|
|
1712
1733
|
await source.query(
|
|
1713
1734
|
(e) => {
|
|
1714
|
-
if (e.name ===
|
|
1735
|
+
if (e.name === _chunkN7K4FQEMcjs.TOMBSTONE_EVENT) closed_streams.add(e.stream);
|
|
1715
1736
|
},
|
|
1716
|
-
{ names: [
|
|
1737
|
+
{ names: [_chunkN7K4FQEMcjs.TOMBSTONE_EVENT] }
|
|
1717
1738
|
);
|
|
1718
1739
|
}
|
|
1719
1740
|
let max_id;
|
|
@@ -1735,11 +1756,11 @@ async function scan(source, opts = {}, callback) {
|
|
|
1735
1756
|
if (!is_valid(event))
|
|
1736
1757
|
throw new Error(`Invalid event at index ${processed}`);
|
|
1737
1758
|
if (on_progress) on_progress({ processed, id: event.id, max_id });
|
|
1738
|
-
if (drop_snapshots && event.name ===
|
|
1759
|
+
if (drop_snapshots && event.name === _chunkN7K4FQEMcjs.SNAP_EVENT) {
|
|
1739
1760
|
dropped_snaps++;
|
|
1740
1761
|
return;
|
|
1741
1762
|
}
|
|
1742
|
-
if (closed_streams.has(event.stream) && event.name !==
|
|
1763
|
+
if (closed_streams.has(event.stream) && event.name !== _chunkN7K4FQEMcjs.TOMBSTONE_EVENT) {
|
|
1743
1764
|
dropped_closed++;
|
|
1744
1765
|
return;
|
|
1745
1766
|
}
|
|
@@ -1806,17 +1827,17 @@ async function scan(source, opts = {}, callback) {
|
|
|
1806
1827
|
async function load(me, target, callback, patch_fn = bare_patch) {
|
|
1807
1828
|
const { stream, actor, asOf } = target;
|
|
1808
1829
|
const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
|
|
1809
|
-
const cached = time_travel ? void 0 : await
|
|
1830
|
+
const cached = time_travel ? void 0 : await _chunkOYR5RIFEcjs.cache.call(void 0, ).get(stream);
|
|
1810
1831
|
const cache_hit = !!cached;
|
|
1811
1832
|
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _72 => _72.state]), () => ( (me.init ? me.init() : {})));
|
|
1812
1833
|
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _73 => _73.patches]), () => ( 0));
|
|
1813
1834
|
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _74 => _74.snaps]), () => ( 0));
|
|
1814
1835
|
let replayed = 0;
|
|
1815
1836
|
let event;
|
|
1816
|
-
await
|
|
1837
|
+
await _chunkOYR5RIFEcjs.store.call(void 0, ).query(
|
|
1817
1838
|
(raw) => {
|
|
1818
1839
|
event = me.view(raw, actor);
|
|
1819
|
-
if (event.name ===
|
|
1840
|
+
if (event.name === _chunkN7K4FQEMcjs.SNAP_EVENT) {
|
|
1820
1841
|
state2 = event.data;
|
|
1821
1842
|
snaps++;
|
|
1822
1843
|
patches = 0;
|
|
@@ -1825,8 +1846,8 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1825
1846
|
state2 = patch_fn(me, state2, me.patch[event.name](event, state2), event);
|
|
1826
1847
|
patches++;
|
|
1827
1848
|
replayed++;
|
|
1828
|
-
} else if (event.name !==
|
|
1829
|
-
|
|
1849
|
+
} else if (event.name !== _chunkN7K4FQEMcjs.TOMBSTONE_EVENT) {
|
|
1850
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).warn(
|
|
1830
1851
|
`Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
|
|
1831
1852
|
);
|
|
1832
1853
|
}
|
|
@@ -1850,7 +1871,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1850
1871
|
...cached ? { after: cached.event_id, with_snaps: true } : { ...time_travel ? {} : { with_snaps: true }, ...asOf }
|
|
1851
1872
|
}
|
|
1852
1873
|
);
|
|
1853
|
-
const head_is_tombstone = _optionalChain([event, 'optionalAccess', _76 => _76.name]) ===
|
|
1874
|
+
const head_is_tombstone = _optionalChain([event, 'optionalAccess', _76 => _76.name]) === _chunkN7K4FQEMcjs.TOMBSTONE_EVENT;
|
|
1854
1875
|
if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
|
|
1855
1876
|
await cache_put(stream, {
|
|
1856
1877
|
stream,
|
|
@@ -1878,7 +1899,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1878
1899
|
if (!stream) throw new Error("Missing target stream");
|
|
1879
1900
|
const reactingTo = _optionalChain([options, 'optionalAccess', _81 => _81.reactingTo]);
|
|
1880
1901
|
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _82 => _82.correlator]), () => ( default_correlator));
|
|
1881
|
-
const validated =
|
|
1902
|
+
const validated = _chunkOYR5RIFEcjs.validate.call(void 0, action2, payload, me.actions[action2]);
|
|
1882
1903
|
const opts = _optionalChain([me, 'access', _83 => _83.options, 'optionalAccess', _84 => _84[action2]]);
|
|
1883
1904
|
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _85 => _85.maxRetries]), () => ( 0));
|
|
1884
1905
|
for (let attempt = 0; ; attempt++) {
|
|
@@ -1889,14 +1910,14 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1889
1910
|
void 0,
|
|
1890
1911
|
patch_fn
|
|
1891
1912
|
);
|
|
1892
|
-
if (_optionalChain([snapshot, 'access', _86 => _86.event, 'optionalAccess', _87 => _87.name]) ===
|
|
1893
|
-
throw new (0,
|
|
1913
|
+
if (_optionalChain([snapshot, 'access', _86 => _86.event, 'optionalAccess', _87 => _87.name]) === _chunkN7K4FQEMcjs.TOMBSTONE_EVENT)
|
|
1914
|
+
throw new (0, _chunkN7K4FQEMcjs.StreamClosedError)(stream);
|
|
1894
1915
|
const expected = _nullishCoalesce(expectedVersion, () => ( (snapshot.version >= 0 ? snapshot.version : void 0)));
|
|
1895
1916
|
if (me.given) {
|
|
1896
1917
|
const invariants = me.given[action2] || [];
|
|
1897
1918
|
invariants.forEach(({ valid: valid2, description }) => {
|
|
1898
1919
|
if (!valid2(snapshot.state, actor))
|
|
1899
|
-
throw new (0,
|
|
1920
|
+
throw new (0, _chunkN7K4FQEMcjs.InvariantError)(
|
|
1900
1921
|
action2,
|
|
1901
1922
|
validated,
|
|
1902
1923
|
target,
|
|
@@ -1913,7 +1934,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1913
1934
|
const tuples = Array.isArray(result[0]) ? result : [result];
|
|
1914
1935
|
const valid = tuples.map(([name, data]) => ({
|
|
1915
1936
|
name,
|
|
1916
|
-
data:
|
|
1937
|
+
data: _chunkOYR5RIFEcjs.validate.call(void 0, name, data, me.events[name])
|
|
1917
1938
|
}));
|
|
1918
1939
|
const emitted = valid.map((e) => me.message(e));
|
|
1919
1940
|
const meta = {
|
|
@@ -1938,7 +1959,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1938
1959
|
};
|
|
1939
1960
|
let committed;
|
|
1940
1961
|
try {
|
|
1941
|
-
committed = await
|
|
1962
|
+
committed = await _chunkOYR5RIFEcjs.store.call(void 0, ).commit(
|
|
1942
1963
|
stream,
|
|
1943
1964
|
emitted,
|
|
1944
1965
|
meta,
|
|
@@ -1947,7 +1968,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1947
1968
|
reactingTo ? expectedVersion : expected
|
|
1948
1969
|
);
|
|
1949
1970
|
} catch (error) {
|
|
1950
|
-
if (error instanceof
|
|
1971
|
+
if (error instanceof _chunkN7K4FQEMcjs.ConcurrencyError) void cache_drop(stream);
|
|
1951
1972
|
throw error;
|
|
1952
1973
|
}
|
|
1953
1974
|
let { state: state2, patches } = snapshot;
|
|
@@ -1986,19 +2007,19 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1986
2007
|
}
|
|
1987
2008
|
return snapshots;
|
|
1988
2009
|
} catch (error) {
|
|
1989
|
-
if (!(error instanceof
|
|
2010
|
+
if (!(error instanceof _chunkN7K4FQEMcjs.ConcurrencyError)) throw error;
|
|
1990
2011
|
if (expectedVersion !== void 0) throw error;
|
|
1991
2012
|
if (attempt >= max_retries) throw error;
|
|
1992
2013
|
if (_optionalChain([opts, 'optionalAccess', _94 => _94.backoff])) {
|
|
1993
2014
|
const delay_ms = compute_backoff_delay(attempt, opts.backoff);
|
|
1994
|
-
if (delay_ms > 0) await
|
|
2015
|
+
if (delay_ms > 0) await _chunkOYR5RIFEcjs.sleep.call(void 0, delay_ms);
|
|
1995
2016
|
}
|
|
1996
2017
|
}
|
|
1997
2018
|
}
|
|
1998
2019
|
}
|
|
1999
2020
|
|
|
2000
2021
|
// src/internal/tracing.ts
|
|
2001
|
-
var PRETTY =
|
|
2022
|
+
var PRETTY = _chunkOYR5RIFEcjs.config.call(void 0, ).env !== "production";
|
|
2002
2023
|
var C_BLUE = "\x1B[38;5;39m";
|
|
2003
2024
|
var C_ORANGE = "\x1B[38;5;208m";
|
|
2004
2025
|
var C_GREEN = "\x1B[38;5;42m";
|
|
@@ -2184,7 +2205,7 @@ function budget_exhausted(lease, options, store_failing) {
|
|
|
2184
2205
|
if (store_failing || !_optionalChain([options, 'optionalAccess', _104 => _104.blockOnError]) || lease.retry <= options.maxRetries)
|
|
2185
2206
|
return void 0;
|
|
2186
2207
|
const error = `Blocking ${lease.stream} after ${lease.retry} claims with no acknowledged progress \u2014 the retry budget (${options.maxRetries}) was spent without the handler ever reporting an error. That means every attempt lost its lease before it could ack: move the reaction to a lane whose leaseMillis covers the handler, then unblock the stream.`;
|
|
2187
|
-
|
|
2208
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).error(error);
|
|
2188
2209
|
return { lease, handled: 0, acked_at: lease.at, error, block: true };
|
|
2189
2210
|
}
|
|
2190
2211
|
function fetch_failure_policy(registry) {
|
|
@@ -2200,13 +2221,13 @@ function fetch_failure_policy(registry) {
|
|
|
2200
2221
|
function finalize(lease, handled, at, error, options, logger, failed_at) {
|
|
2201
2222
|
if (!error) return { lease, handled, acked_at: at };
|
|
2202
2223
|
logger.error(error);
|
|
2203
|
-
const non_retryable = error instanceof
|
|
2224
|
+
const non_retryable = error instanceof _chunkN7K4FQEMcjs.NonRetryableError;
|
|
2204
2225
|
const block2 = options.blockOnError && (non_retryable || lease.retry >= options.maxRetries);
|
|
2205
2226
|
if (block2)
|
|
2206
2227
|
logger.error(
|
|
2207
2228
|
non_retryable ? `Blocking ${lease.stream} on non-retryable error.` : `Blocking ${lease.stream} after ${lease.retry} retries.`
|
|
2208
2229
|
);
|
|
2209
|
-
const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => (
|
|
2230
|
+
const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunkOYR5RIFEcjs.DEFAULT_BACKOFF)));
|
|
2210
2231
|
return {
|
|
2211
2232
|
lease,
|
|
2212
2233
|
handled,
|
|
@@ -2335,7 +2356,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
2335
2356
|
const acked = await ops.ack(submitted);
|
|
2336
2357
|
const expected = submitted.filter((l) => l.due === void 0).length;
|
|
2337
2358
|
if (acked.length < expected)
|
|
2338
|
-
|
|
2359
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).warn(
|
|
2339
2360
|
`drain: ${expected - acked.length} of ${expected} acks were dropped \u2014 the lease was taken by another worker mid-handler. That work will be redelivered (at-least-once), but persistent drops mean leaseMillis is too short for this handler.`
|
|
2340
2361
|
);
|
|
2341
2362
|
const closeable = handled.filter((h) => h.close !== void 0).map((h) => h.close);
|
|
@@ -2362,9 +2383,9 @@ var DrainController = (_class5 = class {
|
|
|
2362
2383
|
* empty claim saw), so a claim never lowers over a raise that landed
|
|
2363
2384
|
* during it.
|
|
2364
2385
|
*/
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2386
|
+
__init15() {this._raised = 0}
|
|
2387
|
+
__init16() {this._lowered = 0}
|
|
2388
|
+
__init17() {this._ratio = 0.5}
|
|
2368
2389
|
/**
|
|
2369
2390
|
* Local wake at the earliest parked (backoff or defer) visit, or at the
|
|
2370
2391
|
* lease expiry after a failed pass (the {@link RETRY} key); the schedule
|
|
@@ -2372,19 +2393,19 @@ var DrainController = (_class5 = class {
|
|
|
2372
2393
|
* drains until a pass leases nothing or the controller stops, and an entry
|
|
2373
2394
|
* stays until handled or until a later pass claims nothing.
|
|
2374
2395
|
*/
|
|
2375
|
-
|
|
2396
|
+
__init18() {this._defer = new DeferTimer(() => {
|
|
2376
2397
|
this.arm();
|
|
2377
2398
|
void this._deps.run_scoped(async () => {
|
|
2378
2399
|
while ((await this.drain()).leased.length > 0) ;
|
|
2379
2400
|
});
|
|
2380
2401
|
})}
|
|
2381
2402
|
|
|
2382
|
-
|
|
2383
|
-
|
|
2403
|
+
__init19() {this._misrouted = /* @__PURE__ */ new Set()}
|
|
2404
|
+
__init20() {this._stopped = false}
|
|
2384
2405
|
/** The pass in flight. Never rejects; graceful shutdown waits on it. */
|
|
2385
2406
|
|
|
2386
2407
|
|
|
2387
|
-
constructor(deps) {;_class5.prototype.
|
|
2408
|
+
constructor(deps) {;_class5.prototype.__init15.call(this);_class5.prototype.__init16.call(this);_class5.prototype.__init17.call(this);_class5.prototype.__init18.call(this);_class5.prototype.__init19.call(this);_class5.prototype.__init20.call(this);
|
|
2388
2409
|
this._deps = deps;
|
|
2389
2410
|
}
|
|
2390
2411
|
arm() {
|
|
@@ -2408,9 +2429,11 @@ var DrainController = (_class5 = class {
|
|
|
2408
2429
|
get lane() {
|
|
2409
2430
|
return this._deps.lane;
|
|
2410
2431
|
}
|
|
2411
|
-
/**
|
|
2432
|
+
/**
|
|
2433
|
+
* Drains every `cycleMs` while armed; the unref'd timer never holds the
|
|
2434
|
+
* process. Called once, when the controller is built.
|
|
2435
|
+
*/
|
|
2412
2436
|
start(cycleMs) {
|
|
2413
|
-
if (this._worker || this._stopped) return;
|
|
2414
2437
|
const run = this._deps.run_scoped;
|
|
2415
2438
|
const tick = async () => {
|
|
2416
2439
|
if (this.armed) await run(() => this.drain());
|
|
@@ -2433,9 +2456,9 @@ var DrainController = (_class5 = class {
|
|
|
2433
2456
|
if (!this.armed || this._stopped || this._inflight)
|
|
2434
2457
|
return EMPTY_DRAIN;
|
|
2435
2458
|
const d = _nullishCoalesce(this._deps.defaults, () => ( {}));
|
|
2436
|
-
const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => (
|
|
2437
|
-
const eventLimit = _nullishCoalesce(options.eventLimit, () => (
|
|
2438
|
-
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => (
|
|
2459
|
+
const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunkOYR5RIFEcjs.DEFAULT_STREAM_LIMIT));
|
|
2460
|
+
const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkOYR5RIFEcjs.DEFAULT_EVENT_LIMIT));
|
|
2461
|
+
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkOYR5RIFEcjs.DEFAULT_LEASE_MILLIS));
|
|
2439
2462
|
if (this._deps.breaker.state(Date.now()) === "open")
|
|
2440
2463
|
return EMPTY_DRAIN;
|
|
2441
2464
|
const pass = this._pass(streamLimit, eventLimit, leaseMillis).finally(
|
|
@@ -2510,7 +2533,7 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
2510
2533
|
const { pii, ...rest } = event;
|
|
2511
2534
|
if (pii == null) {
|
|
2512
2535
|
const shredded = { ...data };
|
|
2513
|
-
for (const f of fields) shredded[f] =
|
|
2536
|
+
for (const f of fields) shredded[f] = _chunkN7K4FQEMcjs.SHREDDED;
|
|
2514
2537
|
return { ...rest, data: shredded };
|
|
2515
2538
|
}
|
|
2516
2539
|
const allowed = !!actor && !!predicate && predicate(event, actor);
|
|
@@ -2521,7 +2544,7 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
2521
2544
|
};
|
|
2522
2545
|
}
|
|
2523
2546
|
const redacted = { ...data };
|
|
2524
|
-
for (const f of fields) redacted[f] =
|
|
2547
|
+
for (const f of fields) redacted[f] = _chunkN7K4FQEMcjs.REDACTED;
|
|
2525
2548
|
return { ...rest, data: redacted };
|
|
2526
2549
|
}
|
|
2527
2550
|
var IDENTITY_GATE = (event) => event;
|
|
@@ -2658,7 +2681,7 @@ function make_deferred(handler, schedule) {
|
|
|
2658
2681
|
const call = handler;
|
|
2659
2682
|
const deferred = async (event, stream, app) => {
|
|
2660
2683
|
const when = typeof schedule === "function" ? schedule(event) : schedule;
|
|
2661
|
-
if (Date.now() < resolve_defer_at(when, event)) throw new (0,
|
|
2684
|
+
if (Date.now() < resolve_defer_at(when, event)) throw new (0, _chunkN7K4FQEMcjs.DeferSignal)(when);
|
|
2662
2685
|
return call(event, stream, app);
|
|
2663
2686
|
};
|
|
2664
2687
|
Object.defineProperty(deferred, "name", { value: handler.name });
|
|
@@ -2727,7 +2750,7 @@ function build_handle(deps) {
|
|
|
2727
2750
|
handled++;
|
|
2728
2751
|
}
|
|
2729
2752
|
} catch (error) {
|
|
2730
|
-
if (error instanceof
|
|
2753
|
+
if (error instanceof _chunkN7K4FQEMcjs.DeferSignal) {
|
|
2731
2754
|
let defer;
|
|
2732
2755
|
try {
|
|
2733
2756
|
defer = resolve_defer_at(error.when, event);
|
|
@@ -2806,24 +2829,24 @@ function build_handle_batch(logger) {
|
|
|
2806
2829
|
|
|
2807
2830
|
// src/internal/settle.ts
|
|
2808
2831
|
var SettleLoop = (_class6 = class {
|
|
2809
|
-
|
|
2832
|
+
__init21() {this._timer = void 0}
|
|
2810
2833
|
/**
|
|
2811
2834
|
* The cycle in flight, set while one runs. Shutdown waits for it
|
|
2812
2835
|
* (`stop()` cancels scheduling only). Never rejects.
|
|
2813
2836
|
*/
|
|
2814
2837
|
|
|
2815
2838
|
/** A wake-up arrived while a cycle ran: run one more pass after it. */
|
|
2816
|
-
|
|
2839
|
+
__init22() {this._pending = false}
|
|
2817
2840
|
/** The last caller's options, used by the next pass. */
|
|
2818
|
-
|
|
2841
|
+
__init23() {this._next = void 0}
|
|
2819
2842
|
/** When the scheduled pass fires (epoch ms). */
|
|
2820
|
-
|
|
2843
|
+
__init24() {this._due = 0}
|
|
2821
2844
|
/** Set at shutdown: nothing schedules again. */
|
|
2822
|
-
|
|
2845
|
+
__init25() {this._stopped = false}
|
|
2823
2846
|
|
|
2824
2847
|
/** Debounce window applied when the caller doesn't override via `SettleOptions.debounceMs`. */
|
|
2825
2848
|
|
|
2826
|
-
constructor(deps, default_debounce_ms) {;_class6.prototype.
|
|
2849
|
+
constructor(deps, default_debounce_ms) {;_class6.prototype.__init21.call(this);_class6.prototype.__init22.call(this);_class6.prototype.__init23.call(this);_class6.prototype.__init24.call(this);_class6.prototype.__init25.call(this);
|
|
2827
2850
|
this._deps = deps;
|
|
2828
2851
|
this._default_debounce_ms = default_debounce_ms;
|
|
2829
2852
|
}
|
|
@@ -2856,8 +2879,7 @@ var SettleLoop = (_class6 = class {
|
|
|
2856
2879
|
this._timer = void 0;
|
|
2857
2880
|
const {
|
|
2858
2881
|
debounceMs: _,
|
|
2859
|
-
|
|
2860
|
-
correlate: { after: _after, ...correlate_query } = {},
|
|
2882
|
+
correlate: correlate_query = {},
|
|
2861
2883
|
maxPasses = Infinity,
|
|
2862
2884
|
...drain_options
|
|
2863
2885
|
} = _nullishCoalesce(this._next, () => ( {}));
|
|
@@ -2870,7 +2892,7 @@ var SettleLoop = (_class6 = class {
|
|
|
2870
2892
|
if (scanned) this._deps.breaker.passed();
|
|
2871
2893
|
const drain = await this._deps.drain(drain_options);
|
|
2872
2894
|
passes.push(drain);
|
|
2873
|
-
const made_progress = drain.leased.length > 0 || scanned &&
|
|
2895
|
+
const made_progress = drain.leased.length > 0 || scanned && pass.read;
|
|
2874
2896
|
if (!made_progress) break;
|
|
2875
2897
|
}
|
|
2876
2898
|
if (passes.length) this._deps.on_settled(merge_drains(passes));
|
|
@@ -2919,7 +2941,7 @@ function validate_only_lanes(options, lanes) {
|
|
|
2919
2941
|
);
|
|
2920
2942
|
}
|
|
2921
2943
|
var Act = (_class7 = class {
|
|
2922
|
-
|
|
2944
|
+
__init26() {this._emitter = new (0, _events2.default)()}
|
|
2923
2945
|
|
|
2924
2946
|
|
|
2925
2947
|
|
|
@@ -2995,14 +3017,14 @@ var Act = (_class7 = class {
|
|
|
2995
3017
|
/** Lanes to arm per event; `"all"` when a dynamic resolver hides the lane. */
|
|
2996
3018
|
|
|
2997
3019
|
|
|
2998
|
-
|
|
3020
|
+
__init27() {this._logger = _chunkOYR5RIFEcjs.log.call(void 0, )}
|
|
2999
3021
|
/** This Act's ports: its own bag, or the singleton adapters. */
|
|
3000
3022
|
|
|
3001
3023
|
/** Runs a body so internal `store()`/`cache()` calls resolve to `_ports`. */
|
|
3002
3024
|
|
|
3003
3025
|
|
|
3004
3026
|
|
|
3005
|
-
|
|
3027
|
+
__init28() {this._close_lock = new CloseLock()}
|
|
3006
3028
|
/** Every lane a controller can exist for: `"default"` plus each declared one. */
|
|
3007
3029
|
|
|
3008
3030
|
/** Drain lanes declared via `.withLane(...)`. Implicit default not included. */
|
|
@@ -3010,16 +3032,16 @@ var Act = (_class7 = class {
|
|
|
3010
3032
|
return this._lanes;
|
|
3011
3033
|
}
|
|
3012
3034
|
/** Use the {@link act} builder rather than constructing directly. */
|
|
3013
|
-
constructor(registry, states = /* @__PURE__ */ new Map(), batch_handlers = /* @__PURE__ */ new Map(), options = {}, lanes = [], patch_fn = bare_patch) {;_class7.prototype.
|
|
3035
|
+
constructor(registry, states = /* @__PURE__ */ new Map(), batch_handlers = /* @__PURE__ */ new Map(), options = {}, lanes = [], patch_fn = bare_patch) {;_class7.prototype.__init26.call(this);_class7.prototype.__init27.call(this);_class7.prototype.__init28.call(this);
|
|
3014
3036
|
this.registry = registry;
|
|
3015
3037
|
this._states = states;
|
|
3016
3038
|
this._batch_handlers = batch_handlers;
|
|
3017
3039
|
this._lanes = lanes;
|
|
3018
3040
|
this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
|
|
3019
3041
|
validate_only_lanes(options, lanes);
|
|
3020
|
-
this._ports = _nullishCoalesce(options.scoped, () => (
|
|
3042
|
+
this._ports = _nullishCoalesce(options.scoped, () => ( _chunkOYR5RIFEcjs.default_scope.call(void 0, )));
|
|
3021
3043
|
const ports = this._ports;
|
|
3022
|
-
this._scoped =
|
|
3044
|
+
this._scoped = _chunkOYR5RIFEcjs.make_run_scoped.call(void 0, {
|
|
3023
3045
|
// Getters, not a spread: the singletons resolve lazily, so a later
|
|
3024
3046
|
// `store(...)` / `cache(...)` still takes effect.
|
|
3025
3047
|
get store() {
|
|
@@ -3029,14 +3051,14 @@ var Act = (_class7 = class {
|
|
|
3029
3051
|
return ports.cache;
|
|
3030
3052
|
},
|
|
3031
3053
|
// Parsed per build, so a bad window throws on every build.
|
|
3032
|
-
autoclose_window:
|
|
3054
|
+
autoclose_window: _chunkOYR5RIFEcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
|
|
3033
3055
|
});
|
|
3034
3056
|
this._correlator = _nullishCoalesce(options.correlator, () => ( default_correlator));
|
|
3035
3057
|
this._es = build_es(this._logger, this._correlator, patch_fn);
|
|
3036
3058
|
this._cd = build_drain(this._logger);
|
|
3037
3059
|
const handle = build_handle({
|
|
3038
3060
|
logger: this._logger,
|
|
3039
|
-
reaction_scope:
|
|
3061
|
+
reaction_scope: _chunkOYR5RIFEcjs.make_reaction_scope.call(void 0, {
|
|
3040
3062
|
do: this.do.bind(this),
|
|
3041
3063
|
load: this.load.bind(this),
|
|
3042
3064
|
query: this.query.bind(this),
|
|
@@ -3066,12 +3088,12 @@ var Act = (_class7 = class {
|
|
|
3066
3088
|
this._ports.store,
|
|
3067
3089
|
options.listen !== false
|
|
3068
3090
|
);
|
|
3069
|
-
|
|
3091
|
+
_chunkOYR5RIFEcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
|
|
3070
3092
|
}
|
|
3071
3093
|
/** Shared by drain, settle and autoclose; bad knobs throw at build. */
|
|
3072
3094
|
_build_breaker(options) {
|
|
3073
3095
|
return new CircuitBreaker(
|
|
3074
|
-
|
|
3096
|
+
_chunkOYR5RIFEcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
|
|
3075
3097
|
{
|
|
3076
3098
|
on_error: (error, circuit) => this._emit_error(error, circuit),
|
|
3077
3099
|
// When the cooldown elapses, settle once: its scan or claim is the
|
|
@@ -3105,7 +3127,7 @@ var Act = (_class7 = class {
|
|
|
3105
3127
|
try {
|
|
3106
3128
|
await this._run_close(targets);
|
|
3107
3129
|
} catch (error) {
|
|
3108
|
-
if (error instanceof
|
|
3130
|
+
if (error instanceof _chunkN7K4FQEMcjs.StoreError) throw error;
|
|
3109
3131
|
this._logger.error(
|
|
3110
3132
|
error,
|
|
3111
3133
|
`Reaction-requested close of ${targets.map((t) => `"${t.stream}"`).join(", ")} failed and was not retried; close it with app.close(...) once the cause is fixed.`
|
|
@@ -3140,7 +3162,7 @@ var Act = (_class7 = class {
|
|
|
3140
3162
|
/** Audit deps, built after the controllers so the lane set is final. */
|
|
3141
3163
|
_build_audit_deps() {
|
|
3142
3164
|
return {
|
|
3143
|
-
store:
|
|
3165
|
+
store: _chunkOYR5RIFEcjs.store,
|
|
3144
3166
|
event_to_state: this._event_to_state,
|
|
3145
3167
|
// Declared lanes, not this process's controllers: a lane another
|
|
3146
3168
|
// worker drains is not `unknown-lane`.
|
|
@@ -3153,7 +3175,7 @@ var Act = (_class7 = class {
|
|
|
3153
3175
|
registry: this.registry,
|
|
3154
3176
|
static_targets: classification.static_targets,
|
|
3155
3177
|
cd: this._cd,
|
|
3156
|
-
max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => (
|
|
3178
|
+
max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => ( _chunkN7K4FQEMcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS)),
|
|
3157
3179
|
// Declared lanes (not active ones): a lane another process claims is
|
|
3158
3180
|
// still a valid destination.
|
|
3159
3181
|
declared_lanes: new Set(this._declared_lanes),
|
|
@@ -3169,7 +3191,7 @@ var Act = (_class7 = class {
|
|
|
3169
3191
|
/** Cold start: an idle deferred stream still fires on time after a restart. */
|
|
3170
3192
|
async _seed_persisted_defers() {
|
|
3171
3193
|
const now = Date.now();
|
|
3172
|
-
await walk_streams(
|
|
3194
|
+
await walk_streams(_chunkOYR5RIFEcjs.store.call(void 0, ), (pos) => {
|
|
3173
3195
|
if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
|
|
3174
3196
|
const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
|
|
3175
3197
|
_optionalChain([controller, 'optionalAccess', _124 => _124.seed_defer, 'call', _125 => _125(pos.stream, pos.deferred_at)]);
|
|
@@ -3188,7 +3210,7 @@ var Act = (_class7 = class {
|
|
|
3188
3210
|
on_settled: (drain) => this.emit("settled", drain),
|
|
3189
3211
|
breaker: this._breaker
|
|
3190
3212
|
},
|
|
3191
|
-
_nullishCoalesce(options.settleDebounceMs, () => (
|
|
3213
|
+
_nullishCoalesce(options.settleDebounceMs, () => ( _chunkN7K4FQEMcjs.DEFAULT_SETTLE_DEBOUNCE_MS))
|
|
3192
3214
|
);
|
|
3193
3215
|
}
|
|
3194
3216
|
|
|
@@ -3208,7 +3230,7 @@ var Act = (_class7 = class {
|
|
|
3208
3230
|
*/
|
|
3209
3231
|
shutdown(options) {
|
|
3210
3232
|
if (!this._shutdown_promise) {
|
|
3211
|
-
|
|
3233
|
+
_chunkOYR5RIFEcjs.resolveShutdownConfig.call(void 0, options);
|
|
3212
3234
|
this._shutdown_promise = (async () => {
|
|
3213
3235
|
this.stop_correlations();
|
|
3214
3236
|
this._settle.stop(true);
|
|
@@ -3228,10 +3250,10 @@ var Act = (_class7 = class {
|
|
|
3228
3250
|
* default for none or 0, and for a running settle), capped.
|
|
3229
3251
|
*/
|
|
3230
3252
|
_derive_grace_ms(running, settling) {
|
|
3231
|
-
let max = settling ?
|
|
3253
|
+
let max = settling ? _chunkOYR5RIFEcjs.DEFAULT_LEASE_MILLIS : 0;
|
|
3232
3254
|
for (const c of running)
|
|
3233
|
-
max = Math.max(max, c.lease_millis ||
|
|
3234
|
-
return Math.min(max,
|
|
3255
|
+
max = Math.max(max, c.lease_millis || _chunkOYR5RIFEcjs.DEFAULT_LEASE_MILLIS);
|
|
3256
|
+
return Math.min(max, _chunkOYR5RIFEcjs.MAX_SHUTDOWN_GRACE_MS);
|
|
3235
3257
|
}
|
|
3236
3258
|
async _await_inflight(grace_ms) {
|
|
3237
3259
|
const running = [...this._drain_controllers.values()].filter(
|
|
@@ -3312,7 +3334,7 @@ var Act = (_class7 = class {
|
|
|
3312
3334
|
* @see {@link ValidationError}, {@link InvariantError}, {@link ConcurrencyError}
|
|
3313
3335
|
*/
|
|
3314
3336
|
async do(action2, target, payload, options) {
|
|
3315
|
-
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.reactingTo]), () => (
|
|
3337
|
+
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.reactingTo]), () => ( _chunkOYR5RIFEcjs.current_reacting.call(void 0, )));
|
|
3316
3338
|
const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _128 => _128.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
|
|
3317
3339
|
return this._scoped(async () => {
|
|
3318
3340
|
const snapshots = await this._es.action(
|
|
@@ -3373,7 +3395,7 @@ var Act = (_class7 = class {
|
|
|
3373
3395
|
return this._scoped(async () => {
|
|
3374
3396
|
let first;
|
|
3375
3397
|
let last;
|
|
3376
|
-
const count = await
|
|
3398
|
+
const count = await _chunkOYR5RIFEcjs.store.call(void 0, ).query((e) => {
|
|
3377
3399
|
const gated = this.registry.query_gate(e.name)(e);
|
|
3378
3400
|
if (!first) first = gated;
|
|
3379
3401
|
last = gated;
|
|
@@ -3403,7 +3425,7 @@ var Act = (_class7 = class {
|
|
|
3403
3425
|
async query_array(query) {
|
|
3404
3426
|
return this._scoped(async () => {
|
|
3405
3427
|
const events = [];
|
|
3406
|
-
await
|
|
3428
|
+
await _chunkOYR5RIFEcjs.store.call(void 0, ).query((e) => {
|
|
3407
3429
|
events.push(this.registry.query_gate(e.name)(e));
|
|
3408
3430
|
}, query);
|
|
3409
3431
|
return events;
|
|
@@ -3423,14 +3445,14 @@ var Act = (_class7 = class {
|
|
|
3423
3445
|
*/
|
|
3424
3446
|
async forget(stream) {
|
|
3425
3447
|
return this._scoped(async () => {
|
|
3426
|
-
const s =
|
|
3448
|
+
const s = _chunkOYR5RIFEcjs.store.call(void 0, );
|
|
3427
3449
|
if (!s.forget_pii) {
|
|
3428
3450
|
throw new Error(
|
|
3429
3451
|
`Store does not implement forget_pii \u2014 adapter cannot comply with sensitive-data erasure. Use an adapter that declares pii_isolation: true (e.g. @rotorsoft/act on the in-memory store).`
|
|
3430
3452
|
);
|
|
3431
3453
|
}
|
|
3432
3454
|
const eventCount = await s.forget_pii(stream);
|
|
3433
|
-
await
|
|
3455
|
+
await _chunkOYR5RIFEcjs.cache.call(void 0, ).invalidate(stream);
|
|
3434
3456
|
if (eventCount > 0) {
|
|
3435
3457
|
this.emit("forgotten", { stream, at: /* @__PURE__ */ new Date(), eventCount });
|
|
3436
3458
|
}
|
|
@@ -3464,7 +3486,7 @@ var Act = (_class7 = class {
|
|
|
3464
3486
|
* @see {@link correlate} for dynamic stream discovery
|
|
3465
3487
|
*/
|
|
3466
3488
|
async drain(options = {}) {
|
|
3467
|
-
|
|
3489
|
+
_chunkOYR5RIFEcjs.resolveDrainConfig.call(void 0, options);
|
|
3468
3490
|
if (!this._drain)
|
|
3469
3491
|
return { fetched: [], leased: [], acked: [], blocked: [] };
|
|
3470
3492
|
return this._scoped(() => this._drain_all(options));
|
|
@@ -3529,8 +3551,9 @@ var Act = (_class7 = class {
|
|
|
3529
3551
|
* target streams their reactions resolve to (static or computed from
|
|
3530
3552
|
* the event), and marks their work so the next drain can claim it.
|
|
3531
3553
|
*
|
|
3532
|
-
* @param query -
|
|
3533
|
-
*
|
|
3554
|
+
* @param query - Only `limit` is used: the most events the pass reads
|
|
3555
|
+
* (default 10). The scan always starts at the correlation checkpoint,
|
|
3556
|
+
* which every reaction shares, so filters and `after` are ignored.
|
|
3534
3557
|
* @returns The number of newly subscribed streams and the last scanned event id
|
|
3535
3558
|
*
|
|
3536
3559
|
* @example Manual correlation
|
|
@@ -3540,7 +3563,7 @@ var Act = (_class7 = class {
|
|
|
3540
3563
|
*
|
|
3541
3564
|
* @see {@link start_correlations} for automatic periodic correlation
|
|
3542
3565
|
*/
|
|
3543
|
-
async correlate(query = {
|
|
3566
|
+
async correlate(query = { limit: 10 }) {
|
|
3544
3567
|
const pass = await this._correlate_pass(query);
|
|
3545
3568
|
return {
|
|
3546
3569
|
subscribed: pass.kind === "scanned" ? pass.subscribed : 0,
|
|
@@ -3552,8 +3575,7 @@ var Act = (_class7 = class {
|
|
|
3552
3575
|
if (!this._drain) return { kind: "idle", last_id: -1 };
|
|
3553
3576
|
return this._scoped(async () => {
|
|
3554
3577
|
const pass = await this._correlate.correlate(query, lease);
|
|
3555
|
-
if (pass.kind === "scanned" &&
|
|
3556
|
-
this._arm_all();
|
|
3578
|
+
if (pass.kind === "scanned" && pass.marked > 0) this._arm_all();
|
|
3557
3579
|
return pass;
|
|
3558
3580
|
});
|
|
3559
3581
|
}
|
|
@@ -3644,7 +3666,7 @@ var Act = (_class7 = class {
|
|
|
3644
3666
|
*/
|
|
3645
3667
|
async reset(input) {
|
|
3646
3668
|
return this._scoped(async () => {
|
|
3647
|
-
const count = await
|
|
3669
|
+
const count = await _chunkOYR5RIFEcjs.store.call(void 0, ).reset(input);
|
|
3648
3670
|
for (const handler of this._batch_handlers.values())
|
|
3649
3671
|
_optionalChain([handler, 'access', _135 => _135[FOLD_RESET], 'optionalCall', _136 => _136()]);
|
|
3650
3672
|
if (count > 0) {
|
|
@@ -3680,7 +3702,7 @@ var Act = (_class7 = class {
|
|
|
3680
3702
|
*/
|
|
3681
3703
|
async unblock(input) {
|
|
3682
3704
|
return this._scoped(async () => {
|
|
3683
|
-
const count = await
|
|
3705
|
+
const count = await _chunkOYR5RIFEcjs.store.call(void 0, ).unblock(input);
|
|
3684
3706
|
if (count > 0) {
|
|
3685
3707
|
this._wake();
|
|
3686
3708
|
}
|
|
@@ -3694,6 +3716,12 @@ var Act = (_class7 = class {
|
|
|
3694
3716
|
* adapter's {@link Store.restore} driver supplies the transaction
|
|
3695
3717
|
* lifecycle and per-event insert.
|
|
3696
3718
|
*
|
|
3719
|
+
* Safe in a live process: restoring into this Act's own store waits
|
|
3720
|
+
* for its correlate passes in flight, replaces the log, then restarts
|
|
3721
|
+
* correlation and settles. A correlate pass that starts meanwhile
|
|
3722
|
+
* reads nothing. Other processes on the same store keep their
|
|
3723
|
+
* correlation state and must be restarted.
|
|
3724
|
+
*
|
|
3697
3725
|
* Throws if the adapter has no restore capability. Throws on the
|
|
3698
3726
|
* first invalid event (negative version, malformed `created`) with
|
|
3699
3727
|
* the running index in the message; atomic transaction rollback in
|
|
@@ -3729,21 +3757,22 @@ var Act = (_class7 = class {
|
|
|
3729
3757
|
return { ...partial, duration_ms: Date.now() - started };
|
|
3730
3758
|
}
|
|
3731
3759
|
const target = _nullishCoalesce(sink, () => ( (() => {
|
|
3732
|
-
const s =
|
|
3760
|
+
const s = _chunkOYR5RIFEcjs.store.call(void 0, );
|
|
3733
3761
|
if (!s.restore) throw new Error("adapter has no restore capability");
|
|
3734
3762
|
return s;
|
|
3735
3763
|
})()));
|
|
3736
3764
|
let kept = 0;
|
|
3737
3765
|
let migrated = 0;
|
|
3738
3766
|
let dropped = { closed_streams: 0, snapshots: 0 };
|
|
3739
|
-
|
|
3767
|
+
const run = () => target.restore(async (callback) => {
|
|
3740
3768
|
const partial = await scan(source, opts, callback);
|
|
3741
3769
|
kept = partial.kept;
|
|
3742
3770
|
migrated = partial.migrated;
|
|
3743
3771
|
dropped = partial.dropped;
|
|
3744
3772
|
});
|
|
3745
|
-
if (
|
|
3746
|
-
|
|
3773
|
+
if (sink) await run();
|
|
3774
|
+
else {
|
|
3775
|
+
await this._correlate.restart(run);
|
|
3747
3776
|
this._wake();
|
|
3748
3777
|
}
|
|
3749
3778
|
return { kept, migrated, dropped, duration_ms: Date.now() - started };
|
|
@@ -3774,7 +3803,7 @@ var Act = (_class7 = class {
|
|
|
3774
3803
|
async blocked_streams(options) {
|
|
3775
3804
|
return this._scoped(async () => {
|
|
3776
3805
|
const positions = [];
|
|
3777
|
-
await
|
|
3806
|
+
await _chunkOYR5RIFEcjs.store.call(void 0, ).query_streams(
|
|
3778
3807
|
(p) => {
|
|
3779
3808
|
positions.push(p);
|
|
3780
3809
|
},
|
|
@@ -3826,7 +3855,7 @@ var Act = (_class7 = class {
|
|
|
3826
3855
|
* @see {@link Store.prioritize} for the underlying primitive
|
|
3827
3856
|
*/
|
|
3828
3857
|
async prioritize(filter, priority) {
|
|
3829
|
-
return this._scoped(() =>
|
|
3858
|
+
return this._scoped(() => _chunkOYR5RIFEcjs.store.call(void 0, ).prioritize(filter, priority));
|
|
3830
3859
|
}
|
|
3831
3860
|
/** Shared by `close()` and reaction-requested closes. */
|
|
3832
3861
|
async _run_close(targets) {
|
|
@@ -3906,7 +3935,7 @@ var Act = (_class7 = class {
|
|
|
3906
3935
|
* @see {@link correlate} for manual correlation
|
|
3907
3936
|
*/
|
|
3908
3937
|
settle(options) {
|
|
3909
|
-
|
|
3938
|
+
_chunkOYR5RIFEcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
|
|
3910
3939
|
this._schedule(options);
|
|
3911
3940
|
}
|
|
3912
3941
|
}, _class7);
|
|
@@ -4062,16 +4091,16 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
4062
4091
|
}),
|
|
4063
4092
|
// Never block on autoclose: a transient query/store error should retry,
|
|
4064
4093
|
// not quarantine the synthetic stream.
|
|
4065
|
-
options: { blockOnError: false, maxRetries:
|
|
4094
|
+
options: { blockOnError: false, maxRetries: _chunkOYR5RIFEcjs.DEFAULT_MAX_RETRIES },
|
|
4066
4095
|
handler: async (event) => {
|
|
4067
4096
|
const aggregate = event.stream;
|
|
4068
4097
|
const window = read_window();
|
|
4069
4098
|
if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
|
|
4070
|
-
throw new (0,
|
|
4071
|
-
const stats = await
|
|
4099
|
+
throw new (0, _chunkN7K4FQEMcjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
|
|
4100
|
+
const stats = await _chunkOYR5RIFEcjs.store.call(void 0, ).query_stats([aggregate], {
|
|
4072
4101
|
count: true,
|
|
4073
4102
|
tail: keep_days !== void 0 ? true : void 0,
|
|
4074
|
-
exclude: [
|
|
4103
|
+
exclude: [_chunkN7K4FQEMcjs.TOMBSTONE_EVENT, _chunkN7K4FQEMcjs.SNAP_EVENT]
|
|
4075
4104
|
});
|
|
4076
4105
|
const entry = stats.get(aggregate);
|
|
4077
4106
|
if (!entry) return;
|
|
@@ -4102,7 +4131,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
4102
4131
|
dues.push(days_after(entry.tail.created, keep_days));
|
|
4103
4132
|
const future = dues.map((d) => d.getTime()).filter((t) => t > Date.now());
|
|
4104
4133
|
if (future.length)
|
|
4105
|
-
throw new (0,
|
|
4134
|
+
throw new (0, _chunkN7K4FQEMcjs.DeferSignal)({ at: new Date(Math.min(...future)) });
|
|
4106
4135
|
}
|
|
4107
4136
|
};
|
|
4108
4137
|
const key = `__autoclose_${st.name}`;
|
|
@@ -4306,9 +4335,9 @@ var _this_ = ({ stream }) => ({
|
|
|
4306
4335
|
|
|
4307
4336
|
// src/builders/builder-utils.ts
|
|
4308
4337
|
function register_lane(config2, lanes) {
|
|
4309
|
-
|
|
4310
|
-
if (config2.name ===
|
|
4311
|
-
throw new Error(`Lane "${
|
|
4338
|
+
_chunkOYR5RIFEcjs.resolveLaneConfig.call(void 0, config2);
|
|
4339
|
+
if (config2.name === _chunkN7K4FQEMcjs.DEFAULT_LANE)
|
|
4340
|
+
throw new Error(`Lane "${_chunkN7K4FQEMcjs.DEFAULT_LANE}" is reserved`);
|
|
4312
4341
|
const existing = lanes.find((l) => l.name === config2.name);
|
|
4313
4342
|
if (!existing) return void lanes.push(config2);
|
|
4314
4343
|
if (existing.leaseMillis !== config2.leaseMillis || existing.streamLimit !== config2.streamLimit || existing.cycleMs !== config2.cycleMs)
|
|
@@ -4350,9 +4379,9 @@ function reaction_on(event, events, builder) {
|
|
|
4350
4379
|
// Validate the whole bag at the declaration site so a bad
|
|
4351
4380
|
// `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
|
|
4352
4381
|
// not a NaN gate on the first retry.
|
|
4353
|
-
options:
|
|
4354
|
-
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _151 => _151.blockOnError]), () => (
|
|
4355
|
-
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _152 => _152.maxRetries]), () => (
|
|
4382
|
+
options: _chunkOYR5RIFEcjs.resolveReactionConfig.call(void 0, {
|
|
4383
|
+
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _151 => _151.blockOnError]), () => ( _chunkOYR5RIFEcjs.DEFAULT_BLOCK_ON_ERROR)),
|
|
4384
|
+
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _152 => _152.maxRetries]), () => ( _chunkOYR5RIFEcjs.DEFAULT_MAX_RETRIES)),
|
|
4356
4385
|
backoff: _optionalChain([options, 'optionalAccess', _153 => _153.backoff])
|
|
4357
4386
|
})
|
|
4358
4387
|
};
|
|
@@ -4437,7 +4466,7 @@ function date_reviver_schema(schema) {
|
|
|
4437
4466
|
|
|
4438
4467
|
// src/builders/event-builder.ts
|
|
4439
4468
|
function event_tags(schema) {
|
|
4440
|
-
const pii =
|
|
4469
|
+
const pii = _chunkN7K4FQEMcjs.pii_schemas.call(void 0, schema);
|
|
4441
4470
|
const pii_dates = {};
|
|
4442
4471
|
for (const [key, field] of Object.entries(pii)) {
|
|
4443
4472
|
const dates = date_reviver_schema(field);
|
|
@@ -4474,7 +4503,7 @@ function make_event_reader(tags, disclosure, predicate = null) {
|
|
|
4474
4503
|
});
|
|
4475
4504
|
}
|
|
4476
4505
|
function build_events(registry, states, lanes, owners) {
|
|
4477
|
-
const declared = /* @__PURE__ */ new Set([
|
|
4506
|
+
const declared = /* @__PURE__ */ new Set([_chunkN7K4FQEMcjs.DEFAULT_LANE, ...lanes.map((l) => l.name)]);
|
|
4478
4507
|
const lane_errors = [];
|
|
4479
4508
|
const tags = /* @__PURE__ */ new Map();
|
|
4480
4509
|
const sensitive2 = /* @__PURE__ */ new Map();
|
|
@@ -4538,7 +4567,7 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4538
4567
|
if (reader) readers.set(event_name, reader);
|
|
4539
4568
|
}
|
|
4540
4569
|
const snap2 = make_event_reader(event_tags(state2.state), "redact", null);
|
|
4541
|
-
if (snap2) readers.set(
|
|
4570
|
+
if (snap2) readers.set(_chunkN7K4FQEMcjs.SNAP_EVENT, snap2);
|
|
4542
4571
|
if (readers.size === 0) continue;
|
|
4543
4572
|
state2.view = (event, actor) => (_nullishCoalesce(readers.get(event.name), () => ( IDENTITY_GATE)))(event, actor);
|
|
4544
4573
|
}
|
|
@@ -4654,7 +4683,7 @@ function act() {
|
|
|
4654
4683
|
const list = deprecation_summary.map(
|
|
4655
4684
|
(d) => `"${d.deprecated}" (current: "${d.current}", state: "${d.state_name}")`
|
|
4656
4685
|
).join(", ");
|
|
4657
|
-
|
|
4686
|
+
_chunkOYR5RIFEcjs.log.call(void 0, ).info(
|
|
4658
4687
|
`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.`
|
|
4659
4688
|
);
|
|
4660
4689
|
}
|
|
@@ -4696,7 +4725,7 @@ function act() {
|
|
|
4696
4725
|
return reaction_on(event, registry.events, builder);
|
|
4697
4726
|
},
|
|
4698
4727
|
build: (options) => {
|
|
4699
|
-
|
|
4728
|
+
_chunkOYR5RIFEcjs.resolveActConfig.call(void 0, options);
|
|
4700
4729
|
const patch_fn = _optionalChain([options, 'optionalAccess', _165 => _165.validateFoldedState]) === true ? validating_patch : bare_patch;
|
|
4701
4730
|
if (!_built) {
|
|
4702
4731
|
for (const proj of pending_projections) add_projection(proj);
|
|
@@ -4748,7 +4777,7 @@ function act() {
|
|
|
4748
4777
|
synthesize_autoclose_reactions(
|
|
4749
4778
|
registry,
|
|
4750
4779
|
states,
|
|
4751
|
-
|
|
4780
|
+
_chunkOYR5RIFEcjs.current_autoclose_window
|
|
4752
4781
|
);
|
|
4753
4782
|
Object.freeze(registry.actions);
|
|
4754
4783
|
Object.freeze(registry.events);
|
|
@@ -4797,8 +4826,8 @@ function _projection(target) {
|
|
|
4797
4826
|
handler,
|
|
4798
4827
|
resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
|
|
4799
4828
|
options: {
|
|
4800
|
-
blockOnError:
|
|
4801
|
-
maxRetries:
|
|
4829
|
+
blockOnError: _chunkOYR5RIFEcjs.DEFAULT_BLOCK_ON_ERROR,
|
|
4830
|
+
maxRetries: _chunkOYR5RIFEcjs.DEFAULT_MAX_RETRIES
|
|
4802
4831
|
}
|
|
4803
4832
|
}),
|
|
4804
4833
|
widened
|
|
@@ -4839,7 +4868,7 @@ function _projection(target) {
|
|
|
4839
4868
|
throw new Error(
|
|
4840
4869
|
`Projection "${target}" .of() partials must share one state name \u2014 got "${name}" and "${partial.name}"`
|
|
4841
4870
|
);
|
|
4842
|
-
const config2 =
|
|
4871
|
+
const config2 = _chunkOYR5RIFEcjs.resolveFoldConfig.call(void 0, options);
|
|
4843
4872
|
const fold_events = {};
|
|
4844
4873
|
for (const partial of partials)
|
|
4845
4874
|
for (const [event_name, schema] of Object.entries(partial.events)) {
|
|
@@ -4857,8 +4886,8 @@ function _projection(target) {
|
|
|
4857
4886
|
handler: noop,
|
|
4858
4887
|
resolver: { target },
|
|
4859
4888
|
options: {
|
|
4860
|
-
blockOnError:
|
|
4861
|
-
maxRetries:
|
|
4889
|
+
blockOnError: _chunkOYR5RIFEcjs.DEFAULT_BLOCK_ON_ERROR,
|
|
4890
|
+
maxRetries: _chunkOYR5RIFEcjs.DEFAULT_MAX_RETRIES
|
|
4862
4891
|
}
|
|
4863
4892
|
}
|
|
4864
4893
|
]
|
|
@@ -4974,7 +5003,7 @@ function action_builder(state2) {
|
|
|
4974
5003
|
throw new Error(`Duplicate action "${action2}"`);
|
|
4975
5004
|
internal.actions[action2] = schema;
|
|
4976
5005
|
if (options) {
|
|
4977
|
-
|
|
5006
|
+
_chunkOYR5RIFEcjs.resolveActionConfig.call(void 0, options);
|
|
4978
5007
|
internal.options ??= {};
|
|
4979
5008
|
internal.options[action2] = options;
|
|
4980
5009
|
}
|
|
@@ -5263,5 +5292,5 @@ function write_line(writer, line) {
|
|
|
5263
5292
|
|
|
5264
5293
|
|
|
5265
5294
|
|
|
5266
|
-
exports.Act = Act; exports.ActorSchema =
|
|
5295
|
+
exports.Act = Act; exports.ActorSchema = _chunkN7K4FQEMcjs.ActorSchema; exports.CausationEventSchema = _chunkN7K4FQEMcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkN7K4FQEMcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkN7K4FQEMcjs.ConcurrencyError; exports.ConsoleLogger = _chunkOYR5RIFEcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunkN7K4FQEMcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunkN7K4FQEMcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunkN7K4FQEMcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunkN7K4FQEMcjs.DeferSignal; exports.Environments = _chunkN7K4FQEMcjs.Environments; exports.Errors = _chunkN7K4FQEMcjs.Errors; exports.EventMetaSchema = _chunkN7K4FQEMcjs.EventMetaSchema; exports.ExitCodes = _chunkN7K4FQEMcjs.ExitCodes; exports.InMemoryCache = _chunkOYR5RIFEcjs.InMemoryCache; exports.InMemoryStore = _chunkOYR5RIFEcjs.InMemoryStore; exports.InvariantError = _chunkN7K4FQEMcjs.InvariantError; exports.LogLevels = _chunkN7K4FQEMcjs.LogLevels; exports.NonRetryableError = _chunkN7K4FQEMcjs.NonRetryableError; exports.PackageSchema = _chunkOYR5RIFEcjs.PackageSchema; exports.QuerySchema = _chunkN7K4FQEMcjs.QuerySchema; exports.REDACTED = _chunkN7K4FQEMcjs.REDACTED; exports.SHREDDED = _chunkN7K4FQEMcjs.SHREDDED; exports.SNAP_EVENT = _chunkN7K4FQEMcjs.SNAP_EVENT; exports.StoreError = _chunkN7K4FQEMcjs.StoreError; exports.StreamClosedError = _chunkN7K4FQEMcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunkN7K4FQEMcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunkN7K4FQEMcjs.TargetSchema; exports.ValidationError = _chunkN7K4FQEMcjs.ValidationError; exports.ZodEmpty = _chunkN7K4FQEMcjs.ZodEmpty; exports.act = act; exports.cache = _chunkOYR5RIFEcjs.cache; exports.config = _chunkOYR5RIFEcjs.config; exports.dateReviver = _chunkOYR5RIFEcjs.dateReviver; exports.default_scope = _chunkOYR5RIFEcjs.default_scope; exports.dispose = _chunkOYR5RIFEcjs.dispose; exports.disposeAndExit = _chunkOYR5RIFEcjs.disposeAndExit; exports.extend = _chunkOYR5RIFEcjs.extend; exports.is_literal_source = _chunkOYR5RIFEcjs.is_literal_source; exports.log = _chunkOYR5RIFEcjs.log; exports.pii_fields = _chunkN7K4FQEMcjs.pii_fields; exports.port = _chunkOYR5RIFEcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkOYR5RIFEcjs.resolveAutocloseConfig2; exports.sensitive = _chunkN7K4FQEMcjs.sensitive; exports.sleep = _chunkOYR5RIFEcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkOYR5RIFEcjs.store; exports.validate = _chunkOYR5RIFEcjs.validate;
|
|
5267
5296
|
//# sourceMappingURL=index.cjs.map
|