@carto/api-client 0.5.8-alpha-others-orderby.2 → 0.5.9-alpha.PR193.1

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.8
6
+
7
+ - feat(widgets): Add othersThreshold to WidgetSource.getCategories (#194)
8
+ - perf(rasters): Improve performance of raster widget spatial filtering (#207)
9
+
5
10
  ### 0.5.7
6
11
 
7
12
  - feat(widgets): Allow local widget calculations without spatial filter (#204)
@@ -159,7 +159,6 @@ __export(src_exports, {
159
159
  getLayerProps: () => getLayerProps,
160
160
  getMaxMarkerSize: () => getMaxMarkerSize,
161
161
  getSizeAccessor: () => getSizeAccessor,
162
- getSorter: () => getSorter,
163
162
  getSpatialIndexFromGeoColumn: () => getSpatialIndexFromGeoColumn,
164
163
  getTextAccessor: () => getTextAccessor,
165
164
  groupValuesByColumn: () => groupValuesByColumn,
@@ -5717,7 +5716,7 @@ function tileFeaturesRaster({
5717
5716
  options.spatialFilter
5718
5717
  );
5719
5718
  if (intersection3 === false) continue;
5720
- const tileSortedCells = cellToChildrenSorted(parent, cellResolution);
5719
+ const tileSortedCells = cellToChildrenRaster(parent, cellResolution);
5721
5720
  for (let i = 0; i < tileSortedCells.length; i++) {
5722
5721
  if (intersection3 !== true && !intersection3.has(tileSortedCells[i])) {
5723
5722
  continue;
@@ -5745,17 +5744,19 @@ function isRasterTile(tile) {
5745
5744
  function isRasterTileVisible(tile) {
5746
5745
  return !!(tile.isVisible && tile.data?.cells?.numericProps);
5747
5746
  }
5748
- function cellToChildrenSorted(parent, resolution) {
5749
- return (0, import_quadbin3.cellToChildren)(parent, resolution).sort(
5750
- (cellA, cellB) => {
5751
- const tileA = (0, import_quadbin3.cellToTile)(cellA);
5752
- const tileB = (0, import_quadbin3.cellToTile)(cellB);
5753
- if (tileA.y !== tileB.y) {
5754
- return tileA.y > tileB.y ? 1 : -1;
5755
- }
5756
- return tileA.x > tileB.x ? 1 : -1;
5757
- }
5758
- );
5747
+ function cellToChildrenRaster(parent, resolution) {
5748
+ const parentTile = (0, import_quadbin3.cellToTile)(parent);
5749
+ const childZ = Number(resolution);
5750
+ const blockSize = 2 ** (childZ - parentTile.z);
5751
+ const childBaseX = parentTile.x * blockSize;
5752
+ const childBaseY = parentTile.y * blockSize;
5753
+ const cells = [];
5754
+ for (let i = 0, il = blockSize ** 2; i < il; i++) {
5755
+ const x = childBaseX + i % blockSize;
5756
+ const y = childBaseY + Math.floor(i / blockSize);
5757
+ cells.push((0, import_quadbin3.tileToCell)({ x, y, z: childZ }));
5758
+ }
5759
+ return cells;
5759
5760
  }
5760
5761
  function isValidBandValue(value, nodata) {
5761
5762
  return Number.isNaN(value) ? false : nodata !== value;
@@ -6082,7 +6083,8 @@ async function requestWithParameters({
6082
6083
  headers: customHeaders = {},
6083
6084
  errorContext,
6084
6085
  maxLengthURL = DEFAULT_MAX_LENGTH_URL,
6085
- localCache
6086
+ localCache,
6087
+ signal
6086
6088
  }) {
6087
6089
  parameters = {
6088
6090
  v: V3_MINOR_VERSION,
@@ -6105,8 +6107,9 @@ async function requestWithParameters({
6105
6107
  const fetchPromise = url.length > maxLengthURL ? fetch(baseUrl, {
6106
6108
  method: "POST",
6107
6109
  body: JSON.stringify(parameters),
6108
- headers
6109
- }) : fetch(url, { headers });
6110
+ headers,
6111
+ signal
6112
+ }) : fetch(url, { headers, signal });
6110
6113
  let response;
6111
6114
  let responseJson;
6112
6115
  const jsonPromise = fetchPromise.then((_response) => {
@@ -6205,7 +6208,7 @@ async function baseSource(endpoint, options, urlParameters) {
6205
6208
  Authorization: `Bearer ${options.accessToken}`,
6206
6209
  ...options.headers
6207
6210
  };
6208
- const parameters = { client: clientId, ...urlParameters };
6211
+ const parameters = { client: clientId, ...options.tags, ...urlParameters };
6209
6212
  const errorContext = {
6210
6213
  requestType: "Map instantiation",
6211
6214
  connection: options.connectionName,
@@ -6426,7 +6429,8 @@ function executeModel(props) {
6426
6429
  filtersLogicalOperator = "and",
6427
6430
  spatialDataType = "geo",
6428
6431
  spatialDataColumn = DEFAULT_GEO_COLUMN,
6429
- spatialFiltersMode = "intersects"
6432
+ spatialFiltersMode = "intersects",
6433
+ tags
6430
6434
  } = source;
6431
6435
  const queryParams = {
6432
6436
  type,
@@ -6435,7 +6439,8 @@ function executeModel(props) {
6435
6439
  params,
6436
6440
  queryParameters: source.queryParameters || "",
6437
6441
  filters,
6438
- filtersLogicalOperator
6442
+ filtersLogicalOperator,
6443
+ tags
6439
6444
  };
6440
6445
  queryParams.spatialDataType = spatialDataType;
6441
6446
  queryParams.spatialDataColumn = spatialDataColumn;
@@ -6570,7 +6575,8 @@ var WidgetRemoteSource = class extends WidgetSource {
6570
6575
  filters: getApplicableFilters(filterOwner, filters || props.filters),
6571
6576
  filtersLogicalOperator: props.filtersLogicalOperator,
6572
6577
  spatialDataType: props.spatialDataType,
6573
- spatialDataColumn: props.spatialDataColumn
6578
+ spatialDataColumn: props.spatialDataColumn,
6579
+ tags: props.tags
6574
6580
  };
6575
6581
  }
6576
6582
  async getCategories(options) {
@@ -6583,14 +6589,7 @@ var WidgetRemoteSource = class extends WidgetSource {
6583
6589
  rawResult,
6584
6590
  ...params
6585
6591
  } = options;
6586
- const {
6587
- column,
6588
- operation: operation2,
6589
- operationColumn,
6590
- operationExp,
6591
- othersThreshold,
6592
- orderBy
6593
- } = params;
6592
+ const { column, operation: operation2, operationColumn, operationExp, othersThreshold } = params;
6594
6593
  if (operation2 === AggregationTypes.Custom) {
6595
6594
  assert2(operationExp, "operationExp is required for custom operation");
6596
6595
  }
@@ -6606,8 +6605,7 @@ var WidgetRemoteSource = class extends WidgetSource {
6606
6605
  operation: operation2,
6607
6606
  operationExp,
6608
6607
  operationColumn: operationColumn || column,
6609
- othersThreshold,
6610
- orderBy
6608
+ othersThreshold
6611
6609
  },
6612
6610
  opts: { signal, headers: this.props.headers }
6613
6611
  });
@@ -7027,8 +7025,7 @@ function groupValuesByColumn({
7027
7025
  joinOperation,
7028
7026
  keysColumn,
7029
7027
  operation: operation2,
7030
- othersThreshold,
7031
- orderBy = "frequency_desc"
7028
+ othersThreshold
7032
7029
  }) {
7033
7030
  if (Array.isArray(data) && data.length === 0) {
7034
7031
  return { rows: null };
@@ -7052,7 +7049,7 @@ function groupValuesByColumn({
7052
7049
  const allCategories = Array.from(groups).map(([name, value]) => ({
7053
7050
  name,
7054
7051
  value: targetOperation(value)
7055
- })).sort(getSorter(orderBy));
7052
+ })).sort((a, b) => b.value - a.value);
7056
7053
  if (othersThreshold && allCategories.length > othersThreshold) {
7057
7054
  const otherValue = allCategories.slice(othersThreshold).flatMap(({ name }) => groups.get(name));
7058
7055
  return {
@@ -7066,21 +7063,6 @@ function groupValuesByColumn({
7066
7063
  rows: allCategories
7067
7064
  };
7068
7065
  }
7069
- function getSorter(orderBy) {
7070
- switch (orderBy) {
7071
- case "frequency_asc":
7072
- return (a, b) => a.value - b.value || localeCompare(a.name, b.name);
7073
- case "frequency_desc":
7074
- return (a, b) => b.value - a.value || localeCompare(a.name, b.name);
7075
- case "alphabetical_asc":
7076
- return (a, b) => localeCompare(a.name, b.name) || b.value - a.value;
7077
- case "alphabetical_desc":
7078
- return (a, b) => localeCompare(b.name, a.name) || b.value - a.value;
7079
- }
7080
- }
7081
- function localeCompare(a, b) {
7082
- return (a ?? "null").localeCompare(b ?? "null");
7083
- }
7084
7066
 
7085
7067
  // src/operations/groupByDate.ts
7086
7068
  init_cjs_shims();
@@ -7655,7 +7637,6 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7655
7637
  filterOwner,
7656
7638
  spatialFilter,
7657
7639
  othersThreshold,
7658
- orderBy = "frequency_desc",
7659
7640
  rawResult
7660
7641
  }) {
7661
7642
  const filteredFeatures = this._getFilteredFeatures(
@@ -7673,8 +7654,7 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
7673
7654
  joinOperation,
7674
7655
  keysColumn: column,
7675
7656
  operation: operation2,
7676
- othersThreshold,
7677
- orderBy
7657
+ othersThreshold
7678
7658
  });
7679
7659
  if (rawResult) {
7680
7660
  return result;
@@ -8409,7 +8389,8 @@ var query = async function(options) {
8409
8389
  localCache,
8410
8390
  connectionName,
8411
8391
  sqlQuery,
8412
- queryParameters
8392
+ queryParameters,
8393
+ internalParameters
8413
8394
  } = options;
8414
8395
  const urlParameters = { q: sqlQuery };
8415
8396
  if (queryParameters) {
@@ -8420,7 +8401,12 @@ var query = async function(options) {
8420
8401
  Authorization: `Bearer ${options.accessToken}`,
8421
8402
  ...options.headers
8422
8403
  };
8423
- const parameters = { client: clientId, ...urlParameters };
8404
+ const parameters = {
8405
+ client: clientId,
8406
+ ...options.tags,
8407
+ ...internalParameters,
8408
+ ...urlParameters
8409
+ };
8424
8410
  const errorContext = {
8425
8411
  requestType: "SQL",
8426
8412
  connection: options.connectionName,
@@ -8433,7 +8419,8 @@ var query = async function(options) {
8433
8419
  headers,
8434
8420
  errorContext,
8435
8421
  maxLengthURL,
8436
- localCache
8422
+ localCache,
8423
+ signal: options.signal
8437
8424
  });
8438
8425
  };
8439
8426
 
@@ -10529,7 +10516,6 @@ function hashBuckets(initialCount) {
10529
10516
  getLayerProps,
10530
10517
  getMaxMarkerSize,
10531
10518
  getSizeAccessor,
10532
- getSorter,
10533
10519
  getSpatialIndexFromGeoColumn,
10534
10520
  getTextAccessor,
10535
10521
  groupValuesByColumn,