@orpc/server 0.0.0-next.eb37cbe → 0.0.0-next.ed15210
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6YJ5NGUE.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/chunk-XHFINNVL.js +217 -0
- package/dist/fetch.js +10 -310
- package/dist/hono.js +30 -0
- package/dist/index.js +718 -193
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/{fetch → adapters/fetch}/index.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/{fetch → adapters/fetch}/orpc-payload-codec.d.ts +1 -1
- package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +2 -2
- 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 +35 -24
- 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 +1 -3
- package/dist/src/implementer-chainable.d.ts +11 -5
- package/dist/src/index.d.ts +7 -4
- package/dist/src/lazy-decorated.d.ts +4 -6
- package/dist/src/middleware-decorated.d.ts +6 -5
- package/dist/src/middleware.d.ts +29 -13
- 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 +24 -18
- package/dist/src/procedure-client.d.ts +9 -22
- package/dist/src/procedure-decorated.d.ts +22 -11
- package/dist/src/procedure-implementer.d.ts +18 -13
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +37 -13
- package/dist/src/router-builder.d.ts +20 -16
- package/dist/src/router-client.d.ts +7 -6
- package/dist/src/router-implementer.d.ts +15 -12
- package/dist/src/router-utils.d.ts +15 -0
- package/dist/src/router.d.ts +9 -6
- package/dist/src/types.d.ts +2 -3
- package/package.json +24 -8
- package/dist/chunk-37HIYNDO.js +0 -182
- package/dist/src/fetch/composite-handler.d.ts +0 -8
- package/dist/src/fetch/orpc-handler.d.ts +0 -20
- package/dist/src/fetch/types.d.ts +0 -16
- package/dist/src/utils.d.ts +0 -3
- /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
package/dist/index.js
CHANGED
@@ -1,39 +1,48 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
+
createORPCErrorConstructorMap,
|
4
5
|
createProcedureClient,
|
5
6
|
flatLazy,
|
6
7
|
getRouterChild,
|
7
8
|
isLazy,
|
8
9
|
isProcedure,
|
9
10
|
lazy,
|
10
|
-
|
11
|
+
middlewareOutputFn,
|
11
12
|
unlazy
|
12
|
-
} from "./chunk-
|
13
|
+
} from "./chunk-XHFINNVL.js";
|
13
14
|
|
14
15
|
// src/builder.ts
|
15
|
-
import { ContractProcedure } from "@orpc/contract";
|
16
|
+
import { ContractProcedure as ContractProcedure4, fallbackContractConfig as fallbackContractConfig4 } from "@orpc/contract";
|
16
17
|
|
17
|
-
// src/
|
18
|
-
import {
|
19
|
-
|
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";
|
20
29
|
|
21
30
|
// src/middleware-decorated.ts
|
22
31
|
function decorateMiddleware(middleware) {
|
23
32
|
const decorated = middleware;
|
24
33
|
decorated.mapInput = (mapInput) => {
|
25
34
|
const mapped = decorateMiddleware(
|
26
|
-
(input, ...rest) => middleware(mapInput(input), ...rest)
|
35
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
27
36
|
);
|
28
37
|
return mapped;
|
29
38
|
};
|
30
39
|
decorated.concat = (concatMiddleware, mapInput) => {
|
31
40
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
32
|
-
const concatted = decorateMiddleware((
|
33
|
-
const next = async (
|
34
|
-
return mapped(
|
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);
|
35
44
|
};
|
36
|
-
const merged = middleware(
|
45
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
37
46
|
return merged;
|
38
47
|
});
|
39
48
|
return concatted;
|
@@ -43,58 +52,82 @@ function decorateMiddleware(middleware) {
|
|
43
52
|
|
44
53
|
// src/procedure-decorated.ts
|
45
54
|
import { DecoratedContractProcedure } from "@orpc/contract";
|
46
|
-
|
47
|
-
|
48
|
-
procedure
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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) {
|
67
81
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
68
|
-
return
|
69
|
-
...
|
70
|
-
middlewares: [...
|
71
|
-
})
|
72
|
-
}
|
73
|
-
|
74
|
-
return
|
75
|
-
...
|
76
|
-
contract: DecoratedContractProcedure.decorate(
|
77
|
-
})
|
78
|
-
}
|
79
|
-
|
80
|
-
|
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) {
|
81
96
|
let min = 0;
|
82
|
-
for (let i = 0; i <
|
83
|
-
const index =
|
97
|
+
for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
|
98
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
|
84
99
|
if (index === -1) {
|
85
|
-
|
100
|
+
castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
|
86
101
|
break;
|
87
102
|
}
|
88
103
|
min = index + 1;
|
89
104
|
}
|
90
105
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
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
|
+
};
|
98
131
|
|
99
132
|
// src/procedure-implementer.ts
|
100
133
|
var ProcedureImplementer = class _ProcedureImplementer {
|
@@ -107,33 +140,153 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
107
140
|
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
108
141
|
return new _ProcedureImplementer({
|
109
142
|
...this["~orpc"],
|
110
|
-
middlewares: [...this["~orpc"].middlewares
|
143
|
+
middlewares: [...this["~orpc"].middlewares, mappedMiddleware]
|
111
144
|
});
|
112
145
|
}
|
113
146
|
handler(handler) {
|
114
|
-
return
|
115
|
-
|
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({
|
116
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"],
|
117
233
|
handler
|
118
|
-
})
|
234
|
+
});
|
119
235
|
}
|
120
236
|
};
|
121
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
|
+
|
122
289
|
// src/hidden.ts
|
123
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
124
|
-
function setRouterContract(obj, contract) {
|
125
|
-
return new Proxy(obj, {
|
126
|
-
get(target, key) {
|
127
|
-
if (key === ROUTER_CONTRACT_SYMBOL) {
|
128
|
-
return contract;
|
129
|
-
}
|
130
|
-
return Reflect.get(target, key);
|
131
|
-
}
|
132
|
-
});
|
133
|
-
}
|
134
|
-
function getRouterContract(obj) {
|
135
|
-
return obj[ROUTER_CONTRACT_SYMBOL];
|
136
|
-
}
|
137
290
|
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
138
291
|
function deepSetLazyRouterPrefix(router, prefix) {
|
139
292
|
return new Proxy(router, {
|
@@ -153,31 +306,10 @@ function getLazyRouterPrefix(obj) {
|
|
153
306
|
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
154
307
|
}
|
155
308
|
|
156
|
-
// src/lazy-utils.ts
|
157
|
-
function createLazyProcedureFormAnyLazy(lazied) {
|
158
|
-
const lazyProcedure = lazy(async () => {
|
159
|
-
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
160
|
-
if (!isProcedure(maybeProcedure)) {
|
161
|
-
throw new Error(`
|
162
|
-
Expected a lazy<procedure> but got lazy<unknown>.
|
163
|
-
This should be caught by TypeScript compilation.
|
164
|
-
Please report this issue if this makes you feel uncomfortable.
|
165
|
-
`);
|
166
|
-
}
|
167
|
-
return { default: maybeProcedure };
|
168
|
-
});
|
169
|
-
return lazyProcedure;
|
170
|
-
}
|
171
|
-
|
172
309
|
// src/lazy-decorated.ts
|
173
310
|
function decorateLazy(lazied) {
|
174
311
|
const flattenLazy = flatLazy(lazied);
|
175
|
-
const
|
176
|
-
procedure: createLazyProcedureFormAnyLazy(flattenLazy),
|
177
|
-
context: void 0
|
178
|
-
});
|
179
|
-
Object.assign(procedureProcedureClient, flattenLazy);
|
180
|
-
const recursive = new Proxy(procedureProcedureClient, {
|
312
|
+
const recursive = new Proxy(flattenLazy, {
|
181
313
|
get(target, key) {
|
182
314
|
if (typeof key !== "string") {
|
183
315
|
return Reflect.get(target, key);
|
@@ -205,20 +337,32 @@ var RouterBuilder = class _RouterBuilder {
|
|
205
337
|
prefix(prefix) {
|
206
338
|
return new _RouterBuilder({
|
207
339
|
...this["~orpc"],
|
208
|
-
prefix:
|
340
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
209
341
|
});
|
210
342
|
}
|
211
343
|
tag(...tags) {
|
212
344
|
return new _RouterBuilder({
|
213
345
|
...this["~orpc"],
|
214
|
-
tags:
|
346
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
215
347
|
});
|
216
348
|
}
|
217
|
-
|
349
|
+
errors(errors) {
|
218
350
|
return new _RouterBuilder({
|
219
351
|
...this["~orpc"],
|
220
|
-
|
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]
|
221
364
|
});
|
365
|
+
return builder;
|
222
366
|
}
|
223
367
|
router(router) {
|
224
368
|
const adapted = adapt(router, this["~orpc"]);
|
@@ -244,7 +388,7 @@ function adapt(item, options) {
|
|
244
388
|
return adaptedLazy;
|
245
389
|
}
|
246
390
|
if (isProcedure(item)) {
|
247
|
-
let decorated =
|
391
|
+
let decorated = DecoratedProcedure.decorate(item);
|
248
392
|
if (options.tags?.length) {
|
249
393
|
decorated = decorated.unshiftTag(...options.tags);
|
250
394
|
}
|
@@ -254,6 +398,9 @@ function adapt(item, options) {
|
|
254
398
|
if (options.middlewares?.length) {
|
255
399
|
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
256
400
|
}
|
401
|
+
if (Object.keys(options.errorMap).length) {
|
402
|
+
decorated = decorated.errors(options.errorMap);
|
403
|
+
}
|
257
404
|
return decorated;
|
258
405
|
}
|
259
406
|
const adapted = {};
|
@@ -263,6 +410,270 @@ function adapt(item, options) {
|
|
263
410
|
return adapted;
|
264
411
|
}
|
265
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
|
+
|
266
677
|
// src/router-implementer.ts
|
267
678
|
var RouterImplementer = class _RouterImplementer {
|
268
679
|
"~type" = "RouterImplementer";
|
@@ -271,37 +682,41 @@ var RouterImplementer = class _RouterImplementer {
|
|
271
682
|
this["~orpc"] = def;
|
272
683
|
}
|
273
684
|
use(middleware) {
|
274
|
-
|
275
|
-
|
276
|
-
middlewares: [...this["~orpc"].middlewares
|
685
|
+
const builder = new _RouterImplementer({
|
686
|
+
contract: this["~orpc"].contract,
|
687
|
+
middlewares: [...this["~orpc"].middlewares, middleware]
|
277
688
|
});
|
689
|
+
return builder;
|
278
690
|
}
|
279
691
|
router(router) {
|
280
|
-
const
|
281
|
-
|
282
|
-
return contracted;
|
692
|
+
const applied = unshiftMiddlewaresRouter(router, this["~orpc"]);
|
693
|
+
return applied;
|
283
694
|
}
|
284
695
|
lazy(loader) {
|
285
|
-
const
|
286
|
-
|
287
|
-
return contracted;
|
696
|
+
const applied = unshiftMiddlewaresRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
697
|
+
return applied;
|
288
698
|
}
|
289
699
|
};
|
290
700
|
|
291
701
|
// src/implementer-chainable.ts
|
292
|
-
function createChainableImplementer(contract,
|
702
|
+
function createChainableImplementer(contract, options) {
|
293
703
|
if (isContractProcedure(contract)) {
|
294
704
|
const implementer = new ProcedureImplementer({
|
295
705
|
contract,
|
296
|
-
middlewares
|
706
|
+
middlewares: options.middlewares,
|
707
|
+
inputValidationIndex: options.inputValidationIndex,
|
708
|
+
outputValidationIndex: options.outputValidationIndex
|
297
709
|
});
|
298
710
|
return implementer;
|
299
711
|
}
|
300
712
|
const chainable = {};
|
301
713
|
for (const key in contract) {
|
302
|
-
chainable[key] = createChainableImplementer(contract[key],
|
714
|
+
chainable[key] = createChainableImplementer(contract[key], options);
|
303
715
|
}
|
304
|
-
const routerImplementer = new RouterImplementer({
|
716
|
+
const routerImplementer = new RouterImplementer({
|
717
|
+
contract,
|
718
|
+
middlewares: options.middlewares
|
719
|
+
});
|
305
720
|
const merged = new Proxy(chainable, {
|
306
721
|
get(target, key) {
|
307
722
|
const next = Reflect.get(target, key);
|
@@ -318,52 +733,100 @@ function createChainableImplementer(contract, middlewares) {
|
|
318
733
|
return merged;
|
319
734
|
}
|
320
735
|
|
321
|
-
// src/
|
322
|
-
|
323
|
-
|
324
|
-
} from "@orpc/contract";
|
325
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
326
|
-
"~type" = "ProcedureBuilder";
|
736
|
+
// src/builder-with-middlewares.ts
|
737
|
+
var BuilderWithMiddlewares = class _BuilderWithMiddlewares {
|
738
|
+
"~type" = "BuilderHasMiddlewares";
|
327
739
|
"~orpc";
|
328
740
|
constructor(def) {
|
329
741
|
this["~orpc"] = def;
|
330
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
|
+
}
|
331
758
|
route(route) {
|
332
|
-
return new
|
759
|
+
return new ProcedureBuilder({
|
333
760
|
...this["~orpc"],
|
334
|
-
contract:
|
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
|
+
})
|
335
770
|
});
|
336
771
|
}
|
337
772
|
input(schema, example) {
|
338
|
-
return new
|
773
|
+
return new ProcedureBuilderWithInput({
|
339
774
|
...this["~orpc"],
|
340
|
-
contract:
|
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
|
+
})
|
341
782
|
});
|
342
783
|
}
|
343
784
|
output(schema, example) {
|
344
|
-
return new
|
785
|
+
return new ProcedureBuilderWithOutput({
|
345
786
|
...this["~orpc"],
|
346
|
-
contract:
|
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
|
+
})
|
347
794
|
});
|
348
795
|
}
|
349
|
-
use(middleware, mapInput) {
|
350
|
-
if (!mapInput) {
|
351
|
-
return new ProcedureImplementer({
|
352
|
-
contract: this["~orpc"].contract,
|
353
|
-
middlewares: this["~orpc"].middlewares
|
354
|
-
}).use(middleware);
|
355
|
-
}
|
356
|
-
return new ProcedureImplementer({
|
357
|
-
contract: this["~orpc"].contract,
|
358
|
-
middlewares: this["~orpc"].middlewares
|
359
|
-
}).use(middleware, mapInput);
|
360
|
-
}
|
361
796
|
handler(handler) {
|
362
|
-
return
|
363
|
-
|
364
|
-
contract:
|
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
|
+
}),
|
365
805
|
handler
|
366
|
-
})
|
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"]);
|
367
830
|
}
|
368
831
|
};
|
369
832
|
|
@@ -374,111 +837,165 @@ var Builder = class _Builder {
|
|
374
837
|
constructor(def) {
|
375
838
|
this["~orpc"] = def;
|
376
839
|
}
|
377
|
-
|
378
|
-
return new _Builder({});
|
379
|
-
}
|
380
|
-
use(middleware) {
|
840
|
+
config(config) {
|
381
841
|
return new _Builder({
|
382
842
|
...this["~orpc"],
|
383
|
-
|
843
|
+
config: {
|
844
|
+
...this["~orpc"].config,
|
845
|
+
...config
|
846
|
+
}
|
384
847
|
});
|
385
848
|
}
|
849
|
+
context() {
|
850
|
+
return this;
|
851
|
+
}
|
386
852
|
middleware(middleware) {
|
387
853
|
return decorateMiddleware(middleware);
|
388
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
|
+
}
|
389
871
|
route(route) {
|
390
872
|
return new ProcedureBuilder({
|
391
|
-
middlewares:
|
392
|
-
|
393
|
-
|
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
|
+
},
|
394
881
|
InputSchema: void 0,
|
395
|
-
OutputSchema: void 0
|
882
|
+
OutputSchema: void 0,
|
883
|
+
errorMap: {}
|
396
884
|
})
|
397
885
|
});
|
398
886
|
}
|
399
887
|
input(schema, example) {
|
400
|
-
return new
|
401
|
-
middlewares:
|
402
|
-
|
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),
|
403
894
|
OutputSchema: void 0,
|
404
895
|
InputSchema: schema,
|
405
|
-
inputExample: example
|
896
|
+
inputExample: example,
|
897
|
+
errorMap: {}
|
406
898
|
})
|
407
899
|
});
|
408
900
|
}
|
409
901
|
output(schema, example) {
|
410
|
-
return new
|
411
|
-
middlewares:
|
412
|
-
|
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),
|
413
908
|
InputSchema: void 0,
|
414
909
|
OutputSchema: schema,
|
415
|
-
outputExample: example
|
910
|
+
outputExample: example,
|
911
|
+
errorMap: {}
|
416
912
|
})
|
417
913
|
});
|
418
914
|
}
|
419
915
|
handler(handler) {
|
420
|
-
return
|
421
|
-
middlewares:
|
422
|
-
|
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),
|
423
922
|
InputSchema: void 0,
|
424
|
-
OutputSchema: void 0
|
923
|
+
OutputSchema: void 0,
|
924
|
+
errorMap: {}
|
425
925
|
}),
|
426
926
|
handler
|
427
|
-
})
|
927
|
+
});
|
428
928
|
}
|
429
929
|
prefix(prefix) {
|
430
930
|
return new RouterBuilder({
|
431
|
-
middlewares:
|
931
|
+
middlewares: [],
|
932
|
+
errorMap: {},
|
432
933
|
prefix
|
433
934
|
});
|
434
935
|
}
|
435
936
|
tag(...tags) {
|
436
937
|
return new RouterBuilder({
|
437
|
-
middlewares:
|
938
|
+
middlewares: [],
|
939
|
+
errorMap: {},
|
438
940
|
tags
|
439
941
|
});
|
440
942
|
}
|
441
943
|
router(router) {
|
442
|
-
return
|
944
|
+
return router;
|
443
945
|
}
|
444
946
|
lazy(loader) {
|
445
|
-
return
|
947
|
+
return decorateLazy(flatLazy(lazy(loader)));
|
446
948
|
}
|
447
949
|
contract(contract) {
|
448
|
-
return createChainableImplementer(contract,
|
950
|
+
return createChainableImplementer(contract, {
|
951
|
+
middlewares: [],
|
952
|
+
inputValidationIndex: 0,
|
953
|
+
outputValidationIndex: 0
|
954
|
+
});
|
449
955
|
}
|
450
956
|
};
|
451
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
|
+
|
452
979
|
// src/router-client.ts
|
453
|
-
function createRouterClient(
|
454
|
-
if (isProcedure(
|
455
|
-
const caller = createProcedureClient(
|
456
|
-
...options,
|
457
|
-
procedure: options.router,
|
458
|
-
context: options.context,
|
459
|
-
path: options.path
|
460
|
-
});
|
980
|
+
function createRouterClient(router, ...rest) {
|
981
|
+
if (isProcedure(router)) {
|
982
|
+
const caller = createProcedureClient(router, ...rest);
|
461
983
|
return caller;
|
462
984
|
}
|
463
|
-
const procedureCaller = isLazy(
|
464
|
-
...options,
|
465
|
-
procedure: createLazyProcedureFormAnyLazy(options.router),
|
466
|
-
context: options.context,
|
467
|
-
path: options.path
|
468
|
-
}) : {};
|
985
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
469
986
|
const recursive = new Proxy(procedureCaller, {
|
470
987
|
get(target, key) {
|
471
988
|
if (typeof key !== "string") {
|
472
989
|
return Reflect.get(target, key);
|
473
990
|
}
|
474
|
-
const next = getRouterChild(
|
991
|
+
const next = getRouterChild(router, key);
|
475
992
|
if (!next) {
|
476
993
|
return Reflect.get(target, key);
|
477
994
|
}
|
478
|
-
|
995
|
+
const [options] = rest;
|
996
|
+
return createRouterClient(next, {
|
479
997
|
...options,
|
480
|
-
|
481
|
-
path: [...options.path ?? [], key]
|
998
|
+
path: [...options?.path ?? [], key]
|
482
999
|
});
|
483
1000
|
}
|
484
1001
|
});
|
@@ -486,33 +1003,41 @@ function createRouterClient(options) {
|
|
486
1003
|
}
|
487
1004
|
|
488
1005
|
// src/index.ts
|
489
|
-
|
490
|
-
var os = new Builder({
|
1006
|
+
import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
1007
|
+
var os = new Builder({
|
1008
|
+
config: {}
|
1009
|
+
});
|
491
1010
|
export {
|
492
1011
|
Builder,
|
1012
|
+
DecoratedProcedure,
|
493
1013
|
LAZY_LOADER_SYMBOL,
|
1014
|
+
ORPCError,
|
494
1015
|
Procedure,
|
495
1016
|
ProcedureBuilder,
|
496
1017
|
ProcedureImplementer,
|
497
1018
|
RouterBuilder,
|
498
1019
|
RouterImplementer,
|
1020
|
+
call,
|
499
1021
|
createChainableImplementer,
|
1022
|
+
createORPCErrorConstructorMap,
|
500
1023
|
createProcedureClient,
|
501
1024
|
createRouterClient,
|
502
1025
|
decorateLazy,
|
503
1026
|
decorateMiddleware,
|
504
|
-
decorateProcedure,
|
505
1027
|
deepSetLazyRouterPrefix,
|
1028
|
+
fallbackConfig,
|
506
1029
|
flatLazy,
|
507
1030
|
getLazyRouterPrefix,
|
508
1031
|
getRouterChild,
|
509
|
-
|
1032
|
+
isDefinedError,
|
510
1033
|
isLazy,
|
511
1034
|
isProcedure,
|
512
1035
|
lazy,
|
513
|
-
|
1036
|
+
middlewareOutputFn,
|
514
1037
|
os,
|
515
|
-
|
516
|
-
|
1038
|
+
safe,
|
1039
|
+
type,
|
1040
|
+
unlazy,
|
1041
|
+
unshiftMiddlewaresRouter
|
517
1042
|
};
|
518
1043
|
//# sourceMappingURL=index.js.map
|