@whatwg-node/node-fetch 0.4.3 → 0.4.4-alpha-20230609075247-db6b788
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/cjs/Body.js +4 -1
- package/cjs/Response.js +13 -1
- package/esm/Body.js +4 -1
- package/esm/Response.js +13 -1
- package/package.json +3 -2
package/cjs/Body.js
CHANGED
@@ -2,13 +2,16 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.PonyfillBody = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
|
+
const node_util_1 = require("node:util");
|
5
6
|
const stream_1 = require("stream");
|
6
7
|
const busboy_1 = tslib_1.__importDefault(require("busboy"));
|
8
|
+
const yieldable_json_1 = require("yieldable-json");
|
7
9
|
const Blob_js_1 = require("./Blob.js");
|
8
10
|
const File_js_1 = require("./File.js");
|
9
11
|
const FormData_js_1 = require("./FormData.js");
|
10
12
|
const ReadableStream_js_1 = require("./ReadableStream.js");
|
11
13
|
const utils_js_1 = require("./utils.js");
|
14
|
+
const JSONParseAsync = (0, node_util_1.promisify)(yieldable_json_1.parseAsync);
|
12
15
|
var BodyInitType;
|
13
16
|
(function (BodyInitType) {
|
14
17
|
BodyInitType["ReadableStream"] = "ReadableStream";
|
@@ -212,7 +215,7 @@ class PonyfillBody {
|
|
212
215
|
}
|
213
216
|
async json() {
|
214
217
|
const text = await this.text();
|
215
|
-
return
|
218
|
+
return JSONParseAsync(text);
|
216
219
|
}
|
217
220
|
async text() {
|
218
221
|
if (this.bodyType === BodyInitType.String) {
|
package/cjs/Response.js
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.PonyfillResponse = void 0;
|
4
4
|
const http_1 = require("http");
|
5
|
+
const yieldable_json_1 = require("yieldable-json");
|
5
6
|
const Body_js_1 = require("./Body.js");
|
6
7
|
const Headers_js_1 = require("./Headers.js");
|
8
|
+
const ReadableStream_js_1 = require("./ReadableStream.js");
|
7
9
|
class PonyfillResponse extends Body_js_1.PonyfillBody {
|
8
10
|
constructor(body, init) {
|
9
11
|
super(body || null, init);
|
@@ -64,7 +66,17 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
64
66
|
});
|
65
67
|
}
|
66
68
|
static json(data, init = {}) {
|
67
|
-
|
69
|
+
const body = new ReadableStream_js_1.PonyfillReadableStream();
|
70
|
+
(0, yieldable_json_1.stringifyAsync)(data, (err, result) => {
|
71
|
+
if (err) {
|
72
|
+
body.readable.destroy(err);
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
body.readable.push(result);
|
76
|
+
body.readable.push(null);
|
77
|
+
}
|
78
|
+
});
|
79
|
+
return new PonyfillResponse(body, {
|
68
80
|
...init,
|
69
81
|
headers: {
|
70
82
|
'Content-Type': 'application/json',
|
package/esm/Body.js
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
+
import { promisify } from 'node:util';
|
1
2
|
import { Readable } from 'stream';
|
2
3
|
import busboy from 'busboy';
|
4
|
+
import { parseAsync } from 'yieldable-json';
|
3
5
|
import { PonyfillBlob } from './Blob.js';
|
4
6
|
import { PonyfillFile } from './File.js';
|
5
7
|
import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
|
6
8
|
import { PonyfillReadableStream } from './ReadableStream.js';
|
7
9
|
import { uint8ArrayToArrayBuffer } from './utils.js';
|
10
|
+
const JSONParseAsync = promisify(parseAsync);
|
8
11
|
var BodyInitType;
|
9
12
|
(function (BodyInitType) {
|
10
13
|
BodyInitType["ReadableStream"] = "ReadableStream";
|
@@ -208,7 +211,7 @@ export class PonyfillBody {
|
|
208
211
|
}
|
209
212
|
async json() {
|
210
213
|
const text = await this.text();
|
211
|
-
return
|
214
|
+
return JSONParseAsync(text);
|
212
215
|
}
|
213
216
|
async text() {
|
214
217
|
if (this.bodyType === BodyInitType.String) {
|
package/esm/Response.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { STATUS_CODES } from 'http';
|
2
|
+
import { stringifyAsync } from 'yieldable-json';
|
2
3
|
import { PonyfillBody } from './Body.js';
|
3
4
|
import { PonyfillHeaders } from './Headers.js';
|
5
|
+
import { PonyfillReadableStream } from './ReadableStream.js';
|
4
6
|
export class PonyfillResponse extends PonyfillBody {
|
5
7
|
constructor(body, init) {
|
6
8
|
super(body || null, init);
|
@@ -61,7 +63,17 @@ export class PonyfillResponse extends PonyfillBody {
|
|
61
63
|
});
|
62
64
|
}
|
63
65
|
static json(data, init = {}) {
|
64
|
-
|
66
|
+
const body = new PonyfillReadableStream();
|
67
|
+
stringifyAsync(data, (err, result) => {
|
68
|
+
if (err) {
|
69
|
+
body.readable.destroy(err);
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
body.readable.push(result);
|
73
|
+
body.readable.push(null);
|
74
|
+
}
|
75
|
+
});
|
76
|
+
return new PonyfillResponse(body, {
|
65
77
|
...init,
|
66
78
|
headers: {
|
67
79
|
'Content-Type': 'application/json',
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.4-alpha-20230609075247-db6b788",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
@@ -8,7 +8,8 @@
|
|
8
8
|
"busboy": "^1.6.0",
|
9
9
|
"fast-querystring": "^1.1.1",
|
10
10
|
"fast-url-parser": "^1.1.3",
|
11
|
-
"tslib": "^2.3.1"
|
11
|
+
"tslib": "^2.3.1",
|
12
|
+
"yieldable-json": "^2.0.1"
|
12
13
|
},
|
13
14
|
"repository": {
|
14
15
|
"type": "git",
|