@trpc/server 11.0.0-alpha-tmp-export-from-main.221 → 11.0.0-alpha-tmp-export-from-main.222
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/index.d.mts +68 -0
- package/dist/adapters/aws-lambda/index.d.ts +54 -6
- package/dist/adapters/aws-lambda/index.js +110 -20
- package/dist/adapters/aws-lambda/index.mjs +94 -4
- package/dist/adapters/express.d.mts +19 -0
- package/dist/adapters/express.d.ts +9 -6
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/express.mjs +1 -1
- package/dist/adapters/fastify/index.d.mts +33 -0
- package/dist/adapters/fastify/index.d.ts +33 -3
- package/dist/adapters/fastify/index.js +124 -5
- package/dist/adapters/fastify/index.mjs +125 -2
- package/dist/adapters/fetch/index.d.mts +51 -0
- package/dist/adapters/fetch/index.d.ts +51 -3
- package/dist/adapters/fetch/index.js +115 -4
- package/dist/adapters/fetch/index.mjs +116 -1
- package/dist/adapters/next.d.mts +21 -0
- package/dist/adapters/next.d.ts +11 -7
- package/dist/adapters/next.js +6 -6
- package/dist/adapters/next.mjs +2 -2
- package/dist/adapters/node-http/content-type/form-data/index.d.mts +219 -0
- package/dist/adapters/node-http/content-type/form-data/index.d.ts +201 -10
- package/dist/adapters/node-http/content-type/form-data/index.js +662 -23
- package/dist/adapters/node-http/content-type/form-data/index.mjs +646 -10
- package/dist/adapters/node-http/{types.d.ts → content-type/json/index.d.mts} +21 -15
- package/dist/adapters/node-http/content-type/json/index.d.ts +89 -2
- package/dist/adapters/node-http/content-type/json/index.js +48 -7
- package/dist/adapters/node-http/content-type/json/index.mjs +44 -3
- package/dist/adapters/node-http/index.d.mts +100 -0
- package/dist/adapters/node-http/index.d.ts +100 -3
- package/dist/adapters/node-http/index.js +106 -4
- package/dist/adapters/node-http/index.mjs +107 -1
- package/dist/adapters/standalone.d.mts +21 -0
- package/dist/adapters/standalone.d.ts +11 -9
- package/dist/adapters/standalone.js +9 -5
- package/dist/adapters/standalone.mjs +2 -2
- package/dist/adapters/ws.d.mts +36 -0
- package/dist/adapters/ws.d.ts +12 -13
- package/dist/adapters/ws.js +30 -28
- package/dist/adapters/ws.mjs +12 -10
- package/dist/http.d.mts +1 -0
- package/dist/http.d.ts +1 -7
- package/dist/http.js +7 -7
- package/dist/http.mjs +1 -1
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +5 -65
- package/dist/index.js +809 -46
- package/dist/index.mjs +798 -1
- package/dist/observable.d.mts +1 -0
- package/dist/observable.d.ts +1 -3
- package/dist/observable.js +8 -8
- package/dist/observable.mjs +1 -1
- package/dist/rpc.d.mts +1 -0
- package/dist/rpc.d.ts +1 -3
- package/dist/rpc.js +5 -5
- package/dist/rpc.mjs +1 -1
- package/dist/shared.d.mts +1 -0
- package/dist/shared.d.ts +1 -26
- package/dist/shared.js +4 -4
- package/dist/shared.mjs +1 -1
- package/dist/unstableDontImportMe.d.mts +1 -0
- package/dist/unstableDontImportMe.d.ts +1 -10
- package/dist/unstableDontImportMe.js +1549 -142
- package/dist/unstableDontImportMe.mjs +1514 -1
- package/package.json +6 -4
- package/dist/@trpc-server/http.d.ts +0 -2
- package/dist/@trpc-server/http.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/index.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.d.ts +0 -48
- package/dist/adapters/aws-lambda/utils.d.ts.map +0 -1
- package/dist/adapters/aws-lambda/utils.js +0 -100
- package/dist/adapters/aws-lambda/utils.mjs +0 -93
- package/dist/adapters/express.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts +0 -13
- package/dist/adapters/fastify/fastifyRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyRequestHandler.js +0 -81
- package/dist/adapters/fastify/fastifyRequestHandler.mjs +0 -79
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts +0 -22
- package/dist/adapters/fastify/fastifyTRPCPlugin.d.ts.map +0 -1
- package/dist/adapters/fastify/fastifyTRPCPlugin.js +0 -51
- package/dist/adapters/fastify/fastifyTRPCPlugin.mjs +0 -49
- package/dist/adapters/fastify/index.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.d.ts +0 -18
- package/dist/adapters/fetch/fetchRequestHandler.d.ts.map +0 -1
- package/dist/adapters/fetch/fetchRequestHandler.js +0 -118
- package/dist/adapters/fetch/fetchRequestHandler.mjs +0 -116
- package/dist/adapters/fetch/index.d.ts.map +0 -1
- package/dist/adapters/fetch/types.d.ts +0 -31
- package/dist/adapters/fetch/types.d.ts.map +0 -1
- package/dist/adapters/next.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.d.ts +0 -70
- 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 -161
- package/dist/adapters/node-http/content-type/form-data/fileUploadHandler.mjs +0 -157
- package/dist/adapters/node-http/content-type/form-data/index.d.ts.map +0 -1
- 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 -30
- package/dist/adapters/node-http/content-type/form-data/uploadHandler.mjs +0 -26
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts +0 -7
- package/dist/adapters/node-http/content-type/json/getPostBody.d.ts.map +0 -1
- package/dist/adapters/node-http/content-type/json/getPostBody.js +0 -42
- package/dist/adapters/node-http/content-type/json/getPostBody.mjs +0 -40
- package/dist/adapters/node-http/content-type/json/index.d.ts.map +0 -1
- package/dist/adapters/node-http/index.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.d.ts +0 -9
- package/dist/adapters/node-http/internals/contentType.d.ts.map +0 -1
- package/dist/adapters/node-http/internals/contentType.js +0 -8
- package/dist/adapters/node-http/internals/contentType.mjs +0 -6
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts +0 -14
- package/dist/adapters/node-http/nodeHTTPRequestHandler.d.ts.map +0 -1
- package/dist/adapters/node-http/nodeHTTPRequestHandler.js +0 -109
- package/dist/adapters/node-http/nodeHTTPRequestHandler.mjs +0 -107
- package/dist/adapters/node-http/types.d.ts.map +0 -1
- package/dist/adapters/standalone.d.ts.map +0 -1
- package/dist/adapters/ws.d.ts.map +0 -1
- package/dist/http.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.js +0 -203
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/index.mjs +0 -201
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.js +0 -167
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/search.mjs +0 -163
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.js +0 -35
- package/dist/node_modules/.pnpm/@web3-storage_multipart-parser@1.0.0/node_modules/@web3-storage/multipart-parser/esm/src/utils.mjs +0 -30
- package/dist/observable.d.ts.map +0 -1
- package/dist/rpc.d.ts.map +0 -1
- package/dist/shared.d.ts.map +0 -1
- package/dist/unstableDontImportMe.d.ts.map +0 -1
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@trpc/core');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
7
|
-
*
|
|
8
|
-
* Do **not** import from `@trpc/core`
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
12
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
13
|
-
* ```
|
|
14
|
-
*/ // @trpc/server
|
|
15
|
-
const trimSlashes = (path)=>{
|
|
16
|
-
path = path.startsWith('/') ? path.slice(1) : path;
|
|
17
|
-
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
18
|
-
return path;
|
|
19
|
-
};
|
|
20
|
-
async function fetchRequestHandler(opts) {
|
|
21
|
-
const resHeaders = new Headers();
|
|
22
|
-
const createContext = async (innerOpts)=>{
|
|
23
|
-
return opts.createContext?.({
|
|
24
|
-
req: opts.req,
|
|
25
|
-
resHeaders,
|
|
26
|
-
...innerOpts
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
const url = new URL(opts.req.url);
|
|
30
|
-
const pathname = trimSlashes(url.pathname);
|
|
31
|
-
const endpoint = trimSlashes(opts.endpoint);
|
|
32
|
-
const path = trimSlashes(pathname.slice(endpoint.length));
|
|
33
|
-
const req = {
|
|
34
|
-
query: url.searchParams,
|
|
35
|
-
method: opts.req.method,
|
|
36
|
-
headers: Object.fromEntries(opts.req.headers),
|
|
37
|
-
body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
|
|
38
|
-
};
|
|
39
|
-
let resolve;
|
|
40
|
-
const promise = new Promise((r)=>resolve = r);
|
|
41
|
-
let status = 200;
|
|
42
|
-
let isStream = false;
|
|
43
|
-
let controller;
|
|
44
|
-
let encoder;
|
|
45
|
-
let formatter;
|
|
46
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
47
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
48
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (typeof value === 'string') {
|
|
52
|
-
resHeaders.set(key, value);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
for (const v of value){
|
|
56
|
-
resHeaders.append(key, v);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
status = head.status;
|
|
60
|
-
if (isStreaming) {
|
|
61
|
-
resHeaders.set('Transfer-Encoding', 'chunked');
|
|
62
|
-
resHeaders.append('Vary', 'trpc-batch-mode');
|
|
63
|
-
const stream = new ReadableStream({
|
|
64
|
-
start (c) {
|
|
65
|
-
controller = c;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
const response = new Response(stream, {
|
|
69
|
-
status,
|
|
70
|
-
headers: resHeaders
|
|
71
|
-
});
|
|
72
|
-
resolve(response);
|
|
73
|
-
encoder = new TextEncoder();
|
|
74
|
-
formatter = core.getBatchStreamFormatter();
|
|
75
|
-
isStream = true;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
const unstable_onChunk = ([index, string])=>{
|
|
79
|
-
if (index === -1) {
|
|
80
|
-
// full response, no streaming
|
|
81
|
-
const response = new Response(string || null, {
|
|
82
|
-
status,
|
|
83
|
-
headers: resHeaders
|
|
84
|
-
});
|
|
85
|
-
resolve(response);
|
|
86
|
-
} else {
|
|
87
|
-
controller.enqueue(encoder.encode(formatter(index, string)));
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
core.resolveHTTPResponse({
|
|
91
|
-
req,
|
|
92
|
-
createContext,
|
|
93
|
-
path,
|
|
94
|
-
router: opts.router,
|
|
95
|
-
batching: opts.batching,
|
|
96
|
-
responseMeta: opts.responseMeta,
|
|
97
|
-
onError (o) {
|
|
98
|
-
opts?.onError?.({
|
|
99
|
-
...o,
|
|
100
|
-
req: opts.req
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
unstable_onHead,
|
|
104
|
-
unstable_onChunk
|
|
105
|
-
}).then(()=>{
|
|
106
|
-
if (isStream) {
|
|
107
|
-
controller.enqueue(encoder.encode(formatter.end()));
|
|
108
|
-
controller.close();
|
|
109
|
-
}
|
|
110
|
-
}).catch(()=>{
|
|
111
|
-
if (isStream) {
|
|
112
|
-
controller.close();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return promise;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
exports.fetchRequestHandler = fetchRequestHandler;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { resolveHTTPResponse, getBatchStreamFormatter } from '@trpc/core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
5
|
-
*
|
|
6
|
-
* Do **not** import from `@trpc/core`
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
10
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
11
|
-
* ```
|
|
12
|
-
*/ // @trpc/server
|
|
13
|
-
const trimSlashes = (path)=>{
|
|
14
|
-
path = path.startsWith('/') ? path.slice(1) : path;
|
|
15
|
-
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
16
|
-
return path;
|
|
17
|
-
};
|
|
18
|
-
async function fetchRequestHandler(opts) {
|
|
19
|
-
const resHeaders = new Headers();
|
|
20
|
-
const createContext = async (innerOpts)=>{
|
|
21
|
-
return opts.createContext?.({
|
|
22
|
-
req: opts.req,
|
|
23
|
-
resHeaders,
|
|
24
|
-
...innerOpts
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const url = new URL(opts.req.url);
|
|
28
|
-
const pathname = trimSlashes(url.pathname);
|
|
29
|
-
const endpoint = trimSlashes(opts.endpoint);
|
|
30
|
-
const path = trimSlashes(pathname.slice(endpoint.length));
|
|
31
|
-
const req = {
|
|
32
|
-
query: url.searchParams,
|
|
33
|
-
method: opts.req.method,
|
|
34
|
-
headers: Object.fromEntries(opts.req.headers),
|
|
35
|
-
body: opts.req.headers.get('content-type')?.startsWith('application/json') ? await opts.req.text() : ''
|
|
36
|
-
};
|
|
37
|
-
let resolve;
|
|
38
|
-
const promise = new Promise((r)=>resolve = r);
|
|
39
|
-
let status = 200;
|
|
40
|
-
let isStream = false;
|
|
41
|
-
let controller;
|
|
42
|
-
let encoder;
|
|
43
|
-
let formatter;
|
|
44
|
-
const unstable_onHead = (head, isStreaming)=>{
|
|
45
|
-
for (const [key, value] of Object.entries(head.headers ?? {})){
|
|
46
|
-
/* istanbul ignore if -- @preserve */ if (typeof value === 'undefined') {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (typeof value === 'string') {
|
|
50
|
-
resHeaders.set(key, value);
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
for (const v of value){
|
|
54
|
-
resHeaders.append(key, v);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
status = head.status;
|
|
58
|
-
if (isStreaming) {
|
|
59
|
-
resHeaders.set('Transfer-Encoding', 'chunked');
|
|
60
|
-
resHeaders.append('Vary', 'trpc-batch-mode');
|
|
61
|
-
const stream = new ReadableStream({
|
|
62
|
-
start (c) {
|
|
63
|
-
controller = c;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
const response = new Response(stream, {
|
|
67
|
-
status,
|
|
68
|
-
headers: resHeaders
|
|
69
|
-
});
|
|
70
|
-
resolve(response);
|
|
71
|
-
encoder = new TextEncoder();
|
|
72
|
-
formatter = getBatchStreamFormatter();
|
|
73
|
-
isStream = true;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const unstable_onChunk = ([index, string])=>{
|
|
77
|
-
if (index === -1) {
|
|
78
|
-
// full response, no streaming
|
|
79
|
-
const response = new Response(string || null, {
|
|
80
|
-
status,
|
|
81
|
-
headers: resHeaders
|
|
82
|
-
});
|
|
83
|
-
resolve(response);
|
|
84
|
-
} else {
|
|
85
|
-
controller.enqueue(encoder.encode(formatter(index, string)));
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
resolveHTTPResponse({
|
|
89
|
-
req,
|
|
90
|
-
createContext,
|
|
91
|
-
path,
|
|
92
|
-
router: opts.router,
|
|
93
|
-
batching: opts.batching,
|
|
94
|
-
responseMeta: opts.responseMeta,
|
|
95
|
-
onError (o) {
|
|
96
|
-
opts?.onError?.({
|
|
97
|
-
...o,
|
|
98
|
-
req: opts.req
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
unstable_onHead,
|
|
102
|
-
unstable_onChunk
|
|
103
|
-
}).then(()=>{
|
|
104
|
-
if (isStream) {
|
|
105
|
-
controller.enqueue(encoder.encode(formatter.end()));
|
|
106
|
-
controller.close();
|
|
107
|
-
}
|
|
108
|
-
}).catch(()=>{
|
|
109
|
-
if (isStream) {
|
|
110
|
-
controller.close();
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
return promise;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export { fetchRequestHandler };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If you're making an adapter for tRPC and looking at this file for reference, you should import types and functions from `@trpc/server` and `@trpc/server/http`
|
|
3
|
-
*
|
|
4
|
-
* Do **not** import from `@trpc/core`
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* import type { AnyTRPCRouter } from '@trpc/server'
|
|
8
|
-
* import type { HTTPBaseHandlerOptions } from '@trpc/server/http'
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
import type { AnyRouter, inferRouterContext } from '../..';
|
|
12
|
-
import type { HTTPBaseHandlerOptions, TRPCRequestInfo } from '../../@trpc-server/http';
|
|
13
|
-
export type FetchCreateContextFnOptions = {
|
|
14
|
-
req: Request;
|
|
15
|
-
resHeaders: Headers;
|
|
16
|
-
info: TRPCRequestInfo;
|
|
17
|
-
};
|
|
18
|
-
export type FetchCreateContextFn<TRouter extends AnyRouter> = (opts: FetchCreateContextFnOptions) => inferRouterContext<TRouter> | Promise<inferRouterContext<TRouter>>;
|
|
19
|
-
export type FetchCreateContextOption<TRouter extends AnyRouter> = unknown extends inferRouterContext<TRouter> ? {
|
|
20
|
-
/**
|
|
21
|
-
* @link https://trpc.io/docs/v11/context
|
|
22
|
-
**/
|
|
23
|
-
createContext?: FetchCreateContextFn<TRouter>;
|
|
24
|
-
} : {
|
|
25
|
-
/**
|
|
26
|
-
* @link https://trpc.io/docs/v11/context
|
|
27
|
-
**/
|
|
28
|
-
createContext: FetchCreateContextFn<TRouter>;
|
|
29
|
-
};
|
|
30
|
-
export type FetchHandlerOptions<TRouter extends AnyRouter> = FetchCreateContextOption<TRouter> & HTTPBaseHandlerOptions<TRouter, Request>;
|
|
31
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapters/fetch/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EAChB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,2BAA2B,GAAG;IACxC,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,eAAe,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC5D,IAAI,EAAE,2BAA2B,KAC9B,kBAAkB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;AAExE,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,SAAS,IAC5D,OAAO,SAAS,kBAAkB,CAAC,OAAO,CAAC,GACvC;IACE;;QAEI;IACJ,aAAa,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CAC/C,GACD;IACE;;QAEI;IACJ,aAAa,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CAC9C,CAAC;AAER,MAAM,MAAM,mBAAmB,CAAC,OAAO,SAAS,SAAS,IACvD,wBAAwB,CAAC,OAAO,CAAC,GAAG,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../src/adapters/next.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGpC,OAAO,KAAK,EACV,8BAA8B,EAC9B,sBAAsB,EACvB,MAAM,aAAa,CAAC;AAGrB,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CACnE,cAAc,EACd,eAAe,CAChB,CAAC;AACF,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5E,wBAAgB,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAC5D,IAAI,EAAE,sBAAsB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,CAAC,GACrE,cAAc,CA8ChB"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import type { UploadHandler } from './uploadHandler';
|
|
4
|
-
export declare function readableStreamToString(stream: ReadableStream<Uint8Array>, encoding?: BufferEncoding): Promise<string>;
|
|
5
|
-
export type FileUploadHandlerFilterArgs = {
|
|
6
|
-
filename: string;
|
|
7
|
-
contentType: string;
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
|
10
|
-
export type FileUploadHandlerPathResolverArgs = {
|
|
11
|
-
filename: string;
|
|
12
|
-
contentType: string;
|
|
13
|
-
name: string;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Chooses the path of the file to be uploaded. If a string is not
|
|
17
|
-
* returned the file will not be written.
|
|
18
|
-
*/
|
|
19
|
-
export type FileUploadHandlerPathResolver = (args: FileUploadHandlerPathResolverArgs) => string | undefined;
|
|
20
|
-
export type FileUploadHandlerOptions = {
|
|
21
|
-
/**
|
|
22
|
-
* Avoid file conflicts by appending a count on the end of the filename
|
|
23
|
-
* if it already exists on disk. Defaults to `true`.
|
|
24
|
-
*/
|
|
25
|
-
avoidFileConflicts?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* The directory to write the upload.
|
|
28
|
-
*/
|
|
29
|
-
directory?: FileUploadHandlerPathResolver | string;
|
|
30
|
-
/**
|
|
31
|
-
* The name of the file in the directory. Can be a relative path, the directory
|
|
32
|
-
* structure will be created if it does not exist.
|
|
33
|
-
*/
|
|
34
|
-
file?: FileUploadHandlerPathResolver;
|
|
35
|
-
/**
|
|
36
|
-
* The maximum upload size allowed. If the size is exceeded an error will be thrown.
|
|
37
|
-
* Defaults to 3000000B (3MB).
|
|
38
|
-
*/
|
|
39
|
-
maxPartSize?: number;
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
* @param filename
|
|
43
|
-
* @param contentType
|
|
44
|
-
* @param name
|
|
45
|
-
*/
|
|
46
|
-
filter?(args: FileUploadHandlerFilterArgs): Promise<boolean> | boolean;
|
|
47
|
-
};
|
|
48
|
-
export declare function createFileUploadHandler({ directory, avoidFileConflicts, file, filter, maxPartSize, }?: FileUploadHandlerOptions): UploadHandler;
|
|
49
|
-
export declare class NodeOnDiskFile {
|
|
50
|
-
private filepath;
|
|
51
|
-
type: string;
|
|
52
|
-
private slicer?;
|
|
53
|
-
name: string;
|
|
54
|
-
lastModified: number;
|
|
55
|
-
webkitRelativePath: string;
|
|
56
|
-
constructor(filepath: string, type: string, slicer?: {
|
|
57
|
-
start: number;
|
|
58
|
-
end: number;
|
|
59
|
-
} | undefined);
|
|
60
|
-
get size(): number;
|
|
61
|
-
slice(start?: number, end?: number, type?: string): NodeOnDiskFile;
|
|
62
|
-
arrayBuffer(): Promise<ArrayBuffer>;
|
|
63
|
-
stream(): ReadableStream<any>;
|
|
64
|
-
stream(): NodeJS.ReadableStream;
|
|
65
|
-
text(): Promise<string>;
|
|
66
|
-
readonly [Symbol.toStringTag] = "File";
|
|
67
|
-
remove(): Promise<void>;
|
|
68
|
-
getFilePath(): string;
|
|
69
|
-
}
|
|
70
|
-
//# 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;AAED,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,MAAM,CAAC,cAAc;IAUzB,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,161 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var node_crypto = require('node:crypto');
|
|
4
|
-
var node_fs = require('node:fs');
|
|
5
|
-
var fs = require('node:fs/promises');
|
|
6
|
-
var node_os = require('node:os');
|
|
7
|
-
var node_path = require('node:path');
|
|
8
|
-
var node_stream = require('node:stream');
|
|
9
|
-
var node_util = require('node:util');
|
|
10
|
-
var streamSlice = require('./streamSlice.js');
|
|
11
|
-
var uploadHandler = require('./uploadHandler.js');
|
|
12
|
-
|
|
13
|
-
async function readableStreamToString(stream, encoding) {
|
|
14
|
-
const reader = stream.getReader();
|
|
15
|
-
const chunks = [];
|
|
16
|
-
async function read() {
|
|
17
|
-
const { done , value } = await reader.read();
|
|
18
|
-
if (done) {
|
|
19
|
-
return;
|
|
20
|
-
} else if (value) {
|
|
21
|
-
chunks.push(value);
|
|
22
|
-
}
|
|
23
|
-
await read();
|
|
24
|
-
}
|
|
25
|
-
await read();
|
|
26
|
-
return Buffer.concat(chunks).toString(encoding);
|
|
27
|
-
}
|
|
28
|
-
const defaultFilePathResolver = ({ filename , })=>{
|
|
29
|
-
const ext = filename ? node_path.extname(filename) : '';
|
|
30
|
-
return 'upload_' + node_crypto.randomBytes(4).readUInt32LE(0) + ext;
|
|
31
|
-
};
|
|
32
|
-
async function uniqueFile(filepath) {
|
|
33
|
-
const ext = node_path.extname(filepath);
|
|
34
|
-
let uniqueFilepath = filepath;
|
|
35
|
-
for(let i = 1; await fs.stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
|
|
36
|
-
uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
|
|
37
|
-
}
|
|
38
|
-
return uniqueFilepath;
|
|
39
|
-
}
|
|
40
|
-
function createFileUploadHandler({ directory =node_os.tmpdir() , avoidFileConflicts =true , file =defaultFilePathResolver , filter , maxPartSize =3000000 } = {}) {
|
|
41
|
-
return async ({ name , filename , contentType , data })=>{
|
|
42
|
-
if (!filename || filter && !await filter({
|
|
43
|
-
name,
|
|
44
|
-
filename,
|
|
45
|
-
contentType
|
|
46
|
-
})) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
const dir = typeof directory === 'string' ? directory : directory({
|
|
50
|
-
name,
|
|
51
|
-
filename,
|
|
52
|
-
contentType
|
|
53
|
-
});
|
|
54
|
-
if (!dir) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
const filedir = node_path.resolve(dir);
|
|
58
|
-
const path = typeof file === 'string' ? file : file({
|
|
59
|
-
name,
|
|
60
|
-
filename,
|
|
61
|
-
contentType
|
|
62
|
-
});
|
|
63
|
-
if (!path) {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
let filepath = node_path.resolve(filedir, path);
|
|
67
|
-
if (avoidFileConflicts) {
|
|
68
|
-
filepath = await uniqueFile(filepath);
|
|
69
|
-
}
|
|
70
|
-
await fs.mkdir(node_path.dirname(filepath), {
|
|
71
|
-
recursive: true
|
|
72
|
-
}).catch(()=>{});
|
|
73
|
-
const writeFileStream = node_fs.createWriteStream(filepath);
|
|
74
|
-
let size = 0;
|
|
75
|
-
let deleteFile = false;
|
|
76
|
-
try {
|
|
77
|
-
for await (const chunk of data){
|
|
78
|
-
size += chunk.byteLength;
|
|
79
|
-
if (size > maxPartSize) {
|
|
80
|
-
deleteFile = true;
|
|
81
|
-
throw new uploadHandler.MaxPartSizeExceededError(name, maxPartSize);
|
|
82
|
-
}
|
|
83
|
-
writeFileStream.write(chunk);
|
|
84
|
-
}
|
|
85
|
-
} finally{
|
|
86
|
-
writeFileStream.end();
|
|
87
|
-
await node_util.promisify(node_stream.finished)(writeFileStream);
|
|
88
|
-
if (deleteFile) {
|
|
89
|
-
await fs.rm(filepath).catch(()=>{});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return new NodeOnDiskFile(filepath, contentType);
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
let _toStringTag = Symbol.toStringTag;
|
|
96
|
-
class NodeOnDiskFile {
|
|
97
|
-
get size() {
|
|
98
|
-
const stats = node_fs.statSync(this.filepath);
|
|
99
|
-
if (this.slicer) {
|
|
100
|
-
const slice = this.slicer.end - this.slicer.start;
|
|
101
|
-
return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
|
|
102
|
-
}
|
|
103
|
-
return stats.size;
|
|
104
|
-
}
|
|
105
|
-
slice(start, end, type) {
|
|
106
|
-
if (typeof start === 'number' && start < 0) start = this.size + start;
|
|
107
|
-
if (typeof end === 'number' && end < 0) end = this.size + end;
|
|
108
|
-
const startOffset = this.slicer?.start ?? 0;
|
|
109
|
-
start = startOffset + (start ?? 0);
|
|
110
|
-
end = startOffset + (end ?? this.size);
|
|
111
|
-
return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
|
|
112
|
-
start,
|
|
113
|
-
end
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
async arrayBuffer() {
|
|
117
|
-
let stream = node_fs.createReadStream(this.filepath);
|
|
118
|
-
if (this.slicer) {
|
|
119
|
-
stream = stream.pipe(streamSlice.streamSlice(this.slicer.start, this.slicer.end));
|
|
120
|
-
}
|
|
121
|
-
return new Promise((resolve, reject)=>{
|
|
122
|
-
const buf = [];
|
|
123
|
-
stream.on('data', (chunk)=>buf.push(chunk));
|
|
124
|
-
stream.on('end', ()=>{
|
|
125
|
-
resolve(Buffer.concat(buf));
|
|
126
|
-
});
|
|
127
|
-
stream.on('error', (err)=>{
|
|
128
|
-
reject(err);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
stream() {
|
|
133
|
-
let stream = node_fs.createReadStream(this.filepath);
|
|
134
|
-
if (this.slicer) {
|
|
135
|
-
stream = stream.pipe(streamSlice.streamSlice(this.slicer.start, this.slicer.end));
|
|
136
|
-
}
|
|
137
|
-
return node_stream.Readable.toWeb(stream);
|
|
138
|
-
}
|
|
139
|
-
async text() {
|
|
140
|
-
return readableStreamToString(this.stream());
|
|
141
|
-
}
|
|
142
|
-
remove() {
|
|
143
|
-
return fs.unlink(this.filepath);
|
|
144
|
-
}
|
|
145
|
-
getFilePath() {
|
|
146
|
-
return this.filepath;
|
|
147
|
-
}
|
|
148
|
-
constructor(filepath, type, slicer){
|
|
149
|
-
this.filepath = filepath;
|
|
150
|
-
this.type = type;
|
|
151
|
-
this.slicer = slicer;
|
|
152
|
-
this.lastModified = 0;
|
|
153
|
-
this.webkitRelativePath = '';
|
|
154
|
-
this[_toStringTag] = 'File';
|
|
155
|
-
this.name = node_path.basename(filepath);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
exports.NodeOnDiskFile = NodeOnDiskFile;
|
|
160
|
-
exports.createFileUploadHandler = createFileUploadHandler;
|
|
161
|
-
exports.readableStreamToString = readableStreamToString;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import { createWriteStream, statSync, createReadStream } from 'node:fs';
|
|
3
|
-
import { mkdir, rm, unlink, stat } from 'node:fs/promises';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { resolve, dirname, basename, extname } from 'node:path';
|
|
6
|
-
import { finished, Readable } from 'node:stream';
|
|
7
|
-
import { promisify } from 'node:util';
|
|
8
|
-
import { streamSlice } from './streamSlice.mjs';
|
|
9
|
-
import { MaxPartSizeExceededError } from './uploadHandler.mjs';
|
|
10
|
-
|
|
11
|
-
async function readableStreamToString(stream, encoding) {
|
|
12
|
-
const reader = stream.getReader();
|
|
13
|
-
const chunks = [];
|
|
14
|
-
async function read() {
|
|
15
|
-
const { done , value } = await reader.read();
|
|
16
|
-
if (done) {
|
|
17
|
-
return;
|
|
18
|
-
} else if (value) {
|
|
19
|
-
chunks.push(value);
|
|
20
|
-
}
|
|
21
|
-
await read();
|
|
22
|
-
}
|
|
23
|
-
await read();
|
|
24
|
-
return Buffer.concat(chunks).toString(encoding);
|
|
25
|
-
}
|
|
26
|
-
const defaultFilePathResolver = ({ filename , })=>{
|
|
27
|
-
const ext = filename ? extname(filename) : '';
|
|
28
|
-
return 'upload_' + randomBytes(4).readUInt32LE(0) + ext;
|
|
29
|
-
};
|
|
30
|
-
async function uniqueFile(filepath) {
|
|
31
|
-
const ext = extname(filepath);
|
|
32
|
-
let uniqueFilepath = filepath;
|
|
33
|
-
for(let i = 1; await stat(uniqueFilepath).then(()=>true).catch(()=>false); i++){
|
|
34
|
-
uniqueFilepath = (ext ? filepath.slice(0, -ext.length) : filepath) + `-${new Date().getTime()}${ext}`;
|
|
35
|
-
}
|
|
36
|
-
return uniqueFilepath;
|
|
37
|
-
}
|
|
38
|
-
function createFileUploadHandler({ directory =tmpdir() , avoidFileConflicts =true , file =defaultFilePathResolver , filter , maxPartSize =3000000 } = {}) {
|
|
39
|
-
return async ({ name , filename , contentType , data })=>{
|
|
40
|
-
if (!filename || filter && !await filter({
|
|
41
|
-
name,
|
|
42
|
-
filename,
|
|
43
|
-
contentType
|
|
44
|
-
})) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
const dir = typeof directory === 'string' ? directory : directory({
|
|
48
|
-
name,
|
|
49
|
-
filename,
|
|
50
|
-
contentType
|
|
51
|
-
});
|
|
52
|
-
if (!dir) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
const filedir = resolve(dir);
|
|
56
|
-
const path = typeof file === 'string' ? file : file({
|
|
57
|
-
name,
|
|
58
|
-
filename,
|
|
59
|
-
contentType
|
|
60
|
-
});
|
|
61
|
-
if (!path) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
let filepath = resolve(filedir, path);
|
|
65
|
-
if (avoidFileConflicts) {
|
|
66
|
-
filepath = await uniqueFile(filepath);
|
|
67
|
-
}
|
|
68
|
-
await mkdir(dirname(filepath), {
|
|
69
|
-
recursive: true
|
|
70
|
-
}).catch(()=>{});
|
|
71
|
-
const writeFileStream = createWriteStream(filepath);
|
|
72
|
-
let size = 0;
|
|
73
|
-
let deleteFile = false;
|
|
74
|
-
try {
|
|
75
|
-
for await (const chunk of data){
|
|
76
|
-
size += chunk.byteLength;
|
|
77
|
-
if (size > maxPartSize) {
|
|
78
|
-
deleteFile = true;
|
|
79
|
-
throw new MaxPartSizeExceededError(name, maxPartSize);
|
|
80
|
-
}
|
|
81
|
-
writeFileStream.write(chunk);
|
|
82
|
-
}
|
|
83
|
-
} finally{
|
|
84
|
-
writeFileStream.end();
|
|
85
|
-
await promisify(finished)(writeFileStream);
|
|
86
|
-
if (deleteFile) {
|
|
87
|
-
await rm(filepath).catch(()=>{});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return new NodeOnDiskFile(filepath, contentType);
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
let _toStringTag = Symbol.toStringTag;
|
|
94
|
-
class NodeOnDiskFile {
|
|
95
|
-
get size() {
|
|
96
|
-
const stats = statSync(this.filepath);
|
|
97
|
-
if (this.slicer) {
|
|
98
|
-
const slice = this.slicer.end - this.slicer.start;
|
|
99
|
-
return slice < 0 ? 0 : slice > stats.size ? stats.size : slice;
|
|
100
|
-
}
|
|
101
|
-
return stats.size;
|
|
102
|
-
}
|
|
103
|
-
slice(start, end, type) {
|
|
104
|
-
if (typeof start === 'number' && start < 0) start = this.size + start;
|
|
105
|
-
if (typeof end === 'number' && end < 0) end = this.size + end;
|
|
106
|
-
const startOffset = this.slicer?.start ?? 0;
|
|
107
|
-
start = startOffset + (start ?? 0);
|
|
108
|
-
end = startOffset + (end ?? this.size);
|
|
109
|
-
return new NodeOnDiskFile(this.filepath, typeof type === 'string' ? type : this.type, {
|
|
110
|
-
start,
|
|
111
|
-
end
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
async arrayBuffer() {
|
|
115
|
-
let stream = createReadStream(this.filepath);
|
|
116
|
-
if (this.slicer) {
|
|
117
|
-
stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
|
|
118
|
-
}
|
|
119
|
-
return new Promise((resolve, reject)=>{
|
|
120
|
-
const buf = [];
|
|
121
|
-
stream.on('data', (chunk)=>buf.push(chunk));
|
|
122
|
-
stream.on('end', ()=>{
|
|
123
|
-
resolve(Buffer.concat(buf));
|
|
124
|
-
});
|
|
125
|
-
stream.on('error', (err)=>{
|
|
126
|
-
reject(err);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
stream() {
|
|
131
|
-
let stream = createReadStream(this.filepath);
|
|
132
|
-
if (this.slicer) {
|
|
133
|
-
stream = stream.pipe(streamSlice(this.slicer.start, this.slicer.end));
|
|
134
|
-
}
|
|
135
|
-
return Readable.toWeb(stream);
|
|
136
|
-
}
|
|
137
|
-
async text() {
|
|
138
|
-
return readableStreamToString(this.stream());
|
|
139
|
-
}
|
|
140
|
-
remove() {
|
|
141
|
-
return unlink(this.filepath);
|
|
142
|
-
}
|
|
143
|
-
getFilePath() {
|
|
144
|
-
return this.filepath;
|
|
145
|
-
}
|
|
146
|
-
constructor(filepath, type, slicer){
|
|
147
|
-
this.filepath = filepath;
|
|
148
|
-
this.type = type;
|
|
149
|
-
this.slicer = slicer;
|
|
150
|
-
this.lastModified = 0;
|
|
151
|
-
this.webkitRelativePath = '';
|
|
152
|
-
this[_toStringTag] = 'File';
|
|
153
|
-
this.name = basename(filepath);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export { NodeOnDiskFile, createFileUploadHandler, readableStreamToString };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/adapters/node-http/content-type/form-data/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,iBAAiB,CAAC;AAKxE;;;;;;;;;GASG;AACH,iBAAe,sBAAsB,CACnC,OAAO,EAAE,eAAe,EACxB,aAAa,EAAE,aAAa,EAC5B,WAAW,SAAW,qBAoEvB;AAED,iBAAS,0BAA0B,CAAC,GAAG,EAAE,eAAe,WAMvD;AAED,eAAO,MAAM,kCAAkC,yLAgC3C,CAAC;AAEL,OAAO,EAAE,sBAAsB,IAAI,mCAAmC,EAAE,CAAC;AACzE,OAAO,EAAE,yBAAyB,IAAI,sCAAsC,EAAE,MAAM,uBAAuB,CAAC;AAC5G,OAAO,EACL,uBAAuB,IAAI,oCAAoC,EAC/D,cAAc,IAAI,2BAA2B,GAC9C,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,qBAAqB,IAAI,kCAAkC,EAC3D,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,0BAA0B,IAAI,uCAAuC,EAAE,CAAC"}
|