@carto/api-client 0.3.1 → 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.
Files changed (72) hide show
  1. package/build/api/carto-api-error.d.ts +26 -0
  2. package/build/api/endpoints.d.ts +24 -0
  3. package/build/api/index.d.ts +5 -0
  4. package/build/api/query.d.ts +3 -0
  5. package/build/api/request-with-parameters.d.ts +8 -0
  6. package/build/api-client.cjs +724 -65
  7. package/build/api-client.cjs.map +1 -1
  8. package/build/api-client.modern.js +607 -59
  9. package/build/api-client.modern.js.map +1 -1
  10. package/build/constants-internal.d.ts +9 -28
  11. package/build/constants.d.ts +24 -2
  12. package/build/index.d.ts +5 -1
  13. package/build/models/model.d.ts +2 -2
  14. package/build/sources/base-source.d.ts +4 -0
  15. package/build/sources/boundary-query-source.d.ts +9 -0
  16. package/build/sources/boundary-table-source.d.ts +7 -0
  17. package/build/sources/h3-query-source.d.ts +3 -0
  18. package/build/sources/h3-table-source.d.ts +3 -0
  19. package/build/sources/h3-tileset-source.d.ts +3 -0
  20. package/build/sources/index.d.ts +27 -5
  21. package/build/sources/quadbin-query-source.d.ts +3 -0
  22. package/build/sources/quadbin-table-source.d.ts +3 -0
  23. package/build/sources/quadbin-tileset-source.d.ts +3 -0
  24. package/build/sources/raster-source.d.ts +3 -0
  25. package/build/sources/types.d.ts +209 -85
  26. package/build/sources/vector-query-source.d.ts +3 -0
  27. package/build/sources/vector-table-source.d.ts +3 -0
  28. package/build/sources/vector-tileset-source.d.ts +3 -0
  29. package/build/types-internal.d.ts +46 -1
  30. package/build/types.d.ts +11 -0
  31. package/build/utils.d.ts +4 -0
  32. package/build/widget-sources/index.d.ts +5 -0
  33. package/build/widget-sources/types.d.ts +95 -0
  34. package/build/{sources → widget-sources}/widget-base-source.d.ts +2 -2
  35. package/build/{sources → widget-sources}/widget-query-source.d.ts +1 -1
  36. package/build/{sources → widget-sources}/widget-table-source.d.ts +1 -1
  37. package/build/{sources → widget-sources}/wrappers.d.ts +1 -1
  38. package/package.json +4 -3
  39. package/src/api/carto-api-error.ts +88 -0
  40. package/src/api/endpoints.ts +84 -0
  41. package/src/api/index.ts +14 -0
  42. package/src/api/query.ts +56 -0
  43. package/src/api/request-with-parameters.ts +135 -0
  44. package/src/constants-internal.ts +9 -30
  45. package/src/constants.ts +32 -3
  46. package/src/global.d.ts +3 -0
  47. package/src/index.ts +38 -1
  48. package/src/models/model.ts +4 -6
  49. package/src/sources/base-source.ts +101 -0
  50. package/src/sources/boundary-query-source.ts +53 -0
  51. package/src/sources/boundary-table-source.ts +41 -0
  52. package/src/sources/h3-query-source.ts +63 -0
  53. package/src/sources/h3-table-source.ts +59 -0
  54. package/src/sources/h3-tileset-source.ts +26 -0
  55. package/src/sources/index.ts +54 -5
  56. package/src/sources/quadbin-query-source.ts +64 -0
  57. package/src/sources/quadbin-table-source.ts +60 -0
  58. package/src/sources/quadbin-tileset-source.ts +26 -0
  59. package/src/sources/raster-source.ts +34 -0
  60. package/src/sources/types.ts +221 -89
  61. package/src/sources/vector-query-source.ts +65 -0
  62. package/src/sources/vector-table-source.ts +59 -0
  63. package/src/sources/vector-tileset-source.ts +26 -0
  64. package/src/types-internal.ts +54 -1
  65. package/src/types.ts +16 -0
  66. package/src/utils.ts +8 -0
  67. package/src/widget-sources/index.ts +5 -0
  68. package/src/widget-sources/types.ts +105 -0
  69. package/src/{sources → widget-sources}/widget-base-source.ts +5 -5
  70. package/src/{sources → widget-sources}/widget-query-source.ts +2 -3
  71. package/src/{sources → widget-sources}/widget-table-source.ts +2 -3
  72. package/src/{sources → widget-sources}/wrappers.ts +1 -22
@@ -3,7 +3,6 @@ import bboxPolygon from '@turf/bbox-polygon';
3
3
  import union from '@turf/union';
4
4
  import { getType } from '@turf/invariant';
5
5
  import { featureCollection, feature, polygon, multiPolygon } from '@turf/helpers';
6
- import { vectorTableSource as vectorTableSource$1, vectorQuerySource as vectorQuerySource$1, h3TableSource as h3TableSource$1, h3QuerySource as h3QuerySource$1, quadbinTableSource as quadbinTableSource$1, quadbinQuerySource as quadbinQuerySource$1 } from '@deck.gl/carto';
7
6
 
8
7
  /**
9
8
  * @internal
@@ -29,8 +28,6 @@ function setClient(c) {
29
28
  client = c;
30
29
  }
31
30
 
32
- /** Current version of @carto/api-client. */
33
- const API_CLIENT_VERSION = "0.3.1";
34
31
  /**
35
32
  * Defines a comparator used when matching a column's values against given filter values.
36
33
  *
@@ -55,6 +52,31 @@ var FilterType;
55
52
  FilterType["TIME"] = "time";
56
53
  FilterType["STRING_SEARCH"] = "stringSearch";
57
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;
58
80
 
59
81
  const FILTER_TYPES = new Set(Object.values(FilterType));
60
82
  const isFilterType = type => FILTER_TYPES.has(type);
@@ -123,6 +145,10 @@ function isEmptyObject(object) {
123
145
  }
124
146
  return true;
125
147
  }
148
+ /** @internal */
149
+ const isObject = x => x !== null && typeof x === 'object';
150
+ /** @internal */
151
+ const isPureObject = x => isObject(x) && x.constructor === {}.constructor;
126
152
 
127
153
  /**
128
154
  * Adds a {@link Filter} to the filter set. Any previous filters with the same
@@ -357,43 +383,6 @@ function _objectWithoutPropertiesLoose(r, e) {
357
383
  return t;
358
384
  }
359
385
 
360
- /******************************************************************************
361
- * DEFAULTS
362
- */
363
- /**
364
- * @internalRemarks Source: @carto/constants
365
- * @internal
366
- */
367
- const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
368
- /**
369
- * @internalRemarks Source: @carto/react-api
370
- * @internal
371
- */
372
- const DEFAULT_GEO_COLUMN = 'geom';
373
- /******************************************************************************
374
- * ENUMS
375
- */
376
- /**
377
- * @internal
378
- * @internalRemarks Source: @carto/constants
379
- */
380
- var MapType;
381
- (function (MapType) {
382
- MapType["TABLE"] = "table";
383
- MapType["QUERY"] = "query";
384
- MapType["TILESET"] = "tileset";
385
- })(MapType || (MapType = {}));
386
- /**
387
- * @internal
388
- * @internalRemarks Source: @carto/constants
389
- */
390
- var ApiVersion;
391
- (function (ApiVersion) {
392
- ApiVersion["V1"] = "v1";
393
- ApiVersion["V2"] = "v2";
394
- ApiVersion["V3"] = "v3";
395
- })(ApiVersion || (ApiVersion = {}));
396
-
397
386
  /**
398
387
  * Return more descriptive error from API
399
388
  * @internalRemarks Source: @carto/react-api
@@ -488,7 +477,7 @@ function executeModel(props) {
488
477
  assert(apiBaseUrl, 'executeModel: missing apiBaseUrl');
489
478
  assert(accessToken, 'executeModel: missing accessToken');
490
479
  assert(apiVersion === V3, 'executeModel: SQL Model API requires CARTO 3+');
491
- assert(type !== MapType.TILESET, 'executeModel: Tilesets not supported');
480
+ assert(type !== 'tileset', 'executeModel: Tilesets not supported');
492
481
  let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
493
482
  const {
494
483
  filters,
@@ -536,7 +525,7 @@ function executeModel(props) {
536
525
  });
537
526
  }
538
527
 
539
- const _excluded = ["filterOwner", "spatialFilter", "abortController"],
528
+ const _excluded$1 = ["filterOwner", "spatialFilter", "abortController"],
540
529
  _excluded2 = ["filterOwner", "spatialFilter", "abortController", "operationExp"],
541
530
  _excluded3 = ["filterOwner", "spatialFilter", "abortController"],
542
531
  _excluded4 = ["filterOwner", "spatialFilter", "abortController"],
@@ -579,7 +568,7 @@ class WidgetBaseSource {
579
568
  spatialFilter,
580
569
  abortController
581
570
  } = options,
582
- params = _objectWithoutPropertiesLoose(options, _excluded);
571
+ params = _objectWithoutPropertiesLoose(options, _excluded$1);
583
572
  const {
584
573
  column,
585
574
  operation,
@@ -884,7 +873,7 @@ WidgetBaseSource.defaultProps = {
884
873
  class WidgetQuerySource extends WidgetBaseSource {
885
874
  getModelSource(owner) {
886
875
  return _extends({}, super._getModelSource(owner), {
887
- type: MapType.QUERY,
876
+ type: 'query',
888
877
  data: this.props.sqlQuery,
889
878
  queryParameters: this.props.queryParameters
890
879
  });
@@ -916,15 +905,547 @@ class WidgetQuerySource extends WidgetBaseSource {
916
905
  class WidgetTableSource extends WidgetBaseSource {
917
906
  getModelSource(owner) {
918
907
  return _extends({}, super._getModelSource(owner), {
919
- type: MapType.TABLE,
908
+ type: 'table',
920
909
  data: this.props.tableName
921
910
  });
922
911
  }
923
912
  }
924
913
 
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
+ // deck.gl
959
+ // SPDX-License-Identifier: MIT
960
+ // Copyright (c) vis.gl contributors
961
+ /**
962
+ *
963
+ * Custom error for reported errors in CARTO Maps API.
964
+ * Provides useful debugging information in console and context for applications.
965
+ *
966
+ */
967
+ class CartoAPIError extends Error {
968
+ constructor(error, errorContext, response, responseJson) {
969
+ let responseString = 'Failed to connect';
970
+ if (response) {
971
+ responseString = 'Server returned: ';
972
+ if (response.status === 400) {
973
+ responseString += 'Bad request';
974
+ } else if (response.status === 401 || response.status === 403) {
975
+ responseString += 'Unauthorized access';
976
+ } else if (response.status === 404) {
977
+ responseString += 'Not found';
978
+ } else {
979
+ responseString += 'Error';
980
+ }
981
+ responseString += ` (${response.status}):`;
982
+ }
983
+ responseString += ` ${error.message || error}`;
984
+ let message = `${errorContext.requestType} API request failed`;
985
+ message += `\n${responseString}`;
986
+ for (const key of Object.keys(errorContext)) {
987
+ if (key === 'requestType') continue;
988
+ message += `\n${formatErrorKey(key)}: ${errorContext[key]}`;
989
+ }
990
+ message += '\n';
991
+ super(message);
992
+ /** Source error from server */
993
+ this.error = void 0;
994
+ /** Context (API call & parameters) in which error occured */
995
+ this.errorContext = void 0;
996
+ /** Response from server */
997
+ this.response = void 0;
998
+ /** JSON Response from server */
999
+ this.responseJson = void 0;
1000
+ this.name = 'CartoAPIError';
1001
+ this.response = response;
1002
+ this.responseJson = responseJson;
1003
+ this.error = error;
1004
+ this.errorContext = errorContext;
1005
+ }
1006
+ }
1007
+ /**
1008
+ * Converts camelCase to Camel Case
1009
+ */
1010
+ function formatErrorKey(key) {
1011
+ return key.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());
1012
+ }
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
+
1030
+ const DEFAULT_HEADERS = {
1031
+ Accept: 'application/json',
1032
+ 'Content-Type': 'application/json'
1033
+ };
1034
+ const REQUEST_CACHE = new Map();
1035
+ async function requestWithParameters({
1036
+ baseUrl,
1037
+ parameters = {},
1038
+ headers: customHeaders = {},
1039
+ errorContext,
1040
+ maxLengthURL = DEFAULT_MAX_LENGTH_URL
1041
+ }) {
1042
+ // Parameters added to all requests issued with `requestWithParameters()`.
1043
+ // These parameters override parameters already in the base URL, but not
1044
+ // user-provided parameters.
1045
+ parameters = _extends({
1046
+ v: V3_MINOR_VERSION,
1047
+ clientId: DEFAULT_CLIENT
1048
+ }, typeof deck !== 'undefined' && deck.VERSION && {
1049
+ deckglVersion: deck.VERSION
1050
+ }, parameters);
1051
+ baseUrl = excludeURLParameters(baseUrl, Object.keys(parameters));
1052
+ const key = createCacheKey(baseUrl, parameters, customHeaders);
1053
+ if (REQUEST_CACHE.has(key)) {
1054
+ return REQUEST_CACHE.get(key);
1055
+ }
1056
+ const url = createURLWithParameters(baseUrl, parameters);
1057
+ const headers = _extends({}, DEFAULT_HEADERS, customHeaders);
1058
+ /* global fetch */
1059
+ const fetchPromise = url.length > maxLengthURL ? fetch(baseUrl, {
1060
+ method: 'POST',
1061
+ body: JSON.stringify(parameters),
1062
+ headers
1063
+ }) : fetch(url, {
1064
+ headers
1065
+ });
1066
+ let response;
1067
+ let responseJson;
1068
+ const jsonPromise = fetchPromise.then(_response => {
1069
+ response = _response;
1070
+ return response.json();
1071
+ }).then(json => {
1072
+ responseJson = json;
1073
+ if (!response || !response.ok) {
1074
+ throw new Error(json.error);
1075
+ }
1076
+ return json;
1077
+ }).catch(error => {
1078
+ REQUEST_CACHE.delete(key);
1079
+ throw new CartoAPIError(error, errorContext, response, responseJson);
1080
+ });
1081
+ REQUEST_CACHE.set(key, jsonPromise);
1082
+ return jsonPromise;
1083
+ }
1084
+ function createCacheKey(baseUrl, parameters, headers) {
1085
+ const parameterEntries = Object.entries(parameters).sort(([a], [b]) => a > b ? 1 : -1);
1086
+ const headerEntries = Object.entries(headers).sort(([a], [b]) => a > b ? 1 : -1);
1087
+ return JSON.stringify({
1088
+ baseUrl,
1089
+ parameters: parameterEntries,
1090
+ headers: headerEntries
1091
+ });
1092
+ }
1093
+ /**
1094
+ * Appends query string parameters to a URL. Existing URL parameters are kept,
1095
+ * unless there is a conflict, in which case the new parameters override
1096
+ * those already in the URL.
1097
+ */
1098
+ function createURLWithParameters(baseUrlString, parameters) {
1099
+ const baseUrl = new URL(baseUrlString);
1100
+ for (const [key, value] of Object.entries(parameters)) {
1101
+ if (isPureObject(value) || Array.isArray(value)) {
1102
+ baseUrl.searchParams.set(key, JSON.stringify(value));
1103
+ } else {
1104
+ baseUrl.searchParams.set(key, value.toString());
1105
+ }
1106
+ }
1107
+ return baseUrl.toString();
1108
+ }
1109
+ /**
1110
+ * Deletes query string parameters from a URL.
1111
+ */
1112
+ function excludeURLParameters(baseUrlString, parameters) {
1113
+ const baseUrl = new URL(baseUrlString);
1114
+ for (const param of parameters) {
1115
+ if (baseUrl.searchParams.has(param)) {
1116
+ baseUrl.searchParams.delete(param);
1117
+ }
1118
+ }
1119
+ return baseUrl.toString();
1120
+ }
1121
+
1122
+ const _excluded = ["accessToken", "connectionName", "cache"];
1123
+ const SOURCE_DEFAULTS = {
1124
+ apiBaseUrl: DEFAULT_API_BASE_URL,
1125
+ clientId: DEFAULT_CLIENT,
1126
+ format: 'tilejson',
1127
+ headers: {},
1128
+ maxLengthURL: DEFAULT_MAX_LENGTH_URL
1129
+ };
1130
+ async function baseSource(endpoint, options, urlParameters) {
1131
+ const {
1132
+ accessToken,
1133
+ connectionName,
1134
+ cache
1135
+ } = options,
1136
+ optionalOptions = _objectWithoutPropertiesLoose(options, _excluded);
1137
+ const mergedOptions = _extends({}, SOURCE_DEFAULTS, {
1138
+ accessToken,
1139
+ connectionName,
1140
+ endpoint
1141
+ });
1142
+ for (const key in optionalOptions) {
1143
+ if (optionalOptions[key]) {
1144
+ mergedOptions[key] = optionalOptions[key];
1145
+ }
1146
+ }
1147
+ const baseUrl = buildSourceUrl(mergedOptions);
1148
+ const {
1149
+ clientId,
1150
+ maxLengthURL,
1151
+ format
1152
+ } = mergedOptions;
1153
+ const headers = _extends({
1154
+ Authorization: `Bearer ${options.accessToken}`
1155
+ }, options.headers);
1156
+ const parameters = _extends({
1157
+ client: clientId
1158
+ }, urlParameters);
1159
+ const errorContext = {
1160
+ requestType: 'Map instantiation',
1161
+ connection: options.connectionName,
1162
+ type: endpoint,
1163
+ source: JSON.stringify(parameters, undefined, 2)
1164
+ };
1165
+ const mapInstantiation = await requestWithParameters({
1166
+ baseUrl,
1167
+ parameters,
1168
+ headers,
1169
+ errorContext,
1170
+ maxLengthURL
1171
+ });
1172
+ const dataUrl = mapInstantiation[format].url[0];
1173
+ if (cache) {
1174
+ cache.value = parseInt(new URL(dataUrl).searchParams.get('cache') || '', 10);
1175
+ }
1176
+ errorContext.requestType = 'Map data';
1177
+ if (format === 'tilejson') {
1178
+ const json = await requestWithParameters({
1179
+ baseUrl: dataUrl,
1180
+ headers,
1181
+ errorContext,
1182
+ maxLengthURL
1183
+ });
1184
+ if (accessToken) {
1185
+ json.accessToken = accessToken;
1186
+ }
1187
+ return json;
1188
+ }
1189
+ return await requestWithParameters({
1190
+ baseUrl: dataUrl,
1191
+ headers,
1192
+ errorContext,
1193
+ maxLengthURL
1194
+ });
1195
+ }
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
+
1243
+ // deck.gl
1244
+ const h3QuerySource$1 = async function h3QuerySource(options) {
1245
+ const {
1246
+ aggregationExp,
1247
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
1248
+ sqlQuery,
1249
+ spatialDataColumn = 'h3',
1250
+ queryParameters,
1251
+ filters
1252
+ } = options;
1253
+ const urlParameters = {
1254
+ aggregationExp,
1255
+ spatialDataColumn,
1256
+ spatialDataType: 'h3',
1257
+ q: sqlQuery
1258
+ };
1259
+ if (aggregationResLevel) {
1260
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
1261
+ }
1262
+ if (queryParameters) {
1263
+ urlParameters.queryParameters = queryParameters;
1264
+ }
1265
+ if (filters) {
1266
+ urlParameters.filters = filters;
1267
+ }
1268
+ return baseSource('query', options, urlParameters);
1269
+ };
1270
+
1271
+ // deck.gl
1272
+ const h3TableSource$1 = async function h3TableSource(options) {
1273
+ const {
1274
+ aggregationExp,
1275
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
1276
+ spatialDataColumn = 'h3',
1277
+ tableName,
1278
+ filters
1279
+ } = options;
1280
+ const urlParameters = {
1281
+ aggregationExp,
1282
+ name: tableName,
1283
+ spatialDataColumn,
1284
+ spatialDataType: 'h3'
1285
+ };
1286
+ if (aggregationResLevel) {
1287
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
1288
+ }
1289
+ if (filters) {
1290
+ urlParameters.filters = filters;
1291
+ }
1292
+ return baseSource('table', options, urlParameters);
1293
+ };
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
+
1321
+ // deck.gl
1322
+ const quadbinQuerySource$1 = async function quadbinQuerySource(options) {
1323
+ const {
1324
+ aggregationExp,
1325
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
1326
+ sqlQuery,
1327
+ spatialDataColumn = 'quadbin',
1328
+ queryParameters,
1329
+ filters
1330
+ } = options;
1331
+ const urlParameters = {
1332
+ aggregationExp,
1333
+ q: sqlQuery,
1334
+ spatialDataColumn,
1335
+ spatialDataType: 'quadbin'
1336
+ };
1337
+ if (aggregationResLevel) {
1338
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
1339
+ }
1340
+ if (queryParameters) {
1341
+ urlParameters.queryParameters = queryParameters;
1342
+ }
1343
+ if (filters) {
1344
+ urlParameters.filters = filters;
1345
+ }
1346
+ return baseSource('query', options, urlParameters);
1347
+ };
1348
+
1349
+ // deck.gl
1350
+ const quadbinTableSource$1 = async function quadbinTableSource(options) {
1351
+ const {
1352
+ aggregationExp,
1353
+ aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
1354
+ spatialDataColumn = 'quadbin',
1355
+ tableName,
1356
+ filters
1357
+ } = options;
1358
+ const urlParameters = {
1359
+ aggregationExp,
1360
+ name: tableName,
1361
+ spatialDataColumn,
1362
+ spatialDataType: 'quadbin'
1363
+ };
1364
+ if (aggregationResLevel) {
1365
+ urlParameters.aggregationResLevel = String(aggregationResLevel);
1366
+ }
1367
+ if (filters) {
1368
+ urlParameters.filters = filters;
1369
+ }
1370
+ return baseSource('table', options, urlParameters);
1371
+ };
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
+
1384
+ // deck.gl
1385
+ const vectorQuerySource$1 = async function vectorQuerySource(options) {
1386
+ const {
1387
+ columns,
1388
+ filters,
1389
+ spatialDataColumn = 'geom',
1390
+ sqlQuery,
1391
+ tileResolution = DEFAULT_TILE_RESOLUTION,
1392
+ queryParameters
1393
+ } = options;
1394
+ const urlParameters = {
1395
+ spatialDataColumn,
1396
+ spatialDataType: 'geo',
1397
+ tileResolution: tileResolution.toString(),
1398
+ q: sqlQuery
1399
+ };
1400
+ if (columns) {
1401
+ urlParameters.columns = columns.join(',');
1402
+ }
1403
+ if (filters) {
1404
+ urlParameters.filters = filters;
1405
+ }
1406
+ if (queryParameters) {
1407
+ urlParameters.queryParameters = queryParameters;
1408
+ }
1409
+ return baseSource('query', options, urlParameters);
1410
+ };
1411
+
1412
+ // deck.gl
1413
+ const vectorTableSource$1 = async function vectorTableSource(options) {
1414
+ const {
1415
+ columns,
1416
+ filters,
1417
+ spatialDataColumn = 'geom',
1418
+ tableName,
1419
+ tileResolution = DEFAULT_TILE_RESOLUTION
1420
+ } = options;
1421
+ const urlParameters = {
1422
+ name: tableName,
1423
+ spatialDataColumn,
1424
+ spatialDataType: 'geo',
1425
+ tileResolution: tileResolution.toString()
1426
+ };
1427
+ if (columns) {
1428
+ urlParameters.columns = columns.join(',');
1429
+ }
1430
+ if (filters) {
1431
+ urlParameters.filters = filters;
1432
+ }
1433
+ return baseSource('table', options, urlParameters);
1434
+ };
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
+
925
1447
  /** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
926
1448
  async function vectorTableSource(props) {
927
- assignDefaultProps(props);
928
1449
  const response = await vectorTableSource$1(props);
929
1450
  return _extends({}, response, {
930
1451
  widgetSource: new WidgetTableSource(props)
@@ -932,7 +1453,6 @@ async function vectorTableSource(props) {
932
1453
  }
933
1454
  /** Wrapper adding Widget API support to [vectorQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
934
1455
  async function vectorQuerySource(props) {
935
- assignDefaultProps(props);
936
1456
  const response = await vectorQuerySource$1(props);
937
1457
  return _extends({}, response, {
938
1458
  widgetSource: new WidgetQuerySource(props)
@@ -940,7 +1460,6 @@ async function vectorQuerySource(props) {
940
1460
  }
941
1461
  /** Wrapper adding Widget API support to [h3TableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
942
1462
  async function h3TableSource(props) {
943
- assignDefaultProps(props);
944
1463
  const response = await h3TableSource$1(props);
945
1464
  return _extends({}, response, {
946
1465
  widgetSource: new WidgetTableSource(props)
@@ -948,7 +1467,6 @@ async function h3TableSource(props) {
948
1467
  }
949
1468
  /** Wrapper adding Widget API support to [h3QuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
950
1469
  async function h3QuerySource(props) {
951
- assignDefaultProps(props);
952
1470
  const response = await h3QuerySource$1(props);
953
1471
  return _extends({}, response, {
954
1472
  widgetSource: new WidgetQuerySource(props)
@@ -956,7 +1474,6 @@ async function h3QuerySource(props) {
956
1474
  }
957
1475
  /** Wrapper adding Widget API support to [quadbinTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
958
1476
  async function quadbinTableSource(props) {
959
- assignDefaultProps(props);
960
1477
  const response = await quadbinTableSource$1(props);
961
1478
  return _extends({}, response, {
962
1479
  widgetSource: new WidgetTableSource(props)
@@ -964,20 +1481,51 @@ async function quadbinTableSource(props) {
964
1481
  }
965
1482
  /** Wrapper adding Widget API support to [quadbinQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
966
1483
  async function quadbinQuerySource(props) {
967
- assignDefaultProps(props);
968
1484
  const response = await quadbinQuerySource$1(props);
969
1485
  return _extends({}, response, {
970
1486
  widgetSource: new WidgetQuerySource(props)
971
1487
  });
972
1488
  }
973
- function assignDefaultProps(props) {
974
- if (typeof deck !== 'undefined' && deck && deck.VERSION) {
975
- props.clientId || (props.clientId = 'deck-gl-carto');
976
- // TODO: Uncomment if/when `@deck.gl/carto` devDependency is removed,
977
- // and source functions are moved here rather than wrapped.
978
- // props.deckglVersion ||= deck.VERSION;
1489
+
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);
979
1504
  }
980
- }
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
+ };
981
1529
 
982
- export { API_CLIENT_VERSION, FilterType, WidgetBaseSource, WidgetQuerySource, WidgetTableSource, addFilter, clearFilters, createPolygonSpatialFilter, createViewportSpatialFilter, getClient, getFilter, h3QuerySource, h3TableSource, hasFilter, quadbinQuerySource, quadbinTableSource, removeFilter, setClient, vectorQuerySource, vectorTableSource };
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 };
983
1531
  //# sourceMappingURL=api-client.modern.js.map