@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.c6c659d
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-MB74GD7C.js +301 -0
- package/dist/chunk-WUOGVGWG.js +1 -0
- package/dist/chunk-ZBJYYEII.js +227 -0
- package/dist/fetch.js +11 -102
- package/dist/hono.js +30 -0
- package/dist/index.js +430 -274
- 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.d.ts +30 -43
- package/dist/src/error.d.ts +10 -0
- package/dist/src/hidden.d.ts +6 -0
- package/dist/src/implementer-chainable.d.ts +10 -0
- package/dist/src/index.d.ts +14 -4
- package/dist/src/lazy-decorated.d.ts +7 -0
- package/dist/src/lazy-utils.d.ts +4 -0
- package/dist/src/lazy.d.ts +18 -0
- package/dist/src/middleware-decorated.d.ts +9 -0
- package/dist/src/middleware.d.ts +21 -12
- package/dist/src/procedure-builder.d.ts +19 -26
- package/dist/src/procedure-client.d.ts +22 -0
- package/dist/src/procedure-decorated.d.ts +26 -0
- package/dist/src/procedure-implementer.d.ts +16 -15
- package/dist/src/procedure-utils.d.ts +17 -0
- package/dist/src/procedure.d.ts +39 -25
- package/dist/src/router-builder.d.ts +24 -17
- package/dist/src/router-client.d.ts +27 -0
- package/dist/src/router-implementer.d.ts +18 -17
- package/dist/src/router.d.ts +11 -15
- package/dist/src/types.d.ts +10 -4
- package/package.json +22 -11
- package/dist/chunk-TDFYNRZV.js +0 -190
- 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-caller.d.ts +0 -19
- package/dist/src/router-caller.d.ts +0 -22
package/dist/index.js
CHANGED
@@ -1,394 +1,550 @@
|
|
1
1
|
import {
|
2
|
+
LAZY_LOADER_SYMBOL,
|
2
3
|
Procedure,
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
createORPCErrorConstructorMap,
|
5
|
+
createProcedureClient,
|
6
|
+
flatLazy,
|
7
|
+
getRouterChild,
|
8
|
+
isLazy,
|
6
9
|
isProcedure,
|
7
|
-
|
8
|
-
|
10
|
+
lazy,
|
11
|
+
mergeContext,
|
12
|
+
unlazy
|
13
|
+
} from "./chunk-ZBJYYEII.js";
|
9
14
|
|
10
15
|
// src/builder.ts
|
11
|
-
import {
|
12
|
-
ContractProcedure,
|
13
|
-
isContractProcedure as isContractProcedure2
|
14
|
-
} from "@orpc/contract";
|
16
|
+
import { ContractProcedure } from "@orpc/contract";
|
15
17
|
|
16
|
-
// src/
|
17
|
-
import {
|
18
|
-
|
19
|
-
} from "@orpc/contract";
|
18
|
+
// src/implementer-chainable.ts
|
19
|
+
import { isContractProcedure } from "@orpc/contract";
|
20
|
+
import { createCallableObject as createCallableObject2 } from "@orpc/shared";
|
20
21
|
|
21
|
-
// src/
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
// src/middleware-decorated.ts
|
23
|
+
function decorateMiddleware(middleware) {
|
24
|
+
const decorated = middleware;
|
25
|
+
decorated.mapInput = (mapInput) => {
|
26
|
+
const mapped = decorateMiddleware(
|
27
|
+
(options, input, ...rest) => middleware(options, mapInput(input), ...rest)
|
28
|
+
);
|
29
|
+
return mapped;
|
30
|
+
};
|
31
|
+
decorated.concat = (concatMiddleware, mapInput) => {
|
32
|
+
const mapped = mapInput ? decorateMiddleware(concatMiddleware).mapInput(mapInput) : concatMiddleware;
|
33
|
+
const concatted = decorateMiddleware((options, input, output, ...rest) => {
|
34
|
+
const next = async (nextOptions) => {
|
35
|
+
return mapped({ ...options, context: mergeContext(nextOptions.context, options.context) }, input, output, ...rest);
|
36
|
+
};
|
37
|
+
const merged = middleware({ ...options, next }, input, output, ...rest);
|
38
|
+
return merged;
|
39
|
+
});
|
40
|
+
return concatted;
|
41
|
+
};
|
42
|
+
return decorated;
|
43
|
+
}
|
44
|
+
|
45
|
+
// src/procedure-decorated.ts
|
46
|
+
import { DecoratedContractProcedure } from "@orpc/contract";
|
47
|
+
import { createCallableObject } from "@orpc/shared";
|
48
|
+
var DecoratedProcedure = class _DecoratedProcedure extends Procedure {
|
49
|
+
static decorate(procedure) {
|
50
|
+
if (procedure instanceof _DecoratedProcedure) {
|
51
|
+
return procedure;
|
52
|
+
}
|
53
|
+
return new _DecoratedProcedure(procedure["~orpc"]);
|
54
|
+
}
|
55
|
+
prefix(prefix) {
|
56
|
+
return new _DecoratedProcedure({
|
57
|
+
...this["~orpc"],
|
58
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).prefix(prefix)
|
59
|
+
});
|
60
|
+
}
|
61
|
+
route(route) {
|
62
|
+
return new _DecoratedProcedure({
|
63
|
+
...this["~orpc"],
|
64
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).route(route)
|
65
|
+
});
|
25
66
|
}
|
26
67
|
use(middleware, mapInput) {
|
27
68
|
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
28
|
-
return new
|
29
|
-
...this
|
30
|
-
middlewares: [...this.
|
69
|
+
return new _DecoratedProcedure({
|
70
|
+
...this["~orpc"],
|
71
|
+
middlewares: [...this["~orpc"].middlewares ?? [], middleware_]
|
31
72
|
});
|
32
73
|
}
|
33
|
-
|
34
|
-
return
|
35
|
-
|
36
|
-
|
37
|
-
contract: this.zz$pi.contract,
|
38
|
-
func
|
39
|
-
}
|
74
|
+
unshiftTag(...tags) {
|
75
|
+
return new _DecoratedProcedure({
|
76
|
+
...this["~orpc"],
|
77
|
+
contract: DecoratedContractProcedure.decorate(this["~orpc"].contract).unshiftTag(...tags)
|
40
78
|
});
|
41
79
|
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
80
|
+
unshiftMiddleware(...middlewares) {
|
81
|
+
const castedMiddlewares = middlewares;
|
82
|
+
if (this["~orpc"].middlewares?.length) {
|
83
|
+
let min = 0;
|
84
|
+
for (let i = 0; i < this["~orpc"].middlewares.length; i++) {
|
85
|
+
const index = castedMiddlewares.indexOf(this["~orpc"].middlewares[i], min);
|
86
|
+
if (index === -1) {
|
87
|
+
castedMiddlewares.push(...this["~orpc"].middlewares.slice(i));
|
88
|
+
break;
|
89
|
+
}
|
90
|
+
min = index + 1;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
return new _DecoratedProcedure({
|
94
|
+
...this["~orpc"],
|
95
|
+
middlewares: castedMiddlewares
|
96
|
+
});
|
48
97
|
}
|
49
98
|
/**
|
50
|
-
*
|
99
|
+
* Make this procedure callable (works like a function while still being a procedure).
|
100
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
51
101
|
*/
|
52
|
-
|
53
|
-
return
|
54
|
-
...this.zz$pb,
|
55
|
-
contract: DecoratedContractProcedure.decorate(this.zz$pb.contract).route(
|
56
|
-
opts
|
57
|
-
)
|
58
|
-
});
|
102
|
+
callable(...rest) {
|
103
|
+
return createCallableObject(this, createProcedureClient(this, ...rest));
|
59
104
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
)
|
67
|
-
});
|
105
|
+
/**
|
106
|
+
* Make this procedure compatible with server action (the same as .callable, but the type is compatible with server action).
|
107
|
+
* **Note**: this only takes effect when this method is called at the end of the chain.
|
108
|
+
*/
|
109
|
+
actionable(...rest) {
|
110
|
+
return this.callable(...rest);
|
68
111
|
}
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
112
|
+
};
|
113
|
+
|
114
|
+
// src/procedure-implementer.ts
|
115
|
+
var ProcedureImplementer = class _ProcedureImplementer {
|
116
|
+
"~type" = "ProcedureImplementer";
|
117
|
+
"~orpc";
|
118
|
+
constructor(def) {
|
119
|
+
this["~orpc"] = def;
|
77
120
|
}
|
78
121
|
use(middleware, mapInput) {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
return new ProcedureImplementer({
|
86
|
-
contract: this.zz$pb.contract,
|
87
|
-
middlewares: this.zz$pb.middlewares
|
88
|
-
}).use(middleware, mapInput);
|
122
|
+
const mappedMiddleware = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
123
|
+
return new _ProcedureImplementer({
|
124
|
+
...this["~orpc"],
|
125
|
+
middlewares: [...this["~orpc"].middlewares ?? [], mappedMiddleware]
|
126
|
+
});
|
89
127
|
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
zz$p: {
|
96
|
-
middlewares: this.zz$pb.middlewares,
|
97
|
-
contract: this.zz$pb.contract,
|
98
|
-
func
|
99
|
-
}
|
128
|
+
handler(handler) {
|
129
|
+
return new DecoratedProcedure({
|
130
|
+
middlewares: this["~orpc"].middlewares,
|
131
|
+
contract: this["~orpc"].contract,
|
132
|
+
handler
|
100
133
|
});
|
101
134
|
}
|
102
135
|
};
|
103
136
|
|
137
|
+
// src/hidden.ts
|
138
|
+
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
139
|
+
function setRouterContract(obj, contract) {
|
140
|
+
return new Proxy(obj, {
|
141
|
+
get(target, key) {
|
142
|
+
if (key === ROUTER_CONTRACT_SYMBOL) {
|
143
|
+
return contract;
|
144
|
+
}
|
145
|
+
return Reflect.get(target, key);
|
146
|
+
}
|
147
|
+
});
|
148
|
+
}
|
149
|
+
function getRouterContract(obj) {
|
150
|
+
return obj[ROUTER_CONTRACT_SYMBOL];
|
151
|
+
}
|
152
|
+
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
153
|
+
function deepSetLazyRouterPrefix(router, prefix) {
|
154
|
+
return new Proxy(router, {
|
155
|
+
get(target, key) {
|
156
|
+
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
157
|
+
const val = Reflect.get(target, key);
|
158
|
+
if (val && (typeof val === "object" || typeof val === "function")) {
|
159
|
+
return deepSetLazyRouterPrefix(val, prefix);
|
160
|
+
}
|
161
|
+
return val;
|
162
|
+
}
|
163
|
+
return prefix;
|
164
|
+
}
|
165
|
+
});
|
166
|
+
}
|
167
|
+
function getLazyRouterPrefix(obj) {
|
168
|
+
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
169
|
+
}
|
170
|
+
|
171
|
+
// src/lazy-decorated.ts
|
172
|
+
function decorateLazy(lazied) {
|
173
|
+
const flattenLazy = flatLazy(lazied);
|
174
|
+
const recursive = new Proxy(flattenLazy, {
|
175
|
+
get(target, key) {
|
176
|
+
if (typeof key !== "string") {
|
177
|
+
return Reflect.get(target, key);
|
178
|
+
}
|
179
|
+
const next = getRouterChild(flattenLazy, key);
|
180
|
+
return decorateLazy(next);
|
181
|
+
}
|
182
|
+
});
|
183
|
+
return recursive;
|
184
|
+
}
|
185
|
+
|
104
186
|
// src/router-builder.ts
|
105
|
-
import { DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract";
|
106
187
|
var RouterBuilder = class _RouterBuilder {
|
107
|
-
|
108
|
-
|
188
|
+
"~type" = "RouterBuilder";
|
189
|
+
"~orpc";
|
190
|
+
constructor(def) {
|
191
|
+
this["~orpc"] = def;
|
192
|
+
if (def.prefix && def.prefix.includes("{")) {
|
193
|
+
throw new Error(`
|
194
|
+
Dynamic routing in prefix not supported yet.
|
195
|
+
Please remove "{" from "${def.prefix}".
|
196
|
+
`);
|
197
|
+
}
|
109
198
|
}
|
110
199
|
prefix(prefix) {
|
111
200
|
return new _RouterBuilder({
|
112
|
-
...this
|
113
|
-
prefix: `${this.
|
201
|
+
...this["~orpc"],
|
202
|
+
prefix: `${this["~orpc"].prefix ?? ""}${prefix}`
|
114
203
|
});
|
115
204
|
}
|
116
|
-
|
117
|
-
if (!tags.length)
|
118
|
-
return this;
|
205
|
+
tag(...tags) {
|
119
206
|
return new _RouterBuilder({
|
120
|
-
...this
|
121
|
-
tags: [...this.
|
207
|
+
...this["~orpc"],
|
208
|
+
tags: [...this["~orpc"].tags ?? [], ...tags]
|
122
209
|
});
|
123
210
|
}
|
124
|
-
use(middleware
|
125
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
211
|
+
use(middleware) {
|
126
212
|
return new _RouterBuilder({
|
127
|
-
...this
|
128
|
-
middlewares: [...this.
|
213
|
+
...this["~orpc"],
|
214
|
+
middlewares: [...this["~orpc"].middlewares ?? [], middleware]
|
129
215
|
});
|
130
216
|
}
|
131
217
|
router(router) {
|
132
|
-
const
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
const middlewares = [
|
139
|
-
...builderMiddlewares,
|
140
|
-
...itemMiddlewares.filter(
|
141
|
-
(item2) => !builderMiddlewares.includes(item2)
|
142
|
-
)
|
143
|
-
];
|
144
|
-
const contract = DecoratedContractProcedure2.decorate(
|
145
|
-
item.zz$p.contract
|
146
|
-
).addTags(...this.zz$rb.tags ?? []);
|
147
|
-
handled[key] = decorateProcedure({
|
148
|
-
zz$p: {
|
149
|
-
...item.zz$p,
|
150
|
-
contract: this.zz$rb.prefix ? contract.prefix(this.zz$rb.prefix) : contract,
|
151
|
-
middlewares
|
152
|
-
}
|
153
|
-
});
|
154
|
-
} else {
|
155
|
-
handled[key] = this.router(item);
|
156
|
-
}
|
157
|
-
}
|
158
|
-
return handled;
|
218
|
+
const adapted = adapt(router, this["~orpc"]);
|
219
|
+
return adapted;
|
220
|
+
}
|
221
|
+
lazy(loader) {
|
222
|
+
const adapted = adapt(flatLazy(lazy(loader)), this["~orpc"]);
|
223
|
+
return adapted;
|
159
224
|
}
|
160
225
|
};
|
226
|
+
function adapt(item, options) {
|
227
|
+
if (isLazy(item)) {
|
228
|
+
const adaptedLazy = decorateLazy(lazy(async () => {
|
229
|
+
const routerOrProcedure = (await unlazy(item)).default;
|
230
|
+
const adapted2 = adapt(routerOrProcedure, options);
|
231
|
+
return { default: adapted2 };
|
232
|
+
}));
|
233
|
+
const lazyPrefix = getLazyRouterPrefix(item);
|
234
|
+
if (options.prefix || lazyPrefix) {
|
235
|
+
const prefixed = deepSetLazyRouterPrefix(adaptedLazy, `${options.prefix ?? ""}${lazyPrefix ?? ""}`);
|
236
|
+
return prefixed;
|
237
|
+
}
|
238
|
+
return adaptedLazy;
|
239
|
+
}
|
240
|
+
if (isProcedure(item)) {
|
241
|
+
let decorated = DecoratedProcedure.decorate(item);
|
242
|
+
if (options.tags?.length) {
|
243
|
+
decorated = decorated.unshiftTag(...options.tags);
|
244
|
+
}
|
245
|
+
if (options.prefix) {
|
246
|
+
decorated = decorated.prefix(options.prefix);
|
247
|
+
}
|
248
|
+
if (options.middlewares?.length) {
|
249
|
+
decorated = decorated.unshiftMiddleware(...options.middlewares);
|
250
|
+
}
|
251
|
+
return decorated;
|
252
|
+
}
|
253
|
+
const adapted = {};
|
254
|
+
for (const key in item) {
|
255
|
+
adapted[key] = adapt(item[key], options);
|
256
|
+
}
|
257
|
+
return adapted;
|
258
|
+
}
|
161
259
|
|
162
260
|
// src/router-implementer.ts
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
261
|
+
var RouterImplementer = class _RouterImplementer {
|
262
|
+
"~type" = "RouterImplementer";
|
263
|
+
"~orpc";
|
264
|
+
constructor(def) {
|
265
|
+
this["~orpc"] = def;
|
266
|
+
}
|
267
|
+
use(middleware) {
|
268
|
+
return new _RouterImplementer({
|
269
|
+
...this["~orpc"],
|
270
|
+
middlewares: [...this["~orpc"].middlewares ?? [], middleware]
|
271
|
+
});
|
169
272
|
}
|
170
273
|
router(router) {
|
171
|
-
|
172
|
-
|
274
|
+
const adapted = new RouterBuilder(this["~orpc"]).router(router);
|
275
|
+
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
276
|
+
return contracted;
|
277
|
+
}
|
278
|
+
lazy(loader) {
|
279
|
+
const adapted = new RouterBuilder(this["~orpc"]).lazy(loader);
|
280
|
+
const contracted = setRouterContract(adapted, this["~orpc"].contract);
|
281
|
+
return contracted;
|
173
282
|
}
|
174
283
|
};
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
} else {
|
185
|
-
result[key] = chainRouterImplementer(item, middlewares);
|
186
|
-
}
|
284
|
+
|
285
|
+
// src/implementer-chainable.ts
|
286
|
+
function createChainableImplementer(contract, middlewares) {
|
287
|
+
if (isContractProcedure(contract)) {
|
288
|
+
const implementer = new ProcedureImplementer({
|
289
|
+
contract,
|
290
|
+
middlewares
|
291
|
+
});
|
292
|
+
return implementer;
|
187
293
|
}
|
188
|
-
const
|
189
|
-
return Object.assign(implementer, result);
|
190
|
-
}
|
191
|
-
function assertRouterImplementation(contract, router, path = []) {
|
294
|
+
const chainable = {};
|
192
295
|
for (const key in contract) {
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
);
|
200
|
-
|
201
|
-
|
202
|
-
if (isProcedure(routerItem)) {
|
203
|
-
if (routerItem.zz$p.contract !== contractItem) {
|
204
|
-
throw new Error(
|
205
|
-
`Mismatch implementation for procedure at [${currentPath.join(".")}]`
|
206
|
-
);
|
207
|
-
}
|
208
|
-
} else {
|
209
|
-
throw new Error(
|
210
|
-
`Mismatch implementation for procedure at [${currentPath.join(".")}]`
|
211
|
-
);
|
296
|
+
chainable[key] = createChainableImplementer(contract[key], middlewares);
|
297
|
+
}
|
298
|
+
const routerImplementer = new RouterImplementer({ contract, middlewares });
|
299
|
+
const merged = new Proxy(chainable, {
|
300
|
+
get(target, key) {
|
301
|
+
const next = Reflect.get(target, key);
|
302
|
+
const method = Reflect.get(routerImplementer, key);
|
303
|
+
if (typeof key !== "string" || typeof method !== "function") {
|
304
|
+
return next;
|
212
305
|
}
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
currentPath
|
218
|
-
);
|
306
|
+
if (!next) {
|
307
|
+
return method.bind(routerImplementer);
|
308
|
+
}
|
309
|
+
return createCallableObject2(next, method.bind(routerImplementer));
|
219
310
|
}
|
220
|
-
}
|
311
|
+
});
|
312
|
+
return merged;
|
221
313
|
}
|
222
314
|
|
315
|
+
// src/procedure-builder.ts
|
316
|
+
import {
|
317
|
+
DecoratedContractProcedure as DecoratedContractProcedure2
|
318
|
+
} from "@orpc/contract";
|
319
|
+
var ProcedureBuilder = class _ProcedureBuilder {
|
320
|
+
"~type" = "ProcedureBuilder";
|
321
|
+
"~orpc";
|
322
|
+
constructor(def) {
|
323
|
+
this["~orpc"] = def;
|
324
|
+
}
|
325
|
+
route(route) {
|
326
|
+
return new _ProcedureBuilder({
|
327
|
+
...this["~orpc"],
|
328
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).route(route)
|
329
|
+
});
|
330
|
+
}
|
331
|
+
input(schema, example) {
|
332
|
+
return new _ProcedureBuilder({
|
333
|
+
...this["~orpc"],
|
334
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).input(schema, example)
|
335
|
+
});
|
336
|
+
}
|
337
|
+
output(schema, example) {
|
338
|
+
return new _ProcedureBuilder({
|
339
|
+
...this["~orpc"],
|
340
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).output(schema, example)
|
341
|
+
});
|
342
|
+
}
|
343
|
+
errors(errors) {
|
344
|
+
return new _ProcedureBuilder({
|
345
|
+
...this["~orpc"],
|
346
|
+
contract: DecoratedContractProcedure2.decorate(this["~orpc"].contract).errors(errors)
|
347
|
+
});
|
348
|
+
}
|
349
|
+
use(middleware, mapInput) {
|
350
|
+
if (!mapInput) {
|
351
|
+
return new ProcedureImplementer({
|
352
|
+
contract: this["~orpc"].contract,
|
353
|
+
middlewares: this["~orpc"].middlewares
|
354
|
+
}).use(middleware);
|
355
|
+
}
|
356
|
+
return new ProcedureImplementer({
|
357
|
+
contract: this["~orpc"].contract,
|
358
|
+
middlewares: this["~orpc"].middlewares
|
359
|
+
}).use(middleware, mapInput);
|
360
|
+
}
|
361
|
+
handler(handler) {
|
362
|
+
return new DecoratedProcedure({
|
363
|
+
middlewares: this["~orpc"].middlewares,
|
364
|
+
contract: this["~orpc"].contract,
|
365
|
+
handler
|
366
|
+
});
|
367
|
+
}
|
368
|
+
};
|
369
|
+
|
223
370
|
// src/builder.ts
|
224
371
|
var Builder = class _Builder {
|
225
|
-
|
226
|
-
|
372
|
+
"~type" = "Builder";
|
373
|
+
"~orpc";
|
374
|
+
constructor(def) {
|
375
|
+
this["~orpc"] = def;
|
227
376
|
}
|
228
|
-
/**
|
229
|
-
* Self chainable
|
230
|
-
*/
|
231
377
|
context() {
|
232
|
-
return
|
378
|
+
return new _Builder({});
|
233
379
|
}
|
234
|
-
use(middleware
|
235
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
380
|
+
use(middleware) {
|
236
381
|
return new _Builder({
|
237
|
-
...this
|
238
|
-
middlewares: [...this.
|
382
|
+
...this["~orpc"],
|
383
|
+
middlewares: [...this["~orpc"].middlewares ?? [], middleware]
|
239
384
|
});
|
240
385
|
}
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
route(
|
386
|
+
middleware(middleware) {
|
387
|
+
return decorateMiddleware(middleware);
|
388
|
+
}
|
389
|
+
route(route) {
|
245
390
|
return new ProcedureBuilder({
|
246
|
-
middlewares: this.
|
391
|
+
middlewares: this["~orpc"].middlewares,
|
247
392
|
contract: new ContractProcedure({
|
248
|
-
|
393
|
+
route,
|
249
394
|
InputSchema: void 0,
|
250
|
-
OutputSchema: void 0
|
395
|
+
OutputSchema: void 0,
|
396
|
+
errorMap: void 0
|
251
397
|
})
|
252
398
|
});
|
253
399
|
}
|
254
400
|
input(schema, example) {
|
255
401
|
return new ProcedureBuilder({
|
256
|
-
middlewares: this.
|
402
|
+
middlewares: this["~orpc"].middlewares,
|
257
403
|
contract: new ContractProcedure({
|
258
404
|
OutputSchema: void 0,
|
259
405
|
InputSchema: schema,
|
260
|
-
inputExample: example
|
406
|
+
inputExample: example,
|
407
|
+
errorMap: void 0
|
261
408
|
})
|
262
409
|
});
|
263
410
|
}
|
264
411
|
output(schema, example) {
|
265
412
|
return new ProcedureBuilder({
|
266
|
-
middlewares: this.
|
413
|
+
middlewares: this["~orpc"].middlewares,
|
267
414
|
contract: new ContractProcedure({
|
268
415
|
InputSchema: void 0,
|
269
416
|
OutputSchema: schema,
|
270
|
-
outputExample: example
|
417
|
+
outputExample: example,
|
418
|
+
errorMap: void 0
|
271
419
|
})
|
272
420
|
});
|
273
421
|
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
InputSchema: void 0,
|
283
|
-
OutputSchema: void 0
|
284
|
-
}),
|
285
|
-
func
|
286
|
-
}
|
422
|
+
errors(errors) {
|
423
|
+
return new ProcedureBuilder({
|
424
|
+
middlewares: this["~orpc"].middlewares,
|
425
|
+
contract: new ContractProcedure({
|
426
|
+
InputSchema: void 0,
|
427
|
+
OutputSchema: void 0,
|
428
|
+
errorMap: errors
|
429
|
+
})
|
287
430
|
});
|
288
431
|
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
}
|
299
|
-
return chainRouterImplementer(
|
300
|
-
contract,
|
301
|
-
this.zz$b.middlewares
|
302
|
-
);
|
303
|
-
}
|
304
|
-
/**
|
305
|
-
* Create ExtendedMiddleware
|
306
|
-
*/
|
307
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
308
|
-
// solution (maybe): create new generic for .output() method
|
309
|
-
middleware(middleware) {
|
310
|
-
return decorateMiddleware(middleware);
|
432
|
+
handler(handler) {
|
433
|
+
return new DecoratedProcedure({
|
434
|
+
middlewares: this["~orpc"].middlewares,
|
435
|
+
contract: new ContractProcedure({
|
436
|
+
InputSchema: void 0,
|
437
|
+
OutputSchema: void 0,
|
438
|
+
errorMap: void 0
|
439
|
+
}),
|
440
|
+
handler
|
441
|
+
});
|
311
442
|
}
|
312
443
|
prefix(prefix) {
|
313
444
|
return new RouterBuilder({
|
314
|
-
|
445
|
+
middlewares: this["~orpc"].middlewares,
|
315
446
|
prefix
|
316
447
|
});
|
317
448
|
}
|
318
|
-
|
449
|
+
tag(...tags) {
|
319
450
|
return new RouterBuilder({
|
320
|
-
|
451
|
+
middlewares: this["~orpc"].middlewares,
|
321
452
|
tags
|
322
453
|
});
|
323
454
|
}
|
324
|
-
/**
|
325
|
-
* Create DecoratedRouter
|
326
|
-
*/
|
327
455
|
router(router) {
|
328
|
-
return new RouterBuilder(this
|
456
|
+
return new RouterBuilder(this["~orpc"]).router(router);
|
457
|
+
}
|
458
|
+
lazy(loader) {
|
459
|
+
return new RouterBuilder(this["~orpc"]).lazy(loader);
|
460
|
+
}
|
461
|
+
contract(contract) {
|
462
|
+
return createChainableImplementer(contract, this["~orpc"].middlewares);
|
329
463
|
}
|
330
464
|
};
|
331
465
|
|
332
|
-
// src/
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
466
|
+
// src/procedure-utils.ts
|
467
|
+
function call(procedure, input, ...rest) {
|
468
|
+
return createProcedureClient(procedure, ...rest)(input);
|
469
|
+
}
|
470
|
+
|
471
|
+
// src/lazy-utils.ts
|
472
|
+
function createLazyProcedureFormAnyLazy(lazied) {
|
473
|
+
const lazyProcedure = lazy(async () => {
|
474
|
+
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
475
|
+
if (!isProcedure(maybeProcedure)) {
|
476
|
+
throw new Error(`
|
477
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
478
|
+
This should be caught by TypeScript compilation.
|
479
|
+
Please report this issue if this makes you feel uncomfortable.
|
480
|
+
`);
|
346
481
|
}
|
347
|
-
|
348
|
-
|
482
|
+
return { default: maybeProcedure };
|
483
|
+
});
|
484
|
+
return lazyProcedure;
|
349
485
|
}
|
350
486
|
|
351
|
-
// src/router-
|
352
|
-
function
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
}
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
487
|
+
// src/router-client.ts
|
488
|
+
function createRouterClient(router, ...rest) {
|
489
|
+
if (isProcedure(router)) {
|
490
|
+
const caller = createProcedureClient(router, ...rest);
|
491
|
+
return caller;
|
492
|
+
}
|
493
|
+
const procedureCaller = isLazy(router) ? createProcedureClient(createLazyProcedureFormAnyLazy(router), ...rest) : {};
|
494
|
+
const recursive = new Proxy(procedureCaller, {
|
495
|
+
get(target, key) {
|
496
|
+
if (typeof key !== "string") {
|
497
|
+
return Reflect.get(target, key);
|
498
|
+
}
|
499
|
+
const next = getRouterChild(router, key);
|
500
|
+
if (!next) {
|
501
|
+
return Reflect.get(target, key);
|
502
|
+
}
|
503
|
+
const [options] = rest;
|
504
|
+
return createRouterClient(next, {
|
505
|
+
...options,
|
506
|
+
path: [...options?.path ?? [], key]
|
368
507
|
});
|
369
508
|
}
|
370
|
-
}
|
371
|
-
return
|
509
|
+
});
|
510
|
+
return recursive;
|
372
511
|
}
|
373
512
|
|
374
513
|
// src/index.ts
|
375
|
-
|
376
|
-
var os = new Builder();
|
514
|
+
import { configGlobal, fallbackToGlobalConfig, isDefinedError, ORPCError, safe } from "@orpc/contract";
|
515
|
+
var os = new Builder({});
|
377
516
|
export {
|
378
517
|
Builder,
|
518
|
+
DecoratedProcedure,
|
519
|
+
LAZY_LOADER_SYMBOL,
|
520
|
+
ORPCError,
|
379
521
|
Procedure,
|
380
522
|
ProcedureBuilder,
|
381
523
|
ProcedureImplementer,
|
524
|
+
RouterBuilder,
|
382
525
|
RouterImplementer,
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
526
|
+
call,
|
527
|
+
configGlobal,
|
528
|
+
createChainableImplementer,
|
529
|
+
createORPCErrorConstructorMap,
|
530
|
+
createProcedureClient,
|
531
|
+
createRouterClient,
|
532
|
+
decorateLazy,
|
387
533
|
decorateMiddleware,
|
388
|
-
|
534
|
+
deepSetLazyRouterPrefix,
|
535
|
+
fallbackToGlobalConfig,
|
536
|
+
flatLazy,
|
537
|
+
getLazyRouterPrefix,
|
538
|
+
getRouterChild,
|
539
|
+
getRouterContract,
|
540
|
+
isDefinedError,
|
541
|
+
isLazy,
|
389
542
|
isProcedure,
|
543
|
+
lazy,
|
390
544
|
mergeContext,
|
391
545
|
os,
|
392
|
-
|
546
|
+
safe,
|
547
|
+
setRouterContract,
|
548
|
+
unlazy
|
393
549
|
};
|
394
550
|
//# sourceMappingURL=index.js.map
|