@orpc/server 0.0.0-next.c59d67c → 0.0.0-next.ca29a36

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.
Files changed (68) hide show
  1. package/README.md +118 -0
  2. package/dist/chunk-MBMXGUNI.js +32 -0
  3. package/dist/chunk-MHVECKBC.js +421 -0
  4. package/dist/chunk-NTHCS5CK.js +182 -0
  5. package/dist/chunk-TXHKQO7N.js +120 -0
  6. package/dist/fetch.js +6 -102
  7. package/dist/hono.js +34 -0
  8. package/dist/index.js +341 -322
  9. package/dist/next.js +31 -0
  10. package/dist/node.js +31 -0
  11. package/dist/plugins.js +11 -0
  12. package/dist/src/adapters/fetch/index.d.ts +3 -0
  13. package/dist/src/adapters/fetch/rpc-handler.d.ts +11 -0
  14. package/dist/src/adapters/fetch/types.d.ts +14 -0
  15. package/dist/src/adapters/hono/index.d.ts +3 -0
  16. package/dist/src/adapters/hono/middleware.d.ts +12 -0
  17. package/dist/src/adapters/next/index.d.ts +3 -0
  18. package/dist/src/adapters/next/serve.d.ts +19 -0
  19. package/dist/src/adapters/node/index.d.ts +3 -0
  20. package/dist/src/adapters/node/rpc-handler.d.ts +11 -0
  21. package/dist/src/adapters/node/types.d.ts +22 -0
  22. package/dist/src/adapters/standard/handler.d.ts +53 -0
  23. package/dist/src/adapters/standard/index.d.ts +6 -0
  24. package/dist/src/adapters/standard/rpc-codec.d.ts +16 -0
  25. package/dist/src/adapters/standard/rpc-handler.d.ts +8 -0
  26. package/dist/src/adapters/standard/rpc-matcher.d.ts +10 -0
  27. package/dist/src/adapters/standard/types.d.ts +21 -0
  28. package/dist/src/builder-variants.d.ts +75 -0
  29. package/dist/src/builder.d.ts +48 -39
  30. package/dist/src/config.d.ts +6 -0
  31. package/dist/src/context.d.ts +8 -0
  32. package/dist/src/error.d.ts +12 -0
  33. package/dist/src/hidden.d.ts +8 -0
  34. package/dist/src/implementer-procedure.d.ts +33 -0
  35. package/dist/src/implementer-variants.d.ts +18 -0
  36. package/dist/src/implementer.d.ts +29 -0
  37. package/dist/src/index.d.ts +19 -9
  38. package/dist/src/lazy-utils.d.ts +6 -0
  39. package/dist/src/lazy.d.ts +22 -0
  40. package/dist/src/middleware-decorated.d.ts +11 -0
  41. package/dist/src/middleware-utils.d.ts +5 -0
  42. package/dist/src/middleware.d.ts +30 -18
  43. package/dist/src/plugins/base.d.ts +11 -0
  44. package/dist/src/plugins/cors.d.ts +19 -0
  45. package/dist/src/plugins/index.d.ts +4 -0
  46. package/dist/src/plugins/response-headers.d.ts +10 -0
  47. package/dist/src/procedure-client.d.ts +33 -0
  48. package/dist/src/procedure-decorated.d.ts +24 -0
  49. package/dist/src/procedure-utils.d.ts +19 -0
  50. package/dist/src/procedure.d.ts +27 -25
  51. package/dist/src/router-accessible-lazy.d.ts +8 -0
  52. package/dist/src/router-client.d.ts +12 -0
  53. package/dist/src/router.d.ts +26 -16
  54. package/dist/src/utils.d.ts +23 -2
  55. package/dist/standard.js +13 -0
  56. package/package.json +37 -9
  57. package/dist/chunk-TDFYNRZV.js +0 -190
  58. package/dist/src/fetch/handle.d.ts +0 -7
  59. package/dist/src/fetch/handler.d.ts +0 -3
  60. package/dist/src/fetch/index.d.ts +0 -4
  61. package/dist/src/fetch/types.d.ts +0 -35
  62. package/dist/src/procedure-builder.d.ts +0 -31
  63. package/dist/src/procedure-caller.d.ts +0 -19
  64. package/dist/src/procedure-implementer.d.ts +0 -18
  65. package/dist/src/router-builder.d.ts +0 -22
  66. package/dist/src/router-caller.d.ts +0 -22
  67. package/dist/src/router-implementer.d.ts +0 -20
  68. package/dist/src/types.d.ts +0 -8
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ <div align="center">
2
+ <image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 />
3
+ </div>
4
+
5
+ <h1></h1>
6
+
7
+ <div align="center">
8
+ <a href="https://codecov.io/gh/unnoq/orpc">
9
+ <img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@orpc/server">
12
+ <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fserver?logo=npm" />
13
+ </a>
14
+ <a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
15
+ <img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
16
+ </a>
17
+ <a href="https://discord.gg/TXEbwRBvQn">
18
+ <img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
19
+ </a>
20
+ </div>
21
+
22
+ <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
+
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
25
+
26
+ ---
27
+
28
+ ## Highlights
29
+
30
+ - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
+ - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
+ - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
+ - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
+ - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
+ - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue), Pinia Colada, and more.
36
+ - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
+ - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
+ - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
+ - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
+ - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
+ - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
+ - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
+ - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
+ - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
+ - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
46
+
47
+ ## Documentation
48
+
49
+ You can find the full documentation [here](https://orpc.unnoq.com).
50
+
51
+ ## Packages
52
+
53
+ - [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
54
+ - [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
55
+ - [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
56
+ - [@orpc/react-query](https://www.npmjs.com/package/@orpc/react-query): Integration with [React Query](https://tanstack.com/query/latest/docs/framework/react/overview).
57
+ - [@orpc/vue-query](https://www.npmjs.com/package/@orpc/vue-query): Integration with [Vue Query](https://tanstack.com/query/latest/docs/framework/vue/overview).
58
+ - [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
59
+ - [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
60
+ - [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
61
+
62
+ ## `@orpc/server`
63
+
64
+ Build your API or implement API contract. Read the [documentation](https://orpc.unnoq.com/docs/getting-started) for more information.
65
+
66
+ ```ts
67
+ import type { IncomingHttpHeaders } from 'node:http'
68
+ import { ORPCError, os } from '@orpc/server'
69
+ import { z } from 'zod'
70
+
71
+ const PlanetSchema = z.object({
72
+ id: z.number().int().min(1),
73
+ name: z.string(),
74
+ description: z.string().optional(),
75
+ })
76
+
77
+ export const listPlanet = os
78
+ .input(
79
+ z.object({
80
+ limit: z.number().int().min(1).max(100).optional(),
81
+ cursor: z.number().int().min(0).default(0),
82
+ }),
83
+ )
84
+ .handler(async ({ input }) => {
85
+ // your list code here
86
+ return [{ id: 1, name: 'name' }]
87
+ })
88
+
89
+ export const findPlanet = os
90
+ .input(PlanetSchema.pick({ id: true }))
91
+ .handler(async ({ input }) => {
92
+ // your find code here
93
+ return { id: 1, name: 'name' }
94
+ })
95
+
96
+ export const createPlanet = os
97
+ .$context<{ headers: IncomingHttpHeaders }>()
98
+ .use(({ context, next }) => {
99
+ const user = parseJWT(context.headers.authorization?.split(' ')[1])
100
+
101
+ if (user) {
102
+ return next({ context: { user } })
103
+ }
104
+
105
+ throw new ORPCError('UNAUTHORIZED')
106
+ })
107
+ .input(PlanetSchema.omit({ id: true }))
108
+ .handler(async ({ input, context }) => {
109
+ // your create code here
110
+ return { id: 1, name: 'name' }
111
+ })
112
+
113
+ export const router = { planet: { list: listPlanet, find: findPlanet, create: createPlanet } }
114
+ ```
115
+
116
+ ## License
117
+
118
+ Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
@@ -0,0 +1,32 @@
1
+ import {
2
+ RPCCodec,
3
+ RPCMatcher,
4
+ StandardHandler
5
+ } from "./chunk-NTHCS5CK.js";
6
+
7
+ // src/adapters/fetch/rpc-handler.ts
8
+ import { toFetchResponse, toStandardRequest } from "@orpc/standard-server-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-MBMXGUNI.js.map
@@ -0,0 +1,421 @@
1
+ // src/lazy.ts
2
+ var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
3
+ function lazy(loader) {
4
+ return {
5
+ [LAZY_LOADER_SYMBOL]: loader
6
+ };
7
+ }
8
+ function isLazy(item) {
9
+ return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
10
+ }
11
+ function unlazy(lazied) {
12
+ return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
13
+ }
14
+
15
+ // src/procedure.ts
16
+ import { isContractProcedure } from "@orpc/contract";
17
+ var Procedure = class {
18
+ "~orpc";
19
+ constructor(def) {
20
+ this["~orpc"] = def;
21
+ }
22
+ };
23
+ function isProcedure(item) {
24
+ if (item instanceof Procedure) {
25
+ return true;
26
+ }
27
+ return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
28
+ }
29
+
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
+ function createORPCErrorConstructorMap(errors) {
72
+ const proxy = new Proxy(errors, {
73
+ get(target, code) {
74
+ if (typeof code !== "string") {
75
+ return Reflect.get(target, code);
76
+ }
77
+ const item = (...[options]) => {
78
+ const config = errors[code];
79
+ return new ORPCError(code, {
80
+ defined: Boolean(config),
81
+ status: config?.status,
82
+ message: options?.message ?? config?.message,
83
+ data: options?.data,
84
+ cause: options?.cause
85
+ });
86
+ };
87
+ return item;
88
+ }
89
+ });
90
+ return proxy;
91
+ }
92
+ async function validateORPCError(map, error) {
93
+ const { code, status, message, data, cause, defined } = error;
94
+ const config = map?.[error.code];
95
+ if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
96
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
97
+ }
98
+ if (!config.data) {
99
+ return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
100
+ }
101
+ const validated = await config.data["~standard"].validate(error.data);
102
+ if (validated.issues) {
103
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
104
+ }
105
+ return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
106
+ }
107
+
108
+ // src/procedure-client.ts
109
+ function createProcedureClient(lazyableProcedure, ...[options]) {
110
+ return async (...[input, callerOptions]) => {
111
+ const path = options?.path ?? [];
112
+ const { default: procedure } = await unlazy(lazyableProcedure);
113
+ const clientContext = callerOptions?.context ?? {};
114
+ const context = await value(options?.context ?? {}, clientContext);
115
+ const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
116
+ try {
117
+ return await intercept(
118
+ options?.interceptors ?? [],
119
+ {
120
+ context,
121
+ input,
122
+ // input only optional when it undefinable so we can safely cast it
123
+ errors,
124
+ path,
125
+ procedure,
126
+ signal: callerOptions?.signal,
127
+ lastEventId: callerOptions?.lastEventId
128
+ },
129
+ (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
130
+ );
131
+ } catch (e) {
132
+ if (!(e instanceof ORPCError2)) {
133
+ throw toError(e);
134
+ }
135
+ const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
136
+ throw validated;
137
+ }
138
+ };
139
+ }
140
+ async function validateInput(procedure, input) {
141
+ const schema = procedure["~orpc"].inputSchema;
142
+ if (!schema) {
143
+ return input;
144
+ }
145
+ const result = await schema["~standard"].validate(input);
146
+ if (result.issues) {
147
+ throw new ORPCError2("BAD_REQUEST", {
148
+ message: "Input validation failed",
149
+ data: {
150
+ issues: result.issues
151
+ },
152
+ cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
153
+ });
154
+ }
155
+ return result.value;
156
+ }
157
+ async function validateOutput(procedure, output) {
158
+ const schema = procedure["~orpc"].outputSchema;
159
+ if (!schema) {
160
+ return output;
161
+ }
162
+ const result = await schema["~standard"].validate(output);
163
+ if (result.issues) {
164
+ throw new ORPCError2("INTERNAL_SERVER_ERROR", {
165
+ message: "Output validation failed",
166
+ cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
167
+ });
168
+ }
169
+ return result.value;
170
+ }
171
+ async function executeProcedureInternal(procedure, options) {
172
+ const middlewares = procedure["~orpc"].middlewares;
173
+ const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
174
+ const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
175
+ let currentIndex = 0;
176
+ let currentContext = options.context;
177
+ let currentInput = options.input;
178
+ const next = async (...[nextOptions]) => {
179
+ const index = currentIndex;
180
+ currentIndex += 1;
181
+ currentContext = { ...currentContext, ...nextOptions?.context };
182
+ if (index === inputValidationIndex) {
183
+ currentInput = await validateInput(procedure, currentInput);
184
+ }
185
+ const mid = middlewares[index];
186
+ const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
187
+ if (index === outputValidationIndex) {
188
+ const validatedOutput = await validateOutput(procedure, result.output);
189
+ return {
190
+ ...result,
191
+ output: validatedOutput
192
+ };
193
+ }
194
+ return result;
195
+ };
196
+ return (await next({})).output;
197
+ }
198
+
199
+ // src/hidden.ts
200
+ var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
201
+ function setRouterContract(obj, contract) {
202
+ return new Proxy(obj, {
203
+ get(target, key) {
204
+ if (key === ROUTER_CONTRACT_SYMBOL) {
205
+ return contract;
206
+ }
207
+ return Reflect.get(target, key);
208
+ }
209
+ });
210
+ }
211
+ function getRouterContract(obj) {
212
+ return obj[ROUTER_CONTRACT_SYMBOL];
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];
253
+ }
254
+
255
+ // src/router.ts
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) {
291
+ let current = router;
292
+ for (let i = 0; i < path.length; i++) {
293
+ const segment = path[i];
294
+ if (!current) {
295
+ return void 0;
296
+ }
297
+ if (isProcedure(current)) {
298
+ return void 0;
299
+ }
300
+ if (!isLazy(current)) {
301
+ current = current[segment];
302
+ continue;
303
+ }
304
+ const lazied = current;
305
+ const rest = path.slice(i);
306
+ const newLazy = lazy(async () => {
307
+ const unwrapped = await unlazy(lazied);
308
+ if (!unwrapped.default) {
309
+ return unwrapped;
310
+ }
311
+ const next = getRouterChild(unwrapped.default, ...rest);
312
+ return { default: next };
313
+ });
314
+ return flatLazy(newLazy);
315
+ }
316
+ return current;
317
+ }
318
+
319
+ // src/router-accessible-lazy.ts
320
+ function createAccessibleLazyRouter(lazied) {
321
+ const flattenLazy = flatLazy(lazied);
322
+ const recursive = new Proxy(flattenLazy, {
323
+ get(target, key) {
324
+ if (typeof key !== "string") {
325
+ return Reflect.get(target, key);
326
+ }
327
+ const next = getRouterChild(flattenLazy, key);
328
+ return createAccessibleLazyRouter(next);
329
+ }
330
+ });
331
+ return recursive;
332
+ }
333
+
334
+ // src/utils.ts
335
+ import { isContractProcedure as isContractProcedure2 } from "@orpc/contract";
336
+ function eachContractProcedure(options, callback, laziedOptions = []) {
337
+ const hiddenContract = getRouterContract(options.router);
338
+ if (hiddenContract) {
339
+ return eachContractProcedure(
340
+ {
341
+ router: hiddenContract,
342
+ path: options.path
343
+ },
344
+ callback,
345
+ laziedOptions
346
+ );
347
+ }
348
+ if (isLazy(options.router)) {
349
+ laziedOptions.push({
350
+ lazied: options.router,
351
+ path: options.path
352
+ });
353
+ } else if (isContractProcedure2(options.router)) {
354
+ callback({
355
+ contract: options.router,
356
+ path: options.path
357
+ });
358
+ } else {
359
+ for (const key in options.router) {
360
+ eachContractProcedure(
361
+ {
362
+ router: options.router[key],
363
+ path: [...options.path, key]
364
+ },
365
+ callback,
366
+ laziedOptions
367
+ );
368
+ }
369
+ }
370
+ return laziedOptions;
371
+ }
372
+ async function eachAllContractProcedure(options, callback) {
373
+ const pending = [options];
374
+ for (const item of pending) {
375
+ const lazies = eachContractProcedure(item, callback);
376
+ for (const lazy2 of lazies) {
377
+ const { default: router } = await unlazy(lazy2.lazied);
378
+ pending.push({
379
+ path: lazy2.path,
380
+ router
381
+ });
382
+ }
383
+ }
384
+ }
385
+ function convertPathToHttpPath(path) {
386
+ return `/${path.map(encodeURIComponent).join("/")}`;
387
+ }
388
+ function createContractedProcedure(contract, procedure) {
389
+ return new Procedure({
390
+ ...procedure["~orpc"],
391
+ errorMap: contract["~orpc"].errorMap,
392
+ route: contract["~orpc"].route,
393
+ meta: contract["~orpc"].meta
394
+ });
395
+ }
396
+
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