@orpc/server 0.0.0-next.8b5a6d6 → 0.0.0-next.8f101b9
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-ESTRJAOX.js +299 -0
- package/dist/chunk-KK4SDLC7.js +320 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/fetch.js +11 -108
- package/dist/hono.js +30 -0
- package/dist/index.js +298 -375
- package/dist/next.js +36 -0
- package/dist/node.js +87 -0
- package/dist/src/adapters/fetch/index.d.ts +6 -0
- package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
- package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +16 -0
- package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +12 -0
- package/dist/src/adapters/fetch/super-json.d.ts +12 -0
- package/dist/src/adapters/fetch/types.d.ts +21 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +12 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +19 -0
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
- package/dist/src/adapters/node/request-listener.d.ts +28 -0
- package/dist/src/adapters/node/types.d.ts +22 -0
- package/dist/src/builder-variants.d.ts +74 -0
- package/dist/src/builder.d.ts +46 -42
- package/dist/src/config.d.ts +6 -0
- package/dist/src/context.d.ts +9 -0
- package/dist/src/hidden.d.ts +8 -0
- package/dist/src/implementer-procedure.d.ts +30 -0
- package/dist/src/implementer-variants.d.ts +16 -0
- package/dist/src/implementer.d.ts +27 -0
- package/dist/src/index.d.ts +15 -11
- package/dist/src/lazy-utils.d.ts +6 -0
- package/dist/src/lazy.d.ts +13 -14
- package/dist/src/middleware-decorated.d.ts +10 -0
- package/dist/src/middleware-utils.d.ts +5 -0
- package/dist/src/middleware.d.ts +28 -17
- package/dist/src/procedure-client.d.ts +20 -0
- package/dist/src/procedure-decorated.d.ts +21 -0
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +25 -28
- package/dist/src/router-accessible-lazy.d.ts +8 -0
- package/dist/src/router-client.d.ts +22 -0
- package/dist/src/router.d.ts +25 -17
- package/package.json +22 -11
- package/dist/chunk-3JMSDC5L.js +0 -274
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -28
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -26
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/router-builder.d.ts +0 -27
- package/dist/src/router-caller.d.ts +0 -25
- package/dist/src/router-implementer.d.ts +0 -24
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
package/dist/index.js
CHANGED
@@ -1,434 +1,351 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
adaptRouter,
|
5
|
+
addMiddleware,
|
6
|
+
createAccessibleLazyRouter,
|
7
|
+
createLazyProcedureFormAnyLazy,
|
8
|
+
createProcedureClient,
|
9
|
+
deepSetLazyRouterPrefix,
|
10
|
+
flatLazy,
|
11
|
+
getLazyRouterPrefix,
|
12
|
+
getRouterChild,
|
13
|
+
getRouterContract,
|
10
14
|
isLazy,
|
11
15
|
isProcedure,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
lazy,
|
17
|
+
middlewareOutputFn,
|
18
|
+
setRouterContract,
|
19
|
+
unlazy
|
20
|
+
} from "./chunk-KK4SDLC7.js";
|
16
21
|
|
17
22
|
// src/builder.ts
|
18
|
-
import {
|
19
|
-
ContractProcedure,
|
20
|
-
isContractProcedure as isContractProcedure2
|
21
|
-
} from "@orpc/contract";
|
23
|
+
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
22
24
|
|
23
|
-
// src/
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
var RouterBuilder = class _RouterBuilder {
|
32
|
-
constructor(zz$rb) {
|
33
|
-
this.zz$rb = zz$rb;
|
34
|
-
if (zz$rb.prefix && zz$rb.prefix.includes("{")) {
|
35
|
-
throw new Error('Prefix cannot contain "{" for dynamic routing');
|
36
|
-
}
|
37
|
-
}
|
38
|
-
prefix(prefix) {
|
39
|
-
return new _RouterBuilder({
|
40
|
-
...this.zz$rb,
|
41
|
-
prefix: `${this.zz$rb.prefix ?? ""}${prefix}`
|
42
|
-
});
|
43
|
-
}
|
44
|
-
tags(...tags) {
|
45
|
-
if (!tags.length)
|
46
|
-
return this;
|
47
|
-
return new _RouterBuilder({
|
48
|
-
...this.zz$rb,
|
49
|
-
tags: [...this.zz$rb.tags ?? [], ...tags]
|
50
|
-
});
|
51
|
-
}
|
52
|
-
use(middleware, mapInput) {
|
53
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
54
|
-
return new _RouterBuilder({
|
55
|
-
...this.zz$rb,
|
56
|
-
middlewares: [...this.zz$rb.middlewares || [], middleware_]
|
57
|
-
});
|
58
|
-
}
|
59
|
-
router(router) {
|
60
|
-
const handled = adaptRouter({
|
61
|
-
routerOrChild: router,
|
62
|
-
middlewares: this.zz$rb.middlewares,
|
63
|
-
tags: this.zz$rb.tags,
|
64
|
-
prefix: this.zz$rb.prefix
|
65
|
-
});
|
66
|
-
return handled;
|
25
|
+
// src/config.ts
|
26
|
+
var DEFAULT_CONFIG = {
|
27
|
+
initialInputValidationIndex: 0,
|
28
|
+
initialOutputValidationIndex: 0
|
29
|
+
};
|
30
|
+
function fallbackConfig(key, value) {
|
31
|
+
if (value === void 0) {
|
32
|
+
return DEFAULT_CONFIG[key];
|
67
33
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
34
|
+
return value;
|
35
|
+
}
|
36
|
+
|
37
|
+
// src/middleware-decorated.ts
|
38
|
+
function decorateMiddleware(middleware) {
|
39
|
+
const decorated = middleware;
|
40
|
+
decorated.mapInput = (mapInput) => {
|
41
|
+
const mapped = decorateMiddleware(
|
42
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
43
|
+
);
|
44
|
+
return mapped;
|
45
|
+
};
|
46
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
47
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
48
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
49
|
+
const next = async (...[nextOptions]) => {
|
50
|
+
return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
|
51
|
+
};
|
52
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
53
|
+
return merged;
|
74
54
|
});
|
75
|
-
return
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
55
|
+
return concatted;
|
56
|
+
};
|
57
|
+
return decorated;
|
58
|
+
}
|
59
|
+
|
60
|
+
// src/procedure-decorated.ts
|
61
|
+
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
62
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
63
|
+
errors(errors) {
|
64
|
+
return new _DecoratedProcedure({
|
65
|
+
...this["~orpc"],
|
66
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
83
67
|
});
|
84
68
|
}
|
85
|
-
|
86
|
-
return
|
87
|
-
...
|
88
|
-
|
69
|
+
meta(meta) {
|
70
|
+
return new _DecoratedProcedure({
|
71
|
+
...this["~orpc"],
|
72
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
89
73
|
});
|
90
74
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
routerOrChild: options.routerOrChild[key]
|
75
|
+
route(route) {
|
76
|
+
return new _DecoratedProcedure({
|
77
|
+
...this["~orpc"],
|
78
|
+
route: mergeRoute(this["~orpc"].route, route)
|
96
79
|
});
|
97
80
|
}
|
98
|
-
return handled;
|
99
|
-
}
|
100
|
-
function adaptLazyRouter(options) {
|
101
|
-
const loader = async () => {
|
102
|
-
const current = (await loadLazy(options.current)).default;
|
103
|
-
return {
|
104
|
-
default: adaptRouter({
|
105
|
-
...options,
|
106
|
-
routerOrChild: current
|
107
|
-
})
|
108
|
-
};
|
109
|
-
};
|
110
|
-
let lazyRouterPrefix = options.prefix;
|
111
|
-
if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") {
|
112
|
-
lazyRouterPrefix = lazyRouterPrefix ? prefixHTTPPath(options.current[LAZY_ROUTER_PREFIX_SYMBOL], lazyRouterPrefix) : options.current[LAZY_ROUTER_PREFIX_SYMBOL];
|
113
|
-
}
|
114
|
-
const decoratedLazy = Object.assign(decorateLazy(createLazy(loader)), {
|
115
|
-
[LAZY_ROUTER_PREFIX_SYMBOL]: lazyRouterPrefix
|
116
|
-
});
|
117
|
-
const recursive = new Proxy(decoratedLazy, {
|
118
|
-
get(target, key) {
|
119
|
-
if (typeof key !== "string") {
|
120
|
-
return Reflect.get(target, key);
|
121
|
-
}
|
122
|
-
return adaptLazyRouter({
|
123
|
-
...options,
|
124
|
-
current: createLazy(async () => {
|
125
|
-
const current = (await loadLazy(options.current)).default;
|
126
|
-
return { default: current[key] };
|
127
|
-
})
|
128
|
-
});
|
129
|
-
}
|
130
|
-
});
|
131
|
-
return recursive;
|
132
|
-
}
|
133
|
-
function adaptProcedure(options) {
|
134
|
-
const builderMiddlewares = options.middlewares ?? [];
|
135
|
-
const procedureMiddlewares = options.procedure.zz$p.middlewares ?? [];
|
136
|
-
const middlewares = [
|
137
|
-
...builderMiddlewares,
|
138
|
-
...procedureMiddlewares.filter(
|
139
|
-
(item) => !builderMiddlewares.includes(item)
|
140
|
-
)
|
141
|
-
];
|
142
|
-
let contract = DecoratedContractProcedure.decorate(
|
143
|
-
options.procedure.zz$p.contract
|
144
|
-
).addTags(...options.tags ?? []);
|
145
|
-
if (options.prefix) {
|
146
|
-
contract = contract.prefix(options.prefix);
|
147
|
-
}
|
148
|
-
return decorateProcedure({
|
149
|
-
zz$p: {
|
150
|
-
...options.procedure.zz$p,
|
151
|
-
contract,
|
152
|
-
middlewares
|
153
|
-
}
|
154
|
-
});
|
155
|
-
}
|
156
|
-
|
157
|
-
// src/procedure-implementer.ts
|
158
|
-
var ProcedureImplementer = class _ProcedureImplementer {
|
159
|
-
constructor(zz$pi) {
|
160
|
-
this.zz$pi = zz$pi;
|
161
|
-
}
|
162
81
|
use(middleware, mapInput) {
|
163
|
-
const
|
164
|
-
return new
|
165
|
-
...this
|
166
|
-
middlewares: [
|
82
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
83
|
+
return new _DecoratedProcedure({
|
84
|
+
...this["~orpc"],
|
85
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
167
86
|
});
|
168
87
|
}
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
88
|
+
/**
|
89
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
90
|
+
*/
|
91
|
+
callable(...rest) {
|
92
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
93
|
+
"~type": "Procedure",
|
94
|
+
"~orpc": this["~orpc"]
|
176
95
|
});
|
177
96
|
}
|
178
|
-
|
179
|
-
|
97
|
+
/**
|
98
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
99
|
+
*/
|
100
|
+
actionable(...rest) {
|
101
|
+
return this.callable(...rest);
|
180
102
|
}
|
181
103
|
};
|
182
104
|
|
183
|
-
// src/
|
184
|
-
var
|
185
|
-
|
186
|
-
|
105
|
+
// src/builder.ts
|
106
|
+
var Builder = class _Builder {
|
107
|
+
"~orpc";
|
108
|
+
constructor(def) {
|
109
|
+
this["~orpc"] = def;
|
187
110
|
}
|
188
111
|
/**
|
189
|
-
*
|
112
|
+
* Reset config
|
190
113
|
*/
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
114
|
+
$config(config) {
|
115
|
+
const inputValidationCount = this["~orpc"].inputValidationIndex - fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex);
|
116
|
+
const outputValidationCount = this["~orpc"].outputValidationIndex - fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex);
|
117
|
+
return new _Builder({
|
118
|
+
...this["~orpc"],
|
119
|
+
config,
|
120
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
121
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
197
122
|
});
|
198
123
|
}
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
124
|
+
/**
|
125
|
+
* Reset initial context
|
126
|
+
*/
|
127
|
+
$context() {
|
128
|
+
return new _Builder({
|
129
|
+
...this["~orpc"],
|
130
|
+
middlewares: [],
|
131
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
132
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
206
133
|
});
|
207
134
|
}
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
135
|
+
/**
|
136
|
+
* Reset initial meta
|
137
|
+
*/
|
138
|
+
$meta(initialMeta) {
|
139
|
+
return new _Builder({
|
140
|
+
...this["~orpc"],
|
141
|
+
meta: initialMeta
|
215
142
|
});
|
216
143
|
}
|
217
|
-
use(middleware, mapInput) {
|
218
|
-
if (!mapInput) {
|
219
|
-
return new ProcedureImplementer({
|
220
|
-
contract: this.zz$pb.contract,
|
221
|
-
middlewares: this.zz$pb.middlewares
|
222
|
-
}).use(middleware);
|
223
|
-
}
|
224
|
-
return new ProcedureImplementer({
|
225
|
-
contract: this.zz$pb.contract,
|
226
|
-
middlewares: this.zz$pb.middlewares
|
227
|
-
}).use(middleware, mapInput);
|
228
|
-
}
|
229
144
|
/**
|
230
|
-
*
|
145
|
+
* Reset initial route
|
231
146
|
*/
|
232
|
-
|
233
|
-
return
|
234
|
-
|
235
|
-
|
236
|
-
contract: this.zz$pb.contract,
|
237
|
-
func
|
238
|
-
}
|
147
|
+
$route(initialRoute) {
|
148
|
+
return new _Builder({
|
149
|
+
...this["~orpc"],
|
150
|
+
route: initialRoute
|
239
151
|
});
|
240
152
|
}
|
241
|
-
|
242
|
-
|
243
|
-
// src/router-implementer.ts
|
244
|
-
import { isContractProcedure } from "@orpc/contract";
|
245
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
246
|
-
var RouterImplementer = class {
|
247
|
-
constructor(zz$ri) {
|
248
|
-
this.zz$ri = zz$ri;
|
249
|
-
}
|
250
|
-
router(router) {
|
251
|
-
return Object.assign(new RouterBuilder({}).router(router), {
|
252
|
-
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
253
|
-
});
|
153
|
+
middleware(middleware) {
|
154
|
+
return decorateMiddleware(middleware);
|
254
155
|
}
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
156
|
+
errors(errors) {
|
157
|
+
return new _Builder({
|
158
|
+
...this["~orpc"],
|
159
|
+
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
260
160
|
});
|
261
161
|
}
|
262
|
-
};
|
263
|
-
function chainRouterImplementer(contract, middlewares) {
|
264
|
-
const result = {};
|
265
|
-
for (const key in contract) {
|
266
|
-
const item = contract[key];
|
267
|
-
if (isContractProcedure(item)) {
|
268
|
-
result[key] = new ProcedureImplementer({
|
269
|
-
contract: item,
|
270
|
-
middlewares
|
271
|
-
});
|
272
|
-
} else {
|
273
|
-
result[key] = chainRouterImplementer(item, middlewares);
|
274
|
-
}
|
275
|
-
}
|
276
|
-
const implementer = new RouterImplementer({ contract });
|
277
|
-
return Object.assign(implementer, result);
|
278
|
-
}
|
279
|
-
|
280
|
-
// src/builder.ts
|
281
|
-
var Builder = class _Builder {
|
282
|
-
constructor(zz$b = {}) {
|
283
|
-
this.zz$b = zz$b;
|
284
|
-
}
|
285
|
-
/**
|
286
|
-
* Self chainable
|
287
|
-
*/
|
288
|
-
context() {
|
289
|
-
return this;
|
290
|
-
}
|
291
162
|
use(middleware, mapInput) {
|
292
|
-
const
|
163
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
293
164
|
return new _Builder({
|
294
|
-
...this
|
295
|
-
middlewares: [
|
165
|
+
...this["~orpc"],
|
166
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
296
167
|
});
|
297
168
|
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
return new ProcedureBuilder({
|
303
|
-
middlewares: this.zz$b.middlewares,
|
304
|
-
contract: new ContractProcedure({
|
305
|
-
...opts,
|
306
|
-
InputSchema: void 0,
|
307
|
-
OutputSchema: void 0
|
308
|
-
})
|
169
|
+
meta(meta) {
|
170
|
+
return new _Builder({
|
171
|
+
...this["~orpc"],
|
172
|
+
meta: mergeMeta2(this["~orpc"].meta, meta)
|
309
173
|
});
|
310
174
|
}
|
311
|
-
|
312
|
-
return new
|
313
|
-
|
314
|
-
|
315
|
-
OutputSchema: void 0,
|
316
|
-
InputSchema: schema,
|
317
|
-
inputExample: example
|
318
|
-
})
|
175
|
+
route(route) {
|
176
|
+
return new _Builder({
|
177
|
+
...this["~orpc"],
|
178
|
+
route: mergeRoute2(this["~orpc"].route, route)
|
319
179
|
});
|
320
180
|
}
|
321
|
-
|
322
|
-
return new
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
OutputSchema: schema,
|
327
|
-
outputExample: example
|
328
|
-
})
|
181
|
+
input(schema) {
|
182
|
+
return new _Builder({
|
183
|
+
...this["~orpc"],
|
184
|
+
inputSchema: schema,
|
185
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
329
186
|
});
|
330
187
|
}
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
zz$p: {
|
337
|
-
middlewares: this.zz$b.middlewares,
|
338
|
-
contract: new ContractProcedure({
|
339
|
-
InputSchema: void 0,
|
340
|
-
OutputSchema: void 0
|
341
|
-
}),
|
342
|
-
func
|
343
|
-
}
|
188
|
+
output(schema) {
|
189
|
+
return new _Builder({
|
190
|
+
...this["~orpc"],
|
191
|
+
outputSchema: schema,
|
192
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
344
193
|
});
|
345
194
|
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
return new ProcedureImplementer({
|
352
|
-
contract,
|
353
|
-
middlewares: this.zz$b.middlewares
|
354
|
-
});
|
355
|
-
}
|
356
|
-
return chainRouterImplementer(
|
357
|
-
contract,
|
358
|
-
this.zz$b.middlewares
|
359
|
-
);
|
360
|
-
}
|
361
|
-
/**
|
362
|
-
* Create ExtendedMiddleware
|
363
|
-
*/
|
364
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
365
|
-
// solution (maybe): create new generic for .output() method
|
366
|
-
middleware(middleware) {
|
367
|
-
return decorateMiddleware(middleware);
|
195
|
+
handler(handler) {
|
196
|
+
return new DecoratedProcedure({
|
197
|
+
...this["~orpc"],
|
198
|
+
handler
|
199
|
+
});
|
368
200
|
}
|
369
201
|
prefix(prefix) {
|
370
|
-
return new
|
371
|
-
...this
|
372
|
-
prefix
|
202
|
+
return new _Builder({
|
203
|
+
...this["~orpc"],
|
204
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
373
205
|
});
|
374
206
|
}
|
375
|
-
|
376
|
-
return new
|
377
|
-
...this
|
378
|
-
tags
|
207
|
+
tag(...tags) {
|
208
|
+
return new _Builder({
|
209
|
+
...this["~orpc"],
|
210
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
379
211
|
});
|
380
212
|
}
|
381
|
-
/**
|
382
|
-
* Create DecoratedRouter
|
383
|
-
*/
|
384
213
|
router(router) {
|
385
|
-
return
|
214
|
+
return adaptRouter(router, this["~orpc"]);
|
386
215
|
}
|
387
216
|
lazy(loader) {
|
388
|
-
return
|
217
|
+
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
389
218
|
}
|
390
219
|
};
|
220
|
+
var os = new Builder({
|
221
|
+
config: {},
|
222
|
+
route: {},
|
223
|
+
meta: {},
|
224
|
+
errorMap: {},
|
225
|
+
inputSchema: void 0,
|
226
|
+
outputSchema: void 0,
|
227
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex"),
|
228
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex"),
|
229
|
+
middlewares: []
|
230
|
+
});
|
391
231
|
|
392
|
-
// src/
|
393
|
-
|
394
|
-
|
395
|
-
}
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
232
|
+
// src/context.ts
|
233
|
+
function mergeContext(context, other) {
|
234
|
+
return { ...context, ...other };
|
235
|
+
}
|
236
|
+
|
237
|
+
// src/implementer.ts
|
238
|
+
import { isContractProcedure } from "@orpc/contract";
|
239
|
+
function implementerInternal(contract, config, middlewares) {
|
240
|
+
if (isContractProcedure(contract)) {
|
241
|
+
const impl2 = new Builder({
|
242
|
+
...contract["~orpc"],
|
243
|
+
config,
|
244
|
+
middlewares,
|
245
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config?.initialInputValidationIndex) + middlewares.length,
|
246
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config?.initialOutputValidationIndex) + middlewares.length
|
247
|
+
});
|
248
|
+
return impl2;
|
249
|
+
}
|
250
|
+
const impl = new Proxy(contract, {
|
251
|
+
get: (target, key) => {
|
252
|
+
let method;
|
253
|
+
if (key === "middleware") {
|
254
|
+
method = (mid) => decorateMiddleware(mid);
|
255
|
+
} else if (key === "use") {
|
256
|
+
method = (mid) => {
|
257
|
+
return implementerInternal(
|
258
|
+
contract,
|
259
|
+
config,
|
260
|
+
addMiddleware(middlewares, mid)
|
261
|
+
);
|
262
|
+
};
|
263
|
+
} else if (key === "router") {
|
264
|
+
method = (router) => {
|
265
|
+
const adapted = adaptRouter(router, {
|
266
|
+
middlewares,
|
267
|
+
errorMap: {}
|
268
|
+
});
|
269
|
+
return setRouterContract(adapted, contract);
|
270
|
+
};
|
271
|
+
} else if (key === "lazy") {
|
272
|
+
method = (loader) => {
|
273
|
+
const adapted = adaptRouter(flatLazy(lazy(loader)), {
|
274
|
+
middlewares,
|
275
|
+
errorMap: {}
|
276
|
+
});
|
277
|
+
return setRouterContract(adapted, contract);
|
278
|
+
};
|
279
|
+
}
|
280
|
+
const next = Reflect.get(target, key);
|
281
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
282
|
+
return method ?? next;
|
283
|
+
}
|
284
|
+
const nextImpl = implementerInternal(next, config, middlewares);
|
285
|
+
if (method) {
|
286
|
+
return new Proxy(method, {
|
287
|
+
get(_, key2) {
|
288
|
+
return Reflect.get(nextImpl, key2);
|
289
|
+
}
|
290
|
+
});
|
291
|
+
}
|
292
|
+
return nextImpl;
|
406
293
|
}
|
407
|
-
}
|
408
|
-
return
|
294
|
+
});
|
295
|
+
return impl;
|
296
|
+
}
|
297
|
+
function implement(contract, config = {}) {
|
298
|
+
const implInternal = implementerInternal(contract, config, []);
|
299
|
+
const impl = new Proxy(implInternal, {
|
300
|
+
get: (target, key) => {
|
301
|
+
let method;
|
302
|
+
if (key === "$context") {
|
303
|
+
method = () => impl;
|
304
|
+
} else if (key === "$config") {
|
305
|
+
method = (config2) => implement(contract, config2);
|
306
|
+
}
|
307
|
+
const next = Reflect.get(target, key);
|
308
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
309
|
+
return method ?? next;
|
310
|
+
}
|
311
|
+
if (method) {
|
312
|
+
return new Proxy(method, {
|
313
|
+
get(_, key2) {
|
314
|
+
return Reflect.get(next, key2);
|
315
|
+
}
|
316
|
+
});
|
317
|
+
}
|
318
|
+
return next;
|
319
|
+
}
|
320
|
+
});
|
321
|
+
return impl;
|
409
322
|
}
|
410
323
|
|
411
|
-
// src/
|
412
|
-
function
|
413
|
-
return
|
324
|
+
// src/procedure-utils.ts
|
325
|
+
function call(procedure, input, ...rest) {
|
326
|
+
return createProcedureClient(procedure, ...rest)(input);
|
414
327
|
}
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
}
|
328
|
+
|
329
|
+
// src/router-client.ts
|
330
|
+
function createRouterClient(router, ...rest) {
|
331
|
+
if (isProcedure(router)) {
|
332
|
+
const caller = createProcedureClient(router, ...rest);
|
333
|
+
return caller;
|
334
|
+
}
|
335
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
422
336
|
const recursive = new Proxy(procedureCaller, {
|
423
337
|
get(target, key) {
|
424
338
|
if (typeof key !== "string") {
|
425
339
|
return Reflect.get(target, key);
|
426
340
|
}
|
427
|
-
const next =
|
428
|
-
|
341
|
+
const next = getRouterChild(router, key);
|
342
|
+
if (!next) {
|
343
|
+
return Reflect.get(target, key);
|
344
|
+
}
|
345
|
+
const [options] = rest;
|
346
|
+
return createRouterClient(next, {
|
429
347
|
...options,
|
430
|
-
|
431
|
-
basePath: [...options.basePath ?? [], key]
|
348
|
+
path: [...options?.path ?? [], key]
|
432
349
|
});
|
433
350
|
}
|
434
351
|
});
|
@@ -436,32 +353,38 @@ function createRouterCallerInternal(options) {
|
|
436
353
|
}
|
437
354
|
|
438
355
|
// src/index.ts
|
439
|
-
|
440
|
-
var os = new Builder();
|
356
|
+
import { isDefinedError, ORPCError, safe, type } from "@orpc/contract";
|
441
357
|
export {
|
442
358
|
Builder,
|
359
|
+
DecoratedProcedure,
|
443
360
|
LAZY_LOADER_SYMBOL,
|
444
|
-
|
361
|
+
ORPCError,
|
445
362
|
Procedure,
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
createFlattenLazy,
|
453
|
-
createLazy,
|
454
|
-
createProcedureCaller,
|
455
|
-
createRouterCaller,
|
456
|
-
decorateLazy,
|
363
|
+
adaptRouter,
|
364
|
+
call,
|
365
|
+
createAccessibleLazyRouter,
|
366
|
+
createLazyProcedureFormAnyLazy,
|
367
|
+
createProcedureClient,
|
368
|
+
createRouterClient,
|
457
369
|
decorateMiddleware,
|
458
|
-
|
370
|
+
deepSetLazyRouterPrefix,
|
371
|
+
fallbackConfig,
|
372
|
+
flatLazy,
|
373
|
+
getLazyRouterPrefix,
|
374
|
+
getRouterChild,
|
375
|
+
getRouterContract,
|
376
|
+
implement,
|
377
|
+
implementerInternal,
|
378
|
+
isDefinedError,
|
459
379
|
isLazy,
|
460
380
|
isProcedure,
|
461
|
-
|
462
|
-
loadProcedure,
|
381
|
+
lazy,
|
463
382
|
mergeContext,
|
383
|
+
middlewareOutputFn,
|
464
384
|
os,
|
465
|
-
|
385
|
+
safe,
|
386
|
+
setRouterContract,
|
387
|
+
type,
|
388
|
+
unlazy
|
466
389
|
};
|
467
390
|
//# sourceMappingURL=index.js.map
|