@loaders.gl/core 4.4.0-alpha.2 → 4.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 (144) hide show
  1. package/README.md +4 -0
  2. package/dist/core-addons/write-file-browser.js +1 -0
  3. package/dist/core-addons/write-file-browser.js.map +1 -0
  4. package/dist/dist.dev.js +641 -286
  5. package/dist/dist.min.js +3 -3
  6. package/dist/index.cjs +411 -262
  7. package/dist/index.cjs.map +4 -4
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +2 -1
  11. package/dist/index.js.map +1 -0
  12. package/dist/iterators/batch-iterators/timed-batch-iterator.js +1 -0
  13. package/dist/iterators/batch-iterators/timed-batch-iterator.js.map +1 -0
  14. package/dist/iterators/make-iterator/make-array-buffer-iterator.js +1 -0
  15. package/dist/iterators/make-iterator/make-array-buffer-iterator.js.map +1 -0
  16. package/dist/iterators/make-iterator/make-blob-iterator.js +1 -0
  17. package/dist/iterators/make-iterator/make-blob-iterator.js.map +1 -0
  18. package/dist/iterators/make-iterator/make-iterator.d.ts.map +1 -1
  19. package/dist/iterators/make-iterator/make-iterator.js +7 -3
  20. package/dist/iterators/make-iterator/make-iterator.js.map +1 -0
  21. package/dist/iterators/make-iterator/make-stream-iterator.js +1 -0
  22. package/dist/iterators/make-iterator/make-stream-iterator.js.map +1 -0
  23. package/dist/iterators/make-iterator/make-string-iterator.d.ts.map +1 -1
  24. package/dist/iterators/make-iterator/make-string-iterator.js +3 -1
  25. package/dist/iterators/make-iterator/make-string-iterator.js.map +1 -0
  26. package/dist/iterators/make-stream/make-stream.js +1 -0
  27. package/dist/iterators/make-stream/make-stream.js.map +1 -0
  28. package/dist/lib/api/create-data-source.js +1 -0
  29. package/dist/lib/api/create-data-source.js.map +1 -0
  30. package/dist/lib/api/encode-table.d.ts.map +1 -1
  31. package/dist/lib/api/encode-table.js +3 -2
  32. package/dist/lib/api/encode-table.js.map +1 -0
  33. package/dist/lib/api/encode.d.ts.map +1 -1
  34. package/dist/lib/api/encode.js +3 -2
  35. package/dist/lib/api/encode.js.map +1 -0
  36. package/dist/lib/api/load-in-batches.js +1 -0
  37. package/dist/lib/api/load-in-batches.js.map +1 -0
  38. package/dist/lib/api/load.d.ts.map +1 -1
  39. package/dist/lib/api/load.js +15 -1
  40. package/dist/lib/api/load.js.map +1 -0
  41. package/dist/lib/api/loader-options.js +1 -0
  42. package/dist/lib/api/loader-options.js.map +1 -0
  43. package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
  44. package/dist/lib/api/parse-in-batches.js +7 -6
  45. package/dist/lib/api/parse-in-batches.js.map +1 -0
  46. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  47. package/dist/lib/api/parse-sync.js +4 -3
  48. package/dist/lib/api/parse-sync.js.map +1 -0
  49. package/dist/lib/api/parse.d.ts.map +1 -1
  50. package/dist/lib/api/parse.js +8 -9
  51. package/dist/lib/api/parse.js.map +1 -0
  52. package/dist/lib/api/register-loaders.js +1 -0
  53. package/dist/lib/api/register-loaders.js.map +1 -0
  54. package/dist/lib/api/select-loader.d.ts +3 -3
  55. package/dist/lib/api/select-loader.d.ts.map +1 -1
  56. package/dist/lib/api/select-loader.js +36 -15
  57. package/dist/lib/api/select-loader.js.map +1 -0
  58. package/dist/lib/api/select-source.js +1 -0
  59. package/dist/lib/api/select-source.js.map +1 -0
  60. package/dist/lib/common.js +1 -0
  61. package/dist/lib/common.js.map +1 -0
  62. package/dist/lib/fetch/fetch-error-message.js +1 -0
  63. package/dist/lib/fetch/fetch-error-message.js.map +1 -0
  64. package/dist/lib/fetch/fetch-error.js +1 -0
  65. package/dist/lib/fetch/fetch-error.js.map +1 -0
  66. package/dist/lib/fetch/fetch-file.js +1 -0
  67. package/dist/lib/fetch/fetch-file.js.map +1 -0
  68. package/dist/lib/fetch/read-array-buffer.js +1 -0
  69. package/dist/lib/fetch/read-array-buffer.js.map +1 -0
  70. package/dist/lib/filesystems/browser-filesystem.js +1 -0
  71. package/dist/lib/filesystems/browser-filesystem.js.map +1 -0
  72. package/dist/lib/filesystems/read-array-buffer.js +1 -0
  73. package/dist/lib/filesystems/read-array-buffer.js.map +1 -0
  74. package/dist/lib/init.js +2 -1
  75. package/dist/lib/init.js.map +1 -0
  76. package/dist/lib/loader-utils/check-errors.js +1 -0
  77. package/dist/lib/loader-utils/check-errors.js.map +1 -0
  78. package/dist/lib/loader-utils/get-data.d.ts +18 -1
  79. package/dist/lib/loader-utils/get-data.d.ts.map +1 -1
  80. package/dist/lib/loader-utils/get-data.js +47 -38
  81. package/dist/lib/loader-utils/get-data.js.map +1 -0
  82. package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -1
  83. package/dist/lib/loader-utils/get-fetch-function.js +7 -5
  84. package/dist/lib/loader-utils/get-fetch-function.js.map +1 -0
  85. package/dist/lib/loader-utils/loader-context.d.ts +2 -2
  86. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
  87. package/dist/lib/loader-utils/loader-context.js +1 -0
  88. package/dist/lib/loader-utils/loader-context.js.map +1 -0
  89. package/dist/lib/loader-utils/loggers.js +1 -0
  90. package/dist/lib/loader-utils/loggers.js.map +1 -0
  91. package/dist/lib/loader-utils/normalize-loader.js +1 -0
  92. package/dist/lib/loader-utils/normalize-loader.js.map +1 -0
  93. package/dist/lib/loader-utils/option-defaults.d.ts +22 -0
  94. package/dist/lib/loader-utils/option-defaults.d.ts.map +1 -1
  95. package/dist/lib/loader-utils/option-defaults.js +63 -33
  96. package/dist/lib/loader-utils/option-defaults.js.map +1 -0
  97. package/dist/lib/loader-utils/option-utils.d.ts +10 -4
  98. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  99. package/dist/lib/loader-utils/option-utils.js +123 -19
  100. package/dist/lib/loader-utils/option-utils.js.map +1 -0
  101. package/dist/lib/progress/fetch-progress.js +1 -0
  102. package/dist/lib/progress/fetch-progress.js.map +1 -0
  103. package/dist/lib/utils/mime-type-utils.js +1 -0
  104. package/dist/lib/utils/mime-type-utils.js.map +1 -0
  105. package/dist/lib/utils/resource-utils.d.ts.map +1 -1
  106. package/dist/lib/utils/resource-utils.js +8 -10
  107. package/dist/lib/utils/resource-utils.js.map +1 -0
  108. package/dist/lib/utils/response-utils.js +2 -1
  109. package/dist/lib/utils/response-utils.js.map +1 -0
  110. package/dist/lib/utils/url-utils.js +1 -0
  111. package/dist/lib/utils/url-utils.js.map +1 -0
  112. package/dist/null-loader.d.ts +3 -3
  113. package/dist/null-loader.d.ts.map +1 -1
  114. package/dist/null-loader.js +2 -1
  115. package/dist/null-loader.js.map +1 -0
  116. package/dist/null-worker-node.js +5 -2
  117. package/dist/null-worker.js +5 -2
  118. package/dist/workers/null-worker-node.js +1 -0
  119. package/dist/workers/null-worker-node.js.map +1 -0
  120. package/dist/workers/null-worker.js +1 -0
  121. package/dist/workers/null-worker.js.map +1 -0
  122. package/package.json +13 -10
  123. package/src/index.ts +1 -1
  124. package/src/iterators/make-iterator/make-iterator.ts +8 -5
  125. package/src/iterators/make-iterator/make-string-iterator.ts +2 -1
  126. package/src/lib/api/encode-table.ts +2 -1
  127. package/src/lib/api/encode.ts +8 -2
  128. package/src/lib/api/load.ts +15 -1
  129. package/src/lib/api/parse-in-batches.ts +26 -19
  130. package/src/lib/api/parse-sync.ts +6 -5
  131. package/src/lib/api/parse.ts +15 -11
  132. package/src/lib/api/select-loader.ts +68 -24
  133. package/src/lib/loader-utils/get-data.ts +62 -48
  134. package/src/lib/loader-utils/get-fetch-function.ts +6 -5
  135. package/src/lib/loader-utils/loader-context.ts +2 -2
  136. package/src/lib/loader-utils/option-defaults.ts +68 -35
  137. package/src/lib/loader-utils/option-utils.ts +146 -29
  138. package/src/lib/utils/resource-utils.ts +9 -12
  139. package/src/lib/utils/response-utils.ts +2 -2
  140. package/src/null-loader.ts +6 -3
  141. package/dist/javascript-utils/is-type.d.ts +0 -21
  142. package/dist/javascript-utils/is-type.d.ts.map +0 -1
  143. package/dist/javascript-utils/is-type.js +0 -25
  144. package/src/javascript-utils/is-type.ts +0 -51
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {isResponse, isBlob} from '../../javascript-utils/is-type';
5
+ import {isResponse, isBlob} from '@loaders.gl/loader-utils';
6
6
  import {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';
7
7
  import {stripQueryString} from './url-utils';
8
8
 
@@ -22,16 +22,15 @@ export type Resource = Response | Blob | string;
22
22
  export function getResourceUrl(resource: unknown): string {
23
23
  // If resource is a `Response`, it contains the information directly as a field
24
24
  if (isResponse(resource)) {
25
- const response = resource as Response;
26
- return response.url;
25
+ return resource.url;
27
26
  }
28
27
 
29
28
  // If the resource is a Blob or a File (subclass of Blob)
30
29
  if (isBlob(resource)) {
31
- const blob = resource as Blob;
32
30
  // File objects have a "name" property. Blob objects don't have any
33
31
  // url (name) information
34
- return (blob as any).name || '';
32
+ const fileName = 'name' in resource ? (resource as File).name : '';
33
+ return fileName || '';
35
34
  }
36
35
 
37
36
  if (typeof resource === 'string') {
@@ -52,16 +51,14 @@ export function getResourceUrl(resource: unknown): string {
52
51
  export function getResourceMIMEType(resource: unknown): string {
53
52
  // If resource is a response, it contains the information directly
54
53
  if (isResponse(resource)) {
55
- const response = resource as Response;
56
- const contentTypeHeader = response.headers.get('content-type') || '';
57
- const noQueryUrl = stripQueryString(response.url);
54
+ const contentTypeHeader = resource.headers.get('content-type') || '';
55
+ const noQueryUrl = stripQueryString(resource.url);
58
56
  return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
59
57
  }
60
58
 
61
59
  // If the resource is a Blob or a File (subclass of Blob)
62
60
  if (isBlob(resource)) {
63
- const blob = resource as Blob;
64
- return blob.type || '';
61
+ return resource.type || '';
65
62
  }
66
63
 
67
64
  if (typeof resource === 'string') {
@@ -81,11 +78,11 @@ export function getResourceMIMEType(resource: unknown): string {
81
78
  */
82
79
  export function getResourceContentLength(resource: unknown): number {
83
80
  if (isResponse(resource)) {
84
- const response = resource as Response;
81
+ const response = resource;
85
82
  return response.headers['content-length'] || -1;
86
83
  }
87
84
  if (isBlob(resource)) {
88
- const blob = resource as Blob;
85
+ const blob = resource;
89
86
  return blob.size;
90
87
  }
91
88
  if (typeof resource === 'string') {
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {isResponse} from '../../javascript-utils/is-type';
5
+ import {isResponse} from '@loaders.gl/loader-utils';
6
6
  import {FetchError} from '../fetch/fetch-error';
7
7
  import {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';
8
8
  import {shortenUrlForDisplay} from './url-utils';
@@ -15,7 +15,7 @@ import {shortenUrlForDisplay} from './url-utils';
15
15
  */
16
16
  export async function makeResponse(resource: unknown): Promise<Response> {
17
17
  if (isResponse(resource)) {
18
- return resource as Response;
18
+ return resource;
19
19
  }
20
20
 
21
21
  // Add content-length header if possible
@@ -45,8 +45,11 @@ export const NullLoader = {
45
45
  version: VERSION,
46
46
  mimeTypes: ['application/x.empty'],
47
47
  extensions: ['null'],
48
- parse: async (arrayBuffer: ArrayBuffer, options?: NullLoaderOptions, context?: LoaderContext) =>
49
- parseSync(arrayBuffer, options || {}, context),
48
+ parse: async (
49
+ arrayBuffer: ArrayBufferLike | ArrayBufferView,
50
+ options?: NullLoaderOptions,
51
+ context?: LoaderContext
52
+ ) => parseSync(arrayBuffer, options || {}, context),
50
53
  parseSync,
51
54
  parseInBatches: async function* generator(asyncIterator, options, context) {
52
55
  for await (const batch of asyncIterator) {
@@ -64,7 +67,7 @@ export const NullLoader = {
64
67
  * web worker. The `context` parameter is stripped using JSON.stringify & parse.
65
68
  */
66
69
  function parseSync(
67
- arrayBuffer: ArrayBuffer,
70
+ arrayBuffer: ArrayBufferLike | ArrayBufferView,
68
71
  options?: NullLoaderOptions,
69
72
  context?: LoaderContext
70
73
  ): null {
@@ -1,21 +0,0 @@
1
- import type { Readable } from 'stream';
2
- /** A DOM or Node readable stream */
3
- export type ReadableStreamType = ReadableStream | Readable;
4
- export declare const isObject: (x: unknown) => boolean;
5
- export declare const isPureObject: (x: any) => boolean;
6
- export declare const isPromise: (x: any) => boolean;
7
- export declare const isIterable: (x: any) => boolean;
8
- export declare const isAsyncIterable: (x: any) => boolean;
9
- export declare const isIterator: (x: any) => boolean;
10
- export declare const isResponse: (x: any) => boolean;
11
- export declare const isFile: (x: unknown) => boolean;
12
- export declare const isBlob: (x: unknown) => boolean;
13
- /** Check for Node.js `Buffer` without triggering bundler to include buffer polyfill */
14
- export declare const isBuffer: (x: any) => boolean;
15
- export declare const isWritableDOMStream: (x: any) => boolean;
16
- export declare const isReadableDOMStream: (x: any) => boolean;
17
- export declare const isWritableNodeStream: (x: any) => boolean;
18
- export declare const isReadableNodeStream: (x: any) => boolean;
19
- export declare const isReadableStream: (x: unknown) => boolean;
20
- export declare const isWritableStream: (x: unknown) => boolean;
21
- //# sourceMappingURL=is-type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-type.d.ts","sourceRoot":"","sources":["../../src/javascript-utils/is-type.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAErC,oCAAoC;AACpC,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG,QAAQ,CAAC;AAK3D,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAoD,CAAC;AAC5F,eAAO,MAAM,YAAY,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OACU,CAAC;AAClD,eAAO,MAAM,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAkD,CAAC;AAEvF,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OACmB,CAAC;AACzD,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OACU,CAAC;AACrD,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAwC,CAAC;AAE9E,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAEK,CAAC;AAE3C,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OACa,CAAC;AACnD,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OACa,CAAC;AAEnD,uFAAuF;AACvF,eAAO,MAAM,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAyD,CAAC;AAE7F,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OACiB,CAAC;AAEhE,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAEyC,CAAC;AAGxF,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OACmC,CAAC;AACnF,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OACmC,CAAC;AACnF,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OACI,CAAC;AACpD,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OACI,CAAC"}
@@ -1,25 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- const isBoolean = (x) => typeof x === 'boolean';
5
- const isFunction = (x) => typeof x === 'function';
6
- export const isObject = (x) => x !== null && typeof x === 'object';
7
- export const isPureObject = (x) => isObject(x) && x.constructor === {}.constructor;
8
- export const isPromise = (x) => isObject(x) && isFunction(x.then);
9
- export const isIterable = (x) => Boolean(x) && typeof x[Symbol.iterator] === 'function';
10
- export const isAsyncIterable = (x) => x && typeof x[Symbol.asyncIterator] === 'function';
11
- export const isIterator = (x) => x && isFunction(x.next);
12
- export const isResponse = (x) => (typeof Response !== 'undefined' && x instanceof Response) ||
13
- (x && x.arrayBuffer && x.text && x.json);
14
- export const isFile = (x) => typeof File !== 'undefined' && x instanceof File;
15
- export const isBlob = (x) => typeof Blob !== 'undefined' && x instanceof Blob;
16
- /** Check for Node.js `Buffer` without triggering bundler to include buffer polyfill */
17
- export const isBuffer = (x) => x && typeof x === 'object' && x.isBuffer;
18
- export const isWritableDOMStream = (x) => isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
19
- export const isReadableDOMStream = (x) => (typeof ReadableStream !== 'undefined' && x instanceof ReadableStream) ||
20
- (isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader));
21
- // Not implemented in Firefox: && isFunction(x.pipeTo)
22
- export const isWritableNodeStream = (x) => isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
23
- export const isReadableNodeStream = (x) => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
24
- export const isReadableStream = (x) => isReadableDOMStream(x) || isReadableNodeStream(x);
25
- export const isWritableStream = (x) => isWritableDOMStream(x) || isWritableNodeStream(x);
@@ -1,51 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
-
5
- import type {Readable} from 'stream';
6
-
7
- /** A DOM or Node readable stream */
8
- export type ReadableStreamType = ReadableStream | Readable;
9
-
10
- const isBoolean: (x: unknown) => boolean = (x) => typeof x === 'boolean';
11
- const isFunction: (x: unknown) => boolean = (x) => typeof x === 'function';
12
-
13
- export const isObject: (x: unknown) => boolean = (x) => x !== null && typeof x === 'object';
14
- export const isPureObject: (x: any) => boolean = (x) =>
15
- isObject(x) && x.constructor === {}.constructor;
16
- export const isPromise: (x: any) => boolean = (x) => isObject(x) && isFunction(x.then);
17
-
18
- export const isIterable: (x: any) => boolean = (x) =>
19
- Boolean(x) && typeof x[Symbol.iterator] === 'function';
20
- export const isAsyncIterable: (x: any) => boolean = (x) =>
21
- x && typeof x[Symbol.asyncIterator] === 'function';
22
- export const isIterator: (x: any) => boolean = (x) => x && isFunction(x.next);
23
-
24
- export const isResponse: (x: any) => boolean = (x) =>
25
- (typeof Response !== 'undefined' && x instanceof Response) ||
26
- (x && x.arrayBuffer && x.text && x.json);
27
-
28
- export const isFile: (x: unknown) => boolean = (x) =>
29
- typeof File !== 'undefined' && x instanceof File;
30
- export const isBlob: (x: unknown) => boolean = (x) =>
31
- typeof Blob !== 'undefined' && x instanceof Blob;
32
-
33
- /** Check for Node.js `Buffer` without triggering bundler to include buffer polyfill */
34
- export const isBuffer: (x: any) => boolean = (x) => x && typeof x === 'object' && x.isBuffer;
35
-
36
- export const isWritableDOMStream: (x: any) => boolean = (x) =>
37
- isObject(x) && isFunction(x.abort) && isFunction(x.getWriter);
38
-
39
- export const isReadableDOMStream: (x: any) => boolean = (x) =>
40
- (typeof ReadableStream !== 'undefined' && x instanceof ReadableStream) ||
41
- (isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader));
42
- // Not implemented in Firefox: && isFunction(x.pipeTo)
43
-
44
- export const isWritableNodeStream: (x: any) => boolean = (x) =>
45
- isObject(x) && isFunction(x.end) && isFunction(x.write) && isBoolean(x.writable);
46
- export const isReadableNodeStream: (x: any) => boolean = (x) =>
47
- isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
48
- export const isReadableStream: (x: unknown) => boolean = (x) =>
49
- isReadableDOMStream(x) || isReadableNodeStream(x);
50
- export const isWritableStream: (x: unknown) => boolean = (x) =>
51
- isWritableDOMStream(x) || isWritableNodeStream(x);