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