@orpc/server 0.11.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{chunk-CVLK2PBB.js → chunk-FL4ZAGNE.js} +134 -56
- package/dist/fetch.js +76 -649
- package/dist/index.js +191 -116
- package/dist/src/builder.d.ts +6 -1
- 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/{adapters/fetch.d.ts → fetch/types.d.ts} +9 -15
- package/dist/src/index.d.ts +3 -0
- package/dist/src/lazy.d.ts +23 -0
- package/dist/src/middleware.d.ts +1 -0
- package/dist/src/procedure-builder.d.ts +1 -0
- package/dist/src/procedure-caller.d.ts +7 -5
- package/dist/src/procedure-implementer.d.ts +6 -1
- package/dist/src/procedure.d.ts +6 -2
- package/dist/src/router-builder.d.ts +6 -0
- package/dist/src/router-caller.d.ts +3 -2
- package/dist/src/router-implementer.d.ts +8 -3
- package/dist/src/router.d.ts +5 -3
- package/dist/src/types.d.ts +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/package.json +10 -9
package/dist/index.js
CHANGED
@@ -1,11 +1,17 @@
|
|
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,
|
7
13
|
mergeContext
|
8
|
-
} from "./chunk-
|
14
|
+
} from "./chunk-FL4ZAGNE.js";
|
9
15
|
|
10
16
|
// src/builder.ts
|
11
17
|
import {
|
@@ -15,9 +21,138 @@ import {
|
|
15
21
|
|
16
22
|
// src/procedure-builder.ts
|
17
23
|
import {
|
18
|
-
DecoratedContractProcedure
|
24
|
+
DecoratedContractProcedure as DecoratedContractProcedure2
|
19
25
|
} from "@orpc/contract";
|
20
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
|
+
}
|
76
|
+
};
|
77
|
+
function adaptRouter(options) {
|
78
|
+
if (isProcedure(options.routerOrChild)) {
|
79
|
+
return adaptProcedure({
|
80
|
+
...options,
|
81
|
+
procedure: options.routerOrChild
|
82
|
+
});
|
83
|
+
}
|
84
|
+
if (isLazy(options.routerOrChild)) {
|
85
|
+
return adaptLazyRouter({
|
86
|
+
...options,
|
87
|
+
current: options.routerOrChild
|
88
|
+
});
|
89
|
+
}
|
90
|
+
const handled = {};
|
91
|
+
for (const key in options.routerOrChild) {
|
92
|
+
handled[key] = adaptRouter({
|
93
|
+
...options,
|
94
|
+
routerOrChild: options.routerOrChild[key]
|
95
|
+
});
|
96
|
+
}
|
97
|
+
return handled;
|
98
|
+
}
|
99
|
+
function adaptLazyRouter(options) {
|
100
|
+
const loader = async () => {
|
101
|
+
const current = (await loadLazy(options.current)).default;
|
102
|
+
return {
|
103
|
+
default: adaptRouter({
|
104
|
+
...options,
|
105
|
+
routerOrChild: current
|
106
|
+
})
|
107
|
+
};
|
108
|
+
};
|
109
|
+
let lazyRouterPrefix = options.prefix;
|
110
|
+
if (LAZY_ROUTER_PREFIX_SYMBOL in options.current && typeof options.current[LAZY_ROUTER_PREFIX_SYMBOL] === "string") {
|
111
|
+
lazyRouterPrefix = lazyRouterPrefix ? prefixHTTPPath(options.current[LAZY_ROUTER_PREFIX_SYMBOL], lazyRouterPrefix) : options.current[LAZY_ROUTER_PREFIX_SYMBOL];
|
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({
|
122
|
+
...options,
|
123
|
+
current: createLazy(async () => {
|
124
|
+
const current = (await loadLazy(options.current)).default;
|
125
|
+
return { default: current[key] };
|
126
|
+
})
|
127
|
+
});
|
128
|
+
}
|
129
|
+
});
|
130
|
+
return recursive;
|
131
|
+
}
|
132
|
+
function adaptProcedure(options) {
|
133
|
+
const builderMiddlewares = options.middlewares ?? [];
|
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
|
+
});
|
154
|
+
}
|
155
|
+
|
21
156
|
// src/procedure-implementer.ts
|
22
157
|
var ProcedureImplementer = class _ProcedureImplementer {
|
23
158
|
constructor(zz$pi) {
|
@@ -39,6 +174,9 @@ var ProcedureImplementer = class _ProcedureImplementer {
|
|
39
174
|
}
|
40
175
|
});
|
41
176
|
}
|
177
|
+
lazy(loader) {
|
178
|
+
return new RouterBuilder(this.zz$pi).lazy(loader);
|
179
|
+
}
|
42
180
|
};
|
43
181
|
|
44
182
|
// src/procedure-builder.ts
|
@@ -52,7 +190,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
52
190
|
route(opts) {
|
53
191
|
return new _ProcedureBuilder({
|
54
192
|
...this.zz$pb,
|
55
|
-
contract:
|
193
|
+
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route(
|
56
194
|
opts
|
57
195
|
)
|
58
196
|
});
|
@@ -60,7 +198,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
60
198
|
input(schema, example) {
|
61
199
|
return new _ProcedureBuilder({
|
62
200
|
...this.zz$pb,
|
63
|
-
contract:
|
201
|
+
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input(
|
64
202
|
schema,
|
65
203
|
example
|
66
204
|
)
|
@@ -69,7 +207,7 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
69
207
|
output(schema, example) {
|
70
208
|
return new _ProcedureBuilder({
|
71
209
|
...this.zz$pb,
|
72
|
-
contract:
|
210
|
+
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output(
|
73
211
|
schema,
|
74
212
|
example
|
75
213
|
)
|
@@ -101,75 +239,24 @@ var ProcedureBuilder = class _ProcedureBuilder {
|
|
101
239
|
}
|
102
240
|
};
|
103
241
|
|
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
242
|
// src/router-implementer.ts
|
163
|
-
import {
|
164
|
-
|
165
|
-
} from "@orpc/contract";
|
243
|
+
import { isContractProcedure } from "@orpc/contract";
|
244
|
+
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
166
245
|
var RouterImplementer = class {
|
167
246
|
constructor(zz$ri) {
|
168
247
|
this.zz$ri = zz$ri;
|
169
248
|
}
|
170
249
|
router(router) {
|
171
|
-
|
172
|
-
|
250
|
+
return Object.assign(new RouterBuilder({}).router(router), {
|
251
|
+
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
252
|
+
});
|
253
|
+
}
|
254
|
+
lazy(loader) {
|
255
|
+
const lazy = createLazy(loader);
|
256
|
+
const decorated = decorateLazy(lazy);
|
257
|
+
return Object.assign(decorated, {
|
258
|
+
[ROUTER_CONTRACT_SYMBOL]: this.zz$ri.contract
|
259
|
+
});
|
173
260
|
}
|
174
261
|
};
|
175
262
|
function chainRouterImplementer(contract, middlewares) {
|
@@ -188,37 +275,6 @@ function chainRouterImplementer(contract, middlewares) {
|
|
188
275
|
const implementer = new RouterImplementer({ contract });
|
189
276
|
return Object.assign(implementer, result);
|
190
277
|
}
|
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
278
|
|
223
279
|
// src/builder.ts
|
224
280
|
var Builder = class _Builder {
|
@@ -327,6 +383,9 @@ var Builder = class _Builder {
|
|
327
383
|
router(router) {
|
328
384
|
return new RouterBuilder(this.zz$b).router(router);
|
329
385
|
}
|
386
|
+
lazy(loader) {
|
387
|
+
return new RouterBuilder(this.zz$b).lazy(loader);
|
388
|
+
}
|
330
389
|
};
|
331
390
|
|
332
391
|
// src/router.ts
|
@@ -350,25 +409,32 @@ function toContractRouter(router) {
|
|
350
409
|
|
351
410
|
// src/router-caller.ts
|
352
411
|
function createRouterCaller(options) {
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
412
|
+
return createRouterCallerInternal({
|
413
|
+
current: options.router,
|
414
|
+
context: options.context,
|
415
|
+
path: options.basePath ?? []
|
416
|
+
});
|
417
|
+
}
|
418
|
+
function createRouterCallerInternal(options) {
|
419
|
+
const procedureCaller = isLazy(options.current) || isProcedure(options.current) ? createProcedureCaller({
|
420
|
+
procedure: options.current,
|
421
|
+
context: options.context,
|
422
|
+
path: options.path
|
423
|
+
}) : {};
|
424
|
+
const recursive = new Proxy(procedureCaller, {
|
425
|
+
get(target, key) {
|
426
|
+
if (typeof key !== "string") {
|
427
|
+
return Reflect.get(target, key);
|
428
|
+
}
|
429
|
+
const next = options.current[key];
|
430
|
+
return createRouterCallerInternal({
|
431
|
+
current: next,
|
366
432
|
context: options.context,
|
367
|
-
|
433
|
+
path: [...options.path, key]
|
368
434
|
});
|
369
435
|
}
|
370
|
-
}
|
371
|
-
return
|
436
|
+
});
|
437
|
+
return recursive;
|
372
438
|
}
|
373
439
|
|
374
440
|
// src/index.ts
|
@@ -376,18 +442,27 @@ export * from "@orpc/shared/error";
|
|
376
442
|
var os = new Builder();
|
377
443
|
export {
|
378
444
|
Builder,
|
445
|
+
LAZY_LOADER_SYMBOL,
|
446
|
+
LAZY_ROUTER_PREFIX_SYMBOL,
|
379
447
|
Procedure,
|
380
448
|
ProcedureBuilder,
|
381
449
|
ProcedureImplementer,
|
450
|
+
ROUTER_CONTRACT_SYMBOL,
|
451
|
+
RouterBuilder,
|
382
452
|
RouterImplementer,
|
383
|
-
assertRouterImplementation,
|
384
453
|
chainRouterImplementer,
|
454
|
+
createFlattenLazy,
|
455
|
+
createLazy,
|
385
456
|
createProcedureCaller,
|
386
457
|
createRouterCaller,
|
458
|
+
decorateLazy,
|
387
459
|
decorateMiddleware,
|
388
460
|
decorateProcedure,
|
461
|
+
isLazy,
|
389
462
|
isProcedure,
|
463
|
+
loadLazy,
|
390
464
|
mergeContext,
|
391
465
|
os,
|
392
466
|
toContractRouter
|
393
467
|
};
|
468
|
+
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import type { IsEqual } from '@orpc/shared';
|
2
|
+
import type { DecoratedLazy } from './lazy';
|
3
|
+
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
|
2
4
|
import type { HandledRouter, Router } from './router';
|
3
5
|
import type { Context, MergeContext } from './types';
|
4
6
|
import { ContractProcedure, type ContractRouter, type HTTPPath, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
5
7
|
import { type DecoratedMiddleware, type MapInputMiddleware, type Middleware } from './middleware';
|
6
|
-
import { type DecoratedProcedure, type ProcedureFunc } from './procedure';
|
7
8
|
import { ProcedureBuilder } from './procedure-builder';
|
8
9
|
import { ProcedureImplementer } from './procedure-implementer';
|
9
10
|
import { RouterBuilder } from './router-builder';
|
@@ -45,4 +46,8 @@ export declare class Builder<TContext extends Context, TExtraContext extends Con
|
|
45
46
|
* Create DecoratedRouter
|
46
47
|
*/
|
47
48
|
router<URouter extends Router<TContext>>(router: URouter): HandledRouter<URouter>;
|
49
|
+
lazy<U extends Router<TContext> | Procedure<TContext, any, any, any, any>>(loader: () => Promise<{
|
50
|
+
default: U;
|
51
|
+
}>): DecoratedLazy<U>;
|
48
52
|
}
|
53
|
+
//# 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
|
@@ -4,21 +4,12 @@ export interface FetchHandlerHooks {
|
|
4
4
|
next: () => Promise<Response>;
|
5
5
|
response: (response: Response) => Response;
|
6
6
|
}
|
7
|
-
export
|
8
|
-
router: TRouter;
|
9
|
-
/**
|
10
|
-
* Hooks for executing logics on lifecycle events.
|
11
|
-
*/
|
12
|
-
hooks?: (context: TRouter extends Router<infer UContext> ? UContext : never, hooks: FetchHandlerHooks) => Promisable<Response>;
|
7
|
+
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
13
8
|
/**
|
14
|
-
*
|
9
|
+
* The `router` used for handling the request and routing,
|
15
10
|
*
|
16
|
-
* @default false
|
17
11
|
*/
|
18
|
-
|
19
|
-
}
|
20
|
-
export declare function createFetchHandler<TRouter extends Router<any>>(options: CreateFetchHandlerOptions<TRouter>): FetchHandler<TRouter>;
|
21
|
-
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
12
|
+
router: TRouter;
|
22
13
|
/**
|
23
14
|
* The request need to be handled.
|
24
15
|
*/
|
@@ -30,12 +21,15 @@ export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
|
30
21
|
* @example /api
|
31
22
|
*/
|
32
23
|
prefix?: string;
|
24
|
+
/**
|
25
|
+
* Hooks for executing logics on lifecycle events.
|
26
|
+
*/
|
27
|
+
hooks?: (context: TRouter extends Router<infer UContext> ? UContext : never, hooks: FetchHandlerHooks) => Promisable<Response>;
|
33
28
|
} & PartialOnUndefinedDeep<{
|
34
29
|
/**
|
35
30
|
* The context used to handle the request.
|
36
31
|
*/
|
37
32
|
context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
|
38
33
|
}>;
|
39
|
-
export
|
40
|
-
|
41
|
-
}
|
34
|
+
export type FetchHandler = <TRouter extends Router<any>>(options: FetchHandlerOptions<TRouter>) => Promise<Response | undefined>;
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/src/index.d.ts
CHANGED
@@ -1,14 +1,17 @@
|
|
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';
|
12
14
|
export * from './utils';
|
13
15
|
export * from '@orpc/shared/error';
|
14
16
|
export declare const os: Builder<Record<string, unknown> | undefined, undefined>;
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -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
|
package/dist/src/middleware.d.ts
CHANGED
@@ -23,3 +23,4 @@ export interface DecoratedMiddleware<TContext extends Context, TExtraContext ext
|
|
23
23
|
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
24
24
|
}
|
25
25
|
export declare function decorateMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput>(middleware: Middleware<TContext, TExtraContext, TInput, TOutput>): DecoratedMiddleware<TContext, TExtraContext, TInput, TOutput>;
|
26
|
+
//# sourceMappingURL=middleware.d.ts.map
|
@@ -28,3 +28,4 @@ export declare class ProcedureBuilder<TContext extends Context, TExtraContext ex
|
|
28
28
|
*/
|
29
29
|
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
30
30
|
}
|
31
|
+
//# sourceMappingURL=procedure-builder.d.ts.map
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import type { SchemaInput, SchemaOutput } from '@orpc/contract';
|
2
|
-
import type {
|
2
|
+
import type { Lazy } from './lazy';
|
3
3
|
import { type Value } from '@orpc/shared';
|
4
|
-
|
4
|
+
import { type ANY_LAZY_PROCEDURE, type ANY_PROCEDURE, type Procedure } from './procedure';
|
5
|
+
export interface CreateProcedureCallerOptions<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE> {
|
5
6
|
procedure: TProcedure;
|
6
7
|
/**
|
7
8
|
* The context used when calling the procedure.
|
8
9
|
*/
|
9
|
-
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> ? UContext : never>;
|
10
|
+
context: Value<TProcedure extends Procedure<infer UContext, any, any, any, any> | Lazy<Procedure<infer UContext, any, any, any, any>> ? UContext : never>;
|
10
11
|
/**
|
11
12
|
* This is helpful for logging and analytics.
|
12
13
|
*
|
@@ -14,5 +15,6 @@ export interface CreateProcedureCallerOptions<TProcedure extends Procedure<any,
|
|
14
15
|
*/
|
15
16
|
path?: string[];
|
16
17
|
}
|
17
|
-
export type ProcedureCaller<TProcedure extends Procedure<any, any,
|
18
|
-
export declare function createProcedureCaller<TProcedure extends
|
18
|
+
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>> ? (...input: [input: SchemaInput<UInputSchema> | FormData] | (undefined extends SchemaInput<UInputSchema> ? [] : never)) => Promise<SchemaOutput<UOutputSchema, UFuncOutput>> : never;
|
19
|
+
export declare function createProcedureCaller<TProcedure extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE>(options: CreateProcedureCallerOptions<TProcedure>): ProcedureCaller<TProcedure>;
|
20
|
+
//# 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,4 +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
|
}
|
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,5 +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
|
-
|
31
|
+
export declare function isProcedure(item: unknown): item is ANY_PROCEDURE;
|
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,4 +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
|
}
|
27
|
+
//# sourceMappingURL=router-builder.d.ts.map
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Value } from '@orpc/shared';
|
2
|
+
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE } from './procedure';
|
2
3
|
import type { Router } from './router';
|
3
|
-
import { type Procedure } from './procedure';
|
4
4
|
import { type ProcedureCaller } from './procedure-caller';
|
5
5
|
export interface CreateRouterCallerOptions<TRouter extends Router<any>> {
|
6
6
|
router: TRouter;
|
@@ -16,6 +16,7 @@ export interface CreateRouterCallerOptions<TRouter extends Router<any>> {
|
|
16
16
|
basePath?: string[];
|
17
17
|
}
|
18
18
|
export type RouterCaller<TRouter extends Router<any>> = {
|
19
|
-
[K in keyof TRouter]: TRouter[K] extends
|
19
|
+
[K in keyof TRouter]: TRouter[K] extends ANY_PROCEDURE | ANY_LAZY_PROCEDURE ? ProcedureCaller<TRouter[K]> : TRouter[K] extends Router<any> ? RouterCaller<TRouter[K]> : never;
|
20
20
|
};
|
21
21
|
export declare function createRouterCaller<TRouter extends Router<any>>(options: CreateRouterCallerOptions<TRouter>): RouterCaller<TRouter>;
|
22
|
+
//# sourceMappingURL=router-caller.d.ts.map
|