import type { AnyService, UnknownService } from "../service/index.js"; import type { Layer } from "./index.js"; export type LayerFnClosure = (inner: In) => Out; /** * Returns a new {@link LayerFn} that implements {@link Layer} by calling a * given function. * * @example * ```ts * import { layerFn } from "@taxum/core/layer"; * import { serviceFn, type Service } from "@taxum/core/service"; * * // A middleware that logs requests before forwarding them to another service. * class LogService implements Service { * public constructor(private readonly inner: Service) {} * * public async invoke(req: string): Promise { * console.log("Request received", req); * return await this.inner.invoke(req); * } * } * * // A `Layer` that wraps services in `LogService`. * const logLayer = layerFn( * (inner: Service) => new LogService(inner) * ); * * // An example service. * const service = serviceFn((req: string) => req.toUpperCase()); * * // Wrap our service in a `LogService` so requests are logged. * const wrappedService = logLayer.layer(service); * ``` */ export declare const layerFn: (f: LayerFnClosure) => Layer; /** * A {@link Layer} implemented by a closure. * * @see {@link layerFn} */ export declare class LayerFn implements Layer { private readonly f; constructor(f: LayerFnClosure); layer(inner: In): Out; }