import { d as Token, l as Provider, t as Container } from "./types-DHrRUW_I.mjs"; //#region src/adapters/next/types.d.ts /** * Minimal shape of React's `cache` function needed by the adapter. * * Passing it in keeps React out of di-craft's dependency graph while still * letting React/Next own the current request cache. * * @example * ```ts * import { cache } from "react"; * * createNextDi({ cache, providers }); * ``` */ type RequestCache = (factory: () => T) => () => T; /** * Options for `createNextDi`. */ type CreateNextDiOptions = { /** * Providers registered once in the root server container. */ readonly providers?: readonly Provider[]; /** * React render cache, imported from `react` in a Next server file. */ readonly cache: RequestCache; /** * Providers registered in each RSC render-scoped child container. */ readonly requestProviders?: () => readonly Provider[]; }; /** * Options for running work inside a fresh explicit child container. */ type RunWithRequestContainerOptions = { /** * Extra providers registered only for this manual request container. */ readonly providers?: readonly Provider[]; /** * Work that owns the request lifecycle. The container is disposed after this * callback settles. */ readonly run: (container: Container) => TResult | Promise; }; /** * Next.js server adapter instance created by `createNextDi`. */ type NextDiAdapter = { /** * Returns the long-lived root server container. */ readonly getRootContainer: () => Container; /** * Returns the current RSC render-scoped child container. */ readonly getRequestContainer: () => Container; /** * Creates a fresh child container manually, useful in route handlers or tests. */ readonly createRequestContainer: (providers?: readonly Provider[]) => Container; /** * Runs work inside a fresh child container and disposes it in a `finally` * block. This does not bind the container to async context; use the callback * argument, or `di-craft/node` when nested async code should call * `getRequestContainer()`. */ readonly runWithRequestContainer: (options: RunWithRequestContainerOptions) => Promise>; /** * Disposes cached instances owned by the root container. */ readonly disposeRootContainer: () => Promise; }; type SerializablePrimitive = string | number | boolean | null; /** * JSON-like value that can safely cross a Server Component boundary. */ type Serializable = SerializablePrimitive | readonly Serializable[] | { readonly [key: string]: Serializable; }; /** * Entity that can expose and restore a serializable state snapshot. * * The snapshot, not the DI container, is what crosses the RSC/client boundary. */ type Hydratable = { /** * Returns the minimal serializable state needed by the client. */ dehydrate(): TSnapshot; /** * Restores state from a previously serialized snapshot. */ hydrate(snapshot: TSnapshot): void; }; /** * Named hydratable tokens that define a client-boundary snapshot shape. * * Use it with `satisfies` to validate the schema without losing literal keys or * token-specific snapshot inference. * * @example * ```ts * const hydration = { * user: USER_STATE, * } satisfies HydrationSchema; * ``` */ type HydrationSchema = Readonly>>>; /** * Snapshot object inferred from a hydration schema. */ type HydrationSnapshot = { readonly [TKey in keyof TSchema]: TSchema[TKey] extends Token> ? TSnapshot : never; }; /** * Options for reading a serializable snapshot from a container. */ type DehydrateOptions = { /** * Container that owns the hydratable state entities. */ readonly container: Container; /** * Hydratable tokens keyed by snapshot field name. */ readonly schema: TSchema; }; /** * Options for restoring a serializable snapshot into a container. */ type HydrateOptions = DehydrateOptions & { /** * Serializable state produced by `dehydrate` for the same schema. */ readonly snapshot: HydrationSnapshot; }; //#endregion //#region src/adapters/next/hydration.d.ts /** * Reads serializable snapshots from hydratable entities declared in a schema. * * Use this on the server side before crossing into a Client Component. Only the * returned snapshot should cross the boundary, not the container or service * instances themselves. * * @example * ```ts * const hydration = { user: USER_STATE }; * const snapshot = dehydrate({ * container: getRequestContainer(), * schema: hydration, * }); * ``` */ declare const dehydrate: (options: DehydrateOptions) => HydrationSnapshot; /** * Restores serializable snapshots into hydratable entities declared in a schema. * * Use this with a client-safe container and the snapshot received through a * Client Component prop. * * @example * ```ts * hydrate({ * container: clientContainer, * schema: hydration, * snapshot, * }); * ``` */ declare const hydrate: (options: HydrateOptions) => void; //#endregion export { Hydratable as a, HydrationSnapshot as c, RunWithRequestContainerOptions as d, Serializable as f, DehydrateOptions as i, NextDiAdapter as l, hydrate as n, HydrateOptions as o, SerializablePrimitive as p, CreateNextDiOptions as r, HydrationSchema as s, dehydrate as t, RequestCache as u }; //# sourceMappingURL=hydration-CaIWtQ3X.d.mts.map