@trpc/server 11.0.0-rc.345 → 11.0.0-rc.347
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/dist/adapters/aws-lambda/content-type/json/index.js +2 -2
- package/dist/adapters/aws-lambda/content-type/json/index.mjs +2 -2
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts +8 -2
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.d.ts.map +1 -1
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.js +13 -2
- package/dist/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.mjs +13 -2
- package/dist/adapters/fastify/content-type/json/index.js +2 -2
- package/dist/adapters/fastify/content-type/json/index.mjs +2 -2
- package/dist/adapters/fetch/content-type/json/index.d.ts.map +1 -1
- package/dist/adapters/fetch/content-type/json/index.js +2 -2
- package/dist/adapters/fetch/content-type/json/index.mjs +2 -2
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +0 -7
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/form-data/index.js +16 -94
- package/dist/adapters/node-http/content-type/form-data/index.mjs +17 -75
- package/dist/adapters/node-http/content-type/json/index.js +2 -2
- package/dist/adapters/node-http/content-type/json/index.mjs +2 -2
- package/dist/adapters/node-http/content-type/octet/index.d.ts.map +1 -1
- package/dist/adapters/node-http/content-type/octet/index.js +2 -2
- package/dist/adapters/node-http/content-type/octet/index.mjs +2 -2
- package/dist/bundle-analysis.json +95 -160
- package/dist/unstable-core-do-not-import/http/contentType.d.ts +1 -1
- package/dist/unstable-core-do-not-import/http/contentType.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/adapters/aws-lambda/content-type/json/index.ts +2 -2
- package/src/adapters/content-handlers/selectContentHandlerOrUnsupportedMediaType.ts +29 -5
- package/src/adapters/fastify/content-type/json/index.ts +2 -2
- package/src/adapters/fetch/content-type/json/index.ts +2 -4
- package/src/adapters/node-http/content-type/form-data/index.ts +15 -119
- package/src/adapters/node-http/content-type/json/index.ts +2 -2
- package/src/adapters/node-http/content-type/octet/index.ts +4 -6
- package/src/unstable-core-do-not-import/http/contentType.ts +1 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -73
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.js +0 -89
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -86
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts +0 -31
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.js +0 -29
- package/dist/adapters/node-http/content-type/form-data/memoryUploadHandler.mjs +0 -27
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts +0 -16
- package/dist/adapters/node-http/content-type/form-data/streamSlice.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/streamSlice.js +0 -46
- package/dist/adapters/node-http/content-type/form-data/streamSlice.mjs +0 -44
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts +0 -45
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.js +0 -18
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -15
- package/src/adapters/node-http/content-type/form-data/fileUploadHandler.ts +0 -277
- package/src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/streamSlice.ts +0 -56
- package/src/adapters/node-http/content-type/form-data/uploadHandler.ts +0 -89
|
@@ -22,8 +22,8 @@ export const getFastifyHTTPJSONContentTypeHandler: <
|
|
|
22
22
|
TResponse extends FastifyReply,
|
|
23
23
|
>() => FastifyHTTPContentTypeHandler<TRouter, TRequest, TResponse> = () => ({
|
|
24
24
|
name: 'fastify-json',
|
|
25
|
-
isMatch(
|
|
26
|
-
return !!
|
|
25
|
+
isMatch: (headers) => {
|
|
26
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
27
27
|
},
|
|
28
28
|
getInputs: async (opts, info) => {
|
|
29
29
|
async function getRawProcedureInputOrThrow() {
|
|
@@ -18,10 +18,8 @@ export const getFetchHTTPJSONContentTypeHandler: <
|
|
|
18
18
|
TRouter extends AnyRouter,
|
|
19
19
|
>() => FetchHTTPContentTypeHandler<TRouter> = () => ({
|
|
20
20
|
name: 'fetch-json',
|
|
21
|
-
isMatch(
|
|
22
|
-
return !!
|
|
23
|
-
.get('content-type')
|
|
24
|
-
?.startsWith('application/json');
|
|
21
|
+
isMatch: (headers) => {
|
|
22
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
25
23
|
},
|
|
26
24
|
getInputs: async (opts, info) => {
|
|
27
25
|
async function getRawProcedureInputOrThrow() {
|
|
@@ -1,112 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2021 Remix Software Inc.
|
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
5
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/formData.ts
|
|
10
|
-
*/
|
|
11
|
-
import * as fs from 'fs/promises';
|
|
12
1
|
import { Readable } from 'stream';
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
14
|
-
// @ts-ignore the type definitions for this package are borked
|
|
15
|
-
import { streamMultipart } from '@web3-storage/multipart-parser';
|
|
16
2
|
// @trpc/server
|
|
17
3
|
import type { AnyRouter } from '../../../../@trpc/server';
|
|
18
4
|
import type { NodeHTTPRequest, NodeHTTPResponse } from '../../types';
|
|
19
|
-
// @trpc/server
|
|
20
5
|
import type { NodeHTTPContentTypeHandler } from '../types';
|
|
21
|
-
import { NodeOnDiskFile } from './fileUploadHandler';
|
|
22
|
-
import { createMemoryUploadHandler } from './memoryUploadHandler';
|
|
23
|
-
import type { UploadHandler, UploadHandlerPart } from './uploadHandler';
|
|
24
|
-
import { MaxBodySizeExceededError } from './uploadHandler';
|
|
25
|
-
|
|
26
|
-
const utfTextDecoder = new TextDecoder('utf-8');
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Allows you to handle multipart forms (file uploads) for your app.
|
|
30
|
-
* Request body parts with a 'filename' property will be treated as files.
|
|
31
|
-
* The rest will be treated as text.
|
|
32
|
-
* @param request The incoming Node HTTP request
|
|
33
|
-
* @param uploadHandler A function that handles file uploads and returns a value to be used in the request body. If uploaded to disk, the returned value is a NodeOnDiskFile. If uploaded to memory, the returned value is a File.
|
|
34
|
-
* @param maxBodySize The maximum size of the request body in bytes. Defaults to Infinity.
|
|
35
|
-
*
|
|
36
|
-
* @link https://remix.run/utils/parse-multipart-form-data
|
|
37
|
-
*/
|
|
38
|
-
async function parseMultipartFormData(
|
|
39
|
-
request: NodeHTTPRequest,
|
|
40
|
-
uploadHandler: UploadHandler,
|
|
41
|
-
maxBodySize = Infinity,
|
|
42
|
-
) {
|
|
43
|
-
const contentType = request.headers['content-type'] ?? '';
|
|
44
|
-
const [type, boundary] = contentType.split(/\s*;\s*boundary=/);
|
|
45
|
-
|
|
46
|
-
if (!boundary || type !== 'multipart/form-data') {
|
|
47
|
-
throw new TypeError('Could not parse content as FormData.');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const formData = new FormData();
|
|
51
|
-
const parts: AsyncIterable<UploadHandlerPart & { done?: true }> =
|
|
52
|
-
streamMultipart(Readable.toWeb(request), boundary);
|
|
53
|
-
|
|
54
|
-
let currentBodySize = 0;
|
|
55
|
-
|
|
56
|
-
const nodeOnDiskFiles: NodeOnDiskFile[] = [];
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
for await (const part of parts) {
|
|
60
|
-
if (part.done) break;
|
|
61
|
-
|
|
62
|
-
if (typeof part.filename === 'string') {
|
|
63
|
-
// This is a file, so the uploadHandler function will be called
|
|
64
|
-
|
|
65
|
-
// only pass basename as the multipart/form-data spec recommends
|
|
66
|
-
// https://datatracker.ietf.org/doc/html/rfc7578#section-4.2
|
|
67
|
-
part.filename = part.filename.split(/[/\\]/).pop();
|
|
68
|
-
const value = await uploadHandler(part as Required<typeof part>);
|
|
69
|
-
|
|
70
|
-
if (typeof value === 'undefined' || value === null) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
// add to cleanup array in case of error
|
|
74
|
-
if (value instanceof NodeOnDiskFile) {
|
|
75
|
-
nodeOnDiskFiles.push(value);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// if the combined size of the body exceeds the max size, throw an error
|
|
79
|
-
currentBodySize += value.size;
|
|
80
|
-
if (currentBodySize > maxBodySize) {
|
|
81
|
-
throw new MaxBodySizeExceededError(maxBodySize);
|
|
82
|
-
}
|
|
83
|
-
// add the file to the form data
|
|
84
|
-
formData.append(part.name, value as any);
|
|
85
|
-
} else {
|
|
86
|
-
// This is text, so we'll decode it and add it to the form data
|
|
87
|
-
let textualPart = '';
|
|
88
|
-
for await (const chunk of part.data) {
|
|
89
|
-
// if the combined size of the body exceeds the max size, throw an error
|
|
90
|
-
currentBodySize += chunk.length;
|
|
91
|
-
if (currentBodySize > maxBodySize) {
|
|
92
|
-
throw new MaxBodySizeExceededError(maxBodySize);
|
|
93
|
-
}
|
|
94
|
-
textualPart += utfTextDecoder.decode(chunk);
|
|
95
|
-
}
|
|
96
|
-
// add the text to the form data
|
|
97
|
-
formData.append(part.name, textualPart);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return formData;
|
|
102
|
-
} catch (e) {
|
|
103
|
-
// clean up any files that were uploaded to disk if an error occurs
|
|
104
|
-
await Promise.all(
|
|
105
|
-
nodeOnDiskFiles.map((file) => fs.unlink(file.getFilePath())),
|
|
106
|
-
);
|
|
107
|
-
throw e;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
6
|
|
|
111
7
|
export const getFormDataContentTypeHandler: <
|
|
112
8
|
TRouter extends AnyRouter,
|
|
@@ -114,28 +10,28 @@ export const getFormDataContentTypeHandler: <
|
|
|
114
10
|
TResponse extends NodeHTTPResponse,
|
|
115
11
|
>() => NodeHTTPContentTypeHandler<TRouter, TRequest, TResponse> = () => ({
|
|
116
12
|
name: 'node-http-formdata',
|
|
117
|
-
isMatch(
|
|
118
|
-
return (
|
|
119
|
-
opts.req.headers['content-type']?.startsWith('multipart/form-data') ??
|
|
120
|
-
false
|
|
121
|
-
);
|
|
13
|
+
isMatch: (headers) => {
|
|
14
|
+
return !!headers.get('content-type')?.startsWith('multipart/form-data');
|
|
122
15
|
},
|
|
123
16
|
async getInputs(opts, inputOpts) {
|
|
124
17
|
if (inputOpts.isBatchCall) {
|
|
125
18
|
throw new Error('Batch calls not supported for form-data');
|
|
126
19
|
}
|
|
127
20
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
21
|
+
const contentType = opts.req.headers['content-type'];
|
|
22
|
+
if (!contentType) {
|
|
23
|
+
// Should be unreachable given the isMatch check
|
|
24
|
+
throw new Error('No content-type header found');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const form = await new Request('https://unused.com', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: { 'content-type': contentType },
|
|
30
|
+
body: Readable.toWeb(opts.req) as ReadableStream,
|
|
31
|
+
// @ts-expect-error - outdated types? this exists
|
|
32
|
+
duplex: 'half',
|
|
33
|
+
}).formData();
|
|
132
34
|
|
|
133
35
|
return form;
|
|
134
36
|
},
|
|
135
37
|
});
|
|
136
|
-
|
|
137
|
-
export {
|
|
138
|
-
MaxBodySizeExceededError,
|
|
139
|
-
MaxPartSizeExceededError,
|
|
140
|
-
type UploadHandler,
|
|
141
|
-
} from './uploadHandler';
|
|
@@ -14,8 +14,8 @@ export const getNodeHTTPJSONContentTypeHandler: <
|
|
|
14
14
|
TResponse extends NodeHTTPResponse,
|
|
15
15
|
>() => NodeHTTPContentTypeHandler<TRouter, TRequest, TResponse> = () => ({
|
|
16
16
|
name: 'node-http-json',
|
|
17
|
-
isMatch(
|
|
18
|
-
return !!
|
|
17
|
+
isMatch: (headers) => {
|
|
18
|
+
return !!headers.get('content-type')?.startsWith('application/json');
|
|
19
19
|
},
|
|
20
20
|
getInputs: async (opts, info) => {
|
|
21
21
|
const bodyResult = await getPostBody(opts);
|
|
@@ -10,12 +10,10 @@ export const getOctetContentTypeHandler: <
|
|
|
10
10
|
TResponse extends NodeHTTPResponse,
|
|
11
11
|
>() => NodeHTTPContentTypeHandler<TRouter, TRequest, TResponse> = () => ({
|
|
12
12
|
name: 'node-http-octet',
|
|
13
|
-
isMatch(
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
) ?? false
|
|
18
|
-
);
|
|
13
|
+
isMatch: (headers) => {
|
|
14
|
+
return !!headers
|
|
15
|
+
.get('content-type')
|
|
16
|
+
?.startsWith('application/octet-stream');
|
|
19
17
|
},
|
|
20
18
|
async getInputs(opts, inputOpts) {
|
|
21
19
|
if (inputOpts.isBatchCall) {
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { UploadHandler } from './uploadHandler';
|
|
3
|
-
export declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
|
|
4
|
-
export type FileUploadHandlerFilterArgs = {
|
|
5
|
-
filename: string;
|
|
6
|
-
contentType: string;
|
|
7
|
-
name: string;
|
|
8
|
-
};
|
|
9
|
-
export type FileUploadHandlerPathResolverArgs = {
|
|
10
|
-
filename: string;
|
|
11
|
-
contentType: string;
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Chooses the path of the file to be uploaded. If a string is not
|
|
16
|
-
* returned the file will not be written.
|
|
17
|
-
*/
|
|
18
|
-
export type FileUploadHandlerPathResolver = (args: FileUploadHandlerPathResolverArgs) => string | undefined;
|
|
19
|
-
export type FileUploadHandlerOptions = {
|
|
20
|
-
/**
|
|
21
|
-
* Avoid file conflicts by appending a count on the end of the filename
|
|
22
|
-
* if it already exists on disk. Defaults to `true`.
|
|
23
|
-
*/
|
|
24
|
-
avoidFileConflicts?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* The directory to write the upload.
|
|
27
|
-
*/
|
|
28
|
-
directory?: FileUploadHandlerPathResolver | string;
|
|
29
|
-
/**
|
|
30
|
-
* The name of the file in the directory. Can be a relative path, the directory
|
|
31
|
-
* structure will be created if it does not exist.
|
|
32
|
-
*/
|
|
33
|
-
file?: FileUploadHandlerPathResolver;
|
|
34
|
-
/**
|
|
35
|
-
* The maximum upload size allowed. If the size is exceeded an error will be thrown.
|
|
36
|
-
* Defaults to 3000000B (3MB).
|
|
37
|
-
*/
|
|
38
|
-
maxPartSize?: number;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* @param filename
|
|
42
|
-
* @param contentType
|
|
43
|
-
* @param name
|
|
44
|
-
*/
|
|
45
|
-
filter?(args: FileUploadHandlerFilterArgs): Promise<boolean> | boolean;
|
|
46
|
-
};
|
|
47
|
-
export declare function createFileUploadHandler({ directory, avoidFileConflicts, file, filter, maxPartSize, }?: FileUploadHandlerOptions): UploadHandler;
|
|
48
|
-
type NodeJSReadableStreamEsque = {
|
|
49
|
-
on(eventName: string | symbol, listener: (...args: any[]) => void): NodeJSReadableStreamEsque;
|
|
50
|
-
};
|
|
51
|
-
export declare class NodeOnDiskFile {
|
|
52
|
-
private filepath;
|
|
53
|
-
type: string;
|
|
54
|
-
private slicer?;
|
|
55
|
-
name: string;
|
|
56
|
-
lastModified: number;
|
|
57
|
-
webkitRelativePath: string;
|
|
58
|
-
constructor(filepath: string, type: string, slicer?: {
|
|
59
|
-
start: number;
|
|
60
|
-
end: number;
|
|
61
|
-
} | undefined);
|
|
62
|
-
get size(): number;
|
|
63
|
-
slice(start?: number, end?: number, type?: string): NodeOnDiskFile;
|
|
64
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
65
|
-
stream(): ReadableStream<any>;
|
|
66
|
-
stream(): NodeJSReadableStreamEsque;
|
|
67
|
-
text(): Promise<string>;
|
|
68
|
-
readonly [Symbol.toStringTag] = "File";
|
|
69
|
-
remove(): Promise<void>;
|
|
70
|
-
getFilePath(): string;
|
|
71
|
-
}
|
|
72
|
-
export {};
|
|
73
|
-
//# sourceMappingURL=fileUploadHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fileUploadHandler.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/fileUploadHandler.ts"],"names":[],"mappings":";AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,QAAQ,CAAC,EAAE,cAAc,mBAoB1B;AAED,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAC1C,IAAI,EAAE,iCAAiC,KACpC,MAAM,GAAG,SAAS,CAAC;AAExB,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,SAAS,CAAC,EAAE,6BAA6B,GAAG,MAAM,CAAC;IACnD;;;OAGG;IACH,IAAI,CAAC,EAAE,6BAA6B,CAAC;IACrC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,MAAM,CAAC,CAAC,IAAI,EAAE,2BAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACxE,CAAC;AA4BF,wBAAgB,uBAAuB,CAAC,EACtC,SAAoB,EACpB,kBAAyB,EACzB,IAA8B,EAC9B,MAAM,EACN,WAAqB,GACtB,GAAE,wBAA6B,GAAG,aAAa,CAyD/C;AACD,KAAK,yBAAyB,GAAG;IAC/B,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAEF,qBAAa,cAAc;IAMvB,OAAO,CAAC,QAAQ;IACT,IAAI,EAAE,MAAM;IACnB,OAAO,CAAC,MAAM,CAAC;IAPjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,SAAK;IACjB,kBAAkB,SAAM;gBAGd,QAAQ,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACX,MAAM,CAAC;eAAW,MAAM;aAAO,MAAM;iBAAE;IAKjD,IAAI,IAAI,IAAI,MAAM,CASjB;IAED,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,cAAc;IAkB5D,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAkBzC,MAAM,IAAI,cAAc,CAAC,GAAG,CAAC;IAC7B,MAAM,IAAI,yBAAyB;IAU7B,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B,SAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU;IAE9C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAGvB,WAAW,IAAI,MAAM;CAGtB"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_fs = require('node:fs');
|
|
4
|
-
var fs = require('node:fs/promises');
|
|
5
|
-
var node_path = require('node:path');
|
|
6
|
-
var node_stream = require('node:stream');
|
|
7
|
-
var streamSlice = require('./streamSlice.js');
|
|
8
|
-
|
|
9
|
-
async function readableStreamToString(stream, encoding) {
|
|
10
|
-
const reader = stream.getReader();
|
|
11
|
-
const chunks = [];
|
|
12
|
-
async function read() {
|
|
13
|
-
const { done , value } = await reader.read();
|
|
14
|
-
if (done) {
|
|
15
|
-
return;
|
|
16
|
-
} else if (value) {
|
|
17
|
-
chunks.push(value);
|
|
18
|
-
}
|
|
19
|
-
await read();
|
|
20
|
-
}
|
|
21
|
-
await read();
|
|
22
|
-
return Buffer.concat(chunks).toString(encoding);
|
|
23
|
-
}
|
|
24
|
-
let _toStringTag = Symbol.toStringTag;
|
|
25
|
-
class NodeOnDiskFile {
|
|
26
|
-
get size() {
|
|
27
|
-
const stats = node_fs.statSync(this.filepath);
|
|
28
|
-
if (this.slicer) {
|
|
29
|
-
const slice = this.slicer.end - this.slicer.start;
|
|
30
|
-
return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
|
|
31
|
-
}
|
|
32
|
-
return stats.size;
|
|
33
|
-
}
|
|
34
|
-
slice(start, end, type) {
|
|
35
|
-
if (typeof start === 'number' && start < 0) start = this.size + start;
|
|
36
|
-
if (typeof end === 'number' && end < 0) end = this.size + end;
|
|
37
|
-
const startOffset = this.slicer?.start ?? 0;
|
|
38
|
-
start = startOffset + (start ?? 0);
|
|
39
|
-
end = startOffset + (end ?? this.size);
|
|
40
|
-
return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
|
|
41
|
-
start,
|
|
42
|
-
end
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async arrayBuffer() {
|
|
46
|
-
let stream = node_fs.createReadStream(this.filepath);
|
|
47
|
-
if (this.slicer) {
|
|
48
|
-
stream = stream.pipe(streamSlice.streamSlice(this.slicer.start, this.slicer.end));
|
|
49
|
-
}
|
|
50
|
-
return new Promise((resolve, reject)=>{
|
|
51
|
-
const buf = [];
|
|
52
|
-
stream.on('data', (chunk)=>buf.push(chunk));
|
|
53
|
-
stream.on('end', ()=>{
|
|
54
|
-
resolve(Buffer.concat(buf));
|
|
55
|
-
});
|
|
56
|
-
stream.on('error', (err)=>{
|
|
57
|
-
reject(err);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
stream() {
|
|
62
|
-
let stream = node_fs.createReadStream(this.filepath);
|
|
63
|
-
if (this.slicer) {
|
|
64
|
-
stream = stream.pipe(streamSlice.streamSlice(this.slicer.start, this.slicer.end));
|
|
65
|
-
}
|
|
66
|
-
return node_stream.Readable.toWeb(stream);
|
|
67
|
-
}
|
|
68
|
-
async text() {
|
|
69
|
-
return readableStreamToString(this.stream());
|
|
70
|
-
}
|
|
71
|
-
remove() {
|
|
72
|
-
return fs.unlink(this.filepath);
|
|
73
|
-
}
|
|
74
|
-
getFilePath() {
|
|
75
|
-
return this.filepath;
|
|
76
|
-
}
|
|
77
|
-
constructor(filepath, type, slicer){
|
|
78
|
-
this.filepath = filepath;
|
|
79
|
-
this.type = type;
|
|
80
|
-
this.slicer = slicer;
|
|
81
|
-
this.lastModified = 0;
|
|
82
|
-
this.webkitRelativePath = '';
|
|
83
|
-
this[_toStringTag] = 'File';
|
|
84
|
-
this.name = node_path.basename(filepath);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
exports.NodeOnDiskFile = NodeOnDiskFile;
|
|
89
|
-
exports.readableStreamToString = readableStreamToString;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { statSync, createReadStream } from 'node:fs';
|
|
2
|
-
import { unlink } from 'node:fs/promises';
|
|
3
|
-
import { basename } from 'node:path';
|
|
4
|
-
import { Readable } from 'node:stream';
|
|
5
|
-
import { streamSlice } from './streamSlice.mjs';
|
|
6
|
-
|
|
7
|
-
async function readableStreamToString(stream, encoding) {
|
|
8
|
-
const reader = stream.getReader();
|
|
9
|
-
const chunks = [];
|
|
10
|
-
async function read() {
|
|
11
|
-
const { done , value } = await reader.read();
|
|
12
|
-
if (done) {
|
|
13
|
-
return;
|
|
14
|
-
} else if (value) {
|
|
15
|
-
chunks.push(value);
|
|
16
|
-
}
|
|
17
|
-
await read();
|
|
18
|
-
}
|
|
19
|
-
await read();
|
|
20
|
-
return Buffer.concat(chunks).toString(encoding);
|
|
21
|
-
}
|
|
22
|
-
let _toStringTag = Symbol.toStringTag;
|
|
23
|
-
class NodeOnDiskFile {
|
|
24
|
-
get size() {
|
|
25
|
-
const stats = statSync(this.filepath);
|
|
26
|
-
if (this.slicer) {
|
|
27
|
-
const slice = this.slicer.end - this.slicer.start;
|
|
28
|
-
return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
|
|
29
|
-
}
|
|
30
|
-
return stats.size;
|
|
31
|
-
}
|
|
32
|
-
slice(start, end, type) {
|
|
33
|
-
if (typeof start === 'number' && start < 0) start = this.size + start;
|
|
34
|
-
if (typeof end === 'number' && end < 0) end = this.size + end;
|
|
35
|
-
const startOffset = this.slicer?.start ?? 0;
|
|
36
|
-
start = startOffset + (start ?? 0);
|
|
37
|
-
end = startOffset + (end ?? this.size);
|
|
38
|
-
return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
|
|
39
|
-
start,
|
|
40
|
-
end
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async arrayBuffer() {
|
|
44
|
-
let stream = createReadStream(this.filepath);
|
|
45
|
-
if (this.slicer) {
|
|
46
|
-
stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
|
|
47
|
-
}
|
|
48
|
-
return new Promise((resolve, reject)=>{
|
|
49
|
-
const buf = [];
|
|
50
|
-
stream.on('data', (chunk)=>buf.push(chunk));
|
|
51
|
-
stream.on('end', ()=>{
|
|
52
|
-
resolve(Buffer.concat(buf));
|
|
53
|
-
});
|
|
54
|
-
stream.on('error', (err)=>{
|
|
55
|
-
reject(err);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
stream() {
|
|
60
|
-
let stream = createReadStream(this.filepath);
|
|
61
|
-
if (this.slicer) {
|
|
62
|
-
stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
|
|
63
|
-
}
|
|
64
|
-
return Readable.toWeb(stream);
|
|
65
|
-
}
|
|
66
|
-
async text() {
|
|
67
|
-
return readableStreamToString(this.stream());
|
|
68
|
-
}
|
|
69
|
-
remove() {
|
|
70
|
-
return unlink(this.filepath);
|
|
71
|
-
}
|
|
72
|
-
getFilePath() {
|
|
73
|
-
return this.filepath;
|
|
74
|
-
}
|
|
75
|
-
constructor(filepath, type, slicer){
|
|
76
|
-
this.filepath = filepath;
|
|
77
|
-
this.type = type;
|
|
78
|
-
this.slicer = slicer;
|
|
79
|
-
this.lastModified = 0;
|
|
80
|
-
this.webkitRelativePath = '';
|
|
81
|
-
this[_toStringTag] = 'File';
|
|
82
|
-
this.name = basename(filepath);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export { NodeOnDiskFile, readableStreamToString };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2021 Remix Software Inc.
|
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
5
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* @link https://github.com/remix-run/remix/blob/0bcb4a304dd2f08f6032c3bf0c3aa7eb5b976901/packages/remix-server-runtime/upload/memoryUploadHandler.ts
|
|
9
|
-
*/
|
|
10
|
-
import type { UploadHandler } from './uploadHandler';
|
|
11
|
-
export type MemoryUploadHandlerFilterArgs = {
|
|
12
|
-
filename?: string;
|
|
13
|
-
contentType: string;
|
|
14
|
-
name: string;
|
|
15
|
-
};
|
|
16
|
-
export type MemoryUploadHandlerOptions = {
|
|
17
|
-
/**
|
|
18
|
-
* The maximum upload size allowed. If the size is exceeded an error will be thrown.
|
|
19
|
-
* Defaults to 3000000B (3MB).
|
|
20
|
-
*/
|
|
21
|
-
maxPartSize?: number;
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param filename
|
|
25
|
-
* @param mimetype
|
|
26
|
-
* @param encoding
|
|
27
|
-
*/
|
|
28
|
-
filter?(args: MemoryUploadHandlerFilterArgs): Promise<boolean> | boolean;
|
|
29
|
-
};
|
|
30
|
-
export declare function createMemoryUploadHandler({ filter, maxPartSize, }?: MemoryUploadHandlerOptions): UploadHandler;
|
|
31
|
-
//# sourceMappingURL=memoryUploadHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoryUploadHandler.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/memoryUploadHandler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,MAAM,CAAC,CAAC,IAAI,EAAE,6BAA6B,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC1E,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,EACxC,MAAM,EACN,WAAqB,GACtB,GAAE,0BAA+B,GAAG,aAAa,CAkBjD"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var uploadHandler = require('./uploadHandler.js');
|
|
4
|
-
|
|
5
|
-
function createMemoryUploadHandler({ filter , maxPartSize =3000000 } = {}) {
|
|
6
|
-
return async ({ filename , contentType , name , data })=>{
|
|
7
|
-
if (filter && !await filter({
|
|
8
|
-
filename,
|
|
9
|
-
contentType,
|
|
10
|
-
name
|
|
11
|
-
})) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
let size = 0;
|
|
15
|
-
const chunks = [];
|
|
16
|
-
for await (const chunk of data){
|
|
17
|
-
size += chunk.byteLength;
|
|
18
|
-
if (size > maxPartSize) {
|
|
19
|
-
throw new uploadHandler.MaxPartSizeExceededError(name, maxPartSize);
|
|
20
|
-
}
|
|
21
|
-
chunks.push(chunk);
|
|
22
|
-
}
|
|
23
|
-
return new File(chunks, filename, {
|
|
24
|
-
type: contentType
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
exports.createMemoryUploadHandler = createMemoryUploadHandler;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { MaxPartSizeExceededError } from './uploadHandler.mjs';
|
|
2
|
-
|
|
3
|
-
function createMemoryUploadHandler({ filter , maxPartSize =3000000 } = {}) {
|
|
4
|
-
return async ({ filename , contentType , name , data })=>{
|
|
5
|
-
if (filter && !await filter({
|
|
6
|
-
filename,
|
|
7
|
-
contentType,
|
|
8
|
-
name
|
|
9
|
-
})) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
let size = 0;
|
|
13
|
-
const chunks = [];
|
|
14
|
-
for await (const chunk of data){
|
|
15
|
-
size += chunk.byteLength;
|
|
16
|
-
if (size > maxPartSize) {
|
|
17
|
-
throw new MaxPartSizeExceededError(name, maxPartSize);
|
|
18
|
-
}
|
|
19
|
-
chunks.push(chunk);
|
|
20
|
-
}
|
|
21
|
-
return new File(chunks, filename, {
|
|
22
|
-
type: contentType
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { createMemoryUploadHandler };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import type { TransformCallback } from 'stream';
|
|
4
|
-
import { Transform } from 'stream';
|
|
5
|
-
declare class SliceStream extends Transform {
|
|
6
|
-
private startIndex;
|
|
7
|
-
private endIndex;
|
|
8
|
-
private indexOffset;
|
|
9
|
-
private emitUp;
|
|
10
|
-
private emitDown;
|
|
11
|
-
constructor(startIndex?: number, endIndex?: number);
|
|
12
|
-
_transform(chunk: any, _: BufferEncoding, done: TransformCallback): void;
|
|
13
|
-
}
|
|
14
|
-
export declare function streamSlice(startIndex?: number, endIndex?: number): SliceStream;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=streamSlice.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streamSlice.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/streamSlice.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,cAAM,WAAY,SAAQ,SAAS;IAKrB,OAAO,CAAC,UAAU;IAAM,OAAO,CAAC,QAAQ;IAJpD,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;gBAEL,UAAU,SAAI,EAAU,QAAQ,SAAW;IAItD,UAAU,CACjB,KAAK,EAAE,GAAG,EACV,CAAC,EAAE,cAAc,EACjB,IAAI,EAAE,iBAAiB,GACtB,IAAI;CAmCR;AAED,wBAAgB,WAAW,CAAC,UAAU,SAAI,EAAE,QAAQ,SAAW,GAAG,WAAW,CAE5E"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_stream = require('node:stream');
|
|
4
|
-
|
|
5
|
-
class SliceStream extends node_stream.Transform {
|
|
6
|
-
_transform(chunk, _, done) {
|
|
7
|
-
this.indexOffset += chunk.length;
|
|
8
|
-
if (!this.emitUp && this.indexOffset >= this.startIndex) {
|
|
9
|
-
this.emitUp = true;
|
|
10
|
-
const start = chunk.length - (this.indexOffset - this.startIndex);
|
|
11
|
-
if (this.indexOffset > this.endIndex) {
|
|
12
|
-
const end = chunk.length - (this.indexOffset - this.endIndex);
|
|
13
|
-
this.emitDown = true;
|
|
14
|
-
this.push(chunk.slice(start, end));
|
|
15
|
-
} else {
|
|
16
|
-
this.push(chunk.slice(start, chunk.length));
|
|
17
|
-
}
|
|
18
|
-
done();
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (this.emitUp && !this.emitDown) {
|
|
22
|
-
if (this.indexOffset >= this.endIndex) {
|
|
23
|
-
this.emitDown = true;
|
|
24
|
-
this.push(chunk.slice(0, chunk.length - (this.indexOffset - this.endIndex)));
|
|
25
|
-
} else {
|
|
26
|
-
this.push(chunk);
|
|
27
|
-
}
|
|
28
|
-
done();
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
done();
|
|
32
|
-
}
|
|
33
|
-
constructor(startIndex = 0, endIndex = Infinity){
|
|
34
|
-
super();
|
|
35
|
-
this.startIndex = startIndex;
|
|
36
|
-
this.endIndex = endIndex;
|
|
37
|
-
this.indexOffset = 0;
|
|
38
|
-
this.emitUp = false;
|
|
39
|
-
this.emitDown = false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function streamSlice(startIndex = 0, endIndex = Infinity) {
|
|
43
|
-
return new SliceStream(startIndex, endIndex);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.streamSlice = streamSlice;
|