@orpc/server 0.0.0-next.cba521d → 0.0.0-next.ccd4e42
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-6RSW63UJ.js +136 -0
- package/dist/chunk-JHLUGXCM.js +294 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/fetch.js +11 -9
- package/dist/hono.js +13 -11
- package/dist/index.js +224 -382
- package/dist/next.js +13 -11
- package/dist/node.js +148 -62
- 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 +6 -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 +33 -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 -29
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +6 -4
- 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/procedure-client.d.ts +6 -8
- package/dist/src/procedure-decorated.d.ts +10 -15
- 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/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +16 -0
- package/package.json +12 -3
- package/dist/chunk-3EVCPLVI.js +0 -301
- package/dist/chunk-OUPZ7QGV.js +0 -245
- 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 -29
- 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-NOA3GBJQ.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,453 +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
|
-
|
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) {
|
67
|
+
errors(errors) {
|
63
68
|
return new _DecoratedProcedure({
|
64
69
|
...this["~orpc"],
|
65
|
-
|
70
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
66
71
|
});
|
67
72
|
}
|
68
|
-
|
69
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
73
|
+
meta(meta) {
|
70
74
|
return new _DecoratedProcedure({
|
71
75
|
...this["~orpc"],
|
72
|
-
|
76
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
73
77
|
});
|
74
78
|
}
|
75
|
-
|
79
|
+
route(route) {
|
76
80
|
return new _DecoratedProcedure({
|
77
81
|
...this["~orpc"],
|
78
|
-
|
82
|
+
route: mergeRoute(this["~orpc"].route, route)
|
79
83
|
});
|
80
84
|
}
|
81
|
-
|
82
|
-
const
|
83
|
-
if (this["~orpc"].preMiddlewares.length) {
|
84
|
-
let min = 0;
|
85
|
-
for (let i = 0; i < this["~orpc"].preMiddlewares.length; i++) {
|
86
|
-
const index = castedMiddlewares.indexOf(this["~orpc"].preMiddlewares[i], min);
|
87
|
-
if (index === -1) {
|
88
|
-
castedMiddlewares.push(...this["~orpc"].preMiddlewares.slice(i));
|
89
|
-
break;
|
90
|
-
}
|
91
|
-
min = index + 1;
|
92
|
-
}
|
93
|
-
}
|
85
|
+
use(middleware, mapInput) {
|
86
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
94
87
|
return new _DecoratedProcedure({
|
95
88
|
...this["~orpc"],
|
96
|
-
|
89
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
97
90
|
});
|
98
91
|
}
|
99
92
|
/**
|
100
93
|
* Make this procedure callable (works like a function while still being a procedure).
|
101
|
-
* **Note**: this only takes effect when this method is called at the end of the chain.
|
102
94
|
*/
|
103
95
|
callable(...rest) {
|
104
|
-
return
|
96
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
97
|
+
"~type": "Procedure",
|
98
|
+
"~orpc": this["~orpc"]
|
99
|
+
});
|
105
100
|
}
|
106
101
|
/**
|
107
102
|
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
108
|
-
* **Note**: this only takes effect when this method is called at the end of the chain.
|
109
103
|
*/
|
110
104
|
actionable(...rest) {
|
111
105
|
return this.callable(...rest);
|
112
106
|
}
|
113
107
|
};
|
114
108
|
|
115
|
-
// src/
|
116
|
-
var
|
117
|
-
"~type" = "ProcedureImplementer";
|
118
|
-
"~orpc";
|
119
|
-
constructor(def) {
|
120
|
-
this["~orpc"] = def;
|
121
|
-
}
|
122
|
-
use(middleware, mapInput) {
|
123
|
-
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
124
|
-
return new _ProcedureImplementer({
|
125
|
-
...this["~orpc"],
|
126
|
-
postMiddlewares: [...this["~orpc"].postMiddlewares, mappedMiddleware]
|
127
|
-
});
|
128
|
-
}
|
129
|
-
handler(handler) {
|
130
|
-
return new DecoratedProcedure({
|
131
|
-
postMiddlewares: this["~orpc"].postMiddlewares,
|
132
|
-
preMiddlewares: this["~orpc"].preMiddlewares,
|
133
|
-
contract: this["~orpc"].contract,
|
134
|
-
handler
|
135
|
-
});
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
// src/hidden.ts
|
140
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
141
|
-
function setRouterContract(obj, contract) {
|
142
|
-
return new Proxy(obj, {
|
143
|
-
get(target, key) {
|
144
|
-
if (key === ROUTER_CONTRACT_SYMBOL) {
|
145
|
-
return contract;
|
146
|
-
}
|
147
|
-
return Reflect.get(target, key);
|
148
|
-
}
|
149
|
-
});
|
150
|
-
}
|
151
|
-
function getRouterContract(obj) {
|
152
|
-
return obj[ROUTER_CONTRACT_SYMBOL];
|
153
|
-
}
|
154
|
-
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
155
|
-
function deepSetLazyRouterPrefix(router, prefix) {
|
156
|
-
return new Proxy(router, {
|
157
|
-
get(target, key) {
|
158
|
-
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
159
|
-
const val = Reflect.get(target, key);
|
160
|
-
if (val && (typeof val === "object" || typeof val === "function")) {
|
161
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
162
|
-
}
|
163
|
-
return val;
|
164
|
-
}
|
165
|
-
return prefix;
|
166
|
-
}
|
167
|
-
});
|
168
|
-
}
|
169
|
-
function getLazyRouterPrefix(obj) {
|
170
|
-
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
171
|
-
}
|
172
|
-
|
173
|
-
// src/lazy-decorated.ts
|
174
|
-
function decorateLazy(lazied) {
|
175
|
-
const flattenLazy = flatLazy(lazied);
|
176
|
-
const recursive = new Proxy(flattenLazy, {
|
177
|
-
get(target, key) {
|
178
|
-
if (typeof key !== "string") {
|
179
|
-
return Reflect.get(target, key);
|
180
|
-
}
|
181
|
-
const next = getRouterChild(flattenLazy, key);
|
182
|
-
return decorateLazy(next);
|
183
|
-
}
|
184
|
-
});
|
185
|
-
return recursive;
|
186
|
-
}
|
187
|
-
|
188
|
-
// src/router-builder.ts
|
189
|
-
var RouterBuilder = class _RouterBuilder {
|
190
|
-
"~type" = "RouterBuilder";
|
109
|
+
// src/builder.ts
|
110
|
+
var Builder = class _Builder {
|
191
111
|
"~orpc";
|
192
112
|
constructor(def) {
|
193
113
|
this["~orpc"] = def;
|
194
|
-
if (def.prefix && def.prefix.includes("{")) {
|
195
|
-
throw new Error(`
|
196
|
-
Dynamic routing in prefix not supported yet.
|
197
|
-
Please remove "{" from "${def.prefix}".
|
198
|
-
`);
|
199
|
-
}
|
200
|
-
}
|
201
|
-
prefix(prefix) {
|
202
|
-
return new _RouterBuilder({
|
203
|
-
...this["~orpc"],
|
204
|
-
prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
|
205
|
-
});
|
206
|
-
}
|
207
|
-
tag(...tags) {
|
208
|
-
return new _RouterBuilder({
|
209
|
-
...this["~orpc"],
|
210
|
-
tags: [...this["~orpc"].tags ?? [], ...tags]
|
211
|
-
});
|
212
114
|
}
|
213
|
-
|
214
|
-
|
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({
|
215
122
|
...this["~orpc"],
|
216
|
-
|
123
|
+
config,
|
124
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
125
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
217
126
|
});
|
218
127
|
}
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
const adapted = adapt(flatLazy(lazy(loader)), this["~orpc"]);
|
225
|
-
return adapted;
|
226
|
-
}
|
227
|
-
};
|
228
|
-
function adapt(item, options) {
|
229
|
-
if (isLazy(item)) {
|
230
|
-
const adaptedLazy = decorateLazy(lazy(async () => {
|
231
|
-
const routerOrProcedure = (await unlazy(item)).default;
|
232
|
-
const adapted2 = adapt(routerOrProcedure, options);
|
233
|
-
return { default: adapted2 };
|
234
|
-
}));
|
235
|
-
const lazyPrefix = getLazyRouterPrefix(item);
|
236
|
-
if (options.prefix || lazyPrefix) {
|
237
|
-
const prefixed = deepSetLazyRouterPrefix(adaptedLazy, `${options.prefix ?? ""}${lazyPrefix ?? ""}`);
|
238
|
-
return prefixed;
|
239
|
-
}
|
240
|
-
return adaptedLazy;
|
241
|
-
}
|
242
|
-
if (isProcedure(item)) {
|
243
|
-
let decorated = DecoratedProcedure.decorate(item);
|
244
|
-
if (options.tags?.length) {
|
245
|
-
decorated = decorated.unshiftTag(...options.tags);
|
246
|
-
}
|
247
|
-
if (options.prefix) {
|
248
|
-
decorated = decorated.prefix(options.prefix);
|
249
|
-
}
|
250
|
-
if (options.middlewares?.length) {
|
251
|
-
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
252
|
-
}
|
253
|
-
return decorated;
|
254
|
-
}
|
255
|
-
const adapted = {};
|
256
|
-
for (const key in item) {
|
257
|
-
adapted[key] = adapt(item[key], options);
|
258
|
-
}
|
259
|
-
return adapted;
|
260
|
-
}
|
261
|
-
|
262
|
-
// src/router-implementer.ts
|
263
|
-
var RouterImplementer = class _RouterImplementer {
|
264
|
-
"~type" = "RouterImplementer";
|
265
|
-
"~orpc";
|
266
|
-
constructor(def) {
|
267
|
-
this["~orpc"] = def;
|
268
|
-
}
|
269
|
-
use(middleware) {
|
270
|
-
return new _RouterImplementer({
|
128
|
+
/**
|
129
|
+
* Reset initial context
|
130
|
+
*/
|
131
|
+
$context() {
|
132
|
+
return new _Builder({
|
271
133
|
...this["~orpc"],
|
272
|
-
middlewares: [
|
273
|
-
|
274
|
-
|
275
|
-
router(router) {
|
276
|
-
const adapted = new RouterBuilder(this["~orpc"]).router(router);
|
277
|
-
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
278
|
-
return contracted;
|
279
|
-
}
|
280
|
-
lazy(loader) {
|
281
|
-
const adapted = new RouterBuilder(this["~orpc"]).lazy(loader);
|
282
|
-
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
283
|
-
return contracted;
|
284
|
-
}
|
285
|
-
};
|
286
|
-
|
287
|
-
// src/implementer-chainable.ts
|
288
|
-
function createChainableImplementer(contract, middlewares = []) {
|
289
|
-
if (isContractProcedure(contract)) {
|
290
|
-
const implementer = new ProcedureImplementer({
|
291
|
-
contract,
|
292
|
-
preMiddlewares: middlewares,
|
293
|
-
postMiddlewares: []
|
134
|
+
middlewares: [],
|
135
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
136
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
294
137
|
});
|
295
|
-
return implementer;
|
296
|
-
}
|
297
|
-
const chainable = {};
|
298
|
-
for (const key in contract) {
|
299
|
-
chainable[key] = createChainableImplementer(contract[key], middlewares);
|
300
138
|
}
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
if (typeof key !== "string" || typeof method !== "function") {
|
307
|
-
return next;
|
308
|
-
}
|
309
|
-
if (!next) {
|
310
|
-
return method.bind(routerImplementer);
|
311
|
-
}
|
312
|
-
return createCallableObject2(next, method.bind(routerImplementer));
|
313
|
-
}
|
314
|
-
});
|
315
|
-
return merged;
|
316
|
-
}
|
317
|
-
|
318
|
-
// src/procedure-builder.ts
|
319
|
-
import {
|
320
|
-
DecoratedContractProcedure as DecoratedContractProcedure2
|
321
|
-
} from "@orpc/contract";
|
322
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
323
|
-
"~type" = "ProcedureBuilder";
|
324
|
-
"~orpc";
|
325
|
-
constructor(def) {
|
326
|
-
this["~orpc"] = def;
|
327
|
-
}
|
328
|
-
route(route) {
|
329
|
-
return new _ProcedureBuilder({
|
139
|
+
/**
|
140
|
+
* Reset initial meta
|
141
|
+
*/
|
142
|
+
$meta(initialMeta) {
|
143
|
+
return new _Builder({
|
330
144
|
...this["~orpc"],
|
331
|
-
|
145
|
+
meta: initialMeta
|
332
146
|
});
|
333
147
|
}
|
334
|
-
|
335
|
-
|
148
|
+
/**
|
149
|
+
* Reset initial route
|
150
|
+
*/
|
151
|
+
$route(initialRoute) {
|
152
|
+
return new _Builder({
|
336
153
|
...this["~orpc"],
|
337
|
-
|
154
|
+
route: initialRoute
|
338
155
|
});
|
339
156
|
}
|
340
|
-
|
341
|
-
return
|
342
|
-
...this["~orpc"],
|
343
|
-
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
344
|
-
});
|
157
|
+
middleware(middleware) {
|
158
|
+
return decorateMiddleware(middleware);
|
345
159
|
}
|
346
160
|
errors(errors) {
|
347
|
-
return new
|
161
|
+
return new _Builder({
|
348
162
|
...this["~orpc"],
|
349
|
-
|
163
|
+
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
350
164
|
});
|
351
165
|
}
|
352
166
|
use(middleware, mapInput) {
|
353
|
-
|
354
|
-
return new ProcedureImplementer({
|
355
|
-
contract: this["~orpc"].contract,
|
356
|
-
preMiddlewares: this["~orpc"].middlewares,
|
357
|
-
postMiddlewares: []
|
358
|
-
}).use(middleware);
|
359
|
-
}
|
360
|
-
return new ProcedureImplementer({
|
361
|
-
contract: this["~orpc"].contract,
|
362
|
-
preMiddlewares: this["~orpc"].middlewares,
|
363
|
-
postMiddlewares: []
|
364
|
-
}).use(middleware, mapInput);
|
365
|
-
}
|
366
|
-
handler(handler) {
|
367
|
-
return new DecoratedProcedure({
|
368
|
-
preMiddlewares: this["~orpc"].middlewares,
|
369
|
-
postMiddlewares: [],
|
370
|
-
contract: this["~orpc"].contract,
|
371
|
-
handler
|
372
|
-
});
|
373
|
-
}
|
374
|
-
};
|
375
|
-
|
376
|
-
// src/builder.ts
|
377
|
-
var Builder = class _Builder {
|
378
|
-
"~type" = "Builder";
|
379
|
-
"~orpc";
|
380
|
-
constructor(def) {
|
381
|
-
this["~orpc"] = def;
|
382
|
-
}
|
383
|
-
context() {
|
167
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
384
168
|
return new _Builder({
|
385
|
-
|
169
|
+
...this["~orpc"],
|
170
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
386
171
|
});
|
387
172
|
}
|
388
|
-
|
173
|
+
meta(meta) {
|
389
174
|
return new _Builder({
|
390
175
|
...this["~orpc"],
|
391
|
-
|
176
|
+
meta: mergeMeta2(this["~orpc"].meta, meta)
|
392
177
|
});
|
393
178
|
}
|
394
|
-
middleware(middleware) {
|
395
|
-
return decorateMiddleware(middleware);
|
396
|
-
}
|
397
179
|
route(route) {
|
398
|
-
return new
|
399
|
-
|
400
|
-
|
401
|
-
route,
|
402
|
-
InputSchema: void 0,
|
403
|
-
OutputSchema: void 0,
|
404
|
-
errorMap: void 0
|
405
|
-
})
|
406
|
-
});
|
407
|
-
}
|
408
|
-
input(schema, example) {
|
409
|
-
return new ProcedureBuilder({
|
410
|
-
middlewares: this["~orpc"].middlewares,
|
411
|
-
contract: new ContractProcedure({
|
412
|
-
OutputSchema: void 0,
|
413
|
-
InputSchema: schema,
|
414
|
-
inputExample: example,
|
415
|
-
errorMap: void 0
|
416
|
-
})
|
180
|
+
return new _Builder({
|
181
|
+
...this["~orpc"],
|
182
|
+
route: mergeRoute2(this["~orpc"].route, route)
|
417
183
|
});
|
418
184
|
}
|
419
|
-
|
420
|
-
return new
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
OutputSchema: schema,
|
425
|
-
outputExample: example,
|
426
|
-
errorMap: void 0
|
427
|
-
})
|
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
|
428
190
|
});
|
429
191
|
}
|
430
|
-
|
431
|
-
return new
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
OutputSchema: void 0,
|
436
|
-
errorMap: errors
|
437
|
-
})
|
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
|
438
197
|
});
|
439
198
|
}
|
440
199
|
handler(handler) {
|
441
200
|
return new DecoratedProcedure({
|
442
|
-
|
443
|
-
postMiddlewares: [],
|
444
|
-
contract: new ContractProcedure({
|
445
|
-
InputSchema: void 0,
|
446
|
-
OutputSchema: void 0,
|
447
|
-
errorMap: void 0
|
448
|
-
}),
|
201
|
+
...this["~orpc"],
|
449
202
|
handler
|
450
203
|
});
|
451
204
|
}
|
452
205
|
prefix(prefix) {
|
453
|
-
return new
|
454
|
-
|
455
|
-
prefix
|
206
|
+
return new _Builder({
|
207
|
+
...this["~orpc"],
|
208
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
456
209
|
});
|
457
210
|
}
|
458
211
|
tag(...tags) {
|
459
|
-
return new
|
460
|
-
|
461
|
-
tags
|
212
|
+
return new _Builder({
|
213
|
+
...this["~orpc"],
|
214
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
462
215
|
});
|
463
216
|
}
|
464
217
|
router(router) {
|
465
|
-
return
|
218
|
+
return adaptRouter(router, this["~orpc"]);
|
466
219
|
}
|
467
220
|
lazy(loader) {
|
468
|
-
return
|
469
|
-
}
|
470
|
-
contract(contract) {
|
471
|
-
return createChainableImplementer(contract, this["~orpc"].middlewares);
|
221
|
+
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
472
222
|
}
|
473
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
|
+
});
|
474
235
|
|
475
|
-
// src/
|
476
|
-
function
|
477
|
-
return
|
236
|
+
// src/context.ts
|
237
|
+
function mergeContext(context, other) {
|
238
|
+
return { ...context, ...other };
|
478
239
|
}
|
479
240
|
|
480
|
-
// src/
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
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;
|
297
|
+
}
|
298
|
+
});
|
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;
|
490
323
|
}
|
491
|
-
return { default: maybeProcedure };
|
492
324
|
});
|
493
|
-
return
|
325
|
+
return impl;
|
326
|
+
}
|
327
|
+
|
328
|
+
// src/procedure-utils.ts
|
329
|
+
function call(procedure, input, ...rest) {
|
330
|
+
return createProcedureClient(procedure, ...rest)(input);
|
494
331
|
}
|
495
332
|
|
496
333
|
// src/router-client.ts
|
@@ -520,43 +357,48 @@ function createRouterClient(router, ...rest) {
|
|
520
357
|
}
|
521
358
|
|
522
359
|
// src/index.ts
|
523
|
-
import {
|
524
|
-
|
525
|
-
middlewares: []
|
526
|
-
});
|
360
|
+
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
361
|
+
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
527
362
|
export {
|
528
363
|
Builder,
|
529
364
|
DecoratedProcedure,
|
530
365
|
LAZY_LOADER_SYMBOL,
|
531
366
|
ORPCError,
|
532
367
|
Procedure,
|
533
|
-
|
534
|
-
|
535
|
-
RouterBuilder,
|
536
|
-
RouterImplementer,
|
368
|
+
ValidationError,
|
369
|
+
adaptRouter,
|
537
370
|
call,
|
538
|
-
|
539
|
-
|
540
|
-
|
371
|
+
convertPathToHttpPath,
|
372
|
+
createAccessibleLazyRouter,
|
373
|
+
createContractedProcedure,
|
374
|
+
createLazyProcedureFormAnyLazy,
|
541
375
|
createProcedureClient,
|
542
376
|
createRouterClient,
|
543
|
-
decorateLazy,
|
544
377
|
decorateMiddleware,
|
545
378
|
deepSetLazyRouterPrefix,
|
546
|
-
|
379
|
+
eachAllContractProcedure,
|
380
|
+
eachContractProcedure,
|
381
|
+
fallbackConfig,
|
547
382
|
flatLazy,
|
548
383
|
getLazyRouterPrefix,
|
549
384
|
getRouterChild,
|
550
385
|
getRouterContract,
|
386
|
+
implement,
|
387
|
+
implementerInternal,
|
551
388
|
isDefinedError,
|
552
389
|
isLazy,
|
553
390
|
isProcedure,
|
554
391
|
lazy,
|
555
392
|
mergeContext,
|
556
393
|
middlewareOutputFn,
|
394
|
+
onError,
|
395
|
+
onFinish,
|
396
|
+
onStart,
|
397
|
+
onSuccess,
|
557
398
|
os,
|
558
399
|
safe,
|
559
400
|
setRouterContract,
|
401
|
+
type,
|
560
402
|
unlazy
|
561
403
|
};
|
562
404
|
//# sourceMappingURL=index.js.map
|