@rotorsoft/act 0.35.1 → 0.36.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 +2 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/@types/act.d.ts +672 -0
- package/dist/@types/act.d.ts.map +1 -0
- package/dist/@types/adapters/console-logger.d.ts +41 -0
- package/dist/@types/adapters/console-logger.d.ts.map +1 -0
- package/dist/@types/adapters/in-memory-cache.d.ts +34 -0
- package/dist/@types/adapters/in-memory-cache.d.ts.map +1 -0
- package/dist/@types/adapters/in-memory-store.d.ts +202 -0
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -0
- package/dist/@types/adapters/index.d.ts +4 -0
- package/dist/@types/adapters/index.d.ts.map +1 -0
- package/dist/@types/builders/act-builder.d.ts +160 -0
- package/dist/@types/builders/act-builder.d.ts.map +1 -0
- package/dist/@types/builders/index.d.ts +13 -0
- package/dist/@types/builders/index.d.ts.map +1 -0
- package/dist/@types/builders/projection-builder.d.ts +101 -0
- package/dist/@types/builders/projection-builder.d.ts.map +1 -0
- package/dist/@types/builders/slice-builder.d.ts +109 -0
- package/dist/@types/builders/slice-builder.d.ts.map +1 -0
- package/dist/@types/builders/state-builder.d.ts +424 -0
- package/dist/@types/builders/state-builder.d.ts.map +1 -0
- package/dist/@types/config.d.ts +119 -0
- package/dist/@types/config.d.ts.map +1 -0
- package/dist/@types/index.d.ts +14 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/@types/internal/build-classify.d.ts +44 -0
- package/dist/@types/internal/build-classify.d.ts.map +1 -0
- package/dist/@types/internal/close-cycle.d.ts +38 -0
- package/dist/@types/internal/close-cycle.d.ts.map +1 -0
- package/dist/@types/internal/correlate-cycle.d.ts +78 -0
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -0
- package/dist/@types/internal/drain-cycle.d.ts +113 -0
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -0
- package/dist/@types/internal/drain-ratio.d.ts +26 -0
- package/dist/@types/internal/drain-ratio.d.ts.map +1 -0
- package/dist/@types/internal/drain.d.ts +41 -0
- package/dist/@types/internal/drain.d.ts.map +1 -0
- package/dist/@types/internal/event-sourcing.d.ts +96 -0
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -0
- package/dist/@types/internal/index.d.ts +29 -0
- package/dist/@types/internal/index.d.ts.map +1 -0
- package/dist/@types/internal/merge.d.ts +31 -0
- package/dist/@types/internal/merge.d.ts.map +1 -0
- package/dist/@types/internal/reactions.d.ts +54 -0
- package/dist/@types/internal/reactions.d.ts.map +1 -0
- package/dist/@types/internal/settle.d.ts +60 -0
- package/dist/@types/internal/settle.d.ts.map +1 -0
- package/dist/@types/internal/tracing.d.ts +45 -0
- package/dist/@types/internal/tracing.d.ts.map +1 -0
- package/dist/@types/lru-map.d.ts +50 -0
- package/dist/@types/lru-map.d.ts.map +1 -0
- package/dist/@types/ports.d.ts +196 -0
- package/dist/@types/ports.d.ts.map +1 -0
- package/dist/@types/signals.d.ts +2 -0
- package/dist/@types/signals.d.ts.map +1 -0
- package/dist/@types/types/action.d.ts +444 -0
- package/dist/@types/types/action.d.ts.map +1 -0
- package/dist/@types/types/errors.d.ts +284 -0
- package/dist/@types/types/errors.d.ts.map +1 -0
- package/dist/@types/types/index.d.ts +39 -0
- package/dist/@types/types/index.d.ts.map +1 -0
- package/dist/@types/types/ports.d.ts +617 -0
- package/dist/@types/types/ports.d.ts.map +1 -0
- package/dist/@types/types/reaction.d.ts +314 -0
- package/dist/@types/types/reaction.d.ts.map +1 -0
- package/dist/@types/types/registry.d.ts +74 -0
- package/dist/@types/types/registry.d.ts.map +1 -0
- package/dist/@types/types/schemas.d.ts +117 -0
- package/dist/@types/types/schemas.d.ts.map +1 -0
- package/dist/@types/utils.d.ts +54 -0
- package/dist/@types/utils.d.ts.map +1 -0
- package/dist/chunk-AGWZY6YT.js +127 -0
- package/dist/chunk-AGWZY6YT.js.map +1 -0
- package/dist/index.cjs +3148 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2979 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +166 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +6 -2
|
@@ -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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module tracing
|
|
3
|
+
* @category Internal
|
|
4
|
+
*
|
|
5
|
+
* Centralized observability for the framework's internal pipelines.
|
|
6
|
+
*
|
|
7
|
+
* Trace decorators wrap a bare implementation with `logger.trace(...)` calls
|
|
8
|
+
* at well-defined moments — entry points for {@link "event-sourcing"} (`load`,
|
|
9
|
+
* `snap`, `action`) and exit points for the {@link "drain"} pipeline (`claim`,
|
|
10
|
+
* `fetch`, `ack`, `block`, `subscribe`). `action` carries both an entry log
|
|
11
|
+
* and a post-commit log to preserve the diagnostic value of the historical
|
|
12
|
+
* mid-function trace points.
|
|
13
|
+
*
|
|
14
|
+
* Output styles:
|
|
15
|
+
* - **Pretty mode** (`config().env !== "production"`) — event-sourcing logs
|
|
16
|
+
* show only the colored target body (color carries the operation/phase),
|
|
17
|
+
* drain logs keep a colored caption.
|
|
18
|
+
* - **Plain mode** (production / log aggregators) — every log gets a textual
|
|
19
|
+
* prefix; event-sourcing uses `caption: body`, drain uses `caption body`.
|
|
20
|
+
*
|
|
21
|
+
* The two factories — {@link buildEs} and {@link buildDrain} — let the
|
|
22
|
+
* orchestrator choose bare or traced variants once at `.build()` time based
|
|
23
|
+
* on the configured log level. Outside this module, no other source file
|
|
24
|
+
* imports tracing primitives.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
import type { Logger, Schemas } from "../types/index.js";
|
|
29
|
+
import type { DrainOps } from "./drain.js";
|
|
30
|
+
import type { EsOps } from "./event-sourcing.js";
|
|
31
|
+
/**
|
|
32
|
+
* Selects bare or traced event-sourcing handlers. Called once by the
|
|
33
|
+
* orchestrator constructor.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildEs(logger: Logger): EsOps;
|
|
38
|
+
/**
|
|
39
|
+
* Selects bare or traced drain-pipeline ops. Called once by the orchestrator
|
|
40
|
+
* constructor.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildDrain<TEvents extends Schemas>(logger: Logger): DrainOps<TEvents>;
|
|
45
|
+
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AA4GjD;;;;;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"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module lru-map
|
|
3
|
+
* @category Internal
|
|
4
|
+
*
|
|
5
|
+
* Tiny bounded LRU map / set built on insertion-ordered `Map`. Used to cap
|
|
6
|
+
* memory in long-running orchestrators that mint large numbers of keys —
|
|
7
|
+
* notably:
|
|
8
|
+
*
|
|
9
|
+
* - {@link InMemoryCache}: stream → state checkpoint
|
|
10
|
+
* - `Act._subscribed_streams`: stream → presence (LruSet)
|
|
11
|
+
*
|
|
12
|
+
* Apps with millions of dynamic streams (one target per aggregate) can't
|
|
13
|
+
* afford an unbounded `Set<string>` — eviction is required.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Bounded LRU map. `get()` promotes; `has()` does not. `set()` always
|
|
19
|
+
* promotes and evicts the oldest entry when at capacity.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare class LruMap<K, V> {
|
|
24
|
+
private readonly _maxSize;
|
|
25
|
+
private readonly _entries;
|
|
26
|
+
constructor(_maxSize: number);
|
|
27
|
+
get(key: K): V | undefined;
|
|
28
|
+
has(key: K): boolean;
|
|
29
|
+
set(key: K, value: V): void;
|
|
30
|
+
delete(key: K): boolean;
|
|
31
|
+
clear(): void;
|
|
32
|
+
get size(): number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Bounded LRU set built on top of {@link LruMap}. `has()` does not promote;
|
|
36
|
+
* `add()` does (re-inserting if already present, evicting the oldest at
|
|
37
|
+
* capacity).
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare class LruSet<T> {
|
|
42
|
+
private readonly _map;
|
|
43
|
+
constructor(maxSize: number);
|
|
44
|
+
has(value: T): boolean;
|
|
45
|
+
add(value: T): void;
|
|
46
|
+
delete(value: T): boolean;
|
|
47
|
+
clear(): void;
|
|
48
|
+
get size(): number;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=lru-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lru-map.d.ts","sourceRoot":"","sources":["../../src/lru-map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;;;GAKG;AACH,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC;IAGV,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;gBAEf,QAAQ,EAAE,MAAM;IAE7C,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAS1B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIpB,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAW3B,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIvB,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAED;;;;;;GAMG;AACH,qBAAa,MAAM,CAAC,CAAC;IACnB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkB;gBAE3B,OAAO,EAAE,MAAM;IAI3B,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;IAItB,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAInB,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO;IAIzB,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { ConsoleLogger } from "./adapters/console-logger.js";
|
|
2
|
+
import type { Cache, Disposable, Disposer, Logger, Store } from "./types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Port/adapter infrastructure for the Act framework.
|
|
5
|
+
*
|
|
6
|
+
* All infrastructure concerns (logging, storage, caching) are managed as
|
|
7
|
+
* singleton adapters injected via port functions. Each port follows the same
|
|
8
|
+
* pattern: first call wins with a sensible default, optional adapter injection.
|
|
9
|
+
*
|
|
10
|
+
* - `log()` — structured logging (default: ConsoleLogger)
|
|
11
|
+
* - `store()` — event persistence (default: InMemoryStore)
|
|
12
|
+
* - `cache()` — state checkpoints (default: InMemoryCache)
|
|
13
|
+
* - `dispose()` — register cleanup functions for graceful shutdown
|
|
14
|
+
*
|
|
15
|
+
* @module ports
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* List of exit codes for process termination. Consumed by signal handlers
|
|
19
|
+
* and {@link disposeAndExit}; not part of the user-facing surface.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare const ExitCodes: readonly ["ERROR", "EXIT"];
|
|
24
|
+
/**
|
|
25
|
+
* Type for allowed exit codes.
|
|
26
|
+
*
|
|
27
|
+
* - `"ERROR"` — abnormal termination (uncaught exception, unhandled rejection)
|
|
28
|
+
* - `"EXIT"` — clean shutdown (SIGINT, SIGTERM, or manual trigger)
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export type ExitCode = (typeof ExitCodes)[number];
|
|
33
|
+
/**
|
|
34
|
+
* Factory function that creates or returns the injected adapter.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
type Injector<Port extends Disposable> = (adapter?: Port) => Port;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a singleton port with optional adapter injection.
|
|
40
|
+
*
|
|
41
|
+
* The first call initializes the adapter (using the provided adapter or the
|
|
42
|
+
* injector's default). Subsequent calls return the cached singleton. Adapters
|
|
43
|
+
* are disposed in reverse registration order during {@link disposeAndExit}.
|
|
44
|
+
*
|
|
45
|
+
* @param injector - Named function that creates the default adapter
|
|
46
|
+
* @returns Port function: call with no args to get the singleton, or pass an
|
|
47
|
+
* adapter on the first call to override the default
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const store = port(function store(adapter?: Store) {
|
|
52
|
+
* return adapter || new InMemoryStore();
|
|
53
|
+
* });
|
|
54
|
+
* const s = store(); // InMemoryStore
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function port<Port extends Disposable>(injector: Injector<Port>): (adapter?: Port) => Port;
|
|
58
|
+
/**
|
|
59
|
+
* Gets or injects the singleton logger.
|
|
60
|
+
*
|
|
61
|
+
* By default, Act uses a built-in {@link ConsoleLogger} that emits JSON lines
|
|
62
|
+
* in production (compatible with GCP, AWS CloudWatch, Datadog) and colorized
|
|
63
|
+
* output in development — zero external dependencies.
|
|
64
|
+
*
|
|
65
|
+
* For pino, inject a `PinoLogger` from `@rotorsoft/act-pino` before building
|
|
66
|
+
* your application.
|
|
67
|
+
*
|
|
68
|
+
* @param adapter - Optional logger implementation to inject
|
|
69
|
+
* @returns The singleton logger instance
|
|
70
|
+
*
|
|
71
|
+
* @example Default console logger
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { log } from "@rotorsoft/act";
|
|
74
|
+
* const logger = log();
|
|
75
|
+
* logger.info("Application started");
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example Injecting pino
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { log } from "@rotorsoft/act";
|
|
81
|
+
* import { PinoLogger } from "@rotorsoft/act-pino";
|
|
82
|
+
* log(new PinoLogger({ level: "debug", pretty: true }));
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @see {@link Logger} for the interface contract
|
|
86
|
+
* @see {@link ConsoleLogger} for the default implementation
|
|
87
|
+
*/
|
|
88
|
+
export declare const log: (adapter?: Logger | ConsoleLogger | undefined) => Logger | ConsoleLogger;
|
|
89
|
+
/**
|
|
90
|
+
* Gets or injects the singleton event store.
|
|
91
|
+
*
|
|
92
|
+
* By default, Act uses an {@link InMemoryStore} suitable for development and
|
|
93
|
+
* testing. For production, inject a persistent store like `PostgresStore` from
|
|
94
|
+
* `@rotorsoft/act-pg` before building your application.
|
|
95
|
+
*
|
|
96
|
+
* **Important:** Store injection must happen before creating any Act instances.
|
|
97
|
+
* Once set, the store cannot be changed without restarting the application.
|
|
98
|
+
*
|
|
99
|
+
* @param adapter - Optional store implementation to inject
|
|
100
|
+
* @returns The singleton store instance
|
|
101
|
+
*
|
|
102
|
+
* @example Default in-memory store
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import { store } from "@rotorsoft/act";
|
|
105
|
+
* const s = store();
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Injecting PostgreSQL
|
|
109
|
+
* ```typescript
|
|
110
|
+
* import { store } from "@rotorsoft/act";
|
|
111
|
+
* import { PostgresStore } from "@rotorsoft/act-pg";
|
|
112
|
+
*
|
|
113
|
+
* store(new PostgresStore({
|
|
114
|
+
* host: "localhost",
|
|
115
|
+
* port: 5432,
|
|
116
|
+
* database: "myapp",
|
|
117
|
+
* user: "postgres",
|
|
118
|
+
* password: "secret",
|
|
119
|
+
* }));
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @see {@link Store} for the interface contract
|
|
123
|
+
* @see {@link InMemoryStore} for the default implementation
|
|
124
|
+
*/
|
|
125
|
+
export declare const store: (adapter?: Store | undefined) => Store;
|
|
126
|
+
/**
|
|
127
|
+
* Gets or injects the singleton cache.
|
|
128
|
+
*
|
|
129
|
+
* By default, Act uses an {@link InMemoryCache} (LRU, maxSize 1000). For
|
|
130
|
+
* distributed deployments, inject a Redis-backed cache before building your
|
|
131
|
+
* application.
|
|
132
|
+
*
|
|
133
|
+
* @param adapter - Optional cache implementation to inject
|
|
134
|
+
* @returns The singleton cache instance
|
|
135
|
+
*
|
|
136
|
+
* @see {@link Cache} for the interface contract
|
|
137
|
+
* @see {@link InMemoryCache} for the default implementation
|
|
138
|
+
*/
|
|
139
|
+
export declare const cache: (adapter?: Cache | undefined) => Cache;
|
|
140
|
+
/**
|
|
141
|
+
* Disposes all registered adapters and disposers, then exits the process.
|
|
142
|
+
*
|
|
143
|
+
* Execution order:
|
|
144
|
+
* 1. Custom disposers (registered via {@link dispose}) — in reverse order
|
|
145
|
+
* 2. Port adapters (log, store, cache) — in reverse registration order
|
|
146
|
+
* 3. Adapter registry is cleared
|
|
147
|
+
* 4. Process exits (skipped in test environment)
|
|
148
|
+
*
|
|
149
|
+
* In production, `"ERROR"` exits are silently ignored to avoid crashing on
|
|
150
|
+
* transient failures (e.g. an uncaught promise in a non-critical path).
|
|
151
|
+
*
|
|
152
|
+
* @param code - Exit code: `"EXIT"` for clean shutdown (exit 0),
|
|
153
|
+
* `"ERROR"` for abnormal termination (exit 1)
|
|
154
|
+
*/
|
|
155
|
+
export declare function disposeAndExit(code?: ExitCode): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Registers a cleanup function for graceful shutdown.
|
|
158
|
+
*
|
|
159
|
+
* Disposers are called automatically on SIGINT, SIGTERM, uncaught exceptions,
|
|
160
|
+
* and unhandled rejections. They execute in reverse registration order before
|
|
161
|
+
* port adapters are disposed.
|
|
162
|
+
*
|
|
163
|
+
* @param disposer - Async function to call during cleanup. Omit to get a
|
|
164
|
+
* reference to {@link disposeAndExit} without registering.
|
|
165
|
+
* @returns Function to manually trigger disposal and exit
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* import { dispose } from "@rotorsoft/act";
|
|
170
|
+
*
|
|
171
|
+
* const db = connectDatabase();
|
|
172
|
+
* dispose(async () => await db.close());
|
|
173
|
+
*
|
|
174
|
+
* // In tests
|
|
175
|
+
* afterAll(async () => await dispose()());
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @see {@link disposeAndExit} for the full shutdown sequence
|
|
179
|
+
*/
|
|
180
|
+
export declare function dispose(disposer?: Disposer): (code?: ExitCode) => Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Event name used internally for snapshot events in the event store.
|
|
183
|
+
* Snapshot events store a full state checkpoint, enabling efficient cold-start
|
|
184
|
+
* recovery without replaying the entire event stream.
|
|
185
|
+
*/
|
|
186
|
+
export declare const SNAP_EVENT = "__snapshot__";
|
|
187
|
+
/**
|
|
188
|
+
* Event name used internally for tombstone events in the event store.
|
|
189
|
+
* A tombstone marks a stream as permanently closed — no further writes
|
|
190
|
+
* are permitted until the stream is explicitly restarted via `close()`.
|
|
191
|
+
*
|
|
192
|
+
* @see {@link Act.close} for the close-the-books API
|
|
193
|
+
*/
|
|
194
|
+
export declare const TOMBSTONE_EVENT = "__tombstone__";
|
|
195
|
+
export {};
|
|
196
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/ports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAI7D,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,QAAQ,EACR,MAAM,EACN,KAAK,EACN,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,SAAS,4BAA6B,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAMlD;;;GAGG;AACH,KAAK,QAAQ,CAAC,IAAI,SAAS,UAAU,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,KAAK,IAAI,CAAC;AAKlE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,IAAI,SAAS,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,IAC5D,UAAU,IAAI,KAAG,IAAI,CAW9B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,GAAG,0EASd,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,KAAK,wCAEhB,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,KAAK,wCAEhB,CAAC;AASH;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,IAAI,GAAE,QAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB3E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,CACrB,QAAQ,CAAC,EAAE,QAAQ,GAClB,CAAC,IAAI,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAGpC;AAMD;;;;GAIG;AACH,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/signals.ts"],"names":[],"mappings":""}
|