@rotorsoft/act 1.32.30 → 1.33.1
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 +0 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/act.d.ts +96 -385
- package/dist/@types/act.d.ts.map +1 -1
- package/dist/@types/adapters/in-memory-store.d.ts.map +1 -1
- package/dist/@types/builders/act-builder.d.ts +2 -115
- package/dist/@types/builders/act-builder.d.ts.map +1 -1
- package/dist/@types/builders/builder-utils.d.ts +1 -1
- package/dist/@types/builders/builder-utils.d.ts.map +1 -1
- package/dist/@types/builders/event-builder.d.ts +5 -5
- package/dist/@types/builders/event-builder.d.ts.map +1 -1
- package/dist/@types/builders/merge.d.ts +1 -1
- package/dist/@types/builders/merge.d.ts.map +1 -1
- package/dist/@types/builders/projection-builder.d.ts +2 -144
- package/dist/@types/builders/projection-builder.d.ts.map +1 -1
- package/dist/@types/builders/slice-builder.d.ts +2 -71
- package/dist/@types/builders/slice-builder.d.ts.map +1 -1
- package/dist/@types/builders/state-builder.d.ts +2 -376
- package/dist/@types/builders/state-builder.d.ts.map +1 -1
- package/dist/@types/config.d.ts +6 -43
- package/dist/@types/config.d.ts.map +1 -1
- package/dist/@types/csv.d.ts +1 -15
- package/dist/@types/csv.d.ts.map +1 -1
- package/dist/@types/index.d.ts +0 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/@types/internal/autoclose-policy.d.ts +1 -59
- package/dist/@types/internal/autoclose-policy.d.ts.map +1 -1
- package/dist/@types/internal/autoclose-reaction.d.ts +1 -2
- package/dist/@types/internal/autoclose-reaction.d.ts.map +1 -1
- package/dist/@types/internal/autoclose-window.d.ts +1 -1
- package/dist/@types/internal/autoclose-window.d.ts.map +1 -1
- package/dist/@types/internal/circuit-breaker.d.ts +1 -2
- package/dist/@types/internal/circuit-breaker.d.ts.map +1 -1
- package/dist/@types/{builders/build-classify.d.ts → internal/classify.d.ts} +2 -15
- package/dist/@types/internal/classify.d.ts.map +1 -0
- package/dist/@types/internal/close-cycle.d.ts.map +1 -1
- package/dist/@types/internal/config.d.ts +2 -42
- package/dist/@types/internal/config.d.ts.map +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts +1 -1
- package/dist/@types/internal/correlate-cycle.d.ts.map +1 -1
- package/dist/@types/internal/{correlator.d.ts → correlation-id.d.ts} +1 -1
- package/dist/@types/internal/correlation-id.d.ts.map +1 -0
- package/dist/@types/internal/defer-config.d.ts.map +1 -1
- package/dist/@types/internal/drain-cycle.d.ts +1 -1
- package/dist/@types/internal/drain-cycle.d.ts.map +1 -1
- package/dist/@types/internal/{drain.d.ts → drain-ops.d.ts} +1 -1
- package/dist/@types/internal/drain-ops.d.ts.map +1 -0
- package/dist/@types/internal/event-sourcing.d.ts +1 -8
- package/dist/@types/internal/event-sourcing.d.ts.map +1 -1
- package/dist/@types/internal/{sensitive.d.ts → pii.d.ts} +4 -71
- package/dist/@types/internal/pii.d.ts.map +1 -0
- package/dist/@types/internal/projection-fold.d.ts +1 -2
- package/dist/@types/internal/projection-fold.d.ts.map +1 -1
- package/dist/@types/internal/{close-signal.d.ts → reaction-dispatch.d.ts} +47 -2
- package/dist/@types/internal/reaction-dispatch.d.ts.map +1 -0
- package/dist/@types/internal/report-once.d.ts +1 -1
- package/dist/@types/internal/settle.d.ts +21 -12
- package/dist/@types/internal/settle.d.ts.map +1 -1
- package/dist/@types/internal/tracing.d.ts +3 -3
- package/dist/@types/internal/tracing.d.ts.map +1 -1
- package/dist/@types/ports.d.ts +3 -43
- package/dist/@types/ports.d.ts.map +1 -1
- package/dist/@types/scoped.d.ts +1 -6
- package/dist/@types/scoped.d.ts.map +1 -1
- package/dist/@types/sensitive.d.ts +56 -0
- package/dist/@types/sensitive.d.ts.map +1 -0
- package/dist/@types/test/index.d.ts +1 -0
- package/dist/@types/test/index.d.ts.map +1 -1
- package/dist/@types/test/sandbox.d.ts +2 -26
- package/dist/@types/test/sandbox.d.ts.map +1 -1
- package/dist/@types/types/act.d.ts +214 -0
- package/dist/@types/types/act.d.ts.map +1 -0
- package/dist/@types/types/action.d.ts +69 -2
- package/dist/@types/types/action.d.ts.map +1 -1
- package/dist/@types/types/builders.d.ts +721 -0
- package/dist/@types/types/builders.d.ts.map +1 -0
- package/dist/@types/types/errors.d.ts +31 -1
- package/dist/@types/types/errors.d.ts.map +1 -1
- package/dist/@types/types/index.d.ts +38 -0
- package/dist/@types/types/index.d.ts.map +1 -1
- package/dist/@types/types/ports.d.ts +20 -18
- package/dist/@types/types/ports.d.ts.map +1 -1
- package/dist/@types/types/reaction.d.ts +11 -1
- package/dist/@types/types/reaction.d.ts.map +1 -1
- package/dist/@types/types/sandbox.d.ts +31 -0
- package/dist/@types/types/sandbox.d.ts.map +1 -0
- package/dist/@types/types/schemas.d.ts +12 -17
- package/dist/@types/types/schemas.d.ts.map +1 -1
- package/dist/chunk-NNWP65YM.cjs +264 -0
- package/dist/chunk-NNWP65YM.cjs.map +1 -0
- package/dist/{chunk-X3MMQIIP.js → chunk-NYH6FNTM.js} +174 -22
- package/dist/chunk-NYH6FNTM.js.map +1 -0
- package/dist/{chunk-HHKLVRR4.js → chunk-TJ4JRRUR.js} +38 -57
- package/dist/chunk-TJ4JRRUR.js.map +1 -0
- package/dist/chunk-YKL44PYX.cjs +1233 -0
- package/dist/chunk-YKL44PYX.cjs.map +1 -0
- package/dist/index.cjs +1954 -3440
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +911 -1063
- package/dist/index.js.map +1 -1
- package/dist/test/index.cjs +16 -1113
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.js +2 -2
- package/dist/test/index.js.map +1 -1
- package/dist/types/index.cjs +58 -276
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.js +15 -1
- package/package.json +2 -2
- package/dist/@types/builders/build-classify.d.ts.map +0 -1
- package/dist/@types/builders/builder-base.d.ts +0 -70
- package/dist/@types/builders/builder-base.d.ts.map +0 -1
- package/dist/@types/builders/reaction-builder.d.ts +0 -55
- package/dist/@types/builders/reaction-builder.d.ts.map +0 -1
- package/dist/@types/internal/close-signal.d.ts.map +0 -1
- package/dist/@types/internal/correlator.d.ts.map +0 -1
- package/dist/@types/internal/defer-signal.d.ts +0 -32
- package/dist/@types/internal/defer-signal.d.ts.map +0 -1
- package/dist/@types/internal/drain.d.ts.map +0 -1
- package/dist/@types/internal/index.d.ts +0 -38
- package/dist/@types/internal/index.d.ts.map +0 -1
- package/dist/@types/internal/sensitive.d.ts.map +0 -1
- package/dist/chunk-HHKLVRR4.js.map +0 -1
- package/dist/chunk-X3MMQIIP.js.map +0 -1
package/dist/test/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/index.ts","../../src/test/sandbox.ts","../../src/internal/lru-map.ts","../../src/adapters/in-memory-cache.ts","../../src/adapters/console-logger.ts","../../src/config.ts","../../src/types/errors.ts","../../src/types/schemas.ts","../../src/internal/sensitive.ts","../../src/types/index.ts","../../src/utils.ts","../../src/scoped.ts","../../src/ports.ts","../../src/adapters/in-memory-store.ts"],"sourcesContent":["export * from \"./sandbox.js\";\n","import { test } from \"vitest\";\nimport type { Act, ActOptions } from \"../act.js\";\nimport { InMemoryCache } from \"../adapters/in-memory-cache.js\";\nimport { InMemoryStore } from \"../adapters/in-memory-store.js\";\nimport type { Cache, Store } from \"../types/index.js\";\n\n/**\n * Minimal structural shape — anything with a `.build()` that returns an\n * Act. Avoids the variance pitfalls of constraining on the full\n * `ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>`\n * generic when called across package boundaries.\n */\ntype AnyActBuilder<TApp> = {\n // `ActOptions<any>` rather than `ActOptions<string>` (the default) — a\n // builder narrowed to `ActOptions<\"default\">` would otherwise trip\n // function-parameter contravariance against `ActOptions<string>`. The\n // `any` only widens `onlyLanes`; the rest of the option shape\n // (`scoped`, `correlator`, `settleDebounceMs`, etc.) still type-checks\n // at the runtime call site below.\n build: (options?: ActOptions<any>) => TApp;\n};\n\n/**\n * Options for {@link sandbox} / {@link fixture}.\n *\n * Defaults to `new InMemoryStore() + new InMemoryCache()` per call.\n * Override `store` / `cache` to point at PG, SQLite, or any other\n * adapter — factories run once per call so each test gets a fresh\n * instance.\n */\nexport type SandboxOptions = {\n /** Factory for the per-test store. Defaults to `new InMemoryStore()`. */\n readonly store?: () => Store | Promise<Store>;\n /** Factory for the per-test cache. Defaults to `new InMemoryCache()`. */\n readonly cache?: () => Cache | Promise<Cache>;\n /** Pass-through ActOptions. `scoped` is filled in by the helper. */\n readonly actOptions?: Omit<ActOptions, \"scoped\">;\n};\n\n/** Return shape of {@link sandbox}. */\nexport type Sandbox<TApp> = {\n readonly app: TApp;\n readonly store: Store;\n readonly cache: Cache;\n /** Tears down the Act, store, and cache. Idempotent. */\n readonly dispose: () => Promise<void>;\n};\n\n/**\n * Build a scoped Act bound to a fresh `{ store, cache }` bag.\n *\n * Intended for parallel-safe test isolation. Each call constructs new\n * ports (defaults to InMemoryStore + InMemoryCache), seeds the store,\n * builds the Act with `ActOptions.scoped`, and returns `{ app, store,\n * cache, dispose }`. The caller owns the lifecycle: `dispose()` performs\n * `app.shutdown()` followed by `store.dispose()` + `cache.dispose()`.\n *\n * Prefer {@link fixture} when fixture-style ergonomics fit; reach for\n * `sandbox` when you need explicit control (e.g., wiring inside\n * `beforeAll` rather than per-test, or two scoped Acts in one test, or\n * direct access to the store/cache handles).\n *\n * @example Per-test isolated Act with explicit dispose\n * ```ts\n * import { sandbox } from \"@rotorsoft/act/test\";\n *\n * const counterBuilder = act().withState(Counter);\n *\n * it(\"increments\", async () => {\n * const { app, dispose } = await sandbox(counterBuilder);\n * await app.do(\"increment\", { stream: \"c-1\", actor }, { by: 1 });\n * expect((await app.load(\"Counter\", \"c-1\")).state.count).toBe(1);\n * await dispose();\n * });\n * ```\n */\nexport async function sandbox<TApp>(\n builder: AnyActBuilder<TApp>,\n options: SandboxOptions = {}\n): Promise<Sandbox<TApp>> {\n const store = options.store ? await options.store() : new InMemoryStore();\n const cache = options.cache ? await options.cache() : new InMemoryCache();\n await store.seed();\n\n const app = builder.build({\n ...options.actOptions,\n scoped: { store, cache },\n });\n\n let _disposed: Promise<void> | undefined;\n const dispose = (): Promise<void> => {\n if (!_disposed) {\n _disposed = (async () => {\n await (app as unknown as Act<any, any, any, any, any>).shutdown();\n await store.dispose();\n await cache.dispose();\n })();\n }\n return _disposed;\n };\n\n return { app, store, cache, dispose };\n}\n\n/**\n * Vitest fixture wrapper around {@link sandbox}.\n *\n * Returns a `test` instance with an `app` fixture — each test gets a\n * fresh, isolated Act and vitest's fixture lifecycle runs the cleanup\n * automatically when the test completes.\n *\n * Works with `test.concurrent(...)` — every concurrent invocation\n * receives its own bag, so tests don't race on the singleton.\n *\n * For tests that also need direct access to the underlying `store` /\n * `cache` handles, use {@link sandbox} explicitly.\n *\n * @example Fixture-style — auto cleanup, parallel-safe\n * ```ts\n * import { fixture } from \"@rotorsoft/act/test\";\n *\n * const test = fixture(act().withState(Counter));\n *\n * test(\"increments\", async ({ app }) => {\n * await app.do(\"increment\", { stream: \"c-1\", actor }, { by: 1 });\n * expect((await app.load(\"Counter\", \"c-1\")).state.count).toBe(1);\n * });\n *\n * test.concurrent(\"isolated from concurrent peers\", async ({ app }) => {\n * // Each concurrent invocation gets its own store + cache — no\n * // singleton contention, no flake.\n * });\n * ```\n */\nexport function fixture<TApp>(\n builder: AnyActBuilder<TApp>,\n defaults: SandboxOptions = {}\n) {\n return test.extend<{ app: TApp }>({\n app: async (\n // biome-ignore lint/correctness/noEmptyPattern: vitest fixture API requires a destructured deps parameter\n {},\n use: (value: TApp) => Promise<void>\n ) => {\n const ctx = await sandbox(builder, defaults);\n try {\n await use(ctx.app);\n } finally {\n await ctx.dispose();\n }\n },\n });\n}\n","/**\n * Tiny bounded LRU map / set built on insertion-ordered `Map`. Used to cap\n * memory in long-running orchestrators that mint large numbers of keys —\n * notably:\n *\n * - {@link InMemoryCache}: stream → state checkpoint\n * - `Act._subscribed_streams`: stream → presence (LruSet)\n *\n * Apps with millions of dynamic streams (one target per aggregate) can't\n * afford an unbounded `Set<string>` — eviction is required.\n */\n\n/**\n * Bounded LRU map. `get()` promotes; `has()` does not. `set()` always\n * promotes and evicts the oldest entry when at capacity.\n */\nexport class LruMap<K, V> {\n private readonly _entries = new Map<K, V>();\n private readonly _max_size: number;\n\n constructor(maxSize: number) {\n this._max_size = maxSize;\n }\n\n get(key: K): V | undefined {\n const v = this._entries.get(key);\n if (v === undefined) return undefined;\n // promote: delete + re-insert moves to most-recent position\n this._entries.delete(key);\n this._entries.set(key, v);\n return v;\n }\n\n has(key: K): boolean {\n return this._entries.has(key);\n }\n\n set(key: K, value: V): void {\n this._entries.delete(key);\n if (this._entries.size >= this._max_size) {\n // size >= maxSize ≥ 1 → at least one entry exists → next().value\n // is the oldest key (asserted with `!`).\n const oldest = this._entries.keys().next().value!;\n this._entries.delete(oldest);\n }\n this._entries.set(key, value);\n }\n\n delete(key: K): boolean {\n return this._entries.delete(key);\n }\n\n clear(): void {\n this._entries.clear();\n }\n\n get size(): number {\n return this._entries.size;\n }\n}\n\n/**\n * Bounded LRU set built on top of {@link LruMap}. `has()` does not promote;\n * `add()` does (re-inserting if already present, evicting the oldest at\n * capacity).\n */\nexport class LruSet<T> {\n private readonly _map: LruMap<T, true>;\n\n constructor(maxSize: number) {\n this._map = new LruMap(maxSize);\n }\n\n has(value: T): boolean {\n return this._map.has(value);\n }\n\n add(value: T): void {\n this._map.set(value, true);\n }\n\n delete(value: T): boolean {\n return this._map.delete(value);\n }\n\n clear(): void {\n this._map.clear();\n }\n\n get size(): number {\n return this._map.size;\n }\n}\n","import { LruMap } from \"../internal/lru-map.js\";\nimport type { Cache, CacheEntry, Schema } from \"../types/index.js\";\n\n/**\n * In-memory LRU cache for stream snapshots.\n *\n * Backed by an internal `LruMap` for O(1) get/set with LRU eviction.\n * Configurable `maxSize` bounds memory usage.\n *\n * @example\n * ```typescript\n * import { cache } from \"@rotorsoft/act\";\n * import { InMemoryCache } from \"@rotorsoft/act\";\n *\n * cache(new InMemoryCache({ maxSize: 500 }));\n * ```\n */\n/* eslint-disable @typescript-eslint/require-await -- async interface for Redis-compatibility */\nexport class InMemoryCache implements Cache {\n // CacheEntry<any> lets `get<TState>` and `set<TState>` flow without casts:\n // any is bidirectionally compatible with the per-call TState binding, while\n // the public Cache interface still presents a typed surface to callers.\n private readonly _entries: LruMap<string, CacheEntry<any>>;\n\n constructor(options?: { maxSize?: number }) {\n this._entries = new LruMap(options?.maxSize ?? 1000);\n }\n\n /** @inheritDoc */\n async get<TState extends Schema>(\n stream: string\n ): Promise<CacheEntry<TState> | undefined> {\n return this._entries.get(stream);\n }\n\n /** @inheritDoc */\n async set<TState extends Schema>(\n stream: string,\n entry: CacheEntry<TState>\n ): Promise<void> {\n this._entries.set(stream, entry);\n }\n\n /** @inheritDoc */\n async invalidate(stream: string): Promise<void> {\n this._entries.delete(stream);\n }\n\n /** @inheritDoc */\n async clear(): Promise<void> {\n this._entries.clear();\n }\n\n /** @inheritDoc */\n async dispose(): Promise<void> {\n this._entries.clear();\n }\n\n /** Current number of entries held by the LRU. */\n get size(): number {\n return this._entries.size;\n }\n}\n","/**\n * @module adapters/console-logger\n *\n * High-performance console logger inspired by pino's design:\n * - Numeric level comparison for O(1) gating\n * - stdout.write() in production for raw JSON lines (no console overhead)\n * - Colorized single-line output in development\n * - No-op method replacement when level is above threshold\n * - Child logger support with merged bindings\n */\nimport type { Logger } from \"../types/index.js\";\n\nconst LEVEL_VALUES: Record<string, number> = {\n fatal: 60,\n error: 50,\n warn: 40,\n info: 30,\n debug: 20,\n trace: 10,\n};\n\nconst LEVEL_COLORS: Record<string, string> = {\n fatal: \"\\x1b[41m\\x1b[37m\", // white on red bg\n error: \"\\x1b[31m\", // red\n warn: \"\\x1b[33m\", // yellow\n info: \"\\x1b[32m\", // green\n debug: \"\\x1b[36m\", // cyan\n trace: \"\\x1b[90m\", // gray\n};\n\nconst RESET = \"\\x1b[0m\";\n\nconst noop = () => {};\n\n/**\n * Default console logger for the Act framework.\n *\n * Production mode emits newline-delimited JSON (compatible with GCP, AWS\n * CloudWatch, Datadog, and other structured log ingestion systems).\n *\n * Development mode emits colorized, human-readable output.\n */\nexport class ConsoleLogger implements Logger {\n level: string;\n private readonly _pretty: boolean;\n\n readonly fatal: Logger[\"fatal\"];\n readonly error: Logger[\"error\"];\n readonly warn: Logger[\"warn\"];\n readonly info: Logger[\"info\"];\n readonly debug: Logger[\"debug\"];\n readonly trace: Logger[\"trace\"];\n\n constructor(\n options: {\n level?: string;\n pretty?: boolean;\n bindings?: Record<string, unknown>;\n } = {}\n ) {\n const {\n level = \"info\",\n pretty = process.env.NODE_ENV !== \"production\",\n bindings,\n } = options;\n this._pretty = pretty;\n this.level = level;\n\n const threshold = LEVEL_VALUES[level] ?? 30;\n const write = pretty\n ? this._pretty_write.bind(this, bindings)\n : this._json_write.bind(this, bindings);\n\n // Assign methods — noop when level is gated (like pino's level-based replacement)\n this.fatal = write.bind(this, \"fatal\", 60); // fatal is always enabled\n this.error = threshold <= 50 ? write.bind(this, \"error\", 50) : noop;\n this.warn = threshold <= 40 ? write.bind(this, \"warn\", 40) : noop;\n this.info = threshold <= 30 ? write.bind(this, \"info\", 30) : noop;\n this.debug = threshold <= 20 ? write.bind(this, \"debug\", 20) : noop;\n this.trace = threshold <= 10 ? write.bind(this, \"trace\", 10) : noop;\n }\n\n /** No-op — `console.log` has no resources to release. */\n async dispose(): Promise<void> {}\n\n /** @inheritDoc */\n child(bindings: Record<string, unknown>): Logger {\n return new ConsoleLogger({\n level: this.level,\n pretty: this._pretty,\n bindings,\n });\n }\n\n private _json_write(\n bindings: Record<string, unknown> | undefined,\n level: string,\n _num: number,\n obj_or_msg: unknown,\n msg?: string\n ): void {\n let obj: Record<string, unknown>;\n let message: string | undefined;\n\n if (typeof obj_or_msg === \"string\") {\n message = obj_or_msg;\n obj = {};\n } else if (obj_or_msg instanceof Error) {\n // Error instances spread to `{}` — capture the salient fields\n // explicitly so structured log aggregators see them.\n message = msg ?? obj_or_msg.message;\n obj = {\n error: { message: obj_or_msg.message, name: obj_or_msg.name },\n stack: obj_or_msg.stack,\n };\n } else if (obj_or_msg !== null && typeof obj_or_msg === \"object\") {\n message = msg;\n obj = { ...(obj_or_msg as Record<string, unknown>) };\n } else {\n message = msg;\n obj = { value: obj_or_msg };\n }\n\n const entry = Object.assign({ level, time: Date.now() }, bindings, obj);\n if (message) entry.msg = message;\n\n let line: string;\n try {\n line = JSON.stringify(entry);\n } catch {\n // Cyclic or unserializable payload — emit a minimal line rather\n // than crash the log call site.\n line = JSON.stringify({\n level,\n time: entry.time,\n msg: message ?? \"[unserializable]\",\n unserializable: true,\n });\n }\n process.stdout.write(line + \"\\n\");\n }\n\n private _pretty_write(\n bindings: Record<string, unknown> | undefined,\n level: string,\n _num: number,\n obj_or_msg: unknown,\n msg?: string\n ): void {\n const color = LEVEL_COLORS[level];\n const tag = `${color}${level.toUpperCase().padEnd(5)}${RESET}`;\n const ts = new Date().toISOString().slice(11, 23); // HH:mm:ss.SSS\n\n let message: string;\n let data: string | undefined;\n\n if (typeof obj_or_msg === \"string\") {\n message = obj_or_msg;\n } else if (obj_or_msg instanceof Error) {\n // Error instances don't serialize their `message`/`stack` via\n // JSON.stringify — `JSON.stringify(err) === \"{}\"`. Render the\n // message inline and the stack as the data payload so operators\n // see something useful instead of an empty object.\n message = msg ?? obj_or_msg.message;\n data = obj_or_msg.stack;\n } else {\n message = msg ?? \"\";\n if (obj_or_msg !== undefined && obj_or_msg !== null) {\n try {\n data = JSON.stringify(obj_or_msg);\n } catch {\n data = \"[unserializable]\";\n }\n }\n }\n\n const bind_str =\n bindings && Object.keys(bindings).length\n ? ` ${JSON.stringify(bindings)}`\n : \"\";\n\n const parts = [ts, tag, message, data, bind_str].filter(Boolean);\n process.stdout.write(parts.join(\" \") + \"\\n\");\n }\n}\n","/**\n * @packageDocumentation\n * Configuration utilities for Act Framework environment, logging, and package metadata.\n *\n * Provides type-safe configuration loading and validation using Zod schemas.\n *\n * @module config\n */\nimport * as fs from \"node:fs\";\nimport { z } from \"zod\";\nimport { log } from \"./ports.js\";\nimport {\n type Environment,\n Environments,\n type LogLevel,\n LogLevels,\n} from \"./types/index.js\";\nimport { extend } from \"./utils.js\";\n\n/**\n * Zod schema for validating package.json metadata.\n * @internal\n */\nexport const PackageSchema = z.object({\n name: z.string().min(1),\n version: z.string().min(1),\n description: z.string().min(1).optional(),\n author: z\n .object({ name: z.string().min(1), email: z.string().optional() })\n .optional()\n .or(z.string().min(1))\n .optional(),\n license: z.string().min(1).optional(),\n dependencies: z.record(z.string(), z.string()).optional(),\n});\n\n/**\n * Type representing the validated package.json metadata.\n *\n * @internal\n */\nexport type Package = z.infer<typeof PackageSchema>;\n\n/**\n * Fallback package metadata when `package.json` can't be read at module\n * load — happens when the framework is consumed from a CWD that doesn't\n * have one (bundled CLIs, Lambda layers, embedded scripts) or when the\n * file exists but is malformed. `name` and `version` also fall back one by\n * one when the file has no valid value for them.\n *\n * The values are deliberately synthetic so callers spot them immediately:\n * `config().name === \"act-fallback\"` is a runtime signal that the framework\n * couldn't load the host project's package.json.\n *\n * @internal\n */\nconst FALLBACK_PACKAGE: Package = {\n name: \"act-fallback\",\n version: \"0.0.0-fallback\",\n description: \"Synthetic fallback — package.json could not be loaded\",\n};\n\n/**\n * Loads the local package.json as a Package object, keeping each field only\n * when it is valid: `npm init -y` writes an empty `description` and\n * `author`, and a bare `{\"type\":\"module\"}` has no name or version. A\n * missing or invalid `name` / `version` falls back to\n * {@link FALLBACK_PACKAGE}. On a read or parse failure, falls back entirely\n * and stashes the error so {@link config} can surface it on first access —\n * we can't call `log()` here because the logger port memoizes on first\n * call and locking it at module load defeats user injection.\n *\n * @internal\n */\nconst get_package = (): Package => {\n try {\n const raw = JSON.parse(fs.readFileSync(\"package.json\").toString());\n const pkg: Record<string, unknown> = {\n name: FALLBACK_PACKAGE.name,\n version: FALLBACK_PACKAGE.version,\n };\n for (const [key, schema] of Object.entries(PackageSchema.shape)) {\n const field = schema.safeParse(raw?.[key]);\n if (field.success && field.data !== undefined) pkg[key] = field.data;\n }\n return pkg as Package;\n } catch (err) {\n pkg_load_error = err;\n return FALLBACK_PACKAGE;\n }\n};\n\n/** Stashed read/parse error from {@link get_package}, surfaced by config(). */\nlet pkg_load_error: unknown;\n\n/**\n * Zod schema for the full Act Framework configuration object.\n * Includes package metadata, environment, logging, and timing options.\n * @internal\n */\nconst BaseSchema = PackageSchema.extend({\n env: z.enum(Environments),\n logLevel: z.enum(LogLevels),\n logSingleLine: z.boolean(),\n sleepMs: z.number().int().min(0).max(5000),\n});\n\n/**\n * Type representing the validated Act Framework configuration object.\n */\nexport type Config = z.infer<typeof BaseSchema>;\n\nconst { NODE_ENV, LOG_LEVEL, LOG_SINGLE_LINE, SLEEP_MS } = process.env;\n\nconst env = (NODE_ENV || \"development\") as Environment;\nconst logLevel = (LOG_LEVEL ||\n (NODE_ENV === \"test\"\n ? \"fatal\"\n : NODE_ENV === \"production\"\n ? \"info\"\n : \"trace\")) as LogLevel;\nconst logSingleLine = (LOG_SINGLE_LINE || \"true\") === \"true\";\nconst sleepMs = parseInt(NODE_ENV === \"test\" ? \"0\" : (SLEEP_MS ?? \"100\"), 10);\n\nconst pkg = get_package();\n\n// Lazily validated on first call. Cannot run extend() at module load\n// because of a utils.ts <-> config.ts cycle (utils imports config for\n// sleep()'s default). Inputs are frozen after import, so the cached\n// result is stable for the life of the process.\nlet _validated: Config | undefined;\n\n/**\n * Gets the current Act Framework configuration.\n *\n * Configuration is loaded from package.json and environment variables, providing\n * type-safe access to application metadata and runtime settings.\n *\n * **Environment Variables:**\n * - `NODE_ENV`: \"development\" | \"test\" | \"staging\" | \"production\" (default: \"development\")\n * - `LOG_LEVEL`: \"fatal\" | \"error\" | \"warn\" | \"info\" | \"debug\" | \"trace\"\n * - `LOG_SINGLE_LINE`: \"true\" | \"false\" (default: \"true\")\n * - `SLEEP_MS`: Milliseconds for sleep utility (default: 100, 0 for tests)\n *\n * **Defaults by environment:**\n * - test: logLevel=\"error\", sleepMs=0\n * - production: logLevel=\"info\"\n * - development: logLevel=\"trace\"\n *\n * @returns The validated configuration object\n *\n * @example Basic usage\n * ```typescript\n * import { config } from \"@rotorsoft/act\";\n *\n * const cfg = config();\n * console.log(`App: ${cfg.name} v${cfg.version}`);\n * console.log(`Environment: ${cfg.env}`);\n * console.log(`Log level: ${cfg.logLevel}`);\n * ```\n *\n * @see {@link Config} for configuration type\n */\nexport const config = (): Config => {\n if (!_validated) {\n _validated = extend(\n { ...pkg, env, logLevel, logSingleLine, sleepMs },\n BaseSchema\n );\n if (pkg_load_error) {\n // Surface the fallback once, after _validated is set so the\n // recursive log() → config() call short-circuits. log() resolves\n // through the port singleton — respects user injection and level.\n const msg =\n pkg_load_error instanceof Error\n ? pkg_load_error.message\n : typeof pkg_load_error === \"string\"\n ? pkg_load_error\n : \"unknown error\";\n log().warn(\n `[act] Could not read package.json (${msg}); using synthetic ` +\n `name=\"${FALLBACK_PACKAGE.name}\" version=\"${FALLBACK_PACKAGE.version}\".`\n );\n pkg_load_error = undefined;\n }\n }\n return _validated;\n};\n","import type {\n Actor,\n Message,\n Schema,\n Schemas,\n Snapshot,\n Target,\n} from \"./action.js\";\n\n/**\n * @packageDocumentation\n * @module act/types\n * @category Types\n * Application error type constants and error classes for the Act Framework.\n *\n * - `ERR_VALIDATION`: Schema validation error\n * - `ERR_INVARIANT`: Invariant validation error\n * - `ERR_CONCURRENCY`: Optimistic concurrency validation error on commits\n */\nexport const Errors = {\n ValidationError: \"ERR_VALIDATION\",\n InvariantError: \"ERR_INVARIANT\",\n ConcurrencyError: \"ERR_CONCURRENCY\",\n StreamClosedError: \"ERR_STREAM_CLOSED\",\n NonRetryableError: \"ERR_NON_RETRYABLE\",\n StoreError: \"ERR_STORE\",\n} as const;\n\n/**\n * Thrown when an action or event payload fails Zod schema validation.\n *\n * This error indicates that data doesn't match the expected schema defined\n * for an action or event. The `details` property contains the Zod validation\n * error with specific information about what failed.\n *\n * @example Catching validation errors\n * ```typescript\n * import { ValidationError } from \"@rotorsoft/act\";\n *\n * try {\n * await app.do(\"createUser\", target, {\n * email: \"invalid-email\", // Missing @ symbol\n * age: -5 // Negative age\n * });\n * } catch (error) {\n * if (error instanceof ValidationError) {\n * console.error(\"Validation failed for:\", error.target);\n * console.error(\"Invalid payload:\", error.payload);\n * console.error(\"Validation details:\", error.details);\n * // details contains Zod error with field-level info\n * }\n * }\n * ```\n *\n * @see {@link https://zod.dev | Zod documentation} for validation details\n */\nexport class ValidationError extends Error {\n /** The type of target being validated (e.g., \"action\", \"event\") */\n public readonly target: string;\n /** The invalid payload that failed validation */\n public readonly payload: any;\n /** Zod validation error details */\n public readonly details: any;\n\n constructor(target: string, payload: any, details: any) {\n super(`Invalid ${target} payload`);\n this.name = Errors.ValidationError;\n this.target = target;\n this.payload = payload;\n this.details = details;\n }\n}\n\n/**\n * Thrown when a business rule (invariant) is violated during action execution.\n *\n * Invariants are conditions that must hold true for an action to succeed.\n * They're checked after loading the current state but before emitting events.\n * This error provides complete context about what action was attempted and\n * why it was rejected.\n *\n * @template TState - State schema type\n * @template TEvents - Event schemas type\n * @template TActions - Action schemas type\n * @template TKey - Action name\n * @template TActor - Actor type extending base Actor\n *\n * @example Catching invariant violations\n * ```typescript\n * import { InvariantError } from \"@rotorsoft/act\";\n *\n * try {\n * await app.do(\"withdraw\",\n * { stream: \"account-123\", actor: { id: \"user1\", name: \"Alice\" } },\n * { amount: 1000 }\n * );\n * } catch (error) {\n * if (error instanceof InvariantError) {\n * console.error(\"Action:\", error.action);\n * console.error(\"Reason:\", error.description);\n * console.error(\"Current state:\", error.snapshot.state);\n * console.error(\"Attempted payload:\", error.payload);\n * }\n * }\n * ```\n *\n * @see {@link Invariant} for defining business rules\n */\nexport class InvariantError<\n TState extends Schema,\n TEvents extends Schemas,\n TActions extends Schemas,\n TKey extends keyof TActions,\n TActor extends Actor = Actor,\n> extends Error {\n /** The action that was attempted */\n readonly action: TKey;\n /** The action payload that was provided */\n readonly payload: Readonly<TActions[TKey]>;\n /** The target stream and actor context */\n readonly target: Target<TActor>;\n /** The current state snapshot when invariant was checked */\n readonly snapshot: Snapshot<TState, TEvents>;\n /** Human-readable description of why the invariant failed */\n readonly description: string;\n\n constructor(\n action: TKey,\n payload: Readonly<TActions[TKey]>,\n target: Target<TActor>,\n snapshot: Snapshot<TState, TEvents>,\n description: string\n ) {\n super(`${action as string} failed invariant: ${description}`);\n this.name = Errors.InvariantError;\n this.action = action;\n this.payload = payload;\n this.target = target;\n this.snapshot = snapshot;\n this.description = description;\n }\n}\n\n/**\n * Thrown when optimistic concurrency control detects a conflict.\n *\n * This error occurs when trying to commit events to a stream that has been\n * modified by another process since it was last loaded. The version number\n * doesn't match expectations, indicating a concurrent modification.\n *\n * This is a normal occurrence in distributed systems and should be handled\n * by reloading the current state and retrying the action.\n *\n * @example Handling concurrency conflicts with retry\n * ```typescript\n * import { ConcurrencyError } from \"@rotorsoft/act\";\n *\n * async function transferWithRetry(from, to, amount, maxRetries = 3) {\n * for (let attempt = 0; attempt < maxRetries; attempt++) {\n * try {\n * await app.do(\"transfer\",\n * { stream: from, actor: currentUser },\n * { to, amount }\n * );\n * return { success: true };\n * } catch (error) {\n * if (error instanceof ConcurrencyError) {\n * if (attempt < maxRetries - 1) {\n * console.log(`Concurrent modification detected, retrying... (${attempt + 1}/${maxRetries})`);\n * await sleep(100 * Math.pow(2, attempt)); // Exponential backoff\n * continue;\n * }\n * }\n * throw error;\n * }\n * }\n * return { success: false, reason: \"Too many concurrent modifications\" };\n * }\n * ```\n *\n * @see {@link Store.commit} for version checking details\n */\nexport class ConcurrencyError extends Error {\n /** The stream that had the concurrent modification */\n public readonly stream: string;\n /** The actual current version in the store */\n public readonly lastVersion: number;\n /** The events that were being committed */\n public readonly events: Message<Schemas, keyof Schemas>[];\n /** The version number that was expected */\n public readonly expectedVersion: number;\n\n constructor(\n stream: string,\n lastVersion: number,\n events: Message<Schemas, keyof Schemas>[],\n expectedVersion: number\n ) {\n // Message lists stream + event names only. Payloads remain accessible\n // via `error.events` for callers who need them — keeping them out of\n // the message avoids MB-scale strings on contended writes and keeps\n // potentially-sensitive data out of log streams.\n super(\n `Concurrency error committing \"${events\n .map((e) => `${stream}.${e.name}`)\n .join(\n \", \"\n )}\". Expected version ${expectedVersion} but found version ${lastVersion}.`\n );\n this.name = Errors.ConcurrencyError;\n this.stream = stream;\n this.lastVersion = lastVersion;\n this.events = events;\n this.expectedVersion = expectedVersion;\n }\n}\n\n/**\n * Thrown when attempting to write to a stream that has been closed\n * with a tombstone event.\n *\n * A tombstoned stream is permanently closed — no further actions can\n * be executed against it. The only way to reopen a tombstoned stream\n * is through `Act.close()` with a `restart` callback.\n *\n * @example\n * ```typescript\n * import { StreamClosedError } from \"@rotorsoft/act\";\n *\n * try {\n * await app.do(\"updateTicket\", target, payload);\n * } catch (error) {\n * if (error instanceof StreamClosedError) {\n * console.error(`Stream ${error.stream} is closed`);\n * }\n * }\n * ```\n *\n * @see {@link Act.close} for closing streams\n */\nexport class StreamClosedError extends Error {\n /** The stream that is closed */\n public readonly stream: string;\n\n constructor(stream: string) {\n super(`Stream \"${stream}\" is closed (tombstoned)`);\n this.name = Errors.StreamClosedError;\n this.stream = stream;\n }\n}\n\n/**\n * Thrown by a {@link Store} adapter when an infrastructure operation fails\n * for a reason that is *not* a domain condition — a dropped connection, a\n * transaction rollback, a query timeout. It is the typed boundary between\n * \"the store is unavailable/degraded\" and the domain errors above\n * ({@link ConcurrencyError}, {@link StreamClosedError}), which describe\n * legitimate outcomes the caller should branch on.\n *\n * Adapters wrap their driver errors in `StoreError` (preserving the\n * original via `cause`) so the orchestrator can distinguish a degraded\n * backend from \"no work\" and react accordingly — see the drain circuit\n * breaker, which trips on repeated `StoreError`s and surfaces an\n * `error` lifecycle event instead of silently spinning on a down\n * database.\n *\n * @example\n * ```typescript\n * app.on(\"error\", ({ error, circuit }) => {\n * if (error instanceof StoreError)\n * alert(`store ${error.operation} failing; circuit=${circuit}`);\n * });\n * ```\n */\nexport class StoreError extends Error {\n /** The store operation that failed (e.g. `\"claim\"`, `\"ack\"`, `\"commit\"`). */\n public readonly operation: string;\n\n constructor(operation: string, options?: { cause?: unknown }) {\n super(`Store operation \"${operation}\" failed`, options);\n this.name = Errors.StoreError;\n this.operation = operation;\n }\n}\n\n/**\n * Thrown by a reaction handler to signal that the failure is permanent\n * and the drain pipeline should block the stream immediately, without\n * consuming the rest of the `maxRetries` budget.\n *\n * The drain finalizer detects `instanceof NonRetryableError` and forces\n * `block = options.blockOnError` regardless of `lease.retry`. When\n * `blockOnError` is `false`, behavior is unchanged (drain keeps retrying\n * forever) — the class never overrides the operator's explicit \"never\n * block\" choice.\n *\n * Use this for failures the handler *knows* won't get better on retry:\n * a 4xx from a webhook, a `ZodError` on malformed input, a \"user\n * deleted\" 404 from a downstream API. Use regular `Error` (or a\n * subclass) for transient failures so the existing retry-with-backoff\n * loop applies.\n *\n * @example Wrapping a permanent downstream error\n * ```typescript\n * import { NonRetryableError } from \"@rotorsoft/act\";\n *\n * .on(\"OrderConfirmed\")\n * .do(async function notifyPartner(event) {\n * const res = await fetch(url, ...);\n * if (res.status >= 400 && res.status < 500) {\n * throw new NonRetryableError(\n * `webhook ${url} responded ${res.status}`,\n * { cause: await res.text() }\n * );\n * }\n * if (!res.ok) throw new Error(`webhook ${url} responded ${res.status}`);\n * })\n * ```\n */\nexport class NonRetryableError extends Error {\n /** The original failure, if any. Mirrors the standard `Error.cause` shape. */\n public override readonly cause?: unknown;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message);\n this.name = Errors.NonRetryableError;\n this.cause = options?.cause;\n }\n}\n","import { type ZodObject, type ZodRawShape, z } from \"zod\";\n// Deep-path import (vs `../internal/index.js`) is deliberate — `_registry` is\n// a side-effect-free leaf, and going through the internal barrel would pull\n// tracing.ts → config.ts in at type-schema load time and crash on TDZ when a\n// test imports a public schema before config is initialized.\nimport { _mark_sensitive, _registry } from \"../internal/sensitive.js\";\n\n/**\n * @packageDocumentation\n * @module act/types\n * @category Types\n * Zod schemas and helpers for the Act Framework.\n */\n\n/**\n * An empty Zod schema (no properties).\n */\nexport const ZodEmpty = z.record(z.string(), z.never());\n\n/**\n * Sensitive-data foundation re-exports.\n *\n * - `REDACTED` / `SHREDDED` — sentinels placed in `event.data[field]`\n * when the caller isn't authorized to see a sensitive field\n * (`.discloses(predicate)` returned `false` or none was declared —\n * recoverable) or the underlying PII was wiped (`Store.forget_pii` —\n * irrecoverable).\n * top-level field names marked via {@link sensitive}. A pure,\n * read-only helper that inspects the out-of-band sensitive registry (a\n * process-global `WeakMap`) `sensitive()` populates, otherwise\n * unreachable from outside the package. Surfaced for adapters and\n * tooling that must reflect input sensitivity on their own wire\n * surface — e.g. the `@rotorsoft/act-http/openapi` emitter marks these\n * fields `writeOnly` + `format: password` so generated clients and\n * Swagger UI don't echo PII freely. Returns `[]` for non-object\n * schemas or objects with no sensitive fields; top-level shape only.\n */\nexport { pii_fields, REDACTED, SHREDDED } from \"../internal/sensitive.js\";\n\n/**\n * Mark a Zod schema as sensitive. Returns the same schema instance — the\n * marker is registered out-of-band so the static type is preserved and the\n * call site reads as a pure annotation.\n *\n * Idempotent: re-wrapping an already-sensitive schema is a no-op.\n *\n * The marker is what the orchestrator inspects to split event payloads into\n * `data` + `pii` on commit, gate reads via `.discloses`, and strip handler\n * payloads. Part of the sensitive-data foundation.\n *\n * @example\n * ```ts\n * import { z } from \"zod\";\n * import { state, sensitive } from \"@rotorsoft/act\";\n *\n * const UserRegistered = z.object({\n * email: sensitive(z.string()),\n * name: sensitive(z.string()),\n * plan: z.enum([\"free\", \"pro\"]), // not sensitive — stays in events.data\n * });\n * ```\n *\n * @param schema - The Zod schema to mark sensitive.\n * @returns The same schema instance, unmodified at the type level.\n */\nexport function sensitive<T extends z.ZodType>(schema: T): T {\n _registry.add(schema, { sensitive: true });\n // Also stamp the def, so the marker survives the clone Zod produces for\n // any refinement chained AFTER this call — `sensitive(z.string()).min(1)`\n // used to lose it silently and write plaintext into `events.data`.\n _mark_sensitive(schema);\n return schema;\n}\n\n/**\n * Zod schema for an actor (user, system, etc.).\n */\nexport const ActorSchema = z\n .object({\n id: z.string(),\n name: z.string(),\n })\n .loose()\n .readonly();\n\n/**\n * Zod schema for a target (stream and actor info).\n */\nexport const TargetSchema = z\n .object({\n stream: z.string(),\n actor: ActorSchema,\n expectedVersion: z.number().optional(),\n })\n .loose()\n .readonly();\n\n/**\n * Zod schema for causation event metadata.\n */\nexport const CausationEventSchema = z.object({\n id: z.number(),\n name: z.string(),\n stream: z.string(),\n});\n\n/**\n * Zod schema for event metadata (correlation and causation).\n */\nexport const EventMetaSchema = z\n .object({\n correlation: z.string(),\n causation: z.object({\n action: TargetSchema.and(z.object({ name: z.string() })).optional(),\n event: CausationEventSchema.optional(),\n }),\n })\n .readonly();\n\n/**\n * Zod schema for committed event metadata (id, stream, version, created, meta).\n */\nexport const CommittedMetaSchema = z\n .object({\n id: z.number(),\n stream: z.string(),\n version: z.number(),\n created: z.date(),\n meta: EventMetaSchema,\n })\n .readonly();\n\n/**\n * Type representing the full state schema for a domain.\n * @property events - Map of event names to Zod schemas.\n * @property actions - Map of action names to Zod schemas.\n * @property state - Zod schema for the state object.\n */\nexport type StateSchema = Readonly<{\n events: Record<string, ZodObject<ZodRawShape> | typeof ZodEmpty>;\n actions: Record<string, ZodObject<ZodRawShape> | typeof ZodEmpty>;\n state: ZodObject<ZodRawShape>;\n}>;\n\n/**\n * Query options for event store queries.\n */\nexport const QuerySchema = z\n .object({\n stream: z.string().optional(),\n names: z.string().array().optional(),\n before: z.number().optional(),\n after: z.number().optional(),\n limit: z.number().optional(),\n created_before: z.date().optional(),\n created_after: z.date().optional(),\n backward: z.boolean().optional(),\n correlation: z.string().optional(),\n with_snaps: z.boolean().optional(),\n with_pii: z.boolean().optional(),\n stream_exact: z.boolean().optional(),\n })\n .readonly();\n","/**\n * Internal mechanics for sensitive data: the registry the public\n * `sensitive(zodType)` (in `types/schemas.ts`) marks, and the helpers the\n * orchestrator calls during commit, load and handler dispatch to gate,\n * redact, shred or strip those fields.\n */\n\nimport { z } from \"zod\";\nimport type { Actor, Committed, Schemas } from \"../types/index.js\";\n\n/**\n * Sentinel placed in `event.data[field]` when the caller isn't authorized to\n * see the sensitive field — either `.discloses(predicate)` returned `false`,\n * or no predicate was declared (framework default-deny). Recoverable: a\n * properly-authorized read returns the plaintext.\n *\n * Re-exported from `types/schemas.ts` as part of the public surface.\n */\nexport const REDACTED = \"[REDACTED]\" as const;\n\n/**\n * Sentinel placed in `event.data[field]` when the underlying PII payload has\n * been wiped via `Store.forget_pii(stream)` — the row's pii column is `NULL`\n * and the original plaintext is gone forever. Irrecoverable.\n *\n * Re-exported from `types/schemas.ts` as part of the public surface.\n */\nexport const SHREDDED = \"[SHREDDED]\" as const;\n\n/**\n * Process-global registry holding every Zod schema marked sensitive. Backed\n * by a `WeakMap`, so wrapper-created instances (`.optional()`, `.nullable()`,\n * `.default()`) that chain off a marked schema produce *new* schema instances\n * the registry doesn't track; the field walker handles those via unwrap.\n *\n * Exported so the public `sensitive(zodType)` wrapper can call `_registry.add`.\n * Underscore prefix marks \"framework-private, don't touch from user code.\"\n */\nexport const _registry = z.registry<{ sensitive: true }>();\n\n/**\n * Marker key stamped onto a schema's own `def`. Zod clones a schema on every\n * refinement (`.min()`, `.email()`, `.trim()`, `.describe()`, `.refine()`,\n * `.transform()`, …) via `{...def}`, which copies own symbol keys — so a\n * marker on the def survives the whole chain, while the `_registry` WeakMap\n * (keyed on the *instance*) does not.\n *\n * The registry is still populated and still consulted: it covers schemas\n * marked before this key existed, and it is the mechanism the public\n * `sensitive()` doc-comment describes.\n */\nconst _SENSITIVE = Symbol.for(\"act.sensitive\");\n\n/**\n * Stamp the def-level marker. Called by the public `sensitive()` alongside\n * `_registry.add`.\n */\nexport function _mark_sensitive(schema: z.ZodType): void {\n const def = (\n schema as unknown as {\n _zod?: { def?: Record<PropertyKey, unknown> };\n }\n )._zod?.def;\n if (def) def[_SENSITIVE] = true;\n}\n\n/**\n * True when the given schema was marked via `sensitive(...)`.\n *\n * Walks through Zod wrapper layers (`.optional()`, `.nullable()`,\n * `.default()`, `.readonly()`) by following `_def.innerType` until it reaches\n * a non-wrapper schema, then checks the registry. Wrappers create new schema\n * instances; the marker lives on the *inner* schema the user wrapped, so we\n * test that one.\n */\nfunction is_pii(schema: z.ZodType): boolean {\n let cur: z.ZodType = schema;\n while (true) {\n if (_registry.has(cur)) return true;\n // Def-level marker: survives the clone a refinement produces, which the\n // instance-keyed registry above cannot.\n const def = (\n cur as unknown as {\n _zod?: { def?: Record<PropertyKey, unknown> };\n }\n )._zod?.def;\n if (def?.[_SENSITIVE] === true) return true;\n const inner = (cur as { _def?: { innerType?: z.ZodType } })._def?.innerType;\n if (!inner || inner === cur) return false;\n cur = inner;\n }\n}\n\n/**\n * Derive an event's sensitive fields, as the declared schema of each.\n *\n * Walks the top-level shape of a `z.object({...})` and keeps the keys whose\n * schema (after unwrapping optional/nullable/default wrappers) was marked via\n * `sensitive(...)`. Returns an empty object for non-object schemas or events\n * with no sensitive fields — the common-case zero-cost path.\n *\n * Only the top-level shape is walked. Sensitive fields nested inside a\n * `z.object` declared inside the event payload would require recursive\n * descent; that's deferred until a real callsite needs it.\n *\n * A union event has no top-level shape, so the options are walked and merged:\n * a key sensitive in any variant must be split, because the stored payload\n * could be that variant.\n * The first variant to declare a key wins, which only matters to a caller that\n * wants the schema rather than the name.\n *\n * Returning the schemas rather than just the names is what lets a caller do\n * something per field — the event builder asks each one whether it holds a\n * date, so the `pii` sidecar's dates can be revived like any other.\n */\nexport function pii_schemas(schema: z.ZodType): Record<string, z.ZodType> {\n const shape = (schema as { shape?: Record<string, z.ZodType> }).shape;\n if (shape && typeof shape === \"object\") {\n const fields: Record<string, z.ZodType> = {};\n for (const key of Object.keys(shape))\n if (is_pii(shape[key])) fields[key] = shape[key];\n return fields;\n }\n const options = (schema as { options?: unknown }).options;\n if (Array.isArray(options)) {\n const fields: Record<string, z.ZodType> = {};\n for (const option of options)\n for (const [key, field] of Object.entries(\n pii_schemas(option as z.ZodType)\n ))\n fields[key] ??= field;\n return fields;\n }\n return {};\n}\n\n/**\n * The names of an event's sensitive fields — {@link pii_schemas} keyed.\n *\n * @internal — consumed by the registry's `sensitive_fields(event_name)` lookup,\n * and public through `types/schemas.ts`, where act-http's OpenAPI emitter uses\n * it to mark request-body properties `writeOnly`.\n */\nexport function pii_fields(schema: z.ZodType): readonly string[] {\n return Object.keys(pii_schemas(schema));\n}\n\n/**\n * Split an emitted event's `data` into `data` (non-sensitive) + `pii`\n * (sensitive) using the field list precomputed at build time. Used by the\n * State's `_pii_split` decorator just before `Store.commit`.\n *\n * Single forward pass over `Object.keys(validated)` — same shape as the\n * spread-and-delete-free implementation in slice 3, just hoisted out of the\n * orchestrator hot path so it's only invoked when the State actually has a\n * sensitive event.\n */\nexport function pii_split<TName, TData extends Record<string, unknown>>(\n emitted: { name: TName; data: TData },\n fields: readonly string[]\n): { name: TName; data: TData; pii: Record<string, unknown> } {\n const data = { ...emitted.data };\n const pii: Record<string, unknown> = {};\n for (const f of fields) {\n if (f in data) {\n pii[f] = data[f];\n delete data[f];\n }\n }\n return { name: emitted.name, data, pii };\n}\n\n/**\n * Build the **external view** of a committed event — the form returned by\n * `load()`, `query()`, `query_array()`, and the snapshot in `do()`'s reply.\n *\n * Only ever reached for events that declare sensitive fields — the sole caller\n * is {@link make_gate}, which the builder invokes exclusively for sensitive\n * events; non-sensitive events short-circuit to {@link IDENTITY_GATE} before\n * they get here. `fields` is therefore guaranteed non-empty (same contract as\n * {@link pii_strip}).\n *\n * - Event whose `pii` payload is null/undefined → substitute {@link SHREDDED}\n * for each declared field. Irrecoverable, so no predicate check.\n * - Event with a `pii` payload, predicate returns `true` → merge `pii` into\n * `data` (plaintext).\n * - Event with a `pii` payload, predicate returns `false` OR no predicate\n * declared (framework default-deny) → substitute {@link REDACTED} for each\n * declared field.\n */\nfunction pii_gate<TEvents extends Schemas, TKey extends keyof TEvents>(\n event: Committed<TEvents, TKey>,\n fields: readonly string[],\n predicate: ((event: any, actor: Actor) => boolean) | null,\n actor: Actor | undefined\n): Committed<TEvents, TKey> {\n const data = event.data as Record<string, unknown>;\n // The external view NEVER carries the isolated `pii` sidecar — dropping it\n // is the whole point of the gate. Keeping it (an earlier `...event` spread)\n // leaked plaintext PII on every gated read surface (`load`, `query`,\n // `query_array`) even while `data` was correctly redacted. Strip it\n // once here; the plaintext lives in `data` only on the authorized path.\n const { pii, ...rest } = event as Committed<TEvents, TKey> & {\n pii?: Record<string, unknown> | null;\n };\n if (pii == null) {\n const shredded: Record<string, unknown> = { ...data };\n for (const f of fields) shredded[f] = SHREDDED;\n return { ...rest, data: shredded as Committed<TEvents, TKey>[\"data\"] };\n }\n // Plaintext path requires both an actor AND a predicate that allows. Missing\n // either → default-deny → REDACTED.\n const allowed = !!actor && !!predicate && predicate(event, actor);\n if (allowed) {\n return {\n ...rest,\n data: { ...data, ...pii } as Committed<TEvents, TKey>[\"data\"],\n };\n }\n const redacted: Record<string, unknown> = { ...data };\n for (const f of fields) redacted[f] = REDACTED;\n return { ...rest, data: redacted as Committed<TEvents, TKey>[\"data\"] };\n}\n\n/**\n * A prebuilt per-event read gate: given a committed event and the reading\n * actor, return the caller-visible form. This is the single gating primitive\n * the builder prebuilds for **every** read surface — both the actor-less\n * `query` / `query_array` (which pass no actor → default-deny) and the\n * actor-aware `load` / `do`-return view (which pass the reader). Non-sensitive\n * events use the shared {@link IDENTITY_GATE}; sensitive events use a redactor\n * built by {@link make_gate} that closes over the field list and the state's\n * disclosure predicate, so the read path never recomputes the sensitive-field\n * lookup nor allocates per event.\n *\n * The `actor` is optional so the actor-less surfaces can call `gate(event)`.\n */\nexport type EventGate = <TEvents extends Schemas, TKey extends keyof TEvents>(\n event: Committed<TEvents, TKey>,\n actor?: Actor\n) => Committed<TEvents, TKey>;\n\n/**\n * Shared zero-cost gate for every event with no `sensitive(...)` fields — a\n * single frozen reference the builder hands back for non-sensitive events, so\n * the common path is one `Map` miss and an identity call, no allocation. This\n * is the \"by default, return the event\" half of the prebuilt per-event gate.\n */\nexport const IDENTITY_GATE: EventGate = (event) => event;\n\n/**\n * Prebuild a read gate for a sensitive event, capturing its field list and the\n * disclosure predicate once at build time. The returned closure defers to\n * {@link pii_gate} with the reading actor supplied per call:\n *\n * - `predicate = null` (the actor-less `query` surfaces, or a state that never\n * declared `.discloses`) → default-deny: declared fields come back\n * {@link REDACTED} (or {@link SHREDDED} once the pii column is forgotten).\n * - `predicate` set + an authorized actor → plaintext merged into `data`.\n *\n * Either way the isolated `pii` sidecar is dropped. The builder stores one gate\n * per sensitive event (per state for the load path; predicate-less for the\n * query path); non-sensitive events fall back to {@link IDENTITY_GATE}.\n */\nexport function make_gate(\n fields: readonly string[],\n predicate: ((event: any, actor: Actor) => boolean) | null\n): EventGate {\n return (event, actor) => pii_gate(event, fields, predicate, actor);\n}\n\n/**\n * Build the **handler view** — sensitive keys removed entirely from `data`\n * and the `pii` field dropped from the event. Used before invoking projection\n * handlers and reaction handlers, which never see PII by framework rule.\n *\n * Different from {@link pii_gate} (which substitutes {@link REDACTED} or\n * {@link SHREDDED}) — projection tables and reaction sinks shouldn't even\n * structurally observe the keys, so a handler that mistakenly writes\n * `event.data.email` into a column would get `undefined`, not a sentinel\n * string that looks like real data. The strictness is deliberate.\n *\n * Reactions that genuinely need PII (e.g. a welcome-email reaction reading\n * `email`) opt back in by explicitly calling `app.load(stream, { actor:\n * system_actor })` inside the handler — pulling PII through the gate at the\n * call site makes the security-relevant path visible in code review.\n */\nexport function pii_strip<\n TEvents extends Schemas,\n TKey extends keyof TEvents & string,\n>(\n event: Committed<TEvents, TKey>,\n fields: readonly string[]\n): Committed<TEvents, TKey> {\n // Contract: `fields` is non-empty. `build_handle` / `build_handle_batch`\n // filter on `fields.length > 0` before invocation.\n const data = event.data as Record<string, unknown>;\n const stripped: Record<string, unknown> = {};\n for (const k of Object.keys(data)) {\n if (!fields.includes(k)) stripped[k] = data[k];\n }\n const { pii: _drop_pii, ...rest } = event as Committed<TEvents, TKey> & {\n pii?: unknown;\n };\n return {\n ...rest,\n data: stripped as Committed<TEvents, TKey>[\"data\"],\n } as Committed<TEvents, TKey>;\n}\n","/**\n * @packageDocumentation\n * @module act/types\n * Barrel file for Act Framework core types.\n *\n * Re-exports all major type definitions for actions, errors, ports, reactions, registries, and schemas.\n * Also defines common environment and log level types/constants for configuration and logging.\n *\n * @remarks\n * Import from this module to access all core framework types in one place.\n */\nexport type * from \"./action.js\";\nexport type * from \"./audit.js\";\nexport * from \"./errors.js\";\nexport type * from \"./ports.js\";\nexport type * from \"./reaction.js\";\nexport type * from \"./registry.js\";\nexport * from \"./schemas.js\";\n\n/**\n * Supported runtime environments for the framework.\n * - `development`: Local development\n * - `test`: Automated testing\n * - `staging`: Pre-production\n * - `production`: Live/production\n */\nexport const Environments = [\n \"development\",\n \"test\",\n \"staging\",\n \"production\",\n] as const;\n\n/**\n * Type representing a valid environment string.\n */\nexport type Environment = (typeof Environments)[number];\n\n/**\n * Supported log levels for framework logging.\n * - `fatal`, `error`, `warn`, `info`, `debug`, `trace`\n */\nexport const LogLevels = [\n \"fatal\",\n \"error\",\n \"warn\",\n \"info\",\n \"debug\",\n \"trace\",\n] as const;\n\n/**\n * Type representing a valid log level string.\n */\nexport type LogLevel = (typeof LogLevels)[number];\n","import { prettifyError, ZodError, type ZodType } from \"zod\";\nimport { config } from \"./config.js\";\nimport { ValidationError } from \"./types/index.js\";\n\n/**\n * @module utils\n * @category Utilities\n *\n * Small utilities used across the framework:\n * - {@link validate} — parse a payload against a Zod schema, throwing\n * {@link ValidationError} on failure.\n * - {@link extend} — validate a source object and merge into defaults.\n * - {@link sleep} — async delay (default duration from `config().sleepMs`).\n */\n\n/**\n * Parse `payload` against `schema`, returning the validated value or throwing\n * a {@link ValidationError} with prettified Zod details. When `schema` is\n * omitted, returns `payload` unchanged. The framework calls this for every\n * `app.do()` action, every emitted event, and every state init.\n *\n * @example\n * ```typescript\n * const UserSchema = z.object({ email: z.string().email() });\n * const user = validate(\"User\", { email: \"alice@example.com\" }, UserSchema);\n * ```\n *\n * @see {@link ValidationError}\n */\nexport const validate = <S>(\n target: string,\n payload: Readonly<S>,\n schema?: ZodType<S>\n): Readonly<S> => {\n try {\n return schema ? schema.parse(payload) : payload;\n } catch (error) {\n if (error instanceof ZodError) {\n throw new ValidationError(target, payload, prettifyError(error));\n }\n throw new ValidationError(target, payload, error);\n }\n};\n\n/**\n * Validate `source` against `schema` and return a new object that merges\n * `source` over the optional `target` defaults. Used by {@link config} for\n * env-var-overrides-defaults patterns; safe to call elsewhere — it never\n * mutates `target`.\n *\n * @example\n * ```typescript\n * const schema = z.object({ host: z.string(), port: z.number() });\n * const cfg = extend({ port: 8080 }, schema, { host: \"localhost\", port: 80 });\n * // → { host: \"localhost\", port: 8080 }\n * ```\n *\n * @throws {@link ValidationError} if `source` fails the schema.\n */\nexport const extend = <\n S extends Record<string, unknown>,\n T extends Record<string, unknown>,\n>(\n source: Readonly<S>,\n schema: ZodType<S>,\n target?: Readonly<T>\n): Readonly<S & T> => {\n const value = validate(\"config\", source, schema);\n return { ...target, ...value } as Readonly<S & T>;\n};\n\n/**\n * Pause for `ms` milliseconds (or `config().sleepMs` when omitted — `100ms`\n * in dev, `0ms` in tests). Used by adapters to simulate async I/O.\n *\n * @example\n * ```typescript\n * await sleep(); // default delay from config\n * await sleep(500); // explicit 500ms\n * ```\n */\nexport async function sleep(ms?: number) {\n return new Promise((resolve) => setTimeout(resolve, ms ?? config().sleepMs));\n}\n\n/**\n * Regex metacharacters that, when present in a reaction `source`, make it a\n * pattern rather than a literal stream name. A source containing none of\n * these is a bare stream name — the common case — and every claim/fetch\n * site matches it by string equality on the store's stream index. A source\n * containing any of them is compiled as a RegExp and matched against\n * candidate streams with the caller's own anchoring (e.g. `^(A|B)$`).\n */\nconst SOURCE_METACHARACTERS = /[\\^$.*+?()[\\]{}|\\\\]/;\n\n/**\n * True when `source` is a **literal** stream name — it carries no regex\n * metacharacter, so every adapter treats it as an exact match. This is the\n * fast, index-friendly path and covers every autoclose/dynamic-resolver\n * source (bare stream names). A `false` return means the source is a\n * **pattern** (contains `^ $ . * + ? ( ) [ ] { } | \\`) and must be compiled\n * as a RegExp before matching — the shape the calculator's static\n * `source: \"^(A|B)$\"` reaction relies on.\n *\n * The single source of truth for literal-vs-pattern classification across\n * correlate (which decides what a source marks), the drain fetch path, and\n * the SQLite adapter (which rejects a non-portable pattern), so all three\n * agree on which sources take the exact path.\n *\n * @example\n * ```typescript\n * is_literal_source(\"Board\"); // → true (exact lookup)\n * is_literal_source(\"^(A|B)$\"); // → false (compile as RegExp)\n * ```\n */\nexport function is_literal_source(source: string): boolean {\n return !SOURCE_METACHARACTERS.test(source);\n}\n\n/**\n * Matches an ISO-8601 timestamp, the shape `JSON.stringify` produces for a\n * `Date`.\n *\n * @internal\n */\nconst ISO_8601 =\n /^(\\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])(\\.\\d+)?(Z|[+-][0-2][0-9]:[0-5][0-9])?$/;\n\n/**\n * Revive ISO-8601-shaped strings into `Date`s during `JSON.parse`.\n *\n * **The framework no longer uses this.** Dates are resolved from the declared\n * `z.date()` paths at build time and converted on read, so a field declared\n * `z.string()` keeps its string even when the value looks like a timestamp\n *. Adapters\n * return what they stored; typing is the orchestrator's job.\n *\n * Kept exported for host applications that parse Act JSON themselves and want\n * the old shape-based behaviour. New code should let the schema decide.\n *\n */\nexport const dateReviver = (_key: string, value: unknown): unknown =>\n typeof value === \"string\" && ISO_8601.test(value) ? new Date(value) : value;\n","/**\n * @module scoped\n * @category Internal\n *\n * Ambient execution context — every `AsyncLocalStorage` the framework owns\n * lives here, and so does every operation on one. No other module calls\n * `.run()` or `.getStore()`; they ask for a runner or a reader instead, so\n * this file is the single place to look at the abstraction.\n *\n * Two contexts:\n *\n * - **ports** — the active Act's store/cache bag, so `store()` / `cache()`\n * resolve per-Act rather than per-process. Installed by the\n * orchestrator via {@link make_run_scoped}, read by the port singletons\n * via {@link current_ports}.\n * - **reaction** — the event a handler is processing, so a dispatch made\n * anywhere inside that handler can thread `reactingTo` whichever `IAct`\n * reference made the call. Installed via {@link run_reacting},\n * read at the orchestrator boundary via {@link current_reacting}.\n *\n * Keeping the mechanics here keeps ambient state out of `internal/`, whose\n * modules are stateless implementations that receive what they need.\n *\n * @internal\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type {\n Actor,\n Cache,\n Committed,\n IAct,\n Schemas,\n Store,\n} from \"./types/index.js\";\n\n/** Per-Act ports bag. Both required together — a shared cache across stores would collide on stream keys. */\nexport type Scoped = {\n readonly store: Store;\n readonly cache: Cache;\n};\n\n/**\n * What an Act actually installs in its frame: the ports a caller passed,\n * plus per-Act settings that runtime code has to read from the *running*\n * Act rather than from whatever closure it was built in.\n *\n * `autoclose_window` is here because the autoclose reactions are\n * synthesized once into the shared registry and handed by reference to\n * every Act built from that builder, so a window captured at synthesis is\n * the first tenant's window for everyone. The frame is per-Act, so\n * reading it here is what makes the setting per-Act too.\n *\n * Wider than {@link Scoped} on purpose: `Scoped` types what a caller\n * *passes* through `ActOptions.scoped` and is public; this is what the\n * orchestrator *installs* and is not.\n *\n * @internal\n */\nexport type ActFrame = Scoped & {\n readonly autoclose_window?: {\n readonly start: number;\n readonly end: number;\n readonly timeZone: string;\n };\n};\n\n/**\n * AsyncLocalStorage carrying the active Act's ports.\n *\n * Exported for in-repo tooling that measures the context itself (the\n * scope-overhead bench). NOT public: `ports.ts` no longer re-exports it and\n * `index.ts` reaches this module only for the `Scoped` type, so it is not\n * importable from the package. Everything else uses the helpers below.\n */\nexport const scoped = new AsyncLocalStorage<ActFrame>();\n\n/**\n * The reaction currently running, as a box the handler can empty.\n *\n * A frame captured by work the handler started and did not await outlives the\n * handler and can never be unbound. The *frame* is unreclaimable, but the\n * *box inside it* is not: clearing `event` as the handler settles turns every\n * later read through that frame into \"no reaction\", without anyone having to\n * ask a second question.\n *\n * Not reachable from `index.ts`.\n */\ntype Reacting = { event: Committed<Schemas, string> | undefined };\n\nconst reacting = new AsyncLocalStorage<Reacting>();\n\n/**\n * Builds the runner an Act uses to enter its own port scope.\n *\n * Every Act gets a frame, including one built without `ActOptions.scoped` —\n * that one carries the singleton adapters (see `default_scope` in `ports.ts`).\n * Entering unconditionally is what makes an Act's ports its own: a runner that\n * collapsed to `fn()` for a singleton Act did not leave whatever frame it was\n * called from, so dispatching into a shared Act from inside a tenant's handler\n * resolved `store()` to that tenant and wrote the shared Act's events into the\n * tenant's log.\n *\n * @internal\n */\nexport function make_run_scoped(\n bag: ActFrame\n): <T>(fn: () => Promise<T>) => Promise<T> {\n return (fn) => scoped.run(bag, fn);\n}\n\n/**\n * The running Act's off-hours autoclose window, or `undefined` when it\n * declared none (or when read outside any Act).\n *\n * Read at resolution time rather than captured at synthesis: the autoclose\n * reactions belong to the shared registry, and only the frame knows which\n * Act is running them.\n *\n * @internal\n */\nexport function current_autoclose_window(): ActFrame[\"autoclose_window\"] {\n return scoped.getStore()?.autoclose_window;\n}\n\n/**\n * The active Act's ports, or `undefined` outside any Act.\n *\n * Every Act runs in a frame, so this is `undefined` only for a call made\n * outside one — `store()` and `cache()` fall back to the singleton adapters\n * there, which is what a bare `store()` in application setup expects.\n *\n * @internal\n */\nexport function current_ports(): Scoped | undefined {\n return scoped.getStore();\n}\n\n/**\n * Runs `fn` with `event` installed as the triggering-event context.\n *\n * Entered per payload rather than per lease: the context has to unwind with\n * the handler so it never reaches the drain cycle, and work a handler started\n * without awaiting has to resume into its own event's frame.\n *\n * @internal\n */\nfunction run_reacting<T>(\n event: Committed<Schemas, string>,\n fn: () => Promise<T>\n): Promise<T> {\n const box: Reacting = { event };\n return reacting.run(box, async () => {\n try {\n return await fn();\n } finally {\n // Anything still running keeps this frame; from here it reads empty.\n box.event = undefined;\n }\n });\n}\n\n/**\n * The event being reacted to, or `undefined` outside a running handler —\n * including inside work that outlived one.\n *\n * @internal\n */\nexport function current_reacting(): Committed<Schemas, string> | undefined {\n return reacting.getStore()?.event;\n}\n\n/**\n * Everything a reaction handler runs inside: the `IAct` facade it is handed\n * as its third argument, and the triggering-event context that every dispatch\n * made within it resolves — including one through a captured `app`.\n *\n * Built here rather than in the dispatcher so the dispatcher never has to\n * know how either half works; it receives this whole and calls it.\n *\n * @internal\n */\nexport type ReactionScope<\n TEvents extends Schemas,\n TActions extends Schemas,\n TActor extends Actor = Actor,\n> = {\n readonly app: IAct<TEvents, TActions, TActor>;\n readonly run: <T>(\n event: Committed<Schemas, string>,\n fn: () => Promise<T>\n ) => Promise<T>;\n};\n\n/**\n * Assembles the reaction scope from the orchestrator's bound `IAct` methods.\n *\n * @internal\n */\nexport function make_reaction_scope<\n TEvents extends Schemas,\n TActions extends Schemas,\n TActor extends Actor = Actor,\n>(\n app: IAct<TEvents, TActions, TActor>\n): ReactionScope<TEvents, TActions, TActor> {\n return { app, run: run_reacting };\n}\n","import { ConsoleLogger } from \"./adapters/console-logger.js\";\nimport { InMemoryCache } from \"./adapters/in-memory-cache.js\";\nimport { InMemoryStore } from \"./adapters/in-memory-store.js\";\nimport { config } from \"./config.js\";\nimport { register_disposer, run_disposers } from \"./disposers.js\";\nimport { current_ports, type Scoped } from \"./scoped.js\";\nimport type {\n Cache,\n Disposable,\n Disposer,\n Logger,\n Store,\n} from \"./types/index.js\";\n\n// `Scoped` is the type of the public `ActOptions.scoped` bag, so it stays\n// exported. The AsyncLocalStorage carrying it does not: it is a mechanism,\n// it was only ever reachable because `index.ts` star-exports this module,\n// and its own doc-comment already declared it internal.\nexport type { Scoped } from \"./scoped.js\";\n\n/**\n * Port/adapter infrastructure for the Act framework.\n *\n * All infrastructure concerns (logging, storage, caching) are managed as\n * singleton adapters injected via port functions. Each port follows the same\n * pattern: first call wins with a sensible default, optional adapter injection.\n *\n * - `log()` — structured logging (default: ConsoleLogger)\n * - `store()` — event persistence (default: InMemoryStore)\n * - `cache()` — state checkpoints (default: InMemoryCache)\n * - `dispose()` — register cleanup functions for graceful shutdown\n *\n * @module ports\n */\n\n/**\n * List of exit codes for process termination. Consumed by signal handlers\n * and {@link disposeAndExit}; not part of the user-facing surface.\n *\n * @internal\n */\nexport const ExitCodes = [\"ERROR\", \"EXIT\"] as const;\n\n/**\n * Type for allowed exit codes.\n *\n * - `\"ERROR\"` — abnormal termination (uncaught exception, unhandled rejection)\n * - `\"EXIT\"` — clean shutdown (SIGINT, SIGTERM, or manual trigger)\n *\n * @internal\n */\nexport type ExitCode = (typeof ExitCodes)[number];\n\n// ---------------------------------------------------------------------------\n// Port factory\n// ---------------------------------------------------------------------------\n\n/**\n * Factory function that creates or returns the injected adapter.\n * @internal\n */\ntype Injector<Port extends Disposable> = (adapter?: Port) => Port;\n\n/** Singleton adapter registry, keyed by injector function name. */\nconst adapters = new Map<string, Disposable>();\n\n/**\n * Creates a singleton port with optional adapter injection.\n *\n * The first call initializes the adapter (using the provided adapter or the\n * injector's default). Subsequent calls return the cached singleton. Adapters\n * are disposed in reverse registration order during {@link disposeAndExit}.\n *\n * @param injector - Named function that creates the default adapter\n * @returns Port function: call with no args to get the singleton, or pass an\n * adapter on the first call to override the default\n *\n * @example\n * ```typescript\n * const store = port(function store(adapter?: Store) {\n * return adapter || new InMemoryStore();\n * });\n * const s = store(); // InMemoryStore\n * ```\n */\nexport function port<Port extends Disposable>(injector: Injector<Port>) {\n return (adapter?: Port): Port => {\n if (!adapters.has(injector.name)) {\n const injected = injector(adapter);\n adapters.set(injector.name, injected);\n // log() is now in adapters (or this IS the log port we just registered),\n // so the recursive call resolves immediately. Routing through the logger\n // means level gating (e.g. silenced in tests at fatal) takes effect.\n log().info(`[act] + ${injector.name}:${injected.constructor.name}`);\n }\n return adapters.get(injector.name) as Port;\n };\n}\n\n// ---------------------------------------------------------------------------\n// Ports: log, store, cache\n// ---------------------------------------------------------------------------\n\n/**\n * Gets or injects the singleton logger.\n *\n * By default, Act uses a built-in {@link ConsoleLogger} that emits JSON lines\n * in production (compatible with GCP, AWS CloudWatch, Datadog) and colorized\n * output in development — zero external dependencies.\n *\n * For pino, inject a `PinoLogger` from `@rotorsoft/act-pino` before building\n * your application.\n *\n * @param adapter - Optional logger implementation to inject\n * @returns The singleton logger instance\n *\n * @example Default console logger\n * ```typescript\n * import { log } from \"@rotorsoft/act\";\n * const logger = log();\n * logger.info(\"Application started\");\n * ```\n *\n * @see {@link Logger} for the interface contract\n * @see {@link ConsoleLogger} for the default implementation\n */\nexport const log = port(function log(adapter?: Logger) {\n const cfg = config();\n return (\n adapter ||\n new ConsoleLogger({\n level: cfg.logLevel,\n pretty: cfg.env !== \"production\",\n })\n );\n});\n\n/**\n * Gets or injects the singleton event store.\n *\n * By default, Act uses an {@link InMemoryStore} suitable for development and\n * testing. For production, inject a persistent store like `PostgresStore` from\n * `@rotorsoft/act-pg` before building your application.\n *\n * **Important:** Store injection must happen before creating any Act instances.\n * Once set, the store cannot be changed without restarting the application.\n *\n * @param adapter - Optional store implementation to inject\n * @returns The singleton store instance\n *\n * @example Default in-memory store\n * ```typescript\n * import { store } from \"@rotorsoft/act\";\n * const s = store();\n * ```\n *\n * @see {@link Store} for the interface contract\n * @see {@link InMemoryStore} for the default implementation\n */\n// ALS check lives outside `port()` — its cache fires only once, so the\n// per-call branch on a scoped Act has to be in the public wrapper.\nconst _store = port(function store(adapter?: Store): Store {\n return adapter ?? new InMemoryStore();\n});\n\nexport const store = ((adapter?: Store): Store => {\n return current_ports()?.store ?? _store(adapter);\n}) as (adapter?: Store) => Store;\n\n/**\n * Gets or injects the singleton cache.\n *\n * By default, Act uses an {@link InMemoryCache} (LRU, maxSize 1000). For\n * distributed deployments, inject a Redis-backed cache before building your\n * application.\n *\n * @param adapter - Optional cache implementation to inject\n * @returns The singleton cache instance\n *\n * @see {@link Cache} for the interface contract\n * @see {@link InMemoryCache} for the default implementation\n */\nconst _cache = port(function cache(adapter?: Cache) {\n return adapter ?? new InMemoryCache();\n});\n\nexport const cache = ((adapter?: Cache): Cache => {\n return current_ports()?.cache ?? _cache(adapter);\n}) as (adapter?: Cache) => Cache;\n\n/**\n * The ports bag an Act without `ActOptions.scoped` runs in: the singleton\n * adapters, read through the same frame a scoped Act uses.\n *\n * Every Act entering a frame is what keeps its ports its own. Without one, a\n * shared Act called from inside a tenant's handler inherited that tenant's\n * frame and committed to the tenant's store.\n *\n * The properties are getters on purpose. The adapters are resolved lazily and\n * injected after `act().build()` in the normal case — `store(new PgStore())`\n * in application setup, or a test's `beforeEach` — so capturing them when the\n * bag is made would pin whatever existed at build time. They read the raw\n * resolvers rather than the public `store()`/`cache()`, which consult the\n * frame this bag *is* and would recurse.\n *\n * @internal\n */\nexport const default_scope = (): Scoped => DEFAULT_SCOPE;\n\nconst DEFAULT_SCOPE: Scoped = {\n get store() {\n return _store();\n },\n get cache() {\n return _cache();\n },\n};\n\n// ---------------------------------------------------------------------------\n// Disposal\n// ---------------------------------------------------------------------------\n\n/**\n * Registered cleanup functions live in `disposers.ts`, which holds\n * lifetime-bound entries weakly so registering never pins its target for the\n * process lifetime. The public surface here is unchanged.\n */\n\n/**\n * Disposes all registered adapters and disposers, then exits the process.\n *\n * Execution order:\n * 1. Custom disposers (registered via {@link dispose}) — in reverse order\n * 2. Port adapters (log, store, cache) — in reverse registration order\n * 3. Adapter registry is cleared\n * 4. Process exits (skipped in test environment)\n *\n * In production, `\"ERROR\"` exits are silently ignored to avoid crashing on\n * transient failures (e.g. an uncaught promise in a non-critical path).\n *\n * @param code - Exit code: `\"EXIT\"` for clean shutdown (exit 0),\n * `\"ERROR\"` for abnormal termination (exit 1)\n */\nexport async function disposeAndExit(code: ExitCode = \"EXIT\"): Promise<void> {\n if (code === \"ERROR\" && config().env === \"production\") {\n // Surface the swallow so incident triage can see it. Without this\n // log the framework looks unresponsive after an uncaught exception\n // in prod — exactly when operators most need a breadcrumb.\n log().warn(\n \"disposeAndExit('ERROR') ignored in production — process kept alive\"\n );\n return;\n }\n\n // Run sequentially in reverse registration order so a disposer can rely on\n // later-registered disposers (and adapters on later-registered adapters)\n // having already finished — Promise.all would race them.\n await run_disposers();\n for (const adapter of [...adapters.values()].reverse()) {\n await adapter.dispose();\n log().info(`[act] - ${adapter.constructor.name}`);\n }\n adapters.clear();\n config().env !== \"test\" && process.exit(code === \"ERROR\" ? 1 : 0);\n}\n\n/**\n * Registers a cleanup function for graceful shutdown.\n *\n * Disposers are called automatically on SIGINT, SIGTERM, uncaught exceptions,\n * and unhandled rejections. They execute in reverse registration order before\n * port adapters are disposed.\n *\n * @param disposer - Async function to call during cleanup. Omit to get a\n * reference to {@link disposeAndExit} without registering.\n * @returns Function to manually trigger disposal and exit\n *\n * @example\n * ```typescript\n * import { dispose } from \"@rotorsoft/act\";\n *\n * const db = connectDatabase();\n * dispose(async () => await db.close());\n *\n * // In tests\n * afterAll(async () => await dispose()());\n * ```\n *\n * @see {@link disposeAndExit} for the full shutdown sequence\n */\nexport function dispose(\n disposer?: Disposer\n): (code?: ExitCode) => Promise<void> {\n disposer && register_disposer(disposer);\n return disposeAndExit;\n}\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\n/**\n * Event name used internally for snapshot events in the event store.\n * Snapshot events store a full state checkpoint, enabling efficient cold-start\n * recovery without replaying the entire event stream.\n */\nexport const SNAP_EVENT = \"__snapshot__\";\n\n/**\n * Event name used internally for tombstone events in the event store.\n * A tombstone marks a stream as permanently closed — no further writes\n * are permitted until the stream is explicitly restarted via `close()`.\n *\n * @see {@link Act.close} for the close-the-books API\n */\nexport const TOMBSTONE_EVENT = \"__tombstone__\";\n\n/**\n * Name of the implicit lane every reaction lands in unless its `.to({lane})`\n * declaration says otherwise. Acts that don't call\n * `.withLane(...)` see only this lane, and behavior is identical to\n * pre-1103 single-controller drain.\n *\n * Persisted on `streams.lane` and threaded as the strict-typed default in\n * builder generics — `lane?: TLanes` always includes `\"default\"`.\n */\nexport const DEFAULT_LANE = \"default\";\n","/**\n * @packageDocumentation\n * @module act/adapters\n * In-memory event store adapter for development and tests.\n *\n * @category Adapters\n */\n\nimport { DEFAULT_LANE, SNAP_EVENT, TOMBSTONE_EVENT } from \"../ports.js\";\nimport { ConcurrencyError } from \"../types/errors.js\";\nimport type {\n BlockedLease,\n Committed,\n EventMeta,\n Lease,\n Message,\n Query,\n QueryStatsOptions,\n QueryStreams,\n QueryStreamsResult,\n Schema,\n Schemas,\n Store,\n StreamFilter,\n StreamPosition,\n StreamStats,\n SubscribeInput,\n} from \"../types/index.js\";\nimport { sleep } from \"../utils.js\";\n\n/** One subscription row: watermark, lease, retry and schedule. */\nclass InMemoryStream {\n readonly stream: string;\n readonly source: string | undefined;\n private _at = -1;\n private _retry = -1;\n private _blocked = false;\n private _error = \"\";\n private _leased_by: string | undefined = undefined;\n private _leased_until: Date | undefined = undefined;\n private _priority = 0;\n private _lane: string = DEFAULT_LANE;\n // While in the future, the stream is held out of `claim`.\n private _deferred_at: number | undefined = undefined;\n // Work mark; `undefined` = never correlated, so `claim` skips it.\n private _correlated_at: number | undefined = undefined;\n\n constructor(\n stream: string,\n source: string | undefined,\n priority = 0,\n lane: string = DEFAULT_LANE\n ) {\n this.stream = stream;\n this.source = source;\n this._priority = priority;\n this._lane = lane;\n }\n\n get priority() {\n return this._priority;\n }\n\n get lane() {\n return this._lane;\n }\n\n /** Replaced on every subscribe, so the current config wins on restart. */\n set lane(value: string) {\n this._lane = value;\n }\n\n bump_priority(priority: number) {\n if (priority > this._priority) this._priority = priority;\n }\n\n get correlated_at() {\n return this._correlated_at;\n }\n\n /** A mark never regresses, including at zero and negatives. */\n mark(correlated_at: number) {\n if (\n this._correlated_at === undefined ||\n correlated_at > this._correlated_at\n )\n this._correlated_at = correlated_at;\n }\n\n /** Operator override; ignores the subscribe-time `max()`. */\n set_priority(priority: number) {\n this._priority = priority;\n }\n\n get is_available() {\n return (\n !this._blocked &&\n (!this._leased_until || this._leased_until <= new Date()) &&\n (!this._deferred_at || this._deferred_at <= Date.now())\n );\n }\n\n defer(deferred_at: number) {\n this._deferred_at = deferred_at;\n // A defer is not a failure, so the redelivery is a fresh attempt.\n this._retry = -1;\n }\n\n get at() {\n return this._at;\n }\n\n get retry() {\n return this._retry;\n }\n\n get blocked() {\n return this._blocked;\n }\n\n get error() {\n return this._error;\n }\n\n get leased_by() {\n return this._leased_by;\n }\n\n get leased_until() {\n return this._leased_until;\n }\n\n get deferred_at() {\n return this._deferred_at;\n }\n\n lease(lease: Lease, millis: number): Lease {\n // The holder is recorded even at zero `millis`: `ack` is gated on it,\n // so a lease with no holder would drop every ack.\n this._leased_by = lease.by;\n this._leased_until = new Date(Date.now() + millis);\n this._retry = this._retry + 1;\n return {\n stream: this.stream,\n source: this.source,\n at: lease.at,\n by: lease.by,\n retry: this._retry,\n lagging: lease.lagging,\n lane: this._lane,\n };\n }\n\n /** Ack, or with `due`, also persist the schedule. See {@link Store.ack}. */\n ack(lease: Lease) {\n if (this._leased_by === lease.by) {\n this._leased_by = undefined;\n this._leased_until = undefined;\n if (lease.due !== undefined) {\n // Advance past the handled prefix and schedule the re-visit with the\n // caller's retry (-1 for a defer, the climbing count for a backoff).\n this._at = lease.at;\n this._retry = lease.retry;\n this._deferred_at = lease.due;\n return undefined;\n }\n this._retry = -1;\n this._at = lease.at;\n this._deferred_at = undefined;\n return {\n stream: this.stream,\n source: this.source,\n at: this._at,\n by: lease.by,\n retry: this._retry,\n lagging: lease.lagging,\n lane: this._lane,\n };\n }\n }\n\n block(lease: Lease, error: string) {\n // Re-blocking is a no-op, like the SQL `AND blocked = false` guard.\n if (this._leased_by === lease.by && !this._blocked) {\n this._blocked = true;\n this._error = error;\n this._deferred_at = undefined;\n return {\n stream: this.stream,\n source: this.source,\n at: this._at,\n by: this._leased_by,\n retry: this._retry,\n error: this._error,\n lagging: lease.lagging,\n lane: this._lane,\n };\n }\n }\n\n /** Retry resets to -1 (released); the next claim makes it 0. */\n reset() {\n this._at = -1;\n this._retry = -1;\n this._blocked = false;\n this._error = \"\";\n this._leased_by = undefined;\n this._leased_until = undefined;\n this._deferred_at = undefined;\n }\n\n /** True only when the stream was blocked. */\n unblock(): boolean {\n if (!this._blocked) return false;\n this._blocked = false;\n this._retry = -1;\n this._error = \"\";\n this._leased_by = undefined;\n this._leased_until = undefined;\n this._deferred_at = undefined;\n return true;\n }\n}\n\n/**\n * In-memory event store: the default when no other store is injected.\n * For development, tests and examples; all data is lost when the process\n * exits. Use {@link PostgresStore} in production.\n *\n * `Store.notify` is not implemented: a single process has no remote writer\n * to hear from, and local commits already arm the drain.\n *\n * @example Using in tests\n * ```typescript\n * import { store } from \"@rotorsoft/act\";\n *\n * describe(\"Counter\", () => {\n * beforeEach(async () => {\n * // Reset store between tests\n * await store().seed();\n * });\n *\n * it(\"increments\", async () => {\n * await app.do(\"increment\", target, { by: 5 });\n * const snapshot = await app.load(Counter, \"counter-1\");\n * expect(snapshot.state.count).toBe(5);\n * });\n * });\n * ```\n *\n * @see {@link Store} for the interface definition\n * @see {@link PostgresStore} for production use\n * @see {@link store} for injecting stores\n *\n * @category Adapters\n */\nexport class InMemoryStore implements Store {\n private _events: Committed<Schemas, keyof Schemas>[] = [];\n // Never reused. Deletions punch holes, so ids are not array indexes.\n private _next_id = 0;\n private _streams: Map<string, InMemoryStream> = new Map();\n /** Correlate checkpoint: how far the log has been READ. */\n private _correlated_at = -1;\n /** Per-correlator checkpoint and lease; keyless callers use `_correlated_at`. */\n private _correlators = new Map<\n string,\n { at: number; by: string; until: number }\n >();\n private _stream_versions: Map<string, number> = new Map();\n // stream → (event_id → cloned pii). Two levels so `forget_pii` drops one\n // inner Map. Absence means no PII.\n private _pii: Map<string, Map<number, Record<string, unknown>>> = new Map();\n\n private _reset_indexes() {\n this._events.length = 0;\n this._next_id = 0;\n this._correlated_at = -1;\n this._stream_versions.clear();\n this._pii.clear();\n }\n\n // Stores a cloned copy, so caller-side mutation can't reach it.\n private _put_pii(stream: string, id: number, pii: Record<string, unknown>) {\n let per_stream = this._pii.get(stream);\n if (!per_stream) {\n per_stream = new Map();\n this._pii.set(stream, per_stream);\n }\n per_stream.set(id, structuredClone(pii));\n }\n\n // First index whose id is greater than `after` (ids are sorted, not dense).\n private _first_index_after(after: number): number {\n let lo = 0;\n let hi = this._events.length;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (this._events[mid].id > after) hi = mid;\n else lo = mid + 1;\n }\n return lo;\n }\n\n // Allocation-free for events without PII, the common case.\n private _with_pii<E extends Schemas>(\n e: Committed<E, keyof E>,\n wanted = true\n ): Committed<E, keyof E> {\n if (!wanted) return e;\n const pii = this._pii.get(e.stream)?.get(e.id);\n return pii ? ({ ...e, pii } as Committed<E, keyof E>) : e;\n }\n\n async dispose() {\n await sleep();\n this._reset_indexes();\n }\n\n async seed() {\n await sleep();\n }\n\n async drop() {\n await sleep();\n this._reset_indexes();\n this._streams = new Map();\n }\n\n private in_query<E extends Schemas>(\n query: Query,\n e: Committed<E, keyof E>\n ): boolean {\n if (query.stream && !this._stream_matches(query.stream, query, e.stream))\n return false;\n if (query.names && !query.names.includes(e.name as string)) return false;\n if (query.correlation && e.meta?.correlation !== query.correlation)\n return false;\n if (e.name === SNAP_EVENT && !query.with_snaps) return false;\n // `created` is not monotonic with `id` (restore keeps it), so time\n // bounds filter; they never end the scan.\n if (query.created_after && e.created <= query.created_after) return false;\n if (query.created_before && e.created >= query.created_before) return false;\n return true;\n }\n\n private _stream_matches(pattern: string, query: Query, stream: string) {\n return query.stream_exact\n ? stream === pattern\n : RegExp(pattern).test(stream);\n }\n\n /** Index of the stream's latest snapshot, or -1; an explicit `after` wins. */\n private _snap_floor(query: Query | undefined): number {\n if (\n !query?.with_snaps ||\n !query.stream_exact ||\n query.stream === undefined ||\n query.after !== undefined\n )\n return -1;\n for (let j = this._events.length - 1; j >= 0; j--) {\n const e = this._events[j];\n if (e.stream === query.stream && e.name === SNAP_EVENT) return j;\n }\n return -1;\n }\n\n async query<E extends Schemas>(\n callback: (event: Committed<E, keyof E>) => void,\n query?: Query\n ) {\n await sleep();\n // The id bounds (`after`, `before`, the snapshot floor) are one index\n // window over the id-ordered log; every other filter is per event.\n const floor = this._snap_floor(query);\n const lo = floor >= 0 ? floor : this._first_index_after(query?.after ?? -1);\n const hi =\n query?.before !== undefined\n ? this._first_index_after(query.before - 1)\n : this._events.length;\n const with_pii = query?.with_pii !== false;\n let count = 0;\n for (let k = 0; k < hi - lo; k++) {\n const e = this._events[query?.backward ? hi - 1 - k : lo + k];\n if (query && !this.in_query(query, e)) continue;\n await Promise.resolve(\n callback(this._with_pii(e as Committed<E, keyof E>, with_pii))\n );\n count++;\n if (query?.limit && count >= query.limit) break;\n }\n return count;\n }\n\n async commit<E extends Schemas>(\n stream: string,\n msgs: Message<E, keyof E>[],\n meta: EventMeta,\n expectedVersion?: number\n ) {\n await sleep();\n const current_version = this._stream_versions.get(stream) ?? -1;\n if (\n typeof expectedVersion === \"number\" &&\n current_version !== expectedVersion\n ) {\n throw new ConcurrencyError(\n stream,\n current_version,\n msgs as Message<Schemas, keyof Schemas>[],\n expectedVersion\n );\n }\n\n let version = current_version + 1;\n const committed = msgs.map(({ name, data, pii }) => {\n const c: Committed<E, keyof E> = {\n id: this._next_id++,\n stream,\n version,\n created: new Date(),\n name,\n data,\n meta,\n };\n // Stored pii-less, so `forget_pii` never touches the event row.\n this._events.push(c as Committed<Schemas, keyof Schemas>);\n if (pii != null) this._put_pii(stream, c.id, pii);\n version++;\n return this._with_pii(c);\n });\n this._stream_versions.set(stream, version - 1);\n return committed;\n }\n\n async claim(\n lagging: number,\n leading: number,\n by: string,\n millis: number,\n lane?: string\n ) {\n await sleep();\n // Eligibility is `at < correlated_at` on the row alone; the event log\n // is never read. An unmarked row is not claimable.\n const has_work = (s: InMemoryStream): boolean =>\n s.correlated_at !== undefined && s.at < s.correlated_at;\n const available = [...this._streams.values()].filter(\n (s) =>\n s.is_available && has_work(s) && (lane === undefined || s.lane === lane)\n );\n // Lagging: priority DESC, then watermark ASC, like the PG SQL. The\n // `fair` slots ignore priority so sustained high-priority load can't\n // starve a default-priority stream.\n const fair = lagging >= 2 ? Math.max(1, Math.floor(lagging / 4)) : 0;\n const by_priority = [...available].sort(\n (a, b) => b.priority - a.priority || a.at - b.at\n );\n const priority_slice = by_priority.slice(0, lagging - fair);\n const picked = new Set(priority_slice.map((s) => s.stream));\n const fair_slice = [...available]\n .sort((a, b) => a.at - b.at)\n .filter((s) => !picked.has(s.stream))\n .slice(0, fair);\n const lag = [...priority_slice, ...fair_slice].map((s) => ({\n stream: s.stream,\n source: s.source,\n at: s.at,\n lagging: true,\n }));\n const lead = available\n .sort((a, b) => b.at - a.at)\n .slice(0, leading)\n .map((s) => ({\n stream: s.stream,\n source: s.source,\n at: s.at,\n lagging: false,\n }));\n const seen = new Set<string>();\n const combined = [...lag, ...lead].filter((p) => {\n if (seen.has(p.stream)) return false;\n seen.add(p.stream);\n return true;\n });\n return combined\n .map((p) =>\n this._streams.get(p.stream)?.lease({ ...p, by, retry: 0 }, millis)\n )\n .filter((l) => !!l);\n }\n\n async subscribe(\n streams: SubscribeInput[],\n correlated_at?: number,\n correlator?: { key: string; by: string; millis: number }\n ) {\n await sleep();\n\n // The checkpoint is monotonic. With a correlator, position and lease\n // are per key.\n let correlating: boolean | undefined;\n let keyed_at: number | undefined;\n if (correlator) {\n const now = Date.now();\n const held = this._correlators.get(correlator.key);\n // A key with no row yet inherits the shared position, so a new\n // correlator does not re-read history.\n const at = Math.max(held?.at ?? this._correlated_at, correlated_at ?? -1);\n keyed_at = at;\n if (!held || held.until < now || held.by === correlator.by) {\n correlating = true;\n this._correlators.set(correlator.key, {\n at,\n by: correlator.by,\n // Release outright, or a successor in the same ms is still refused.\n until: correlator.millis > 0 ? now + correlator.millis : 0,\n });\n } else {\n // Refused, but the position still advances: this caller may already\n // have scanned and marked.\n correlating = false;\n held.at = at;\n }\n // How far any correlator has read.\n if (correlated_at !== undefined && correlated_at > this._correlated_at)\n this._correlated_at = correlated_at;\n } else if (\n correlated_at !== undefined &&\n correlated_at > this._correlated_at\n )\n this._correlated_at = correlated_at;\n\n let subscribed = 0;\n for (const {\n stream,\n source,\n priority = 0,\n lane = DEFAULT_LANE,\n correlated_at,\n } of streams) {\n const existing = this._streams.get(stream);\n if (existing) {\n // The lane rides the priority max (compared before the bump), so a\n // lower-priority resolution can't re-lane the stream.\n if (priority >= existing.priority) existing.lane = lane;\n existing.bump_priority(priority);\n if (correlated_at !== undefined) existing.mark(correlated_at);\n } else {\n const created = new InMemoryStream(stream, source, priority, lane);\n if (correlated_at !== undefined) created.mark(correlated_at);\n this._streams.set(stream, created);\n subscribed++;\n }\n }\n let watermark = -1;\n for (const s of this._streams.values()) {\n if (s.at > watermark) watermark = s.at;\n }\n return {\n subscribed,\n watermark,\n correlated_at: keyed_at ?? this._correlated_at,\n ...(correlating === undefined ? {} : { correlating }),\n };\n }\n\n async ack(leases: Lease[]) {\n await sleep();\n // One synchronous pass: the in-memory form of the single transaction.\n return leases\n .map((l) => this._streams.get(l.stream)?.ack(l))\n .filter((l) => !!l);\n }\n\n async block(leases: BlockedLease[]) {\n await sleep();\n return leases\n .map((l) => this._streams.get(l.stream)?.block(l, l.error))\n .filter((l) => !!l);\n }\n\n async defer(input: string[] | StreamFilter, deferred_at: number) {\n await sleep();\n const selected = this._select(input);\n for (const s of selected) s.defer(deferred_at);\n return selected.length;\n }\n\n /** De-duplicated like the SQL `stream = ANY(...)`; unknown names skipped. */\n private _select(input: string[] | StreamFilter): InMemoryStream[] {\n if (Array.isArray(input))\n return [...new Set(input)]\n .map((name) => this._streams.get(name))\n .filter((s) => s !== undefined);\n return [...this._streams.values()].filter(this._filter_predicate(input));\n }\n\n private _filter_predicate(\n filter: StreamFilter\n ): (s: InMemoryStream) => boolean {\n const stream_re =\n filter.stream !== undefined && !filter.stream_exact\n ? new RegExp(filter.stream)\n : undefined;\n const source_re =\n filter.source !== undefined && !filter.source_exact\n ? new RegExp(filter.source)\n : undefined;\n return (s) => {\n if (filter.stream !== undefined) {\n if (\n filter.stream_exact\n ? s.stream !== filter.stream\n : !stream_re!.test(s.stream)\n )\n return false;\n }\n if (filter.source !== undefined) {\n if (s.source === undefined) return false;\n if (\n filter.source_exact\n ? s.source !== filter.source\n : !source_re!.test(s.source)\n )\n return false;\n }\n if (filter.blocked !== undefined && s.blocked !== filter.blocked)\n return false;\n if (filter.lane !== undefined && s.lane !== filter.lane) return false;\n return true;\n };\n }\n\n async reset(input: string[] | StreamFilter) {\n await sleep();\n const selected = this._select(input);\n for (const s of selected) s.reset();\n return selected.length;\n }\n\n async forget_pii(stream: string): Promise<number> {\n await sleep();\n const count = this._pii.get(stream)?.size ?? 0;\n this._pii.delete(stream);\n return count;\n }\n\n async unblock(input: string[] | StreamFilter) {\n await sleep();\n const selected = this._select(\n Array.isArray(input) ? input : { ...input, blocked: true }\n );\n return selected.filter((s) => s.unblock()).length;\n }\n\n async prioritize(filter: StreamFilter, priority: number) {\n await sleep();\n const changed = this._select(filter).filter((s) => s.priority !== priority);\n for (const s of changed) s.set_priority(priority);\n return changed.length;\n }\n\n async query_streams(\n callback: (position: StreamPosition) => void,\n query?: QueryStreams\n ): Promise<QueryStreamsResult> {\n await sleep();\n const limit = query?.limit ?? 100;\n const after = query?.after;\n const source_matches = query?.source_matches;\n const matches = this._filter_predicate(query ?? {});\n // Reverse-match: the stored `source` pattern must match a requested name.\n const reverse_cache = new Map<string, RegExp>();\n const reverse_match = (source: string): boolean => {\n let re = reverse_cache.get(source);\n if (!re) {\n re = new RegExp(source);\n reverse_cache.set(source, re);\n }\n return source_matches!.some((name) => re!.test(name));\n };\n\n // The default sort is code-unit order, which agrees with the `<=`\n // cursor and the SQL binary collation; `localeCompare` would not.\n const sorted = [...this._streams.keys()]\n .sort()\n .map((stream) => this._streams.get(stream) as InMemoryStream);\n\n let count = 0;\n for (const s of sorted) {\n if (after !== undefined && s.stream <= after) continue;\n if (!matches(s)) continue;\n if (source_matches !== undefined) {\n // No source consumes every stream, so it matches any name.\n if (s.source && !reverse_match(s.source)) continue;\n }\n // Before emitting, so `limit: 0` returns none.\n if (count >= limit) break;\n callback({\n stream: s.stream,\n source: s.source,\n at: s.at,\n retry: s.retry,\n blocked: s.blocked,\n error: s.error,\n priority: s.priority,\n leased_by: s.leased_by,\n leased_until: s.leased_until,\n lane: s.lane,\n deferred_at: s.deferred_at,\n correlated_at: s.correlated_at,\n });\n count++;\n }\n return { maxEventId: this._events.at(-1)?.id ?? -1, count };\n }\n\n async query_stats<E extends Schemas>(\n input: string[] | Pick<StreamFilter, \"stream\" | \"stream_exact\">,\n options?: QueryStatsOptions<E>\n ): Promise<Map<string, StreamStats<E>>> {\n await sleep();\n const exclude = new Set<string>(options?.exclude ?? []);\n const want_tail = options?.tail ?? false;\n const want_count = options?.count ?? false;\n const want_names = options?.names ?? false;\n const before = options?.before;\n const after = options?.after;\n const limit = options?.limit;\n\n const array_targets = Array.isArray(input) ? new Set(input) : null;\n const filter = Array.isArray(input) ? null : input;\n const stream_re =\n filter?.stream !== undefined && !filter.stream_exact\n ? new RegExp(filter.stream)\n : undefined;\n\n const scope_cache = new Map<string, boolean>();\n const in_scope = (stream: string): boolean => {\n const cached = scope_cache.get(stream);\n if (cached !== undefined) return cached;\n let ok = true;\n if (array_targets) {\n ok = array_targets.has(stream);\n } else if (filter?.stream !== undefined) {\n ok = filter.stream_exact\n ? stream === filter.stream\n : // stream_re set when stream is regex\n stream_re!.test(stream);\n }\n scope_cache.set(stream, ok);\n return ok;\n };\n\n type Acc = {\n head: Committed<Schemas, keyof Schemas>;\n tail?: Committed<Schemas, keyof Schemas>;\n count: number;\n names?: Record<string, number>;\n };\n const acc = new Map<string, Acc>();\n for (const e of this._events) {\n if (before !== undefined && e.id >= before) continue;\n if (!in_scope(e.stream)) continue;\n if (exclude.has(e.name as string)) continue;\n let a = acc.get(e.stream);\n if (!a) {\n a = { head: e, count: 0 };\n if (want_tail) a.tail = e;\n if (want_names) a.names = {};\n acc.set(e.stream, a);\n }\n a.head = e;\n a.count++;\n if (want_names) {\n const n = String(e.name);\n a.names![n] = (a.names![n] ?? 0) + 1;\n }\n }\n\n // Code-unit order, to agree with the `<=` cursor (see query_streams).\n const ordered = [...acc.keys()].sort();\n const out = new Map<string, StreamStats<E>>();\n for (const stream of ordered) {\n if (limit !== undefined && out.size >= limit) break;\n if (after !== undefined && stream <= after) continue;\n const a = acc.get(stream)!;\n const stats: {\n head: Committed<Schemas, keyof Schemas>;\n tail?: Committed<Schemas, keyof Schemas>;\n count?: number;\n names?: Record<string, number>;\n } = { head: a.head };\n if (want_tail) stats.tail = a.tail;\n if (want_count) stats.count = a.count;\n if (want_names) stats.names = a.names;\n out.set(stream, stats as StreamStats<E>);\n }\n return out;\n }\n\n async truncate(\n targets: Array<{\n stream: string;\n snapshot?: Schema;\n meta?: EventMeta;\n before?: Date;\n max_id?: number;\n }>\n ) {\n await sleep();\n const result = new Map<\n string,\n {\n deleted: number;\n committed: Committed<Schemas, keyof Schemas>;\n before?: Date;\n }\n >();\n\n const windowed = targets.filter((t) => t.before !== undefined);\n if (windowed.length) {\n const drop = new Set<number>();\n for (const { stream, before, max_id } of windowed) {\n let boundary: Committed<Schemas, keyof Schemas> | undefined;\n for (const e of this._events) {\n if (\n e.stream === stream &&\n e.name === SNAP_EVENT &&\n e.created < before! &&\n (max_id === undefined || e.id <= max_id) &&\n (!boundary || e.id > boundary.id)\n )\n boundary = e;\n }\n if (!boundary) continue; // no qualifying snapshot → no-op\n let deleted = 0;\n for (const e of this._events) {\n if (e.stream === stream && e.id < boundary.id) {\n drop.add(e.id);\n this._pii.get(stream)?.delete(e.id);\n deleted++;\n }\n }\n result.set(stream, { deleted, committed: boundary, before });\n }\n if (drop.size) this._events = this._events.filter((e) => !drop.has(e.id));\n }\n\n const full = targets.filter((t) => t.before === undefined);\n // Per target, like the SQL adapters, so a stream listed twice gets one seed.\n for (const { stream, snapshot, meta } of full) {\n let deleted = 0;\n this._events = this._events.filter((e) => {\n if (e.stream !== stream) return true;\n deleted++;\n return false;\n });\n // Subscriptions untouched; `seed()` reaps inert ones.\n this._stream_versions.delete(stream);\n this._pii.delete(stream);\n const event: Committed<Schemas, keyof Schemas> = {\n id: this._next_id++,\n stream,\n version: 0,\n created: new Date(),\n name: snapshot !== undefined ? SNAP_EVENT : TOMBSTONE_EVENT,\n data: snapshot ?? {},\n meta: meta ?? { correlation: \"\", causation: {} },\n };\n this._events.push(event);\n this._stream_versions.set(stream, 0);\n result.set(stream, { deleted, committed: event });\n }\n return result;\n }\n\n /** A throw inside the driver restores the captured state. Ids restart at 0. */\n async restore(\n driver: (\n callback: (event: Committed<Schemas, keyof Schemas>) => Promise<number>\n ) => Promise<void>\n ): Promise<void> {\n await sleep();\n const prev_events = this._events;\n const prev_next_id = this._next_id;\n const prev_streams = this._streams;\n const prev_stream_versions = this._stream_versions;\n const prev_pii = this._pii;\n const prev_correlated_at = this._correlated_at;\n const prev_correlators = new Map(\n [...this._correlators].map(([k, v]) => [k, { ...v }])\n );\n // Renumbered from 0, so checkpoints restart too; leases are kept.\n this._correlated_at = -1;\n for (const c of this._correlators.values()) c.at = -1;\n this._events = [];\n this._next_id = 0;\n this._streams = new Map();\n this._stream_versions = new Map();\n this._pii = new Map();\n try {\n await driver(async (event) => {\n const id = this._next_id++;\n // Split `pii` out like `commit`, so `forget_pii` erases restored PII.\n const { pii, ...rest } = event;\n const committed: Committed<Schemas, keyof Schemas> = { ...rest, id };\n this._events.push(committed);\n if (pii != null) this._put_pii(event.stream, id, pii);\n // Last event per stream wins.\n this._stream_versions.set(event.stream, event.version);\n return id;\n });\n } catch (err) {\n this._events = prev_events;\n this._next_id = prev_next_id;\n this._streams = prev_streams;\n this._stream_versions = prev_stream_versions;\n this._pii = prev_pii;\n this._correlated_at = prev_correlated_at;\n this._correlators = prev_correlators;\n throw err;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACA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I,cAAc;AACxE,QAAMD,OAAM,KAAK;AAEjB,QAAM,MAAM,QAAQ,MAAM;AAAA,IACxB,GAAG,QAAQ;AAAA,IACX,QAAQ,EAAE,OAAAA,QAAO,OAAAC,OAAM;AAAA,EACzB,CAAC;AAED,MAAI;AACJ,QAAM,UAAU,MAAqB;AACnC,QAAI,CAAC,WAAW;AACd,mBAAa,YAAY;AACvB,cAAO,IAAgD,SAAS;AAChE,cAAMD,OAAM,QAAQ;AACpB,cAAMC,OAAM,QAAQ;AAAA,MACtB,GAAG;AAAA,IACL;AACA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,KAAK,OAAAD,QAAO,OAAAC,QAAO,QAAQ;AACtC;AAgCO,SAAS,QACd,SACA,WAA2B,CAAC,GAC5B;AACA,SAAO,mBAAK,OAAsB;AAAA,IAChC,KAAK,OAEH,CAAC,GACD,QACG;AACH,YAAM,MAAM,MAAM,QAAQ,SAAS,QAAQ;AAC3C,UAAI;AACF,cAAM,IAAI,IAAI,GAAG;AAAA,MACnB,UAAE;AACA,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["import_zod","import_zod","import_zod","pkg","log","correlated_at","store","cache"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/act-root/act-root/libs/act/dist/test/index.cjs","../../src/test/sandbox.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACA;ACNA,gCAAqB;AAmDrB,MAAA,SAAsB,OAAA,CACpB,OAAA,EACA,QAAA,EAA0B,CAAC,CAAA,EACH;AACxB,EAAA,MAAM,MAAA,EAAQ,OAAA,CAAQ,MAAA,EAAQ,MAAM,OAAA,CAAQ,KAAA,CAAM,EAAA,EAAI,IAAI,oCAAA,CAAc,CAAA;AACxE,EAAA,MAAM,MAAA,EAAQ,OAAA,CAAQ,MAAA,EAAQ,MAAM,OAAA,CAAQ,KAAA,CAAM,EAAA,EAAI,IAAI,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","sourcesContent":[null,"import { test } from \"vitest\";\nimport type { Act } from \"../act.js\";\nimport { InMemoryCache } from \"../adapters/in-memory-cache.js\";\nimport { InMemoryStore } from \"../adapters/in-memory-store.js\";\nimport type { ActOptions, Cache, Store } from \"../types/index.js\";\nimport type { Sandbox, SandboxOptions } from \"../types/sandbox.js\";\n\n/**\n * Minimal structural shape — anything with a `.build()` that returns an\n * Act. Avoids the variance pitfalls of constraining on the full\n * `ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>`\n * generic when called across package boundaries.\n */\ntype AnyActBuilder<TApp> = {\n // `ActOptions<any>` rather than `ActOptions<string>` (the default) — a\n // builder narrowed to `ActOptions<\"default\">` would otherwise trip\n // function-parameter contravariance against `ActOptions<string>`. The\n // `any` only widens `onlyLanes`; the rest of the option shape\n // (`scoped`, `correlator`, `settleDebounceMs`, etc.) still type-checks\n // at the runtime call site below.\n build: (options?: ActOptions<any>) => TApp;\n};\n\n/**\n * Build a scoped Act bound to a fresh `{ store, cache }` bag.\n *\n * Intended for parallel-safe test isolation. Each call constructs new\n * ports (defaults to InMemoryStore + InMemoryCache), seeds the store,\n * builds the Act with `ActOptions.scoped`, and returns `{ app, store,\n * cache, dispose }`. The caller owns the lifecycle: `dispose()` performs\n * `app.shutdown()` followed by `store.dispose()` + `cache.dispose()`.\n *\n * Prefer {@link fixture} when fixture-style ergonomics fit; reach for\n * `sandbox` when you need explicit control (e.g., wiring inside\n * `beforeAll` rather than per-test, or two scoped Acts in one test, or\n * direct access to the store/cache handles).\n *\n * @example Per-test isolated Act with explicit dispose\n * ```ts\n * import { sandbox } from \"@rotorsoft/act/test\";\n *\n * const counterBuilder = act().withState(Counter);\n *\n * it(\"increments\", async () => {\n * const { app, dispose } = await sandbox(counterBuilder);\n * await app.do(\"increment\", { stream: \"c-1\", actor }, { by: 1 });\n * expect((await app.load(\"Counter\", \"c-1\")).state.count).toBe(1);\n * await dispose();\n * });\n * ```\n */\nexport async function sandbox<TApp>(\n builder: AnyActBuilder<TApp>,\n options: SandboxOptions = {}\n): Promise<Sandbox<TApp>> {\n const store = options.store ? await options.store() : new InMemoryStore();\n const cache = options.cache ? await options.cache() : new InMemoryCache();\n await store.seed();\n\n const app = builder.build({\n ...options.actOptions,\n scoped: { store, cache },\n });\n\n let _disposed: Promise<void> | undefined;\n const dispose = (): Promise<void> => {\n if (!_disposed) {\n _disposed = (async () => {\n await (app as unknown as Act<any, any, any, any, any>).shutdown();\n await store.dispose();\n await cache.dispose();\n })();\n }\n return _disposed;\n };\n\n return { app, store, cache, dispose };\n}\n\n/**\n * Vitest fixture wrapper around {@link sandbox}.\n *\n * Returns a `test` instance with an `app` fixture — each test gets a\n * fresh, isolated Act and vitest's fixture lifecycle runs the cleanup\n * automatically when the test completes.\n *\n * Works with `test.concurrent(...)` — every concurrent invocation\n * receives its own bag, so tests don't race on the singleton.\n *\n * For tests that also need direct access to the underlying `store` /\n * `cache` handles, use {@link sandbox} explicitly.\n *\n * @example Fixture-style — auto cleanup, parallel-safe\n * ```ts\n * import { fixture } from \"@rotorsoft/act/test\";\n *\n * const test = fixture(act().withState(Counter));\n *\n * test(\"increments\", async ({ app }) => {\n * await app.do(\"increment\", { stream: \"c-1\", actor }, { by: 1 });\n * expect((await app.load(\"Counter\", \"c-1\")).state.count).toBe(1);\n * });\n *\n * test.concurrent(\"isolated from concurrent peers\", async ({ app }) => {\n * // Each concurrent invocation gets its own store + cache — no\n * // singleton contention, no flake.\n * });\n * ```\n */\nexport function fixture<TApp>(\n builder: AnyActBuilder<TApp>,\n defaults: SandboxOptions = {}\n) {\n return test.extend<{ app: TApp }>({\n app: async (\n // biome-ignore lint/correctness/noEmptyPattern: vitest fixture API requires a destructured deps parameter\n {},\n use: (value: TApp) => Promise<void>\n ) => {\n const ctx = await sandbox(builder, defaults);\n try {\n await use(ctx.app);\n } finally {\n await ctx.dispose();\n }\n },\n });\n}\n"]}
|
package/dist/test/index.js
CHANGED
package/dist/test/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/sandbox.ts"],"sourcesContent":["import { test } from \"vitest\";\nimport type { Act
|
|
1
|
+
{"version":3,"sources":["../../src/test/sandbox.ts"],"sourcesContent":["import { test } from \"vitest\";\nimport type { Act } from \"../act.js\";\nimport { InMemoryCache } from \"../adapters/in-memory-cache.js\";\nimport { InMemoryStore } from \"../adapters/in-memory-store.js\";\nimport type { ActOptions, Cache, Store } from \"../types/index.js\";\nimport type { Sandbox, SandboxOptions } from \"../types/sandbox.js\";\n\n/**\n * Minimal structural shape — anything with a `.build()` that returns an\n * Act. Avoids the variance pitfalls of constraining on the full\n * `ActBuilder<TSchemaReg, TEvents, TActions, TStateMap, TActor>`\n * generic when called across package boundaries.\n */\ntype AnyActBuilder<TApp> = {\n // `ActOptions<any>` rather than `ActOptions<string>` (the default) — a\n // builder narrowed to `ActOptions<\"default\">` would otherwise trip\n // function-parameter contravariance against `ActOptions<string>`. The\n // `any` only widens `onlyLanes`; the rest of the option shape\n // (`scoped`, `correlator`, `settleDebounceMs`, etc.) still type-checks\n // at the runtime call site below.\n build: (options?: ActOptions<any>) => TApp;\n};\n\n/**\n * Build a scoped Act bound to a fresh `{ store, cache }` bag.\n *\n * Intended for parallel-safe test isolation. Each call constructs new\n * ports (defaults to InMemoryStore + InMemoryCache), seeds the store,\n * builds the Act with `ActOptions.scoped`, and returns `{ app, store,\n * cache, dispose }`. The caller owns the lifecycle: `dispose()` performs\n * `app.shutdown()` followed by `store.dispose()` + `cache.dispose()`.\n *\n * Prefer {@link fixture} when fixture-style ergonomics fit; reach for\n * `sandbox` when you need explicit control (e.g., wiring inside\n * `beforeAll` rather than per-test, or two scoped Acts in one test, or\n * direct access to the store/cache handles).\n *\n * @example Per-test isolated Act with explicit dispose\n * ```ts\n * import { sandbox } from \"@rotorsoft/act/test\";\n *\n * const counterBuilder = act().withState(Counter);\n *\n * it(\"increments\", async () => {\n * const { app, dispose } = await sandbox(counterBuilder);\n * await app.do(\"increment\", { stream: \"c-1\", actor }, { by: 1 });\n * expect((await app.load(\"Counter\", \"c-1\")).state.count).toBe(1);\n * await dispose();\n * });\n * ```\n */\nexport async function sandbox<TApp>(\n builder: AnyActBuilder<TApp>,\n options: SandboxOptions = {}\n): Promise<Sandbox<TApp>> {\n const store = options.store ? await options.store() : new InMemoryStore();\n const cache = options.cache ? await options.cache() : new InMemoryCache();\n await store.seed();\n\n const app = builder.build({\n ...options.actOptions,\n scoped: { store, cache },\n });\n\n let _disposed: Promise<void> | undefined;\n const dispose = (): Promise<void> => {\n if (!_disposed) {\n _disposed = (async () => {\n await (app as unknown as Act<any, any, any, any, any>).shutdown();\n await store.dispose();\n await cache.dispose();\n })();\n }\n return _disposed;\n };\n\n return { app, store, cache, dispose };\n}\n\n/**\n * Vitest fixture wrapper around {@link sandbox}.\n *\n * Returns a `test` instance with an `app` fixture — each test gets a\n * fresh, isolated Act and vitest's fixture lifecycle runs the cleanup\n * automatically when the test completes.\n *\n * Works with `test.concurrent(...)` — every concurrent invocation\n * receives its own bag, so tests don't race on the singleton.\n *\n * For tests that also need direct access to the underlying `store` /\n * `cache` handles, use {@link sandbox} explicitly.\n *\n * @example Fixture-style — auto cleanup, parallel-safe\n * ```ts\n * import { fixture } from \"@rotorsoft/act/test\";\n *\n * const test = fixture(act().withState(Counter));\n *\n * test(\"increments\", async ({ app }) => {\n * await app.do(\"increment\", { stream: \"c-1\", actor }, { by: 1 });\n * expect((await app.load(\"Counter\", \"c-1\")).state.count).toBe(1);\n * });\n *\n * test.concurrent(\"isolated from concurrent peers\", async ({ app }) => {\n * // Each concurrent invocation gets its own store + cache — no\n * // singleton contention, no flake.\n * });\n * ```\n */\nexport function fixture<TApp>(\n builder: AnyActBuilder<TApp>,\n defaults: SandboxOptions = {}\n) {\n return test.extend<{ app: TApp }>({\n app: async (\n // biome-ignore lint/correctness/noEmptyPattern: vitest fixture API requires a destructured deps parameter\n {},\n use: (value: TApp) => Promise<void>\n ) => {\n const ctx = await sandbox(builder, defaults);\n try {\n await use(ctx.app);\n } finally {\n await ctx.dispose();\n }\n },\n });\n}\n"],"mappings":";;;;;;;AAAA,SAAS,YAAY;AAmDrB,eAAsB,QACpB,SACA,UAA0B,CAAC,GACH;AACxB,QAAM,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,MAAM,IAAI,IAAI,cAAc;AACxE,QAAM,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,MAAM,IAAI,IAAI,cAAc;AACxE,QAAM,MAAM,KAAK;AAEjB,QAAM,MAAM,QAAQ,MAAM;AAAA,IACxB,GAAG,QAAQ;AAAA,IACX,QAAQ,EAAE,OAAO,MAAM;AAAA,EACzB,CAAC;AAED,MAAI;AACJ,QAAM,UAAU,MAAqB;AACnC,QAAI,CAAC,WAAW;AACd,mBAAa,YAAY;AACvB,cAAO,IAAgD,SAAS;AAChE,cAAM,MAAM,QAAQ;AACpB,cAAM,MAAM,QAAQ;AAAA,MACtB,GAAG;AAAA,IACL;AACA,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,KAAK,OAAO,OAAO,QAAQ;AACtC;AAgCO,SAAS,QACd,SACA,WAA2B,CAAC,GAC5B;AACA,SAAO,KAAK,OAAsB;AAAA,IAChC,KAAK,OAEH,CAAC,GACD,QACG;AACH,YAAM,MAAM,MAAM,QAAQ,SAAS,QAAQ;AAC3C,UAAI;AACF,cAAM,IAAI,IAAI,GAAG;AAAA,MACnB,UAAE;AACA,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
|