@carto/api-client 0.0.1-0 → 0.0.1-2
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/CHANGELOG.md +7 -0
- package/README.md +125 -13
- package/build/api-client.cjs +336 -198
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +327 -193
- package/build/api-client.modern.js.map +1 -1
- package/build/client.d.ts +12 -2
- package/build/constants-internal.d.ts +23 -5
- package/build/constants.d.ts +19 -15
- package/build/index.d.ts +0 -1
- package/build/models/common.d.ts +2 -5
- package/build/models/model.d.ts +18 -4
- package/build/sources/types.d.ts +30 -14
- package/build/sources/widget-base-source.d.ts +73 -18
- package/build/sources/widget-query-source.d.ts +25 -3
- package/build/sources/widget-table-source.d.ts +25 -3
- package/build/sources/wrappers.d.ts +21 -14
- package/build/types.d.ts +14 -28
- package/package.json +4 -6
- package/src/client.ts +14 -6
- package/src/constants-internal.ts +26 -5
- package/src/constants.ts +19 -18
- package/src/index.ts +0 -1
- package/src/models/common.ts +8 -18
- package/src/models/model.ts +44 -27
- package/src/sources/types.ts +32 -16
- package/src/sources/widget-base-source.ts +164 -104
- package/src/sources/widget-query-source.ts +30 -7
- package/src/sources/widget-table-source.ts +29 -7
- package/src/sources/wrappers.ts +38 -21
- package/src/types.ts +24 -32
package/build/api-client.cjs
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* @internalRemarks Source: @carto/react-core
|
|
4
|
+
*/
|
|
5
|
+
let client = 'carto-api-client';
|
|
6
|
+
/**
|
|
7
|
+
* Returns current client ID, used to categorize API requests. For internal use only.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
* @internalRemarks Source: @carto/react-core
|
|
11
|
+
*/
|
|
12
|
+
function getClient() {
|
|
13
|
+
return client;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets current client ID, used to categorize API requests. For internal use only.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
* @internalRemarks Source: @carto/react-core
|
|
20
|
+
*/
|
|
21
|
+
function setClient(c) {
|
|
22
|
+
client = c;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
|
|
27
|
+
*
|
|
28
|
+
* @internalRemarks Source: @carto/react-core
|
|
29
|
+
*/
|
|
17
30
|
exports.GroupDateType = void 0;
|
|
18
31
|
(function (GroupDateType) {
|
|
19
32
|
GroupDateType["YEARS"] = "year";
|
|
@@ -24,7 +37,20 @@ exports.GroupDateType = void 0;
|
|
|
24
37
|
GroupDateType["MINUTES"] = "minute";
|
|
25
38
|
GroupDateType["SECONDS"] = "second";
|
|
26
39
|
})(exports.GroupDateType || (exports.GroupDateType = {}));
|
|
27
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* Defines a comparator used when matching a column's values against given filter values.
|
|
42
|
+
*
|
|
43
|
+
* Example:
|
|
44
|
+
*
|
|
45
|
+
* ```javascript
|
|
46
|
+
* import { FilterType } from '@carto/api-client';
|
|
47
|
+
* const filters = {
|
|
48
|
+
* column_name: { [FilterType.IN]: { values: ['a', 'b', 'c'] } }
|
|
49
|
+
* };
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @internalRemarks Source: @carto/react-api, @deck.gl/carto
|
|
53
|
+
*/
|
|
28
54
|
exports.FilterType = void 0;
|
|
29
55
|
(function (FilterType) {
|
|
30
56
|
FilterType["IN"] = "in";
|
|
@@ -36,26 +62,9 @@ exports.FilterType = void 0;
|
|
|
36
62
|
FilterType["STRING_SEARCH"] = "stringSearch";
|
|
37
63
|
})(exports.FilterType || (exports.FilterType = {}));
|
|
38
64
|
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
* @internalRemarks Source: @carto/react-core
|
|
42
|
-
*/
|
|
43
|
-
let client = CLIENT_ID;
|
|
44
|
-
/** @internalRemarks Source: @carto/react-core */
|
|
45
|
-
function getClient() {
|
|
46
|
-
return client;
|
|
47
|
-
}
|
|
48
|
-
/** @internalRemarks Source: @carto/react-core */
|
|
49
|
-
function setClient(c) {
|
|
50
|
-
client = c;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Threshold to use GET requests, vs POST
|
|
55
|
-
* @internalRemarks Source: @carto/constants
|
|
56
|
-
* @internal
|
|
65
|
+
/******************************************************************************
|
|
66
|
+
* DEFAULTS
|
|
57
67
|
*/
|
|
58
|
-
const REQUEST_GET_MAX_URL_LENGTH = 2048;
|
|
59
68
|
/**
|
|
60
69
|
* @internalRemarks Source: @carto/constants
|
|
61
70
|
* @internal
|
|
@@ -66,6 +75,29 @@ const DEFAULT_API_BASE_URL$1 = 'https://gcp-us-east1.api.carto.com';
|
|
|
66
75
|
* @internal
|
|
67
76
|
*/
|
|
68
77
|
const DEFAULT_GEO_COLUMN = 'geom';
|
|
78
|
+
/******************************************************************************
|
|
79
|
+
* ENUMS
|
|
80
|
+
*/
|
|
81
|
+
/**
|
|
82
|
+
* @internal
|
|
83
|
+
* @internalRemarks Source: @carto/constants
|
|
84
|
+
*/
|
|
85
|
+
var MapType;
|
|
86
|
+
(function (MapType) {
|
|
87
|
+
MapType["TABLE"] = "table";
|
|
88
|
+
MapType["QUERY"] = "query";
|
|
89
|
+
MapType["TILESET"] = "tileset";
|
|
90
|
+
})(MapType || (MapType = {}));
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
* @internalRemarks Source: @carto/constants
|
|
94
|
+
*/
|
|
95
|
+
var ApiVersion;
|
|
96
|
+
(function (ApiVersion) {
|
|
97
|
+
ApiVersion["V1"] = "v1";
|
|
98
|
+
ApiVersion["V2"] = "v2";
|
|
99
|
+
ApiVersion["V3"] = "v3";
|
|
100
|
+
})(ApiVersion || (ApiVersion = {}));
|
|
69
101
|
|
|
70
102
|
const FILTER_TYPES = new Set(Object.values(exports.FilterType));
|
|
71
103
|
const isFilterType = type => FILTER_TYPES.has(type);
|
|
@@ -149,7 +181,7 @@ function _catch(body, recover) {
|
|
|
149
181
|
const makeCall = function (_ref2) {
|
|
150
182
|
let {
|
|
151
183
|
url,
|
|
152
|
-
|
|
184
|
+
accessToken,
|
|
153
185
|
opts
|
|
154
186
|
} = _ref2;
|
|
155
187
|
try {
|
|
@@ -170,15 +202,15 @@ const makeCall = function (_ref2) {
|
|
|
170
202
|
const _temp = _catch(function () {
|
|
171
203
|
return Promise.resolve(fetch(url.toString(), {
|
|
172
204
|
headers: {
|
|
173
|
-
Authorization: `Bearer ${
|
|
174
|
-
...(isPost
|
|
205
|
+
Authorization: `Bearer ${accessToken}`,
|
|
206
|
+
...(isPost && {
|
|
175
207
|
'Content-Type': 'application/json'
|
|
176
|
-
}
|
|
208
|
+
})
|
|
177
209
|
},
|
|
178
|
-
...(isPost
|
|
210
|
+
...(isPost && {
|
|
179
211
|
method: opts?.method,
|
|
180
212
|
body: opts?.body
|
|
181
|
-
}
|
|
213
|
+
}),
|
|
182
214
|
signal: opts?.abortController?.signal,
|
|
183
215
|
...opts?.otherOptions
|
|
184
216
|
})).then(function (_fetch) {
|
|
@@ -217,15 +249,13 @@ function dealWithApiError(_ref) {
|
|
|
217
249
|
throw new Error(msg);
|
|
218
250
|
}
|
|
219
251
|
}
|
|
220
|
-
/** @internalRemarks Source: @carto/react-api */
|
|
221
|
-
function checkCredentials(credentials) {
|
|
222
|
-
if (!credentials || !credentials.apiBaseUrl || !credentials.accessToken) {
|
|
223
|
-
throw new Error('Missing or bad credentials provided');
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
252
|
|
|
227
253
|
/** @internalRemarks Source: @carto/react-api */
|
|
228
254
|
const AVAILABLE_MODELS = ['category', 'histogram', 'formula', 'timeseries', 'range', 'scatterplot', 'table'];
|
|
255
|
+
const {
|
|
256
|
+
V3
|
|
257
|
+
} = ApiVersion;
|
|
258
|
+
const REQUEST_GET_MAX_URL_LENGTH = 2048;
|
|
229
259
|
/**
|
|
230
260
|
* Execute a SQL model request.
|
|
231
261
|
* @internalRemarks Source: @carto/react-api
|
|
@@ -234,23 +264,29 @@ function executeModel(props) {
|
|
|
234
264
|
assert(props.source, 'executeModel: missing source');
|
|
235
265
|
assert(props.model, 'executeModel: missing model');
|
|
236
266
|
assert(props.params, 'executeModel: missing params');
|
|
237
|
-
assert(AVAILABLE_MODELS.
|
|
267
|
+
assert(AVAILABLE_MODELS.includes(props.model), `executeModel: model provided isn't valid. Available models: ${AVAILABLE_MODELS.join(', ')}`);
|
|
238
268
|
const {
|
|
239
|
-
source,
|
|
240
269
|
model,
|
|
270
|
+
source,
|
|
241
271
|
params,
|
|
242
|
-
spatialFilter,
|
|
243
272
|
opts
|
|
244
273
|
} = props;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
274
|
+
const {
|
|
275
|
+
type,
|
|
276
|
+
apiVersion,
|
|
277
|
+
apiBaseUrl,
|
|
278
|
+
accessToken,
|
|
279
|
+
connectionName
|
|
280
|
+
} = source;
|
|
281
|
+
assert(apiBaseUrl, 'executeModel: missing apiBaseUrl');
|
|
282
|
+
assert(accessToken, 'executeModel: missing accessToken');
|
|
283
|
+
assert(apiVersion === V3, 'executeModel: SQL Model API requires CARTO 3+');
|
|
284
|
+
assert(type !== MapType.TILESET, 'executeModel: Tilesets not supported');
|
|
285
|
+
let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
|
|
249
286
|
const {
|
|
250
287
|
filters,
|
|
251
288
|
filtersLogicalOperator = 'and',
|
|
252
|
-
data
|
|
253
|
-
type
|
|
289
|
+
data
|
|
254
290
|
} = source;
|
|
255
291
|
const queryParameters = source.queryParameters ? JSON.stringify(source.queryParameters) : '';
|
|
256
292
|
const queryParams = {
|
|
@@ -263,8 +299,8 @@ function executeModel(props) {
|
|
|
263
299
|
filtersLogicalOperator
|
|
264
300
|
};
|
|
265
301
|
// API supports multiple filters, we apply it only to geoColumn
|
|
266
|
-
const spatialFilters = spatialFilter ? {
|
|
267
|
-
[source.geoColumn ? source.geoColumn : DEFAULT_GEO_COLUMN]: spatialFilter
|
|
302
|
+
const spatialFilters = source.spatialFilter ? {
|
|
303
|
+
[source.geoColumn ? source.geoColumn : DEFAULT_GEO_COLUMN]: source.spatialFilter
|
|
268
304
|
} : undefined;
|
|
269
305
|
if (spatialFilters) {
|
|
270
306
|
queryParams.spatialFilters = JSON.stringify(spatialFilters);
|
|
@@ -284,7 +320,7 @@ function executeModel(props) {
|
|
|
284
320
|
}
|
|
285
321
|
return makeCall({
|
|
286
322
|
url,
|
|
287
|
-
|
|
323
|
+
accessToken: source.accessToken,
|
|
288
324
|
opts: {
|
|
289
325
|
...opts,
|
|
290
326
|
method: isGet ? 'GET' : 'POST',
|
|
@@ -295,95 +331,120 @@ function executeModel(props) {
|
|
|
295
331
|
});
|
|
296
332
|
}
|
|
297
333
|
|
|
334
|
+
/**
|
|
335
|
+
* Source for Widget API requests on a data source defined by a SQL query.
|
|
336
|
+
*
|
|
337
|
+
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
338
|
+
*/
|
|
298
339
|
class WidgetBaseSource {
|
|
299
340
|
constructor(props) {
|
|
300
341
|
this.props = void 0;
|
|
301
|
-
this.credentials = void 0;
|
|
302
|
-
this.connectionName = void 0;
|
|
303
342
|
this.props = {
|
|
304
343
|
...WidgetBaseSource.defaultProps,
|
|
305
344
|
...props
|
|
306
345
|
};
|
|
307
|
-
this.connectionName = props.connectionName;
|
|
308
|
-
this.credentials = {
|
|
309
|
-
apiVersion: props.apiVersion || exports.ApiVersion.V3,
|
|
310
|
-
apiBaseUrl: props.apiBaseUrl || DEFAULT_API_BASE_URL$1,
|
|
311
|
-
clientId: props.clientId || getClient(),
|
|
312
|
-
accessToken: props.accessToken,
|
|
313
|
-
geoColumn: props.geoColumn || DEFAULT_GEO_COLUMN
|
|
314
|
-
};
|
|
315
346
|
}
|
|
316
|
-
|
|
347
|
+
_getModelSource(owner) {
|
|
348
|
+
const props = this.props;
|
|
317
349
|
return {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
350
|
+
apiVersion: props.apiVersion,
|
|
351
|
+
apiBaseUrl: props.apiBaseUrl,
|
|
352
|
+
clientId: props.clientId,
|
|
353
|
+
accessToken: props.accessToken,
|
|
354
|
+
connectionName: props.connectionName,
|
|
355
|
+
filters: getApplicableFilters(owner, props.filters),
|
|
356
|
+
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
357
|
+
geoColumn: props.geoColumn
|
|
322
358
|
};
|
|
323
359
|
}
|
|
324
|
-
|
|
360
|
+
/****************************************************************************
|
|
361
|
+
* CATEGORIES
|
|
362
|
+
*/
|
|
363
|
+
/**
|
|
364
|
+
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
365
|
+
* charts including grouped bar charts, pie charts, and tree charts.
|
|
366
|
+
*/
|
|
367
|
+
getCategories(props) {
|
|
325
368
|
try {
|
|
326
369
|
const _this = this;
|
|
327
370
|
const {
|
|
328
371
|
filterOwner,
|
|
329
372
|
spatialFilter,
|
|
330
373
|
abortController,
|
|
331
|
-
operationExp,
|
|
332
374
|
...params
|
|
333
375
|
} = props;
|
|
334
376
|
const {
|
|
335
377
|
column,
|
|
336
|
-
operation
|
|
378
|
+
operation,
|
|
379
|
+
operationColumn
|
|
337
380
|
} = params;
|
|
338
381
|
return Promise.resolve(executeModel({
|
|
339
|
-
model: '
|
|
340
|
-
source:
|
|
341
|
-
|
|
382
|
+
model: 'category',
|
|
383
|
+
source: {
|
|
384
|
+
..._this.getModelSource(filterOwner),
|
|
385
|
+
spatialFilter
|
|
386
|
+
},
|
|
342
387
|
params: {
|
|
343
|
-
column
|
|
388
|
+
column,
|
|
344
389
|
operation,
|
|
345
|
-
|
|
390
|
+
operationColumn: operationColumn || column
|
|
346
391
|
},
|
|
347
392
|
opts: {
|
|
348
393
|
abortController
|
|
349
394
|
}
|
|
350
|
-
}).then(res => normalizeObjectKeys(res.rows
|
|
395
|
+
}).then(res => normalizeObjectKeys(res.rows)));
|
|
351
396
|
} catch (e) {
|
|
352
397
|
return Promise.reject(e);
|
|
353
398
|
}
|
|
354
399
|
}
|
|
355
|
-
|
|
400
|
+
/****************************************************************************
|
|
401
|
+
* FORMULA
|
|
402
|
+
*/
|
|
403
|
+
/**
|
|
404
|
+
* Returns a scalar numerical statistic over all matching data. Suitable
|
|
405
|
+
* for 'headline' or 'scorecard' figures such as counts and sums.
|
|
406
|
+
*/
|
|
407
|
+
getFormula(props) {
|
|
356
408
|
try {
|
|
357
409
|
const _this2 = this;
|
|
358
410
|
const {
|
|
359
411
|
filterOwner,
|
|
360
412
|
spatialFilter,
|
|
361
413
|
abortController,
|
|
414
|
+
operationExp,
|
|
362
415
|
...params
|
|
363
416
|
} = props;
|
|
364
417
|
const {
|
|
365
418
|
column,
|
|
366
|
-
operation
|
|
367
|
-
operationColumn
|
|
419
|
+
operation
|
|
368
420
|
} = params;
|
|
369
421
|
return Promise.resolve(executeModel({
|
|
370
|
-
model: '
|
|
371
|
-
source:
|
|
372
|
-
|
|
422
|
+
model: 'formula',
|
|
423
|
+
source: {
|
|
424
|
+
..._this2.getModelSource(filterOwner),
|
|
425
|
+
spatialFilter
|
|
426
|
+
},
|
|
373
427
|
params: {
|
|
374
|
-
column,
|
|
428
|
+
column: column ?? '*',
|
|
375
429
|
operation,
|
|
376
|
-
|
|
430
|
+
operationExp
|
|
377
431
|
},
|
|
378
432
|
opts: {
|
|
379
433
|
abortController
|
|
380
434
|
}
|
|
381
|
-
}).then(res => normalizeObjectKeys(res.rows)));
|
|
435
|
+
}).then(res => normalizeObjectKeys(res.rows[0])));
|
|
382
436
|
} catch (e) {
|
|
383
437
|
return Promise.reject(e);
|
|
384
438
|
}
|
|
385
439
|
}
|
|
386
|
-
|
|
440
|
+
/****************************************************************************
|
|
441
|
+
* HISTOGRAM
|
|
442
|
+
*/
|
|
443
|
+
/**
|
|
444
|
+
* Returns a list of labeled datapoints for 'bins' of data defined as ticks
|
|
445
|
+
* over a numerical range. Suitable for histogram charts.
|
|
446
|
+
*/
|
|
447
|
+
getHistogram(props) {
|
|
387
448
|
try {
|
|
388
449
|
const _this3 = this;
|
|
389
450
|
const {
|
|
@@ -393,24 +454,53 @@ class WidgetBaseSource {
|
|
|
393
454
|
...params
|
|
394
455
|
} = props;
|
|
395
456
|
const {
|
|
396
|
-
column
|
|
457
|
+
column,
|
|
458
|
+
operation,
|
|
459
|
+
ticks
|
|
397
460
|
} = params;
|
|
398
461
|
return Promise.resolve(executeModel({
|
|
399
|
-
model: '
|
|
400
|
-
source:
|
|
401
|
-
|
|
462
|
+
model: 'histogram',
|
|
463
|
+
source: {
|
|
464
|
+
..._this3.getModelSource(filterOwner),
|
|
465
|
+
spatialFilter
|
|
466
|
+
},
|
|
402
467
|
params: {
|
|
403
|
-
column
|
|
468
|
+
column,
|
|
469
|
+
operation,
|
|
470
|
+
ticks
|
|
404
471
|
},
|
|
405
472
|
opts: {
|
|
406
473
|
abortController
|
|
407
474
|
}
|
|
408
|
-
}).then(res => normalizeObjectKeys(res.rows
|
|
475
|
+
}).then(res => normalizeObjectKeys(res.rows))).then(function (data) {
|
|
476
|
+
if (data.length) {
|
|
477
|
+
// Given N ticks the API returns up to N+1 bins, omitting any empty bins. Bins
|
|
478
|
+
// include 1 bin below the lowest tick, N-1 between ticks, and 1 bin above the highest tick.
|
|
479
|
+
const result = Array(ticks.length + 1).fill(0);
|
|
480
|
+
data.forEach(_ref => {
|
|
481
|
+
let {
|
|
482
|
+
tick,
|
|
483
|
+
value
|
|
484
|
+
} = _ref;
|
|
485
|
+
return result[tick] = value;
|
|
486
|
+
});
|
|
487
|
+
return result;
|
|
488
|
+
}
|
|
489
|
+
return [];
|
|
490
|
+
});
|
|
409
491
|
} catch (e) {
|
|
410
492
|
return Promise.reject(e);
|
|
411
493
|
}
|
|
412
494
|
}
|
|
413
|
-
|
|
495
|
+
/****************************************************************************
|
|
496
|
+
* RANGE
|
|
497
|
+
*/
|
|
498
|
+
/**
|
|
499
|
+
* Returns a range (min and max) for a numerical column of matching rows.
|
|
500
|
+
* Suitable for displaying certain 'headline' or 'scorecard' statistics,
|
|
501
|
+
* or rendering a range slider UI for filtering.
|
|
502
|
+
*/
|
|
503
|
+
getRange(props) {
|
|
414
504
|
try {
|
|
415
505
|
const _this4 = this;
|
|
416
506
|
const {
|
|
@@ -420,34 +510,32 @@ class WidgetBaseSource {
|
|
|
420
510
|
...params
|
|
421
511
|
} = props;
|
|
422
512
|
const {
|
|
423
|
-
|
|
424
|
-
sortBy,
|
|
425
|
-
sortDirection,
|
|
426
|
-
page = 0,
|
|
427
|
-
rowsPerPage = 10
|
|
513
|
+
column
|
|
428
514
|
} = params;
|
|
429
515
|
return Promise.resolve(executeModel({
|
|
430
|
-
model: '
|
|
431
|
-
source:
|
|
432
|
-
|
|
516
|
+
model: 'range',
|
|
517
|
+
source: {
|
|
518
|
+
..._this4.getModelSource(filterOwner),
|
|
519
|
+
spatialFilter
|
|
520
|
+
},
|
|
433
521
|
params: {
|
|
434
|
-
column
|
|
435
|
-
sortBy,
|
|
436
|
-
sortDirection,
|
|
437
|
-
limit: rowsPerPage,
|
|
438
|
-
offset: page * rowsPerPage
|
|
522
|
+
column
|
|
439
523
|
},
|
|
440
524
|
opts: {
|
|
441
525
|
abortController
|
|
442
526
|
}
|
|
443
|
-
}).then(res => (
|
|
444
|
-
rows: normalizeObjectKeys(res.rows),
|
|
445
|
-
totalCount: res.metadata.total
|
|
446
|
-
})));
|
|
527
|
+
}).then(res => normalizeObjectKeys(res.rows[0])));
|
|
447
528
|
} catch (e) {
|
|
448
529
|
return Promise.reject(e);
|
|
449
530
|
}
|
|
450
531
|
}
|
|
532
|
+
/****************************************************************************
|
|
533
|
+
* SCATTER
|
|
534
|
+
*/
|
|
535
|
+
/**
|
|
536
|
+
* Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
|
|
537
|
+
* values. Suitable for rendering scatter plots.
|
|
538
|
+
*/
|
|
451
539
|
getScatter(props) {
|
|
452
540
|
try {
|
|
453
541
|
const _this5 = this;
|
|
@@ -467,8 +555,10 @@ class WidgetBaseSource {
|
|
|
467
555
|
const HARD_LIMIT = 500;
|
|
468
556
|
return Promise.resolve(executeModel({
|
|
469
557
|
model: 'scatterplot',
|
|
470
|
-
source:
|
|
471
|
-
|
|
558
|
+
source: {
|
|
559
|
+
..._this5.getModelSource(filterOwner),
|
|
560
|
+
spatialFilter
|
|
561
|
+
},
|
|
472
562
|
params: {
|
|
473
563
|
xAxisColumn,
|
|
474
564
|
xAxisJoinOperation,
|
|
@@ -479,130 +569,189 @@ class WidgetBaseSource {
|
|
|
479
569
|
opts: {
|
|
480
570
|
abortController
|
|
481
571
|
}
|
|
482
|
-
}).then(res => normalizeObjectKeys(res.rows)).then(res => res.map(
|
|
572
|
+
}).then(res => normalizeObjectKeys(res.rows)).then(res => res.map(_ref2 => {
|
|
483
573
|
let {
|
|
484
574
|
x,
|
|
485
575
|
y
|
|
486
|
-
} =
|
|
576
|
+
} = _ref2;
|
|
487
577
|
return [x, y];
|
|
488
578
|
})));
|
|
489
579
|
} catch (e) {
|
|
490
580
|
return Promise.reject(e);
|
|
491
581
|
}
|
|
492
582
|
}
|
|
493
|
-
|
|
583
|
+
/****************************************************************************
|
|
584
|
+
* TABLE
|
|
585
|
+
*/
|
|
586
|
+
/**
|
|
587
|
+
* Returns a list of arbitrary data rows, with support for pagination and
|
|
588
|
+
* sorting. Suitable for displaying tables and lists.
|
|
589
|
+
*/
|
|
590
|
+
getTable(props) {
|
|
494
591
|
try {
|
|
495
592
|
const _this6 = this;
|
|
496
593
|
const {
|
|
497
594
|
filterOwner,
|
|
498
|
-
abortController,
|
|
499
595
|
spatialFilter,
|
|
596
|
+
abortController,
|
|
500
597
|
...params
|
|
501
598
|
} = props;
|
|
502
599
|
const {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
stepMultiplier,
|
|
509
|
-
splitByCategory,
|
|
510
|
-
splitByCategoryLimit,
|
|
511
|
-
splitByCategoryValues
|
|
600
|
+
columns,
|
|
601
|
+
sortBy,
|
|
602
|
+
sortDirection,
|
|
603
|
+
page = 0,
|
|
604
|
+
rowsPerPage = 10
|
|
512
605
|
} = params;
|
|
513
606
|
return Promise.resolve(executeModel({
|
|
514
|
-
model: '
|
|
515
|
-
source:
|
|
516
|
-
|
|
607
|
+
model: 'table',
|
|
608
|
+
source: {
|
|
609
|
+
..._this6.getModelSource(filterOwner),
|
|
610
|
+
spatialFilter
|
|
611
|
+
},
|
|
517
612
|
params: {
|
|
518
|
-
column,
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
operation,
|
|
524
|
-
splitByCategory,
|
|
525
|
-
splitByCategoryLimit,
|
|
526
|
-
splitByCategoryValues
|
|
613
|
+
column: columns,
|
|
614
|
+
sortBy,
|
|
615
|
+
sortDirection,
|
|
616
|
+
limit: rowsPerPage,
|
|
617
|
+
offset: page * rowsPerPage
|
|
527
618
|
},
|
|
528
619
|
opts: {
|
|
529
620
|
abortController
|
|
530
621
|
}
|
|
531
622
|
}).then(res => ({
|
|
532
623
|
rows: normalizeObjectKeys(res.rows),
|
|
533
|
-
|
|
624
|
+
totalCount: res.metadata.total
|
|
534
625
|
})));
|
|
535
626
|
} catch (e) {
|
|
536
627
|
return Promise.reject(e);
|
|
537
628
|
}
|
|
538
629
|
}
|
|
539
|
-
|
|
630
|
+
/****************************************************************************
|
|
631
|
+
* TIME SERIES
|
|
632
|
+
*/
|
|
633
|
+
/**
|
|
634
|
+
* Returns a series of labeled numerical values, grouped into equally-sized
|
|
635
|
+
* time intervals. Suitable for rendering time series charts.
|
|
636
|
+
*/
|
|
637
|
+
getTimeSeries(props) {
|
|
540
638
|
try {
|
|
541
639
|
const _this7 = this;
|
|
542
640
|
const {
|
|
543
641
|
filterOwner,
|
|
544
|
-
spatialFilter,
|
|
545
642
|
abortController,
|
|
643
|
+
spatialFilter,
|
|
546
644
|
...params
|
|
547
645
|
} = props;
|
|
548
646
|
const {
|
|
549
647
|
column,
|
|
648
|
+
operationColumn,
|
|
649
|
+
joinOperation,
|
|
550
650
|
operation,
|
|
551
|
-
|
|
651
|
+
stepSize,
|
|
652
|
+
stepMultiplier,
|
|
653
|
+
splitByCategory,
|
|
654
|
+
splitByCategoryLimit,
|
|
655
|
+
splitByCategoryValues
|
|
552
656
|
} = params;
|
|
553
657
|
return Promise.resolve(executeModel({
|
|
554
|
-
model: '
|
|
555
|
-
source:
|
|
556
|
-
|
|
658
|
+
model: 'timeseries',
|
|
659
|
+
source: {
|
|
660
|
+
..._this7.getModelSource(filterOwner),
|
|
661
|
+
spatialFilter
|
|
662
|
+
},
|
|
557
663
|
params: {
|
|
558
664
|
column,
|
|
665
|
+
stepSize,
|
|
666
|
+
stepMultiplier,
|
|
667
|
+
operationColumn: operationColumn || column,
|
|
668
|
+
joinOperation,
|
|
559
669
|
operation,
|
|
560
|
-
|
|
670
|
+
splitByCategory,
|
|
671
|
+
splitByCategoryLimit,
|
|
672
|
+
splitByCategoryValues
|
|
561
673
|
},
|
|
562
674
|
opts: {
|
|
563
675
|
abortController
|
|
564
676
|
}
|
|
565
|
-
}).then(res =>
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const result = Array(ticks.length + 1).fill(0);
|
|
570
|
-
data.forEach(_ref2 => {
|
|
571
|
-
let {
|
|
572
|
-
tick,
|
|
573
|
-
value
|
|
574
|
-
} = _ref2;
|
|
575
|
-
return result[tick] = value;
|
|
576
|
-
});
|
|
577
|
-
return result;
|
|
578
|
-
}
|
|
579
|
-
return [];
|
|
580
|
-
});
|
|
677
|
+
}).then(res => ({
|
|
678
|
+
rows: normalizeObjectKeys(res.rows),
|
|
679
|
+
categories: res.metadata?.categories
|
|
680
|
+
})));
|
|
581
681
|
} catch (e) {
|
|
582
682
|
return Promise.reject(e);
|
|
583
683
|
}
|
|
584
684
|
}
|
|
585
685
|
}
|
|
586
686
|
WidgetBaseSource.defaultProps = {
|
|
687
|
+
apiVersion: ApiVersion.V3,
|
|
688
|
+
apiBaseUrl: DEFAULT_API_BASE_URL$1,
|
|
689
|
+
clientId: getClient(),
|
|
587
690
|
filters: {},
|
|
588
|
-
filtersLogicalOperator: 'and'
|
|
691
|
+
filtersLogicalOperator: 'and',
|
|
692
|
+
geoColumn: DEFAULT_GEO_COLUMN
|
|
589
693
|
};
|
|
590
694
|
|
|
695
|
+
/**
|
|
696
|
+
* Source for Widget API requests on a data source defined by a SQL query.
|
|
697
|
+
*
|
|
698
|
+
* Generally not intended to be constructed directly. Instead, call
|
|
699
|
+
* {@link vectorQuerySource}, {@link h3QuerySource}, or {@link quadbinQuerySource},
|
|
700
|
+
* which can be shared with map layers. Sources contain a `widgetSource` property,
|
|
701
|
+
* for use by widget implementations.
|
|
702
|
+
*
|
|
703
|
+
* Example:
|
|
704
|
+
*
|
|
705
|
+
* ```javascript
|
|
706
|
+
* import { vectorQuerySource } from '@carto/api-client';
|
|
707
|
+
*
|
|
708
|
+
* const data = vectorQuerySource({
|
|
709
|
+
* accessToken: '••••',
|
|
710
|
+
* connectionName: 'carto_dw',
|
|
711
|
+
* sqlQuery: 'SELECT * FROM carto-demo-data.demo_tables.retail_stores'
|
|
712
|
+
* });
|
|
713
|
+
*
|
|
714
|
+
* const { widgetSource } = await data;
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
591
717
|
class WidgetQuerySource extends WidgetBaseSource {
|
|
592
|
-
|
|
718
|
+
getModelSource(owner) {
|
|
593
719
|
return {
|
|
594
|
-
...super.
|
|
595
|
-
type:
|
|
596
|
-
data: this.props.sqlQuery
|
|
720
|
+
...super._getModelSource(owner),
|
|
721
|
+
type: MapType.QUERY,
|
|
722
|
+
data: this.props.sqlQuery,
|
|
723
|
+
queryParameters: this.props.queryParameters
|
|
597
724
|
};
|
|
598
725
|
}
|
|
599
726
|
}
|
|
600
727
|
|
|
728
|
+
/**
|
|
729
|
+
* Source for Widget API requests on a data source defined as a table.
|
|
730
|
+
*
|
|
731
|
+
* Generally not intended to be constructed directly. Instead, call
|
|
732
|
+
* {@link vectorTableSource}, {@link h3TableSource}, or {@link quadbinTableSource},
|
|
733
|
+
* which can be shared with map layers. Sources contain a `widgetSource` property,
|
|
734
|
+
* for use by widget implementations.
|
|
735
|
+
*
|
|
736
|
+
* Example:
|
|
737
|
+
*
|
|
738
|
+
* ```javascript
|
|
739
|
+
* import { vectorTableSource } from '@carto/api-client';
|
|
740
|
+
*
|
|
741
|
+
* const data = vectorTableSource({
|
|
742
|
+
* accessToken: '••••',
|
|
743
|
+
* connectionName: 'carto_dw',
|
|
744
|
+
* tableName: 'carto-demo-data.demo_tables.retail_stores'
|
|
745
|
+
* });
|
|
746
|
+
*
|
|
747
|
+
* const { widgetSource } = await data;
|
|
748
|
+
* ```
|
|
749
|
+
*/
|
|
601
750
|
class WidgetTableSource extends WidgetBaseSource {
|
|
602
|
-
|
|
751
|
+
getModelSource(owner) {
|
|
603
752
|
return {
|
|
604
|
-
...super.
|
|
605
|
-
type:
|
|
753
|
+
...super._getModelSource(owner),
|
|
754
|
+
type: MapType.TABLE,
|
|
606
755
|
data: this.props.tableName
|
|
607
756
|
};
|
|
608
757
|
}
|
|
@@ -666,7 +815,7 @@ const V3_MINOR_VERSION = '3.4';
|
|
|
666
815
|
const MAX_GET_LENGTH = 8192;
|
|
667
816
|
const DEFAULT_PARAMETERS = {
|
|
668
817
|
v: V3_MINOR_VERSION,
|
|
669
|
-
deckglVersion: "0.0.1-
|
|
818
|
+
deckglVersion: "0.0.1-2"
|
|
670
819
|
};
|
|
671
820
|
const DEFAULT_HEADERS = {
|
|
672
821
|
Accept: 'application/json',
|
|
@@ -1070,12 +1219,9 @@ const vectorTilesetSource$1 = async function (options) {
|
|
|
1070
1219
|
vectorTilesetSource: vectorTilesetSource$1
|
|
1071
1220
|
});
|
|
1072
1221
|
|
|
1073
|
-
|
|
1074
|
-
* VECTOR SOURCES
|
|
1075
|
-
*/
|
|
1076
|
-
/** Wrapper adding widget support to {@link _vectorTableSource}. */
|
|
1222
|
+
/** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1077
1223
|
|
|
1078
|
-
/** Wrapper adding
|
|
1224
|
+
/** Wrapper adding Widget API support to [quadbinTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1079
1225
|
const quadbinTilesetSource = function () {
|
|
1080
1226
|
try {
|
|
1081
1227
|
throw new Error('not implemented');
|
|
@@ -1083,7 +1229,7 @@ const quadbinTilesetSource = function () {
|
|
|
1083
1229
|
return Promise.reject(e);
|
|
1084
1230
|
}
|
|
1085
1231
|
};
|
|
1086
|
-
/** Wrapper adding
|
|
1232
|
+
/** Wrapper adding Widget API support to [quadbinQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1087
1233
|
const quadbinQuerySource = function (props) {
|
|
1088
1234
|
try {
|
|
1089
1235
|
return Promise.resolve(quadbinQuerySource$1(props)).then(function (response) {
|
|
@@ -1096,10 +1242,7 @@ const quadbinQuerySource = function (props) {
|
|
|
1096
1242
|
return Promise.reject(e);
|
|
1097
1243
|
}
|
|
1098
1244
|
};
|
|
1099
|
-
|
|
1100
|
-
* QUADBIN SOURCES
|
|
1101
|
-
*/
|
|
1102
|
-
/** Wrapper adding widget support to {@link _quadbinTableSource}. */
|
|
1245
|
+
/** Wrapper adding Widget API support to [quadbinTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1103
1246
|
const quadbinTableSource = function (props) {
|
|
1104
1247
|
try {
|
|
1105
1248
|
return Promise.resolve(quadbinTableSource$1(props)).then(function (response) {
|
|
@@ -1112,7 +1255,7 @@ const quadbinTableSource = function (props) {
|
|
|
1112
1255
|
return Promise.reject(e);
|
|
1113
1256
|
}
|
|
1114
1257
|
};
|
|
1115
|
-
/** Wrapper adding
|
|
1258
|
+
/** Wrapper adding Widget API support to [h3TilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1116
1259
|
const h3TilesetSource = function () {
|
|
1117
1260
|
try {
|
|
1118
1261
|
throw new Error('not implemented');
|
|
@@ -1120,7 +1263,7 @@ const h3TilesetSource = function () {
|
|
|
1120
1263
|
return Promise.reject(e);
|
|
1121
1264
|
}
|
|
1122
1265
|
};
|
|
1123
|
-
/** Wrapper adding
|
|
1266
|
+
/** Wrapper adding Widget API support to [h3QuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1124
1267
|
const h3QuerySource = function (props) {
|
|
1125
1268
|
try {
|
|
1126
1269
|
return Promise.resolve(h3QuerySource$1(props)).then(function (response) {
|
|
@@ -1133,10 +1276,7 @@ const h3QuerySource = function (props) {
|
|
|
1133
1276
|
return Promise.reject(e);
|
|
1134
1277
|
}
|
|
1135
1278
|
};
|
|
1136
|
-
|
|
1137
|
-
* H3 SOURCES
|
|
1138
|
-
*/
|
|
1139
|
-
/** Wrapper adding widget support to {@link _h3TableSource}. */
|
|
1279
|
+
/** Wrapper adding Widget API support to [h3TableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1140
1280
|
const h3TableSource = function (props) {
|
|
1141
1281
|
try {
|
|
1142
1282
|
return Promise.resolve(h3TableSource$1(props)).then(function (response) {
|
|
@@ -1149,7 +1289,7 @@ const h3TableSource = function (props) {
|
|
|
1149
1289
|
return Promise.reject(e);
|
|
1150
1290
|
}
|
|
1151
1291
|
};
|
|
1152
|
-
/** Wrapper adding
|
|
1292
|
+
/** Wrapper adding Widget API support to [vectorTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1153
1293
|
const vectorTilesetSource = function () {
|
|
1154
1294
|
try {
|
|
1155
1295
|
throw new Error('not implemented');
|
|
@@ -1157,7 +1297,7 @@ const vectorTilesetSource = function () {
|
|
|
1157
1297
|
return Promise.reject(e);
|
|
1158
1298
|
}
|
|
1159
1299
|
};
|
|
1160
|
-
/** Wrapper adding
|
|
1300
|
+
/** Wrapper adding Widget API support to [vectorQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
|
|
1161
1301
|
const vectorQuerySource = function (props) {
|
|
1162
1302
|
try {
|
|
1163
1303
|
return Promise.resolve(vectorQuerySource$1(props)).then(function (response) {
|
|
@@ -1183,11 +1323,9 @@ const vectorTableSource = function (props) {
|
|
|
1183
1323
|
}
|
|
1184
1324
|
};
|
|
1185
1325
|
|
|
1186
|
-
exports.CLIENT_ID = CLIENT_ID;
|
|
1187
1326
|
exports.WidgetBaseSource = WidgetBaseSource;
|
|
1188
1327
|
exports.WidgetQuerySource = WidgetQuerySource;
|
|
1189
1328
|
exports.WidgetTableSource = WidgetTableSource;
|
|
1190
|
-
exports.executeModel = executeModel;
|
|
1191
1329
|
exports.getClient = getClient;
|
|
1192
1330
|
exports.h3QuerySource = h3QuerySource;
|
|
1193
1331
|
exports.h3TableSource = h3TableSource;
|