@carto/api-client 0.5.0-alpha.3 → 0.5.0-alpha.5

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 (131) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/api-client.cjs +3332 -3100
  3. package/build/api-client.d.cts +1373 -0
  4. package/build/api-client.d.ts +1373 -0
  5. package/build/api-client.js +1712 -0
  6. package/build/chunk-V3E7BKVR.js +2063 -0
  7. package/build/worker.d.ts +2 -0
  8. package/build/worker.js +25 -0
  9. package/package.json +51 -45
  10. package/src/api/carto-api-error.ts +1 -1
  11. package/src/api/query.ts +5 -5
  12. package/src/api/request-with-parameters.ts +6 -6
  13. package/src/client.ts +3 -3
  14. package/src/constants-internal.ts +5 -11
  15. package/src/constants.ts +6 -6
  16. package/src/deck/get-data-filter-extension-props.ts +146 -0
  17. package/src/deck/index.ts +1 -0
  18. package/src/filters/Filter.ts +18 -8
  19. package/src/filters/FilterTypes.ts +2 -2
  20. package/src/filters/geosjonFeatures.ts +2 -2
  21. package/src/filters/tileFeatures.ts +19 -41
  22. package/src/filters.ts +4 -4
  23. package/src/geo.ts +12 -14
  24. package/src/global.d.ts +3 -8
  25. package/src/index.ts +1 -0
  26. package/src/models/common.ts +9 -7
  27. package/src/models/model.ts +3 -4
  28. package/src/operations/aggregation.ts +5 -5
  29. package/src/operations/applySorting.ts +4 -4
  30. package/src/operations/groupBy.ts +4 -4
  31. package/src/operations/groupByDate.ts +1 -1
  32. package/src/operations/histogram.ts +4 -4
  33. package/src/operations/scatterPlot.ts +4 -4
  34. package/src/sources/base-source.ts +8 -8
  35. package/src/sources/boundary-query-source.ts +2 -2
  36. package/src/sources/boundary-table-source.ts +2 -2
  37. package/src/sources/h3-query-source.ts +7 -5
  38. package/src/sources/h3-table-source.ts +7 -5
  39. package/src/sources/h3-tileset-source.ts +12 -5
  40. package/src/sources/index.ts +26 -26
  41. package/src/sources/quadbin-query-source.ts +7 -5
  42. package/src/sources/quadbin-table-source.ts +7 -5
  43. package/src/sources/quadbin-tileset-source.ts +12 -5
  44. package/src/sources/raster-source.ts +7 -16
  45. package/src/sources/types.ts +10 -4
  46. package/src/sources/vector-query-source.ts +2 -3
  47. package/src/sources/vector-table-source.ts +2 -3
  48. package/src/sources/vector-tileset-source.ts +13 -6
  49. package/src/spatial-index.ts +4 -4
  50. package/src/types-internal.ts +5 -5
  51. package/src/types.ts +15 -21
  52. package/src/utils/makeIntervalComplete.ts +1 -1
  53. package/src/utils.ts +3 -3
  54. package/src/widget-sources/index.ts +1 -1
  55. package/src/widget-sources/types.ts +5 -3
  56. package/src/widget-sources/widget-query-source.ts +6 -2
  57. package/src/widget-sources/widget-remote-source.ts +66 -18
  58. package/src/widget-sources/widget-source.ts +0 -28
  59. package/src/widget-sources/widget-table-source.ts +6 -2
  60. package/src/widget-sources/widget-tileset-source.ts +130 -90
  61. package/src/widget-sources/widget-tileset-worker-source.ts +238 -0
  62. package/src/workers/constants.ts +13 -0
  63. package/src/workers/types.ts +20 -0
  64. package/src/workers/utils.ts +33 -0
  65. package/src/workers/widget-tileset-worker.ts +36 -0
  66. package/build/api/carto-api-error.d.ts +0 -26
  67. package/build/api/endpoints.d.ts +0 -24
  68. package/build/api/index.d.ts +0 -5
  69. package/build/api/query.d.ts +0 -3
  70. package/build/api/request-with-parameters.d.ts +0 -10
  71. package/build/api-client.cjs.map +0 -1
  72. package/build/api-client.modern.js +0 -3304
  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 -21
  82. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  83. package/build/filters/tileFeaturesRaster.d.ts +0 -16
  84. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  85. package/build/filters.d.ts +0 -39
  86. package/build/geo.d.ts +0 -19
  87. package/build/index.d.ts +0 -15
  88. package/build/models/common.d.ts +0 -27
  89. package/build/models/index.d.ts +0 -3
  90. package/build/models/model.d.ts +0 -37
  91. package/build/operations/aggregation.d.ts +0 -8
  92. package/build/operations/applySorting.d.ts +0 -20
  93. package/build/operations/groupBy.d.ts +0 -15
  94. package/build/operations/groupByDate.d.ts +0 -11
  95. package/build/operations/histogram.d.ts +0 -13
  96. package/build/operations/index.d.ts +0 -6
  97. package/build/operations/scatterPlot.d.ts +0 -14
  98. package/build/sources/base-source.d.ts +0 -4
  99. package/build/sources/boundary-query-source.d.ts +0 -10
  100. package/build/sources/boundary-table-source.d.ts +0 -8
  101. package/build/sources/h3-query-source.d.ts +0 -5
  102. package/build/sources/h3-table-source.d.ts +0 -5
  103. package/build/sources/h3-tileset-source.d.ts +0 -5
  104. package/build/sources/index.d.ts +0 -26
  105. package/build/sources/quadbin-query-source.d.ts +0 -5
  106. package/build/sources/quadbin-table-source.d.ts +0 -5
  107. package/build/sources/quadbin-tileset-source.d.ts +0 -5
  108. package/build/sources/raster-source.d.ts +0 -5
  109. package/build/sources/types.d.ts +0 -366
  110. package/build/sources/vector-query-source.d.ts +0 -5
  111. package/build/sources/vector-table-source.d.ts +0 -5
  112. package/build/sources/vector-tileset-source.d.ts +0 -5
  113. package/build/spatial-index.d.ts +0 -14
  114. package/build/types-internal.d.ts +0 -56
  115. package/build/types.d.ts +0 -148
  116. package/build/utils/dateUtils.d.ts +0 -10
  117. package/build/utils/getTileFormat.d.ts +0 -3
  118. package/build/utils/makeIntervalComplete.d.ts +0 -2
  119. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  120. package/build/utils/transformToTileCoords.d.ts +0 -9
  121. package/build/utils.d.ts +0 -32
  122. package/build/widget-sources/index.d.ts +0 -7
  123. package/build/widget-sources/types.d.ts +0 -158
  124. package/build/widget-sources/widget-query-source.d.ts +0 -33
  125. package/build/widget-sources/widget-raster-source.d.ts +0 -11
  126. package/build/widget-sources/widget-remote-source.d.ts +0 -18
  127. package/build/widget-sources/widget-source.d.ts +0 -74
  128. package/build/widget-sources/widget-table-source.d.ts +0 -33
  129. package/build/widget-sources/widget-tileset-source.d.ts +0 -77
  130. package/src/filters/tileFeaturesRaster.ts +0 -111
  131. package/src/widget-sources/widget-raster-source.ts +0 -14
@@ -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,10 +34,48 @@ export type WidgetRemoteSourceProps = WidgetSourceProps;
31
34
  export abstract class WidgetRemoteSource<
32
35
  Props extends WidgetRemoteSourceProps,
33
36
  > 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
+ /**
45
+ * Subclasses of {@link WidgetRemoteSource} must implement this method, calling
46
+ * {@link WidgetRemoteSource.prototype._getModelSource} for common source
47
+ * properties, and adding additional required properties including 'type' and
48
+ * 'data'.
49
+ */
50
+ protected abstract getModelSource(
51
+ filters: Filters | undefined,
52
+ filterOwner?: string
53
+ ): ModelSource;
54
+
55
+ protected _getModelSource(
56
+ filters: Filters | undefined,
57
+ filterOwner?: string
58
+ ): Omit<ModelSource, 'type' | 'data'> {
59
+ const props = this.props;
60
+ return {
61
+ apiVersion: props.apiVersion as ApiVersion,
62
+ apiBaseUrl: props.apiBaseUrl as string,
63
+ clientId: props.clientId as string,
64
+ accessToken: props.accessToken,
65
+ connectionName: props.connectionName,
66
+ filters: getApplicableFilters(filterOwner, filters || props.filters),
67
+ filtersLogicalOperator: props.filtersLogicalOperator,
68
+ spatialDataType: props.spatialDataType,
69
+ spatialDataColumn: props.spatialDataColumn,
70
+ dataResolution: (props as Partial<AggregationOptions>).dataResolution,
71
+ };
72
+ }
73
+
34
74
  async getCategories(
35
75
  options: CategoryRequestOptions
36
76
  ): Promise<CategoryResponse> {
37
77
  const {
78
+ filters = this.props.filters,
38
79
  filterOwner,
39
80
  spatialFilter,
40
81
  spatialFiltersMode,
@@ -43,7 +84,7 @@ export abstract class WidgetRemoteSource<
43
84
  ...params
44
85
  } = options;
45
86
  const {column, operation, operationColumn} = params;
46
- const source = this.getModelSource(filterOwner);
87
+ const source = this.getModelSource(filters, filterOwner);
47
88
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
48
89
  source,
49
90
  spatialFilter,
@@ -65,7 +106,7 @@ export abstract class WidgetRemoteSource<
65
106
  operation,
66
107
  operationColumn: operationColumn || column,
67
108
  },
68
- opts: {abortController},
109
+ opts: {abortController, headers: this._headers},
69
110
  }).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
70
111
  }
71
112
 
@@ -73,6 +114,7 @@ export abstract class WidgetRemoteSource<
73
114
  options: FeaturesRequestOptions
74
115
  ): Promise<FeaturesResponse> {
75
116
  const {
117
+ filters = this.props.filters,
76
118
  filterOwner,
77
119
  spatialFilter,
78
120
  spatialFiltersMode,
@@ -81,7 +123,7 @@ export abstract class WidgetRemoteSource<
81
123
  ...params
82
124
  } = options;
83
125
  const {columns, dataType, featureIds, z, limit, tileResolution} = params;
84
- const source = this.getModelSource(filterOwner);
126
+ const source = this.getModelSource(filters, filterOwner);
85
127
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
86
128
  source,
87
129
  spatialFilter,
@@ -106,13 +148,14 @@ export abstract class WidgetRemoteSource<
106
148
  limit: limit || 1000,
107
149
  tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
108
150
  },
109
- opts: {abortController},
151
+ opts: {abortController, headers: this._headers},
110
152
  // Avoid `normalizeObjectKeys()`, which changes column names.
111
153
  }).then(({rows}: FeaturesModelResponse) => ({rows}));
112
154
  }
113
155
 
114
156
  async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
115
157
  const {
158
+ filters = this.props.filters,
116
159
  filterOwner,
117
160
  spatialFilter,
118
161
  spatialFiltersMode,
@@ -122,7 +165,7 @@ export abstract class WidgetRemoteSource<
122
165
  ...params
123
166
  } = options;
124
167
  const {column, operation} = params;
125
- const source = this.getModelSource(filterOwner);
168
+ const source = this.getModelSource(filters, filterOwner);
126
169
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
127
170
  source,
128
171
  spatialFilter,
@@ -144,7 +187,7 @@ export abstract class WidgetRemoteSource<
144
187
  operation: operation ?? 'count',
145
188
  operationExp,
146
189
  },
147
- opts: {abortController},
190
+ opts: {abortController, headers: this._headers},
148
191
  }).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
149
192
  }
150
193
 
@@ -152,6 +195,7 @@ export abstract class WidgetRemoteSource<
152
195
  options: HistogramRequestOptions
153
196
  ): Promise<HistogramResponse> {
154
197
  const {
198
+ filters = this.props.filters,
155
199
  filterOwner,
156
200
  spatialFilter,
157
201
  spatialFiltersMode,
@@ -160,7 +204,7 @@ export abstract class WidgetRemoteSource<
160
204
  ...params
161
205
  } = options;
162
206
  const {column, operation, ticks} = params;
163
- const source = this.getModelSource(filterOwner);
207
+ const source = this.getModelSource(filters, filterOwner);
164
208
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
165
209
  source,
166
210
  spatialFilter,
@@ -178,7 +222,7 @@ export abstract class WidgetRemoteSource<
178
222
  spatialFilter,
179
223
  },
180
224
  params: {column, operation, ticks},
181
- opts: {abortController},
225
+ opts: {abortController, headers: this._headers},
182
226
  }).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
183
227
 
184
228
  if (data.length) {
@@ -196,6 +240,7 @@ export abstract class WidgetRemoteSource<
196
240
 
197
241
  async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
198
242
  const {
243
+ filters = this.props.filters,
199
244
  filterOwner,
200
245
  spatialFilter,
201
246
  spatialFiltersMode,
@@ -204,7 +249,7 @@ export abstract class WidgetRemoteSource<
204
249
  ...params
205
250
  } = options;
206
251
  const {column} = params;
207
- const source = this.getModelSource(filterOwner);
252
+ const source = this.getModelSource(filters, filterOwner);
208
253
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
209
254
  source,
210
255
  spatialFilter,
@@ -222,12 +267,13 @@ export abstract class WidgetRemoteSource<
222
267
  spatialFilter,
223
268
  },
224
269
  params: {column},
225
- opts: {abortController},
270
+ opts: {abortController, headers: this._headers},
226
271
  }).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
227
272
  }
228
273
 
229
274
  async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
230
275
  const {
276
+ filters = this.props.filters,
231
277
  filterOwner,
232
278
  spatialFilter,
233
279
  spatialFiltersMode,
@@ -238,7 +284,7 @@ export abstract class WidgetRemoteSource<
238
284
  const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
239
285
  params;
240
286
 
241
- const source = this.getModelSource(filterOwner);
287
+ const source = this.getModelSource(filters, filterOwner);
242
288
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
243
289
  source,
244
290
  spatialFilter,
@@ -265,7 +311,7 @@ export abstract class WidgetRemoteSource<
265
311
  yAxisJoinOperation,
266
312
  limit: HARD_LIMIT,
267
313
  },
268
- opts: {abortController},
314
+ opts: {abortController, headers: this._headers},
269
315
  })
270
316
  .then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
271
317
  .then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
@@ -273,6 +319,7 @@ export abstract class WidgetRemoteSource<
273
319
 
274
320
  async getTable(options: TableRequestOptions): Promise<TableResponse> {
275
321
  const {
322
+ filters = this.props.filters,
276
323
  filterOwner,
277
324
  spatialFilter,
278
325
  spatialFiltersMode,
@@ -281,7 +328,7 @@ export abstract class WidgetRemoteSource<
281
328
  ...params
282
329
  } = options;
283
330
  const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
284
- const source = this.getModelSource(filterOwner);
331
+ const source = this.getModelSource(filters, filterOwner);
285
332
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
286
333
  source,
287
334
  spatialFilter,
@@ -308,7 +355,7 @@ export abstract class WidgetRemoteSource<
308
355
  limit,
309
356
  offset,
310
357
  },
311
- opts: {abortController},
358
+ opts: {abortController, headers: this._headers},
312
359
  }).then((res: TableModelResponse) => ({
313
360
  // Avoid `normalizeObjectKeys()`, which changes column names.
314
361
  rows: res.rows ?? (res as any).ROWS,
@@ -320,6 +367,7 @@ export abstract class WidgetRemoteSource<
320
367
  options: TimeSeriesRequestOptions
321
368
  ): Promise<TimeSeriesResponse> {
322
369
  const {
370
+ filters = this.props.filters,
323
371
  filterOwner,
324
372
  abortController,
325
373
  spatialFilter,
@@ -339,7 +387,7 @@ export abstract class WidgetRemoteSource<
339
387
  splitByCategoryValues,
340
388
  } = params;
341
389
 
342
- const source = this.getModelSource(filterOwner);
390
+ const source = this.getModelSource(filters, filterOwner);
343
391
  const spatialFiltersResolution = this._getSpatialFiltersResolution(
344
392
  source,
345
393
  spatialFilter,
@@ -370,7 +418,7 @@ export abstract class WidgetRemoteSource<
370
418
  splitByCategoryLimit,
371
419
  splitByCategoryValues,
372
420
  },
373
- opts: {abortController},
421
+ opts: {abortController, headers: this._headers},
374
422
  }).then((res: TimeSeriesModelResponse) => ({
375
423
  rows: normalizeObjectKeys(res.rows),
376
424
  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;
@@ -52,32 +50,6 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
52
50
  this.props = {...WidgetSource.defaultProps, ...props};
53
51
  }
54
52
 
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'.
60
- */
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
- };
79
- }
80
-
81
53
  protected _getSpatialFiltersResolution(
82
54
  source: Omit<ModelSource, 'type' | 'data'>,
83
55
  spatialFilter?: SpatialFilter,
@@ -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
  };