@orpc/server 0.0.0-next.fea68c1 → 0.0.0-next.ff68fdb
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 +4 -2
- 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 +278 -0
- package/dist/index.d.ts +278 -0
- package/dist/{index.js → index.mjs} +85 -152
- package/dist/plugins/index.d.mts +31 -0
- package/dist/plugins/index.d.ts +31 -0
- package/dist/{chunk-TXHKQO7N.js → plugins/index.mjs} +12 -29
- package/dist/{chunk-NTHCS5CK.js → shared/server.3mOimouH.mjs} +21 -45
- package/dist/{chunk-MHVECKBC.js → shared/server.B_5ZADvP.mjs} +152 -210
- package/dist/shared/server.BgDZnmUZ.mjs +28 -0
- package/dist/shared/server.CL84X8p4.d.mts +75 -0
- package/dist/shared/server.DnmJuN02.d.mts +144 -0
- package/dist/shared/server.DnmJuN02.d.ts +144 -0
- package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
- package/dist/shared/server.hqPWnakL.d.ts +75 -0
- package/package.json +29 -34
- package/dist/chunk-MBMXGUNI.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,56 @@
|
|
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 isStartWithMiddlewares(middlewares, compare) {
|
25
|
+
if (compare.length > middlewares.length) {
|
26
|
+
return false;
|
27
|
+
}
|
28
|
+
for (let i = 0; i < middlewares.length; i++) {
|
29
|
+
if (compare[i] === void 0) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (middlewares[i] !== compare[i]) {
|
33
|
+
return false;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
function mergeMiddlewares(first, second, options) {
|
39
|
+
if (options.dedupeLeading && isStartWithMiddlewares(second, first)) {
|
40
|
+
return second;
|
41
|
+
}
|
42
|
+
return [...first, ...second];
|
43
|
+
}
|
44
|
+
function addMiddleware(middlewares, addition) {
|
45
|
+
return [...middlewares, addition];
|
13
46
|
}
|
14
47
|
|
15
|
-
|
16
|
-
import { isContractProcedure } from "@orpc/contract";
|
17
|
-
var Procedure = class {
|
48
|
+
class Procedure {
|
18
49
|
"~orpc";
|
19
50
|
constructor(def) {
|
20
51
|
this["~orpc"] = def;
|
21
52
|
}
|
22
|
-
}
|
53
|
+
}
|
23
54
|
function isProcedure(item) {
|
24
55
|
if (item instanceof Procedure) {
|
25
56
|
return true;
|
@@ -27,47 +58,6 @@ function isProcedure(item) {
|
|
27
58
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
28
59
|
}
|
29
60
|
|
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
61
|
function createORPCErrorConstructorMap(errors) {
|
72
62
|
const proxy = new Proxy(errors, {
|
73
63
|
get(target, code) {
|
@@ -105,7 +95,10 @@ async function validateORPCError(map, error) {
|
|
105
95
|
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
106
96
|
}
|
107
97
|
|
108
|
-
|
98
|
+
function middlewareOutputFn(output) {
|
99
|
+
return { output, context: {} };
|
100
|
+
}
|
101
|
+
|
109
102
|
function createProcedureClient(lazyableProcedure, ...[options]) {
|
110
103
|
return async (...[input, callerOptions]) => {
|
111
104
|
const path = options?.path ?? [];
|
@@ -129,7 +122,7 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
129
122
|
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
130
123
|
);
|
131
124
|
} catch (e) {
|
132
|
-
if (!(e instanceof
|
125
|
+
if (!(e instanceof ORPCError)) {
|
133
126
|
throw toError(e);
|
134
127
|
}
|
135
128
|
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
@@ -144,7 +137,7 @@ async function validateInput(procedure, input) {
|
|
144
137
|
}
|
145
138
|
const result = await schema["~standard"].validate(input);
|
146
139
|
if (result.issues) {
|
147
|
-
throw new
|
140
|
+
throw new ORPCError("BAD_REQUEST", {
|
148
141
|
message: "Input validation failed",
|
149
142
|
data: {
|
150
143
|
issues: result.issues
|
@@ -161,7 +154,7 @@ async function validateOutput(procedure, output) {
|
|
161
154
|
}
|
162
155
|
const result = await schema["~standard"].validate(output);
|
163
156
|
if (result.issues) {
|
164
|
-
throw new
|
157
|
+
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
165
158
|
message: "Output validation failed",
|
166
159
|
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
167
160
|
});
|
@@ -196,98 +189,22 @@ async function executeProcedureInternal(procedure, options) {
|
|
196
189
|
return (await next({})).output;
|
197
190
|
}
|
198
191
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
return new Proxy(obj, {
|
192
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
193
|
+
function setHiddenRouterContract(router, contract) {
|
194
|
+
return new Proxy(router, {
|
203
195
|
get(target, key) {
|
204
|
-
if (key ===
|
196
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
205
197
|
return contract;
|
206
198
|
}
|
207
199
|
return Reflect.get(target, key);
|
208
200
|
}
|
209
201
|
});
|
210
202
|
}
|
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];
|
203
|
+
function getHiddenRouterContract(router) {
|
204
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
253
205
|
}
|
254
206
|
|
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) {
|
207
|
+
function getRouter(router, path) {
|
291
208
|
let current = router;
|
292
209
|
for (let i = 0; i < path.length; i++) {
|
293
210
|
const segment = path[i];
|
@@ -303,89 +220,131 @@ function getRouterChild(router, ...path) {
|
|
303
220
|
}
|
304
221
|
const lazied = current;
|
305
222
|
const rest = path.slice(i);
|
306
|
-
|
223
|
+
return lazy(async () => {
|
307
224
|
const unwrapped = await unlazy(lazied);
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
312
|
-
return { default: next };
|
313
|
-
});
|
314
|
-
return flatLazy(newLazy);
|
225
|
+
const next = getRouter(unwrapped.default, rest);
|
226
|
+
return unlazy(next);
|
227
|
+
}, getLazyMeta(lazied));
|
315
228
|
}
|
316
229
|
return current;
|
317
230
|
}
|
318
|
-
|
319
|
-
// src/router-accessible-lazy.ts
|
320
231
|
function createAccessibleLazyRouter(lazied) {
|
321
|
-
const
|
322
|
-
const recursive = new Proxy(flattenLazy, {
|
232
|
+
const recursive = new Proxy(lazied, {
|
323
233
|
get(target, key) {
|
324
234
|
if (typeof key !== "string") {
|
325
235
|
return Reflect.get(target, key);
|
326
236
|
}
|
327
|
-
const next =
|
237
|
+
const next = getRouter(lazied, [key]);
|
328
238
|
return createAccessibleLazyRouter(next);
|
329
239
|
}
|
330
240
|
});
|
331
241
|
return recursive;
|
332
242
|
}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
243
|
+
function enhanceRouter(router, options) {
|
244
|
+
if (isLazy(router)) {
|
245
|
+
const laziedMeta = getLazyMeta(router);
|
246
|
+
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
247
|
+
const enhanced2 = lazy(async () => {
|
248
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
249
|
+
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
250
|
+
return unlazy(enhanced3);
|
251
|
+
}, {
|
252
|
+
...laziedMeta,
|
253
|
+
prefix: enhancedPrefix
|
254
|
+
});
|
255
|
+
const accessible = createAccessibleLazyRouter(enhanced2);
|
256
|
+
return accessible;
|
347
257
|
}
|
348
|
-
if (
|
349
|
-
|
350
|
-
|
258
|
+
if (isProcedure(router)) {
|
259
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
|
260
|
+
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
261
|
+
const enhanced2 = new Procedure({
|
262
|
+
...router["~orpc"],
|
263
|
+
route: enhanceRoute(router["~orpc"].route, options),
|
264
|
+
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
265
|
+
middlewares: newMiddlewares,
|
266
|
+
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
267
|
+
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
268
|
+
});
|
269
|
+
return enhanced2;
|
270
|
+
}
|
271
|
+
const enhanced = {};
|
272
|
+
for (const key in router) {
|
273
|
+
enhanced[key] = enhanceRouter(router[key], options);
|
274
|
+
}
|
275
|
+
return enhanced;
|
276
|
+
}
|
277
|
+
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
278
|
+
let currentRouter = options.router;
|
279
|
+
const hiddenContract = getHiddenRouterContract(options.router);
|
280
|
+
if (hiddenContract !== void 0) {
|
281
|
+
currentRouter = hiddenContract;
|
282
|
+
}
|
283
|
+
if (isLazy(currentRouter)) {
|
284
|
+
lazyOptions.push({
|
285
|
+
router: currentRouter,
|
351
286
|
path: options.path
|
352
287
|
});
|
353
|
-
} else if (
|
288
|
+
} else if (isContractProcedure(currentRouter)) {
|
354
289
|
callback({
|
355
|
-
contract:
|
290
|
+
contract: currentRouter,
|
356
291
|
path: options.path
|
357
292
|
});
|
358
293
|
} else {
|
359
|
-
for (const key in
|
360
|
-
|
294
|
+
for (const key in currentRouter) {
|
295
|
+
traverseContractProcedures(
|
361
296
|
{
|
362
|
-
router:
|
297
|
+
router: currentRouter[key],
|
363
298
|
path: [...options.path, key]
|
364
299
|
},
|
365
300
|
callback,
|
366
|
-
|
301
|
+
lazyOptions
|
367
302
|
);
|
368
303
|
}
|
369
304
|
}
|
370
|
-
return
|
305
|
+
return lazyOptions;
|
371
306
|
}
|
372
|
-
async function
|
307
|
+
async function resolveContractProcedures(options, callback) {
|
373
308
|
const pending = [options];
|
374
|
-
for (const
|
375
|
-
const
|
376
|
-
for (const
|
377
|
-
const { default: router } = await unlazy(
|
309
|
+
for (const options2 of pending) {
|
310
|
+
const lazyOptions = traverseContractProcedures(options2, callback);
|
311
|
+
for (const options3 of lazyOptions) {
|
312
|
+
const { default: router } = await unlazy(options3.router);
|
378
313
|
pending.push({
|
379
|
-
|
380
|
-
|
314
|
+
router,
|
315
|
+
path: options3.path
|
381
316
|
});
|
382
317
|
}
|
383
318
|
}
|
384
319
|
}
|
385
|
-
function
|
386
|
-
|
320
|
+
async function unlazyRouter(router) {
|
321
|
+
if (isProcedure(router)) {
|
322
|
+
return router;
|
323
|
+
}
|
324
|
+
const unlazied = {};
|
325
|
+
for (const key in router) {
|
326
|
+
const item = router[key];
|
327
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
328
|
+
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
329
|
+
}
|
330
|
+
return unlazied;
|
387
331
|
}
|
388
|
-
|
332
|
+
|
333
|
+
function createAssertedLazyProcedure(lazied) {
|
334
|
+
const lazyProcedure = lazy(async () => {
|
335
|
+
const { default: maybeProcedure } = await unlazy(lazied);
|
336
|
+
if (!isProcedure(maybeProcedure)) {
|
337
|
+
throw new Error(`
|
338
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
339
|
+
This should be caught by TypeScript compilation.
|
340
|
+
Please report this issue if this makes you feel uncomfortable.
|
341
|
+
`);
|
342
|
+
}
|
343
|
+
return { default: maybeProcedure };
|
344
|
+
}, getLazyMeta(lazied));
|
345
|
+
return lazyProcedure;
|
346
|
+
}
|
347
|
+
function createContractedProcedure(procedure, contract) {
|
389
348
|
return new Procedure({
|
390
349
|
...procedure["~orpc"],
|
391
350
|
errorMap: contract["~orpc"].errorMap,
|
@@ -393,29 +352,12 @@ function createContractedProcedure(contract, procedure) {
|
|
393
352
|
meta: contract["~orpc"].meta
|
394
353
|
});
|
395
354
|
}
|
355
|
+
function call(procedure, input, ...rest) {
|
356
|
+
return createProcedureClient(procedure, ...rest)(input);
|
357
|
+
}
|
358
|
+
|
359
|
+
function toHttpPath(path) {
|
360
|
+
return `/${path.map(encodeURIComponent).join("/")}`;
|
361
|
+
}
|
396
362
|
|
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
|
363
|
+
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, createORPCErrorConstructorMap as j, getLazyMeta as k, lazy as l, middlewareOutputFn as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { RPCSerializer } from '@orpc/client/standard';
|
2
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
3
|
+
import { S as StandardHandler, a as RPCMatcher, R as RPCCodec } from './server.3mOimouH.mjs';
|
4
|
+
|
5
|
+
class RPCHandler {
|
6
|
+
standardHandler;
|
7
|
+
constructor(router, options = {}) {
|
8
|
+
const serializer = new RPCSerializer();
|
9
|
+
const matcher = new RPCMatcher();
|
10
|
+
const codec = new RPCCodec(serializer);
|
11
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
12
|
+
}
|
13
|
+
async handle(request, ...[
|
14
|
+
options = {}
|
15
|
+
]) {
|
16
|
+
const standardRequest = toStandardLazyRequest(request);
|
17
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
18
|
+
if (!result.matched) {
|
19
|
+
return result;
|
20
|
+
}
|
21
|
+
return {
|
22
|
+
matched: true,
|
23
|
+
response: toFetchResponse(result.response, options)
|
24
|
+
};
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
export { RPCHandler as R };
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import { HTTPPath, AnySchema, Meta, InferSchemaOutput, ErrorFromErrorMap } from '@orpc/contract';
|
2
|
+
import { Interceptor, MaybeOptionalOptions } from '@orpc/shared';
|
3
|
+
import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
|
4
|
+
import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DnmJuN02.mjs';
|
5
|
+
import { ORPCError } from '@orpc/client';
|
6
|
+
|
7
|
+
type StandardParams = Record<string, string>;
|
8
|
+
type StandardMatchResult = {
|
9
|
+
path: readonly string[];
|
10
|
+
procedure: AnyProcedure;
|
11
|
+
params?: StandardParams;
|
12
|
+
} | undefined;
|
13
|
+
interface StandardMatcher {
|
14
|
+
init(router: AnyRouter): void;
|
15
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
16
|
+
}
|
17
|
+
interface StandardCodec {
|
18
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
19
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
20
|
+
decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
21
|
+
}
|
22
|
+
|
23
|
+
type StandardHandleOptions<T extends Context> = {
|
24
|
+
prefix?: HTTPPath;
|
25
|
+
} & (Record<never, never> extends T ? {
|
26
|
+
context?: T;
|
27
|
+
} : {
|
28
|
+
context: T;
|
29
|
+
});
|
30
|
+
type StandardHandleResult = {
|
31
|
+
matched: true;
|
32
|
+
response: StandardResponse;
|
33
|
+
} | {
|
34
|
+
matched: false;
|
35
|
+
response: undefined;
|
36
|
+
};
|
37
|
+
type StandardHandlerInterceptorOptions<T extends Context> = StandardHandleOptions<T> & {
|
38
|
+
context: T;
|
39
|
+
request: StandardLazyRequest;
|
40
|
+
};
|
41
|
+
interface StandardHandlerOptions<TContext extends Context> {
|
42
|
+
plugins?: HandlerPlugin<TContext>[];
|
43
|
+
/**
|
44
|
+
* Interceptors at the request level, helpful when you want catch errors
|
45
|
+
*/
|
46
|
+
interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
47
|
+
/**
|
48
|
+
* Interceptors at the root level, helpful when you want override the request/response
|
49
|
+
*/
|
50
|
+
rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, unknown>[];
|
51
|
+
/**
|
52
|
+
*
|
53
|
+
* Interceptors for procedure client.
|
54
|
+
*/
|
55
|
+
clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, AnySchema, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
|
56
|
+
}
|
57
|
+
declare class StandardHandler<T extends Context> {
|
58
|
+
private readonly matcher;
|
59
|
+
private readonly codec;
|
60
|
+
private readonly options;
|
61
|
+
private readonly plugin;
|
62
|
+
constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
|
63
|
+
handle(request: StandardLazyRequest, ...[options]: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<StandardHandleResult>;
|
64
|
+
}
|
65
|
+
|
66
|
+
interface HandlerPlugin<TContext extends Context> {
|
67
|
+
init?(options: StandardHandlerOptions<TContext>): void;
|
68
|
+
}
|
69
|
+
declare class CompositePlugin<TContext extends Context> implements HandlerPlugin<TContext> {
|
70
|
+
private readonly plugins;
|
71
|
+
constructor(plugins?: HandlerPlugin<TContext>[]);
|
72
|
+
init(options: StandardHandlerOptions<TContext>): void;
|
73
|
+
}
|
74
|
+
|
75
|
+
export { CompositePlugin as C, type HandlerPlugin as H, type StandardHandleOptions as S, type StandardHandlerInterceptorOptions as a, type StandardHandlerOptions as b, type StandardCodec as c, type StandardParams as d, type StandardMatcher as e, type StandardMatchResult as f, type StandardHandleResult as g, StandardHandler as h };
|