@orpc/server 2.0.0-beta.3 → 2.0.0-beta.30

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 (56) hide show
  1. package/README.md +71 -101
  2. package/dist/adapters/aws-lambda/index.d.mts +93 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +93 -0
  4. package/dist/adapters/aws-lambda/index.mjs +66 -0
  5. package/dist/adapters/crossws/index.d.mts +17 -8
  6. package/dist/adapters/crossws/index.d.ts +17 -8
  7. package/dist/adapters/crossws/index.mjs +10 -7
  8. package/dist/adapters/fastify/index.d.mts +85 -0
  9. package/dist/adapters/fastify/index.d.ts +85 -0
  10. package/dist/adapters/fastify/index.mjs +66 -0
  11. package/dist/adapters/fetch/index.d.mts +16 -67
  12. package/dist/adapters/fetch/index.d.ts +16 -67
  13. package/dist/adapters/fetch/index.mjs +8 -144
  14. package/dist/adapters/message-port/index.d.mts +19 -16
  15. package/dist/adapters/message-port/index.d.ts +19 -16
  16. package/dist/adapters/message-port/index.mjs +28 -32
  17. package/dist/adapters/node/index.d.mts +15 -49
  18. package/dist/adapters/node/index.d.ts +15 -49
  19. package/dist/adapters/node/index.mjs +9 -120
  20. package/dist/adapters/standard/index.d.mts +6 -6
  21. package/dist/adapters/standard/index.d.ts +6 -6
  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 +42 -26
  26. package/dist/adapters/websocket/index.d.ts +42 -26
  27. package/dist/adapters/websocket/index.mjs +33 -25
  28. package/dist/extensions/callable.d.mts +2 -2
  29. package/dist/extensions/callable.d.ts +2 -2
  30. package/dist/extensions/callable.mjs +2 -2
  31. package/dist/helpers/index.d.mts +23 -6
  32. package/dist/helpers/index.d.ts +23 -6
  33. package/dist/helpers/index.mjs +13 -5
  34. package/dist/index.d.mts +311 -16
  35. package/dist/index.d.ts +311 -16
  36. package/dist/index.mjs +126 -34
  37. package/dist/plugins/index.d.mts +236 -18
  38. package/dist/plugins/index.d.ts +236 -18
  39. package/dist/plugins/index.mjs +474 -15
  40. package/dist/shared/server.BhHrioCw.d.ts +34 -0
  41. package/dist/shared/{server.T9F3bzZx.d.ts → server.C2n16pp0.d.ts} +34 -9
  42. package/dist/shared/server.Cd4Z1hpV.mjs +69 -0
  43. package/dist/shared/{server.CrlKQucM.mjs → server.CkButhNT.mjs} +21 -38
  44. package/dist/shared/{server.B_U9y00a.d.mts → server.CkNnZ5F-.d.mts} +34 -9
  45. package/dist/shared/{server.BL22TloH.d.mts → server.CwrYlF72.d.mts} +31 -41
  46. package/dist/shared/{server.BL22TloH.d.ts → server.CwrYlF72.d.ts} +31 -41
  47. package/dist/shared/server.D0Ipbmdv.d.mts +34 -0
  48. package/dist/shared/{server.GDpX6Df8.mjs → server.D9VprDph.mjs} +82 -49
  49. package/dist/shared/{server.BwHnWUuN.mjs → server.Dh77P3ii.mjs} +17 -10
  50. package/dist/shared/{server.Pa0F03f_.d.ts → server.Dm0os-OP.d.mts} +24 -12
  51. package/dist/shared/{server.EOHJ3NJr.d.ts → server.DrN1Pj1-.d.ts} +3 -3
  52. package/dist/shared/{server.BsNNjG5J.d.mts → server.DtfwuV6U.d.ts} +24 -12
  53. package/dist/shared/{server.BB_Ik9Ph.d.mts → server.JbCIPL4P.d.mts} +3 -3
  54. package/dist/shared/{server.CjOb6ItT.mjs → server.eCTV8Vpp.mjs} +1 -1
  55. package/package.json +46 -12
  56. package/dist/shared/server.D_QauotT.mjs +0 -30
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';
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';
2
+ export { ValidationError, asyncIteratorObject, defineMeta, error, eventIterator, reconcileORPCError, type } from '@orpc/contract';
3
+ import { toArray, bindMethods, isTypescriptObject, resolveMaybeOptionalOptions } from '@orpc/shared';
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.CkButhNT.mjs';
6
+ export { u as unlazy } from './shared/server.CkButhNT.mjs';
7
+ import { D as DecoratedProcedure } from './shared/server.eCTV8Vpp.mjs';
8
+ import { b as augmentRouter, d as augmentImplementedRouter, e as withHiddenRouterContract, f as createGuardedProcedureLazy, g as getRouter } from './shared/server.Dh77P3ii.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.Dh77P3ii.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';
@@ -86,9 +86,19 @@ function decorateMiddleware(middleware) {
86
86
 
87
87
  class Builder {
88
88
  "~orpc";
89
+ /**
90
+ * Private constructor to prevent direct instantiation.
91
+ * Use the static `create` method to initialize a new instance with a safe initial definition.
92
+ */
89
93
  constructor(definition) {
90
94
  this["~orpc"] = definition;
91
95
  }
96
+ /**
97
+ * Creates a fresh builder with an empty definition.
98
+ * Prefer the exported `os` instance over calling this directly.
99
+ *
100
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
101
+ */
92
102
  static create() {
93
103
  return new Builder({
94
104
  errorMap: {},
@@ -96,9 +106,32 @@ class Builder {
96
106
  orderedMiddlewares: []
97
107
  });
98
108
  }
109
+ /**
110
+ * Declares the initial context type that must be provided when executing
111
+ * procedures built from this builder.
112
+ *
113
+ * @see {@link https://orpc.dev/docs/context#initial-context | Context - Initial Context}
114
+ */
99
115
  $context() {
100
116
  return this;
101
117
  }
118
+ /**
119
+ * Overrides the procedure configuration, such as disabling runtime
120
+ * input/output validation.
121
+ *
122
+ * @see {@link https://orpc.dev/docs/advanced/validation-customization | Validation Customization}
123
+ */
124
+ $config(config) {
125
+ return new Builder({
126
+ ...this["~orpc"],
127
+ ...config
128
+ });
129
+ }
130
+ /**
131
+ * Applies metadata plugins to procedures built from this builder.
132
+ *
133
+ * @see {@link https://orpc.dev/docs/metadata | Metadata}
134
+ */
102
135
  meta(...plugins) {
103
136
  const [meta, metaPlugins] = resolveMetaPlugins(
104
137
  this["~orpc"].meta,
@@ -111,6 +144,12 @@ class Builder {
111
144
  metaPlugins
112
145
  });
113
146
  }
147
+ /**
148
+ * Defines typesafe errors that procedures built from this builder can throw
149
+ * via the `errors` utility in handlers and middleware.
150
+ *
151
+ * @see {@link https://orpc.dev/docs/error-handling#typesafe-errors | Error Handling - Typesafe Errors}
152
+ */
114
153
  errors(errors) {
115
154
  let builder = new Builder({
116
155
  ...this["~orpc"],
@@ -122,6 +161,12 @@ class Builder {
122
161
  }
123
162
  return builder;
124
163
  }
164
+ /**
165
+ * Applies a middleware that runs before the handler of every procedure
166
+ * built from this builder.
167
+ *
168
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
169
+ */
125
170
  use(middleware) {
126
171
  let builder = new Builder({
127
172
  ...this["~orpc"],
@@ -137,6 +182,12 @@ class Builder {
137
182
  }
138
183
  return builder;
139
184
  }
185
+ /**
186
+ * Creates a standalone middleware that can be composed and applied to any
187
+ * compatible builder or procedure with `.use`.
188
+ *
189
+ * @see {@link https://orpc.dev/docs/middleware | Middleware}
190
+ */
140
191
  middleware(middleware) {
141
192
  const allMiddlewares = [
142
193
  ...this["~orpc"].orderedMiddlewares.map(({ middleware: middleware2 }) => middleware2),
@@ -156,6 +207,11 @@ class Builder {
156
207
  };
157
208
  return current;
158
209
  }
210
+ /**
211
+ * Defines the input schema used to validate and type the procedure input.
212
+ *
213
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
214
+ */
159
215
  input(schema) {
160
216
  let builder = new Builder({
161
217
  ...this["~orpc"],
@@ -167,6 +223,11 @@ class Builder {
167
223
  }
168
224
  return builder;
169
225
  }
226
+ /**
227
+ * Defines the output schema used to validate and type the procedure output.
228
+ *
229
+ * @see {@link https://orpc.dev/docs/procedure#inputoutput-validation | Procedure - Input/Output Validation}
230
+ */
170
231
  output(schema) {
171
232
  let builder = new Builder({
172
233
  ...this["~orpc"],
@@ -178,6 +239,12 @@ class Builder {
178
239
  }
179
240
  return builder;
180
241
  }
242
+ /**
243
+ * Defines the function that implements the procedure and completes the
244
+ * chain, returning a callable procedure.
245
+ *
246
+ * @see {@link https://orpc.dev/docs/procedure | Procedure}
247
+ */
181
248
  handler(handler) {
182
249
  let procedure = new DecoratedProcedure({
183
250
  ...this["~orpc"],
@@ -189,14 +256,24 @@ class Builder {
189
256
  }
190
257
  return procedure;
191
258
  }
259
+ /**
260
+ * Applies the builder's middleware, errors, and metadata to every procedure
261
+ * in the given router.
262
+ *
263
+ * @see {@link https://orpc.dev/docs/router#extending-router | Router - Extending Router}
264
+ */
192
265
  router(router) {
193
266
  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
267
+ ...this["~orpc"],
268
+ middlewares: this["~orpc"].orderedMiddlewares.map(({ middleware }) => middleware)
198
269
  });
199
270
  }
271
+ /**
272
+ * Like `.router`, but loads the router lazily on first access, which helps
273
+ * reduce startup time for large applications.
274
+ *
275
+ * @see {@link https://orpc.dev/docs/router#lazy-router | Router - Lazy Router}
276
+ */
200
277
  lazy(loader) {
201
278
  return new Lazy({
202
279
  loader: async () => {
@@ -256,15 +333,20 @@ class ImplementedProcedure extends Procedure {
256
333
  }
257
334
 
258
335
  class SharedRouterImplementer {
259
- constructor(contract, middlewares) {
336
+ constructor(contract, config, middlewares) {
260
337
  this.contract = contract;
338
+ this.config = config;
261
339
  this.middlewares = middlewares;
262
340
  }
263
- static create(contract, middlewares = []) {
264
- return new SharedRouterImplementer(contract, middlewares);
341
+ static create(contract, config, middlewares = []) {
342
+ return new SharedRouterImplementer(
343
+ contract,
344
+ config,
345
+ middlewares
346
+ );
265
347
  }
266
348
  use(middleware) {
267
- return createRouterImplementerInternal(this.contract, [...this.middlewares, middleware]);
349
+ return createRouterImplementerInternal(this.contract, this.config, [...this.middlewares, middleware]);
268
350
  }
269
351
  middleware(middleware) {
270
352
  const allMiddlewares = [
@@ -280,6 +362,7 @@ class SharedRouterImplementer {
280
362
  router(router) {
281
363
  if (this.middlewares.length) {
282
364
  router = augmentImplementedRouter(router, {
365
+ ...this.config,
283
366
  middlewares: this.middlewares
284
367
  });
285
368
  }
@@ -292,6 +375,7 @@ class SharedRouterImplementer {
292
375
  const { default: router } = await originalLoader();
293
376
  return {
294
377
  default: augmentImplementedRouter(router, {
378
+ ...this.config,
295
379
  middlewares: this.middlewares
296
380
  })
297
381
  };
@@ -300,12 +384,13 @@ class SharedRouterImplementer {
300
384
  return new Lazy({ loader, meta: {} });
301
385
  }
302
386
  }
303
- function createRouterImplementer(contract) {
304
- return createRouterImplementerInternal(contract, []);
387
+ function createRouterImplementer(contract, config) {
388
+ return createRouterImplementerInternal(contract, config, []);
305
389
  }
306
- function createRouterImplementerInternal(contract, middlewares) {
390
+ function createRouterImplementerInternal(contract, config, middlewares) {
307
391
  if (contract instanceof ProcedureContract) {
308
392
  return new ProcedureImplementer({
393
+ ...config,
309
394
  ...contract["~orpc"],
310
395
  orderedMiddlewares: middlewares.map((middleware) => ({ middleware }))
311
396
  });
@@ -313,16 +398,16 @@ function createRouterImplementerInternal(contract, middlewares) {
313
398
  const implementer = {};
314
399
  for (const key in contract) {
315
400
  const child = contract[key];
316
- implementer[key] = createRouterImplementerInternal(child, middlewares);
401
+ implementer[key] = createRouterImplementerInternal(child, config, middlewares);
317
402
  }
318
- const shared = bindMethods(SharedRouterImplementer.create(contract, middlewares));
403
+ const shared = bindMethods(SharedRouterImplementer.create(contract, config, middlewares));
319
404
  for (const key in shared) {
320
405
  const method = shared[key];
321
406
  if (key in implementer) {
322
407
  const child = implementer[key];
323
408
  implementer[key] = new Proxy(method, {
324
409
  get(_, p) {
325
- return getOrBind(child, p);
410
+ return Reflect.get(child, p);
326
411
  }
327
412
  });
328
413
  } else {
@@ -332,22 +417,24 @@ function createRouterImplementerInternal(contract, middlewares) {
332
417
  return implementer;
333
418
  }
334
419
 
335
- function implement(contract) {
336
- const routerImplementer = createRouterImplementer(contract);
420
+ function implement(contract, config = {}) {
421
+ const routerImplementer = createRouterImplementer(contract, config);
337
422
  const implementer = new Proxy(routerImplementer, {
338
423
  get(_, p) {
339
424
  let method;
340
425
  if (p === "$context") {
341
426
  method = () => implementer;
427
+ } else if (p === "$config") {
428
+ method = (incoming) => implement(contract, { ...config, ...incoming });
342
429
  }
343
- const value = getOrBind(routerImplementer, p);
430
+ const value = Reflect.get(routerImplementer, p);
344
431
  if (method) {
345
432
  if (!isTypescriptObject(value)) {
346
433
  return method;
347
434
  }
348
435
  return new Proxy(method, {
349
436
  get(_2, p2) {
350
- return getOrBind(value, p2);
437
+ return Reflect.get(value, p2);
351
438
  }
352
439
  });
353
440
  }
@@ -363,19 +450,24 @@ function createRouterClient(router, ...rest) {
363
450
  return createProcedureClient(router, options);
364
451
  }
365
452
  const procedureCaller = router instanceof Lazy ? createProcedureClient(createGuardedProcedureLazy(router), options) : {};
453
+ const cache = /* @__PURE__ */ new Map();
366
454
  const recursive = new Proxy(procedureCaller, {
367
455
  get(target, key) {
368
456
  if (typeof key !== "string" || router instanceof Lazy && RECURSIVE_CLIENT_UNWRAP_KEYS.has(key)) {
369
- return getOrBind(target, key);
457
+ return Reflect.get(target, key);
370
458
  }
371
- const next = getRouter(router, [key]);
372
- if (!next) {
373
- return getOrBind(target, key);
459
+ let nextClient = cache.get(key);
460
+ if (nextClient === void 0) {
461
+ const next = getRouter(router, [key]);
462
+ if (!next) {
463
+ return Reflect.get(target, key);
464
+ }
465
+ nextClient = createRouterClient(next, {
466
+ ...options,
467
+ path: [...toArray(options.path), key]
468
+ });
469
+ cache.set(key, nextClient);
374
470
  }
375
- const nextClient = createRouterClient(next, {
376
- ...options,
377
- path: [...toArray(options.path), key]
378
- });
379
471
  return nextClient;
380
472
  }
381
473
  });
@@ -1,10 +1,19 @@
1
- import { Value, Promisable } from '@orpc/shared';
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';
1
+ import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
+ import { StandardLazyRequest, StandardHeaders, StandardMethod } from '@standardserver/core';
3
+ import { Context } from '../index.mjs';
4
+ import { StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions, StandardHandlerOptions, StandardHandlerInterceptorOptions } from '../adapters/standard/index.mjs';
5
+ export { R as RequestLimitHandlerPlugin, a as RequestLimitHandlerPluginOptions } from '../shared/server.D0Ipbmdv.mjs';
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.
@@ -30,7 +39,39 @@ interface BatchHandlerPluginOptions<T extends Context> {
30
39
  * @default {}
31
40
  */
32
41
  headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
42
+ /**
43
+ * Keep-alive settings for streaming batch responses.
44
+ *
45
+ * When enabled, a zero-length length-prefixed frame is sent periodically while the
46
+ * stream is idle (no message sent for `interval` ms). Clients ignore these frames.
47
+ * Only applies to streaming mode.
48
+ *
49
+ * @default { enabled: true, interval: 15000 }
50
+ */
51
+ keepAlive?: undefined | {
52
+ /**
53
+ * If true, a keep-alive frame is sent periodically while the stream is idle.
54
+ *
55
+ * @default true
56
+ */
57
+ enabled: boolean;
58
+ /**
59
+ * Interval (in milliseconds) between keep-alive frames after the last message.
60
+ *
61
+ * @default 15000
62
+ */
63
+ interval?: number;
64
+ };
33
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
+ */
34
75
  declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
35
76
  name: string;
36
77
  /**
@@ -42,6 +83,8 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
42
83
  private readonly mapSubrequest;
43
84
  private readonly successStatus;
44
85
  private readonly headers;
86
+ private readonly keepAliveEnabled;
87
+ private readonly keepAliveInterval;
45
88
  constructor(options?: BatchHandlerPluginOptions<T>);
46
89
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
47
90
  }
@@ -53,18 +96,18 @@ interface CORSHandlerPluginOptions<T extends Context> {
53
96
  *
54
97
  * @default (origin) => origin
55
98
  */
56
- origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
99
+ origin?: Value<string | readonly string[] | null | undefined, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
57
100
  /**
58
101
  * Configures the `Timing-Allow-Origin` header.
59
102
  * Can be a string, an array of allowed origins, or a function that returns the allowed origin(s).
60
103
  *
61
104
  * @default undefined
62
105
  */
63
- timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
106
+ timingOrigin?: Value<string | readonly string[] | null | undefined, [origin: string | undefined, options: StandardHandlerRoutingInterceptorOptions<T>]>;
64
107
  /**
65
108
  * Configures the `Access-Control-Allow-Methods` header for preflight requests.
66
109
  *
67
- * @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH']
110
+ * @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']
68
111
  */
69
112
  allowMethods?: readonly string[];
70
113
  /**
@@ -94,9 +137,10 @@ interface CORSHandlerPluginOptions<T extends Context> {
94
137
  exposeHeaders?: readonly string[];
95
138
  }
96
139
  /**
97
- * 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.
98
142
  *
99
- * @see {@link https://orpc.dev/docs/plugins/cors CORS Plugin Docs}
143
+ * @see {@link https://orpc.dev/docs/plugins/cors | CORS Handler Plugin}
100
144
  */
101
145
  declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
102
146
  private readonly options;
@@ -112,17 +156,83 @@ declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlu
112
156
  }
113
157
 
114
158
  /**
115
- * Adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
116
- * When a request includes cookies, it helps ensure the request originates from JavaScript
117
- * (for example, fetch/XHR) rather than from standard HTML forms or direct browser navigation.
159
+ * Adds Cross-Site Request Forgery (CSRF) protection that makes the safe `GET` method as
160
+ * secure as unsafe ones such as `POST`. It rejects `GET` requests arriving as top-level
161
+ * navigations initiated cross-site or from outside the browser, the only context where
162
+ * another site can make a browser attach `SameSite=Lax` cookies to a safe-method request.
163
+ *
164
+ * @remarks
165
+ * **Note**: Requests browsers send without `SameSite=Lax` cookies, such as cross-site `fetch`
166
+ * and `<img>`, pass through, so procedures stay reachable from other sites. This safeguard
167
+ * requires authentication cookies explicitly marked `SameSite=Lax` or `SameSite=Strict`,
168
+ * since browsers may attach other cookies to the requests that pass.
169
+ *
170
+ * @see {@link https://orpc.dev/docs/plugins/get-method-csrf-protection | GET Method CSRF Protection Plugin}
171
+ */
172
+ declare class GetMethodCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
173
+ name: string;
174
+ /** Judge the real request, before batch splits it into client-authored sub-requests. */
175
+ after: string[];
176
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
177
+ private isAllowed;
178
+ }
179
+
180
+ interface MethodOverrideHandlerPluginOptions {
181
+ /**
182
+ * The query parameter carrying the override method.
183
+ *
184
+ * @default 'method'
185
+ */
186
+ param?: string;
187
+ /**
188
+ * The methods a POST request may be overridden to.
189
+ *
190
+ * GET and HEAD are excluded by default because they switch input decoding
191
+ * from the request body to the query string and widen the CSRF surface.
192
+ *
193
+ * @default ['PUT', 'PATCH', 'DELETE']
194
+ */
195
+ methods?: readonly StandardMethod[];
196
+ }
197
+ /**
198
+ * Overrides the HTTP method of a POST request based on a query parameter,
199
+ * so HTML forms (which only support GET and POST) can invoke procedures
200
+ * routed as PUT, PATCH, or DELETE.
201
+ *
202
+ * @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
203
+ */
204
+ declare class MethodOverrideHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
205
+ name: string;
206
+ /**
207
+ * Should override batch sub-request methods, not the original batch request.
208
+ */
209
+ before: string[];
210
+ private readonly param;
211
+ private readonly methods;
212
+ constructor(options?: MethodOverrideHandlerPluginOptions);
213
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
214
+ }
215
+
216
+ /**
217
+ * Decompresses incoming request bodies based on the Content-Encoding header,
218
+ * supporting gzip, deflate, and deflate-raw.
118
219
  *
119
- * @info This plugin is enabled by default for `RPCHandler` over HTTP.
220
+ * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
120
221
  */
121
- declare class CSRFGuardHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
222
+ declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
122
223
  name: string;
224
+ /**
225
+ * Should decompress the original batch request body instead of sub-requests.
226
+ */
227
+ after: string[];
123
228
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
124
229
  }
125
230
 
231
+ /**
232
+ * The context shape into which the Request Headers Plugin injects `reqHeaders`.
233
+ *
234
+ * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
235
+ */
126
236
  interface RequestHeadersHandlerPluginContext {
127
237
  /**
128
238
  * Request headers as a Headers instance. This is injected by the Request Headers Plugin.
@@ -133,13 +243,55 @@ interface RequestHeadersHandlerPluginContext {
133
243
  * The Request Headers Plugin injects a `reqHeaders` instance into the context,
134
244
  * allowing access to request headers in oRPC.
135
245
  *
136
- * @see {@link https://orpc.dev/docs/plugins/request-headers Request Headers Plugin Docs}
246
+ * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
137
247
  */
138
248
  declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
139
249
  name: string;
140
250
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
141
251
  }
142
252
 
253
+ interface ResponseCompressionHandlerPluginOptions<_T extends Context> {
254
+ /**
255
+ * The compression schemes to use for response compression.
256
+ * Schemes are prioritized by their order in this array and
257
+ * only applied if the client supports them (via Accept-Encoding).
258
+ *
259
+ * @default ['gzip', 'deflate']
260
+ */
261
+ encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
262
+ /**
263
+ * The minimum response size in bytes required to trigger compression.
264
+ * Responses smaller than this threshold will not be compressed to avoid overhead.
265
+ * If the response size cannot be determined, compression will still be applied.
266
+ *
267
+ * @default 1024 (1KB)
268
+ */
269
+ threshold?: number;
270
+ }
271
+ /**
272
+ * Compresses response bodies based on the client's Accept-Encoding header.
273
+ * Works at the standard handler level, so it supports all adapters.
274
+ *
275
+ * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
276
+ */
277
+ declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
278
+ name: string;
279
+ /**
280
+ * Compression should be done after batching, to compress the final response.
281
+ * Compression should also be done after response headers are set, to access final headers like Content-Type and Cache-Control.
282
+ */
283
+ after: string[];
284
+ private readonly encodings;
285
+ private readonly threshold;
286
+ constructor(options?: ResponseCompressionHandlerPluginOptions<T>);
287
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
288
+ }
289
+
290
+ /**
291
+ * The context shape into which the Response Headers Plugin injects `resHeaders`.
292
+ *
293
+ * @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
294
+ */
143
295
  interface ResponseHeadersHandlerPluginContext {
144
296
  /**
145
297
  * Response headers as a Headers instance. This is injected by the Response Headers Plugin.
@@ -151,7 +303,7 @@ interface ResponseHeadersHandlerPluginContext {
151
303
  * The Response Headers Plugin allows you to set response headers in oRPC.
152
304
  * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
153
305
  *
154
- * @see {@link https://orpc.dev/docs/plugins/response-headers Response Headers Plugin Docs}
306
+ * @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
155
307
  */
156
308
  declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
157
309
  name: string;
@@ -162,5 +314,71 @@ declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPlugi
162
314
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
163
315
  }
164
316
 
165
- export { BatchHandlerPlugin, CORSHandlerPlugin, CSRFGuardHandlerPlugin, RequestHeadersHandlerPlugin, ResponseHeadersHandlerPlugin };
166
- export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, RequestHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext };
317
+ interface RethrowHandlerPluginOptions<T extends Context> {
318
+ /**
319
+ * Decide which errors should be rethrown.
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * const rethrowPlugin = new RethrowHandlerPlugin({
324
+ * filter: (error) => {
325
+ * // Rethrow all non-ORPCError errors
326
+ * return !(error instanceof ORPCError)
327
+ * }
328
+ * })
329
+ * ```
330
+ */
331
+ filter: (error: ThrowableError, options: StandardHandlerInterceptorOptions<T>) => boolean;
332
+ }
333
+ /**
334
+ * The plugin can bypass oRPC's built-in error handling
335
+ * and rethrow matching errors directly to your framework's error handling mechanism
336
+ * (e.g., NestJS exception filters, Express error middleware).
337
+ *
338
+ * @see {@link https://orpc.dev/docs/plugins/rethrow | Rethrow Handler Plugin}
339
+ */
340
+ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
341
+ name: string;
342
+ private readonly filter;
343
+ private readonly CONTEXT_SYMBOL;
344
+ constructor(options: RethrowHandlerPluginOptions<T>);
345
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
346
+ }
347
+
348
+ interface TimeoutHandlerPluginOptions<T extends Context> {
349
+ /**
350
+ * Timeout in milliseconds before the request signal is aborted.
351
+ * This only covers producing the response, use `streamingTimeout`
352
+ * to limit streaming response bodies.
353
+ * Use `null` or `undefined` to disable the timeout.
354
+ */
355
+ timeout: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]>;
356
+ /**
357
+ * Timeout in milliseconds for the full duration of a streaming response body
358
+ * (async iterator object or readable stream), measured from when the response is produced.
359
+ * When exceeded, the request signal is aborted and the body ends
360
+ * once its producer honors the signal.
361
+ * Usually higher than `timeout`.
362
+ * Use `null` or `undefined` to disable the timeout.
363
+ *
364
+ * @default undefined (streaming responses run without limit)
365
+ */
366
+ streamingTimeout?: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]>;
367
+ }
368
+ /**
369
+ * The Timeout Handler Plugin aborts the request signal with an `AbortError`
370
+ * when handling exceeds a configured timeout. It only aborts the signal,
371
+ * the procedure must honor it to stop early and produce the response.
372
+ *
373
+ * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
374
+ */
375
+ declare class TimeoutHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
376
+ private readonly timeout;
377
+ private readonly streamingTimeout;
378
+ name: string;
379
+ constructor(options: NoInfer<TimeoutHandlerPluginOptions<T>>);
380
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
381
+ }
382
+
383
+ export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, GetMethodCsrfProtectionHandlerPlugin, MethodOverrideHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, TimeoutHandlerPlugin };
384
+ export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, MethodOverrideHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions, TimeoutHandlerPluginOptions };