@orpc/server 0.0.0-next.9b3a030 → 0.0.0-next.9fc14d1

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 (76) hide show
  1. package/README.md +120 -0
  2. package/dist/adapters/fetch/index.d.mts +28 -0
  3. package/dist/adapters/fetch/index.d.ts +28 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +21 -0
  6. package/dist/adapters/hono/index.d.ts +21 -0
  7. package/dist/adapters/hono/index.mjs +32 -0
  8. package/dist/adapters/next/index.d.mts +28 -0
  9. package/dist/adapters/next/index.d.ts +28 -0
  10. package/dist/adapters/next/index.mjs +29 -0
  11. package/dist/adapters/node/index.d.mts +36 -0
  12. package/dist/adapters/node/index.d.ts +36 -0
  13. package/dist/adapters/node/index.mjs +32 -0
  14. package/dist/adapters/standard/index.d.mts +26 -0
  15. package/dist/adapters/standard/index.d.ts +26 -0
  16. package/dist/adapters/standard/index.mjs +6 -0
  17. package/dist/index.d.mts +278 -0
  18. package/dist/index.d.ts +278 -0
  19. package/dist/index.mjs +346 -0
  20. package/dist/plugins/index.d.mts +31 -0
  21. package/dist/plugins/index.d.ts +31 -0
  22. package/dist/plugins/index.mjs +103 -0
  23. package/dist/shared/server.BXfgvxK8.d.ts +8 -0
  24. package/dist/shared/server.B_5ZADvP.mjs +363 -0
  25. package/dist/shared/server.D1vPuPwc.mjs +29 -0
  26. package/dist/shared/server.DKCNBSd-.d.mts +8 -0
  27. package/dist/shared/server.DisswUB5.mjs +158 -0
  28. package/dist/shared/server.Dj89-yLZ.d.ts +75 -0
  29. package/dist/shared/server.DnmJuN02.d.mts +144 -0
  30. package/dist/shared/server.DnmJuN02.d.ts +144 -0
  31. package/dist/shared/server.DpIMjOfC.d.mts +75 -0
  32. package/dist/shared/server.Q6ZmnTgO.mjs +12 -0
  33. package/package.json +36 -24
  34. package/dist/chunk-DNG2IB3R.js +0 -227
  35. package/dist/chunk-V3I7RIRY.js +0 -302
  36. package/dist/chunk-WUOGVGWG.js +0 -1
  37. package/dist/fetch.js +0 -15
  38. package/dist/hono.js +0 -30
  39. package/dist/index.js +0 -545
  40. package/dist/next.js +0 -36
  41. package/dist/node.js +0 -87
  42. package/dist/src/adapters/fetch/index.d.ts +0 -6
  43. package/dist/src/adapters/fetch/orpc-handler.d.ts +0 -20
  44. package/dist/src/adapters/fetch/orpc-payload-codec.d.ts +0 -16
  45. package/dist/src/adapters/fetch/orpc-procedure-matcher.d.ts +0 -12
  46. package/dist/src/adapters/fetch/super-json.d.ts +0 -12
  47. package/dist/src/adapters/fetch/types.d.ts +0 -21
  48. package/dist/src/adapters/hono/index.d.ts +0 -3
  49. package/dist/src/adapters/hono/middleware.d.ts +0 -12
  50. package/dist/src/adapters/next/index.d.ts +0 -3
  51. package/dist/src/adapters/next/serve.d.ts +0 -19
  52. package/dist/src/adapters/node/index.d.ts +0 -5
  53. package/dist/src/adapters/node/orpc-handler.d.ts +0 -12
  54. package/dist/src/adapters/node/request-listener.d.ts +0 -28
  55. package/dist/src/adapters/node/types.d.ts +0 -22
  56. package/dist/src/builder.d.ts +0 -36
  57. package/dist/src/error.d.ts +0 -10
  58. package/dist/src/hidden.d.ts +0 -6
  59. package/dist/src/implementer-chainable.d.ts +0 -10
  60. package/dist/src/index.d.ts +0 -24
  61. package/dist/src/lazy-decorated.d.ts +0 -10
  62. package/dist/src/lazy-utils.d.ts +0 -4
  63. package/dist/src/lazy.d.ts +0 -18
  64. package/dist/src/middleware-decorated.d.ts +0 -9
  65. package/dist/src/middleware.d.ts +0 -35
  66. package/dist/src/procedure-builder.d.ts +0 -24
  67. package/dist/src/procedure-client.d.ts +0 -34
  68. package/dist/src/procedure-decorated.d.ts +0 -15
  69. package/dist/src/procedure-implementer.d.ts +0 -19
  70. package/dist/src/procedure.d.ts +0 -43
  71. package/dist/src/router-builder.d.ts +0 -29
  72. package/dist/src/router-client.d.ts +0 -25
  73. package/dist/src/router-implementer.d.ts +0 -21
  74. package/dist/src/router.d.ts +0 -16
  75. package/dist/src/types.d.ts +0 -14
  76. package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,31 @@
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.DpIMjOfC.mjs';
2
+ export { C as CompositePlugin } from '../shared/server.DpIMjOfC.mjs';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.DnmJuN02.mjs';
5
+ import '@orpc/contract';
6
+ import '@orpc/standard-server';
7
+ import '@orpc/client';
8
+
9
+ interface CORSOptions<TContext extends Context> {
10
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: readonly string[];
13
+ allowHeaders?: readonly string[];
14
+ maxAge?: number;
15
+ credentials?: boolean;
16
+ exposeHeaders?: readonly string[];
17
+ }
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
+ private readonly options;
20
+ constructor(options?: CORSOptions<TContext>);
21
+ init(options: StandardHandlerOptions<TContext>): void;
22
+ }
23
+
24
+ interface ResponseHeadersPluginContext {
25
+ resHeaders?: Headers;
26
+ }
27
+ declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
+ init(options: StandardHandlerOptions<TContext>): void;
29
+ }
30
+
31
+ export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
@@ -0,0 +1,31 @@
1
+ import { b as StandardHandlerInterceptorOptions, H as HandlerPlugin, a as StandardHandlerOptions } from '../shared/server.Dj89-yLZ.js';
2
+ export { C as CompositePlugin } from '../shared/server.Dj89-yLZ.js';
3
+ import { Value } from '@orpc/shared';
4
+ import { C as Context } from '../shared/server.DnmJuN02.js';
5
+ import '@orpc/contract';
6
+ import '@orpc/standard-server';
7
+ import '@orpc/client';
8
+
9
+ interface CORSOptions<TContext extends Context> {
10
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
11
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string, options: StandardHandlerInterceptorOptions<TContext>]>;
12
+ allowMethods?: readonly string[];
13
+ allowHeaders?: readonly string[];
14
+ maxAge?: number;
15
+ credentials?: boolean;
16
+ exposeHeaders?: readonly string[];
17
+ }
18
+ declare class CORSPlugin<TContext extends Context> implements HandlerPlugin<TContext> {
19
+ private readonly options;
20
+ constructor(options?: CORSOptions<TContext>);
21
+ init(options: StandardHandlerOptions<TContext>): void;
22
+ }
23
+
24
+ interface ResponseHeadersPluginContext {
25
+ resHeaders?: Headers;
26
+ }
27
+ declare class ResponseHeadersPlugin<TContext extends ResponseHeadersPluginContext & Context> implements HandlerPlugin<TContext> {
28
+ init(options: StandardHandlerOptions<TContext>): void;
29
+ }
30
+
31
+ export { type CORSOptions, CORSPlugin, HandlerPlugin, ResponseHeadersPlugin, type ResponseHeadersPluginContext };
@@ -0,0 +1,103 @@
1
+ export { C as CompositePlugin } from '../shared/server.Q6ZmnTgO.mjs';
2
+ import { value } from '@orpc/shared';
3
+
4
+ class CORSPlugin {
5
+ options;
6
+ constructor(options = {}) {
7
+ const defaults = {
8
+ origin: (origin) => origin,
9
+ allowMethods: ["GET", "HEAD", "PUT", "POST", "DELETE", "PATCH"]
10
+ };
11
+ this.options = {
12
+ ...defaults,
13
+ ...options
14
+ };
15
+ }
16
+ init(options) {
17
+ options.rootInterceptors ??= [];
18
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
19
+ if (interceptorOptions.request.method === "OPTIONS") {
20
+ const resHeaders = {};
21
+ if (this.options.maxAge !== void 0) {
22
+ resHeaders["access-control-max-age"] = this.options.maxAge.toString();
23
+ }
24
+ if (this.options.allowMethods?.length) {
25
+ resHeaders["access-control-allow-methods"] = this.options.allowMethods.join(",");
26
+ }
27
+ const allowHeaders = this.options.allowHeaders ?? interceptorOptions.request.headers["access-control-request-headers"];
28
+ if (Array.isArray(allowHeaders) && allowHeaders.length) {
29
+ resHeaders["access-control-allow-headers"] = allowHeaders.join(",");
30
+ } else if (typeof allowHeaders === "string") {
31
+ resHeaders["access-control-allow-headers"] = allowHeaders;
32
+ }
33
+ return {
34
+ matched: true,
35
+ response: {
36
+ status: 204,
37
+ headers: resHeaders,
38
+ body: void 0
39
+ }
40
+ };
41
+ }
42
+ return interceptorOptions.next();
43
+ });
44
+ options.rootInterceptors.unshift(async (interceptorOptions) => {
45
+ const result = await interceptorOptions.next();
46
+ if (!result.matched) {
47
+ return result;
48
+ }
49
+ const origin = Array.isArray(interceptorOptions.request.headers.origin) ? interceptorOptions.request.headers.origin.join(",") : interceptorOptions.request.headers.origin || "";
50
+ const allowedOrigin = await value(this.options.origin, origin, interceptorOptions);
51
+ const allowedOriginArr = Array.isArray(allowedOrigin) ? allowedOrigin : [allowedOrigin];
52
+ if (allowedOriginArr.includes("*")) {
53
+ result.response.headers["access-control-allow-origin"] = "*";
54
+ } else {
55
+ if (allowedOriginArr.includes(origin)) {
56
+ result.response.headers["access-control-allow-origin"] = origin;
57
+ }
58
+ result.response.headers.vary = interceptorOptions.request.headers.vary ?? "origin";
59
+ }
60
+ const allowedTimingOrigin = await value(this.options.timingOrigin, origin, interceptorOptions);
61
+ const allowedTimingOriginArr = Array.isArray(allowedTimingOrigin) ? allowedTimingOrigin : [allowedTimingOrigin];
62
+ if (allowedTimingOriginArr.includes("*")) {
63
+ result.response.headers["timing-allow-origin"] = "*";
64
+ } else if (allowedTimingOriginArr.includes(origin)) {
65
+ result.response.headers["timing-allow-origin"] = origin;
66
+ }
67
+ if (this.options.credentials) {
68
+ result.response.headers["access-control-allow-credentials"] = "true";
69
+ }
70
+ if (this.options.exposeHeaders?.length) {
71
+ result.response.headers["access-control-expose-headers"] = this.options.exposeHeaders.join(",");
72
+ }
73
+ return result;
74
+ });
75
+ }
76
+ }
77
+
78
+ class ResponseHeadersPlugin {
79
+ init(options) {
80
+ options.rootInterceptors ??= [];
81
+ options.rootInterceptors.push(async (interceptorOptions) => {
82
+ const headers = new Headers();
83
+ interceptorOptions.context.resHeaders = headers;
84
+ const result = await interceptorOptions.next();
85
+ if (!result.matched) {
86
+ return result;
87
+ }
88
+ const responseHeaders = result.response.headers;
89
+ for (const [key, value] of headers) {
90
+ if (Array.isArray(responseHeaders[key])) {
91
+ responseHeaders[key].push(value);
92
+ } else if (responseHeaders[key] !== void 0) {
93
+ responseHeaders[key] = [responseHeaders[key], value];
94
+ } else {
95
+ responseHeaders[key] = value;
96
+ }
97
+ }
98
+ return result;
99
+ });
100
+ }
101
+ }
102
+
103
+ export { CORSPlugin, ResponseHeadersPlugin };
@@ -0,0 +1,8 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context } from './server.DnmJuN02.js';
3
+ import { a as StandardHandlerOptions } from './server.Dj89-yLZ.js';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ }
7
+
8
+ export type { StandardRPCHandlerOptions as S };
@@ -0,0 +1,363 @@
1
+ import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
2
+ import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
3
+ import { value, intercept, toError } from '@orpc/shared';
4
+
5
+ const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
6
+ function lazy(loader, meta = {}) {
7
+ return {
8
+ [LAZY_SYMBOL]: {
9
+ loader,
10
+ meta
11
+ }
12
+ };
13
+ }
14
+ function isLazy(item) {
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;
19
+ }
20
+ function unlazy(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];
46
+ }
47
+
48
+ class Procedure {
49
+ "~orpc";
50
+ constructor(def) {
51
+ this["~orpc"] = def;
52
+ }
53
+ }
54
+ function isProcedure(item) {
55
+ if (item instanceof Procedure) {
56
+ return true;
57
+ }
58
+ return isContractProcedure(item) && "middlewares" in item["~orpc"] && "inputValidationIndex" in item["~orpc"] && "outputValidationIndex" in item["~orpc"] && "handler" in item["~orpc"];
59
+ }
60
+
61
+ function createORPCErrorConstructorMap(errors) {
62
+ const proxy = new Proxy(errors, {
63
+ get(target, code) {
64
+ if (typeof code !== "string") {
65
+ return Reflect.get(target, code);
66
+ }
67
+ const item = (...[options]) => {
68
+ const config = errors[code];
69
+ return new ORPCError(code, {
70
+ defined: Boolean(config),
71
+ status: config?.status,
72
+ message: options?.message ?? config?.message,
73
+ data: options?.data,
74
+ cause: options?.cause
75
+ });
76
+ };
77
+ return item;
78
+ }
79
+ });
80
+ return proxy;
81
+ }
82
+ async function validateORPCError(map, error) {
83
+ const { code, status, message, data, cause, defined } = error;
84
+ const config = map?.[error.code];
85
+ if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
86
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
87
+ }
88
+ if (!config.data) {
89
+ return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
90
+ }
91
+ const validated = await config.data["~standard"].validate(error.data);
92
+ if (validated.issues) {
93
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
94
+ }
95
+ return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
96
+ }
97
+
98
+ function middlewareOutputFn(output) {
99
+ return { output, context: {} };
100
+ }
101
+
102
+ function createProcedureClient(lazyableProcedure, ...[options]) {
103
+ return async (...[input, callerOptions]) => {
104
+ const path = options?.path ?? [];
105
+ const { default: procedure } = await unlazy(lazyableProcedure);
106
+ const clientContext = callerOptions?.context ?? {};
107
+ const context = await value(options?.context ?? {}, clientContext);
108
+ const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
109
+ try {
110
+ return await intercept(
111
+ options?.interceptors ?? [],
112
+ {
113
+ context,
114
+ input,
115
+ // input only optional when it undefinable so we can safely cast it
116
+ errors,
117
+ path,
118
+ procedure,
119
+ signal: callerOptions?.signal,
120
+ lastEventId: callerOptions?.lastEventId
121
+ },
122
+ (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
123
+ );
124
+ } catch (e) {
125
+ if (!(e instanceof ORPCError)) {
126
+ throw toError(e);
127
+ }
128
+ const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
129
+ throw validated;
130
+ }
131
+ };
132
+ }
133
+ async function validateInput(procedure, input) {
134
+ const schema = procedure["~orpc"].inputSchema;
135
+ if (!schema) {
136
+ return input;
137
+ }
138
+ const result = await schema["~standard"].validate(input);
139
+ if (result.issues) {
140
+ throw new ORPCError("BAD_REQUEST", {
141
+ message: "Input validation failed",
142
+ data: {
143
+ issues: result.issues
144
+ },
145
+ cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
146
+ });
147
+ }
148
+ return result.value;
149
+ }
150
+ async function validateOutput(procedure, output) {
151
+ const schema = procedure["~orpc"].outputSchema;
152
+ if (!schema) {
153
+ return output;
154
+ }
155
+ const result = await schema["~standard"].validate(output);
156
+ if (result.issues) {
157
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
158
+ message: "Output validation failed",
159
+ cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
160
+ });
161
+ }
162
+ return result.value;
163
+ }
164
+ async function executeProcedureInternal(procedure, options) {
165
+ const middlewares = procedure["~orpc"].middlewares;
166
+ const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
167
+ const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
168
+ let currentIndex = 0;
169
+ let currentContext = options.context;
170
+ let currentInput = options.input;
171
+ const next = async (...[nextOptions]) => {
172
+ const index = currentIndex;
173
+ currentIndex += 1;
174
+ currentContext = { ...currentContext, ...nextOptions?.context };
175
+ if (index === inputValidationIndex) {
176
+ currentInput = await validateInput(procedure, currentInput);
177
+ }
178
+ const mid = middlewares[index];
179
+ const result = mid ? await mid({ ...options, context: currentContext, next }, currentInput, middlewareOutputFn) : { output: await procedure["~orpc"].handler({ ...options, context: currentContext, input: currentInput }), context: currentContext };
180
+ if (index === outputValidationIndex) {
181
+ const validatedOutput = await validateOutput(procedure, result.output);
182
+ return {
183
+ ...result,
184
+ output: validatedOutput
185
+ };
186
+ }
187
+ return result;
188
+ };
189
+ return (await next({})).output;
190
+ }
191
+
192
+ const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
193
+ function setHiddenRouterContract(router, contract) {
194
+ return new Proxy(router, {
195
+ get(target, key) {
196
+ if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
197
+ return contract;
198
+ }
199
+ return Reflect.get(target, key);
200
+ }
201
+ });
202
+ }
203
+ function getHiddenRouterContract(router) {
204
+ return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
205
+ }
206
+
207
+ function getRouter(router, path) {
208
+ let current = router;
209
+ for (let i = 0; i < path.length; i++) {
210
+ const segment = path[i];
211
+ if (!current) {
212
+ return void 0;
213
+ }
214
+ if (isProcedure(current)) {
215
+ return void 0;
216
+ }
217
+ if (!isLazy(current)) {
218
+ current = current[segment];
219
+ continue;
220
+ }
221
+ const lazied = current;
222
+ const rest = path.slice(i);
223
+ return lazy(async () => {
224
+ const unwrapped = await unlazy(lazied);
225
+ const next = getRouter(unwrapped.default, rest);
226
+ return unlazy(next);
227
+ }, getLazyMeta(lazied));
228
+ }
229
+ return current;
230
+ }
231
+ function createAccessibleLazyRouter(lazied) {
232
+ const recursive = new Proxy(lazied, {
233
+ get(target, key) {
234
+ if (typeof key !== "string") {
235
+ return Reflect.get(target, key);
236
+ }
237
+ const next = getRouter(lazied, [key]);
238
+ return createAccessibleLazyRouter(next);
239
+ }
240
+ });
241
+ return recursive;
242
+ }
243
+ function enhanceRouter(router, options) {
244
+ if (isLazy(router)) {
245
+ const laziedMeta = getLazyMeta(router);
246
+ const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
247
+ const enhanced2 = lazy(async () => {
248
+ const { default: unlaziedRouter } = await unlazy(router);
249
+ const enhanced3 = enhanceRouter(unlaziedRouter, options);
250
+ return unlazy(enhanced3);
251
+ }, {
252
+ ...laziedMeta,
253
+ prefix: enhancedPrefix
254
+ });
255
+ const accessible = createAccessibleLazyRouter(enhanced2);
256
+ return accessible;
257
+ }
258
+ if (isProcedure(router)) {
259
+ const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
260
+ const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
261
+ const enhanced2 = new Procedure({
262
+ ...router["~orpc"],
263
+ route: enhanceRoute(router["~orpc"].route, options),
264
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
265
+ middlewares: newMiddlewares,
266
+ inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
267
+ outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
268
+ });
269
+ return enhanced2;
270
+ }
271
+ const enhanced = {};
272
+ for (const key in router) {
273
+ enhanced[key] = enhanceRouter(router[key], options);
274
+ }
275
+ return enhanced;
276
+ }
277
+ function traverseContractProcedures(options, callback, lazyOptions = []) {
278
+ let currentRouter = options.router;
279
+ const hiddenContract = getHiddenRouterContract(options.router);
280
+ if (hiddenContract !== void 0) {
281
+ currentRouter = hiddenContract;
282
+ }
283
+ if (isLazy(currentRouter)) {
284
+ lazyOptions.push({
285
+ router: currentRouter,
286
+ path: options.path
287
+ });
288
+ } else if (isContractProcedure(currentRouter)) {
289
+ callback({
290
+ contract: currentRouter,
291
+ path: options.path
292
+ });
293
+ } else {
294
+ for (const key in currentRouter) {
295
+ traverseContractProcedures(
296
+ {
297
+ router: currentRouter[key],
298
+ path: [...options.path, key]
299
+ },
300
+ callback,
301
+ lazyOptions
302
+ );
303
+ }
304
+ }
305
+ return lazyOptions;
306
+ }
307
+ async function resolveContractProcedures(options, callback) {
308
+ const pending = [options];
309
+ for (const options2 of pending) {
310
+ const lazyOptions = traverseContractProcedures(options2, callback);
311
+ for (const options3 of lazyOptions) {
312
+ const { default: router } = await unlazy(options3.router);
313
+ pending.push({
314
+ router,
315
+ path: options3.path
316
+ });
317
+ }
318
+ }
319
+ }
320
+ async function unlazyRouter(router) {
321
+ if (isProcedure(router)) {
322
+ return router;
323
+ }
324
+ const unlazied = {};
325
+ for (const key in router) {
326
+ const item = router[key];
327
+ const { default: unlaziedRouter } = await unlazy(item);
328
+ unlazied[key] = await unlazyRouter(unlaziedRouter);
329
+ }
330
+ return unlazied;
331
+ }
332
+
333
+ function createAssertedLazyProcedure(lazied) {
334
+ const lazyProcedure = lazy(async () => {
335
+ const { default: maybeProcedure } = await unlazy(lazied);
336
+ if (!isProcedure(maybeProcedure)) {
337
+ throw new Error(`
338
+ Expected a lazy<procedure> but got lazy<unknown>.
339
+ This should be caught by TypeScript compilation.
340
+ Please report this issue if this makes you feel uncomfortable.
341
+ `);
342
+ }
343
+ return { default: maybeProcedure };
344
+ }, getLazyMeta(lazied));
345
+ return lazyProcedure;
346
+ }
347
+ function createContractedProcedure(procedure, contract) {
348
+ return new Procedure({
349
+ ...procedure["~orpc"],
350
+ errorMap: contract["~orpc"].errorMap,
351
+ route: contract["~orpc"].route,
352
+ meta: contract["~orpc"].meta
353
+ });
354
+ }
355
+ function call(procedure, input, ...rest) {
356
+ return createProcedureClient(procedure, ...rest)(input);
357
+ }
358
+
359
+ function toHttpPath(path) {
360
+ return `/${path.map(encodeURIComponent).join("/")}`;
361
+ }
362
+
363
+ export { LAZY_SYMBOL as L, Procedure as P, toHttpPath as a, createContractedProcedure as b, createProcedureClient as c, addMiddleware as d, enhanceRouter as e, isLazy as f, getRouter as g, createAssertedLazyProcedure as h, isProcedure as i, createORPCErrorConstructorMap as j, getLazyMeta as k, lazy as l, middlewareOutputFn as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
@@ -0,0 +1,29 @@
1
+ import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
2
+ import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
3
+ import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DisswUB5.mjs';
4
+
5
+ class RPCHandler {
6
+ standardHandler;
7
+ constructor(router, options = {}) {
8
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
9
+ const serializer = new StandardRPCSerializer(jsonSerializer);
10
+ const matcher = new StandardRPCMatcher();
11
+ const codec = new StandardRPCCodec(serializer);
12
+ this.standardHandler = new StandardHandler(router, matcher, codec, options);
13
+ }
14
+ async handle(request, ...[
15
+ options = {}
16
+ ]) {
17
+ const standardRequest = toStandardLazyRequest(request);
18
+ const result = await this.standardHandler.handle(standardRequest, options);
19
+ if (!result.matched) {
20
+ return result;
21
+ }
22
+ return {
23
+ matched: true,
24
+ response: toFetchResponse(result.response, options)
25
+ };
26
+ }
27
+ }
28
+
29
+ export { RPCHandler as R };
@@ -0,0 +1,8 @@
1
+ import { StandardRPCJsonSerializerOptions } from '@orpc/client/standard';
2
+ import { C as Context } from './server.DnmJuN02.mjs';
3
+ import { a as StandardHandlerOptions } from './server.DpIMjOfC.mjs';
4
+
5
+ interface StandardRPCHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardRPCJsonSerializerOptions {
6
+ }
7
+
8
+ export type { StandardRPCHandlerOptions as S };