@carto/api-client 0.5.15 → 0.5.16

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## 0.5
4
4
 
5
+ ### 0.5.16
6
+
7
+ - feat(widgets): Add getAggregations() method (#229)
8
+ - chore(deps): bump h3-js from 4.2.1 to 4.3.0 (#232)
9
+
5
10
  ### 0.5.15
6
11
 
7
12
  - feat(sources): Add support for trajectory data sources (#227, #228)
@@ -6420,7 +6420,8 @@ var AVAILABLE_MODELS = [
6420
6420
  "timeseries",
6421
6421
  "range",
6422
6422
  "scatterplot",
6423
- "table"
6423
+ "table",
6424
+ "aggregations"
6424
6425
  ];
6425
6426
  var { V3 } = ApiVersion;
6426
6427
  var REQUEST_GET_MAX_URL_LENGTH = 2048;
@@ -6863,6 +6864,30 @@ var WidgetRemoteSource = class extends WidgetSource {
6863
6864
  categories: res.metadata?.categories
6864
6865
  }));
6865
6866
  }
6867
+ async getAggregations(options) {
6868
+ const {
6869
+ signal,
6870
+ filters = this.props.filters,
6871
+ filterOwner,
6872
+ spatialFilter,
6873
+ spatialFiltersMode,
6874
+ aggregations
6875
+ } = options;
6876
+ return executeModel({
6877
+ model: "aggregations",
6878
+ source: {
6879
+ ...this.getModelSource(filters, filterOwner),
6880
+ spatialFiltersMode,
6881
+ spatialFilter
6882
+ },
6883
+ params: {
6884
+ aggregations
6885
+ },
6886
+ opts: { signal, headers: this.props.headers }
6887
+ }).then((res) => ({
6888
+ rows: res.rows.map((row) => normalizeObjectKeys(row))
6889
+ }));
6890
+ }
6866
6891
  /** @experimental */
6867
6892
  async getExtent(options = {}) {
6868
6893
  const { signal, filters = this.props.filters, filterOwner } = options;
@@ -7685,6 +7710,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7685
7710
  assertColumn(this._features, column);
7686
7711
  }
7687
7712
  const targetOperation = aggregationFunctions[operation2];
7713
+ assert2(targetOperation, `Unsupported aggregation operation: ${operation2}`);
7688
7714
  return {
7689
7715
  value: targetOperation(filteredFeatures, column, joinOperation)
7690
7716
  };
@@ -7883,6 +7909,39 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7883
7909
  max: aggregationFunctions.max(filteredFeatures, column)
7884
7910
  };
7885
7911
  }
7912
+ async getAggregations({
7913
+ aggregations,
7914
+ filters,
7915
+ filterOwner,
7916
+ spatialFilter
7917
+ }) {
7918
+ const filteredFeatures = this._getFilteredFeatures(
7919
+ spatialFilter,
7920
+ filters,
7921
+ filterOwner
7922
+ );
7923
+ if (!this._features.length) {
7924
+ return { rows: [] };
7925
+ }
7926
+ assert2(
7927
+ typeof aggregations !== "string",
7928
+ "Unsupported tileset SQL aggregation"
7929
+ );
7930
+ const result = {};
7931
+ const usedAliases = /* @__PURE__ */ new Set();
7932
+ for (const { column, operation: operation2, alias } of aggregations) {
7933
+ if (column && column !== "*" || operation2 !== AggregationTypes.Count) {
7934
+ assertColumn(this._features, column);
7935
+ }
7936
+ const aliasKey = alias.toLowerCase();
7937
+ assert2(!usedAliases.has(aliasKey), `Duplicate alias: ${aliasKey}`);
7938
+ usedAliases.add(aliasKey);
7939
+ const targetOperation = aggregationFunctions[operation2];
7940
+ assert2(targetOperation, `Unsupported operation: ${operation2}`);
7941
+ result[alias] = targetOperation(filteredFeatures, column);
7942
+ }
7943
+ return { rows: [result] };
7944
+ }
7886
7945
  /** @experimental */
7887
7946
  async getExtent() {
7888
7947
  return Promise.reject(new Error("not implemented"));
@@ -8117,6 +8176,16 @@ var WidgetTilesetSource = class extends WidgetSource {
8117
8176
  }) {
8118
8177
  return this._executeWorkerMethod("getRange" /* GET_RANGE */, [options], signal);
8119
8178
  }
8179
+ async getAggregations({
8180
+ signal,
8181
+ ...options
8182
+ }) {
8183
+ return this._executeWorkerMethod(
8184
+ "getAggregations" /* GET_AGGREGATIONS */,
8185
+ [options],
8186
+ signal
8187
+ );
8188
+ }
8120
8189
  /** @experimental */
8121
8190
  async getExtent() {
8122
8191
  return Promise.resolve({