@orpc/node 2.0.0-beta.48 → 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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <img alt="codecov" src="https://codecov.io/gh/middleapi/orpc/branch/main/graph/badge.svg">
6
6
  </a>
7
7
  <a href="https://www.npmjs.com/package/@orpc/node">
8
- <img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fnode?logo=npm" />
8
+ <img alt="monthly downloads" src="https://img.shields.io/npm/dm/%40orpc%2Fnode?logo=npm" />
9
9
  </a>
10
10
  <a href="https://app.codspeed.io/middleapi/orpc?utm_source=badge">
11
11
  <img alt="CodSpeed" src="https://img.shields.io/endpoint?url=https://codspeed.io/badge.json" />
@@ -41,10 +41,11 @@ export const router = {
41
41
  Then call them from a client that knows every input and output, without generating anything:
42
42
 
43
43
  ```ts
44
- import type { RouterClient } from '@orpc/server'
45
- import type { router } from './router'
46
44
  import { createORPCClient } from '@orpc/client'
47
45
  import { RPCLink } from '@orpc/client/fetch'
46
+ import type { RouterClient } from '@orpc/server'
47
+
48
+ import type { router } from './router'
48
49
 
49
50
  const link = new RPCLink({ origin: 'http://localhost:3000', url: '/rpc' })
50
51
  const client: RouterClient<typeof router> = createORPCClient(link)
@@ -208,7 +209,6 @@ With thanks to [40 past sponsors](https://orpc.dev/sponsors#past-sponsors) who h
208
209
  <tr>
209
210
  <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
211
  <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>
212
212
  </tr>
213
213
  </table>
214
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,129 @@
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
+ * Compresses every successful [batch](https://orpc.dev/docs/plugins/batch) response, which the
9
+ * runtime-agnostic {@link https://orpc.dev/docs/plugins/response-compression | Response Compression Plugin}
10
+ * leaves untouched when framed: a batch frames subresponses of mixed content types, so its envelope
11
+ * has none of its own and nothing says whether the contents compress. Registering this plugin
12
+ * states that they do.
13
+ *
14
+ * @remarks
15
+ * Each message is flushed as soon as it is produced, so a streaming batch stays streaming.
16
+ * This is why the plugin lives in the Node.js package: `zlib` can flush mid-stream, while the
17
+ * web `CompressionStream` cannot, and would hold every early message until the batch ends.
18
+ *
19
+ * @see {@link https://orpc.dev/docs/plugins/batch-response-compression | Batch Response Compression Plugin}
20
+ */
21
+ export class BatchResponseCompressionHandlerPlugin {
22
+ name = '~batch-response-compression';
23
+ /**
24
+ * Compression should be done after batching, to compress the assembled batch response
25
+ * rather than each subresponse inside it.
26
+ */
27
+ after = ['~batch'];
28
+ encodings;
29
+ threshold;
30
+ constructor(options = {}) {
31
+ this.encodings = options.encodings ?? ['gzip', 'deflate'];
32
+ this.threshold = options.threshold ?? 1024;
33
+ }
34
+ init(options) {
35
+ const routingInterceptor = async ({ next, ...interceptorOptions }) => {
36
+ const result = await next();
37
+ if (!result.matched) {
38
+ return result;
39
+ }
40
+ /**
41
+ * The batch plugin only engages on a request carrying this header, so a response framed like
42
+ * a batch without it belongs to a procedure serving that content type itself, whose own file
43
+ * semantics must survive untouched.
44
+ */
45
+ if (flattenStandardHeader(interceptorOptions.request.headers[BATCH_HEADER]) === undefined) {
46
+ return result;
47
+ }
48
+ const response = result.response;
49
+ const headers = response.headers;
50
+ const body = response.body;
51
+ /**
52
+ * A batch that failed as a whole answers with a plain message instead of subresponses,
53
+ * so only a successful envelope is a batch payload worth compressing.
54
+ */
55
+ if (response.status >= 400) {
56
+ return result;
57
+ }
58
+ const encoding = negotiateResponseCompressionEncoding(response, interceptorOptions.request.headers, this.encodings);
59
+ if (encoding === undefined) {
60
+ return result;
61
+ }
62
+ let stream;
63
+ /**
64
+ * A framed body is opaque bytes, while a json one still has to be parsed as json,
65
+ * so each keeps the hint that tells the client how to read it.
66
+ */
67
+ let bodyHeaders;
68
+ /**
69
+ * A buffered batch with no binary or stream subresponse stays a plain array of messages, serialized
70
+ * as json by the adapter. The header and status above already say this is a batch envelope,
71
+ * so the array itself is the only thing left to recognise.
72
+ */
73
+ if (Array.isArray(body)) {
74
+ // Serialized here rather than by the adapter, which no longer sees the array
75
+ const [string, jsonHeaders] = toFetchBody(body, headers);
76
+ const json = new Blob([string]);
77
+ if (json.size < this.threshold) {
78
+ return result;
79
+ }
80
+ stream = json.stream();
81
+ bodyHeaders = {
82
+ 'content-type': jsonHeaders['content-type'],
83
+ // An empty hint rather than none, so the adapter does not hint the compressed stream as `octet-stream`
84
+ 'standard-server': jsonHeaders['standard-server'] ?? [],
85
+ };
86
+ }
87
+ // Every other batch body is the length-prefixed framing, buffered into a blob or streamed
88
+ else if (body instanceof Blob || body instanceof ReadableStream) {
89
+ if (body instanceof Blob && Number.isFinite(body.size) && body.size < this.threshold) {
90
+ return result;
91
+ }
92
+ stream = body instanceof Blob ? body.stream() : body;
93
+ bodyHeaders = { 'standard-server': 'octet-stream' };
94
+ }
95
+ else {
96
+ return result;
97
+ }
98
+ return {
99
+ ...result,
100
+ response: {
101
+ ...response,
102
+ body: stream.pipeThrough(createFlushingCompressionStream(encoding)),
103
+ headers: {
104
+ ...toCompressedHeaders(headers, encoding),
105
+ ...bodyHeaders,
106
+ },
107
+ },
108
+ };
109
+ };
110
+ return {
111
+ ...options,
112
+ routingInterceptors: [routingInterceptor, ...toArray(options.routingInterceptors)],
113
+ };
114
+ }
115
+ }
116
+ /**
117
+ * A compressor that ends every write with a sync flush, so each batch message reaches the client
118
+ * as soon as the batch produces it instead of waiting in the compressor for the batch to end.
119
+ * The few bytes each flush costs are what keep a streaming batch streaming.
120
+ */
121
+ function createFlushingCompressionStream(encoding) {
122
+ const zlibOptions = { flush: constants.Z_SYNC_FLUSH };
123
+ const compressor = encoding === 'gzip'
124
+ ? createGzip(zlibOptions)
125
+ : encoding === 'deflate'
126
+ ? createDeflate(zlibOptions)
127
+ : createDeflateRaw(zlibOptions);
128
+ return Duplex.toWeb(compressor);
129
+ }
@@ -0,0 +1,3 @@
1
+ export * from './batch-response-compression-handler-plugin.ts';
2
+ export * from './static-file-handler-plugin.ts';
3
+ export * from './tmp-file-upload-handler-plugin.ts';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './batch-response-compression-handler-plugin.js';
2
+ export * from './static-file-handler-plugin.js';
3
+ export * from './tmp-file-upload-handler-plugin.js';
@@ -0,0 +1,60 @@
1
+ import { Buffer } from 'node:buffer';
2
+ export interface MultipartPart {
3
+ /**
4
+ * The `name` parameter of the part's `Content-Disposition` header, with the
5
+ * serialization escapes of `"`, `\r`, and `\n` decoded.
6
+ */
7
+ name: string;
8
+ /**
9
+ * The `filename` parameter of the part's `Content-Disposition` header,
10
+ * decoded like `name`, or `undefined` when the part is a plain field. An
11
+ * empty string is a file part, matching how browsers submit an empty file
12
+ * input.
13
+ */
14
+ filename: string | undefined;
15
+ /**
16
+ * The part's `Content-Type` header value, if present.
17
+ */
18
+ type: string | undefined;
19
+ /**
20
+ * The size in bytes of the part's header block, including the blank line.
21
+ */
22
+ headerSize: number;
23
+ }
24
+ export interface MultipartPartWriter {
25
+ /**
26
+ * Receives one chunk of the part's body. The chunk is only valid until the
27
+ * returned promise resolves, so it must be consumed or copied synchronously.
28
+ */
29
+ write(chunk: Buffer): void | Promise<void>;
30
+ /**
31
+ * Called once after the part's final chunk.
32
+ */
33
+ end(): void | Promise<void>;
34
+ }
35
+ /**
36
+ * Parses a `multipart/form-data` byte stream part by part, so a part's body can be
37
+ * consumed as it arrives instead of being buffered whole. Bodies are delivered to the
38
+ * writer `onPart` returns, with writer promises awaited for backpressure, so parts are
39
+ * processed strictly one at a time.
40
+ *
41
+ * Line endings are strictly CRLF, every part must carry a `form-data` content
42
+ * disposition with a `name` parameter, and a malformed or truncated body throws a
43
+ * `TypeError`, matching the standard parser's strictness.
44
+ *
45
+ * @see https://www.rfc-editor.org/rfc/rfc7578
46
+ * @see https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
47
+ */
48
+ export declare function parseMultipart(source: ReadableStream<Uint8Array>, boundary: string, onPart: (part: MultipartPart) => MultipartPartWriter | Promise<MultipartPartWriter>): Promise<void>;
49
+ /**
50
+ * Extracts the `key=value` parameters that follow a header's leading token.
51
+ * The first occurrence of a parameter wins.
52
+ *
53
+ * A backslash inside a quoted value is a literal character rather than an
54
+ * escape, matching the standard parser: the multipart serialization escapes
55
+ * `"` as `%22`, so a quote can never occur inside a value, while filenames
56
+ * with literal backslashes are common and must survive verbatim.
57
+ *
58
+ * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm
59
+ */
60
+ export declare function parseHeaderParameters(header: string): Map<string, string>;
@@ -0,0 +1,221 @@
1
+ import { Buffer } from 'node:buffer';
2
+ /**
3
+ * Part headers are tiny in practice, so an unterminated header block is cut off
4
+ * long before it can buffer a request-sized payload in memory.
5
+ */
6
+ const MAX_PART_HEADER_SIZE = 16 * 1024;
7
+ const CRLF = /* @__PURE__ */ Buffer.from('\r\n');
8
+ const HEADER_BLOCK_END = /* @__PURE__ */ Buffer.from('\r\n\r\n');
9
+ /**
10
+ * Parses a `multipart/form-data` byte stream part by part, so a part's body can be
11
+ * consumed as it arrives instead of being buffered whole. Bodies are delivered to the
12
+ * writer `onPart` returns, with writer promises awaited for backpressure, so parts are
13
+ * processed strictly one at a time.
14
+ *
15
+ * Line endings are strictly CRLF, every part must carry a `form-data` content
16
+ * disposition with a `name` parameter, and a malformed or truncated body throws a
17
+ * `TypeError`, matching the standard parser's strictness.
18
+ *
19
+ * @see https://www.rfc-editor.org/rfc/rfc7578
20
+ * @see https://www.rfc-editor.org/rfc/rfc2046#section-5.1.1
21
+ */
22
+ export async function parseMultipart(source, boundary, onPart) {
23
+ const delimiter = Buffer.from(`\r\n--${boundary}`);
24
+ /**
25
+ * Seeded with a virtual CRLF so the opening `--boundary` line, which the grammar
26
+ * allows without a preceding line break, matches the same needle as every
27
+ * later delimiter.
28
+ */
29
+ let buffer = CRLF;
30
+ let state = 'preamble';
31
+ let writer;
32
+ let done = false;
33
+ const process = async () => {
34
+ while (true) {
35
+ if (state === 'preamble' || state === 'body') {
36
+ const index = buffer.indexOf(delimiter);
37
+ if (index === -1) {
38
+ // All bytes except a possible delimiter prefix are settled and can be flushed
39
+ const settledLength = buffer.length - delimiter.length + 1;
40
+ if (settledLength > 0) {
41
+ if (state === 'body') {
42
+ await writer.write(buffer.subarray(0, settledLength));
43
+ }
44
+ buffer = buffer.subarray(settledLength);
45
+ }
46
+ return;
47
+ }
48
+ if (state === 'body') {
49
+ if (index > 0) {
50
+ await writer.write(buffer.subarray(0, index));
51
+ }
52
+ await writer.end();
53
+ writer = undefined;
54
+ }
55
+ buffer = buffer.subarray(index + delimiter.length);
56
+ state = 'delimiter-end';
57
+ continue;
58
+ }
59
+ if (state === 'delimiter-end') {
60
+ if (buffer.length < 2) {
61
+ return;
62
+ }
63
+ // A close delimiter is `--` immediately after the boundary, everything after it is epilogue
64
+ if (buffer[0] === 0x2d && buffer[1] === 0x2d) {
65
+ done = true;
66
+ buffer = Buffer.alloc(0);
67
+ return;
68
+ }
69
+ state = 'transport-padding';
70
+ continue;
71
+ }
72
+ if (state === 'transport-padding') {
73
+ let index = 0;
74
+ while (index < buffer.length && (buffer[index] === 0x20 || buffer[index] === 0x09)) {
75
+ index++;
76
+ }
77
+ buffer = buffer.subarray(index);
78
+ if (buffer.length < 2) {
79
+ return;
80
+ }
81
+ if (buffer[0] !== 0x0d || buffer[1] !== 0x0a) {
82
+ throw new TypeError('Invalid multipart body: expected CRLF after a boundary delimiter');
83
+ }
84
+ buffer = buffer.subarray(2);
85
+ state = 'headers';
86
+ continue;
87
+ }
88
+ // A part without headers can never carry the required content-disposition
89
+ if (buffer[0] === 0x0d && buffer[1] === 0x0a) {
90
+ throw new TypeError('Invalid multipart body: part is missing the content-disposition header');
91
+ }
92
+ const headerWindow = MAX_PART_HEADER_SIZE + HEADER_BLOCK_END.length;
93
+ const headerEnd = buffer.subarray(0, headerWindow).indexOf(HEADER_BLOCK_END);
94
+ if (headerEnd === -1) {
95
+ if (buffer.length >= headerWindow) {
96
+ throw new TypeError('Invalid multipart body: part headers exceed the maximum allowed size');
97
+ }
98
+ return;
99
+ }
100
+ const headerSize = headerEnd + HEADER_BLOCK_END.length;
101
+ const part = parsePartHeaders(buffer.subarray(0, headerEnd).toString(), headerSize);
102
+ buffer = buffer.subarray(headerSize);
103
+ writer = await onPart(part);
104
+ state = 'body';
105
+ }
106
+ };
107
+ for await (const chunk of source) {
108
+ if (done) {
109
+ continue;
110
+ }
111
+ // A bare view suffices when nothing is retained, skipping a copy
112
+ buffer =
113
+ buffer.length === 0
114
+ ? Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength)
115
+ : Buffer.concat([buffer, chunk]);
116
+ await process();
117
+ }
118
+ if (!done) {
119
+ throw new TypeError('Invalid multipart body: unexpected end of body');
120
+ }
121
+ }
122
+ function parsePartHeaders(block, headerSize) {
123
+ let contentDisposition;
124
+ let contentType;
125
+ for (const line of block.split('\r\n')) {
126
+ const colon = line.indexOf(':');
127
+ if (colon === -1) {
128
+ throw new TypeError('Invalid multipart body: malformed part header');
129
+ }
130
+ const name = line.slice(0, colon).trim().toLowerCase();
131
+ if (name === 'content-disposition') {
132
+ contentDisposition = line.slice(colon + 1).trim();
133
+ }
134
+ else if (name === 'content-type') {
135
+ contentType = line.slice(colon + 1).trim();
136
+ }
137
+ }
138
+ if (contentDisposition === undefined) {
139
+ throw new TypeError('Invalid multipart body: part is missing the content-disposition header');
140
+ }
141
+ // The standard parser accepts no disposition type other than form-data, case-insensitively
142
+ const semicolon = contentDisposition.indexOf(';');
143
+ const dispositionType = (semicolon === -1 ? contentDisposition : contentDisposition.slice(0, semicolon))
144
+ .trim()
145
+ .toLowerCase();
146
+ if (dispositionType !== 'form-data') {
147
+ throw new TypeError('Invalid multipart body: content-disposition must be form-data');
148
+ }
149
+ const parameters = parseHeaderParameters(contentDisposition);
150
+ const name = parameters.get('name');
151
+ if (name === undefined) {
152
+ throw new TypeError('Invalid multipart body: content-disposition header is missing the name parameter');
153
+ }
154
+ const filename = parameters.get('filename');
155
+ return {
156
+ name: decodeContentDispositionParameter(name),
157
+ filename: filename === undefined ? undefined : decodeContentDispositionParameter(filename),
158
+ type: contentType,
159
+ headerSize,
160
+ };
161
+ }
162
+ /**
163
+ * The multipart serialization every spec-compliant client uses escapes `"`, `\r`,
164
+ * and `\n` in content-disposition names and filenames as `%22`, `%0D`, and `%0A`,
165
+ * and the standard parser reverses exactly these three.
166
+ *
167
+ * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm
168
+ */
169
+ function decodeContentDispositionParameter(value) {
170
+ return value.replaceAll('%22', '"').replaceAll('%0D', '\r').replaceAll('%0A', '\n');
171
+ }
172
+ /**
173
+ * Extracts the `key=value` parameters that follow a header's leading token.
174
+ * The first occurrence of a parameter wins.
175
+ *
176
+ * A backslash inside a quoted value is a literal character rather than an
177
+ * escape, matching the standard parser: the multipart serialization escapes
178
+ * `"` as `%22`, so a quote can never occur inside a value, while filenames
179
+ * with literal backslashes are common and must survive verbatim.
180
+ *
181
+ * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart/form-data-encoding-algorithm
182
+ */
183
+ export function parseHeaderParameters(header) {
184
+ const parameters = new Map();
185
+ let index = header.indexOf(';');
186
+ while (index !== -1 && index < header.length) {
187
+ index++;
188
+ while (index < header.length && (header[index] === ' ' || header[index] === '\t')) {
189
+ index++;
190
+ }
191
+ let equals = index;
192
+ while (equals < header.length && header[equals] !== '=' && header[equals] !== ';') {
193
+ equals++;
194
+ }
195
+ if (equals === header.length) {
196
+ break;
197
+ }
198
+ // A parameter without a value ends at the next semicolon and is skipped
199
+ if (header[equals] === ';') {
200
+ index = equals;
201
+ continue;
202
+ }
203
+ const key = header.slice(index, equals).trim().toLowerCase();
204
+ index = equals + 1;
205
+ let value;
206
+ if (header[index] === '"') {
207
+ const closing = header.indexOf('"', index + 1);
208
+ value = closing === -1 ? header.slice(index + 1) : header.slice(index + 1, closing);
209
+ index = closing === -1 ? -1 : header.indexOf(';', closing + 1);
210
+ }
211
+ else {
212
+ const semicolon = header.indexOf(';', index);
213
+ value = (semicolon === -1 ? header.slice(index) : header.slice(index, semicolon)).trim();
214
+ index = semicolon;
215
+ }
216
+ if (!parameters.has(key)) {
217
+ parameters.set(key, value);
218
+ }
219
+ }
220
+ return parameters;
221
+ }
@@ -0,0 +1,84 @@
1
+ import type { Context } from '@orpc/server';
2
+ import type { StandardHandlerOptions, StandardHandlerPlugin } from '@orpc/server/standard';
3
+ export interface StaticFileHandlerPluginOptions {
4
+ /**
5
+ * The directory files are served from. Resolved against the working
6
+ * directory when relative.
7
+ */
8
+ rootDir: string;
9
+ /**
10
+ * The URL path files are served under, appended to the handler prefix
11
+ * when one is set.
12
+ *
13
+ * @default '/'
14
+ */
15
+ path?: `/${string}` | undefined;
16
+ /**
17
+ * The file served when the request path resolves to a directory.
18
+ * Set to `false` to disable directory index files.
19
+ *
20
+ * @default 'index.html'
21
+ */
22
+ indexFile?: string | false | undefined;
23
+ /**
24
+ * A file served with status 200 when no file matches the request path,
25
+ * relative to `rootDir`. Useful for single-page application routing.
26
+ *
27
+ * @default undefined
28
+ */
29
+ fallbackFile?: string | undefined;
30
+ /**
31
+ * The `Cache-Control` response header value. Set to `false` to omit the header.
32
+ *
33
+ * @default 'public, max-age=0'
34
+ */
35
+ cacheControl?: string | false | undefined;
36
+ /**
37
+ * Whether files and directories whose name starts with a dot can be served.
38
+ * This is a request path policy, so it does not apply to a configured `indexFile`
39
+ * or `fallbackFile`, nor to the target of a symbolic link.
40
+ * When disabled, names shaped like 8.3 short names, such as `ENV~1`, are refused too,
41
+ * since NTFS and FAT resolve them to dotfiles.
42
+ *
43
+ * @default false
44
+ */
45
+ dotfiles?: boolean | undefined;
46
+ /**
47
+ * Whether precompressed sidecar files (`.br`, `.zst`, `.gz`) can be served
48
+ * when the client accepts their encoding and the content type is compressible.
49
+ *
50
+ * @default false
51
+ */
52
+ precompressed?: boolean | undefined;
53
+ /**
54
+ * Content types keyed by lowercase file extension without the dot, taking precedence over
55
+ * the type detected from the extension. Values are sent verbatim, so a text type needs its
56
+ * own charset. Extensions that neither this nor the detection recognises are served as
57
+ * `application/octet-stream`.
58
+ */
59
+ mimeTypes?: Record<string, string> | undefined;
60
+ }
61
+ /**
62
+ * Serves static files from a directory: index files, `ETag`/`Last-Modified`
63
+ * revalidation, range requests, and precompressed sidecars. Files are served
64
+ * as a fallback, so matched procedures always win.
65
+ *
66
+ * @see {@link https://orpc.dev/docs/plugins/static-file | Static File Plugin}
67
+ */
68
+ export declare class StaticFileHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
69
+ name: string;
70
+ after: string[];
71
+ before: string[];
72
+ private readonly rootDir;
73
+ private readonly path;
74
+ private readonly indexFile;
75
+ private readonly fallbackFilePath;
76
+ private readonly cacheControl;
77
+ private readonly unsafeSegmentRegex;
78
+ private readonly precompressed;
79
+ private readonly mimeTypes;
80
+ constructor(options: StaticFileHandlerPluginOptions);
81
+ init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
82
+ private serve;
83
+ private resolveContentType;
84
+ }