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

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 (100) hide show
  1. package/dist/dist.min.js +15 -18
  2. package/dist/es5/index.js +0 -7
  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/parse-in-batches.js +11 -13
  6. package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
  7. package/dist/es5/lib/api/parse-sync.js +2 -6
  8. package/dist/es5/lib/api/parse-sync.js.map +1 -1
  9. package/dist/es5/lib/api/parse.js +10 -12
  10. package/dist/es5/lib/api/parse.js.map +1 -1
  11. package/dist/es5/lib/api/save.js.map +1 -1
  12. package/dist/es5/lib/api/select-loader.js +5 -3
  13. package/dist/es5/lib/api/select-loader.js.map +1 -1
  14. package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
  15. package/dist/es5/lib/filesystems/filesystem.js.map +1 -1
  16. package/dist/es5/lib/init.js +1 -1
  17. package/dist/es5/lib/init.js.map +1 -1
  18. package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
  19. package/dist/es5/lib/loader-utils/loader-context.js +2 -2
  20. package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
  21. package/dist/es5/lib/loader-utils/loggers.js.map +1 -1
  22. package/dist/es5/lib/loader-utils/option-utils.js +3 -4
  23. package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
  24. package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
  25. package/dist/es5/null-loader.js +1 -1
  26. package/dist/es5/null-loader.js.map +1 -1
  27. package/dist/esm/index.js +0 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -1
  30. package/dist/esm/lib/api/parse-in-batches.js +3 -4
  31. package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
  32. package/dist/esm/lib/api/parse-sync.js +2 -4
  33. package/dist/esm/lib/api/parse-sync.js.map +1 -1
  34. package/dist/esm/lib/api/parse.js +1 -2
  35. package/dist/esm/lib/api/parse.js.map +1 -1
  36. package/dist/esm/lib/api/save.js.map +1 -1
  37. package/dist/esm/lib/api/select-loader.js +5 -3
  38. package/dist/esm/lib/api/select-loader.js.map +1 -1
  39. package/dist/esm/lib/filesystems/browser-filesystem.js.map +1 -1
  40. package/dist/esm/lib/filesystems/filesystem.js.map +1 -1
  41. package/dist/esm/lib/init.js +1 -1
  42. package/dist/esm/lib/init.js.map +1 -1
  43. package/dist/esm/lib/loader-utils/get-data.js.map +1 -1
  44. package/dist/esm/lib/loader-utils/loader-context.js +2 -2
  45. package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
  46. package/dist/esm/lib/loader-utils/loggers.js.map +1 -1
  47. package/dist/esm/lib/loader-utils/option-utils.js +2 -2
  48. package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
  49. package/dist/esm/lib/progress/fetch-progress.js.map +1 -1
  50. package/dist/esm/null-loader.js +1 -1
  51. package/dist/esm/null-loader.js.map +1 -1
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/iterators/make-stream/make-node-stream.d.ts.map +1 -1
  55. package/dist/iterators/make-stream/make-node-stream.js +5 -2
  56. package/dist/lib/api/parse-in-batches.js +1 -2
  57. package/dist/lib/api/parse-sync.d.ts.map +1 -1
  58. package/dist/lib/api/parse-sync.js +2 -3
  59. package/dist/lib/api/parse.d.ts +2 -2
  60. package/dist/lib/api/parse.js +4 -2
  61. package/dist/lib/api/save.d.ts +2 -2
  62. package/dist/lib/api/save.d.ts.map +1 -1
  63. package/dist/lib/api/select-loader.d.ts.map +1 -1
  64. package/dist/lib/api/select-loader.js +8 -3
  65. package/dist/lib/filesystems/browser-filesystem.d.ts +2 -2
  66. package/dist/lib/filesystems/browser-filesystem.d.ts.map +1 -1
  67. package/dist/lib/filesystems/browser-filesystem.js +1 -1
  68. package/dist/lib/filesystems/filesystem.d.ts.map +1 -1
  69. package/dist/lib/filesystems/filesystem.js +1 -0
  70. package/dist/lib/init.d.ts.map +1 -1
  71. package/dist/lib/init.js +1 -0
  72. package/dist/lib/loader-utils/get-data.d.ts.map +1 -1
  73. package/dist/lib/loader-utils/get-data.js +1 -0
  74. package/dist/lib/loader-utils/loader-context.d.ts +5 -2
  75. package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
  76. package/dist/lib/loader-utils/loader-context.js +3 -3
  77. package/dist/lib/loader-utils/loggers.d.ts +10 -8
  78. package/dist/lib/loader-utils/loggers.d.ts.map +1 -1
  79. package/dist/lib/loader-utils/option-utils.d.ts +1 -1
  80. package/dist/lib/loader-utils/option-utils.d.ts.map +1 -1
  81. package/dist/lib/loader-utils/option-utils.js +7 -5
  82. package/dist/null-worker-node.js +9 -4
  83. package/dist/null-worker.js +9 -4
  84. package/package.json +4 -4
  85. package/src/index.ts +1 -1
  86. package/src/iterators/make-stream/make-node-stream.ts +5 -2
  87. package/src/lib/api/parse-in-batches.ts +5 -5
  88. package/src/lib/api/parse-sync.ts +4 -5
  89. package/src/lib/api/parse.ts +9 -5
  90. package/src/lib/api/save.ts +2 -2
  91. package/src/lib/api/select-loader.ts +24 -13
  92. package/src/lib/filesystems/browser-filesystem.ts +3 -3
  93. package/src/lib/filesystems/filesystem.ts +2 -0
  94. package/src/lib/init.ts +1 -0
  95. package/src/lib/loader-utils/get-data.ts +1 -0
  96. package/src/lib/loader-utils/loader-context.ts +8 -5
  97. package/src/lib/loader-utils/loggers.ts +10 -8
  98. package/src/lib/loader-utils/option-utils.ts +23 -14
  99. package/src/lib/progress/fetch-progress.ts +9 -1
  100. package/src/null-loader.ts +1 -1
@@ -143,7 +143,7 @@ function createLoaderWorker(loader) {
143
143
  arrayBuffer: input,
144
144
  options,
145
145
  context: __spreadProps(__spreadValues({}, context), {
146
- parse: parseOnMainThread
146
+ _parse: parseOnMainThread
147
147
  })
148
148
  });
149
149
  WorkerBody.postMessage("done", { result });
@@ -156,7 +156,7 @@ function createLoaderWorker(loader) {
156
156
  }
157
157
  };
158
158
  }
159
- function parseOnMainThread(arrayBuffer, options) {
159
+ function parseOnMainThread(arrayBuffer, loader, options, context) {
160
160
  return new Promise((resolve, reject) => {
161
161
  const id = requestId++;
162
162
  const onMessage = (type, payload2) => {
@@ -180,7 +180,12 @@ function parseOnMainThread(arrayBuffer, options) {
180
180
  WorkerBody.postMessage("process", payload);
181
181
  });
182
182
  }
183
- async function parseData({ loader, arrayBuffer, options, context }) {
183
+ async function parseData({
184
+ loader,
185
+ arrayBuffer,
186
+ options,
187
+ context
188
+ }) {
184
189
  let data;
185
190
  let parser;
186
191
  if (loader.parseSync || loader.parse) {
@@ -201,7 +206,7 @@ async function parseData({ loader, arrayBuffer, options, context }) {
201
206
  }
202
207
 
203
208
  // src/null-loader.ts
204
- var VERSION = true ? "4.0.0-alpha.21" : "latest";
209
+ var VERSION = true ? "4.0.0-alpha.22" : "latest";
205
210
  var NullLoader = {
206
211
  name: "Null loader",
207
212
  id: "null",
@@ -125,7 +125,7 @@
125
125
  options,
126
126
  context: {
127
127
  ...context,
128
- parse: parseOnMainThread
128
+ _parse: parseOnMainThread
129
129
  }
130
130
  });
131
131
  WorkerBody.postMessage("done", { result });
@@ -138,7 +138,7 @@
138
138
  }
139
139
  };
140
140
  }
141
- function parseOnMainThread(arrayBuffer, options) {
141
+ function parseOnMainThread(arrayBuffer, loader, options, context) {
142
142
  return new Promise((resolve, reject) => {
143
143
  const id = requestId++;
144
144
  const onMessage = (type, payload2) => {
@@ -162,7 +162,12 @@
162
162
  WorkerBody.postMessage("process", payload);
163
163
  });
164
164
  }
165
- async function parseData({ loader, arrayBuffer, options, context }) {
165
+ async function parseData({
166
+ loader,
167
+ arrayBuffer,
168
+ options,
169
+ context
170
+ }) {
166
171
  let data;
167
172
  let parser;
168
173
  if (loader.parseSync || loader.parse) {
@@ -184,7 +189,7 @@
184
189
  }
185
190
 
186
191
  // src/null-loader.ts
187
- var VERSION = true ? "4.0.0-alpha.21" : "latest";
192
+ var VERSION = true ? "4.0.0-alpha.22" : "latest";
188
193
  var NullLoader = {
189
194
  name: "Null loader",
190
195
  id: "null",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/core",
3
- "version": "4.0.0-alpha.21",
3
+ "version": "4.0.0-alpha.22",
4
4
  "description": "The core API for working with loaders.gl loaders and writers",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -47,9 +47,9 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@babel/runtime": "^7.3.1",
50
- "@loaders.gl/loader-utils": "4.0.0-alpha.21",
51
- "@loaders.gl/worker-utils": "4.0.0-alpha.21",
50
+ "@loaders.gl/loader-utils": "4.0.0-alpha.22",
51
+ "@loaders.gl/worker-utils": "4.0.0-alpha.22",
52
52
  "@probe.gl/log": "^4.0.2"
53
53
  },
54
- "gitHead": "df5d670b136192b26941396e944f9c46be788e83"
54
+ "gitHead": "0da838c506d1275383f2fd3d244d9c72b25397d2"
55
55
  }
package/src/index.ts CHANGED
@@ -55,7 +55,7 @@ export {JSONLoader} from '@loaders.gl/loader-utils';
55
55
  // EXPERIMENTAL
56
56
  export {default as _fetchProgress} from './lib/progress/fetch-progress';
57
57
  export {default as _BrowserFileSystem} from './lib/filesystems/browser-filesystem';
58
- export {FileSystem} from './lib/filesystems/filesystem';
58
+ export type {FileSystem} from './lib/filesystems/filesystem';
59
59
 
60
60
  // FOR TESTING
61
61
  export {_unregisterLoaders} from './lib/api/register-loaders';
@@ -13,9 +13,12 @@ export function makeStream<ArrayBuffer>(
13
13
  source: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>,
14
14
  options?: ReadableOptions
15
15
  ): ReadableType {
16
+ // @ts-ignore AsyncGenerator
16
17
  const iterator = source[Symbol.asyncIterator]
17
- ? source[Symbol.asyncIterator]()
18
- : source[Symbol.iterator]();
18
+ ? // @ts-ignore AsyncGenerator
19
+ source[Symbol.asyncIterator]()
20
+ : // @ts-ignore AsyncGenerator
21
+ source[Symbol.iterator]();
19
22
  return new AsyncIterableReadable(iterator, options);
20
23
  }
21
24
 
@@ -4,7 +4,7 @@ import type {Batch} from '@loaders.gl/schema';
4
4
  import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
5
5
  import type {LoaderContext, BatchableDataType} from '@loaders.gl/loader-utils';
6
6
  import type {LoaderBatchType, LoaderOptionsType} from '@loaders.gl/loader-utils';
7
- import {assert, concatenateArrayBuffersAsync} from '@loaders.gl/loader-utils';
7
+ import {concatenateArrayBuffersAsync} from '@loaders.gl/loader-utils';
8
8
  import {isLoaderObject} from '../loader-utils/normalize-loader';
9
9
  import {normalizeOptions} from '../loader-utils/option-utils';
10
10
  import {getLoaderContext} from '../loader-utils/loader-context';
@@ -59,8 +59,6 @@ export async function parseInBatches(
59
59
  options?: LoaderOptions,
60
60
  context?: LoaderContext
61
61
  ): Promise<AsyncIterable<unknown>> {
62
- assert(!context || typeof context === 'object'); // parseInBatches no longer accepts final url
63
-
64
62
  const loaderArray = Array.isArray(loaders) ? loaders : undefined;
65
63
 
66
64
  // Signature: parseInBatches(data, options, url) - Uses registered loaders
@@ -88,7 +86,7 @@ export async function parseInBatches(
88
86
  // Normalize options
89
87
  options = normalizeOptions(options, loader, loaderArray, url);
90
88
  context = getLoaderContext(
91
- {url, parseInBatches, parse, loaders: loaderArray},
89
+ {url, _parseInBatches: parseInBatches, _parse: parse, loaders: loaderArray},
92
90
  options,
93
91
  context || null
94
92
  );
@@ -123,7 +121,9 @@ async function parseWithLoaderInBatches(
123
121
  bytesUsed: 0
124
122
  };
125
123
 
126
- async function* makeMetadataBatchIterator(iterator) {
124
+ async function* makeMetadataBatchIterator(
125
+ iterator: Iterable<unknown> | AsyncIterable<unknown>
126
+ ): AsyncIterable<unknown> {
127
127
  yield metadataBatch;
128
128
  yield* iterator;
129
129
  }
@@ -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';
@@ -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,7 +29,7 @@ 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>,
@@ -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
  }
@@ -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;
@@ -1,3 +1,5 @@
1
+ // loaders.gl, MIT license
2
+
1
3
  export type ReadOptions = {};
2
4
 
3
5
  export type Stat = {
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
  }
@@ -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?: {};