effect-orpc 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -146
- package/dist/index.js +421 -133
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/contract.ts +15 -12
- package/src/effect-builder.ts +63 -40
- package/src/effect-enhance-router.ts +3 -3
- package/src/effect-procedure.ts +38 -14
- package/src/effect-runtime.ts +647 -115
- package/src/extension/state.ts +3 -5
- package/src/index.ts +1 -0
- package/src/runtime-source.ts +70 -12
- package/src/tagged-error.ts +1 -1
- package/src/tests/contract.test.ts +5 -8
- package/src/tests/effect-builder.proxy.test.ts +15 -17
- package/src/tests/effect-builder.test.ts +352 -161
- package/src/tests/effect-callback-shapes.test.ts +410 -0
- package/src/tests/effect-error-map.test.ts +12 -14
- package/src/tests/effect-procedure.test.ts +53 -11
- package/src/tests/parity-shared.ts +2 -2
- package/src/types/effect-builder-surface.ts +1 -1
- package/src/types/index.ts +76 -51
- package/src/types/variants.ts +5 -5
package/src/types/index.ts
CHANGED
|
@@ -24,15 +24,10 @@ import type {
|
|
|
24
24
|
RouterBuilder,
|
|
25
25
|
} from "@orpc/server";
|
|
26
26
|
import type { MaybeOptionalOptions } from "@orpc/shared";
|
|
27
|
-
import type {
|
|
28
|
-
Context as EffectContext,
|
|
29
|
-
Effect,
|
|
30
|
-
Layer,
|
|
31
|
-
ManagedRuntime,
|
|
32
|
-
Option,
|
|
33
|
-
} from "effect";
|
|
27
|
+
import type { Context as EffectContext, Effect, Layer, Option } from "effect";
|
|
34
28
|
import type { YieldWrap } from "effect/Utils";
|
|
35
29
|
|
|
30
|
+
import type { EffectRuntimeRunner } from "../runtime-source";
|
|
36
31
|
import type {
|
|
37
32
|
EffectErrorConstructorMap,
|
|
38
33
|
EffectErrorMap,
|
|
@@ -54,7 +49,7 @@ type EffectBuilderDefBase<
|
|
|
54
49
|
>;
|
|
55
50
|
|
|
56
51
|
/**
|
|
57
|
-
* Extended builder definition that includes
|
|
52
|
+
* Extended builder definition that includes Effect execution state.
|
|
58
53
|
*/
|
|
59
54
|
export interface EffectBuilderDef<
|
|
60
55
|
TInputSchema extends AnySchema,
|
|
@@ -69,7 +64,7 @@ export interface EffectBuilderDef<
|
|
|
69
64
|
TEffectErrorMap,
|
|
70
65
|
TMeta
|
|
71
66
|
> {
|
|
72
|
-
|
|
67
|
+
runner: EffectRuntimeRunner<TRequirementsProvided, TRuntimeError>;
|
|
73
68
|
/**
|
|
74
69
|
* Optional span configuration for Effect tracing.
|
|
75
70
|
*/
|
|
@@ -83,7 +78,7 @@ export interface EffectBuilderDef<
|
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
/**
|
|
86
|
-
* Extended procedure definition that includes
|
|
81
|
+
* Extended procedure definition that includes Effect execution state.
|
|
87
82
|
*/
|
|
88
83
|
export interface EffectProcedureDef<
|
|
89
84
|
TInitialContext extends Context,
|
|
@@ -102,7 +97,7 @@ export interface EffectProcedureDef<
|
|
|
102
97
|
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
103
98
|
TMeta
|
|
104
99
|
> {
|
|
105
|
-
|
|
100
|
+
runner: EffectRuntimeRunner<TRequirementsProvided, TRuntimeError>;
|
|
106
101
|
effectErrorMap: TEffectErrorMap;
|
|
107
102
|
effectSteps?: readonly EffectPipelineStep[];
|
|
108
103
|
effectHandler?: EffectProcedureHandlerConfig;
|
|
@@ -140,18 +135,17 @@ export type EffectProcedureHandler<
|
|
|
140
135
|
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
141
136
|
TMeta
|
|
142
137
|
>,
|
|
143
|
-
) =>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
| EffectErrorMapToUnion<TEffectErrorMap>
|
|
148
|
-
| ORPCError<ORPCErrorCode, unknown>,
|
|
138
|
+
) =>
|
|
139
|
+
| Effect.Effect<
|
|
140
|
+
THandlerOutput,
|
|
141
|
+
EffectOperationError<TEffectErrorMap>,
|
|
149
142
|
TRequirementsProvided
|
|
150
143
|
>
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
144
|
+
| EffectCallbackGenerator<
|
|
145
|
+
THandlerOutput,
|
|
146
|
+
TEffectErrorMap,
|
|
147
|
+
TRequirementsProvided
|
|
148
|
+
>;
|
|
155
149
|
|
|
156
150
|
export interface EffectProcedureHandlerConfig {
|
|
157
151
|
readonly effectFn: EffectProcedureHandler<any, any, any, any, any, any>;
|
|
@@ -162,6 +156,26 @@ export interface EffectProcedureHandlerConfig {
|
|
|
162
156
|
type EffectTagService<T extends EffectContext.Tag<any, any>> =
|
|
163
157
|
T extends EffectContext.Tag<any, infer S> ? S : never;
|
|
164
158
|
|
|
159
|
+
type EffectOperationError<TEffectErrorMap extends EffectErrorMap> =
|
|
160
|
+
| EffectErrorMapToUnion<TEffectErrorMap>
|
|
161
|
+
| ORPCError<ORPCErrorCode, unknown>;
|
|
162
|
+
|
|
163
|
+
type EffectCallbackGenerator<
|
|
164
|
+
TReturn,
|
|
165
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
166
|
+
TRequirementsProvided,
|
|
167
|
+
> = Generator<
|
|
168
|
+
YieldWrap<
|
|
169
|
+
Effect.Effect<
|
|
170
|
+
unknown,
|
|
171
|
+
EffectOperationError<TEffectErrorMap>,
|
|
172
|
+
TRequirementsProvided
|
|
173
|
+
>
|
|
174
|
+
>,
|
|
175
|
+
TReturn,
|
|
176
|
+
never
|
|
177
|
+
>;
|
|
178
|
+
|
|
165
179
|
export type EffectProvider<
|
|
166
180
|
TCurrentContext extends Context,
|
|
167
181
|
TInput,
|
|
@@ -176,11 +190,17 @@ export type EffectProvider<
|
|
|
176
190
|
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
177
191
|
TMeta
|
|
178
192
|
>,
|
|
179
|
-
) =>
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
) =>
|
|
194
|
+
| Effect.Effect<
|
|
195
|
+
EffectTagService<TTag>,
|
|
196
|
+
EffectOperationError<TEffectErrorMap>,
|
|
197
|
+
TRequirementsProvided
|
|
198
|
+
>
|
|
199
|
+
| EffectCallbackGenerator<
|
|
200
|
+
EffectTagService<TTag>,
|
|
201
|
+
TEffectErrorMap,
|
|
202
|
+
TRequirementsProvided
|
|
203
|
+
>;
|
|
184
204
|
|
|
185
205
|
export type EffectOptionalProvider<
|
|
186
206
|
TCurrentContext extends Context,
|
|
@@ -196,11 +216,17 @@ export type EffectOptionalProvider<
|
|
|
196
216
|
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
197
217
|
TMeta
|
|
198
218
|
>,
|
|
199
|
-
) =>
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
219
|
+
) =>
|
|
220
|
+
| Effect.Effect<
|
|
221
|
+
Option.Option<EffectTagService<TTag>>,
|
|
222
|
+
EffectOperationError<TEffectErrorMap>,
|
|
223
|
+
TRequirementsProvided
|
|
224
|
+
>
|
|
225
|
+
| EffectCallbackGenerator<
|
|
226
|
+
Option.Option<EffectTagService<TTag>>,
|
|
227
|
+
TEffectErrorMap,
|
|
228
|
+
TRequirementsProvided
|
|
229
|
+
>;
|
|
204
230
|
|
|
205
231
|
interface EffectMiddlewareNext<
|
|
206
232
|
TOutput,
|
|
@@ -332,17 +358,16 @@ export type EffectOrORPCMiddleware<
|
|
|
332
358
|
) =>
|
|
333
359
|
| MiddlewareResult<TOutContext, TOutput>
|
|
334
360
|
| PromiseLike<MiddlewareResult<TOutContext, TOutput>>
|
|
335
|
-
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
>
|
|
343
|
-
>,
|
|
361
|
+
| void
|
|
362
|
+
| Effect.Effect<
|
|
363
|
+
EffectMiddlewareResult<TOutContext, TOutput> | void,
|
|
364
|
+
EffectOperationError<TEffectErrorMap>,
|
|
365
|
+
TRequirementsProvided
|
|
366
|
+
>
|
|
367
|
+
| EffectCallbackGenerator<
|
|
344
368
|
EffectMiddlewareResult<TOutContext, TOutput> | void,
|
|
345
|
-
|
|
369
|
+
TEffectErrorMap,
|
|
370
|
+
TRequirementsProvided
|
|
346
371
|
>;
|
|
347
372
|
|
|
348
373
|
export type EffectMiddlewareOptions<
|
|
@@ -389,18 +414,18 @@ export type EffectMiddleware<
|
|
|
389
414
|
TEffectErrorMap,
|
|
390
415
|
TRequirementsProvided
|
|
391
416
|
>,
|
|
392
|
-
) =>
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
| EffectErrorMapToUnion<TEffectErrorMap>
|
|
397
|
-
| ORPCError<ORPCErrorCode, unknown>,
|
|
417
|
+
) =>
|
|
418
|
+
| Effect.Effect<
|
|
419
|
+
EffectMiddlewareResult<TOutContext, TOutput> | void,
|
|
420
|
+
EffectOperationError<TEffectErrorMap>,
|
|
398
421
|
TRequirementsProvided
|
|
399
422
|
>
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
423
|
+
| EffectCallbackGenerator<
|
|
424
|
+
EffectMiddlewareResult<TOutContext, TOutput> | void,
|
|
425
|
+
TEffectErrorMap,
|
|
426
|
+
TRequirementsProvided
|
|
427
|
+
>
|
|
428
|
+
| void;
|
|
404
429
|
|
|
405
430
|
type EffectProvideStep = {
|
|
406
431
|
readonly _tag: "provide";
|
package/src/types/variants.ts
CHANGED
|
@@ -294,7 +294,7 @@ export interface EffectBuilderWithMiddlewares<
|
|
|
294
294
|
|
|
295
295
|
/**
|
|
296
296
|
* Defines the handler of the procedure using an Effect.
|
|
297
|
-
* The Effect is executed using the
|
|
297
|
+
* The Effect is executed using the configured Effect runtime source.
|
|
298
298
|
* The effect is automatically wrapped with `Effect.withSpan`.
|
|
299
299
|
*
|
|
300
300
|
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
@@ -648,7 +648,7 @@ export interface EffectProcedureBuilder<
|
|
|
648
648
|
|
|
649
649
|
/**
|
|
650
650
|
* Defines the handler of the procedure using an Effect.
|
|
651
|
-
* The Effect is executed using the
|
|
651
|
+
* The Effect is executed using the configured Effect runtime source.
|
|
652
652
|
* The effect is automatically wrapped with `Effect.withSpan`.
|
|
653
653
|
*
|
|
654
654
|
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
@@ -958,7 +958,7 @@ export interface EffectProcedureBuilderWithInput<
|
|
|
958
958
|
|
|
959
959
|
/**
|
|
960
960
|
* Defines the handler of the procedure using an Effect.
|
|
961
|
-
* The Effect is executed using the
|
|
961
|
+
* The Effect is executed using the configured Effect runtime source.
|
|
962
962
|
* The effect is automatically wrapped with `Effect.withSpan`.
|
|
963
963
|
*
|
|
964
964
|
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
@@ -1234,7 +1234,7 @@ export interface EffectProcedureBuilderWithOutput<
|
|
|
1234
1234
|
|
|
1235
1235
|
/**
|
|
1236
1236
|
* Defines the handler of the procedure using an Effect.
|
|
1237
|
-
* The Effect is executed using the
|
|
1237
|
+
* The Effect is executed using the configured Effect runtime source.
|
|
1238
1238
|
* The effect is automatically wrapped with `Effect.withSpan`.
|
|
1239
1239
|
*
|
|
1240
1240
|
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
@@ -1526,7 +1526,7 @@ export interface EffectProcedureBuilderWithInputOutput<
|
|
|
1526
1526
|
|
|
1527
1527
|
/**
|
|
1528
1528
|
* Defines the handler of the procedure using an Effect.
|
|
1529
|
-
* The Effect is executed using the
|
|
1529
|
+
* The Effect is executed using the configured Effect runtime source.
|
|
1530
1530
|
* The effect is automatically wrapped with `Effect.withSpan`.
|
|
1531
1531
|
*
|
|
1532
1532
|
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|