@orpc/server 0.0.0-next.e9dc36e → 0.0.0-next.ee0aeaf
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-VARUID7X.js +273 -0
- package/dist/fetch.js +80 -650
- package/dist/index.js +193 -140
- package/dist/src/builder.d.ts +9 -4
- package/dist/src/fetch/handle.d.ts +7 -0
- package/dist/src/fetch/handler.d.ts +3 -0
- package/dist/src/fetch/index.d.ts +4 -0
- package/dist/src/fetch/types.d.ts +28 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/lazy.d.ts +23 -0
- package/dist/src/procedure-caller.d.ts +18 -11
- package/dist/src/procedure-implementer.d.ts +5 -1
- package/dist/src/procedure.d.ts +5 -2
- package/dist/src/router-builder.d.ts +5 -0
- package/dist/src/router-caller.d.ts +7 -4
- package/dist/src/router-implementer.d.ts +7 -3
- package/dist/src/router.d.ts +7 -7
- package/dist/src/types.d.ts +7 -1
- package/package.json +15 -19
- package/dist/chunk-TDFYNRZV.js +0 -190
- package/dist/chunk-TDFYNRZV.js.map +0 -1
- package/dist/fetch.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/src/adapters/fetch.d.ts +0 -42
- package/dist/src/adapters/fetch.d.ts.map +0 -1
- package/dist/src/builder.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/middleware.d.ts.map +0 -1
- package/dist/src/procedure-builder.d.ts.map +0 -1
- package/dist/src/procedure-caller.d.ts.map +0 -1
- package/dist/src/procedure-implementer.d.ts.map +0 -1
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router-builder.d.ts.map +0 -1
- package/dist/src/router-caller.d.ts.map +0 -1
- package/dist/src/router-implementer.d.ts.map +0 -1
- package/dist/src/router.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/adapters/fetch.test.ts +0 -629
- package/src/adapters/fetch.ts +0 -290
- package/src/builder.test.ts +0 -371
- package/src/builder.ts +0 -238
- package/src/index.ts +0 -16
- package/src/middleware.test.ts +0 -260
- package/src/middleware.ts +0 -136
- package/src/procedure-builder.test.ts +0 -223
- package/src/procedure-builder.ts +0 -158
- package/src/procedure-caller.test.ts +0 -171
- package/src/procedure-caller.ts +0 -138
- package/src/procedure-implementer.test.ts +0 -220
- package/src/procedure-implementer.ts +0 -102
- package/src/procedure.test.ts +0 -317
- package/src/procedure.ts +0 -237
- package/src/router-builder.test.ts +0 -106
- package/src/router-builder.ts +0 -122
- package/src/router-caller.test.ts +0 -126
- package/src/router-caller.ts +0 -64
- package/src/router-implementer.test.ts +0 -116
- package/src/router-implementer.ts +0 -113
- package/src/router.test-d.ts +0 -48
- package/src/router.test.ts +0 -142
- package/src/router.ts +0 -91
- package/src/types.test.ts +0 -18
- package/src/types.ts +0 -13
- package/src/utils.test.ts +0 -16
- package/src/utils.ts +0 -16
package/dist/index.js
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
import {
|
2
|
+
LAZY_LOADER_SYMBOL,
|
2
3
|
Procedure,
|
4
|
+
createFlattenLazy,
|
5
|
+
createLazy,
|
3
6
|
createProcedureCaller,
|
7
|
+
decorateLazy,
|
4
8
|
decorateMiddleware,
|
5
9
|
decorateProcedure,
|
10
|
+
isLazy,
|
6
11
|
isProcedure,
|
12
|
+
loadLazy,
|
13
|
+
loadProcedure,
|
7
14
|
mergeContext
|
8
|
-
} from "./chunk-
|
15
|
+
} from "./chunk-VARUID7X.js";
|
9
16
|
|
10
17
|
// src/builder.ts
|
11
18
|
import {
|
@@ -15,9 +22,138 @@ import {
|
|
15
22
|
|
16
23
|
// src/procedure-builder.ts
|
17
24
|
import {
|
18
|
-
DecoratedContractProcedure
|
25
|
+
DecoratedContractProcedure as DecoratedContractProcedure2
|
19
26
|
} from "@orpc/contract";
|
20
27
|
|
28
|
+
// src/router-builder.ts
|
29
|
+
import { DecoratedContractProcedure } 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
|
+
}
|
77
|
+
};
|
78
|
+
function adaptRouter(options) {
|
79
|
+
if (isProcedure(options.routerOrChild)) {
|
80
|
+
return adaptProcedure({
|
81
|
+
...options,
|
82
|
+
procedure: options.routerOrChild
|
83
|
+
});
|
84
|
+
}
|
85
|
+
if (isLazy(options.routerOrChild)) {
|
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;
|
99
|
+
}
|
100
|
+
function adaptLazyRouter(options) {
|
101
|
+
const loader = async () => {
|
102
|
+
const current = (await loadLazy(options.current)).default;
|
103
|
+
return {
|
104
|
+
default: adaptRouter({
|
105
|
+
...options,
|
106
|
+
routerOrChild: current
|
107
|
+
})
|
108
|
+
};
|
109
|
+
};
|
110
|
+
let lazyRouterPrefix = options.prefix;
|
111
|
+
if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") {
|
112
|
+
lazyRouterPrefix = `${options.current[LAZY_ROUTER_PREFIX_SYMBOL]}${lazyRouterPrefix ?? ""}`;
|
113
|
+
}
|
114
|
+
const decoratedLazy = Object.assign(decorateLazy(createLazy(loader)), {
|
115
|
+
[LAZY_ROUTER_PREFIX_SYMBOL]: lazyRouterPrefix
|
116
|
+
});
|
117
|
+
const recursive = new Proxy(decoratedLazy, {
|
118
|
+
get(target, key) {
|
119
|
+
if (typeof key !== "string") {
|
120
|
+
return Reflect.get(target, key);
|
121
|
+
}
|
122
|
+
return adaptLazyRouter({
|
123
|
+
...options,
|
124
|
+
current: createLazy(async () => {
|
125
|
+
const current = (await loadLazy(options.current)).default;
|
126
|
+
return { default: current[key] };
|
127
|
+
})
|
128
|
+
});
|
129
|
+
}
|
130
|
+
});
|
131
|
+
return recursive;
|
132
|
+
}
|
133
|
+
function adaptProcedure(options) {
|
134
|
+
const builderMiddlewares = options.middlewares ?? [];
|
135
|
+
const procedureMiddlewares = options.procedure.zz$p.middlewares ?? [];
|
136
|
+
const middlewares = [
|
137
|
+
...builderMiddlewares,
|
138
|
+
...procedureMiddlewares.filter(
|
139
|
+
(item) => !builderMiddlewares.includes(item)
|
140
|
+
)
|
141
|
+
];
|
142
|
+
let contract = DecoratedContractProcedure.decorate(
|
143
|
+
options.procedure.zz$p.contract
|
144
|
+
).pushTag(...options.tags ?? []);
|
145
|
+
if (options.prefix) {
|
146
|
+
contract = contract.prefix(options.prefix);
|
147
|
+
}
|
148
|
+
return decorateProcedure({
|
149
|
+
zz$p: {
|
150
|
+
...options.procedure.zz$p,
|
151
|
+
contract,
|
152
|
+
middlewares
|
153
|
+
}
|
154
|
+
});
|
155
|
+
}
|
156
|
+
|
21
157
|
// src/procedure-implementer.ts
|
22
158
|
var ProcedureImplementer = class _ProcedureImplementer {
|
23
159
|
constructor(zz$pi) {
|
@@ -39,6 +175,9 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
39
175
|
}
|
40
176
|
});
|
41
177
|
}
|
178
|
+
lazy(loader) {
|
179
|
+
return new RouterBuilder(this.zz$pi).lazy(loader);
|
180
|
+
}
|
42
181
|
};
|
43
182
|
|
44
183
|
// src/procedure-builder.ts
|
@@ -52,7 +191,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
52
191
|
route(opts) {
|
53
192
|
return new _ProcedureBuilder({
|
54
193
|
...this.zz$pb,
|
55
|
-
contract:
|
194
|
+
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route(
|
56
195
|
opts
|
57
196
|
)
|
58
197
|
});
|
@@ -60,7 +199,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
60
199
|
input(schema, example) {
|
61
200
|
return new _ProcedureBuilder({
|
62
201
|
...this.zz$pb,
|
63
|
-
contract:
|
202
|
+
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input(
|
64
203
|
schema,
|
65
204
|
example
|
66
205
|
)
|
@@ -69,7 +208,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
69
208
|
output(schema, example) {
|
70
209
|
return new _ProcedureBuilder({
|
71
210
|
...this.zz$pb,
|
72
|
-
contract:
|
211
|
+
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output(
|
73
212
|
schema,
|
74
213
|
example
|
75
214
|
)
|
@@ -101,75 +240,24 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
101
240
|
}
|
102
241
|
};
|
103
242
|
|
104
|
-
// src/router-builder.ts
|
105
|
-
import { DecoratedContractProcedure as DecoratedContractProcedure2 } from "@orpc/contract";
|
106
|
-
var RouterBuilder = class _RouterBuilder {
|
107
|
-
constructor(zz$rb) {
|
108
|
-
this.zz$rb = zz$rb;
|
109
|
-
}
|
110
|
-
prefix(prefix) {
|
111
|
-
return new _RouterBuilder({
|
112
|
-
...this.zz$rb,
|
113
|
-
prefix: `${this.zz$rb.prefix ?? ""}${prefix}`
|
114
|
-
});
|
115
|
-
}
|
116
|
-
tags(...tags) {
|
117
|
-
if (!tags.length)
|
118
|
-
return this;
|
119
|
-
return new _RouterBuilder({
|
120
|
-
...this.zz$rb,
|
121
|
-
tags: [...this.zz$rb.tags ?? [], ...tags]
|
122
|
-
});
|
123
|
-
}
|
124
|
-
use(middleware, mapInput) {
|
125
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
126
|
-
return new _RouterBuilder({
|
127
|
-
...this.zz$rb,
|
128
|
-
middlewares: [...this.zz$rb.middlewares || [], middleware_]
|
129
|
-
});
|
130
|
-
}
|
131
|
-
router(router) {
|
132
|
-
const handled = {};
|
133
|
-
for (const key in router) {
|
134
|
-
const item = router[key];
|
135
|
-
if (isProcedure(item)) {
|
136
|
-
const builderMiddlewares = this.zz$rb.middlewares ?? [];
|
137
|
-
const itemMiddlewares = item.zz$p.middlewares ?? [];
|
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;
|
159
|
-
}
|
160
|
-
};
|
161
|
-
|
162
243
|
// src/router-implementer.ts
|
163
|
-
import {
|
164
|
-
|
165
|
-
} from "@orpc/contract";
|
244
|
+
import { isContractProcedure } from "@orpc/contract";
|
245
|
+
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
166
246
|
var RouterImplementer = class {
|
167
247
|
constructor(zz$ri) {
|
168
248
|
this.zz$ri = zz$ri;
|
169
249
|
}
|
170
250
|
router(router) {
|
171
|
-
|
172
|
-
|
251
|
+
return Object.assign(new RouterBuilder({}).router(router), {
|
252
|
+
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
253
|
+
});
|
254
|
+
}
|
255
|
+
lazy(loader) {
|
256
|
+
const lazy = createLazy(loader);
|
257
|
+
const decorated = decorateLazy(lazy);
|
258
|
+
return Object.assign(decorated, {
|
259
|
+
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
260
|
+
});
|
173
261
|
}
|
174
262
|
};
|
175
263
|
function chainRouterImplementer(contract, middlewares) {
|
@@ -188,37 +276,6 @@ function chainRouterImplementer(contract, middlewares) {
|
|
188
276
|
const implementer = new RouterImplementer({ contract });
|
189
277
|
return Object.assign(implementer, result);
|
190
278
|
}
|
191
|
-
function assertRouterImplementation(contract, router, path = []) {
|
192
|
-
for (const key in contract) {
|
193
|
-
const currentPath = [...path, key];
|
194
|
-
const contractItem = contract[key];
|
195
|
-
const routerItem = router[key];
|
196
|
-
if (!routerItem) {
|
197
|
-
throw new Error(
|
198
|
-
`Missing implementation for procedure at [${currentPath.join(".")}]`
|
199
|
-
);
|
200
|
-
}
|
201
|
-
if (isContractProcedure(contractItem)) {
|
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
|
-
);
|
212
|
-
}
|
213
|
-
} else {
|
214
|
-
assertRouterImplementation(
|
215
|
-
contractItem,
|
216
|
-
routerItem,
|
217
|
-
currentPath
|
218
|
-
);
|
219
|
-
}
|
220
|
-
}
|
221
|
-
}
|
222
279
|
|
223
280
|
// src/builder.ts
|
224
281
|
var Builder = class _Builder {
|
@@ -241,11 +298,11 @@ var Builder = class _Builder {
|
|
241
298
|
/**
|
242
299
|
* Convert to ContractProcedureBuilder
|
243
300
|
*/
|
244
|
-
route(
|
301
|
+
route(route) {
|
245
302
|
return new ProcedureBuilder({
|
246
303
|
middlewares: this.zz$b.middlewares,
|
247
304
|
contract: new ContractProcedure({
|
248
|
-
|
305
|
+
route,
|
249
306
|
InputSchema: void 0,
|
250
307
|
OutputSchema: void 0
|
251
308
|
})
|
@@ -327,48 +384,36 @@ var Builder = class _Builder {
|
|
327
384
|
router(router) {
|
328
385
|
return new RouterBuilder(this.zz$b).router(router);
|
329
386
|
}
|
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
|
-
}
|
387
|
+
lazy(loader) {
|
388
|
+
return new RouterBuilder(this.zz$b).lazy(loader);
|
347
389
|
}
|
348
|
-
|
349
|
-
}
|
390
|
+
};
|
350
391
|
|
351
392
|
// src/router-caller.ts
|
352
393
|
function createRouterCaller(options) {
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
394
|
+
return createRouterCallerInternal(options);
|
395
|
+
}
|
396
|
+
function createRouterCallerInternal(options) {
|
397
|
+
const procedureCaller = isLazy(options.router) || isProcedure(options.router) ? createProcedureCaller({
|
398
|
+
...options,
|
399
|
+
procedure: options.router,
|
400
|
+
context: options.context,
|
401
|
+
path: options.basePath
|
402
|
+
}) : {};
|
403
|
+
const recursive = new Proxy(procedureCaller, {
|
404
|
+
get(target, key) {
|
405
|
+
if (typeof key !== "string") {
|
406
|
+
return Reflect.get(target, key);
|
407
|
+
}
|
408
|
+
const next = options.router[key];
|
409
|
+
return createRouterCallerInternal({
|
410
|
+
...options,
|
411
|
+
router: next,
|
412
|
+
basePath: [...options.basePath ?? [], key]
|
368
413
|
});
|
369
414
|
}
|
370
|
-
}
|
371
|
-
return
|
415
|
+
});
|
416
|
+
return recursive;
|
372
417
|
}
|
373
418
|
|
374
419
|
// src/index.ts
|
@@ -376,19 +421,27 @@ export * from "@orpc/shared/error";
|
|
376
421
|
var os = new Builder();
|
377
422
|
export {
|
378
423
|
Builder,
|
424
|
+
LAZY_LOADER_SYMBOL,
|
425
|
+
LAZY_ROUTER_PREFIX_SYMBOL,
|
379
426
|
Procedure,
|
380
427
|
ProcedureBuilder,
|
381
428
|
ProcedureImplementer,
|
429
|
+
ROUTER_CONTRACT_SYMBOL,
|
430
|
+
RouterBuilder,
|
382
431
|
RouterImplementer,
|
383
|
-
assertRouterImplementation,
|
384
432
|
chainRouterImplementer,
|
433
|
+
createFlattenLazy,
|
434
|
+
createLazy,
|
385
435
|
createProcedureCaller,
|
386
436
|
createRouterCaller,
|
437
|
+
decorateLazy,
|
387
438
|
decorateMiddleware,
|
388
439
|
decorateProcedure,
|
440
|
+
isLazy,
|
389
441
|
isProcedure,
|
442
|
+
loadLazy,
|
443
|
+
loadProcedure,
|
390
444
|
mergeContext,
|
391
|
-
os
|
392
|
-
toContractRouter
|
445
|
+
os
|
393
446
|
};
|
394
447
|
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE, ContractRouter, HTTPPath, RouteOptions, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
1
2
|
import type { IsEqual } from '@orpc/shared';
|
3
|
+
import type { DecoratedLazy } from './lazy';
|
4
|
+
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
|
2
5
|
import type { HandledRouter, Router } from './router';
|
3
6
|
import type { Context, MergeContext } from './types';
|
4
|
-
import { ContractProcedure
|
7
|
+
import { ContractProcedure } from '@orpc/contract';
|
5
8
|
import { type DecoratedMiddleware, type MapInputMiddleware, type Middleware } from './middleware';
|
6
|
-
import { type DecoratedProcedure, type ProcedureFunc } from './procedure';
|
7
9
|
import { ProcedureBuilder } from './procedure-builder';
|
8
10
|
import { ProcedureImplementer } from './procedure-implementer';
|
9
11
|
import { RouterBuilder } from './router-builder';
|
@@ -24,7 +26,7 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
24
26
|
/**
|
25
27
|
* Convert to ContractProcedureBuilder
|
26
28
|
*/
|
27
|
-
route(
|
29
|
+
route(route: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
28
30
|
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
29
31
|
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
30
32
|
/**
|
@@ -34,7 +36,7 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
34
36
|
/**
|
35
37
|
* Convert to ProcedureImplementer | RouterBuilder
|
36
38
|
*/
|
37
|
-
contract<UContract extends
|
39
|
+
contract<UContract extends ANY_CONTRACT_PROCEDURE | ContractRouter>(contract: UContract): UContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : UContract extends ContractRouter ? ChainedRouterImplementer<TContext, UContract, TExtraContext> : never;
|
38
40
|
/**
|
39
41
|
* Create ExtendedMiddleware
|
40
42
|
*/
|
@@ -45,5 +47,8 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
45
47
|
* Create DecoratedRouter
|
46
48
|
*/
|
47
49
|
router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>;
|
50
|
+
lazy<U extends Router<TContext> | Procedure<TContext, any, any, any, any>>(loader: () => Promise<{
|
51
|
+
default: U;
|
52
|
+
}>): DecoratedLazy<U>;
|
48
53
|
}
|
49
54
|
//# sourceMappingURL=builder.d.ts.map
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type { Router } from '../router';
|
2
|
+
import type { FetchHandler, FetchHandlerOptions } from './types';
|
3
|
+
export type HandleFetchRequestOptions<TRouter extends Router<any>> = FetchHandlerOptions<TRouter> & {
|
4
|
+
handlers: readonly [FetchHandler, ...FetchHandler[]];
|
5
|
+
};
|
6
|
+
export declare function handleFetchRequest<TRouter extends Router<any>>(options: HandleFetchRequestOptions<TRouter>): Promise<Response>;
|
7
|
+
//# sourceMappingURL=handle.d.ts.map
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
2
|
+
import type { Router } from '../router';
|
3
|
+
import type { CallerOptions } from '../types';
|
4
|
+
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
5
|
+
/**
|
6
|
+
* The `router` used for handling the request and routing,
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
router: TRouter;
|
10
|
+
/**
|
11
|
+
* The request need to be handled.
|
12
|
+
*/
|
13
|
+
request: Request;
|
14
|
+
/**
|
15
|
+
* Remove the prefix from the request path.
|
16
|
+
*
|
17
|
+
* @example /orpc
|
18
|
+
* @example /api
|
19
|
+
*/
|
20
|
+
prefix?: string;
|
21
|
+
} & PartialOnUndefinedDeep<{
|
22
|
+
/**
|
23
|
+
* The context used to handle the request.
|
24
|
+
*/
|
25
|
+
context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
|
26
|
+
}> & CallerOptions & Hooks<Request, Response, TRouter extends Router<infer UContext> ? UContext : never, CallerOptions>;
|
27
|
+
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
import { Builder } from './builder';
|
2
2
|
export * from './builder';
|
3
|
+
export * from './lazy';
|
3
4
|
export * from './middleware';
|
4
5
|
export * from './procedure';
|
5
6
|
export * from './procedure-builder';
|
6
7
|
export * from './procedure-caller';
|
7
8
|
export * from './procedure-implementer';
|
8
9
|
export * from './router';
|
10
|
+
export * from './router-builder';
|
9
11
|
export * from './router-caller';
|
10
12
|
export * from './router-implementer';
|
11
13
|
export * from './types';
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { Procedure } from './procedure';
|
2
|
+
import type { ProcedureCaller } from './procedure-caller';
|
3
|
+
export declare const LAZY_LOADER_SYMBOL: unique symbol;
|
4
|
+
export interface Lazy<T> {
|
5
|
+
[LAZY_LOADER_SYMBOL]: () => Promise<{
|
6
|
+
default: T;
|
7
|
+
}>;
|
8
|
+
}
|
9
|
+
export type ANY_LAZY = Lazy<any>;
|
10
|
+
export declare function createLazy<T>(loader: () => Promise<{
|
11
|
+
default: T;
|
12
|
+
}>): Lazy<T>;
|
13
|
+
export declare function loadLazy<T>(lazy: Lazy<T>): Promise<{
|
14
|
+
default: T;
|
15
|
+
}>;
|
16
|
+
export declare function isLazy(item: unknown): item is ANY_LAZY;
|
17
|
+
export type FlattenLazy<T> = T extends Lazy<infer U> ? FlattenLazy<U> : Lazy<T>;
|
18
|
+
export declare function createFlattenLazy<T>(lazy: Lazy<T>): FlattenLazy<T>;
|
19
|
+
export type DecoratedLazy<T> = T extends Lazy<infer U> ? DecoratedLazy<U> : (T extends Procedure<infer UContext, any, any, any, any> ? Lazy<T> & (undefined extends UContext ? ProcedureCaller<T> : unknown) : T extends Record<any, any> ? {
|
20
|
+
[K in keyof T]: DecoratedLazy<T[K]>;
|
21
|
+
} /** Notice: this still a lazy, but type not work when I & Lazy<T>, maybe it's a bug, should improve */ : Lazy<T>);
|
22
|
+
export declare function decorateLazy<T>(lazy: Lazy<T>): DecoratedLazy<T>;
|
23
|
+
//# sourceMappingURL=lazy.d.ts.map
|
@@ -1,19 +1,26 @@
|
|
1
1
|
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type {
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
*/
|
9
|
-
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> ? UContext : never>;
|
2
|
+
import type { Hooks, PartialOnUndefinedDeep, Value } from '@orpc/shared';
|
3
|
+
import type { Lazy } from './lazy';
|
4
|
+
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Procedure } from './procedure';
|
5
|
+
import type { Caller } from './types';
|
6
|
+
export type CreateProcedureCallerOptions<T extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = T extends Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<infer UContext, any, any, infer UOutputSchema, infer UFuncOutput>> ? {
|
7
|
+
procedure: T;
|
10
8
|
/**
|
11
9
|
* This is helpful for logging and analytics.
|
12
10
|
*
|
13
11
|
* @internal
|
14
12
|
*/
|
15
13
|
path?: string[];
|
16
|
-
}
|
17
|
-
|
18
|
-
|
14
|
+
} & PartialOnUndefinedDeep<{
|
15
|
+
/**
|
16
|
+
* The context used when calling the procedure.
|
17
|
+
*/
|
18
|
+
context: Value<UContext>;
|
19
|
+
}> & Hooks<unknown, SchemaOutput<UOutputSchema, UFuncOutput>, UContext, {
|
20
|
+
path: string[];
|
21
|
+
procedure: ANY_PROCEDURE;
|
22
|
+
}> : never;
|
23
|
+
export type ProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> = TProcedure extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput> | Lazy<Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>> ? Caller<SchemaInput<UInputSchema>, SchemaOutput<UOutputSchema, UFuncOutput>> : never;
|
24
|
+
export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>;
|
25
|
+
export declare function loadProcedure(procedure: ANY_PROCEDURE | ANY_LAZY_PROCEDURE): Promise<ANY_PROCEDURE>;
|
19
26
|
//# sourceMappingURL=procedure-caller.d.ts.map
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
+
import type { DecoratedLazy } from './lazy';
|
3
|
+
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
|
2
4
|
import type { Context, MergeContext } from './types';
|
3
5
|
import { type MapInputMiddleware, type Middleware } from './middleware';
|
4
|
-
import { type DecoratedProcedure, type ProcedureFunc } from './procedure';
|
5
6
|
export declare class ProcedureImplementer<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
6
7
|
zz$pi: {
|
7
8
|
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
@@ -14,5 +15,8 @@ export declare class ProcedureImplementer<TContext extends Context, TExtraContex
|
|
14
15
|
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, SchemaOutput<TInputSchema>, SchemaInput<TOutputSchema>>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
15
16
|
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, SchemaInput<TOutputSchema>>, mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>): ProcedureImplementer<TContext, MergeContext<TExtraContext, UExtraContext>, TInputSchema, TOutputSchema>;
|
16
17
|
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
18
|
+
lazy<U extends Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, SchemaOutput<TOutputSchema>>>(loader: () => Promise<{
|
19
|
+
default: U;
|
20
|
+
}>): DecoratedLazy<U>;
|
17
21
|
}
|
18
22
|
//# sourceMappingURL=procedure-implementer.d.ts.map
|
package/dist/src/procedure.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Promisable } from '@orpc/shared';
|
2
|
+
import type { Lazy } from './lazy';
|
2
3
|
import type { ProcedureCaller } from './procedure-caller';
|
3
4
|
import type { Context, MergeContext, Meta } from './types';
|
4
5
|
import { type ContractProcedure, type HTTPPath, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
@@ -15,6 +16,9 @@ export declare class Procedure<TContext extends Context, TExtraContext extends C
|
|
15
16
|
func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
16
17
|
});
|
17
18
|
}
|
19
|
+
export type ANY_PROCEDURE = Procedure<any, any, any, any, any>;
|
20
|
+
export type WELL_DEFINED_PROCEDURE = Procedure<Context, Context, Schema, Schema, unknown>;
|
21
|
+
export type ANY_LAZY_PROCEDURE = Lazy<ANY_PROCEDURE>;
|
18
22
|
export type DecoratedProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>> = Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput> & {
|
19
23
|
prefix: (prefix: HTTPPath) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
20
24
|
route: (opts: RouteOptions) => DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
@@ -24,6 +28,5 @@ export interface ProcedureFunc<TContext extends Context, TExtraContext extends C
|
|
24
28
|
(input: SchemaOutput<TInputSchema>, context: MergeContext<TContext, TExtraContext>, meta: Meta): Promisable<SchemaInput<TOutputSchema, TOutput>>;
|
25
29
|
}
|
26
30
|
export declare function decorateProcedure<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema, TFuncOutput extends SchemaOutput<TOutputSchema>>(procedure: Procedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, TFuncOutput>;
|
27
|
-
export
|
28
|
-
export declare function isProcedure(item: unknown): item is WELL_DEFINED_PROCEDURE;
|
31
|
+
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
29
32
|
//# sourceMappingURL=procedure.d.ts.map
|
@@ -1,7 +1,9 @@
|
|
1
|
+
import type { DecoratedLazy } from './lazy';
|
1
2
|
import type { HandledRouter, Router } from './router';
|
2
3
|
import type { Context, MergeContext } from './types';
|
3
4
|
import { type HTTPPath } from '@orpc/contract';
|
4
5
|
import { type MapInputMiddleware, type Middleware } from './middleware';
|
6
|
+
export declare const LAZY_ROUTER_PREFIX_SYMBOL: unique symbol;
|
5
7
|
export declare class RouterBuilder<TContext extends Context, TExtraContext extends Context> {
|
6
8
|
zz$rb: {
|
7
9
|
prefix?: HTTPPath;
|
@@ -18,5 +20,8 @@ export declare class RouterBuilder<TContext extends Context, TExtraContext exten
|
|
18
20
|
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, unknown, unknown>): RouterBuilder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
19
21
|
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, unknown>, mapInput: MapInputMiddleware<unknown, UMappedInput>): RouterBuilder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
20
22
|
router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>;
|
23
|
+
lazy<U extends Router<TContext>>(loader: () => Promise<{
|
24
|
+
default: U;
|
25
|
+
}>): DecoratedLazy<U>;
|
21
26
|
}
|
22
27
|
//# sourceMappingURL=router-builder.d.ts.map
|