@carto/api-client 0.5.7-alpha.3 → 0.5.7-alpha.6

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.
@@ -103,11 +103,11 @@ __export(src_exports, {
103
103
  ApiVersion: () => ApiVersion,
104
104
  BASEMAP: () => basemap_styles_default,
105
105
  CartoAPIError: () => CartoAPIError,
106
+ CellSet: () => CellSet,
106
107
  DEFAULT_API_BASE_URL: () => DEFAULT_API_BASE_URL,
107
108
  FEATURE_GEOM_PROPERTY: () => FEATURE_GEOM_PROPERTY,
108
109
  FilterType: () => FilterType,
109
110
  OPACITY_MAP: () => OPACITY_MAP,
110
- OTHERS_CATEGORY_NAME: () => OTHERS_CATEGORY_NAME,
111
111
  Provider: () => Provider,
112
112
  SOURCE_DEFAULTS: () => SOURCE_DEFAULTS,
113
113
  SchemaFieldType: () => SchemaFieldType,
@@ -5664,15 +5664,20 @@ function tileFeaturesRaster({
5664
5664
  const tileResolution = (0, import_quadbin2.getResolution)(tiles[0].index.q);
5665
5665
  const tileBlockSize = tiles[0].data.blockSize;
5666
5666
  const cellResolution = tileResolution + BigInt(Math.log2(tileBlockSize));
5667
- const spatialFilterCells = new Set(
5668
- (0, import_quadbin2.geometryToCells)(options.spatialFilter, cellResolution)
5669
- );
5670
5667
  const data = /* @__PURE__ */ new Map();
5671
5668
  for (const tile of tiles) {
5672
5669
  const parent = tile.index.q;
5673
- const children = cellToChildrenSorted(parent, cellResolution);
5674
- for (let i = 0; i < children.length; i++) {
5675
- if (!spatialFilterCells.has(children[i])) continue;
5670
+ const tilePolygon = (0, import_quadbin2.cellToBoundary)(parent);
5671
+ const tileFilter = turf_intersect_default(
5672
+ featureCollection([feature(tilePolygon), feature(options.spatialFilter)])
5673
+ );
5674
+ const needsFilter = tileFilter ? !turf_boolean_within_default(tilePolygon, options.spatialFilter) : false;
5675
+ const tileFilterCells = needsFilter ? new Set((0, import_quadbin2.geometryToCells)(tileFilter.geometry, cellResolution)) : null;
5676
+ const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5677
+ for (let i = 0; i < tileSortedCells.length; i++) {
5678
+ if (needsFilter && !tileFilterCells.has(tileSortedCells[i])) {
5679
+ continue;
5680
+ }
5676
5681
  const cellData = {};
5677
5682
  let cellDataExists = false;
5678
5683
  for (const band in tile.data.cells.numericProps) {
@@ -5684,7 +5689,7 @@ function tileFeaturesRaster({
5684
5689
  }
5685
5690
  }
5686
5691
  if (cellDataExists) {
5687
- data.set(children[i], cellData);
5692
+ data.set(tileSortedCells[i], cellData);
5688
5693
  }
5689
5694
  }
5690
5695
  }
@@ -6529,7 +6534,7 @@ var WidgetRemoteSource = class extends WidgetSource {
6529
6534
  spatialFiltersMode,
6530
6535
  ...params
6531
6536
  } = options;
6532
- const { column, operation: operation2, operationColumn, operationExp, othersThreshold } = params;
6537
+ const { column, operation: operation2, operationColumn, operationExp } = params;
6533
6538
  if (operation2 === AggregationTypes.Custom) {
6534
6539
  assert2(operationExp, "operationExp is required for custom operation");
6535
6540
  }
@@ -6544,8 +6549,7 @@ var WidgetRemoteSource = class extends WidgetSource {
6544
6549
  column,
6545
6550
  operation: operation2,
6546
6551
  operationExp,
6547
- operationColumn: operationColumn || column,
6548
- othersThreshold
6552
+ operationColumn: operationColumn || column
6549
6553
  },
6550
6554
  opts: { signal, headers: this.props.headers }
6551
6555
  }).then((res) => normalizeObjectKeys(res.rows));
@@ -6948,19 +6952,12 @@ function normalizeSortByOptions({
6948
6952
 
6949
6953
  // src/operations/groupBy.ts
6950
6954
  init_cjs_shims();
6951
-
6952
- // src/widget-sources/constants.ts
6953
- init_cjs_shims();
6954
- var OTHERS_CATEGORY_NAME = "_carto_others";
6955
-
6956
- // src/operations/groupBy.ts
6957
6955
  function groupValuesByColumn({
6958
6956
  data,
6959
6957
  valuesColumns,
6960
6958
  joinOperation,
6961
6959
  keysColumn,
6962
- operation: operation2,
6963
- othersThreshold
6960
+ operation: operation2
6964
6961
  }) {
6965
6962
  if (Array.isArray(data) && data.length === 0) {
6966
6963
  return null;
@@ -6978,23 +6975,13 @@ function groupValuesByColumn({
6978
6975
  return accumulator;
6979
6976
  }, /* @__PURE__ */ new Map());
6980
6977
  const targetOperation = aggregationFunctions[operation2];
6981
- if (!targetOperation) {
6982
- return [];
6983
- }
6984
- const allCategories = Array.from(groups).map(([name, value]) => ({
6985
- name,
6986
- value: targetOperation(value)
6987
- }));
6988
- allCategories.sort((a, b) => b.value - a.value);
6989
- if (othersThreshold && allCategories.length > othersThreshold) {
6990
- const otherNames = allCategories.map((entry) => entry.name).slice(othersThreshold);
6991
- const otherValue = otherNames.flatMap((name) => groups.get(name));
6992
- allCategories.push({
6993
- name: OTHERS_CATEGORY_NAME,
6994
- value: targetOperation(otherValue)
6995
- });
6978
+ if (targetOperation) {
6979
+ return Array.from(groups).map(([name, value]) => ({
6980
+ name,
6981
+ value: targetOperation(value)
6982
+ }));
6996
6983
  }
6997
- return allCategories;
6984
+ return [];
6998
6985
  }
6999
6986
 
7000
6987
  // src/operations/groupByDate.ts
@@ -7568,8 +7555,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7568
7555
  joinOperation,
7569
7556
  filters,
7570
7557
  filterOwner,
7571
- spatialFilter,
7572
- othersThreshold
7558
+ spatialFilter
7573
7559
  }) {
7574
7560
  const filteredFeatures = this._getFilteredFeatures(
7575
7561
  spatialFilter,
@@ -7585,8 +7571,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7585
7571
  valuesColumns: normalizeColumns(operationColumn || column),
7586
7572
  joinOperation,
7587
7573
  keysColumn: column,
7588
- operation: operation2,
7589
- othersThreshold
7574
+ operation: operation2
7590
7575
  });
7591
7576
  return groups || [];
7592
7577
  }
@@ -10309,17 +10294,74 @@ function _getHexagonResolution(viewport, tileSize) {
10309
10294
  Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
10310
10295
  );
10311
10296
  }
10297
+
10298
+ // src/utils/CellSet.ts
10299
+ init_cjs_shims();
10300
+ var EMPTY_U32 = 2 ** 32 - 1;
10301
+ var CellSet = class {
10302
+ constructor(cells) {
10303
+ /** List of cells stored by the set. Stored by reference, without copying. */
10304
+ __publicField(this, "cells");
10305
+ /** DataView representing a single cell ID. Pre-allocated to reduce memory during queries. */
10306
+ __publicField(this, "cellView", new DataView(new ArrayBuffer(8)));
10307
+ /** Hash table, mapping a hash index (computed) to an index in the 'cells' array. */
10308
+ __publicField(this, "hashTable");
10309
+ this.cells = cells;
10310
+ this.hashTable = new Uint32Array(hashBuckets(cells.length)).fill(EMPTY_U32);
10311
+ for (let cellIndex = 0; cellIndex < cells.length; cellIndex++) {
10312
+ this.hashTable[this.hashLookup(cells[cellIndex])] = cellIndex;
10313
+ }
10314
+ }
10315
+ has(cell) {
10316
+ const hashIndex = this.hashLookup(cell);
10317
+ return this.hashTable[hashIndex] !== EMPTY_U32;
10318
+ }
10319
+ hashLookup(cell) {
10320
+ this.cellView.setBigUint64(0, cell);
10321
+ const hashval = hash(this.cellView);
10322
+ const hashmod = this.hashTable.length - 1;
10323
+ let bucket = hashval & hashmod;
10324
+ for (let probe = 0; probe <= hashmod; probe++) {
10325
+ const cellIndex = this.hashTable[bucket];
10326
+ if (cellIndex === EMPTY_U32 || cell === this.cells[cellIndex]) {
10327
+ return bucket;
10328
+ }
10329
+ bucket = bucket + probe + 1 & hashmod;
10330
+ }
10331
+ throw new Error("Hash table full.");
10332
+ }
10333
+ };
10334
+ function hash(view, h = 0) {
10335
+ const m = 1540483477;
10336
+ const r = 24;
10337
+ for (let i = 0, il = view.byteLength / 4; i < il; i++) {
10338
+ let k = view.getUint32(i * 4);
10339
+ k = Math.imul(k, m) >>> 0;
10340
+ k = (k ^ k >> r) >>> 0;
10341
+ k = Math.imul(k, m) >>> 0;
10342
+ h = Math.imul(h, m) >>> 0;
10343
+ h = (h ^ k) >>> 0;
10344
+ }
10345
+ return h;
10346
+ }
10347
+ function hashBuckets(initialCount) {
10348
+ let buckets = 1;
10349
+ while (buckets < initialCount + initialCount / 4) {
10350
+ buckets *= 2;
10351
+ }
10352
+ return buckets;
10353
+ }
10312
10354
  // Annotate the CommonJS export names for ESM import in node:
10313
10355
  0 && (module.exports = {
10314
10356
  AggregationTypes,
10315
10357
  ApiVersion,
10316
10358
  BASEMAP,
10317
10359
  CartoAPIError,
10360
+ CellSet,
10318
10361
  DEFAULT_API_BASE_URL,
10319
10362
  FEATURE_GEOM_PROPERTY,
10320
10363
  FilterType,
10321
10364
  OPACITY_MAP,
10322
- OTHERS_CATEGORY_NAME,
10323
10365
  Provider,
10324
10366
  SOURCE_DEFAULTS,
10325
10367
  SchemaFieldType,