@orpc/server 0.0.0-next.4555a17 → 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-GK2Z6B6W.js +230 -0
- package/dist/chunk-SXUFCJBY.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +11 -107
- package/dist/hono.js +30 -0
- package/dist/index.js +890 -294
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- 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 +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- 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 +42 -47
- 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 +6 -0
- package/dist/src/implementer-chainable.d.ts +14 -0
- package/dist/src/index.d.ts +13 -4
- package/dist/src/lazy-decorated.d.ts +7 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +6 -11
- package/dist/src/middleware-decorated.d.ts +10 -0
- package/dist/src/middleware.d.ts +22 -12
- 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 +24 -28
- package/dist/src/procedure-client.d.ts +22 -0
- package/dist/src/procedure-decorated.d.ts +26 -0
- package/dist/src/procedure-implementer.d.ts +19 -19
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +39 -26
- package/dist/src/router-builder.d.ts +29 -23
- package/dist/src/router-client.d.ts +26 -0
- package/dist/src/router-implementer.d.ts +18 -20
- package/dist/src/router.d.ts +11 -15
- package/dist/src/types.d.ts +8 -8
- package/package.json +22 -10
- package/dist/chunk-VARUID7X.js +0 -273
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -28
- package/dist/src/procedure-caller.d.ts +0 -26
- package/dist/src/router-caller.d.ts +0 -25
package/dist/index.js
CHANGED
@@ -1,415 +1,999 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
decorateMiddleware,
|
9
|
-
decorateProcedure,
|
4
|
+
createORPCErrorConstructorMap,
|
5
|
+
createProcedureClient,
|
6
|
+
flatLazy,
|
7
|
+
getRouterChild,
|
10
8
|
isLazy,
|
11
9
|
isProcedure,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
lazy,
|
11
|
+
mergeContext,
|
12
|
+
middlewareOutputFn,
|
13
|
+
unlazy
|
14
|
+
} from "./chunk-GK2Z6B6W.js";
|
16
15
|
|
17
16
|
// src/builder.ts
|
18
|
-
import {
|
19
|
-
|
20
|
-
|
21
|
-
} from "@orpc/contract";
|
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
|
23
|
+
import { ContractProcedure } from "@orpc/contract";
|
22
24
|
|
23
25
|
// src/procedure-builder.ts
|
24
|
-
import {
|
25
|
-
DecoratedContractProcedure as DecoratedContractProcedure2
|
26
|
-
} from "@orpc/contract";
|
26
|
+
import { ContractProcedureBuilder, DecoratedContractProcedure as DecoratedContractProcedure4 } from "@orpc/contract";
|
27
27
|
|
28
|
-
// src/
|
28
|
+
// src/procedure-builder-with-input.ts
|
29
|
+
import { ContractProcedureBuilderWithInput, DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract";
|
30
|
+
|
31
|
+
// src/middleware-decorated.ts
|
32
|
+
function decorateMiddleware(middleware) {
|
33
|
+
const decorated = middleware;
|
34
|
+
decorated.mapInput = (mapInput) => {
|
35
|
+
const mapped = decorateMiddleware(
|
36
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
37
|
+
);
|
38
|
+
return mapped;
|
39
|
+
};
|
40
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
41
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
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);
|
45
|
+
};
|
46
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
47
|
+
return merged;
|
48
|
+
});
|
49
|
+
return concatted;
|
50
|
+
};
|
51
|
+
return decorated;
|
52
|
+
}
|
53
|
+
|
54
|
+
// src/procedure-decorated.ts
|
29
55
|
import { DecoratedContractProcedure } from "@orpc/contract";
|
30
|
-
var
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if (zz$rb.prefix && zz$rb.prefix.includes("{")) {
|
35
|
-
throw new Error('Prefix cannot contain "{" for dynamic routing');
|
56
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
57
|
+
static decorate(procedure) {
|
58
|
+
if (procedure instanceof _DecoratedProcedure) {
|
59
|
+
return procedure;
|
36
60
|
}
|
61
|
+
return new _DecoratedProcedure(procedure["~orpc"]);
|
37
62
|
}
|
38
63
|
prefix(prefix) {
|
39
|
-
return new
|
40
|
-
...this
|
41
|
-
|
64
|
+
return new _DecoratedProcedure({
|
65
|
+
...this["~orpc"],
|
66
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
|
42
67
|
});
|
43
68
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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)
|
50
79
|
});
|
51
80
|
}
|
52
81
|
use(middleware, mapInput) {
|
53
82
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
54
|
-
return new
|
55
|
-
...this
|
56
|
-
middlewares: [...this.
|
83
|
+
return new _DecoratedProcedure({
|
84
|
+
...this["~orpc"],
|
85
|
+
middlewares: [...this["~orpc"].middlewares, middleware_]
|
57
86
|
});
|
58
87
|
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
tags: this.zz$rb.tags,
|
64
|
-
prefix: this.zz$rb.prefix
|
88
|
+
unshiftTag(...tags) {
|
89
|
+
return new _DecoratedProcedure({
|
90
|
+
...this["~orpc"],
|
91
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
|
65
92
|
});
|
66
|
-
return handled;
|
67
93
|
}
|
68
|
-
|
69
|
-
const
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
94
|
+
unshiftMiddleware(...middlewares) {
|
95
|
+
const castedMiddlewares = middlewares;
|
96
|
+
if (this["~orpc"].middlewares.length) {
|
97
|
+
let min = 0;
|
98
|
+
for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
|
99
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
|
100
|
+
if (index === -1) {
|
101
|
+
castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
min = index + 1;
|
105
|
+
}
|
106
|
+
}
|
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"]
|
74
122
|
});
|
75
|
-
|
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);
|
76
129
|
}
|
77
130
|
};
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
131
|
+
|
132
|
+
// src/procedure-implementer.ts
|
133
|
+
var ProcedureImplementer = class _ProcedureImplementer {
|
134
|
+
"~type" = "ProcedureImplementer";
|
135
|
+
"~orpc";
|
136
|
+
constructor(def) {
|
137
|
+
this["~orpc"] = def;
|
138
|
+
}
|
139
|
+
use(middleware, mapInput) {
|
140
|
+
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
141
|
+
return new _ProcedureImplementer({
|
142
|
+
...this["~orpc"],
|
143
|
+
middlewares: [...this["~orpc"].middlewares, mappedMiddleware]
|
83
144
|
});
|
84
145
|
}
|
85
|
-
|
86
|
-
return
|
87
|
-
...
|
88
|
-
|
146
|
+
handler(handler) {
|
147
|
+
return new DecoratedProcedure({
|
148
|
+
...this["~orpc"],
|
149
|
+
handler
|
89
150
|
});
|
90
151
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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)
|
96
165
|
});
|
97
166
|
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
+
});
|
113
280
|
}
|
114
|
-
|
115
|
-
|
281
|
+
};
|
282
|
+
|
283
|
+
// src/hidden.ts
|
284
|
+
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
285
|
+
function setRouterContract(obj, contract) {
|
286
|
+
return new Proxy(obj, {
|
287
|
+
get(target, key) {
|
288
|
+
if (key === ROUTER_CONTRACT_SYMBOL) {
|
289
|
+
return contract;
|
290
|
+
}
|
291
|
+
return Reflect.get(target, key);
|
292
|
+
}
|
116
293
|
});
|
117
|
-
|
294
|
+
}
|
295
|
+
function getRouterContract(obj) {
|
296
|
+
return obj[ROUTER_CONTRACT_SYMBOL];
|
297
|
+
}
|
298
|
+
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
299
|
+
function deepSetLazyRouterPrefix(router, prefix) {
|
300
|
+
return new Proxy(router, {
|
118
301
|
get(target, key) {
|
119
|
-
if (
|
120
|
-
|
302
|
+
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
303
|
+
const val = Reflect.get(target, key);
|
304
|
+
if (val && (typeof val === "object" || typeof val === "function")) {
|
305
|
+
return deepSetLazyRouterPrefix(val, prefix);
|
306
|
+
}
|
307
|
+
return val;
|
121
308
|
}
|
122
|
-
return
|
123
|
-
...options,
|
124
|
-
current: createLazy(async () => {
|
125
|
-
const current = (await loadLazy(options.current)).default;
|
126
|
-
return { default: current[key] };
|
127
|
-
})
|
128
|
-
});
|
309
|
+
return prefix;
|
129
310
|
}
|
130
311
|
});
|
131
|
-
return recursive;
|
132
312
|
}
|
133
|
-
function
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
}
|
148
|
-
return decorateProcedure({
|
149
|
-
zz$p: {
|
150
|
-
...options.procedure.zz$p,
|
151
|
-
contract,
|
152
|
-
middlewares
|
313
|
+
function getLazyRouterPrefix(obj) {
|
314
|
+
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
315
|
+
}
|
316
|
+
|
317
|
+
// src/lazy-decorated.ts
|
318
|
+
function decorateLazy(lazied) {
|
319
|
+
const flattenLazy = flatLazy(lazied);
|
320
|
+
const recursive = new Proxy(flattenLazy, {
|
321
|
+
get(target, key) {
|
322
|
+
if (typeof key !== "string") {
|
323
|
+
return Reflect.get(target, key);
|
324
|
+
}
|
325
|
+
const next = getRouterChild(flattenLazy, key);
|
326
|
+
return decorateLazy(next);
|
153
327
|
}
|
154
328
|
});
|
329
|
+
return recursive;
|
155
330
|
}
|
156
331
|
|
157
|
-
// src/
|
158
|
-
var
|
159
|
-
|
160
|
-
|
332
|
+
// src/router-builder.ts
|
333
|
+
var RouterBuilder = class _RouterBuilder {
|
334
|
+
"~type" = "RouterBuilder";
|
335
|
+
"~orpc";
|
336
|
+
constructor(def) {
|
337
|
+
this["~orpc"] = def;
|
338
|
+
if (def.prefix && def.prefix.includes("{")) {
|
339
|
+
throw new Error(`
|
340
|
+
Dynamic routing in prefix not supported yet.
|
341
|
+
Please remove "{" from "${def.prefix}".
|
342
|
+
`);
|
343
|
+
}
|
161
344
|
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
middlewares: [...this.zz$pi.middlewares ?? [], middleware_]
|
345
|
+
prefix(prefix) {
|
346
|
+
return new _RouterBuilder({
|
347
|
+
...this["~orpc"],
|
348
|
+
prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
|
167
349
|
});
|
168
350
|
}
|
169
|
-
|
170
|
-
return
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
351
|
+
tag(...tags) {
|
352
|
+
return new _RouterBuilder({
|
353
|
+
...this["~orpc"],
|
354
|
+
tags: [...this["~orpc"].tags ?? [], ...tags]
|
355
|
+
});
|
356
|
+
}
|
357
|
+
errors(errors) {
|
358
|
+
return new _RouterBuilder({
|
359
|
+
...this["~orpc"],
|
360
|
+
errorMap: {
|
361
|
+
...this["~orpc"].errorMap,
|
362
|
+
...errors
|
175
363
|
}
|
176
364
|
});
|
177
365
|
}
|
366
|
+
use(middleware) {
|
367
|
+
return new _RouterBuilder({
|
368
|
+
...this["~orpc"],
|
369
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
370
|
+
});
|
371
|
+
}
|
372
|
+
router(router) {
|
373
|
+
const adapted = adapt(router, this["~orpc"]);
|
374
|
+
return adapted;
|
375
|
+
}
|
178
376
|
lazy(loader) {
|
179
|
-
|
377
|
+
const adapted = adapt(flatLazy(lazy(loader)), this["~orpc"]);
|
378
|
+
return adapted;
|
180
379
|
}
|
181
380
|
};
|
381
|
+
function adapt(item, options) {
|
382
|
+
if (isLazy(item)) {
|
383
|
+
const adaptedLazy = decorateLazy(lazy(async () => {
|
384
|
+
const routerOrProcedure = (await unlazy(item)).default;
|
385
|
+
const adapted2 = adapt(routerOrProcedure, options);
|
386
|
+
return { default: adapted2 };
|
387
|
+
}));
|
388
|
+
const lazyPrefix = getLazyRouterPrefix(item);
|
389
|
+
if (options.prefix || lazyPrefix) {
|
390
|
+
const prefixed = deepSetLazyRouterPrefix(adaptedLazy, `${options.prefix ?? ""}${lazyPrefix ?? ""}`);
|
391
|
+
return prefixed;
|
392
|
+
}
|
393
|
+
return adaptedLazy;
|
394
|
+
}
|
395
|
+
if (isProcedure(item)) {
|
396
|
+
let decorated = DecoratedProcedure.decorate(item);
|
397
|
+
if (options.tags?.length) {
|
398
|
+
decorated = decorated.unshiftTag(...options.tags);
|
399
|
+
}
|
400
|
+
if (options.prefix) {
|
401
|
+
decorated = decorated.prefix(options.prefix);
|
402
|
+
}
|
403
|
+
if (options.middlewares?.length) {
|
404
|
+
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
405
|
+
}
|
406
|
+
if (Object.keys(options.errorMap).length) {
|
407
|
+
decorated = decorated.errors(options.errorMap);
|
408
|
+
}
|
409
|
+
return decorated;
|
410
|
+
}
|
411
|
+
const adapted = {};
|
412
|
+
for (const key in item) {
|
413
|
+
adapted[key] = adapt(item[key], options);
|
414
|
+
}
|
415
|
+
return adapted;
|
416
|
+
}
|
182
417
|
|
183
|
-
// src/
|
184
|
-
var
|
185
|
-
|
186
|
-
|
418
|
+
// src/builder-with-errors-middlewares.ts
|
419
|
+
var BuilderWithErrorsMiddlewares = class _BuilderWithErrorsMiddlewares {
|
420
|
+
"~type" = "BuilderWithErrorsMiddlewares";
|
421
|
+
"~orpc";
|
422
|
+
constructor(def) {
|
423
|
+
this["~orpc"] = def;
|
187
424
|
}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
+
})
|
197
455
|
});
|
198
456
|
}
|
199
457
|
input(schema, example) {
|
200
|
-
return new
|
201
|
-
...this
|
202
|
-
contract:
|
203
|
-
|
204
|
-
|
205
|
-
|
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
|
+
})
|
206
467
|
});
|
207
468
|
}
|
208
469
|
output(schema, example) {
|
209
|
-
return new
|
210
|
-
...this
|
211
|
-
contract:
|
212
|
-
|
213
|
-
|
214
|
-
|
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
|
+
})
|
215
479
|
});
|
216
480
|
}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
})
|
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
|
+
});
|
228
492
|
}
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
238
550
|
}
|
239
551
|
});
|
240
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
|
+
}
|
241
649
|
};
|
242
650
|
|
243
|
-
// src/
|
651
|
+
// src/builder-with-middlewares.ts
|
652
|
+
import { ContractProcedure as ContractProcedure3 } from "@orpc/contract";
|
653
|
+
|
654
|
+
// src/implementer-chainable.ts
|
244
655
|
import { isContractProcedure } from "@orpc/contract";
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
656
|
+
import { createCallableObject } from "@orpc/shared";
|
657
|
+
|
658
|
+
// src/router-implementer.ts
|
659
|
+
var RouterImplementer = class _RouterImplementer {
|
660
|
+
"~type" = "RouterImplementer";
|
661
|
+
"~orpc";
|
662
|
+
constructor(def) {
|
663
|
+
this["~orpc"] = def;
|
249
664
|
}
|
250
|
-
|
251
|
-
return
|
252
|
-
[
|
665
|
+
use(middleware) {
|
666
|
+
return new _RouterImplementer({
|
667
|
+
...this["~orpc"],
|
668
|
+
middlewares: [...this["~orpc"].middlewares ?? [], middleware]
|
253
669
|
});
|
254
670
|
}
|
671
|
+
router(router) {
|
672
|
+
const adapted = new RouterBuilder({
|
673
|
+
...this["~orpc"],
|
674
|
+
errorMap: {}
|
675
|
+
}).router(router);
|
676
|
+
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
677
|
+
return contracted;
|
678
|
+
}
|
255
679
|
lazy(loader) {
|
256
|
-
const
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
680
|
+
const adapted = new RouterBuilder({
|
681
|
+
...this["~orpc"],
|
682
|
+
errorMap: {}
|
683
|
+
}).lazy(loader);
|
684
|
+
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
685
|
+
return contracted;
|
261
686
|
}
|
262
687
|
};
|
263
|
-
|
264
|
-
|
688
|
+
|
689
|
+
// src/implementer-chainable.ts
|
690
|
+
function createChainableImplementer(contract, options) {
|
691
|
+
if (isContractProcedure(contract)) {
|
692
|
+
const implementer = new ProcedureImplementer({
|
693
|
+
contract,
|
694
|
+
middlewares: options.middlewares,
|
695
|
+
inputValidationIndex: options.inputValidationIndex,
|
696
|
+
outputValidationIndex: options.outputValidationIndex
|
697
|
+
});
|
698
|
+
return implementer;
|
699
|
+
}
|
700
|
+
const chainable = {};
|
265
701
|
for (const key in contract) {
|
266
|
-
|
267
|
-
if (isContractProcedure(item)) {
|
268
|
-
result[key] = new ProcedureImplementer({
|
269
|
-
contract: item,
|
270
|
-
middlewares
|
271
|
-
});
|
272
|
-
} else {
|
273
|
-
result[key] = chainRouterImplementer(item, middlewares);
|
274
|
-
}
|
702
|
+
chainable[key] = createChainableImplementer(contract[key], options);
|
275
703
|
}
|
276
|
-
const
|
277
|
-
|
704
|
+
const routerImplementer = new RouterImplementer({
|
705
|
+
contract,
|
706
|
+
middlewares: options.middlewares
|
707
|
+
});
|
708
|
+
const merged = new Proxy(chainable, {
|
709
|
+
get(target, key) {
|
710
|
+
const next = Reflect.get(target, key);
|
711
|
+
const method = Reflect.get(routerImplementer, key);
|
712
|
+
if (typeof key !== "string" || typeof method !== "function") {
|
713
|
+
return next;
|
714
|
+
}
|
715
|
+
if (!next) {
|
716
|
+
return method.bind(routerImplementer);
|
717
|
+
}
|
718
|
+
return createCallableObject(next, method.bind(routerImplementer));
|
719
|
+
}
|
720
|
+
});
|
721
|
+
return merged;
|
278
722
|
}
|
279
723
|
|
280
|
-
// src/builder.ts
|
281
|
-
var
|
282
|
-
|
283
|
-
|
724
|
+
// src/builder-with-middlewares.ts
|
725
|
+
var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
|
726
|
+
"~type" = "BuilderHasMiddlewares";
|
727
|
+
"~orpc";
|
728
|
+
constructor(def) {
|
729
|
+
this["~orpc"] = def;
|
284
730
|
}
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
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
|
+
});
|
290
738
|
}
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
middlewares: [...this.zz$b.middlewares || [], middleware_]
|
739
|
+
errors(errors) {
|
740
|
+
return new BuilderWithErrorsMiddlewares({
|
741
|
+
...this["~orpc"],
|
742
|
+
errorMap: errors
|
296
743
|
});
|
297
744
|
}
|
298
|
-
/**
|
299
|
-
* Convert to ContractProcedureBuilder
|
300
|
-
*/
|
301
745
|
route(route) {
|
302
746
|
return new ProcedureBuilder({
|
303
|
-
|
304
|
-
contract: new
|
305
|
-
route
|
747
|
+
...this["~orpc"],
|
748
|
+
contract: new ContractProcedure3({
|
749
|
+
route: {
|
750
|
+
...this["~orpc"].config.initialRoute,
|
751
|
+
...route
|
752
|
+
},
|
306
753
|
InputSchema: void 0,
|
307
|
-
OutputSchema: void 0
|
754
|
+
OutputSchema: void 0,
|
755
|
+
errorMap: {}
|
308
756
|
})
|
309
757
|
});
|
310
758
|
}
|
311
759
|
input(schema, example) {
|
312
|
-
return new
|
313
|
-
|
314
|
-
contract: new
|
760
|
+
return new ProcedureBuilderWithInput({
|
761
|
+
...this["~orpc"],
|
762
|
+
contract: new ContractProcedure3({
|
763
|
+
route: this["~orpc"].config.initialRoute,
|
315
764
|
OutputSchema: void 0,
|
316
765
|
InputSchema: schema,
|
317
|
-
inputExample: example
|
766
|
+
inputExample: example,
|
767
|
+
errorMap: {}
|
318
768
|
})
|
319
769
|
});
|
320
770
|
}
|
321
771
|
output(schema, example) {
|
322
|
-
return new
|
323
|
-
|
324
|
-
contract: new
|
772
|
+
return new ProcedureBuilderWithOutput({
|
773
|
+
...this["~orpc"],
|
774
|
+
contract: new ContractProcedure3({
|
775
|
+
route: this["~orpc"].config.initialRoute,
|
325
776
|
InputSchema: void 0,
|
326
777
|
OutputSchema: schema,
|
327
|
-
outputExample: example
|
778
|
+
outputExample: example,
|
779
|
+
errorMap: {}
|
328
780
|
})
|
329
781
|
});
|
330
782
|
}
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
}),
|
342
|
-
func
|
343
|
-
}
|
783
|
+
handler(handler) {
|
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
|
+
}),
|
792
|
+
handler
|
344
793
|
});
|
345
794
|
}
|
346
|
-
|
347
|
-
|
348
|
-
|
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
|
+
}
|
349
821
|
contract(contract) {
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
822
|
+
return createChainableImplementer(contract, this["~orpc"]);
|
823
|
+
}
|
824
|
+
};
|
825
|
+
|
826
|
+
// src/builder.ts
|
827
|
+
var Builder = class _Builder {
|
828
|
+
"~type" = "Builder";
|
829
|
+
"~orpc";
|
830
|
+
constructor(def) {
|
831
|
+
this["~orpc"] = def;
|
832
|
+
}
|
833
|
+
config(config) {
|
834
|
+
return new _Builder({
|
835
|
+
...this["~orpc"],
|
836
|
+
config: {
|
837
|
+
...this["~orpc"].config,
|
838
|
+
...config
|
839
|
+
}
|
840
|
+
});
|
841
|
+
}
|
842
|
+
context() {
|
843
|
+
return this;
|
360
844
|
}
|
361
|
-
/**
|
362
|
-
* Create ExtendedMiddleware
|
363
|
-
*/
|
364
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
365
|
-
// solution (maybe): create new generic for .output() method
|
366
845
|
middleware(middleware) {
|
367
846
|
return decorateMiddleware(middleware);
|
368
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
|
+
}
|
863
|
+
route(route) {
|
864
|
+
return new ProcedureBuilder({
|
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
|
+
},
|
873
|
+
InputSchema: void 0,
|
874
|
+
OutputSchema: void 0,
|
875
|
+
errorMap: {}
|
876
|
+
})
|
877
|
+
});
|
878
|
+
}
|
879
|
+
input(schema, example) {
|
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,
|
886
|
+
OutputSchema: void 0,
|
887
|
+
InputSchema: schema,
|
888
|
+
inputExample: example,
|
889
|
+
errorMap: {}
|
890
|
+
})
|
891
|
+
});
|
892
|
+
}
|
893
|
+
output(schema, example) {
|
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,
|
900
|
+
InputSchema: void 0,
|
901
|
+
OutputSchema: schema,
|
902
|
+
outputExample: example,
|
903
|
+
errorMap: {}
|
904
|
+
})
|
905
|
+
});
|
906
|
+
}
|
907
|
+
handler(handler) {
|
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,
|
914
|
+
InputSchema: void 0,
|
915
|
+
OutputSchema: void 0,
|
916
|
+
errorMap: {}
|
917
|
+
}),
|
918
|
+
handler
|
919
|
+
});
|
920
|
+
}
|
369
921
|
prefix(prefix) {
|
370
922
|
return new RouterBuilder({
|
371
|
-
|
923
|
+
middlewares: [],
|
924
|
+
errorMap: {},
|
372
925
|
prefix
|
373
926
|
});
|
374
927
|
}
|
375
|
-
|
928
|
+
tag(...tags) {
|
376
929
|
return new RouterBuilder({
|
377
|
-
|
930
|
+
middlewares: [],
|
931
|
+
errorMap: {},
|
378
932
|
tags
|
379
933
|
});
|
380
934
|
}
|
381
|
-
/**
|
382
|
-
* Create DecoratedRouter
|
383
|
-
*/
|
384
935
|
router(router) {
|
385
|
-
return new RouterBuilder(
|
936
|
+
return new RouterBuilder({
|
937
|
+
middlewares: [],
|
938
|
+
errorMap: []
|
939
|
+
}).router(router);
|
386
940
|
}
|
387
941
|
lazy(loader) {
|
388
|
-
return new RouterBuilder(
|
942
|
+
return new RouterBuilder({
|
943
|
+
middlewares: [],
|
944
|
+
errorMap: {}
|
945
|
+
}).lazy(loader);
|
946
|
+
}
|
947
|
+
contract(contract) {
|
948
|
+
return createChainableImplementer(contract, {
|
949
|
+
middlewares: [],
|
950
|
+
inputValidationIndex: 0,
|
951
|
+
outputValidationIndex: 0
|
952
|
+
});
|
389
953
|
}
|
390
954
|
};
|
391
955
|
|
392
|
-
// src/
|
393
|
-
function
|
394
|
-
return
|
956
|
+
// src/procedure-utils.ts
|
957
|
+
function call(procedure, input, ...rest) {
|
958
|
+
return createProcedureClient(procedure, ...rest)(input);
|
395
959
|
}
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
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
|
+
|
977
|
+
// src/router-client.ts
|
978
|
+
function createRouterClient(router, ...rest) {
|
979
|
+
if (isProcedure(router)) {
|
980
|
+
const caller = createProcedureClient(router, ...rest);
|
981
|
+
return caller;
|
982
|
+
}
|
983
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
403
984
|
const recursive = new Proxy(procedureCaller, {
|
404
985
|
get(target, key) {
|
405
986
|
if (typeof key !== "string") {
|
406
987
|
return Reflect.get(target, key);
|
407
988
|
}
|
408
|
-
const next =
|
409
|
-
|
989
|
+
const next = getRouterChild(router, key);
|
990
|
+
if (!next) {
|
991
|
+
return Reflect.get(target, key);
|
992
|
+
}
|
993
|
+
const [options] = rest;
|
994
|
+
return createRouterClient(next, {
|
410
995
|
...options,
|
411
|
-
|
412
|
-
basePath: [...options.basePath ?? [], key]
|
996
|
+
path: [...options?.path ?? [], key]
|
413
997
|
});
|
414
998
|
}
|
415
999
|
});
|
@@ -417,31 +1001,43 @@ function createRouterCallerInternal(options) {
|
|
417
1001
|
}
|
418
1002
|
|
419
1003
|
// src/index.ts
|
420
|
-
|
421
|
-
var os = new Builder(
|
1004
|
+
import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
1005
|
+
var os = new Builder({
|
1006
|
+
config: {}
|
1007
|
+
});
|
422
1008
|
export {
|
423
1009
|
Builder,
|
1010
|
+
DecoratedProcedure,
|
424
1011
|
LAZY_LOADER_SYMBOL,
|
425
|
-
|
1012
|
+
ORPCError,
|
426
1013
|
Procedure,
|
427
1014
|
ProcedureBuilder,
|
428
1015
|
ProcedureImplementer,
|
429
|
-
ROUTER_CONTRACT_SYMBOL,
|
430
1016
|
RouterBuilder,
|
431
1017
|
RouterImplementer,
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
1018
|
+
call,
|
1019
|
+
createChainableImplementer,
|
1020
|
+
createORPCErrorConstructorMap,
|
1021
|
+
createProcedureClient,
|
1022
|
+
createRouterClient,
|
437
1023
|
decorateLazy,
|
438
1024
|
decorateMiddleware,
|
439
|
-
|
1025
|
+
deepSetLazyRouterPrefix,
|
1026
|
+
fallbackConfig,
|
1027
|
+
flatLazy,
|
1028
|
+
getLazyRouterPrefix,
|
1029
|
+
getRouterChild,
|
1030
|
+
getRouterContract,
|
1031
|
+
isDefinedError,
|
440
1032
|
isLazy,
|
441
1033
|
isProcedure,
|
442
|
-
|
443
|
-
loadProcedure,
|
1034
|
+
lazy,
|
444
1035
|
mergeContext,
|
445
|
-
|
1036
|
+
middlewareOutputFn,
|
1037
|
+
os,
|
1038
|
+
safe,
|
1039
|
+
setRouterContract,
|
1040
|
+
type,
|
1041
|
+
unlazy
|
446
1042
|
};
|
447
1043
|
//# sourceMappingURL=index.js.map
|