@carto/api-client 0.0.1-1 → 0.0.30

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.
@@ -1,19 +1,32 @@
1
- const CLIENT_ID = 'carto-api-client';
2
- /** @internalRemarks Source: @carto/constants */
3
- exports.MapType = void 0;
4
- (function (MapType) {
5
- MapType["TABLE"] = "table";
6
- MapType["QUERY"] = "query";
7
- MapType["TILESET"] = "tileset";
8
- })(exports.MapType || (exports.MapType = {}));
9
- /** @internalRemarks Source: @carto/constants */
10
- exports.ApiVersion = void 0;
11
- (function (ApiVersion) {
12
- ApiVersion["V1"] = "v1";
13
- ApiVersion["V2"] = "v2";
14
- ApiVersion["V3"] = "v3";
15
- })(exports.ApiVersion || (exports.ApiVersion = {}));
16
- /** @internalRemarks Source: @carto/react-core */
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
- /** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
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
- * Default client
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
- credentials,
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 ${credentials.accessToken}`,
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.indexOf(props.model) !== -1, `executeModel: model provided isn't valid. Available models: ${AVAILABLE_MODELS.join(', ')}`);
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
- checkCredentials(source.credentials);
246
- assert(source.credentials.apiVersion === exports.ApiVersion.V3, 'SQL Model API is a feature only available in CARTO 3.');
247
- assert(source.type !== exports.MapType.TILESET, 'executeModel: Tileset not supported');
248
- let url = `${source.credentials.apiBaseUrl}/v3/sql/${source.connection}/model/${model}`;
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
- credentials: source.credentials,
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
- getSource(owner) {
347
+ _getModelSource(owner) {
348
+ const props = this.props;
317
349
  return {
318
- ...this.props,
319
- credentials: this.credentials,
320
- connection: this.connectionName,
321
- filters: getApplicableFilters(owner, this.props.filters)
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
- getFormula(props) {
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(options) {
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
- } = props;
375
+ } = options;
334
376
  const {
335
377
  column,
336
- operation
378
+ operation,
379
+ operationColumn
337
380
  } = params;
338
381
  return Promise.resolve(executeModel({
339
- model: 'formula',
340
- source: _this.getSource(filterOwner),
341
- spatialFilter,
382
+ model: 'category',
383
+ source: {
384
+ ..._this.getModelSource(filterOwner),
385
+ spatialFilter
386
+ },
342
387
  params: {
343
- column: column ?? '*',
388
+ column,
344
389
  operation,
345
- operationExp
390
+ operationColumn: operationColumn || column
346
391
  },
347
392
  opts: {
348
393
  abortController
349
394
  }
350
- }).then(res => normalizeObjectKeys(res.rows[0])));
395
+ }).then(res => normalizeObjectKeys(res.rows)));
351
396
  } catch (e) {
352
397
  return Promise.reject(e);
353
398
  }
354
399
  }
355
- getCategories(props) {
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(options) {
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
- } = props;
416
+ } = options;
364
417
  const {
365
418
  column,
366
- operation,
367
- operationColumn
419
+ operation
368
420
  } = params;
369
421
  return Promise.resolve(executeModel({
370
- model: 'category',
371
- source: _this2.getSource(filterOwner),
372
- spatialFilter,
422
+ model: 'formula',
423
+ source: {
424
+ ..._this2.getModelSource(filterOwner),
425
+ spatialFilter
426
+ },
373
427
  params: {
374
- column,
428
+ column: column ?? '*',
375
429
  operation,
376
- operationColumn: operationColumn || column
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
- getRange(props) {
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(options) {
387
448
  try {
388
449
  const _this3 = this;
389
450
  const {
@@ -391,26 +452,55 @@ class WidgetBaseSource {
391
452
  spatialFilter,
392
453
  abortController,
393
454
  ...params
394
- } = props;
455
+ } = options;
395
456
  const {
396
- column
457
+ column,
458
+ operation,
459
+ ticks
397
460
  } = params;
398
461
  return Promise.resolve(executeModel({
399
- model: 'range',
400
- source: _this3.getSource(filterOwner),
401
- spatialFilter,
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[0])));
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
- getTable(props) {
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(options) {
414
504
  try {
415
505
  const _this4 = this;
416
506
  const {
@@ -418,37 +508,35 @@ class WidgetBaseSource {
418
508
  spatialFilter,
419
509
  abortController,
420
510
  ...params
421
- } = props;
511
+ } = options;
422
512
  const {
423
- columns,
424
- sortBy,
425
- sortDirection,
426
- page = 0,
427
- rowsPerPage = 10
513
+ column
428
514
  } = params;
429
515
  return Promise.resolve(executeModel({
430
- model: 'table',
431
- source: _this4.getSource(filterOwner),
432
- spatialFilter,
516
+ model: 'range',
517
+ source: {
518
+ ..._this4.getModelSource(filterOwner),
519
+ spatialFilter
520
+ },
433
521
  params: {
434
- column: columns,
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
  }
451
- getScatter(props) {
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
+ */
539
+ getScatter(options) {
452
540
  try {
453
541
  const _this5 = this;
454
542
  const {
@@ -456,7 +544,7 @@ class WidgetBaseSource {
456
544
  spatialFilter,
457
545
  abortController,
458
546
  ...params
459
- } = props;
547
+ } = options;
460
548
  const {
461
549
  xAxisColumn,
462
550
  xAxisJoinOperation,
@@ -467,8 +555,10 @@ class WidgetBaseSource {
467
555
  const HARD_LIMIT = 500;
468
556
  return Promise.resolve(executeModel({
469
557
  model: 'scatterplot',
470
- source: _this5.getSource(filterOwner),
471
- spatialFilter,
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(_ref => {
572
+ }).then(res => normalizeObjectKeys(res.rows)).then(res => res.map(_ref2 => {
483
573
  let {
484
574
  x,
485
575
  y
486
- } = _ref;
576
+ } = _ref2;
487
577
  return [x, y];
488
578
  })));
489
579
  } catch (e) {
490
580
  return Promise.reject(e);
491
581
  }
492
582
  }
493
- getTimeSeries(props) {
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(options) {
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
- } = props;
598
+ } = options;
502
599
  const {
503
- column,
504
- operationColumn,
505
- joinOperation,
506
- operation,
507
- stepSize,
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: 'timeseries',
515
- source: _this6.getSource(filterOwner),
516
- spatialFilter,
607
+ model: 'table',
608
+ source: {
609
+ ..._this6.getModelSource(filterOwner),
610
+ spatialFilter
611
+ },
517
612
  params: {
518
- column,
519
- stepSize,
520
- stepMultiplier,
521
- operationColumn: operationColumn || column,
522
- joinOperation,
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
- categories: res.metadata?.categories
624
+ totalCount: res.metadata.total
534
625
  })));
535
626
  } catch (e) {
536
627
  return Promise.reject(e);
537
628
  }
538
629
  }
539
- getHistogram(props) {
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(options) {
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
- } = props;
645
+ } = options;
548
646
  const {
549
647
  column,
648
+ operationColumn,
649
+ joinOperation,
550
650
  operation,
551
- ticks
651
+ stepSize,
652
+ stepMultiplier,
653
+ splitByCategory,
654
+ splitByCategoryLimit,
655
+ splitByCategoryValues
552
656
  } = params;
553
657
  return Promise.resolve(executeModel({
554
- model: 'histogram',
555
- source: _this7.getSource(filterOwner),
556
- spatialFilter,
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
- ticks
670
+ splitByCategory,
671
+ splitByCategoryLimit,
672
+ splitByCategoryValues
561
673
  },
562
674
  opts: {
563
675
  abortController
564
676
  }
565
- }).then(res => normalizeObjectKeys(res.rows))).then(function (data) {
566
- if (data.length) {
567
- // Given N ticks the API returns up to N+1 bins, omitting any empty bins. Bins
568
- // include 1 bin below the lowest tick, N-1 between ticks, and 1 bin above the highest tick.
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
- getSource(owner) {
718
+ getModelSource(owner) {
593
719
  return {
594
- ...super.getSource(owner),
595
- type: exports.MapType.QUERY,
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
- getSource(owner) {
751
+ getModelSource(owner) {
603
752
  return {
604
- ...super.getSource(owner),
605
- type: exports.MapType.TABLE,
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-1"
818
+ deckglVersion: "0.0.30"
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 widget support to {@link _quadbinTilesetSource}. */
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 widget support to {@link _quadbinQuerySource}. */
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 widget support to {@link _h3TilesetSource}. */
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 widget support to {@link _h3QuerySource}. */
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 widget support to {@link _vectorTilesetSource}. */
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 widget support to {@link _vectorQuerySource}. */
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;