@loaders.gl/core 4.2.0-alpha.5 → 4.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/dist.dev.js +1946 -1868
  2. package/dist/dist.min.js +3 -3
  3. package/dist/index.cjs +115 -71
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/lib/api/parse-in-batches.js +1 -0
  9. package/dist/lib/api/select-loader.d.ts.map +1 -1
  10. package/dist/lib/api/select-loader.js +3 -2
  11. package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -1
  12. package/dist/lib/fetch/fetch-error-message.js +2 -0
  13. package/dist/lib/fetch/fetch-error.d.ts +14 -0
  14. package/dist/lib/fetch/fetch-error.d.ts.map +1 -0
  15. package/dist/lib/fetch/fetch-error.js +17 -0
  16. package/dist/lib/fetch/fetch-file.d.ts.map +1 -1
  17. package/dist/lib/fetch/fetch-file.js +1 -0
  18. package/dist/lib/filesystems/browser-filesystem.js +4 -3
  19. package/dist/lib/init.js +1 -1
  20. package/dist/lib/loader-utils/loggers.js +1 -0
  21. package/dist/lib/loader-utils/option-utils.d.ts +1 -1
  22. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  23. package/dist/lib/loader-utils/option-utils.js +3 -0
  24. package/dist/lib/utils/mime-type-utils.d.ts +8 -0
  25. package/dist/lib/utils/mime-type-utils.d.ts.map +1 -1
  26. package/dist/lib/utils/mime-type-utils.js +13 -0
  27. package/dist/lib/utils/response-utils.d.ts.map +1 -1
  28. package/dist/lib/utils/response-utils.js +16 -10
  29. package/dist/lib/utils/url-utils.d.ts +1 -0
  30. package/dist/lib/utils/url-utils.d.ts.map +1 -1
  31. package/dist/lib/utils/url-utils.js +8 -0
  32. package/dist/null-loader.d.ts +40 -3
  33. package/dist/null-loader.d.ts.map +1 -1
  34. package/dist/null-loader.js +5 -1
  35. package/dist/null-worker-node.js +6 -2
  36. package/dist/null-worker.js +6 -2
  37. package/package.json +9 -8
  38. package/src/index.ts +1 -0
  39. package/src/lib/api/parse-in-batches.ts +6 -5
  40. package/src/lib/api/select-loader.ts +3 -2
  41. package/src/lib/fetch/fetch-error-message.ts +2 -0
  42. package/src/lib/fetch/fetch-error.ts +18 -0
  43. package/src/lib/fetch/fetch-file.ts +1 -0
  44. package/src/lib/loader-utils/option-utils.ts +3 -1
  45. package/src/lib/utils/mime-type-utils.ts +14 -0
  46. package/src/lib/utils/resource-utils.ts +1 -1
  47. package/src/lib/utils/response-utils.ts +19 -11
  48. package/src/lib/utils/url-utils.ts +9 -0
  49. package/src/null-loader.ts +9 -4
@@ -8,6 +8,20 @@
8
8
  const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
9
9
  const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
10
10
 
11
+ /**
12
+ * Compare two MIME types, case insensitively etc.
13
+ * @param mimeType1
14
+ * @param mimeType2
15
+ * @returns true if the MIME types are equivalent
16
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#structure_of_a_mime_type
17
+ */
18
+ export function compareMIMETypes(mimeType1: string, mimeType2: string): boolean {
19
+ if (mimeType1.toLowerCase() === mimeType2.toLowerCase()) {
20
+ return true;
21
+ }
22
+ return false;
23
+ }
24
+
11
25
  /**
12
26
  * Remove extra data like `charset` from MIME types
13
27
  * @param mimeString
@@ -31,7 +31,7 @@ export function getResourceUrl(resource: unknown): string {
31
31
  const blob = resource as Blob;
32
32
  // File objects have a "name" property. Blob objects don't have any
33
33
  // url (name) information
34
- return blob.name || '';
34
+ return (blob as any).name || '';
35
35
  }
36
36
 
37
37
  if (typeof resource === 'string') {
@@ -3,7 +3,9 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {isResponse} from '../../javascript-utils/is-type';
6
+ import {FetchError} from '../fetch/fetch-error';
6
7
  import {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';
8
+ import {shortenUrlForDisplay} from './url-utils';
7
9
 
8
10
  /**
9
11
  * Returns a Response object
@@ -58,8 +60,8 @@ export async function makeResponse(resource: unknown): Promise<Response> {
58
60
  */
59
61
  export async function checkResponse(response: Response): Promise<void> {
60
62
  if (!response.ok) {
61
- const message = await getResponseError(response);
62
- throw new Error(message);
63
+ const error = await getResponseError(response);
64
+ throw error;
63
65
  }
64
66
  }
65
67
 
@@ -77,20 +79,26 @@ export function checkResponseSync(response: Response): void {
77
79
 
78
80
  // HELPERS
79
81
 
80
- async function getResponseError(response: Response): Promise<string> {
81
- let message = `Failed to fetch resource ${response.url} (${response.status}): `;
82
+ async function getResponseError(response: Response): Promise<Error> {
83
+ const shortUrl = shortenUrlForDisplay(response.url);
84
+ let message = `Failed to fetch resource (${response.status}) ${response.statusText}: ${shortUrl}`;
85
+ message = message.length > 100 ? `${message.slice(0, 100)}...` : message;
86
+
87
+ const info = {
88
+ reason: response.statusText,
89
+ url: response.url,
90
+ response
91
+ };
92
+
82
93
  try {
83
94
  const contentType = response.headers.get('Content-Type');
84
- let text = response.statusText;
85
- if (contentType?.includes('application/json')) {
86
- text += ` ${await response.text()}`;
87
- }
88
- message += text;
89
- message = message.length > 60 ? `${message.slice(0, 60)}...` : message;
95
+ info.reason = contentType?.includes('application/json')
96
+ ? await response.json()
97
+ : response.text();
90
98
  } catch (error) {
91
99
  // eslint forbids return in a finally statement, so we just catch here
92
100
  }
93
- return message;
101
+ return new FetchError(message, info);
94
102
  }
95
103
 
96
104
  async function getInitialDataUrl(
@@ -12,3 +12,12 @@ export function extractQueryString(url): string {
12
12
  export function stripQueryString(url): string {
13
13
  return url.replace(QUERY_STRING_PATTERN, '');
14
14
  }
15
+
16
+ export function shortenUrlForDisplay(url: string): string {
17
+ if (url.length < 50) {
18
+ return url;
19
+ }
20
+ const urlEnd = url.slice(url.length - 15);
21
+ const urlStart = url.substr(0, 32);
22
+ return `${urlStart}...${urlEnd}`;
23
+ }
@@ -16,7 +16,9 @@ export type NullLoaderOptions = LoaderOptions & {
16
16
  /**
17
17
  * Loads any data and returns null (or optionally passes through data unparsed)
18
18
  */
19
- export const NullWorkerLoader: Loader<null, never, NullLoaderOptions> = {
19
+ export const NullWorkerLoader = {
20
+ dataType: null,
21
+ batchType: null as never,
20
22
  name: 'Null loader',
21
23
  id: 'null',
22
24
  module: 'core',
@@ -28,12 +30,15 @@ export const NullWorkerLoader: Loader<null, never, NullLoaderOptions> = {
28
30
  options: {
29
31
  null: {}
30
32
  }
31
- };
33
+ } as const satisfies Loader<null, never, NullLoaderOptions>;
32
34
 
33
35
  /**
34
36
  * Loads any data and returns null (or optionally passes through data unparsed)
35
37
  */
36
- export const NullLoader: LoaderWithParser<null, null, NullLoaderOptions> = {
38
+ export const NullLoader = {
39
+ dataType: null,
40
+ batchType: null,
41
+
37
42
  name: 'Null loader',
38
43
  id: 'null',
39
44
  module: 'core',
@@ -52,7 +57,7 @@ export const NullLoader: LoaderWithParser<null, null, NullLoaderOptions> = {
52
57
  options: {
53
58
  null: {}
54
59
  }
55
- };
60
+ } as const satisfies LoaderWithParser<null, null, NullLoaderOptions>;
56
61
 
57
62
  /**
58
63
  * Returns arguments passed to the parse API in a format that can be transferred to a