@orpc/server 0.0.0-next.e9dc36e → 0.0.0-next.ed15210
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-6YJ5NGUE.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/chunk-XHFINNVL.js +217 -0
- package/dist/fetch.js +12 -678
- package/dist/hono.js +30 -0
- package/dist/index.js +918 -269
- 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 +49 -0
- package/dist/src/builder-with-errors.d.ts +49 -0
- package/dist/src/builder-with-middlewares.d.ts +49 -0
- package/dist/src/builder.d.ts +42 -45
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +10 -0
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +4 -0
- package/dist/src/implementer-chainable.d.ts +16 -0
- package/dist/src/index.d.ts +16 -5
- package/dist/src/lazy-decorated.d.ts +8 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +18 -0
- package/dist/src/middleware-decorated.d.ts +9 -0
- package/dist/src/middleware.d.ts +30 -17
- package/dist/src/procedure-builder-with-input.d.ts +35 -0
- package/dist/src/procedure-builder-with-output.d.ts +34 -0
- package/dist/src/procedure-builder.d.ts +26 -29
- package/dist/src/procedure-client.d.ts +21 -0
- package/dist/src/procedure-decorated.d.ts +25 -0
- package/dist/src/procedure-implementer.d.ts +21 -16
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +43 -25
- package/dist/src/router-builder.d.ts +31 -20
- package/dist/src/router-client.d.ts +26 -0
- package/dist/src/router-implementer.d.ts +21 -17
- package/dist/src/router-utils.d.ts +15 -0
- package/dist/src/router.d.ts +14 -15
- package/dist/src/types.d.ts +8 -5
- package/package.json +29 -21
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/chunk-TDFYNRZV.js.map +0 -1
- package/dist/fetch.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/src/adapters/fetch.d.ts +0 -42
- package/dist/src/adapters/fetch.d.ts.map +0 -1
- package/dist/src/builder.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/middleware.d.ts.map +0 -1
- package/dist/src/procedure-builder.d.ts.map +0 -1
- package/dist/src/procedure-caller.d.ts +0 -19
- package/dist/src/procedure-caller.d.ts.map +0 -1
- package/dist/src/procedure-implementer.d.ts.map +0 -1
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router-builder.d.ts.map +0 -1
- package/dist/src/router-caller.d.ts +0 -22
- package/dist/src/router-caller.d.ts.map +0 -1
- package/dist/src/router-implementer.d.ts.map +0 -1
- package/dist/src/router.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils.d.ts +0 -3
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/adapters/fetch.test.ts +0 -629
- package/src/adapters/fetch.ts +0 -290
- package/src/builder.test.ts +0 -371
- package/src/builder.ts +0 -238
- package/src/index.ts +0 -16
- package/src/middleware.test.ts +0 -260
- package/src/middleware.ts +0 -136
- package/src/procedure-builder.test.ts +0 -223
- package/src/procedure-builder.ts +0 -158
- package/src/procedure-caller.test.ts +0 -171
- package/src/procedure-caller.ts +0 -138
- package/src/procedure-implementer.test.ts +0 -220
- package/src/procedure-implementer.ts +0 -102
- package/src/procedure.test.ts +0 -317
- package/src/procedure.ts +0 -237
- package/src/router-builder.test.ts +0 -106
- package/src/router-builder.ts +0 -122
- package/src/router-caller.test.ts +0 -126
- package/src/router-caller.ts +0 -64
- package/src/router-implementer.test.ts +0 -116
- package/src/router-implementer.ts +0 -113
- package/src/router.test-d.ts +0 -48
- package/src/router.test.ts +0 -142
- package/src/router.ts +0 -91
- package/src/types.test.ts +0 -18
- package/src/types.ts +0 -13
- package/src/utils.test.ts +0 -16
- package/src/utils.ts +0 -16
package/dist/index.js
CHANGED
@@ -1,394 +1,1043 @@
|
|
1
1
|
import {
|
2
|
+
LAZY_LOADER_SYMBOL,
|
2
3
|
Procedure,
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
createORPCErrorConstructorMap,
|
5
|
+
createProcedureClient,
|
6
|
+
flatLazy,
|
7
|
+
getRouterChild,
|
8
|
+
isLazy,
|
6
9
|
isProcedure,
|
7
|
-
|
8
|
-
|
10
|
+
lazy,
|
11
|
+
middlewareOutputFn,
|
12
|
+
unlazy
|
13
|
+
} from "./chunk-XHFINNVL.js";
|
9
14
|
|
10
15
|
// src/builder.ts
|
11
|
-
import {
|
12
|
-
|
13
|
-
|
14
|
-
} from "@orpc/contract";
|
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";
|
15
23
|
|
16
24
|
// src/procedure-builder.ts
|
17
|
-
import {
|
18
|
-
|
19
|
-
|
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
|
+
};
|
20
131
|
|
21
132
|
// src/procedure-implementer.ts
|
22
133
|
var ProcedureImplementer = class _ProcedureImplementer {
|
23
|
-
|
24
|
-
|
134
|
+
"~type" = "ProcedureImplementer";
|
135
|
+
"~orpc";
|
136
|
+
constructor(def) {
|
137
|
+
this["~orpc"] = def;
|
25
138
|
}
|
26
139
|
use(middleware, mapInput) {
|
27
|
-
const
|
140
|
+
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
28
141
|
return new _ProcedureImplementer({
|
29
|
-
...this
|
30
|
-
middlewares: [...this.
|
142
|
+
...this["~orpc"],
|
143
|
+
middlewares: [...this["~orpc"].middlewares, mappedMiddleware]
|
31
144
|
});
|
32
145
|
}
|
33
|
-
|
34
|
-
return
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
40
234
|
});
|
41
235
|
}
|
42
236
|
};
|
43
237
|
|
44
238
|
// src/procedure-builder.ts
|
45
239
|
var ProcedureBuilder = class _ProcedureBuilder {
|
46
|
-
|
47
|
-
|
240
|
+
"~type" = "ProcedureBuilder";
|
241
|
+
"~orpc";
|
242
|
+
constructor(def) {
|
243
|
+
this["~orpc"] = def;
|
48
244
|
}
|
49
|
-
|
50
|
-
* Self chainable
|
51
|
-
*/
|
52
|
-
route(opts) {
|
245
|
+
errors(errors) {
|
53
246
|
return new _ProcedureBuilder({
|
54
|
-
...this
|
55
|
-
contract:
|
56
|
-
opts
|
57
|
-
)
|
247
|
+
...this["~orpc"],
|
248
|
+
contract: DecoratedContractProcedure4.decorate(this["~orpc"].contract).errors(errors)
|
58
249
|
});
|
59
250
|
}
|
60
|
-
|
251
|
+
route(route) {
|
61
252
|
return new _ProcedureBuilder({
|
62
|
-
...this
|
63
|
-
contract:
|
64
|
-
schema,
|
65
|
-
example
|
66
|
-
)
|
253
|
+
...this["~orpc"],
|
254
|
+
contract: DecoratedContractProcedure4.decorate(this["~orpc"].contract).route(route)
|
67
255
|
});
|
68
256
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
)
|
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]
|
76
263
|
});
|
264
|
+
return builder;
|
77
265
|
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}).use(middleware);
|
84
|
-
}
|
85
|
-
return new ProcedureImplementer({
|
86
|
-
contract: this.zz$pb.contract,
|
87
|
-
middlewares: this.zz$pb.middlewares
|
88
|
-
}).use(middleware, mapInput);
|
266
|
+
input(schema, example) {
|
267
|
+
return new ProcedureBuilderWithInput({
|
268
|
+
...this["~orpc"],
|
269
|
+
contract: new ContractProcedureBuilder(this["~orpc"].contract["~orpc"]).input(schema, example)
|
270
|
+
});
|
89
271
|
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
100
282
|
});
|
101
283
|
}
|
102
284
|
};
|
103
285
|
|
104
286
|
// src/router-builder.ts
|
105
|
-
import {
|
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
|
106
325
|
var RouterBuilder = class _RouterBuilder {
|
107
|
-
|
108
|
-
|
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
|
+
}
|
109
336
|
}
|
110
337
|
prefix(prefix) {
|
111
338
|
return new _RouterBuilder({
|
112
|
-
...this
|
113
|
-
prefix:
|
339
|
+
...this["~orpc"],
|
340
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
114
341
|
});
|
115
342
|
}
|
116
|
-
|
117
|
-
if (!tags.length)
|
118
|
-
return this;
|
343
|
+
tag(...tags) {
|
119
344
|
return new _RouterBuilder({
|
120
|
-
...this
|
121
|
-
tags: [
|
345
|
+
...this["~orpc"],
|
346
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
122
347
|
});
|
123
348
|
}
|
124
|
-
|
125
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
349
|
+
errors(errors) {
|
126
350
|
return new _RouterBuilder({
|
127
|
-
...this
|
128
|
-
|
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]
|
129
364
|
});
|
365
|
+
return builder;
|
130
366
|
}
|
131
367
|
router(router) {
|
132
|
-
const
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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);
|
157
400
|
}
|
158
|
-
|
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);
|
159
506
|
}
|
160
507
|
};
|
161
508
|
|
162
|
-
// src/
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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
|
+
});
|
169
631
|
}
|
170
632
|
router(router) {
|
171
|
-
|
172
|
-
|
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);
|
173
643
|
}
|
174
644
|
};
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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);
|
186
667
|
}
|
668
|
+
return decorated;
|
669
|
+
}
|
670
|
+
const applied = {};
|
671
|
+
for (const key in router) {
|
672
|
+
applied[key] = unshiftMiddlewaresRouter(router[key], options);
|
187
673
|
}
|
188
|
-
|
189
|
-
return Object.assign(implementer, result);
|
674
|
+
return applied;
|
190
675
|
}
|
191
|
-
|
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 = {};
|
192
713
|
for (const key in contract) {
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
`Mismatch implementation for procedure at [${currentPath.join(".")}]`
|
206
|
-
);
|
207
|
-
}
|
208
|
-
} else {
|
209
|
-
throw new Error(
|
210
|
-
`Mismatch implementation for procedure at [${currentPath.join(".")}]`
|
211
|
-
);
|
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;
|
212
726
|
}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
currentPath
|
218
|
-
);
|
727
|
+
if (!next) {
|
728
|
+
return method.bind(routerImplementer);
|
729
|
+
}
|
730
|
+
return createCallableObject(next, method.bind(routerImplementer));
|
219
731
|
}
|
220
|
-
}
|
732
|
+
});
|
733
|
+
return merged;
|
221
734
|
}
|
222
735
|
|
223
|
-
// src/builder.ts
|
224
|
-
var
|
225
|
-
|
226
|
-
|
736
|
+
// src/builder-with-middlewares.ts
|
737
|
+
var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
|
738
|
+
"~type" = "BuilderHasMiddlewares";
|
739
|
+
"~orpc";
|
740
|
+
constructor(def) {
|
741
|
+
this["~orpc"] = def;
|
227
742
|
}
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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;
|
233
751
|
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
middlewares: [...this.zz$b.middlewares || [], middleware_]
|
752
|
+
errors(errors) {
|
753
|
+
return new BuilderWithErrorsMiddlewares({
|
754
|
+
...this["~orpc"],
|
755
|
+
errorMap: errors
|
239
756
|
});
|
240
757
|
}
|
241
|
-
|
242
|
-
* Convert to ContractProcedureBuilder
|
243
|
-
*/
|
244
|
-
route(opts) {
|
758
|
+
route(route) {
|
245
759
|
return new ProcedureBuilder({
|
246
|
-
|
247
|
-
contract: new
|
248
|
-
|
760
|
+
...this["~orpc"],
|
761
|
+
contract: new ContractProcedure3({
|
762
|
+
route: {
|
763
|
+
...this["~orpc"].config.initialRoute,
|
764
|
+
...route
|
765
|
+
},
|
249
766
|
InputSchema: void 0,
|
250
|
-
OutputSchema: void 0
|
767
|
+
OutputSchema: void 0,
|
768
|
+
errorMap: {}
|
251
769
|
})
|
252
770
|
});
|
253
771
|
}
|
254
772
|
input(schema, example) {
|
255
|
-
return new
|
256
|
-
|
257
|
-
contract: new
|
773
|
+
return new ProcedureBuilderWithInput({
|
774
|
+
...this["~orpc"],
|
775
|
+
contract: new ContractProcedure3({
|
776
|
+
route: fallbackContractConfig3("defaultInitialRoute", this["~orpc"].config.initialRoute),
|
258
777
|
OutputSchema: void 0,
|
259
778
|
InputSchema: schema,
|
260
|
-
inputExample: example
|
779
|
+
inputExample: example,
|
780
|
+
errorMap: {}
|
261
781
|
})
|
262
782
|
});
|
263
783
|
}
|
264
784
|
output(schema, example) {
|
265
|
-
return new
|
266
|
-
|
267
|
-
contract: new
|
785
|
+
return new ProcedureBuilderWithOutput({
|
786
|
+
...this["~orpc"],
|
787
|
+
contract: new ContractProcedure3({
|
788
|
+
route: fallbackContractConfig3("defaultInitialRoute", this["~orpc"].config.initialRoute),
|
268
789
|
InputSchema: void 0,
|
269
790
|
OutputSchema: schema,
|
270
|
-
outputExample: example
|
791
|
+
outputExample: example,
|
792
|
+
errorMap: {}
|
271
793
|
})
|
272
794
|
});
|
273
795
|
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
}),
|
285
|
-
func
|
286
|
-
}
|
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
|
287
806
|
});
|
288
807
|
}
|
289
|
-
|
290
|
-
|
291
|
-
|
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
|
+
}
|
292
828
|
contract(contract) {
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
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;
|
303
851
|
}
|
304
|
-
/**
|
305
|
-
* Create ExtendedMiddleware
|
306
|
-
*/
|
307
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
308
|
-
// solution (maybe): create new generic for .output() method
|
309
852
|
middleware(middleware) {
|
310
853
|
return decorateMiddleware(middleware);
|
311
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
|
+
}
|
312
929
|
prefix(prefix) {
|
313
930
|
return new RouterBuilder({
|
314
|
-
|
931
|
+
middlewares: [],
|
932
|
+
errorMap: {},
|
315
933
|
prefix
|
316
934
|
});
|
317
935
|
}
|
318
|
-
|
936
|
+
tag(...tags) {
|
319
937
|
return new RouterBuilder({
|
320
|
-
|
938
|
+
middlewares: [],
|
939
|
+
errorMap: {},
|
321
940
|
tags
|
322
941
|
});
|
323
942
|
}
|
324
|
-
/**
|
325
|
-
* Create DecoratedRouter
|
326
|
-
*/
|
327
943
|
router(router) {
|
328
|
-
return
|
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
|
+
});
|
329
955
|
}
|
330
956
|
};
|
331
957
|
|
332
|
-
// src/
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
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
|
+
`);
|
346
973
|
}
|
347
|
-
|
348
|
-
|
974
|
+
return { default: maybeProcedure };
|
975
|
+
});
|
976
|
+
return lazyProcedure;
|
349
977
|
}
|
350
978
|
|
351
|
-
// src/router-
|
352
|
-
function
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
}
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
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]
|
368
999
|
});
|
369
1000
|
}
|
370
|
-
}
|
371
|
-
return
|
1001
|
+
});
|
1002
|
+
return recursive;
|
372
1003
|
}
|
373
1004
|
|
374
1005
|
// src/index.ts
|
375
|
-
|
376
|
-
var os = new Builder(
|
1006
|
+
import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
1007
|
+
var os = new Builder({
|
1008
|
+
config: {}
|
1009
|
+
});
|
377
1010
|
export {
|
378
1011
|
Builder,
|
1012
|
+
DecoratedProcedure,
|
1013
|
+
LAZY_LOADER_SYMBOL,
|
1014
|
+
ORPCError,
|
379
1015
|
Procedure,
|
380
1016
|
ProcedureBuilder,
|
381
1017
|
ProcedureImplementer,
|
1018
|
+
RouterBuilder,
|
382
1019
|
RouterImplementer,
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
1020
|
+
call,
|
1021
|
+
createChainableImplementer,
|
1022
|
+
createORPCErrorConstructorMap,
|
1023
|
+
createProcedureClient,
|
1024
|
+
createRouterClient,
|
1025
|
+
decorateLazy,
|
387
1026
|
decorateMiddleware,
|
388
|
-
|
1027
|
+
deepSetLazyRouterPrefix,
|
1028
|
+
fallbackConfig,
|
1029
|
+
flatLazy,
|
1030
|
+
getLazyRouterPrefix,
|
1031
|
+
getRouterChild,
|
1032
|
+
isDefinedError,
|
1033
|
+
isLazy,
|
389
1034
|
isProcedure,
|
390
|
-
|
1035
|
+
lazy,
|
1036
|
+
middlewareOutputFn,
|
391
1037
|
os,
|
392
|
-
|
1038
|
+
safe,
|
1039
|
+
type,
|
1040
|
+
unlazy,
|
1041
|
+
unshiftMiddlewaresRouter
|
393
1042
|
};
|
394
1043
|
//# sourceMappingURL=index.js.map
|