/** * `@nwire/container` — DI seam. * * The top-level entry exposes the `Container` contract + * binding metadata types only — zero awilix dependency. Libraries * that need the type contract but not the runtime import from here. * * `dummyContainer()` is a no-op container that throws a helpful * error on `resolve()` — used as a fallback for standalone wire * collections that aren't attached to a real app. * * The awilix-backed implementation lives at `@nwire/container/awilix`: * * import { createContainer } from "@nwire/container/awilix"; * * The split keeps awilix out of the dependency tree of any consumer * that just needs to type a container parameter. */ /** * One row per active registration, surfaced by `container.list()`. Studio * reads this through `.nwire/di.json` (emitted by `@nwire/scan`) to render * "what's in the container, and which file registered it?". */ export interface BindingEntry { readonly name: string; readonly kind: "singleton" | "transient" | "scoped"; readonly hasDispose: boolean; readonly hasCheck: boolean; } /** * Opt-in per-binding lifecycle + lifetime metadata. Plugins pass these * through `bind(name, factory, opts)` in their setup closures; the * container persists them so `dispose()` and `runChecks()` can drive them. */ export interface RegisterOptions { readonly dispose?: (value: T) => void | Promise; readonly check?: (value: T) => void | Promise; readonly lifetime?: "singleton" | "transient" | "scoped"; } /** One row of `runChecks()` output — pairs the binding name with its check result. */ export interface HealthResult { readonly name: string; readonly ok: boolean; readonly error?: unknown; readonly durationMs: number; } /** Anything that produces a T when called with no args (factory) or with cradle (deps-aware factory). */ type Factory = ((...args: any[]) => T) | (new (...args: any[]) => T); /** Accepted value shapes for `register()`. */ type Registrable = T | Factory; export interface Container { resolve(name: K): K extends keyof TCradle ? TCradle[K] : T; register(name: K, factory: K extends keyof TCradle ? Registrable : Registrable, opts?: RegisterOptions): void; readonly cradle: TCradle; createScope(): Container; has(name: keyof TCradle | (string & {})): boolean; list(): ReadonlyArray; dispose(): Promise; runChecks(): Promise; /** * Escape hatch — the underlying implementation handle (awilix container * for the canonical impl). Typed as `unknown` here so the top-level * contract carries no implementation dependency. */ readonly raw: unknown; } /** * `dummyContainer()` — a no-op container that throws on every `resolve` * with a clear message naming the missing binding and pointing at the * canonical `createContainer` import path. * * Used by `@nwire/endpoint` as the fallback `containerOf(wire)` result for * standalone wire collections that aren't attached to a real app, and by * libraries that just want a placeholder for tests. */ export declare function dummyContainer(): Container; export {};