@carto/api-client 0.4.0-alpha.0 → 0.4.0-alpha.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/build/api/carto-api-error.d.ts +9 -1
- package/build/api/endpoints.d.ts +3 -1
- package/build/api/index.d.ts +5 -4
- package/build/api/request-with-parameters.d.ts +1 -1
- package/build/api-client.cjs +256 -59
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +207 -53
- package/build/api-client.modern.js.map +1 -1
- package/build/constants-internal.d.ts +9 -28
- package/build/constants.d.ts +24 -10
- package/build/index.d.ts +4 -5
- package/build/models/model.d.ts +2 -2
- package/build/sources/base-source.d.ts +1 -1
- package/build/sources/boundary-query-source.d.ts +1 -1
- package/build/sources/index.d.ts +1 -1
- package/build/sources/types.d.ts +2 -1
- package/build/types-internal.d.ts +46 -1
- package/build/types.d.ts +11 -0
- package/build/widget-sources/widget-base-source.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/carto-api-error.ts +17 -1
- package/src/api/endpoints.ts +3 -1
- package/src/api/index.ts +9 -12
- package/src/api/query.ts +1 -1
- package/src/api/request-with-parameters.ts +3 -7
- package/src/constants-internal.ts +9 -30
- package/src/constants.ts +32 -16
- package/src/index.ts +33 -5
- package/src/models/model.ts +4 -6
- package/src/sources/base-source.ts +2 -1
- package/src/sources/boundary-query-source.ts +1 -1
- package/src/sources/h3-query-source.ts +1 -1
- package/src/sources/h3-table-source.ts +1 -1
- package/src/sources/index.ts +6 -1
- package/src/sources/quadbin-query-source.ts +1 -1
- package/src/sources/quadbin-table-source.ts +1 -1
- package/src/sources/types.ts +2 -6
- package/src/sources/vector-query-source.ts +1 -1
- package/src/sources/vector-table-source.ts +1 -1
- package/src/types-internal.ts +54 -1
- package/src/types.ts +16 -0
- package/src/widget-sources/widget-base-source.ts +5 -5
- package/src/widget-sources/widget-query-source.ts +1 -2
- package/src/widget-sources/widget-table-source.ts +1 -2
- package/src/widget-sources/wrappers.ts +0 -1
- package/build/api/types.d.ts +0 -227
- package/src/api/types.ts +0 -301
|
@@ -28,17 +28,6 @@ function setClient(c) {
|
|
|
28
28
|
client = c;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/** Current version of @carto/api-client. */
|
|
32
|
-
const API_CLIENT_VERSION = "0.4.0-alpha.0";
|
|
33
|
-
const DEFAULT_API_BASE_URL$1 = 'https://gcp-us-east1.api.carto.com';
|
|
34
|
-
const DEFAULT_CLIENT = 'deck-gl-carto';
|
|
35
|
-
const V3_MINOR_VERSION = '3.4';
|
|
36
|
-
// Fastly default limit is 8192; leave some padding.
|
|
37
|
-
const DEFAULT_MAX_LENGTH_URL = 7000;
|
|
38
|
-
const DEFAULT_TILE_SIZE = 512;
|
|
39
|
-
const DEFAULT_TILE_RESOLUTION = 0.5;
|
|
40
|
-
const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
|
|
41
|
-
const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
|
|
42
31
|
/**
|
|
43
32
|
* Defines a comparator used when matching a column's values against given filter values.
|
|
44
33
|
*
|
|
@@ -63,6 +52,31 @@ var FilterType;
|
|
|
63
52
|
FilterType["TIME"] = "time";
|
|
64
53
|
FilterType["STRING_SEARCH"] = "stringSearch";
|
|
65
54
|
})(FilterType || (FilterType = {}));
|
|
55
|
+
/** @internalRemarks Source: @carto/constants */
|
|
56
|
+
var ApiVersion;
|
|
57
|
+
(function (ApiVersion) {
|
|
58
|
+
ApiVersion["V1"] = "v1";
|
|
59
|
+
ApiVersion["V2"] = "v2";
|
|
60
|
+
ApiVersion["V3"] = "v3";
|
|
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;
|
|
66
80
|
|
|
67
81
|
const FILTER_TYPES = new Set(Object.values(FilterType));
|
|
68
82
|
const isFilterType = type => FILTER_TYPES.has(type);
|
|
@@ -369,43 +383,6 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
369
383
|
return t;
|
|
370
384
|
}
|
|
371
385
|
|
|
372
|
-
/******************************************************************************
|
|
373
|
-
* DEFAULTS
|
|
374
|
-
*/
|
|
375
|
-
/**
|
|
376
|
-
* @internalRemarks Source: @carto/constants
|
|
377
|
-
* @internal
|
|
378
|
-
*/
|
|
379
|
-
const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
|
|
380
|
-
/**
|
|
381
|
-
* @internalRemarks Source: @carto/react-api
|
|
382
|
-
* @internal
|
|
383
|
-
*/
|
|
384
|
-
const DEFAULT_GEO_COLUMN = 'geom';
|
|
385
|
-
/******************************************************************************
|
|
386
|
-
* ENUMS
|
|
387
|
-
*/
|
|
388
|
-
/**
|
|
389
|
-
* @internal
|
|
390
|
-
* @internalRemarks Source: @carto/constants
|
|
391
|
-
*/
|
|
392
|
-
var MapType;
|
|
393
|
-
(function (MapType) {
|
|
394
|
-
MapType["TABLE"] = "table";
|
|
395
|
-
MapType["QUERY"] = "query";
|
|
396
|
-
MapType["TILESET"] = "tileset";
|
|
397
|
-
})(MapType || (MapType = {}));
|
|
398
|
-
/**
|
|
399
|
-
* @internal
|
|
400
|
-
* @internalRemarks Source: @carto/constants
|
|
401
|
-
*/
|
|
402
|
-
var ApiVersion;
|
|
403
|
-
(function (ApiVersion) {
|
|
404
|
-
ApiVersion["V1"] = "v1";
|
|
405
|
-
ApiVersion["V2"] = "v2";
|
|
406
|
-
ApiVersion["V3"] = "v3";
|
|
407
|
-
})(ApiVersion || (ApiVersion = {}));
|
|
408
|
-
|
|
409
386
|
/**
|
|
410
387
|
* Return more descriptive error from API
|
|
411
388
|
* @internalRemarks Source: @carto/react-api
|
|
@@ -500,7 +477,7 @@ function executeModel(props) {
|
|
|
500
477
|
assert(apiBaseUrl, 'executeModel: missing apiBaseUrl');
|
|
501
478
|
assert(accessToken, 'executeModel: missing accessToken');
|
|
502
479
|
assert(apiVersion === V3, 'executeModel: SQL Model API requires CARTO 3+');
|
|
503
|
-
assert(type !==
|
|
480
|
+
assert(type !== 'tileset', 'executeModel: Tilesets not supported');
|
|
504
481
|
let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
|
|
505
482
|
const {
|
|
506
483
|
filters,
|
|
@@ -896,7 +873,7 @@ WidgetBaseSource.defaultProps = {
|
|
|
896
873
|
class WidgetQuerySource extends WidgetBaseSource {
|
|
897
874
|
getModelSource(owner) {
|
|
898
875
|
return _extends({}, super._getModelSource(owner), {
|
|
899
|
-
type:
|
|
876
|
+
type: 'query',
|
|
900
877
|
data: this.props.sqlQuery,
|
|
901
878
|
queryParameters: this.props.queryParameters
|
|
902
879
|
});
|
|
@@ -928,7 +905,7 @@ class WidgetQuerySource extends WidgetBaseSource {
|
|
|
928
905
|
class WidgetTableSource extends WidgetBaseSource {
|
|
929
906
|
getModelSource(owner) {
|
|
930
907
|
return _extends({}, super._getModelSource(owner), {
|
|
931
|
-
type:
|
|
908
|
+
type: 'table',
|
|
932
909
|
data: this.props.tableName
|
|
933
910
|
});
|
|
934
911
|
}
|
|
@@ -943,6 +920,27 @@ function joinPath(...args) {
|
|
|
943
920
|
function buildV3Path(apiBaseUrl, version, endpoint, ...rest) {
|
|
944
921
|
return joinPath(apiBaseUrl, version, endpoint, ...rest);
|
|
945
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
|
+
}
|
|
946
944
|
function buildSourceUrl({
|
|
947
945
|
apiBaseUrl,
|
|
948
946
|
connectionName,
|
|
@@ -950,6 +948,12 @@ function buildSourceUrl({
|
|
|
950
948
|
}) {
|
|
951
949
|
return buildV3Path(apiBaseUrl, 'v3', 'maps', connectionName, endpoint);
|
|
952
950
|
}
|
|
951
|
+
function buildQueryUrl({
|
|
952
|
+
apiBaseUrl,
|
|
953
|
+
connectionName
|
|
954
|
+
}) {
|
|
955
|
+
return buildV3Path(apiBaseUrl, 'v3', 'sql', connectionName, 'query');
|
|
956
|
+
}
|
|
953
957
|
|
|
954
958
|
// deck.gl
|
|
955
959
|
// SPDX-License-Identifier: MIT
|
|
@@ -1007,6 +1011,22 @@ function formatErrorKey(key) {
|
|
|
1007
1011
|
return key.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());
|
|
1008
1012
|
}
|
|
1009
1013
|
|
|
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;
|
|
1029
|
+
|
|
1010
1030
|
const DEFAULT_HEADERS = {
|
|
1011
1031
|
Accept: 'application/json',
|
|
1012
1032
|
'Content-Type': 'application/json'
|
|
@@ -1101,7 +1121,7 @@ function excludeURLParameters(baseUrlString, parameters) {
|
|
|
1101
1121
|
|
|
1102
1122
|
const _excluded = ["accessToken", "connectionName", "cache"];
|
|
1103
1123
|
const SOURCE_DEFAULTS = {
|
|
1104
|
-
apiBaseUrl: DEFAULT_API_BASE_URL
|
|
1124
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
1105
1125
|
clientId: DEFAULT_CLIENT,
|
|
1106
1126
|
format: 'tilejson',
|
|
1107
1127
|
headers: {},
|
|
@@ -1174,6 +1194,52 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
1174
1194
|
});
|
|
1175
1195
|
}
|
|
1176
1196
|
|
|
1197
|
+
// deck.gl
|
|
1198
|
+
const boundaryQuerySource = async function boundaryQuerySource(options) {
|
|
1199
|
+
const {
|
|
1200
|
+
columns,
|
|
1201
|
+
filters,
|
|
1202
|
+
tilesetTableName,
|
|
1203
|
+
propertiesSqlQuery,
|
|
1204
|
+
queryParameters
|
|
1205
|
+
} = options;
|
|
1206
|
+
const urlParameters = {
|
|
1207
|
+
tilesetTableName,
|
|
1208
|
+
propertiesSqlQuery
|
|
1209
|
+
};
|
|
1210
|
+
if (columns) {
|
|
1211
|
+
urlParameters.columns = columns.join(',');
|
|
1212
|
+
}
|
|
1213
|
+
if (filters) {
|
|
1214
|
+
urlParameters.filters = filters;
|
|
1215
|
+
}
|
|
1216
|
+
if (queryParameters) {
|
|
1217
|
+
urlParameters.queryParameters = queryParameters;
|
|
1218
|
+
}
|
|
1219
|
+
return baseSource('boundary', options, urlParameters);
|
|
1220
|
+
};
|
|
1221
|
+
|
|
1222
|
+
// deck.gl
|
|
1223
|
+
const boundaryTableSource = async function boundaryTableSource(options) {
|
|
1224
|
+
const {
|
|
1225
|
+
filters,
|
|
1226
|
+
tilesetTableName,
|
|
1227
|
+
columns,
|
|
1228
|
+
propertiesTableName
|
|
1229
|
+
} = options;
|
|
1230
|
+
const urlParameters = {
|
|
1231
|
+
tilesetTableName,
|
|
1232
|
+
propertiesTableName
|
|
1233
|
+
};
|
|
1234
|
+
if (columns) {
|
|
1235
|
+
urlParameters.columns = columns.join(',');
|
|
1236
|
+
}
|
|
1237
|
+
if (filters) {
|
|
1238
|
+
urlParameters.filters = filters;
|
|
1239
|
+
}
|
|
1240
|
+
return baseSource('boundary', options, urlParameters);
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1177
1243
|
// deck.gl
|
|
1178
1244
|
const h3QuerySource$1 = async function h3QuerySource(options) {
|
|
1179
1245
|
const {
|
|
@@ -1226,6 +1292,32 @@ const h3TableSource$1 = async function h3TableSource(options) {
|
|
|
1226
1292
|
return baseSource('table', options, urlParameters);
|
|
1227
1293
|
};
|
|
1228
1294
|
|
|
1295
|
+
// deck.gl
|
|
1296
|
+
const h3TilesetSource = async function h3TilesetSource(options) {
|
|
1297
|
+
const {
|
|
1298
|
+
tableName
|
|
1299
|
+
} = options;
|
|
1300
|
+
const urlParameters = {
|
|
1301
|
+
name: tableName
|
|
1302
|
+
};
|
|
1303
|
+
return baseSource('tileset', options, urlParameters);
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
// deck.gl
|
|
1307
|
+
const rasterSource = async function rasterSource(options) {
|
|
1308
|
+
const {
|
|
1309
|
+
tableName,
|
|
1310
|
+
filters
|
|
1311
|
+
} = options;
|
|
1312
|
+
const urlParameters = {
|
|
1313
|
+
name: tableName
|
|
1314
|
+
};
|
|
1315
|
+
if (filters) {
|
|
1316
|
+
urlParameters.filters = filters;
|
|
1317
|
+
}
|
|
1318
|
+
return baseSource('raster', options, urlParameters);
|
|
1319
|
+
};
|
|
1320
|
+
|
|
1229
1321
|
// deck.gl
|
|
1230
1322
|
const quadbinQuerySource$1 = async function quadbinQuerySource(options) {
|
|
1231
1323
|
const {
|
|
@@ -1278,6 +1370,17 @@ const quadbinTableSource$1 = async function quadbinTableSource(options) {
|
|
|
1278
1370
|
return baseSource('table', options, urlParameters);
|
|
1279
1371
|
};
|
|
1280
1372
|
|
|
1373
|
+
// deck.gl
|
|
1374
|
+
const quadbinTilesetSource = async function quadbinTilesetSource(options) {
|
|
1375
|
+
const {
|
|
1376
|
+
tableName
|
|
1377
|
+
} = options;
|
|
1378
|
+
const urlParameters = {
|
|
1379
|
+
name: tableName
|
|
1380
|
+
};
|
|
1381
|
+
return baseSource('tileset', options, urlParameters);
|
|
1382
|
+
};
|
|
1383
|
+
|
|
1281
1384
|
// deck.gl
|
|
1282
1385
|
const vectorQuerySource$1 = async function vectorQuerySource(options) {
|
|
1283
1386
|
const {
|
|
@@ -1330,6 +1433,17 @@ const vectorTableSource$1 = async function vectorTableSource(options) {
|
|
|
1330
1433
|
return baseSource('table', options, urlParameters);
|
|
1331
1434
|
};
|
|
1332
1435
|
|
|
1436
|
+
// deck.gl
|
|
1437
|
+
const vectorTilesetSource = async function vectorTilesetSource(options) {
|
|
1438
|
+
const {
|
|
1439
|
+
tableName
|
|
1440
|
+
} = options;
|
|
1441
|
+
const urlParameters = {
|
|
1442
|
+
name: tableName
|
|
1443
|
+
};
|
|
1444
|
+
return baseSource('tileset', options, urlParameters);
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1333
1447
|
/** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1334
1448
|
async function vectorTableSource(props) {
|
|
1335
1449
|
const response = await vectorTableSource$1(props);
|
|
@@ -1373,5 +1487,45 @@ async function quadbinQuerySource(props) {
|
|
|
1373
1487
|
});
|
|
1374
1488
|
}
|
|
1375
1489
|
|
|
1376
|
-
|
|
1490
|
+
const query = async function query(options) {
|
|
1491
|
+
const {
|
|
1492
|
+
apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl,
|
|
1493
|
+
clientId = SOURCE_DEFAULTS.clientId,
|
|
1494
|
+
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL,
|
|
1495
|
+
connectionName,
|
|
1496
|
+
sqlQuery,
|
|
1497
|
+
queryParameters
|
|
1498
|
+
} = options;
|
|
1499
|
+
const urlParameters = {
|
|
1500
|
+
q: sqlQuery
|
|
1501
|
+
};
|
|
1502
|
+
if (queryParameters) {
|
|
1503
|
+
urlParameters.queryParameters = JSON.stringify(queryParameters);
|
|
1504
|
+
}
|
|
1505
|
+
const baseUrl = buildQueryUrl({
|
|
1506
|
+
apiBaseUrl,
|
|
1507
|
+
connectionName
|
|
1508
|
+
});
|
|
1509
|
+
const headers = _extends({
|
|
1510
|
+
Authorization: `Bearer ${options.accessToken}`
|
|
1511
|
+
}, options.headers);
|
|
1512
|
+
const parameters = _extends({
|
|
1513
|
+
client: clientId
|
|
1514
|
+
}, urlParameters);
|
|
1515
|
+
const errorContext = {
|
|
1516
|
+
requestType: 'SQL',
|
|
1517
|
+
connection: options.connectionName,
|
|
1518
|
+
type: 'query',
|
|
1519
|
+
source: JSON.stringify(parameters, undefined, 2)
|
|
1520
|
+
};
|
|
1521
|
+
return await requestWithParameters({
|
|
1522
|
+
baseUrl,
|
|
1523
|
+
parameters,
|
|
1524
|
+
headers,
|
|
1525
|
+
errorContext,
|
|
1526
|
+
maxLengthURL
|
|
1527
|
+
});
|
|
1528
|
+
};
|
|
1529
|
+
|
|
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 };
|
|
1377
1531
|
//# sourceMappingURL=api-client.modern.js.map
|