@whatwg-node/node-fetch 0.4.4-alpha-20230613125046-1d1ae5e → 0.4.4-alpha-20230613135956-bb8c0b1
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/Headers.js +60 -1
- package/cjs/Request.js +2 -2
- package/cjs/Response.js +18 -23
- package/esm/Headers.js +60 -1
- package/esm/Request.js +2 -2
- package/esm/Response.js +18 -23
- package/package.json +1 -1
- package/typings/Response.d.cts +1 -1
- package/typings/Response.d.ts +1 -1
package/cjs/Headers.js
CHANGED
@@ -108,21 +108,80 @@ class PonyfillHeaders {
|
|
108
108
|
this.getMap().delete(key);
|
109
109
|
}
|
110
110
|
forEach(callback) {
|
111
|
+
if (!this.mapIsBuilt) {
|
112
|
+
if (this.headersInit) {
|
113
|
+
if (Array.isArray(this.headersInit)) {
|
114
|
+
this.headersInit.forEach(([key, value]) => {
|
115
|
+
callback(value, key, this);
|
116
|
+
});
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
if (isHeadersLike(this.headersInit)) {
|
120
|
+
this.headersInit.forEach(callback);
|
121
|
+
return;
|
122
|
+
}
|
123
|
+
Object.entries(this.headersInit).forEach(([key, value]) => {
|
124
|
+
if (value != null) {
|
125
|
+
if (Array.isArray(value)) {
|
126
|
+
value.forEach(v => {
|
127
|
+
callback(v, key, this);
|
128
|
+
});
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
callback(value, key, this);
|
132
|
+
}
|
133
|
+
});
|
134
|
+
}
|
135
|
+
return;
|
136
|
+
}
|
111
137
|
this.getMap().forEach((value, key) => {
|
112
138
|
callback(value, key, this);
|
113
139
|
});
|
114
140
|
}
|
115
141
|
keys() {
|
142
|
+
if (!this.mapIsBuilt) {
|
143
|
+
if (this.headersInit) {
|
144
|
+
if (Array.isArray(this.headersInit)) {
|
145
|
+
return this.headersInit.map(([key]) => key)[Symbol.iterator]();
|
146
|
+
}
|
147
|
+
if (isHeadersLike(this.headersInit)) {
|
148
|
+
return this.headersInit.keys();
|
149
|
+
}
|
150
|
+
return Object.keys(this.headersInit)[Symbol.iterator]();
|
151
|
+
}
|
152
|
+
}
|
116
153
|
return this.getMap().keys();
|
117
154
|
}
|
118
155
|
values() {
|
156
|
+
if (!this.mapIsBuilt) {
|
157
|
+
if (this.headersInit) {
|
158
|
+
if (Array.isArray(this.headersInit)) {
|
159
|
+
return this.headersInit.map(([, value]) => value)[Symbol.iterator]();
|
160
|
+
}
|
161
|
+
if (isHeadersLike(this.headersInit)) {
|
162
|
+
return this.headersInit.values();
|
163
|
+
}
|
164
|
+
return Object.values(this.headersInit)[Symbol.iterator]();
|
165
|
+
}
|
166
|
+
}
|
119
167
|
return this.getMap().values();
|
120
168
|
}
|
121
169
|
entries() {
|
170
|
+
if (!this.mapIsBuilt) {
|
171
|
+
if (this.headersInit) {
|
172
|
+
if (Array.isArray(this.headersInit)) {
|
173
|
+
return this.headersInit[Symbol.iterator]();
|
174
|
+
}
|
175
|
+
if (isHeadersLike(this.headersInit)) {
|
176
|
+
return this.headersInit.entries();
|
177
|
+
}
|
178
|
+
return Object.entries(this.headersInit)[Symbol.iterator]();
|
179
|
+
}
|
180
|
+
}
|
122
181
|
return this.getMap().entries();
|
123
182
|
}
|
124
183
|
[Symbol.iterator]() {
|
125
|
-
return this.
|
184
|
+
return this.entries();
|
126
185
|
}
|
127
186
|
}
|
128
187
|
exports.PonyfillHeaders = PonyfillHeaders;
|
package/cjs/Request.js
CHANGED
@@ -28,8 +28,6 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
28
28
|
requestInit = options;
|
29
29
|
}
|
30
30
|
super(bodyInit, options);
|
31
|
-
this.destination = '';
|
32
|
-
this.priority = 'auto';
|
33
31
|
this.cache = requestInit?.cache || 'default';
|
34
32
|
this.credentials = requestInit?.credentials || 'same-origin';
|
35
33
|
this.headers =
|
@@ -47,6 +45,8 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
47
45
|
this.headersSerializer = requestInit?.headersSerializer || utils_js_1.getHeadersObj;
|
48
46
|
this.agent = requestInit?.agent;
|
49
47
|
this.url = url || '';
|
48
|
+
this.destination = 'document';
|
49
|
+
this.priority = 'auto';
|
50
50
|
const contentTypeInHeaders = this.headers.get('content-type');
|
51
51
|
if (!contentTypeInHeaders) {
|
52
52
|
if (this.contentType) {
|
package/cjs/Response.js
CHANGED
@@ -5,30 +5,18 @@ const http_1 = require("http");
|
|
5
5
|
const Body_js_1 = require("./Body.js");
|
6
6
|
const Headers_js_1 = require("./Headers.js");
|
7
7
|
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
8
|
-
const DEFAULT_JSON_HEADERS_INIT = {
|
9
|
-
'content-type': JSON_CONTENT_TYPE,
|
10
|
-
};
|
11
|
-
const DEFAULT_JSON_HEADERS = new Headers_js_1.PonyfillHeaders(DEFAULT_JSON_HEADERS_INIT);
|
12
|
-
const DEFAULT_JSON_INIT = {
|
13
|
-
headers: DEFAULT_JSON_HEADERS_INIT,
|
14
|
-
};
|
15
8
|
class PonyfillResponse extends Body_js_1.PonyfillBody {
|
16
9
|
constructor(body, init) {
|
17
10
|
super(body || null, init);
|
18
|
-
this.headers =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
this.
|
23
|
-
this.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
this.statusText = init.statusText || http_1.STATUS_CODES[this.status] || 'OK';
|
28
|
-
this.url = init.url || '';
|
29
|
-
this.redirected = init.redirected || false;
|
30
|
-
this.type = init.type || 'default';
|
31
|
-
}
|
11
|
+
this.headers =
|
12
|
+
init?.headers && (0, Headers_js_1.isHeadersLike)(init.headers)
|
13
|
+
? init.headers
|
14
|
+
: new Headers_js_1.PonyfillHeaders(init?.headers);
|
15
|
+
this.status = init?.status || 200;
|
16
|
+
this.statusText = init?.statusText || http_1.STATUS_CODES[this.status] || 'OK';
|
17
|
+
this.url = init?.url || '';
|
18
|
+
this.redirected = init?.redirected || false;
|
19
|
+
this.type = init?.type || 'default';
|
32
20
|
const contentTypeInHeaders = this.headers.get('content-type');
|
33
21
|
if (!contentTypeInHeaders) {
|
34
22
|
if (this.contentType) {
|
@@ -72,18 +60,25 @@ class PonyfillResponse extends Body_js_1.PonyfillBody {
|
|
72
60
|
});
|
73
61
|
}
|
74
62
|
static json(data, init) {
|
63
|
+
const jsonStr = JSON.stringify(data);
|
75
64
|
if (init != null) {
|
76
65
|
if (init.headers != null) {
|
77
66
|
init.headers = new Headers_js_1.PonyfillHeaders(init.headers);
|
78
67
|
if (!init.headers.has('content-type')) {
|
79
68
|
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
80
69
|
}
|
70
|
+
if (!init.headers.has('content-length')) {
|
71
|
+
init.headers.set('content-length', Buffer.byteLength(jsonStr).toString());
|
72
|
+
}
|
81
73
|
}
|
82
74
|
else {
|
83
|
-
init.headers =
|
75
|
+
init.headers = [
|
76
|
+
['content-type', JSON_CONTENT_TYPE],
|
77
|
+
['content-length', Buffer.byteLength(jsonStr).toString()],
|
78
|
+
];
|
84
79
|
}
|
85
80
|
}
|
86
|
-
return new PonyfillResponse(JSON.stringify(data), init
|
81
|
+
return new PonyfillResponse(JSON.stringify(data), init);
|
87
82
|
}
|
88
83
|
}
|
89
84
|
exports.PonyfillResponse = PonyfillResponse;
|
package/esm/Headers.js
CHANGED
@@ -104,20 +104,79 @@ export class PonyfillHeaders {
|
|
104
104
|
this.getMap().delete(key);
|
105
105
|
}
|
106
106
|
forEach(callback) {
|
107
|
+
if (!this.mapIsBuilt) {
|
108
|
+
if (this.headersInit) {
|
109
|
+
if (Array.isArray(this.headersInit)) {
|
110
|
+
this.headersInit.forEach(([key, value]) => {
|
111
|
+
callback(value, key, this);
|
112
|
+
});
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
if (isHeadersLike(this.headersInit)) {
|
116
|
+
this.headersInit.forEach(callback);
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
Object.entries(this.headersInit).forEach(([key, value]) => {
|
120
|
+
if (value != null) {
|
121
|
+
if (Array.isArray(value)) {
|
122
|
+
value.forEach(v => {
|
123
|
+
callback(v, key, this);
|
124
|
+
});
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
callback(value, key, this);
|
128
|
+
}
|
129
|
+
});
|
130
|
+
}
|
131
|
+
return;
|
132
|
+
}
|
107
133
|
this.getMap().forEach((value, key) => {
|
108
134
|
callback(value, key, this);
|
109
135
|
});
|
110
136
|
}
|
111
137
|
keys() {
|
138
|
+
if (!this.mapIsBuilt) {
|
139
|
+
if (this.headersInit) {
|
140
|
+
if (Array.isArray(this.headersInit)) {
|
141
|
+
return this.headersInit.map(([key]) => key)[Symbol.iterator]();
|
142
|
+
}
|
143
|
+
if (isHeadersLike(this.headersInit)) {
|
144
|
+
return this.headersInit.keys();
|
145
|
+
}
|
146
|
+
return Object.keys(this.headersInit)[Symbol.iterator]();
|
147
|
+
}
|
148
|
+
}
|
112
149
|
return this.getMap().keys();
|
113
150
|
}
|
114
151
|
values() {
|
152
|
+
if (!this.mapIsBuilt) {
|
153
|
+
if (this.headersInit) {
|
154
|
+
if (Array.isArray(this.headersInit)) {
|
155
|
+
return this.headersInit.map(([, value]) => value)[Symbol.iterator]();
|
156
|
+
}
|
157
|
+
if (isHeadersLike(this.headersInit)) {
|
158
|
+
return this.headersInit.values();
|
159
|
+
}
|
160
|
+
return Object.values(this.headersInit)[Symbol.iterator]();
|
161
|
+
}
|
162
|
+
}
|
115
163
|
return this.getMap().values();
|
116
164
|
}
|
117
165
|
entries() {
|
166
|
+
if (!this.mapIsBuilt) {
|
167
|
+
if (this.headersInit) {
|
168
|
+
if (Array.isArray(this.headersInit)) {
|
169
|
+
return this.headersInit[Symbol.iterator]();
|
170
|
+
}
|
171
|
+
if (isHeadersLike(this.headersInit)) {
|
172
|
+
return this.headersInit.entries();
|
173
|
+
}
|
174
|
+
return Object.entries(this.headersInit)[Symbol.iterator]();
|
175
|
+
}
|
176
|
+
}
|
118
177
|
return this.getMap().entries();
|
119
178
|
}
|
120
179
|
[Symbol.iterator]() {
|
121
|
-
return this.
|
180
|
+
return this.entries();
|
122
181
|
}
|
123
182
|
}
|
package/esm/Request.js
CHANGED
@@ -25,8 +25,6 @@ export class PonyfillRequest extends PonyfillBody {
|
|
25
25
|
requestInit = options;
|
26
26
|
}
|
27
27
|
super(bodyInit, options);
|
28
|
-
this.destination = '';
|
29
|
-
this.priority = 'auto';
|
30
28
|
this.cache = requestInit?.cache || 'default';
|
31
29
|
this.credentials = requestInit?.credentials || 'same-origin';
|
32
30
|
this.headers =
|
@@ -44,6 +42,8 @@ export class PonyfillRequest extends PonyfillBody {
|
|
44
42
|
this.headersSerializer = requestInit?.headersSerializer || getHeadersObj;
|
45
43
|
this.agent = requestInit?.agent;
|
46
44
|
this.url = url || '';
|
45
|
+
this.destination = 'document';
|
46
|
+
this.priority = 'auto';
|
47
47
|
const contentTypeInHeaders = this.headers.get('content-type');
|
48
48
|
if (!contentTypeInHeaders) {
|
49
49
|
if (this.contentType) {
|
package/esm/Response.js
CHANGED
@@ -2,30 +2,18 @@ import { STATUS_CODES } from 'http';
|
|
2
2
|
import { PonyfillBody } from './Body.js';
|
3
3
|
import { isHeadersLike, PonyfillHeaders } from './Headers.js';
|
4
4
|
const JSON_CONTENT_TYPE = 'application/json; charset=utf-8';
|
5
|
-
const DEFAULT_JSON_HEADERS_INIT = {
|
6
|
-
'content-type': JSON_CONTENT_TYPE,
|
7
|
-
};
|
8
|
-
const DEFAULT_JSON_HEADERS = new PonyfillHeaders(DEFAULT_JSON_HEADERS_INIT);
|
9
|
-
const DEFAULT_JSON_INIT = {
|
10
|
-
headers: DEFAULT_JSON_HEADERS_INIT,
|
11
|
-
};
|
12
5
|
export class PonyfillResponse extends PonyfillBody {
|
13
6
|
constructor(body, init) {
|
14
7
|
super(body || null, init);
|
15
|
-
this.headers =
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
this.
|
20
|
-
this.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
this.statusText = init.statusText || STATUS_CODES[this.status] || 'OK';
|
25
|
-
this.url = init.url || '';
|
26
|
-
this.redirected = init.redirected || false;
|
27
|
-
this.type = init.type || 'default';
|
28
|
-
}
|
8
|
+
this.headers =
|
9
|
+
init?.headers && isHeadersLike(init.headers)
|
10
|
+
? init.headers
|
11
|
+
: new PonyfillHeaders(init?.headers);
|
12
|
+
this.status = init?.status || 200;
|
13
|
+
this.statusText = init?.statusText || STATUS_CODES[this.status] || 'OK';
|
14
|
+
this.url = init?.url || '';
|
15
|
+
this.redirected = init?.redirected || false;
|
16
|
+
this.type = init?.type || 'default';
|
29
17
|
const contentTypeInHeaders = this.headers.get('content-type');
|
30
18
|
if (!contentTypeInHeaders) {
|
31
19
|
if (this.contentType) {
|
@@ -69,17 +57,24 @@ export class PonyfillResponse extends PonyfillBody {
|
|
69
57
|
});
|
70
58
|
}
|
71
59
|
static json(data, init) {
|
60
|
+
const jsonStr = JSON.stringify(data);
|
72
61
|
if (init != null) {
|
73
62
|
if (init.headers != null) {
|
74
63
|
init.headers = new PonyfillHeaders(init.headers);
|
75
64
|
if (!init.headers.has('content-type')) {
|
76
65
|
init.headers.set('content-type', JSON_CONTENT_TYPE);
|
77
66
|
}
|
67
|
+
if (!init.headers.has('content-length')) {
|
68
|
+
init.headers.set('content-length', Buffer.byteLength(jsonStr).toString());
|
69
|
+
}
|
78
70
|
}
|
79
71
|
else {
|
80
|
-
init.headers =
|
72
|
+
init.headers = [
|
73
|
+
['content-type', JSON_CONTENT_TYPE],
|
74
|
+
['content-length', Buffer.byteLength(jsonStr).toString()],
|
75
|
+
];
|
81
76
|
}
|
82
77
|
}
|
83
|
-
return new PonyfillResponse(JSON.stringify(data), init
|
78
|
+
return new PonyfillResponse(JSON.stringify(data), init);
|
84
79
|
}
|
85
80
|
}
|
package/package.json
CHANGED
package/typings/Response.d.cts
CHANGED
@@ -7,8 +7,8 @@ export type ResponsePonyfilInit = PonyfillBodyOptions & Omit<ResponseInit, 'head
|
|
7
7
|
type?: ResponseType;
|
8
8
|
};
|
9
9
|
export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> implements Response {
|
10
|
-
constructor(body?: BodyPonyfillInit | null, init?: ResponsePonyfilInit);
|
11
10
|
headers: Headers;
|
11
|
+
constructor(body?: BodyPonyfillInit | null, init?: ResponsePonyfilInit);
|
12
12
|
get ok(): boolean;
|
13
13
|
status: number;
|
14
14
|
statusText: string;
|
package/typings/Response.d.ts
CHANGED
@@ -7,8 +7,8 @@ export type ResponsePonyfilInit = PonyfillBodyOptions & Omit<ResponseInit, 'head
|
|
7
7
|
type?: ResponseType;
|
8
8
|
};
|
9
9
|
export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> implements Response {
|
10
|
-
constructor(body?: BodyPonyfillInit | null, init?: ResponsePonyfilInit);
|
11
10
|
headers: Headers;
|
11
|
+
constructor(body?: BodyPonyfillInit | null, init?: ResponsePonyfilInit);
|
12
12
|
get ok(): boolean;
|
13
13
|
status: number;
|
14
14
|
statusText: string;
|