@rotorsoft/act 1.33.16 → 1.33.17
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 +6 -0
- 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/{chunk-E5H3NRCT.js → chunk-5KTVG7IM.js} +28 -37
- package/dist/chunk-5KTVG7IM.js.map +1 -0
- package/dist/{chunk-EN2KFJ7W.cjs → chunk-J6QMZEQF.cjs} +34 -43
- package/dist/chunk-J6QMZEQF.cjs.map +1 -0
- package/dist/index.cjs +158 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -12
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +3 -3
- package/dist/test/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 _chunkJ6QMZEQFcjs = require('./chunk-J6QMZEQF.cjs');
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
@@ -74,20 +74,20 @@ var _chunkPMS6BMIUcjs = require('./chunk-PMS6BMIU.cjs');
|
|
|
74
74
|
|
|
75
75
|
// src/signals.ts
|
|
76
76
|
process.once("SIGINT", async (arg) => {
|
|
77
|
-
|
|
78
|
-
await
|
|
77
|
+
_chunkJ6QMZEQFcjs.log.call(void 0, ).info(arg, "SIGINT");
|
|
78
|
+
await _chunkJ6QMZEQFcjs.disposeAndExit.call(void 0, "EXIT");
|
|
79
79
|
});
|
|
80
80
|
process.once("SIGTERM", async (arg) => {
|
|
81
|
-
|
|
82
|
-
await
|
|
81
|
+
_chunkJ6QMZEQFcjs.log.call(void 0, ).info(arg, "SIGTERM");
|
|
82
|
+
await _chunkJ6QMZEQFcjs.disposeAndExit.call(void 0, "EXIT");
|
|
83
83
|
});
|
|
84
84
|
process.once("uncaughtException", async (arg) => {
|
|
85
|
-
|
|
86
|
-
await
|
|
85
|
+
_chunkJ6QMZEQFcjs.log.call(void 0, ).error(arg, "Uncaught Exception");
|
|
86
|
+
await _chunkJ6QMZEQFcjs.disposeAndExit.call(void 0, "ERROR");
|
|
87
87
|
});
|
|
88
88
|
process.once("unhandledRejection", async (arg) => {
|
|
89
|
-
|
|
90
|
-
await
|
|
89
|
+
_chunkJ6QMZEQFcjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
|
|
90
|
+
await _chunkJ6QMZEQFcjs.disposeAndExit.call(void 0, "ERROR");
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
// src/act.ts
|
|
@@ -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 _chunkJ6QMZEQFcjs.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,7 +935,7 @@ 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 _chunkJ6QMZEQFcjs.store.call(void 0, ).query(
|
|
939
939
|
(event) => {
|
|
940
940
|
if (min_id === void 0 || event.id < min_id) min_id = event.id;
|
|
941
941
|
if (event.name === _chunkPMS6BMIUcjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
|
|
@@ -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
|
+
_chunkJ6QMZEQFcjs.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,13 +977,13 @@ function source_matcher() {
|
|
|
977
977
|
};
|
|
978
978
|
}
|
|
979
979
|
async function scan_stream_heads(streams) {
|
|
980
|
-
const stats = await
|
|
980
|
+
const stats = await _chunkJ6QMZEQFcjs.store.call(void 0, ).query_stats(streams, {
|
|
981
981
|
exclude: [_chunkPMS6BMIUcjs.SNAP_EVENT]
|
|
982
982
|
});
|
|
983
|
-
const domain_heads = await
|
|
983
|
+
const domain_heads = await _chunkJ6QMZEQFcjs.store.call(void 0, ).query_stats(streams, {
|
|
984
984
|
exclude: [_chunkPMS6BMIUcjs.SNAP_EVENT, _chunkPMS6BMIUcjs.TOMBSTONE_EVENT]
|
|
985
985
|
});
|
|
986
|
-
const true_heads = await
|
|
986
|
+
const true_heads = await _chunkJ6QMZEQFcjs.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]);
|
|
@@ -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
|
+
_chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.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;
|
|
@@ -1100,13 +1100,13 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
1100
1100
|
}
|
|
1101
1101
|
};
|
|
1102
1102
|
});
|
|
1103
|
-
const truncated = await
|
|
1103
|
+
const truncated = await _chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.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
|
+
_chunkJ6QMZEQFcjs.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, _chunkJ6QMZEQFcjs.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, _chunkJ6QMZEQFcjs.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 (_chunkJ6QMZEQFcjs.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 = () => ({
|
|
@@ -1279,7 +1300,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
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 _chunkJ6QMZEQFcjs.store.call(void 0, ).query(
|
|
1283
1304
|
(event) => {
|
|
1284
1305
|
if (stopped) return;
|
|
1285
1306
|
const register = this._registry.events[event.name];
|
|
@@ -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 _chunkJ6QMZEQFcjs.store.call(void 0, ).query_streams(
|
|
1406
1427
|
(position) => {
|
|
1407
1428
|
row = position;
|
|
1408
1429
|
},
|
|
@@ -1442,7 +1463,7 @@ var CorrelateCycle = (_class3 = class {
|
|
|
1442
1463
|
millis: 0
|
|
1443
1464
|
});
|
|
1444
1465
|
} catch (error) {
|
|
1445
|
-
|
|
1466
|
+
_chunkJ6QMZEQFcjs.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) => _chunkJ6QMZEQFcjs.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 && _chunkJ6QMZEQFcjs.is_literal_source.call(void 0, source) ? true : void 0;
|
|
1604
1625
|
try {
|
|
1605
|
-
await
|
|
1626
|
+
await _chunkJ6QMZEQFcjs.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) => _chunkJ6QMZEQFcjs.store.call(void 0, ).ack(leases);
|
|
1647
|
+
var block = (leases) => _chunkJ6QMZEQFcjs.store.call(void 0, ).block(leases);
|
|
1648
|
+
var subscribe = (streams, correlated_at, correlator) => _chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.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) => _chunkJ6QMZEQFcjs.cache.call(void 0, ).set(stream, entry).catch(
|
|
1663
|
+
(err) => _chunkJ6QMZEQFcjs.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) => _chunkJ6QMZEQFcjs.cache.call(void 0, ).invalidate(stream).catch(
|
|
1669
|
+
(err) => _chunkJ6QMZEQFcjs.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,7 +1674,7 @@ 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 _chunkJ6QMZEQFcjs.store.call(void 0, ).commit(
|
|
1657
1678
|
stream,
|
|
1658
1679
|
[{ name: _chunkPMS6BMIUcjs.SNAP_EVENT, data: snapshot.state }],
|
|
1659
1680
|
{
|
|
@@ -1666,14 +1687,14 @@ 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
|
+
_chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.store.call(void 0, ).commit(
|
|
1677
1698
|
stream,
|
|
1678
1699
|
[{ name: _chunkPMS6BMIUcjs.TOMBSTONE_EVENT, data: {} }],
|
|
1679
1700
|
{ correlation, causation: {} },
|
|
@@ -1806,14 +1827,14 @@ 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 _chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.store.call(void 0, ).query(
|
|
1817
1838
|
(raw) => {
|
|
1818
1839
|
event = me.view(raw, actor);
|
|
1819
1840
|
if (event.name === _chunkPMS6BMIUcjs.SNAP_EVENT) {
|
|
@@ -1826,7 +1847,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1826
1847
|
patches++;
|
|
1827
1848
|
replayed++;
|
|
1828
1849
|
} else if (event.name !== _chunkPMS6BMIUcjs.TOMBSTONE_EVENT) {
|
|
1829
|
-
|
|
1850
|
+
_chunkJ6QMZEQFcjs.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
|
}
|
|
@@ -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 = _chunkJ6QMZEQFcjs.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++) {
|
|
@@ -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: _chunkJ6QMZEQFcjs.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 _chunkJ6QMZEQFcjs.store.call(void 0, ).commit(
|
|
1942
1963
|
stream,
|
|
1943
1964
|
emitted,
|
|
1944
1965
|
meta,
|
|
@@ -1991,14 +2012,14 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
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 _chunkJ6QMZEQFcjs.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 = _chunkJ6QMZEQFcjs.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
|
+
_chunkJ6QMZEQFcjs.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) {
|
|
@@ -2206,7 +2227,7 @@ function finalize(lease, handled, at, error, options, logger, failed_at) {
|
|
|
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, () => ( _chunkJ6QMZEQFcjs.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
|
+
_chunkJ6QMZEQFcjs.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)), () => ( _chunkJ6QMZEQFcjs.DEFAULT_STREAM_LIMIT));
|
|
2460
|
+
const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkJ6QMZEQFcjs.DEFAULT_EVENT_LIMIT));
|
|
2461
|
+
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkJ6QMZEQFcjs.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(
|
|
@@ -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
|
}
|
|
@@ -2919,7 +2942,7 @@ function validate_only_lanes(options, lanes) {
|
|
|
2919
2942
|
);
|
|
2920
2943
|
}
|
|
2921
2944
|
var Act = (_class7 = class {
|
|
2922
|
-
|
|
2945
|
+
__init26() {this._emitter = new (0, _events2.default)()}
|
|
2923
2946
|
|
|
2924
2947
|
|
|
2925
2948
|
|
|
@@ -2995,14 +3018,14 @@ var Act = (_class7 = class {
|
|
|
2995
3018
|
/** Lanes to arm per event; `"all"` when a dynamic resolver hides the lane. */
|
|
2996
3019
|
|
|
2997
3020
|
|
|
2998
|
-
|
|
3021
|
+
__init27() {this._logger = _chunkJ6QMZEQFcjs.log.call(void 0, )}
|
|
2999
3022
|
/** This Act's ports: its own bag, or the singleton adapters. */
|
|
3000
3023
|
|
|
3001
3024
|
/** Runs a body so internal `store()`/`cache()` calls resolve to `_ports`. */
|
|
3002
3025
|
|
|
3003
3026
|
|
|
3004
3027
|
|
|
3005
|
-
|
|
3028
|
+
__init28() {this._close_lock = new CloseLock()}
|
|
3006
3029
|
/** Every lane a controller can exist for: `"default"` plus each declared one. */
|
|
3007
3030
|
|
|
3008
3031
|
/** Drain lanes declared via `.withLane(...)`. Implicit default not included. */
|
|
@@ -3010,16 +3033,16 @@ var Act = (_class7 = class {
|
|
|
3010
3033
|
return this._lanes;
|
|
3011
3034
|
}
|
|
3012
3035
|
/** 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.
|
|
3036
|
+
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
3037
|
this.registry = registry;
|
|
3015
3038
|
this._states = states;
|
|
3016
3039
|
this._batch_handlers = batch_handlers;
|
|
3017
3040
|
this._lanes = lanes;
|
|
3018
3041
|
this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
|
|
3019
3042
|
validate_only_lanes(options, lanes);
|
|
3020
|
-
this._ports = _nullishCoalesce(options.scoped, () => (
|
|
3043
|
+
this._ports = _nullishCoalesce(options.scoped, () => ( _chunkJ6QMZEQFcjs.default_scope.call(void 0, )));
|
|
3021
3044
|
const ports = this._ports;
|
|
3022
|
-
this._scoped =
|
|
3045
|
+
this._scoped = _chunkJ6QMZEQFcjs.make_run_scoped.call(void 0, {
|
|
3023
3046
|
// Getters, not a spread: the singletons resolve lazily, so a later
|
|
3024
3047
|
// `store(...)` / `cache(...)` still takes effect.
|
|
3025
3048
|
get store() {
|
|
@@ -3029,14 +3052,14 @@ var Act = (_class7 = class {
|
|
|
3029
3052
|
return ports.cache;
|
|
3030
3053
|
},
|
|
3031
3054
|
// Parsed per build, so a bad window throws on every build.
|
|
3032
|
-
autoclose_window:
|
|
3055
|
+
autoclose_window: _chunkJ6QMZEQFcjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
|
|
3033
3056
|
});
|
|
3034
3057
|
this._correlator = _nullishCoalesce(options.correlator, () => ( default_correlator));
|
|
3035
3058
|
this._es = build_es(this._logger, this._correlator, patch_fn);
|
|
3036
3059
|
this._cd = build_drain(this._logger);
|
|
3037
3060
|
const handle = build_handle({
|
|
3038
3061
|
logger: this._logger,
|
|
3039
|
-
reaction_scope:
|
|
3062
|
+
reaction_scope: _chunkJ6QMZEQFcjs.make_reaction_scope.call(void 0, {
|
|
3040
3063
|
do: this.do.bind(this),
|
|
3041
3064
|
load: this.load.bind(this),
|
|
3042
3065
|
query: this.query.bind(this),
|
|
@@ -3066,12 +3089,12 @@ var Act = (_class7 = class {
|
|
|
3066
3089
|
this._ports.store,
|
|
3067
3090
|
options.listen !== false
|
|
3068
3091
|
);
|
|
3069
|
-
|
|
3092
|
+
_chunkJ6QMZEQFcjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
|
|
3070
3093
|
}
|
|
3071
3094
|
/** Shared by drain, settle and autoclose; bad knobs throw at build. */
|
|
3072
3095
|
_build_breaker(options) {
|
|
3073
3096
|
return new CircuitBreaker(
|
|
3074
|
-
|
|
3097
|
+
_chunkJ6QMZEQFcjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
|
|
3075
3098
|
{
|
|
3076
3099
|
on_error: (error, circuit) => this._emit_error(error, circuit),
|
|
3077
3100
|
// When the cooldown elapses, settle once: its scan or claim is the
|
|
@@ -3140,7 +3163,7 @@ var Act = (_class7 = class {
|
|
|
3140
3163
|
/** Audit deps, built after the controllers so the lane set is final. */
|
|
3141
3164
|
_build_audit_deps() {
|
|
3142
3165
|
return {
|
|
3143
|
-
store:
|
|
3166
|
+
store: _chunkJ6QMZEQFcjs.store,
|
|
3144
3167
|
event_to_state: this._event_to_state,
|
|
3145
3168
|
// Declared lanes, not this process's controllers: a lane another
|
|
3146
3169
|
// worker drains is not `unknown-lane`.
|
|
@@ -3169,7 +3192,7 @@ var Act = (_class7 = class {
|
|
|
3169
3192
|
/** Cold start: an idle deferred stream still fires on time after a restart. */
|
|
3170
3193
|
async _seed_persisted_defers() {
|
|
3171
3194
|
const now = Date.now();
|
|
3172
|
-
await walk_streams(
|
|
3195
|
+
await walk_streams(_chunkJ6QMZEQFcjs.store.call(void 0, ), (pos) => {
|
|
3173
3196
|
if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
|
|
3174
3197
|
const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
|
|
3175
3198
|
_optionalChain([controller, 'optionalAccess', _124 => _124.seed_defer, 'call', _125 => _125(pos.stream, pos.deferred_at)]);
|
|
@@ -3208,7 +3231,7 @@ var Act = (_class7 = class {
|
|
|
3208
3231
|
*/
|
|
3209
3232
|
shutdown(options) {
|
|
3210
3233
|
if (!this._shutdown_promise) {
|
|
3211
|
-
|
|
3234
|
+
_chunkJ6QMZEQFcjs.resolveShutdownConfig.call(void 0, options);
|
|
3212
3235
|
this._shutdown_promise = (async () => {
|
|
3213
3236
|
this.stop_correlations();
|
|
3214
3237
|
this._settle.stop(true);
|
|
@@ -3228,10 +3251,10 @@ var Act = (_class7 = class {
|
|
|
3228
3251
|
* default for none or 0, and for a running settle), capped.
|
|
3229
3252
|
*/
|
|
3230
3253
|
_derive_grace_ms(running, settling) {
|
|
3231
|
-
let max = settling ?
|
|
3254
|
+
let max = settling ? _chunkJ6QMZEQFcjs.DEFAULT_LEASE_MILLIS : 0;
|
|
3232
3255
|
for (const c of running)
|
|
3233
|
-
max = Math.max(max, c.lease_millis ||
|
|
3234
|
-
return Math.min(max,
|
|
3256
|
+
max = Math.max(max, c.lease_millis || _chunkJ6QMZEQFcjs.DEFAULT_LEASE_MILLIS);
|
|
3257
|
+
return Math.min(max, _chunkJ6QMZEQFcjs.MAX_SHUTDOWN_GRACE_MS);
|
|
3235
3258
|
}
|
|
3236
3259
|
async _await_inflight(grace_ms) {
|
|
3237
3260
|
const running = [...this._drain_controllers.values()].filter(
|
|
@@ -3312,7 +3335,7 @@ var Act = (_class7 = class {
|
|
|
3312
3335
|
* @see {@link ValidationError}, {@link InvariantError}, {@link ConcurrencyError}
|
|
3313
3336
|
*/
|
|
3314
3337
|
async do(action2, target, payload, options) {
|
|
3315
|
-
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.reactingTo]), () => (
|
|
3338
|
+
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _127 => _127.reactingTo]), () => ( _chunkJ6QMZEQFcjs.current_reacting.call(void 0, )));
|
|
3316
3339
|
const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _128 => _128.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
|
|
3317
3340
|
return this._scoped(async () => {
|
|
3318
3341
|
const snapshots = await this._es.action(
|
|
@@ -3373,7 +3396,7 @@ var Act = (_class7 = class {
|
|
|
3373
3396
|
return this._scoped(async () => {
|
|
3374
3397
|
let first;
|
|
3375
3398
|
let last;
|
|
3376
|
-
const count = await
|
|
3399
|
+
const count = await _chunkJ6QMZEQFcjs.store.call(void 0, ).query((e) => {
|
|
3377
3400
|
const gated = this.registry.query_gate(e.name)(e);
|
|
3378
3401
|
if (!first) first = gated;
|
|
3379
3402
|
last = gated;
|
|
@@ -3403,7 +3426,7 @@ var Act = (_class7 = class {
|
|
|
3403
3426
|
async query_array(query) {
|
|
3404
3427
|
return this._scoped(async () => {
|
|
3405
3428
|
const events = [];
|
|
3406
|
-
await
|
|
3429
|
+
await _chunkJ6QMZEQFcjs.store.call(void 0, ).query((e) => {
|
|
3407
3430
|
events.push(this.registry.query_gate(e.name)(e));
|
|
3408
3431
|
}, query);
|
|
3409
3432
|
return events;
|
|
@@ -3423,14 +3446,14 @@ var Act = (_class7 = class {
|
|
|
3423
3446
|
*/
|
|
3424
3447
|
async forget(stream) {
|
|
3425
3448
|
return this._scoped(async () => {
|
|
3426
|
-
const s =
|
|
3449
|
+
const s = _chunkJ6QMZEQFcjs.store.call(void 0, );
|
|
3427
3450
|
if (!s.forget_pii) {
|
|
3428
3451
|
throw new Error(
|
|
3429
3452
|
`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
3453
|
);
|
|
3431
3454
|
}
|
|
3432
3455
|
const eventCount = await s.forget_pii(stream);
|
|
3433
|
-
await
|
|
3456
|
+
await _chunkJ6QMZEQFcjs.cache.call(void 0, ).invalidate(stream);
|
|
3434
3457
|
if (eventCount > 0) {
|
|
3435
3458
|
this.emit("forgotten", { stream, at: /* @__PURE__ */ new Date(), eventCount });
|
|
3436
3459
|
}
|
|
@@ -3464,7 +3487,7 @@ var Act = (_class7 = class {
|
|
|
3464
3487
|
* @see {@link correlate} for dynamic stream discovery
|
|
3465
3488
|
*/
|
|
3466
3489
|
async drain(options = {}) {
|
|
3467
|
-
|
|
3490
|
+
_chunkJ6QMZEQFcjs.resolveDrainConfig.call(void 0, options);
|
|
3468
3491
|
if (!this._drain)
|
|
3469
3492
|
return { fetched: [], leased: [], acked: [], blocked: [] };
|
|
3470
3493
|
return this._scoped(() => this._drain_all(options));
|
|
@@ -3644,7 +3667,7 @@ var Act = (_class7 = class {
|
|
|
3644
3667
|
*/
|
|
3645
3668
|
async reset(input) {
|
|
3646
3669
|
return this._scoped(async () => {
|
|
3647
|
-
const count = await
|
|
3670
|
+
const count = await _chunkJ6QMZEQFcjs.store.call(void 0, ).reset(input);
|
|
3648
3671
|
for (const handler of this._batch_handlers.values())
|
|
3649
3672
|
_optionalChain([handler, 'access', _135 => _135[FOLD_RESET], 'optionalCall', _136 => _136()]);
|
|
3650
3673
|
if (count > 0) {
|
|
@@ -3680,7 +3703,7 @@ var Act = (_class7 = class {
|
|
|
3680
3703
|
*/
|
|
3681
3704
|
async unblock(input) {
|
|
3682
3705
|
return this._scoped(async () => {
|
|
3683
|
-
const count = await
|
|
3706
|
+
const count = await _chunkJ6QMZEQFcjs.store.call(void 0, ).unblock(input);
|
|
3684
3707
|
if (count > 0) {
|
|
3685
3708
|
this._wake();
|
|
3686
3709
|
}
|
|
@@ -3694,6 +3717,12 @@ var Act = (_class7 = class {
|
|
|
3694
3717
|
* adapter's {@link Store.restore} driver supplies the transaction
|
|
3695
3718
|
* lifecycle and per-event insert.
|
|
3696
3719
|
*
|
|
3720
|
+
* Safe in a live process: restoring into this Act's own store waits
|
|
3721
|
+
* for its correlate passes in flight, replaces the log, then restarts
|
|
3722
|
+
* correlation and settles. A correlate pass that starts meanwhile
|
|
3723
|
+
* reads nothing. Other processes on the same store keep their
|
|
3724
|
+
* correlation state and must be restarted.
|
|
3725
|
+
*
|
|
3697
3726
|
* Throws if the adapter has no restore capability. Throws on the
|
|
3698
3727
|
* first invalid event (negative version, malformed `created`) with
|
|
3699
3728
|
* the running index in the message; atomic transaction rollback in
|
|
@@ -3729,21 +3758,22 @@ var Act = (_class7 = class {
|
|
|
3729
3758
|
return { ...partial, duration_ms: Date.now() - started };
|
|
3730
3759
|
}
|
|
3731
3760
|
const target = _nullishCoalesce(sink, () => ( (() => {
|
|
3732
|
-
const s =
|
|
3761
|
+
const s = _chunkJ6QMZEQFcjs.store.call(void 0, );
|
|
3733
3762
|
if (!s.restore) throw new Error("adapter has no restore capability");
|
|
3734
3763
|
return s;
|
|
3735
3764
|
})()));
|
|
3736
3765
|
let kept = 0;
|
|
3737
3766
|
let migrated = 0;
|
|
3738
3767
|
let dropped = { closed_streams: 0, snapshots: 0 };
|
|
3739
|
-
|
|
3768
|
+
const run = () => target.restore(async (callback) => {
|
|
3740
3769
|
const partial = await scan(source, opts, callback);
|
|
3741
3770
|
kept = partial.kept;
|
|
3742
3771
|
migrated = partial.migrated;
|
|
3743
3772
|
dropped = partial.dropped;
|
|
3744
3773
|
});
|
|
3745
|
-
if (
|
|
3746
|
-
|
|
3774
|
+
if (sink) await run();
|
|
3775
|
+
else {
|
|
3776
|
+
await this._correlate.restart(run);
|
|
3747
3777
|
this._wake();
|
|
3748
3778
|
}
|
|
3749
3779
|
return { kept, migrated, dropped, duration_ms: Date.now() - started };
|
|
@@ -3774,7 +3804,7 @@ var Act = (_class7 = class {
|
|
|
3774
3804
|
async blocked_streams(options) {
|
|
3775
3805
|
return this._scoped(async () => {
|
|
3776
3806
|
const positions = [];
|
|
3777
|
-
await
|
|
3807
|
+
await _chunkJ6QMZEQFcjs.store.call(void 0, ).query_streams(
|
|
3778
3808
|
(p) => {
|
|
3779
3809
|
positions.push(p);
|
|
3780
3810
|
},
|
|
@@ -3826,7 +3856,7 @@ var Act = (_class7 = class {
|
|
|
3826
3856
|
* @see {@link Store.prioritize} for the underlying primitive
|
|
3827
3857
|
*/
|
|
3828
3858
|
async prioritize(filter, priority) {
|
|
3829
|
-
return this._scoped(() =>
|
|
3859
|
+
return this._scoped(() => _chunkJ6QMZEQFcjs.store.call(void 0, ).prioritize(filter, priority));
|
|
3830
3860
|
}
|
|
3831
3861
|
/** Shared by `close()` and reaction-requested closes. */
|
|
3832
3862
|
async _run_close(targets) {
|
|
@@ -3906,7 +3936,7 @@ var Act = (_class7 = class {
|
|
|
3906
3936
|
* @see {@link correlate} for manual correlation
|
|
3907
3937
|
*/
|
|
3908
3938
|
settle(options) {
|
|
3909
|
-
|
|
3939
|
+
_chunkJ6QMZEQFcjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
|
|
3910
3940
|
this._schedule(options);
|
|
3911
3941
|
}
|
|
3912
3942
|
}, _class7);
|
|
@@ -4062,13 +4092,13 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
4062
4092
|
}),
|
|
4063
4093
|
// Never block on autoclose: a transient query/store error should retry,
|
|
4064
4094
|
// not quarantine the synthetic stream.
|
|
4065
|
-
options: { blockOnError: false, maxRetries:
|
|
4095
|
+
options: { blockOnError: false, maxRetries: _chunkJ6QMZEQFcjs.DEFAULT_MAX_RETRIES },
|
|
4066
4096
|
handler: async (event) => {
|
|
4067
4097
|
const aggregate = event.stream;
|
|
4068
4098
|
const window = read_window();
|
|
4069
4099
|
if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
|
|
4070
4100
|
throw new (0, _chunkPMS6BMIUcjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
|
|
4071
|
-
const stats = await
|
|
4101
|
+
const stats = await _chunkJ6QMZEQFcjs.store.call(void 0, ).query_stats([aggregate], {
|
|
4072
4102
|
count: true,
|
|
4073
4103
|
tail: keep_days !== void 0 ? true : void 0,
|
|
4074
4104
|
exclude: [_chunkPMS6BMIUcjs.TOMBSTONE_EVENT, _chunkPMS6BMIUcjs.SNAP_EVENT]
|
|
@@ -4306,7 +4336,7 @@ var _this_ = ({ stream }) => ({
|
|
|
4306
4336
|
|
|
4307
4337
|
// src/builders/builder-utils.ts
|
|
4308
4338
|
function register_lane(config2, lanes) {
|
|
4309
|
-
|
|
4339
|
+
_chunkJ6QMZEQFcjs.resolveLaneConfig.call(void 0, config2);
|
|
4310
4340
|
if (config2.name === _chunkPMS6BMIUcjs.DEFAULT_LANE)
|
|
4311
4341
|
throw new Error(`Lane "${_chunkPMS6BMIUcjs.DEFAULT_LANE}" is reserved`);
|
|
4312
4342
|
const existing = lanes.find((l) => l.name === config2.name);
|
|
@@ -4350,9 +4380,9 @@ function reaction_on(event, events, builder) {
|
|
|
4350
4380
|
// Validate the whole bag at the declaration site so a bad
|
|
4351
4381
|
// `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
|
|
4352
4382
|
// 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]), () => (
|
|
4383
|
+
options: _chunkJ6QMZEQFcjs.resolveReactionConfig.call(void 0, {
|
|
4384
|
+
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _151 => _151.blockOnError]), () => ( _chunkJ6QMZEQFcjs.DEFAULT_BLOCK_ON_ERROR)),
|
|
4385
|
+
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _152 => _152.maxRetries]), () => ( _chunkJ6QMZEQFcjs.DEFAULT_MAX_RETRIES)),
|
|
4356
4386
|
backoff: _optionalChain([options, 'optionalAccess', _153 => _153.backoff])
|
|
4357
4387
|
})
|
|
4358
4388
|
};
|
|
@@ -4654,7 +4684,7 @@ function act() {
|
|
|
4654
4684
|
const list = deprecation_summary.map(
|
|
4655
4685
|
(d) => `"${d.deprecated}" (current: "${d.current}", state: "${d.state_name}")`
|
|
4656
4686
|
).join(", ");
|
|
4657
|
-
|
|
4687
|
+
_chunkJ6QMZEQFcjs.log.call(void 0, ).info(
|
|
4658
4688
|
`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
4689
|
);
|
|
4660
4690
|
}
|
|
@@ -4696,7 +4726,7 @@ function act() {
|
|
|
4696
4726
|
return reaction_on(event, registry.events, builder);
|
|
4697
4727
|
},
|
|
4698
4728
|
build: (options) => {
|
|
4699
|
-
|
|
4729
|
+
_chunkJ6QMZEQFcjs.resolveActConfig.call(void 0, options);
|
|
4700
4730
|
const patch_fn = _optionalChain([options, 'optionalAccess', _165 => _165.validateFoldedState]) === true ? validating_patch : bare_patch;
|
|
4701
4731
|
if (!_built) {
|
|
4702
4732
|
for (const proj of pending_projections) add_projection(proj);
|
|
@@ -4748,7 +4778,7 @@ function act() {
|
|
|
4748
4778
|
synthesize_autoclose_reactions(
|
|
4749
4779
|
registry,
|
|
4750
4780
|
states,
|
|
4751
|
-
|
|
4781
|
+
_chunkJ6QMZEQFcjs.current_autoclose_window
|
|
4752
4782
|
);
|
|
4753
4783
|
Object.freeze(registry.actions);
|
|
4754
4784
|
Object.freeze(registry.events);
|
|
@@ -4797,8 +4827,8 @@ function _projection(target) {
|
|
|
4797
4827
|
handler,
|
|
4798
4828
|
resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
|
|
4799
4829
|
options: {
|
|
4800
|
-
blockOnError:
|
|
4801
|
-
maxRetries:
|
|
4830
|
+
blockOnError: _chunkJ6QMZEQFcjs.DEFAULT_BLOCK_ON_ERROR,
|
|
4831
|
+
maxRetries: _chunkJ6QMZEQFcjs.DEFAULT_MAX_RETRIES
|
|
4802
4832
|
}
|
|
4803
4833
|
}),
|
|
4804
4834
|
widened
|
|
@@ -4839,7 +4869,7 @@ function _projection(target) {
|
|
|
4839
4869
|
throw new Error(
|
|
4840
4870
|
`Projection "${target}" .of() partials must share one state name \u2014 got "${name}" and "${partial.name}"`
|
|
4841
4871
|
);
|
|
4842
|
-
const config2 =
|
|
4872
|
+
const config2 = _chunkJ6QMZEQFcjs.resolveFoldConfig.call(void 0, options);
|
|
4843
4873
|
const fold_events = {};
|
|
4844
4874
|
for (const partial of partials)
|
|
4845
4875
|
for (const [event_name, schema] of Object.entries(partial.events)) {
|
|
@@ -4857,8 +4887,8 @@ function _projection(target) {
|
|
|
4857
4887
|
handler: noop,
|
|
4858
4888
|
resolver: { target },
|
|
4859
4889
|
options: {
|
|
4860
|
-
blockOnError:
|
|
4861
|
-
maxRetries:
|
|
4890
|
+
blockOnError: _chunkJ6QMZEQFcjs.DEFAULT_BLOCK_ON_ERROR,
|
|
4891
|
+
maxRetries: _chunkJ6QMZEQFcjs.DEFAULT_MAX_RETRIES
|
|
4862
4892
|
}
|
|
4863
4893
|
}
|
|
4864
4894
|
]
|
|
@@ -4974,7 +5004,7 @@ function action_builder(state2) {
|
|
|
4974
5004
|
throw new Error(`Duplicate action "${action2}"`);
|
|
4975
5005
|
internal.actions[action2] = schema;
|
|
4976
5006
|
if (options) {
|
|
4977
|
-
|
|
5007
|
+
_chunkJ6QMZEQFcjs.resolveActionConfig.call(void 0, options);
|
|
4978
5008
|
internal.options ??= {};
|
|
4979
5009
|
internal.options[action2] = options;
|
|
4980
5010
|
}
|
|
@@ -5263,5 +5293,5 @@ function write_line(writer, line) {
|
|
|
5263
5293
|
|
|
5264
5294
|
|
|
5265
5295
|
|
|
5266
|
-
exports.Act = Act; exports.ActorSchema = _chunkPMS6BMIUcjs.ActorSchema; exports.CausationEventSchema = _chunkPMS6BMIUcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkPMS6BMIUcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkPMS6BMIUcjs.ConcurrencyError; exports.ConsoleLogger =
|
|
5296
|
+
exports.Act = Act; exports.ActorSchema = _chunkPMS6BMIUcjs.ActorSchema; exports.CausationEventSchema = _chunkPMS6BMIUcjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkPMS6BMIUcjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkPMS6BMIUcjs.ConcurrencyError; exports.ConsoleLogger = _chunkJ6QMZEQFcjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunkPMS6BMIUcjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunkPMS6BMIUcjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunkPMS6BMIUcjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunkPMS6BMIUcjs.DeferSignal; exports.Environments = _chunkPMS6BMIUcjs.Environments; exports.Errors = _chunkPMS6BMIUcjs.Errors; exports.EventMetaSchema = _chunkPMS6BMIUcjs.EventMetaSchema; exports.ExitCodes = _chunkPMS6BMIUcjs.ExitCodes; exports.InMemoryCache = _chunkJ6QMZEQFcjs.InMemoryCache; exports.InMemoryStore = _chunkJ6QMZEQFcjs.InMemoryStore; exports.InvariantError = _chunkPMS6BMIUcjs.InvariantError; exports.LogLevels = _chunkPMS6BMIUcjs.LogLevels; exports.NonRetryableError = _chunkPMS6BMIUcjs.NonRetryableError; exports.PackageSchema = _chunkJ6QMZEQFcjs.PackageSchema; exports.QuerySchema = _chunkPMS6BMIUcjs.QuerySchema; exports.REDACTED = _chunkPMS6BMIUcjs.REDACTED; exports.SHREDDED = _chunkPMS6BMIUcjs.SHREDDED; exports.SNAP_EVENT = _chunkPMS6BMIUcjs.SNAP_EVENT; exports.StoreError = _chunkPMS6BMIUcjs.StoreError; exports.StreamClosedError = _chunkPMS6BMIUcjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunkPMS6BMIUcjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunkPMS6BMIUcjs.TargetSchema; exports.ValidationError = _chunkPMS6BMIUcjs.ValidationError; exports.ZodEmpty = _chunkPMS6BMIUcjs.ZodEmpty; exports.act = act; exports.cache = _chunkJ6QMZEQFcjs.cache; exports.config = _chunkJ6QMZEQFcjs.config; exports.dateReviver = _chunkJ6QMZEQFcjs.dateReviver; exports.default_scope = _chunkJ6QMZEQFcjs.default_scope; exports.dispose = _chunkJ6QMZEQFcjs.dispose; exports.disposeAndExit = _chunkJ6QMZEQFcjs.disposeAndExit; exports.extend = _chunkJ6QMZEQFcjs.extend; exports.is_literal_source = _chunkJ6QMZEQFcjs.is_literal_source; exports.log = _chunkJ6QMZEQFcjs.log; exports.pii_fields = _chunkPMS6BMIUcjs.pii_fields; exports.port = _chunkJ6QMZEQFcjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkJ6QMZEQFcjs.resolveAutocloseConfig2; exports.sensitive = _chunkPMS6BMIUcjs.sensitive; exports.sleep = _chunkJ6QMZEQFcjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkJ6QMZEQFcjs.store; exports.validate = _chunkJ6QMZEQFcjs.validate;
|
|
5267
5297
|
//# sourceMappingURL=index.cjs.map
|