@orpc/node 2.0.0-beta.46 → 2.0.0-beta.48

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.
package/README.md CHANGED
@@ -156,10 +156,11 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
156
156
  <td align="center"><a href="https://github.com/christ12938?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="christ12938"><img src="https://avatars.githubusercontent.com/u/25758598?v=4" width="167" alt="christ12938"/><br />christ12938</a></td>
157
157
  <td align="center"><a href="https://github.com/Ryanjso?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ryan Soderberg"><img src="https://avatars.githubusercontent.com/u/39172778?u=5ed913c31d57e7221b75784abcad48c7ebddde27&amp;v=4" width="167" alt="Ryan Soderberg"/><br />Ryan Soderberg</a></td>
158
158
  <td align="center"><a href="https://github.com/itigoore01?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="shota"><img src="https://avatars.githubusercontent.com/u/11831107?u=c976a6dc7e055eb026304c46c99100ed22b0c8e0&amp;v=4" width="167" alt="shota"/><br />shota</a></td>
159
+ <td align="center"><a href="https://github.com/Nic13Gamer?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Nicholas"><img src="https://avatars.githubusercontent.com/u/54724556?u=56a7ab430ce7a80d648ab6eba051d454a818ed0b&amp;v=4" width="167" alt="Nicholas"/><br />Nicholas</a></td>
159
160
  <td align="center"><a href="https://github.com/ellis-driscoll?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Ellis Driscoll"><img src="https://avatars.githubusercontent.com/u/70685966?u=c5f95bc33b5991d9744abe00052542e4a2ed3cb9&amp;v=4" width="167" alt="Ellis Driscoll"/><br />Ellis Driscoll</a></td>
160
- <td align="center"><a href="https://github.com/hoangbn?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&amp;v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
161
161
  </tr>
162
162
  <tr>
163
+ <td align="center"><a href="https://github.com/hoangbn?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Hoang Nguyen"><img src="https://avatars.githubusercontent.com/u/38968280?u=c90084c6de65c56facabab7ba13a72a49ddbc3e4&amp;v=4" width="167" alt="Hoang Nguyen"/><br />Hoang Nguyen</a></td>
163
164
  <td align="center"><a href="https://opencollective.com/guest-ac41de3b?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Orestis Ioannou"><img src="https://images.opencollective.com/guest-ac41de3b/avatar/460.png" width="167" alt="Orestis Ioannou"/><br />Orestis Ioannou</a></td>
164
165
  <td align="center"><a href="https://automatio.ai/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Stefan Smiljkovic"><img src="https://avatars.githubusercontent.com/u/1984909?u=b7bf5bc40ed49df3c22f69d2da7b8d78709c49ed&amp;v=4" width="167" alt="Stefan Smiljkovic"/><br />Stefan Smiljkovic</a></td>
165
166
  </tr>
@@ -190,10 +191,9 @@ Like what we build over at [middleapi](https://github.com/middleapi)? You can he
190
191
  <td align="center"><a href="https://kellychan.im/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Kelly Peilin Chan"><img src="https://avatars.githubusercontent.com/u/520852?u=6b0f7105f694e7b5cacf410a3f04c7044b469dc8&amp;v=4" width="139" alt="Kelly Peilin Chan"/><br />Kelly Peilin Chan</a></td>
191
192
  <td align="center"><a href="https://guyariely.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Guy Ariely"><img src="https://avatars.githubusercontent.com/u/42813496?u=edb6b7f563bf28e160a290832e7da57c0506f8ca&amp;v=4" width="139" alt="Guy Ariely"/><br />Guy Ariely</a></td>
192
193
  <td align="center"><a href="https://paulsenon.com/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="PaulSenon"><img src="https://avatars.githubusercontent.com/u/19531087?u=6385741eb91d200b8c513ec6045482e301767ca6&amp;v=4" width="139" alt="PaulSenon"/><br />PaulSenon</a></td>
193
- <td align="center"><a href="https://nakasyou.how/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Shotaro Nakamura"><img src="https://avatars.githubusercontent.com/u/79000684?u=f644df3f29f0e8677a90967115774564f1d9d6ab&amp;v=4" width="139" alt="Shotaro Nakamura"/><br />Shotaro Nakamura</a></td>
194
+ <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
194
195
  </tr>
195
196
  <tr>
196
- <td align="center"><a href="https://piscis.dev/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Alex"><img src="https://avatars.githubusercontent.com/u/326163?u=b245f368bd940cf51d08c0b6bf55f8257f359437&amp;v=4" width="139" alt="Alex"/><br />Alex</a></td>
197
197
  <td align="center"><a href="https://opensource.gubanov.eu/?ref=middleapi&amp;utm_source=middleapi&amp;utm_medium=sponsor" target="_blank" rel="noopener sponsored" title="Andrey Gubanov"><img src="https://avatars.githubusercontent.com/u/1082083?u=c5f2daf7ebece498e85c83367bb37b4e10e2649d&amp;v=4" width="139" alt="Andrey Gubanov"/><br />Andrey Gubanov</a></td>
198
198
  </tr>
199
199
  </table>
@@ -206,7 +206,9 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
206
206
 
207
207
  <table>
208
208
  <tr>
209
- <td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude for Open Source</a></td>
209
+ <td align="center"><a href="https://claude.com/contact-sales/claude-for-oss" target="_blank" rel="noopener" title="Claude for Open Source"><img src="https://cdn.simpleicons.org/claude" width="64" alt="Claude"/><br />Claude</a></td>
210
+ <td align="center"><a href="https://pullfrog.com/for-oss" target="_blank" rel="noopener" title="Pullfrog for OSS"><img src="https://avatars.githubusercontent.com/in/1768019?s=128&amp;v=4" width="64" alt="Pullfrog"/><br />Pullfrog</a></td>
211
+ <td align="center"><a href="https://macroscope.com/open-source" target="_blank" rel="noopener" title="Macroscope for Open Source"><img src="https://avatars.githubusercontent.com/in/900172?s=128&amp;v=4" width="64" alt="Macroscope"/><br />Macroscope</a></td>
210
212
  </tr>
211
213
  </table>
212
214
 
@@ -0,0 +1,46 @@
1
+ import type { Context } from "@orpc/server";
2
+ import type { StandardHandlerOptions, StandardHandlerPlugin } from "@orpc/server/standard";
3
+ export interface BatchResponseCompressionHandlerPluginOptions {
4
+ /**
5
+ * The compression schemes to use for batch responses.
6
+ * Schemes are prioritized by their order in this array and
7
+ * only applied if the client supports them (via Accept-Encoding).
8
+ *
9
+ * @default ['gzip', 'deflate']
10
+ */
11
+ encodings?: readonly ("gzip" | "deflate" | "deflate-raw")[] | undefined;
12
+ /**
13
+ * The minimum response size in bytes required to trigger compression.
14
+ * Responses smaller than this threshold will not be compressed to avoid overhead.
15
+ * A streaming batch response has no size until it ends, so it is always compressed.
16
+ *
17
+ * @default 1024 (1KB)
18
+ */
19
+ threshold?: number | undefined;
20
+ }
21
+ /**
22
+ * Compresses every successful [batch](https://orpc.dev/docs/plugins/batch) response, which the
23
+ * runtime-agnostic {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
24
+ * leaves untouched when framed: a batch frames subresponses of mixed content types, so its envelope
25
+ * has none of its own and nothing says whether the contents compress. Registering this plugin
26
+ * states that they do.
27
+ *
28
+ * @remarks
29
+ * Each message is flushed as soon as it is produced, so a streaming batch stays streaming.
30
+ * This is why the plugin lives in the Node.js package: `zlib` can flush mid-stream, while the
31
+ * web `CompressionStream` cannot, and would hold every early message until the batch ends.
32
+ *
33
+ * @see {@link https://orpc.dev/docs/plugins/batch-response-compression | Batch Response Compression Plugin}
34
+ */
35
+ export declare class BatchResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
36
+ name: string;
37
+ /**
38
+ * Compression should be done after batching, to compress the assembled batch response
39
+ * rather than each subresponse inside it.
40
+ */
41
+ after: string[];
42
+ private readonly encodings;
43
+ private readonly threshold;
44
+ constructor(options?: BatchResponseCompressionHandlerPluginOptions);
45
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
46
+ }
@@ -0,0 +1,88 @@
1
+ import { Duplex } from "node:stream";
2
+ import { constants, createDeflate, createDeflateRaw, createGzip } from "node:zlib";
3
+ import { BATCH_HEADER, negotiateResponseCompressionEncoding, toCompressedHeaders } from "@orpc/server/plugins";
4
+ import { toArray } from "@orpc/shared";
5
+ import { flattenStandardHeader } from "@standard-server/core";
6
+ import { toFetchBody } from "@standard-server/fetch";
7
+
8
+ export class BatchResponseCompressionHandlerPlugin {
9
+ name = "~batch-response-compression";
10
+
11
+ after = ["~batch"];
12
+ encodings;
13
+ threshold;
14
+ constructor(options = {}) {
15
+ this.encodings = options.encodings ?? ["gzip", "deflate"];
16
+ this.threshold = options.threshold ?? 1024;
17
+ }
18
+ init(options) {
19
+ const routingInterceptor = async ({ next, ...interceptorOptions }) => {
20
+ const result = await next();
21
+ if (!result.matched) {
22
+ return result;
23
+ }
24
+
25
+ if (flattenStandardHeader(interceptorOptions.request.headers[BATCH_HEADER]) === undefined) {
26
+ return result;
27
+ }
28
+ const response = result.response;
29
+ const headers = response.headers;
30
+ const body = response.body;
31
+
32
+ if (response.status >= 400) {
33
+ return result;
34
+ }
35
+ const encoding = negotiateResponseCompressionEncoding(response, interceptorOptions.request.headers, this.encodings);
36
+ if (encoding === undefined) {
37
+ return result;
38
+ }
39
+ let stream;
40
+
41
+ let bodyHeaders;
42
+
43
+ if (Array.isArray(body)) {
44
+
45
+ const [string, jsonHeaders] = toFetchBody(body, headers);
46
+ const json = new Blob([string]);
47
+ if (json.size < this.threshold) {
48
+ return result;
49
+ }
50
+ stream = json.stream();
51
+ bodyHeaders = {
52
+ "content-type": jsonHeaders["content-type"],
53
+
54
+ "standard-server": jsonHeaders["standard-server"] ?? []
55
+ };
56
+ } else if (body instanceof Blob || body instanceof ReadableStream) {
57
+ if (body instanceof Blob && Number.isFinite(body.size) && body.size < this.threshold) {
58
+ return result;
59
+ }
60
+ stream = body instanceof Blob ? body.stream() : body;
61
+ bodyHeaders = { "standard-server": "octet-stream" };
62
+ } else {
63
+ return result;
64
+ }
65
+ return {
66
+ ...result,
67
+ response: {
68
+ ...response,
69
+ body: stream.pipeThrough(createFlushingCompressionStream(encoding)),
70
+ headers: {
71
+ ...toCompressedHeaders(headers, encoding),
72
+ ...bodyHeaders
73
+ }
74
+ }
75
+ };
76
+ };
77
+ return {
78
+ ...options,
79
+ routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)]
80
+ };
81
+ }
82
+ }
83
+
84
+ function createFlushingCompressionStream(encoding) {
85
+ const zlibOptions = { flush: constants.Z_SYNC_FLUSH };
86
+ const compressor = encoding === "gzip" ? createGzip(zlibOptions) : encoding === "deflate" ? createDeflate(zlibOptions) : createDeflateRaw(zlibOptions);
87
+ return Duplex.toWeb(compressor);
88
+ }
package/dist/index.d.mts CHANGED
@@ -1,316 +1,3 @@
1
- import { Context } from '@orpc/server';
2
- import { StandardHandlerPlugin, StandardHandlerOptions, StandardHandlerRoutingInterceptorOptions } from '@orpc/server/standard';
3
- import { Value, Promisable } from '@orpc/shared';
4
- import { FilePropertyBag } from 'node:buffer';
5
-
6
- interface BatchResponseCompressionHandlerPluginOptions {
7
- /**
8
- * The compression schemes to use for batch responses.
9
- * Schemes are prioritized by their order in this array and
10
- * only applied if the client supports them (via Accept-Encoding).
11
- *
12
- * @default ['gzip', 'deflate']
13
- */
14
- encodings?: readonly ('gzip' | 'deflate' | 'deflate-raw')[] | undefined;
15
- /**
16
- * The minimum response size in bytes required to trigger compression.
17
- * Responses smaller than this threshold will not be compressed to avoid overhead.
18
- * A streaming batch response has no size until it ends, so it is always compressed.
19
- *
20
- * @default 1024 (1KB)
21
- */
22
- threshold?: number | undefined;
23
- }
24
- /**
25
- * Compresses every successful [batch](https://orpc.dev/docs/plugins/batch) response, which the
26
- * runtime-agnostic {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
27
- * leaves untouched when framed: a batch frames subresponses of mixed content types, so its envelope
28
- * has none of its own and nothing says whether the contents compress. Registering this plugin
29
- * states that they do.
30
- *
31
- * @remarks
32
- * Each message is flushed as soon as it is produced, so a streaming batch stays streaming.
33
- * This is why the plugin lives in the Node.js package: `zlib` can flush mid-stream, while the
34
- * web `CompressionStream` cannot, and would hold every early message until the batch ends.
35
- *
36
- * @see {@link https://orpc.dev/docs/plugins/batch-response-compression | Batch Response Compression Plugin}
37
- */
38
- declare class BatchResponseCompressionHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
39
- name: string;
40
- /**
41
- * Compression should be done after batching, to compress the assembled batch response
42
- * rather than each subresponse inside it.
43
- */
44
- after: string[];
45
- private readonly encodings;
46
- private readonly threshold;
47
- constructor(options?: BatchResponseCompressionHandlerPluginOptions);
48
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
49
- }
50
-
51
- interface StaticFileHandlerPluginOptions {
52
- /**
53
- * The directory files are served from. Resolved against the working
54
- * directory when relative.
55
- */
56
- rootDir: string;
57
- /**
58
- * The URL path files are served under, appended to the handler prefix
59
- * when one is set.
60
- *
61
- * @default '/'
62
- */
63
- path?: `/${string}` | undefined;
64
- /**
65
- * The file served when the request path resolves to a directory.
66
- * Set to `false` to disable directory index files.
67
- *
68
- * @default 'index.html'
69
- */
70
- indexFile?: string | false | undefined;
71
- /**
72
- * A file served with status 200 when no file matches the request path,
73
- * relative to `rootDir`. Useful for single-page application routing.
74
- *
75
- * @default undefined
76
- */
77
- fallbackFile?: string | undefined;
78
- /**
79
- * The `Cache-Control` response header value. Set to `false` to omit the header.
80
- *
81
- * @default 'public, max-age=0'
82
- */
83
- cacheControl?: string | false | undefined;
84
- /**
85
- * Whether files and directories whose name starts with a dot can be served.
86
- * When disabled, names shaped like 8.3 short names, such as `ENV~1`, are refused too,
87
- * since NTFS and FAT resolve them to dotfiles.
88
- *
89
- * @default false
90
- */
91
- dotfiles?: boolean | undefined;
92
- /**
93
- * Whether precompressed sidecar files (`.br`, `.zst`, `.gz`) can be served
94
- * when the client accepts their encoding and the content type is compressible.
95
- *
96
- * @default false
97
- */
98
- precompressed?: boolean | undefined;
99
- /**
100
- * Whether symbolic links whose target lies outside `rootDir` can be served.
101
- * Enabling this makes every file the links reach publicly readable.
102
- *
103
- * @default false
104
- */
105
- allowSymlinks?: boolean | undefined;
106
- /**
107
- * Content types keyed by lowercase file extension without the dot, taking precedence over
108
- * the type detected from the extension. Values are sent verbatim, so a text type needs its
109
- * own charset. Extensions that neither this nor the detection recognises are served as
110
- * `application/octet-stream`.
111
- */
112
- mimeTypes?: Record<string, string> | undefined;
113
- }
114
- /**
115
- * Serves static files from a directory with standard HTTP semantics:
116
- * `ETag`/`Last-Modified` conditional requests, range requests, index files,
117
- * and directory traversal protection. Files are served as a fallback,
118
- * so matched procedures always win.
119
- *
120
- * @remarks
121
- * Deliberate deviations, all matching `send`, nginx, and Hono: range handling applies to `GET`
122
- * only, so `HEAD` always reports the full length even though `Accept-Ranges` advertises support;
123
- * a suffix range against an empty file answers `416`; and `dotfiles` is a request-path policy,
124
- * so it never applies to a configured `indexFile` or `fallbackFile`.
125
- *
126
- * @see {@link https://orpc.dev/docs/plugins/static-file | Static File Plugin}
127
- */
128
- declare class StaticFileHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
129
- name: string;
130
- /**
131
- * Ensure the request span is available when the interceptor renames it.
132
- */
133
- after: string[];
134
- private readonly rootDir;
135
- /** `rootDir` with a trailing separator, precomputed for the lexical containment check. */
136
- private readonly rootDirPrefix;
137
- /**
138
- * `rootDir` with its own symbolic links resolved, paired with its trailing separator form.
139
- * Resolved once, so a symlinked `rootDir` keeps working and platform links like the macOS
140
- * `/var` to `/private/var` do not reject every file.
141
- */
142
- private readonly rootDirRealPaths;
143
- private readonly path;
144
- private readonly indexFile;
145
- private readonly fallbackFile;
146
- private readonly cacheControl;
147
- private readonly dotfiles;
148
- private readonly precompressed;
149
- private readonly allowSymlinks;
150
- private readonly mimeTypes;
151
- constructor(options: StaticFileHandlerPluginOptions);
152
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
153
- /**
154
- * Joins segments under `rootDir` and guarantees the result cannot escape it,
155
- * as a second layer of defense after URL segment validation.
156
- */
157
- private resolveWithinRoot;
158
- /**
159
- * Resolves symbolic links and confirms the target is still inside the root,
160
- * which the lexical `resolveWithinRoot` check cannot see.
161
- */
162
- private resolveContainedRealPath;
163
- private resolveContentType;
164
- private resolveBasePath;
165
- /**
166
- * Resolves segments under `rootDir` and stats the result, rejecting anything that
167
- * escapes the root either lexically or by following a symbolic link.
168
- */
169
- private lookup;
170
- /**
171
- * Normalizes the url path into filesystem segments,
172
- * returning `undefined` when the request can never map to a servable file.
173
- */
174
- private resolveSegments;
175
- private serve;
176
- }
177
-
178
- interface TmpFileUploadHandlerPluginMaxBodySize {
179
- /**
180
- * The maximum size in bytes of request body content buffered into memory:
181
- * JSON, URL-encoded forms, and the fields, part headers, and in-memory files
182
- * of a multipart body in total, and each event of an event stream on its
183
- * own. Exceeding it rejects with `PAYLOAD_TOO_LARGE`, except for uploads,
184
- * which spool to disk instead once they no longer fit. Usually the lowest of
185
- * the three limits, because this content cannot stream anywhere.
186
- */
187
- memory: number;
188
- /**
189
- * The maximum total size in bytes of uploaded file content: file bodies and
190
- * the file parts of a multipart body combined, whether held in memory or
191
- * spooled to temporary files. A larger body rejects the request with
192
- * `PAYLOAD_TOO_LARGE`.
193
- */
194
- file: number;
195
- /**
196
- * The maximum total size in bytes of a request body that is consumed as a
197
- * stream: event streams and raw binary streams. Enforced while the stream is
198
- * consumed, so an oversized stream fails at the reader. Usually the highest
199
- * of the three limits, but keep it finite so no client can stream
200
- * indefinitely.
201
- */
202
- stream: number;
203
- }
204
- interface TmpFileUploadHandlerPluginOptions<T extends Context> {
205
- /**
206
- * The directory temporary files are created under. Each request that spools
207
- * an upload gets its own subdirectory inside it, removed when the request
208
- * finishes.
209
- *
210
- * @default os.tmpdir()
211
- */
212
- tmpDir?: string | undefined;
213
- /**
214
- * The size limit for each kind of request body, either fixed or resolved
215
- * per request, so limits can follow the request itself, such as a larger
216
- * allowance for an authenticated user than for a guest. Every kind is
217
- * required when the option is given, so none is left unbounded by accident;
218
- * set a kind to `Number.POSITIVE_INFINITY` to deliberately leave it
219
- * unlimited.
220
- *
221
- * A resolver runs only when a body is parsed, so a request without one never
222
- * pays for it, and it receives the request as it arrived, before this plugin
223
- * wraps its body resolution.
224
- *
225
- * @default unlimited for every kind
226
- */
227
- maxBodySize?: Value<Promisable<TmpFileUploadHandlerPluginMaxBodySize>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
228
- /**
229
- * The size in bytes an uploaded file must exceed before it is spooled to a
230
- * temporary file. Smaller files stay in memory as plain `File`s, counted
231
- * against `maxBodySize.memory`, and spool anyway once they no longer fit.
232
- * Set to `0` to spool every non-empty upload.
233
- *
234
- * @default 64 * 1024
235
- */
236
- spoolThreshold?: number | undefined;
237
- }
238
- /**
239
- * A `File` whose content lives in a temporary file on disk and is read lazily,
240
- * so it can represent an upload far larger than available memory.
241
- *
242
- * @remarks
243
- * Node's `fs.openAsBlob`, which backs this class, has known bugs with files
244
- * over 2 GiB ({@link https://github.com/nodejs/node/issues/52585}): `size` is
245
- * truncated above 4 GiB and `slice()` is unreliable above 2 GiB, while
246
- * whole-file reads like `stream()` stay correct. When size or random access
247
- * matters for such a file, stat or read {@link path} directly.
248
- *
249
- * @see {@link https://orpc.dev/docs/plugins/tmp-file-upload | Tmp File Upload Plugin}
250
- */
251
- declare class TmpFile extends File {
252
- /**
253
- * Absolute path of the temporary file holding this file's content.
254
- * The file is removed when the request finishes, so move or copy it
255
- * to keep the content. The `File` reads from this path, so it must
256
- * not be read after the file is moved or removed.
257
- */
258
- readonly path: string;
259
- constructor(blob: Blob,
260
- /**
261
- * Absolute path of the temporary file holding this file's content.
262
- * The file is removed when the request finishes, so move or copy it
263
- * to keep the content. The `File` reads from this path, so it must
264
- * not be read after the file is moved or removed.
265
- */
266
- path: string, name: string, options?: FilePropertyBag);
267
- }
268
- /**
269
- * Parses file uploads into temporary files instead of memory. Bodies the standard
270
- * body parser would buffer into an in-memory `File`, and multipart file parts, are
271
- * streamed to disk once they outgrow the spool threshold and surfaced as lazily read
272
- * {@link TmpFile} instances, so requests far larger than available memory parse in
273
- * constant memory. Smaller uploads stay in memory as plain `File`s. Every other body is
274
- * left to the standard parser.
275
- *
276
- * Request body sizes are limited per content category: buffered in memory, uploaded
277
- * files, and streamed, each limit fixed or resolved per request. This subsumes the
278
- * request limit plugin while sizing each kind of body to what it actually costs.
279
- *
280
- * @remarks
281
- * Temporary files are removed when the request finishes. A streaming response body,
282
- * an event iterator or a raw stream, keeps them alive until it completes, so
283
- * responses that read the upload while streaming work. Any other response is
284
- * transmitted after removal, so one that embeds the upload itself, as a `File` or
285
- * inside `FormData`, needs the content copied or the file moved first.
286
- *
287
- * @see {@link https://orpc.dev/docs/plugins/tmp-file-upload | Tmp File Upload Plugin}
288
- */
289
- declare class TmpFileUploadHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
290
- name: string;
291
- /**
292
- * Should parse the original request body instead of batched sub-requests.
293
- */
294
- after: string[];
295
- /**
296
- * Should run inside the limit and compression plugins, so spooling receives
297
- * the size-checked, decompressed bytes.
298
- */
299
- before: string[];
300
- private readonly tmpDir;
301
- private readonly maxBodySize;
302
- private readonly spoolThreshold;
303
- constructor(options?: TmpFileUploadHandlerPluginOptions<T>);
304
- init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
305
- private resolveBody;
306
- /**
307
- * Enforces size limits on a body the standard parser handles, counting the
308
- * raw bytes before handing them back for regular parsing.
309
- */
310
- private parseLimitedBody;
311
- private parseFileBody;
312
- private parseMultipartBody;
313
- }
314
-
315
- export { BatchResponseCompressionHandlerPlugin, StaticFileHandlerPlugin, TmpFile, TmpFileUploadHandlerPlugin };
316
- export type { BatchResponseCompressionHandlerPluginOptions, StaticFileHandlerPluginOptions, TmpFileUploadHandlerPluginMaxBodySize, TmpFileUploadHandlerPluginOptions };
1
+ export * from "./batch-response-compression-handler-plugin.mjs";
2
+ export * from "./static-file-handler-plugin.mjs";
3
+ export * from "./tmp-file-upload-handler-plugin.mjs";