import { ORPCErrorCode, ORPCErrorOptions, ORPCError, HTTPPath, ClientContext, Client } from '@rubenbupe/orpc-client'; import { MaybeOptionalOptions, Promisable, Interceptor, Value } from '@rubenbupe/orpc-shared'; import { ErrorMap, ErrorMapItem, InferSchemaInput, AnySchema, Meta, ContractProcedureDef, InferSchemaOutput, ErrorFromErrorMap, AnyContractRouter, ContractProcedure } from '@rubenbupe/orpc-contract'; 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 function validateORPCError(map: ErrorMap, error: ORPCError): Promise>; declare const LAZY_SYMBOL: unique symbol; interface LazyMeta { prefix?: HTTPPath; } interface Lazy { [LAZY_SYMBOL]: { loader: () => Promise<{ default: T; }>; meta: LazyMeta; }; } type Lazyable = T | Lazy; 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; } declare class Procedure { '~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; } 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; } /** * Options for creating a procedure caller with comprehensive type safety */ type CreateProcedureClientOptions = { /** * This is helpful for logging and analytics. */ path?: readonly string[]; interceptors?: Interceptor, InferSchemaOutput, ErrorFromErrorMap>[]; } & (Record extends TInitialContext ? { context?: Value; } : { context: Value; }); declare function createProcedureClient(lazyableProcedure: Lazyable>, ...[options]: MaybeOptionalOptions>): ProcedureClient; 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; type InferRouterInitialContexts = T extends Procedure ? UInitialContext : { [K in keyof T]: T[K] extends Lazyable ? InferRouterInitialContexts : never; }; type InferRouterCurrentContexts = T extends Procedure ? UCurrentContext : { [K in keyof T]: T[K] extends Lazyable ? InferRouterCurrentContexts : never; }; type InferRouterInputs = T extends Procedure ? InferSchemaInput : { [K in keyof T]: T[K] extends Lazyable ? InferRouterInputs : never; }; type InferRouterOutputs = T extends Procedure ? InferSchemaOutput : { [K in keyof T]: T[K] extends Lazyable ? InferRouterOutputs : never; }; export { middlewareOutputFn as B, isProcedure as F, createProcedureClient as G, Procedure as b, mergeCurrentContext as m, createORPCErrorConstructorMap as n, LAZY_SYMBOL as o, lazy as q, isLazy as r, getLazyMeta as s, unlazy as u, validateORPCError as v }; export type { AnyProcedure as A, Context as C, ProcedureHandlerOptions as D, ProcedureDef as E, InferRouterInitialContexts as H, InferRouterInitialContext as I, InferRouterCurrentContexts as J, InferRouterInputs as K, Lazyable as L, Middleware as M, InferRouterOutputs as N, ORPCErrorConstructorMap as O, ProcedureClientInterceptorOptions as P, Router as R, AnyRouter as a, MergedInitialContext as c, MergedCurrentContext as d, MapInputMiddleware as e, CreateProcedureClientOptions as f, ProcedureClient as g, AnyMiddleware as h, Lazy as i, ProcedureHandler as j, ORPCErrorConstructorMapItemOptions as k, ORPCErrorConstructorMapItem as l, LazyMeta as p, MiddlewareResult as t, MiddlewareNextFnOptions as w, MiddlewareNextFn as x, MiddlewareOutputFn as y, MiddlewareOptions as z };