effect-orpc 0.1.1 → 1.0.0-effect-v4.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.
@@ -0,0 +1,14 @@
1
+ // src/service-context-bridge.ts
2
+ var bridge;
3
+ function installServiceContextBridge(nextBridge) {
4
+ bridge = nextBridge;
5
+ }
6
+ function getCurrentServices() {
7
+ return bridge?.getCurrentServices();
8
+ }
9
+
10
+ export {
11
+ installServiceContextBridge,
12
+ getCurrentServices
13
+ };
14
+ //# sourceMappingURL=chunk-E5YLLTJI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/service-context-bridge.ts"],"sourcesContent":["import type { ServiceMap } from \"effect\";\n\nexport interface ServiceContextBridge {\n readonly getCurrentServices: () => ServiceMap.ServiceMap<any> | undefined;\n}\n\nlet bridge: ServiceContextBridge | undefined;\n\nexport function installServiceContextBridge(\n nextBridge: ServiceContextBridge | undefined,\n): void {\n bridge = nextBridge;\n}\n\nexport function getCurrentServices(): ServiceMap.ServiceMap<any> | undefined {\n return bridge?.getCurrentServices();\n}\n"],"mappings":";AAMA,IAAI;AAEG,SAAS,4BACd,YACM;AACN,WAAS;AACX;AAEO,SAAS,qBAA6D;AAC3E,SAAO,QAAQ,mBAAmB;AACpC;","names":[]}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
- getCurrentFiberRefs
3
- } from "./chunk-VOWRLWZZ.js";
2
+ getCurrentServices
3
+ } from "./chunk-E5YLLTJI.js";
4
4
 
5
5
  // src/effect-builder.ts
6
6
  import {
@@ -17,7 +17,7 @@ import {
17
17
  fallbackConfig,
18
18
  lazy as lazy2
19
19
  } from "@orpc/server";
20
- import { Cause as Cause2, Effect, Exit } from "effect";
20
+ import { Cause as Cause2, Effect, Exit, ServiceMap } from "effect";
21
21
 
22
22
  // src/effect-enhance-router.ts
23
23
  import {
@@ -344,6 +344,32 @@ function addSpanStackTrace() {
344
344
  }
345
345
  };
346
346
  }
347
+ function toORPCErrorFromCause(cause) {
348
+ const reason = cause.reasons[0];
349
+ if (reason === void 0) {
350
+ return new ORPCError2("INTERNAL_SERVER_ERROR");
351
+ }
352
+ if (Cause2.isDieReason(reason)) {
353
+ return new ORPCError2("INTERNAL_SERVER_ERROR", {
354
+ cause: reason.defect
355
+ });
356
+ }
357
+ if (Cause2.isFailReason(reason)) {
358
+ const error = reason.error;
359
+ if (isORPCTaggedError(error)) {
360
+ return error.toORPCError();
361
+ }
362
+ if (error instanceof ORPCError2) {
363
+ return error;
364
+ }
365
+ return new ORPCError2("INTERNAL_SERVER_ERROR", {
366
+ cause: error
367
+ });
368
+ }
369
+ return new ORPCError2("INTERNAL_SERVER_ERROR", {
370
+ cause: new Error(`${reason.fiberId} Interrupted`)
371
+ });
372
+ }
347
373
  var EffectBuilder = class _EffectBuilder {
348
374
  constructor(def) {
349
375
  const { runtime, spanConfig, effectErrorMap, ...orpcDef } = def;
@@ -600,46 +626,16 @@ var EffectBuilder = class _EffectBuilder {
600
626
  const tracedEffect = Effect.withSpan(resolver(effectOpts), spanName, {
601
627
  captureStackTrace
602
628
  });
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, {
629
+ const parentServices = getCurrentServices();
630
+ const exit = parentServices ? await Effect.runPromiseExitWith(
631
+ ServiceMap.merge(await runtime.services(), parentServices)
632
+ )(tracedEffect, {
633
+ signal: opts.signal
634
+ }) : await runtime.runPromiseExit(tracedEffect, {
608
635
  signal: opts.signal
609
636
  });
610
637
  if (Exit.isFailure(exit)) {
611
- throw Cause2.match(exit.cause, {
612
- onDie(defect) {
613
- return new ORPCError2("INTERNAL_SERVER_ERROR", {
614
- cause: defect
615
- });
616
- },
617
- onFail(error) {
618
- if (isORPCTaggedError(error)) {
619
- return error.toORPCError();
620
- }
621
- if (error instanceof ORPCError2) {
622
- return error;
623
- }
624
- return new ORPCError2("INTERNAL_SERVER_ERROR", {
625
- cause: error
626
- });
627
- },
628
- onInterrupt(fiberId) {
629
- return new ORPCError2("INTERNAL_SERVER_ERROR", {
630
- cause: new Error(`${fiberId} Interrupted`)
631
- });
632
- },
633
- onSequential(left) {
634
- return left;
635
- },
636
- onEmpty: new ORPCError2("INTERNAL_SERVER_ERROR", {
637
- cause: new Error("Unknown error")
638
- }),
639
- onParallel(left) {
640
- return left;
641
- }
642
- });
638
+ throw toORPCErrorFromCause(exit.cause);
643
639
  }
644
640
  return exit.value;
645
641
  }
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 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,iBAAAC;AAAA,EACA;AAAA,EACA,sBAAAC;AAAA,EACA;AAAA,EACA,QAAAC;AAAA,OACK;AACP,SAAS,SAAAC,QAAO,QAAQ,YAAY;;;ACvCpC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;;;ACGP,SAAS,WAAW,kBAAkB;AACtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACdP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mCAAmC;AAC5C,OAAuB;AACvB,YAAY,UAAU;AAOf,IAAM,kBAAiC,uBAAO;AAAA,EACnD;AACF;AAwEO,SAAS,uBAC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AAK,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 {\n mergeMeta,\n mergePrefix,\n mergeRoute,\n mergeTags,\n ORPCError,\n} from \"@orpc/contract\";\nimport type {\n AnyMiddleware,\n BuilderConfig,\n BuilderDef,\n Context,\n IntersectPick,\n Lazy,\n MapInputMiddleware,\n MergedCurrentContext,\n MergedInitialContext,\n Middleware,\n ProcedureHandler,\n ProcedureHandlerOptions,\n Router,\n} from \"@orpc/server\";\nimport {\n addMiddleware,\n Builder,\n decorateMiddleware,\n fallbackConfig,\n lazy,\n} from \"@orpc/server\";\nimport { Cause, Effect, Exit, ManagedRuntime, ServiceMap } from \"effect\";\n\nimport { enhanceEffectRouter } from \"./effect-enhance-router\";\nimport { EffectDecoratedProcedure } from \"./effect-procedure\";\nimport { getCurrentServices } from \"./service-context-bridge\";\nimport type {\n EffectErrorConstructorMap,\n EffectErrorMap,\n MergedEffectErrorMap,\n} from \"./tagged-error\";\nimport {\n createEffectErrorConstructorMap,\n effectErrorMapToErrorMap,\n isORPCTaggedError,\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\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\nfunction toORPCErrorFromCause(\n cause: Cause.Cause<unknown>,\n): ORPCError<string, unknown> {\n const reason = cause.reasons[0];\n\n if (reason === undefined) {\n return new ORPCError(\"INTERNAL_SERVER_ERROR\");\n }\n\n if (Cause.isDieReason(reason)) {\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: reason.defect,\n });\n }\n\n if (Cause.isFailReason(reason)) {\n const error = reason.error;\n\n if (isORPCTaggedError(error)) {\n return error.toORPCError();\n }\n if (error instanceof ORPCError) {\n return error;\n }\n\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: error,\n });\n }\n\n return new ORPCError(\"INTERNAL_SERVER_ERROR\", {\n cause: new Error(`${reason.fiberId} Interrupted`),\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 parentServices = getCurrentServices();\n const exit = parentServices\n ? await Effect.runPromiseExitWith(\n ServiceMap.merge(await runtime.services(), parentServices),\n )(tracedEffect, {\n signal: opts.signal,\n })\n : await runtime.runPromiseExit(tracedEffect, {\n signal: opts.signal,\n });\n\n if (Exit.isFailure(exit)) {\n throw toORPCErrorFromCause(exit.cause);\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 {\n enhanceRoute,\n mergePrefix,\n type EnhanceRouteOptions,\n} from \"@orpc/contract\";\nimport {\n createAccessibleLazyRouter,\n getLazyMeta,\n isLazy,\n isProcedure,\n lazy,\n mergeMiddlewares,\n unlazy,\n type AnyMiddleware,\n type AnyRouter,\n type Context,\n type Lazyable,\n} from \"@orpc/server\";\nimport type { ManagedRuntime } from \"effect\";\n\nimport { EffectProcedure } from \"./effect-procedure\";\nimport { effectErrorMapToErrorMap, type EffectErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from \"./types\";\n\ninterface EnhanceEffectRouterOptions<\n TEffectErrorMap extends EffectErrorMap,\n TRequirementsProvided,\n TRuntimeError,\n> extends EnhanceRouteOptions {\n middlewares: readonly AnyMiddleware[];\n errorMap: TEffectErrorMap;\n dedupeLeadingMiddlewares: boolean;\n runtime: ManagedRuntime.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 { mergeMeta, mergeRoute } 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 {\n addMiddleware,\n createActionableClient,\n createProcedureClient,\n decorateMiddleware,\n Procedure,\n} from \"@orpc/server\";\nimport type { IntersectPick, MaybeOptionalOptions } from \"@orpc/shared\";\n\nimport type {\n EffectErrorConstructorMap,\n EffectErrorMap,\n MergedEffectErrorMap,\n} from \"./tagged-error\";\nimport { effectErrorMapToErrorMap } from \"./tagged-error\";\nimport type { EffectErrorMapToErrorMap, EffectProcedureDef } from \"./types\";\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 {\n fallbackORPCErrorMessage,\n fallbackORPCErrorStatus,\n isORPCErrorStatus,\n ORPCError,\n} from \"@orpc/client\";\nimport type {\n AnySchema,\n ErrorMap,\n ErrorMapItem,\n InferSchemaOutput,\n} from \"@orpc/contract\";\nimport type { ORPCErrorConstructorMap } from \"@orpc/server\";\nimport type { MaybeOptionalOptions } from \"@orpc/shared\";\nimport { resolveMaybeOptionalOptions } from \"@orpc/shared\";\nimport type { Pipeable } from \"effect\";\nimport * as Cause from \"effect/Cause\";\nimport * as Data from \"effect/Data\";\n\nimport type { EffectErrorMapToErrorMap } from \"./types\";\n\n/**\n * Symbol to access the underlying ORPCError instance\n */\nexport const ORPCErrorSymbol: unique symbol = Symbol.for(\n \"@orpc/effect/ORPCTaggedError\",\n);\n\n/**\n * Instance type for ORPCTaggedError that combines YieldableError with ORPCError properties\n */\nexport interface ORPCTaggedErrorInstance<\n TTag extends string,\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n>\n extends Cause.YieldableError, Pipeable.Pipeable {\n readonly _tag: TTag;\n readonly code: TCode;\n readonly status: number;\n readonly schema: TSchema;\n readonly data: InferSchemaOutput<TSchema>;\n readonly defined: boolean;\n readonly [ORPCErrorSymbol]: ORPCError<TCode, InferSchemaOutput<TSchema>>;\n\n toJSON(): ORPCErrorJSON<TCode, InferSchemaOutput<TSchema>> & { _tag: TTag };\n toORPCError(): ORPCError<TCode, InferSchemaOutput<TSchema>>;\n}\n\n/**\n * Options for creating an ORPCTaggedError\n */\nexport type ORPCTaggedErrorOptions<TData> = Omit<\n ORPCErrorOptions<TData>,\n \"defined\"\n> & { defined?: boolean };\n\n/**\n * Constructor type for ORPCTaggedError classes\n */\nexport interface ORPCTaggedErrorClass<\n TTag extends string,\n TCode extends ORPCErrorCode,\n TSchema extends AnySchema = AnySchema,\n> {\n readonly _tag: TTag;\n readonly code: TCode;\n new (\n ...args: MaybeOptionalOptions<\n ORPCTaggedErrorOptions<InferSchemaOutput<TSchema>>\n >\n ): ORPCTaggedErrorInstance<TTag, TCode, TSchema>;\n}\n\n/**\n * Type helper to infer the ORPCError type from an ORPCTaggedError\n */\nexport type InferORPCError<T> =\n T extends ORPCTaggedErrorInstance<string, infer TCode, infer TSchema>\n ? ORPCError<TCode, InferSchemaOutput<TSchema>>\n : never;\n\n/**\n * Any ORPCTaggedErrorClass\n * Uses `...args: any[]` for the constructor to accept any tagged error class,\n * regardless of whether TData requires options to be provided.\n */\nexport type AnyORPCTaggedErrorClass = {\n readonly _tag: string;\n readonly code: ORPCErrorCode;\n new (\n ...args: any[]\n ): ORPCTaggedErrorInstance<string, ORPCErrorCode, AnySchema>;\n};\n\n/**\n * Check if a value is an ORPCTaggedErrorClass (constructor)\n */\nexport function isORPCTaggedErrorClass(\n value: unknown,\n): value is AnyORPCTaggedErrorClass {\n return (\n typeof value === \"function\" &&\n \"_tag\" in value &&\n \"code\" in value &&\n typeof value._tag === \"string\" &&\n typeof value.code === \"string\"\n );\n}\n\n/**\n * Check if a value is an ORPCTaggedError instance\n */\nexport function isORPCTaggedError(\n value: unknown,\n): value is ORPCTaggedErrorInstance<string, ORPCErrorCode, AnySchema> {\n return (\n typeof value === \"object\" && value !== null && ORPCErrorSymbol in value\n );\n}\n\n/**\n * Converts a PascalCase or camelCase string to CONSTANT_CASE.\n * e.g., \"UserNotFoundError\" -> \"USER_NOT_FOUND_ERROR\"\n */\nfunction toConstantCase<T extends string>(str: T): ToConstantCase<T> {\n return str\n .replace(/([a-z])([A-Z])/g, \"$1_$2\")\n .replace(/([A-Z])([A-Z][a-z])/g, \"$1_$2\")\n .toUpperCase() as ToConstantCase<T>;\n}\n/**\n * Checks if a character is an uppercase letter (A-Z)\n */\ntype IsUpperLetter<C extends string> =\n C extends Uppercase<C>\n ? C extends Lowercase<C>\n ? false // Not a letter (number, special char)\n : true\n : false;\n\n/**\n * Checks if a character is a lowercase letter (a-z)\n */\ntype IsLowerLetter<C extends string> =\n C extends Lowercase<C>\n ? C extends Uppercase<C>\n ? false // Not a letter (number, special char)\n : true\n : false;\n\n/**\n * Converts PascalCase or camelCase to CONSTANT_CASE.\n * Handles consecutive uppercase letters correctly.\n *\n * @example\n * type T1 = ToConstantCase<\"ABCCode\">; // \"ABC_CODE\"\n * type T2 = ToConstantCase<\"UserCode\">; // \"USER_CODE\"\n * type T3 = ToConstantCase<\"XMLHttpRequest\">; // \"XML_HTTP_REQUEST\"\n */\ntype ToConstantCase<\n S extends string,\n Acc extends string = \"\",\n PrevChar extends string = \"\",\n InUpperSequence extends boolean = false,\n> = S extends `${infer Head}${infer Tail}`\n ? IsUpperLetter<Head> extends true\n ? Acc extends \"\"\n ? // First character - no underscore\n ToConstantCase<Tail, Head, Head, false>\n : PrevChar extends \"\"\n ? // Shouldn't happen, but handle gracefully\n ToConstantCase<Tail, Head, Head, false>\n : IsUpperLetter<PrevChar> extends true\n ? // We're in an uppercase sequence\n Tail extends `${infer Next}${infer _}`\n ? IsLowerLetter<Next> extends true\n ? // Next char is lowercase, so Head starts a new word - insert underscore\n ToConstantCase<Tail, `${Acc}_${Head}`, Head, false>\n : // Next char is uppercase or non-letter - continue sequence\n ToConstantCase<Tail, `${Acc}${Head}`, Head, true>\n : // Tail is empty - just append\n ToConstantCase<Tail, `${Acc}${Head}`, Head, true>\n : // Transition from lowercase to uppercase - insert underscore\n ToConstantCase<Tail, `${Acc}_${Head}`, Head, false>\n : IsLowerLetter<Head> extends true\n ? InUpperSequence extends true\n ? // End of uppercase sequence (2+) - insert underscore before lowercase\n ToConstantCase<Tail, `${Acc}_${Uppercase<Head>}`, Head, false>\n : // Single uppercase or no uppercase - no underscore\n ToConstantCase<Tail, `${Acc}${Uppercase<Head>}`, Head, false>\n : // Non-letter character - reset sequence\n ToConstantCase<Tail, `${Acc}${Head}`, Head, false>\n : Acc;\n\n/**\n * Converts a tag name to an error code in CONSTANT_CASE.\n */\nexport type TagToCode<TTag extends string> = ToConstantCase<TTag>;\n\n/**\n * Creates a tagged error class that combines Effect's YieldableError with ORPCError.\n *\n * This allows you to create errors that:\n * - Can be yielded in Effect generators (`yield* myError`)\n * - Have all ORPCError properties (code, status, data, defined)\n * - Can be converted to a plain ORPCError for oRPC handlers\n *\n * The returned factory function takes:\n * - `tag` - The unique tag for this error type (used for discriminated unions)\n * - `codeOrOptions` - Optional ORPC error code or options. If omitted, code defaults to CONSTANT_CASE of tag\n * - `defaultOptions` - Optional default options for status and message (when code is provided)\n *\n * @example\n * ```ts\n * import { ORPCTaggedError } from '@orpc/effect'\n * import { Effect } from 'effect'\n *\n * // Define a custom error (code defaults to 'USER_NOT_FOUND_ERROR')\n * class UserNotFoundError extends ORPCTaggedError<UserNotFoundError>()('UserNotFoundError') {}\n *\n * // With explicit code\n * class NotFoundError extends ORPCTaggedError<NotFoundError>()('NotFoundError', 'NOT_FOUND') {}\n *\n * // Use in an Effect\n * const getUser = (id: string) => Effect.gen(function* () {\n * const user = yield* findUser(id)\n * if (!user) {\n * return yield* new UserNotFoundError({ data: { userId: id } })\n * }\n * return user\n * })\n *\n * // With custom data type\n * class ValidationError extends ORPCTaggedError<ValidationError, { fields: string[] }>()('ValidationError', 'BAD_REQUEST') {}\n *\n * // With options only (code defaults to 'VALIDATION_ERROR')\n * class ValidationError2 extends ORPCTaggedError<ValidationError2, { fields: string[] }>()(\n * 'ValidationError2',\n * { message: 'Validation failed' }\n * ) {}\n * ```\n */\nexport function ORPCTaggedError<\n TTag extends string,\n TSchema extends AnySchema = AnySchema,\n TCode extends ORPCErrorCode = ToConstantCase<TTag>,\n>(\n tag: TTag,\n props?: {\n schema?: TSchema;\n status?: number;\n message?: string;\n code?: TCode;\n },\n): ORPCTaggedErrorClass<TTag, TCode, TSchema> {\n const code: TCode = props?.code ?? (toConstantCase(tag) as any);\n class ORPCTaggedErrorBase\n extends Data.TaggedError(tag)\n implements ORPCTaggedErrorInstance<TTag, TCode, TSchema>\n {\n readonly status: number;\n readonly defined: boolean;\n readonly data: InferSchemaOutput<TSchema>;\n readonly code: TCode = code;\n readonly schema = props?.schema as TSchema;\n readonly [ORPCErrorSymbol]: ORPCError<TCode, InferSchemaOutput<TSchema>>;\n\n constructor(\n ...rest: MaybeOptionalOptions<\n ORPCTaggedErrorOptions<InferSchemaOutput<TSchema>>\n >\n ) {\n super();\n\n const opts = resolveMaybeOptionalOptions(rest);\n const status = opts.status ?? props?.status;\n\n if (status !== undefined && !isORPCErrorStatus(status)) {\n throw new globalThis.Error(\n \"[ORPCTaggedError] Invalid error status code.\",\n );\n }\n\n this.status = fallbackORPCErrorStatus(code, status);\n this.defined = opts.defined ?? true;\n this.data = opts.data as InferSchemaOutput<TSchema>;\n this.message = fallbackORPCErrorMessage(\n this.code,\n opts.message ?? props?.message,\n );\n this.cause = opts.cause;\n\n this[ORPCErrorSymbol] = new ORPCError<TCode, InferSchemaOutput<TSchema>>(\n this.code,\n {\n status: this.status,\n message: this.message,\n data: this.data,\n defined: this.defined,\n cause: this.cause,\n },\n );\n }\n\n /**\n * Converts this error to a plain ORPCError.\n * Useful when you need to return from an oRPC handler.\n */\n toORPCError(): ORPCError<TCode, InferSchemaOutput<TSchema>> {\n return this[ORPCErrorSymbol];\n }\n\n 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":";;;;;AAUA;AAAA,EACE,aAAAA;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,EACA,aAAAC;AAAA,OACK;AAgBP;AAAA,EACE,iBAAAC;AAAA,EACA;AAAA,EACA,sBAAAC;AAAA,EACA;AAAA,EACA,QAAAC;AAAA,OACK;AACP,SAAS,SAAAC,QAAO,QAAQ,MAAsB,kBAAkB;;;ACvChE;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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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","ORPCError","Cause","decorateMiddleware","addMiddleware","mergeMeta","mergeRoute","mergePrefix","lazy"]}
package/dist/node.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import {
2
- installFiberContextBridge
3
- } from "./chunk-VOWRLWZZ.js";
2
+ installServiceContextBridge
3
+ } from "./chunk-E5YLLTJI.js";
4
4
 
5
5
  // src/node.ts
6
- import { Effect } from "effect";
7
6
  import { AsyncLocalStorage } from "async_hooks";
8
- var fiberRefsStorage = new AsyncLocalStorage();
7
+ import { Effect } from "effect";
8
+ var servicesStorage = new AsyncLocalStorage();
9
9
  var bridge = {
10
- getCurrentFiberRefs: () => fiberRefsStorage.getStore()
10
+ getCurrentServices: () => servicesStorage.getStore()
11
11
  };
12
- installFiberContextBridge(bridge);
12
+ installServiceContextBridge(bridge);
13
13
  function withFiberContext(fn) {
14
14
  return Effect.flatMap(
15
- Effect.getFiberRefs,
16
- (fiberRefs) => Effect.promise(() => fiberRefsStorage.run(fiberRefs, fn))
15
+ Effect.services(),
16
+ (services) => Effect.promise(() => servicesStorage.run(services, fn))
17
17
  );
18
18
  }
19
19
  export {
package/dist/node.js.map CHANGED
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../src/node.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport type { ServiceMap } from \"effect\";\nimport { Effect } from \"effect\";\n\nimport {\n installServiceContextBridge,\n type ServiceContextBridge,\n} from \"./service-context-bridge\";\n\nconst servicesStorage = new AsyncLocalStorage<ServiceMap.ServiceMap<any>>();\n\nconst bridge: ServiceContextBridge = {\n getCurrentServices: () => servicesStorage.getStore(),\n};\n\ninstallServiceContextBridge(bridge);\n\nexport function withFiberContext<T, R = never>(\n fn: () => Promise<T>,\n): Effect.Effect<T, never, R> {\n return Effect.flatMap(Effect.services<R>(), (services) =>\n Effect.promise(() => servicesStorage.run(services, fn)),\n );\n}\n"],"mappings":";;;;;AAAA,SAAS,yBAAyB;AAGlC,SAAS,cAAc;AAOvB,IAAM,kBAAkB,IAAI,kBAA8C;AAE1E,IAAM,SAA+B;AAAA,EACnC,oBAAoB,MAAM,gBAAgB,SAAS;AACrD;AAEA,4BAA4B,MAAM;AAE3B,SAAS,iBACd,IAC4B;AAC5B,SAAO,OAAO;AAAA,IAAQ,OAAO,SAAY;AAAA,IAAG,CAAC,aAC3C,OAAO,QAAQ,MAAM,gBAAgB,IAAI,UAAU,EAAE,CAAC;AAAA,EACxD;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-orpc",
3
- "version": "0.1.1",
3
+ "version": "1.0.0-effect-v4.1",
4
4
  "keywords": [
5
5
  "effect",
6
6
  "orpc",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/bun": "latest",
50
- "effect": "^3.18.4",
50
+ "effect": "^4.0.0-beta.27",
51
51
  "oxfmt": "^0.21.0",
52
52
  "oxlint": "^1.36.0",
53
53
  "tsup": "^8.5.1",
@@ -59,7 +59,7 @@
59
59
  "@orpc/contract": ">=1.13.0",
60
60
  "@orpc/server": ">=1.13.0",
61
61
  "@orpc/shared": ">=1.13.0",
62
- "effect": ">=3.18.0",
62
+ "effect": ">=4.0.0-beta.27",
63
63
  "typescript": "^5"
64
64
  }
65
65
  }