@carto/api-client 0.0.32 → 0.0.37
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/LICENSE.md +21 -0
- package/README.md +21 -2
- package/build/api-client.cjs +24 -36
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +24 -21
- package/build/api-client.modern.js.map +1 -1
- package/build/sources/wrappers.d.ts +0 -6
- package/package.json +9 -7
- package/src/models/model.ts +3 -2
- package/src/sources/wrappers.ts +19 -13
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CARTO
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# `@carto/api-client`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
JavaScript (and TypeScript) client library for [CARTO](https://carto.com/) APIs and framework-agnostic [CARTO + deck.gl](https://docs.carto.com/carto-for-developers/carto-for-deck.gl) applications.
|
|
4
|
+
|
|
5
|
+
Includes:
|
|
6
|
+
|
|
7
|
+
- [Widget](https://docs.carto.com/carto-for-developers/carto-for-react/guides/widgets) APIs
|
|
8
|
+
- … TBD
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
@@ -127,10 +132,24 @@ function createViewStatePolygon(viewState) {
|
|
|
127
132
|
}
|
|
128
133
|
```
|
|
129
134
|
|
|
135
|
+
### Specifying columns to fetch
|
|
136
|
+
|
|
137
|
+
Factory functions, like `vectorTableSource`, support both layers
|
|
138
|
+
and widgets. While reusing the same sources has advantages, including simplicity, it's important to understand which columns are fetched, which
|
|
139
|
+
depends on the source type.
|
|
140
|
+
|
|
141
|
+
- **Table sources:** Layers fetch only columns specified by the `columns`
|
|
142
|
+
parameter. Widgets fetch only the columns they need, and are unaffected by
|
|
143
|
+
the `columns` parameter.
|
|
144
|
+
- **Query sources:** Source SQL query must include all columns needed by any
|
|
145
|
+
layers or widgets using the source. Layers fetch only the subset specified
|
|
146
|
+
by the `columns` parameter. Widgets fetch only the subset they need, and are unaffected by the `columns` parameter.
|
|
147
|
+
- **Tileset sources:** Not yet supported.
|
|
148
|
+
|
|
130
149
|
## Versioning
|
|
131
150
|
|
|
132
151
|
Package versioning follows [Semantic Versioning 2.0.0](https://semver.org/).
|
|
133
152
|
|
|
134
153
|
## License
|
|
135
154
|
|
|
136
|
-
|
|
155
|
+
Provided as open source under [MIT License](./LICENSE.md).
|
package/build/api-client.cjs
CHANGED
|
@@ -276,7 +276,8 @@ function executeModel(props) {
|
|
|
276
276
|
apiVersion,
|
|
277
277
|
apiBaseUrl,
|
|
278
278
|
accessToken,
|
|
279
|
-
connectionName
|
|
279
|
+
connectionName,
|
|
280
|
+
clientId
|
|
280
281
|
} = source;
|
|
281
282
|
assert(apiBaseUrl, 'executeModel: missing apiBaseUrl');
|
|
282
283
|
assert(accessToken, 'executeModel: missing accessToken');
|
|
@@ -291,7 +292,7 @@ function executeModel(props) {
|
|
|
291
292
|
const queryParameters = source.queryParameters ? JSON.stringify(source.queryParameters) : '';
|
|
292
293
|
const queryParams = {
|
|
293
294
|
type,
|
|
294
|
-
client:
|
|
295
|
+
client: clientId,
|
|
295
296
|
source: data,
|
|
296
297
|
params: JSON.stringify(params),
|
|
297
298
|
queryParameters,
|
|
@@ -815,7 +816,7 @@ const V3_MINOR_VERSION = '3.4';
|
|
|
815
816
|
const MAX_GET_LENGTH = 8192;
|
|
816
817
|
const DEFAULT_PARAMETERS = {
|
|
817
818
|
v: V3_MINOR_VERSION,
|
|
818
|
-
deckglVersion: "0.0.
|
|
819
|
+
deckglVersion: "0.0.37"
|
|
819
820
|
};
|
|
820
821
|
const DEFAULT_HEADERS = {
|
|
821
822
|
Accept: 'application/json',
|
|
@@ -1068,7 +1069,7 @@ const h3TableSource$1 = async function (options) {
|
|
|
1068
1069
|
return baseSource('table', options, urlParameters);
|
|
1069
1070
|
};
|
|
1070
1071
|
|
|
1071
|
-
const h3TilesetSource
|
|
1072
|
+
const h3TilesetSource = async function (options) {
|
|
1072
1073
|
const {
|
|
1073
1074
|
tableName
|
|
1074
1075
|
} = options;
|
|
@@ -1132,7 +1133,7 @@ const quadbinTableSource$1 = async function (options) {
|
|
|
1132
1133
|
return baseSource('table', options, urlParameters);
|
|
1133
1134
|
};
|
|
1134
1135
|
|
|
1135
|
-
const quadbinTilesetSource
|
|
1136
|
+
const quadbinTilesetSource = async function (options) {
|
|
1136
1137
|
const {
|
|
1137
1138
|
tableName
|
|
1138
1139
|
} = options;
|
|
@@ -1194,7 +1195,7 @@ const vectorTableSource$1 = async function (options) {
|
|
|
1194
1195
|
return baseSource('table', options, urlParameters);
|
|
1195
1196
|
};
|
|
1196
1197
|
|
|
1197
|
-
const vectorTilesetSource
|
|
1198
|
+
const vectorTilesetSource = async function (options) {
|
|
1198
1199
|
const {
|
|
1199
1200
|
tableName
|
|
1200
1201
|
} = options;
|
|
@@ -1209,29 +1210,22 @@ const vectorTilesetSource$1 = async function (options) {
|
|
|
1209
1210
|
boundaryTableSource,
|
|
1210
1211
|
h3QuerySource: h3QuerySource$1,
|
|
1211
1212
|
h3TableSource: h3TableSource$1,
|
|
1212
|
-
h3TilesetSource
|
|
1213
|
+
h3TilesetSource,
|
|
1213
1214
|
rasterSource,
|
|
1214
1215
|
quadbinQuerySource: quadbinQuerySource$1,
|
|
1215
1216
|
quadbinTableSource: quadbinTableSource$1,
|
|
1216
|
-
quadbinTilesetSource
|
|
1217
|
+
quadbinTilesetSource,
|
|
1217
1218
|
vectorQuerySource: vectorQuerySource$1,
|
|
1218
1219
|
vectorTableSource: vectorTableSource$1,
|
|
1219
|
-
vectorTilesetSource
|
|
1220
|
+
vectorTilesetSource
|
|
1220
1221
|
});
|
|
1221
1222
|
|
|
1222
1223
|
/** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1223
1224
|
|
|
1224
|
-
/** Wrapper adding Widget API support to [quadbinTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1225
|
-
const quadbinTilesetSource = function () {
|
|
1226
|
-
try {
|
|
1227
|
-
throw new Error('not implemented');
|
|
1228
|
-
} catch (e) {
|
|
1229
|
-
return Promise.reject(e);
|
|
1230
|
-
}
|
|
1231
|
-
};
|
|
1232
1225
|
/** Wrapper adding Widget API support to [quadbinQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1233
1226
|
const quadbinQuerySource = function (props) {
|
|
1234
1227
|
try {
|
|
1228
|
+
assignDefaultProps(props);
|
|
1235
1229
|
return Promise.resolve(quadbinQuerySource$1(props)).then(function (response) {
|
|
1236
1230
|
return {
|
|
1237
1231
|
...response,
|
|
@@ -1245,6 +1239,7 @@ const quadbinQuerySource = function (props) {
|
|
|
1245
1239
|
/** Wrapper adding Widget API support to [quadbinTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1246
1240
|
const quadbinTableSource = function (props) {
|
|
1247
1241
|
try {
|
|
1242
|
+
assignDefaultProps(props);
|
|
1248
1243
|
return Promise.resolve(quadbinTableSource$1(props)).then(function (response) {
|
|
1249
1244
|
return {
|
|
1250
1245
|
...response,
|
|
@@ -1255,17 +1250,10 @@ const quadbinTableSource = function (props) {
|
|
|
1255
1250
|
return Promise.reject(e);
|
|
1256
1251
|
}
|
|
1257
1252
|
};
|
|
1258
|
-
/** Wrapper adding Widget API support to [h3TilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1259
|
-
const h3TilesetSource = function () {
|
|
1260
|
-
try {
|
|
1261
|
-
throw new Error('not implemented');
|
|
1262
|
-
} catch (e) {
|
|
1263
|
-
return Promise.reject(e);
|
|
1264
|
-
}
|
|
1265
|
-
};
|
|
1266
1253
|
/** Wrapper adding Widget API support to [h3QuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1267
1254
|
const h3QuerySource = function (props) {
|
|
1268
1255
|
try {
|
|
1256
|
+
assignDefaultProps(props);
|
|
1269
1257
|
return Promise.resolve(h3QuerySource$1(props)).then(function (response) {
|
|
1270
1258
|
return {
|
|
1271
1259
|
...response,
|
|
@@ -1279,6 +1267,7 @@ const h3QuerySource = function (props) {
|
|
|
1279
1267
|
/** Wrapper adding Widget API support to [h3TableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1280
1268
|
const h3TableSource = function (props) {
|
|
1281
1269
|
try {
|
|
1270
|
+
assignDefaultProps(props);
|
|
1282
1271
|
return Promise.resolve(h3TableSource$1(props)).then(function (response) {
|
|
1283
1272
|
return {
|
|
1284
1273
|
...response,
|
|
@@ -1289,17 +1278,10 @@ const h3TableSource = function (props) {
|
|
|
1289
1278
|
return Promise.reject(e);
|
|
1290
1279
|
}
|
|
1291
1280
|
};
|
|
1292
|
-
/** Wrapper adding Widget API support to [vectorTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1293
|
-
const vectorTilesetSource = function () {
|
|
1294
|
-
try {
|
|
1295
|
-
throw new Error('not implemented');
|
|
1296
|
-
} catch (e) {
|
|
1297
|
-
return Promise.reject(e);
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
1281
|
/** Wrapper adding Widget API support to [vectorQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1301
1282
|
const vectorQuerySource = function (props) {
|
|
1302
1283
|
try {
|
|
1284
|
+
assignDefaultProps(props);
|
|
1303
1285
|
return Promise.resolve(vectorQuerySource$1(props)).then(function (response) {
|
|
1304
1286
|
return {
|
|
1305
1287
|
...response,
|
|
@@ -1312,6 +1294,7 @@ const vectorQuerySource = function (props) {
|
|
|
1312
1294
|
};
|
|
1313
1295
|
const vectorTableSource = function (props) {
|
|
1314
1296
|
try {
|
|
1297
|
+
assignDefaultProps(props);
|
|
1315
1298
|
return Promise.resolve(vectorTableSource$1(props)).then(function (response) {
|
|
1316
1299
|
return {
|
|
1317
1300
|
...response,
|
|
@@ -1322,6 +1305,14 @@ const vectorTableSource = function (props) {
|
|
|
1322
1305
|
return Promise.reject(e);
|
|
1323
1306
|
}
|
|
1324
1307
|
};
|
|
1308
|
+
function assignDefaultProps(props) {
|
|
1309
|
+
if (typeof deck !== 'undefined' && deck && deck.VERSION) {
|
|
1310
|
+
props.clientId ||= 'deck-gl-carto';
|
|
1311
|
+
// TODO: Uncomment if/when `@deck.gl/carto` devDependency is removed,
|
|
1312
|
+
// and source functions are moved here rather than wrapped.
|
|
1313
|
+
// props.deckglVersion ||= deck.VERSION;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1325
1316
|
|
|
1326
1317
|
exports.WidgetBaseSource = WidgetBaseSource;
|
|
1327
1318
|
exports.WidgetQuerySource = WidgetQuerySource;
|
|
@@ -1329,12 +1320,9 @@ exports.WidgetTableSource = WidgetTableSource;
|
|
|
1329
1320
|
exports.getClient = getClient;
|
|
1330
1321
|
exports.h3QuerySource = h3QuerySource;
|
|
1331
1322
|
exports.h3TableSource = h3TableSource;
|
|
1332
|
-
exports.h3TilesetSource = h3TilesetSource;
|
|
1333
1323
|
exports.quadbinQuerySource = quadbinQuerySource;
|
|
1334
1324
|
exports.quadbinTableSource = quadbinTableSource;
|
|
1335
|
-
exports.quadbinTilesetSource = quadbinTilesetSource;
|
|
1336
1325
|
exports.setClient = setClient;
|
|
1337
1326
|
exports.vectorQuerySource = vectorQuerySource;
|
|
1338
1327
|
exports.vectorTableSource = vectorTableSource;
|
|
1339
|
-
exports.vectorTilesetSource = vectorTilesetSource;
|
|
1340
1328
|
//# sourceMappingURL=api-client.cjs.map
|