@orpc/server 0.0.0-next.6a8bf13 → 0.0.0-next.6acfc62
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-JBPBLCBJ.js +136 -0
- package/dist/chunk-NOA3GBJQ.js +380 -0
- package/dist/chunk-OWMUECGT.js +111 -0
- package/dist/chunk-SUGWQSMQ.js +308 -0
- package/dist/fetch.js +14 -106
- package/dist/hono.js +42 -0
- package/dist/index.js +312 -375
- package/dist/next.js +39 -0
- package/dist/node.js +175 -0
- package/dist/plugins.js +11 -0
- package/dist/src/adapters/fetch/index.d.ts +4 -0
- package/dist/src/adapters/fetch/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/fetch/types.d.ts +13 -0
- package/dist/src/adapters/fetch/utils.d.ts +6 -0
- package/dist/src/adapters/hono/index.d.ts +3 -0
- package/dist/src/adapters/hono/middleware.d.ts +13 -0
- package/dist/src/adapters/next/index.d.ts +3 -0
- package/dist/src/adapters/next/serve.d.ts +20 -0
- package/dist/src/adapters/node/index.d.ts +4 -0
- package/dist/src/adapters/node/rpc-handler.d.ts +10 -0
- package/dist/src/adapters/node/types.d.ts +21 -0
- 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 +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 +17 -0
- package/dist/src/implementer.d.ts +28 -0
- package/dist/src/index.d.ts +16 -10
- 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/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 +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/dist/src/utils.d.ts +23 -2
- package/dist/standard.js +17 -0
- package/package.json +34 -9
- package/dist/chunk-MZXEMHFS.js +0 -272
- 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 -27
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -25
- 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 -8
package/dist/index.js
CHANGED
@@ -1,434 +1,355 @@
|
|
1
1
|
import {
|
2
2
|
LAZY_LOADER_SYMBOL,
|
3
3
|
Procedure,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
adaptRouter,
|
5
|
+
addMiddleware,
|
6
|
+
convertPathToHttpPath,
|
7
|
+
createAccessibleLazyRouter,
|
8
|
+
createContractedProcedure,
|
9
|
+
createLazyProcedureFormAnyLazy,
|
10
|
+
createProcedureClient,
|
11
|
+
deepSetLazyRouterPrefix,
|
12
|
+
eachAllContractProcedure,
|
13
|
+
eachContractProcedure,
|
14
|
+
flatLazy,
|
15
|
+
getLazyRouterPrefix,
|
16
|
+
getRouterChild,
|
17
|
+
getRouterContract,
|
10
18
|
isLazy,
|
11
19
|
isProcedure,
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
lazy,
|
21
|
+
middlewareOutputFn,
|
22
|
+
setRouterContract,
|
23
|
+
unlazy
|
24
|
+
} from "./chunk-NOA3GBJQ.js";
|
16
25
|
|
17
26
|
// src/builder.ts
|
18
|
-
import {
|
19
|
-
ContractProcedure,
|
20
|
-
isContractProcedure as isContractProcedure2
|
21
|
-
} from "@orpc/contract";
|
27
|
+
import { mergeErrorMap as mergeErrorMap2, mergeMeta as mergeMeta2, mergePrefix, mergeRoute as mergeRoute2, mergeTags } from "@orpc/contract";
|
22
28
|
|
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;
|
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];
|
67
37
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
38
|
+
return value;
|
39
|
+
}
|
40
|
+
|
41
|
+
// src/middleware-decorated.ts
|
42
|
+
function decorateMiddleware(middleware) {
|
43
|
+
const decorated = middleware;
|
44
|
+
decorated.mapInput = (mapInput) => {
|
45
|
+
const mapped = decorateMiddleware(
|
46
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
47
|
+
);
|
48
|
+
return mapped;
|
49
|
+
};
|
50
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
51
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
52
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
53
|
+
const next = async (...[nextOptions]) => {
|
54
|
+
return mapped({ ...options, context: { ...nextOptions?.context, ...options.context } }, input, output, ...rest);
|
55
|
+
};
|
56
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
57
|
+
return merged;
|
74
58
|
});
|
75
|
-
return
|
76
|
-
}
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
59
|
+
return concatted;
|
60
|
+
};
|
61
|
+
return decorated;
|
62
|
+
}
|
63
|
+
|
64
|
+
// src/procedure-decorated.ts
|
65
|
+
import { mergeErrorMap, mergeMeta, mergeRoute } from "@orpc/contract";
|
66
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
67
|
+
errors(errors) {
|
68
|
+
return new _DecoratedProcedure({
|
69
|
+
...this["~orpc"],
|
70
|
+
errorMap: mergeErrorMap(this["~orpc"].errorMap, errors)
|
83
71
|
});
|
84
72
|
}
|
85
|
-
|
86
|
-
return
|
87
|
-
...
|
88
|
-
|
73
|
+
meta(meta) {
|
74
|
+
return new _DecoratedProcedure({
|
75
|
+
...this["~orpc"],
|
76
|
+
meta: mergeMeta(this["~orpc"].meta, meta)
|
89
77
|
});
|
90
78
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
routerOrChild: options.routerOrChild[key]
|
79
|
+
route(route) {
|
80
|
+
return new _DecoratedProcedure({
|
81
|
+
...this["~orpc"],
|
82
|
+
route: mergeRoute(this["~orpc"].route, route)
|
96
83
|
});
|
97
84
|
}
|
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
85
|
use(middleware, mapInput) {
|
163
|
-
const
|
164
|
-
return new
|
165
|
-
...this
|
166
|
-
middlewares: [
|
86
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
87
|
+
return new _DecoratedProcedure({
|
88
|
+
...this["~orpc"],
|
89
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
167
90
|
});
|
168
91
|
}
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
92
|
+
/**
|
93
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
94
|
+
*/
|
95
|
+
callable(...rest) {
|
96
|
+
return Object.assign(createProcedureClient(this, ...rest), {
|
97
|
+
"~type": "Procedure",
|
98
|
+
"~orpc": this["~orpc"]
|
176
99
|
});
|
177
100
|
}
|
178
|
-
|
179
|
-
|
101
|
+
/**
|
102
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
103
|
+
*/
|
104
|
+
actionable(...rest) {
|
105
|
+
return this.callable(...rest);
|
180
106
|
}
|
181
107
|
};
|
182
108
|
|
183
|
-
// src/
|
184
|
-
var
|
185
|
-
|
186
|
-
|
109
|
+
// src/builder.ts
|
110
|
+
var Builder = class _Builder {
|
111
|
+
"~orpc";
|
112
|
+
constructor(def) {
|
113
|
+
this["~orpc"] = def;
|
187
114
|
}
|
188
115
|
/**
|
189
|
-
*
|
116
|
+
* Reset config
|
190
117
|
*/
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
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({
|
122
|
+
...this["~orpc"],
|
123
|
+
config,
|
124
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", config.initialInputValidationIndex) + inputValidationCount,
|
125
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", config.initialOutputValidationIndex) + outputValidationCount
|
197
126
|
});
|
198
127
|
}
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
128
|
+
/**
|
129
|
+
* Reset initial context
|
130
|
+
*/
|
131
|
+
$context() {
|
132
|
+
return new _Builder({
|
133
|
+
...this["~orpc"],
|
134
|
+
middlewares: [],
|
135
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex),
|
136
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex)
|
206
137
|
});
|
207
138
|
}
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
139
|
+
/**
|
140
|
+
* Reset initial meta
|
141
|
+
*/
|
142
|
+
$meta(initialMeta) {
|
143
|
+
return new _Builder({
|
144
|
+
...this["~orpc"],
|
145
|
+
meta: initialMeta
|
215
146
|
});
|
216
147
|
}
|
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
148
|
/**
|
230
|
-
*
|
149
|
+
* Reset initial route
|
231
150
|
*/
|
232
|
-
|
233
|
-
return
|
234
|
-
|
235
|
-
|
236
|
-
contract: this.zz$pb.contract,
|
237
|
-
func
|
238
|
-
}
|
151
|
+
$route(initialRoute) {
|
152
|
+
return new _Builder({
|
153
|
+
...this["~orpc"],
|
154
|
+
route: initialRoute
|
239
155
|
});
|
240
156
|
}
|
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
|
-
});
|
157
|
+
middleware(middleware) {
|
158
|
+
return decorateMiddleware(middleware);
|
254
159
|
}
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
160
|
+
errors(errors) {
|
161
|
+
return new _Builder({
|
162
|
+
...this["~orpc"],
|
163
|
+
errorMap: mergeErrorMap2(this["~orpc"].errorMap, errors)
|
260
164
|
});
|
261
165
|
}
|
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
166
|
use(middleware, mapInput) {
|
292
|
-
const
|
167
|
+
const mapped = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
293
168
|
return new _Builder({
|
294
|
-
...this
|
295
|
-
middlewares: [
|
169
|
+
...this["~orpc"],
|
170
|
+
middlewares: addMiddleware(this["~orpc"].middlewares, mapped)
|
296
171
|
});
|
297
172
|
}
|
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
|
-
})
|
173
|
+
meta(meta) {
|
174
|
+
return new _Builder({
|
175
|
+
...this["~orpc"],
|
176
|
+
meta: mergeMeta2(this["~orpc"].meta, meta)
|
309
177
|
});
|
310
178
|
}
|
311
|
-
|
312
|
-
return new
|
313
|
-
|
314
|
-
|
315
|
-
OutputSchema: void 0,
|
316
|
-
InputSchema: schema,
|
317
|
-
inputExample: example
|
318
|
-
})
|
179
|
+
route(route) {
|
180
|
+
return new _Builder({
|
181
|
+
...this["~orpc"],
|
182
|
+
route: mergeRoute2(this["~orpc"].route, route)
|
319
183
|
});
|
320
184
|
}
|
321
|
-
|
322
|
-
return new
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
OutputSchema: schema,
|
327
|
-
outputExample: example
|
328
|
-
})
|
185
|
+
input(schema) {
|
186
|
+
return new _Builder({
|
187
|
+
...this["~orpc"],
|
188
|
+
inputSchema: schema,
|
189
|
+
inputValidationIndex: fallbackConfig("initialInputValidationIndex", this["~orpc"].config.initialInputValidationIndex) + this["~orpc"].middlewares.length
|
329
190
|
});
|
330
191
|
}
|
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
|
-
}
|
192
|
+
output(schema) {
|
193
|
+
return new _Builder({
|
194
|
+
...this["~orpc"],
|
195
|
+
outputSchema: schema,
|
196
|
+
outputValidationIndex: fallbackConfig("initialOutputValidationIndex", this["~orpc"].config.initialOutputValidationIndex) + this["~orpc"].middlewares.length
|
344
197
|
});
|
345
198
|
}
|
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);
|
199
|
+
handler(handler) {
|
200
|
+
return new DecoratedProcedure({
|
201
|
+
...this["~orpc"],
|
202
|
+
handler
|
203
|
+
});
|
368
204
|
}
|
369
205
|
prefix(prefix) {
|
370
|
-
return new
|
371
|
-
...this
|
372
|
-
prefix
|
206
|
+
return new _Builder({
|
207
|
+
...this["~orpc"],
|
208
|
+
prefix: mergePrefix(this["~orpc"].prefix, prefix)
|
373
209
|
});
|
374
210
|
}
|
375
|
-
|
376
|
-
return new
|
377
|
-
...this
|
378
|
-
tags
|
211
|
+
tag(...tags) {
|
212
|
+
return new _Builder({
|
213
|
+
...this["~orpc"],
|
214
|
+
tags: mergeTags(this["~orpc"].tags, tags)
|
379
215
|
});
|
380
216
|
}
|
381
|
-
/**
|
382
|
-
* Create DecoratedRouter
|
383
|
-
*/
|
384
217
|
router(router) {
|
385
|
-
return
|
218
|
+
return adaptRouter(router, this["~orpc"]);
|
386
219
|
}
|
387
220
|
lazy(loader) {
|
388
|
-
return
|
221
|
+
return adaptRouter(flatLazy(lazy(loader)), this["~orpc"]);
|
389
222
|
}
|
390
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
|
+
});
|
391
235
|
|
392
|
-
// src/
|
393
|
-
|
394
|
-
|
395
|
-
}
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
236
|
+
// src/context.ts
|
237
|
+
function mergeContext(context, other) {
|
238
|
+
return { ...context, ...other };
|
239
|
+
}
|
240
|
+
|
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;
|
406
297
|
}
|
407
|
-
}
|
408
|
-
return
|
298
|
+
});
|
299
|
+
return impl;
|
300
|
+
}
|
301
|
+
function implement(contract, config = {}) {
|
302
|
+
const implInternal = implementerInternal(contract, config, []);
|
303
|
+
const impl = new Proxy(implInternal, {
|
304
|
+
get: (target, key) => {
|
305
|
+
let method;
|
306
|
+
if (key === "$context") {
|
307
|
+
method = () => impl;
|
308
|
+
} else if (key === "$config") {
|
309
|
+
method = (config2) => implement(contract, config2);
|
310
|
+
}
|
311
|
+
const next = Reflect.get(target, key);
|
312
|
+
if (!next || typeof next !== "function" && typeof next !== "object") {
|
313
|
+
return method ?? next;
|
314
|
+
}
|
315
|
+
if (method) {
|
316
|
+
return new Proxy(method, {
|
317
|
+
get(_, key2) {
|
318
|
+
return Reflect.get(next, key2);
|
319
|
+
}
|
320
|
+
});
|
321
|
+
}
|
322
|
+
return next;
|
323
|
+
}
|
324
|
+
});
|
325
|
+
return impl;
|
409
326
|
}
|
410
327
|
|
411
|
-
// src/
|
412
|
-
function
|
413
|
-
return
|
328
|
+
// src/procedure-utils.ts
|
329
|
+
function call(procedure, input, ...rest) {
|
330
|
+
return createProcedureClient(procedure, ...rest)(input);
|
414
331
|
}
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
}
|
332
|
+
|
333
|
+
// src/router-client.ts
|
334
|
+
function createRouterClient(router, ...rest) {
|
335
|
+
if (isProcedure(router)) {
|
336
|
+
const caller = createProcedureClient(router, ...rest);
|
337
|
+
return caller;
|
338
|
+
}
|
339
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
422
340
|
const recursive = new Proxy(procedureCaller, {
|
423
341
|
get(target, key) {
|
424
342
|
if (typeof key !== "string") {
|
425
343
|
return Reflect.get(target, key);
|
426
344
|
}
|
427
|
-
const next =
|
428
|
-
|
345
|
+
const next = getRouterChild(router, key);
|
346
|
+
if (!next) {
|
347
|
+
return Reflect.get(target, key);
|
348
|
+
}
|
349
|
+
const [options] = rest;
|
350
|
+
return createRouterClient(next, {
|
429
351
|
...options,
|
430
|
-
|
431
|
-
basePath: [...options.basePath ?? [], key]
|
352
|
+
path: [...options?.path ?? [], key]
|
432
353
|
});
|
433
354
|
}
|
434
355
|
});
|
@@ -436,32 +357,48 @@ function createRouterCallerInternal(options) {
|
|
436
357
|
}
|
437
358
|
|
438
359
|
// src/index.ts
|
439
|
-
|
440
|
-
|
360
|
+
import { isDefinedError, ORPCError, safe, type, ValidationError } from "@orpc/contract";
|
361
|
+
import { onError, onFinish, onStart, onSuccess } from "@orpc/shared";
|
441
362
|
export {
|
442
363
|
Builder,
|
364
|
+
DecoratedProcedure,
|
443
365
|
LAZY_LOADER_SYMBOL,
|
444
|
-
|
366
|
+
ORPCError,
|
445
367
|
Procedure,
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
createRouterCaller,
|
456
|
-
decorateLazy,
|
368
|
+
ValidationError,
|
369
|
+
adaptRouter,
|
370
|
+
call,
|
371
|
+
convertPathToHttpPath,
|
372
|
+
createAccessibleLazyRouter,
|
373
|
+
createContractedProcedure,
|
374
|
+
createLazyProcedureFormAnyLazy,
|
375
|
+
createProcedureClient,
|
376
|
+
createRouterClient,
|
457
377
|
decorateMiddleware,
|
458
|
-
|
378
|
+
deepSetLazyRouterPrefix,
|
379
|
+
eachAllContractProcedure,
|
380
|
+
eachContractProcedure,
|
381
|
+
fallbackConfig,
|
382
|
+
flatLazy,
|
383
|
+
getLazyRouterPrefix,
|
384
|
+
getRouterChild,
|
385
|
+
getRouterContract,
|
386
|
+
implement,
|
387
|
+
implementerInternal,
|
388
|
+
isDefinedError,
|
459
389
|
isLazy,
|
460
390
|
isProcedure,
|
461
|
-
|
462
|
-
loadProcedure,
|
391
|
+
lazy,
|
463
392
|
mergeContext,
|
393
|
+
middlewareOutputFn,
|
394
|
+
onError,
|
395
|
+
onFinish,
|
396
|
+
onStart,
|
397
|
+
onSuccess,
|
464
398
|
os,
|
465
|
-
|
399
|
+
safe,
|
400
|
+
setRouterContract,
|
401
|
+
type,
|
402
|
+
unlazy
|
466
403
|
};
|
467
404
|
//# sourceMappingURL=index.js.map
|