@whatwg-node/node-fetch 0.5.11 → 0.5.12-alpha-20240531123246-0ce0cb68420abde647ade7c6d43ce8498ca0e24b
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 +19 -1
- package/esm/ReadableStream.js +3 -0
- package/esm/Response.js +3 -0
- package/esm/index.js +1 -0
- package/esm/utils.js +17 -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
|
}
|
@@ -172,3 +174,4 @@ class PonyfillReadableStream {
|
|
172
174
|
}
|
173
175
|
}
|
174
176
|
exports.PonyfillReadableStream = PonyfillReadableStream;
|
177
|
+
_a = Symbol.toStringTag;
|
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.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.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,9 +1,27 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isNodeReadable = exports.isArrayBufferView = exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = void 0;
|
3
|
+
exports.isNodeReadable = exports.isArrayBufferView = exports.fakePromise = exports.defaultHeadersSerializer = exports.getHeadersObj = exports.patchReadableFromWeb = void 0;
|
4
|
+
const stream_1 = require("stream");
|
4
5
|
function isHeadersInstance(obj) {
|
5
6
|
return obj?.forEach != null;
|
6
7
|
}
|
8
|
+
function patchReadableFromWeb() {
|
9
|
+
try {
|
10
|
+
const originalReadableFromWeb = stream_1.Readable.fromWeb;
|
11
|
+
if (originalReadableFromWeb.name !== 'ReadableFromWebPatchedByWhatWgNode') {
|
12
|
+
stream_1.Readable.fromWeb = function ReadableFromWebPatchedByWhatWgNode(stream) {
|
13
|
+
if (stream.readable != null) {
|
14
|
+
return stream.readable;
|
15
|
+
}
|
16
|
+
return originalReadableFromWeb(stream);
|
17
|
+
};
|
18
|
+
}
|
19
|
+
}
|
20
|
+
catch (e) {
|
21
|
+
console.warn('Could not patch Readable.fromWeb, so this might break Readable.fromWeb usage with the whatwg-node and the integrations like Fastify', e);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
exports.patchReadableFromWeb = patchReadableFromWeb;
|
7
25
|
function getHeadersObj(headers) {
|
8
26
|
if (headers == null || !isHeadersInstance(headers)) {
|
9
27
|
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
|
}
|
@@ -168,3 +170,4 @@ export class PonyfillReadableStream {
|
|
168
170
|
return isReadableStream(instance);
|
169
171
|
}
|
170
172
|
}
|
173
|
+
_a = Symbol.toStringTag;
|
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,23 @@
|
|
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
|
+
}
|
16
|
+
}
|
17
|
+
catch (e) {
|
18
|
+
console.warn('Could not patch Readable.fromWeb, so this might break Readable.fromWeb usage with the whatwg-node and the integrations like Fastify', e);
|
19
|
+
}
|
20
|
+
}
|
4
21
|
export function getHeadersObj(headers) {
|
5
22
|
if (headers == null || !isHeadersInstance(headers)) {
|
6
23
|
return headers;
|
package/package.json
CHANGED
@@ -17,4 +17,5 @@ export declare class PonyfillReadableStream<T> implements ReadableStream<T> {
|
|
17
17
|
readable: ReadableStream<T2>;
|
18
18
|
}): ReadableStream<T2>;
|
19
19
|
static [Symbol.hasInstance](instance: unknown): instance is PonyfillReadableStream<unknown>;
|
20
|
+
[Symbol.toStringTag]: string;
|
20
21
|
}
|
@@ -17,4 +17,5 @@ export declare class PonyfillReadableStream<T> implements ReadableStream<T> {
|
|
17
17
|
readable: ReadableStream<T2>;
|
18
18
|
}): ReadableStream<T2>;
|
19
19
|
static [Symbol.hasInstance](instance: unknown): instance is PonyfillReadableStream<unknown>;
|
20
|
+
[Symbol.toStringTag]: string;
|
20
21
|
}
|
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,5 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { Readable } from 'stream';
|
3
|
+
export declare function patchReadableFromWeb(): void;
|
3
4
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
4
5
|
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
5
6
|
export declare function fakePromise<T>(value: T): Promise<T>;
|
package/typings/utils.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { Readable } from 'stream';
|
3
|
+
export declare function patchReadableFromWeb(): void;
|
3
4
|
export declare function getHeadersObj(headers: Headers): Record<string, string>;
|
4
5
|
export declare function defaultHeadersSerializer(headers: Headers, onContentLength?: (value: string) => void): string[];
|
5
6
|
export declare function fakePromise<T>(value: T): Promise<T>;
|