@rotorsoft/act 1.18.5 → 1.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +30 -7
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/builders/act-builder.d.ts.map +1 -1
- package/dist/@types/internal/autoclose-reaction.d.ts +39 -0
- package/dist/@types/internal/autoclose-reaction.d.ts.map +1 -0
- package/dist/@types/internal/index.d.ts +1 -0
- package/dist/@types/internal/index.d.ts.map +1 -1
- package/dist/index.cjs +190 -157
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +190 -157
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/@types/act.d.ts
CHANGED
|
@@ -254,13 +254,6 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
254
254
|
readonly registry: Registry<TSchemaReg, TEvents, TActions, keyof TStateMap & string>;
|
|
255
255
|
/** Map of state name → state definition; populated by the builder. */
|
|
256
256
|
private readonly _states;
|
|
257
|
-
/**
|
|
258
|
-
* Resolved autoclose configuration (#837 / epic #802). Frozen at
|
|
259
|
-
* `act().build()` via {@link resolveAutocloseConfig}.
|
|
260
|
-
*
|
|
261
|
-
* @internal
|
|
262
|
-
*/
|
|
263
|
-
private readonly _autoclose_config;
|
|
264
257
|
/**
|
|
265
258
|
* Emit a lifecycle event. The payload type is inferred from the event name
|
|
266
259
|
* via {@link ActLifecycleEvents}.
|
|
@@ -359,6 +352,36 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
359
352
|
* instance; later slices fan out one `DrainController` per lane.
|
|
360
353
|
*/
|
|
361
354
|
constructor(registry: Registry<TSchemaReg, TEvents, TActions, keyof TStateMap & string>, states?: Map<string, State<any, any, any>>, batch_handlers?: Map<string, BatchHandler<any>>, options?: ActOptions, lanes?: ReadonlyArray<LaneConfig>);
|
|
355
|
+
/**
|
|
356
|
+
* Circuit breaker shared by every store-polling loop (drain, the settle
|
|
357
|
+
* correlate, autoclose). Validates the knobs eagerly so out-of-range
|
|
358
|
+
* values throw at build time, not on the first cycle tick.
|
|
359
|
+
*/
|
|
360
|
+
private _build_breaker;
|
|
361
|
+
/**
|
|
362
|
+
* One DrainController per active lane. The implicit "default" lane is
|
|
363
|
+
* always present unless onlyLanes excludes it. Each controller filters
|
|
364
|
+
* its claim() by its lane name; the legacy single-controller path is the
|
|
365
|
+
* active set === { "default" } case with `lane: undefined` deps so
|
|
366
|
+
* claim() doesn't filter (preserves the single-lane SQL planner shape
|
|
367
|
+
* for apps that never call withLane).
|
|
368
|
+
*/
|
|
369
|
+
private _build_drain_controllers;
|
|
370
|
+
/**
|
|
371
|
+
* Audit deps bag. Snapshotted after registry classification and
|
|
372
|
+
* drain-controller build so the audit module sees the finalized lane
|
|
373
|
+
* set. Held as an immutable bag — the orchestrator never carries audit
|
|
374
|
+
* logic itself, only this typed contract.
|
|
375
|
+
*/
|
|
376
|
+
private _build_audit_deps;
|
|
377
|
+
/**
|
|
378
|
+
* Correlate cycle over the classified registry. The cold-start callback
|
|
379
|
+
* arms every controller — historical events may need processing —
|
|
380
|
+
* except on writer-only instances (`drain: false`).
|
|
381
|
+
*/
|
|
382
|
+
private _build_correlate;
|
|
383
|
+
/** Settle loop driving correlate + drain to quiescence. */
|
|
384
|
+
private _build_settle;
|
|
362
385
|
/** True after the first `shutdown()` call. Guards idempotency. */
|
|
363
386
|
private _shutdown_promise;
|
|
364
387
|
/**
|
package/dist/@types/act.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"AACA,OAAO,EASL,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EAelB,MAAM,qBAAqB,C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AAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAa7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,KAAK,CACH,UAAU,CAAC,EAAE,aAAa,EAAE,EAC5B,OAAO,CAAC,EAAE,YAAY,GACrB,aAAa,CAAC,YAAY,CAAC;IAI9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACG,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAyBzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;CAO1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/act-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"act-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/act-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAgBjD,OAAO,EAAE,YAAY,EAAO,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,KAAK,EAEL,UAAU,EAGV,MAAM,EACN,cAAc,EACd,OAAO,EACP,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAA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3
|
+
* @category Internal
|
|
4
|
+
*
|
|
5
|
+
* Synthesis of the online close-the-books reaction. `.autocloses(policy)`
|
|
6
|
+
* is not a sweep: it is a reaction on every event the declaring state owns
|
|
7
|
+
* that evaluates the policy against the LIVE head (so a reopened stream
|
|
8
|
+
* re-evaluates correctly), defers to the cooldown's earliest opening
|
|
9
|
+
* (`head.created + the policy's min after`), and closes via `CloseSignal`
|
|
10
|
+
* once the policy holds.
|
|
11
|
+
*
|
|
12
|
+
* Runs at build time — after the registry is fully merged and before the
|
|
13
|
+
* orchestrator classifies it — so the synthesized dynamic resolver is
|
|
14
|
+
* discovered by `classify_registry` and its target stream subscribed. The
|
|
15
|
+
* registry is complete once the builder finishes; the orchestrator never
|
|
16
|
+
* mutates it.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
import type { Registry, SchemaRegister, Schemas, State } from "../types/index.js";
|
|
21
|
+
import { type AutocloseConfig } from "./autoclose-config.js";
|
|
22
|
+
/**
|
|
23
|
+
* Prefix for the synthetic per-aggregate stream the autoclose reaction
|
|
24
|
+
* runs on. `target = \`${AUTOCLOSE_TARGET_PREFIX}${aggregate}\``, `source =
|
|
25
|
+
* aggregate` — a watermark distinct from the aggregate's own reactions, so
|
|
26
|
+
* an autoclose defer never short-circuits them. Internal; not a public
|
|
27
|
+
* surface.
|
|
28
|
+
*/
|
|
29
|
+
export declare const AUTOCLOSE_TARGET_PREFIX = "__autoclose__:";
|
|
30
|
+
/**
|
|
31
|
+
* Inject one synthesized autoclose reaction per `.autocloses(...)` state
|
|
32
|
+
* into the registry's event registers. The handler resolves ports at call
|
|
33
|
+
* time (`store()`), so the reaction is orchestrator-agnostic; the resolved
|
|
34
|
+
* window/cadence config is captured here, at build.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare function synthesize_autoclose_reactions<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas>(registry: Registry<TSchemaReg, TEvents, TActions>, states: ReadonlyMap<string, State<any, any, any>>, config: AutocloseConfig): void;
|
|
39
|
+
//# sourceMappingURL=autoclose-reaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoclose-reaction.d.ts","sourceRoot":"","sources":["../../../src/internal/autoclose-reaction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAEV,QAAQ,EACR,cAAc,EACd,OAAO,EACP,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,uBAAuB,CAAC;AAI/B;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EAExB,QAAQ,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EACjD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,EACjD,MAAM,EAAE,eAAe,GACtB,IAAI,CAgEN"}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
export { type AuditDeps, audit } from "./audit.js";
|
|
20
20
|
export { type AutocloseConfig, DEFAULT_AUTOCLOSE_CYCLE_MINUTES, DEFAULT_CLOSE_BATCH_SIZE, DEFAULT_CLOSE_YIELD_MS, hour_in_zone, in_autoclose_window, resolveAutocloseConfig, } from "./autoclose-config.js";
|
|
21
21
|
export { type AutoclosePolicy, compile_autoclose_policy, policy_min_after_ms, } from "./autoclose-policy.js";
|
|
22
|
+
export { AUTOCLOSE_TARGET_PREFIX, synthesize_autoclose_reactions, } from "./autoclose-reaction.js";
|
|
22
23
|
export type { EventLaneSet } from "./build-classify.js";
|
|
23
24
|
export { ALL_LANES, classify_registry } from "./build-classify.js";
|
|
24
25
|
export { reaction_on, register_lane } from "./builder-utils.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,KAAK,eAAe,EACpB,+BAA+B,EAC/B,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,eAAe,EACpB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,KAAK,EAAE,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AK,YAAY,EACjB,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,MAAM,EACN,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,GACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -2084,6 +2084,108 @@ function compile_autoclose_policy(options) {
|
|
|
2084
2084
|
};
|
|
2085
2085
|
}
|
|
2086
2086
|
|
|
2087
|
+
// src/internal/close-signal.ts
|
|
2088
|
+
var CloseSignal = class extends Error {
|
|
2089
|
+
/**
|
|
2090
|
+
* Stream to close. Omitted → the reaction's own lease stream (a self-close).
|
|
2091
|
+
* The synthesized autoclose reaction sets it to the aggregate stream, since
|
|
2092
|
+
* its lease runs on a synthetic `__autoclose__` target.
|
|
2093
|
+
*/
|
|
2094
|
+
stream;
|
|
2095
|
+
/** Optional archive callback to run while the stream is guarded. */
|
|
2096
|
+
archive;
|
|
2097
|
+
/**
|
|
2098
|
+
* Watermark to ack the requesting reaction to before the close runs. The
|
|
2099
|
+
* close-cycle safety guard skips a stream whose subscriptions (matched by
|
|
2100
|
+
* source) lag the head; the autoclose reaction's `source` is the aggregate,
|
|
2101
|
+
* so it must advance its own watermark to the live head id it evaluated
|
|
2102
|
+
* against — otherwise it blocks its own close. Defaults to the triggering
|
|
2103
|
+
* event id when omitted.
|
|
2104
|
+
*/
|
|
2105
|
+
at;
|
|
2106
|
+
constructor(opts) {
|
|
2107
|
+
super("reaction requested close");
|
|
2108
|
+
this.name = "CloseSignal";
|
|
2109
|
+
this.stream = opts?.stream;
|
|
2110
|
+
this.archive = opts?.archive;
|
|
2111
|
+
this.at = opts?.at;
|
|
2112
|
+
}
|
|
2113
|
+
};
|
|
2114
|
+
|
|
2115
|
+
// src/internal/defer-signal.ts
|
|
2116
|
+
var DeferSignal = class extends Error {
|
|
2117
|
+
/**
|
|
2118
|
+
* The unresolved schedule. The dispatcher turns this into an absolute
|
|
2119
|
+
* due-time by resolving it against the triggering event.
|
|
2120
|
+
*/
|
|
2121
|
+
when;
|
|
2122
|
+
constructor(when) {
|
|
2123
|
+
super("reaction deferred");
|
|
2124
|
+
this.name = "DeferSignal";
|
|
2125
|
+
this.when = when;
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
|
|
2129
|
+
// src/internal/autoclose-reaction.ts
|
|
2130
|
+
var AUTOCLOSE_TARGET_PREFIX = "__autoclose__:";
|
|
2131
|
+
function synthesize_autoclose_reactions(registry, states, config2) {
|
|
2132
|
+
for (const st of states.values()) {
|
|
2133
|
+
const predicate = st.autoclose;
|
|
2134
|
+
if (!predicate) continue;
|
|
2135
|
+
const after_ms = st.autoclose_after_ms;
|
|
2136
|
+
const archiver = st.archive;
|
|
2137
|
+
const reaction = {
|
|
2138
|
+
// Run on a SYNTHETIC stream — `source` is the aggregate, `target` is a
|
|
2139
|
+
// per-aggregate `__autoclose__` key — so the autoclose reaction never
|
|
2140
|
+
// shares a watermark with the aggregate's own reactions. A shared
|
|
2141
|
+
// watermark would let autoclose's defer short-circuit the aggregate's
|
|
2142
|
+
// other reactions (the "a defer affects all reactions on a stream"
|
|
2143
|
+
// hazard). The close still targets the aggregate (`source`).
|
|
2144
|
+
resolver: (e) => ({
|
|
2145
|
+
target: `${AUTOCLOSE_TARGET_PREFIX}${e.stream}`,
|
|
2146
|
+
source: e.stream
|
|
2147
|
+
}),
|
|
2148
|
+
// Never block on autoclose: a transient query/store error should retry,
|
|
2149
|
+
// not quarantine the synthetic stream.
|
|
2150
|
+
options: { blockOnError: false, maxRetries: 3 },
|
|
2151
|
+
handler: async (event) => {
|
|
2152
|
+
const aggregate = event.stream;
|
|
2153
|
+
if (!in_autoclose_window(config2.autocloseWindow, /* @__PURE__ */ new Date()))
|
|
2154
|
+
throw new DeferSignal({
|
|
2155
|
+
at: new Date(Date.now() + config2.autocloseCycleMinutes * 6e4)
|
|
2156
|
+
});
|
|
2157
|
+
const stats = await store2().query_stats([aggregate], {
|
|
2158
|
+
count: true,
|
|
2159
|
+
exclude: [TOMBSTONE_EVENT]
|
|
2160
|
+
});
|
|
2161
|
+
const entry = stats.get(aggregate);
|
|
2162
|
+
if (!entry) return;
|
|
2163
|
+
const head = entry.head;
|
|
2164
|
+
if (predicate(aggregate, head, entry.count))
|
|
2165
|
+
throw new CloseSignal({
|
|
2166
|
+
stream: aggregate,
|
|
2167
|
+
archive: archiver ? () => archiver(aggregate, head) : void 0,
|
|
2168
|
+
// Ack this reaction's own watermark to the live head so the
|
|
2169
|
+
// close-cycle guard (which matches subscriptions by source =
|
|
2170
|
+
// aggregate) sees it caught up instead of blocking its own close.
|
|
2171
|
+
at: head.id
|
|
2172
|
+
});
|
|
2173
|
+
if (after_ms !== void 0)
|
|
2174
|
+
throw new DeferSignal({
|
|
2175
|
+
at: new Date(head.created.getTime() + after_ms)
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
const key = `__autoclose_${st.name}`;
|
|
2180
|
+
for (const event_name of Object.keys(st.events)) {
|
|
2181
|
+
registry.events[event_name]?.reactions.set(
|
|
2182
|
+
key,
|
|
2183
|
+
reaction
|
|
2184
|
+
);
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2087
2189
|
// src/internal/build-classify.ts
|
|
2088
2190
|
var ALL_LANES = /* @__PURE__ */ Symbol("act-1103/all-lanes");
|
|
2089
2191
|
function classify_registry(registry, states) {
|
|
@@ -2139,22 +2241,6 @@ function classify_registry(registry, states) {
|
|
|
2139
2241
|
|
|
2140
2242
|
// src/internal/defer-config.ts
|
|
2141
2243
|
var import_zod7 = require("zod");
|
|
2142
|
-
|
|
2143
|
-
// src/internal/defer-signal.ts
|
|
2144
|
-
var DeferSignal = class extends Error {
|
|
2145
|
-
/**
|
|
2146
|
-
* The unresolved schedule. The dispatcher turns this into an absolute
|
|
2147
|
-
* due-time by resolving it against the triggering event.
|
|
2148
|
-
*/
|
|
2149
|
-
when;
|
|
2150
|
-
constructor(when) {
|
|
2151
|
-
super("reaction deferred");
|
|
2152
|
-
this.name = "DeferSignal";
|
|
2153
|
-
this.when = when;
|
|
2154
|
-
}
|
|
2155
|
-
};
|
|
2156
|
-
|
|
2157
|
-
// src/internal/defer-config.ts
|
|
2158
2244
|
var DeferDurationSchema = import_zod7.z.object({
|
|
2159
2245
|
days: import_zod7.z.number().positive().optional(),
|
|
2160
2246
|
hours: import_zod7.z.number().positive().optional(),
|
|
@@ -2638,34 +2724,6 @@ async function truncate_and_warm_cache(guarded, seed_states, guard_events, corre
|
|
|
2638
2724
|
return truncated;
|
|
2639
2725
|
}
|
|
2640
2726
|
|
|
2641
|
-
// src/internal/close-signal.ts
|
|
2642
|
-
var CloseSignal = class extends Error {
|
|
2643
|
-
/**
|
|
2644
|
-
* Stream to close. Omitted → the reaction's own lease stream (a self-close).
|
|
2645
|
-
* The synthesized autoclose reaction sets it to the aggregate stream, since
|
|
2646
|
-
* its lease runs on a synthetic `__autoclose__` target.
|
|
2647
|
-
*/
|
|
2648
|
-
stream;
|
|
2649
|
-
/** Optional archive callback to run while the stream is guarded. */
|
|
2650
|
-
archive;
|
|
2651
|
-
/**
|
|
2652
|
-
* Watermark to ack the requesting reaction to before the close runs. The
|
|
2653
|
-
* close-cycle safety guard skips a stream whose subscriptions (matched by
|
|
2654
|
-
* source) lag the head; the autoclose reaction's `source` is the aggregate,
|
|
2655
|
-
* so it must advance its own watermark to the live head id it evaluated
|
|
2656
|
-
* against — otherwise it blocks its own close. Defaults to the triggering
|
|
2657
|
-
* event id when omitted.
|
|
2658
|
-
*/
|
|
2659
|
-
at;
|
|
2660
|
-
constructor(opts) {
|
|
2661
|
-
super("reaction requested close");
|
|
2662
|
-
this.name = "CloseSignal";
|
|
2663
|
-
this.stream = opts?.stream;
|
|
2664
|
-
this.archive = opts?.archive;
|
|
2665
|
-
this.at = opts?.at;
|
|
2666
|
-
}
|
|
2667
|
-
};
|
|
2668
|
-
|
|
2669
2727
|
// src/internal/correlate-cycle.ts
|
|
2670
2728
|
var CorrelateCycle = class {
|
|
2671
2729
|
_checkpoint = -1;
|
|
@@ -3833,7 +3891,15 @@ var SettleLoop = class {
|
|
|
3833
3891
|
// src/act.ts
|
|
3834
3892
|
var DEFAULT_MAX_SUBSCRIBED_STREAMS = 1e3;
|
|
3835
3893
|
var DEFAULT_SETTLE_DEBOUNCE_MS = 10;
|
|
3836
|
-
|
|
3894
|
+
function validate_only_lanes(options, lanes) {
|
|
3895
|
+
if (!options.onlyLanes || options.onlyLanes.length === 0) return;
|
|
3896
|
+
const declared = /* @__PURE__ */ new Set(["default", ...lanes.map((l) => l.name)]);
|
|
3897
|
+
const unknown = options.onlyLanes.filter((l) => !declared.has(l));
|
|
3898
|
+
if (unknown.length > 0)
|
|
3899
|
+
throw new Error(
|
|
3900
|
+
`ActOptions.onlyLanes references undeclared lane(s): ${unknown.map((l) => `"${l}"`).join(", ")}`
|
|
3901
|
+
);
|
|
3902
|
+
}
|
|
3837
3903
|
var Act = class {
|
|
3838
3904
|
_emitter = new import_node_events.default();
|
|
3839
3905
|
/** ACT-984: orchestrator-owned circuit breaker shared by all drain lanes. */
|
|
@@ -3868,13 +3934,6 @@ var Act = class {
|
|
|
3868
3934
|
registry;
|
|
3869
3935
|
/** Map of state name → state definition; populated by the builder. */
|
|
3870
3936
|
_states;
|
|
3871
|
-
/**
|
|
3872
|
-
* Resolved autoclose configuration (#837 / epic #802). Frozen at
|
|
3873
|
-
* `act().build()` via {@link resolveAutocloseConfig}.
|
|
3874
|
-
*
|
|
3875
|
-
* @internal
|
|
3876
|
-
*/
|
|
3877
|
-
_autoclose_config;
|
|
3878
3937
|
/**
|
|
3879
3938
|
* Emit a lifecycle event. The payload type is inferred from the event name
|
|
3880
3939
|
* via {@link ActLifecycleEvents}.
|
|
@@ -3991,17 +4050,7 @@ var Act = class {
|
|
|
3991
4050
|
this._states = states;
|
|
3992
4051
|
this._batch_handlers = batch_handlers;
|
|
3993
4052
|
this._lanes = lanes;
|
|
3994
|
-
|
|
3995
|
-
const declared = /* @__PURE__ */ new Set([
|
|
3996
|
-
"default",
|
|
3997
|
-
...lanes.map((l) => l.name)
|
|
3998
|
-
]);
|
|
3999
|
-
const unknown = options.onlyLanes.filter((l) => !declared.has(l));
|
|
4000
|
-
if (unknown.length > 0)
|
|
4001
|
-
throw new Error(
|
|
4002
|
-
`ActOptions.onlyLanes references undeclared lane(s): ${unknown.map((l) => `"${l}"`).join(", ")}`
|
|
4003
|
-
);
|
|
4004
|
-
}
|
|
4053
|
+
validate_only_lanes(options, lanes);
|
|
4005
4054
|
this._scoped = options.scoped ? (fn) => scoped.run(options.scoped, fn) : (fn) => fn();
|
|
4006
4055
|
this._correlator = options.correlator ?? default_correlator;
|
|
4007
4056
|
this._es = build_es(this._logger, this._correlator);
|
|
@@ -4015,99 +4064,59 @@ var Act = class {
|
|
|
4015
4064
|
bound_forget: this._bound_forget
|
|
4016
4065
|
});
|
|
4017
4066
|
this._handle_batch = build_handle_batch(this._logger);
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
const archiver = st.archive;
|
|
4023
|
-
const reaction = {
|
|
4024
|
-
// Run on a SYNTHETIC stream — `source` is the aggregate, `target` is a
|
|
4025
|
-
// per-aggregate `__autoclose__` key — so the autoclose reaction never
|
|
4026
|
-
// shares a watermark with the aggregate's own reactions. A shared
|
|
4027
|
-
// watermark would let autoclose's defer short-circuit the aggregate's
|
|
4028
|
-
// other reactions (the "a defer affects all reactions on a stream"
|
|
4029
|
-
// hazard). The close still targets the aggregate (`source`).
|
|
4030
|
-
resolver: (e) => ({
|
|
4031
|
-
target: `${AUTOCLOSE_TARGET_PREFIX}${e.stream}`,
|
|
4032
|
-
source: e.stream
|
|
4033
|
-
}),
|
|
4034
|
-
// Never block on autoclose: a transient query/store error should retry,
|
|
4035
|
-
// not quarantine the synthetic stream.
|
|
4036
|
-
options: { blockOnError: false, maxRetries: 3 },
|
|
4037
|
-
handler: async (event) => {
|
|
4038
|
-
const aggregate = event.stream;
|
|
4039
|
-
const config2 = this._autoclose_config;
|
|
4040
|
-
if (!in_autoclose_window(config2.autocloseWindow, /* @__PURE__ */ new Date()))
|
|
4041
|
-
throw new DeferSignal({
|
|
4042
|
-
at: new Date(Date.now() + config2.autocloseCycleMinutes * 6e4)
|
|
4043
|
-
});
|
|
4044
|
-
const stats = await store2().query_stats([aggregate], {
|
|
4045
|
-
count: true,
|
|
4046
|
-
exclude: [TOMBSTONE_EVENT]
|
|
4047
|
-
});
|
|
4048
|
-
const entry = stats.get(aggregate);
|
|
4049
|
-
if (!entry) return;
|
|
4050
|
-
const head = entry.head;
|
|
4051
|
-
if (predicate(aggregate, head, entry.count))
|
|
4052
|
-
throw new CloseSignal({
|
|
4053
|
-
stream: aggregate,
|
|
4054
|
-
archive: archiver ? () => archiver(aggregate, head) : void 0,
|
|
4055
|
-
// Ack this reaction's own watermark to the live head so the
|
|
4056
|
-
// close-cycle guard (which matches subscriptions by source =
|
|
4057
|
-
// aggregate) sees it caught up instead of blocking its own close.
|
|
4058
|
-
at: head.id
|
|
4059
|
-
});
|
|
4060
|
-
if (after_ms !== void 0)
|
|
4061
|
-
throw new DeferSignal({
|
|
4062
|
-
at: new Date(head.created.getTime() + after_ms)
|
|
4063
|
-
});
|
|
4064
|
-
}
|
|
4065
|
-
};
|
|
4066
|
-
const key = `__autoclose_${st.name}`;
|
|
4067
|
-
for (const event_name of Object.keys(st.events)) {
|
|
4068
|
-
this.registry.events[event_name]?.reactions.set(
|
|
4069
|
-
key,
|
|
4070
|
-
reaction
|
|
4071
|
-
);
|
|
4072
|
-
}
|
|
4073
|
-
}
|
|
4074
|
-
const {
|
|
4075
|
-
static_targets,
|
|
4076
|
-
has_dynamic_resolvers,
|
|
4077
|
-
reactive_events,
|
|
4078
|
-
event_to_state,
|
|
4079
|
-
event_to_lanes
|
|
4080
|
-
} = classify_registry(this.registry, this._states);
|
|
4081
|
-
this._reactive_events = reactive_events;
|
|
4067
|
+
const classification = classify_registry(this.registry, this._states);
|
|
4068
|
+
this._reactive_events = classification.reactive_events;
|
|
4069
|
+
this._event_to_state = classification.event_to_state;
|
|
4070
|
+
this._event_to_lanes = classification.event_to_lanes;
|
|
4082
4071
|
this._listen = options.listen !== false;
|
|
4083
4072
|
this._drain = options.drain !== false;
|
|
4084
|
-
this.
|
|
4085
|
-
this.
|
|
4073
|
+
this._breaker = this._build_breaker(options);
|
|
4074
|
+
this._drain_controllers = this._build_drain_controllers(options, lanes);
|
|
4075
|
+
this._audit_deps = this._build_audit_deps();
|
|
4076
|
+
this._correlate = this._build_correlate(options, classification);
|
|
4077
|
+
this._settle = this._build_settle(options);
|
|
4078
|
+
this._notify_disposer = this._wire_notify(options.scoped?.store ?? store2());
|
|
4079
|
+
dispose(() => this.shutdown());
|
|
4080
|
+
}
|
|
4081
|
+
/**
|
|
4082
|
+
* Circuit breaker shared by every store-polling loop (drain, the settle
|
|
4083
|
+
* correlate, autoclose). Validates the knobs eagerly so out-of-range
|
|
4084
|
+
* values throw at build time, not on the first cycle tick.
|
|
4085
|
+
*/
|
|
4086
|
+
_build_breaker(options) {
|
|
4087
|
+
return new CircuitBreaker(
|
|
4086
4088
|
resolveCircuitBreakerConfig(options.circuitBreaker),
|
|
4087
4089
|
{
|
|
4088
4090
|
on_error: (error, circuit) => this._emit_error(error, circuit),
|
|
4089
4091
|
// Re-probe the store when the cooldown elapses, so recovery is
|
|
4090
4092
|
// automatic even on the default lane (which has no periodic poller).
|
|
4091
|
-
//
|
|
4092
|
-
//
|
|
4093
|
-
//
|
|
4094
|
-
//
|
|
4095
|
-
//
|
|
4096
|
-
//
|
|
4097
|
-
//
|
|
4098
|
-
// re-opens the breaker and reschedules the wake.
|
|
4093
|
+
// Any polling loop can trip the shared breaker — but a bare `drain()`
|
|
4094
|
+
// only touches the store when the controller is armed, so a trip
|
|
4095
|
+
// from a correlate failure could go unprobed. `settle()` always runs
|
|
4096
|
+
// a correlate (a store query) before draining, so it re-probes
|
|
4097
|
+
// regardless of which loop opened the breaker: one success closes it
|
|
4098
|
+
// and every loop resumes on its own cadence. A failed probe re-opens
|
|
4099
|
+
// the breaker and reschedules the wake.
|
|
4099
4100
|
on_retry: () => {
|
|
4100
4101
|
this.settle({ debounceMs: 0 });
|
|
4101
4102
|
}
|
|
4102
4103
|
}
|
|
4103
4104
|
);
|
|
4104
|
-
|
|
4105
|
-
|
|
4105
|
+
}
|
|
4106
|
+
/**
|
|
4107
|
+
* One DrainController per active lane. The implicit "default" lane is
|
|
4108
|
+
* always present unless onlyLanes excludes it. Each controller filters
|
|
4109
|
+
* its claim() by its lane name; the legacy single-controller path is the
|
|
4110
|
+
* active set === { "default" } case with `lane: undefined` deps so
|
|
4111
|
+
* claim() doesn't filter (preserves the single-lane SQL planner shape
|
|
4112
|
+
* for apps that never call withLane).
|
|
4113
|
+
*/
|
|
4114
|
+
_build_drain_controllers(options, lanes) {
|
|
4106
4115
|
const all_lanes = ["default", ...lanes.map((l) => l.name)];
|
|
4107
4116
|
const only_set = options.onlyLanes && options.onlyLanes.length > 0 ? new Set(options.onlyLanes) : void 0;
|
|
4108
4117
|
const active_lanes = only_set ? all_lanes.filter((n) => only_set.has(n)) : all_lanes;
|
|
4109
4118
|
const single_default_lane = active_lanes.length === 1 && active_lanes[0] === "default";
|
|
4110
|
-
|
|
4119
|
+
const controllers = /* @__PURE__ */ new Map();
|
|
4111
4120
|
for (const name of active_lanes) {
|
|
4112
4121
|
const cfg = lanes.find((l) => l.name === name);
|
|
4113
4122
|
const controller = new DrainController({
|
|
@@ -4119,10 +4128,11 @@ var Act = class {
|
|
|
4119
4128
|
handle_batch: this._handle_batch,
|
|
4120
4129
|
on_acked: (acked) => this.emit("acked", acked),
|
|
4121
4130
|
on_blocked: (blocked) => this.emit("blocked", blocked),
|
|
4122
|
-
// Reaction-requested close
|
|
4131
|
+
// Reaction-requested close. Runs the same close machinery as
|
|
4123
4132
|
// `app.close` (tombstone guard + archive + atomic truncate) for the
|
|
4124
|
-
// targets a handler signalled via `CloseSignal`. No `correlate()`
|
|
4125
|
-
// — the drain that produced these targets has already
|
|
4133
|
+
// targets a handler signalled via `CloseSignal`. No `correlate()`
|
|
4134
|
+
// here — the drain that produced these targets has already
|
|
4135
|
+
// correlated.
|
|
4126
4136
|
on_close: async (targets) => {
|
|
4127
4137
|
const close_actor = { id: "$close", name: "close" };
|
|
4128
4138
|
const result = await run_close_cycle(targets, {
|
|
@@ -4138,7 +4148,7 @@ var Act = class {
|
|
|
4138
4148
|
breaker: this._breaker,
|
|
4139
4149
|
// Pass lane only when a true per-lane controller is active.
|
|
4140
4150
|
// The all-lanes (single default) case keeps lane=undefined so
|
|
4141
|
-
// adapter SQL collapses to the
|
|
4151
|
+
// adapter SQL collapses to the single-lane shape.
|
|
4142
4152
|
lane: single_default_lane ? void 0 : name,
|
|
4143
4153
|
defaults: cfg && {
|
|
4144
4154
|
streamLimit: cfg.streamLimit,
|
|
@@ -4147,30 +4157,47 @@ var Act = class {
|
|
|
4147
4157
|
});
|
|
4148
4158
|
if (cfg?.cycleMs !== void 0 && options.drain !== false)
|
|
4149
4159
|
controller.start(cfg.cycleMs);
|
|
4150
|
-
|
|
4160
|
+
controllers.set(name, controller);
|
|
4151
4161
|
}
|
|
4152
|
-
|
|
4162
|
+
return controllers;
|
|
4163
|
+
}
|
|
4164
|
+
/**
|
|
4165
|
+
* Audit deps bag. Snapshotted after registry classification and
|
|
4166
|
+
* drain-controller build so the audit module sees the finalized lane
|
|
4167
|
+
* set. Held as an immutable bag — the orchestrator never carries audit
|
|
4168
|
+
* logic itself, only this typed contract.
|
|
4169
|
+
*/
|
|
4170
|
+
_build_audit_deps() {
|
|
4171
|
+
return {
|
|
4153
4172
|
store: store2,
|
|
4154
4173
|
logger: this._logger,
|
|
4155
|
-
event_to_state,
|
|
4174
|
+
event_to_state: this._event_to_state,
|
|
4156
4175
|
states: this._states,
|
|
4157
|
-
known_events: new Set(
|
|
4176
|
+
known_events: new Set(this._event_to_state.keys()),
|
|
4158
4177
|
declared_lanes: new Set(this._drain_controllers.keys()),
|
|
4159
|
-
routed_events: new Set(
|
|
4178
|
+
routed_events: new Set(this._event_to_lanes.keys())
|
|
4160
4179
|
};
|
|
4161
|
-
|
|
4180
|
+
}
|
|
4181
|
+
/**
|
|
4182
|
+
* Correlate cycle over the classified registry. The cold-start callback
|
|
4183
|
+
* arms every controller — historical events may need processing —
|
|
4184
|
+
* except on writer-only instances (`drain: false`).
|
|
4185
|
+
*/
|
|
4186
|
+
_build_correlate(options, classification) {
|
|
4187
|
+
return new CorrelateCycle(
|
|
4162
4188
|
this.registry,
|
|
4163
|
-
static_targets,
|
|
4164
|
-
has_dynamic_resolvers,
|
|
4189
|
+
classification.static_targets,
|
|
4190
|
+
classification.has_dynamic_resolvers,
|
|
4165
4191
|
this._cd,
|
|
4166
4192
|
options.maxSubscribedStreams ?? DEFAULT_MAX_SUBSCRIBED_STREAMS,
|
|
4167
|
-
// Cold start: assume drain is needed (historical events may need processing).
|
|
4168
|
-
// #803: writer-only instances skip the cold-start arm.
|
|
4169
4193
|
() => {
|
|
4170
4194
|
if (this._drain && this._reactive_events.size > 0) this._arm_all();
|
|
4171
4195
|
}
|
|
4172
4196
|
);
|
|
4173
|
-
|
|
4197
|
+
}
|
|
4198
|
+
/** Settle loop driving correlate + drain to quiescence. */
|
|
4199
|
+
_build_settle(options) {
|
|
4200
|
+
return new SettleLoop(
|
|
4174
4201
|
{
|
|
4175
4202
|
init: () => this._correlate.init(),
|
|
4176
4203
|
checkpoint: () => this._correlate.checkpoint,
|
|
@@ -4181,8 +4208,6 @@ var Act = class {
|
|
|
4181
4208
|
},
|
|
4182
4209
|
options.settleDebounceMs ?? DEFAULT_SETTLE_DEBOUNCE_MS
|
|
4183
4210
|
);
|
|
4184
|
-
this._notify_disposer = this._wire_notify(options.scoped?.store ?? store2());
|
|
4185
|
-
dispose(() => this.shutdown());
|
|
4186
4211
|
}
|
|
4187
4212
|
/** True after the first `shutdown()` call. Guards idempotency. */
|
|
4188
4213
|
_shutdown_promise;
|
|
@@ -5231,6 +5256,14 @@ function act() {
|
|
|
5231
5256
|
};
|
|
5232
5257
|
batch_handlers.set(target, wrapped);
|
|
5233
5258
|
}
|
|
5259
|
+
synthesize_autoclose_reactions(
|
|
5260
|
+
registry,
|
|
5261
|
+
states,
|
|
5262
|
+
resolveAutocloseConfig(options ?? {})
|
|
5263
|
+
);
|
|
5264
|
+
Object.freeze(registry.actions);
|
|
5265
|
+
Object.freeze(registry.events);
|
|
5266
|
+
Object.freeze(registry);
|
|
5234
5267
|
_built = true;
|
|
5235
5268
|
}
|
|
5236
5269
|
return new Act(
|