@carto/api-client 0.5.0-alpha.8 → 0.5.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 (43) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/build/api-client.cjs +15248 -3366
  3. package/build/api-client.cjs.map +1 -0
  4. package/build/api-client.d.cts +529 -182
  5. package/build/api-client.d.ts +529 -182
  6. package/build/api-client.js +15000 -3227
  7. package/build/api-client.js.map +1 -0
  8. package/build/worker.js +5118 -810
  9. package/build/worker.js.map +1 -0
  10. package/package.json +47 -31
  11. package/src/api/query.ts +2 -1
  12. package/src/constants-internal.ts +10 -0
  13. package/src/constants.ts +5 -1
  14. package/src/deck/get-data-filter-extension-props.ts +27 -9
  15. package/src/fetch-map/basemap-styles.ts +159 -0
  16. package/src/fetch-map/basemap.ts +120 -0
  17. package/src/fetch-map/fetch-map.ts +331 -0
  18. package/src/fetch-map/index.ts +13 -0
  19. package/src/fetch-map/layer-map.ts +461 -0
  20. package/src/fetch-map/parse-map.ts +425 -0
  21. package/src/fetch-map/source.ts +233 -0
  22. package/src/fetch-map/types.ts +268 -0
  23. package/src/fetch-map/utils.ts +69 -0
  24. package/src/filters/tileFeatures.ts +27 -10
  25. package/src/filters/tileFeaturesRaster.ts +122 -0
  26. package/src/index.ts +1 -0
  27. package/src/models/model.ts +0 -7
  28. package/src/sources/base-source.ts +4 -2
  29. package/src/sources/h3-tileset-source.ts +1 -1
  30. package/src/sources/quadbin-tileset-source.ts +1 -1
  31. package/src/sources/raster-source.ts +18 -5
  32. package/src/sources/types.ts +15 -8
  33. package/src/sources/vector-tileset-source.ts +1 -1
  34. package/src/spatial-index.ts +3 -84
  35. package/src/types.ts +16 -2
  36. package/src/widget-sources/index.ts +1 -0
  37. package/src/widget-sources/types.ts +0 -2
  38. package/src/widget-sources/widget-raster-source.ts +14 -0
  39. package/src/widget-sources/widget-remote-source.ts +16 -91
  40. package/src/widget-sources/widget-source.ts +9 -25
  41. package/src/widget-sources/widget-tileset-source-impl.ts +13 -16
  42. package/src/widget-sources/widget-tileset-source.ts +53 -47
  43. package/src/workers/widget-tileset-worker.ts +5 -7
@@ -116,11 +116,6 @@ export type AggregationOptions = {
116
116
  * @default 6 for quadbin and 4 for h3 sources
117
117
  */
118
118
  aggregationResLevel?: number;
119
-
120
- /**
121
- * Original resolution of the spatial index data as stored in the DW
122
- */
123
- dataResolution?: number;
124
119
  };
125
120
 
126
121
  export type FilterOptions = {
@@ -196,7 +191,7 @@ export type TilesetSourceOptions = {
196
191
  * Whether to use Web Workers for local widget calculations. Workers
197
192
  * are used by default if the runtime environment supports ES Module Workers.
198
193
  */
199
- widgetSourceWorker?: boolean;
194
+ widgetWorker?: boolean;
200
195
  };
201
196
 
202
197
  export type ColumnsOption = {
@@ -364,8 +359,20 @@ export enum RasterBandColorinterp {
364
359
  Palette = 'palette',
365
360
  }
366
361
 
362
+ export type RasterBandType =
363
+ | 'uint8'
364
+ | 'int8'
365
+ | 'uint16'
366
+ | 'int16'
367
+ | 'uint32'
368
+ | 'int32'
369
+ | 'uint64'
370
+ | 'int64'
371
+ | 'float32'
372
+ | 'float64';
373
+
367
374
  export type RasterMetadataBand = {
368
- type: string;
375
+ type: RasterBandType;
369
376
  name: string;
370
377
  stats: RasterMetadataBandStats;
371
378
  /**
@@ -379,7 +386,7 @@ export type RasterMetadataBand = {
379
386
  /**
380
387
  * Default color mapping for unique values (or if coloprinterp is `palette`)
381
388
  */
382
- colortable?: Record<string, number[]>;
389
+ colortable?: Record<string, [number, number, number, number]>;
383
390
 
384
391
  /**
385
392
  * No value representation.
@@ -2,13 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
+ import {baseSource} from './base-source.js';
5
6
  import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
6
7
  import {getTileFormat} from '../utils/getTileFormat.js';
7
8
  import {
8
9
  WidgetTilesetSource,
9
10
  WidgetTilesetSourceResult,
10
11
  } from '../widget-sources/index.js';
11
- import {baseSource} from './base-source.js';
12
12
  import type {
13
13
  SourceOptions,
14
14
  TilesetSourceOptions,
@@ -1,88 +1,6 @@
1
- import {
2
- DEFAULT_AGGREGATION_RES_LEVEL_H3,
3
- DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
4
- } from './constants-internal.js';
5
- import type {ModelSource} from './models/model.js';
6
- import type {AggregationOptions} from './sources/types.js';
7
- import type {ViewState} from './widget-sources/index.js';
8
-
1
+ // Default tile display size in deck.gl, in viewport pixels. May differ
2
+ // from size or resolution assumed when generating the tile data,
9
3
  const DEFAULT_TILE_SIZE = 512;
10
- const QUADBIN_ZOOM_MAX_OFFSET = 4;
11
-
12
- export function getSpatialFiltersResolution(
13
- source: Partial<ModelSource & AggregationOptions>,
14
- viewState: ViewState
15
- ): number | undefined {
16
- const dataResolution = source.dataResolution ?? Number.MAX_VALUE;
17
-
18
- const aggregationResLevel =
19
- source.aggregationResLevel ??
20
- (source.spatialDataType === 'h3'
21
- ? DEFAULT_AGGREGATION_RES_LEVEL_H3
22
- : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
23
-
24
- const aggregationResLevelOffset = Math.max(
25
- 0,
26
- Math.floor(aggregationResLevel)
27
- );
28
-
29
- const currentZoomInt = Math.ceil(viewState.zoom);
30
- if (source.spatialDataType === 'h3') {
31
- const tileSize = DEFAULT_TILE_SIZE;
32
- const maxResolutionForZoom =
33
- maxH3SpatialFiltersResolutions.find(
34
- ([zoom]) => zoom === currentZoomInt
35
- )?.[1] ?? Math.max(0, currentZoomInt - 3);
36
-
37
- const maxSpatialFiltersResolution = maxResolutionForZoom
38
- ? Math.min(dataResolution, maxResolutionForZoom)
39
- : dataResolution;
40
-
41
- const hexagonResolution =
42
- _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
43
-
44
- return Math.min(hexagonResolution, maxSpatialFiltersResolution);
45
- }
46
-
47
- if (source.spatialDataType === 'quadbin') {
48
- const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
49
- const maxSpatialFiltersResolution = Math.min(
50
- dataResolution,
51
- maxResolutionForZoom
52
- );
53
-
54
- const quadsResolution =
55
- Math.floor(viewState.zoom) + aggregationResLevelOffset;
56
- return Math.min(quadsResolution, maxSpatialFiltersResolution);
57
- }
58
-
59
- return undefined;
60
- }
61
-
62
- const maxH3SpatialFiltersResolutions = [
63
- [20, 14],
64
- [19, 13],
65
- [18, 12],
66
- [17, 11],
67
- [16, 10],
68
- [15, 9],
69
- [14, 8],
70
- [13, 7],
71
- [12, 7],
72
- [11, 7],
73
- [10, 6],
74
- [9, 6],
75
- [8, 5],
76
- [7, 4],
77
- [6, 4],
78
- [5, 3],
79
- [4, 2],
80
- [3, 1],
81
- [2, 1],
82
- [1, 0],
83
- ];
84
-
85
- // stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
86
4
 
87
5
  // Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
88
6
  const BIAS = 2;
@@ -92,6 +10,7 @@ const BIAS = 2;
92
10
  * a H3 resolution such that the screen space size of the hexagons is
93
11
  * "similar" to the given tileSize on screen. Intended for use with deck.gl.
94
12
  * @internal
13
+ * @privateRemarks Source: https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
95
14
  */
96
15
  export function _getHexagonResolution(
97
16
  viewport: {zoom: number; latitude: number},
package/src/types.ts CHANGED
@@ -12,6 +12,16 @@ export type Format = 'json' | 'geojson' | 'tilejson';
12
12
  /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
13
13
  export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
14
14
 
15
+ /** @privateRemarks Source: cloud-native */
16
+ export type ProviderType =
17
+ | 'bigquery'
18
+ | 'postgres'
19
+ | 'snowflake'
20
+ | 'redshift'
21
+ | 'databricks'
22
+ | 'carto'
23
+ | 'carto_dw';
24
+
15
25
  /**
16
26
  * Alias for GeoJSON 'BBox' type, semantically representing a viewport.
17
27
  * Order of values is "west", "south", "east", "north".
@@ -28,8 +38,6 @@ export type Viewport = [number, number, number, number];
28
38
  export type Tile = {
29
39
  index: {x: number; y: number; z: number};
30
40
  id: string;
31
- content: unknown;
32
- zoom: number;
33
41
  bbox: {west: number; east: number; north: number; south: number};
34
42
  isVisible: boolean;
35
43
  data?: BinaryFeatureCollection;
@@ -40,6 +48,12 @@ export type SpatialIndexTile = Tile & {
40
48
  data?: (Feature & {id: bigint})[];
41
49
  };
42
50
 
51
+ export type RasterTile = Tile & {
52
+ id: string;
53
+ index: {q: bigint; i: string};
54
+ data?: Raster;
55
+ };
56
+
43
57
  /** @privateRemarks Source: @deck.gl/carto */
44
58
  export type Raster = {
45
59
  blockSize: number;
@@ -1,5 +1,6 @@
1
1
  export * from './widget-source.js';
2
2
  export * from './widget-query-source.js';
3
+ export * from './widget-raster-source.js';
3
4
  export * from './widget-remote-source.js';
4
5
  export * from './widget-table-source.js';
5
6
  export * from './widget-tileset-source.js';
@@ -22,8 +22,6 @@ interface BaseRequestOptions {
22
22
  signal?: AbortSignal;
23
23
  spatialFilter?: SpatialFilter;
24
24
  spatialFiltersMode?: SpatialFilterPolyfillMode;
25
- /** Required for table- and query-based spatial index sources (H3, Quadbin). */
26
- spatialIndexReferenceViewState?: ViewState;
27
25
  /** Overrides source filters, if any. */
28
26
  filters?: Filters;
29
27
  filterOwner?: string;
@@ -0,0 +1,14 @@
1
+ import {RasterMetadata} from '../sources/index.js';
2
+ import {
3
+ WidgetTilesetSource,
4
+ WidgetTilesetSourceProps,
5
+ } from './widget-tileset-source.js';
6
+
7
+ export type WidgetRasterSourceProps = WidgetTilesetSourceProps & {
8
+ rasterMetadata: RasterMetadata;
9
+ spatialDataType: 'quadbin';
10
+ };
11
+
12
+ export type WidgetRasterSourceResult = {widgetSource: WidgetRasterSource};
13
+
14
+ export class WidgetRasterSource extends WidgetTilesetSource<WidgetRasterSourceProps> {}
@@ -22,7 +22,6 @@ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
22
22
  import {WidgetSource, WidgetSourceProps} from './widget-source.js';
23
23
  import {Filters} from '../types.js';
24
24
  import {ApiVersion} from '../constants.js';
25
- import {AggregationOptions} from '../sources/types.js';
26
25
 
27
26
  export type WidgetRemoteSourceProps = WidgetSourceProps;
28
27
 
@@ -34,13 +33,6 @@ export type WidgetRemoteSourceProps = WidgetSourceProps;
34
33
  export abstract class WidgetRemoteSource<
35
34
  Props extends WidgetRemoteSourceProps,
36
35
  > extends WidgetSource<Props> {
37
- protected _headers: Record<string, string> = {};
38
-
39
- /** Assigns HTTP headers to be included on API requests from this source. */
40
- setRequestHeaders(headers: Record<string, string>): void {
41
- this._headers = headers;
42
- }
43
-
44
36
  /**
45
37
  * Subclasses of {@link WidgetRemoteSource} must implement this method, calling
46
38
  * {@link WidgetRemoteSource.prototype._getModelSource} for common source
@@ -67,7 +59,6 @@ export abstract class WidgetRemoteSource<
67
59
  filtersLogicalOperator: props.filtersLogicalOperator,
68
60
  spatialDataType: props.spatialDataType,
69
61
  spatialDataColumn: props.spatialDataColumn,
70
- dataResolution: (props as Partial<AggregationOptions>).dataResolution,
71
62
  };
72
63
  }
73
64
 
@@ -80,24 +71,16 @@ export abstract class WidgetRemoteSource<
80
71
  filterOwner,
81
72
  spatialFilter,
82
73
  spatialFiltersMode,
83
- spatialIndexReferenceViewState,
84
74
  ...params
85
75
  } = options;
86
76
  const {column, operation, operationColumn} = params;
87
- const source = this.getModelSource(filters, filterOwner);
88
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
89
- source,
90
- spatialFilter,
91
- spatialIndexReferenceViewState
92
- );
93
77
 
94
78
  type CategoriesModelResponse = {rows: {name: string; value: number}[]};
95
79
 
96
80
  return executeModel({
97
81
  model: 'category',
98
82
  source: {
99
- ...source,
100
- spatialFiltersResolution,
83
+ ...this.getModelSource(filters, filterOwner),
101
84
  spatialFiltersMode,
102
85
  spatialFilter,
103
86
  },
@@ -106,7 +89,7 @@ export abstract class WidgetRemoteSource<
106
89
  operation,
107
90
  operationColumn: operationColumn || column,
108
91
  },
109
- opts: {signal, headers: this._headers},
92
+ opts: {signal, headers: this.props.headers},
110
93
  }).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
111
94
  }
112
95
 
@@ -119,24 +102,16 @@ export abstract class WidgetRemoteSource<
119
102
  filterOwner,
120
103
  spatialFilter,
121
104
  spatialFiltersMode,
122
- spatialIndexReferenceViewState,
123
105
  ...params
124
106
  } = options;
125
107
  const {columns, dataType, featureIds, z, limit, tileResolution} = params;
126
- const source = this.getModelSource(filters, filterOwner);
127
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
128
- source,
129
- spatialFilter,
130
- spatialIndexReferenceViewState
131
- );
132
108
 
133
109
  type FeaturesModelResponse = {rows: Record<string, unknown>[]};
134
110
 
135
111
  return executeModel({
136
112
  model: 'pick',
137
113
  source: {
138
- ...source,
139
- spatialFiltersResolution,
114
+ ...this.getModelSource(filters, filterOwner),
140
115
  spatialFiltersMode,
141
116
  spatialFilter,
142
117
  },
@@ -148,7 +123,7 @@ export abstract class WidgetRemoteSource<
148
123
  limit: limit || 1000,
149
124
  tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
150
125
  },
151
- opts: {signal, headers: this._headers},
126
+ opts: {signal, headers: this.props.headers},
152
127
  // Avoid `normalizeObjectKeys()`, which changes column names.
153
128
  }).then(({rows}: FeaturesModelResponse) => ({rows}));
154
129
  }
@@ -160,25 +135,17 @@ export abstract class WidgetRemoteSource<
160
135
  filterOwner,
161
136
  spatialFilter,
162
137
  spatialFiltersMode,
163
- spatialIndexReferenceViewState,
164
138
  operationExp,
165
139
  ...params
166
140
  } = options;
167
141
  const {column, operation} = params;
168
- const source = this.getModelSource(filters, filterOwner);
169
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
170
- source,
171
- spatialFilter,
172
- spatialIndexReferenceViewState
173
- );
174
142
 
175
143
  type FormulaModelResponse = {rows: {value: number}[]};
176
144
 
177
145
  return executeModel({
178
146
  model: 'formula',
179
147
  source: {
180
- ...source,
181
- spatialFiltersResolution,
148
+ ...this.getModelSource(filters, filterOwner),
182
149
  spatialFiltersMode,
183
150
  spatialFilter,
184
151
  },
@@ -187,7 +154,7 @@ export abstract class WidgetRemoteSource<
187
154
  operation: operation ?? 'count',
188
155
  operationExp,
189
156
  },
190
- opts: {signal, headers: this._headers},
157
+ opts: {signal, headers: this.props.headers},
191
158
  }).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
192
159
  }
193
160
 
@@ -200,29 +167,21 @@ export abstract class WidgetRemoteSource<
200
167
  filterOwner,
201
168
  spatialFilter,
202
169
  spatialFiltersMode,
203
- spatialIndexReferenceViewState,
204
170
  ...params
205
171
  } = options;
206
172
  const {column, operation, ticks} = params;
207
- const source = this.getModelSource(filters, filterOwner);
208
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
209
- source,
210
- spatialFilter,
211
- spatialIndexReferenceViewState
212
- );
213
173
 
214
174
  type HistogramModelResponse = {rows: {tick: number; value: number}[]};
215
175
 
216
176
  const data = await executeModel({
217
177
  model: 'histogram',
218
178
  source: {
219
- ...source,
220
- spatialFiltersResolution,
179
+ ...this.getModelSource(filters, filterOwner),
221
180
  spatialFiltersMode,
222
181
  spatialFilter,
223
182
  },
224
183
  params: {column, operation, ticks},
225
- opts: {signal, headers: this._headers},
184
+ opts: {signal, headers: this.props.headers},
226
185
  }).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
227
186
 
228
187
  if (data.length) {
@@ -245,29 +204,21 @@ export abstract class WidgetRemoteSource<
245
204
  filterOwner,
246
205
  spatialFilter,
247
206
  spatialFiltersMode,
248
- spatialIndexReferenceViewState,
249
207
  ...params
250
208
  } = options;
251
209
  const {column} = params;
252
- const source = this.getModelSource(filters, filterOwner);
253
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
254
- source,
255
- spatialFilter,
256
- spatialIndexReferenceViewState
257
- );
258
210
 
259
211
  type RangeModelResponse = {rows: {min: number; max: number}[]};
260
212
 
261
213
  return executeModel({
262
214
  model: 'range',
263
215
  source: {
264
- ...source,
265
- spatialFiltersResolution,
216
+ ...this.getModelSource(filters, filterOwner),
266
217
  spatialFiltersMode,
267
218
  spatialFilter,
268
219
  },
269
220
  params: {column},
270
- opts: {signal, headers: this._headers},
221
+ opts: {signal, headers: this.props.headers},
271
222
  }).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
272
223
  }
273
224
 
@@ -278,19 +229,11 @@ export abstract class WidgetRemoteSource<
278
229
  filterOwner,
279
230
  spatialFilter,
280
231
  spatialFiltersMode,
281
- spatialIndexReferenceViewState,
282
232
  ...params
283
233
  } = options;
284
234
  const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
285
235
  params;
286
236
 
287
- const source = this.getModelSource(filters, filterOwner);
288
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
289
- source,
290
- spatialFilter,
291
- spatialIndexReferenceViewState
292
- );
293
-
294
237
  // Make sure this is sync with the same constant in cloud-native/maps-api
295
238
  const HARD_LIMIT = 500;
296
239
 
@@ -299,8 +242,7 @@ export abstract class WidgetRemoteSource<
299
242
  return executeModel({
300
243
  model: 'scatterplot',
301
244
  source: {
302
- ...source,
303
- spatialFiltersResolution,
245
+ ...this.getModelSource(filters, filterOwner),
304
246
  spatialFiltersMode,
305
247
  spatialFilter,
306
248
  },
@@ -311,7 +253,7 @@ export abstract class WidgetRemoteSource<
311
253
  yAxisJoinOperation,
312
254
  limit: HARD_LIMIT,
313
255
  },
314
- opts: {signal, headers: this._headers},
256
+ opts: {signal, headers: this.props.headers},
315
257
  })
316
258
  .then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
317
259
  .then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
@@ -324,16 +266,9 @@ export abstract class WidgetRemoteSource<
324
266
  filterOwner,
325
267
  spatialFilter,
326
268
  spatialFiltersMode,
327
- spatialIndexReferenceViewState,
328
269
  ...params
329
270
  } = options;
330
271
  const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
331
- const source = this.getModelSource(filters, filterOwner);
332
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
333
- source,
334
- spatialFilter,
335
- spatialIndexReferenceViewState
336
- );
337
272
 
338
273
  type TableModelResponse = {
339
274
  rows: Record<string, number | string>[];
@@ -343,8 +278,7 @@ export abstract class WidgetRemoteSource<
343
278
  return executeModel({
344
279
  model: 'table',
345
280
  source: {
346
- ...source,
347
- spatialFiltersResolution,
281
+ ...this.getModelSource(filters, filterOwner),
348
282
  spatialFiltersMode,
349
283
  spatialFilter,
350
284
  },
@@ -355,7 +289,7 @@ export abstract class WidgetRemoteSource<
355
289
  limit,
356
290
  offset,
357
291
  },
358
- opts: {signal, headers: this._headers},
292
+ opts: {signal, headers: this.props.headers},
359
293
  }).then((res: TableModelResponse) => ({
360
294
  // Avoid `normalizeObjectKeys()`, which changes column names.
361
295
  rows: res.rows ?? (res as any).ROWS,
@@ -372,7 +306,6 @@ export abstract class WidgetRemoteSource<
372
306
  filterOwner,
373
307
  spatialFilter,
374
308
  spatialFiltersMode,
375
- spatialIndexReferenceViewState,
376
309
  ...params
377
310
  } = options;
378
311
  const {
@@ -387,13 +320,6 @@ export abstract class WidgetRemoteSource<
387
320
  splitByCategoryValues,
388
321
  } = params;
389
322
 
390
- const source = this.getModelSource(filters, filterOwner);
391
- const spatialFiltersResolution = this._getSpatialFiltersResolution(
392
- source,
393
- spatialFilter,
394
- spatialIndexReferenceViewState
395
- );
396
-
397
323
  type TimeSeriesModelResponse = {
398
324
  rows: {name: string; value: number}[];
399
325
  metadata: {categories: string[]};
@@ -402,8 +328,7 @@ export abstract class WidgetRemoteSource<
402
328
  return executeModel({
403
329
  model: 'timeseries',
404
330
  source: {
405
- ...source,
406
- spatialFiltersResolution,
331
+ ...this.getModelSource(filters, filterOwner),
407
332
  spatialFiltersMode,
408
333
  spatialFilter,
409
334
  },
@@ -418,7 +343,7 @@ export abstract class WidgetRemoteSource<
418
343
  splitByCategoryLimit,
419
344
  splitByCategoryValues,
420
345
  },
421
- opts: {signal, headers: this._headers},
346
+ opts: {signal, headers: this.props.headers},
422
347
  }).then((res: TimeSeriesModelResponse) => ({
423
348
  rows: normalizeObjectKeys(res.rows),
424
349
  categories: res.metadata?.categories,
@@ -15,14 +15,11 @@ import {
15
15
  TableResponse,
16
16
  TimeSeriesRequestOptions,
17
17
  TimeSeriesResponse,
18
- ViewState,
19
18
  } from './types.js';
20
- import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
19
+ import {FilterLogicalOperator, Filter} from '../types.js';
21
20
  import {getClient} from '../client.js';
22
- import {ModelSource} from '../models/model.js';
23
21
  import {SourceOptions} from '../sources/index.js';
24
22
  import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
25
- import {getSpatialFiltersResolution} from '../spatial-index.js';
26
23
 
27
24
  export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
28
25
  apiVersion?: ApiVersion;
@@ -35,7 +32,9 @@ export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
35
32
  *
36
33
  * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
37
34
  */
38
- export abstract class WidgetSource<Props extends WidgetSourceProps> {
35
+ export abstract class WidgetSource<
36
+ Props extends WidgetSourceProps = WidgetSourceProps,
37
+ > {
39
38
  readonly props: Props;
40
39
 
41
40
  static defaultProps: Partial<WidgetSourceProps> = {
@@ -47,7 +46,11 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
47
46
  };
48
47
 
49
48
  constructor(props: Props) {
50
- this.props = {...WidgetSource.defaultProps, ...props};
49
+ this.props = {
50
+ ...WidgetSource.defaultProps,
51
+ clientId: getClient(), // Refresh clientId, default may have changed.
52
+ ...props,
53
+ };
51
54
  }
52
55
 
53
56
  /**
@@ -61,25 +64,6 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
61
64
  // no-op in most cases, but required for worker sources.
62
65
  }
63
66
 
64
- protected _getSpatialFiltersResolution(
65
- source: Omit<ModelSource, 'type' | 'data'>,
66
- spatialFilter?: SpatialFilter,
67
- referenceViewState?: ViewState
68
- ): number | undefined {
69
- // spatialFiltersResolution applies only to spatial index sources.
70
- if (!spatialFilter || source.spatialDataType === 'geo') {
71
- return;
72
- }
73
-
74
- if (!referenceViewState) {
75
- throw new Error(
76
- 'Missing required option, "spatialIndexReferenceViewState".'
77
- );
78
- }
79
-
80
- return getSpatialFiltersResolution(source, referenceViewState);
81
- }
82
-
83
67
  /**
84
68
  * Returns a list of labeled datapoints for categorical data. Suitable for
85
69
  * charts including grouped bar charts, pie charts, and tree charts.
@@ -84,13 +84,10 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
84
84
  }
85
85
 
86
86
  this._features = tileFeatures({
87
- tiles: this._tiles,
88
- tileFormat: this.props.tileFormat,
87
+ ...this.props,
89
88
  ...this._tileFeatureExtractOptions,
90
-
89
+ tiles: this._tiles,
91
90
  spatialFilter,
92
- spatialDataColumn: this.props.spatialDataColumn,
93
- spatialDataType: this.props.spatialDataType,
94
91
  });
95
92
 
96
93
  prevInputs.spatialFilter = spatialFilter;
@@ -128,15 +125,6 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
128
125
  filterOwner,
129
126
  spatialFilter,
130
127
  }: FormulaRequestOptions): Promise<FormulaResponse> {
131
- if (operation === 'custom') {
132
- throw new Error('Custom aggregation not supported for tilesets');
133
- }
134
-
135
- // Column is required except when operation is 'count'.
136
- if ((column && column !== '*') || operation !== 'count') {
137
- assertColumn(this._features, column);
138
- }
139
-
140
128
  const filteredFeatures = this._getFilteredFeatures(
141
129
  spatialFilter,
142
130
  filters,
@@ -147,6 +135,15 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
147
135
  return {value: null};
148
136
  }
149
137
 
138
+ if (operation === 'custom') {
139
+ throw new Error('Custom aggregation not supported for tilesets');
140
+ }
141
+
142
+ // Column is required except when operation is 'count'.
143
+ if ((column && column !== '*') || operation !== 'count') {
144
+ assertColumn(this._features, column);
145
+ }
146
+
150
147
  const targetOperation = aggregationFunctions[operation];
151
148
  return {
152
149
  value: targetOperation(filteredFeatures, column, joinOperation),
@@ -347,8 +344,6 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
347
344
  filterOwner,
348
345
  spatialFilter,
349
346
  }: RangeRequestOptions): Promise<RangeResponse> {
350
- assertColumn(this._features, column);
351
-
352
347
  const filteredFeatures = this._getFilteredFeatures(
353
348
  spatialFilter,
354
349
  filters,
@@ -361,6 +356,8 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
361
356
  return null;
362
357
  }
363
358
 
359
+ assertColumn(this._features, column);
360
+
364
361
  return {
365
362
  min: aggregationFunctions.min(filteredFeatures, column),
366
363
  max: aggregationFunctions.max(filteredFeatures, column),