@carto/api-client 0.5.0-alpha.1 → 0.5.0-alpha.13

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 (127) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/api-client.cjs +3162 -3206
  3. package/build/api-client.cjs.map +1 -1
  4. package/build/api-client.d.cts +1399 -0
  5. package/build/api-client.d.ts +1399 -0
  6. package/build/api-client.js +3673 -0
  7. package/build/api-client.js.map +1 -0
  8. package/build/worker.d.ts +2 -0
  9. package/build/worker.js +1949 -0
  10. package/build/worker.js.map +1 -0
  11. package/package.json +61 -46
  12. package/src/api/carto-api-error.ts +1 -1
  13. package/src/api/query.ts +5 -5
  14. package/src/api/request-with-parameters.ts +6 -6
  15. package/src/client.ts +3 -3
  16. package/src/constants-internal.ts +5 -11
  17. package/src/constants.ts +6 -6
  18. package/src/deck/get-data-filter-extension-props.ts +164 -0
  19. package/src/deck/index.ts +1 -0
  20. package/src/filters/Filter.ts +18 -8
  21. package/src/filters/FilterTypes.ts +2 -2
  22. package/src/filters/geosjonFeatures.ts +2 -2
  23. package/src/filters/tileFeatures.ts +12 -17
  24. package/src/filters.ts +4 -4
  25. package/src/geo.ts +12 -14
  26. package/src/global.d.ts +3 -8
  27. package/src/index.ts +3 -0
  28. package/src/models/common.ts +11 -9
  29. package/src/models/model.ts +3 -4
  30. package/src/operations/aggregation.ts +5 -5
  31. package/src/operations/applySorting.ts +4 -4
  32. package/src/operations/groupBy.ts +4 -4
  33. package/src/operations/groupByDate.ts +1 -1
  34. package/src/operations/histogram.ts +4 -4
  35. package/src/operations/scatterPlot.ts +4 -4
  36. package/src/sources/base-source.ts +8 -8
  37. package/src/sources/boundary-query-source.ts +2 -2
  38. package/src/sources/boundary-table-source.ts +2 -2
  39. package/src/sources/h3-query-source.ts +7 -5
  40. package/src/sources/h3-table-source.ts +7 -5
  41. package/src/sources/h3-tileset-source.ts +4 -4
  42. package/src/sources/index.ts +26 -26
  43. package/src/sources/quadbin-query-source.ts +7 -5
  44. package/src/sources/quadbin-table-source.ts +7 -5
  45. package/src/sources/quadbin-tileset-source.ts +4 -4
  46. package/src/sources/raster-source.ts +2 -2
  47. package/src/sources/types.ts +9 -3
  48. package/src/sources/vector-query-source.ts +2 -3
  49. package/src/sources/vector-table-source.ts +2 -3
  50. package/src/sources/vector-tileset-source.ts +5 -5
  51. package/src/spatial-index.ts +12 -10
  52. package/src/types-internal.ts +5 -5
  53. package/src/types.ts +15 -15
  54. package/src/utils/makeIntervalComplete.ts +1 -1
  55. package/src/utils.ts +3 -3
  56. package/src/widget-sources/index.ts +1 -0
  57. package/src/widget-sources/types.ts +6 -4
  58. package/src/widget-sources/widget-query-source.ts +6 -2
  59. package/src/widget-sources/widget-remote-source.ts +67 -26
  60. package/src/widget-sources/widget-source.ts +10 -25
  61. package/src/widget-sources/widget-table-source.ts +6 -2
  62. package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
  63. package/src/widget-sources/widget-tileset-source.ts +199 -299
  64. package/src/workers/constants.ts +13 -0
  65. package/src/workers/types.ts +19 -0
  66. package/src/workers/widget-tileset-worker.ts +40 -0
  67. package/build/api/carto-api-error.d.ts +0 -26
  68. package/build/api/endpoints.d.ts +0 -24
  69. package/build/api/index.d.ts +0 -5
  70. package/build/api/query.d.ts +0 -3
  71. package/build/api/request-with-parameters.d.ts +0 -10
  72. package/build/api-client.modern.js +0 -3574
  73. package/build/api-client.modern.js.map +0 -1
  74. package/build/client.d.ts +0 -14
  75. package/build/constants-internal.d.ts +0 -26
  76. package/build/constants.d.ts +0 -53
  77. package/build/filters/Filter.d.ts +0 -13
  78. package/build/filters/FilterTypes.d.ts +0 -3
  79. package/build/filters/geosjonFeatures.d.ts +0 -8
  80. package/build/filters/index.d.ts +0 -6
  81. package/build/filters/tileFeatures.d.ts +0 -20
  82. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  83. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  84. package/build/filters.d.ts +0 -39
  85. package/build/geo.d.ts +0 -19
  86. package/build/index.d.ts +0 -14
  87. package/build/models/common.d.ts +0 -27
  88. package/build/models/index.d.ts +0 -3
  89. package/build/models/model.d.ts +0 -37
  90. package/build/operations/aggregation.d.ts +0 -8
  91. package/build/operations/applySorting.d.ts +0 -20
  92. package/build/operations/groupBy.d.ts +0 -15
  93. package/build/operations/groupByDate.d.ts +0 -11
  94. package/build/operations/histogram.d.ts +0 -13
  95. package/build/operations/index.d.ts +0 -6
  96. package/build/operations/scatterPlot.d.ts +0 -14
  97. package/build/sources/base-source.d.ts +0 -4
  98. package/build/sources/boundary-query-source.d.ts +0 -10
  99. package/build/sources/boundary-table-source.d.ts +0 -8
  100. package/build/sources/h3-query-source.d.ts +0 -5
  101. package/build/sources/h3-table-source.d.ts +0 -5
  102. package/build/sources/h3-tileset-source.d.ts +0 -5
  103. package/build/sources/index.d.ts +0 -26
  104. package/build/sources/quadbin-query-source.d.ts +0 -5
  105. package/build/sources/quadbin-table-source.d.ts +0 -5
  106. package/build/sources/quadbin-tileset-source.d.ts +0 -5
  107. package/build/sources/raster-source.d.ts +0 -4
  108. package/build/sources/types.d.ts +0 -366
  109. package/build/sources/vector-query-source.d.ts +0 -5
  110. package/build/sources/vector-table-source.d.ts +0 -5
  111. package/build/sources/vector-tileset-source.d.ts +0 -5
  112. package/build/spatial-index.d.ts +0 -8
  113. package/build/types-internal.d.ts +0 -56
  114. package/build/types.d.ts +0 -140
  115. package/build/utils/dateUtils.d.ts +0 -10
  116. package/build/utils/getTileFormat.d.ts +0 -3
  117. package/build/utils/makeIntervalComplete.d.ts +0 -2
  118. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  119. package/build/utils/transformToTileCoords.d.ts +0 -9
  120. package/build/utils.d.ts +0 -32
  121. package/build/widget-sources/index.d.ts +0 -5
  122. package/build/widget-sources/types.d.ts +0 -158
  123. package/build/widget-sources/widget-query-source.d.ts +0 -33
  124. package/build/widget-sources/widget-remote-source.d.ts +0 -18
  125. package/build/widget-sources/widget-source.d.ts +0 -74
  126. package/build/widget-sources/widget-table-source.d.ts +0 -33
  127. package/build/widget-sources/widget-tileset-source.d.ts +0 -76
package/src/types.ts CHANGED
@@ -6,10 +6,10 @@ import type {BinaryFeature, BinaryFeatureCollection} from '@loaders.gl/schema';
6
6
  * MAPS AND TILES
7
7
  */
8
8
 
9
- /** @internalRemarks Source: @deck.gl/carto */
9
+ /** @privateRemarks Source: @deck.gl/carto */
10
10
  export type Format = 'json' | 'geojson' | 'tilejson';
11
11
 
12
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
12
+ /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
13
13
  export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
14
14
 
15
15
  /**
@@ -23,7 +23,7 @@ export type Viewport = [number, number, number, number];
23
23
  * required for local widget calculations. Deeper dependencies on deck.gl
24
24
  * APIs should be minimized within this library: @deck.gl/carto depends
25
25
  * on the API client, not the other way around.
26
- * @internalRemarks Source: @deck.gl/geo-layers
26
+ * @privateRemarks Source: @deck.gl/geo-layers
27
27
  */
28
28
  export type Tile = {
29
29
  index: {x: number; y: number; z: number};
@@ -40,7 +40,7 @@ export type SpatialIndexTile = Tile & {
40
40
  data?: (Feature & {id: bigint})[];
41
41
  };
42
42
 
43
- /** @internalRemarks Source: @deck.gl/carto */
43
+ /** @privateRemarks Source: @deck.gl/carto */
44
44
  export type Raster = {
45
45
  blockSize: number;
46
46
  cells: {
@@ -56,8 +56,8 @@ export type Raster = {
56
56
  /**
57
57
  * Enum for the different types of aggregations available for widgets.
58
58
  *
59
- * @internalRemarks Source: @carto/constants
60
- * @internalRemarks Converted from enum to type union, for improved declarative API.
59
+ * @privateRemarks Source: @carto/constants
60
+ * @privateRemarks Converted from enum to type union, for improved declarative API.
61
61
  */
62
62
  export type AggregationType =
63
63
  | 'count'
@@ -71,15 +71,15 @@ export type AggregationType =
71
71
  * FILTERS
72
72
  */
73
73
 
74
- /** @internalRemarks Source: @carto/react-api */
74
+ /** @privateRemarks Source: @carto/react-api */
75
75
  export type SpatialFilter = Polygon | MultiPolygon;
76
76
 
77
- /** @internalRemarks Source: @deck.gl/carto */
77
+ /** @privateRemarks Source: @deck.gl/carto */
78
78
  export interface Filters {
79
79
  [column: string]: Filter;
80
80
  }
81
81
 
82
- /** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
82
+ /** @privateRemarks Source: @carto/react-api, @deck.gl/carto */
83
83
  export interface Filter {
84
84
  [FilterType.IN]?: {owner?: string; values: number[] | string[]};
85
85
  /** [a, b] both are included. */
@@ -94,7 +94,7 @@ export interface Filter {
94
94
  };
95
95
  }
96
96
 
97
- /** @internalRemarks Source: @carto/react-core */
97
+ /** @privateRemarks Source: @carto/react-core */
98
98
  export type FilterLogicalOperator = 'and' | 'or';
99
99
 
100
100
  /**
@@ -120,7 +120,7 @@ export type StringSearchOptions = {
120
120
  /**
121
121
  * Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
122
122
  *
123
- * @internalRemarks Source: @carto/react-core
123
+ * @privateRemarks Source: @carto/react-core
124
124
  */
125
125
  export type GroupDateType =
126
126
  | 'year'
@@ -142,7 +142,7 @@ export type SortColumnType = 'number' | 'string' | 'date';
142
142
  * SQL QUERY PARAMETERS
143
143
  */
144
144
 
145
- /** @internalRemarks Source: @deck.gl/carto */
145
+ /** @privateRemarks Source: @deck.gl/carto */
146
146
  export type QueryParameterValue =
147
147
  | string
148
148
  | number
@@ -150,11 +150,11 @@ export type QueryParameterValue =
150
150
  | Array<QueryParameterValue>
151
151
  | object;
152
152
 
153
- /** @internalRemarks Source: @deck.gl/carto */
153
+ /** @privateRemarks Source: @deck.gl/carto */
154
154
  export type NamedQueryParameter = Record<string, QueryParameterValue>;
155
155
 
156
- /** @internalRemarks Source: @deck.gl/carto */
156
+ /** @privateRemarks Source: @deck.gl/carto */
157
157
  export type PositionalQueryParameter = QueryParameterValue[];
158
158
 
159
- /** @internalRemarks Source: @deck.gl/carto */
159
+ /** @privateRemarks Source: @deck.gl/carto */
160
160
  export type QueryParameters = NamedQueryParameter | PositionalQueryParameter;
@@ -1,4 +1,4 @@
1
- import {FilterInterval, FilterIntervalComplete} from '../types';
1
+ import {FilterInterval, FilterIntervalComplete} from '../types.js';
2
2
 
3
3
  export function makeIntervalComplete(
4
4
  intervals: FilterInterval[]
package/src/utils.ts CHANGED
@@ -39,7 +39,7 @@ type Row<T> = Record<string, T> | Record<string, T>[] | T[] | T;
39
39
  * Due to each data warehouse having its own behavior with columns,
40
40
  * we need to normalize them and transform every key to lowercase.
41
41
  *
42
- * @internalRemarks Source: @carto/react-widgets
42
+ * @privateRemarks Source: @carto/react-widgets
43
43
  * @internal
44
44
  */
45
45
  export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
@@ -59,7 +59,7 @@ export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
59
59
  ) as R;
60
60
  }
61
61
 
62
- /** @internalRemarks Source: @carto/react-core */
62
+ /** @privateRemarks Source: @carto/react-core */
63
63
  export function assert(condition: unknown, message: string): asserts condition {
64
64
  if (!condition) {
65
65
  throw new Error(message);
@@ -67,7 +67,7 @@ export function assert(condition: unknown, message: string): asserts condition {
67
67
  }
68
68
 
69
69
  /**
70
- * @internalRemarks Source: @carto/react-core
70
+ * @privateRemarks Source: @carto/react-core
71
71
  * @internal
72
72
  */
73
73
  export class InvalidColumnError extends Error {
@@ -1,3 +1,4 @@
1
+ export * from './widget-source.js';
1
2
  export * from './widget-query-source.js';
2
3
  export * from './widget-remote-source.js';
3
4
  export * from './widget-table-source.js';
@@ -1,11 +1,11 @@
1
- import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types';
1
+ import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types.js';
2
2
  import {
3
+ Filters,
3
4
  GroupDateType,
4
5
  SortColumnType,
5
6
  SortDirection,
6
7
  SpatialFilter,
7
- } from '../types';
8
- import type {WidgetRemoteSource} from './widget-remote-source';
8
+ } from '../types.js';
9
9
 
10
10
  /******************************************************************************
11
11
  * WIDGET API REQUESTS
@@ -19,11 +19,13 @@ export interface ViewState {
19
19
 
20
20
  /** Common options for {@link WidgetRemoteSource} requests. */
21
21
  interface BaseRequestOptions {
22
+ signal?: AbortSignal;
22
23
  spatialFilter?: SpatialFilter;
23
24
  spatialFiltersMode?: SpatialFilterPolyfillMode;
24
25
  /** Required for table- and query-based spatial index sources (H3, Quadbin). */
25
26
  spatialIndexReferenceViewState?: ViewState;
26
- abortController?: AbortController;
27
+ /** Overrides source filters, if any. */
28
+ filters?: Filters;
27
29
  filterOwner?: string;
28
30
  }
29
31
 
@@ -8,6 +8,7 @@ import {
8
8
  WidgetRemoteSourceProps,
9
9
  } from './widget-remote-source.js';
10
10
  import {ModelSource} from '../models/model.js';
11
+ import {Filters} from '../types.js';
11
12
 
12
13
  type LayerQuerySourceOptions =
13
14
  | Omit<VectorQuerySourceOptions, 'filters'>
@@ -41,9 +42,12 @@ export type WidgetQuerySourceResult = {widgetSource: WidgetQuerySource};
41
42
  export class WidgetQuerySource extends WidgetRemoteSource<
42
43
  LayerQuerySourceOptions & WidgetRemoteSourceProps
43
44
  > {
44
- protected override getModelSource(owner: string): ModelSource {
45
+ protected override getModelSource(
46
+ filters: Filters | undefined,
47
+ filterOwner?: string
48
+ ): ModelSource {
45
49
  return {
46
- ...super._getModelSource(owner),
50
+ ...super._getModelSource(filters, filterOwner),
47
51
  type: 'query',
48
52
  data: this.props.sqlQuery,
49
53
  queryParameters: this.props.queryParameters,
@@ -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,
@@ -17,9 +17,12 @@ import {
17
17
  TimeSeriesRequestOptions,
18
18
  TimeSeriesResponse,
19
19
  } from './types.js';
20
- import {normalizeObjectKeys} from '../utils.js';
20
+ import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
21
21
  import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
22
22
  import {WidgetSource, WidgetSourceProps} from './widget-source.js';
23
+ import {Filters} from '../types.js';
24
+ import {ApiVersion} from '../constants.js';
25
+ import {AggregationOptions} from '../sources/types.js';
23
26
 
24
27
  export type WidgetRemoteSourceProps = WidgetSourceProps;
25
28
 
@@ -31,19 +34,50 @@ export type WidgetRemoteSourceProps = WidgetSourceProps;
31
34
  export abstract class WidgetRemoteSource<
32
35
  Props extends WidgetRemoteSourceProps,
33
36
  > extends WidgetSource<Props> {
37
+ /**
38
+ * Subclasses of {@link WidgetRemoteSource} must implement this method, calling
39
+ * {@link WidgetRemoteSource.prototype._getModelSource} for common source
40
+ * properties, and adding additional required properties including 'type' and
41
+ * 'data'.
42
+ */
43
+ protected abstract getModelSource(
44
+ filters: Filters | undefined,
45
+ filterOwner?: string
46
+ ): ModelSource;
47
+
48
+ protected _getModelSource(
49
+ filters: Filters | undefined,
50
+ filterOwner?: string
51
+ ): Omit<ModelSource, 'type' | 'data'> {
52
+ const props = this.props;
53
+ return {
54
+ apiVersion: props.apiVersion as ApiVersion,
55
+ apiBaseUrl: props.apiBaseUrl as string,
56
+ clientId: props.clientId as string,
57
+ accessToken: props.accessToken,
58
+ connectionName: props.connectionName,
59
+ filters: getApplicableFilters(filterOwner, filters || props.filters),
60
+ filtersLogicalOperator: props.filtersLogicalOperator,
61
+ spatialDataType: props.spatialDataType,
62
+ spatialDataColumn: props.spatialDataColumn,
63
+ dataResolution: (props as Partial<AggregationOptions>).dataResolution,
64
+ };
65
+ }
66
+
34
67
  async getCategories(
35
68
  options: CategoryRequestOptions
36
69
  ): Promise<CategoryResponse> {
37
70
  const {
71
+ signal,
72
+ filters = this.props.filters,
38
73
  filterOwner,
39
74
  spatialFilter,
40
75
  spatialFiltersMode,
41
76
  spatialIndexReferenceViewState,
42
- abortController,
43
77
  ...params
44
78
  } = options;
45
79
  const {column, operation, operationColumn} = params;
46
- const source = this.getModelSource(filterOwner);
80
+ const source = this.getModelSource(filters, filterOwner);
47
81
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
48
82
  source,
49
83
  spatialFilter,
@@ -65,7 +99,7 @@ export abstract class WidgetRemoteSource<
65
99
  operation,
66
100
  operationColumn: operationColumn || column,
67
101
  },
68
- opts: {abortController},
102
+ opts: {signal, headers: this.props.headers},
69
103
  }).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
70
104
  }
71
105
 
@@ -73,15 +107,16 @@ export abstract class WidgetRemoteSource<
73
107
  options: FeaturesRequestOptions
74
108
  ): Promise<FeaturesResponse> {
75
109
  const {
110
+ signal,
111
+ filters = this.props.filters,
76
112
  filterOwner,
77
113
  spatialFilter,
78
114
  spatialFiltersMode,
79
115
  spatialIndexReferenceViewState,
80
- abortController,
81
116
  ...params
82
117
  } = options;
83
118
  const {columns, dataType, featureIds, z, limit, tileResolution} = params;
84
- const source = this.getModelSource(filterOwner);
119
+ const source = this.getModelSource(filters, filterOwner);
85
120
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
86
121
  source,
87
122
  spatialFilter,
@@ -106,23 +141,24 @@ export abstract class WidgetRemoteSource<
106
141
  limit: limit || 1000,
107
142
  tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
108
143
  },
109
- opts: {abortController},
144
+ opts: {signal, headers: this.props.headers},
110
145
  // Avoid `normalizeObjectKeys()`, which changes column names.
111
146
  }).then(({rows}: FeaturesModelResponse) => ({rows}));
112
147
  }
113
148
 
114
149
  async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
115
150
  const {
151
+ signal,
152
+ filters = this.props.filters,
116
153
  filterOwner,
117
154
  spatialFilter,
118
155
  spatialFiltersMode,
119
156
  spatialIndexReferenceViewState,
120
- abortController,
121
157
  operationExp,
122
158
  ...params
123
159
  } = options;
124
160
  const {column, operation} = params;
125
- const source = this.getModelSource(filterOwner);
161
+ const source = this.getModelSource(filters, filterOwner);
126
162
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
127
163
  source,
128
164
  spatialFilter,
@@ -144,7 +180,7 @@ export abstract class WidgetRemoteSource<
144
180
  operation: operation ?? 'count',
145
181
  operationExp,
146
182
  },
147
- opts: {abortController},
183
+ opts: {signal, headers: this.props.headers},
148
184
  }).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
149
185
  }
150
186
 
@@ -152,15 +188,16 @@ export abstract class WidgetRemoteSource<
152
188
  options: HistogramRequestOptions
153
189
  ): Promise<HistogramResponse> {
154
190
  const {
191
+ signal,
192
+ filters = this.props.filters,
155
193
  filterOwner,
156
194
  spatialFilter,
157
195
  spatialFiltersMode,
158
196
  spatialIndexReferenceViewState,
159
- abortController,
160
197
  ...params
161
198
  } = options;
162
199
  const {column, operation, ticks} = params;
163
- const source = this.getModelSource(filterOwner);
200
+ const source = this.getModelSource(filters, filterOwner);
164
201
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
165
202
  source,
166
203
  spatialFilter,
@@ -178,7 +215,7 @@ export abstract class WidgetRemoteSource<
178
215
  spatialFilter,
179
216
  },
180
217
  params: {column, operation, ticks},
181
- opts: {abortController},
218
+ opts: {signal, headers: this.props.headers},
182
219
  }).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
183
220
 
184
221
  if (data.length) {
@@ -196,15 +233,16 @@ export abstract class WidgetRemoteSource<
196
233
 
197
234
  async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
198
235
  const {
236
+ signal,
237
+ filters = this.props.filters,
199
238
  filterOwner,
200
239
  spatialFilter,
201
240
  spatialFiltersMode,
202
241
  spatialIndexReferenceViewState,
203
- abortController,
204
242
  ...params
205
243
  } = options;
206
244
  const {column} = params;
207
- const source = this.getModelSource(filterOwner);
245
+ const source = this.getModelSource(filters, filterOwner);
208
246
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
209
247
  source,
210
248
  spatialFilter,
@@ -222,23 +260,24 @@ export abstract class WidgetRemoteSource<
222
260
  spatialFilter,
223
261
  },
224
262
  params: {column},
225
- opts: {abortController},
263
+ opts: {signal, headers: this.props.headers},
226
264
  }).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
227
265
  }
228
266
 
229
267
  async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
230
268
  const {
269
+ signal,
270
+ filters = this.props.filters,
231
271
  filterOwner,
232
272
  spatialFilter,
233
273
  spatialFiltersMode,
234
274
  spatialIndexReferenceViewState,
235
- abortController,
236
275
  ...params
237
276
  } = options;
238
277
  const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
239
278
  params;
240
279
 
241
- const source = this.getModelSource(filterOwner);
280
+ const source = this.getModelSource(filters, filterOwner);
242
281
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
243
282
  source,
244
283
  spatialFilter,
@@ -265,7 +304,7 @@ export abstract class WidgetRemoteSource<
265
304
  yAxisJoinOperation,
266
305
  limit: HARD_LIMIT,
267
306
  },
268
- opts: {abortController},
307
+ opts: {signal, headers: this.props.headers},
269
308
  })
270
309
  .then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
271
310
  .then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
@@ -273,15 +312,16 @@ export abstract class WidgetRemoteSource<
273
312
 
274
313
  async getTable(options: TableRequestOptions): Promise<TableResponse> {
275
314
  const {
315
+ signal,
316
+ filters = this.props.filters,
276
317
  filterOwner,
277
318
  spatialFilter,
278
319
  spatialFiltersMode,
279
320
  spatialIndexReferenceViewState,
280
- abortController,
281
321
  ...params
282
322
  } = options;
283
323
  const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
284
- const source = this.getModelSource(filterOwner);
324
+ const source = this.getModelSource(filters, filterOwner);
285
325
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
286
326
  source,
287
327
  spatialFilter,
@@ -308,7 +348,7 @@ export abstract class WidgetRemoteSource<
308
348
  limit,
309
349
  offset,
310
350
  },
311
- opts: {abortController},
351
+ opts: {signal, headers: this.props.headers},
312
352
  }).then((res: TableModelResponse) => ({
313
353
  // Avoid `normalizeObjectKeys()`, which changes column names.
314
354
  rows: res.rows ?? (res as any).ROWS,
@@ -320,8 +360,9 @@ export abstract class WidgetRemoteSource<
320
360
  options: TimeSeriesRequestOptions
321
361
  ): Promise<TimeSeriesResponse> {
322
362
  const {
363
+ signal,
364
+ filters = this.props.filters,
323
365
  filterOwner,
324
- abortController,
325
366
  spatialFilter,
326
367
  spatialFiltersMode,
327
368
  spatialIndexReferenceViewState,
@@ -339,7 +380,7 @@ export abstract class WidgetRemoteSource<
339
380
  splitByCategoryValues,
340
381
  } = params;
341
382
 
342
- const source = this.getModelSource(filterOwner);
383
+ const source = this.getModelSource(filters, filterOwner);
343
384
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
344
385
  source,
345
386
  spatialFilter,
@@ -370,7 +411,7 @@ export abstract class WidgetRemoteSource<
370
411
  splitByCategoryLimit,
371
412
  splitByCategoryValues,
372
413
  },
373
- opts: {abortController},
414
+ opts: {signal, headers: this.props.headers},
374
415
  }).then((res: TimeSeriesModelResponse) => ({
375
416
  rows: normalizeObjectKeys(res.rows),
376
417
  categories: res.metadata?.categories,
@@ -18,13 +18,11 @@ import {
18
18
  ViewState,
19
19
  } from './types.js';
20
20
  import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
21
- import {getApplicableFilters} from '../utils.js';
22
21
  import {getClient} from '../client.js';
23
22
  import {ModelSource} from '../models/model.js';
24
23
  import {SourceOptions} from '../sources/index.js';
25
24
  import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
26
25
  import {getSpatialFiltersResolution} from '../spatial-index.js';
27
- import {AggregationOptions} from '../sources/types.js';
28
26
 
29
27
  export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
30
28
  apiVersion?: ApiVersion;
@@ -37,7 +35,9 @@ export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
37
35
  *
38
36
  * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
39
37
  */
40
- export abstract class WidgetSource<Props extends WidgetSourceProps> {
38
+ export abstract class WidgetSource<
39
+ Props extends WidgetSourceProps = WidgetSourceProps,
40
+ > {
41
41
  readonly props: Props;
42
42
 
43
43
  static defaultProps: Partial<WidgetSourceProps> = {
@@ -53,29 +53,14 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
53
53
  }
54
54
 
55
55
  /**
56
- * Subclasses of {@link WidgetRemoteSource} must implement this method, calling
57
- * {@link WidgetRemoteSource.prototype._getModelSource} for common source
58
- * properties, and adding additional required properties including 'type' and
59
- * 'data'.
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.
60
61
  */
61
- protected abstract getModelSource(owner: string | undefined): ModelSource;
62
-
63
- protected _getModelSource(
64
- owner?: string
65
- ): Omit<ModelSource, 'type' | 'data'> {
66
- const props = this.props;
67
- return {
68
- apiVersion: props.apiVersion as ApiVersion,
69
- apiBaseUrl: props.apiBaseUrl as string,
70
- clientId: props.clientId as string,
71
- accessToken: props.accessToken,
72
- connectionName: props.connectionName,
73
- filters: getApplicableFilters(owner, props.filters),
74
- filtersLogicalOperator: props.filtersLogicalOperator,
75
- spatialDataType: props.spatialDataType,
76
- spatialDataColumn: props.spatialDataColumn,
77
- dataResolution: (props as Partial<AggregationOptions>).dataResolution,
78
- };
62
+ destroy() {
63
+ // no-op in most cases, but required for worker sources.
79
64
  }
80
65
 
81
66
  protected _getSpatialFiltersResolution(
@@ -8,6 +8,7 @@ import {
8
8
  WidgetRemoteSourceProps,
9
9
  } from './widget-remote-source.js';
10
10
  import {ModelSource} from '../models/model.js';
11
+ import {Filters} from '../types.js';
11
12
 
12
13
  type LayerTableSourceOptions =
13
14
  | Omit<VectorTableSourceOptions, 'filters'>
@@ -41,9 +42,12 @@ export type WidgetTableSourceResult = {widgetSource: WidgetTableSource};
41
42
  export class WidgetTableSource extends WidgetRemoteSource<
42
43
  LayerTableSourceOptions & WidgetRemoteSourceProps
43
44
  > {
44
- protected override getModelSource(owner: string): ModelSource {
45
+ protected override getModelSource(
46
+ filters: Filters | undefined,
47
+ filterOwner?: string
48
+ ): ModelSource {
45
49
  return {
46
- ...super._getModelSource(owner),
50
+ ...super._getModelSource(filters, filterOwner),
47
51
  type: 'table',
48
52
  data: this.props.tableName,
49
53
  };