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