@orpc/server 0.0.0-next.cba521d → 0.0.0-next.cc4cb21
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-EWOWWNDI.js +182 -0
- package/dist/chunk-MHVECKBC.js +421 -0
- package/dist/chunk-TXHKQO7N.js +120 -0
- package/dist/chunk-XT6IYOIS.js +32 -0
- package/dist/fetch.js +6 -11
- package/dist/hono.js +18 -14
- package/dist/index.js +236 -385
- 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 -21
- 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 -33
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +8 -22
- 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-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/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-MHVECKBC.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,10 +50,14 @@ 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
|
36
|
-
|
37
|
-
|
38
|
-
|
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);
|
39
61
|
return merged;
|
40
62
|
});
|
41
63
|
return concatted;
|
@@ -44,453 +66,272 @@ function decorateMiddleware(middleware) {
|
|
44
66
|
}
|
45
67
|
|
46
68
|
// src/procedure-decorated.ts
|
47
|
-
import {
|
48
|
-
import { createCallableObject } from "@orpc/shared";
|
69
|
+
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
49
70
|
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) {
|
71
|
+
errors(errors) {
|
63
72
|
return new _DecoratedProcedure({
|
64
73
|
...this["~orpc"],
|
65
|
-
|
74
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
66
75
|
});
|
67
76
|
}
|
68
|
-
|
69
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
77
|
+
meta(meta) {
|
70
78
|
return new _DecoratedProcedure({
|
71
79
|
...this["~orpc"],
|
72
|
-
|
80
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
73
81
|
});
|
74
82
|
}
|
75
|
-
|
83
|
+
route(route) {
|
76
84
|
return new _DecoratedProcedure({
|
77
85
|
...this["~orpc"],
|
78
|
-
|
86
|
+
route: mergeRoute(this["~orpc"].route, route)
|
79
87
|
});
|
80
88
|
}
|
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
|
-
}
|
89
|
+
use(middleware, mapInput) {
|
90
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
94
91
|
return new _DecoratedProcedure({
|
95
92
|
...this["~orpc"],
|
96
|
-
|
93
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
97
94
|
});
|
98
95
|
}
|
99
96
|
/**
|
100
97
|
* 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
98
|
*/
|
103
99
|
callable(...rest) {
|
104
|
-
return
|
100
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
101
|
+
"~type": "Procedure",
|
102
|
+
"~orpc": this["~orpc"]
|
103
|
+
});
|
105
104
|
}
|
106
105
|
/**
|
107
106
|
* 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
107
|
*/
|
110
108
|
actionable(...rest) {
|
111
109
|
return this.callable(...rest);
|
112
110
|
}
|
113
111
|
};
|
114
112
|
|
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";
|
113
|
+
// src/builder.ts
|
114
|
+
var Builder = class _Builder {
|
191
115
|
"~orpc";
|
192
116
|
constructor(def) {
|
193
117
|
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
118
|
}
|
213
|
-
|
214
|
-
|
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({
|
215
126
|
...this["~orpc"],
|
216
|
-
|
127
|
+
config,
|
128
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
129
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
217
130
|
});
|
218
131
|
}
|
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({
|
132
|
+
/**
|
133
|
+
* Reset initial context
|
134
|
+
*/
|
135
|
+
$context() {
|
136
|
+
return new _Builder({
|
271
137
|
...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: []
|
138
|
+
middlewares: [],
|
139
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
140
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
294
141
|
});
|
295
|
-
return implementer;
|
296
|
-
}
|
297
|
-
const chainable = {};
|
298
|
-
for (const key in contract) {
|
299
|
-
chainable[key] = createChainableImplementer(contract[key], middlewares);
|
300
142
|
}
|
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({
|
143
|
+
/**
|
144
|
+
* Reset initial meta
|
145
|
+
*/
|
146
|
+
$meta(initialMeta) {
|
147
|
+
return new _Builder({
|
330
148
|
...this["~orpc"],
|
331
|
-
|
149
|
+
meta: initialMeta
|
332
150
|
});
|
333
151
|
}
|
334
|
-
|
335
|
-
|
152
|
+
/**
|
153
|
+
* Reset initial route
|
154
|
+
*/
|
155
|
+
$route(initialRoute) {
|
156
|
+
return new _Builder({
|
336
157
|
...this["~orpc"],
|
337
|
-
|
158
|
+
route: initialRoute
|
338
159
|
});
|
339
160
|
}
|
340
|
-
|
341
|
-
return
|
342
|
-
...this["~orpc"],
|
343
|
-
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
344
|
-
});
|
161
|
+
middleware(middleware) {
|
162
|
+
return decorateMiddleware(middleware);
|
345
163
|
}
|
346
164
|
errors(errors) {
|
347
|
-
return new
|
165
|
+
return new _Builder({
|
348
166
|
...this["~orpc"],
|
349
|
-
|
167
|
+
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
350
168
|
});
|
351
169
|
}
|
352
170
|
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() {
|
171
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
384
172
|
return new _Builder({
|
385
|
-
|
173
|
+
...this["~orpc"],
|
174
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
386
175
|
});
|
387
176
|
}
|
388
|
-
|
177
|
+
meta(meta) {
|
389
178
|
return new _Builder({
|
390
179
|
...this["~orpc"],
|
391
|
-
|
180
|
+
meta: mergeMeta2(this["~orpc"].meta, meta)
|
392
181
|
});
|
393
182
|
}
|
394
|
-
middleware(middleware) {
|
395
|
-
return decorateMiddleware(middleware);
|
396
|
-
}
|
397
183
|
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
|
-
})
|
184
|
+
return new _Builder({
|
185
|
+
...this["~orpc"],
|
186
|
+
route: mergeRoute2(this["~orpc"].route, route)
|
417
187
|
});
|
418
188
|
}
|
419
|
-
|
420
|
-
return new
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
OutputSchema: schema,
|
425
|
-
outputExample: example,
|
426
|
-
errorMap: void 0
|
427
|
-
})
|
189
|
+
input(schema) {
|
190
|
+
return new _Builder({
|
191
|
+
...this["~orpc"],
|
192
|
+
inputSchema: schema,
|
193
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
428
194
|
});
|
429
195
|
}
|
430
|
-
|
431
|
-
return new
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
OutputSchema: void 0,
|
436
|
-
errorMap: errors
|
437
|
-
})
|
196
|
+
output(schema) {
|
197
|
+
return new _Builder({
|
198
|
+
...this["~orpc"],
|
199
|
+
outputSchema: schema,
|
200
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
438
201
|
});
|
439
202
|
}
|
440
203
|
handler(handler) {
|
441
204
|
return new DecoratedProcedure({
|
442
|
-
|
443
|
-
postMiddlewares: [],
|
444
|
-
contract: new ContractProcedure({
|
445
|
-
InputSchema: void 0,
|
446
|
-
OutputSchema: void 0,
|
447
|
-
errorMap: void 0
|
448
|
-
}),
|
205
|
+
...this["~orpc"],
|
449
206
|
handler
|
450
207
|
});
|
451
208
|
}
|
452
209
|
prefix(prefix) {
|
453
|
-
return new
|
454
|
-
|
455
|
-
prefix
|
210
|
+
return new _Builder({
|
211
|
+
...this["~orpc"],
|
212
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
456
213
|
});
|
457
214
|
}
|
458
215
|
tag(...tags) {
|
459
|
-
return new
|
460
|
-
|
461
|
-
tags
|
216
|
+
return new _Builder({
|
217
|
+
...this["~orpc"],
|
218
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
462
219
|
});
|
463
220
|
}
|
464
221
|
router(router) {
|
465
|
-
return
|
222
|
+
return adaptRouter(router, this["~orpc"]);
|
466
223
|
}
|
467
224
|
lazy(loader) {
|
468
|
-
return
|
469
|
-
}
|
470
|
-
contract(contract) {
|
471
|
-
return createChainableImplementer(contract, this["~orpc"].middlewares);
|
225
|
+
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
472
226
|
}
|
473
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
|
+
});
|
474
239
|
|
475
|
-
// src/
|
476
|
-
function
|
477
|
-
return
|
240
|
+
// src/context.ts
|
241
|
+
function mergeContext(context, other) {
|
242
|
+
return { ...context, ...other };
|
478
243
|
}
|
479
244
|
|
480
|
-
// src/
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
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;
|
301
|
+
}
|
302
|
+
});
|
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;
|
490
327
|
}
|
491
|
-
return { default: maybeProcedure };
|
492
328
|
});
|
493
|
-
return
|
329
|
+
return impl;
|
330
|
+
}
|
331
|
+
|
332
|
+
// src/procedure-utils.ts
|
333
|
+
function call(procedure, input, ...rest) {
|
334
|
+
return createProcedureClient(procedure, ...rest)(input);
|
494
335
|
}
|
495
336
|
|
496
337
|
// src/router-client.ts
|
@@ -520,43 +361,53 @@ function createRouterClient(router, ...rest) {
|
|
520
361
|
}
|
521
362
|
|
522
363
|
// src/index.ts
|
523
|
-
import {
|
524
|
-
|
525
|
-
|
526
|
-
}
|
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";
|
527
368
|
export {
|
528
369
|
Builder,
|
529
370
|
DecoratedProcedure,
|
530
371
|
LAZY_LOADER_SYMBOL,
|
531
372
|
ORPCError,
|
532
373
|
Procedure,
|
533
|
-
|
534
|
-
|
535
|
-
RouterBuilder,
|
536
|
-
RouterImplementer,
|
374
|
+
ValidationError,
|
375
|
+
adaptRouter,
|
537
376
|
call,
|
538
|
-
|
539
|
-
|
540
|
-
|
377
|
+
convertPathToHttpPath,
|
378
|
+
createAccessibleLazyRouter,
|
379
|
+
createContractedProcedure,
|
380
|
+
createLazyProcedureFormAnyLazy,
|
541
381
|
createProcedureClient,
|
542
382
|
createRouterClient,
|
543
|
-
decorateLazy,
|
544
383
|
decorateMiddleware,
|
545
384
|
deepSetLazyRouterPrefix,
|
546
|
-
|
385
|
+
eachAllContractProcedure,
|
386
|
+
eachContractProcedure,
|
387
|
+
eventIterator,
|
388
|
+
fallbackConfig,
|
547
389
|
flatLazy,
|
390
|
+
getEventMeta,
|
548
391
|
getLazyRouterPrefix,
|
549
392
|
getRouterChild,
|
550
393
|
getRouterContract,
|
394
|
+
implement,
|
395
|
+
implementerInternal,
|
551
396
|
isDefinedError,
|
552
397
|
isLazy,
|
553
398
|
isProcedure,
|
554
399
|
lazy,
|
555
400
|
mergeContext,
|
556
401
|
middlewareOutputFn,
|
402
|
+
onError,
|
403
|
+
onFinish,
|
404
|
+
onStart,
|
405
|
+
onSuccess,
|
557
406
|
os,
|
558
407
|
safe,
|
559
408
|
setRouterContract,
|
560
|
-
|
409
|
+
type,
|
410
|
+
unlazy,
|
411
|
+
withEventMeta
|
561
412
|
};
|
562
413
|
//# sourceMappingURL=index.js.map
|