@whatwg-node/node-fetch 0.5.11-alpha-20240327142620-7e48e923e7d5db8190d1a60110883d229f7d893c → 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.
@@ -3,18 +3,6 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.PonyfillReadableStream = void 0;
5
5
  const stream_1 = require("stream");
6
- try {
7
- const originalReadableFromWeb = stream_1.Readable.fromWeb;
8
- stream_1.Readable.fromWeb = function fromWeb(stream) {
9
- if (stream instanceof PonyfillReadableStream) {
10
- return stream.readable;
11
- }
12
- return originalReadableFromWeb(stream);
13
- };
14
- }
15
- catch (e) {
16
- console.warn('Could not patch Readable.fromWeb, so this might break Readable.fromWeb usage with the whatwg-node and the integrations like Fastify', e);
17
- }
18
6
  function createController(desiredSize, readable) {
19
7
  let chunks = [];
20
8
  let _closed = false;
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,17 +1,5 @@
1
1
  var _a;
2
2
  import { Readable } from 'stream';
3
- try {
4
- const originalReadableFromWeb = Readable.fromWeb;
5
- Readable.fromWeb = function fromWeb(stream) {
6
- if (stream instanceof PonyfillReadableStream) {
7
- return stream.readable;
8
- }
9
- return originalReadableFromWeb(stream);
10
- };
11
- }
12
- catch (e) {
13
- console.warn('Could not patch Readable.fromWeb, so this might break Readable.fromWeb usage with the whatwg-node and the integrations like Fastify', e);
14
- }
15
3
  function createController(desiredSize, readable) {
16
4
  let chunks = [];
17
5
  let _closed = false;
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.11-alpha-20240327142620-7e48e923e7d5db8190d1a60110883d229f7d893c",
3
+ "version": "0.5.11-alpha-20240327142842-26e172534a26bc875f63385a16971fbdc5b95d8b",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -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>;