@carto/api-client 0.4.6 → 0.4.7-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/build/api-client.cjs +3473 -1556
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +1389 -0
- package/build/api-client.d.ts +1389 -0
- package/build/api-client.js +3676 -0
- package/build/api-client.js.map +1 -0
- package/build/worker.d.ts +2 -0
- package/build/worker.js +1949 -0
- package/build/worker.js.map +1 -0
- package/package.json +58 -40
- package/src/api/carto-api-error.ts +1 -1
- package/src/api/query.ts +5 -5
- package/src/api/request-with-parameters.ts +6 -6
- package/src/client.ts +3 -3
- package/src/constants-internal.ts +5 -11
- package/src/constants.ts +28 -3
- package/src/deck/get-data-filter-extension-props.ts +146 -0
- package/src/deck/index.ts +1 -0
- package/src/filters/Filter.ts +179 -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 +51 -0
- package/src/filters/tileFeaturesGeometries.ts +444 -0
- package/src/filters/tileFeaturesSpatialIndex.ts +119 -0
- package/src/filters.ts +4 -4
- package/src/geo.ts +12 -14
- package/src/global.d.ts +3 -8
- package/src/index.ts +7 -0
- package/src/models/common.ts +11 -9
- package/src/models/index.ts +1 -1
- package/src/models/model.ts +3 -4
- 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/base-source.ts +8 -8
- package/src/sources/boundary-query-source.ts +2 -2
- package/src/sources/boundary-table-source.ts +2 -2
- package/src/sources/h3-query-source.ts +7 -5
- package/src/sources/h3-table-source.ts +7 -5
- package/src/sources/h3-tileset-source.ts +20 -8
- package/src/sources/index.ts +26 -26
- package/src/sources/quadbin-query-source.ts +7 -5
- package/src/sources/quadbin-table-source.ts +7 -5
- package/src/sources/quadbin-tileset-source.ts +20 -8
- package/src/sources/raster-source.ts +3 -2
- package/src/sources/types.ts +9 -3
- package/src/sources/vector-query-source.ts +7 -5
- package/src/sources/vector-table-source.ts +7 -5
- package/src/sources/vector-tileset-source.ts +21 -8
- package/src/spatial-index.ts +4 -5
- package/src/types-internal.ts +11 -5
- package/src/types.ts +73 -15
- 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 +3 -3
- package/src/widget-sources/index.ts +3 -1
- package/src/widget-sources/types.ts +37 -25
- package/src/widget-sources/widget-query-source.ts +12 -5
- package/src/widget-sources/{widget-base-source.ts → widget-remote-source.ts} +55 -149
- package/src/widget-sources/widget-source.ts +145 -0
- package/src/widget-sources/widget-table-source.ts +12 -5
- package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
- package/src/widget-sources/widget-tileset-source.ts +311 -0
- package/src/workers/constants.ts +13 -0
- package/src/workers/types.ts +19 -0
- package/src/workers/widget-tileset-worker.ts +40 -0
- package/build/api/carto-api-error.d.ts +0 -26
- package/build/api/endpoints.d.ts +0 -24
- package/build/api/index.d.ts +0 -5
- package/build/api/query.d.ts +0 -3
- package/build/api/request-with-parameters.d.ts +0 -10
- package/build/api-client.modern.js +0 -1742
- package/build/api-client.modern.js.map +0 -1
- package/build/client.d.ts +0 -14
- package/build/constants-internal.d.ts +0 -26
- package/build/constants.d.ts +0 -31
- package/build/filters.d.ts +0 -39
- package/build/geo.d.ts +0 -19
- package/build/index.d.ts +0 -11
- package/build/models/common.d.ts +0 -27
- package/build/models/index.d.ts +0 -3
- package/build/models/model.d.ts +0 -37
- package/build/sources/base-source.d.ts +0 -4
- package/build/sources/boundary-query-source.d.ts +0 -10
- package/build/sources/boundary-table-source.d.ts +0 -8
- package/build/sources/h3-query-source.d.ts +0 -5
- package/build/sources/h3-table-source.d.ts +0 -5
- package/build/sources/h3-tileset-source.d.ts +0 -4
- package/build/sources/index.d.ts +0 -26
- package/build/sources/quadbin-query-source.d.ts +0 -5
- package/build/sources/quadbin-table-source.d.ts +0 -5
- package/build/sources/quadbin-tileset-source.d.ts +0 -4
- package/build/sources/raster-source.d.ts +0 -4
- package/build/sources/types.d.ts +0 -366
- package/build/sources/vector-query-source.d.ts +0 -5
- package/build/sources/vector-table-source.d.ts +0 -5
- package/build/sources/vector-tileset-source.d.ts +0 -4
- package/build/spatial-index.d.ts +0 -14
- package/build/types-internal.d.ts +0 -52
- package/build/types.d.ts +0 -80
- package/build/utils.d.ts +0 -32
- package/build/widget-sources/index.d.ts +0 -4
- package/build/widget-sources/types.d.ts +0 -149
- package/build/widget-sources/widget-base-source.d.ts +0 -99
- package/build/widget-sources/widget-query-source.d.ts +0 -33
- package/build/widget-sources/widget-table-source.d.ts +0 -33
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {executeModel} from '../models/index.js';
|
|
1
|
+
import {executeModel, ModelSource} from '../models/index.js';
|
|
2
2
|
import {
|
|
3
3
|
CategoryRequestOptions,
|
|
4
4
|
CategoryResponse,
|
|
@@ -16,56 +16,38 @@ import {
|
|
|
16
16
|
TableResponse,
|
|
17
17
|
TimeSeriesRequestOptions,
|
|
18
18
|
TimeSeriesResponse,
|
|
19
|
-
ViewState,
|
|
20
19
|
} from './types.js';
|
|
21
|
-
import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
|
|
22
20
|
import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
|
|
23
|
-
import {getClient} from '../client.js';
|
|
24
|
-
import {ModelSource} from '../models/model.js';
|
|
25
|
-
import {SourceOptions} from '../sources/index.js';
|
|
26
|
-
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
27
21
|
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
28
|
-
import {
|
|
22
|
+
import {WidgetSource, WidgetSourceProps} from './widget-source.js';
|
|
23
|
+
import {Filters} from '../types.js';
|
|
24
|
+
import {ApiVersion} from '../constants.js';
|
|
29
25
|
import {AggregationOptions} from '../sources/types.js';
|
|
30
26
|
|
|
31
|
-
export
|
|
32
|
-
apiVersion?: ApiVersion;
|
|
33
|
-
filters?: Record<string, Filter>;
|
|
34
|
-
filtersLogicalOperator?: FilterLogicalOperator;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type WidgetSource = WidgetBaseSource<WidgetBaseSourceProps>;
|
|
27
|
+
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
38
28
|
|
|
39
29
|
/**
|
|
40
|
-
* Source for Widget API requests
|
|
30
|
+
* Source for Widget API requests.
|
|
41
31
|
*
|
|
42
32
|
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
43
33
|
*/
|
|
44
|
-
export abstract class
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
static defaultProps: Partial<WidgetBaseSourceProps> = {
|
|
48
|
-
apiVersion: ApiVersion.V3,
|
|
49
|
-
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
50
|
-
clientId: getClient(),
|
|
51
|
-
filters: {},
|
|
52
|
-
filtersLogicalOperator: 'and',
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
constructor(props: Props) {
|
|
56
|
-
this.props = {...WidgetBaseSource.defaultProps, ...props};
|
|
57
|
-
}
|
|
58
|
-
|
|
34
|
+
export abstract class WidgetRemoteSource<
|
|
35
|
+
Props extends WidgetRemoteSourceProps,
|
|
36
|
+
> extends WidgetSource<Props> {
|
|
59
37
|
/**
|
|
60
|
-
* Subclasses of {@link
|
|
61
|
-
* {@link
|
|
38
|
+
* Subclasses of {@link WidgetRemoteSource} must implement this method, calling
|
|
39
|
+
* {@link WidgetRemoteSource.prototype._getModelSource} for common source
|
|
62
40
|
* properties, and adding additional required properties including 'type' and
|
|
63
41
|
* 'data'.
|
|
64
42
|
*/
|
|
65
|
-
protected abstract getModelSource(
|
|
43
|
+
protected abstract getModelSource(
|
|
44
|
+
filters: Filters | undefined,
|
|
45
|
+
filterOwner?: string
|
|
46
|
+
): ModelSource;
|
|
66
47
|
|
|
67
48
|
protected _getModelSource(
|
|
68
|
-
|
|
49
|
+
filters: Filters | undefined,
|
|
50
|
+
filterOwner?: string
|
|
69
51
|
): Omit<ModelSource, 'type' | 'data'> {
|
|
70
52
|
const props = this.props;
|
|
71
53
|
return {
|
|
@@ -74,7 +56,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
74
56
|
clientId: props.clientId as string,
|
|
75
57
|
accessToken: props.accessToken,
|
|
76
58
|
connectionName: props.connectionName,
|
|
77
|
-
filters: getApplicableFilters(
|
|
59
|
+
filters: getApplicableFilters(filterOwner, filters || props.filters),
|
|
78
60
|
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
79
61
|
spatialDataType: props.spatialDataType,
|
|
80
62
|
spatialDataColumn: props.spatialDataColumn,
|
|
@@ -82,46 +64,20 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
82
64
|
};
|
|
83
65
|
}
|
|
84
66
|
|
|
85
|
-
protected _getSpatialFiltersResolution(
|
|
86
|
-
source: Omit<ModelSource, 'type' | 'data'>,
|
|
87
|
-
spatialFilter?: SpatialFilter,
|
|
88
|
-
referenceViewState?: ViewState
|
|
89
|
-
): number | undefined {
|
|
90
|
-
// spatialFiltersResolution applies only to spatial index sources.
|
|
91
|
-
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!referenceViewState) {
|
|
96
|
-
throw new Error(
|
|
97
|
-
'Missing required option, "spatialIndexReferenceViewState".'
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return getSpatialFiltersResolution(source, referenceViewState);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/****************************************************************************
|
|
105
|
-
* CATEGORIES
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
110
|
-
* charts including grouped bar charts, pie charts, and tree charts.
|
|
111
|
-
*/
|
|
112
67
|
async getCategories(
|
|
113
68
|
options: CategoryRequestOptions
|
|
114
69
|
): Promise<CategoryResponse> {
|
|
115
70
|
const {
|
|
71
|
+
signal,
|
|
72
|
+
filters = this.props.filters,
|
|
116
73
|
filterOwner,
|
|
117
74
|
spatialFilter,
|
|
118
75
|
spatialFiltersMode,
|
|
119
76
|
spatialIndexReferenceViewState,
|
|
120
|
-
abortController,
|
|
121
77
|
...params
|
|
122
78
|
} = options;
|
|
123
79
|
const {column, operation, operationColumn} = params;
|
|
124
|
-
const source = this.getModelSource(filterOwner);
|
|
80
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
125
81
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
126
82
|
source,
|
|
127
83
|
spatialFilter,
|
|
@@ -143,35 +99,24 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
143
99
|
operation,
|
|
144
100
|
operationColumn: operationColumn || column,
|
|
145
101
|
},
|
|
146
|
-
opts: {
|
|
102
|
+
opts: {signal, headers: this.props.headers},
|
|
147
103
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
148
104
|
}
|
|
149
105
|
|
|
150
|
-
/****************************************************************************
|
|
151
|
-
* FEATURES
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
156
|
-
* matching features. In datasets containing features with duplicate geometries,
|
|
157
|
-
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
158
|
-
* results may be returned than IDs in the request.
|
|
159
|
-
* @internal
|
|
160
|
-
* @experimental
|
|
161
|
-
*/
|
|
162
106
|
async getFeatures(
|
|
163
107
|
options: FeaturesRequestOptions
|
|
164
108
|
): Promise<FeaturesResponse> {
|
|
165
109
|
const {
|
|
110
|
+
signal,
|
|
111
|
+
filters = this.props.filters,
|
|
166
112
|
filterOwner,
|
|
167
113
|
spatialFilter,
|
|
168
114
|
spatialFiltersMode,
|
|
169
115
|
spatialIndexReferenceViewState,
|
|
170
|
-
abortController,
|
|
171
116
|
...params
|
|
172
117
|
} = options;
|
|
173
118
|
const {columns, dataType, featureIds, z, limit, tileResolution} = params;
|
|
174
|
-
const source = this.getModelSource(filterOwner);
|
|
119
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
175
120
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
176
121
|
source,
|
|
177
122
|
spatialFilter,
|
|
@@ -196,31 +141,24 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
196
141
|
limit: limit || 1000,
|
|
197
142
|
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
|
|
198
143
|
},
|
|
199
|
-
opts: {
|
|
144
|
+
opts: {signal, headers: this.props.headers},
|
|
200
145
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
201
146
|
}).then(({rows}: FeaturesModelResponse) => ({rows}));
|
|
202
147
|
}
|
|
203
148
|
|
|
204
|
-
/****************************************************************************
|
|
205
|
-
* FORMULA
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Returns a scalar numerical statistic over all matching data. Suitable
|
|
210
|
-
* for 'headline' or 'scorecard' figures such as counts and sums.
|
|
211
|
-
*/
|
|
212
149
|
async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
|
|
213
150
|
const {
|
|
151
|
+
signal,
|
|
152
|
+
filters = this.props.filters,
|
|
214
153
|
filterOwner,
|
|
215
154
|
spatialFilter,
|
|
216
155
|
spatialFiltersMode,
|
|
217
156
|
spatialIndexReferenceViewState,
|
|
218
|
-
abortController,
|
|
219
157
|
operationExp,
|
|
220
158
|
...params
|
|
221
159
|
} = options;
|
|
222
160
|
const {column, operation} = params;
|
|
223
|
-
const source = this.getModelSource(filterOwner);
|
|
161
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
224
162
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
225
163
|
source,
|
|
226
164
|
spatialFilter,
|
|
@@ -237,32 +175,29 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
237
175
|
spatialFiltersMode,
|
|
238
176
|
spatialFilter,
|
|
239
177
|
},
|
|
240
|
-
params: {
|
|
241
|
-
|
|
178
|
+
params: {
|
|
179
|
+
column: column ?? '*',
|
|
180
|
+
operation: operation ?? 'count',
|
|
181
|
+
operationExp,
|
|
182
|
+
},
|
|
183
|
+
opts: {signal, headers: this.props.headers},
|
|
242
184
|
}).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
243
185
|
}
|
|
244
186
|
|
|
245
|
-
/****************************************************************************
|
|
246
|
-
* HISTOGRAM
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Returns a list of labeled datapoints for 'bins' of data defined as ticks
|
|
251
|
-
* over a numerical range. Suitable for histogram charts.
|
|
252
|
-
*/
|
|
253
187
|
async getHistogram(
|
|
254
188
|
options: HistogramRequestOptions
|
|
255
189
|
): Promise<HistogramResponse> {
|
|
256
190
|
const {
|
|
191
|
+
signal,
|
|
192
|
+
filters = this.props.filters,
|
|
257
193
|
filterOwner,
|
|
258
194
|
spatialFilter,
|
|
259
195
|
spatialFiltersMode,
|
|
260
196
|
spatialIndexReferenceViewState,
|
|
261
|
-
abortController,
|
|
262
197
|
...params
|
|
263
198
|
} = options;
|
|
264
199
|
const {column, operation, ticks} = params;
|
|
265
|
-
const source = this.getModelSource(filterOwner);
|
|
200
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
266
201
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
267
202
|
source,
|
|
268
203
|
spatialFilter,
|
|
@@ -280,7 +215,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
280
215
|
spatialFilter,
|
|
281
216
|
},
|
|
282
217
|
params: {column, operation, ticks},
|
|
283
|
-
opts: {
|
|
218
|
+
opts: {signal, headers: this.props.headers},
|
|
284
219
|
}).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
|
|
285
220
|
|
|
286
221
|
if (data.length) {
|
|
@@ -296,26 +231,18 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
296
231
|
return [];
|
|
297
232
|
}
|
|
298
233
|
|
|
299
|
-
/****************************************************************************
|
|
300
|
-
* RANGE
|
|
301
|
-
*/
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Returns a range (min and max) for a numerical column of matching rows.
|
|
305
|
-
* Suitable for displaying certain 'headline' or 'scorecard' statistics,
|
|
306
|
-
* or rendering a range slider UI for filtering.
|
|
307
|
-
*/
|
|
308
234
|
async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
|
|
309
235
|
const {
|
|
236
|
+
signal,
|
|
237
|
+
filters = this.props.filters,
|
|
310
238
|
filterOwner,
|
|
311
239
|
spatialFilter,
|
|
312
240
|
spatialFiltersMode,
|
|
313
241
|
spatialIndexReferenceViewState,
|
|
314
|
-
abortController,
|
|
315
242
|
...params
|
|
316
243
|
} = options;
|
|
317
244
|
const {column} = params;
|
|
318
|
-
const source = this.getModelSource(filterOwner);
|
|
245
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
319
246
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
320
247
|
source,
|
|
321
248
|
spatialFilter,
|
|
@@ -333,31 +260,24 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
333
260
|
spatialFilter,
|
|
334
261
|
},
|
|
335
262
|
params: {column},
|
|
336
|
-
opts: {
|
|
263
|
+
opts: {signal, headers: this.props.headers},
|
|
337
264
|
}).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
338
265
|
}
|
|
339
266
|
|
|
340
|
-
/****************************************************************************
|
|
341
|
-
* SCATTER
|
|
342
|
-
*/
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
|
|
346
|
-
* values. Suitable for rendering scatter plots.
|
|
347
|
-
*/
|
|
348
267
|
async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
|
|
349
268
|
const {
|
|
269
|
+
signal,
|
|
270
|
+
filters = this.props.filters,
|
|
350
271
|
filterOwner,
|
|
351
272
|
spatialFilter,
|
|
352
273
|
spatialFiltersMode,
|
|
353
274
|
spatialIndexReferenceViewState,
|
|
354
|
-
abortController,
|
|
355
275
|
...params
|
|
356
276
|
} = options;
|
|
357
277
|
const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
|
|
358
278
|
params;
|
|
359
279
|
|
|
360
|
-
const source = this.getModelSource(filterOwner);
|
|
280
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
361
281
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
362
282
|
source,
|
|
363
283
|
spatialFilter,
|
|
@@ -384,31 +304,24 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
384
304
|
yAxisJoinOperation,
|
|
385
305
|
limit: HARD_LIMIT,
|
|
386
306
|
},
|
|
387
|
-
opts: {
|
|
307
|
+
opts: {signal, headers: this.props.headers},
|
|
388
308
|
})
|
|
389
309
|
.then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
|
|
390
310
|
.then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
|
|
391
311
|
}
|
|
392
312
|
|
|
393
|
-
/****************************************************************************
|
|
394
|
-
* TABLE
|
|
395
|
-
*/
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Returns a list of arbitrary data rows, with support for pagination and
|
|
399
|
-
* sorting. Suitable for displaying tables and lists.
|
|
400
|
-
*/
|
|
401
313
|
async getTable(options: TableRequestOptions): Promise<TableResponse> {
|
|
402
314
|
const {
|
|
315
|
+
signal,
|
|
316
|
+
filters = this.props.filters,
|
|
403
317
|
filterOwner,
|
|
404
318
|
spatialFilter,
|
|
405
319
|
spatialFiltersMode,
|
|
406
320
|
spatialIndexReferenceViewState,
|
|
407
|
-
abortController,
|
|
408
321
|
...params
|
|
409
322
|
} = options;
|
|
410
323
|
const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
|
|
411
|
-
const source = this.getModelSource(filterOwner);
|
|
324
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
412
325
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
413
326
|
source,
|
|
414
327
|
spatialFilter,
|
|
@@ -435,7 +348,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
435
348
|
limit,
|
|
436
349
|
offset,
|
|
437
350
|
},
|
|
438
|
-
opts: {
|
|
351
|
+
opts: {signal, headers: this.props.headers},
|
|
439
352
|
}).then((res: TableModelResponse) => ({
|
|
440
353
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
441
354
|
rows: res.rows ?? (res as any).ROWS,
|
|
@@ -443,20 +356,13 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
443
356
|
}));
|
|
444
357
|
}
|
|
445
358
|
|
|
446
|
-
/****************************************************************************
|
|
447
|
-
* TIME SERIES
|
|
448
|
-
*/
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Returns a series of labeled numerical values, grouped into equally-sized
|
|
452
|
-
* time intervals. Suitable for rendering time series charts.
|
|
453
|
-
*/
|
|
454
359
|
async getTimeSeries(
|
|
455
360
|
options: TimeSeriesRequestOptions
|
|
456
361
|
): Promise<TimeSeriesResponse> {
|
|
457
362
|
const {
|
|
363
|
+
signal,
|
|
364
|
+
filters = this.props.filters,
|
|
458
365
|
filterOwner,
|
|
459
|
-
abortController,
|
|
460
366
|
spatialFilter,
|
|
461
367
|
spatialFiltersMode,
|
|
462
368
|
spatialIndexReferenceViewState,
|
|
@@ -474,7 +380,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
474
380
|
splitByCategoryValues,
|
|
475
381
|
} = params;
|
|
476
382
|
|
|
477
|
-
const source = this.getModelSource(filterOwner);
|
|
383
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
478
384
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
479
385
|
source,
|
|
480
386
|
spatialFilter,
|
|
@@ -505,7 +411,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
505
411
|
splitByCategoryLimit,
|
|
506
412
|
splitByCategoryValues,
|
|
507
413
|
},
|
|
508
|
-
opts: {
|
|
414
|
+
opts: {signal, headers: this.props.headers},
|
|
509
415
|
}).then((res: TimeSeriesModelResponse) => ({
|
|
510
416
|
rows: normalizeObjectKeys(res.rows),
|
|
511
417
|
categories: res.metadata?.categories,
|
|
@@ -0,0 +1,145 @@
|
|
|
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 {getClient} from '../client.js';
|
|
22
|
+
import {ModelSource} from '../models/model.js';
|
|
23
|
+
import {SourceOptions} from '../sources/index.js';
|
|
24
|
+
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
25
|
+
import {getSpatialFiltersResolution} from '../spatial-index.js';
|
|
26
|
+
|
|
27
|
+
export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
28
|
+
apiVersion?: ApiVersion;
|
|
29
|
+
filters?: Record<string, Filter>;
|
|
30
|
+
filtersLogicalOperator?: FilterLogicalOperator;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Source for Widget API requests on a data source defined by a SQL query.
|
|
35
|
+
*
|
|
36
|
+
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
37
|
+
*/
|
|
38
|
+
export abstract class WidgetSource<
|
|
39
|
+
Props extends WidgetSourceProps = WidgetSourceProps,
|
|
40
|
+
> {
|
|
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
|
+
* Destroys the widget source and releases allocated resources.
|
|
57
|
+
*
|
|
58
|
+
* For remote sources (tables, queries) this has no effect, but for local
|
|
59
|
+
* sources (tilesets, rasters) these resources will affect performance
|
|
60
|
+
* and stability if many (10+) sources are created and not released.
|
|
61
|
+
*/
|
|
62
|
+
destroy() {
|
|
63
|
+
// no-op in most cases, but required for worker sources.
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected _getSpatialFiltersResolution(
|
|
67
|
+
source: Omit<ModelSource, 'type' | 'data'>,
|
|
68
|
+
spatialFilter?: SpatialFilter,
|
|
69
|
+
referenceViewState?: ViewState
|
|
70
|
+
): number | undefined {
|
|
71
|
+
// spatialFiltersResolution applies only to spatial index sources.
|
|
72
|
+
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!referenceViewState) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
'Missing required option, "spatialIndexReferenceViewState".'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return getSpatialFiltersResolution(source, referenceViewState);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
87
|
+
* charts including grouped bar charts, pie charts, and tree charts.
|
|
88
|
+
*/
|
|
89
|
+
abstract getCategories(
|
|
90
|
+
options: CategoryRequestOptions
|
|
91
|
+
): Promise<CategoryResponse>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
95
|
+
* matching features. In datasets containing features with duplicate geometries,
|
|
96
|
+
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
97
|
+
* results may be returned than IDs in the request.
|
|
98
|
+
* @internal
|
|
99
|
+
* @experimental
|
|
100
|
+
*/
|
|
101
|
+
abstract getFeatures(
|
|
102
|
+
options: FeaturesRequestOptions
|
|
103
|
+
): Promise<FeaturesResponse>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns a scalar numerical statistic over all matching data. Suitable
|
|
107
|
+
* for 'headline' or 'scorecard' figures such as counts and sums.
|
|
108
|
+
*/
|
|
109
|
+
abstract getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Returns a list of labeled datapoints for 'bins' of data defined as ticks
|
|
113
|
+
* over a numerical range. Suitable for histogram charts.
|
|
114
|
+
*/
|
|
115
|
+
abstract getHistogram(
|
|
116
|
+
options: HistogramRequestOptions
|
|
117
|
+
): Promise<HistogramResponse>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Returns a range (min and max) for a numerical column of matching rows.
|
|
121
|
+
* Suitable for displaying certain 'headline' or 'scorecard' statistics,
|
|
122
|
+
* or rendering a range slider UI for filtering.
|
|
123
|
+
*/
|
|
124
|
+
abstract getRange(options: RangeRequestOptions): Promise<RangeResponse>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
|
|
128
|
+
* values. Suitable for rendering scatter plots.
|
|
129
|
+
*/
|
|
130
|
+
abstract getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns a list of arbitrary data rows, with support for pagination and
|
|
134
|
+
* sorting. Suitable for displaying tables and lists.
|
|
135
|
+
*/
|
|
136
|
+
abstract getTable(options: TableRequestOptions): Promise<TableResponse>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns a series of labeled numerical values, grouped into equally-sized
|
|
140
|
+
* time intervals. Suitable for rendering time series charts.
|
|
141
|
+
*/
|
|
142
|
+
abstract getTimeSeries(
|
|
143
|
+
options: TimeSeriesRequestOptions
|
|
144
|
+
): Promise<TimeSeriesResponse>;
|
|
145
|
+
}
|
|
@@ -3,8 +3,12 @@ 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';
|
|
11
|
+
import {Filters} from '../types.js';
|
|
8
12
|
|
|
9
13
|
type LayerTableSourceOptions =
|
|
10
14
|
| Omit<VectorTableSourceOptions, 'filters'>
|
|
@@ -35,12 +39,15 @@ export type WidgetTableSourceResult = {widgetSource: WidgetTableSource};
|
|
|
35
39
|
* const { widgetSource } = await data;
|
|
36
40
|
* ```
|
|
37
41
|
*/
|
|
38
|
-
export class WidgetTableSource extends
|
|
39
|
-
LayerTableSourceOptions &
|
|
42
|
+
export class WidgetTableSource extends WidgetRemoteSource<
|
|
43
|
+
LayerTableSourceOptions & WidgetRemoteSourceProps
|
|
40
44
|
> {
|
|
41
|
-
protected override getModelSource(
|
|
45
|
+
protected override getModelSource(
|
|
46
|
+
filters: Filters | undefined,
|
|
47
|
+
filterOwner?: string
|
|
48
|
+
): ModelSource {
|
|
42
49
|
return {
|
|
43
|
-
...super._getModelSource(
|
|
50
|
+
...super._getModelSource(filters, filterOwner),
|
|
44
51
|
type: 'table',
|
|
45
52
|
data: this.props.tableName,
|
|
46
53
|
};
|