@whatwg-node/fetch 0.4.0 → 0.4.3
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/CHANGELOG.md +18 -0
- package/dist/create-node-ponyfill.js +29 -0
- package/dist/getFormDataMethod.js +27 -19
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @whatwg-node/fetch
|
|
2
2
|
|
|
3
|
+
## 0.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`c9f05f2`](https://github.com/ardatan/whatwg-node/commit/c9f05f21fb96f63bc22359e3b7981cb9b3b727b5) Thanks [@ardatan](https://github.com/ardatan)! - Add ponyfills for Response.redirect, Response.json and Response.error
|
|
8
|
+
|
|
9
|
+
## 0.4.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`7f37b6d`](https://github.com/ardatan/whatwg-node/commit/7f37b6dbeb76cfa54e0ed8672812bf016c1df4fa) Thanks [@ardatan](https://github.com/ardatan)! - fix(fetch): respect filesLimit even with fieldsFirst
|
|
14
|
+
|
|
15
|
+
## 0.4.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`53753bb`](https://github.com/ardatan/whatwg-node/commit/53753bb5dd83fbc1e7253784b02f2b1f2e02fdb9) Thanks [@ardatan](https://github.com/ardatan)! - fix(fetch): fix formData function
|
|
20
|
+
|
|
3
21
|
## 0.4.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -319,5 +319,34 @@ module.exports = function createNodePonyfill(opts = {}) {
|
|
|
319
319
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
+
|
|
323
|
+
if (!ponyfills.Response.redirect) {
|
|
324
|
+
ponyfills.Response.redirect = function (url, status = 302) {
|
|
325
|
+
return new ponyfills.Response(null, {
|
|
326
|
+
status,
|
|
327
|
+
headers: {
|
|
328
|
+
Location: url,
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (!ponyfills.Response.json) {
|
|
334
|
+
ponyfills.Response.json = function (data, init = {}) {
|
|
335
|
+
return new ponyfills.Response(JSON.stringify(data), {
|
|
336
|
+
...init,
|
|
337
|
+
headers: {
|
|
338
|
+
"Content-Type": "application/json",
|
|
339
|
+
...init.headers,
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
if (!ponyfills.Response.error) {
|
|
345
|
+
ponyfills.Response.error = function () {
|
|
346
|
+
return new ponyfills.Response(null, {
|
|
347
|
+
status: 500,
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
}
|
|
322
351
|
return ponyfills;
|
|
323
352
|
}
|
|
@@ -10,9 +10,6 @@ module.exports = function getFormDataMethod(File, limits) {
|
|
|
10
10
|
fileStream,
|
|
11
11
|
formData,
|
|
12
12
|
}) {
|
|
13
|
-
if (fileStream._consumedAsFile) {
|
|
14
|
-
return Promise.resolve(formData.get(name));
|
|
15
|
-
}
|
|
16
13
|
return new Promise((resolve, reject) => {
|
|
17
14
|
const chunks = [];
|
|
18
15
|
fileStream.on('limit', () => {
|
|
@@ -22,9 +19,11 @@ module.exports = function getFormDataMethod(File, limits) {
|
|
|
22
19
|
chunks.push(chunk);
|
|
23
20
|
})
|
|
24
21
|
fileStream.on('close', () => {
|
|
22
|
+
if (fileStream.truncated) {
|
|
23
|
+
reject(new Error(`File size limit exceeded: ${limits.fileSize} bytes`));
|
|
24
|
+
}
|
|
25
25
|
const file = new File(chunks, filename, { type: mimeType });
|
|
26
26
|
formData.set(name, file);
|
|
27
|
-
fileStream._consumedAsFile = true;
|
|
28
27
|
resolve(file);
|
|
29
28
|
});
|
|
30
29
|
})
|
|
@@ -58,7 +57,8 @@ module.exports = function getFormDataMethod(File, limits) {
|
|
|
58
57
|
reject(new Error(`Fields limit exceeded: ${limits.fields}`));
|
|
59
58
|
})
|
|
60
59
|
bb.on('file', (name, fileStream, { filename, mimeType }) => {
|
|
61
|
-
|
|
60
|
+
let file$;
|
|
61
|
+
if (limits && limits.fieldsFirst) {
|
|
62
62
|
resolve(formData);
|
|
63
63
|
const fakeFileObj = {
|
|
64
64
|
name: filename,
|
|
@@ -80,24 +80,32 @@ module.exports = function getFormDataMethod(File, limits) {
|
|
|
80
80
|
throw new Error(`Cannot slice file before consuming the stream.`);
|
|
81
81
|
case 'text':
|
|
82
82
|
case 'arrayBuffer':
|
|
83
|
-
return () =>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
return () => {
|
|
84
|
+
if (!file$) {
|
|
85
|
+
file$ = consumeStreamAsFile({
|
|
86
|
+
name,
|
|
87
|
+
filename,
|
|
88
|
+
mimeType,
|
|
89
|
+
fileStream,
|
|
90
|
+
formData,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
return file$.then(file => file[prop]());
|
|
94
|
+
}
|
|
90
95
|
}
|
|
91
96
|
},
|
|
92
97
|
}))
|
|
93
98
|
} else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
if (!file$) {
|
|
100
|
+
file$ = consumeStreamAsFile({
|
|
101
|
+
name,
|
|
102
|
+
filename,
|
|
103
|
+
mimeType,
|
|
104
|
+
fileStream,
|
|
105
|
+
formData,
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
file$.catch(reject);
|
|
101
109
|
}
|
|
102
110
|
})
|
|
103
111
|
bb.on('filesLimit', () => {
|