effect-orpc 0.0.10 → 0.1.1
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/README.md +45 -0
- package/dist/chunk-VOWRLWZZ.js +14 -0
- package/dist/chunk-VOWRLWZZ.js.map +1 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/node.js +22 -0
- package/dist/node.js.map +1 -0
- package/package.json +7 -3
- package/src/effect-builder.ts +13 -3
- package/src/fiber-context-bridge.ts +17 -0
- package/src/node.ts +23 -0
- package/src/tests/effect-builder.test.ts +86 -4
- package/src/types/variants.ts +6 -6
package/README.md
CHANGED
|
@@ -23,6 +23,16 @@ pnpm add effect-orpc
|
|
|
23
23
|
bun add effect-orpc
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
`makeEffectORPC` stays on the main `effect-orpc` entrypoint. Only import
|
|
27
|
+
`withFiberContext` from `effect-orpc/node`.
|
|
28
|
+
|
|
29
|
+
The reason for the separate `/node` entrypoint is that `withFiberContext` relies
|
|
30
|
+
on Node/Bun's `AsyncLocalStorage` from `node:async_hooks` to carry Effect
|
|
31
|
+
`FiberRef` state across framework async boundaries. The main package stays
|
|
32
|
+
runtime-agnostic.
|
|
33
|
+
|
|
34
|
+
Runnable demos live in the repository's `examples/` directory.
|
|
35
|
+
|
|
26
36
|
## Demo
|
|
27
37
|
|
|
28
38
|
```ts
|
|
@@ -87,6 +97,41 @@ export const router = {
|
|
|
87
97
|
export type Router = typeof router;
|
|
88
98
|
```
|
|
89
99
|
|
|
100
|
+
## Request-Scoped Fiber Context
|
|
101
|
+
|
|
102
|
+
If you run `effect-orpc` inside a framework such as Hono, the handler executes
|
|
103
|
+
through the runtime boundary and will not automatically inherit request-local
|
|
104
|
+
`FiberRef` state from outer middleware. Import `makeEffectORPC` from the main
|
|
105
|
+
package, and wrap the framework continuation with `withFiberContext` from
|
|
106
|
+
`effect-orpc/node` to preserve request-scoped logs, tracing annotations, and
|
|
107
|
+
other fiber-local state.
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { Hono } from "hono";
|
|
111
|
+
import { Effect, ManagedRuntime } from "effect";
|
|
112
|
+
import { makeEffectORPC } from "effect-orpc";
|
|
113
|
+
import { withFiberContext } from "effect-orpc/node";
|
|
114
|
+
|
|
115
|
+
const runtime = ManagedRuntime.make(AppLive);
|
|
116
|
+
const effectOs = makeEffectORPC(runtime);
|
|
117
|
+
const app = new Hono();
|
|
118
|
+
|
|
119
|
+
app.use("*", async (c, next) => {
|
|
120
|
+
await Effect.runPromise(
|
|
121
|
+
Effect.gen(function* () {
|
|
122
|
+
yield* Effect.annotateLogsScoped({
|
|
123
|
+
requestId: c.get("requestId"),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
yield* withFiberContext(() => next());
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
If you do not need framework-to-handler fiber propagation, you do not need the
|
|
133
|
+
`/node` entrypoint at all.
|
|
134
|
+
|
|
90
135
|
## Type Safety
|
|
91
136
|
|
|
92
137
|
The wrapper enforces that Effect procedures only use services provided by the `ManagedRuntime`. If you try to use a service that isn't in the runtime, you'll get a compile-time error:
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/fiber-context-bridge.ts
|
|
2
|
+
var bridge;
|
|
3
|
+
function installFiberContextBridge(nextBridge) {
|
|
4
|
+
bridge = nextBridge;
|
|
5
|
+
}
|
|
6
|
+
function getCurrentFiberRefs() {
|
|
7
|
+
return bridge?.getCurrentFiberRefs();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
installFiberContextBridge,
|
|
12
|
+
getCurrentFiberRefs
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-VOWRLWZZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fiber-context-bridge.ts"],"sourcesContent":["import type { FiberRefs } from \"effect\";\n\nexport interface FiberContextBridge {\n readonly getCurrentFiberRefs: () => FiberRefs.FiberRefs | undefined;\n}\n\nlet bridge: FiberContextBridge | undefined;\n\nexport function installFiberContextBridge(\n nextBridge: FiberContextBridge | undefined,\n): void {\n bridge = nextBridge;\n}\n\nexport function getCurrentFiberRefs(): FiberRefs.FiberRefs | undefined {\n return bridge?.getCurrentFiberRefs();\n}\n"],"mappings":";AAMA,IAAI;AAEG,SAAS,0BACd,YACM;AACN,WAAS;AACX;AAEO,SAAS,sBAAuD;AACrE,SAAO,QAAQ,oBAAoB;AACrC;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getCurrentFiberRefs
|
|
3
|
+
} from "./chunk-VOWRLWZZ.js";
|
|
4
|
+
|
|
1
5
|
// src/effect-builder.ts
|
|
2
6
|
import {
|
|
3
7
|
mergeMeta as mergeMeta2,
|
|
@@ -596,7 +600,11 @@ var EffectBuilder = class _EffectBuilder {
|
|
|
596
600
|
const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {
|
|
597
601
|
captureStackTrace
|
|
598
602
|
});
|
|
599
|
-
const
|
|
603
|
+
const parentFiberRefs = getCurrentFiberRefs();
|
|
604
|
+
const effectWithRefs = parentFiberRefs ? Effect.setFiberRefs(parentFiberRefs).pipe(
|
|
605
|
+
Effect.andThen(tracedEffect)
|
|
606
|
+
) : tracedEffect;
|
|
607
|
+
const exit = await runtime.runPromiseExit(effectWithRefs, {
|
|
600
608
|
signal: opts.signal
|
|
601
609
|
});
|
|
602
610
|
if (Exit.isFailure(exit)) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/effect-builder.ts","../src/effect-enhance-router.ts","../src/effect-procedure.ts","../src/tagged-error.ts"],"sourcesContent":["import type {\n AnySchema,\n ContractRouter,\n ErrorMap,\n HTTPPath,\n InferSchemaOutput,\n Meta,\n Route,\n Schema,\n} from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n BuilderConfig,\n BuilderDef,\n Context,\n Lazy,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ProcedureHandler,\n ProcedureHandlerOptions,\n Router,\n} from \"@orpc/server\";\nimport type { IntersectPick } from \"@orpc/shared\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport {\n mergeMeta,\n mergePrefix,\n mergeRoute,\n mergeTags,\n ORPCError,\n} from \"@orpc/contract\";\nimport {\n addMiddleware,\n Builder,\n decorateMiddleware,\n fallbackConfig,\n lazy,\n} from \"@orpc/server\";\nimport { Cause, Effect, Exit } from \"effect\";\n\nimport type {\n EffectErrorConstructorMap,\n EffectErrorMap,\n MergedEffectErrorMap,\n} from \"./tagged-error\";\nimport type {\n AnyBuilderLike,\n EffectBuilderDef,\n EffectErrorMapToErrorMap,\n EffectProcedureBuilderWithInput,\n EffectProcedureHandler,\n EffectRouterBuilder,\n EnhancedEffectRouter,\n InferBuilderCurrentContext,\n InferBuilderErrorMap,\n InferBuilderInitialContext,\n InferBuilderInputSchema,\n InferBuilderMeta,\n InferBuilderOutputSchema,\n} from \"./types\";\n\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport {\n createEffectErrorConstructorMap,\n effectErrorMapToErrorMap,\n isORPCTaggedError,\n} from \"./tagged-error\";\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 *\n * @returns A function that lazily extracts the relevant stack frame\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> {\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 declare \"~orpc\": BuilderDef<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >;\n\n constructor(\n def: EffectBuilderDef<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n ) {\n const { runtime, spanConfig, effectErrorMap, ...orpcDef } = def;\n this[\"~orpc\"] = orpcDef;\n this[\"~effect\"] = { runtime, spanConfig, effectErrorMap, ...orpcDef };\n }\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 $config(\n config: BuilderConfig,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const inputValidationCount =\n this[\"~effect\"].inputValidationIndex -\n fallbackConfig(\n \"initialInputValidationIndex\",\n this[\"~effect\"].config.initialInputValidationIndex,\n );\n const outputValidationCount =\n this[\"~effect\"].outputValidationIndex -\n fallbackConfig(\n \"initialOutputValidationIndex\",\n this[\"~effect\"].config.initialOutputValidationIndex,\n );\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n config,\n dedupeLeadingMiddlewares: fallbackConfig(\n \"dedupeLeadingMiddlewares\",\n config.dedupeLeadingMiddlewares,\n ),\n inputValidationIndex:\n fallbackConfig(\n \"initialInputValidationIndex\",\n config.initialInputValidationIndex,\n ) + inputValidationCount,\n outputValidationIndex:\n fallbackConfig(\n \"initialOutputValidationIndex\",\n config.initialOutputValidationIndex,\n ) + outputValidationCount,\n });\n }\n\n /**\n * Set or override the initial context.\n *\n * @see {@link https://orpc.dev/docs/context Context Docs}\n */\n $context<U extends Context>(): EffectBuilder<\n U & Record<never, never>,\n U,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n /**\n * We need `& Record<never, never>` to deal with `has no properties in common with type` error\n */\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n middlewares: [],\n inputValidationIndex: fallbackConfig(\n \"initialInputValidationIndex\",\n this[\"~effect\"].config.initialInputValidationIndex,\n ),\n outputValidationIndex: fallbackConfig(\n \"initialOutputValidationIndex\",\n this[\"~effect\"].config.initialOutputValidationIndex,\n ),\n });\n }\n\n /**\n * Sets or overrides the initial meta.\n *\n * @see {@link https://orpc.dev/docs/metadata Metadata Docs}\n */\n $meta<U extends Meta>(\n initialMeta: U,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n U & Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n > {\n /**\n * We need `& Record<never, never>` to deal with `has no properties in common with type` error\n */\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n meta: initialMeta,\n });\n }\n\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 $route(\n initialRoute: Route,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n route: initialRoute,\n });\n }\n\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 $input<U extends AnySchema>(\n initialInputSchema?: U,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n inputSchema: initialInputSchema,\n });\n }\n\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 errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const newEffectErrorMap: MergedEffectErrorMap<TEffectErrorMap, U> = {\n ...this[\"~effect\"].effectErrorMap,\n ...errors,\n };\n return new EffectBuilder({\n ...this[\"~effect\"],\n errorMap: effectErrorMapToErrorMap(newEffectErrorMap),\n effectErrorMap: newEffectErrorMap,\n });\n }\n\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 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 unknown,\n EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\n >,\n ): EffectBuilder<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n\n use(\n middleware: AnyMiddleware,\n mapInput?: MapInputMiddleware<any, any>,\n ): EffectBuilder<any, any, any, any, any, any, any, any> {\n const mapped = mapInput\n ? decorateMiddleware(middleware).mapInput(mapInput)\n : middleware;\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n middlewares: addMiddleware(this[\"~effect\"].middlewares, mapped),\n });\n }\n\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 meta(\n meta: TMeta,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n meta: mergeMeta(this[\"~effect\"].meta, meta),\n });\n }\n\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 route(\n route: Route,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n route: mergeRoute(this[\"~effect\"].route, route),\n });\n }\n\n /**\n * Defines the input validation schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}\n */\n input<USchema extends AnySchema>(\n schema: USchema,\n ): EffectProcedureBuilderWithInput<\n TInitialContext,\n TCurrentContext,\n USchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n inputSchema: schema,\n inputValidationIndex:\n fallbackConfig(\n \"initialInputValidationIndex\",\n this[\"~effect\"].config.initialInputValidationIndex,\n ) + this[\"~effect\"].middlewares.length,\n // we cast to any because EffectProcedureBuilderWithInput is expecting\n // use() input type to be defined, and EffectBuilder types its use() input\n // to unknown to allow any middleware to be passed\n // ---\n // note: the original implentation of the builder also uses any for the same reason\n }) as any;\n }\n\n /**\n * Defines the output validation schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}\n */\n output<USchema extends AnySchema>(\n schema: USchema,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n USchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n outputSchema: schema,\n outputValidationIndex:\n fallbackConfig(\n \"initialOutputValidationIndex\",\n this[\"~effect\"].config.initialOutputValidationIndex,\n ) + this[\"~effect\"].middlewares.length,\n });\n }\n\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 traced(\n spanName: string,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n spanConfig: {\n name: spanName,\n captureStackTrace: addSpanStackTrace(),\n },\n });\n }\n\n handler<UFuncOutput>(\n handler: ProcedureHandler<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n UFuncOutput,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n Schema<UFuncOutput, UFuncOutput>,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n handler,\n });\n }\n\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 effect<UFuncOutput>(\n effectFn: EffectProcedureHandler<\n TCurrentContext,\n TInputSchema,\n UFuncOutput,\n TEffectErrorMap,\n TRequirementsProvided,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n Schema<UFuncOutput, UFuncOutput>,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const { runtime, spanConfig } = this[\"~effect\"];\n // Capture stack trace at definition time for default tracing\n const defaultCaptureStackTrace = addSpanStackTrace();\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n handler: async (opts) => {\n const effectOpts: ProcedureHandlerOptions<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\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(\n this[\"~effect\"].effectErrorMap,\n ),\n };\n const spanName = spanConfig?.name ?? opts.path.join(\".\");\n const captureStackTrace =\n spanConfig?.captureStackTrace ?? defaultCaptureStackTrace;\n const resolver = Effect.fnUntraced(effectFn);\n const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {\n captureStackTrace,\n });\n const exit = await runtime.runPromiseExit(tracedEffect, {\n signal: opts.signal,\n });\n\n if (Exit.isFailure(exit)) {\n throw Cause.match(exit.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\n return exit.value;\n },\n });\n }\n\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 prefix(\n prefix: HTTPPath,\n ): EffectRouterBuilder<\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n prefix: mergePrefix(this[\"~effect\"].prefix, prefix),\n }) as any;\n }\n\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 tag(\n ...tags: string[]\n ): EffectRouterBuilder<\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n tags: mergeTags(this[\"~effect\"].tags, tags),\n }) as any;\n }\n\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 router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(\n router: U,\n ): EnhancedEffectRouter<\n U,\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap\n > {\n return enhanceEffectRouter(router, {\n ...this[\"~effect\"],\n }) as any; // Type instantiation is excessively deep and possibly infinite\n }\n\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 lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(\n loader: () => Promise<{ default: U }>,\n ): EnhancedEffectRouter<\n Lazy<U>,\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap\n > {\n return enhanceEffectRouter(lazy(loader), {\n ...this[\"~effect\"],\n }) as any; // Type instantiation is excessively deep and possibly infinite\n }\n}\n\n/**\n * Creates an Effect-aware procedure builder with the specified ManagedRuntime.\n * Uses the default `os` builder 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 return new EffectBuilder({\n ...resolvedBuilder[\"~orpc\"],\n errorMap: effectErrorMapToErrorMap(resolvedBuilder[\"~orpc\"].errorMap),\n effectErrorMap: resolvedBuilder[\"~orpc\"].errorMap,\n runtime,\n });\n}\n\nfunction emptyBuilder(): AnyBuilderLike {\n return new Builder({\n config: {},\n route: {},\n meta: {},\n errorMap: {},\n inputValidationIndex: fallbackConfig(\"initialInputValidationIndex\"),\n outputValidationIndex: fallbackConfig(\"initialOutputValidationIndex\"),\n middlewares: [],\n dedupeLeadingMiddlewares: true,\n });\n}\n","import type { ManagedRuntime } from \"effect/ManagedRuntime\";\n\nimport {\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\";\n\nimport type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from \"./types\";\n\nimport { EffectProcedure } from \"./effect-procedure\";\nimport { effectErrorMapToErrorMap, type EffectErrorMap } from \"./tagged-error\";\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 enhanced = enhanceEffectRouter(unlaziedRouter, options);\n return unlazy(enhanced);\n },\n {\n ...laziedMeta,\n prefix: enhancedPrefix,\n },\n );\n\n const accessible = createAccessibleLazyRouter(enhanced);\n\n return accessible as any;\n }\n\n if (isProcedure(router)) {\n const newMiddlewares = mergeMiddlewares(\n options.middlewares,\n router[\"~orpc\"].middlewares,\n { dedupeLeading: options.dedupeLeadingMiddlewares },\n );\n const newMiddlewareAdded =\n newMiddlewares.length - router[\"~orpc\"].middlewares.length;\n\n const effectErrorMap = {\n ...options.errorMap,\n ...router[\"~orpc\"].errorMap,\n };\n const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =\n effectErrorMapToErrorMap(effectErrorMap);\n const enhanced = new EffectProcedure({\n ...router[\"~orpc\"],\n route: enhanceRoute(router[\"~orpc\"].route, options),\n effectErrorMap,\n errorMap: errorMap as EffectErrorMapToErrorMap<typeof effectErrorMap>,\n middlewares: newMiddlewares,\n inputValidationIndex:\n router[\"~orpc\"].inputValidationIndex + newMiddlewareAdded,\n outputValidationIndex:\n router[\"~orpc\"].outputValidationIndex + newMiddlewareAdded,\n runtime: options.runtime,\n });\n\n return enhanced as any;\n }\n\n const enhanced = {} as 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 {\n AnySchema,\n InferSchemaInput,\n InferSchemaOutput,\n Meta,\n Route,\n} from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n Context,\n CreateProcedureClientOptions,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ProcedureActionableClient,\n ProcedureClient,\n ProcedureDef,\n} from \"@orpc/server\";\nimport type { IntersectPick, MaybeOptionalOptions } from \"@orpc/shared\";\n\nimport { mergeMeta, mergeRoute } from \"@orpc/contract\";\nimport {\n addMiddleware,\n createActionableClient,\n createProcedureClient,\n decorateMiddleware,\n Procedure,\n} from \"@orpc/server\";\n\nimport type {\n EffectErrorConstructorMap,\n EffectErrorMap,\n MergedEffectErrorMap,\n} from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureDef } from \"./types\";\n\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\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 ) {\n super(def);\n this[\"~effect\"] = def;\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> extends EffectProcedure<\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 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 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 ) {\n super(def);\n this[\"~effect\"] = def;\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 errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const newEffectErrorMap: MergedEffectErrorMap<TEffectErrorMap, U> = {\n ...this[\"~effect\"].effectErrorMap,\n ...errors,\n };\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n effectErrorMap: newEffectErrorMap,\n errorMap: effectErrorMapToErrorMap(newEffectErrorMap),\n });\n }\n\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 meta(\n meta: TMeta,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n meta: mergeMeta(this[\"~effect\"].meta, meta),\n });\n }\n\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 route(\n route: Route,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n route: mergeRoute(this[\"~effect\"].route, route),\n });\n }\n\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 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 EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n\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 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 EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\n >,\n mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,\n ): EffectDecoratedProcedure<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n\n use(\n middleware: AnyMiddleware,\n mapInput?: MapInputMiddleware<any, any>,\n ): EffectDecoratedProcedure<any, any, any, any, any, any, any, any> {\n const mapped = mapInput\n ? decorateMiddleware(middleware).mapInput(mapInput)\n : middleware;\n\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n middlewares: addMiddleware(this[\"~effect\"].middlewares, mapped),\n });\n }\n\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 callable<TClientContext extends ClientContext>(\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<\n TInitialContext,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta,\n TClientContext\n >\n >\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > &\n ProcedureClient<\n TClientContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > {\n const client: ProcedureClient<\n TClientContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > = createProcedureClient(this, ...rest);\n\n return new Proxy(client, {\n get: (target, key) => {\n return Reflect.has(this, key)\n ? Reflect.get(this, key)\n : Reflect.get(target, key);\n },\n has: (target, key) => {\n return Reflect.has(this, key) || Reflect.has(target, key);\n },\n }) as any;\n }\n\n /**\n * Make this procedure compatible with server action.\n *\n * @see {@link https://orpc.dev/docs/server-action Server Action Docs}\n */\n actionable(\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<\n TInitialContext,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta,\n Record<never, never>\n >\n >\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > &\n ProcedureActionableClient<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > {\n const action: ProcedureActionableClient<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > = createActionableClient(createProcedureClient(this, ...rest));\n\n return new Proxy(action, {\n get: (target, key) => {\n return Reflect.has(this, key)\n ? Reflect.get(this, key)\n : Reflect.get(target, key);\n },\n has: (target, key) => {\n return Reflect.has(this, key) || Reflect.has(target, key);\n },\n }) as any;\n }\n}\n","import type {\n ORPCErrorCode,\n ORPCErrorJSON,\n ORPCErrorOptions,\n} from \"@orpc/client\";\nimport type {\n AnySchema,\n ErrorMap,\n ErrorMapItem,\n InferSchemaOutput,\n} from \"@orpc/contract\";\nimport type { ORPCErrorConstructorMap } from \"@orpc/server\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\nimport type { Pipeable } from \"effect\";\n\nimport {\n fallbackORPCErrorMessage,\n fallbackORPCErrorStatus,\n isORPCErrorStatus,\n ORPCError,\n} from \"@orpc/client\";\nimport { resolveMaybeOptionalOptions } from \"@orpc/shared\";\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 */\nexport type EffectErrorConstructorMap<T extends EffectErrorMap> =\n ORPCErrorConstructorMap<EffectErrorMapToErrorMap<T>>;\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 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"],"mappings":";AA2BA;AAAA,EACE,aAAAA;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,OACK;AACP;AAAA,EACE,iBAAAC;AAAA,EACA;AAAA,EACA,sBAAAC;AAAA,EACA;AAAA,EACA,QAAAC;AAAA,OACK;AACP,SAAS,SAAAC,QAAO,QAAQ,YAAY;;;ACvCpC;AAAA,EACE;AAAA,EAC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AAA;AAAA;AAAA;AAAA;AAAA,EAOA,OACE,QAMA;AACA,WAAO,oBAAoB,QAAQ;AAAA,MACjC,GAAG,KAAK,SAAS;AAAA,IACnB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KACE,QAMA;AACA,WAAO,oBAAoBC,MAAK,MAAM,GAAG;AAAA,MACvC,GAAG,KAAK,SAAS;AAAA,IACnB,CAAC;AAAA,EACH;AACF;AA2FO,SAAS,eACd,SACA,SAUA;AACA,QAAM,kBAAkB,WAAW,aAAa;AAChD,SAAO,IAAI,cAAc;AAAA,IACvB,GAAG,gBAAgB,OAAO;AAAA,IAC1B,UAAU,yBAAyB,gBAAgB,OAAO,EAAE,QAAQ;AAAA,IACpE,gBAAgB,gBAAgB,OAAO,EAAE;AAAA,IACzC;AAAA,EACF,CAAC;AACH;AAEA,SAAS,eAA+B;AACtC,SAAO,IAAI,QAAQ;AAAA,IACjB,QAAQ,CAAC;AAAA,IACT,OAAO,CAAC;AAAA,IACR,MAAM,CAAC;AAAA,IACP,UAAU,CAAC;AAAA,IACX,sBAAsB,eAAe,6BAA6B;AAAA,IAClE,uBAAuB,eAAe,8BAA8B;AAAA,IACpE,aAAa,CAAC;AAAA,IACd,0BAA0B;AAAA,EAC5B,CAAC;AACH;","names":["mergeMeta","mergePrefix","mergeRoute","ORPCError","addMiddleware","decorateMiddleware","lazy","Cause","enhanced","decorateMiddleware","addMiddleware","mergeMeta","mergeRoute","Cause","ORPCError","mergePrefix","lazy"]}
|
|
1
|
+
{"version":3,"sources":["../src/effect-builder.ts","../src/effect-enhance-router.ts","../src/effect-procedure.ts","../src/tagged-error.ts"],"sourcesContent":["import type {\n AnySchema,\n ContractRouter,\n ErrorMap,\n HTTPPath,\n InferSchemaOutput,\n Meta,\n Route,\n Schema,\n} from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n BuilderConfig,\n BuilderDef,\n Context,\n Lazy,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ProcedureHandler,\n ProcedureHandlerOptions,\n Router,\n} from \"@orpc/server\";\nimport type { IntersectPick } from \"@orpc/shared\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport {\n mergeMeta,\n mergePrefix,\n mergeRoute,\n mergeTags,\n ORPCError,\n} from \"@orpc/contract\";\nimport {\n addMiddleware,\n Builder,\n decorateMiddleware,\n fallbackConfig,\n lazy,\n} from \"@orpc/server\";\nimport { Cause, Effect, Exit } from \"effect\";\n\nimport type {\n EffectErrorConstructorMap,\n EffectErrorMap,\n MergedEffectErrorMap,\n} from \"./tagged-error\";\nimport type {\n AnyBuilderLike,\n EffectBuilderDef,\n EffectErrorMapToErrorMap,\n EffectProcedureBuilderWithInput,\n EffectProcedureBuilderWithOutput,\n EffectProcedureHandler,\n EffectRouterBuilder,\n EnhancedEffectRouter,\n InferBuilderCurrentContext,\n InferBuilderErrorMap,\n InferBuilderInitialContext,\n InferBuilderInputSchema,\n InferBuilderMeta,\n InferBuilderOutputSchema,\n} from \"./types\";\n\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport { getCurrentFiberRefs } from \"./fiber-context-bridge\";\nimport {\n createEffectErrorConstructorMap,\n effectErrorMapToErrorMap,\n isORPCTaggedError,\n} from \"./tagged-error\";\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 *\n * @returns A function that lazily extracts the relevant stack frame\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> {\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 declare \"~orpc\": BuilderDef<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >;\n\n constructor(\n def: EffectBuilderDef<\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >,\n ) {\n const { runtime, spanConfig, effectErrorMap, ...orpcDef } = def;\n this[\"~orpc\"] = orpcDef;\n this[\"~effect\"] = { runtime, spanConfig, effectErrorMap, ...orpcDef };\n }\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 $config(\n config: BuilderConfig,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const inputValidationCount =\n this[\"~effect\"].inputValidationIndex -\n fallbackConfig(\n \"initialInputValidationIndex\",\n this[\"~effect\"].config.initialInputValidationIndex,\n );\n const outputValidationCount =\n this[\"~effect\"].outputValidationIndex -\n fallbackConfig(\n \"initialOutputValidationIndex\",\n this[\"~effect\"].config.initialOutputValidationIndex,\n );\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n config,\n dedupeLeadingMiddlewares: fallbackConfig(\n \"dedupeLeadingMiddlewares\",\n config.dedupeLeadingMiddlewares,\n ),\n inputValidationIndex:\n fallbackConfig(\n \"initialInputValidationIndex\",\n config.initialInputValidationIndex,\n ) + inputValidationCount,\n outputValidationIndex:\n fallbackConfig(\n \"initialOutputValidationIndex\",\n config.initialOutputValidationIndex,\n ) + outputValidationCount,\n });\n }\n\n /**\n * Set or override the initial context.\n *\n * @see {@link https://orpc.dev/docs/context Context Docs}\n */\n $context<U extends Context>(): EffectBuilder<\n U & Record<never, never>,\n U,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n /**\n * We need `& Record<never, never>` to deal with `has no properties in common with type` error\n */\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n middlewares: [],\n inputValidationIndex: fallbackConfig(\n \"initialInputValidationIndex\",\n this[\"~effect\"].config.initialInputValidationIndex,\n ),\n outputValidationIndex: fallbackConfig(\n \"initialOutputValidationIndex\",\n this[\"~effect\"].config.initialOutputValidationIndex,\n ),\n });\n }\n\n /**\n * Sets or overrides the initial meta.\n *\n * @see {@link https://orpc.dev/docs/metadata Metadata Docs}\n */\n $meta<U extends Meta>(\n initialMeta: U,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n U & Record<never, never>,\n TRequirementsProvided,\n TRuntimeError\n > {\n /**\n * We need `& Record<never, never>` to deal with `has no properties in common with type` error\n */\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n meta: initialMeta,\n });\n }\n\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 $route(\n initialRoute: Route,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n route: initialRoute,\n });\n }\n\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 $input<U extends AnySchema>(\n initialInputSchema?: U,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n U,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n inputSchema: initialInputSchema,\n });\n }\n\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 errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const newEffectErrorMap: MergedEffectErrorMap<TEffectErrorMap, U> = {\n ...this[\"~effect\"].effectErrorMap,\n ...errors,\n };\n return new EffectBuilder({\n ...this[\"~effect\"],\n errorMap: effectErrorMapToErrorMap(newEffectErrorMap),\n effectErrorMap: newEffectErrorMap,\n });\n }\n\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 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 unknown,\n EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\n >,\n ): EffectBuilder<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n\n use(\n middleware: AnyMiddleware,\n mapInput?: MapInputMiddleware<any, any>,\n ): EffectBuilder<any, any, any, any, any, any, any, any> {\n const mapped = mapInput\n ? decorateMiddleware(middleware).mapInput(mapInput)\n : middleware;\n\n return new EffectBuilder({\n ...this[\"~effect\"],\n middlewares: addMiddleware(this[\"~effect\"].middlewares, mapped),\n });\n }\n\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 meta(\n meta: TMeta,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n meta: mergeMeta(this[\"~effect\"].meta, meta),\n });\n }\n\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 route(\n route: Route,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n route: mergeRoute(this[\"~effect\"].route, route),\n });\n }\n\n /**\n * Defines the input validation schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}\n */\n input<USchema extends AnySchema>(\n schema: USchema,\n ): EffectProcedureBuilderWithInput<\n TInitialContext,\n TCurrentContext,\n USchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n inputSchema: schema,\n inputValidationIndex:\n fallbackConfig(\n \"initialInputValidationIndex\",\n this[\"~effect\"].config.initialInputValidationIndex,\n ) + this[\"~effect\"].middlewares.length,\n // we cast to any because EffectProcedureBuilderWithInput is expecting\n // use() input type to be defined, and EffectBuilder types its use() input\n // to unknown to allow any middleware to be passed\n // ---\n // note: the original implentation of the builder also uses any for the same reason\n }) as any;\n }\n\n /**\n * Defines the output validation schema.\n *\n * @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}\n */\n output<USchema extends AnySchema>(\n schema: USchema,\n ): EffectProcedureBuilderWithOutput<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n USchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n // We cast to any because EffectProcedureBuilderWithOutput narrows\n // handler/effect output typing based on the declared output schema.\n return new EffectBuilder({\n ...this[\"~effect\"],\n outputSchema: schema,\n outputValidationIndex:\n fallbackConfig(\n \"initialOutputValidationIndex\",\n this[\"~effect\"].config.initialOutputValidationIndex,\n ) + this[\"~effect\"].middlewares.length,\n }) as any;\n }\n\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 traced(\n spanName: string,\n ): EffectBuilder<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n spanConfig: {\n name: spanName,\n captureStackTrace: addSpanStackTrace(),\n },\n });\n }\n\n handler<UFuncOutput>(\n handler: ProcedureHandler<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n UFuncOutput,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n Schema<UFuncOutput, UFuncOutput>,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n handler,\n });\n }\n\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 effect<UFuncOutput>(\n effectFn: EffectProcedureHandler<\n TCurrentContext,\n TInputSchema,\n UFuncOutput,\n TEffectErrorMap,\n TRequirementsProvided,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n Schema<UFuncOutput, UFuncOutput>,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const { runtime, spanConfig } = this[\"~effect\"];\n // Capture stack trace at definition time for default tracing\n const defaultCaptureStackTrace = addSpanStackTrace();\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n handler: async (opts) => {\n const effectOpts: ProcedureHandlerOptions<\n TCurrentContext,\n InferSchemaOutput<TInputSchema>,\n EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\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(\n this[\"~effect\"].effectErrorMap,\n ),\n };\n const spanName = spanConfig?.name ?? opts.path.join(\".\");\n const captureStackTrace =\n spanConfig?.captureStackTrace ?? defaultCaptureStackTrace;\n const resolver = Effect.fnUntraced(effectFn);\n const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {\n captureStackTrace,\n });\n const parentFiberRefs = getCurrentFiberRefs();\n const effectWithRefs = parentFiberRefs\n ? Effect.setFiberRefs(parentFiberRefs).pipe(\n Effect.andThen(tracedEffect),\n )\n : tracedEffect;\n const exit = await runtime.runPromiseExit(effectWithRefs, {\n signal: opts.signal,\n });\n\n if (Exit.isFailure(exit)) {\n throw Cause.match(exit.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\n return exit.value;\n },\n });\n }\n\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 prefix(\n prefix: HTTPPath,\n ): EffectRouterBuilder<\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n prefix: mergePrefix(this[\"~effect\"].prefix, prefix),\n }) as any;\n }\n\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 tag(\n ...tags: string[]\n ): EffectRouterBuilder<\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectBuilder({\n ...this[\"~effect\"],\n tags: mergeTags(this[\"~effect\"].tags, tags),\n }) as any;\n }\n\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 router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(\n router: U,\n ): EnhancedEffectRouter<\n U,\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap\n > {\n return enhanceEffectRouter(router, {\n ...this[\"~effect\"],\n }) as any; // Type instantiation is excessively deep and possibly infinite\n }\n\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 lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(\n loader: () => Promise<{ default: U }>,\n ): EnhancedEffectRouter<\n Lazy<U>,\n TInitialContext,\n TCurrentContext,\n TEffectErrorMap\n > {\n return enhanceEffectRouter(lazy(loader), {\n ...this[\"~effect\"],\n }) as any; // Type instantiation is excessively deep and possibly infinite\n }\n}\n\n/**\n * Creates an Effect-aware procedure builder with the specified ManagedRuntime.\n * Uses the default `os` builder 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 return new EffectBuilder({\n ...resolvedBuilder[\"~orpc\"],\n errorMap: effectErrorMapToErrorMap(resolvedBuilder[\"~orpc\"].errorMap),\n effectErrorMap: resolvedBuilder[\"~orpc\"].errorMap,\n runtime,\n });\n}\n\nfunction emptyBuilder(): AnyBuilderLike {\n return new Builder({\n config: {},\n route: {},\n meta: {},\n errorMap: {},\n inputValidationIndex: fallbackConfig(\"initialInputValidationIndex\"),\n outputValidationIndex: fallbackConfig(\"initialOutputValidationIndex\"),\n middlewares: [],\n dedupeLeadingMiddlewares: true,\n });\n}\n","import type { ManagedRuntime } from \"effect/ManagedRuntime\";\n\nimport {\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\";\n\nimport type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from \"./types\";\n\nimport { EffectProcedure } from \"./effect-procedure\";\nimport { effectErrorMapToErrorMap, type EffectErrorMap } from \"./tagged-error\";\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 enhanced = enhanceEffectRouter(unlaziedRouter, options);\n return unlazy(enhanced);\n },\n {\n ...laziedMeta,\n prefix: enhancedPrefix,\n },\n );\n\n const accessible = createAccessibleLazyRouter(enhanced);\n\n return accessible as any;\n }\n\n if (isProcedure(router)) {\n const newMiddlewares = mergeMiddlewares(\n options.middlewares,\n router[\"~orpc\"].middlewares,\n { dedupeLeading: options.dedupeLeadingMiddlewares },\n );\n const newMiddlewareAdded =\n newMiddlewares.length - router[\"~orpc\"].middlewares.length;\n\n const effectErrorMap = {\n ...options.errorMap,\n ...router[\"~orpc\"].errorMap,\n };\n const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =\n effectErrorMapToErrorMap(effectErrorMap);\n const enhanced = new EffectProcedure({\n ...router[\"~orpc\"],\n route: enhanceRoute(router[\"~orpc\"].route, options),\n effectErrorMap,\n errorMap: errorMap as EffectErrorMapToErrorMap<typeof effectErrorMap>,\n middlewares: newMiddlewares,\n inputValidationIndex:\n router[\"~orpc\"].inputValidationIndex + newMiddlewareAdded,\n outputValidationIndex:\n router[\"~orpc\"].outputValidationIndex + newMiddlewareAdded,\n runtime: options.runtime,\n });\n\n return enhanced as any;\n }\n\n const enhanced = {} as 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 {\n AnySchema,\n InferSchemaInput,\n InferSchemaOutput,\n Meta,\n Route,\n} from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n Context,\n CreateProcedureClientOptions,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ProcedureActionableClient,\n ProcedureClient,\n ProcedureDef,\n} from \"@orpc/server\";\nimport type { IntersectPick, MaybeOptionalOptions } from \"@orpc/shared\";\n\nimport { mergeMeta, mergeRoute } from \"@orpc/contract\";\nimport {\n addMiddleware,\n createActionableClient,\n createProcedureClient,\n decorateMiddleware,\n Procedure,\n} from \"@orpc/server\";\n\nimport type {\n EffectErrorConstructorMap,\n EffectErrorMap,\n MergedEffectErrorMap,\n} from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureDef } from \"./types\";\n\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\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 ) {\n super(def);\n this[\"~effect\"] = def;\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> extends EffectProcedure<\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 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 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 ) {\n super(def);\n this[\"~effect\"] = def;\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 errors<U extends EffectErrorMap>(\n errors: U,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n MergedEffectErrorMap<TEffectErrorMap, U>,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n const newEffectErrorMap: MergedEffectErrorMap<TEffectErrorMap, U> = {\n ...this[\"~effect\"].effectErrorMap,\n ...errors,\n };\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n effectErrorMap: newEffectErrorMap,\n errorMap: effectErrorMapToErrorMap(newEffectErrorMap),\n });\n }\n\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 meta(\n meta: TMeta,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n meta: mergeMeta(this[\"~effect\"].meta, meta),\n });\n }\n\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 route(\n route: Route,\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > {\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n route: mergeRoute(this[\"~effect\"].route, route),\n });\n }\n\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 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 EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\n >,\n ): EffectDecoratedProcedure<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n\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 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 EffectErrorConstructorMap<TEffectErrorMap>,\n TMeta\n >,\n mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,\n ): EffectDecoratedProcedure<\n MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,\n MergedCurrentContext<TCurrentContext, UOutContext>,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n >;\n\n use(\n middleware: AnyMiddleware,\n mapInput?: MapInputMiddleware<any, any>,\n ): EffectDecoratedProcedure<any, any, any, any, any, any, any, any> {\n const mapped = mapInput\n ? decorateMiddleware(middleware).mapInput(mapInput)\n : middleware;\n\n return new EffectDecoratedProcedure({\n ...this[\"~effect\"],\n middlewares: addMiddleware(this[\"~effect\"].middlewares, mapped),\n });\n }\n\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 callable<TClientContext extends ClientContext>(\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<\n TInitialContext,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta,\n TClientContext\n >\n >\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > &\n ProcedureClient<\n TClientContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > {\n const client: ProcedureClient<\n TClientContext,\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > = createProcedureClient(this, ...rest);\n\n return new Proxy(client, {\n get: (target, key) => {\n return Reflect.has(this, key)\n ? Reflect.get(this, key)\n : Reflect.get(target, key);\n },\n has: (target, key) => {\n return Reflect.has(this, key) || Reflect.has(target, key);\n },\n }) as any;\n }\n\n /**\n * Make this procedure compatible with server action.\n *\n * @see {@link https://orpc.dev/docs/server-action Server Action Docs}\n */\n actionable(\n ...rest: MaybeOptionalOptions<\n CreateProcedureClientOptions<\n TInitialContext,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>,\n TMeta,\n Record<never, never>\n >\n >\n ): EffectDecoratedProcedure<\n TInitialContext,\n TCurrentContext,\n TInputSchema,\n TOutputSchema,\n TEffectErrorMap,\n TMeta,\n TRequirementsProvided,\n TRuntimeError\n > &\n ProcedureActionableClient<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > {\n const action: ProcedureActionableClient<\n TInputSchema,\n TOutputSchema,\n EffectErrorMapToErrorMap<TEffectErrorMap>\n > = createActionableClient(createProcedureClient(this, ...rest));\n\n return new Proxy(action, {\n get: (target, key) => {\n return Reflect.has(this, key)\n ? Reflect.get(this, key)\n : Reflect.get(target, key);\n },\n has: (target, key) => {\n return Reflect.has(this, key) || Reflect.has(target, key);\n },\n }) as any;\n }\n}\n","import type {\n ORPCErrorCode,\n ORPCErrorJSON,\n ORPCErrorOptions,\n} from \"@orpc/client\";\nimport type {\n AnySchema,\n ErrorMap,\n ErrorMapItem,\n InferSchemaOutput,\n} from \"@orpc/contract\";\nimport type { ORPCErrorConstructorMap } from \"@orpc/server\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\nimport type { Pipeable } from \"effect\";\n\nimport {\n fallbackORPCErrorMessage,\n fallbackORPCErrorStatus,\n isORPCErrorStatus,\n ORPCError,\n} from \"@orpc/client\";\nimport { resolveMaybeOptionalOptions } from \"@orpc/shared\";\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 */\nexport type EffectErrorConstructorMap<T extends EffectErrorMap> =\n ORPCErrorConstructorMap<EffectErrorMapToErrorMap<T>>;\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 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"],"mappings":";;;;;AA2BA;AAAA,EACE,aAAAA;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,OACK;AACP;AAAA,EACE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ACjB,QAAQC,aAAY,KAAK,SAAS,EAAE,QAAQ,MAAM;AAAA,IACpD,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OACK,MAQH;AACA,WAAO,IAAI,eAAc;AAAA,MACvB,GAAG,KAAK,SAAS;AAAA,MACjB,MAAM,UAAU,KAAK,SAAS,EAAE,MAAM,IAAI;AAAA,IAC5C,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OACE,QAMA;AACA,WAAO,oBAAoB,QAAQ;AAAA,MACjC,GAAG,KAAK,SAAS;AAAA,IACnB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,KACE,QAMA;AACA,WAAO,oBAAoBC,MAAK,MAAM,GAAG;AAAA,MACvC,GAAG,KAAK,SAAS;AAAA,IACnB,CAAC;AAAA,EACH;AACF;AA2FO,SAAS,eACd,SACA,SAUA;AACA,QAAM,kBAAkB,WAAW,aAAa;AAChD,SAAO,IAAI,cAAc;AAAA,IACvB,GAAG,gBAAgB,OAAO;AAAA,IAC1B,UAAU,yBAAyB,gBAAgB,OAAO,EAAE,QAAQ;AAAA,IACpE,gBAAgB,gBAAgB,OAAO,EAAE;AAAA,IACzC;AAAA,EACF,CAAC;AACH;AAEA,SAAS,eAA+B;AACtC,SAAO,IAAI,QAAQ;AAAA,IACjB,QAAQ,CAAC;AAAA,IACT,OAAO,CAAC;AAAA,IACR,MAAM,CAAC;AAAA,IACP,UAAU,CAAC;AAAA,IACX,sBAAsB,eAAe,6BAA6B;AAAA,IAClE,uBAAuB,eAAe,8BAA8B;AAAA,IACpE,aAAa,CAAC;AAAA,IACd,0BAA0B;AAAA,EAC5B,CAAC;AACH;","names":["mergeMeta","mergePrefix","mergeRoute","ORPCError","addMiddleware","decorateMiddleware","lazy","Cause","enhanced","decorateMiddleware","addMiddleware","mergeMeta","mergeRoute","Cause","ORPCError","mergePrefix","lazy"]}
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installFiberContextBridge
|
|
3
|
+
} from "./chunk-VOWRLWZZ.js";
|
|
4
|
+
|
|
5
|
+
// src/node.ts
|
|
6
|
+
import { Effect } from "effect";
|
|
7
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
8
|
+
var fiberRefsStorage = new AsyncLocalStorage();
|
|
9
|
+
var bridge = {
|
|
10
|
+
getCurrentFiberRefs: () => fiberRefsStorage.getStore()
|
|
11
|
+
};
|
|
12
|
+
installFiberContextBridge(bridge);
|
|
13
|
+
function withFiberContext(fn) {
|
|
14
|
+
return Effect.flatMap(
|
|
15
|
+
Effect.getFiberRefs,
|
|
16
|
+
(fiberRefs) => Effect.promise(() => fiberRefsStorage.run(fiberRefs, fn))
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
withFiberContext
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node.ts"],"sourcesContent":["import type { FiberRefs } from \"effect\";\n\nimport { Effect } from \"effect\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport {\n installFiberContextBridge,\n type FiberContextBridge,\n} from \"./fiber-context-bridge\";\n\nconst fiberRefsStorage = new AsyncLocalStorage<FiberRefs.FiberRefs>();\n\nconst bridge: FiberContextBridge = {\n getCurrentFiberRefs: () => fiberRefsStorage.getStore(),\n};\n\ninstallFiberContextBridge(bridge);\n\nexport function withFiberContext<T>(fn: () => Promise<T>): Effect.Effect<T> {\n return Effect.flatMap(Effect.getFiberRefs, (fiberRefs) =>\n Effect.promise(() => fiberRefsStorage.run(fiberRefs, fn)),\n );\n}\n"],"mappings":";;;;;AAEA,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAOlC,IAAM,mBAAmB,IAAI,kBAAuC;AAEpE,IAAM,SAA6B;AAAA,EACjC,qBAAqB,MAAM,iBAAiB,SAAS;AACvD;AAEA,0BAA0B,MAAM;AAEzB,SAAS,iBAAoB,IAAwC;AAC1E,SAAO,OAAO;AAAA,IAAQ,OAAO;AAAA,IAAc,CAAC,cAC1C,OAAO,QAAQ,MAAM,iBAAiB,IAAI,WAAW,EAAE,CAAC;AAAA,EAC1D;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-orpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"effect",
|
|
6
6
|
"orpc",
|
|
@@ -20,13 +20,18 @@
|
|
|
20
20
|
],
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".": "./src/index.ts"
|
|
23
|
+
".": "./src/index.ts",
|
|
24
|
+
"./node": "./src/node.ts"
|
|
24
25
|
},
|
|
25
26
|
"publishConfig": {
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
29
|
"types": "./src/index.ts",
|
|
29
30
|
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./node": {
|
|
33
|
+
"types": "./src/node.ts",
|
|
34
|
+
"default": "./dist/node.js"
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
},
|
|
@@ -46,7 +51,6 @@
|
|
|
46
51
|
"oxfmt": "^0.21.0",
|
|
47
52
|
"oxlint": "^1.36.0",
|
|
48
53
|
"tsup": "^8.5.1",
|
|
49
|
-
"ultracite": "7.0.3",
|
|
50
54
|
"vitest": "^4.0.16",
|
|
51
55
|
"zod": "^4.3.4"
|
|
52
56
|
},
|
package/src/effect-builder.ts
CHANGED
|
@@ -51,6 +51,7 @@ import type {
|
|
|
51
51
|
EffectBuilderDef,
|
|
52
52
|
EffectErrorMapToErrorMap,
|
|
53
53
|
EffectProcedureBuilderWithInput,
|
|
54
|
+
EffectProcedureBuilderWithOutput,
|
|
54
55
|
EffectProcedureHandler,
|
|
55
56
|
EffectRouterBuilder,
|
|
56
57
|
EnhancedEffectRouter,
|
|
@@ -64,6 +65,7 @@ import type {
|
|
|
64
65
|
|
|
65
66
|
import { enhanceEffectRouter } from "./effect-enhance-router";
|
|
66
67
|
import { EffectDecoratedProcedure } from "./effect-procedure";
|
|
68
|
+
import { getCurrentFiberRefs } from "./fiber-context-bridge";
|
|
67
69
|
import {
|
|
68
70
|
createEffectErrorConstructorMap,
|
|
69
71
|
effectErrorMapToErrorMap,
|
|
@@ -484,7 +486,7 @@ export class EffectBuilder<
|
|
|
484
486
|
*/
|
|
485
487
|
output<USchema extends AnySchema>(
|
|
486
488
|
schema: USchema,
|
|
487
|
-
):
|
|
489
|
+
): EffectProcedureBuilderWithOutput<
|
|
488
490
|
TInitialContext,
|
|
489
491
|
TCurrentContext,
|
|
490
492
|
TInputSchema,
|
|
@@ -494,6 +496,8 @@ export class EffectBuilder<
|
|
|
494
496
|
TRequirementsProvided,
|
|
495
497
|
TRuntimeError
|
|
496
498
|
> {
|
|
499
|
+
// We cast to any because EffectProcedureBuilderWithOutput narrows
|
|
500
|
+
// handler/effect output typing based on the declared output schema.
|
|
497
501
|
return new EffectBuilder({
|
|
498
502
|
...this["~effect"],
|
|
499
503
|
outputSchema: schema,
|
|
@@ -502,7 +506,7 @@ export class EffectBuilder<
|
|
|
502
506
|
"initialOutputValidationIndex",
|
|
503
507
|
this["~effect"].config.initialOutputValidationIndex,
|
|
504
508
|
) + this["~effect"].middlewares.length,
|
|
505
|
-
});
|
|
509
|
+
}) as any;
|
|
506
510
|
}
|
|
507
511
|
|
|
508
512
|
/**
|
|
@@ -624,7 +628,13 @@ export class EffectBuilder<
|
|
|
624
628
|
const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {
|
|
625
629
|
captureStackTrace,
|
|
626
630
|
});
|
|
627
|
-
const
|
|
631
|
+
const parentFiberRefs = getCurrentFiberRefs();
|
|
632
|
+
const effectWithRefs = parentFiberRefs
|
|
633
|
+
? Effect.setFiberRefs(parentFiberRefs).pipe(
|
|
634
|
+
Effect.andThen(tracedEffect),
|
|
635
|
+
)
|
|
636
|
+
: tracedEffect;
|
|
637
|
+
const exit = await runtime.runPromiseExit(effectWithRefs, {
|
|
628
638
|
signal: opts.signal,
|
|
629
639
|
});
|
|
630
640
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FiberRefs } from "effect";
|
|
2
|
+
|
|
3
|
+
export interface FiberContextBridge {
|
|
4
|
+
readonly getCurrentFiberRefs: () => FiberRefs.FiberRefs | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
let bridge: FiberContextBridge | undefined;
|
|
8
|
+
|
|
9
|
+
export function installFiberContextBridge(
|
|
10
|
+
nextBridge: FiberContextBridge | undefined,
|
|
11
|
+
): void {
|
|
12
|
+
bridge = nextBridge;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getCurrentFiberRefs(): FiberRefs.FiberRefs | undefined {
|
|
16
|
+
return bridge?.getCurrentFiberRefs();
|
|
17
|
+
}
|
package/src/node.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { FiberRefs } from "effect";
|
|
2
|
+
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
installFiberContextBridge,
|
|
8
|
+
type FiberContextBridge,
|
|
9
|
+
} from "./fiber-context-bridge";
|
|
10
|
+
|
|
11
|
+
const fiberRefsStorage = new AsyncLocalStorage<FiberRefs.FiberRefs>();
|
|
12
|
+
|
|
13
|
+
const bridge: FiberContextBridge = {
|
|
14
|
+
getCurrentFiberRefs: () => fiberRefsStorage.getStore(),
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
installFiberContextBridge(bridge);
|
|
18
|
+
|
|
19
|
+
export function withFiberContext<T>(fn: () => Promise<T>): Effect.Effect<T> {
|
|
20
|
+
return Effect.flatMap(Effect.getFiberRefs, (fiberRefs) =>
|
|
21
|
+
Effect.promise(() => fiberRefsStorage.run(fiberRefs, fn)),
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import type { InferSchemaOutput } from "@orpc/contract";
|
|
2
|
+
|
|
1
3
|
import { isContractProcedure } from "@orpc/contract";
|
|
2
4
|
import { os } from "@orpc/server";
|
|
3
|
-
import { Effect, Layer, ManagedRuntime } from "effect";
|
|
4
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { Effect, FiberRef, Layer, ManagedRuntime } from "effect";
|
|
6
|
+
import { beforeEach, describe, expect, expectTypeOf, it, vi } from "vitest";
|
|
5
7
|
import z from "zod";
|
|
6
8
|
|
|
7
9
|
import { EffectBuilder, makeEffectORPC } from "../effect-builder";
|
|
8
10
|
import { EffectDecoratedProcedure } from "../effect-procedure";
|
|
11
|
+
import { withFiberContext } from "../node";
|
|
9
12
|
import { effectErrorMapToErrorMap, ORPCTaggedError } from "../tagged-error";
|
|
10
13
|
import {
|
|
11
14
|
baseErrorMap,
|
|
@@ -159,6 +162,58 @@ describe("effectBuilder", () => {
|
|
|
159
162
|
expect(result).toEqual({ output: "processed-test-input" });
|
|
160
163
|
expect(effectFn).toHaveBeenCalledTimes(1);
|
|
161
164
|
});
|
|
165
|
+
|
|
166
|
+
it(".effect does not inherit parent FiberRefs by default", async () => {
|
|
167
|
+
const requestIdRef = FiberRef.unsafeMake("missing");
|
|
168
|
+
const applied = builder.effect(function* () {
|
|
169
|
+
return yield* FiberRef.get(requestIdRef);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const result = await Effect.runPromise(
|
|
173
|
+
Effect.gen(function* () {
|
|
174
|
+
yield* FiberRef.set(requestIdRef, "req-123");
|
|
175
|
+
return yield* Effect.promise(() =>
|
|
176
|
+
applied["~effect"].handler({
|
|
177
|
+
context: {},
|
|
178
|
+
input: undefined,
|
|
179
|
+
path: ["test"],
|
|
180
|
+
procedure: applied as any,
|
|
181
|
+
signal: undefined,
|
|
182
|
+
lastEventId: undefined,
|
|
183
|
+
errors: {},
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
}),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
expect(result).toBe("missing");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it(".effect inherits parent FiberRefs with withFiberContext", async () => {
|
|
193
|
+
const requestIdRef = FiberRef.unsafeMake("missing");
|
|
194
|
+
const applied = builder.effect(function* () {
|
|
195
|
+
return yield* FiberRef.get(requestIdRef);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const result = await Effect.runPromise(
|
|
199
|
+
Effect.gen(function* () {
|
|
200
|
+
yield* FiberRef.set(requestIdRef, "req-123");
|
|
201
|
+
return yield* withFiberContext(() =>
|
|
202
|
+
applied["~effect"].handler({
|
|
203
|
+
context: {},
|
|
204
|
+
input: undefined,
|
|
205
|
+
path: ["test"],
|
|
206
|
+
procedure: applied as any,
|
|
207
|
+
signal: undefined,
|
|
208
|
+
lastEventId: undefined,
|
|
209
|
+
errors: {},
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
expect(result).toBe("req-123");
|
|
216
|
+
});
|
|
162
217
|
});
|
|
163
218
|
|
|
164
219
|
describe("makeEffectORPC factory", () => {
|
|
@@ -213,7 +268,7 @@ describe("makeEffectORPC factory", () => {
|
|
|
213
268
|
it("supports Effect.fn generator syntax", async () => {
|
|
214
269
|
const effectBuilder = makeEffectORPC(runtime);
|
|
215
270
|
|
|
216
|
-
//
|
|
271
|
+
//
|
|
217
272
|
const procedure = effectBuilder.effect(function* () {
|
|
218
273
|
const a = yield* Effect.succeed(1);
|
|
219
274
|
const b = yield* Effect.succeed(2);
|
|
@@ -284,7 +339,6 @@ describe("effect with services", () => {
|
|
|
284
339
|
const serviceRuntime = ManagedRuntime.make(CounterLive);
|
|
285
340
|
const effectBuilder = makeEffectORPC(serviceRuntime);
|
|
286
341
|
|
|
287
|
-
// oxlint-disable-next-line require-yield
|
|
288
342
|
const procedure = effectBuilder.input(z.number()).effect(function* ({
|
|
289
343
|
input,
|
|
290
344
|
}) {
|
|
@@ -516,4 +570,32 @@ describe("default tracing (without .traced())", () => {
|
|
|
516
570
|
const withInput = effectBuilder.input(z.string());
|
|
517
571
|
expect(withInput["~effect"].spanConfig).toBeUndefined();
|
|
518
572
|
});
|
|
573
|
+
|
|
574
|
+
it("enforces the declared output schema for effect handlers", () => {
|
|
575
|
+
const declaredOutputSchema = z.object({ name: z.string() });
|
|
576
|
+
|
|
577
|
+
makeEffectORPC(runtime)
|
|
578
|
+
.input(z.string())
|
|
579
|
+
.output(declaredOutputSchema)
|
|
580
|
+
.effect(
|
|
581
|
+
// @ts-expect-error input().output() should constrain the effect return type
|
|
582
|
+
// oxlint-disable-next-line require-yield
|
|
583
|
+
function* () {
|
|
584
|
+
return { count: 1 };
|
|
585
|
+
},
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
const procedure = makeEffectORPC(runtime)
|
|
589
|
+
.output(declaredOutputSchema)
|
|
590
|
+
// @ts-expect-error output() should constrain the effect return type
|
|
591
|
+
// oxlint-disable-next-line require-yield
|
|
592
|
+
.effect(function* () {
|
|
593
|
+
return { count: 1 };
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
type ProcedureOutput = InferSchemaOutput<
|
|
597
|
+
NonNullable<(typeof procedure)["~orpc"]["outputSchema"]>
|
|
598
|
+
>;
|
|
599
|
+
expectTypeOf<ProcedureOutput>().toEqualTypeOf<{ name: string }>();
|
|
600
|
+
});
|
|
519
601
|
});
|
package/src/types/variants.ts
CHANGED
|
@@ -910,11 +910,11 @@ export interface EffectProcedureBuilderWithOutput<
|
|
|
910
910
|
TRuntimeError
|
|
911
911
|
>;
|
|
912
912
|
|
|
913
|
-
"effect"
|
|
913
|
+
"effect"(
|
|
914
914
|
effectFn: EffectProcedureHandler<
|
|
915
915
|
TCurrentContext,
|
|
916
916
|
InferSchemaOutput<TInputSchema>,
|
|
917
|
-
|
|
917
|
+
InferSchemaInput<TOutputSchema>,
|
|
918
918
|
TEffectErrorMap,
|
|
919
919
|
TRequirementsProvided,
|
|
920
920
|
TMeta
|
|
@@ -923,7 +923,7 @@ export interface EffectProcedureBuilderWithOutput<
|
|
|
923
923
|
TInitialContext,
|
|
924
924
|
TCurrentContext,
|
|
925
925
|
TInputSchema,
|
|
926
|
-
|
|
926
|
+
TOutputSchema,
|
|
927
927
|
TEffectErrorMap,
|
|
928
928
|
TMeta,
|
|
929
929
|
TRequirementsProvided,
|
|
@@ -1123,11 +1123,11 @@ export interface EffectProcedureBuilderWithInputOutput<
|
|
|
1123
1123
|
TRuntimeError
|
|
1124
1124
|
>;
|
|
1125
1125
|
|
|
1126
|
-
"effect"
|
|
1126
|
+
"effect"(
|
|
1127
1127
|
effectFn: EffectProcedureHandler<
|
|
1128
1128
|
TCurrentContext,
|
|
1129
1129
|
InferSchemaOutput<TInputSchema>,
|
|
1130
|
-
|
|
1130
|
+
InferSchemaInput<TOutputSchema>,
|
|
1131
1131
|
TEffectErrorMap,
|
|
1132
1132
|
TRequirementsProvided,
|
|
1133
1133
|
TMeta
|
|
@@ -1136,7 +1136,7 @@ export interface EffectProcedureBuilderWithInputOutput<
|
|
|
1136
1136
|
TInitialContext,
|
|
1137
1137
|
TCurrentContext,
|
|
1138
1138
|
TInputSchema,
|
|
1139
|
-
|
|
1139
|
+
TOutputSchema,
|
|
1140
1140
|
TEffectErrorMap,
|
|
1141
1141
|
TMeta,
|
|
1142
1142
|
TRequirementsProvided,
|