@carto/api-client 0.4.0-alpha.1 → 0.4.0-alpha.4

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 (40) hide show
  1. package/build/api-client.cjs +106 -184
  2. package/build/api-client.cjs.map +1 -1
  3. package/build/api-client.modern.js +97 -144
  4. package/build/api-client.modern.js.map +1 -1
  5. package/build/constants-internal.d.ts +11 -3
  6. package/build/constants.d.ts +0 -18
  7. package/build/index.d.ts +1 -1
  8. package/build/models/common.d.ts +7 -2
  9. package/build/sources/h3-query-source.d.ts +2 -1
  10. package/build/sources/h3-table-source.d.ts +2 -1
  11. package/build/sources/quadbin-query-source.d.ts +2 -1
  12. package/build/sources/quadbin-table-source.d.ts +2 -1
  13. package/build/sources/vector-query-source.d.ts +2 -1
  14. package/build/sources/vector-table-source.d.ts +2 -1
  15. package/build/widget-sources/index.d.ts +0 -1
  16. package/build/widget-sources/widget-query-source.d.ts +3 -0
  17. package/build/widget-sources/widget-table-source.d.ts +3 -0
  18. package/package.json +1 -1
  19. package/src/api/request-with-parameters.ts +3 -2
  20. package/src/client.ts +2 -2
  21. package/src/constants-internal.ts +14 -3
  22. package/src/constants.ts +0 -25
  23. package/src/index.ts +17 -7
  24. package/src/models/common.ts +11 -3
  25. package/src/models/model.ts +1 -1
  26. package/src/sources/base-source.ts +3 -3
  27. package/src/sources/h3-query-source.ts +8 -6
  28. package/src/sources/h3-table-source.ts +8 -6
  29. package/src/sources/quadbin-query-source.ts +8 -6
  30. package/src/sources/quadbin-table-source.ts +8 -6
  31. package/src/sources/vector-query-source.ts +12 -7
  32. package/src/sources/vector-table-source.ts +12 -7
  33. package/src/types.ts +0 -1
  34. package/src/utils.ts +1 -2
  35. package/src/widget-sources/index.ts +0 -1
  36. package/src/widget-sources/widget-base-source.ts +2 -2
  37. package/src/widget-sources/widget-query-source.ts +2 -0
  38. package/src/widget-sources/widget-table-source.ts +2 -0
  39. package/build/widget-sources/wrappers.d.ts +0 -48
  40. package/src/widget-sources/wrappers.ts +0 -120
@@ -12,9 +12,9 @@ var union__default = /*#__PURE__*/_interopDefaultLegacy(union);
12
12
 
13
13
  /**
14
14
  * @internal
15
- * @internalRemarks Source: @carto/react-core
15
+ * @internalRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
16
16
  */
17
- let client = 'carto-api-client';
17
+ let client = 'deck-gl-carto';
18
18
  /**
19
19
  * Returns current client ID, used to categorize API requests. For internal use only.
20
20
  *
@@ -65,24 +65,6 @@ exports.ApiVersion = void 0;
65
65
  ApiVersion["V2"] = "v2";
66
66
  ApiVersion["V3"] = "v3";
67
67
  })(exports.ApiVersion || (exports.ApiVersion = {}));
68
- /******************************************************************************
69
- * DEFAULTS
70
- */
71
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
72
- const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
73
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
74
- const DEFAULT_CLIENT = 'deck-gl-carto';
75
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
76
- const DEFAULT_GEO_COLUMN = 'geom';
77
- /**
78
- * Fastly default limit is 8192; leave some padding.
79
- * @internalRemarks Source: @deck.gl/carto
80
- */
81
- const DEFAULT_MAX_LENGTH_URL = 7000;
82
- /** @internalRemarks Source: @deck.gl/carto */
83
- const DEFAULT_TILE_SIZE = 512;
84
- /** @internalRemarks Source: @deck.gl/carto */
85
- const DEFAULT_TILE_RESOLUTION = 0.5;
86
68
 
87
69
  const FILTER_TYPES = new Set(Object.values(exports.FilterType));
88
70
  const isFilterType = type => FILTER_TYPES.has(type);
@@ -371,6 +353,30 @@ function _isMultiPolygon(geometry) {
371
353
  return invariant.getType(geometry) === 'MultiPolygon';
372
354
  }
373
355
 
356
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
357
+ const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
358
+ /** @internal */
359
+ const V3_MINOR_VERSION = '3.4';
360
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
361
+ const DEFAULT_GEO_COLUMN = 'geom';
362
+ /**
363
+ * Fastly default limit is 8192; leave some padding.
364
+ * @internalRemarks Source: @deck.gl/carto
365
+ */
366
+ const DEFAULT_MAX_LENGTH_URL = 7000;
367
+ /** @internalRemarks Source: @deck.gl/carto */
368
+ const DEFAULT_TILE_RESOLUTION = 0.5;
369
+ /**
370
+ * @internalRemarks Source: @deck.gl/carto
371
+ * @internal
372
+ */
373
+ const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
374
+ /**
375
+ * @internalRemarks Source: @deck.gl/carto
376
+ * @internal
377
+ */
378
+ const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
379
+
374
380
  /**
375
381
  * Return more descriptive error from API
376
382
  * @internalRemarks Source: @carto/react-api
@@ -447,7 +453,7 @@ function dealWithApiError(_ref) {
447
453
  if (data.error === 'Column not found') {
448
454
  throw new InvalidColumnError(`${data.error} ${data.column_name}`);
449
455
  }
450
- if (data.error?.includes('Missing columns')) {
456
+ if (typeof data.error === 'string' && data.error?.includes('Missing columns')) {
451
457
  throw new InvalidColumnError(data.error);
452
458
  }
453
459
  switch (response.status) {
@@ -970,54 +976,6 @@ class WidgetTableSource extends WidgetBaseSource {
970
976
  }
971
977
  }
972
978
 
973
- // deck.gl
974
- // SPDX-License-Identifier: MIT
975
- // Copyright (c) vis.gl contributors
976
- function joinPath() {
977
- return [].slice.call(arguments).map(part => part.endsWith('/') ? part.slice(0, -1) : part).join('/');
978
- }
979
- function buildV3Path(apiBaseUrl, version, endpoint) {
980
- return joinPath(apiBaseUrl, version, endpoint, ...[].slice.call(arguments, 3));
981
- }
982
- /** @internal Required by fetchMap(). */
983
- function buildPublicMapUrl(_ref) {
984
- let {
985
- apiBaseUrl,
986
- cartoMapId
987
- } = _ref;
988
- return buildV3Path(apiBaseUrl, 'v3', 'maps', 'public', cartoMapId);
989
- }
990
- /** @internal Required by fetchMap(). */
991
- function buildStatsUrl(_ref2) {
992
- let {
993
- attribute,
994
- apiBaseUrl,
995
- connectionName,
996
- source,
997
- type
998
- } = _ref2;
999
- if (type === 'query') {
1000
- return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, attribute);
1001
- }
1002
- // type === 'table'
1003
- return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, source, attribute);
1004
- }
1005
- function buildSourceUrl(_ref3) {
1006
- let {
1007
- apiBaseUrl,
1008
- connectionName,
1009
- endpoint
1010
- } = _ref3;
1011
- return buildV3Path(apiBaseUrl, 'v3', 'maps', connectionName, endpoint);
1012
- }
1013
- function buildQueryUrl(_ref4) {
1014
- let {
1015
- apiBaseUrl,
1016
- connectionName
1017
- } = _ref4;
1018
- return buildV3Path(apiBaseUrl, 'v3', 'sql', connectionName, 'query');
1019
- }
1020
-
1021
979
  // deck.gl
1022
980
  // SPDX-License-Identifier: MIT
1023
981
  // Copyright (c) vis.gl contributors
@@ -1074,21 +1032,53 @@ function formatErrorKey(key) {
1074
1032
  return key.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());
1075
1033
  }
1076
1034
 
1077
- /******************************************************************************
1078
- * VERSIONS
1079
- */
1080
- /** @internal */
1081
- const V3_MINOR_VERSION = '3.4';
1082
- /**
1083
- * @internalRemarks Source: @deck.gl/carto
1084
- * @internal
1085
- */
1086
- const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
1087
- /**
1088
- * @internalRemarks Source: @deck.gl/carto
1089
- * @internal
1090
- */
1091
- const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
1035
+ // deck.gl
1036
+ // SPDX-License-Identifier: MIT
1037
+ // Copyright (c) vis.gl contributors
1038
+ function joinPath() {
1039
+ return [].slice.call(arguments).map(part => part.endsWith('/') ? part.slice(0, -1) : part).join('/');
1040
+ }
1041
+ function buildV3Path(apiBaseUrl, version, endpoint) {
1042
+ return joinPath(apiBaseUrl, version, endpoint, ...[].slice.call(arguments, 3));
1043
+ }
1044
+ /** @internal Required by fetchMap(). */
1045
+ function buildPublicMapUrl(_ref) {
1046
+ let {
1047
+ apiBaseUrl,
1048
+ cartoMapId
1049
+ } = _ref;
1050
+ return buildV3Path(apiBaseUrl, 'v3', 'maps', 'public', cartoMapId);
1051
+ }
1052
+ /** @internal Required by fetchMap(). */
1053
+ function buildStatsUrl(_ref2) {
1054
+ let {
1055
+ attribute,
1056
+ apiBaseUrl,
1057
+ connectionName,
1058
+ source,
1059
+ type
1060
+ } = _ref2;
1061
+ if (type === 'query') {
1062
+ return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, attribute);
1063
+ }
1064
+ // type === 'table'
1065
+ return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, source, attribute);
1066
+ }
1067
+ function buildSourceUrl(_ref3) {
1068
+ let {
1069
+ apiBaseUrl,
1070
+ connectionName,
1071
+ endpoint
1072
+ } = _ref3;
1073
+ return buildV3Path(apiBaseUrl, 'v3', 'maps', connectionName, endpoint);
1074
+ }
1075
+ function buildQueryUrl(_ref4) {
1076
+ let {
1077
+ apiBaseUrl,
1078
+ connectionName
1079
+ } = _ref4;
1080
+ return buildV3Path(apiBaseUrl, 'v3', 'sql', connectionName, 'query');
1081
+ }
1092
1082
 
1093
1083
  // deck.gl
1094
1084
  const requestWithParameters = function (_ref) {
@@ -1105,7 +1095,7 @@ const requestWithParameters = function (_ref) {
1105
1095
  // user-provided parameters.
1106
1096
  parameters = {
1107
1097
  v: V3_MINOR_VERSION,
1108
- clientId: DEFAULT_CLIENT,
1098
+ client: getClient(),
1109
1099
  ...(typeof deck !== 'undefined' && deck.VERSION && {
1110
1100
  deckglVersion: deck.VERSION
1111
1101
  }),
@@ -1286,7 +1276,7 @@ const baseSource = function (endpoint, options, urlParameters) {
1286
1276
  };
1287
1277
  const SOURCE_DEFAULTS = {
1288
1278
  apiBaseUrl: DEFAULT_API_BASE_URL,
1289
- clientId: DEFAULT_CLIENT,
1279
+ clientId: getClient(),
1290
1280
  format: 'tilejson',
1291
1281
  headers: {},
1292
1282
  maxLengthURL: DEFAULT_MAX_LENGTH_URL
@@ -1347,7 +1337,7 @@ const boundaryTableSource = function (options) {
1347
1337
  };
1348
1338
 
1349
1339
  // deck.gl
1350
- const h3QuerySource$1 = function (options) {
1340
+ const h3QuerySource = function (options) {
1351
1341
  try {
1352
1342
  const {
1353
1343
  aggregationExp,
@@ -1372,14 +1362,17 @@ const h3QuerySource$1 = function (options) {
1372
1362
  if (filters) {
1373
1363
  urlParameters.filters = filters;
1374
1364
  }
1375
- return Promise.resolve(baseSource('query', options, urlParameters));
1365
+ return Promise.resolve(baseSource('query', options, urlParameters).then(result => ({
1366
+ ...result,
1367
+ widgetSource: new WidgetQuerySource(options)
1368
+ })));
1376
1369
  } catch (e) {
1377
1370
  return Promise.reject(e);
1378
1371
  }
1379
1372
  };
1380
1373
 
1381
1374
  // deck.gl
1382
- const h3TableSource$1 = function (options) {
1375
+ const h3TableSource = function (options) {
1383
1376
  try {
1384
1377
  const {
1385
1378
  aggregationExp,
@@ -1400,7 +1393,10 @@ const h3TableSource$1 = function (options) {
1400
1393
  if (filters) {
1401
1394
  urlParameters.filters = filters;
1402
1395
  }
1403
- return Promise.resolve(baseSource('table', options, urlParameters));
1396
+ return Promise.resolve(baseSource('table', options, urlParameters).then(result => ({
1397
+ ...result,
1398
+ widgetSource: new WidgetTableSource(options)
1399
+ })));
1404
1400
  } catch (e) {
1405
1401
  return Promise.reject(e);
1406
1402
  }
@@ -1441,7 +1437,7 @@ const rasterSource = function (options) {
1441
1437
  };
1442
1438
 
1443
1439
  // deck.gl
1444
- const quadbinQuerySource$1 = function (options) {
1440
+ const quadbinQuerySource = function (options) {
1445
1441
  try {
1446
1442
  const {
1447
1443
  aggregationExp,
@@ -1466,14 +1462,17 @@ const quadbinQuerySource$1 = function (options) {
1466
1462
  if (filters) {
1467
1463
  urlParameters.filters = filters;
1468
1464
  }
1469
- return Promise.resolve(baseSource('query', options, urlParameters));
1465
+ return Promise.resolve(baseSource('query', options, urlParameters).then(result => ({
1466
+ ...result,
1467
+ widgetSource: new WidgetQuerySource(options)
1468
+ })));
1470
1469
  } catch (e) {
1471
1470
  return Promise.reject(e);
1472
1471
  }
1473
1472
  };
1474
1473
 
1475
1474
  // deck.gl
1476
- const quadbinTableSource$1 = function (options) {
1475
+ const quadbinTableSource = function (options) {
1477
1476
  try {
1478
1477
  const {
1479
1478
  aggregationExp,
@@ -1494,7 +1493,10 @@ const quadbinTableSource$1 = function (options) {
1494
1493
  if (filters) {
1495
1494
  urlParameters.filters = filters;
1496
1495
  }
1497
- return Promise.resolve(baseSource('table', options, urlParameters));
1496
+ return Promise.resolve(baseSource('table', options, urlParameters).then(result => ({
1497
+ ...result,
1498
+ widgetSource: new WidgetTableSource(options)
1499
+ })));
1498
1500
  } catch (e) {
1499
1501
  return Promise.reject(e);
1500
1502
  }
@@ -1516,7 +1518,7 @@ const quadbinTilesetSource = function (options) {
1516
1518
  };
1517
1519
 
1518
1520
  // deck.gl
1519
- const vectorQuerySource$1 = function (options) {
1521
+ const vectorQuerySource = function (options) {
1520
1522
  try {
1521
1523
  const {
1522
1524
  columns,
@@ -1541,14 +1543,17 @@ const vectorQuerySource$1 = function (options) {
1541
1543
  if (queryParameters) {
1542
1544
  urlParameters.queryParameters = queryParameters;
1543
1545
  }
1544
- return Promise.resolve(baseSource('query', options, urlParameters));
1546
+ return Promise.resolve(baseSource('query', options, urlParameters).then(result => ({
1547
+ ...result,
1548
+ widgetSource: new WidgetQuerySource(options)
1549
+ })));
1545
1550
  } catch (e) {
1546
1551
  return Promise.reject(e);
1547
1552
  }
1548
1553
  };
1549
1554
 
1550
1555
  // deck.gl
1551
- const vectorTableSource$1 = function (options) {
1556
+ const vectorTableSource = function (options) {
1552
1557
  try {
1553
1558
  const {
1554
1559
  columns,
@@ -1569,7 +1574,10 @@ const vectorTableSource$1 = function (options) {
1569
1574
  if (filters) {
1570
1575
  urlParameters.filters = filters;
1571
1576
  }
1572
- return Promise.resolve(baseSource('table', options, urlParameters));
1577
+ return Promise.resolve(baseSource('table', options, urlParameters).then(result => ({
1578
+ ...result,
1579
+ widgetSource: new WidgetTableSource(options)
1580
+ })));
1573
1581
  } catch (e) {
1574
1582
  return Promise.reject(e);
1575
1583
  }
@@ -1590,86 +1598,6 @@ const vectorTilesetSource = function (options) {
1590
1598
  }
1591
1599
  };
1592
1600
 
1593
- /** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
1594
-
1595
- /** Wrapper adding Widget API support to [quadbinQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
1596
- const quadbinQuerySource = function (props) {
1597
- try {
1598
- return Promise.resolve(quadbinQuerySource$1(props)).then(function (response) {
1599
- return {
1600
- ...response,
1601
- widgetSource: new WidgetQuerySource(props)
1602
- };
1603
- });
1604
- } catch (e) {
1605
- return Promise.reject(e);
1606
- }
1607
- };
1608
- /** Wrapper adding Widget API support to [quadbinTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
1609
- const quadbinTableSource = function (props) {
1610
- try {
1611
- return Promise.resolve(quadbinTableSource$1(props)).then(function (response) {
1612
- return {
1613
- ...response,
1614
- widgetSource: new WidgetTableSource(props)
1615
- };
1616
- });
1617
- } catch (e) {
1618
- return Promise.reject(e);
1619
- }
1620
- };
1621
- /** Wrapper adding Widget API support to [h3QuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
1622
- const h3QuerySource = function (props) {
1623
- try {
1624
- return Promise.resolve(h3QuerySource$1(props)).then(function (response) {
1625
- return {
1626
- ...response,
1627
- widgetSource: new WidgetQuerySource(props)
1628
- };
1629
- });
1630
- } catch (e) {
1631
- return Promise.reject(e);
1632
- }
1633
- };
1634
- /** Wrapper adding Widget API support to [h3TableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
1635
- const h3TableSource = function (props) {
1636
- try {
1637
- return Promise.resolve(h3TableSource$1(props)).then(function (response) {
1638
- return {
1639
- ...response,
1640
- widgetSource: new WidgetTableSource(props)
1641
- };
1642
- });
1643
- } catch (e) {
1644
- return Promise.reject(e);
1645
- }
1646
- };
1647
- /** Wrapper adding Widget API support to [vectorQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
1648
- const vectorQuerySource = function (props) {
1649
- try {
1650
- return Promise.resolve(vectorQuerySource$1(props)).then(function (response) {
1651
- return {
1652
- ...response,
1653
- widgetSource: new WidgetQuerySource(props)
1654
- };
1655
- });
1656
- } catch (e) {
1657
- return Promise.reject(e);
1658
- }
1659
- };
1660
- const vectorTableSource = function (props) {
1661
- try {
1662
- return Promise.resolve(vectorTableSource$1(props)).then(function (response) {
1663
- return {
1664
- ...response,
1665
- widgetSource: new WidgetTableSource(props)
1666
- };
1667
- });
1668
- } catch (e) {
1669
- return Promise.reject(e);
1670
- }
1671
- };
1672
-
1673
1601
  // deck.gl
1674
1602
  const query = function (options) {
1675
1603
  try {
@@ -1718,12 +1646,6 @@ const query = function (options) {
1718
1646
  };
1719
1647
 
1720
1648
  exports.CartoAPIError = CartoAPIError;
1721
- exports.DEFAULT_API_BASE_URL = DEFAULT_API_BASE_URL;
1722
- exports.DEFAULT_CLIENT = DEFAULT_CLIENT;
1723
- exports.DEFAULT_GEO_COLUMN = DEFAULT_GEO_COLUMN;
1724
- exports.DEFAULT_MAX_LENGTH_URL = DEFAULT_MAX_LENGTH_URL;
1725
- exports.DEFAULT_TILE_RESOLUTION = DEFAULT_TILE_RESOLUTION;
1726
- exports.DEFAULT_TILE_SIZE = DEFAULT_TILE_SIZE;
1727
1649
  exports.SOURCE_DEFAULTS = SOURCE_DEFAULTS;
1728
1650
  exports.WidgetBaseSource = WidgetBaseSource;
1729
1651
  exports.WidgetQuerySource = WidgetQuerySource;