@loaders.gl/polyfills 4.0.0-alpha.9 → 4.0.0-beta.1

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.
Files changed (53) hide show
  1. package/dist/dist.min.js +10 -89
  2. package/dist/es5/index.js +0 -27
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/node/fetch/fetch.node.js +2 -3
  5. package/dist/es5/node/fetch/fetch.node.js.map +1 -1
  6. package/dist/es5/node/file/install-file-polyfills.js +1 -4
  7. package/dist/es5/node/file/install-file-polyfills.js.map +1 -1
  8. package/dist/esm/index.js +0 -4
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/node/fetch/fetch.node.js +2 -3
  11. package/dist/esm/node/fetch/fetch.node.js.map +1 -1
  12. package/dist/esm/node/file/install-file-polyfills.js +1 -4
  13. package/dist/esm/node/file/install-file-polyfills.js.map +1 -1
  14. package/dist/index.d.ts +0 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/node/fetch/fetch.node.d.ts +1 -1
  17. package/dist/node/fetch/fetch.node.d.ts.map +1 -1
  18. package/package.json +2 -2
  19. package/src/index.ts +7 -7
  20. package/src/node/fetch/fetch.node.ts +6 -5
  21. package/src/node/file/install-file-polyfills.ts +2 -2
  22. package/dist/bundle.js +0 -5
  23. package/dist/es5/node/fetch/fetch-file.node.js +0 -83
  24. package/dist/es5/node/fetch/fetch-file.node.js.map +0 -1
  25. package/dist/esm/node/fetch/fetch-file.node.js +0 -50
  26. package/dist/esm/node/fetch/fetch-file.node.js.map +0 -1
  27. package/dist/index.js +0 -97
  28. package/dist/lib/encoding-indexes.js +0 -35
  29. package/dist/lib/encoding.js +0 -2779
  30. package/dist/libs/encoding-indexes-asian.js +0 -14
  31. package/dist/node/buffer/btoa.node.js +0 -14
  32. package/dist/node/buffer/to-array-buffer.node.js +0 -12
  33. package/dist/node/fetch/fetch-file.node.d.ts +0 -4
  34. package/dist/node/fetch/fetch-file.node.d.ts.map +0 -1
  35. package/dist/node/fetch/fetch-file.node.js +0 -51
  36. package/dist/node/fetch/fetch.node.js +0 -143
  37. package/dist/node/fetch/headers.node.js +0 -106
  38. package/dist/node/fetch/response.node.js +0 -76
  39. package/dist/node/fetch/utils/decode-data-uri.node.js +0 -65
  40. package/dist/node/fetch/utils/stream-utils.node.js +0 -73
  41. package/dist/node/file/blob-stream-controller.js +0 -63
  42. package/dist/node/file/blob-stream.js +0 -37
  43. package/dist/node/file/blob.js +0 -160
  44. package/dist/node/file/file-reader.js +0 -35
  45. package/dist/node/file/file.js +0 -37
  46. package/dist/node/file/install-file-polyfills.js +0 -27
  47. package/dist/node/file/readable-stream.js +0 -11
  48. package/dist/node/images/encode-image.node.js +0 -41
  49. package/dist/node/images/parse-image.node.js +0 -41
  50. package/dist/promise/all-settled.js +0 -24
  51. package/dist/utils/assert.js +0 -9
  52. package/dist/utils/globals.js +0 -36
  53. package/src/node/fetch/fetch-file.node.ts +0 -51
package/dist/dist.min.js CHANGED
@@ -1,10 +1,5 @@
1
1
  (() => {
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
3
  var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
9
4
  var __esm = (fn, res) => function __init() {
10
5
  return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
@@ -17,17 +12,6 @@
17
12
  for (var name in all)
18
13
  __defProp(target, name, { get: all[name], enumerable: true });
19
14
  };
20
- var __reExport = (target, module, desc) => {
21
- if (module && typeof module === "object" || typeof module === "function") {
22
- for (let key of __getOwnPropNames(module))
23
- if (!__hasOwnProp.call(target, key) && key !== "default")
24
- __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
25
- }
26
- return target;
27
- };
28
- var __toModule = (module) => {
29
- return __reExport(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? { get: () => module.default, enumerable: true } : { value: module, enumerable: true })), module);
30
- };
31
15
 
32
16
  // src/utils/globals.ts
33
17
  var isBrowser, globals, global_;
@@ -1666,18 +1650,6 @@
1666
1650
  }
1667
1651
  });
1668
1652
 
1669
- // (disabled):src/node/file/readable-stream
1670
- var init_readable_stream = __esm({
1671
- "(disabled):src/node/file/readable-stream"() {
1672
- }
1673
- });
1674
-
1675
- // (disabled):src/node/file/blob
1676
- var init_blob = __esm({
1677
- "(disabled):src/node/file/blob"() {
1678
- }
1679
- });
1680
-
1681
1653
  // src/node/file/file-reader.ts
1682
1654
  var FileReaderPolyfill;
1683
1655
  var init_file_reader = __esm({
@@ -1722,10 +1694,15 @@
1722
1694
  }
1723
1695
  });
1724
1696
 
1697
+ // (disabled):src/node/file/blob
1698
+ var init_blob = __esm({
1699
+ "(disabled):src/node/file/blob"() {
1700
+ }
1701
+ });
1702
+
1725
1703
  // src/node/file/install-file-polyfills.ts
1726
1704
  function installFilePolyfills() {
1727
1705
  if (typeof ReadableStream === "undefined" && global) {
1728
- global.ReadableStream = import_readable_stream.ReadableStreamPolyfill;
1729
1706
  }
1730
1707
  if (typeof Blob === "undefined" && global) {
1731
1708
  global.Blob = import_blob.BlobPolyfill;
@@ -1739,69 +1716,17 @@
1739
1716
  }
1740
1717
  var init_install_file_polyfills = __esm({
1741
1718
  "src/node/file/install-file-polyfills.ts"() {
1742
- init_readable_stream();
1743
1719
  init_blob();
1744
1720
  init_file_reader();
1745
1721
  init_file();
1746
1722
  }
1747
1723
  });
1748
1724
 
1749
- // (disabled):fs
1750
- var require_fs = __commonJS({
1751
- "(disabled):fs"() {
1752
- }
1753
- });
1754
-
1755
- // src/node/fetch/fetch-file.node.ts
1756
- async function fetchFileNode(url, options) {
1757
- const noqueryUrl = url.split("?")[0];
1758
- try {
1759
- const body = await new Promise((resolve, reject) => {
1760
- const stream = import_fs.default.createReadStream(noqueryUrl, { encoding: null });
1761
- stream.once("readable", () => resolve(stream));
1762
- stream.on("error", (error) => reject(error));
1763
- });
1764
- const status = 200;
1765
- const statusText = "OK";
1766
- const headers = getHeadersForFile(noqueryUrl);
1767
- return new import_response.Response(body, { headers, status, statusText, url });
1768
- } catch (error) {
1769
- const status = 400;
1770
- const statusText = error.message;
1771
- const headers = {};
1772
- return new import_response.Response(error.message, { headers, status, statusText, url });
1773
- }
1774
- }
1775
- function getHeadersForFile(noqueryUrl) {
1776
- const headers = {};
1777
- if (!headers["content-length"]) {
1778
- const stats = import_fs.default.statSync(noqueryUrl);
1779
- headers["content-length"] = stats.size;
1780
- }
1781
- if (noqueryUrl.endsWith(".gz")) {
1782
- noqueryUrl = noqueryUrl.slice(0, -3);
1783
- headers["content-encoding"] = "gzip";
1784
- }
1785
- return new import_headers.Headers(headers);
1786
- }
1787
- var import_fs;
1788
- var init_fetch_file_node = __esm({
1789
- "src/node/fetch/fetch-file.node.ts"() {
1790
- import_fs = __toModule(require_fs());
1791
- init_response();
1792
- init_headers();
1793
- }
1794
- });
1795
-
1796
1725
  // src/index.ts
1797
1726
  var src_exports = {};
1798
1727
  __export(src_exports, {
1799
- BlobPolyfill: () => import_blob2.BlobPolyfill,
1800
1728
  FilePolyfill: () => import_file2.FilePolyfill,
1801
1729
  FileReaderPolyfill: () => FileReaderPolyfill,
1802
- ReadableStreamPolyfill: () => import_readable_stream2.ReadableStreamPolyfill,
1803
- _fetchFileNode: () => fetchFileNode,
1804
- _fetchNode: () => import_fetch2.fetchNode,
1805
1730
  installFilePolyfills: () => installFilePolyfills
1806
1731
  });
1807
1732
  var installTextEncoder, installTextDecoder;
@@ -1816,13 +1741,9 @@
1816
1741
  init_fetch();
1817
1742
  init_encode_image();
1818
1743
  init_parse_image();
1819
- init_readable_stream();
1820
- init_blob();
1821
1744
  init_file_reader();
1822
1745
  init_file();
1823
1746
  init_install_file_polyfills();
1824
- init_fetch();
1825
- init_fetch_file_node();
1826
1747
  installTextEncoder = !isBrowser || !("TextEncoder" in global_);
1827
1748
  if (installTextEncoder) {
1828
1749
  global_["TextEncoder"] = TextEncoder;
@@ -1837,11 +1758,11 @@
1837
1758
  if (!isBrowser && !("btoa" in global_) && base64.btoa) {
1838
1759
  global_["btoa"] = base64.btoa;
1839
1760
  }
1840
- if (!isBrowser && !("Headers" in global_) && import_headers2.Headers) {
1841
- global_["Headers"] = import_headers2.Headers;
1761
+ if (!isBrowser && !("Headers" in global_) && import_headers.Headers) {
1762
+ global_["Headers"] = import_headers.Headers;
1842
1763
  }
1843
- if (!isBrowser && !("Response" in global_) && import_response2.Response) {
1844
- global_["Response"] = import_response2.Response;
1764
+ if (!isBrowser && !("Response" in global_) && import_response.Response) {
1765
+ global_["Response"] = import_response.Response;
1845
1766
  }
1846
1767
  if (!isBrowser && !("fetch" in global_) && import_fetch.fetchNode) {
1847
1768
  global_["fetch"] = import_fetch.fetchNode;
package/dist/es5/index.js CHANGED
@@ -4,12 +4,6 @@ var _typeof = require("@babel/runtime/helpers/typeof");
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- Object.defineProperty(exports, "BlobPolyfill", {
8
- enumerable: true,
9
- get: function get() {
10
- return _blob.BlobPolyfill;
11
- }
12
- });
13
7
  Object.defineProperty(exports, "FilePolyfill", {
14
8
  enumerable: true,
15
9
  get: function get() {
@@ -22,24 +16,6 @@ Object.defineProperty(exports, "FileReaderPolyfill", {
22
16
  return _fileReader.FileReaderPolyfill;
23
17
  }
24
18
  });
25
- Object.defineProperty(exports, "ReadableStreamPolyfill", {
26
- enumerable: true,
27
- get: function get() {
28
- return _readableStream.ReadableStreamPolyfill;
29
- }
30
- });
31
- Object.defineProperty(exports, "_fetchFileNode", {
32
- enumerable: true,
33
- get: function get() {
34
- return _fetchFile.fetchFileNode;
35
- }
36
- });
37
- Object.defineProperty(exports, "_fetchNode", {
38
- enumerable: true,
39
- get: function get() {
40
- return _fetch.fetchNode;
41
- }
42
- });
43
19
  Object.defineProperty(exports, "installFilePolyfills", {
44
20
  enumerable: true,
45
21
  get: function get() {
@@ -55,12 +31,9 @@ var _response = require("./node/fetch/response.node");
55
31
  var _fetch = require("./node/fetch/fetch.node");
56
32
  var _encodeImage = require("./node/images/encode-image.node");
57
33
  var _parseImage = require("./node/images/parse-image.node");
58
- var _readableStream = require("./node/file/readable-stream");
59
- var _blob = require("./node/file/blob");
60
34
  var _fileReader = require("./node/file/file-reader");
61
35
  var _file = require("./node/file/file");
62
36
  var _installFilePolyfills = require("./node/file/install-file-polyfills");
63
- var _fetchFile = require("./node/fetch/fetch-file.node");
64
37
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
65
38
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
66
39
  var installTextEncoder = !_globals.isBrowser || !('TextEncoder' in _globals.global);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_globals","require","_encoding","_allSettled","base64","_interopRequireWildcard","_headers","_response","_fetch","_encodeImage","_parseImage","_readableStream","_blob","_fileReader","_file","_installFilePolyfills","_fetchFile","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","installTextEncoder","isBrowser","global","TextEncoder","installTextDecoder","TextDecoder","atob","btoa","HeadersNode","ResponseNode","fetchNode","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","Promise","allSettled"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\nexport {ReadableStreamPolyfill} from './node/file/readable-stream';\nexport {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\nexport {fetchNode as _fetchNode} from './node/fetch/fetch.node';\nexport {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// POLYFILL: fetch\n// - Node: Yes\n// - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAGA,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAEA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAEA,IAAAU,eAAA,GAAAV,OAAA;AACA,IAAAW,KAAA,GAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AACA,IAAAa,KAAA,GAAAb,OAAA;AACA,IAAAc,qBAAA,GAAAd,OAAA;AAEA,IAAAe,UAAA,G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AAC,mBAAmB,CAAC,GAAGW,+BAAmB;AACnD;AAEA,IAAI,EAAE,YAAY,IAAIC,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACC,UAAU,GAAGA,sBAAU;AACjC"}
1
+ {"version":3,"file":"index.js","names":["_globals","require","_encoding","_allSettled","base64","_interopRequireWildcard","_headers","_response","_fetch","_encodeImage","_parseImage","_fileReader","_file","_installFilePolyfills","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","installTextEncoder","isBrowser","global","TextEncoder","installTextDecoder","TextDecoder","atob","btoa","HeadersNode","ResponseNode","fetchNode","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","Promise","allSettled"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\n// export {ReadableStreamPolyfill} from './node/file/readable-stream';\n// export {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// DEPRECATED POLYFILL:\n// - Node v18+: No, not needed\n// - Node v16 and lower: Yes\n// - Browsers (evergreen): Not needed.\n// - IE11: No. This polyfill is node only, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAGA,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAEA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAEA,IAAAQ,YAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AAIA,IAAAU,W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EAClEV,eAAM,CAAC,iBAAiB,CAAC,GAAGU,0BAAc;EAC1CV,eAAM,CAAC,mBAAmB,CAAC,GAAGW,+BAAmB;AACnD;AAEA,IAAI,EAAE,YAAY,IAAIC,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACC,UAAU,GAAGA,sBAAU;AACjC"}
@@ -14,7 +14,6 @@ var _https = _interopRequireDefault(require("https"));
14
14
  var _response = require("./response.node");
15
15
  var _headers = require("./headers.node");
16
16
  var _decodeDataUri2 = require("./utils/decode-data-uri.node");
17
- var _fetchFile = require("./fetch-file.node");
18
17
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
19
  var isDataURL = function isDataURL(url) {
@@ -33,12 +32,12 @@ function _fetchNode() {
33
32
  while (1) switch (_context.prev = _context.next) {
34
33
  case 0:
35
34
  _context.prev = 0;
36
- if (!(!isRequestURL(url) && !isDataURL(url))) {
35
+ if (!(globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url)))) {
37
36
  _context.next = 5;
38
37
  break;
39
38
  }
40
39
  _context.next = 4;
41
- return (0, _fetchFile.fetchFileNode)(url, options);
40
+ return fetch(url, options);
42
41
  case 4:
43
42
  return _context.abrupt("return", _context.sent);
44
43
  case 5:
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.node.js","names":["_http","_interopRequireDefault","require","_https","_response","_headers","_decodeDataUri2","_fetchFile","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","isDataURL","url","startsWith","isRequestURL","fetchNode","_x","_x2","_fetchNode","_asyncToGenerator2","_regenerator","mark","_callee","options","_decodeDataUri","arrayBuffer","mimeType","response","syntheticResponseHeaders","originalUrl","body","headers","_getStatus","status","statusText","followRedirect","redirectUrl","wrap","_callee$","_context","prev","next","fetchFileNode","abrupt","sent","decodeDataUri","Response","endsWith","slice","createHTTPRequestReadStream","getHeaders","getStatus","undefined","has","generateRedirectUrl","get","t0","String","stop","_x3","_x4","_createHTTPRequestReadStream","_callee2","_callee2$","_context2","Promise","resolve","reject","requestOptions","getRequestOptions","req","https","request","res","http","on","error","end","location","URL","pathname","href","originalHeaders","_i","_Object$keys","toLowerCase","urlObject","hostname","path","method","fetch","port","httpResponse","statusCode","statusMessage","additionalHeaders","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign","Headers"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nimport {fetchFileNode} from './fetch-file.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options): Promise<Response> {\n try {\n // Handle file streams in node\n if (!isRequestURL(url) && !isDataURL(url)) {\n return await fetchFileNode(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":";;;;;;;;;;;AAEA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAEA,IAAAK,UAAA,GAAAL,OAAA;AAAgD,SAAAM,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAA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AAE;IAC9B,IAAMmE,aAAa,GAAGC,gBAAgB,CAACvF,GAAG,CAAC;IAC3C,IAAIwF,MAAM,CAACC,QAAQ,CAACH,aAAa,CAAC,EAAE;MAClCnE,OAAO,CAAC,gBAAgB,CAAC,GAAGmE,aAAa;IAC3C;EACF;EAEA7G,MAAM,CAACiH,MAAM,CAACvE,OAAO,EAAEgE,iBAAiB,CAAC;EAEzC,OAAO,IAAIQ,gBAAO,CAACxE,OAAO,CAAC;AAC7B;AAGA,SAASoE,gBAAgBA,CAACvF,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAACV,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
1
+ {"version":3,"file":"fetch.node.js","names":["_http","_interopRequireDefault","require","_https","_response","_headers","_decodeDataUri2","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","isDataURL","url","startsWith","isRequestURL","fetchNode","_x","_x2","_fetchNode","_asyncToGenerator2","_regenerator","mark","_callee","options","_decodeDataUri","arrayBuffer","mimeType","response","syntheticResponseHeaders","originalUrl","body","headers","_getStatus","status","statusText","followRedirect","redirectUrl","wrap","_callee$","_context","prev","next","globalThis","fetch","abrupt","sent","decodeDataUri","Response","endsWith","slice","createHTTPRequestReadStream","getHeaders","getStatus","undefined","has","generateRedirectUrl","get","t0","String","stop","_x3","_x4","_createHTTPRequestReadStream","_callee2","_callee2$","_context2","Promise","resolve","reject","requestOptions","getRequestOptions","req","https","request","res","http","on","error","end","location","URL","pathname","href","originalHeaders","_i","_Object$keys","toLowerCase","urlObject","hostname","path","method","port","httpResponse","statusCode","statusMessage","additionalHeaders","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign","Headers"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options: RequestInit): Promise<Response> {\n try {\n // Handle file streams in node\n // @ts-expect-error\n if (globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url))) {\n // @ts-expect-error\n return await fetch(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n // @ts-expect-error\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":";;;;;;;;;;;AAEA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AAA2D,SAAAK,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,QAAAC,gBAAA,CAAAC,OAAA,EAAAR,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,SAAAhB,MAAA,CAAAmB,yBAAA,GAAAnB,MAAA,CAAAoB,gBAAA,CAAAV,MAAA,EAAAV,MAAA,CAAAmB,yBAAA,CAAAL,MAAA,KAAAlB,OAAA,CAAAI,MAAA,CAAAc,MAAA,G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IAAxBG,iBAAiB,GAAA9F,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAoD,SAAA,GAAApD,SAAA,MAAG,CAAC,CAAC;EAC3D,IAAM8B,OAAO,GAAG,CAAC,CAAC;EAElB,IAAI6D,YAAY,IAAIA,YAAY,CAAC7D,OAAO,EAAE;IACxC,IAAMiE,WAAW,GAAGJ,YAAY,CAAC7D,OAAO;IACxC,KAAK,IAAM1B,GAAG,IAAI2F,WAAW,EAAE;MAC7B,IAAMC,MAAM,GAAGD,WAAW,CAAC3F,GAAG,CAAC;MAC/B0B,OAAO,CAAC1B,GAAG,CAACiF,WAAW,CAAC,CAAC,CAAC,GAAG5B,MAAM,CAACuC,MAAM,CAAC;IAC7C;EACF;EAGA,IAAI,CAAClE,OAAO,CAAC,gBAAgB,CAAC,EAAE;IAC9B,IAAMmE,aAAa,GAAGC,gBAAgB,CAACvF,GAAG,CAAC;IAC3C,IAAIwF,MAAM,CAACC,QAAQ,CAACH,aAAa,CAAC,EAAE;MAClCnE,OAAO,CAAC,gBAAgB,CAAC,GAAGmE,aAAa;IAC3C;EACF;EAEA7G,MAAM,CAACiH,MAAM,CAACvE,OAAO,EAAEgE,iBAAiB,CAAC;EAEzC,OAAO,IAAIQ,gBAAO,CAACxE,OAAO,CAAC;AAC7B;AAGA,SAASoE,gBAAgBA,CAACvF,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAACV,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.installFilePolyfills = installFilePolyfills;
7
- var _readableStream = require("./readable-stream");
8
7
  var _blob = require("./blob");
9
8
  var _fileReader = require("./file-reader");
10
9
  var _file = require("./file");
11
10
  function installFilePolyfills() {
12
- if (typeof ReadableStream === 'undefined' && global) {
13
- global.ReadableStream = _readableStream.ReadableStreamPolyfill;
14
- }
11
+ if (typeof ReadableStream === 'undefined' && global) {}
15
12
  if (typeof Blob === 'undefined' && global) {
16
13
  global.Blob = _blob.BlobPolyfill;
17
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"install-file-polyfills.js","names":["_readableStream","require","_blob","_fileReader","_file","installFilePolyfills","ReadableStream","global","ReadableStreamPolyfill","Blob","BlobPolyfill","FileReader","FileReaderPolyfill","File","FilePolyfill"],"sources":["../../../../src/node/file/install-file-polyfills.ts"],"sourcesContent":["import {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobPolyfill} from './blob';\nimport {FileReaderPolyfill} from './file-reader';\nimport {FilePolyfill} from './file';\n\nexport function installFilePolyfills() {\n if (typeof ReadableStream === 'undefined' && global) {\n // @ts-ignore;\n global.ReadableStream = ReadableStreamPolyfill;\n }\n\n if (typeof Blob === 'undefined' && global) {\n // @ts-ignore;\n global.Blob = BlobPolyfill;\n }\n\n if (typeof FileReader === 'undefined' && global) {\n // @ts-ignore;\n global.FileReader = FileReaderPolyfill;\n }\n\n // Install minimal Node.js File polyfill\n if (typeof File === 'undefined' && global) {\n // @ts-ignore;\n global.File = FilePolyfill;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAEO,SAASI,oBAAoBA,CAAA,EAAG;EACrC,IAAI,OAAOC,cAAc,KAAK,WAAW,IAAIC,MAAM,EAAE;IAEnDA,MAAM,CAACD,cAAc,GAAGE,sCAAsB;EAChD;EAEA,IAAI,OAAOC,IAAI,KAAK,WAAW,IAAIF,MAAM,EAAE;IAEzCA,MAAM,CAACE,IAAI,GAAGC,kBAAY;EAC5B;EAEA,IAAI,OAAOC,UAAU,KAAK,WAAW,IAAIJ,MAAM,EAAE;IAE/CA,MAAM,CAACI,UAAU,GAAGC,8BAAkB;EACxC;EAGA,IAAI,OAAOC,IAAI,KAAK,WAAW,IAAIN,MAAM,EAAE;IAEzCA,MAAM,CAACM,IAAI,GAAGC,kBAAY;EAC5B;AACF"}
1
+ {"version":3,"file":"install-file-polyfills.js","names":["_blob","require","_fileReader","_file","installFilePolyfills","ReadableStream","global","Blob","BlobPolyfill","FileReader","FileReaderPolyfill","File","FilePolyfill"],"sources":["../../../../src/node/file/install-file-polyfills.ts"],"sourcesContent":["// import {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobPolyfill} from './blob';\nimport {FileReaderPolyfill} from './file-reader';\nimport {FilePolyfill} from './file';\n\nexport function installFilePolyfills() {\n if (typeof ReadableStream === 'undefined' && global) {\n // @ts-ignore;\n // global.ReadableStream = ReadableStreamPolyfill;\n }\n\n if (typeof Blob === 'undefined' && global) {\n // @ts-ignore;\n global.Blob = BlobPolyfill;\n }\n\n if (typeof FileReader === 'undefined' && global) {\n // @ts-ignore;\n global.FileReader = FileReaderPolyfill;\n }\n\n // Install minimal Node.js File polyfill\n if (typeof File === 'undefined' && global) {\n // @ts-ignore;\n global.File = FilePolyfill;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEO,SAASG,oBAAoBA,CAAA,EAAG;EACrC,IAAI,OAAOC,cAAc,KAAK,WAAW,IAAIC,MAAM,EAAE,CAGrD;EAEA,IAAI,OAAOC,IAAI,KAAK,WAAW,IAAID,MAAM,EAAE;IAEzCA,MAAM,CAACC,IAAI,GAAGC,kBAAY;EAC5B;EAEA,IAAI,OAAOC,UAAU,KAAK,WAAW,IAAIH,MAAM,EAAE;IAE/CA,MAAM,CAACG,UAAU,GAAGC,8BAAkB;EACxC;EAGA,IAAI,OAAOC,IAAI,KAAK,WAAW,IAAIL,MAAM,EAAE;IAEzCA,MAAM,CAACK,IAAI,GAAGC,kBAAY;EAC5B;AACF"}
package/dist/esm/index.js CHANGED
@@ -7,13 +7,9 @@ import { Response as ResponseNode } from './node/fetch/response.node';
7
7
  import { fetchNode } from './node/fetch/fetch.node';
8
8
  import { encodeImageNode } from './node/images/encode-image.node';
9
9
  import { parseImageNode, NODE_FORMAT_SUPPORT } from './node/images/parse-image.node';
10
- export { ReadableStreamPolyfill } from './node/file/readable-stream';
11
- export { BlobPolyfill } from './node/file/blob';
12
10
  export { FileReaderPolyfill } from './node/file/file-reader';
13
11
  export { FilePolyfill } from './node/file/file';
14
12
  export { installFilePolyfills } from './node/file/install-file-polyfills';
15
- export { fetchNode as _fetchNode } from './node/fetch/fetch.node';
16
- export { fetchFileNode as _fetchFileNode } from './node/fetch/fetch-file.node';
17
13
  const installTextEncoder = !isBrowser || !('TextEncoder' in global);
18
14
  if (installTextEncoder) {
19
15
  global['TextEncoder'] = TextEncoder;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["isBrowser","global","TextDecoder","TextEncoder","allSettled","base64","Headers","HeadersNode","Response","ResponseNode","fetchNode","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","ReadableStreamPolyfill","BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","_fetchNode","fetchFileNode","_fetchFileNode","installTextEncoder","installTextDecoder","atob","btoa","Promise"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\nexport {ReadableStreamPolyfill} from './node/file/readable-stream';\nexport {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\nexport {fetchNode as _fetchNode} from './node/fetch/fetch.node';\nexport {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// POLYFILL: fetch\n// - Node: Yes\n// - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":"AACA,SAAQA,SAAS,EAAEC,MAAM,QAAO,iBAAiB;AAEjD,SAAQC,WAAW,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AMA,IAAI,CAACzB,SAAS,IAAI,EAAE,SAAS,IAAIC,MAAM,CAAC,IAAIM,WAAW,EAAE;EACvDN,MAAM,CAAC,SAAS,CAAC,GAAGM,WAAW;AACjC;AAEA,IAAI,CAACP,SAAS,IAAI,EAAE,UAAU,IAAIC,MAAM,CAAC,IAAIQ,YAAY,EAAE;EACzDR,MAAM,CAAC,UAAU,CAAC,GAAGQ,YAAY;AACnC;AAEA,IAAI,CAACT,SAAS,IAAI,EAAE,OAAO,IAAIC,MAAM,CAAC,IAAIS,SAAS,EAAE;EACnDT,MAAM,CAAC,OAAO,CAAC,GAAGS,SAAS;AAC7B;AAMA,IAAI,CAACV,SAAS,IAAI,EAAE,kBAAkB,IAAIC,MAAM,CAAC,IAAIU,eAAe,EAAE;EACpEV,MAAM,CAAC,kBAAkB,CAAC,GAAGU,eAAe;AAC9C;AAEA,IAAI,CAACX,SAAS,IAAI,EAAE,iBAAiB,IAAIC,MAAM,CAAC,IAAIW,cAAc,EAAE;EAClEX,MAAM,CAAC,iBAAiB,CAAC,GAAGW,cAAc;EAC1CX,MAAM,CAAC,mBAAmB,CAAC,GAAGY,mBAAmB;AACnD;AAEA,IAAI,EAAE,YAAY,IAAIa,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACtB,UAAU,GAAGA,UAAU;AACjC"}
1
+ {"version":3,"file":"index.js","names":["isBrowser","global","TextDecoder","TextEncoder","allSettled","base64","Headers","HeadersNode","Response","ResponseNode","fetchNode","encodeImageNode","parseImageNode","NODE_FORMAT_SUPPORT","FileReaderPolyfill","FilePolyfill","installFilePolyfills","installTextEncoder","installTextDecoder","atob","btoa","Promise"],"sources":["../../src/index.ts"],"sourcesContent":["/* eslint-disable dot-notation */\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './lib/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport {Headers as HeadersNode} from './node/fetch/headers.node';\nimport {Response as ResponseNode} from './node/fetch/response.node';\nimport {fetchNode as fetchNode} from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';\n\n// export {ReadableStreamPolyfill} from './node/file/readable-stream';\n// export {BlobPolyfill} from './node/file/blob';\nexport {FileReaderPolyfill} from './node/file/file-reader';\nexport {FilePolyfill} from './node/file/file';\nexport {installFilePolyfills} from './node/file/install-file-polyfills';\n\n// POLYFILLS: TextEncoder, TextDecoder\n// - Recent Node versions have these classes but virtually no encodings unless special build.\n// - Browser: Edge, IE11 do not have these\n\nconst installTextEncoder = !isBrowser || !('TextEncoder' in global);\nif (installTextEncoder) {\n global['TextEncoder'] = TextEncoder;\n}\n\nconst installTextDecoder = !isBrowser || !('TextDecoder' in global);\nif (installTextDecoder) {\n global['TextDecoder'] = TextDecoder;\n}\n\n// POLYFILLS: btoa, atob\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('atob' in global) && base64.atob) {\n global['atob'] = base64.atob;\n}\nif (!isBrowser && !('btoa' in global) && base64.btoa) {\n global['btoa'] = base64.btoa;\n}\n\n// DEPRECATED POLYFILL:\n// - Node v18+: No, not needed\n// - Node v16 and lower: Yes\n// - Browsers (evergreen): Not needed.\n// - IE11: No. This polyfill is node only, install external polyfill\n\nif (!isBrowser && !('Headers' in global) && HeadersNode) {\n global['Headers'] = HeadersNode;\n}\n\nif (!isBrowser && !('Response' in global) && ResponseNode) {\n global['Response'] = ResponseNode;\n}\n\nif (!isBrowser && !('fetch' in global) && fetchNode) {\n global['fetch'] = fetchNode;\n}\n\n// NODE IMAGE FUNCTIONS:\n// These are not official polyfills but used by the @loaders.gl/images module if installed\n// TODO - is there an appropriate Image API we could polyfill using an adapter?\n\nif (!isBrowser && !('_encodeImageNode' in global) && encodeImageNode) {\n global['_encodeImageNode'] = encodeImageNode;\n}\n\nif (!isBrowser && !('_parseImageNode' in global) && parseImageNode) {\n global['_parseImageNode'] = parseImageNode;\n global['_imageFormatsNode'] = NODE_FORMAT_SUPPORT;\n}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"mappings":"AACA,SAAQA,SAAS,EAAEC,MAAM,QAAO,iBAAiB;AAEjD,SAAQC,WAAW,EAAEC,WAAW,QAAO,gBAAgB;AACvD,SAAQC,UAAU,QAAO,uBAAuB;AAGhD,OAAO,KAAKC,MAAM,MAAM,yBAAyB;AAEjD,SAAQC,OAAO,IAAIC,WAAW,QAAO,2BAA2B;AAChE,SAAQC,QAAQ,IAAIC,YAAY,QAAO,4BAA4B;AACnE,SAAQC,SAAsB,QAAO,yBAAyB;AAE9D,SAAQC,eAAe,QAAO,iCAAiC;AAC/D,SAAQC,cAAc,EAAEC,mBAAmB,QAAO,gCAAgC;AAIlF,SAAQC,kBAAkB,QAAO,yBAAyB;AAC1D,SAAQC,YAAY,QAAO,kBAAkB;AAC7C,SAAQC,oBAAoB,QAAO,oCAAoC;AAMvE,MAAMC,kBAAkB,GAAG,CAACjB,SAAS,IAAI,EAAE,aAAa,IAAIC,MAAM,CAAC;AACnE,IAAIgB,kBAAkB,EAAE;EACtBhB,MAAM,CAAC,aAAa,CAAC,GAAGE,WAAW;AACrC;AAEA,MAAMe,kBAAkB,GAAG,CAAClB,SAAS,IAAI,EAAE,aAAa,IAAIC,MAAM,CAAC;AACnE,IAAIiB,kBAAkB,EAAE;EACtBjB,MAAM,CAAC,aAAa,CAAC,GAAGC,WAAW;AACrC;AAMA,IAAI,CAACF,SAAS,IAAI,EAAE,MAAM,IAAIC,MAAM,CAAC,IAAII,MAAM,CAACc,IAAI,EAAE;EACpDlB,MAAM,CAAC,MAAM,CAAC,GAAGI,MAAM,CAACc,IAAI;AAC9B;AACA,IAAI,CAACnB,SAAS,IAAI,EAAE,MAAM,IAAIC,MAAM,CAAC,IAAII,MAAM,CAACe,IAAI,EAAE;EACpDnB,MAAM,CAAC,MAAM,CAAC,GAAGI,MAAM,CAACe,IAAI;AAC9B;AAQA,IAAI,CAACpB,SAAS,IAAI,EAAE,SAAS,IAAIC,MAAM,CAAC,IAAIM,WAAW,EAAE;EACvDN,MAAM,CAAC,SAAS,CAAC,GAAGM,WAAW;AACjC;AAEA,IAAI,CAACP,SAAS,IAAI,EAAE,UAAU,IAAIC,MAAM,CAAC,IAAIQ,YAAY,EAAE;EACzDR,MAAM,CAAC,UAAU,CAAC,GAAGQ,YAAY;AACnC;AAEA,IAAI,CAACT,SAAS,IAAI,EAAE,OAAO,IAAIC,MAAM,CAAC,IAAIS,SAAS,EAAE;EACnDT,MAAM,CAAC,OAAO,CAAC,GAAGS,SAAS;AAC7B;AAMA,IAAI,CAACV,SAAS,IAAI,EAAE,kBAAkB,IAAIC,MAAM,CAAC,IAAIU,eAAe,EAAE;EACpEV,MAAM,CAAC,kBAAkB,CAAC,GAAGU,eAAe;AAC9C;AAEA,IAAI,CAACX,SAAS,IAAI,EAAE,iBAAiB,IAAIC,MAAM,CAAC,IAAIW,cAAc,EAAE;EAClEX,MAAM,CAAC,iBAAiB,CAAC,GAAGW,cAAc;EAC1CX,MAAM,CAAC,mBAAmB,CAAC,GAAGY,mBAAmB;AACnD;AAEA,IAAI,EAAE,YAAY,IAAIQ,OAAO,CAAC,EAAE;EAE9BA,OAAO,CAACjB,UAAU,GAAGA,UAAU;AACjC"}
@@ -3,13 +3,12 @@ import https from 'https';
3
3
  import { Response } from './response.node';
4
4
  import { Headers } from './headers.node';
5
5
  import { decodeDataUri } from './utils/decode-data-uri.node';
6
- import { fetchFileNode } from './fetch-file.node';
7
6
  const isDataURL = url => url.startsWith('data:');
8
7
  const isRequestURL = url => url.startsWith('http:') || url.startsWith('https:');
9
8
  export async function fetchNode(url, options) {
10
9
  try {
11
- if (!isRequestURL(url) && !isDataURL(url)) {
12
- return await fetchFileNode(url, options);
10
+ if (globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url))) {
11
+ return await fetch(url, options);
13
12
  }
14
13
  if (isDataURL(url)) {
15
14
  const {
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.node.js","names":["http","https","Response","Headers","decodeDataUri","fetchFileNode","isDataURL","url","startsWith","isRequestURL","fetchNode","options","arrayBuffer","mimeType","response","headers","syntheticResponseHeaders","originalUrl","endsWith","slice","body","createHTTPRequestReadStream","getHeaders","status","statusText","getStatus","followRedirect","undefined","has","redirectUrl","generateRedirectUrl","get","error","String","Promise","resolve","reject","requestOptions","getRequestOptions","req","request","res","on","end","location","URL","pathname","href","originalHeaders","key","Object","keys","toLowerCase","urlObject","hostname","path","method","fetch","port","httpResponse","statusCode","statusMessage","additionalHeaders","arguments","length","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nimport {fetchFileNode} from './fetch-file.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options): Promise<Response> {\n try {\n // Handle file streams in node\n if (!isRequestURL(url) && !isDataURL(url)) {\n return await fetchFileNode(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":"AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAAQC,QAAQ,QAAO,iBAAiB;AACxC,SAAQC,OAAO,QAAO,gBAAgB;AACtC,SAAQC,aAAa,QAAO,8BAA8B;AAE1D,SAAQC,aAAa,QAAO,mBAAmB;AAE/C,MAAMC,SAAS,GAAIC,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC;AACnE,MAAMC,YAAY,GAAIF,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC,IAAID,GAAG,CAACC,UAAU,CAAC,QAAQ,CAAC;AAQlG,OAAO,eAAeE,SAASA,CAACH,GAAW,EAAEI,OAAO,EAAqB;EACvE,IAAI;IAEF,IAAI,CAACF,YAAY,CAACF,GAAG,CAAC,IAAI,CAACD,SAAS,CAACC,GAAG,CAAC,EAAE;MACzC,OAAO,MAAMF,aAAa,CAACE,GAAG,EAAEI,OAAO,CAAC;I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,OAAO;IACxC,KAAK,MAAMkC,GAAG,IAAIgB,WAAW,EAAE;MAC7B,MAAMC,MAAM,GAAGD,WAAW,CAAChB,GAAG,CAAC;MAC/BlC,OAAO,CAACkC,GAAG,CAACG,WAAW,CAAC,CAAC,CAAC,GAAGnB,MAAM,CAACiC,MAAM,CAAC;IAC7C;EACF;EAGA,IAAI,CAACnD,OAAO,CAAC,gBAAgB,CAAC,EAAE;IAC9B,MAAMoD,aAAa,GAAGC,gBAAgB,CAAC7D,GAAG,CAAC;IAC3C,IAAI8D,MAAM,CAACC,QAAQ,CAACH,aAAa,CAAC,EAAE;MAClCpD,OAAO,CAAC,gBAAgB,CAAC,GAAGoD,aAAa;IAC3C;EACF;EAEAjB,MAAM,CAACqB,MAAM,CAACxD,OAAO,EAAE+C,iBAAiB,CAAC;EAEzC,OAAO,IAAI3D,OAAO,CAACY,OAAO,CAAC;AAC7B;AAGA,SAASqD,gBAAgBA,CAAC7D,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAACyD,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
1
+ {"version":3,"file":"fetch.node.js","names":["http","https","Response","Headers","decodeDataUri","isDataURL","url","startsWith","isRequestURL","fetchNode","options","globalThis","fetch","arrayBuffer","mimeType","response","headers","syntheticResponseHeaders","originalUrl","endsWith","slice","body","createHTTPRequestReadStream","getHeaders","status","statusText","getStatus","followRedirect","undefined","has","redirectUrl","generateRedirectUrl","get","error","String","Promise","resolve","reject","requestOptions","getRequestOptions","req","request","res","on","end","location","URL","pathname","href","originalHeaders","key","Object","keys","toLowerCase","urlObject","hostname","path","method","port","httpResponse","statusCode","statusMessage","additionalHeaders","arguments","length","httpHeaders","header","contentLength","getContentLength","Number","isFinite","assign"],"sources":["../../../../src/node/fetch/fetch.node.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport http from 'http';\nimport https from 'https';\nimport {Response} from './response.node';\nimport {Headers} from './headers.node';\nimport {decodeDataUri} from './utils/decode-data-uri.node';\n\nconst isDataURL = (url: string): boolean => url.startsWith('data:');\nconst isRequestURL = (url: string): boolean => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\n// eslint-disable-next-line complexity\nexport async function fetchNode(url: string, options: RequestInit): Promise<Response> {\n try {\n // Handle file streams in node\n // @ts-expect-error\n if (globalThis.fetch !== fetchNode && (isRequestURL(url) || isDataURL(url))) {\n // @ts-expect-error\n return await fetch(url, options);\n }\n\n // Handle data urls in node, to match `fetch``\n // Note - this loses the MIME type, data URIs are handled directly in fetch\n if (isDataURL(url)) {\n const {arrayBuffer, mimeType} = decodeDataUri(url);\n const response = new Response(arrayBuffer, {\n headers: {'content-type': mimeType},\n url\n });\n return response;\n }\n\n // Automatically decompress gzipped files with .gz extension\n const syntheticResponseHeaders = {};\n const originalUrl = url;\n if (url.endsWith('.gz')) {\n url = url.slice(0, -3);\n syntheticResponseHeaders['content-encoding'] = 'gzip';\n }\n\n // Need to create the stream in advance since Response constructor needs to be sync\n const body = await createHTTPRequestReadStream(originalUrl, options);\n const headers = getHeaders(url, body, syntheticResponseHeaders);\n const {status, statusText} = getStatus(body);\n\n const followRedirect =\n // @ts-expect-error\n !options || options.followRedirect || options.followRedirect === undefined;\n\n if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {\n const redirectUrl = generateRedirectUrl(url, headers.get('location'));\n\n // Redirect\n return await fetchNode(redirectUrl, options);\n }\n return new Response(body, {headers, status, statusText, url});\n } catch (error) {\n // TODO - what error code to use here?\n return new Response(null, {status: 400, statusText: String(error), url});\n }\n}\n\n/** Returns a promise that resolves to a readable stream */\nexport async function createHTTPRequestReadStream(\n url: string,\n options\n): Promise<http.IncomingMessage> {\n // HANDLE HTTP/HTTPS REQUESTS IN NODE\n // TODO: THIS IS BAD SINCE WE RETURN A PROMISE INSTEAD OF A STREAM\n return await new Promise((resolve, reject) => {\n const requestOptions = getRequestOptions(url, options);\n const req = url.startsWith('https:')\n ? https.request(requestOptions, (res) => resolve(res))\n : http.request(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\n/**\n * Generate redirect url from location without origin and protocol.\n * @param originalUrl\n * @param redirectUrl\n */\nfunction generateRedirectUrl(originalUrl: string, location: string): string {\n if (location.startsWith('http')) {\n return location;\n }\n // If url doesn't have origin and protocol just extend current url origin with location.\n const url = new URL(originalUrl);\n url.pathname = location;\n\n return url.href;\n}\n\n// HELPER FUNCTIONS\n\nfunction getRequestOptions(url: string, options?: {fetch?: typeof fetch; headers?}) {\n // Ensure header keys are lower case so that we can merge without duplicates\n const originalHeaders = options?.headers || {};\n const headers = {};\n for (const key of Object.keys(originalHeaders)) {\n headers[key.toLowerCase()] = originalHeaders[key];\n }\n\n // Add default accept-encoding to headers\n headers['accept-encoding'] = headers['accept-encoding'] || 'gzip,br,deflate';\n\n const urlObject = new URL(url);\n return {\n hostname: urlObject.hostname,\n path: urlObject.pathname,\n method: 'GET',\n // Add options and user provided 'options.fetch' overrides if available\n ...options,\n ...options?.fetch,\n // Override with updated headers with accepted encodings:\n headers,\n port: urlObject.port\n };\n}\n\nfunction getStatus(httpResponse: http.IncomingMessage): {status: number; statusText: string} {\n if (httpResponse.statusCode) {\n return {status: httpResponse.statusCode, statusText: httpResponse.statusMessage || 'NA'};\n }\n return {status: 200, statusText: 'OK'};\n}\n\nfunction getHeaders(url, httpResponse, additionalHeaders = {}) {\n const headers = {};\n\n if (httpResponse && httpResponse.headers) {\n const httpHeaders = httpResponse.headers;\n for (const key in httpHeaders) {\n const header = httpHeaders[key];\n headers[key.toLowerCase()] = String(header);\n }\n }\n\n // Fix up content length if we can for best progress experience\n if (!headers['content-length']) {\n const contentLength = getContentLength(url);\n if (Number.isFinite(contentLength)) {\n headers['content-length'] = contentLength;\n }\n }\n\n Object.assign(headers, additionalHeaders);\n\n return new Headers(headers);\n}\n\n/** Needs to be read from actual headers */\nfunction getContentLength(url: string): number | null {\n // TODO - remove media type etc\n return isDataURL(url) ? url.length - 'data:'.length : null;\n}\n"],"mappings":"AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAAQC,QAAQ,QAAO,iBAAiB;AACxC,SAAQC,OAAO,QAAO,gBAAgB;AACtC,SAAQC,aAAa,QAAO,8BAA8B;AAE1D,MAAMC,SAAS,GAAIC,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC;AACnE,MAAMC,YAAY,GAAIF,GAAW,IAAcA,GAAG,CAACC,UAAU,CAAC,OAAO,CAAC,IAAID,GAAG,CAACC,UAAU,CAAC,QAAQ,CAAC;AAQlG,OAAO,eAAeE,SAASA,CAACH,GAAW,EAAEI,OAAoB,EAAqB;EACpF,IAAI;IAGF,IAAIC,UAAU,CAACC,KAAK,KAAKH,SAAS,KAAKD,YAAY,CAACF,GAAG,CAAC,IAAID,SAAS,CAACC,GAAG,CAAC,CAAC,EAAE;MAE3E,OAAO,MAAMM,KAAK,CAACN,GAAG,EAAEI,OAAO,CAAC;IAClC;IAIA,IAAIL,SAAS,CAACC,GAAG,CAAC,EAAE;MAClB,MAAM;QAACO,WAAW;QAAEC;MAAQ,CAAC,GAAGV,aAAa,CAACE,GAAG,CAAC;MAClD,MAAMS,QAAQ,GAAG,IAAIb,QAAQ,CAACW,WAAW,EAAE;QACzCG,OAAO,EAAE;UAAC,cAAc,EAAEF;QAAQ,CAAC;QACnCR;MACF,CAAC,CAAC;MACF,OAAOS,QAAQ;IACjB;IAGA,MAAME,wBAAwB,GAAG,CAAC,CAAC;IACnC,MAAMC,WAAW,GAAGZ,GAAG;IACvB,IAAIA,GAAG,CAACa,QAAQ,CAAC,KAAK,CAAC,EAAE;MACvBb,GAAG,GAAGA,GAAG,CAACc,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;MACtBH,wBAAwB,CAAC,kBAAkB,CAAC,GAAG,MAAM;I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,CAACa,OAAO,CAAC;AAC7B;AAGA,SAASoD,gBAAgBA,CAAC9D,GAAW,EAAiB;EAEpD,OAAOD,SAAS,CAACC,GAAG,CAAC,GAAGA,GAAG,CAAC0D,MAAM,GAAG,OAAO,CAACA,MAAM,GAAG,IAAI;AAC5D"}
@@ -1,11 +1,8 @@
1
- import { ReadableStreamPolyfill } from './readable-stream';
2
1
  import { BlobPolyfill } from './blob';
3
2
  import { FileReaderPolyfill } from './file-reader';
4
3
  import { FilePolyfill } from './file';
5
4
  export function installFilePolyfills() {
6
- if (typeof ReadableStream === 'undefined' && global) {
7
- global.ReadableStream = ReadableStreamPolyfill;
8
- }
5
+ if (typeof ReadableStream === 'undefined' && global) {}
9
6
  if (typeof Blob === 'undefined' && global) {
10
7
  global.Blob = BlobPolyfill;
11
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"install-file-polyfills.js","names":["ReadableStreamPolyfill","BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","ReadableStream","global","Blob","FileReader","File"],"sources":["../../../../src/node/file/install-file-polyfills.ts"],"sourcesContent":["import {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobPolyfill} from './blob';\nimport {FileReaderPolyfill} from './file-reader';\nimport {FilePolyfill} from './file';\n\nexport function installFilePolyfills() {\n if (typeof ReadableStream === 'undefined' && global) {\n // @ts-ignore;\n global.ReadableStream = ReadableStreamPolyfill;\n }\n\n if (typeof Blob === 'undefined' && global) {\n // @ts-ignore;\n global.Blob = BlobPolyfill;\n }\n\n if (typeof FileReader === 'undefined' && global) {\n // @ts-ignore;\n global.FileReader = FileReaderPolyfill;\n }\n\n // Install minimal Node.js File polyfill\n if (typeof File === 'undefined' && global) {\n // @ts-ignore;\n global.File = FilePolyfill;\n }\n}\n"],"mappings":"AAAA,SAAQA,sBAAsB,QAAO,mBAAmB;AACxD,SAAQC,YAAY,QAAO,QAAQ;AACnC,SAAQC,kBAAkB,QAAO,eAAe;AAChD,SAAQC,YAAY,QAAO,QAAQ;AAEnC,OAAO,SAASC,oBAAoBA,CAAA,EAAG;EACrC,IAAI,OAAOC,cAAc,KAAK,WAAW,IAAIC,MAAM,EAAE;IAEnDA,MAAM,CAACD,cAAc,GAAGL,sBAAsB;EAChD;EAEA,IAAI,OAAOO,IAAI,KAAK,WAAW,IAAID,MAAM,EAAE;IAEzCA,MAAM,CAACC,IAAI,GAAGN,YAAY;EAC5B;EAEA,IAAI,OAAOO,UAAU,KAAK,WAAW,IAAIF,MAAM,EAAE;IAE/CA,MAAM,CAACE,UAAU,GAAGN,kBAAkB;EACxC;EAGA,IAAI,OAAOO,IAAI,KAAK,WAAW,IAAIH,MAAM,EAAE;IAEzCA,MAAM,CAACG,IAAI,GAAGN,YAAY;EAC5B;AACF"}
1
+ {"version":3,"file":"install-file-polyfills.js","names":["BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","ReadableStream","global","Blob","FileReader","File"],"sources":["../../../../src/node/file/install-file-polyfills.ts"],"sourcesContent":["// import {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobPolyfill} from './blob';\nimport {FileReaderPolyfill} from './file-reader';\nimport {FilePolyfill} from './file';\n\nexport function installFilePolyfills() {\n if (typeof ReadableStream === 'undefined' && global) {\n // @ts-ignore;\n // global.ReadableStream = ReadableStreamPolyfill;\n }\n\n if (typeof Blob === 'undefined' && global) {\n // @ts-ignore;\n global.Blob = BlobPolyfill;\n }\n\n if (typeof FileReader === 'undefined' && global) {\n // @ts-ignore;\n global.FileReader = FileReaderPolyfill;\n }\n\n // Install minimal Node.js File polyfill\n if (typeof File === 'undefined' && global) {\n // @ts-ignore;\n global.File = FilePolyfill;\n }\n}\n"],"mappings":"AACA,SAAQA,YAAY,QAAO,QAAQ;AACnC,SAAQC,kBAAkB,QAAO,eAAe;AAChD,SAAQC,YAAY,QAAO,QAAQ;AAEnC,OAAO,SAASC,oBAAoBA,CAAA,EAAG;EACrC,IAAI,OAAOC,cAAc,KAAK,WAAW,IAAIC,MAAM,EAAE,CAGrD;EAEA,IAAI,OAAOC,IAAI,KAAK,WAAW,IAAID,MAAM,EAAE;IAEzCA,MAAM,CAACC,IAAI,GAAGN,YAAY;EAC5B;EAEA,IAAI,OAAOO,UAAU,KAAK,WAAW,IAAIF,MAAM,EAAE;IAE/CA,MAAM,CAACE,UAAU,GAAGN,kBAAkB;EACxC;EAGA,IAAI,OAAOO,IAAI,KAAK,WAAW,IAAIH,MAAM,EAAE;IAEzCA,MAAM,CAACG,IAAI,GAAGN,YAAY;EAC5B;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- export { ReadableStreamPolyfill } from './node/file/readable-stream';
2
- export { BlobPolyfill } from './node/file/blob';
3
1
  export { FileReaderPolyfill } from './node/file/file-reader';
4
2
  export { FilePolyfill } from './node/file/file';
5
3
  export { installFilePolyfills } from './node/file/install-file-polyfills';
6
- export { fetchNode as _fetchNode } from './node/fetch/fetch.node';
7
- export { fetchFileNode as _fetchFileNode } from './node/fetch/fetch-file.node';
8
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,sBAAsB,EAAC,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,kBAAkB,EAAC,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAC,SAAS,IAAI,UAAU,EAAC,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAC,aAAa,IAAI,cAAc,EAAC,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAC,kBAAkB,EAAC,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAC,oBAAoB,EAAC,MAAM,oCAAoC,CAAC"}
@@ -6,7 +6,7 @@ import { Response } from './response.node';
6
6
  * @param url
7
7
  * @param options
8
8
  */
9
- export declare function fetchNode(url: string, options: any): Promise<Response>;
9
+ export declare function fetchNode(url: string, options: RequestInit): Promise<Response>;
10
10
  /** Returns a promise that resolves to a readable stream */
11
11
  export declare function createHTTPRequestReadStream(url: string, options: any): Promise<http.IncomingMessage>;
12
12
  //# sourceMappingURL=fetch.node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.node.d.ts","sourceRoot":"","sources":["../../../src/node/fetch/fetch.node.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AASzC;;;;GAIG;AAEH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,KAAA,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6CvE;AAED,2DAA2D;AAC3D,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,MAAM,EACX,OAAO,KAAA,GACN,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAW/B"}
1
+ {"version":3,"file":"fetch.node.d.ts","sourceRoot":"","sources":["../../../src/node/fetch/fetch.node.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAOzC;;;;GAIG;AAEH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgDpF;AAED,2DAA2D;AAC3D,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,MAAM,EACX,OAAO,KAAA,GACN,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAW/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/polyfills",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Polyfills for TextEncoder/TextDecoder",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -105,5 +105,5 @@
105
105
  "through": "^2.3.8",
106
106
  "web-streams-polyfill": "^3.0.0"
107
107
  },
108
- "gitHead": "03ff81ab468f20f3bddeec787aa88d477a7e1c72"
108
+ "gitHead": "35c625e67132b0784e597d9ddabae8aefea29ff2"
109
109
  }
package/src/index.ts CHANGED
@@ -14,13 +14,11 @@ import {fetchNode as fetchNode} from './node/fetch/fetch.node';
14
14
  import {encodeImageNode} from './node/images/encode-image.node';
15
15
  import {parseImageNode, NODE_FORMAT_SUPPORT} from './node/images/parse-image.node';
16
16
 
17
- export {ReadableStreamPolyfill} from './node/file/readable-stream';
18
- export {BlobPolyfill} from './node/file/blob';
17
+ // export {ReadableStreamPolyfill} from './node/file/readable-stream';
18
+ // export {BlobPolyfill} from './node/file/blob';
19
19
  export {FileReaderPolyfill} from './node/file/file-reader';
20
20
  export {FilePolyfill} from './node/file/file';
21
21
  export {installFilePolyfills} from './node/file/install-file-polyfills';
22
- export {fetchNode as _fetchNode} from './node/fetch/fetch.node';
23
- export {fetchFileNode as _fetchFileNode} from './node/fetch/fetch-file.node';
24
22
 
25
23
  // POLYFILLS: TextEncoder, TextDecoder
26
24
  // - Recent Node versions have these classes but virtually no encodings unless special build.
@@ -47,9 +45,11 @@ if (!isBrowser && !('btoa' in global) && base64.btoa) {
47
45
  global['btoa'] = base64.btoa;
48
46
  }
49
47
 
50
- // POLYFILL: fetch
51
- // - Node: Yes
52
- // - Browser: No. For This polyfill is node only, IE11 etc, install external polyfill
48
+ // DEPRECATED POLYFILL:
49
+ // - Node v18+: No, not needed
50
+ // - Node v16 and lower: Yes
51
+ // - Browsers (evergreen): Not needed.
52
+ // - IE11: No. This polyfill is node only, install external polyfill
53
53
 
54
54
  if (!isBrowser && !('Headers' in global) && HeadersNode) {
55
55
  global['Headers'] = HeadersNode;