@loaders.gl/loader-utils 4.3.2 → 4.4.0-alpha.1

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 (66) hide show
  1. package/dist/format-types.d.ts +24 -0
  2. package/dist/format-types.d.ts.map +1 -0
  3. package/dist/format-types.js +4 -0
  4. package/dist/index.cjs +41 -25
  5. package/dist/index.cjs.map +3 -3
  6. package/dist/index.d.ts +10 -8
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2 -3
  9. package/dist/json-loader.js +1 -1
  10. package/dist/lib/files/blob-file.d.ts +1 -1
  11. package/dist/lib/files/blob-file.d.ts.map +1 -1
  12. package/dist/lib/files/blob-file.js +3 -1
  13. package/dist/lib/files/http-file.d.ts +1 -1
  14. package/dist/lib/files/http-file.d.ts.map +1 -1
  15. package/dist/lib/files/http-file.js +1 -1
  16. package/dist/lib/files/node-file-facade.d.ts +1 -1
  17. package/dist/lib/files/node-file-facade.d.ts.map +1 -1
  18. package/dist/lib/files/node-file-facade.js +1 -1
  19. package/dist/lib/log-utils/log.js +1 -1
  20. package/dist/lib/option-utils/merge-options.d.ts +12 -0
  21. package/dist/lib/option-utils/merge-options.d.ts.map +1 -0
  22. package/dist/lib/option-utils/{merge-loader-options.js → merge-options.js} +4 -1
  23. package/dist/lib/sources/data-source.d.ts +25 -13
  24. package/dist/lib/sources/data-source.d.ts.map +1 -1
  25. package/dist/lib/sources/data-source.js +30 -8
  26. package/dist/lib/sources/image-source.d.ts +1 -4
  27. package/dist/lib/sources/image-source.d.ts.map +1 -1
  28. package/dist/lib/sources/image-source.js +2 -2
  29. package/dist/lib/sources/image-tile-source.d.ts +2 -1
  30. package/dist/lib/sources/image-tile-source.d.ts.map +1 -1
  31. package/dist/lib/sources/tile-source-adapter.d.ts +3 -3
  32. package/dist/lib/sources/tile-source-adapter.d.ts.map +1 -1
  33. package/dist/lib/sources/tile-source-adapter.js +0 -1
  34. package/dist/lib/sources/tile-source.d.ts +3 -5
  35. package/dist/lib/sources/tile-source.d.ts.map +1 -1
  36. package/dist/lib/sources/vector-source.d.ts +2 -4
  37. package/dist/lib/sources/vector-source.d.ts.map +1 -1
  38. package/dist/lib/sources/vector-source.js +1 -2
  39. package/dist/lib/sources/vector-tile-source.d.ts +2 -2
  40. package/dist/lib/sources/vector-tile-source.d.ts.map +1 -1
  41. package/dist/loader-types.d.ts +9 -8
  42. package/dist/loader-types.d.ts.map +1 -1
  43. package/dist/source-types.d.ts +20 -8
  44. package/dist/source-types.d.ts.map +1 -1
  45. package/dist/source-types.js +1 -0
  46. package/dist/writer-types.d.ts +8 -8
  47. package/dist/writer-types.d.ts.map +1 -1
  48. package/package.json +4 -7
  49. package/src/format-types.ts +27 -0
  50. package/src/index.ts +15 -8
  51. package/src/lib/files/blob-file.ts +4 -2
  52. package/src/lib/files/http-file.ts +1 -1
  53. package/src/lib/files/node-file-facade.ts +1 -1
  54. package/src/lib/option-utils/{merge-loader-options.ts → merge-options.ts} +10 -6
  55. package/src/lib/sources/data-source.ts +51 -17
  56. package/src/lib/sources/image-source.ts +2 -7
  57. package/src/lib/sources/image-tile-source.ts +2 -4
  58. package/src/lib/sources/tile-source-adapter.ts +4 -4
  59. package/src/lib/sources/tile-source.ts +3 -9
  60. package/src/lib/sources/vector-source.ts +2 -6
  61. package/src/lib/sources/vector-tile-source.ts +2 -5
  62. package/src/loader-types.ts +12 -15
  63. package/src/source-types.ts +35 -10
  64. package/src/writer-types.ts +10 -12
  65. package/dist/lib/option-utils/merge-loader-options.d.ts +0 -9
  66. package/dist/lib/option-utils/merge-loader-options.d.ts.map +0 -1
@@ -1,3 +1,4 @@
1
+ import type { Format } from "./format-types.js";
1
2
  /** Options for writers */
2
3
  export type WriterOptions = {
3
4
  /** worker source. If is set will be used instead of loading worker from the Internet */
@@ -12,21 +13,23 @@ export type WriterOptions = {
12
13
  /**
13
14
  * A writer definition that can be used with `@loaders.gl/core` functions
14
15
  */
15
- export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = {
16
+ export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = Format & {
16
17
  /** The result type of this loader */
17
18
  dataType?: DataT;
18
19
  /** The batched result type of this loader */
19
20
  batchType?: BatchT;
21
+ /** Version should be injected by build tools */
22
+ version: string;
23
+ /** A boolean, or a URL */
24
+ worker?: string | boolean;
25
+ options: WriterOptionsT;
26
+ deprecatedOptions?: Record<string, string>;
20
27
  /** Human readable name */
21
28
  name: string;
22
29
  /** id should be the same as the field used in LoaderOptions */
23
30
  id: string;
24
31
  /** module is used to generate worker threads, need to be the module directory name */
25
32
  module: string;
26
- /** Version should be injected by build tools */
27
- version: string;
28
- /** A boolean, or a URL */
29
- worker?: string | boolean;
30
33
  /** Which category does this loader belong to */
31
34
  category?: string;
32
35
  /** File extensions that are potential matches with this loader. */
@@ -37,9 +40,6 @@ export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOpt
37
40
  binary?: boolean;
38
41
  /** Is the input of this loader text */
39
42
  text?: boolean;
40
- /** Default options for this writer */
41
- options: WriterOptionsT;
42
- deprecatedOptions?: Record<string, string>;
43
43
  };
44
44
  /**
45
45
  * A writer definition that can be used with `@loaders.gl/core` functions
@@ -1 +1 @@
1
- {"version":3,"file":"writer-types.d.ts","sourceRoot":"","sources":["../src/writer-types.ts"],"names":[],"mappings":"AAMA,0BAA0B;AAC1B,MAAM,MAAM,aAAa,GAAG;IAC1B,wFAAwF;IACxF,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAIvB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,4GAA4G;IAC5G,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,8BAA8B;IAC9B,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB,CAAC;AAEF;;GAEG;AAEH,MAAM,MAAM,MAAM,CAAC,K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AM,IACnC,CAAC,SAAS,MAAM,CAAC,MAAM,QAAQ,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,QAAQ,GAAG,KAAK,CAAC;AAChE,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,MAAM,IACpC,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,MAAM,SAAS,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/loader-utils",
3
- "version": "4.3.2",
3
+ "version": "4.4.0-alpha.1",
4
4
  "description": "Framework-independent loaders for 3D graphics formats",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -45,13 +45,10 @@
45
45
  "stream": false
46
46
  },
47
47
  "dependencies": {
48
- "@loaders.gl/schema": "4.3.2",
49
- "@loaders.gl/worker-utils": "4.3.2",
48
+ "@loaders.gl/schema": "4.4.0-alpha.1",
49
+ "@loaders.gl/worker-utils": "4.4.0-alpha.1",
50
50
  "@probe.gl/log": "^4.0.2",
51
51
  "@probe.gl/stats": "^4.0.2"
52
52
  },
53
- "peerDependencies": {
54
- "@loaders.gl/core": "^4.3.0"
55
- },
56
- "gitHead": "b4203b8703f64a38d6f79a3113bc7bb51d45c93a"
53
+ "gitHead": "f1732de45907bd500bf4eedb4803beca8bf4bfb0"
57
54
  }
@@ -0,0 +1,27 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /**
6
+ * An object that describes a format
7
+ */
8
+ export type Format = {
9
+ /** Human readable name */
10
+ name: string;
11
+ /** Unique lower-case id string for this format. Used for e.g. LoaderOptions */
12
+ id: string;
13
+ /** loaders.gl module that contains the implementation of this format */
14
+ module: string;
15
+ /** Which category does this loader belong to */
16
+ category?: string;
17
+ /** File extensions that are potential matches with this loader. */
18
+ extensions: string[];
19
+ /** MIMETypes that indicate a match with this loader. @note Some MIMETypes are generic and supported by many loaders */
20
+ mimeTypes: string[];
21
+ /** Is this a binary format */
22
+ binary?: boolean;
23
+ /** Is this a text format */
24
+ text?: boolean;
25
+ /** Test some initial bytes of content to see if this loader might be a match */
26
+ tests?: (((ArrayBuffer: ArrayBuffer) => boolean) | ArrayBuffer | string)[];
27
+ };
package/src/index.ts CHANGED
@@ -20,6 +20,10 @@ export type {
20
20
  FetchLike
21
21
  } from './types';
22
22
 
23
+ // formats
24
+
25
+ export type {Format} from './format-types';
26
+
23
27
  // loaders
24
28
 
25
29
  export type {
@@ -63,7 +67,10 @@ export {
63
67
  export {log} from './lib/log-utils/log';
64
68
 
65
69
  // Options and modules
66
- export {mergeLoaderOptions} from './lib/option-utils/merge-loader-options';
70
+ export type {RequiredOptions} from './lib/option-utils/merge-options';
71
+ export {mergeOptions, getRequiredOptions} from './lib/option-utils/merge-options';
72
+
73
+ // Modules (external libraries)
67
74
  export {registerJSModules} from './lib/module-utils/js-module-utils';
68
75
  export {checkJSModule, getJSModule, getJSModuleOrNull} from './lib/module-utils/js-module-utils';
69
76
 
@@ -150,25 +157,25 @@ export {FileHandleFile} from './lib/file-provider/file-handle-file';
150
157
  export {DataViewFile} from './lib/file-provider/data-view-file';
151
158
 
152
159
  // EXPERIMENTAL: DATA SOURCES
153
- export type {Source} from './source-types';
160
+ export type {Source, SourceArrayOptionsType, SourceArrayDataSourceType} from './source-types';
154
161
 
155
- export type {DataSourceProps} from './lib/sources/data-source';
162
+ export type {DataSourceOptions} from './lib/sources/data-source';
156
163
  export {DataSource} from './lib/sources/data-source';
157
164
 
158
165
  export {ImageSource} from './lib/sources/image-source';
159
166
  export type {ImageType} from './lib/sources/utils/image-type';
160
- export type {ImageSourceProps, ImageSourceMetadata} from './lib/sources/image-source';
167
+ export type {ImageSourceMetadata} from './lib/sources/image-source';
161
168
  export type {GetImageParameters} from './lib/sources/image-source';
162
169
 
163
- export {VectorSource} from './lib/sources/vector-source';
164
- export type {VectorSourceProps, VectorSourceMetadata} from './lib/sources/vector-source';
170
+ export type {VectorSource} from './lib/sources/vector-source';
171
+ export type {VectorSourceMetadata} from './lib/sources/vector-source';
165
172
  export type {GetFeaturesParameters} from './lib/sources/vector-source';
166
173
 
167
- export type {TileSource, TileSourceProps} from './lib/sources/tile-source';
174
+ export type {TileSource} from './lib/sources/tile-source';
168
175
  export type {TileSourceMetadata, GetTileParameters} from './lib/sources/tile-source';
169
176
  export type {GetTileDataParameters} from './lib/sources/tile-source';
170
177
 
171
178
  export type {ImageTileSource} from './lib/sources/image-tile-source';
172
179
 
173
- export type {VectorTileSource, VectorTileSourceProps} from './lib/sources/vector-tile-source';
180
+ export type {VectorTileSource} from './lib/sources/vector-tile-source';
174
181
  export type {VectorTile} from './lib/sources/vector-tile-source';
@@ -30,8 +30,10 @@ export class BlobFile implements ReadableFile {
30
30
  };
31
31
  }
32
32
 
33
- async read(start: number, length: number): Promise<ArrayBuffer> {
34
- const arrayBuffer = await this.handle.slice(start, start + length).arrayBuffer();
33
+ async read(start?: number | bigint, length?: number): Promise<ArrayBuffer> {
34
+ const arrayBuffer = await this.handle
35
+ .slice(Number(start), Number(start) + Number(length))
36
+ .arrayBuffer();
35
37
  return arrayBuffer;
36
38
  }
37
39
  }
@@ -30,7 +30,7 @@ export class HttpFile implements ReadableFile {
30
30
  };
31
31
  }
32
32
 
33
- async read(offset: number | bigint, length: number): Promise<ArrayBuffer> {
33
+ async read(offset: number | bigint = 0, length: number = 0): Promise<ArrayBuffer> {
34
34
  const response = await this.fetchRange(offset, length);
35
35
  const arrayBuffer = await response.arrayBuffer();
36
36
  return arrayBuffer;
@@ -25,7 +25,7 @@ export class NodeFileFacade implements ReadableFile, WritableFile {
25
25
  throw new Error('Can\'t instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.');
26
26
  }
27
27
  /** Read data */
28
- async read(start?: number | bigint, end?: number | bigint): Promise<ArrayBuffer> {
28
+ async read(start?: number | bigint, length?: number): Promise<ArrayBuffer> {
29
29
  throw NOT_IMPLEMENTED;
30
30
  }
31
31
  /** Write to file. The number of bytes written will be returned */
@@ -2,7 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {LoaderOptions} from '../../loader-types';
5
+ export type RequiredOptions<T> = Required<{[K in keyof T]: Required<T[K]>}>;
6
+
7
+ export function getRequiredOptions<T>(options: T): RequiredOptions<T> {
8
+ return options as RequiredOptions<T>;
9
+ }
6
10
 
7
11
  /**
8
12
  *
@@ -10,11 +14,11 @@ import {LoaderOptions} from '../../loader-types';
10
14
  * @param newOptions
11
15
  * @returns
12
16
  */
13
- export function mergeLoaderOptions<Options extends LoaderOptions>(
14
- baseOptions: Options | undefined,
15
- newOptions: Options
16
- ): Options {
17
- return mergeOptionsRecursively(baseOptions || {}, newOptions) as Options;
17
+ export function mergeOptions<OptionsT extends Record<string, unknown>>(
18
+ baseOptions: OptionsT | undefined,
19
+ newOptions: OptionsT
20
+ ): OptionsT {
21
+ return mergeOptionsRecursively(baseOptions || {}, newOptions) as OptionsT;
18
22
  }
19
23
 
20
24
  function mergeOptionsRecursively(
@@ -2,34 +2,68 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {LoaderOptions} from '@loaders.gl/loader-utils';
5
+ import type {LoaderOptions, Loader} from '../../loader-types';
6
+ import type {RequiredOptions} from '../option-utils/merge-options';
7
+ import {mergeOptions} from '../option-utils/merge-options';
8
+ import {resolvePath} from '../path-utils/file-aliases';
6
9
 
7
10
  /** Common properties for all data sources */
8
- export type DataSourceProps = {
9
- url?: string | Blob;
10
- /** LoaderOptions provide an option to override `fetch`. Will also be passed to any sub loaders */
11
- loadOptions?: LoaderOptions;
12
- };
11
+ export type DataSourceOptions = Partial<{
12
+ core: {
13
+ /** Allows application to specify which source should be selected. Matches `Source.type`. Defaults to 'auto' */
14
+ type?: string;
15
+ /** Any dataset attributions (in case underlying metadata does not include attributions) */
16
+ attributions?: string[];
17
+ /** LoaderOptions provide an option to override `fetch`. Will also be passed to any sub loaders */
18
+ loadOptions?: LoaderOptions;
19
+ /** Make additional loaders available to the data source */
20
+ loaders?: Loader[];
21
+ };
22
+ [key: string]: Record<string, unknown>;
23
+ }>;
13
24
 
14
25
  /** base class of all data sources */
15
- export abstract class DataSource<PropsT extends DataSourceProps = DataSourceProps> {
16
- abstract data: unknown;
17
- /** A resolved fetch function extracted from loadOptions prop */
18
- fetch: (url: string, options?: RequestInit) => Promise<Response>;
26
+ export abstract class DataSource<DataT, OptionsT extends DataSourceOptions> {
27
+ static defaultOptions: Required<DataSourceOptions> = {
28
+ core: {
29
+ type: 'auto',
30
+ attributions: [],
31
+ loadOptions: {},
32
+ loaders: []
33
+ }
34
+ };
35
+
36
+ optionsType?: OptionsT & DataSourceOptions;
37
+ options: Required<OptionsT & DataSourceOptions>;
38
+ readonly data: DataT;
39
+ readonly url: string;
40
+
19
41
  /** The actual load options, if calling a loaders.gl loader */
20
42
  loadOptions: LoaderOptions;
43
+ /** A resolved fetch function extracted from loadOptions prop */
44
+ fetch: (url: string, options?: RequestInit) => Promise<Response>;
21
45
  _needsRefresh: boolean = true;
22
46
 
23
- props: PropsT;
24
-
25
- constructor(props: PropsT) {
26
- this.props = {...props};
27
- this.loadOptions = {...props.loadOptions};
47
+ constructor(
48
+ data: DataT,
49
+ options: OptionsT,
50
+ defaultOptions?: Omit<RequiredOptions<OptionsT>, 'core'>
51
+ ) {
52
+ if (defaultOptions) {
53
+ // @ts-expect-error Typescript gets confused
54
+ this.options = mergeOptions({...defaultOptions, core: DataSource.defaultOptions}, options);
55
+ } else {
56
+ // @ts-expect-error
57
+ this.options = {...options};
58
+ }
59
+ this.data = data;
60
+ this.url = typeof data === 'string' ? resolvePath(data) : '';
61
+ this.loadOptions = {...this.options.core?.loadOptions};
28
62
  this.fetch = getFetchFunction(this.loadOptions);
29
63
  }
30
64
 
31
- setProps(props: PropsT) {
32
- this.props = Object.assign(this.props, props);
65
+ setProps(options: OptionsT) {
66
+ this.options = Object.assign(this.options, options);
33
67
  // TODO - add a shallow compare to avoid setting refresh if no change?
34
68
  this.setNeedsRefresh();
35
69
  }
@@ -2,19 +2,14 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {DataSourceProps} from './data-source';
6
- import {DataSource} from './data-source';
7
5
  // TODO - can we import from schema?
8
6
  import {ImageType} from './utils/image-type';
9
-
10
- export type ImageSourceProps = DataSourceProps;
7
+ // TODO - remove (this breaks WMS layer)
11
8
 
12
9
  /**
13
10
  * ImageSource - data sources that allow images to be queried by (geospatial) extents
14
11
  */
15
- export abstract class ImageSource<
16
- PropsT extends ImageSourceProps = ImageSourceProps
17
- > extends DataSource<PropsT> {
12
+ export abstract class ImageSource {
18
13
  static type: string = 'template';
19
14
  static testURL = (url: string): boolean => false;
20
15
 
@@ -16,9 +16,7 @@ export type ImageTileSourceProps = TileSourceProps;
16
16
  * MapTileSource - data sources that allow data to be queried by (geospatial) tile
17
17
  * @note If geospatial, bounding box is expected to be in web mercator coordinates
18
18
  */
19
- export interface ImageTileSource<
20
- PropsT extends TileSourceProps = TileSourceProps,
21
- MetadataT extends TileSourceMetadata = TileSourceMetadata
22
- > extends TileSource<PropsT, MetadataT> {
19
+ export interface ImageTileSource extends TileSource {
20
+ getMetadata(): Promise<TileSourceMetadata>;
23
21
  getImageTile(parameters: GetTileParameters): Promise<ImageType | null>;
24
22
  }
@@ -9,12 +9,12 @@ import {ImageSource, ImageSourceMetadata} from './image-source';
9
9
  * @note
10
10
  * - If geospatial, bounding box is expected to be in web mercator coordinates
11
11
  */
12
- // @ts-expect-error TODO - does not implement all DataSource members
13
- export class TileSourceAdapter implements TileSource<ImageSourceMetadata> {
14
- readonly viewportSource: ImageSource;
15
- constructor(source: ImageSource) {
12
+ export class TileSourceAdapter<ImageSourceT extends ImageSource> implements TileSource {
13
+ readonly viewportSource: ImageSourceT;
14
+ constructor(source: ImageSourceT) {
16
15
  this.viewportSource = source;
17
16
  }
17
+
18
18
  async getMetadata(): Promise<ImageSourceMetadata> {
19
19
  return await this.viewportSource.getMetadata();
20
20
  }
@@ -2,25 +2,19 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {DataSourceProps} from './data-source';
6
- import {DataSource} from './data-source';
7
-
8
5
  /**
9
6
  * Props for a TileSource
10
7
  */
11
- export type TileSourceProps = DataSourceProps;
8
+ export type TileSourceProps = {};
12
9
 
13
10
  /**
14
11
  * MapTileSource - data sources that allow data to be queried by (geospatial) extents
15
12
  * @note
16
13
  * - If geospatial, bounding box is expected to be in web mercator coordinates
17
14
  */
18
- export interface TileSource<
19
- PropsT extends TileSourceProps = TileSourceProps,
20
- MetadataT extends TileSourceMetadata = TileSourceMetadata
21
- > extends DataSource<PropsT> {
15
+ export interface TileSource {
22
16
  // extends DataSource {
23
- getMetadata(): Promise<MetadataT>;
17
+ getMetadata(): Promise<TileSourceMetadata>;
24
18
  /** Flat parameters */
25
19
  getTile(parameters: GetTileParameters): Promise<unknown | null>;
26
20
  /** deck.gl compatibility: TileLayer and MTVLayer */
@@ -3,19 +3,15 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Schema, GeoJSONTable, BinaryFeatureCollection} from '@loaders.gl/schema';
6
- import type {DataSourceProps} from './data-source';
7
- import {DataSource} from './data-source';
8
6
 
9
- export type VectorSourceProps = DataSourceProps;
7
+ export type VectorSourceProps = {};
10
8
 
11
9
  /**
12
10
  * VectorSource - data sources that allow features to be queried by (geospatial) extents
13
11
  * @note
14
12
  * - If geospatial, bounding box is expected to be in web mercator coordinates
15
13
  */
16
- export abstract class VectorSource<
17
- PropsT extends VectorSourceProps = VectorSourceProps
18
- > extends DataSource<PropsT> {
14
+ export abstract class VectorSource {
19
15
  static type: string = 'template';
20
16
  static testURL = (url: string): boolean => false;
21
17
 
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import type {Schema, Feature, BinaryFeatureCollection} from '@loaders.gl/schema';
6
- import {TileSource, TileSourceProps, TileSourceMetadata, GetTileParameters} from './tile-source';
6
+ import {TileSource, TileSourceProps, GetTileParameters} from './tile-source';
7
7
  import type {GetTileDataParameters} from './tile-source';
8
8
 
9
9
  export type VectorTile = unknown;
@@ -14,10 +14,7 @@ export type VectorTileSourceProps = TileSourceProps;
14
14
  * VectorTileSource - data sources that allow data to be queried by (geospatial) tile
15
15
  * @note If geospatial, bounding box is expected to be in web mercator coordinates
16
16
  */
17
- export interface VectorTileSource<
18
- PropsT extends VectorTileSourceProps = VectorTileSourceProps,
19
- MetadataT extends TileSourceMetadata = TileSourceMetadata
20
- > extends TileSource<PropsT, MetadataT> {
17
+ export interface VectorTileSource extends TileSource {
21
18
  getSchema(): Promise<Schema>;
22
19
  getVectorTile(parameters: GetTileParameters): Promise<VectorTile | null>;
23
20
  getTileData(
@@ -2,10 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {
6
- FetchLike,
7
- TransformBatches /* , DataType, SyncDataType, BatchableDataType */
8
- } from './types';
5
+ import type {Format} from './format-types';
6
+ import {FetchLike, TransformBatches} from './types';
9
7
  import {ReadableFile} from './lib/files/file';
10
8
 
11
9
  // LOADERS
@@ -113,7 +111,7 @@ type PreloadOptions = {
113
111
  /**
114
112
  * A worker loader definition that can be used with `@loaders.gl/core` functions
115
113
  */
116
- export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = {
114
+ export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> = Format & {
117
115
  /** The result type of this loader */
118
116
  dataType?: DataT;
119
117
  /** The batched result type of this loader */
@@ -123,6 +121,11 @@ export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> =
123
121
  options: LoaderOptionsT;
124
122
  /** Deprecated Options */
125
123
  deprecatedOptions?: Record<string, string | Record<string, string>>;
124
+ /** Version should be injected by build tools */
125
+ version: string;
126
+ /** A boolean, or a URL */
127
+ worker?: string | boolean;
128
+ // end Worker
126
129
 
127
130
  /** Human readable name */
128
131
  name: string;
@@ -130,19 +133,12 @@ export type Loader<DataT = any, BatchT = any, LoaderOptionsT = LoaderOptions> =
130
133
  id: string;
131
134
  /** module is used to generate worker threads, need to be the module directory name */
132
135
  module: string;
133
- /** Version should be injected by build tools */
134
- version: string;
135
- /** A boolean, or a URL */
136
- worker?: string | boolean;
137
- // end Worker
138
-
139
136
  /** Which category does this loader belong to */
140
137
  category?: string;
141
138
  /** File extensions that are potential matches with this loader. */
142
139
  extensions: string[];
143
140
  /** MIMETypes that indicate a match with this loader. @note Some MIMETypes are generic and supported by many loaders */
144
141
  mimeTypes: string[];
145
-
146
142
  /** Is the input of this loader binary */
147
143
  binary?: boolean;
148
144
  /** Is the input of this loader text */
@@ -295,12 +291,13 @@ type Preload = (url: string, options?: PreloadOptions) => any;
295
291
 
296
292
  /** Typescript helper to extract options type from a loader type */
297
293
  export type LoaderOptionsType<T = Loader> =
298
- T extends Loader<any, any, infer Options> ? Options : never;
294
+ T extends Loader<unknown, unknown, infer Options> ? Options : never;
299
295
  /** Typescript helper to extract data type from a loader type */
300
296
  export type LoaderReturnType<T = Loader> =
301
- T extends Loader<infer Return, any, any> ? Return : never;
297
+ T extends Loader<infer Return, unknown, unknown> ? Return : never;
302
298
  /** Typescript helper to extract batch type from a loader type */
303
- export type LoaderBatchType<T = Loader> = T extends Loader<any, infer Batch, any> ? Batch : never;
299
+ export type LoaderBatchType<T = Loader> =
300
+ T extends Loader<unknown, infer Batch, unknown> ? Batch : never;
304
301
 
305
302
  /** Typescript helper to extract options type from an array of loader types */
306
303
  export type LoaderArrayOptionsType<LoadersT extends Loader[] = Loader[]> =
@@ -2,7 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {DataSource, DataSourceProps} from './lib/sources/data-source';
5
+ import type {Format} from './format-types';
6
+ import type {DataSource, DataSourceOptions} from './lib/sources/data-source';
6
7
 
7
8
  /**
8
9
  * A `Source` contains metadata and a factory method for creating instances of a specific `DataSource`.
@@ -11,13 +12,15 @@ import type {DataSource, DataSourceProps} from './lib/sources/data-source';
11
12
  * `createDataSource(... , [MVTSource, PMTilesSource, ...])
12
13
  */
13
14
  export interface Source<
14
- DataSourceT extends DataSource = DataSource,
15
- DataSourcePropsT extends DataSourceProps = any
16
- > {
15
+ DataSourceT extends DataSource<unknown, DataSourceOptions> = DataSource<
16
+ unknown,
17
+ DataSourceOptions
18
+ >
19
+ > extends Format {
17
20
  /** Type of source created by this service */
18
- source?: DataSourceT;
19
- /** Type of props used when creating sources */
20
- props?: DataSourcePropsT;
21
+ dataSource?: DataSourceT;
22
+ /** Type of options used when creating sources */
23
+ options?: DataSourceT['optionsType'];
21
24
 
22
25
  /** Name of the service */
23
26
  name: string;
@@ -30,8 +33,6 @@ export interface Source<
30
33
  extensions: string[];
31
34
  /** MIME extensions that this service uses */
32
35
  mimeTypes: string[];
33
- /** Default options */
34
- options: DataSourcePropsT;
35
36
 
36
37
  /** Type string identifying this service, e.g. 'wms' */
37
38
  type: string;
@@ -40,10 +41,34 @@ export interface Source<
40
41
  /** Can source be created from a Blob or File */
41
42
  fromBlob: boolean;
42
43
 
44
+ /** Default options */
45
+ defaultOptions: Omit<
46
+ Required<{[K in keyof DataSourceT['options']]: Required<DataSourceT['options'][K]>}>,
47
+ 'core'
48
+ >;
49
+
43
50
  /** Check if a URL can support this service */
44
51
  testURL: (url: string) => boolean;
45
52
  /** Test data */
46
53
  testData?: (data: Blob) => boolean;
47
54
  /** Create a source */
48
- createDataSource(data: string | Blob, props: DataSourcePropsT): DataSourceT;
55
+ createDataSource(data: string | Blob, options: Readonly<DataSourceT['optionsType']>): DataSourceT;
49
56
  }
57
+
58
+ // T extends Source<DataSource, any> ? DataSource : never;
59
+ // T extends Source<any, infer PropsType> ? PropsType : never;
60
+
61
+ /** Typescript helper to extract input data type from a source type */
62
+ export type SourcePropsType<SourceT extends Source> = Required<SourceT['options']>;
63
+
64
+ /** Typescript helper to extract the source options type from a source type */
65
+ export type SourceDataSourceType<SourceT extends Source> = SourceT['dataSource'];
66
+
67
+ /** Typescript helper to extract options type from an array of source types */
68
+ export type SourceArrayOptionsType<SourcesT extends Source[] = Source[]> =
69
+ SourcesT[number]['options'] & DataSourceOptions;
70
+
71
+ /** Typescript helper to extract data type from a source type */
72
+ export type SourceArrayDataSourceType<SourcesT extends Source[] = Source[]> =
73
+ SourcesT[number]['dataSource'];
74
+ /** Typescript helper to extract batch type from a source type */
@@ -2,6 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
+ import type {Format} from './format-types';
6
+
5
7
  // WRITERS
6
8
 
7
9
  /** Options for writers */
@@ -24,11 +26,18 @@ export type WriterOptions = {
24
26
  * A writer definition that can be used with `@loaders.gl/core` functions
25
27
  */
26
28
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
- export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = {
29
+ export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOptions> = Format & {
28
30
  /** The result type of this loader */
29
31
  dataType?: DataT;
30
32
  /** The batched result type of this loader */
31
33
  batchType?: BatchT;
34
+ /** Version should be injected by build tools */
35
+ version: string;
36
+ /** A boolean, or a URL */
37
+ worker?: string | boolean;
38
+ // end Worker
39
+ options: WriterOptionsT;
40
+ deprecatedOptions?: Record<string, string>;
32
41
 
33
42
  /** Human readable name */
34
43
  name: string;
@@ -36,27 +45,16 @@ export type Writer<DataT = unknown, BatchT = unknown, WriterOptionsT = WriterOpt
36
45
  id: string;
37
46
  /** module is used to generate worker threads, need to be the module directory name */
38
47
  module: string;
39
- /** Version should be injected by build tools */
40
- version: string;
41
- /** A boolean, or a URL */
42
- worker?: string | boolean;
43
- // end Worker
44
-
45
48
  /** Which category does this loader belong to */
46
49
  category?: string;
47
50
  /** File extensions that are potential matches with this loader. */
48
51
  extensions: string[];
49
52
  /** MIMETypes that indicate a match with this loader. @note Some MIMETypes are generic and supported by many loaders */
50
53
  mimeTypes?: string[];
51
-
52
54
  /** Is the input of this loader binary */
53
55
  binary?: boolean;
54
56
  /** Is the input of this loader text */
55
57
  text?: boolean;
56
-
57
- /** Default options for this writer */
58
- options: WriterOptionsT;
59
- deprecatedOptions?: Record<string, string>;
60
58
  };
61
59
 
62
60
  /**