effect-orpc 0.0.5 → 0.0.7
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 +175 -537
- package/dist/index.js +274 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/effect-builder.ts +367 -178
- package/src/effect-enhance-router.ts +114 -0
- package/src/effect-procedure.ts +95 -32
- package/src/index.ts +20 -7
- package/src/tagged-error.ts +154 -100
- package/src/tests/effect-builder.test.ts +52 -39
- package/src/tests/effect-error-map.test.ts +36 -31
- package/src/tests/effect-procedure.test.ts +12 -12
- package/src/tests/tagged-error.test.ts +84 -27
- package/src/types/index.ts +422 -0
- package/src/types/variants.ts +1327 -0
|
@@ -0,0 +1,1327 @@
|
|
|
1
|
+
import type { HTTPPath } from "@orpc/client";
|
|
2
|
+
import type {
|
|
3
|
+
AnySchema,
|
|
4
|
+
ContractRouter,
|
|
5
|
+
InferSchemaInput,
|
|
6
|
+
InferSchemaOutput,
|
|
7
|
+
Meta,
|
|
8
|
+
Route,
|
|
9
|
+
Schema,
|
|
10
|
+
} from "@orpc/contract";
|
|
11
|
+
import type {
|
|
12
|
+
AccessibleLazyRouter,
|
|
13
|
+
AnyRouter,
|
|
14
|
+
BuilderDef,
|
|
15
|
+
Context,
|
|
16
|
+
EnhanceRouterOptions,
|
|
17
|
+
IntersectPick,
|
|
18
|
+
Lazy,
|
|
19
|
+
Lazyable,
|
|
20
|
+
MapInputMiddleware,
|
|
21
|
+
MergedCurrentContext,
|
|
22
|
+
MergedInitialContext,
|
|
23
|
+
Middleware,
|
|
24
|
+
Router,
|
|
25
|
+
} from "@orpc/server";
|
|
26
|
+
|
|
27
|
+
import type {
|
|
28
|
+
EffectBuilderDef,
|
|
29
|
+
EffectErrorMapToErrorMap,
|
|
30
|
+
EffectProcedureHandler,
|
|
31
|
+
} from ".";
|
|
32
|
+
import type {
|
|
33
|
+
EffectDecoratedProcedure,
|
|
34
|
+
EffectProcedure,
|
|
35
|
+
} from "../effect-procedure";
|
|
36
|
+
import type {
|
|
37
|
+
EffectErrorConstructorMap,
|
|
38
|
+
EffectErrorMap,
|
|
39
|
+
MergedEffectErrorMap,
|
|
40
|
+
} from "../tagged-error";
|
|
41
|
+
|
|
42
|
+
export interface EffectBuilderWithMiddlewares<
|
|
43
|
+
TInitialContext extends Context,
|
|
44
|
+
TCurrentContext extends Context,
|
|
45
|
+
TInputSchema extends AnySchema,
|
|
46
|
+
TOutputSchema extends AnySchema,
|
|
47
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
48
|
+
TMeta extends Meta,
|
|
49
|
+
TRequirementsProvided,
|
|
50
|
+
TRuntimeError,
|
|
51
|
+
> {
|
|
52
|
+
/**
|
|
53
|
+
* This property holds the defined options and the effect-specific properties.
|
|
54
|
+
*/
|
|
55
|
+
"~effect": EffectBuilderDef<
|
|
56
|
+
TInputSchema,
|
|
57
|
+
TOutputSchema,
|
|
58
|
+
TEffectErrorMap,
|
|
59
|
+
TMeta,
|
|
60
|
+
TRequirementsProvided,
|
|
61
|
+
TRuntimeError
|
|
62
|
+
>;
|
|
63
|
+
/**
|
|
64
|
+
* This property holds the defined options.
|
|
65
|
+
*/
|
|
66
|
+
"~orpc": BuilderDef<
|
|
67
|
+
TInputSchema,
|
|
68
|
+
TOutputSchema,
|
|
69
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
70
|
+
TMeta
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds type-safe custom errors.
|
|
75
|
+
* The provided errors are spared-merged with any existing errors.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
78
|
+
*/
|
|
79
|
+
"errors"<U extends EffectErrorMap>(
|
|
80
|
+
errors: U,
|
|
81
|
+
): EffectBuilderWithMiddlewares<
|
|
82
|
+
TInitialContext,
|
|
83
|
+
TCurrentContext,
|
|
84
|
+
TInputSchema,
|
|
85
|
+
TOutputSchema,
|
|
86
|
+
Omit<TEffectErrorMap, keyof U> & U,
|
|
87
|
+
TMeta,
|
|
88
|
+
TRequirementsProvided,
|
|
89
|
+
TRuntimeError
|
|
90
|
+
>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
94
|
+
*
|
|
95
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
96
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
97
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
98
|
+
*/
|
|
99
|
+
"use"<
|
|
100
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
101
|
+
UInContext extends Context = TCurrentContext,
|
|
102
|
+
>(
|
|
103
|
+
middleware: Middleware<
|
|
104
|
+
UInContext | TCurrentContext,
|
|
105
|
+
UOutContext,
|
|
106
|
+
unknown,
|
|
107
|
+
unknown,
|
|
108
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
109
|
+
TMeta
|
|
110
|
+
>,
|
|
111
|
+
): EffectBuilderWithMiddlewares<
|
|
112
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
113
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
114
|
+
TInputSchema,
|
|
115
|
+
TOutputSchema,
|
|
116
|
+
TEffectErrorMap,
|
|
117
|
+
TMeta,
|
|
118
|
+
TRequirementsProvided,
|
|
119
|
+
TRuntimeError
|
|
120
|
+
>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Sets or updates the metadata.
|
|
124
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
125
|
+
*
|
|
126
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
127
|
+
*/
|
|
128
|
+
"meta"(
|
|
129
|
+
meta: TMeta,
|
|
130
|
+
): EffectBuilderWithMiddlewares<
|
|
131
|
+
TInitialContext,
|
|
132
|
+
TCurrentContext,
|
|
133
|
+
TInputSchema,
|
|
134
|
+
TOutputSchema,
|
|
135
|
+
TEffectErrorMap,
|
|
136
|
+
TMeta,
|
|
137
|
+
TRequirementsProvided,
|
|
138
|
+
TRuntimeError
|
|
139
|
+
>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sets or updates the route definition.
|
|
143
|
+
* The provided route is spared-merged with any existing route.
|
|
144
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
145
|
+
*
|
|
146
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
147
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
148
|
+
*/
|
|
149
|
+
"route"(
|
|
150
|
+
route: Route,
|
|
151
|
+
): EffectProcedureBuilder<
|
|
152
|
+
TInitialContext,
|
|
153
|
+
TCurrentContext,
|
|
154
|
+
TInputSchema,
|
|
155
|
+
TOutputSchema,
|
|
156
|
+
TEffectErrorMap,
|
|
157
|
+
TMeta,
|
|
158
|
+
TRequirementsProvided,
|
|
159
|
+
TRuntimeError
|
|
160
|
+
>;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Defines the input validation schema.
|
|
164
|
+
*
|
|
165
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
166
|
+
*/
|
|
167
|
+
"input"<USchema extends AnySchema>(
|
|
168
|
+
schema: USchema,
|
|
169
|
+
): EffectProcedureBuilderWithInput<
|
|
170
|
+
TInitialContext,
|
|
171
|
+
TCurrentContext,
|
|
172
|
+
USchema,
|
|
173
|
+
TOutputSchema,
|
|
174
|
+
TEffectErrorMap,
|
|
175
|
+
TMeta,
|
|
176
|
+
TRequirementsProvided,
|
|
177
|
+
TRuntimeError
|
|
178
|
+
>;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Defines the output validation schema.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
184
|
+
*/
|
|
185
|
+
"output"<USchema extends AnySchema>(
|
|
186
|
+
schema: USchema,
|
|
187
|
+
): EffectProcedureBuilderWithOutput<
|
|
188
|
+
TInitialContext,
|
|
189
|
+
TCurrentContext,
|
|
190
|
+
TInputSchema,
|
|
191
|
+
USchema,
|
|
192
|
+
TEffectErrorMap,
|
|
193
|
+
TMeta,
|
|
194
|
+
TRequirementsProvided,
|
|
195
|
+
TRuntimeError
|
|
196
|
+
>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Defines the handler of the procedure.
|
|
200
|
+
*
|
|
201
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
202
|
+
*/
|
|
203
|
+
"handler"<UFuncOutput>(
|
|
204
|
+
handler: EffectProcedureHandler<
|
|
205
|
+
TCurrentContext,
|
|
206
|
+
unknown,
|
|
207
|
+
UFuncOutput,
|
|
208
|
+
TEffectErrorMap,
|
|
209
|
+
TRequirementsProvided,
|
|
210
|
+
TMeta
|
|
211
|
+
>,
|
|
212
|
+
): EffectDecoratedProcedure<
|
|
213
|
+
TInitialContext,
|
|
214
|
+
TCurrentContext,
|
|
215
|
+
TInputSchema,
|
|
216
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
217
|
+
TEffectErrorMap,
|
|
218
|
+
TMeta,
|
|
219
|
+
TRequirementsProvided,
|
|
220
|
+
TRuntimeError
|
|
221
|
+
>;
|
|
222
|
+
|
|
223
|
+
"effect"<UFuncOutput>(
|
|
224
|
+
effectFn: EffectProcedureHandler<
|
|
225
|
+
TCurrentContext,
|
|
226
|
+
InferSchemaOutput<TInputSchema>,
|
|
227
|
+
UFuncOutput,
|
|
228
|
+
TEffectErrorMap,
|
|
229
|
+
TRequirementsProvided,
|
|
230
|
+
TMeta
|
|
231
|
+
>,
|
|
232
|
+
): EffectDecoratedProcedure<
|
|
233
|
+
TInitialContext,
|
|
234
|
+
TCurrentContext,
|
|
235
|
+
TInputSchema,
|
|
236
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
237
|
+
TEffectErrorMap,
|
|
238
|
+
TMeta,
|
|
239
|
+
TRequirementsProvided,
|
|
240
|
+
TRuntimeError
|
|
241
|
+
>;
|
|
242
|
+
|
|
243
|
+
"traced"(
|
|
244
|
+
spanName: string,
|
|
245
|
+
): EffectProcedureBuilderWithInput<
|
|
246
|
+
TInitialContext,
|
|
247
|
+
TCurrentContext,
|
|
248
|
+
TInputSchema,
|
|
249
|
+
TOutputSchema,
|
|
250
|
+
TEffectErrorMap,
|
|
251
|
+
TMeta,
|
|
252
|
+
TRequirementsProvided,
|
|
253
|
+
TRuntimeError
|
|
254
|
+
>;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Prefixes all procedures in the router.
|
|
258
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
259
|
+
*
|
|
260
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
261
|
+
*
|
|
262
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
263
|
+
*/
|
|
264
|
+
"prefix"(
|
|
265
|
+
prefix: HTTPPath,
|
|
266
|
+
): EffectRouterBuilder<
|
|
267
|
+
TInitialContext,
|
|
268
|
+
TCurrentContext,
|
|
269
|
+
TEffectErrorMap,
|
|
270
|
+
TMeta,
|
|
271
|
+
TRequirementsProvided,
|
|
272
|
+
TRuntimeError
|
|
273
|
+
>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Adds tags to all procedures in the router.
|
|
277
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
278
|
+
*
|
|
279
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
280
|
+
*/
|
|
281
|
+
"tag"(
|
|
282
|
+
...tags: string[]
|
|
283
|
+
): EffectRouterBuilder<
|
|
284
|
+
TInitialContext,
|
|
285
|
+
TCurrentContext,
|
|
286
|
+
TEffectErrorMap,
|
|
287
|
+
TMeta,
|
|
288
|
+
TRequirementsProvided,
|
|
289
|
+
TRuntimeError
|
|
290
|
+
>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Applies all of the previously defined options to the specified router.
|
|
294
|
+
*
|
|
295
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
296
|
+
*/
|
|
297
|
+
"router"<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
|
|
298
|
+
router: U,
|
|
299
|
+
): EnhancedEffectRouter<U, TInitialContext, TCurrentContext, TEffectErrorMap>;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Create a lazy router
|
|
303
|
+
* And applies all of the previously defined options to the specified router.
|
|
304
|
+
*
|
|
305
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
306
|
+
*/
|
|
307
|
+
"lazy"<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
|
|
308
|
+
loader: () => Promise<{ default: U }>,
|
|
309
|
+
): EnhancedEffectRouter<
|
|
310
|
+
Lazy<U>,
|
|
311
|
+
TInitialContext,
|
|
312
|
+
TCurrentContext,
|
|
313
|
+
TEffectErrorMap
|
|
314
|
+
>;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export interface EffectProcedureBuilder<
|
|
318
|
+
TInitialContext extends Context,
|
|
319
|
+
TCurrentContext extends Context,
|
|
320
|
+
TInputSchema extends AnySchema,
|
|
321
|
+
TOutputSchema extends AnySchema,
|
|
322
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
323
|
+
TMeta extends Meta,
|
|
324
|
+
TRequirementsProvided,
|
|
325
|
+
TRuntimeError,
|
|
326
|
+
> {
|
|
327
|
+
/**
|
|
328
|
+
* This property holds the defined options and the effect-specific properties.
|
|
329
|
+
*/
|
|
330
|
+
"~effect": EffectBuilderDef<
|
|
331
|
+
TInputSchema,
|
|
332
|
+
TOutputSchema,
|
|
333
|
+
TEffectErrorMap,
|
|
334
|
+
TMeta,
|
|
335
|
+
TRequirementsProvided,
|
|
336
|
+
TRuntimeError
|
|
337
|
+
>;
|
|
338
|
+
/**
|
|
339
|
+
* This property holds the defined options.
|
|
340
|
+
*/
|
|
341
|
+
"~orpc": BuilderDef<
|
|
342
|
+
TInputSchema,
|
|
343
|
+
TOutputSchema,
|
|
344
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
345
|
+
TMeta
|
|
346
|
+
>;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Adds type-safe custom errors.
|
|
350
|
+
* The provided errors are spared-merged with any existing errors.
|
|
351
|
+
*
|
|
352
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
353
|
+
*/
|
|
354
|
+
"errors"<U extends EffectErrorMap>(
|
|
355
|
+
errors: U,
|
|
356
|
+
): EffectProcedureBuilder<
|
|
357
|
+
TInitialContext,
|
|
358
|
+
TCurrentContext,
|
|
359
|
+
TInputSchema,
|
|
360
|
+
TOutputSchema,
|
|
361
|
+
MergedEffectErrorMap<TEffectErrorMap, U>,
|
|
362
|
+
TMeta,
|
|
363
|
+
TRequirementsProvided,
|
|
364
|
+
TRuntimeError
|
|
365
|
+
>;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
369
|
+
*
|
|
370
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
371
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
372
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
373
|
+
*/
|
|
374
|
+
"use"<
|
|
375
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
376
|
+
UInContext extends Context = TCurrentContext,
|
|
377
|
+
>(
|
|
378
|
+
middleware: Middleware<
|
|
379
|
+
UInContext | TCurrentContext,
|
|
380
|
+
UOutContext,
|
|
381
|
+
unknown,
|
|
382
|
+
unknown,
|
|
383
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
384
|
+
TMeta
|
|
385
|
+
>,
|
|
386
|
+
): EffectProcedureBuilder<
|
|
387
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
388
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
389
|
+
TInputSchema,
|
|
390
|
+
TOutputSchema,
|
|
391
|
+
TEffectErrorMap,
|
|
392
|
+
TMeta,
|
|
393
|
+
TRequirementsProvided,
|
|
394
|
+
TRuntimeError
|
|
395
|
+
>;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Sets or updates the metadata.
|
|
399
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
400
|
+
*
|
|
401
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
402
|
+
*/
|
|
403
|
+
"meta"(
|
|
404
|
+
meta: TMeta,
|
|
405
|
+
): EffectProcedureBuilder<
|
|
406
|
+
TInitialContext,
|
|
407
|
+
TCurrentContext,
|
|
408
|
+
TInputSchema,
|
|
409
|
+
TOutputSchema,
|
|
410
|
+
TEffectErrorMap,
|
|
411
|
+
TMeta,
|
|
412
|
+
TRequirementsProvided,
|
|
413
|
+
TRuntimeError
|
|
414
|
+
>;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Sets or updates the route definition.
|
|
418
|
+
* The provided route is spared-merged with any existing route.
|
|
419
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
420
|
+
*
|
|
421
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
422
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
423
|
+
*/
|
|
424
|
+
"route"(
|
|
425
|
+
route: Route,
|
|
426
|
+
): EffectProcedureBuilder<
|
|
427
|
+
TInitialContext,
|
|
428
|
+
TCurrentContext,
|
|
429
|
+
TInputSchema,
|
|
430
|
+
TOutputSchema,
|
|
431
|
+
TEffectErrorMap,
|
|
432
|
+
TMeta,
|
|
433
|
+
TRequirementsProvided,
|
|
434
|
+
TRuntimeError
|
|
435
|
+
>;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Defines the input validation schema.
|
|
439
|
+
*
|
|
440
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
441
|
+
*/
|
|
442
|
+
"input"<USchema extends AnySchema>(
|
|
443
|
+
schema: USchema,
|
|
444
|
+
): EffectProcedureBuilderWithInput<
|
|
445
|
+
TInitialContext,
|
|
446
|
+
TCurrentContext,
|
|
447
|
+
USchema,
|
|
448
|
+
TOutputSchema,
|
|
449
|
+
TEffectErrorMap,
|
|
450
|
+
TMeta,
|
|
451
|
+
TRequirementsProvided,
|
|
452
|
+
TRuntimeError
|
|
453
|
+
>;
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Defines the output validation schema.
|
|
457
|
+
*
|
|
458
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
459
|
+
*/
|
|
460
|
+
"output"<USchema extends AnySchema>(
|
|
461
|
+
schema: USchema,
|
|
462
|
+
): EffectProcedureBuilderWithOutput<
|
|
463
|
+
TInitialContext,
|
|
464
|
+
TCurrentContext,
|
|
465
|
+
TInputSchema,
|
|
466
|
+
USchema,
|
|
467
|
+
TEffectErrorMap,
|
|
468
|
+
TMeta,
|
|
469
|
+
TRequirementsProvided,
|
|
470
|
+
TRuntimeError
|
|
471
|
+
>;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Defines the handler of the procedure.
|
|
475
|
+
*
|
|
476
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
477
|
+
*/
|
|
478
|
+
"handler"<UFuncOutput>(
|
|
479
|
+
handler: EffectProcedureHandler<
|
|
480
|
+
TCurrentContext,
|
|
481
|
+
unknown,
|
|
482
|
+
UFuncOutput,
|
|
483
|
+
TEffectErrorMap,
|
|
484
|
+
TRequirementsProvided,
|
|
485
|
+
TMeta
|
|
486
|
+
>,
|
|
487
|
+
): EffectDecoratedProcedure<
|
|
488
|
+
TInitialContext,
|
|
489
|
+
TCurrentContext,
|
|
490
|
+
TInputSchema,
|
|
491
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
492
|
+
TEffectErrorMap,
|
|
493
|
+
TMeta,
|
|
494
|
+
TRequirementsProvided,
|
|
495
|
+
TRuntimeError
|
|
496
|
+
>;
|
|
497
|
+
|
|
498
|
+
"effect"<UFuncOutput>(
|
|
499
|
+
effectFn: EffectProcedureHandler<
|
|
500
|
+
TCurrentContext,
|
|
501
|
+
InferSchemaOutput<TInputSchema>,
|
|
502
|
+
UFuncOutput,
|
|
503
|
+
TEffectErrorMap,
|
|
504
|
+
TRequirementsProvided,
|
|
505
|
+
TMeta
|
|
506
|
+
>,
|
|
507
|
+
): EffectDecoratedProcedure<
|
|
508
|
+
TInitialContext,
|
|
509
|
+
TCurrentContext,
|
|
510
|
+
TInputSchema,
|
|
511
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
512
|
+
TEffectErrorMap,
|
|
513
|
+
TMeta,
|
|
514
|
+
TRequirementsProvided,
|
|
515
|
+
TRuntimeError
|
|
516
|
+
>;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export interface EffectProcedureBuilderWithInput<
|
|
520
|
+
TInitialContext extends Context,
|
|
521
|
+
TCurrentContext extends Context,
|
|
522
|
+
TInputSchema extends AnySchema,
|
|
523
|
+
TOutputSchema extends AnySchema,
|
|
524
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
525
|
+
TMeta extends Meta,
|
|
526
|
+
TRequirementsProvided,
|
|
527
|
+
TRuntimeError,
|
|
528
|
+
> {
|
|
529
|
+
/**
|
|
530
|
+
* This property holds the defined options and the effect-specific properties.
|
|
531
|
+
*/
|
|
532
|
+
"~effect": EffectBuilderDef<
|
|
533
|
+
TInputSchema,
|
|
534
|
+
TOutputSchema,
|
|
535
|
+
TEffectErrorMap,
|
|
536
|
+
TMeta,
|
|
537
|
+
TRequirementsProvided,
|
|
538
|
+
TRuntimeError
|
|
539
|
+
>;
|
|
540
|
+
/**
|
|
541
|
+
* This property holds the defined options.
|
|
542
|
+
*/
|
|
543
|
+
"~orpc": BuilderDef<
|
|
544
|
+
TInputSchema,
|
|
545
|
+
TOutputSchema,
|
|
546
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
547
|
+
TMeta
|
|
548
|
+
>;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Adds type-safe custom errors.
|
|
552
|
+
* The provided errors are spared-merged with any existing errors.
|
|
553
|
+
*
|
|
554
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
555
|
+
*/
|
|
556
|
+
"errors"<U extends EffectErrorMap>(
|
|
557
|
+
errors: U,
|
|
558
|
+
): EffectProcedureBuilderWithInput<
|
|
559
|
+
TInitialContext,
|
|
560
|
+
TCurrentContext,
|
|
561
|
+
TInputSchema,
|
|
562
|
+
TOutputSchema,
|
|
563
|
+
MergedEffectErrorMap<TEffectErrorMap, U>,
|
|
564
|
+
TMeta,
|
|
565
|
+
TRequirementsProvided,
|
|
566
|
+
TRuntimeError
|
|
567
|
+
>;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
571
|
+
*
|
|
572
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
573
|
+
* @info Pass second argument to map the input.
|
|
574
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
575
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
576
|
+
*/
|
|
577
|
+
"use"<
|
|
578
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
579
|
+
UInContext extends Context = TCurrentContext,
|
|
580
|
+
>(
|
|
581
|
+
middleware: Middleware<
|
|
582
|
+
UInContext | TCurrentContext,
|
|
583
|
+
UOutContext,
|
|
584
|
+
unknown,
|
|
585
|
+
unknown,
|
|
586
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
587
|
+
TMeta
|
|
588
|
+
>,
|
|
589
|
+
): EffectProcedureBuilderWithInput<
|
|
590
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
591
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
592
|
+
TInputSchema,
|
|
593
|
+
TOutputSchema,
|
|
594
|
+
TEffectErrorMap,
|
|
595
|
+
TMeta,
|
|
596
|
+
TRequirementsProvided,
|
|
597
|
+
TRuntimeError
|
|
598
|
+
>;
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
602
|
+
*
|
|
603
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
604
|
+
* @info Pass second argument to map the input.
|
|
605
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
606
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
607
|
+
*/
|
|
608
|
+
"use"<
|
|
609
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
610
|
+
UInput,
|
|
611
|
+
UInContext extends Context = TCurrentContext,
|
|
612
|
+
>(
|
|
613
|
+
middleware: Middleware<
|
|
614
|
+
UInContext | TCurrentContext,
|
|
615
|
+
UOutContext,
|
|
616
|
+
UInput,
|
|
617
|
+
unknown,
|
|
618
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
619
|
+
TMeta
|
|
620
|
+
>,
|
|
621
|
+
mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,
|
|
622
|
+
): EffectProcedureBuilderWithInput<
|
|
623
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
624
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
625
|
+
TInputSchema,
|
|
626
|
+
TOutputSchema,
|
|
627
|
+
TEffectErrorMap,
|
|
628
|
+
TMeta,
|
|
629
|
+
TRequirementsProvided,
|
|
630
|
+
TRuntimeError
|
|
631
|
+
>;
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* Sets or updates the metadata.
|
|
635
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
636
|
+
*
|
|
637
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
638
|
+
*/
|
|
639
|
+
"meta"(
|
|
640
|
+
meta: TMeta,
|
|
641
|
+
): EffectProcedureBuilderWithInput<
|
|
642
|
+
TInitialContext,
|
|
643
|
+
TCurrentContext,
|
|
644
|
+
TInputSchema,
|
|
645
|
+
TOutputSchema,
|
|
646
|
+
TEffectErrorMap,
|
|
647
|
+
TMeta,
|
|
648
|
+
TRequirementsProvided,
|
|
649
|
+
TRuntimeError
|
|
650
|
+
>;
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Sets or updates the route definition.
|
|
654
|
+
* The provided route is spared-merged with any existing route.
|
|
655
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
656
|
+
*
|
|
657
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
658
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
659
|
+
*/
|
|
660
|
+
"route"(
|
|
661
|
+
route: Route,
|
|
662
|
+
): EffectProcedureBuilderWithInput<
|
|
663
|
+
TInitialContext,
|
|
664
|
+
TCurrentContext,
|
|
665
|
+
TInputSchema,
|
|
666
|
+
TOutputSchema,
|
|
667
|
+
TEffectErrorMap,
|
|
668
|
+
TMeta,
|
|
669
|
+
TRequirementsProvided,
|
|
670
|
+
TRuntimeError
|
|
671
|
+
>;
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Defines the output validation schema.
|
|
675
|
+
*
|
|
676
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
677
|
+
*/
|
|
678
|
+
"output"<USchema extends AnySchema>(
|
|
679
|
+
schema: USchema,
|
|
680
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
681
|
+
TInitialContext,
|
|
682
|
+
TCurrentContext,
|
|
683
|
+
TInputSchema,
|
|
684
|
+
USchema,
|
|
685
|
+
TEffectErrorMap,
|
|
686
|
+
TMeta,
|
|
687
|
+
TRequirementsProvided,
|
|
688
|
+
TRuntimeError
|
|
689
|
+
>;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Defines the handler of the procedure.
|
|
693
|
+
*
|
|
694
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
695
|
+
*/
|
|
696
|
+
"handler"<UFuncOutput>(
|
|
697
|
+
handler: EffectProcedureHandler<
|
|
698
|
+
TCurrentContext,
|
|
699
|
+
InferSchemaOutput<TInputSchema>,
|
|
700
|
+
UFuncOutput,
|
|
701
|
+
TEffectErrorMap,
|
|
702
|
+
TRequirementsProvided,
|
|
703
|
+
TMeta
|
|
704
|
+
>,
|
|
705
|
+
): EffectDecoratedProcedure<
|
|
706
|
+
TInitialContext,
|
|
707
|
+
TCurrentContext,
|
|
708
|
+
TInputSchema,
|
|
709
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
710
|
+
TEffectErrorMap,
|
|
711
|
+
TMeta,
|
|
712
|
+
TRequirementsProvided,
|
|
713
|
+
TRuntimeError
|
|
714
|
+
>;
|
|
715
|
+
|
|
716
|
+
"effect"<UFuncOutput>(
|
|
717
|
+
effectFn: EffectProcedureHandler<
|
|
718
|
+
TCurrentContext,
|
|
719
|
+
InferSchemaOutput<TInputSchema>,
|
|
720
|
+
UFuncOutput,
|
|
721
|
+
TEffectErrorMap,
|
|
722
|
+
TRequirementsProvided,
|
|
723
|
+
TMeta
|
|
724
|
+
>,
|
|
725
|
+
): EffectDecoratedProcedure<
|
|
726
|
+
TInitialContext,
|
|
727
|
+
TCurrentContext,
|
|
728
|
+
TInputSchema,
|
|
729
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
730
|
+
TEffectErrorMap,
|
|
731
|
+
TMeta,
|
|
732
|
+
TRequirementsProvided,
|
|
733
|
+
TRuntimeError
|
|
734
|
+
>;
|
|
735
|
+
|
|
736
|
+
"traced"(
|
|
737
|
+
spanName: string,
|
|
738
|
+
): EffectProcedureBuilderWithInput<
|
|
739
|
+
TInitialContext,
|
|
740
|
+
TCurrentContext,
|
|
741
|
+
TInputSchema,
|
|
742
|
+
TOutputSchema,
|
|
743
|
+
TEffectErrorMap,
|
|
744
|
+
TMeta,
|
|
745
|
+
TRequirementsProvided,
|
|
746
|
+
TRuntimeError
|
|
747
|
+
>;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
export interface EffectProcedureBuilderWithOutput<
|
|
751
|
+
TInitialContext extends Context,
|
|
752
|
+
TCurrentContext extends Context,
|
|
753
|
+
TInputSchema extends AnySchema,
|
|
754
|
+
TOutputSchema extends AnySchema,
|
|
755
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
756
|
+
TMeta extends Meta,
|
|
757
|
+
TRequirementsProvided,
|
|
758
|
+
TRuntimeError,
|
|
759
|
+
> {
|
|
760
|
+
/**
|
|
761
|
+
* This property holds the defined options and the effect-specific properties.
|
|
762
|
+
*/
|
|
763
|
+
"~effect": EffectBuilderDef<
|
|
764
|
+
TInputSchema,
|
|
765
|
+
TOutputSchema,
|
|
766
|
+
TEffectErrorMap,
|
|
767
|
+
TMeta,
|
|
768
|
+
TRequirementsProvided,
|
|
769
|
+
TRuntimeError
|
|
770
|
+
>;
|
|
771
|
+
/**
|
|
772
|
+
* This property holds the defined options.
|
|
773
|
+
*/
|
|
774
|
+
"~orpc": BuilderDef<
|
|
775
|
+
TInputSchema,
|
|
776
|
+
TOutputSchema,
|
|
777
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
778
|
+
TMeta
|
|
779
|
+
>;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Adds type-safe custom errors.
|
|
783
|
+
* The provided errors are spared-merged with any existing errors.
|
|
784
|
+
*
|
|
785
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
786
|
+
*/
|
|
787
|
+
"errors"<U extends EffectErrorMap>(
|
|
788
|
+
errors: U,
|
|
789
|
+
): EffectProcedureBuilderWithOutput<
|
|
790
|
+
TInitialContext,
|
|
791
|
+
TCurrentContext,
|
|
792
|
+
TInputSchema,
|
|
793
|
+
TOutputSchema,
|
|
794
|
+
TEffectErrorMap,
|
|
795
|
+
TMeta,
|
|
796
|
+
TRequirementsProvided,
|
|
797
|
+
TRuntimeError
|
|
798
|
+
>;
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
802
|
+
*
|
|
803
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
804
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
805
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
806
|
+
*/
|
|
807
|
+
"use"<
|
|
808
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
809
|
+
UInContext extends Context = TCurrentContext,
|
|
810
|
+
>(
|
|
811
|
+
middleware: Middleware<
|
|
812
|
+
UInContext | TCurrentContext,
|
|
813
|
+
UOutContext,
|
|
814
|
+
unknown,
|
|
815
|
+
InferSchemaInput<TOutputSchema>,
|
|
816
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
817
|
+
TMeta
|
|
818
|
+
>,
|
|
819
|
+
): EffectProcedureBuilderWithOutput<
|
|
820
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
821
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
822
|
+
TInputSchema,
|
|
823
|
+
TOutputSchema,
|
|
824
|
+
TEffectErrorMap,
|
|
825
|
+
TMeta,
|
|
826
|
+
TRequirementsProvided,
|
|
827
|
+
TRuntimeError
|
|
828
|
+
>;
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Sets or updates the metadata.
|
|
832
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
833
|
+
*
|
|
834
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
835
|
+
*/
|
|
836
|
+
"meta"(
|
|
837
|
+
meta: TMeta,
|
|
838
|
+
): EffectProcedureBuilderWithOutput<
|
|
839
|
+
TInitialContext,
|
|
840
|
+
TCurrentContext,
|
|
841
|
+
TInputSchema,
|
|
842
|
+
TOutputSchema,
|
|
843
|
+
TEffectErrorMap,
|
|
844
|
+
TMeta,
|
|
845
|
+
TRequirementsProvided,
|
|
846
|
+
TRuntimeError
|
|
847
|
+
>;
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Sets or updates the route definition.
|
|
851
|
+
* The provided route is spared-merged with any existing route.
|
|
852
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
853
|
+
*
|
|
854
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
855
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
856
|
+
*/
|
|
857
|
+
"route"(
|
|
858
|
+
route: Route,
|
|
859
|
+
): EffectProcedureBuilderWithOutput<
|
|
860
|
+
TInitialContext,
|
|
861
|
+
TCurrentContext,
|
|
862
|
+
TInputSchema,
|
|
863
|
+
TOutputSchema,
|
|
864
|
+
TEffectErrorMap,
|
|
865
|
+
TMeta,
|
|
866
|
+
TRequirementsProvided,
|
|
867
|
+
TRuntimeError
|
|
868
|
+
>;
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Defines the input validation schema.
|
|
872
|
+
*
|
|
873
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
874
|
+
*/
|
|
875
|
+
"input"<USchema extends AnySchema>(
|
|
876
|
+
schema: USchema,
|
|
877
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
878
|
+
TInitialContext,
|
|
879
|
+
TCurrentContext,
|
|
880
|
+
USchema,
|
|
881
|
+
TOutputSchema,
|
|
882
|
+
TEffectErrorMap,
|
|
883
|
+
TMeta,
|
|
884
|
+
TRequirementsProvided,
|
|
885
|
+
TRuntimeError
|
|
886
|
+
>;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Defines the handler of the procedure.
|
|
890
|
+
*
|
|
891
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
892
|
+
*/
|
|
893
|
+
"handler"(
|
|
894
|
+
handler: EffectProcedureHandler<
|
|
895
|
+
TCurrentContext,
|
|
896
|
+
unknown,
|
|
897
|
+
InferSchemaInput<TOutputSchema>,
|
|
898
|
+
TEffectErrorMap,
|
|
899
|
+
TRequirementsProvided,
|
|
900
|
+
TMeta
|
|
901
|
+
>,
|
|
902
|
+
): EffectDecoratedProcedure<
|
|
903
|
+
TInitialContext,
|
|
904
|
+
TCurrentContext,
|
|
905
|
+
TInputSchema,
|
|
906
|
+
TOutputSchema,
|
|
907
|
+
TEffectErrorMap,
|
|
908
|
+
TMeta,
|
|
909
|
+
TRequirementsProvided,
|
|
910
|
+
TRuntimeError
|
|
911
|
+
>;
|
|
912
|
+
|
|
913
|
+
"effect"<UFuncOutput>(
|
|
914
|
+
effectFn: EffectProcedureHandler<
|
|
915
|
+
TCurrentContext,
|
|
916
|
+
InferSchemaOutput<TInputSchema>,
|
|
917
|
+
UFuncOutput,
|
|
918
|
+
TEffectErrorMap,
|
|
919
|
+
TRequirementsProvided,
|
|
920
|
+
TMeta
|
|
921
|
+
>,
|
|
922
|
+
): EffectDecoratedProcedure<
|
|
923
|
+
TInitialContext,
|
|
924
|
+
TCurrentContext,
|
|
925
|
+
TInputSchema,
|
|
926
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
927
|
+
TEffectErrorMap,
|
|
928
|
+
TMeta,
|
|
929
|
+
TRequirementsProvided,
|
|
930
|
+
TRuntimeError
|
|
931
|
+
>;
|
|
932
|
+
|
|
933
|
+
"traced"(
|
|
934
|
+
spanName: string,
|
|
935
|
+
): EffectProcedureBuilderWithInput<
|
|
936
|
+
TInitialContext,
|
|
937
|
+
TCurrentContext,
|
|
938
|
+
TInputSchema,
|
|
939
|
+
TOutputSchema,
|
|
940
|
+
TEffectErrorMap,
|
|
941
|
+
TMeta,
|
|
942
|
+
TRequirementsProvided,
|
|
943
|
+
TRuntimeError
|
|
944
|
+
>;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
export interface EffectProcedureBuilderWithInputOutput<
|
|
948
|
+
TInitialContext extends Context,
|
|
949
|
+
TCurrentContext extends Context,
|
|
950
|
+
TInputSchema extends AnySchema,
|
|
951
|
+
TOutputSchema extends AnySchema,
|
|
952
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
953
|
+
TMeta extends Meta,
|
|
954
|
+
TRequirementsProvided,
|
|
955
|
+
TRuntimeError,
|
|
956
|
+
> {
|
|
957
|
+
/**
|
|
958
|
+
* This property holds the defined options and the effect-specific properties.
|
|
959
|
+
*/
|
|
960
|
+
"~effect": EffectBuilderDef<
|
|
961
|
+
TInputSchema,
|
|
962
|
+
TOutputSchema,
|
|
963
|
+
TEffectErrorMap,
|
|
964
|
+
TMeta,
|
|
965
|
+
TRequirementsProvided,
|
|
966
|
+
TRuntimeError
|
|
967
|
+
>;
|
|
968
|
+
/**
|
|
969
|
+
* This property holds the defined options.
|
|
970
|
+
*/
|
|
971
|
+
"~orpc": BuilderDef<
|
|
972
|
+
TInputSchema,
|
|
973
|
+
TOutputSchema,
|
|
974
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
975
|
+
TMeta
|
|
976
|
+
>;
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Adds type-safe custom errors.
|
|
980
|
+
* The provided errors are spared-merged with any existing errors.
|
|
981
|
+
*
|
|
982
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
983
|
+
*/
|
|
984
|
+
"errors"<U extends EffectErrorMap>(
|
|
985
|
+
errors: U,
|
|
986
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
987
|
+
TInitialContext,
|
|
988
|
+
TCurrentContext,
|
|
989
|
+
TInputSchema,
|
|
990
|
+
TOutputSchema,
|
|
991
|
+
MergedEffectErrorMap<TEffectErrorMap, U>,
|
|
992
|
+
TMeta,
|
|
993
|
+
TRequirementsProvided,
|
|
994
|
+
TRuntimeError
|
|
995
|
+
>;
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
999
|
+
*
|
|
1000
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
1001
|
+
* @info Pass second argument to map the input.
|
|
1002
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
1003
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
1004
|
+
*/
|
|
1005
|
+
"use"<
|
|
1006
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
1007
|
+
UInContext extends Context = TCurrentContext,
|
|
1008
|
+
>(
|
|
1009
|
+
middleware: Middleware<
|
|
1010
|
+
UInContext | TCurrentContext,
|
|
1011
|
+
UOutContext,
|
|
1012
|
+
InferSchemaOutput<TInputSchema>,
|
|
1013
|
+
InferSchemaInput<TOutputSchema>,
|
|
1014
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
1015
|
+
TMeta
|
|
1016
|
+
>,
|
|
1017
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
1018
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
1019
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
1020
|
+
TInputSchema,
|
|
1021
|
+
TOutputSchema,
|
|
1022
|
+
TEffectErrorMap,
|
|
1023
|
+
TMeta,
|
|
1024
|
+
TRequirementsProvided,
|
|
1025
|
+
TRuntimeError
|
|
1026
|
+
>;
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
1030
|
+
*
|
|
1031
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
1032
|
+
* @info Pass second argument to map the input.
|
|
1033
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
1034
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
1035
|
+
*/
|
|
1036
|
+
"use"<
|
|
1037
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
1038
|
+
UInput,
|
|
1039
|
+
UInContext extends Context = TCurrentContext,
|
|
1040
|
+
>(
|
|
1041
|
+
middleware: Middleware<
|
|
1042
|
+
UInContext | TCurrentContext,
|
|
1043
|
+
UOutContext,
|
|
1044
|
+
UInput,
|
|
1045
|
+
InferSchemaInput<TOutputSchema>,
|
|
1046
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
1047
|
+
TMeta
|
|
1048
|
+
>,
|
|
1049
|
+
mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,
|
|
1050
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
1051
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
1052
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
1053
|
+
TInputSchema,
|
|
1054
|
+
TOutputSchema,
|
|
1055
|
+
TEffectErrorMap,
|
|
1056
|
+
TMeta,
|
|
1057
|
+
TRequirementsProvided,
|
|
1058
|
+
TRuntimeError
|
|
1059
|
+
>;
|
|
1060
|
+
|
|
1061
|
+
/**
|
|
1062
|
+
* Sets or updates the metadata.
|
|
1063
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
1064
|
+
*
|
|
1065
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
1066
|
+
*/
|
|
1067
|
+
"meta"(
|
|
1068
|
+
meta: TMeta,
|
|
1069
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
1070
|
+
TInitialContext,
|
|
1071
|
+
TCurrentContext,
|
|
1072
|
+
TInputSchema,
|
|
1073
|
+
TOutputSchema,
|
|
1074
|
+
TEffectErrorMap,
|
|
1075
|
+
TMeta,
|
|
1076
|
+
TRequirementsProvided,
|
|
1077
|
+
TRuntimeError
|
|
1078
|
+
>;
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Sets or updates the route definition.
|
|
1082
|
+
* The provided route is spared-merged with any existing route.
|
|
1083
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
1084
|
+
*
|
|
1085
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
1086
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
1087
|
+
*/
|
|
1088
|
+
"route"(
|
|
1089
|
+
route: Route,
|
|
1090
|
+
): EffectProcedureBuilderWithInputOutput<
|
|
1091
|
+
TInitialContext,
|
|
1092
|
+
TCurrentContext,
|
|
1093
|
+
TInputSchema,
|
|
1094
|
+
TOutputSchema,
|
|
1095
|
+
TEffectErrorMap,
|
|
1096
|
+
TMeta,
|
|
1097
|
+
TRequirementsProvided,
|
|
1098
|
+
TRuntimeError
|
|
1099
|
+
>;
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Defines the handler of the procedure.
|
|
1103
|
+
*
|
|
1104
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
1105
|
+
*/
|
|
1106
|
+
"handler"(
|
|
1107
|
+
handler: EffectProcedureHandler<
|
|
1108
|
+
TCurrentContext,
|
|
1109
|
+
InferSchemaOutput<TInputSchema>,
|
|
1110
|
+
InferSchemaInput<TOutputSchema>,
|
|
1111
|
+
TEffectErrorMap,
|
|
1112
|
+
TRequirementsProvided,
|
|
1113
|
+
TMeta
|
|
1114
|
+
>,
|
|
1115
|
+
): EffectDecoratedProcedure<
|
|
1116
|
+
TInitialContext,
|
|
1117
|
+
TCurrentContext,
|
|
1118
|
+
TInputSchema,
|
|
1119
|
+
TOutputSchema,
|
|
1120
|
+
TEffectErrorMap,
|
|
1121
|
+
TMeta,
|
|
1122
|
+
TRequirementsProvided,
|
|
1123
|
+
TRuntimeError
|
|
1124
|
+
>;
|
|
1125
|
+
|
|
1126
|
+
"effect"<UFuncOutput>(
|
|
1127
|
+
effectFn: EffectProcedureHandler<
|
|
1128
|
+
TCurrentContext,
|
|
1129
|
+
InferSchemaOutput<TInputSchema>,
|
|
1130
|
+
UFuncOutput,
|
|
1131
|
+
TEffectErrorMap,
|
|
1132
|
+
TRequirementsProvided,
|
|
1133
|
+
TMeta
|
|
1134
|
+
>,
|
|
1135
|
+
): EffectDecoratedProcedure<
|
|
1136
|
+
TInitialContext,
|
|
1137
|
+
TCurrentContext,
|
|
1138
|
+
TInputSchema,
|
|
1139
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
1140
|
+
TEffectErrorMap,
|
|
1141
|
+
TMeta,
|
|
1142
|
+
TRequirementsProvided,
|
|
1143
|
+
TRuntimeError
|
|
1144
|
+
>;
|
|
1145
|
+
|
|
1146
|
+
"traced"(
|
|
1147
|
+
spanName: string,
|
|
1148
|
+
): EffectProcedureBuilderWithInput<
|
|
1149
|
+
TInitialContext,
|
|
1150
|
+
TCurrentContext,
|
|
1151
|
+
TInputSchema,
|
|
1152
|
+
TOutputSchema,
|
|
1153
|
+
TEffectErrorMap,
|
|
1154
|
+
TMeta,
|
|
1155
|
+
TRequirementsProvided,
|
|
1156
|
+
TRuntimeError
|
|
1157
|
+
>;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
export interface EffectRouterBuilder<
|
|
1161
|
+
TInitialContext extends Context,
|
|
1162
|
+
TCurrentContext extends Context,
|
|
1163
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
1164
|
+
TMeta extends Meta,
|
|
1165
|
+
TRequirementsProvided,
|
|
1166
|
+
TRuntimeError,
|
|
1167
|
+
> {
|
|
1168
|
+
/**
|
|
1169
|
+
* This property holds the defined options.
|
|
1170
|
+
*/
|
|
1171
|
+
"~orpc": EnhanceRouterOptions<EffectErrorMapToErrorMap<TEffectErrorMap>>;
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Adds type-safe custom errors.
|
|
1175
|
+
* The provided errors are spared-merged with any existing errors.
|
|
1176
|
+
*
|
|
1177
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
1178
|
+
*/
|
|
1179
|
+
"errors"<U extends EffectErrorMap>(
|
|
1180
|
+
errors: U,
|
|
1181
|
+
): EffectRouterBuilder<
|
|
1182
|
+
TInitialContext,
|
|
1183
|
+
TCurrentContext,
|
|
1184
|
+
TEffectErrorMap,
|
|
1185
|
+
TMeta,
|
|
1186
|
+
TRequirementsProvided,
|
|
1187
|
+
TRuntimeError
|
|
1188
|
+
>;
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
1192
|
+
*
|
|
1193
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
1194
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
1195
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
1196
|
+
*/
|
|
1197
|
+
"use"<
|
|
1198
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
1199
|
+
UInContext extends Context = TCurrentContext,
|
|
1200
|
+
>(
|
|
1201
|
+
middleware: Middleware<
|
|
1202
|
+
UInContext | TCurrentContext,
|
|
1203
|
+
UOutContext,
|
|
1204
|
+
unknown,
|
|
1205
|
+
unknown,
|
|
1206
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
1207
|
+
TMeta
|
|
1208
|
+
>,
|
|
1209
|
+
): EffectRouterBuilder<
|
|
1210
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
1211
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
1212
|
+
TEffectErrorMap,
|
|
1213
|
+
TMeta,
|
|
1214
|
+
TRequirementsProvided,
|
|
1215
|
+
TRuntimeError
|
|
1216
|
+
>;
|
|
1217
|
+
|
|
1218
|
+
/**
|
|
1219
|
+
* Prefixes all procedures in the router.
|
|
1220
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
1221
|
+
*
|
|
1222
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
1223
|
+
*
|
|
1224
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
1225
|
+
*/
|
|
1226
|
+
"prefix"(
|
|
1227
|
+
prefix: HTTPPath,
|
|
1228
|
+
): EffectRouterBuilder<
|
|
1229
|
+
TInitialContext,
|
|
1230
|
+
TCurrentContext,
|
|
1231
|
+
TEffectErrorMap,
|
|
1232
|
+
TMeta,
|
|
1233
|
+
TRequirementsProvided,
|
|
1234
|
+
TRuntimeError
|
|
1235
|
+
>;
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* Adds tags to all procedures in the router.
|
|
1239
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
1240
|
+
*
|
|
1241
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
1242
|
+
*/
|
|
1243
|
+
"tag"(
|
|
1244
|
+
...tags: string[]
|
|
1245
|
+
): EffectRouterBuilder<
|
|
1246
|
+
TInitialContext,
|
|
1247
|
+
TCurrentContext,
|
|
1248
|
+
TEffectErrorMap,
|
|
1249
|
+
TMeta,
|
|
1250
|
+
TRequirementsProvided,
|
|
1251
|
+
TRuntimeError
|
|
1252
|
+
>;
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Applies all of the previously defined options to the specified router.
|
|
1256
|
+
*
|
|
1257
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
1258
|
+
*/
|
|
1259
|
+
"router"<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
|
|
1260
|
+
router: U,
|
|
1261
|
+
): EnhancedEffectRouter<U, TInitialContext, TCurrentContext, TEffectErrorMap>;
|
|
1262
|
+
|
|
1263
|
+
/**
|
|
1264
|
+
* Create a lazy router
|
|
1265
|
+
* And applies all of the previously defined options to the specified router.
|
|
1266
|
+
*
|
|
1267
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
1268
|
+
*/
|
|
1269
|
+
"lazy"<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
|
|
1270
|
+
loader: () => Promise<{ default: U }>,
|
|
1271
|
+
): EnhancedEffectRouter<
|
|
1272
|
+
Lazy<U>,
|
|
1273
|
+
TInitialContext,
|
|
1274
|
+
TCurrentContext,
|
|
1275
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>
|
|
1276
|
+
>;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
export type EnhancedEffectRouter<
|
|
1280
|
+
T extends Lazyable<AnyRouter>,
|
|
1281
|
+
TInitialContext extends Context,
|
|
1282
|
+
TCurrentContext extends Context,
|
|
1283
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
1284
|
+
> =
|
|
1285
|
+
T extends Lazy<infer U extends AnyRouter>
|
|
1286
|
+
? AccessibleLazyRouter<
|
|
1287
|
+
EnhancedEffectRouter<
|
|
1288
|
+
U,
|
|
1289
|
+
TInitialContext,
|
|
1290
|
+
TCurrentContext,
|
|
1291
|
+
TEffectErrorMap
|
|
1292
|
+
>
|
|
1293
|
+
>
|
|
1294
|
+
: T extends EffectProcedure<
|
|
1295
|
+
infer UInitialContext,
|
|
1296
|
+
infer UCurrentContext,
|
|
1297
|
+
infer UInputSchema,
|
|
1298
|
+
infer UOutputSchema,
|
|
1299
|
+
infer UEffectErrorMap,
|
|
1300
|
+
infer UMeta,
|
|
1301
|
+
infer URequirementsProvided,
|
|
1302
|
+
infer URuntimeError
|
|
1303
|
+
>
|
|
1304
|
+
? EffectProcedure<
|
|
1305
|
+
MergedInitialContext<
|
|
1306
|
+
TInitialContext,
|
|
1307
|
+
UInitialContext,
|
|
1308
|
+
TCurrentContext
|
|
1309
|
+
>,
|
|
1310
|
+
UCurrentContext,
|
|
1311
|
+
UInputSchema,
|
|
1312
|
+
UOutputSchema,
|
|
1313
|
+
MergedEffectErrorMap<TEffectErrorMap, UEffectErrorMap>,
|
|
1314
|
+
UMeta,
|
|
1315
|
+
URequirementsProvided,
|
|
1316
|
+
URuntimeError
|
|
1317
|
+
>
|
|
1318
|
+
: {
|
|
1319
|
+
[K in keyof T]: T[K] extends Lazyable<AnyRouter>
|
|
1320
|
+
? EnhancedEffectRouter<
|
|
1321
|
+
T[K],
|
|
1322
|
+
TInitialContext,
|
|
1323
|
+
TCurrentContext,
|
|
1324
|
+
TEffectErrorMap
|
|
1325
|
+
>
|
|
1326
|
+
: never;
|
|
1327
|
+
};
|