effect-orpc 0.2.0 → 0.2.2
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/dist/index.js +472 -422
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/effect-builder.ts +365 -406
- package/src/effect-enhance-router.ts +20 -21
- package/src/effect-procedure.ts +274 -219
- 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 +2 -0
- package/src/tests/effect-builder.proxy.test.ts +253 -0
- package/src/tests/parity.effect-builder.test.ts +17 -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 -10
- package/src/types/variants.ts +75 -0
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import type { ManagedRuntime } from "effect/ManagedRuntime";
|
|
20
20
|
|
|
21
21
|
import { EffectProcedure } from "./effect-procedure";
|
|
22
|
+
import { getEffectErrorMap, unwrapEffectUpstream } from "./extension/state";
|
|
22
23
|
import { effectErrorMapToErrorMap, type EffectErrorMap } from "./tagged-error";
|
|
23
24
|
import type { EffectErrorMapToErrorMap, EnhancedEffectRouter } from "./types";
|
|
24
25
|
|
|
@@ -51,14 +52,14 @@ export function enhanceEffectRouter<
|
|
|
51
52
|
if (isLazy(router)) {
|
|
52
53
|
const laziedMeta = getLazyMeta(router);
|
|
53
54
|
const enhancedPrefix = laziedMeta?.prefix
|
|
54
|
-
? mergePrefix(options.prefix, laziedMeta
|
|
55
|
+
? mergePrefix(options.prefix, laziedMeta.prefix)
|
|
55
56
|
: options.prefix;
|
|
56
57
|
|
|
57
58
|
const enhanced = lazy(
|
|
58
59
|
async () => {
|
|
59
60
|
const { default: unlaziedRouter } = await unlazy(router);
|
|
60
|
-
const
|
|
61
|
-
return unlazy(
|
|
61
|
+
const wrappedRouter = enhanceEffectRouter(unlaziedRouter, options);
|
|
62
|
+
return unlazy(wrappedRouter);
|
|
62
63
|
},
|
|
63
64
|
{
|
|
64
65
|
...laziedMeta,
|
|
@@ -66,43 +67,41 @@ export function enhanceEffectRouter<
|
|
|
66
67
|
},
|
|
67
68
|
);
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return accessible as any;
|
|
70
|
+
return createAccessibleLazyRouter(enhanced) as any;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
if (isProcedure(router)) {
|
|
75
|
-
const
|
|
74
|
+
const source = unwrapEffectUpstream(router);
|
|
75
|
+
const sourceEffectErrorMap = getEffectErrorMap(router);
|
|
76
|
+
const middlewares = mergeMiddlewares(
|
|
76
77
|
options.middlewares,
|
|
77
|
-
|
|
78
|
+
source["~orpc"].middlewares,
|
|
78
79
|
{ dedupeLeading: options.dedupeLeadingMiddlewares },
|
|
79
80
|
);
|
|
80
81
|
const newMiddlewareAdded =
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
middlewares.length - source["~orpc"].middlewares.length;
|
|
83
83
|
const effectErrorMap = {
|
|
84
84
|
...options.errorMap,
|
|
85
|
-
...
|
|
85
|
+
...sourceEffectErrorMap,
|
|
86
86
|
};
|
|
87
87
|
const errorMap: EffectErrorMapToErrorMap<typeof effectErrorMap> =
|
|
88
88
|
effectErrorMapToErrorMap(effectErrorMap);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
|
|
90
|
+
return new EffectProcedure({
|
|
91
|
+
...source["~orpc"],
|
|
92
|
+
route: enhanceRoute(source["~orpc"].route, options),
|
|
92
93
|
effectErrorMap,
|
|
93
94
|
errorMap: errorMap as EffectErrorMapToErrorMap<typeof effectErrorMap>,
|
|
94
|
-
middlewares
|
|
95
|
+
middlewares,
|
|
95
96
|
inputValidationIndex:
|
|
96
|
-
|
|
97
|
+
source["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
97
98
|
outputValidationIndex:
|
|
98
|
-
|
|
99
|
+
source["~orpc"].outputValidationIndex + newMiddlewareAdded,
|
|
99
100
|
runtime: options.runtime,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return enhanced as any;
|
|
101
|
+
}) as any;
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
const enhanced
|
|
104
|
+
const enhanced: Record<string, any> = {};
|
|
106
105
|
|
|
107
106
|
for (const key in router) {
|
|
108
107
|
enhanced[key] = enhanceEffectRouter(router[key]!, options);
|
package/src/effect-procedure.ts
CHANGED
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import type { ClientContext } from "@orpc/client";
|
|
2
|
-
import type {
|
|
3
|
-
AnySchema,
|
|
4
|
-
InferSchemaInput,
|
|
5
|
-
InferSchemaOutput,
|
|
6
|
-
Meta,
|
|
7
|
-
Route,
|
|
8
|
-
} from "@orpc/contract";
|
|
2
|
+
import type { AnySchema, Meta, Route } from "@orpc/contract";
|
|
9
3
|
import { mergeMeta, mergeRoute } from "@orpc/contract";
|
|
10
4
|
import type {
|
|
11
5
|
AnyMiddleware,
|
|
12
6
|
Context,
|
|
13
7
|
CreateProcedureClientOptions,
|
|
14
8
|
MapInputMiddleware,
|
|
15
|
-
MergedCurrentContext,
|
|
16
|
-
MergedInitialContext,
|
|
17
|
-
Middleware,
|
|
18
|
-
ProcedureActionableClient,
|
|
19
|
-
ProcedureClient,
|
|
20
9
|
ProcedureDef,
|
|
21
10
|
} from "@orpc/server";
|
|
22
11
|
import {
|
|
@@ -26,16 +15,238 @@ import {
|
|
|
26
15
|
decorateMiddleware,
|
|
27
16
|
Procedure,
|
|
28
17
|
} from "@orpc/server";
|
|
29
|
-
import type {
|
|
18
|
+
import type { MaybeOptionalOptions } from "@orpc/shared";
|
|
30
19
|
|
|
31
|
-
import
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
import { composeSurfaceProxy } from "./extension/compose-surfaces";
|
|
21
|
+
import {
|
|
22
|
+
createNodeProxy,
|
|
23
|
+
unhandled,
|
|
24
|
+
type NodeProxyContext,
|
|
25
|
+
} from "./extension/create-node-proxy";
|
|
26
|
+
import {
|
|
27
|
+
assertEffectState,
|
|
28
|
+
attachEffectState,
|
|
29
|
+
type EffectProxyTarget,
|
|
30
|
+
} from "./extension/state";
|
|
31
|
+
import type { EffectErrorMap, MergedEffectErrorMap } from "./tagged-error";
|
|
36
32
|
import { effectErrorMapToErrorMap } from "./tagged-error";
|
|
37
33
|
import type { EffectErrorMapToErrorMap, EffectProcedureDef } from "./types";
|
|
34
|
+
import type { EffectDecoratedProcedureSurface } from "./types/effect-procedure-surface";
|
|
35
|
+
|
|
36
|
+
type AnyProcedureLike = Procedure<any, any, any, any, any, any>;
|
|
37
|
+
type AnyEffectProcedure = EffectProcedure<
|
|
38
|
+
any,
|
|
39
|
+
any,
|
|
40
|
+
any,
|
|
41
|
+
any,
|
|
42
|
+
any,
|
|
43
|
+
any,
|
|
44
|
+
any,
|
|
45
|
+
any
|
|
46
|
+
>;
|
|
47
|
+
type AnyEffectDecoratedProcedure = EffectDecoratedProcedure<
|
|
48
|
+
any,
|
|
49
|
+
any,
|
|
50
|
+
any,
|
|
51
|
+
any,
|
|
52
|
+
any,
|
|
53
|
+
any,
|
|
54
|
+
any,
|
|
55
|
+
any
|
|
56
|
+
>;
|
|
57
|
+
type EffectProcedureTarget<
|
|
58
|
+
T extends AnyEffectProcedure | AnyEffectDecoratedProcedure =
|
|
59
|
+
| AnyEffectProcedure
|
|
60
|
+
| AnyEffectDecoratedProcedure,
|
|
61
|
+
> = T & EffectProxyTarget<AnyProcedureLike>;
|
|
62
|
+
|
|
63
|
+
const procedureVirtualDescriptors = {
|
|
64
|
+
"~effect": { enumerable: true },
|
|
65
|
+
actionable: { enumerable: false },
|
|
66
|
+
callable: { enumerable: false },
|
|
67
|
+
errors: { enumerable: false },
|
|
68
|
+
meta: { enumerable: false },
|
|
69
|
+
route: { enumerable: false },
|
|
70
|
+
use: { enumerable: false },
|
|
71
|
+
} as const;
|
|
72
|
+
|
|
73
|
+
const baseProcedureVirtualKeys = ["~effect"] as const;
|
|
74
|
+
const decoratedProcedureVirtualKeys = [
|
|
75
|
+
...baseProcedureVirtualKeys,
|
|
76
|
+
"errors",
|
|
77
|
+
"meta",
|
|
78
|
+
"route",
|
|
79
|
+
"use",
|
|
80
|
+
"callable",
|
|
81
|
+
"actionable",
|
|
82
|
+
] as const;
|
|
83
|
+
|
|
84
|
+
function getOrCreateVirtualMethod<T>(
|
|
85
|
+
context: NodeProxyContext<EffectProcedureTarget, AnyProcedureLike>,
|
|
86
|
+
prop: PropertyKey,
|
|
87
|
+
factory: () => T,
|
|
88
|
+
): T {
|
|
89
|
+
const cache = context.methodCache;
|
|
90
|
+
if (cache.has(prop)) {
|
|
91
|
+
return cache.get(prop) as T;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const value = factory();
|
|
95
|
+
cache.set(prop, value);
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getEffectProcedureDef(
|
|
100
|
+
context: NodeProxyContext<EffectProcedureTarget, AnyProcedureLike>,
|
|
101
|
+
): EffectProcedureDef<any, any, any, any, any, any, any, any> {
|
|
102
|
+
return {
|
|
103
|
+
...context.upstream["~orpc"],
|
|
104
|
+
effectErrorMap: context.state.effectErrorMap,
|
|
105
|
+
runtime: context.state.runtime,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function createEffectProcedureProxy<
|
|
110
|
+
T extends AnyEffectProcedure | AnyEffectDecoratedProcedure,
|
|
111
|
+
>(
|
|
112
|
+
target: EffectProcedureTarget<T>,
|
|
113
|
+
decorated: boolean,
|
|
114
|
+
): EffectProcedureTarget<T> {
|
|
115
|
+
return createNodeProxy<EffectProcedureTarget<T>, AnyProcedureLike>(target, {
|
|
116
|
+
getVirtual(context, prop, receiver) {
|
|
117
|
+
if (prop === "~effect") {
|
|
118
|
+
return getEffectProcedureDef(context);
|
|
119
|
+
}
|
|
38
120
|
|
|
121
|
+
if (!decorated) {
|
|
122
|
+
return unhandled();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const state = context.state;
|
|
126
|
+
|
|
127
|
+
switch (prop) {
|
|
128
|
+
case "errors":
|
|
129
|
+
return getOrCreateVirtualMethod(context, prop, () => {
|
|
130
|
+
return <U extends EffectErrorMap>(errors: U) => {
|
|
131
|
+
const nextEffectErrorMap: MergedEffectErrorMap<
|
|
132
|
+
typeof state.effectErrorMap,
|
|
133
|
+
U
|
|
134
|
+
> = {
|
|
135
|
+
...state.effectErrorMap,
|
|
136
|
+
...errors,
|
|
137
|
+
};
|
|
138
|
+
return new EffectDecoratedProcedure({
|
|
139
|
+
...getEffectProcedureDef(context),
|
|
140
|
+
effectErrorMap: nextEffectErrorMap,
|
|
141
|
+
errorMap: effectErrorMapToErrorMap(nextEffectErrorMap),
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
case "meta":
|
|
146
|
+
return getOrCreateVirtualMethod(context, prop, () => {
|
|
147
|
+
return (meta: Meta) =>
|
|
148
|
+
new EffectDecoratedProcedure({
|
|
149
|
+
...getEffectProcedureDef(context),
|
|
150
|
+
meta: mergeMeta(getEffectProcedureDef(context).meta, meta),
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
case "route":
|
|
154
|
+
return getOrCreateVirtualMethod(context, prop, () => {
|
|
155
|
+
return (route: Route) =>
|
|
156
|
+
new EffectDecoratedProcedure({
|
|
157
|
+
...getEffectProcedureDef(context),
|
|
158
|
+
route: mergeRoute(getEffectProcedureDef(context).route, route),
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
case "use":
|
|
162
|
+
return getOrCreateVirtualMethod(context, prop, () => {
|
|
163
|
+
return (
|
|
164
|
+
middleware: AnyMiddleware,
|
|
165
|
+
mapInput?: MapInputMiddleware<any, any>,
|
|
166
|
+
) => {
|
|
167
|
+
const mapped = mapInput
|
|
168
|
+
? decorateMiddleware(middleware).mapInput(mapInput)
|
|
169
|
+
: middleware;
|
|
170
|
+
|
|
171
|
+
return new EffectDecoratedProcedure({
|
|
172
|
+
...getEffectProcedureDef(context),
|
|
173
|
+
middlewares: addMiddleware(
|
|
174
|
+
getEffectProcedureDef(context).middlewares,
|
|
175
|
+
mapped,
|
|
176
|
+
),
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
case "callable":
|
|
181
|
+
return <TClientContext extends ClientContext>(
|
|
182
|
+
...rest: MaybeOptionalOptions<
|
|
183
|
+
CreateProcedureClientOptions<any, any, any, any, TClientContext>
|
|
184
|
+
>
|
|
185
|
+
) => {
|
|
186
|
+
const client = createProcedureClient(
|
|
187
|
+
receiver as AnyProcedureLike,
|
|
188
|
+
...rest,
|
|
189
|
+
);
|
|
190
|
+
return composeSurfaceProxy(
|
|
191
|
+
receiver as EffectDecoratedProcedure<
|
|
192
|
+
any,
|
|
193
|
+
any,
|
|
194
|
+
any,
|
|
195
|
+
any,
|
|
196
|
+
any,
|
|
197
|
+
any,
|
|
198
|
+
any,
|
|
199
|
+
any
|
|
200
|
+
>,
|
|
201
|
+
client,
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
case "actionable":
|
|
205
|
+
return (
|
|
206
|
+
...rest: MaybeOptionalOptions<
|
|
207
|
+
CreateProcedureClientOptions<
|
|
208
|
+
any,
|
|
209
|
+
any,
|
|
210
|
+
any,
|
|
211
|
+
any,
|
|
212
|
+
Record<never, never>
|
|
213
|
+
>
|
|
214
|
+
>
|
|
215
|
+
) => {
|
|
216
|
+
const client = createProcedureClient(
|
|
217
|
+
receiver as AnyProcedureLike,
|
|
218
|
+
...rest,
|
|
219
|
+
);
|
|
220
|
+
const action = createActionableClient(client);
|
|
221
|
+
return composeSurfaceProxy(
|
|
222
|
+
receiver as EffectDecoratedProcedure<
|
|
223
|
+
any,
|
|
224
|
+
any,
|
|
225
|
+
any,
|
|
226
|
+
any,
|
|
227
|
+
any,
|
|
228
|
+
any,
|
|
229
|
+
any,
|
|
230
|
+
any
|
|
231
|
+
>,
|
|
232
|
+
action,
|
|
233
|
+
);
|
|
234
|
+
};
|
|
235
|
+
default:
|
|
236
|
+
return unhandled();
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
virtualDescriptors: procedureVirtualDescriptors,
|
|
240
|
+
virtualKeys: decorated
|
|
241
|
+
? decoratedProcedureVirtualKeys
|
|
242
|
+
: baseProcedureVirtualKeys,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Effect-aware base procedure that carries the upstream procedure definition
|
|
248
|
+
* together with Effect runtime and error metadata.
|
|
249
|
+
*/
|
|
39
250
|
export class EffectProcedure<
|
|
40
251
|
TInitialContext extends Context,
|
|
41
252
|
TCurrentContext extends Context,
|
|
@@ -89,9 +300,17 @@ export class EffectProcedure<
|
|
|
89
300
|
TRequirementsProvided,
|
|
90
301
|
TRuntimeError
|
|
91
302
|
>,
|
|
303
|
+
procedure?: AnyProcedureLike,
|
|
92
304
|
) {
|
|
93
305
|
super(def);
|
|
94
|
-
this
|
|
306
|
+
attachEffectState(this, procedure ?? new Procedure(def), {
|
|
307
|
+
effectErrorMap: def.effectErrorMap,
|
|
308
|
+
runtime: def.runtime,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
if (new.target === EffectProcedure) {
|
|
312
|
+
return createEffectProcedureProxy(this, false);
|
|
313
|
+
}
|
|
95
314
|
}
|
|
96
315
|
}
|
|
97
316
|
|
|
@@ -110,20 +329,8 @@ export class EffectDecoratedProcedure<
|
|
|
110
329
|
TMeta extends Meta,
|
|
111
330
|
TRequirementsProvided,
|
|
112
331
|
TRuntimeError,
|
|
113
|
-
>
|
|
114
|
-
|
|
115
|
-
TCurrentContext,
|
|
116
|
-
TInputSchema,
|
|
117
|
-
TOutputSchema,
|
|
118
|
-
TEffectErrorMap,
|
|
119
|
-
TMeta,
|
|
120
|
-
TRequirementsProvided,
|
|
121
|
-
TRuntimeError
|
|
122
|
-
> {
|
|
123
|
-
/**
|
|
124
|
-
* This property holds the defined options and the effect-specific properties.
|
|
125
|
-
*/
|
|
126
|
-
declare "~effect": EffectProcedureDef<
|
|
332
|
+
>
|
|
333
|
+
extends EffectProcedure<
|
|
127
334
|
TInitialContext,
|
|
128
335
|
TCurrentContext,
|
|
129
336
|
TInputSchema,
|
|
@@ -132,18 +339,9 @@ export class EffectDecoratedProcedure<
|
|
|
132
339
|
TMeta,
|
|
133
340
|
TRequirementsProvided,
|
|
134
341
|
TRuntimeError
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
TCurrentContext,
|
|
139
|
-
TInputSchema,
|
|
140
|
-
TOutputSchema,
|
|
141
|
-
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
142
|
-
TMeta
|
|
143
|
-
>;
|
|
144
|
-
|
|
145
|
-
constructor(
|
|
146
|
-
def: EffectProcedureDef<
|
|
342
|
+
>
|
|
343
|
+
implements
|
|
344
|
+
EffectDecoratedProcedureSurface<
|
|
147
345
|
TInitialContext,
|
|
148
346
|
TCurrentContext,
|
|
149
347
|
TInputSchema,
|
|
@@ -152,50 +350,31 @@ export class EffectDecoratedProcedure<
|
|
|
152
350
|
TMeta,
|
|
153
351
|
TRequirementsProvided,
|
|
154
352
|
TRuntimeError
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
super(def);
|
|
158
|
-
this["~effect"] = def;
|
|
159
|
-
}
|
|
160
|
-
|
|
353
|
+
>
|
|
354
|
+
{
|
|
161
355
|
/**
|
|
162
356
|
* Adds type-safe custom errors.
|
|
163
357
|
* Supports both traditional oRPC error definitions and ORPCTaggedError classes.
|
|
164
358
|
*
|
|
165
359
|
* @see {@link https://orpc.dev/docs/error-handling#type%E2%80%90safe-error-handling Type-Safe Error Handling Docs}
|
|
166
360
|
*/
|
|
167
|
-
errors<
|
|
168
|
-
errors: U,
|
|
169
|
-
): EffectDecoratedProcedure<
|
|
361
|
+
declare errors: EffectDecoratedProcedureSurface<
|
|
170
362
|
TInitialContext,
|
|
171
363
|
TCurrentContext,
|
|
172
364
|
TInputSchema,
|
|
173
365
|
TOutputSchema,
|
|
174
|
-
|
|
366
|
+
TEffectErrorMap,
|
|
175
367
|
TMeta,
|
|
176
368
|
TRequirementsProvided,
|
|
177
369
|
TRuntimeError
|
|
178
|
-
>
|
|
179
|
-
const newEffectErrorMap: MergedEffectErrorMap<TEffectErrorMap, U> = {
|
|
180
|
-
...this["~effect"].effectErrorMap,
|
|
181
|
-
...errors,
|
|
182
|
-
};
|
|
183
|
-
return new EffectDecoratedProcedure({
|
|
184
|
-
...this["~effect"],
|
|
185
|
-
effectErrorMap: newEffectErrorMap,
|
|
186
|
-
errorMap: effectErrorMapToErrorMap(newEffectErrorMap),
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
370
|
+
>["errors"];
|
|
190
371
|
/**
|
|
191
372
|
* Sets or updates the metadata.
|
|
192
373
|
* The provided metadata is spared-merged with any existing metadata.
|
|
193
374
|
*
|
|
194
375
|
* @see {@link https://orpc.dev/docs/metadata Metadata Docs}
|
|
195
376
|
*/
|
|
196
|
-
meta
|
|
197
|
-
meta: TMeta,
|
|
198
|
-
): EffectDecoratedProcedure<
|
|
377
|
+
declare meta: EffectDecoratedProcedureSurface<
|
|
199
378
|
TInitialContext,
|
|
200
379
|
TCurrentContext,
|
|
201
380
|
TInputSchema,
|
|
@@ -204,13 +383,7 @@ export class EffectDecoratedProcedure<
|
|
|
204
383
|
TMeta,
|
|
205
384
|
TRequirementsProvided,
|
|
206
385
|
TRuntimeError
|
|
207
|
-
>
|
|
208
|
-
return new EffectDecoratedProcedure({
|
|
209
|
-
...this["~effect"],
|
|
210
|
-
meta: mergeMeta(this["~effect"].meta, meta),
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
386
|
+
>["meta"];
|
|
214
387
|
/**
|
|
215
388
|
* Sets or updates the route definition.
|
|
216
389
|
* The provided route is spared-merged with any existing route.
|
|
@@ -219,9 +392,7 @@ export class EffectDecoratedProcedure<
|
|
|
219
392
|
* @see {@link https://orpc.dev/docs/openapi/routing OpenAPI Routing Docs}
|
|
220
393
|
* @see {@link https://orpc.dev/docs/openapi/input-output-structure OpenAPI Input/Output Structure Docs}
|
|
221
394
|
*/
|
|
222
|
-
route
|
|
223
|
-
route: Route,
|
|
224
|
-
): EffectDecoratedProcedure<
|
|
395
|
+
declare route: EffectDecoratedProcedureSurface<
|
|
225
396
|
TInitialContext,
|
|
226
397
|
TCurrentContext,
|
|
227
398
|
TInputSchema,
|
|
@@ -230,13 +401,7 @@ export class EffectDecoratedProcedure<
|
|
|
230
401
|
TMeta,
|
|
231
402
|
TRequirementsProvided,
|
|
232
403
|
TRuntimeError
|
|
233
|
-
>
|
|
234
|
-
return new EffectDecoratedProcedure({
|
|
235
|
-
...this["~effect"],
|
|
236
|
-
route: mergeRoute(this["~effect"].route, route),
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
404
|
+
>["route"];
|
|
240
405
|
/**
|
|
241
406
|
* Uses a middleware to modify the context or improve the pipeline.
|
|
242
407
|
*
|
|
@@ -245,92 +410,22 @@ export class EffectDecoratedProcedure<
|
|
|
245
410
|
* @note The current context must be satisfy middleware dependent-context
|
|
246
411
|
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
247
412
|
*/
|
|
248
|
-
use<
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
>(
|
|
252
|
-
middleware: Middleware<
|
|
253
|
-
UInContext | TCurrentContext,
|
|
254
|
-
UOutContext,
|
|
255
|
-
InferSchemaOutput<TInputSchema>,
|
|
256
|
-
InferSchemaInput<TOutputSchema>,
|
|
257
|
-
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
258
|
-
TMeta
|
|
259
|
-
>,
|
|
260
|
-
): EffectDecoratedProcedure<
|
|
261
|
-
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
262
|
-
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
263
|
-
TInputSchema,
|
|
264
|
-
TOutputSchema,
|
|
265
|
-
TEffectErrorMap,
|
|
266
|
-
TMeta,
|
|
267
|
-
TRequirementsProvided,
|
|
268
|
-
TRuntimeError
|
|
269
|
-
>;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Uses a middleware to modify the context or improve the pipeline.
|
|
273
|
-
*
|
|
274
|
-
* @info Supports both normal middleware and inline middleware implementations.
|
|
275
|
-
* @info Pass second argument to map the input.
|
|
276
|
-
* @note The current context must be satisfy middleware dependent-context
|
|
277
|
-
* @see {@link https://orpc.dev/docs/middleware Middleware Docs}
|
|
278
|
-
*/
|
|
279
|
-
use<
|
|
280
|
-
UOutContext extends IntersectPick<TCurrentContext, UOutContext>,
|
|
281
|
-
UInput,
|
|
282
|
-
UInContext extends Context = TCurrentContext,
|
|
283
|
-
>(
|
|
284
|
-
middleware: Middleware<
|
|
285
|
-
UInContext | TCurrentContext,
|
|
286
|
-
UOutContext,
|
|
287
|
-
UInput,
|
|
288
|
-
InferSchemaInput<TOutputSchema>,
|
|
289
|
-
EffectErrorConstructorMap<TEffectErrorMap>,
|
|
290
|
-
TMeta
|
|
291
|
-
>,
|
|
292
|
-
mapInput: MapInputMiddleware<InferSchemaOutput<TInputSchema>, UInput>,
|
|
293
|
-
): EffectDecoratedProcedure<
|
|
294
|
-
MergedInitialContext<TInitialContext, UInContext, TCurrentContext>,
|
|
295
|
-
MergedCurrentContext<TCurrentContext, UOutContext>,
|
|
413
|
+
declare use: EffectDecoratedProcedureSurface<
|
|
414
|
+
TInitialContext,
|
|
415
|
+
TCurrentContext,
|
|
296
416
|
TInputSchema,
|
|
297
417
|
TOutputSchema,
|
|
298
418
|
TEffectErrorMap,
|
|
299
419
|
TMeta,
|
|
300
420
|
TRequirementsProvided,
|
|
301
421
|
TRuntimeError
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
use(
|
|
305
|
-
middleware: AnyMiddleware,
|
|
306
|
-
mapInput?: MapInputMiddleware<any, any>,
|
|
307
|
-
): EffectDecoratedProcedure<any, any, any, any, any, any, any, any> {
|
|
308
|
-
const mapped = mapInput
|
|
309
|
-
? decorateMiddleware(middleware).mapInput(mapInput)
|
|
310
|
-
: middleware;
|
|
311
|
-
|
|
312
|
-
return new EffectDecoratedProcedure({
|
|
313
|
-
...this["~effect"],
|
|
314
|
-
middlewares: addMiddleware(this["~effect"].middlewares, mapped),
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
422
|
+
>["use"];
|
|
318
423
|
/**
|
|
319
424
|
* Make this procedure callable (works like a function while still being a procedure).
|
|
320
425
|
*
|
|
321
426
|
* @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
|
|
322
427
|
*/
|
|
323
|
-
callable<
|
|
324
|
-
...rest: MaybeOptionalOptions<
|
|
325
|
-
CreateProcedureClientOptions<
|
|
326
|
-
TInitialContext,
|
|
327
|
-
TOutputSchema,
|
|
328
|
-
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
329
|
-
TMeta,
|
|
330
|
-
TClientContext
|
|
331
|
-
>
|
|
332
|
-
>
|
|
333
|
-
): EffectDecoratedProcedure<
|
|
428
|
+
declare callable: EffectDecoratedProcedureSurface<
|
|
334
429
|
TInitialContext,
|
|
335
430
|
TCurrentContext,
|
|
336
431
|
TInputSchema,
|
|
@@ -339,48 +434,13 @@ export class EffectDecoratedProcedure<
|
|
|
339
434
|
TMeta,
|
|
340
435
|
TRequirementsProvided,
|
|
341
436
|
TRuntimeError
|
|
342
|
-
>
|
|
343
|
-
ProcedureClient<
|
|
344
|
-
TClientContext,
|
|
345
|
-
TInputSchema,
|
|
346
|
-
TOutputSchema,
|
|
347
|
-
EffectErrorMapToErrorMap<TEffectErrorMap>
|
|
348
|
-
> {
|
|
349
|
-
const client: ProcedureClient<
|
|
350
|
-
TClientContext,
|
|
351
|
-
TInputSchema,
|
|
352
|
-
TOutputSchema,
|
|
353
|
-
EffectErrorMapToErrorMap<TEffectErrorMap>
|
|
354
|
-
> = createProcedureClient(this, ...rest);
|
|
355
|
-
|
|
356
|
-
return new Proxy(client, {
|
|
357
|
-
get: (target, key) => {
|
|
358
|
-
return Reflect.has(this, key)
|
|
359
|
-
? Reflect.get(this, key)
|
|
360
|
-
: Reflect.get(target, key);
|
|
361
|
-
},
|
|
362
|
-
has: (target, key) => {
|
|
363
|
-
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
364
|
-
},
|
|
365
|
-
}) as any;
|
|
366
|
-
}
|
|
367
|
-
|
|
437
|
+
>["callable"];
|
|
368
438
|
/**
|
|
369
439
|
* Make this procedure compatible with server action.
|
|
370
440
|
*
|
|
371
441
|
* @see {@link https://orpc.dev/docs/server-action Server Action Docs}
|
|
372
442
|
*/
|
|
373
|
-
actionable
|
|
374
|
-
...rest: MaybeOptionalOptions<
|
|
375
|
-
CreateProcedureClientOptions<
|
|
376
|
-
TInitialContext,
|
|
377
|
-
TOutputSchema,
|
|
378
|
-
EffectErrorMapToErrorMap<TEffectErrorMap>,
|
|
379
|
-
TMeta,
|
|
380
|
-
Record<never, never>
|
|
381
|
-
>
|
|
382
|
-
>
|
|
383
|
-
): EffectDecoratedProcedure<
|
|
443
|
+
declare actionable: EffectDecoratedProcedureSurface<
|
|
384
444
|
TInitialContext,
|
|
385
445
|
TCurrentContext,
|
|
386
446
|
TInputSchema,
|
|
@@ -389,27 +449,22 @@ export class EffectDecoratedProcedure<
|
|
|
389
449
|
TMeta,
|
|
390
450
|
TRequirementsProvided,
|
|
391
451
|
TRuntimeError
|
|
392
|
-
>
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
> {
|
|
398
|
-
const action: ProcedureActionableClient<
|
|
452
|
+
>["actionable"];
|
|
453
|
+
constructor(
|
|
454
|
+
def: EffectProcedureDef<
|
|
455
|
+
TInitialContext,
|
|
456
|
+
TCurrentContext,
|
|
399
457
|
TInputSchema,
|
|
400
458
|
TOutputSchema,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return Reflect.has(this, key) || Reflect.has(target, key);
|
|
412
|
-
},
|
|
413
|
-
}) as any;
|
|
459
|
+
TEffectErrorMap,
|
|
460
|
+
TMeta,
|
|
461
|
+
TRequirementsProvided,
|
|
462
|
+
TRuntimeError
|
|
463
|
+
>,
|
|
464
|
+
procedure?: AnyProcedureLike,
|
|
465
|
+
) {
|
|
466
|
+
super(def, procedure);
|
|
467
|
+
assertEffectState<AnyProcedureLike>(this);
|
|
468
|
+
return createEffectProcedureProxy(this, true);
|
|
414
469
|
}
|
|
415
470
|
}
|