@orpc/server 0.0.0-next.9588d75 → 0.0.0-next.96f9dd3

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 (65) hide show
  1. package/README.md +131 -0
  2. package/dist/adapters/fetch/index.d.mts +54 -0
  3. package/dist/adapters/fetch/index.d.ts +54 -0
  4. package/dist/adapters/fetch/index.mjs +9 -0
  5. package/dist/adapters/hono/index.d.mts +22 -0
  6. package/dist/adapters/hono/index.d.ts +22 -0
  7. package/dist/adapters/hono/index.mjs +32 -0
  8. package/dist/adapters/next/index.d.mts +29 -0
  9. package/dist/adapters/next/index.d.ts +29 -0
  10. package/dist/adapters/next/index.mjs +29 -0
  11. package/dist/adapters/node/index.d.mts +53 -0
  12. package/dist/adapters/node/index.d.ts +53 -0
  13. package/dist/adapters/node/index.mjs +85 -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 +291 -0
  18. package/dist/index.d.ts +291 -0
  19. package/dist/index.mjs +363 -0
  20. package/dist/plugins/index.d.mts +66 -0
  21. package/dist/plugins/index.d.ts +66 -0
  22. package/dist/plugins/index.mjs +196 -0
  23. package/dist/shared/server.BFt8M4Cr.d.ts +8 -0
  24. package/dist/shared/server.BVwwTHyO.mjs +9 -0
  25. package/dist/shared/server.Bc6jnvPE.d.ts +10 -0
  26. package/dist/shared/server.BlxK0o8R.d.mts +66 -0
  27. package/dist/shared/server.C37gDhSZ.mjs +364 -0
  28. package/dist/shared/server.CCPFkKqC.mjs +98 -0
  29. package/dist/shared/server.CCgy73tk.d.mts +10 -0
  30. package/dist/shared/server.DJrRF9vD.mjs +162 -0
  31. package/dist/shared/server.DLt5njUb.d.mts +143 -0
  32. package/dist/shared/server.DLt5njUb.d.ts +143 -0
  33. package/dist/shared/server.DuTpqr2w.d.ts +66 -0
  34. package/dist/shared/server.JgWzFqlo.d.mts +8 -0
  35. package/package.json +43 -15
  36. package/dist/chunk-FN62GL22.js +0 -182
  37. package/dist/fetch.js +0 -286
  38. package/dist/index.js +0 -518
  39. package/dist/src/builder.d.ts +0 -35
  40. package/dist/src/fetch/composite-handler.d.ts +0 -8
  41. package/dist/src/fetch/index.d.ts +0 -6
  42. package/dist/src/fetch/orpc-handler.d.ts +0 -20
  43. package/dist/src/fetch/orpc-payload-codec.d.ts +0 -9
  44. package/dist/src/fetch/orpc-procedure-matcher.d.ts +0 -12
  45. package/dist/src/fetch/super-json.d.ts +0 -12
  46. package/dist/src/fetch/types.d.ts +0 -16
  47. package/dist/src/hidden.d.ts +0 -6
  48. package/dist/src/implementer-chainable.d.ts +0 -10
  49. package/dist/src/index.d.ts +0 -23
  50. package/dist/src/lazy-decorated.d.ts +0 -10
  51. package/dist/src/lazy-utils.d.ts +0 -4
  52. package/dist/src/lazy.d.ts +0 -18
  53. package/dist/src/middleware-decorated.d.ts +0 -8
  54. package/dist/src/middleware.d.ts +0 -23
  55. package/dist/src/procedure-builder.d.ts +0 -22
  56. package/dist/src/procedure-client.d.ts +0 -29
  57. package/dist/src/procedure-decorated.d.ts +0 -14
  58. package/dist/src/procedure-implementer.d.ts +0 -18
  59. package/dist/src/procedure.d.ts +0 -23
  60. package/dist/src/router-builder.d.ts +0 -29
  61. package/dist/src/router-client.d.ts +0 -25
  62. package/dist/src/router-implementer.d.ts +0 -21
  63. package/dist/src/router.d.ts +0 -16
  64. package/dist/src/types.d.ts +0 -12
  65. package/dist/src/utils.d.ts +0 -3
@@ -0,0 +1,9 @@
1
+ function resolveFriendlyStandardHandleOptions(options) {
2
+ return {
3
+ ...options,
4
+ context: options?.context ?? {}
5
+ // Context only optional if all fields are optional
6
+ };
7
+ }
8
+
9
+ export { resolveFriendlyStandardHandleOptions as r };
@@ -0,0 +1,10 @@
1
+ import { C as Context } from './server.DLt5njUb.js';
2
+ import { S as StandardHandleOptions } from './server.DuTpqr2w.js';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+
10
+ export type { FriendlyStandardHandleOptions as F };
@@ -0,0 +1,66 @@
1
+ import { HTTPPath, ORPCError } from '@orpc/client';
2
+ import { Meta, InferSchemaOutput, AnySchema, ErrorFromErrorMap } from '@orpc/contract';
3
+ import { Interceptor, ThrowableError } from '@orpc/shared';
4
+ import { StandardResponse, StandardLazyRequest } from '@orpc/standard-server';
5
+ import { a as AnyRouter, A as AnyProcedure, C as Context, P as ProcedureClientInterceptorOptions, R as Router } from './server.DLt5njUb.mjs';
6
+
7
+ type StandardParams = Record<string, string>;
8
+ type StandardMatchResult = {
9
+ path: readonly string[];
10
+ procedure: AnyProcedure;
11
+ params?: StandardParams;
12
+ } | undefined;
13
+ interface StandardMatcher {
14
+ init(router: AnyRouter): void;
15
+ match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
16
+ }
17
+ interface StandardCodec {
18
+ encode(output: unknown, procedure: AnyProcedure): StandardResponse;
19
+ encodeError(error: ORPCError<any, any>): StandardResponse;
20
+ decode(request: StandardLazyRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
21
+ }
22
+
23
+ interface StandardHandleOptions<T extends Context> {
24
+ prefix?: HTTPPath;
25
+ context: T;
26
+ }
27
+ type StandardHandleResult = {
28
+ matched: true;
29
+ response: StandardResponse;
30
+ } | {
31
+ matched: false;
32
+ response: undefined;
33
+ };
34
+ interface StandardHandlerPlugin<TContext extends Context> {
35
+ init?(options: StandardHandlerOptions<TContext>): void;
36
+ }
37
+ interface StandardHandlerInterceptorOptions<T extends Context> extends StandardHandleOptions<T> {
38
+ request: StandardLazyRequest;
39
+ }
40
+ interface StandardHandlerOptions<TContext extends Context> {
41
+ plugins?: StandardHandlerPlugin<TContext>[];
42
+ /**
43
+ * Interceptors at the request level, helpful when you want catch errors
44
+ */
45
+ interceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
46
+ /**
47
+ * Interceptors at the root level, helpful when you want override the request/response
48
+ */
49
+ rootInterceptors?: Interceptor<StandardHandlerInterceptorOptions<TContext>, StandardHandleResult, ThrowableError>[];
50
+ /**
51
+ *
52
+ * Interceptors for procedure client.
53
+ */
54
+ clientInterceptors?: Interceptor<ProcedureClientInterceptorOptions<TContext, Record<never, never>, Meta>, InferSchemaOutput<AnySchema>, ErrorFromErrorMap<Record<never, never>>>[];
55
+ }
56
+ declare class StandardHandler<T extends Context> {
57
+ private readonly matcher;
58
+ private readonly codec;
59
+ private readonly interceptors;
60
+ private readonly clientInterceptors;
61
+ private readonly rootInterceptors;
62
+ constructor(router: Router<any, T>, matcher: StandardMatcher, codec: StandardCodec, options: NoInfer<StandardHandlerOptions<T>>);
63
+ handle(request: StandardLazyRequest, options: StandardHandleOptions<T>): Promise<StandardHandleResult>;
64
+ }
65
+
66
+ export { type StandardHandleOptions as S, type StandardHandlerOptions as a, type StandardCodec as b, type StandardParams as c, type StandardMatcher as d, type StandardMatchResult as e, type StandardHandleResult as f, type StandardHandlerPlugin as g, type StandardHandlerInterceptorOptions as h, StandardHandler as i };
@@ -0,0 +1,364 @@
1
+ import { isContractProcedure, ValidationError, mergePrefix, mergeErrorMap, enhanceRoute } from '@orpc/contract';
2
+ import { fallbackORPCErrorStatus, ORPCError } from '@orpc/client';
3
+ import { value, intercept } from '@orpc/shared';
4
+
5
+ const LAZY_SYMBOL = Symbol("ORPC_LAZY_SYMBOL");
6
+ function lazy(loader, meta = {}) {
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 mergeCurrentContext(context, other) {
62
+ return { ...context, ...other };
63
+ }
64
+
65
+ function createORPCErrorConstructorMap(errors) {
66
+ const proxy = new Proxy(errors, {
67
+ get(target, code) {
68
+ if (typeof code !== "string") {
69
+ return Reflect.get(target, code);
70
+ }
71
+ const item = (...[options]) => {
72
+ const config = errors[code];
73
+ return new ORPCError(code, {
74
+ defined: Boolean(config),
75
+ status: config?.status,
76
+ message: options?.message ?? config?.message,
77
+ data: options?.data,
78
+ cause: options?.cause
79
+ });
80
+ };
81
+ return item;
82
+ }
83
+ });
84
+ return proxy;
85
+ }
86
+ async function validateORPCError(map, error) {
87
+ const { code, status, message, data, cause, defined } = error;
88
+ const config = map?.[error.code];
89
+ if (!config || fallbackORPCErrorStatus(error.code, config.status) !== error.status) {
90
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
91
+ }
92
+ if (!config.data) {
93
+ return defined ? error : new ORPCError(code, { defined: true, status, message, data, cause });
94
+ }
95
+ const validated = await config.data["~standard"].validate(error.data);
96
+ if (validated.issues) {
97
+ return defined ? new ORPCError(code, { defined: false, status, message, data, cause }) : error;
98
+ }
99
+ return new ORPCError(code, { defined: true, status, message, data: validated.value, cause });
100
+ }
101
+
102
+ function middlewareOutputFn(output) {
103
+ return { output, context: {} };
104
+ }
105
+
106
+ function createProcedureClient(lazyableProcedure, ...[options]) {
107
+ return async (...[input, callerOptions]) => {
108
+ const path = options?.path ?? [];
109
+ const { default: procedure } = await unlazy(lazyableProcedure);
110
+ const clientContext = callerOptions?.context ?? {};
111
+ const context = await value(options?.context ?? {}, clientContext);
112
+ const errors = createORPCErrorConstructorMap(procedure["~orpc"].errorMap);
113
+ try {
114
+ return await intercept(
115
+ options?.interceptors ?? [],
116
+ {
117
+ context,
118
+ input,
119
+ // input only optional when it undefinable so we can safely cast it
120
+ errors,
121
+ path,
122
+ procedure,
123
+ signal: callerOptions?.signal,
124
+ lastEventId: callerOptions?.lastEventId
125
+ },
126
+ (interceptorOptions) => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions)
127
+ );
128
+ } catch (e) {
129
+ if (!(e instanceof ORPCError)) {
130
+ throw e;
131
+ }
132
+ const validated = await validateORPCError(procedure["~orpc"].errorMap, e);
133
+ throw validated;
134
+ }
135
+ };
136
+ }
137
+ async function validateInput(procedure, input) {
138
+ const schema = procedure["~orpc"].inputSchema;
139
+ if (!schema) {
140
+ return input;
141
+ }
142
+ const result = await schema["~standard"].validate(input);
143
+ if (result.issues) {
144
+ throw new ORPCError("BAD_REQUEST", {
145
+ message: "Input validation failed",
146
+ data: {
147
+ issues: result.issues
148
+ },
149
+ cause: new ValidationError({ message: "Input validation failed", issues: result.issues })
150
+ });
151
+ }
152
+ return result.value;
153
+ }
154
+ async function validateOutput(procedure, output) {
155
+ const schema = procedure["~orpc"].outputSchema;
156
+ if (!schema) {
157
+ return output;
158
+ }
159
+ const result = await schema["~standard"].validate(output);
160
+ if (result.issues) {
161
+ throw new ORPCError("INTERNAL_SERVER_ERROR", {
162
+ message: "Output validation failed",
163
+ cause: new ValidationError({ message: "Output validation failed", issues: result.issues })
164
+ });
165
+ }
166
+ return result.value;
167
+ }
168
+ async function executeProcedureInternal(procedure, options) {
169
+ const middlewares = procedure["~orpc"].middlewares;
170
+ const inputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].inputValidationIndex), middlewares.length);
171
+ const outputValidationIndex = Math.min(Math.max(0, procedure["~orpc"].outputValidationIndex), middlewares.length);
172
+ const next = async (index, context, input) => {
173
+ let currentInput = input;
174
+ if (index === inputValidationIndex) {
175
+ currentInput = await validateInput(procedure, currentInput);
176
+ }
177
+ const mid = middlewares[index];
178
+ const output = mid ? (await mid({
179
+ ...options,
180
+ context,
181
+ next: async (...[nextOptions]) => {
182
+ const nextContext = nextOptions?.context ?? {};
183
+ return {
184
+ output: await next(index + 1, mergeCurrentContext(context, nextContext), currentInput),
185
+ context: nextContext
186
+ };
187
+ }
188
+ }, currentInput, middlewareOutputFn)).output : await procedure["~orpc"].handler({ ...options, context, input: currentInput });
189
+ if (index === outputValidationIndex) {
190
+ return await validateOutput(procedure, output);
191
+ }
192
+ return output;
193
+ };
194
+ return next(0, options.context, options.input);
195
+ }
196
+
197
+ const HIDDEN_ROUTER_CONTRACT_SYMBOL = Symbol("ORPC_HIDDEN_ROUTER_CONTRACT");
198
+ function setHiddenRouterContract(router, contract) {
199
+ return new Proxy(router, {
200
+ get(target, key) {
201
+ if (key === HIDDEN_ROUTER_CONTRACT_SYMBOL) {
202
+ return contract;
203
+ }
204
+ return Reflect.get(target, key);
205
+ }
206
+ });
207
+ }
208
+ function getHiddenRouterContract(router) {
209
+ return router[HIDDEN_ROUTER_CONTRACT_SYMBOL];
210
+ }
211
+
212
+ function getRouter(router, path) {
213
+ let current = router;
214
+ for (let i = 0; i < path.length; i++) {
215
+ const segment = path[i];
216
+ if (!current) {
217
+ return void 0;
218
+ }
219
+ if (isProcedure(current)) {
220
+ return void 0;
221
+ }
222
+ if (!isLazy(current)) {
223
+ current = current[segment];
224
+ continue;
225
+ }
226
+ const lazied = current;
227
+ const rest = path.slice(i);
228
+ return lazy(async () => {
229
+ const unwrapped = await unlazy(lazied);
230
+ const next = getRouter(unwrapped.default, rest);
231
+ return unlazy(next);
232
+ }, getLazyMeta(lazied));
233
+ }
234
+ return current;
235
+ }
236
+ function createAccessibleLazyRouter(lazied) {
237
+ const recursive = new Proxy(lazied, {
238
+ get(target, key) {
239
+ if (typeof key !== "string") {
240
+ return Reflect.get(target, key);
241
+ }
242
+ const next = getRouter(lazied, [key]);
243
+ return createAccessibleLazyRouter(next);
244
+ }
245
+ });
246
+ return recursive;
247
+ }
248
+ function enhanceRouter(router, options) {
249
+ if (isLazy(router)) {
250
+ const laziedMeta = getLazyMeta(router);
251
+ const enhancedPrefix = laziedMeta?.prefix ? mergePrefix(options.prefix, laziedMeta?.prefix) : options.prefix;
252
+ const enhanced2 = lazy(async () => {
253
+ const { default: unlaziedRouter } = await unlazy(router);
254
+ const enhanced3 = enhanceRouter(unlaziedRouter, options);
255
+ return unlazy(enhanced3);
256
+ }, {
257
+ ...laziedMeta,
258
+ prefix: enhancedPrefix
259
+ });
260
+ const accessible = createAccessibleLazyRouter(enhanced2);
261
+ return accessible;
262
+ }
263
+ if (isProcedure(router)) {
264
+ const newMiddlewares = mergeMiddlewares(options.middlewares, router["~orpc"].middlewares, { dedupeLeading: options.dedupeLeadingMiddlewares });
265
+ const newMiddlewareAdded = newMiddlewares.length - router["~orpc"].middlewares.length;
266
+ const enhanced2 = new Procedure({
267
+ ...router["~orpc"],
268
+ route: enhanceRoute(router["~orpc"].route, options),
269
+ errorMap: mergeErrorMap(options.errorMap, router["~orpc"].errorMap),
270
+ middlewares: newMiddlewares,
271
+ inputValidationIndex: router["~orpc"].inputValidationIndex + newMiddlewareAdded,
272
+ outputValidationIndex: router["~orpc"].outputValidationIndex + newMiddlewareAdded
273
+ });
274
+ return enhanced2;
275
+ }
276
+ const enhanced = {};
277
+ for (const key in router) {
278
+ enhanced[key] = enhanceRouter(router[key], options);
279
+ }
280
+ return enhanced;
281
+ }
282
+ function traverseContractProcedures(options, callback, lazyOptions = []) {
283
+ let currentRouter = options.router;
284
+ const hiddenContract = getHiddenRouterContract(options.router);
285
+ if (hiddenContract !== void 0) {
286
+ currentRouter = hiddenContract;
287
+ }
288
+ if (isLazy(currentRouter)) {
289
+ lazyOptions.push({
290
+ router: currentRouter,
291
+ path: options.path
292
+ });
293
+ } else if (isContractProcedure(currentRouter)) {
294
+ callback({
295
+ contract: currentRouter,
296
+ path: options.path
297
+ });
298
+ } else {
299
+ for (const key in currentRouter) {
300
+ traverseContractProcedures(
301
+ {
302
+ router: currentRouter[key],
303
+ path: [...options.path, key]
304
+ },
305
+ callback,
306
+ lazyOptions
307
+ );
308
+ }
309
+ }
310
+ return lazyOptions;
311
+ }
312
+ async function resolveContractProcedures(options, callback) {
313
+ const pending = [options];
314
+ for (const options2 of pending) {
315
+ const lazyOptions = traverseContractProcedures(options2, callback);
316
+ for (const options3 of lazyOptions) {
317
+ const { default: router } = await unlazy(options3.router);
318
+ pending.push({
319
+ router,
320
+ path: options3.path
321
+ });
322
+ }
323
+ }
324
+ }
325
+ async function unlazyRouter(router) {
326
+ if (isProcedure(router)) {
327
+ return router;
328
+ }
329
+ const unlazied = {};
330
+ for (const key in router) {
331
+ const item = router[key];
332
+ const { default: unlaziedRouter } = await unlazy(item);
333
+ unlazied[key] = await unlazyRouter(unlaziedRouter);
334
+ }
335
+ return unlazied;
336
+ }
337
+
338
+ function createAssertedLazyProcedure(lazied) {
339
+ const lazyProcedure = lazy(async () => {
340
+ const { default: maybeProcedure } = await unlazy(lazied);
341
+ if (!isProcedure(maybeProcedure)) {
342
+ throw new Error(`
343
+ Expected a lazy<procedure> but got lazy<unknown>.
344
+ This should be caught by TypeScript compilation.
345
+ Please report this issue if this makes you feel uncomfortable.
346
+ `);
347
+ }
348
+ return { default: maybeProcedure };
349
+ }, getLazyMeta(lazied));
350
+ return lazyProcedure;
351
+ }
352
+ function createContractedProcedure(procedure, contract) {
353
+ return new Procedure({
354
+ ...procedure["~orpc"],
355
+ errorMap: contract["~orpc"].errorMap,
356
+ route: contract["~orpc"].route,
357
+ meta: contract["~orpc"].meta
358
+ });
359
+ }
360
+ function call(procedure, input, ...rest) {
361
+ return createProcedureClient(procedure, ...rest)(input);
362
+ }
363
+
364
+ export { LAZY_SYMBOL as L, Procedure as P, createContractedProcedure as a, addMiddleware as b, createProcedureClient as c, isLazy as d, enhanceRouter as e, createAssertedLazyProcedure as f, getRouter as g, createORPCErrorConstructorMap as h, isProcedure as i, getLazyMeta as j, middlewareOutputFn as k, lazy as l, mergeCurrentContext as m, isStartWithMiddlewares as n, mergeMiddlewares as o, call as p, getHiddenRouterContract as q, createAccessibleLazyRouter as r, setHiddenRouterContract as s, traverseContractProcedures as t, unlazy as u, validateORPCError as v, resolveContractProcedures as w, unlazyRouter as x };
@@ -0,0 +1,98 @@
1
+ import { ORPCError } from '@orpc/client';
2
+ import { StandardRPCJsonSerializer, StandardRPCSerializer } from '@orpc/client/standard';
3
+ import { S as StandardHandler, b as StandardRPCMatcher, a as StandardRPCCodec } from './server.DJrRF9vD.mjs';
4
+ import { toArray, intercept, resolveMaybeOptionalOptions } from '@orpc/shared';
5
+ import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
6
+ import { r as resolveFriendlyStandardHandleOptions } from './server.BVwwTHyO.mjs';
7
+
8
+ class BodyLimitPlugin {
9
+ maxBodySize;
10
+ constructor(options) {
11
+ this.maxBodySize = options.maxBodySize;
12
+ }
13
+ initRuntimeAdapter(options) {
14
+ options.adapterInterceptors ??= [];
15
+ options.adapterInterceptors.push(async (options2) => {
16
+ if (!options2.request.body) {
17
+ return options2.next();
18
+ }
19
+ let currentBodySize = 0;
20
+ const rawReader = options2.request.body.getReader();
21
+ const reader = new ReadableStream({
22
+ start: async (controller) => {
23
+ try {
24
+ if (Number(options2.request.headers.get("content-length")) > this.maxBodySize) {
25
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
26
+ return;
27
+ }
28
+ while (true) {
29
+ const { done, value } = await rawReader.read();
30
+ if (done) {
31
+ break;
32
+ }
33
+ currentBodySize += value.length;
34
+ if (currentBodySize > this.maxBodySize) {
35
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
36
+ break;
37
+ }
38
+ controller.enqueue(value);
39
+ }
40
+ } finally {
41
+ controller.close();
42
+ }
43
+ }
44
+ });
45
+ const requestInit = { body: reader, duplex: "half" };
46
+ return options2.next({
47
+ ...options2,
48
+ request: new Request(options2.request, requestInit)
49
+ });
50
+ });
51
+ }
52
+ }
53
+
54
+ class FetchHandler {
55
+ constructor(standardHandler, options = {}) {
56
+ this.standardHandler = standardHandler;
57
+ for (const plugin of toArray(options.plugins)) {
58
+ plugin.initRuntimeAdapter?.(options);
59
+ }
60
+ this.adapterInterceptors = toArray(options.adapterInterceptors);
61
+ this.toFetchResponseOptions = options;
62
+ }
63
+ toFetchResponseOptions;
64
+ adapterInterceptors;
65
+ async handle(request, ...rest) {
66
+ return intercept(
67
+ this.adapterInterceptors,
68
+ {
69
+ ...resolveFriendlyStandardHandleOptions(resolveMaybeOptionalOptions(rest)),
70
+ request,
71
+ toFetchResponseOptions: this.toFetchResponseOptions
72
+ },
73
+ async ({ request: request2, toFetchResponseOptions, ...options }) => {
74
+ const standardRequest = toStandardLazyRequest(request2);
75
+ const result = await this.standardHandler.handle(standardRequest, options);
76
+ if (!result.matched) {
77
+ return result;
78
+ }
79
+ return {
80
+ matched: true,
81
+ response: toFetchResponse(result.response, toFetchResponseOptions)
82
+ };
83
+ }
84
+ );
85
+ }
86
+ }
87
+
88
+ class RPCHandler extends FetchHandler {
89
+ constructor(router, options = {}) {
90
+ const jsonSerializer = new StandardRPCJsonSerializer(options);
91
+ const serializer = new StandardRPCSerializer(jsonSerializer);
92
+ const matcher = new StandardRPCMatcher();
93
+ const codec = new StandardRPCCodec(serializer);
94
+ super(new StandardHandler(router, matcher, codec, options), options);
95
+ }
96
+ }
97
+
98
+ export { BodyLimitPlugin as B, FetchHandler as F, RPCHandler as R };
@@ -0,0 +1,10 @@
1
+ import { C as Context } from './server.DLt5njUb.mjs';
2
+ import { S as StandardHandleOptions } from './server.BlxK0o8R.mjs';
3
+
4
+ type FriendlyStandardHandleOptions<T extends Context> = Omit<StandardHandleOptions<T>, 'context'> & (Record<never, never> extends T ? {
5
+ context?: T;
6
+ } : {
7
+ context: T;
8
+ });
9
+
10
+ export type { FriendlyStandardHandleOptions as F };