effect-orpc 0.1.4 → 0.2.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.
@@ -4,12 +4,10 @@ import type {
4
4
  ErrorMap,
5
5
  ErrorMapItem,
6
6
  Meta,
7
- Route,
8
7
  Schema,
9
8
  } from "@orpc/contract";
10
9
  import type {
11
10
  Builder,
12
- BuilderConfig,
13
11
  BuilderDef,
14
12
  BuilderWithMiddlewares,
15
13
  Context,
@@ -22,7 +20,6 @@ import type {
22
20
  ProcedureHandlerOptions,
23
21
  RouterBuilder,
24
22
  } from "@orpc/server";
25
- import type { Promisable } from "@orpc/shared";
26
23
  import type { Effect, ManagedRuntime } from "effect";
27
24
  import type { YieldWrap } from "effect/Utils";
28
25
 
@@ -33,6 +30,19 @@ import type {
33
30
  ORPCTaggedErrorInstance,
34
31
  } from "../tagged-error";
35
32
 
33
+ type EffectBuilderDefBase<
34
+ TInputSchema extends AnySchema,
35
+ TOutputSchema extends AnySchema,
36
+ TEffectErrorMap extends EffectErrorMap,
37
+ TMeta extends Meta,
38
+ > = EnhanceRouterOptions<EffectErrorMapToErrorMap<TEffectErrorMap>> &
39
+ BuilderDef<
40
+ TInputSchema,
41
+ TOutputSchema,
42
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
43
+ TMeta
44
+ >;
45
+
36
46
  /**
37
47
  * Extended builder definition that includes the Effect ManagedRuntime.
38
48
  */
@@ -43,14 +53,12 @@ export interface EffectBuilderDef<
43
53
  TMeta extends Meta,
44
54
  TRequirementsProvided,
45
55
  TRuntimeError,
46
- > extends EnhanceRouterOptions<EffectErrorMapToErrorMap<TEffectErrorMap>> {
47
- inputValidationIndex: number;
48
- outputValidationIndex: number;
49
- config: BuilderConfig;
50
- meta: TMeta;
51
- route: Route;
52
- inputSchema?: TInputSchema;
53
- outputSchema?: TOutputSchema;
56
+ > extends EffectBuilderDefBase<
57
+ TInputSchema,
58
+ TOutputSchema,
59
+ TEffectErrorMap,
60
+ TMeta
61
+ > {
54
62
  runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;
55
63
  /**
56
64
  * Optional span configuration for Effect tracing.
@@ -62,21 +70,6 @@ export interface EffectBuilderDef<
62
70
  effectErrorMap: TEffectErrorMap;
63
71
  }
64
72
 
65
- export type NonEffectProcedureHandler<
66
- TCurrentContext extends Context,
67
- TInput,
68
- THandlerOutput,
69
- TEffectErrorMap extends EffectErrorMap,
70
- TMeta extends Meta,
71
- > = (
72
- opt: ProcedureHandlerOptions<
73
- TCurrentContext,
74
- TInput,
75
- EffectErrorConstructorMap<TEffectErrorMap>,
76
- TMeta
77
- >,
78
- ) => Promisable<THandlerOutput>;
79
-
80
73
  /**
81
74
  * Extended procedure definition that includes the Effect ManagedRuntime.
82
75
  */
@@ -429,4 +422,7 @@ export type InferBuilderMeta<T> =
429
422
  ? TMeta
430
423
  : Meta;
431
424
 
425
+ export type { EffectBuilderSurface } from "./effect-builder-surface";
426
+ export type { EffectDecoratedProcedureSurface } from "./effect-procedure-surface";
427
+
432
428
  export * from "./variants";
@@ -21,6 +21,7 @@ import type {
21
21
  MergedCurrentContext,
22
22
  MergedInitialContext,
23
23
  Middleware,
24
+ ProcedureHandler,
24
25
  Router,
25
26
  } from "@orpc/server";
26
27
 
@@ -201,12 +202,11 @@ export interface EffectBuilderWithMiddlewares<
201
202
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
202
203
  */
203
204
  "handler"<UFuncOutput>(
204
- handler: EffectProcedureHandler<
205
+ handler: ProcedureHandler<
205
206
  TCurrentContext,
206
207
  unknown,
207
208
  UFuncOutput,
208
- TEffectErrorMap,
209
- TRequirementsProvided,
209
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
210
210
  TMeta
211
211
  >,
212
212
  ): EffectDecoratedProcedure<
@@ -220,6 +220,13 @@ export interface EffectBuilderWithMiddlewares<
220
220
  TRuntimeError
221
221
  >;
222
222
 
223
+ /**
224
+ * Defines the handler of the procedure using an Effect.
225
+ * The Effect is executed using the ManagedRuntime provided during builder creation.
226
+ * The effect is automatically wrapped with `Effect.withSpan`.
227
+ *
228
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
229
+ */
223
230
  "effect"<UFuncOutput>(
224
231
  effectFn: EffectProcedureHandler<
225
232
  TCurrentContext,
@@ -240,6 +247,14 @@ export interface EffectBuilderWithMiddlewares<
240
247
  TRuntimeError
241
248
  >;
242
249
 
250
+ /**
251
+ * Adds a traceable span to the procedure for telemetry.
252
+ * The span name is used for Effect tracing via `Effect.withSpan`.
253
+ * Stack trace is captured at the call site for better error reporting.
254
+ *
255
+ * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
256
+ * @returns A traced procedure builder
257
+ */
243
258
  "traced"(
244
259
  spanName: string,
245
260
  ): EffectProcedureBuilderWithInput<
@@ -476,12 +491,11 @@ export interface EffectProcedureBuilder<
476
491
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
477
492
  */
478
493
  "handler"<UFuncOutput>(
479
- handler: EffectProcedureHandler<
494
+ handler: ProcedureHandler<
480
495
  TCurrentContext,
481
496
  unknown,
482
497
  UFuncOutput,
483
- TEffectErrorMap,
484
- TRequirementsProvided,
498
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
485
499
  TMeta
486
500
  >,
487
501
  ): EffectDecoratedProcedure<
@@ -495,6 +509,13 @@ export interface EffectProcedureBuilder<
495
509
  TRuntimeError
496
510
  >;
497
511
 
512
+ /**
513
+ * Defines the handler of the procedure using an Effect.
514
+ * The Effect is executed using the ManagedRuntime provided during builder creation.
515
+ * The effect is automatically wrapped with `Effect.withSpan`.
516
+ *
517
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
518
+ */
498
519
  "effect"<UFuncOutput>(
499
520
  effectFn: EffectProcedureHandler<
500
521
  TCurrentContext,
@@ -514,6 +535,27 @@ export interface EffectProcedureBuilder<
514
535
  TRequirementsProvided,
515
536
  TRuntimeError
516
537
  >;
538
+
539
+ /**
540
+ * Adds a traceable span to the procedure for telemetry.
541
+ * The span name is used for Effect tracing via `Effect.withSpan`.
542
+ * Stack trace is captured at the call site for better error reporting.
543
+ *
544
+ * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
545
+ * @returns A traced procedure builder
546
+ */
547
+ "traced"(
548
+ spanName: string,
549
+ ): EffectProcedureBuilder<
550
+ TInitialContext,
551
+ TCurrentContext,
552
+ TInputSchema,
553
+ TOutputSchema,
554
+ TEffectErrorMap,
555
+ TMeta,
556
+ TRequirementsProvided,
557
+ TRuntimeError
558
+ >;
517
559
  }
518
560
 
519
561
  export interface EffectProcedureBuilderWithInput<
@@ -694,12 +736,11 @@ export interface EffectProcedureBuilderWithInput<
694
736
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
695
737
  */
696
738
  "handler"<UFuncOutput>(
697
- handler: EffectProcedureHandler<
739
+ handler: ProcedureHandler<
698
740
  TCurrentContext,
699
741
  InferSchemaOutput<TInputSchema>,
700
742
  UFuncOutput,
701
- TEffectErrorMap,
702
- TRequirementsProvided,
743
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
703
744
  TMeta
704
745
  >,
705
746
  ): EffectDecoratedProcedure<
@@ -713,6 +754,13 @@ export interface EffectProcedureBuilderWithInput<
713
754
  TRuntimeError
714
755
  >;
715
756
 
757
+ /**
758
+ * Defines the handler of the procedure using an Effect.
759
+ * The Effect is executed using the ManagedRuntime provided during builder creation.
760
+ * The effect is automatically wrapped with `Effect.withSpan`.
761
+ *
762
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
763
+ */
716
764
  "effect"<UFuncOutput>(
717
765
  effectFn: EffectProcedureHandler<
718
766
  TCurrentContext,
@@ -733,6 +781,14 @@ export interface EffectProcedureBuilderWithInput<
733
781
  TRuntimeError
734
782
  >;
735
783
 
784
+ /**
785
+ * Adds a traceable span to the procedure for telemetry.
786
+ * The span name is used for Effect tracing via `Effect.withSpan`.
787
+ * Stack trace is captured at the call site for better error reporting.
788
+ *
789
+ * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
790
+ * @returns A traced procedure builder
791
+ */
736
792
  "traced"(
737
793
  spanName: string,
738
794
  ): EffectProcedureBuilderWithInput<
@@ -791,7 +847,7 @@ export interface EffectProcedureBuilderWithOutput<
791
847
  TCurrentContext,
792
848
  TInputSchema,
793
849
  TOutputSchema,
794
- TEffectErrorMap,
850
+ MergedEffectErrorMap<TEffectErrorMap, U>,
795
851
  TMeta,
796
852
  TRequirementsProvided,
797
853
  TRuntimeError
@@ -891,12 +947,11 @@ export interface EffectProcedureBuilderWithOutput<
891
947
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
892
948
  */
893
949
  "handler"(
894
- handler: EffectProcedureHandler<
950
+ handler: ProcedureHandler<
895
951
  TCurrentContext,
896
952
  unknown,
897
953
  InferSchemaInput<TOutputSchema>,
898
- TEffectErrorMap,
899
- TRequirementsProvided,
954
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
900
955
  TMeta
901
956
  >,
902
957
  ): EffectDecoratedProcedure<
@@ -910,6 +965,13 @@ export interface EffectProcedureBuilderWithOutput<
910
965
  TRuntimeError
911
966
  >;
912
967
 
968
+ /**
969
+ * Defines the handler of the procedure using an Effect.
970
+ * The Effect is executed using the ManagedRuntime provided during builder creation.
971
+ * The effect is automatically wrapped with `Effect.withSpan`.
972
+ *
973
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
974
+ */
913
975
  "effect"(
914
976
  effectFn: EffectProcedureHandler<
915
977
  TCurrentContext,
@@ -930,6 +992,14 @@ export interface EffectProcedureBuilderWithOutput<
930
992
  TRuntimeError
931
993
  >;
932
994
 
995
+ /**
996
+ * Adds a traceable span to the procedure for telemetry.
997
+ * The span name is used for Effect tracing via `Effect.withSpan`.
998
+ * Stack trace is captured at the call site for better error reporting.
999
+ *
1000
+ * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
1001
+ * @returns A traced procedure builder
1002
+ */
933
1003
  "traced"(
934
1004
  spanName: string,
935
1005
  ): EffectProcedureBuilderWithInput<
@@ -1104,12 +1174,11 @@ export interface EffectProcedureBuilderWithInputOutput<
1104
1174
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
1105
1175
  */
1106
1176
  "handler"(
1107
- handler: EffectProcedureHandler<
1177
+ handler: ProcedureHandler<
1108
1178
  TCurrentContext,
1109
1179
  InferSchemaOutput<TInputSchema>,
1110
1180
  InferSchemaInput<TOutputSchema>,
1111
- TEffectErrorMap,
1112
- TRequirementsProvided,
1181
+ EffectErrorMapToErrorMap<TEffectErrorMap>,
1113
1182
  TMeta
1114
1183
  >,
1115
1184
  ): EffectDecoratedProcedure<
@@ -1123,6 +1192,13 @@ export interface EffectProcedureBuilderWithInputOutput<
1123
1192
  TRuntimeError
1124
1193
  >;
1125
1194
 
1195
+ /**
1196
+ * Defines the handler of the procedure using an Effect.
1197
+ * The Effect is executed using the ManagedRuntime provided during builder creation.
1198
+ * The effect is automatically wrapped with `Effect.withSpan`.
1199
+ *
1200
+ * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
1201
+ */
1126
1202
  "effect"(
1127
1203
  effectFn: EffectProcedureHandler<
1128
1204
  TCurrentContext,
@@ -1143,6 +1219,14 @@ export interface EffectProcedureBuilderWithInputOutput<
1143
1219
  TRuntimeError
1144
1220
  >;
1145
1221
 
1222
+ /**
1223
+ * Adds a traceable span to the procedure for telemetry.
1224
+ * The span name is used for Effect tracing via `Effect.withSpan`.
1225
+ * Stack trace is captured at the call site for better error reporting.
1226
+ *
1227
+ * @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
1228
+ * @returns A traced procedure builder
1229
+ */
1146
1230
  "traced"(
1147
1231
  spanName: string,
1148
1232
  ): EffectProcedureBuilderWithInput<