@orpc/server 0.0.0-next.9306271 → 0.0.0-next.93e6063
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/README.md +118 -0
- package/dist/adapters/fetch/index.d.mts +27 -0
- package/dist/adapters/fetch/index.d.ts +27 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +20 -0
- package/dist/adapters/hono/index.d.ts +20 -0
- package/dist/adapters/hono/index.mjs +32 -0
- package/dist/adapters/next/index.d.mts +27 -0
- package/dist/adapters/next/index.d.ts +27 -0
- package/dist/adapters/next/index.mjs +29 -0
- package/dist/adapters/node/index.d.mts +35 -0
- package/dist/adapters/node/index.d.ts +35 -0
- package/dist/adapters/node/index.mjs +30 -0
- package/dist/adapters/standard/index.d.mts +29 -0
- package/dist/adapters/standard/index.d.ts +29 -0
- package/dist/adapters/standard/index.mjs +7 -0
- package/dist/index.d.mts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.mjs +333 -0
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/plugins/index.mjs +103 -0
- package/dist/shared/server.B-ewprcf.d.ts +77 -0
- package/dist/shared/server.BBGuTxHE.mjs +163 -0
- package/dist/shared/server.CA-o8cUY.d.mts +9 -0
- package/dist/shared/server.Cn9ybJtE.d.mts +152 -0
- package/dist/shared/server.Cn9ybJtE.d.ts +152 -0
- package/dist/shared/server.DJrh0Ceu.d.mts +77 -0
- package/dist/shared/server.DPQt9YYq.d.ts +9 -0
- package/dist/shared/server.KwueCzFr.mjs +26 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.V6zT5iYQ.mjs +379 -0
- package/package.json +41 -18
- package/dist/chunk-3JMSDC5L.js +0 -274
- package/dist/fetch.js +0 -112
- package/dist/index.js +0 -467
- package/dist/src/builder.d.ts +0 -53
- package/dist/src/fetch/handle.d.ts +0 -7
- package/dist/src/fetch/handler.d.ts +0 -3
- package/dist/src/fetch/index.d.ts +0 -4
- package/dist/src/fetch/types.d.ts +0 -28
- package/dist/src/index.d.ts +0 -17
- package/dist/src/lazy.d.ts +0 -23
- package/dist/src/middleware.d.ts +0 -26
- package/dist/src/procedure-builder.d.ts +0 -31
- package/dist/src/procedure-caller.d.ts +0 -26
- package/dist/src/procedure-implementer.d.ts +0 -22
- package/dist/src/procedure.d.ts +0 -32
- package/dist/src/router-builder.d.ts +0 -27
- package/dist/src/router-caller.d.ts +0 -25
- package/dist/src/router-implementer.d.ts +0 -24
- package/dist/src/router.d.ts +0 -21
- package/dist/src/types.d.ts +0 -14
- package/dist/src/utils.d.ts +0 -3
package/dist/index.js
DELETED
@@ -1,467 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
LAZY_LOADER_SYMBOL,
|
3
|
-
Procedure,
|
4
|
-
createFlattenLazy,
|
5
|
-
createLazy,
|
6
|
-
createProcedureCaller,
|
7
|
-
decorateLazy,
|
8
|
-
decorateMiddleware,
|
9
|
-
decorateProcedure,
|
10
|
-
isLazy,
|
11
|
-
isProcedure,
|
12
|
-
loadLazy,
|
13
|
-
loadProcedure,
|
14
|
-
mergeContext
|
15
|
-
} from "./chunk-3JMSDC5L.js";
|
16
|
-
|
17
|
-
// src/builder.ts
|
18
|
-
import {
|
19
|
-
ContractProcedure,
|
20
|
-
isContractProcedure as isContractProcedure2
|
21
|
-
} from "@orpc/contract";
|
22
|
-
|
23
|
-
// src/procedure-builder.ts
|
24
|
-
import {
|
25
|
-
DecoratedContractProcedure as DecoratedContractProcedure2
|
26
|
-
} from "@orpc/contract";
|
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
|
-
|
157
|
-
// src/procedure-implementer.ts
|
158
|
-
var ProcedureImplementer = class _ProcedureImplementer {
|
159
|
-
constructor(zz$pi) {
|
160
|
-
this.zz$pi = zz$pi;
|
161
|
-
}
|
162
|
-
use(middleware, mapInput) {
|
163
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
164
|
-
return new _ProcedureImplementer({
|
165
|
-
...this.zz$pi,
|
166
|
-
middlewares: [...this.zz$pi.middlewares ?? [], middleware_]
|
167
|
-
});
|
168
|
-
}
|
169
|
-
func(func) {
|
170
|
-
return decorateProcedure({
|
171
|
-
zz$p: {
|
172
|
-
middlewares: this.zz$pi.middlewares,
|
173
|
-
contract: this.zz$pi.contract,
|
174
|
-
func
|
175
|
-
}
|
176
|
-
});
|
177
|
-
}
|
178
|
-
lazy(loader) {
|
179
|
-
return new RouterBuilder(this.zz$pi).lazy(loader);
|
180
|
-
}
|
181
|
-
};
|
182
|
-
|
183
|
-
// src/procedure-builder.ts
|
184
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
185
|
-
constructor(zz$pb) {
|
186
|
-
this.zz$pb = zz$pb;
|
187
|
-
}
|
188
|
-
/**
|
189
|
-
* Self chainable
|
190
|
-
*/
|
191
|
-
route(opts) {
|
192
|
-
return new _ProcedureBuilder({
|
193
|
-
...this.zz$pb,
|
194
|
-
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route(
|
195
|
-
opts
|
196
|
-
)
|
197
|
-
});
|
198
|
-
}
|
199
|
-
input(schema, example) {
|
200
|
-
return new _ProcedureBuilder({
|
201
|
-
...this.zz$pb,
|
202
|
-
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input(
|
203
|
-
schema,
|
204
|
-
example
|
205
|
-
)
|
206
|
-
});
|
207
|
-
}
|
208
|
-
output(schema, example) {
|
209
|
-
return new _ProcedureBuilder({
|
210
|
-
...this.zz$pb,
|
211
|
-
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output(
|
212
|
-
schema,
|
213
|
-
example
|
214
|
-
)
|
215
|
-
});
|
216
|
-
}
|
217
|
-
use(middleware, mapInput) {
|
218
|
-
if (!mapInput) {
|
219
|
-
return new ProcedureImplementer({
|
220
|
-
contract: this.zz$pb.contract,
|
221
|
-
middlewares: this.zz$pb.middlewares
|
222
|
-
}).use(middleware);
|
223
|
-
}
|
224
|
-
return new ProcedureImplementer({
|
225
|
-
contract: this.zz$pb.contract,
|
226
|
-
middlewares: this.zz$pb.middlewares
|
227
|
-
}).use(middleware, mapInput);
|
228
|
-
}
|
229
|
-
/**
|
230
|
-
* Convert to Procedure
|
231
|
-
*/
|
232
|
-
func(func) {
|
233
|
-
return decorateProcedure({
|
234
|
-
zz$p: {
|
235
|
-
middlewares: this.zz$pb.middlewares,
|
236
|
-
contract: this.zz$pb.contract,
|
237
|
-
func
|
238
|
-
}
|
239
|
-
});
|
240
|
-
}
|
241
|
-
};
|
242
|
-
|
243
|
-
// src/router-implementer.ts
|
244
|
-
import { isContractProcedure } from "@orpc/contract";
|
245
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
246
|
-
var RouterImplementer = class {
|
247
|
-
constructor(zz$ri) {
|
248
|
-
this.zz$ri = zz$ri;
|
249
|
-
}
|
250
|
-
router(router) {
|
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
|
-
});
|
261
|
-
}
|
262
|
-
};
|
263
|
-
function chainRouterImplementer(contract, middlewares) {
|
264
|
-
const result = {};
|
265
|
-
for (const key in contract) {
|
266
|
-
const item = contract[key];
|
267
|
-
if (isContractProcedure(item)) {
|
268
|
-
result[key] = new ProcedureImplementer({
|
269
|
-
contract: item,
|
270
|
-
middlewares
|
271
|
-
});
|
272
|
-
} else {
|
273
|
-
result[key] = chainRouterImplementer(item, middlewares);
|
274
|
-
}
|
275
|
-
}
|
276
|
-
const implementer = new RouterImplementer({ contract });
|
277
|
-
return Object.assign(implementer, result);
|
278
|
-
}
|
279
|
-
|
280
|
-
// src/builder.ts
|
281
|
-
var Builder = class _Builder {
|
282
|
-
constructor(zz$b = {}) {
|
283
|
-
this.zz$b = zz$b;
|
284
|
-
}
|
285
|
-
/**
|
286
|
-
* Self chainable
|
287
|
-
*/
|
288
|
-
context() {
|
289
|
-
return this;
|
290
|
-
}
|
291
|
-
use(middleware, mapInput) {
|
292
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
293
|
-
return new _Builder({
|
294
|
-
...this.zz$b,
|
295
|
-
middlewares: [...this.zz$b.middlewares || [], middleware_]
|
296
|
-
});
|
297
|
-
}
|
298
|
-
/**
|
299
|
-
* Convert to ContractProcedureBuilder
|
300
|
-
*/
|
301
|
-
route(opts) {
|
302
|
-
return new ProcedureBuilder({
|
303
|
-
middlewares: this.zz$b.middlewares,
|
304
|
-
contract: new ContractProcedure({
|
305
|
-
...opts,
|
306
|
-
InputSchema: void 0,
|
307
|
-
OutputSchema: void 0
|
308
|
-
})
|
309
|
-
});
|
310
|
-
}
|
311
|
-
input(schema, example) {
|
312
|
-
return new ProcedureBuilder({
|
313
|
-
middlewares: this.zz$b.middlewares,
|
314
|
-
contract: new ContractProcedure({
|
315
|
-
OutputSchema: void 0,
|
316
|
-
InputSchema: schema,
|
317
|
-
inputExample: example
|
318
|
-
})
|
319
|
-
});
|
320
|
-
}
|
321
|
-
output(schema, example) {
|
322
|
-
return new ProcedureBuilder({
|
323
|
-
middlewares: this.zz$b.middlewares,
|
324
|
-
contract: new ContractProcedure({
|
325
|
-
InputSchema: void 0,
|
326
|
-
OutputSchema: schema,
|
327
|
-
outputExample: example
|
328
|
-
})
|
329
|
-
});
|
330
|
-
}
|
331
|
-
/**
|
332
|
-
* Convert to Procedure
|
333
|
-
*/
|
334
|
-
func(func) {
|
335
|
-
return decorateProcedure({
|
336
|
-
zz$p: {
|
337
|
-
middlewares: this.zz$b.middlewares,
|
338
|
-
contract: new ContractProcedure({
|
339
|
-
InputSchema: void 0,
|
340
|
-
OutputSchema: void 0
|
341
|
-
}),
|
342
|
-
func
|
343
|
-
}
|
344
|
-
});
|
345
|
-
}
|
346
|
-
/**
|
347
|
-
* Convert to ProcedureImplementer | RouterBuilder
|
348
|
-
*/
|
349
|
-
contract(contract) {
|
350
|
-
if (isContractProcedure2(contract)) {
|
351
|
-
return new ProcedureImplementer({
|
352
|
-
contract,
|
353
|
-
middlewares: this.zz$b.middlewares
|
354
|
-
});
|
355
|
-
}
|
356
|
-
return chainRouterImplementer(
|
357
|
-
contract,
|
358
|
-
this.zz$b.middlewares
|
359
|
-
);
|
360
|
-
}
|
361
|
-
/**
|
362
|
-
* Create ExtendedMiddleware
|
363
|
-
*/
|
364
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
365
|
-
// solution (maybe): create new generic for .output() method
|
366
|
-
middleware(middleware) {
|
367
|
-
return decorateMiddleware(middleware);
|
368
|
-
}
|
369
|
-
prefix(prefix) {
|
370
|
-
return new RouterBuilder({
|
371
|
-
...this.zz$b,
|
372
|
-
prefix
|
373
|
-
});
|
374
|
-
}
|
375
|
-
tags(...tags) {
|
376
|
-
return new RouterBuilder({
|
377
|
-
...this.zz$b,
|
378
|
-
tags
|
379
|
-
});
|
380
|
-
}
|
381
|
-
/**
|
382
|
-
* Create DecoratedRouter
|
383
|
-
*/
|
384
|
-
router(router) {
|
385
|
-
return new RouterBuilder(this.zz$b).router(router);
|
386
|
-
}
|
387
|
-
lazy(loader) {
|
388
|
-
return new RouterBuilder(this.zz$b).lazy(loader);
|
389
|
-
}
|
390
|
-
};
|
391
|
-
|
392
|
-
// src/router.ts
|
393
|
-
import {
|
394
|
-
isContractProcedure as isContractProcedure3
|
395
|
-
} from "@orpc/contract";
|
396
|
-
function toContractRouter(router) {
|
397
|
-
const contract = {};
|
398
|
-
for (const key in router) {
|
399
|
-
const item = router[key];
|
400
|
-
if (isContractProcedure3(item)) {
|
401
|
-
contract[key] = item;
|
402
|
-
} else if (isProcedure(item)) {
|
403
|
-
contract[key] = item.zz$p.contract;
|
404
|
-
} else {
|
405
|
-
contract[key] = toContractRouter(item);
|
406
|
-
}
|
407
|
-
}
|
408
|
-
return contract;
|
409
|
-
}
|
410
|
-
|
411
|
-
// src/router-caller.ts
|
412
|
-
function createRouterCaller(options) {
|
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]
|
432
|
-
});
|
433
|
-
}
|
434
|
-
});
|
435
|
-
return recursive;
|
436
|
-
}
|
437
|
-
|
438
|
-
// src/index.ts
|
439
|
-
export * from "@orpc/shared/error";
|
440
|
-
var os = new Builder();
|
441
|
-
export {
|
442
|
-
Builder,
|
443
|
-
LAZY_LOADER_SYMBOL,
|
444
|
-
LAZY_ROUTER_PREFIX_SYMBOL,
|
445
|
-
Procedure,
|
446
|
-
ProcedureBuilder,
|
447
|
-
ProcedureImplementer,
|
448
|
-
ROUTER_CONTRACT_SYMBOL,
|
449
|
-
RouterBuilder,
|
450
|
-
RouterImplementer,
|
451
|
-
chainRouterImplementer,
|
452
|
-
createFlattenLazy,
|
453
|
-
createLazy,
|
454
|
-
createProcedureCaller,
|
455
|
-
createRouterCaller,
|
456
|
-
decorateLazy,
|
457
|
-
decorateMiddleware,
|
458
|
-
decorateProcedure,
|
459
|
-
isLazy,
|
460
|
-
isProcedure,
|
461
|
-
loadLazy,
|
462
|
-
loadProcedure,
|
463
|
-
mergeContext,
|
464
|
-
os,
|
465
|
-
toContractRouter
|
466
|
-
};
|
467
|
-
//# sourceMappingURL=index.js.map
|
package/dist/src/builder.d.ts
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
import type { IsEqual } from '@orpc/shared';
|
2
|
-
import type { DecoratedLazy } from './lazy';
|
3
|
-
import type { DecoratedProcedure, Procedure, ProcedureFunc } from './procedure';
|
4
|
-
import type { HandledRouter, Router } from './router';
|
5
|
-
import type { Context, MergeContext } from './types';
|
6
|
-
import { ContractProcedure, type ContractRouter, type HTTPPath, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
7
|
-
import { type DecoratedMiddleware, type MapInputMiddleware, type Middleware } from './middleware';
|
8
|
-
import { ProcedureBuilder } from './procedure-builder';
|
9
|
-
import { ProcedureImplementer } from './procedure-implementer';
|
10
|
-
import { RouterBuilder } from './router-builder';
|
11
|
-
import { type ChainedRouterImplementer } from './router-implementer';
|
12
|
-
export declare class Builder<TContext extends Context, TExtraContext extends Context> {
|
13
|
-
zz$b: {
|
14
|
-
middlewares?: Middleware<any, any, any, any>[];
|
15
|
-
};
|
16
|
-
constructor(zz$b?: {
|
17
|
-
middlewares?: Middleware<any, any, any, any>[];
|
18
|
-
});
|
19
|
-
/**
|
20
|
-
* Self chainable
|
21
|
-
*/
|
22
|
-
context<UContext extends Context>(): IsEqual<UContext, Context> extends true ? Builder<TContext, TExtraContext> : Builder<UContext, TExtraContext>;
|
23
|
-
use<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, unknown, unknown>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
24
|
-
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>): Builder<TContext, MergeContext<TExtraContext, UExtraContext>>;
|
25
|
-
/**
|
26
|
-
* Convert to ContractProcedureBuilder
|
27
|
-
*/
|
28
|
-
route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, undefined, undefined>;
|
29
|
-
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, undefined>;
|
30
|
-
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, undefined, USchema>;
|
31
|
-
/**
|
32
|
-
* Convert to Procedure
|
33
|
-
*/
|
34
|
-
func<UFuncOutput = undefined>(func: ProcedureFunc<TContext, TExtraContext, undefined, undefined, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, undefined, undefined, UFuncOutput>;
|
35
|
-
/**
|
36
|
-
* Convert to ProcedureImplementer | RouterBuilder
|
37
|
-
*/
|
38
|
-
contract<UContract extends ContractProcedure<any, any> | ContractRouter>(contract: UContract): UContract extends ContractProcedure<infer UInputSchema, infer UOutputSchema> ? ProcedureImplementer<TContext, TExtraContext, UInputSchema, UOutputSchema> : UContract extends ContractRouter ? ChainedRouterImplementer<TContext, UContract, TExtraContext> : never;
|
39
|
-
/**
|
40
|
-
* Create ExtendedMiddleware
|
41
|
-
*/
|
42
|
-
middleware<UExtraContext extends Context = undefined, TInput = unknown, TOutput = any>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>): DecoratedMiddleware<MergeContext<TContext, TExtraContext>, UExtraContext, TInput, TOutput>;
|
43
|
-
prefix(prefix: HTTPPath): RouterBuilder<TContext, TExtraContext>;
|
44
|
-
tags(...tags: string[]): RouterBuilder<TContext, TExtraContext>;
|
45
|
-
/**
|
46
|
-
* Create DecoratedRouter
|
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>;
|
52
|
-
}
|
53
|
-
//# sourceMappingURL=builder.d.ts.map
|
@@ -1,7 +0,0 @@
|
|
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
|
@@ -1,28 +0,0 @@
|
|
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
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
import { Builder } from './builder';
|
2
|
-
export * from './builder';
|
3
|
-
export * from './lazy';
|
4
|
-
export * from './middleware';
|
5
|
-
export * from './procedure';
|
6
|
-
export * from './procedure-builder';
|
7
|
-
export * from './procedure-caller';
|
8
|
-
export * from './procedure-implementer';
|
9
|
-
export * from './router';
|
10
|
-
export * from './router-builder';
|
11
|
-
export * from './router-caller';
|
12
|
-
export * from './router-implementer';
|
13
|
-
export * from './types';
|
14
|
-
export * from './utils';
|
15
|
-
export * from '@orpc/shared/error';
|
16
|
-
export declare const os: Builder<Record<string, unknown> | undefined, undefined>;
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/lazy.d.ts
DELETED
@@ -1,23 +0,0 @@
|
|
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
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
import type { Promisable } from '@orpc/shared';
|
2
|
-
import type { Context, MergeContext, Meta } from './types';
|
3
|
-
export type MiddlewareResult<TExtraContext extends Context, TOutput> = Promisable<{
|
4
|
-
output: TOutput;
|
5
|
-
context: TExtraContext;
|
6
|
-
}>;
|
7
|
-
export interface MiddlewareMeta<TOutput> extends Meta {
|
8
|
-
next: <UExtraContext extends Context = undefined>(options: UExtraContext extends undefined ? {
|
9
|
-
context?: UExtraContext;
|
10
|
-
} : {
|
11
|
-
context: UExtraContext;
|
12
|
-
}) => MiddlewareResult<UExtraContext, TOutput>;
|
13
|
-
output: <UOutput>(output: UOutput) => MiddlewareResult<undefined, UOutput>;
|
14
|
-
}
|
15
|
-
export interface Middleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput> {
|
16
|
-
(input: TInput, context: TContext, meta: MiddlewareMeta<TOutput>): Promisable<MiddlewareResult<TExtraContext, TOutput>>;
|
17
|
-
}
|
18
|
-
export interface MapInputMiddleware<TInput, TMappedInput> {
|
19
|
-
(input: TInput): TMappedInput;
|
20
|
-
}
|
21
|
-
export interface DecoratedMiddleware<TContext extends Context, TExtraContext extends Context, TInput, TOutput> extends Middleware<TContext, TExtraContext, TInput, TOutput> {
|
22
|
-
concat: (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UInput = TInput>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UInput & TInput, TOutput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, TInput & UInput, TOutput>) & (<UExtraContext extends Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>> | undefined = undefined, UInput = TInput, UMappedInput = unknown>(middleware: Middleware<MergeContext<TContext, TExtraContext>, UExtraContext, UMappedInput, TOutput>, mapInput: MapInputMiddleware<UInput, UMappedInput>) => DecoratedMiddleware<TContext, MergeContext<TExtraContext, UExtraContext>, TInput & UInput, TOutput>);
|
23
|
-
mapInput: <UInput = unknown>(map: MapInputMiddleware<UInput, TInput>) => DecoratedMiddleware<TContext, TExtraContext, UInput, TOutput>;
|
24
|
-
}
|
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
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import type { MapInputMiddleware, Middleware } from './middleware';
|
2
|
-
import type { Context, MergeContext } from './types';
|
3
|
-
import { type ContractProcedure, type RouteOptions, type Schema, type SchemaInput, type SchemaOutput } from '@orpc/contract';
|
4
|
-
import { type DecoratedProcedure, type ProcedureFunc } from './procedure';
|
5
|
-
import { ProcedureImplementer } from './procedure-implementer';
|
6
|
-
export declare class ProcedureBuilder<TContext extends Context, TExtraContext extends Context, TInputSchema extends Schema, TOutputSchema extends Schema> {
|
7
|
-
zz$pb: {
|
8
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
9
|
-
middlewares?: Middleware<any, any, any, any>[];
|
10
|
-
};
|
11
|
-
constructor(zz$pb: {
|
12
|
-
contract: ContractProcedure<TInputSchema, TOutputSchema>;
|
13
|
-
middlewares?: Middleware<any, any, any, any>[];
|
14
|
-
});
|
15
|
-
/**
|
16
|
-
* Self chainable
|
17
|
-
*/
|
18
|
-
route(opts: RouteOptions): ProcedureBuilder<TContext, TExtraContext, TInputSchema, TOutputSchema>;
|
19
|
-
input<USchema extends Schema = undefined>(schema: USchema, example?: SchemaInput<USchema>): ProcedureBuilder<TContext, TExtraContext, USchema, TOutputSchema>;
|
20
|
-
output<USchema extends Schema = undefined>(schema: USchema, example?: SchemaOutput<USchema>): ProcedureBuilder<TContext, TExtraContext, TInputSchema, USchema>;
|
21
|
-
/**
|
22
|
-
* Convert to ProcedureBuilder
|
23
|
-
*/
|
24
|
-
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>;
|
25
|
-
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>;
|
26
|
-
/**
|
27
|
-
* Convert to Procedure
|
28
|
-
*/
|
29
|
-
func<UFuncOutput extends SchemaOutput<TOutputSchema>>(func: ProcedureFunc<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>): DecoratedProcedure<TContext, TExtraContext, TInputSchema, TOutputSchema, UFuncOutput>;
|
30
|
-
}
|
31
|
-
//# sourceMappingURL=procedure-builder.d.ts.map
|