effect-orpc 0.1.4 → 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/README.md +95 -0
- package/dist/index.js +806 -476
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/contract.ts +491 -0
- package/src/effect-builder.ts +349 -619
- package/src/effect-enhance-router.ts +20 -21
- package/src/effect-procedure.ts +274 -263
- package/src/effect-runtime.ts +134 -0
- package/src/eoc.ts +499 -0
- 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 +20 -3
- package/src/tagged-error.ts +24 -4
- package/src/tests/contract.test.ts +346 -0
- package/src/tests/effect-builder.proxy.test.ts +253 -0
- package/src/tests/effect-error-map.test.ts +22 -3
- package/src/tests/parity-shared.ts +32 -0
- package/src/tests/parity.contract-builder-variants.test.ts +192 -0
- package/src/tests/parity.contract-builder.test.ts +222 -0
- package/src/tests/parity.effect-builder.test.ts +210 -0
- package/src/tests/parity.effect-procedure.test.ts +124 -0
- package/src/tests/parity.implementer-variants.test.ts +249 -0
- package/src/tests/parity.implementer.test.ts +280 -0
- package/src/tests/shared.ts +2 -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 -26
- package/src/types/variants.ts +100 -16
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnySchema,
|
|
3
|
+
ContractRouter,
|
|
4
|
+
HTTPPath,
|
|
5
|
+
InferSchemaOutput,
|
|
6
|
+
Meta,
|
|
7
|
+
Route,
|
|
8
|
+
Schema,
|
|
9
|
+
} from "@orpc/contract";
|
|
10
|
+
import type {
|
|
11
|
+
BuilderConfig,
|
|
12
|
+
BuilderDef,
|
|
13
|
+
Context,
|
|
14
|
+
DecoratedMiddleware,
|
|
15
|
+
Lazy,
|
|
16
|
+
MergedCurrentContext,
|
|
17
|
+
MergedInitialContext,
|
|
18
|
+
Middleware,
|
|
19
|
+
ProcedureHandler,
|
|
20
|
+
Router,
|
|
21
|
+
} from "@orpc/server";
|
|
22
|
+
import type { IntersectPick } from "@orpc/shared";
|
|
23
|
+
|
|
24
|
+
import type {
|
|
25
|
+
EffectBuilderDef,
|
|
26
|
+
EffectErrorMapToErrorMap,
|
|
27
|
+
EffectProcedureBuilderWithInput,
|
|
28
|
+
EffectProcedureBuilderWithOutput,
|
|
29
|
+
EffectProcedureHandler,
|
|
30
|
+
EffectRouterBuilder,
|
|
31
|
+
EnhancedEffectRouter,
|
|
32
|
+
} from ".";
|
|
33
|
+
import type { EffectDecoratedProcedure } from "../effect-procedure";
|
|
34
|
+
import type {
|
|
35
|
+
EffectErrorConstructorMap,
|
|
36
|
+
EffectErrorMap,
|
|
37
|
+
MergedEffectErrorMap,
|
|
38
|
+
} from "../tagged-error";
|
|
39
|
+
|
|
40
|
+
export interface EffectBuilderSurface<
|
|
41
|
+
TInitialContext extends Context,
|
|
42
|
+
TCurrentContext extends Context,
|
|
43
|
+
TInputSchema extends AnySchema,
|
|
44
|
+
TOutputSchema extends AnySchema,
|
|
45
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
46
|
+
TMeta extends Meta,
|
|
47
|
+
TRequirementsProvided,
|
|
48
|
+
TRuntimeError,
|
|
49
|
+
> {
|
|
50
|
+
/**
|
|
51
|
+
* This property holds the defined options and the effect-specific properties.
|
|
52
|
+
*/
|
|
53
|
+
"~effect": EffectBuilderDef<
|
|
54
|
+
TInputSchema,
|
|
55
|
+
TOutputSchema,
|
|
56
|
+
TEffectErrorMap,
|
|
57
|
+
TMeta,
|
|
58
|
+
TRequirementsProvided,
|
|
59
|
+
TRuntimeError
|
|
60
|
+
>;
|
|
61
|
+
/**
|
|
62
|
+
* This property holds the defined options.
|
|
63
|
+
*/
|
|
64
|
+
"~orpc": BuilderDef<
|
|
65
|
+
TInputSchema,
|
|
66
|
+
TOutputSchema,
|
|
67
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
68
|
+
TMeta
|
|
69
|
+
>;
|
|
70
|
+
/**
|
|
71
|
+
* Sets or overrides the config.
|
|
72
|
+
*
|
|
73
|
+
* @see {@link https://orpc.dev/docs/client/server-side#middlewares-order Middlewares Order Docs}
|
|
74
|
+
* @see {@link https://orpc.dev/docs/best-practices/dedupe-middleware#configuration Dedupe Middleware Docs}
|
|
75
|
+
*/
|
|
76
|
+
$config(
|
|
77
|
+
config: BuilderConfig,
|
|
78
|
+
): EffectBuilderSurface<
|
|
79
|
+
TInitialContext,
|
|
80
|
+
TCurrentContext,
|
|
81
|
+
TInputSchema,
|
|
82
|
+
TOutputSchema,
|
|
83
|
+
TEffectErrorMap,
|
|
84
|
+
TMeta,
|
|
85
|
+
TRequirementsProvided,
|
|
86
|
+
TRuntimeError
|
|
87
|
+
>;
|
|
88
|
+
/**
|
|
89
|
+
* Set or override the initial context.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://orpc.dev/docs/context Context Docs}
|
|
92
|
+
*/
|
|
93
|
+
$context<U extends Context>(): EffectBuilderSurface<
|
|
94
|
+
U & Record<never, never>,
|
|
95
|
+
U,
|
|
96
|
+
TInputSchema,
|
|
97
|
+
TOutputSchema,
|
|
98
|
+
TEffectErrorMap,
|
|
99
|
+
TMeta,
|
|
100
|
+
TRequirementsProvided,
|
|
101
|
+
TRuntimeError
|
|
102
|
+
>;
|
|
103
|
+
/**
|
|
104
|
+
* Sets or overrides the initial meta.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
107
|
+
*/
|
|
108
|
+
$meta<U extends Meta>(
|
|
109
|
+
initialMeta: U,
|
|
110
|
+
): EffectBuilderSurface<
|
|
111
|
+
TInitialContext,
|
|
112
|
+
TCurrentContext,
|
|
113
|
+
TInputSchema,
|
|
114
|
+
TOutputSchema,
|
|
115
|
+
TEffectErrorMap,
|
|
116
|
+
U & Record<never, never>,
|
|
117
|
+
TRequirementsProvided,
|
|
118
|
+
TRuntimeError
|
|
119
|
+
>;
|
|
120
|
+
/**
|
|
121
|
+
* Sets or overrides the initial route.
|
|
122
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
123
|
+
*
|
|
124
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
125
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
126
|
+
*/
|
|
127
|
+
$route(
|
|
128
|
+
initialRoute: Route,
|
|
129
|
+
): EffectBuilderSurface<
|
|
130
|
+
TInitialContext,
|
|
131
|
+
TCurrentContext,
|
|
132
|
+
TInputSchema,
|
|
133
|
+
TOutputSchema,
|
|
134
|
+
TEffectErrorMap,
|
|
135
|
+
TMeta,
|
|
136
|
+
TRequirementsProvided,
|
|
137
|
+
TRuntimeError
|
|
138
|
+
>;
|
|
139
|
+
/**
|
|
140
|
+
* Sets or overrides the initial input schema.
|
|
141
|
+
*
|
|
142
|
+
* @see {@link https://orpc.dev/docs/procedure#initial-configuration Initial Procedure Configuration Docs}
|
|
143
|
+
*/
|
|
144
|
+
$input<U extends AnySchema>(
|
|
145
|
+
initialInputSchema?: U,
|
|
146
|
+
): EffectBuilderSurface<
|
|
147
|
+
TInitialContext,
|
|
148
|
+
TCurrentContext,
|
|
149
|
+
U,
|
|
150
|
+
TOutputSchema,
|
|
151
|
+
TEffectErrorMap,
|
|
152
|
+
TMeta,
|
|
153
|
+
TRequirementsProvided,
|
|
154
|
+
TRuntimeError
|
|
155
|
+
>;
|
|
156
|
+
/**
|
|
157
|
+
* Creates a middleware.
|
|
158
|
+
*
|
|
159
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
160
|
+
*/
|
|
161
|
+
middleware<
|
|
162
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
163
|
+
TInput,
|
|
164
|
+
TOutput = any,
|
|
165
|
+
>(
|
|
166
|
+
middleware: Middleware<
|
|
167
|
+
TInitialContext,
|
|
168
|
+
UOutContext,
|
|
169
|
+
TInput,
|
|
170
|
+
TOutput,
|
|
171
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
172
|
+
TMeta
|
|
173
|
+
>,
|
|
174
|
+
): DecoratedMiddleware<
|
|
175
|
+
TInitialContext,
|
|
176
|
+
UOutContext,
|
|
177
|
+
TInput,
|
|
178
|
+
TOutput,
|
|
179
|
+
any,
|
|
180
|
+
TMeta
|
|
181
|
+
>;
|
|
182
|
+
/**
|
|
183
|
+
* Adds type-safe custom errors.
|
|
184
|
+
* Supports both traditional oRPC error definitions and ORPCTaggedError classes.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* // Traditional format
|
|
189
|
+
* builder.errors({ BAD_REQUEST: { status: 400, message: 'Bad request' } })
|
|
190
|
+
*
|
|
191
|
+
* // Tagged error class
|
|
192
|
+
* builder.errors({ USER_NOT_FOUND: UserNotFoundError })
|
|
193
|
+
*
|
|
194
|
+
* // Mixed
|
|
195
|
+
* builder.errors({
|
|
196
|
+
* BAD_REQUEST: { status: 400 },
|
|
197
|
+
* USER_NOT_FOUND: UserNotFoundError,
|
|
198
|
+
* })
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
202
|
+
*/
|
|
203
|
+
errors<U extends EffectErrorMap>(
|
|
204
|
+
errors: U,
|
|
205
|
+
): EffectBuilderSurface<
|
|
206
|
+
TInitialContext,
|
|
207
|
+
TCurrentContext,
|
|
208
|
+
TInputSchema,
|
|
209
|
+
TOutputSchema,
|
|
210
|
+
MergedEffectErrorMap<TEffectErrorMap, U>,
|
|
211
|
+
TMeta,
|
|
212
|
+
TRequirementsProvided,
|
|
213
|
+
TRuntimeError
|
|
214
|
+
>;
|
|
215
|
+
/**
|
|
216
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
217
|
+
*
|
|
218
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
219
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
220
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
221
|
+
*/
|
|
222
|
+
use<
|
|
223
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
224
|
+
UInContext extends Context = TCurrentContext,
|
|
225
|
+
>(
|
|
226
|
+
middleware: Middleware<
|
|
227
|
+
UInContext | TCurrentContext,
|
|
228
|
+
UOutContext,
|
|
229
|
+
InferSchemaOutput<TInputSchema>,
|
|
230
|
+
unknown,
|
|
231
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
232
|
+
TMeta
|
|
233
|
+
>,
|
|
234
|
+
): EffectBuilderSurface<
|
|
235
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
236
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
237
|
+
TInputSchema,
|
|
238
|
+
TOutputSchema,
|
|
239
|
+
TEffectErrorMap,
|
|
240
|
+
TMeta,
|
|
241
|
+
TRequirementsProvided,
|
|
242
|
+
TRuntimeError
|
|
243
|
+
>;
|
|
244
|
+
/**
|
|
245
|
+
* Sets or updates the metadata.
|
|
246
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
247
|
+
*
|
|
248
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
249
|
+
*/
|
|
250
|
+
meta(
|
|
251
|
+
meta: TMeta,
|
|
252
|
+
): EffectBuilderSurface<
|
|
253
|
+
TInitialContext,
|
|
254
|
+
TCurrentContext,
|
|
255
|
+
TInputSchema,
|
|
256
|
+
TOutputSchema,
|
|
257
|
+
TEffectErrorMap,
|
|
258
|
+
TMeta,
|
|
259
|
+
TRequirementsProvided,
|
|
260
|
+
TRuntimeError
|
|
261
|
+
>;
|
|
262
|
+
/**
|
|
263
|
+
* Sets or updates the route definition.
|
|
264
|
+
* The provided route is spared-merged with any existing route.
|
|
265
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
266
|
+
*
|
|
267
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
268
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
269
|
+
*/
|
|
270
|
+
route(
|
|
271
|
+
route: Route,
|
|
272
|
+
): EffectBuilderSurface<
|
|
273
|
+
TInitialContext,
|
|
274
|
+
TCurrentContext,
|
|
275
|
+
TInputSchema,
|
|
276
|
+
TOutputSchema,
|
|
277
|
+
TEffectErrorMap,
|
|
278
|
+
TMeta,
|
|
279
|
+
TRequirementsProvided,
|
|
280
|
+
TRuntimeError
|
|
281
|
+
>;
|
|
282
|
+
/**
|
|
283
|
+
* Defines the input validation schema.
|
|
284
|
+
*
|
|
285
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Input Validation Docs}
|
|
286
|
+
*/
|
|
287
|
+
input<USchema extends AnySchema>(
|
|
288
|
+
schema: USchema,
|
|
289
|
+
): EffectProcedureBuilderWithInput<
|
|
290
|
+
TInitialContext,
|
|
291
|
+
TCurrentContext,
|
|
292
|
+
USchema,
|
|
293
|
+
TOutputSchema,
|
|
294
|
+
TEffectErrorMap,
|
|
295
|
+
TMeta,
|
|
296
|
+
TRequirementsProvided,
|
|
297
|
+
TRuntimeError
|
|
298
|
+
>;
|
|
299
|
+
/**
|
|
300
|
+
* Defines the output validation schema.
|
|
301
|
+
*
|
|
302
|
+
* @see {@link https://orpc.dev/docs/procedure#input-output-validation Output Validation Docs}
|
|
303
|
+
*/
|
|
304
|
+
output<USchema extends AnySchema>(
|
|
305
|
+
schema: USchema,
|
|
306
|
+
): EffectProcedureBuilderWithOutput<
|
|
307
|
+
TInitialContext,
|
|
308
|
+
TCurrentContext,
|
|
309
|
+
TInputSchema,
|
|
310
|
+
USchema,
|
|
311
|
+
TEffectErrorMap,
|
|
312
|
+
TMeta,
|
|
313
|
+
TRequirementsProvided,
|
|
314
|
+
TRuntimeError
|
|
315
|
+
>;
|
|
316
|
+
/**
|
|
317
|
+
* Adds a traceable span to the procedure for telemetry.
|
|
318
|
+
* The span name is used for Effect tracing via `Effect.withSpan`.
|
|
319
|
+
* Stack trace is captured at the call site for better error reporting.
|
|
320
|
+
*
|
|
321
|
+
* @param spanName - The name of the span for telemetry (e.g., 'users.getUser')
|
|
322
|
+
* @returns An EffectBuilder with span tracing configured
|
|
323
|
+
*/
|
|
324
|
+
traced(
|
|
325
|
+
spanName: string,
|
|
326
|
+
): EffectBuilderSurface<
|
|
327
|
+
TInitialContext,
|
|
328
|
+
TCurrentContext,
|
|
329
|
+
TInputSchema,
|
|
330
|
+
TOutputSchema,
|
|
331
|
+
TEffectErrorMap,
|
|
332
|
+
TMeta,
|
|
333
|
+
TRequirementsProvided,
|
|
334
|
+
TRuntimeError
|
|
335
|
+
>;
|
|
336
|
+
/**
|
|
337
|
+
* Defines the handler of the procedure using a standard async/sync function.
|
|
338
|
+
*
|
|
339
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
340
|
+
*/
|
|
341
|
+
handler<UFuncOutput>(
|
|
342
|
+
handler: ProcedureHandler<
|
|
343
|
+
TCurrentContext,
|
|
344
|
+
InferSchemaOutput<TInputSchema>,
|
|
345
|
+
UFuncOutput,
|
|
346
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
347
|
+
TMeta
|
|
348
|
+
>,
|
|
349
|
+
): EffectDecoratedProcedure<
|
|
350
|
+
TInitialContext,
|
|
351
|
+
TCurrentContext,
|
|
352
|
+
TInputSchema,
|
|
353
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
354
|
+
TEffectErrorMap,
|
|
355
|
+
TMeta,
|
|
356
|
+
TRequirementsProvided,
|
|
357
|
+
TRuntimeError
|
|
358
|
+
>;
|
|
359
|
+
/**
|
|
360
|
+
* Defines the handler of the procedure using an Effect.
|
|
361
|
+
* The Effect is executed using the ManagedRuntime provided during builder creation.
|
|
362
|
+
* The effect is automatically wrapped with `Effect.withSpan`.
|
|
363
|
+
*
|
|
364
|
+
* @see {@link https://orpc.dev/docs/procedure Procedure Docs}
|
|
365
|
+
*/
|
|
366
|
+
effect<UFuncOutput>(
|
|
367
|
+
effectFn: EffectProcedureHandler<
|
|
368
|
+
TCurrentContext,
|
|
369
|
+
TInputSchema,
|
|
370
|
+
UFuncOutput,
|
|
371
|
+
TEffectErrorMap,
|
|
372
|
+
TRequirementsProvided,
|
|
373
|
+
TMeta
|
|
374
|
+
>,
|
|
375
|
+
): EffectDecoratedProcedure<
|
|
376
|
+
TInitialContext,
|
|
377
|
+
TCurrentContext,
|
|
378
|
+
TInputSchema,
|
|
379
|
+
Schema<UFuncOutput, UFuncOutput>,
|
|
380
|
+
TEffectErrorMap,
|
|
381
|
+
TMeta,
|
|
382
|
+
TRequirementsProvided,
|
|
383
|
+
TRuntimeError
|
|
384
|
+
>;
|
|
385
|
+
/**
|
|
386
|
+
* Prefixes all procedures in the router.
|
|
387
|
+
* The provided prefix is post-appended to any existing router prefix.
|
|
388
|
+
*
|
|
389
|
+
* @note This option does not affect procedures that do not define a path in their route definition.
|
|
390
|
+
*
|
|
391
|
+
* @see {@link https://orpc.dev/docs/openapi/routing#route-prefixes OpenAPI Route Prefixes Docs}
|
|
392
|
+
*/
|
|
393
|
+
prefix(
|
|
394
|
+
prefix: HTTPPath,
|
|
395
|
+
): EffectRouterBuilder<
|
|
396
|
+
TInitialContext,
|
|
397
|
+
TCurrentContext,
|
|
398
|
+
TEffectErrorMap,
|
|
399
|
+
TMeta,
|
|
400
|
+
TRequirementsProvided,
|
|
401
|
+
TRuntimeError
|
|
402
|
+
>;
|
|
403
|
+
/**
|
|
404
|
+
* Adds tags to all procedures in the router.
|
|
405
|
+
* This helpful when you want to group procedures together in the OpenAPI specification.
|
|
406
|
+
*
|
|
407
|
+
* @see {@link https://orpc.dev/docs/openapi/openapi-specification#operation-metadata OpenAPI Operation Metadata Docs}
|
|
408
|
+
*/
|
|
409
|
+
tag(
|
|
410
|
+
...tags: string[]
|
|
411
|
+
): EffectRouterBuilder<
|
|
412
|
+
TInitialContext,
|
|
413
|
+
TCurrentContext,
|
|
414
|
+
TEffectErrorMap,
|
|
415
|
+
TMeta,
|
|
416
|
+
TRequirementsProvided,
|
|
417
|
+
TRuntimeError
|
|
418
|
+
>;
|
|
419
|
+
/**
|
|
420
|
+
* Applies all of the previously defined options to the specified router.
|
|
421
|
+
*
|
|
422
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
423
|
+
*/
|
|
424
|
+
router<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
|
|
425
|
+
router: U,
|
|
426
|
+
): EnhancedEffectRouter<U, TInitialContext, TCurrentContext, TEffectErrorMap>;
|
|
427
|
+
/**
|
|
428
|
+
* Create a lazy router
|
|
429
|
+
* And applies all of the previously defined options to the specified router.
|
|
430
|
+
*
|
|
431
|
+
* @see {@link https://orpc.dev/docs/router#extending-router Extending Router Docs}
|
|
432
|
+
*/
|
|
433
|
+
lazy<U extends Router<ContractRouter<TMeta>, TCurrentContext>>(
|
|
434
|
+
loader: () => Promise<{ default: U }>,
|
|
435
|
+
): EnhancedEffectRouter<
|
|
436
|
+
Lazy<U>,
|
|
437
|
+
TInitialContext,
|
|
438
|
+
TCurrentContext,
|
|
439
|
+
TEffectErrorMap
|
|
440
|
+
>;
|
|
441
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type { ClientContext } from "@orpc/client";
|
|
2
|
+
import type {
|
|
3
|
+
AnySchema,
|
|
4
|
+
InferSchemaInput,
|
|
5
|
+
InferSchemaOutput,
|
|
6
|
+
Meta,
|
|
7
|
+
Route,
|
|
8
|
+
} from "@orpc/contract";
|
|
9
|
+
import type {
|
|
10
|
+
Context,
|
|
11
|
+
CreateProcedureClientOptions,
|
|
12
|
+
MapInputMiddleware,
|
|
13
|
+
MergedCurrentContext,
|
|
14
|
+
MergedInitialContext,
|
|
15
|
+
Middleware,
|
|
16
|
+
ProcedureActionableClient,
|
|
17
|
+
ProcedureClient,
|
|
18
|
+
ProcedureDef,
|
|
19
|
+
} from "@orpc/server";
|
|
20
|
+
import type { IntersectPick, MaybeOptionalOptions } from "@orpc/shared";
|
|
21
|
+
|
|
22
|
+
import type { EffectProcedureDef, EffectErrorMapToErrorMap } from ".";
|
|
23
|
+
import type { EffectDecoratedProcedure } from "../effect-procedure";
|
|
24
|
+
import type {
|
|
25
|
+
EffectErrorConstructorMap,
|
|
26
|
+
EffectErrorMap,
|
|
27
|
+
MergedEffectErrorMap,
|
|
28
|
+
} from "../tagged-error";
|
|
29
|
+
|
|
30
|
+
export interface EffectDecoratedProcedureSurface<
|
|
31
|
+
TInitialContext extends Context,
|
|
32
|
+
TCurrentContext extends Context,
|
|
33
|
+
TInputSchema extends AnySchema,
|
|
34
|
+
TOutputSchema extends AnySchema,
|
|
35
|
+
TEffectErrorMap extends EffectErrorMap,
|
|
36
|
+
TMeta extends Meta,
|
|
37
|
+
TRequirementsProvided,
|
|
38
|
+
TRuntimeError,
|
|
39
|
+
> {
|
|
40
|
+
/**
|
|
41
|
+
* This property holds the defined options and the effect-specific properties.
|
|
42
|
+
*/
|
|
43
|
+
"~effect": EffectProcedureDef<
|
|
44
|
+
TInitialContext,
|
|
45
|
+
TCurrentContext,
|
|
46
|
+
TInputSchema,
|
|
47
|
+
TOutputSchema,
|
|
48
|
+
TEffectErrorMap,
|
|
49
|
+
TMeta,
|
|
50
|
+
TRequirementsProvided,
|
|
51
|
+
TRuntimeError
|
|
52
|
+
>;
|
|
53
|
+
/**
|
|
54
|
+
* This property holds the defined options.
|
|
55
|
+
*/
|
|
56
|
+
"~orpc": ProcedureDef<
|
|
57
|
+
TInitialContext,
|
|
58
|
+
TCurrentContext,
|
|
59
|
+
TInputSchema,
|
|
60
|
+
TOutputSchema,
|
|
61
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
62
|
+
TMeta
|
|
63
|
+
>;
|
|
64
|
+
/**
|
|
65
|
+
* Adds type-safe custom errors.
|
|
66
|
+
* Supports both traditional oRPC error definitions and ORPCTaggedError classes.
|
|
67
|
+
*
|
|
68
|
+
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
69
|
+
*/
|
|
70
|
+
errors<U extends EffectErrorMap>(
|
|
71
|
+
errors: U,
|
|
72
|
+
): EffectDecoratedProcedure<
|
|
73
|
+
TInitialContext,
|
|
74
|
+
TCurrentContext,
|
|
75
|
+
TInputSchema,
|
|
76
|
+
TOutputSchema,
|
|
77
|
+
MergedEffectErrorMap<TEffectErrorMap, U>,
|
|
78
|
+
TMeta,
|
|
79
|
+
TRequirementsProvided,
|
|
80
|
+
TRuntimeError
|
|
81
|
+
>;
|
|
82
|
+
/**
|
|
83
|
+
* Sets or updates the metadata.
|
|
84
|
+
* The provided metadata is spared-merged with any existing metadata.
|
|
85
|
+
*
|
|
86
|
+
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
87
|
+
*/
|
|
88
|
+
meta(
|
|
89
|
+
meta: TMeta,
|
|
90
|
+
): EffectDecoratedProcedure<
|
|
91
|
+
TInitialContext,
|
|
92
|
+
TCurrentContext,
|
|
93
|
+
TInputSchema,
|
|
94
|
+
TOutputSchema,
|
|
95
|
+
TEffectErrorMap,
|
|
96
|
+
TMeta,
|
|
97
|
+
TRequirementsProvided,
|
|
98
|
+
TRuntimeError
|
|
99
|
+
>;
|
|
100
|
+
/**
|
|
101
|
+
* Sets or updates the route definition.
|
|
102
|
+
* The provided route is spared-merged with any existing route.
|
|
103
|
+
* This option is typically relevant when integrating with OpenAPI.
|
|
104
|
+
*
|
|
105
|
+
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
106
|
+
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
107
|
+
*/
|
|
108
|
+
route(
|
|
109
|
+
route: Route,
|
|
110
|
+
): EffectDecoratedProcedure<
|
|
111
|
+
TInitialContext,
|
|
112
|
+
TCurrentContext,
|
|
113
|
+
TInputSchema,
|
|
114
|
+
TOutputSchema,
|
|
115
|
+
TEffectErrorMap,
|
|
116
|
+
TMeta,
|
|
117
|
+
TRequirementsProvided,
|
|
118
|
+
TRuntimeError
|
|
119
|
+
>;
|
|
120
|
+
/**
|
|
121
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
122
|
+
*
|
|
123
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
124
|
+
* @info Pass second argument to map the input.
|
|
125
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
126
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
127
|
+
*/
|
|
128
|
+
use<
|
|
129
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
130
|
+
UInContext extends Context = TCurrentContext,
|
|
131
|
+
>(
|
|
132
|
+
middleware: Middleware<
|
|
133
|
+
UInContext | TCurrentContext,
|
|
134
|
+
UOutContext,
|
|
135
|
+
InferSchemaOutput<TInputSchema>,
|
|
136
|
+
InferSchemaInput<TOutputSchema>,
|
|
137
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
138
|
+
TMeta
|
|
139
|
+
>,
|
|
140
|
+
): EffectDecoratedProcedure<
|
|
141
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
142
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
143
|
+
TInputSchema,
|
|
144
|
+
TOutputSchema,
|
|
145
|
+
TEffectErrorMap,
|
|
146
|
+
TMeta,
|
|
147
|
+
TRequirementsProvided,
|
|
148
|
+
TRuntimeError
|
|
149
|
+
>;
|
|
150
|
+
/**
|
|
151
|
+
* Uses a middleware to modify the context or improve the pipeline.
|
|
152
|
+
*
|
|
153
|
+
* @info Supports both normal middleware and inline middleware implementations.
|
|
154
|
+
* @info Pass second argument to map the input.
|
|
155
|
+
* @note The current context must be satisfy middleware dependent-context
|
|
156
|
+
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
157
|
+
*/
|
|
158
|
+
use<
|
|
159
|
+
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
160
|
+
UInput,
|
|
161
|
+
UInContext extends Context = TCurrentContext,
|
|
162
|
+
>(
|
|
163
|
+
middleware: Middleware<
|
|
164
|
+
UInContext | TCurrentContext,
|
|
165
|
+
UOutContext,
|
|
166
|
+
UInput,
|
|
167
|
+
InferSchemaInput<TOutputSchema>,
|
|
168
|
+
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
169
|
+
TMeta
|
|
170
|
+
>,
|
|
171
|
+
mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,
|
|
172
|
+
): EffectDecoratedProcedure<
|
|
173
|
+
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
174
|
+
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
175
|
+
TInputSchema,
|
|
176
|
+
TOutputSchema,
|
|
177
|
+
TEffectErrorMap,
|
|
178
|
+
TMeta,
|
|
179
|
+
TRequirementsProvided,
|
|
180
|
+
TRuntimeError
|
|
181
|
+
>;
|
|
182
|
+
/**
|
|
183
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
|
184
|
+
*
|
|
185
|
+
* @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
|
|
186
|
+
*/
|
|
187
|
+
callable<TClientContext extends ClientContext>(
|
|
188
|
+
...rest: MaybeOptionalOptions<
|
|
189
|
+
CreateProcedureClientOptions<
|
|
190
|
+
TInitialContext,
|
|
191
|
+
TOutputSchema,
|
|
192
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
193
|
+
TMeta,
|
|
194
|
+
TClientContext
|
|
195
|
+
>
|
|
196
|
+
>
|
|
197
|
+
): EffectDecoratedProcedure<
|
|
198
|
+
TInitialContext,
|
|
199
|
+
TCurrentContext,
|
|
200
|
+
TInputSchema,
|
|
201
|
+
TOutputSchema,
|
|
202
|
+
TEffectErrorMap,
|
|
203
|
+
TMeta,
|
|
204
|
+
TRequirementsProvided,
|
|
205
|
+
TRuntimeError
|
|
206
|
+
> &
|
|
207
|
+
ProcedureClient<
|
|
208
|
+
TClientContext,
|
|
209
|
+
TInputSchema,
|
|
210
|
+
TOutputSchema,
|
|
211
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>
|
|
212
|
+
>;
|
|
213
|
+
/**
|
|
214
|
+
* Make this procedure compatible with server action.
|
|
215
|
+
*
|
|
216
|
+
* @see {@link https://orpc.dev/docs/server-action Server Action Docs}
|
|
217
|
+
*/
|
|
218
|
+
actionable(
|
|
219
|
+
...rest: MaybeOptionalOptions<
|
|
220
|
+
CreateProcedureClientOptions<
|
|
221
|
+
TInitialContext,
|
|
222
|
+
TOutputSchema,
|
|
223
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
224
|
+
TMeta,
|
|
225
|
+
Record<never, never>
|
|
226
|
+
>
|
|
227
|
+
>
|
|
228
|
+
): EffectDecoratedProcedure<
|
|
229
|
+
TInitialContext,
|
|
230
|
+
TCurrentContext,
|
|
231
|
+
TInputSchema,
|
|
232
|
+
TOutputSchema,
|
|
233
|
+
TEffectErrorMap,
|
|
234
|
+
TMeta,
|
|
235
|
+
TRequirementsProvided,
|
|
236
|
+
TRuntimeError
|
|
237
|
+
> &
|
|
238
|
+
ProcedureActionableClient<
|
|
239
|
+
TInputSchema,
|
|
240
|
+
TOutputSchema,
|
|
241
|
+
EffectErrorMapToErrorMap<TEffectErrorMap>
|
|
242
|
+
>;
|
|
243
|
+
}
|