@rotorsoft/act 0.32.6 → 0.33.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.
Files changed (32) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/@types/act.d.ts +22 -66
  3. package/dist/@types/act.d.ts.map +1 -1
  4. package/dist/@types/internal/build-classify.d.ts +44 -0
  5. package/dist/@types/internal/build-classify.d.ts.map +1 -0
  6. package/dist/@types/internal/correlate-cycle.d.ts +73 -0
  7. package/dist/@types/internal/correlate-cycle.d.ts.map +1 -0
  8. package/dist/@types/internal/drain-cycle.d.ts +57 -5
  9. package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
  10. package/dist/@types/internal/drain.d.ts +2 -0
  11. package/dist/@types/internal/drain.d.ts.map +1 -1
  12. package/dist/@types/internal/event-sourcing.d.ts +5 -2
  13. package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
  14. package/dist/@types/internal/index.d.ts +10 -7
  15. package/dist/@types/internal/index.d.ts.map +1 -1
  16. package/dist/@types/internal/merge.d.ts.map +1 -1
  17. package/dist/@types/internal/reactions.d.ts +54 -0
  18. package/dist/@types/internal/reactions.d.ts.map +1 -0
  19. package/dist/@types/internal/settle.d.ts +60 -0
  20. package/dist/@types/internal/settle.d.ts.map +1 -0
  21. package/dist/@types/internal/tracing.d.ts +2 -0
  22. package/dist/@types/internal/tracing.d.ts.map +1 -1
  23. package/dist/@types/lru-map.d.ts.map +1 -0
  24. package/dist/@types/types/action.d.ts +27 -0
  25. package/dist/@types/types/action.d.ts.map +1 -1
  26. package/dist/index.cjs +497 -342
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.js +496 -342
  29. package/dist/index.js.map +1 -1
  30. package/package.json +2 -2
  31. package/dist/@types/internal/lru-map.d.ts.map +0 -1
  32. /package/dist/@types/{internal/lru-map.d.ts → lru-map.d.ts} +0 -0
@@ -31,6 +31,13 @@ import type { Actor, AsOf, BatchHandler, BlockedLease, CloseResult, CloseTarget,
31
31
  * {@link ActOptions.maxSubscribedStreams} based on expected concurrency.
32
32
  */
33
33
  export declare const DEFAULT_MAX_SUBSCRIBED_STREAMS = 1000;
34
+ /**
35
+ * Default debounce window (ms) for `settle()` when neither the per-call
36
+ * `SettleOptions.debounceMs` nor `ActOptions.settleDebounceMs` is set.
37
+ * Coalesces commits in the same tick and small bursts; sub-perceptible
38
+ * latency on the `"settled"` signal.
39
+ */
40
+ export declare const DEFAULT_SETTLE_DEBOUNCE_MS = 10;
34
41
  /**
35
42
  * Lifecycle events emitted by {@link Act}, mapped to their payload type.
36
43
  * Drives the typing of `emit` / `on` / `off` — the event-name argument
@@ -48,38 +55,27 @@ export type ActLifecycleEvents<TSchemaReg extends SchemaRegister<TActions>, TEve
48
55
  *
49
56
  * @property maxSubscribedStreams - Cap for the LRU set tracking already-
50
57
  * subscribed reaction streams. Default: {@link DEFAULT_MAX_SUBSCRIBED_STREAMS}.
58
+ * @property settleDebounceMs - Debounce window (ms) used by `settle()` when
59
+ * the caller doesn't pass `SettleOptions.debounceMs`. Tune this once per
60
+ * Act instance instead of threading the value through every call site.
61
+ * Default: {@link DEFAULT_SETTLE_DEBOUNCE_MS}.
51
62
  */
52
63
  export type ActOptions = {
53
64
  readonly maxSubscribedStreams?: number;
65
+ readonly settleDebounceMs?: number;
54
66
  };
55
67
  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> {
56
68
  readonly registry: Registry<TSchemaReg, TEvents, TActions>;
57
69
  private readonly _states;
58
70
  private _emitter;
59
- private _drain_locked;
60
- private _drain_lag2lead_ratio;
61
- private _correlation_timer;
62
- private _settle_timer;
63
- private _settling;
64
- private _correlation_checkpoint;
65
- /**
66
- * Streams already subscribed via store.subscribe() — both the static
67
- * targets registered at init and dynamic targets discovered by
68
- * correlate(). correlate() consults this set to avoid re-subscribing
69
- * known streams.
70
- *
71
- * Bounded LRU so apps that mint millions of dynamic targets (one per
72
- * aggregate) don't grow this unbounded. Eviction costs at most one
73
- * redundant store.subscribe() call per evicted-but-still-active stream
74
- * (subscribe is idempotent). Cap configurable via {@link ActOptions}.
75
- */
76
- private readonly _subscribed_streams;
77
- private _has_dynamic_resolvers;
78
- private _correlation_initialized;
79
71
  /** Event names with at least one registered reaction (computed at build time) */
80
72
  private readonly _reactive_events;
81
- /** Set in do() when a committed event has reactions — cleared by drain() */
82
- private _needs_drain;
73
+ /** Drain pipeline driver: armed flag, concurrency lock, adaptive ratio. */
74
+ private readonly _drain;
75
+ /** Correlation state machine: lazy init, dynamic-resolver scan, periodic worker. */
76
+ private readonly _correlate;
77
+ /** Debounced correlate→drain catch-up loop. */
78
+ private readonly _settle;
83
79
  /**
84
80
  * Emit a lifecycle event. The payload type is inferred from the event name
85
81
  * via {@link ActLifecycleEvents}.
@@ -100,8 +96,6 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
100
96
  * @param registry The registry of state, event, and action schemas
101
97
  * @param states Map of state names to their (potentially merged) state definitions
102
98
  */
103
- /** Static resolver targets collected at build time */
104
- private readonly _static_targets;
105
99
  /** Batch handlers for static-target projections (target → handler) */
106
100
  private readonly _batch_handlers;
107
101
  /** Event-sourcing handlers, optionally wrapped with trace decorators */
@@ -123,9 +117,9 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
123
117
  private readonly _bound_load;
124
118
  private readonly _bound_query;
125
119
  private readonly _bound_query_array;
126
- /** Pre-bound dispatchers handed to runDrainCycle each cycle. */
127
- private readonly _bound_handle;
128
- private readonly _bound_handle_batch;
120
+ /** Reaction dispatchers built once and handed to runDrainCycle each cycle. */
121
+ private readonly _handle;
122
+ private readonly _handle_batch;
129
123
  constructor(registry: Registry<TSchemaReg, TEvents, TActions>, _states?: Map<string, State<any, any, any>>, batchHandlers?: Map<string, BatchHandler<any>>, options?: ActOptions);
130
124
  /**
131
125
  * Executes an action on a state instance, committing resulting events.
@@ -335,36 +329,6 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
335
329
  * @see {@link query} for large result sets
336
330
  */
337
331
  query_array(query: Query): Promise<Committed<TEvents, keyof TEvents>[]>;
338
- /**
339
- * Shared finalization for the two reaction-runner shapes (per-event
340
- * `handle` and bulk `handleBatch`). Centralizes the error log, retry-vs-
341
- * block decision, and the "error reported only when nothing was handled"
342
- * rule that's true in both shapes (in batch mode, `handled` is always 0
343
- * on failure, so the rule degenerates to "always reported").
344
- */
345
- private _finalize;
346
- /**
347
- * Handles leased reactions one event at a time.
348
- *
349
- * Called by the main `drain` loop after fetching new events. Each handler
350
- * receives a scoped `IAct` proxy that auto-injects the triggering event
351
- * as `reactingTo` when `do()` is called without it, maintaining
352
- * correlation chains by default (#587). Handlers can still pass an
353
- * explicit `reactingTo` to override.
354
- *
355
- * @internal
356
- */
357
- private handle;
358
- /**
359
- * Handles a batch of events for a projection with a batch handler.
360
- *
361
- * Called by `drain()` when a leased stream is a static-target projection
362
- * with a registered batch handler. All events are passed to the handler
363
- * in a single call, enabling bulk DB operations.
364
- *
365
- * @internal
366
- */
367
- private handleBatch;
368
332
  /**
369
333
  * Processes pending reactions by draining uncommitted events from the event store.
370
334
  *
@@ -404,7 +368,7 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
404
368
  * @see {@link correlate} for dynamic stream discovery
405
369
  * @see {@link start_correlations} for automatic correlation
406
370
  */
407
- drain({ streamLimit, eventLimit, leaseMillis, }?: DrainOptions): Promise<Drain<TEvents>>;
371
+ drain(options?: DrainOptions): Promise<Drain<TEvents>>;
408
372
  /**
409
373
  * Discovers and registers new streams dynamically based on reaction resolvers.
410
374
  *
@@ -450,14 +414,6 @@ export declare class Act<TSchemaReg extends SchemaRegister<TActions>, TEvents ex
450
414
  * @see {@link start_correlations} for automatic periodic correlation
451
415
  * @see {@link stop_correlations} to stop automatic correlation
452
416
  */
453
- /**
454
- * Initialize correlation state on first call.
455
- * - Reads max(at) from store as cold-start checkpoint
456
- * - Subscribes static resolver targets (idempotent upsert)
457
- * - Populates the subscribed statics set
458
- * @internal
459
- */
460
- private _init_correlation;
461
417
  correlate(query?: Query): Promise<{
462
418
  subscribed: number;
463
419
  last_id: number;
@@ -1 +1 @@
1
- {"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/act.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,KAAK,EAEL,KAAK,EAGL,QAAQ,EACR,MAAM,EACN,cAAc,EACd,OAAO,EACP,aAAa,EACb,QAAQ,EACR,KAAK,EACL,MAAM,EACP,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,OAAO,CAAC;AAEnD;;;;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,EAAE,CAAC;IAC3C,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACxC,CAAC;AAEF,qBAAa,GAAG,CACd,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OA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,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAmBzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;CAG1C"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @module build-classify
3
+ * @category Internal
4
+ *
5
+ * Build-time classification of the registry + state map. The Act constructor
6
+ * needs four pre-computed inputs to wire its runtime subsystems:
7
+ *
8
+ * - `staticTargets` — known-up-front reaction targets (statics get
9
+ * subscribed once at init; dynamics scan per event)
10
+ * - `hasDynamicResolvers` — short-circuit flag for `correlate()`
11
+ * - `reactiveEvents` — event names with at least one reaction (drives
12
+ * the drain skip-flag in `do()` and `reset()`)
13
+ * - `eventToState` — event-name → owning state, for `close({restart})`
14
+ * seed loading in multi-state apps
15
+ *
16
+ * Pure function — single pass over events + states, fully testable without
17
+ * instantiating Act.
18
+ *
19
+ * @internal
20
+ */
21
+ import type { Registry, Schema, SchemaRegister, Schemas, State } from "../types/index.js";
22
+ import type { StaticTarget } from "./correlate-cycle.js";
23
+ /**
24
+ * Classification result. Returned by {@link classifyRegistry}; consumed
25
+ * piecewise by Act's constructor.
26
+ *
27
+ * @internal
28
+ */
29
+ export type Classification = {
30
+ readonly staticTargets: StaticTarget[];
31
+ readonly hasDynamicResolvers: boolean;
32
+ readonly reactiveEvents: ReadonlySet<string>;
33
+ readonly eventToState: ReadonlyMap<string, State<any, any, any>>;
34
+ };
35
+ /**
36
+ * Walk the registry once to collect static reaction targets, the dynamic-
37
+ * resolvers flag, the set of reactive event names, and the event-to-state
38
+ * map. Static targets are deduplicated by (target, source) — two reactions
39
+ * routing to the same projection produce one subscription.
40
+ *
41
+ * @internal
42
+ */
43
+ export declare function classifyRegistry<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas>(registry: Registry<TSchemaReg, TEvents, TActions>, states: ReadonlyMap<string, State<Schema, any, any>>): Classification;
44
+ //# sourceMappingURL=build-classify.d.ts.map
@@ -0,0 +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;CAClE,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,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,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,GACnD,cAAc,CAiChB"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @module correlate-cycle
3
+ * @category Internal
4
+ *
5
+ * Correlation — the discovery half of the correlate→drain pair. Owns the
6
+ * lazy init (subscribe static targets, read cold-start watermark), the
7
+ * dynamic-resolver scan that registers new streams as events arrive, and
8
+ * the periodic timer that drives background discovery.
9
+ *
10
+ * The Act orchestrator passes registry + classification (which static
11
+ * targets to subscribe, whether any dynamic resolvers exist) at build
12
+ * time; everything past that lives here.
13
+ *
14
+ * @internal
15
+ */
16
+ import type { Query, Registry, SchemaRegister, Schemas } from "../types/index.js";
17
+ import type { DrainOps } from "./drain.js";
18
+ /**
19
+ * Static resolver target collected at build time. Subscribed once during
20
+ * init; never re-evaluated.
21
+ *
22
+ * @internal
23
+ */
24
+ export type StaticTarget = {
25
+ readonly stream: string;
26
+ readonly source?: string;
27
+ };
28
+ /**
29
+ * Drives correlation for one Act instance. Owns the checkpoint, the
30
+ * subscribed-streams LRU, and the periodic timer.
31
+ *
32
+ * @internal
33
+ */
34
+ export declare class CorrelateCycle<TSchemaReg extends SchemaRegister<TActions>, TEvents extends Schemas, TActions extends Schemas> {
35
+ private readonly registry;
36
+ private readonly staticTargets;
37
+ private readonly hasDynamicResolvers;
38
+ private readonly cd;
39
+ private readonly onInit?;
40
+ private _checkpoint;
41
+ private _initialized;
42
+ private _timer;
43
+ private readonly _subscribed;
44
+ constructor(registry: Registry<TSchemaReg, TEvents, TActions>, staticTargets: ReadonlyArray<StaticTarget>, hasDynamicResolvers: boolean, cd: DrainOps<TEvents>, maxSubscribedStreams: number, onInit?: (() => void) | undefined);
45
+ /** Last correlated event id. */
46
+ get checkpoint(): number;
47
+ /**
48
+ * Initialize correlation state on first call.
49
+ * - Reads max(at) from store as cold-start checkpoint
50
+ * - Subscribes static resolver targets (idempotent upsert)
51
+ * - Populates the subscribed-streams LRU
52
+ * - Fires `onInit` once (Act uses this to flag a cold-start drain)
53
+ */
54
+ init(): Promise<void>;
55
+ /**
56
+ * Discover dynamic-resolver targets in the events past the checkpoint
57
+ * and register any new streams via `cd.subscribe`. Static targets are
58
+ * subscribed at init time, so this only walks dynamic resolvers.
59
+ */
60
+ correlate(query?: Query): Promise<{
61
+ subscribed: number;
62
+ last_id: number;
63
+ }>;
64
+ /**
65
+ * Start a periodic correlation worker. Returns false if one is already
66
+ * running. Errors from `correlate()` are sent to `console.error` (matches
67
+ * pre-extraction behavior; the timer keeps running on failure).
68
+ */
69
+ startPolling(query?: Query, frequency?: number, callback?: (subscribed: number) => void): boolean;
70
+ /** Stop the periodic correlation worker. Idempotent. */
71
+ stopPolling(): void;
72
+ }
73
+ //# sourceMappingURL=correlate-cycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correlate-cycle.d.ts","sourceRoot":"","sources":["../../../src/internal/correlate-cycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EACV,KAAK,EAEL,QAAQ,EACR,cAAc,EACd,OAAO,EACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,cAAc,CACzB,UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC,EAC3C,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO;IAQtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,EAAE;IAEnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IAX1B,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAyD;IACvE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAiB;gBAG1B,QAAQ,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,CAAC,EACjD,aAAa,EAAE,aAAa,CAAC,YAAY,CAAC,EAC1C,mBAAmB,EAAE,OAAO,EAC5B,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,EACtC,oBAAoB,EAAE,MAAM,EACX,MAAM,CAAC,GAAE,MAAM,IAAI,aAAA;IAKtC,gCAAgC;IAChC,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B;;;;OAIG;IACG,SAAS,CACb,KAAK,GAAE,KAAgC,GACtC,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IA+DnD;;;;OAIG;IACH,YAAY,CACV,KAAK,GAAE,KAAU,EACjB,SAAS,SAAS,EAClB,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,GACtC,OAAO;IAgBV,wDAAwD;IACxD,WAAW,IAAI,IAAI;CAMpB"}
@@ -2,14 +2,19 @@
2
2
  * @module drain-cycle
3
3
  * @category Internal
4
4
  *
5
- * Pure drain-pipeline orchestration: one round-trip of claim fetch →
6
- * group → dispatch → ack/block. The Act orchestrator owns the `_needs_drain`
7
- * / `_drain_locked` flags and the adaptive lag-to-lead ratio; everything
8
- * sequential between those state updates lives here.
5
+ * Two layers of the drain pipeline:
6
+ *
7
+ * - {@link runDrainCycle} pure function for one round-trip of
8
+ * claim fetch group dispatch → ack/block. No orchestrator state.
9
+ * Reusable for property tests and standalone benchmarks.
10
+ *
11
+ * - {@link DrainController} — stateful driver that owns the armed flag,
12
+ * the concurrency lock, and the adaptive lag/lead ratio. Wraps
13
+ * `runDrainCycle` with the lifecycle decisions Act used to make inline.
9
14
  *
10
15
  * @internal
11
16
  */
12
- import type { BatchHandler, BlockedLease, Fetch, Lease, ReactionPayload, Registry, SchemaRegister, Schemas } from "../types/index.js";
17
+ import type { BatchHandler, BlockedLease, Drain, DrainOptions, Fetch, Lease, Logger, ReactionPayload, Registry, SchemaRegister, Schemas } from "../types/index.js";
13
18
  import type { DrainOps } from "./drain.js";
14
19
  /**
15
20
  * Outcome of processing a single leased stream — produced by Act's `handle`
@@ -58,4 +63,51 @@ export type DrainCycle<TEvents extends Schemas> = {
58
63
  * @internal
59
64
  */
60
65
  export declare function runDrainCycle<TEvents extends Schemas, TActions extends Schemas, TSchemaReg extends SchemaRegister<TActions>>(ops: DrainOps<TEvents>, registry: Registry<TSchemaReg, TEvents, TActions>, batchHandlers: Map<string, BatchHandler<TEvents>>, handle: Handle<TEvents>, handleBatch: HandleBatch<TEvents>, lagging: number, leading: number, eventLimit: number, leaseMillis: number): Promise<DrainCycle<TEvents> | undefined>;
66
+ /**
67
+ * Dependencies the {@link DrainController} needs from the orchestrator.
68
+ * The lifecycle event sinks (`onAcked` / `onBlocked`) are callbacks so
69
+ * this module doesn't reach back into Act's emitter.
70
+ *
71
+ * @internal
72
+ */
73
+ export type DrainControllerDeps<TEvents extends Schemas, TActions extends Schemas, TSchemaReg extends SchemaRegister<TActions>> = {
74
+ readonly logger: Logger;
75
+ readonly ops: DrainOps<TEvents>;
76
+ readonly registry: Registry<TSchemaReg, TEvents, TActions>;
77
+ readonly batchHandlers: Map<string, BatchHandler<TEvents>>;
78
+ readonly handle: Handle<TEvents>;
79
+ readonly handleBatch: HandleBatch<TEvents>;
80
+ readonly onAcked: (acked: Lease[]) => void;
81
+ readonly onBlocked: (blocked: BlockedLease[]) => void;
82
+ };
83
+ /**
84
+ * Stateful driver around {@link runDrainCycle}. Owns:
85
+ *
86
+ * - `_armed` — has any commit / reset / cold-start signaled work to do?
87
+ * - `_locked` — concurrent-call guard (overlapping `drain()` calls return
88
+ * an empty result instead of running twice)
89
+ * - `_ratio` — adaptive lag-to-lead frontier split, updated per cycle
90
+ *
91
+ * The orchestrator owns commits, lifecycle emission, and `arm()` triggers
92
+ * — the controller owns everything between those edges.
93
+ *
94
+ * @internal
95
+ */
96
+ export declare class DrainController<TEvents extends Schemas, TActions extends Schemas, TSchemaReg extends SchemaRegister<TActions>> {
97
+ private readonly deps;
98
+ private _armed;
99
+ private _locked;
100
+ private _ratio;
101
+ constructor(deps: DrainControllerDeps<TEvents, TActions, TSchemaReg>);
102
+ /**
103
+ * Signal that a commit (or reset / cold-start) may have produced work.
104
+ * Subsequent `drain()` calls will run the pipeline; once the pipeline
105
+ * settles to no-progress, the controller disarms itself.
106
+ */
107
+ arm(): void;
108
+ /** Read-only flag — true while a commit / reset is unprocessed. */
109
+ get armed(): boolean;
110
+ /** Run one drain pass. Short-circuits when not armed or already running. */
111
+ drain({ streamLimit, eventLimit, leaseMillis, }?: DrainOptions): Promise<Drain<TEvents>>;
112
+ }
61
113
  //# sourceMappingURL=drain-cycle.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"drain-cycle.d.ts","sourceRoot":"","sources":["../../../src/internal/drain-cycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,KAAK,EACL,eAAe,EACf,QAAQ,EACR,cAAc,EACd,OAAO,EACR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC;IAClC,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,MAAM,CAAC,OAAO,SAAS,OAAO,IAAI,CAC5C,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,KACjC,OAAO,CAAC,YAAY,CAAC,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,OAAO,SAAS,OAAO,IAAI,CACjD,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,EAAE,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UAAU,SAAS,cAAc,CAAC,QAAQ,CAAC;IAOzC,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAO;gBAGF,IAAI,EAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC;IAG3E;;;;OAIG;IACH,GAAG,IAAI,IAAI;IAIX,mEAAmE;IACnE,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,4EAA4E;IACtE,KAAK,CAAC,EACV,WAAgB,EAChB,UAAe,EACf,WAAoB,GACrB,GAAE,YAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;CAgD/C"}
@@ -15,6 +15,8 @@
15
15
  * mirroring the shape of {@link "event-sourcing"}. Trace decoration is
16
16
  * layered on top in {@link "tracing"} and selected by the orchestrator at
17
17
  * construction time. No tracing imports here.
18
+ *
19
+ * @internal
18
20
  */
19
21
  import type { BlockedLease, Fetch, Lease, Schemas } from "../types/index.js";
20
22
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"drain.d.ts","sourceRoot":"","sources":["../../../src/internal/drain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EACV,YAAY,EAEZ,KAAK,EACL,KAAK,EACL,OAAO,EACR,MAAM,mBAAmB,CAAC;AAE3B,gBAAgB;AAChB,MAAM,WAAW,QAAQ,CAAC,OAAO,SAAS,OAAO;IAC/C,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,KAAK,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7B,GAAG,EAAE,OAAO,GAAG,CAAC;IAChB,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,SAAS,EAAE,OAAO,SAAS,CAAC;CAC7B;AAED,eAAO,MAAM,KAAK,GAChB,SAAS,MAAM,EACf,SAAS,MAAM,EACf,IAA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CAAC;AAEnE,wBAAsB,KAAK,CAAC,OAAO,SAAS,OAAO,EACjD,MAAM,EAAE,KAAK,EAAE,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAYzB;AAED,eAAO,MAAM,GAAG,GAAI,QAAQ,KAAK,EAAE,KAAG,OAAO,CAAC,KAAK,EAAE,CAAwB,CAAC;AAE9E,eAAO,MAAM,KAAK,GAAI,QAAQ,YAAY,EAAE,KAAG,OAAO,CAAC,YAAY,EAAE,CAC9C,CAAC;AAExB,eAAO,MAAM,SAAS,GACpB,SAAS,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,KAClD,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CACxB,CAAC"}
@@ -1,15 +1,18 @@
1
1
  /**
2
2
  * @module event-sourcing
3
- * @category Event Sourcing
3
+ * @category Internal
4
4
  *
5
5
  * Pure event-sourcing primitives: `snap` persists state checkpoints, `load`
6
6
  * reconstructs state by replaying events through reducers, and `action`
7
7
  * validates an action, runs invariants, emits events, and commits them
8
- * atomically.
8
+ * atomically. `tombstone` commits the close-the-books guard with optimistic
9
+ * concurrency.
9
10
  *
10
11
  * These are the bare implementations — observability is layered on top in
11
12
  * {@link "tracing"} and wired by the orchestrator at construction time.
12
13
  * No tracing imports here, no module-level mutable state.
14
+ *
15
+ * @internal
13
16
  */
14
17
  import type { AsOf, Committed, Schema, Schemas, Snapshot, State, Target } from "../types/index.js";
15
18
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"event-sourcing.d.ts","sourceRoot":"","sources":["../../../src/internal/event-sourcing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EAGT,MAAM,EACN,OAAO,EACP,QAAQ,EACR,KAAK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AQ,SAAS,OAAO,EAExB,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EACpC,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,EACxD,IAAI,CAAC,EAAE,IAAI,GACV,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAyDpC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,MAAM,CAC1B,MAAM,SAAS,MAAM,EACrB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EACxB,IAAI,SAAS,MAAM,QAAQ,EAE3B,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,EACpC,MAAM,EAAE,IAAI,EACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EACjC,UAAU,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,EAC9C,cAAc,UAAQ,GACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAiItC"}
@@ -8,19 +8,22 @@
8
8
  * what lives here is implementation detail used by `Act`, the builders, and
9
9
  * the orchestrator's pipelines.
10
10
  *
11
- * Only symbols actually consumed *outside* `internal/` are re-exported here.
12
- * Modules within `internal/` import each other directly by file path, and
13
- * tests that need bare ops (e.g., `action`, `load`) likewise import from
11
+ * Only symbols actually consumed *via this barrel* from outside `internal/`
12
+ * are re-exported here. Modules within `internal/` import each other
13
+ * directly by file path; production code in `adapters/` and tests that
14
+ * need bare ops (e.g., `action`, `load`, `LruMap`) likewise import from
14
15
  * the specific source file.
15
16
  *
16
17
  * @internal
17
18
  */
18
- export { runCloseCycle, type CloseCycleDeps } from "./close-cycle.js";
19
- export { runDrainCycle, type DrainCycle, type HandleResult, } from "./drain-cycle.js";
20
- export { computeLagLeadRatio } from "./drain-ratio.js";
19
+ export { classifyRegistry } from "./build-classify.js";
20
+ export { runCloseCycle } from "./close-cycle.js";
21
+ export { CorrelateCycle } from "./correlate-cycle.js";
22
+ export { DrainController, type Handle, type HandleBatch, } from "./drain-cycle.js";
21
23
  export { type DrainOps } from "./drain.js";
22
24
  export { type EsOps } from "./event-sourcing.js";
23
- export { LruMap, LruSet } from "./lru-map.js";
24
25
  export { _this_, mergeEventRegister, mergeProjection, registerState, } from "./merge.js";
26
+ export { buildHandle, buildHandleBatch } from "./reactions.js";
27
+ export { SettleLoop } from "./settle.js";
25
28
  export { buildDrain, buildEs } from "./tracing.js";
26
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EACL,aAAa,EACb,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO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AED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC1B,IAAI,CAiBN;AAGD,eAAO,MAAM,MAAM,GAAI,YAAY;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;;;CAGnD,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @module reactions
3
+ * @category Internal
4
+ *
5
+ * Reaction dispatch — what runs inside the drain pipeline once `runDrainCycle`
6
+ * has fetched events for a leased stream. Two shapes:
7
+ *
8
+ * - per-event `handle`: walks payloads sequentially, builds a scoped `IAct`
9
+ * that auto-injects `reactingTo` so handlers don't have to thread it
10
+ * through manually
11
+ * - bulk `handleBatch`: hands every event for a static-target projection to
12
+ * a single batch callback, enabling one-transaction replays
13
+ *
14
+ * Both share `_finalize`, which collapses the retry-vs-block decision and
15
+ * the "report error only when nothing was handled" rule.
16
+ *
17
+ * @internal
18
+ */
19
+ import type { Actor, IAct, Logger, Schemas } from "../types/index.js";
20
+ import type { Handle, HandleBatch } from "./drain-cycle.js";
21
+ /**
22
+ * Dependencies a reaction handler needs from the orchestrator: the logger
23
+ * for retry/error breadcrumbs, plus the bound `IAct` methods that the scoped
24
+ * proxy hands to user reaction code.
25
+ *
26
+ * @internal
27
+ */
28
+ export type ReactionDeps<TEvents extends Schemas, TActions extends Schemas, TActor extends Actor = Actor> = {
29
+ readonly logger: Logger;
30
+ readonly boundDo: IAct<TEvents, TActions, TActor>["do"];
31
+ readonly boundLoad: IAct<TEvents, TActions, TActor>["load"];
32
+ readonly boundQuery: IAct<TEvents, TActions, TActor>["query"];
33
+ readonly boundQueryArray: IAct<TEvents, TActions, TActor>["query_array"];
34
+ };
35
+ /**
36
+ * Builds the per-event reaction dispatcher passed to `runDrainCycle`.
37
+ *
38
+ * The scoped `IAct` proxy auto-injects the triggering event as `reactingTo`
39
+ * when handlers call `do()` without it (#587), keeping the correlation
40
+ * chain by default. The non-do methods are reused across all dispatches —
41
+ * only `do` rebinds per payload because it captures the triggering event.
42
+ *
43
+ * @internal
44
+ */
45
+ export declare function buildHandle<TEvents extends Schemas, TActions extends Schemas, TActor extends Actor = Actor>(deps: ReactionDeps<TEvents, TActions, TActor>): Handle<TEvents>;
46
+ /**
47
+ * Builds the bulk reaction dispatcher passed to `runDrainCycle`. All events
48
+ * for a static-target projection are handed to a single callback so the
49
+ * projection can do one transaction per drain (catch-up replays especially).
50
+ *
51
+ * @internal
52
+ */
53
+ export declare function buildHandleBatch<TEvents extends Schemas>(logger: Logger): HandleBatch<TEvents>;
54
+ //# sourceMappingURL=reactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactions.d.ts","sourceRoot":"","sources":["../../../src/internal/reactions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EACV,KAAK,EAGL,IAAI,EAEJ,MAAM,EAGN,OAAO,EAER,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAgB,MAAM,kBAAkB,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,CACtB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EACxB,MAAM,SAAS,KAAK,GAAG,KAAK,IAC1B;IACF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC;IACxD,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5D,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;IAC9D,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC;CAC1E,CAAC;AA6BF;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,OAAO,SAAS,OAAO,EACvB,QAAQ,SAAS,OAAO,EACxB,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,IAAI,EAAE,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,CAoDhE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,OAAO,EACtD,MAAM,EAAE,MAAM,GACb,WAAW,CAAC,OAAO,CAAC,CA2BtB"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @module settle
3
+ * @category Internal
4
+ *
5
+ * Debounced correlate→drain loop. Sits one level above both correlation
6
+ * and drain: schedule() coalesces rapid callers into a single cycle, then
7
+ * runs correlate+drain in a loop until a pass produces no progress.
8
+ *
9
+ * Owns the debounce timer and the reentrancy flag. Everything else is
10
+ * supplied via the `SettleDeps` callbacks so this module stays free of
11
+ * orchestrator state.
12
+ *
13
+ * @internal
14
+ */
15
+ import type { Drain, DrainOptions, Logger, Query, Schemas, SettleOptions } from "../types/index.js";
16
+ /**
17
+ * Callbacks the settle loop needs from the orchestrator. Modeled as an
18
+ * input bag so this file doesn't import `Act` (avoids a cycle) and stays
19
+ * independently testable.
20
+ *
21
+ * @internal
22
+ */
23
+ export type SettleDeps<TEvents extends Schemas> = {
24
+ readonly logger: Logger;
25
+ readonly init: () => Promise<void>;
26
+ readonly checkpoint: () => number;
27
+ readonly correlate: (query: Query) => Promise<{
28
+ subscribed: number;
29
+ last_id: number;
30
+ }>;
31
+ readonly drain: (options: DrainOptions) => Promise<Drain<TEvents>>;
32
+ readonly onSettled: (drain: Drain<TEvents>) => void;
33
+ };
34
+ /**
35
+ * Drives the debounced correlate→drain catch-up cycle. One instance per
36
+ * Act orchestrator.
37
+ *
38
+ * @internal
39
+ */
40
+ export declare class SettleLoop<TEvents extends Schemas> {
41
+ private readonly deps;
42
+ /** Debounce window applied when the caller doesn't override via `SettleOptions.debounceMs`. */
43
+ private readonly defaultDebounceMs;
44
+ private _timer;
45
+ private _running;
46
+ constructor(deps: SettleDeps<TEvents>,
47
+ /** Debounce window applied when the caller doesn't override via `SettleOptions.debounceMs`. */
48
+ defaultDebounceMs: number);
49
+ /**
50
+ * Schedule a settle pass. Multiple calls inside the debounce window
51
+ * coalesce into one cycle. The cycle runs correlate→drain in a loop
52
+ * until no progress is made (no new subscriptions, no acks, no blocks)
53
+ * or `maxPasses` is reached, then emits the `"settled"` lifecycle event
54
+ * via {@link SettleDeps.onSettled}.
55
+ */
56
+ schedule(options?: SettleOptions): void;
57
+ /** Cancel any pending or active settle cycle. Idempotent. */
58
+ stop(): void;
59
+ }
60
+ //# sourceMappingURL=settle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settle.d.ts","sourceRoot":"","sources":["../../../src/internal/settle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,YAAY,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,OAAO,SAAS,OAAO,IAAI;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,MAAM,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,CAClB,KAAK,EAAE,KAAK,KACT,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACnE,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CACrD,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,UAAU,CAAC,OAAO,SAAS,OAAO;IAK3C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,+FAA+F;IAC/F,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IANpC,OAAO,CAAC,MAAM,CAAwD;IACtE,OAAO,CAAC,QAAQ,CAAS;gBAGN,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC;IAC1C,+FAA+F;IAC9E,iBAAiB,EAAE,MAAM;IAG5C;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;IA0C3C,6DAA6D;IAC7D,IAAI,IAAI,IAAI;CAMb"}
@@ -22,6 +22,8 @@
22
22
  * orchestrator choose bare or traced variants once at `.build()` time based
23
23
  * on the configured log level. Outside this module, no other source file
24
24
  * imports tracing primitives.
25
+ *
26
+ * @internal
25
27
  */
26
28
  import type { Logger, Schemas } from "../types/index.js";
27
29
  import { type DrainOps } from "./drain.js";
@@ -1 +1 @@
1
- {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../../src/internal/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAqDjD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAqD7C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,OAAO,EAChD,MAAM,EAAE,MAAM,GACb,QAAQ,CAAC,OAAO,CAAC,CAyDnB"}
1
+ {"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../../src/internal/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAQ,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AA2GjD;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CA+D7C;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,OAAO,EAChD,MAAM,EAAE,MAAM,GACb,QAAQ,CAAC,OAAO,CAAC,CAyDnB"}