@orpc/server 2.0.0-beta.2 → 2.0.0-beta.21

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 (46) hide show
  1. package/README.md +32 -21
  2. package/dist/adapters/crossws/index.d.mts +11 -8
  3. package/dist/adapters/crossws/index.d.ts +11 -8
  4. package/dist/adapters/crossws/index.mjs +10 -7
  5. package/dist/adapters/fetch/index.d.mts +8 -56
  6. package/dist/adapters/fetch/index.d.ts +8 -56
  7. package/dist/adapters/fetch/index.mjs +6 -136
  8. package/dist/adapters/message-port/index.d.mts +11 -13
  9. package/dist/adapters/message-port/index.d.ts +11 -13
  10. package/dist/adapters/message-port/index.mjs +28 -32
  11. package/dist/adapters/node/index.d.mts +7 -37
  12. package/dist/adapters/node/index.d.ts +7 -37
  13. package/dist/adapters/node/index.mjs +6 -112
  14. package/dist/adapters/standard/index.d.mts +6 -6
  15. package/dist/adapters/standard/index.d.ts +6 -6
  16. package/dist/adapters/standard/index.mjs +3 -3
  17. package/dist/adapters/standard-peer/index.d.mts +2 -2
  18. package/dist/adapters/standard-peer/index.d.ts +2 -2
  19. package/dist/adapters/websocket/index.d.mts +36 -26
  20. package/dist/adapters/websocket/index.d.ts +36 -26
  21. package/dist/adapters/websocket/index.mjs +33 -25
  22. package/dist/extensions/callable.d.mts +1 -1
  23. package/dist/extensions/callable.d.ts +1 -1
  24. package/dist/extensions/callable.mjs +2 -2
  25. package/dist/helpers/index.d.mts +3 -3
  26. package/dist/helpers/index.d.ts +3 -3
  27. package/dist/helpers/index.mjs +13 -5
  28. package/dist/index.d.mts +19 -16
  29. package/dist/index.d.ts +19 -16
  30. package/dist/index.mjs +36 -22
  31. package/dist/plugins/index.d.mts +136 -5
  32. package/dist/plugins/index.d.ts +136 -5
  33. package/dist/plugins/index.mjs +394 -6
  34. package/dist/shared/{server.BsNNjG5J.d.mts → server.15O7oC1p.d.mts} +1 -1
  35. package/dist/shared/{server.B_U9y00a.d.mts → server.B4BnEWWm.d.mts} +6 -5
  36. package/dist/shared/{server.EOHJ3NJr.d.ts → server.BhsVw7m7.d.ts} +2 -2
  37. package/dist/shared/{server.BwHnWUuN.mjs → server.BoiFpNT7.mjs} +4 -2
  38. package/dist/shared/{server.GDpX6Df8.mjs → server.COPVXhDG.mjs} +3 -3
  39. package/dist/shared/{server.BL22TloH.d.mts → server.CcR4kgje.d.mts} +25 -3
  40. package/dist/shared/{server.BL22TloH.d.ts → server.CcR4kgje.d.ts} +25 -3
  41. package/dist/shared/{server.T9F3bzZx.d.ts → server.CnN50DHH.d.ts} +6 -5
  42. package/dist/shared/{server.CjOb6ItT.mjs → server.DBs0rrf9.mjs} +1 -1
  43. package/dist/shared/{server.BB_Ik9Ph.d.mts → server.DDFizwfU.d.mts} +2 -2
  44. package/dist/shared/{server.CrlKQucM.mjs → server.DofEOwf-.mjs} +11 -7
  45. package/dist/shared/{server.Pa0F03f_.d.ts → server.m3szVJGU.d.ts} +1 -1
  46. package/package.json +9 -10
package/dist/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  import { mergeErrorMap, resolveMetaPlugins, getHiddenMetaPlugins, ProcedureContract } from '@orpc/contract';
2
- export { ValidationError, defineMeta, eventIterator, reconcileORPCError, type } from '@orpc/contract';
2
+ export { ValidationError, asyncIteratorObject, defineMeta, eventIterator, reconcileORPCError, type } from '@orpc/contract';
3
3
  import { toArray, bindMethods, getOrBind, isTypescriptObject, resolveMaybeOptionalOptions } from '@orpc/shared';
4
- export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onError, onFinish, onStart, onSuccess, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
5
- import { L as Lazy, P as Procedure, c as createProcedureClient } from './shared/server.CrlKQucM.mjs';
6
- export { a as createORPCErrorConstructorMap, u as unlazy } from './shared/server.CrlKQucM.mjs';
7
- import { D as DecoratedProcedure } from './shared/server.CjOb6ItT.mjs';
8
- import { b as augmentRouter, d as augmentImplementedRouter, e as withHiddenRouterContract, f as createGuardedProcedureLazy, g as getRouter } from './shared/server.BwHnWUuN.mjs';
9
- export { a as DEFAULT_ERROR_STATUS, D as DEFAULT_SUCCESS_STATUS, h as call, c as createContractProcedure, i as getHiddenRouterContract, u as unlazyRouter, j as walkProcedureContractsAsync, w as walkProcedureContractsSync } from './shared/server.BwHnWUuN.mjs';
4
+ export { AsyncIteratorClass, asyncIteratorToStream, asyncIteratorToUnproxiedDataStream, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, onAsyncIteratorObjectError, onError, onFinish, onReadableStreamError, onStart, onSuccess, streamToAsyncIteratorObject, streamToAsyncIteratorObject as streamToEventIterator } from '@orpc/shared';
5
+ import { L as Lazy, P as Procedure, c as createProcedureClient } from './shared/server.DofEOwf-.mjs';
6
+ export { a as createORPCErrorConstructorMap, u as unlazy } from './shared/server.DofEOwf-.mjs';
7
+ import { D as DecoratedProcedure } from './shared/server.DBs0rrf9.mjs';
8
+ import { b as augmentRouter, d as augmentImplementedRouter, e as withHiddenRouterContract, f as createGuardedProcedureLazy, g as getRouter } from './shared/server.BoiFpNT7.mjs';
9
+ export { a as DEFAULT_ERROR_STATUS, D as DEFAULT_SUCCESS_STATUS, h as call, c as createContractProcedure, i as getHiddenRouterContract, u as unlazyRouter, j as walkProcedureContractsAsync, w as walkProcedureContractsSync } from './shared/server.BoiFpNT7.mjs';
10
10
  import { RECURSIVE_CLIENT_UNWRAP_KEYS } from '@orpc/client';
11
11
  export { COMMON_ERROR_STATUS_MAP, ORPCError, RPCJsonSerializer, RPCSerializer, cloneORPCError, isDefinedError, isInferableError, safe, toORPCError } from '@orpc/client';
12
12
  export { ErrorEvent, getEventMeta, unwrapEvent, withEventMeta } from '@standardserver/core';
@@ -99,6 +99,12 @@ class Builder {
99
99
  $context() {
100
100
  return this;
101
101
  }
102
+ $config(config) {
103
+ return new Builder({
104
+ ...this["~orpc"],
105
+ ...config
106
+ });
107
+ }
102
108
  meta(...plugins) {
103
109
  const [meta, metaPlugins] = resolveMetaPlugins(
104
110
  this["~orpc"].meta,
@@ -191,10 +197,8 @@ class Builder {
191
197
  }
192
198
  router(router) {
193
199
  return augmentRouter(router, {
194
- middlewares: this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware),
195
- meta: this["~orpc"].meta,
196
- metaPlugins: this["~orpc"].metaPlugins,
197
- errorMap: this["~orpc"].errorMap
200
+ ...this["~orpc"],
201
+ middlewares: this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware)
198
202
  });
199
203
  }
200
204
  lazy(loader) {
@@ -256,15 +260,20 @@ class ImplementedProcedure extends Procedure {
256
260
  }
257
261
 
258
262
  class SharedRouterImplementer {
259
- constructor(contract, middlewares) {
263
+ constructor(contract, config, middlewares) {
260
264
  this.contract = contract;
265
+ this.config = config;
261
266
  this.middlewares = middlewares;
262
267
  }
263
- static create(contract, middlewares = []) {
264
- return new SharedRouterImplementer(contract, middlewares);
268
+ static create(contract, config, middlewares = []) {
269
+ return new SharedRouterImplementer(
270
+ contract,
271
+ config,
272
+ middlewares
273
+ );
265
274
  }
266
275
  use(middleware) {
267
- return createRouterImplementerInternal(this.contract, [...this.middlewares, middleware]);
276
+ return createRouterImplementerInternal(this.contract, this.config, [...this.middlewares, middleware]);
268
277
  }
269
278
  middleware(middleware) {
270
279
  const allMiddlewares = [
@@ -280,6 +289,7 @@ class SharedRouterImplementer {
280
289
  router(router) {
281
290
  if (this.middlewares.length) {
282
291
  router = augmentImplementedRouter(router, {
292
+ ...this.config,
283
293
  middlewares: this.middlewares
284
294
  });
285
295
  }
@@ -292,6 +302,7 @@ class SharedRouterImplementer {
292
302
  const { default: router } = await originalLoader();
293
303
  return {
294
304
  default: augmentImplementedRouter(router, {
305
+ ...this.config,
295
306
  middlewares: this.middlewares
296
307
  })
297
308
  };
@@ -300,12 +311,13 @@ class SharedRouterImplementer {
300
311
  return new Lazy({ loader, meta: {} });
301
312
  }
302
313
  }
303
- function createRouterImplementer(contract) {
304
- return createRouterImplementerInternal(contract, []);
314
+ function createRouterImplementer(contract, config) {
315
+ return createRouterImplementerInternal(contract, config, []);
305
316
  }
306
- function createRouterImplementerInternal(contract, middlewares) {
317
+ function createRouterImplementerInternal(contract, config, middlewares) {
307
318
  if (contract instanceof ProcedureContract) {
308
319
  return new ProcedureImplementer({
320
+ ...config,
309
321
  ...contract["~orpc"],
310
322
  orderedMiddlewares: middlewares.map((middleware) => ({ middleware }))
311
323
  });
@@ -313,9 +325,9 @@ function createRouterImplementerInternal(contract, middlewares) {
313
325
  const implementer = {};
314
326
  for (const key in contract) {
315
327
  const child = contract[key];
316
- implementer[key] = createRouterImplementerInternal(child, middlewares);
328
+ implementer[key] = createRouterImplementerInternal(child, config, middlewares);
317
329
  }
318
- const shared = bindMethods(SharedRouterImplementer.create(contract, middlewares));
330
+ const shared = bindMethods(SharedRouterImplementer.create(contract, config, middlewares));
319
331
  for (const key in shared) {
320
332
  const method = shared[key];
321
333
  if (key in implementer) {
@@ -332,13 +344,15 @@ function createRouterImplementerInternal(contract, middlewares) {
332
344
  return implementer;
333
345
  }
334
346
 
335
- function implement(contract) {
336
- const routerImplementer = createRouterImplementer(contract);
347
+ function implement(contract, config = {}) {
348
+ const routerImplementer = createRouterImplementer(contract, config);
337
349
  const implementer = new Proxy(routerImplementer, {
338
350
  get(_, p) {
339
351
  let method;
340
352
  if (p === "$context") {
341
353
  method = () => implementer;
354
+ } else if (p === "$config") {
355
+ method = (incoming) => implement(contract, { ...config, ...incoming });
342
356
  }
343
357
  const value = getOrBind(routerImplementer, p);
344
358
  if (method) {
@@ -1,7 +1,7 @@
1
- import { Value, Promisable } from '@orpc/shared';
1
+ import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
2
  import { StandardLazyRequest, StandardHeaders } from '@standardserver/core';
3
- import { C as Context } from '../shared/server.BL22TloH.mjs';
4
- import { e as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions } from '../shared/server.BB_Ik9Ph.mjs';
3
+ import { C as Context } from '../shared/server.CcR4kgje.mjs';
4
+ import { e as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions, g as StandardHandlerInterceptorOptions } from '../shared/server.DDFizwfU.mjs';
5
5
  import '@orpc/client';
6
6
  import '@orpc/contract';
7
7
 
@@ -30,6 +30,29 @@ interface BatchHandlerPluginOptions<T extends Context> {
30
30
  * @default {}
31
31
  */
32
32
  headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
33
+ /**
34
+ * Keep-alive settings for streaming batch responses.
35
+ *
36
+ * When enabled, a zero-length length-prefixed frame is sent periodically while the
37
+ * stream is idle (no message sent for `interval` ms). Clients ignore these frames.
38
+ * Only applies to streaming mode.
39
+ *
40
+ * @default { enabled: true, interval: 15000 }
41
+ */
42
+ keepAlive?: undefined | {
43
+ /**
44
+ * If true, a keep-alive frame is sent periodically while the stream is idle.
45
+ *
46
+ * @default true
47
+ */
48
+ enabled: boolean;
49
+ /**
50
+ * Interval (in milliseconds) between keep-alive frames after the last message.
51
+ *
52
+ * @default 15000
53
+ */
54
+ interval?: number;
55
+ };
33
56
  }
34
57
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
35
58
  name: string;
@@ -42,6 +65,8 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
42
65
  private readonly mapSubrequest;
43
66
  private readonly successStatus;
44
67
  private readonly headers;
68
+ private readonly keepAliveEnabled;
69
+ private readonly keepAliveInterval;
45
70
  constructor(options?: BatchHandlerPluginOptions<T>);
46
71
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
47
72
  }
@@ -123,6 +148,15 @@ declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandl
123
148
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
124
149
  }
125
150
 
151
+ declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
152
+ name: string;
153
+ /**
154
+ * Should decompress the original batch request body instead of sub-requests.
155
+ */
156
+ after: string[];
157
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
158
+ }
159
+
126
160
  interface RequestHeadersHandlerPluginContext {
127
161
  /**
128
162
  * Request headers as a Headers instance. This is injected by the Request Headers Plugin.
@@ -140,6 +174,72 @@ declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginC
140
174
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
141
175
  }
142
176
 
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
+ interface ResponseCompressionHandlerPluginOptions<_T extends Context> {
207
+ /**
208
+ * The compression schemes to use for response compression.
209
+ * Schemes are prioritized by their order in this array and
210
+ * only applied if the client supports them (via Accept-Encoding).
211
+ *
212
+ * @default ['gzip', 'deflate']
213
+ */
214
+ encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
215
+ /**
216
+ * The minimum response size in bytes required to trigger compression.
217
+ * Responses smaller than this threshold will not be compressed to avoid overhead.
218
+ * If the response size cannot be determined, compression will still be applied.
219
+ *
220
+ * @default 1024 (1KB)
221
+ */
222
+ threshold?: number;
223
+ }
224
+ /**
225
+ * Compresses response bodies based on the client's Accept-Encoding header.
226
+ * Works at the standard handler level, so it supports all adapters.
227
+ *
228
+ * @see {@link https://orpc.dev/docs/plugins/response-compression Response Compression Plugin Docs}
229
+ */
230
+ declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
231
+ name: string;
232
+ /**
233
+ * Compression should be done after batching, to compress the final response.
234
+ * Compression should also be done after response headers are set, to access final headers like Content-Type and Cache-Control.
235
+ */
236
+ after: string[];
237
+ private readonly encodings;
238
+ private readonly threshold;
239
+ constructor(options?: ResponseCompressionHandlerPluginOptions<T>);
240
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
241
+ }
242
+
143
243
  interface ResponseHeadersHandlerPluginContext {
144
244
  /**
145
245
  * Response headers as a Headers instance. This is injected by the Response Headers Plugin.
@@ -162,5 +262,36 @@ declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPlugi
162
262
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
163
263
  }
164
264
 
165
- export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestHeadersHandlerPlugin, ResponseHeadersHandlerPlugin };
166
- export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext };
265
+ interface RethrowHandlerPluginOptions<T extends Context> {
266
+ /**
267
+ * Decide which errors should be rethrown.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * const rethrowPlugin = new RethrowHandlerPlugin({
272
+ * filter: (error) => {
273
+ * // Rethrow all non-ORPCError errors
274
+ * return !(error instanceof ORPCError)
275
+ * }
276
+ * })
277
+ * ```
278
+ */
279
+ filter: (error: ThrowableError, options: StandardHandlerInterceptorOptions<T>) => boolean;
280
+ }
281
+ /**
282
+ * The plugin can bypass oRPC's built-in error handling
283
+ * and rethrow matching errors directly to your framework's error handling mechanism
284
+ * (e.g., NestJS exception filters, Express error middleware).
285
+ *
286
+ * @see {@link https://orpc.dev/docs/plugins/rethrow Rethrow Plugin Documentation}
287
+ */
288
+ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
289
+ name: string;
290
+ private readonly filter;
291
+ private readonly CONTEXT_SYMBOL;
292
+ constructor(options: RethrowHandlerPluginOptions<T>);
293
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
294
+ }
295
+
296
+ export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestLimitHandlerPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, RethrowHandlerPlugin };
297
+ export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestLimitHandlerPluginOptions, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, RethrowHandlerPluginOptions };
@@ -1,7 +1,7 @@
1
- import { Value, Promisable } from '@orpc/shared';
1
+ import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
2
  import { StandardLazyRequest, StandardHeaders } from '@standardserver/core';
3
- import { C as Context } from '../shared/server.BL22TloH.js';
4
- import { e as StandardHandlerPlugin, f as StandardHandlerRoutingInterceptorOptions, a as StandardHandlerOptions } from '../shared/server.EOHJ3NJr.js';
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';
5
5
  import '@orpc/client';
6
6
  import '@orpc/contract';
7
7
 
@@ -30,6 +30,29 @@ interface BatchHandlerPluginOptions<T extends Context> {
30
30
  * @default {}
31
31
  */
32
32
  headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
33
+ /**
34
+ * Keep-alive settings for streaming batch responses.
35
+ *
36
+ * When enabled, a zero-length length-prefixed frame is sent periodically while the
37
+ * stream is idle (no message sent for `interval` ms). Clients ignore these frames.
38
+ * Only applies to streaming mode.
39
+ *
40
+ * @default { enabled: true, interval: 15000 }
41
+ */
42
+ keepAlive?: undefined | {
43
+ /**
44
+ * If true, a keep-alive frame is sent periodically while the stream is idle.
45
+ *
46
+ * @default true
47
+ */
48
+ enabled: boolean;
49
+ /**
50
+ * Interval (in milliseconds) between keep-alive frames after the last message.
51
+ *
52
+ * @default 15000
53
+ */
54
+ interval?: number;
55
+ };
33
56
  }
34
57
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
35
58
  name: string;
@@ -42,6 +65,8 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
42
65
  private readonly mapSubrequest;
43
66
  private readonly successStatus;
44
67
  private readonly headers;
68
+ private readonly keepAliveEnabled;
69
+ private readonly keepAliveInterval;
45
70
  constructor(options?: BatchHandlerPluginOptions<T>);
46
71
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
47
72
  }
@@ -123,6 +148,15 @@ declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandl
123
148
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
124
149
  }
125
150
 
151
+ declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
152
+ name: string;
153
+ /**
154
+ * Should decompress the original batch request body instead of sub-requests.
155
+ */
156
+ after: string[];
157
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
158
+ }
159
+
126
160
  interface RequestHeadersHandlerPluginContext {
127
161
  /**
128
162
  * Request headers as a Headers instance. This is injected by the Request Headers Plugin.
@@ -140,6 +174,72 @@ declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginC
140
174
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
141
175
  }
142
176
 
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
+ interface ResponseCompressionHandlerPluginOptions<_T extends Context> {
207
+ /**
208
+ * The compression schemes to use for response compression.
209
+ * Schemes are prioritized by their order in this array and
210
+ * only applied if the client supports them (via Accept-Encoding).
211
+ *
212
+ * @default ['gzip', 'deflate']
213
+ */
214
+ encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
215
+ /**
216
+ * The minimum response size in bytes required to trigger compression.
217
+ * Responses smaller than this threshold will not be compressed to avoid overhead.
218
+ * If the response size cannot be determined, compression will still be applied.
219
+ *
220
+ * @default 1024 (1KB)
221
+ */
222
+ threshold?: number;
223
+ }
224
+ /**
225
+ * Compresses response bodies based on the client's Accept-Encoding header.
226
+ * Works at the standard handler level, so it supports all adapters.
227
+ *
228
+ * @see {@link https://orpc.dev/docs/plugins/response-compression Response Compression Plugin Docs}
229
+ */
230
+ declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
231
+ name: string;
232
+ /**
233
+ * Compression should be done after batching, to compress the final response.
234
+ * Compression should also be done after response headers are set, to access final headers like Content-Type and Cache-Control.
235
+ */
236
+ after: string[];
237
+ private readonly encodings;
238
+ private readonly threshold;
239
+ constructor(options?: ResponseCompressionHandlerPluginOptions<T>);
240
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
241
+ }
242
+
143
243
  interface ResponseHeadersHandlerPluginContext {
144
244
  /**
145
245
  * Response headers as a Headers instance. This is injected by the Response Headers Plugin.
@@ -162,5 +262,36 @@ declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPlugi
162
262
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
163
263
  }
164
264
 
165
- export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestHeadersHandlerPlugin, ResponseHeadersHandlerPlugin };
166
- export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext };
265
+ interface RethrowHandlerPluginOptions<T extends Context> {
266
+ /**
267
+ * Decide which errors should be rethrown.
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * const rethrowPlugin = new RethrowHandlerPlugin({
272
+ * filter: (error) => {
273
+ * // Rethrow all non-ORPCError errors
274
+ * return !(error instanceof ORPCError)
275
+ * }
276
+ * })
277
+ * ```
278
+ */
279
+ filter: (error: ThrowableError, options: StandardHandlerInterceptorOptions<T>) => boolean;
280
+ }
281
+ /**
282
+ * The plugin can bypass oRPC's built-in error handling
283
+ * and rethrow matching errors directly to your framework's error handling mechanism
284
+ * (e.g., NestJS exception filters, Express error middleware).
285
+ *
286
+ * @see {@link https://orpc.dev/docs/plugins/rethrow Rethrow Plugin Documentation}
287
+ */
288
+ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
289
+ name: string;
290
+ private readonly filter;
291
+ private readonly CONTEXT_SYMBOL;
292
+ constructor(options: RethrowHandlerPluginOptions<T>);
293
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
294
+ }
295
+
296
+ export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestLimitHandlerPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, RethrowHandlerPlugin };
297
+ export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestLimitHandlerPluginOptions, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, RethrowHandlerPluginOptions };