@orpc/server 0.0.0-next.ca29a36 → 0.0.0-next.cac5dd3
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 +28 -18
- package/dist/adapters/bun-ws/index.d.mts +35 -0
- package/dist/adapters/bun-ws/index.d.ts +35 -0
- package/dist/adapters/bun-ws/index.mjs +51 -0
- package/dist/adapters/crossws/index.d.mts +30 -0
- package/dist/adapters/crossws/index.d.ts +30 -0
- package/dist/adapters/crossws/index.mjs +51 -0
- package/dist/adapters/fetch/index.d.mts +78 -0
- package/dist/adapters/fetch/index.d.ts +78 -0
- package/dist/adapters/fetch/index.mjs +110 -0
- package/dist/adapters/node/index.d.mts +77 -0
- package/dist/adapters/node/index.d.ts +77 -0
- package/dist/adapters/node/index.mjs +95 -0
- package/dist/adapters/standard/index.d.mts +26 -0
- package/dist/adapters/standard/index.d.ts +26 -0
- package/dist/adapters/standard/index.mjs +7 -0
- package/dist/adapters/websocket/index.d.mts +27 -0
- package/dist/adapters/websocket/index.d.ts +27 -0
- package/dist/adapters/websocket/index.mjs +38 -0
- package/dist/adapters/ws/index.d.mts +28 -0
- package/dist/adapters/ws/index.d.ts +28 -0
- package/dist/adapters/ws/index.mjs +38 -0
- package/dist/index.d.mts +829 -0
- package/dist/index.d.ts +829 -0
- package/dist/index.mjs +474 -0
- package/dist/plugins/index.d.mts +156 -0
- package/dist/plugins/index.d.ts +156 -0
- package/dist/plugins/index.mjs +251 -0
- package/dist/shared/server.4FnxLwwr.mjs +186 -0
- package/dist/shared/server.BRoxSiSC.d.mts +12 -0
- package/dist/shared/server.BVwwTHyO.mjs +9 -0
- package/dist/shared/server.BW-nUGgA.mjs +36 -0
- package/dist/shared/server.BjiJH9Vo.d.ts +10 -0
- package/dist/shared/server.Cy1vfSiG.d.ts +12 -0
- package/dist/{chunk-MHVECKBC.js → shared/server.DG7Tamti.mjs} +170 -224
- package/dist/shared/server.DPWk5pjW.d.mts +192 -0
- package/dist/shared/server.DPWk5pjW.d.ts +192 -0
- package/dist/shared/server.QUe9N8P4.d.mts +10 -0
- package/dist/shared/server.YZzrREz9.d.ts +74 -0
- package/dist/shared/server.eWLxY3lq.d.mts +74 -0
- package/package.json +57 -39
- package/dist/chunk-MBMXGUNI.js +0 -32
- package/dist/chunk-NTHCS5CK.js +0 -182
- package/dist/chunk-TXHKQO7N.js +0 -120
- package/dist/fetch.js +0 -10
- package/dist/hono.js +0 -34
- package/dist/index.js +0 -413
- package/dist/next.js +0 -31
- 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,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
|
2
|
+
import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
|
3
|
+
import { value, intercept } 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
|
-
|
17
|
-
|
48
|
+
class Procedure {
|
49
|
+
/**
|
50
|
+
* This property holds the defined options.
|
51
|
+
*/
|
18
52
|
"~orpc";
|
19
53
|
constructor(def) {
|
20
54
|
this["~orpc"] = def;
|
21
55
|
}
|
22
|
-
}
|
56
|
+
}
|
23
57
|
function isProcedure(item) {
|
24
58
|
if (item instanceof Procedure) {
|
25
59
|
return true;
|
@@ -27,47 +61,10 @@ function isProcedure(item) {
|
|
27
61
|
return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
|
28
62
|
}
|
29
63
|
|
30
|
-
|
31
|
-
|
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: {} };
|
64
|
+
function mergeCurrentContext(context, other) {
|
65
|
+
return { ...context, ...other };
|
62
66
|
}
|
63
67
|
|
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
68
|
function createORPCErrorConstructorMap(errors) {
|
72
69
|
const proxy = new Proxy(errors, {
|
73
70
|
get(target, code) {
|
@@ -105,7 +102,10 @@ async function validateORPCError(map, error) {
|
|
105
102
|
return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
|
106
103
|
}
|
107
104
|
|
108
|
-
|
105
|
+
function middlewareOutputFn(output) {
|
106
|
+
return { output, context: {} };
|
107
|
+
}
|
108
|
+
|
109
109
|
function createProcedureClient(lazyableProcedure, ...[options]) {
|
110
110
|
return async (...[input, callerOptions]) => {
|
111
111
|
const path = options?.path ?? [];
|
@@ -129,8 +129,8 @@ function createProcedureClient(lazyableProcedure, ...[options]) {
|
|
129
129
|
(interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
|
130
130
|
);
|
131
131
|
} catch (e) {
|
132
|
-
if (!(e instanceof
|
133
|
-
throw
|
132
|
+
if (!(e instanceof ORPCError)) {
|
133
|
+
throw e;
|
134
134
|
}
|
135
135
|
const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
|
136
136
|
throw validated;
|
@@ -144,7 +144,7 @@ async function validateInput(procedure, input) {
|
|
144
144
|
}
|
145
145
|
const result = await schema["~standard"].validate(input);
|
146
146
|
if (result.issues) {
|
147
|
-
throw new
|
147
|
+
throw new ORPCError("BAD_REQUEST", {
|
148
148
|
message: "Input validation failed",
|
149
149
|
data: {
|
150
150
|
issues: result.issues
|
@@ -161,7 +161,7 @@ async function validateOutput(procedure, output) {
|
|
161
161
|
}
|
162
162
|
const result = await schema["~standard"].validate(output);
|
163
163
|
if (result.issues) {
|
164
|
-
throw new
|
164
|
+
throw new ORPCError("INTERNAL_SERVER_ERROR", {
|
165
165
|
message: "Output validation failed",
|
166
166
|
cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
|
167
167
|
});
|
@@ -172,122 +172,47 @@ async function executeProcedureInternal(procedure, options) {
|
|
172
172
|
const middlewares = procedure["~orpc"].middlewares;
|
173
173
|
const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
|
174
174
|
const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
|
175
|
-
|
176
|
-
|
177
|
-
let currentInput = options.input;
|
178
|
-
const next = async (...[nextOptions]) => {
|
179
|
-
const index = currentIndex;
|
180
|
-
currentIndex += 1;
|
181
|
-
currentContext = { ...currentContext, ...nextOptions?.context };
|
175
|
+
const next = async (index, context, input) => {
|
176
|
+
let currentInput = input;
|
182
177
|
if (index === inputValidationIndex) {
|
183
178
|
currentInput = await validateInput(procedure, currentInput);
|
184
179
|
}
|
185
180
|
const mid = middlewares[index];
|
186
|
-
const
|
181
|
+
const output = mid ? (await mid({
|
182
|
+
...options,
|
183
|
+
context,
|
184
|
+
next: async (...[nextOptions]) => {
|
185
|
+
const nextContext = nextOptions?.context ?? {};
|
186
|
+
return {
|
187
|
+
output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
|
188
|
+
context: nextContext
|
189
|
+
};
|
190
|
+
}
|
191
|
+
}, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
|
187
192
|
if (index === outputValidationIndex) {
|
188
|
-
|
189
|
-
return {
|
190
|
-
...result,
|
191
|
-
output: validatedOutput
|
192
|
-
};
|
193
|
+
return await validateOutput(procedure, output);
|
193
194
|
}
|
194
|
-
return
|
195
|
+
return output;
|
195
196
|
};
|
196
|
-
return (
|
197
|
+
return next(0, options.context, options.input);
|
197
198
|
}
|
198
199
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
return new Proxy(obj, {
|
200
|
+
const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
|
201
|
+
function setHiddenRouterContract(router, contract) {
|
202
|
+
return new Proxy(router, {
|
203
203
|
get(target, key) {
|
204
|
-
if (key ===
|
204
|
+
if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
|
205
205
|
return contract;
|
206
206
|
}
|
207
207
|
return Reflect.get(target, key);
|
208
208
|
}
|
209
209
|
});
|
210
210
|
}
|
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];
|
211
|
+
function getHiddenRouterContract(router) {
|
212
|
+
return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
|
253
213
|
}
|
254
214
|
|
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) {
|
215
|
+
function getRouter(router, path) {
|
291
216
|
let current = router;
|
292
217
|
for (let i = 0; i < path.length; i++) {
|
293
218
|
const segment = path[i];
|
@@ -303,89 +228,131 @@ function getRouterChild(router, ...path) {
|
|
303
228
|
}
|
304
229
|
const lazied = current;
|
305
230
|
const rest = path.slice(i);
|
306
|
-
|
231
|
+
return lazy(async () => {
|
307
232
|
const unwrapped = await unlazy(lazied);
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
const next = getRouterChild(unwrapped.default, ...rest);
|
312
|
-
return { default: next };
|
313
|
-
});
|
314
|
-
return flatLazy(newLazy);
|
233
|
+
const next = getRouter(unwrapped.default, rest);
|
234
|
+
return unlazy(next);
|
235
|
+
}, getLazyMeta(lazied));
|
315
236
|
}
|
316
237
|
return current;
|
317
238
|
}
|
318
|
-
|
319
|
-
// src/router-accessible-lazy.ts
|
320
239
|
function createAccessibleLazyRouter(lazied) {
|
321
|
-
const
|
322
|
-
const recursive = new Proxy(flattenLazy, {
|
240
|
+
const recursive = new Proxy(lazied, {
|
323
241
|
get(target, key) {
|
324
242
|
if (typeof key !== "string") {
|
325
243
|
return Reflect.get(target, key);
|
326
244
|
}
|
327
|
-
const next =
|
245
|
+
const next = getRouter(lazied, [key]);
|
328
246
|
return createAccessibleLazyRouter(next);
|
329
247
|
}
|
330
248
|
});
|
331
249
|
return recursive;
|
332
250
|
}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
251
|
+
function enhanceRouter(router, options) {
|
252
|
+
if (isLazy(router)) {
|
253
|
+
const laziedMeta = getLazyMeta(router);
|
254
|
+
const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
|
255
|
+
const enhanced2 = lazy(async () => {
|
256
|
+
const { default: unlaziedRouter } = await unlazy(router);
|
257
|
+
const enhanced3 = enhanceRouter(unlaziedRouter, options);
|
258
|
+
return unlazy(enhanced3);
|
259
|
+
}, {
|
260
|
+
...laziedMeta,
|
261
|
+
prefix: enhancedPrefix
|
262
|
+
});
|
263
|
+
const accessible = createAccessibleLazyRouter(enhanced2);
|
264
|
+
return accessible;
|
265
|
+
}
|
266
|
+
if (isProcedure(router)) {
|
267
|
+
const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
|
268
|
+
const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
|
269
|
+
const enhanced2 = new Procedure({
|
270
|
+
...router["~orpc"],
|
271
|
+
route: enhanceRoute(router["~orpc"].route, options),
|
272
|
+
errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
|
273
|
+
middlewares: newMiddlewares,
|
274
|
+
inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
|
275
|
+
outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
|
276
|
+
});
|
277
|
+
return enhanced2;
|
347
278
|
}
|
348
|
-
|
349
|
-
|
350
|
-
|
279
|
+
const enhanced = {};
|
280
|
+
for (const key in router) {
|
281
|
+
enhanced[key] = enhanceRouter(router[key], options);
|
282
|
+
}
|
283
|
+
return enhanced;
|
284
|
+
}
|
285
|
+
function traverseContractProcedures(options, callback, lazyOptions = []) {
|
286
|
+
let currentRouter = options.router;
|
287
|
+
const hiddenContract = getHiddenRouterContract(options.router);
|
288
|
+
if (hiddenContract !== void 0) {
|
289
|
+
currentRouter = hiddenContract;
|
290
|
+
}
|
291
|
+
if (isLazy(currentRouter)) {
|
292
|
+
lazyOptions.push({
|
293
|
+
router: currentRouter,
|
351
294
|
path: options.path
|
352
295
|
});
|
353
|
-
} else if (
|
296
|
+
} else if (isContractProcedure(currentRouter)) {
|
354
297
|
callback({
|
355
|
-
contract:
|
298
|
+
contract: currentRouter,
|
356
299
|
path: options.path
|
357
300
|
});
|
358
301
|
} else {
|
359
|
-
for (const key in
|
360
|
-
|
302
|
+
for (const key in currentRouter) {
|
303
|
+
traverseContractProcedures(
|
361
304
|
{
|
362
|
-
router:
|
305
|
+
router: currentRouter[key],
|
363
306
|
path: [...options.path, key]
|
364
307
|
},
|
365
308
|
callback,
|
366
|
-
|
309
|
+
lazyOptions
|
367
310
|
);
|
368
311
|
}
|
369
312
|
}
|
370
|
-
return
|
313
|
+
return lazyOptions;
|
371
314
|
}
|
372
|
-
async function
|
315
|
+
async function resolveContractProcedures(options, callback) {
|
373
316
|
const pending = [options];
|
374
|
-
for (const
|
375
|
-
const
|
376
|
-
for (const
|
377
|
-
const { default: router } = await unlazy(
|
317
|
+
for (const options2 of pending) {
|
318
|
+
const lazyOptions = traverseContractProcedures(options2, callback);
|
319
|
+
for (const options3 of lazyOptions) {
|
320
|
+
const { default: router } = await unlazy(options3.router);
|
378
321
|
pending.push({
|
379
|
-
|
380
|
-
|
322
|
+
router,
|
323
|
+
path: options3.path
|
381
324
|
});
|
382
325
|
}
|
383
326
|
}
|
384
327
|
}
|
385
|
-
function
|
386
|
-
|
328
|
+
async function unlazyRouter(router) {
|
329
|
+
if (isProcedure(router)) {
|
330
|
+
return router;
|
331
|
+
}
|
332
|
+
const unlazied = {};
|
333
|
+
for (const key in router) {
|
334
|
+
const item = router[key];
|
335
|
+
const { default: unlaziedRouter } = await unlazy(item);
|
336
|
+
unlazied[key] = await unlazyRouter(unlaziedRouter);
|
337
|
+
}
|
338
|
+
return unlazied;
|
339
|
+
}
|
340
|
+
|
341
|
+
function createAssertedLazyProcedure(lazied) {
|
342
|
+
const lazyProcedure = lazy(async () => {
|
343
|
+
const { default: maybeProcedure } = await unlazy(lazied);
|
344
|
+
if (!isProcedure(maybeProcedure)) {
|
345
|
+
throw new Error(`
|
346
|
+
Expected a lazy<procedure> but got lazy<unknown>.
|
347
|
+
This should be caught by TypeScript compilation.
|
348
|
+
Please report this issue if this makes you feel uncomfortable.
|
349
|
+
`);
|
350
|
+
}
|
351
|
+
return { default: maybeProcedure };
|
352
|
+
}, getLazyMeta(lazied));
|
353
|
+
return lazyProcedure;
|
387
354
|
}
|
388
|
-
function createContractedProcedure(
|
355
|
+
function createContractedProcedure(procedure, contract) {
|
389
356
|
return new Procedure({
|
390
357
|
...procedure["~orpc"],
|
391
358
|
errorMap: contract["~orpc"].errorMap,
|
@@ -393,29 +360,8 @@ function createContractedProcedure(contract, procedure) {
|
|
393
360
|
meta: contract["~orpc"].meta
|
394
361
|
});
|
395
362
|
}
|
363
|
+
function call(procedure, input, ...rest) {
|
364
|
+
return createProcedureClient(procedure, ...rest)(input);
|
365
|
+
}
|
396
366
|
|
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
|
367
|
+
export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext 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 };
|