@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
@@ -6,9 +6,9 @@ import { featureCollection, feature, polygon, multiPolygon } from '@turf/helpers
6
6
 
7
7
  /**
8
8
  * @internal
9
- * @internalRemarks Source: @carto/react-core
9
+ * @internalRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
10
10
  */
11
- let client = 'carto-api-client';
11
+ let client = 'deck-gl-carto';
12
12
  /**
13
13
  * Returns current client ID, used to categorize API requests. For internal use only.
14
14
  *
@@ -59,24 +59,6 @@ var ApiVersion;
59
59
  ApiVersion["V2"] = "v2";
60
60
  ApiVersion["V3"] = "v3";
61
61
  })(ApiVersion || (ApiVersion = {}));
62
- /******************************************************************************
63
- * DEFAULTS
64
- */
65
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
66
- const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
67
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
68
- const DEFAULT_CLIENT = 'deck-gl-carto';
69
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
70
- const DEFAULT_GEO_COLUMN = 'geom';
71
- /**
72
- * Fastly default limit is 8192; leave some padding.
73
- * @internalRemarks Source: @deck.gl/carto
74
- */
75
- const DEFAULT_MAX_LENGTH_URL = 7000;
76
- /** @internalRemarks Source: @deck.gl/carto */
77
- const DEFAULT_TILE_SIZE = 512;
78
- /** @internalRemarks Source: @deck.gl/carto */
79
- const DEFAULT_TILE_RESOLUTION = 0.5;
80
62
 
81
63
  const FILTER_TYPES = new Set(Object.values(FilterType));
82
64
  const isFilterType = type => FILTER_TYPES.has(type);
@@ -383,6 +365,30 @@ function _objectWithoutPropertiesLoose(r, e) {
383
365
  return t;
384
366
  }
385
367
 
368
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
369
+ const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
370
+ /** @internal */
371
+ const V3_MINOR_VERSION = '3.4';
372
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
373
+ const DEFAULT_GEO_COLUMN = 'geom';
374
+ /**
375
+ * Fastly default limit is 8192; leave some padding.
376
+ * @internalRemarks Source: @deck.gl/carto
377
+ */
378
+ const DEFAULT_MAX_LENGTH_URL = 7000;
379
+ /** @internalRemarks Source: @deck.gl/carto */
380
+ const DEFAULT_TILE_RESOLUTION = 0.5;
381
+ /**
382
+ * @internalRemarks Source: @deck.gl/carto
383
+ * @internal
384
+ */
385
+ const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
386
+ /**
387
+ * @internalRemarks Source: @deck.gl/carto
388
+ * @internal
389
+ */
390
+ const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
391
+
386
392
  /**
387
393
  * Return more descriptive error from API
388
394
  * @internalRemarks Source: @carto/react-api
@@ -395,7 +401,7 @@ function dealWithApiError({
395
401
  if (data.error === 'Column not found') {
396
402
  throw new InvalidColumnError(`${data.error} ${data.column_name}`);
397
403
  }
398
- if ((_data$error = data.error) != null && _data$error.includes('Missing columns')) {
404
+ if (typeof data.error === 'string' && (_data$error = data.error) != null && _data$error.includes('Missing columns')) {
399
405
  throw new InvalidColumnError(data.error);
400
406
  }
401
407
  switch (response.status) {
@@ -911,50 +917,6 @@ class WidgetTableSource extends WidgetBaseSource {
911
917
  }
912
918
  }
913
919
 
914
- // deck.gl
915
- // SPDX-License-Identifier: MIT
916
- // Copyright (c) vis.gl contributors
917
- function joinPath(...args) {
918
- return args.map(part => part.endsWith('/') ? part.slice(0, -1) : part).join('/');
919
- }
920
- function buildV3Path(apiBaseUrl, version, endpoint, ...rest) {
921
- return joinPath(apiBaseUrl, version, endpoint, ...rest);
922
- }
923
- /** @internal Required by fetchMap(). */
924
- function buildPublicMapUrl({
925
- apiBaseUrl,
926
- cartoMapId
927
- }) {
928
- return buildV3Path(apiBaseUrl, 'v3', 'maps', 'public', cartoMapId);
929
- }
930
- /** @internal Required by fetchMap(). */
931
- function buildStatsUrl({
932
- attribute,
933
- apiBaseUrl,
934
- connectionName,
935
- source,
936
- type
937
- }) {
938
- if (type === 'query') {
939
- return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, attribute);
940
- }
941
- // type === 'table'
942
- return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, source, attribute);
943
- }
944
- function buildSourceUrl({
945
- apiBaseUrl,
946
- connectionName,
947
- endpoint
948
- }) {
949
- return buildV3Path(apiBaseUrl, 'v3', 'maps', connectionName, endpoint);
950
- }
951
- function buildQueryUrl({
952
- apiBaseUrl,
953
- connectionName
954
- }) {
955
- return buildV3Path(apiBaseUrl, 'v3', 'sql', connectionName, 'query');
956
- }
957
-
958
920
  // deck.gl
959
921
  // SPDX-License-Identifier: MIT
960
922
  // Copyright (c) vis.gl contributors
@@ -1011,21 +973,49 @@ function formatErrorKey(key) {
1011
973
  return key.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());
1012
974
  }
1013
975
 
1014
- /******************************************************************************
1015
- * VERSIONS
1016
- */
1017
- /** @internal */
1018
- const V3_MINOR_VERSION = '3.4';
1019
- /**
1020
- * @internalRemarks Source: @deck.gl/carto
1021
- * @internal
1022
- */
1023
- const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
1024
- /**
1025
- * @internalRemarks Source: @deck.gl/carto
1026
- * @internal
1027
- */
1028
- const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
976
+ // deck.gl
977
+ // SPDX-License-Identifier: MIT
978
+ // Copyright (c) vis.gl contributors
979
+ function joinPath(...args) {
980
+ return args.map(part => part.endsWith('/') ? part.slice(0, -1) : part).join('/');
981
+ }
982
+ function buildV3Path(apiBaseUrl, version, endpoint, ...rest) {
983
+ return joinPath(apiBaseUrl, version, endpoint, ...rest);
984
+ }
985
+ /** @internal Required by fetchMap(). */
986
+ function buildPublicMapUrl({
987
+ apiBaseUrl,
988
+ cartoMapId
989
+ }) {
990
+ return buildV3Path(apiBaseUrl, 'v3', 'maps', 'public', cartoMapId);
991
+ }
992
+ /** @internal Required by fetchMap(). */
993
+ function buildStatsUrl({
994
+ attribute,
995
+ apiBaseUrl,
996
+ connectionName,
997
+ source,
998
+ type
999
+ }) {
1000
+ if (type === 'query') {
1001
+ return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, attribute);
1002
+ }
1003
+ // type === 'table'
1004
+ return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, source, attribute);
1005
+ }
1006
+ function buildSourceUrl({
1007
+ apiBaseUrl,
1008
+ connectionName,
1009
+ endpoint
1010
+ }) {
1011
+ return buildV3Path(apiBaseUrl, 'v3', 'maps', connectionName, endpoint);
1012
+ }
1013
+ function buildQueryUrl({
1014
+ apiBaseUrl,
1015
+ connectionName
1016
+ }) {
1017
+ return buildV3Path(apiBaseUrl, 'v3', 'sql', connectionName, 'query');
1018
+ }
1029
1019
 
1030
1020
  const DEFAULT_HEADERS = {
1031
1021
  Accept: 'application/json',
@@ -1044,7 +1034,7 @@ async function requestWithParameters({
1044
1034
  // user-provided parameters.
1045
1035
  parameters = _extends({
1046
1036
  v: V3_MINOR_VERSION,
1047
- clientId: DEFAULT_CLIENT
1037
+ client: getClient()
1048
1038
  }, typeof deck !== 'undefined' && deck.VERSION && {
1049
1039
  deckglVersion: deck.VERSION
1050
1040
  }, parameters);
@@ -1122,7 +1112,7 @@ function excludeURLParameters(baseUrlString, parameters) {
1122
1112
  const _excluded = ["accessToken", "connectionName", "cache"];
1123
1113
  const SOURCE_DEFAULTS = {
1124
1114
  apiBaseUrl: DEFAULT_API_BASE_URL,
1125
- clientId: DEFAULT_CLIENT,
1115
+ clientId: getClient(),
1126
1116
  format: 'tilejson',
1127
1117
  headers: {},
1128
1118
  maxLengthURL: DEFAULT_MAX_LENGTH_URL
@@ -1240,8 +1230,7 @@ const boundaryTableSource = async function boundaryTableSource(options) {
1240
1230
  return baseSource('boundary', options, urlParameters);
1241
1231
  };
1242
1232
 
1243
- // deck.gl
1244
- const h3QuerySource$1 = async function h3QuerySource(options) {
1233
+ const h3QuerySource = async function h3QuerySource(options) {
1245
1234
  const {
1246
1235
  aggregationExp,
1247
1236
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
@@ -1265,11 +1254,12 @@ const h3QuerySource$1 = async function h3QuerySource(options) {
1265
1254
  if (filters) {
1266
1255
  urlParameters.filters = filters;
1267
1256
  }
1268
- return baseSource('query', options, urlParameters);
1257
+ return baseSource('query', options, urlParameters).then(result => _extends({}, result, {
1258
+ widgetSource: new WidgetQuerySource(options)
1259
+ }));
1269
1260
  };
1270
1261
 
1271
- // deck.gl
1272
- const h3TableSource$1 = async function h3TableSource(options) {
1262
+ const h3TableSource = async function h3TableSource(options) {
1273
1263
  const {
1274
1264
  aggregationExp,
1275
1265
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
@@ -1289,7 +1279,9 @@ const h3TableSource$1 = async function h3TableSource(options) {
1289
1279
  if (filters) {
1290
1280
  urlParameters.filters = filters;
1291
1281
  }
1292
- return baseSource('table', options, urlParameters);
1282
+ return baseSource('table', options, urlParameters).then(result => _extends({}, result, {
1283
+ widgetSource: new WidgetTableSource(options)
1284
+ }));
1293
1285
  };
1294
1286
 
1295
1287
  // deck.gl
@@ -1318,8 +1310,7 @@ const rasterSource = async function rasterSource(options) {
1318
1310
  return baseSource('raster', options, urlParameters);
1319
1311
  };
1320
1312
 
1321
- // deck.gl
1322
- const quadbinQuerySource$1 = async function quadbinQuerySource(options) {
1313
+ const quadbinQuerySource = async function quadbinQuerySource(options) {
1323
1314
  const {
1324
1315
  aggregationExp,
1325
1316
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
@@ -1343,11 +1334,12 @@ const quadbinQuerySource$1 = async function quadbinQuerySource(options) {
1343
1334
  if (filters) {
1344
1335
  urlParameters.filters = filters;
1345
1336
  }
1346
- return baseSource('query', options, urlParameters);
1337
+ return baseSource('query', options, urlParameters).then(result => _extends({}, result, {
1338
+ widgetSource: new WidgetQuerySource(options)
1339
+ }));
1347
1340
  };
1348
1341
 
1349
- // deck.gl
1350
- const quadbinTableSource$1 = async function quadbinTableSource(options) {
1342
+ const quadbinTableSource = async function quadbinTableSource(options) {
1351
1343
  const {
1352
1344
  aggregationExp,
1353
1345
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
@@ -1367,7 +1359,9 @@ const quadbinTableSource$1 = async function quadbinTableSource(options) {
1367
1359
  if (filters) {
1368
1360
  urlParameters.filters = filters;
1369
1361
  }
1370
- return baseSource('table', options, urlParameters);
1362
+ return baseSource('table', options, urlParameters).then(result => _extends({}, result, {
1363
+ widgetSource: new WidgetTableSource(options)
1364
+ }));
1371
1365
  };
1372
1366
 
1373
1367
  // deck.gl
@@ -1381,8 +1375,7 @@ const quadbinTilesetSource = async function quadbinTilesetSource(options) {
1381
1375
  return baseSource('tileset', options, urlParameters);
1382
1376
  };
1383
1377
 
1384
- // deck.gl
1385
- const vectorQuerySource$1 = async function vectorQuerySource(options) {
1378
+ const vectorQuerySource = async function vectorQuerySource(options) {
1386
1379
  const {
1387
1380
  columns,
1388
1381
  filters,
@@ -1406,11 +1399,12 @@ const vectorQuerySource$1 = async function vectorQuerySource(options) {
1406
1399
  if (queryParameters) {
1407
1400
  urlParameters.queryParameters = queryParameters;
1408
1401
  }
1409
- return baseSource('query', options, urlParameters);
1402
+ return baseSource('query', options, urlParameters).then(result => _extends({}, result, {
1403
+ widgetSource: new WidgetQuerySource(options)
1404
+ }));
1410
1405
  };
1411
1406
 
1412
- // deck.gl
1413
- const vectorTableSource$1 = async function vectorTableSource(options) {
1407
+ const vectorTableSource = async function vectorTableSource(options) {
1414
1408
  const {
1415
1409
  columns,
1416
1410
  filters,
@@ -1430,7 +1424,9 @@ const vectorTableSource$1 = async function vectorTableSource(options) {
1430
1424
  if (filters) {
1431
1425
  urlParameters.filters = filters;
1432
1426
  }
1433
- return baseSource('table', options, urlParameters);
1427
+ return baseSource('table', options, urlParameters).then(result => _extends({}, result, {
1428
+ widgetSource: new WidgetTableSource(options)
1429
+ }));
1434
1430
  };
1435
1431
 
1436
1432
  // deck.gl
@@ -1444,49 +1440,6 @@ const vectorTilesetSource = async function vectorTilesetSource(options) {
1444
1440
  return baseSource('tileset', options, urlParameters);
1445
1441
  };
1446
1442
 
1447
- /** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
1448
- async function vectorTableSource(props) {
1449
- const response = await vectorTableSource$1(props);
1450
- return _extends({}, response, {
1451
- widgetSource: new WidgetTableSource(props)
1452
- });
1453
- }
1454
- /** Wrapper adding Widget API support to [vectorQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
1455
- async function vectorQuerySource(props) {
1456
- const response = await vectorQuerySource$1(props);
1457
- return _extends({}, response, {
1458
- widgetSource: new WidgetQuerySource(props)
1459
- });
1460
- }
1461
- /** Wrapper adding Widget API support to [h3TableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
1462
- async function h3TableSource(props) {
1463
- const response = await h3TableSource$1(props);
1464
- return _extends({}, response, {
1465
- widgetSource: new WidgetTableSource(props)
1466
- });
1467
- }
1468
- /** Wrapper adding Widget API support to [h3QuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
1469
- async function h3QuerySource(props) {
1470
- const response = await h3QuerySource$1(props);
1471
- return _extends({}, response, {
1472
- widgetSource: new WidgetQuerySource(props)
1473
- });
1474
- }
1475
- /** Wrapper adding Widget API support to [quadbinTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
1476
- async function quadbinTableSource(props) {
1477
- const response = await quadbinTableSource$1(props);
1478
- return _extends({}, response, {
1479
- widgetSource: new WidgetTableSource(props)
1480
- });
1481
- }
1482
- /** Wrapper adding Widget API support to [quadbinQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
1483
- async function quadbinQuerySource(props) {
1484
- const response = await quadbinQuerySource$1(props);
1485
- return _extends({}, response, {
1486
- widgetSource: new WidgetQuerySource(props)
1487
- });
1488
- }
1489
-
1490
1443
  const query = async function query(options) {
1491
1444
  const {
1492
1445
  apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl,
@@ -1527,5 +1480,5 @@ const query = async function query(options) {
1527
1480
  });
1528
1481
  };
1529
1482
 
1530
- export { ApiVersion, CartoAPIError, DEFAULT_API_BASE_URL, DEFAULT_CLIENT, DEFAULT_GEO_COLUMN, DEFAULT_MAX_LENGTH_URL, DEFAULT_TILE_RESOLUTION, DEFAULT_TILE_SIZE, FilterType, SOURCE_DEFAULTS, WidgetBaseSource, WidgetQuerySource, WidgetTableSource, addFilter, boundaryQuerySource, boundaryTableSource, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, getClient, getFilter, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, setClient, vectorQuerySource, vectorTableSource, vectorTilesetSource };
1483
+ export { ApiVersion, CartoAPIError, FilterType, SOURCE_DEFAULTS, WidgetBaseSource, WidgetQuerySource, WidgetTableSource, addFilter, boundaryQuerySource, boundaryTableSource, buildPublicMapUrl, buildStatsUrl, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, getClient, getFilter, h3QuerySource, h3TableSource, h3TilesetSource, hasFilter, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, query, rasterSource, removeFilter, requestWithParameters, setClient, vectorQuerySource, vectorTableSource, vectorTilesetSource };
1531
1484
  //# sourceMappingURL=api-client.modern.js.map