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