@orpc/server 0.0.0-next.6c13765 → 0.0.0-next.6c5bfe4
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 +26 -0
- package/dist/adapters/fetch/index.d.ts +26 -0
- package/dist/adapters/fetch/index.mjs +9 -0
- package/dist/adapters/hono/index.d.mts +19 -0
- package/dist/adapters/hono/index.d.ts +19 -0
- package/dist/{hono.js → adapters/hono/index.mjs} +11 -13
- package/dist/adapters/next/index.d.mts +26 -0
- package/dist/adapters/next/index.d.ts +26 -0
- package/dist/{next.js → adapters/next/index.mjs} +11 -13
- package/dist/adapters/node/index.d.mts +34 -0
- package/dist/adapters/node/index.d.ts +34 -0
- package/dist/adapters/node/index.mjs +31 -0
- package/dist/adapters/standard/index.d.mts +25 -0
- package/dist/adapters/standard/index.d.ts +25 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/{index.js → index.mjs} +60 -134
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/{chunk-WQNNSBXW.js → plugins/index.mjs} +11 -28
- package/dist/shared/server.BZRSVRDu.d.ts +77 -0
- package/dist/shared/server.CPteJIPP.d.mts +143 -0
- package/dist/shared/server.CPteJIPP.d.ts +143 -0
- package/dist/shared/server.CXu_v2vM.mjs +28 -0
- package/dist/{chunk-77FU7QSO.js → shared/server.N2ttmv6r.mjs} +22 -45
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.iM8li30u.d.mts +77 -0
- package/dist/{chunk-MHVECKBC.js → shared/server.kPUGzsdw.mjs} +146 -210
- package/package.json +29 -34
- package/dist/chunk-47YYO5JS.js +0 -32
- package/dist/fetch.js +0 -10
- package/dist/node.js +0 -31
- package/dist/plugins.js +0 -11
- package/dist/src/adapters/fetch/index.d.ts +0 -3
- package/dist/src/adapters/fetch/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/fetch/types.d.ts +0 -14
- package/dist/src/adapters/hono/index.d.ts +0 -3
- package/dist/src/adapters/hono/middleware.d.ts +0 -12
- package/dist/src/adapters/next/index.d.ts +0 -3
- package/dist/src/adapters/next/serve.d.ts +0 -19
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/rpc-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -22
- package/dist/src/adapters/standard/handler.d.ts +0 -53
- package/dist/src/adapters/standard/index.d.ts +0 -6
- package/dist/src/adapters/standard/rpc-codec.d.ts +0 -16
- package/dist/src/adapters/standard/rpc-handler.d.ts +0 -8
- package/dist/src/adapters/standard/rpc-matcher.d.ts +0 -10
- package/dist/src/adapters/standard/types.d.ts +0 -21
- package/dist/src/builder-variants.d.ts +0 -75
- package/dist/src/builder.d.ts +0 -58
- package/dist/src/config.d.ts +0 -6
- package/dist/src/context.d.ts +0 -8
- package/dist/src/error.d.ts +0 -12
- package/dist/src/hidden.d.ts +0 -8
- package/dist/src/implementer-procedure.d.ts +0 -33
- package/dist/src/implementer-variants.d.ts +0 -18
- package/dist/src/implementer.d.ts +0 -29
- package/dist/src/index.d.ts +0 -25
- package/dist/src/lazy-utils.d.ts +0 -6
- package/dist/src/lazy.d.ts +0 -22
- package/dist/src/middleware-decorated.d.ts +0 -11
- package/dist/src/middleware-utils.d.ts +0 -5
- package/dist/src/middleware.d.ts +0 -38
- package/dist/src/plugins/base.d.ts +0 -11
- package/dist/src/plugins/cors.d.ts +0 -19
- package/dist/src/plugins/index.d.ts +0 -4
- package/dist/src/plugins/response-headers.d.ts +0 -10
- package/dist/src/procedure-client.d.ts +0 -33
- package/dist/src/procedure-decorated.d.ts +0 -24
- package/dist/src/procedure-utils.d.ts +0 -19
- package/dist/src/procedure.d.ts +0 -31
- package/dist/src/router-accessible-lazy.d.ts +0 -8
- package/dist/src/router-client.d.ts +0 -12
- package/dist/src/router.d.ts +0 -30
- package/dist/src/utils.d.ts +0 -24
- package/dist/standard.js +0 -13
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
|
2
|
+
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
|
3
|
+
import { value, intercept, toError } from '@orpc/shared';
|
|
4
|
+
|
|
5
|
+
const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
|
|
6
|
+
function lazy(loader, meta = {}) {
|
|
4
7
|
return {
|
|
5
|
-
[
|
|
8
|
+
[LAZY_SYMBOL]: {
|
|
9
|
+
loader,
|
|
10
|
+
meta
|
|
11
|
+
}
|
|
6
12
|
};
|
|
7
13
|
}
|
|
8
14
|
function isLazy(item) {
|
|
9
|
-
return (typeof item === "object" || typeof item === "function") && item !== null &&
|
|
15
|
+
return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_SYMBOL in item;
|
|
16
|
+
}
|
|
17
|
+
function getLazyMeta(lazied) {
|
|
18
|
+
return lazied[LAZY_SYMBOL].meta;
|
|
10
19
|
}
|
|
11
20
|
function unlazy(lazied) {
|
|
12
|
-
return isLazy(lazied) ? lazied[
|
|
21
|
+
return isLazy(lazied) ? lazied[LAZY_SYMBOL].loader() : Promise.resolve({ default: lazied });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function dedupeMiddlewares(compare, middlewares) {
|
|
25
|
+
let min = 0;
|
|
26
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
27
|
+
const index = compare.indexOf(middlewares[i], min);
|
|
28
|
+
if (index === -1) {
|
|
29
|
+
return middlewares.slice(i);
|
|
30
|
+
}
|
|
31
|
+
min = index + 1;
|
|
32
|
+
}
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
function mergeMiddlewares(first, second) {
|
|
36
|
+
return [...first, ...dedupeMiddlewares(first, second)];
|
|
37
|
+
}
|
|
38
|
+
function addMiddleware(middlewares, addition) {
|
|
39
|
+
return [...middlewares, addition];
|
|
13
40
|
}
|
|
14
41
|
|
|
15
|
-
|
|
16
|
-
import { isContractProcedure } from "@orpc/contract";
|
|
17
|
-
var Procedure = class {
|
|
42
|
+
class Procedure {
|
|
18
43
|
"~orpc";
|
|
19
44
|
constructor(def) {
|
|
20
45
|
this["~orpc"] = def;
|
|
21
46
|
}
|
|
22
|
-
}
|
|
47
|
+
}
|
|
23
48
|
function isProcedure(item) {
|
|
24
49
|
if (item instanceof Procedure) {
|
|
25
50
|
return true;
|
|
@@ -27,47 +52,6 @@ function isProcedure(item) {
|
|
|
27
52
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
|
28
53
|
}
|
|
29
54
|
|
|
30
|
-
// src/lazy-utils.ts
|
|
31
|
-
function flatLazy(lazied) {
|
|
32
|
-
const flattenLoader = async () => {
|
|
33
|
-
let current = await unlazy(lazied);
|
|
34
|
-
while (true) {
|
|
35
|
-
if (!isLazy(current.default)) {
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
current = await unlazy(current.default);
|
|
39
|
-
}
|
|
40
|
-
return current;
|
|
41
|
-
};
|
|
42
|
-
return lazy(flattenLoader);
|
|
43
|
-
}
|
|
44
|
-
function createLazyProcedureFormAnyLazy(lazied) {
|
|
45
|
-
const lazyProcedure = lazy(async () => {
|
|
46
|
-
const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
|
|
47
|
-
if (!isProcedure(maybeProcedure)) {
|
|
48
|
-
throw new Error(`
|
|
49
|
-
Expected a lazy<procedure> but got lazy<unknown>.
|
|
50
|
-
This should be caught by TypeScript compilation.
|
|
51
|
-
Please report this issue if this makes you feel uncomfortable.
|
|
52
|
-
`);
|
|
53
|
-
}
|
|
54
|
-
return { default: maybeProcedure };
|
|
55
|
-
});
|
|
56
|
-
return lazyProcedure;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/middleware.ts
|
|
60
|
-
function middlewareOutputFn(output) {
|
|
61
|
-
return { output, context: {} };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// src/procedure-client.ts
|
|
65
|
-
import { ORPCError as ORPCError2 } from "@orpc/client";
|
|
66
|
-
import { ValidationError } from "@orpc/contract";
|
|
67
|
-
import { intercept, toError, value } from "@orpc/shared";
|
|
68
|
-
|
|
69
|
-
// src/error.ts
|
|
70
|
-
import { fallbackORPCErrorStatus, ORPCError } from "@orpc/client";
|
|
71
55
|
function createORPCErrorConstructorMap(errors) {
|
|
72
56
|
const proxy = new Proxy(errors, {
|
|
73
57
|
get(target, code) {
|
|
@@ -105,7 +89,10 @@ async function validateORPCError(map, error) {
|
|
|
105
89
|
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
|
106
90
|
}
|
|
107
91
|
|
|
108
|
-
|
|
92
|
+
function middlewareOutputFn(output) {
|
|
93
|
+
return { output, context: {} };
|
|
94
|
+
}
|
|
95
|
+
|
|
109
96
|
function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
110
97
|
return async (...[input, callerOptions]) => {
|
|
111
98
|
const path = options?.path ?? [];
|
|
@@ -129,7 +116,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
|
129
116
|
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
|
130
117
|
);
|
|
131
118
|
} catch (e) {
|
|
132
|
-
if (!(e instanceof
|
|
119
|
+
if (!(e instanceof ORPCError)) {
|
|
133
120
|
throw toError(e);
|
|
134
121
|
}
|
|
135
122
|
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
|
@@ -144,7 +131,7 @@ async function validateInput(procedure, input) {
|
|
|
144
131
|
}
|
|
145
132
|
const result = await schema["~standard"].validate(input);
|
|
146
133
|
if (result.issues) {
|
|
147
|
-
throw new
|
|
134
|
+
throw new ORPCError("BAD_REQUEST", {
|
|
148
135
|
message: "Input validation failed",
|
|
149
136
|
data: {
|
|
150
137
|
issues: result.issues
|
|
@@ -161,7 +148,7 @@ async function validateOutput(procedure, output) {
|
|
|
161
148
|
}
|
|
162
149
|
const result = await schema["~standard"].validate(output);
|
|
163
150
|
if (result.issues) {
|
|
164
|
-
throw new
|
|
151
|
+
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
|
165
152
|
message: "Output validation failed",
|
|
166
153
|
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
|
167
154
|
});
|
|
@@ -196,98 +183,22 @@ async function executeProcedureInternal(procedure, options) {
|
|
|
196
183
|
return (await next({})).output;
|
|
197
184
|
}
|
|
198
185
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return new Proxy(obj, {
|
|
186
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
|
187
|
+
function setHiddenRouterContract(router, contract) {
|
|
188
|
+
return new Proxy(router, {
|
|
203
189
|
get(target, key) {
|
|
204
|
-
if (key ===
|
|
190
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
|
205
191
|
return contract;
|
|
206
192
|
}
|
|
207
193
|
return Reflect.get(target, key);
|
|
208
194
|
}
|
|
209
195
|
});
|
|
210
196
|
}
|
|
211
|
-
function
|
|
212
|
-
return
|
|
213
|
-
}
|
|
214
|
-
var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
|
|
215
|
-
function deepSetLazyRouterPrefix(router, prefix) {
|
|
216
|
-
return new Proxy(router, {
|
|
217
|
-
get(target, key) {
|
|
218
|
-
if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
|
|
219
|
-
const val = Reflect.get(target, key);
|
|
220
|
-
if (isLazy(val)) {
|
|
221
|
-
return deepSetLazyRouterPrefix(val, prefix);
|
|
222
|
-
}
|
|
223
|
-
return val;
|
|
224
|
-
}
|
|
225
|
-
return prefix;
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
function getLazyRouterPrefix(obj) {
|
|
230
|
-
return obj[LAZY_ROUTER_PREFIX_SYMBOL];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/router.ts
|
|
234
|
-
import { adaptRoute, mergeErrorMap, mergePrefix } from "@orpc/contract";
|
|
235
|
-
|
|
236
|
-
// src/middleware-utils.ts
|
|
237
|
-
function dedupeMiddlewares(compare, middlewares) {
|
|
238
|
-
let min = 0;
|
|
239
|
-
for (let i = 0; i < middlewares.length; i++) {
|
|
240
|
-
const index = compare.indexOf(middlewares[i], min);
|
|
241
|
-
if (index === -1) {
|
|
242
|
-
return middlewares.slice(i);
|
|
243
|
-
}
|
|
244
|
-
min = index + 1;
|
|
245
|
-
}
|
|
246
|
-
return [];
|
|
247
|
-
}
|
|
248
|
-
function mergeMiddlewares(first, second) {
|
|
249
|
-
return [...first, ...dedupeMiddlewares(first, second)];
|
|
250
|
-
}
|
|
251
|
-
function addMiddleware(middlewares, addition) {
|
|
252
|
-
return [...middlewares, addition];
|
|
197
|
+
function getHiddenRouterContract(router) {
|
|
198
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
|
253
199
|
}
|
|
254
200
|
|
|
255
|
-
|
|
256
|
-
function adaptRouter(router, options) {
|
|
257
|
-
if (isLazy(router)) {
|
|
258
|
-
const adapted2 = lazy(async () => {
|
|
259
|
-
const unlaziedRouter = (await unlazy(router)).default;
|
|
260
|
-
const adapted3 = adaptRouter(unlaziedRouter, options);
|
|
261
|
-
return { default: adapted3 };
|
|
262
|
-
});
|
|
263
|
-
const accessible = createAccessibleLazyRouter(adapted2);
|
|
264
|
-
const currentPrefix = getLazyRouterPrefix(router);
|
|
265
|
-
const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
|
|
266
|
-
if (prefix) {
|
|
267
|
-
return deepSetLazyRouterPrefix(accessible, prefix);
|
|
268
|
-
}
|
|
269
|
-
return accessible;
|
|
270
|
-
}
|
|
271
|
-
if (isProcedure(router)) {
|
|
272
|
-
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
|
273
|
-
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
274
|
-
const adapted2 = new Procedure({
|
|
275
|
-
...router["~orpc"],
|
|
276
|
-
route: adaptRoute(router["~orpc"].route, options),
|
|
277
|
-
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
278
|
-
middlewares: newMiddlewares,
|
|
279
|
-
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
280
|
-
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
281
|
-
});
|
|
282
|
-
return adapted2;
|
|
283
|
-
}
|
|
284
|
-
const adapted = {};
|
|
285
|
-
for (const key in router) {
|
|
286
|
-
adapted[key] = adaptRouter(router[key], options);
|
|
287
|
-
}
|
|
288
|
-
return adapted;
|
|
289
|
-
}
|
|
290
|
-
function getRouterChild(router, ...path) {
|
|
201
|
+
function getRouter(router, path) {
|
|
291
202
|
let current = router;
|
|
292
203
|
for (let i = 0; i < path.length; i++) {
|
|
293
204
|
const segment = path[i];
|
|
@@ -303,89 +214,131 @@ function getRouterChild(router, ...path) {
|
|
|
303
214
|
}
|
|
304
215
|
const lazied = current;
|
|
305
216
|
const rest = path.slice(i);
|
|
306
|
-
|
|
217
|
+
return lazy(async () => {
|
|
307
218
|
const unwrapped = await unlazy(lazied);
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
|
312
|
-
return { default: next };
|
|
313
|
-
});
|
|
314
|
-
return flatLazy(newLazy);
|
|
219
|
+
const next = getRouter(unwrapped.default, rest);
|
|
220
|
+
return unlazy(next);
|
|
221
|
+
}, getLazyMeta(lazied));
|
|
315
222
|
}
|
|
316
223
|
return current;
|
|
317
224
|
}
|
|
318
|
-
|
|
319
|
-
// src/router-accessible-lazy.ts
|
|
320
225
|
function createAccessibleLazyRouter(lazied) {
|
|
321
|
-
const
|
|
322
|
-
const recursive = new Proxy(flattenLazy, {
|
|
226
|
+
const recursive = new Proxy(lazied, {
|
|
323
227
|
get(target, key) {
|
|
324
228
|
if (typeof key !== "string") {
|
|
325
229
|
return Reflect.get(target, key);
|
|
326
230
|
}
|
|
327
|
-
const next =
|
|
231
|
+
const next = getRouter(lazied, [key]);
|
|
328
232
|
return createAccessibleLazyRouter(next);
|
|
329
233
|
}
|
|
330
234
|
});
|
|
331
235
|
return recursive;
|
|
332
236
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
237
|
+
function enhanceRouter(router, options) {
|
|
238
|
+
if (isLazy(router)) {
|
|
239
|
+
const laziedMeta = getLazyMeta(router);
|
|
240
|
+
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
|
241
|
+
const enhanced2 = lazy(async () => {
|
|
242
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
|
243
|
+
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
|
244
|
+
return unlazy(enhanced3);
|
|
245
|
+
}, {
|
|
246
|
+
...laziedMeta,
|
|
247
|
+
prefix: enhancedPrefix
|
|
248
|
+
});
|
|
249
|
+
const accessible = createAccessibleLazyRouter(enhanced2);
|
|
250
|
+
return accessible;
|
|
251
|
+
}
|
|
252
|
+
if (isProcedure(router)) {
|
|
253
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
|
|
254
|
+
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
|
255
|
+
const enhanced2 = new Procedure({
|
|
256
|
+
...router["~orpc"],
|
|
257
|
+
route: enhanceRoute(router["~orpc"].route, options),
|
|
258
|
+
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
|
259
|
+
middlewares: newMiddlewares,
|
|
260
|
+
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
|
261
|
+
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
|
262
|
+
});
|
|
263
|
+
return enhanced2;
|
|
347
264
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
265
|
+
const enhanced = {};
|
|
266
|
+
for (const key in router) {
|
|
267
|
+
enhanced[key] = enhanceRouter(router[key], options);
|
|
268
|
+
}
|
|
269
|
+
return enhanced;
|
|
270
|
+
}
|
|
271
|
+
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
|
272
|
+
let currentRouter = options.router;
|
|
273
|
+
const hiddenContract = getHiddenRouterContract(options.router);
|
|
274
|
+
if (hiddenContract !== void 0) {
|
|
275
|
+
currentRouter = hiddenContract;
|
|
276
|
+
}
|
|
277
|
+
if (isLazy(currentRouter)) {
|
|
278
|
+
lazyOptions.push({
|
|
279
|
+
router: currentRouter,
|
|
351
280
|
path: options.path
|
|
352
281
|
});
|
|
353
|
-
} else if (
|
|
282
|
+
} else if (isContractProcedure(currentRouter)) {
|
|
354
283
|
callback({
|
|
355
|
-
contract:
|
|
284
|
+
contract: currentRouter,
|
|
356
285
|
path: options.path
|
|
357
286
|
});
|
|
358
287
|
} else {
|
|
359
|
-
for (const key in
|
|
360
|
-
|
|
288
|
+
for (const key in currentRouter) {
|
|
289
|
+
traverseContractProcedures(
|
|
361
290
|
{
|
|
362
|
-
router:
|
|
291
|
+
router: currentRouter[key],
|
|
363
292
|
path: [...options.path, key]
|
|
364
293
|
},
|
|
365
294
|
callback,
|
|
366
|
-
|
|
295
|
+
lazyOptions
|
|
367
296
|
);
|
|
368
297
|
}
|
|
369
298
|
}
|
|
370
|
-
return
|
|
299
|
+
return lazyOptions;
|
|
371
300
|
}
|
|
372
|
-
async function
|
|
301
|
+
async function resolveContractProcedures(options, callback) {
|
|
373
302
|
const pending = [options];
|
|
374
|
-
for (const
|
|
375
|
-
const
|
|
376
|
-
for (const
|
|
377
|
-
const { default: router } = await unlazy(
|
|
303
|
+
for (const options2 of pending) {
|
|
304
|
+
const lazyOptions = traverseContractProcedures(options2, callback);
|
|
305
|
+
for (const options3 of lazyOptions) {
|
|
306
|
+
const { default: router } = await unlazy(options3.router);
|
|
378
307
|
pending.push({
|
|
379
|
-
|
|
380
|
-
|
|
308
|
+
router,
|
|
309
|
+
path: options3.path
|
|
381
310
|
});
|
|
382
311
|
}
|
|
383
312
|
}
|
|
384
313
|
}
|
|
385
|
-
function
|
|
386
|
-
|
|
314
|
+
async function unlazyRouter(router) {
|
|
315
|
+
if (isProcedure(router)) {
|
|
316
|
+
return router;
|
|
317
|
+
}
|
|
318
|
+
const unlazied = {};
|
|
319
|
+
for (const key in router) {
|
|
320
|
+
const item = router[key];
|
|
321
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
|
322
|
+
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
|
323
|
+
}
|
|
324
|
+
return unlazied;
|
|
387
325
|
}
|
|
388
|
-
|
|
326
|
+
|
|
327
|
+
function createAssertedLazyProcedure(lazied) {
|
|
328
|
+
const lazyProcedure = lazy(async () => {
|
|
329
|
+
const { default: maybeProcedure } = await unlazy(lazied);
|
|
330
|
+
if (!isProcedure(maybeProcedure)) {
|
|
331
|
+
throw new Error(`
|
|
332
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
|
333
|
+
This should be caught by TypeScript compilation.
|
|
334
|
+
Please report this issue if this makes you feel uncomfortable.
|
|
335
|
+
`);
|
|
336
|
+
}
|
|
337
|
+
return { default: maybeProcedure };
|
|
338
|
+
}, getLazyMeta(lazied));
|
|
339
|
+
return lazyProcedure;
|
|
340
|
+
}
|
|
341
|
+
function createContractedProcedure(procedure, contract) {
|
|
389
342
|
return new Procedure({
|
|
390
343
|
...procedure["~orpc"],
|
|
391
344
|
errorMap: contract["~orpc"].errorMap,
|
|
@@ -393,29 +346,12 @@ function createContractedProcedure(contract, procedure) {
|
|
|
393
346
|
meta: contract["~orpc"].meta
|
|
394
347
|
});
|
|
395
348
|
}
|
|
349
|
+
function call(procedure, input, ...rest) {
|
|
350
|
+
return createProcedureClient(procedure, ...rest)(input);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function toHttpPath(path) {
|
|
354
|
+
return `/${path.map(encodeURIComponent).join("/")}`;
|
|
355
|
+
}
|
|
396
356
|
|
|
397
|
-
export {
|
|
398
|
-
LAZY_LOADER_SYMBOL,
|
|
399
|
-
lazy,
|
|
400
|
-
isLazy,
|
|
401
|
-
unlazy,
|
|
402
|
-
Procedure,
|
|
403
|
-
isProcedure,
|
|
404
|
-
flatLazy,
|
|
405
|
-
createLazyProcedureFormAnyLazy,
|
|
406
|
-
addMiddleware,
|
|
407
|
-
middlewareOutputFn,
|
|
408
|
-
createProcedureClient,
|
|
409
|
-
setRouterContract,
|
|
410
|
-
getRouterContract,
|
|
411
|
-
deepSetLazyRouterPrefix,
|
|
412
|
-
getLazyRouterPrefix,
|
|
413
|
-
createAccessibleLazyRouter,
|
|
414
|
-
adaptRouter,
|
|
415
|
-
getRouterChild,
|
|
416
|
-
eachContractProcedure,
|
|
417
|
-
eachAllContractProcedure,
|
|
418
|
-
convertPathToHttpPath,
|
|
419
|
-
createContractedProcedure
|
|
420
|
-
};
|
|
421
|
-
//# sourceMappingURL=chunk-MHVECKBC.js.map
|
|
357
|
+
export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, getLazyMeta as j, call as k, lazy as l, middlewareOutputFn as m, getHiddenRouterContract as n, createAccessibleLazyRouter as o, unlazyRouter as p, resolveContractProcedures as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.6c5bfe4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -15,47 +15,42 @@
|
|
|
15
15
|
],
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types": "./dist/
|
|
19
|
-
"import": "./dist/index.
|
|
20
|
-
"default": "./dist/index.
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
21
|
},
|
|
22
22
|
"./plugins": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"import": "./dist/plugins.
|
|
25
|
-
"default": "./dist/plugins.
|
|
23
|
+
"types": "./dist/plugins/index.d.mts",
|
|
24
|
+
"import": "./dist/plugins/index.mjs",
|
|
25
|
+
"default": "./dist/plugins/index.mjs"
|
|
26
26
|
},
|
|
27
27
|
"./standard": {
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/standard.
|
|
30
|
-
"default": "./dist/standard.
|
|
28
|
+
"types": "./dist/adapters/standard/index.d.mts",
|
|
29
|
+
"import": "./dist/adapters/standard/index.mjs",
|
|
30
|
+
"default": "./dist/adapters/standard/index.mjs"
|
|
31
31
|
},
|
|
32
32
|
"./fetch": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"import": "./dist/fetch.
|
|
35
|
-
"default": "./dist/fetch.
|
|
33
|
+
"types": "./dist/adapters/fetch/index.d.mts",
|
|
34
|
+
"import": "./dist/adapters/fetch/index.mjs",
|
|
35
|
+
"default": "./dist/adapters/fetch/index.mjs"
|
|
36
36
|
},
|
|
37
37
|
"./hono": {
|
|
38
|
-
"types": "./dist/
|
|
39
|
-
"import": "./dist/hono.
|
|
40
|
-
"default": "./dist/hono.
|
|
38
|
+
"types": "./dist/adapters/hono/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/hono/index.mjs",
|
|
40
|
+
"default": "./dist/adapters/hono/index.mjs"
|
|
41
41
|
},
|
|
42
42
|
"./next": {
|
|
43
|
-
"types": "./dist/
|
|
44
|
-
"import": "./dist/next.
|
|
45
|
-
"default": "./dist/next.
|
|
43
|
+
"types": "./dist/adapters/next/index.d.mts",
|
|
44
|
+
"import": "./dist/adapters/next/index.mjs",
|
|
45
|
+
"default": "./dist/adapters/next/index.mjs"
|
|
46
46
|
},
|
|
47
47
|
"./node": {
|
|
48
|
-
"types": "./dist/
|
|
49
|
-
"import": "./dist/node.
|
|
50
|
-
"default": "./dist/node.
|
|
51
|
-
},
|
|
52
|
-
"./🔒/*": {
|
|
53
|
-
"types": "./dist/src/*.d.ts"
|
|
48
|
+
"types": "./dist/adapters/node/index.d.mts",
|
|
49
|
+
"import": "./dist/adapters/node/index.mjs",
|
|
50
|
+
"default": "./dist/adapters/node/index.mjs"
|
|
54
51
|
}
|
|
55
52
|
},
|
|
56
53
|
"files": [
|
|
57
|
-
"!**/*.map",
|
|
58
|
-
"!**/*.tsbuildinfo",
|
|
59
54
|
"dist"
|
|
60
55
|
],
|
|
61
56
|
"peerDependencies": {
|
|
@@ -63,18 +58,18 @@
|
|
|
63
58
|
"next": ">=14.0.0"
|
|
64
59
|
},
|
|
65
60
|
"dependencies": {
|
|
66
|
-
"@orpc/
|
|
67
|
-
"@orpc/
|
|
68
|
-
"@orpc/
|
|
69
|
-
"@orpc/
|
|
70
|
-
"@orpc/
|
|
71
|
-
"@orpc/
|
|
61
|
+
"@orpc/client": "0.0.0-next.6c5bfe4",
|
|
62
|
+
"@orpc/contract": "0.0.0-next.6c5bfe4",
|
|
63
|
+
"@orpc/standard-server": "0.0.0-next.6c5bfe4",
|
|
64
|
+
"@orpc/shared": "0.0.0-next.6c5bfe4",
|
|
65
|
+
"@orpc/standard-server-node": "0.0.0-next.6c5bfe4",
|
|
66
|
+
"@orpc/standard-server-fetch": "0.0.0-next.6c5bfe4"
|
|
72
67
|
},
|
|
73
68
|
"devDependencies": {
|
|
74
69
|
"light-my-request": "^6.5.1"
|
|
75
70
|
},
|
|
76
71
|
"scripts": {
|
|
77
|
-
"build": "
|
|
72
|
+
"build": "unbuild",
|
|
78
73
|
"build:watch": "pnpm run build --watch",
|
|
79
74
|
"type:check": "tsc -b"
|
|
80
75
|
}
|
package/dist/chunk-47YYO5JS.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RPCCodec,
|
|
3
|
-
RPCMatcher,
|
|
4
|
-
StandardHandler
|
|
5
|
-
} from "./chunk-77FU7QSO.js";
|
|
6
|
-
|
|
7
|
-
// src/adapters/fetch/rpc-handler.ts
|
|
8
|
-
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
|
9
|
-
var RPCHandler = class {
|
|
10
|
-
standardHandler;
|
|
11
|
-
constructor(router, options) {
|
|
12
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
|
13
|
-
const codec = options?.codec ?? new RPCCodec();
|
|
14
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
15
|
-
}
|
|
16
|
-
async handle(request, ...rest) {
|
|
17
|
-
const standardRequest = toStandardRequest(request);
|
|
18
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
19
|
-
if (!result.matched) {
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
matched: true,
|
|
24
|
-
response: toFetchResponse(result.response)
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
RPCHandler
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=chunk-47YYO5JS.js.map
|
package/dist/fetch.js
DELETED
package/dist/node.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RPCCodec,
|
|
3
|
-
RPCMatcher,
|
|
4
|
-
StandardHandler
|
|
5
|
-
} from "./chunk-77FU7QSO.js";
|
|
6
|
-
import "./chunk-MHVECKBC.js";
|
|
7
|
-
import "./chunk-WQNNSBXW.js";
|
|
8
|
-
|
|
9
|
-
// src/adapters/node/rpc-handler.ts
|
|
10
|
-
import { sendStandardResponse, toStandardRequest } from "@orpc/server-standard-node";
|
|
11
|
-
var RPCHandler = class {
|
|
12
|
-
standardHandler;
|
|
13
|
-
constructor(router, options) {
|
|
14
|
-
const codec = options?.codec ?? new RPCCodec();
|
|
15
|
-
const matcher = options?.matcher ?? new RPCMatcher();
|
|
16
|
-
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
17
|
-
}
|
|
18
|
-
async handle(req, res, ...rest) {
|
|
19
|
-
const standardRequest = toStandardRequest(req, res);
|
|
20
|
-
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
21
|
-
if (!result.matched) {
|
|
22
|
-
return { matched: false };
|
|
23
|
-
}
|
|
24
|
-
await sendStandardResponse(res, result.response);
|
|
25
|
-
return { matched: true };
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export {
|
|
29
|
-
RPCHandler
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=node.js.map
|
package/dist/plugins.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { MaybeOptionalOptions } from '@orpc/shared';
|
|
2
|
-
import type { Context } from '../../context';
|
|
3
|
-
import type { Router } from '../../router';
|
|
4
|
-
import type { RPCHandlerOptions, StandardHandleOptions } from '../standard';
|
|
5
|
-
import type { FetchHandler, FetchHandleResult } from './types';
|
|
6
|
-
export declare class RPCHandler<T extends Context> implements FetchHandler<T> {
|
|
7
|
-
private readonly standardHandler;
|
|
8
|
-
constructor(router: Router<T, any>, options?: NoInfer<RPCHandlerOptions<T>>);
|
|
9
|
-
handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=rpc-handler.d.ts.map
|