@carto/api-client 0.5.0-alpha.9 → 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 +15240 -3357
  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 +14684 -2910
  7. package/build/api-client.js.map +1 -0
  8. package/build/worker.js +5116 -618
  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 +24 -21
  43. package/src/workers/widget-tileset-worker.ts +1 -1
@@ -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
  }