@carto/api-client 0.5.0-alpha.9 → 0.5.1-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 (43) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/build/api-client.cjs +15241 -3358
  3. package/build/api-client.cjs.map +1 -0
  4. package/build/api-client.d.cts +528 -181
  5. package/build/api-client.d.ts +528 -181
  6. package/build/api-client.js +14685 -2911
  7. package/build/api-client.js.map +1 -0
  8. package/build/worker.js +5117 -619
  9. package/build/worker.js.map +1 -0
  10. package/package.json +49 -32
  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 +1 -3
  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 +16 -19
  42. package/src/widget-sources/widget-tileset-source.ts +24 -21
  43. package/src/workers/widget-tileset-worker.ts +1 -1
@@ -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),
@@ -390,15 +387,15 @@ function assertColumn(
390
387
  features: FeatureData[],
391
388
  ...columnArgs: string[] | string[][]
392
389
  ) {
393
- // TODO(cleanup): Can drop support for multiple column shapes here?
394
-
395
390
  // Due to the multiple column shape, we normalise it as an array with normalizeColumns
396
391
  const columns = Array.from(new Set(columnArgs.map(normalizeColumns).flat()));
397
392
 
398
393
  const featureKeys = Object.keys(features[0]);
399
394
 
395
+ // For backward compatibility, '' should pass column validation. For example,
396
+ // operation='count',operationColumn='' is accepted.
400
397
  const invalidColumns = columns.filter(
401
- (column) => !featureKeys.includes(column)
398
+ (column) => column && !featureKeys.includes(column)
402
399
  );
403
400
 
404
401
  if (invalidColumns.length) {
@@ -55,18 +55,20 @@ export type WidgetTilesetSourceResult = {widgetSource: WidgetTilesetSource};
55
55
  * const { widgetSource } = await data;
56
56
  * ```
57
57
  */
58
- export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
58
+ export class WidgetTilesetSource<
59
+ Props extends WidgetTilesetSourceProps = WidgetTilesetSourceProps,
60
+ > extends WidgetSource<Props> {
59
61
  protected _localImpl: WidgetTilesetSourceImpl | null = null;
60
62
 
61
63
  protected _workerImpl: Worker | null = null;
62
64
  protected _workerEnabled: boolean;
63
65
  protected _workerNextRequestId = 1;
64
66
 
65
- constructor(props: WidgetTilesetSourceProps) {
67
+ constructor(props: Props) {
66
68
  super(props);
67
69
 
68
70
  this._workerEnabled =
69
- (props.widgetSourceWorker ?? true) &&
71
+ (props.widgetWorker ?? true) &&
70
72
  TSUP_FORMAT !== 'cjs' &&
71
73
  typeof Worker !== 'undefined';
72
74
 
@@ -127,15 +129,6 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
127
129
  const worker = this._getWorker();
128
130
  const requestId = this._workerNextRequestId++;
129
131
 
130
- // TODO: ViewState may contain non-serializable data, which we do not need.
131
- // Remove this sanitization after sc-469614 is fixed.
132
- const options = params[0] as any;
133
- if (options?.spatialIndexReferenceViewState) {
134
- const {zoom, latitude, longitude} =
135
- options.spatialIndexReferenceViewState;
136
- options.spatialIndexReferenceViewState = {zoom, latitude, longitude};
137
- }
138
-
139
132
  let resolve: ((value: T) => void) | null = null;
140
133
  let reject: ((reason: any) => void) | null = null;
141
134
 
@@ -145,10 +138,9 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
145
138
  function onMessage(e: MessageEvent) {
146
139
  const response = e.data as WorkerResponse;
147
140
  if (response.requestId !== requestId) return;
141
+ if (signal?.aborted) return; // handled by 'abort' listener
148
142
 
149
- if (signal?.aborted) {
150
- reject!(new Error(signal.reason));
151
- } else if (response.ok) {
143
+ if (response.ok) {
152
144
  resolve!(response.result as T);
153
145
  } else {
154
146
  reject!(new Error(response.error));
@@ -199,11 +191,22 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
199
191
 
200
192
  const worker = this._getWorker();
201
193
 
202
- tiles = (tiles as Tile[]).map(({id, bbox, data}) => ({
203
- id,
204
- bbox,
205
- data,
206
- }));
194
+ // We cannot pass an instance of Tile2DHeader to a Web Worker, and must
195
+ // extract properties required for widget calculations. Note that the
196
+ // `tile: Tile = {...}` assignment is structured so TS will warn if any
197
+ // types required by the internal 'Tile' type are missing.
198
+ tiles = (tiles as Tile[]).map(
199
+ ({id, index, bbox, isVisible, data}: Tile) => {
200
+ const tile: Tile = {
201
+ id,
202
+ index,
203
+ isVisible,
204
+ data,
205
+ bbox,
206
+ };
207
+ return tile;
208
+ }
209
+ );
207
210
 
208
211
  worker.postMessage({
209
212
  method: Method.LOAD_TILES,
@@ -220,7 +223,7 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
220
223
  const worker = this._getWorker();
221
224
 
222
225
  worker.postMessage({
223
- type: Method.SET_TILE_FEATURE_EXTRACT_OPTIONS,
226
+ method: Method.SET_TILE_FEATURE_EXTRACT_OPTIONS,
224
227
  params: [options],
225
228
  });
226
229
  }
@@ -18,7 +18,7 @@ addEventListener('message', (e) => {
18
18
  if (method === Method.INIT) {
19
19
  source = new WidgetTilesetSourceImpl({
20
20
  ...(params[0] as WidgetTilesetSourceProps),
21
- widgetSourceWorker: false,
21
+ widgetWorker: false,
22
22
  });
23
23
  return;
24
24
  }