@carto/api-client 0.5.0-alpha.7 → 0.5.0-alpha.8

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.
@@ -433,7 +433,6 @@ __export(src_exports, {
433
433
  WidgetSource: () => WidgetSource,
434
434
  WidgetTableSource: () => WidgetTableSource,
435
435
  WidgetTilesetSource: () => WidgetTilesetSource,
436
- WidgetTilesetWorkerSource: () => WidgetTilesetWorkerSource,
437
436
  _buildFeatureFilter: () => _buildFeatureFilter,
438
437
  _getHexagonResolution: () => _getHexagonResolution,
439
438
  addFilter: () => addFilter,
@@ -2105,6 +2104,15 @@ var _WidgetSource = class _WidgetSource {
2105
2104
  __publicField(this, "props");
2106
2105
  this.props = { ..._WidgetSource.defaultProps, ...props };
2107
2106
  }
2107
+ /**
2108
+ * Destroys the widget source and releases allocated resources.
2109
+ *
2110
+ * For remote sources (tables, queries) this has no effect, but for local
2111
+ * sources (tilesets, rasters) these resources will affect performance
2112
+ * and stability if many (10+) sources are created and not released.
2113
+ */
2114
+ destroy() {
2115
+ }
2108
2116
  _getSpatialFiltersResolution(source, spatialFilter, referenceViewState) {
2109
2117
  if (!spatialFilter || source.spatialDataType === "geo") {
2110
2118
  return;
@@ -2639,6 +2647,9 @@ var WidgetTableSource = class extends WidgetRemoteSource {
2639
2647
  // src/widget-sources/widget-tileset-source.ts
2640
2648
  init_cjs_shims();
2641
2649
 
2650
+ // src/widget-sources/widget-tileset-source-impl.ts
2651
+ init_cjs_shims();
2652
+
2642
2653
  // src/operations/aggregation.ts
2643
2654
  init_cjs_shims();
2644
2655
  var aggregationFunctions = {
@@ -2987,9 +2998,9 @@ function scatterPlot({
2987
2998
  );
2988
2999
  }
2989
3000
 
2990
- // src/widget-sources/widget-tileset-source.ts
3001
+ // src/widget-sources/widget-tileset-source-impl.ts
2991
3002
  var import_boolean_equal = require("@turf/boolean-equal");
2992
- var WidgetTilesetSource = class extends WidgetSource {
3003
+ var WidgetTilesetSourceImpl = class extends WidgetSource {
2993
3004
  constructor() {
2994
3005
  super(...arguments);
2995
3006
  __publicField(this, "_tiles", []);
@@ -3274,40 +3285,56 @@ function normalizeColumns(columns) {
3274
3285
  return Array.isArray(columns) ? columns : typeof columns === "string" ? [columns] : [];
3275
3286
  }
3276
3287
 
3277
- // src/widget-sources/widget-tileset-worker-source.ts
3278
- init_cjs_shims();
3279
- var WidgetTilesetWorkerSource = class extends WidgetSource {
3288
+ // src/widget-sources/widget-tileset-source.ts
3289
+ var WidgetTilesetSource = class extends WidgetSource {
3280
3290
  constructor(props) {
3281
3291
  super(props);
3282
- /////////////////////////////////////////////////////////////////////////////
3283
- // WEB WORKER MANAGEMENT
3284
- __publicField(this, "_worker", null);
3292
+ __publicField(this, "_localImpl", null);
3293
+ __publicField(this, "_workerImpl", null);
3294
+ __publicField(this, "_workerEnabled");
3285
3295
  __publicField(this, "_workerNextRequestId", 1);
3296
+ this._workerEnabled = (props.widgetSourceWorker ?? true) && false;
3297
+ this._localImpl = this._workerEnabled ? null : new WidgetTilesetSourceImpl(this.props);
3298
+ }
3299
+ destroy() {
3300
+ this._localImpl?.destroy();
3301
+ this._localImpl = null;
3302
+ this._workerImpl?.terminate();
3303
+ this._workerImpl = null;
3304
+ super.destroy();
3286
3305
  }
3306
+ /////////////////////////////////////////////////////////////////////////////
3307
+ // WEB WORKER MANAGEMENT
3287
3308
  /**
3288
3309
  * Returns an initialized Worker, to be reused for the lifecycle of this
3289
3310
  * source instance.
3290
3311
  */
3291
3312
  _getWorker() {
3292
- if (this._worker) {
3293
- return this._worker;
3313
+ if (this._workerImpl || this._localImpl) {
3314
+ return this._workerImpl;
3294
3315
  }
3295
- this._worker = new Worker(
3296
- new URL("@carto/api-client/worker", importMetaUrl),
3297
- {
3316
+ try {
3317
+ this._workerImpl = new Worker(new URL("worker.js", importMetaUrl), {
3298
3318
  type: "module",
3299
3319
  name: "cartowidgettileset"
3300
- }
3301
- );
3302
- this._worker.postMessage({
3303
- method: "init" /* INIT */,
3304
- params: [this.props]
3305
- });
3306
- return this._worker;
3320
+ });
3321
+ this._workerImpl.postMessage({
3322
+ method: "init" /* INIT */,
3323
+ params: [this.props]
3324
+ });
3325
+ return this._workerImpl;
3326
+ } catch {
3327
+ this._workerEnabled = false;
3328
+ this._localImpl = new WidgetTilesetSourceImpl(this.props);
3329
+ return null;
3330
+ }
3307
3331
  }
3308
3332
  /** Executes a given method on the worker. */
3309
3333
  _executeWorkerMethod(method, params, signal) {
3310
3334
  const worker = this._getWorker();
3335
+ if (!worker) {
3336
+ return this._localImpl[method](...params);
3337
+ }
3311
3338
  const requestId = this._workerNextRequestId++;
3312
3339
  const options = params[0];
3313
3340
  if (options?.spatialIndexReferenceViewState) {
@@ -3355,19 +3382,27 @@ var WidgetTilesetWorkerSource = class extends WidgetSource {
3355
3382
  * before computing statistics on the tiles.
3356
3383
  */
3357
3384
  loadTiles(tiles2) {
3385
+ const worker = this._getWorker();
3386
+ if (!worker) {
3387
+ return this._localImpl.loadTiles(tiles2);
3388
+ }
3358
3389
  tiles2 = tiles2.map(({ id, bbox, data }) => ({
3359
3390
  id,
3360
3391
  bbox,
3361
3392
  data
3362
3393
  }));
3363
- this._getWorker().postMessage({
3394
+ worker.postMessage({
3364
3395
  method: "loadTiles" /* LOAD_TILES */,
3365
3396
  params: [tiles2]
3366
3397
  });
3367
3398
  }
3368
3399
  /** Configures options used to extract features from tiles. */
3369
3400
  setTileFeatureExtractOptions(options) {
3370
- this._getWorker().postMessage({
3401
+ const worker = this._getWorker();
3402
+ if (!worker) {
3403
+ return this._localImpl?.setTileFeatureExtractOptions(options);
3404
+ }
3405
+ worker.postMessage({
3371
3406
  type: "setTileFeatureExtractOptions" /* SET_TILE_FEATURE_EXTRACT_OPTIONS */,
3372
3407
  params: [options]
3373
3408
  });
@@ -3381,7 +3416,11 @@ var WidgetTilesetWorkerSource = class extends WidgetSource {
3381
3416
  geojson,
3382
3417
  spatialFilter
3383
3418
  }) {
3384
- this._getWorker().postMessage({
3419
+ const worker = this._getWorker();
3420
+ if (!worker) {
3421
+ return this._localImpl.loadGeoJSON({ geojson, spatialFilter });
3422
+ }
3423
+ worker.postMessage({
3385
3424
  method: "loadGeoJSON" /* LOAD_GEOJSON */,
3386
3425
  params: [{ geojson, spatialFilter }]
3387
3426
  });
@@ -3521,36 +3560,14 @@ function getTileFormat(tilejson) {
3521
3560
  return tileParams.get("formatTiles") === "mvt" ? "mvt" /* MVT */ : "binary" /* BINARY */;
3522
3561
  }
3523
3562
 
3524
- // src/workers/utils.ts
3525
- init_cjs_shims();
3526
- var _isModuleWorkerSupported = true ? false : null;
3527
- function isModuleWorkerSupported() {
3528
- if (_isModuleWorkerSupported !== null) {
3529
- return _isModuleWorkerSupported;
3530
- }
3531
- try {
3532
- new Worker("blob://", {
3533
- get type() {
3534
- _isModuleWorkerSupported = true;
3535
- return "module";
3536
- }
3537
- });
3538
- } catch {
3539
- } finally {
3540
- _isModuleWorkerSupported || (_isModuleWorkerSupported = false);
3541
- }
3542
- return _isModuleWorkerSupported;
3543
- }
3544
-
3545
3563
  // src/sources/h3-tileset-source.ts
3546
3564
  var h3TilesetSource = async function(options) {
3547
3565
  const { tableName, spatialDataColumn = "h3" } = options;
3548
3566
  const urlParameters = { name: tableName };
3549
- const WidgetSourceClass = options.widgetSourceWorker !== false && isModuleWorkerSupported() ? WidgetTilesetWorkerSource : WidgetTilesetSource;
3550
3567
  return baseSource("tileset", options, urlParameters).then(
3551
3568
  (result) => ({
3552
3569
  ...result,
3553
- widgetSource: new WidgetSourceClass({
3570
+ widgetSource: new WidgetTilesetSource({
3554
3571
  ...options,
3555
3572
  tileFormat: getTileFormat(result),
3556
3573
  spatialDataColumn,
@@ -3656,11 +3673,10 @@ init_cjs_shims();
3656
3673
  var quadbinTilesetSource = async function(options) {
3657
3674
  const { tableName, spatialDataColumn = "quadbin" } = options;
3658
3675
  const urlParameters = { name: tableName };
3659
- const WidgetSourceClass = options.widgetSourceWorker !== false && isModuleWorkerSupported() ? WidgetTilesetWorkerSource : WidgetTilesetSource;
3660
3676
  return baseSource("tileset", options, urlParameters).then(
3661
3677
  (result) => ({
3662
3678
  ...result,
3663
- widgetSource: new WidgetSourceClass({
3679
+ widgetSource: new WidgetTilesetSource({
3664
3680
  ...options,
3665
3681
  tileFormat: getTileFormat(result),
3666
3682
  spatialDataColumn,
@@ -3761,11 +3777,10 @@ init_cjs_shims();
3761
3777
  var vectorTilesetSource = async function(options) {
3762
3778
  const { tableName, spatialDataColumn = DEFAULT_GEO_COLUMN } = options;
3763
3779
  const urlParameters = { name: tableName };
3764
- const WidgetSourceClass = options.widgetSourceWorker !== false && isModuleWorkerSupported() ? WidgetTilesetWorkerSource : WidgetTilesetSource;
3765
3780
  return baseSource("tileset", options, urlParameters).then(
3766
3781
  (result) => ({
3767
3782
  ...result,
3768
- widgetSource: new WidgetSourceClass({
3783
+ widgetSource: new WidgetTilesetSource({
3769
3784
  ...options,
3770
3785
  tileFormat: getTileFormat(result),
3771
3786
  spatialDataColumn,
@@ -3831,7 +3846,6 @@ var query = async function(options) {
3831
3846
  WidgetSource,
3832
3847
  WidgetTableSource,
3833
3848
  WidgetTilesetSource,
3834
- WidgetTilesetWorkerSource,
3835
3849
  _buildFeatureFilter,
3836
3850
  _getHexagonResolution,
3837
3851
  addFilter,
@@ -863,6 +863,14 @@ declare abstract class WidgetSource<Props extends WidgetSourceProps> {
863
863
  readonly props: Props;
864
864
  static defaultProps: Partial<WidgetSourceProps>;
865
865
  constructor(props: Props);
866
+ /**
867
+ * Destroys the widget source and releases allocated resources.
868
+ *
869
+ * For remote sources (tables, queries) this has no effect, but for local
870
+ * sources (tilesets, rasters) these resources will affect performance
871
+ * and stability if many (10+) sources are created and not released.
872
+ */
873
+ destroy(): void;
866
874
  protected _getSpatialFiltersResolution(source: Omit<ModelSource, 'type' | 'data'>, spatialFilter?: SpatialFilter, referenceViewState?: ViewState): number | undefined;
867
875
  /**
868
876
  * Returns a list of labeled datapoints for categorical data. Suitable for
@@ -1066,36 +1074,26 @@ type TileFeaturesSpatialIndexOptions = {
1066
1074
  };
1067
1075
  declare function tileFeaturesSpatialIndex({ tiles, spatialFilter, spatialDataColumn, spatialDataType, }: TileFeaturesSpatialIndexOptions): FeatureData[];
1068
1076
 
1069
- type WidgetTilesetSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters'> & {
1070
- tileFormat: TileFormat;
1071
- spatialDataType: SpatialDataType;
1072
- };
1073
- type WidgetTilesetSourceResult = {
1074
- widgetSource: WidgetTilesetSource;
1075
- };
1077
+ declare enum Method {
1078
+ INIT = "init",
1079
+ LOAD_TILES = "loadTiles",
1080
+ SET_TILE_FEATURE_EXTRACT_OPTIONS = "setTileFeatureExtractOptions",
1081
+ LOAD_GEOJSON = "loadGeoJSON",
1082
+ GET_FORMULA = "getFormula",
1083
+ GET_HISTOGRAM = "getHistogram",
1084
+ GET_CATEGORIES = "getCategories",
1085
+ GET_SCATTER = "getScatter",
1086
+ GET_TABLE = "getTable",
1087
+ GET_TIME_SERIES = "getTimeSeries",
1088
+ GET_RANGE = "getRange"
1089
+ }
1090
+
1076
1091
  /**
1077
- * Source for Widget API requests on a data source defined by a tileset.
1078
- *
1079
- * Generally not intended to be constructed directly. Instead, call
1080
- * {@link vectorTilesetSource}, {@link h3TilesetSource}, or {@link quadbinTilesetSource},
1081
- * which can be shared with map layers. Sources contain a `widgetSource`
1082
- * property, for use by widget implementations.
1083
- *
1084
- * Example:
1085
- *
1086
- * ```javascript
1087
- * import { vectorTilesetSource } from '@carto/api-client';
1088
- *
1089
- * const data = vectorTilesetSource({
1090
- * accessToken: '••••',
1091
- * connectionName: 'carto_dw',
1092
- * tableName: 'carto-demo-data.demo_rasters.my_tileset_source'
1093
- * });
1094
- *
1095
- * const { widgetSource } = await data;
1096
- * ```
1092
+ * Local (in-memory) implementation of tileset widget calculations. This class
1093
+ * may be instantiated by {@link WidgetTilesetSource} in a Web Worker when
1094
+ * supported, or on the main thread.
1097
1095
  */
1098
- declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
1096
+ declare class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourceProps> {
1099
1097
  private _tiles;
1100
1098
  private _features;
1101
1099
  private _tileFeatureExtractOptions;
@@ -1132,40 +1130,49 @@ declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
1132
1130
  private _getFilteredFeatures;
1133
1131
  }
1134
1132
 
1135
- declare enum Method {
1136
- INIT = "init",
1137
- LOAD_TILES = "loadTiles",
1138
- SET_TILE_FEATURE_EXTRACT_OPTIONS = "setTileFeatureExtractOptions",
1139
- LOAD_GEOJSON = "loadGeoJSON",
1140
- GET_FORMULA = "getFormula",
1141
- GET_HISTOGRAM = "getHistogram",
1142
- GET_CATEGORIES = "getCategories",
1143
- GET_SCATTER = "getScatter",
1144
- GET_TABLE = "getTable",
1145
- GET_TIME_SERIES = "getTimeSeries",
1146
- GET_RANGE = "getRange"
1147
- }
1148
-
1133
+ type WidgetTilesetSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters'> & {
1134
+ tileFormat: TileFormat;
1135
+ spatialDataType: SpatialDataType;
1136
+ };
1137
+ type WidgetTilesetSourceResult = {
1138
+ widgetSource: WidgetTilesetSource;
1139
+ };
1149
1140
  /**
1150
- * Wrapper for {@link WidgetTilesetSource}, moving calculations to Web Workers.
1151
- * When supported, use of both classes is identical.
1141
+ * Source for Widget API requests on a data source defined by a tileset.
1142
+ *
1143
+ * Generally not intended to be constructed directly. Instead, call
1144
+ * {@link vectorTilesetSource}, {@link h3TilesetSource}, or {@link quadbinTilesetSource},
1145
+ * which can be shared with map layers. Sources contain a `widgetSource`
1146
+ * property, for use by widget implementations.
1147
+ *
1148
+ * Example:
1149
+ *
1150
+ * ```javascript
1151
+ * import { vectorTilesetSource } from '@carto/api-client';
1152
1152
  *
1153
- * To use this wrapper, the application and environment must support ESM Web
1154
- * Workers. For older build systems based on CommonJS, or in environments like
1155
- * Node.js, it may be necessary to use {@link WidgetTilesetSource} directly,
1156
- * and to (optionally) create workers manually in the application.
1153
+ * const data = vectorTilesetSource({
1154
+ * accessToken: '••••',
1155
+ * connectionName: 'carto_dw',
1156
+ * tableName: 'carto-demo-data.demo_rasters.my_tileset_source'
1157
+ * });
1158
+ *
1159
+ * const { widgetSource } = await data;
1160
+ * ```
1157
1161
  */
1158
- declare class WidgetTilesetWorkerSource extends WidgetSource<WidgetTilesetSourceProps> {
1159
- constructor(props: WidgetTilesetSourceProps);
1160
- protected _worker: Worker | null;
1162
+ declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
1163
+ protected _localImpl: WidgetTilesetSourceImpl | null;
1164
+ protected _workerImpl: Worker | null;
1165
+ protected _workerEnabled: boolean;
1161
1166
  protected _workerNextRequestId: number;
1167
+ constructor(props: WidgetTilesetSourceProps);
1168
+ destroy(): void;
1162
1169
  /**
1163
1170
  * Returns an initialized Worker, to be reused for the lifecycle of this
1164
1171
  * source instance.
1165
1172
  */
1166
- _getWorker(): Worker;
1173
+ protected _getWorker(): Worker | null;
1167
1174
  /** Executes a given method on the worker. */
1168
- _executeWorkerMethod<T>(method: Method, params: unknown[], signal?: AbortSignal): Promise<T>;
1175
+ protected _executeWorkerMethod<T>(method: Method, params: unknown[], signal?: AbortSignal): Promise<T>;
1169
1176
  /**
1170
1177
  * Loads features as a list of tiles (typically provided by deck.gl).
1171
1178
  * After tiles are loaded, {@link extractTileFeatures} must be called
@@ -1381,4 +1388,4 @@ declare function makeIntervalComplete(intervals: FilterInterval[]): FilterInterv
1381
1388
  */
1382
1389
  declare function transformToTileCoords<T extends Geometry>(geometry: T, bbox: BBox): T;
1383
1390
 
1384
- export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, ApiVersion, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryRequestOptions, type CategoryResponse, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GeojsonResult, type GetFilterOptions, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type JsonResult, type MapType, type NamedQueryParameter, type PositionalQueryParameter, Provider, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RemoveFilterOptions, SOURCE_DEFAULTS, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SortColumnType, type SortDirection, type SourceOptions, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, type SpatialIndexTile, type StringSearchOptions, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type TilejsonResult, type TilesetSourceOptions, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, WidgetTilesetWorkerSource, type _DataFilterExtensionProps, _buildFeatureFilter, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getDataFilterExtensionProps, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
1391
+ export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, ApiVersion, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryRequestOptions, type CategoryResponse, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GeojsonResult, type GetFilterOptions, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type JsonResult, type MapType, type NamedQueryParameter, type PositionalQueryParameter, Provider, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RemoveFilterOptions, SOURCE_DEFAULTS, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SortColumnType, type SortDirection, type SourceOptions, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, type SpatialIndexTile, type StringSearchOptions, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type TilejsonResult, type TilesetSourceOptions, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, type _DataFilterExtensionProps, _buildFeatureFilter, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getDataFilterExtensionProps, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
@@ -863,6 +863,14 @@ declare abstract class WidgetSource<Props extends WidgetSourceProps> {
863
863
  readonly props: Props;
864
864
  static defaultProps: Partial<WidgetSourceProps>;
865
865
  constructor(props: Props);
866
+ /**
867
+ * Destroys the widget source and releases allocated resources.
868
+ *
869
+ * For remote sources (tables, queries) this has no effect, but for local
870
+ * sources (tilesets, rasters) these resources will affect performance
871
+ * and stability if many (10+) sources are created and not released.
872
+ */
873
+ destroy(): void;
866
874
  protected _getSpatialFiltersResolution(source: Omit<ModelSource, 'type' | 'data'>, spatialFilter?: SpatialFilter, referenceViewState?: ViewState): number | undefined;
867
875
  /**
868
876
  * Returns a list of labeled datapoints for categorical data. Suitable for
@@ -1066,36 +1074,26 @@ type TileFeaturesSpatialIndexOptions = {
1066
1074
  };
1067
1075
  declare function tileFeaturesSpatialIndex({ tiles, spatialFilter, spatialDataColumn, spatialDataType, }: TileFeaturesSpatialIndexOptions): FeatureData[];
1068
1076
 
1069
- type WidgetTilesetSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters'> & {
1070
- tileFormat: TileFormat;
1071
- spatialDataType: SpatialDataType;
1072
- };
1073
- type WidgetTilesetSourceResult = {
1074
- widgetSource: WidgetTilesetSource;
1075
- };
1077
+ declare enum Method {
1078
+ INIT = "init",
1079
+ LOAD_TILES = "loadTiles",
1080
+ SET_TILE_FEATURE_EXTRACT_OPTIONS = "setTileFeatureExtractOptions",
1081
+ LOAD_GEOJSON = "loadGeoJSON",
1082
+ GET_FORMULA = "getFormula",
1083
+ GET_HISTOGRAM = "getHistogram",
1084
+ GET_CATEGORIES = "getCategories",
1085
+ GET_SCATTER = "getScatter",
1086
+ GET_TABLE = "getTable",
1087
+ GET_TIME_SERIES = "getTimeSeries",
1088
+ GET_RANGE = "getRange"
1089
+ }
1090
+
1076
1091
  /**
1077
- * Source for Widget API requests on a data source defined by a tileset.
1078
- *
1079
- * Generally not intended to be constructed directly. Instead, call
1080
- * {@link vectorTilesetSource}, {@link h3TilesetSource}, or {@link quadbinTilesetSource},
1081
- * which can be shared with map layers. Sources contain a `widgetSource`
1082
- * property, for use by widget implementations.
1083
- *
1084
- * Example:
1085
- *
1086
- * ```javascript
1087
- * import { vectorTilesetSource } from '@carto/api-client';
1088
- *
1089
- * const data = vectorTilesetSource({
1090
- * accessToken: '••••',
1091
- * connectionName: 'carto_dw',
1092
- * tableName: 'carto-demo-data.demo_rasters.my_tileset_source'
1093
- * });
1094
- *
1095
- * const { widgetSource } = await data;
1096
- * ```
1092
+ * Local (in-memory) implementation of tileset widget calculations. This class
1093
+ * may be instantiated by {@link WidgetTilesetSource} in a Web Worker when
1094
+ * supported, or on the main thread.
1097
1095
  */
1098
- declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
1096
+ declare class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourceProps> {
1099
1097
  private _tiles;
1100
1098
  private _features;
1101
1099
  private _tileFeatureExtractOptions;
@@ -1132,40 +1130,49 @@ declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
1132
1130
  private _getFilteredFeatures;
1133
1131
  }
1134
1132
 
1135
- declare enum Method {
1136
- INIT = "init",
1137
- LOAD_TILES = "loadTiles",
1138
- SET_TILE_FEATURE_EXTRACT_OPTIONS = "setTileFeatureExtractOptions",
1139
- LOAD_GEOJSON = "loadGeoJSON",
1140
- GET_FORMULA = "getFormula",
1141
- GET_HISTOGRAM = "getHistogram",
1142
- GET_CATEGORIES = "getCategories",
1143
- GET_SCATTER = "getScatter",
1144
- GET_TABLE = "getTable",
1145
- GET_TIME_SERIES = "getTimeSeries",
1146
- GET_RANGE = "getRange"
1147
- }
1148
-
1133
+ type WidgetTilesetSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters'> & {
1134
+ tileFormat: TileFormat;
1135
+ spatialDataType: SpatialDataType;
1136
+ };
1137
+ type WidgetTilesetSourceResult = {
1138
+ widgetSource: WidgetTilesetSource;
1139
+ };
1149
1140
  /**
1150
- * Wrapper for {@link WidgetTilesetSource}, moving calculations to Web Workers.
1151
- * When supported, use of both classes is identical.
1141
+ * Source for Widget API requests on a data source defined by a tileset.
1142
+ *
1143
+ * Generally not intended to be constructed directly. Instead, call
1144
+ * {@link vectorTilesetSource}, {@link h3TilesetSource}, or {@link quadbinTilesetSource},
1145
+ * which can be shared with map layers. Sources contain a `widgetSource`
1146
+ * property, for use by widget implementations.
1147
+ *
1148
+ * Example:
1149
+ *
1150
+ * ```javascript
1151
+ * import { vectorTilesetSource } from '@carto/api-client';
1152
1152
  *
1153
- * To use this wrapper, the application and environment must support ESM Web
1154
- * Workers. For older build systems based on CommonJS, or in environments like
1155
- * Node.js, it may be necessary to use {@link WidgetTilesetSource} directly,
1156
- * and to (optionally) create workers manually in the application.
1153
+ * const data = vectorTilesetSource({
1154
+ * accessToken: '••••',
1155
+ * connectionName: 'carto_dw',
1156
+ * tableName: 'carto-demo-data.demo_rasters.my_tileset_source'
1157
+ * });
1158
+ *
1159
+ * const { widgetSource } = await data;
1160
+ * ```
1157
1161
  */
1158
- declare class WidgetTilesetWorkerSource extends WidgetSource<WidgetTilesetSourceProps> {
1159
- constructor(props: WidgetTilesetSourceProps);
1160
- protected _worker: Worker | null;
1162
+ declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
1163
+ protected _localImpl: WidgetTilesetSourceImpl | null;
1164
+ protected _workerImpl: Worker | null;
1165
+ protected _workerEnabled: boolean;
1161
1166
  protected _workerNextRequestId: number;
1167
+ constructor(props: WidgetTilesetSourceProps);
1168
+ destroy(): void;
1162
1169
  /**
1163
1170
  * Returns an initialized Worker, to be reused for the lifecycle of this
1164
1171
  * source instance.
1165
1172
  */
1166
- _getWorker(): Worker;
1173
+ protected _getWorker(): Worker | null;
1167
1174
  /** Executes a given method on the worker. */
1168
- _executeWorkerMethod<T>(method: Method, params: unknown[], signal?: AbortSignal): Promise<T>;
1175
+ protected _executeWorkerMethod<T>(method: Method, params: unknown[], signal?: AbortSignal): Promise<T>;
1169
1176
  /**
1170
1177
  * Loads features as a list of tiles (typically provided by deck.gl).
1171
1178
  * After tiles are loaded, {@link extractTileFeatures} must be called
@@ -1381,4 +1388,4 @@ declare function makeIntervalComplete(intervals: FilterInterval[]): FilterInterv
1381
1388
  */
1382
1389
  declare function transformToTileCoords<T extends Geometry>(geometry: T, bbox: BBox): T;
1383
1390
 
1384
- export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, ApiVersion, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryRequestOptions, type CategoryResponse, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GeojsonResult, type GetFilterOptions, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type JsonResult, type MapType, type NamedQueryParameter, type PositionalQueryParameter, Provider, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RemoveFilterOptions, SOURCE_DEFAULTS, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SortColumnType, type SortDirection, type SourceOptions, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, type SpatialIndexTile, type StringSearchOptions, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type TilejsonResult, type TilesetSourceOptions, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, WidgetTilesetWorkerSource, type _DataFilterExtensionProps, _buildFeatureFilter, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getDataFilterExtensionProps, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };
1391
+ export { type APIErrorContext, type APIRequestType, type AddFilterOptions, type AggregationFunction, type AggregationType, ApiVersion, type BoundaryQuerySourceOptions, type BoundaryQuerySourceResponse, type BoundaryTableSourceOptions, type BoundaryTableSourceResponse, CartoAPIError, type CategoryRequestOptions, type CategoryResponse, DEFAULT_API_BASE_URL, FEATURE_GEOM_PROPERTY, type FeaturesRequestOptions, type FeaturesResponse, type Filter, type FilterFunction, type FilterInterval, type FilterIntervalComplete, type FilterIntervalExtremum, type FilterLogicalOperator, FilterType, type Filters, type Format, type FormulaRequestOptions, type FormulaResponse, type GeojsonResult, type GetFilterOptions, type GroupByFeature, type GroupDateType, type H3QuerySourceOptions, type H3QuerySourceResponse, type H3TableSourceOptions, type H3TableSourceResponse, type H3TilesetSourceOptions, type H3TilesetSourceResponse, type HasFilterOptions, type HistogramRequestOptions, type HistogramResponse, type JsonResult, type MapType, type NamedQueryParameter, type PositionalQueryParameter, Provider, type QuadbinQuerySourceOptions, type QuadbinQuerySourceResponse, type QuadbinTableSourceOptions, type QuadbinTableSourceResponse, type QuadbinTilesetSourceOptions, type QuadbinTilesetSourceResponse, type QueryOptions, type QueryParameterValue, type QueryParameters, type QueryResult, type QuerySourceOptions, type RangeRequestOptions, type RangeResponse, type Raster, RasterBandColorinterp, type RasterMetadata, type RasterMetadataBand, type RasterMetadataBandStats, type RasterSourceOptions, type RemoveFilterOptions, SOURCE_DEFAULTS, type ScatterPlotFeature, type ScatterRequestOptions, type ScatterResponse, type SortColumnType, type SortDirection, type SourceOptions, type SpatialFilter, type SpatialFilterPolyfillMode, SpatialIndex, type SpatialIndexTile, type StringSearchOptions, type TableRequestOptions, type TableResponse, type TableSourceOptions, type Tile, type TileFeatureExtractOptions, type TileFeatures, type TileFeaturesSpatialIndexOptions, TileFormat, type TileResolution, type TilejsonResult, type TilesetSourceOptions, type TimeSeriesRequestOptions, type TimeSeriesResponse, type VectorLayer, type VectorQuerySourceOptions, type VectorQuerySourceResponse, type VectorTableSourceOptions, type VectorTableSourceResponse, type VectorTilesetSourceOptions, type VectorTilesetSourceResponse, type ViewState, type Viewport, WidgetQuerySource, type WidgetQuerySourceResult, WidgetRemoteSource, type WidgetRemoteSourceProps, WidgetSource, type WidgetSourceProps, WidgetTableSource, type WidgetTableSourceResult, WidgetTilesetSource, type WidgetTilesetSourceProps, type WidgetTilesetSourceResult, type _DataFilterExtensionProps, _buildFeatureFilter, _getHexagonResolution, addFilter, aggregate, aggregationFunctions, applyFilters, applySorting, boundaryQuerySource, boundaryTableSource, buildBinaryFeatureFilter, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, filterFunctions, geojsonFeatures, getClient, getDataFilterExtensionProps, getFilter, groupValuesByColumn, groupValuesByDateColumn, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, histogram, makeIntervalComplete, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, scatterPlot, setClient, tileFeatures, tileFeaturesGeometries, tileFeaturesSpatialIndex, transformToTileCoords, vectorQuerySource, vectorTableSource, vectorTilesetSource };