@whatwg-node/node-fetch 0.5.17 → 0.5.18-alpha-20240726144438-d85e825aca3e8ac57c7758d5ec88ed5c27358fcc
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/ReadableStream.js +3 -0
- package/cjs/Response.js +3 -0
- package/cjs/index.js +3 -1
- package/cjs/utils.js +24 -0
- package/esm/ReadableStream.js +3 -0
- package/esm/Response.js +3 -0
- package/esm/index.js +1 -0
- package/esm/utils.js +23 -0
- package/package.json +1 -1
- package/typings/ReadableStream.d.cts +1 -0
- package/typings/ReadableStream.d.ts +1 -0
- package/typings/Response.d.cts +1 -0
- package/typings/Response.d.ts +1 -0
- package/typings/index.d.cts +1 -0
- package/typings/index.d.ts +1 -0
- package/typings/utils.d.cts +1 -0
- package/typings/utils.d.ts +1 -0
package/cjs/ReadableStream.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
+
var _a;
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
4
|
exports.PonyfillReadableStream = void 0;
|
4
5
|
const stream_1 = require("stream");
|
@@ -52,6 +53,7 @@ function isReadableStream(obj) {
|
|
52
53
|
class PonyfillReadableStream {
|
53
54
|
constructor(underlyingSource) {
|
54
55
|
this.locked = false;
|
56
|
+
this[_a] = 'ReadableStream';
|
55
57
|
if (underlyingSource instanceof PonyfillReadableStream && underlyingSource.readable != null) {
|
56
58
|
this.readable = underlyingSource.readable;
|
57
59
|
}
|
@@ -184,6 +186,7 @@ class PonyfillReadableStream {
|
|
184
186
|
}
|
185
187
|
}
|
186
188
|
exports.PonyfillReadableStream = PonyfillReadableStream;
|
189
|
+
_a = Symbol.toStringTag;
|
187
190
|
function isPonyfillWritableStream(obj) {
|
188
191
|
return obj?.writable != null;
|
189
192
|
}
|
package/cjs/Response.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
+
var _a;
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
4
|
exports.PonyfillResponse = void 0;
|
4
5
|
const http_1 = require("http");
|
@@ -8,6 +9,7 @@ const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
|
8
9
|
class PonyfillResponse extends Body_js_1.PonyfillBody {
|
9
10
|
constructor(body, init) {
|
10
11
|
super(body || null, init);
|
12
|
+
this[_a] = 'Response';
|
11
13
|
this.headers =
|
12
14
|
init?.headers && (0, Headers_js_1.isHeadersLike)(init.headers)
|
13
15
|
? init.headers
|
@@ -71,3 +73,4 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
71
73
|
}
|
72
74
|
}
|
73
75
|
exports.PonyfillResponse = PonyfillResponse;
|
76
|
+
_a = Symbol.toStringTag;
|
package/cjs/index.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.DecompressionStream = exports.CompressionStream = exports.TransformStream = exports.WritableStream = exports.URLSearchParams = exports.URL = exports.btoa = exports.TextDecoder = exports.TextEncoder = exports.Blob = exports.FormData = exports.File = exports.ReadableStream = exports.Response = exports.Request = exports.Body = exports.Headers = exports.fetch = void 0;
|
3
|
+
exports.DecompressionStream = exports.CompressionStream = exports.TransformStream = exports.WritableStream = exports.URLSearchParams = exports.URL = exports.btoa = exports.TextDecoder = exports.TextEncoder = exports.Blob = exports.FormData = exports.File = exports.ReadableStream = exports.Response = exports.Request = exports.Body = exports.Headers = exports.fetch = exports.patchReadableFromWeb = void 0;
|
4
|
+
var utils_js_1 = require("./utils.js");
|
5
|
+
Object.defineProperty(exports, "patchReadableFromWeb", { enumerable: true, get: function () { return utils_js_1.patchReadableFromWeb; } });
|
4
6
|
var fetch_js_1 = require("./fetch.js");
|
5
7
|
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_js_1.fetchPonyfill; } });
|
6
8
|
var Headers_js_1 = require("./Headers.js");
|
package/cjs/utils.js
CHANGED
@@ -1,13 +1,37 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.patchReadableFromWeb = patchReadableFromWeb;
|
3
4
|
exports.getHeadersObj = getHeadersObj;
|
4
5
|
exports.defaultHeadersSerializer = defaultHeadersSerializer;
|
5
6
|
exports.fakePromise = fakePromise;
|
6
7
|
exports.isArrayBufferView = isArrayBufferView;
|
7
8
|
exports.isNodeReadable = isNodeReadable;
|
9
|
+
const stream_1 = require("stream");
|
8
10
|
function isHeadersInstance(obj) {
|
9
11
|
return obj?.forEach != null;
|
10
12
|
}
|
13
|
+
function patchReadableFromWeb() {
|
14
|
+
try {
|
15
|
+
const originalReadableFromWeb = stream_1.Readable.fromWeb;
|
16
|
+
if (originalReadableFromWeb.name !== 'ReadableFromWebPatchedByWhatWgNode') {
|
17
|
+
stream_1.Readable.fromWeb = function ReadableFromWebPatchedByWhatWgNode(stream) {
|
18
|
+
if (stream.readable != null) {
|
19
|
+
return stream.readable;
|
20
|
+
}
|
21
|
+
return originalReadableFromWeb(stream);
|
22
|
+
};
|
23
|
+
if (typeof jest === 'object' && typeof afterEach === 'function') {
|
24
|
+
// To relax jest, we should remove the patch after each test
|
25
|
+
afterEach(() => {
|
26
|
+
stream_1.Readable.fromWeb = originalReadableFromWeb;
|
27
|
+
});
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
catch (e) {
|
32
|
+
console.warn('Could not patch Readable.fromWeb, so this might break Readable.fromWeb usage with the whatwg-node and the integrations like Fastify', e);
|
33
|
+
}
|
34
|
+
}
|
11
35
|
function getHeadersObj(headers) {
|
12
36
|
if (headers == null || !isHeadersInstance(headers)) {
|
13
37
|
return headers;
|
package/esm/ReadableStream.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
var _a;
|
1
2
|
import { Readable } from 'stream';
|
2
3
|
function createController(desiredSize, readable) {
|
3
4
|
let chunks = [];
|
@@ -49,6 +50,7 @@ function isReadableStream(obj) {
|
|
49
50
|
export class PonyfillReadableStream {
|
50
51
|
constructor(underlyingSource) {
|
51
52
|
this.locked = false;
|
53
|
+
this[_a] = 'ReadableStream';
|
52
54
|
if (underlyingSource instanceof PonyfillReadableStream && underlyingSource.readable != null) {
|
53
55
|
this.readable = underlyingSource.readable;
|
54
56
|
}
|
@@ -180,6 +182,7 @@ export class PonyfillReadableStream {
|
|
180
182
|
return isReadableStream(instance);
|
181
183
|
}
|
182
184
|
}
|
185
|
+
_a = Symbol.toStringTag;
|
183
186
|
function isPonyfillWritableStream(obj) {
|
184
187
|
return obj?.writable != null;
|
185
188
|
}
|
package/esm/Response.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
var _a;
|
1
2
|
import { STATUS_CODES } from 'http';
|
2
3
|
import { PonyfillBody } from './Body.js';
|
3
4
|
import { isHeadersLike, PonyfillHeaders } from './Headers.js';
|
@@ -5,6 +6,7 @@ const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
|
5
6
|
export class PonyfillResponse extends PonyfillBody {
|
6
7
|
constructor(body, init) {
|
7
8
|
super(body || null, init);
|
9
|
+
this[_a] = 'Response';
|
8
10
|
this.headers =
|
9
11
|
init?.headers && isHeadersLike(init.headers)
|
10
12
|
? init.headers
|
@@ -67,3 +69,4 @@ export class PonyfillResponse extends PonyfillBody {
|
|
67
69
|
return new PonyfillResponse(JSON.stringify(data), init);
|
68
70
|
}
|
69
71
|
}
|
72
|
+
_a = Symbol.toStringTag;
|
package/esm/index.js
CHANGED
package/esm/utils.js
CHANGED
@@ -1,6 +1,29 @@
|
|
1
|
+
import { Readable } from 'stream';
|
1
2
|
function isHeadersInstance(obj) {
|
2
3
|
return obj?.forEach != null;
|
3
4
|
}
|
5
|
+
export function patchReadableFromWeb() {
|
6
|
+
try {
|
7
|
+
const originalReadableFromWeb = Readable.fromWeb;
|
8
|
+
if (originalReadableFromWeb.name !== 'ReadableFromWebPatchedByWhatWgNode') {
|
9
|
+
Readable.fromWeb = function ReadableFromWebPatchedByWhatWgNode(stream) {
|
10
|
+
if (stream.readable != null) {
|
11
|
+
return stream.readable;
|
12
|
+
}
|
13
|
+
return originalReadableFromWeb(stream);
|
14
|
+
};
|
15
|
+
if (typeof jest === 'object' && typeof afterEach === 'function') {
|
16
|
+
// To relax jest, we should remove the patch after each test
|
17
|
+
afterEach(() => {
|
18
|
+
Readable.fromWeb = originalReadableFromWeb;
|
19
|
+
});
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
catch (e) {
|
24
|
+
console.warn('Could not patch Readable.fromWeb, so this might break Readable.fromWeb usage with the whatwg-node and the integrations like Fastify', e);
|
25
|
+
}
|
26
|
+
}
|
4
27
|
export function getHeadersObj(headers) {
|
5
28
|
if (headers == null || !isHeadersInstance(headers)) {
|
6
29
|
return headers;
|
package/package.json
CHANGED
@@ -16,4 +16,5 @@ export declare class PonyfillReadableStream<T> implements ReadableStream<T> {
|
|
16
16
|
readable: ReadableStream<T2>;
|
17
17
|
}): ReadableStream<T2>;
|
18
18
|
static [Symbol.hasInstance](instance: unknown): instance is PonyfillReadableStream<unknown>;
|
19
|
+
[Symbol.toStringTag]: string;
|
19
20
|
}
|
@@ -16,4 +16,5 @@ export declare class PonyfillReadableStream<T> implements ReadableStream<T> {
|
|
16
16
|
readable: ReadableStream<T2>;
|
17
17
|
}): ReadableStream<T2>;
|
18
18
|
static [Symbol.hasInstance](instance: unknown): instance is PonyfillReadableStream<unknown>;
|
19
|
+
[Symbol.toStringTag]: string;
|
19
20
|
}
|
package/typings/Response.d.cts
CHANGED
@@ -19,4 +19,5 @@ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> i
|
|
19
19
|
static error(): PonyfillResponse<any>;
|
20
20
|
static redirect(url: string, status?: number): PonyfillResponse<any>;
|
21
21
|
static json<T = any>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<T>;
|
22
|
+
[Symbol.toStringTag]: string;
|
22
23
|
}
|
package/typings/Response.d.ts
CHANGED
@@ -19,4 +19,5 @@ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> i
|
|
19
19
|
static error(): PonyfillResponse<any>;
|
20
20
|
static redirect(url: string, status?: number): PonyfillResponse<any>;
|
21
21
|
static json<T = any>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<T>;
|
22
|
+
[Symbol.toStringTag]: string;
|
22
23
|
}
|
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED
package/typings/utils.d.cts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Readable } from 'stream';
|
2
|
+
export declare function patchReadableFromWeb(): void;
|
2
3
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
3
4
|
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
4
5
|
export declare function fakePromise<T>(value: T): Promise<T>;
|
package/typings/utils.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { Readable } from 'stream';
|
2
|
+
export declare function patchReadableFromWeb(): void;
|
2
3
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
3
4
|
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
4
5
|
export declare function fakePromise<T>(value: T): Promise<T>;
|