@loaders.gl/polyfills 3.1.0-alpha.4 → 4.0.0-alpha.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 (114) hide show
  1. package/dist/{esm/bundle.js → bundle.js} +0 -0
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/{esm/index.js → index.js} +0 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/{es5/libs → libs}/encoding-indexes.js +0 -0
  6. package/dist/{es5/libs → libs}/encoding.js +0 -0
  7. package/dist/{esm/node → node}/buffer/btoa.node.js +0 -0
  8. package/dist/node/buffer/btoa.node.js.map +1 -0
  9. package/dist/{esm/node → node}/buffer/to-array-buffer.node.js +0 -0
  10. package/dist/node/buffer/to-array-buffer.node.js.map +1 -0
  11. package/dist/{esm/node → node}/fetch/fetch.node.js +12 -1
  12. package/dist/node/fetch/fetch.node.js.map +1 -0
  13. package/dist/{esm/node → node}/fetch/headers.node.js +1 -1
  14. package/dist/node/fetch/headers.node.js.map +1 -0
  15. package/dist/{esm/node → node}/fetch/response.node.js +0 -0
  16. package/dist/node/fetch/response.node.js.map +1 -0
  17. package/dist/{esm/node → node}/fetch/utils/decode-data-uri.node.js +2 -2
  18. package/dist/node/fetch/utils/decode-data-uri.node.js.map +1 -0
  19. package/dist/{esm/node → node}/fetch/utils/stream-utils.node.js +0 -0
  20. package/dist/node/fetch/utils/stream-utils.node.js.map +1 -0
  21. package/dist/{esm/node → node}/file/blob-stream-controller.js +0 -0
  22. package/dist/node/file/blob-stream-controller.js.map +1 -0
  23. package/dist/{esm/node → node}/file/blob-stream.js +0 -0
  24. package/dist/node/file/blob-stream.js.map +1 -0
  25. package/dist/{esm/node → node}/file/blob.js +0 -0
  26. package/dist/node/file/blob.js.map +1 -0
  27. package/dist/{esm/node → node}/file/file-reader.js +1 -1
  28. package/dist/node/file/file-reader.js.map +1 -0
  29. package/dist/{esm/node → node}/file/file.js +0 -0
  30. package/dist/node/file/file.js.map +1 -0
  31. package/dist/{esm/node → node}/file/install-file-polyfills.js +0 -0
  32. package/dist/node/file/install-file-polyfills.js.map +1 -0
  33. package/dist/{esm/node → node}/file/readable-stream.js +0 -0
  34. package/dist/node/file/readable-stream.js.map +1 -0
  35. package/dist/{esm/node → node}/images/encode-image.node.js +0 -0
  36. package/dist/node/images/encode-image.node.js.map +1 -0
  37. package/dist/{esm/node → node}/images/parse-image.node.js +0 -0
  38. package/dist/node/images/parse-image.node.js.map +1 -0
  39. package/dist/{esm/promise → promise}/all-settled.js +0 -0
  40. package/dist/promise/all-settled.js.map +1 -0
  41. package/dist/utils/assert.js +6 -0
  42. package/dist/utils/assert.js.map +1 -0
  43. package/dist/{esm/utils → utils}/globals.js +0 -0
  44. package/dist/utils/globals.js.map +1 -0
  45. package/package.json +5 -5
  46. package/src/node/fetch/fetch.node.ts +19 -2
  47. package/dist/dist.min.js +0 -2
  48. package/dist/dist.min.js.map +0 -1
  49. package/dist/es5/bundle.js +0 -7
  50. package/dist/es5/bundle.js.map +0 -1
  51. package/dist/es5/index.js +0 -122
  52. package/dist/es5/index.js.map +0 -1
  53. package/dist/es5/node/buffer/btoa.node.js +0 -16
  54. package/dist/es5/node/buffer/btoa.node.js.map +0 -1
  55. package/dist/es5/node/buffer/to-array-buffer.node.js +0 -16
  56. package/dist/es5/node/buffer/to-array-buffer.node.js.map +0 -1
  57. package/dist/es5/node/fetch/fetch.node.js +0 -172
  58. package/dist/es5/node/fetch/fetch.node.js.map +0 -1
  59. package/dist/es5/node/fetch/headers.node.js +0 -175
  60. package/dist/es5/node/fetch/headers.node.js.map +0 -1
  61. package/dist/es5/node/fetch/response.node.js +0 -231
  62. package/dist/es5/node/fetch/response.node.js.map +0 -1
  63. package/dist/es5/node/fetch/utils/decode-data-uri.node.js +0 -74
  64. package/dist/es5/node/fetch/utils/decode-data-uri.node.js.map +0 -1
  65. package/dist/es5/node/fetch/utils/stream-utils.node.js +0 -187
  66. package/dist/es5/node/fetch/utils/stream-utils.node.js.map +0 -1
  67. package/dist/es5/node/file/blob-stream-controller.js +0 -110
  68. package/dist/es5/node/file/blob-stream-controller.js.map +0 -1
  69. package/dist/es5/node/file/blob-stream.js +0 -93
  70. package/dist/es5/node/file/blob-stream.js.map +0 -1
  71. package/dist/es5/node/file/blob.js +0 -259
  72. package/dist/es5/node/file/blob.js.map +0 -1
  73. package/dist/es5/node/file/file-reader.js +0 -189
  74. package/dist/es5/node/file/file-reader.js.map +0 -1
  75. package/dist/es5/node/file/file.js +0 -63
  76. package/dist/es5/node/file/file.js.map +0 -1
  77. package/dist/es5/node/file/install-file-polyfills.js +0 -33
  78. package/dist/es5/node/file/install-file-polyfills.js.map +0 -1
  79. package/dist/es5/node/file/readable-stream.js +0 -40
  80. package/dist/es5/node/file/readable-stream.js.map +0 -1
  81. package/dist/es5/node/images/encode-image.node.js +0 -36
  82. package/dist/es5/node/images/encode-image.node.js.map +0 -1
  83. package/dist/es5/node/images/parse-image.node.js +0 -61
  84. package/dist/es5/node/images/parse-image.node.js.map +0 -1
  85. package/dist/es5/promise/all-settled.js +0 -29
  86. package/dist/es5/promise/all-settled.js.map +0 -1
  87. package/dist/es5/utils/assert.js +0 -13
  88. package/dist/es5/utils/assert.js.map +0 -1
  89. package/dist/es5/utils/globals.js +0 -21
  90. package/dist/es5/utils/globals.js.map +0 -1
  91. package/dist/esm/bundle.js.map +0 -1
  92. package/dist/esm/index.js.map +0 -1
  93. package/dist/esm/libs/encoding-indexes.js +0 -51
  94. package/dist/esm/libs/encoding.js +0 -3084
  95. package/dist/esm/node/buffer/btoa.node.js.map +0 -1
  96. package/dist/esm/node/buffer/to-array-buffer.node.js.map +0 -1
  97. package/dist/esm/node/fetch/fetch.node.js.map +0 -1
  98. package/dist/esm/node/fetch/headers.node.js.map +0 -1
  99. package/dist/esm/node/fetch/response.node.js.map +0 -1
  100. package/dist/esm/node/fetch/utils/decode-data-uri.node.js.map +0 -1
  101. package/dist/esm/node/fetch/utils/stream-utils.node.js.map +0 -1
  102. package/dist/esm/node/file/blob-stream-controller.js.map +0 -1
  103. package/dist/esm/node/file/blob-stream.js.map +0 -1
  104. package/dist/esm/node/file/blob.js.map +0 -1
  105. package/dist/esm/node/file/file-reader.js.map +0 -1
  106. package/dist/esm/node/file/file.js.map +0 -1
  107. package/dist/esm/node/file/install-file-polyfills.js.map +0 -1
  108. package/dist/esm/node/file/readable-stream.js.map +0 -1
  109. package/dist/esm/node/images/encode-image.node.js.map +0 -1
  110. package/dist/esm/node/images/parse-image.node.js.map +0 -1
  111. package/dist/esm/promise/all-settled.js.map +0 -1
  112. package/dist/esm/utils/assert.js +0 -6
  113. package/dist/esm/utils/assert.js.map +0 -1
  114. package/dist/esm/utils/globals.js.map +0 -1
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["DOMParser","isBrowser","global","TextDecoder","TextEncoder","allSettled","base64","HeadersNode","ResponseNode","fetchNode","encodeImageNode","parseImageNode","ReadableStreamPolyfill","BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","installTextEncoder","installTextDecoder","atob","btoa","Promise"],"mappings":"AACA,SAAQA,SAAR,QAAwB,QAAxB;AACA,SAAQC,SAAR,EAAmBC,MAAnB,QAAgC,iBAAhC;AAEA,SAAQC,WA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,GAAoBK,WAApB;AACD;;AAED,IAAI,CAACN,SAAD,IAAc,EAAE,cAAcC,MAAhB,CAAd,IAAyCM,YAA7C,EAA2D;AACzDN,EAAAA,MAAM,CAAC,UAAD,CAAN,GAAqBM,YAArB;AACD;;AAED,IAAI,CAACP,SAAD,IAAc,EAAE,WAAWC,MAAb,CAAd,IAAsCO,SAA1C,EAAqD;AACnDP,EAAAA,MAAM,CAAC,OAAD,CAAN,GAAkBO,SAAlB;AACD;;AAMD,IAAI,CAACR,SAAD,IAAc,EAAE,eAAeC,MAAjB,CAAd,IAA0CF,SAA9C,EAAyD;AACvDE,EAAAA,MAAM,CAAC,WAAD,CAAN,GAAsBF,SAAtB;AACD;;AAMD,IAAI,CAACC,SAAD,IAAc,EAAE,sBAAsBC,MAAxB,CAAd,IAAiDQ,eAArD,EAAsE;AACpER,EAAAA,MAAM,CAAC,kBAAD,CAAN,GAA6BQ,eAA7B;AACD;;AAED,IAAI,CAACT,SAAD,IAAc,EAAE,qBAAqBC,MAAvB,CAAd,IAAgDS,cAApD,EAAoE;AAClET,EAAAA,MAAM,CAAC,iBAAD,CAAN,GAA4BS,cAA5B;AACD;;AAED,IAAI,EAAE,gBAAgBU,OAAlB,CAAJ,EAAgC;AAE9BA,EAAAA,OAAO,CAAChB,UAAR,GAAqBA,UAArB;AACD","sourcesContent":["/* eslint-disable dot-notation */\nimport {DOMParser} from 'xmldom';\nimport {isBrowser, global} from './utils/globals';\n\nimport {TextDecoder, TextEncoder} from './libs/encoding';\nimport {allSettled} from './promise/all-settled';\n\n// Node specific\nimport * as base64 from './node/buffer/btoa.node';\n\nimport HeadersNode from './node/fetch/headers.node';\nimport ResponseNode from './node/fetch/response.node';\nimport fetchNode from './node/fetch/fetch.node';\n\nimport {encodeImageNode} from './node/images/encode-image.node';\nimport {parseImageNode} 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';\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// POLYFILL: DOMParser\n// - Node: Yes\n// - Browser: No\n\nif (!isBrowser && !('DOMParser' in global) && DOMParser) {\n global['DOMParser'] = DOMParser;\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}\n\nif (!('allSettled' in Promise)) {\n // @ts-ignore\n Promise.allSettled = allSettled;\n}\n"],"file":"index.js"}
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/buffer/btoa.node.ts"],"names":["atob","string","Buffer","from","toString","btoa","base64"],"mappings":"AAIA,OAAO,SAASA,IAAT,CAAcC,MAAd,EAAsB;AAC3B,SAAOC,MAAM,CAACC,IAAP,CAAYF,MAAZ,EAAoBG,QAApB,CAA6B,QAA7B,CAAP;AACD;AAED,OAAO,SAASC,IAAT,CAAcC,MAAd,EAAsB;AAC3B,SAAOJ,MAAM,CAACC,IAAP,CAAYG,MAAZ,EAAoB,QAApB,EAA8BF,QAA9B,CAAuC,OAAvC,CAAP;AACD","sourcesContent":["// btoa, atob polyfills for Node.js\n// Note: The atob and btoa functions (not just the polyfills!) are not unicode safe\n// But still useful for unit testing\n\nexport function atob(string) {\n return Buffer.from(string).toString('base64');\n}\n\nexport function btoa(base64) {\n return Buffer.from(base64, 'base64').toString('ascii');\n}\n"],"file":"btoa.node.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/buffer/to-array-buffer.node.ts"],"names":["bufferToArrayBuffer","buffer","Buffer","isBuffer","typedArray","Uint8Array"],"mappings":"AAAA,OAAO,SAASA,mBAAT,CAA6BC,MAA7B,EAAqC;AAE1C,MAAIC,MAAM,CAACC,QAAP,CAAgBF,MAAhB,CAAJ,EAA6B;AAC3B,UAAMG,UAAU,GAAG,IAAIC,UAAJ,CAAeJ,MAAf,CAAnB;AACA,WAAOG,UAAU,CAACH,MAAlB;AACD;;AACD,SAAOA,MAAP;AACD","sourcesContent":["export function bufferToArrayBuffer(buffer) {\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (Buffer.isBuffer(buffer)) {\n const typedArray = new Uint8Array(buffer);\n return typedArray.buffer;\n }\n return buffer;\n}\n"],"file":"to-array-buffer.node.js"}
@@ -41,7 +41,8 @@ export default async function fetchNode(url, options) {
41
41
  const followRedirect = !options || options.followRedirect || options.followRedirect === undefined;
42
42
 
43
43
  if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {
44
- return await fetchNode(headers.get('location'), options);
44
+ const redirectUrl = generateRedirectUrl(url, headers.get('location'));
45
+ return await fetchNode(redirectUrl, options);
45
46
  }
46
47
 
47
48
  return new Response(body, {
@@ -59,6 +60,16 @@ export default async function fetchNode(url, options) {
59
60
  }
60
61
  }
61
62
 
63
+ function generateRedirectUrl(originalUrl, location) {
64
+ if (location.startsWith('http')) {
65
+ return location;
66
+ }
67
+
68
+ const url = new URL(originalUrl);
69
+ url.pathname = location;
70
+ return url.href;
71
+ }
72
+
62
73
  function getStatus(httpResponse) {
63
74
  if (httpResponse.statusCode) {
64
75
  return {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/fetch/fetch.node.ts"],"names":["fs","Response","Headers","decodeDataUri","createReadStream","isDataURL","url","startsWith","isRequestURL","fetchNode","options","arrayBuffer","mimeType","response","headers","syntheticResponseHeaders","originalUrl","endsWith","slice","body","getHeaders","status","statusText","getStatus","followRedirect","undefined","has","redirectUrl","generateRedirectUrl","get","error","String","location","URL","pathname","href","httpResponse","statusCode","statusMessage","additionalHeaders","httpHeaders","key","header","toLowerCase","contentLength","getContentLength","Number","isFinite","Object","assign","length","noqueryUrl","split","stats","statSync","size"],"mappings":"AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,OAAOC,QAAP,MAAqB,iBAArB;AACA,OAAOC,OAAP,MAAoB,gBAApB;AAEA,SAAQC,aAAR,QAA4B,8BAA5B;AACA,SAAQC,gBAAR,QAA+B,2BAA/B;;AAEA,MAAMC,SAAS,GAAIC,GAAD,IAASA,GAAG,CAACC,UAAJ,CAAe,OAAf,CAA3B;;AACA,MAAMC,YAAY,GAAIF,GAAD,IAASA,GAAG,CAACC,UAAJ,CAAe,OAAf,KAA2BD,GAAG,CAACC,UAAJ,CAAe,QAAf,CAAzD;;AAOA,eAAe,eAAeE,SAAf,CAAyBH,GAAzB,EAA8BI,OAA9B,EAAuC;AACpD,MAAI;AAGF,QAAIL,SAAS,CAACC,GAAD,CAAb,EAAoB;AAClB,YAAM;AAACK,QAAAA,WAAD;AAAcC,QAAAA;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G,CAACE,WAAJ,EAAD,CAAP,GAA6BZ,MAAM,CAACW,MAAD,CAAnC;AACD;AACF;;AAGD,MAAI,CAAC5B,OAAO,CAAC,gBAAD,CAAZ,EAAgC;AAC9B,UAAM8B,aAAa,GAAGC,gBAAgB,CAACvC,GAAD,CAAtC;;AACA,QAAIwC,MAAM,CAACC,QAAP,CAAgBH,aAAhB,CAAJ,EAAoC;AAClC9B,MAAAA,OAAO,CAAC,gBAAD,CAAP,GAA4B8B,aAA5B;AACD;AACF;;AAEDI,EAAAA,MAAM,CAACC,MAAP,CAAcnC,OAAd,EAAuByB,iBAAvB;AAEA,SAAO,IAAIrC,OAAJ,CAAYY,OAAZ,CAAP;AACD;;AAED,SAAS+B,gBAAT,CAA0BvC,GAA1B,EAA+B;AAC7B,MAAIE,YAAY,CAACF,GAAD,CAAhB,EAAuB;AAErB,WAAO,IAAP;AACD,GAHD,MAGO,IAAID,SAAS,CAACC,GAAD,CAAb,EAAoB;AAEzB,WAAOA,GAAG,CAAC4C,MAAJ,GAAa,QAAQA,MAA5B;AACD;;AAGD,MAAI;AAEF,UAAMC,UAAU,GAAG7C,GAAG,CAAC8C,KAAJ,CAAU,GAAV,EAAe,CAAf,CAAnB;AACA,UAAMC,KAAK,GAAGrD,EAAE,CAACsD,QAAH,CAAYH,UAAZ,CAAd;AACA,WAAOE,KAAK,CAACE,IAAb;AACD,GALD,CAKE,OAAOzB,KAAP,EAAc,CAEf;;AAED,SAAO,IAAP;AACD","sourcesContent":["import fs from 'fs'; // `fs` will be empty object in browsers (see package.json \"browser\" field).\nimport Response from './response.node';\nimport Headers from './headers.node';\n\nimport {decodeDataUri} from './utils/decode-data-uri.node';\nimport {createReadStream} from './utils/stream-utils.node';\n\nconst isDataURL = (url) => url.startsWith('data:');\nconst isRequestURL = (url) => url.startsWith('http:') || url.startsWith('https:');\n\n/**\n * Emulation of Browser fetch for Node.js\n * @param url\n * @param options\n */\nexport default async function fetchNode(url, options) {\n try {\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 createReadStream(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/**\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// PRIVATE\n\nfunction getStatus(httpResponse) {\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\nfunction getContentLength(url) {\n if (isRequestURL(url)) {\n // Needs to be read from actual headers\n return null;\n } else if (isDataURL(url)) {\n // TODO - remove media type etc\n return url.length - 'data:'.length;\n }\n // File URL\n // TODO - how to handle non-existing file, this presumably just throws\n try {\n // strip query params from URL\n const noqueryUrl = url.split('?')[0];\n const stats = fs.statSync(noqueryUrl);\n return stats.size;\n } catch (error) {\n // ignore for now\n }\n\n return null;\n}\n"],"file":"fetch.node.js"}
@@ -22,7 +22,7 @@ export default class Headers {
22
22
  name = normalizeName(name);
23
23
  value = normalizeValue(value);
24
24
  const oldValue = this.map[name];
25
- this.map[name] = oldValue ? `${oldValue}, ${value}` : value;
25
+ this.map[name] = oldValue ? "".concat(oldValue, ", ").concat(value) : value;
26
26
  }
27
27
 
28
28
  delete(name) {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/fetch/headers.node.ts"],"names":["Symbol","iterator","Headers","constructor","headers","map","forEach","value","name","append","Array","isArray","header","Object","getOwnPropertyNames","normalizeName","normalizeValue","oldValue","delete","get","has","hasOwnProperty","set","visitor","thisArg","call","keys","items","push","iteratorFor","values","entries","String","test","TypeError","toLowerCase","next","shift","done","undefined"],"mappings":";;;;mBA+EIA,MAAM,CAACC,Q;AA3EX,eAAe,MAAMC,OAAN,CAAc;AAG3BC,EAAAA,WAAW,CAACC,OAAD,EAAU;AAAA;;AACnB,SAAKC,GAAL,GAAW,EAAX;;AAEA,QAAID,OAAO,YAAYF,OAAvB,EAAgC;AAC9BE,MAAAA,OAAO,CAACE,OAAR,CAAgB,CAACC,KAAD,EAAQC,IAAR,KAAiB,KAAKC,MAAL,CAAYD,IAAZ,EAAkBD,KAAlB,CAAjC;AACD,KAFD,MAEO,IAAIG,KAAK,CAACC,OAAN,CAAcP,OAAd,CAAJ,EAA4B;AACjCA,MAAAA,OAAO,CAACE,OAAR,CA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,EAA8B;AAC5BA,IAAAA,IAAI,GAAGwB,MAAM,CAACxB,IAAD,CAAb;AACD;;AACD,MAAI,4BAA4ByB,IAA5B,CAAiCzB,IAAjC,KAA0CA,IAAI,KAAK,EAAvD,EAA2D;AACzD,UAAM,IAAI0B,SAAJ,CAAc,wCAAd,CAAN;AACD;;AACD,SAAO1B,IAAI,CAAC2B,WAAL,EAAP;AACD;;AAED,SAASnB,cAAT,CAAwBT,KAAxB,EAA+B;AAC7B,MAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;AAC7BA,IAAAA,KAAK,GAAGyB,MAAM,CAACzB,KAAD,CAAd;AACD;;AACD,SAAOA,KAAP;AACD;;AAGD,SAASsB,WAAT,CAAqBF,KAArB,EAA4B;AAC1B,QAAM1B,QAAQ,GAAG;AACfmC,IAAAA,IAAI,GAAG;AACL,YAAM7B,KAAK,GAAGoB,KAAK,CAACU,KAAN,EAAd;AACA,aAAO;AAACC,QAAAA,IAAI,EAAE/B,KAAK,KAAKgC,SAAjB;AAA4BhC,QAAAA;AAA5B,OAAP;AACD;;AAJc,GAAjB;;AAOAN,EAAAA,QAAQ,CAACD,MAAM,CAACC,QAAR,CAAR,GAA4B,YAAY;AACtC,WAAOA,QAAP;AACD,GAFD;;AAIA,SAAOA,QAAP;AACD","sourcesContent":["/**\n * Polyfill for Browser Headers\n * Based on https://github.com/github/fetch under MIT license\n */\nexport default class Headers {\n map: {};\n\n constructor(headers) {\n this.map = {};\n\n if (headers instanceof Headers) {\n headers.forEach((value, name) => this.append(name, value));\n } else if (Array.isArray(headers)) {\n headers.forEach((header) => this.append(header[0], header[1]));\n } else if (headers) {\n Object.getOwnPropertyNames(headers).forEach((name) => this.append(name, headers[name]));\n }\n }\n\n append(name, value) {\n name = normalizeName(name);\n value = normalizeValue(value);\n const oldValue = this.map[name];\n this.map[name] = oldValue ? `${oldValue}, ${value}` : value;\n }\n\n delete(name) {\n delete this.map[normalizeName(name)];\n }\n\n get(name) {\n name = normalizeName(name);\n return this.has(name) ? this.map[name] : null;\n }\n\n has(name) {\n return this.map.hasOwnProperty(normalizeName(name));\n }\n\n set(name, value) {\n this.map[normalizeName(name)] = normalizeValue(value);\n }\n\n forEach(visitor, thisArg = null) {\n for (const name in this.map) {\n if (this.map.hasOwnProperty(name)) {\n if (thisArg) {\n visitor.call(thisArg, this.map[name], name, this);\n } else {\n visitor(this.map[name], name, this);\n }\n }\n }\n }\n\n keys() {\n const items: any[] = [];\n this.forEach(function (value, name) {\n items.push(name);\n });\n return iteratorFor(items);\n }\n\n values() {\n const items: any[] = [];\n this.forEach(function (value) {\n items.push(value);\n });\n return iteratorFor(items);\n }\n\n entries() {\n const items: any[] = [];\n this.forEach(function (value, name) {\n items.push([name, value]);\n });\n return iteratorFor(items);\n }\n\n *[Symbol.iterator]() {\n // @ts-ignore must have a '[Symbol.iterator]()' method that returns an iterator.\n yield* this.entries();\n }\n}\n\nfunction normalizeName(name) {\n if (typeof name !== 'string') {\n name = String(name);\n }\n if (/[^a-z0-9\\-#$%&'*+.^_`|~]/i.test(name) || name === '') {\n throw new TypeError('Invalid character in header field name');\n }\n return name.toLowerCase();\n}\n\nfunction normalizeValue(value) {\n if (typeof value !== 'string') {\n value = String(value);\n }\n return value;\n}\n\n// Build a destructive iterator for the value list\nfunction iteratorFor(items) {\n const iterator = {\n next() {\n const value = items.shift();\n return {done: value === undefined, value};\n }\n };\n\n iterator[Symbol.iterator] = function () {\n return iterator;\n };\n\n return iterator;\n}\n"],"file":"headers.node.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/fetch/response.node.ts"],"names":["assert","decompressReadStream","concatenateReadStream","Headers","isBoolean","x","isFunction","isObject","isReadableNodeStream","read","pipe","readable","Readable","Response","constructor","body","options","headers","status","statusText","url","ok","_body","from","TextEncoder","encode","ArrayBuffer","bodyUsed","arrayBuffer","data","text","textDecoder","TextDecoder","decode","json","JSON","parse","blob","Blob","Error"],"mappings":";AAAA,SAAQA,MAAR,QAA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ID,IAAJ,CAAS,CAAC,MAAM,KAAKV,WAAL,EAAP,CAAT,CAAP;AACD;;AAzE2B","sourcesContent":["import {assert} from '../../utils/assert';\nimport {decompressReadStream, concatenateReadStream} from './utils/stream-utils.node';\nimport Headers from './headers.node';\n\nconst isBoolean = (x) => typeof x === 'boolean';\nconst isFunction = (x) => typeof x === 'function';\nconst isObject = (x) => x !== null && typeof x === 'object';\nconst isReadableNodeStream = (x) =>\n isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);\n\n/**\n * Polyfill for Browser Response\n *\n * Under Node.js we return a mock \"fetch response object\"\n * so that apps can use the same API as in the browser.\n *\n * Note: This is intended to be a \"lightweight\" implementation and will have limitations.\n *\n * See https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\nimport {Readable} from 'stream';\n\nexport default class Response {\n readonly ok: boolean;\n readonly status: number;\n readonly statusText: string;\n readonly headers: Headers;\n readonly url: string;\n bodyUsed: boolean = false;\n private readonly _body;\n\n // TODO - handle ArrayBuffer, ArrayBufferView, Buffer\n constructor(\n body,\n options: {\n headers?;\n status?: number;\n statusText?: string;\n url: string;\n }\n ) {\n const {headers, status = 200, statusText = 'OK', url} = options || {};\n\n this.url = url;\n this.ok = status === 200;\n this.status = status; // TODO - handle errors and set status\n this.statusText = statusText;\n this.headers = new Headers(options?.headers || {});\n\n // Check for content-encoding and create a decompression stream\n if (isReadableNodeStream(body)) {\n this._body = decompressReadStream(body, headers);\n } else if (typeof body === 'string') {\n this._body = Readable.from([new TextEncoder().encode(body)]);\n } else {\n this._body = Readable.from([body || new ArrayBuffer(0)]);\n }\n }\n\n // Subset of Properties\n\n // Returns a readable stream to the \"body\" of the response (or file)\n get body() {\n assert(!this.bodyUsed);\n assert(isReadableNodeStream(this._body)); // Not implemented: conversion of ArrayBuffer etc to stream\n this.bodyUsed = true;\n return this._body;\n }\n\n // Subset of Methods\n\n async arrayBuffer() {\n if (!isReadableNodeStream(this._body)) {\n return this._body || new ArrayBuffer(0);\n }\n const data = await concatenateReadStream(this._body);\n return data;\n }\n\n async text() {\n const arrayBuffer = await this.arrayBuffer();\n const textDecoder = new TextDecoder();\n return textDecoder.decode(arrayBuffer);\n }\n\n async json() {\n const text = await this.text();\n return JSON.parse(text);\n }\n\n async blob() {\n if (typeof Blob === 'undefined') {\n throw new Error('Blob polyfill not installed');\n }\n return new Blob([await this.arrayBuffer()]);\n }\n}\n"],"file":"response.node.js"}
@@ -20,7 +20,7 @@ export function decodeDataUri(uri) {
20
20
  if (!mimeType) {
21
21
  mimeType = 'text/plain;charset=US-ASCII';
22
22
  } else if (mimeType.startsWith(';')) {
23
- mimeType = `text/plain${mimeType}`;
23
+ mimeType = "text/plain".concat(mimeType);
24
24
  }
25
25
 
26
26
  return {
@@ -52,6 +52,6 @@ export function toArrayBuffer(data) {
52
52
  return data._toArrayBuffer();
53
53
  }
54
54
 
55
- return assert(false, `toArrayBuffer(${JSON.stringify(data, null, 2).slice(10)})`);
55
+ return assert(false, "toArrayBuffer(".concat(JSON.stringify(data, null, 2).slice(10), ")"));
56
56
  }
57
57
  //# sourceMappingURL=decode-data-uri.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/node/fetch/utils/decode-data-uri.node.ts"],"names":["assert","isArrayBuffer","x","ArrayBuffer","isBuffer","Buffer","decodeDataUri","uri","dataIndex","indexOf","buffer","mimeType","slice","from","trim","decodeURIComponent","startsWith","arrayBuffer","toArrayBuffer","data","typedArray","Uint8Array","isView","text","uint8Array","TextEncoder","encode","_toArrayBuffer","JSON","stringify"],"mappings":"AAEA,SAAQA,MAAR,QAAqB,uBAArB;;AAEA,MAAMC,aAAa,GAAIC,CAAD,IAAOA,CAAC,IAAIA,CAAC,YAAYC,WAA/C;;AACA,MAAMC,QAAQ,GAAIF,CAAD,IAAOA,CAAC,IAAIA,CAAC,YAAYG,MAA1C;;AAQA,OAAO,SAASC,aAAT,CAAuBC,GAAvB,EAA4B;AACjC,QAAMC,SAAS,GAAGD,G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CAACmB,MAAZ,CAAmBH,IAAnB,CAAJ,EAA8B;AAC5B,WAAOA,IAAI,CAACT,MAAZ;AACD;;AAED,MAAI,OAAOS,IAAP,KAAgB,QAApB,EAA8B;AAC5B,UAAMI,IAAI,GAAGJ,IAAb;AACA,UAAMK,UAAU,GAAG,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBH,IAAzB,CAAnB;AACA,WAAOC,UAAU,CAACd,MAAlB;AACD;;AAGD,MAAIS,IAAI,IAAI,OAAOA,IAAP,KAAgB,QAAxB,IAAoCA,IAAI,CAACQ,cAA7C,EAA6D;AAC3D,WAAOR,IAAI,CAACQ,cAAL,EAAP;AACD;;AAED,SAAO3B,MAAM,CAAC,KAAD,0BAAyB4B,IAAI,CAACC,SAAL,CAAeV,IAAf,EAAqB,IAArB,EAA2B,CAA3B,EAA8BP,KAA9B,CAAoC,EAApC,CAAzB,OAAb;AACD","sourcesContent":["// Based on binary-gltf-utils under MIT license: Copyright (c) 2016-17 Karl Cheng\n\nimport {assert} from '../../../utils/assert';\n\nconst isArrayBuffer = (x) => x && x instanceof ArrayBuffer;\nconst isBuffer = (x) => x && x instanceof Buffer;\n\n/**\n * Parses a data URI into a buffer, as well as retrieving its declared MIME type.\n *\n * @param {string} uri - a data URI (assumed to be valid)\n * @returns {Object} { buffer, mimeType }\n */\nexport function decodeDataUri(uri) {\n const dataIndex = uri.indexOf(',');\n\n let buffer;\n let mimeType;\n if (uri.slice(dataIndex - 7, dataIndex) === ';base64') {\n buffer = Buffer.from(uri.slice(dataIndex + 1), 'base64');\n mimeType = uri.slice(5, dataIndex - 7).trim();\n } else {\n buffer = Buffer.from(decodeURIComponent(uri.slice(dataIndex + 1)));\n mimeType = uri.slice(5, dataIndex).trim();\n }\n\n if (!mimeType) {\n mimeType = 'text/plain;charset=US-ASCII';\n } else if (mimeType.startsWith(';')) {\n mimeType = `text/plain${mimeType}`;\n }\n\n return {arrayBuffer: toArrayBuffer(buffer), mimeType};\n}\n\n/**\n * @param data\n * @todo Duplicate of core\n */\nexport function toArrayBuffer(data) {\n if (isArrayBuffer(data)) {\n return data;\n }\n\n // TODO - per docs we should just be able to call buffer.buffer, but there are issues\n if (isBuffer(data)) {\n const typedArray = new Uint8Array(data);\n return typedArray.buffer;\n }\n\n // Careful - Node Buffers will look like ArrayBuffers (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n return data.buffer;\n }\n\n if (typeof data === 'string') {\n const text = data;\n const uint8Array = new TextEncoder().encode(text);\n return uint8Array.buffer;\n }\n\n // HACK to support Blob polyfill\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n return data._toArrayBuffer();\n }\n\n return assert(false, `toArrayBuffer(${JSON.stringify(data, null, 2).slice(10)})`);\n}\n"],"file":"decode-data-uri.node.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/node/fetch/utils/stream-utils.node.ts"],"names":["fs","http","https","zlib","toArrayBuffer","isRequestURL","url","startsWith","createReadStream","options","noqueryUrl","split","Promise","resolve","reject","stream","encoding","once","on","error","requestFunction","request","requestOptions","getRequestOptions","req","res","end","decompressReadStream","readStream","headers","get","pipe","createBrotliDecompress","createGunzip","createDeflate","concatenateReadStream","arrayBuffer","ArrayBuffer","read","chunk","Error","chunkAsArrayBuffer","concatenateArrayBuffers","originalHeaders","key","Object","keys","toLowerCase","urlObject","URL","hostname","path","pathname","method","fetch","source1","source2","sourceArray1","Uint8Array","sourceArray2","temp","byteLength","set","buffer"],"mappings":"AAAA,OAAOA,EAAP,MAAe,IAAf;AACA,OAAOC,IAAP,MAAiB,MAAjB;AACA,OAAOC,KAAP,MAAkB,OAAlB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AAEA,SAAQC,aAAR,QAA4B,wBAA5B;;AAEA,MAAMC,YAAY,GAAIC,GAAD,IAASA,GAAG,CAACC,UAAJ,CAAe,OAAf,KAA2BD,GAAG,CAACC,UAAJ,CAAe,QAAf,CAAzD;;AAGA,OAAO,eAAeC,gBAAf,CAAgCF,GA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AK,MAAMe,GAAX,IAAkBC,MAAM,CAACC,IAAP,CAAYH,eAAZ,CAAlB,EAAgD;AAC9Cd,IAAAA,OAAO,CAACe,GAAG,CAACG,WAAJ,EAAD,CAAP,GAA6BJ,eAAe,CAACC,GAAD,CAA5C;AACD;;AAGDf,EAAAA,OAAO,CAAC,iBAAD,CAAP,GAA6BA,OAAO,CAAC,iBAAD,CAAP,IAA8B,iBAA3D;AAEA,QAAMmB,SAAS,GAAG,IAAIC,GAAJ,CAAQ3C,GAAR,CAAlB;AACA,SAAO;AACL4C,IAAAA,QAAQ,EAAEF,SAAS,CAACE,QADf;AAELC,IAAAA,IAAI,EAAEH,SAAS,CAACI,QAFX;AAGLC,IAAAA,MAAM,EAAE,KAHH;AAKL,OAAG5C,OALE;AAML,QAAGA,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAE6C,KAAZ,CANK;AAQLzB,IAAAA;AARK,GAAP;AAUD;;AAED,SAASa,uBAAT,CAAiCa,OAAjC,EAA0CC,OAA1C,EAAmD;AACjD,QAAMC,YAAY,GAAGF,OAAO,YAAYlB,WAAnB,GAAiC,IAAIqB,UAAJ,CAAeH,OAAf,CAAjC,GAA2DA,OAAhF;AACA,QAAMI,YAAY,GAAGH,OAAO,YAAYnB,WAAnB,GAAiC,IAAIqB,UAAJ,CAAeF,OAAf,CAAjC,GAA2DA,OAAhF;AACA,QAAMI,IAAI,GAAG,IAAIF,UAAJ,CAAeD,YAAY,CAACI,UAAb,GAA0BF,YAAY,CAACE,UAAtD,CAAb;AACAD,EAAAA,IAAI,CAACE,GAAL,CAASL,YAAT,EAAuB,CAAvB;AACAG,EAAAA,IAAI,CAACE,GAAL,CAASH,YAAT,EAAuBF,YAAY,CAACI,UAApC;AACA,SAAOD,IAAI,CAACG,MAAZ;AACD","sourcesContent":["import fs from 'fs'; // `fs` will be empty object in browsers (see package.json \"browser\" field).\nimport http from 'http';\nimport https from 'https';\nimport zlib from 'zlib';\n\nimport {toArrayBuffer} from './decode-data-uri.node';\n\nconst isRequestURL = (url) => url.startsWith('http:') || url.startsWith('https:');\n\n// Returns a promise that resolves to a readable stream\nexport async function createReadStream(url, options) {\n // Handle file streams in node\n if (!isRequestURL(url)) {\n const noqueryUrl = url.split('?')[0];\n // Now open the stream\n return await new Promise((resolve, reject) => {\n // @ts-ignore\n const stream = fs.createReadStream(noqueryUrl, {encoding: null});\n stream.once('readable', () => resolve(stream));\n stream.on('error', (error) => reject(error));\n });\n }\n\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 requestFunction = url.startsWith('https:') ? https.request : http.request;\n const requestOptions = getRequestOptions(url, options);\n const req = requestFunction(requestOptions, (res) => resolve(res));\n req.on('error', (error) => reject(error));\n req.end();\n });\n}\n\nexport function decompressReadStream(readStream, headers) {\n switch (headers.get('content-encoding')) {\n case 'br':\n return readStream.pipe(zlib.createBrotliDecompress());\n case 'gzip':\n return readStream.pipe(zlib.createGunzip());\n case 'deflate':\n return readStream.pipe(zlib.createDeflate());\n default:\n // No compression or an unknown one, just return it as is\n return readStream;\n }\n}\n\nexport async function concatenateReadStream(readStream) {\n let arrayBuffer = new ArrayBuffer(0);\n\n return await new Promise((resolve, reject) => {\n readStream.on('error', (error) => reject(error));\n\n // Once the readable callback has been added, stream switches to \"flowing mode\"\n // In Node 10 (but not 12 and 14) this causes `data` and `end` to never be called unless we read data here\n readStream.on('readable', () => readStream.read());\n\n readStream.on('data', (chunk) => {\n if (typeof chunk === 'string') {\n reject(new Error('Read stream not binary'));\n }\n const chunkAsArrayBuffer = toArrayBuffer(chunk);\n arrayBuffer = concatenateArrayBuffers(arrayBuffer, chunkAsArrayBuffer);\n });\n\n readStream.on('end', () => resolve(arrayBuffer));\n });\n}\n\n// HELPERS\n\nfunction getRequestOptions(url, 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 };\n}\n\nfunction concatenateArrayBuffers(source1, source2) {\n const sourceArray1 = source1 instanceof ArrayBuffer ? new Uint8Array(source1) : source1;\n const sourceArray2 = source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2;\n const temp = new Uint8Array(sourceArray1.byteLength + sourceArray2.byteLength);\n temp.set(sourceArray1, 0);\n temp.set(sourceArray2, sourceArray1.byteLength);\n return temp.buffer;\n}\n"],"file":"stream-utils.node.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/blob-stream-controller.ts"],"names":["BlobStreamController","constructor","chunks","start","controller","work","isWorking","isCancelled","desiredSize","next","error","done","enqueue","value","close","pull","cancel"],"mappings":";AAIA,OAAO,MAAMA,oBAAN,CAA2B;AAQhCC,EAAAA,WAAW,CAACC,MAAD,EAA+B;AAAA;;AAAA,uCANb,KAMa;;AAAA,yCALX,KAKW;;AACxC,SAAKA,MAAL,GAAcA,MAAd;AACD;;AAKDC,EAAAA,KAAK,CAACC,UAAD,EAA8C;AACjD,SAAKC,IAAL,CAAUD,UAAV;AACD;;AAMS,QAAJC,IAAI,CAACD,UAAD,EAA8C;AACtD,UAAM;AAACF,MAAAA;AAAD,QAAW,IAAjB;AAEA,SAAKI,SAAL,GAAiB,IAAjB;;AACA,WAAO,CAAC,KAAKC,WAAN,IAAqB,CAACH,UAAU,CAACI,WAAX,IAA0B,CAA3B,IAAgC,CAA5D,EAA+D;AAC7D,UAAIC,IAAJ;;AACA,UAAI;AACFA,QAAAA,IAAI,GAAGP,MAAM,CAACO,IAAP,EAAP;AACD,OAFD,CAEE,OAAOC,KAAP,EAAc;AACdN,QAAAA,UAAU,CAACM,KAAX,CAAiBA,KAAjB;AACA;AACD;;AAED,UAAID,IAAJ,EAAU;AACR,YAAI,CAACA,IAAI,CAACE,IAAN,IAAc,CAAC,KAAKJ,WAAxB,EAAqC;AACnCH,UAAAA,UAAU,CAACQ,OAAX,CAAmBH,IAAI,CAACI,KAAxB;AACD,SAFD,MAEO;AACLT,UAAAA,UAAU,CAACU,KAAX;AACD;AACF;AACF;;AAED,SAAKR,SAAL,GAAiB,KAAjB;AACD;;AAMDS,EAAAA,IAAI,CAACX,UAAD,EAAa;AACf,QAAI,CAAC,KAAKE,SAAV,EAAqB;AACnB,WAAKD,IAAL,CAAUD,UAAV;AACD;AACF;;AACDY,EAAAA,MAAM,GAAG;AACP,SAAKT,WAAL,GAAmB,IAAnB;AACD;;AA3D+B","sourcesContent":["/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nexport class BlobStreamController {\n private chunks: Iterator<Uint8Array>;\n private isWorking: boolean = false;\n private isCancelled: boolean = false;\n\n /**\n * @param chunks\n */\n constructor(chunks: Iterator<Uint8Array>) {\n this.chunks = chunks;\n }\n\n /**\n * @param controller\n */\n start(controller: ReadableStreamDefaultController) {\n this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n\n /**\n *\n * @param controller\n */\n async work(controller: ReadableStreamDefaultController) {\n const {chunks} = this;\n\n this.isWorking = true;\n while (!this.isCancelled && (controller.desiredSize || 0) > 0) {\n let next: {done?: boolean; value?: Uint8Array} | undefined;\n try {\n next = chunks.next();\n } catch (error) {\n controller.error(error);\n break;\n }\n\n if (next) {\n if (!next.done && !this.isCancelled) {\n controller.enqueue(next.value);\n } else {\n controller.close();\n }\n }\n }\n\n this.isWorking = false;\n }\n\n /**\n *\n * @param {ReadableStreamDefaultController} controller\n */\n pull(controller) {\n if (!this.isWorking) {\n this.work(controller); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n cancel() {\n this.isCancelled = true;\n }\n}\n"],"file":"blob-stream-controller.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/blob-stream.ts"],"names":["ReadableStreamPolyfill","BlobStreamController","Symbol","asyncIterator","BlobStream","constructor","chunks","values","type","_chunks","_options","reader","getReader","releaseLock"],"mappings":";;;;AAIA,SAAQA,sBAAR,QAAqC,mBAArC;AACA,SAAQC,oBAAR,QAAmC,0BAAnC;wBAyBUC,MAAM,CAACC,a;AAhBjB,OAAO,MAAMC,UAAN,SAA4BJ,sBAA5B,CAAsD;AAK3DK,EAAAA,WAAW,CAACC,MAAD,EAAS;AAElB,UAAM,IAAIL,oBAAJ,CAAyBK,MAAM,CAACC,MAAP,EAAzB,CAAN,EAAiD;AAACC,MAAAA,IAAI,EAAE;AAAP,KAAjD;;AAFkB;;AAIlB,SAAKC,OAAL,GAAeH,MAAf;AACD;;AAMD,iCAA8BI,QAA9B,EAA+F;AAC7F,UAAMC,MAAM,GAAG,KAAKC,SAAL,EAAf;AACA,WAAO,KAAKH,OAAZ;AACAE,IAAAA,MAAM,CAACE,WAAP;AACD;;AApB0D","sourcesContent":["/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nimport {ReadableStreamPolyfill} from './readable-stream';\nimport {BlobStreamController} from './blob-stream-controller';\n\n/**\n * Blob stream is a `ReadableStream` extension optimized to have minimal\n * overhead when consumed as `AsyncIterable<Uint8Array>`.\n * extends {ReadableStream<Uint8Array>}\n * implements {AsyncIterable<Uint8Array>}\n */\n// @ts-ignore\nexport class BlobStream<T> extends ReadableStreamPolyfill<T> {\n private readonly _chunks: Uint8Array[];\n /**\n * @param chunks\n */\n constructor(chunks) {\n // @ts-ignore\n super(new BlobStreamController(chunks.values()), {type: 'bytes'});\n /** @private */\n this._chunks = chunks;\n }\n\n /**\n * @property [_options.preventCancel]\n */\n // @ts-ignore\n async *[Symbol.asyncIterator](_options?: {preventCancel?: boolean}): AsyncIterable<Uint8Array> {\n const reader = this.getReader();\n yield* this._chunks;\n reader.releaseLock();\n }\n}\n"],"file":"blob-stream.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/blob.ts"],"names":["BlobStream","Symbol","toStringTag","BlobPolyfill","constructor","init","options","parts","size","part","bytes","TextEncoder","encode","push","byteLength","ArrayBuffer","Uint8Array","isView","buffer","byteOffset","String","type","readType","slice","start","end","offset","Math","max","min","limit","span","blob","blobSize","blobParts","chunk","subarray","arrayBuffer","_toArrayBuffer","text","decoder","TextDecoder","decode","stream","toString","set","input","toLowerCase","test"],"mappings":";;;;AACA,SAAQA,UAAR,QAAyB,eAAzB;sBAsJOC,MAAM,CAACC,W;AAhJd,OAAO,MAAMC,YAAN,CAAmB;AAWxBC,EAAAA,WAAW,CAACC,IAAgB,GAAG,EAApB,EAAwBC,OAAwB,GAAG,EAAnD,EAAuD;AAAA;;AAAA;;AAAA;;AAChE,SAAKC,KAAL,GAAa,EAAb;AAEA,SAAKC,IAAL,GAAY,CAAZ;;AACA,SAAK,MAAMC,IAAX,IAAmBJ,IAAnB,EAAyB;AACvB,UAAI,OAAOI,IAAP,KAAgB,QAApB,EAA8B;AAC5B,cAAMC,KAAK,GAAG,IAAIC,WAAJ,GAAkBC,MAAlB,CAAyBH,IAAzB,CAAd;AACA,aAAKF,KAAL,CAAWM,IAAX,CAAgBH,KAAhB;AACA,aAAKF,IAAL,IAAaE,KAAK,CAACI,UAAnB;AACD,OAJD,MAIO,IAAIL,IAAI,YAAYN,YAApB,EAAkC;AACvC,aAAKK,IAAL,IAAaC,IAAI,CAACD,IAAlB;AAGA,aAAKD,KAAL,CAAWM,IAAX,CAAgB,GAAGJ,IAAI,CAACF,KAAxB;AACD,OALM,MAKA,IAAIE,IAAI,YAAYM,WAApB,EAAiC;AACtC,aAAKR,KAAL,CAAWM,IAAX,CAAgB,IAAIG,UAAJ,CAAeP,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GAAG,IAAIC,WAAJ,EAAhB;AACA,QAAIF,IAAI,GAAG,EAAX;;AACA,SAAK,MAAM9B,IAAX,IAAmB,KAAKF,KAAxB,EAA+B;AAC7BgC,MAAAA,IAAI,IAAIC,OAAO,CAACE,MAAR,CAAejC,IAAf,CAAR;AACD;;AACD,WAAO8B,IAAP;AACD;;AAKDI,EAAAA,MAAM,GAAoB;AACxB,WAAO,IAAI3C,UAAJ,CAAoB,KAAKO,KAAzB,CAAP;AACD;;AAKDqC,EAAAA,QAAQ,GAAG;AACT,WAAO,eAAP;AACD;;AAED,8BAA2B;AACzB,WAAO,MAAP;AACD;;AAEDN,EAAAA,cAAc,GAAgB;AAC5B,UAAMpB,MAAM,GAAG,IAAIH,WAAJ,CAAgB,KAAKP,IAArB,CAAf;AACA,UAAME,KAAK,GAAG,IAAIM,UAAJ,CAAeE,MAAf,CAAd;AACA,QAAIQ,MAAM,GAAG,CAAb;;AACA,SAAK,MAAMjB,IAAX,IAAmB,KAAKF,KAAxB,EAA+B;AAC7BG,MAAAA,KAAK,CAACmC,GAAN,CAAUpC,IAAV,EAAgBiB,MAAhB;AACAA,MAAAA,MAAM,IAAIjB,IAAI,CAACK,UAAf;AACD;;AACD,WAAOI,MAAP;AACD;;AA7JuB;;AAkK1B,SAASI,QAAT,CAAkBwB,KAAa,GAAG,EAAlC,EAA8C;AAC5C,QAAMzB,IAAI,GAAGD,MAAM,CAAC0B,KAAD,CAAN,CAAcC,WAAd,EAAb;AACA,SAAO,mBAAmBC,IAAnB,CAAwB3B,IAAxB,IAAgC,EAAhC,GAAqCA,IAA5C;AACD","sourcesContent":["// Forked from @gozala's web-blob under MIT license https://github.com/Gozala/web-blob\nimport {BlobStream} from './blob-stream';\n\n/**\n * Forked from @gozala's web-blob under MIT license\n * @see https://github.com/Gozala/web-blob\n */\nexport class BlobPolyfill {\n // implements Blob {\n /** The MIME type of the data contained in the Blob. If type is unknown, string is empty. */\n readonly type: string;\n /** The size, in bytes, of the data contained in the Blob object. */\n size: number;\n private parts: Uint8Array[];\n /**\n * @param [init]\n * @param [options]\n */\n constructor(init: BlobPart[] = [], options: BlobPropertyBag = {}) {\n this.parts = [];\n\n this.size = 0;\n for (const part of init) {\n if (typeof part === 'string') {\n const bytes = new TextEncoder().encode(part);\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n } else if (part instanceof BlobPolyfill) {\n this.size += part.size;\n // @ts-ignore - `parts` is marked private so TS will complain about\n // accessing it.\n this.parts.push(...part.parts);\n } else if (part instanceof ArrayBuffer) {\n this.parts.push(new Uint8Array(part));\n this.size += part.byteLength;\n } else if (part instanceof Uint8Array) {\n this.parts.push(part);\n this.size += part.byteLength;\n } else if (ArrayBuffer.isView(part)) {\n const {buffer, byteOffset, byteLength} = part;\n this.parts.push(new Uint8Array(buffer, byteOffset, byteLength));\n this.size += byteLength;\n } else {\n const bytes = new TextEncoder().encode(String(part));\n this.parts.push(bytes);\n this.size += bytes.byteLength;\n }\n }\n\n /** @private */\n this.type = readType(options.type);\n }\n\n /**\n * Returns a new Blob object containing the data in the specified range of\n * bytes of the blob on which it's called.\n * @param start=0 - An index into the Blob indicating the first\n * byte to include in the new Blob. If you specify a negative value, it's\n * treated as an offset from the end of the Blob toward the beginning. For\n * example, `-10` would be the 10th from last byte in the Blob. The default\n * value is `0`. If you specify a value for start that is larger than the\n * size of the source Blob, the returned Blob has size 0 and contains no\n * data.\n * @param end - An index into the `Blob` indicating the first byte\n * that will *not* be included in the new `Blob` (i.e. the byte exactly at\n * this index is not included). If you specify a negative value, it's treated\n * as an offset from the end of the Blob toward the beginning. For example,\n * `-10` would be the 10th from last byte in the `Blob`. The default value is\n * size.\n * @param type - The content type to assign to the new Blob;\n * this will be the value of its type property. The default value is an empty\n * string.\n */\n slice(start: number = 0, end: number = this.size, type: string = ''): Blob {\n const {size, parts: parts} = this;\n let offset = start < 0 ? Math.max(size + start, 0) : Math.min(start, size);\n\n let limit = end < 0 ? Math.max(size + end, 0) : Math.min(end, size);\n const span = Math.max(limit - offset, 0);\n const blob = new BlobPolyfill([], {type});\n\n if (span === 0) {\n // @ts-ignore\n return blob;\n }\n\n let blobSize = 0;\n const blobParts: Uint8Array[] = [];\n for (const part of parts) {\n const {byteLength} = part;\n if (offset > 0 && byteLength <= offset) {\n offset -= byteLength;\n limit -= byteLength;\n } else {\n const chunk = part.subarray(offset, Math.min(byteLength, limit));\n blobParts.push(chunk);\n blobSize += chunk.byteLength;\n // no longer need to take that into account\n offset = 0;\n\n // don't add the overflow to new blobParts\n if (blobSize >= span) {\n break;\n }\n }\n }\n\n blob.parts = blobParts;\n blob.size = blobSize;\n\n // @ts-ignore\n return blob;\n }\n\n /**\n * Returns a promise that resolves with an ArrayBuffer containing the entire\n * contents of the Blob as binary data.\n */\n // eslint-disable-next-line require-await\n async arrayBuffer(): Promise<ArrayBuffer> {\n return this._toArrayBuffer();\n }\n\n /**\n * Returns a promise that resolves with a USVString containing the entire\n * contents of the Blob interpreted as UTF-8 text.\n */\n // eslint-disable-next-line require-await\n async text(): Promise<string> {\n const decoder = new TextDecoder();\n let text = '';\n for (const part of this.parts) {\n text += decoder.decode(part);\n }\n return text;\n }\n\n /**\n */\n // @ts-ignore\n stream(): BlobStream<any> {\n return new BlobStream<any>(this.parts);\n }\n\n /**\n * @returns {string}\n */\n toString() {\n return '[object Blob]';\n }\n\n get [Symbol.toStringTag]() {\n return 'Blob';\n }\n\n _toArrayBuffer(): ArrayBuffer {\n const buffer = new ArrayBuffer(this.size);\n const bytes = new Uint8Array(buffer);\n let offset = 0;\n for (const part of this.parts) {\n bytes.set(part, offset);\n offset += part.byteLength;\n }\n return buffer;\n }\n}\n\n/**\n */\nfunction readType(input: string = ''): string {\n const type = String(input).toLowerCase();\n return /[^\\u0020-\\u007E]/.test(type) ? '' : type;\n}\n"],"file":"blob.js"}
@@ -57,7 +57,7 @@ export class FileReaderPolyfill {
57
57
 
58
58
  async readAsDataURL(blob) {
59
59
  const text = await blob.text();
60
- const dataUrl = `data://;base64,${atob(text)}`;
60
+ const dataUrl = "data://;base64,".concat(atob(text));
61
61
 
62
62
  if (this.onload) {
63
63
  this.onload({
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/file-reader.ts"],"names":["atob","FileReaderPolyfill","constructor","onload","abort","readAsArrayBuffer","blob","arrayBuffer","target","result","readAsBinaryString","Error","readAsDataURL","text","dataUrl","readAsText"],"mappings":";AAAA,SAAQA,IAAR,QAAmB,qBAAnB;AAEA,OAAO,MAAMC,kBAAN,CAA+C;AAmBpDC,EAAAA,WAAW,GAAG;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,MAAL,GAAc,IAAd;AACD;;AAEDC,EAAAA,KAAK,GAAS;AACZ;AACD;;AAEsB,QAAjBC,iBAAiB,CAACC,IAAD,EAA4B;AACjD,UAAMC,WAAW,GAAG,MAAMD,IAAI,CAACC,WAAL,EAA1B;;AACA,QAAI,KAAKJ,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEF;AAAT;AAAT,OAAZ;AACD;AACF;;AAEuB,QAAlBG,kBAAkB,CAACJ,IAAD,EAAO;AAC7B,UAAMK,KAAK,CAAC,iBAAD,CAAX;AACD;;AAEkB,QAAbC,aAAa,CAACN,IAAD,EAAO;AACxB,UAAMO,IAAI,GAAG,MAAMP,IAAI,CAACO,IAAL,EAAnB;AACA,UAAMC,OAAO,4BAAqBd,IAAI,CAACa,IAAD,CAAzB,CAAb;;AACA,QAAI,KAAKV,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEK;AAAT;AAAT,OAAZ;AACD;AACF;;AAEe,QAAVC,UAAU,CAACT,IAAD,EAAO;AACrB,UAAMO,IAAI,GAAG,MAAMP,IAAI,CAACO,IAAL,EAAnB;;AACA,QAAI,KAAKV,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAY;AAACK,QAAAA,MAAM,EAAE;AAACC,UAAAA,MAAM,EAAEI;AAAT;AAAT,OAAZ;AACD;AACF;;AAnDmD","sourcesContent":["import {atob} from '../buffer/btoa.node';\n\nexport class FileReaderPolyfill implements FileReader {\n // onload: ({result: any}) => void;\n onload;\n onabort;\n onerror;\n error;\n onloadstart;\n onloadend;\n onprogress;\n\n readyState;\n result;\n DONE;\n EMPTY;\n LOADING;\n addEventListener;\n removeEventListener;\n dispatchEvent;\n\n constructor() {\n this.onload = null;\n }\n\n abort(): void {\n return;\n }\n\n async readAsArrayBuffer(blob: Blob): Promise<void> {\n const arrayBuffer = await blob.arrayBuffer();\n if (this.onload) {\n this.onload({target: {result: arrayBuffer}});\n }\n }\n\n async readAsBinaryString(blob) {\n throw Error('Not implemented');\n }\n\n async readAsDataURL(blob) {\n const text = await blob.text();\n const dataUrl = `data://;base64,${atob(text)}`;\n if (this.onload) {\n this.onload({target: {result: dataUrl}});\n }\n }\n\n async readAsText(blob) {\n const text = await blob.text();\n if (this.onload) {\n this.onload({target: {result: text}});\n }\n }\n}\n"],"file":"file-reader.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/file.ts"],"names":["BlobPolyfill","Symbol","toStringTag","FilePolyfill","constructor","init","name","options","String","replace","lastModified","Date","now"],"mappings":";;;;AACA,SAAQA,YAAR,QAA2B,QAA3B;sBAqCOC,MAAM,CAACC,W;AA9Bd,OAAO,MAAMC,YAAN,SAA2BH,YAA3B,CAAwC;AAoB7CI,EAAAA,WAAW,CAACC,IAAD,EAAmBC,IAAnB,EAAiCC,OAAwB,GAAG,EAA5D,EAAgE;AACzE,UAAMF,IAAN,EAAYE,OAAZ;;AADyE,kCAhB5D,EAgB4D;;AAAA,gDAd9C,EAc8C;;AAAA;;AAKzE,SAAKD,IAAL,GAAYE,MAAM,CAACF,IAAD,CAAN,CAAaG,OAAb,CAAqB,KAArB,EAA4B,GAA5B,CAAZ;AAEA,SAAKC,YAAL,GAAoB,CAAAH,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEG,YAAT,KAAyBC,IAAI,CAACC,GAAL,EAA7C;AACD;;AAED,8BAA2B;AACzB,WAAO,MAAP;AACD;;AAhC4C","sourcesContent":["// Forked from @gozala's web-file under MIT license https://github.com/Gozala/web-file\nimport {BlobPolyfill} from './blob';\n\n/**\n * Forked from @gozala's web-file under MIT license\n * @see https://github.com/Gozala/web-file\n */\n// @ts-ignore\nexport class FilePolyfill extends BlobPolyfill {\n // implements File {\n // public API\n /** The name of the file referenced by the File object. */\n name: string = '';\n /** The path the URL of the File is relative to. */\n webkitRelativePath: string = '';\n\n /**\n * Returns the last modified time of the file, in millisecond since the UNIX\n * epoch (January 1st, 1970 at Midnight).\n */\n lastModified: number;\n\n /**\n * @param init\n * @param name - A USVString representing the file name or the path\n * to the file.\n * @param [options]\n */\n constructor(init: BlobPart[], name: string, options: FilePropertyBag = {}) {\n super(init, options);\n // Per File API spec https://w3c.github.io/FileAPI/#file-constructor\n // Every \"/\" character of file name must be replaced with a \":\".\n /** @private */\n this.name = String(name).replace(/\\//g, ':');\n /** @private */\n this.lastModified = options?.lastModified || Date.now();\n }\n\n get [Symbol.toStringTag]() {\n return 'File';\n }\n}\n"],"file":"file.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/install-file-polyfills.ts"],"names":["ReadableStreamPolyfill","BlobPolyfill","FileReaderPolyfill","FilePolyfill","installFilePolyfills","ReadableStream","global","Blob","FileReader","File"],"mappings":"AAAA,SAAQA,sBAAR,QAAqC,mBAArC;AACA,SAAQC,YAAR,QAA2B,QAA3B;AACA,SAAQC,kBAAR,QAAiC,eAAjC;AACA,SAAQC,YAAR,QAA2B,QAA3B;AAEA,OAAO,SAASC,oBAAT,GAAgC;AACrC,MAAI,OAAOC,cAAP,KAA0B,WAA1B,IAAyCC,MAA7C,EAAqD;AAEnDA,IAAAA,MAAM,CAACD,cAAP,GAAwBL,sBAAxB;AACD;;AAED,MAAI,OAAOO,IAAP,KAAgB,WAAhB,IAA+BD,MAAnC,EAA2C;AAEzCA,IAAAA,MAAM,CAACC,IAAP,GAAcN,YAAd;AACD;;AAED,MAAI,OAAOO,UAAP,KAAsB,WAAtB,IAAqCF,MAAzC,EAAiD;AAE/CA,IAAAA,MAAM,CAACE,UAAP,GAAoBN,kBAApB;AACD;;AAGD,MAAI,OAAOO,IAAP,KAAgB,WAAhB,IAA+BH,MAAnC,EAA2C;AAEzCA,IAAAA,MAAM,CAACG,IAAP,GAAcN,YAAd;AACD;AACF","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"],"file":"install-file-polyfills.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/file/readable-stream.ts"],"names":["ReadableStream","WSPReadableStream","global","ReadableStreamPolyfill"],"mappings":"AAAA,SAAQA,cAAc,IAAIC,iBAA1B,QAAkD,sBAAlD;AAIA,OAAOC,MAAM,CAACF,cAAd;AAGA,OAAO,MAAMG,sBAAN,SAAwCF,iBAAxC,CAAuF","sourcesContent":["import {ReadableStream as WSPReadableStream} from 'web-streams-polyfill';\n\n// Want a polyfill, but please don't install it\n// @ts-ignore\ndelete global.ReadableStream;\n\n// @ts-ignore\nexport class ReadableStreamPolyfill<T> extends WSPReadableStream<T> implements ReadableStream {}\n"],"file":"readable-stream.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/images/encode-image.node.ts"],"names":["savePixels","ndarray","bufferToArrayBuffer","encodeImageToStreamNode","image","options","type","replace","pixels","data","width","height","encodeImageNode","imageStream","Promise","resolve","buffers","on","buffer","push","Buffer","concat"],"mappings":"AAEA,OAAOA,UAAP,MAAuB,aAAvB;AACA,OAAOC,OAAP,MAAoB,SAApB;AACA,SAAQC,mBAAR,QAAkC,gCAAlC;AAYA,OAAO,SAASC,uBAAT,CACLC,KADK,EAELC,OAFK,EAGL;AAEA,QAAMC,IAAI,GAAGD,OAAO,CAACC,IAAR,GAAeD,OAAO,CAACC,IAAR,CAAaC,OAAb,CAAqB,QAArB,EAA+B,EAA/B,CAAf,GAAoD,MAAjE;AACA,QAAMC,MAAM,GAAGP,OAAO,CAACG,KAAK,CAACK,IAAP,EAAa,CAACL,KAAK,CAACM,KAAP,EAAcN,KAAK,CAACO,MAApB,EAA4B,CAA5B,CAAb,EAA6C,CAAC,CAAD,EAAIP,KAAK,CAACM,KAAN,GAAc,CAAlB,EAAqB,CAArB,CAA7C,EAAsE,CAAtE,CAAtB;AAGA,SAAOV,UAAU,CAACQ,MAAD,EAASF,IAAT,EAAeD,OAAf,CAAjB;AACD;AAED,OAAO,SAASO,eAAT,CAAyBR,KAAzB,EAAgCC,OAAhC,EAAyC;AAC9C,QAAMQ,WAAW,GAAGV,uBAAuB,CAACC,KAAD,EAAQC,OAAR,CAA3C;AAEA,SAAO,IAAIS,OAAJ,CAAaC,OAAD,IAAa;AAC9B,UAAMC,OAAc,GAAG,EAAvB;AACAH,IAAAA,WAAW,CAACI,EAAZ,CAAe,MAAf,EAAwBC,MAAD,IAAYF,OAAO,CAACG,IAAR,CAAaD,MAAb,CAAnC;AAEAL,IAAAA,WAAW,CAACI,EAAZ,CAAe,KAAf,EAAsB,MAAM;AAC1B,YAAMC,MAAM,GAAGE,MAAM,CAACC,MAAP,CAAcL,OAAd,CAAf;AACAD,MAAAA,OAAO,CAACb,mBAAmB,CAACgB,MAAD,CAApB,CAAP;AACD,KAHD;AAID,GARM,CAAP;AASD","sourcesContent":["// Use stackgl modules for DOM-less reading and writing of images\n\nimport savePixels from 'save-pixels';\nimport ndarray from 'ndarray';\nimport {bufferToArrayBuffer} from '../buffer/to-array-buffer.node';\n\n/**\n * Returns data bytes representing a compressed image in PNG or JPG format,\n * This data can be saved using file system (f) methods or\n * used in a request.\n * @param image to save\n * @param options\n * @param options.type='png' - png, jpg or image/png, image/jpg are valid\n * @param options.dataURI - Whether to include a data URI header\n * @return {*} bytes\n */\nexport function encodeImageToStreamNode(\n image: {data: any; width: number; height: number},\n options: {type?: string; dataURI?: string}\n) {\n // Support MIME type strings\n const type = options.type ? options.type.replace('image/', '') : 'jpeg';\n const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);\n\n // Note: savePixels returns a stream\n return savePixels(pixels, type, options);\n}\n\nexport function encodeImageNode(image, options) {\n const imageStream = encodeImageToStreamNode(image, options);\n\n return new Promise((resolve) => {\n const buffers: any[] = [];\n imageStream.on('data', (buffer) => buffers.push(buffer));\n // TODO - convert to arraybuffer?\n imageStream.on('end', () => {\n const buffer = Buffer.concat(buffers);\n resolve(bufferToArrayBuffer(buffer));\n });\n });\n}\n"],"file":"encode-image.node.js"}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/node/images/parse-image.node.ts"],"names":["getPixels","assert","util","parseImageNode","arrayBuffer","mimeType","getPixelsAsync","promisify","buffer","Buffer","from","ndarray","shape","layers","length","shift","data","width","height","components"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,YAAtB;AACA,SAAQC,MAAR,QAAqB,oBAArB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AAYA,OAAO,eAAeC,cAAf,CAA8BC,WAA9B,EAAwDC,QAAxD,EAA4F;AACjGJ,EAAAA,MAAM,CAACI,QAAD,EAAW,mDAAX,CAAN;AAIA,QAAMC,cAAc,GAAGJ,IAAI,CAACK,SAAL,CAAeP,SAAf,CAAvB;AAEA,QAAMQ,MAAM,GAAGJ,WAAW,YAAYK,MAAvB,GAAgCL,WAAhC,GAA8CK,MAAM,CAACC,IAAP,CAAYN,WAAZ,CAA7D;AAEA,QAAMO,OAAO,GAAG,MAAML,cAAc,CAACE,MAAD,EAASH,QAAT,CAApC;AAEA,QAAMO,KAAK,GAAG,CAAC,GAAGD,OAAO,CAACC,KAAZ,CAAd;AACA,QAAMC,MAAM,GAAGF,OAAO,CAACC,KAAR,CAAcE,MAAd,KAAyB,CAAzB,GAA6BH,OAAO,CAACC,KAAR,CAAcG,KAAd,EAA7B,GAAqD,CAApE;AAGA,SAAO;AACLH,IAAAA,KADK;AAELI,IAAAA,IAAI,EAAEL,OAAO,CAACK,IAFT;AAGLC,IAAAA,KAAK,EAAEN,OAAO,CAACC,KAAR,CAAc,CAAd,CAHF;AAILM,IAAAA,MAAM,EAAEP,OAAO,CAACC,KAAR,CAAc,CAAd,CAJH;AAKLO,IAAAA,UAAU,EAAER,OAAO,CAACC,KAAR,CAAc,CAAd,CALP;AAMLC,IAAAA;AANK,GAAP;AAQD","sourcesContent":["import getPixels from 'get-pixels';\nimport {assert} from '../../utils/assert';\nimport util from 'util';\n\n// Note: These types are also defined in @loaders.gl/images and need to be kept in sync\ntype NDArray = {\n shape: number[];\n data: Uint8Array;\n width: number;\n height: number;\n components: number;\n layers: number[];\n};\n\nexport async function parseImageNode(arrayBuffer: ArrayBuffer, mimeType: string): Promise<NDArray> {\n assert(mimeType, 'MIMEType is required to parse image under Node.js');\n\n // TODO - check if getPixels callback is asynchronous if provided with buffer input\n // if not, parseImage can be a sync function\n const getPixelsAsync = util.promisify(getPixels);\n\n const buffer = arrayBuffer instanceof Buffer ? arrayBuffer : Buffer.from(arrayBuffer);\n\n const ndarray = await getPixelsAsync(buffer, mimeType);\n\n const shape = [...ndarray.shape];\n const layers = ndarray.shape.length === 4 ? ndarray.shape.shift() : 1;\n\n // extract width/height etc\n return {\n shape,\n data: ndarray.data,\n width: ndarray.shape[0],\n height: ndarray.shape[1],\n components: ndarray.shape[2],\n layers\n };\n}\n"],"file":"parse-image.node.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/promise/all-settled.ts"],"names":["REJECTED_STATUS","FULFILLED_STATUS","allSettled","promises","mappedPromises","map","promise","then","value","status","catch","reason","Promise","all"],"mappings":"AAAA,OAAO,MAAMA,eAAe,GAAG,UAAxB;AACP,OAAO,MAAMC,gBAAgB,GAAG,WAAzB;AAQP,OAAO,SAASC,UAAT,CAAoBC,QAApB,EAA4D;AACjE,QAAMC,cAAc,GAAGD,QAAQ,CAACE,GAAT,CAAcC,OAAD,IAAa;AAC/C,WAAOA,OAAO,CACXC,IADI,CACEC,KAAD,IAAW;AACf,aAAO;AAACC,QAAAA,MAAM,EAAER,gBAAT;AAA2BO,QAAAA;AAA3B,OAAP;AACD,KAHI,EAIJE,KAJI,CAIGC,MAAD,IAAY;AACjB,aAAO;AAACF,QAAAA,MAAM,EAAET,eAAT;AAA0BW,QAAAA;AAA1B,OAAP;AACD,KANI,CAAP;AAOD,GARsB,CAAvB;AASA,SAAOC,OAAO,CAACC,GAAR,CAAYT,cAAZ,CAAP;AACD","sourcesContent":["export const REJECTED_STATUS = 'rejected';\nexport const FULFILLED_STATUS = 'fulfilled';\n\n/**\n * Handle list of promises and return all values regardless of results.\n * Polyfill for Promise.allSettled() method.\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled\n * @param promises\n */\nexport function allSettled(promises: Promise<any>[]): Promise<any> {\n const mappedPromises = promises.map((promise) => {\n return promise\n .then((value) => {\n return {status: FULFILLED_STATUS, value};\n })\n .catch((reason) => {\n return {status: REJECTED_STATUS, reason};\n });\n });\n return Promise.all(mappedPromises);\n}\n"],"file":"all-settled.js"}
@@ -0,0 +1,6 @@
1
+ export function assert(condition, message) {
2
+ if (!condition) {
3
+ throw new Error("@loaders.gl/polyfills assertion ".concat(message));
4
+ }
5
+ }
6
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/assert.ts"],"names":["assert","condition","message","Error"],"mappings":"AAAA,OAAO,SAASA,MAAT,CAAgBC,SAAhB,EAAgCC,OAAhC,EAAwD;AAC7D,MAAI,CAACD,SAAL,EAAgB;AACd,UAAM,IAAIE,KAAJ,2CAA6CD,OAA7C,EAAN;AACD;AACF","sourcesContent":["export function assert(condition: any, message?: string): void {\n if (!condition) {\n throw new Error(`@loaders.gl/polyfills assertion ${message}`);\n }\n}\n"],"file":"assert.js"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/globals.ts"],"names":["isBrowser","process","String","browser","globals","self","window","global","global_"],"mappings":"AAwBA,MAAMA,SAAkB,GAEtB,OAAOC,OAAP,KAAmB,QAAnB,IAA+BC,MAAM,CAACD,OAAD,CAAN,KAAoB,kBAAnD,IAAyEA,OAAO,CAACE,OAFnF;AAIA,MAAMC,OAAO,GAAG;AACdC,EAAAA,IAAI,EAAE,OAAOA,IAAP,KAAgB,WAAhB,IAA+BA,IADvB;AAEdC,EAAAA,MAAM,EAAE,OAAOA,MAAP,KAAkB,WAAlB,IAAiCA,MAF3B;AAGdC,EAAAA,MAAM,EAAE,OAAOA,MAAP,KAAkB,WAAlB,IAAiCA;AAH3B,CAAhB;AAMA,MAAMC,OAAe,GAAIJ,OAAO,CAACG,MAAR,IAAkBH,OAAO,CAACC,IAA1B,IAAkCD,OAAO,CAACE,MAAnE;AAEA,SAAQN,SAAR,EAAmBQ,OAAO,IAAID,MAA9B","sourcesContent":["// Copyright (c) 2015 - 2017 Uber Technologies, Inc.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\n// Purpose: include this in your module to avoids adding dependencies on\n// micro modules like 'global' and 'is-browser';\n\n/* eslint-disable no-restricted-globals */\nconst isBrowser: boolean =\n // @ts-ignore process.browser\n typeof process !== 'object' || String(process) !== '[object process]' || process.browser;\n\nconst globals = {\n self: typeof self !== 'undefined' && self,\n window: typeof window !== 'undefined' && window,\n global: typeof global !== 'undefined' && global\n};\n\nconst global_: object = (globals.global || globals.self || globals.window) as object;\n\nexport {isBrowser, global_ as global};\n"],"file":"globals.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/polyfills",
3
- "version": "3.1.0-alpha.4",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "Polyfills for TextEncoder/TextDecoder",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -18,8 +18,8 @@
18
18
  "TextDecoder"
19
19
  ],
20
20
  "types": "src/index.ts",
21
- "main": "dist/es5/index.js",
22
- "module": "dist/esm/index.js",
21
+ "main": "dist/index.js",
22
+ "module": "dist/index.js",
23
23
  "files": [
24
24
  "src",
25
25
  "dist",
@@ -93,7 +93,7 @@
93
93
  },
94
94
  "scripts": {
95
95
  "pre-build": "npm run build-bundle",
96
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js"
96
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js"
97
97
  },
98
98
  "dependencies": {
99
99
  "@babel/runtime": "^7.3.1",
@@ -105,5 +105,5 @@
105
105
  "web-streams-polyfill": "^3.0.0",
106
106
  "xmldom": "^0.5.0"
107
107
  },
108
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
108
+ "gitHead": "e48f5534fe7188c810f23f965a440c144b3cf6d0"
109
109
  }
@@ -43,10 +43,11 @@ export default async function fetchNode(url, options) {
43
43
  !options || options.followRedirect || options.followRedirect === undefined;
44
44
 
45
45
  if (status >= 300 && status < 400 && headers.has('location') && followRedirect) {
46
+ const redirectUrl = generateRedirectUrl(url, headers.get('location'));
47
+
46
48
  // Redirect
47
- return await fetchNode(headers.get('location'), options);
49
+ return await fetchNode(redirectUrl, options);
48
50
  }
49
-
50
51
  return new Response(body, {headers, status, statusText, url});
51
52
  } catch (error) {
52
53
  // TODO - what error code to use here?
@@ -54,6 +55,22 @@ export default async function fetchNode(url, options) {
54
55
  }
55
56
  }
56
57
 
58
+ /**
59
+ * Generate redirect url from location without origin and protocol.
60
+ * @param originalUrl
61
+ * @param redirectUrl
62
+ */
63
+ function generateRedirectUrl(originalUrl: string, location: string): string {
64
+ if (location.startsWith('http')) {
65
+ return location;
66
+ }
67
+ // If url doesn't have origin and protocol just extend current url origin with location.
68
+ const url = new URL(originalUrl);
69
+ url.pathname = location;
70
+
71
+ return url.href;
72
+ }
73
+
57
74
  // HELPER FUNCTIONS
58
75
  // PRIVATE
59
76