@orpc/server 2.0.0-beta.43 → 2.0.0-beta.45

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 (39) hide show
  1. package/README.md +56 -57
  2. package/dist/adapters/aws-lambda/index.mjs +2 -2
  3. package/dist/adapters/crossws/index.mjs +2 -2
  4. package/dist/adapters/fastify/index.mjs +2 -2
  5. package/dist/adapters/fetch/index.d.mts +2 -2
  6. package/dist/adapters/fetch/index.d.ts +2 -2
  7. package/dist/adapters/fetch/index.mjs +2 -2
  8. package/dist/adapters/message-port/index.d.mts +1 -1
  9. package/dist/adapters/message-port/index.d.ts +1 -1
  10. package/dist/adapters/message-port/index.mjs +2 -2
  11. package/dist/adapters/node/index.d.mts +1 -1
  12. package/dist/adapters/node/index.d.ts +1 -1
  13. package/dist/adapters/node/index.mjs +2 -2
  14. package/dist/adapters/standard/index.d.mts +10 -8
  15. package/dist/adapters/standard/index.d.ts +10 -8
  16. package/dist/adapters/standard/index.mjs +2 -2
  17. package/dist/adapters/websocket/index.mjs +2 -2
  18. package/dist/helpers/index.d.mts +2 -1
  19. package/dist/helpers/index.d.ts +2 -1
  20. package/dist/helpers/index.mjs +3 -9
  21. package/dist/index.d.mts +14 -7
  22. package/dist/index.d.ts +14 -7
  23. package/dist/index.mjs +2 -2
  24. package/dist/plugins/index.d.mts +64 -55
  25. package/dist/plugins/index.d.ts +64 -55
  26. package/dist/plugins/index.mjs +232 -146
  27. package/dist/shared/{server.BllfVJLm.d.mts → server.B4hFgqPr.d.mts} +2 -2
  28. package/dist/shared/{server.BEdOJs6S.d.mts → server.BWhT-63L.d.mts} +5 -5
  29. package/dist/shared/{server.BEdOJs6S.d.ts → server.BWhT-63L.d.ts} +5 -5
  30. package/dist/shared/{server.CVO0hWyj.d.mts → server.BYNQ06wN.d.ts} +5 -5
  31. package/dist/shared/{server.BgvqVW_v.mjs → server.BcxD3fmU.mjs} +15 -3
  32. package/dist/shared/{server.COfbQ0D8.d.ts → server.CI0qiBzm.d.ts} +2 -2
  33. package/dist/shared/{server.DFEuNUt4.d.ts → server.CO_upro1.d.ts} +3 -3
  34. package/dist/shared/{server.DZeVx8K9.d.ts → server.DcDZdSrg.d.ts} +1 -1
  35. package/dist/shared/{server.UG_xdTub.d.mts → server.DgcwQ-Wr.d.mts} +3 -3
  36. package/dist/shared/{server.B1ecixZJ.mjs → server.Kbq-C85k.mjs} +7 -20
  37. package/dist/shared/{server.DJNkZPfD.d.ts → server.TVSii8T9.d.mts} +5 -5
  38. package/dist/shared/{server.DD1roZl9.d.mts → server.TjEHK8V3.d.mts} +1 -1
  39. package/package.json +15 -15
@@ -1,14 +1,15 @@
1
1
  import { Value, Promisable, ThrowableError } from '@orpc/shared';
2
- import { StandardLazyRequest, StandardHeaders, StandardMethod, StandardResponse } from '@standard-server/core';
2
+ import { StandardLazyRequest, StandardResponse, StandardHeaders, StandardMethod } from '@standard-server/core';
3
3
  import { Context } from '../index.js';
4
4
  import { StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions, StandardHandlerOptions, StandardHandlerInterceptorOptions } from '../adapters/standard/index.js';
5
- export { R as RequestLimitHandlerPlugin, a as RequestLimitHandlerPluginOptions } from '../shared/server.COfbQ0D8.js';
5
+ export { R as RequestLimitHandlerPlugin, a as RequestLimitHandlerPluginOptions } from '../shared/server.CI0qiBzm.js';
6
+ export { BATCH_HEADER, DEFAULT_BATCH_MAX_SIZE } from '@orpc/client/plugins';
6
7
  import '@orpc/client';
7
8
  import '@orpc/contract';
8
9
 
9
10
  /**
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).
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.
12
13
  *
13
14
  * Decoding is driven by the `standard-server` body hint, not this header,
14
15
  * so it only serves to describe the payload to logs, proxies, and dev tools.
@@ -16,40 +17,51 @@ import '@orpc/contract';
16
17
  declare const BATCH_CONTENT_TYPE = "application/vnd.orpc.batch";
17
18
  interface BatchHandlerPluginOptions<T extends Context> {
18
19
  /**
19
- * The max size of the batch allowed.
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.
20
22
  *
21
- * @default 10
23
+ * @default DEFAULT_BATCH_MAX_SIZE (10)
24
+ * @see {@link https://orpc.dev/docs/plugins/batch#max-size | Batch Plugin - Max Size}
22
25
  */
23
- maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]>;
26
+ maxSize?: Value<Promisable<number>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
24
27
  /**
25
28
  * Map each subrequest in the batch before it is processed.
26
29
  *
27
30
  * @default merges the batch request headers into the subrequest, giving them priority over
28
31
  * the subrequest headers, and removes the `orpc-batch` header to prevent nested batching
29
32
  */
30
- mapSubrequest?: (subrequest: StandardLazyRequest, batchOptions: StandardHandlerRoutingInterceptorOptions<T>) => StandardLazyRequest;
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;
31
41
  /**
32
42
  * Success batch response status code.
33
43
  *
34
44
  * @default 207
35
45
  */
36
- successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
46
+ successStatus?: Value<Promisable<number>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
37
47
  /**
38
48
  * Success batch response headers.
39
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
+ *
40
53
  * @default {}
41
54
  */
42
- headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]>;
55
+ headers?: Value<Promisable<StandardHeaders>, [batchOptions: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
43
56
  /**
44
- * Keep-alive settings for streaming batch responses.
57
+ * Keep-alive settings for batch responses that stream.
45
58
  *
46
59
  * When enabled, a zero-length length-prefixed frame is sent periodically while the
47
60
  * stream is idle (no message sent for `interval` ms). Clients ignore these frames.
48
- * Only applies to streaming mode.
49
61
  *
50
62
  * @default { enabled: true, interval: 15000 }
51
63
  */
52
- keepAlive?: undefined | {
64
+ keepAlive?: {
53
65
  /**
54
66
  * If true, a keep-alive frame is sent periodically while the stream is idle.
55
67
  *
@@ -61,14 +73,17 @@ interface BatchHandlerPluginOptions<T extends Context> {
61
73
  *
62
74
  * @default 15000
63
75
  */
64
- interval?: number;
65
- };
76
+ interval?: number | undefined;
77
+ } | undefined;
66
78
  }
67
79
  /**
68
80
  * Handles batch requests sent by the client Batch Link Plugin, splitting each
69
- * batch into sub-requests and streaming their responses back together.
81
+ * batch into sub-requests and sending their responses back together.
70
82
  *
71
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
+ *
72
87
  * **Note**: HTTP/2 and later already multiplex requests over a single connection, which often makes this plugin unnecessary.
73
88
  *
74
89
  * @see {@link https://orpc.dev/docs/plugins/batch | Batch Plugin}
@@ -82,6 +97,7 @@ declare class BatchHandlerPlugin<T extends Context> implements StandardHandlerPl
82
97
  after: string[];
83
98
  private readonly maxSize;
84
99
  private readonly mapSubrequest;
100
+ private readonly mapSubresponse;
85
101
  private readonly successStatus;
86
102
  private readonly headers;
87
103
  private readonly keepAliveEnabled;
@@ -95,39 +111,45 @@ interface CORSHandlerPluginOptions<T extends Context> {
95
111
  * Configures the `Access-Control-Allow-Origin` header.
96
112
  * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
97
113
  *
114
+ * A function must only return origins it has validated: returning the incoming origin
115
+ * unchecked allows every origin.
116
+ *
98
117
  * @default '*'
99
118
  */
100
- origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
119
+ origin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
101
120
  /**
102
121
  * Configures the `Timing-Allow-Origin` header.
103
122
  * Can be a string, an array of allowed origins, or a function (optionally async) that returns the allowed origin(s).
104
123
  */
105
- timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]>;
124
+ timingOrigin?: Value<Promisable<string | readonly string[] | null | undefined>, [origin: string, options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
106
125
  /**
107
126
  * Configures the `Access-Control-Allow-Methods` header for preflight requests.
108
127
  *
109
128
  * @default ['GET', 'HEAD', 'PUT', 'POST', 'DELETE', 'PATCH', 'QUERY']
110
129
  */
111
- allowMethods?: readonly string[];
130
+ allowMethods?: readonly string[] | undefined;
112
131
  /**
113
132
  * Configures the `Access-Control-Allow-Headers` header for preflight requests.
114
133
  * Falls back to the request's `Access-Control-Request-Headers` if not set.
115
134
  * When set, it replaces that fallback, so include every non-safelisted header
116
135
  * clients send, such as `Content-Type`.
117
136
  */
118
- allowHeaders?: readonly string[];
137
+ allowHeaders?: readonly string[] | undefined;
119
138
  /**
120
139
  * Configures the `Access-Control-Max-Age` header (in seconds) for preflight requests.
121
140
  */
122
- maxAge?: number;
141
+ maxAge?: number | undefined;
123
142
  /**
124
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.
125
147
  */
126
- credentials?: boolean;
148
+ credentials?: boolean | undefined;
127
149
  /**
128
150
  * Configures the `Access-Control-Expose-Headers` header.
129
151
  */
130
- exposeHeaders?: readonly string[];
152
+ exposeHeaders?: readonly string[] | undefined;
131
153
  }
132
154
  /**
133
155
  * Configures the [CORS Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
@@ -177,7 +199,7 @@ interface MethodOverrideHandlerPluginOptions {
177
199
  *
178
200
  * @default 'method'
179
201
  */
180
- param?: string;
202
+ param?: string | undefined;
181
203
  /**
182
204
  * The methods a POST request may be overridden to.
183
205
  *
@@ -186,7 +208,7 @@ interface MethodOverrideHandlerPluginOptions {
186
208
  *
187
209
  * @default ['PUT', 'PATCH', 'DELETE']
188
210
  */
189
- methods?: readonly StandardMethod[];
211
+ methods?: readonly StandardMethod[] | undefined;
190
212
  }
191
213
  /**
192
214
  * Overrides the HTTP method of a POST request based on a query parameter,
@@ -207,31 +229,6 @@ declare class MethodOverrideHandlerPlugin<T extends Context> implements Standard
207
229
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
208
230
  }
209
231
 
210
- /**
211
- * Rejects requests whose decoded input contains prototype-polluting keys: an own
212
- * `__proto__` key, or an own `constructor` key holding a `prototype` key. oRPC's own
213
- * decoding never assigns through the prototype chain, so this plugin exists to stop such
214
- * keys from reaching application code that merges, clones, or path-sets input with a
215
- * library vulnerable to prototype pollution. An `AsyncIteratorObject` input is checked
216
- * value by value as it arrives, and a polluting value fails that iteration instead.
217
- *
218
- * @see {@link https://orpc.dev/docs/plugins/prototype-pollution-protection | Prototype Pollution Protection Plugin}
219
- */
220
- declare class PrototypePollutionProtectionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
221
- name: string;
222
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
223
- private rejectPollutingInput;
224
- /**
225
- * Walks the containers the built-in codecs can produce: arrays, maps, sets, and plain
226
- * objects, including null-prototype ones. Arrays get the same key checks as plain objects,
227
- * since structured clone, as used over MessagePort, keeps named keys like `__proto__` on
228
- * them. Other objects, such as files and dates, carry no attacker-authored keys and are
229
- * left alone. The walk is iterative, so input nested deeper than the call stack allows
230
- * still gets the intended verdict instead of a `RangeError`.
231
- */
232
- private containsPollutingKey;
233
- }
234
-
235
232
  /**
236
233
  * Decompresses incoming request bodies based on the Content-Encoding header,
237
234
  * supporting gzip, deflate, and deflate-raw.
@@ -277,7 +274,7 @@ interface ResponseCompressionHandlerPluginOptions<T extends Context> {
277
274
  *
278
275
  * @default ['gzip', 'deflate']
279
276
  */
280
- encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[];
277
+ encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[] | undefined;
281
278
  /**
282
279
  * The minimum response size in bytes required to trigger compression.
283
280
  * Responses smaller than this threshold will not be compressed to avoid overhead.
@@ -285,7 +282,7 @@ interface ResponseCompressionHandlerPluginOptions<T extends Context> {
285
282
  *
286
283
  * @default 1024 (1KB)
287
284
  */
288
- threshold?: number;
285
+ threshold?: number | undefined;
289
286
  /**
290
287
  * Determines whether a response with the given Content-Type should be compressed.
291
288
  * Only consulted for binary transfers (streams, files, and file form-data parts).
@@ -293,7 +290,7 @@ interface ResponseCompressionHandlerPluginOptions<T extends Context> {
293
290
  *
294
291
  * @default isCompressibleContentType (covers common text-based formats)
295
292
  */
296
- isCompressibleContentType?: (contentType: string | null | undefined, options: StandardHandlerRoutingInterceptorOptions<T>) => boolean;
293
+ isCompressibleContentType?: ((contentType: string | null | undefined, options: StandardHandlerRoutingInterceptorOptions<T>) => boolean) | undefined;
297
294
  }
298
295
  /**
299
296
  * Compresses response bodies based on the client's Accept-Encoding header.
@@ -384,6 +381,18 @@ declare class RethrowHandlerPlugin<T extends Context> implements StandardHandler
384
381
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
385
382
  }
386
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
+
387
396
  interface TimeoutHandlerPluginOptions<T extends Context> {
388
397
  /**
389
398
  * Timeout in milliseconds before the request signal is aborted.
@@ -402,7 +411,7 @@ interface TimeoutHandlerPluginOptions<T extends Context> {
402
411
  *
403
412
  * @default undefined (streaming responses run without limit)
404
413
  */
405
- streamingTimeout?: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]>;
414
+ streamingTimeout?: Value<number | null | undefined, [options: StandardHandlerInterceptorOptions<T>]> | undefined;
406
415
  }
407
416
  /**
408
417
  * The Timeout Handler Plugin aborts the request signal with an `AbortError`
@@ -419,5 +428,5 @@ declare class TimeoutHandlerPlugin<T extends Context> implements StandardHandler
419
428
  init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
420
429
  }
421
430
 
422
- export { BATCH_CONTENT_TYPE, BatchHandlerPlugin, CORSHandlerPlugin, CORSHandlerPlugin as CORSPlugin, GetMethodCsrfProtectionHandlerPlugin, MethodOverrideHandlerPlugin, PrototypePollutionProtectionHandlerPlugin, RequestCompressionHandlerPlugin, RequestHeadersHandlerPlugin, RequestHeadersHandlerPlugin as RequestHeadersPlugin, ResponseCompressionHandlerPlugin, ResponseHeadersHandlerPlugin, ResponseHeadersHandlerPlugin as ResponseHeadersPlugin, RethrowHandlerPlugin, TimeoutHandlerPlugin, negotiateResponseCompressionEncoding, toCompressedHeaders };
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 };
423
432
  export type { BatchHandlerPluginOptions, CORSHandlerPluginOptions, MethodOverrideHandlerPluginOptions, RequestHeadersHandlerPluginContext, RequestHeadersHandlerPluginContext as RequestHeadersPluginContext, ResponseCompressionHandlerPluginOptions, ResponseHeadersHandlerPluginContext, ResponseHeadersHandlerPluginContext as ResponseHeadersPluginContext, RethrowHandlerPluginOptions, TimeoutHandlerPluginOptions };