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