effect-orpc 0.0.5 → 0.0.7

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.
@@ -1,7 +1,8 @@
1
- import type { ORPCErrorCode } from "@orpc/client";
2
1
  import type {
3
2
  AnySchema,
3
+ ContractRouter,
4
4
  ErrorMap,
5
+ HTTPPath,
5
6
  InferSchemaOutput,
6
7
  Meta,
7
8
  Route,
@@ -9,23 +10,26 @@ import type {
9
10
  } from "@orpc/contract";
10
11
  import type {
11
12
  AnyMiddleware,
13
+ BuilderConfig,
12
14
  BuilderDef,
13
15
  Context,
16
+ Lazy,
14
17
  MapInputMiddleware,
15
18
  MergedCurrentContext,
16
19
  MergedInitialContext,
17
20
  Middleware,
18
- ORPCErrorConstructorMap,
21
+ ProcedureHandler,
19
22
  ProcedureHandlerOptions,
23
+ Router,
20
24
  } from "@orpc/server";
21
25
  import type { IntersectPick } from "@orpc/shared";
22
26
  import type { ManagedRuntime } from "effect";
23
- import type { YieldWrap } from "effect/Utils";
24
27
 
25
28
  import {
26
- mergeErrorMap,
27
29
  mergeMeta,
30
+ mergePrefix,
28
31
  mergeRoute,
32
+ mergeTags,
29
33
  ORPCError,
30
34
  } from "@orpc/contract";
31
35
  import {
@@ -33,16 +37,32 @@ import {
33
37
  Builder,
34
38
  decorateMiddleware,
35
39
  fallbackConfig,
40
+ lazy,
36
41
  } from "@orpc/server";
37
42
  import { Cause, Effect, Exit } from "effect";
38
43
 
39
44
  import type {
40
45
  EffectErrorConstructorMap,
41
46
  EffectErrorMap,
42
- EffectErrorMapToUnion,
43
47
  MergedEffectErrorMap,
44
48
  } from "./tagged-error";
49
+ import type {
50
+ AnyBuilderLike,
51
+ EffectBuilderDef,
52
+ EffectErrorMapToErrorMap,
53
+ EffectProcedureBuilderWithInput,
54
+ EffectProcedureHandler,
55
+ EffectRouterBuilder,
56
+ EnhancedEffectRouter,
57
+ InferBuilderCurrentContext,
58
+ InferBuilderErrorMap,
59
+ InferBuilderInitialContext,
60
+ InferBuilderInputSchema,
61
+ InferBuilderMeta,
62
+ InferBuilderOutputSchema,
63
+ } from "./types";
45
64
 
65
+ import { enhanceEffectRouter } from "./effect-enhance-router";
46
66
  import { EffectDecoratedProcedure } from "./effect-procedure";
47
67
  import {
48
68
  createEffectErrorConstructorMap,
@@ -79,93 +99,6 @@ export function addSpanStackTrace(): () => string | undefined {
79
99
  };
80
100
  }
81
101
 
82
- /**
83
- * Configuration for Effect span tracing.
84
- */
85
- export interface EffectSpanConfig {
86
- /**
87
- * The name of the span for telemetry.
88
- */
89
- name: string;
90
- /**
91
- * Function to lazily capture the stack trace at definition time.
92
- */
93
- captureStackTrace: () => string | undefined;
94
- }
95
-
96
- /**
97
- * Options passed to the Effect procedure handler.
98
- */
99
- export interface EffectProcedureHandlerOptions<
100
- TCurrentContext extends Context,
101
- TInput,
102
- TEffectErrorMap extends EffectErrorMap,
103
- TMeta extends Meta,
104
- > extends Omit<
105
- ProcedureHandlerOptions<
106
- TCurrentContext,
107
- TInput,
108
- ORPCErrorConstructorMap<any>,
109
- TMeta
110
- >,
111
- "errors"
112
- > {
113
- errors: EffectErrorConstructorMap<TEffectErrorMap>;
114
- }
115
-
116
- /**
117
- * Handler type for Effect procedures.
118
- * The handler receives procedure options and returns an Effect.
119
- */
120
- export type EffectProcedureHandler<
121
- TCurrentContext extends Context,
122
- TInput,
123
- THandlerOutput,
124
- TEffectErrorMap extends EffectErrorMap,
125
- TRequirementsProvided,
126
- TMeta extends Meta,
127
- > = (
128
- opt: EffectProcedureHandlerOptions<
129
- TCurrentContext,
130
- TInput,
131
- TEffectErrorMap,
132
- TMeta
133
- >,
134
- ) => Generator<
135
- YieldWrap<
136
- Effect.Effect<
137
- any,
138
- | EffectErrorMapToUnion<TEffectErrorMap>
139
- | ORPCError<ORPCErrorCode, unknown>,
140
- TRequirementsProvided
141
- >
142
- >,
143
- THandlerOutput,
144
- never
145
- >;
146
-
147
- /**
148
- * Extended builder definition that includes the Effect ManagedRuntime.
149
- */
150
- export interface EffectBuilderDef<
151
- TInputSchema extends AnySchema,
152
- TOutputSchema extends AnySchema,
153
- TEffectErrorMap extends EffectErrorMap,
154
- TMeta extends Meta,
155
- TRequirementsProvided,
156
- TRuntimeError,
157
- > extends BuilderDef<TInputSchema, TOutputSchema, ErrorMap, TMeta> {
158
- runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;
159
- /**
160
- * Optional span configuration for Effect tracing.
161
- */
162
- spanConfig?: EffectSpanConfig;
163
- /**
164
- * Effect-extended error map that supports both traditional errors and tagged errors.
165
- */
166
- effectErrorMap: TEffectErrorMap;
167
- }
168
-
169
102
  /**
170
103
  * Effect-native procedure builder that wraps an oRPC Builder instance
171
104
  * and adds Effect-specific capabilities while preserving Effect error
@@ -181,7 +114,10 @@ export class EffectBuilder<
181
114
  TRequirementsProvided,
182
115
  TRuntimeError,
183
116
  > {
184
- "~orpc": EffectBuilderDef<
117
+ /**
118
+ * This property holds the defined options and the effect-specific properties.
119
+ */
120
+ declare "~effect": EffectBuilderDef<
185
121
  TInputSchema,
186
122
  TOutputSchema,
187
123
  TEffectErrorMap,
@@ -189,6 +125,12 @@ export class EffectBuilder<
189
125
  TRequirementsProvided,
190
126
  TRuntimeError
191
127
  >;
128
+ declare "~orpc": BuilderDef<
129
+ TInputSchema,
130
+ TOutputSchema,
131
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
132
+ TMeta
133
+ >;
192
134
 
193
135
  constructor(
194
136
  def: EffectBuilderDef<
@@ -200,7 +142,168 @@ export class EffectBuilder<
200
142
  TRuntimeError
201
143
  >,
202
144
  ) {
203
- this["~orpc"] = def;
145
+ const { runtime, spanConfig, effectErrorMap, ...orpcDef } = def;
146
+ this["~orpc"] = orpcDef;
147
+ this["~effect"] = { runtime, spanConfig, effectErrorMap, ...orpcDef };
148
+ }
149
+
150
+ /**
151
+ * Sets or overrides the config.
152
+ *
153
+ * @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs}
154
+ * @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
155
+ */
156
+ $config(
157
+ config: BuilderConfig,
158
+ ): EffectBuilder<
159
+ TInitialContext,
160
+ TCurrentContext,
161
+ TInputSchema,
162
+ TOutputSchema,
163
+ TEffectErrorMap,
164
+ TMeta,
165
+ TRequirementsProvided,
166
+ TRuntimeError
167
+ > {
168
+ const inputValidationCount =
169
+ this["~effect"].inputValidationIndex -
170
+ fallbackConfig(
171
+ "initialInputValidationIndex",
172
+ this["~effect"].config.initialInputValidationIndex,
173
+ );
174
+ const outputValidationCount =
175
+ this["~effect"].outputValidationIndex -
176
+ fallbackConfig(
177
+ "initialOutputValidationIndex",
178
+ this["~effect"].config.initialOutputValidationIndex,
179
+ );
180
+
181
+ return new EffectBuilder({
182
+ ...this["~effect"],
183
+ config,
184
+ dedupeLeadingMiddlewares: fallbackConfig(
185
+ "dedupeLeadingMiddlewares",
186
+ config.dedupeLeadingMiddlewares,
187
+ ),
188
+ inputValidationIndex:
189
+ fallbackConfig(
190
+ "initialInputValidationIndex",
191
+ config.initialInputValidationIndex,
192
+ ) + inputValidationCount,
193
+ outputValidationIndex:
194
+ fallbackConfig(
195
+ "initialOutputValidationIndex",
196
+ config.initialOutputValidationIndex,
197
+ ) + outputValidationCount,
198
+ });
199
+ }
200
+
201
+ /**
202
+ * Set or override the initial context.
203
+ *
204
+ * @see {@link https://orpc.dev/docs/context Context Docs}
205
+ */
206
+ $context<U extends Context>(): EffectBuilder<
207
+ U & Record<never, never>,
208
+ U,
209
+ TInputSchema,
210
+ TOutputSchema,
211
+ TEffectErrorMap,
212
+ TMeta,
213
+ TRequirementsProvided,
214
+ TRuntimeError
215
+ > {
216
+ /**
217
+ * We need `& Record<never, never>` to deal with `has no properties in common with type` error
218
+ */
219
+
220
+ return new EffectBuilder({
221
+ ...this["~effect"],
222
+ middlewares: [],
223
+ inputValidationIndex: fallbackConfig(
224
+ "initialInputValidationIndex",
225
+ this["~effect"].config.initialInputValidationIndex,
226
+ ),
227
+ outputValidationIndex: fallbackConfig(
228
+ "initialOutputValidationIndex",
229
+ this["~effect"].config.initialOutputValidationIndex,
230
+ ),
231
+ });
232
+ }
233
+
234
+ /**
235
+ * Sets or overrides the initial meta.
236
+ *
237
+ * @see {@link https://orpc.dev/docs/metadata Metadata Docs}
238
+ */
239
+ $meta<U extends Meta>(
240
+ initialMeta: U,
241
+ ): EffectBuilder<
242
+ TInitialContext,
243
+ TCurrentContext,
244
+ TInputSchema,
245
+ TOutputSchema,
246
+ TEffectErrorMap,
247
+ U & Record<never, never>,
248
+ TRequirementsProvided,
249
+ TRuntimeError
250
+ > {
251
+ /**
252
+ * We need `& Record<never, never>` to deal with `has no properties in common with type` error
253
+ */
254
+
255
+ return new EffectBuilder({
256
+ ...this["~effect"],
257
+ meta: initialMeta,
258
+ });
259
+ }
260
+
261
+ /**
262
+ * Sets or overrides the initial route.
263
+ * This option is typically relevant when integrating with OpenAPI.
264
+ *
265
+ * @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
266
+ * @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
267
+ */
268
+ $route(
269
+ initialRoute: Route,
270
+ ): EffectBuilder<
271
+ TInitialContext,
272
+ TCurrentContext,
273
+ TInputSchema,
274
+ TOutputSchema,
275
+ TEffectErrorMap,
276
+ TMeta,
277
+ TRequirementsProvided,
278
+ TRuntimeError
279
+ > {
280
+ return new EffectBuilder({
281
+ ...this["~effect"],
282
+ route: initialRoute,
283
+ });
284
+ }
285
+
286
+ /**
287
+ * Sets or overrides the initial input schema.
288
+ *
289
+ * @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
290
+ */
291
+ $input<U extends AnySchema>(
292
+ initialInputSchema?: U,
293
+ ): EffectBuilder<
294
+ TInitialContext,
295
+ TCurrentContext,
296
+ U,
297
+ TOutputSchema,
298
+ TEffectErrorMap,
299
+ TMeta,
300
+ TRequirementsProvided,
301
+ TRuntimeError
302
+ > {
303
+ return new EffectBuilder({
304
+ ...this["~effect"],
305
+ inputSchema: initialInputSchema,
306
+ });
204
307
  }
205
308
 
206
309
  /**
@@ -236,16 +339,14 @@ export class EffectBuilder<
236
339
  TRequirementsProvided,
237
340
  TRuntimeError
238
341
  > {
342
+ const newEffectErrorMap: MergedEffectErrorMap<TEffectErrorMap, U> = {
343
+ ...this["~effect"].effectErrorMap,
344
+ ...errors,
345
+ };
239
346
  return new EffectBuilder({
240
- ...this["~orpc"],
241
- errorMap: mergeErrorMap(
242
- this["~orpc"].errorMap,
243
- effectErrorMapToErrorMap(errors),
244
- ),
245
- effectErrorMap: {
246
- ...this["~orpc"].effectErrorMap,
247
- ...errors,
248
- },
347
+ ...this["~effect"],
348
+ errorMap: effectErrorMapToErrorMap(newEffectErrorMap),
349
+ effectErrorMap: newEffectErrorMap,
249
350
  });
250
351
  }
251
352
 
@@ -263,9 +364,9 @@ export class EffectBuilder<
263
364
  middleware: Middleware<
264
365
  UInContext | TCurrentContext,
265
366
  UOutContext,
367
+ InferSchemaOutput<TInputSchema>,
266
368
  unknown,
267
- unknown,
268
- ORPCErrorConstructorMap<ErrorMap>,
369
+ EffectErrorConstructorMap<TEffectErrorMap>,
269
370
  TMeta
270
371
  >,
271
372
  ): EffectBuilder<
@@ -288,8 +389,8 @@ export class EffectBuilder<
288
389
  : middleware;
289
390
 
290
391
  return new EffectBuilder({
291
- ...this["~orpc"],
292
- middlewares: addMiddleware(this["~orpc"].middlewares, mapped),
392
+ ...this["~effect"],
393
+ middlewares: addMiddleware(this["~effect"].middlewares, mapped),
293
394
  });
294
395
  }
295
396
 
@@ -312,8 +413,8 @@ export class EffectBuilder<
312
413
  TRuntimeError
313
414
  > {
314
415
  return new EffectBuilder({
315
- ...this["~orpc"],
316
- meta: mergeMeta(this["~orpc"].meta, meta),
416
+ ...this["~effect"],
417
+ meta: mergeMeta(this["~effect"].meta, meta),
317
418
  });
318
419
  }
319
420
 
@@ -338,8 +439,8 @@ export class EffectBuilder<
338
439
  TRuntimeError
339
440
  > {
340
441
  return new EffectBuilder({
341
- ...this["~orpc"],
342
- route: mergeRoute(this["~orpc"].route, route),
442
+ ...this["~effect"],
443
+ route: mergeRoute(this["~effect"].route, route),
343
444
  });
344
445
  }
345
446
 
@@ -350,7 +451,7 @@ export class EffectBuilder<
350
451
  */
351
452
  input<USchema extends AnySchema>(
352
453
  schema: USchema,
353
- ): EffectBuilder<
454
+ ): EffectProcedureBuilderWithInput<
354
455
  TInitialContext,
355
456
  TCurrentContext,
356
457
  USchema,
@@ -361,14 +462,19 @@ export class EffectBuilder<
361
462
  TRuntimeError
362
463
  > {
363
464
  return new EffectBuilder({
364
- ...this["~orpc"],
465
+ ...this["~effect"],
365
466
  inputSchema: schema,
366
467
  inputValidationIndex:
367
468
  fallbackConfig(
368
469
  "initialInputValidationIndex",
369
- this["~orpc"].config.initialInputValidationIndex,
370
- ) + this["~orpc"].middlewares.length,
371
- });
470
+ this["~effect"].config.initialInputValidationIndex,
471
+ ) + this["~effect"].middlewares.length,
472
+ // we cast to any because EffectProcedureBuilderWithInput is expecting
473
+ // use() input type to be defined, and EffectBuilder types its use() input
474
+ // to unknown to allow any middleware to be passed
475
+ // ---
476
+ // note: the original implentation of the builder also uses any for the same reason
477
+ }) as any;
372
478
  }
373
479
 
374
480
  /**
@@ -389,13 +495,13 @@ export class EffectBuilder<
389
495
  TRuntimeError
390
496
  > {
391
497
  return new EffectBuilder({
392
- ...this["~orpc"],
498
+ ...this["~effect"],
393
499
  outputSchema: schema,
394
500
  outputValidationIndex:
395
501
  fallbackConfig(
396
502
  "initialOutputValidationIndex",
397
- this["~orpc"].config.initialOutputValidationIndex,
398
- ) + this["~orpc"].middlewares.length,
503
+ this["~effect"].config.initialOutputValidationIndex,
504
+ ) + this["~effect"].middlewares.length,
399
505
  });
400
506
  }
401
507
 
@@ -431,7 +537,7 @@ export class EffectBuilder<
431
537
  TRuntimeError
432
538
  > {
433
539
  return new EffectBuilder({
434
- ...this["~orpc"],
540
+ ...this["~effect"],
435
541
  spanConfig: {
436
542
  name: spanName,
437
543
  captureStackTrace: addSpanStackTrace(),
@@ -439,6 +545,30 @@ export class EffectBuilder<
439
545
  });
440
546
  }
441
547
 
548
+ handler<UFuncOutput>(
549
+ handler: ProcedureHandler<
550
+ TCurrentContext,
551
+ InferSchemaOutput<TInputSchema>,
552
+ UFuncOutput,
553
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
554
+ TMeta
555
+ >,
556
+ ): EffectDecoratedProcedure<
557
+ TInitialContext,
558
+ TCurrentContext,
559
+ TInputSchema,
560
+ Schema<UFuncOutput, UFuncOutput>,
561
+ TEffectErrorMap,
562
+ TMeta,
563
+ TRequirementsProvided,
564
+ TRuntimeError
565
+ > {
566
+ return new EffectDecoratedProcedure({
567
+ ...this["~effect"],
568
+ handler,
569
+ });
570
+ }
571
+
442
572
  /**
443
573
  * Defines the handler of the procedure using an Effect.
444
574
  * The Effect is executed using the ManagedRuntime provided during builder creation.
@@ -449,7 +579,7 @@ export class EffectBuilder<
449
579
  effect<UFuncOutput>(
450
580
  effectFn: EffectProcedureHandler<
451
581
  TCurrentContext,
452
- InferSchemaOutput<TInputSchema>,
582
+ TInputSchema,
453
583
  UFuncOutput,
454
584
  TEffectErrorMap,
455
585
  TRequirementsProvided,
@@ -465,16 +595,16 @@ export class EffectBuilder<
465
595
  TRequirementsProvided,
466
596
  TRuntimeError
467
597
  > {
468
- const { runtime, spanConfig } = this["~orpc"];
598
+ const { runtime, spanConfig } = this["~effect"];
469
599
  // Capture stack trace at definition time for default tracing
470
600
  const defaultCaptureStackTrace = addSpanStackTrace();
471
601
  return new EffectDecoratedProcedure({
472
- ...this["~orpc"],
602
+ ...this["~effect"],
473
603
  handler: async (opts) => {
474
- const effectOpts: EffectProcedureHandlerOptions<
604
+ const effectOpts: ProcedureHandlerOptions<
475
605
  TCurrentContext,
476
606
  InferSchemaOutput<TInputSchema>,
477
- TEffectErrorMap,
607
+ EffectErrorConstructorMap<TEffectErrorMap>,
478
608
  TMeta
479
609
  > = {
480
610
  context: opts.context,
@@ -483,7 +613,9 @@ export class EffectBuilder<
483
613
  procedure: opts.procedure,
484
614
  signal: opts.signal,
485
615
  lastEventId: opts.lastEventId,
486
- errors: createEffectErrorConstructorMap(this["~orpc"].effectErrorMap),
616
+ errors: createEffectErrorConstructorMap(
617
+ this["~effect"].effectErrorMap,
618
+ ),
487
619
  };
488
620
  const spanName = spanConfig?.name ?? opts.path.join(".");
489
621
  const captureStackTrace =
@@ -535,19 +667,89 @@ export class EffectBuilder<
535
667
  },
536
668
  });
537
669
  }
538
- }
539
670
 
540
- /**
541
- * Any oRPC builder-like object that has the `~orpc` definition property.
542
- * This includes Builder, BuilderWithMiddlewares, ProcedureBuilder, etc.
543
- */
544
- export interface AnyBuilderLike<
545
- TInputSchema extends AnySchema,
546
- TOutputSchema extends AnySchema,
547
- TErrorMap extends ErrorMap,
548
- TMeta extends Meta,
549
- > {
550
- "~orpc": BuilderDef<TInputSchema, TOutputSchema, TErrorMap, TMeta>;
671
+ /**
672
+ * Prefixes all procedures in the router.
673
+ * The provided prefix is post-appended to any existing router prefix.
674
+ *
675
+ * @note This option does not affect procedures that do not define a path in their route definition.
676
+ *
677
+ * @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
678
+ */
679
+ prefix(
680
+ prefix: HTTPPath,
681
+ ): EffectRouterBuilder<
682
+ TInitialContext,
683
+ TCurrentContext,
684
+ TEffectErrorMap,
685
+ TMeta,
686
+ TRequirementsProvided,
687
+ TRuntimeError
688
+ > {
689
+ return new EffectBuilder({
690
+ ...this["~effect"],
691
+ prefix: mergePrefix(this["~effect"].prefix, prefix),
692
+ }) as any;
693
+ }
694
+
695
+ /**
696
+ * Adds tags to all procedures in the router.
697
+ * This helpful when you want to group procedures together in the OpenAPI specification.
698
+ *
699
+ * @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
700
+ */
701
+ tag(
702
+ ...tags: string[]
703
+ ): EffectRouterBuilder<
704
+ TInitialContext,
705
+ TCurrentContext,
706
+ TEffectErrorMap,
707
+ TMeta,
708
+ TRequirementsProvided,
709
+ TRuntimeError
710
+ > {
711
+ return new EffectBuilder({
712
+ ...this["~effect"],
713
+ tags: mergeTags(this["~effect"].tags, tags),
714
+ }) as any;
715
+ }
716
+
717
+ /**
718
+ * Applies all of the previously defined options to the specified router.
719
+ *
720
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
721
+ */
722
+ router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
723
+ router: U,
724
+ ): EnhancedEffectRouter<
725
+ U,
726
+ TInitialContext,
727
+ TCurrentContext,
728
+ TEffectErrorMap
729
+ > {
730
+ return enhanceEffectRouter(router, {
731
+ ...this["~effect"],
732
+ }) as any; // Type instantiation is excessively deep and possibly infinite
733
+ }
734
+
735
+ /**
736
+ * Create a lazy router
737
+ * And applies all of the previously defined options to the specified router.
738
+ *
739
+ * @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
740
+ */
741
+ lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
742
+ loader: () => Promise<{ default: U }>,
743
+ ): EnhancedEffectRouter<
744
+ Lazy<U>,
745
+ TInitialContext,
746
+ TCurrentContext,
747
+ TEffectErrorMap
748
+ > {
749
+ return enhanceEffectRouter(lazy(loader), {
750
+ ...this["~effect"],
751
+ }) as any; // Type instantiation is excessively deep and possibly infinite
752
+ }
551
753
  }
552
754
 
553
755
  /**
@@ -613,6 +815,12 @@ export function makeEffectORPC<TRequirementsProvided, TRuntimeError>(
613
815
  * ```
614
816
  */
615
817
  export function makeEffectORPC<
818
+ TBuilder extends AnyBuilderLike<
819
+ TInputSchema,
820
+ TOutputSchema,
821
+ TErrorMap,
822
+ TMeta
823
+ >,
616
824
  TInputSchema extends AnySchema,
617
825
  TOutputSchema extends AnySchema,
618
826
  TErrorMap extends ErrorMap,
@@ -621,65 +829,46 @@ export function makeEffectORPC<
621
829
  TRuntimeError,
622
830
  >(
623
831
  runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,
624
- builder: AnyBuilderLike<TInputSchema, TOutputSchema, TErrorMap, TMeta>,
832
+ builder: TBuilder,
625
833
  ): EffectBuilder<
626
- Context,
627
- Context,
628
- TInputSchema,
629
- TOutputSchema,
630
- TErrorMap,
631
- TMeta,
834
+ InferBuilderInitialContext<TBuilder>,
835
+ InferBuilderCurrentContext<TBuilder>,
836
+ InferBuilderInputSchema<TBuilder>,
837
+ InferBuilderOutputSchema<TBuilder>,
838
+ InferBuilderErrorMap<TBuilder>,
839
+ InferBuilderMeta<TBuilder>,
632
840
  TRequirementsProvided,
633
841
  TRuntimeError
634
842
  >;
635
843
 
636
- export function makeEffectORPC<
637
- TInputSchema extends AnySchema,
638
- TOutputSchema extends AnySchema,
639
- TErrorMap extends ErrorMap,
640
- TMeta extends Meta,
641
- TRequirementsProvided,
642
- TRuntimeError,
643
- >(
844
+ export function makeEffectORPC<TRequirementsProvided, TRuntimeError>(
644
845
  runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>,
645
- builder?: AnyBuilderLike<TInputSchema, TOutputSchema, TErrorMap, TMeta>,
846
+ builder?: AnyBuilderLike,
646
847
  ): EffectBuilder<
647
- Context,
648
- Context,
649
- TInputSchema,
650
- TOutputSchema,
651
- TErrorMap,
652
- TMeta,
848
+ any,
849
+ any,
850
+ any,
851
+ any,
852
+ any,
853
+ any,
653
854
  TRequirementsProvided,
654
855
  TRuntimeError
655
856
  > {
656
- const resolvedBuilder =
657
- builder ?? emptyBuilder<TInputSchema, TOutputSchema, TErrorMap, TMeta>();
857
+ const resolvedBuilder = builder ?? emptyBuilder();
658
858
  return new EffectBuilder({
659
859
  ...resolvedBuilder["~orpc"],
860
+ errorMap: effectErrorMapToErrorMap(resolvedBuilder["~orpc"].errorMap),
660
861
  effectErrorMap: resolvedBuilder["~orpc"].errorMap,
661
862
  runtime,
662
863
  });
663
864
  }
664
865
 
665
- function emptyBuilder<
666
- TInputSchema extends AnySchema,
667
- TOutputSchema extends AnySchema,
668
- TErrorMap extends ErrorMap,
669
- TMeta extends Meta,
670
- >() {
671
- return new Builder<
672
- Record<never, never>,
673
- Record<never, never>,
674
- TInputSchema,
675
- TOutputSchema,
676
- TErrorMap,
677
- TMeta
678
- >({
866
+ function emptyBuilder(): AnyBuilderLike {
867
+ return new Builder({
679
868
  config: {},
680
869
  route: {},
681
- meta: {} as TMeta,
682
- errorMap: {} as TErrorMap,
870
+ meta: {},
871
+ errorMap: {},
683
872
  inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
684
873
  outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
685
874
  middlewares: [],