@orpc/server 0.0.0-next.1d55ec0 → 0.0.0-next.2f8ca7f
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-3JMSDC5L.js +274 -0
- package/dist/fetch.js +82 -650
- package/dist/index.js +191 -117
- 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/fetch/types.d.ts +28 -0
- 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 +19 -11
- 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 +8 -4
- package/dist/src/router-implementer.d.ts +8 -3
- package/dist/src/router.d.ts +7 -5
- package/dist/src/types.d.ts +8 -1
- package/dist/src/utils.d.ts +1 -0
- package/package.json +10 -9
- package/dist/chunk-CVLK2PBB.js +0 -189
- package/dist/src/adapters/fetch.d.ts +0 -41
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-3JMSDC5L.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, prefixHTTPPath } 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 = lazyRouterPrefix ? prefixHTTPPath(options.current[LAZY_ROUTER_PREFIX_SYMBOL], lazyRouterPrefix) : options.current[LAZY_ROUTER_PREFIX_SYMBOL];
|
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
|
+
).addTags(...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 {
|
@@ -327,6 +384,9 @@ var Builder = class _Builder {
|
|
327
384
|
router(router) {
|
328
385
|
return new RouterBuilder(this.zz$b).router(router);
|
329
386
|
}
|
387
|
+
lazy(loader) {
|
388
|
+
return new RouterBuilder(this.zz$b).lazy(loader);
|
389
|
+
}
|
330
390
|
};
|
331
391
|
|
332
392
|
// src/router.ts
|
@@ -350,25 +410,29 @@ function toContractRouter(router) {
|
|
350
410
|
|
351
411
|
// src/router-caller.ts
|
352
412
|
function createRouterCaller(options) {
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
413
|
+
return createRouterCallerInternal(options);
|
414
|
+
}
|
415
|
+
function createRouterCallerInternal(options) {
|
416
|
+
const procedureCaller = isLazy(options.router) || isProcedure(options.router) ? createProcedureCaller({
|
417
|
+
...options,
|
418
|
+
procedure: options.router,
|
419
|
+
context: options.context,
|
420
|
+
path: options.basePath
|
421
|
+
}) : {};
|
422
|
+
const recursive = new Proxy(procedureCaller, {
|
423
|
+
get(target, key) {
|
424
|
+
if (typeof key !== "string") {
|
425
|
+
return Reflect.get(target, key);
|
426
|
+
}
|
427
|
+
const next = options.router[key];
|
428
|
+
return createRouterCallerInternal({
|
429
|
+
...options,
|
430
|
+
router: next,
|
431
|
+
basePath: [...options.basePath ?? [], key]
|
368
432
|
});
|
369
433
|
}
|
370
|
-
}
|
371
|
-
return
|
434
|
+
});
|
435
|
+
return recursive;
|
372
436
|
}
|
373
437
|
|
374
438
|
// src/index.ts
|
@@ -376,18 +440,28 @@ export * from "@orpc/shared/error";
|
|
376
440
|
var os = new Builder();
|
377
441
|
export {
|
378
442
|
Builder,
|
443
|
+
LAZY_LOADER_SYMBOL,
|
444
|
+
LAZY_ROUTER_PREFIX_SYMBOL,
|
379
445
|
Procedure,
|
380
446
|
ProcedureBuilder,
|
381
447
|
ProcedureImplementer,
|
448
|
+
ROUTER_CONTRACT_SYMBOL,
|
449
|
+
RouterBuilder,
|
382
450
|
RouterImplementer,
|
383
|
-
assertRouterImplementation,
|
384
451
|
chainRouterImplementer,
|
452
|
+
createFlattenLazy,
|
453
|
+
createLazy,
|
385
454
|
createProcedureCaller,
|
386
455
|
createRouterCaller,
|
456
|
+
decorateLazy,
|
387
457
|
decorateMiddleware,
|
388
458
|
decorateProcedure,
|
459
|
+
isLazy,
|
389
460
|
isProcedure,
|
461
|
+
loadLazy,
|
462
|
+
loadProcedure,
|
390
463
|
mergeContext,
|
391
464
|
os,
|
392
465
|
toContractRouter
|
393
466
|
};
|
467
|
+
//# 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
|
@@ -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,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,18 +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>;
|
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,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,8 +1,11 @@
|
|
1
|
-
import type { Value } from '@orpc/shared';
|
1
|
+
import type { Hooks, 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
|
-
export interface CreateRouterCallerOptions<TRouter extends Router<any>> {
|
5
|
+
export interface CreateRouterCallerOptions<TRouter extends Router<any>> extends Hooks<unknown, unknown, TRouter extends Router<infer UContext> ? UContext : never, {
|
6
|
+
path: string[];
|
7
|
+
procedure: ANY_PROCEDURE;
|
8
|
+
}> {
|
6
9
|
router: TRouter;
|
7
10
|
/**
|
8
11
|
* The context used when calling the procedure.
|
@@ -16,6 +19,7 @@ export interface CreateRouterCallerOptions<TRouter extends Router<any>> {
|
|
16
19
|
basePath?: string[];
|
17
20
|
}
|
18
21
|
export type RouterCaller<TRouter extends Router<any>> = {
|
19
|
-
[K in keyof TRouter]: TRouter[K] extends
|
22
|
+
[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
23
|
};
|
21
24
|
export declare function createRouterCaller<TRouter extends Router<any>>(options: CreateRouterCallerOptions<TRouter>): RouterCaller<TRouter>;
|
25
|
+
//# sourceMappingURL=router-caller.d.ts.map
|