@carto/api-client 0.5.0-alpha.1 → 0.5.0-alpha.13

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 (127) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/api-client.cjs +3162 -3206
  3. package/build/api-client.cjs.map +1 -1
  4. package/build/api-client.d.cts +1399 -0
  5. package/build/api-client.d.ts +1399 -0
  6. package/build/api-client.js +3673 -0
  7. package/build/api-client.js.map +1 -0
  8. package/build/worker.d.ts +2 -0
  9. package/build/worker.js +1949 -0
  10. package/build/worker.js.map +1 -0
  11. package/package.json +61 -46
  12. package/src/api/carto-api-error.ts +1 -1
  13. package/src/api/query.ts +5 -5
  14. package/src/api/request-with-parameters.ts +6 -6
  15. package/src/client.ts +3 -3
  16. package/src/constants-internal.ts +5 -11
  17. package/src/constants.ts +6 -6
  18. package/src/deck/get-data-filter-extension-props.ts +164 -0
  19. package/src/deck/index.ts +1 -0
  20. package/src/filters/Filter.ts +18 -8
  21. package/src/filters/FilterTypes.ts +2 -2
  22. package/src/filters/geosjonFeatures.ts +2 -2
  23. package/src/filters/tileFeatures.ts +12 -17
  24. package/src/filters.ts +4 -4
  25. package/src/geo.ts +12 -14
  26. package/src/global.d.ts +3 -8
  27. package/src/index.ts +3 -0
  28. package/src/models/common.ts +11 -9
  29. package/src/models/model.ts +3 -4
  30. package/src/operations/aggregation.ts +5 -5
  31. package/src/operations/applySorting.ts +4 -4
  32. package/src/operations/groupBy.ts +4 -4
  33. package/src/operations/groupByDate.ts +1 -1
  34. package/src/operations/histogram.ts +4 -4
  35. package/src/operations/scatterPlot.ts +4 -4
  36. package/src/sources/base-source.ts +8 -8
  37. package/src/sources/boundary-query-source.ts +2 -2
  38. package/src/sources/boundary-table-source.ts +2 -2
  39. package/src/sources/h3-query-source.ts +7 -5
  40. package/src/sources/h3-table-source.ts +7 -5
  41. package/src/sources/h3-tileset-source.ts +4 -4
  42. package/src/sources/index.ts +26 -26
  43. package/src/sources/quadbin-query-source.ts +7 -5
  44. package/src/sources/quadbin-table-source.ts +7 -5
  45. package/src/sources/quadbin-tileset-source.ts +4 -4
  46. package/src/sources/raster-source.ts +2 -2
  47. package/src/sources/types.ts +9 -3
  48. package/src/sources/vector-query-source.ts +2 -3
  49. package/src/sources/vector-table-source.ts +2 -3
  50. package/src/sources/vector-tileset-source.ts +5 -5
  51. package/src/spatial-index.ts +12 -10
  52. package/src/types-internal.ts +5 -5
  53. package/src/types.ts +15 -15
  54. package/src/utils/makeIntervalComplete.ts +1 -1
  55. package/src/utils.ts +3 -3
  56. package/src/widget-sources/index.ts +1 -0
  57. package/src/widget-sources/types.ts +6 -4
  58. package/src/widget-sources/widget-query-source.ts +6 -2
  59. package/src/widget-sources/widget-remote-source.ts +67 -26
  60. package/src/widget-sources/widget-source.ts +10 -25
  61. package/src/widget-sources/widget-table-source.ts +6 -2
  62. package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
  63. package/src/widget-sources/widget-tileset-source.ts +199 -299
  64. package/src/workers/constants.ts +13 -0
  65. package/src/workers/types.ts +19 -0
  66. package/src/workers/widget-tileset-worker.ts +40 -0
  67. package/build/api/carto-api-error.d.ts +0 -26
  68. package/build/api/endpoints.d.ts +0 -24
  69. package/build/api/index.d.ts +0 -5
  70. package/build/api/query.d.ts +0 -3
  71. package/build/api/request-with-parameters.d.ts +0 -10
  72. package/build/api-client.modern.js +0 -3574
  73. package/build/api-client.modern.js.map +0 -1
  74. package/build/client.d.ts +0 -14
  75. package/build/constants-internal.d.ts +0 -26
  76. package/build/constants.d.ts +0 -53
  77. package/build/filters/Filter.d.ts +0 -13
  78. package/build/filters/FilterTypes.d.ts +0 -3
  79. package/build/filters/geosjonFeatures.d.ts +0 -8
  80. package/build/filters/index.d.ts +0 -6
  81. package/build/filters/tileFeatures.d.ts +0 -20
  82. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  83. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  84. package/build/filters.d.ts +0 -39
  85. package/build/geo.d.ts +0 -19
  86. package/build/index.d.ts +0 -14
  87. package/build/models/common.d.ts +0 -27
  88. package/build/models/index.d.ts +0 -3
  89. package/build/models/model.d.ts +0 -37
  90. package/build/operations/aggregation.d.ts +0 -8
  91. package/build/operations/applySorting.d.ts +0 -20
  92. package/build/operations/groupBy.d.ts +0 -15
  93. package/build/operations/groupByDate.d.ts +0 -11
  94. package/build/operations/histogram.d.ts +0 -13
  95. package/build/operations/index.d.ts +0 -6
  96. package/build/operations/scatterPlot.d.ts +0 -14
  97. package/build/sources/base-source.d.ts +0 -4
  98. package/build/sources/boundary-query-source.d.ts +0 -10
  99. package/build/sources/boundary-table-source.d.ts +0 -8
  100. package/build/sources/h3-query-source.d.ts +0 -5
  101. package/build/sources/h3-table-source.d.ts +0 -5
  102. package/build/sources/h3-tileset-source.d.ts +0 -5
  103. package/build/sources/index.d.ts +0 -26
  104. package/build/sources/quadbin-query-source.d.ts +0 -5
  105. package/build/sources/quadbin-table-source.d.ts +0 -5
  106. package/build/sources/quadbin-tileset-source.d.ts +0 -5
  107. package/build/sources/raster-source.d.ts +0 -4
  108. package/build/sources/types.d.ts +0 -366
  109. package/build/sources/vector-query-source.d.ts +0 -5
  110. package/build/sources/vector-table-source.d.ts +0 -5
  111. package/build/sources/vector-tileset-source.d.ts +0 -5
  112. package/build/spatial-index.d.ts +0 -8
  113. package/build/types-internal.d.ts +0 -56
  114. package/build/types.d.ts +0 -140
  115. package/build/utils/dateUtils.d.ts +0 -10
  116. package/build/utils/getTileFormat.d.ts +0 -3
  117. package/build/utils/makeIntervalComplete.d.ts +0 -2
  118. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  119. package/build/utils/transformToTileCoords.d.ts +0 -9
  120. package/build/utils.d.ts +0 -32
  121. package/build/widget-sources/index.d.ts +0 -5
  122. package/build/widget-sources/types.d.ts +0 -158
  123. package/build/widget-sources/widget-query-source.d.ts +0 -33
  124. package/build/widget-sources/widget-remote-source.d.ts +0 -18
  125. package/build/widget-sources/widget-source.d.ts +0 -74
  126. package/build/widget-sources/widget-table-source.d.ts +0 -33
  127. package/build/widget-sources/widget-tileset-source.d.ts +0 -76
package/src/client.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @internal
3
- * @internalRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
3
+ * @privateRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
4
4
  */
5
5
  let client = 'deck-gl-carto';
6
6
 
@@ -8,7 +8,7 @@ let client = 'deck-gl-carto';
8
8
  * Returns current client ID, used to categorize API requests. For internal use only.
9
9
  *
10
10
  * @internal
11
- * @internalRemarks Source: @carto/react-core
11
+ * @privateRemarks Source: @carto/react-core
12
12
  */
13
13
  export function getClient() {
14
14
  return client;
@@ -18,7 +18,7 @@ export function getClient() {
18
18
  * Sets current client ID, used to categorize API requests. For internal use only.
19
19
  *
20
20
  * @internal
21
- * @internalRemarks Source: @carto/react-core
21
+ * @privateRemarks Source: @carto/react-core
22
22
  */
23
23
  export function setClient(c: string) {
24
24
  client = c;
@@ -1,32 +1,26 @@
1
- /**
2
- * Current version of @carto/api-client.
3
- * @internal
4
- */
5
- export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
6
-
7
1
  /** @internal */
8
2
  export const V3_MINOR_VERSION = '3.4';
9
3
 
10
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
4
+ /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
11
5
  export const DEFAULT_GEO_COLUMN = 'geom';
12
6
 
13
7
  /**
14
8
  * Fastly default limit is 8192; leave some padding.
15
- * @internalRemarks Source: @deck.gl/carto
9
+ * @privateRemarks Source: @deck.gl/carto
16
10
  */
17
11
  export const DEFAULT_MAX_LENGTH_URL = 7000;
18
12
 
19
- /** @internalRemarks Source: @deck.gl/carto */
13
+ /** @privateRemarks Source: @deck.gl/carto */
20
14
  export const DEFAULT_TILE_RESOLUTION = 0.5;
21
15
 
22
16
  /**
23
- * @internalRemarks Source: @deck.gl/carto
17
+ * @privateRemarks Source: @deck.gl/carto
24
18
  * @internal
25
19
  */
26
20
  export const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
27
21
 
28
22
  /**
29
- * @internalRemarks Source: @deck.gl/carto
23
+ * @privateRemarks Source: @deck.gl/carto
30
24
  * @internal
31
25
  */
32
26
  export const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
package/src/constants.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * };
11
11
  * ```
12
12
  *
13
- * @internalRemarks Source: @carto/react-api, @deck.gl/carto
13
+ * @privateRemarks Source: @carto/react-api, @deck.gl/carto
14
14
  */
15
15
  export enum FilterType {
16
16
  IN = 'in',
@@ -22,17 +22,17 @@ export enum FilterType {
22
22
  STRING_SEARCH = 'stringSearch',
23
23
  }
24
24
 
25
- /** @internalRemarks Source: @carto/constants */
25
+ /** @privateRemarks Source: @carto/constants */
26
26
  export enum ApiVersion {
27
27
  V1 = 'v1',
28
28
  V2 = 'v2',
29
29
  V3 = 'v3',
30
30
  }
31
31
 
32
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
32
+ /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
33
33
  export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
34
34
 
35
- /** @internalRemarks Source: @carto/react-core */
35
+ /** @privateRemarks Source: @carto/react-core */
36
36
  export enum TileFormat {
37
37
  MVT = 'mvt',
38
38
  JSON = 'json',
@@ -40,14 +40,14 @@ export enum TileFormat {
40
40
  BINARY = 'binary',
41
41
  }
42
42
 
43
- /** @internalRemarks Source: @carto/react-core */
43
+ /** @privateRemarks Source: @carto/react-core */
44
44
  export enum SpatialIndex {
45
45
  H3 = 'h3',
46
46
  S2 = 's2',
47
47
  QUADBIN = 'quadbin',
48
48
  }
49
49
 
50
- /** @internalRemarks Source: @carto/react-core */
50
+ /** @privateRemarks Source: @carto/react-core */
51
51
  export enum Provider {
52
52
  BIGQUERY = 'bigquery',
53
53
  REDSHIFT = 'redshift',
@@ -0,0 +1,164 @@
1
+ import {Feature} from 'geojson';
2
+ import {FilterLogicalOperator, Filters} from '../types.js';
3
+ import {FilterType} from '../constants.js';
4
+ import {_buildFeatureFilter} from '../filters/index.js';
5
+ import {FeatureData} from '../types-internal.js';
6
+
7
+ type TimeFilter = Filters['string'][FilterType.TIME] & {
8
+ params?: {offsetBy?: number};
9
+ };
10
+
11
+ /**
12
+ * deck.gl's DataFilterExtension supports GPU filtering with 1–4 values. We
13
+ * allocate filters[0] to generic filters and filters[1] to time filters.
14
+ *
15
+ * getFilterValue() _must_ return an array of the same size as the filterSize
16
+ * used to initialize the DataFilterExtension. We document that users must use
17
+ * filterSize=4 for compatibility with @link {getDataFilterExtensionProps}.
18
+ */
19
+ const DEFAULT_FILTER_SIZE = 4;
20
+
21
+ /** @experimental Prefer type definition from deck.gl. */
22
+ export type _DataFilterExtensionProps = {
23
+ filterRange: number[][];
24
+ updateTriggers: Record<string, string>;
25
+ getFilterValue: (feature: Feature | FeatureData) => number[];
26
+ };
27
+
28
+ /**
29
+ * Creates props for DataFilterExtension, from `@deck.gl/extensions`, given
30
+ * a set of filters. Requires that DataFilterExtension is initialized with
31
+ * filterSize=4, where the CARTO filters will occupy the first two slots.
32
+ *
33
+ * @example To create a deck.gl layer with GPU data filtering:
34
+ * ```typescript
35
+ * import {DataFilterExtension} from '@deck.gl/extensions';
36
+ * import {VectorTileLayer} from '@deck.gl/layers';
37
+ * import {getDataFilterExtensionProps} from '@carto/api-client';
38
+ *
39
+ * const layer = new VectorTileLayer({
40
+ * data: data,
41
+ * extensions: [new DataFilterExtension({filterSize: 4})],
42
+ * ...getDataFilterExtensionProps(filters),
43
+ * });
44
+ * ```
45
+ */
46
+ export function getDataFilterExtensionProps(
47
+ filters: Filters,
48
+ filtersLogicalOperator?: FilterLogicalOperator
49
+ ): _DataFilterExtensionProps {
50
+ const {filtersWithoutTimeType, timeColumn, timeFilter} =
51
+ getFiltersByType(filters);
52
+ return {
53
+ filterRange: getFilterRange(timeFilter, DEFAULT_FILTER_SIZE),
54
+ updateTriggers: getUpdateTriggers(
55
+ filtersWithoutTimeType,
56
+ timeColumn,
57
+ timeFilter
58
+ ),
59
+ getFilterValue: getFilterValue(
60
+ filtersWithoutTimeType,
61
+ timeColumn,
62
+ timeFilter,
63
+ DEFAULT_FILTER_SIZE,
64
+ filtersLogicalOperator
65
+ ),
66
+ };
67
+ }
68
+
69
+ /** @internal */
70
+ function getFiltersByType(filters: Filters) {
71
+ const filtersWithoutTimeType: Filters = {};
72
+
73
+ let timeColumn: string | null = null;
74
+ let timeFilter: TimeFilter | null = null;
75
+
76
+ for (const [column, columnData] of Object.entries(filters)) {
77
+ for (const [type, typeData] of Object.entries(columnData) as [
78
+ FilterType,
79
+ unknown,
80
+ ][]) {
81
+ if (type === FilterType.TIME) {
82
+ timeColumn = column;
83
+ timeFilter = typeData as TimeFilter;
84
+ } else {
85
+ filtersWithoutTimeType[column] = {[type]: typeData};
86
+ }
87
+ }
88
+ }
89
+
90
+ return {
91
+ filtersWithoutTimeType,
92
+ timeColumn,
93
+ timeFilter,
94
+ };
95
+ }
96
+
97
+ /** @internal */
98
+ function getFilterRange(
99
+ timeFilter: TimeFilter | null,
100
+ filterSize: number
101
+ ): number[][] {
102
+ const result = Array(filterSize).fill([0, 0]);
103
+ // According to getFilterValue all filters are resolved as 0 or 1 in the first position of the array
104
+ // except the time filter value that is resolved with the real value of the feature in the second position of the array
105
+ result[0] = [1, 1];
106
+ if (timeFilter) {
107
+ const offsetBy = timeFilter.params?.offsetBy || 0;
108
+ result[1] = timeFilter.values[0].map((v) => v - offsetBy);
109
+ }
110
+ return result;
111
+ }
112
+
113
+ /** @internal */
114
+ function getUpdateTriggers(
115
+ filtersWithoutTimeType: Filters,
116
+ timeColumn: string | null,
117
+ timeFilter: TimeFilter | null
118
+ ) {
119
+ const result: Record<string, object> = {...filtersWithoutTimeType};
120
+
121
+ // We don't want to change the layer UpdateTriggers every time that the time filter changes
122
+ // because this filter is changed by the time series widget during its animation
123
+ // so we remove the time filter value from the `updateTriggers`
124
+ if (timeColumn && timeFilter) {
125
+ result[timeColumn] = {
126
+ ...result[timeColumn],
127
+ offsetBy: timeFilter.params?.offsetBy,
128
+ [FilterType.TIME]: {}, // Allows working with other filters, without an impact on performance.
129
+ };
130
+ }
131
+ return {
132
+ getFilterValue: JSON.stringify(result),
133
+ };
134
+ }
135
+
136
+ /** @internal */
137
+ function getFilterValue(
138
+ filtersWithoutTimeType: Filters,
139
+ timeColumn: string | null,
140
+ timeFilter: TimeFilter | null,
141
+ filterSize: number,
142
+ filtersLogicalOperator?: FilterLogicalOperator
143
+ ) {
144
+ const result = Array(filterSize).fill(0);
145
+ const featureFilter = _buildFeatureFilter({
146
+ filters: filtersWithoutTimeType,
147
+ type: 'number',
148
+ filtersLogicalOperator,
149
+ });
150
+
151
+ // We evaluate all filters except the time filter using _buildFeatureFilter function.
152
+ // For the time filter, we return the value of the feature and we will change the getFilterRange result
153
+ // every time this filter changes
154
+ return (feature: Feature | FeatureData) => {
155
+ result[0] = featureFilter(feature);
156
+
157
+ if (timeColumn && timeFilter) {
158
+ const offsetBy = timeFilter.params?.offsetBy || 0;
159
+ const f = (feature.properties || feature) as Record<string, unknown>;
160
+ result[1] = (f[timeColumn] as number) - offsetBy;
161
+ }
162
+ return result;
163
+ };
164
+ }
@@ -0,0 +1 @@
1
+ export * from './get-data-filter-extension-props.js';
@@ -1,8 +1,8 @@
1
- import {filterFunctions} from './FilterTypes';
2
- import {Filter, FilterLogicalOperator, Filters} from '../types';
1
+ import {filterFunctions} from './FilterTypes.js';
2
+ import {Filter, FilterLogicalOperator, Filters} from '../types.js';
3
3
  import {Feature} from 'geojson';
4
- import {FilterType} from '../constants';
5
- import {FeatureData} from '../types-internal';
4
+ import {FilterType} from '../constants.js';
5
+ import {FeatureData} from '../types-internal.js';
6
6
  import {BinaryFeature} from '@loaders.gl/schema';
7
7
 
8
8
  const LOGICAL_OPERATOR_METHODS: Record<
@@ -44,7 +44,11 @@ function passesFilter(
44
44
  });
45
45
  }
46
46
 
47
- export function buildFeatureFilter({
47
+ /**
48
+ * @internal
49
+ * @privateRemarks Exported for use in @deck.gl/carto's getDataFilterExtensionProps.
50
+ */
51
+ export function _buildFeatureFilter({
48
52
  filters = {},
49
53
  type = 'boolean',
50
54
  filtersLogicalOperator = 'and',
@@ -74,18 +78,24 @@ export function buildFeatureFilter({
74
78
  };
75
79
  }
76
80
 
77
- // Apply certain filters to a collection of features
81
+ /**
82
+ * Apply certain filters to a collection of features.
83
+ * @internal
84
+ */
78
85
  export function applyFilters(
79
86
  features: FeatureData[],
80
87
  filters: Filters,
81
88
  filtersLogicalOperator: FilterLogicalOperator
82
89
  ) {
83
90
  return Object.keys(filters).length
84
- ? features.filter(buildFeatureFilter({filters, filtersLogicalOperator}))
91
+ ? features.filter(_buildFeatureFilter({filters, filtersLogicalOperator}))
85
92
  : features;
86
93
  }
87
94
 
88
- // Binary
95
+ /**
96
+ * Binary.
97
+ * @internal
98
+ */
89
99
  export function buildBinaryFeatureFilter({filters = {}}: {filters: Filters}) {
90
100
  const columns = Object.keys(filters);
91
101
 
@@ -1,5 +1,5 @@
1
- import {FilterType} from '../constants';
2
- import {FilterInterval, StringSearchOptions} from '../types';
1
+ import {FilterType} from '../constants.js';
2
+ import {FilterInterval, StringSearchOptions} from '../types.js';
3
3
  import {makeIntervalComplete} from '../utils/makeIntervalComplete.js';
4
4
 
5
5
  export type FilterFunction = (
@@ -1,7 +1,7 @@
1
1
  import intersects from '@turf/boolean-intersects';
2
2
  import {FeatureCollection} from 'geojson';
3
- import {SpatialFilter} from '..';
4
- import {FeatureData} from '../types-internal';
3
+ import {FeatureData} from '../types-internal.js';
4
+ import {SpatialFilter} from '../types.js';
5
5
 
6
6
  export function geojsonFeatures({
7
7
  geojson,
@@ -1,28 +1,29 @@
1
- import {SpatialFilter, SpatialIndexTile, Tile} from '../types';
2
- import {tileFeaturesGeometries} from './tileFeaturesGeometries';
3
- import {tileFeaturesSpatialIndex} from './tileFeaturesSpatialIndex';
4
- import {SpatialIndex, TileFormat} from '../constants';
5
- import {DEFAULT_GEO_COLUMN} from '../constants-internal';
6
- import {FeatureData} from '../types-internal';
7
- import {SpatialDataType} from '../sources/types';
1
+ import {SpatialFilter, SpatialIndexTile, Tile} from '../types.js';
2
+ import {tileFeaturesGeometries} from './tileFeaturesGeometries.js';
3
+ import {tileFeaturesSpatialIndex} from './tileFeaturesSpatialIndex.js';
4
+ import {TileFormat} from '../constants.js';
5
+ import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
6
+ import {FeatureData} from '../types-internal.js';
7
+ import {SpatialDataType} from '../sources/types.js';
8
8
 
9
- /** @internalRemarks Source: @carto/react-core */
9
+ /** @privateRemarks Source: @carto/react-core */
10
10
  export type TileFeatures = {
11
11
  tiles: Tile[];
12
12
  tileFormat: TileFormat;
13
13
  spatialDataType: SpatialDataType;
14
14
  spatialDataColumn?: string;
15
- spatialFilter?: SpatialFilter;
15
+ spatialFilter: SpatialFilter;
16
16
  uniqueIdProperty?: string;
17
17
  options?: TileFeatureExtractOptions;
18
18
  };
19
19
 
20
- /** @internalRemarks Source: @carto/react-core */
20
+ /** @privateRemarks Source: @carto/react-core */
21
21
  export type TileFeatureExtractOptions = {
22
22
  storeGeometry?: boolean;
23
+ uniqueIdProperty?: string;
23
24
  };
24
25
 
25
- /** @internalRemarks Source: @carto/react-core */
26
+ /** @privateRemarks Source: @carto/react-core */
26
27
  export function tileFeatures({
27
28
  tiles,
28
29
  spatialFilter,
@@ -32,12 +33,6 @@ export function tileFeatures({
32
33
  spatialDataType,
33
34
  options = {},
34
35
  }: TileFeatures): FeatureData[] {
35
- // TODO(cleanup): Is an empty response the expected result when spatialFilter
36
- // is omitted? Why not make the parameter required, or return the full input?
37
- if (!spatialFilter) {
38
- return [];
39
- }
40
-
41
36
  if (spatialDataType !== 'geo') {
42
37
  return tileFeaturesSpatialIndex({
43
38
  tiles: tiles as SpatialIndexTile[],
package/src/filters.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {FilterType} from './constants';
2
- import {Filter} from './types';
3
- import {isEmptyObject} from './utils';
1
+ import {FilterType} from './constants.js';
2
+ import {Filter} from './types.js';
3
+ import {isEmptyObject} from './utils.js';
4
4
 
5
5
  type FilterTypeOptions<T extends FilterType> = {
6
6
  type: T;
@@ -121,7 +121,7 @@ export function getFilter<T extends FilterType>(
121
121
  return null;
122
122
  }
123
123
 
124
- if (!owner || owner === filter[type as FilterType]?.owner) {
124
+ if (!owner || owner === filter[type]?.owner) {
125
125
  return filter[type] || null;
126
126
  }
127
127
 
package/src/geo.ts CHANGED
@@ -4,7 +4,7 @@ import union from '@turf/union';
4
4
  import {getType} from '@turf/invariant';
5
5
  import {polygon, multiPolygon, feature, featureCollection} from '@turf/helpers';
6
6
  import type {BBox, Geometry, MultiPolygon, Polygon, Position} from 'geojson';
7
- import {SpatialFilter} from './types';
7
+ import {SpatialFilter} from './types.js';
8
8
 
9
9
  /**
10
10
  * Returns a {@link SpatialFilter} for a given viewport, typically obtained
@@ -40,7 +40,7 @@ export function createPolygonSpatialFilter(
40
40
  * Check if a viewport is large enough to represent a global coverage.
41
41
  * In this case the spatial filter parameter for widget calculation is removed.
42
42
  *
43
- * @internalRemarks Source: @carto/react-core
43
+ * @privateRemarks Source: @carto/react-core
44
44
  */
45
45
  function _isGlobalViewport(viewport: BBox) {
46
46
  const [minx, miny, maxx, maxy] = viewport;
@@ -54,7 +54,7 @@ function _isGlobalViewport(viewport: BBox) {
54
54
  *
55
55
  * It results in a Polygon or MultiPolygon strictly inside the validity range.
56
56
  *
57
- * @internalRemarks Source: @carto/react-core
57
+ * @privateRemarks Source: @carto/react-core
58
58
  */
59
59
  function _normalizeGeometry(
60
60
  geometry: Polygon | MultiPolygon
@@ -100,19 +100,19 @@ function _normalizeGeometry(
100
100
  return result;
101
101
  }
102
102
 
103
- /** @internalRemarks Source: @carto/react-core */
103
+ /** @privateRemarks Source: @carto/react-core */
104
104
  function _cleanPolygonCoords(cc: Position[][]) {
105
105
  const coords = cc.filter((c) => c.length > 0);
106
106
  return coords.length > 0 ? coords : null;
107
107
  }
108
108
 
109
- /** @internalRemarks Source: @carto/react-core */
109
+ /** @privateRemarks Source: @carto/react-core */
110
110
  function _cleanMultiPolygonCoords(ccc: Position[][][]) {
111
111
  const coords = ccc.map(_cleanPolygonCoords).filter((cc) => cc);
112
112
  return coords.length > 0 ? coords : null;
113
113
  }
114
114
 
115
- /** @internalRemarks Source: @carto/react-core */
115
+ /** @privateRemarks Source: @carto/react-core */
116
116
  function _clean(
117
117
  geometry: Polygon | MultiPolygon | null
118
118
  ): Polygon | MultiPolygon | null {
@@ -121,36 +121,34 @@ function _clean(
121
121
  }
122
122
 
123
123
  if (_isPolygon(geometry)) {
124
- const coords = _cleanPolygonCoords((geometry as Polygon).coordinates);
124
+ const coords = _cleanPolygonCoords(geometry.coordinates);
125
125
  return coords ? polygon(coords).geometry : null;
126
126
  }
127
127
 
128
128
  if (_isMultiPolygon(geometry)) {
129
- const coords = _cleanMultiPolygonCoords(
130
- (geometry as MultiPolygon).coordinates
131
- );
129
+ const coords = _cleanMultiPolygonCoords(geometry.coordinates);
132
130
  return coords ? multiPolygon(coords as Position[][][]).geometry : null;
133
131
  }
134
132
 
135
133
  return null;
136
134
  }
137
135
 
138
- /** @internalRemarks Source: @carto/react-core */
136
+ /** @privateRemarks Source: @carto/react-core */
139
137
  function _txContourCoords(cc: Position[], distance: number) {
140
138
  return cc.map((c) => [c[0] + distance, c[1]]);
141
139
  }
142
140
 
143
- /** @internalRemarks Source: @carto/react-core */
141
+ /** @privateRemarks Source: @carto/react-core */
144
142
  function _txPolygonCoords(ccc: Position[][], distance: number) {
145
143
  return ccc.map((cc) => _txContourCoords(cc, distance));
146
144
  }
147
145
 
148
- /** @internalRemarks Source: @carto/react-core */
146
+ /** @privateRemarks Source: @carto/react-core */
149
147
  function _txMultiPolygonCoords(cccc: Position[][][], distance: number) {
150
148
  return cccc.map((ccc) => _txPolygonCoords(ccc, distance));
151
149
  }
152
150
 
153
- /** @internalRemarks Source: @carto/react-core */
151
+ /** @privateRemarks Source: @carto/react-core */
154
152
  function _tx(geometry: Polygon | MultiPolygon, distance: number) {
155
153
  if (geometry && getType(geometry) === 'Polygon') {
156
154
  const coords = _txPolygonCoords(
package/src/global.d.ts CHANGED
@@ -1,10 +1,5 @@
1
- /**
2
- * Injected by microbundle, with:
3
- * ```
4
- * --define __CARTO_API_CLIENT_VERSION=$npm_package_version
5
- * ```
6
- */
7
- declare const __CARTO_API_CLIENT_VERSION: string;
8
-
9
1
  /** Defined by @deck.gl/core. */
10
2
  declare const deck: {VERSION: string | undefined} | undefined;
3
+
4
+ /** Defined by tsup. */
5
+ declare const TSUP_FORMAT: 'esm' | 'cjs';
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './client.js';
2
2
  export * from './constants.js';
3
+ export * from './deck/index.js';
3
4
  export * from './filters.js';
4
5
  export * from './geo.js';
5
6
  export * from './sources/index.js';
@@ -17,6 +18,8 @@ export {
17
18
  requestWithParameters,
18
19
  } from './api/index.js';
19
20
 
21
+ export {_getHexagonResolution} from './spatial-index.js';
22
+
20
23
  // For unit testing only.
21
24
  export * from './filters/index.js';
22
25
  export * from './operations/index.js';
@@ -1,9 +1,10 @@
1
1
  import {InvalidColumnError} from '../utils.js';
2
2
 
3
- /** @internalRemarks Source: @carto/react-api */
3
+ /** @privateRemarks Source: @carto/react-api */
4
4
  export interface ModelRequestOptions {
5
5
  method: 'GET' | 'POST';
6
- abortController?: AbortController;
6
+ headers?: Record<string, string>;
7
+ signal?: AbortSignal;
7
8
  otherOptions?: Record<string, unknown>;
8
9
  body?: string;
9
10
  }
@@ -16,7 +17,7 @@ interface ModelErrorResponse {
16
17
 
17
18
  /**
18
19
  * Return more descriptive error from API
19
- * @internalRemarks Source: @carto/react-api
20
+ * @privateRemarks Source: @carto/react-api
20
21
  */
21
22
  export function dealWithApiError({
22
23
  response,
@@ -42,15 +43,15 @@ export function dealWithApiError({
42
43
  case 403:
43
44
  throw new Error('Forbidden access to the requested data');
44
45
  default:
45
- const msg =
46
+ throw new Error(
46
47
  data && data.error && typeof data.error === 'string'
47
48
  ? data.error
48
- : JSON.stringify(data?.hint || data.error?.[0]);
49
- throw new Error(msg);
49
+ : JSON.stringify(data?.hint || data.error?.[0])
50
+ );
50
51
  }
51
52
  }
52
53
 
53
- /** @internalRemarks Source: @carto/react-api */
54
+ /** @privateRemarks Source: @carto/react-api */
54
55
  export async function makeCall({
55
56
  url,
56
57
  accessToken,
@@ -68,19 +69,20 @@ export async function makeCall({
68
69
  headers: {
69
70
  Authorization: `Bearer ${accessToken}`,
70
71
  ...(isPost && {'Content-Type': 'application/json'}),
72
+ ...opts.headers,
71
73
  },
72
74
  ...(isPost && {
73
75
  method: opts?.method,
74
76
  body: opts?.body,
75
77
  }),
76
- signal: opts?.abortController?.signal,
78
+ signal: opts?.signal,
77
79
  ...opts?.otherOptions,
78
80
  });
79
81
  data = await response.json();
80
82
  } catch (error) {
81
83
  if ((error as Error).name === 'AbortError') throw error;
82
84
 
83
- throw new Error(`Failed request: ${error}`);
85
+ throw new Error(`Failed request: ${error as Error}`);
84
86
  }
85
87
 
86
88
  if (!response.ok) {
@@ -6,13 +6,12 @@ import {
6
6
  QueryParameters,
7
7
  SpatialFilter,
8
8
  } from '../types.js';
9
- import {$TODO} from '../types-internal.js';
10
9
  import {assert, isPureObject} from '../utils.js';
11
10
  import {ModelRequestOptions, makeCall} from './common.js';
12
11
  import {ApiVersion} from '../constants.js';
13
12
  import {SpatialDataType, SpatialFilterPolyfillMode} from '../sources/types.js';
14
13
 
15
- /** @internalRemarks Source: @carto/react-api */
14
+ /** @privateRemarks Source: @carto/react-api */
16
15
  const AVAILABLE_MODELS = [
17
16
  'category',
18
17
  'histogram',
@@ -51,7 +50,7 @@ const REQUEST_GET_MAX_URL_LENGTH = 2048;
51
50
 
52
51
  /**
53
52
  * Execute a SQL model request.
54
- * @internalRemarks Source: @carto/react-api
53
+ * @privateRemarks Source: @carto/react-api
55
54
  */
56
55
  export function executeModel(props: {
57
56
  model: Model;
@@ -152,7 +151,7 @@ function objectToURLSearchParams(object: Record<string, unknown>) {
152
151
  } else if (object[key] === null) {
153
152
  params.append(key, 'null');
154
153
  } else if (object[key] !== undefined) {
155
- params.append(key, String(object[key]));
154
+ params.append(key, String(object[key] as unknown));
156
155
  }
157
156
  }
158
157
  return params;
@@ -1,14 +1,14 @@
1
- import {AggregationType} from '../types';
2
- import {FeatureData} from '../types-internal';
1
+ import {AggregationType} from '../types.js';
2
+ import {FeatureData} from '../types-internal.js';
3
3
 
4
- /** @internalRemarks Source: @carto/react-core */
4
+ /** @privateRemarks Source: @carto/react-core */
5
5
  export type AggregationFunction = (
6
6
  values: unknown[] | FeatureData[],
7
7
  keys?: string[] | string,
8
8
  joinOperation?: AggregationType
9
9
  ) => number;
10
10
 
11
- /** @internalRemarks Source: @carto/react-core */
11
+ /** @privateRemarks Source: @carto/react-core */
12
12
  export const aggregationFunctions: Record<
13
13
  Exclude<AggregationType, 'custom'>,
14
14
  AggregationFunction
@@ -20,7 +20,7 @@ export const aggregationFunctions: Record<
20
20
  avg: (...args) => applyAggregationFunction(avg, ...args),
21
21
  };
22
22
 
23
- /** @internalRemarks Source: @carto/react-core */
23
+ /** @privateRemarks Source: @carto/react-core */
24
24
  export function aggregate(
25
25
  feature: FeatureData,
26
26
  keys?: string[],