@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.
Files changed (69) hide show
  1. package/dist/dist.min.js +76 -45
  2. package/dist/es5/lib/api/parse-in-batches.js +15 -14
  3. package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
  4. package/dist/es5/lib/api/parse-sync.js +3 -4
  5. package/dist/es5/lib/api/parse-sync.js.map +1 -1
  6. package/dist/es5/lib/api/parse.js +3 -3
  7. package/dist/es5/lib/api/parse.js.map +1 -1
  8. package/dist/es5/lib/api/select-loader.js +6 -7
  9. package/dist/es5/lib/api/select-loader.js.map +1 -1
  10. package/dist/es5/lib/init.js +1 -1
  11. package/dist/es5/lib/init.js.map +1 -1
  12. package/dist/es5/lib/loader-utils/loader-context.js +16 -8
  13. package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
  14. package/dist/es5/lib/utils/resource-utils.js +31 -27
  15. package/dist/es5/lib/utils/resource-utils.js.map +1 -1
  16. package/dist/es5/lib/utils/response-utils.js +6 -5
  17. package/dist/es5/lib/utils/response-utils.js.map +1 -1
  18. package/dist/es5/lib/utils/url-utils.js +16 -0
  19. package/dist/es5/lib/utils/url-utils.js.map +1 -0
  20. package/dist/es5/null-loader.js +1 -1
  21. package/dist/es5/null-loader.js.map +1 -1
  22. package/dist/esm/lib/api/parse-in-batches.js +6 -7
  23. package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
  24. package/dist/esm/lib/api/parse-sync.js +4 -6
  25. package/dist/esm/lib/api/parse-sync.js.map +1 -1
  26. package/dist/esm/lib/api/parse.js +3 -5
  27. package/dist/esm/lib/api/parse.js.map +1 -1
  28. package/dist/esm/lib/api/select-loader.js +7 -10
  29. package/dist/esm/lib/api/select-loader.js.map +1 -1
  30. package/dist/esm/lib/init.js +1 -1
  31. package/dist/esm/lib/init.js.map +1 -1
  32. package/dist/esm/lib/loader-utils/loader-context.js +16 -8
  33. package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
  34. package/dist/esm/lib/utils/resource-utils.js +29 -26
  35. package/dist/esm/lib/utils/resource-utils.js.map +1 -1
  36. package/dist/esm/lib/utils/response-utils.js +3 -5
  37. package/dist/esm/lib/utils/response-utils.js.map +1 -1
  38. package/dist/esm/lib/utils/url-utils.js +9 -0
  39. package/dist/esm/lib/utils/url-utils.js.map +1 -0
  40. package/dist/esm/null-loader.js +1 -1
  41. package/dist/esm/null-loader.js.map +1 -1
  42. package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
  43. package/dist/lib/api/parse-in-batches.js +4 -7
  44. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  45. package/dist/lib/api/parse-sync.js +3 -3
  46. package/dist/lib/api/parse.js +2 -2
  47. package/dist/lib/api/select-loader.d.ts.map +1 -1
  48. package/dist/lib/api/select-loader.js +6 -3
  49. package/dist/lib/loader-utils/loader-context.d.ts +1 -1
  50. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
  51. package/dist/lib/loader-utils/loader-context.js +17 -7
  52. package/dist/lib/utils/resource-utils.d.ts +17 -8
  53. package/dist/lib/utils/resource-utils.d.ts.map +1 -1
  54. package/dist/lib/utils/resource-utils.js +46 -34
  55. package/dist/lib/utils/response-utils.d.ts.map +1 -1
  56. package/dist/lib/utils/response-utils.js +2 -1
  57. package/dist/lib/utils/url-utils.d.ts +3 -0
  58. package/dist/lib/utils/url-utils.d.ts.map +1 -0
  59. package/dist/lib/utils/url-utils.js +14 -0
  60. package/dist/null-worker.js +1 -1
  61. package/package.json +4 -4
  62. package/src/lib/api/parse-in-batches.ts +8 -9
  63. package/src/lib/api/parse-sync.ts +8 -4
  64. package/src/lib/api/parse.ts +3 -3
  65. package/src/lib/api/select-loader.ts +7 -4
  66. package/src/lib/loader-utils/loader-context.ts +19 -8
  67. package/src/lib/utils/resource-utils.ts +54 -34
  68. package/src/lib/utils/response-utils.ts +3 -2
  69. 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
- const QUERY_STRING_PATTERN = /\?.*/;
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 an object with `url` and (MIME) `type` fields
8
- * If it cannot determine url or type, the corresponding value will be an empty string
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
- * @param resource Any type, but only Responses, string URLs and data URLs are processed
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 getResourceUrlAndType(resource: any): {url: string; type: string} {
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 url = stripQueryString(resource.url || '');
18
- const contentTypeHeader = resource.headers.get('content-type') || '';
19
- return {
20
- url,
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
- 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
- };
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: any): number {
80
+ export function getResourceContentLength(resource: unknown): number {
59
81
  if (isResponse(resource)) {
60
- return resource.headers['content-length'] || -1;
82
+ const response = resource as Response;
83
+ return response.headers['content-length'] || -1;
61
84
  }
62
85
  if (isBlob(resource)) {
63
- return resource.size;
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, getResourceUrlAndType} from './resource-utils';
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 {url, type} = getResourceUrlAndType(resource);
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
+ }