@carto/api-client 0.4.0-alpha.4 → 0.4.0-alpha.6

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.
@@ -65,6 +65,8 @@ exports.ApiVersion = void 0;
65
65
  ApiVersion["V2"] = "v2";
66
66
  ApiVersion["V3"] = "v3";
67
67
  })(exports.ApiVersion || (exports.ApiVersion = {}));
68
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
69
+ const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
68
70
 
69
71
  const FILTER_TYPES = new Set(Object.values(exports.FilterType));
70
72
  const isFilterType = type => FILTER_TYPES.has(type);
@@ -353,8 +355,10 @@ function _isMultiPolygon(geometry) {
353
355
  return invariant.getType(geometry) === 'MultiPolygon';
354
356
  }
355
357
 
356
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
357
- const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
358
+ /**
359
+ * Current version of @carto/api-client.
360
+ * @internal
361
+ */
358
362
  /** @internal */
359
363
  const V3_MINOR_VERSION = '3.4';
360
364
  /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
@@ -468,7 +472,7 @@ function dealWithApiError(_ref) {
468
472
  }
469
473
 
470
474
  /** @internalRemarks Source: @carto/react-api */
471
- const AVAILABLE_MODELS = ['category', 'histogram', 'formula', 'timeseries', 'range', 'scatterplot', 'table'];
475
+ const AVAILABLE_MODELS = ['category', 'histogram', 'formula', 'pick', 'timeseries', 'range', 'scatterplot', 'table'];
472
476
  const {
473
477
  V3
474
478
  } = exports.ApiVersion;
@@ -502,9 +506,10 @@ function executeModel(props) {
502
506
  assert(type !== 'tileset', 'executeModel: Tilesets not supported');
503
507
  let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
504
508
  const {
509
+ data,
505
510
  filters,
506
511
  filtersLogicalOperator = 'and',
507
- data
512
+ geoColumn = DEFAULT_GEO_COLUMN
508
513
  } = source;
509
514
  const queryParameters = source.queryParameters ? JSON.stringify(source.queryParameters) : '';
510
515
  const queryParams = {
@@ -516,9 +521,13 @@ function executeModel(props) {
516
521
  filters: JSON.stringify(filters),
517
522
  filtersLogicalOperator
518
523
  };
524
+ // Picking Model API requires 'spatialDataColumn'.
525
+ if (model === 'pick') {
526
+ queryParams.spatialDataColumn = geoColumn;
527
+ }
519
528
  // API supports multiple filters, we apply it only to geoColumn
520
529
  const spatialFilters = source.spatialFilter ? {
521
- [source.geoColumn ? source.geoColumn : DEFAULT_GEO_COLUMN]: source.spatialFilter
530
+ [geoColumn]: source.spatialFilter
522
531
  } : undefined;
523
532
  if (spatialFilters) {
524
533
  queryParams.spatialFilters = JSON.stringify(spatialFilters);
@@ -615,6 +624,58 @@ class WidgetBaseSource {
615
624
  return Promise.reject(e);
616
625
  }
617
626
  }
627
+ /****************************************************************************
628
+ * FEATURES
629
+ */
630
+ /**
631
+ * Given a list of feature IDs (as found in `_carto_feature_id`) returns all
632
+ * matching features. In datasets containing features with duplicate geometries,
633
+ * feature IDs may be duplicated (IDs are a hash of geometry) and so more
634
+ * results may be returned than IDs in the request.
635
+ * @internal
636
+ * @experimental
637
+ */
638
+ getFeatures(options) {
639
+ try {
640
+ const _this2 = this;
641
+ const {
642
+ filterOwner,
643
+ spatialFilter,
644
+ abortController,
645
+ ...params
646
+ } = options;
647
+ const {
648
+ columns,
649
+ dataType,
650
+ featureIds,
651
+ z,
652
+ limit,
653
+ tileResolution
654
+ } = params;
655
+ return Promise.resolve(executeModel({
656
+ model: 'pick',
657
+ source: {
658
+ ..._this2.getModelSource(filterOwner),
659
+ spatialFilter
660
+ },
661
+ params: {
662
+ columns,
663
+ dataType,
664
+ featureIds,
665
+ z,
666
+ limit: limit || 1000,
667
+ tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION
668
+ },
669
+ opts: {
670
+ abortController
671
+ }
672
+ }).then(res => ({
673
+ rows: normalizeObjectKeys(res.rows)
674
+ })));
675
+ } catch (e) {
676
+ return Promise.reject(e);
677
+ }
678
+ }
618
679
  /****************************************************************************
619
680
  * FORMULA
620
681
  */
@@ -624,7 +685,7 @@ class WidgetBaseSource {
624
685
  */
625
686
  getFormula(options) {
626
687
  try {
627
- const _this2 = this;
688
+ const _this3 = this;
628
689
  const {
629
690
  filterOwner,
630
691
  spatialFilter,
@@ -639,7 +700,7 @@ class WidgetBaseSource {
639
700
  return Promise.resolve(executeModel({
640
701
  model: 'formula',
641
702
  source: {
642
- ..._this2.getModelSource(filterOwner),
703
+ ..._this3.getModelSource(filterOwner),
643
704
  spatialFilter
644
705
  },
645
706
  params: {
@@ -664,7 +725,7 @@ class WidgetBaseSource {
664
725
  */
665
726
  getHistogram(options) {
666
727
  try {
667
- const _this3 = this;
728
+ const _this4 = this;
668
729
  const {
669
730
  filterOwner,
670
731
  spatialFilter,
@@ -679,7 +740,7 @@ class WidgetBaseSource {
679
740
  return Promise.resolve(executeModel({
680
741
  model: 'histogram',
681
742
  source: {
682
- ..._this3.getModelSource(filterOwner),
743
+ ..._this4.getModelSource(filterOwner),
683
744
  spatialFilter
684
745
  },
685
746
  params: {
@@ -720,7 +781,7 @@ class WidgetBaseSource {
720
781
  */
721
782
  getRange(options) {
722
783
  try {
723
- const _this4 = this;
784
+ const _this5 = this;
724
785
  const {
725
786
  filterOwner,
726
787
  spatialFilter,
@@ -733,7 +794,7 @@ class WidgetBaseSource {
733
794
  return Promise.resolve(executeModel({
734
795
  model: 'range',
735
796
  source: {
736
- ..._this4.getModelSource(filterOwner),
797
+ ..._this5.getModelSource(filterOwner),
737
798
  spatialFilter
738
799
  },
739
800
  params: {
@@ -756,7 +817,7 @@ class WidgetBaseSource {
756
817
  */
757
818
  getScatter(options) {
758
819
  try {
759
- const _this5 = this;
820
+ const _this6 = this;
760
821
  const {
761
822
  filterOwner,
762
823
  spatialFilter,
@@ -774,7 +835,7 @@ class WidgetBaseSource {
774
835
  return Promise.resolve(executeModel({
775
836
  model: 'scatterplot',
776
837
  source: {
777
- ..._this5.getModelSource(filterOwner),
838
+ ..._this6.getModelSource(filterOwner),
778
839
  spatialFilter
779
840
  },
780
841
  params: {
@@ -807,7 +868,7 @@ class WidgetBaseSource {
807
868
  */
808
869
  getTable(options) {
809
870
  try {
810
- const _this6 = this;
871
+ const _this7 = this;
811
872
  const {
812
873
  filterOwner,
813
874
  spatialFilter,
@@ -824,7 +885,7 @@ class WidgetBaseSource {
824
885
  return Promise.resolve(executeModel({
825
886
  model: 'table',
826
887
  source: {
827
- ..._this6.getModelSource(filterOwner),
888
+ ..._this7.getModelSource(filterOwner),
828
889
  spatialFilter
829
890
  },
830
891
  params: {
@@ -855,7 +916,7 @@ class WidgetBaseSource {
855
916
  */
856
917
  getTimeSeries(options) {
857
918
  try {
858
- const _this7 = this;
919
+ const _this8 = this;
859
920
  const {
860
921
  filterOwner,
861
922
  abortController,
@@ -876,7 +937,7 @@ class WidgetBaseSource {
876
937
  return Promise.resolve(executeModel({
877
938
  model: 'timeseries',
878
939
  source: {
879
- ..._this7.getModelSource(filterOwner),
940
+ ..._this8.getModelSource(filterOwner),
880
941
  spatialFilter
881
942
  },
882
943
  params: {
@@ -1646,6 +1707,7 @@ const query = function (options) {
1646
1707
  };
1647
1708
 
1648
1709
  exports.CartoAPIError = CartoAPIError;
1710
+ exports.DEFAULT_API_BASE_URL = DEFAULT_API_BASE_URL;
1649
1711
  exports.SOURCE_DEFAULTS = SOURCE_DEFAULTS;
1650
1712
  exports.WidgetBaseSource = WidgetBaseSource;
1651
1713
  exports.WidgetQuerySource = WidgetQuerySource;