@orpc/node 2.0.0-beta.49 → 2.0.0-beta.51
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 +10 -8
- package/dist/batch-response-compression-handler-plugin.d.ts +30 -29
- package/dist/batch-response-compression-handler-plugin.js +104 -125
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -3
- package/dist/multipart.js +160 -211
- package/dist/static-file-handler-plugin.d.ts +74 -74
- package/dist/static-file-handler-plugin.js +175 -200
- package/dist/tmp-file-upload-handler-plugin.d.ts +92 -101
- package/dist/tmp-file-upload-handler-plugin.js +379 -451
- package/package.json +7 -7
- package/dist/multipart.d.ts +0 -60
|
@@ -1,215 +1,190 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { toWebReadableStream } from
|
|
7
|
-
import mime from
|
|
1
|
+
import { getTracer, isAcceptableEncoding, isCompressibleContentType, matchesHttpPathPrefix, mergeHttpPath, parseAcceptEncodingQualities, safeDecodeURIComponent, toArray } from "@orpc/shared";
|
|
2
|
+
import { flattenStandardHeader, parseStandardUrl } from "@standard-server/core";
|
|
3
|
+
import { createReadStream } from "node:fs";
|
|
4
|
+
import { stat } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { toWebReadableStream } from "@standard-server/node";
|
|
7
|
+
import mime from "mime";
|
|
8
|
+
// src/static-file-handler-plugin.ts
|
|
8
9
|
const UNSAFE_SEGMENT_REGEX = /^[. ]+$|[\0/\\]/;
|
|
9
10
|
const UNSAFE_OR_DOTFILE_SEGMENT_REGEX = /^[. ]+$|^\.|^[^.]{0,6}~\d|[\0/\\]/;
|
|
10
11
|
const PRECOMPRESSED_ENCODINGS = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
["br", ".br"],
|
|
13
|
+
["zstd", ".zst"],
|
|
14
|
+
["gzip", ".gz"]
|
|
14
15
|
];
|
|
15
16
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
resolveContentType(filePath) {
|
|
159
|
-
const extension = path.extname(filePath).slice(1).toLowerCase();
|
|
160
|
-
const configured = this.mimeTypes[extension];
|
|
161
|
-
if (configured !== undefined) {
|
|
162
|
-
return configured;
|
|
163
|
-
}
|
|
164
|
-
const contentType = mime.getType(extension);
|
|
165
|
-
if (contentType === null) {
|
|
166
|
-
return 'application/octet-stream';
|
|
167
|
-
}
|
|
168
|
-
return contentType.startsWith('text/') ? `${contentType}; charset=utf-8` : contentType;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
17
|
+
* Serves static files from a directory: index files, `ETag`/`Last-Modified`
|
|
18
|
+
* revalidation, range requests, and precompressed sidecars. Files are served
|
|
19
|
+
* as a fallback, so matched procedures always win.
|
|
20
|
+
*
|
|
21
|
+
* @see {@link https://orpc.dev/docs/plugins/static-file | Static File Plugin}
|
|
22
|
+
*/
|
|
23
|
+
var StaticFileHandlerPlugin = class {
|
|
24
|
+
name = "~static-file";
|
|
25
|
+
after = ["~tracing"];
|
|
26
|
+
before = ["~head-method"];
|
|
27
|
+
rootDir;
|
|
28
|
+
path;
|
|
29
|
+
indexFile;
|
|
30
|
+
fallbackFilePath;
|
|
31
|
+
cacheControl;
|
|
32
|
+
unsafeSegmentRegex;
|
|
33
|
+
precompressed;
|
|
34
|
+
mimeTypes;
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.rootDir = path.resolve(options.rootDir);
|
|
37
|
+
this.path = stripTrailingSlash(options.path ?? "/");
|
|
38
|
+
this.indexFile = options.indexFile ?? "index.html";
|
|
39
|
+
this.fallbackFilePath = options.fallbackFile === void 0 ? void 0 : path.join(this.rootDir, options.fallbackFile);
|
|
40
|
+
this.cacheControl = options.cacheControl ?? "public, max-age=0";
|
|
41
|
+
this.unsafeSegmentRegex = options.dotfiles ? UNSAFE_SEGMENT_REGEX : UNSAFE_OR_DOTFILE_SEGMENT_REGEX;
|
|
42
|
+
this.precompressed = options.precompressed ?? false;
|
|
43
|
+
this.mimeTypes = Object.assign(Object.create(null), options.mimeTypes);
|
|
44
|
+
}
|
|
45
|
+
init(options) {
|
|
46
|
+
const routingInterceptor = async ({ next, request, prefix }) => {
|
|
47
|
+
const result = await next();
|
|
48
|
+
if (result.matched || request.method !== "GET" && request.method !== "HEAD") return result;
|
|
49
|
+
const base = prefix === void 0 ? this.path : stripTrailingSlash(mergeHttpPath(prefix, this.path));
|
|
50
|
+
const response = await this.serve(request, base);
|
|
51
|
+
if (response === void 0) return result;
|
|
52
|
+
getTracer()?.getActiveSpan()?.updateName(`${request.method} ${base === "/" ? "" : base}/* (static file)`);
|
|
53
|
+
return {
|
|
54
|
+
matched: true,
|
|
55
|
+
response
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
...options,
|
|
60
|
+
routingInterceptors: [...toArray(options.routingInterceptors), routingInterceptor]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async serve(request, base) {
|
|
64
|
+
const [pathname] = parseStandardUrl(request.url);
|
|
65
|
+
if (base !== "/" && !matchesHttpPathPrefix(pathname, base)) return;
|
|
66
|
+
const segments = [];
|
|
67
|
+
let isDirectoryUrl = false;
|
|
68
|
+
for (const rawSegment of pathname.slice(base.length).split("/")) {
|
|
69
|
+
const segment = safeDecodeURIComponent(rawSegment);
|
|
70
|
+
isDirectoryUrl = segment === "" || segment === ".";
|
|
71
|
+
if (isDirectoryUrl) continue;
|
|
72
|
+
if (this.unsafeSegmentRegex.test(segment)) return;
|
|
73
|
+
segments.push(segment);
|
|
74
|
+
}
|
|
75
|
+
let filePath = path.join(this.rootDir, ...segments);
|
|
76
|
+
let stats = isDirectoryUrl ? void 0 : await getStats(filePath);
|
|
77
|
+
if (isDirectoryUrl || stats?.isDirectory()) {
|
|
78
|
+
stats = void 0;
|
|
79
|
+
if (this.indexFile !== false) {
|
|
80
|
+
filePath = path.join(filePath, this.indexFile);
|
|
81
|
+
stats = await getStats(filePath);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!stats?.isFile() && this.fallbackFilePath !== void 0) {
|
|
85
|
+
filePath = this.fallbackFilePath;
|
|
86
|
+
stats = await getStats(filePath);
|
|
87
|
+
}
|
|
88
|
+
if (!stats?.isFile()) return;
|
|
89
|
+
const contentType = this.resolveContentType(filePath);
|
|
90
|
+
const headers = {};
|
|
91
|
+
let contentEncoding;
|
|
92
|
+
if (this.precompressed && isCompressibleContentType(contentType)) {
|
|
93
|
+
headers.vary = "accept-encoding";
|
|
94
|
+
const qualities = parseAcceptEncodingQualities(flattenStandardHeader(request.headers["accept-encoding"]));
|
|
95
|
+
for (const [encoding, extension] of PRECOMPRESSED_ENCODINGS) {
|
|
96
|
+
if (!isAcceptableEncoding(qualities, encoding)) continue;
|
|
97
|
+
const variantStats = await getStats(filePath + extension);
|
|
98
|
+
if (variantStats?.isFile()) {
|
|
99
|
+
filePath += extension;
|
|
100
|
+
stats = variantStats;
|
|
101
|
+
contentEncoding = encoding;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const size = stats.size;
|
|
107
|
+
const etag = `"${size.toString(16)}-${stats.mtime.getTime().toString(16)}"`;
|
|
108
|
+
const lastModifiedTime = Math.floor(stats.mtime.getTime() / 1e3) * 1e3;
|
|
109
|
+
headers.etag = etag;
|
|
110
|
+
headers["last-modified"] = stats.mtime.toUTCString();
|
|
111
|
+
headers["accept-ranges"] = "bytes";
|
|
112
|
+
if (this.cacheControl !== false) headers["cache-control"] = this.cacheControl;
|
|
113
|
+
if (isNotModified(request.headers, etag, lastModifiedTime)) return {
|
|
114
|
+
status: 304,
|
|
115
|
+
headers
|
|
116
|
+
};
|
|
117
|
+
let status = 200;
|
|
118
|
+
let start = 0;
|
|
119
|
+
let end = size - 1;
|
|
120
|
+
const range = request.method === "GET" ? flattenStandardHeader(request.headers.range) : void 0;
|
|
121
|
+
if (range !== void 0 && isRangeApplicable(request.headers, etag, lastModifiedTime)) {
|
|
122
|
+
const parsed = parseByteRange(range, size);
|
|
123
|
+
if (parsed === "unsatisfiable") return {
|
|
124
|
+
status: 416,
|
|
125
|
+
headers: {
|
|
126
|
+
...headers,
|
|
127
|
+
"content-range": `bytes */${size}`
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
if (parsed !== void 0) {
|
|
131
|
+
status = 206;
|
|
132
|
+
[start, end] = parsed;
|
|
133
|
+
headers["content-range"] = `bytes ${start}-${end}/${size}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (contentEncoding !== void 0) headers["content-encoding"] = contentEncoding;
|
|
137
|
+
headers["content-type"] = contentType;
|
|
138
|
+
headers["content-length"] = `${end - start + 1}`;
|
|
139
|
+
const body = request.method === "HEAD" ? new ReadableStream({ start: (controller) => controller.close() }) : toWebReadableStream(createReadStream(filePath, status === 206 ? {
|
|
140
|
+
start,
|
|
141
|
+
end
|
|
142
|
+
} : void 0));
|
|
143
|
+
return {
|
|
144
|
+
status,
|
|
145
|
+
headers,
|
|
146
|
+
body
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
resolveContentType(filePath) {
|
|
150
|
+
const extension = path.extname(filePath).slice(1).toLowerCase();
|
|
151
|
+
const configured = this.mimeTypes[extension];
|
|
152
|
+
if (configured !== void 0) return configured;
|
|
153
|
+
const contentType = mime.getType(extension);
|
|
154
|
+
if (contentType === null) return "application/octet-stream";
|
|
155
|
+
return contentType.startsWith("text/") ? `${contentType}; charset=utf-8` : contentType;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
171
158
|
function getStats(filePath) {
|
|
172
|
-
|
|
159
|
+
return stat(filePath).catch(() => void 0);
|
|
173
160
|
}
|
|
174
161
|
function stripTrailingSlash(path) {
|
|
175
|
-
|
|
162
|
+
return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
176
163
|
}
|
|
177
164
|
function isNotModified(requestHeaders, etag, lastModifiedTime) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
const ifModifiedSince = flattenStandardHeader(requestHeaders['if-modified-since']);
|
|
187
|
-
return ifModifiedSince !== undefined && lastModifiedTime <= Date.parse(ifModifiedSince);
|
|
165
|
+
const ifNoneMatch = flattenStandardHeader(requestHeaders["if-none-match"]);
|
|
166
|
+
if (ifNoneMatch !== void 0) return ifNoneMatch.trim() === "*" || ifNoneMatch.split(",").some((tag) => {
|
|
167
|
+
tag = tag.trim();
|
|
168
|
+
return (tag.startsWith("W/") ? tag.slice(2) : tag) === etag;
|
|
169
|
+
});
|
|
170
|
+
const ifModifiedSince = flattenStandardHeader(requestHeaders["if-modified-since"]);
|
|
171
|
+
return ifModifiedSince !== void 0 && lastModifiedTime <= Date.parse(ifModifiedSince);
|
|
188
172
|
}
|
|
189
173
|
function isRangeApplicable(requestHeaders, etag, lastModifiedTime) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
return ifRange.startsWith('"') || ifRange.startsWith('W/')
|
|
195
|
-
? ifRange === etag
|
|
196
|
-
: Date.parse(ifRange) === lastModifiedTime;
|
|
174
|
+
const ifRange = flattenStandardHeader(requestHeaders["if-range"]);
|
|
175
|
+
if (ifRange === void 0) return true;
|
|
176
|
+
return ifRange.startsWith("\"") || ifRange.startsWith("W/") ? ifRange === etag : Date.parse(ifRange) === lastModifiedTime;
|
|
197
177
|
}
|
|
198
178
|
function parseByteRange(range, size) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
const start = Number(match[1]);
|
|
210
|
-
if (start >= size) {
|
|
211
|
-
return 'unsatisfiable';
|
|
212
|
-
}
|
|
213
|
-
const end = match[2] === '' ? size - 1 : Math.min(Number(match[2]), size - 1);
|
|
214
|
-
return end < start ? undefined : [start, end];
|
|
179
|
+
const match = range.match(/^bytes=\s*(\d*)-(\d*)$/i);
|
|
180
|
+
if (match === null || match[1] === "" && match[2] === "") return;
|
|
181
|
+
if (match[1] === "") {
|
|
182
|
+
const suffixLength = Number(match[2]);
|
|
183
|
+
return suffixLength === 0 || size === 0 ? "unsatisfiable" : [Math.max(0, size - suffixLength), size - 1];
|
|
184
|
+
}
|
|
185
|
+
const start = Number(match[1]);
|
|
186
|
+
if (start >= size) return "unsatisfiable";
|
|
187
|
+
const end = match[2] === "" ? size - 1 : Math.min(Number(match[2]), size - 1);
|
|
188
|
+
return end < start ? void 0 : [start, end];
|
|
215
189
|
}
|
|
190
|
+
export { StaticFileHandlerPlugin };
|
|
@@ -1,68 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { Promisable, Value } from "@orpc/shared";
|
|
2
|
+
import { FilePropertyBag } from "node:buffer";
|
|
3
|
+
import { Context } from "@orpc/server";
|
|
4
|
+
import { StandardHandlerOptions, StandardHandlerPlugin, StandardHandlerRoutingInterceptorOptions } from "@orpc/server/standard";
|
|
5
5
|
export interface TmpFileUploadHandlerPluginMaxBodySize {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The maximum size in bytes of request body content buffered into memory:
|
|
8
|
+
* JSON, URL-encoded forms, and the fields, part headers, and in-memory files
|
|
9
|
+
* of a multipart body in total, and each event of an event stream on its
|
|
10
|
+
* own. Exceeding it rejects with `PAYLOAD_TOO_LARGE`, except for uploads,
|
|
11
|
+
* which spool to disk instead once they no longer fit. Usually the lowest of
|
|
12
|
+
* the three limits, because this content cannot stream anywhere.
|
|
13
|
+
*/
|
|
14
|
+
memory: number;
|
|
15
|
+
/**
|
|
16
|
+
* The maximum total size in bytes of uploaded file content: file bodies and
|
|
17
|
+
* the file parts of a multipart body combined, whether held in memory or
|
|
18
|
+
* spooled to temporary files. A larger body rejects the request with
|
|
19
|
+
* `PAYLOAD_TOO_LARGE`.
|
|
20
|
+
*/
|
|
21
|
+
file: number;
|
|
22
|
+
/**
|
|
23
|
+
* The maximum total size in bytes of a request body that is consumed as a
|
|
24
|
+
* stream: event streams and raw binary streams. Enforced while the stream is
|
|
25
|
+
* consumed, so an oversized stream fails at the reader. Usually the highest
|
|
26
|
+
* of the three limits, but keep it finite so no client can stream
|
|
27
|
+
* indefinitely.
|
|
28
|
+
*/
|
|
29
|
+
stream: number;
|
|
30
30
|
}
|
|
31
31
|
export interface TmpFileUploadHandlerPluginOptions<T extends Context> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
65
|
-
spoolThreshold?: number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The directory temporary files are created under. Each request that spools
|
|
34
|
+
* an upload gets its own subdirectory inside it, removed when the request
|
|
35
|
+
* finishes.
|
|
36
|
+
*
|
|
37
|
+
* @default os.tmpdir()
|
|
38
|
+
*/
|
|
39
|
+
tmpDir?: string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The size limit for each kind of request body, either fixed or resolved
|
|
42
|
+
* per request, so limits can follow the request itself, such as a larger
|
|
43
|
+
* allowance for an authenticated user than for a guest. Every kind is
|
|
44
|
+
* required when the option is given, so none is left unbounded by accident;
|
|
45
|
+
* set a kind to `Number.POSITIVE_INFINITY` to deliberately leave it
|
|
46
|
+
* unlimited.
|
|
47
|
+
*
|
|
48
|
+
* A resolver runs only when a body is parsed, so a request without one never
|
|
49
|
+
* pays for it, and it receives the request as it arrived, before this plugin
|
|
50
|
+
* wraps its body resolution.
|
|
51
|
+
*
|
|
52
|
+
* @default unlimited for every kind
|
|
53
|
+
*/
|
|
54
|
+
maxBodySize?: Value<Promisable<TmpFileUploadHandlerPluginMaxBodySize>, [options: StandardHandlerRoutingInterceptorOptions<T>]> | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* The size in bytes an uploaded file must exceed before it is spooled to a
|
|
57
|
+
* temporary file. Smaller files stay in memory as plain `File`s, counted
|
|
58
|
+
* against `maxBodySize.memory`, and spool anyway once they no longer fit.
|
|
59
|
+
* Set to `0` to spool every non-empty upload.
|
|
60
|
+
*
|
|
61
|
+
* @default 64 * 1024
|
|
62
|
+
*/
|
|
63
|
+
spoolThreshold?: number | undefined;
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* A `File` whose content lives in a temporary file on disk and is read lazily,
|
|
@@ -78,21 +76,14 @@ export interface TmpFileUploadHandlerPluginOptions<T extends Context> {
|
|
|
78
76
|
* @see {@link https://orpc.dev/docs/plugins/tmp-file-upload | Tmp File Upload Plugin}
|
|
79
77
|
*/
|
|
80
78
|
export declare class TmpFile extends File {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Absolute path of the temporary file holding this file's content.
|
|
91
|
-
* The file is removed when the request finishes, so move or copy it
|
|
92
|
-
* to keep the content. The `File` reads from this path, so it must
|
|
93
|
-
* not be read after the file is moved or removed.
|
|
94
|
-
*/
|
|
95
|
-
path: string, name: string, options?: FilePropertyBag);
|
|
79
|
+
/**
|
|
80
|
+
* Absolute path of the temporary file holding this file's content.
|
|
81
|
+
* The file is removed when the request finishes, so move or copy it
|
|
82
|
+
* to keep the content. The `File` reads from this path, so it must
|
|
83
|
+
* not be read after the file is moved or removed.
|
|
84
|
+
*/
|
|
85
|
+
readonly path: string;
|
|
86
|
+
constructor(blob: Blob, path: string, name: string, options?: FilePropertyBag);
|
|
96
87
|
}
|
|
97
88
|
/**
|
|
98
89
|
* Parses file uploads into temporary files instead of memory. Bodies the standard
|
|
@@ -116,27 +107,27 @@ export declare class TmpFile extends File {
|
|
|
116
107
|
* @see {@link https://orpc.dev/docs/plugins/tmp-file-upload | Tmp File Upload Plugin}
|
|
117
108
|
*/
|
|
118
109
|
export declare class TmpFileUploadHandlerPlugin<T extends Context> implements StandardHandlerPlugin<T> {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
110
|
+
name: string;
|
|
111
|
+
/**
|
|
112
|
+
* Should parse the original request body instead of batched sub-requests.
|
|
113
|
+
*/
|
|
114
|
+
after: string[];
|
|
115
|
+
/**
|
|
116
|
+
* Should run inside the limit and compression plugins, so spooling receives
|
|
117
|
+
* the size-checked, decompressed bytes.
|
|
118
|
+
*/
|
|
119
|
+
before: string[];
|
|
120
|
+
private readonly tmpDir;
|
|
121
|
+
private readonly maxBodySize;
|
|
122
|
+
private readonly spoolThreshold;
|
|
123
|
+
constructor(options?: TmpFileUploadHandlerPluginOptions<T>);
|
|
124
|
+
init(options: StandardHandlerOptions<T>): StandardHandlerOptions<T>;
|
|
125
|
+
private resolveBody;
|
|
126
|
+
/**
|
|
127
|
+
* Enforces size limits on a body the standard parser handles, counting the
|
|
128
|
+
* raw bytes before handing them back for regular parsing.
|
|
129
|
+
*/
|
|
130
|
+
private parseLimitedBody;
|
|
131
|
+
private parseFileBody;
|
|
132
|
+
private parseMultipartBody;
|
|
133
|
+
}
|