@carto/api-client 0.5.0-alpha.14 → 0.5.0-alpha.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/build/worker.js CHANGED
@@ -1,81 +1,7 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __commonJS = (cb, mod2) => function __require() {
9
- return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
25
- mod2
26
- ));
27
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
4
 
29
- // node_modules/thenby/thenBy.module.js
30
- var require_thenBy_module = __commonJS({
31
- "node_modules/thenby/thenBy.module.js"(exports, module) {
32
- "use strict";
33
- module.exports = function() {
34
- function identity(v) {
35
- return v;
36
- }
37
- function ignoreCase(v) {
38
- return typeof v === "string" ? v.toLowerCase() : v;
39
- }
40
- function makeCompareFunction(f, opt) {
41
- opt = typeof opt === "object" ? opt : { direction: opt };
42
- if (typeof f != "function") {
43
- var prop = f;
44
- f = function(v1) {
45
- return !!v1[prop] ? v1[prop] : "";
46
- };
47
- }
48
- if (f.length === 1) {
49
- var uf = f;
50
- var preprocess = opt.ignoreCase ? ignoreCase : identity;
51
- var cmp = opt.cmp || function(v1, v2) {
52
- return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;
53
- };
54
- f = function(v1, v2) {
55
- return cmp(preprocess(uf(v1)), preprocess(uf(v2)));
56
- };
57
- }
58
- const descTokens = { "-1": "", desc: "" };
59
- if (opt.direction in descTokens) return function(v1, v2) {
60
- return -f(v1, v2);
61
- };
62
- return f;
63
- }
64
- function tb(func, opt) {
65
- var x = typeof this == "function" && !this.firstBy ? this : false;
66
- var y = makeCompareFunction(func, opt);
67
- var f = x ? function(a, b) {
68
- return x(a, b) || y(a, b);
69
- } : y;
70
- f.thenBy = tb;
71
- return f;
72
- }
73
- tb.firstBy = tb;
74
- return tb;
75
- }();
76
- }
77
- });
78
-
79
5
  // src/constants.ts
80
6
  var FilterType = /* @__PURE__ */ ((FilterType2) => {
81
7
  FilterType2["IN"] = "in";
@@ -86,6 +12,10 @@ var FilterType = /* @__PURE__ */ ((FilterType2) => {
86
12
  return FilterType2;
87
13
  })(FilterType || {});
88
14
  var DEFAULT_API_BASE_URL = "https://gcp-us-east1.api.carto.com";
15
+ var SpatialIndexColumn = Object.freeze({
16
+ ["h3" /* H3 */]: ["h3", "hex", "h3id", "hex_id", "h3hex"],
17
+ ["quadbin" /* QUADBIN */]: ["quadbin"]
18
+ });
89
19
 
90
20
  // src/utils.ts
91
21
  var FILTER_TYPES = new Set(Object.values(FilterType));
@@ -804,8 +734,8 @@ function getSpatialIndex(spatialDataType) {
804
734
 
805
735
  // src/constants-internal.ts
806
736
  var DEFAULT_GEO_COLUMN = "geom";
807
- var DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
808
- var DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
737
+ var DEFAULT_AGGREGATION_EXP_ALIAS = "__aggregationValue";
738
+ var DEFAULT_AGGREGATION_EXP = `1 AS ${DEFAULT_AGGREGATION_EXP_ALIAS}`;
809
739
 
810
740
  // src/filters/tileFeaturesRaster.ts
811
741
  import {
@@ -991,8 +921,53 @@ function normalizeKeys(keys) {
991
921
  return Array.isArray(keys) ? keys : typeof keys === "string" ? [keys] : void 0;
992
922
  }
993
923
 
924
+ // src/vendor/thenby.ts
925
+ var firstBy = function() {
926
+ function identity(v) {
927
+ return v;
928
+ }
929
+ function ignoreCase(v) {
930
+ return typeof v === "string" ? v.toLowerCase() : v;
931
+ }
932
+ function makeCompareFunction(f, opt) {
933
+ opt = typeof opt === "object" ? opt : { direction: opt };
934
+ if (typeof f != "function") {
935
+ const prop = f;
936
+ f = function(v1) {
937
+ return v1[prop] ? v1[prop] : "";
938
+ };
939
+ }
940
+ if (f.length === 1) {
941
+ const uf = f;
942
+ const preprocess = opt.ignoreCase ? ignoreCase : identity;
943
+ const cmp = opt.cmp || function(v1, v2) {
944
+ return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;
945
+ };
946
+ f = function(v1, v2) {
947
+ return cmp(preprocess(uf(v1)), preprocess(uf(v2)));
948
+ };
949
+ }
950
+ const descTokens = { "-1": "", desc: "" };
951
+ if (opt.direction in descTokens)
952
+ return function(v1, v2) {
953
+ return -f(v1, v2);
954
+ };
955
+ return f;
956
+ }
957
+ function tb(func, opt) {
958
+ const x = typeof this == "function" && !this.firstBy ? this : false;
959
+ const y = makeCompareFunction(func, opt);
960
+ const f = x ? function(a, b) {
961
+ return x(a, b) || y(a, b);
962
+ } : y;
963
+ f.thenBy = tb;
964
+ return f;
965
+ }
966
+ tb.firstBy = tb;
967
+ return tb;
968
+ }();
969
+
994
970
  // src/operations/applySorting.ts
995
- var import_thenby = __toESM(require_thenBy_module(), 1);
996
971
  function applySorting(features, {
997
972
  sortBy,
998
973
  sortByDirection = "asc",
@@ -1023,7 +998,7 @@ function createSortFn({
1023
998
  sortByDirection,
1024
999
  sortByColumnType
1025
1000
  });
1026
- let sortFn = (0, import_thenby.firstBy)(...firstSortOption);
1001
+ let sortFn = firstBy(...firstSortOption);
1027
1002
  for (const sortOptions of othersSortOptions) {
1028
1003
  sortFn = sortFn.thenBy(...sortOptions);
1029
1004
  }
@@ -1258,77 +1233,16 @@ function getClient() {
1258
1233
  return client;
1259
1234
  }
1260
1235
 
1261
- // src/spatial-index.ts
1262
- var DEFAULT_TILE_SIZE = 512;
1263
- var QUADBIN_ZOOM_MAX_OFFSET = 4;
1264
- function getSpatialFiltersResolution(source2, viewState) {
1265
- const dataResolution = source2.dataResolution ?? Number.MAX_VALUE;
1266
- const aggregationResLevel = source2.aggregationResLevel ?? (source2.spatialDataType === "h3" ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN);
1267
- const aggregationResLevelOffset = Math.max(
1268
- 0,
1269
- Math.floor(aggregationResLevel)
1270
- );
1271
- const currentZoomInt = Math.ceil(viewState.zoom);
1272
- if (source2.spatialDataType === "h3") {
1273
- const tileSize = DEFAULT_TILE_SIZE;
1274
- const maxResolutionForZoom = maxH3SpatialFiltersResolutions.find(
1275
- ([zoom]) => zoom === currentZoomInt
1276
- )?.[1] ?? Math.max(0, currentZoomInt - 3);
1277
- const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
1278
- const hexagonResolution = _getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
1279
- return Math.min(hexagonResolution, maxSpatialFiltersResolution);
1280
- }
1281
- if (source2.spatialDataType === "quadbin") {
1282
- const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
1283
- const maxSpatialFiltersResolution = Math.min(
1284
- dataResolution,
1285
- maxResolutionForZoom
1286
- );
1287
- const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
1288
- return Math.min(quadsResolution, maxSpatialFiltersResolution);
1289
- }
1290
- return void 0;
1291
- }
1292
- var maxH3SpatialFiltersResolutions = [
1293
- [20, 14],
1294
- [19, 13],
1295
- [18, 12],
1296
- [17, 11],
1297
- [16, 10],
1298
- [15, 9],
1299
- [14, 8],
1300
- [13, 7],
1301
- [12, 7],
1302
- [11, 7],
1303
- [10, 6],
1304
- [9, 6],
1305
- [8, 5],
1306
- [7, 4],
1307
- [6, 4],
1308
- [5, 3],
1309
- [4, 2],
1310
- [3, 1],
1311
- [2, 1],
1312
- [1, 0]
1313
- ];
1314
- var BIAS = 2;
1315
- function _getHexagonResolution(viewport, tileSize) {
1316
- const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
1317
- const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
1318
- const latitudeScaleFactor = Math.log(
1319
- 1 / Math.cos(Math.PI * viewport.latitude / 180)
1320
- );
1321
- return Math.max(
1322
- 0,
1323
- Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
1324
- );
1325
- }
1326
-
1327
1236
  // src/widget-sources/widget-source.ts
1328
1237
  var _WidgetSource = class _WidgetSource {
1329
1238
  constructor(props) {
1330
1239
  __publicField(this, "props");
1331
- this.props = { ..._WidgetSource.defaultProps, ...props };
1240
+ this.props = {
1241
+ ..._WidgetSource.defaultProps,
1242
+ clientId: getClient(),
1243
+ // Refresh clientId, default may have changed.
1244
+ ...props
1245
+ };
1332
1246
  }
1333
1247
  /**
1334
1248
  * Destroys the widget source and releases allocated resources.
@@ -1339,17 +1253,6 @@ var _WidgetSource = class _WidgetSource {
1339
1253
  */
1340
1254
  destroy() {
1341
1255
  }
1342
- _getSpatialFiltersResolution(source2, spatialFilter, referenceViewState) {
1343
- if (!spatialFilter || source2.spatialDataType === "geo") {
1344
- return;
1345
- }
1346
- if (!referenceViewState) {
1347
- throw new Error(
1348
- 'Missing required option, "spatialIndexReferenceViewState".'
1349
- );
1350
- }
1351
- return getSpatialFiltersResolution(source2, referenceViewState);
1352
- }
1353
1256
  };
1354
1257
  __publicField(_WidgetSource, "defaultProps", {
1355
1258
  apiVersion: "v3" /* V3 */,