@orpc/server 0.0.0-next.f22c7ec → 0.0.0-next.f56d2b3
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-2HRHHZJD.js → chunk-ESTRJAOX.js} +5 -7
- package/dist/chunk-KK4SDLC7.js +320 -0
- package/dist/fetch.js +2 -2
- package/dist/hono.js +3 -3
- package/dist/index.js +205 -405
- package/dist/next.js +3 -3
- package/dist/node.js +6 -6
- package/dist/src/adapters/fetch/orpc-handler.d.ts +1 -1
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +4 -4
- package/dist/src/adapters/fetch/types.d.ts +4 -4
- package/dist/src/adapters/hono/middleware.d.ts +3 -3
- package/dist/src/adapters/next/serve.d.ts +8 -8
- package/dist/src/adapters/node/orpc-handler.d.ts +2 -2
- package/dist/src/adapters/node/types.d.ts +5 -5
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +50 -31
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +5 -3
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +16 -0
- package/dist/src/implementer.d.ts +27 -0
- package/dist/src/index.d.ts +9 -13
- package/dist/src/lazy-utils.d.ts +4 -2
- package/dist/src/lazy.d.ts +9 -5
- package/dist/src/middleware-decorated.d.ts +7 -6
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +22 -21
- package/dist/src/procedure-client.d.ts +6 -8
- package/dist/src/procedure-decorated.d.ts +10 -14
- package/dist/src/procedure-utils.d.ts +2 -2
- package/dist/src/procedure.d.ts +19 -34
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +6 -10
- package/dist/src/router.d.ts +25 -12
- package/package.json +3 -3
- package/dist/chunk-SA7HGGVY.js +0 -242
- package/dist/src/error.d.ts +0 -10
- package/dist/src/implementer-chainable.d.ts +0 -10
- package/dist/src/lazy-decorated.d.ts +0 -7
- package/dist/src/procedure-builder.d.ts +0 -24
- package/dist/src/procedure-implementer.d.ts +0 -20
- package/dist/src/router-builder.d.ts +0 -31
- package/dist/src/router-implementer.d.ts +0 -21
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
package/dist/index.js
CHANGED
@@ -1,24 +1,38 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
-
|
4
|
+
adaptRouter,
|
5
|
+
addMiddleware,
|
6
|
+
createAccessibleLazyRouter,
|
7
|
+
createLazyProcedureFormAnyLazy,
|
5
8
|
createProcedureClient,
|
9
|
+
deepSetLazyRouterPrefix,
|
6
10
|
flatLazy,
|
11
|
+
getLazyRouterPrefix,
|
7
12
|
getRouterChild,
|
13
|
+
getRouterContract,
|
8
14
|
isLazy,
|
9
15
|
isProcedure,
|
10
16
|
lazy,
|
11
|
-
mergeContext,
|
12
17
|
middlewareOutputFn,
|
18
|
+
setRouterContract,
|
13
19
|
unlazy
|
14
|
-
} from "./chunk-
|
20
|
+
} from "./chunk-KK4SDLC7.js";
|
15
21
|
|
16
22
|
// src/builder.ts
|
17
|
-
import {
|
23
|
+
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
18
24
|
|
19
|
-
// src/
|
20
|
-
|
21
|
-
|
25
|
+
// src/config.ts
|
26
|
+
var DEFAULT_CONFIG = {
|
27
|
+
initialInputValidationIndex: 0,
|
28
|
+
initialOutputValidationIndex: 0
|
29
|
+
};
|
30
|
+
function fallbackConfig(key, value) {
|
31
|
+
if (value === void 0) {
|
32
|
+
return DEFAULT_CONFIG[key];
|
33
|
+
}
|
34
|
+
return value;
|
35
|
+
}
|
22
36
|
|
23
37
|
// src/middleware-decorated.ts
|
24
38
|
function decorateMiddleware(middleware) {
|
@@ -32,8 +46,8 @@ function decorateMiddleware(middleware) {
|
|
32
46
|
decorated.concat = (concatMiddleware, mapInput) => {
|
33
47
|
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
34
48
|
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
35
|
-
const next = async (nextOptions) => {
|
36
|
-
return mapped({ ...options, context:
|
49
|
+
const next = async (...[nextOptions]) => {
|
50
|
+
return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
|
37
51
|
};
|
38
52
|
const merged = middleware({ ...options, next }, input, output, ...rest);
|
39
53
|
return merged;
|
@@ -44,61 +58,31 @@ function decorateMiddleware(middleware) {
|
|
44
58
|
}
|
45
59
|
|
46
60
|
// src/procedure-decorated.ts
|
47
|
-
import {
|
61
|
+
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
48
62
|
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
49
|
-
static decorate(procedure) {
|
50
|
-
if (procedure instanceof _DecoratedProcedure) {
|
51
|
-
return procedure;
|
52
|
-
}
|
53
|
-
return new _DecoratedProcedure(procedure["~orpc"]);
|
54
|
-
}
|
55
|
-
prefix(prefix) {
|
56
|
-
return new _DecoratedProcedure({
|
57
|
-
...this["~orpc"],
|
58
|
-
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
|
59
|
-
});
|
60
|
-
}
|
61
|
-
route(route) {
|
62
|
-
return new _DecoratedProcedure({
|
63
|
-
...this["~orpc"],
|
64
|
-
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).route(route)
|
65
|
-
});
|
66
|
-
}
|
67
63
|
errors(errors) {
|
68
64
|
return new _DecoratedProcedure({
|
69
65
|
...this["~orpc"],
|
70
|
-
|
66
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
71
67
|
});
|
72
68
|
}
|
73
|
-
|
74
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
69
|
+
meta(meta) {
|
75
70
|
return new _DecoratedProcedure({
|
76
71
|
...this["~orpc"],
|
77
|
-
|
72
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
78
73
|
});
|
79
74
|
}
|
80
|
-
|
75
|
+
route(route) {
|
81
76
|
return new _DecoratedProcedure({
|
82
77
|
...this["~orpc"],
|
83
|
-
|
78
|
+
route: mergeRoute(this["~orpc"].route, route)
|
84
79
|
});
|
85
80
|
}
|
86
|
-
|
87
|
-
const
|
88
|
-
if (this["~orpc"].preMiddlewares.length) {
|
89
|
-
let min = 0;
|
90
|
-
for (let i = 0; i < this["~orpc"].preMiddlewares.length; i++) {
|
91
|
-
const index = castedMiddlewares.indexOf(this["~orpc"].preMiddlewares[i], min);
|
92
|
-
if (index === -1) {
|
93
|
-
castedMiddlewares.push(...this["~orpc"].preMiddlewares.slice(i));
|
94
|
-
break;
|
95
|
-
}
|
96
|
-
min = index + 1;
|
97
|
-
}
|
98
|
-
}
|
81
|
+
use(middleware, mapInput) {
|
82
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
99
83
|
return new _DecoratedProcedure({
|
100
84
|
...this["~orpc"],
|
101
|
-
|
85
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
102
86
|
});
|
103
87
|
}
|
104
88
|
/**
|
@@ -118,407 +102,228 @@ var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
|
118
102
|
}
|
119
103
|
};
|
120
104
|
|
121
|
-
// src/
|
122
|
-
var
|
123
|
-
"~type" = "ProcedureImplementer";
|
124
|
-
"~orpc";
|
125
|
-
constructor(def) {
|
126
|
-
this["~orpc"] = def;
|
127
|
-
}
|
128
|
-
use(middleware, mapInput) {
|
129
|
-
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
130
|
-
return new _ProcedureImplementer({
|
131
|
-
...this["~orpc"],
|
132
|
-
postMiddlewares: [...this["~orpc"].postMiddlewares, mappedMiddleware]
|
133
|
-
});
|
134
|
-
}
|
135
|
-
handler(handler) {
|
136
|
-
return new DecoratedProcedure({
|
137
|
-
postMiddlewares: this["~orpc"].postMiddlewares,
|
138
|
-
preMiddlewares: this["~orpc"].preMiddlewares,
|
139
|
-
contract: this["~orpc"].contract,
|
140
|
-
handler
|
141
|
-
});
|
142
|
-
}
|
143
|
-
};
|
144
|
-
|
145
|
-
// src/hidden.ts
|
146
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
147
|
-
function setRouterContract(obj, contract) {
|
148
|
-
return new Proxy(obj, {
|
149
|
-
get(target, key) {
|
150
|
-
if (key === ROUTER_CONTRACT_SYMBOL) {
|
151
|
-
return contract;
|
152
|
-
}
|
153
|
-
return Reflect.get(target, key);
|
154
|
-
}
|
155
|
-
});
|
156
|
-
}
|
157
|
-
function getRouterContract(obj) {
|
158
|
-
return obj[ROUTER_CONTRACT_SYMBOL];
|
159
|
-
}
|
160
|
-
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
161
|
-
function deepSetLazyRouterPrefix(router, prefix) {
|
162
|
-
return new Proxy(router, {
|
163
|
-
get(target, key) {
|
164
|
-
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
165
|
-
const val = Reflect.get(target, key);
|
166
|
-
if (val && (typeof val === "object" || typeof val === "function")) {
|
167
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
168
|
-
}
|
169
|
-
return val;
|
170
|
-
}
|
171
|
-
return prefix;
|
172
|
-
}
|
173
|
-
});
|
174
|
-
}
|
175
|
-
function getLazyRouterPrefix(obj) {
|
176
|
-
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
177
|
-
}
|
178
|
-
|
179
|
-
// src/lazy-decorated.ts
|
180
|
-
function decorateLazy(lazied) {
|
181
|
-
const flattenLazy = flatLazy(lazied);
|
182
|
-
const recursive = new Proxy(flattenLazy, {
|
183
|
-
get(target, key) {
|
184
|
-
if (typeof key !== "string") {
|
185
|
-
return Reflect.get(target, key);
|
186
|
-
}
|
187
|
-
const next = getRouterChild(flattenLazy, key);
|
188
|
-
return decorateLazy(next);
|
189
|
-
}
|
190
|
-
});
|
191
|
-
return recursive;
|
192
|
-
}
|
193
|
-
|
194
|
-
// src/router-builder.ts
|
195
|
-
var RouterBuilder = class _RouterBuilder {
|
196
|
-
"~type" = "RouterBuilder";
|
197
|
-
"~orpc";
|
198
|
-
constructor(def) {
|
199
|
-
this["~orpc"] = def;
|
200
|
-
if (def.prefix && def.prefix.includes("{")) {
|
201
|
-
throw new Error(`
|
202
|
-
Dynamic routing in prefix not supported yet.
|
203
|
-
Please remove "{" from "${def.prefix}".
|
204
|
-
`);
|
205
|
-
}
|
206
|
-
}
|
207
|
-
prefix(prefix) {
|
208
|
-
return new _RouterBuilder({
|
209
|
-
...this["~orpc"],
|
210
|
-
prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
|
211
|
-
});
|
212
|
-
}
|
213
|
-
tag(...tags) {
|
214
|
-
return new _RouterBuilder({
|
215
|
-
...this["~orpc"],
|
216
|
-
tags: [...this["~orpc"].tags ?? [], ...tags]
|
217
|
-
});
|
218
|
-
}
|
219
|
-
errors(errors) {
|
220
|
-
return new _RouterBuilder({
|
221
|
-
...this["~orpc"],
|
222
|
-
errorMap: {
|
223
|
-
...this["~orpc"].errorMap,
|
224
|
-
...errors
|
225
|
-
}
|
226
|
-
});
|
227
|
-
}
|
228
|
-
use(middleware) {
|
229
|
-
return new _RouterBuilder({
|
230
|
-
...this["~orpc"],
|
231
|
-
middlewares: [...this["~orpc"].middlewares, middleware]
|
232
|
-
});
|
233
|
-
}
|
234
|
-
router(router) {
|
235
|
-
const adapted = adapt(router, this["~orpc"]);
|
236
|
-
return adapted;
|
237
|
-
}
|
238
|
-
lazy(loader) {
|
239
|
-
const adapted = adapt(flatLazy(lazy(loader)), this["~orpc"]);
|
240
|
-
return adapted;
|
241
|
-
}
|
242
|
-
};
|
243
|
-
function adapt(item, options) {
|
244
|
-
if (isLazy(item)) {
|
245
|
-
const adaptedLazy = decorateLazy(lazy(async () => {
|
246
|
-
const routerOrProcedure = (await unlazy(item)).default;
|
247
|
-
const adapted2 = adapt(routerOrProcedure, options);
|
248
|
-
return { default: adapted2 };
|
249
|
-
}));
|
250
|
-
const lazyPrefix = getLazyRouterPrefix(item);
|
251
|
-
if (options.prefix || lazyPrefix) {
|
252
|
-
const prefixed = deepSetLazyRouterPrefix(adaptedLazy, `${options.prefix ?? ""}${lazyPrefix ?? ""}`);
|
253
|
-
return prefixed;
|
254
|
-
}
|
255
|
-
return adaptedLazy;
|
256
|
-
}
|
257
|
-
if (isProcedure(item)) {
|
258
|
-
let decorated = DecoratedProcedure.decorate(item);
|
259
|
-
if (options.tags?.length) {
|
260
|
-
decorated = decorated.unshiftTag(...options.tags);
|
261
|
-
}
|
262
|
-
if (options.prefix) {
|
263
|
-
decorated = decorated.prefix(options.prefix);
|
264
|
-
}
|
265
|
-
if (options.middlewares?.length) {
|
266
|
-
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
267
|
-
}
|
268
|
-
if (Object.keys(options.errorMap).length) {
|
269
|
-
decorated = decorated.errors(options.errorMap);
|
270
|
-
}
|
271
|
-
return decorated;
|
272
|
-
}
|
273
|
-
const adapted = {};
|
274
|
-
for (const key in item) {
|
275
|
-
adapted[key] = adapt(item[key], options);
|
276
|
-
}
|
277
|
-
return adapted;
|
278
|
-
}
|
279
|
-
|
280
|
-
// src/router-implementer.ts
|
281
|
-
var RouterImplementer = class _RouterImplementer {
|
282
|
-
"~type" = "RouterImplementer";
|
105
|
+
// src/builder.ts
|
106
|
+
var Builder = class _Builder {
|
283
107
|
"~orpc";
|
284
108
|
constructor(def) {
|
285
109
|
this["~orpc"] = def;
|
286
110
|
}
|
287
|
-
|
288
|
-
|
111
|
+
/**
|
112
|
+
* Reset config
|
113
|
+
*/
|
114
|
+
$config(config) {
|
115
|
+
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
116
|
+
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
117
|
+
return new _Builder({
|
289
118
|
...this["~orpc"],
|
290
|
-
|
119
|
+
config,
|
120
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
121
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
291
122
|
});
|
292
123
|
}
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
299
|
-
return contracted;
|
300
|
-
}
|
301
|
-
lazy(loader) {
|
302
|
-
const adapted = new RouterBuilder({
|
124
|
+
/**
|
125
|
+
* Reset initial context
|
126
|
+
*/
|
127
|
+
$context() {
|
128
|
+
return new _Builder({
|
303
129
|
...this["~orpc"],
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
return contracted;
|
308
|
-
}
|
309
|
-
};
|
310
|
-
|
311
|
-
// src/implementer-chainable.ts
|
312
|
-
function createChainableImplementer(contract, middlewares = []) {
|
313
|
-
if (isContractProcedure(contract)) {
|
314
|
-
const implementer = new ProcedureImplementer({
|
315
|
-
contract,
|
316
|
-
preMiddlewares: middlewares,
|
317
|
-
postMiddlewares: []
|
130
|
+
middlewares: [],
|
131
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
132
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
318
133
|
});
|
319
|
-
return implementer;
|
320
134
|
}
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
const merged = new Proxy(chainable, {
|
327
|
-
get(target, key) {
|
328
|
-
const next = Reflect.get(target, key);
|
329
|
-
const method = Reflect.get(routerImplementer, key);
|
330
|
-
if (typeof key !== "string" || typeof method !== "function") {
|
331
|
-
return next;
|
332
|
-
}
|
333
|
-
if (!next) {
|
334
|
-
return method.bind(routerImplementer);
|
335
|
-
}
|
336
|
-
return createCallableObject(next, method.bind(routerImplementer));
|
337
|
-
}
|
338
|
-
});
|
339
|
-
return merged;
|
340
|
-
}
|
341
|
-
|
342
|
-
// src/procedure-builder.ts
|
343
|
-
import {
|
344
|
-
DecoratedContractProcedure as DecoratedContractProcedure2
|
345
|
-
} from "@orpc/contract";
|
346
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
347
|
-
"~type" = "ProcedureBuilder";
|
348
|
-
"~orpc";
|
349
|
-
constructor(def) {
|
350
|
-
this["~orpc"] = def;
|
351
|
-
}
|
352
|
-
route(route) {
|
353
|
-
return new _ProcedureBuilder({
|
135
|
+
/**
|
136
|
+
* Reset initial meta
|
137
|
+
*/
|
138
|
+
$meta(initialMeta) {
|
139
|
+
return new _Builder({
|
354
140
|
...this["~orpc"],
|
355
|
-
|
141
|
+
meta: initialMeta
|
356
142
|
});
|
357
143
|
}
|
358
|
-
|
359
|
-
|
144
|
+
/**
|
145
|
+
* Reset initial route
|
146
|
+
*/
|
147
|
+
$route(initialRoute) {
|
148
|
+
return new _Builder({
|
360
149
|
...this["~orpc"],
|
361
|
-
|
150
|
+
route: initialRoute
|
362
151
|
});
|
363
152
|
}
|
364
|
-
|
365
|
-
return
|
366
|
-
...this["~orpc"],
|
367
|
-
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
368
|
-
});
|
153
|
+
middleware(middleware) {
|
154
|
+
return decorateMiddleware(middleware);
|
369
155
|
}
|
370
156
|
errors(errors) {
|
371
|
-
return new
|
157
|
+
return new _Builder({
|
372
158
|
...this["~orpc"],
|
373
|
-
|
159
|
+
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
374
160
|
});
|
375
161
|
}
|
376
162
|
use(middleware, mapInput) {
|
377
|
-
|
378
|
-
return new ProcedureImplementer({
|
379
|
-
contract: this["~orpc"].contract,
|
380
|
-
preMiddlewares: this["~orpc"].middlewares,
|
381
|
-
postMiddlewares: []
|
382
|
-
}).use(middleware);
|
383
|
-
}
|
384
|
-
return new ProcedureImplementer({
|
385
|
-
contract: this["~orpc"].contract,
|
386
|
-
preMiddlewares: this["~orpc"].middlewares,
|
387
|
-
postMiddlewares: []
|
388
|
-
}).use(middleware, mapInput);
|
389
|
-
}
|
390
|
-
handler(handler) {
|
391
|
-
return new DecoratedProcedure({
|
392
|
-
preMiddlewares: this["~orpc"].middlewares,
|
393
|
-
postMiddlewares: [],
|
394
|
-
contract: this["~orpc"].contract,
|
395
|
-
handler
|
396
|
-
});
|
397
|
-
}
|
398
|
-
};
|
399
|
-
|
400
|
-
// src/builder.ts
|
401
|
-
var Builder = class _Builder {
|
402
|
-
"~type" = "Builder";
|
403
|
-
"~orpc";
|
404
|
-
constructor(def) {
|
405
|
-
this["~orpc"] = def;
|
406
|
-
}
|
407
|
-
// TODO: separate it
|
408
|
-
context() {
|
409
|
-
return new _Builder({
|
410
|
-
middlewares: [],
|
411
|
-
errorMap: {}
|
412
|
-
});
|
413
|
-
}
|
414
|
-
use(middleware) {
|
163
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
415
164
|
return new _Builder({
|
416
165
|
...this["~orpc"],
|
417
|
-
middlewares:
|
166
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
418
167
|
});
|
419
168
|
}
|
420
|
-
|
169
|
+
meta(meta) {
|
421
170
|
return new _Builder({
|
422
171
|
...this["~orpc"],
|
423
|
-
|
424
|
-
...this["~orpc"].errorMap,
|
425
|
-
...errors
|
426
|
-
}
|
172
|
+
meta: mergeMeta2(this["~orpc"].meta, meta)
|
427
173
|
});
|
428
174
|
}
|
429
|
-
// TODO: not allow define middleware after has context, or anything else
|
430
|
-
middleware(middleware) {
|
431
|
-
return decorateMiddleware(middleware);
|
432
|
-
}
|
433
175
|
route(route) {
|
434
|
-
return new
|
435
|
-
|
436
|
-
|
437
|
-
route,
|
438
|
-
InputSchema: void 0,
|
439
|
-
OutputSchema: void 0,
|
440
|
-
errorMap: this["~orpc"].errorMap
|
441
|
-
})
|
176
|
+
return new _Builder({
|
177
|
+
...this["~orpc"],
|
178
|
+
route: mergeRoute2(this["~orpc"].route, route)
|
442
179
|
});
|
443
180
|
}
|
444
|
-
input(schema
|
445
|
-
return new
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
InputSchema: schema,
|
450
|
-
inputExample: example,
|
451
|
-
errorMap: this["~orpc"].errorMap
|
452
|
-
})
|
181
|
+
input(schema) {
|
182
|
+
return new _Builder({
|
183
|
+
...this["~orpc"],
|
184
|
+
inputSchema: schema,
|
185
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
453
186
|
});
|
454
187
|
}
|
455
|
-
output(schema
|
456
|
-
return new
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
OutputSchema: schema,
|
461
|
-
outputExample: example,
|
462
|
-
errorMap: this["~orpc"].errorMap
|
463
|
-
})
|
188
|
+
output(schema) {
|
189
|
+
return new _Builder({
|
190
|
+
...this["~orpc"],
|
191
|
+
outputSchema: schema,
|
192
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
464
193
|
});
|
465
194
|
}
|
466
195
|
handler(handler) {
|
467
196
|
return new DecoratedProcedure({
|
468
|
-
|
469
|
-
postMiddlewares: [],
|
470
|
-
contract: new ContractProcedure({
|
471
|
-
InputSchema: void 0,
|
472
|
-
OutputSchema: void 0,
|
473
|
-
errorMap: this["~orpc"].errorMap
|
474
|
-
}),
|
197
|
+
...this["~orpc"],
|
475
198
|
handler
|
476
199
|
});
|
477
200
|
}
|
478
201
|
prefix(prefix) {
|
479
|
-
return new
|
480
|
-
|
481
|
-
|
482
|
-
prefix
|
202
|
+
return new _Builder({
|
203
|
+
...this["~orpc"],
|
204
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
483
205
|
});
|
484
206
|
}
|
485
207
|
tag(...tags) {
|
486
|
-
return new
|
487
|
-
|
488
|
-
|
489
|
-
tags
|
208
|
+
return new _Builder({
|
209
|
+
...this["~orpc"],
|
210
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
490
211
|
});
|
491
212
|
}
|
492
213
|
router(router) {
|
493
|
-
return
|
214
|
+
return adaptRouter(router, this["~orpc"]);
|
494
215
|
}
|
495
216
|
lazy(loader) {
|
496
|
-
return
|
497
|
-
}
|
498
|
-
contract(contract) {
|
499
|
-
return createChainableImplementer(contract, this["~orpc"].middlewares);
|
217
|
+
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
500
218
|
}
|
501
219
|
};
|
220
|
+
var os = new Builder({
|
221
|
+
config: {},
|
222
|
+
route: {},
|
223
|
+
meta: {},
|
224
|
+
errorMap: {},
|
225
|
+
inputSchema: void 0,
|
226
|
+
outputSchema: void 0,
|
227
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
228
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
229
|
+
middlewares: []
|
230
|
+
});
|
502
231
|
|
503
|
-
// src/
|
504
|
-
function
|
505
|
-
return
|
232
|
+
// src/context.ts
|
233
|
+
function mergeContext(context, other) {
|
234
|
+
return { ...context, ...other };
|
506
235
|
}
|
507
236
|
|
508
|
-
// src/
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
237
|
+
// src/implementer.ts
|
238
|
+
import { isContractProcedure } from "@orpc/contract";
|
239
|
+
function implementerInternal(contract, config, middlewares) {
|
240
|
+
if (isContractProcedure(contract)) {
|
241
|
+
const impl2 = new Builder({
|
242
|
+
...contract["~orpc"],
|
243
|
+
config,
|
244
|
+
middlewares,
|
245
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
246
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
247
|
+
});
|
248
|
+
return impl2;
|
249
|
+
}
|
250
|
+
const impl = new Proxy(contract, {
|
251
|
+
get: (target, key) => {
|
252
|
+
let method;
|
253
|
+
if (key === "middleware") {
|
254
|
+
method = (mid) => decorateMiddleware(mid);
|
255
|
+
} else if (key === "use") {
|
256
|
+
method = (mid) => {
|
257
|
+
return implementerInternal(
|
258
|
+
contract,
|
259
|
+
config,
|
260
|
+
addMiddleware(middlewares, mid)
|
261
|
+
);
|
262
|
+
};
|
263
|
+
} else if (key === "router") {
|
264
|
+
method = (router) => {
|
265
|
+
const adapted = adaptRouter(router, {
|
266
|
+
middlewares,
|
267
|
+
errorMap: {}
|
268
|
+
});
|
269
|
+
return setRouterContract(adapted, contract);
|
270
|
+
};
|
271
|
+
} else if (key === "lazy") {
|
272
|
+
method = (loader) => {
|
273
|
+
const adapted = adaptRouter(flatLazy(lazy(loader)), {
|
274
|
+
middlewares,
|
275
|
+
errorMap: {}
|
276
|
+
});
|
277
|
+
return setRouterContract(adapted, contract);
|
278
|
+
};
|
279
|
+
}
|
280
|
+
const next = Reflect.get(target, key);
|
281
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
282
|
+
return method ?? next;
|
283
|
+
}
|
284
|
+
const nextImpl = implementerInternal(next, config, middlewares);
|
285
|
+
if (method) {
|
286
|
+
return new Proxy(method, {
|
287
|
+
get(_, key2) {
|
288
|
+
return Reflect.get(nextImpl, key2);
|
289
|
+
}
|
290
|
+
});
|
291
|
+
}
|
292
|
+
return nextImpl;
|
518
293
|
}
|
519
|
-
return { default: maybeProcedure };
|
520
294
|
});
|
521
|
-
return
|
295
|
+
return impl;
|
296
|
+
}
|
297
|
+
function implement(contract, config = {}) {
|
298
|
+
const implInternal = implementerInternal(contract, config, []);
|
299
|
+
const impl = new Proxy(implInternal, {
|
300
|
+
get: (target, key) => {
|
301
|
+
let method;
|
302
|
+
if (key === "$context") {
|
303
|
+
method = () => impl;
|
304
|
+
} else if (key === "$config") {
|
305
|
+
method = (config2) => implement(contract, config2);
|
306
|
+
}
|
307
|
+
const next = Reflect.get(target, key);
|
308
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
309
|
+
return method ?? next;
|
310
|
+
}
|
311
|
+
if (method) {
|
312
|
+
return new Proxy(method, {
|
313
|
+
get(_, key2) {
|
314
|
+
return Reflect.get(next, key2);
|
315
|
+
}
|
316
|
+
});
|
317
|
+
}
|
318
|
+
return next;
|
319
|
+
}
|
320
|
+
});
|
321
|
+
return impl;
|
322
|
+
}
|
323
|
+
|
324
|
+
// src/procedure-utils.ts
|
325
|
+
function call(procedure, input, ...rest) {
|
326
|
+
return createProcedureClient(procedure, ...rest)(input);
|
522
327
|
}
|
523
328
|
|
524
329
|
// src/router-client.ts
|
@@ -548,35 +353,29 @@ function createRouterClient(router, ...rest) {
|
|
548
353
|
}
|
549
354
|
|
550
355
|
// src/index.ts
|
551
|
-
import {
|
552
|
-
var os = new Builder({
|
553
|
-
middlewares: [],
|
554
|
-
errorMap: {}
|
555
|
-
});
|
356
|
+
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
556
357
|
export {
|
557
358
|
Builder,
|
558
359
|
DecoratedProcedure,
|
559
360
|
LAZY_LOADER_SYMBOL,
|
560
361
|
ORPCError,
|
561
362
|
Procedure,
|
562
|
-
|
563
|
-
|
564
|
-
RouterBuilder,
|
565
|
-
RouterImplementer,
|
363
|
+
ValidationError,
|
364
|
+
adaptRouter,
|
566
365
|
call,
|
567
|
-
|
568
|
-
|
569
|
-
createORPCErrorConstructorMap,
|
366
|
+
createAccessibleLazyRouter,
|
367
|
+
createLazyProcedureFormAnyLazy,
|
570
368
|
createProcedureClient,
|
571
369
|
createRouterClient,
|
572
|
-
decorateLazy,
|
573
370
|
decorateMiddleware,
|
574
371
|
deepSetLazyRouterPrefix,
|
575
|
-
|
372
|
+
fallbackConfig,
|
576
373
|
flatLazy,
|
577
374
|
getLazyRouterPrefix,
|
578
375
|
getRouterChild,
|
579
376
|
getRouterContract,
|
377
|
+
implement,
|
378
|
+
implementerInternal,
|
580
379
|
isDefinedError,
|
581
380
|
isLazy,
|
582
381
|
isProcedure,
|
@@ -586,6 +385,7 @@ export {
|
|
586
385
|
os,
|
587
386
|
safe,
|
588
387
|
setRouterContract,
|
388
|
+
type,
|
589
389
|
unlazy
|
590
390
|
};
|
591
391
|
//# sourceMappingURL=index.js.map
|