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