@rotorsoft/act 2.1.3 → 2.1.5
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/internal/autoclose-reaction.d.ts.map +1 -1
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/types/action.d.ts +2 -2
- package/dist/@types/types/builders.d.ts +2 -2
- package/dist/@types/types/restore.d.ts +3 -1
- package/dist/@types/types/restore.d.ts.map +1 -1
- package/dist/index.cjs +183 -170
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +110 -97
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1161,9 +1161,101 @@ var subscribe = (streams, correlated_at, correlator) => _chunkQWYMR7ZPcjs.store.
|
|
|
1161
1161
|
// src/internal/event-sourcing.ts
|
|
1162
1162
|
var _actpatch = require('@rotorsoft/act-patch');
|
|
1163
1163
|
|
|
1164
|
+
|
|
1165
|
+
// src/internal/date-reviver.ts
|
|
1166
|
+
|
|
1167
|
+
function variant_schema(schema, walk) {
|
|
1168
|
+
const shape = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, schema), 'optionalAccess', _50 => _50.shape]);
|
|
1169
|
+
if (!shape) {
|
|
1170
|
+
const dates = walk(schema);
|
|
1171
|
+
return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
|
|
1172
|
+
}
|
|
1173
|
+
const next = {};
|
|
1174
|
+
let dated = false;
|
|
1175
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
1176
|
+
const dates = walk(field);
|
|
1177
|
+
if (dates) dated = true;
|
|
1178
|
+
next[key] = (_nullishCoalesce(dates, () => ( field))).optional();
|
|
1179
|
+
}
|
|
1180
|
+
return { schema: _zod.z.looseObject(next), dated };
|
|
1181
|
+
}
|
|
1182
|
+
function date_reviver_schema(schema) {
|
|
1183
|
+
let recursive = false;
|
|
1184
|
+
const pass = (tie) => {
|
|
1185
|
+
const done = /* @__PURE__ */ new Map();
|
|
1186
|
+
const active = /* @__PURE__ */ new Set();
|
|
1187
|
+
const walk = (node) => {
|
|
1188
|
+
if (done.has(node)) return done.get(node);
|
|
1189
|
+
if (active.has(node)) {
|
|
1190
|
+
recursive = true;
|
|
1191
|
+
return tie ? _zod.z.lazy(() => done.get(node)) : void 0;
|
|
1192
|
+
}
|
|
1193
|
+
active.add(node);
|
|
1194
|
+
const result = build(node, walk);
|
|
1195
|
+
active.delete(node);
|
|
1196
|
+
done.set(node, result);
|
|
1197
|
+
return result;
|
|
1198
|
+
};
|
|
1199
|
+
return walk(schema);
|
|
1200
|
+
};
|
|
1201
|
+
const first = pass(false);
|
|
1202
|
+
return first && recursive ? pass(true) : first;
|
|
1203
|
+
}
|
|
1204
|
+
function build(schema, walk) {
|
|
1205
|
+
const def = _chunkQFYPSI6Pcjs.def_of.call(void 0, schema);
|
|
1206
|
+
if (!def) return void 0;
|
|
1207
|
+
const inner = () => walk(def.innerType);
|
|
1208
|
+
switch (def.type) {
|
|
1209
|
+
case "date":
|
|
1210
|
+
return _zod.z.coerce.date();
|
|
1211
|
+
case "object": {
|
|
1212
|
+
const shape = def.shape;
|
|
1213
|
+
if (!shape) return void 0;
|
|
1214
|
+
const dated = {};
|
|
1215
|
+
for (const [key, field] of Object.entries(shape)) {
|
|
1216
|
+
const dates = walk(field);
|
|
1217
|
+
if (dates) dated[key] = dates.optional();
|
|
1218
|
+
}
|
|
1219
|
+
return Object.keys(dated).length ? _zod.z.looseObject(dated) : void 0;
|
|
1220
|
+
}
|
|
1221
|
+
case "array": {
|
|
1222
|
+
const element = walk(def.element);
|
|
1223
|
+
return element && _zod.z.array(element);
|
|
1224
|
+
}
|
|
1225
|
+
case "tuple": {
|
|
1226
|
+
const items = def.items.map((i) => walk(i));
|
|
1227
|
+
return items.some(Boolean) ? _zod.z.tuple(items.map((i) => _nullishCoalesce(i, () => ( _zod.z.unknown())))) : void 0;
|
|
1228
|
+
}
|
|
1229
|
+
case "record": {
|
|
1230
|
+
const value = walk(def.valueType);
|
|
1231
|
+
return value && _zod.z.record(_zod.z.string(), value);
|
|
1232
|
+
}
|
|
1233
|
+
case "union": {
|
|
1234
|
+
const variants = def.options.map(
|
|
1235
|
+
(o) => variant_schema(o, walk)
|
|
1236
|
+
);
|
|
1237
|
+
return variants.some((v) => v.dated) ? _zod.z.union(variants.map((v) => v.schema)) : void 0;
|
|
1238
|
+
}
|
|
1239
|
+
case "nullable":
|
|
1240
|
+
return _optionalChain([inner, 'call', _51 => _51(), 'optionalAccess', _52 => _52.nullable, 'call', _53 => _53()]);
|
|
1241
|
+
case "pipe":
|
|
1242
|
+
return walk(def.out);
|
|
1243
|
+
case "lazy":
|
|
1244
|
+
return walk(def.getter());
|
|
1245
|
+
case "intersection": {
|
|
1246
|
+
const left = walk(def.left);
|
|
1247
|
+
const right = walk(def.right);
|
|
1248
|
+
return left && right ? left.pipe(right) : _nullishCoalesce(left, () => ( right));
|
|
1249
|
+
}
|
|
1250
|
+
default:
|
|
1251
|
+
return _chunkQFYPSI6Pcjs.inner_of.call(void 0, def) ? inner() : void 0;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// src/internal/event-sourcing.ts
|
|
1164
1256
|
var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
|
|
1165
1257
|
var value_at = (value, path) => path.reduce(
|
|
1166
|
-
(at, key) => _optionalChain([at, 'optionalAccess',
|
|
1258
|
+
(at, key) => _optionalChain([at, 'optionalAccess', _54 => _54[key]]),
|
|
1167
1259
|
value
|
|
1168
1260
|
);
|
|
1169
1261
|
var check_invariants = (target, state2, schema, pii_aware) => {
|
|
@@ -1264,6 +1356,12 @@ async function scan(source, opts = {}, callback) {
|
|
|
1264
1356
|
let processed = 0;
|
|
1265
1357
|
let at;
|
|
1266
1358
|
const started = /* @__PURE__ */ new Set();
|
|
1359
|
+
const migration_dates = new Map(
|
|
1360
|
+
Object.entries(_nullishCoalesce(event_migrations, () => ( {}))).map(([name, { from_schema }]) => [
|
|
1361
|
+
name,
|
|
1362
|
+
date_reviver_schema(from_schema)
|
|
1363
|
+
])
|
|
1364
|
+
);
|
|
1267
1365
|
const closed_streams = /* @__PURE__ */ new Set();
|
|
1268
1366
|
if (drop_closed_streams) {
|
|
1269
1367
|
await source.query(
|
|
@@ -1286,6 +1384,7 @@ async function scan(source, opts = {}, callback) {
|
|
|
1286
1384
|
let id;
|
|
1287
1385
|
await source.query(
|
|
1288
1386
|
async (event) => {
|
|
1387
|
+
if (at !== void 0 && event.id <= at) return;
|
|
1289
1388
|
got++;
|
|
1290
1389
|
id = event.id;
|
|
1291
1390
|
processed++;
|
|
@@ -1303,9 +1402,12 @@ async function scan(source, opts = {}, callback) {
|
|
|
1303
1402
|
return;
|
|
1304
1403
|
}
|
|
1305
1404
|
let migrated = event;
|
|
1306
|
-
const migration = _optionalChain([event_migrations, 'optionalAccess',
|
|
1405
|
+
const migration = _optionalChain([event_migrations, 'optionalAccess', _55 => _55[event.name]]);
|
|
1307
1406
|
if (migration) {
|
|
1308
|
-
const
|
|
1407
|
+
const revived = _optionalChain([migration_dates, 'access', _56 => _56.get, 'call', _57 => _57(event.name), 'optionalAccess', _58 => _58.safeParse, 'call', _59 => _59(event.data)]);
|
|
1408
|
+
const old_data = migration.from_schema.parse(
|
|
1409
|
+
_optionalChain([revived, 'optionalAccess', _60 => _60.success]) ? revived.data : event.data
|
|
1410
|
+
);
|
|
1309
1411
|
const new_data = migration.migrate(old_data);
|
|
1310
1412
|
migration.to_schema.parse(new_data);
|
|
1311
1413
|
migrated = {
|
|
@@ -1342,6 +1444,7 @@ async function scan(source, opts = {}, callback) {
|
|
|
1342
1444
|
// A cause missing from the source has no id in the new
|
|
1343
1445
|
// log; its old id would name another event there.
|
|
1344
1446
|
id: _nullishCoalesce(id_map.get(cause.id), () => ( -1)),
|
|
1447
|
+
name: _nullishCoalesce(_optionalChain([event_migrations, 'optionalAccess', _61 => _61[cause.name], 'optionalAccess', _62 => _62.to]), () => ( cause.name)),
|
|
1345
1448
|
stream: stream_rename ? stream_rename(cause.stream) : cause.stream
|
|
1346
1449
|
}
|
|
1347
1450
|
}
|
|
@@ -1373,9 +1476,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1373
1476
|
const seeded = time_travel && asOf.limit === void 0 && !asOf.created_after;
|
|
1374
1477
|
const cached = time_travel ? void 0 : await _chunkQWYMR7ZPcjs.cache.call(void 0, ).get(stream);
|
|
1375
1478
|
const cache_hit = !!cached;
|
|
1376
|
-
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1377
|
-
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1378
|
-
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1479
|
+
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _63 => _63.state]), () => ( (me.init ? me.init() : {})));
|
|
1480
|
+
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _64 => _64.patches]), () => ( 0));
|
|
1481
|
+
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _65 => _65.snaps]), () => ( 0));
|
|
1379
1482
|
let replayed = 0;
|
|
1380
1483
|
let event;
|
|
1381
1484
|
await _chunkQWYMR7ZPcjs.store.call(void 0, ).query(
|
|
@@ -1396,7 +1499,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1396
1499
|
`Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
|
|
1397
1500
|
);
|
|
1398
1501
|
}
|
|
1399
|
-
_optionalChain([callback, 'optionalCall',
|
|
1502
|
+
_optionalChain([callback, 'optionalCall', _66 => _66({
|
|
1400
1503
|
event,
|
|
1401
1504
|
state: state2,
|
|
1402
1505
|
version: event.version,
|
|
@@ -1420,7 +1523,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1420
1523
|
) : time_travel ? asOf : { with_snaps: true }
|
|
1421
1524
|
}
|
|
1422
1525
|
);
|
|
1423
|
-
const head_is_tombstone = _optionalChain([event, 'optionalAccess',
|
|
1526
|
+
const head_is_tombstone = _optionalChain([event, 'optionalAccess', _67 => _67.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT;
|
|
1424
1527
|
if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
|
|
1425
1528
|
await cache_put(stream, {
|
|
1426
1529
|
stream,
|
|
@@ -1434,9 +1537,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1434
1537
|
return {
|
|
1435
1538
|
event,
|
|
1436
1539
|
state: state2,
|
|
1437
|
-
version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess',
|
|
1540
|
+
version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _68 => _68.version]), () => ( _optionalChain([cached, 'optionalAccess', _69 => _69.version]))), () => ( -1)),
|
|
1438
1541
|
// Captured with `state`, so consumers never race a separate cache lookup.
|
|
1439
|
-
id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess',
|
|
1542
|
+
id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _70 => _70.id]), () => ( _optionalChain([cached, 'optionalAccess', _71 => _71.event_id]))), () => ( -1)),
|
|
1440
1543
|
patches,
|
|
1441
1544
|
snaps,
|
|
1442
1545
|
cache_hit,
|
|
@@ -1463,7 +1566,7 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
|
|
|
1463
1566
|
void 0,
|
|
1464
1567
|
patch_fn
|
|
1465
1568
|
);
|
|
1466
|
-
if (_optionalChain([snapshot, 'access',
|
|
1569
|
+
if (_optionalChain([snapshot, 'access', _72 => _72.event, 'optionalAccess', _73 => _73.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT)
|
|
1467
1570
|
throw new (0, _chunkQFYPSI6Pcjs.StreamClosedError)(stream);
|
|
1468
1571
|
return {
|
|
1469
1572
|
state: l.state,
|
|
@@ -1478,12 +1581,12 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
|
|
|
1478
1581
|
async function action(me, action2, target, payload, options, patch_fn = bare_patch) {
|
|
1479
1582
|
const { stream, expectedVersion, actor } = target;
|
|
1480
1583
|
if (!stream) throw new Error("Missing target stream");
|
|
1481
|
-
const reactingTo = _optionalChain([options, 'optionalAccess',
|
|
1482
|
-
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1584
|
+
const reactingTo = _optionalChain([options, 'optionalAccess', _74 => _74.reactingTo]);
|
|
1585
|
+
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _75 => _75.correlator]), () => ( default_correlator));
|
|
1483
1586
|
const validated = _chunkQWYMR7ZPcjs.validate.call(void 0, action2, payload, me.actions[action2]);
|
|
1484
|
-
const opts = _optionalChain([me, 'access',
|
|
1485
|
-
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1486
|
-
const loads = _nullishCoalesce(_optionalChain([me, 'access',
|
|
1587
|
+
const opts = _optionalChain([me, 'access', _76 => _76.options, 'optionalAccess', _77 => _77[action2]]);
|
|
1588
|
+
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _78 => _78.maxRetries]), () => ( 0));
|
|
1589
|
+
const loads = _nullishCoalesce(_optionalChain([me, 'access', _79 => _79.loads, 'optionalAccess', _80 => _80[action2]]), () => ( []));
|
|
1487
1590
|
for (let attempt = 0; ; attempt++) {
|
|
1488
1591
|
try {
|
|
1489
1592
|
const snapshot = await load(
|
|
@@ -1492,7 +1595,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1492
1595
|
void 0,
|
|
1493
1596
|
patch_fn
|
|
1494
1597
|
);
|
|
1495
|
-
if (_optionalChain([snapshot, 'access',
|
|
1598
|
+
if (_optionalChain([snapshot, 'access', _81 => _81.event, 'optionalAccess', _82 => _82.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT)
|
|
1496
1599
|
throw new (0, _chunkQFYPSI6Pcjs.StreamClosedError)(stream);
|
|
1497
1600
|
const own = {
|
|
1498
1601
|
state: me,
|
|
@@ -1516,9 +1619,9 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1516
1619
|
)
|
|
1517
1620
|
) : [];
|
|
1518
1621
|
const loaded = Object.fromEntries(
|
|
1519
|
-
others.map((p, i) => [loads[i].name, _optionalChain([p, 'optionalAccess',
|
|
1622
|
+
others.map((p, i) => [loads[i].name, _optionalChain([p, 'optionalAccess', _83 => _83.snapshot, 'access', _84 => _84.state])])
|
|
1520
1623
|
);
|
|
1521
|
-
for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access',
|
|
1624
|
+
for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _85 => _85.requires, 'optionalAccess', _86 => _86[action2]]), () => ( [])))
|
|
1522
1625
|
if (!holds(validated, snapshot.state, actor, loaded))
|
|
1523
1626
|
throw new (0, _chunkQFYPSI6Pcjs.PreconditionError)(
|
|
1524
1627
|
action2,
|
|
@@ -1550,10 +1653,10 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1550
1653
|
`Action "${action2}" appends only to the streams it loads; it must append an event to its own stream too`
|
|
1551
1654
|
);
|
|
1552
1655
|
const appends = [own, ...others].filter(
|
|
1553
|
-
(p) => !!_optionalChain([p, 'optionalAccess',
|
|
1656
|
+
(p) => !!_optionalChain([p, 'optionalAccess', _87 => _87.events, 'access', _88 => _88.length])
|
|
1554
1657
|
);
|
|
1555
1658
|
const meta = {
|
|
1556
|
-
correlation: _optionalChain([reactingTo, 'optionalAccess',
|
|
1659
|
+
correlation: _optionalChain([reactingTo, 'optionalAccess', _89 => _89.meta, 'access', _90 => _90.correlation]) || correlator({
|
|
1557
1660
|
action: action2,
|
|
1558
1661
|
state: me.name,
|
|
1559
1662
|
stream,
|
|
@@ -1631,13 +1734,13 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1631
1734
|
};
|
|
1632
1735
|
});
|
|
1633
1736
|
const last = appended.at(-1);
|
|
1634
|
-
const snap_event = _optionalChain([owner, 'access',
|
|
1737
|
+
const snap_event = _optionalChain([owner, 'access', _91 => _91.snap, 'optionalCall', _92 => _92(last)]) ? await snap(last) : void 0;
|
|
1635
1738
|
if (!owner.pii_aware)
|
|
1636
1739
|
void cache_put(append.stream, {
|
|
1637
1740
|
stream: append.stream,
|
|
1638
1741
|
state: last.state,
|
|
1639
|
-
version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess',
|
|
1640
|
-
event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess',
|
|
1742
|
+
version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _93 => _93.version]), () => ( last.event.version)),
|
|
1743
|
+
event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _94 => _94.id]), () => ( last.event.id)),
|
|
1641
1744
|
patches: snap_event ? 0 : last.patches,
|
|
1642
1745
|
snaps: snap_event ? last.snaps + 1 : last.snaps
|
|
1643
1746
|
});
|
|
@@ -1653,7 +1756,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1653
1756
|
if (!(error instanceof _chunkQFYPSI6Pcjs.ConcurrencyError)) throw error;
|
|
1654
1757
|
if (expectedVersion !== void 0 && error.stream === stream) throw error;
|
|
1655
1758
|
if (attempt >= max_retries) throw error;
|
|
1656
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1759
|
+
if (_optionalChain([opts, 'optionalAccess', _95 => _95.backoff])) {
|
|
1657
1760
|
const delay_ms = compute_backoff_delay(attempt, opts.backoff);
|
|
1658
1761
|
if (delay_ms > 0) await _chunkQWYMR7ZPcjs.sleep.call(void 0, delay_ms);
|
|
1659
1762
|
}
|
|
@@ -1708,9 +1811,9 @@ var as_of_marker = (asOf) => {
|
|
|
1708
1811
|
return parts.length ? ` (as-of ${parts.join(" ")})` : " (as-of)";
|
|
1709
1812
|
};
|
|
1710
1813
|
var traced = (inner, exit, entry) => (async (...args) => {
|
|
1711
|
-
_optionalChain([entry, 'optionalCall',
|
|
1814
|
+
_optionalChain([entry, 'optionalCall', _96 => _96(...args)]);
|
|
1712
1815
|
const result = await inner(...args);
|
|
1713
|
-
_optionalChain([exit, 'optionalCall',
|
|
1816
|
+
_optionalChain([exit, 'optionalCall', _97 => _97(result, ...args)]);
|
|
1714
1817
|
return result;
|
|
1715
1818
|
});
|
|
1716
1819
|
function build_es(logger, correlator = default_correlator, patch_fn = bare_patch) {
|
|
@@ -1719,7 +1822,7 @@ function build_es(logger, correlator = default_correlator, patch_fn = bare_patch
|
|
|
1719
1822
|
action_name,
|
|
1720
1823
|
target,
|
|
1721
1824
|
payload,
|
|
1722
|
-
{ ...options, correlator: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1825
|
+
{ ...options, correlator: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _98 => _98.correlator]), () => ( correlator)) },
|
|
1723
1826
|
patch_fn
|
|
1724
1827
|
);
|
|
1725
1828
|
const bound_load = (me, target, callback) => load(me, target, callback, patch_fn);
|
|
@@ -1793,7 +1896,7 @@ function build_drain(logger) {
|
|
|
1793
1896
|
subscribe: logger.level !== "trace" ? subscribe : traced(subscribe, (result, streams) => {
|
|
1794
1897
|
if (!result.subscribed) return;
|
|
1795
1898
|
const lanes = new Set(streams.map((s) => _nullishCoalesce(s.lane, () => ( "default"))));
|
|
1796
|
-
const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access',
|
|
1899
|
+
const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _99 => _99[0], 'optionalAccess', _100 => _100.lane]) : void 0;
|
|
1797
1900
|
const data = streams.map(
|
|
1798
1901
|
({ stream, lane }) => uniform_lane || !lane || lane === "default" ? hue(C_STREAM, stream) : `${hue(C_STREAM, stream)}${dim(`[${lane}]`)}`
|
|
1799
1902
|
).join(" ");
|
|
@@ -1805,7 +1908,7 @@ function build_drain(logger) {
|
|
|
1805
1908
|
}
|
|
1806
1909
|
function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
1807
1910
|
if (logger.level !== "trace" || !leased.length) return;
|
|
1808
|
-
const lane = _optionalChain([leased, 'access',
|
|
1911
|
+
const lane = _optionalChain([leased, 'access', _101 => _101[0], 'optionalAccess', _102 => _102.lane]);
|
|
1809
1912
|
const fetch_by_stream = new Map(fetched.map((f) => [f.stream, f]));
|
|
1810
1913
|
const acked_by_stream = new Map(acked.map((a) => [a.stream, a.at]));
|
|
1811
1914
|
const blocked_by_stream = new Map(blocked.map((b) => [b.stream, b.error]));
|
|
@@ -1814,8 +1917,8 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
1814
1917
|
);
|
|
1815
1918
|
const detail = leased.map(({ stream, at, retry }) => {
|
|
1816
1919
|
const f = fetch_by_stream.get(stream);
|
|
1817
|
-
const key = _optionalChain([f, 'optionalAccess',
|
|
1818
|
-
const events = _optionalChain([f, 'optionalAccess',
|
|
1920
|
+
const key = _optionalChain([f, 'optionalAccess', _103 => _103.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
|
|
1921
|
+
const events = _optionalChain([f, 'optionalAccess', _104 => _104.events, 'access', _105 => _105.length]) ? ` ${dim(
|
|
1819
1922
|
`[${f.events.map(({ id, name }) => `#${id} ${String(name)}`).join(", ")}]`
|
|
1820
1923
|
)}` : "";
|
|
1821
1924
|
const acked_at = acked_by_stream.get(stream);
|
|
@@ -1843,7 +1946,7 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
1843
1946
|
|
|
1844
1947
|
// src/internal/drain-cycle.ts
|
|
1845
1948
|
function budget_exhausted(lease, options, store_failing) {
|
|
1846
|
-
if (store_failing || !_optionalChain([options, 'optionalAccess',
|
|
1949
|
+
if (store_failing || !_optionalChain([options, 'optionalAccess', _106 => _106.blockOnError]) || lease.retry <= options.maxRetries)
|
|
1847
1950
|
return void 0;
|
|
1848
1951
|
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.`;
|
|
1849
1952
|
_chunkQWYMR7ZPcjs.log.call(void 0, ).error(error);
|
|
@@ -1907,7 +2010,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
1907
2010
|
const fetched = await ops.fetch(leased, eventLimit);
|
|
1908
2011
|
const fetch_map = /* @__PURE__ */ new Map();
|
|
1909
2012
|
const fetch_window_at = fetched.reduce(
|
|
1910
|
-
(max, { at, events }) => Math.max(max, _optionalChain([events, 'access',
|
|
2013
|
+
(max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _107 => _107.at, 'call', _108 => _108(-1), 'optionalAccess', _109 => _109.id]) || at),
|
|
1911
2014
|
0
|
|
1912
2015
|
);
|
|
1913
2016
|
for (const f of fetched) {
|
|
@@ -1971,11 +2074,11 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
1971
2074
|
deps.logger
|
|
1972
2075
|
)
|
|
1973
2076
|
);
|
|
1974
|
-
const at = _optionalChain([entry, 'access',
|
|
2077
|
+
const at = _optionalChain([entry, 'access', _110 => _110.fetch, 'access', _111 => _111.events, 'access', _112 => _112.at, 'call', _113 => _113(-1), 'optionalAccess', _114 => _114.id]) || fetch_window_at;
|
|
1975
2078
|
const { payloads } = entry;
|
|
1976
2079
|
const exhausted = budget_exhausted(
|
|
1977
2080
|
lease,
|
|
1978
|
-
_optionalChain([payloads, 'access',
|
|
2081
|
+
_optionalChain([payloads, 'access', _115 => _115[0], 'optionalAccess', _116 => _116.options]),
|
|
1979
2082
|
store_failing
|
|
1980
2083
|
);
|
|
1981
2084
|
if (exhausted) return Promise.resolve(exhausted);
|
|
@@ -2060,7 +2163,7 @@ var DrainController = (_class3 = class {
|
|
|
2060
2163
|
}
|
|
2061
2164
|
/** This lane's configured lease, or `undefined`; the shutdown grace basis. */
|
|
2062
2165
|
get lease_millis() {
|
|
2063
|
-
return _optionalChain([this, 'access',
|
|
2166
|
+
return _optionalChain([this, 'access', _117 => _117._deps, 'access', _118 => _118.defaults, 'optionalAccess', _119 => _119.leaseMillis]);
|
|
2064
2167
|
}
|
|
2065
2168
|
get lane() {
|
|
2066
2169
|
return this._deps.lane;
|
|
@@ -2186,11 +2289,11 @@ var CloseSignal = class extends Error {
|
|
|
2186
2289
|
constructor(opts) {
|
|
2187
2290
|
super("reaction requested close");
|
|
2188
2291
|
this.name = "CloseSignal";
|
|
2189
|
-
this.stream = _optionalChain([opts, 'optionalAccess',
|
|
2190
|
-
this.archive = _optionalChain([opts, 'optionalAccess',
|
|
2191
|
-
this.at = _optionalChain([opts, 'optionalAccess',
|
|
2192
|
-
this.before = _optionalChain([opts, 'optionalAccess',
|
|
2193
|
-
this.defer = _optionalChain([opts, 'optionalAccess',
|
|
2292
|
+
this.stream = _optionalChain([opts, 'optionalAccess', _120 => _120.stream]);
|
|
2293
|
+
this.archive = _optionalChain([opts, 'optionalAccess', _121 => _121.archive]);
|
|
2294
|
+
this.at = _optionalChain([opts, 'optionalAccess', _122 => _122.at]);
|
|
2295
|
+
this.before = _optionalChain([opts, 'optionalAccess', _123 => _123.before]);
|
|
2296
|
+
this.defer = _optionalChain([opts, 'optionalAccess', _124 => _124.defer]);
|
|
2194
2297
|
}
|
|
2195
2298
|
};
|
|
2196
2299
|
function build_handle(deps) {
|
|
@@ -2244,7 +2347,7 @@ function build_handle(deps) {
|
|
|
2244
2347
|
// Advance to the live head the handler evaluated against (when
|
|
2245
2348
|
// provided) so the close-cycle guard sees this reaction caught up.
|
|
2246
2349
|
acked_at: _nullishCoalesce(error.at, () => ( event.id)),
|
|
2247
|
-
defer: _optionalChain([error, 'access',
|
|
2350
|
+
defer: _optionalChain([error, 'access', _125 => _125.defer, 'optionalAccess', _126 => _126.getTime, 'call', _127 => _127()]),
|
|
2248
2351
|
// Close the signalled stream (the autoclose reaction's aggregate,
|
|
2249
2352
|
// which differs from its synthetic lease stream); a self-closing
|
|
2250
2353
|
// user reaction omits it and closes its own lease stream. A
|
|
@@ -2341,10 +2444,12 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2341
2444
|
throw new CloseSignal({
|
|
2342
2445
|
stream: aggregate,
|
|
2343
2446
|
archive: archiver ? () => archiver(aggregate, head) : void 0,
|
|
2344
|
-
//
|
|
2345
|
-
//
|
|
2346
|
-
//
|
|
2347
|
-
|
|
2447
|
+
// Hold the head and look again tomorrow: a close skipped for a
|
|
2448
|
+
// lagging reaction, or a failed archive, retries then, and a
|
|
2449
|
+
// closed stream has no head left to act on. The close guard
|
|
2450
|
+
// ignores this parked row, so it doesn't block its own close.
|
|
2451
|
+
at: head.id - 1,
|
|
2452
|
+
defer: days_after(/* @__PURE__ */ new Date(), 1)
|
|
2348
2453
|
});
|
|
2349
2454
|
if (keep_days !== void 0) {
|
|
2350
2455
|
const cutoff = days_before_now(keep_days);
|
|
@@ -2373,7 +2478,7 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2373
2478
|
};
|
|
2374
2479
|
const key = `__autoclose_${st.name}`;
|
|
2375
2480
|
for (const event_name of Object.keys(st.events)) {
|
|
2376
|
-
_optionalChain([registry, 'access',
|
|
2481
|
+
_optionalChain([registry, 'access', _128 => _128.events, 'access', _129 => _129[event_name], 'optionalAccess', _130 => _130.reactions, 'access', _131 => _131.set, 'call', _132 => _132(
|
|
2377
2482
|
key,
|
|
2378
2483
|
reaction
|
|
2379
2484
|
)]);
|
|
@@ -2429,7 +2534,7 @@ async function run_close_cycle(targets, deps) {
|
|
|
2429
2534
|
() => run_full_closes(full, target_map, deps, skipped)
|
|
2430
2535
|
);
|
|
2431
2536
|
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT).map(([stream]) => stream);
|
|
2432
|
-
if (retired.length) _optionalChain([deps, 'access',
|
|
2537
|
+
if (retired.length) _optionalChain([deps, 'access', _133 => _133.forget_subscribed, 'optionalCall', _134 => _134(retired)]);
|
|
2433
2538
|
for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
|
|
2434
2539
|
return { truncated, skipped };
|
|
2435
2540
|
}
|
|
@@ -2449,7 +2554,7 @@ async function run_full_closes(full, target_map, deps, skipped) {
|
|
|
2449
2554
|
const info = stream_info.get(target.stream);
|
|
2450
2555
|
if (!info) continue;
|
|
2451
2556
|
const owner = deps.event_to_state.get(info.last_event_name);
|
|
2452
|
-
if (_optionalChain([owner, 'optionalAccess',
|
|
2557
|
+
if (_optionalChain([owner, 'optionalAccess', _135 => _135.pii_aware])) {
|
|
2453
2558
|
deps.logger.error(
|
|
2454
2559
|
`Refusing to close "${target.stream}" with restart: state "${owner.name}" carries sensitive fields, so a restart seed would persist redacted values while deleting the originals. Close it without restart to retire the stream, or leave it open.`
|
|
2455
2560
|
);
|
|
@@ -2575,8 +2680,8 @@ async function scan_stream_heads(streams) {
|
|
|
2575
2680
|
const true_heads = await _chunkQWYMR7ZPcjs.store.call(void 0, ).query_stats(streams, {});
|
|
2576
2681
|
const out = /* @__PURE__ */ new Map();
|
|
2577
2682
|
for (const [stream, { head }] of domain_heads) {
|
|
2578
|
-
const marker_head = _optionalChain([stats, 'access',
|
|
2579
|
-
const interrupted = _optionalChain([marker_head, 'optionalAccess',
|
|
2683
|
+
const marker_head = _optionalChain([stats, 'access', _136 => _136.get, 'call', _137 => _137(stream), 'optionalAccess', _138 => _138.head]);
|
|
2684
|
+
const interrupted = _optionalChain([marker_head, 'optionalAccess', _139 => _139.name]) === _chunkQFYPSI6Pcjs.TOMBSTONE_EVENT;
|
|
2580
2685
|
out.set(stream, {
|
|
2581
2686
|
max_id: head.id,
|
|
2582
2687
|
version: true_heads.get(stream).head.version,
|
|
@@ -2644,7 +2749,7 @@ async function guard_with_tombstones(safe, stream_info, correlation, tombstone2,
|
|
|
2644
2749
|
async function load_restart_seeds(guarded, target_map, stream_info, event_to_state, load2, logger) {
|
|
2645
2750
|
const seed_states = /* @__PURE__ */ new Map();
|
|
2646
2751
|
await Promise.all(
|
|
2647
|
-
guarded.filter((s) => _optionalChain([target_map, 'access',
|
|
2752
|
+
guarded.filter((s) => _optionalChain([target_map, 'access', _140 => _140.get, 'call', _141 => _141(s), 'optionalAccess', _142 => _142.restart])).map(async (stream) => {
|
|
2648
2753
|
const last_event_name = stream_info.get(stream).last_event_name;
|
|
2649
2754
|
const owner_state = event_to_state.get(last_event_name);
|
|
2650
2755
|
if (!owner_state) {
|
|
@@ -2661,14 +2766,14 @@ async function load_restart_seeds(guarded, target_map, stream_info, event_to_sta
|
|
|
2661
2766
|
}
|
|
2662
2767
|
async function run_archive_callbacks(guarded, target_map) {
|
|
2663
2768
|
for (const stream of guarded) {
|
|
2664
|
-
const archive_fn = _optionalChain([target_map, 'access',
|
|
2769
|
+
const archive_fn = _optionalChain([target_map, 'access', _143 => _143.get, 'call', _144 => _144(stream), 'optionalAccess', _145 => _145.archive]);
|
|
2665
2770
|
if (archive_fn) await archive_fn();
|
|
2666
2771
|
}
|
|
2667
2772
|
}
|
|
2668
2773
|
async function heads_still_guarded(guarded, guard_events, skipped) {
|
|
2669
2774
|
const heads = await _chunkQWYMR7ZPcjs.store.call(void 0, ).query_stats(guarded, {});
|
|
2670
2775
|
return guarded.filter((stream) => {
|
|
2671
|
-
if (_optionalChain([heads, 'access',
|
|
2776
|
+
if (_optionalChain([heads, 'access', _146 => _146.get, 'call', _147 => _147(stream), 'optionalAccess', _148 => _148.head, 'access', _149 => _149.id]) === guard_events.get(stream).id)
|
|
2672
2777
|
return true;
|
|
2673
2778
|
skipped.push(stream);
|
|
2674
2779
|
return false;
|
|
@@ -2813,7 +2918,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2813
2918
|
lane
|
|
2814
2919
|
});
|
|
2815
2920
|
}
|
|
2816
|
-
await _optionalChain([this, 'access',
|
|
2921
|
+
await _optionalChain([this, 'access', _150 => _150._on_init, 'optionalCall', _151 => _151()]);
|
|
2817
2922
|
}
|
|
2818
2923
|
/**
|
|
2819
2924
|
* Replace the log with no pass in flight, then cold-start: a pass that
|
|
@@ -2936,8 +3041,8 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2936
3041
|
correlated_at: void 0
|
|
2937
3042
|
};
|
|
2938
3043
|
const seen_in_scan = correlated.has(resolved.target);
|
|
2939
|
-
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess',
|
|
2940
|
-
const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess',
|
|
3044
|
+
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _152 => _152.lane])), () => ( _chunkQFYPSI6Pcjs.DEFAULT_LANE));
|
|
3045
|
+
const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _153 => _153.priority]);
|
|
2941
3046
|
const resolved_lane = _nullishCoalesce(lane, () => ( _chunkQFYPSI6Pcjs.DEFAULT_LANE));
|
|
2942
3047
|
if (held_priority === priority && held_lane !== resolved_lane)
|
|
2943
3048
|
report_lane_conflict(
|
|
@@ -2992,7 +3097,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2992
3097
|
).length;
|
|
2993
3098
|
this._checkpoint = last_id;
|
|
2994
3099
|
for (const { stream, priority, lane } of streams) {
|
|
2995
|
-
if (_optionalChain([correlated, 'access',
|
|
3100
|
+
if (_optionalChain([correlated, 'access', _154 => _154.get, 'call', _155 => _155(stream), 'optionalAccess', _156 => _156.upgraded]))
|
|
2996
3101
|
this._dynamic_subscriptions.set(stream, {
|
|
2997
3102
|
priority,
|
|
2998
3103
|
lane
|
|
@@ -3231,7 +3336,7 @@ var SettleLoop = (_class6 = class {
|
|
|
3231
3336
|
this._pending = true;
|
|
3232
3337
|
return;
|
|
3233
3338
|
}
|
|
3234
|
-
const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
3339
|
+
const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _157 => _157.debounceMs]), () => ( this._default_debounce_ms));
|
|
3235
3340
|
const due = Date.now() + delay;
|
|
3236
3341
|
if (this._timer) {
|
|
3237
3342
|
if (due >= this._due) return;
|
|
@@ -3477,7 +3582,7 @@ var Act = (_class7 = class {
|
|
|
3477
3582
|
// Apps that declare no lanes pass no lane filter to `claim`.
|
|
3478
3583
|
_build_drain_controllers(options, lanes, handle, handle_batch) {
|
|
3479
3584
|
const all_lanes = this._declared_lanes;
|
|
3480
|
-
const only_set = _optionalChain([options, 'access',
|
|
3585
|
+
const only_set = _optionalChain([options, 'access', _158 => _158.onlyLanes, 'optionalAccess', _159 => _159.length]) ? new Set(options.onlyLanes) : void 0;
|
|
3481
3586
|
const active_lanes = only_set ? all_lanes.filter((n) => only_set.has(n)) : all_lanes;
|
|
3482
3587
|
const single_default_lane = lanes.length === 0;
|
|
3483
3588
|
const controllers = /* @__PURE__ */ new Map();
|
|
@@ -3514,7 +3619,7 @@ var Act = (_class7 = class {
|
|
|
3514
3619
|
leaseMillis: cfg.leaseMillis
|
|
3515
3620
|
}
|
|
3516
3621
|
});
|
|
3517
|
-
if (_optionalChain([cfg, 'optionalAccess',
|
|
3622
|
+
if (_optionalChain([cfg, 'optionalAccess', _160 => _160.cycleMs]) !== void 0 && this._drain)
|
|
3518
3623
|
controller.start(cfg.cycleMs);
|
|
3519
3624
|
controllers.set(name, controller);
|
|
3520
3625
|
}
|
|
@@ -3565,7 +3670,7 @@ var Act = (_class7 = class {
|
|
|
3565
3670
|
await walk_streams(_chunkQWYMR7ZPcjs.store.call(void 0, ), (pos) => {
|
|
3566
3671
|
if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
|
|
3567
3672
|
const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
|
|
3568
|
-
_optionalChain([controller, 'optionalAccess',
|
|
3673
|
+
_optionalChain([controller, 'optionalAccess', _161 => _161.seed_defer, 'call', _162 => _162(pos.stream, pos.deferred_at)]);
|
|
3569
3674
|
});
|
|
3570
3675
|
}
|
|
3571
3676
|
_build_settle(options) {
|
|
@@ -3606,7 +3711,7 @@ var Act = (_class7 = class {
|
|
|
3606
3711
|
for (const c of this._drain_controllers.values()) c.stop();
|
|
3607
3712
|
const disposer = await this._notify_disposer;
|
|
3608
3713
|
if (disposer) await disposer();
|
|
3609
|
-
await this._await_inflight(_optionalChain([options, 'optionalAccess',
|
|
3714
|
+
await this._await_inflight(_optionalChain([options, 'optionalAccess', _163 => _163.graceMs]));
|
|
3610
3715
|
await this._scoped(() => this._correlate.release_correlation());
|
|
3611
3716
|
this._emitter.removeAllListeners();
|
|
3612
3717
|
})();
|
|
@@ -3703,8 +3808,8 @@ var Act = (_class7 = class {
|
|
|
3703
3808
|
* @see {@link ValidationError}, {@link PreconditionError}, {@link ConcurrencyError}
|
|
3704
3809
|
*/
|
|
3705
3810
|
async do(action2, target, payload, options) {
|
|
3706
|
-
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
3707
|
-
const do_options = reacting_to === _optionalChain([options, 'optionalAccess',
|
|
3811
|
+
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _164 => _164.reactingTo]), () => ( _chunkQWYMR7ZPcjs.current_reacting.call(void 0, )));
|
|
3812
|
+
const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _165 => _165.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
|
|
3708
3813
|
return this._scoped(async () => {
|
|
3709
3814
|
const snapshots = await this._es.action(
|
|
3710
3815
|
this.registry.actions[action2],
|
|
@@ -3781,7 +3886,7 @@ var Act = (_class7 = class {
|
|
|
3781
3886
|
const gated = this.registry.query_gate(e.name)(e);
|
|
3782
3887
|
if (!first) first = gated;
|
|
3783
3888
|
last = gated;
|
|
3784
|
-
_optionalChain([callback, 'optionalCall',
|
|
3889
|
+
_optionalChain([callback, 'optionalCall', _166 => _166(gated)]);
|
|
3785
3890
|
}, query);
|
|
3786
3891
|
return { first, last, count };
|
|
3787
3892
|
});
|
|
@@ -3902,7 +4007,7 @@ var Act = (_class7 = class {
|
|
|
3902
4007
|
}
|
|
3903
4008
|
if (to_arm.size === 0) return false;
|
|
3904
4009
|
this._correlate.arm();
|
|
3905
|
-
for (const lane of to_arm) _optionalChain([this, 'access',
|
|
4010
|
+
for (const lane of to_arm) _optionalChain([this, 'access', _167 => _167._drain_controllers, 'access', _168 => _168.get, 'call', _169 => _169(lane), 'optionalAccess', _170 => _170.arm, 'call', _171 => _171()]);
|
|
3906
4011
|
return true;
|
|
3907
4012
|
}
|
|
3908
4013
|
// In parallel, so a slow lane never holds up a fast one.
|
|
@@ -4046,7 +4151,7 @@ var Act = (_class7 = class {
|
|
|
4046
4151
|
return this._scoped(async () => {
|
|
4047
4152
|
const count = await _chunkQWYMR7ZPcjs.store.call(void 0, ).reset(input);
|
|
4048
4153
|
for (const handler of this._batch_handlers.values())
|
|
4049
|
-
_optionalChain([handler, 'access',
|
|
4154
|
+
_optionalChain([handler, 'access', _172 => _172[FOLD_RESET], 'optionalCall', _173 => _173()]);
|
|
4050
4155
|
if (count > 0) {
|
|
4051
4156
|
this._wake();
|
|
4052
4157
|
}
|
|
@@ -4185,7 +4290,7 @@ var Act = (_class7 = class {
|
|
|
4185
4290
|
(p) => {
|
|
4186
4291
|
positions.push(p);
|
|
4187
4292
|
},
|
|
4188
|
-
{ blocked: true, after: _optionalChain([options, 'optionalAccess',
|
|
4293
|
+
{ blocked: true, after: _optionalChain([options, 'optionalAccess', _174 => _174.after]), limit: _optionalChain([options, 'optionalAccess', _175 => _175.limit]) }
|
|
4189
4294
|
);
|
|
4190
4295
|
return positions;
|
|
4191
4296
|
});
|
|
@@ -4558,9 +4663,9 @@ function reaction_on(event, events, builder) {
|
|
|
4558
4663
|
// `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
|
|
4559
4664
|
// not a NaN gate on the first retry.
|
|
4560
4665
|
options: _chunkQWYMR7ZPcjs.resolveReactionConfig.call(void 0, {
|
|
4561
|
-
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4562
|
-
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4563
|
-
backoff: _optionalChain([options, 'optionalAccess',
|
|
4666
|
+
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _176 => _176.blockOnError]), () => ( _chunkQWYMR7ZPcjs.DEFAULT_BLOCK_ON_ERROR)),
|
|
4667
|
+
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _177 => _177.maxRetries]), () => ( _chunkQWYMR7ZPcjs.DEFAULT_MAX_RETRIES)),
|
|
4668
|
+
backoff: _optionalChain([options, 'optionalAccess', _178 => _178.backoff])
|
|
4564
4669
|
})
|
|
4565
4670
|
};
|
|
4566
4671
|
},
|
|
@@ -4576,98 +4681,6 @@ function reaction_on(event, events, builder) {
|
|
|
4576
4681
|
|
|
4577
4682
|
// src/builders/event-builder.ts
|
|
4578
4683
|
|
|
4579
|
-
|
|
4580
|
-
// src/internal/date-reviver.ts
|
|
4581
|
-
|
|
4582
|
-
function variant_schema(schema, walk) {
|
|
4583
|
-
const shape = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, schema), 'optionalAccess', _168 => _168.shape]);
|
|
4584
|
-
if (!shape) {
|
|
4585
|
-
const dates = walk(schema);
|
|
4586
|
-
return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
|
|
4587
|
-
}
|
|
4588
|
-
const next = {};
|
|
4589
|
-
let dated = false;
|
|
4590
|
-
for (const [key, field] of Object.entries(shape)) {
|
|
4591
|
-
const dates = walk(field);
|
|
4592
|
-
if (dates) dated = true;
|
|
4593
|
-
next[key] = (_nullishCoalesce(dates, () => ( field))).optional();
|
|
4594
|
-
}
|
|
4595
|
-
return { schema: _zod.z.looseObject(next), dated };
|
|
4596
|
-
}
|
|
4597
|
-
function date_reviver_schema(schema) {
|
|
4598
|
-
let recursive = false;
|
|
4599
|
-
const pass = (tie) => {
|
|
4600
|
-
const done = /* @__PURE__ */ new Map();
|
|
4601
|
-
const active = /* @__PURE__ */ new Set();
|
|
4602
|
-
const walk = (node) => {
|
|
4603
|
-
if (done.has(node)) return done.get(node);
|
|
4604
|
-
if (active.has(node)) {
|
|
4605
|
-
recursive = true;
|
|
4606
|
-
return tie ? _zod.z.lazy(() => done.get(node)) : void 0;
|
|
4607
|
-
}
|
|
4608
|
-
active.add(node);
|
|
4609
|
-
const result = build(node, walk);
|
|
4610
|
-
active.delete(node);
|
|
4611
|
-
done.set(node, result);
|
|
4612
|
-
return result;
|
|
4613
|
-
};
|
|
4614
|
-
return walk(schema);
|
|
4615
|
-
};
|
|
4616
|
-
const first = pass(false);
|
|
4617
|
-
return first && recursive ? pass(true) : first;
|
|
4618
|
-
}
|
|
4619
|
-
function build(schema, walk) {
|
|
4620
|
-
const def = _chunkQFYPSI6Pcjs.def_of.call(void 0, schema);
|
|
4621
|
-
if (!def) return void 0;
|
|
4622
|
-
const inner = () => walk(def.innerType);
|
|
4623
|
-
switch (def.type) {
|
|
4624
|
-
case "date":
|
|
4625
|
-
return _zod.z.coerce.date();
|
|
4626
|
-
case "object": {
|
|
4627
|
-
const shape = def.shape;
|
|
4628
|
-
if (!shape) return void 0;
|
|
4629
|
-
const dated = {};
|
|
4630
|
-
for (const [key, field] of Object.entries(shape)) {
|
|
4631
|
-
const dates = walk(field);
|
|
4632
|
-
if (dates) dated[key] = dates.optional();
|
|
4633
|
-
}
|
|
4634
|
-
return Object.keys(dated).length ? _zod.z.looseObject(dated) : void 0;
|
|
4635
|
-
}
|
|
4636
|
-
case "array": {
|
|
4637
|
-
const element = walk(def.element);
|
|
4638
|
-
return element && _zod.z.array(element);
|
|
4639
|
-
}
|
|
4640
|
-
case "tuple": {
|
|
4641
|
-
const items = def.items.map((i) => walk(i));
|
|
4642
|
-
return items.some(Boolean) ? _zod.z.tuple(items.map((i) => _nullishCoalesce(i, () => ( _zod.z.unknown())))) : void 0;
|
|
4643
|
-
}
|
|
4644
|
-
case "record": {
|
|
4645
|
-
const value = walk(def.valueType);
|
|
4646
|
-
return value && _zod.z.record(_zod.z.string(), value);
|
|
4647
|
-
}
|
|
4648
|
-
case "union": {
|
|
4649
|
-
const variants = def.options.map(
|
|
4650
|
-
(o) => variant_schema(o, walk)
|
|
4651
|
-
);
|
|
4652
|
-
return variants.some((v) => v.dated) ? _zod.z.union(variants.map((v) => v.schema)) : void 0;
|
|
4653
|
-
}
|
|
4654
|
-
case "nullable":
|
|
4655
|
-
return _optionalChain([inner, 'call', _169 => _169(), 'optionalAccess', _170 => _170.nullable, 'call', _171 => _171()]);
|
|
4656
|
-
case "pipe":
|
|
4657
|
-
return walk(def.out);
|
|
4658
|
-
case "lazy":
|
|
4659
|
-
return walk(def.getter());
|
|
4660
|
-
case "intersection": {
|
|
4661
|
-
const left = walk(def.left);
|
|
4662
|
-
const right = walk(def.right);
|
|
4663
|
-
return left && right ? left.pipe(right) : _nullishCoalesce(left, () => ( right));
|
|
4664
|
-
}
|
|
4665
|
-
default:
|
|
4666
|
-
return _chunkQFYPSI6Pcjs.inner_of.call(void 0, def) ? inner() : void 0;
|
|
4667
|
-
}
|
|
4668
|
-
}
|
|
4669
|
-
|
|
4670
|
-
// src/builders/event-builder.ts
|
|
4671
4684
|
function event_tags(schema) {
|
|
4672
4685
|
const pii = _chunkQFYPSI6Pcjs.pii_schemas.call(void 0, schema);
|
|
4673
4686
|
const pii_dates = {};
|
|
@@ -4790,7 +4803,7 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4790
4803
|
return { sensitive: sensitive2, advisory, query_readers, handler_readers };
|
|
4791
4804
|
}
|
|
4792
4805
|
function reads_as_string(schema) {
|
|
4793
|
-
const type = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, _chunkQFYPSI6Pcjs.output_of.call(void 0, schema)), 'optionalAccess',
|
|
4806
|
+
const type = _optionalChain([_chunkQFYPSI6Pcjs.def_of.call(void 0, _chunkQFYPSI6Pcjs.output_of.call(void 0, schema)), 'optionalAccess', _179 => _179.type]);
|
|
4794
4807
|
return type === "string" || type === "transform";
|
|
4795
4808
|
}
|
|
4796
4809
|
|
|
@@ -4848,7 +4861,7 @@ function act() {
|
|
|
4848
4861
|
let _built = false;
|
|
4849
4862
|
const read_wrap = (original) => {
|
|
4850
4863
|
const wrapped = async (events, stream) => {
|
|
4851
|
-
const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access',
|
|
4864
|
+
const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _180 => _180.get, 'call', _181 => _181(e.name), 'optionalCall', _182 => _182(e)]), () => ( e)));
|
|
4852
4865
|
return original(read, stream);
|
|
4853
4866
|
};
|
|
4854
4867
|
const reset = original[FOLD_RESET];
|
|
@@ -4889,7 +4902,7 @@ function act() {
|
|
|
4889
4902
|
});
|
|
4890
4903
|
}
|
|
4891
4904
|
for (const [action_name, handler] of Object.entries(state2.on)) {
|
|
4892
|
-
const static_target = _optionalChain([handler, 'optionalAccess',
|
|
4905
|
+
const static_target = _optionalChain([handler, 'optionalAccess', _183 => _183._static_emit]);
|
|
4893
4906
|
if (static_target && deprecated.has(static_target)) {
|
|
4894
4907
|
const current = current_version_of(static_target, event_names);
|
|
4895
4908
|
throw new Error(
|
|
@@ -4962,7 +4975,7 @@ function act() {
|
|
|
4962
4975
|
`State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
|
|
4963
4976
|
);
|
|
4964
4977
|
const claimed = fold_specs.find((s) => s.target === proj.target);
|
|
4965
|
-
if (_optionalChain([claimed, 'optionalAccess',
|
|
4978
|
+
if (_optionalChain([claimed, 'optionalAccess', _184 => _184.projection]) === proj) continue;
|
|
4966
4979
|
if (batch_handlers.has(proj.target) || claimed)
|
|
4967
4980
|
throw new Error(
|
|
4968
4981
|
`Duplicate projection target "${proj.target}" \u2014 a target is served by one batch handler or one state projection, never both`
|
|
@@ -4996,7 +5009,7 @@ function act() {
|
|
|
4996
5009
|
`Action "${action2}" loads "${l.state.name}", which is not registered \u2014 add it via withState/withSlice before build()`
|
|
4997
5010
|
);
|
|
4998
5011
|
const deprecated = l.events.find(
|
|
4999
|
-
(e) => _optionalChain([_de, 'access',
|
|
5012
|
+
(e) => _optionalChain([_de, 'access', _185 => _185.get, 'call', _186 => _186(registered.name), 'optionalAccess', _187 => _187.has, 'call', _188 => _188(e)])
|
|
5000
5013
|
);
|
|
5001
5014
|
if (deprecated)
|
|
5002
5015
|
throw new Error(
|