@orpc/server 1.14.9 → 1.14.11

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 (78) hide show
  1. package/README.md +52 -98
  2. package/dist/adapters/crossws/index.d.mts +45 -21
  3. package/dist/adapters/crossws/index.d.ts +45 -21
  4. package/dist/adapters/crossws/index.mjs +40 -18
  5. package/dist/adapters/fetch/index.d.mts +64 -96
  6. package/dist/adapters/fetch/index.d.ts +64 -96
  7. package/dist/adapters/fetch/index.mjs +34 -139
  8. package/dist/adapters/message-port/index.d.mts +49 -34
  9. package/dist/adapters/message-port/index.d.ts +49 -34
  10. package/dist/adapters/message-port/index.mjs +68 -37
  11. package/dist/adapters/node/index.d.mts +63 -71
  12. package/dist/adapters/node/index.d.ts +63 -71
  13. package/dist/adapters/node/index.mjs +36 -113
  14. package/dist/adapters/standard/index.d.mts +16 -18
  15. package/dist/adapters/standard/index.d.ts +16 -18
  16. package/dist/adapters/standard/index.mjs +5 -5
  17. package/dist/adapters/standard-peer/index.d.mts +12 -14
  18. package/dist/adapters/standard-peer/index.d.ts +12 -14
  19. package/dist/adapters/standard-peer/index.mjs +2 -21
  20. package/dist/adapters/websocket/index.d.mts +53 -38
  21. package/dist/adapters/websocket/index.d.ts +53 -38
  22. package/dist/adapters/websocket/index.mjs +59 -42
  23. package/dist/extensions/callable.d.mts +10 -0
  24. package/dist/extensions/callable.d.ts +10 -0
  25. package/dist/extensions/callable.mjs +11 -0
  26. package/dist/helpers/index.d.mts +4 -4
  27. package/dist/helpers/index.d.ts +4 -4
  28. package/dist/helpers/index.mjs +13 -5
  29. package/dist/index.d.mts +166 -770
  30. package/dist/index.d.ts +166 -770
  31. package/dist/index.mjs +306 -399
  32. package/dist/plugins/index.d.mts +214 -121
  33. package/dist/plugins/index.d.ts +214 -121
  34. package/dist/plugins/index.mjs +576 -214
  35. package/dist/shared/server.15O7oC1p.d.mts +61 -0
  36. package/dist/shared/server.B4BnEWWm.d.mts +67 -0
  37. package/dist/shared/server.BhsVw7m7.d.ts +104 -0
  38. package/dist/shared/server.BoiFpNT7.mjs +224 -0
  39. package/dist/shared/server.COPVXhDG.mjs +271 -0
  40. package/dist/shared/server.CX4vUnDk.mjs +11 -0
  41. package/dist/shared/server.CcR4kgje.d.mts +206 -0
  42. package/dist/shared/server.CcR4kgje.d.ts +206 -0
  43. package/dist/shared/server.CnN50DHH.d.ts +67 -0
  44. package/dist/shared/server.DBs0rrf9.mjs +41 -0
  45. package/dist/shared/server.DDFizwfU.d.mts +104 -0
  46. package/dist/shared/server.D_QauotT.mjs +30 -0
  47. package/dist/shared/server.DofEOwf-.mjs +237 -0
  48. package/dist/shared/{server.DZ5BIITo.mjs → server.W91HSRkE.mjs} +2 -2
  49. package/dist/shared/server.m3szVJGU.d.ts +61 -0
  50. package/package.json +26 -56
  51. package/dist/adapters/aws-lambda/index.d.mts +0 -46
  52. package/dist/adapters/aws-lambda/index.d.ts +0 -46
  53. package/dist/adapters/aws-lambda/index.mjs +0 -40
  54. package/dist/adapters/bun-ws/index.d.mts +0 -36
  55. package/dist/adapters/bun-ws/index.d.ts +0 -36
  56. package/dist/adapters/bun-ws/index.mjs +0 -47
  57. package/dist/adapters/fastify/index.d.mts +0 -53
  58. package/dist/adapters/fastify/index.d.ts +0 -53
  59. package/dist/adapters/fastify/index.mjs +0 -52
  60. package/dist/adapters/ws/index.d.mts +0 -31
  61. package/dist/adapters/ws/index.d.ts +0 -31
  62. package/dist/adapters/ws/index.mjs +0 -41
  63. package/dist/hibernation/index.d.mts +0 -44
  64. package/dist/hibernation/index.d.ts +0 -44
  65. package/dist/hibernation/index.mjs +0 -65
  66. package/dist/shared/server.7cEtMB30.d.ts +0 -74
  67. package/dist/shared/server.B8gYOD5g.d.mts +0 -12
  68. package/dist/shared/server.BqadksTP.d.mts +0 -74
  69. package/dist/shared/server.C8_sRzQB.d.mts +0 -42
  70. package/dist/shared/server.ChUyt5-i.d.mts +0 -32
  71. package/dist/shared/server.ChyoA9XY.d.ts +0 -42
  72. package/dist/shared/server.DEBcqOjg.mjs +0 -418
  73. package/dist/shared/server.EfTOZ2Q7.d.ts +0 -12
  74. package/dist/shared/server.TEVCLCFC.mjs +0 -39
  75. package/dist/shared/server.ZxHCEN1h.mjs +0 -226
  76. package/dist/shared/server.qKsRrdxW.d.mts +0 -193
  77. package/dist/shared/server.qKsRrdxW.d.ts +0 -193
  78. package/dist/shared/server.yoEB3Fx4.d.ts +0 -32
@@ -0,0 +1,61 @@
1
+ import { RouterContract, ProcedureContract, ORPCErrorFromErrorMap, ThrowableError, InferSchemaInput, InferSchemaOutput } from '@orpc/contract';
2
+ import { C as Context, a as Procedure, L as Lazyable, M as MergedContext } from './server.CcR4kgje.mjs';
3
+
4
+ type Router<TInitialContext extends Context> = Procedure<TInitialContext, any, any, any, any, any> | {
5
+ [k: string]: Lazyable<Router<TInitialContext>>;
6
+ };
7
+ type ContractedRouter<T extends RouterContract, TInitialContext extends Context> = T extends ProcedureContract<infer $InputSchema, infer $OutputSchema, infer $ErrorMap> ? Procedure<TInitialContext, any, $InputSchema, $OutputSchema, $ErrorMap, never> : {
8
+ [K in keyof T]: T[K] extends RouterContract ? Lazyable<ContractedRouter<T[K], TInitialContext>> : never;
9
+ };
10
+ type AnyRouter = Router<any>;
11
+ type InferRouterInitialContext<T extends AnyRouter> = T extends Router<infer $> ? $ : never;
12
+ /**
13
+ * Infer all initial context of the router.
14
+ *
15
+ * @info A procedure is a router too.
16
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
17
+ */
18
+ type InferRouterInitialContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, any, any, any, any, any> ? UInitialContext : {
19
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInitialContexts<U> : never;
20
+ };
21
+ /**
22
+ * Infer all current context of the router.
23
+ *
24
+ * @info A procedure is a router too.
25
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
26
+ */
27
+ type InferRouterFinalContexts<T extends AnyRouter> = T extends Procedure<infer UInitialContext, infer UInjectedContext, any, any, any, any> ? MergedContext<UInitialContext, UInjectedContext> : {
28
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterFinalContexts<U> : never;
29
+ };
30
+ /**
31
+ * Infer all router inputs
32
+ *
33
+ * @info A procedure is a router too.
34
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
35
+ */
36
+ type InferRouterInputs<T extends AnyRouter> = T extends Procedure<any, any, infer UInputSchema, any, any, any> ? InferSchemaInput<UInputSchema> : {
37
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterInputs<U> : never;
38
+ };
39
+ /**
40
+ * Infer all router outputs
41
+ *
42
+ * @info A procedure is a router too.
43
+ * @see {@link https://orpc.dev/docs/router#utilities Router Utilities Docs}
44
+ */
45
+ type InferRouterOutputs<T extends AnyRouter> = T extends Procedure<any, any, any, infer UOutputSchema, any, any> ? InferSchemaOutput<UOutputSchema> : {
46
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterOutputs<U> : never;
47
+ };
48
+ /**
49
+ * Infer the union of throwable errors for entire router.
50
+ */
51
+ type InferRouterError<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
52
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterError<U> : never;
53
+ }[keyof T];
54
+ /**
55
+ * Infer throwable errors for each procedure, preserving the router shape.
56
+ */
57
+ type InferRouterErrors<T extends AnyRouter> = T extends Procedure<any, any, any, any, infer UErrorMap, infer UReturnedError> ? ORPCErrorFromErrorMap<UErrorMap> | UReturnedError | ThrowableError : {
58
+ [K in keyof T]: T[K] extends Lazyable<infer U extends AnyRouter> ? InferRouterErrors<U> : never;
59
+ };
60
+
61
+ export type { AnyRouter as A, ContractedRouter as C, InferRouterInitialContext as I, Router as R, InferRouterError as a, InferRouterErrors as b, InferRouterFinalContexts as c, InferRouterInitialContexts as d, InferRouterInputs as e, InferRouterOutputs as f };
@@ -0,0 +1,67 @@
1
+ import { RPCSerializer, AnyORPCError } from '@orpc/client';
2
+ import { Value, Promisable } from '@orpc/shared';
3
+ import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
+ import { A as AnyProcedure, C as Context } from './server.CcR4kgje.mjs';
5
+ import { A as AnyRouter } from './server.15O7oC1p.mjs';
6
+ import { AnyProcedureContract } from '@orpc/contract';
7
+ import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.DDFizwfU.mjs';
8
+
9
+ interface RPCMatcherOptions {
10
+ /**
11
+ * Filter which procedures are exposed for matching. Return `false` to exclude.
12
+ *
13
+ * @default true
14
+ */
15
+ filter?: Value<boolean, [procedure: AnyProcedureContract | AnyProcedure, path: string[]]>;
16
+ }
17
+ declare class RPCMatcher {
18
+ private readonly filter;
19
+ private readonly rootRouter;
20
+ private readonly tree;
21
+ private pendingLazyRouters;
22
+ constructor(router: AnyRouter, options?: RPCMatcherOptions);
23
+ private index;
24
+ match(_method: StandardMethod, pathname: `/${string}`, prefix: `/${string}` | undefined): Promise<{
25
+ path: string[];
26
+ procedure: AnyProcedure;
27
+ } | undefined>;
28
+ private matchPathname;
29
+ private resolvePendingLazyRouters;
30
+ private resolveProcedure;
31
+ }
32
+
33
+ interface RPCHandlerCodecOptions<T extends Context> extends RPCMatcherOptions {
34
+ /**
35
+ * Override the default RPC serializer.
36
+ */
37
+ serializer?: Pick<RPCSerializer, keyof RPCSerializer>;
38
+ /**
39
+ * Resolve HTTP status for encoded successful outputs.
40
+ *
41
+ * Value should be in the `2xx` range and must be less than `400`.
42
+ * Return `undefined` or `null` to fallback to default
43
+ *
44
+ * @default DEFAULT_SUCCESS_STATUS (200)
45
+ */
46
+ outputStatus?: Value<number | undefined | null, [output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>]>;
47
+ /**
48
+ * Mapping ORPCError Code -> HTTP Status Code
49
+ * The status code should be in the `4xx` or `5xx` range (must be greater than or equal to `400`).
50
+ *
51
+ * @default COMMON_ERROR_STATUS_MAP
52
+ */
53
+ errorStatusMap?: Record<string, number> | undefined;
54
+ }
55
+ declare class RPCHandlerCodec<T extends Context> implements StandardHandlerCodec<T> {
56
+ private readonly matcher;
57
+ private readonly serializer;
58
+ private readonly errorStatusMap;
59
+ private readonly outputStatus;
60
+ constructor(router: AnyRouter, options?: RPCHandlerCodecOptions<T>);
61
+ resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promise<StandardHandlerCodecResolvedProcedure | undefined>;
62
+ encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
63
+ encodeError(error: AnyORPCError, _procedure: AnyProcedure, _path: string[], _options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
64
+ }
65
+
66
+ export { RPCHandlerCodec as a, RPCMatcher as b };
67
+ export type { RPCHandlerCodecOptions as R, RPCMatcherOptions as c };
@@ -0,0 +1,104 @@
1
+ import { AnyORPCError } from '@orpc/client';
2
+ import { OrderablePlugin, Interceptor, Promisable } from '@orpc/shared';
3
+ import { StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
+ import { C as Context, c as ProcedureClientInterceptor, A as AnyProcedure } from './server.CcR4kgje.js';
5
+ import { Schema, ErrorMap } from '@orpc/contract';
6
+
7
+ interface StandardHandlerPlugin<T extends Context> extends OrderablePlugin {
8
+ /**
9
+ * Initializes the plugin and returns new handler options.
10
+ * Called once per plugin instance during composition.
11
+ *
12
+ * This method allows plugins to wrap, extend, or transform handler options
13
+ * such as interceptors, or configuration.
14
+ *
15
+ * @param options - The current handler options from previous plugins or base configuration
16
+ * @returns Transformed handler options with plugin's modifications applied
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * init(options) {
21
+ * return {
22
+ * ...options,
23
+ * interceptors: [...(options.interceptors || []), myInterceptor]
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ init?(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
29
+ }
30
+ declare class CompositeStandardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
31
+ readonly name = "~composite";
32
+ protected readonly plugins: StandardHandlerPlugin<T>[];
33
+ constructor(plugins?: StandardHandlerPlugin<T>[]);
34
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
35
+ }
36
+
37
+ interface StandardHandlerHandleOptions<T extends Context> {
38
+ prefix?: `/${string}` | undefined;
39
+ context: T;
40
+ }
41
+ type StandardHandlerHandleResult = {
42
+ matched: true;
43
+ response: StandardResponse;
44
+ } | {
45
+ matched: false;
46
+ response?: undefined;
47
+ };
48
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandlerCodecResolvedProcedure, StandardHandlerHandleOptions<T> {
49
+ request: StandardLazyRequest;
50
+ }
51
+ type StandardHandlerInterceptor<T extends Context> = Interceptor<StandardHandlerInterceptorOptions<T>, Promise<StandardResponse>>;
52
+ interface StandardHandlerRoutingInterceptorOptions<T extends Context> extends StandardHandlerHandleOptions<T> {
53
+ request: StandardLazyRequest;
54
+ }
55
+ type StandardHandlerRoutingInterceptor<T extends Context> = Interceptor<StandardHandlerRoutingInterceptorOptions<T>, Promise<StandardHandlerHandleResult>>;
56
+ interface StandardHandlerOptions<TContext extends Context> {
57
+ /**
58
+ * Fired on every request before routing, useful when you want
59
+ * to intercept all requests regardless of whether they match a procedure or not.
60
+ *
61
+ * @examples
62
+ * - batch plugins - separate one request into multiple and call multiple next
63
+ * - openapi spec plugin - to intercept a request and early response
64
+ */
65
+ routingInterceptors?: StandardHandlerRoutingInterceptor<TContext>[];
66
+ /**
67
+ * interceptor run after routing and before error handler,
68
+ * useful for error handling, logging, metrics, etc.
69
+ */
70
+ interceptors?: StandardHandlerInterceptor<TContext>[];
71
+ /**
72
+ *
73
+ * ClientInterceptor equivalent with createRouterClient.interceptors / createProcedure.interceptors
74
+ * useful for error handling, logging, metrics, etc. (not counting encoding/decoding)
75
+ */
76
+ clientInterceptors?: ProcedureClientInterceptor<TContext, Schema<unknown>, ErrorMap, any>[];
77
+ plugins?: StandardHandlerPlugin<TContext>[];
78
+ }
79
+ declare class StandardHandler<T extends Context> {
80
+ private readonly codec;
81
+ private readonly routingInterceptors;
82
+ private readonly interceptors;
83
+ private readonly clientInterceptors;
84
+ constructor(codec: StandardHandlerCodec<T>, options: StandardHandlerOptions<T>);
85
+ handle(request: StandardLazyRequest, { context, prefix }: StandardHandlerHandleOptions<T>): Promise<StandardHandlerHandleResult>;
86
+ }
87
+ declare class OtelHandlerPlugin implements StandardHandlerPlugin<any> {
88
+ name: string;
89
+ init(options: StandardHandlerOptions<any>): StandardHandlerOptions<any>;
90
+ }
91
+
92
+ interface StandardHandlerCodecResolvedProcedure {
93
+ path: string[];
94
+ procedure: AnyProcedure;
95
+ decodeInput: () => Promise<unknown>;
96
+ }
97
+ interface StandardHandlerCodec<T extends Context> {
98
+ resolveProcedure(request: StandardLazyRequest, options: StandardHandlerHandleOptions<T>): Promisable<StandardHandlerCodecResolvedProcedure | undefined>;
99
+ encodeOutput(output: unknown, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
100
+ encodeError(error: AnyORPCError, procedure: AnyProcedure, path: string[], options: StandardHandlerHandleOptions<T>): Promisable<StandardResponse>;
101
+ }
102
+
103
+ export { CompositeStandardHandlerPlugin as C, OtelHandlerPlugin as O, StandardHandler as S };
104
+ export type { StandardHandlerOptions as a, StandardHandlerHandleOptions as b, StandardHandlerCodec as c, StandardHandlerCodecResolvedProcedure as d, StandardHandlerPlugin as e, StandardHandlerRoutingInterceptorOptions as f, StandardHandlerInterceptorOptions as g, StandardHandlerHandleResult as h, StandardHandlerInterceptor as i, StandardHandlerRoutingInterceptor as j };
@@ -0,0 +1,224 @@
1
+ import { c as createProcedureClient, P as Procedure, L as Lazy, u as unlazy } from './server.DofEOwf-.mjs';
2
+ import { resolveMetaPlugins, mergeErrorMap, ProcedureContract } from '@orpc/contract';
3
+ import { getOrBind, omit, isTypescriptObject } from '@orpc/shared';
4
+
5
+ const DEFAULT_SUCCESS_STATUS = 200;
6
+ const DEFAULT_ERROR_STATUS = 500;
7
+
8
+ function createGuardedProcedureLazy(lazy) {
9
+ const guarded = new Lazy({
10
+ ...lazy["~orpc"],
11
+ async loader() {
12
+ const { default: maybeProcedure } = await unlazy(lazy);
13
+ if (!(maybeProcedure instanceof Procedure)) {
14
+ throw new TypeError(`
15
+ Expected a lazy<procedure> but got lazy<unknown>.
16
+ This should be caught by TypeScript compilation.
17
+ Please report this issue if you think this is a bug.
18
+ `);
19
+ }
20
+ return { default: maybeProcedure };
21
+ }
22
+ });
23
+ return guarded;
24
+ }
25
+ function createContractProcedure(procedure, contract) {
26
+ return new Procedure({
27
+ ...procedure["~orpc"],
28
+ errorMap: contract["~orpc"].errorMap,
29
+ meta: contract["~orpc"].meta,
30
+ metaPlugins: contract["~orpc"].metaPlugins
31
+ });
32
+ }
33
+ function call(lazyableProcedure, ...[
34
+ input = void 0,
35
+ options = {}
36
+ ]) {
37
+ return createProcedureClient(lazyableProcedure, options)(input, options);
38
+ }
39
+
40
+ const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol.for("ORPC_HIDDEN_ROUTER_CONTRACT");
41
+ function withHiddenRouterContract(router, contract) {
42
+ return new Proxy(router, {
43
+ get(target, key) {
44
+ if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
45
+ return contract;
46
+ }
47
+ return getOrBind(target, key);
48
+ }
49
+ });
50
+ }
51
+ function getHiddenRouterContract(router) {
52
+ return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
53
+ }
54
+
55
+ function augmentRouter(router, options) {
56
+ if (router instanceof Lazy) {
57
+ const [meta, metaPlugins] = resolveMetaPlugins(
58
+ options.meta,
59
+ options.metaPlugins,
60
+ router["~orpc"].metaPlugins
61
+ );
62
+ const enhanced2 = new Lazy({
63
+ meta,
64
+ metaPlugins,
65
+ async loader() {
66
+ const { default: unlaziedRouter } = await unlazy(router);
67
+ const enhanced3 = augmentRouter(unlaziedRouter, options);
68
+ return unlazy(enhanced3);
69
+ }
70
+ });
71
+ return enhanced2;
72
+ }
73
+ if (router instanceof Procedure) {
74
+ const [meta, metaPlugins] = resolveMetaPlugins(
75
+ options.meta,
76
+ options.metaPlugins,
77
+ router["~orpc"].metaPlugins
78
+ );
79
+ const enhanced2 = new Procedure({
80
+ ...omit(options, ["middlewares", "errorMap", "meta", "metaPlugins"]),
81
+ ...router["~orpc"],
82
+ meta,
83
+ metaPlugins,
84
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
85
+ orderedMiddlewares: [
86
+ ...options.middlewares.map((middleware) => ({ middleware, inputSchemasLengthAtUse: 0, outputSchemasLengthAtUse: 0 })),
87
+ ...router["~orpc"].orderedMiddlewares
88
+ ]
89
+ });
90
+ return enhanced2;
91
+ }
92
+ if (!isTypescriptObject(router)) {
93
+ return router;
94
+ }
95
+ const enhanced = {};
96
+ for (const key in router) {
97
+ enhanced[key] = augmentRouter(router[key], options);
98
+ }
99
+ return enhanced;
100
+ }
101
+ function augmentImplementedRouter(router, options) {
102
+ if (router instanceof Lazy) {
103
+ const enhanced2 = new Lazy({
104
+ ...router["~orpc"],
105
+ async loader() {
106
+ const { default: unlaziedRouter } = await unlazy(router);
107
+ const enhanced3 = augmentImplementedRouter(unlaziedRouter, options);
108
+ return unlazy(enhanced3);
109
+ }
110
+ });
111
+ return enhanced2;
112
+ }
113
+ if (router instanceof Procedure) {
114
+ const enhanced2 = new Procedure({
115
+ ...omit(options, ["middlewares"]),
116
+ ...router["~orpc"],
117
+ orderedMiddlewares: [
118
+ ...options.middlewares.map((middleware) => ({ middleware, inputSchemasLengthAtUse: 0, outputSchemasLengthAtUse: 0 })),
119
+ ...router["~orpc"].orderedMiddlewares
120
+ ]
121
+ });
122
+ return enhanced2;
123
+ }
124
+ if (!isTypescriptObject(router)) {
125
+ return router;
126
+ }
127
+ const enhanced = {};
128
+ for (const key in router) {
129
+ enhanced[key] = augmentImplementedRouter(router[key], options);
130
+ }
131
+ return enhanced;
132
+ }
133
+ function getRouter(router, path) {
134
+ let current = router;
135
+ for (let i = 0; i < path.length; i++) {
136
+ const segment = path[i];
137
+ if (!isTypescriptObject(current)) {
138
+ return void 0;
139
+ }
140
+ if (current instanceof Procedure) {
141
+ return void 0;
142
+ }
143
+ if (!(current instanceof Lazy)) {
144
+ current = current[segment];
145
+ continue;
146
+ }
147
+ const lazied = current;
148
+ const rest = path.slice(i);
149
+ return new Lazy({
150
+ ...lazied["~orpc"],
151
+ async loader() {
152
+ const unwrapped = await unlazy(lazied);
153
+ const next = getRouter(unwrapped.default, rest);
154
+ return await unlazy(next);
155
+ }
156
+ });
157
+ }
158
+ if (!isTypescriptObject(current)) {
159
+ return void 0;
160
+ }
161
+ return current;
162
+ }
163
+ function walkProcedureContractsSync(router, callback, path = []) {
164
+ const hiddenContract = getHiddenRouterContract(router);
165
+ if (hiddenContract !== void 0) {
166
+ router = hiddenContract;
167
+ }
168
+ if (router instanceof ProcedureContract) {
169
+ callback(router, path);
170
+ return [];
171
+ }
172
+ if (!isTypescriptObject(router)) {
173
+ return [];
174
+ }
175
+ const lazyResults = [];
176
+ for (const key in router) {
177
+ const value = router[key];
178
+ if (value instanceof Lazy) {
179
+ lazyResults.push({ router: value, path: [...path, key] });
180
+ } else {
181
+ lazyResults.push(...walkProcedureContractsSync(value, callback, [...path, key]));
182
+ }
183
+ }
184
+ return lazyResults;
185
+ }
186
+ async function walkProcedureContractsAsync(router, callback, path = []) {
187
+ const hiddenContract = getHiddenRouterContract(router);
188
+ if (hiddenContract !== void 0) {
189
+ router = hiddenContract;
190
+ }
191
+ if (router instanceof ProcedureContract) {
192
+ await callback(router, path);
193
+ return;
194
+ }
195
+ if (!isTypescriptObject(router)) {
196
+ return;
197
+ }
198
+ for (const key in router) {
199
+ const value = router[key];
200
+ if (value instanceof Lazy) {
201
+ const { default: router2 } = await unlazy(value);
202
+ await walkProcedureContractsAsync(router2, callback, [...path, key]);
203
+ } else {
204
+ await walkProcedureContractsAsync(value, callback, [...path, key]);
205
+ }
206
+ }
207
+ }
208
+ async function unlazyRouter(router) {
209
+ if (router instanceof Procedure) {
210
+ return router;
211
+ }
212
+ if (!isTypescriptObject(router)) {
213
+ return router;
214
+ }
215
+ const unlazied = {};
216
+ for (const key in router) {
217
+ const item = router[key];
218
+ const { default: unlaziedRouter } = await unlazy(item);
219
+ unlazied[key] = await unlazyRouter(unlaziedRouter);
220
+ }
221
+ return unlazied;
222
+ }
223
+
224
+ export { DEFAULT_SUCCESS_STATUS as D, DEFAULT_ERROR_STATUS as a, augmentRouter as b, createContractProcedure as c, augmentImplementedRouter as d, withHiddenRouterContract as e, createGuardedProcedureLazy as f, getRouter as g, call as h, getHiddenRouterContract as i, walkProcedureContractsAsync as j, unlazyRouter as u, walkProcedureContractsSync as w };