@loaders.gl/core 3.4.0-alpha.4 → 3.4.0
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.min.js +76 -45
- package/dist/es5/lib/api/parse-in-batches.js +15 -14
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +3 -4
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +3 -3
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +6 -7
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/loader-context.js +16 -8
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/utils/resource-utils.js +31 -27
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +6 -5
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +16 -0
- package/dist/es5/lib/utils/url-utils.js.map +1 -0
- package/dist/es5/null-loader.js +1 -1
- package/dist/es5/null-loader.js.map +1 -1
- package/dist/esm/lib/api/parse-in-batches.js +6 -7
- package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
- package/dist/esm/lib/api/parse-sync.js +4 -6
- package/dist/esm/lib/api/parse-sync.js.map +1 -1
- package/dist/esm/lib/api/parse.js +3 -5
- package/dist/esm/lib/api/parse.js.map +1 -1
- package/dist/esm/lib/api/select-loader.js +7 -10
- package/dist/esm/lib/api/select-loader.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/lib/init.js.map +1 -1
- package/dist/esm/lib/loader-utils/loader-context.js +16 -8
- package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/esm/lib/utils/resource-utils.js +29 -26
- package/dist/esm/lib/utils/resource-utils.js.map +1 -1
- package/dist/esm/lib/utils/response-utils.js +3 -5
- package/dist/esm/lib/utils/response-utils.js.map +1 -1
- package/dist/esm/lib/utils/url-utils.js +9 -0
- package/dist/esm/lib/utils/url-utils.js.map +1 -0
- package/dist/esm/null-loader.js +1 -1
- package/dist/esm/null-loader.js.map +1 -1
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +4 -7
- package/dist/lib/api/parse-sync.d.ts.map +1 -1
- package/dist/lib/api/parse-sync.js +3 -3
- package/dist/lib/api/parse.js +2 -2
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +6 -3
- package/dist/lib/loader-utils/loader-context.d.ts +1 -1
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
- package/dist/lib/loader-utils/loader-context.js +17 -7
- package/dist/lib/utils/resource-utils.d.ts +17 -8
- package/dist/lib/utils/resource-utils.d.ts.map +1 -1
- package/dist/lib/utils/resource-utils.js +46 -34
- package/dist/lib/utils/response-utils.d.ts.map +1 -1
- package/dist/lib/utils/response-utils.js +2 -1
- package/dist/lib/utils/url-utils.d.ts +3 -0
- package/dist/lib/utils/url-utils.d.ts.map +1 -0
- package/dist/lib/utils/url-utils.js +14 -0
- package/dist/null-worker.js +1 -1
- package/package.json +4 -4
- package/src/lib/api/parse-in-batches.ts +8 -9
- package/src/lib/api/parse-sync.ts +8 -4
- package/src/lib/api/parse.ts +3 -3
- package/src/lib/api/select-loader.ts +7 -4
- package/src/lib/loader-utils/loader-context.ts +19 -8
- package/src/lib/utils/resource-utils.ts +54 -34
- package/src/lib/utils/response-utils.ts +3 -2
- package/src/lib/utils/url-utils.ts +12 -0
|
@@ -1,51 +1,73 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import {isResponse, isBlob} from '../../javascript-utils/is-type';
|
|
2
4
|
import {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';
|
|
5
|
+
import {stripQueryString} from './url-utils';
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* A loadable resource. Includes:
|
|
9
|
+
* `Response`, `Blob` (`File` is a subclass), string URLs and data URLs
|
|
10
|
+
*/
|
|
11
|
+
export type Resource = Response | Blob | string;
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
|
-
* Returns
|
|
8
|
-
*
|
|
14
|
+
* Returns the URL associated with this resource.
|
|
15
|
+
* The returned value may include a query string and need further processing.
|
|
16
|
+
* If it cannot determine url, the corresponding value will be an empty string
|
|
9
17
|
*
|
|
10
|
-
* @
|
|
18
|
+
* @todo string parameters are assumed to be URLs
|
|
19
|
+
*/
|
|
20
|
+
export function getResourceUrl(resource: unknown): string {
|
|
21
|
+
// If resource is a `Response`, it contains the information directly as a field
|
|
22
|
+
if (isResponse(resource)) {
|
|
23
|
+
const response = resource as Response;
|
|
24
|
+
return response.url;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// If the resource is a Blob or a File (subclass of Blob)
|
|
28
|
+
if (isBlob(resource)) {
|
|
29
|
+
const blob = resource as Blob;
|
|
30
|
+
// File objects have a "name" property. Blob objects don't have any
|
|
31
|
+
// url (name) information
|
|
32
|
+
return blob.name || '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof resource === 'string') {
|
|
36
|
+
return resource;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Unknown
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns the URL associated with this resource.
|
|
45
|
+
* The returned value may include a query string and need further processing.
|
|
46
|
+
* If it cannot determine url, the corresponding value will be an empty string
|
|
11
47
|
*
|
|
12
48
|
* @todo string parameters are assumed to be URLs
|
|
13
49
|
*/
|
|
14
|
-
export function
|
|
50
|
+
export function getResourceMIMEType(resource: unknown): string {
|
|
15
51
|
// If resource is a response, it contains the information directly
|
|
16
52
|
if (isResponse(resource)) {
|
|
17
|
-
const
|
|
18
|
-
const contentTypeHeader =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)
|
|
22
|
-
};
|
|
53
|
+
const response = resource as Response;
|
|
54
|
+
const contentTypeHeader = response.headers.get('content-type') || '';
|
|
55
|
+
const noQueryUrl = stripQueryString(response.url);
|
|
56
|
+
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
23
57
|
}
|
|
24
58
|
|
|
25
59
|
// If the resource is a Blob or a File (subclass of Blob)
|
|
26
60
|
if (isBlob(resource)) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// url (name) information
|
|
30
|
-
url: stripQueryString(resource.name || ''),
|
|
31
|
-
type: resource.type || ''
|
|
32
|
-
};
|
|
61
|
+
const blob = resource as Blob;
|
|
62
|
+
return blob.type || '';
|
|
33
63
|
}
|
|
34
64
|
|
|
35
65
|
if (typeof resource === 'string') {
|
|
36
|
-
return
|
|
37
|
-
// TODO this could mess up data URL but it doesn't matter as it is just used for inference
|
|
38
|
-
url: stripQueryString(resource),
|
|
39
|
-
// If a data url
|
|
40
|
-
type: parseMIMETypeFromURL(resource)
|
|
41
|
-
};
|
|
66
|
+
return parseMIMETypeFromURL(resource);
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
// Unknown
|
|
45
|
-
return
|
|
46
|
-
url: '',
|
|
47
|
-
type: ''
|
|
48
|
-
};
|
|
70
|
+
return '';
|
|
49
71
|
}
|
|
50
72
|
|
|
51
73
|
/**
|
|
@@ -55,12 +77,14 @@ export function getResourceUrlAndType(resource: any): {url: string; type: string
|
|
|
55
77
|
|
|
56
78
|
* @note string parameters are NOT assumed to be URLs
|
|
57
79
|
*/
|
|
58
|
-
export function getResourceContentLength(resource:
|
|
80
|
+
export function getResourceContentLength(resource: unknown): number {
|
|
59
81
|
if (isResponse(resource)) {
|
|
60
|
-
|
|
82
|
+
const response = resource as Response;
|
|
83
|
+
return response.headers['content-length'] || -1;
|
|
61
84
|
}
|
|
62
85
|
if (isBlob(resource)) {
|
|
63
|
-
|
|
86
|
+
const blob = resource as Blob;
|
|
87
|
+
return blob.size;
|
|
64
88
|
}
|
|
65
89
|
if (typeof resource === 'string') {
|
|
66
90
|
// TODO - handle data URL?
|
|
@@ -74,7 +98,3 @@ export function getResourceContentLength(resource: any): number {
|
|
|
74
98
|
}
|
|
75
99
|
return -1;
|
|
76
100
|
}
|
|
77
|
-
|
|
78
|
-
function stripQueryString(url) {
|
|
79
|
-
return url.replace(QUERY_STRING_PATTERN, '');
|
|
80
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {isResponse} from '../../javascript-utils/is-type';
|
|
2
|
-
import {getResourceContentLength,
|
|
2
|
+
import {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns a Response object
|
|
@@ -22,7 +22,8 @@ export async function makeResponse(resource: any): Promise<Response> {
|
|
|
22
22
|
|
|
23
23
|
// `new Response(File)` does not preserve content-type and URL
|
|
24
24
|
// so we add them here
|
|
25
|
-
const
|
|
25
|
+
const url = getResourceUrl(resource);
|
|
26
|
+
const type = getResourceMIMEType(resource);
|
|
26
27
|
if (type) {
|
|
27
28
|
headers['content-type'] = type;
|
|
28
29
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
const QUERY_STRING_PATTERN = /\?.*/;
|
|
4
|
+
|
|
5
|
+
export function extractQueryString(url): string {
|
|
6
|
+
const matches = url.match(QUERY_STRING_PATTERN);
|
|
7
|
+
return matches && matches[0];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function stripQueryString(url): string {
|
|
11
|
+
return url.replace(QUERY_STRING_PATTERN, '');
|
|
12
|
+
}
|