@carto/api-client 0.4.2-alpha.0 → 0.4.3

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 (48) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/build/api/query.d.ts +1 -1
  3. package/build/api-client.cjs +990 -1163
  4. package/build/api-client.cjs.map +1 -1
  5. package/build/api-client.modern.js +876 -1044
  6. package/build/api-client.modern.js.map +1 -1
  7. package/build/index.d.ts +1 -1
  8. package/build/models/model.d.ts +1 -7
  9. package/build/sources/boundary-query-source.d.ts +2 -1
  10. package/build/sources/boundary-table-source.d.ts +2 -1
  11. package/build/sources/h3-query-source.d.ts +2 -1
  12. package/build/sources/h3-table-source.d.ts +2 -1
  13. package/build/sources/h3-tileset-source.d.ts +2 -1
  14. package/build/sources/index.d.ts +13 -14
  15. package/build/sources/quadbin-query-source.d.ts +2 -1
  16. package/build/sources/quadbin-table-source.d.ts +2 -1
  17. package/build/sources/quadbin-tileset-source.d.ts +2 -1
  18. package/build/sources/raster-source.d.ts +2 -1
  19. package/build/sources/types.d.ts +57 -36
  20. package/build/sources/vector-query-source.d.ts +2 -1
  21. package/build/sources/vector-table-source.d.ts +2 -1
  22. package/build/sources/vector-tileset-source.d.ts +2 -1
  23. package/build/utils.d.ts +1 -1
  24. package/build/widget-sources/types.d.ts +1 -8
  25. package/build/widget-sources/widget-base-source.d.ts +1 -0
  26. package/package.json +1 -1
  27. package/src/api/query.ts +2 -1
  28. package/src/index.ts +1 -36
  29. package/src/models/model.ts +24 -47
  30. package/src/sources/boundary-query-source.ts +4 -2
  31. package/src/sources/boundary-table-source.ts +4 -2
  32. package/src/sources/h3-query-source.ts +4 -8
  33. package/src/sources/h3-table-source.ts +4 -7
  34. package/src/sources/h3-tileset-source.ts +4 -2
  35. package/src/sources/index.ts +54 -24
  36. package/src/sources/quadbin-query-source.ts +5 -7
  37. package/src/sources/quadbin-table-source.ts +5 -7
  38. package/src/sources/quadbin-tileset-source.ts +4 -2
  39. package/src/sources/raster-source.ts +4 -2
  40. package/src/sources/types.ts +63 -41
  41. package/src/sources/vector-query-source.ts +10 -5
  42. package/src/sources/vector-table-source.ts +10 -5
  43. package/src/sources/vector-tileset-source.ts +4 -2
  44. package/src/utils.ts +1 -1
  45. package/src/widget-sources/types.ts +1 -9
  46. package/src/widget-sources/widget-base-source.ts +21 -190
  47. package/build/spatial-index.d.ts +0 -11
  48. package/src/spatial-index.ts +0 -119
@@ -12,9 +12,11 @@ import type {
12
12
  export type H3TilesetSourceOptions = SourceOptions & TilesetSourceOptions;
13
13
  type UrlParameters = {name: string};
14
14
 
15
+ export type H3TilesetSourceResponse = TilejsonResult;
16
+
15
17
  export const h3TilesetSource = async function (
16
18
  options: H3TilesetSourceOptions
17
- ): Promise<TilejsonResult> {
19
+ ): Promise<H3TilesetSourceResponse> {
18
20
  const {tableName} = options;
19
21
  const urlParameters: UrlParameters = {name: tableName};
20
22
 
@@ -22,5 +24,5 @@ export const h3TilesetSource = async function (
22
24
  'tileset',
23
25
  options,
24
26
  urlParameters
25
- ) as Promise<TilejsonResult>;
27
+ ) as Promise<H3TilesetSourceResponse>;
26
28
  };
@@ -4,56 +4,86 @@
4
4
 
5
5
  export {SOURCE_DEFAULTS} from './base-source';
6
6
  export type {
7
- VectorLayer,
8
- RasterMetadataBandStats,
9
- RasterBandColorinterp,
10
- RasterMetadataBand,
11
- RasterMetadata,
12
- TilejsonResult,
13
7
  GeojsonResult,
14
8
  JsonResult,
15
9
  QueryResult,
10
+ QuerySourceOptions,
11
+ RasterBandColorinterp,
12
+ RasterMetadata,
13
+ RasterMetadataBand,
14
+ RasterMetadataBandStats,
15
+ SourceOptions,
16
+ TableSourceOptions,
17
+ TilejsonResult,
18
+ TilesetSourceOptions,
19
+ VectorLayer,
16
20
  } from './types';
17
21
 
18
22
  export {boundaryQuerySource} from './boundary-query-source';
19
- export type {BoundaryQuerySourceOptions} from './boundary-query-source';
23
+ export type {
24
+ BoundaryQuerySourceOptions,
25
+ BoundaryQuerySourceResponse,
26
+ } from './boundary-query-source';
20
27
 
21
28
  export {boundaryTableSource} from './boundary-table-source';
22
- export type {BoundaryTableSourceOptions} from './boundary-table-source';
29
+ export type {
30
+ BoundaryTableSourceOptions,
31
+ BoundaryTableSourceResponse,
32
+ } from './boundary-table-source';
23
33
 
24
34
  export {h3QuerySource} from './h3-query-source';
25
- export type {H3QuerySourceOptions} from './h3-query-source';
35
+ export type {
36
+ H3QuerySourceOptions,
37
+ H3QuerySourceResponse,
38
+ } from './h3-query-source';
26
39
 
27
40
  export {h3TableSource} from './h3-table-source';
28
- export type {H3TableSourceOptions} from './h3-table-source';
41
+ export type {
42
+ H3TableSourceOptions,
43
+ H3TableSourceResponse,
44
+ } from './h3-table-source';
29
45
 
30
46
  export {h3TilesetSource} from './h3-tileset-source';
31
- export type {H3TilesetSourceOptions} from './h3-tileset-source';
47
+ export type {
48
+ H3TilesetSourceOptions,
49
+ H3TilesetSourceResponse,
50
+ } from './h3-tileset-source';
32
51
 
33
52
  export {rasterSource} from './raster-source';
34
- export type {RasterSourceOptions} from './raster-source';
53
+ export type {RasterSourceOptions, RasterSourceResponse} from './raster-source';
35
54
 
36
55
  export {quadbinQuerySource} from './quadbin-query-source';
37
- export type {QuadbinQuerySourceOptions} from './quadbin-query-source';
56
+ export type {
57
+ QuadbinQuerySourceOptions,
58
+ QuadbinQuerySourceResponse,
59
+ } from './quadbin-query-source';
38
60
 
39
61
  export {quadbinTableSource} from './quadbin-table-source';
40
- export type {QuadbinTableSourceOptions} from './quadbin-table-source';
62
+ export type {
63
+ QuadbinTableSourceOptions,
64
+ QuadbinTableSourceResponse,
65
+ } from './quadbin-table-source';
41
66
 
42
67
  export {quadbinTilesetSource} from './quadbin-tileset-source';
43
- export type {QuadbinTilesetSourceOptions} from './quadbin-tileset-source';
68
+ export type {
69
+ QuadbinTilesetSourceOptions,
70
+ QuadbinTilesetSourceResponse,
71
+ } from './quadbin-tileset-source';
44
72
 
45
73
  export {vectorQuerySource} from './vector-query-source';
46
- export type {VectorQuerySourceOptions} from './vector-query-source';
74
+ export type {
75
+ VectorQuerySourceOptions,
76
+ VectorQuerySourceResponse,
77
+ } from './vector-query-source';
47
78
 
48
79
  export {vectorTableSource} from './vector-table-source';
49
- export type {VectorTableSourceOptions} from './vector-table-source';
80
+ export type {
81
+ VectorTableSourceOptions,
82
+ VectorTableSourceResponse,
83
+ } from './vector-table-source';
50
84
 
51
85
  export {vectorTilesetSource} from './vector-tileset-source';
52
- export type {VectorTilesetSourceOptions} from './vector-tileset-source';
53
-
54
86
  export type {
55
- SourceOptions,
56
- QuerySourceOptions,
57
- TableSourceOptions,
58
- TilesetSourceOptions,
59
- } from './types';
87
+ VectorTilesetSourceOptions,
88
+ VectorTilesetSourceResponse,
89
+ } from './vector-tileset-source';
@@ -30,9 +30,12 @@ type UrlParameters = {
30
30
  filters?: Record<string, unknown>;
31
31
  };
32
32
 
33
+ export type QuadbinQuerySourceResponse = TilejsonResult &
34
+ WidgetQuerySourceResult;
35
+
33
36
  export const quadbinQuerySource = async function (
34
37
  options: QuadbinQuerySourceOptions
35
- ): Promise<TilejsonResult & WidgetQuerySourceResult> {
38
+ ): Promise<QuadbinQuerySourceResponse> {
36
39
  const {
37
40
  aggregationExp,
38
41
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
@@ -60,12 +63,7 @@ export const quadbinQuerySource = async function (
60
63
  return baseSource<UrlParameters>('query', options, urlParameters).then(
61
64
  (result) => ({
62
65
  ...(result as TilejsonResult),
63
- widgetSource: new WidgetQuerySource({
64
- ...options,
65
- // NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
66
- spatialDataColumn,
67
- spatialDataType: 'quadbin',
68
- }),
66
+ widgetSource: new WidgetQuerySource(options),
69
67
  })
70
68
  );
71
69
  };
@@ -29,9 +29,12 @@ type UrlParameters = {
29
29
  filters?: Record<string, unknown>;
30
30
  };
31
31
 
32
+ export type QuadbinTableSourceResponse = TilejsonResult &
33
+ WidgetTableSourceResult;
34
+
32
35
  export const quadbinTableSource = async function (
33
36
  options: QuadbinTableSourceOptions
34
- ): Promise<TilejsonResult & WidgetTableSourceResult> {
37
+ ): Promise<QuadbinTableSourceResponse> {
35
38
  const {
36
39
  aggregationExp,
37
40
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
@@ -56,12 +59,7 @@ export const quadbinTableSource = async function (
56
59
  return baseSource<UrlParameters>('table', options, urlParameters).then(
57
60
  (result) => ({
58
61
  ...(result as TilejsonResult),
59
- widgetSource: new WidgetTableSource({
60
- ...options,
61
- // NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
62
- spatialDataColumn,
63
- spatialDataType: 'quadbin',
64
- }),
62
+ widgetSource: new WidgetTableSource(options),
65
63
  })
66
64
  );
67
65
  };
@@ -12,9 +12,11 @@ import type {
12
12
  export type QuadbinTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
13
13
  type UrlParameters = {name: string};
14
14
 
15
+ export type QuadbinTilesetSourceResponse = TilejsonResult;
16
+
15
17
  export const quadbinTilesetSource = async function (
16
18
  options: QuadbinTilesetSourceOptions
17
- ): Promise<TilejsonResult> {
19
+ ): Promise<QuadbinTilesetSourceResponse> {
18
20
  const {tableName} = options;
19
21
  const urlParameters: UrlParameters = {name: tableName};
20
22
 
@@ -22,5 +24,5 @@ export const quadbinTilesetSource = async function (
22
24
  'tileset',
23
25
  options,
24
26
  urlParameters
25
- ) as Promise<TilejsonResult>;
27
+ ) as Promise<QuadbinTilesetSourceResponse>;
26
28
  };
@@ -18,9 +18,11 @@ type UrlParameters = {
18
18
  filters?: Record<string, unknown>;
19
19
  };
20
20
 
21
+ export type RasterSourceResponse = TilejsonResult;
22
+
21
23
  export const rasterSource = async function (
22
24
  options: RasterSourceOptions
23
- ): Promise<TilejsonResult> {
25
+ ): Promise<RasterSourceResponse> {
24
26
  const {tableName, filters} = options;
25
27
  const urlParameters: UrlParameters = {name: tableName};
26
28
  if (filters) {
@@ -30,5 +32,5 @@ export const rasterSource = async function (
30
32
  'raster',
31
33
  options,
32
34
  urlParameters
33
- ) as Promise<TilejsonResult>;
35
+ ) as Promise<RasterSourceResponse>;
34
36
  };
@@ -48,33 +48,6 @@ export type SourceOptionalOptions = {
48
48
  */
49
49
  maxLengthURL?: number;
50
50
 
51
- /**
52
- * The column name and the type of geospatial support.
53
- *
54
- * If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
55
- */
56
- spatialDataColumn?: string;
57
-
58
- /**
59
- * The type of geospatial support. Defaults to `'geo'`.
60
- */
61
- spatialDataType?: SpatialDataType;
62
-
63
- /**
64
- * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
65
- * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
66
- * the quantization grid proportionately.
67
- *
68
- * Supported `tileResolution` values, with corresponding grid sizes:
69
- *
70
- * - 0.25: 256x256
71
- * - 0.5: 512x512
72
- * - 1: 1024x1024
73
- * - 2: 2048x2048
74
- * - 4: 4096x4096
75
- */
76
- tileResolution?: TileResolution;
77
-
78
51
  /**
79
52
  * By default, local in-memory caching is enabled.
80
53
  */
@@ -116,11 +89,6 @@ export type AggregationOptions = {
116
89
  * @default 6 for quadbin and 4 for h3 sources
117
90
  */
118
91
  aggregationResLevel?: number;
119
-
120
- /**
121
- * Original resolution of the spatial index data as stored in the DW
122
- */
123
- dataResolution?: number;
124
92
  };
125
93
 
126
94
  export type FilterOptions = {
@@ -131,9 +99,31 @@ export type FilterOptions = {
131
99
  };
132
100
 
133
101
  export type QuerySourceOptions = {
134
- /** Full SQL query with query paremeter placeholders (if any). */
102
+ /**
103
+ * The column name and the type of geospatial support.
104
+ *
105
+ * If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
106
+ */
107
+ spatialDataColumn?: string;
108
+
109
+ /** SQL query. */
135
110
  sqlQuery: string;
136
111
 
112
+ /**
113
+ * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
114
+ * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
115
+ * the quantization grid proportionately.
116
+ *
117
+ * Supported `tileResolution` values, with corresponding grid sizes:
118
+ *
119
+ * - 0.25: 256x256
120
+ * - 0.5: 512x512
121
+ * - 1: 1024x1024
122
+ * - 2: 2048x2048
123
+ * - 4: 4096x4096
124
+ */
125
+ tileResolution?: TileResolution;
126
+
137
127
  /**
138
128
  * Values for named or positional paramteres in the query.
139
129
  *
@@ -159,6 +149,15 @@ export type QuerySourceOptions = {
159
149
  * ```
160
150
  */
161
151
  queryParameters?: QueryParameters;
152
+
153
+ /**
154
+ * Comma-separated aggregation expressions. If assigned on a vector source, source is grouped by geometry and then aggregated.
155
+ *
156
+ * Example:
157
+ *
158
+ * 1 as value, avg(rev) as average_revenue
159
+ */
160
+ aggregationExp?: string;
162
161
  };
163
162
 
164
163
  export type TableSourceOptions = {
@@ -166,6 +165,37 @@ export type TableSourceOptions = {
166
165
  * Fully qualified name of table.
167
166
  */
168
167
  tableName: string;
168
+
169
+ /**
170
+ * The column name and the type of geospatial support.
171
+ *
172
+ * If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
173
+ */
174
+ spatialDataColumn?: string;
175
+
176
+ /**
177
+ * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
178
+ * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
179
+ * the quantization grid proportionately.
180
+ *
181
+ * Supported `tileResolution` values, with corresponding grid sizes:
182
+ *
183
+ * - 0.25: 256x256
184
+ * - 0.5: 512x512
185
+ * - 1: 1024x1024
186
+ * - 2: 2048x2048
187
+ * - 4: 4096x4096
188
+ */
189
+ tileResolution?: TileResolution;
190
+
191
+ /**
192
+ * Comma-separated aggregation expressions. If assigned on a vector source, source is grouped by geometry and then aggregated.
193
+ *
194
+ * Example:
195
+ *
196
+ * 1 as value, avg(rev) as average_revenue
197
+ */
198
+ aggregationExp?: string;
169
199
  };
170
200
 
171
201
  export type TilesetSourceOptions = {
@@ -186,14 +216,6 @@ export type ColumnsOption = {
186
216
 
187
217
  export type SpatialDataType = 'geo' | 'h3' | 'quadbin';
188
218
 
189
- /**
190
- * Strategy used for covering spatial filter geometry with spatial indexes.
191
- * See https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_polyfill_mode
192
- * or https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_polyfill_mode for more information.
193
- * @internalRemarks Source: cloud-native maps-api
194
- * */
195
- export type SpatialFilterPolyfillMode = 'center' | 'intersects' | 'contains';
196
-
197
219
  export type TilejsonMapInstantiation = MapInstantiation & {
198
220
  tilejson: {url: string[]};
199
221
  };
@@ -31,11 +31,15 @@ type UrlParameters = {
31
31
  tileResolution?: string;
32
32
  q: string;
33
33
  queryParameters?: Record<string, unknown> | unknown[];
34
+ aggregationExp?: string;
34
35
  };
35
36
 
37
+ export type VectorQuerySourceResponse = TilejsonResult &
38
+ WidgetQuerySourceResult;
39
+
36
40
  export const vectorQuerySource = async function (
37
41
  options: VectorQuerySourceOptions
38
- ): Promise<TilejsonResult & WidgetQuerySourceResult> {
42
+ ): Promise<VectorQuerySourceResponse> {
39
43
  const {
40
44
  columns,
41
45
  filters,
@@ -43,6 +47,7 @@ export const vectorQuerySource = async function (
43
47
  sqlQuery,
44
48
  tileResolution = DEFAULT_TILE_RESOLUTION,
45
49
  queryParameters,
50
+ aggregationExp,
46
51
  } = options;
47
52
 
48
53
  const urlParameters: UrlParameters = {
@@ -61,13 +66,13 @@ export const vectorQuerySource = async function (
61
66
  if (queryParameters) {
62
67
  urlParameters.queryParameters = queryParameters;
63
68
  }
69
+ if (aggregationExp) {
70
+ urlParameters.aggregationExp = aggregationExp;
71
+ }
64
72
  return baseSource<UrlParameters>('query', options, urlParameters).then(
65
73
  (result) => ({
66
74
  ...(result as TilejsonResult),
67
- widgetSource: new WidgetQuerySource({
68
- ...options,
69
- spatialDataType: 'geo',
70
- }),
75
+ widgetSource: new WidgetQuerySource(options),
71
76
  })
72
77
  );
73
78
  };
@@ -30,17 +30,22 @@ type UrlParameters = {
30
30
  spatialDataColumn?: string;
31
31
  tileResolution?: string;
32
32
  name: string;
33
+ aggregationExp?: string;
33
34
  };
34
35
 
36
+ export type VectorTableSourceResponse = TilejsonResult &
37
+ WidgetTableSourceResult;
38
+
35
39
  export const vectorTableSource = async function (
36
40
  options: VectorTableSourceOptions
37
- ): Promise<TilejsonResult & WidgetTableSourceResult> {
41
+ ): Promise<VectorTableSourceResponse> {
38
42
  const {
39
43
  columns,
40
44
  filters,
41
45
  spatialDataColumn = 'geom',
42
46
  tableName,
43
47
  tileResolution = DEFAULT_TILE_RESOLUTION,
48
+ aggregationExp,
44
49
  } = options;
45
50
 
46
51
  const urlParameters: UrlParameters = {
@@ -56,13 +61,13 @@ export const vectorTableSource = async function (
56
61
  if (filters) {
57
62
  urlParameters.filters = filters;
58
63
  }
64
+ if (aggregationExp) {
65
+ urlParameters.aggregationExp = aggregationExp;
66
+ }
59
67
  return baseSource<UrlParameters>('table', options, urlParameters).then(
60
68
  (result) => ({
61
69
  ...(result as TilejsonResult),
62
- widgetSource: new WidgetTableSource({
63
- ...options,
64
- spatialDataType: 'geo',
65
- }),
70
+ widgetSource: new WidgetTableSource(options),
66
71
  })
67
72
  );
68
73
  };
@@ -12,9 +12,11 @@ import type {
12
12
  export type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
13
13
  type UrlParameters = {name: string};
14
14
 
15
+ export type VectorTilesetSourceResponse = TilejsonResult;
16
+
15
17
  export const vectorTilesetSource = async function (
16
18
  options: VectorTilesetSourceOptions
17
- ): Promise<TilejsonResult> {
19
+ ): Promise<VectorTilesetSourceResponse> {
18
20
  const {tableName} = options;
19
21
  const urlParameters: UrlParameters = {name: tableName};
20
22
 
@@ -22,5 +24,5 @@ export const vectorTilesetSource = async function (
22
24
  'tileset',
23
25
  options,
24
26
  urlParameters
25
- ) as Promise<TilejsonResult>;
27
+ ) as Promise<VectorTilesetSourceResponse>;
26
28
  };
package/src/utils.ts CHANGED
@@ -57,7 +57,7 @@ export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
57
57
  }
58
58
 
59
59
  /** @internalRemarks Source: @carto/react-core */
60
- export function assert(condition: unknown, message: string): asserts condition {
60
+ export function assert(condition: unknown, message: string) {
61
61
  if (!condition) {
62
62
  throw new Error(message);
63
63
  }
@@ -1,4 +1,4 @@
1
- import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types';
1
+ import {TileResolution} from '../sources/types';
2
2
  import {
3
3
  GroupDateType,
4
4
  SortColumnType,
@@ -10,19 +10,11 @@ import {
10
10
  * WIDGET API REQUESTS
11
11
  */
12
12
 
13
- export interface ViewState {
14
- zoom: number;
15
- latitude: number;
16
- longitude: number;
17
- }
18
-
19
13
  /** Common options for {@link WidgetBaseSource} requests. */
20
14
  interface BaseRequestOptions {
21
15
  spatialFilter?: SpatialFilter;
22
- spatialFiltersMode?: SpatialFilterPolyfillMode;
23
16
  abortController?: AbortController;
24
17
  filterOwner?: string;
25
- viewState?: ViewState;
26
18
  }
27
19
 
28
20
  /** Options for {@link WidgetBaseSource#getCategories}. */