@loaders.gl/core 4.0.0-alpha.19 → 4.0.0-alpha.21

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 (93) hide show
  1. package/dist/dist.min.js +24 -26
  2. package/dist/es5/index.js +7 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
  5. package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
  6. package/dist/es5/javascript-utils/is-type.js +1 -1
  7. package/dist/es5/javascript-utils/is-type.js.map +1 -1
  8. package/dist/es5/lib/api/encode-table.js.map +1 -1
  9. package/dist/es5/lib/api/encode.js.map +1 -1
  10. package/dist/es5/lib/api/load-in-batches.js +6 -3
  11. package/dist/es5/lib/api/load-in-batches.js.map +1 -1
  12. package/dist/es5/lib/api/load.js.map +1 -1
  13. package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
  14. package/dist/es5/lib/api/parse-sync.js.map +1 -1
  15. package/dist/es5/lib/api/parse.js +10 -10
  16. package/dist/es5/lib/api/parse.js.map +1 -1
  17. package/dist/es5/lib/filesystems/filesystem.js.map +1 -1
  18. package/dist/es5/lib/init.js +1 -1
  19. package/dist/es5/lib/loader-utils/get-fetch-function.js +5 -5
  20. package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -1
  21. package/dist/es5/null-loader.js +6 -14
  22. package/dist/es5/null-loader.js.map +1 -1
  23. package/dist/esm/index.js +1 -0
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
  26. package/dist/esm/iterators/make-stream/make-dom-stream.js.map +1 -1
  27. package/dist/esm/javascript-utils/is-type.js +1 -1
  28. package/dist/esm/javascript-utils/is-type.js.map +1 -1
  29. package/dist/esm/lib/api/encode-table.js.map +1 -1
  30. package/dist/esm/lib/api/encode.js.map +1 -1
  31. package/dist/esm/lib/api/load-in-batches.js +6 -3
  32. package/dist/esm/lib/api/load-in-batches.js.map +1 -1
  33. package/dist/esm/lib/api/load.js.map +1 -1
  34. package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
  35. package/dist/esm/lib/api/parse-sync.js.map +1 -1
  36. package/dist/esm/lib/api/parse.js +9 -9
  37. package/dist/esm/lib/api/parse.js.map +1 -1
  38. package/dist/esm/lib/filesystems/filesystem.js.map +1 -1
  39. package/dist/esm/lib/init.js +1 -1
  40. package/dist/esm/lib/loader-utils/get-fetch-function.js +5 -5
  41. package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -1
  42. package/dist/esm/null-loader.js +6 -14
  43. package/dist/esm/null-loader.js.map +1 -1
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts +1 -1
  47. package/dist/iterators/batch-iterators/timed-batch-iterator.d.ts.map +1 -1
  48. package/dist/iterators/make-stream/make-dom-stream.d.ts.map +1 -1
  49. package/dist/iterators/make-stream/make-dom-stream.js +1 -0
  50. package/dist/javascript-utils/is-type.d.ts +5 -5
  51. package/dist/javascript-utils/is-type.d.ts.map +1 -1
  52. package/dist/javascript-utils/is-type.js +1 -1
  53. package/dist/lib/api/encode.d.ts +5 -5
  54. package/dist/lib/api/encode.d.ts.map +1 -1
  55. package/dist/lib/api/load-in-batches.d.ts +5 -0
  56. package/dist/lib/api/load-in-batches.d.ts.map +1 -1
  57. package/dist/lib/api/load-in-batches.js +10 -3
  58. package/dist/lib/api/load.d.ts +1 -2
  59. package/dist/lib/api/load.d.ts.map +1 -1
  60. package/dist/lib/api/parse-in-batches.d.ts +13 -7
  61. package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
  62. package/dist/lib/api/parse-in-batches.js +1 -0
  63. package/dist/lib/api/parse-sync.d.ts +13 -7
  64. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  65. package/dist/lib/api/parse-sync.js +0 -4
  66. package/dist/lib/api/parse.d.ts +11 -1
  67. package/dist/lib/api/parse.d.ts.map +1 -1
  68. package/dist/lib/api/parse.js +10 -9
  69. package/dist/lib/filesystems/filesystem.d.ts +3 -3
  70. package/dist/lib/filesystems/filesystem.d.ts.map +1 -1
  71. package/dist/lib/loader-utils/get-fetch-function.d.ts +2 -2
  72. package/dist/lib/loader-utils/get-fetch-function.d.ts.map +1 -1
  73. package/dist/lib/loader-utils/get-fetch-function.js +5 -5
  74. package/dist/null-loader.d.ts +6 -3
  75. package/dist/null-loader.d.ts.map +1 -1
  76. package/dist/null-loader.js +9 -14
  77. package/dist/null-worker-node.js +6 -11
  78. package/dist/null-worker.js +6 -11
  79. package/package.json +4 -4
  80. package/src/index.ts +1 -0
  81. package/src/iterators/batch-iterators/timed-batch-iterator.ts +4 -1
  82. package/src/iterators/make-stream/make-dom-stream.ts +2 -1
  83. package/src/javascript-utils/is-type.ts +12 -8
  84. package/src/lib/api/encode-table.ts +1 -1
  85. package/src/lib/api/encode.ts +10 -10
  86. package/src/lib/api/load-in-batches.ts +45 -7
  87. package/src/lib/api/load.ts +2 -5
  88. package/src/lib/api/parse-in-batches.ts +39 -10
  89. package/src/lib/api/parse-sync.ts +34 -12
  90. package/src/lib/api/parse.ts +29 -12
  91. package/src/lib/filesystems/filesystem.ts +3 -3
  92. package/src/lib/loader-utils/get-fetch-function.ts +7 -7
  93. package/src/null-loader.ts +23 -17
@@ -1,11 +1,9 @@
1
+ // loaders.gl, MIT license
2
+
1
3
  import type {Batch} from '@loaders.gl/schema';
2
- import type {
3
- BatchableDataType,
4
- Loader,
5
- LoaderWithParser,
6
- LoaderContext,
7
- LoaderOptions
8
- } from '@loaders.gl/loader-utils';
4
+ import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
5
+ import type {LoaderContext, BatchableDataType} from '@loaders.gl/loader-utils';
6
+ import type {LoaderBatchType, LoaderOptionsType} from '@loaders.gl/loader-utils';
9
7
  import {assert, concatenateArrayBuffersAsync} from '@loaders.gl/loader-utils';
10
8
  import {isLoaderObject} from '../loader-utils/normalize-loader';
11
9
  import {normalizeOptions} from '../loader-utils/option-utils';
@@ -17,6 +15,37 @@ import {selectLoader} from './select-loader';
17
15
  // Ensure `parse` is available in context if loader falls back to `parse`
18
16
  import {parse} from './parse';
19
17
 
18
+ /**
19
+ * Parses `data` synchronously using a specified loader
20
+ */
21
+ export async function parseInBatches<
22
+ LoaderT extends Loader,
23
+ OptionsT extends LoaderOptions = LoaderOptionsType<LoaderT>
24
+ >(
25
+ data: BatchableDataType,
26
+ loader: LoaderT,
27
+ options?: OptionsT,
28
+ context?: LoaderContext
29
+ ): Promise<AsyncIterable<LoaderBatchType<LoaderT>>>;
30
+
31
+ /**
32
+ * Parses `data` using one of the supplied loaders
33
+ */
34
+ export async function parseInBatches(
35
+ data: BatchableDataType,
36
+ loaders: Loader[],
37
+ options?: LoaderOptions,
38
+ context?: LoaderContext
39
+ ): Promise<AsyncIterable<any>>;
40
+
41
+ /**
42
+ * Parses `data` in batches by selecting a pre-registered loader
43
+ */
44
+ export async function parseInBatches(
45
+ data: BatchableDataType,
46
+ options?: LoaderOptions
47
+ ): Promise<AsyncIterable<any>>;
48
+
20
49
  /**
21
50
  * Parses `data` using a specified loader
22
51
  * @param data
@@ -29,7 +58,7 @@ export async function parseInBatches(
29
58
  loaders?: Loader | Loader[] | LoaderOptions,
30
59
  options?: LoaderOptions,
31
60
  context?: LoaderContext
32
- ): Promise<AsyncIterable<any>> {
61
+ ): Promise<AsyncIterable<unknown>> {
33
62
  assert(!context || typeof context === 'object'); // parseInBatches no longer accepts final url
34
63
 
35
64
  const loaderArray = Array.isArray(loaders) ? loaders : undefined;
@@ -75,7 +104,7 @@ async function parseWithLoaderInBatches(
75
104
  data: BatchableDataType,
76
105
  options: LoaderOptions,
77
106
  context: LoaderContext
78
- ): Promise<AsyncIterable<any>> {
107
+ ): Promise<AsyncIterable<unknown>> {
79
108
  const outputIterator = await parseToOutputIterator(loader, data, options, context);
80
109
 
81
110
  // Generate metadata batch if requested
@@ -112,7 +141,7 @@ async function parseToOutputIterator(
112
141
  data: BatchableDataType,
113
142
  options: LoaderOptions,
114
143
  context: LoaderContext
115
- ): Promise<AsyncIterable<any>> {
144
+ ): Promise<AsyncIterable<unknown>> {
116
145
  // Get an iterator from the input
117
146
  const inputIterator = await getAsyncIterableFromData(data, options);
118
147
 
@@ -1,10 +1,6 @@
1
- import type {
2
- SyncDataType,
3
- Loader,
4
- LoaderWithParser,
5
- LoaderContext,
6
- LoaderOptions
7
- } from '@loaders.gl/loader-utils';
1
+ import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
2
+ import type {LoaderContext, SyncDataType} from '@loaders.gl/loader-utils';
3
+ import type {LoaderOptionsType, LoaderReturnType} from '@loaders.gl/loader-utils';
8
4
  import {assert} from '@loaders.gl/loader-utils';
9
5
  import {selectLoaderSync} from './select-loader';
10
6
  import {isLoaderObject} from '../loader-utils/normalize-loader';
@@ -13,19 +9,45 @@ import {getArrayBufferOrStringFromDataSync} from '../loader-utils/get-data';
13
9
  import {getLoaderContext, getLoadersFromContext} from '../loader-utils/loader-context';
14
10
  import {getResourceUrl} from '../utils/resource-utils';
15
11
 
12
+ // OVERLOADS
13
+
14
+ /**
15
+ * Parses `data` synchronously using the specified loader
16
+ */
17
+ export function parseSync<
18
+ LoaderT extends Loader,
19
+ OptionsT extends LoaderOptions = LoaderOptionsType<LoaderT>
20
+ >(
21
+ data: SyncDataType,
22
+ loader: LoaderT,
23
+ options?: OptionsT,
24
+ context?: LoaderContext
25
+ ): LoaderReturnType<LoaderT>;
26
+
27
+ /**
28
+ * Parses `data` synchronously by matching one of the supplied loaders
29
+ */
30
+ export function parseSync(
31
+ data: SyncDataType,
32
+ loaders: Loader[],
33
+ options?: LoaderOptions,
34
+ context?: LoaderContext
35
+ ): any;
36
+
37
+ /**
38
+ * Parses `data` synchronously by matching a pre=registered loader
39
+ */
40
+ export function parseSync(data: SyncDataType, options?: LoaderOptions): any;
41
+
16
42
  /**
17
43
  * Parses `data` synchronously using a specified loader
18
- * @param data
19
- * @param loaders
20
- * @param options
21
- * @param context
22
44
  */
23
45
  export function parseSync(
24
46
  data: SyncDataType,
25
47
  loaders?: Loader | Loader[] | LoaderOptions,
26
48
  options?: LoaderOptions,
27
49
  context?: LoaderContext
28
- ): any {
50
+ ): unknown {
29
51
  assert(!context || typeof context === 'object'); // parseSync no longer accepts final url
30
52
 
31
53
  // Signature: parseSync(data, options)
@@ -1,9 +1,10 @@
1
1
  // loaders.gl, MIT license
2
2
 
3
- import type {DataType, Loader, LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
3
+ import type {Loader, LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
4
+ import type {DataType, LoaderWithParser} from '@loaders.gl/loader-utils';
4
5
  import type {LoaderOptionsType, LoaderReturnType} from '@loaders.gl/loader-utils';
5
- import {assert, validateWorkerVersion} from '@loaders.gl/worker-utils';
6
6
  import {parseWithWorker, canParseWithWorker} from '@loaders.gl/loader-utils';
7
+ import {assert, validateWorkerVersion} from '@loaders.gl/worker-utils';
7
8
  import {isLoaderObject} from '../loader-utils/normalize-loader';
8
9
  import {isResponse} from '../../javascript-utils/is-type';
9
10
  import {normalizeOptions} from '../loader-utils/option-utils';
@@ -14,6 +15,9 @@ import {selectLoader} from './select-loader';
14
15
 
15
16
  // type LoaderArrayType<T> = T extends (infer Loader)[] ? LoaderOptionsType<Loader> : T
16
17
 
18
+ /**
19
+ * Parses `data` asynchronously using the supplied loaders
20
+ */
17
21
  export async function parse<
18
22
  LoaderT extends Loader,
19
23
  OptionsT extends LoaderOptions = LoaderOptionsType<LoaderT>
@@ -24,6 +28,9 @@ export async function parse<
24
28
  context?: LoaderContext
25
29
  ): Promise<LoaderReturnType<LoaderT>>;
26
30
 
31
+ /**
32
+ * Parses `data` asynchronously by matching one of the supplied loaders
33
+ */
27
34
  export async function parse(
28
35
  data: DataType | Promise<DataType>,
29
36
  loaders: Loader[],
@@ -31,6 +38,9 @@ export async function parse(
31
38
  context?: LoaderContext
32
39
  ): Promise<any>;
33
40
 
41
+ /**
42
+ * Parses data asynchronously by matching a pre-registered loader
43
+ */
34
44
  export async function parse(
35
45
  data: DataType | Promise<DataType>,
36
46
  options?: LoaderOptions
@@ -49,7 +59,7 @@ export async function parse(
49
59
  loaders?: Loader | Loader[] | LoaderOptions,
50
60
  options?: LoaderOptions,
51
61
  context?: LoaderContext
52
- ): Promise<any> {
62
+ ): Promise<unknown> {
53
63
  assert(!context || typeof context === 'object'); // parse no longer accepts final url
54
64
 
55
65
  // Signature: parse(data, options, context | url)
@@ -88,7 +98,12 @@ export async function parse(
88
98
 
89
99
  // TODO: support progress and abort
90
100
  // TODO - should accept loader.parseAsyncIterator and concatenate.
91
- async function parseWithLoader(loader, data, options, context) {
101
+ async function parseWithLoader(
102
+ loader: Loader,
103
+ data,
104
+ options: LoaderOptions,
105
+ context: LoaderContext
106
+ ): Promise<unknown> {
92
107
  validateWorkerVersion(loader);
93
108
 
94
109
  if (isResponse(data)) {
@@ -96,15 +111,17 @@ async function parseWithLoader(loader, data, options, context) {
96
111
  const response = data as Response;
97
112
  const {ok, redirected, status, statusText, type, url} = response;
98
113
  const headers = Object.fromEntries(response.headers.entries());
114
+ // @ts-expect-error TODO - fix this
99
115
  context.response = {headers, ok, redirected, status, statusText, type, url};
100
116
  }
101
117
 
102
118
  data = await getArrayBufferOrStringFromData(data, loader, options);
103
119
 
120
+ const loaderWithParser = loader as LoaderWithParser;
121
+
104
122
  // First check for synchronous text parser, wrap results in promises
105
- if (loader.parseTextSync && typeof data === 'string') {
106
- options.dataType = 'text';
107
- return loader.parseTextSync(data, options, context, loader);
123
+ if (loaderWithParser.parseTextSync && typeof data === 'string') {
124
+ return loaderWithParser.parseTextSync(data, options, context);
108
125
  }
109
126
 
110
127
  // If we have a workerUrl and the loader can parse the given options efficiently in a worker
@@ -113,16 +130,16 @@ async function parseWithLoader(loader, data, options, context) {
113
130
  }
114
131
 
115
132
  // Check for asynchronous parser
116
- if (loader.parseText && typeof data === 'string') {
117
- return await loader.parseText(data, options, context, loader);
133
+ if (loaderWithParser.parseText && typeof data === 'string') {
134
+ return await loaderWithParser.parseText(data, options, context);
118
135
  }
119
136
 
120
- if (loader.parse) {
121
- return await loader.parse(data, options, context, loader);
137
+ if (loaderWithParser.parse) {
138
+ return await loaderWithParser.parse(data, options, context);
122
139
  }
123
140
 
124
141
  // This should not happen, all sync loaders should also offer `parse` function
125
- assert(!loader.parseSync);
142
+ assert(!loaderWithParser.parseSync);
126
143
 
127
144
  // TBD - If asynchronous parser not available, return null
128
145
  throw new Error(`${loader.id} loader - no parser found and worker is disabled`);
@@ -36,9 +36,9 @@ export interface FileSystem {
36
36
  * A random access file system
37
37
  */
38
38
  export interface RandomAccessReadFileSystem extends FileSystem {
39
- open(path: string, flags, mode?): Promise<any>;
40
- close(fd: any): Promise<void>;
41
- fstat(fd: any): Promise<Stat>;
39
+ open(path: string, flags: unknown, mode?: unknown): Promise<any>;
40
+ close(fd: unknown): Promise<void>;
41
+ fstat(fd: unknown): Promise<Stat>;
42
42
  read(
43
43
  fd: any,
44
44
  buffer: ArrayBuffer | ArrayBufferView,
@@ -1,6 +1,6 @@
1
1
  // loaders.gl, MIT license
2
2
 
3
- import type {LoaderContext, LoaderOptions} from '@loaders.gl/loader-utils';
3
+ import type {LoaderContext, LoaderOptions, FetchLike} from '@loaders.gl/loader-utils';
4
4
  import {isObject} from '../../javascript-utils/is-type';
5
5
  import {fetchFile} from '../fetch/fetch-file';
6
6
  import {getGlobalLoaderOptions} from './option-utils';
@@ -13,19 +13,19 @@ import {getGlobalLoaderOptions} from './option-utils';
13
13
  export function getFetchFunction(
14
14
  options?: LoaderOptions,
15
15
  context?: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>
16
- ) {
16
+ ): FetchLike {
17
17
  const globalOptions = getGlobalLoaderOptions();
18
18
 
19
- const fetchOptions = options || globalOptions;
19
+ const loaderOptions = options || globalOptions;
20
20
 
21
21
  // options.fetch can be a function
22
- if (typeof fetchOptions.fetch === 'function') {
23
- return fetchOptions.fetch;
22
+ if (typeof loaderOptions.fetch === 'function') {
23
+ return loaderOptions.fetch;
24
24
  }
25
25
 
26
26
  // options.fetch can be an options object
27
- if (isObject(fetchOptions.fetch)) {
28
- return (url) => fetchFile(url, fetchOptions as RequestInit);
27
+ if (isObject(loaderOptions.fetch)) {
28
+ return (url) => fetchFile(url, loaderOptions.fetch as RequestInit);
29
29
  }
30
30
 
31
31
  // else refer to context (from parent loader) if available
@@ -2,12 +2,17 @@
2
2
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
3
3
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
4
4
 
5
- import {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';
5
+ import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
6
+ import {LoaderContext} from 'modules/loader-utils/dist';
7
+
8
+ export type NullLoaderOptions = LoaderOptions & {
9
+ null?: {};
10
+ };
6
11
 
7
12
  /**
8
13
  * Loads any data and returns null (or optionally passes through data unparsed)
9
14
  */
10
- export const NullWorkerLoader: Loader = {
15
+ export const NullWorkerLoader: Loader<null, never, NullLoaderOptions> = {
11
16
  name: 'Null loader',
12
17
  id: 'null',
13
18
  module: 'core',
@@ -21,27 +26,18 @@ export const NullWorkerLoader: Loader = {
21
26
  }
22
27
  };
23
28
 
24
- /**
25
- * Returns arguments passed to the parse API in a format that can be transfered to a
26
- * web worker. The `context` parameter is stripped using JSON.stringify & parse.
27
- */
28
- function parseSync(arrayBuffer, options, context) {
29
- if (!options.null.echoParameters) return null;
30
- context = context && JSON.parse(JSON.stringify(context));
31
- return {arrayBuffer, options, context};
32
- }
33
-
34
29
  /**
35
30
  * Loads any data and returns null (or optionally passes through data unparsed)
36
31
  */
37
- export const NullLoader: LoaderWithParser = {
32
+ export const NullLoader: LoaderWithParser<null, null, NullLoaderOptions> = {
38
33
  name: 'Null loader',
39
34
  id: 'null',
40
35
  module: 'core',
41
36
  version: VERSION,
42
37
  mimeTypes: ['application/x.empty'],
43
38
  extensions: ['null'],
44
- parse: async (arrayBuffer, options, context) => parseSync(arrayBuffer, options, context),
39
+ parse: async (arrayBuffer: ArrayBuffer, options?: NullLoaderOptions, context?: LoaderContext) =>
40
+ parseSync(arrayBuffer, options || {}, context),
45
41
  parseSync,
46
42
  parseInBatches: async function* generator(asyncIterator, options, context) {
47
43
  for await (const batch of asyncIterator) {
@@ -50,8 +46,18 @@ export const NullLoader: LoaderWithParser = {
50
46
  },
51
47
  tests: [() => false],
52
48
  options: {
53
- null: {
54
- echoParameters: false
55
- }
49
+ null: {}
56
50
  }
57
51
  };
52
+
53
+ /**
54
+ * Returns arguments passed to the parse API in a format that can be transferred to a
55
+ * web worker. The `context` parameter is stripped using JSON.stringify & parse.
56
+ */
57
+ function parseSync(
58
+ arrayBuffer: ArrayBuffer,
59
+ options?: NullLoaderOptions,
60
+ context?: LoaderContext
61
+ ): null {
62
+ return null;
63
+ }