@orpc/server 2.0.0-beta.47 → 2.0.0-beta.49

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 (178) hide show
  1. package/README.md +6 -7
  2. package/dist/adapters/aws-lambda/handler.d.ts +25 -0
  3. package/dist/adapters/aws-lambda/handler.js +24 -0
  4. package/dist/adapters/aws-lambda/index.d.ts +10 -45
  5. package/dist/adapters/aws-lambda/index.js +2 -0
  6. package/dist/adapters/aws-lambda/rpc-handler.d.ts +19 -0
  7. package/dist/adapters/aws-lambda/rpc-handler.js +18 -0
  8. package/dist/adapters/crossws/handler.d.ts +45 -0
  9. package/dist/adapters/crossws/handler.js +60 -0
  10. package/dist/adapters/crossws/index.d.ts +2 -63
  11. package/dist/adapters/crossws/index.js +2 -0
  12. package/dist/adapters/crossws/rpc-handler.d.ts +16 -0
  13. package/dist/adapters/crossws/rpc-handler.js +15 -0
  14. package/dist/adapters/fastify/handler.d.ts +21 -0
  15. package/dist/adapters/fastify/handler.js +20 -0
  16. package/dist/adapters/fastify/index.d.ts +2 -42
  17. package/dist/adapters/fastify/index.js +2 -0
  18. package/dist/adapters/fastify/rpc-handler.d.ts +15 -0
  19. package/dist/adapters/fastify/rpc-handler.js +14 -0
  20. package/dist/adapters/fetch/handler.d.ts +23 -0
  21. package/dist/adapters/fetch/handler.js +22 -0
  22. package/dist/adapters/fetch/index.d.ts +5 -45
  23. package/dist/adapters/fetch/index.js +7 -0
  24. package/dist/adapters/fetch/rpc-handler.d.ts +17 -0
  25. package/dist/adapters/fetch/rpc-handler.js +16 -0
  26. package/dist/adapters/message-port/{index.d.mts → handler.d.ts} +17 -30
  27. package/dist/adapters/message-port/handler.js +86 -0
  28. package/dist/adapters/message-port/index.d.ts +2 -77
  29. package/dist/adapters/message-port/index.js +2 -0
  30. package/dist/adapters/message-port/rpc-handler.d.ts +16 -0
  31. package/dist/adapters/message-port/rpc-handler.js +15 -0
  32. package/dist/adapters/node/handler.d.ts +21 -0
  33. package/dist/adapters/node/handler.js +20 -0
  34. package/dist/adapters/node/index.d.ts +5 -42
  35. package/dist/adapters/node/index.js +7 -0
  36. package/dist/adapters/node/rpc-handler.d.ts +16 -0
  37. package/dist/adapters/node/rpc-handler.js +15 -0
  38. package/dist/adapters/standard/codec.d.ts +16 -0
  39. package/dist/adapters/standard/codec.js +1 -0
  40. package/dist/adapters/standard/handler.d.ts +68 -0
  41. package/dist/adapters/standard/handler.js +205 -0
  42. package/dist/adapters/standard/index.d.ts +6 -95
  43. package/dist/adapters/standard/index.js +5 -0
  44. package/dist/adapters/standard/plugin.d.ts +32 -0
  45. package/dist/adapters/standard/plugin.js +16 -0
  46. package/dist/adapters/standard/rpc-handler-codec.d.ts +46 -0
  47. package/dist/adapters/standard/rpc-handler-codec.js +51 -0
  48. package/dist/adapters/standard/rpc-matcher.d.ts +53 -0
  49. package/dist/adapters/standard/rpc-matcher.js +152 -0
  50. package/dist/adapters/standard/utils.d.ts +10 -0
  51. package/dist/adapters/standard/utils.js +6 -0
  52. package/dist/adapters/standard-peer/index.d.ts +1 -11
  53. package/dist/adapters/standard-peer/index.js +1 -0
  54. package/dist/adapters/standard-peer/utils.d.ts +4 -0
  55. package/dist/adapters/standard-peer/utils.js +7 -0
  56. package/dist/adapters/websocket/{index.d.mts → handler.d.ts} +11 -29
  57. package/dist/adapters/websocket/handler.js +85 -0
  58. package/dist/adapters/websocket/index.d.ts +2 -77
  59. package/dist/adapters/websocket/index.js +2 -0
  60. package/dist/adapters/websocket/rpc-handler.d.ts +16 -0
  61. package/dist/adapters/websocket/rpc-handler.js +15 -0
  62. package/dist/builder-variants.d.ts +226 -0
  63. package/dist/builder-variants.js +1 -0
  64. package/dist/builder.d.ts +127 -0
  65. package/dist/builder.js +226 -0
  66. package/dist/constants.d.ts +2 -0
  67. package/dist/constants.js +2 -0
  68. package/dist/context.d.ts +6 -0
  69. package/dist/context.js +1 -0
  70. package/dist/extensions/callable.d.ts +6 -5
  71. package/dist/extensions/callable.js +7 -0
  72. package/dist/helpers/base64url.d.ts +31 -0
  73. package/dist/helpers/base64url.js +53 -0
  74. package/dist/helpers/cookie.d.ts +51 -0
  75. package/dist/helpers/cookie.js +69 -0
  76. package/dist/helpers/encryption.d.ts +28 -0
  77. package/dist/helpers/encryption.js +80 -0
  78. package/dist/helpers/index.d.ts +4 -167
  79. package/dist/helpers/index.js +4 -0
  80. package/dist/helpers/signing.d.ts +50 -0
  81. package/dist/helpers/signing.js +88 -0
  82. package/dist/implementer-procedure.d.ts +16 -0
  83. package/dist/implementer-procedure.js +44 -0
  84. package/dist/implementer-router.d.ts +40 -0
  85. package/dist/implementer-router.js +117 -0
  86. package/dist/implementer.d.ts +16 -0
  87. package/dist/implementer.js +37 -0
  88. package/dist/index.d.ts +45 -460
  89. package/dist/index.js +48 -0
  90. package/dist/lazy.d.ts +20 -0
  91. package/dist/lazy.js +31 -0
  92. package/dist/middleware-decorated.d.ts +10 -0
  93. package/dist/middleware-decorated.js +71 -0
  94. package/dist/middleware.d.ts +54 -0
  95. package/dist/middleware.js +1 -0
  96. package/dist/plugins/batch.d.ts +102 -0
  97. package/dist/plugins/batch.js +405 -0
  98. package/dist/plugins/cors.d.ts +73 -0
  99. package/dist/plugins/cors.js +112 -0
  100. package/dist/plugins/get-method-csrf-protection.d.ts +23 -0
  101. package/dist/plugins/get-method-csrf-protection.js +64 -0
  102. package/dist/plugins/head-method.d.ts +23 -0
  103. package/dist/plugins/head-method.js +104 -0
  104. package/dist/plugins/index.d.ts +29 -422
  105. package/dist/plugins/index.js +29 -0
  106. package/dist/plugins/method-override.d.ts +38 -0
  107. package/dist/plugins/method-override.js +50 -0
  108. package/dist/plugins/request-compression.d.ts +16 -0
  109. package/dist/plugins/request-compression.js +82 -0
  110. package/dist/plugins/request-headers.d.ts +22 -0
  111. package/dist/plugins/request-headers.js +30 -0
  112. package/dist/{shared/server.CgBF3Vj1.d.ts → plugins/request-limit.d.ts} +4 -8
  113. package/dist/plugins/request-limit.js +68 -0
  114. package/dist/plugins/response-compression.d.ts +59 -0
  115. package/dist/plugins/response-compression.js +209 -0
  116. package/dist/plugins/response-headers.d.ts +30 -0
  117. package/dist/plugins/response-headers.js +47 -0
  118. package/dist/plugins/rethrow.d.ts +33 -0
  119. package/dist/plugins/rethrow.js +59 -0
  120. package/dist/plugins/signal-sync.d.ts +13 -0
  121. package/dist/plugins/signal-sync.js +91 -0
  122. package/dist/plugins/timeout.d.ts +37 -0
  123. package/dist/plugins/timeout.js +59 -0
  124. package/dist/procedure-client.d.ts +19 -0
  125. package/dist/procedure-client.js +175 -0
  126. package/dist/procedure-decorated.d.ts +10 -0
  127. package/dist/procedure-decorated.js +44 -0
  128. package/dist/procedure-utils.d.ts +41 -0
  129. package/dist/procedure-utils.js +49 -0
  130. package/dist/procedure.d.ts +72 -0
  131. package/dist/procedure.js +24 -0
  132. package/dist/router-client.d.ts +23 -0
  133. package/dist/router-client.js +43 -0
  134. package/dist/router-hidden.d.ts +5 -0
  135. package/dist/router-hidden.js +14 -0
  136. package/dist/router-utils.d.ts +48 -0
  137. package/dist/router-utils.js +202 -0
  138. package/dist/{shared/server.Dz7j9BEh.d.ts → router.d.ts} +14 -15
  139. package/dist/router.js +1 -0
  140. package/package.json +84 -86
  141. package/dist/adapters/aws-lambda/index.d.mts +0 -51
  142. package/dist/adapters/aws-lambda/index.mjs +0 -39
  143. package/dist/adapters/crossws/index.d.mts +0 -63
  144. package/dist/adapters/crossws/index.mjs +0 -68
  145. package/dist/adapters/fastify/index.d.mts +0 -42
  146. package/dist/adapters/fastify/index.mjs +0 -39
  147. package/dist/adapters/fetch/index.d.mts +0 -47
  148. package/dist/adapters/fetch/index.mjs +0 -42
  149. package/dist/adapters/message-port/index.mjs +0 -87
  150. package/dist/adapters/node/index.d.mts +0 -44
  151. package/dist/adapters/node/index.mjs +0 -41
  152. package/dist/adapters/standard/index.d.mts +0 -95
  153. package/dist/adapters/standard/index.mjs +0 -8
  154. package/dist/adapters/standard-peer/index.d.mts +0 -11
  155. package/dist/adapters/standard-peer/index.mjs +0 -10
  156. package/dist/adapters/websocket/index.mjs +0 -87
  157. package/dist/extensions/callable.d.mts +0 -10
  158. package/dist/extensions/callable.mjs +0 -11
  159. package/dist/helpers/index.d.mts +0 -167
  160. package/dist/helpers/index.mjs +0 -200
  161. package/dist/index.d.mts +0 -476
  162. package/dist/index.mjs +0 -463
  163. package/dist/plugins/index.d.mts +0 -432
  164. package/dist/plugins/index.mjs +0 -965
  165. package/dist/shared/server.1ExWFMze.mjs +0 -69
  166. package/dist/shared/server.9B1jEm5a.d.mts +0 -105
  167. package/dist/shared/server.BB464y-6.mjs +0 -207
  168. package/dist/shared/server.BC5BIu02.d.mts +0 -73
  169. package/dist/shared/server.BSYGskId.d.ts +0 -14
  170. package/dist/shared/server.BvG3boBj.d.mts +0 -14
  171. package/dist/shared/server.CTV_mC2P.d.mts +0 -34
  172. package/dist/shared/server.CYbIpHbH.mjs +0 -239
  173. package/dist/shared/server.Chq5FpXf.mjs +0 -353
  174. package/dist/shared/server.DFPxP2v3.d.mts +0 -166
  175. package/dist/shared/server.DFPxP2v3.d.ts +0 -166
  176. package/dist/shared/server.DOg7ke6y.d.ts +0 -105
  177. package/dist/shared/server.W91HSRkE.mjs +0 -9
  178. package/dist/shared/server.sBQSgqK3.mjs +0 -41
@@ -1,432 +0,0 @@
1
- import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
- import { StandardLazyRequest, StandardResponse, StandardHeaders, StandardMethod } from '@standard-server/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.CTV_mC2P.mjs';
6
- export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from '@orpc/client/plugins';
7
- import '@orpc/client';
8
- import '@orpc/contract';
9
-
10
- /**
11
- * Content type for batch responses that use the length-prefixed binary framing,
12
- * which they do when any sub-response contains binary or is a stream.
13
- *
14
- * Decoding is driven by the `standard-server` body hint, not this header,
15
- * so it only serves to describe the payload to logs, proxies, and dev tools.
16
- */
17
- declare const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
18
- interface BatchHandlerPluginOptions<T extends Context> {
19
- /**
20
- * The max size of the batch allowed. Larger batches are rejected with a `413`,
21
- * so keep the client Batch Link Plugin's `maxSize` at or below it.
22
- *
23
- * @default DEFAULT_BATCH_MAX_SIZE (10)
24
- * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
25
- */
26
- maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
27
- /**
28
- * Map each subrequest in the batch before it is processed.
29
- *
30
- * @default merges the batch request headers into the subrequest, giving them priority over
31
- * the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
32
- */
33
- mapSubrequest?: ((subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest) | undefined;
34
- /**
35
- * Map each sub-response in the batch before it is sent.
36
- *
37
- * @default removes the headers the batch response already has with the same value, which the client
38
- * merges back, and `set-cookie`, which the browser ignores there and JavaScript could read
39
- */
40
- mapSubresponse?: ((subresponse: StandardResponse, partialBatchResponse: Pick<StandardResponse, 'status' | 'headers'>, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardResponse) | undefined;
41
- /**
42
- * Success batch response status code.
43
- *
44
- * @default 207
45
- */
46
- successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
47
- /**
48
- * Success batch response headers.
49
- *
50
- * The batch response also gets the cookies its sub-responses set, and the headers they all share.
51
- * Headers set here win, and setting one to `undefined` keeps it off, except `set-cookie` and `vary`, which merge.
52
- *
53
- * @default {}
54
- */
55
- headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
56
- /**
57
- * Keep-alive settings for batch responses that stream.
58
- *
59
- * When enabled, a zero-length length-prefixed frame is sent periodically while the
60
- * stream is idle (no message sent for `interval` ms). Clients ignore these frames.
61
- *
62
- * @default { enabled: true, interval: 15000 }
63
- */
64
- keepAlive?: {
65
- /**
66
- * If true, a keep-alive frame is sent periodically while the stream is idle.
67
- *
68
- * @default true
69
- */
70
- enabled: boolean;
71
- /**
72
- * Interval (in milliseconds) between keep-alive frames after the last message.
73
- *
74
- * @default 15000
75
- */
76
- interval?: number | undefined;
77
- } | undefined;
78
- }
79
- /**
80
- * Handles batch requests sent by the client Batch Link Plugin, splitting each
81
- * batch into sub-requests and sending their responses back together.
82
- *
83
- * @remarks
84
- * The batch starts the response once every sub-response is ready, so it carries the cookies sub-requests
85
- * set and the headers every sub-response shares. It streams when a sub-response is a stream.
86
- *
87
- * **Note**: HTTP/2 and later already multiplex requests over a single connection, which often makes this plugin unnecessary.
88
- *
89
- * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
90
- */
91
- declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
92
- name: string;
93
- /**
94
- * Run batch interceptors inside the tracing interceptors
95
- * so each subrequest gets its own span instead of sharing one batch-level span.
96
- */
97
- after: string[];
98
- private readonly maxSize;
99
- private readonly mapSubrequest;
100
- private readonly mapSubresponse;
101
- private readonly successStatus;
102
- private readonly headers;
103
- private readonly keepAliveEnabled;
104
- private readonly keepAliveInterval;
105
- constructor(options?: BatchHandlerPluginOptions<T>);
106
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
107
- }
108
-
109
- interface CORSHandlerPluginOptions<T extends Context> {
110
- /**
111
- * Configures the `Access-Control-Allow-Origin` header.
112
- * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
113
- *
114
- * A function must only return origins it has validated: returning the incoming origin
115
- * unchecked allows every origin.
116
- *
117
- * @default '*'
118
- */
119
- origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
120
- /**
121
- * Configures the `Timing-Allow-Origin` header.
122
- * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
123
- */
124
- timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
125
- /**
126
- * Configures the `Access-Control-Allow-Methods` header for preflight requests.
127
- *
128
- * @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']
129
- */
130
- allowMethods?: readonly string[] | undefined;
131
- /**
132
- * Configures the `Access-Control-Allow-Headers` header for preflight requests.
133
- * Falls back to the request's `Access-Control-Request-Headers` if not set.
134
- * When set, it replaces that fallback, so include every non-safelisted header
135
- * clients send, such as `Content-Type`.
136
- */
137
- allowHeaders?: readonly string[] | undefined;
138
- /**
139
- * Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
140
- */
141
- maxAge?: number | undefined;
142
- /**
143
- * Configures the `Access-Control-Allow-Credentials` header.
144
- *
145
- * When enabled, `origin` must allow trusted origins only: every allowed origin can send
146
- * authenticated requests as your users and read the responses.
147
- */
148
- credentials?: boolean | undefined;
149
- /**
150
- * Configures the `Access-Control-Expose-Headers` header.
151
- */
152
- exposeHeaders?: readonly string[] | undefined;
153
- }
154
- /**
155
- * Configures the [CORS Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
156
- * for your API, including preflight requests.
157
- *
158
- * @see {@link https://orpc.dev/docs/plugins/cors | CORS Handler Plugin}
159
- */
160
- declare class CORSHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
161
- private readonly options;
162
- name: string;
163
- /**
164
- * - Do not create spans for CORS preflight requests.
165
- * - Run CORS interceptors before batch interceptors so headers are applied to
166
- * the actual response rather than sub-responses.
167
- */
168
- after: string[];
169
- constructor(options?: CORSHandlerPluginOptions<T>);
170
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
171
- private resolveOrigin;
172
- }
173
-
174
- /**
175
- * Adds Cross-Site Request Forgery (CSRF) protection that makes the safe `GET` method as
176
- * secure as unsafe ones such as `POST`. It rejects `GET` requests arriving as top-level
177
- * navigations initiated cross-site or from outside the browser, the only context where
178
- * another site can make a browser attach `SameSite=Lax` cookies to a safe-method request.
179
- * Requests matching no procedure stay unmatched, so they can fall through to whatever
180
- * serves the rest of the site.
181
- *
182
- * @remarks
183
- * **Note**: Requests browsers send without `SameSite=Lax` cookies, such as cross-site `fetch`
184
- * and `<img>`, pass through, so procedures stay reachable from other sites. This safeguard
185
- * requires authentication cookies explicitly marked `SameSite=Lax` or `SameSite=Strict`,
186
- * since browsers may attach other cookies to the requests that pass.
187
- *
188
- * @see {@link https://orpc.dev/docs/plugins/get-method-csrf-protection | GET Method CSRF Protection Plugin}
189
- */
190
- declare class GetMethodCsrfProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
191
- name: string;
192
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
193
- private isAllowed;
194
- }
195
-
196
- interface MethodOverrideHandlerPluginOptions {
197
- /**
198
- * The query parameter carrying the override method.
199
- *
200
- * @default 'method'
201
- */
202
- param?: string | undefined;
203
- /**
204
- * The methods a POST request may be overridden to.
205
- *
206
- * GET and HEAD are excluded by default because they switch input decoding
207
- * from the request body to the query string and widen the CSRF surface.
208
- *
209
- * @default ['PUT', 'PATCH', 'DELETE']
210
- */
211
- methods?: readonly StandardMethod[] | undefined;
212
- }
213
- /**
214
- * Overrides the HTTP method of a POST request based on a query parameter,
215
- * so HTML forms (which only support GET and POST) can invoke procedures
216
- * routed as PUT, PATCH, or DELETE.
217
- *
218
- * @see {@link https://orpc.dev/docs/plugins/method-override | Method Override Plugin}
219
- */
220
- declare class MethodOverrideHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
221
- name: string;
222
- /**
223
- * Should override batch sub-request methods, not the original batch request.
224
- */
225
- before: string[];
226
- private readonly param;
227
- private readonly methods;
228
- constructor(options?: MethodOverrideHandlerPluginOptions);
229
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
230
- }
231
-
232
- /**
233
- * Decompresses incoming request bodies based on the Content-Encoding header,
234
- * supporting gzip, deflate, and deflate-raw.
235
- *
236
- * @see {@link https://orpc.dev/docs/plugins/request-compression | Request Compression Plugin}
237
- */
238
- declare class RequestCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
239
- name: string;
240
- /**
241
- * Should decompress the original batch request body instead of sub-requests.
242
- */
243
- after: string[];
244
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
245
- }
246
-
247
- /**
248
- * The context shape into which the Request Headers Plugin injects `reqHeaders`.
249
- *
250
- * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
251
- */
252
- interface RequestHeadersHandlerPluginContext {
253
- /**
254
- * Request headers as a Headers instance. This is injected by the Request Headers Plugin.
255
- */
256
- reqHeaders?: Headers | undefined;
257
- }
258
- /**
259
- * The Request Headers Plugin injects a `reqHeaders` instance into the context,
260
- * allowing access to request headers in oRPC.
261
- *
262
- * @see {@link https://orpc.dev/docs/plugins/request-headers | Request Headers Plugin}
263
- */
264
- declare class RequestHeadersHandlerPlugin<T extends RequestHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
265
- name: string;
266
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
267
- }
268
-
269
- interface ResponseCompressionHandlerPluginOptions<T extends Context> {
270
- /**
271
- * The compression schemes to use for response compression.
272
- * Schemes are prioritized by their order in this array and
273
- * only applied if the client supports them (via Accept-Encoding).
274
- *
275
- * @default ['gzip', 'deflate']
276
- */
277
- encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[] | undefined;
278
- /**
279
- * The minimum response size in bytes required to trigger compression.
280
- * Responses smaller than this threshold will not be compressed to avoid overhead.
281
- * If the response size cannot be determined, compression will still be applied.
282
- *
283
- * @default 1024 (1KB)
284
- */
285
- threshold?: number | undefined;
286
- /**
287
- * Determines whether a response with the given Content-Type should be compressed.
288
- * Only consulted for binary transfers (streams, files, and file form-data parts).
289
- * Also receives the routing interceptor options for per-request decisions.
290
- *
291
- * @default isCompressibleContentType (covers common text-based formats)
292
- */
293
- isCompressibleContentType?: ((contentType: string | null | undefined, options: StandardHandlerRoutingInterceptorOptions<T>) => boolean) | undefined;
294
- }
295
- /**
296
- * Compresses response bodies based on the client's Accept-Encoding header.
297
- * Works at the standard handler level, so it supports all adapters.
298
- *
299
- * @see {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
300
- */
301
- declare class ResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
302
- name: string;
303
- /**
304
- * Compression should be done after batching, to compress the final response.
305
- * Compression should also be done after response headers are set, to access final headers like Content-Type and Cache-Control.
306
- */
307
- after: string[];
308
- private readonly encodings;
309
- private readonly threshold;
310
- private readonly isCompressibleContentType;
311
- constructor(options?: ResponseCompressionHandlerPluginOptions<T>);
312
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
313
- }
314
- /**
315
- * Picks the first of `encodings` the client accepts, or `undefined` when the response
316
- * must be sent as is because it is already encoded, partial, or forbids transforms.
317
- * Shared by the response compression plugins so they agree on when to compress.
318
- */
319
- declare function negotiateResponseCompressionEncoding<TEncoding extends string>(response: StandardResponse, requestHeaders: StandardHeaders, encodings: readonly TEncoding[]): TEncoding | undefined;
320
- /**
321
- * The headers of a response whose body is compressed with `encoding`.
322
- * Shared by the response compression plugins so compressed responses carry the same headers.
323
- */
324
- declare function toCompressedHeaders(headers: StandardHeaders, encoding: string): StandardHeaders;
325
-
326
- /**
327
- * The context shape into which the Response Headers Plugin injects `resHeaders`.
328
- *
329
- * @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
330
- */
331
- interface ResponseHeadersHandlerPluginContext {
332
- /**
333
- * Response headers as a Headers instance. This is injected by the Response Headers Plugin.
334
- * When set before the response is sent, these headers will be included in the response. If not set, no additional headers will be added.
335
- */
336
- resHeaders?: Headers | undefined;
337
- }
338
- /**
339
- * The Response Headers Plugin allows you to set response headers in oRPC.
340
- * It injects a resHeaders instance into the context, enabling you to modify response headers easily.
341
- *
342
- * @see {@link https://orpc.dev/docs/plugins/response-headers | Response Headers Plugin}
343
- */
344
- declare class ResponseHeadersHandlerPlugin<T extends ResponseHeadersHandlerPluginContext> implements StandardHandlerPlugin<T> {
345
- name: string;
346
- /**
347
- * Interceptors should run after batch interceptors so headers are applied to each sub-response.
348
- */
349
- before: string[];
350
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
351
- }
352
-
353
- interface RethrowHandlerPluginOptions<T extends Context> {
354
- /**
355
- * Decide which errors should be rethrown.
356
- *
357
- * @example
358
- * ```ts
359
- * const rethrowPlugin = new RethrowHandlerPlugin({
360
- * filter: (error) => {
361
- * // Rethrow all non-ORPCError errors
362
- * return !(error instanceof ORPCError)
363
- * }
364
- * })
365
- * ```
366
- */
367
- filter: (error: ThrowableError, options: StandardHandlerInterceptorOptions<T>) => boolean;
368
- }
369
- /**
370
- * The plugin can bypass oRPC's built-in error handling
371
- * and rethrow matching errors directly to your framework's error handling mechanism
372
- * (e.g., NestJS exception filters, Express error middleware).
373
- *
374
- * @see {@link https://orpc.dev/docs/plugins/rethrow | Rethrow Handler Plugin}
375
- */
376
- declare class RethrowHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
377
- name: string;
378
- private readonly filter;
379
- private readonly CONTEXT_SYMBOL;
380
- constructor(options: RethrowHandlerPluginOptions<T>);
381
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
382
- }
383
-
384
- /**
385
- * Keeps the request signal and a streaming output (async iterator object or readable stream) in sync:
386
- * cancelling the output aborts the signal with an `AbortError`,
387
- * and aborting the signal ends the output with the abort reason and cancels it.
388
- *
389
- * @see {@link https://orpc.dev/docs/plugins/signal-sync | Signal Sync Plugin}
390
- */
391
- declare class SignalSyncHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
392
- name: string;
393
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
394
- }
395
-
396
- interface TimeoutHandlerPluginOptions<T extends Context> {
397
- /**
398
- * Timeout in milliseconds before the request signal is aborted.
399
- * This only covers producing the response, use `streamingTimeout`
400
- * to limit streaming response bodies.
401
- * Use `null` or `undefined` to disable the timeout.
402
- */
403
- timeout: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]>;
404
- /**
405
- * Timeout in milliseconds for the full duration of a streaming response body
406
- * (async iterator object or readable stream), measured from when the response is produced.
407
- * When exceeded, the request signal is aborted and the body ends
408
- * once its producer honors the signal.
409
- * Usually higher than `timeout`.
410
- * Use `null` or `undefined` to disable the timeout.
411
- *
412
- * @default undefined (streaming responses run without limit)
413
- */
414
- streamingTimeout?: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]> | undefined;
415
- }
416
- /**
417
- * The Timeout Handler Plugin aborts the request signal with an `AbortError`
418
- * when handling exceeds a configured timeout. It only aborts the signal,
419
- * the procedure must honor it to stop early and produce the response.
420
- *
421
- * @see {@link https://orpc.dev/docs/plugins/timeout | Timeout Plugin}
422
- */
423
- declare class TimeoutHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
424
- private readonly timeout;
425
- private readonly streamingTimeout;
426
- name: string;
427
- constructor(options: NoInfer<TimeoutHandlerPluginOptions<T>>);
428
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
429
- }
430
-
431
- export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, GetMethodCsrfProtectionHandlerPlugin, MethodOverrideHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, SignalSyncHandlerPlugin, TimeoutHandlerPlugin, negotiateResponseCompressionEncoding, toCompressedHeaders };
432
- export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, MethodOverrideHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions, TimeoutHandlerPluginOptions };