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.
@@ -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 the Effect ManagedRuntime.
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
- runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;
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 the Effect ManagedRuntime.
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
- runtime: ManagedRuntime.ManagedRuntime<TRequirementsProvided, TRuntimeError>;
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
- ) => Generator<
144
- YieldWrap<
145
- Effect.Effect<
146
- any,
147
- | EffectErrorMapToUnion<TEffectErrorMap>
148
- | ORPCError<ORPCErrorCode, unknown>,
138
+ ) =>
139
+ | Effect.Effect<
140
+ THandlerOutput,
141
+ EffectOperationError<TEffectErrorMap>,
149
142
  TRequirementsProvided
150
143
  >
151
- >,
152
- THandlerOutput,
153
- never
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
- ) => Effect.Effect<
180
- EffectTagService<TTag>,
181
- EffectErrorMapToUnion<TEffectErrorMap> | ORPCError<ORPCErrorCode, unknown>,
182
- TRequirementsProvided
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
- ) => Effect.Effect<
200
- Option.Option<EffectTagService<TTag>>,
201
- EffectErrorMapToUnion<TEffectErrorMap> | ORPCError<ORPCErrorCode, unknown>,
202
- TRequirementsProvided
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
- | Generator<
336
- YieldWrap<
337
- Effect.Effect<
338
- unknown,
339
- | EffectErrorMapToUnion<TEffectErrorMap>
340
- | ORPCError<ORPCErrorCode, unknown>,
341
- TRequirementsProvided
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
- never
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
- ) => Generator<
393
- YieldWrap<
394
- Effect.Effect<
395
- unknown,
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
- EffectMiddlewareResult<TOutContext, TOutput> | void,
402
- never
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";
@@ -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 ManagedRuntime provided during builder creation.
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 ManagedRuntime provided during builder creation.
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 ManagedRuntime provided during builder creation.
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 ManagedRuntime provided during builder creation.
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 ManagedRuntime provided during builder creation.
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}