@whatwg-node/node-fetch 0.5.10 → 0.5.11-alpha-20240327142842-26e172534a26bc875f63385a16971fbdc5b95d8b

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.
@@ -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,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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;
4
+ const utils_js_1 = require("./utils.js");
4
5
  var fetch_js_1 = require("./fetch.js");
5
6
  Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_js_1.fetchPonyfill; } });
6
7
  var Headers_js_1 = require("./Headers.js");
@@ -27,3 +28,5 @@ var URL_js_1 = require("./URL.js");
27
28
  Object.defineProperty(exports, "URL", { enumerable: true, get: function () { return URL_js_1.PonyfillURL; } });
28
29
  var URLSearchParams_js_1 = require("./URLSearchParams.js");
29
30
  Object.defineProperty(exports, "URLSearchParams", { enumerable: true, get: function () { return URLSearchParams_js_1.PonyfillURLSearchParams; } });
31
+ // Not sure it is the right thing to do, but it is the only way to make it work for Fastify
32
+ (0, utils_js_1.patchReadableFromWeb)();
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;
@@ -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
@@ -1,3 +1,4 @@
1
+ import { patchReadableFromWeb } from './utils.js';
1
2
  export { fetchPonyfill as fetch } from './fetch.js';
2
3
  export { PonyfillHeaders as Headers } from './Headers.js';
3
4
  export { PonyfillBody as Body } from './Body.js';
@@ -10,3 +11,5 @@ export { PonyfillBlob as Blob } from './Blob.js';
10
11
  export { PonyfillTextEncoder as TextEncoder, PonyfillTextDecoder as TextDecoder, PonyfillBtoa as btoa, } from './TextEncoderDecoder.js';
11
12
  export { PonyfillURL as URL } from './URL.js';
12
13
  export { PonyfillURLSearchParams as URLSearchParams } from './URLSearchParams.js';
14
+ // Not sure it is the right thing to do, but it is the only way to make it work for Fastify
15
+ patchReadableFromWeb();
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.5.10",
3
+ "version": "0.5.11-alpha-20240327142842-26e172534a26bc875f63385a16971fbdc5b95d8b",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -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
  }
@@ -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
  }
@@ -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
  }
@@ -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>;
@@ -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>;