@rotorsoft/act 1.34.4 → 1.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +8 -6
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/builders/act-builder.d.ts.map +1 -1
- package/dist/@types/builders/state-builder.d.ts +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts +4 -2
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts +1 -6
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/internal/projection-fold.d.ts +1 -1
- package/dist/@types/internal/projection-fold.d.ts.map +1 -1
- package/dist/@types/internal/tracing.d.ts.map +1 -1
- package/dist/@types/types/act.d.ts +5 -21
- package/dist/@types/types/act.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +34 -16
- package/dist/@types/types/action.d.ts.map +1 -1
- package/dist/@types/types/builders.d.ts +26 -30
- package/dist/@types/types/builders.d.ts.map +1 -1
- package/dist/@types/types/errors.d.ts +56 -29
- package/dist/@types/types/errors.d.ts.map +1 -1
- package/dist/{chunk-GBAMBUDN.cjs → chunk-BNTVE7RQ.cjs} +13 -13
- package/dist/{chunk-GBAMBUDN.cjs.map → chunk-BNTVE7RQ.cjs.map} +1 -1
- package/dist/{chunk-BKCNU6FF.js → chunk-DH2HW5XJ.js} +13 -4
- package/dist/chunk-DH2HW5XJ.js.map +1 -0
- package/dist/{chunk-RF5MV72K.cjs → chunk-L66OOP2F.cjs} +14 -5
- package/dist/chunk-L66OOP2F.cjs.map +1 -0
- package/dist/{chunk-IEM2NS6J.js → chunk-MHPUVTMX.js} +2 -2
- package/dist/index.cjs +287 -263
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +96 -72
- 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 +4 -2
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +3 -1
- package/package.json +1 -1
- package/dist/chunk-BKCNU6FF.js.map +0 -1
- package/dist/chunk-RF5MV72K.cjs.map +0 -1
- /package/dist/{chunk-IEM2NS6J.js.map → chunk-MHPUVTMX.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
var
|
|
43
|
+
var _chunkBNTVE7RQcjs = require('./chunk-BNTVE7RQ.cjs');
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
@@ -70,24 +70,25 @@ var _chunkGBAMBUDNcjs = require('./chunk-GBAMBUDN.cjs');
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
|
|
74
|
+
var _chunkL66OOP2Fcjs = require('./chunk-L66OOP2F.cjs');
|
|
74
75
|
|
|
75
76
|
// src/signals.ts
|
|
76
77
|
process.once("SIGINT", async (arg) => {
|
|
77
|
-
|
|
78
|
-
await
|
|
78
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).info(arg, "SIGINT");
|
|
79
|
+
await _chunkBNTVE7RQcjs.disposeAndExit.call(void 0, "EXIT");
|
|
79
80
|
});
|
|
80
81
|
process.once("SIGTERM", async (arg) => {
|
|
81
|
-
|
|
82
|
-
await
|
|
82
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).info(arg, "SIGTERM");
|
|
83
|
+
await _chunkBNTVE7RQcjs.disposeAndExit.call(void 0, "EXIT");
|
|
83
84
|
});
|
|
84
85
|
process.once("uncaughtException", async (arg) => {
|
|
85
|
-
|
|
86
|
-
await
|
|
86
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
|
|
87
|
+
await _chunkBNTVE7RQcjs.disposeAndExit.call(void 0, "ERROR");
|
|
87
88
|
});
|
|
88
89
|
process.once("unhandledRejection", async (arg) => {
|
|
89
|
-
|
|
90
|
-
await
|
|
90
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
|
|
91
|
+
await _chunkBNTVE7RQcjs.disposeAndExit.call(void 0, "ERROR");
|
|
91
92
|
});
|
|
92
93
|
|
|
93
94
|
// src/act.ts
|
|
@@ -195,7 +196,7 @@ async function* audit(deps, categories, options = {}) {
|
|
|
195
196
|
if (need_stats) {
|
|
196
197
|
const stats = await deps.store().query_stats(
|
|
197
198
|
{},
|
|
198
|
-
{ count: true, names: true, exclude: [
|
|
199
|
+
{ count: true, names: true, exclude: [_chunkL66OOP2Fcjs.SNAP_EVENT] }
|
|
199
200
|
);
|
|
200
201
|
for (const [stream, s] of stats) {
|
|
201
202
|
for (const p of passes) _optionalChain([p, 'access', _4 => _4.on_stat, 'optionalCall', _5 => _5(stream, s)]);
|
|
@@ -277,7 +278,7 @@ var make_schema_pass = (deps) => {
|
|
|
277
278
|
return;
|
|
278
279
|
}
|
|
279
280
|
const schema = state2.events[name];
|
|
280
|
-
const sensitive2 =
|
|
281
|
+
const sensitive2 = _chunkL66OOP2Fcjs.pii_fields.call(void 0, schema);
|
|
281
282
|
let parse_schema = schema;
|
|
282
283
|
if (sensitive2.length > 0) {
|
|
283
284
|
const omitter = schema.omit;
|
|
@@ -411,7 +412,7 @@ var make_restart_candidate_pass = (deps, options) => {
|
|
|
411
412
|
{
|
|
412
413
|
stream,
|
|
413
414
|
stream_exact: true,
|
|
414
|
-
names: [
|
|
415
|
+
names: [_chunkL66OOP2Fcjs.SNAP_EVENT],
|
|
415
416
|
with_snaps: true
|
|
416
417
|
}
|
|
417
418
|
);
|
|
@@ -840,7 +841,7 @@ async function run_close_cycle(targets, deps) {
|
|
|
840
841
|
deps,
|
|
841
842
|
() => run_full_closes(full, target_map, deps, skipped)
|
|
842
843
|
);
|
|
843
|
-
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name ===
|
|
844
|
+
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT).map(([stream]) => stream);
|
|
844
845
|
if (retired.length) _optionalChain([deps, 'access', _42 => _42.forget_subscribed, 'optionalCall', _43 => _43(retired)]);
|
|
845
846
|
for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
|
|
846
847
|
return { truncated, skipped };
|
|
@@ -922,7 +923,7 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
922
923
|
if (!await windowed_prune_pending(t.stream, t.before, max_id))
|
|
923
924
|
return void 0;
|
|
924
925
|
if (t.archive) await t.archive();
|
|
925
|
-
const result = await
|
|
926
|
+
const result = await _chunkBNTVE7RQcjs.store.call(void 0, ).truncate([
|
|
926
927
|
{ stream: t.stream, before: t.before, max_id }
|
|
927
928
|
]);
|
|
928
929
|
return result.get(t.stream);
|
|
@@ -935,10 +936,10 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
935
936
|
async function windowed_prune_pending(stream, before, max_id) {
|
|
936
937
|
let boundary_id;
|
|
937
938
|
let min_id;
|
|
938
|
-
await
|
|
939
|
+
await _chunkBNTVE7RQcjs.store.call(void 0, ).query(
|
|
939
940
|
(event) => {
|
|
940
941
|
if (min_id === void 0 || event.id < min_id) min_id = event.id;
|
|
941
|
-
if (event.name ===
|
|
942
|
+
if (event.name === _chunkL66OOP2Fcjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
|
|
942
943
|
boundary_id = event.id;
|
|
943
944
|
},
|
|
944
945
|
{ stream, stream_exact: true, with_snaps: true, after: -1 }
|
|
@@ -949,7 +950,7 @@ async function probe_min_watermarks(streams, page_size, checkpoint) {
|
|
|
949
950
|
const min_at = /* @__PURE__ */ new Map();
|
|
950
951
|
const matches = source_matcher();
|
|
951
952
|
await walk_streams(
|
|
952
|
-
|
|
953
|
+
_chunkBNTVE7RQcjs.store.call(void 0, ),
|
|
953
954
|
(position) => {
|
|
954
955
|
const pending = position.correlated_at === void 0 || position.at < position.correlated_at;
|
|
955
956
|
const cap = pending ? position.at : Math.max(position.at, checkpoint);
|
|
@@ -977,17 +978,17 @@ function source_matcher() {
|
|
|
977
978
|
};
|
|
978
979
|
}
|
|
979
980
|
async function scan_stream_heads(streams) {
|
|
980
|
-
const stats = await
|
|
981
|
-
exclude: [
|
|
981
|
+
const stats = await _chunkBNTVE7RQcjs.store.call(void 0, ).query_stats(streams, {
|
|
982
|
+
exclude: [_chunkL66OOP2Fcjs.SNAP_EVENT]
|
|
982
983
|
});
|
|
983
|
-
const domain_heads = await
|
|
984
|
-
exclude: [
|
|
984
|
+
const domain_heads = await _chunkBNTVE7RQcjs.store.call(void 0, ).query_stats(streams, {
|
|
985
|
+
exclude: [_chunkL66OOP2Fcjs.SNAP_EVENT, _chunkL66OOP2Fcjs.TOMBSTONE_EVENT]
|
|
985
986
|
});
|
|
986
|
-
const true_heads = await
|
|
987
|
+
const true_heads = await _chunkBNTVE7RQcjs.store.call(void 0, ).query_stats(streams, {});
|
|
987
988
|
const out = /* @__PURE__ */ new Map();
|
|
988
989
|
for (const [stream, { head }] of domain_heads) {
|
|
989
990
|
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]) ===
|
|
991
|
+
const interrupted = _optionalChain([marker_head, 'optionalAccess', _48 => _48.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT;
|
|
991
992
|
out.set(stream, {
|
|
992
993
|
max_id: head.id,
|
|
993
994
|
version: true_heads.get(stream).head.version,
|
|
@@ -1011,7 +1012,7 @@ async function partition_by_safety(stream_info, reactive, skipped, page_size, ca
|
|
|
1011
1012
|
const matches = source_matcher();
|
|
1012
1013
|
const targets = [...stream_info.keys()];
|
|
1013
1014
|
await walk_streams(
|
|
1014
|
-
|
|
1015
|
+
_chunkBNTVE7RQcjs.store.call(void 0, ),
|
|
1015
1016
|
(position) => {
|
|
1016
1017
|
const has_work = position.correlated_at !== void 0 && position.at < position.correlated_at;
|
|
1017
1018
|
if (!has_work) return;
|
|
@@ -1077,7 +1078,7 @@ async function run_archive_callbacks(guarded, target_map) {
|
|
|
1077
1078
|
}
|
|
1078
1079
|
}
|
|
1079
1080
|
async function heads_still_guarded(guarded, guard_events, skipped) {
|
|
1080
|
-
const heads = await
|
|
1081
|
+
const heads = await _chunkBNTVE7RQcjs.store.call(void 0, ).query_stats(guarded, {});
|
|
1081
1082
|
return guarded.filter((stream) => {
|
|
1082
1083
|
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
1084
|
return true;
|
|
@@ -1095,18 +1096,18 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
1095
1096
|
meta: {
|
|
1096
1097
|
correlation,
|
|
1097
1098
|
causation: {
|
|
1098
|
-
event: { id: guard.id, name:
|
|
1099
|
+
event: { id: guard.id, name: _chunkL66OOP2Fcjs.TOMBSTONE_EVENT, stream: guard.stream }
|
|
1099
1100
|
}
|
|
1100
1101
|
}
|
|
1101
1102
|
};
|
|
1102
1103
|
});
|
|
1103
|
-
const truncated = await
|
|
1104
|
+
const truncated = await _chunkBNTVE7RQcjs.store.call(void 0, ).truncate(trunc_targets);
|
|
1104
1105
|
await Promise.all(
|
|
1105
1106
|
guarded.map(async (stream) => {
|
|
1106
1107
|
const entry = truncated.get(stream);
|
|
1107
1108
|
const state2 = seed_states.get(stream);
|
|
1108
1109
|
if (state2 && entry) {
|
|
1109
|
-
await
|
|
1110
|
+
await _chunkBNTVE7RQcjs.cache.call(void 0, ).set(stream, {
|
|
1110
1111
|
stream,
|
|
1111
1112
|
state: state2,
|
|
1112
1113
|
version: entry.committed.version,
|
|
@@ -1115,7 +1116,7 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
1115
1116
|
snaps: 1
|
|
1116
1117
|
});
|
|
1117
1118
|
} else {
|
|
1118
|
-
await
|
|
1119
|
+
await _chunkBNTVE7RQcjs.cache.call(void 0, ).invalidate(stream);
|
|
1119
1120
|
}
|
|
1120
1121
|
})
|
|
1121
1122
|
);
|
|
@@ -1129,7 +1130,7 @@ var _crypto = require('crypto');
|
|
|
1129
1130
|
function report_once(seen, key, message) {
|
|
1130
1131
|
if (seen.has(key)) return;
|
|
1131
1132
|
seen.add(key);
|
|
1132
|
-
|
|
1133
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).error(new Error(message));
|
|
1133
1134
|
}
|
|
1134
1135
|
|
|
1135
1136
|
// src/internal/correlate-cycle.ts
|
|
@@ -1180,7 +1181,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1180
1181
|
// never lets a resolution re-lane them.
|
|
1181
1182
|
|
|
1182
1183
|
__init11() {this._static_subscriptions = /* @__PURE__ */ new Map()}
|
|
1183
|
-
__init12() {this._patterns = new (0,
|
|
1184
|
+
__init12() {this._patterns = new (0, _chunkBNTVE7RQcjs.LruMap)(PATTERN_CACHE_SIZE)}
|
|
1184
1185
|
|
|
1185
1186
|
|
|
1186
1187
|
|
|
@@ -1198,7 +1199,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1198
1199
|
on_init
|
|
1199
1200
|
}) {;_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);
|
|
1200
1201
|
this._key = shard ? `${registry_key(registry.events)}:${[...shard].sort().join(",")}` : registry_key(registry.events);
|
|
1201
|
-
this._dynamic_subscriptions = new (0,
|
|
1202
|
+
this._dynamic_subscriptions = new (0, _chunkBNTVE7RQcjs.LruMap)(max_subscribed_streams);
|
|
1202
1203
|
this._registry = registry;
|
|
1203
1204
|
this._declared_lanes = declared_lanes;
|
|
1204
1205
|
this._static_targets = static_targets;
|
|
@@ -1256,7 +1257,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1256
1257
|
/** Would the target's own `fetch` (filtered by `source`) return this event? */
|
|
1257
1258
|
_in_fetch_window(source, stream) {
|
|
1258
1259
|
if (source === void 0 || source === stream) return true;
|
|
1259
|
-
if (
|
|
1260
|
+
if (_chunkBNTVE7RQcjs.is_literal_source.call(void 0, source)) return false;
|
|
1260
1261
|
let pattern = this._patterns.get(source);
|
|
1261
1262
|
if (!pattern) {
|
|
1262
1263
|
pattern = new RegExp(source);
|
|
@@ -1265,9 +1266,9 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1265
1266
|
return pattern.test(stream);
|
|
1266
1267
|
}
|
|
1267
1268
|
/** Scan past the checkpoint, subscribe new targets and raise their work marks. */
|
|
1268
|
-
async correlate(
|
|
1269
|
+
async correlate(limit, lease = false) {
|
|
1269
1270
|
if (this._restoring) return { kind: "idle", last_id: this._checkpoint };
|
|
1270
|
-
const pass = this._scan(
|
|
1271
|
+
const pass = this._scan(limit, lease);
|
|
1271
1272
|
this._passes.add(pass);
|
|
1272
1273
|
try {
|
|
1273
1274
|
return await pass;
|
|
@@ -1275,7 +1276,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1275
1276
|
this._passes.delete(pass);
|
|
1276
1277
|
}
|
|
1277
1278
|
}
|
|
1278
|
-
async _scan(
|
|
1279
|
+
async _scan(limit, lease) {
|
|
1279
1280
|
await this._init();
|
|
1280
1281
|
const epoch = this._epoch;
|
|
1281
1282
|
const idle = () => ({
|
|
@@ -1299,7 +1300,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1299
1300
|
const correlated = /* @__PURE__ */ new Map();
|
|
1300
1301
|
let last_id = after;
|
|
1301
1302
|
let stopped = false;
|
|
1302
|
-
const found = await
|
|
1303
|
+
const found = await _chunkBNTVE7RQcjs.store.call(void 0, ).query(
|
|
1303
1304
|
(event) => {
|
|
1304
1305
|
if (stopped) return;
|
|
1305
1306
|
const register = this._registry.events[event.name];
|
|
@@ -1344,9 +1345,9 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1344
1345
|
correlated_at: void 0
|
|
1345
1346
|
};
|
|
1346
1347
|
const seen_in_scan = correlated.has(resolved.target);
|
|
1347
|
-
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _61 => _61.lane])), () => (
|
|
1348
|
+
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _61 => _61.lane])), () => ( _chunkL66OOP2Fcjs.DEFAULT_LANE));
|
|
1348
1349
|
const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _62 => _62.priority]);
|
|
1349
|
-
const resolved_lane = _nullishCoalesce(lane, () => (
|
|
1350
|
+
const resolved_lane = _nullishCoalesce(lane, () => ( _chunkL66OOP2Fcjs.DEFAULT_LANE));
|
|
1350
1351
|
if (held_priority === priority && held_lane !== resolved_lane)
|
|
1351
1352
|
report_lane_conflict(
|
|
1352
1353
|
this._reported,
|
|
@@ -1370,7 +1371,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1370
1371
|
},
|
|
1371
1372
|
// Resolvers see `pii: null`: correlate runs actor-less, and one
|
|
1372
1373
|
// undecryptable row would otherwise stop every stream's reactions.
|
|
1373
|
-
{ after, limit
|
|
1374
|
+
{ after, limit, with_pii: false }
|
|
1374
1375
|
);
|
|
1375
1376
|
if (this._declared_lanes.size > 1) await this._recall(correlated);
|
|
1376
1377
|
const read = last_id > after;
|
|
@@ -1409,7 +1410,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1409
1410
|
return { kind: "scanned", last_id, subscribed, marked, read };
|
|
1410
1411
|
}
|
|
1411
1412
|
this._checkpoint = last_id;
|
|
1412
|
-
if (!stopped && found !==
|
|
1413
|
+
if (!stopped && found !== limit) this._lowered = raised;
|
|
1413
1414
|
return { kind: "scanned", last_id, subscribed: 0, marked: 0, read };
|
|
1414
1415
|
}
|
|
1415
1416
|
/**
|
|
@@ -1422,7 +1423,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1422
1423
|
await Promise.all(
|
|
1423
1424
|
missed.map(async ([stream, entry]) => {
|
|
1424
1425
|
let row;
|
|
1425
|
-
await
|
|
1426
|
+
await _chunkBNTVE7RQcjs.store.call(void 0, ).query_streams(
|
|
1426
1427
|
(position) => {
|
|
1427
1428
|
row = position;
|
|
1428
1429
|
},
|
|
@@ -1434,8 +1435,8 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1434
1435
|
lane: row.lane
|
|
1435
1436
|
});
|
|
1436
1437
|
if (entry.priority > row.priority) return;
|
|
1437
|
-
const held_lane = _nullishCoalesce(row.lane, () => (
|
|
1438
|
-
const resolved_lane = _nullishCoalesce(entry.lane, () => (
|
|
1438
|
+
const held_lane = _nullishCoalesce(row.lane, () => ( _chunkL66OOP2Fcjs.DEFAULT_LANE));
|
|
1439
|
+
const resolved_lane = _nullishCoalesce(entry.lane, () => ( _chunkL66OOP2Fcjs.DEFAULT_LANE));
|
|
1439
1440
|
if (entry.priority === row.priority && held_lane !== resolved_lane)
|
|
1440
1441
|
report_lane_conflict(
|
|
1441
1442
|
this._reported,
|
|
@@ -1461,7 +1462,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1461
1462
|
millis: 0
|
|
1462
1463
|
});
|
|
1463
1464
|
} catch (error) {
|
|
1464
|
-
|
|
1465
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).warn(
|
|
1465
1466
|
`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)}`
|
|
1466
1467
|
);
|
|
1467
1468
|
}
|
|
@@ -1614,14 +1615,14 @@ function compute_lag_lead_ratio(handled, lagging, leading) {
|
|
|
1614
1615
|
}
|
|
1615
1616
|
|
|
1616
1617
|
// src/internal/drain-ops.ts
|
|
1617
|
-
var claim = (lagging, leading, by, millis, lane) =>
|
|
1618
|
+
var claim = (lagging, leading, by, millis, lane) => _chunkBNTVE7RQcjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
|
|
1618
1619
|
async function fetch(leased, eventLimit) {
|
|
1619
1620
|
return Promise.all(
|
|
1620
1621
|
leased.map(async ({ stream, source, at, lagging }) => {
|
|
1621
1622
|
const events = [];
|
|
1622
|
-
const stream_exact = source !== void 0 &&
|
|
1623
|
+
const stream_exact = source !== void 0 && _chunkBNTVE7RQcjs.is_literal_source.call(void 0, source) ? true : void 0;
|
|
1623
1624
|
try {
|
|
1624
|
-
await
|
|
1625
|
+
await _chunkBNTVE7RQcjs.store.call(void 0, ).query((e) => events.push(e), {
|
|
1625
1626
|
stream: source,
|
|
1626
1627
|
stream_exact,
|
|
1627
1628
|
after: at,
|
|
@@ -1641,30 +1642,46 @@ async function fetch(leased, eventLimit) {
|
|
|
1641
1642
|
})
|
|
1642
1643
|
);
|
|
1643
1644
|
}
|
|
1644
|
-
var ack = (leases) =>
|
|
1645
|
-
var block = (leases) =>
|
|
1646
|
-
var subscribe = (streams, correlated_at, correlator) =>
|
|
1645
|
+
var ack = (leases) => _chunkBNTVE7RQcjs.store.call(void 0, ).ack(leases);
|
|
1646
|
+
var block = (leases) => _chunkBNTVE7RQcjs.store.call(void 0, ).block(leases);
|
|
1647
|
+
var subscribe = (streams, correlated_at, correlator) => _chunkBNTVE7RQcjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
|
|
1647
1648
|
|
|
1648
1649
|
// src/internal/event-sourcing.ts
|
|
1649
1650
|
var _actpatch = require('@rotorsoft/act-patch');
|
|
1651
|
+
var _zod2 = require('zod');
|
|
1650
1652
|
var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
|
|
1651
|
-
var
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1653
|
+
var value_at = (value, path) => path.reduce(
|
|
1654
|
+
(at, key) => _optionalChain([at, 'optionalAccess', _67 => _67[key]]),
|
|
1655
|
+
value
|
|
1656
|
+
);
|
|
1657
|
+
var check_invariants = (target, state2, schema, pii_aware) => {
|
|
1658
|
+
let result;
|
|
1659
|
+
try {
|
|
1660
|
+
result = schema.safeParse(state2);
|
|
1661
|
+
} catch (error) {
|
|
1662
|
+
throw new (0, _chunkL66OOP2Fcjs.ValidationError)(target, state2, error);
|
|
1663
|
+
}
|
|
1664
|
+
if (result.success) return;
|
|
1665
|
+
const issues = pii_aware ? result.error.issues.filter((issue) => {
|
|
1666
|
+
const value = value_at(state2, issue.path);
|
|
1667
|
+
return value !== _chunkL66OOP2Fcjs.REDACTED && value !== _chunkL66OOP2Fcjs.SHREDDED;
|
|
1668
|
+
}) : result.error.issues;
|
|
1669
|
+
if (issues.length)
|
|
1670
|
+
throw new (0, _chunkL66OOP2Fcjs.ValidationError)(
|
|
1671
|
+
target,
|
|
1672
|
+
state2,
|
|
1673
|
+
_zod2.prettifyError.call(void 0, new (0, _zod2.ZodError)(issues))
|
|
1674
|
+
);
|
|
1658
1675
|
};
|
|
1659
1676
|
var DEFAULT_BATCH = 500;
|
|
1660
|
-
var cache_put = (stream, entry) =>
|
|
1661
|
-
(err) =>
|
|
1677
|
+
var cache_put = (stream, entry) => _chunkBNTVE7RQcjs.cache.call(void 0, ).set(stream, entry).catch(
|
|
1678
|
+
(err) => _chunkBNTVE7RQcjs.log.call(void 0, ).warn(
|
|
1662
1679
|
err,
|
|
1663
1680
|
"cache set skipped; the next load re-folds from the store"
|
|
1664
1681
|
)
|
|
1665
1682
|
);
|
|
1666
|
-
var cache_drop = (stream) =>
|
|
1667
|
-
(err) =>
|
|
1683
|
+
var cache_drop = (stream) => _chunkBNTVE7RQcjs.cache.call(void 0, ).invalidate(stream).catch(
|
|
1684
|
+
(err) => _chunkBNTVE7RQcjs.log.call(void 0, ).warn(
|
|
1668
1685
|
err,
|
|
1669
1686
|
"cache invalidate skipped; a stale checkpoint re-folds from its event_id"
|
|
1670
1687
|
)
|
|
@@ -1672,9 +1689,9 @@ var cache_drop = (stream) => _chunkGBAMBUDNcjs.cache.call(void 0, ).invalidate(s
|
|
|
1672
1689
|
async function snap(snapshot) {
|
|
1673
1690
|
const { id, stream, name, meta, version } = snapshot.event;
|
|
1674
1691
|
try {
|
|
1675
|
-
const [committed] = await
|
|
1692
|
+
const [committed] = await _chunkBNTVE7RQcjs.store.call(void 0, ).commit(
|
|
1676
1693
|
stream,
|
|
1677
|
-
[{ name:
|
|
1694
|
+
[{ name: _chunkL66OOP2Fcjs.SNAP_EVENT, data: snapshot.state }],
|
|
1678
1695
|
{
|
|
1679
1696
|
correlation: meta.correlation,
|
|
1680
1697
|
causation: { event: { id, name, stream } }
|
|
@@ -1685,22 +1702,22 @@ async function snap(snapshot) {
|
|
|
1685
1702
|
return committed;
|
|
1686
1703
|
} catch (error) {
|
|
1687
1704
|
const reason = error instanceof Error ? error.message : String(error);
|
|
1688
|
-
|
|
1705
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).warn(
|
|
1689
1706
|
`Snapshot write failed on stream "${stream}": ${reason} \u2014 cold starts will replay full history until snapshots succeed.`
|
|
1690
1707
|
);
|
|
1691
1708
|
}
|
|
1692
1709
|
}
|
|
1693
1710
|
async function tombstone(stream, expectedVersion, correlation) {
|
|
1694
1711
|
try {
|
|
1695
|
-
const [committed] = await
|
|
1712
|
+
const [committed] = await _chunkBNTVE7RQcjs.store.call(void 0, ).commit(
|
|
1696
1713
|
stream,
|
|
1697
|
-
[{ name:
|
|
1714
|
+
[{ name: _chunkL66OOP2Fcjs.TOMBSTONE_EVENT, data: {} }],
|
|
1698
1715
|
{ correlation, causation: {} },
|
|
1699
1716
|
expectedVersion
|
|
1700
1717
|
);
|
|
1701
1718
|
return committed;
|
|
1702
1719
|
} catch (error) {
|
|
1703
|
-
if (error instanceof
|
|
1720
|
+
if (error instanceof _chunkL66OOP2Fcjs.ConcurrencyError) return void 0;
|
|
1704
1721
|
throw error;
|
|
1705
1722
|
}
|
|
1706
1723
|
}
|
|
@@ -1730,9 +1747,9 @@ async function scan(source, opts = {}, callback) {
|
|
|
1730
1747
|
if (drop_closed_streams) {
|
|
1731
1748
|
await source.query(
|
|
1732
1749
|
(e) => {
|
|
1733
|
-
if (e.name ===
|
|
1750
|
+
if (e.name === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT) closed_streams.add(e.stream);
|
|
1734
1751
|
},
|
|
1735
|
-
{ names: [
|
|
1752
|
+
{ names: [_chunkL66OOP2Fcjs.TOMBSTONE_EVENT] }
|
|
1736
1753
|
);
|
|
1737
1754
|
}
|
|
1738
1755
|
let max_id;
|
|
@@ -1754,16 +1771,16 @@ async function scan(source, opts = {}, callback) {
|
|
|
1754
1771
|
if (!is_valid(event))
|
|
1755
1772
|
throw new Error(`Invalid event at index ${processed}`);
|
|
1756
1773
|
if (on_progress) on_progress({ processed, id: event.id, max_id });
|
|
1757
|
-
if (drop_snapshots && event.name ===
|
|
1774
|
+
if (drop_snapshots && event.name === _chunkL66OOP2Fcjs.SNAP_EVENT) {
|
|
1758
1775
|
dropped_snaps++;
|
|
1759
1776
|
return;
|
|
1760
1777
|
}
|
|
1761
|
-
if (closed_streams.has(event.stream) && event.name !==
|
|
1778
|
+
if (closed_streams.has(event.stream) && event.name !== _chunkL66OOP2Fcjs.TOMBSTONE_EVENT) {
|
|
1762
1779
|
dropped_closed++;
|
|
1763
1780
|
return;
|
|
1764
1781
|
}
|
|
1765
1782
|
let migrated = event;
|
|
1766
|
-
const migration = _optionalChain([event_migrations, 'optionalAccess',
|
|
1783
|
+
const migration = _optionalChain([event_migrations, 'optionalAccess', _68 => _68[event.name]]);
|
|
1767
1784
|
if (migration) {
|
|
1768
1785
|
const old_data = migration.from_schema.parse(event.data);
|
|
1769
1786
|
const new_data = migration.migrate(old_data);
|
|
@@ -1785,7 +1802,7 @@ async function scan(source, opts = {}, callback) {
|
|
|
1785
1802
|
return;
|
|
1786
1803
|
}
|
|
1787
1804
|
let remapped = migrated;
|
|
1788
|
-
const caused_by = _optionalChain([migrated, 'access',
|
|
1805
|
+
const caused_by = _optionalChain([migrated, 'access', _69 => _69.meta, 'access', _70 => _70.causation, 'access', _71 => _71.event, 'optionalAccess', _72 => _72.id]);
|
|
1789
1806
|
if (caused_by !== void 0) {
|
|
1790
1807
|
const new_caused_by = id_map.get(caused_by);
|
|
1791
1808
|
if (new_caused_by !== void 0 && new_caused_by !== caused_by) {
|
|
@@ -1825,17 +1842,17 @@ async function scan(source, opts = {}, callback) {
|
|
|
1825
1842
|
async function load(me, target, callback, patch_fn = bare_patch) {
|
|
1826
1843
|
const { stream, actor, asOf } = target;
|
|
1827
1844
|
const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
|
|
1828
|
-
const cached = time_travel ? void 0 : await
|
|
1845
|
+
const cached = time_travel ? void 0 : await _chunkBNTVE7RQcjs.cache.call(void 0, ).get(stream);
|
|
1829
1846
|
const cache_hit = !!cached;
|
|
1830
|
-
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1831
|
-
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1832
|
-
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1847
|
+
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _73 => _73.state]), () => ( (me.init ? me.init() : {})));
|
|
1848
|
+
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _74 => _74.patches]), () => ( 0));
|
|
1849
|
+
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _75 => _75.snaps]), () => ( 0));
|
|
1833
1850
|
let replayed = 0;
|
|
1834
1851
|
let event;
|
|
1835
|
-
await
|
|
1852
|
+
await _chunkBNTVE7RQcjs.store.call(void 0, ).query(
|
|
1836
1853
|
(raw) => {
|
|
1837
1854
|
event = me.view(raw, actor);
|
|
1838
|
-
if (event.name ===
|
|
1855
|
+
if (event.name === _chunkL66OOP2Fcjs.SNAP_EVENT) {
|
|
1839
1856
|
state2 = event.data;
|
|
1840
1857
|
snaps++;
|
|
1841
1858
|
patches = 0;
|
|
@@ -1844,12 +1861,12 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1844
1861
|
state2 = patch_fn(me, state2, me.patch[event.name](event, state2), event);
|
|
1845
1862
|
patches++;
|
|
1846
1863
|
replayed++;
|
|
1847
|
-
} else if (event.name !==
|
|
1848
|
-
|
|
1864
|
+
} else if (event.name !== _chunkL66OOP2Fcjs.TOMBSTONE_EVENT) {
|
|
1865
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).warn(
|
|
1849
1866
|
`Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
|
|
1850
1867
|
);
|
|
1851
1868
|
}
|
|
1852
|
-
_optionalChain([callback, 'optionalCall',
|
|
1869
|
+
_optionalChain([callback, 'optionalCall', _76 => _76({
|
|
1853
1870
|
event,
|
|
1854
1871
|
state: state2,
|
|
1855
1872
|
version: event.version,
|
|
@@ -1869,7 +1886,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1869
1886
|
...cached ? { after: cached.event_id, with_snaps: true } : { ...time_travel ? {} : { with_snaps: true }, ...asOf }
|
|
1870
1887
|
}
|
|
1871
1888
|
);
|
|
1872
|
-
const head_is_tombstone = _optionalChain([event, 'optionalAccess',
|
|
1889
|
+
const head_is_tombstone = _optionalChain([event, 'optionalAccess', _77 => _77.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT;
|
|
1873
1890
|
if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
|
|
1874
1891
|
await cache_put(stream, {
|
|
1875
1892
|
stream,
|
|
@@ -1883,9 +1900,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1883
1900
|
return {
|
|
1884
1901
|
event,
|
|
1885
1902
|
state: state2,
|
|
1886
|
-
version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess',
|
|
1903
|
+
version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _78 => _78.version]), () => ( _optionalChain([cached, 'optionalAccess', _79 => _79.version]))), () => ( -1)),
|
|
1887
1904
|
// Captured with `state`, so consumers never race a separate cache lookup.
|
|
1888
|
-
id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess',
|
|
1905
|
+
id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _80 => _80.id]), () => ( _optionalChain([cached, 'optionalAccess', _81 => _81.event_id]))), () => ( -1)),
|
|
1889
1906
|
patches,
|
|
1890
1907
|
snaps,
|
|
1891
1908
|
cache_hit,
|
|
@@ -1895,11 +1912,11 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1895
1912
|
async function action(me, action2, target, payload, options, patch_fn = bare_patch) {
|
|
1896
1913
|
const { stream, expectedVersion, actor } = target;
|
|
1897
1914
|
if (!stream) throw new Error("Missing target stream");
|
|
1898
|
-
const reactingTo = _optionalChain([options, 'optionalAccess',
|
|
1899
|
-
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1900
|
-
const validated =
|
|
1901
|
-
const opts = _optionalChain([me, 'access',
|
|
1902
|
-
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1915
|
+
const reactingTo = _optionalChain([options, 'optionalAccess', _82 => _82.reactingTo]);
|
|
1916
|
+
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _83 => _83.correlator]), () => ( default_correlator));
|
|
1917
|
+
const validated = _chunkBNTVE7RQcjs.validate.call(void 0, action2, payload, me.actions[action2]);
|
|
1918
|
+
const opts = _optionalChain([me, 'access', _84 => _84.options, 'optionalAccess', _85 => _85[action2]]);
|
|
1919
|
+
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _86 => _86.maxRetries]), () => ( 0));
|
|
1903
1920
|
for (let attempt = 0; ; attempt++) {
|
|
1904
1921
|
try {
|
|
1905
1922
|
const snapshot = await load(
|
|
@@ -1908,41 +1925,38 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1908
1925
|
void 0,
|
|
1909
1926
|
patch_fn
|
|
1910
1927
|
);
|
|
1911
|
-
if (_optionalChain([snapshot, 'access',
|
|
1912
|
-
throw new (0,
|
|
1928
|
+
if (_optionalChain([snapshot, 'access', _87 => _87.event, 'optionalAccess', _88 => _88.name]) === _chunkL66OOP2Fcjs.TOMBSTONE_EVENT)
|
|
1929
|
+
throw new (0, _chunkL66OOP2Fcjs.StreamClosedError)(stream);
|
|
1913
1930
|
const expected = _nullishCoalesce(expectedVersion, () => ( (snapshot.version >= 0 ? snapshot.version : void 0)));
|
|
1914
|
-
for (const { valid
|
|
1915
|
-
if (!
|
|
1916
|
-
throw new (0,
|
|
1931
|
+
for (const { valid, description } of _nullishCoalesce(_optionalChain([me, 'access', _89 => _89.given, 'optionalAccess', _90 => _90[action2]]), () => ( [])))
|
|
1932
|
+
if (!valid(snapshot.state, actor))
|
|
1933
|
+
throw new (0, _chunkL66OOP2Fcjs.InvariantError)(
|
|
1917
1934
|
action2,
|
|
1918
1935
|
validated,
|
|
1919
1936
|
target,
|
|
1920
1937
|
snapshot,
|
|
1921
1938
|
description
|
|
1922
1939
|
);
|
|
1923
|
-
for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access',
|
|
1940
|
+
for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _91 => _91.requires, 'optionalAccess', _92 => _92[action2]]), () => ( [])))
|
|
1924
1941
|
if (!holds(validated, snapshot.state, actor))
|
|
1925
|
-
throw new (0,
|
|
1942
|
+
throw new (0, _chunkL66OOP2Fcjs.PreconditionError)(
|
|
1926
1943
|
action2,
|
|
1927
1944
|
validated,
|
|
1928
1945
|
target,
|
|
1929
1946
|
snapshot,
|
|
1930
|
-
description
|
|
1931
|
-
"precondition"
|
|
1947
|
+
description
|
|
1932
1948
|
);
|
|
1933
1949
|
const result = me.on[action2](validated, snapshot, target);
|
|
1934
|
-
if (!result)
|
|
1935
|
-
if (Array.isArray(result) && result.length === 0) {
|
|
1950
|
+
if (!result || Array.isArray(result) && !result.length)
|
|
1936
1951
|
return [snapshot];
|
|
1937
|
-
}
|
|
1938
1952
|
const tuples = Array.isArray(result[0]) ? result : [result];
|
|
1939
|
-
const
|
|
1953
|
+
const events = tuples.map(([name, data]) => ({
|
|
1940
1954
|
name,
|
|
1941
|
-
data:
|
|
1955
|
+
data: _chunkBNTVE7RQcjs.validate.call(void 0, name, data, me.events[name])
|
|
1942
1956
|
}));
|
|
1943
|
-
const emitted =
|
|
1957
|
+
const emitted = events.map((e) => me.message(e));
|
|
1944
1958
|
const meta = {
|
|
1945
|
-
correlation: _optionalChain([reactingTo, 'optionalAccess',
|
|
1959
|
+
correlation: _optionalChain([reactingTo, 'optionalAccess', _93 => _93.meta, 'access', _94 => _94.correlation]) || correlator({
|
|
1946
1960
|
action: action2,
|
|
1947
1961
|
state: me.name,
|
|
1948
1962
|
stream,
|
|
@@ -1961,9 +1975,31 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1961
1975
|
} : void 0
|
|
1962
1976
|
}
|
|
1963
1977
|
};
|
|
1978
|
+
let { state: state2, patches } = snapshot;
|
|
1979
|
+
const created = /* @__PURE__ */ new Date();
|
|
1980
|
+
const folded = events.map((e, i) => {
|
|
1981
|
+
const event = {
|
|
1982
|
+
...e,
|
|
1983
|
+
id: -1,
|
|
1984
|
+
stream,
|
|
1985
|
+
version: snapshot.version + i + 1,
|
|
1986
|
+
created,
|
|
1987
|
+
meta
|
|
1988
|
+
};
|
|
1989
|
+
const patch2 = me.patch[event.name](event, state2);
|
|
1990
|
+
state2 = patch_fn(me, state2, patch2, event);
|
|
1991
|
+
patches++;
|
|
1992
|
+
return { state: state2, patch: patch2, patches };
|
|
1993
|
+
});
|
|
1994
|
+
check_invariants(
|
|
1995
|
+
`${me.name}.${action2}`,
|
|
1996
|
+
state2,
|
|
1997
|
+
me.state,
|
|
1998
|
+
me.pii_aware
|
|
1999
|
+
);
|
|
1964
2000
|
let committed;
|
|
1965
2001
|
try {
|
|
1966
|
-
committed = await
|
|
2002
|
+
committed = await _chunkBNTVE7RQcjs.store.call(void 0, ).commit(
|
|
1967
2003
|
stream,
|
|
1968
2004
|
emitted,
|
|
1969
2005
|
meta,
|
|
@@ -1972,38 +2008,31 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1972
2008
|
reactingTo ? expectedVersion : expected
|
|
1973
2009
|
);
|
|
1974
2010
|
} catch (error) {
|
|
1975
|
-
if (error instanceof
|
|
2011
|
+
if (error instanceof _chunkL66OOP2Fcjs.ConcurrencyError) void cache_drop(stream);
|
|
1976
2012
|
throw error;
|
|
1977
2013
|
}
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
patches
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
patches,
|
|
1990
|
-
snaps: snapshot.snaps,
|
|
1991
|
-
patch: p,
|
|
1992
|
-
cache_hit: snapshot.cache_hit,
|
|
1993
|
-
replayed: snapshot.replayed
|
|
1994
|
-
};
|
|
1995
|
-
});
|
|
2014
|
+
const snapshots = committed.map((row, i) => ({
|
|
2015
|
+
event: { ...row, data: events[i].data },
|
|
2016
|
+
state: folded[i].state,
|
|
2017
|
+
version: row.version,
|
|
2018
|
+
id: row.id,
|
|
2019
|
+
patches: folded[i].patches,
|
|
2020
|
+
snaps: snapshot.snaps,
|
|
2021
|
+
patch: folded[i].patch,
|
|
2022
|
+
cache_hit: snapshot.cache_hit,
|
|
2023
|
+
replayed: snapshot.replayed
|
|
2024
|
+
}));
|
|
1996
2025
|
const last = snapshots.at(-1);
|
|
1997
2026
|
const contiguous = committed[0].version === snapshot.version + 1;
|
|
1998
|
-
const snapped = contiguous && _optionalChain([me, 'access',
|
|
2027
|
+
const snapped = contiguous && _optionalChain([me, 'access', _95 => _95.snap, 'optionalCall', _96 => _96(last)]);
|
|
1999
2028
|
const snap_event = snapped ? await snap(last) : void 0;
|
|
2000
2029
|
if (!me.pii_aware) {
|
|
2001
2030
|
if (contiguous)
|
|
2002
2031
|
void cache_put(stream, {
|
|
2003
2032
|
stream,
|
|
2004
2033
|
state: last.state,
|
|
2005
|
-
version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess',
|
|
2006
|
-
event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess',
|
|
2034
|
+
version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _97 => _97.version]), () => ( last.event.version)),
|
|
2035
|
+
event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _98 => _98.id]), () => ( last.event.id)),
|
|
2007
2036
|
patches: snap_event ? 0 : last.patches,
|
|
2008
2037
|
snaps: snap_event ? last.snaps + 1 : last.snaps
|
|
2009
2038
|
});
|
|
@@ -2011,19 +2040,19 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
2011
2040
|
}
|
|
2012
2041
|
return snapshots;
|
|
2013
2042
|
} catch (error) {
|
|
2014
|
-
if (!(error instanceof
|
|
2043
|
+
if (!(error instanceof _chunkL66OOP2Fcjs.ConcurrencyError)) throw error;
|
|
2015
2044
|
if (expectedVersion !== void 0) throw error;
|
|
2016
2045
|
if (attempt >= max_retries) throw error;
|
|
2017
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
2046
|
+
if (_optionalChain([opts, 'optionalAccess', _99 => _99.backoff])) {
|
|
2018
2047
|
const delay_ms = compute_backoff_delay(attempt, opts.backoff);
|
|
2019
|
-
if (delay_ms > 0) await
|
|
2048
|
+
if (delay_ms > 0) await _chunkBNTVE7RQcjs.sleep.call(void 0, delay_ms);
|
|
2020
2049
|
}
|
|
2021
2050
|
}
|
|
2022
2051
|
}
|
|
2023
2052
|
}
|
|
2024
2053
|
|
|
2025
2054
|
// src/internal/tracing.ts
|
|
2026
|
-
var PRETTY =
|
|
2055
|
+
var PRETTY = _chunkBNTVE7RQcjs.config.call(void 0, ).env !== "production";
|
|
2027
2056
|
var C_BLUE = "\x1B[38;5;39m";
|
|
2028
2057
|
var C_ORANGE = "\x1B[38;5;208m";
|
|
2029
2058
|
var C_GREEN = "\x1B[38;5;42m";
|
|
@@ -2069,9 +2098,9 @@ var as_of_marker = (asOf) => {
|
|
|
2069
2098
|
return parts.length ? ` (as-of ${parts.join(" ")})` : " (as-of)";
|
|
2070
2099
|
};
|
|
2071
2100
|
var traced = (inner, exit, entry) => (async (...args) => {
|
|
2072
|
-
_optionalChain([entry, 'optionalCall',
|
|
2101
|
+
_optionalChain([entry, 'optionalCall', _100 => _100(...args)]);
|
|
2073
2102
|
const result = await inner(...args);
|
|
2074
|
-
_optionalChain([exit, 'optionalCall',
|
|
2103
|
+
_optionalChain([exit, 'optionalCall', _101 => _101(result, ...args)]);
|
|
2075
2104
|
return result;
|
|
2076
2105
|
});
|
|
2077
2106
|
function build_es(logger, correlator = default_correlator, patch_fn = bare_patch) {
|
|
@@ -2156,7 +2185,7 @@ function build_drain(logger) {
|
|
|
2156
2185
|
subscribe: logger.level !== "trace" ? subscribe : traced(subscribe, (result, streams) => {
|
|
2157
2186
|
if (!result.subscribed) return;
|
|
2158
2187
|
const lanes = new Set(streams.map((s) => _nullishCoalesce(s.lane, () => ( "default"))));
|
|
2159
|
-
const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access',
|
|
2188
|
+
const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _102 => _102[0], 'optionalAccess', _103 => _103.lane]) : void 0;
|
|
2160
2189
|
const data = streams.map(
|
|
2161
2190
|
({ stream, lane }) => uniform_lane || !lane || lane === "default" ? hue(C_STREAM, stream) : `${hue(C_STREAM, stream)}${dim(`[${lane}]`)}`
|
|
2162
2191
|
).join(" ");
|
|
@@ -2168,7 +2197,7 @@ function build_drain(logger) {
|
|
|
2168
2197
|
}
|
|
2169
2198
|
function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
2170
2199
|
if (logger.level !== "trace" || !leased.length) return;
|
|
2171
|
-
const lane = _optionalChain([leased, 'access',
|
|
2200
|
+
const lane = _optionalChain([leased, 'access', _104 => _104[0], 'optionalAccess', _105 => _105.lane]);
|
|
2172
2201
|
const fetch_by_stream = new Map(fetched.map((f) => [f.stream, f]));
|
|
2173
2202
|
const acked_by_stream = new Map(acked.map((a) => [a.stream, a.at]));
|
|
2174
2203
|
const blocked_by_stream = new Map(blocked.map((b) => [b.stream, b.error]));
|
|
@@ -2177,8 +2206,8 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
2177
2206
|
);
|
|
2178
2207
|
const detail = leased.map(({ stream, at, retry }) => {
|
|
2179
2208
|
const f = fetch_by_stream.get(stream);
|
|
2180
|
-
const key = _optionalChain([f, 'optionalAccess',
|
|
2181
|
-
const events = _optionalChain([f, 'optionalAccess',
|
|
2209
|
+
const key = _optionalChain([f, 'optionalAccess', _106 => _106.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
|
|
2210
|
+
const events = _optionalChain([f, 'optionalAccess', _107 => _107.events, 'access', _108 => _108.length]) ? ` ${dim(
|
|
2182
2211
|
`[${f.events.map(({ id, name }) => `#${id} ${String(name)}`).join(", ")}]`
|
|
2183
2212
|
)}` : "";
|
|
2184
2213
|
const acked_at = acked_by_stream.get(stream);
|
|
@@ -2206,10 +2235,10 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
2206
2235
|
|
|
2207
2236
|
// src/internal/drain-cycle.ts
|
|
2208
2237
|
function budget_exhausted(lease, options, store_failing) {
|
|
2209
|
-
if (store_failing || !_optionalChain([options, 'optionalAccess',
|
|
2238
|
+
if (store_failing || !_optionalChain([options, 'optionalAccess', _109 => _109.blockOnError]) || lease.retry <= options.maxRetries)
|
|
2210
2239
|
return void 0;
|
|
2211
2240
|
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.`;
|
|
2212
|
-
|
|
2241
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).error(error);
|
|
2213
2242
|
return { lease, handled: 0, acked_at: lease.at, error, block: true };
|
|
2214
2243
|
}
|
|
2215
2244
|
function fetch_failure_policy(registry) {
|
|
@@ -2225,13 +2254,13 @@ function fetch_failure_policy(registry) {
|
|
|
2225
2254
|
function finalize(lease, handled, at, error, options, logger, failed_at) {
|
|
2226
2255
|
if (!error) return { lease, handled, acked_at: at };
|
|
2227
2256
|
logger.error(error);
|
|
2228
|
-
const non_retryable = error instanceof
|
|
2257
|
+
const non_retryable = error instanceof _chunkL66OOP2Fcjs.NonRetryableError;
|
|
2229
2258
|
const block2 = options.blockOnError && (non_retryable || lease.retry >= options.maxRetries);
|
|
2230
2259
|
if (block2)
|
|
2231
2260
|
logger.error(
|
|
2232
2261
|
non_retryable ? `Blocking ${lease.stream} on non-retryable error.` : `Blocking ${lease.stream} after ${lease.retry} retries.`
|
|
2233
2262
|
);
|
|
2234
|
-
const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => (
|
|
2263
|
+
const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunkBNTVE7RQcjs.DEFAULT_BACKOFF)));
|
|
2235
2264
|
return {
|
|
2236
2265
|
lease,
|
|
2237
2266
|
handled,
|
|
@@ -2270,7 +2299,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
2270
2299
|
const fetched = await ops.fetch(leased, eventLimit);
|
|
2271
2300
|
const fetch_map = /* @__PURE__ */ new Map();
|
|
2272
2301
|
const fetch_window_at = fetched.reduce(
|
|
2273
|
-
(max, { at, events }) => Math.max(max, _optionalChain([events, 'access',
|
|
2302
|
+
(max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _110 => _110.at, 'call', _111 => _111(-1), 'optionalAccess', _112 => _112.id]) || at),
|
|
2274
2303
|
0
|
|
2275
2304
|
);
|
|
2276
2305
|
for (const f of fetched) {
|
|
@@ -2334,11 +2363,11 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
2334
2363
|
deps.logger
|
|
2335
2364
|
)
|
|
2336
2365
|
);
|
|
2337
|
-
const at = _optionalChain([entry, 'access',
|
|
2366
|
+
const at = _optionalChain([entry, 'access', _113 => _113.fetch, 'access', _114 => _114.events, 'access', _115 => _115.at, 'call', _116 => _116(-1), 'optionalAccess', _117 => _117.id]) || fetch_window_at;
|
|
2338
2367
|
const { payloads } = entry;
|
|
2339
2368
|
const exhausted = budget_exhausted(
|
|
2340
2369
|
lease,
|
|
2341
|
-
_optionalChain([payloads, 'access',
|
|
2370
|
+
_optionalChain([payloads, 'access', _118 => _118[0], 'optionalAccess', _119 => _119.options]),
|
|
2342
2371
|
store_failing
|
|
2343
2372
|
);
|
|
2344
2373
|
if (exhausted) return Promise.resolve(exhausted);
|
|
@@ -2359,7 +2388,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
2359
2388
|
const acked = submitted.length ? await ops.ack(submitted) : [];
|
|
2360
2389
|
const expected = submitted.filter((l) => l.due === void 0).length;
|
|
2361
2390
|
if (acked.length < expected)
|
|
2362
|
-
|
|
2391
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).warn(
|
|
2363
2392
|
`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.`
|
|
2364
2393
|
);
|
|
2365
2394
|
const closeable = handled.filter((h) => h.close !== void 0).map((h) => h.close);
|
|
@@ -2427,7 +2456,7 @@ var DrainController = (_class5 = class {
|
|
|
2427
2456
|
}
|
|
2428
2457
|
/** This lane's configured lease, or `undefined`; the shutdown grace basis. */
|
|
2429
2458
|
get lease_millis() {
|
|
2430
|
-
return _optionalChain([this, 'access',
|
|
2459
|
+
return _optionalChain([this, 'access', _120 => _120._deps, 'access', _121 => _121.defaults, 'optionalAccess', _122 => _122.leaseMillis]);
|
|
2431
2460
|
}
|
|
2432
2461
|
get lane() {
|
|
2433
2462
|
return this._deps.lane;
|
|
@@ -2459,9 +2488,9 @@ var DrainController = (_class5 = class {
|
|
|
2459
2488
|
if (!this.armed || this._stopped || this._inflight)
|
|
2460
2489
|
return EMPTY_DRAIN;
|
|
2461
2490
|
const d = _nullishCoalesce(this._deps.defaults, () => ( {}));
|
|
2462
|
-
const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => (
|
|
2463
|
-
const eventLimit = _nullishCoalesce(options.eventLimit, () => (
|
|
2464
|
-
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => (
|
|
2491
|
+
const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunkBNTVE7RQcjs.DEFAULT_STREAM_LIMIT));
|
|
2492
|
+
const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkBNTVE7RQcjs.DEFAULT_EVENT_LIMIT));
|
|
2493
|
+
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkBNTVE7RQcjs.DEFAULT_LEASE_MILLIS));
|
|
2465
2494
|
if (this._deps.breaker.state(Date.now()) === "open")
|
|
2466
2495
|
return EMPTY_DRAIN;
|
|
2467
2496
|
const pass = this._pass(streamLimit, eventLimit, leaseMillis).finally(
|
|
@@ -2536,7 +2565,7 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
2536
2565
|
const { pii, ...rest } = event;
|
|
2537
2566
|
if (pii == null) {
|
|
2538
2567
|
const shredded = { ...data };
|
|
2539
|
-
for (const f of fields) shredded[f] =
|
|
2568
|
+
for (const f of fields) shredded[f] = _chunkL66OOP2Fcjs.SHREDDED;
|
|
2540
2569
|
return { ...rest, data: shredded };
|
|
2541
2570
|
}
|
|
2542
2571
|
const allowed = !!actor && !!predicate && predicate(event, actor);
|
|
@@ -2547,7 +2576,7 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
2547
2576
|
};
|
|
2548
2577
|
}
|
|
2549
2578
|
const redacted = { ...data };
|
|
2550
|
-
for (const f of fields) redacted[f] =
|
|
2579
|
+
for (const f of fields) redacted[f] = _chunkL66OOP2Fcjs.REDACTED;
|
|
2551
2580
|
return { ...rest, data: redacted };
|
|
2552
2581
|
}
|
|
2553
2582
|
var IDENTITY_GATE = (event) => event;
|
|
@@ -2569,7 +2598,7 @@ function pii_strip(event, fields) {
|
|
|
2569
2598
|
|
|
2570
2599
|
// src/internal/projection-fold.ts
|
|
2571
2600
|
var FOLD_RESET = /* @__PURE__ */ Symbol("act.fold.reset");
|
|
2572
|
-
function make_fold_handler(me, flush, config2, patch_fn
|
|
2601
|
+
function make_fold_handler(me, flush, config2, patch_fn, sensitive_fields) {
|
|
2573
2602
|
const load_me = {
|
|
2574
2603
|
...me,
|
|
2575
2604
|
view: (raw, actor) => {
|
|
@@ -2655,7 +2684,7 @@ function make_fold_handler(me, flush, config2, patch_fn = bare_patch, sensitive_
|
|
|
2655
2684
|
}
|
|
2656
2685
|
|
|
2657
2686
|
// src/internal/defer-config.ts
|
|
2658
|
-
|
|
2687
|
+
|
|
2659
2688
|
var DeferDurationSchema = _zod2.z.object({
|
|
2660
2689
|
days: _zod2.z.number().positive().optional(),
|
|
2661
2690
|
hours: _zod2.z.number().positive().optional(),
|
|
@@ -2684,7 +2713,7 @@ function make_deferred(handler, schedule) {
|
|
|
2684
2713
|
const call = handler;
|
|
2685
2714
|
const deferred = async (event, stream, app) => {
|
|
2686
2715
|
const when = typeof schedule === "function" ? schedule(event) : schedule;
|
|
2687
|
-
if (Date.now() < resolve_defer_at(when, event)) throw new (0,
|
|
2716
|
+
if (Date.now() < resolve_defer_at(when, event)) throw new (0, _chunkL66OOP2Fcjs.DeferSignal)(when);
|
|
2688
2717
|
return call(event, stream, app);
|
|
2689
2718
|
};
|
|
2690
2719
|
Object.defineProperty(deferred, "name", { value: handler.name });
|
|
@@ -2720,10 +2749,10 @@ var CloseSignal = class extends Error {
|
|
|
2720
2749
|
constructor(opts) {
|
|
2721
2750
|
super("reaction requested close");
|
|
2722
2751
|
this.name = "CloseSignal";
|
|
2723
|
-
this.stream = _optionalChain([opts, 'optionalAccess',
|
|
2724
|
-
this.archive = _optionalChain([opts, 'optionalAccess',
|
|
2725
|
-
this.at = _optionalChain([opts, 'optionalAccess',
|
|
2726
|
-
this.before = _optionalChain([opts, 'optionalAccess',
|
|
2752
|
+
this.stream = _optionalChain([opts, 'optionalAccess', _123 => _123.stream]);
|
|
2753
|
+
this.archive = _optionalChain([opts, 'optionalAccess', _124 => _124.archive]);
|
|
2754
|
+
this.at = _optionalChain([opts, 'optionalAccess', _125 => _125.at]);
|
|
2755
|
+
this.before = _optionalChain([opts, 'optionalAccess', _126 => _126.before]);
|
|
2727
2756
|
}
|
|
2728
2757
|
};
|
|
2729
2758
|
function build_handle(deps) {
|
|
@@ -2753,7 +2782,7 @@ function build_handle(deps) {
|
|
|
2753
2782
|
handled++;
|
|
2754
2783
|
}
|
|
2755
2784
|
} catch (error) {
|
|
2756
|
-
if (error instanceof
|
|
2785
|
+
if (error instanceof _chunkL66OOP2Fcjs.DeferSignal) {
|
|
2757
2786
|
let defer;
|
|
2758
2787
|
try {
|
|
2759
2788
|
defer = resolve_defer_at(error.when, event);
|
|
@@ -2870,7 +2899,7 @@ var SettleLoop = (_class6 = class {
|
|
|
2870
2899
|
this._pending = true;
|
|
2871
2900
|
return;
|
|
2872
2901
|
}
|
|
2873
|
-
const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
2902
|
+
const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.debounceMs]), () => ( this._default_debounce_ms));
|
|
2874
2903
|
const due = Date.now() + delay;
|
|
2875
2904
|
if (this._timer) {
|
|
2876
2905
|
if (due >= this._due) return;
|
|
@@ -2933,10 +2962,8 @@ var SettleLoop = (_class6 = class {
|
|
|
2933
2962
|
}, _class6);
|
|
2934
2963
|
|
|
2935
2964
|
// src/act.ts
|
|
2936
|
-
function validate_only_lanes(
|
|
2937
|
-
|
|
2938
|
-
const declared = /* @__PURE__ */ new Set(["default", ...lanes.map((l) => l.name)]);
|
|
2939
|
-
const unknown = options.onlyLanes.filter((l) => !declared.has(l));
|
|
2965
|
+
function validate_only_lanes(only, declared) {
|
|
2966
|
+
const unknown = (_nullishCoalesce(only, () => ( []))).filter((l) => !declared.includes(l));
|
|
2940
2967
|
if (unknown.length > 0)
|
|
2941
2968
|
throw new Error(
|
|
2942
2969
|
`ActOptions.onlyLanes references undeclared lane(s): ${unknown.map((l) => `"${l}"`).join(", ")}`
|
|
@@ -3019,7 +3046,7 @@ var Act = (_class7 = class {
|
|
|
3019
3046
|
/** Lanes to arm per event; `"all"` when a dynamic resolver hides the lane. */
|
|
3020
3047
|
|
|
3021
3048
|
|
|
3022
|
-
__init27() {this._logger =
|
|
3049
|
+
__init27() {this._logger = _chunkBNTVE7RQcjs.log.call(void 0, )}
|
|
3023
3050
|
/** This Act's ports: its own bag, or the singleton adapters. */
|
|
3024
3051
|
|
|
3025
3052
|
/** Runs a body so internal `store()`/`cache()` calls resolve to `_ports`. */
|
|
@@ -3040,10 +3067,10 @@ var Act = (_class7 = class {
|
|
|
3040
3067
|
this._batch_handlers = batch_handlers;
|
|
3041
3068
|
this._lanes = lanes;
|
|
3042
3069
|
this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
|
|
3043
|
-
validate_only_lanes(options,
|
|
3044
|
-
this._ports = _nullishCoalesce(options.scoped, () => (
|
|
3070
|
+
validate_only_lanes(options.onlyLanes, this._declared_lanes);
|
|
3071
|
+
this._ports = _nullishCoalesce(options.scoped, () => ( _chunkBNTVE7RQcjs.default_scope.call(void 0, )));
|
|
3045
3072
|
const ports = this._ports;
|
|
3046
|
-
this._scoped =
|
|
3073
|
+
this._scoped = _chunkBNTVE7RQcjs.make_run_scoped.call(void 0, {
|
|
3047
3074
|
// Getters, not a spread: the singletons resolve lazily, so a later
|
|
3048
3075
|
// `store(...)` / `cache(...)` still takes effect.
|
|
3049
3076
|
get store() {
|
|
@@ -3053,14 +3080,14 @@ var Act = (_class7 = class {
|
|
|
3053
3080
|
return ports.cache;
|
|
3054
3081
|
},
|
|
3055
3082
|
// Parsed per build, so a bad window throws on every build.
|
|
3056
|
-
autoclose_window:
|
|
3083
|
+
autoclose_window: _chunkBNTVE7RQcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
|
|
3057
3084
|
});
|
|
3058
3085
|
this._correlator = _nullishCoalesce(options.correlator, () => ( default_correlator));
|
|
3059
3086
|
this._es = build_es(this._logger, this._correlator, patch_fn);
|
|
3060
3087
|
this._cd = build_drain(this._logger);
|
|
3061
3088
|
const handle = build_handle({
|
|
3062
3089
|
logger: this._logger,
|
|
3063
|
-
reaction_scope:
|
|
3090
|
+
reaction_scope: _chunkBNTVE7RQcjs.make_reaction_scope.call(void 0, {
|
|
3064
3091
|
do: this.do.bind(this),
|
|
3065
3092
|
load: this.load.bind(this),
|
|
3066
3093
|
query: this.query.bind(this),
|
|
@@ -3082,7 +3109,7 @@ var Act = (_class7 = class {
|
|
|
3082
3109
|
handle,
|
|
3083
3110
|
handle_batch
|
|
3084
3111
|
);
|
|
3085
|
-
this._advise_orphaned_lanes(
|
|
3112
|
+
this._advise_orphaned_lanes();
|
|
3086
3113
|
this._audit_deps = this._build_audit_deps();
|
|
3087
3114
|
this._correlate = this._build_correlate(options, classification);
|
|
3088
3115
|
this._settle = this._build_settle(options);
|
|
@@ -3090,12 +3117,12 @@ var Act = (_class7 = class {
|
|
|
3090
3117
|
this._ports.store,
|
|
3091
3118
|
options.listen !== false
|
|
3092
3119
|
);
|
|
3093
|
-
|
|
3120
|
+
_chunkBNTVE7RQcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
|
|
3094
3121
|
}
|
|
3095
3122
|
/** Shared by drain, settle and autoclose; bad knobs throw at build. */
|
|
3096
3123
|
_build_breaker(options) {
|
|
3097
3124
|
return new CircuitBreaker(
|
|
3098
|
-
|
|
3125
|
+
_chunkBNTVE7RQcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
|
|
3099
3126
|
{
|
|
3100
3127
|
on_error: (error, circuit) => this._emit_error(error, circuit),
|
|
3101
3128
|
// When the cooldown elapses, settle once: its scan or claim is the
|
|
@@ -3107,7 +3134,7 @@ var Act = (_class7 = class {
|
|
|
3107
3134
|
/** Apps that declare no lanes pass no lane filter to `claim`. */
|
|
3108
3135
|
_build_drain_controllers(options, lanes, handle, handle_batch) {
|
|
3109
3136
|
const all_lanes = this._declared_lanes;
|
|
3110
|
-
const only_set = options.onlyLanes
|
|
3137
|
+
const only_set = _optionalChain([options, 'access', _128 => _128.onlyLanes, 'optionalAccess', _129 => _129.length]) ? new Set(options.onlyLanes) : void 0;
|
|
3111
3138
|
const active_lanes = only_set ? all_lanes.filter((n) => only_set.has(n)) : all_lanes;
|
|
3112
3139
|
const single_default_lane = lanes.length === 0;
|
|
3113
3140
|
const controllers = /* @__PURE__ */ new Map();
|
|
@@ -3129,7 +3156,7 @@ var Act = (_class7 = class {
|
|
|
3129
3156
|
try {
|
|
3130
3157
|
await this._run_close(targets);
|
|
3131
3158
|
} catch (error) {
|
|
3132
|
-
if (error instanceof
|
|
3159
|
+
if (error instanceof _chunkL66OOP2Fcjs.StoreError) throw error;
|
|
3133
3160
|
this._logger.error(
|
|
3134
3161
|
error,
|
|
3135
3162
|
`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.`
|
|
@@ -3144,15 +3171,14 @@ var Act = (_class7 = class {
|
|
|
3144
3171
|
leaseMillis: cfg.leaseMillis
|
|
3145
3172
|
}
|
|
3146
3173
|
});
|
|
3147
|
-
if (_optionalChain([cfg, 'optionalAccess',
|
|
3174
|
+
if (_optionalChain([cfg, 'optionalAccess', _130 => _130.cycleMs]) !== void 0 && this._drain)
|
|
3148
3175
|
controller.start(cfg.cycleMs);
|
|
3149
3176
|
controllers.set(name, controller);
|
|
3150
3177
|
}
|
|
3151
3178
|
return controllers;
|
|
3152
3179
|
}
|
|
3153
3180
|
/** One process can't see the cluster, so it reports its own lane gaps. */
|
|
3154
|
-
_advise_orphaned_lanes(
|
|
3155
|
-
if (!options.onlyLanes || options.onlyLanes.length === 0) return;
|
|
3181
|
+
_advise_orphaned_lanes() {
|
|
3156
3182
|
const active = new Set(this._drain_controllers.keys());
|
|
3157
3183
|
const orphaned = this._declared_lanes.filter((name) => !active.has(name));
|
|
3158
3184
|
if (orphaned.length === 0) return;
|
|
@@ -3164,7 +3190,7 @@ var Act = (_class7 = class {
|
|
|
3164
3190
|
/** Audit deps, built after the controllers so the lane set is final. */
|
|
3165
3191
|
_build_audit_deps() {
|
|
3166
3192
|
return {
|
|
3167
|
-
store:
|
|
3193
|
+
store: _chunkBNTVE7RQcjs.store,
|
|
3168
3194
|
event_to_state: this._event_to_state,
|
|
3169
3195
|
// Declared lanes, not this process's controllers: a lane another
|
|
3170
3196
|
// worker drains is not `unknown-lane`.
|
|
@@ -3177,7 +3203,7 @@ var Act = (_class7 = class {
|
|
|
3177
3203
|
registry: this.registry,
|
|
3178
3204
|
static_targets: classification.static_targets,
|
|
3179
3205
|
cd: this._cd,
|
|
3180
|
-
max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => (
|
|
3206
|
+
max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => ( _chunkL66OOP2Fcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS)),
|
|
3181
3207
|
// Declared lanes (not active ones): a lane another process claims is
|
|
3182
3208
|
// still a valid destination.
|
|
3183
3209
|
declared_lanes: new Set(this._declared_lanes),
|
|
@@ -3193,26 +3219,23 @@ var Act = (_class7 = class {
|
|
|
3193
3219
|
/** Cold start: an idle deferred stream still fires on time after a restart. */
|
|
3194
3220
|
async _seed_persisted_defers() {
|
|
3195
3221
|
const now = Date.now();
|
|
3196
|
-
await walk_streams(
|
|
3222
|
+
await walk_streams(_chunkBNTVE7RQcjs.store.call(void 0, ), (pos) => {
|
|
3197
3223
|
if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
|
|
3198
3224
|
const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
|
|
3199
|
-
_optionalChain([controller, 'optionalAccess',
|
|
3225
|
+
_optionalChain([controller, 'optionalAccess', _131 => _131.seed_defer, 'call', _132 => _132(pos.stream, pos.deferred_at)]);
|
|
3200
3226
|
});
|
|
3201
3227
|
}
|
|
3202
3228
|
_build_settle(options) {
|
|
3203
3229
|
return new SettleLoop(
|
|
3204
3230
|
{
|
|
3205
|
-
correlate: (q) => this._correlate_pass(
|
|
3206
|
-
{ ...q, limit: _nullishCoalesce(_nullishCoalesce(q.limit, () => ( this._poll_limit)), () => ( 100)) },
|
|
3207
|
-
true
|
|
3208
|
-
),
|
|
3231
|
+
correlate: (q) => this._correlate_pass(_nullishCoalesce(_nullishCoalesce(q.limit, () => ( this._poll_limit)), () => ( 100)), true),
|
|
3209
3232
|
// `settle()` validated the options, and `_schedule` skips writer-only
|
|
3210
3233
|
// instances, so the loop drains through the internal path.
|
|
3211
3234
|
drain: (o) => this._scoped(() => this._drain_all(o)),
|
|
3212
3235
|
on_settled: (drain) => this.emit("settled", drain),
|
|
3213
3236
|
breaker: this._breaker
|
|
3214
3237
|
},
|
|
3215
|
-
_nullishCoalesce(options.settleDebounceMs, () => (
|
|
3238
|
+
_nullishCoalesce(options.settleDebounceMs, () => ( _chunkL66OOP2Fcjs.DEFAULT_SETTLE_DEBOUNCE_MS))
|
|
3216
3239
|
);
|
|
3217
3240
|
}
|
|
3218
3241
|
|
|
@@ -3232,7 +3255,7 @@ var Act = (_class7 = class {
|
|
|
3232
3255
|
*/
|
|
3233
3256
|
shutdown(options) {
|
|
3234
3257
|
if (!this._shutdown_promise) {
|
|
3235
|
-
|
|
3258
|
+
_chunkBNTVE7RQcjs.resolveShutdownConfig.call(void 0, options);
|
|
3236
3259
|
this._shutdown_promise = (async () => {
|
|
3237
3260
|
this.stop_correlations();
|
|
3238
3261
|
this._settle.stop(true);
|
|
@@ -3240,7 +3263,7 @@ var Act = (_class7 = class {
|
|
|
3240
3263
|
for (const c of this._drain_controllers.values()) c.stop();
|
|
3241
3264
|
const disposer = await this._notify_disposer;
|
|
3242
3265
|
if (disposer) await disposer();
|
|
3243
|
-
await this._await_inflight(_optionalChain([options, 'optionalAccess',
|
|
3266
|
+
await this._await_inflight(_optionalChain([options, 'optionalAccess', _133 => _133.graceMs]));
|
|
3244
3267
|
await this._scoped(() => this._correlate.release_correlation());
|
|
3245
3268
|
this._emitter.removeAllListeners();
|
|
3246
3269
|
})();
|
|
@@ -3252,10 +3275,10 @@ var Act = (_class7 = class {
|
|
|
3252
3275
|
* default for none or 0, and for a running settle), capped.
|
|
3253
3276
|
*/
|
|
3254
3277
|
_derive_grace_ms(running, settling) {
|
|
3255
|
-
let max = settling ?
|
|
3278
|
+
let max = settling ? _chunkBNTVE7RQcjs.DEFAULT_LEASE_MILLIS : 0;
|
|
3256
3279
|
for (const c of running)
|
|
3257
|
-
max = Math.max(max, c.lease_millis ||
|
|
3258
|
-
return Math.min(max,
|
|
3280
|
+
max = Math.max(max, c.lease_millis || _chunkBNTVE7RQcjs.DEFAULT_LEASE_MILLIS);
|
|
3281
|
+
return Math.min(max, _chunkBNTVE7RQcjs.MAX_SHUTDOWN_GRACE_MS);
|
|
3259
3282
|
}
|
|
3260
3283
|
async _await_inflight(grace_ms) {
|
|
3261
3284
|
const running = [...this._drain_controllers.values()].filter(
|
|
@@ -3300,9 +3323,10 @@ var Act = (_class7 = class {
|
|
|
3300
3323
|
}
|
|
3301
3324
|
/**
|
|
3302
3325
|
* Executes an action: validates the payload, loads the state, checks its
|
|
3303
|
-
*
|
|
3304
|
-
*
|
|
3305
|
-
*
|
|
3326
|
+
* preconditions, runs the handler, folds the events it emits, checks the
|
|
3327
|
+
* state's invariants (its schema) on the result, and commits them with
|
|
3328
|
+
* optimistic concurrency on the stream. The reactions to those events
|
|
3329
|
+
* settle on their own (unless `autoSettle: false`).
|
|
3306
3330
|
*
|
|
3307
3331
|
* @template TKey - Action name from registered actions
|
|
3308
3332
|
* @param action - The name of the action to execute
|
|
@@ -3313,8 +3337,9 @@ var Act = (_class7 = class {
|
|
|
3313
3337
|
* framework or orchestrator-level correlator for this call only.
|
|
3314
3338
|
* @returns Array of snapshots for all affected states (usually one)
|
|
3315
3339
|
*
|
|
3316
|
-
* @throws {ValidationError} If payload doesn't match action schema
|
|
3317
|
-
*
|
|
3340
|
+
* @throws {ValidationError} If the payload doesn't match the action schema,
|
|
3341
|
+
* or the state the action leaves breaks the state schema
|
|
3342
|
+
* @throws {PreconditionError} If business rules are violated
|
|
3318
3343
|
* @throws {ConcurrencyError} If another process modified the stream
|
|
3319
3344
|
*
|
|
3320
3345
|
* @example Basic action execution
|
|
@@ -3333,11 +3358,11 @@ var Act = (_class7 = class {
|
|
|
3333
3358
|
*
|
|
3334
3359
|
* @see {@link Target} for target structure
|
|
3335
3360
|
* @see {@link Snapshot} for return value structure
|
|
3336
|
-
* @see {@link ValidationError}, {@link
|
|
3361
|
+
* @see {@link ValidationError}, {@link PreconditionError}, {@link ConcurrencyError}
|
|
3337
3362
|
*/
|
|
3338
3363
|
async do(action2, target, payload, options) {
|
|
3339
|
-
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
3340
|
-
const do_options = reacting_to === _optionalChain([options, 'optionalAccess',
|
|
3364
|
+
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _134 => _134.reactingTo]), () => ( _chunkBNTVE7RQcjs.current_reacting.call(void 0, )));
|
|
3365
|
+
const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _135 => _135.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
|
|
3341
3366
|
return this._scoped(async () => {
|
|
3342
3367
|
const snapshots = await this._es.action(
|
|
3343
3368
|
this.registry.actions[action2],
|
|
@@ -3397,11 +3422,11 @@ var Act = (_class7 = class {
|
|
|
3397
3422
|
return this._scoped(async () => {
|
|
3398
3423
|
let first;
|
|
3399
3424
|
let last;
|
|
3400
|
-
const count = await
|
|
3425
|
+
const count = await _chunkBNTVE7RQcjs.store.call(void 0, ).query((e) => {
|
|
3401
3426
|
const gated = this.registry.query_gate(e.name)(e);
|
|
3402
3427
|
if (!first) first = gated;
|
|
3403
3428
|
last = gated;
|
|
3404
|
-
_optionalChain([callback, 'optionalCall',
|
|
3429
|
+
_optionalChain([callback, 'optionalCall', _136 => _136(gated)]);
|
|
3405
3430
|
}, query);
|
|
3406
3431
|
return { first, last, count };
|
|
3407
3432
|
});
|
|
@@ -3427,7 +3452,7 @@ var Act = (_class7 = class {
|
|
|
3427
3452
|
async query_array(query) {
|
|
3428
3453
|
return this._scoped(async () => {
|
|
3429
3454
|
const events = [];
|
|
3430
|
-
await
|
|
3455
|
+
await _chunkBNTVE7RQcjs.store.call(void 0, ).query((e) => {
|
|
3431
3456
|
events.push(this.registry.query_gate(e.name)(e));
|
|
3432
3457
|
}, query);
|
|
3433
3458
|
return events;
|
|
@@ -3447,14 +3472,14 @@ var Act = (_class7 = class {
|
|
|
3447
3472
|
*/
|
|
3448
3473
|
async forget(stream) {
|
|
3449
3474
|
return this._scoped(async () => {
|
|
3450
|
-
const s =
|
|
3475
|
+
const s = _chunkBNTVE7RQcjs.store.call(void 0, );
|
|
3451
3476
|
if (!s.forget_pii) {
|
|
3452
3477
|
throw new Error(
|
|
3453
3478
|
`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).`
|
|
3454
3479
|
);
|
|
3455
3480
|
}
|
|
3456
3481
|
const eventCount = await s.forget_pii(stream);
|
|
3457
|
-
await
|
|
3482
|
+
await _chunkBNTVE7RQcjs.cache.call(void 0, ).invalidate(stream);
|
|
3458
3483
|
if (eventCount > 0) {
|
|
3459
3484
|
this.emit("forgotten", { stream, at: /* @__PURE__ */ new Date(), eventCount });
|
|
3460
3485
|
}
|
|
@@ -3488,7 +3513,7 @@ var Act = (_class7 = class {
|
|
|
3488
3513
|
* @see {@link correlate} for dynamic stream discovery
|
|
3489
3514
|
*/
|
|
3490
3515
|
async drain(options = {}) {
|
|
3491
|
-
|
|
3516
|
+
_chunkBNTVE7RQcjs.resolveDrainConfig.call(void 0, options);
|
|
3492
3517
|
if (!this._drain)
|
|
3493
3518
|
return { fetched: [], leased: [], acked: [], blocked: [] };
|
|
3494
3519
|
return this._scoped(() => this._drain_all(options));
|
|
@@ -3528,7 +3553,7 @@ var Act = (_class7 = class {
|
|
|
3528
3553
|
}
|
|
3529
3554
|
if (to_arm.size === 0) return false;
|
|
3530
3555
|
this._correlate.arm();
|
|
3531
|
-
for (const lane of to_arm) _optionalChain([this, 'access',
|
|
3556
|
+
for (const lane of to_arm) _optionalChain([this, 'access', _137 => _137._drain_controllers, 'access', _138 => _138.get, 'call', _139 => _139(lane), 'optionalAccess', _140 => _140.arm, 'call', _141 => _141()]);
|
|
3532
3557
|
return true;
|
|
3533
3558
|
}
|
|
3534
3559
|
/** In parallel, so a slow lane never holds up a fast one. */
|
|
@@ -3567,17 +3592,17 @@ var Act = (_class7 = class {
|
|
|
3567
3592
|
* @see {@link start_correlations} for automatic periodic correlation
|
|
3568
3593
|
*/
|
|
3569
3594
|
async correlate(query = {}) {
|
|
3570
|
-
const pass = await this._correlate_pass(
|
|
3595
|
+
const pass = await this._correlate_pass(_nullishCoalesce(query.limit, () => ( 10)));
|
|
3571
3596
|
return {
|
|
3572
3597
|
subscribed: pass.kind === "scanned" ? pass.subscribed : 0,
|
|
3573
3598
|
last_id: pass.last_id
|
|
3574
3599
|
};
|
|
3575
3600
|
}
|
|
3576
3601
|
/** One correlate pass; arms every lane when it found work. */
|
|
3577
|
-
async _correlate_pass(
|
|
3602
|
+
async _correlate_pass(limit, lease = false) {
|
|
3578
3603
|
if (!this._drain) return { kind: "idle", last_id: -1 };
|
|
3579
3604
|
return this._scoped(async () => {
|
|
3580
|
-
const pass = await this._correlate.correlate(
|
|
3605
|
+
const pass = await this._correlate.correlate(limit, lease);
|
|
3581
3606
|
if (pass.kind === "scanned" && pass.marked > 0) this._arm_all();
|
|
3582
3607
|
return pass;
|
|
3583
3608
|
});
|
|
@@ -3670,9 +3695,9 @@ var Act = (_class7 = class {
|
|
|
3670
3695
|
*/
|
|
3671
3696
|
async reset(input) {
|
|
3672
3697
|
return this._scoped(async () => {
|
|
3673
|
-
const count = await
|
|
3698
|
+
const count = await _chunkBNTVE7RQcjs.store.call(void 0, ).reset(input);
|
|
3674
3699
|
for (const handler of this._batch_handlers.values())
|
|
3675
|
-
_optionalChain([handler, 'access',
|
|
3700
|
+
_optionalChain([handler, 'access', _142 => _142[FOLD_RESET], 'optionalCall', _143 => _143()]);
|
|
3676
3701
|
if (count > 0) {
|
|
3677
3702
|
this._wake();
|
|
3678
3703
|
}
|
|
@@ -3706,7 +3731,7 @@ var Act = (_class7 = class {
|
|
|
3706
3731
|
*/
|
|
3707
3732
|
async unblock(input) {
|
|
3708
3733
|
return this._scoped(async () => {
|
|
3709
|
-
const count = await
|
|
3734
|
+
const count = await _chunkBNTVE7RQcjs.store.call(void 0, ).unblock(input);
|
|
3710
3735
|
if (count > 0) {
|
|
3711
3736
|
this._wake();
|
|
3712
3737
|
}
|
|
@@ -3761,7 +3786,7 @@ var Act = (_class7 = class {
|
|
|
3761
3786
|
return { ...partial, duration_ms: Date.now() - started };
|
|
3762
3787
|
}
|
|
3763
3788
|
const target = _nullishCoalesce(sink, () => ( (() => {
|
|
3764
|
-
const s =
|
|
3789
|
+
const s = _chunkBNTVE7RQcjs.store.call(void 0, );
|
|
3765
3790
|
if (!s.restore) throw new Error("adapter has no restore capability");
|
|
3766
3791
|
return s;
|
|
3767
3792
|
})()));
|
|
@@ -3807,11 +3832,11 @@ var Act = (_class7 = class {
|
|
|
3807
3832
|
async blocked_streams(options) {
|
|
3808
3833
|
return this._scoped(async () => {
|
|
3809
3834
|
const positions = [];
|
|
3810
|
-
await
|
|
3835
|
+
await _chunkBNTVE7RQcjs.store.call(void 0, ).query_streams(
|
|
3811
3836
|
(p) => {
|
|
3812
3837
|
positions.push(p);
|
|
3813
3838
|
},
|
|
3814
|
-
{ blocked: true, after: _optionalChain([options, 'optionalAccess',
|
|
3839
|
+
{ blocked: true, after: _optionalChain([options, 'optionalAccess', _144 => _144.after]), limit: _optionalChain([options, 'optionalAccess', _145 => _145.limit]) }
|
|
3815
3840
|
);
|
|
3816
3841
|
return positions;
|
|
3817
3842
|
});
|
|
@@ -3859,7 +3884,7 @@ var Act = (_class7 = class {
|
|
|
3859
3884
|
* @see {@link Store.prioritize} for the underlying primitive
|
|
3860
3885
|
*/
|
|
3861
3886
|
async prioritize(filter, priority) {
|
|
3862
|
-
return this._scoped(() =>
|
|
3887
|
+
return this._scoped(() => _chunkBNTVE7RQcjs.store.call(void 0, ).prioritize(filter, priority));
|
|
3863
3888
|
}
|
|
3864
3889
|
/** Shared by `close()` and reaction-requested closes. */
|
|
3865
3890
|
async _run_close(targets) {
|
|
@@ -3939,7 +3964,7 @@ var Act = (_class7 = class {
|
|
|
3939
3964
|
* @see {@link correlate} for manual correlation
|
|
3940
3965
|
*/
|
|
3941
3966
|
settle(options) {
|
|
3942
|
-
|
|
3967
|
+
_chunkBNTVE7RQcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
|
|
3943
3968
|
this._schedule(options);
|
|
3944
3969
|
}
|
|
3945
3970
|
}, _class7);
|
|
@@ -4005,12 +4030,12 @@ function policy_min_after_days(options) {
|
|
|
4005
4030
|
const parsed = AutoclosePolicySchema.parse(options);
|
|
4006
4031
|
const windows = [];
|
|
4007
4032
|
if (parsed.after) windows.push(parsed.after.days);
|
|
4008
|
-
if (_optionalChain([parsed, 'access',
|
|
4033
|
+
if (_optionalChain([parsed, 'access', _146 => _146.or, 'optionalAccess', _147 => _147.after])) windows.push(parsed.or.after.days);
|
|
4009
4034
|
return windows.length ? Math.min(...windows) : void 0;
|
|
4010
4035
|
}
|
|
4011
4036
|
function policy_keep_days(options) {
|
|
4012
4037
|
const parsed = AutoclosePolicySchema.parse(options);
|
|
4013
|
-
return _optionalChain([parsed, 'access',
|
|
4038
|
+
return _optionalChain([parsed, 'access', _148 => _148.keep, 'optionalAccess', _149 => _149.days]);
|
|
4014
4039
|
}
|
|
4015
4040
|
function compile_autoclose_policy(options) {
|
|
4016
4041
|
const parsed = AutoclosePolicySchema.parse(options);
|
|
@@ -4042,7 +4067,7 @@ function hour_in_zone(now, timeZone) {
|
|
|
4042
4067
|
hour: "2-digit",
|
|
4043
4068
|
hourCycle: "h23"
|
|
4044
4069
|
}).formatToParts(now);
|
|
4045
|
-
return Number(_optionalChain([parts, 'access',
|
|
4070
|
+
return Number(_optionalChain([parts, 'access', _150 => _150.find, 'call', _151 => _151((p) => p.type === "hour"), 'optionalAccess', _152 => _152.value]));
|
|
4046
4071
|
}
|
|
4047
4072
|
function hour_in_range(hour, start, end) {
|
|
4048
4073
|
return start < end ? hour >= start && hour < end : hour >= start || hour < end;
|
|
@@ -4095,16 +4120,16 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
4095
4120
|
}),
|
|
4096
4121
|
// Never block on autoclose: a transient query/store error should retry,
|
|
4097
4122
|
// not quarantine the synthetic stream.
|
|
4098
|
-
options: { blockOnError: false, maxRetries:
|
|
4123
|
+
options: { blockOnError: false, maxRetries: _chunkBNTVE7RQcjs.DEFAULT_MAX_RETRIES },
|
|
4099
4124
|
handler: async (event) => {
|
|
4100
4125
|
const aggregate = event.stream;
|
|
4101
4126
|
const window = read_window();
|
|
4102
4127
|
if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
|
|
4103
|
-
throw new (0,
|
|
4104
|
-
const stats = await
|
|
4128
|
+
throw new (0, _chunkL66OOP2Fcjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
|
|
4129
|
+
const stats = await _chunkBNTVE7RQcjs.store.call(void 0, ).query_stats([aggregate], {
|
|
4105
4130
|
count: true,
|
|
4106
4131
|
tail: keep_days !== void 0 ? true : void 0,
|
|
4107
|
-
exclude: [
|
|
4132
|
+
exclude: [_chunkL66OOP2Fcjs.TOMBSTONE_EVENT, _chunkL66OOP2Fcjs.SNAP_EVENT]
|
|
4108
4133
|
});
|
|
4109
4134
|
const entry = stats.get(aggregate);
|
|
4110
4135
|
if (!entry) return;
|
|
@@ -4135,12 +4160,12 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
4135
4160
|
dues.push(days_after(entry.tail.created, keep_days));
|
|
4136
4161
|
const future = dues.map((d) => d.getTime()).filter((t) => t > Date.now());
|
|
4137
4162
|
if (future.length)
|
|
4138
|
-
throw new (0,
|
|
4163
|
+
throw new (0, _chunkL66OOP2Fcjs.DeferSignal)({ at: new Date(Math.min(...future)) });
|
|
4139
4164
|
}
|
|
4140
4165
|
};
|
|
4141
4166
|
const key = `__autoclose_${st.name}`;
|
|
4142
4167
|
for (const event_name of Object.keys(st.events)) {
|
|
4143
|
-
_optionalChain([registry, 'access',
|
|
4168
|
+
_optionalChain([registry, 'access', _153 => _153.events, 'access', _154 => _154[event_name], 'optionalAccess', _155 => _155.reactions, 'access', _156 => _156.set, 'call', _157 => _157(
|
|
4144
4169
|
key,
|
|
4145
4170
|
reaction
|
|
4146
4171
|
)]);
|
|
@@ -4340,9 +4365,9 @@ var _this_ = ({ stream }) => ({
|
|
|
4340
4365
|
|
|
4341
4366
|
// src/builders/builder-utils.ts
|
|
4342
4367
|
function register_lane(config2, lanes) {
|
|
4343
|
-
|
|
4344
|
-
if (config2.name ===
|
|
4345
|
-
throw new Error(`Lane "${
|
|
4368
|
+
_chunkBNTVE7RQcjs.resolveLaneConfig.call(void 0, config2);
|
|
4369
|
+
if (config2.name === _chunkL66OOP2Fcjs.DEFAULT_LANE)
|
|
4370
|
+
throw new Error(`Lane "${_chunkL66OOP2Fcjs.DEFAULT_LANE}" is reserved`);
|
|
4346
4371
|
const existing = lanes.find((l) => l.name === config2.name);
|
|
4347
4372
|
if (!existing) return void lanes.push(config2);
|
|
4348
4373
|
if (existing.leaseMillis !== config2.leaseMillis || existing.streamLimit !== config2.streamLimit || existing.cycleMs !== config2.cycleMs)
|
|
@@ -4384,10 +4409,10 @@ function reaction_on(event, events, builder) {
|
|
|
4384
4409
|
// Validate the whole bag at the declaration site so a bad
|
|
4385
4410
|
// `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
|
|
4386
4411
|
// not a NaN gate on the first retry.
|
|
4387
|
-
options:
|
|
4388
|
-
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4389
|
-
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4390
|
-
backoff: _optionalChain([options, 'optionalAccess',
|
|
4412
|
+
options: _chunkBNTVE7RQcjs.resolveReactionConfig.call(void 0, {
|
|
4413
|
+
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _158 => _158.blockOnError]), () => ( _chunkBNTVE7RQcjs.DEFAULT_BLOCK_ON_ERROR)),
|
|
4414
|
+
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _159 => _159.maxRetries]), () => ( _chunkBNTVE7RQcjs.DEFAULT_MAX_RETRIES)),
|
|
4415
|
+
backoff: _optionalChain([options, 'optionalAccess', _160 => _160.backoff])
|
|
4391
4416
|
})
|
|
4392
4417
|
};
|
|
4393
4418
|
},
|
|
@@ -4406,9 +4431,9 @@ function reaction_on(event, events, builder) {
|
|
|
4406
4431
|
|
|
4407
4432
|
// src/internal/date-reviver.ts
|
|
4408
4433
|
|
|
4409
|
-
var def_of = (schema) => _nullishCoalesce(_optionalChain([schema, 'access',
|
|
4434
|
+
var def_of = (schema) => _nullishCoalesce(_optionalChain([schema, 'access', _161 => _161._zod, 'optionalAccess', _162 => _162.def]), () => ( schema.def));
|
|
4410
4435
|
function variant_schema(schema) {
|
|
4411
|
-
const shape = _optionalChain([def_of, 'call',
|
|
4436
|
+
const shape = _optionalChain([def_of, 'call', _163 => _163(schema), 'optionalAccess', _164 => _164.shape]);
|
|
4412
4437
|
if (!shape) {
|
|
4413
4438
|
const dates = date_reviver_schema(schema);
|
|
4414
4439
|
return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
|
|
@@ -4456,7 +4481,7 @@ function date_reviver_schema(schema) {
|
|
|
4456
4481
|
return variants.some((v) => v.dated) ? _zod2.z.union(variants.map((v) => v.schema)) : void 0;
|
|
4457
4482
|
}
|
|
4458
4483
|
case "nullable":
|
|
4459
|
-
return _optionalChain([inner, 'call',
|
|
4484
|
+
return _optionalChain([inner, 'call', _165 => _165(), 'optionalAccess', _166 => _166.nullable, 'call', _167 => _167()]);
|
|
4460
4485
|
case "optional":
|
|
4461
4486
|
case "nonoptional":
|
|
4462
4487
|
case "readonly":
|
|
@@ -4471,7 +4496,7 @@ function date_reviver_schema(schema) {
|
|
|
4471
4496
|
|
|
4472
4497
|
// src/builders/event-builder.ts
|
|
4473
4498
|
function event_tags(schema) {
|
|
4474
|
-
const pii =
|
|
4499
|
+
const pii = _chunkL66OOP2Fcjs.pii_schemas.call(void 0, schema);
|
|
4475
4500
|
const pii_dates = {};
|
|
4476
4501
|
for (const [key, field] of Object.entries(pii)) {
|
|
4477
4502
|
const dates = date_reviver_schema(field);
|
|
@@ -4508,7 +4533,7 @@ function make_event_reader(tags, disclosure, predicate = null) {
|
|
|
4508
4533
|
});
|
|
4509
4534
|
}
|
|
4510
4535
|
function build_events(registry, states, lanes, owners) {
|
|
4511
|
-
const declared = /* @__PURE__ */ new Set([
|
|
4536
|
+
const declared = /* @__PURE__ */ new Set([_chunkL66OOP2Fcjs.DEFAULT_LANE, ...lanes.map((l) => l.name)]);
|
|
4512
4537
|
const lane_errors = [];
|
|
4513
4538
|
const tags = /* @__PURE__ */ new Map();
|
|
4514
4539
|
const sensitive2 = /* @__PURE__ */ new Map();
|
|
@@ -4572,7 +4597,7 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4572
4597
|
if (reader) readers.set(event_name, reader);
|
|
4573
4598
|
}
|
|
4574
4599
|
const snap2 = make_event_reader(event_tags(state2.state), "redact", null);
|
|
4575
|
-
if (snap2) readers.set(
|
|
4600
|
+
if (snap2) readers.set(_chunkL66OOP2Fcjs.SNAP_EVENT, snap2);
|
|
4576
4601
|
if (readers.size === 0) continue;
|
|
4577
4602
|
state2.view = (event, actor) => (_nullishCoalesce(readers.get(event.name), () => ( IDENTITY_GATE)))(event, actor);
|
|
4578
4603
|
}
|
|
@@ -4633,14 +4658,14 @@ function act() {
|
|
|
4633
4658
|
let _built = false;
|
|
4634
4659
|
const read_wrap = (original) => {
|
|
4635
4660
|
const wrapped = async (events, stream) => {
|
|
4636
|
-
const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access',
|
|
4661
|
+
const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _168 => _168.get, 'call', _169 => _169(e.name), 'optionalCall', _170 => _170(e)]), () => ( e)));
|
|
4637
4662
|
return original(read, stream);
|
|
4638
4663
|
};
|
|
4639
4664
|
const reset = original[FOLD_RESET];
|
|
4640
4665
|
if (reset) Object.defineProperty(wrapped, FOLD_RESET, { value: reset });
|
|
4641
4666
|
return wrapped;
|
|
4642
4667
|
};
|
|
4643
|
-
const make_batch_handlers = (
|
|
4668
|
+
const make_batch_handlers = () => {
|
|
4644
4669
|
const handlers = new Map(batch_handlers);
|
|
4645
4670
|
for (const spec of fold_specs) {
|
|
4646
4671
|
handlers.set(
|
|
@@ -4650,7 +4675,7 @@ function act() {
|
|
|
4650
4675
|
spec.merged,
|
|
4651
4676
|
spec.flush,
|
|
4652
4677
|
spec.config,
|
|
4653
|
-
|
|
4678
|
+
bare_patch,
|
|
4654
4679
|
// Head loads strip sensitive keys like the warm path.
|
|
4655
4680
|
registry.sensitive_fields
|
|
4656
4681
|
)
|
|
@@ -4675,7 +4700,7 @@ function act() {
|
|
|
4675
4700
|
});
|
|
4676
4701
|
}
|
|
4677
4702
|
for (const [action_name, handler] of Object.entries(state2.on)) {
|
|
4678
|
-
const static_target = _optionalChain([handler, 'optionalAccess',
|
|
4703
|
+
const static_target = _optionalChain([handler, 'optionalAccess', _171 => _171._static_emit]);
|
|
4679
4704
|
if (static_target && deprecated.has(static_target)) {
|
|
4680
4705
|
const current = current_version_of(static_target, event_names);
|
|
4681
4706
|
throw new Error(
|
|
@@ -4688,7 +4713,7 @@ function act() {
|
|
|
4688
4713
|
const list = deprecation_summary.map(
|
|
4689
4714
|
(d) => `"${d.deprecated}" (current: "${d.current}", state: "${d.state_name}")`
|
|
4690
4715
|
).join(", ");
|
|
4691
|
-
|
|
4716
|
+
_chunkBNTVE7RQcjs.log.call(void 0, ).info(
|
|
4692
4717
|
`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.`
|
|
4693
4718
|
);
|
|
4694
4719
|
}
|
|
@@ -4730,8 +4755,7 @@ function act() {
|
|
|
4730
4755
|
return reaction_on(event, registry.events, builder);
|
|
4731
4756
|
},
|
|
4732
4757
|
build: (options) => {
|
|
4733
|
-
|
|
4734
|
-
const patch_fn = _optionalChain([options, 'optionalAccess', _169 => _169.validateFoldedState]) === true ? validating_patch : bare_patch;
|
|
4758
|
+
_chunkBNTVE7RQcjs.resolveActConfig.call(void 0, options);
|
|
4735
4759
|
if (!_built) {
|
|
4736
4760
|
for (const proj of pending_projections) add_projection(proj);
|
|
4737
4761
|
for (const proj of fold_projections) {
|
|
@@ -4749,7 +4773,7 @@ function act() {
|
|
|
4749
4773
|
`State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
|
|
4750
4774
|
);
|
|
4751
4775
|
const claimed = fold_specs.find((s) => s.target === proj.target);
|
|
4752
|
-
if (_optionalChain([claimed, 'optionalAccess',
|
|
4776
|
+
if (_optionalChain([claimed, 'optionalAccess', _172 => _172.projection]) === proj) continue;
|
|
4753
4777
|
if (batch_handlers.has(proj.target) || claimed)
|
|
4754
4778
|
throw new Error(
|
|
4755
4779
|
`Duplicate projection target "${proj.target}" \u2014 a target is served by one batch handler or one state projection, never both`
|
|
@@ -4782,7 +4806,7 @@ function act() {
|
|
|
4782
4806
|
synthesize_autoclose_reactions(
|
|
4783
4807
|
registry,
|
|
4784
4808
|
states,
|
|
4785
|
-
|
|
4809
|
+
_chunkBNTVE7RQcjs.current_autoclose_window
|
|
4786
4810
|
);
|
|
4787
4811
|
Object.freeze(registry.actions);
|
|
4788
4812
|
Object.freeze(registry.events);
|
|
@@ -4792,10 +4816,9 @@ function act() {
|
|
|
4792
4816
|
return new Act(
|
|
4793
4817
|
registry,
|
|
4794
4818
|
states,
|
|
4795
|
-
make_batch_handlers(
|
|
4819
|
+
make_batch_handlers(),
|
|
4796
4820
|
options,
|
|
4797
|
-
lanes
|
|
4798
|
-
patch_fn
|
|
4821
|
+
lanes
|
|
4799
4822
|
);
|
|
4800
4823
|
},
|
|
4801
4824
|
events: registry.events
|
|
@@ -4831,8 +4854,8 @@ function _projection(target) {
|
|
|
4831
4854
|
handler,
|
|
4832
4855
|
resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
|
|
4833
4856
|
options: {
|
|
4834
|
-
blockOnError:
|
|
4835
|
-
maxRetries:
|
|
4857
|
+
blockOnError: _chunkBNTVE7RQcjs.DEFAULT_BLOCK_ON_ERROR,
|
|
4858
|
+
maxRetries: _chunkBNTVE7RQcjs.DEFAULT_MAX_RETRIES
|
|
4836
4859
|
}
|
|
4837
4860
|
}),
|
|
4838
4861
|
widened
|
|
@@ -4873,7 +4896,7 @@ function _projection(target) {
|
|
|
4873
4896
|
throw new Error(
|
|
4874
4897
|
`Projection "${target}" .of() partials must share one state name \u2014 got "${name}" and "${partial.name}"`
|
|
4875
4898
|
);
|
|
4876
|
-
const config2 =
|
|
4899
|
+
const config2 = _chunkBNTVE7RQcjs.resolveFoldConfig.call(void 0, options);
|
|
4877
4900
|
const fold_events = {};
|
|
4878
4901
|
for (const partial of partials)
|
|
4879
4902
|
for (const [event_name, schema] of Object.entries(partial.events)) {
|
|
@@ -4891,8 +4914,8 @@ function _projection(target) {
|
|
|
4891
4914
|
handler: noop,
|
|
4892
4915
|
resolver: { target },
|
|
4893
4916
|
options: {
|
|
4894
|
-
blockOnError:
|
|
4895
|
-
maxRetries:
|
|
4917
|
+
blockOnError: _chunkBNTVE7RQcjs.DEFAULT_BLOCK_ON_ERROR,
|
|
4918
|
+
maxRetries: _chunkBNTVE7RQcjs.DEFAULT_MAX_RETRIES
|
|
4896
4919
|
}
|
|
4897
4920
|
}
|
|
4898
4921
|
]
|
|
@@ -5008,7 +5031,7 @@ function action_builder(state2) {
|
|
|
5008
5031
|
throw new Error(`Duplicate action "${action2}"`);
|
|
5009
5032
|
internal.actions[action2] = schema;
|
|
5010
5033
|
if (options) {
|
|
5011
|
-
|
|
5034
|
+
_chunkBNTVE7RQcjs.resolveActionConfig.call(void 0, options);
|
|
5012
5035
|
internal.options ??= {};
|
|
5013
5036
|
internal.options[action2] = options;
|
|
5014
5037
|
}
|
|
@@ -5300,5 +5323,6 @@ function write_line(writer, line) {
|
|
|
5300
5323
|
|
|
5301
5324
|
|
|
5302
5325
|
|
|
5303
|
-
|
|
5326
|
+
|
|
5327
|
+
exports.Act = Act; exports.ActorSchema = _chunkL66OOP2Fcjs.ActorSchema; exports.CausationEventSchema = _chunkL66OOP2Fcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkL66OOP2Fcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkL66OOP2Fcjs.ConcurrencyError; exports.ConsoleLogger = _chunkBNTVE7RQcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunkL66OOP2Fcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunkL66OOP2Fcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunkL66OOP2Fcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunkL66OOP2Fcjs.DeferSignal; exports.Environments = _chunkL66OOP2Fcjs.Environments; exports.Errors = _chunkL66OOP2Fcjs.Errors; exports.EventMetaSchema = _chunkL66OOP2Fcjs.EventMetaSchema; exports.ExitCodes = _chunkL66OOP2Fcjs.ExitCodes; exports.InMemoryCache = _chunkBNTVE7RQcjs.InMemoryCache; exports.InMemoryStore = _chunkBNTVE7RQcjs.InMemoryStore; exports.InvariantError = _chunkL66OOP2Fcjs.InvariantError; exports.LogLevels = _chunkL66OOP2Fcjs.LogLevels; exports.NonRetryableError = _chunkL66OOP2Fcjs.NonRetryableError; exports.PackageSchema = _chunkBNTVE7RQcjs.PackageSchema; exports.PreconditionError = _chunkL66OOP2Fcjs.PreconditionError; exports.QuerySchema = _chunkL66OOP2Fcjs.QuerySchema; exports.REDACTED = _chunkL66OOP2Fcjs.REDACTED; exports.SHREDDED = _chunkL66OOP2Fcjs.SHREDDED; exports.SNAP_EVENT = _chunkL66OOP2Fcjs.SNAP_EVENT; exports.StoreError = _chunkL66OOP2Fcjs.StoreError; exports.StreamClosedError = _chunkL66OOP2Fcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunkL66OOP2Fcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunkL66OOP2Fcjs.TargetSchema; exports.ValidationError = _chunkL66OOP2Fcjs.ValidationError; exports.ZodEmpty = _chunkL66OOP2Fcjs.ZodEmpty; exports.act = act; exports.cache = _chunkBNTVE7RQcjs.cache; exports.config = _chunkBNTVE7RQcjs.config; exports.dateReviver = _chunkBNTVE7RQcjs.dateReviver; exports.default_scope = _chunkBNTVE7RQcjs.default_scope; exports.dispose = _chunkBNTVE7RQcjs.dispose; exports.disposeAndExit = _chunkBNTVE7RQcjs.disposeAndExit; exports.extend = _chunkBNTVE7RQcjs.extend; exports.is_literal_source = _chunkBNTVE7RQcjs.is_literal_source; exports.log = _chunkBNTVE7RQcjs.log; exports.pii_fields = _chunkL66OOP2Fcjs.pii_fields; exports.port = _chunkBNTVE7RQcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkBNTVE7RQcjs.resolveAutocloseConfig2; exports.sensitive = _chunkL66OOP2Fcjs.sensitive; exports.sleep = _chunkBNTVE7RQcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkBNTVE7RQcjs.store; exports.validate = _chunkBNTVE7RQcjs.validate;
|
|
5304
5328
|
//# sourceMappingURL=index.cjs.map
|