@orpc/server 2.0.0-beta.23 → 2.0.0-beta.24

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 (54) hide show
  1. package/README.md +4 -1
  2. package/dist/adapters/aws-lambda/index.d.mts +104 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +104 -0
  4. package/dist/adapters/aws-lambda/index.mjs +73 -0
  5. package/dist/adapters/crossws/index.d.mts +10 -4
  6. package/dist/adapters/crossws/index.d.ts +10 -4
  7. package/dist/adapters/crossws/index.mjs +3 -3
  8. package/dist/adapters/fastify/index.d.mts +96 -0
  9. package/dist/adapters/fastify/index.d.ts +96 -0
  10. package/dist/adapters/fastify/index.mjs +73 -0
  11. package/dist/adapters/fetch/index.d.mts +13 -5
  12. package/dist/adapters/fetch/index.d.ts +13 -5
  13. package/dist/adapters/fetch/index.mjs +5 -4
  14. package/dist/adapters/message-port/index.d.mts +12 -7
  15. package/dist/adapters/message-port/index.d.ts +12 -7
  16. package/dist/adapters/message-port/index.mjs +3 -3
  17. package/dist/adapters/node/index.d.mts +12 -5
  18. package/dist/adapters/node/index.d.ts +12 -5
  19. package/dist/adapters/node/index.mjs +6 -4
  20. package/dist/adapters/standard/index.d.mts +5 -5
  21. package/dist/adapters/standard/index.d.ts +5 -5
  22. package/dist/adapters/standard/index.mjs +3 -3
  23. package/dist/adapters/standard-peer/index.d.mts +2 -2
  24. package/dist/adapters/standard-peer/index.d.ts +2 -2
  25. package/dist/adapters/websocket/index.d.mts +10 -4
  26. package/dist/adapters/websocket/index.d.ts +10 -4
  27. package/dist/adapters/websocket/index.mjs +3 -3
  28. package/dist/extensions/callable.d.mts +1 -1
  29. package/dist/extensions/callable.d.ts +1 -1
  30. package/dist/extensions/callable.mjs +2 -2
  31. package/dist/helpers/index.d.mts +20 -3
  32. package/dist/helpers/index.d.ts +20 -3
  33. package/dist/index.d.mts +39 -7
  34. package/dist/index.d.ts +39 -7
  35. package/dist/index.mjs +23 -18
  36. package/dist/plugins/index.d.mts +49 -40
  37. package/dist/plugins/index.d.ts +49 -40
  38. package/dist/plugins/index.mjs +10 -67
  39. package/dist/shared/{server.DofEOwf-.mjs → server.7T18Khvf.mjs} +6 -32
  40. package/dist/shared/{server.DBs0rrf9.mjs → server.B2pXdfpL.mjs} +1 -1
  41. package/dist/shared/{server.DG9aQpJK.d.ts → server.BUvC0G_8.d.ts} +3 -3
  42. package/dist/shared/server.BhHrioCw.d.ts +34 -0
  43. package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
  44. package/dist/shared/{server.CcR4kgje.d.ts → server.CwrYlF72.d.mts} +10 -42
  45. package/dist/shared/{server.CcR4kgje.d.mts → server.CwrYlF72.d.ts} +10 -42
  46. package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
  47. package/dist/shared/{server.A8J9H8OE.mjs → server.DEGjTAPW.mjs} +2 -2
  48. package/dist/shared/{server.D4cnq66J.mjs → server.DgunZU0v.mjs} +3 -3
  49. package/dist/shared/{server.m3szVJGU.d.ts → server.Dm0os-OP.d.mts} +24 -12
  50. package/dist/shared/{server.BhsVw7m7.d.ts → server.DrN1Pj1-.d.ts} +3 -3
  51. package/dist/shared/{server.15O7oC1p.d.mts → server.DtfwuV6U.d.ts} +24 -12
  52. package/dist/shared/{server.DDFizwfU.d.mts → server.JbCIPL4P.d.mts} +3 -3
  53. package/dist/shared/{server.omY4cUs0.d.mts → server.zySQaS-n.d.mts} +3 -3
  54. package/package.json +26 -9
@@ -1,10 +1,19 @@
1
1
  import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
2
  import { StandardLazyRequest, StandardHeaders } from '@standardserver/core';
3
- import { C as Context } from '../shared/server.CcR4kgje.js';
4
- import { e as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions, g as StandardHandlerInterceptorOptions } from '../shared/server.BhsVw7m7.js';
3
+ import { C as Context } from '../shared/server.CwrYlF72.js';
4
+ import { S as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions, g as StandardHandlerInterceptorOptions } from '../shared/server.DrN1Pj1-.js';
5
+ export { R as RequestLimitHandlerPlugin, a as RequestLimitHandlerPluginOptions } from '../shared/server.BhHrioCw.js';
5
6
  import '@orpc/client';
6
7
  import '@orpc/contract';
7
8
 
9
+ /**
10
+ * Content type for batch responses that use the length-prefixed binary framing
11
+ * (streaming mode, and buffered mode when any sub-response contains binary).
12
+ *
13
+ * Decoding is driven by the `standard-server` body hint, not this header,
14
+ * so it only serves to describe the payload to logs, proxies, and dev tools.
15
+ */
16
+ declare const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
8
17
  interface BatchHandlerPluginOptions<T extends Context> {
9
18
  /**
10
19
  * The max size of the batch allowed.
@@ -54,6 +63,15 @@ interface BatchHandlerPluginOptions<T extends Context> {
54
63
  interval?: number;
55
64
  };
56
65
  }
66
+ /**
67
+ * Handles batch requests sent by the client Batch Link Plugin, splitting each
68
+ * batch into sub-requests and streaming their responses back together.
69
+ *
70
+ * @remarks
71
+ * **Note**: HTTP/2 and later already multiplex requests over a single connection, which often makes this plugin unnecessary.
72
+ *
73
+ * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
74
+ */
57
75
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
58
76
  name: string;
59
77
  /**
@@ -119,9 +137,10 @@ interface CORSHandlerPluginOptions<T extends Context> {
119
137
  exposeHeaders?: readonly string[];
120
138
  }
121
139
  /**
122
- * CORSHandlerPlugin is a plugin for oRPC that allows you to configure CORS for your API.
140
+ * Configures the [CORS Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
141
+ * for your API, including preflight requests.
123
142
  *
124
- * @see {@link https://orpc.dev/docs/plugins/cors CORS Plugin Docs}
143
+ * @see {@link https://orpc.dev/docs/plugins/cors | CORS Handler Plugin}
125
144
  */
126
145
  declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
127
146
  private readonly options;
@@ -141,13 +160,22 @@ declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlu
141
160
  * When a request includes cookies, it helps ensure the request originates from JavaScript
142
161
  * (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
143
162
  *
144
- * @info This plugin is enabled by default for `RPCHandler` over HTTP.
163
+ * @remarks
164
+ * **Note**: This plugin is enabled by default for `RPCHandler` over HTTP.
165
+ *
166
+ * @see {@link https://orpc.dev/docs/plugins/csrf-guard | CSRF Guard Plugin}
145
167
  */
146
168
  declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
147
169
  name: string;
148
170
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
149
171
  }
150
172
 
173
+ /**
174
+ * Decompresses incoming request bodies based on the Content-Encoding header,
175
+ * supporting gzip, deflate, and deflate-raw.
176
+ *
177
+ * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
178
+ */
151
179
  declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
152
180
  name: string;
153
181
  /**
@@ -157,6 +185,11 @@ declare class RequestCompressionHandlerPlugin<T extends Context> implements Stan
157
185
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
158
186
  }
159
187
 
188
+ /**
189
+ * The context shape into which the Request Headers Plugin injects `reqHeaders`.
190
+ *
191
+ * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
192
+ */
160
193
  interface RequestHeadersHandlerPluginContext {
161
194
  /**
162
195
  * Request headers as a Headers instance. This is injected by the Request Headers Plugin.
@@ -167,42 +200,13 @@ interface RequestHeadersHandlerPluginContext {
167
200
  * The Request Headers Plugin injects a `reqHeaders` instance into the context,
168
201
  * allowing access to request headers in oRPC.
169
202
  *
170
- * @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
203
+ * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
171
204
  */
172
205
  declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
173
206
  name: string;
174
207
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
175
208
  }
176
209
 
177
- interface RequestLimitHandlerPluginOptions {
178
- /**
179
- * The maximum allowed request body size in bytes.
180
- */
181
- maxBodySize: number;
182
- }
183
- /**
184
- * Rejects requests whose body exceeds `maxBodySize`.
185
- *
186
- * When used with the request compression plugin, the limit applies to the
187
- * decompressed payload rather than the compressed wire size.
188
- *
189
- * @see {@link https://orpc.dev/docs/plugins/request-limit Request Limit Plugin Docs}
190
- */
191
- declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
192
- name: string;
193
- /**
194
- * Should limit the original batch request body instead of sub-requests.
195
- */
196
- after: string[];
197
- /**
198
- * Should limit the final body size instead of the compressed one.
199
- */
200
- before: string[];
201
- private readonly maxBodySize;
202
- constructor(options: RequestLimitHandlerPluginOptions);
203
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
204
- }
205
-
206
210
  interface ResponseCompressionHandlerPluginOptions<_T extends Context> {
207
211
  /**
208
212
  * The compression schemes to use for response compression.
@@ -225,7 +229,7 @@ interface ResponseCompressionHandlerPluginOptions<_T extends Context> {
225
229
  * Compresses response bodies based on the client's Accept-Encoding header.
226
230
  * Works at the standard handler level, so it supports all adapters.
227
231
  *
228
- * @see {@link https://orpc.dev/docs/plugins/response-compression Response Compression Plugin Docs}
232
+ * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
229
233
  */
230
234
  declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
231
235
  name: string;
@@ -240,6 +244,11 @@ declare class ResponseCompressionHandlerPlugin<T extends Context> implements Sta
240
244
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
241
245
  }
242
246
 
247
+ /**
248
+ * The context shape into which the Response Headers Plugin injects `resHeaders`.
249
+ *
250
+ * @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
251
+ */
243
252
  interface ResponseHeadersHandlerPluginContext {
244
253
  /**
245
254
  * Response headers as a Headers instance. This is injected by the Response Headers Plugin.
@@ -251,7 +260,7 @@ interface ResponseHeadersHandlerPluginContext {
251
260
  * The Response Headers Plugin allows you to set response headers in oRPC.
252
261
  * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
253
262
  *
254
- * @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
263
+ * @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
255
264
  */
256
265
  declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
257
266
  name: string;
@@ -283,7 +292,7 @@ interface RethrowHandlerPluginOptions<T extends Context> {
283
292
  * and rethrow matching errors directly to your framework's error handling mechanism
284
293
  * (e.g., NestJS exception filters, Express error middleware).
285
294
  *
286
- * @see {@link https://orpc.dev/docs/plugins/rethrow Rethrow Plugin Documentation}
295
+ * @see {@link https://orpc.dev/docs/plugins/rethrow | Rethrow Handler Plugin}
287
296
  */
288
297
  declare class RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
289
298
  name: string;
@@ -293,5 +302,5 @@ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandler
293
302
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
294
303
  }
295
304
 
296
- export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestLimitHandlerPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, RethrowHandlerPlugin };
297
- export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestLimitHandlerPluginOptions, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, RethrowHandlerPluginOptions };
305
+ export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, CSRFGuardHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin };
306
+ export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions };
@@ -3,8 +3,10 @@ import { flattenStandardHeader, parseStandardUrl, generateContentDisposition, me
3
3
  import { isClientPeerSendMessage, ServerPeer, encodePeerMessage } from '@standardserver/peer';
4
4
  export { C as CSRFGuardHandlerPlugin } from '../shared/server.D_QauotT.mjs';
5
5
  import { toFetchHeaders, toStandardBody, toStandardHeaders } from '@standardserver/fetch';
6
- import { ORPCError } from '@orpc/client';
6
+ export { R as RequestLimitHandlerPlugin } from '../shared/server.Cd4Z1hpV.mjs';
7
+ import '@orpc/client';
7
8
 
9
+ const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
8
10
  class BatchHandlerPlugin {
9
11
  name = "~batch";
10
12
  /**
@@ -121,7 +123,7 @@ class BatchHandlerPlugin {
121
123
  response: {
122
124
  status,
123
125
  headers,
124
- body: new Blob(chunks, { type: "application/octet-stream" })
126
+ body: new Blob(chunks, { type: BATCH_CONTENT_TYPE })
125
127
  }
126
128
  };
127
129
  }
@@ -182,7 +184,11 @@ class BatchHandlerPlugin {
182
184
  });
183
185
  return {
184
186
  matched: true,
185
- response: { status, headers, body: stream }
187
+ response: {
188
+ status,
189
+ headers: { ...headers, "content-type": BATCH_CONTENT_TYPE },
190
+ body: stream
191
+ }
186
192
  };
187
193
  };
188
194
  return {
@@ -365,69 +371,6 @@ class RequestHeadersHandlerPlugin {
365
371
  }
366
372
  }
367
373
 
368
- class RequestLimitHandlerPlugin {
369
- name = "~request-limit";
370
- /**
371
- * Should limit the original batch request body instead of sub-requests.
372
- */
373
- after = ["~batch"];
374
- /**
375
- * Should limit the final body size instead of the compressed one.
376
- */
377
- before = ["~request-compression"];
378
- maxBodySize;
379
- constructor(options) {
380
- this.maxBodySize = options.maxBodySize;
381
- }
382
- init(options) {
383
- const maxBodySize = this.maxBodySize;
384
- const routingInterceptor = async ({ next, ...interceptorOptions }) => {
385
- return next({
386
- ...interceptorOptions,
387
- request: {
388
- ...interceptorOptions.request,
389
- async resolveBody(hint) {
390
- const contentLength = Number(
391
- flattenStandardHeader(interceptorOptions.request.headers["content-length"])
392
- );
393
- if (Number.isFinite(contentLength) && contentLength > maxBodySize) {
394
- throw new ORPCError("PAYLOAD_TOO_LARGE");
395
- }
396
- const stream = await interceptorOptions.request.resolveBody("octet-stream");
397
- if (!(stream instanceof ReadableStream)) {
398
- return stream;
399
- }
400
- let currentBodySize = 0;
401
- const limitedStream = stream.pipeThrough(
402
- new TransformStream({
403
- transform(chunk, controller) {
404
- currentBodySize += chunk.byteLength;
405
- if (currentBodySize > maxBodySize) {
406
- controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
407
- return;
408
- }
409
- controller.enqueue(chunk);
410
- }
411
- })
412
- );
413
- const response = new Response(limitedStream, {
414
- headers: toFetchHeaders(interceptorOptions.request.headers)
415
- });
416
- return toStandardBody(response, { hint });
417
- }
418
- }
419
- });
420
- };
421
- return {
422
- ...options,
423
- routingInterceptors: [
424
- routingInterceptor,
425
- ...toArray(options.routingInterceptors)
426
- ]
427
- };
428
- }
429
- }
430
-
431
374
  const AVG_BYTES_PER_CHAR = 1.2;
432
375
  class ResponseCompressionHandlerPlugin {
433
376
  name = "~response-compression";
@@ -690,4 +633,4 @@ class RethrowHandlerPlugin {
690
633
  }
691
634
  }
692
635
 
693
- export { BatchHandlerPlugin, CORSHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestLimitHandlerPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, RethrowHandlerPlugin };
636
+ export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin };
@@ -1,32 +1,6 @@
1
- import { ORPCError, wrapAsyncIteratorPreservingEventMeta, cloneORPCError } from '@orpc/client';
2
- import { reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
3
- import { getOrBind, resolveMaybeOptionalOptions, getConstructor, isTypescriptObject, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream } from '@orpc/shared';
4
-
5
- function createORPCErrorConstructorMap(errorMap) {
6
- const proxy = new Proxy(errorMap, {
7
- get(target, code) {
8
- if (typeof code !== "string") {
9
- return getOrBind(target, code);
10
- }
11
- const item = (...rest) => {
12
- const options = resolveMaybeOptionalOptions(rest);
13
- const config = errorMap[code];
14
- const error = new ORPCError(code, {
15
- message: options.message ?? config?.message,
16
- data: options.data,
17
- cause: options.cause
18
- });
19
- if (config) {
20
- error.defined = true;
21
- error.inferable = true;
22
- }
23
- return error;
24
- };
25
- return item;
26
- }
27
- });
28
- return proxy;
29
- }
1
+ import { wrapAsyncIteratorPreservingEventMeta, ORPCError, cloneORPCError } from '@orpc/client';
2
+ import { createORPCErrorConstructorMap, reconcileORPCError, ValidationError, ProcedureContract } from '@orpc/contract';
3
+ import { getConstructor, isTypescriptObject, resolveMaybeOptionalOptions, toArray, value, runWithSpan, intercept, isAsyncIteratorObject, override, traceAsyncIterator, traceReadableStream } from '@orpc/shared';
30
4
 
31
5
  class Lazy {
32
6
  "~orpc";
@@ -34,7 +8,7 @@ class Lazy {
34
8
  this["~orpc"] = def;
35
9
  }
36
10
  /**
37
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
11
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
38
12
  */
39
13
  static [Symbol.hasInstance](instance) {
40
14
  if (this !== Lazy) {
@@ -220,7 +194,7 @@ class Procedure {
220
194
  this["~orpc"] = def;
221
195
  }
222
196
  /**
223
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
197
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
224
198
  */
225
199
  static [Symbol.hasInstance](instance) {
226
200
  if (this !== Procedure) {
@@ -234,4 +208,4 @@ class Procedure {
234
208
  }
235
209
  }
236
210
 
237
- export { Lazy as L, Procedure as P, createORPCErrorConstructorMap as a, createProcedureClient as c, unlazy as u };
211
+ export { Lazy as L, Procedure as P, createProcedureClient as c, unlazy as u };
@@ -1,5 +1,5 @@
1
1
  import { resolveMetaPlugins, mergeErrorMap, getHiddenMetaPlugins } from '@orpc/contract';
2
- import { P as Procedure } from './server.DofEOwf-.mjs';
2
+ import { P as Procedure } from './server.7T18Khvf.mjs';
3
3
 
4
4
  class DecoratedProcedure extends Procedure {
5
5
  meta(...plugins) {
@@ -1,10 +1,10 @@
1
1
  import { RPCSerializer, AnyORPCError } from '@orpc/client';
2
2
  import { Value, Promisable } from '@orpc/shared';
3
3
  import { StandardMethod, StandardLazyRequest, StandardResponse } from '@standardserver/core';
4
- import { A as AnyProcedure, C as Context } from './server.CcR4kgje.js';
5
- import { A as AnyRouter } from './server.m3szVJGU.js';
4
+ import { A as AnyProcedure, C as Context } from './server.CwrYlF72.js';
5
+ import { A as AnyRouter } from './server.DtfwuV6U.js';
6
6
  import { AnyProcedureContract } from '@orpc/contract';
7
- import { b as StandardHandlerHandleOptions, c as StandardHandlerCodec, d as StandardHandlerCodecResolvedProcedure } from './server.BhsVw7m7.js';
7
+ import { c as StandardHandlerHandleOptions, d as StandardHandlerCodec, e as StandardHandlerCodecResolvedProcedure } from './server.DrN1Pj1-.js';
8
8
 
9
9
  interface RPCMatcherOptions {
10
10
  /**
@@ -0,0 +1,34 @@
1
+ import { C as Context } from './server.CwrYlF72.js';
2
+ import { S as StandardHandlerPlugin, a as StandardHandlerOptions } from './server.DrN1Pj1-.js';
3
+
4
+ interface RequestLimitHandlerPluginOptions {
5
+ /**
6
+ * The maximum allowed request body size in bytes.
7
+ */
8
+ maxBodySize: number;
9
+ }
10
+ /**
11
+ * Rejects requests whose body exceeds `maxBodySize`.
12
+ *
13
+ * When used with the request compression plugin, the limit applies to the
14
+ * decompressed payload rather than the compressed wire size.
15
+ *
16
+ * @see {@link https://orpc.dev/docs/plugins/request-limit | Request Limit Plugin}
17
+ */
18
+ declare class RequestLimitHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
19
+ name: string;
20
+ /**
21
+ * Should limit the original batch request body instead of sub-requests.
22
+ */
23
+ after: string[];
24
+ /**
25
+ * Should limit the final body size instead of the compressed one.
26
+ */
27
+ before: string[];
28
+ private readonly maxBodySize;
29
+ constructor(options: RequestLimitHandlerPluginOptions);
30
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
31
+ }
32
+
33
+ export { RequestLimitHandlerPlugin as R };
34
+ export type { RequestLimitHandlerPluginOptions as a };
@@ -0,0 +1,69 @@
1
+ import { ORPCError } from '@orpc/client';
2
+ import { toArray } from '@orpc/shared';
3
+ import { flattenStandardHeader } from '@standardserver/core';
4
+ import { toFetchHeaders, toStandardBody } from '@standardserver/fetch';
5
+
6
+ class RequestLimitHandlerPlugin {
7
+ name = "~request-limit";
8
+ /**
9
+ * Should limit the original batch request body instead of sub-requests.
10
+ */
11
+ after = ["~batch"];
12
+ /**
13
+ * Should limit the final body size instead of the compressed one.
14
+ */
15
+ before = ["~request-compression"];
16
+ maxBodySize;
17
+ constructor(options) {
18
+ this.maxBodySize = options.maxBodySize;
19
+ }
20
+ init(options) {
21
+ const maxBodySize = this.maxBodySize;
22
+ const routingInterceptor = async ({ next, ...interceptorOptions }) => {
23
+ return next({
24
+ ...interceptorOptions,
25
+ request: {
26
+ ...interceptorOptions.request,
27
+ async resolveBody(hint) {
28
+ const contentLength = Number(
29
+ flattenStandardHeader(interceptorOptions.request.headers["content-length"])
30
+ );
31
+ if (Number.isFinite(contentLength) && contentLength > maxBodySize) {
32
+ throw new ORPCError("PAYLOAD_TOO_LARGE");
33
+ }
34
+ const stream = await interceptorOptions.request.resolveBody("octet-stream");
35
+ if (!(stream instanceof ReadableStream)) {
36
+ return stream;
37
+ }
38
+ let currentBodySize = 0;
39
+ const limitedStream = stream.pipeThrough(
40
+ new TransformStream({
41
+ transform(chunk, controller) {
42
+ currentBodySize += chunk.byteLength;
43
+ if (currentBodySize > maxBodySize) {
44
+ controller.error(new ORPCError("PAYLOAD_TOO_LARGE"));
45
+ return;
46
+ }
47
+ controller.enqueue(chunk);
48
+ }
49
+ })
50
+ );
51
+ const response = new Response(limitedStream, {
52
+ headers: toFetchHeaders(interceptorOptions.request.headers)
53
+ });
54
+ return toStandardBody(response, { hint });
55
+ }
56
+ }
57
+ });
58
+ };
59
+ return {
60
+ ...options,
61
+ routingInterceptors: [
62
+ routingInterceptor,
63
+ ...toArray(options.routingInterceptors)
64
+ ]
65
+ };
66
+ }
67
+ }
68
+
69
+ export { RequestLimitHandlerPlugin as R };
@@ -1,5 +1,5 @@
1
- import { ORPCErrorCode, ORPCErrorOptions, ORPCError, AnyORPCError, ClientContext, Client } from '@orpc/client';
2
- import { ErrorMap, ErrorMapItem, InferSchemaInput, AnyMetaPlugin, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
1
+ import { AnyORPCError, ClientContext, Client } from '@orpc/client';
2
+ import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
3
3
  import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
4
4
 
5
5
  interface Context {
@@ -8,40 +8,6 @@ interface Context {
8
8
  type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & Omit<TInContext, keyof TInitial | keyof TOutContext>;
9
9
  type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : Omit<TCurrent, keyof TOutContext> & TOutContext;
10
10
 
11
- type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
12
- interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
13
- (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
14
- }
15
- type ORPCErrorConstructorMap<T extends ErrorMap> = {
16
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
17
- };
18
- /**
19
- * Creates a map of ORPC error constructors.
20
- *
21
- * The returned object is a `Proxy` that allows access to arbitrary error codes:
22
- * - If the code exists in the provided `errorMap`, the corresponding constructor
23
- * will create a **defined** `ORPCError`.
24
- * - If the code does not exist, a fallback `ORPCError` constructor is returned.
25
- *
26
- * The `in` operator can be used to check whether an error code is explicitly
27
- * defined in the map.
28
- *
29
- * @example
30
- * ```ts
31
- * const errorMap = createORPCErrorConstructorMap({
32
- * NOT_FOUND: {
33
- * status: 404,
34
- * message: 'Not Found',
35
- * },
36
- * })
37
- *
38
- * if ('NOT_FOUND' in errorMap) {
39
- * const error = errorMap.NOT_FOUND()
40
- * }
41
- * ```
42
- */
43
- declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
44
-
45
11
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
46
12
  output: TOutput;
47
13
  context: TOutContext;
@@ -124,7 +90,8 @@ interface ProcedureConfig {
124
90
  * When enabled, input schemas are not validated at runtime.
125
91
  * Schemas are still used for type inference and OpenAPI generation.
126
92
  *
127
- * @warning Do not disable validation for schemas that transform values.
93
+ * @remarks
94
+ * **Warning**: Do not disable validation for schemas that transform values.
128
95
  *
129
96
  * @default false
130
97
  */
@@ -135,7 +102,8 @@ interface ProcedureConfig {
135
102
  *
136
103
  * Useful when output schemas exist only for specification generation.
137
104
  *
138
- * @warning Do not disable validation for schemas that transform values.
105
+ * @remarks
106
+ * **Warning**: Do not disable validation for schemas that transform values.
139
107
  *
140
108
  * @default false
141
109
  */
@@ -162,7 +130,7 @@ declare class Procedure<TInitialContext extends Context, TInjectedContext extend
162
130
  '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
163
131
  constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
164
132
  /**
165
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
133
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
166
134
  */
167
135
  static [Symbol.hasInstance](instance: unknown): boolean;
168
136
  }
@@ -179,7 +147,7 @@ declare class Lazy<T> {
179
147
  '~orpc': LazyDefinition<T>;
180
148
  constructor(def: LazyDefinition<T>);
181
149
  /**
182
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
150
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
183
151
  */
184
152
  static [Symbol.hasInstance](instance: unknown): boolean;
185
153
  }
@@ -202,5 +170,5 @@ type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema exten
202
170
  });
203
171
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
204
172
 
205
- export { Procedure as a, Lazy as h, createORPCErrorConstructorMap as x, createProcedureClient as y, unlazy as z };
206
- export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, ORPCErrorConstructorMap as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, OrderedMiddleware as j, LazyDefinition as k, MiddlewareDefinition as l, MiddlewareDone as m, MiddlewareDoneOptions as n, MiddlewareNext as o, MiddlewareNextOptions as p, MiddlewareOptions as q, MiddlewareResult as r, ORPCErrorConstructorMapItem as s, ORPCErrorConstructorMapItemOptions as t, ProcedureClientInterceptorOptions as u, ProcedureDefinition as v, ProcedureHandlerOptions as w };
173
+ export { Procedure as a, Lazy as h, createProcedureClient as u, unlazy as v };
174
+ export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };
@@ -1,5 +1,5 @@
1
- import { ORPCErrorCode, ORPCErrorOptions, ORPCError, AnyORPCError, ClientContext, Client } from '@orpc/client';
2
- import { ErrorMap, ErrorMapItem, InferSchemaInput, AnyMetaPlugin, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
1
+ import { AnyORPCError, ClientContext, Client } from '@orpc/client';
2
+ import { ErrorMap, AnyMetaPlugin, ORPCErrorConstructorMap, AnySchema, ProcedureContractDefinition, Meta, InferSchemaOutput, ORPCErrorFromErrorMap, InferSchemaInput } from '@orpc/contract';
3
3
  import { MaybeOptionalOptions, Promisable, Interceptor, PromiseWithError, ThrowableError, Value } from '@orpc/shared';
4
4
 
5
5
  interface Context {
@@ -8,40 +8,6 @@ interface Context {
8
8
  type MergedInitialContext<TInitial extends Context, TOutContext extends Context, TInContext extends Context> = Exclude<keyof TInContext, keyof TInitial | keyof TOutContext> extends never ? TInitial : TInitial & Omit<TInContext, keyof TInitial | keyof TOutContext>;
9
9
  type MergedContext<TCurrent extends Context, TOutContext extends Context> = keyof TOutContext extends never ? TCurrent : Omit<TCurrent, keyof TOutContext> & TOutContext;
10
10
 
11
- type ORPCErrorConstructorMapItemOptions<TData> = Omit<ORPCErrorOptions<TData>, 'status'>;
12
- interface ORPCErrorConstructorMapItem<TCode extends ORPCErrorCode, TInData> {
13
- (...rest: MaybeOptionalOptions<ORPCErrorConstructorMapItemOptions<TInData>>): ORPCError<TCode, TInData>;
14
- }
15
- type ORPCErrorConstructorMap<T extends ErrorMap> = {
16
- [K in keyof T]: K extends ORPCErrorCode ? T[K] extends ErrorMapItem<infer UInputSchema> ? ORPCErrorConstructorMapItem<K, InferSchemaInput<UInputSchema>> : never : never;
17
- };
18
- /**
19
- * Creates a map of ORPC error constructors.
20
- *
21
- * The returned object is a `Proxy` that allows access to arbitrary error codes:
22
- * - If the code exists in the provided `errorMap`, the corresponding constructor
23
- * will create a **defined** `ORPCError`.
24
- * - If the code does not exist, a fallback `ORPCError` constructor is returned.
25
- *
26
- * The `in` operator can be used to check whether an error code is explicitly
27
- * defined in the map.
28
- *
29
- * @example
30
- * ```ts
31
- * const errorMap = createORPCErrorConstructorMap({
32
- * NOT_FOUND: {
33
- * status: 404,
34
- * message: 'Not Found',
35
- * },
36
- * })
37
- *
38
- * if ('NOT_FOUND' in errorMap) {
39
- * const error = errorMap.NOT_FOUND()
40
- * }
41
- * ```
42
- */
43
- declare function createORPCErrorConstructorMap<T extends ErrorMap>(errorMap: T): ORPCErrorConstructorMap<T>;
44
-
45
11
  type MiddlewareResult<TOutContext extends Context, TOutput> = Promisable<{
46
12
  output: TOutput;
47
13
  context: TOutContext;
@@ -124,7 +90,8 @@ interface ProcedureConfig {
124
90
  * When enabled, input schemas are not validated at runtime.
125
91
  * Schemas are still used for type inference and OpenAPI generation.
126
92
  *
127
- * @warning Do not disable validation for schemas that transform values.
93
+ * @remarks
94
+ * **Warning**: Do not disable validation for schemas that transform values.
128
95
  *
129
96
  * @default false
130
97
  */
@@ -135,7 +102,8 @@ interface ProcedureConfig {
135
102
  *
136
103
  * Useful when output schemas exist only for specification generation.
137
104
  *
138
- * @warning Do not disable validation for schemas that transform values.
105
+ * @remarks
106
+ * **Warning**: Do not disable validation for schemas that transform values.
139
107
  *
140
108
  * @default false
141
109
  */
@@ -162,7 +130,7 @@ declare class Procedure<TInitialContext extends Context, TInjectedContext extend
162
130
  '~orpc': ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
163
131
  constructor(def: ProcedureDefinition<TInitialContext, TInjectedContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>);
164
132
  /**
165
- * Checks if the given instance satisfies the {@see Procedure} class/interface.
133
+ * Checks if the given instance satisfies the {@link Procedure} class/interface.
166
134
  */
167
135
  static [Symbol.hasInstance](instance: unknown): boolean;
168
136
  }
@@ -179,7 +147,7 @@ declare class Lazy<T> {
179
147
  '~orpc': LazyDefinition<T>;
180
148
  constructor(def: LazyDefinition<T>);
181
149
  /**
182
- * Checks if the given instance satisfies the {@see Lazy} class/interface.
150
+ * Checks if the given instance satisfies the {@link Lazy} class/interface.
183
151
  */
184
152
  static [Symbol.hasInstance](instance: unknown): boolean;
185
153
  }
@@ -202,5 +170,5 @@ type ProcedureClientOptions<TInitialContext extends Context, TOutputSchema exten
202
170
  });
203
171
  declare function createProcedureClient<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TReturnedError extends AnyORPCError, TClientContext extends ClientContext = object>(lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>>, ...rest: MaybeOptionalOptions<ProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TReturnedError, TClientContext>>): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap, TReturnedError>;
204
172
 
205
- export { Procedure as a, Lazy as h, createORPCErrorConstructorMap as x, createProcedureClient as y, unlazy as z };
206
- export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, ORPCErrorConstructorMap as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, OrderedMiddleware as j, LazyDefinition as k, MiddlewareDefinition as l, MiddlewareDone as m, MiddlewareDoneOptions as n, MiddlewareNext as o, MiddlewareNextOptions as p, MiddlewareOptions as q, MiddlewareResult as r, ORPCErrorConstructorMapItem as s, ORPCErrorConstructorMapItemOptions as t, ProcedureClientInterceptorOptions as u, ProcedureDefinition as v, ProcedureHandlerOptions as w };
173
+ export { Procedure as a, Lazy as h, createProcedureClient as u, unlazy as v };
174
+ export type { AnyProcedure as A, Context as C, Lazyable as L, MergedContext as M, OrderedMiddleware as O, ProcedureClientOptions as P, ProcedureClient as b, ProcedureClientInterceptor as c, Middleware as d, MergedInitialContext as e, ProcedureConfig as f, AnyMiddleware as g, ProcedureHandler as i, LazyDefinition as j, MiddlewareDefinition as k, MiddlewareDone as l, MiddlewareDoneOptions as m, MiddlewareNext as n, MiddlewareNextOptions as o, MiddlewareOptions as p, MiddlewareResult as q, ProcedureClientInterceptorOptions as r, ProcedureDefinition as s, ProcedureHandlerOptions as t };