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