@loaders.gl/loader-utils 4.0.0-alpha.20 → 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 (60) hide show
  1. package/dist/es5/index.js +19 -0
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/json-loader.js +1 -1
  4. package/dist/es5/json-loader.js.map +1 -1
  5. package/dist/es5/lib/option-utils/merge-loader-options.js.map +1 -1
  6. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js +2 -2
  7. package/dist/es5/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  8. package/dist/es5/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
  9. package/dist/es5/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  10. package/dist/es5/loader-types.js +58 -0
  11. package/dist/es5/loader-types.js.map +1 -0
  12. package/dist/es5/types.js.map +1 -1
  13. package/dist/es5/writer-types.js +2 -0
  14. package/dist/es5/writer-types.js.map +1 -0
  15. package/dist/esm/index.js +1 -0
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/json-loader.js +1 -1
  18. package/dist/esm/json-loader.js.map +1 -1
  19. package/dist/esm/lib/option-utils/merge-loader-options.js.map +1 -1
  20. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js +2 -2
  21. package/dist/esm/lib/worker-loader-utils/create-loader-worker.js.map +1 -1
  22. package/dist/esm/lib/worker-loader-utils/encode-with-worker.js.map +1 -1
  23. package/dist/esm/lib/worker-loader-utils/parse-with-worker.js.map +1 -1
  24. package/dist/esm/loader-types.js +16 -0
  25. package/dist/esm/loader-types.js.map +1 -0
  26. package/dist/esm/types.js.map +1 -1
  27. package/dist/esm/writer-types.js +2 -0
  28. package/dist/esm/writer-types.js.map +1 -0
  29. package/dist/index.d.ts +4 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +7 -2
  32. package/dist/json-loader.d.ts +1 -1
  33. package/dist/json-loader.d.ts.map +1 -1
  34. package/dist/lib/option-utils/merge-loader-options.d.ts +1 -1
  35. package/dist/lib/option-utils/merge-loader-options.d.ts.map +1 -1
  36. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts +1 -1
  37. package/dist/lib/worker-loader-utils/create-loader-worker.d.ts.map +1 -1
  38. package/dist/lib/worker-loader-utils/create-loader-worker.js +3 -2
  39. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts +1 -1
  40. package/dist/lib/worker-loader-utils/encode-with-worker.d.ts.map +1 -1
  41. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts +2 -2
  42. package/dist/lib/worker-loader-utils/parse-with-worker.d.ts.map +1 -1
  43. package/dist/loader-types.d.ts +208 -0
  44. package/dist/loader-types.d.ts.map +1 -0
  45. package/dist/loader-types.js +36 -0
  46. package/dist/types.d.ts +1 -200
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/writer-types.d.ts +36 -0
  49. package/dist/writer-types.d.ts.map +1 -0
  50. package/dist/writer-types.js +3 -0
  51. package/package.json +3 -3
  52. package/src/index.ts +24 -13
  53. package/src/json-loader.ts +1 -1
  54. package/src/lib/option-utils/merge-loader-options.ts +1 -1
  55. package/src/lib/worker-loader-utils/create-loader-worker.ts +20 -4
  56. package/src/lib/worker-loader-utils/encode-with-worker.ts +1 -1
  57. package/src/lib/worker-loader-utils/parse-with-worker.ts +2 -2
  58. package/src/loader-types.ts +366 -0
  59. package/src/types.ts +2 -321
  60. package/src/writer-types.ts +61 -0
@@ -0,0 +1,366 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import {
4
+ FetchLike,
5
+ TransformBatches /* , DataType, SyncDataType, BatchableDataType */
6
+ } from './types';
7
+
8
+ // LOADERS
9
+
10
+ /**
11
+ * Core Loader Options
12
+ */
13
+ export type LoaderOptions = {
14
+ /** fetch options or a custom fetch function */
15
+ fetch?: typeof fetch | FetchLike | RequestInit | null;
16
+ /** Do not throw on errors */
17
+ nothrow?: boolean;
18
+
19
+ /** loader selection, search first for supplied mimeType */
20
+ mimeType?: string;
21
+ /** loader selection, provide fallback mimeType is server does not provide */
22
+ fallbackMimeType?: string;
23
+ /** loader selection, avoid searching registered loaders */
24
+ ignoreRegisteredLoaders?: boolean;
25
+
26
+ // general
27
+ /** Experimental: Supply a logger to the parser */
28
+ log?: any;
29
+ /** Force to load WASM libraries from local file system in NodeJS or from loaders.gl CDN in a web browser */
30
+ useLocalLibraries?: boolean;
31
+
32
+ // batched parsing
33
+
34
+ /** Size of each batch. `auto` matches batches to size of incoming chunks */
35
+ batchSize?: number | 'auto';
36
+ /** Minimal amount of time between batches */
37
+ batchDebounceMs?: number;
38
+ /** Stop loading after a given number of rows (compare SQL limit clause) */
39
+ limit?: 0;
40
+ /** Experimental: Stop loading after reaching */
41
+ _limitMB?: 0;
42
+ /** Generate metadata batches */
43
+ metadata?: boolean;
44
+ /** Transforms to run on incoming batches */
45
+ transforms?: TransformBatches[];
46
+
47
+ // workers
48
+
49
+ /** CDN load workers from */
50
+ CDN?: string | null;
51
+ /** Set to `false` to disable workers */
52
+ worker?: boolean;
53
+ /** Number of concurrent workers (per loader) on desktop browser */
54
+ maxConcurrency?: number;
55
+ /** Number of concurrent workers (per loader) on mobile browsers */
56
+ maxMobileConcurrency?: number;
57
+ /** Set to `false` to prevent reuse workers */
58
+ reuseWorkers?: boolean;
59
+ /** Whether to use workers under Node.js (experimental) */
60
+ _nodeWorkers?: boolean;
61
+ /** set to 'test' to run local worker */
62
+ _workerType?: string;
63
+
64
+ /** @deprecated `options.batchType` removed, Use `options.<loader>.type` instead */
65
+ batchType?: 'row' | 'columnar' | 'arrow';
66
+ /** @deprecated `options.throw removed`, Use `options.nothrow` instead */
67
+ throws?: boolean;
68
+ /** @deprecated `options.dataType` no longer used */
69
+ dataType?: never;
70
+ /** @deprecated `options.uri` no longer used */
71
+ uri?: never;
72
+ /** @deprecated `options.method` removed. Use `options.fetch.method` */
73
+ method?: never;
74
+ /** @deprecated `options.headers` removed. Use `options.fetch.headers` */
75
+ headers?: never;
76
+ /** @deprecated `options.body` removed. Use `options.fetch.body` */
77
+ body?: never;
78
+ /** @deprecated `options.mode` removed. Use `options.fetch.mode` */
79
+ mode?: never;
80
+ /** @deprecated `options.credentials` removed. Use `options.fetch.credentials` */
81
+ credentials?: never;
82
+ /** @deprecated `options.cache` removed. Use `options.fetch.cache` */
83
+ cache?: never;
84
+ /** @deprecated `options.redirect` removed. Use `options.fetch.redirect` */
85
+ redirect?: never;
86
+ /** @deprecated `options.referrer` removed. Use `options.fetch.referrer` */
87
+ referrer?: never;
88
+ /** @deprecated `options.referrerPolicy` removed. Use `options.fetch.referrerPolicy` */
89
+ referrerPolicy?: never;
90
+ /** @deprecated `options.integrity` removed. Use `options.fetch.integrity` */
91
+ integrity?: never;
92
+ /** @deprecated `options.keepalive` removed. Use `options.fetch.keepalive` */
93
+ keepalive?: never;
94
+ /** @deprecated `options.signal` removed. Use `options.fetch.signal` */
95
+ signal?: never;
96
+
97
+ // Accept other keys (loader options objects, e.g. `options.csv`, `options.json` ...)
98
+ [loaderId: string]: unknown;
99
+ };
100
+
101
+ type PreloadOptions = {
102
+ [key: string]: unknown;
103
+ };
104
+
105
+ /**
106
+ * A worker loader definition that can be used with `@loaders.gl/core` functions
107
+ */
108
+ export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = {
109
+ /** The result type of this loader */
110
+ dataType?: DataT;
111
+ /** The batched result type of this loader */
112
+ batchType?: BatchT;
113
+
114
+ /** Default Options */
115
+ options: LoaderOptionsT;
116
+ /** Deprecated Options */
117
+ deprecatedOptions?: Record<string, string | Record<string, string>>;
118
+
119
+ /** Human readable name */
120
+ name: string;
121
+ /** id should be the same as the field used in LoaderOptions */
122
+ id: string;
123
+ /** module is used to generate worker threads, need to be the module directory name */
124
+ module: string;
125
+ /** Version should be injected by build tools */
126
+ version: string;
127
+ /** A boolean, or a URL */
128
+ worker?: string | boolean;
129
+ // end Worker
130
+
131
+ /** Which category does this loader belong to */
132
+ category?: string;
133
+ /** File extensions that are potential matches with this loader. */
134
+ extensions: string[];
135
+ /** MIMETypes that indicate a match with this loader. @note Some MIMETypes are generic and supported by many loaders */
136
+ mimeTypes: string[];
137
+
138
+ /** Is the input of this loader binary */
139
+ binary?: boolean;
140
+ /** Is the input of this loader text */
141
+ text?: boolean;
142
+
143
+ /** Test some initial bytes of content to see if this loader might be a match */
144
+ tests?: (((ArrayBuffer: ArrayBuffer) => boolean) | ArrayBuffer | string)[];
145
+
146
+ /** @deprecated */
147
+ supported?: boolean;
148
+ /** @deprecated */
149
+ testText?: (string: string) => boolean;
150
+ };
151
+
152
+ /**
153
+ * A "bundled" loader definition that can be used with `@loaders.gl/core` functions
154
+ * If a worker loader is supported it will also be supported.
155
+ */
156
+ export type LoaderWithParser<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = Loader<
157
+ DataT,
158
+ BatchT,
159
+ LoaderOptionsT
160
+ > & {
161
+ /** Perform actions before load. @deprecated Not officially supported. */
162
+ preload?: Preload;
163
+ /** Parse atomically from an arraybuffer asynchronously */
164
+ parse: (
165
+ arrayBuffer: ArrayBuffer,
166
+ options?: LoaderOptionsT,
167
+ context?: LoaderContext
168
+ ) => Promise<DataT>;
169
+ /** Parse atomically from an arraybuffer synchronously */
170
+ parseSync?: (
171
+ arrayBuffer: ArrayBuffer,
172
+ options?: LoaderOptionsT,
173
+ context?: LoaderContext
174
+ ) => DataT;
175
+ /** Parse atomically from a string asynchronously */
176
+ parseText?: (text: string, options?: LoaderOptionsT, context?: LoaderContext) => Promise<DataT>;
177
+ /** Parse atomically from a string synchronously */
178
+ parseTextSync?: (text: string, options?: LoaderOptionsT, context?: LoaderContext) => DataT;
179
+ /** Parse batches of data from an iterator, return an iterator that yield parsed batches. */
180
+ parseInBatches?: (
181
+ iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
182
+ options?: LoaderOptionsT,
183
+ context?: LoaderContext
184
+ ) => AsyncIterable<BatchT>;
185
+ /** Like `parseInBatches` for loaders that don't integrate with fetch. @deprecated Not officially supported. */
186
+ parseFileInBatches?: (
187
+ file: Blob,
188
+ options?: LoaderOptionsT,
189
+ context?: LoaderContext
190
+ ) => AsyncIterable<BatchT>;
191
+ };
192
+
193
+ /**
194
+ * A Loader context is provided as a third parameters to a loader object's
195
+ * parse functions when that loader is called by other loaders rather then
196
+ * directly by the application.
197
+ *
198
+ * - The context object allows the subloaders to be aware of the parameters and
199
+ * options that the application provided in the top level call.
200
+ * - The context also providedsaccess to parse functions so that the subloader
201
+ * does not need to include the core module.
202
+ * - In addition, the context's parse functions may also redirect loads from worker
203
+ * threads back to main thread.
204
+ */
205
+ export type LoaderContext = {
206
+ /** Loader list provided to top-level loader call plus any sub loaders */
207
+ loaders?: Loader[] | null;
208
+ /** If URL is available. */
209
+ url?: string;
210
+ /** the file name component of the URL (leading path and query string removed) */
211
+ filename?: string;
212
+ /** the directory name component of the URL (leading path excluding file name and query string) */
213
+ baseUrl?: string;
214
+ /** Query string (characters after `?`) */
215
+ queryString?: string;
216
+
217
+ /** Provides access to any application overrides of fetch() */
218
+ fetch: typeof fetch | FetchLike;
219
+
220
+ /** TBD */
221
+ response?: Response;
222
+
223
+ /**
224
+ * Parse function for subloaders. Avoids importing `core`. In workers, may redirect to main thread
225
+ */
226
+ _parse: (
227
+ arrayBuffer: ArrayBuffer,
228
+ loaders?: Loader | Loader[] | LoaderOptions,
229
+ options?: LoaderOptions,
230
+ context?: LoaderContext
231
+ ) => Promise<any>;
232
+
233
+ /**
234
+ * ParseSync function. Avoids importing `core`. In workers, may redirect to main thread
235
+ * @deprecated Do not call directly, use `parseSyncFromContext` instead
236
+ */
237
+ _parseSync?: (
238
+ arrayBuffer: ArrayBuffer,
239
+ loaders?: Loader | Loader[] | LoaderOptions,
240
+ options?: LoaderOptions,
241
+ context?: LoaderContext
242
+ ) => any;
243
+
244
+ /**
245
+ * ParseInBatches function. Avoids importing `core`.
246
+ * @deprecated Do not call directly, use `parseInBatchesFromContext` instead
247
+ */
248
+ _parseInBatches?: (
249
+ iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
250
+ loaders?: Loader | Loader[] | LoaderOptions,
251
+ options?: LoaderOptions,
252
+ context?: LoaderContext
253
+ ) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
254
+ };
255
+
256
+ // type Parse = (
257
+ // arrayBuffer: ArrayBuffer,
258
+ // options?: LoaderOptions,
259
+ // context?: LoaderContext
260
+ // ) => Promise<any>;
261
+ // type ParseSync = (
262
+ // arrayBuffer: ArrayBuffer,
263
+ // options?: LoaderOptions,
264
+ // context?: LoaderContext
265
+ // ) => any;
266
+ // type ParseText = (text: string, options?: LoaderOptions) => Promise<any>;
267
+ // type ParseTextSync = (text: string, options?: LoaderOptions) => any;
268
+ // type ParseInBatches = (
269
+ // iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
270
+ // options?: LoaderOptions,
271
+ // context?: LoaderContext
272
+ // ) => AsyncIterable<any>;
273
+ // type ParseFileInBatches = (
274
+ // file: Blob,
275
+ // options?: LoaderOptions,
276
+ // context?: LoaderContext
277
+ // ) => AsyncIterable<any>;
278
+
279
+ type Preload = (url: string, options?: PreloadOptions) => any;
280
+
281
+ /** Typescript helper to extract options type from a generic loader type */
282
+ export type LoaderOptionsType<T = Loader> = T extends Loader<any, any, infer Options>
283
+ ? Options
284
+ : never;
285
+ /** Typescript helper to extract data type from a generic loader type */
286
+ export type LoaderReturnType<T = Loader> = T extends Loader<infer Return, any, any>
287
+ ? Return
288
+ : never;
289
+ /** Typescript helper to extract batch type from a generic loader type */
290
+ export type LoaderBatchType<T = Loader> = T extends Loader<any, infer Batch, any> ? Batch : never;
291
+
292
+ /**
293
+ * Parses `data` asynchronously using the supplied loader, parse function provided via the loader context
294
+ */
295
+ export async function parseFromContext<
296
+ LoaderT extends Loader,
297
+ OptionsT extends LoaderOptions = LoaderOptionsType<LoaderT>
298
+ >(
299
+ data: ArrayBuffer,
300
+ loader: LoaderT,
301
+ options: OptionsT | undefined,
302
+ context: LoaderContext
303
+ ): Promise<LoaderReturnType<LoaderT>>;
304
+
305
+ /**
306
+ * Parses `data` asynchronously by matching one of the supplied loader
307
+ */
308
+ export async function parseFromContext(
309
+ data: ArrayBuffer,
310
+ loaders: Loader[],
311
+ options: LoaderOptions | undefined,
312
+ context: LoaderContext
313
+ ): Promise<unknown>;
314
+
315
+ /**
316
+ * Parses `data` using a specified loader
317
+ * @param data
318
+ * @param loaders
319
+ * @param options
320
+ * @param context
321
+ */
322
+ // implementation signature
323
+ export async function parseFromContext(
324
+ data: ArrayBuffer,
325
+ loaders: Loader | Loader[],
326
+ options: LoaderOptions | undefined,
327
+ context: LoaderContext
328
+ ): Promise<unknown> {
329
+ return context._parse(data, loaders, options, context);
330
+ }
331
+
332
+ /**
333
+ * Parses `data` synchronously using the specified loader, parse function provided via the loader context
334
+ */
335
+ export function parseSyncFromContext<
336
+ LoaderT extends Loader,
337
+ OptionsT extends LoaderOptions = LoaderOptionsType<LoaderT>
338
+ >(
339
+ data: ArrayBuffer,
340
+ loader: LoaderT,
341
+ options: OptionsT | undefined,
342
+ context: LoaderContext
343
+ ): LoaderReturnType<LoaderT> {
344
+ if (!context._parseSync) {
345
+ throw new Error('parseSync');
346
+ }
347
+ return context._parseSync(data, loader, options, context);
348
+ }
349
+
350
+ /**
351
+ * Parses `data` synchronously using a specified loader, parse function provided via the loader context
352
+ */
353
+ export async function parseInBatchesFromContext<
354
+ LoaderT extends Loader,
355
+ OptionsT extends LoaderOptions = LoaderOptionsType<LoaderT>
356
+ >(
357
+ data: Iterable<ArrayBuffer> | AsyncIterable<ArrayBuffer>,
358
+ loader: LoaderT,
359
+ options: OptionsT | undefined,
360
+ context: LoaderContext
361
+ ): Promise<AsyncIterable<LoaderBatchType<LoaderT>>> {
362
+ if (!context._parseInBatches) {
363
+ throw new Error('parseInBatches');
364
+ }
365
+ return context._parseInBatches(data, loader, options, context);
366
+ }
package/src/types.ts CHANGED
@@ -39,328 +39,9 @@ export type NumberArray = number[] | TypedArray;
39
39
 
40
40
  export type NumericArray = number[] | TypedArray;
41
41
 
42
- type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
42
+ // FETCH
43
43
 
44
- // LOADERS
45
-
46
- /**
47
- * Core Loader Options
48
- */
49
- export type LoaderOptions = {
50
- /** fetch options or a custom fetch function */
51
- fetch?: typeof fetch | FetchLike | RequestInit | null;
52
- /** Do not throw on errors */
53
- nothrow?: boolean;
54
-
55
- /** loader selection, search first for supplied mimeType */
56
- mimeType?: string;
57
- /** loader selection, provide fallback mimeType is server does not provide */
58
- fallbackMimeType?: string;
59
- /** loader selection, avoid searching registered loaders */
60
- ignoreRegisteredLoaders?: boolean;
61
-
62
- // general
63
- /** Experimental: Supply a logger to the parser */
64
- log?: any;
65
- /** Force to load WASM libraries from local file system in NodeJS or from loaders.gl CDN in a web browser */
66
- useLocalLibraries?: boolean;
67
-
68
- // batched parsing
69
-
70
- /** Size of each batch. `auto` matches batches to size of incoming chunks */
71
- batchSize?: number | 'auto';
72
- /** Minimal amount of time between batches */
73
- batchDebounceMs?: number;
74
- /** Stop loading after a given number of rows (compare SQL limit clause) */
75
- limit?: 0;
76
- /** Experimental: Stop loading after reaching */
77
- _limitMB?: 0;
78
- /** Generate metadata batches */
79
- metadata?: boolean;
80
- /** Transforms to run on incoming batches */
81
- transforms?: TransformBatches[];
82
-
83
- // workers
84
-
85
- /** CDN load workers from */
86
- CDN?: string | null;
87
- /** Set to `false` to disable workers */
88
- worker?: boolean;
89
- /** Number of concurrent workers (per loader) on desktop browser */
90
- maxConcurrency?: number;
91
- /** Number of concurrent workers (per loader) on mobile browsers */
92
- maxMobileConcurrency?: number;
93
- /** Set to `false` to prevent reuse workers */
94
- reuseWorkers?: boolean;
95
- /** Whether to use workers under Node.js (experimental) */
96
- _nodeWorkers?: boolean;
97
- /** set to 'test' to run local worker */
98
- _workerType?: string;
99
-
100
- /** @deprecated `options.batchType` removed, Use `options.<loader>.type` instead */
101
- batchType?: 'row' | 'columnar' | 'arrow';
102
- /** @deprecated `options.throw removed`, Use `options.nothrow` instead */
103
- throws?: boolean;
104
- /** @deprecated `options.dataType` no longer used */
105
- dataType?: never;
106
- /** @deprecated `options.uri` no longer used */
107
- uri?: never;
108
- /** @deprecated `options.method` removed. Use `options.fetch.method` */
109
- method?: never;
110
- /** @deprecated `options.headers` removed. Use `options.fetch.headers` */
111
- headers?: never;
112
- /** @deprecated `options.body` removed. Use `options.fetch.body` */
113
- body?: never;
114
- /** @deprecated `options.mode` removed. Use `options.fetch.mode` */
115
- mode?: never;
116
- /** @deprecated `options.credentials` removed. Use `options.fetch.credentials` */
117
- credentials?: never;
118
- /** @deprecated `options.cache` removed. Use `options.fetch.cache` */
119
- cache?: never;
120
- /** @deprecated `options.redirect` removed. Use `options.fetch.redirect` */
121
- redirect?: never;
122
- /** @deprecated `options.referrer` removed. Use `options.fetch.referrer` */
123
- referrer?: never;
124
- /** @deprecated `options.referrerPolicy` removed. Use `options.fetch.referrerPolicy` */
125
- referrerPolicy?: never;
126
- /** @deprecated `options.integrity` removed. Use `options.fetch.integrity` */
127
- integrity?: never;
128
- /** @deprecated `options.keepalive` removed. Use `options.fetch.keepalive` */
129
- keepalive?: never;
130
- /** @deprecated `options.signal` removed. Use `options.fetch.signal` */
131
- signal?: never;
132
-
133
- // Accept other keys (loader options objects, e.g. `options.csv`, `options.json` ...)
134
- [loaderId: string]: unknown;
135
- };
136
-
137
- type PreloadOptions = {
138
- [key: string]: unknown;
139
- };
140
-
141
- /**
142
- * A worker loader definition that can be used with `@loaders.gl/core` functions
143
- */
144
- export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = {
145
- // Types
146
- dataType?: DataT;
147
- batchType?: BatchT;
148
-
149
- /** Default Options */
150
- options: LoaderOptionsT;
151
- /** Deprecated Options */
152
- deprecatedOptions?: Record<string, string | Record<string, string>>;
153
-
154
- // Worker
155
- name: string;
156
- /** id should be the same as the field used in LoaderOptions */
157
- id: string;
158
- /** module is used to generate worker threads, need to be the module directory name */
159
- module: string;
160
- /** Version should be injected by build tools */
161
- version: string;
162
- /** A boolean, or a URL */
163
- worker?: string | boolean;
164
- // end Worker
165
-
166
- /** Which category does this loader belong to */
167
- category?: string;
168
- /** What extensions does this loader generate */
169
- extensions: string[];
170
- mimeTypes: string[];
171
-
172
- binary?: boolean;
173
- text?: boolean;
174
-
175
- tests?: (((ArrayBuffer: ArrayBuffer) => boolean) | ArrayBuffer | string)[];
176
-
177
- // TODO - deprecated
178
- supported?: boolean;
179
- testText?: (string: string) => boolean;
180
- };
181
-
182
- /**
183
- * A "bundled" loader definition that can be used with `@loaders.gl/core` functions
184
- * If a worker loader is supported it will also be supported.
185
- */
186
- export type LoaderWithParser<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = Loader<
187
- DataT,
188
- BatchT,
189
- LoaderOptionsT
190
- > & {
191
- // TODO - deprecated
192
- testText?: (string: string) => boolean;
193
-
194
- parse: (
195
- arrayBuffer: ArrayBuffer,
196
- options?: LoaderOptionsT,
197
- context?: LoaderContext
198
- ) => Promise<DataT>;
199
- preload?: Preload;
200
- parseSync?: (
201
- arrayBuffer: ArrayBuffer,
202
- options?: LoaderOptionsT,
203
- context?: LoaderContext
204
- ) => DataT;
205
- parseText?: (text: string, options?: LoaderOptionsT) => Promise<DataT>;
206
- parseTextSync?: (text: string, options?: LoaderOptionsT) => DataT;
207
- parseInBatches?: (
208
- iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
209
- options?: LoaderOptionsT,
210
- context?: LoaderContext
211
- ) => AsyncIterable<BatchT>;
212
- parseFileInBatches?: (
213
- file: Blob,
214
- options?: LoaderOptionsT,
215
- context?: LoaderContext
216
- ) => AsyncIterable<BatchT>;
217
- };
218
-
219
- /**
220
- * A Loader context is provided as a third parameters to a loader object's
221
- * parse functions when that loader is called by other loaders rather then
222
- * directly by the application.
223
- *
224
- * - The context object allows the subloaders to be aware of the parameters and
225
- * options that the application provided in the top level call.
226
- * - The context also providedsaccess to parse functions so that the subloader
227
- * does not need to include the core module.
228
- * - In addition, the context's parse functions may also redirect loads from worker
229
- * threads back to main thread.
230
- */
231
- export type LoaderContext = {
232
- loaders?: Loader[] | null;
233
- /** If URL is available. */
234
- url?: string;
235
- /** the file name component of the URL (leading path and query string removed) */
236
- filename?: string;
237
- /** the directory name component of the URL (leading path excluding file name and query string) */
238
- baseUrl?: string;
239
- /** Query string (characters after `?`) */
240
- queryString?: string;
241
-
242
- /** Provides access to any application overrides of fetch() */
243
- fetch: typeof fetch | FetchLike;
244
- /** TBD */
245
- response?: Response;
246
- /** Parse function. Use instead of importing `core`. In workers, may redirect to main thread */
247
- parse: (
248
- arrayBuffer: ArrayBuffer,
249
- loaders?: Loader | Loader[] | LoaderOptions,
250
- options?: LoaderOptions,
251
- context?: LoaderContext
252
- ) => Promise<any>;
253
- /** ParseSync function. Use instead of importing `core`. In workers, may redirect to main thread */
254
- parseSync?: (
255
- arrayBuffer: ArrayBuffer,
256
- loaders?: Loader | Loader[] | LoaderOptions,
257
- options?: LoaderOptions,
258
- context?: LoaderContext
259
- ) => any;
260
- /** ParseInBatches function. Use instead of importing `core`. */
261
- parseInBatches?: (
262
- iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
263
- loaders?: Loader | Loader[] | LoaderOptions,
264
- options?: LoaderOptions,
265
- context?: LoaderContext
266
- ) => AsyncIterable<any> | Promise<AsyncIterable<any>>;
267
- };
268
-
269
- // type Parse = (
270
- // arrayBuffer: ArrayBuffer,
271
- // options?: LoaderOptions,
272
- // context?: LoaderContext
273
- // ) => Promise<any>;
274
- // type ParseSync = (
275
- // arrayBuffer: ArrayBuffer,
276
- // options?: LoaderOptions,
277
- // context?: LoaderContext
278
- // ) => any;
279
- // type ParseText = (text: string, options?: LoaderOptions) => Promise<any>;
280
- // type ParseTextSync = (text: string, options?: LoaderOptions) => any;
281
- // type ParseInBatches = (
282
- // iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
283
- // options?: LoaderOptions,
284
- // context?: LoaderContext
285
- // ) => AsyncIterable<any>;
286
- // type ParseFileInBatches = (
287
- // file: Blob,
288
- // options?: LoaderOptions,
289
- // context?: LoaderContext
290
- // ) => AsyncIterable<any>;
291
-
292
- type Preload = (url: string, options?: PreloadOptions) => any;
293
-
294
- /** Typescript helper to extract options type from a generic loader type */
295
- export type LoaderOptionsType<T = Loader> = T extends Loader<any, any, infer Options>
296
- ? Options
297
- : never;
298
- /** Typescript helper to extract data type from a generic loader type */
299
- export type LoaderReturnType<T = Loader> = T extends Loader<infer Return, any, any>
300
- ? Return
301
- : never;
302
- /** Typescript helper to extract batch type from a generic loader type */
303
- export type LoaderBatchType<T = Loader> = T extends Loader<any, infer Batch, any> ? Batch : never;
304
-
305
- // WRITERS
306
-
307
- /** Options for writers */
308
- export type WriterOptions = {
309
- /** worker source. If is set will be used instead of loading worker from the Internet */
310
- souce?: string | null;
311
- /** Force to load WASM libraries from local file system in NodeJS or from loaders.gl CDN in a web browser */
312
- useLocalLibraries?: boolean;
313
- /** writer-specific options */
314
- [writerId: string]: any;
315
- };
316
-
317
- /**
318
- * A writer definition that can be used with `@loaders.gl/core` functions
319
- */
320
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
321
- export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = {
322
- name: string;
323
-
324
- id: string;
325
- module: string;
326
- version: string;
327
- worker?: string | boolean;
328
-
329
- // TODO - are these are needed?
330
- extensions?: string[];
331
- mimeTypes?: string[];
332
- binary?: boolean;
333
- text?: boolean;
334
-
335
- options: WriterOptionsT;
336
- deprecatedOptions?: Record<string, string>;
337
-
338
- // encodeText?: EncodeText;
339
- // encode?: Encode;
340
- encodeSync?: EncodeSync;
341
- // encodeInBatches?: EncodeInBatches;
342
- encodeURLtoURL?: EncodeURLtoURL;
343
-
344
- encode?(data: DataT, options?: WriterOptionsT): Promise<ArrayBuffer>;
345
- encodeText?(table: DataT, options?: WriterOptionsT): Promise<string> | string;
346
- encodeInBatches?(data: AsyncIterable<any>, options?: WriterOptionsT): AsyncIterable<ArrayBuffer>;
347
- };
348
-
349
- // type Encode = (data: any, options?: WriterOptions) => Promise<ArrayBuffer>;
350
- type EncodeSync = (data: any, options?: WriterOptions) => ArrayBuffer;
351
- // TODO
352
- // type EncodeText = Function;
353
- // type EncodeInBatches = Function;
354
- type EncodeURLtoURL = (
355
- inputUrl: string,
356
- outputUrl: string,
357
- options?: WriterOptions
358
- ) => Promise<string>;
359
-
360
- /** Typescript helper to extract the writer options type from a generic writer type */
361
- export type WriterOptionsType<T = Writer> = T extends Writer<unknown, unknown, infer Options>
362
- ? Options
363
- : never;
44
+ export type FetchLike = (url: string, options?: RequestInit) => Promise<Response>;
364
45
 
365
46
  // MISC TYPES
366
47