@carto/api-client 0.3.0 → 0.4.0-alpha.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.
Files changed (66) hide show
  1. package/build/api/carto-api-error.d.ts +18 -0
  2. package/build/api/endpoints.d.ts +22 -0
  3. package/build/api/index.d.ts +4 -0
  4. package/build/api/query.d.ts +3 -0
  5. package/build/api/request-with-parameters.d.ts +8 -0
  6. package/build/api/types.d.ts +227 -0
  7. package/build/api-client.cjs +487 -24
  8. package/build/api-client.cjs.map +1 -1
  9. package/build/api-client.modern.js +423 -25
  10. package/build/api-client.modern.js.map +1 -1
  11. package/build/constants.d.ts +8 -0
  12. package/build/index.d.ts +6 -1
  13. package/build/sources/base-source.d.ts +4 -0
  14. package/build/sources/boundary-query-source.d.ts +9 -0
  15. package/build/sources/boundary-table-source.d.ts +7 -0
  16. package/build/sources/h3-query-source.d.ts +3 -0
  17. package/build/sources/h3-table-source.d.ts +3 -0
  18. package/build/sources/h3-tileset-source.d.ts +3 -0
  19. package/build/sources/index.d.ts +27 -5
  20. package/build/sources/quadbin-query-source.d.ts +3 -0
  21. package/build/sources/quadbin-table-source.d.ts +3 -0
  22. package/build/sources/quadbin-tileset-source.d.ts +3 -0
  23. package/build/sources/raster-source.d.ts +3 -0
  24. package/build/sources/types.d.ts +208 -85
  25. package/build/sources/vector-query-source.d.ts +3 -0
  26. package/build/sources/vector-table-source.d.ts +3 -0
  27. package/build/sources/vector-tileset-source.d.ts +3 -0
  28. package/build/utils.d.ts +4 -0
  29. package/build/widget-sources/index.d.ts +5 -0
  30. package/build/widget-sources/types.d.ts +95 -0
  31. package/build/{sources → widget-sources}/widget-base-source.d.ts +1 -1
  32. package/build/{sources → widget-sources}/widget-query-source.d.ts +1 -1
  33. package/build/{sources → widget-sources}/widget-table-source.d.ts +1 -1
  34. package/build/{sources → widget-sources}/wrappers.d.ts +1 -1
  35. package/package.json +4 -3
  36. package/src/api/carto-api-error.ts +72 -0
  37. package/src/api/endpoints.ts +82 -0
  38. package/src/api/index.ts +17 -0
  39. package/src/api/query.ts +56 -0
  40. package/src/api/request-with-parameters.ts +139 -0
  41. package/src/api/types.ts +301 -0
  42. package/src/constants.ts +13 -0
  43. package/src/global.d.ts +3 -0
  44. package/src/index.ts +10 -1
  45. package/src/sources/base-source.ts +100 -0
  46. package/src/sources/boundary-query-source.ts +53 -0
  47. package/src/sources/boundary-table-source.ts +41 -0
  48. package/src/sources/h3-query-source.ts +63 -0
  49. package/src/sources/h3-table-source.ts +59 -0
  50. package/src/sources/h3-tileset-source.ts +26 -0
  51. package/src/sources/index.ts +49 -5
  52. package/src/sources/quadbin-query-source.ts +64 -0
  53. package/src/sources/quadbin-table-source.ts +60 -0
  54. package/src/sources/quadbin-tileset-source.ts +26 -0
  55. package/src/sources/raster-source.ts +34 -0
  56. package/src/sources/types.ts +226 -90
  57. package/src/sources/vector-query-source.ts +65 -0
  58. package/src/sources/vector-table-source.ts +59 -0
  59. package/src/sources/vector-tileset-source.ts +26 -0
  60. package/src/utils.ts +8 -0
  61. package/src/widget-sources/index.ts +5 -0
  62. package/src/widget-sources/types.ts +105 -0
  63. package/src/{sources → widget-sources}/widget-base-source.ts +4 -3
  64. package/src/{sources → widget-sources}/widget-query-source.ts +1 -1
  65. package/src/{sources → widget-sources}/widget-table-source.ts +1 -1
  66. package/src/{sources → widget-sources}/wrappers.ts +1 -21
@@ -1,105 +1,241 @@
1
- import {
2
- GroupDateType,
3
- SortColumnType,
4
- SortDirection,
5
- SpatialFilter,
6
- } from '../types';
7
-
8
- /******************************************************************************
9
- * WIDGET API REQUESTS
10
- */
11
-
12
- /** Common options for {@link WidgetBaseSource} requests. */
13
- interface BaseRequestOptions {
14
- spatialFilter?: SpatialFilter;
15
- abortController?: AbortController;
16
- filterOwner?: string;
17
- }
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Feature} from 'geojson';
6
+ import type {
7
+ Filters,
8
+ Format,
9
+ MapInstantiation,
10
+ QueryParameters,
11
+ } from '../api/types';
12
+
13
+ export type SourceRequiredOptions = {
14
+ /** Carto platform access token. */
15
+ accessToken: string;
16
+
17
+ /** Data warehouse connection name in Carto platform. */
18
+ connectionName: string;
19
+ };
18
20
 
19
- /** Options for {@link WidgetBaseSource#getCategories}. */
20
- export interface CategoryRequestOptions extends BaseRequestOptions {
21
- column: string;
22
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
23
- operationColumn?: string;
24
- }
21
+ export type SourceOptionalOptions = {
22
+ /**
23
+ * Base URL of the CARTO Maps API.
24
+ *
25
+ * Example for account located in EU-west region: `https://gcp-eu-west1.api.carto.com`
26
+ *
27
+ * @default https://gcp-us-east1.api.carto.com
28
+ */
29
+ apiBaseUrl: string;
30
+
31
+ /**
32
+ * Custom HTTP headers added to map instantiation and data requests.
33
+ */
34
+ headers: Record<string, string>;
35
+
36
+ /**
37
+ * Cache buster value returned by map instantiation.
38
+ *
39
+ * Carto source saves `cache` value of map instantiation response in `cache.value`, so it can be used to
40
+ * check if underlying map data has changed between distinct source requests.
41
+ */
42
+ cache?: {value?: number};
43
+
44
+ clientId: string;
45
+ /** @deprecated use `query` instead **/
46
+ format: Format;
47
+
48
+ /**
49
+ * Maximum URL character length. Above this limit, requests use POST.
50
+ * Used to avoid browser and CDN limits.
51
+ * @default {@link DEFAULT_MAX_LENGTH_URL}
52
+ */
53
+ maxLengthURL?: number;
54
+ };
25
55
 
26
- /** Options for {@link WidgetBaseSource#getFormula}. */
27
- export interface FormulaRequestOptions extends BaseRequestOptions {
28
- column: string;
29
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
30
- operationExp?: string;
31
- }
56
+ export type SourceOptions = SourceRequiredOptions &
57
+ Partial<SourceOptionalOptions>;
58
+
59
+ export type AggregationOptions = {
60
+ /**
61
+ * Defines the aggregation expressions that will be calculated from the resulting columns on each grid cell.
62
+ *
63
+ * Example:
64
+ *
65
+ * sum(pop) as total_population, avg(rev) as average_revenue
66
+ */
67
+ aggregationExp: string;
68
+
69
+ /**
70
+ * Defines the tile aggregation resolution.
71
+ *
72
+ * @default 6 for quadbin and 4 for h3 sources
73
+ */
74
+ aggregationResLevel?: number;
75
+ };
32
76
 
33
- /** Options for {@link WidgetBaseSource#getHistogram}. */
34
- export interface HistogramRequestOptions extends BaseRequestOptions {
35
- column: string;
36
- ticks: number[];
37
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
38
- }
77
+ export type FilterOptions = {
78
+ /**
79
+ * Filters to apply to the data source on the server
80
+ */
81
+ filters?: Filters;
82
+ };
39
83
 
40
- /** Options for {@link WidgetBaseSource#getRange}. */
41
- export interface RangeRequestOptions extends BaseRequestOptions {
42
- column: string;
43
- }
84
+ export type QuerySourceOptions = {
85
+ /**
86
+ * The column name and the type of geospatial support.
87
+ *
88
+ * If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
89
+ */
90
+ spatialDataColumn?: string;
91
+
92
+ /** SQL query. */
93
+ sqlQuery: string;
94
+
95
+ /**
96
+ * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
97
+ * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
98
+ * the quantization grid proportionately.
99
+ *
100
+ * Supported `tileResolution` values, with corresponding grid sizes:
101
+ *
102
+ * - 0.25: 256x256
103
+ * - 0.5: 512x512
104
+ * - 1: 1024x1024
105
+ * - 2: 2048x2048
106
+ * - 4: 4096x4096
107
+ */
108
+ tileResolution?: TileResolution;
109
+
110
+ /**
111
+ * Values for named or positional paramteres in the query.
112
+ *
113
+ * The way query parameters are determined by data warehouse.
114
+ *
115
+ * * BigQuery has named query parameters, specified with a dictionary, and referenced by key (`@key`)
116
+ *
117
+ * ```
118
+ * sqlQuery: "SELECT * FROM carto-demo-data.demo_tables.retail_stores WHERE storetype = ⁣@type AND revenue > ⁣@minRevenue"
119
+ * queryParameters: { type: 'Supermarket', minRevenue: 1000000 }
120
+ * ```
121
+ * * Snowflake supports positional parameters, in the form `:1`, `:2`, etc.
122
+ *
123
+ * ```
124
+ * sqlQuery: "SELECT * FROM demo_db.public.import_retail_stores WHERE storetype = :2 AND revenue > :1
125
+ * queryParameters: [100000, "Supermarket"]
126
+ * ```
127
+ * * Postgres and Redhisft supports positional parameters, but in the form `$1`, `$2`, etc.
128
+ *
129
+ * ```
130
+ * sqlQuery: "SELECT * FROM carto_demo_data.demo_tables.retail_stores WHERE storetype = $2 AND revenue > $1
131
+ * queryParameters: [100000, "Supermarket"]
132
+ * ```
133
+ */
134
+ queryParameters?: QueryParameters;
135
+ };
44
136
 
45
- /** Options for {@link WidgetBaseSource#getScatter}. */
46
- export interface ScatterRequestOptions extends BaseRequestOptions {
47
- xAxisColumn: string;
48
- xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
49
- yAxisColumn: string;
50
- yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
51
- }
137
+ export type TableSourceOptions = {
138
+ /**
139
+ * Fully qualified name of table.
140
+ */
141
+ tableName: string;
142
+
143
+ /**
144
+ * The column name and the type of geospatial support.
145
+ *
146
+ * If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
147
+ */
148
+ spatialDataColumn?: string;
149
+
150
+ /**
151
+ * Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
152
+ * quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
153
+ * the quantization grid proportionately.
154
+ *
155
+ * Supported `tileResolution` values, with corresponding grid sizes:
156
+ *
157
+ * - 0.25: 256x256
158
+ * - 0.5: 512x512
159
+ * - 1: 1024x1024
160
+ * - 2: 2048x2048
161
+ * - 4: 4096x4096
162
+ */
163
+ tileResolution?: TileResolution;
164
+ };
52
165
 
53
- /** Options for {@link WidgetBaseSource#getTable}. */
54
- export interface TableRequestOptions extends BaseRequestOptions {
55
- columns: string[];
56
- sortBy?: string;
57
- sortDirection?: SortDirection;
58
- sortByColumnType?: SortColumnType;
59
- offset?: number;
60
- limit?: number;
61
- }
166
+ export type TilesetSourceOptions = {
167
+ /**
168
+ * Fully qualified name of tileset.
169
+ */
170
+ tableName: string;
171
+ };
62
172
 
63
- /** Options for {@link WidgetBaseSource#getTimeSeries}. */
64
- export interface TimeSeriesRequestOptions extends BaseRequestOptions {
65
- column: string;
66
- stepSize?: GroupDateType;
67
- stepMultiplier?: number;
68
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
69
- operationColumn?: string;
70
- joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
71
- splitByCategory?: string;
72
- splitByCategoryLimit?: number;
73
- splitByCategoryValues?: string[];
74
- }
173
+ export type ColumnsOption = {
174
+ /**
175
+ * Columns to retrieve from the table.
176
+ *
177
+ * If not present, all columns are returned.
178
+ */
179
+ columns?: string[];
180
+ };
75
181
 
76
- /******************************************************************************
77
- * WIDGET API RESPONSES
78
- */
182
+ export type SpatialDataType = 'geo' | 'h3' | 'quadbin';
79
183
 
80
- /** Response from {@link WidgetBaseSource#getFormula}. */
81
- export type FormulaResponse = {value: number};
184
+ export type TilejsonMapInstantiation = MapInstantiation & {
185
+ tilejson: {url: string[]};
186
+ };
187
+
188
+ export type TileResolution = 0.25 | 0.5 | 1 | 2 | 4;
189
+
190
+ export interface Tilejson {
191
+ tilejson: string;
192
+ name: string;
193
+ description: string;
194
+ version: string;
195
+ attribution: string;
196
+ scheme: string;
197
+ tiles: string[];
198
+ properties_tiles: string[];
199
+ minresolution: number;
200
+ maxresolution: number;
201
+ minzoom: number;
202
+ maxzoom: number;
203
+ bounds: [number, number, number, number];
204
+ center: [number, number, number];
205
+ vector_layers: VectorLayer[];
206
+ tilestats: Tilestats;
207
+ tileResolution?: TileResolution;
208
+ }
82
209
 
83
- /** Response from {@link WidgetBaseSource#getCategories}. */
84
- export type CategoryResponse = {name: string; value: number}[];
210
+ export interface Tilestats {
211
+ layerCount: number;
212
+ layers: Layer[];
213
+ }
85
214
 
86
- /** Response from {@link WidgetBaseSource#getRange}. */
87
- export type RangeResponse = {min: number; max: number};
215
+ export interface Layer {
216
+ layer: string;
217
+ count: number;
218
+ attributeCount: number;
219
+ attributes: Attribute[];
220
+ }
88
221
 
89
- /** Response from {@link WidgetBaseSource#getTable}. */
90
- export type TableResponse = {
91
- totalCount: number;
92
- rows: Record<string, number | string>[];
93
- };
222
+ export interface Attribute {
223
+ attribute: string;
224
+ type: string;
225
+ }
94
226
 
95
- /** Response from {@link WidgetBaseSource#getScatter}. */
96
- export type ScatterResponse = [number, number][];
227
+ export interface VectorLayer {
228
+ id: string;
229
+ minzoom: number;
230
+ maxzoom: number;
231
+ fields: Record<string, string>;
232
+ }
97
233
 
98
- /** Response from {@link WidgetBaseSource#getTimeSeries}. */
99
- export type TimeSeriesResponse = {
100
- rows: {name: string; value: number}[];
101
- categories: string[];
234
+ export type TilejsonResult = Tilejson & {accessToken: string};
235
+ export type GeojsonResult = {type: 'FeatureCollection'; features: Feature[]};
236
+ export type JsonResult = any[];
237
+ export type QueryResult = {
238
+ meta: {cacheHit: boolean; location: string; totalBytesProcessed: string};
239
+ rows: Record<string, any>[];
240
+ schema: {name: string; type: string}[];
102
241
  };
103
-
104
- /** Response from {@link WidgetBaseSource#getHistogram}. */
105
- export type HistogramResponse = number[];
@@ -0,0 +1,65 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /* eslint-disable camelcase */
6
+ import {DEFAULT_TILE_RESOLUTION} from '../constants';
7
+ import {baseSource} from './base-source';
8
+ import type {
9
+ FilterOptions,
10
+ SourceOptions,
11
+ QuerySourceOptions,
12
+ SpatialDataType,
13
+ TilejsonResult,
14
+ ColumnsOption,
15
+ } from './types';
16
+
17
+ export type VectorQuerySourceOptions = SourceOptions &
18
+ QuerySourceOptions &
19
+ FilterOptions &
20
+ ColumnsOption;
21
+
22
+ type UrlParameters = {
23
+ columns?: string;
24
+ filters?: Record<string, unknown>;
25
+ spatialDataType: SpatialDataType;
26
+ spatialDataColumn?: string;
27
+ tileResolution?: string;
28
+ q: string;
29
+ queryParameters?: Record<string, unknown> | unknown[];
30
+ };
31
+
32
+ export const vectorQuerySource = async function (
33
+ options: VectorQuerySourceOptions
34
+ ): Promise<TilejsonResult> {
35
+ const {
36
+ columns,
37
+ filters,
38
+ spatialDataColumn = 'geom',
39
+ sqlQuery,
40
+ tileResolution = DEFAULT_TILE_RESOLUTION,
41
+ queryParameters,
42
+ } = options;
43
+
44
+ const urlParameters: UrlParameters = {
45
+ spatialDataColumn,
46
+ spatialDataType: 'geo',
47
+ tileResolution: tileResolution.toString(),
48
+ q: sqlQuery,
49
+ };
50
+
51
+ if (columns) {
52
+ urlParameters.columns = columns.join(',');
53
+ }
54
+ if (filters) {
55
+ urlParameters.filters = filters;
56
+ }
57
+ if (queryParameters) {
58
+ urlParameters.queryParameters = queryParameters;
59
+ }
60
+ return baseSource<UrlParameters>(
61
+ 'query',
62
+ options,
63
+ urlParameters
64
+ ) as Promise<TilejsonResult>;
65
+ };
@@ -0,0 +1,59 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ /* eslint-disable camelcase */
6
+ import {DEFAULT_TILE_RESOLUTION} from '../constants';
7
+ import {baseSource} from './base-source';
8
+ import type {
9
+ FilterOptions,
10
+ ColumnsOption,
11
+ SourceOptions,
12
+ SpatialDataType,
13
+ TableSourceOptions,
14
+ TilejsonResult,
15
+ } from './types';
16
+
17
+ export type VectorTableSourceOptions = SourceOptions &
18
+ TableSourceOptions &
19
+ FilterOptions &
20
+ ColumnsOption;
21
+ type UrlParameters = {
22
+ columns?: string;
23
+ filters?: Record<string, unknown>;
24
+ spatialDataType: SpatialDataType;
25
+ spatialDataColumn?: string;
26
+ tileResolution?: string;
27
+ name: string;
28
+ };
29
+
30
+ export const vectorTableSource = async function (
31
+ options: VectorTableSourceOptions
32
+ ): Promise<TilejsonResult> {
33
+ const {
34
+ columns,
35
+ filters,
36
+ spatialDataColumn = 'geom',
37
+ tableName,
38
+ tileResolution = DEFAULT_TILE_RESOLUTION,
39
+ } = options;
40
+
41
+ const urlParameters: UrlParameters = {
42
+ name: tableName,
43
+ spatialDataColumn,
44
+ spatialDataType: 'geo',
45
+ tileResolution: tileResolution.toString(),
46
+ };
47
+
48
+ if (columns) {
49
+ urlParameters.columns = columns.join(',');
50
+ }
51
+ if (filters) {
52
+ urlParameters.filters = filters;
53
+ }
54
+ return baseSource<UrlParameters>(
55
+ 'table',
56
+ options,
57
+ urlParameters
58
+ ) as Promise<TilejsonResult>;
59
+ };
@@ -0,0 +1,26 @@
1
+ // deck.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import {baseSource} from './base-source';
6
+ import type {
7
+ SourceOptions,
8
+ TilesetSourceOptions,
9
+ TilejsonResult,
10
+ } from './types';
11
+
12
+ export type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
13
+ type UrlParameters = {name: string};
14
+
15
+ export const vectorTilesetSource = async function (
16
+ options: VectorTilesetSourceOptions
17
+ ): Promise<TilejsonResult> {
18
+ const {tableName} = options;
19
+ const urlParameters: UrlParameters = {name: tableName};
20
+
21
+ return baseSource<UrlParameters>(
22
+ 'tileset',
23
+ options,
24
+ urlParameters
25
+ ) as Promise<TilejsonResult>;
26
+ };
package/src/utils.ts CHANGED
@@ -90,3 +90,11 @@ export function isEmptyObject(object: object): boolean {
90
90
  }
91
91
  return true;
92
92
  }
93
+
94
+ /** @internal */
95
+ export const isObject: (x: unknown) => boolean = (x) =>
96
+ x !== null && typeof x === 'object';
97
+
98
+ /** @internal */
99
+ export const isPureObject: (x: any) => boolean = (x) =>
100
+ isObject(x) && x.constructor === {}.constructor;
@@ -0,0 +1,5 @@
1
+ export * from './widget-base-source.js';
2
+ export * from './widget-query-source.js';
3
+ export * from './widget-table-source.js';
4
+ export * from './wrappers.js';
5
+ export * from './types.js';
@@ -0,0 +1,105 @@
1
+ import {
2
+ GroupDateType,
3
+ SortColumnType,
4
+ SortDirection,
5
+ SpatialFilter,
6
+ } from '../types';
7
+
8
+ /******************************************************************************
9
+ * WIDGET API REQUESTS
10
+ */
11
+
12
+ /** Common options for {@link WidgetBaseSource} requests. */
13
+ interface BaseRequestOptions {
14
+ spatialFilter?: SpatialFilter;
15
+ abortController?: AbortController;
16
+ filterOwner?: string;
17
+ }
18
+
19
+ /** Options for {@link WidgetBaseSource#getCategories}. */
20
+ export interface CategoryRequestOptions extends BaseRequestOptions {
21
+ column: string;
22
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
23
+ operationColumn?: string;
24
+ }
25
+
26
+ /** Options for {@link WidgetBaseSource#getFormula}. */
27
+ export interface FormulaRequestOptions extends BaseRequestOptions {
28
+ column: string;
29
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
30
+ operationExp?: string;
31
+ }
32
+
33
+ /** Options for {@link WidgetBaseSource#getHistogram}. */
34
+ export interface HistogramRequestOptions extends BaseRequestOptions {
35
+ column: string;
36
+ ticks: number[];
37
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
38
+ }
39
+
40
+ /** Options for {@link WidgetBaseSource#getRange}. */
41
+ export interface RangeRequestOptions extends BaseRequestOptions {
42
+ column: string;
43
+ }
44
+
45
+ /** Options for {@link WidgetBaseSource#getScatter}. */
46
+ export interface ScatterRequestOptions extends BaseRequestOptions {
47
+ xAxisColumn: string;
48
+ xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
49
+ yAxisColumn: string;
50
+ yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
51
+ }
52
+
53
+ /** Options for {@link WidgetBaseSource#getTable}. */
54
+ export interface TableRequestOptions extends BaseRequestOptions {
55
+ columns: string[];
56
+ sortBy?: string;
57
+ sortDirection?: SortDirection;
58
+ sortByColumnType?: SortColumnType;
59
+ offset?: number;
60
+ limit?: number;
61
+ }
62
+
63
+ /** Options for {@link WidgetBaseSource#getTimeSeries}. */
64
+ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
65
+ column: string;
66
+ stepSize?: GroupDateType;
67
+ stepMultiplier?: number;
68
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
69
+ operationColumn?: string;
70
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
71
+ splitByCategory?: string;
72
+ splitByCategoryLimit?: number;
73
+ splitByCategoryValues?: string[];
74
+ }
75
+
76
+ /******************************************************************************
77
+ * WIDGET API RESPONSES
78
+ */
79
+
80
+ /** Response from {@link WidgetBaseSource#getFormula}. */
81
+ export type FormulaResponse = {value: number};
82
+
83
+ /** Response from {@link WidgetBaseSource#getCategories}. */
84
+ export type CategoryResponse = {name: string; value: number}[];
85
+
86
+ /** Response from {@link WidgetBaseSource#getRange}. */
87
+ export type RangeResponse = {min: number; max: number};
88
+
89
+ /** Response from {@link WidgetBaseSource#getTable}. */
90
+ export type TableResponse = {
91
+ totalCount: number;
92
+ rows: Record<string, number | string>[];
93
+ };
94
+
95
+ /** Response from {@link WidgetBaseSource#getScatter}. */
96
+ export type ScatterResponse = [number, number][];
97
+
98
+ /** Response from {@link WidgetBaseSource#getTimeSeries}. */
99
+ export type TimeSeriesResponse = {
100
+ rows: {name: string; value: number}[];
101
+ categories: string[];
102
+ };
103
+
104
+ /** Response from {@link WidgetBaseSource#getHistogram}. */
105
+ export type HistogramResponse = number[];
@@ -16,7 +16,6 @@ import {
16
16
  TimeSeriesResponse,
17
17
  } from './types.js';
18
18
  import {FilterLogicalOperator, Filter} from '../types.js';
19
- import {SourceOptions} from '@deck.gl/carto';
20
19
  import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
21
20
  import {
22
21
  DEFAULT_API_BASE_URL,
@@ -25,6 +24,7 @@ import {
25
24
  } from '../constants-internal.js';
26
25
  import {getClient} from '../client.js';
27
26
  import {ModelSource} from '../models/model.js';
27
+ import {SourceOptions} from '../sources/index.js';
28
28
 
29
29
  export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
30
30
  apiVersion?: ApiVersion;
@@ -258,8 +258,9 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
258
258
  },
259
259
  opts: {abortController},
260
260
  }).then((res: TableModelResponse) => ({
261
- rows: normalizeObjectKeys(res.rows),
262
- totalCount: res.metadata.total,
261
+ // Avoid `normalizeObjectKeys()`, which changes column names.
262
+ rows: res.rows ?? (res as any).ROWS,
263
+ totalCount: res.metadata?.total ?? (res as any).METADATA?.TOTAL,
263
264
  }));
264
265
  }
265
266
 
@@ -2,7 +2,7 @@ import {
2
2
  H3QuerySourceOptions,
3
3
  QuadbinQuerySourceOptions,
4
4
  VectorQuerySourceOptions,
5
- } from '@deck.gl/carto';
5
+ } from '../sources/index.js';
6
6
  import {MapType} from '../constants-internal.js';
7
7
  import {WidgetBaseSource, WidgetBaseSourceProps} from './widget-base-source.js';
8
8
  import {ModelSource} from '../models/model.js';
@@ -2,7 +2,7 @@ import {
2
2
  H3TableSourceOptions,
3
3
  QuadbinTableSourceOptions,
4
4
  VectorTableSourceOptions,
5
- } from '@deck.gl/carto';
5
+ } from '../sources/index.js';
6
6
  import {WidgetBaseSource, WidgetBaseSourceProps} from './widget-base-source.js';
7
7
  import {MapType} from '../constants-internal.js';
8
8
  import {ModelSource} from '../models/model.js';