import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@orpc/client'; import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@orpc/contract'; import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, Value } from '@orpc/shared'; type Context = Record; type MergedInitialContext = TInitial & Omit; type MergedCurrentContext = Omit & U; declare function mergeCurrentContext(context: T, other: U): MergedCurrentContext; type ORPCErrorConstructorMapItemOptions = Omit, 'defined' | 'status'>; type ORPCErrorConstructorMapItem = (...rest: MaybeOptionalOptions>) => ORPCError; type ORPCErrorConstructorMap = { [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem ? ORPCErrorConstructorMapItem> : never : never; }; declare function createORPCErrorConstructorMap(errors: T): ORPCErrorConstructorMap; declare const LAZY_SYMBOL: unique symbol; interface LazyMeta { prefix?: HTTPPath; } interface Lazy { [LAZY_SYMBOL]: { loader: () => Promise<{ default: T; }>; meta: LazyMeta; }; } type Lazyable = T | Lazy; /** * Creates a lazy-loaded item. * * @warning The `prefix` in `meta` only holds metadata and does not apply the prefix to the lazy router, use `os.prefix(...).lazy(...)` instead. */ declare function lazy(loader: () => Promise<{ default: T; }>, meta?: LazyMeta): Lazy; declare function isLazy(item: unknown): item is Lazy; declare function getLazyMeta(lazied: Lazy): LazyMeta; declare function unlazy>(lazied: T): Promise<{ default: T extends Lazy ? U : T; }>; interface ProcedureHandlerOptions, TMeta extends Meta> { context: TCurrentContext; input: TInput; path: readonly string[]; procedure: Procedure; signal?: AbortSignal; lastEventId: string | undefined; errors: TErrorConstructorMap; } interface ProcedureHandler { (opt: ProcedureHandlerOptions, TMeta>): Promisable; } interface ProcedureDef extends ContractProcedureDef { __initialContext?: (type: TInitialContext) => unknown; middlewares: readonly AnyMiddleware[]; inputValidationIndex: number; outputValidationIndex: number; handler: ProcedureHandler; } /** * This class represents a procedure. * * @see {@link https://orpc.dev/docs/procedure Procedure Docs} */ declare class Procedure { /** * This property holds the defined options. */ '~orpc': ProcedureDef; constructor(def: ProcedureDef); } type AnyProcedure = Procedure; declare function isProcedure(item: unknown): item is AnyProcedure; type MiddlewareResult = Promisable<{ output: TOutput; context: TOutContext; }>; type MiddlewareNextFnOptions = Record extends TOutContext ? { context?: TOutContext; } : { context: TOutContext; }; interface MiddlewareNextFn { >(...rest: MaybeOptionalOptions>): MiddlewareResult; } interface MiddlewareOutputFn { (output: TOutput): MiddlewareResult, TOutput>; } interface MiddlewareOptions, TMeta extends Meta> { context: TInContext; path: readonly string[]; procedure: Procedure; signal?: AbortSignal; lastEventId: string | undefined; next: MiddlewareNextFn; errors: TErrorConstructorMap; } /** * A function that represents a middleware. * * @see {@link https://orpc.dev/docs/middleware Middleware Docs} */ interface Middleware, TMeta extends Meta> { (options: MiddlewareOptions, input: TInput, output: MiddlewareOutputFn): Promisable>; } type AnyMiddleware = Middleware; interface MapInputMiddleware { (input: TInput): TMappedInput; } declare function middlewareOutputFn(output: TOutput): MiddlewareResult, TOutput>; type ProcedureClient = Client, InferSchemaOutput, ErrorFromErrorMap>; interface ProcedureClientInterceptorOptions { context: TInitialContext; input: unknown; errors: ORPCErrorConstructorMap; path: readonly string[]; procedure: Procedure; signal?: AbortSignal; lastEventId: string | undefined; } type CreateProcedureClientOptions = { /** * This is helpful for logging and analytics. */ path?: readonly string[]; interceptors?: Interceptor, PromiseWithError, ErrorFromErrorMap>>[]; } & (Record extends TInitialContext ? { context?: Value, [clientContext: TClientContext]>; } : { context: Value, [clientContext: TClientContext]>; }); /** * Create Server-side client from a procedure. * * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs} */ declare function createProcedureClient(lazyableProcedure: Lazyable>, ...rest: MaybeOptionalOptions>): ProcedureClient; /** * Represents a router, which defines a hierarchical structure of procedures. * * @info A procedure is a router too. * @see {@link https://orpc.dev/docs/contract-first/define-contract#contract-router Contract Router Docs} */ type Router = T extends ContractProcedure ? Procedure : { [K in keyof T]: T[K] extends AnyContractRouter ? Lazyable> : never; }; type AnyRouter = Router; type InferRouterInitialContext = T extends Router ? UInitialContext : never; /** * Infer all initial context of the router. * * @info A procedure is a router too. * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs} */ type InferRouterInitialContexts = T extends Procedure ? UInitialContext : { [K in keyof T]: T[K] extends Lazyable ? InferRouterInitialContexts : never; }; /** * Infer all current context of the router. * * @info A procedure is a router too. * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs} */ type InferRouterCurrentContexts = T extends Procedure ? UCurrentContext : { [K in keyof T]: T[K] extends Lazyable ? InferRouterCurrentContexts : never; }; /** * Infer all router inputs * * @info A procedure is a router too. * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs} */ type InferRouterInputs = T extends Procedure ? InferSchemaInput : { [K in keyof T]: T[K] extends Lazyable ? InferRouterInputs : never; }; /** * Infer all router outputs * * @info A procedure is a router too. * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs} */ type InferRouterOutputs = T extends Procedure ? InferSchemaOutput : { [K in keyof T]: T[K] extends Lazyable ? InferRouterOutputs : never; }; export { isProcedure as E, createProcedureClient as F, Procedure as P, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, middlewareOutputFn as z }; export type { AnyProcedure as A, ProcedureHandlerOptions as B, Context as C, ProcedureDef as D, InferRouterInitialContexts as G, InferRouterCurrentContexts as H, InferRouterInitialContext as I, InferRouterInputs as J, InferRouterOutputs as K, Lazyable as L, MergedInitialContext as M, ORPCErrorConstructorMap as O, Router as R, AnyMiddleware as a, AnyRouter as b, Lazy as c, ProcedureClientInterceptorOptions as d, Middleware as e, MergedCurrentContext as f, MapInputMiddleware as g, CreateProcedureClientOptions as h, ProcedureClient as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as v, MiddlewareNextFn as w, MiddlewareOutputFn as x, MiddlewareOptions as y };