effect-orpc 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/contract.ts","../src/effect-builder.ts","../src/effect-enhance-router.ts","../src/effect-procedure.ts","../src/extension/compose-surfaces.ts","../src/extension/state.ts","../src/extension/create-node-proxy.ts","../src/tagged-error.ts","../src/effect-runtime.ts","../src/eoc.ts"],"sourcesContent":["import type {\n AnyContractRouter,\n AnySchema,\n ContractProcedure,\n ErrorMap,\n InferContractRouterErrorMap,\n InferContractRouterMeta,\n InferSchemaInput,\n InferSchemaOutput,\n Meta,\n} from \"@orpc/contract\";\nimport { isContractProcedure } from \"@orpc/contract\";\nimport type {\n BuilderConfig,\n BuilderDef,\n Context,\n DecoratedMiddleware,\n ImplementedProcedure,\n Lazy,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ORPCErrorConstructorMap,\n ProcedureHandler,\n Router,\n} from \"@orpc/server\";\nimport { implement } from \"@orpc/server\";\nimport type { IntersectPick } from \"@orpc/shared\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport { addSpanStackTrace } from \"./effect-builder\";\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport { createEffectProcedureHandler } from \"./effect-runtime\";\nimport { effectContractSymbol, getEffectContractErrorMap } from \"./eoc\";\nimport type { EffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureHandler } from \"./types\";\n\ntype ContractLeafEffectHandler<\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TMeta extends Meta,\n> = EffectProcedureHandler<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n InferSchemaInput<TOutputSchema>,\n TErrorMap,\n TRequirementsProvided,\n TMeta\n>;\n\ntype InferContractLeafEffectErrorMap<\n TContract,\n TErrorMap extends ErrorMap,\n> = TContract extends {\n [effectContractSymbol]: {\n errorMap: infer TEffectErrorMap extends EffectErrorMap;\n };\n}\n ? TEffectErrorMap\n : TErrorMap;\n\nexport interface EffectProcedureImplementer<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n> {\n \"~orpc\": BuilderDef<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TErrorMap>,\n TMeta\n >;\n use<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n UInContext extends Context = TCurrentContext,\n >(\n middleware: Middleware<\n UInContext | TCurrentContext,\n UOutContext,\n InferSchemaOutput<TInputSchema>,\n InferSchemaInput<TOutputSchema>,\n ORPCErrorConstructorMap<EffectErrorMapToErrorMap<TErrorMap>>,\n TMeta\n >,\n ): EffectProcedureImplementer<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n use<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n UInput,\n UInContext extends Context = TCurrentContext,\n >(\n middleware: Middleware<\n UInContext | TCurrentContext,\n UOutContext,\n UInput,\n InferSchemaInput<TOutputSchema>,\n ORPCErrorConstructorMap<EffectErrorMapToErrorMap<TErrorMap>>,\n TMeta\n >,\n mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,\n ): EffectProcedureImplementer<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n handler(\n handler: ProcedureHandler<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n InferSchemaInput<TOutputSchema>,\n EffectErrorMapToErrorMap<TErrorMap>,\n TMeta\n >,\n ): ImplementedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TErrorMap>,\n TMeta\n >;\n effect(\n effectFn: ContractLeafEffectHandler<\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TRequirementsProvided,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n}\n\nexport type EffectImplementerInternal<\n TContract extends AnyContractRouter,\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TRequirementsProvided,\n TRuntimeError,\n> =\n TContract extends ContractProcedure<\n infer TInputSchema,\n infer TOutputSchema,\n infer TErrorMap extends ErrorMap,\n infer TMeta extends Meta\n >\n ? EffectProcedureImplementer<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n InferContractLeafEffectErrorMap<TContract, TErrorMap>,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >\n : {\n middleware<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n TInput,\n TOutput = any,\n >(\n middleware: Middleware<\n TInitialContext,\n UOutContext,\n TInput,\n TOutput,\n ORPCErrorConstructorMap<InferContractRouterErrorMap<TContract>>,\n InferContractRouterMeta<TContract>\n >,\n ): DecoratedMiddleware<\n TInitialContext,\n UOutContext,\n TInput,\n TOutput,\n any,\n InferContractRouterMeta<TContract>\n >;\n use<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n UInContext extends Context = TCurrentContext,\n >(\n middleware: Middleware<\n UInContext | TCurrentContext,\n UOutContext,\n unknown,\n unknown,\n ORPCErrorConstructorMap<InferContractRouterErrorMap<TContract>>,\n InferContractRouterMeta<TContract>\n >,\n ): EffectImplementerInternal<\n TContract,\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TRequirementsProvided,\n TRuntimeError\n >;\n router<U extends Router<TContract, TCurrentContext>>(\n router: U,\n ): ReturnType<\n typeof enhanceEffectRouter<\n U,\n TInitialContext,\n TCurrentContext,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n >\n >;\n lazy<U extends Router<TContract, TCurrentContext>>(\n loader: () => Promise<{ default: U }>,\n ): ReturnType<\n typeof enhanceEffectRouter<\n Lazy<U>,\n TInitialContext,\n TCurrentContext,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n >\n >;\n } & {\n [K in keyof TContract]: TContract[K] extends AnyContractRouter\n ? EffectImplementerInternal<\n TContract[K],\n TInitialContext,\n TCurrentContext,\n TRequirementsProvided,\n TRuntimeError\n >\n : never;\n };\n\nexport type EffectImplementer<\n TContract extends AnyContractRouter,\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TRequirementsProvided,\n TRuntimeError,\n> = {\n $context<U extends Context>(): EffectImplementer<\n TContract,\n U & Record<never, never>,\n U,\n TRequirementsProvided,\n TRuntimeError\n >;\n $config(\n config: BuilderConfig,\n ): EffectImplementer<\n TContract,\n TInitialContext,\n TCurrentContext,\n TRequirementsProvided,\n TRuntimeError\n >;\n} & EffectImplementerInternal<\n TContract,\n TInitialContext,\n TCurrentContext,\n TRequirementsProvided,\n TRuntimeError\n>;\n\nconst CONTRACT_HIDDEN_METHODS = new Set([\n \"$config\",\n \"$context\",\n \"$input\",\n \"$meta\",\n \"$route\",\n \"errors\",\n \"input\",\n \"lazy\",\n \"meta\",\n \"middleware\",\n \"output\",\n \"prefix\",\n \"route\",\n \"router\",\n \"tag\",\n]);\n\nfunction makeEnhanceOptions<TRequirementsProvided, TRuntimeError>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n) {\n return {\n middlewares: [],\n errorMap: {},\n dedupeLeadingMiddlewares: true,\n runtime,\n } as const;\n}\n\nfunction wrapContractNode<\n TContract extends AnyContractRouter,\n TRequirementsProvided,\n TRuntimeError,\n>(\n contract: TContract,\n target: any,\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n): EffectImplementerInternal<\n TContract,\n Context,\n Context,\n TRequirementsProvided,\n TRuntimeError\n> {\n const cache = new Map<PropertyKey, unknown>();\n\n return new Proxy(target, {\n get(currentTarget, prop, receiver) {\n if (cache.has(prop)) {\n return cache.get(prop);\n }\n\n if (isContractProcedure(contract)) {\n if (prop === \"effect\") {\n const effect = (\n effectFn: ContractLeafEffectHandler<any, any, any, any, any, any>,\n ) => {\n const effectErrorMap =\n getEffectContractErrorMap(contract) ??\n currentTarget[\"~orpc\"].errorMap;\n\n return new EffectDecoratedProcedure({\n ...currentTarget[\"~orpc\"],\n errorMap: effectErrorMapToErrorMap(effectErrorMap),\n effectErrorMap,\n runtime,\n handler: createEffectProcedureHandler({\n runtime,\n effectErrorMap,\n effectFn,\n defaultCaptureStackTrace: addSpanStackTrace(),\n }),\n });\n };\n\n cache.set(prop, effect);\n return effect;\n }\n\n if (prop === \"use\") {\n const use = (...args: unknown[]) =>\n wrapContractNode(\n contract,\n Reflect.apply(\n Reflect.get(currentTarget, prop, currentTarget),\n currentTarget,\n args,\n ),\n runtime,\n );\n\n cache.set(prop, use);\n return use;\n }\n\n if (CONTRACT_HIDDEN_METHODS.has(String(prop))) {\n return undefined;\n }\n } else {\n if (prop === \"$context\" || prop === \"$config\" || prop === \"use\") {\n const wrappedMethod = (...args: unknown[]) =>\n wrapContractNode(\n contract,\n Reflect.apply(\n Reflect.get(currentTarget, prop, currentTarget),\n currentTarget,\n args,\n ),\n runtime,\n );\n\n cache.set(prop, wrappedMethod);\n return wrappedMethod;\n }\n\n if (prop === \"router\" || prop === \"lazy\") {\n const wrappedMethod = (...args: unknown[]) =>\n enhanceEffectRouter(\n Reflect.apply(\n Reflect.get(currentTarget, prop, currentTarget),\n currentTarget,\n args,\n ) as any,\n makeEnhanceOptions(runtime),\n );\n\n cache.set(prop, wrappedMethod);\n return wrappedMethod;\n }\n\n if (typeof prop === \"string\" && prop in contract) {\n const child = wrapContractNode(\n (contract as Record<string, AnyContractRouter>)[prop]!,\n Reflect.get(currentTarget, prop, receiver),\n runtime,\n );\n\n cache.set(prop, child);\n return child;\n }\n }\n\n const value = Reflect.get(currentTarget, prop, receiver);\n return typeof value === \"function\" ? value.bind(currentTarget) : value;\n },\n has(currentTarget, prop) {\n if (isContractProcedure(contract)) {\n if (prop === \"effect\") {\n return true;\n }\n if (CONTRACT_HIDDEN_METHODS.has(String(prop))) {\n return false;\n }\n } else if (typeof prop === \"string\" && prop in contract) {\n return true;\n }\n\n return Reflect.has(currentTarget, prop);\n },\n }) as EffectImplementerInternal<\n TContract,\n Context,\n Context,\n TRequirementsProvided,\n TRuntimeError\n >;\n}\n\nexport function implementEffect<\n TContract extends AnyContractRouter,\n TRequirementsProvided,\n TRuntimeError,\n>(\n contract: TContract,\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n): EffectImplementer<\n TContract,\n Record<never, never>,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n> {\n return wrapContractNode(\n contract,\n implement(contract),\n runtime,\n ) as EffectImplementer<\n TContract,\n Record<never, never>,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n >;\n}\n","import type {\n AnySchema,\n ContractRouter,\n ErrorMap,\n Meta,\n Schema,\n} from \"@orpc/contract\";\nimport type { Context, Router } from \"@orpc/server\";\nimport { Builder, fallbackConfig, lazy } from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport { createEffectProcedureHandler } from \"./effect-runtime\";\nimport {\n createNodeProxy,\n unhandled,\n type NodeProxyContext,\n} from \"./extension/create-node-proxy\";\nimport {\n attachEffectState,\n getEffectErrorMap,\n unwrapEffectUpstream,\n type EffectProxyTarget,\n} from \"./extension/state\";\nimport type { EffectErrorMap, MergedEffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type {\n AnyBuilderLike,\n EffectBuilderDef,\n InferBuilderCurrentContext,\n InferBuilderErrorMap,\n InferBuilderInitialContext,\n InferBuilderInputSchema,\n InferBuilderMeta,\n InferBuilderOutputSchema,\n} from \"./types\";\nimport type { EffectBuilderSurface } from \"./types/effect-builder-surface\";\n\nconst builderVirtualDescriptors = {\n \"~effect\": { enumerable: true },\n effect: { enumerable: false },\n errors: { enumerable: false },\n handler: { enumerable: false },\n lazy: { enumerable: false },\n router: { enumerable: false },\n traced: { enumerable: false },\n} as const;\n\nconst builderVirtualKeys = [\n \"~effect\",\n \"errors\",\n \"effect\",\n \"traced\",\n \"handler\",\n \"router\",\n \"lazy\",\n] as const;\n\ntype EffectBuilderTarget = EffectBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n> &\n EffectProxyTarget<AnyBuilderLike>;\n\nfunction isBuilderLike(value: unknown): value is AnyBuilderLike {\n return typeof value === \"object\" && value !== null && \"~orpc\" in value;\n}\n\nfunction getOrCreateVirtualMethod<T>(\n context: NodeProxyContext<EffectBuilderTarget, AnyBuilderLike>,\n prop: PropertyKey,\n factory: () => T,\n): T {\n const cache = context.methodCache;\n if (cache.has(prop)) {\n return cache.get(prop) as T;\n }\n\n const value = factory();\n cache.set(prop, value);\n return value;\n}\n\nfunction getEffectBuilderDef(\n context: NodeProxyContext<EffectBuilderTarget, AnyBuilderLike>,\n): EffectBuilderDef<any, any, any, any, any, any> {\n return {\n ...context.upstream[\"~orpc\"],\n effectErrorMap: context.state.effectErrorMap,\n runtime: context.state.runtime,\n spanConfig: context.state.spanConfig,\n };\n}\n\nfunction wrapBuilderLike(\n builder: AnyBuilderLike,\n state: NodeProxyContext<EffectBuilderTarget, AnyBuilderLike>[\"state\"],\n): EffectBuilder<any, any, any, any, any, any, any, any> {\n return new EffectBuilder(\n {\n ...builder[\"~orpc\"],\n effectErrorMap: state.effectErrorMap,\n runtime: state.runtime,\n spanConfig: state.spanConfig,\n },\n unwrapEffectUpstream(builder),\n );\n}\n\nfunction createEffectBuilderProxy(\n target: EffectBuilderTarget,\n): EffectBuilderTarget {\n return createNodeProxy<EffectBuilderTarget, AnyBuilderLike>(target, {\n getVirtual(context, prop) {\n const effectDef = getEffectBuilderDef(context);\n if (prop === \"~effect\") {\n return getEffectBuilderDef(context);\n }\n\n const { upstream: source, state } = context;\n\n switch (prop) {\n case \"errors\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return <U extends EffectErrorMap>(errors: U) => {\n const nextEffectErrorMap: MergedEffectErrorMap<\n typeof state.effectErrorMap,\n U\n > = {\n ...state.effectErrorMap,\n ...errors,\n };\n const nextBuilder: AnyBuilderLike = Reflect.apply(\n Reflect.get(source, \"errors\", source),\n source,\n [effectErrorMapToErrorMap(errors)],\n );\n\n return wrapBuilderLike(nextBuilder, {\n ...state,\n effectErrorMap: nextEffectErrorMap,\n });\n };\n });\n case \"effect\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n effectFn: Parameters<\n EffectBuilderSurface<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >[\"effect\"]\n >[0],\n ) => {\n const defaultCaptureStackTrace = addSpanStackTrace();\n return new EffectDecoratedProcedure({\n ...effectDef,\n handler: async (opts) => {\n return createEffectProcedureHandler({\n defaultCaptureStackTrace,\n effectErrorMap: state.effectErrorMap,\n effectFn,\n runtime: state.runtime,\n spanConfig: state.spanConfig,\n })(opts as any);\n },\n });\n };\n });\n case \"traced\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (spanName: string) =>\n wrapBuilderLike(source, {\n ...state,\n spanConfig: {\n captureStackTrace: addSpanStackTrace(),\n name: spanName,\n },\n });\n });\n case \"handler\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n handler: Parameters<\n EffectBuilderSurface<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >[\"handler\"]\n >[0],\n ) =>\n new EffectDecoratedProcedure({\n ...effectDef,\n handler,\n });\n });\n case \"router\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (router: Router<ContractRouter<any>, any>) =>\n enhanceEffectRouter(router, effectDef) as any;\n });\n case \"lazy\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n loader: () => Promise<{\n default: Router<ContractRouter<any>, any>;\n }>,\n ) => enhanceEffectRouter(lazy(loader), effectDef) as any;\n });\n default:\n return unhandled();\n }\n },\n virtualDescriptors: builderVirtualDescriptors,\n virtualKeys: builderVirtualKeys,\n wrapResult(context, _prop, result) {\n if (!isBuilderLike(result)) {\n return result;\n }\n\n return wrapBuilderLike(result, context.state);\n },\n });\n}\n\n/**\n * Captures the stack trace at the call site for better error reporting in spans.\n * This is called at procedure definition time to capture where the procedure was defined.\n */\nexport function addSpanStackTrace(): () => string | undefined {\n const ErrorConstructor = Error as typeof Error & {\n stackTraceLimit?: number;\n };\n const limit = ErrorConstructor.stackTraceLimit;\n ErrorConstructor.stackTraceLimit = 3;\n const traceError = new Error();\n ErrorConstructor.stackTraceLimit = limit;\n let cache: false | string = false;\n return () => {\n if (cache !== false) {\n return cache;\n }\n if (traceError.stack !== undefined) {\n const stack = traceError.stack.split(\"\\n\");\n if (stack[3] !== undefined) {\n cache = stack[3].trim();\n return cache;\n }\n }\n };\n}\n\n/**\n * Effect-native procedure builder that wraps an oRPC Builder instance\n * and adds Effect-specific capabilities while preserving Effect error\n * and requirements types.\n */\nexport class EffectBuilder<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n> implements EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n> {\n declare $config: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$config\"];\n declare $context: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$context\"];\n declare $meta: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$meta\"];\n declare $route: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$route\"];\n declare $input: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$input\"];\n declare \"~effect\": EffectBuilderDef<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n declare \"~orpc\": EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"~orpc\"];\n declare middleware: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"middleware\"];\n declare errors: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"errors\"];\n declare use: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"use\"];\n declare meta: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"meta\"];\n declare route: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"route\"];\n declare input: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"input\"];\n declare output: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"output\"];\n declare traced: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"traced\"];\n declare handler: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"handler\"];\n declare effect: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"effect\"];\n declare prefix: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"prefix\"];\n declare tag: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"tag\"];\n declare router: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"router\"];\n declare lazy: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"lazy\"];\n\n constructor(\n def: EffectBuilderDef<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n builder?: AnyBuilderLike,\n ) {\n const { runtime, spanConfig, effectErrorMap, ...orpcDef } = def;\n\n attachEffectState(this, builder ?? new Builder(orpcDef), {\n effectErrorMap,\n runtime,\n spanConfig,\n });\n\n return createEffectBuilderProxy(this);\n }\n}\n\n/**\n * Creates an Effect-aware procedure builder with the specified ManagedRuntime.\n * Uses the default builder shape from `@orpc/server`.\n *\n * @param runtime - The ManagedRuntime that provides services for Effect procedures\n * @returns An EffectBuilder instance for creating Effect-native procedures\n */\nexport function makeEffectORPC<TRequirementsProvided, TRuntimeError>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n): EffectBuilder<\n Context,\n Context,\n Schema<unknown, unknown>,\n Schema<unknown, unknown>,\n Record<never, never>,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n>;\n\n/**\n * Creates an Effect-aware procedure builder by wrapping an existing oRPC Builder\n * with the specified ManagedRuntime.\n *\n * @param runtime - The ManagedRuntime that provides services for Effect procedures\n * @param builder - The oRPC Builder instance to wrap\n * @returns An EffectBuilder instance that extends the original builder with Effect support\n */\nexport function makeEffectORPC<\n TBuilder extends AnyBuilderLike<\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta\n >,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TErrorMap extends ErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n builder: TBuilder,\n): EffectBuilder<\n InferBuilderInitialContext<TBuilder>,\n InferBuilderCurrentContext<TBuilder>,\n InferBuilderInputSchema<TBuilder>,\n InferBuilderOutputSchema<TBuilder>,\n InferBuilderErrorMap<TBuilder>,\n InferBuilderMeta<TBuilder>,\n TRequirementsProvided,\n TRuntimeError\n>;\n\nexport function makeEffectORPC<TRequirementsProvided, TRuntimeError>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n builder?: AnyBuilderLike,\n): EffectBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n TRequirementsProvided,\n TRuntimeError\n> {\n const resolvedBuilder = builder ?? emptyBuilder();\n const effectErrorMap = getEffectErrorMap(resolvedBuilder);\n return new EffectBuilder(\n {\n ...resolvedBuilder[\"~orpc\"],\n effectErrorMap: effectErrorMap,\n errorMap: effectErrorMapToErrorMap(effectErrorMap),\n runtime,\n },\n unwrapEffectUpstream(resolvedBuilder),\n );\n}\n\nfunction emptyBuilder(): AnyBuilderLike {\n return new Builder({\n config: {},\n dedupeLeadingMiddlewares: true,\n errorMap: {},\n inputValidationIndex: fallbackConfig(\"initialInputValidationIndex\"),\n meta: {},\n middlewares: [],\n outputValidationIndex: fallbackConfig(\"initialOutputValidationIndex\"),\n route: {},\n });\n}\n","import {\n enhanceRoute,\n mergePrefix,\n type EnhanceRouteOptions,\n} from \"@orpc/contract\";\nimport {\n createAccessibleLazyRouter,\n getLazyMeta,\n isLazy,\n isProcedure,\n lazy,\n mergeMiddlewares,\n unlazy,\n type AnyMiddleware,\n type AnyRouter,\n type Context,\n type Lazyable,\n} from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect/ManagedRuntime\";\n\nimport { EffectProcedure } from \"./effect-procedure\";\nimport { getEffectErrorMap, unwrapEffectUpstream } from \"./extension/state\";\nimport { effectErrorMapToErrorMap, type EffectErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from \"./types\";\n\ninterface EnhanceEffectRouterOptions<\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n> extends EnhanceRouteOptions {\n middlewares: readonly AnyMiddleware[];\n errorMap: TEffectErrorMap;\n dedupeLeadingMiddlewares: boolean;\n runtime: ManagedRuntime<TRequirementsProvided, TRuntimeError>;\n}\n\nexport function enhanceEffectRouter<\n T extends Lazyable<AnyRouter>,\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n>(\n router: T,\n options: EnhanceEffectRouterOptions<\n TEffectErrorMap,\n TRequirementsProvided,\n TRuntimeError\n >,\n): EnhancedEffectRouter<T, TInitialContext, TCurrentContext, TEffectErrorMap> {\n if (isLazy(router)) {\n const laziedMeta = getLazyMeta(router);\n const enhancedPrefix = laziedMeta?.prefix\n ? mergePrefix(options.prefix, laziedMeta.prefix)\n : options.prefix;\n\n const enhanced = lazy(\n async () => {\n const { default: unlaziedRouter } = await unlazy(router);\n const wrappedRouter = enhanceEffectRouter(unlaziedRouter, options);\n return unlazy(wrappedRouter);\n },\n {\n ...laziedMeta,\n prefix: enhancedPrefix,\n },\n );\n\n return createAccessibleLazyRouter(enhanced) as any;\n }\n\n if (isProcedure(router)) {\n const source = unwrapEffectUpstream(router);\n const sourceEffectErrorMap = getEffectErrorMap(router);\n const middlewares = mergeMiddlewares(\n options.middlewares,\n source[\"~orpc\"].middlewares,\n { dedupeLeading: options.dedupeLeadingMiddlewares },\n );\n const newMiddlewareAdded =\n middlewares.length - source[\"~orpc\"].middlewares.length;\n const effectErrorMap = {\n ...options.errorMap,\n ...sourceEffectErrorMap,\n };\n const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =\n effectErrorMapToErrorMap(effectErrorMap);\n\n return new EffectProcedure({\n ...source[\"~orpc\"],\n route: enhanceRoute(source[\"~orpc\"].route, options),\n effectErrorMap,\n errorMap: errorMap as EffectErrorMapToErrorMap<typeof effectErrorMap>,\n middlewares,\n inputValidationIndex:\n source[\"~orpc\"].inputValidationIndex + newMiddlewareAdded,\n outputValidationIndex:\n source[\"~orpc\"].outputValidationIndex + newMiddlewareAdded,\n runtime: options.runtime,\n }) as any;\n }\n\n const enhanced: Record<string, any> = {};\n\n for (const key in router) {\n enhanced[key] = enhanceEffectRouter(router[key]!, options);\n }\n\n return enhanced as any;\n}\n","import type { ClientContext } from \"@orpc/client\";\nimport type { AnySchema, Meta, Route } from \"@orpc/contract\";\nimport { mergeMeta, mergeRoute } from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n Context,\n CreateProcedureClientOptions,\n MapInputMiddleware,\n ProcedureDef,\n} from \"@orpc/server\";\nimport {\n addMiddleware,\n createActionableClient,\n createProcedureClient,\n decorateMiddleware,\n Procedure,\n} from \"@orpc/server\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\n\nimport { composeSurfaceProxy } from \"./extension/compose-surfaces\";\nimport {\n createNodeProxy,\n unhandled,\n type NodeProxyContext,\n} from \"./extension/create-node-proxy\";\nimport {\n assertEffectState,\n attachEffectState,\n type EffectProxyTarget,\n} from \"./extension/state\";\nimport type { EffectErrorMap, MergedEffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureDef } from \"./types\";\nimport type { EffectDecoratedProcedureSurface } from \"./types/effect-procedure-surface\";\n\ntype AnyProcedureLike = Procedure<any, any, any, any, any, any>;\ntype AnyEffectProcedure = EffectProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\ntype AnyEffectDecoratedProcedure = EffectDecoratedProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\ntype EffectProcedureTarget<\n T extends AnyEffectProcedure | AnyEffectDecoratedProcedure =\n | AnyEffectProcedure\n | AnyEffectDecoratedProcedure,\n> = T & EffectProxyTarget<AnyProcedureLike>;\n\nconst procedureVirtualDescriptors = {\n \"~effect\": { enumerable: true },\n actionable: { enumerable: false },\n callable: { enumerable: false },\n errors: { enumerable: false },\n meta: { enumerable: false },\n route: { enumerable: false },\n use: { enumerable: false },\n} as const;\n\nconst baseProcedureVirtualKeys = [\"~effect\"] as const;\nconst decoratedProcedureVirtualKeys = [\n ...baseProcedureVirtualKeys,\n \"errors\",\n \"meta\",\n \"route\",\n \"use\",\n \"callable\",\n \"actionable\",\n] as const;\n\nfunction getOrCreateVirtualMethod<T>(\n context: NodeProxyContext<EffectProcedureTarget, AnyProcedureLike>,\n prop: PropertyKey,\n factory: () => T,\n): T {\n const cache = context.methodCache;\n if (cache.has(prop)) {\n return cache.get(prop) as T;\n }\n\n const value = factory();\n cache.set(prop, value);\n return value;\n}\n\nfunction getEffectProcedureDef(\n context: NodeProxyContext<EffectProcedureTarget, AnyProcedureLike>,\n): EffectProcedureDef<any, any, any, any, any, any, any, any> {\n return {\n ...context.upstream[\"~orpc\"],\n effectErrorMap: context.state.effectErrorMap,\n runtime: context.state.runtime,\n };\n}\n\nfunction createEffectProcedureProxy<\n T extends AnyEffectProcedure | AnyEffectDecoratedProcedure,\n>(\n target: EffectProcedureTarget<T>,\n decorated: boolean,\n): EffectProcedureTarget<T> {\n return createNodeProxy<EffectProcedureTarget<T>, AnyProcedureLike>(target, {\n getVirtual(context, prop, receiver) {\n if (prop === \"~effect\") {\n return getEffectProcedureDef(context);\n }\n\n if (!decorated) {\n return unhandled();\n }\n\n const state = context.state;\n\n switch (prop) {\n case \"errors\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return <U extends EffectErrorMap>(errors: U) => {\n const nextEffectErrorMap: MergedEffectErrorMap<\n typeof state.effectErrorMap,\n U\n > = {\n ...state.effectErrorMap,\n ...errors,\n };\n return new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n effectErrorMap: nextEffectErrorMap,\n errorMap: effectErrorMapToErrorMap(nextEffectErrorMap),\n });\n };\n });\n case \"meta\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (meta: Meta) =>\n new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n meta: mergeMeta(getEffectProcedureDef(context).meta, meta),\n });\n });\n case \"route\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (route: Route) =>\n new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n route: mergeRoute(getEffectProcedureDef(context).route, route),\n });\n });\n case \"use\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n middleware: AnyMiddleware,\n mapInput?: MapInputMiddleware<any, any>,\n ) => {\n const mapped = mapInput\n ? decorateMiddleware(middleware).mapInput(mapInput)\n : middleware;\n\n return new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n middlewares: addMiddleware(\n getEffectProcedureDef(context).middlewares,\n mapped,\n ),\n });\n };\n });\n case \"callable\":\n return <TClientContext extends ClientContext>(\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<any, any, any, any, TClientContext>\n >\n ) => {\n const client = createProcedureClient(\n receiver as AnyProcedureLike,\n ...rest,\n );\n return composeSurfaceProxy(\n receiver as EffectDecoratedProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n client,\n );\n };\n case \"actionable\":\n return (\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<\n any,\n any,\n any,\n any,\n Record<never, never>\n >\n >\n ) => {\n const client = createProcedureClient(\n receiver as AnyProcedureLike,\n ...rest,\n );\n const action = createActionableClient(client);\n return composeSurfaceProxy(\n receiver as EffectDecoratedProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n action,\n );\n };\n default:\n return unhandled();\n }\n },\n virtualDescriptors: procedureVirtualDescriptors,\n virtualKeys: decorated\n ? decoratedProcedureVirtualKeys\n : baseProcedureVirtualKeys,\n });\n}\n\n/**\n * Effect-aware base procedure that carries the upstream procedure definition\n * together with Effect runtime and error metadata.\n */\nexport class EffectProcedure<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n> extends Procedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n> {\n declare \"~effect\": EffectProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n declare \"~orpc\": ProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >;\n\n constructor(\n def: EffectProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n procedure?: AnyProcedureLike,\n ) {\n super(def);\n attachEffectState(this, procedure ?? new Procedure(def), {\n effectErrorMap: def.effectErrorMap,\n runtime: def.runtime,\n });\n\n if (new.target === EffectProcedure) {\n return createEffectProcedureProxy(this, false);\n }\n }\n}\n\n/**\n * An Effect-native decorated procedure that preserves Effect error and requirements types.\n *\n * This class extends Procedure with additional type parameters for Effect-specific\n * type information, allowing full type inference of Effect errors and requirements.\n */\nexport class EffectDecoratedProcedure<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n>\n extends EffectProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >\n implements\n EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >\n{\n declare errors: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"errors\"];\n declare meta: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"meta\"];\n declare route: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"route\"];\n declare use: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"use\"];\n declare callable: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"callable\"];\n declare actionable: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"actionable\"];\n constructor(\n def: EffectProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n procedure?: AnyProcedureLike,\n ) {\n super(def, procedure);\n assertEffectState<AnyProcedureLike>(this);\n return createEffectProcedureProxy(this, true);\n }\n}\n","export function composeSurfaceProxy<\n TSurface extends object,\n TTarget extends object,\n>(surface: TSurface, target: TTarget): TSurface & TTarget {\n return new Proxy(target, {\n get(currentTarget, prop, receiver) {\n return Reflect.has(surface, prop)\n ? Reflect.get(surface, prop, surface)\n : Reflect.get(currentTarget, prop, receiver);\n },\n has(currentTarget, prop) {\n return Reflect.has(surface, prop) || Reflect.has(currentTarget, prop);\n },\n }) as TSurface & TTarget;\n}\n","import type { ManagedRuntime } from \"effect\";\n\nimport type { EffectErrorMap } from \"../tagged-error\";\nimport type { EffectSpanConfig } from \"../types\";\n\nexport interface EffectExtensionState<\n TRequirementsProvided = any,\n TRuntimeError = any,\n> {\n /**\n * Extended error map that supports both traditional oRPC errors and ORPCTaggedError classes.\n * @see {@link EffectErrorMap}\n */\n effectErrorMap: EffectErrorMap;\n /**\n * The Effect ManagedRuntime that provides services for Effect procedures.\n * @see {@link ManagedRuntime.ManagedRuntime}\n */\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;\n /**\n * Configuration for Effect span tracing.\n * @see {@link EffectSpanConfig}\n */\n spanConfig?: EffectSpanConfig;\n}\n\nexport interface EffectInternals<TUpstream extends object = object> {\n upstream: TUpstream;\n state: EffectExtensionState;\n methodCache: Map<PropertyKey, unknown>;\n}\n\nexport const effectInternalsSymbol = Symbol(\"effect-orpc/internals\");\n\nexport interface EffectProxyTarget<TUpstream extends object = object> {\n [effectInternalsSymbol]: EffectInternals<TUpstream>;\n}\n\nexport function attachEffectState<\n TTarget extends object,\n TUpstream extends object,\n>(\n target: TTarget,\n upstream: TUpstream,\n state: EffectExtensionState,\n): asserts target is TTarget & EffectProxyTarget<TUpstream> {\n Object.defineProperties(target, {\n [effectInternalsSymbol]: {\n configurable: true,\n value: {\n methodCache: new Map<PropertyKey, unknown>(),\n state,\n upstream,\n } satisfies EffectInternals<TUpstream>,\n },\n });\n}\n\nexport function getEffectInternals<TUpstream extends object>(\n target: EffectProxyTarget<TUpstream>,\n): EffectInternals<TUpstream> {\n return target[effectInternalsSymbol];\n}\n\nexport function getEffectUpstream<TUpstream extends object>(\n target: EffectProxyTarget<TUpstream>,\n): TUpstream {\n return getEffectInternals(target).upstream;\n}\n\nexport function getEffectState(\n target: EffectProxyTarget,\n): EffectExtensionState {\n return getEffectInternals(target).state;\n}\n\nexport function getEffectMethodCache(\n target: EffectProxyTarget,\n): Map<PropertyKey, unknown> {\n return getEffectInternals(target).methodCache;\n}\n\nexport function hasEffectState(value: unknown): value is EffectProxyTarget {\n return (\n typeof value === \"object\" &&\n value !== null &&\n effectInternalsSymbol in (value as object)\n );\n}\n\nexport function assertEffectState<TUpstream extends object>(\n value: object,\n): asserts value is EffectProxyTarget<TUpstream> {\n if (!hasEffectState(value)) {\n throw new Error(\"Expected effect state to be attached\");\n }\n}\n\nexport function getEffectErrorMap(value: {\n \"~effect\"?: { effectErrorMap: EffectErrorMap };\n \"~orpc\": { errorMap: EffectErrorMap };\n}): EffectErrorMap {\n return value[\"~effect\"]?.effectErrorMap ?? value[\"~orpc\"].errorMap;\n}\n\nexport function unwrapEffectUpstream<T extends object>(value: T): T {\n return hasEffectState(value) ? (getEffectUpstream(value) as T) : value;\n}\n","import {\n effectInternalsSymbol,\n getEffectInternals,\n type EffectExtensionState,\n type EffectProxyTarget,\n} from \"./state\";\n\nconst unhandledProperty = Symbol(\"effect-orpc/unhandledProperty\");\n\nexport type UnhandledProperty = typeof unhandledProperty;\n\nexport interface NodeProxyContext<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n> {\n methodCache: Map<PropertyKey, unknown>;\n state: EffectExtensionState;\n target: TTarget;\n upstream: TSource;\n}\n\ninterface NodeProxyInternalConfig<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n> {\n getProperty?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n getVirtual?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n virtualDescriptors?: Partial<\n Record<string | symbol, Pick<PropertyDescriptor, \"enumerable\">>\n >;\n virtualKeys?: readonly (string | symbol)[];\n wrapResult?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n result: unknown,\n receiver: unknown,\n ) => unknown;\n}\n\n/**\n * Configures how an Effect-aware node proxy exposes virtual properties and\n * rewrites returned values while the upstream builder/procedure remains the\n * source of truth for passthrough behavior.\n */\nexport interface NodeProxyConfig<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n> extends NodeProxyInternalConfig<TTarget, TSource> {\n /**\n * Returns a value for virtual properties such as `~effect` or custom\n * proxy-backed methods. Return `unhandled()` to fall back to the next step.\n */\n getVirtual?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n /**\n * Intercepts property access before upstream passthrough. Return\n * `unhandled()` to delegate to the wrapped upstream node.\n */\n getProperty?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n /**\n * Declares which virtual keys should appear in reflection APIs like `in`,\n * `Object.keys`, and descriptor lookup.\n */\n virtualKeys?: readonly (string | symbol)[];\n /**\n * Controls enumerability for virtual keys exposed through the proxy.\n */\n virtualDescriptors?: Partial<\n Record<string | symbol, Pick<PropertyDescriptor, \"enumerable\">>\n >;\n /**\n * Rewraps upstream method results when they should stay inside the Effect\n * extension model.\n */\n wrapResult?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n result: unknown,\n receiver: unknown,\n ) => unknown;\n}\n\nfunction createNodeProxyContext<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n>(target: TTarget): NodeProxyContext<TTarget, TSource> {\n const internals = getEffectInternals(target);\n return {\n methodCache: internals.methodCache,\n state: internals.state,\n target,\n upstream: internals.upstream as TSource,\n };\n}\n\nfunction createBoundMethod<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n>(\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n value: (...args: unknown[]) => unknown,\n config: NodeProxyInternalConfig<TTarget, TSource>,\n receiver: unknown,\n): (...args: unknown[]) => unknown {\n const cache = context.methodCache;\n if (cache.has(prop)) {\n return cache.get(prop) as (...args: unknown[]) => unknown;\n }\n\n const wrapped = (...args: unknown[]) => {\n const result = Reflect.apply(value, context.upstream, args);\n return config.wrapResult?.(context, prop, result, receiver) ?? result;\n };\n\n cache.set(prop, wrapped);\n return wrapped;\n}\n\n/**\n * Creates an Effect-aware proxy around a local shell object.\n *\n * @param target The local Effect wrapper instance that already has upstream and\n * state symbols attached via `attachEffectState`.\n * @param config The extension hooks that define virtual properties,\n * interception points, and result rewrapping behavior for the proxy.\n */\nexport function createNodeProxy<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n>(target: TTarget, config: NodeProxyConfig<TTarget, TSource>): TTarget {\n const privateKeys = new Set<PropertyKey>([effectInternalsSymbol]);\n const virtualKeys = new Set(config.virtualKeys ?? []);\n\n return new Proxy(target, {\n get(currentTarget, prop, receiver) {\n if (privateKeys.has(prop)) {\n return Reflect.get(currentTarget, prop, receiver);\n }\n\n const context = createNodeProxyContext<TTarget, TSource>(\n currentTarget as TTarget,\n );\n\n const virtualValue = config.getVirtual?.(context, prop, receiver);\n if (virtualValue !== undefined && virtualValue !== unhandledProperty) {\n return virtualValue;\n }\n\n const propertyValue = config.getProperty?.(context, prop, receiver);\n if (propertyValue !== undefined && propertyValue !== unhandledProperty) {\n return propertyValue;\n }\n\n const sourceValue = Reflect.get(context.upstream, prop, context.upstream);\n\n if (Reflect.has(context.upstream, prop)) {\n if (typeof sourceValue === \"function\") {\n return createBoundMethod(\n context,\n prop,\n sourceValue as (...args: unknown[]) => unknown,\n config,\n receiver,\n );\n }\n\n return sourceValue;\n }\n\n return Reflect.get(currentTarget, prop, receiver);\n },\n\n has(currentTarget, prop) {\n if (virtualKeys.has(prop)) {\n return true;\n }\n\n const context = createNodeProxyContext<TTarget, TSource>(currentTarget);\n return (\n Reflect.has(context.upstream, prop) || Reflect.has(currentTarget, prop)\n );\n },\n\n ownKeys(currentTarget) {\n const keys = new Set<string | symbol>();\n\n for (const key of Reflect.ownKeys(currentTarget)) {\n if (!privateKeys.has(key)) {\n keys.add(key);\n }\n }\n\n const context = createNodeProxyContext<TTarget, TSource>(\n currentTarget as TTarget,\n );\n\n for (const key of Reflect.ownKeys(context.upstream)) {\n keys.add(key);\n }\n\n for (const key of virtualKeys) {\n keys.add(key);\n }\n\n return [...keys];\n },\n\n getOwnPropertyDescriptor(currentTarget, prop) {\n const context = createNodeProxyContext<TTarget, TSource>(\n currentTarget as TTarget,\n );\n\n if (virtualKeys.has(prop)) {\n const value = config.getVirtual?.(context, prop, currentTarget);\n if (value !== undefined && value !== unhandledProperty) {\n return {\n configurable: true,\n enumerable: config.virtualDescriptors?.[prop]?.enumerable ?? false,\n value,\n writable: false,\n };\n }\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(\n context.upstream,\n prop,\n );\n\n if (descriptor === undefined) {\n return Reflect.getOwnPropertyDescriptor(currentTarget, prop);\n }\n\n if (\"value\" in descriptor && typeof descriptor.value === \"function\") {\n return {\n ...descriptor,\n value: createBoundMethod(\n context,\n prop,\n descriptor.value as (...args: unknown[]) => unknown,\n config,\n currentTarget,\n ),\n };\n }\n\n return descriptor;\n },\n });\n}\n\nexport function unhandled(): UnhandledProperty {\n return unhandledProperty;\n}\n","import type {\n ORPCErrorCode,\n ORPCErrorJSON,\n ORPCErrorOptions,\n} from \"@orpc/client\";\nimport {\n fallbackORPCErrorMessage,\n fallbackORPCErrorStatus,\n isORPCErrorStatus,\n ORPCError,\n} from \"@orpc/client\";\nimport type {\n AnySchema,\n ErrorMap,\n ErrorMapItem,\n InferSchemaOutput,\n} from \"@orpc/contract\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\nimport { resolveMaybeOptionalOptions } from \"@orpc/shared\";\nimport type { Pipeable } from \"effect\";\nimport * as Cause from \"effect/Cause\";\nimport * as Data from \"effect/Data\";\n\nimport type { EffectErrorMapToErrorMap } from \"./types\";\n\n/**\n * Symbol to access the underlying ORPCError instance\n */\nexport const ORPCErrorSymbol: unique symbol = Symbol.for(\n \"@orpc/effect/ORPCTaggedError\",\n);\n\n/**\n * Instance type for ORPCTaggedError that combines YieldableError with ORPCError properties\n */\nexport interface ORPCTaggedErrorInstance<\n TTag extends string,\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n>\n extends Cause.YieldableError, Pipeable.Pipeable {\n readonly _tag: TTag;\n readonly code: TCode;\n readonly status: number;\n readonly schema: TSchema;\n readonly data: InferSchemaOutput<TSchema>;\n readonly defined: boolean;\n readonly [ORPCErrorSymbol]: ORPCError<TCode, InferSchemaOutput<TSchema>>;\n\n toJSON(): ORPCErrorJSON<TCode, InferSchemaOutput<TSchema>> & { _tag: TTag };\n toORPCError(): ORPCError<TCode, InferSchemaOutput<TSchema>>;\n}\n\n/**\n * Options for creating an ORPCTaggedError\n */\nexport type ORPCTaggedErrorOptions<TData> = Omit<\n ORPCErrorOptions<TData>,\n \"defined\"\n> & { defined?: boolean };\n\n/**\n * Constructor type for ORPCTaggedError classes\n */\nexport interface ORPCTaggedErrorClass<\n TTag extends string,\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n> {\n readonly _tag: TTag;\n readonly code: TCode;\n new (\n ...args: MaybeOptionalOptions<\n ORPCTaggedErrorOptions<InferSchemaOutput<TSchema>>\n >\n ): ORPCTaggedErrorInstance<TTag, TCode, TSchema>;\n}\n\n/**\n * Type helper to infer the ORPCError type from an ORPCTaggedError\n */\nexport type InferORPCError<T> =\n T extends ORPCTaggedErrorInstance<string, infer TCode, infer TSchema>\n ? ORPCError<TCode, InferSchemaOutput<TSchema>>\n : never;\n\n/**\n * Any ORPCTaggedErrorClass\n * Uses `...args: any[]` for the constructor to accept any tagged error class,\n * regardless of whether TData requires options to be provided.\n */\nexport type AnyORPCTaggedErrorClass = {\n readonly _tag: string;\n readonly code: ORPCErrorCode;\n new (\n ...args: any[]\n ): ORPCTaggedErrorInstance<string, ORPCErrorCode, AnySchema>;\n};\n\n/**\n * Check if a value is an ORPCTaggedErrorClass (constructor)\n */\nexport function isORPCTaggedErrorClass(\n value: unknown,\n): value is AnyORPCTaggedErrorClass {\n return (\n typeof value === \"function\" &&\n \"_tag\" in value &&\n \"code\" in value &&\n typeof value._tag === \"string\" &&\n typeof value.code === \"string\"\n );\n}\n\n/**\n * Check if a value is an ORPCTaggedError instance\n */\nexport function isORPCTaggedError(\n value: unknown,\n): value is ORPCTaggedErrorInstance<string, ORPCErrorCode, AnySchema> {\n return (\n typeof value === \"object\" && value !== null && ORPCErrorSymbol in value\n );\n}\n\n/**\n * Converts a PascalCase or camelCase string to CONSTANT_CASE.\n * e.g., \"UserNotFoundError\" -> \"USER_NOT_FOUND_ERROR\"\n */\nfunction toConstantCase<T extends string>(str: T): ToConstantCase<T> {\n return str\n .replace(/([a-z])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toUpperCase() as ToConstantCase<T>;\n}\n/**\n * Checks if a character is an uppercase letter (A-Z)\n */\ntype IsUpperLetter<C extends string> =\n C extends Uppercase<C>\n ? C extends Lowercase<C>\n ? false // Not a letter (number, special char)\n : true\n : false;\n\n/**\n * Checks if a character is a lowercase letter (a-z)\n */\ntype IsLowerLetter<C extends string> =\n C extends Lowercase<C>\n ? C extends Uppercase<C>\n ? false // Not a letter (number, special char)\n : true\n : false;\n\n/**\n * Converts PascalCase or camelCase to CONSTANT_CASE.\n * Handles consecutive uppercase letters correctly.\n *\n * @example\n * type T1 = ToConstantCase<\"ABCCode\">; // \"ABC_CODE\"\n * type T2 = ToConstantCase<\"UserCode\">; // \"USER_CODE\"\n * type T3 = ToConstantCase<\"XMLHttpRequest\">; // \"XML_HTTP_REQUEST\"\n */\ntype ToConstantCase<\n S extends string,\n Acc extends string = \"\",\n PrevChar extends string = \"\",\n InUpperSequence extends boolean = false,\n> = S extends `${infer Head}${infer Tail}`\n ? IsUpperLetter<Head> extends true\n ? Acc extends \"\"\n ? // First character - no underscore\n ToConstantCase<Tail, Head, Head, false>\n : PrevChar extends \"\"\n ? // Shouldn't happen, but handle gracefully\n ToConstantCase<Tail, Head, Head, false>\n : IsUpperLetter<PrevChar> extends true\n ? // We're in an uppercase sequence\n Tail extends `${infer Next}${infer _}`\n ? IsLowerLetter<Next> extends true\n ? // Next char is lowercase, so Head starts a new word - insert underscore\n ToConstantCase<Tail, `${Acc}_${Head}`, Head, false>\n : // Next char is uppercase or non-letter - continue sequence\n ToConstantCase<Tail, `${Acc}${Head}`, Head, true>\n : // Tail is empty - just append\n ToConstantCase<Tail, `${Acc}${Head}`, Head, true>\n : // Transition from lowercase to uppercase - insert underscore\n ToConstantCase<Tail, `${Acc}_${Head}`, Head, false>\n : IsLowerLetter<Head> extends true\n ? InUpperSequence extends true\n ? // End of uppercase sequence (2+) - insert underscore before lowercase\n ToConstantCase<Tail, `${Acc}_${Uppercase<Head>}`, Head, false>\n : // Single uppercase or no uppercase - no underscore\n ToConstantCase<Tail, `${Acc}${Uppercase<Head>}`, Head, false>\n : // Non-letter character - reset sequence\n ToConstantCase<Tail, `${Acc}${Head}`, Head, false>\n : Acc;\n\n/**\n * Converts a tag name to an error code in CONSTANT_CASE.\n */\nexport type TagToCode<TTag extends string> = ToConstantCase<TTag>;\n\n/**\n * Creates a tagged error class that combines Effect's YieldableError with ORPCError.\n *\n * This allows you to create errors that:\n * - Can be yielded in Effect generators (`yield* myError`)\n * - Have all ORPCError properties (code, status, data, defined)\n * - Can be converted to a plain ORPCError for oRPC handlers\n *\n * The returned factory function takes:\n * - `tag` - The unique tag for this error type (used for discriminated unions)\n * - `codeOrOptions` - Optional ORPC error code or options. If omitted, code defaults to CONSTANT_CASE of tag\n * - `defaultOptions` - Optional default options for status and message (when code is provided)\n *\n * @example\n * ```ts\n * import { ORPCTaggedError } from '@orpc/effect'\n * import { Effect } from 'effect'\n *\n * // Define a custom error (code defaults to 'USER_NOT_FOUND_ERROR')\n * class UserNotFoundError extends ORPCTaggedError<UserNotFoundError>()('UserNotFoundError') {}\n *\n * // With explicit code\n * class NotFoundError extends ORPCTaggedError<NotFoundError>()('NotFoundError', 'NOT_FOUND') {}\n *\n * // Use in an Effect\n * const getUser = (id: string) => Effect.gen(function* () {\n * const user = yield* findUser(id)\n * if (!user) {\n * return yield* new UserNotFoundError({ data: { userId: id } })\n * }\n * return user\n * })\n *\n * // With custom data type\n * class ValidationError extends ORPCTaggedError<ValidationError, { fields: string[] }>()('ValidationError', 'BAD_REQUEST') {}\n *\n * // With options only (code defaults to 'VALIDATION_ERROR')\n * class ValidationError2 extends ORPCTaggedError<ValidationError2, { fields: string[] }>()(\n * 'ValidationError2',\n * { message: 'Validation failed' }\n * ) {}\n * ```\n */\nexport function ORPCTaggedError<\n TTag extends string,\n TSchema extends AnySchema = AnySchema,\n TCode extends ORPCErrorCode = ToConstantCase<TTag>,\n>(\n tag: TTag,\n props?: {\n schema?: TSchema;\n status?: number;\n message?: string;\n code?: TCode;\n },\n): ORPCTaggedErrorClass<TTag, TCode, TSchema> {\n const code: TCode = props?.code ?? (toConstantCase(tag) as any);\n class ORPCTaggedErrorBase\n extends Data.TaggedError(tag)\n implements ORPCTaggedErrorInstance<TTag, TCode, TSchema>\n {\n readonly status: number;\n readonly defined: boolean;\n readonly data: InferSchemaOutput<TSchema>;\n readonly code: TCode = code;\n readonly schema = props?.schema as TSchema;\n readonly [ORPCErrorSymbol]: ORPCError<TCode, InferSchemaOutput<TSchema>>;\n\n constructor(\n ...rest: MaybeOptionalOptions<\n ORPCTaggedErrorOptions<InferSchemaOutput<TSchema>>\n >\n ) {\n super();\n\n const opts = resolveMaybeOptionalOptions(rest);\n const status = opts.status ?? props?.status;\n\n if (status !== undefined && !isORPCErrorStatus(status)) {\n throw new globalThis.Error(\n \"[ORPCTaggedError] Invalid error status code.\",\n );\n }\n\n this.status = fallbackORPCErrorStatus(code, status);\n this.defined = opts.defined ?? true;\n this.data = opts.data as InferSchemaOutput<TSchema>;\n this.message = fallbackORPCErrorMessage(\n this.code,\n opts.message ?? props?.message,\n );\n this.cause = opts.cause;\n\n this[ORPCErrorSymbol] = new ORPCError<TCode, InferSchemaOutput<TSchema>>(\n this.code,\n {\n status: this.status,\n message: this.message,\n data: this.data,\n defined: this.defined,\n cause: this.cause,\n },\n );\n }\n\n /**\n * Converts this error to a plain ORPCError.\n * Useful when you need to return from an oRPC handler.\n */\n toORPCError(): ORPCError<TCode, InferSchemaOutput<TSchema>> {\n return this[ORPCErrorSymbol];\n }\n\n override toJSON(): ORPCErrorJSON<TCode, InferSchemaOutput<TSchema>> & {\n _tag: TTag;\n } {\n return {\n _tag: this._tag,\n defined: this[ORPCErrorSymbol].defined,\n code: this[ORPCErrorSymbol].code,\n status: this[ORPCErrorSymbol].status,\n message: this[ORPCErrorSymbol].message,\n data: this[ORPCErrorSymbol].data,\n };\n }\n }\n\n return Object.assign(ORPCTaggedErrorBase, {\n _tag: tag,\n code,\n } as const);\n}\n\n/**\n * Converts an ORPCTaggedError to a plain ORPCError.\n * Useful in handlers that need to throw ORPCError.\n *\n * @example\n * ```ts\n * const handler = effectOs.effect(function* () {\n * const result = yield* someOperation.pipe(\n * Effect.catchTag('UserNotFoundError', (e) =>\n * Effect.fail(toORPCError(e))\n * )\n * )\n * return result\n * })\n * ```\n */\nexport function toORPCError<\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n>(\n error: ORPCTaggedErrorInstance<string, TCode, TSchema>,\n): ORPCError<TCode, InferSchemaOutput<TSchema>> {\n return error[ORPCErrorSymbol];\n}\n\n// ============================================================================\n// Extended Error Map Types for Effect\n// ============================================================================\n\n/**\n * An item in the EffectErrorMap - can be either a traditional ErrorMapItem or an ORPCTaggedErrorClass\n */\nexport type EffectErrorMapItem =\n | ErrorMapItem<AnySchema>\n | AnyORPCTaggedErrorClass;\n\nexport type ORPCTaggedErrorClassToErrorMapItem<T> =\n T extends ORPCTaggedErrorClass<any, any, infer TData>\n ? {\n status?: number;\n message?: string;\n data?: TData;\n }\n : never;\n\n/**\n * Extended error map that supports both traditional oRPC errors and ORPCTaggedError classes.\n *\n * @example\n * ```ts\n * const errorMap = {\n * // Traditional format\n * BAD_REQUEST: { status: 400, message: 'Bad request' },\n *\n * // Tagged error class reference\n * USER_NOT_FOUND: UserNotFoundError,\n * } satisfies EffectErrorMap\n * ```\n */\nexport type EffectErrorMap = {\n [key in ORPCErrorCode]?: EffectErrorMapItem;\n};\n\n/**\n * Merges two EffectErrorMaps, with the second map taking precedence.\n */\nexport type MergedEffectErrorMap<\n T1 extends EffectErrorMap,\n T2 extends EffectErrorMap,\n> = Omit<T1, keyof T2> & T2;\n\n/**\n * Extracts the instance type from an EffectErrorMapItem\n */\nexport type EffectErrorMapItemToInstance<\n TCode extends ORPCErrorCode,\n T extends EffectErrorMapItem,\n> = T extends AnyORPCTaggedErrorClass\n ? InstanceType<T>\n : T extends { data?: infer TData }\n ? ORPCError<TCode, TData>\n : ORPCError<TCode, unknown>;\n\n/**\n * Converts an EffectErrorMap to a union of error instances.\n */\nexport type EffectErrorMapToUnion<T extends EffectErrorMap> = {\n [K in keyof T]: K extends ORPCErrorCode\n ? T[K] extends EffectErrorMapItem\n ? EffectErrorMapItemToInstance<K, T[K]>\n : never\n : never;\n}[keyof T];\n\n/**\n * Constructor map for EffectErrorMap - provides typed error constructors for handlers.\n */\ntype EffectErrorConstructor<\n TCode extends ORPCErrorCode,\n TItem,\n> = TItem extends AnyORPCTaggedErrorClass\n ? (...args: ConstructorParameters<TItem>) => InstanceType<TItem>\n : TItem extends { data?: infer TSchema extends AnySchema }\n ? (\n ...rest: MaybeOptionalOptions<\n Omit<\n ORPCErrorOptions<InferSchemaOutput<TSchema>>,\n \"defined\" | \"status\"\n >\n >\n ) => ORPCError<TCode, InferSchemaOutput<TSchema>>\n : (\n ...rest: MaybeOptionalOptions<\n Omit<ORPCErrorOptions<unknown>, \"defined\" | \"status\">\n >\n ) => ORPCError<TCode, unknown>;\n\nexport type EffectErrorConstructorMap<T extends EffectErrorMap> = {\n [K in Extract<keyof T, ORPCErrorCode>]: EffectErrorConstructor<K, T[K]>;\n};\n\n/**\n * Creates an error constructor map from an EffectErrorMap.\n * Tagged error classes are passed through directly.\n * Traditional error items become ORPCError factory functions.\n */\nexport function createEffectErrorConstructorMap<T extends EffectErrorMap>(\n errors: T | undefined,\n): EffectErrorConstructorMap<T> {\n const target = errors ?? ({} as T);\n const proxy = new Proxy(target, {\n get(proxyTarget, code) {\n if (typeof code !== \"string\") {\n return Reflect.get(proxyTarget, code);\n }\n\n const config = target[code];\n\n // If it's a tagged error class, create a class constructor function\n if (isORPCTaggedErrorClass(config)) {\n return (\n ...opts: MaybeOptionalOptions<ORPCTaggedErrorOptions<unknown>>\n ) => new config(...opts);\n }\n\n // Otherwise, create a factory function for ORPCError\n return (\n ...rest: MaybeOptionalOptions<\n Omit<ORPCErrorOptions<unknown>, \"defined\" | \"status\">\n >\n ) => {\n const options = resolveMaybeOptionalOptions(rest);\n return new ORPCError(code, {\n defined: Boolean(config),\n status: config?.status,\n message: options.message ?? config?.message,\n data: options.data,\n cause: options.cause,\n });\n };\n },\n });\n\n return proxy as unknown as EffectErrorConstructorMap<T>;\n}\n\n/**\n * Converts an EffectErrorMap to a standard oRPC ErrorMap for interop.\n * Tagged error classes are converted to their equivalent ErrorMapItem format.\n */\nexport function effectErrorMapToErrorMap<T extends EffectErrorMap>(\n errorMap: T | undefined,\n): EffectErrorMapToErrorMap<T> {\n const result: ErrorMap = {};\n\n if (!errorMap) {\n return result as ErrorMap & EffectErrorMapToErrorMap<T>;\n }\n\n for (const [code, ClassOrErrorItem] of Object.entries(errorMap)) {\n if (!ClassOrErrorItem) {\n continue;\n }\n\n if (isORPCTaggedErrorClass(ClassOrErrorItem)) {\n const classInstance = new ClassOrErrorItem();\n result[classInstance.code] = {\n status: classInstance.status,\n message: classInstance.message,\n data: classInstance.schema,\n };\n } else {\n result[code] = ClassOrErrorItem;\n }\n }\n\n return result as ErrorMap & EffectErrorMapToErrorMap<T>;\n}\n","import { ORPCError } from \"@orpc/contract\";\nimport type {\n Context,\n ProcedureHandler,\n ProcedureHandlerOptions,\n} from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect\";\nimport { Cause, Effect, Exit, FiberRefs } from \"effect\";\n\nimport { getCurrentFiberRefs } from \"./fiber-context-bridge\";\nimport type { EffectErrorConstructorMap, EffectErrorMap } from \"./tagged-error\";\nimport {\n createEffectErrorConstructorMap,\n isORPCTaggedError,\n} from \"./tagged-error\";\nimport type { EffectProcedureHandler, EffectSpanConfig } from \"./types\";\n\nexport function toORPCErrorFromCause(\n cause: Cause.Cause<unknown>,\n): ORPCError<string, unknown> {\n return Cause.match(cause, {\n onDie(defect) {\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: defect,\n });\n },\n onFail(error) {\n if (isORPCTaggedError(error)) {\n return error.toORPCError();\n }\n if (error instanceof ORPCError) {\n return error;\n }\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: error,\n });\n },\n onInterrupt(fiberId) {\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: new Error(`${fiberId} Interrupted`),\n });\n },\n onSequential(left) {\n return left;\n },\n onEmpty: new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: new Error(\"Unknown error\"),\n }),\n onParallel(left) {\n return left;\n },\n });\n}\n\nexport function createEffectProcedureHandler<\n TCurrentContext extends Context,\n TInput,\n TOutput,\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n TMeta,\n>(options: {\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;\n effectErrorMap: TEffectErrorMap;\n effectFn: EffectProcedureHandler<\n TCurrentContext,\n TInput,\n TOutput,\n TEffectErrorMap,\n TRequirementsProvided,\n any\n >;\n spanConfig?: EffectSpanConfig;\n defaultCaptureStackTrace: () => string | undefined;\n}): ProcedureHandler<\n TCurrentContext,\n TInput,\n TOutput,\n any,\n TMeta & Record<never, never>\n> {\n const {\n runtime,\n effectErrorMap,\n effectFn,\n spanConfig,\n defaultCaptureStackTrace,\n } = options;\n\n return async (opts) => {\n const effectOpts: ProcedureHandlerOptions<\n TCurrentContext,\n TInput,\n EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta & Record<never, never>\n > = {\n context: opts.context,\n input: opts.input,\n path: opts.path,\n procedure: opts.procedure,\n signal: opts.signal,\n lastEventId: opts.lastEventId,\n errors: createEffectErrorConstructorMap(effectErrorMap),\n };\n\n const spanName = spanConfig?.name ?? opts.path.join(\".\");\n const captureStackTrace =\n spanConfig?.captureStackTrace ?? defaultCaptureStackTrace;\n const resolver = Effect.fnUntraced(effectFn as any);\n const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {\n captureStackTrace,\n });\n const parentFiberRefs = getCurrentFiberRefs();\n const effectWithRefs = parentFiberRefs\n ? Effect.fiberIdWith((fiberId) =>\n Effect.flatMap(Effect.getFiberRefs, (fiberRefs) =>\n Effect.setFiberRefs(\n FiberRefs.joinAs(fiberRefs, fiberId, parentFiberRefs),\n ).pipe(Effect.andThen(tracedEffect)),\n ),\n )\n : tracedEffect;\n const exit = await runtime.runPromiseExit(effectWithRefs, {\n signal: opts.signal,\n });\n\n if (Exit.isFailure(exit)) {\n throw toORPCErrorFromCause(exit.cause);\n }\n\n return exit.value as TOutput;\n };\n}\n","import type {\n AnySchema,\n ContractProcedure,\n ContractRouter,\n ErrorMap,\n HTTPPath,\n Meta,\n Route,\n Schema,\n} from \"@orpc/contract\";\nimport { isContractProcedure, oc } from \"@orpc/contract\";\n\nimport type { EffectErrorMap, MergedEffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap } from \"./types\";\n\nexport const effectContractSymbol: unique symbol = Symbol.for(\n \"@orpc/effect/contract\",\n);\n\ninterface EffectContractMetadata<TEffectErrorMap extends EffectErrorMap> {\n readonly [effectContractSymbol]: {\n readonly errorMap: TEffectErrorMap;\n };\n}\n\ntype LocalEffectErrorMap<T> =\n T extends EffectContractMetadata<infer TEffectErrorMap extends EffectErrorMap>\n ? TEffectErrorMap\n : Record<never, never>;\n\ntype ContractWithEffectErrorMap<T, TEffectErrorMap extends EffectErrorMap> =\n T extends ContractProcedure<\n infer TInputSchema,\n infer TOutputSchema,\n infer TErrorMap extends ErrorMap,\n infer TMeta extends Meta\n >\n ? ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> &\n EffectContractMetadata<\n MergedEffectErrorMap<TEffectErrorMap, LocalEffectErrorMap<T>>\n >\n : T extends ContractRouter<Meta>\n ? {\n [K in keyof T]: ContractWithEffectErrorMap<T[K], TEffectErrorMap>;\n }\n : never;\n\nexport interface EffectContractProcedureBuilder<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n input<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInput<\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n output<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n U,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractProcedureBuilderWithInput<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilderWithInput<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilderWithInput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilderWithInput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n output<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n U,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractProcedureBuilderWithOutput<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n input<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInputOutput<\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractProcedureBuilderWithInputOutput<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractRouterBuilder<\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n> extends EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractRouterBuilder<\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n prefix(prefix: HTTPPath): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n tag(...tags: string[]): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n router<T extends ContractRouter<TMeta>>(\n router: T,\n ): ContractWithEffectErrorMap<T, TEffectErrorMap>;\n}\n\nexport interface EffectContractBuilder<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n $meta<U extends Meta>(\n initialMeta: U,\n ): EffectContractBuilder<TInputSchema, TOutputSchema, TEffectErrorMap, U>;\n $route(\n initialRoute: Route,\n ): EffectContractBuilder<TInputSchema, TOutputSchema, TEffectErrorMap, TMeta>;\n $input<U extends AnySchema>(\n initialInputSchema?: U,\n ): EffectContractBuilder<U, TOutputSchema, TEffectErrorMap, TMeta>;\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractBuilder<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n input<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInput<\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n output<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n U,\n TEffectErrorMap,\n TMeta\n >;\n prefix(prefix: HTTPPath): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n tag(...tags: string[]): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n router<T extends ContractRouter<TMeta>>(\n router: T,\n ): ContractWithEffectErrorMap<T, TEffectErrorMap>;\n}\n\nfunction isWrappableContractBuilder(value: unknown): value is {\n \"~orpc\": { errorMap: ErrorMap };\n} {\n return typeof value === \"object\" && value !== null && \"~orpc\" in value;\n}\n\nfunction mergeEffectErrorMaps(\n left: EffectErrorMap | undefined,\n right: EffectErrorMap | undefined,\n): EffectErrorMap | undefined {\n if (!left) {\n return right;\n }\n\n if (!right) {\n return left;\n }\n\n return {\n ...left,\n ...right,\n };\n}\n\nfunction setEffectContractErrorMap(\n value: object,\n effectErrorMap: EffectErrorMap | undefined,\n): void {\n if (!effectErrorMap) {\n return;\n }\n\n Object.defineProperty(value, effectContractSymbol, {\n value: { errorMap: effectErrorMap },\n enumerable: false,\n configurable: true,\n });\n}\n\nexport function getEffectContractErrorMap(\n value: unknown,\n): EffectErrorMap | undefined {\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n return (value as Partial<EffectContractMetadata<EffectErrorMap>>)[\n effectContractSymbol\n ]?.errorMap;\n}\n\nfunction applyEffectContractErrorMapToRouter(\n router: ContractRouter<Meta>,\n source: ContractRouter<Meta> | undefined,\n inheritedEffectErrorMap: EffectErrorMap | undefined,\n): void {\n const routerRecord = router as Record<string, ContractRouter<Meta>>;\n const sourceRecord = source as\n | Record<string, ContractRouter<Meta>>\n | undefined;\n\n for (const key of Object.keys(routerRecord)) {\n const routerValue = routerRecord[key];\n const sourceValue =\n sourceRecord && typeof sourceRecord === \"object\"\n ? sourceRecord[key]\n : undefined;\n\n if (!routerValue) {\n continue;\n }\n\n if (isContractProcedure(routerValue)) {\n const sourceEffectErrorMap = getEffectContractErrorMap(sourceValue);\n setEffectContractErrorMap(\n routerValue,\n mergeEffectErrorMaps(inheritedEffectErrorMap, sourceEffectErrorMap),\n );\n continue;\n }\n\n if (typeof routerValue === \"object\") {\n applyEffectContractErrorMapToRouter(\n routerValue,\n sourceValue as ContractRouter<Meta> | undefined,\n inheritedEffectErrorMap,\n );\n }\n }\n}\n\nfunction wrapEffectContractBuilder<T>(\n builder: T,\n inheritedEffectErrorMap?: EffectErrorMap,\n): T {\n const currentEffectErrorMap =\n inheritedEffectErrorMap ?? getEffectContractErrorMap(builder);\n\n if (typeof builder === \"object\" && builder !== null) {\n setEffectContractErrorMap(builder as object, currentEffectErrorMap);\n }\n\n const proxy = new Proxy(builder as object, {\n get(target, prop, receiver) {\n if (prop === effectContractSymbol) {\n return currentEffectErrorMap\n ? { errorMap: currentEffectErrorMap }\n : undefined;\n }\n\n if (prop === \"errors\") {\n return (errors: EffectErrorMap) => {\n const nextEffectErrorMap = mergeEffectErrorMaps(\n currentEffectErrorMap,\n errors,\n );\n\n return wrapEffectContractBuilder(\n Reflect.apply(Reflect.get(target, prop, receiver), target, [\n effectErrorMapToErrorMap(errors),\n ]),\n nextEffectErrorMap,\n );\n };\n }\n\n if (prop === \"router\") {\n return (router: ContractRouter<Meta>) => {\n const result = Reflect.apply(\n Reflect.get(target, prop, receiver),\n target,\n [router],\n ) as ContractRouter<Meta>;\n\n applyEffectContractErrorMapToRouter(\n result,\n router,\n currentEffectErrorMap,\n );\n\n return result;\n };\n }\n\n const value = Reflect.get(target, prop, receiver);\n if (typeof value !== \"function\") {\n return value;\n }\n\n return (...args: unknown[]) => {\n const result = Reflect.apply(value, target, args);\n return isWrappableContractBuilder(result)\n ? wrapEffectContractBuilder(result, currentEffectErrorMap)\n : result;\n };\n },\n }) as T;\n\n setEffectContractErrorMap(proxy as object, currentEffectErrorMap);\n\n return proxy;\n}\n\nexport const eoc = wrapEffectContractBuilder(\n oc,\n {},\n) as unknown as EffectContractBuilder<\n Schema<unknown, unknown>,\n Schema<unknown, unknown>,\n Record<never, never>,\n Record<never, never>\n>;\n"],"mappings":";;;;;AAWA,SAAS,uBAAAA,4BAA2B;AAgBpC,SAAS,iBAAiB;;;ACnB1B,SAAS,SAAS,gBAAgB,QAAAC,aAAY;;;ACR9C;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;;;ACfP,SAAS,WAAW,kBAAkB;AAQtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;AChBA,SAAS,oBAGd,SAAmB,QAAqC;AACxD,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,IAAI,eAAe,MAAM,UAAU;AACjC,aAAO,QAAQ,IAAI,SAAS,IAAI,IAC5B,QAAQ,IAAI,SAAS,MAAM,OAAO,IAClC,QAAQ,IAAI,eAAe,MAAM,QAAQ;AAAA,IAC/C;AAAA,IACA,IAAI,e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ACA;AAAA,YACF;AAAA,YACA;AAAA,UACF;AAEF,gBAAM,IAAI,MAAM,aAAa;AAC7B,iBAAO;AAAA,QACT;AAEA,YAAI,SAAS,YAAY,SAAS,QAAQ;AACxC,gBAAM,gBAAgB,IAAI,SACxB;AAAA,YACE,QAAQ;AAAA,cACN,QAAQ,IAAI,eAAe,MAAM,aAAa;AAAA,cAC9C;AAAA,cACA;AAAA,YACF;AAAA,YACA,mBAAmB,OAAO;AAAA,UAC5B;AAEF,gBAAM,IAAI,MAAM,aAAa;AAC7B,iBAAO;AAAA,QACT;AAEA,YAAI,OAAO,SAAS,YAAY,QAAQ,UAAU;AAChD,gBAAM,QAAQ;AAAA,YACX,SAA+C,IAAI;AAAA,YACpD,QAAQ,IAAI,eAAe,MAAM,QAAQ;AAAA,YACzC;AAAA,UACF;AAEA,gBAAM,IAAI,MAAM,KAAK;AACrB,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,YAAM,QAAQ,QAAQ,IAAI,eAAe,MAAM,QAAQ;AACvD,aAAO,OAAO,UAAU,aAAa,MAAM,KAAK,aAAa,IAAI;AAAA,IACnE;AAAA,IACA,IAAI,eAAe,MAAM;AACvB,UAAIA,qBAAoB,QAAQ,GAAG;AACjC,YAAI,SAAS,UAAU;AACrB,iBAAO;AAAA,QACT;AACA,YAAI,wBAAwB,IAAI,OAAO,IAAI,CAAC,GAAG;AAC7C,iBAAO;AAAA,QACT;AAAA,MACF,WAAW,OAAO,SAAS,YAAY,QAAQ,UAAU;AACvD,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,IAAI,eAAe,IAAI;AAAA,IACxC;AAAA,EACF,CAAC;AAOH;AAEO,SAAS,gBAKd,UACA,SAOA;AACA,SAAO;AAAA,IACL;AAAA,IACA,UAAU,QAAQ;AAAA,IAClB;AAAA,EACF;AAOF;","names":["isContractProcedure","lazy","enhanced","ORPCError","Cause","Cause","ORPCError","getOrCreateVirtualMethod","lazy","isContractProcedure"]}
1
+ {"version":3,"sources":["../src/contract.ts","../src/effect-builder.ts","../src/effect-enhance-router.ts","../src/effect-procedure.ts","../src/extension/compose-surfaces.ts","../src/extension/state.ts","../src/extension/create-node-proxy.ts","../src/tagged-error.ts","../src/effect-runtime.ts","../src/eoc.ts"],"sourcesContent":["import type {\n AnyContractRouter,\n AnySchema,\n ContractProcedure,\n ErrorMap,\n InferContractRouterErrorMap,\n InferContractRouterMeta,\n InferSchemaInput,\n InferSchemaOutput,\n Meta,\n} from \"@orpc/contract\";\nimport { isContractProcedure } from \"@orpc/contract\";\nimport type {\n BuilderConfig,\n BuilderDef,\n Context,\n DecoratedMiddleware,\n ImplementedProcedure,\n Lazy,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ORPCErrorConstructorMap,\n ProcedureHandler,\n Router,\n} from \"@orpc/server\";\nimport { implement } from \"@orpc/server\";\nimport type { IntersectPick } from \"@orpc/shared\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport { addSpanStackTrace } from \"./effect-builder\";\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport { createEffectProcedureHandler } from \"./effect-runtime\";\nimport { effectContractSymbol, getEffectContractErrorMap } from \"./eoc\";\nimport type { EffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureHandler } from \"./types\";\n\ntype ContractLeafEffectHandler<\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TMeta extends Meta,\n> = EffectProcedureHandler<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n InferSchemaInput<TOutputSchema>,\n TErrorMap,\n TRequirementsProvided,\n TMeta\n>;\n\ntype InferContractLeafEffectErrorMap<\n TContract,\n TErrorMap extends ErrorMap,\n> = TContract extends {\n [effectContractSymbol]: {\n errorMap: infer TEffectErrorMap extends EffectErrorMap;\n };\n}\n ? TEffectErrorMap\n : TErrorMap;\n\nexport interface EffectProcedureImplementer<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n> {\n \"~orpc\": BuilderDef<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TErrorMap>,\n TMeta\n >;\n use<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n UInContext extends Context = TCurrentContext,\n >(\n middleware: Middleware<\n UInContext | TCurrentContext,\n UOutContext,\n InferSchemaOutput<TInputSchema>,\n InferSchemaInput<TOutputSchema>,\n ORPCErrorConstructorMap<EffectErrorMapToErrorMap<TErrorMap>>,\n TMeta\n >,\n ): EffectProcedureImplementer<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n use<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n UInput,\n UInContext extends Context = TCurrentContext,\n >(\n middleware: Middleware<\n UInContext | TCurrentContext,\n UOutContext,\n UInput,\n InferSchemaInput<TOutputSchema>,\n ORPCErrorConstructorMap<EffectErrorMapToErrorMap<TErrorMap>>,\n TMeta\n >,\n mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,\n ): EffectProcedureImplementer<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n handler(\n handler: ProcedureHandler<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n InferSchemaInput<TOutputSchema>,\n EffectErrorMapToErrorMap<TErrorMap>,\n TMeta\n >,\n ): ImplementedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TErrorMap>,\n TMeta\n >;\n effect(\n effectFn: ContractLeafEffectHandler<\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TRequirementsProvided,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n}\n\nexport type EffectImplementerInternal<\n TContract extends AnyContractRouter,\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TRequirementsProvided,\n TRuntimeError,\n> =\n TContract extends ContractProcedure<\n infer TInputSchema,\n infer TOutputSchema,\n infer TErrorMap extends ErrorMap,\n infer TMeta extends Meta\n >\n ? EffectProcedureImplementer<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n InferContractLeafEffectErrorMap<TContract, TErrorMap>,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >\n : {\n middleware<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n TInput,\n TOutput = any,\n >(\n middleware: Middleware<\n TInitialContext,\n UOutContext,\n TInput,\n TOutput,\n ORPCErrorConstructorMap<InferContractRouterErrorMap<TContract>>,\n InferContractRouterMeta<TContract>\n >,\n ): DecoratedMiddleware<\n TInitialContext,\n UOutContext,\n TInput,\n TOutput,\n any,\n InferContractRouterMeta<TContract>\n >;\n use<\n UOutContext extends IntersectPick<TCurrentContext, UOutContext>,\n UInContext extends Context = TCurrentContext,\n >(\n middleware: Middleware<\n UInContext | TCurrentContext,\n UOutContext,\n unknown,\n unknown,\n ORPCErrorConstructorMap<InferContractRouterErrorMap<TContract>>,\n InferContractRouterMeta<TContract>\n >,\n ): EffectImplementerInternal<\n TContract,\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TRequirementsProvided,\n TRuntimeError\n >;\n router<U extends Router<TContract, TCurrentContext>>(\n router: U,\n ): ReturnType<\n typeof enhanceEffectRouter<\n U,\n TInitialContext,\n TCurrentContext,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n >\n >;\n lazy<U extends Router<TContract, TCurrentContext>>(\n loader: () => Promise<{ default: U }>,\n ): ReturnType<\n typeof enhanceEffectRouter<\n Lazy<U>,\n TInitialContext,\n TCurrentContext,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n >\n >;\n } & {\n [K in keyof TContract]: TContract[K] extends AnyContractRouter\n ? EffectImplementerInternal<\n TContract[K],\n TInitialContext,\n TCurrentContext,\n TRequirementsProvided,\n TRuntimeError\n >\n : never;\n };\n\nexport type EffectImplementer<\n TContract extends AnyContractRouter,\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TRequirementsProvided,\n TRuntimeError,\n> = {\n $context<U extends Context>(): EffectImplementer<\n TContract,\n U & Record<never, never>,\n U,\n TRequirementsProvided,\n TRuntimeError\n >;\n $config(\n config: BuilderConfig,\n ): EffectImplementer<\n TContract,\n TInitialContext,\n TCurrentContext,\n TRequirementsProvided,\n TRuntimeError\n >;\n} & EffectImplementerInternal<\n TContract,\n TInitialContext,\n TCurrentContext,\n TRequirementsProvided,\n TRuntimeError\n>;\n\nconst CONTRACT_HIDDEN_METHODS = new Set([\n \"$config\",\n \"$context\",\n \"$input\",\n \"$meta\",\n \"$route\",\n \"errors\",\n \"input\",\n \"lazy\",\n \"meta\",\n \"middleware\",\n \"output\",\n \"prefix\",\n \"route\",\n \"router\",\n \"tag\",\n]);\n\nfunction makeEnhanceOptions<TRequirementsProvided, TRuntimeError>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n) {\n return {\n middlewares: [],\n errorMap: {},\n dedupeLeadingMiddlewares: true,\n runtime,\n } as const;\n}\n\nfunction wrapContractNode<\n TContract extends AnyContractRouter,\n TRequirementsProvided,\n TRuntimeError,\n>(\n contract: TContract,\n target: any,\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n): EffectImplementerInternal<\n TContract,\n Context,\n Context,\n TRequirementsProvided,\n TRuntimeError\n> {\n const cache = new Map<PropertyKey, unknown>();\n\n return new Proxy(target, {\n get(currentTarget, prop, receiver) {\n if (cache.has(prop)) {\n return cache.get(prop);\n }\n\n if (isContractProcedure(contract)) {\n if (prop === \"effect\") {\n const effect = (\n effectFn: ContractLeafEffectHandler<any, any, any, any, any, any>,\n ) => {\n const effectErrorMap =\n getEffectContractErrorMap(contract) ??\n currentTarget[\"~orpc\"].errorMap;\n\n return new EffectDecoratedProcedure({\n ...currentTarget[\"~orpc\"],\n errorMap: effectErrorMapToErrorMap(effectErrorMap),\n effectErrorMap,\n runtime,\n handler: createEffectProcedureHandler({\n runtime,\n effectErrorMap,\n effectFn,\n defaultCaptureStackTrace: addSpanStackTrace(),\n }),\n });\n };\n\n cache.set(prop, effect);\n return effect;\n }\n\n if (prop === \"use\") {\n const use = (...args: unknown[]) =>\n wrapContractNode(\n contract,\n Reflect.apply(\n Reflect.get(currentTarget, prop, currentTarget),\n currentTarget,\n args,\n ),\n runtime,\n );\n\n cache.set(prop, use);\n return use;\n }\n\n if (CONTRACT_HIDDEN_METHODS.has(String(prop))) {\n return undefined;\n }\n } else {\n if (prop === \"$context\" || prop === \"$config\" || prop === \"use\") {\n const wrappedMethod = (...args: unknown[]) =>\n wrapContractNode(\n contract,\n Reflect.apply(\n Reflect.get(currentTarget, prop, currentTarget),\n currentTarget,\n args,\n ),\n runtime,\n );\n\n cache.set(prop, wrappedMethod);\n return wrappedMethod;\n }\n\n if (prop === \"router\" || prop === \"lazy\") {\n const wrappedMethod = (...args: unknown[]) =>\n enhanceEffectRouter(\n Reflect.apply(\n Reflect.get(currentTarget, prop, currentTarget),\n currentTarget,\n args,\n ) as any,\n makeEnhanceOptions(runtime),\n );\n\n cache.set(prop, wrappedMethod);\n return wrappedMethod;\n }\n\n if (typeof prop === \"string\" && prop in contract) {\n const child = wrapContractNode(\n (contract as Record<string, AnyContractRouter>)[prop]!,\n Reflect.get(currentTarget, prop, receiver),\n runtime,\n );\n\n cache.set(prop, child);\n return child;\n }\n }\n\n const value = Reflect.get(currentTarget, prop, receiver);\n return typeof value === \"function\" ? value.bind(currentTarget) : value;\n },\n has(currentTarget, prop) {\n if (isContractProcedure(contract)) {\n if (prop === \"effect\") {\n return true;\n }\n if (CONTRACT_HIDDEN_METHODS.has(String(prop))) {\n return false;\n }\n } else if (typeof prop === \"string\" && prop in contract) {\n return true;\n }\n\n return Reflect.has(currentTarget, prop);\n },\n }) as EffectImplementerInternal<\n TContract,\n Context,\n Context,\n TRequirementsProvided,\n TRuntimeError\n >;\n}\n\nexport function implementEffect<\n TContract extends AnyContractRouter,\n TRequirementsProvided,\n TRuntimeError,\n>(\n contract: TContract,\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n): EffectImplementer<\n TContract,\n Record<never, never>,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n> {\n return wrapContractNode(\n contract,\n implement(contract),\n runtime,\n ) as EffectImplementer<\n TContract,\n Record<never, never>,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n >;\n}\n","import type {\n AnySchema,\n ContractRouter,\n ErrorMap,\n Meta,\n Schema,\n} from \"@orpc/contract\";\nimport type { Context, Router } from \"@orpc/server\";\nimport { Builder, fallbackConfig, lazy } from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport { createEffectProcedureHandler } from \"./effect-runtime\";\nimport {\n createNodeProxy,\n unhandled,\n type NodeProxyContext,\n} from \"./extension/create-node-proxy\";\nimport {\n attachEffectState,\n getEffectErrorMap,\n unwrapEffectUpstream,\n type EffectProxyTarget,\n} from \"./extension/state\";\nimport type { EffectErrorMap, MergedEffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type {\n AnyBuilderLike,\n EffectBuilderDef,\n InferBuilderCurrentContext,\n InferBuilderErrorMap,\n InferBuilderInitialContext,\n InferBuilderInputSchema,\n InferBuilderMeta,\n InferBuilderOutputSchema,\n} from \"./types\";\nimport type { EffectBuilderSurface } from \"./types/effect-builder-surface\";\n\nconst builderVirtualDescriptors = {\n \"~effect\": { enumerable: true },\n effect: { enumerable: false },\n errors: { enumerable: false },\n handler: { enumerable: false },\n lazy: { enumerable: false },\n router: { enumerable: false },\n traced: { enumerable: false },\n} as const;\n\nconst builderVirtualKeys = [\n \"~effect\",\n \"errors\",\n \"effect\",\n \"traced\",\n \"handler\",\n \"router\",\n \"lazy\",\n] as const;\n\ntype EffectBuilderTarget = EffectBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n> &\n EffectProxyTarget<AnyBuilderLike>;\n\nfunction isBuilderLike(value: unknown): value is AnyBuilderLike {\n return typeof value === \"object\" && value !== null && \"~orpc\" in value;\n}\n\nfunction getOrCreateVirtualMethod<T>(\n context: NodeProxyContext<EffectBuilderTarget, AnyBuilderLike>,\n prop: PropertyKey,\n factory: () => T,\n): T {\n const cache = context.methodCache;\n if (cache.has(prop)) {\n return cache.get(prop) as T;\n }\n\n const value = factory();\n cache.set(prop, value);\n return value;\n}\n\nfunction getEffectBuilderDef(\n context: NodeProxyContext<EffectBuilderTarget, AnyBuilderLike>,\n): EffectBuilderDef<any, any, any, any, any, any> {\n return {\n ...context.upstream[\"~orpc\"],\n effectErrorMap: context.state.effectErrorMap,\n runtime: context.state.runtime,\n spanConfig: context.state.spanConfig,\n };\n}\n\nfunction wrapBuilderLike(\n builder: AnyBuilderLike,\n state: NodeProxyContext<EffectBuilderTarget, AnyBuilderLike>[\"state\"],\n): EffectBuilder<any, any, any, any, any, any, any, any> {\n return new EffectBuilder(\n {\n ...builder[\"~orpc\"],\n effectErrorMap: state.effectErrorMap,\n runtime: state.runtime,\n spanConfig: state.spanConfig,\n },\n unwrapEffectUpstream(builder),\n );\n}\n\nfunction createEffectBuilderProxy(\n target: EffectBuilderTarget,\n): EffectBuilderTarget {\n return createNodeProxy<EffectBuilderTarget, AnyBuilderLike>(target, {\n getVirtual(context, prop) {\n const effectDef = getEffectBuilderDef(context);\n if (prop === \"~effect\") {\n return getEffectBuilderDef(context);\n }\n\n const { upstream: source, state } = context;\n\n switch (prop) {\n case \"errors\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return <U extends EffectErrorMap>(errors: U) => {\n const nextEffectErrorMap: MergedEffectErrorMap<\n typeof state.effectErrorMap,\n U\n > = {\n ...state.effectErrorMap,\n ...errors,\n };\n const nextBuilder: AnyBuilderLike = Reflect.apply(\n Reflect.get(source, \"errors\", source),\n source,\n [effectErrorMapToErrorMap(errors)],\n );\n\n return wrapBuilderLike(nextBuilder, {\n ...state,\n effectErrorMap: nextEffectErrorMap,\n });\n };\n });\n case \"effect\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n effectFn: Parameters<\n EffectBuilderSurface<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >[\"effect\"]\n >[0],\n ) => {\n const defaultCaptureStackTrace = addSpanStackTrace();\n return new EffectDecoratedProcedure({\n ...effectDef,\n handler: async (opts) => {\n return createEffectProcedureHandler({\n defaultCaptureStackTrace,\n effectErrorMap: state.effectErrorMap,\n effectFn,\n runtime: state.runtime,\n spanConfig: state.spanConfig,\n })(opts as any);\n },\n });\n };\n });\n case \"traced\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (spanName: string) =>\n wrapBuilderLike(source, {\n ...state,\n spanConfig: {\n captureStackTrace: addSpanStackTrace(),\n name: spanName,\n },\n });\n });\n case \"handler\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n handler: Parameters<\n EffectBuilderSurface<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >[\"handler\"]\n >[0],\n ) =>\n new EffectDecoratedProcedure({\n ...effectDef,\n handler,\n });\n });\n case \"router\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (router: Router<ContractRouter<any>, any>) =>\n enhanceEffectRouter(router, effectDef) as any;\n });\n case \"lazy\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n loader: () => Promise<{\n default: Router<ContractRouter<any>, any>;\n }>,\n ) => enhanceEffectRouter(lazy(loader), effectDef) as any;\n });\n default:\n return unhandled();\n }\n },\n virtualDescriptors: builderVirtualDescriptors,\n virtualKeys: builderVirtualKeys,\n wrapResult(context, _prop, result) {\n if (!isBuilderLike(result)) {\n return result;\n }\n\n return wrapBuilderLike(result, context.state);\n },\n });\n}\n\n/**\n * Captures the stack trace at the call site for better error reporting in spans.\n * This is called at procedure definition time to capture where the procedure was defined.\n */\nexport function addSpanStackTrace(): () => string | undefined {\n const ErrorConstructor = Error as typeof Error & {\n stackTraceLimit?: number;\n };\n const limit = ErrorConstructor.stackTraceLimit;\n ErrorConstructor.stackTraceLimit = 3;\n const traceError = new Error();\n ErrorConstructor.stackTraceLimit = limit;\n let cache: false | string = false;\n return () => {\n if (cache !== false) {\n return cache;\n }\n if (traceError.stack !== undefined) {\n const stack = traceError.stack.split(\"\\n\");\n if (stack[3] !== undefined) {\n cache = stack[3].trim();\n return cache;\n }\n }\n };\n}\n\n/**\n * Effect-native procedure builder that wraps an oRPC Builder instance\n * and adds Effect-specific capabilities while preserving Effect error\n * and requirements types.\n */\nexport class EffectBuilder<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n> implements EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n> {\n /**\n * Sets or overrides the config.\n *\n * @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs}\n * @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}\n */\n declare $config: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$config\"];\n /**\n * Set or override the initial context.\n *\n * @see {@link https://orpc.dev/docs/context Context Docs}\n */\n declare $context: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$context\"];\n /**\n * Sets or overrides the initial meta.\n *\n * @see {@link https://orpc.dev/docs/metadata Metadata Docs}\n */\n declare $meta: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$meta\"];\n /**\n * Sets or overrides the initial route.\n * This option is typically relevant when integrating with OpenAPI.\n *\n * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}\n * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}\n */\n declare $route: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$route\"];\n /**\n * Sets or overrides the initial input schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}\n */\n declare $input: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"$input\"];\n /**\n * This property holds the defined options and the effect-specific properties.\n */\n declare \"~effect\": EffectBuilderDef<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n /**\n * This property holds the defined options.\n */\n declare \"~orpc\": EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"~orpc\"];\n /**\n * Creates a middleware.\n *\n * @see {@link https://orpc.dev/docs/middleware Middleware Docs}\n */\n declare middleware: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"middleware\"];\n /**\n * Adds type-safe custom errors.\n * Supports both traditional oRPC error definitions and ORPCTaggedError classes.\n *\n * @example\n * ```ts\n * // Traditional format\n * builder.errors({ BAD_REQUEST: { status: 400, message: 'Bad request' } })\n *\n * // Tagged error class\n * builder.errors({ USER_NOT_FOUND: UserNotFoundError })\n *\n * // Mixed\n * builder.errors({\n * BAD_REQUEST: { status: 400 },\n * USER_NOT_FOUND: UserNotFoundError,\n * })\n * ```\n *\n * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}\n */\n declare errors: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"errors\"];\n /**\n * Uses a middleware to modify the context or improve the pipeline.\n *\n * @info Supports both normal middleware and inline middleware implementations.\n * @note The current context must be satisfy middleware dependent-context\n * @see {@link https://orpc.dev/docs/middleware Middleware Docs}\n */\n declare use: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"use\"];\n /**\n * Sets or updates the metadata.\n * The provided metadata is spared-merged with any existing metadata.\n *\n * @see {@link https://orpc.dev/docs/metadata Metadata Docs}\n */\n declare meta: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"meta\"];\n /**\n * Sets or updates the route definition.\n * The provided route is spared-merged with any existing route.\n * This option is typically relevant when integrating with OpenAPI.\n *\n * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}\n * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}\n */\n declare route: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"route\"];\n /**\n * Defines the input validation schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}\n */\n declare input: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"input\"];\n /**\n * Defines the output validation schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}\n */\n declare output: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"output\"];\n /**\n * Adds a traceable span to the procedure for telemetry.\n * The span name is used for Effect tracing via `Effect.withSpan`.\n * Stack trace is captured at the call site for better error reporting.\n *\n * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')\n * @returns An EffectBuilder with span tracing configured\n *\n * @example\n * ```ts\n * const getUser = effectOs\n * .input(z.object({ id: z.string() }))\n * .traced('users.getUser')\n * .effect(function* ({ input }) {\n * const userService = yield* UserService\n * return yield* userService.findById(input.id)\n * })\n * ```\n */\n declare traced: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"traced\"];\n /**\n * Defines the handler of the procedure using a standard async/sync function.\n *\n * @see {@link https://orpc.dev/docs/procedure Procedure Docs}\n */\n declare handler: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"handler\"];\n /**\n * Defines the handler of the procedure using an Effect.\n * The Effect is executed using the ManagedRuntime provided during builder creation.\n * The effect is automatically wrapped with `Effect.withSpan`.\n *\n * @see {@link https://orpc.dev/docs/procedure Procedure Docs}\n */\n declare effect: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"effect\"];\n /**\n * Prefixes all procedures in the router.\n * The provided prefix is post-appended to any existing router prefix.\n *\n * @note This option does not affect procedures that do not define a path in their route definition.\n *\n * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}\n */\n declare prefix: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"prefix\"];\n /**\n * Adds tags to all procedures in the router.\n * This helpful when you want to group procedures together in the OpenAPI specification.\n *\n * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}\n */\n declare tag: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"tag\"];\n /**\n * Applies all of the previously defined options to the specified router.\n *\n * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}\n */\n declare router: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"router\"];\n /**\n * Create a lazy router\n * And applies all of the previously defined options to the specified router.\n *\n * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}\n */\n declare lazy: EffectBuilderSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"lazy\"];\n\n constructor(\n def: EffectBuilderDef<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n builder?: AnyBuilderLike,\n ) {\n const { runtime, spanConfig, effectErrorMap, ...orpcDef } = def;\n\n attachEffectState(this, builder ?? new Builder(orpcDef), {\n effectErrorMap,\n runtime,\n spanConfig,\n });\n\n return createEffectBuilderProxy(this);\n }\n}\n\n/**\n * Creates an Effect-aware procedure builder with the specified ManagedRuntime.\n * Uses the default builder shape from `@orpc/server`.\n *\n * @param runtime - The ManagedRuntime that provides services for Effect procedures\n * @returns An EffectBuilder instance for creating Effect-native procedures\n *\n * @example\n * ```ts\n * import { makeEffectORPC } from '@orpc/effect'\n * import { Effect, Layer, ManagedRuntime } from 'effect'\n *\n * const runtime = ManagedRuntime.make(Layer.empty)\n * const effectOs = makeEffectORPC(runtime)\n *\n * const hello = effectOs.effect(() => Effect.succeed('Hello!'))\n * ```\n */\nexport function makeEffectORPC<TRequirementsProvided, TRuntimeError>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n): EffectBuilder<\n Context,\n Context,\n Schema<unknown, unknown>,\n Schema<unknown, unknown>,\n Record<never, never>,\n Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n>;\n\n/**\n * Creates an Effect-aware procedure builder by wrapping an existing oRPC Builder\n * with the specified ManagedRuntime.\n *\n * @param runtime - The ManagedRuntime that provides services for Effect procedures\n * @param builder - The oRPC Builder instance to wrap (e.g., a customized `os`)\n * @returns An EffectBuilder instance that extends the original builder with Effect support\n *\n * @example\n * ```ts\n * import { makeEffectORPC } from '@orpc/effect'\n * import { os } from '@orpc/server'\n * import { Effect, Layer, ManagedRuntime } from 'effect'\n *\n * // Create a customized builder\n * const authedOs = os.use(authMiddleware)\n *\n * // Wrap it with Effect support\n * const runtime = ManagedRuntime.make(UserServiceLive)\n * const effectOs = makeEffectORPC(runtime, authedOs)\n *\n * const getUser = effectOs\n * .input(z.object({ id: z.string() }))\n * .effect(\n * Effect.fn(function* ({ input }) {\n * const userService = yield* UserService\n * return yield* userService.findById(input.id)\n * })\n * )\n * ```\n */\nexport function makeEffectORPC<\n TBuilder extends AnyBuilderLike<\n TInputSchema,\n TOutputSchema,\n TErrorMap,\n TMeta\n >,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TErrorMap extends ErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n builder: TBuilder,\n): EffectBuilder<\n InferBuilderInitialContext<TBuilder>,\n InferBuilderCurrentContext<TBuilder>,\n InferBuilderInputSchema<TBuilder>,\n InferBuilderOutputSchema<TBuilder>,\n InferBuilderErrorMap<TBuilder>,\n InferBuilderMeta<TBuilder>,\n TRequirementsProvided,\n TRuntimeError\n>;\n\nexport function makeEffectORPC<TRequirementsProvided, TRuntimeError>(\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,\n builder?: AnyBuilderLike,\n): EffectBuilder<\n any,\n any,\n any,\n any,\n any,\n any,\n TRequirementsProvided,\n TRuntimeError\n> {\n const resolvedBuilder = builder ?? emptyBuilder();\n const effectErrorMap = getEffectErrorMap(resolvedBuilder);\n return new EffectBuilder(\n {\n ...resolvedBuilder[\"~orpc\"],\n effectErrorMap: effectErrorMap,\n errorMap: effectErrorMapToErrorMap(effectErrorMap),\n runtime,\n },\n unwrapEffectUpstream(resolvedBuilder),\n );\n}\n\nfunction emptyBuilder(): AnyBuilderLike {\n return new Builder({\n config: {},\n dedupeLeadingMiddlewares: true,\n errorMap: {},\n inputValidationIndex: fallbackConfig(\"initialInputValidationIndex\"),\n meta: {},\n middlewares: [],\n outputValidationIndex: fallbackConfig(\"initialOutputValidationIndex\"),\n route: {},\n });\n}\n","import {\n enhanceRoute,\n mergePrefix,\n type EnhanceRouteOptions,\n} from \"@orpc/contract\";\nimport {\n createAccessibleLazyRouter,\n getLazyMeta,\n isLazy,\n isProcedure,\n lazy,\n mergeMiddlewares,\n unlazy,\n type AnyMiddleware,\n type AnyRouter,\n type Context,\n type Lazyable,\n} from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect/ManagedRuntime\";\n\nimport { EffectProcedure } from \"./effect-procedure\";\nimport { getEffectErrorMap, unwrapEffectUpstream } from \"./extension/state\";\nimport { effectErrorMapToErrorMap, type EffectErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from \"./types\";\n\ninterface EnhanceEffectRouterOptions<\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n> extends EnhanceRouteOptions {\n middlewares: readonly AnyMiddleware[];\n errorMap: TEffectErrorMap;\n dedupeLeadingMiddlewares: boolean;\n runtime: ManagedRuntime<TRequirementsProvided, TRuntimeError>;\n}\n\nexport function enhanceEffectRouter<\n T extends Lazyable<AnyRouter>,\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n>(\n router: T,\n options: EnhanceEffectRouterOptions<\n TEffectErrorMap,\n TRequirementsProvided,\n TRuntimeError\n >,\n): EnhancedEffectRouter<T, TInitialContext, TCurrentContext, TEffectErrorMap> {\n if (isLazy(router)) {\n const laziedMeta = getLazyMeta(router);\n const enhancedPrefix = laziedMeta?.prefix\n ? mergePrefix(options.prefix, laziedMeta.prefix)\n : options.prefix;\n\n const enhanced = lazy(\n async () => {\n const { default: unlaziedRouter } = await unlazy(router);\n const wrappedRouter = enhanceEffectRouter(unlaziedRouter, options);\n return unlazy(wrappedRouter);\n },\n {\n ...laziedMeta,\n prefix: enhancedPrefix,\n },\n );\n\n return createAccessibleLazyRouter(enhanced) as any;\n }\n\n if (isProcedure(router)) {\n const source = unwrapEffectUpstream(router);\n const sourceEffectErrorMap = getEffectErrorMap(router);\n const middlewares = mergeMiddlewares(\n options.middlewares,\n source[\"~orpc\"].middlewares,\n { dedupeLeading: options.dedupeLeadingMiddlewares },\n );\n const newMiddlewareAdded =\n middlewares.length - source[\"~orpc\"].middlewares.length;\n const effectErrorMap = {\n ...options.errorMap,\n ...sourceEffectErrorMap,\n };\n const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =\n effectErrorMapToErrorMap(effectErrorMap);\n\n return new EffectProcedure({\n ...source[\"~orpc\"],\n route: enhanceRoute(source[\"~orpc\"].route, options),\n effectErrorMap,\n errorMap: errorMap as EffectErrorMapToErrorMap<typeof effectErrorMap>,\n middlewares,\n inputValidationIndex:\n source[\"~orpc\"].inputValidationIndex + newMiddlewareAdded,\n outputValidationIndex:\n source[\"~orpc\"].outputValidationIndex + newMiddlewareAdded,\n runtime: options.runtime,\n }) as any;\n }\n\n const enhanced: Record<string, any> = {};\n\n for (const key in router) {\n enhanced[key] = enhanceEffectRouter(router[key]!, options);\n }\n\n return enhanced as any;\n}\n","import type { ClientContext } from \"@orpc/client\";\nimport type { AnySchema, Meta, Route } from \"@orpc/contract\";\nimport { mergeMeta, mergeRoute } from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n Context,\n CreateProcedureClientOptions,\n MapInputMiddleware,\n ProcedureDef,\n} from \"@orpc/server\";\nimport {\n addMiddleware,\n createActionableClient,\n createProcedureClient,\n decorateMiddleware,\n Procedure,\n} from \"@orpc/server\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\n\nimport { composeSurfaceProxy } from \"./extension/compose-surfaces\";\nimport {\n createNodeProxy,\n unhandled,\n type NodeProxyContext,\n} from \"./extension/create-node-proxy\";\nimport {\n assertEffectState,\n attachEffectState,\n type EffectProxyTarget,\n} from \"./extension/state\";\nimport type { EffectErrorMap, MergedEffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureDef } from \"./types\";\nimport type { EffectDecoratedProcedureSurface } from \"./types/effect-procedure-surface\";\n\ntype AnyProcedureLike = Procedure<any, any, any, any, any, any>;\ntype AnyEffectProcedure = EffectProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\ntype AnyEffectDecoratedProcedure = EffectDecoratedProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>;\ntype EffectProcedureTarget<\n T extends AnyEffectProcedure | AnyEffectDecoratedProcedure =\n | AnyEffectProcedure\n | AnyEffectDecoratedProcedure,\n> = T & EffectProxyTarget<AnyProcedureLike>;\n\nconst procedureVirtualDescriptors = {\n \"~effect\": { enumerable: true },\n actionable: { enumerable: false },\n callable: { enumerable: false },\n errors: { enumerable: false },\n meta: { enumerable: false },\n route: { enumerable: false },\n use: { enumerable: false },\n} as const;\n\nconst baseProcedureVirtualKeys = [\"~effect\"] as const;\nconst decoratedProcedureVirtualKeys = [\n ...baseProcedureVirtualKeys,\n \"errors\",\n \"meta\",\n \"route\",\n \"use\",\n \"callable\",\n \"actionable\",\n] as const;\n\nfunction getOrCreateVirtualMethod<T>(\n context: NodeProxyContext<EffectProcedureTarget, AnyProcedureLike>,\n prop: PropertyKey,\n factory: () => T,\n): T {\n const cache = context.methodCache;\n if (cache.has(prop)) {\n return cache.get(prop) as T;\n }\n\n const value = factory();\n cache.set(prop, value);\n return value;\n}\n\nfunction getEffectProcedureDef(\n context: NodeProxyContext<EffectProcedureTarget, AnyProcedureLike>,\n): EffectProcedureDef<any, any, any, any, any, any, any, any> {\n return {\n ...context.upstream[\"~orpc\"],\n effectErrorMap: context.state.effectErrorMap,\n runtime: context.state.runtime,\n };\n}\n\nfunction createEffectProcedureProxy<\n T extends AnyEffectProcedure | AnyEffectDecoratedProcedure,\n>(\n target: EffectProcedureTarget<T>,\n decorated: boolean,\n): EffectProcedureTarget<T> {\n return createNodeProxy<EffectProcedureTarget<T>, AnyProcedureLike>(target, {\n getVirtual(context, prop, receiver) {\n if (prop === \"~effect\") {\n return getEffectProcedureDef(context);\n }\n\n if (!decorated) {\n return unhandled();\n }\n\n const state = context.state;\n\n switch (prop) {\n case \"errors\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return <U extends EffectErrorMap>(errors: U) => {\n const nextEffectErrorMap: MergedEffectErrorMap<\n typeof state.effectErrorMap,\n U\n > = {\n ...state.effectErrorMap,\n ...errors,\n };\n return new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n effectErrorMap: nextEffectErrorMap,\n errorMap: effectErrorMapToErrorMap(nextEffectErrorMap),\n });\n };\n });\n case \"meta\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (meta: Meta) =>\n new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n meta: mergeMeta(getEffectProcedureDef(context).meta, meta),\n });\n });\n case \"route\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (route: Route) =>\n new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n route: mergeRoute(getEffectProcedureDef(context).route, route),\n });\n });\n case \"use\":\n return getOrCreateVirtualMethod(context, prop, () => {\n return (\n middleware: AnyMiddleware,\n mapInput?: MapInputMiddleware<any, any>,\n ) => {\n const mapped = mapInput\n ? decorateMiddleware(middleware).mapInput(mapInput)\n : middleware;\n\n return new EffectDecoratedProcedure({\n ...getEffectProcedureDef(context),\n middlewares: addMiddleware(\n getEffectProcedureDef(context).middlewares,\n mapped,\n ),\n });\n };\n });\n case \"callable\":\n return <TClientContext extends ClientContext>(\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<any, any, any, any, TClientContext>\n >\n ) => {\n const client = createProcedureClient(\n receiver as AnyProcedureLike,\n ...rest,\n );\n return composeSurfaceProxy(\n receiver as EffectDecoratedProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n client,\n );\n };\n case \"actionable\":\n return (\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<\n any,\n any,\n any,\n any,\n Record<never, never>\n >\n >\n ) => {\n const client = createProcedureClient(\n receiver as AnyProcedureLike,\n ...rest,\n );\n const action = createActionableClient(client);\n return composeSurfaceProxy(\n receiver as EffectDecoratedProcedure<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >,\n action,\n );\n };\n default:\n return unhandled();\n }\n },\n virtualDescriptors: procedureVirtualDescriptors,\n virtualKeys: decorated\n ? decoratedProcedureVirtualKeys\n : baseProcedureVirtualKeys,\n });\n}\n\n/**\n * Effect-aware base procedure that carries the upstream procedure definition\n * together with Effect runtime and error metadata.\n */\nexport class EffectProcedure<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n> extends Procedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n> {\n /**\n * This property holds the defined options and the effect-specific properties.\n */\n declare \"~effect\": EffectProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n /**\n * This property holds the defined options.\n */\n declare \"~orpc\": ProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >;\n\n constructor(\n def: EffectProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n procedure?: AnyProcedureLike,\n ) {\n super(def);\n attachEffectState(this, procedure ?? new Procedure(def), {\n effectErrorMap: def.effectErrorMap,\n runtime: def.runtime,\n });\n\n if (new.target === EffectProcedure) {\n return createEffectProcedureProxy(this, false);\n }\n }\n}\n\n/**\n * An Effect-native decorated procedure that preserves Effect error and requirements types.\n *\n * This class extends Procedure with additional type parameters for Effect-specific\n * type information, allowing full type inference of Effect errors and requirements.\n */\nexport class EffectDecoratedProcedure<\n TInitialContext extends Context,\n TCurrentContext extends Context,\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n TRequirementsProvided,\n TRuntimeError,\n>\n extends EffectProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >\n implements\n EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >\n{\n /**\n * Adds type-safe custom errors.\n * Supports both traditional oRPC error definitions and ORPCTaggedError classes.\n *\n * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}\n */\n declare errors: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"errors\"];\n /**\n * Sets or updates the metadata.\n * The provided metadata is spared-merged with any existing metadata.\n *\n * @see {@link https://orpc.dev/docs/metadata Metadata Docs}\n */\n declare meta: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"meta\"];\n /**\n * Sets or updates the route definition.\n * The provided route is spared-merged with any existing route.\n * This option is typically relevant when integrating with OpenAPI.\n *\n * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}\n * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}\n */\n declare route: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"route\"];\n /**\n * Uses a middleware to modify the context or improve the pipeline.\n *\n * @info Supports both normal middleware and inline middleware implementations.\n * @info Pass second argument to map the input.\n * @note The current context must be satisfy middleware dependent-context\n * @see {@link https://orpc.dev/docs/middleware Middleware Docs}\n */\n declare use: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"use\"];\n /**\n * Make this procedure callable (works like a function while still being a procedure).\n *\n * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}\n */\n declare callable: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"callable\"];\n /**\n * Make this procedure compatible with server action.\n *\n * @see {@link https://orpc.dev/docs/server-action Server Action Docs}\n */\n declare actionable: EffectDecoratedProcedureSurface<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >[\"actionable\"];\n constructor(\n def: EffectProcedureDef<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n procedure?: AnyProcedureLike,\n ) {\n super(def, procedure);\n assertEffectState<AnyProcedureLike>(this);\n return createEffectProcedureProxy(this, true);\n }\n}\n","export function composeSurfaceProxy<\n TSurface extends object,\n TTarget extends object,\n>(surface: TSurface, target: TTarget): TSurface & TTarget {\n return new Proxy(target, {\n get(currentTarget, prop, receiver) {\n return Reflect.has(surface, prop)\n ? Reflect.get(surface, prop, surface)\n : Reflect.get(currentTarget, prop, receiver);\n },\n has(currentTarget, prop) {\n return Reflect.has(surface, prop) || Reflect.has(currentTarget, prop);\n },\n }) as TSurface & TTarget;\n}\n","import type { ManagedRuntime } from \"effect\";\n\nimport type { EffectErrorMap } from \"../tagged-error\";\nimport type { EffectSpanConfig } from \"../types\";\n\nexport interface EffectExtensionState<\n TRequirementsProvided = any,\n TRuntimeError = any,\n> {\n /**\n * Extended error map that supports both traditional oRPC errors and ORPCTaggedError classes.\n * @see {@link EffectErrorMap}\n */\n effectErrorMap: EffectErrorMap;\n /**\n * The Effect ManagedRuntime that provides services for Effect procedures.\n * @see {@link ManagedRuntime.ManagedRuntime}\n */\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;\n /**\n * Configuration for Effect span tracing.\n * @see {@link EffectSpanConfig}\n */\n spanConfig?: EffectSpanConfig;\n}\n\nexport interface EffectInternals<TUpstream extends object = object> {\n upstream: TUpstream;\n state: EffectExtensionState;\n methodCache: Map<PropertyKey, unknown>;\n}\n\nexport const effectInternalsSymbol = Symbol(\"effect-orpc/internals\");\n\nexport interface EffectProxyTarget<TUpstream extends object = object> {\n [effectInternalsSymbol]: EffectInternals<TUpstream>;\n}\n\nexport function attachEffectState<\n TTarget extends object,\n TUpstream extends object,\n>(\n target: TTarget,\n upstream: TUpstream,\n state: EffectExtensionState,\n): asserts target is TTarget & EffectProxyTarget<TUpstream> {\n Object.defineProperties(target, {\n [effectInternalsSymbol]: {\n configurable: true,\n value: {\n methodCache: new Map<PropertyKey, unknown>(),\n state,\n upstream,\n } satisfies EffectInternals<TUpstream>,\n },\n });\n}\n\nexport function getEffectInternals<TUpstream extends object>(\n target: EffectProxyTarget<TUpstream>,\n): EffectInternals<TUpstream> {\n return target[effectInternalsSymbol];\n}\n\nexport function getEffectUpstream<TUpstream extends object>(\n target: EffectProxyTarget<TUpstream>,\n): TUpstream {\n return getEffectInternals(target).upstream;\n}\n\nexport function getEffectState(\n target: EffectProxyTarget,\n): EffectExtensionState {\n return getEffectInternals(target).state;\n}\n\nexport function getEffectMethodCache(\n target: EffectProxyTarget,\n): Map<PropertyKey, unknown> {\n return getEffectInternals(target).methodCache;\n}\n\nexport function hasEffectState(value: unknown): value is EffectProxyTarget {\n return (\n typeof value === \"object\" &&\n value !== null &&\n effectInternalsSymbol in (value as object)\n );\n}\n\nexport function assertEffectState<TUpstream extends object>(\n value: object,\n): asserts value is EffectProxyTarget<TUpstream> {\n if (!hasEffectState(value)) {\n throw new Error(\"Expected effect state to be attached\");\n }\n}\n\nexport function getEffectErrorMap(value: {\n \"~effect\"?: { effectErrorMap: EffectErrorMap };\n \"~orpc\": { errorMap: EffectErrorMap };\n}): EffectErrorMap {\n return value[\"~effect\"]?.effectErrorMap ?? value[\"~orpc\"].errorMap;\n}\n\nexport function unwrapEffectUpstream<T extends object>(value: T): T {\n return hasEffectState(value) ? (getEffectUpstream(value) as T) : value;\n}\n","import {\n effectInternalsSymbol,\n getEffectInternals,\n type EffectExtensionState,\n type EffectProxyTarget,\n} from \"./state\";\n\nconst unhandledProperty = Symbol(\"effect-orpc/unhandledProperty\");\n\nexport type UnhandledProperty = typeof unhandledProperty;\n\nexport interface NodeProxyContext<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n> {\n methodCache: Map<PropertyKey, unknown>;\n state: EffectExtensionState;\n target: TTarget;\n upstream: TSource;\n}\n\ninterface NodeProxyInternalConfig<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n> {\n getProperty?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n getVirtual?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n virtualDescriptors?: Partial<\n Record<string | symbol, Pick<PropertyDescriptor, \"enumerable\">>\n >;\n virtualKeys?: readonly (string | symbol)[];\n wrapResult?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n result: unknown,\n receiver: unknown,\n ) => unknown;\n}\n\n/**\n * Configures how an Effect-aware node proxy exposes virtual properties and\n * rewrites returned values while the upstream builder/procedure remains the\n * source of truth for passthrough behavior.\n */\nexport interface NodeProxyConfig<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n> extends NodeProxyInternalConfig<TTarget, TSource> {\n /**\n * Returns a value for virtual properties such as `~effect` or custom\n * proxy-backed methods. Return `unhandled()` to fall back to the next step.\n */\n getVirtual?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n /**\n * Intercepts property access before upstream passthrough. Return\n * `unhandled()` to delegate to the wrapped upstream node.\n */\n getProperty?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n receiver: unknown,\n ) => unknown | UnhandledProperty;\n /**\n * Declares which virtual keys should appear in reflection APIs like `in`,\n * `Object.keys`, and descriptor lookup.\n */\n virtualKeys?: readonly (string | symbol)[];\n /**\n * Controls enumerability for virtual keys exposed through the proxy.\n */\n virtualDescriptors?: Partial<\n Record<string | symbol, Pick<PropertyDescriptor, \"enumerable\">>\n >;\n /**\n * Rewraps upstream method results when they should stay inside the Effect\n * extension model.\n */\n wrapResult?: (\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n result: unknown,\n receiver: unknown,\n ) => unknown;\n}\n\nfunction createNodeProxyContext<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n>(target: TTarget): NodeProxyContext<TTarget, TSource> {\n const internals = getEffectInternals(target);\n return {\n methodCache: internals.methodCache,\n state: internals.state,\n target,\n upstream: internals.upstream as TSource,\n };\n}\n\nfunction createBoundMethod<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n>(\n context: NodeProxyContext<TTarget, TSource>,\n prop: PropertyKey,\n value: (...args: unknown[]) => unknown,\n config: NodeProxyInternalConfig<TTarget, TSource>,\n receiver: unknown,\n): (...args: unknown[]) => unknown {\n const cache = context.methodCache;\n if (cache.has(prop)) {\n return cache.get(prop) as (...args: unknown[]) => unknown;\n }\n\n const wrapped = (...args: unknown[]) => {\n const result = Reflect.apply(value, context.upstream, args);\n return config.wrapResult?.(context, prop, result, receiver) ?? result;\n };\n\n cache.set(prop, wrapped);\n return wrapped;\n}\n\n/**\n * Creates an Effect-aware proxy around a local shell object.\n *\n * @param target The local Effect wrapper instance that already has upstream and\n * state symbols attached via `attachEffectState`.\n * @param config The extension hooks that define virtual properties,\n * interception points, and result rewrapping behavior for the proxy.\n */\nexport function createNodeProxy<\n TTarget extends EffectProxyTarget<TSource>,\n TSource extends object,\n>(target: TTarget, config: NodeProxyConfig<TTarget, TSource>): TTarget {\n const privateKeys = new Set<PropertyKey>([effectInternalsSymbol]);\n const virtualKeys = new Set(config.virtualKeys ?? []);\n\n return new Proxy(target, {\n get(currentTarget, prop, receiver) {\n if (privateKeys.has(prop)) {\n return Reflect.get(currentTarget, prop, receiver);\n }\n\n const context = createNodeProxyContext<TTarget, TSource>(\n currentTarget as TTarget,\n );\n\n const virtualValue = config.getVirtual?.(context, prop, receiver);\n if (virtualValue !== undefined && virtualValue !== unhandledProperty) {\n return virtualValue;\n }\n\n const propertyValue = config.getProperty?.(context, prop, receiver);\n if (propertyValue !== undefined && propertyValue !== unhandledProperty) {\n return propertyValue;\n }\n\n const sourceValue = Reflect.get(context.upstream, prop, context.upstream);\n\n if (Reflect.has(context.upstream, prop)) {\n if (typeof sourceValue === \"function\") {\n return createBoundMethod(\n context,\n prop,\n sourceValue as (...args: unknown[]) => unknown,\n config,\n receiver,\n );\n }\n\n return sourceValue;\n }\n\n return Reflect.get(currentTarget, prop, receiver);\n },\n\n has(currentTarget, prop) {\n if (virtualKeys.has(prop)) {\n return true;\n }\n\n const context = createNodeProxyContext<TTarget, TSource>(currentTarget);\n return (\n Reflect.has(context.upstream, prop) || Reflect.has(currentTarget, prop)\n );\n },\n\n ownKeys(currentTarget) {\n const keys = new Set<string | symbol>();\n\n for (const key of Reflect.ownKeys(currentTarget)) {\n if (!privateKeys.has(key)) {\n keys.add(key);\n }\n }\n\n const context = createNodeProxyContext<TTarget, TSource>(\n currentTarget as TTarget,\n );\n\n for (const key of Reflect.ownKeys(context.upstream)) {\n keys.add(key);\n }\n\n for (const key of virtualKeys) {\n keys.add(key);\n }\n\n return [...keys];\n },\n\n getOwnPropertyDescriptor(currentTarget, prop) {\n const context = createNodeProxyContext<TTarget, TSource>(\n currentTarget as TTarget,\n );\n\n if (virtualKeys.has(prop)) {\n const value = config.getVirtual?.(context, prop, currentTarget);\n if (value !== undefined && value !== unhandledProperty) {\n return {\n configurable: true,\n enumerable: config.virtualDescriptors?.[prop]?.enumerable ?? false,\n value,\n writable: false,\n };\n }\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(\n context.upstream,\n prop,\n );\n\n if (descriptor === undefined) {\n return Reflect.getOwnPropertyDescriptor(currentTarget, prop);\n }\n\n if (\"value\" in descriptor && typeof descriptor.value === \"function\") {\n return {\n ...descriptor,\n value: createBoundMethod(\n context,\n prop,\n descriptor.value as (...args: unknown[]) => unknown,\n config,\n currentTarget,\n ),\n };\n }\n\n return descriptor;\n },\n });\n}\n\nexport function unhandled(): UnhandledProperty {\n return unhandledProperty;\n}\n","import type {\n ORPCErrorCode,\n ORPCErrorJSON,\n ORPCErrorOptions,\n} from \"@orpc/client\";\nimport {\n fallbackORPCErrorMessage,\n fallbackORPCErrorStatus,\n isORPCErrorStatus,\n ORPCError,\n} from \"@orpc/client\";\nimport type {\n AnySchema,\n ErrorMap,\n ErrorMapItem,\n InferSchemaOutput,\n} from \"@orpc/contract\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\nimport { resolveMaybeOptionalOptions } from \"@orpc/shared\";\nimport type { Pipeable } from \"effect\";\nimport * as Cause from \"effect/Cause\";\nimport * as Data from \"effect/Data\";\n\nimport type { EffectErrorMapToErrorMap } from \"./types\";\n\n/**\n * Symbol to access the underlying ORPCError instance\n */\nexport const ORPCErrorSymbol: unique symbol = Symbol.for(\n \"@orpc/effect/ORPCTaggedError\",\n);\n\n/**\n * Instance type for ORPCTaggedError that combines YieldableError with ORPCError properties\n */\nexport interface ORPCTaggedErrorInstance<\n TTag extends string,\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n>\n extends Cause.YieldableError, Pipeable.Pipeable {\n readonly _tag: TTag;\n readonly code: TCode;\n readonly status: number;\n readonly schema: TSchema;\n readonly data: InferSchemaOutput<TSchema>;\n readonly defined: boolean;\n readonly [ORPCErrorSymbol]: ORPCError<TCode, InferSchemaOutput<TSchema>>;\n\n toJSON(): ORPCErrorJSON<TCode, InferSchemaOutput<TSchema>> & { _tag: TTag };\n toORPCError(): ORPCError<TCode, InferSchemaOutput<TSchema>>;\n}\n\n/**\n * Options for creating an ORPCTaggedError\n */\nexport type ORPCTaggedErrorOptions<TData> = Omit<\n ORPCErrorOptions<TData>,\n \"defined\"\n> & { defined?: boolean };\n\n/**\n * Constructor type for ORPCTaggedError classes\n */\nexport interface ORPCTaggedErrorClass<\n TTag extends string,\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n> {\n readonly _tag: TTag;\n readonly code: TCode;\n new (\n ...args: MaybeOptionalOptions<\n ORPCTaggedErrorOptions<InferSchemaOutput<TSchema>>\n >\n ): ORPCTaggedErrorInstance<TTag, TCode, TSchema>;\n}\n\n/**\n * Type helper to infer the ORPCError type from an ORPCTaggedError\n */\nexport type InferORPCError<T> =\n T extends ORPCTaggedErrorInstance<string, infer TCode, infer TSchema>\n ? ORPCError<TCode, InferSchemaOutput<TSchema>>\n : never;\n\n/**\n * Any ORPCTaggedErrorClass\n * Uses `...args: any[]` for the constructor to accept any tagged error class,\n * regardless of whether TData requires options to be provided.\n */\nexport type AnyORPCTaggedErrorClass = {\n readonly _tag: string;\n readonly code: ORPCErrorCode;\n new (\n ...args: any[]\n ): ORPCTaggedErrorInstance<string, ORPCErrorCode, AnySchema>;\n};\n\n/**\n * Check if a value is an ORPCTaggedErrorClass (constructor)\n */\nexport function isORPCTaggedErrorClass(\n value: unknown,\n): value is AnyORPCTaggedErrorClass {\n return (\n typeof value === \"function\" &&\n \"_tag\" in value &&\n \"code\" in value &&\n typeof value._tag === \"string\" &&\n typeof value.code === \"string\"\n );\n}\n\n/**\n * Check if a value is an ORPCTaggedError instance\n */\nexport function isORPCTaggedError(\n value: unknown,\n): value is ORPCTaggedErrorInstance<string, ORPCErrorCode, AnySchema> {\n return (\n typeof value === \"object\" && value !== null && ORPCErrorSymbol in value\n );\n}\n\n/**\n * Converts a PascalCase or camelCase string to CONSTANT_CASE.\n * e.g., \"UserNotFoundError\" -> \"USER_NOT_FOUND_ERROR\"\n */\nfunction toConstantCase<T extends string>(str: T): ToConstantCase<T> {\n return str\n .replace(/([a-z])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toUpperCase() as ToConstantCase<T>;\n}\n/**\n * Checks if a character is an uppercase letter (A-Z)\n */\ntype IsUpperLetter<C extends string> =\n C extends Uppercase<C>\n ? C extends Lowercase<C>\n ? false // Not a letter (number, special char)\n : true\n : false;\n\n/**\n * Checks if a character is a lowercase letter (a-z)\n */\ntype IsLowerLetter<C extends string> =\n C extends Lowercase<C>\n ? C extends Uppercase<C>\n ? false // Not a letter (number, special char)\n : true\n : false;\n\n/**\n * Converts PascalCase or camelCase to CONSTANT_CASE.\n * Handles consecutive uppercase letters correctly.\n *\n * @example\n * type T1 = ToConstantCase<\"ABCCode\">; // \"ABC_CODE\"\n * type T2 = ToConstantCase<\"UserCode\">; // \"USER_CODE\"\n * type T3 = ToConstantCase<\"XMLHttpRequest\">; // \"XML_HTTP_REQUEST\"\n */\ntype ToConstantCase<\n S extends string,\n Acc extends string = \"\",\n PrevChar extends string = \"\",\n InUpperSequence extends boolean = false,\n> = S extends `${infer Head}${infer Tail}`\n ? IsUpperLetter<Head> extends true\n ? Acc extends \"\"\n ? // First character - no underscore\n ToConstantCase<Tail, Head, Head, false>\n : PrevChar extends \"\"\n ? // Shouldn't happen, but handle gracefully\n ToConstantCase<Tail, Head, Head, false>\n : IsUpperLetter<PrevChar> extends true\n ? // We're in an uppercase sequence\n Tail extends `${infer Next}${infer _}`\n ? IsLowerLetter<Next> extends true\n ? // Next char is lowercase, so Head starts a new word - insert underscore\n ToConstantCase<Tail, `${Acc}_${Head}`, Head, false>\n : // Next char is uppercase or non-letter - continue sequence\n ToConstantCase<Tail, `${Acc}${Head}`, Head, true>\n : // Tail is empty - just append\n ToConstantCase<Tail, `${Acc}${Head}`, Head, true>\n : // Transition from lowercase to uppercase - insert underscore\n ToConstantCase<Tail, `${Acc}_${Head}`, Head, false>\n : IsLowerLetter<Head> extends true\n ? InUpperSequence extends true\n ? // End of uppercase sequence (2+) - insert underscore before lowercase\n ToConstantCase<Tail, `${Acc}_${Uppercase<Head>}`, Head, false>\n : // Single uppercase or no uppercase - no underscore\n ToConstantCase<Tail, `${Acc}${Uppercase<Head>}`, Head, false>\n : // Non-letter character - reset sequence\n ToConstantCase<Tail, `${Acc}${Head}`, Head, false>\n : Acc;\n\n/**\n * Converts a tag name to an error code in CONSTANT_CASE.\n */\nexport type TagToCode<TTag extends string> = ToConstantCase<TTag>;\n\n/**\n * Creates a tagged error class that combines Effect's YieldableError with ORPCError.\n *\n * This allows you to create errors that:\n * - Can be yielded in Effect generators (`yield* myError`)\n * - Have all ORPCError properties (code, status, data, defined)\n * - Can be converted to a plain ORPCError for oRPC handlers\n *\n * The returned factory function takes:\n * - `tag` - The unique tag for this error type (used for discriminated unions)\n * - `codeOrOptions` - Optional ORPC error code or options. If omitted, code defaults to CONSTANT_CASE of tag\n * - `defaultOptions` - Optional default options for status and message (when code is provided)\n *\n * @example\n * ```ts\n * import { ORPCTaggedError } from '@orpc/effect'\n * import { Effect } from 'effect'\n *\n * // Define a custom error (code defaults to 'USER_NOT_FOUND_ERROR')\n * class UserNotFoundError extends ORPCTaggedError<UserNotFoundError>()('UserNotFoundError') {}\n *\n * // With explicit code\n * class NotFoundError extends ORPCTaggedError<NotFoundError>()('NotFoundError', 'NOT_FOUND') {}\n *\n * // Use in an Effect\n * const getUser = (id: string) => Effect.gen(function* () {\n * const user = yield* findUser(id)\n * if (!user) {\n * return yield* new UserNotFoundError({ data: { userId: id } })\n * }\n * return user\n * })\n *\n * // With custom data type\n * class ValidationError extends ORPCTaggedError<ValidationError, { fields: string[] }>()('ValidationError', 'BAD_REQUEST') {}\n *\n * // With options only (code defaults to 'VALIDATION_ERROR')\n * class ValidationError2 extends ORPCTaggedError<ValidationError2, { fields: string[] }>()(\n * 'ValidationError2',\n * { message: 'Validation failed' }\n * ) {}\n * ```\n */\nexport function ORPCTaggedError<\n TTag extends string,\n TSchema extends AnySchema = AnySchema,\n TCode extends ORPCErrorCode = ToConstantCase<TTag>,\n>(\n tag: TTag,\n props?: {\n schema?: TSchema;\n status?: number;\n message?: string;\n code?: TCode;\n },\n): ORPCTaggedErrorClass<TTag, TCode, TSchema> {\n const code: TCode = props?.code ?? (toConstantCase(tag) as any);\n class ORPCTaggedErrorBase\n extends Data.TaggedError(tag)\n implements ORPCTaggedErrorInstance<TTag, TCode, TSchema>\n {\n readonly status: number;\n readonly defined: boolean;\n readonly data: InferSchemaOutput<TSchema>;\n readonly code: TCode = code;\n readonly schema = props?.schema as TSchema;\n readonly [ORPCErrorSymbol]: ORPCError<TCode, InferSchemaOutput<TSchema>>;\n\n constructor(\n ...rest: MaybeOptionalOptions<\n ORPCTaggedErrorOptions<InferSchemaOutput<TSchema>>\n >\n ) {\n super();\n\n const opts = resolveMaybeOptionalOptions(rest);\n const status = opts.status ?? props?.status;\n\n if (status !== undefined && !isORPCErrorStatus(status)) {\n throw new globalThis.Error(\n \"[ORPCTaggedError] Invalid error status code.\",\n );\n }\n\n this.status = fallbackORPCErrorStatus(code, status);\n this.defined = opts.defined ?? true;\n this.data = opts.data as InferSchemaOutput<TSchema>;\n this.message = fallbackORPCErrorMessage(\n this.code,\n opts.message ?? props?.message,\n );\n this.cause = opts.cause;\n\n this[ORPCErrorSymbol] = new ORPCError<TCode, InferSchemaOutput<TSchema>>(\n this.code,\n {\n status: this.status,\n message: this.message,\n data: this.data,\n defined: this.defined,\n cause: this.cause,\n },\n );\n }\n\n /**\n * Converts this error to a plain ORPCError.\n * Useful when you need to return from an oRPC handler.\n */\n toORPCError(): ORPCError<TCode, InferSchemaOutput<TSchema>> {\n return this[ORPCErrorSymbol];\n }\n\n override toJSON(): ORPCErrorJSON<TCode, InferSchemaOutput<TSchema>> & {\n _tag: TTag;\n } {\n return {\n _tag: this._tag,\n defined: this[ORPCErrorSymbol].defined,\n code: this[ORPCErrorSymbol].code,\n status: this[ORPCErrorSymbol].status,\n message: this[ORPCErrorSymbol].message,\n data: this[ORPCErrorSymbol].data,\n };\n }\n }\n\n return Object.assign(ORPCTaggedErrorBase, {\n _tag: tag,\n code,\n } as const);\n}\n\n/**\n * Converts an ORPCTaggedError to a plain ORPCError.\n * Useful in handlers that need to throw ORPCError.\n *\n * @example\n * ```ts\n * const handler = effectOs.effect(function* () {\n * const result = yield* someOperation.pipe(\n * Effect.catchTag('UserNotFoundError', (e) =>\n * Effect.fail(toORPCError(e))\n * )\n * )\n * return result\n * })\n * ```\n */\nexport function toORPCError<\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n>(\n error: ORPCTaggedErrorInstance<string, TCode, TSchema>,\n): ORPCError<TCode, InferSchemaOutput<TSchema>> {\n return error[ORPCErrorSymbol];\n}\n\n// ============================================================================\n// Extended Error Map Types for Effect\n// ============================================================================\n\n/**\n * An item in the EffectErrorMap - can be either a traditional ErrorMapItem or an ORPCTaggedErrorClass\n */\nexport type EffectErrorMapItem =\n | ErrorMapItem<AnySchema>\n | AnyORPCTaggedErrorClass;\n\nexport type ORPCTaggedErrorClassToErrorMapItem<T> =\n T extends ORPCTaggedErrorClass<any, any, infer TData>\n ? {\n status?: number;\n message?: string;\n data?: TData;\n }\n : never;\n\n/**\n * Extended error map that supports both traditional oRPC errors and ORPCTaggedError classes.\n *\n * @example\n * ```ts\n * const errorMap = {\n * // Traditional format\n * BAD_REQUEST: { status: 400, message: 'Bad request' },\n *\n * // Tagged error class reference\n * USER_NOT_FOUND: UserNotFoundError,\n * } satisfies EffectErrorMap\n * ```\n */\nexport type EffectErrorMap = {\n [key in ORPCErrorCode]?: EffectErrorMapItem;\n};\n\n/**\n * Merges two EffectErrorMaps, with the second map taking precedence.\n */\nexport type MergedEffectErrorMap<\n T1 extends EffectErrorMap,\n T2 extends EffectErrorMap,\n> = Omit<T1, keyof T2> & T2;\n\n/**\n * Extracts the instance type from an EffectErrorMapItem\n */\nexport type EffectErrorMapItemToInstance<\n TCode extends ORPCErrorCode,\n T extends EffectErrorMapItem,\n> = T extends AnyORPCTaggedErrorClass\n ? InstanceType<T>\n : T extends { data?: infer TData }\n ? ORPCError<TCode, TData>\n : ORPCError<TCode, unknown>;\n\n/**\n * Converts an EffectErrorMap to a union of error instances.\n */\nexport type EffectErrorMapToUnion<T extends EffectErrorMap> = {\n [K in keyof T]: K extends ORPCErrorCode\n ? T[K] extends EffectErrorMapItem\n ? EffectErrorMapItemToInstance<K, T[K]>\n : never\n : never;\n}[keyof T];\n\n/**\n * Constructor map for EffectErrorMap - provides typed error constructors for handlers.\n */\ntype EffectErrorConstructor<\n TCode extends ORPCErrorCode,\n TItem,\n> = TItem extends AnyORPCTaggedErrorClass\n ? (...args: ConstructorParameters<TItem>) => InstanceType<TItem>\n : TItem extends { data?: infer TSchema extends AnySchema }\n ? (\n ...rest: MaybeOptionalOptions<\n Omit<\n ORPCErrorOptions<InferSchemaOutput<TSchema>>,\n \"defined\" | \"status\"\n >\n >\n ) => ORPCError<TCode, InferSchemaOutput<TSchema>>\n : (\n ...rest: MaybeOptionalOptions<\n Omit<ORPCErrorOptions<unknown>, \"defined\" | \"status\">\n >\n ) => ORPCError<TCode, unknown>;\n\nexport type EffectErrorConstructorMap<T extends EffectErrorMap> = {\n [K in Extract<keyof T, ORPCErrorCode>]: EffectErrorConstructor<K, T[K]>;\n};\n\n/**\n * Creates an error constructor map from an EffectErrorMap.\n * Tagged error classes are passed through directly.\n * Traditional error items become ORPCError factory functions.\n */\nexport function createEffectErrorConstructorMap<T extends EffectErrorMap>(\n errors: T | undefined,\n): EffectErrorConstructorMap<T> {\n const target = errors ?? ({} as T);\n const proxy = new Proxy(target, {\n get(proxyTarget, code) {\n if (typeof code !== \"string\") {\n return Reflect.get(proxyTarget, code);\n }\n\n const config = target[code];\n\n // If it's a tagged error class, create a class constructor function\n if (isORPCTaggedErrorClass(config)) {\n return (\n ...opts: MaybeOptionalOptions<ORPCTaggedErrorOptions<unknown>>\n ) => new config(...opts);\n }\n\n // Otherwise, create a factory function for ORPCError\n return (\n ...rest: MaybeOptionalOptions<\n Omit<ORPCErrorOptions<unknown>, \"defined\" | \"status\">\n >\n ) => {\n const options = resolveMaybeOptionalOptions(rest);\n return new ORPCError(code, {\n defined: Boolean(config),\n status: config?.status,\n message: options.message ?? config?.message,\n data: options.data,\n cause: options.cause,\n });\n };\n },\n });\n\n return proxy as unknown as EffectErrorConstructorMap<T>;\n}\n\n/**\n * Converts an EffectErrorMap to a standard oRPC ErrorMap for interop.\n * Tagged error classes are converted to their equivalent ErrorMapItem format.\n */\nexport function effectErrorMapToErrorMap<T extends EffectErrorMap>(\n errorMap: T | undefined,\n): EffectErrorMapToErrorMap<T> {\n const result: ErrorMap = {};\n\n if (!errorMap) {\n return result as ErrorMap & EffectErrorMapToErrorMap<T>;\n }\n\n for (const [code, ClassOrErrorItem] of Object.entries(errorMap)) {\n if (!ClassOrErrorItem) {\n continue;\n }\n\n if (isORPCTaggedErrorClass(ClassOrErrorItem)) {\n const classInstance = new ClassOrErrorItem();\n result[classInstance.code] = {\n status: classInstance.status,\n message: classInstance.message,\n data: classInstance.schema,\n };\n } else {\n result[code] = ClassOrErrorItem;\n }\n }\n\n return result as ErrorMap & EffectErrorMapToErrorMap<T>;\n}\n","import { ORPCError } from \"@orpc/contract\";\nimport type {\n Context,\n ProcedureHandler,\n ProcedureHandlerOptions,\n} from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect\";\nimport { Cause, Effect, Exit, FiberRefs } from \"effect\";\n\nimport { getCurrentFiberRefs } from \"./fiber-context-bridge\";\nimport type { EffectErrorConstructorMap, EffectErrorMap } from \"./tagged-error\";\nimport {\n createEffectErrorConstructorMap,\n isORPCTaggedError,\n} from \"./tagged-error\";\nimport type { EffectProcedureHandler, EffectSpanConfig } from \"./types\";\n\nexport function toORPCErrorFromCause(\n cause: Cause.Cause<unknown>,\n): ORPCError<string, unknown> {\n return Cause.match(cause, {\n onDie(defect) {\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: defect,\n });\n },\n onFail(error) {\n if (isORPCTaggedError(error)) {\n return error.toORPCError();\n }\n if (error instanceof ORPCError) {\n return error;\n }\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: error,\n });\n },\n onInterrupt(fiberId) {\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: new Error(`${fiberId} Interrupted`),\n });\n },\n onSequential(left) {\n return left;\n },\n onEmpty: new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: new Error(\"Unknown error\"),\n }),\n onParallel(left) {\n return left;\n },\n });\n}\n\nexport function createEffectProcedureHandler<\n TCurrentContext extends Context,\n TInput,\n TOutput,\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n TMeta,\n>(options: {\n runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;\n effectErrorMap: TEffectErrorMap;\n effectFn: EffectProcedureHandler<\n TCurrentContext,\n TInput,\n TOutput,\n TEffectErrorMap,\n TRequirementsProvided,\n any\n >;\n spanConfig?: EffectSpanConfig;\n defaultCaptureStackTrace: () => string | undefined;\n}): ProcedureHandler<\n TCurrentContext,\n TInput,\n TOutput,\n any,\n TMeta & Record<never, never>\n> {\n const {\n runtime,\n effectErrorMap,\n effectFn,\n spanConfig,\n defaultCaptureStackTrace,\n } = options;\n\n return async (opts) => {\n const effectOpts: ProcedureHandlerOptions<\n TCurrentContext,\n TInput,\n EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta & Record<never, never>\n > = {\n context: opts.context,\n input: opts.input,\n path: opts.path,\n procedure: opts.procedure,\n signal: opts.signal,\n lastEventId: opts.lastEventId,\n errors: createEffectErrorConstructorMap(effectErrorMap),\n };\n\n const spanName = spanConfig?.name ?? opts.path.join(\".\");\n const captureStackTrace =\n spanConfig?.captureStackTrace ?? defaultCaptureStackTrace;\n const resolver = Effect.fnUntraced(effectFn as any);\n const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {\n captureStackTrace,\n });\n const parentFiberRefs = getCurrentFiberRefs();\n const effectWithRefs = parentFiberRefs\n ? Effect.fiberIdWith((fiberId) =>\n Effect.flatMap(Effect.getFiberRefs, (fiberRefs) =>\n Effect.setFiberRefs(\n FiberRefs.joinAs(fiberRefs, fiberId, parentFiberRefs),\n ).pipe(Effect.andThen(tracedEffect)),\n ),\n )\n : tracedEffect;\n const exit = await runtime.runPromiseExit(effectWithRefs, {\n signal: opts.signal,\n });\n\n if (Exit.isFailure(exit)) {\n throw toORPCErrorFromCause(exit.cause);\n }\n\n return exit.value as TOutput;\n };\n}\n","import type {\n AnySchema,\n ContractProcedure,\n ContractRouter,\n ErrorMap,\n HTTPPath,\n Meta,\n Route,\n Schema,\n} from \"@orpc/contract\";\nimport { isContractProcedure, oc } from \"@orpc/contract\";\n\nimport type { EffectErrorMap, MergedEffectErrorMap } from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap } from \"./types\";\n\nexport const effectContractSymbol: unique symbol = Symbol.for(\n \"@orpc/effect/contract\",\n);\n\ninterface EffectContractMetadata<TEffectErrorMap extends EffectErrorMap> {\n readonly [effectContractSymbol]: {\n readonly errorMap: TEffectErrorMap;\n };\n}\n\ntype LocalEffectErrorMap<T> =\n T extends EffectContractMetadata<infer TEffectErrorMap extends EffectErrorMap>\n ? TEffectErrorMap\n : Record<never, never>;\n\ntype ContractWithEffectErrorMap<T, TEffectErrorMap extends EffectErrorMap> =\n T extends ContractProcedure<\n infer TInputSchema,\n infer TOutputSchema,\n infer TErrorMap extends ErrorMap,\n infer TMeta extends Meta\n >\n ? ContractProcedure<TInputSchema, TOutputSchema, TErrorMap, TMeta> &\n EffectContractMetadata<\n MergedEffectErrorMap<TEffectErrorMap, LocalEffectErrorMap<T>>\n >\n : T extends ContractRouter<Meta>\n ? {\n [K in keyof T]: ContractWithEffectErrorMap<T[K], TEffectErrorMap>;\n }\n : never;\n\nexport interface EffectContractProcedureBuilder<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n input<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInput<\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n output<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n U,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractProcedureBuilderWithInput<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilderWithInput<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilderWithInput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilderWithInput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n output<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n U,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractProcedureBuilderWithOutput<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n input<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInputOutput<\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractProcedureBuilderWithInputOutput<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilderWithInputOutput<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n}\n\nexport interface EffectContractRouterBuilder<\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n> extends EffectContractMetadata<TEffectErrorMap> {\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractRouterBuilder<\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n prefix(prefix: HTTPPath): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n tag(...tags: string[]): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n router<T extends ContractRouter<TMeta>>(\n router: T,\n ): ContractWithEffectErrorMap<T, TEffectErrorMap>;\n}\n\nexport interface EffectContractBuilder<\n TInputSchema extends AnySchema,\n TOutputSchema extends AnySchema,\n TEffectErrorMap extends EffectErrorMap,\n TMeta extends Meta,\n>\n extends\n ContractProcedure<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n EffectContractMetadata<TEffectErrorMap> {\n $meta<U extends Meta>(\n initialMeta: U,\n ): EffectContractBuilder<TInputSchema, TOutputSchema, TEffectErrorMap, U>;\n $route(\n initialRoute: Route,\n ): EffectContractBuilder<TInputSchema, TOutputSchema, TEffectErrorMap, TMeta>;\n $input<U extends AnySchema>(\n initialInputSchema?: U,\n ): EffectContractBuilder<U, TOutputSchema, TEffectErrorMap, TMeta>;\n errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectContractBuilder<\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta\n >;\n meta(\n meta: TMeta,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n route(\n route: Route,\n ): EffectContractProcedureBuilder<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n input<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithInput<\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta\n >;\n output<U extends AnySchema>(\n schema: U,\n ): EffectContractProcedureBuilderWithOutput<\n TInputSchema,\n U,\n TEffectErrorMap,\n TMeta\n >;\n prefix(prefix: HTTPPath): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n tag(...tags: string[]): EffectContractRouterBuilder<TEffectErrorMap, TMeta>;\n router<T extends ContractRouter<TMeta>>(\n router: T,\n ): ContractWithEffectErrorMap<T, TEffectErrorMap>;\n}\n\nfunction isWrappableContractBuilder(value: unknown): value is {\n \"~orpc\": { errorMap: ErrorMap };\n} {\n return typeof value === \"object\" && value !== null && \"~orpc\" in value;\n}\n\nfunction mergeEffectErrorMaps(\n left: EffectErrorMap | undefined,\n right: EffectErrorMap | undefined,\n): EffectErrorMap | undefined {\n if (!left) {\n return right;\n }\n\n if (!right) {\n return left;\n }\n\n return {\n ...left,\n ...right,\n };\n}\n\nfunction setEffectContractErrorMap(\n value: object,\n effectErrorMap: EffectErrorMap | undefined,\n): void {\n if (!effectErrorMap) {\n return;\n }\n\n Object.defineProperty(value, effectContractSymbol, {\n value: { errorMap: effectErrorMap },\n enumerable: false,\n configurable: true,\n });\n}\n\nexport function getEffectContractErrorMap(\n value: unknown,\n): EffectErrorMap | undefined {\n if (typeof value !== \"object\" || value === null) {\n return undefined;\n }\n\n return (value as Partial<EffectContractMetadata<EffectErrorMap>>)[\n effectContractSymbol\n ]?.errorMap;\n}\n\nfunction applyEffectContractErrorMapToRouter(\n router: ContractRouter<Meta>,\n source: ContractRouter<Meta> | undefined,\n inheritedEffectErrorMap: EffectErrorMap | undefined,\n): void {\n const routerRecord = router as Record<string, ContractRouter<Meta>>;\n const sourceRecord = source as\n | Record<string, ContractRouter<Meta>>\n | undefined;\n\n for (const key of Object.keys(routerRecord)) {\n const routerValue = routerRecord[key];\n const sourceValue =\n sourceRecord && typeof sourceRecord === \"object\"\n ? sourceRecord[key]\n : undefined;\n\n if (!routerValue) {\n continue;\n }\n\n if (isContractProcedure(routerValue)) {\n const sourceEffectErrorMap = getEffectContractErrorMap(sourceValue);\n setEffectContractErrorMap(\n routerValue,\n mergeEffectErrorMaps(inheritedEffectErrorMap, sourceEffectErrorMap),\n );\n continue;\n }\n\n if (typeof routerValue === \"object\") {\n applyEffectContractErrorMapToRouter(\n routerValue,\n sourceValue as ContractRouter<Meta> | undefined,\n inheritedEffectErrorMap,\n );\n }\n }\n}\n\nfunction wrapEffectContractBuilder<T>(\n builder: T,\n inheritedEffectErrorMap?: EffectErrorMap,\n): T {\n const currentEffectErrorMap =\n inheritedEffectErrorMap ?? getEffectContractErrorMap(builder);\n\n if (typeof builder === \"object\" && builder !== null) {\n setEffectContractErrorMap(builder as object, currentEffectErrorMap);\n }\n\n const proxy = new Proxy(builder as object, {\n get(target, prop, receiver) {\n if (prop === effectContractSymbol) {\n return currentEffectErrorMap\n ? { errorMap: currentEffectErrorMap }\n : undefined;\n }\n\n if (prop === \"errors\") {\n return (errors: EffectErrorMap) => {\n const nextEffectErrorMap = mergeEffectErrorMaps(\n currentEffectErrorMap,\n errors,\n );\n\n return wrapEffectContractBuilder(\n Reflect.apply(Reflect.get(target, prop, receiver), target, [\n effectErrorMapToErrorMap(errors),\n ]),\n nextEffectErrorMap,\n );\n };\n }\n\n if (prop === \"router\") {\n return (router: ContractRouter<Meta>) => {\n const result = Reflect.apply(\n Reflect.get(target, prop, receiver),\n target,\n [router],\n ) as ContractRouter<Meta>;\n\n applyEffectContractErrorMapToRouter(\n result,\n router,\n currentEffectErrorMap,\n );\n\n return result;\n };\n }\n\n const value = Reflect.get(target, prop, receiver);\n if (typeof value !== \"function\") {\n return value;\n }\n\n return (...args: unknown[]) => {\n const result = Reflect.apply(value, target, args);\n return isWrappableContractBuilder(result)\n ? wrapEffectContractBuilder(result, currentEffectErrorMap)\n : result;\n };\n },\n }) as T;\n\n setEffectContractErrorMap(proxy as object, currentEffectErrorMap);\n\n return proxy;\n}\n\nexport const eoc = wrapEffectContractBuilder(\n oc,\n {},\n) as unknown as EffectContractBuilder<\n Schema<unknown, unknown>,\n Schema<unknown, unknown>,\n Record<never, never>,\n Record<never, never>\n>;\n"],"mappings":";;;;;AAWA,SAAS,uBAAAA,4BAA2B;AAgBpC,SAAS,iBAAiB;;;ACnB1B,SAAS,SAAS,gBAAgB,QAAAC,aAAY;;;ACR9C;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;;;ACfP,SAAS,WAAW,kBAAkB;AAQtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;AChBA,SAAS,oBAGd,SAAmB,QAAqC;AACxD,SAAO,IAAI,MAAM,QAAQ;AAAA,IACvB,IAAI,eAAe,MAAM,UAAU;AACjC,aAAO,QAAQ,IAAI,SAAS,IAAI,IAC5B,QAAQ,IAAI,SAAS,MAAM,OAAO,IAClC,QAAQ,IAAI,eAAe,MAAM,QAAQ;AAAA,IAC/C;AAAA,IACA,IAAI,eAAe,MAAM;AACvB,aAA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YACA;AAAA,UACF;AAEF,gBAAM,IAAI,MAAM,aAAa;AAC7B,iBAAO;AAAA,QACT;AAEA,YAAI,SAAS,YAAY,SAAS,QAAQ;AACxC,gBAAM,gBAAgB,IAAI,SACxB;AAAA,YACE,QAAQ;AAAA,cACN,QAAQ,IAAI,eAAe,MAAM,aAAa;AAAA,cAC9C;AAAA,cACA;AAAA,YACF;AAAA,YACA,mBAAmB,OAAO;AAAA,UAC5B;AAEF,gBAAM,IAAI,MAAM,aAAa;AAC7B,iBAAO;AAAA,QACT;AAEA,YAAI,OAAO,SAAS,YAAY,QAAQ,UAAU;AAChD,gBAAM,QAAQ;AAAA,YACX,SAA+C,IAAI;AAAA,YACpD,QAAQ,IAAI,eAAe,MAAM,QAAQ;AAAA,YACzC;AAAA,UACF;AAEA,gBAAM,IAAI,MAAM,KAAK;AACrB,iBAAO;AAAA,QACT;AAAA,MACF;AAEA,YAAM,QAAQ,QAAQ,IAAI,eAAe,MAAM,QAAQ;AACvD,aAAO,OAAO,UAAU,aAAa,MAAM,KAAK,aAAa,IAAI;AAAA,IACnE;AAAA,IACA,IAAI,eAAe,MAAM;AACvB,UAAIA,qBAAoB,QAAQ,GAAG;AACjC,YAAI,SAAS,UAAU;AACrB,iBAAO;AAAA,QACT;AACA,YAAI,wBAAwB,IAAI,OAAO,IAAI,CAAC,GAAG;AAC7C,iBAAO;AAAA,QACT;AAAA,MACF,WAAW,OAAO,SAAS,YAAY,QAAQ,UAAU;AACvD,eAAO;AAAA,MACT;AAEA,aAAO,QAAQ,IAAI,eAAe,IAAI;AAAA,IACxC;AAAA,EACF,CAAC;AAOH;AAEO,SAAS,gBAKd,UACA,SAOA;AACA,SAAO;AAAA,IACL;AAAA,IACA,UAAU,QAAQ;AAAA,IAClB;AAAA,EACF;AAOF;","names":["isContractProcedure","lazy","enhanced","ORPCError","Cause","Cause","ORPCError","getOrCreateVirtualMethod","lazy","isContractProcedure"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-orpc",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "keywords": [
5
5
  "effect",
6
6
  "orpc",
@@ -292,6 +292,12 @@ export class EffectBuilder<
292
292
  TRequirementsProvided,
293
293
  TRuntimeError
294
294
  > {
295
+ /**
296
+ * Sets or overrides the config.
297
+ *
298
+ * @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs}
299
+ * @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
300
+ */
295
301
  declare $config: EffectBuilderSurface<
296
302
  TInitialContext,
297
303
  TCurrentContext,
@@ -302,6 +308,11 @@ export class EffectBuilder<
302
308
  TRequirementsProvided,
303
309
  TRuntimeError
304
310
  >["$config"];
311
+ /**
312
+ * Set or override the initial context.
313
+ *
314
+ * @see {@link https://orpc.dev/docs/context Context Docs}
315
+ */
305
316
  declare $context: EffectBuilderSurface<
306
317
  TInitialContext,
307
318
  TCurrentContext,
@@ -312,6 +323,11 @@ export class EffectBuilder<
312
323
  TRequirementsProvided,
313
324
  TRuntimeError
314
325
  >["$context"];
326
+ /**
327
+ * Sets or overrides the initial meta.
328
+ *
329
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
330
+ */
315
331
  declare $meta: EffectBuilderSurface<
316
332
  TInitialContext,
317
333
  TCurrentContext,
@@ -322,6 +338,13 @@ export class EffectBuilder<
322
338
  TRequirementsProvided,
323
339
  TRuntimeError
324
340
  >["$meta"];
341
+ /**
342
+ * Sets or overrides the initial route.
343
+ * This option is typically relevant when integrating with OpenAPI.
344
+ *
345
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
346
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
347
+ */
325
348
  declare $route: EffectBuilderSurface<
326
349
  TInitialContext,
327
350
  TCurrentContext,
@@ -332,6 +355,11 @@ export class EffectBuilder<
332
355
  TRequirementsProvided,
333
356
  TRuntimeError
334
357
  >["$route"];
358
+ /**
359
+ * Sets or overrides the initial input schema.
360
+ *
361
+ * @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
362
+ */
335
363
  declare $input: EffectBuilderSurface<
336
364
  TInitialContext,
337
365
  TCurrentContext,
@@ -342,6 +370,9 @@ export class EffectBuilder<
342
370
  TRequirementsProvided,
343
371
  TRuntimeError
344
372
  >["$input"];
373
+ /**
374
+ * This property holds the defined options and the effect-specific properties.
375
+ */
345
376
  declare "~effect": EffectBuilderDef<
346
377
  TInputSchema,
347
378
  TOutputSchema,
@@ -350,6 +381,9 @@ export class EffectBuilder<
350
381
  TRequirementsProvided,
351
382
  TRuntimeError
352
383
  >;
384
+ /**
385
+ * This property holds the defined options.
386
+ */
353
387
  declare "~orpc": EffectBuilderSurface<
354
388
  TInitialContext,
355
389
  TCurrentContext,
@@ -360,6 +394,11 @@ export class EffectBuilder<
360
394
  TRequirementsProvided,
361
395
  TRuntimeError
362
396
  >["~orpc"];
397
+ /**
398
+ * Creates a middleware.
399
+ *
400
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
401
+ */
363
402
  declare middleware: EffectBuilderSurface<
364
403
  TInitialContext,
365
404
  TCurrentContext,
@@ -370,6 +409,27 @@ export class EffectBuilder<
370
409
  TRequirementsProvided,
371
410
  TRuntimeError
372
411
  >["middleware"];
412
+ /**
413
+ * Adds type-safe custom errors.
414
+ * Supports both traditional oRPC error definitions and ORPCTaggedError classes.
415
+ *
416
+ * @example
417
+ * ```ts
418
+ * // Traditional format
419
+ * builder.errors({ BAD_REQUEST: { status: 400, message: 'Bad request' } })
420
+ *
421
+ * // Tagged error class
422
+ * builder.errors({ USER_NOT_FOUND: UserNotFoundError })
423
+ *
424
+ * // Mixed
425
+ * builder.errors({
426
+ * BAD_REQUEST: { status: 400 },
427
+ * USER_NOT_FOUND: UserNotFoundError,
428
+ * })
429
+ * ```
430
+ *
431
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
432
+ */
373
433
  declare errors: EffectBuilderSurface<
374
434
  TInitialContext,
375
435
  TCurrentContext,
@@ -380,6 +440,13 @@ export class EffectBuilder<
380
440
  TRequirementsProvided,
381
441
  TRuntimeError
382
442
  >["errors"];
443
+ /**
444
+ * Uses a middleware to modify the context or improve the pipeline.
445
+ *
446
+ * @info Supports both normal middleware and inline middleware implementations.
447
+ * @note The current context must be satisfy middleware dependent-context
448
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
449
+ */
383
450
  declare use: EffectBuilderSurface<
384
451
  TInitialContext,
385
452
  TCurrentContext,
@@ -390,6 +457,12 @@ export class EffectBuilder<
390
457
  TRequirementsProvided,
391
458
  TRuntimeError
392
459
  >["use"];
460
+ /**
461
+ * Sets or updates the metadata.
462
+ * The provided metadata is spared-merged with any existing metadata.
463
+ *
464
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
465
+ */
393
466
  declare meta: EffectBuilderSurface<
394
467
  TInitialContext,
395
468
  TCurrentContext,
@@ -400,6 +473,14 @@ export class EffectBuilder<
400
473
  TRequirementsProvided,
401
474
  TRuntimeError
402
475
  >["meta"];
476
+ /**
477
+ * Sets or updates the route definition.
478
+ * The provided route is spared-merged with any existing route.
479
+ * This option is typically relevant when integrating with OpenAPI.
480
+ *
481
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
482
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
483
+ */
403
484
  declare route: EffectBuilderSurface<
404
485
  TInitialContext,
405
486
  TCurrentContext,
@@ -410,6 +491,11 @@ export class EffectBuilder<
410
491
  TRequirementsProvided,
411
492
  TRuntimeError
412
493
  >["route"];
494
+ /**
495
+ * Defines the input validation schema.
496
+ *
497
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
498
+ */
413
499
  declare input: EffectBuilderSurface<
414
500
  TInitialContext,
415
501
  TCurrentContext,
@@ -420,6 +506,11 @@ export class EffectBuilder<
420
506
  TRequirementsProvided,
421
507
  TRuntimeError
422
508
  >["input"];
509
+ /**
510
+ * Defines the output validation schema.
511
+ *
512
+ * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
513
+ */
423
514
  declare output: EffectBuilderSurface<
424
515
  TInitialContext,
425
516
  TCurrentContext,
@@ -430,6 +521,25 @@ export class EffectBuilder<
430
521
  TRequirementsProvided,
431
522
  TRuntimeError
432
523
  >["output"];
524
+ /**
525
+ * Adds a traceable span to the procedure for telemetry.
526
+ * The span name is used for Effect tracing via `Effect.withSpan`.
527
+ * Stack trace is captured at the call site for better error reporting.
528
+ *
529
+ * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
530
+ * @returns An EffectBuilder with span tracing configured
531
+ *
532
+ * @example
533
+ * ```ts
534
+ * const getUser = effectOs
535
+ * .input(z.object({ id: z.string() }))
536
+ * .traced('users.getUser')
537
+ * .effect(function* ({ input }) {
538
+ * const userService = yield* UserService
539
+ * return yield* userService.findById(input.id)
540
+ * })
541
+ * ```
542
+ */
433
543
  declare traced: EffectBuilderSurface<
434
544
  TInitialContext,
435
545
  TCurrentContext,
@@ -440,6 +550,11 @@ export class EffectBuilder<
440
550
  TRequirementsProvided,
441
551
  TRuntimeError
442
552
  >["traced"];
553
+ /**
554
+ * Defines the handler of the procedure using a standard async/sync function.
555
+ *
556
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
557
+ */
443
558
  declare handler: EffectBuilderSurface<
444
559
  TInitialContext,
445
560
  TCurrentContext,
@@ -450,6 +565,13 @@ export class EffectBuilder<
450
565
  TRequirementsProvided,
451
566
  TRuntimeError
452
567
  >["handler"];
568
+ /**
569
+ * Defines the handler of the procedure using an Effect.
570
+ * The Effect is executed using the ManagedRuntime provided during builder creation.
571
+ * The effect is automatically wrapped with `Effect.withSpan`.
572
+ *
573
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
574
+ */
453
575
  declare effect: EffectBuilderSurface<
454
576
  TInitialContext,
455
577
  TCurrentContext,
@@ -460,6 +582,14 @@ export class EffectBuilder<
460
582
  TRequirementsProvided,
461
583
  TRuntimeError
462
584
  >["effect"];
585
+ /**
586
+ * Prefixes all procedures in the router.
587
+ * The provided prefix is post-appended to any existing router prefix.
588
+ *
589
+ * @note This option does not affect procedures that do not define a path in their route definition.
590
+ *
591
+ * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
592
+ */
463
593
  declare prefix: EffectBuilderSurface<
464
594
  TInitialContext,
465
595
  TCurrentContext,
@@ -470,6 +600,12 @@ export class EffectBuilder<
470
600
  TRequirementsProvided,
471
601
  TRuntimeError
472
602
  >["prefix"];
603
+ /**
604
+ * Adds tags to all procedures in the router.
605
+ * This helpful when you want to group procedures together in the OpenAPI specification.
606
+ *
607
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
608
+ */
473
609
  declare tag: EffectBuilderSurface<
474
610
  TInitialContext,
475
611
  TCurrentContext,
@@ -480,6 +616,11 @@ export class EffectBuilder<
480
616
  TRequirementsProvided,
481
617
  TRuntimeError
482
618
  >["tag"];
619
+ /**
620
+ * Applies all of the previously defined options to the specified router.
621
+ *
622
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
623
+ */
483
624
  declare router: EffectBuilderSurface<
484
625
  TInitialContext,
485
626
  TCurrentContext,
@@ -490,6 +631,12 @@ export class EffectBuilder<
490
631
  TRequirementsProvided,
491
632
  TRuntimeError
492
633
  >["router"];
634
+ /**
635
+ * Create a lazy router
636
+ * And applies all of the previously defined options to the specified router.
637
+ *
638
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
639
+ */
493
640
  declare lazy: EffectBuilderSurface<
494
641
  TInitialContext,
495
642
  TCurrentContext,
@@ -530,6 +677,17 @@ export class EffectBuilder<
530
677
  *
531
678
  * @param runtime - The ManagedRuntime that provides services for Effect procedures
532
679
  * @returns An EffectBuilder instance for creating Effect-native procedures
680
+ *
681
+ * @example
682
+ * ```ts
683
+ * import { makeEffectORPC } from '@orpc/effect'
684
+ * import { Effect, Layer, ManagedRuntime } from 'effect'
685
+ *
686
+ * const runtime = ManagedRuntime.make(Layer.empty)
687
+ * const effectOs = makeEffectORPC(runtime)
688
+ *
689
+ * const hello = effectOs.effect(() => Effect.succeed('Hello!'))
690
+ * ```
533
691
  */
534
692
  export function makeEffectORPC<TRequirementsProvided, TRuntimeError>(
535
693
  runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,
@@ -549,8 +707,31 @@ export function makeEffectORPC<TRequirementsProvided, TRuntimeError>(
549
707
  * with the specified ManagedRuntime.
550
708
  *
551
709
  * @param runtime - The ManagedRuntime that provides services for Effect procedures
552
- * @param builder - The oRPC Builder instance to wrap
710
+ * @param builder - The oRPC Builder instance to wrap (e.g., a customized `os`)
553
711
  * @returns An EffectBuilder instance that extends the original builder with Effect support
712
+ *
713
+ * @example
714
+ * ```ts
715
+ * import { makeEffectORPC } from '@orpc/effect'
716
+ * import { os } from '@orpc/server'
717
+ * import { Effect, Layer, ManagedRuntime } from 'effect'
718
+ *
719
+ * // Create a customized builder
720
+ * const authedOs = os.use(authMiddleware)
721
+ *
722
+ * // Wrap it with Effect support
723
+ * const runtime = ManagedRuntime.make(UserServiceLive)
724
+ * const effectOs = makeEffectORPC(runtime, authedOs)
725
+ *
726
+ * const getUser = effectOs
727
+ * .input(z.object({ id: z.string() }))
728
+ * .effect(
729
+ * Effect.fn(function* ({ input }) {
730
+ * const userService = yield* UserService
731
+ * return yield* userService.findById(input.id)
732
+ * })
733
+ * )
734
+ * ```
554
735
  */
555
736
  export function makeEffectORPC<
556
737
  TBuilder extends AnyBuilderLike<
@@ -264,6 +264,9 @@ export class EffectProcedure<
264
264
  EffectErrorMapToErrorMap<TEffectErrorMap>,
265
265
  TMeta
266
266
  > {
267
+ /**
268
+ * This property holds the defined options and the effect-specific properties.
269
+ */
267
270
  declare "~effect": EffectProcedureDef<
268
271
  TInitialContext,
269
272
  TCurrentContext,
@@ -274,6 +277,9 @@ export class EffectProcedure<
274
277
  TRequirementsProvided,
275
278
  TRuntimeError
276
279
  >;
280
+ /**
281
+ * This property holds the defined options.
282
+ */
277
283
  declare "~orpc": ProcedureDef<
278
284
  TInitialContext,
279
285
  TCurrentContext,
@@ -346,6 +352,12 @@ export class EffectDecoratedProcedure<
346
352
  TRuntimeError
347
353
  >
348
354
  {
355
+ /**
356
+ * Adds type-safe custom errors.
357
+ * Supports both traditional oRPC error definitions and ORPCTaggedError classes.
358
+ *
359
+ * @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
360
+ */
349
361
  declare errors: EffectDecoratedProcedureSurface<
350
362
  TInitialContext,
351
363
  TCurrentContext,
@@ -356,6 +368,12 @@ export class EffectDecoratedProcedure<
356
368
  TRequirementsProvided,
357
369
  TRuntimeError
358
370
  >["errors"];
371
+ /**
372
+ * Sets or updates the metadata.
373
+ * The provided metadata is spared-merged with any existing metadata.
374
+ *
375
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
376
+ */
359
377
  declare meta: EffectDecoratedProcedureSurface<
360
378
  TInitialContext,
361
379
  TCurrentContext,
@@ -366,6 +384,14 @@ export class EffectDecoratedProcedure<
366
384
  TRequirementsProvided,
367
385
  TRuntimeError
368
386
  >["meta"];
387
+ /**
388
+ * Sets or updates the route definition.
389
+ * The provided route is spared-merged with any existing route.
390
+ * This option is typically relevant when integrating with OpenAPI.
391
+ *
392
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
393
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
394
+ */
369
395
  declare route: EffectDecoratedProcedureSurface<
370
396
  TInitialContext,
371
397
  TCurrentContext,
@@ -376,6 +402,14 @@ export class EffectDecoratedProcedure<
376
402
  TRequirementsProvided,
377
403
  TRuntimeError
378
404
  >["route"];
405
+ /**
406
+ * Uses a middleware to modify the context or improve the pipeline.
407
+ *
408
+ * @info Supports both normal middleware and inline middleware implementations.
409
+ * @info Pass second argument to map the input.
410
+ * @note The current context must be satisfy middleware dependent-context
411
+ * @see {@link https://orpc.dev/docs/middleware Middleware Docs}
412
+ */
379
413
  declare use: EffectDecoratedProcedureSurface<
380
414
  TInitialContext,
381
415
  TCurrentContext,
@@ -386,6 +420,11 @@ export class EffectDecoratedProcedure<
386
420
  TRequirementsProvided,
387
421
  TRuntimeError
388
422
  >["use"];
423
+ /**
424
+ * Make this procedure callable (works like a function while still being a procedure).
425
+ *
426
+ * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
427
+ */
389
428
  declare callable: EffectDecoratedProcedureSurface<
390
429
  TInitialContext,
391
430
  TCurrentContext,
@@ -396,6 +435,11 @@ export class EffectDecoratedProcedure<
396
435
  TRequirementsProvided,
397
436
  TRuntimeError
398
437
  >["callable"];
438
+ /**
439
+ * Make this procedure compatible with server action.
440
+ *
441
+ * @see {@link https://orpc.dev/docs/server-action Server Action Docs}
442
+ */
399
443
  declare actionable: EffectDecoratedProcedureSurface<
400
444
  TInitialContext,
401
445
  TCurrentContext,