@orpc/server 0.0.0-next.b6be6f0 → 0.0.0-next.bc564a6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/dist/chunk-ESTRJAOX.js +299 -0
  2. package/dist/chunk-KK4SDLC7.js +320 -0
  3. package/dist/chunk-WUOGVGWG.js +1 -0
  4. package/dist/fetch.js +10 -310
  5. package/dist/hono.js +30 -0
  6. package/dist/index.js +256 -383
  7. package/dist/next.js +36 -0
  8. package/dist/node.js +87 -0
  9. package/dist/src/{fetch → adapters/fetch}/index.d.ts +1 -1
  10. package/dist/src/adapters/fetch/orpc-handler.d.ts +20 -0
  11. package/dist/src/{fetch → adapters/fetch}/orpc-payload-codec.d.ts +1 -1
  12. package/dist/src/{fetch → adapters/fetch}/orpc-procedure-matcher.d.ts +4 -4
  13. package/dist/src/adapters/fetch/types.d.ts +21 -0
  14. package/dist/src/adapters/hono/index.d.ts +3 -0
  15. package/dist/src/adapters/hono/middleware.d.ts +12 -0
  16. package/dist/src/adapters/next/index.d.ts +3 -0
  17. package/dist/src/adapters/next/serve.d.ts +19 -0
  18. package/dist/src/adapters/node/index.d.ts +5 -0
  19. package/dist/src/adapters/node/orpc-handler.d.ts +12 -0
  20. package/dist/src/adapters/node/request-listener.d.ts +28 -0
  21. package/dist/src/adapters/node/types.d.ts +22 -0
  22. package/dist/src/builder-variants.d.ts +74 -0
  23. package/dist/src/builder.d.ts +52 -30
  24. package/dist/src/config.d.ts +6 -0
  25. package/dist/src/context.d.ts +9 -0
  26. package/dist/src/hidden.d.ts +6 -4
  27. package/dist/src/implementer-procedure.d.ts +30 -0
  28. package/dist/src/implementer-variants.d.ts +16 -0
  29. package/dist/src/implementer.d.ts +27 -0
  30. package/dist/src/index.d.ts +10 -12
  31. package/dist/src/lazy-utils.d.ts +4 -2
  32. package/dist/src/lazy.d.ts +9 -5
  33. package/dist/src/middleware-decorated.d.ts +7 -5
  34. package/dist/src/middleware-utils.d.ts +5 -0
  35. package/dist/src/middleware.d.ts +28 -14
  36. package/dist/src/procedure-client.d.ts +8 -22
  37. package/dist/src/procedure-decorated.d.ts +18 -11
  38. package/dist/src/procedure-utils.d.ts +17 -0
  39. package/dist/src/procedure.d.ts +24 -18
  40. package/dist/src/router-accessible-lazy.d.ts +8 -0
  41. package/dist/src/router-client.d.ts +7 -10
  42. package/dist/src/router.d.ts +25 -12
  43. package/package.json +24 -8
  44. package/dist/chunk-37HIYNDO.js +0 -182
  45. package/dist/src/fetch/composite-handler.d.ts +0 -8
  46. package/dist/src/fetch/orpc-handler.d.ts +0 -20
  47. package/dist/src/fetch/types.d.ts +0 -16
  48. package/dist/src/implementer-chainable.d.ts +0 -10
  49. package/dist/src/lazy-decorated.d.ts +0 -10
  50. package/dist/src/procedure-builder.d.ts +0 -22
  51. package/dist/src/procedure-implementer.d.ts +0 -18
  52. package/dist/src/router-builder.d.ts +0 -29
  53. package/dist/src/router-implementer.d.ts +0 -21
  54. package/dist/src/types.d.ts +0 -12
  55. package/dist/src/utils.d.ts +0 -3
  56. /package/dist/src/{fetch → adapters/fetch}/super-json.d.ts +0 -0
@@ -0,0 +1,299 @@
1
+ import {
2
+ __export,
3
+ createProcedureClient,
4
+ getRouterChild,
5
+ isProcedure,
6
+ unlazy
7
+ } from "./chunk-KK4SDLC7.js";
8
+
9
+ // src/adapters/fetch/super-json.ts
10
+ var super_json_exports = {};
11
+ __export(super_json_exports, {
12
+ deserialize: () => deserialize,
13
+ serialize: () => serialize
14
+ });
15
+
16
+ // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/getType.js
17
+ function getType(payload) {
18
+ return Object.prototype.toString.call(payload).slice(8, -1);
19
+ }
20
+
21
+ // ../../node_modules/.pnpm/is-what@5.0.2/node_modules/is-what/dist/isPlainObject.js
22
+ function isPlainObject(payload) {
23
+ if (getType(payload) !== "Object")
24
+ return false;
25
+ const prototype = Object.getPrototypeOf(payload);
26
+ return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
27
+ }
28
+
29
+ // src/adapters/fetch/super-json.ts
30
+ function serialize(value, segments = [], meta = []) {
31
+ if (typeof value === "bigint") {
32
+ meta.push(["bigint", segments]);
33
+ return { data: value.toString(), meta };
34
+ }
35
+ if (value instanceof Date) {
36
+ meta.push(["date", segments]);
37
+ const data = Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString();
38
+ return { data, meta };
39
+ }
40
+ if (Number.isNaN(value)) {
41
+ meta.push(["nan", segments]);
42
+ return { data: "NaN", meta };
43
+ }
44
+ if (value instanceof RegExp) {
45
+ meta.push(["regexp", segments]);
46
+ return { data: value.toString(), meta };
47
+ }
48
+ if (value instanceof URL) {
49
+ meta.push(["url", segments]);
50
+ return { data: value.toString(), meta };
51
+ }
52
+ if (isPlainObject(value)) {
53
+ const data = {};
54
+ for (const k in value) {
55
+ data[k] = serialize(value[k], [...segments, k], meta).data;
56
+ }
57
+ return { data, meta };
58
+ }
59
+ if (Array.isArray(value)) {
60
+ const data = value.map((v, i) => {
61
+ if (v === void 0) {
62
+ meta.push(["undefined", [...segments, i]]);
63
+ return null;
64
+ }
65
+ return serialize(v, [...segments, i], meta).data;
66
+ });
67
+ return { data, meta };
68
+ }
69
+ if (value instanceof Set) {
70
+ const result = serialize(Array.from(value), segments, meta);
71
+ meta.push(["set", segments]);
72
+ return result;
73
+ }
74
+ if (value instanceof Map) {
75
+ const result = serialize(Array.from(value.entries()), segments, meta);
76
+ meta.push(["map", segments]);
77
+ return result;
78
+ }
79
+ return { data: value, meta };
80
+ }
81
+ function deserialize({
82
+ data,
83
+ meta
84
+ }) {
85
+ if (meta.length === 0) {
86
+ return data;
87
+ }
88
+ const ref = { data };
89
+ for (const [type, segments] of meta) {
90
+ let currentRef = ref;
91
+ let preSegment = "data";
92
+ for (let i = 0; i < segments.length; i++) {
93
+ currentRef = currentRef[preSegment];
94
+ preSegment = segments[i];
95
+ }
96
+ switch (type) {
97
+ case "nan":
98
+ currentRef[preSegment] = Number.NaN;
99
+ break;
100
+ case "bigint":
101
+ currentRef[preSegment] = BigInt(currentRef[preSegment]);
102
+ break;
103
+ case "date":
104
+ currentRef[preSegment] = new Date(currentRef[preSegment]);
105
+ break;
106
+ case "regexp": {
107
+ const [, pattern, flags] = currentRef[preSegment].match(/^\/(.*)\/([a-z]*)$/);
108
+ currentRef[preSegment] = new RegExp(pattern, flags);
109
+ break;
110
+ }
111
+ case "url":
112
+ currentRef[preSegment] = new URL(currentRef[preSegment]);
113
+ break;
114
+ case "undefined":
115
+ currentRef[preSegment] = void 0;
116
+ break;
117
+ case "map":
118
+ currentRef[preSegment] = new Map(currentRef[preSegment]);
119
+ break;
120
+ case "set":
121
+ currentRef[preSegment] = new Set(currentRef[preSegment]);
122
+ break;
123
+ /* v8 ignore next 3 */
124
+ default: {
125
+ const _expected = type;
126
+ }
127
+ }
128
+ }
129
+ return ref.data;
130
+ }
131
+
132
+ // src/adapters/fetch/orpc-payload-codec.ts
133
+ import { ORPCError } from "@orpc/contract";
134
+ import { findDeepMatches, set } from "@orpc/shared";
135
+ var ORPCPayloadCodec = class {
136
+ /**
137
+ * If method is GET, the payload will be encoded as query string.
138
+ * If method is GET and payload contain file, the method will be fallback to fallbackMethod. (fallbackMethod = GET will force to use GET method)
139
+ */
140
+ encode(payload, method = "POST", fallbackMethod = "POST") {
141
+ const { data, meta } = serialize(payload);
142
+ const { maps, values } = findDeepMatches((v) => v instanceof Blob, data);
143
+ if (method === "GET" && (values.length === 0 || fallbackMethod === "GET")) {
144
+ const query = new URLSearchParams({
145
+ data: JSON.stringify(data),
146
+ meta: JSON.stringify(meta)
147
+ });
148
+ return {
149
+ query,
150
+ method: "GET"
151
+ };
152
+ }
153
+ const nonGETMethod = method === "GET" ? fallbackMethod : method;
154
+ if (values.length > 0) {
155
+ const form = new FormData();
156
+ if (data !== void 0) {
157
+ form.append("data", JSON.stringify(data));
158
+ }
159
+ form.append("meta", JSON.stringify(meta));
160
+ form.append("maps", JSON.stringify(maps));
161
+ for (const i in values) {
162
+ const value = values[i];
163
+ form.append(i, value);
164
+ }
165
+ return {
166
+ body: form,
167
+ method: nonGETMethod
168
+ };
169
+ }
170
+ return {
171
+ body: JSON.stringify({ data, meta }),
172
+ headers: new Headers({
173
+ "content-type": "application/json"
174
+ }),
175
+ method: nonGETMethod
176
+ };
177
+ }
178
+ async decode(re) {
179
+ try {
180
+ if ("method" in re && re.method === "GET") {
181
+ const url = new URL(re.url);
182
+ const query = url.searchParams;
183
+ const data = JSON.parse(query.getAll("data").at(-1));
184
+ const meta = JSON.parse(query.getAll("meta").at(-1));
185
+ return deserialize({
186
+ data,
187
+ meta
188
+ });
189
+ }
190
+ if (re.headers.get("content-type")?.startsWith("multipart/form-data")) {
191
+ const form = await re.formData();
192
+ const rawData = form.get("data");
193
+ const rawMeta = form.get("meta");
194
+ const rawMaps = form.get("maps");
195
+ let data = JSON.parse(rawData);
196
+ const meta = JSON.parse(rawMeta);
197
+ const maps = JSON.parse(rawMaps);
198
+ for (const i in maps) {
199
+ data = set(data, maps[i], form.get(i));
200
+ }
201
+ return deserialize({
202
+ data,
203
+ meta
204
+ });
205
+ }
206
+ const json = await re.json();
207
+ return deserialize(json);
208
+ } catch (e) {
209
+ throw new ORPCError("BAD_REQUEST", {
210
+ message: "Cannot parse request/response. Please check the request/response body and Content-Type header.",
211
+ cause: e
212
+ });
213
+ }
214
+ }
215
+ };
216
+
217
+ // src/adapters/fetch/orpc-procedure-matcher.ts
218
+ import { trim } from "@orpc/shared";
219
+ var ORPCProcedureMatcher = class {
220
+ constructor(router) {
221
+ this.router = router;
222
+ }
223
+ async match(pathname) {
224
+ const path = trim(pathname, "/").split("/").map(decodeURIComponent);
225
+ const match = getRouterChild(this.router, ...path);
226
+ const { default: maybeProcedure } = await unlazy(match);
227
+ if (!isProcedure(maybeProcedure)) {
228
+ return void 0;
229
+ }
230
+ return {
231
+ procedure: maybeProcedure,
232
+ path
233
+ };
234
+ }
235
+ };
236
+
237
+ // src/adapters/fetch/orpc-handler.ts
238
+ import { ORPCError as ORPCError2 } from "@orpc/contract";
239
+ import { executeWithHooks, trim as trim2 } from "@orpc/shared";
240
+ var RPCHandler = class {
241
+ constructor(router, options) {
242
+ this.options = options;
243
+ this.procedureMatcher = options?.procedureMatcher ?? new ORPCProcedureMatcher(router);
244
+ this.payloadCodec = options?.payloadCodec ?? new ORPCPayloadCodec();
245
+ }
246
+ procedureMatcher;
247
+ payloadCodec;
248
+ async handle(request, ...[options]) {
249
+ const context = options?.context ?? {};
250
+ const execute = async () => {
251
+ const url = new URL(request.url);
252
+ const pathname = `/${trim2(url.pathname.replace(options?.prefix ?? "", ""), "/")}`;
253
+ const match = await this.procedureMatcher.match(pathname);
254
+ if (!match) {
255
+ return { matched: false, response: void 0 };
256
+ }
257
+ const input = await this.payloadCodec.decode(request);
258
+ const client = createProcedureClient(match.procedure, {
259
+ context,
260
+ path: match.path
261
+ });
262
+ const output = await client(input, { signal: request.signal });
263
+ const { body, headers } = this.payloadCodec.encode(output);
264
+ const response = new Response(body, { headers });
265
+ return { matched: true, response };
266
+ };
267
+ try {
268
+ const result = await executeWithHooks({
269
+ context,
270
+ execute,
271
+ input: request,
272
+ hooks: this.options,
273
+ meta: {
274
+ signal: request.signal
275
+ }
276
+ });
277
+ return result;
278
+ } catch (e) {
279
+ const error = e instanceof ORPCError2 ? e : new ORPCError2("INTERNAL_SERVER_ERROR", {
280
+ message: "Internal server error",
281
+ cause: e
282
+ });
283
+ const { body, headers } = this.payloadCodec.encode(error.toJSON());
284
+ const response = new Response(body, {
285
+ headers,
286
+ status: error.status
287
+ });
288
+ return { matched: true, response };
289
+ }
290
+ }
291
+ };
292
+
293
+ export {
294
+ super_json_exports,
295
+ ORPCPayloadCodec,
296
+ ORPCProcedureMatcher,
297
+ RPCHandler
298
+ };
299
+ //# sourceMappingURL=chunk-ESTRJAOX.js.map
@@ -0,0 +1,320 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/lazy.ts
8
+ var LAZY_LOADER_SYMBOL = Symbol("ORPC_LAZY_LOADER");
9
+ function lazy(loader) {
10
+ return {
11
+ [LAZY_LOADER_SYMBOL]: loader
12
+ };
13
+ }
14
+ function isLazy(item) {
15
+ return (typeof item === "object" || typeof item === "function") && item !== null && LAZY_LOADER_SYMBOL in item && typeof item[LAZY_LOADER_SYMBOL] === "function";
16
+ }
17
+ function unlazy(lazied) {
18
+ return isLazy(lazied) ? lazied[LAZY_LOADER_SYMBOL]() : Promise.resolve({ default: lazied });
19
+ }
20
+
21
+ // src/procedure.ts
22
+ import { isContractProcedure } from "@orpc/contract";
23
+ var Procedure = class {
24
+ "~orpc";
25
+ constructor(def) {
26
+ this["~orpc"] = def;
27
+ }
28
+ };
29
+ function isProcedure(item) {
30
+ if (item instanceof Procedure) {
31
+ return true;
32
+ }
33
+ return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
34
+ }
35
+
36
+ // src/lazy-utils.ts
37
+ function flatLazy(lazied) {
38
+ const flattenLoader = async () => {
39
+ let current = await unlazy(lazied);
40
+ while (true) {
41
+ if (!isLazy(current.default)) {
42
+ break;
43
+ }
44
+ current = await unlazy(current.default);
45
+ }
46
+ return current;
47
+ };
48
+ return lazy(flattenLoader);
49
+ }
50
+ function createLazyProcedureFormAnyLazy(lazied) {
51
+ const lazyProcedure = lazy(async () => {
52
+ const { default: maybeProcedure } = await unlazy(flatLazy(lazied));
53
+ if (!isProcedure(maybeProcedure)) {
54
+ throw new Error(`
55
+ Expected a lazy<procedure> but got lazy<unknown>.
56
+ This should be caught by TypeScript compilation.
57
+ Please report this issue if this makes you feel uncomfortable.
58
+ `);
59
+ }
60
+ return { default: maybeProcedure };
61
+ });
62
+ return lazyProcedure;
63
+ }
64
+
65
+ // src/middleware.ts
66
+ function middlewareOutputFn(output) {
67
+ return { output, context: {} };
68
+ }
69
+
70
+ // src/procedure-client.ts
71
+ import { createORPCErrorConstructorMap, ORPCError, validateORPCError, ValidationError } from "@orpc/contract";
72
+ import { executeWithHooks, toError, value } from "@orpc/shared";
73
+ function createProcedureClient(lazyableProcedure, ...[options]) {
74
+ return async (...[input, callerOptions]) => {
75
+ const path = options?.path ?? [];
76
+ const { default: procedure } = await unlazy(lazyableProcedure);
77
+ const context = await value(options?.context ?? {}, callerOptions?.context);
78
+ const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
79
+ const executeOptions = {
80
+ input,
81
+ context,
82
+ errors,
83
+ path,
84
+ procedure,
85
+ signal: callerOptions?.signal
86
+ };
87
+ try {
88
+ const output = await executeWithHooks({
89
+ hooks: options,
90
+ input,
91
+ context,
92
+ meta: executeOptions,
93
+ execute: () => executeProcedureInternal(procedure, executeOptions)
94
+ });
95
+ return output;
96
+ } catch (e) {
97
+ if (!(e instanceof ORPCError)) {
98
+ throw toError(e);
99
+ }
100
+ const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
101
+ throw validated;
102
+ }
103
+ };
104
+ }
105
+ async function validateInput(procedure, input) {
106
+ const schema = procedure["~orpc"].inputSchema;
107
+ if (!schema) {
108
+ return input;
109
+ }
110
+ const result = await schema["~standard"].validate(input);
111
+ if (result.issues) {
112
+ throw new ORPCError("BAD_REQUEST", {
113
+ message: "Input validation failed",
114
+ data: {
115
+ issues: result.issues
116
+ },
117
+ cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
118
+ });
119
+ }
120
+ return result.value;
121
+ }
122
+ async function validateOutput(procedure, output) {
123
+ const schema = procedure["~orpc"].outputSchema;
124
+ if (!schema) {
125
+ return output;
126
+ }
127
+ const result = await schema["~standard"].validate(output);
128
+ if (result.issues) {
129
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
130
+ message: "Output validation failed",
131
+ cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
132
+ });
133
+ }
134
+ return result.value;
135
+ }
136
+ async function executeProcedureInternal(procedure, options) {
137
+ const middlewares = procedure["~orpc"].middlewares;
138
+ const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
139
+ const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
140
+ let currentIndex = 0;
141
+ let currentContext = options.context;
142
+ let currentInput = options.input;
143
+ const next = async (...[nextOptions]) => {
144
+ const index = currentIndex;
145
+ currentIndex += 1;
146
+ currentContext = { ...currentContext, ...nextOptions?.context };
147
+ if (index === inputValidationIndex) {
148
+ currentInput = await validateInput(procedure, currentInput);
149
+ }
150
+ const mid = middlewares[index];
151
+ const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
152
+ if (index === outputValidationIndex) {
153
+ const validatedOutput = await validateOutput(procedure, result.output);
154
+ return {
155
+ ...result,
156
+ output: validatedOutput
157
+ };
158
+ }
159
+ return result;
160
+ };
161
+ return (await next({})).output;
162
+ }
163
+
164
+ // src/hidden.ts
165
+ var ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_ROUTER_CONTRACT");
166
+ function setRouterContract(obj, contract) {
167
+ return new Proxy(obj, {
168
+ get(target, key) {
169
+ if (key === ROUTER_CONTRACT_SYMBOL) {
170
+ return contract;
171
+ }
172
+ return Reflect.get(target, key);
173
+ }
174
+ });
175
+ }
176
+ function getRouterContract(obj) {
177
+ return obj[ROUTER_CONTRACT_SYMBOL];
178
+ }
179
+ var LAZY_ROUTER_PREFIX_SYMBOL = Symbol("ORPC_LAZY_ROUTER_PREFIX");
180
+ function deepSetLazyRouterPrefix(router, prefix) {
181
+ return new Proxy(router, {
182
+ get(target, key) {
183
+ if (key !== LAZY_ROUTER_PREFIX_SYMBOL) {
184
+ const val = Reflect.get(target, key);
185
+ if (isLazy(val)) {
186
+ return deepSetLazyRouterPrefix(val, prefix);
187
+ }
188
+ return val;
189
+ }
190
+ return prefix;
191
+ }
192
+ });
193
+ }
194
+ function getLazyRouterPrefix(obj) {
195
+ return obj[LAZY_ROUTER_PREFIX_SYMBOL];
196
+ }
197
+
198
+ // src/router.ts
199
+ import { adaptRoute, mergeErrorMap, mergePrefix } from "@orpc/contract";
200
+
201
+ // src/middleware-utils.ts
202
+ function dedupeMiddlewares(compare, middlewares) {
203
+ let min = 0;
204
+ for (let i = 0; i < middlewares.length; i++) {
205
+ const index = compare.indexOf(middlewares[i], min);
206
+ if (index === -1) {
207
+ return middlewares.slice(i);
208
+ }
209
+ min = index + 1;
210
+ }
211
+ return [];
212
+ }
213
+ function mergeMiddlewares(first, second) {
214
+ return [...first, ...dedupeMiddlewares(first, second)];
215
+ }
216
+ function addMiddleware(middlewares, addition) {
217
+ return [...middlewares, addition];
218
+ }
219
+
220
+ // src/router.ts
221
+ function adaptRouter(router, options) {
222
+ if (isLazy(router)) {
223
+ const adapted2 = lazy(async () => {
224
+ const unlaziedRouter = (await unlazy(router)).default;
225
+ const adapted3 = adaptRouter(unlaziedRouter, options);
226
+ return { default: adapted3 };
227
+ });
228
+ const accessible = createAccessibleLazyRouter(adapted2);
229
+ const currentPrefix = getLazyRouterPrefix(router);
230
+ const prefix = currentPrefix ? mergePrefix(options.prefix, currentPrefix) : options.prefix;
231
+ if (prefix) {
232
+ return deepSetLazyRouterPrefix(accessible, prefix);
233
+ }
234
+ return accessible;
235
+ }
236
+ if (isProcedure(router)) {
237
+ const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares);
238
+ const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
239
+ const adapted2 = new Procedure({
240
+ ...router["~orpc"],
241
+ route: adaptRoute(router["~orpc"].route, options),
242
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
243
+ middlewares: newMiddlewares,
244
+ inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
245
+ outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
246
+ });
247
+ return adapted2;
248
+ }
249
+ const adapted = {};
250
+ for (const key in router) {
251
+ adapted[key] = adaptRouter(router[key], options);
252
+ }
253
+ return adapted;
254
+ }
255
+ function getRouterChild(router, ...path) {
256
+ let current = router;
257
+ for (let i = 0; i < path.length; i++) {
258
+ const segment = path[i];
259
+ if (!current) {
260
+ return void 0;
261
+ }
262
+ if (isProcedure(current)) {
263
+ return void 0;
264
+ }
265
+ if (!isLazy(current)) {
266
+ current = current[segment];
267
+ continue;
268
+ }
269
+ const lazied = current;
270
+ const rest = path.slice(i);
271
+ const newLazy = lazy(async () => {
272
+ const unwrapped = await unlazy(lazied);
273
+ if (!unwrapped.default) {
274
+ return unwrapped;
275
+ }
276
+ const next = getRouterChild(unwrapped.default, ...rest);
277
+ return { default: next };
278
+ });
279
+ return flatLazy(newLazy);
280
+ }
281
+ return current;
282
+ }
283
+
284
+ // src/router-accessible-lazy.ts
285
+ function createAccessibleLazyRouter(lazied) {
286
+ const flattenLazy = flatLazy(lazied);
287
+ const recursive = new Proxy(flattenLazy, {
288
+ get(target, key) {
289
+ if (typeof key !== "string") {
290
+ return Reflect.get(target, key);
291
+ }
292
+ const next = getRouterChild(flattenLazy, key);
293
+ return createAccessibleLazyRouter(next);
294
+ }
295
+ });
296
+ return recursive;
297
+ }
298
+
299
+ export {
300
+ __export,
301
+ LAZY_LOADER_SYMBOL,
302
+ lazy,
303
+ isLazy,
304
+ unlazy,
305
+ Procedure,
306
+ isProcedure,
307
+ flatLazy,
308
+ createLazyProcedureFormAnyLazy,
309
+ addMiddleware,
310
+ middlewareOutputFn,
311
+ createProcedureClient,
312
+ setRouterContract,
313
+ getRouterContract,
314
+ deepSetLazyRouterPrefix,
315
+ getLazyRouterPrefix,
316
+ createAccessibleLazyRouter,
317
+ adaptRouter,
318
+ getRouterChild
319
+ };
320
+ //# sourceMappingURL=chunk-KK4SDLC7.js.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-WUOGVGWG.js.map