@rotorsoft/act 2.0.1 → 2.0.3
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/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/builders/state-builder.d.ts.map +1 -1
- package/dist/@types/internal/autoclose-policy.d.ts +0 -9
- package/dist/@types/internal/autoclose-policy.d.ts.map +1 -1
- package/dist/@types/utils.d.ts +46 -0
- package/dist/@types/utils.d.ts.map +1 -1
- package/dist/{chunk-UO7HNLSH.js → chunk-ESFICIG2.js} +3 -3
- package/dist/{chunk-S2BEPQ5Z.cjs → chunk-KGJQXN3S.cjs} +47 -25
- package/dist/chunk-KGJQXN3S.cjs.map +1 -0
- package/dist/{chunk-3CQWJ4UA.cjs → chunk-VD4BLAY4.cjs} +2 -2
- package/dist/{chunk-3CQWJ4UA.cjs.map → chunk-VD4BLAY4.cjs.map} +1 -1
- package/dist/{chunk-33D5NQNQ.js → chunk-YAHM7P64.js} +37 -15
- package/dist/chunk-YAHM7P64.js.map +1 -0
- package/dist/index.cjs +240 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +4 -4
- package/dist/test/index.js +2 -2
- package/dist/types/index.cjs +2 -2
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-33D5NQNQ.js.map +0 -1
- package/dist/chunk-S2BEPQ5Z.cjs.map +0 -1
- /package/dist/{chunk-UO7HNLSH.js.map → chunk-ESFICIG2.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
var _chunkS2BEPQ5Zcjs = require('./chunk-S2BEPQ5Z.cjs');
|
|
48
47
|
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
|
|
51
|
+
var _chunkKGJQXN3Scjs = require('./chunk-KGJQXN3S.cjs');
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
|
|
@@ -77,24 +77,28 @@ var _chunkS2BEPQ5Zcjs = require('./chunk-S2BEPQ5Z.cjs');
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
var _chunkVD4BLAY4cjs = require('./chunk-VD4BLAY4.cjs');
|
|
81
85
|
|
|
82
86
|
// src/signals.ts
|
|
83
87
|
process.once("SIGINT", async (arg) => {
|
|
84
|
-
|
|
85
|
-
await
|
|
88
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).info(arg, "SIGINT");
|
|
89
|
+
await _chunkKGJQXN3Scjs.disposeAndExit.call(void 0, "EXIT");
|
|
86
90
|
});
|
|
87
91
|
process.once("SIGTERM", async (arg) => {
|
|
88
|
-
|
|
89
|
-
await
|
|
92
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).info(arg, "SIGTERM");
|
|
93
|
+
await _chunkKGJQXN3Scjs.disposeAndExit.call(void 0, "EXIT");
|
|
90
94
|
});
|
|
91
95
|
process.once("uncaughtException", async (arg) => {
|
|
92
|
-
|
|
93
|
-
await
|
|
96
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).error(arg, "Uncaught Exception");
|
|
97
|
+
await _chunkKGJQXN3Scjs.disposeAndExit.call(void 0, "ERROR");
|
|
94
98
|
});
|
|
95
99
|
process.once("unhandledRejection", async (arg) => {
|
|
96
|
-
|
|
97
|
-
await
|
|
100
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).error(arg, "Unhandled Rejection");
|
|
101
|
+
await _chunkKGJQXN3Scjs.disposeAndExit.call(void 0, "ERROR");
|
|
98
102
|
});
|
|
99
103
|
|
|
100
104
|
// src/act.ts
|
|
@@ -202,7 +206,7 @@ async function* audit(deps, categories, options = {}) {
|
|
|
202
206
|
if (need_stats) {
|
|
203
207
|
const stats = await deps.store().query_stats(
|
|
204
208
|
{},
|
|
205
|
-
{ count: true, names: true, exclude: [
|
|
209
|
+
{ count: true, names: true, exclude: [_chunkVD4BLAY4cjs.SNAP_EVENT] }
|
|
206
210
|
);
|
|
207
211
|
for (const [stream, s] of stats) {
|
|
208
212
|
for (const p of passes) _optionalChain([p, 'access', _4 => _4.on_stat, 'optionalCall', _5 => _5(stream, s)]);
|
|
@@ -284,7 +288,7 @@ var make_schema_pass = (deps) => {
|
|
|
284
288
|
return;
|
|
285
289
|
}
|
|
286
290
|
const schema = state2.events[name];
|
|
287
|
-
const sensitive2 =
|
|
291
|
+
const sensitive2 = _chunkVD4BLAY4cjs.pii_fields.call(void 0, schema);
|
|
288
292
|
let parse_schema = schema;
|
|
289
293
|
if (sensitive2.length > 0) {
|
|
290
294
|
const omitter = schema.omit;
|
|
@@ -418,7 +422,7 @@ var make_restart_candidate_pass = (deps, options) => {
|
|
|
418
422
|
{
|
|
419
423
|
stream,
|
|
420
424
|
stream_exact: true,
|
|
421
|
-
names: [
|
|
425
|
+
names: [_chunkVD4BLAY4cjs.SNAP_EVENT],
|
|
422
426
|
with_snaps: true,
|
|
423
427
|
// From the start: on its own, `with_snaps` resumes at the latest.
|
|
424
428
|
after: -1
|
|
@@ -578,7 +582,7 @@ var make_correlation_gaps_pass = () => {
|
|
|
578
582
|
seen_ids.add(e.id);
|
|
579
583
|
const causation = _optionalChain([e, 'access', _31 => _31.meta, 'optionalAccess', _32 => _32.causation]);
|
|
580
584
|
const parent_id = _optionalChain([causation, 'optionalAccess', _33 => _33.event, 'optionalAccess', _34 => _34.id]);
|
|
581
|
-
if (parent_id !== void 0 && e.name !==
|
|
585
|
+
if (parent_id !== void 0 && e.name !== _chunkVD4BLAY4cjs.TOMBSTONE_EVENT) {
|
|
582
586
|
checks.push({ stream: e.stream, id: e.id, parent_id });
|
|
583
587
|
}
|
|
584
588
|
},
|
|
@@ -862,20 +866,13 @@ function compile_is(is) {
|
|
|
862
866
|
function compile_reaches(reaches) {
|
|
863
867
|
return (_stream, _head, count) => count >= reaches;
|
|
864
868
|
}
|
|
865
|
-
function policy_min_after_days(options) {
|
|
866
|
-
const parsed = AutoclosePolicySchema.parse(options);
|
|
867
|
-
const windows = [];
|
|
868
|
-
if (parsed.after) windows.push(parsed.after.days);
|
|
869
|
-
if (_optionalChain([parsed, 'access', _42 => _42.or, 'optionalAccess', _43 => _43.after])) windows.push(parsed.or.after.days);
|
|
870
|
-
return windows.length ? Math.min(...windows) : void 0;
|
|
871
|
-
}
|
|
872
869
|
function policy_after_windows(options) {
|
|
873
870
|
const parsed = AutoclosePolicySchema.parse(options);
|
|
874
|
-
return [parsed.after, _optionalChain([parsed, 'access',
|
|
871
|
+
return [parsed.after, _optionalChain([parsed, 'access', _42 => _42.or, 'optionalAccess', _43 => _43.after])].flatMap((w) => w ? [w.days] : []);
|
|
875
872
|
}
|
|
876
873
|
function policy_keep_days(options) {
|
|
877
874
|
const parsed = AutoclosePolicySchema.parse(options);
|
|
878
|
-
return _optionalChain([parsed, 'access',
|
|
875
|
+
return _optionalChain([parsed, 'access', _44 => _44.keep, 'optionalAccess', _45 => _45.days]);
|
|
879
876
|
}
|
|
880
877
|
function compile_autoclose_policy(options) {
|
|
881
878
|
const parsed = AutoclosePolicySchema.parse(options);
|
|
@@ -907,7 +904,7 @@ function hour_in_zone(now, timeZone) {
|
|
|
907
904
|
hour: "2-digit",
|
|
908
905
|
hourCycle: "h23"
|
|
909
906
|
}).formatToParts(now);
|
|
910
|
-
return Number(_optionalChain([parts, 'access',
|
|
907
|
+
return Number(_optionalChain([parts, 'access', _46 => _46.find, 'call', _47 => _47((p) => p.type === "hour"), 'optionalAccess', _48 => _48.value]));
|
|
911
908
|
}
|
|
912
909
|
function hour_in_range(hour, start, end) {
|
|
913
910
|
return start < end ? hour >= start && hour < end : hour >= start || hour < end;
|
|
@@ -968,7 +965,7 @@ function make_deferred(handler, schedule) {
|
|
|
968
965
|
const call = handler;
|
|
969
966
|
const deferred = async (event, stream, app) => {
|
|
970
967
|
const when = typeof schedule === "function" ? schedule(event) : schedule;
|
|
971
|
-
if (Date.now() < resolve_defer_at(when, event)) throw new (0,
|
|
968
|
+
if (Date.now() < resolve_defer_at(when, event)) throw new (0, _chunkVD4BLAY4cjs.DeferSignal)(when);
|
|
972
969
|
return call(event, stream, app);
|
|
973
970
|
};
|
|
974
971
|
Object.defineProperty(deferred, "name", { value: handler.name });
|
|
@@ -1100,7 +1097,7 @@ function compute_lag_lead_ratio(handled, lagging, leading) {
|
|
|
1100
1097
|
function report_once(seen, key, message) {
|
|
1101
1098
|
if (seen.has(key)) return;
|
|
1102
1099
|
seen.add(key);
|
|
1103
|
-
|
|
1100
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).error(new Error(message));
|
|
1104
1101
|
}
|
|
1105
1102
|
|
|
1106
1103
|
// src/internal/correlation-id.ts
|
|
@@ -1128,14 +1125,14 @@ function close_correlation(correlator, actor) {
|
|
|
1128
1125
|
}
|
|
1129
1126
|
|
|
1130
1127
|
// src/internal/drain-ops.ts
|
|
1131
|
-
var claim = (lagging, leading, by, millis, lane) =>
|
|
1128
|
+
var claim = (lagging, leading, by, millis, lane) => _chunkKGJQXN3Scjs.store.call(void 0, ).claim(lagging, leading, by, millis, lane);
|
|
1132
1129
|
async function fetch(leased, eventLimit) {
|
|
1133
1130
|
return Promise.all(
|
|
1134
1131
|
leased.map(async ({ stream, source, at, lagging }) => {
|
|
1135
1132
|
const events = [];
|
|
1136
|
-
const stream_exact = source !== void 0 &&
|
|
1133
|
+
const stream_exact = source !== void 0 && _chunkKGJQXN3Scjs.is_literal_source.call(void 0, source, stream) ? true : void 0;
|
|
1137
1134
|
try {
|
|
1138
|
-
await
|
|
1135
|
+
await _chunkKGJQXN3Scjs.store.call(void 0, ).query((e) => events.push(e), {
|
|
1139
1136
|
stream: source,
|
|
1140
1137
|
stream_exact,
|
|
1141
1138
|
after: at,
|
|
@@ -1148,23 +1145,23 @@ async function fetch(leased, eventLimit) {
|
|
|
1148
1145
|
at,
|
|
1149
1146
|
lagging,
|
|
1150
1147
|
events: [],
|
|
1151
|
-
error: _nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1148
|
+
error: _nullishCoalesce(_optionalChain([error, 'optionalAccess', _49 => _49.message]), () => ( String(error)))
|
|
1152
1149
|
};
|
|
1153
1150
|
}
|
|
1154
1151
|
return { stream, source, at, lagging, events };
|
|
1155
1152
|
})
|
|
1156
1153
|
);
|
|
1157
1154
|
}
|
|
1158
|
-
var ack = (leases) =>
|
|
1159
|
-
var block = (leases) =>
|
|
1160
|
-
var subscribe = (streams, correlated_at, correlator) =>
|
|
1155
|
+
var ack = (leases) => _chunkKGJQXN3Scjs.store.call(void 0, ).ack(leases);
|
|
1156
|
+
var block = (leases) => _chunkKGJQXN3Scjs.store.call(void 0, ).block(leases);
|
|
1157
|
+
var subscribe = (streams, correlated_at, correlator) => _chunkKGJQXN3Scjs.store.call(void 0, ).subscribe(streams, correlated_at, correlator);
|
|
1161
1158
|
|
|
1162
1159
|
// src/internal/event-sourcing.ts
|
|
1163
1160
|
var _actpatch = require('@rotorsoft/act-patch');
|
|
1164
1161
|
|
|
1165
1162
|
var bare_patch = (_me, state2, partial) => _actpatch.patch.call(void 0, state2, partial);
|
|
1166
1163
|
var value_at = (value, path) => path.reduce(
|
|
1167
|
-
(at, key) => _optionalChain([at, 'optionalAccess',
|
|
1164
|
+
(at, key) => _optionalChain([at, 'optionalAccess', _50 => _50[key]]),
|
|
1168
1165
|
value
|
|
1169
1166
|
);
|
|
1170
1167
|
var check_invariants = (target, state2, schema, pii_aware) => {
|
|
@@ -1172,29 +1169,29 @@ var check_invariants = (target, state2, schema, pii_aware) => {
|
|
|
1172
1169
|
try {
|
|
1173
1170
|
result = schema.safeParse(state2);
|
|
1174
1171
|
} catch (error) {
|
|
1175
|
-
throw new (0,
|
|
1172
|
+
throw new (0, _chunkVD4BLAY4cjs.ValidationError)(target, state2, error);
|
|
1176
1173
|
}
|
|
1177
1174
|
if (result.success) return;
|
|
1178
1175
|
const issues = pii_aware ? result.error.issues.filter((issue) => {
|
|
1179
1176
|
const value = value_at(state2, issue.path);
|
|
1180
|
-
return value !==
|
|
1177
|
+
return value !== _chunkVD4BLAY4cjs.REDACTED && value !== _chunkVD4BLAY4cjs.SHREDDED;
|
|
1181
1178
|
}) : result.error.issues;
|
|
1182
1179
|
if (issues.length)
|
|
1183
|
-
throw new (0,
|
|
1180
|
+
throw new (0, _chunkVD4BLAY4cjs.ValidationError)(
|
|
1184
1181
|
target,
|
|
1185
1182
|
state2,
|
|
1186
1183
|
_zod.prettifyError.call(void 0, new (0, _zod.ZodError)(issues))
|
|
1187
1184
|
);
|
|
1188
1185
|
};
|
|
1189
1186
|
var DEFAULT_BATCH = 500;
|
|
1190
|
-
var cache_put = (stream, entry) =>
|
|
1191
|
-
(err) =>
|
|
1187
|
+
var cache_put = (stream, entry) => _chunkKGJQXN3Scjs.cache.call(void 0, ).set(stream, entry).catch(
|
|
1188
|
+
(err) => _chunkKGJQXN3Scjs.log.call(void 0, ).warn(
|
|
1192
1189
|
err,
|
|
1193
1190
|
"cache set skipped; the next load re-folds from the store"
|
|
1194
1191
|
)
|
|
1195
1192
|
);
|
|
1196
|
-
var cache_drop = (stream) =>
|
|
1197
|
-
(err) =>
|
|
1193
|
+
var cache_drop = (stream) => _chunkKGJQXN3Scjs.cache.call(void 0, ).invalidate(stream).catch(
|
|
1194
|
+
(err) => _chunkKGJQXN3Scjs.log.call(void 0, ).warn(
|
|
1198
1195
|
err,
|
|
1199
1196
|
"cache invalidate skipped; a stale checkpoint re-folds from its event_id"
|
|
1200
1197
|
)
|
|
@@ -1202,11 +1199,11 @@ var cache_drop = (stream) => _chunkS2BEPQ5Zcjs.cache.call(void 0, ).invalidate(s
|
|
|
1202
1199
|
async function snap(snapshot) {
|
|
1203
1200
|
const { id, stream, name, meta, version } = snapshot.event;
|
|
1204
1201
|
try {
|
|
1205
|
-
const [committed] = await
|
|
1202
|
+
const [committed] = await _chunkKGJQXN3Scjs.store.call(void 0, ).commit(
|
|
1206
1203
|
[
|
|
1207
1204
|
{
|
|
1208
1205
|
stream,
|
|
1209
|
-
msgs: [{ name:
|
|
1206
|
+
msgs: [{ name: _chunkVD4BLAY4cjs.SNAP_EVENT, data: snapshot.state }],
|
|
1210
1207
|
// IMPORTANT! - state events are committed right after the snapshot event
|
|
1211
1208
|
expectedVersion: version
|
|
1212
1209
|
}
|
|
@@ -1219,18 +1216,18 @@ async function snap(snapshot) {
|
|
|
1219
1216
|
return committed;
|
|
1220
1217
|
} catch (error) {
|
|
1221
1218
|
const reason = error instanceof Error ? error.message : String(error);
|
|
1222
|
-
|
|
1219
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).warn(
|
|
1223
1220
|
`Snapshot write failed on stream "${stream}": ${reason} \u2014 cold starts will replay full history until snapshots succeed.`
|
|
1224
1221
|
);
|
|
1225
1222
|
}
|
|
1226
1223
|
}
|
|
1227
1224
|
async function tombstone(stream, expectedVersion, correlation) {
|
|
1228
1225
|
try {
|
|
1229
|
-
const [committed] = await
|
|
1226
|
+
const [committed] = await _chunkKGJQXN3Scjs.store.call(void 0, ).commit(
|
|
1230
1227
|
[
|
|
1231
1228
|
{
|
|
1232
1229
|
stream,
|
|
1233
|
-
msgs: [{ name:
|
|
1230
|
+
msgs: [{ name: _chunkVD4BLAY4cjs.TOMBSTONE_EVENT, data: {} }],
|
|
1234
1231
|
expectedVersion
|
|
1235
1232
|
}
|
|
1236
1233
|
],
|
|
@@ -1238,7 +1235,7 @@ async function tombstone(stream, expectedVersion, correlation) {
|
|
|
1238
1235
|
);
|
|
1239
1236
|
return committed;
|
|
1240
1237
|
} catch (error) {
|
|
1241
|
-
if (error instanceof
|
|
1238
|
+
if (error instanceof _chunkVD4BLAY4cjs.ConcurrencyError) return void 0;
|
|
1242
1239
|
throw error;
|
|
1243
1240
|
}
|
|
1244
1241
|
}
|
|
@@ -1268,9 +1265,9 @@ async function scan(source, opts = {}, callback) {
|
|
|
1268
1265
|
if (drop_closed_streams) {
|
|
1269
1266
|
await source.query(
|
|
1270
1267
|
(e) => {
|
|
1271
|
-
if (e.name ===
|
|
1268
|
+
if (e.name === _chunkVD4BLAY4cjs.TOMBSTONE_EVENT) closed_streams.add(e.stream);
|
|
1272
1269
|
},
|
|
1273
|
-
{ names: [
|
|
1270
|
+
{ names: [_chunkVD4BLAY4cjs.TOMBSTONE_EVENT] }
|
|
1274
1271
|
);
|
|
1275
1272
|
}
|
|
1276
1273
|
let max_id;
|
|
@@ -1292,16 +1289,16 @@ async function scan(source, opts = {}, callback) {
|
|
|
1292
1289
|
if (!is_valid(event))
|
|
1293
1290
|
throw new Error(`Invalid event at index ${processed}`);
|
|
1294
1291
|
if (on_progress) on_progress({ processed, id: event.id, max_id });
|
|
1295
|
-
if (drop_snapshots && event.name ===
|
|
1292
|
+
if (drop_snapshots && event.name === _chunkVD4BLAY4cjs.SNAP_EVENT) {
|
|
1296
1293
|
dropped_snaps++;
|
|
1297
1294
|
return;
|
|
1298
1295
|
}
|
|
1299
|
-
if (closed_streams.has(event.stream) && event.name !==
|
|
1296
|
+
if (closed_streams.has(event.stream) && event.name !== _chunkVD4BLAY4cjs.TOMBSTONE_EVENT) {
|
|
1300
1297
|
dropped_closed++;
|
|
1301
1298
|
return;
|
|
1302
1299
|
}
|
|
1303
1300
|
let migrated = event;
|
|
1304
|
-
const migration = _optionalChain([event_migrations, 'optionalAccess',
|
|
1301
|
+
const migration = _optionalChain([event_migrations, 'optionalAccess', _51 => _51[event.name]]);
|
|
1305
1302
|
if (migration) {
|
|
1306
1303
|
const old_data = migration.from_schema.parse(event.data);
|
|
1307
1304
|
const new_data = migration.migrate(old_data);
|
|
@@ -1323,7 +1320,7 @@ async function scan(source, opts = {}, callback) {
|
|
|
1323
1320
|
return;
|
|
1324
1321
|
}
|
|
1325
1322
|
let remapped = migrated;
|
|
1326
|
-
const caused_by = _optionalChain([migrated, 'access',
|
|
1323
|
+
const caused_by = _optionalChain([migrated, 'access', _52 => _52.meta, 'access', _53 => _53.causation, 'access', _54 => _54.event, 'optionalAccess', _55 => _55.id]);
|
|
1327
1324
|
if (caused_by !== void 0) {
|
|
1328
1325
|
const new_caused_by = id_map.get(caused_by);
|
|
1329
1326
|
if (new_caused_by !== void 0 && new_caused_by !== caused_by) {
|
|
@@ -1364,18 +1361,18 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1364
1361
|
const { stream, actor, asOf } = target;
|
|
1365
1362
|
const time_travel = !!asOf && Object.values(asOf).some((v) => v !== void 0);
|
|
1366
1363
|
const seeded = time_travel && asOf.limit === void 0 && !asOf.created_after;
|
|
1367
|
-
const cached = time_travel ? void 0 : await
|
|
1364
|
+
const cached = time_travel ? void 0 : await _chunkKGJQXN3Scjs.cache.call(void 0, ).get(stream);
|
|
1368
1365
|
const cache_hit = !!cached;
|
|
1369
|
-
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1370
|
-
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1371
|
-
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess',
|
|
1366
|
+
let state2 = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _56 => _56.state]), () => ( (me.init ? me.init() : {})));
|
|
1367
|
+
let patches = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _57 => _57.patches]), () => ( 0));
|
|
1368
|
+
let snaps = _nullishCoalesce(_optionalChain([cached, 'optionalAccess', _58 => _58.snaps]), () => ( 0));
|
|
1372
1369
|
let replayed = 0;
|
|
1373
1370
|
let event;
|
|
1374
|
-
await
|
|
1371
|
+
await _chunkKGJQXN3Scjs.store.call(void 0, ).query(
|
|
1375
1372
|
(raw) => {
|
|
1376
|
-
if (seeded && raw.name ===
|
|
1373
|
+
if (seeded && raw.name === _chunkVD4BLAY4cjs.SNAP_EVENT && replayed > 0) return;
|
|
1377
1374
|
event = me.view(raw, actor);
|
|
1378
|
-
if (event.name ===
|
|
1375
|
+
if (event.name === _chunkVD4BLAY4cjs.SNAP_EVENT) {
|
|
1379
1376
|
state2 = event.data;
|
|
1380
1377
|
snaps++;
|
|
1381
1378
|
patches = 0;
|
|
@@ -1384,12 +1381,12 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1384
1381
|
state2 = patch_fn(me, state2, me.patch[event.name](event, state2), event);
|
|
1385
1382
|
patches++;
|
|
1386
1383
|
replayed++;
|
|
1387
|
-
} else if (event.name !==
|
|
1388
|
-
|
|
1384
|
+
} else if (event.name !== _chunkVD4BLAY4cjs.TOMBSTONE_EVENT) {
|
|
1385
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).warn(
|
|
1389
1386
|
`Skipping unknown event "${String(event.name)}" on stream "${stream}" (id=${event.id}) \u2014 no reducer in state "${me.name}"`
|
|
1390
1387
|
);
|
|
1391
1388
|
}
|
|
1392
|
-
_optionalChain([callback, 'optionalCall',
|
|
1389
|
+
_optionalChain([callback, 'optionalCall', _59 => _59({
|
|
1393
1390
|
event,
|
|
1394
1391
|
state: state2,
|
|
1395
1392
|
version: event.version,
|
|
@@ -1413,7 +1410,7 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1413
1410
|
) : time_travel ? asOf : { with_snaps: true }
|
|
1414
1411
|
}
|
|
1415
1412
|
);
|
|
1416
|
-
const head_is_tombstone = _optionalChain([event, 'optionalAccess',
|
|
1413
|
+
const head_is_tombstone = _optionalChain([event, 'optionalAccess', _60 => _60.name]) === _chunkVD4BLAY4cjs.TOMBSTONE_EVENT;
|
|
1417
1414
|
if (replayed > 0 && !time_travel && event && !me.pii_aware && !head_is_tombstone) {
|
|
1418
1415
|
await cache_put(stream, {
|
|
1419
1416
|
stream,
|
|
@@ -1427,9 +1424,9 @@ async function load(me, target, callback, patch_fn = bare_patch) {
|
|
|
1427
1424
|
return {
|
|
1428
1425
|
event,
|
|
1429
1426
|
state: state2,
|
|
1430
|
-
version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess',
|
|
1427
|
+
version: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _61 => _61.version]), () => ( _optionalChain([cached, 'optionalAccess', _62 => _62.version]))), () => ( -1)),
|
|
1431
1428
|
// Captured with `state`, so consumers never race a separate cache lookup.
|
|
1432
|
-
id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess',
|
|
1429
|
+
id: _nullishCoalesce(_nullishCoalesce(_optionalChain([event, 'optionalAccess', _63 => _63.id]), () => ( _optionalChain([cached, 'optionalAccess', _64 => _64.event_id]))), () => ( -1)),
|
|
1433
1430
|
patches,
|
|
1434
1431
|
snaps,
|
|
1435
1432
|
cache_hit,
|
|
@@ -1456,8 +1453,8 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
|
|
|
1456
1453
|
void 0,
|
|
1457
1454
|
patch_fn
|
|
1458
1455
|
);
|
|
1459
|
-
if (_optionalChain([snapshot, 'access',
|
|
1460
|
-
throw new (0,
|
|
1456
|
+
if (_optionalChain([snapshot, 'access', _65 => _65.event, 'optionalAccess', _66 => _66.name]) === _chunkVD4BLAY4cjs.TOMBSTONE_EVENT)
|
|
1457
|
+
throw new (0, _chunkVD4BLAY4cjs.StreamClosedError)(stream);
|
|
1461
1458
|
return {
|
|
1462
1459
|
state: l.state,
|
|
1463
1460
|
stream,
|
|
@@ -1471,12 +1468,12 @@ async function load_others(loads, payload, own, actor, patch_fn, refuse) {
|
|
|
1471
1468
|
async function action(me, action2, target, payload, options, patch_fn = bare_patch) {
|
|
1472
1469
|
const { stream, expectedVersion, actor } = target;
|
|
1473
1470
|
if (!stream) throw new Error("Missing target stream");
|
|
1474
|
-
const reactingTo = _optionalChain([options, 'optionalAccess',
|
|
1475
|
-
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1476
|
-
const validated =
|
|
1477
|
-
const opts = _optionalChain([me, 'access',
|
|
1478
|
-
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess',
|
|
1479
|
-
const loads = _nullishCoalesce(_optionalChain([me, 'access',
|
|
1471
|
+
const reactingTo = _optionalChain([options, 'optionalAccess', _67 => _67.reactingTo]);
|
|
1472
|
+
const correlator = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.correlator]), () => ( default_correlator));
|
|
1473
|
+
const validated = _chunkKGJQXN3Scjs.validate.call(void 0, action2, payload, me.actions[action2]);
|
|
1474
|
+
const opts = _optionalChain([me, 'access', _69 => _69.options, 'optionalAccess', _70 => _70[action2]]);
|
|
1475
|
+
const max_retries = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _71 => _71.maxRetries]), () => ( 0));
|
|
1476
|
+
const loads = _nullishCoalesce(_optionalChain([me, 'access', _72 => _72.loads, 'optionalAccess', _73 => _73[action2]]), () => ( []));
|
|
1480
1477
|
for (let attempt = 0; ; attempt++) {
|
|
1481
1478
|
try {
|
|
1482
1479
|
const snapshot = await load(
|
|
@@ -1485,8 +1482,8 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1485
1482
|
void 0,
|
|
1486
1483
|
patch_fn
|
|
1487
1484
|
);
|
|
1488
|
-
if (_optionalChain([snapshot, 'access',
|
|
1489
|
-
throw new (0,
|
|
1485
|
+
if (_optionalChain([snapshot, 'access', _74 => _74.event, 'optionalAccess', _75 => _75.name]) === _chunkVD4BLAY4cjs.TOMBSTONE_EVENT)
|
|
1486
|
+
throw new (0, _chunkVD4BLAY4cjs.StreamClosedError)(stream);
|
|
1490
1487
|
const own = {
|
|
1491
1488
|
state: me,
|
|
1492
1489
|
stream,
|
|
@@ -1500,7 +1497,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1500
1497
|
{ stream, state: snapshot.state },
|
|
1501
1498
|
target.actor,
|
|
1502
1499
|
patch_fn,
|
|
1503
|
-
(description) => new (0,
|
|
1500
|
+
(description) => new (0, _chunkVD4BLAY4cjs.PreconditionError)(
|
|
1504
1501
|
action2,
|
|
1505
1502
|
validated,
|
|
1506
1503
|
target,
|
|
@@ -1509,11 +1506,11 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1509
1506
|
)
|
|
1510
1507
|
) : [];
|
|
1511
1508
|
const loaded = Object.fromEntries(
|
|
1512
|
-
others.map((p, i) => [loads[i].name, _optionalChain([p, 'optionalAccess',
|
|
1509
|
+
others.map((p, i) => [loads[i].name, _optionalChain([p, 'optionalAccess', _76 => _76.snapshot, 'access', _77 => _77.state])])
|
|
1513
1510
|
);
|
|
1514
|
-
for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access',
|
|
1511
|
+
for (const { holds, description } of _nullishCoalesce(_optionalChain([me, 'access', _78 => _78.requires, 'optionalAccess', _79 => _79[action2]]), () => ( [])))
|
|
1515
1512
|
if (!holds(validated, snapshot.state, actor, loaded))
|
|
1516
|
-
throw new (0,
|
|
1513
|
+
throw new (0, _chunkVD4BLAY4cjs.PreconditionError)(
|
|
1517
1514
|
action2,
|
|
1518
1515
|
validated,
|
|
1519
1516
|
target,
|
|
@@ -1535,7 +1532,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1535
1532
|
);
|
|
1536
1533
|
to.events.push({
|
|
1537
1534
|
name: event,
|
|
1538
|
-
data:
|
|
1535
|
+
data: _chunkKGJQXN3Scjs.validate.call(void 0, event, data, to.state.events[event])
|
|
1539
1536
|
});
|
|
1540
1537
|
}
|
|
1541
1538
|
if (!own.events.length)
|
|
@@ -1543,10 +1540,10 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1543
1540
|
`Action "${action2}" appends only to the streams it loads; it must append an event to its own stream too`
|
|
1544
1541
|
);
|
|
1545
1542
|
const appends = [own, ...others].filter(
|
|
1546
|
-
(p) => !!_optionalChain([p, 'optionalAccess',
|
|
1543
|
+
(p) => !!_optionalChain([p, 'optionalAccess', _80 => _80.events, 'access', _81 => _81.length])
|
|
1547
1544
|
);
|
|
1548
1545
|
const meta = {
|
|
1549
|
-
correlation: _optionalChain([reactingTo, 'optionalAccess',
|
|
1546
|
+
correlation: _optionalChain([reactingTo, 'optionalAccess', _82 => _82.meta, 'access', _83 => _83.correlation]) || correlator({
|
|
1550
1547
|
action: action2,
|
|
1551
1548
|
state: me.name,
|
|
1552
1549
|
stream,
|
|
@@ -1592,7 +1589,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1592
1589
|
});
|
|
1593
1590
|
let committed;
|
|
1594
1591
|
try {
|
|
1595
|
-
committed = await
|
|
1592
|
+
committed = await _chunkKGJQXN3Scjs.store.call(void 0, ).commit(
|
|
1596
1593
|
appends.map((p) => ({
|
|
1597
1594
|
stream: p.stream,
|
|
1598
1595
|
msgs: p.events.map((e) => p.state.message(e)),
|
|
@@ -1601,7 +1598,7 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1601
1598
|
meta
|
|
1602
1599
|
);
|
|
1603
1600
|
} catch (error) {
|
|
1604
|
-
if (error instanceof
|
|
1601
|
+
if (error instanceof _chunkVD4BLAY4cjs.ConcurrencyError) void cache_drop(error.stream);
|
|
1605
1602
|
throw error;
|
|
1606
1603
|
}
|
|
1607
1604
|
let row = 0;
|
|
@@ -1624,13 +1621,13 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1624
1621
|
};
|
|
1625
1622
|
});
|
|
1626
1623
|
const last = appended.at(-1);
|
|
1627
|
-
const snap_event = _optionalChain([owner, 'access',
|
|
1624
|
+
const snap_event = _optionalChain([owner, 'access', _84 => _84.snap, 'optionalCall', _85 => _85(last)]) ? await snap(last) : void 0;
|
|
1628
1625
|
if (!owner.pii_aware)
|
|
1629
1626
|
void cache_put(append.stream, {
|
|
1630
1627
|
stream: append.stream,
|
|
1631
1628
|
state: last.state,
|
|
1632
|
-
version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess',
|
|
1633
|
-
event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess',
|
|
1629
|
+
version: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _86 => _86.version]), () => ( last.event.version)),
|
|
1630
|
+
event_id: _nullishCoalesce(_optionalChain([snap_event, 'optionalAccess', _87 => _87.id]), () => ( last.event.id)),
|
|
1634
1631
|
patches: snap_event ? 0 : last.patches,
|
|
1635
1632
|
snaps: snap_event ? last.snaps + 1 : last.snaps
|
|
1636
1633
|
});
|
|
@@ -1643,19 +1640,19 @@ async function action(me, action2, target, payload, options, patch_fn = bare_pat
|
|
|
1643
1640
|
}
|
|
1644
1641
|
return snapshots;
|
|
1645
1642
|
} catch (error) {
|
|
1646
|
-
if (!(error instanceof
|
|
1643
|
+
if (!(error instanceof _chunkVD4BLAY4cjs.ConcurrencyError)) throw error;
|
|
1647
1644
|
if (expectedVersion !== void 0 && error.stream === stream) throw error;
|
|
1648
1645
|
if (attempt >= max_retries) throw error;
|
|
1649
|
-
if (_optionalChain([opts, 'optionalAccess',
|
|
1646
|
+
if (_optionalChain([opts, 'optionalAccess', _88 => _88.backoff])) {
|
|
1650
1647
|
const delay_ms = compute_backoff_delay(attempt, opts.backoff);
|
|
1651
|
-
if (delay_ms > 0) await
|
|
1648
|
+
if (delay_ms > 0) await _chunkKGJQXN3Scjs.sleep.call(void 0, delay_ms);
|
|
1652
1649
|
}
|
|
1653
1650
|
}
|
|
1654
1651
|
}
|
|
1655
1652
|
}
|
|
1656
1653
|
|
|
1657
1654
|
// src/internal/tracing.ts
|
|
1658
|
-
var PRETTY =
|
|
1655
|
+
var PRETTY = _chunkKGJQXN3Scjs.config.call(void 0, ).env !== "production";
|
|
1659
1656
|
var C_BLUE = "\x1B[38;5;39m";
|
|
1660
1657
|
var C_ORANGE = "\x1B[38;5;208m";
|
|
1661
1658
|
var C_GREEN = "\x1B[38;5;42m";
|
|
@@ -1701,9 +1698,9 @@ var as_of_marker = (asOf) => {
|
|
|
1701
1698
|
return parts.length ? ` (as-of ${parts.join(" ")})` : " (as-of)";
|
|
1702
1699
|
};
|
|
1703
1700
|
var traced = (inner, exit, entry) => (async (...args) => {
|
|
1704
|
-
_optionalChain([entry, 'optionalCall',
|
|
1701
|
+
_optionalChain([entry, 'optionalCall', _89 => _89(...args)]);
|
|
1705
1702
|
const result = await inner(...args);
|
|
1706
|
-
_optionalChain([exit, 'optionalCall',
|
|
1703
|
+
_optionalChain([exit, 'optionalCall', _90 => _90(result, ...args)]);
|
|
1707
1704
|
return result;
|
|
1708
1705
|
});
|
|
1709
1706
|
function build_es(logger, correlator = default_correlator, patch_fn = bare_patch) {
|
|
@@ -1712,7 +1709,7 @@ function build_es(logger, correlator = default_correlator, patch_fn = bare_patch
|
|
|
1712
1709
|
action_name,
|
|
1713
1710
|
target,
|
|
1714
1711
|
payload,
|
|
1715
|
-
{ ...options, correlator: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1712
|
+
{ ...options, correlator: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _91 => _91.correlator]), () => ( correlator)) },
|
|
1716
1713
|
patch_fn
|
|
1717
1714
|
);
|
|
1718
1715
|
const bound_load = (me, target, callback) => load(me, target, callback, patch_fn);
|
|
@@ -1786,7 +1783,7 @@ function build_drain(logger) {
|
|
|
1786
1783
|
subscribe: logger.level !== "trace" ? subscribe : traced(subscribe, (result, streams) => {
|
|
1787
1784
|
if (!result.subscribed) return;
|
|
1788
1785
|
const lanes = new Set(streams.map((s) => _nullishCoalesce(s.lane, () => ( "default"))));
|
|
1789
|
-
const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access',
|
|
1786
|
+
const uniform_lane = lanes.size === 1 ? _optionalChain([streams, 'access', _92 => _92[0], 'optionalAccess', _93 => _93.lane]) : void 0;
|
|
1790
1787
|
const data = streams.map(
|
|
1791
1788
|
({ stream, lane }) => uniform_lane || !lane || lane === "default" ? hue(C_STREAM, stream) : `${hue(C_STREAM, stream)}${dim(`[${lane}]`)}`
|
|
1792
1789
|
).join(" ");
|
|
@@ -1798,7 +1795,7 @@ function build_drain(logger) {
|
|
|
1798
1795
|
}
|
|
1799
1796
|
function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
1800
1797
|
if (logger.level !== "trace" || !leased.length) return;
|
|
1801
|
-
const lane = _optionalChain([leased, 'access',
|
|
1798
|
+
const lane = _optionalChain([leased, 'access', _94 => _94[0], 'optionalAccess', _95 => _95.lane]);
|
|
1802
1799
|
const fetch_by_stream = new Map(fetched.map((f) => [f.stream, f]));
|
|
1803
1800
|
const acked_by_stream = new Map(acked.map((a) => [a.stream, a.at]));
|
|
1804
1801
|
const blocked_by_stream = new Map(blocked.map((b) => [b.stream, b.error]));
|
|
@@ -1807,8 +1804,8 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
1807
1804
|
);
|
|
1808
1805
|
const detail = leased.map(({ stream, at, retry }) => {
|
|
1809
1806
|
const f = fetch_by_stream.get(stream);
|
|
1810
|
-
const key = _optionalChain([f, 'optionalAccess',
|
|
1811
|
-
const events = _optionalChain([f, 'optionalAccess',
|
|
1807
|
+
const key = _optionalChain([f, 'optionalAccess', _96 => _96.source]) ? `${hue(C_STREAM, stream)}${dim(`<-${f.source}`)}` : hue(C_STREAM, stream);
|
|
1808
|
+
const events = _optionalChain([f, 'optionalAccess', _97 => _97.events, 'access', _98 => _98.length]) ? ` ${dim(
|
|
1812
1809
|
`[${f.events.map(({ id, name }) => `#${id} ${String(name)}`).join(", ")}]`
|
|
1813
1810
|
)}` : "";
|
|
1814
1811
|
const acked_at = acked_by_stream.get(stream);
|
|
@@ -1836,10 +1833,10 @@ function trace_cycle(logger, leased, fetched, handled, acked, blocked) {
|
|
|
1836
1833
|
|
|
1837
1834
|
// src/internal/drain-cycle.ts
|
|
1838
1835
|
function budget_exhausted(lease, options, store_failing) {
|
|
1839
|
-
if (store_failing || !_optionalChain([options, 'optionalAccess',
|
|
1836
|
+
if (store_failing || !_optionalChain([options, 'optionalAccess', _99 => _99.blockOnError]) || lease.retry <= options.maxRetries)
|
|
1840
1837
|
return void 0;
|
|
1841
1838
|
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.`;
|
|
1842
|
-
|
|
1839
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).error(error);
|
|
1843
1840
|
return { lease, handled: 0, acked_at: lease.at, error, block: true };
|
|
1844
1841
|
}
|
|
1845
1842
|
function fetch_failure_policy(registry) {
|
|
@@ -1855,13 +1852,13 @@ function fetch_failure_policy(registry) {
|
|
|
1855
1852
|
function finalize(lease, handled, at, error, options, logger, failed_at) {
|
|
1856
1853
|
if (!error) return { lease, handled, acked_at: at };
|
|
1857
1854
|
logger.error(error);
|
|
1858
|
-
const non_retryable = error instanceof
|
|
1855
|
+
const non_retryable = error instanceof _chunkVD4BLAY4cjs.NonRetryableError;
|
|
1859
1856
|
const block2 = options.blockOnError && (non_retryable || lease.retry >= options.maxRetries);
|
|
1860
1857
|
if (block2)
|
|
1861
1858
|
logger.error(
|
|
1862
1859
|
non_retryable ? `Blocking ${lease.stream} on non-retryable error.` : `Blocking ${lease.stream} after ${lease.retry} retries.`
|
|
1863
1860
|
);
|
|
1864
|
-
const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => (
|
|
1861
|
+
const next_attempt_at = block2 ? void 0 : Date.now() + compute_backoff_delay(lease.retry, _nullishCoalesce(options.backoff, () => ( _chunkKGJQXN3Scjs.DEFAULT_BACKOFF)));
|
|
1865
1862
|
return {
|
|
1866
1863
|
lease,
|
|
1867
1864
|
handled,
|
|
@@ -1900,7 +1897,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
1900
1897
|
const fetched = await ops.fetch(leased, eventLimit);
|
|
1901
1898
|
const fetch_map = /* @__PURE__ */ new Map();
|
|
1902
1899
|
const fetch_window_at = fetched.reduce(
|
|
1903
|
-
(max, { at, events }) => Math.max(max, _optionalChain([events, 'access',
|
|
1900
|
+
(max, { at, events }) => Math.max(max, _optionalChain([events, 'access', _100 => _100.at, 'call', _101 => _101(-1), 'optionalAccess', _102 => _102.id]) || at),
|
|
1904
1901
|
0
|
|
1905
1902
|
);
|
|
1906
1903
|
for (const f of fetched) {
|
|
@@ -1964,11 +1961,11 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
1964
1961
|
deps.logger
|
|
1965
1962
|
)
|
|
1966
1963
|
);
|
|
1967
|
-
const at = _optionalChain([entry, 'access',
|
|
1964
|
+
const at = _optionalChain([entry, 'access', _103 => _103.fetch, 'access', _104 => _104.events, 'access', _105 => _105.at, 'call', _106 => _106(-1), 'optionalAccess', _107 => _107.id]) || fetch_window_at;
|
|
1968
1965
|
const { payloads } = entry;
|
|
1969
1966
|
const exhausted = budget_exhausted(
|
|
1970
1967
|
lease,
|
|
1971
|
-
_optionalChain([payloads, 'access',
|
|
1968
|
+
_optionalChain([payloads, 'access', _108 => _108[0], 'optionalAccess', _109 => _109.options]),
|
|
1972
1969
|
store_failing
|
|
1973
1970
|
);
|
|
1974
1971
|
if (exhausted) return Promise.resolve(exhausted);
|
|
@@ -1989,7 +1986,7 @@ async function run_drain_cycle(deps, cycle) {
|
|
|
1989
1986
|
const acked = submitted.length ? await ops.ack(submitted) : [];
|
|
1990
1987
|
const expected = submitted.filter((l) => l.due === void 0).length;
|
|
1991
1988
|
if (acked.length < expected)
|
|
1992
|
-
|
|
1989
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).warn(
|
|
1993
1990
|
`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.`
|
|
1994
1991
|
);
|
|
1995
1992
|
const closeable = handled.filter((h) => h.close !== void 0).map((h) => h.close);
|
|
@@ -2053,7 +2050,7 @@ var DrainController = (_class3 = class {
|
|
|
2053
2050
|
}
|
|
2054
2051
|
/** This lane's configured lease, or `undefined`; the shutdown grace basis. */
|
|
2055
2052
|
get lease_millis() {
|
|
2056
|
-
return _optionalChain([this, 'access',
|
|
2053
|
+
return _optionalChain([this, 'access', _110 => _110._deps, 'access', _111 => _111.defaults, 'optionalAccess', _112 => _112.leaseMillis]);
|
|
2057
2054
|
}
|
|
2058
2055
|
get lane() {
|
|
2059
2056
|
return this._deps.lane;
|
|
@@ -2085,9 +2082,9 @@ var DrainController = (_class3 = class {
|
|
|
2085
2082
|
if (!this.armed || this._stopped || this._inflight)
|
|
2086
2083
|
return EMPTY_DRAIN;
|
|
2087
2084
|
const d = _nullishCoalesce(this._deps.defaults, () => ( {}));
|
|
2088
|
-
const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => (
|
|
2089
|
-
const eventLimit = _nullishCoalesce(options.eventLimit, () => (
|
|
2090
|
-
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => (
|
|
2085
|
+
const streamLimit = _nullishCoalesce(_nullishCoalesce(d.streamLimit, () => ( options.streamLimit)), () => ( _chunkKGJQXN3Scjs.DEFAULT_STREAM_LIMIT));
|
|
2086
|
+
const eventLimit = _nullishCoalesce(options.eventLimit, () => ( _chunkKGJQXN3Scjs.DEFAULT_EVENT_LIMIT));
|
|
2087
|
+
const leaseMillis = _nullishCoalesce(_nullishCoalesce(d.leaseMillis, () => ( options.leaseMillis)), () => ( _chunkKGJQXN3Scjs.DEFAULT_LEASE_MILLIS));
|
|
2091
2088
|
if (this._deps.breaker.state(Date.now()) === "open")
|
|
2092
2089
|
return EMPTY_DRAIN;
|
|
2093
2090
|
const pass = this._pass(streamLimit, eventLimit, leaseMillis).finally(
|
|
@@ -2179,11 +2176,11 @@ var CloseSignal = class extends Error {
|
|
|
2179
2176
|
constructor(opts) {
|
|
2180
2177
|
super("reaction requested close");
|
|
2181
2178
|
this.name = "CloseSignal";
|
|
2182
|
-
this.stream = _optionalChain([opts, 'optionalAccess',
|
|
2183
|
-
this.archive = _optionalChain([opts, 'optionalAccess',
|
|
2184
|
-
this.at = _optionalChain([opts, 'optionalAccess',
|
|
2185
|
-
this.before = _optionalChain([opts, 'optionalAccess',
|
|
2186
|
-
this.defer = _optionalChain([opts, 'optionalAccess',
|
|
2179
|
+
this.stream = _optionalChain([opts, 'optionalAccess', _113 => _113.stream]);
|
|
2180
|
+
this.archive = _optionalChain([opts, 'optionalAccess', _114 => _114.archive]);
|
|
2181
|
+
this.at = _optionalChain([opts, 'optionalAccess', _115 => _115.at]);
|
|
2182
|
+
this.before = _optionalChain([opts, 'optionalAccess', _116 => _116.before]);
|
|
2183
|
+
this.defer = _optionalChain([opts, 'optionalAccess', _117 => _117.defer]);
|
|
2187
2184
|
}
|
|
2188
2185
|
};
|
|
2189
2186
|
function build_handle(deps) {
|
|
@@ -2213,7 +2210,7 @@ function build_handle(deps) {
|
|
|
2213
2210
|
handled++;
|
|
2214
2211
|
}
|
|
2215
2212
|
} catch (error) {
|
|
2216
|
-
if (error instanceof
|
|
2213
|
+
if (error instanceof _chunkVD4BLAY4cjs.DeferSignal) {
|
|
2217
2214
|
let defer;
|
|
2218
2215
|
try {
|
|
2219
2216
|
defer = resolve_defer_at(error.when, event);
|
|
@@ -2237,7 +2234,7 @@ function build_handle(deps) {
|
|
|
2237
2234
|
// Advance to the live head the handler evaluated against (when
|
|
2238
2235
|
// provided) so the close-cycle guard sees this reaction caught up.
|
|
2239
2236
|
acked_at: _nullishCoalesce(error.at, () => ( event.id)),
|
|
2240
|
-
defer: _optionalChain([error, 'access',
|
|
2237
|
+
defer: _optionalChain([error, 'access', _118 => _118.defer, 'optionalAccess', _119 => _119.getTime, 'call', _120 => _120()]),
|
|
2241
2238
|
// Close the signalled stream (the autoclose reaction's aggregate,
|
|
2242
2239
|
// which differs from its synthetic lease stream); a self-closing
|
|
2243
2240
|
// user reaction omits it and closes its own lease stream. A
|
|
@@ -2310,22 +2307,22 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2310
2307
|
// An anchored stream name would read as a pattern, and a store may refuse
|
|
2311
2308
|
// it at subscribe, stopping every reaction. Such a stream has no
|
|
2312
2309
|
// autoclose: `app.close` still closes it.
|
|
2313
|
-
resolver: (e) =>
|
|
2310
|
+
resolver: (e) => _chunkKGJQXN3Scjs.is_literal_source.call(void 0, e.stream) ? {
|
|
2314
2311
|
target: `${AUTOCLOSE_TARGET_PREFIX}${e.stream}`,
|
|
2315
2312
|
source: e.stream
|
|
2316
2313
|
} : void 0,
|
|
2317
2314
|
// Never block on autoclose: a transient query/store error should retry,
|
|
2318
2315
|
// not quarantine the synthetic stream.
|
|
2319
|
-
options: { blockOnError: false, maxRetries:
|
|
2316
|
+
options: { blockOnError: false, maxRetries: _chunkKGJQXN3Scjs.DEFAULT_MAX_RETRIES },
|
|
2320
2317
|
handler: async (event) => {
|
|
2321
2318
|
const aggregate = event.stream;
|
|
2322
2319
|
const window = read_window();
|
|
2323
2320
|
if (!in_autoclose_window(window, /* @__PURE__ */ new Date()))
|
|
2324
|
-
throw new (0,
|
|
2325
|
-
const stats = await
|
|
2321
|
+
throw new (0, _chunkVD4BLAY4cjs.DeferSignal)({ at: next_window_open(window, /* @__PURE__ */ new Date()) });
|
|
2322
|
+
const stats = await _chunkKGJQXN3Scjs.store.call(void 0, ).query_stats([aggregate], {
|
|
2326
2323
|
count: true,
|
|
2327
2324
|
tail: keep_days !== void 0 ? true : void 0,
|
|
2328
|
-
exclude: [
|
|
2325
|
+
exclude: [_chunkVD4BLAY4cjs.TOMBSTONE_EVENT, _chunkVD4BLAY4cjs.SNAP_EVENT]
|
|
2329
2326
|
});
|
|
2330
2327
|
const entry = stats.get(aggregate);
|
|
2331
2328
|
if (!entry) return;
|
|
@@ -2361,12 +2358,12 @@ function synthesize_autoclose_reactions(registry, states, read_window) {
|
|
|
2361
2358
|
dues.push(days_after(entry.tail.created, keep_days));
|
|
2362
2359
|
const future = dues.map((d) => d.getTime()).filter((t) => t > Date.now());
|
|
2363
2360
|
if (future.length)
|
|
2364
|
-
throw new (0,
|
|
2361
|
+
throw new (0, _chunkVD4BLAY4cjs.DeferSignal)({ at: new Date(Math.min(...future)) });
|
|
2365
2362
|
}
|
|
2366
2363
|
};
|
|
2367
2364
|
const key = `__autoclose_${st.name}`;
|
|
2368
2365
|
for (const event_name of Object.keys(st.events)) {
|
|
2369
|
-
_optionalChain([registry, 'access',
|
|
2366
|
+
_optionalChain([registry, 'access', _121 => _121.events, 'access', _122 => _122[event_name], 'optionalAccess', _123 => _123.reactions, 'access', _124 => _124.set, 'call', _125 => _125(
|
|
2370
2367
|
key,
|
|
2371
2368
|
reaction
|
|
2372
2369
|
)]);
|
|
@@ -2421,8 +2418,8 @@ async function run_close_cycle(targets, deps) {
|
|
|
2421
2418
|
deps,
|
|
2422
2419
|
() => run_full_closes(full, target_map, deps, skipped)
|
|
2423
2420
|
);
|
|
2424
|
-
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name ===
|
|
2425
|
-
if (retired.length) _optionalChain([deps, 'access',
|
|
2421
|
+
const retired = [...truncated.entries()].filter(([, r]) => r.committed.name === _chunkVD4BLAY4cjs.TOMBSTONE_EVENT).map(([stream]) => stream);
|
|
2422
|
+
if (retired.length) _optionalChain([deps, 'access', _126 => _126.forget_subscribed, 'optionalCall', _127 => _127(retired)]);
|
|
2426
2423
|
for (const [stream, entry] of windowed_result) truncated.set(stream, entry);
|
|
2427
2424
|
return { truncated, skipped };
|
|
2428
2425
|
}
|
|
@@ -2442,7 +2439,7 @@ async function run_full_closes(full, target_map, deps, skipped) {
|
|
|
2442
2439
|
const info = stream_info.get(target.stream);
|
|
2443
2440
|
if (!info) continue;
|
|
2444
2441
|
const owner = deps.event_to_state.get(info.last_event_name);
|
|
2445
|
-
if (_optionalChain([owner, 'optionalAccess',
|
|
2442
|
+
if (_optionalChain([owner, 'optionalAccess', _128 => _128.pii_aware])) {
|
|
2446
2443
|
deps.logger.error(
|
|
2447
2444
|
`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.`
|
|
2448
2445
|
);
|
|
@@ -2503,7 +2500,7 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
2503
2500
|
if (!await windowed_prune_pending(t.stream, t.before, max_id))
|
|
2504
2501
|
return void 0;
|
|
2505
2502
|
if (t.archive) await t.archive();
|
|
2506
|
-
const result = await
|
|
2503
|
+
const result = await _chunkKGJQXN3Scjs.store.call(void 0, ).truncate([
|
|
2507
2504
|
{ stream: t.stream, before: t.before, max_id }
|
|
2508
2505
|
]);
|
|
2509
2506
|
return result.get(t.stream);
|
|
@@ -2516,10 +2513,10 @@ async function run_windowed_closes(windowed, deps, skipped) {
|
|
|
2516
2513
|
async function windowed_prune_pending(stream, before, max_id) {
|
|
2517
2514
|
let boundary_id;
|
|
2518
2515
|
let min_id;
|
|
2519
|
-
await
|
|
2516
|
+
await _chunkKGJQXN3Scjs.store.call(void 0, ).query(
|
|
2520
2517
|
(event) => {
|
|
2521
2518
|
if (min_id === void 0 || event.id < min_id) min_id = event.id;
|
|
2522
|
-
if (event.name ===
|
|
2519
|
+
if (event.name === _chunkVD4BLAY4cjs.SNAP_EVENT && event.created < before && (max_id === void 0 || event.id <= max_id) && (boundary_id === void 0 || event.id > boundary_id))
|
|
2523
2520
|
boundary_id = event.id;
|
|
2524
2521
|
},
|
|
2525
2522
|
{ stream, stream_exact: true, with_snaps: true, after: -1 }
|
|
@@ -2530,7 +2527,7 @@ async function probe_min_watermarks(streams, page_size, checkpoint) {
|
|
|
2530
2527
|
const min_at = /* @__PURE__ */ new Map();
|
|
2531
2528
|
const matches = source_matcher();
|
|
2532
2529
|
await walk_streams(
|
|
2533
|
-
|
|
2530
|
+
_chunkKGJQXN3Scjs.store.call(void 0, ),
|
|
2534
2531
|
(position) => {
|
|
2535
2532
|
const pending = position.correlated_at === void 0 || position.at < position.correlated_at;
|
|
2536
2533
|
const cap = pending ? position.at : Math.max(position.at, checkpoint);
|
|
@@ -2549,7 +2546,7 @@ function source_matcher() {
|
|
|
2549
2546
|
const compiled = /* @__PURE__ */ new Map();
|
|
2550
2547
|
return (source, target, stream) => {
|
|
2551
2548
|
if (!source) return true;
|
|
2552
|
-
if (
|
|
2549
|
+
if (_chunkKGJQXN3Scjs.is_literal_source.call(void 0, source, target)) return source === stream;
|
|
2553
2550
|
let re = compiled.get(source);
|
|
2554
2551
|
if (!re) {
|
|
2555
2552
|
re = new RegExp(source);
|
|
@@ -2559,17 +2556,17 @@ function source_matcher() {
|
|
|
2559
2556
|
};
|
|
2560
2557
|
}
|
|
2561
2558
|
async function scan_stream_heads(streams) {
|
|
2562
|
-
const stats = await
|
|
2563
|
-
exclude: [
|
|
2559
|
+
const stats = await _chunkKGJQXN3Scjs.store.call(void 0, ).query_stats(streams, {
|
|
2560
|
+
exclude: [_chunkVD4BLAY4cjs.SNAP_EVENT]
|
|
2564
2561
|
});
|
|
2565
|
-
const domain_heads = await
|
|
2566
|
-
exclude: [
|
|
2562
|
+
const domain_heads = await _chunkKGJQXN3Scjs.store.call(void 0, ).query_stats(streams, {
|
|
2563
|
+
exclude: [_chunkVD4BLAY4cjs.SNAP_EVENT, _chunkVD4BLAY4cjs.TOMBSTONE_EVENT]
|
|
2567
2564
|
});
|
|
2568
|
-
const true_heads = await
|
|
2565
|
+
const true_heads = await _chunkKGJQXN3Scjs.store.call(void 0, ).query_stats(streams, {});
|
|
2569
2566
|
const out = /* @__PURE__ */ new Map();
|
|
2570
2567
|
for (const [stream, { head }] of domain_heads) {
|
|
2571
|
-
const marker_head = _optionalChain([stats, 'access',
|
|
2572
|
-
const interrupted = _optionalChain([marker_head, 'optionalAccess',
|
|
2568
|
+
const marker_head = _optionalChain([stats, 'access', _129 => _129.get, 'call', _130 => _130(stream), 'optionalAccess', _131 => _131.head]);
|
|
2569
|
+
const interrupted = _optionalChain([marker_head, 'optionalAccess', _132 => _132.name]) === _chunkVD4BLAY4cjs.TOMBSTONE_EVENT;
|
|
2573
2570
|
out.set(stream, {
|
|
2574
2571
|
max_id: head.id,
|
|
2575
2572
|
version: true_heads.get(stream).head.version,
|
|
@@ -2592,7 +2589,7 @@ async function partition_by_safety(stream_info, reactive, skipped, page_size, ca
|
|
|
2592
2589
|
const pending_set = /* @__PURE__ */ new Set();
|
|
2593
2590
|
const matches = source_matcher();
|
|
2594
2591
|
await walk_streams(
|
|
2595
|
-
|
|
2592
|
+
_chunkKGJQXN3Scjs.store.call(void 0, ),
|
|
2596
2593
|
(position) => {
|
|
2597
2594
|
const has_work = position.correlated_at !== void 0 && position.at < position.correlated_at;
|
|
2598
2595
|
if (!has_work) return;
|
|
@@ -2637,7 +2634,7 @@ async function guard_with_tombstones(safe, stream_info, correlation, tombstone2,
|
|
|
2637
2634
|
async function load_restart_seeds(guarded, target_map, stream_info, event_to_state, load2, logger) {
|
|
2638
2635
|
const seed_states = /* @__PURE__ */ new Map();
|
|
2639
2636
|
await Promise.all(
|
|
2640
|
-
guarded.filter((s) => _optionalChain([target_map, 'access',
|
|
2637
|
+
guarded.filter((s) => _optionalChain([target_map, 'access', _133 => _133.get, 'call', _134 => _134(s), 'optionalAccess', _135 => _135.restart])).map(async (stream) => {
|
|
2641
2638
|
const last_event_name = stream_info.get(stream).last_event_name;
|
|
2642
2639
|
const owner_state = event_to_state.get(last_event_name);
|
|
2643
2640
|
if (!owner_state) {
|
|
@@ -2654,14 +2651,14 @@ async function load_restart_seeds(guarded, target_map, stream_info, event_to_sta
|
|
|
2654
2651
|
}
|
|
2655
2652
|
async function run_archive_callbacks(guarded, target_map) {
|
|
2656
2653
|
for (const stream of guarded) {
|
|
2657
|
-
const archive_fn = _optionalChain([target_map, 'access',
|
|
2654
|
+
const archive_fn = _optionalChain([target_map, 'access', _136 => _136.get, 'call', _137 => _137(stream), 'optionalAccess', _138 => _138.archive]);
|
|
2658
2655
|
if (archive_fn) await archive_fn();
|
|
2659
2656
|
}
|
|
2660
2657
|
}
|
|
2661
2658
|
async function heads_still_guarded(guarded, guard_events, skipped) {
|
|
2662
|
-
const heads = await
|
|
2659
|
+
const heads = await _chunkKGJQXN3Scjs.store.call(void 0, ).query_stats(guarded, {});
|
|
2663
2660
|
return guarded.filter((stream) => {
|
|
2664
|
-
if (_optionalChain([heads, 'access',
|
|
2661
|
+
if (_optionalChain([heads, 'access', _139 => _139.get, 'call', _140 => _140(stream), 'optionalAccess', _141 => _141.head, 'access', _142 => _142.id]) === guard_events.get(stream).id)
|
|
2665
2662
|
return true;
|
|
2666
2663
|
skipped.push(stream);
|
|
2667
2664
|
return false;
|
|
@@ -2677,18 +2674,18 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
2677
2674
|
meta: {
|
|
2678
2675
|
correlation,
|
|
2679
2676
|
causation: {
|
|
2680
|
-
event: { id: guard.id, name:
|
|
2677
|
+
event: { id: guard.id, name: _chunkVD4BLAY4cjs.TOMBSTONE_EVENT, stream: guard.stream }
|
|
2681
2678
|
}
|
|
2682
2679
|
}
|
|
2683
2680
|
};
|
|
2684
2681
|
});
|
|
2685
|
-
const truncated = await
|
|
2682
|
+
const truncated = await _chunkKGJQXN3Scjs.store.call(void 0, ).truncate(trunc_targets);
|
|
2686
2683
|
await Promise.all(
|
|
2687
2684
|
guarded.map(async (stream) => {
|
|
2688
2685
|
const entry = truncated.get(stream);
|
|
2689
2686
|
const state2 = seed_states.get(stream);
|
|
2690
2687
|
if (state2 && entry) {
|
|
2691
|
-
await
|
|
2688
|
+
await _chunkKGJQXN3Scjs.cache.call(void 0, ).set(stream, {
|
|
2692
2689
|
stream,
|
|
2693
2690
|
state: state2,
|
|
2694
2691
|
version: entry.committed.version,
|
|
@@ -2697,7 +2694,7 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
2697
2694
|
snaps: 1
|
|
2698
2695
|
});
|
|
2699
2696
|
} else {
|
|
2700
|
-
await
|
|
2697
|
+
await _chunkKGJQXN3Scjs.cache.call(void 0, ).invalidate(stream);
|
|
2701
2698
|
}
|
|
2702
2699
|
})
|
|
2703
2700
|
);
|
|
@@ -2749,7 +2746,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2749
2746
|
// never lets a resolution re-lane them.
|
|
2750
2747
|
|
|
2751
2748
|
__init18() {this._static_subscriptions = /* @__PURE__ */ new Map()}
|
|
2752
|
-
__init19() {this._patterns = new (0,
|
|
2749
|
+
__init19() {this._patterns = new (0, _chunkKGJQXN3Scjs.LruMap)(PATTERN_CACHE_SIZE)}
|
|
2753
2750
|
|
|
2754
2751
|
|
|
2755
2752
|
|
|
@@ -2767,7 +2764,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2767
2764
|
on_init
|
|
2768
2765
|
}) {;_class5.prototype.__init10.call(this);_class5.prototype.__init11.call(this);_class5.prototype.__init12.call(this);_class5.prototype.__init13.call(this);_class5.prototype.__init14.call(this);_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);
|
|
2769
2766
|
this._key = shard ? `${registry_key(registry.events)}:${[...shard].sort().join(",")}` : registry_key(registry.events);
|
|
2770
|
-
this._dynamic_subscriptions = new (0,
|
|
2767
|
+
this._dynamic_subscriptions = new (0, _chunkKGJQXN3Scjs.LruMap)(max_subscribed_streams);
|
|
2771
2768
|
this._registry = registry;
|
|
2772
2769
|
this._declared_lanes = declared_lanes;
|
|
2773
2770
|
this._static_targets = static_targets;
|
|
@@ -2799,7 +2796,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2799
2796
|
lane
|
|
2800
2797
|
});
|
|
2801
2798
|
}
|
|
2802
|
-
await _optionalChain([this, 'access',
|
|
2799
|
+
await _optionalChain([this, 'access', _143 => _143._on_init, 'optionalCall', _144 => _144()]);
|
|
2803
2800
|
}
|
|
2804
2801
|
/**
|
|
2805
2802
|
* Replace the log with no pass in flight, then cold-start: a pass that
|
|
@@ -2825,7 +2822,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2825
2822
|
// Would the target's own `fetch` (filtered by `source`) return this event?
|
|
2826
2823
|
_in_fetch_window(source, stream) {
|
|
2827
2824
|
if (source === void 0 || source === stream) return true;
|
|
2828
|
-
if (
|
|
2825
|
+
if (_chunkKGJQXN3Scjs.is_literal_source.call(void 0, source)) return false;
|
|
2829
2826
|
let pattern = this._patterns.get(source);
|
|
2830
2827
|
if (!pattern) {
|
|
2831
2828
|
pattern = new RegExp(source);
|
|
@@ -2868,7 +2865,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2868
2865
|
const correlated = /* @__PURE__ */ new Map();
|
|
2869
2866
|
let last_id = after;
|
|
2870
2867
|
let stopped = false;
|
|
2871
|
-
const found = await
|
|
2868
|
+
const found = await _chunkKGJQXN3Scjs.store.call(void 0, ).query(
|
|
2872
2869
|
(event) => {
|
|
2873
2870
|
if (stopped) return;
|
|
2874
2871
|
const register = this._registry.events[event.name];
|
|
@@ -2913,9 +2910,9 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2913
2910
|
correlated_at: void 0
|
|
2914
2911
|
};
|
|
2915
2912
|
const seen_in_scan = correlated.has(resolved.target);
|
|
2916
|
-
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess',
|
|
2917
|
-
const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess',
|
|
2918
|
-
const resolved_lane = _nullishCoalesce(lane, () => (
|
|
2913
|
+
const held_lane = _nullishCoalesce((seen_in_scan ? entry.lane : _optionalChain([recorded, 'optionalAccess', _145 => _145.lane])), () => ( _chunkVD4BLAY4cjs.DEFAULT_LANE));
|
|
2914
|
+
const held_priority = seen_in_scan ? entry.priority : _optionalChain([recorded, 'optionalAccess', _146 => _146.priority]);
|
|
2915
|
+
const resolved_lane = _nullishCoalesce(lane, () => ( _chunkVD4BLAY4cjs.DEFAULT_LANE));
|
|
2919
2916
|
if (held_priority === priority && held_lane !== resolved_lane)
|
|
2920
2917
|
report_lane_conflict(
|
|
2921
2918
|
this._reported,
|
|
@@ -2969,7 +2966,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2969
2966
|
).length;
|
|
2970
2967
|
this._checkpoint = last_id;
|
|
2971
2968
|
for (const { stream, priority, lane } of streams) {
|
|
2972
|
-
if (_optionalChain([correlated, 'access',
|
|
2969
|
+
if (_optionalChain([correlated, 'access', _147 => _147.get, 'call', _148 => _148(stream), 'optionalAccess', _149 => _149.upgraded]))
|
|
2973
2970
|
this._dynamic_subscriptions.set(stream, {
|
|
2974
2971
|
priority,
|
|
2975
2972
|
lane
|
|
@@ -2989,7 +2986,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
2989
2986
|
await Promise.all(
|
|
2990
2987
|
missed.map(async ([stream, entry]) => {
|
|
2991
2988
|
let row;
|
|
2992
|
-
await
|
|
2989
|
+
await _chunkKGJQXN3Scjs.store.call(void 0, ).query_streams(
|
|
2993
2990
|
(position) => {
|
|
2994
2991
|
row = position;
|
|
2995
2992
|
},
|
|
@@ -3001,8 +2998,8 @@ var CorrelateCycle = (_class5 = class {
|
|
|
3001
2998
|
lane: row.lane
|
|
3002
2999
|
});
|
|
3003
3000
|
if (entry.priority > row.priority) return;
|
|
3004
|
-
const held_lane = _nullishCoalesce(row.lane, () => (
|
|
3005
|
-
const resolved_lane = _nullishCoalesce(entry.lane, () => (
|
|
3001
|
+
const held_lane = _nullishCoalesce(row.lane, () => ( _chunkVD4BLAY4cjs.DEFAULT_LANE));
|
|
3002
|
+
const resolved_lane = _nullishCoalesce(entry.lane, () => ( _chunkVD4BLAY4cjs.DEFAULT_LANE));
|
|
3006
3003
|
if (entry.priority === row.priority && held_lane !== resolved_lane)
|
|
3007
3004
|
report_lane_conflict(
|
|
3008
3005
|
this._reported,
|
|
@@ -3028,7 +3025,7 @@ var CorrelateCycle = (_class5 = class {
|
|
|
3028
3025
|
millis: 0
|
|
3029
3026
|
});
|
|
3030
3027
|
} catch (error) {
|
|
3031
|
-
|
|
3028
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).warn(
|
|
3032
3029
|
`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(_nullishCoalesce(error.cause, () => ( error)))}`
|
|
3033
3030
|
);
|
|
3034
3031
|
}
|
|
@@ -3052,7 +3049,7 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
3052
3049
|
const { pii, ...rest } = event;
|
|
3053
3050
|
if (pii == null) {
|
|
3054
3051
|
const shredded = { ...data };
|
|
3055
|
-
for (const f of fields) shredded[f] =
|
|
3052
|
+
for (const f of fields) shredded[f] = _chunkVD4BLAY4cjs.SHREDDED;
|
|
3056
3053
|
return { ...rest, data: shredded };
|
|
3057
3054
|
}
|
|
3058
3055
|
const allowed = !!actor && !!predicate && predicate(event, actor);
|
|
@@ -3063,7 +3060,7 @@ function pii_gate(event, fields, predicate, actor) {
|
|
|
3063
3060
|
};
|
|
3064
3061
|
}
|
|
3065
3062
|
const redacted = { ...data };
|
|
3066
|
-
for (const f of fields) redacted[f] =
|
|
3063
|
+
for (const f of fields) redacted[f] = _chunkVD4BLAY4cjs.REDACTED;
|
|
3067
3064
|
return { ...rest, data: redacted };
|
|
3068
3065
|
}
|
|
3069
3066
|
var IDENTITY_GATE = (event) => event;
|
|
@@ -3208,7 +3205,7 @@ var SettleLoop = (_class6 = class {
|
|
|
3208
3205
|
this._pending = true;
|
|
3209
3206
|
return;
|
|
3210
3207
|
}
|
|
3211
|
-
const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
3208
|
+
const delay = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _150 => _150.debounceMs]), () => ( this._default_debounce_ms));
|
|
3212
3209
|
const due = Date.now() + delay;
|
|
3213
3210
|
if (this._timer) {
|
|
3214
3211
|
if (due >= this._due) return;
|
|
@@ -3365,7 +3362,7 @@ var Act = (_class7 = class {
|
|
|
3365
3362
|
// Lanes to arm per event; `"all"` when a dynamic resolver hides the lane.
|
|
3366
3363
|
|
|
3367
3364
|
|
|
3368
|
-
__init27() {this._logger =
|
|
3365
|
+
__init27() {this._logger = _chunkKGJQXN3Scjs.log.call(void 0, )}
|
|
3369
3366
|
// This Act's ports: its own bag, or the singleton adapters.
|
|
3370
3367
|
|
|
3371
3368
|
// Runs a body so internal `store()`/`cache()` calls resolve to `_ports`.
|
|
@@ -3387,10 +3384,10 @@ var Act = (_class7 = class {
|
|
|
3387
3384
|
this._lanes = lanes;
|
|
3388
3385
|
this._declared_lanes = ["default", ...lanes.map((l) => l.name)];
|
|
3389
3386
|
validate_only_lanes(options.onlyLanes, this._declared_lanes);
|
|
3390
|
-
if (options.scoped)
|
|
3391
|
-
this._ports = _nullishCoalesce(options.scoped, () => (
|
|
3387
|
+
if (options.scoped) _chunkKGJQXN3Scjs.check_store.call(void 0, options.scoped.store);
|
|
3388
|
+
this._ports = _nullishCoalesce(options.scoped, () => ( _chunkKGJQXN3Scjs.default_scope.call(void 0, )));
|
|
3392
3389
|
const ports = this._ports;
|
|
3393
|
-
this._scoped =
|
|
3390
|
+
this._scoped = _chunkKGJQXN3Scjs.make_run_scoped.call(void 0, {
|
|
3394
3391
|
// Getters, not a spread: the singletons resolve lazily, so a later
|
|
3395
3392
|
// `store(...)` / `cache(...)` still takes effect.
|
|
3396
3393
|
get store() {
|
|
@@ -3400,14 +3397,14 @@ var Act = (_class7 = class {
|
|
|
3400
3397
|
return ports.cache;
|
|
3401
3398
|
},
|
|
3402
3399
|
// Parsed per build, so a bad window throws on every build.
|
|
3403
|
-
autoclose_window:
|
|
3400
|
+
autoclose_window: _chunkKGJQXN3Scjs.resolveAutocloseConfig.call(void 0, options).autocloseWindow
|
|
3404
3401
|
});
|
|
3405
3402
|
this._correlator = _nullishCoalesce(options.correlator, () => ( default_correlator));
|
|
3406
3403
|
this._es = build_es(this._logger, this._correlator, patch_fn);
|
|
3407
3404
|
this._cd = build_drain(this._logger);
|
|
3408
3405
|
const handle = build_handle({
|
|
3409
3406
|
logger: this._logger,
|
|
3410
|
-
reaction_scope:
|
|
3407
|
+
reaction_scope: _chunkKGJQXN3Scjs.make_reaction_scope.call(void 0, {
|
|
3411
3408
|
do: this.do.bind(this),
|
|
3412
3409
|
load: this.load.bind(this),
|
|
3413
3410
|
query: this.query.bind(this),
|
|
@@ -3437,12 +3434,12 @@ var Act = (_class7 = class {
|
|
|
3437
3434
|
this._ports.store,
|
|
3438
3435
|
options.listen !== false
|
|
3439
3436
|
);
|
|
3440
|
-
|
|
3437
|
+
_chunkKGJQXN3Scjs.register_weak_disposer.call(void 0, new WeakRef(this), (self) => self.shutdown());
|
|
3441
3438
|
}
|
|
3442
3439
|
// Shared by drain, settle and autoclose; bad knobs throw at build.
|
|
3443
3440
|
_build_breaker(options) {
|
|
3444
3441
|
return new CircuitBreaker(
|
|
3445
|
-
|
|
3442
|
+
_chunkKGJQXN3Scjs.resolveCircuitBreakerConfig.call(void 0, options.circuitBreaker),
|
|
3446
3443
|
{
|
|
3447
3444
|
on_error: (error, circuit) => this._emit_error(error, circuit),
|
|
3448
3445
|
// When the cooldown elapses, settle once: its scan or claim is the
|
|
@@ -3454,7 +3451,7 @@ var Act = (_class7 = class {
|
|
|
3454
3451
|
// Apps that declare no lanes pass no lane filter to `claim`.
|
|
3455
3452
|
_build_drain_controllers(options, lanes, handle, handle_batch) {
|
|
3456
3453
|
const all_lanes = this._declared_lanes;
|
|
3457
|
-
const only_set = _optionalChain([options, 'access',
|
|
3454
|
+
const only_set = _optionalChain([options, 'access', _151 => _151.onlyLanes, 'optionalAccess', _152 => _152.length]) ? new Set(options.onlyLanes) : void 0;
|
|
3458
3455
|
const active_lanes = only_set ? all_lanes.filter((n) => only_set.has(n)) : all_lanes;
|
|
3459
3456
|
const single_default_lane = lanes.length === 0;
|
|
3460
3457
|
const controllers = /* @__PURE__ */ new Map();
|
|
@@ -3476,7 +3473,7 @@ var Act = (_class7 = class {
|
|
|
3476
3473
|
try {
|
|
3477
3474
|
await this._run_close(targets);
|
|
3478
3475
|
} catch (error) {
|
|
3479
|
-
if (error instanceof
|
|
3476
|
+
if (error instanceof _chunkVD4BLAY4cjs.StoreError) throw error;
|
|
3480
3477
|
this._logger.error(
|
|
3481
3478
|
error,
|
|
3482
3479
|
`Reaction-requested close of ${targets.map((t) => `"${t.stream}"`).join(", ")} failed and was not retried; close it with app.close(...) once the cause is fixed.`
|
|
@@ -3491,7 +3488,7 @@ var Act = (_class7 = class {
|
|
|
3491
3488
|
leaseMillis: cfg.leaseMillis
|
|
3492
3489
|
}
|
|
3493
3490
|
});
|
|
3494
|
-
if (_optionalChain([cfg, 'optionalAccess',
|
|
3491
|
+
if (_optionalChain([cfg, 'optionalAccess', _153 => _153.cycleMs]) !== void 0 && this._drain)
|
|
3495
3492
|
controller.start(cfg.cycleMs);
|
|
3496
3493
|
controllers.set(name, controller);
|
|
3497
3494
|
}
|
|
@@ -3510,7 +3507,7 @@ var Act = (_class7 = class {
|
|
|
3510
3507
|
// Audit deps, built after the controllers so the lane set is final.
|
|
3511
3508
|
_build_audit_deps() {
|
|
3512
3509
|
return {
|
|
3513
|
-
store:
|
|
3510
|
+
store: _chunkKGJQXN3Scjs.store,
|
|
3514
3511
|
event_to_state: this._event_to_state,
|
|
3515
3512
|
// Declared lanes, not this process's controllers: a lane another
|
|
3516
3513
|
// worker drains is not `unknown-lane`.
|
|
@@ -3523,7 +3520,7 @@ var Act = (_class7 = class {
|
|
|
3523
3520
|
registry: this.registry,
|
|
3524
3521
|
static_targets: classification.static_targets,
|
|
3525
3522
|
cd: this._cd,
|
|
3526
|
-
max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => (
|
|
3523
|
+
max_subscribed_streams: _nullishCoalesce(options.maxSubscribedStreams, () => ( _chunkVD4BLAY4cjs.DEFAULT_MAX_SUBSCRIBED_STREAMS)),
|
|
3527
3524
|
// Declared lanes (not active ones): a lane another process claims is
|
|
3528
3525
|
// still a valid destination.
|
|
3529
3526
|
declared_lanes: new Set(this._declared_lanes),
|
|
@@ -3539,10 +3536,10 @@ var Act = (_class7 = class {
|
|
|
3539
3536
|
// Cold start: an idle deferred stream still fires on time after a restart.
|
|
3540
3537
|
async _seed_persisted_defers() {
|
|
3541
3538
|
const now = Date.now();
|
|
3542
|
-
await walk_streams(
|
|
3539
|
+
await walk_streams(_chunkKGJQXN3Scjs.store.call(void 0, ), (pos) => {
|
|
3543
3540
|
if (pos.deferred_at === void 0 || pos.deferred_at <= now) return;
|
|
3544
3541
|
const controller = this._drain_controllers.get(_nullishCoalesce(pos.lane, () => ( "default")));
|
|
3545
|
-
_optionalChain([controller, 'optionalAccess',
|
|
3542
|
+
_optionalChain([controller, 'optionalAccess', _154 => _154.seed_defer, 'call', _155 => _155(pos.stream, pos.deferred_at)]);
|
|
3546
3543
|
});
|
|
3547
3544
|
}
|
|
3548
3545
|
_build_settle(options) {
|
|
@@ -3555,7 +3552,7 @@ var Act = (_class7 = class {
|
|
|
3555
3552
|
on_settled: (drain) => this.emit("settled", drain),
|
|
3556
3553
|
breaker: this._breaker
|
|
3557
3554
|
},
|
|
3558
|
-
_nullishCoalesce(options.settleDebounceMs, () => (
|
|
3555
|
+
_nullishCoalesce(options.settleDebounceMs, () => ( _chunkVD4BLAY4cjs.DEFAULT_SETTLE_DEBOUNCE_MS))
|
|
3559
3556
|
);
|
|
3560
3557
|
}
|
|
3561
3558
|
|
|
@@ -3575,7 +3572,7 @@ var Act = (_class7 = class {
|
|
|
3575
3572
|
*/
|
|
3576
3573
|
shutdown(options) {
|
|
3577
3574
|
if (!this._shutdown_promise) {
|
|
3578
|
-
|
|
3575
|
+
_chunkKGJQXN3Scjs.resolveShutdownConfig.call(void 0, options);
|
|
3579
3576
|
this._shutdown_promise = (async () => {
|
|
3580
3577
|
this.stop_correlations();
|
|
3581
3578
|
this._settle.stop(true);
|
|
@@ -3583,7 +3580,7 @@ var Act = (_class7 = class {
|
|
|
3583
3580
|
for (const c of this._drain_controllers.values()) c.stop();
|
|
3584
3581
|
const disposer = await this._notify_disposer;
|
|
3585
3582
|
if (disposer) await disposer();
|
|
3586
|
-
await this._await_inflight(_optionalChain([options, 'optionalAccess',
|
|
3583
|
+
await this._await_inflight(_optionalChain([options, 'optionalAccess', _156 => _156.graceMs]));
|
|
3587
3584
|
await this._scoped(() => this._correlate.release_correlation());
|
|
3588
3585
|
this._emitter.removeAllListeners();
|
|
3589
3586
|
})();
|
|
@@ -3593,10 +3590,10 @@ var Act = (_class7 = class {
|
|
|
3593
3590
|
// The largest `leaseMillis` among lanes with a cycle in flight (the
|
|
3594
3591
|
// default for none or 0, and for a running settle), capped.
|
|
3595
3592
|
_derive_grace_ms(running, settling) {
|
|
3596
|
-
let max = settling ?
|
|
3593
|
+
let max = settling ? _chunkKGJQXN3Scjs.DEFAULT_LEASE_MILLIS : 0;
|
|
3597
3594
|
for (const c of running)
|
|
3598
|
-
max = Math.max(max, c.lease_millis ||
|
|
3599
|
-
return Math.min(max,
|
|
3595
|
+
max = Math.max(max, c.lease_millis || _chunkKGJQXN3Scjs.DEFAULT_LEASE_MILLIS);
|
|
3596
|
+
return Math.min(max, _chunkKGJQXN3Scjs.MAX_SHUTDOWN_GRACE_MS);
|
|
3600
3597
|
}
|
|
3601
3598
|
async _await_inflight(grace_ms) {
|
|
3602
3599
|
const running = [...this._drain_controllers.values()].filter(
|
|
@@ -3680,8 +3677,8 @@ var Act = (_class7 = class {
|
|
|
3680
3677
|
* @see {@link ValidationError}, {@link PreconditionError}, {@link ConcurrencyError}
|
|
3681
3678
|
*/
|
|
3682
3679
|
async do(action2, target, payload, options) {
|
|
3683
|
-
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
3684
|
-
const do_options = reacting_to === _optionalChain([options, 'optionalAccess',
|
|
3680
|
+
const reacting_to = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _157 => _157.reactingTo]), () => ( _chunkKGJQXN3Scjs.current_reacting.call(void 0, )));
|
|
3681
|
+
const do_options = reacting_to === _optionalChain([options, 'optionalAccess', _158 => _158.reactingTo]) ? options : { ...options, reactingTo: reacting_to };
|
|
3685
3682
|
return this._scoped(async () => {
|
|
3686
3683
|
const snapshots = await this._es.action(
|
|
3687
3684
|
this.registry.actions[action2],
|
|
@@ -3755,11 +3752,11 @@ var Act = (_class7 = class {
|
|
|
3755
3752
|
return this._scoped(async () => {
|
|
3756
3753
|
let first;
|
|
3757
3754
|
let last;
|
|
3758
|
-
const count = await
|
|
3755
|
+
const count = await _chunkKGJQXN3Scjs.store.call(void 0, ).query((e) => {
|
|
3759
3756
|
const gated = this.registry.query_gate(e.name)(e);
|
|
3760
3757
|
if (!first) first = gated;
|
|
3761
3758
|
last = gated;
|
|
3762
|
-
_optionalChain([callback, 'optionalCall',
|
|
3759
|
+
_optionalChain([callback, 'optionalCall', _159 => _159(gated)]);
|
|
3763
3760
|
}, query);
|
|
3764
3761
|
return { first, last, count };
|
|
3765
3762
|
});
|
|
@@ -3785,7 +3782,7 @@ var Act = (_class7 = class {
|
|
|
3785
3782
|
async query_array(query) {
|
|
3786
3783
|
return this._scoped(async () => {
|
|
3787
3784
|
const events = [];
|
|
3788
|
-
await
|
|
3785
|
+
await _chunkKGJQXN3Scjs.store.call(void 0, ).query((e) => {
|
|
3789
3786
|
events.push(this.registry.query_gate(e.name)(e));
|
|
3790
3787
|
}, query);
|
|
3791
3788
|
return events;
|
|
@@ -3805,14 +3802,14 @@ var Act = (_class7 = class {
|
|
|
3805
3802
|
*/
|
|
3806
3803
|
async forget(stream) {
|
|
3807
3804
|
return this._scoped(async () => {
|
|
3808
|
-
const s =
|
|
3805
|
+
const s = _chunkKGJQXN3Scjs.store.call(void 0, );
|
|
3809
3806
|
if (!s.forget_pii) {
|
|
3810
3807
|
throw new Error(
|
|
3811
3808
|
`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).`
|
|
3812
3809
|
);
|
|
3813
3810
|
}
|
|
3814
3811
|
const eventCount = await s.forget_pii(stream);
|
|
3815
|
-
await
|
|
3812
|
+
await _chunkKGJQXN3Scjs.cache.call(void 0, ).invalidate(stream);
|
|
3816
3813
|
if (eventCount > 0) {
|
|
3817
3814
|
this.emit("forgotten", { stream, at: /* @__PURE__ */ new Date(), eventCount });
|
|
3818
3815
|
}
|
|
@@ -3846,7 +3843,7 @@ var Act = (_class7 = class {
|
|
|
3846
3843
|
* @see {@link correlate} for dynamic stream discovery
|
|
3847
3844
|
*/
|
|
3848
3845
|
async drain(options = {}) {
|
|
3849
|
-
|
|
3846
|
+
_chunkKGJQXN3Scjs.resolveDrainConfig.call(void 0, options);
|
|
3850
3847
|
if (!this._drain)
|
|
3851
3848
|
return { fetched: [], leased: [], acked: [], blocked: [] };
|
|
3852
3849
|
return this._scoped(() => this._drain_all(options));
|
|
@@ -3884,7 +3881,7 @@ var Act = (_class7 = class {
|
|
|
3884
3881
|
}
|
|
3885
3882
|
if (to_arm.size === 0) return false;
|
|
3886
3883
|
this._correlate.arm();
|
|
3887
|
-
for (const lane of to_arm) _optionalChain([this, 'access',
|
|
3884
|
+
for (const lane of to_arm) _optionalChain([this, 'access', _160 => _160._drain_controllers, 'access', _161 => _161.get, 'call', _162 => _162(lane), 'optionalAccess', _163 => _163.arm, 'call', _164 => _164()]);
|
|
3888
3885
|
return true;
|
|
3889
3886
|
}
|
|
3890
3887
|
// In parallel, so a slow lane never holds up a fast one.
|
|
@@ -4026,9 +4023,9 @@ var Act = (_class7 = class {
|
|
|
4026
4023
|
*/
|
|
4027
4024
|
async reset(input) {
|
|
4028
4025
|
return this._scoped(async () => {
|
|
4029
|
-
const count = await
|
|
4026
|
+
const count = await _chunkKGJQXN3Scjs.store.call(void 0, ).reset(input);
|
|
4030
4027
|
for (const handler of this._batch_handlers.values())
|
|
4031
|
-
_optionalChain([handler, 'access',
|
|
4028
|
+
_optionalChain([handler, 'access', _165 => _165[FOLD_RESET], 'optionalCall', _166 => _166()]);
|
|
4032
4029
|
if (count > 0) {
|
|
4033
4030
|
this._wake();
|
|
4034
4031
|
}
|
|
@@ -4062,7 +4059,7 @@ var Act = (_class7 = class {
|
|
|
4062
4059
|
*/
|
|
4063
4060
|
async unblock(input) {
|
|
4064
4061
|
return this._scoped(async () => {
|
|
4065
|
-
const count = await
|
|
4062
|
+
const count = await _chunkKGJQXN3Scjs.store.call(void 0, ).unblock(input);
|
|
4066
4063
|
if (count > 0) {
|
|
4067
4064
|
this._wake();
|
|
4068
4065
|
}
|
|
@@ -4117,7 +4114,7 @@ var Act = (_class7 = class {
|
|
|
4117
4114
|
return { ...partial, duration_ms: Date.now() - started };
|
|
4118
4115
|
}
|
|
4119
4116
|
const target = _nullishCoalesce(sink, () => ( (() => {
|
|
4120
|
-
const s =
|
|
4117
|
+
const s = _chunkKGJQXN3Scjs.store.call(void 0, );
|
|
4121
4118
|
if (!s.restore) throw new Error("adapter has no restore capability");
|
|
4122
4119
|
return s;
|
|
4123
4120
|
})()));
|
|
@@ -4163,11 +4160,11 @@ var Act = (_class7 = class {
|
|
|
4163
4160
|
async blocked_streams(options) {
|
|
4164
4161
|
return this._scoped(async () => {
|
|
4165
4162
|
const positions = [];
|
|
4166
|
-
await
|
|
4163
|
+
await _chunkKGJQXN3Scjs.store.call(void 0, ).query_streams(
|
|
4167
4164
|
(p) => {
|
|
4168
4165
|
positions.push(p);
|
|
4169
4166
|
},
|
|
4170
|
-
{ blocked: true, after: _optionalChain([options, 'optionalAccess',
|
|
4167
|
+
{ blocked: true, after: _optionalChain([options, 'optionalAccess', _167 => _167.after]), limit: _optionalChain([options, 'optionalAccess', _168 => _168.limit]) }
|
|
4171
4168
|
);
|
|
4172
4169
|
return positions;
|
|
4173
4170
|
});
|
|
@@ -4215,7 +4212,7 @@ var Act = (_class7 = class {
|
|
|
4215
4212
|
* @see {@link Store.prioritize} for the underlying primitive
|
|
4216
4213
|
*/
|
|
4217
4214
|
async prioritize(filter, priority) {
|
|
4218
|
-
return this._scoped(() =>
|
|
4215
|
+
return this._scoped(() => _chunkKGJQXN3Scjs.store.call(void 0, ).prioritize(filter, priority));
|
|
4219
4216
|
}
|
|
4220
4217
|
// Shared by `close()` and reaction-requested closes.
|
|
4221
4218
|
async _run_close(targets) {
|
|
@@ -4295,7 +4292,7 @@ var Act = (_class7 = class {
|
|
|
4295
4292
|
* @see {@link correlate} for manual correlation
|
|
4296
4293
|
*/
|
|
4297
4294
|
settle(options) {
|
|
4298
|
-
|
|
4295
|
+
_chunkKGJQXN3Scjs.resolveSettleConfig.call(void 0, _nullishCoalesce(options, () => ( {})));
|
|
4299
4296
|
this._schedule(options);
|
|
4300
4297
|
}
|
|
4301
4298
|
}, _class7);
|
|
@@ -4303,9 +4300,9 @@ var Act = (_class7 = class {
|
|
|
4303
4300
|
// src/builders/merge.ts
|
|
4304
4301
|
|
|
4305
4302
|
function base_type_name(schema) {
|
|
4306
|
-
let def =
|
|
4307
|
-
for (let inner =
|
|
4308
|
-
def =
|
|
4303
|
+
let def = _chunkVD4BLAY4cjs.def_of.call(void 0, schema);
|
|
4304
|
+
for (let inner = _chunkVD4BLAY4cjs.inner_of.call(void 0, def); inner; inner = _chunkVD4BLAY4cjs.inner_of.call(void 0, def))
|
|
4305
|
+
def = _chunkVD4BLAY4cjs.def_of.call(void 0, inner);
|
|
4309
4306
|
return def.type === "array" ? `array of ${base_type_name(def.element)}` : def.type;
|
|
4310
4307
|
}
|
|
4311
4308
|
function merge_schemas(existing, incoming, state_name) {
|
|
@@ -4492,9 +4489,9 @@ var _this_ = ({ stream }) => ({
|
|
|
4492
4489
|
|
|
4493
4490
|
// src/builders/builder-utils.ts
|
|
4494
4491
|
function register_lane(config2, lanes) {
|
|
4495
|
-
|
|
4496
|
-
if (config2.name ===
|
|
4497
|
-
throw new Error(`Lane "${
|
|
4492
|
+
_chunkKGJQXN3Scjs.resolveLaneConfig.call(void 0, config2);
|
|
4493
|
+
if (config2.name === _chunkVD4BLAY4cjs.DEFAULT_LANE)
|
|
4494
|
+
throw new Error(`Lane "${_chunkVD4BLAY4cjs.DEFAULT_LANE}" is reserved`);
|
|
4498
4495
|
const existing = lanes.find((l) => l.name === config2.name);
|
|
4499
4496
|
if (!existing) return void lanes.push(config2);
|
|
4500
4497
|
if (existing.leaseMillis !== config2.leaseMillis || existing.streamLimit !== config2.streamLimit || existing.cycleMs !== config2.cycleMs)
|
|
@@ -4536,10 +4533,10 @@ function reaction_on(event, events, builder) {
|
|
|
4536
4533
|
// Validate the whole bag at the declaration site so a bad
|
|
4537
4534
|
// `maxRetries`/`backoff`/`blockOnError` throws ZodError at build,
|
|
4538
4535
|
// not a NaN gate on the first retry.
|
|
4539
|
-
options:
|
|
4540
|
-
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4541
|
-
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
4542
|
-
backoff: _optionalChain([options, 'optionalAccess',
|
|
4536
|
+
options: _chunkKGJQXN3Scjs.resolveReactionConfig.call(void 0, {
|
|
4537
|
+
blockOnError: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _169 => _169.blockOnError]), () => ( _chunkKGJQXN3Scjs.DEFAULT_BLOCK_ON_ERROR)),
|
|
4538
|
+
maxRetries: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _170 => _170.maxRetries]), () => ( _chunkKGJQXN3Scjs.DEFAULT_MAX_RETRIES)),
|
|
4539
|
+
backoff: _optionalChain([options, 'optionalAccess', _171 => _171.backoff])
|
|
4543
4540
|
})
|
|
4544
4541
|
};
|
|
4545
4542
|
},
|
|
@@ -4559,7 +4556,7 @@ function reaction_on(event, events, builder) {
|
|
|
4559
4556
|
// src/internal/date-reviver.ts
|
|
4560
4557
|
|
|
4561
4558
|
function variant_schema(schema, walk) {
|
|
4562
|
-
const shape = _optionalChain([
|
|
4559
|
+
const shape = _optionalChain([_chunkVD4BLAY4cjs.def_of.call(void 0, schema), 'optionalAccess', _172 => _172.shape]);
|
|
4563
4560
|
if (!shape) {
|
|
4564
4561
|
const dates = walk(schema);
|
|
4565
4562
|
return { schema: _nullishCoalesce(dates, () => ( schema)), dated: !!dates };
|
|
@@ -4596,7 +4593,7 @@ function date_reviver_schema(schema) {
|
|
|
4596
4593
|
return first && recursive ? pass(true) : first;
|
|
4597
4594
|
}
|
|
4598
4595
|
function build(schema, walk) {
|
|
4599
|
-
const def =
|
|
4596
|
+
const def = _chunkVD4BLAY4cjs.def_of.call(void 0, schema);
|
|
4600
4597
|
if (!def) return void 0;
|
|
4601
4598
|
const inner = () => walk(def.innerType);
|
|
4602
4599
|
switch (def.type) {
|
|
@@ -4631,7 +4628,7 @@ function build(schema, walk) {
|
|
|
4631
4628
|
return variants.some((v) => v.dated) ? _zod.z.union(variants.map((v) => v.schema)) : void 0;
|
|
4632
4629
|
}
|
|
4633
4630
|
case "nullable":
|
|
4634
|
-
return _optionalChain([inner, 'call',
|
|
4631
|
+
return _optionalChain([inner, 'call', _173 => _173(), 'optionalAccess', _174 => _174.nullable, 'call', _175 => _175()]);
|
|
4635
4632
|
case "pipe":
|
|
4636
4633
|
return walk(def.out);
|
|
4637
4634
|
case "lazy":
|
|
@@ -4642,13 +4639,13 @@ function build(schema, walk) {
|
|
|
4642
4639
|
return left && right ? left.pipe(right) : _nullishCoalesce(left, () => ( right));
|
|
4643
4640
|
}
|
|
4644
4641
|
default:
|
|
4645
|
-
return
|
|
4642
|
+
return _chunkVD4BLAY4cjs.inner_of.call(void 0, def) ? inner() : void 0;
|
|
4646
4643
|
}
|
|
4647
4644
|
}
|
|
4648
4645
|
|
|
4649
4646
|
// src/builders/event-builder.ts
|
|
4650
4647
|
function event_tags(schema) {
|
|
4651
|
-
const pii =
|
|
4648
|
+
const pii = _chunkVD4BLAY4cjs.pii_schemas.call(void 0, schema);
|
|
4652
4649
|
const pii_dates = {};
|
|
4653
4650
|
for (const [key, field] of Object.entries(pii)) {
|
|
4654
4651
|
const dates = date_reviver_schema(field);
|
|
@@ -4686,7 +4683,7 @@ function make_event_reader(tags, disclosure, predicate = null) {
|
|
|
4686
4683
|
});
|
|
4687
4684
|
}
|
|
4688
4685
|
function build_events(registry, states, lanes, owners) {
|
|
4689
|
-
const declared = /* @__PURE__ */ new Set([
|
|
4686
|
+
const declared = /* @__PURE__ */ new Set([_chunkVD4BLAY4cjs.DEFAULT_LANE, ...lanes.map((l) => l.name)]);
|
|
4690
4687
|
const lane_errors = [];
|
|
4691
4688
|
const tags = /* @__PURE__ */ new Map();
|
|
4692
4689
|
const sensitive2 = /* @__PURE__ */ new Map();
|
|
@@ -4761,7 +4758,7 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4761
4758
|
if (reader) readers.set(event_name, reader);
|
|
4762
4759
|
}
|
|
4763
4760
|
const snap2 = make_event_reader(event_tags(state2.state), "redact", null);
|
|
4764
|
-
if (snap2) readers.set(
|
|
4761
|
+
if (snap2) readers.set(_chunkVD4BLAY4cjs.SNAP_EVENT, snap2);
|
|
4765
4762
|
if (readers.size === 0) continue;
|
|
4766
4763
|
state2.view = (event, actor) => (_nullishCoalesce(readers.get(event.name), () => ( IDENTITY_GATE)))(event, actor);
|
|
4767
4764
|
}
|
|
@@ -4769,7 +4766,7 @@ function build_events(registry, states, lanes, owners) {
|
|
|
4769
4766
|
return { sensitive: sensitive2, advisory, query_readers, handler_readers };
|
|
4770
4767
|
}
|
|
4771
4768
|
function reads_as_string(schema) {
|
|
4772
|
-
const type = _optionalChain([
|
|
4769
|
+
const type = _optionalChain([_chunkVD4BLAY4cjs.def_of.call(void 0, _chunkVD4BLAY4cjs.output_of.call(void 0, schema)), 'optionalAccess', _176 => _176.type]);
|
|
4773
4770
|
return type === "string" || type === "transform";
|
|
4774
4771
|
}
|
|
4775
4772
|
|
|
@@ -4827,7 +4824,7 @@ function act() {
|
|
|
4827
4824
|
let _built = false;
|
|
4828
4825
|
const read_wrap = (original) => {
|
|
4829
4826
|
const wrapped = async (events, stream) => {
|
|
4830
|
-
const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access',
|
|
4827
|
+
const read = events.map((e) => _nullishCoalesce(_optionalChain([_hr, 'access', _177 => _177.get, 'call', _178 => _178(e.name), 'optionalCall', _179 => _179(e)]), () => ( e)));
|
|
4831
4828
|
return original(read, stream);
|
|
4832
4829
|
};
|
|
4833
4830
|
const reset = original[FOLD_RESET];
|
|
@@ -4868,7 +4865,7 @@ function act() {
|
|
|
4868
4865
|
});
|
|
4869
4866
|
}
|
|
4870
4867
|
for (const [action_name, handler] of Object.entries(state2.on)) {
|
|
4871
|
-
const static_target = _optionalChain([handler, 'optionalAccess',
|
|
4868
|
+
const static_target = _optionalChain([handler, 'optionalAccess', _180 => _180._static_emit]);
|
|
4872
4869
|
if (static_target && deprecated.has(static_target)) {
|
|
4873
4870
|
const current = current_version_of(static_target, event_names);
|
|
4874
4871
|
throw new Error(
|
|
@@ -4881,7 +4878,7 @@ function act() {
|
|
|
4881
4878
|
const list = deprecation_summary.map(
|
|
4882
4879
|
(d) => `"${d.deprecated}" (current: "${d.current}", state: "${d.state_name}")`
|
|
4883
4880
|
).join(", ");
|
|
4884
|
-
|
|
4881
|
+
_chunkKGJQXN3Scjs.log.call(void 0, ).info(
|
|
4885
4882
|
`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.`
|
|
4886
4883
|
);
|
|
4887
4884
|
}
|
|
@@ -4923,7 +4920,7 @@ function act() {
|
|
|
4923
4920
|
return reaction_on(event, registry.events, builder);
|
|
4924
4921
|
},
|
|
4925
4922
|
build: (options) => {
|
|
4926
|
-
|
|
4923
|
+
_chunkKGJQXN3Scjs.resolveActConfig.call(void 0, options);
|
|
4927
4924
|
if (!_built) {
|
|
4928
4925
|
for (const proj of pending_projections) add_projection(proj);
|
|
4929
4926
|
for (const proj of fold_projections) {
|
|
@@ -4941,7 +4938,7 @@ function act() {
|
|
|
4941
4938
|
`State projection "${proj.target}" of "${fold.name}" is missing events ${missing.join(", ")} \u2014 pass every partial of the state to .of()`
|
|
4942
4939
|
);
|
|
4943
4940
|
const claimed = fold_specs.find((s) => s.target === proj.target);
|
|
4944
|
-
if (_optionalChain([claimed, 'optionalAccess',
|
|
4941
|
+
if (_optionalChain([claimed, 'optionalAccess', _181 => _181.projection]) === proj) continue;
|
|
4945
4942
|
if (batch_handlers.has(proj.target) || claimed)
|
|
4946
4943
|
throw new Error(
|
|
4947
4944
|
`Duplicate projection target "${proj.target}" \u2014 a target is served by one batch handler or one state projection, never both`
|
|
@@ -4963,7 +4960,7 @@ function act() {
|
|
|
4963
4960
|
for (const [name, gate] of built.query_readers) _qg.set(name, gate);
|
|
4964
4961
|
for (const [name, gate] of built.handler_readers) _hr.set(name, gate);
|
|
4965
4962
|
finalize_deprecations();
|
|
4966
|
-
if (built.advisory)
|
|
4963
|
+
if (built.advisory) _chunkKGJQXN3Scjs.log.call(void 0, ).warn(built.advisory);
|
|
4967
4964
|
for (const [name, state2] of states) {
|
|
4968
4965
|
if (!state2.loads) continue;
|
|
4969
4966
|
const resolved = {};
|
|
@@ -4975,7 +4972,7 @@ function act() {
|
|
|
4975
4972
|
`Action "${action2}" loads "${l.state.name}", which is not registered \u2014 add it via withState/withSlice before build()`
|
|
4976
4973
|
);
|
|
4977
4974
|
const deprecated = l.events.find(
|
|
4978
|
-
(e) => _optionalChain([_de, 'access',
|
|
4975
|
+
(e) => _optionalChain([_de, 'access', _182 => _182.get, 'call', _183 => _183(registered.name), 'optionalAccess', _184 => _184.has, 'call', _185 => _185(e)])
|
|
4979
4976
|
);
|
|
4980
4977
|
if (deprecated)
|
|
4981
4978
|
throw new Error(
|
|
@@ -5007,7 +5004,7 @@ function act() {
|
|
|
5007
5004
|
synthesize_autoclose_reactions(
|
|
5008
5005
|
registry,
|
|
5009
5006
|
states,
|
|
5010
|
-
|
|
5007
|
+
_chunkKGJQXN3Scjs.current_autoclose_window
|
|
5011
5008
|
);
|
|
5012
5009
|
Object.freeze(registry.actions);
|
|
5013
5010
|
Object.freeze(registry.events);
|
|
@@ -5055,8 +5052,8 @@ function _projection(target) {
|
|
|
5055
5052
|
handler,
|
|
5056
5053
|
resolver: _nullishCoalesce(default_resolver, () => ( _this_)),
|
|
5057
5054
|
options: {
|
|
5058
|
-
blockOnError:
|
|
5059
|
-
maxRetries:
|
|
5055
|
+
blockOnError: _chunkKGJQXN3Scjs.DEFAULT_BLOCK_ON_ERROR,
|
|
5056
|
+
maxRetries: _chunkKGJQXN3Scjs.DEFAULT_MAX_RETRIES
|
|
5060
5057
|
}
|
|
5061
5058
|
}),
|
|
5062
5059
|
widened
|
|
@@ -5097,7 +5094,7 @@ function _projection(target) {
|
|
|
5097
5094
|
throw new Error(
|
|
5098
5095
|
`Projection "${target}" .of() partials must share one state name \u2014 got "${name}" and "${partial.name}"`
|
|
5099
5096
|
);
|
|
5100
|
-
const config2 =
|
|
5097
|
+
const config2 = _chunkKGJQXN3Scjs.resolveFoldConfig.call(void 0, options);
|
|
5101
5098
|
const fold_events = {};
|
|
5102
5099
|
for (const partial of partials)
|
|
5103
5100
|
for (const [event_name, schema] of Object.entries(partial.events)) {
|
|
@@ -5115,8 +5112,8 @@ function _projection(target) {
|
|
|
5115
5112
|
handler: noop,
|
|
5116
5113
|
resolver: { target },
|
|
5117
5114
|
options: {
|
|
5118
|
-
blockOnError:
|
|
5119
|
-
maxRetries:
|
|
5115
|
+
blockOnError: _chunkKGJQXN3Scjs.DEFAULT_BLOCK_ON_ERROR,
|
|
5116
|
+
maxRetries: _chunkKGJQXN3Scjs.DEFAULT_MAX_RETRIES
|
|
5120
5117
|
}
|
|
5121
5118
|
}
|
|
5122
5119
|
]
|
|
@@ -5232,7 +5229,7 @@ function action_builder(state2) {
|
|
|
5232
5229
|
throw new Error(`Duplicate action "${action2}"`);
|
|
5233
5230
|
internal.actions[action2] = schema;
|
|
5234
5231
|
if (options) {
|
|
5235
|
-
|
|
5232
|
+
_chunkKGJQXN3Scjs.resolveActionConfig.call(void 0, options);
|
|
5236
5233
|
internal.options ??= {};
|
|
5237
5234
|
internal.options[action2] = options;
|
|
5238
5235
|
}
|
|
@@ -5304,8 +5301,9 @@ function action_builder(state2) {
|
|
|
5304
5301
|
internal.autoclose = compile_autoclose_policy(
|
|
5305
5302
|
policy
|
|
5306
5303
|
);
|
|
5307
|
-
|
|
5308
|
-
internal.autoclose_after_windows =
|
|
5304
|
+
const windows = policy_after_windows(policy);
|
|
5305
|
+
internal.autoclose_after_windows = windows;
|
|
5306
|
+
internal.autoclose_after_days = windows.length ? Math.min(...windows) : void 0;
|
|
5309
5307
|
internal.autoclose_keep_days = policy_keep_days(policy);
|
|
5310
5308
|
return builder;
|
|
5311
5309
|
},
|
|
@@ -5544,5 +5542,9 @@ function write_line(writer, line) {
|
|
|
5544
5542
|
|
|
5545
5543
|
|
|
5546
5544
|
|
|
5547
|
-
|
|
5545
|
+
|
|
5546
|
+
|
|
5547
|
+
|
|
5548
|
+
|
|
5549
|
+
exports.Act = Act; exports.ActorSchema = _chunkVD4BLAY4cjs.ActorSchema; exports.CausationEventSchema = _chunkVD4BLAY4cjs.CausationEventSchema; exports.CommittedMetaSchema = _chunkVD4BLAY4cjs.CommittedMetaSchema; exports.ConcurrencyError = _chunkVD4BLAY4cjs.ConcurrencyError; exports.ConsoleLogger = _chunkKGJQXN3Scjs.ConsoleLogger; exports.CsvFile = CsvFile; exports.DEFAULT_LANE = _chunkVD4BLAY4cjs.DEFAULT_LANE; exports.DEFAULT_MAX_SUBSCRIBED_STREAMS = _chunkVD4BLAY4cjs.DEFAULT_MAX_SUBSCRIBED_STREAMS; exports.DEFAULT_QUERY_STREAMS_LIMIT = _chunkKGJQXN3Scjs.DEFAULT_QUERY_STREAMS_LIMIT; exports.DEFAULT_SETTLE_DEBOUNCE_MS = _chunkVD4BLAY4cjs.DEFAULT_SETTLE_DEBOUNCE_MS; exports.DeferSignal = _chunkVD4BLAY4cjs.DeferSignal; exports.Environments = _chunkVD4BLAY4cjs.Environments; exports.Errors = _chunkVD4BLAY4cjs.Errors; exports.EventMetaSchema = _chunkVD4BLAY4cjs.EventMetaSchema; exports.ExitCodes = _chunkVD4BLAY4cjs.ExitCodes; exports.InMemoryCache = _chunkKGJQXN3Scjs.InMemoryCache; exports.InMemoryStore = _chunkKGJQXN3Scjs.InMemoryStore; exports.LogLevels = _chunkVD4BLAY4cjs.LogLevels; exports.NonRetryableError = _chunkVD4BLAY4cjs.NonRetryableError; exports.PackageSchema = _chunkKGJQXN3Scjs.PackageSchema; exports.PreconditionError = _chunkVD4BLAY4cjs.PreconditionError; exports.QuerySchema = _chunkVD4BLAY4cjs.QuerySchema; exports.REDACTED = _chunkVD4BLAY4cjs.REDACTED; exports.SHREDDED = _chunkVD4BLAY4cjs.SHREDDED; exports.SNAP_EVENT = _chunkVD4BLAY4cjs.SNAP_EVENT; exports.StoreError = _chunkVD4BLAY4cjs.StoreError; exports.StreamClosedError = _chunkVD4BLAY4cjs.StreamClosedError; exports.TOMBSTONE_EVENT = _chunkVD4BLAY4cjs.TOMBSTONE_EVENT; exports.TargetSchema = _chunkVD4BLAY4cjs.TargetSchema; exports.ValidationError = _chunkVD4BLAY4cjs.ValidationError; exports.ZodEmpty = _chunkVD4BLAY4cjs.ZodEmpty; exports.act = act; exports.cache = _chunkKGJQXN3Scjs.cache; exports.check_appends = _chunkKGJQXN3Scjs.check_appends; exports.concurrency_error = _chunkKGJQXN3Scjs.concurrency_error; exports.config = _chunkKGJQXN3Scjs.config; exports.dateReviver = _chunkKGJQXN3Scjs.dateReviver; exports.default_scope = _chunkKGJQXN3Scjs.default_scope; exports.dispose = _chunkKGJQXN3Scjs.dispose; exports.disposeAndExit = _chunkKGJQXN3Scjs.disposeAndExit; exports.extend = _chunkKGJQXN3Scjs.extend; exports.fair_slots = _chunkKGJQXN3Scjs.fair_slots; exports.is_literal_source = _chunkKGJQXN3Scjs.is_literal_source; exports.log = _chunkKGJQXN3Scjs.log; exports.notification_of = _chunkKGJQXN3Scjs.notification_of; exports.pii_fields = _chunkVD4BLAY4cjs.pii_fields; exports.port = _chunkKGJQXN3Scjs.port; exports.projection = projection; exports.resolveAutocloseConfig = _chunkKGJQXN3Scjs.resolveAutocloseConfig2; exports.seed_event = _chunkKGJQXN3Scjs.seed_event; exports.sensitive = _chunkVD4BLAY4cjs.sensitive; exports.sleep = _chunkKGJQXN3Scjs.sleep; exports.slice = slice; exports.state = state; exports.store = _chunkKGJQXN3Scjs.store; exports.throw_if_stale = _chunkKGJQXN3Scjs.throw_if_stale; exports.validate = _chunkKGJQXN3Scjs.validate;
|
|
5548
5550
|
//# sourceMappingURL=index.cjs.map
|