@orpc/server 0.0.0-next.db1f26d → 0.0.0-next.df024bb
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.BBGuTxHE.mjs +163 -0
- package/dist/shared/server.BMaJxq9W.d.mts +9 -0
- package/dist/shared/server.BT-fqIEm.d.mts +77 -0
- package/dist/shared/server.DpdgHO1j.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/dist/shared/server.ptXwNGQr.d.mts +158 -0
- package/dist/shared/server.ptXwNGQr.d.ts +158 -0
- package/dist/shared/server.xL87pHsk.d.ts +77 -0
- package/package.json +41 -18
- package/dist/chunk-FL4ZAGNE.js +0 -267
- package/dist/fetch.js +0 -107
- package/dist/index.js +0 -468
- 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 -35
- 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 -20
- 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 -22
- package/dist/src/router-implementer.d.ts +0 -24
- package/dist/src/router.d.ts +0 -21
- package/dist/src/types.d.ts +0 -8
- package/dist/src/utils.d.ts +0 -3
package/dist/fetch.js
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createProcedureCaller,
|
3
|
-
isLazy,
|
4
|
-
isProcedure
|
5
|
-
} from "./chunk-FL4ZAGNE.js";
|
6
|
-
|
7
|
-
// src/fetch/handle.ts
|
8
|
-
import { ORPCError } from "@orpc/shared/error";
|
9
|
-
async function handleFetchRequest(options) {
|
10
|
-
for (const handler of options.handlers) {
|
11
|
-
const response = await handler(options);
|
12
|
-
if (response) {
|
13
|
-
return response;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
const error = new ORPCError({ code: "NOT_FOUND", message: "Not found" });
|
17
|
-
return new Response(JSON.stringify(error.toJSON()), {
|
18
|
-
status: error.status,
|
19
|
-
headers: {
|
20
|
-
"Content-Type": "application/json"
|
21
|
-
}
|
22
|
-
});
|
23
|
-
}
|
24
|
-
|
25
|
-
// src/fetch/handler.ts
|
26
|
-
import { ORPC_HEADER, ORPC_HEADER_VALUE } from "@orpc/contract";
|
27
|
-
import { trim, value } from "@orpc/shared";
|
28
|
-
import { ORPCError as ORPCError2 } from "@orpc/shared/error";
|
29
|
-
import { ORPCDeserializer, ORPCSerializer } from "@orpc/transformer";
|
30
|
-
var serializer = new ORPCSerializer();
|
31
|
-
var deserializer = new ORPCDeserializer();
|
32
|
-
function createORPCHandler() {
|
33
|
-
return async (options) => {
|
34
|
-
if (options.request.headers.get(ORPC_HEADER) !== ORPC_HEADER_VALUE) {
|
35
|
-
return void 0;
|
36
|
-
}
|
37
|
-
const context = await value(options.context);
|
38
|
-
const handler = async () => {
|
39
|
-
const url = new URL(options.request.url);
|
40
|
-
const pathname = `/${trim(url.pathname.replace(options.prefix ?? "", ""), "/")}`;
|
41
|
-
const match = resolveORPCRouter(options.router, pathname);
|
42
|
-
if (!match) {
|
43
|
-
throw new ORPCError2({ code: "NOT_FOUND", message: "Not found" });
|
44
|
-
}
|
45
|
-
const input = await deserializeRequest(options.request);
|
46
|
-
const caller = createProcedureCaller({
|
47
|
-
context,
|
48
|
-
procedure: match.procedure,
|
49
|
-
path: match.path
|
50
|
-
});
|
51
|
-
const output = await caller(input);
|
52
|
-
const { body, headers } = serializer.serialize(output);
|
53
|
-
return new Response(body, {
|
54
|
-
status: 200,
|
55
|
-
headers
|
56
|
-
});
|
57
|
-
};
|
58
|
-
try {
|
59
|
-
return await options.hooks?.(
|
60
|
-
context,
|
61
|
-
{ next: handler, response: (response) => response }
|
62
|
-
) ?? await handler();
|
63
|
-
} catch (e) {
|
64
|
-
const error = e instanceof ORPCError2 ? e : new ORPCError2({
|
65
|
-
code: "INTERNAL_SERVER_ERROR",
|
66
|
-
message: "Internal server error",
|
67
|
-
cause: e
|
68
|
-
});
|
69
|
-
const { body, headers } = serializer.serialize(error.toJSON());
|
70
|
-
return new Response(body, {
|
71
|
-
status: error.status,
|
72
|
-
headers
|
73
|
-
});
|
74
|
-
}
|
75
|
-
};
|
76
|
-
}
|
77
|
-
function resolveORPCRouter(router, pathname) {
|
78
|
-
const path = trim(pathname, "/").split("/").map(decodeURIComponent);
|
79
|
-
let current = router;
|
80
|
-
for (const segment of path) {
|
81
|
-
if (typeof current !== "object" && typeof current !== "function" || !current) {
|
82
|
-
current = void 0;
|
83
|
-
break;
|
84
|
-
}
|
85
|
-
current = current[segment];
|
86
|
-
}
|
87
|
-
return isProcedure(current) || isLazy(current) ? {
|
88
|
-
procedure: current,
|
89
|
-
path
|
90
|
-
} : void 0;
|
91
|
-
}
|
92
|
-
async function deserializeRequest(request) {
|
93
|
-
try {
|
94
|
-
return await deserializer.deserialize(request);
|
95
|
-
} catch (e) {
|
96
|
-
throw new ORPCError2({
|
97
|
-
code: "BAD_REQUEST",
|
98
|
-
message: "Cannot parse request. Please check the request body and Content-Type header.",
|
99
|
-
cause: e
|
100
|
-
});
|
101
|
-
}
|
102
|
-
}
|
103
|
-
export {
|
104
|
-
createORPCHandler,
|
105
|
-
handleFetchRequest
|
106
|
-
};
|
107
|
-
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
DELETED
@@ -1,468 +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
|
-
mergeContext
|
14
|
-
} from "./chunk-FL4ZAGNE.js";
|
15
|
-
|
16
|
-
// src/builder.ts
|
17
|
-
import {
|
18
|
-
ContractProcedure,
|
19
|
-
isContractProcedure as isContractProcedure2
|
20
|
-
} from "@orpc/contract";
|
21
|
-
|
22
|
-
// src/procedure-builder.ts
|
23
|
-
import {
|
24
|
-
DecoratedContractProcedure as DecoratedContractProcedure2
|
25
|
-
} from "@orpc/contract";
|
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
|
-
|
156
|
-
// src/procedure-implementer.ts
|
157
|
-
var ProcedureImplementer = class _ProcedureImplementer {
|
158
|
-
constructor(zz$pi) {
|
159
|
-
this.zz$pi = zz$pi;
|
160
|
-
}
|
161
|
-
use(middleware, mapInput) {
|
162
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
163
|
-
return new _ProcedureImplementer({
|
164
|
-
...this.zz$pi,
|
165
|
-
middlewares: [...this.zz$pi.middlewares ?? [], middleware_]
|
166
|
-
});
|
167
|
-
}
|
168
|
-
func(func) {
|
169
|
-
return decorateProcedure({
|
170
|
-
zz$p: {
|
171
|
-
middlewares: this.zz$pi.middlewares,
|
172
|
-
contract: this.zz$pi.contract,
|
173
|
-
func
|
174
|
-
}
|
175
|
-
});
|
176
|
-
}
|
177
|
-
lazy(loader) {
|
178
|
-
return new RouterBuilder(this.zz$pi).lazy(loader);
|
179
|
-
}
|
180
|
-
};
|
181
|
-
|
182
|
-
// src/procedure-builder.ts
|
183
|
-
var ProcedureBuilder = class _ProcedureBuilder {
|
184
|
-
constructor(zz$pb) {
|
185
|
-
this.zz$pb = zz$pb;
|
186
|
-
}
|
187
|
-
/**
|
188
|
-
* Self chainable
|
189
|
-
*/
|
190
|
-
route(opts) {
|
191
|
-
return new _ProcedureBuilder({
|
192
|
-
...this.zz$pb,
|
193
|
-
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).route(
|
194
|
-
opts
|
195
|
-
)
|
196
|
-
});
|
197
|
-
}
|
198
|
-
input(schema, example) {
|
199
|
-
return new _ProcedureBuilder({
|
200
|
-
...this.zz$pb,
|
201
|
-
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).input(
|
202
|
-
schema,
|
203
|
-
example
|
204
|
-
)
|
205
|
-
});
|
206
|
-
}
|
207
|
-
output(schema, example) {
|
208
|
-
return new _ProcedureBuilder({
|
209
|
-
...this.zz$pb,
|
210
|
-
contract: DecoratedContractProcedure2.decorate(this.zz$pb.contract).output(
|
211
|
-
schema,
|
212
|
-
example
|
213
|
-
)
|
214
|
-
});
|
215
|
-
}
|
216
|
-
use(middleware, mapInput) {
|
217
|
-
if (!mapInput) {
|
218
|
-
return new ProcedureImplementer({
|
219
|
-
contract: this.zz$pb.contract,
|
220
|
-
middlewares: this.zz$pb.middlewares
|
221
|
-
}).use(middleware);
|
222
|
-
}
|
223
|
-
return new ProcedureImplementer({
|
224
|
-
contract: this.zz$pb.contract,
|
225
|
-
middlewares: this.zz$pb.middlewares
|
226
|
-
}).use(middleware, mapInput);
|
227
|
-
}
|
228
|
-
/**
|
229
|
-
* Convert to Procedure
|
230
|
-
*/
|
231
|
-
func(func) {
|
232
|
-
return decorateProcedure({
|
233
|
-
zz$p: {
|
234
|
-
middlewares: this.zz$pb.middlewares,
|
235
|
-
contract: this.zz$pb.contract,
|
236
|
-
func
|
237
|
-
}
|
238
|
-
});
|
239
|
-
}
|
240
|
-
};
|
241
|
-
|
242
|
-
// src/router-implementer.ts
|
243
|
-
import { isContractProcedure } from "@orpc/contract";
|
244
|
-
var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
|
245
|
-
var RouterImplementer = class {
|
246
|
-
constructor(zz$ri) {
|
247
|
-
this.zz$ri = zz$ri;
|
248
|
-
}
|
249
|
-
router(router) {
|
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
|
-
});
|
260
|
-
}
|
261
|
-
};
|
262
|
-
function chainRouterImplementer(contract, middlewares) {
|
263
|
-
const result = {};
|
264
|
-
for (const key in contract) {
|
265
|
-
const item = contract[key];
|
266
|
-
if (isContractProcedure(item)) {
|
267
|
-
result[key] = new ProcedureImplementer({
|
268
|
-
contract: item,
|
269
|
-
middlewares
|
270
|
-
});
|
271
|
-
} else {
|
272
|
-
result[key] = chainRouterImplementer(item, middlewares);
|
273
|
-
}
|
274
|
-
}
|
275
|
-
const implementer = new RouterImplementer({ contract });
|
276
|
-
return Object.assign(implementer, result);
|
277
|
-
}
|
278
|
-
|
279
|
-
// src/builder.ts
|
280
|
-
var Builder = class _Builder {
|
281
|
-
constructor(zz$b = {}) {
|
282
|
-
this.zz$b = zz$b;
|
283
|
-
}
|
284
|
-
/**
|
285
|
-
* Self chainable
|
286
|
-
*/
|
287
|
-
context() {
|
288
|
-
return this;
|
289
|
-
}
|
290
|
-
use(middleware, mapInput) {
|
291
|
-
const middleware_ = mapInput ? decorateMiddleware(middleware).mapInput(mapInput) : middleware;
|
292
|
-
return new _Builder({
|
293
|
-
...this.zz$b,
|
294
|
-
middlewares: [...this.zz$b.middlewares || [], middleware_]
|
295
|
-
});
|
296
|
-
}
|
297
|
-
/**
|
298
|
-
* Convert to ContractProcedureBuilder
|
299
|
-
*/
|
300
|
-
route(opts) {
|
301
|
-
return new ProcedureBuilder({
|
302
|
-
middlewares: this.zz$b.middlewares,
|
303
|
-
contract: new ContractProcedure({
|
304
|
-
...opts,
|
305
|
-
InputSchema: void 0,
|
306
|
-
OutputSchema: void 0
|
307
|
-
})
|
308
|
-
});
|
309
|
-
}
|
310
|
-
input(schema, example) {
|
311
|
-
return new ProcedureBuilder({
|
312
|
-
middlewares: this.zz$b.middlewares,
|
313
|
-
contract: new ContractProcedure({
|
314
|
-
OutputSchema: void 0,
|
315
|
-
InputSchema: schema,
|
316
|
-
inputExample: example
|
317
|
-
})
|
318
|
-
});
|
319
|
-
}
|
320
|
-
output(schema, example) {
|
321
|
-
return new ProcedureBuilder({
|
322
|
-
middlewares: this.zz$b.middlewares,
|
323
|
-
contract: new ContractProcedure({
|
324
|
-
InputSchema: void 0,
|
325
|
-
OutputSchema: schema,
|
326
|
-
outputExample: example
|
327
|
-
})
|
328
|
-
});
|
329
|
-
}
|
330
|
-
/**
|
331
|
-
* Convert to Procedure
|
332
|
-
*/
|
333
|
-
func(func) {
|
334
|
-
return decorateProcedure({
|
335
|
-
zz$p: {
|
336
|
-
middlewares: this.zz$b.middlewares,
|
337
|
-
contract: new ContractProcedure({
|
338
|
-
InputSchema: void 0,
|
339
|
-
OutputSchema: void 0
|
340
|
-
}),
|
341
|
-
func
|
342
|
-
}
|
343
|
-
});
|
344
|
-
}
|
345
|
-
/**
|
346
|
-
* Convert to ProcedureImplementer | RouterBuilder
|
347
|
-
*/
|
348
|
-
contract(contract) {
|
349
|
-
if (isContractProcedure2(contract)) {
|
350
|
-
return new ProcedureImplementer({
|
351
|
-
contract,
|
352
|
-
middlewares: this.zz$b.middlewares
|
353
|
-
});
|
354
|
-
}
|
355
|
-
return chainRouterImplementer(
|
356
|
-
contract,
|
357
|
-
this.zz$b.middlewares
|
358
|
-
);
|
359
|
-
}
|
360
|
-
/**
|
361
|
-
* Create ExtendedMiddleware
|
362
|
-
*/
|
363
|
-
// TODO: TOutput always any, infer not work at all, because TOutput used inside middleware params,
|
364
|
-
// solution (maybe): create new generic for .output() method
|
365
|
-
middleware(middleware) {
|
366
|
-
return decorateMiddleware(middleware);
|
367
|
-
}
|
368
|
-
prefix(prefix) {
|
369
|
-
return new RouterBuilder({
|
370
|
-
...this.zz$b,
|
371
|
-
prefix
|
372
|
-
});
|
373
|
-
}
|
374
|
-
tags(...tags) {
|
375
|
-
return new RouterBuilder({
|
376
|
-
...this.zz$b,
|
377
|
-
tags
|
378
|
-
});
|
379
|
-
}
|
380
|
-
/**
|
381
|
-
* Create DecoratedRouter
|
382
|
-
*/
|
383
|
-
router(router) {
|
384
|
-
return new RouterBuilder(this.zz$b).router(router);
|
385
|
-
}
|
386
|
-
lazy(loader) {
|
387
|
-
return new RouterBuilder(this.zz$b).lazy(loader);
|
388
|
-
}
|
389
|
-
};
|
390
|
-
|
391
|
-
// src/router.ts
|
392
|
-
import {
|
393
|
-
isContractProcedure as isContractProcedure3
|
394
|
-
} from "@orpc/contract";
|
395
|
-
function toContractRouter(router) {
|
396
|
-
const contract = {};
|
397
|
-
for (const key in router) {
|
398
|
-
const item = router[key];
|
399
|
-
if (isContractProcedure3(item)) {
|
400
|
-
contract[key] = item;
|
401
|
-
} else if (isProcedure(item)) {
|
402
|
-
contract[key] = item.zz$p.contract;
|
403
|
-
} else {
|
404
|
-
contract[key] = toContractRouter(item);
|
405
|
-
}
|
406
|
-
}
|
407
|
-
return contract;
|
408
|
-
}
|
409
|
-
|
410
|
-
// src/router-caller.ts
|
411
|
-
function createRouterCaller(options) {
|
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,
|
432
|
-
context: options.context,
|
433
|
-
path: [...options.path, key]
|
434
|
-
});
|
435
|
-
}
|
436
|
-
});
|
437
|
-
return recursive;
|
438
|
-
}
|
439
|
-
|
440
|
-
// src/index.ts
|
441
|
-
export * from "@orpc/shared/error";
|
442
|
-
var os = new Builder();
|
443
|
-
export {
|
444
|
-
Builder,
|
445
|
-
LAZY_LOADER_SYMBOL,
|
446
|
-
LAZY_ROUTER_PREFIX_SYMBOL,
|
447
|
-
Procedure,
|
448
|
-
ProcedureBuilder,
|
449
|
-
ProcedureImplementer,
|
450
|
-
ROUTER_CONTRACT_SYMBOL,
|
451
|
-
RouterBuilder,
|
452
|
-
RouterImplementer,
|
453
|
-
chainRouterImplementer,
|
454
|
-
createFlattenLazy,
|
455
|
-
createLazy,
|
456
|
-
createProcedureCaller,
|
457
|
-
createRouterCaller,
|
458
|
-
decorateLazy,
|
459
|
-
decorateMiddleware,
|
460
|
-
decorateProcedure,
|
461
|
-
isLazy,
|
462
|
-
isProcedure,
|
463
|
-
loadLazy,
|
464
|
-
mergeContext,
|
465
|
-
os,
|
466
|
-
toContractRouter
|
467
|
-
};
|
468
|
-
//# 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,35 +0,0 @@
|
|
1
|
-
import type { PartialOnUndefinedDeep, Promisable, Value } from '@orpc/shared';
|
2
|
-
import type { Router } from '../router';
|
3
|
-
export interface FetchHandlerHooks {
|
4
|
-
next: () => Promise<Response>;
|
5
|
-
response: (response: Response) => Response;
|
6
|
-
}
|
7
|
-
export type FetchHandlerOptions<TRouter extends Router<any>> = {
|
8
|
-
/**
|
9
|
-
* The `router` used for handling the request and routing,
|
10
|
-
*
|
11
|
-
*/
|
12
|
-
router: TRouter;
|
13
|
-
/**
|
14
|
-
* The request need to be handled.
|
15
|
-
*/
|
16
|
-
request: Request;
|
17
|
-
/**
|
18
|
-
* Remove the prefix from the request path.
|
19
|
-
*
|
20
|
-
* @example /orpc
|
21
|
-
* @example /api
|
22
|
-
*/
|
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>;
|
28
|
-
} & PartialOnUndefinedDeep<{
|
29
|
-
/**
|
30
|
-
* The context used to handle the request.
|
31
|
-
*/
|
32
|
-
context: Value<TRouter extends Router<infer UContext> ? UContext : never>;
|
33
|
-
}>;
|
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
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
|