effect-orpc 0.2.0 → 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.
- package/dist/index.js +472 -422
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/effect-builder.ts +348 -570
- package/src/effect-enhance-router.ts +20 -21
- package/src/effect-procedure.ts +274 -263
- package/src/extension/compose-surfaces.ts +15 -0
- package/src/extension/create-node-proxy.ts +270 -0
- package/src/extension/state.ts +108 -0
- package/src/index.ts +2 -0
- package/src/tests/effect-builder.proxy.test.ts +253 -0
- package/src/tests/parity.effect-builder.test.ts +17 -0
- package/src/types/effect-builder-surface.ts +441 -0
- package/src/types/effect-procedure-surface.ts +243 -0
- package/src/types/index.ts +22 -10
- package/src/types/variants.ts +75 -0
package/src/types/index.ts
CHANGED
|
@@ -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,
|
|
@@ -32,6 +30,19 @@ import type {
|
|
|
32
30
|
ORPCTaggedErrorInstance,
|
|
33
31
|
} from "../tagged-error";
|
|
34
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
|
+
|
|
35
46
|
/**
|
|
36
47
|
* Extended builder definition that includes the Effect ManagedRuntime.
|
|
37
48
|
*/
|
|
@@ -42,14 +53,12 @@ export interface EffectBuilderDef<
|
|
|
42
53
|
TMeta extends Meta,
|
|
43
54
|
TRequirementsProvided,
|
|
44
55
|
TRuntimeError,
|
|
45
|
-
> extends
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
inputSchema?: TInputSchema;
|
|
52
|
-
outputSchema?: TOutputSchema;
|
|
56
|
+
> extends EffectBuilderDefBase<
|
|
57
|
+
TInputSchema,
|
|
58
|
+
TOutputSchema,
|
|
59
|
+
TEffectErrorMap,
|
|
60
|
+
TMeta
|
|
61
|
+
> {
|
|
53
62
|
runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;
|
|
54
63
|
/**
|
|
55
64
|
* Optional span configuration for Effect tracing.
|
|
@@ -413,4 +422,7 @@ export type InferBuilderMeta<T> =
|
|
|
413
422
|
? TMeta
|
|
414
423
|
: Meta;
|
|
415
424
|
|
|
425
|
+
export type { EffectBuilderSurface } from "./effect-builder-surface";
|
|
426
|
+
export type { EffectDecoratedProcedureSurface } from "./effect-procedure-surface";
|
|
427
|
+
|
|
416
428
|
export * from "./variants";
|
package/src/types/variants.ts
CHANGED
|
@@ -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<
|
|
@@ -494,6 +509,13 @@ export interface EffectProcedureBuilder<
|
|
|
494
509
|
TRuntimeError
|
|
495
510
|
>;
|
|
496
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
|
+
*/
|
|
497
519
|
"effect"<UFuncOutput>(
|
|
498
520
|
effectFn: EffectProcedureHandler<
|
|
499
521
|
TCurrentContext,
|
|
@@ -514,6 +536,14 @@ export interface EffectProcedureBuilder<
|
|
|
514
536
|
TRuntimeError
|
|
515
537
|
>;
|
|
516
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
|
+
*/
|
|
517
547
|
"traced"(
|
|
518
548
|
spanName: string,
|
|
519
549
|
): EffectProcedureBuilder<
|
|
@@ -724,6 +754,13 @@ export interface EffectProcedureBuilderWithInput<
|
|
|
724
754
|
TRuntimeError
|
|
725
755
|
>;
|
|
726
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
|
+
*/
|
|
727
764
|
"effect"<UFuncOutput>(
|
|
728
765
|
effectFn: EffectProcedureHandler<
|
|
729
766
|
TCurrentContext,
|
|
@@ -744,6 +781,14 @@ export interface EffectProcedureBuilderWithInput<
|
|
|
744
781
|
TRuntimeError
|
|
745
782
|
>;
|
|
746
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
|
+
*/
|
|
747
792
|
"traced"(
|
|
748
793
|
spanName: string,
|
|
749
794
|
): EffectProcedureBuilderWithInput<
|
|
@@ -920,6 +965,13 @@ export interface EffectProcedureBuilderWithOutput<
|
|
|
920
965
|
TRuntimeError
|
|
921
966
|
>;
|
|
922
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
|
+
*/
|
|
923
975
|
"effect"(
|
|
924
976
|
effectFn: EffectProcedureHandler<
|
|
925
977
|
TCurrentContext,
|
|
@@ -940,6 +992,14 @@ export interface EffectProcedureBuilderWithOutput<
|
|
|
940
992
|
TRuntimeError
|
|
941
993
|
>;
|
|
942
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
|
+
*/
|
|
943
1003
|
"traced"(
|
|
944
1004
|
spanName: string,
|
|
945
1005
|
): EffectProcedureBuilderWithInput<
|
|
@@ -1132,6 +1192,13 @@ export interface EffectProcedureBuilderWithInputOutput<
|
|
|
1132
1192
|
TRuntimeError
|
|
1133
1193
|
>;
|
|
1134
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
|
+
*/
|
|
1135
1202
|
"effect"(
|
|
1136
1203
|
effectFn: EffectProcedureHandler<
|
|
1137
1204
|
TCurrentContext,
|
|
@@ -1152,6 +1219,14 @@ export interface EffectProcedureBuilderWithInputOutput<
|
|
|
1152
1219
|
TRuntimeError
|
|
1153
1220
|
>;
|
|
1154
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
|
+
*/
|
|
1155
1230
|
"traced"(
|
|
1156
1231
|
spanName: string,
|
|
1157
1232
|
): EffectProcedureBuilderWithInput<
|