@loaders.gl/core 3.4.0-alpha.3 → 3.4.0-alpha.5

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 (103) hide show
  1. package/dist/dist.min.js +127 -97
  2. package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
  3. package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -1
  4. package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
  5. package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
  6. package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
  7. package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
  8. package/dist/es5/lib/api/encode.js.map +1 -1
  9. package/dist/es5/lib/api/parse-in-batches.js +15 -14
  10. package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
  11. package/dist/es5/lib/api/parse-sync.js +3 -4
  12. package/dist/es5/lib/api/parse-sync.js.map +1 -1
  13. package/dist/es5/lib/api/parse.js +3 -3
  14. package/dist/es5/lib/api/parse.js.map +1 -1
  15. package/dist/es5/lib/api/register-loaders.js.map +1 -1
  16. package/dist/es5/lib/api/select-loader.js +6 -7
  17. package/dist/es5/lib/api/select-loader.js.map +1 -1
  18. package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
  19. package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
  20. package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
  21. package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -1
  22. package/dist/es5/lib/init.js +1 -1
  23. package/dist/es5/lib/init.js.map +1 -1
  24. package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
  25. package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
  26. package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -1
  27. package/dist/es5/lib/loader-utils/loader-context.js +16 -8
  28. package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
  29. package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -1
  30. package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
  31. package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
  32. package/dist/es5/lib/utils/resource-utils.js +31 -27
  33. package/dist/es5/lib/utils/resource-utils.js.map +1 -1
  34. package/dist/es5/lib/utils/response-utils.js +6 -5
  35. package/dist/es5/lib/utils/response-utils.js.map +1 -1
  36. package/dist/es5/lib/utils/url-utils.js +16 -0
  37. package/dist/es5/lib/utils/url-utils.js.map +1 -0
  38. package/dist/es5/null-loader.js +1 -1
  39. package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
  40. package/dist/esm/iterators/make-iterator/make-blob-iterator.js.map +1 -1
  41. package/dist/esm/iterators/make-iterator/make-stream-iterator.js.map +1 -1
  42. package/dist/esm/iterators/make-iterator/make-string-iterator.js.map +1 -1
  43. package/dist/esm/iterators/make-stream/make-dom-stream.js.map +1 -1
  44. package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -1
  45. package/dist/esm/lib/api/encode.js.map +1 -1
  46. package/dist/esm/lib/api/parse-in-batches.js +6 -7
  47. package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
  48. package/dist/esm/lib/api/parse-sync.js +4 -6
  49. package/dist/esm/lib/api/parse-sync.js.map +1 -1
  50. package/dist/esm/lib/api/parse.js +3 -5
  51. package/dist/esm/lib/api/parse.js.map +1 -1
  52. package/dist/esm/lib/api/register-loaders.js.map +1 -1
  53. package/dist/esm/lib/api/select-loader.js +7 -10
  54. package/dist/esm/lib/api/select-loader.js.map +1 -1
  55. package/dist/esm/lib/fetch/fetch-error-message.js.map +1 -1
  56. package/dist/esm/lib/fetch/read-array-buffer.js.map +1 -1
  57. package/dist/esm/lib/filesystems/browser-filesystem.js.map +1 -1
  58. package/dist/esm/lib/filesystems/read-array-buffer.js.map +1 -1
  59. package/dist/esm/lib/init.js +1 -1
  60. package/dist/esm/lib/init.js.map +1 -1
  61. package/dist/esm/lib/loader-utils/check-errors.js.map +1 -1
  62. package/dist/esm/lib/loader-utils/get-data.js.map +1 -1
  63. package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -1
  64. package/dist/esm/lib/loader-utils/loader-context.js +16 -8
  65. package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
  66. package/dist/esm/lib/loader-utils/option-defaults.js.map +1 -1
  67. package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
  68. package/dist/esm/lib/progress/fetch-progress.js.map +1 -1
  69. package/dist/esm/lib/utils/resource-utils.js +29 -26
  70. package/dist/esm/lib/utils/resource-utils.js.map +1 -1
  71. package/dist/esm/lib/utils/response-utils.js +3 -5
  72. package/dist/esm/lib/utils/response-utils.js.map +1 -1
  73. package/dist/esm/lib/utils/url-utils.js +9 -0
  74. package/dist/esm/lib/utils/url-utils.js.map +1 -0
  75. package/dist/esm/null-loader.js +1 -1
  76. package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
  77. package/dist/lib/api/parse-in-batches.js +4 -7
  78. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  79. package/dist/lib/api/parse-sync.js +3 -3
  80. package/dist/lib/api/parse.js +2 -2
  81. package/dist/lib/api/select-loader.d.ts.map +1 -1
  82. package/dist/lib/api/select-loader.js +6 -3
  83. package/dist/lib/loader-utils/loader-context.d.ts +1 -1
  84. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
  85. package/dist/lib/loader-utils/loader-context.js +17 -7
  86. package/dist/lib/utils/resource-utils.d.ts +17 -8
  87. package/dist/lib/utils/resource-utils.d.ts.map +1 -1
  88. package/dist/lib/utils/resource-utils.js +46 -34
  89. package/dist/lib/utils/response-utils.d.ts.map +1 -1
  90. package/dist/lib/utils/response-utils.js +2 -1
  91. package/dist/lib/utils/url-utils.d.ts +3 -0
  92. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  93. package/dist/lib/utils/url-utils.js +14 -0
  94. package/dist/null-worker.js +1 -1
  95. package/package.json +4 -4
  96. package/src/lib/api/parse-in-batches.ts +8 -9
  97. package/src/lib/api/parse-sync.ts +8 -4
  98. package/src/lib/api/parse.ts +3 -3
  99. package/src/lib/api/select-loader.ts +7 -4
  100. package/src/lib/loader-utils/loader-context.ts +19 -8
  101. package/src/lib/utils/resource-utils.ts +54 -34
  102. package/src/lib/utils/response-utils.ts +3 -2
  103. package/src/lib/utils/url-utils.ts +12 -0
@@ -1,38 +1,44 @@
1
1
  import { isResponse, isBlob } from '../../javascript-utils/is-type';
2
2
  import { parseMIMEType, parseMIMETypeFromURL } from './mime-type-utils';
3
- const QUERY_STRING_PATTERN = /\?.*/;
4
- export function getResourceUrlAndType(resource) {
3
+ import { stripQueryString } from './url-utils';
4
+ export function getResourceUrl(resource) {
5
5
  if (isResponse(resource)) {
6
- const url = stripQueryString(resource.url || '');
7
- const contentTypeHeader = resource.headers.get('content-type') || '';
8
- return {
9
- url,
10
- type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)
11
- };
6
+ const response = resource;
7
+ return response.url;
12
8
  }
13
9
  if (isBlob(resource)) {
14
- return {
15
- url: stripQueryString(resource.name || ''),
16
- type: resource.type || ''
17
- };
10
+ const blob = resource;
11
+ return blob.name || '';
18
12
  }
19
13
  if (typeof resource === 'string') {
20
- return {
21
- url: stripQueryString(resource),
22
- type: parseMIMETypeFromURL(resource)
23
- };
24
- }
25
- return {
26
- url: '',
27
- type: ''
28
- };
14
+ return resource;
15
+ }
16
+ return '';
17
+ }
18
+ export function getResourceMIMEType(resource) {
19
+ if (isResponse(resource)) {
20
+ const response = resource;
21
+ const contentTypeHeader = response.headers.get('content-type') || '';
22
+ const noQueryUrl = stripQueryString(response.url);
23
+ return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
24
+ }
25
+ if (isBlob(resource)) {
26
+ const blob = resource;
27
+ return blob.type || '';
28
+ }
29
+ if (typeof resource === 'string') {
30
+ return parseMIMETypeFromURL(resource);
31
+ }
32
+ return '';
29
33
  }
30
34
  export function getResourceContentLength(resource) {
31
35
  if (isResponse(resource)) {
32
- return resource.headers['content-length'] || -1;
36
+ const response = resource;
37
+ return response.headers['content-length'] || -1;
33
38
  }
34
39
  if (isBlob(resource)) {
35
- return resource.size;
40
+ const blob = resource;
41
+ return blob.size;
36
42
  }
37
43
  if (typeof resource === 'string') {
38
44
  return resource.length;
@@ -45,7 +51,4 @@ export function getResourceContentLength(resource) {
45
51
  }
46
52
  return -1;
47
53
  }
48
- function stripQueryString(url) {
49
- return url.replace(QUERY_STRING_PATTERN, '');
50
- }
51
54
  //# sourceMappingURL=resource-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-utils.js","names":["isResponse","isBlob","parseMIMEType","parseMIMETypeFromURL","QUERY_STRING_PATTERN","getResourceUrlAndType","resource","url","stripQueryString","contentTypeHeader","headers","get","type","name","getResourceContentLength","size","length","ArrayBuffer","byteLength","isView","replace"],"sources":["../../../../src/lib/utils/resource-utils.ts"],"sourcesContent":["import {isResponse, isBlob} from '../../javascript-utils/is-type';\nimport {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';\n\nconst QUERY_STRING_PATTERN = /\\?.*/;\n\n/**\n * Returns an object with `url` and (MIME) `type` fields\n * If it cannot determine url or type, the corresponding value will be an empty string\n *\n * @param resource Any type, but only Responses, string URLs and data URLs are processed\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceUrlAndType(resource: any): {url: string; type: string} {\n // If resource is a response, it contains the information directly\n if (isResponse(resource)) {\n const url = stripQueryString(resource.url || '');\n const contentTypeHeader = resource.headers.get('content-type') || '';\n return {\n url,\n type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)\n };\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n return {\n // File objects have a \"name\" property. Blob objects don't have any\n // url (name) information\n url: stripQueryString(resource.name || ''),\n type: resource.type || ''\n };\n }\n\n if (typeof resource === 'string') {\n return {\n // TODO this could mess up data URL but it doesn't matter as it is just used for inference\n url: stripQueryString(resource),\n // If a data url\n type: parseMIMETypeFromURL(resource)\n };\n }\n\n // Unknown\n return {\n url: '',\n type: ''\n };\n}\n\n/**\n * Returns (approximate) content length for a resource if it can be determined.\n * Returns -1 if content length cannot be determined.\n * @param resource\n\n * @note string parameters are NOT assumed to be URLs\n */\nexport function getResourceContentLength(resource: any): number {\n if (isResponse(resource)) {\n return resource.headers['content-length'] || -1;\n }\n if (isBlob(resource)) {\n return resource.size;\n }\n if (typeof resource === 'string') {\n // TODO - handle data URL?\n return resource.length;\n }\n if (resource instanceof ArrayBuffer) {\n return resource.byteLength;\n }\n if (ArrayBuffer.isView(resource)) {\n return resource.byteLength;\n }\n return -1;\n}\n\nfunction stripQueryString(url) {\n return url.replace(QUERY_STRING_PATTERN, '');\n}\n"],"mappings":"AAAA,SAAQA,UAAU,EAAEC,MAAM,QAAO,gCAAgC;AACjE,SAAQC,aAAa,EAAEC,oBAAoB,QAAO,mBAAmB;AAErE,MAAMC,oBAAoB,GAAG,MAAM;AAUnC,OAAO,SAASC,qBAAqBA,CAACC,QAAa,EAA+B;EAEhF,IAAIN,UAAU,CAACM,QAAQ,CAAC,EAAE;IACxB,MAAMC,GAAG,GAAGC,gBAAgB,CAACF,QAAQ,CAACC,GAAG,IAAI,EAAE,CAAC;IAChD,MAAME,iBAAiB,GAAGH,QAAQ,CAACI,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE;IACpE,OAAO;MACLJ,GAAG;MACHK,IAAI,EAAEV,aAAa,CAACO,iBAAiB,CAAC,IAAIN,oBAAoB,CAACI,GAAG;IACpE,CAAC;EACH;EAGA,IAAIN,MAAM,CAACK,QAAQ,CAAC,EAAE;IACpB,OAAO;MAGLC,GAAG,EAAEC,gBAAgB,CAACF,QAAQ,CAACO,IAAI,IAAI,EAAE,CAAC;MAC1CD,IAAI,EAAEN,QAAQ,CAACM,IAAI,IAAI;IACzB,CAAC;EACH;EAEA,IAAI,OAAON,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAO;MAELC,GAAG,EAAEC,gBAAgB,CAACF,QAAQ,CAAC;MAE/BM,IAAI,EAAET,oBAAoB,CAACG,QAAQ;IACrC,CAAC;EACH;EAGA,OAAO;IACLC,GAAG,EAAE,EAAE;IACPK,IAAI,EAAE;EACR,CAAC;AACH;AASA,OAAO,SAASE,wBAAwBA,CAACR,QAAa,EAAU;EAC9D,IAAIN,UAAU,CAACM,QAAQ,CAAC,EAAE;IACxB,OAAOA,QAAQ,CAACI,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;EACjD;EACA,IAAIT,MAAM,CAACK,QAAQ,CAAC,EAAE;IACpB,OAAOA,QAAQ,CAACS,IAAI;EACtB;EACA,IAAI,OAAOT,QAAQ,KAAK,QAAQ,EAAE;IAEhC,OAAOA,QAAQ,CAACU,MAAM;EACxB;EACA,IAAIV,QAAQ,YAAYW,WAAW,EAAE;IACnC,OAAOX,QAAQ,CAACY,UAAU;EAC5B;EACA,IAAID,WAAW,CAACE,MAAM,CAACb,QAAQ,CAAC,EAAE;IAChC,OAAOA,QAAQ,CAACY,UAAU;EAC5B;EACA,OAAO,CAAC,CAAC;AACX;AAEA,SAASV,gBAAgBA,CAACD,GAAG,EAAE;EAC7B,OAAOA,GAAG,CAACa,OAAO,CAAChB,oBAAoB,EAAE,EAAE,CAAC;AAC9C"}
1
+ {"version":3,"file":"resource-utils.js","names":["isResponse","isBlob","parseMIMEType","parseMIMETypeFromURL","stripQueryString","getResourceUrl","resource","response","url","blob","name","getResourceMIMEType","contentTypeHeader","headers","get","noQueryUrl","type","getResourceContentLength","size","length","ArrayBuffer","byteLength","isView"],"sources":["../../../../src/lib/utils/resource-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {isResponse, isBlob} from '../../javascript-utils/is-type';\nimport {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';\nimport {stripQueryString} from './url-utils';\n\n/**\n * A loadable resource. Includes:\n * `Response`, `Blob` (`File` is a subclass), string URLs and data URLs\n */\nexport type Resource = Response | Blob | string;\n\n/**\n * Returns the URL associated with this resource.\n * The returned value may include a query string and need further processing.\n * If it cannot determine url, the corresponding value will be an empty string\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceUrl(resource: unknown): string {\n // If resource is a `Response`, it contains the information directly as a field\n if (isResponse(resource)) {\n const response = resource as Response;\n return response.url;\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n const blob = resource as Blob;\n // File objects have a \"name\" property. Blob objects don't have any\n // url (name) information\n return blob.name || '';\n }\n\n if (typeof resource === 'string') {\n return resource;\n }\n\n // Unknown\n return '';\n}\n\n/**\n * Returns the URL associated with this resource.\n * The returned value may include a query string and need further processing.\n * If it cannot determine url, the corresponding value will be an empty string\n *\n * @todo string parameters are assumed to be URLs\n */\nexport function getResourceMIMEType(resource: unknown): string {\n // If resource is a response, it contains the information directly\n if (isResponse(resource)) {\n const response = resource as Response;\n const contentTypeHeader = response.headers.get('content-type') || '';\n const noQueryUrl = stripQueryString(response.url);\n return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);\n }\n\n // If the resource is a Blob or a File (subclass of Blob)\n if (isBlob(resource)) {\n const blob = resource as Blob;\n return blob.type || '';\n }\n\n if (typeof resource === 'string') {\n return parseMIMETypeFromURL(resource);\n }\n\n // Unknown\n return '';\n}\n\n/**\n * Returns (approximate) content length for a resource if it can be determined.\n * Returns -1 if content length cannot be determined.\n * @param resource\n\n * @note string parameters are NOT assumed to be URLs\n */\nexport function getResourceContentLength(resource: unknown): number {\n if (isResponse(resource)) {\n const response = resource as Response;\n return response.headers['content-length'] || -1;\n }\n if (isBlob(resource)) {\n const blob = resource as Blob;\n return blob.size;\n }\n if (typeof resource === 'string') {\n // TODO - handle data URL?\n return resource.length;\n }\n if (resource instanceof ArrayBuffer) {\n return resource.byteLength;\n }\n if (ArrayBuffer.isView(resource)) {\n return resource.byteLength;\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,EAAE;IACxB,MAAMC,QAAQ,GAAGD,QAAoB;IACrC,OAAOC,QAAQ,CAACM,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;EACjD;EACA,IAAIZ,MAAM,CAACK,QAAQ,CAAC,EAAE;IACpB,MAAMG,IAAI,GAAGH,QAAgB;IAC7B,OAAOG,IAAI,CAACS,IAAI;EAClB;EACA,IAAI,OAAOZ,QAAQ,KAAK,QAAQ,EAAE;IAEhC,OAAOA,QAAQ,CAACa,MAAM;EACxB;EACA,IAAIb,QAAQ,YAAYc,WAAW,EAAE;IACnC,OAAOd,QAAQ,CAACe,UAAU;EAC5B;EACA,IAAID,WAAW,CAACE,MAAM,CAAChB,QAAQ,CAAC,EAAE;IAChC,OAAOA,QAAQ,CAACe,UAAU;EAC5B;EACA,OAAO,CAAC,CAAC;AACX"}
@@ -1,5 +1,5 @@
1
1
  import { isResponse } from '../../javascript-utils/is-type';
2
- import { getResourceContentLength, getResourceUrlAndType } from './resource-utils';
2
+ import { getResourceContentLength, getResourceUrl, getResourceMIMEType } from './resource-utils';
3
3
  export async function makeResponse(resource) {
4
4
  if (isResponse(resource)) {
5
5
  return resource;
@@ -9,10 +9,8 @@ export async function makeResponse(resource) {
9
9
  if (contentLength >= 0) {
10
10
  headers['content-length'] = String(contentLength);
11
11
  }
12
- const {
13
- url,
14
- type
15
- } = getResourceUrlAndType(resource);
12
+ const url = getResourceUrl(resource);
13
+ const type = getResourceMIMEType(resource);
16
14
  if (type) {
17
15
  headers['content-type'] = type;
18
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"response-utils.js","names":["isResponse","getResourceContentLength","getResourceUrlAndType","makeResponse","resource","headers","contentLength","String","url","type","initialDataUrl","getInitialDataUrl","TextEncoder","encode","response","Response","Object","defineProperty","value","checkResponse","ok","message","getResponseError","Error","checkResponseSync","concat","status","statusText","length","slice","contentType","get","text","includes","error","INITIAL_DATA_LENGTH","Blob","blobSlice","Promise","resolve","reader","FileReader","onload","event","_event$target","target","result","readAsDataURL","ArrayBuffer","base64","arrayBufferToBase64","buffer","binary","bytes","Uint8Array","i","byteLength","fromCharCode","btoa"],"sources":["../../../../src/lib/utils/response-utils.ts"],"sourcesContent":["import {isResponse} from '../../javascript-utils/is-type';\nimport {getResourceContentLength, getResourceUrlAndType} from './resource-utils';\n\n/**\n * Returns a Response object\n * Adds content-length header when possible\n *\n * @param resource\n */\nexport async function makeResponse(resource: any): Promise<Response> {\n if (isResponse(resource)) {\n return resource;\n }\n\n // Add content-length header if possible\n const headers: {[header: string]: string} = {};\n\n const contentLength = getResourceContentLength(resource);\n if (contentLength >= 0) {\n headers['content-length'] = String(contentLength);\n }\n\n // `new Response(File)` does not preserve content-type and URL\n // so we add them here\n const {url, type} = getResourceUrlAndType(resource);\n if (type) {\n headers['content-type'] = type;\n }\n\n // Add a custom header with initial bytes if available\n const initialDataUrl = await getInitialDataUrl(resource);\n if (initialDataUrl) {\n headers['x-first-bytes'] = initialDataUrl;\n }\n\n // TODO - is this the best way of handling strings?\n // Maybe package as data URL instead?\n if (typeof resource === 'string') {\n // Convert to ArrayBuffer to avoid Response treating it as a URL\n resource = new TextEncoder().encode(resource);\n }\n\n // Attempt to create a Response from the resource, adding headers and setting url\n const response = new Response(resource, {headers});\n // We can't control `Response.url` via constructor, use a property override to record URL.\n Object.defineProperty(response, 'url', {value: url});\n return response;\n}\n\n/**\n * Checks response status (async) and throws a helpful error message if status is not OK.\n * @param response\n */\nexport async function checkResponse(response: Response): Promise<void> {\n if (!response.ok) {\n const message = await getResponseError(response);\n throw new Error(message);\n }\n}\n\n/**\n * Checks response status (sync) and throws a helpful error message if status is not OK.\n * @param response\n */\nexport function checkResponseSync(response: Response): void {\n if (!response.ok) {\n let message = `${response.status} ${response.statusText}`;\n message = message.length > 60 ? `${message.slice(0, 60)}...` : message;\n throw new Error(message);\n }\n}\n\n// HELPERS\n\nasync function getResponseError(response): Promise<string> {\n let message = `Failed to fetch resource ${response.url} (${response.status}): `;\n try {\n const contentType = response.headers.get('Content-Type');\n let text = response.statusText;\n if (contentType.includes('application/json')) {\n text += ` ${await response.text()}`;\n }\n message += text;\n message = message.length > 60 ? `${message.slice(0, 60)}...` : message;\n } catch (error) {\n // eslint forbids return in a finally statement, so we just catch here\n }\n return message;\n}\n\nasync function getInitialDataUrl(resource): Promise<string | null> {\n const INITIAL_DATA_LENGTH = 5;\n if (typeof resource === 'string') {\n return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;\n }\n if (resource instanceof Blob) {\n const blobSlice = resource.slice(0, 5);\n return await new Promise((resolve) => {\n const reader = new FileReader();\n reader.onload = (event) => resolve(event?.target?.result as string);\n reader.readAsDataURL(blobSlice);\n });\n }\n if (resource instanceof ArrayBuffer) {\n const slice = resource.slice(0, INITIAL_DATA_LENGTH);\n const base64 = arrayBufferToBase64(slice);\n return `data:base64,${base64}`;\n }\n return null;\n}\n\n// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string\nfunction arrayBufferToBase64(buffer) {\n let binary = '';\n const bytes = new Uint8Array(buffer);\n for (let i = 0; i < bytes.byteLength; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n"],"mappings":"AAAA,SAAQA,UAAU,QAAO,gCAAgC;AACzD,SAAQC,wBAAwB,EAAEC,qBAAqB,QAAO,kBAAkB;AAQhF,OAAO,eAAeC,YAAYA,CAACC,QAAa,EAAqB;EACnE,IAAIJ,UAAU,CAACI,QAAQ,CAAC,EAAE;IACxB,OAAOA,QAAQ;EACjB;EAGA,MAAMC,OAAmC,GAAG,CAAC,CAAC;EAE9C,MAAMC,aAAa,GAAGL,wBAAwB,CAACG,QAAQ,CAAC;EACxD,IAAIE,aAAa,IAAI,CAAC,EAAE;IACtBD,OAAO,CAAC,gBAAgB,CAAC,GAAGE,MAAM,CAACD,aAAa,CAAC;EACnD;EAIA,MAAM;IAACE,GAAG;IAAEC;EAAI,CAAC,GAAGP,qBAAqB,CAACE,QAAQ,CAAC;EACnD,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,CAAC,CAAC;EACJ;EACA,IAAIjC,QAAQ,YAAY4C,WAAW,EAAE;IACnC,MAAMnB,KAAK,GAAGzB,QAAQ,CAACyB,KAAK,CAAC,CAAC,EAAEM,mBAAmB,CAAC;IACpD,MAAMc,MAAM,GAAGC,mBAAmB,CAACrB,KAAK,CAAC;IACzC,sBAAAJ,MAAA,CAAsBwB,MAAM;EAC9B;EACA,OAAO,IAAI;AACb;AAGA,SAASC,mBAAmBA,CAACC,MAAM,EAAE;EACnC,IAAIC,MAAM,GAAG,EAAE;EACf,MAAMC,KAAK,GAAG,IAAIC,UAAU,CAACH,MAAM,CAAC;EACpC,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,KAAK,CAACG,UAAU,EAAED,CAAC,EAAE,EAAE;IACzCH,MAAM,IAAI7C,MAAM,CAACkD,YAAY,CAACJ,KAAK,CAACE,CAAC,CAAC,CAAC;EACzC;EACA,OAAOG,IAAI,CAACN,MAAM,CAAC;AACrB"}
1
+ {"version":3,"file":"response-utils.js","names":["isResponse","getResourceContentLength","getResourceUrl","getResourceMIMEType","makeResponse","resource","headers","contentLength","String","url","type","initialDataUrl","getInitialDataUrl","TextEncoder","encode","response","Response","Object","defineProperty","value","checkResponse","ok","message","getResponseError","Error","checkResponseSync","concat","status","statusText","length","slice","contentType","get","text","includes","error","INITIAL_DATA_LENGTH","Blob","blobSlice","Promise","resolve","reader","FileReader","onload","event","_event$target","target","result","readAsDataURL","ArrayBuffer","base64","arrayBufferToBase64","buffer","binary","bytes","Uint8Array","i","byteLength","fromCharCode","btoa"],"sources":["../../../../src/lib/utils/response-utils.ts"],"sourcesContent":["import {isResponse} from '../../javascript-utils/is-type';\nimport {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';\n\n/**\n * Returns a Response object\n * Adds content-length header when possible\n *\n * @param resource\n */\nexport async function makeResponse(resource: any): Promise<Response> {\n if (isResponse(resource)) {\n return resource;\n }\n\n // Add content-length header if possible\n const headers: {[header: string]: string} = {};\n\n const contentLength = getResourceContentLength(resource);\n if (contentLength >= 0) {\n headers['content-length'] = String(contentLength);\n }\n\n // `new Response(File)` does not preserve content-type and URL\n // so we add them here\n const url = getResourceUrl(resource);\n const type = getResourceMIMEType(resource);\n if (type) {\n headers['content-type'] = type;\n }\n\n // Add a custom header with initial bytes if available\n const initialDataUrl = await getInitialDataUrl(resource);\n if (initialDataUrl) {\n headers['x-first-bytes'] = initialDataUrl;\n }\n\n // TODO - is this the best way of handling strings?\n // Maybe package as data URL instead?\n if (typeof resource === 'string') {\n // Convert to ArrayBuffer to avoid Response treating it as a URL\n resource = new TextEncoder().encode(resource);\n }\n\n // Attempt to create a Response from the resource, adding headers and setting url\n const response = new Response(resource, {headers});\n // We can't control `Response.url` via constructor, use a property override to record URL.\n Object.defineProperty(response, 'url', {value: url});\n return response;\n}\n\n/**\n * Checks response status (async) and throws a helpful error message if status is not OK.\n * @param response\n */\nexport async function checkResponse(response: Response): Promise<void> {\n if (!response.ok) {\n const message = await getResponseError(response);\n throw new Error(message);\n }\n}\n\n/**\n * Checks response status (sync) and throws a helpful error message if status is not OK.\n * @param response\n */\nexport function checkResponseSync(response: Response): void {\n if (!response.ok) {\n let message = `${response.status} ${response.statusText}`;\n message = message.length > 60 ? `${message.slice(0, 60)}...` : message;\n throw new Error(message);\n }\n}\n\n// HELPERS\n\nasync function getResponseError(response): Promise<string> {\n let message = `Failed to fetch resource ${response.url} (${response.status}): `;\n try {\n const contentType = response.headers.get('Content-Type');\n let text = response.statusText;\n if (contentType.includes('application/json')) {\n text += ` ${await response.text()}`;\n }\n message += text;\n message = message.length > 60 ? `${message.slice(0, 60)}...` : message;\n } catch (error) {\n // eslint forbids return in a finally statement, so we just catch here\n }\n return message;\n}\n\nasync function getInitialDataUrl(resource): Promise<string | null> {\n const INITIAL_DATA_LENGTH = 5;\n if (typeof resource === 'string') {\n return `data:,${resource.slice(0, INITIAL_DATA_LENGTH)}`;\n }\n if (resource instanceof Blob) {\n const blobSlice = resource.slice(0, 5);\n return await new Promise((resolve) => {\n const reader = new FileReader();\n reader.onload = (event) => resolve(event?.target?.result as string);\n reader.readAsDataURL(blobSlice);\n });\n }\n if (resource instanceof ArrayBuffer) {\n const slice = resource.slice(0, INITIAL_DATA_LENGTH);\n const base64 = arrayBufferToBase64(slice);\n return `data:base64,${base64}`;\n }\n return null;\n}\n\n// https://stackoverflow.com/questions/9267899/arraybuffer-to-base64-encoded-string\nfunction arrayBufferToBase64(buffer) {\n let binary = '';\n const bytes = new Uint8Array(buffer);\n for (let i = 0; i < bytes.byteLength; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n}\n"],"mappings":"AAAA,SAAQA,UAAU,QAAO,gCAAgC;AACzD,SAAQC,wBAAwB,EAAEC,cAAc,EAAEC,mBAAmB,QAAO,kBAAkB;AAQ9F,OAAO,eAAeC,YAAYA,CAACC,QAAa,EAAqB;EACnE,IAAIL,UAAU,CAACK,QAAQ,CAAC,EAAE;IACxB,OAAOA,QAAQ;EACjB;EAGA,MAAMC,OAAmC,GAAG,CAAC,CAAC;EAE9C,MAAMC,aAAa,GAAGN,wBAAwB,CAACI,QAAQ,CAAC;EACxD,IAAIE,aAAa,IAAI,CAAC,EAAE;IACtBD,OAAO,CAAC,gBAAgB,CAAC,GAAGE,MAAM,CAACD,aAAa,CAAC;EACnD;EAIA,MAAME,GAAG,GAAGP,cAAc,CAACG,QAAQ,CAAC;EACpC,MAAMK,IAAI,GAAGP,mBAAmB,CAACE,QAAQ,CAAC;EAC1C,IAAIK,IAAI,EAAE;IACRJ,OAAO,CAAC,cAAc,CAAC,GAAGI,IAAI;EAChC;EAGA,MAAMC,cAAc,GAAG,MAAMC,iBAAiB,CAACP,QAAQ,CAAC;EACxD,IAAIM,cAAc,EAAE;IAClBL,OAAO,CAAC,eAAe,CAAC,GAAGK,cAAc;EAC3C;EAIA,IAAI,OAAON,QAAQ,KAAK,QAAQ,EAAE;IAEhCA,QAAQ,GAAG,IAAI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AACb;AAGA,SAASC,mBAAmBA,CAACC,MAAM,EAAE;EACnC,IAAIC,MAAM,GAAG,EAAE;EACf,MAAMC,KAAK,GAAG,IAAIC,UAAU,CAACH,MAAM,CAAC;EACpC,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,KAAK,CAACG,UAAU,EAAED,CAAC,EAAE,EAAE;IACzCH,MAAM,IAAI7C,MAAM,CAACkD,YAAY,CAACJ,KAAK,CAACE,CAAC,CAAC,CAAC;EACzC;EACA,OAAOG,IAAI,CAACN,MAAM,CAAC;AACrB"}
@@ -0,0 +1,9 @@
1
+ const QUERY_STRING_PATTERN = /\?.*/;
2
+ export function extractQueryString(url) {
3
+ const matches = url.match(QUERY_STRING_PATTERN);
4
+ return matches && matches[0];
5
+ }
6
+ export function stripQueryString(url) {
7
+ return url.replace(QUERY_STRING_PATTERN, '');
8
+ }
9
+ //# sourceMappingURL=url-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-utils.js","names":["QUERY_STRING_PATTERN","extractQueryString","url","matches","match","stripQueryString","replace"],"sources":["../../../../src/lib/utils/url-utils.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nconst QUERY_STRING_PATTERN = /\\?.*/;\n\nexport function extractQueryString(url): string {\n const matches = url.match(QUERY_STRING_PATTERN);\n return matches && matches[0];\n}\n\nexport function stripQueryString(url): string {\n return url.replace(QUERY_STRING_PATTERN, '');\n}\n"],"mappings":"AAEA,MAAMA,oBAAoB,GAAG,MAAM;AAEnC,OAAO,SAASC,kBAAkBA,CAACC,GAAG,EAAU;EAC9C,MAAMC,OAAO,GAAGD,GAAG,CAACE,KAAK,CAACJ,oBAAoB,CAAC;EAC/C,OAAOG,OAAO,IAAIA,OAAO,CAAC,CAAC,CAAC;AAC9B;AAEA,OAAO,SAASE,gBAAgBA,CAACH,GAAG,EAAU;EAC5C,OAAOA,GAAG,CAACI,OAAO,CAACN,oBAAoB,EAAE,EAAE,CAAC;AAC9C"}
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "3.4.0-alpha.3" !== 'undefined' ? "3.4.0-alpha.3" : 'latest';
1
+ const VERSION = typeof "3.4.0-alpha.5" !== 'undefined' ? "3.4.0-alpha.5" : 'latest';
2
2
  export const NullWorkerLoader = {
3
3
  name: 'Null loader',
4
4
  id: 'null',
@@ -1 +1 @@
1
- {"version":3,"file":"parse-in-batches.d.ts","sourceRoot":"","sources":["../../../src/lib/api/parse-in-batches.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,MAAM,EAEN,aAAa,EACb,aAAa,EACd,MAAM,0BAA0B,CAAC;AAYlC;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,EAC3C,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAqC7B"}
1
+ {"version":3,"file":"parse-in-batches.d.ts","sourceRoot":"","sources":["../../../src/lib/api/parse-in-batches.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EACjB,MAAM,EAEN,aAAa,EACb,aAAa,EACd,MAAM,0BAA0B,CAAC;AAYlC;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,EAC3C,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAoC7B"}
@@ -19,6 +19,7 @@ const parse_1 = require("./parse");
19
19
  */
20
20
  async function parseInBatches(data, loaders, options, context) {
21
21
  (0, loader_utils_1.assert)(!context || typeof context === 'object'); // parseInBatches no longer accepts final url
22
+ const loaderArray = Array.isArray(loaders) ? loaders : undefined;
22
23
  // Signature: parseInBatches(data, options, url) - Uses registered loaders
23
24
  if (!Array.isArray(loaders) && !(0, normalize_loader_1.isLoaderObject)(loaders)) {
24
25
  context = undefined; // context not supported in short signature
@@ -28,7 +29,7 @@ async function parseInBatches(data, loaders, options, context) {
28
29
  data = await data; // Resolve any promise
29
30
  options = options || {};
30
31
  // Extract a url for auto detection
31
- const { url } = (0, resource_utils_1.getResourceUrlAndType)(data);
32
+ const url = (0, resource_utils_1.getResourceUrl)(data);
32
33
  // Chooses a loader and normalizes it
33
34
  // Note - only uses URL and contentType for streams and iterator inputs
34
35
  const loader = await (0, select_loader_1.selectLoader)(data, loaders, options);
@@ -38,12 +39,8 @@ async function parseInBatches(data, loaders, options, context) {
38
39
  return null;
39
40
  }
40
41
  // Normalize options
41
- // @ts-ignore
42
- options = (0, option_utils_1.normalizeOptions)(options, loader, loaders, url);
43
- // @ts-ignore
44
- context = (0, loader_context_1.getLoaderContext)(
45
- // @ts-ignore
46
- { url, parseInBatches, parse: parse_1.parse, loaders: loaders }, options, context);
42
+ options = (0, option_utils_1.normalizeOptions)(options, loader, loaderArray, url);
43
+ context = (0, loader_context_1.getLoaderContext)({ url, parseInBatches, parse: parse_1.parse, loaders: loaderArray }, options, context || null);
47
44
  return await parseWithLoaderInBatches(loader, data, options, context);
48
45
  }
49
46
  exports.parseInBatches = parseInBatches;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-sync.d.ts","sourceRoot":"","sources":["../../../src/lib/api/parse-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EAEN,aAAa,EACb,aAAa,EACd,MAAM,0BAA0B,CAAC;AASlC;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,EAC3C,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,GAAG,CAmCL"}
1
+ {"version":3,"file":"parse-sync.d.ts","sourceRoot":"","sources":["../../../src/lib/api/parse-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EAEN,aAAa,EACb,aAAa,EACd,MAAM,0BAA0B,CAAC;AASlC;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,EAC3C,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,GAAG,CAuCL"}
@@ -37,11 +37,11 @@ function parseSync(data, loaders, options, context) {
37
37
  // Normalize options
38
38
  options = (0, option_utils_1.normalizeOptions)(options, loader, candidateLoaders);
39
39
  // Extract a url for auto detection
40
- const { url } = (0, resource_utils_1.getResourceUrlAndType)(data);
40
+ const url = (0, resource_utils_1.getResourceUrl)(data);
41
41
  const parse = () => {
42
- throw new Error('parseSync called parse');
42
+ throw new Error('parseSync called parse (which is async');
43
43
  };
44
- context = (0, loader_context_1.getLoaderContext)({ url, parseSync, parse, loaders: loaders }, options);
44
+ context = (0, loader_context_1.getLoaderContext)({ url, parseSync, parse, loaders: loaders }, options, context || null);
45
45
  return parseWithLoaderSync(loader, data, options, context);
46
46
  }
47
47
  exports.parseSync = parseSync;
@@ -29,7 +29,7 @@ async function parse(data, loaders, options, context) {
29
29
  data = await data; // Resolve any promise
30
30
  options = options || {};
31
31
  // Extract a url for auto detection
32
- const { url } = (0, resource_utils_1.getResourceUrlAndType)(data);
32
+ const url = (0, resource_utils_1.getResourceUrl)(data);
33
33
  // Chooses a loader (and normalizes it)
34
34
  // Also use any loaders in the context, new loaders take priority
35
35
  const typedLoaders = loaders;
@@ -43,7 +43,7 @@ async function parse(data, loaders, options, context) {
43
43
  // Normalize options
44
44
  options = (0, option_utils_1.normalizeOptions)(options, loader, candidateLoaders, url);
45
45
  // Get a context (if already present, will be unchanged)
46
- context = (0, loader_context_1.getLoaderContext)({ url, parse, loaders: candidateLoaders }, options, context);
46
+ context = (0, loader_context_1.getLoaderContext)({ url, parse, loaders: candidateLoaders }, options, context || null);
47
47
  return await parseWithLoader(loader, data, options, context);
48
48
  }
49
49
  exports.parse = parse;
@@ -1 +1 @@
1
- {"version":3,"file":"select-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAcnF;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,GAAG,IAAI,CAmCf"}
1
+ {"version":3,"file":"select-loader.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAenF;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,WAAW,GAAG,MAAM,EAC5C,OAAO,GAAE,MAAM,EAAE,GAAG,MAAW,EAC/B,OAAO,CAAC,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,aAAa,GACtB,MAAM,GAAG,IAAI,CAmCf"}
@@ -7,6 +7,7 @@ const log_1 = require("../utils/log");
7
7
  const resource_utils_1 = require("../utils/resource-utils");
8
8
  const register_loaders_1 = require("./register-loaders");
9
9
  const is_type_1 = require("../../javascript-utils/is-type");
10
+ const url_utils_1 = require("../utils/url-utils");
10
11
  const EXT_PATTERN = /\.([^.]+)$/;
11
12
  // TODO - Need a variant that peeks at streams for parseInBatches
12
13
  // TODO - Detect multiple matching loaders? Use heuristics to grade matches?
@@ -85,8 +86,9 @@ exports.selectLoaderSync = selectLoaderSync;
85
86
  /** Implements loaders selection logic */
86
87
  // eslint-disable-next-line complexity
87
88
  function selectLoaderInternal(data, loaders, options, context) {
88
- const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(data);
89
- const testUrl = url || context?.url;
89
+ const url = (0, resource_utils_1.getResourceUrl)(data);
90
+ const type = (0, resource_utils_1.getResourceMIMEType)(data);
91
+ const testUrl = (0, url_utils_1.stripQueryString)(url) || context?.url;
90
92
  let loader = null;
91
93
  let reason = '';
92
94
  // if options.mimeType is supplied, it takes precedence
@@ -124,7 +126,8 @@ function validHTTPResponse(data) {
124
126
  }
125
127
  /** Generate a helpful message to help explain why loader selection failed. */
126
128
  function getNoValidLoaderMessage(data) {
127
- const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(data);
129
+ const url = (0, resource_utils_1.getResourceUrl)(data);
130
+ const type = (0, resource_utils_1.getResourceMIMEType)(data);
128
131
  let message = 'No valid loader found (';
129
132
  message += url ? `${loader_utils_1.path.filename(url)}, ` : 'no url provided, ';
130
133
  message += `MIME type: ${type ? `"${type}"` : 'not provided'}, `;
@@ -8,6 +8,6 @@ import type { Loader, LoaderOptions, LoaderContext } from '@loaders.gl/loader-ut
8
8
  * @param options
9
9
  * @param previousContext
10
10
  */
11
- export declare function getLoaderContext(context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>, options?: LoaderOptions, previousContext?: LoaderContext | null): LoaderContext;
11
+ export declare function getLoaderContext(context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>, options: LoaderOptions, parentContext: LoaderContext | null): LoaderContext;
12
12
  export declare function getLoadersFromContext(loaders: Loader[] | Loader | undefined, context?: LoaderContext): any;
13
13
  //# sourceMappingURL=loader-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader-context.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/loader-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAGnF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,EAC7E,OAAO,CAAC,EAAE,aAAa,EACvB,eAAe,GAAE,aAAa,GAAG,IAAW,GAC3C,aAAa,CAkBf;AAGD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,EACtC,OAAO,CAAC,EAAE,aAAa,OAkBxB"}
1
+ {"version":3,"file":"loader-context.d.ts","sourceRoot":"","sources":["../../../src/lib/loader-utils/loader-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAKnF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,EAC7E,OAAO,EAAE,aAAa,EACtB,aAAa,EAAE,aAAa,GAAG,IAAI,GAClC,aAAa,CA2Bf;AAGD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,EACtC,OAAO,CAAC,EAAE,aAAa,OAkBxB"}
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLoadersFromContext = exports.getLoaderContext = void 0;
4
4
  const get_fetch_function_1 = require("./get-fetch-function");
5
+ const url_utils_1 = require("../utils/url-utils");
6
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
5
7
  /**
6
8
  * "sub" loaders invoked by other loaders get a "context" injected on `this`
7
9
  * The context will inject core methods like `parse` and contain information
@@ -11,21 +13,29 @@ const get_fetch_function_1 = require("./get-fetch-function");
11
13
  * @param options
12
14
  * @param previousContext
13
15
  */
14
- function getLoaderContext(context, options, previousContext = null) {
16
+ function getLoaderContext(context, options, parentContext) {
15
17
  // For recursive calls, we already have a context
16
18
  // TODO - add any additional loaders to context?
17
- if (previousContext) {
18
- return previousContext;
19
+ if (parentContext) {
20
+ return parentContext;
19
21
  }
20
- const resolvedContext = {
22
+ const newContext = {
21
23
  fetch: (0, get_fetch_function_1.getFetchFunction)(options, context),
22
24
  ...context
23
25
  };
26
+ // Parse URLs so that subloaders can easily generate correct strings
27
+ if (newContext.url) {
28
+ const baseUrl = (0, url_utils_1.stripQueryString)(newContext.url);
29
+ newContext.baseUrl = baseUrl;
30
+ newContext.queryString = (0, url_utils_1.extractQueryString)(newContext.url);
31
+ newContext.filename = loader_utils_1.path.filename(baseUrl);
32
+ newContext.baseUrl = loader_utils_1.path.dirname(baseUrl);
33
+ }
24
34
  // Recursive loading does not use single loader
25
- if (!Array.isArray(resolvedContext.loaders)) {
26
- resolvedContext.loaders = null;
35
+ if (!Array.isArray(newContext.loaders)) {
36
+ newContext.loaders = null;
27
37
  }
28
- return resolvedContext;
38
+ return newContext;
29
39
  }
30
40
  exports.getLoaderContext = getLoaderContext;
31
41
  // eslint-disable-next-line complexity
@@ -1,15 +1,24 @@
1
1
  /**
2
- * Returns an object with `url` and (MIME) `type` fields
3
- * If it cannot determine url or type, the corresponding value will be an empty string
2
+ * A loadable resource. Includes:
3
+ * `Response`, `Blob` (`File` is a subclass), string URLs and data URLs
4
+ */
5
+ export type Resource = Response | Blob | string;
6
+ /**
7
+ * Returns the URL associated with this resource.
8
+ * The returned value may include a query string and need further processing.
9
+ * If it cannot determine url, the corresponding value will be an empty string
4
10
  *
5
- * @param resource Any type, but only Responses, string URLs and data URLs are processed
11
+ * @todo string parameters are assumed to be URLs
12
+ */
13
+ export declare function getResourceUrl(resource: unknown): string;
14
+ /**
15
+ * Returns the URL associated with this resource.
16
+ * The returned value may include a query string and need further processing.
17
+ * If it cannot determine url, the corresponding value will be an empty string
6
18
  *
7
19
  * @todo string parameters are assumed to be URLs
8
20
  */
9
- export declare function getResourceUrlAndType(resource: any): {
10
- url: string;
11
- type: string;
12
- };
21
+ export declare function getResourceMIMEType(resource: unknown): string;
13
22
  /**
14
23
  * Returns (approximate) content length for a resource if it can be determined.
15
24
  * Returns -1 if content length cannot be determined.
@@ -17,5 +26,5 @@ export declare function getResourceUrlAndType(resource: any): {
17
26
 
18
27
  * @note string parameters are NOT assumed to be URLs
19
28
  */
20
- export declare function getResourceContentLength(resource: any): number;
29
+ export declare function getResourceContentLength(resource: unknown): number;
21
30
  //# sourceMappingURL=resource-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/resource-utils.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,GAAG,GAAG;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAmChF;AAED;;;;;;IAMI;AACJ,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,MAAM,CAkB9D"}
1
+ {"version":3,"file":"resource-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/resource-utils.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAC;AAEhD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAqBxD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAqB7D;AAED;;;;;;IAMI;AACJ,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAoBlE"}
@@ -1,51 +1,64 @@
1
1
  "use strict";
2
+ // loaders.gl, MIT license
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getResourceContentLength = exports.getResourceUrlAndType = void 0;
4
+ exports.getResourceContentLength = exports.getResourceMIMEType = exports.getResourceUrl = void 0;
4
5
  const is_type_1 = require("../../javascript-utils/is-type");
5
6
  const mime_type_utils_1 = require("./mime-type-utils");
6
- const QUERY_STRING_PATTERN = /\?.*/;
7
+ const url_utils_1 = require("./url-utils");
7
8
  /**
8
- * Returns an object with `url` and (MIME) `type` fields
9
- * If it cannot determine url or type, the corresponding value will be an empty string
9
+ * Returns the URL associated with this resource.
10
+ * The returned value may include a query string and need further processing.
11
+ * If it cannot determine url, the corresponding value will be an empty string
10
12
  *
11
- * @param resource Any type, but only Responses, string URLs and data URLs are processed
13
+ * @todo string parameters are assumed to be URLs
14
+ */
15
+ function getResourceUrl(resource) {
16
+ // If resource is a `Response`, it contains the information directly as a field
17
+ if ((0, is_type_1.isResponse)(resource)) {
18
+ const response = resource;
19
+ return response.url;
20
+ }
21
+ // If the resource is a Blob or a File (subclass of Blob)
22
+ if ((0, is_type_1.isBlob)(resource)) {
23
+ const blob = resource;
24
+ // File objects have a "name" property. Blob objects don't have any
25
+ // url (name) information
26
+ return blob.name || '';
27
+ }
28
+ if (typeof resource === 'string') {
29
+ return resource;
30
+ }
31
+ // Unknown
32
+ return '';
33
+ }
34
+ exports.getResourceUrl = getResourceUrl;
35
+ /**
36
+ * Returns the URL associated with this resource.
37
+ * The returned value may include a query string and need further processing.
38
+ * If it cannot determine url, the corresponding value will be an empty string
12
39
  *
13
40
  * @todo string parameters are assumed to be URLs
14
41
  */
15
- function getResourceUrlAndType(resource) {
42
+ function getResourceMIMEType(resource) {
16
43
  // If resource is a response, it contains the information directly
17
44
  if ((0, is_type_1.isResponse)(resource)) {
18
- const url = stripQueryString(resource.url || '');
19
- const contentTypeHeader = resource.headers.get('content-type') || '';
20
- return {
21
- url,
22
- type: (0, mime_type_utils_1.parseMIMEType)(contentTypeHeader) || (0, mime_type_utils_1.parseMIMETypeFromURL)(url)
23
- };
45
+ const response = resource;
46
+ const contentTypeHeader = response.headers.get('content-type') || '';
47
+ const noQueryUrl = (0, url_utils_1.stripQueryString)(response.url);
48
+ return (0, mime_type_utils_1.parseMIMEType)(contentTypeHeader) || (0, mime_type_utils_1.parseMIMETypeFromURL)(noQueryUrl);
24
49
  }
25
50
  // If the resource is a Blob or a File (subclass of Blob)
26
51
  if ((0, is_type_1.isBlob)(resource)) {
27
- return {
28
- // File objects have a "name" property. Blob objects don't have any
29
- // url (name) information
30
- url: stripQueryString(resource.name || ''),
31
- type: resource.type || ''
32
- };
52
+ const blob = resource;
53
+ return blob.type || '';
33
54
  }
34
55
  if (typeof resource === 'string') {
35
- return {
36
- // TODO this could mess up data URL but it doesn't matter as it is just used for inference
37
- url: stripQueryString(resource),
38
- // If a data url
39
- type: (0, mime_type_utils_1.parseMIMETypeFromURL)(resource)
40
- };
56
+ return (0, mime_type_utils_1.parseMIMETypeFromURL)(resource);
41
57
  }
42
58
  // Unknown
43
- return {
44
- url: '',
45
- type: ''
46
- };
59
+ return '';
47
60
  }
48
- exports.getResourceUrlAndType = getResourceUrlAndType;
61
+ exports.getResourceMIMEType = getResourceMIMEType;
49
62
  /**
50
63
  * Returns (approximate) content length for a resource if it can be determined.
51
64
  * Returns -1 if content length cannot be determined.
@@ -55,10 +68,12 @@ exports.getResourceUrlAndType = getResourceUrlAndType;
55
68
  */
56
69
  function getResourceContentLength(resource) {
57
70
  if ((0, is_type_1.isResponse)(resource)) {
58
- return resource.headers['content-length'] || -1;
71
+ const response = resource;
72
+ return response.headers['content-length'] || -1;
59
73
  }
60
74
  if ((0, is_type_1.isBlob)(resource)) {
61
- return resource.size;
75
+ const blob = resource;
76
+ return blob.size;
62
77
  }
63
78
  if (typeof resource === 'string') {
64
79
  // TODO - handle data URL?
@@ -73,6 +88,3 @@ function getResourceContentLength(resource) {
73
88
  return -1;
74
89
  }
75
90
  exports.getResourceContentLength = getResourceContentLength;
76
- function stripQueryString(url) {
77
- return url.replace(QUERY_STRING_PATTERN, '');
78
- }
@@ -1 +1 @@
1
- {"version":3,"file":"response-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/response-utils.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsCnE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAM1D"}
1
+ {"version":3,"file":"response-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/response-utils.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuCnE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAM1D"}
@@ -21,7 +21,8 @@ async function makeResponse(resource) {
21
21
  }
22
22
  // `new Response(File)` does not preserve content-type and URL
23
23
  // so we add them here
24
- const { url, type } = (0, resource_utils_1.getResourceUrlAndType)(resource);
24
+ const url = (0, resource_utils_1.getResourceUrl)(resource);
25
+ const type = (0, resource_utils_1.getResourceMIMEType)(resource);
25
26
  if (type) {
26
27
  headers['content-type'] = type;
27
28
  }
@@ -0,0 +1,3 @@
1
+ export declare function extractQueryString(url: any): string;
2
+ export declare function stripQueryString(url: any): string;
3
+ //# sourceMappingURL=url-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/url-utils.ts"],"names":[],"mappings":"AAIA,wBAAgB,kBAAkB,CAAC,GAAG,KAAA,GAAG,MAAM,CAG9C;AAED,wBAAgB,gBAAgB,CAAC,GAAG,KAAA,GAAG,MAAM,CAE5C"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.stripQueryString = exports.extractQueryString = void 0;
5
+ const QUERY_STRING_PATTERN = /\?.*/;
6
+ function extractQueryString(url) {
7
+ const matches = url.match(QUERY_STRING_PATTERN);
8
+ return matches && matches[0];
9
+ }
10
+ exports.extractQueryString = extractQueryString;
11
+ function stripQueryString(url) {
12
+ return url.replace(QUERY_STRING_PATTERN, '');
13
+ }
14
+ exports.stripQueryString = stripQueryString;
@@ -184,7 +184,7 @@
184
184
  }
185
185
 
186
186
  // src/null-loader.ts
187
- var VERSION = true ? "3.4.0-alpha.3" : "latest";
187
+ var VERSION = true ? "3.4.0-alpha.5" : "latest";
188
188
  function parseSync(arrayBuffer, options, context) {
189
189
  if (!options.null.echoParameters)
190
190
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/core",
3
- "version": "3.4.0-alpha.3",
3
+ "version": "3.4.0-alpha.5",
4
4
  "description": "The core API for working with loaders.gl loaders and writers",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -42,9 +42,9 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@babel/runtime": "^7.3.1",
45
- "@loaders.gl/loader-utils": "3.4.0-alpha.3",
46
- "@loaders.gl/worker-utils": "3.4.0-alpha.3",
45
+ "@loaders.gl/loader-utils": "3.4.0-alpha.5",
46
+ "@loaders.gl/worker-utils": "3.4.0-alpha.5",
47
47
  "@probe.gl/log": "^4.0.1"
48
48
  },
49
- "gitHead": "a954528dd1d78a1f128d8f6b07e4baeb7a296924"
49
+ "gitHead": "686929f85b3420c15df051eab769942b260dd242"
50
50
  }