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

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 (125) hide show
  1. package/dist/dist.min.js +15 -18
  2. package/dist/es5/index.js +4 -12
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
  5. package/dist/es5/lib/api/load-in-batches.js.map +1 -1
  6. package/dist/es5/lib/api/load.js.map +1 -1
  7. package/dist/es5/lib/api/parse-in-batches.js +11 -13
  8. package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
  9. package/dist/es5/lib/api/parse-sync.js +2 -6
  10. package/dist/es5/lib/api/parse-sync.js.map +1 -1
  11. package/dist/es5/lib/api/parse.js +10 -12
  12. package/dist/es5/lib/api/parse.js.map +1 -1
  13. package/dist/es5/lib/api/save.js.map +1 -1
  14. package/dist/es5/lib/api/select-loader.js +5 -3
  15. package/dist/es5/lib/api/select-loader.js.map +1 -1
  16. package/dist/es5/lib/filesystems/browser-filesystem.js +2 -2
  17. package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
  18. package/dist/es5/lib/init.js +1 -1
  19. package/dist/es5/lib/init.js.map +1 -1
  20. package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
  21. package/dist/es5/lib/loader-utils/loader-context.js +2 -2
  22. package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
  23. package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
  24. package/dist/es5/lib/loader-utils/option-utils.js +3 -4
  25. package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
  26. package/dist/es5/lib/progress/fetch-progress.js +1 -1
  27. package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
  28. package/dist/es5/null-loader.js +1 -1
  29. package/dist/es5/null-loader.js.map +1 -1
  30. package/dist/esm/index.js +2 -3
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -1
  33. package/dist/esm/lib/api/load-in-batches.js.map +1 -1
  34. package/dist/esm/lib/api/load.js.map +1 -1
  35. package/dist/esm/lib/api/parse-in-batches.js +3 -4
  36. package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
  37. package/dist/esm/lib/api/parse-sync.js +2 -4
  38. package/dist/esm/lib/api/parse-sync.js.map +1 -1
  39. package/dist/esm/lib/api/parse.js +1 -2
  40. package/dist/esm/lib/api/parse.js.map +1 -1
  41. package/dist/esm/lib/api/save.js.map +1 -1
  42. package/dist/esm/lib/api/select-loader.js +5 -3
  43. package/dist/esm/lib/api/select-loader.js.map +1 -1
  44. package/dist/esm/lib/filesystems/browser-filesystem.js +1 -1
  45. package/dist/esm/lib/filesystems/browser-filesystem.js.map +1 -1
  46. package/dist/esm/lib/init.js +1 -1
  47. package/dist/esm/lib/init.js.map +1 -1
  48. package/dist/esm/lib/loader-utils/get-data.js.map +1 -1
  49. package/dist/esm/lib/loader-utils/loader-context.js +2 -2
  50. package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
  51. package/dist/esm/lib/loader-utils/loggers.js.map +1 -1
  52. package/dist/esm/lib/loader-utils/option-utils.js +2 -2
  53. package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
  54. package/dist/esm/lib/progress/fetch-progress.js +1 -1
  55. package/dist/esm/lib/progress/fetch-progress.js.map +1 -1
  56. package/dist/esm/null-loader.js +1 -1
  57. package/dist/esm/null-loader.js.map +1 -1
  58. package/dist/index.d.ts +3 -4
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +2 -5
  61. package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -1
  62. package/dist/iterators/make-stream/make-node-stream.js +5 -2
  63. package/dist/lib/api/load-in-batches.d.ts +2 -2
  64. package/dist/lib/api/load-in-batches.d.ts.map +1 -1
  65. package/dist/lib/api/load.d.ts +4 -2
  66. package/dist/lib/api/load.d.ts.map +1 -1
  67. package/dist/lib/api/parse-in-batches.d.ts +2 -2
  68. package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
  69. package/dist/lib/api/parse-in-batches.js +1 -2
  70. package/dist/lib/api/parse-sync.d.ts +2 -2
  71. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  72. package/dist/lib/api/parse-sync.js +2 -3
  73. package/dist/lib/api/parse.d.ts +4 -4
  74. package/dist/lib/api/parse.d.ts.map +1 -1
  75. package/dist/lib/api/parse.js +4 -2
  76. package/dist/lib/api/save.d.ts +2 -2
  77. package/dist/lib/api/save.d.ts.map +1 -1
  78. package/dist/lib/api/select-loader.d.ts.map +1 -1
  79. package/dist/lib/api/select-loader.js +8 -3
  80. package/dist/lib/filesystems/browser-filesystem.d.ts +4 -4
  81. package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -1
  82. package/dist/lib/filesystems/browser-filesystem.js +3 -2
  83. package/dist/lib/init.d.ts.map +1 -1
  84. package/dist/lib/init.js +1 -0
  85. package/dist/lib/loader-utils/get-data.d.ts.map +1 -1
  86. package/dist/lib/loader-utils/get-data.js +1 -0
  87. package/dist/lib/loader-utils/loader-context.d.ts +5 -2
  88. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
  89. package/dist/lib/loader-utils/loader-context.js +3 -3
  90. package/dist/lib/loader-utils/loggers.d.ts +10 -8
  91. package/dist/lib/loader-utils/loggers.d.ts.map +1 -1
  92. package/dist/lib/loader-utils/option-utils.d.ts +1 -1
  93. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  94. package/dist/lib/loader-utils/option-utils.js +7 -5
  95. package/dist/lib/progress/fetch-progress.d.ts +1 -1
  96. package/dist/lib/progress/fetch-progress.d.ts.map +1 -1
  97. package/dist/lib/progress/fetch-progress.js +2 -1
  98. package/dist/null-worker-node.js +9 -4
  99. package/dist/null-worker.js +9 -4
  100. package/package.json +4 -4
  101. package/src/index.ts +4 -5
  102. package/src/iterators/make-stream/make-node-stream.ts +5 -2
  103. package/src/lib/api/load-in-batches.ts +4 -4
  104. package/src/lib/api/load.ts +22 -11
  105. package/src/lib/api/parse-in-batches.ts +7 -7
  106. package/src/lib/api/parse-sync.ts +6 -7
  107. package/src/lib/api/parse.ts +11 -7
  108. package/src/lib/api/save.ts +2 -2
  109. package/src/lib/api/select-loader.ts +24 -13
  110. package/src/lib/filesystems/browser-filesystem.ts +5 -5
  111. package/src/lib/init.ts +1 -0
  112. package/src/lib/loader-utils/get-data.ts +1 -0
  113. package/src/lib/loader-utils/loader-context.ts +8 -5
  114. package/src/lib/loader-utils/loggers.ts +10 -8
  115. package/src/lib/loader-utils/option-utils.ts +23 -14
  116. package/src/lib/progress/fetch-progress.ts +10 -2
  117. package/src/null-loader.ts +1 -1
  118. package/dist/es5/lib/filesystems/filesystem.js +0 -2
  119. package/dist/es5/lib/filesystems/filesystem.js.map +0 -1
  120. package/dist/esm/lib/filesystems/filesystem.js +0 -2
  121. package/dist/esm/lib/filesystems/filesystem.js.map +0 -1
  122. package/dist/lib/filesystems/filesystem.d.ts +0 -46
  123. package/dist/lib/filesystems/filesystem.d.ts.map +0 -1
  124. package/dist/lib/filesystems/filesystem.js +0 -2
  125. package/src/lib/filesystems/filesystem.ts +0 -49
@@ -1,7 +1,8 @@
1
+ // loaders.gl, MIT license
2
+
1
3
  import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
2
4
  import type {LoaderContext, SyncDataType} from '@loaders.gl/loader-utils';
3
5
  import type {LoaderOptionsType, LoaderReturnType} from '@loaders.gl/loader-utils';
4
- import {assert} from '@loaders.gl/loader-utils';
5
6
  import {selectLoaderSync} from './select-loader';
6
7
  import {isLoaderObject} from '../loader-utils/normalize-loader';
7
8
  import {normalizeOptions} from '../loader-utils/option-utils';
@@ -32,12 +33,12 @@ export function parseSync(
32
33
  loaders: Loader[],
33
34
  options?: LoaderOptions,
34
35
  context?: LoaderContext
35
- ): any;
36
+ ): unknown;
36
37
 
37
38
  /**
38
39
  * Parses `data` synchronously by matching a pre=registered loader
39
40
  */
40
- export function parseSync(data: SyncDataType, options?: LoaderOptions): any;
41
+ export function parseSync(data: SyncDataType, options?: LoaderOptions): unknown;
41
42
 
42
43
  /**
43
44
  * Parses `data` synchronously using a specified loader
@@ -48,8 +49,6 @@ export function parseSync(
48
49
  options?: LoaderOptions,
49
50
  context?: LoaderContext
50
51
  ): unknown {
51
- assert(!context || typeof context === 'object'); // parseSync no longer accepts final url
52
-
53
52
  // Signature: parseSync(data, options)
54
53
  // Uses registered loaders
55
54
  if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
@@ -71,7 +70,7 @@ export function parseSync(
71
70
  }
72
71
 
73
72
  // Normalize options
74
- options = normalizeOptions(options, loader, candidateLoaders);
73
+ options = normalizeOptions(options, loader, candidateLoaders as Loader[] | undefined);
75
74
 
76
75
  // Extract a url for auto detection
77
76
  const url = getResourceUrl(data);
@@ -80,7 +79,7 @@ export function parseSync(
80
79
  throw new Error('parseSync called parse (which is async');
81
80
  };
82
81
  context = getLoaderContext(
83
- {url, parseSync, parse, loaders: loaders as Loader[]},
82
+ {url, _parseSync: parse, _parse: parse, loaders: loaders as Loader[]},
84
83
  options,
85
84
  context || null
86
85
  );
@@ -16,7 +16,7 @@ import {selectLoader} from './select-loader';
16
16
  // type LoaderArrayType<T> = T extends (infer Loader)[] ? LoaderOptionsType<Loader> : T
17
17
 
18
18
  /**
19
- * Parses `data` asynchronously using the supplied loaders
19
+ * Parses `data` asynchronously using the supplied loader
20
20
  */
21
21
  export async function parse<
22
22
  LoaderT extends Loader,
@@ -29,14 +29,14 @@ export async function parse<
29
29
  ): Promise<LoaderReturnType<LoaderT>>;
30
30
 
31
31
  /**
32
- * Parses `data` asynchronously by matching one of the supplied loaders
32
+ * Parses `data` asynchronously by matching one of the supplied loader
33
33
  */
34
34
  export async function parse(
35
35
  data: DataType | Promise<DataType>,
36
36
  loaders: Loader[],
37
37
  options?: LoaderOptions,
38
38
  context?: LoaderContext
39
- ): Promise<any>;
39
+ ): Promise<unknown>;
40
40
 
41
41
  /**
42
42
  * Parses data asynchronously by matching a pre-registered loader
@@ -44,7 +44,7 @@ export async function parse(
44
44
  export async function parse(
45
45
  data: DataType | Promise<DataType>,
46
46
  options?: LoaderOptions
47
- ): Promise<any>;
47
+ ): Promise<unknown>;
48
48
 
49
49
  /**
50
50
  * Parses `data` using a specified loader
@@ -60,8 +60,6 @@ export async function parse(
60
60
  options?: LoaderOptions,
61
61
  context?: LoaderContext
62
62
  ): Promise<unknown> {
63
- assert(!context || typeof context === 'object'); // parse no longer accepts final url
64
-
65
63
  // Signature: parse(data, options, context | url)
66
64
  // Uses registered loaders
67
65
  if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
@@ -88,10 +86,16 @@ export async function parse(
88
86
  }
89
87
 
90
88
  // Normalize options
89
+ // @ts-expect-error
91
90
  options = normalizeOptions(options, loader, candidateLoaders, url); // Could be invalid...
92
91
 
93
92
  // Get a context (if already present, will be unchanged)
94
- context = getLoaderContext({url, parse, loaders: candidateLoaders}, options, context || null);
93
+ context = getLoaderContext(
94
+ // @ts-expect-error
95
+ {url, _parse: parse, loaders: candidateLoaders},
96
+ options,
97
+ context || null
98
+ );
95
99
 
96
100
  return await parseWithLoader(loader, data, options, context);
97
101
  }
@@ -2,12 +2,12 @@ import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
2
2
  import {encode, encodeSync} from './encode';
3
3
  import {writeFile, writeFileSync} from '../fetch/write-file';
4
4
 
5
- export async function save(data, url, writer: Writer, options: WriterOptions) {
5
+ export async function save(data: unknown, url: string, writer: Writer, options: WriterOptions) {
6
6
  const encodedData = await encode(data, writer, options);
7
7
  return await writeFile(url, encodedData);
8
8
  }
9
9
 
10
- export function saveSync(data, url, writer, options) {
10
+ export function saveSync(data: unknown, url: string, writer: Writer, options: WriterOptions) {
11
11
  const encodedData = encodeSync(data, writer, options);
12
12
  return writeFileSync(url, encodedData);
13
13
  }
@@ -6,6 +6,7 @@ import {getResourceUrl, getResourceMIMEType} from '../utils/resource-utils';
6
6
  import {getRegisteredLoaders} from './register-loaders';
7
7
  import {isBlob} from '../../javascript-utils/is-type';
8
8
  import {stripQueryString} from '../utils/url-utils';
9
+ import {TypedArray} from '@loaders.gl/schema';
9
10
 
10
11
  const EXT_PATTERN = /\.([^.]+)$/;
11
12
 
@@ -135,12 +136,16 @@ function selectLoaderInternal(
135
136
  reason = reason || (loader ? `matched MIME type ${type}` : '');
136
137
 
137
138
  // Look for loader via initial bytes (Note: not always accessible (e.g. Response, stream, async iterator)
139
+ // @ts-ignore Blob | Response
138
140
  loader = loader || findLoaderByInitialBytes(loaders, data);
141
+ // @ts-ignore Blob | Response
139
142
  reason = reason || (loader ? `matched initial data ${getFirstCharacters(data)}` : '');
140
143
 
141
144
  // Look up loader by fallback mime type
142
- loader = loader || findLoaderByMIMEType(loaders, options?.fallbackMimeType);
143
- reason = reason || (loader ? `matched fallback MIME type ${type}` : '');
145
+ if (options?.fallbackMimeType) {
146
+ loader = loader || findLoaderByMIMEType(loaders, options?.fallbackMimeType);
147
+ reason = reason || (loader ? `matched fallback MIME type ${type}` : '');
148
+ }
144
149
 
145
150
  if (reason) {
146
151
  log.log(1, `selectLoader selected ${loader?.name}: ${reason}.`);
@@ -150,7 +155,7 @@ function selectLoaderInternal(
150
155
  }
151
156
 
152
157
  /** Check HTTP Response */
153
- function validHTTPResponse(data: any): boolean {
158
+ function validHTTPResponse(data: unknown): boolean {
154
159
  // HANDLE HTTP status
155
160
  if (data instanceof Response) {
156
161
  // 204 - NO CONTENT. This handles cases where e.g. a tile server responds with 204 for a missing tile
@@ -162,7 +167,7 @@ function validHTTPResponse(data: any): boolean {
162
167
  }
163
168
 
164
169
  /** Generate a helpful message to help explain why loader selection failed. */
165
- function getNoValidLoaderMessage(data): string {
170
+ function getNoValidLoaderMessage(data: string | ArrayBuffer | Response | Blob): string {
166
171
  const url = getResourceUrl(data);
167
172
  const type = getResourceMIMEType(data);
168
173
 
@@ -170,6 +175,7 @@ function getNoValidLoaderMessage(data): string {
170
175
  message += url ? `${path.filename(url)}, ` : 'no url provided, ';
171
176
  message += `MIME type: ${type ? `"${type}"` : 'not provided'}, `;
172
177
  // First characters are only accessible when called on data (string or arrayBuffer).
178
+ // @ts-ignore Blob | Response
173
179
  const firstCharacters: string = data ? getFirstCharacters(data) : '';
174
180
  message += firstCharacters ? ` first bytes: "${firstCharacters}"` : 'first bytes: not available';
175
181
  message += ')';
@@ -204,7 +210,7 @@ function findLoaderByExtension(loaders: Loader[], extension: string): Loader | n
204
210
  return null;
205
211
  }
206
212
 
207
- function findLoaderByMIMEType(loaders, mimeType) {
213
+ function findLoaderByMIMEType(loaders: Loader[], mimeType: string): Loader | null {
208
214
  for (const loader of loaders) {
209
215
  if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
210
216
  return loader;
@@ -219,7 +225,7 @@ function findLoaderByMIMEType(loaders, mimeType) {
219
225
  return null;
220
226
  }
221
227
 
222
- function findLoaderByInitialBytes(loaders, data) {
228
+ function findLoaderByInitialBytes(loaders: Loader[], data: string | ArrayBuffer): Loader | null {
223
229
  if (!data) {
224
230
  return null;
225
231
  }
@@ -245,27 +251,32 @@ function findLoaderByInitialBytes(loaders, data) {
245
251
  return null;
246
252
  }
247
253
 
248
- function testDataAgainstText(data, loader) {
254
+ function testDataAgainstText(data: string, loader: Loader): boolean {
249
255
  if (loader.testText) {
250
256
  return loader.testText(data);
251
257
  }
252
258
 
253
259
  const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
254
- return tests.some((test) => data.startsWith(test));
260
+ return tests.some((test) => data.startsWith(test as string));
255
261
  }
256
262
 
257
- function testDataAgainstBinary(data, byteOffset, loader) {
263
+ function testDataAgainstBinary(data: ArrayBuffer, byteOffset: number, loader: Loader): boolean {
258
264
  const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
259
265
  return tests.some((test) => testBinary(data, byteOffset, loader, test));
260
266
  }
261
267
 
262
- function testBinary(data, byteOffset, loader, test) {
268
+ function testBinary(
269
+ data: ArrayBuffer,
270
+ byteOffset: number,
271
+ loader: Loader,
272
+ test?: ArrayBuffer | string | ((b: ArrayBuffer) => boolean)
273
+ ): boolean {
263
274
  if (test instanceof ArrayBuffer) {
264
275
  return compareArrayBuffers(test, data, test.byteLength);
265
276
  }
266
277
  switch (typeof test) {
267
278
  case 'function':
268
- return test(data, loader);
279
+ return test(data);
269
280
 
270
281
  case 'string':
271
282
  // Magic bytes check: If `test` is a string, check if binary data starts with that strings
@@ -277,7 +288,7 @@ function testBinary(data, byteOffset, loader, test) {
277
288
  }
278
289
  }
279
290
 
280
- function getFirstCharacters(data, length: number = 5) {
291
+ function getFirstCharacters(data: string | ArrayBuffer | TypedArray, length: number = 5) {
281
292
  if (typeof data === 'string') {
282
293
  return data.slice(0, length);
283
294
  } else if (ArrayBuffer.isView(data)) {
@@ -290,7 +301,7 @@ function getFirstCharacters(data, length: number = 5) {
290
301
  return '';
291
302
  }
292
303
 
293
- function getMagicString(arrayBuffer, byteOffset, length) {
304
+ function getMagicString(arrayBuffer: ArrayBuffer, byteOffset: number, length: number): string {
294
305
  if (arrayBuffer.byteLength < byteOffset + length) {
295
306
  return '';
296
307
  }
@@ -1,4 +1,4 @@
1
- import type {FileSystem} from './filesystem';
1
+ import type {FileSystem} from '@loaders.gl/loader-utils';
2
2
 
3
3
  type BrowserFileSystemOptions = {
4
4
  fetch?: typeof fetch;
@@ -8,7 +8,7 @@ type BrowserFileSystemOptions = {
8
8
  * FileSystem adapter for a browser FileList.
9
9
  * Holds a list of browser 'File' objects.
10
10
  */
11
- export default class BrowserFileSystem implements FileSystem {
11
+ export class BrowserFileSystem implements FileSystem {
12
12
  private _fetch: typeof fetch;
13
13
  private files: {[filename: string]: File} = {};
14
14
  private lowerCaseFiles: {[filename: string]: File} = {};
@@ -109,7 +109,7 @@ export default class BrowserFileSystem implements FileSystem {
109
109
  // implements IRandomAccessFileSystem
110
110
 
111
111
  // RANDOM ACCESS
112
- async open(pathname: string, flags, mode?): Promise<any> {
112
+ async open(pathname: string, flags: unknown, mode?: unknown): Promise<any> {
113
113
  return this.files[pathname];
114
114
  }
115
115
 
@@ -144,8 +144,8 @@ export default class BrowserFileSystem implements FileSystem {
144
144
  // PRIVATE
145
145
 
146
146
  // Supports case independent paths, and file usage tracking
147
- _getFile(path, used) {
148
- // Prefer case match, but fall back to case indepent.
147
+ _getFile(path: string, used: boolean): File {
148
+ // Prefer case match, but fall back to case independent.
149
149
  const file = this.files[path] || this.lowerCaseFiles[path];
150
150
  if (file && used) {
151
151
  this.usedFiles[path] = true;
package/src/lib/init.ts CHANGED
@@ -8,6 +8,7 @@ const version = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '';
8
8
  if (!globalThis.loaders) {
9
9
  log.log(1, `loaders.gl ${version}`)();
10
10
 
11
+ // @ts-ignore TS2339: Property 'loaders' does not exist on type 'Window & typeof globalThis'.
11
12
  globalThis.loaders = Object.assign(globalThis.loaders || {}, {
12
13
  VERSION: version,
13
14
  log
@@ -127,6 +127,7 @@ export async function getAsyncIterableFromData(
127
127
  }
128
128
 
129
129
  if (isAsyncIterable(data)) {
130
+ // @ts-ignore
130
131
  return data[Symbol.asyncIterator]();
131
132
  }
132
133
 
@@ -3,6 +3,9 @@ import {getFetchFunction} from './get-fetch-function';
3
3
  import {extractQueryString, stripQueryString} from '../utils/url-utils';
4
4
  import {path} from '@loaders.gl/loader-utils';
5
5
 
6
+ /** Properties for creating an updated context */
7
+ type LoaderContextProps = Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>;
8
+
6
9
  /**
7
10
  * "sub" loaders invoked by other loaders get a "context" injected on `this`
8
11
  * The context will inject core methods like `parse` and contain information
@@ -13,7 +16,7 @@ import {path} from '@loaders.gl/loader-utils';
13
16
  * @param previousContext
14
17
  */
15
18
  export function getLoaderContext(
16
- context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>,
19
+ context: LoaderContextProps,
17
20
  options: LoaderOptions,
18
21
  parentContext: LoaderContext | null
19
22
  ): LoaderContext {
@@ -49,9 +52,9 @@ export function getLoaderContext(
49
52
  export function getLoadersFromContext(
50
53
  loaders: Loader[] | Loader | undefined,
51
54
  context?: LoaderContext
52
- ) {
53
- // A single non-array loader is force selected, but only on top-level (context === null)
54
- if (!context && loaders && !Array.isArray(loaders)) {
55
+ ): Loader | Loader[] | undefined {
56
+ // A single loader (non-array) indicates no selection desired. Force select.
57
+ if (loaders && !Array.isArray(loaders)) {
55
58
  return loaders;
56
59
  }
57
60
 
@@ -65,5 +68,5 @@ export function getLoadersFromContext(
65
68
  candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
66
69
  }
67
70
  // If no loaders, return null to look in globally registered loaders
68
- return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;
71
+ return candidateLoaders && candidateLoaders.length ? candidateLoaders : undefined;
69
72
  }
@@ -3,18 +3,20 @@ import {Log} from '@probe.gl/log';
3
3
 
4
4
  export const probeLog = new Log({id: 'loaders.gl'});
5
5
 
6
+ type LogFunction = () => void;
7
+
6
8
  // Logs nothing
7
9
  export class NullLog {
8
- log() {
10
+ log(): LogFunction {
9
11
  return () => {};
10
12
  }
11
- info() {
13
+ info(): LogFunction {
12
14
  return () => {};
13
15
  }
14
- warn() {
16
+ warn(): LogFunction {
15
17
  return () => {};
16
18
  }
17
- error() {
19
+ error(): LogFunction {
18
20
  return () => {};
19
21
  }
20
22
  }
@@ -26,16 +28,16 @@ export class ConsoleLog {
26
28
  constructor() {
27
29
  this.console = console; // eslint-disable-line
28
30
  }
29
- log(...args) {
31
+ log(...args: unknown[]): LogFunction {
30
32
  return this.console.log.bind(this.console, ...args);
31
33
  }
32
- info(...args) {
34
+ info(...args: unknown[]): LogFunction {
33
35
  return this.console.info.bind(this.console, ...args);
34
36
  }
35
- warn(...args) {
37
+ warn(...args: unknown[]): LogFunction {
36
38
  return this.console.warn.bind(this.console, ...args);
37
39
  }
38
- error(...args) {
40
+ error(...args: unknown[]): LogFunction {
39
41
  return this.console.error.bind(this.console, ...args);
40
42
  }
41
43
  }
@@ -33,12 +33,12 @@ export function getGlobalLoaderState(): GlobalLoaderState {
33
33
  * NOTE: This use case is not reliable but can help when testing new versions of loaders.gl with existing frameworks
34
34
  * @returns global loader options merged with default loader options
35
35
  */
36
- export const getGlobalLoaderOptions = (): LoaderOptions => {
36
+ export function getGlobalLoaderOptions(): LoaderOptions {
37
37
  const state = getGlobalLoaderState();
38
38
  // Ensure all default loader options from this library are mentioned
39
39
  state.globalOptions = state.globalOptions || {...DEFAULT_LOADER_OPTIONS};
40
40
  return state.globalOptions;
41
- };
41
+ }
42
42
 
43
43
  /**
44
44
  * Set global loader options
@@ -47,6 +47,7 @@ export const getGlobalLoaderOptions = (): LoaderOptions => {
47
47
  export function setGlobalOptions(options: LoaderOptions): void {
48
48
  const state = getGlobalLoaderState();
49
49
  const globalOptions = getGlobalLoaderOptions();
50
+ // @ts-expect-error First param looks incorrect
50
51
  state.globalOptions = normalizeOptionsInternal(globalOptions, options);
51
52
  }
52
53
 
@@ -77,12 +78,15 @@ export function normalizeOptions(
77
78
  * @param options
78
79
  * @param loaders
79
80
  */
80
- function validateOptions(options: LoaderOptions, loaders: Loader[]) {
81
+ function validateOptions(options: LoaderOptions, loaders: Loader[]): void {
81
82
  // Check top level options
82
83
  validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);
83
84
  for (const loader of loaders) {
84
85
  // Get the scoped, loader specific options from the user supplied options
85
- const idOptions = (options && options[loader.id]) || {};
86
+ const idOptions: Record<string, unknown> = ((options && options[loader.id]) || {}) as Record<
87
+ string,
88
+ unknown
89
+ >;
86
90
 
87
91
  // Get scoped, loader specific default and deprecated options from the selected loader
88
92
  const loaderOptions = (loader.options && loader.options[loader.id]) || {};
@@ -90,18 +94,19 @@ function validateOptions(options: LoaderOptions, loaders: Loader[]) {
90
94
  (loader.deprecatedOptions && loader.deprecatedOptions[loader.id]) || {};
91
95
 
92
96
  // Validate loader specific options
97
+ // @ts-ignore
93
98
  validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
94
99
  }
95
100
  }
96
101
 
97
102
  // eslint-disable-next-line max-params, complexity
98
103
  function validateOptionsObject(
99
- options,
104
+ options: LoaderOptions,
100
105
  id: string | null,
101
- defaultOptions,
102
- deprecatedOptions,
106
+ defaultOptions: Record<string, unknown>,
107
+ deprecatedOptions: Record<string, unknown>,
103
108
  loaders: Loader[]
104
- ) {
109
+ ): void {
105
110
  const loaderName = id || 'Top level';
106
111
  const prefix = id ? `${id}.` : '';
107
112
 
@@ -127,7 +132,7 @@ function validateOptionsObject(
127
132
  }
128
133
  }
129
134
 
130
- function findSimilarOption(optionKey, loaders) {
135
+ function findSimilarOption(optionKey: string, loaders: Loader[]): string {
131
136
  const lowerCaseOptionKey = optionKey.toLowerCase();
132
137
  let bestSuggestion = '';
133
138
  for (const loader of loaders) {
@@ -146,7 +151,11 @@ function findSimilarOption(optionKey, loaders) {
146
151
  return bestSuggestion;
147
152
  }
148
153
 
149
- function normalizeOptionsInternal(loader, options, url?: string) {
154
+ function normalizeOptionsInternal(
155
+ loader: Loader,
156
+ options: LoaderOptions,
157
+ url?: string
158
+ ): LoaderOptions {
150
159
  const loaderDefaultOptions = loader.options || {};
151
160
 
152
161
  const mergedOptions = {...loaderDefaultOptions};
@@ -165,7 +174,7 @@ function normalizeOptionsInternal(loader, options, url?: string) {
165
174
  }
166
175
 
167
176
  // Merge nested options objects
168
- function mergeNestedFields(mergedOptions, options) {
177
+ function mergeNestedFields(mergedOptions: LoaderOptions, options: LoaderOptions): void {
169
178
  for (const key in options) {
170
179
  // Check for nested options
171
180
  // object in options => either no key in defaultOptions or object in defaultOptions
@@ -173,8 +182,8 @@ function mergeNestedFields(mergedOptions, options) {
173
182
  const value = options[key];
174
183
  if (isPureObject(value) && isPureObject(mergedOptions[key])) {
175
184
  mergedOptions[key] = {
176
- ...mergedOptions[key],
177
- ...options[key]
185
+ ...(mergedOptions[key] as object),
186
+ ...(options[key] as object)
178
187
  };
179
188
  } else {
180
189
  mergedOptions[key] = options[key];
@@ -192,7 +201,7 @@ function mergeNestedFields(mergedOptions, options) {
192
201
  * TODO - extract query parameters?
193
202
  * TODO - should these be injected on context instead of options?
194
203
  */
195
- function addUrlOptions(options, url?: string) {
204
+ function addUrlOptions(options: LoaderOptions, url?: string): void {
196
205
  if (url && !('baseUri' in options)) {
197
206
  options.baseUri = url;
198
207
  }
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Intercepts the Response stream and creates a new Response
5
5
  */
6
- export default async function fetchProgress(
6
+ export async function fetchProgress(
7
7
  response: Response | Promise<Response>,
8
8
  onProgress: any, // TODO better callback types
9
9
  onDone = () => {},
@@ -43,7 +43,15 @@ export default async function fetchProgress(
43
43
  // Forward to original streams controller
44
44
  // TODO - this causes a crazy deep "async stack"... rewrite as async iterator?
45
45
  // eslint-disable-next-line max-params
46
- async function read(controller, reader, loadedBytes, totalBytes, onProgress, onDone, onError) {
46
+ async function read(
47
+ controller: any,
48
+ reader: any,
49
+ loadedBytes: number,
50
+ totalBytes: number,
51
+ onProgress: Function,
52
+ onDone: Function,
53
+ onError: Function
54
+ ): Promise<void> {
47
55
  try {
48
56
  const {done, value} = await reader.read();
49
57
  if (done) {
@@ -3,7 +3,7 @@
3
3
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
4
4
 
5
5
  import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
6
- import {LoaderContext} from 'modules/loader-utils/dist';
6
+ import {LoaderContext} from '@loaders.gl/loader-utils';
7
7
 
8
8
  export type NullLoaderOptions = LoaderOptions & {
9
9
  null?: {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=filesystem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filesystem.js","names":[],"sources":["../../../../src/lib/filesystems/filesystem.ts"],"sourcesContent":["export type ReadOptions = {};\n\nexport type Stat = {\n size: number;\n isDirectory: () => boolean;\n};\n\n/**\n * A FileSystem interface can encapsulate various file sources,\n * a FileList, a ZipFile, a GoogleDrive etc.\n */\nexport interface FileSystem {\n /**\n * Return a list of file names\n * @param dirname directory name. file system root directory if omitted\n */\n readdir(dirname?: string, options?: {recursive?: boolean}): Promise<string[]>;\n\n /**\n * Gets information from a local file from the filesystem\n * @param filename file name to stat\n * @param options currently unused\n * @throws if filename is not in local filesystem\n */\n stat(filename: string, options?: object): Promise<{size: number}>;\n\n /**\n * Fetches a local file from the filesystem (or a URL)\n * @param filename\n * @param options\n */\n fetch(filename: RequestInfo, options?: RequestInit): Promise<Response>;\n}\n\n/**\n * A random access file system\n */\nexport interface RandomAccessReadFileSystem extends FileSystem {\n open(path: string, flags: unknown, mode?: unknown): Promise<any>;\n close(fd: unknown): Promise<void>;\n fstat(fd: unknown): Promise<Stat>;\n read(\n fd: any,\n buffer: ArrayBuffer | ArrayBufferView,\n offset?: number,\n length?: number,\n position?: number\n ): Promise<{bytesRead: number; buffer: ArrayBuffer}>;\n}\n"],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=filesystem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filesystem.js","names":[],"sources":["../../../../src/lib/filesystems/filesystem.ts"],"sourcesContent":["export type ReadOptions = {};\n\nexport type Stat = {\n size: number;\n isDirectory: () => boolean;\n};\n\n/**\n * A FileSystem interface can encapsulate various file sources,\n * a FileList, a ZipFile, a GoogleDrive etc.\n */\nexport interface FileSystem {\n /**\n * Return a list of file names\n * @param dirname directory name. file system root directory if omitted\n */\n readdir(dirname?: string, options?: {recursive?: boolean}): Promise<string[]>;\n\n /**\n * Gets information from a local file from the filesystem\n * @param filename file name to stat\n * @param options currently unused\n * @throws if filename is not in local filesystem\n */\n stat(filename: string, options?: object): Promise<{size: number}>;\n\n /**\n * Fetches a local file from the filesystem (or a URL)\n * @param filename\n * @param options\n */\n fetch(filename: RequestInfo, options?: RequestInit): Promise<Response>;\n}\n\n/**\n * A random access file system\n */\nexport interface RandomAccessReadFileSystem extends FileSystem {\n open(path: string, flags: unknown, mode?: unknown): Promise<any>;\n close(fd: unknown): Promise<void>;\n fstat(fd: unknown): Promise<Stat>;\n read(\n fd: any,\n buffer: ArrayBuffer | ArrayBufferView,\n offset?: number,\n length?: number,\n position?: number\n ): Promise<{bytesRead: number; buffer: ArrayBuffer}>;\n}\n"],"mappings":""}
@@ -1,46 +0,0 @@
1
- export type ReadOptions = {};
2
- export type Stat = {
3
- size: number;
4
- isDirectory: () => boolean;
5
- };
6
- /**
7
- * A FileSystem interface can encapsulate various file sources,
8
- * a FileList, a ZipFile, a GoogleDrive etc.
9
- */
10
- export interface FileSystem {
11
- /**
12
- * Return a list of file names
13
- * @param dirname directory name. file system root directory if omitted
14
- */
15
- readdir(dirname?: string, options?: {
16
- recursive?: boolean;
17
- }): Promise<string[]>;
18
- /**
19
- * Gets information from a local file from the filesystem
20
- * @param filename file name to stat
21
- * @param options currently unused
22
- * @throws if filename is not in local filesystem
23
- */
24
- stat(filename: string, options?: object): Promise<{
25
- size: number;
26
- }>;
27
- /**
28
- * Fetches a local file from the filesystem (or a URL)
29
- * @param filename
30
- * @param options
31
- */
32
- fetch(filename: RequestInfo, options?: RequestInit): Promise<Response>;
33
- }
34
- /**
35
- * A random access file system
36
- */
37
- export interface RandomAccessReadFileSystem extends FileSystem {
38
- open(path: string, flags: unknown, mode?: unknown): Promise<any>;
39
- close(fd: unknown): Promise<void>;
40
- fstat(fd: unknown): Promise<Stat>;
41
- read(fd: any, buffer: ArrayBuffer | ArrayBufferView, offset?: number, length?: number, position?: number): Promise<{
42
- bytesRead: number;
43
- buffer: ArrayBuffer;
44
- }>;
45
- }
46
- //# sourceMappingURL=filesystem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../../src/lib/filesystems/filesystem.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,EAAE,CAAC;AAE7B,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAE9E;;;;;OAKG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC,CAAC,CAAC;IAElE;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxE;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,UAAU;IAC5D,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,KAAK,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,CACF,EAAE,EAAE,GAAG,EACP,MAAM,EAAE,WAAW,GAAG,eAAe,EACrC,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAC,CAAC,CAAC;CACtD"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,49 +0,0 @@
1
- export type ReadOptions = {};
2
-
3
- export type Stat = {
4
- size: number;
5
- isDirectory: () => boolean;
6
- };
7
-
8
- /**
9
- * A FileSystem interface can encapsulate various file sources,
10
- * a FileList, a ZipFile, a GoogleDrive etc.
11
- */
12
- export interface FileSystem {
13
- /**
14
- * Return a list of file names
15
- * @param dirname directory name. file system root directory if omitted
16
- */
17
- readdir(dirname?: string, options?: {recursive?: boolean}): Promise<string[]>;
18
-
19
- /**
20
- * Gets information from a local file from the filesystem
21
- * @param filename file name to stat
22
- * @param options currently unused
23
- * @throws if filename is not in local filesystem
24
- */
25
- stat(filename: string, options?: object): Promise<{size: number}>;
26
-
27
- /**
28
- * Fetches a local file from the filesystem (or a URL)
29
- * @param filename
30
- * @param options
31
- */
32
- fetch(filename: RequestInfo, options?: RequestInit): Promise<Response>;
33
- }
34
-
35
- /**
36
- * A random access file system
37
- */
38
- export interface RandomAccessReadFileSystem extends FileSystem {
39
- open(path: string, flags: unknown, mode?: unknown): Promise<any>;
40
- close(fd: unknown): Promise<void>;
41
- fstat(fd: unknown): Promise<Stat>;
42
- read(
43
- fd: any,
44
- buffer: ArrayBuffer | ArrayBufferView,
45
- offset?: number,
46
- length?: number,
47
- position?: number
48
- ): Promise<{bytesRead: number; buffer: ArrayBuffer}>;
49
- }