@whatwg-node/node-fetch 0.8.2 → 0.8.3-alpha-20251110163100-4652b77de1cf710e75445db45d91cdf62127a39f

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,27 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillCompressionStream = void 0;
4
- const node_zlib_1 = require("node:zlib");
4
+ const tslib_1 = require("tslib");
5
+ const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
5
6
  const TransformStream_js_1 = require("./TransformStream.js");
7
+ const utils_js_1 = require("./utils.js");
6
8
  class PonyfillCompressionStream extends TransformStream_js_1.PonyfillTransformStream {
7
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
8
- ? ['gzip', 'deflate', 'br']
9
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
9
+ static supportedFormats = (0, utils_js_1.getSupportedFormats)();
10
10
  constructor(compressionFormat) {
11
11
  switch (compressionFormat) {
12
12
  case 'x-gzip':
13
13
  case 'gzip':
14
- super((0, node_zlib_1.createGzip)());
14
+ super(node_zlib_1.default.createGzip());
15
15
  break;
16
16
  case 'x-deflate':
17
17
  case 'deflate':
18
- super((0, node_zlib_1.createDeflate)());
18
+ super(node_zlib_1.default.createDeflate());
19
19
  break;
20
20
  case 'deflate-raw':
21
- super((0, node_zlib_1.createDeflateRaw)());
21
+ super(node_zlib_1.default.createDeflateRaw());
22
22
  break;
23
23
  case 'br':
24
- super((0, node_zlib_1.createBrotliCompress)());
24
+ super(node_zlib_1.default.createBrotliCompress());
25
+ break;
26
+ case 'zstd':
27
+ super(node_zlib_1.default.createZstdCompress());
25
28
  break;
26
29
  default:
27
30
  throw new Error(`Unsupported compression format: ${compressionFormat}`);
@@ -1,27 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillDecompressionStream = void 0;
4
- const node_zlib_1 = require("node:zlib");
4
+ const tslib_1 = require("tslib");
5
+ const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
5
6
  const TransformStream_js_1 = require("./TransformStream.js");
7
+ const utils_js_1 = require("./utils.js");
6
8
  class PonyfillDecompressionStream extends TransformStream_js_1.PonyfillTransformStream {
7
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
8
- ? ['gzip', 'deflate', 'br']
9
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
9
+ static supportedFormats = (0, utils_js_1.getSupportedFormats)();
10
10
  constructor(compressionFormat) {
11
11
  switch (compressionFormat) {
12
12
  case 'x-gzip':
13
13
  case 'gzip':
14
- super((0, node_zlib_1.createGunzip)());
14
+ super(node_zlib_1.default.createGunzip());
15
15
  break;
16
16
  case 'x-deflate':
17
17
  case 'deflate':
18
- super((0, node_zlib_1.createInflate)());
18
+ super(node_zlib_1.default.createInflate());
19
19
  break;
20
20
  case 'deflate-raw':
21
- super((0, node_zlib_1.createInflateRaw)());
21
+ super(node_zlib_1.default.createInflateRaw());
22
22
  break;
23
23
  case 'br':
24
- super((0, node_zlib_1.createBrotliDecompress)());
24
+ super(node_zlib_1.default.createBrotliDecompress());
25
+ break;
26
+ case 'zstd':
27
+ super(node_zlib_1.default.createZstdDecompress());
25
28
  break;
26
29
  default:
27
30
  throw new TypeError(`Unsupported compression format: '${compressionFormat}'`);
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fetchNodeHttp = fetchNodeHttp;
4
+ const tslib_1 = require("tslib");
4
5
  const node_http_1 = require("node:http");
5
6
  const node_https_1 = require("node:https");
6
7
  const node_stream_1 = require("node:stream");
7
- const node_zlib_1 = require("node:zlib");
8
+ const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
8
9
  const promise_helpers_1 = require("@whatwg-node/promise-helpers");
9
10
  const Request_js_1 = require("./Request.js");
10
11
  const Response_js_1 = require("./Response.js");
@@ -61,18 +62,21 @@ function fetchNodeHttp(fetchRequest) {
61
62
  switch (contentEncoding) {
62
63
  case 'x-gzip':
63
64
  case 'gzip':
64
- outputStream = (0, node_zlib_1.createGunzip)();
65
+ outputStream = node_zlib_1.default.createGunzip();
65
66
  break;
66
67
  case 'x-deflate':
67
68
  case 'deflate':
68
- outputStream = (0, node_zlib_1.createInflate)();
69
+ outputStream = node_zlib_1.default.createInflate();
69
70
  break;
70
71
  case 'x-deflate-raw':
71
72
  case 'deflate-raw':
72
- outputStream = (0, node_zlib_1.createInflateRaw)();
73
+ outputStream = node_zlib_1.default.createInflateRaw();
73
74
  break;
74
75
  case 'br':
75
- outputStream = (0, node_zlib_1.createBrotliDecompress)();
76
+ outputStream = node_zlib_1.default.createBrotliDecompress();
77
+ break;
78
+ case 'zstd':
79
+ outputStream = node_zlib_1.default.createZstdDecompress();
76
80
  break;
77
81
  }
78
82
  if (nodeResponse.headers.location && (0, utils_js_1.shouldRedirect)(nodeResponse.statusCode)) {
package/cjs/utils.js CHANGED
@@ -10,7 +10,10 @@ exports.shouldRedirect = shouldRedirect;
10
10
  exports.pipeThrough = pipeThrough;
11
11
  exports.endStream = endStream;
12
12
  exports.safeWrite = safeWrite;
13
+ exports.getSupportedFormats = getSupportedFormats;
14
+ const tslib_1 = require("tslib");
13
15
  const node_events_1 = require("node:events");
16
+ const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
14
17
  function isHeadersInstance(obj) {
15
18
  return obj?.forEach != null;
16
19
  }
@@ -109,3 +112,13 @@ class AbortError extends Error {
109
112
  this.name = 'AbortError';
110
113
  }
111
114
  }
115
+ function getSupportedFormats() {
116
+ const baseFormats = ['gzip', 'deflate', 'br'];
117
+ if (!globalThis.process?.versions?.node?.startsWith('2')) {
118
+ baseFormats.push('deflate-raw');
119
+ }
120
+ if (node_zlib_1.default.createZstdCompress != null) {
121
+ baseFormats.push('zstd');
122
+ }
123
+ return baseFormats;
124
+ }
@@ -1,24 +1,26 @@
1
- import { createBrotliCompress, createDeflate, createDeflateRaw, createGzip } from 'node:zlib';
1
+ import zlib from 'node:zlib';
2
2
  import { PonyfillTransformStream } from './TransformStream.js';
3
+ import { getSupportedFormats } from './utils.js';
3
4
  export class PonyfillCompressionStream extends PonyfillTransformStream {
4
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
5
- ? ['gzip', 'deflate', 'br']
6
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
5
+ static supportedFormats = getSupportedFormats();
7
6
  constructor(compressionFormat) {
8
7
  switch (compressionFormat) {
9
8
  case 'x-gzip':
10
9
  case 'gzip':
11
- super(createGzip());
10
+ super(zlib.createGzip());
12
11
  break;
13
12
  case 'x-deflate':
14
13
  case 'deflate':
15
- super(createDeflate());
14
+ super(zlib.createDeflate());
16
15
  break;
17
16
  case 'deflate-raw':
18
- super(createDeflateRaw());
17
+ super(zlib.createDeflateRaw());
19
18
  break;
20
19
  case 'br':
21
- super(createBrotliCompress());
20
+ super(zlib.createBrotliCompress());
21
+ break;
22
+ case 'zstd':
23
+ super(zlib.createZstdCompress());
22
24
  break;
23
25
  default:
24
26
  throw new Error(`Unsupported compression format: ${compressionFormat}`);
@@ -1,24 +1,26 @@
1
- import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib';
1
+ import zlib from 'node:zlib';
2
2
  import { PonyfillTransformStream } from './TransformStream.js';
3
+ import { getSupportedFormats } from './utils.js';
3
4
  export class PonyfillDecompressionStream extends PonyfillTransformStream {
4
- static supportedFormats = globalThis.process?.version?.startsWith('v2')
5
- ? ['gzip', 'deflate', 'br']
6
- : ['gzip', 'deflate', 'deflate-raw', 'br'];
5
+ static supportedFormats = getSupportedFormats();
7
6
  constructor(compressionFormat) {
8
7
  switch (compressionFormat) {
9
8
  case 'x-gzip':
10
9
  case 'gzip':
11
- super(createGunzip());
10
+ super(zlib.createGunzip());
12
11
  break;
13
12
  case 'x-deflate':
14
13
  case 'deflate':
15
- super(createInflate());
14
+ super(zlib.createInflate());
16
15
  break;
17
16
  case 'deflate-raw':
18
- super(createInflateRaw());
17
+ super(zlib.createInflateRaw());
19
18
  break;
20
19
  case 'br':
21
- super(createBrotliDecompress());
20
+ super(zlib.createBrotliDecompress());
21
+ break;
22
+ case 'zstd':
23
+ super(zlib.createZstdDecompress());
22
24
  break;
23
25
  default:
24
26
  throw new TypeError(`Unsupported compression format: '${compressionFormat}'`);
@@ -1,7 +1,7 @@
1
1
  import { request as httpRequest, STATUS_CODES } from 'node:http';
2
2
  import { request as httpsRequest } from 'node:https';
3
3
  import { PassThrough, Readable } from 'node:stream';
4
- import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib';
4
+ import zlib from 'node:zlib';
5
5
  import { handleMaybePromise } from '@whatwg-node/promise-helpers';
6
6
  import { PonyfillRequest } from './Request.js';
7
7
  import { PonyfillResponse } from './Response.js';
@@ -58,18 +58,21 @@ export function fetchNodeHttp(fetchRequest) {
58
58
  switch (contentEncoding) {
59
59
  case 'x-gzip':
60
60
  case 'gzip':
61
- outputStream = createGunzip();
61
+ outputStream = zlib.createGunzip();
62
62
  break;
63
63
  case 'x-deflate':
64
64
  case 'deflate':
65
- outputStream = createInflate();
65
+ outputStream = zlib.createInflate();
66
66
  break;
67
67
  case 'x-deflate-raw':
68
68
  case 'deflate-raw':
69
- outputStream = createInflateRaw();
69
+ outputStream = zlib.createInflateRaw();
70
70
  break;
71
71
  case 'br':
72
- outputStream = createBrotliDecompress();
72
+ outputStream = zlib.createBrotliDecompress();
73
+ break;
74
+ case 'zstd':
75
+ outputStream = zlib.createZstdDecompress();
73
76
  break;
74
77
  }
75
78
  if (nodeResponse.headers.location && shouldRedirect(nodeResponse.statusCode)) {
package/esm/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { once } from 'node:events';
2
+ import zlib from 'node:zlib';
2
3
  function isHeadersInstance(obj) {
3
4
  return obj?.forEach != null;
4
5
  }
@@ -96,3 +97,13 @@ class AbortError extends Error {
96
97
  this.name = 'AbortError';
97
98
  }
98
99
  }
100
+ export function getSupportedFormats() {
101
+ const baseFormats = ['gzip', 'deflate', 'br'];
102
+ if (!globalThis.process?.versions?.node?.startsWith('2')) {
103
+ baseFormats.push('deflate-raw');
104
+ }
105
+ if (zlib.createZstdCompress != null) {
106
+ baseFormats.push('zstd');
107
+ }
108
+ return baseFormats;
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.8.2",
3
+ "version": "0.8.3-alpha-20251110163100-4652b77de1cf710e75445db45d91cdf62127a39f",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -1,5 +1,5 @@
1
1
  import { PonyfillTransformStream } from './TransformStream.cjs';
2
- export type PonyfillCompressionFormat = 'x-gzip' | 'gzip' | 'x-deflate' | 'deflate' | 'deflate-raw' | 'br';
2
+ export type PonyfillCompressionFormat = 'x-gzip' | 'gzip' | 'x-deflate' | 'deflate' | 'deflate-raw' | 'br' | 'zstd';
3
3
  export declare class PonyfillCompressionStream extends PonyfillTransformStream implements CompressionStream {
4
4
  static supportedFormats: PonyfillCompressionFormat[];
5
5
  constructor(compressionFormat: PonyfillCompressionFormat);
@@ -1,5 +1,5 @@
1
1
  import { PonyfillTransformStream } from './TransformStream.js';
2
- export type PonyfillCompressionFormat = 'x-gzip' | 'gzip' | 'x-deflate' | 'deflate' | 'deflate-raw' | 'br';
2
+ export type PonyfillCompressionFormat = 'x-gzip' | 'gzip' | 'x-deflate' | 'deflate' | 'deflate-raw' | 'br' | 'zstd';
3
3
  export declare class PonyfillCompressionStream extends PonyfillTransformStream implements CompressionStream {
4
4
  static supportedFormats: PonyfillCompressionFormat[];
5
5
  constructor(compressionFormat: PonyfillCompressionFormat);
@@ -1,4 +1,5 @@
1
1
  import { Readable, Writable } from 'node:stream';
2
+ import { PonyfillCompressionFormat } from './CompressionStream';
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 { fakePromise } from '@whatwg-node/promise-helpers';
@@ -16,3 +17,4 @@ export declare function endStream(stream: {
16
17
  end: () => void;
17
18
  }): void;
18
19
  export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
20
+ export declare function getSupportedFormats(): PonyfillCompressionFormat[];
@@ -1,4 +1,5 @@
1
1
  import { Readable, Writable } from 'node:stream';
2
+ import { PonyfillCompressionFormat } from './CompressionStream';
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 { fakePromise } from '@whatwg-node/promise-helpers';
@@ -16,3 +17,4 @@ export declare function endStream(stream: {
16
17
  end: () => void;
17
18
  }): void;
18
19
  export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
20
+ export declare function getSupportedFormats(): PonyfillCompressionFormat[];