@whatwg-node/node-fetch 0.7.25-alpha-20250730140253-899e500946f54513ea71cd1804e5d068bcf55c57 → 0.7.25-alpha-20250731231608-1ed5805b7f2d6c45e43801caebb747d50101df7a

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/Blob.js CHANGED
@@ -148,11 +148,11 @@ class PonyfillBlob {
148
148
  if (this.blobParts.length === 1) {
149
149
  if (node_buffer_1.Buffer.isBuffer(this.blobParts[0])) {
150
150
  this._buffer = this.blobParts[0];
151
- return (0, utils_js_1.fakePromise)(this.blobParts[0]);
151
+ return (0, utils_js_1.fakePromise)(this._buffer);
152
152
  }
153
153
  if (this.blobParts[0] instanceof Uint8Array) {
154
154
  this._buffer = node_buffer_1.Buffer.from(this.blobParts[0]);
155
- return (0, utils_js_1.fakePromise)(this.blobParts[0]);
155
+ return (0, utils_js_1.fakePromise)(this._buffer);
156
156
  }
157
157
  if (hasBytesMethod(this.blobParts[0])) {
158
158
  return this.blobParts[0].bytes();
package/cjs/Response.js CHANGED
@@ -48,15 +48,60 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
48
48
  status,
49
49
  });
50
50
  }
51
- static json(data, init = {}) {
52
- init.headers =
53
- init?.headers && (0, Headers_js_1.isHeadersLike)(init.headers)
54
- ? init.headers
55
- : new Headers_js_1.PonyfillHeaders(init?.headers);
56
- if (!init.headers.has('content-type')) {
57
- init.headers.set('content-type', JSON_CONTENT_TYPE);
51
+ static json(data, init) {
52
+ const bodyInit = JSON.stringify(data);
53
+ if (!init) {
54
+ init = {
55
+ headers: {
56
+ 'content-type': JSON_CONTENT_TYPE,
57
+ 'content-length': Buffer.byteLength(bodyInit).toString(),
58
+ },
59
+ };
60
+ }
61
+ else if (!init.headers) {
62
+ init.headers = {
63
+ 'content-type': JSON_CONTENT_TYPE,
64
+ 'content-length': Buffer.byteLength(bodyInit).toString(),
65
+ };
66
+ }
67
+ else if ((0, Headers_js_1.isHeadersLike)(init.headers)) {
68
+ if (!init.headers.has('content-type')) {
69
+ init.headers.set('content-type', JSON_CONTENT_TYPE);
70
+ }
71
+ if (!init.headers.has('content-length')) {
72
+ init.headers.set('content-length', Buffer.byteLength(bodyInit).toString());
73
+ }
74
+ }
75
+ else if (Array.isArray(init.headers)) {
76
+ let contentTypeExists = false;
77
+ let contentLengthExists = false;
78
+ for (const [key] of init.headers) {
79
+ if (contentLengthExists && contentTypeExists) {
80
+ break;
81
+ }
82
+ if (!contentTypeExists && key.toLowerCase() === 'content-type') {
83
+ contentTypeExists = true;
84
+ }
85
+ else if (!contentLengthExists && key.toLowerCase() === 'content-length') {
86
+ contentLengthExists = true;
87
+ }
88
+ }
89
+ if (!contentTypeExists) {
90
+ init.headers.push(['content-type', JSON_CONTENT_TYPE]);
91
+ }
92
+ if (!contentLengthExists) {
93
+ init.headers.push(['content-length', Buffer.byteLength(bodyInit).toString()]);
94
+ }
95
+ }
96
+ else if (typeof init.headers === 'object') {
97
+ if (init.headers?.['content-type'] == null) {
98
+ init.headers['content-type'] = JSON_CONTENT_TYPE;
99
+ }
100
+ if (init.headers?.['content-length'] == null) {
101
+ init.headers['content-length'] = Buffer.byteLength(bodyInit).toString();
102
+ }
58
103
  }
59
- return new PonyfillResponse(JSON.stringify(data), init);
104
+ return new PonyfillResponse(bodyInit, init);
60
105
  }
61
106
  [Symbol.toStringTag] = 'Response';
62
107
  }
package/esm/Blob.js CHANGED
@@ -137,11 +137,11 @@ export class PonyfillBlob {
137
137
  if (this.blobParts.length === 1) {
138
138
  if (Buffer.isBuffer(this.blobParts[0])) {
139
139
  this._buffer = this.blobParts[0];
140
- return fakePromise(this.blobParts[0]);
140
+ return fakePromise(this._buffer);
141
141
  }
142
142
  if (this.blobParts[0] instanceof Uint8Array) {
143
143
  this._buffer = Buffer.from(this.blobParts[0]);
144
- return fakePromise(this.blobParts[0]);
144
+ return fakePromise(this._buffer);
145
145
  }
146
146
  if (hasBytesMethod(this.blobParts[0])) {
147
147
  return this.blobParts[0].bytes();
package/esm/Response.js CHANGED
@@ -45,15 +45,60 @@ export class PonyfillResponse extends PonyfillBody {
45
45
  status,
46
46
  });
47
47
  }
48
- static json(data, init = {}) {
49
- init.headers =
50
- init?.headers && isHeadersLike(init.headers)
51
- ? init.headers
52
- : new PonyfillHeaders(init?.headers);
53
- if (!init.headers.has('content-type')) {
54
- init.headers.set('content-type', JSON_CONTENT_TYPE);
48
+ static json(data, init) {
49
+ const bodyInit = JSON.stringify(data);
50
+ if (!init) {
51
+ init = {
52
+ headers: {
53
+ 'content-type': JSON_CONTENT_TYPE,
54
+ 'content-length': Buffer.byteLength(bodyInit).toString(),
55
+ },
56
+ };
57
+ }
58
+ else if (!init.headers) {
59
+ init.headers = {
60
+ 'content-type': JSON_CONTENT_TYPE,
61
+ 'content-length': Buffer.byteLength(bodyInit).toString(),
62
+ };
63
+ }
64
+ else if (isHeadersLike(init.headers)) {
65
+ if (!init.headers.has('content-type')) {
66
+ init.headers.set('content-type', JSON_CONTENT_TYPE);
67
+ }
68
+ if (!init.headers.has('content-length')) {
69
+ init.headers.set('content-length', Buffer.byteLength(bodyInit).toString());
70
+ }
71
+ }
72
+ else if (Array.isArray(init.headers)) {
73
+ let contentTypeExists = false;
74
+ let contentLengthExists = false;
75
+ for (const [key] of init.headers) {
76
+ if (contentLengthExists && contentTypeExists) {
77
+ break;
78
+ }
79
+ if (!contentTypeExists && key.toLowerCase() === 'content-type') {
80
+ contentTypeExists = true;
81
+ }
82
+ else if (!contentLengthExists && key.toLowerCase() === 'content-length') {
83
+ contentLengthExists = true;
84
+ }
85
+ }
86
+ if (!contentTypeExists) {
87
+ init.headers.push(['content-type', JSON_CONTENT_TYPE]);
88
+ }
89
+ if (!contentLengthExists) {
90
+ init.headers.push(['content-length', Buffer.byteLength(bodyInit).toString()]);
91
+ }
92
+ }
93
+ else if (typeof init.headers === 'object') {
94
+ if (init.headers?.['content-type'] == null) {
95
+ init.headers['content-type'] = JSON_CONTENT_TYPE;
96
+ }
97
+ if (init.headers?.['content-length'] == null) {
98
+ init.headers['content-length'] = Buffer.byteLength(bodyInit).toString();
99
+ }
55
100
  }
56
- return new PonyfillResponse(JSON.stringify(data), init);
101
+ return new PonyfillResponse(bodyInit, init);
57
102
  }
58
103
  [Symbol.toStringTag] = 'Response';
59
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.25-alpha-20250730140253-899e500946f54513ea71cd1804e5d068bcf55c57",
3
+ "version": "0.7.25-alpha-20250731231608-1ed5805b7f2d6c45e43801caebb747d50101df7a",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -16,7 +16,7 @@ interface BlobOptions {
16
16
  size?: number | null;
17
17
  }
18
18
  export declare function hasBufferMethod(obj: any): obj is {
19
- buffer(): Promise<Buffer>;
19
+ buffer(): Promise<Buffer<ArrayBuffer>>;
20
20
  };
21
21
  export declare function hasArrayBufferMethod(obj: any): obj is {
22
22
  arrayBuffer(): Promise<ArrayBuffer>;
@@ -42,10 +42,10 @@ export declare class PonyfillBlob implements Blob {
42
42
  private encoding;
43
43
  private _size;
44
44
  constructor(blobParts?: BlobPart[], options?: BlobOptions);
45
- _buffer: Buffer | null;
46
- buffer(): Promise<Buffer<ArrayBufferLike>>;
45
+ _buffer: Buffer<ArrayBuffer> | null;
46
+ buffer(): Promise<Buffer<ArrayBuffer>>;
47
47
  arrayBuffer(): Promise<ArrayBuffer>;
48
- bytes(): Promise<Uint8Array>;
48
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
49
49
  _text: string | null;
50
50
  text(): Promise<string>;
51
51
  _json: any;
package/typings/Blob.d.ts CHANGED
@@ -16,7 +16,7 @@ interface BlobOptions {
16
16
  size?: number | null;
17
17
  }
18
18
  export declare function hasBufferMethod(obj: any): obj is {
19
- buffer(): Promise<Buffer>;
19
+ buffer(): Promise<Buffer<ArrayBuffer>>;
20
20
  };
21
21
  export declare function hasArrayBufferMethod(obj: any): obj is {
22
22
  arrayBuffer(): Promise<ArrayBuffer>;
@@ -42,10 +42,10 @@ export declare class PonyfillBlob implements Blob {
42
42
  private encoding;
43
43
  private _size;
44
44
  constructor(blobParts?: BlobPart[], options?: BlobOptions);
45
- _buffer: Buffer | null;
46
- buffer(): Promise<Buffer<ArrayBufferLike>>;
45
+ _buffer: Buffer<ArrayBuffer> | null;
46
+ buffer(): Promise<Buffer<ArrayBuffer>>;
47
47
  arrayBuffer(): Promise<ArrayBuffer>;
48
- bytes(): Promise<Uint8Array>;
48
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
49
49
  _text: string | null;
50
50
  text(): Promise<string>;
51
51
  _json: any;
@@ -34,18 +34,18 @@ export declare class PonyfillBody<TJSON = any> implements Body {
34
34
  protected handleContentLengthHeader(this: PonyfillBody & {
35
35
  headers: Headers;
36
36
  }, forceSet?: boolean): void;
37
- get body(): PonyfillReadableStream<Uint8Array> | null;
38
- _chunks: MaybePromise<Uint8Array[]> | null;
39
- _doCollectChunksFromReadableJob(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
40
- _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
+ get body(): PonyfillReadableStream<Uint8Array<ArrayBuffer>> | null;
38
+ _chunks: MaybePromise<Uint8Array<ArrayBuffer>[]> | null;
39
+ _doCollectChunksFromReadableJob(): MaybePromise<Uint8Array<ArrayBuffer>[]>;
40
+ _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBuffer>[]>;
41
41
  _blob: PonyfillBlob | null;
42
42
  blob(): Promise<PonyfillBlob>;
43
43
  _formData: PonyfillFormData | null;
44
44
  formData(opts?: {
45
45
  formDataLimits: FormDataLimits;
46
46
  }): Promise<PonyfillFormData>;
47
- buffer(): Promise<Buffer>;
48
- bytes(): Promise<Uint8Array>;
47
+ buffer(): Promise<Buffer<ArrayBuffer>>;
48
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
49
49
  arrayBuffer(): Promise<ArrayBuffer>;
50
50
  _json: TJSON | null;
51
51
  json(): Promise<TJSON>;
package/typings/Body.d.ts CHANGED
@@ -34,18 +34,18 @@ export declare class PonyfillBody<TJSON = any> implements Body {
34
34
  protected handleContentLengthHeader(this: PonyfillBody & {
35
35
  headers: Headers;
36
36
  }, forceSet?: boolean): void;
37
- get body(): PonyfillReadableStream<Uint8Array> | null;
38
- _chunks: MaybePromise<Uint8Array[]> | null;
39
- _doCollectChunksFromReadableJob(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
40
- _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
+ get body(): PonyfillReadableStream<Uint8Array<ArrayBuffer>> | null;
38
+ _chunks: MaybePromise<Uint8Array<ArrayBuffer>[]> | null;
39
+ _doCollectChunksFromReadableJob(): MaybePromise<Uint8Array<ArrayBuffer>[]>;
40
+ _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBuffer>[]>;
41
41
  _blob: PonyfillBlob | null;
42
42
  blob(): Promise<PonyfillBlob>;
43
43
  _formData: PonyfillFormData | null;
44
44
  formData(opts?: {
45
45
  formDataLimits: FormDataLimits;
46
46
  }): Promise<PonyfillFormData>;
47
- buffer(): Promise<Buffer>;
48
- bytes(): Promise<Uint8Array>;
47
+ buffer(): Promise<Buffer<ArrayBuffer>>;
48
+ bytes(): Promise<Uint8Array<ArrayBuffer>>;
49
49
  arrayBuffer(): Promise<ArrayBuffer>;
50
50
  _json: TJSON | null;
51
51
  json(): Promise<TJSON>;
@@ -18,6 +18,6 @@ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> i
18
18
  clone(): this;
19
19
  static error(): PonyfillResponse<any>;
20
20
  static redirect(url: string, status?: number): PonyfillResponse<any>;
21
- static json<T>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<any>;
21
+ static json<T = any>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<T>;
22
22
  [Symbol.toStringTag]: string;
23
23
  }
@@ -18,6 +18,6 @@ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> i
18
18
  clone(): this;
19
19
  static error(): PonyfillResponse<any>;
20
20
  static redirect(url: string, status?: number): PonyfillResponse<any>;
21
- static json<T>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<any>;
21
+ static json<T = any>(data: T, init?: ResponsePonyfilInit): PonyfillResponse<T>;
22
22
  [Symbol.toStringTag]: string;
23
23
  }
@@ -2,7 +2,7 @@ import { Buffer } from 'node:buffer';
2
2
  export declare class PonyfillTextEncoder implements TextEncoder {
3
3
  encoding: BufferEncoding;
4
4
  constructor(encoding?: BufferEncoding);
5
- encode(input: string): Buffer;
5
+ encode(input: string): Buffer<ArrayBuffer>;
6
6
  encodeInto(source: string, destination: Uint8Array): TextEncoderEncodeIntoResult;
7
7
  }
8
8
  export declare class PonyfillTextDecoder implements TextDecoder {
@@ -2,7 +2,7 @@ import { Buffer } from 'node:buffer';
2
2
  export declare class PonyfillTextEncoder implements TextEncoder {
3
3
  encoding: BufferEncoding;
4
4
  constructor(encoding?: BufferEncoding);
5
- encode(input: string): Buffer;
5
+ encode(input: string): Buffer<ArrayBuffer>;
6
6
  encodeInto(source: string, destination: Uint8Array): TextEncoderEncodeIntoResult;
7
7
  }
8
8
  export declare class PonyfillTextDecoder implements TextDecoder {