@loaders.gl/core 4.3.0-alpha.2 → 4.3.0-alpha.4

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.
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ export { loadInBatches } from "./lib/api/load-in-batches.js";
13
13
  export { encodeTable, encodeTableAsText, encodeTableInBatches } from "./lib/api/encode-table.js";
14
14
  export { encode, encodeSync, encodeInBatches, encodeURLtoURL } from "./lib/api/encode.js";
15
15
  export { encodeText, encodeTextSync } from "./lib/api/encode.js";
16
+ export { createDataSource } from "./lib/api/create-data-source.js";
17
+ export { selectSource as _selectSource } from "./lib/api/select-source.js";
16
18
  export { setPathPrefix, getPathPrefix, resolvePath } from '@loaders.gl/loader-utils';
17
19
  export { RequestScheduler } from '@loaders.gl/loader-utils';
18
20
  export { makeIterator } from "./iterators/make-iterator/make-iterator.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,MAAM,EACN,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,IAAI,EACJ,UAAU,EACV,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAC,SAAS,EAAC,kCAA+B;AACjD,OAAO,EAAC,UAAU,EAAC,mCAAgC;AAEnD,OAAO,EAAC,eAAe,EAAC,yCAAsC;AAK9D,OAAO,EAAC,gBAAgB,EAAE,gBAAgB,EAAC,oCAAiC;AAC5E,OAAO,EAAC,eAAe,EAAC,sCAAmC;AAC3D,OAAO,EAAC,YAAY,EAAE,gBAAgB,EAAC,mCAAgC;AAGvE,OAAO,EAAC,KAAK,EAAC,2BAAwB;AACtC,OAAO,EAAC,SAAS,EAAC,gCAA6B;AAC/C,OAAO,EAAC,cAAc,EAAC,sCAAm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C,yBAAsB;AAC3D,OAAO,EAAC,UAAU,EAAC,MAAM,0BAA0B,CAAC;AAGpD,OAAO,EAAC,aAAa,IAAI,cAAc,EAAC,yCAAsC;AAC9E,OAAO,EAAC,iBAAiB,IAAI,kBAAkB,EAAC,gDAA6C;AAG7F,OAAO,EAAC,kBAAkB,EAAC,sCAAmC;AAM9D,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAC,OAAO,EAAE,4BAA4B,EAAC,MAAM,0BAA0B,CAAC;AAE/E,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,YAAY,EACZ,SAAS,EACT,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EACjB,sCAAmC"}
package/dist/index.js CHANGED
@@ -21,6 +21,9 @@ export { loadInBatches } from "./lib/api/load-in-batches.js";
21
21
  export { encodeTable, encodeTableAsText, encodeTableInBatches } from "./lib/api/encode-table.js";
22
22
  export { encode, encodeSync, encodeInBatches, encodeURLtoURL } from "./lib/api/encode.js";
23
23
  export { encodeText, encodeTextSync } from "./lib/api/encode.js";
24
+ // SERVICES AND SOURCES
25
+ export { createDataSource } from "./lib/api/create-data-source.js";
26
+ export { selectSource as _selectSource } from "./lib/api/select-source.js";
24
27
  // CORE UTILS SHARED WITH LOADERS (RE-EXPORTED FROM LOADER-UTILS)
25
28
  export { setPathPrefix, getPathPrefix, resolvePath } from '@loaders.gl/loader-utils';
26
29
  export { RequestScheduler } from '@loaders.gl/loader-utils';
@@ -0,0 +1,13 @@
1
+ import type { DataSourceProps } from '@loaders.gl/loader-utils';
2
+ import { DataSource, Source } from '@loaders.gl/loader-utils';
3
+ /**
4
+ * Creates a source from a service
5
+ * If type is not supplied, will try to automatically detect the the
6
+ * @param url URL to the data source
7
+ * @param type type of source. if not known, set to 'auto'
8
+ * @returns an DataSource instance
9
+ */
10
+ export declare function createDataSource<DataSourcePropsT extends DataSourceProps = DataSourceProps, DataSourceT extends DataSource = DataSource>(data: string | Blob, sources: Source[], props: DataSourcePropsT & {
11
+ type?: string;
12
+ }): DataSourceT;
13
+ //# sourceMappingURL=create-data-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-data-source.d.ts","sourceRoot":"","sources":["../../../src/lib/api/create-data-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAE5D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,gBAAgB,SAAS,eAAe,GAAG,eAAe,EAC1D,WAAW,SAAS,UAAU,GAAG,UAAU,EAC3C,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,gBAAgB,GAAG;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,WAAW,CAQhG"}
@@ -0,0 +1,38 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /**
5
+ * Creates a source from a service
6
+ * If type is not supplied, will try to automatically detect the the
7
+ * @param url URL to the data source
8
+ * @param type type of source. if not known, set to 'auto'
9
+ * @returns an DataSource instance
10
+ */
11
+ export function createDataSource(data, sources, props) {
12
+ const { type = 'auto' } = props;
13
+ const source = type === 'auto' ? selectSource(data, sources) : getSourceOfType(type, sources);
14
+ if (!source) {
15
+ throw new Error('Not a valid image source type');
16
+ }
17
+ return source.createDataSource(data, props);
18
+ }
19
+ // TODO - use selectSource...
20
+ /** Guess service type from URL */
21
+ function selectSource(url, sources) {
22
+ for (const service of sources) {
23
+ // @ts-expect-error
24
+ if (service.testURL && service.testURL(url)) {
25
+ return service;
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ /** Guess service type from URL */
31
+ function getSourceOfType(type, sources) {
32
+ for (const service of sources) {
33
+ if (service.type === type) {
34
+ return service;
35
+ }
36
+ }
37
+ return null;
38
+ }
@@ -0,0 +1,8 @@
1
+ import type { Source } from '@loaders.gl/loader-utils';
2
+ /** Guess service type from URL */
3
+ export declare function selectSource(url: string | Blob, sources: Source[], options?: {
4
+ /** Provide id of a source to select that source. Omit or provide 'auto' to test the source*/
5
+ type?: string;
6
+ nothrow?: boolean;
7
+ }): Source | null;
8
+ //# sourceMappingURL=select-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-source.d.ts","sourceRoot":"","sources":["../../../src/lib/api/select-source.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAErD,kCAAkC;AAClC,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,CAAC,EAAE;IACR,6FAA6F;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,MAAM,GAAG,IAAI,CAkBf"}
@@ -0,0 +1,31 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ /** Guess service type from URL */
5
+ export function selectSource(url, sources, options) {
6
+ const type = options?.type || 'auto';
7
+ let selectedSource = null;
8
+ if (type === 'auto') {
9
+ for (const source of sources) {
10
+ if (typeof url === 'string' && source.testURL && source.testURL(url)) {
11
+ return source;
12
+ }
13
+ }
14
+ }
15
+ else {
16
+ selectedSource = getSourceOfType(type, sources);
17
+ }
18
+ if (!selectedSource && !options?.nothrow) {
19
+ throw new Error('Not a valid image source type');
20
+ }
21
+ return selectedSource;
22
+ }
23
+ /** Guess service type from URL */
24
+ function getSourceOfType(type, sources) {
25
+ for (const service of sources) {
26
+ if (service.type === type) {
27
+ return service;
28
+ }
29
+ }
30
+ return null;
31
+ }
package/dist/lib/init.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  import { log } from '@loaders.gl/loader-utils';
5
5
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
- const version = typeof "4.3.0-alpha.1" !== 'undefined' ? "4.3.0-alpha.1" : '';
6
+ const version = typeof "4.3.0-alpha.3" !== 'undefined' ? "4.3.0-alpha.3" : '';
7
7
  // @ts-ignore
8
8
  if (!globalThis.loaders) {
9
9
  log.log(1, `loaders.gl ${version}`)();
@@ -76,11 +76,13 @@ async function getResponseError(response) {
76
76
  url: response.url,
77
77
  response
78
78
  };
79
+ // See if we got an error message in the body
79
80
  try {
80
81
  const contentType = response.headers.get('Content-Type');
81
- info.reason = contentType?.includes('application/json')
82
- ? await response.json()
83
- : response.text();
82
+ info.reason =
83
+ !response.bodyUsed && contentType?.includes('application/json')
84
+ ? await response.json()
85
+ : await response.text();
84
86
  }
85
87
  catch (error) {
86
88
  // eslint forbids return in a finally statement, so we just catch here
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  // __VERSION__ is injected by babel-plugin-version-inline
5
5
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
- const VERSION = typeof "4.3.0-alpha.1" !== 'undefined' ? "4.3.0-alpha.1" : 'latest';
6
+ const VERSION = typeof "4.3.0-alpha.3" !== 'undefined' ? "4.3.0-alpha.3" : 'latest';
7
7
  /**
8
8
  * Loads any data and returns null (or optionally passes through data unparsed)
9
9
  */
@@ -235,7 +235,7 @@ async function parseData({
235
235
  }
236
236
 
237
237
  // src/null-loader.ts
238
- var VERSION = true ? "4.3.0-alpha.1" : "latest";
238
+ var VERSION = true ? "4.3.0-alpha.3" : "latest";
239
239
  var NullLoader = {
240
240
  dataType: null,
241
241
  batchType: null,
@@ -200,7 +200,7 @@
200
200
  }
201
201
 
202
202
  // src/null-loader.ts
203
- var VERSION = true ? "4.3.0-alpha.1" : "latest";
203
+ var VERSION = true ? "4.3.0-alpha.3" : "latest";
204
204
  var NullLoader = {
205
205
  dataType: null,
206
206
  batchType: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/core",
3
- "version": "4.3.0-alpha.2",
3
+ "version": "4.3.0-alpha.4",
4
4
  "description": "The core API for working with loaders.gl loaders and writers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -55,10 +55,10 @@
55
55
  "build-worker-node": "esbuild src/workers/null-worker.ts --outfile=dist/null-worker-node.js --bundle --platform=node --target=node16 --define:__VERSION__=\\\"$npm_package_version\\\""
56
56
  },
57
57
  "dependencies": {
58
- "@loaders.gl/loader-utils": "4.3.0-alpha.2",
59
- "@loaders.gl/schema": "4.3.0-alpha.2",
60
- "@loaders.gl/worker-utils": "4.3.0-alpha.2",
58
+ "@loaders.gl/loader-utils": "4.3.0-alpha.4",
59
+ "@loaders.gl/schema": "4.3.0-alpha.4",
60
+ "@loaders.gl/worker-utils": "4.3.0-alpha.4",
61
61
  "@probe.gl/log": "^4.0.2"
62
62
  },
63
- "gitHead": "77a3cb538ab7a1fbf74245f25590210451689f5c"
63
+ "gitHead": "4900ac4c4de20366c050b80cef04dc5b52d167af"
64
64
  }
package/src/index.ts CHANGED
@@ -46,6 +46,10 @@ export {encodeTable, encodeTableAsText, encodeTableInBatches} from './lib/api/en
46
46
  export {encode, encodeSync, encodeInBatches, encodeURLtoURL} from './lib/api/encode';
47
47
  export {encodeText, encodeTextSync} from './lib/api/encode';
48
48
 
49
+ // SERVICES AND SOURCES
50
+ export {createDataSource} from './lib/api/create-data-source';
51
+ export {selectSource as _selectSource} from './lib/api/select-source';
52
+
49
53
  // CORE UTILS SHARED WITH LOADERS (RE-EXPORTED FROM LOADER-UTILS)
50
54
  export {setPathPrefix, getPathPrefix, resolvePath} from '@loaders.gl/loader-utils';
51
55
  export {RequestScheduler} from '@loaders.gl/loader-utils';
@@ -0,0 +1,50 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {DataSourceProps} from '@loaders.gl/loader-utils';
6
+ import {DataSource, Source} from '@loaders.gl/loader-utils';
7
+
8
+ /**
9
+ * Creates a source from a service
10
+ * If type is not supplied, will try to automatically detect the the
11
+ * @param url URL to the data source
12
+ * @param type type of source. if not known, set to 'auto'
13
+ * @returns an DataSource instance
14
+ */
15
+ export function createDataSource<
16
+ DataSourcePropsT extends DataSourceProps = DataSourceProps,
17
+ DataSourceT extends DataSource = DataSource
18
+ >(data: string | Blob, sources: Source[], props: DataSourcePropsT & {type?: string}): DataSourceT {
19
+ const {type = 'auto'} = props;
20
+ const source = type === 'auto' ? selectSource(data, sources) : getSourceOfType(type, sources);
21
+
22
+ if (!source) {
23
+ throw new Error('Not a valid image source type');
24
+ }
25
+ return source.createDataSource(data, props) as DataSourceT;
26
+ }
27
+
28
+ // TODO - use selectSource...
29
+
30
+ /** Guess service type from URL */
31
+ function selectSource(url: string | Blob, sources: Source[]): Source | null {
32
+ for (const service of sources) {
33
+ // @ts-expect-error
34
+ if (service.testURL && service.testURL(url)) {
35
+ return service;
36
+ }
37
+ }
38
+
39
+ return null;
40
+ }
41
+
42
+ /** Guess service type from URL */
43
+ function getSourceOfType(type: string, sources: Source[]): Source | null {
44
+ for (const service of sources) {
45
+ if (service.type === type) {
46
+ return service;
47
+ }
48
+ }
49
+ return null;
50
+ }
@@ -0,0 +1,44 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Source} from '@loaders.gl/loader-utils';
6
+
7
+ /** Guess service type from URL */
8
+ export function selectSource(
9
+ url: string | Blob,
10
+ sources: Source[],
11
+ options?: {
12
+ /** Provide id of a source to select that source. Omit or provide 'auto' to test the source*/
13
+ type?: string;
14
+ nothrow?: boolean;
15
+ }
16
+ ): Source | null {
17
+ const type = options?.type || 'auto';
18
+ let selectedSource: Source | null = null;
19
+ if (type === 'auto') {
20
+ for (const source of sources) {
21
+ if (typeof url === 'string' && source.testURL && source.testURL(url)) {
22
+ return source;
23
+ }
24
+ }
25
+ } else {
26
+ selectedSource = getSourceOfType(type, sources);
27
+ }
28
+
29
+ if (!selectedSource && !options?.nothrow) {
30
+ throw new Error('Not a valid image source type');
31
+ }
32
+
33
+ return selectedSource;
34
+ }
35
+
36
+ /** Guess service type from URL */
37
+ function getSourceOfType(type: string, sources: Source[]): Source | null {
38
+ for (const service of sources) {
39
+ if (service.type === type) {
40
+ return service;
41
+ }
42
+ }
43
+ return null;
44
+ }
@@ -90,11 +90,13 @@ async function getResponseError(response: Response): Promise<Error> {
90
90
  response
91
91
  };
92
92
 
93
+ // See if we got an error message in the body
93
94
  try {
94
95
  const contentType = response.headers.get('Content-Type');
95
- info.reason = contentType?.includes('application/json')
96
- ? await response.json()
97
- : response.text();
96
+ info.reason =
97
+ !response.bodyUsed && contentType?.includes('application/json')
98
+ ? await response.json()
99
+ : await response.text();
98
100
  } catch (error) {
99
101
  // eslint forbids return in a finally statement, so we just catch here
100
102
  }