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