@orpc/server 0.0.0-next.4a31e17 → 0.0.0-next.4e27480
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-6A7XHEBH.js → chunk-GK2Z6B6W.js} +85 -44
- package/dist/{chunk-B2EZJB7X.js → chunk-SXUFCJBY.js} +18 -20
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +5 -22
- package/dist/hono.js +30 -0
- package/dist/index.js +689 -167
- package/dist/next.js +36 -0
- package/dist/node.js +69 -27
- package/dist/src/adapters/fetch/index.d.ts +0 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +9 -9
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +1 -1
- package/dist/src/adapters/fetch/types.d.ts +11 -6
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +1 -1
- package/dist/src/adapters/node/orpc-handler.d.ts +7 -7
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +10 -9
- package/dist/src/builder-with-errors-middlewares.d.ts +51 -0
- package/dist/src/builder-with-errors.d.ts +52 -0
- package/dist/src/builder-with-middlewares.d.ts +48 -0
- package/dist/src/builder.d.ts +36 -22
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +11 -0
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +2 -2
- package/dist/src/implementer-chainable.d.ts +7 -3
- package/dist/src/index.d.ts +5 -3
- package/dist/src/lazy-decorated.d.ts +3 -6
- package/dist/src/middleware-decorated.d.ts +7 -5
- package/dist/src/middleware.d.ts +21 -8
- package/dist/src/procedure-builder-with-input.d.ts +34 -0
- package/dist/src/procedure-builder-with-output.d.ts +33 -0
- package/dist/src/procedure-builder.d.ts +22 -17
- package/dist/src/procedure-client.d.ts +8 -20
- package/dist/src/procedure-decorated.d.ts +22 -10
- package/dist/src/procedure-implementer.d.ts +16 -12
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +35 -13
- package/dist/src/router-builder.d.ts +19 -15
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +7 -6
- package/dist/src/router.d.ts +5 -5
- package/dist/src/types.d.ts +2 -0
- package/package.json +18 -8
- package/dist/src/adapters/fetch/composite-handler.d.ts +0 -8
- package/dist/src/adapters/node/composite-handler.d.ts +0 -9
package/dist/index.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
+
createORPCErrorConstructorMap,
|
4
5
|
createProcedureClient,
|
5
6
|
flatLazy,
|
6
7
|
getRouterChild,
|
@@ -8,32 +9,41 @@ import {
|
|
8
9
|
isProcedure,
|
9
10
|
lazy,
|
10
11
|
mergeContext,
|
12
|
+
middlewareOutputFn,
|
11
13
|
unlazy
|
12
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-GK2Z6B6W.js";
|
13
15
|
|
14
16
|
// src/builder.ts
|
17
|
+
import { ContractProcedure as ContractProcedure4 } from "@orpc/contract";
|
18
|
+
|
19
|
+
// src/builder-with-errors.ts
|
20
|
+
import { ContractProcedure as ContractProcedure2 } from "@orpc/contract";
|
21
|
+
|
22
|
+
// src/builder-with-errors-middlewares.ts
|
15
23
|
import { ContractProcedure } from "@orpc/contract";
|
16
24
|
|
17
|
-
// src/
|
18
|
-
import {
|
19
|
-
|
25
|
+
// src/procedure-builder.ts
|
26
|
+
import { ContractProcedureBuilder, DecoratedContractProcedure as DecoratedContractProcedure4 } from "@orpc/contract";
|
27
|
+
|
28
|
+
// src/procedure-builder-with-input.ts
|
29
|
+
import { ContractProcedureBuilderWithInput, DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract";
|
20
30
|
|
21
31
|
// src/middleware-decorated.ts
|
22
32
|
function decorateMiddleware(middleware) {
|
23
33
|
const decorated = middleware;
|
24
34
|
decorated.mapInput = (mapInput) => {
|
25
35
|
const mapped = decorateMiddleware(
|
26
|
-
(input, ...rest) => middleware(mapInput(input), ...rest)
|
36
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
27
37
|
);
|
28
38
|
return mapped;
|
29
39
|
};
|
30
40
|
decorated.concat = (concatMiddleware, mapInput) => {
|
31
41
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
32
|
-
const concatted = decorateMiddleware((
|
33
|
-
const next = async (
|
34
|
-
return mapped(
|
42
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
43
|
+
const next = async (nextOptions) => {
|
44
|
+
return mapped({ ...options, context: mergeContext(nextOptions.context, options.context) }, input, output, ...rest);
|
35
45
|
};
|
36
|
-
const merged = middleware(
|
46
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
37
47
|
return merged;
|
38
48
|
});
|
39
49
|
return concatted;
|
@@ -43,58 +53,81 @@ function decorateMiddleware(middleware) {
|
|
43
53
|
|
44
54
|
// src/procedure-decorated.ts
|
45
55
|
import { DecoratedContractProcedure } from "@orpc/contract";
|
46
|
-
|
47
|
-
|
48
|
-
procedure
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
56
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
57
|
+
static decorate(procedure) {
|
58
|
+
if (procedure instanceof _DecoratedProcedure) {
|
59
|
+
return procedure;
|
60
|
+
}
|
61
|
+
return new _DecoratedProcedure(procedure["~orpc"]);
|
62
|
+
}
|
63
|
+
prefix(prefix) {
|
64
|
+
return new _DecoratedProcedure({
|
65
|
+
...this["~orpc"],
|
66
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
|
67
|
+
});
|
68
|
+
}
|
69
|
+
route(route) {
|
70
|
+
return new _DecoratedProcedure({
|
71
|
+
...this["~orpc"],
|
72
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).route(route)
|
73
|
+
});
|
74
|
+
}
|
75
|
+
errors(errors) {
|
76
|
+
return new _DecoratedProcedure({
|
77
|
+
...this["~orpc"],
|
78
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).errors(errors)
|
79
|
+
});
|
80
|
+
}
|
81
|
+
use(middleware, mapInput) {
|
67
82
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
68
|
-
return
|
69
|
-
...
|
70
|
-
middlewares: [...
|
71
|
-
})
|
72
|
-
}
|
73
|
-
|
74
|
-
return
|
75
|
-
...
|
76
|
-
contract: DecoratedContractProcedure.decorate(
|
77
|
-
})
|
78
|
-
}
|
79
|
-
|
80
|
-
|
83
|
+
return new _DecoratedProcedure({
|
84
|
+
...this["~orpc"],
|
85
|
+
middlewares: [...this["~orpc"].middlewares, middleware_]
|
86
|
+
});
|
87
|
+
}
|
88
|
+
unshiftTag(...tags) {
|
89
|
+
return new _DecoratedProcedure({
|
90
|
+
...this["~orpc"],
|
91
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
|
92
|
+
});
|
93
|
+
}
|
94
|
+
unshiftMiddleware(...middlewares) {
|
95
|
+
const castedMiddlewares = middlewares;
|
96
|
+
if (this["~orpc"].middlewares.length) {
|
81
97
|
let min = 0;
|
82
|
-
for (let i = 0; i <
|
83
|
-
const index =
|
98
|
+
for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
|
99
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
|
84
100
|
if (index === -1) {
|
85
|
-
|
101
|
+
castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
|
86
102
|
break;
|
87
103
|
}
|
88
104
|
min = index + 1;
|
89
105
|
}
|
90
106
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
107
|
+
const numNewMiddlewares = castedMiddlewares.length - this["~orpc"].middlewares.length;
|
108
|
+
return new _DecoratedProcedure({
|
109
|
+
...this["~orpc"],
|
110
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + numNewMiddlewares,
|
111
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + numNewMiddlewares,
|
112
|
+
middlewares: castedMiddlewares
|
113
|
+
});
|
114
|
+
}
|
115
|
+
/**
|
116
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
117
|
+
*/
|
118
|
+
callable(...rest) {
|
119
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
120
|
+
"~type": "Procedure",
|
121
|
+
"~orpc": this["~orpc"]
|
122
|
+
});
|
123
|
+
}
|
124
|
+
/**
|
125
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
126
|
+
*/
|
127
|
+
actionable(...rest) {
|
128
|
+
return this.callable(...rest);
|
129
|
+
}
|
130
|
+
};
|
98
131
|
|
99
132
|
// src/procedure-implementer.ts
|
100
133
|
var ProcedureImplementer = class _ProcedureImplementer {
|
@@ -107,15 +140,143 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
107
140
|
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
108
141
|
return new _ProcedureImplementer({
|
109
142
|
...this["~orpc"],
|
110
|
-
middlewares: [...this["~orpc"].middlewares
|
143
|
+
middlewares: [...this["~orpc"].middlewares, mappedMiddleware]
|
111
144
|
});
|
112
145
|
}
|
113
146
|
handler(handler) {
|
114
|
-
return
|
115
|
-
|
116
|
-
contract: this["~orpc"].contract,
|
147
|
+
return new DecoratedProcedure({
|
148
|
+
...this["~orpc"],
|
117
149
|
handler
|
118
|
-
})
|
150
|
+
});
|
151
|
+
}
|
152
|
+
};
|
153
|
+
|
154
|
+
// src/procedure-builder-with-input.ts
|
155
|
+
var ProcedureBuilderWithInput = class _ProcedureBuilderWithInput {
|
156
|
+
"~type" = "ProcedureBuilderWithInput";
|
157
|
+
"~orpc";
|
158
|
+
constructor(def) {
|
159
|
+
this["~orpc"] = def;
|
160
|
+
}
|
161
|
+
errors(errors) {
|
162
|
+
return new _ProcedureBuilderWithInput({
|
163
|
+
...this["~orpc"],
|
164
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
165
|
+
});
|
166
|
+
}
|
167
|
+
route(route) {
|
168
|
+
return new _ProcedureBuilderWithInput({
|
169
|
+
...this["~orpc"],
|
170
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).route(route)
|
171
|
+
});
|
172
|
+
}
|
173
|
+
use(middleware, mapInput) {
|
174
|
+
const maybeWithMapInput = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
175
|
+
return new _ProcedureBuilderWithInput({
|
176
|
+
...this["~orpc"],
|
177
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
178
|
+
middlewares: [...this["~orpc"].middlewares, maybeWithMapInput]
|
179
|
+
});
|
180
|
+
}
|
181
|
+
output(schema, example) {
|
182
|
+
return new ProcedureImplementer({
|
183
|
+
...this["~orpc"],
|
184
|
+
contract: new ContractProcedureBuilderWithInput(this["~orpc"].contract["~orpc"]).output(schema, example)
|
185
|
+
});
|
186
|
+
}
|
187
|
+
handler(handler) {
|
188
|
+
return new DecoratedProcedure({
|
189
|
+
...this["~orpc"],
|
190
|
+
handler
|
191
|
+
});
|
192
|
+
}
|
193
|
+
};
|
194
|
+
|
195
|
+
// src/procedure-builder-with-output.ts
|
196
|
+
import { ContractProcedureBuilderWithOutput, DecoratedContractProcedure as DecoratedContractProcedure3 } from "@orpc/contract";
|
197
|
+
var ProcedureBuilderWithOutput = class _ProcedureBuilderWithOutput {
|
198
|
+
"~type" = "ProcedureBuilderWithOutput";
|
199
|
+
"~orpc";
|
200
|
+
constructor(def) {
|
201
|
+
this["~orpc"] = def;
|
202
|
+
}
|
203
|
+
errors(errors) {
|
204
|
+
return new _ProcedureBuilderWithOutput({
|
205
|
+
...this["~orpc"],
|
206
|
+
contract: DecoratedContractProcedure3.decorate(this["~orpc"].contract).errors(errors)
|
207
|
+
});
|
208
|
+
}
|
209
|
+
route(route) {
|
210
|
+
return new _ProcedureBuilderWithOutput({
|
211
|
+
...this["~orpc"],
|
212
|
+
contract: DecoratedContractProcedure3.decorate(this["~orpc"].contract).route(route)
|
213
|
+
});
|
214
|
+
}
|
215
|
+
use(middleware) {
|
216
|
+
return new _ProcedureBuilderWithOutput({
|
217
|
+
...this["~orpc"],
|
218
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
219
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
220
|
+
});
|
221
|
+
}
|
222
|
+
input(schema, example) {
|
223
|
+
return new ProcedureImplementer({
|
224
|
+
...this["~orpc"],
|
225
|
+
contract: new ContractProcedureBuilderWithOutput(this["~orpc"].contract["~orpc"]).input(schema, example)
|
226
|
+
});
|
227
|
+
}
|
228
|
+
handler(handler) {
|
229
|
+
return new DecoratedProcedure({
|
230
|
+
...this["~orpc"],
|
231
|
+
handler
|
232
|
+
});
|
233
|
+
}
|
234
|
+
};
|
235
|
+
|
236
|
+
// src/procedure-builder.ts
|
237
|
+
var ProcedureBuilder = class _ProcedureBuilder {
|
238
|
+
"~type" = "ProcedureBuilder";
|
239
|
+
"~orpc";
|
240
|
+
constructor(def) {
|
241
|
+
this["~orpc"] = def;
|
242
|
+
}
|
243
|
+
errors(errors) {
|
244
|
+
return new _ProcedureBuilder({
|
245
|
+
...this["~orpc"],
|
246
|
+
contract: DecoratedContractProcedure4.decorate(this["~orpc"].contract).errors(errors)
|
247
|
+
});
|
248
|
+
}
|
249
|
+
route(route) {
|
250
|
+
return new _ProcedureBuilder({
|
251
|
+
...this["~orpc"],
|
252
|
+
contract: DecoratedContractProcedure4.decorate(this["~orpc"].contract).route(route)
|
253
|
+
});
|
254
|
+
}
|
255
|
+
use(middleware) {
|
256
|
+
return new _ProcedureBuilder({
|
257
|
+
...this["~orpc"],
|
258
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
259
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
260
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
261
|
+
});
|
262
|
+
}
|
263
|
+
input(schema, example) {
|
264
|
+
return new ProcedureBuilderWithInput({
|
265
|
+
...this["~orpc"],
|
266
|
+
contract: new ContractProcedureBuilder(this["~orpc"].contract["~orpc"]).input(schema, example)
|
267
|
+
});
|
268
|
+
}
|
269
|
+
output(schema, example) {
|
270
|
+
return new ProcedureBuilderWithOutput({
|
271
|
+
...this["~orpc"],
|
272
|
+
contract: new ContractProcedureBuilder(this["~orpc"].contract["~orpc"]).output(schema, example)
|
273
|
+
});
|
274
|
+
}
|
275
|
+
handler(handler) {
|
276
|
+
return new DecoratedProcedure({
|
277
|
+
...this["~orpc"],
|
278
|
+
handler
|
279
|
+
});
|
119
280
|
}
|
120
281
|
};
|
121
282
|
|
@@ -153,31 +314,10 @@ function getLazyRouterPrefix(obj) {
|
|
153
314
|
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
154
315
|
}
|
155
316
|
|
156
|
-
// src/lazy-utils.ts
|
157
|
-
function createLazyProcedureFormAnyLazy(lazied) {
|
158
|
-
const lazyProcedure = lazy(async () => {
|
159
|
-
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
160
|
-
if (!isProcedure(maybeProcedure)) {
|
161
|
-
throw new Error(`
|
162
|
-
Expected a lazy<procedure> but got lazy<unknown>.
|
163
|
-
This should be caught by TypeScript compilation.
|
164
|
-
Please report this issue if this makes you feel uncomfortable.
|
165
|
-
`);
|
166
|
-
}
|
167
|
-
return { default: maybeProcedure };
|
168
|
-
});
|
169
|
-
return lazyProcedure;
|
170
|
-
}
|
171
|
-
|
172
317
|
// src/lazy-decorated.ts
|
173
318
|
function decorateLazy(lazied) {
|
174
319
|
const flattenLazy = flatLazy(lazied);
|
175
|
-
const
|
176
|
-
procedure: createLazyProcedureFormAnyLazy(flattenLazy),
|
177
|
-
context: void 0
|
178
|
-
});
|
179
|
-
Object.assign(procedureProcedureClient, flattenLazy);
|
180
|
-
const recursive = new Proxy(procedureProcedureClient, {
|
320
|
+
const recursive = new Proxy(flattenLazy, {
|
181
321
|
get(target, key) {
|
182
322
|
if (typeof key !== "string") {
|
183
323
|
return Reflect.get(target, key);
|
@@ -214,10 +354,19 @@ var RouterBuilder = class _RouterBuilder {
|
|
214
354
|
tags: [...this["~orpc"].tags ?? [], ...tags]
|
215
355
|
});
|
216
356
|
}
|
357
|
+
errors(errors) {
|
358
|
+
return new _RouterBuilder({
|
359
|
+
...this["~orpc"],
|
360
|
+
errorMap: {
|
361
|
+
...this["~orpc"].errorMap,
|
362
|
+
...errors
|
363
|
+
}
|
364
|
+
});
|
365
|
+
}
|
217
366
|
use(middleware) {
|
218
367
|
return new _RouterBuilder({
|
219
368
|
...this["~orpc"],
|
220
|
-
middlewares: [...this["~orpc"].middlewares
|
369
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
221
370
|
});
|
222
371
|
}
|
223
372
|
router(router) {
|
@@ -244,7 +393,7 @@ function adapt(item, options) {
|
|
244
393
|
return adaptedLazy;
|
245
394
|
}
|
246
395
|
if (isProcedure(item)) {
|
247
|
-
let decorated =
|
396
|
+
let decorated = DecoratedProcedure.decorate(item);
|
248
397
|
if (options.tags?.length) {
|
249
398
|
decorated = decorated.unshiftTag(...options.tags);
|
250
399
|
}
|
@@ -254,6 +403,9 @@ function adapt(item, options) {
|
|
254
403
|
if (options.middlewares?.length) {
|
255
404
|
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
256
405
|
}
|
406
|
+
if (Object.keys(options.errorMap).length) {
|
407
|
+
decorated = decorated.errors(options.errorMap);
|
408
|
+
}
|
257
409
|
return decorated;
|
258
410
|
}
|
259
411
|
const adapted = {};
|
@@ -263,6 +415,246 @@ function adapt(item, options) {
|
|
263
415
|
return adapted;
|
264
416
|
}
|
265
417
|
|
418
|
+
// src/builder-with-errors-middlewares.ts
|
419
|
+
var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
|
420
|
+
"~type" = "BuilderWithErrorsMiddlewares";
|
421
|
+
"~orpc";
|
422
|
+
constructor(def) {
|
423
|
+
this["~orpc"] = def;
|
424
|
+
}
|
425
|
+
errors(errors) {
|
426
|
+
return new _BuilderWithErrorsMiddlewares({
|
427
|
+
...this["~orpc"],
|
428
|
+
errorMap: {
|
429
|
+
...this["~orpc"].errorMap,
|
430
|
+
...errors
|
431
|
+
}
|
432
|
+
});
|
433
|
+
}
|
434
|
+
use(middleware) {
|
435
|
+
return new _BuilderWithErrorsMiddlewares({
|
436
|
+
...this["~orpc"],
|
437
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
438
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
439
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
440
|
+
// FIXME: I believe we can remove `as any` here
|
441
|
+
});
|
442
|
+
}
|
443
|
+
route(route) {
|
444
|
+
return new ProcedureBuilder({
|
445
|
+
...this["~orpc"],
|
446
|
+
contract: new ContractProcedure({
|
447
|
+
route: {
|
448
|
+
...this["~orpc"].config.initialRoute,
|
449
|
+
...route
|
450
|
+
},
|
451
|
+
InputSchema: void 0,
|
452
|
+
OutputSchema: void 0,
|
453
|
+
errorMap: this["~orpc"].errorMap
|
454
|
+
})
|
455
|
+
});
|
456
|
+
}
|
457
|
+
input(schema, example) {
|
458
|
+
return new ProcedureBuilderWithInput({
|
459
|
+
...this["~orpc"],
|
460
|
+
contract: new ContractProcedure({
|
461
|
+
route: this["~orpc"].config.initialRoute,
|
462
|
+
OutputSchema: void 0,
|
463
|
+
InputSchema: schema,
|
464
|
+
inputExample: example,
|
465
|
+
errorMap: this["~orpc"].errorMap
|
466
|
+
})
|
467
|
+
});
|
468
|
+
}
|
469
|
+
output(schema, example) {
|
470
|
+
return new ProcedureBuilderWithOutput({
|
471
|
+
...this["~orpc"],
|
472
|
+
contract: new ContractProcedure({
|
473
|
+
route: this["~orpc"].config.initialRoute,
|
474
|
+
InputSchema: void 0,
|
475
|
+
OutputSchema: schema,
|
476
|
+
outputExample: example,
|
477
|
+
errorMap: this["~orpc"].errorMap
|
478
|
+
})
|
479
|
+
});
|
480
|
+
}
|
481
|
+
handler(handler) {
|
482
|
+
return new DecoratedProcedure({
|
483
|
+
...this["~orpc"],
|
484
|
+
contract: new ContractProcedure({
|
485
|
+
route: this["~orpc"].config.initialRoute,
|
486
|
+
InputSchema: void 0,
|
487
|
+
OutputSchema: void 0,
|
488
|
+
errorMap: this["~orpc"].errorMap
|
489
|
+
}),
|
490
|
+
handler
|
491
|
+
});
|
492
|
+
}
|
493
|
+
prefix(prefix) {
|
494
|
+
return new RouterBuilder({
|
495
|
+
...this["~orpc"],
|
496
|
+
prefix
|
497
|
+
});
|
498
|
+
}
|
499
|
+
tag(...tags) {
|
500
|
+
return new RouterBuilder({
|
501
|
+
...this["~orpc"],
|
502
|
+
tags
|
503
|
+
});
|
504
|
+
}
|
505
|
+
router(router) {
|
506
|
+
return new RouterBuilder(this["~orpc"]).router(router);
|
507
|
+
}
|
508
|
+
lazy(loader) {
|
509
|
+
return new RouterBuilder(this["~orpc"]).lazy(loader);
|
510
|
+
}
|
511
|
+
};
|
512
|
+
|
513
|
+
// src/config.ts
|
514
|
+
var DEFAULT_CONFIG = {
|
515
|
+
initialInputValidationIndex: 0,
|
516
|
+
initialOutputValidationIndex: 0
|
517
|
+
};
|
518
|
+
function fallbackConfig(key, value) {
|
519
|
+
if (value === void 0) {
|
520
|
+
return DEFAULT_CONFIG[key];
|
521
|
+
}
|
522
|
+
return value;
|
523
|
+
}
|
524
|
+
|
525
|
+
// src/builder-with-errors.ts
|
526
|
+
var BuilderWithErrors = class _BuilderWithErrors {
|
527
|
+
"~type" = "BuilderWithErrors";
|
528
|
+
"~orpc";
|
529
|
+
constructor(def) {
|
530
|
+
this["~orpc"] = def;
|
531
|
+
}
|
532
|
+
config(config) {
|
533
|
+
return new _BuilderWithErrors({
|
534
|
+
...this["~orpc"],
|
535
|
+
config: {
|
536
|
+
...this["~orpc"].config,
|
537
|
+
...config
|
538
|
+
}
|
539
|
+
});
|
540
|
+
}
|
541
|
+
context() {
|
542
|
+
return this;
|
543
|
+
}
|
544
|
+
errors(errors) {
|
545
|
+
return new _BuilderWithErrors({
|
546
|
+
...this["~orpc"],
|
547
|
+
errorMap: {
|
548
|
+
...this["~orpc"].errorMap,
|
549
|
+
...errors
|
550
|
+
}
|
551
|
+
});
|
552
|
+
}
|
553
|
+
middleware(middleware) {
|
554
|
+
return decorateMiddleware(middleware);
|
555
|
+
}
|
556
|
+
use(middleware) {
|
557
|
+
return new BuilderWithErrorsMiddlewares({
|
558
|
+
...this["~orpc"],
|
559
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + 1,
|
560
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + 1,
|
561
|
+
middlewares: [middleware]
|
562
|
+
// FIXME: I believe we can remove `as any` here
|
563
|
+
});
|
564
|
+
}
|
565
|
+
route(route) {
|
566
|
+
return new ProcedureBuilder({
|
567
|
+
middlewares: [],
|
568
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
569
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
570
|
+
contract: new ContractProcedure2({
|
571
|
+
route: {
|
572
|
+
...this["~orpc"].config.initialRoute,
|
573
|
+
...route
|
574
|
+
},
|
575
|
+
InputSchema: void 0,
|
576
|
+
OutputSchema: void 0,
|
577
|
+
errorMap: this["~orpc"].errorMap
|
578
|
+
})
|
579
|
+
});
|
580
|
+
}
|
581
|
+
input(schema, example) {
|
582
|
+
return new ProcedureBuilderWithInput({
|
583
|
+
middlewares: [],
|
584
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
585
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
586
|
+
contract: new ContractProcedure2({
|
587
|
+
route: this["~orpc"].config.initialRoute,
|
588
|
+
OutputSchema: void 0,
|
589
|
+
InputSchema: schema,
|
590
|
+
inputExample: example,
|
591
|
+
errorMap: this["~orpc"].errorMap
|
592
|
+
})
|
593
|
+
});
|
594
|
+
}
|
595
|
+
output(schema, example) {
|
596
|
+
return new ProcedureBuilderWithOutput({
|
597
|
+
middlewares: [],
|
598
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
599
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
600
|
+
contract: new ContractProcedure2({
|
601
|
+
route: this["~orpc"].config.initialRoute,
|
602
|
+
InputSchema: void 0,
|
603
|
+
OutputSchema: schema,
|
604
|
+
outputExample: example,
|
605
|
+
errorMap: this["~orpc"].errorMap
|
606
|
+
})
|
607
|
+
});
|
608
|
+
}
|
609
|
+
handler(handler) {
|
610
|
+
return new DecoratedProcedure({
|
611
|
+
middlewares: [],
|
612
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
613
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
614
|
+
contract: new ContractProcedure2({
|
615
|
+
route: this["~orpc"].config.initialRoute,
|
616
|
+
InputSchema: void 0,
|
617
|
+
OutputSchema: void 0,
|
618
|
+
errorMap: this["~orpc"].errorMap
|
619
|
+
}),
|
620
|
+
handler
|
621
|
+
});
|
622
|
+
}
|
623
|
+
prefix(prefix) {
|
624
|
+
return new RouterBuilder({
|
625
|
+
middlewares: [],
|
626
|
+
errorMap: this["~orpc"].errorMap,
|
627
|
+
prefix
|
628
|
+
});
|
629
|
+
}
|
630
|
+
tag(...tags) {
|
631
|
+
return new RouterBuilder({
|
632
|
+
middlewares: [],
|
633
|
+
errorMap: this["~orpc"].errorMap,
|
634
|
+
tags
|
635
|
+
});
|
636
|
+
}
|
637
|
+
router(router) {
|
638
|
+
return new RouterBuilder({
|
639
|
+
middlewares: [],
|
640
|
+
...this["~orpc"]
|
641
|
+
}).router(router);
|
642
|
+
}
|
643
|
+
lazy(loader) {
|
644
|
+
return new RouterBuilder({
|
645
|
+
middlewares: [],
|
646
|
+
...this["~orpc"]
|
647
|
+
}).lazy(loader);
|
648
|
+
}
|
649
|
+
};
|
650
|
+
|
651
|
+
// src/builder-with-middlewares.ts
|
652
|
+
import { ContractProcedure as ContractProcedure3 } from "@orpc/contract";
|
653
|
+
|
654
|
+
// src/implementer-chainable.ts
|
655
|
+
import { isContractProcedure } from "@orpc/contract";
|
656
|
+
import { createCallableObject } from "@orpc/shared";
|
657
|
+
|
266
658
|
// src/router-implementer.ts
|
267
659
|
var RouterImplementer = class _RouterImplementer {
|
268
660
|
"~type" = "RouterImplementer";
|
@@ -277,31 +669,42 @@ var RouterImplementer = class _RouterImplementer {
|
|
277
669
|
});
|
278
670
|
}
|
279
671
|
router(router) {
|
280
|
-
const adapted = new RouterBuilder(
|
672
|
+
const adapted = new RouterBuilder({
|
673
|
+
...this["~orpc"],
|
674
|
+
errorMap: {}
|
675
|
+
}).router(router);
|
281
676
|
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
282
677
|
return contracted;
|
283
678
|
}
|
284
679
|
lazy(loader) {
|
285
|
-
const adapted = new RouterBuilder(
|
680
|
+
const adapted = new RouterBuilder({
|
681
|
+
...this["~orpc"],
|
682
|
+
errorMap: {}
|
683
|
+
}).lazy(loader);
|
286
684
|
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
287
685
|
return contracted;
|
288
686
|
}
|
289
687
|
};
|
290
688
|
|
291
689
|
// src/implementer-chainable.ts
|
292
|
-
function createChainableImplementer(contract,
|
690
|
+
function createChainableImplementer(contract, options) {
|
293
691
|
if (isContractProcedure(contract)) {
|
294
692
|
const implementer = new ProcedureImplementer({
|
295
693
|
contract,
|
296
|
-
middlewares
|
694
|
+
middlewares: options.middlewares,
|
695
|
+
inputValidationIndex: options.inputValidationIndex,
|
696
|
+
outputValidationIndex: options.outputValidationIndex
|
297
697
|
});
|
298
698
|
return implementer;
|
299
699
|
}
|
300
700
|
const chainable = {};
|
301
701
|
for (const key in contract) {
|
302
|
-
chainable[key] = createChainableImplementer(contract[key],
|
702
|
+
chainable[key] = createChainableImplementer(contract[key], options);
|
303
703
|
}
|
304
|
-
const routerImplementer = new RouterImplementer({
|
704
|
+
const routerImplementer = new RouterImplementer({
|
705
|
+
contract,
|
706
|
+
middlewares: options.middlewares
|
707
|
+
});
|
305
708
|
const merged = new Proxy(chainable, {
|
306
709
|
get(target, key) {
|
307
710
|
const next = Reflect.get(target, key);
|
@@ -318,52 +721,105 @@ function createChainableImplementer(contract, middlewares) {
|
|
318
721
|
return merged;
|
319
722
|
}
|
320
723
|
|
321
|
-
// src/
|
322
|
-
|
323
|
-
|
324
|
-
} from "@orpc/contract";
|
325
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
326
|
-
"~type" = "ProcedureBuilder";
|
724
|
+
// src/builder-with-middlewares.ts
|
725
|
+
var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
|
726
|
+
"~type" = "BuilderHasMiddlewares";
|
327
727
|
"~orpc";
|
328
728
|
constructor(def) {
|
329
729
|
this["~orpc"] = def;
|
330
730
|
}
|
731
|
+
use(middleware) {
|
732
|
+
return new _BuilderWithMiddlewares({
|
733
|
+
...this["~orpc"],
|
734
|
+
inputValidationIndex: this["~orpc"].inputValidationIndex + 1,
|
735
|
+
outputValidationIndex: this["~orpc"].outputValidationIndex + 1,
|
736
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
737
|
+
});
|
738
|
+
}
|
739
|
+
errors(errors) {
|
740
|
+
return new BuilderWithErrorsMiddlewares({
|
741
|
+
...this["~orpc"],
|
742
|
+
errorMap: errors
|
743
|
+
});
|
744
|
+
}
|
331
745
|
route(route) {
|
332
|
-
return new
|
746
|
+
return new ProcedureBuilder({
|
333
747
|
...this["~orpc"],
|
334
|
-
contract:
|
748
|
+
contract: new ContractProcedure3({
|
749
|
+
route: {
|
750
|
+
...this["~orpc"].config.initialRoute,
|
751
|
+
...route
|
752
|
+
},
|
753
|
+
InputSchema: void 0,
|
754
|
+
OutputSchema: void 0,
|
755
|
+
errorMap: {}
|
756
|
+
})
|
335
757
|
});
|
336
758
|
}
|
337
759
|
input(schema, example) {
|
338
|
-
return new
|
760
|
+
return new ProcedureBuilderWithInput({
|
339
761
|
...this["~orpc"],
|
340
|
-
contract:
|
762
|
+
contract: new ContractProcedure3({
|
763
|
+
route: this["~orpc"].config.initialRoute,
|
764
|
+
OutputSchema: void 0,
|
765
|
+
InputSchema: schema,
|
766
|
+
inputExample: example,
|
767
|
+
errorMap: {}
|
768
|
+
})
|
341
769
|
});
|
342
770
|
}
|
343
771
|
output(schema, example) {
|
344
|
-
return new
|
772
|
+
return new ProcedureBuilderWithOutput({
|
345
773
|
...this["~orpc"],
|
346
|
-
contract:
|
774
|
+
contract: new ContractProcedure3({
|
775
|
+
route: this["~orpc"].config.initialRoute,
|
776
|
+
InputSchema: void 0,
|
777
|
+
OutputSchema: schema,
|
778
|
+
outputExample: example,
|
779
|
+
errorMap: {}
|
780
|
+
})
|
347
781
|
});
|
348
782
|
}
|
349
|
-
use(middleware, mapInput) {
|
350
|
-
if (!mapInput) {
|
351
|
-
return new ProcedureImplementer({
|
352
|
-
contract: this["~orpc"].contract,
|
353
|
-
middlewares: this["~orpc"].middlewares
|
354
|
-
}).use(middleware);
|
355
|
-
}
|
356
|
-
return new ProcedureImplementer({
|
357
|
-
contract: this["~orpc"].contract,
|
358
|
-
middlewares: this["~orpc"].middlewares
|
359
|
-
}).use(middleware, mapInput);
|
360
|
-
}
|
361
783
|
handler(handler) {
|
362
|
-
return
|
363
|
-
|
364
|
-
contract:
|
784
|
+
return new DecoratedProcedure({
|
785
|
+
...this["~orpc"],
|
786
|
+
contract: new ContractProcedure3({
|
787
|
+
route: this["~orpc"].config.initialRoute,
|
788
|
+
InputSchema: void 0,
|
789
|
+
OutputSchema: void 0,
|
790
|
+
errorMap: {}
|
791
|
+
}),
|
365
792
|
handler
|
366
|
-
})
|
793
|
+
});
|
794
|
+
}
|
795
|
+
prefix(prefix) {
|
796
|
+
return new RouterBuilder({
|
797
|
+
middlewares: this["~orpc"].middlewares,
|
798
|
+
errorMap: {},
|
799
|
+
prefix
|
800
|
+
});
|
801
|
+
}
|
802
|
+
tag(...tags) {
|
803
|
+
return new RouterBuilder({
|
804
|
+
middlewares: this["~orpc"].middlewares,
|
805
|
+
errorMap: {},
|
806
|
+
tags
|
807
|
+
});
|
808
|
+
}
|
809
|
+
router(router) {
|
810
|
+
return new RouterBuilder({
|
811
|
+
errorMap: {},
|
812
|
+
...this["~orpc"]
|
813
|
+
}).router(router);
|
814
|
+
}
|
815
|
+
lazy(loader) {
|
816
|
+
return new RouterBuilder({
|
817
|
+
errorMap: {},
|
818
|
+
...this["~orpc"]
|
819
|
+
}).lazy(loader);
|
820
|
+
}
|
821
|
+
contract(contract) {
|
822
|
+
return createChainableImplementer(contract, this["~orpc"]);
|
367
823
|
}
|
368
824
|
};
|
369
825
|
|
@@ -374,111 +830,170 @@ var Builder = class _Builder {
|
|
374
830
|
constructor(def) {
|
375
831
|
this["~orpc"] = def;
|
376
832
|
}
|
377
|
-
|
378
|
-
return new _Builder({});
|
379
|
-
}
|
380
|
-
use(middleware) {
|
833
|
+
config(config) {
|
381
834
|
return new _Builder({
|
382
835
|
...this["~orpc"],
|
383
|
-
|
836
|
+
config: {
|
837
|
+
...this["~orpc"].config,
|
838
|
+
...config
|
839
|
+
}
|
384
840
|
});
|
385
841
|
}
|
842
|
+
context() {
|
843
|
+
return this;
|
844
|
+
}
|
386
845
|
middleware(middleware) {
|
387
846
|
return decorateMiddleware(middleware);
|
388
847
|
}
|
848
|
+
errors(errors) {
|
849
|
+
return new BuilderWithErrors({
|
850
|
+
...this["~orpc"],
|
851
|
+
errorMap: errors
|
852
|
+
});
|
853
|
+
}
|
854
|
+
use(middleware) {
|
855
|
+
return new BuilderWithMiddlewares({
|
856
|
+
...this["~orpc"],
|
857
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + 1,
|
858
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + 1,
|
859
|
+
middlewares: [middleware]
|
860
|
+
// FIXME: I believe we can remove `as any` here
|
861
|
+
});
|
862
|
+
}
|
389
863
|
route(route) {
|
390
864
|
return new ProcedureBuilder({
|
391
|
-
middlewares:
|
392
|
-
|
393
|
-
|
865
|
+
middlewares: [],
|
866
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
867
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
868
|
+
contract: new ContractProcedure4({
|
869
|
+
route: {
|
870
|
+
...this["~orpc"].config.initialRoute,
|
871
|
+
...route
|
872
|
+
},
|
394
873
|
InputSchema: void 0,
|
395
|
-
OutputSchema: void 0
|
874
|
+
OutputSchema: void 0,
|
875
|
+
errorMap: {}
|
396
876
|
})
|
397
877
|
});
|
398
878
|
}
|
399
879
|
input(schema, example) {
|
400
|
-
return new
|
401
|
-
middlewares:
|
402
|
-
|
880
|
+
return new ProcedureBuilderWithInput({
|
881
|
+
middlewares: [],
|
882
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
883
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
884
|
+
contract: new ContractProcedure4({
|
885
|
+
route: this["~orpc"].config.initialRoute,
|
403
886
|
OutputSchema: void 0,
|
404
887
|
InputSchema: schema,
|
405
|
-
inputExample: example
|
888
|
+
inputExample: example,
|
889
|
+
errorMap: {}
|
406
890
|
})
|
407
891
|
});
|
408
892
|
}
|
409
893
|
output(schema, example) {
|
410
|
-
return new
|
411
|
-
middlewares:
|
412
|
-
|
894
|
+
return new ProcedureBuilderWithOutput({
|
895
|
+
middlewares: [],
|
896
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
897
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
898
|
+
contract: new ContractProcedure4({
|
899
|
+
route: this["~orpc"].config.initialRoute,
|
413
900
|
InputSchema: void 0,
|
414
901
|
OutputSchema: schema,
|
415
|
-
outputExample: example
|
902
|
+
outputExample: example,
|
903
|
+
errorMap: {}
|
416
904
|
})
|
417
905
|
});
|
418
906
|
}
|
419
907
|
handler(handler) {
|
420
|
-
return
|
421
|
-
middlewares:
|
422
|
-
|
908
|
+
return new DecoratedProcedure({
|
909
|
+
middlewares: [],
|
910
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
911
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex),
|
912
|
+
contract: new ContractProcedure4({
|
913
|
+
route: this["~orpc"].config.initialRoute,
|
423
914
|
InputSchema: void 0,
|
424
|
-
OutputSchema: void 0
|
915
|
+
OutputSchema: void 0,
|
916
|
+
errorMap: {}
|
425
917
|
}),
|
426
918
|
handler
|
427
|
-
})
|
919
|
+
});
|
428
920
|
}
|
429
921
|
prefix(prefix) {
|
430
922
|
return new RouterBuilder({
|
431
|
-
middlewares:
|
923
|
+
middlewares: [],
|
924
|
+
errorMap: {},
|
432
925
|
prefix
|
433
926
|
});
|
434
927
|
}
|
435
928
|
tag(...tags) {
|
436
929
|
return new RouterBuilder({
|
437
|
-
middlewares:
|
930
|
+
middlewares: [],
|
931
|
+
errorMap: {},
|
438
932
|
tags
|
439
933
|
});
|
440
934
|
}
|
441
935
|
router(router) {
|
442
|
-
return new RouterBuilder(
|
936
|
+
return new RouterBuilder({
|
937
|
+
middlewares: [],
|
938
|
+
errorMap: []
|
939
|
+
}).router(router);
|
443
940
|
}
|
444
941
|
lazy(loader) {
|
445
|
-
return new RouterBuilder(
|
942
|
+
return new RouterBuilder({
|
943
|
+
middlewares: [],
|
944
|
+
errorMap: {}
|
945
|
+
}).lazy(loader);
|
446
946
|
}
|
447
947
|
contract(contract) {
|
448
|
-
return createChainableImplementer(contract,
|
948
|
+
return createChainableImplementer(contract, {
|
949
|
+
middlewares: [],
|
950
|
+
inputValidationIndex: 0,
|
951
|
+
outputValidationIndex: 0
|
952
|
+
});
|
449
953
|
}
|
450
954
|
};
|
451
955
|
|
956
|
+
// src/procedure-utils.ts
|
957
|
+
function call(procedure, input, ...rest) {
|
958
|
+
return createProcedureClient(procedure, ...rest)(input);
|
959
|
+
}
|
960
|
+
|
961
|
+
// src/lazy-utils.ts
|
962
|
+
function createLazyProcedureFormAnyLazy(lazied) {
|
963
|
+
const lazyProcedure = lazy(async () => {
|
964
|
+
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
965
|
+
if (!isProcedure(maybeProcedure)) {
|
966
|
+
throw new Error(`
|
967
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
968
|
+
This should be caught by TypeScript compilation.
|
969
|
+
Please report this issue if this makes you feel uncomfortable.
|
970
|
+
`);
|
971
|
+
}
|
972
|
+
return { default: maybeProcedure };
|
973
|
+
});
|
974
|
+
return lazyProcedure;
|
975
|
+
}
|
976
|
+
|
452
977
|
// src/router-client.ts
|
453
|
-
function createRouterClient(
|
454
|
-
if (isProcedure(
|
455
|
-
const caller = createProcedureClient(
|
456
|
-
...options,
|
457
|
-
procedure: options.router,
|
458
|
-
context: options.context,
|
459
|
-
path: options.path
|
460
|
-
});
|
978
|
+
function createRouterClient(router, ...rest) {
|
979
|
+
if (isProcedure(router)) {
|
980
|
+
const caller = createProcedureClient(router, ...rest);
|
461
981
|
return caller;
|
462
982
|
}
|
463
|
-
const procedureCaller = isLazy(
|
464
|
-
...options,
|
465
|
-
procedure: createLazyProcedureFormAnyLazy(options.router),
|
466
|
-
context: options.context,
|
467
|
-
path: options.path
|
468
|
-
}) : {};
|
983
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
469
984
|
const recursive = new Proxy(procedureCaller, {
|
470
985
|
get(target, key) {
|
471
986
|
if (typeof key !== "string") {
|
472
987
|
return Reflect.get(target, key);
|
473
988
|
}
|
474
|
-
const next = getRouterChild(
|
989
|
+
const next = getRouterChild(router, key);
|
475
990
|
if (!next) {
|
476
991
|
return Reflect.get(target, key);
|
477
992
|
}
|
478
|
-
|
993
|
+
const [options] = rest;
|
994
|
+
return createRouterClient(next, {
|
479
995
|
...options,
|
480
|
-
|
481
|
-
path: [...options.path ?? [], key]
|
996
|
+
path: [...options?.path ?? [], key]
|
482
997
|
});
|
483
998
|
}
|
484
999
|
});
|
@@ -486,36 +1001,43 @@ function createRouterClient(options) {
|
|
486
1001
|
}
|
487
1002
|
|
488
1003
|
// src/index.ts
|
489
|
-
import {
|
490
|
-
|
491
|
-
|
1004
|
+
import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
1005
|
+
var os = new Builder({
|
1006
|
+
config: {}
|
1007
|
+
});
|
492
1008
|
export {
|
493
1009
|
Builder,
|
1010
|
+
DecoratedProcedure,
|
494
1011
|
LAZY_LOADER_SYMBOL,
|
1012
|
+
ORPCError,
|
495
1013
|
Procedure,
|
496
1014
|
ProcedureBuilder,
|
497
1015
|
ProcedureImplementer,
|
498
1016
|
RouterBuilder,
|
499
1017
|
RouterImplementer,
|
500
|
-
|
1018
|
+
call,
|
501
1019
|
createChainableImplementer,
|
1020
|
+
createORPCErrorConstructorMap,
|
502
1021
|
createProcedureClient,
|
503
1022
|
createRouterClient,
|
504
1023
|
decorateLazy,
|
505
1024
|
decorateMiddleware,
|
506
|
-
decorateProcedure,
|
507
1025
|
deepSetLazyRouterPrefix,
|
508
|
-
|
1026
|
+
fallbackConfig,
|
509
1027
|
flatLazy,
|
510
1028
|
getLazyRouterPrefix,
|
511
1029
|
getRouterChild,
|
512
1030
|
getRouterContract,
|
1031
|
+
isDefinedError,
|
513
1032
|
isLazy,
|
514
1033
|
isProcedure,
|
515
1034
|
lazy,
|
516
1035
|
mergeContext,
|
1036
|
+
middlewareOutputFn,
|
517
1037
|
os,
|
1038
|
+
safe,
|
518
1039
|
setRouterContract,
|
1040
|
+
type,
|
519
1041
|
unlazy
|
520
1042
|
};
|
521
1043
|
//# sourceMappingURL=index.js.map
|