@carto/api-client 0.4.3 → 0.5.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.
- package/CHANGELOG.md +4 -0
- package/build/api/query.d.ts +1 -1
- package/build/api-client.cjs +2388 -261
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +2237 -262
- package/build/api-client.modern.js.map +1 -1
- package/build/constants.d.ts +22 -0
- package/build/filters/Filter.d.ts +13 -0
- package/build/filters/FilterTypes.d.ts +3 -0
- package/build/filters/geosjonFeatures.d.ts +8 -0
- package/build/filters/index.d.ts +6 -0
- package/build/filters/tileFeatures.d.ts +20 -0
- package/build/filters/tileFeaturesGeometries.d.ts +13 -0
- package/build/filters/tileFeaturesSpatialIndex.d.ts +10 -0
- package/build/index.d.ts +4 -0
- package/build/models/index.d.ts +1 -1
- package/build/models/model.d.ts +7 -1
- package/build/operations/aggregation.d.ts +8 -0
- package/build/operations/applySorting.d.ts +20 -0
- package/build/operations/groupBy.d.ts +15 -0
- package/build/operations/groupByDate.d.ts +11 -0
- package/build/operations/histogram.d.ts +13 -0
- package/build/operations/index.d.ts +6 -0
- package/build/operations/scatterPlot.d.ts +14 -0
- package/build/sources/h3-tileset-source.d.ts +2 -1
- package/build/sources/index.d.ts +1 -1
- package/build/sources/quadbin-tileset-source.d.ts +2 -1
- package/build/sources/types.d.ts +36 -41
- package/build/sources/vector-tileset-source.d.ts +2 -1
- package/build/spatial-index.d.ts +8 -0
- package/build/types-internal.d.ts +4 -0
- package/build/types.d.ts +61 -1
- package/build/utils/dateUtils.d.ts +10 -0
- package/build/utils/getTileFormat.d.ts +3 -0
- package/build/utils/makeIntervalComplete.d.ts +2 -0
- package/build/utils/transformTileCoordsToWGS84.d.ts +8 -0
- package/build/utils/transformToTileCoords.d.ts +9 -0
- package/build/utils.d.ts +1 -1
- package/build/widget-sources/index.d.ts +2 -1
- package/build/widget-sources/types.d.ts +40 -23
- package/build/widget-sources/widget-query-source.d.ts +2 -2
- package/build/widget-sources/widget-remote-source.d.ts +18 -0
- package/build/widget-sources/{widget-base-source.d.ts → widget-source.d.ts} +16 -41
- package/build/widget-sources/widget-table-source.d.ts +2 -2
- package/build/widget-sources/widget-tileset-source.d.ts +67 -0
- package/package.json +36 -35
- package/src/api/query.ts +1 -2
- package/src/constants.ts +25 -0
- package/src/filters/Filter.ts +169 -0
- package/src/filters/FilterTypes.ts +109 -0
- package/src/filters/geosjonFeatures.ts +32 -0
- package/src/filters/index.ts +6 -0
- package/src/filters/tileFeatures.ts +56 -0
- package/src/filters/tileFeaturesGeometries.ts +444 -0
- package/src/filters/tileFeaturesSpatialIndex.ts +119 -0
- package/src/index.ts +6 -0
- package/src/models/index.ts +1 -1
- package/src/models/model.ts +47 -24
- package/src/operations/aggregation.ts +154 -0
- package/src/operations/applySorting.ts +109 -0
- package/src/operations/groupBy.ts +59 -0
- package/src/operations/groupByDate.ts +98 -0
- package/src/operations/histogram.ts +66 -0
- package/src/operations/index.ts +6 -0
- package/src/operations/scatterPlot.ts +50 -0
- package/src/sources/h3-query-source.ts +7 -1
- package/src/sources/h3-table-source.ts +6 -1
- package/src/sources/h3-tileset-source.ts +18 -6
- package/src/sources/index.ts +1 -1
- package/src/sources/quadbin-query-source.ts +6 -1
- package/src/sources/quadbin-table-source.ts +6 -1
- package/src/sources/quadbin-tileset-source.ts +18 -6
- package/src/sources/raster-source.ts +1 -0
- package/src/sources/types.ts +41 -45
- package/src/sources/vector-query-source.ts +10 -3
- package/src/sources/vector-table-source.ts +10 -3
- package/src/sources/vector-tileset-source.ts +19 -6
- package/src/spatial-index.ts +111 -0
- package/src/types-internal.ts +6 -0
- package/src/types.ts +60 -2
- package/src/utils/dateUtils.ts +28 -0
- package/src/utils/getTileFormat.ts +9 -0
- package/src/utils/makeIntervalComplete.ts +17 -0
- package/src/utils/transformTileCoordsToWGS84.ts +77 -0
- package/src/utils/transformToTileCoords.ts +85 -0
- package/src/utils.ts +9 -6
- package/src/widget-sources/index.ts +2 -1
- package/src/widget-sources/types.ts +42 -23
- package/src/widget-sources/widget-query-source.ts +6 -3
- package/src/widget-sources/{widget-base-source.ts → widget-remote-source.ts} +169 -144
- package/src/widget-sources/widget-source.ts +160 -0
- package/src/widget-sources/widget-table-source.ts +6 -3
- package/src/widget-sources/widget-tileset-source.ts +396 -0
|
@@ -17,90 +17,49 @@ import {
|
|
|
17
17
|
TimeSeriesRequestOptions,
|
|
18
18
|
TimeSeriesResponse,
|
|
19
19
|
} from './types.js';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {ModelSource} from '../models/model.js';
|
|
24
|
-
import {SourceOptions} from '../sources/index.js';
|
|
25
|
-
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
26
|
-
import {
|
|
27
|
-
DEFAULT_GEO_COLUMN,
|
|
28
|
-
DEFAULT_TILE_RESOLUTION,
|
|
29
|
-
} from '../constants-internal.js';
|
|
30
|
-
|
|
31
|
-
export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
32
|
-
apiVersion?: ApiVersion;
|
|
33
|
-
geoColumn?: string;
|
|
34
|
-
filters?: Record<string, Filter>;
|
|
35
|
-
filtersLogicalOperator?: FilterLogicalOperator;
|
|
36
|
-
}
|
|
20
|
+
import {normalizeObjectKeys} from '../utils.js';
|
|
21
|
+
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
22
|
+
import {WidgetSource, WidgetSourceProps} from './widget-source.js';
|
|
37
23
|
|
|
38
|
-
export type
|
|
24
|
+
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
39
25
|
|
|
40
26
|
/**
|
|
41
|
-
* Source for Widget API requests
|
|
27
|
+
* Source for Widget API requests.
|
|
42
28
|
*
|
|
43
29
|
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
44
30
|
*/
|
|
45
|
-
export abstract class
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
static defaultProps: Partial<WidgetBaseSourceProps> = {
|
|
49
|
-
apiVersion: ApiVersion.V3,
|
|
50
|
-
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
51
|
-
clientId: getClient(),
|
|
52
|
-
filters: {},
|
|
53
|
-
filtersLogicalOperator: 'and',
|
|
54
|
-
geoColumn: DEFAULT_GEO_COLUMN,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
constructor(props: Props) {
|
|
58
|
-
this.props = {...WidgetBaseSource.defaultProps, ...props};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Subclasses of {@link WidgetBaseSource} must implement this method, calling
|
|
63
|
-
* {@link WidgetBaseSource.prototype._getModelSource} for common source
|
|
64
|
-
* properties, and adding additional required properties including 'type' and
|
|
65
|
-
* 'data'.
|
|
66
|
-
*/
|
|
67
|
-
protected abstract getModelSource(owner: string | undefined): ModelSource;
|
|
68
|
-
|
|
69
|
-
protected _getModelSource(
|
|
70
|
-
owner?: string
|
|
71
|
-
): Omit<ModelSource, 'type' | 'data'> {
|
|
72
|
-
const props = this.props;
|
|
73
|
-
return {
|
|
74
|
-
apiVersion: props.apiVersion as ApiVersion,
|
|
75
|
-
apiBaseUrl: props.apiBaseUrl as string,
|
|
76
|
-
clientId: props.clientId as string,
|
|
77
|
-
accessToken: props.accessToken,
|
|
78
|
-
connectionName: props.connectionName,
|
|
79
|
-
filters: getApplicableFilters(owner, props.filters),
|
|
80
|
-
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
81
|
-
geoColumn: props.geoColumn,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/****************************************************************************
|
|
86
|
-
* CATEGORIES
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
91
|
-
* charts including grouped bar charts, pie charts, and tree charts.
|
|
92
|
-
*/
|
|
31
|
+
export abstract class WidgetRemoteSource<
|
|
32
|
+
Props extends WidgetRemoteSourceProps,
|
|
33
|
+
> extends WidgetSource<Props> {
|
|
93
34
|
async getCategories(
|
|
94
35
|
options: CategoryRequestOptions
|
|
95
36
|
): Promise<CategoryResponse> {
|
|
96
|
-
const {
|
|
37
|
+
const {
|
|
38
|
+
filterOwner,
|
|
39
|
+
spatialFilter,
|
|
40
|
+
spatialFiltersMode,
|
|
41
|
+
spatialIndexReferenceViewState,
|
|
42
|
+
abortController,
|
|
43
|
+
...params
|
|
44
|
+
} = options;
|
|
97
45
|
const {column, operation, operationColumn} = params;
|
|
46
|
+
const source = this.getModelSource(filterOwner);
|
|
47
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
48
|
+
source,
|
|
49
|
+
spatialFilter,
|
|
50
|
+
spatialIndexReferenceViewState
|
|
51
|
+
);
|
|
98
52
|
|
|
99
53
|
type CategoriesModelResponse = {rows: {name: string; value: number}[]};
|
|
100
54
|
|
|
101
55
|
return executeModel({
|
|
102
56
|
model: 'category',
|
|
103
|
-
source: {
|
|
57
|
+
source: {
|
|
58
|
+
...source,
|
|
59
|
+
spatialFiltersResolution,
|
|
60
|
+
spatialFiltersMode,
|
|
61
|
+
spatialFilter,
|
|
62
|
+
},
|
|
104
63
|
params: {
|
|
105
64
|
column,
|
|
106
65
|
operation,
|
|
@@ -110,29 +69,35 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
110
69
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
111
70
|
}
|
|
112
71
|
|
|
113
|
-
/****************************************************************************
|
|
114
|
-
* FEATURES
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
119
|
-
* matching features. In datasets containing features with duplicate geometries,
|
|
120
|
-
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
121
|
-
* results may be returned than IDs in the request.
|
|
122
|
-
* @internal
|
|
123
|
-
* @experimental
|
|
124
|
-
*/
|
|
125
72
|
async getFeatures(
|
|
126
73
|
options: FeaturesRequestOptions
|
|
127
74
|
): Promise<FeaturesResponse> {
|
|
128
|
-
const {
|
|
75
|
+
const {
|
|
76
|
+
filterOwner,
|
|
77
|
+
spatialFilter,
|
|
78
|
+
spatialFiltersMode,
|
|
79
|
+
spatialIndexReferenceViewState,
|
|
80
|
+
abortController,
|
|
81
|
+
...params
|
|
82
|
+
} = options;
|
|
129
83
|
const {columns, dataType, featureIds, z, limit, tileResolution} = params;
|
|
84
|
+
const source = this.getModelSource(filterOwner);
|
|
85
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
86
|
+
source,
|
|
87
|
+
spatialFilter,
|
|
88
|
+
spatialIndexReferenceViewState
|
|
89
|
+
);
|
|
130
90
|
|
|
131
91
|
type FeaturesModelResponse = {rows: Record<string, unknown>[]};
|
|
132
92
|
|
|
133
93
|
return executeModel({
|
|
134
94
|
model: 'pick',
|
|
135
|
-
source: {
|
|
95
|
+
source: {
|
|
96
|
+
...source,
|
|
97
|
+
spatialFiltersResolution,
|
|
98
|
+
spatialFiltersMode,
|
|
99
|
+
spatialFilter,
|
|
100
|
+
},
|
|
136
101
|
params: {
|
|
137
102
|
columns,
|
|
138
103
|
dataType,
|
|
@@ -146,53 +111,72 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
146
111
|
}).then(({rows}: FeaturesModelResponse) => ({rows}));
|
|
147
112
|
}
|
|
148
113
|
|
|
149
|
-
/****************************************************************************
|
|
150
|
-
* FORMULA
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Returns a scalar numerical statistic over all matching data. Suitable
|
|
155
|
-
* for 'headline' or 'scorecard' figures such as counts and sums.
|
|
156
|
-
*/
|
|
157
114
|
async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
|
|
158
115
|
const {
|
|
159
116
|
filterOwner,
|
|
160
117
|
spatialFilter,
|
|
118
|
+
spatialFiltersMode,
|
|
119
|
+
spatialIndexReferenceViewState,
|
|
161
120
|
abortController,
|
|
162
121
|
operationExp,
|
|
163
122
|
...params
|
|
164
123
|
} = options;
|
|
165
124
|
const {column, operation} = params;
|
|
125
|
+
const source = this.getModelSource(filterOwner);
|
|
126
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
127
|
+
source,
|
|
128
|
+
spatialFilter,
|
|
129
|
+
spatialIndexReferenceViewState
|
|
130
|
+
);
|
|
166
131
|
|
|
167
132
|
type FormulaModelResponse = {rows: {value: number}[]};
|
|
168
133
|
|
|
169
134
|
return executeModel({
|
|
170
135
|
model: 'formula',
|
|
171
|
-
source: {
|
|
172
|
-
|
|
136
|
+
source: {
|
|
137
|
+
...source,
|
|
138
|
+
spatialFiltersResolution,
|
|
139
|
+
spatialFiltersMode,
|
|
140
|
+
spatialFilter,
|
|
141
|
+
},
|
|
142
|
+
params: {
|
|
143
|
+
column: column ?? '*',
|
|
144
|
+
operation: operation ?? 'count',
|
|
145
|
+
operationExp,
|
|
146
|
+
},
|
|
173
147
|
opts: {abortController},
|
|
174
148
|
}).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
175
149
|
}
|
|
176
150
|
|
|
177
|
-
/****************************************************************************
|
|
178
|
-
* HISTOGRAM
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Returns a list of labeled datapoints for 'bins' of data defined as ticks
|
|
183
|
-
* over a numerical range. Suitable for histogram charts.
|
|
184
|
-
*/
|
|
185
151
|
async getHistogram(
|
|
186
152
|
options: HistogramRequestOptions
|
|
187
153
|
): Promise<HistogramResponse> {
|
|
188
|
-
const {
|
|
154
|
+
const {
|
|
155
|
+
filterOwner,
|
|
156
|
+
spatialFilter,
|
|
157
|
+
spatialFiltersMode,
|
|
158
|
+
spatialIndexReferenceViewState,
|
|
159
|
+
abortController,
|
|
160
|
+
...params
|
|
161
|
+
} = options;
|
|
189
162
|
const {column, operation, ticks} = params;
|
|
163
|
+
const source = this.getModelSource(filterOwner);
|
|
164
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
165
|
+
source,
|
|
166
|
+
spatialFilter,
|
|
167
|
+
spatialIndexReferenceViewState
|
|
168
|
+
);
|
|
190
169
|
|
|
191
170
|
type HistogramModelResponse = {rows: {tick: number; value: number}[]};
|
|
192
171
|
|
|
193
172
|
const data = await executeModel({
|
|
194
173
|
model: 'histogram',
|
|
195
|
-
source: {
|
|
174
|
+
source: {
|
|
175
|
+
...source,
|
|
176
|
+
spatialFiltersResolution,
|
|
177
|
+
spatialFiltersMode,
|
|
178
|
+
spatialFilter,
|
|
179
|
+
},
|
|
196
180
|
params: {column, operation, ticks},
|
|
197
181
|
opts: {abortController},
|
|
198
182
|
}).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
|
|
@@ -210,42 +194,57 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
210
194
|
return [];
|
|
211
195
|
}
|
|
212
196
|
|
|
213
|
-
/****************************************************************************
|
|
214
|
-
* RANGE
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Returns a range (min and max) for a numerical column of matching rows.
|
|
219
|
-
* Suitable for displaying certain 'headline' or 'scorecard' statistics,
|
|
220
|
-
* or rendering a range slider UI for filtering.
|
|
221
|
-
*/
|
|
222
197
|
async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
|
|
223
|
-
const {
|
|
198
|
+
const {
|
|
199
|
+
filterOwner,
|
|
200
|
+
spatialFilter,
|
|
201
|
+
spatialFiltersMode,
|
|
202
|
+
spatialIndexReferenceViewState,
|
|
203
|
+
abortController,
|
|
204
|
+
...params
|
|
205
|
+
} = options;
|
|
224
206
|
const {column} = params;
|
|
207
|
+
const source = this.getModelSource(filterOwner);
|
|
208
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
209
|
+
source,
|
|
210
|
+
spatialFilter,
|
|
211
|
+
spatialIndexReferenceViewState
|
|
212
|
+
);
|
|
225
213
|
|
|
226
214
|
type RangeModelResponse = {rows: {min: number; max: number}[]};
|
|
227
215
|
|
|
228
216
|
return executeModel({
|
|
229
217
|
model: 'range',
|
|
230
|
-
source: {
|
|
218
|
+
source: {
|
|
219
|
+
...source,
|
|
220
|
+
spatialFiltersResolution,
|
|
221
|
+
spatialFiltersMode,
|
|
222
|
+
spatialFilter,
|
|
223
|
+
},
|
|
231
224
|
params: {column},
|
|
232
225
|
opts: {abortController},
|
|
233
226
|
}).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
234
227
|
}
|
|
235
228
|
|
|
236
|
-
/****************************************************************************
|
|
237
|
-
* SCATTER
|
|
238
|
-
*/
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
|
|
242
|
-
* values. Suitable for rendering scatter plots.
|
|
243
|
-
*/
|
|
244
229
|
async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
|
|
245
|
-
const {
|
|
230
|
+
const {
|
|
231
|
+
filterOwner,
|
|
232
|
+
spatialFilter,
|
|
233
|
+
spatialFiltersMode,
|
|
234
|
+
spatialIndexReferenceViewState,
|
|
235
|
+
abortController,
|
|
236
|
+
...params
|
|
237
|
+
} = options;
|
|
246
238
|
const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
|
|
247
239
|
params;
|
|
248
240
|
|
|
241
|
+
const source = this.getModelSource(filterOwner);
|
|
242
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
243
|
+
source,
|
|
244
|
+
spatialFilter,
|
|
245
|
+
spatialIndexReferenceViewState
|
|
246
|
+
);
|
|
247
|
+
|
|
249
248
|
// Make sure this is sync with the same constant in cloud-native/maps-api
|
|
250
249
|
const HARD_LIMIT = 500;
|
|
251
250
|
|
|
@@ -253,7 +252,12 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
253
252
|
|
|
254
253
|
return executeModel({
|
|
255
254
|
model: 'scatterplot',
|
|
256
|
-
source: {
|
|
255
|
+
source: {
|
|
256
|
+
...source,
|
|
257
|
+
spatialFiltersResolution,
|
|
258
|
+
spatialFiltersMode,
|
|
259
|
+
spatialFilter,
|
|
260
|
+
},
|
|
257
261
|
params: {
|
|
258
262
|
xAxisColumn,
|
|
259
263
|
xAxisJoinOperation,
|
|
@@ -267,17 +271,22 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
267
271
|
.then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
|
|
268
272
|
}
|
|
269
273
|
|
|
270
|
-
/****************************************************************************
|
|
271
|
-
* TABLE
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Returns a list of arbitrary data rows, with support for pagination and
|
|
276
|
-
* sorting. Suitable for displaying tables and lists.
|
|
277
|
-
*/
|
|
278
274
|
async getTable(options: TableRequestOptions): Promise<TableResponse> {
|
|
279
|
-
const {
|
|
275
|
+
const {
|
|
276
|
+
filterOwner,
|
|
277
|
+
spatialFilter,
|
|
278
|
+
spatialFiltersMode,
|
|
279
|
+
spatialIndexReferenceViewState,
|
|
280
|
+
abortController,
|
|
281
|
+
...params
|
|
282
|
+
} = options;
|
|
280
283
|
const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
|
|
284
|
+
const source = this.getModelSource(filterOwner);
|
|
285
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
286
|
+
source,
|
|
287
|
+
spatialFilter,
|
|
288
|
+
spatialIndexReferenceViewState
|
|
289
|
+
);
|
|
281
290
|
|
|
282
291
|
type TableModelResponse = {
|
|
283
292
|
rows: Record<string, number | string>[];
|
|
@@ -286,7 +295,12 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
286
295
|
|
|
287
296
|
return executeModel({
|
|
288
297
|
model: 'table',
|
|
289
|
-
source: {
|
|
298
|
+
source: {
|
|
299
|
+
...source,
|
|
300
|
+
spatialFiltersResolution,
|
|
301
|
+
spatialFiltersMode,
|
|
302
|
+
spatialFilter,
|
|
303
|
+
},
|
|
290
304
|
params: {
|
|
291
305
|
column: columns,
|
|
292
306
|
sortBy,
|
|
@@ -302,18 +316,17 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
302
316
|
}));
|
|
303
317
|
}
|
|
304
318
|
|
|
305
|
-
/****************************************************************************
|
|
306
|
-
* TIME SERIES
|
|
307
|
-
*/
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Returns a series of labeled numerical values, grouped into equally-sized
|
|
311
|
-
* time intervals. Suitable for rendering time series charts.
|
|
312
|
-
*/
|
|
313
319
|
async getTimeSeries(
|
|
314
320
|
options: TimeSeriesRequestOptions
|
|
315
321
|
): Promise<TimeSeriesResponse> {
|
|
316
|
-
const {
|
|
322
|
+
const {
|
|
323
|
+
filterOwner,
|
|
324
|
+
abortController,
|
|
325
|
+
spatialFilter,
|
|
326
|
+
spatialFiltersMode,
|
|
327
|
+
spatialIndexReferenceViewState,
|
|
328
|
+
...params
|
|
329
|
+
} = options;
|
|
317
330
|
const {
|
|
318
331
|
column,
|
|
319
332
|
operationColumn,
|
|
@@ -326,6 +339,13 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
326
339
|
splitByCategoryValues,
|
|
327
340
|
} = params;
|
|
328
341
|
|
|
342
|
+
const source = this.getModelSource(filterOwner);
|
|
343
|
+
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
344
|
+
source,
|
|
345
|
+
spatialFilter,
|
|
346
|
+
spatialIndexReferenceViewState
|
|
347
|
+
);
|
|
348
|
+
|
|
329
349
|
type TimeSeriesModelResponse = {
|
|
330
350
|
rows: {name: string; value: number}[];
|
|
331
351
|
metadata: {categories: string[]};
|
|
@@ -333,7 +353,12 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
333
353
|
|
|
334
354
|
return executeModel({
|
|
335
355
|
model: 'timeseries',
|
|
336
|
-
source: {
|
|
356
|
+
source: {
|
|
357
|
+
...source,
|
|
358
|
+
spatialFiltersResolution,
|
|
359
|
+
spatialFiltersMode,
|
|
360
|
+
spatialFilter,
|
|
361
|
+
},
|
|
337
362
|
params: {
|
|
338
363
|
column,
|
|
339
364
|
stepSize,
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CategoryRequestOptions,
|
|
3
|
+
CategoryResponse,
|
|
4
|
+
FeaturesRequestOptions,
|
|
5
|
+
FeaturesResponse,
|
|
6
|
+
FormulaRequestOptions,
|
|
7
|
+
FormulaResponse,
|
|
8
|
+
HistogramRequestOptions,
|
|
9
|
+
HistogramResponse,
|
|
10
|
+
RangeRequestOptions,
|
|
11
|
+
RangeResponse,
|
|
12
|
+
ScatterRequestOptions,
|
|
13
|
+
ScatterResponse,
|
|
14
|
+
TableRequestOptions,
|
|
15
|
+
TableResponse,
|
|
16
|
+
TimeSeriesRequestOptions,
|
|
17
|
+
TimeSeriesResponse,
|
|
18
|
+
ViewState,
|
|
19
|
+
} from './types.js';
|
|
20
|
+
import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
|
|
21
|
+
import {getApplicableFilters} from '../utils.js';
|
|
22
|
+
import {getClient} from '../client.js';
|
|
23
|
+
import {ModelSource} from '../models/model.js';
|
|
24
|
+
import {SourceOptions} from '../sources/index.js';
|
|
25
|
+
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
26
|
+
import {getSpatialFiltersResolution} from '../spatial-index.js';
|
|
27
|
+
import {AggregationOptions} from '../sources/types.js';
|
|
28
|
+
|
|
29
|
+
export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
30
|
+
apiVersion?: ApiVersion;
|
|
31
|
+
filters?: Record<string, Filter>;
|
|
32
|
+
filtersLogicalOperator?: FilterLogicalOperator;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Source for Widget API requests on a data source defined by a SQL query.
|
|
37
|
+
*
|
|
38
|
+
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
39
|
+
*/
|
|
40
|
+
export abstract class WidgetSource<Props extends WidgetSourceProps> {
|
|
41
|
+
readonly props: Props;
|
|
42
|
+
|
|
43
|
+
static defaultProps: Partial<WidgetSourceProps> = {
|
|
44
|
+
apiVersion: ApiVersion.V3,
|
|
45
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
46
|
+
clientId: getClient(),
|
|
47
|
+
filters: {},
|
|
48
|
+
filtersLogicalOperator: 'and',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
constructor(props: Props) {
|
|
52
|
+
this.props = {...WidgetSource.defaultProps, ...props};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Subclasses of {@link WidgetRemoteSource} must implement this method, calling
|
|
57
|
+
* {@link WidgetRemoteSource.prototype._getModelSource} for common source
|
|
58
|
+
* properties, and adding additional required properties including 'type' and
|
|
59
|
+
* 'data'.
|
|
60
|
+
*/
|
|
61
|
+
protected abstract getModelSource(owner: string | undefined): ModelSource;
|
|
62
|
+
|
|
63
|
+
protected _getModelSource(
|
|
64
|
+
owner?: string
|
|
65
|
+
): Omit<ModelSource, 'type' | 'data'> {
|
|
66
|
+
const props = this.props;
|
|
67
|
+
return {
|
|
68
|
+
apiVersion: props.apiVersion as ApiVersion,
|
|
69
|
+
apiBaseUrl: props.apiBaseUrl as string,
|
|
70
|
+
clientId: props.clientId as string,
|
|
71
|
+
accessToken: props.accessToken,
|
|
72
|
+
connectionName: props.connectionName,
|
|
73
|
+
filters: getApplicableFilters(owner, props.filters),
|
|
74
|
+
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
75
|
+
spatialDataType: props.spatialDataType,
|
|
76
|
+
spatialDataColumn: props.spatialDataColumn,
|
|
77
|
+
dataResolution: (props as Partial<AggregationOptions>).dataResolution,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected _getSpatialFiltersResolution(
|
|
82
|
+
source: Omit<ModelSource, 'type' | 'data'>,
|
|
83
|
+
spatialFilter?: SpatialFilter,
|
|
84
|
+
referenceViewState?: ViewState
|
|
85
|
+
): number | undefined {
|
|
86
|
+
// spatialFiltersResolution applies only to spatial index sources.
|
|
87
|
+
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!referenceViewState) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
'Missing required option, "spatialIndexReferenceViewState".'
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return getSpatialFiltersResolution(source, referenceViewState);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
102
|
+
* charts including grouped bar charts, pie charts, and tree charts.
|
|
103
|
+
*/
|
|
104
|
+
abstract getCategories(
|
|
105
|
+
options: CategoryRequestOptions
|
|
106
|
+
): Promise<CategoryResponse>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
110
|
+
* matching features. In datasets containing features with duplicate geometries,
|
|
111
|
+
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
112
|
+
* results may be returned than IDs in the request.
|
|
113
|
+
* @internal
|
|
114
|
+
* @experimental
|
|
115
|
+
*/
|
|
116
|
+
abstract getFeatures(
|
|
117
|
+
options: FeaturesRequestOptions
|
|
118
|
+
): Promise<FeaturesResponse>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns a scalar numerical statistic over all matching data. Suitable
|
|
122
|
+
* for 'headline' or 'scorecard' figures such as counts and sums.
|
|
123
|
+
*/
|
|
124
|
+
abstract getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Returns a list of labeled datapoints for 'bins' of data defined as ticks
|
|
128
|
+
* over a numerical range. Suitable for histogram charts.
|
|
129
|
+
*/
|
|
130
|
+
abstract getHistogram(
|
|
131
|
+
options: HistogramRequestOptions
|
|
132
|
+
): Promise<HistogramResponse>;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Returns a range (min and max) for a numerical column of matching rows.
|
|
136
|
+
* Suitable for displaying certain 'headline' or 'scorecard' statistics,
|
|
137
|
+
* or rendering a range slider UI for filtering.
|
|
138
|
+
*/
|
|
139
|
+
abstract getRange(options: RangeRequestOptions): Promise<RangeResponse>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
|
|
143
|
+
* values. Suitable for rendering scatter plots.
|
|
144
|
+
*/
|
|
145
|
+
abstract getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns a list of arbitrary data rows, with support for pagination and
|
|
149
|
+
* sorting. Suitable for displaying tables and lists.
|
|
150
|
+
*/
|
|
151
|
+
abstract getTable(options: TableRequestOptions): Promise<TableResponse>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns a series of labeled numerical values, grouped into equally-sized
|
|
155
|
+
* time intervals. Suitable for rendering time series charts.
|
|
156
|
+
*/
|
|
157
|
+
abstract getTimeSeries(
|
|
158
|
+
options: TimeSeriesRequestOptions
|
|
159
|
+
): Promise<TimeSeriesResponse>;
|
|
160
|
+
}
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
QuadbinTableSourceOptions,
|
|
4
4
|
VectorTableSourceOptions,
|
|
5
5
|
} from '../sources/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
WidgetRemoteSource,
|
|
8
|
+
WidgetRemoteSourceProps,
|
|
9
|
+
} from './widget-remote-source.js';
|
|
7
10
|
import {ModelSource} from '../models/model.js';
|
|
8
11
|
|
|
9
12
|
type LayerTableSourceOptions =
|
|
@@ -35,8 +38,8 @@ export type WidgetTableSourceResult = {widgetSource: WidgetTableSource};
|
|
|
35
38
|
* const { widgetSource } = await data;
|
|
36
39
|
* ```
|
|
37
40
|
*/
|
|
38
|
-
export class WidgetTableSource extends
|
|
39
|
-
LayerTableSourceOptions &
|
|
41
|
+
export class WidgetTableSource extends WidgetRemoteSource<
|
|
42
|
+
LayerTableSourceOptions & WidgetRemoteSourceProps
|
|
40
43
|
> {
|
|
41
44
|
protected override getModelSource(owner: string): ModelSource {
|
|
42
45
|
return {
|