effect-orpc 0.2.2 → 0.4.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,11 +24,15 @@ import type {
24
24
  ProcedureHandler,
25
25
  Router,
26
26
  } from "@orpc/server";
27
+ import type { Context as EffectContext, Layer } from "effect";
27
28
 
28
29
  import type {
29
30
  EffectBuilderDef,
30
31
  EffectErrorMapToErrorMap,
32
+ EffectOptionalProvider,
33
+ EffectOrORPCMiddleware,
31
34
  EffectProcedureHandler,
35
+ EffectProvider,
32
36
  } from ".";
33
37
  import type {
34
38
  EffectDecoratedProcedure,
@@ -40,6 +44,9 @@ import type {
40
44
  MergedEffectErrorMap,
41
45
  } from "../tagged-error";
42
46
 
47
+ type EffectTagIdentifier<T extends EffectContext.Tag<any, any>> =
48
+ T extends EffectContext.Tag<infer I, any> ? I : never;
49
+
43
50
  export interface EffectBuilderWithMiddlewares<
44
51
  TInitialContext extends Context,
45
52
  TCurrentContext extends Context,
@@ -101,12 +108,13 @@ export interface EffectBuilderWithMiddlewares<
101
108
  UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
102
109
  UInContext extends Context = TCurrentContext,
103
110
  >(
104
- middleware: Middleware<
111
+ middleware: EffectOrORPCMiddleware<
105
112
  UInContext | TCurrentContext,
106
113
  UOutContext,
107
114
  unknown,
108
115
  unknown,
109
- EffectErrorConstructorMap<TEffectErrorMap>,
116
+ TEffectErrorMap,
117
+ TRequirementsProvided,
110
118
  TMeta
111
119
  >,
112
120
  ): EffectBuilderWithMiddlewares<
@@ -120,6 +128,70 @@ export interface EffectBuilderWithMiddlewares<
120
128
  TRuntimeError
121
129
  >;
122
130
 
131
+ /**
132
+ * Provides an Effect layer to downstream procedures.
133
+ */
134
+ "provide"<TLayerOut, TLayerError, TLayerIn extends TRequirementsProvided>(
135
+ layer: Layer.Layer<TLayerOut, TLayerError, TLayerIn>,
136
+ ): EffectBuilderWithMiddlewares<
137
+ TInitialContext,
138
+ TCurrentContext,
139
+ TInputSchema,
140
+ TOutputSchema,
141
+ TEffectErrorMap,
142
+ TMeta,
143
+ TRequirementsProvided | TLayerOut,
144
+ TRuntimeError | TLayerError
145
+ >;
146
+
147
+ /**
148
+ * Provides a request-scoped Effect service to downstream procedures.
149
+ */
150
+ "provide"<TTag extends EffectContext.Tag<any, any>>(
151
+ tag: TTag,
152
+ provider: EffectProvider<
153
+ TCurrentContext,
154
+ InferSchemaOutput<TInputSchema>,
155
+ TEffectErrorMap,
156
+ TRequirementsProvided,
157
+ TMeta,
158
+ TTag
159
+ >,
160
+ ): EffectBuilderWithMiddlewares<
161
+ TInitialContext,
162
+ TCurrentContext,
163
+ TInputSchema,
164
+ TOutputSchema,
165
+ TEffectErrorMap,
166
+ TMeta,
167
+ TRequirementsProvided | EffectTagIdentifier<TTag>,
168
+ TRuntimeError
169
+ >;
170
+
171
+ /**
172
+ * Optionally provides a request-scoped Effect service to downstream procedures.
173
+ */
174
+ "provideOptional"<TTag extends EffectContext.Tag<any, any>>(
175
+ tag: TTag,
176
+ provider: EffectOptionalProvider<
177
+ TCurrentContext,
178
+ InferSchemaOutput<TInputSchema>,
179
+ TEffectErrorMap,
180
+ TRequirementsProvided,
181
+ TMeta,
182
+ TTag
183
+ >,
184
+ ): EffectBuilderWithMiddlewares<
185
+ TInitialContext,
186
+ TCurrentContext,
187
+ TInputSchema,
188
+ TOutputSchema,
189
+ TEffectErrorMap,
190
+ TMeta,
191
+ TRequirementsProvided,
192
+ TRuntimeError
193
+ >;
194
+
123
195
  /**
124
196
  * Sets or updates the metadata.
125
197
  * The provided metadata is spared-merged with any existing metadata.
@@ -222,7 +294,7 @@ export interface EffectBuilderWithMiddlewares<
222
294
 
223
295
  /**
224
296
  * Defines the handler of the procedure using an Effect.
225
- * The Effect is executed using the ManagedRuntime provided during builder creation.
297
+ * The Effect is executed using the configured Effect runtime source.
226
298
  * The effect is automatically wrapped with `Effect.withSpan`.
227
299
  *
228
300
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
@@ -390,12 +462,13 @@ export interface EffectProcedureBuilder<
390
462
  UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
391
463
  UInContext extends Context = TCurrentContext,
392
464
  >(
393
- middleware: Middleware<
465
+ middleware: EffectOrORPCMiddleware<
394
466
  UInContext | TCurrentContext,
395
467
  UOutContext,
396
468
  unknown,
397
469
  unknown,
398
- EffectErrorConstructorMap<TEffectErrorMap>,
470
+ TEffectErrorMap,
471
+ TRequirementsProvided,
399
472
  TMeta
400
473
  >,
401
474
  ): EffectProcedureBuilder<
@@ -409,6 +482,70 @@ export interface EffectProcedureBuilder<
409
482
  TRuntimeError
410
483
  >;
411
484
 
485
+ /**
486
+ * Provides an Effect layer to downstream procedures.
487
+ */
488
+ "provide"<TLayerOut, TLayerError, TLayerIn extends TRequirementsProvided>(
489
+ layer: Layer.Layer<TLayerOut, TLayerError, TLayerIn>,
490
+ ): EffectProcedureBuilder<
491
+ TInitialContext,
492
+ TCurrentContext,
493
+ TInputSchema,
494
+ TOutputSchema,
495
+ TEffectErrorMap,
496
+ TMeta,
497
+ TRequirementsProvided | TLayerOut,
498
+ TRuntimeError | TLayerError
499
+ >;
500
+
501
+ /**
502
+ * Provides a request-scoped Effect service to downstream procedures.
503
+ */
504
+ "provide"<TTag extends EffectContext.Tag<any, any>>(
505
+ tag: TTag,
506
+ provider: EffectProvider<
507
+ TCurrentContext,
508
+ InferSchemaOutput<TInputSchema>,
509
+ TEffectErrorMap,
510
+ TRequirementsProvided,
511
+ TMeta,
512
+ TTag
513
+ >,
514
+ ): EffectProcedureBuilder<
515
+ TInitialContext,
516
+ TCurrentContext,
517
+ TInputSchema,
518
+ TOutputSchema,
519
+ TEffectErrorMap,
520
+ TMeta,
521
+ TRequirementsProvided | EffectTagIdentifier<TTag>,
522
+ TRuntimeError
523
+ >;
524
+
525
+ /**
526
+ * Optionally provides a request-scoped Effect service to downstream procedures.
527
+ */
528
+ "provideOptional"<TTag extends EffectContext.Tag<any, any>>(
529
+ tag: TTag,
530
+ provider: EffectOptionalProvider<
531
+ TCurrentContext,
532
+ InferSchemaOutput<TInputSchema>,
533
+ TEffectErrorMap,
534
+ TRequirementsProvided,
535
+ TMeta,
536
+ TTag
537
+ >,
538
+ ): EffectProcedureBuilder<
539
+ TInitialContext,
540
+ TCurrentContext,
541
+ TInputSchema,
542
+ TOutputSchema,
543
+ TEffectErrorMap,
544
+ TMeta,
545
+ TRequirementsProvided,
546
+ TRuntimeError
547
+ >;
548
+
412
549
  /**
413
550
  * Sets or updates the metadata.
414
551
  * The provided metadata is spared-merged with any existing metadata.
@@ -511,7 +648,7 @@ export interface EffectProcedureBuilder<
511
648
 
512
649
  /**
513
650
  * Defines the handler of the procedure using an Effect.
514
- * The Effect is executed using the ManagedRuntime provided during builder creation.
651
+ * The Effect is executed using the configured Effect runtime source.
515
652
  * The effect is automatically wrapped with `Effect.withSpan`.
516
653
  *
517
654
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
@@ -620,12 +757,13 @@ export interface EffectProcedureBuilderWithInput<
620
757
  UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
621
758
  UInContext extends Context = TCurrentContext,
622
759
  >(
623
- middleware: Middleware<
760
+ middleware: EffectOrORPCMiddleware<
624
761
  UInContext | TCurrentContext,
625
762
  UOutContext,
763
+ InferSchemaOutput<TInputSchema>,
626
764
  unknown,
627
- unknown,
628
- EffectErrorConstructorMap<TEffectErrorMap>,
765
+ TEffectErrorMap,
766
+ TRequirementsProvided,
629
767
  TMeta
630
768
  >,
631
769
  ): EffectProcedureBuilderWithInput<
@@ -672,6 +810,70 @@ export interface EffectProcedureBuilderWithInput<
672
810
  TRuntimeError
673
811
  >;
674
812
 
813
+ /**
814
+ * Provides an Effect layer to downstream procedures.
815
+ */
816
+ "provide"<TLayerOut, TLayerError, TLayerIn extends TRequirementsProvided>(
817
+ layer: Layer.Layer<TLayerOut, TLayerError, TLayerIn>,
818
+ ): EffectProcedureBuilderWithInput<
819
+ TInitialContext,
820
+ TCurrentContext,
821
+ TInputSchema,
822
+ TOutputSchema,
823
+ TEffectErrorMap,
824
+ TMeta,
825
+ TRequirementsProvided | TLayerOut,
826
+ TRuntimeError | TLayerError
827
+ >;
828
+
829
+ /**
830
+ * Provides a request-scoped Effect service to downstream procedures.
831
+ */
832
+ "provide"<TTag extends EffectContext.Tag<any, any>>(
833
+ tag: TTag,
834
+ provider: EffectProvider<
835
+ TCurrentContext,
836
+ InferSchemaOutput<TInputSchema>,
837
+ TEffectErrorMap,
838
+ TRequirementsProvided,
839
+ TMeta,
840
+ TTag
841
+ >,
842
+ ): EffectProcedureBuilderWithInput<
843
+ TInitialContext,
844
+ TCurrentContext,
845
+ TInputSchema,
846
+ TOutputSchema,
847
+ TEffectErrorMap,
848
+ TMeta,
849
+ TRequirementsProvided | EffectTagIdentifier<TTag>,
850
+ TRuntimeError
851
+ >;
852
+
853
+ /**
854
+ * Optionally provides a request-scoped Effect service to downstream procedures.
855
+ */
856
+ "provideOptional"<TTag extends EffectContext.Tag<any, any>>(
857
+ tag: TTag,
858
+ provider: EffectOptionalProvider<
859
+ TCurrentContext,
860
+ InferSchemaOutput<TInputSchema>,
861
+ TEffectErrorMap,
862
+ TRequirementsProvided,
863
+ TMeta,
864
+ TTag
865
+ >,
866
+ ): EffectProcedureBuilderWithInput<
867
+ TInitialContext,
868
+ TCurrentContext,
869
+ TInputSchema,
870
+ TOutputSchema,
871
+ TEffectErrorMap,
872
+ TMeta,
873
+ TRequirementsProvided,
874
+ TRuntimeError
875
+ >;
876
+
675
877
  /**
676
878
  * Sets or updates the metadata.
677
879
  * The provided metadata is spared-merged with any existing metadata.
@@ -756,7 +958,7 @@ export interface EffectProcedureBuilderWithInput<
756
958
 
757
959
  /**
758
960
  * Defines the handler of the procedure using an Effect.
759
- * The Effect is executed using the ManagedRuntime provided during builder creation.
961
+ * The Effect is executed using the configured Effect runtime source.
760
962
  * The effect is automatically wrapped with `Effect.withSpan`.
761
963
  *
762
964
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
@@ -864,12 +1066,13 @@ export interface EffectProcedureBuilderWithOutput<
864
1066
  UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
865
1067
  UInContext extends Context = TCurrentContext,
866
1068
  >(
867
- middleware: Middleware<
1069
+ middleware: EffectOrORPCMiddleware<
868
1070
  UInContext | TCurrentContext,
869
1071
  UOutContext,
870
1072
  unknown,
871
1073
  InferSchemaInput<TOutputSchema>,
872
- EffectErrorConstructorMap<TEffectErrorMap>,
1074
+ TEffectErrorMap,
1075
+ TRequirementsProvided,
873
1076
  TMeta
874
1077
  >,
875
1078
  ): EffectProcedureBuilderWithOutput<
@@ -883,6 +1086,70 @@ export interface EffectProcedureBuilderWithOutput<
883
1086
  TRuntimeError
884
1087
  >;
885
1088
 
1089
+ /**
1090
+ * Provides an Effect layer to downstream procedures.
1091
+ */
1092
+ "provide"<TLayerOut, TLayerError, TLayerIn extends TRequirementsProvided>(
1093
+ layer: Layer.Layer<TLayerOut, TLayerError, TLayerIn>,
1094
+ ): EffectProcedureBuilderWithOutput<
1095
+ TInitialContext,
1096
+ TCurrentContext,
1097
+ TInputSchema,
1098
+ TOutputSchema,
1099
+ TEffectErrorMap,
1100
+ TMeta,
1101
+ TRequirementsProvided | TLayerOut,
1102
+ TRuntimeError | TLayerError
1103
+ >;
1104
+
1105
+ /**
1106
+ * Provides a request-scoped Effect service to downstream procedures.
1107
+ */
1108
+ "provide"<TTag extends EffectContext.Tag<any, any>>(
1109
+ tag: TTag,
1110
+ provider: EffectProvider<
1111
+ TCurrentContext,
1112
+ InferSchemaOutput<TInputSchema>,
1113
+ TEffectErrorMap,
1114
+ TRequirementsProvided,
1115
+ TMeta,
1116
+ TTag
1117
+ >,
1118
+ ): EffectProcedureBuilderWithOutput<
1119
+ TInitialContext,
1120
+ TCurrentContext,
1121
+ TInputSchema,
1122
+ TOutputSchema,
1123
+ TEffectErrorMap,
1124
+ TMeta,
1125
+ TRequirementsProvided | EffectTagIdentifier<TTag>,
1126
+ TRuntimeError
1127
+ >;
1128
+
1129
+ /**
1130
+ * Optionally provides a request-scoped Effect service to downstream procedures.
1131
+ */
1132
+ "provideOptional"<TTag extends EffectContext.Tag<any, any>>(
1133
+ tag: TTag,
1134
+ provider: EffectOptionalProvider<
1135
+ TCurrentContext,
1136
+ InferSchemaOutput<TInputSchema>,
1137
+ TEffectErrorMap,
1138
+ TRequirementsProvided,
1139
+ TMeta,
1140
+ TTag
1141
+ >,
1142
+ ): EffectProcedureBuilderWithOutput<
1143
+ TInitialContext,
1144
+ TCurrentContext,
1145
+ TInputSchema,
1146
+ TOutputSchema,
1147
+ TEffectErrorMap,
1148
+ TMeta,
1149
+ TRequirementsProvided,
1150
+ TRuntimeError
1151
+ >;
1152
+
886
1153
  /**
887
1154
  * Sets or updates the metadata.
888
1155
  * The provided metadata is spared-merged with any existing metadata.
@@ -967,7 +1234,7 @@ export interface EffectProcedureBuilderWithOutput<
967
1234
 
968
1235
  /**
969
1236
  * Defines the handler of the procedure using an Effect.
970
- * The Effect is executed using the ManagedRuntime provided during builder creation.
1237
+ * The Effect is executed using the configured Effect runtime source.
971
1238
  * The effect is automatically wrapped with `Effect.withSpan`.
972
1239
  *
973
1240
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
@@ -1076,12 +1343,13 @@ export interface EffectProcedureBuilderWithInputOutput<
1076
1343
  UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
1077
1344
  UInContext extends Context = TCurrentContext,
1078
1345
  >(
1079
- middleware: Middleware<
1346
+ middleware: EffectOrORPCMiddleware<
1080
1347
  UInContext | TCurrentContext,
1081
1348
  UOutContext,
1082
1349
  InferSchemaOutput<TInputSchema>,
1083
1350
  InferSchemaInput<TOutputSchema>,
1084
- EffectErrorConstructorMap<TEffectErrorMap>,
1351
+ TEffectErrorMap,
1352
+ TRequirementsProvided,
1085
1353
  TMeta
1086
1354
  >,
1087
1355
  ): EffectProcedureBuilderWithInputOutput<
@@ -1128,6 +1396,70 @@ export interface EffectProcedureBuilderWithInputOutput<
1128
1396
  TRuntimeError
1129
1397
  >;
1130
1398
 
1399
+ /**
1400
+ * Provides an Effect layer to downstream procedures.
1401
+ */
1402
+ "provide"<TLayerOut, TLayerError, TLayerIn extends TRequirementsProvided>(
1403
+ layer: Layer.Layer<TLayerOut, TLayerError, TLayerIn>,
1404
+ ): EffectProcedureBuilderWithInputOutput<
1405
+ TInitialContext,
1406
+ TCurrentContext,
1407
+ TInputSchema,
1408
+ TOutputSchema,
1409
+ TEffectErrorMap,
1410
+ TMeta,
1411
+ TRequirementsProvided | TLayerOut,
1412
+ TRuntimeError | TLayerError
1413
+ >;
1414
+
1415
+ /**
1416
+ * Provides a request-scoped Effect service to downstream procedures.
1417
+ */
1418
+ "provide"<TTag extends EffectContext.Tag<any, any>>(
1419
+ tag: TTag,
1420
+ provider: EffectProvider<
1421
+ TCurrentContext,
1422
+ InferSchemaOutput<TInputSchema>,
1423
+ TEffectErrorMap,
1424
+ TRequirementsProvided,
1425
+ TMeta,
1426
+ TTag
1427
+ >,
1428
+ ): EffectProcedureBuilderWithInputOutput<
1429
+ TInitialContext,
1430
+ TCurrentContext,
1431
+ TInputSchema,
1432
+ TOutputSchema,
1433
+ TEffectErrorMap,
1434
+ TMeta,
1435
+ TRequirementsProvided | EffectTagIdentifier<TTag>,
1436
+ TRuntimeError
1437
+ >;
1438
+
1439
+ /**
1440
+ * Optionally provides a request-scoped Effect service to downstream procedures.
1441
+ */
1442
+ "provideOptional"<TTag extends EffectContext.Tag<any, any>>(
1443
+ tag: TTag,
1444
+ provider: EffectOptionalProvider<
1445
+ TCurrentContext,
1446
+ InferSchemaOutput<TInputSchema>,
1447
+ TEffectErrorMap,
1448
+ TRequirementsProvided,
1449
+ TMeta,
1450
+ TTag
1451
+ >,
1452
+ ): EffectProcedureBuilderWithInputOutput<
1453
+ TInitialContext,
1454
+ TCurrentContext,
1455
+ TInputSchema,
1456
+ TOutputSchema,
1457
+ TEffectErrorMap,
1458
+ TMeta,
1459
+ TRequirementsProvided,
1460
+ TRuntimeError
1461
+ >;
1462
+
1131
1463
  /**
1132
1464
  * Sets or updates the metadata.
1133
1465
  * The provided metadata is spared-merged with any existing metadata.
@@ -1194,7 +1526,7 @@ export interface EffectProcedureBuilderWithInputOutput<
1194
1526
 
1195
1527
  /**
1196
1528
  * Defines the handler of the procedure using an Effect.
1197
- * The Effect is executed using the ManagedRuntime provided during builder creation.
1529
+ * The Effect is executed using the configured Effect runtime source.
1198
1530
  * The effect is automatically wrapped with `Effect.withSpan`.
1199
1531
  *
1200
1532
  * @see {@link https://orpc.dev/docs/procedure Procedure Docs}
@@ -1282,12 +1614,13 @@ export interface EffectRouterBuilder<
1282
1614
  UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
1283
1615
  UInContext extends Context = TCurrentContext,
1284
1616
  >(
1285
- middleware: Middleware<
1617
+ middleware: EffectOrORPCMiddleware<
1286
1618
  UInContext | TCurrentContext,
1287
1619
  UOutContext,
1288
1620
  unknown,
1289
1621
  unknown,
1290
- EffectErrorConstructorMap<TEffectErrorMap>,
1622
+ TEffectErrorMap,
1623
+ TRequirementsProvided,
1291
1624
  TMeta
1292
1625
  >,
1293
1626
  ): EffectRouterBuilder<
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/fiber-context-bridge.ts"],"sourcesContent":["import type { FiberRefs } from \"effect\";\n\nexport interface FiberContextBridge {\n readonly getCurrentFiberRefs: () => FiberRefs.FiberRefs | undefined;\n}\n\nlet bridge: FiberContextBridge | undefined;\n\nexport function installFiberContextBridge(\n nextBridge: FiberContextBridge | undefined,\n): void {\n bridge = nextBridge;\n}\n\nexport function getCurrentFiberRefs(): FiberRefs.FiberRefs | undefined {\n return bridge?.getCurrentFiberRefs();\n}\n"],"mappings":";AAMA,IAAI;AAEG,SAAS,0BACd,YACM;AACN,WAAS;AACX;AAEO,SAAS,sBAAuD;AACrE,SAAO,QAAQ,oBAAoB;AACrC;","names":[]}