@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.
- package/dist/dist.dev.js +1946 -1868
- package/dist/dist.min.js +3 -3
- package/dist/index.cjs +115 -71
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/lib/api/parse-in-batches.js +1 -0
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +3 -2
- package/dist/lib/fetch/fetch-error-message.d.ts.map +1 -1
- package/dist/lib/fetch/fetch-error-message.js +2 -0
- package/dist/lib/fetch/fetch-error.d.ts +14 -0
- package/dist/lib/fetch/fetch-error.d.ts.map +1 -0
- package/dist/lib/fetch/fetch-error.js +17 -0
- package/dist/lib/fetch/fetch-file.d.ts.map +1 -1
- package/dist/lib/fetch/fetch-file.js +1 -0
- package/dist/lib/filesystems/browser-filesystem.js +4 -3
- package/dist/lib/init.js +1 -1
- package/dist/lib/loader-utils/loggers.js +1 -0
- package/dist/lib/loader-utils/option-utils.d.ts +1 -1
- package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
- package/dist/lib/loader-utils/option-utils.js +3 -0
- package/dist/lib/utils/mime-type-utils.d.ts +8 -0
- package/dist/lib/utils/mime-type-utils.d.ts.map +1 -1
- package/dist/lib/utils/mime-type-utils.js +13 -0
- package/dist/lib/utils/response-utils.d.ts.map +1 -1
- package/dist/lib/utils/response-utils.js +16 -10
- package/dist/lib/utils/url-utils.d.ts +1 -0
- package/dist/lib/utils/url-utils.d.ts.map +1 -1
- package/dist/lib/utils/url-utils.js +8 -0
- package/dist/null-loader.d.ts +40 -3
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +5 -1
- package/dist/null-worker-node.js +6 -2
- package/dist/null-worker.js +6 -2
- package/package.json +9 -8
- package/src/index.ts +1 -0
- package/src/lib/api/parse-in-batches.ts +6 -5
- package/src/lib/api/select-loader.ts +3 -2
- package/src/lib/fetch/fetch-error-message.ts +2 -0
- package/src/lib/fetch/fetch-error.ts +18 -0
- package/src/lib/fetch/fetch-file.ts +1 -0
- package/src/lib/loader-utils/option-utils.ts +3 -1
- package/src/lib/utils/mime-type-utils.ts +14 -0
- package/src/lib/utils/resource-utils.ts +1 -1
- package/src/lib/utils/response-utils.ts +19 -11
- package/src/lib/utils/url-utils.ts +9 -0
- 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
|
|
62
|
-
throw
|
|
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<
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
}
|
package/src/null-loader.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|