@deck.gl/carto 9.0.0-beta.9 → 9.0.0

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "CARTO official integration with Deck.gl. Build geospatial applications using CARTO and Deck.gl.",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "version": "9.0.0-beta.9",
6
+ "version": "9.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -42,12 +42,12 @@
42
42
  "prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
43
43
  },
44
44
  "dependencies": {
45
- "@loaders.gl/gis": "^4.2.0-alpha.5",
46
- "@loaders.gl/loader-utils": "^4.2.0-alpha.5",
47
- "@loaders.gl/mvt": "^4.2.0-alpha.5",
48
- "@loaders.gl/schema": "^4.2.0-alpha.5",
49
- "@loaders.gl/tiles": "^4.2.0-alpha.5",
50
- "@luma.gl/constants": "^9.0.0",
45
+ "@loaders.gl/gis": "^4.1.4",
46
+ "@loaders.gl/loader-utils": "^4.1.4",
47
+ "@loaders.gl/mvt": "^4.1.4",
48
+ "@loaders.gl/schema": "^4.1.4",
49
+ "@loaders.gl/tiles": "^4.1.4",
50
+ "@luma.gl/constants": "^9.0.6",
51
51
  "@math.gl/web-mercator": "^4.0.0",
52
52
  "@types/d3-array": "^3.0.2",
53
53
  "@types/d3-color": "^1.4.2",
@@ -64,13 +64,13 @@
64
64
  "quadbin": "^0.2.0"
65
65
  },
66
66
  "peerDependencies": {
67
- "@deck.gl/aggregation-layers": "^9.0.0-beta",
68
- "@deck.gl/core": "^9.0.0-beta",
69
- "@deck.gl/extensions": "^9.0.0-beta",
70
- "@deck.gl/geo-layers": "^9.0.0-beta",
71
- "@deck.gl/layers": "^9.0.0-beta",
72
- "@loaders.gl/core": "^4.2.0-alpha.5",
67
+ "@deck.gl/aggregation-layers": "^9.0.0",
68
+ "@deck.gl/core": "^9.0.0",
69
+ "@deck.gl/extensions": "^9.0.0",
70
+ "@deck.gl/geo-layers": "^9.0.0",
71
+ "@deck.gl/layers": "^9.0.0",
72
+ "@loaders.gl/core": "^4.1.0",
73
73
  "@luma.gl/core": "^9.0.0"
74
74
  },
75
- "gitHead": "44cfc784310d1c6ac7766ff80e0df8c364f97354"
75
+ "gitHead": "fcb5ccf0a899e651949b24986488211e278e9321"
76
76
  }
@@ -9,7 +9,7 @@ function encodeParameter(name: string, value: string | boolean | number): string
9
9
  return `${name}=${encodeURIComponent(value)}`;
10
10
  }
11
11
 
12
- const REQUEST_CACHE = new Map();
12
+ const REQUEST_CACHE = new Map<string, Promise<unknown>>();
13
13
  export async function requestWithParameters<T = any>({
14
14
  accessToken,
15
15
  baseUrl,
@@ -25,47 +25,40 @@ export async function requestWithParameters<T = any>({
25
25
  }): Promise<T> {
26
26
  const key = createCacheKey(baseUrl, parameters || {}, customHeaders || {});
27
27
  if (REQUEST_CACHE.has(key)) {
28
- return REQUEST_CACHE.get(key);
29
- }
30
-
31
- let url = baseUrl;
32
- if (parameters) {
33
- const encodedParameters = Object.entries({...DEFAULT_PARAMETERS, ...parameters}).map(
34
- ([key, value]) => {
35
- return encodeParameter(key, value);
36
- }
37
- );
38
- url += `?${encodedParameters.join('&')}`;
28
+ return REQUEST_CACHE.get(key) as Promise<T>;
39
29
  }
40
30
 
31
+ const url = parameters ? createURLWithParameters(baseUrl, parameters) : baseUrl;
41
32
  const headers = {...DEFAULT_HEADERS, ...customHeaders};
42
- try {
43
- /* global fetch */
44
- let response: Response;
45
- if (url.length > MAX_GET_LENGTH) {
46
- response = await fetch(baseUrl, {method: 'POST', body: JSON.stringify(parameters), headers});
47
- } else {
48
- response = await fetch(url, {headers});
49
- }
50
- let json: any;
51
- try {
52
- json = await response.json();
33
+
34
+ /* global fetch */
35
+ const fetchPromise =
36
+ url.length > MAX_GET_LENGTH
37
+ ? fetch(baseUrl, {method: 'POST', body: JSON.stringify(parameters), headers})
38
+ : fetch(url, {headers});
39
+
40
+ let response: Response | undefined;
41
+ const jsonPromise: Promise<T> = fetchPromise
42
+ .then((_response: Response) => {
43
+ response = _response;
44
+ return response.json();
45
+ })
46
+ .then((json: any) => {
47
+ if (!response || !response.ok) {
48
+ throw new Error(json.error);
49
+ }
53
50
  if (accessToken) {
54
51
  json.accessToken = accessToken;
55
52
  }
56
- } catch {
57
- json = {error: ''};
58
- }
59
- if (!response.ok) {
53
+ return json;
54
+ })
55
+ .catch((error: Error) => {
60
56
  REQUEST_CACHE.delete(key);
61
- throw new CartoAPIError(json.error, errorContext, response);
62
- }
57
+ throw new CartoAPIError(error, errorContext, response);
58
+ });
63
59
 
64
- REQUEST_CACHE.set(key, json);
65
- return json;
66
- } catch (error) {
67
- throw new CartoAPIError(error as Error, errorContext);
68
- }
60
+ REQUEST_CACHE.set(key, jsonPromise);
61
+ return jsonPromise;
69
62
  }
70
63
 
71
64
  function createCacheKey(
@@ -77,3 +70,12 @@ function createCacheKey(
77
70
  const headerEntries = Object.entries(headers).sort(([a], [b]) => (a > b ? 1 : -1));
78
71
  return JSON.stringify({baseUrl, parameters: parameterEntries, headers: headerEntries});
79
72
  }
73
+
74
+ function createURLWithParameters(baseUrl: string, parameters: Record<string, string>): string {
75
+ const encodedParameters = Object.entries({...DEFAULT_PARAMETERS, ...parameters}).map(
76
+ ([key, value]) => {
77
+ return encodeParameter(key, value);
78
+ }
79
+ );
80
+ return `${baseUrl}?${encodedParameters.join('&')}`;
81
+ }
package/src/index.ts CHANGED
@@ -83,7 +83,13 @@ export {
83
83
  };
84
84
 
85
85
  export type {
86
+ GeojsonResult,
87
+ JsonResult,
86
88
  TilejsonResult,
89
+ SourceOptions,
90
+ QuerySourceOptions,
91
+ TableSourceOptions,
92
+ TilesetSourceOptions,
87
93
  BoundaryQuerySourceOptions,
88
94
  BoundaryTableSourceOptions,
89
95
  H3QuerySourceOptions,
@@ -95,7 +101,5 @@ export type {
95
101
  QuadbinTilesetSourceOptions,
96
102
  VectorQuerySourceOptions,
97
103
  VectorTableSourceOptions,
98
- VectorTilesetSourceOptions,
99
- GeojsonResult,
100
- JsonResult
104
+ VectorTilesetSourceOptions
101
105
  } from './sources/index';
@@ -16,7 +16,7 @@ import {
16
16
  import {GeoJsonLayer} from '@deck.gl/layers';
17
17
  import {binaryToGeojson} from '@loaders.gl/gis';
18
18
  import type {BinaryFeatureCollection} from '@loaders.gl/schema';
19
- import type {Feature} from 'geojson';
19
+ import type {Feature, Geometry} from 'geojson';
20
20
 
21
21
  import type {TilejsonResult} from '../sources/types';
22
22
  import {TilejsonPropType, injectAccessToken, mergeBoundaryData} from './utils';
@@ -153,7 +153,7 @@ export default class VectorTileLayer<
153
153
  const {data} = params.sourceLayer!.props;
154
154
  info.object = binaryToGeojson(data as BinaryFeatureCollection, {
155
155
  globalFeatureId: info.index
156
- }) as Feature;
156
+ }) as Feature<Geometry, FeaturePropertiesT>;
157
157
  }
158
158
 
159
159
  return info;
@@ -36,3 +36,10 @@ export type {VectorTableSourceOptions} from './vector-table-source';
36
36
 
37
37
  export {vectorTilesetSource} from './vector-tileset-source';
38
38
  export type {VectorTilesetSourceOptions} from './vector-tileset-source';
39
+
40
+ export type {
41
+ SourceOptions,
42
+ QuerySourceOptions,
43
+ TableSourceOptions,
44
+ TilesetSourceOptions
45
+ } from './types';