import { ConsoleLogger } from "./adapters/console-logger.js"; import { type Scoped } from "./scoped.js"; import type { Cache, Disposable, Disposer, Logger, Store } from "./types/index.js"; export type { Scoped } from "./scoped.js"; /** * Port/adapter infrastructure for the Act framework. * * All infrastructure concerns (logging, storage, caching) are managed as * singleton adapters injected via port functions. Each port follows the same * pattern: first call wins with a sensible default, optional adapter injection. * * - `log()` — structured logging (default: ConsoleLogger) * - `store()` — event persistence (default: InMemoryStore) * - `cache()` — state checkpoints (default: InMemoryCache) * - `dispose()` — register cleanup functions for graceful shutdown * * @module ports */ /** * List of exit codes for process termination. Consumed by signal handlers * and {@link disposeAndExit}; not part of the user-facing surface. * * @internal */ export declare const ExitCodes: readonly ["ERROR", "EXIT"]; /** * Type for allowed exit codes. * * - `"ERROR"` — abnormal termination (uncaught exception, unhandled rejection) * - `"EXIT"` — clean shutdown (SIGINT, SIGTERM, or manual trigger) * * @internal */ export type ExitCode = (typeof ExitCodes)[number]; /** * Factory function that creates or returns the injected adapter. * @internal */ type Injector = (adapter?: Port) => Port; /** * Creates a singleton port with optional adapter injection. * * The first call initializes the adapter (using the provided adapter or the * injector's default). Subsequent calls return the cached singleton. Adapters * are disposed in reverse registration order during {@link disposeAndExit}. * * @param injector - Named function that creates the default adapter * @returns Port function: call with no args to get the singleton, or pass an * adapter on the first call to override the default * * @example * ```typescript * const store = port(function store(adapter?: Store) { * return adapter || new InMemoryStore(); * }); * const s = store(); // InMemoryStore * ``` */ export declare function port(injector: Injector): (adapter?: Port) => Port; /** * Gets or injects the singleton logger. * * By default, Act uses a built-in {@link ConsoleLogger} that emits JSON lines * in production (compatible with GCP, AWS CloudWatch, Datadog) and colorized * output in development — zero external dependencies. * * For pino, inject a `PinoLogger` from `@rotorsoft/act-pino` before building * your application. * * @param adapter - Optional logger implementation to inject * @returns The singleton logger instance * * @example Default console logger * ```typescript * import { log } from "@rotorsoft/act"; * const logger = log(); * logger.info("Application started"); * ``` * * @example Injecting pino * ```typescript * import { log } from "@rotorsoft/act"; * import { PinoLogger } from "@rotorsoft/act-pino"; * log(new PinoLogger({ level: "debug", pretty: true })); * ``` * * @see {@link Logger} for the interface contract * @see {@link ConsoleLogger} for the default implementation */ export declare const log: (adapter?: ConsoleLogger | Logger | undefined) => ConsoleLogger | Logger; export declare const store: (adapter?: Store) => Store; export declare const cache: (adapter?: Cache) => Cache; /** * The ports bag an Act without `ActOptions.scoped` runs in: the singleton * adapters, read through the same frame a scoped Act uses. * * Every Act entering a frame is what keeps its ports its own. Without one, a * shared Act called from inside a tenant's handler inherited that tenant's * frame and committed to the tenant's store (#1597). * * The properties are getters on purpose. The adapters are resolved lazily and * injected after `act().build()` in the normal case — `store(new PgStore())` * in application setup, or a test's `beforeEach` — so capturing them when the * bag is made would pin whatever existed at build time. They read the raw * resolvers rather than the public `store()`/`cache()`, which consult the * frame this bag *is* and would recurse. * * @internal */ export declare const default_scope: () => Scoped; /** * Registered cleanup functions live in `disposers.ts`, which holds * lifetime-bound entries weakly so registering never pins its target for the * process lifetime (#1441). The public surface here is unchanged. */ /** * Disposes all registered adapters and disposers, then exits the process. * * Execution order: * 1. Custom disposers (registered via {@link dispose}) — in reverse order * 2. Port adapters (log, store, cache) — in reverse registration order * 3. Adapter registry is cleared * 4. Process exits (skipped in test environment) * * In production, `"ERROR"` exits are silently ignored to avoid crashing on * transient failures (e.g. an uncaught promise in a non-critical path). * * @param code - Exit code: `"EXIT"` for clean shutdown (exit 0), * `"ERROR"` for abnormal termination (exit 1) */ export declare function disposeAndExit(code?: ExitCode): Promise; /** * Registers a cleanup function for graceful shutdown. * * Disposers are called automatically on SIGINT, SIGTERM, uncaught exceptions, * and unhandled rejections. They execute in reverse registration order before * port adapters are disposed. * * @param disposer - Async function to call during cleanup. Omit to get a * reference to {@link disposeAndExit} without registering. * @returns Function to manually trigger disposal and exit * * @example * ```typescript * import { dispose } from "@rotorsoft/act"; * * const db = connectDatabase(); * dispose(async () => await db.close()); * * // In tests * afterAll(async () => await dispose()()); * ``` * * @see {@link disposeAndExit} for the full shutdown sequence */ export declare function dispose(disposer?: Disposer): (code?: ExitCode) => Promise; /** * Event name used internally for snapshot events in the event store. * Snapshot events store a full state checkpoint, enabling efficient cold-start * recovery without replaying the entire event stream. */ export declare const SNAP_EVENT = "__snapshot__"; /** * Event name used internally for tombstone events in the event store. * A tombstone marks a stream as permanently closed — no further writes * are permitted until the stream is explicitly restarted via `close()`. * * @see {@link Act.close} for the close-the-books API */ export declare const TOMBSTONE_EVENT = "__tombstone__"; /** * Name of the implicit lane every reaction lands in unless its `.to({lane})` * declaration says otherwise (ACT-1103). Acts that don't call * `.withLane(...)` see only this lane, and behavior is identical to * pre-1103 single-controller drain. * * Persisted on `streams.lane` and threaded as the strict-typed default in * builder generics — `lane?: TLanes` always includes `"default"`. */ export declare const DEFAULT_LANE = "default"; //# sourceMappingURL=ports.d.ts.map