@rotorsoft/act 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -379
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +93 -5
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/console-logger.d.ts.map +1 -1
- package/dist/@types/adapters/in-memory-store.d.ts +4 -1
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/builders/act-builder.d.ts +33 -9
- package/dist/@types/builders/act-builder.d.ts.map +1 -1
- package/dist/@types/builders/slice-builder.d.ts +23 -8
- package/dist/@types/builders/slice-builder.d.ts.map +1 -1
- package/dist/@types/internal/audit.d.ts +95 -0
- package/dist/@types/internal/audit.d.ts.map +1 -0
- package/dist/@types/internal/build-classify.d.ts +20 -0
- package/dist/@types/internal/build-classify.d.ts.map +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts +1 -0
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/drain-cycle.d.ts +43 -3
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
- package/dist/@types/internal/drain.d.ts +3 -1
- package/dist/@types/internal/drain.d.ts.map +1 -1
- package/dist/@types/internal/index.d.ts +4 -2
- package/dist/@types/internal/index.d.ts.map +1 -1
- package/dist/@types/internal/reactions.d.ts.map +1 -1
- package/dist/@types/internal/tracing.d.ts +51 -0
- package/dist/@types/internal/tracing.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +10 -0
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/test/sandbox.d.ts +1 -1
- package/dist/@types/test/sandbox.d.ts.map +1 -1
- package/dist/@types/types/audit.d.ts +126 -0
- package/dist/@types/types/audit.d.ts.map +1 -0
- package/dist/@types/types/index.d.ts +1 -0
- package/dist/@types/types/index.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +9 -2
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/@types/types/reaction.d.ts +20 -2
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/{chunk-VMX7RPTC.js → chunk-TZWDSNSN.js} +1 -1
- package/dist/{chunk-VMX7RPTC.js.map → chunk-TZWDSNSN.js.map} +1 -1
- package/dist/{chunk-LKRNWD7C.js → chunk-VC6MSVC3.js} +47 -12
- package/dist/chunk-VC6MSVC3.js.map +1 -0
- package/dist/index.cjs +1584 -886
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1538 -874
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +52 -18
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +11 -11
- package/dist/test/index.js.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-LKRNWD7C.js.map +0 -1
package/dist/@types/act.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Scoped } from "./ports.js";
|
|
2
|
-
import type { Actor, AsOf, BatchHandler, BlockedLease, CloseResult, CloseTarget, Committed, Correlator, Drain, DrainOptions, IAct, Lease, Query, Registry, Schema, SchemaRegister, Schemas, SettleOptions, Snapshot, State, StoreNotification, StreamFilter, StreamPosition, Target } from "./types/index.js";
|
|
2
|
+
import type { Actor, AsOf, AuditCategory, AuditFinding, AuditOptions, BatchHandler, BlockedLease, CloseResult, CloseTarget, Committed, Correlator, Drain, DrainOptions, IAct, LaneConfig, Lease, Query, Registry, Schema, SchemaRegister, Schemas, SettleOptions, Snapshot, State, StoreNotification, StreamFilter, StreamPosition, Target } from "./types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* @category Orchestrator
|
|
5
5
|
* @see Store
|
|
@@ -75,7 +75,7 @@ export type ActLifecycleEvents<TSchemaReg extends SchemaRegister<TActions>, TEve
|
|
|
75
75
|
* Act instance instead of threading the value through every call site.
|
|
76
76
|
* Default: {@link DEFAULT_SETTLE_DEBOUNCE_MS}.
|
|
77
77
|
*/
|
|
78
|
-
export type ActOptions = {
|
|
78
|
+
export type ActOptions<TLanes extends string = string> = {
|
|
79
79
|
readonly maxSubscribedStreams?: number;
|
|
80
80
|
readonly settleDebounceMs?: number;
|
|
81
81
|
/**
|
|
@@ -97,6 +97,8 @@ export type ActOptions = {
|
|
|
97
97
|
* for the close-the-books transaction.
|
|
98
98
|
*/
|
|
99
99
|
readonly correlator?: Correlator;
|
|
100
|
+
/** Restrict this process to a subset of declared lanes (ACT-1103). */
|
|
101
|
+
readonly onlyLanes?: ReadonlyArray<TLanes>;
|
|
100
102
|
};
|
|
101
103
|
export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = Record<string, never>, TActor extends Actor = Actor> implements IAct<TEvents, TActions, TActor> {
|
|
102
104
|
readonly registry: Registry<TSchemaReg, TEvents, TActions>;
|
|
@@ -104,8 +106,8 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
104
106
|
private _emitter;
|
|
105
107
|
/** Event names with at least one registered reaction (computed at build time) */
|
|
106
108
|
private readonly _reactive_events;
|
|
107
|
-
/**
|
|
108
|
-
private readonly
|
|
109
|
+
/** One DrainController per active lane, keyed by lane name. */
|
|
110
|
+
private readonly _drain_controllers;
|
|
109
111
|
/** Correlation state machine: lazy init, dynamic-resolver scan, periodic worker. */
|
|
110
112
|
private readonly _correlate;
|
|
111
113
|
/** Debounced correlate→drain catch-up loop. */
|
|
@@ -151,6 +153,22 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
151
153
|
* set when seeding a `restart` snapshot in multi-state apps.
|
|
152
154
|
*/
|
|
153
155
|
private readonly _event_to_state;
|
|
156
|
+
/**
|
|
157
|
+
* Event-name → lane fan-in for selective arming (ACT-1103). Built by
|
|
158
|
+
* `classifyRegistry` once per build. `"all"` means at least one of
|
|
159
|
+
* the event's reactions is a dynamic resolver (lane opaque until
|
|
160
|
+
* runtime); a `Set<string>` lists the static lanes only that event's
|
|
161
|
+
* reactions target.
|
|
162
|
+
*/
|
|
163
|
+
private readonly _event_to_lanes;
|
|
164
|
+
/**
|
|
165
|
+
* Audit dependency bag (#723). Built once at construction; held as
|
|
166
|
+
* an immutable snapshot of the registry state the audit module
|
|
167
|
+
* needs. Lives in `internal/audit.ts` — this orchestrator never
|
|
168
|
+
* carries audit logic, only the deps + a one-liner that hands them
|
|
169
|
+
* over.
|
|
170
|
+
*/
|
|
171
|
+
private readonly _audit_deps;
|
|
154
172
|
/** Logger resolved at construction time (after user port configuration) */
|
|
155
173
|
private readonly _logger;
|
|
156
174
|
/** Wraps a public-method body so internal `store()`/`cache()` resolve to the
|
|
@@ -174,6 +192,10 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
174
192
|
/** Reaction dispatchers built once and handed to runDrainCycle each cycle. */
|
|
175
193
|
private readonly _handle;
|
|
176
194
|
private readonly _handle_batch;
|
|
195
|
+
/** Declared drain lanes (ACT-1103). */
|
|
196
|
+
private readonly _lanes;
|
|
197
|
+
/** Drain lanes declared via `.withLane(...)`. Implicit default not included. */
|
|
198
|
+
get lanes(): ReadonlyArray<LaneConfig>;
|
|
177
199
|
/**
|
|
178
200
|
* Create a new Act orchestrator. Prefer the {@link act} builder over
|
|
179
201
|
* direct construction — `act()...build()` wires the registry, merges
|
|
@@ -184,8 +206,11 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
184
206
|
* @param _states Merged map of state name → state definition
|
|
185
207
|
* @param batchHandlers Static-target projection batch handlers (target → handler)
|
|
186
208
|
* @param options Tuning knobs — see {@link ActOptions}
|
|
209
|
+
* @param lanes Declared drain lanes (ACT-1103). The builder collects
|
|
210
|
+
* these from `.withLane(...)` calls. Slice 1 records them on the
|
|
211
|
+
* instance; later slices fan out one `DrainController` per lane.
|
|
187
212
|
*/
|
|
188
|
-
constructor(registry: Registry<TSchemaReg, TEvents, TActions>, _states?: Map<string, State<any, any, any>>, batchHandlers?: Map<string, BatchHandler<any>>, options?: ActOptions);
|
|
213
|
+
constructor(registry: Registry<TSchemaReg, TEvents, TActions>, _states?: Map<string, State<any, any, any>>, batchHandlers?: Map<string, BatchHandler<any>>, options?: ActOptions, lanes?: ReadonlyArray<LaneConfig>);
|
|
189
214
|
/** True after the first `shutdown()` call. Guards idempotency. */
|
|
190
215
|
private _shutdown_promise;
|
|
191
216
|
/**
|
|
@@ -447,6 +472,27 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
447
472
|
* @see {@link start_correlations} for automatic correlation
|
|
448
473
|
*/
|
|
449
474
|
drain(options?: DrainOptions): Promise<Drain<TEvents>>;
|
|
475
|
+
/** Arm every active lane controller (ACT-1103). */
|
|
476
|
+
private _armAll;
|
|
477
|
+
/**
|
|
478
|
+
* Arm only the lane controllers whose reactions match the supplied
|
|
479
|
+
* event names (ACT-1103 selective arming). Events with any dynamic
|
|
480
|
+
* resolver fall back to `_armAll()` via the `"all"` sentinel — the
|
|
481
|
+
* resolver's lane isn't known until correlate runs the function.
|
|
482
|
+
* Events with no reactions are skipped; `_event_to_lanes` doesn't
|
|
483
|
+
* carry them. Returns true when any controller was armed (used by
|
|
484
|
+
* the notify handler to decide whether to schedule a settle).
|
|
485
|
+
*/
|
|
486
|
+
private _armForEventNames;
|
|
487
|
+
/** Drain every active lane controller in parallel and aggregate.
|
|
488
|
+
*
|
|
489
|
+
* Parallel — not sequential — so a slow lane's in-flight handler does
|
|
490
|
+
* not block a fast lane's claim/dispatch/ack cycle. Each controller's
|
|
491
|
+
* `claim()` is independent (filtered by lane); the store's
|
|
492
|
+
* `SKIP LOCKED` keeps cross-controller races safe. Lifecycle events
|
|
493
|
+
* (`acked`, `blocked`) may interleave by lane — listeners filter via
|
|
494
|
+
* `lease.lane`. */
|
|
495
|
+
private _drainAll;
|
|
450
496
|
/**
|
|
451
497
|
* Discovers and registers new streams dynamically based on reaction resolvers.
|
|
452
498
|
*
|
|
@@ -663,6 +709,48 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
663
709
|
after?: string;
|
|
664
710
|
limit?: number;
|
|
665
711
|
}): Promise<StreamPosition[]>;
|
|
712
|
+
/**
|
|
713
|
+
* Operator-driven store audit (#723).
|
|
714
|
+
*
|
|
715
|
+
* Walks the connected store and yields per-category findings —
|
|
716
|
+
* each tagged with the remediation it suggests. Same operator-
|
|
717
|
+
* driven category as `app.close()` / `app.reset()` /
|
|
718
|
+
* `app.unblock()` / `app.blocked_streams()`: never auto-invoked by
|
|
719
|
+
* the framework; the operator decides when to run it (CI gate,
|
|
720
|
+
* scheduled job, ad-hoc forensics) and what to do with the
|
|
721
|
+
* findings.
|
|
722
|
+
*
|
|
723
|
+
* Categories are independent — pass a subset to scope the work,
|
|
724
|
+
* or omit to run everything:
|
|
725
|
+
*
|
|
726
|
+
* ```typescript
|
|
727
|
+
* // Targeted: schema drift + deprecated-event load only
|
|
728
|
+
* for await (const f of app.audit(["schema", "deprecated-load"], {
|
|
729
|
+
* query: { created_after: lastScan },
|
|
730
|
+
* thresholds: { deprecatedLoadShareMin: 0.10 },
|
|
731
|
+
* })) {
|
|
732
|
+
* await escalate(f);
|
|
733
|
+
* }
|
|
734
|
+
*
|
|
735
|
+
* // Full audit, default thresholds
|
|
736
|
+
* for await (const f of app.audit()) console.log(f);
|
|
737
|
+
* ```
|
|
738
|
+
*
|
|
739
|
+
* Returns an `AsyncIterable` so callers can `break` early — the
|
|
740
|
+
* underlying store paginations respect the iterator protocol and
|
|
741
|
+
* stop cleanly. Each finding is emitted independently, so
|
|
742
|
+
* pipelining into Slack / persistence / further analysis works
|
|
743
|
+
* without buffering the full report in memory.
|
|
744
|
+
*
|
|
745
|
+
* Findings shape — see {@link AuditFinding}. The discriminated
|
|
746
|
+
* union carries enough context for the operator to act on each
|
|
747
|
+
* finding directly: stream id, event id, recommendation hints.
|
|
748
|
+
*
|
|
749
|
+
* @param categories - Subset of categories to run (default: all).
|
|
750
|
+
* @param options - Query window + per-category thresholds.
|
|
751
|
+
* @returns Async iterable of {@link AuditFinding}.
|
|
752
|
+
*/
|
|
753
|
+
audit(categories?: AuditCategory[], options?: AuditOptions): AsyncIterable<AuditFinding>;
|
|
666
754
|
/**
|
|
667
755
|
* Bulk-update scheduling priority for streams matching `filter`.
|
|
668
756
|
*
|
package/dist/@types/act.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAgB,KAAK,MAAM,EAAiB,MAAM,YAAY,CAAC;AACtE,OAAO,KAAK,EACV,KAAK,EACL,IAAI,EACJ,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,EACV,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,KAAK,EAEL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,aAAa,EACb,QAAQ,EACR,KAAK,EAEL,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,MAAM,EACP,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,OAAO,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,KAAK,CAAC;AAE7C;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAC5B,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,IACtB;IACF,SAAS,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,EAA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Q,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;gBAG9B,OAAO,GAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B;IAwBR,yDAAyD;IACnD,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9B,kBAAkB;IAClB,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM;IAQhD,OAAO,CAAC,UAAU;IAgDlB,OAAO,CAAC,YAAY;CA0CrB"}
|
|
@@ -118,7 +118,7 @@ export declare class InMemoryStore implements Store {
|
|
|
118
118
|
* @param millis - Lease duration in milliseconds.
|
|
119
119
|
* @returns Granted leases.
|
|
120
120
|
*/
|
|
121
|
-
claim(lagging: number, leading: number, by: string, millis: number): Promise<Lease[]>;
|
|
121
|
+
claim(lagging: number, leading: number, by: string, millis: number, lane?: string): Promise<Lease[]>;
|
|
122
122
|
/**
|
|
123
123
|
* Registers streams for event processing. When the same stream is
|
|
124
124
|
* resubscribed with a different priority, the **maximum** wins — so
|
|
@@ -132,6 +132,7 @@ export declare class InMemoryStore implements Store {
|
|
|
132
132
|
stream: string;
|
|
133
133
|
source?: string;
|
|
134
134
|
priority?: number;
|
|
135
|
+
lane?: string;
|
|
135
136
|
}>): Promise<{
|
|
136
137
|
subscribed: number;
|
|
137
138
|
watermark: number;
|
|
@@ -147,6 +148,7 @@ export declare class InMemoryStore implements Store {
|
|
|
147
148
|
by: string;
|
|
148
149
|
retry: number;
|
|
149
150
|
lagging: boolean;
|
|
151
|
+
lane: string;
|
|
150
152
|
}[]>;
|
|
151
153
|
/**
|
|
152
154
|
* Block a stream for processing after failing to process and reaching max retries with blocking enabled.
|
|
@@ -161,6 +163,7 @@ export declare class InMemoryStore implements Store {
|
|
|
161
163
|
retry: number;
|
|
162
164
|
error: string;
|
|
163
165
|
lagging: boolean;
|
|
166
|
+
lane: string;
|
|
164
167
|
}[]>;
|
|
165
168
|
/**
|
|
166
169
|
* Build a predicate from a {@link StreamFilter}. Compiled regexes are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory-store.d.ts","sourceRoot":"","sources":["../../../src/adapters/in-memory-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACT,KAAK,EACL,OAAO,EACP,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"in-memory-store.d.ts","sourceRoot":"","sources":["../../../src/adapters/in-memory-store.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACT,KAAK,EACL,OAAO,EACP,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,KAAK,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAwL3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,qBAAa,aAAc,YAAW,KAAK;IAEzC,OAAO,CAAC,OAAO,CAA2C;IAE1D,OAAO,CAAC,QAAQ,CAA0C;IAE1D,OAAO,CAAC,eAAe,CAAkC;IAGzD,OAAO,CAAC,mBAAmB,CAAkC;IAE7D,OAAO,CAAC,kBAAkB,CAAM;IAEhC,OAAO,CAAC,aAAa;IAOrB;;;OAGG;IACG,OAAO;IAKb;;;OAGG;IACG,IAAI;IAIV;;;OAGG;IACG,IAAI;IAMV,OAAO,CAAC,QAAQ;IAahB;;;;;OAKG;IACG,KAAK,CAAC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,YAAY,GACnB,OAAO,CAAC,kBAAkB,CAAC;IA0D9B;;;;;;;;;;;;;;;OAeG;IACG,WAAW,CAAC,CAAC,SAAS,OAAO,EACjC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,cAAc,CAAC,EAC/D,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IA6EvC;;;;OAIG;IACG,QAAQ,CACZ,OAAO,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,CAAC;iBAmBW,MAAM;mBAAa,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;;CA6BpE"}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* Fluent builder for composing event-sourced applications.
|
|
6
6
|
*/
|
|
7
7
|
import { Act, type ActOptions } from "../act.js";
|
|
8
|
-
import
|
|
8
|
+
import { DEFAULT_LANE } from "../ports.js";
|
|
9
|
+
import type { Actor, Committed, EventRegister, IAct, LaneConfig, ReactionOptions, ReactionResolver, Schema, SchemaRegister, Schemas, Snapshot, State } from "../types/index.js";
|
|
9
10
|
import type { Projection } from "./projection-builder.js";
|
|
10
11
|
import type { Slice } from "./slice-builder.js";
|
|
11
12
|
/**
|
|
@@ -16,6 +17,7 @@ import type { Slice } from "./slice-builder.js";
|
|
|
16
17
|
* - Registering slices via `.withSlice()`
|
|
17
18
|
* - Registering projections via `.withProjection()`
|
|
18
19
|
* - Locking a custom actor type via `.withActor<TActor>()`
|
|
20
|
+
* - Declaring drain lanes via `.withLane({name, ...})` (ACT-1103)
|
|
19
21
|
* - Defining event reactions via `.on()` → `.do()` → `.to()`
|
|
20
22
|
* - Building the orchestrator via `.build()`
|
|
21
23
|
*
|
|
@@ -24,11 +26,14 @@ import type { Slice } from "./slice-builder.js";
|
|
|
24
26
|
* @template TActions - Action schemas (maps action names to action payload schemas)
|
|
25
27
|
* @template TStateMap - Map of state names to state schemas
|
|
26
28
|
* @template TActor - Actor type extending base Actor
|
|
29
|
+
* @template TLanes - Union of declared lane names (ACT-1103). Narrowed by
|
|
30
|
+
* `.withLane({name})` calls so `.to({lane})` and `ActOptions.onlyLanes`
|
|
31
|
+
* reject typos at compile time. Starts at `"default"`.
|
|
27
32
|
*
|
|
28
33
|
* @see {@link act} for usage examples
|
|
29
34
|
* @see {@link Act} for the built orchestrator API
|
|
30
35
|
*/
|
|
31
|
-
export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
36
|
+
export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor, TLanes extends string = typeof DEFAULT_LANE> = {
|
|
32
37
|
/**
|
|
33
38
|
* Registers a state definition with the builder.
|
|
34
39
|
*
|
|
@@ -41,7 +46,7 @@ export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents exte
|
|
|
41
46
|
[K in keyof TNewActions]: TNewState;
|
|
42
47
|
}, TEvents & TNewEvents, TActions & TNewActions, TStateMap & {
|
|
43
48
|
[K in TNewName]: TNewState;
|
|
44
|
-
}, TActor>;
|
|
49
|
+
}, TActor, TLanes>;
|
|
45
50
|
/**
|
|
46
51
|
* Registers a slice with the builder.
|
|
47
52
|
*
|
|
@@ -51,14 +56,14 @@ export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents exte
|
|
|
51
56
|
*
|
|
52
57
|
* @throws {Error} If duplicate action or event names are detected
|
|
53
58
|
*/
|
|
54
|
-
withSlice: <TNewSchemaReg extends SchemaRegister<TNewActions>, TNewEvents extends Schemas, TNewActions extends Schemas, TNewMap extends Record<string, Schema
|
|
59
|
+
withSlice: <TNewSchemaReg extends SchemaRegister<TNewActions>, TNewEvents extends Schemas, TNewActions extends Schemas, TNewMap extends Record<string, Schema>, TNewLanes extends string>(slice: Slice<TNewSchemaReg, TNewEvents, TNewActions, TNewMap, Actor, TNewLanes>) => ActBuilder<TSchemaReg & TNewSchemaReg, TEvents & TNewEvents, TActions & TNewActions, TStateMap & TNewMap, TActor, TLanes | TNewLanes>;
|
|
55
60
|
/**
|
|
56
61
|
* Registers a standalone projection with the builder.
|
|
57
62
|
*
|
|
58
63
|
* The projection's events must be a subset of events already registered
|
|
59
64
|
* via `.withState()` or `.withSlice()`.
|
|
60
65
|
*/
|
|
61
|
-
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
66
|
+
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes>;
|
|
62
67
|
/**
|
|
63
68
|
* Locks a custom actor type for this application.
|
|
64
69
|
*
|
|
@@ -85,7 +90,23 @@ export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents exte
|
|
|
85
90
|
* }, { by: 5 });
|
|
86
91
|
* ```
|
|
87
92
|
*/
|
|
88
|
-
withActor: <TNewActor extends Actor>() => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TNewActor>;
|
|
93
|
+
withActor: <TNewActor extends Actor>() => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TNewActor, TLanes>;
|
|
94
|
+
/**
|
|
95
|
+
* Declares a drain lane (ACT-1103). Lane name narrows `TLanes` so
|
|
96
|
+
* `.to({lane})` and `ActOptions.onlyLanes` type-check against it.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const app = act()
|
|
101
|
+
* .withState(Counter)
|
|
102
|
+
* .withLane({ name: "slow", leaseMillis: 60_000, streamLimit: 5 })
|
|
103
|
+
* .on("OrderConfirmed")
|
|
104
|
+
* .do(deliverWebhook)
|
|
105
|
+
* .to({ target: "webhooks-out", lane: "slow" })
|
|
106
|
+
* .build();
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
withLane: <const TConfig extends LaneConfig>(config: TConfig) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes | TConfig["name"]>;
|
|
89
110
|
/**
|
|
90
111
|
* Begins defining a reaction to a specific event.
|
|
91
112
|
*
|
|
@@ -98,19 +119,22 @@ export type ActBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents exte
|
|
|
98
119
|
* @returns An object with `.do()` method to define the reaction handler
|
|
99
120
|
*/
|
|
100
121
|
on: <TKey extends keyof TEvents>(event: TKey) => {
|
|
101
|
-
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: IAct<TEvents, TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor> & {
|
|
102
|
-
to: (resolver: ReactionResolver<TEvents, TKey> | string) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
122
|
+
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: IAct<TEvents, TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes> & {
|
|
123
|
+
to: (resolver: ReactionResolver<TEvents, TKey, TLanes> | string) => ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes>;
|
|
103
124
|
};
|
|
104
125
|
};
|
|
105
126
|
/**
|
|
106
127
|
* Builds and returns the Act orchestrator instance.
|
|
107
128
|
*
|
|
108
129
|
* @param options - Optional runtime overrides (see {@link ActOptions}).
|
|
130
|
+
* `options.onlyLanes` is narrowed to the declared `TLanes` union, so
|
|
131
|
+
* `onlyLanes: ["typo"]` is a compile error when the lane wasn't
|
|
132
|
+
* declared via `.withLane(...)`.
|
|
109
133
|
* @returns The Act orchestrator instance
|
|
110
134
|
*
|
|
111
135
|
* @see {@link Act} for available orchestrator methods
|
|
112
136
|
*/
|
|
113
|
-
build: (options?: ActOptions) => Act<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
137
|
+
build: (options?: ActOptions<TLanes>) => Act<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
114
138
|
/**
|
|
115
139
|
* The registered event schemas and their reaction maps.
|
|
116
140
|
*/
|
|
@@ -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;AASjD,OAAO,EAAE,YAAY,EAAO,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,KAAK,EAEL,SAAS,EACT,aAAa,EACb,IAAI,EACJ,UAAU,EAEV,eAAe,EACf,gBAAgB,EAEhB,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAgDhD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,UAAU,CACpB,UAAU,SAA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Q,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;SAC3E,CAAC;KACH,CAAC;IACF;;;;;;;;;;OAUG;IACH,KAAK,EAAE,CACL,OAAO,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,KACzB,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3D;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,GAAG,CAEjB,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,GAAG,EAAE,EAChD,OAAO,SAAS,OAAO,GAAG,EAAE,EAC5B,QAAQ,SAAS,OAAO,GAAG,EAAE,EAC7B,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,EAC7C,MAAM,SAAS,KAAK,GAAG,KAAK,KACzB,UAAU,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAuMhE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DEFAULT_LANE } from "../ports.js";
|
|
2
|
+
import type { Actor, Committed, EventRegister, IAct, LaneConfig, ReactionOptions, ReactionResolver, Schema, SchemaRegister, Schemas, Snapshot, State } from "../types/index.js";
|
|
2
3
|
import type { Projection } from "./projection-builder.js";
|
|
3
4
|
/**
|
|
4
5
|
* A self-contained functional slice grouping partial states with their
|
|
@@ -11,17 +12,26 @@ import type { Projection } from "./projection-builder.js";
|
|
|
11
12
|
* @template TStateMap - Map of state names to state schemas
|
|
12
13
|
* @template TActor - Actor type extending base Actor
|
|
13
14
|
*/
|
|
14
|
-
export type Slice<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
15
|
+
export type Slice<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor, TLanes extends string = typeof DEFAULT_LANE> = {
|
|
15
16
|
readonly _tag: "Slice";
|
|
16
17
|
readonly states: Map<string, State<any, any, any>>;
|
|
17
18
|
readonly events: EventRegister<TEvents>;
|
|
18
19
|
readonly projections: ReadonlyArray<Projection<any>>;
|
|
20
|
+
/**
|
|
21
|
+
* Drain lanes declared on this slice via `.withLane(...)` (ACT-1103).
|
|
22
|
+
* `act().withSlice(slice)` merges these into the Act's lane set so
|
|
23
|
+
* `.to({lane})` is statically checked at the slice's call site against
|
|
24
|
+
* the lanes the slice itself declared.
|
|
25
|
+
*/
|
|
26
|
+
readonly lanes: ReadonlyArray<LaneConfig>;
|
|
19
27
|
/** @internal phantom field for type-level state schema tracking */
|
|
20
28
|
readonly _S?: TSchemaReg;
|
|
21
29
|
/** @internal phantom field for type-level state name tracking */
|
|
22
30
|
readonly _M?: TStateMap;
|
|
23
31
|
/** @internal phantom field for type-level actor tracking */
|
|
24
32
|
readonly _TActor?: TActor;
|
|
33
|
+
/** @internal phantom field for type-level lane union tracking */
|
|
34
|
+
readonly _TLanes?: TLanes;
|
|
25
35
|
};
|
|
26
36
|
/**
|
|
27
37
|
* Fluent builder interface for composing functional slices.
|
|
@@ -35,7 +45,7 @@ export type Slice<TSchemaReg extends SchemaRegister<TActions>, TEvents extends S
|
|
|
35
45
|
* @template TStateMap - Map of state names to state schemas
|
|
36
46
|
* @template TActor - Actor type extending base Actor
|
|
37
47
|
*/
|
|
38
|
-
export type SliceBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor> = {
|
|
48
|
+
export type SliceBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas, TStateMap extends Record<string, Schema> = {}, TActor extends Actor = Actor, TLanes extends string = typeof DEFAULT_LANE> = {
|
|
39
49
|
/**
|
|
40
50
|
* Registers a state definition with the slice.
|
|
41
51
|
*
|
|
@@ -47,26 +57,31 @@ export type SliceBuilder<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
|
|
|
47
57
|
[K in keyof TNewActions]: TNewState;
|
|
48
58
|
}, TEvents & TNewEvents, TActions & TNewActions, TStateMap & {
|
|
49
59
|
[K in TNewName]: TNewState;
|
|
50
|
-
}, TActor>;
|
|
60
|
+
}, TActor, TLanes>;
|
|
51
61
|
/**
|
|
52
62
|
* Embeds a built Projection within this slice. The projection's events
|
|
53
63
|
* must be a subset of events from states already registered via
|
|
54
64
|
* `.withState()`. Projection handlers preserve their `(event, stream)`
|
|
55
65
|
* signature and do not receive the app interface.
|
|
56
66
|
*/
|
|
57
|
-
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
67
|
+
withProjection: <TNewEvents extends Schemas>(projection: [Exclude<keyof TNewEvents, keyof TEvents>] extends [never] ? Projection<TNewEvents> : never) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes>;
|
|
68
|
+
/**
|
|
69
|
+
* Declares a drain lane on this slice (ACT-1103). Merged into the
|
|
70
|
+
* parent Act's lane set by `act().withSlice(slice)`.
|
|
71
|
+
*/
|
|
72
|
+
withLane: <const TConfig extends LaneConfig>(config: TConfig) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes | TConfig["name"]>;
|
|
58
73
|
/**
|
|
59
74
|
* Begins defining a reaction scoped to this slice's events.
|
|
60
75
|
*/
|
|
61
76
|
on: <TKey extends keyof TEvents>(event: TKey) => {
|
|
62
|
-
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: IAct<TEvents, TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor> & {
|
|
63
|
-
to: (resolver: ReactionResolver<TEvents, TKey> | string) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
77
|
+
do: (handler: (event: Committed<TEvents, TKey>, stream: string, app: IAct<TEvents, TActions, TActor>) => Promise<Snapshot<Schema, TEvents> | void>, options?: Partial<ReactionOptions>) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes> & {
|
|
78
|
+
to: (resolver: ReactionResolver<TEvents, TKey, TLanes> | string) => SliceBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes>;
|
|
64
79
|
};
|
|
65
80
|
};
|
|
66
81
|
/**
|
|
67
82
|
* Builds and returns the Slice data structure.
|
|
68
83
|
*/
|
|
69
|
-
build: () => Slice<TSchemaReg, TEvents, TActions, TStateMap, TActor>;
|
|
84
|
+
build: () => Slice<TSchemaReg, TEvents, TActions, TStateMap, TActor, TLanes>;
|
|
70
85
|
/**
|
|
71
86
|
* The registered event schemas and their reaction maps.
|
|
72
87
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/slice-builder.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,IAAI,
|
|
1
|
+
{"version":3,"file":"slice-builder.d.ts","sourceRoot":"","sources":["../../../src/builders/slice-builder.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EACV,KAAK,EACL,SAAS,EACT,aAAa,EACb,IAAI,EACJ,UAAU,EAEV,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,cAAc,EACd,OAAO,EACP,QAAQ,EACR,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK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-category {@link AuditFinding}s.
|
|
8
|
+
* Each category answers a different "what should I do with this store?"
|
|
9
|
+
* question and pairs with a remediation:
|
|
10
|
+
*
|
|
11
|
+
* - `schema` → fix the data model (poison events, unknown names)
|
|
12
|
+
* - `close-candidate` → `app.close([...])`
|
|
13
|
+
* - `restart-candidate` → `app.close([{stream, restart:true}, …])`
|
|
14
|
+
* - `deprecated-load` → `app.close([...])` on the heaviest carriers
|
|
15
|
+
* - `reaction-health` → `app.unblock(...)` / `app.reset(...)`
|
|
16
|
+
* - `snapshot-drift` → manual `load({snap:true})` or wait for policy
|
|
17
|
+
* - `routing-health` → restart-with-new-config to re-lane
|
|
18
|
+
* - `correlation-gaps` → fix upstream correlator misconfig
|
|
19
|
+
* - `clock-anomalies` → infra remediation (clock skew)
|
|
20
|
+
*
|
|
21
|
+
* ## Single-scan multiplex (efficiency contract)
|
|
22
|
+
*
|
|
23
|
+
* Earlier draft had each category run its own `store.query(...)`,
|
|
24
|
+
* which meant N requested categories → N table walks. Bad for large
|
|
25
|
+
* stores. Refactored to a pass-based design: each category is a
|
|
26
|
+
* factory that returns an {@link AuditPass} with optional per-row
|
|
27
|
+
* callbacks (`onEvent` / `onStream` / `onStat`) and a `finalize` hook
|
|
28
|
+
* for any second-pass work. The dispatcher determines the UNION of
|
|
29
|
+
* required data sources, runs each *once*, and broadcasts each row
|
|
30
|
+
* to all interested passes. Worst case: three scans total (events,
|
|
31
|
+
* streams, stats) regardless of how many categories the operator
|
|
32
|
+
* requested. Most categories also share state — close-candidate and
|
|
33
|
+
* restart-candidate both consume the same `onStat` stream; schema,
|
|
34
|
+
* correlation-gaps, and clock-anomalies all hang off the same
|
|
35
|
+
* `onEvent` broadcast.
|
|
36
|
+
*
|
|
37
|
+
* Categories that need follow-up work (snapshot-drift's per-stream
|
|
38
|
+
* snapshot lookup, correlation-gaps' orphan-id check after collecting
|
|
39
|
+
* ids) do that in their `finalize` hook with their own targeted store
|
|
40
|
+
* calls — keeps the shared scan path minimal.
|
|
41
|
+
*
|
|
42
|
+
* Isolated from orchestration internals — `act.ts` builds the
|
|
43
|
+
* {@link AuditDeps} bag at `.build()` time and hands it here via
|
|
44
|
+
* a one-liner. The audit module never reaches into
|
|
45
|
+
* `internal/{event-sourcing,drain-cycle,settle,close-cycle}.ts`; it
|
|
46
|
+
* only reads through the deps interface and the public `Store`
|
|
47
|
+
* surface. Same shape as `act-tck` within the workspace — a peer of
|
|
48
|
+
* orchestration, not entangled with its private mechanics.
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
import type { AuditCategory, AuditFinding, AuditOptions, Logger, State, Store } from "../types/index.js";
|
|
53
|
+
/**
|
|
54
|
+
* Snapshot of orchestrator state the audit reads. Built once at
|
|
55
|
+
* `app.build()`; the audit treats it as immutable for the duration
|
|
56
|
+
* of a call. The orchestrator never passes its own private maps in
|
|
57
|
+
* directly — this bag is the abstraction boundary so a future
|
|
58
|
+
* orchestration refactor can't accidentally entangle with audit
|
|
59
|
+
* logic.
|
|
60
|
+
*/
|
|
61
|
+
export type AuditDeps = {
|
|
62
|
+
readonly store: () => Store;
|
|
63
|
+
readonly logger: Logger;
|
|
64
|
+
/** event-name → state that registers it (for schema validation). */
|
|
65
|
+
readonly event_to_state: ReadonlyMap<string, State<any, any, any>>;
|
|
66
|
+
/** state-name → state (for snapshot-supported check on restart-candidate). */
|
|
67
|
+
readonly states: ReadonlyMap<string, State<any, any, any>>;
|
|
68
|
+
/** All event names the registry knows (for unknown-name detection). */
|
|
69
|
+
readonly known_events: ReadonlySet<string>;
|
|
70
|
+
/** Declared drain lanes (for routing-health unknown-lane). */
|
|
71
|
+
readonly declared_lanes: ReadonlySet<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Event names that the registry has at least one reaction for —
|
|
74
|
+
* used by routing-health to detect "registered but unrouted"
|
|
75
|
+
* events. Normalized down from the internal `eventToLanes` map
|
|
76
|
+
* (which carries lane-set details audit doesn't need).
|
|
77
|
+
*/
|
|
78
|
+
readonly routed_events: ReadonlySet<string>;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Top-level audit dispatcher. Single-scan multiplex: each requested
|
|
82
|
+
* category contributes a `AuditPass`, the dispatcher determines the
|
|
83
|
+
* union of required data sources (events / streams / stats), runs
|
|
84
|
+
* each once, broadcasts rows, and yields per-category findings in
|
|
85
|
+
* the order the categories were requested.
|
|
86
|
+
*
|
|
87
|
+
* Callers can `break` the iteration early — the underlying scan
|
|
88
|
+
* loops have already completed by the time yield starts, so early
|
|
89
|
+
* break only saves the iteration over already-collected findings.
|
|
90
|
+
* (Per-row early termination during a scan isn't feasible without
|
|
91
|
+
* coordination across passes; the audit is bounded by `options.query`
|
|
92
|
+
* scoping rather than mid-scan cancellation.)
|
|
93
|
+
*/
|
|
94
|
+
export declare function audit(deps: AuditDeps, categories?: AuditCategory[], options?: AuditOptions): AsyncIterable<AuditFinding>;
|
|
95
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../src/internal/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EAEZ,MAAM,EAEN,KAAK,EACL,KAAK,EAGN,MAAM,mBAAmB,CAAC;AAG3B;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oEAAoE;IACpE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACnE,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,uEAAuE;IACvE,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3C,8DAA8D;IAC9D,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7C,CAAC;AAmDF;;;;;;;;;;;;;GAaG;AACH,wBAAuB,KAAK,CAC1B,IAAI,EAAE,SAAS,EACf,UAAU,CAAC,EAAE,aAAa,EAAE,EAC5B,OAAO,GAAE,YAAiB,GACzB,aAAa,CAAC,YAAY,CAAC,CA8C7B"}
|
|
@@ -26,11 +26,31 @@ import type { StaticTarget } from "./correlate-cycle.js";
|
|
|
26
26
|
*
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
|
+
/**
|
|
30
|
+
* Sentinel for "any reaction on this event has a dynamic resolver, so
|
|
31
|
+
* the lane is opaque until correlate runs the function — arm every
|
|
32
|
+
* controller." A Symbol rather than a string literal so it can't
|
|
33
|
+
* collide with a user-declared lane named `"all"`.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare const ALL_LANES: unique symbol;
|
|
38
|
+
/**
|
|
39
|
+
* Per-event lane fan-in (ACT-1103). For events whose every reaction
|
|
40
|
+
* has a static resolver, the value is the union of those reactions'
|
|
41
|
+
* declared lanes — `do()` arms only those controllers on commit. For
|
|
42
|
+
* events with at least one dynamic resolver, the value is
|
|
43
|
+
* {@link ALL_LANES}; `do()` falls back to arming every controller.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export type EventLaneSet = ReadonlySet<string> | typeof ALL_LANES;
|
|
29
48
|
export type Classification = {
|
|
30
49
|
readonly staticTargets: StaticTarget[];
|
|
31
50
|
readonly hasDynamicResolvers: boolean;
|
|
32
51
|
readonly reactiveEvents: ReadonlySet<string>;
|
|
33
52
|
readonly eventToState: ReadonlyMap<string, State<any, any, any>>;
|
|
53
|
+
readonly eventToLanes: ReadonlyMap<string, EventLaneSet>;
|
|
34
54
|
};
|
|
35
55
|
/**
|
|
36
56
|
* Walk the registry once to collect static reaction targets, the dynamic-
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-classify.d.ts","sourceRoot":"","sources":["../../../src/internal/build-classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,aAAa,EAAE,YAAY,EAAE,CAAC;IACvC,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"build-classify.d.ts","sourceRoot":"","sources":["../../../src/internal/build-classify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,KAAK,EACN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD;;;;;GAKG;AACH;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,EAAE,OAAO,MAAqC,CAAC;AAErE;;;;;;;;GA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