@whatwg-node/node-fetch 0.4.4-alpha-20230613121110-c7b77d2 → 0.4.4-alpha-20230613122807-eff9007

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
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
- var _PonyfillBlob_encoding;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.PonyfillBlob = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const ReadableStream_js_1 = require("./ReadableStream.js");
7
5
  const utils_js_1 = require("./utils.js");
8
6
  function getBlobPartAsBuffer(blobPart) {
@@ -30,9 +28,8 @@ function isBlob(obj) {
30
28
  class PonyfillBlob {
31
29
  constructor(blobParts, options) {
32
30
  this.blobParts = blobParts;
33
- _PonyfillBlob_encoding.set(this, void 0);
34
31
  this.type = options?.type || 'application/octet-stream';
35
- tslib_1.__classPrivateFieldSet(this, _PonyfillBlob_encoding, options?.encoding || 'utf8', "f");
32
+ this.encoding = options?.encoding || 'utf8';
36
33
  }
37
34
  async buffer() {
38
35
  const bufferChunks = [];
@@ -64,7 +61,7 @@ class PonyfillBlob {
64
61
  }
65
62
  else {
66
63
  const buf = getBlobPartAsBuffer(blobPart);
67
- text += buf.toString(tslib_1.__classPrivateFieldGet(this, _PonyfillBlob_encoding, "f"));
64
+ text += buf.toString(this.encoding);
68
65
  }
69
66
  }
70
67
  return text;
@@ -120,4 +117,3 @@ class PonyfillBlob {
120
117
  }
121
118
  }
122
119
  exports.PonyfillBlob = PonyfillBlob;
123
- _PonyfillBlob_encoding = new WeakMap();
package/cjs/Headers.js CHANGED
@@ -1,34 +1,95 @@
1
1
  "use strict";
2
- var _PonyfillHeaders_instances, _PonyfillHeaders_map, _PonyfillHeaders_mapIsBuilt, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, _PonyfillHeaders_objectOriginalKeysOfHeadersInit, _PonyfillHeaders_headersInit, _PonyfillHeaders__get, _PonyfillHeaders_getMap;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.PonyfillHeaders = exports.isHeadersLike = void 0;
5
- const tslib_1 = require("tslib");
6
4
  function isHeadersLike(headers) {
7
- return headers && typeof headers.get === 'function' && typeof headers.forEach === 'function';
5
+ return headers?.get && headers?.forEach;
8
6
  }
9
7
  exports.isHeadersLike = isHeadersLike;
10
8
  class PonyfillHeaders {
11
9
  constructor(headersInit) {
12
- _PonyfillHeaders_instances.add(this);
13
- _PonyfillHeaders_map.set(this, new Map());
14
- _PonyfillHeaders_mapIsBuilt.set(this, false);
15
- _PonyfillHeaders_objectNormalizedKeysOfHeadersInit.set(this, []);
16
- _PonyfillHeaders_objectOriginalKeysOfHeadersInit.set(this, []);
17
- _PonyfillHeaders_headersInit.set(this, void 0);
10
+ this.map = new Map();
11
+ this.mapIsBuilt = false;
12
+ this.objectNormalizedKeysOfHeadersInit = [];
13
+ this.objectOriginalKeysOfHeadersInit = [];
18
14
  if (isHeadersLike(headersInit)) {
19
15
  return headersInit;
20
16
  }
21
- tslib_1.__classPrivateFieldSet(this, _PonyfillHeaders_headersInit, headersInit, "f");
17
+ this.headersInit = headersInit;
18
+ }
19
+ // perf: we don't need to build `this.map` for Requests, as we can access the headers directly
20
+ _get(key) {
21
+ // If the map is built, reuse it
22
+ if (this.mapIsBuilt) {
23
+ return this.map.get(key.toLowerCase()) || null;
24
+ }
25
+ // If the map is not built, try to get the value from the this.headersInit
26
+ if (this.headersInit == null) {
27
+ return null;
28
+ }
29
+ const normalized = key.toLowerCase();
30
+ if (Array.isArray(this.headersInit)) {
31
+ return this.headersInit.find(header => header[0] === normalized);
32
+ }
33
+ else if (isHeadersLike(this.headersInit)) {
34
+ return this.headersInit.get(normalized);
35
+ }
36
+ else {
37
+ const initValue = this.headersInit[key] || this.headersInit[normalized];
38
+ if (initValue != null) {
39
+ return initValue;
40
+ }
41
+ if (!this.objectNormalizedKeysOfHeadersInit.length) {
42
+ Object.keys(this.headersInit).forEach(k => {
43
+ this.objectOriginalKeysOfHeadersInit.push(k);
44
+ this.objectNormalizedKeysOfHeadersInit.push(k.toLowerCase());
45
+ });
46
+ }
47
+ const index = this.objectNormalizedKeysOfHeadersInit.indexOf(normalized);
48
+ if (index === -1) {
49
+ return null;
50
+ }
51
+ const originalKey = this.objectOriginalKeysOfHeadersInit[index];
52
+ return this.headersInit[originalKey];
53
+ }
54
+ }
55
+ // perf: Build the map of headers lazily, only when we need to access all headers or write to it.
56
+ // I could do a getter here, but I'm too lazy to type `getter`.
57
+ getMap() {
58
+ if (this.mapIsBuilt) {
59
+ return this.map;
60
+ }
61
+ if (this.headersInit != null) {
62
+ if (Array.isArray(this.headersInit)) {
63
+ this.map = new Map(this.headersInit);
64
+ }
65
+ else if (isHeadersLike(this.headersInit)) {
66
+ this.headersInit.forEach((value, key) => {
67
+ this.map.set(key, value);
68
+ });
69
+ }
70
+ else {
71
+ for (const initKey in this.headersInit) {
72
+ const initValue = this.headersInit[initKey];
73
+ if (initValue != null) {
74
+ const normalizedValue = Array.isArray(initValue) ? initValue.join(', ') : initValue;
75
+ const normalizedKey = initKey.toLowerCase();
76
+ this.map.set(normalizedKey, normalizedValue);
77
+ }
78
+ }
79
+ }
80
+ }
81
+ this.mapIsBuilt = true;
82
+ return this.map;
22
83
  }
23
84
  append(name, value) {
24
85
  const key = name.toLowerCase();
25
- const existingValue = tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).get(key);
86
+ const existingValue = this.getMap().get(key);
26
87
  const finalValue = existingValue ? `${existingValue}, ${value}` : value;
27
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).set(key, finalValue);
88
+ this.getMap().set(key, finalValue);
28
89
  }
29
90
  get(name) {
30
91
  const key = name.toLowerCase();
31
- const value = tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders__get).call(this, key);
92
+ const value = this._get(key);
32
93
  if (value == null) {
33
94
  return null;
34
95
  }
@@ -39,92 +100,32 @@ class PonyfillHeaders {
39
100
  }
40
101
  has(name) {
41
102
  const key = name.toLowerCase();
42
- return !!tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders__get).call(this, key); // we might need to check if header exists and not just check if it's not nullable
103
+ return !!this._get(key); // we might need to check if header exists and not just check if it's not nullable
43
104
  }
44
105
  set(name, value) {
45
106
  const key = name.toLowerCase();
46
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).set(key, value);
107
+ this.getMap().set(key, value);
47
108
  }
48
109
  delete(name) {
49
110
  const key = name.toLowerCase();
50
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).delete(key);
111
+ this.getMap().delete(key);
51
112
  }
52
113
  forEach(callback) {
53
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).forEach((value, key) => {
114
+ this.getMap().forEach((value, key) => {
54
115
  callback(value, key, this);
55
116
  });
56
117
  }
57
118
  keys() {
58
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).keys();
119
+ return this.getMap().keys();
59
120
  }
60
121
  values() {
61
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).values();
122
+ return this.getMap().values();
62
123
  }
63
124
  entries() {
64
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).entries();
125
+ return this.getMap().entries();
65
126
  }
66
- [(_PonyfillHeaders_map = new WeakMap(), _PonyfillHeaders_mapIsBuilt = new WeakMap(), _PonyfillHeaders_objectNormalizedKeysOfHeadersInit = new WeakMap(), _PonyfillHeaders_objectOriginalKeysOfHeadersInit = new WeakMap(), _PonyfillHeaders_headersInit = new WeakMap(), _PonyfillHeaders_instances = new WeakSet(), _PonyfillHeaders__get = function _PonyfillHeaders__get(key) {
67
- // If the map is built, reuse it
68
- if (tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_mapIsBuilt, "f")) {
69
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_map, "f").get(key.toLowerCase()) || null;
70
- }
71
- // If the map is not built, try to get the value from the this.headersInit
72
- if (tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f") == null) {
73
- return null;
74
- }
75
- const normalized = key.toLowerCase();
76
- if (Array.isArray(tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
77
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f").find(header => header[0] === normalized);
78
- }
79
- else if (isHeadersLike(tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
80
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f").get(normalized);
81
- }
82
- else {
83
- const initValue = tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[key] || tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[normalized];
84
- if (initValue != null) {
85
- return initValue;
86
- }
87
- if (!tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, "f").length) {
88
- Object.keys(tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")).forEach(k => {
89
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_objectOriginalKeysOfHeadersInit, "f").push(k);
90
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, "f").push(k.toLowerCase());
91
- });
92
- }
93
- const index = tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, "f").indexOf(normalized);
94
- if (index === -1) {
95
- return null;
96
- }
97
- const originalKey = tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_objectOriginalKeysOfHeadersInit, "f")[index];
98
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[originalKey];
99
- }
100
- }, _PonyfillHeaders_getMap = function _PonyfillHeaders_getMap() {
101
- if (tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_mapIsBuilt, "f")) {
102
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_map, "f");
103
- }
104
- if (tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f") != null) {
105
- if (Array.isArray(tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
106
- tslib_1.__classPrivateFieldSet(this, _PonyfillHeaders_map, new Map(tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")), "f");
107
- }
108
- else if (isHeadersLike(tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
109
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f").forEach((value, key) => {
110
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_map, "f").set(key, value);
111
- });
112
- }
113
- else {
114
- for (const initKey in tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")) {
115
- const initValue = tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[initKey];
116
- if (initValue != null) {
117
- const normalizedValue = Array.isArray(initValue) ? initValue.join(', ') : initValue;
118
- const normalizedKey = initKey.toLowerCase();
119
- tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_map, "f").set(normalizedKey, normalizedValue);
120
- }
121
- }
122
- }
123
- }
124
- tslib_1.__classPrivateFieldSet(this, _PonyfillHeaders_mapIsBuilt, true, "f");
125
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_map, "f");
126
- }, Symbol.iterator)]() {
127
- return tslib_1.__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).entries();
127
+ [Symbol.iterator]() {
128
+ return this.getMap().entries();
128
129
  }
129
130
  }
130
131
  exports.PonyfillHeaders = PonyfillHeaders;
package/cjs/Request.js CHANGED
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
- var _PonyfillRequest_signal;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.PonyfillRequest = void 0;
5
- const tslib_1 = require("tslib");
6
4
  const Body_js_1 = require("./Body.js");
7
5
  const Headers_js_1 = require("./Headers.js");
8
6
  const utils_js_1 = require("./utils.js");
@@ -32,7 +30,6 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
32
30
  super(bodyInit, options);
33
31
  this.destination = '';
34
32
  this.priority = 'auto';
35
- _PonyfillRequest_signal.set(this, void 0);
36
33
  this.cache = requestInit?.cache || 'default';
37
34
  this.credentials = requestInit?.credentials || 'same-origin';
38
35
  this.headers =
@@ -46,7 +43,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
46
43
  this.redirect = requestInit?.redirect || 'follow';
47
44
  this.referrer = requestInit?.referrer || 'about:client';
48
45
  this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
49
- tslib_1.__classPrivateFieldSet(this, _PonyfillRequest_signal, requestInit?.signal, "f");
46
+ this._signal = requestInit?.signal;
50
47
  this.headersSerializer = requestInit?.headersSerializer || utils_js_1.getHeadersObj;
51
48
  this.agent = requestInit?.agent;
52
49
  this.url = url || '';
@@ -72,14 +69,13 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
72
69
  get signal() {
73
70
  // Create a new signal only if needed
74
71
  // Because the creation of signal is expensive
75
- if (!tslib_1.__classPrivateFieldGet(this, _PonyfillRequest_signal, "f")) {
76
- tslib_1.__classPrivateFieldSet(this, _PonyfillRequest_signal, new AbortController().signal, "f");
72
+ if (!this._signal) {
73
+ this._signal = new AbortController().signal;
77
74
  }
78
- return tslib_1.__classPrivateFieldGet(this, _PonyfillRequest_signal, "f");
75
+ return this._signal;
79
76
  }
80
77
  clone() {
81
78
  return new PonyfillRequest(this);
82
79
  }
83
80
  }
84
81
  exports.PonyfillRequest = PonyfillRequest;
85
- _PonyfillRequest_signal = new WeakMap();
package/esm/Blob.js CHANGED
@@ -1,5 +1,3 @@
1
- var _PonyfillBlob_encoding;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import { PonyfillReadableStream } from './ReadableStream.js';
4
2
  import { uint8ArrayToArrayBuffer } from './utils.js';
5
3
  function getBlobPartAsBuffer(blobPart) {
@@ -27,9 +25,8 @@ function isBlob(obj) {
27
25
  export class PonyfillBlob {
28
26
  constructor(blobParts, options) {
29
27
  this.blobParts = blobParts;
30
- _PonyfillBlob_encoding.set(this, void 0);
31
28
  this.type = options?.type || 'application/octet-stream';
32
- __classPrivateFieldSet(this, _PonyfillBlob_encoding, options?.encoding || 'utf8', "f");
29
+ this.encoding = options?.encoding || 'utf8';
33
30
  }
34
31
  async buffer() {
35
32
  const bufferChunks = [];
@@ -61,7 +58,7 @@ export class PonyfillBlob {
61
58
  }
62
59
  else {
63
60
  const buf = getBlobPartAsBuffer(blobPart);
64
- text += buf.toString(__classPrivateFieldGet(this, _PonyfillBlob_encoding, "f"));
61
+ text += buf.toString(this.encoding);
65
62
  }
66
63
  }
67
64
  return text;
@@ -116,4 +113,3 @@ export class PonyfillBlob {
116
113
  throw new Error('Not implemented');
117
114
  }
118
115
  }
119
- _PonyfillBlob_encoding = new WeakMap();
package/esm/Headers.js CHANGED
@@ -1,30 +1,91 @@
1
- var _PonyfillHeaders_instances, _PonyfillHeaders_map, _PonyfillHeaders_mapIsBuilt, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, _PonyfillHeaders_objectOriginalKeysOfHeadersInit, _PonyfillHeaders_headersInit, _PonyfillHeaders__get, _PonyfillHeaders_getMap;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  export function isHeadersLike(headers) {
4
- return headers && typeof headers.get === 'function' && typeof headers.forEach === 'function';
2
+ return headers?.get && headers?.forEach;
5
3
  }
6
4
  export class PonyfillHeaders {
7
5
  constructor(headersInit) {
8
- _PonyfillHeaders_instances.add(this);
9
- _PonyfillHeaders_map.set(this, new Map());
10
- _PonyfillHeaders_mapIsBuilt.set(this, false);
11
- _PonyfillHeaders_objectNormalizedKeysOfHeadersInit.set(this, []);
12
- _PonyfillHeaders_objectOriginalKeysOfHeadersInit.set(this, []);
13
- _PonyfillHeaders_headersInit.set(this, void 0);
6
+ this.map = new Map();
7
+ this.mapIsBuilt = false;
8
+ this.objectNormalizedKeysOfHeadersInit = [];
9
+ this.objectOriginalKeysOfHeadersInit = [];
14
10
  if (isHeadersLike(headersInit)) {
15
11
  return headersInit;
16
12
  }
17
- __classPrivateFieldSet(this, _PonyfillHeaders_headersInit, headersInit, "f");
13
+ this.headersInit = headersInit;
14
+ }
15
+ // perf: we don't need to build `this.map` for Requests, as we can access the headers directly
16
+ _get(key) {
17
+ // If the map is built, reuse it
18
+ if (this.mapIsBuilt) {
19
+ return this.map.get(key.toLowerCase()) || null;
20
+ }
21
+ // If the map is not built, try to get the value from the this.headersInit
22
+ if (this.headersInit == null) {
23
+ return null;
24
+ }
25
+ const normalized = key.toLowerCase();
26
+ if (Array.isArray(this.headersInit)) {
27
+ return this.headersInit.find(header => header[0] === normalized);
28
+ }
29
+ else if (isHeadersLike(this.headersInit)) {
30
+ return this.headersInit.get(normalized);
31
+ }
32
+ else {
33
+ const initValue = this.headersInit[key] || this.headersInit[normalized];
34
+ if (initValue != null) {
35
+ return initValue;
36
+ }
37
+ if (!this.objectNormalizedKeysOfHeadersInit.length) {
38
+ Object.keys(this.headersInit).forEach(k => {
39
+ this.objectOriginalKeysOfHeadersInit.push(k);
40
+ this.objectNormalizedKeysOfHeadersInit.push(k.toLowerCase());
41
+ });
42
+ }
43
+ const index = this.objectNormalizedKeysOfHeadersInit.indexOf(normalized);
44
+ if (index === -1) {
45
+ return null;
46
+ }
47
+ const originalKey = this.objectOriginalKeysOfHeadersInit[index];
48
+ return this.headersInit[originalKey];
49
+ }
50
+ }
51
+ // perf: Build the map of headers lazily, only when we need to access all headers or write to it.
52
+ // I could do a getter here, but I'm too lazy to type `getter`.
53
+ getMap() {
54
+ if (this.mapIsBuilt) {
55
+ return this.map;
56
+ }
57
+ if (this.headersInit != null) {
58
+ if (Array.isArray(this.headersInit)) {
59
+ this.map = new Map(this.headersInit);
60
+ }
61
+ else if (isHeadersLike(this.headersInit)) {
62
+ this.headersInit.forEach((value, key) => {
63
+ this.map.set(key, value);
64
+ });
65
+ }
66
+ else {
67
+ for (const initKey in this.headersInit) {
68
+ const initValue = this.headersInit[initKey];
69
+ if (initValue != null) {
70
+ const normalizedValue = Array.isArray(initValue) ? initValue.join(', ') : initValue;
71
+ const normalizedKey = initKey.toLowerCase();
72
+ this.map.set(normalizedKey, normalizedValue);
73
+ }
74
+ }
75
+ }
76
+ }
77
+ this.mapIsBuilt = true;
78
+ return this.map;
18
79
  }
19
80
  append(name, value) {
20
81
  const key = name.toLowerCase();
21
- const existingValue = __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).get(key);
82
+ const existingValue = this.getMap().get(key);
22
83
  const finalValue = existingValue ? `${existingValue}, ${value}` : value;
23
- __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).set(key, finalValue);
84
+ this.getMap().set(key, finalValue);
24
85
  }
25
86
  get(name) {
26
87
  const key = name.toLowerCase();
27
- const value = __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders__get).call(this, key);
88
+ const value = this._get(key);
28
89
  if (value == null) {
29
90
  return null;
30
91
  }
@@ -35,91 +96,31 @@ export class PonyfillHeaders {
35
96
  }
36
97
  has(name) {
37
98
  const key = name.toLowerCase();
38
- return !!__classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders__get).call(this, key); // we might need to check if header exists and not just check if it's not nullable
99
+ return !!this._get(key); // we might need to check if header exists and not just check if it's not nullable
39
100
  }
40
101
  set(name, value) {
41
102
  const key = name.toLowerCase();
42
- __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).set(key, value);
103
+ this.getMap().set(key, value);
43
104
  }
44
105
  delete(name) {
45
106
  const key = name.toLowerCase();
46
- __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).delete(key);
107
+ this.getMap().delete(key);
47
108
  }
48
109
  forEach(callback) {
49
- __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).forEach((value, key) => {
110
+ this.getMap().forEach((value, key) => {
50
111
  callback(value, key, this);
51
112
  });
52
113
  }
53
114
  keys() {
54
- return __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).keys();
115
+ return this.getMap().keys();
55
116
  }
56
117
  values() {
57
- return __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).values();
118
+ return this.getMap().values();
58
119
  }
59
120
  entries() {
60
- return __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).entries();
121
+ return this.getMap().entries();
61
122
  }
62
- [(_PonyfillHeaders_map = new WeakMap(), _PonyfillHeaders_mapIsBuilt = new WeakMap(), _PonyfillHeaders_objectNormalizedKeysOfHeadersInit = new WeakMap(), _PonyfillHeaders_objectOriginalKeysOfHeadersInit = new WeakMap(), _PonyfillHeaders_headersInit = new WeakMap(), _PonyfillHeaders_instances = new WeakSet(), _PonyfillHeaders__get = function _PonyfillHeaders__get(key) {
63
- // If the map is built, reuse it
64
- if (__classPrivateFieldGet(this, _PonyfillHeaders_mapIsBuilt, "f")) {
65
- return __classPrivateFieldGet(this, _PonyfillHeaders_map, "f").get(key.toLowerCase()) || null;
66
- }
67
- // If the map is not built, try to get the value from the this.headersInit
68
- if (__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f") == null) {
69
- return null;
70
- }
71
- const normalized = key.toLowerCase();
72
- if (Array.isArray(__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
73
- return __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f").find(header => header[0] === normalized);
74
- }
75
- else if (isHeadersLike(__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
76
- return __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f").get(normalized);
77
- }
78
- else {
79
- const initValue = __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[key] || __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[normalized];
80
- if (initValue != null) {
81
- return initValue;
82
- }
83
- if (!__classPrivateFieldGet(this, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, "f").length) {
84
- Object.keys(__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")).forEach(k => {
85
- __classPrivateFieldGet(this, _PonyfillHeaders_objectOriginalKeysOfHeadersInit, "f").push(k);
86
- __classPrivateFieldGet(this, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, "f").push(k.toLowerCase());
87
- });
88
- }
89
- const index = __classPrivateFieldGet(this, _PonyfillHeaders_objectNormalizedKeysOfHeadersInit, "f").indexOf(normalized);
90
- if (index === -1) {
91
- return null;
92
- }
93
- const originalKey = __classPrivateFieldGet(this, _PonyfillHeaders_objectOriginalKeysOfHeadersInit, "f")[index];
94
- return __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[originalKey];
95
- }
96
- }, _PonyfillHeaders_getMap = function _PonyfillHeaders_getMap() {
97
- if (__classPrivateFieldGet(this, _PonyfillHeaders_mapIsBuilt, "f")) {
98
- return __classPrivateFieldGet(this, _PonyfillHeaders_map, "f");
99
- }
100
- if (__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f") != null) {
101
- if (Array.isArray(__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
102
- __classPrivateFieldSet(this, _PonyfillHeaders_map, new Map(__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")), "f");
103
- }
104
- else if (isHeadersLike(__classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f"))) {
105
- __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f").forEach((value, key) => {
106
- __classPrivateFieldGet(this, _PonyfillHeaders_map, "f").set(key, value);
107
- });
108
- }
109
- else {
110
- for (const initKey in __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")) {
111
- const initValue = __classPrivateFieldGet(this, _PonyfillHeaders_headersInit, "f")[initKey];
112
- if (initValue != null) {
113
- const normalizedValue = Array.isArray(initValue) ? initValue.join(', ') : initValue;
114
- const normalizedKey = initKey.toLowerCase();
115
- __classPrivateFieldGet(this, _PonyfillHeaders_map, "f").set(normalizedKey, normalizedValue);
116
- }
117
- }
118
- }
119
- }
120
- __classPrivateFieldSet(this, _PonyfillHeaders_mapIsBuilt, true, "f");
121
- return __classPrivateFieldGet(this, _PonyfillHeaders_map, "f");
122
- }, Symbol.iterator)]() {
123
- return __classPrivateFieldGet(this, _PonyfillHeaders_instances, "m", _PonyfillHeaders_getMap).call(this).entries();
123
+ [Symbol.iterator]() {
124
+ return this.getMap().entries();
124
125
  }
125
126
  }
package/esm/Request.js CHANGED
@@ -1,5 +1,3 @@
1
- var _PonyfillRequest_signal;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import { PonyfillBody } from './Body.js';
4
2
  import { isHeadersLike, PonyfillHeaders } from './Headers.js';
5
3
  import { getHeadersObj } from './utils.js';
@@ -29,7 +27,6 @@ export class PonyfillRequest extends PonyfillBody {
29
27
  super(bodyInit, options);
30
28
  this.destination = '';
31
29
  this.priority = 'auto';
32
- _PonyfillRequest_signal.set(this, void 0);
33
30
  this.cache = requestInit?.cache || 'default';
34
31
  this.credentials = requestInit?.credentials || 'same-origin';
35
32
  this.headers =
@@ -43,7 +40,7 @@ export class PonyfillRequest extends PonyfillBody {
43
40
  this.redirect = requestInit?.redirect || 'follow';
44
41
  this.referrer = requestInit?.referrer || 'about:client';
45
42
  this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
46
- __classPrivateFieldSet(this, _PonyfillRequest_signal, requestInit?.signal, "f");
43
+ this._signal = requestInit?.signal;
47
44
  this.headersSerializer = requestInit?.headersSerializer || getHeadersObj;
48
45
  this.agent = requestInit?.agent;
49
46
  this.url = url || '';
@@ -69,13 +66,12 @@ export class PonyfillRequest extends PonyfillBody {
69
66
  get signal() {
70
67
  // Create a new signal only if needed
71
68
  // Because the creation of signal is expensive
72
- if (!__classPrivateFieldGet(this, _PonyfillRequest_signal, "f")) {
73
- __classPrivateFieldSet(this, _PonyfillRequest_signal, new AbortController().signal, "f");
69
+ if (!this._signal) {
70
+ this._signal = new AbortController().signal;
74
71
  }
75
- return __classPrivateFieldGet(this, _PonyfillRequest_signal, "f");
72
+ return this._signal;
76
73
  }
77
74
  clone() {
78
75
  return new PonyfillRequest(this);
79
76
  }
80
77
  }
81
- _PonyfillRequest_signal = new WeakMap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.4.4-alpha-20230613121110-c7b77d2",
3
+ "version": "0.4.4-alpha-20230613122807-eff9007",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -12,9 +12,9 @@ interface BlobOptions {
12
12
  type?: string | undefined;
13
13
  }
14
14
  export declare class PonyfillBlob implements Blob {
15
- #private;
16
15
  private blobParts;
17
16
  type: string;
17
+ private encoding;
18
18
  constructor(blobParts: BlobPart[], options?: BlobOptions);
19
19
  buffer(): Promise<Buffer>;
20
20
  arrayBuffer(): Promise<ArrayBuffer>;
package/typings/Blob.d.ts CHANGED
@@ -12,9 +12,9 @@ interface BlobOptions {
12
12
  type?: string | undefined;
13
13
  }
14
14
  export declare class PonyfillBlob implements Blob {
15
- #private;
16
15
  private blobParts;
17
16
  type: string;
17
+ private encoding;
18
18
  constructor(blobParts: BlobPart[], options?: BlobOptions);
19
19
  buffer(): Promise<Buffer>;
20
20
  arrayBuffer(): Promise<ArrayBuffer>;
@@ -1,8 +1,14 @@
1
1
  export type PonyfillHeadersInit = [string, string][] | Record<string, string | string[] | undefined> | Headers;
2
2
  export declare function isHeadersLike(headers: any): headers is Headers;
3
3
  export declare class PonyfillHeaders implements Headers {
4
- #private;
4
+ private map;
5
+ private mapIsBuilt;
6
+ private objectNormalizedKeysOfHeadersInit;
7
+ private objectOriginalKeysOfHeadersInit;
8
+ private headersInit?;
5
9
  constructor(headersInit?: PonyfillHeadersInit);
10
+ private _get;
11
+ private getMap;
6
12
  append(name: string, value: string): void;
7
13
  get(name: string): string | null;
8
14
  has(name: string): boolean;
@@ -1,8 +1,14 @@
1
1
  export type PonyfillHeadersInit = [string, string][] | Record<string, string | string[] | undefined> | Headers;
2
2
  export declare function isHeadersLike(headers: any): headers is Headers;
3
3
  export declare class PonyfillHeaders implements Headers {
4
- #private;
4
+ private map;
5
+ private mapIsBuilt;
6
+ private objectNormalizedKeysOfHeadersInit;
7
+ private objectOriginalKeysOfHeadersInit;
8
+ private headersInit?;
5
9
  constructor(headersInit?: PonyfillHeadersInit);
10
+ private _get;
11
+ private getMap;
6
12
  append(name: string, value: string): void;
7
13
  get(name: string): string | null;
8
14
  has(name: string): boolean;
@@ -10,7 +10,6 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
10
10
  };
11
11
  type HeadersSerializer = (headers: Headers) => Record<string, string>;
12
12
  export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
13
- #private;
14
13
  constructor(input: RequestInfo | URL, options?: RequestPonyfillInit);
15
14
  headersSerializer: HeadersSerializer;
16
15
  cache: RequestCache;
@@ -26,6 +25,7 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
26
25
  referrer: string;
27
26
  referrerPolicy: ReferrerPolicy;
28
27
  url: string;
28
+ private _signal;
29
29
  get signal(): AbortSignal;
30
30
  agent?: Agent;
31
31
  clone(): PonyfillRequest;
@@ -10,7 +10,6 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
10
10
  };
11
11
  type HeadersSerializer = (headers: Headers) => Record<string, string>;
12
12
  export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
13
- #private;
14
13
  constructor(input: RequestInfo | URL, options?: RequestPonyfillInit);
15
14
  headersSerializer: HeadersSerializer;
16
15
  cache: RequestCache;
@@ -26,6 +25,7 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
26
25
  referrer: string;
27
26
  referrerPolicy: ReferrerPolicy;
28
27
  url: string;
28
+ private _signal;
29
29
  get signal(): AbortSignal;
30
30
  agent?: Agent;
31
31
  clone(): PonyfillRequest;