@carto/api-client 0.4.1-alpha.0 → 0.4.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.
- package/CHANGELOG.md +6 -0
- package/build/api/query.d.ts +1 -1
- package/build/api/request-with-parameters.d.ts +3 -1
- package/build/api-client.cjs +71 -231
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +88 -239
- package/build/api-client.modern.js.map +1 -1
- package/build/models/model.d.ts +1 -7
- package/build/sources/index.d.ts +1 -1
- package/build/sources/types.d.ts +175 -34
- package/build/utils.d.ts +1 -1
- package/build/widget-sources/types.d.ts +1 -8
- package/build/widget-sources/widget-base-source.d.ts +1 -0
- package/package.json +1 -1
- package/src/api/query.ts +4 -1
- package/src/api/request-with-parameters.ts +34 -4
- package/src/models/model.ts +24 -47
- package/src/sources/base-source.ts +4 -1
- package/src/sources/h3-query-source.ts +1 -7
- package/src/sources/h3-table-source.ts +1 -6
- package/src/sources/index.ts +5 -0
- package/src/sources/quadbin-query-source.ts +1 -6
- package/src/sources/quadbin-table-source.ts +1 -6
- package/src/sources/types.ts +200 -36
- package/src/sources/vector-query-source.ts +1 -4
- package/src/sources/vector-table-source.ts +1 -5
- package/src/utils.ts +1 -1
- package/src/widget-sources/types.ts +1 -9
- package/src/widget-sources/widget-base-source.ts +19 -185
- package/build/spatial-index.d.ts +0 -11
- package/src/spatial-index.ts +0 -119
|
@@ -493,43 +493,41 @@ function executeModel(props) {
|
|
|
493
493
|
data,
|
|
494
494
|
filters,
|
|
495
495
|
filtersLogicalOperator = 'and',
|
|
496
|
-
|
|
497
|
-
spatialFiltersMode = 'intersects',
|
|
498
|
-
spatialFiltersResolution = 0
|
|
496
|
+
geoColumn = DEFAULT_GEO_COLUMN
|
|
499
497
|
} = source;
|
|
498
|
+
const queryParameters = source.queryParameters ? JSON.stringify(source.queryParameters) : '';
|
|
500
499
|
const queryParams = {
|
|
501
500
|
type,
|
|
502
501
|
client: clientId,
|
|
503
502
|
source: data,
|
|
504
|
-
params,
|
|
505
|
-
queryParameters
|
|
506
|
-
filters,
|
|
503
|
+
params: JSON.stringify(params),
|
|
504
|
+
queryParameters,
|
|
505
|
+
filters: JSON.stringify(filters),
|
|
507
506
|
filtersLogicalOperator
|
|
508
507
|
};
|
|
509
|
-
const spatialDataColumn = source.spatialDataColumn || DEFAULT_GEO_COLUMN;
|
|
510
508
|
// Picking Model API requires 'spatialDataColumn'.
|
|
511
509
|
if (model === 'pick') {
|
|
512
|
-
queryParams.spatialDataColumn =
|
|
510
|
+
queryParams.spatialDataColumn = geoColumn;
|
|
513
511
|
}
|
|
514
|
-
// API supports multiple filters, we apply it only to
|
|
512
|
+
// API supports multiple filters, we apply it only to geoColumn
|
|
515
513
|
const spatialFilters = source.spatialFilter ? {
|
|
516
|
-
[
|
|
514
|
+
[geoColumn]: source.spatialFilter
|
|
517
515
|
} : undefined;
|
|
518
516
|
if (spatialFilters) {
|
|
519
|
-
queryParams.spatialFilters =
|
|
520
|
-
queryParams.spatialDataColumn = spatialDataColumn;
|
|
521
|
-
queryParams.spatialDataType = spatialDataType;
|
|
517
|
+
queryParams.spatialFilters = JSON.stringify(spatialFilters);
|
|
522
518
|
}
|
|
523
|
-
|
|
524
|
-
if (spatialFiltersResolution > 0) {
|
|
525
|
-
queryParams.spatialFiltersResolution = spatialFiltersResolution;
|
|
526
|
-
}
|
|
527
|
-
queryParams.spatialFiltersMode = spatialFiltersMode;
|
|
528
|
-
}
|
|
529
|
-
const urlWithSearchParams = url + '?' + objectToURLSearchParams(queryParams).toString();
|
|
519
|
+
const urlWithSearchParams = url + '?' + new URLSearchParams(queryParams).toString();
|
|
530
520
|
const isGet = urlWithSearchParams.length <= REQUEST_GET_MAX_URL_LENGTH;
|
|
531
521
|
if (isGet) {
|
|
532
522
|
url = urlWithSearchParams;
|
|
523
|
+
} else {
|
|
524
|
+
// undo the JSON.stringify, @TODO find a better pattern
|
|
525
|
+
queryParams.params = params;
|
|
526
|
+
queryParams.filters = filters;
|
|
527
|
+
queryParams.queryParameters = source.queryParameters;
|
|
528
|
+
if (spatialFilters) {
|
|
529
|
+
queryParams.spatialFilters = spatialFilters;
|
|
530
|
+
}
|
|
533
531
|
}
|
|
534
532
|
return makeCall({
|
|
535
533
|
url,
|
|
@@ -541,75 +539,15 @@ function executeModel(props) {
|
|
|
541
539
|
})
|
|
542
540
|
});
|
|
543
541
|
}
|
|
544
|
-
function objectToURLSearchParams(object) {
|
|
545
|
-
const params = new URLSearchParams();
|
|
546
|
-
for (const key in object) {
|
|
547
|
-
if (isPureObject(object[key])) {
|
|
548
|
-
params.append(key, JSON.stringify(object[key]));
|
|
549
|
-
} else if (Array.isArray(object[key])) {
|
|
550
|
-
params.append(key, JSON.stringify(object[key]));
|
|
551
|
-
} else if (object[key] === null) {
|
|
552
|
-
params.append(key, 'null');
|
|
553
|
-
} else if (object[key] !== undefined) {
|
|
554
|
-
params.append(key, String(object[key]));
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
return params;
|
|
558
|
-
}
|
|
559
542
|
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const dataResolution = (_source$dataResolutio = source.dataResolution) != null ? _source$dataResolutio : Number.MAX_VALUE;
|
|
569
|
-
const aggregationResLevel = (_source$aggregationRe = source.aggregationResLevel) != null ? _source$aggregationRe : source.spatialDataType === 'h3' ? DEFAULT_AGGREGATION_RES_LEVEL_H3 : DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN;
|
|
570
|
-
const aggregationResLevelOffset = Math.max(0, Math.floor(aggregationResLevel));
|
|
571
|
-
const currentZoomInt = Math.ceil(viewState.zoom);
|
|
572
|
-
if (source.spatialDataType === 'h3') {
|
|
573
|
-
var _maxH3SpatialFiltersR, _maxH3SpatialFiltersR2;
|
|
574
|
-
const tileSize = DEFAULT_TILE_SIZE;
|
|
575
|
-
const maxResolutionForZoom = (_maxH3SpatialFiltersR = (_maxH3SpatialFiltersR2 = maxH3SpatialFiltersResolutions.find(([zoom]) => zoom === currentZoomInt)) == null ? void 0 : _maxH3SpatialFiltersR2[1]) != null ? _maxH3SpatialFiltersR : Math.max(0, currentZoomInt - 3);
|
|
576
|
-
const maxSpatialFiltersResolution = maxResolutionForZoom ? Math.min(dataResolution, maxResolutionForZoom) : dataResolution;
|
|
577
|
-
const hexagonResolution = getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
578
|
-
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
579
|
-
}
|
|
580
|
-
if (source.spatialDataType === 'quadbin') {
|
|
581
|
-
const maxResolutionForZoom = currentZoomInt + QUADBIN_ZOOM_MAX_OFFSET;
|
|
582
|
-
const maxSpatialFiltersResolution = Math.min(dataResolution, maxResolutionForZoom);
|
|
583
|
-
const quadsResolution = Math.floor(viewState.zoom) + aggregationResLevelOffset;
|
|
584
|
-
return Math.min(quadsResolution, maxSpatialFiltersResolution);
|
|
585
|
-
}
|
|
586
|
-
return undefined;
|
|
587
|
-
}
|
|
588
|
-
const maxH3SpatialFiltersResolutions = [[20, 14], [19, 13], [18, 12], [17, 11], [16, 10], [15, 9], [14, 8], [13, 7], [12, 7], [11, 7], [10, 6], [9, 6], [8, 5], [7, 4], [6, 4], [5, 3], [4, 2], [3, 1], [2, 1], [1, 0]];
|
|
589
|
-
// stolen from https://github.com/visgl/deck.gl/blob/master/modules/carto/src/layers/h3-tileset-2d.ts
|
|
590
|
-
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
591
|
-
const BIAS = 2;
|
|
592
|
-
// Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
593
|
-
// a H3 resolution such that the screen space size of the hexagons is
|
|
594
|
-
// similar
|
|
595
|
-
function getHexagonResolution(viewport, tileSize) {
|
|
596
|
-
// Difference in given tile size compared to deck's internal 512px tile size,
|
|
597
|
-
// expressed as an offset to the viewport zoom.
|
|
598
|
-
const zoomOffset = Math.log2(tileSize / DEFAULT_TILE_SIZE);
|
|
599
|
-
const hexagonScaleFactor = 2 / 3 * (viewport.zoom - zoomOffset);
|
|
600
|
-
const latitudeScaleFactor = Math.log(1 / Math.cos(Math.PI * viewport.latitude / 180));
|
|
601
|
-
// Clip and bias
|
|
602
|
-
return Math.max(0, Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS));
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
const _excluded$1 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "viewState"],
|
|
606
|
-
_excluded2 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "viewState"],
|
|
607
|
-
_excluded3 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "operationExp", "viewState"],
|
|
608
|
-
_excluded4 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "viewState"],
|
|
609
|
-
_excluded5 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "viewState"],
|
|
610
|
-
_excluded6 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "viewState"],
|
|
611
|
-
_excluded7 = ["filterOwner", "spatialFilter", "spatialFiltersMode", "abortController", "viewState"],
|
|
612
|
-
_excluded8 = ["filterOwner", "abortController", "spatialFilter", "spatialFiltersMode", "viewState"];
|
|
543
|
+
const _excluded$1 = ["filterOwner", "spatialFilter", "abortController"],
|
|
544
|
+
_excluded2 = ["filterOwner", "spatialFilter", "abortController"],
|
|
545
|
+
_excluded3 = ["filterOwner", "spatialFilter", "abortController", "operationExp"],
|
|
546
|
+
_excluded4 = ["filterOwner", "spatialFilter", "abortController"],
|
|
547
|
+
_excluded5 = ["filterOwner", "spatialFilter", "abortController"],
|
|
548
|
+
_excluded6 = ["filterOwner", "spatialFilter", "abortController"],
|
|
549
|
+
_excluded7 = ["filterOwner", "spatialFilter", "abortController"],
|
|
550
|
+
_excluded8 = ["filterOwner", "abortController", "spatialFilter"];
|
|
613
551
|
/**
|
|
614
552
|
* Source for Widget API requests on a data source defined by a SQL query.
|
|
615
553
|
*
|
|
@@ -630,8 +568,7 @@ class WidgetBaseSource {
|
|
|
630
568
|
connectionName: props.connectionName,
|
|
631
569
|
filters: getApplicableFilters(owner, props.filters),
|
|
632
570
|
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
633
|
-
|
|
634
|
-
spatialDataColumn: props.spatialDataColumn
|
|
571
|
+
geoColumn: props.geoColumn
|
|
635
572
|
};
|
|
636
573
|
}
|
|
637
574
|
/****************************************************************************
|
|
@@ -645,9 +582,7 @@ class WidgetBaseSource {
|
|
|
645
582
|
const {
|
|
646
583
|
filterOwner,
|
|
647
584
|
spatialFilter,
|
|
648
|
-
|
|
649
|
-
abortController,
|
|
650
|
-
viewState
|
|
585
|
+
abortController
|
|
651
586
|
} = options,
|
|
652
587
|
params = _objectWithoutPropertiesLoose(options, _excluded$1);
|
|
653
588
|
const {
|
|
@@ -655,19 +590,9 @@ class WidgetBaseSource {
|
|
|
655
590
|
operation,
|
|
656
591
|
operationColumn
|
|
657
592
|
} = params;
|
|
658
|
-
const source = this.getModelSource(filterOwner);
|
|
659
|
-
let spatialFiltersResolution;
|
|
660
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
661
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
662
|
-
source,
|
|
663
|
-
viewState
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
593
|
return executeModel({
|
|
667
594
|
model: 'category',
|
|
668
|
-
source: _extends({},
|
|
669
|
-
spatialFiltersResolution,
|
|
670
|
-
spatialFiltersMode,
|
|
595
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
671
596
|
spatialFilter
|
|
672
597
|
}),
|
|
673
598
|
params: {
|
|
@@ -695,9 +620,7 @@ class WidgetBaseSource {
|
|
|
695
620
|
const {
|
|
696
621
|
filterOwner,
|
|
697
622
|
spatialFilter,
|
|
698
|
-
|
|
699
|
-
abortController,
|
|
700
|
-
viewState
|
|
623
|
+
abortController
|
|
701
624
|
} = options,
|
|
702
625
|
params = _objectWithoutPropertiesLoose(options, _excluded2);
|
|
703
626
|
const {
|
|
@@ -708,19 +631,9 @@ class WidgetBaseSource {
|
|
|
708
631
|
limit,
|
|
709
632
|
tileResolution
|
|
710
633
|
} = params;
|
|
711
|
-
const source = this.getModelSource(filterOwner);
|
|
712
|
-
let spatialFiltersResolution;
|
|
713
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
714
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
715
|
-
source,
|
|
716
|
-
viewState
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
634
|
return executeModel({
|
|
720
635
|
model: 'pick',
|
|
721
|
-
source: _extends({},
|
|
722
|
-
spatialFiltersResolution,
|
|
723
|
-
spatialFiltersMode,
|
|
636
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
724
637
|
spatialFilter
|
|
725
638
|
}),
|
|
726
639
|
params: {
|
|
@@ -749,29 +662,17 @@ class WidgetBaseSource {
|
|
|
749
662
|
const {
|
|
750
663
|
filterOwner,
|
|
751
664
|
spatialFilter,
|
|
752
|
-
spatialFiltersMode,
|
|
753
665
|
abortController,
|
|
754
|
-
operationExp
|
|
755
|
-
viewState
|
|
666
|
+
operationExp
|
|
756
667
|
} = options,
|
|
757
668
|
params = _objectWithoutPropertiesLoose(options, _excluded3);
|
|
758
669
|
const {
|
|
759
670
|
column,
|
|
760
671
|
operation
|
|
761
672
|
} = params;
|
|
762
|
-
const source = this.getModelSource(filterOwner);
|
|
763
|
-
let spatialFiltersResolution;
|
|
764
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
765
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
766
|
-
source,
|
|
767
|
-
viewState
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
673
|
return executeModel({
|
|
771
674
|
model: 'formula',
|
|
772
|
-
source: _extends({},
|
|
773
|
-
spatialFiltersResolution,
|
|
774
|
-
spatialFiltersMode,
|
|
675
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
775
676
|
spatialFilter
|
|
776
677
|
}),
|
|
777
678
|
params: {
|
|
@@ -795,9 +696,7 @@ class WidgetBaseSource {
|
|
|
795
696
|
const {
|
|
796
697
|
filterOwner,
|
|
797
698
|
spatialFilter,
|
|
798
|
-
|
|
799
|
-
abortController,
|
|
800
|
-
viewState
|
|
699
|
+
abortController
|
|
801
700
|
} = options,
|
|
802
701
|
params = _objectWithoutPropertiesLoose(options, _excluded4);
|
|
803
702
|
const {
|
|
@@ -805,19 +704,9 @@ class WidgetBaseSource {
|
|
|
805
704
|
operation,
|
|
806
705
|
ticks
|
|
807
706
|
} = params;
|
|
808
|
-
const source = this.getModelSource(filterOwner);
|
|
809
|
-
let spatialFiltersResolution;
|
|
810
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
811
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
812
|
-
source,
|
|
813
|
-
viewState
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
707
|
const data = await executeModel({
|
|
817
708
|
model: 'histogram',
|
|
818
|
-
source: _extends({},
|
|
819
|
-
spatialFiltersResolution,
|
|
820
|
-
spatialFiltersMode,
|
|
709
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
821
710
|
spatialFilter
|
|
822
711
|
}),
|
|
823
712
|
params: {
|
|
@@ -853,27 +742,15 @@ class WidgetBaseSource {
|
|
|
853
742
|
const {
|
|
854
743
|
filterOwner,
|
|
855
744
|
spatialFilter,
|
|
856
|
-
|
|
857
|
-
abortController,
|
|
858
|
-
viewState
|
|
745
|
+
abortController
|
|
859
746
|
} = options,
|
|
860
747
|
params = _objectWithoutPropertiesLoose(options, _excluded5);
|
|
861
748
|
const {
|
|
862
749
|
column
|
|
863
750
|
} = params;
|
|
864
|
-
const source = this.getModelSource(filterOwner);
|
|
865
|
-
let spatialFiltersResolution;
|
|
866
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
867
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
868
|
-
source,
|
|
869
|
-
viewState
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
751
|
return executeModel({
|
|
873
752
|
model: 'range',
|
|
874
|
-
source: _extends({},
|
|
875
|
-
spatialFiltersResolution,
|
|
876
|
-
spatialFiltersMode,
|
|
753
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
877
754
|
spatialFilter
|
|
878
755
|
}),
|
|
879
756
|
params: {
|
|
@@ -895,9 +772,7 @@ class WidgetBaseSource {
|
|
|
895
772
|
const {
|
|
896
773
|
filterOwner,
|
|
897
774
|
spatialFilter,
|
|
898
|
-
|
|
899
|
-
abortController,
|
|
900
|
-
viewState
|
|
775
|
+
abortController
|
|
901
776
|
} = options,
|
|
902
777
|
params = _objectWithoutPropertiesLoose(options, _excluded6);
|
|
903
778
|
const {
|
|
@@ -906,21 +781,11 @@ class WidgetBaseSource {
|
|
|
906
781
|
yAxisColumn,
|
|
907
782
|
yAxisJoinOperation
|
|
908
783
|
} = params;
|
|
909
|
-
const source = this.getModelSource(filterOwner);
|
|
910
|
-
let spatialFiltersResolution;
|
|
911
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
912
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
913
|
-
source,
|
|
914
|
-
viewState
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
784
|
// Make sure this is sync with the same constant in cloud-native/maps-api
|
|
918
785
|
const HARD_LIMIT = 500;
|
|
919
786
|
return executeModel({
|
|
920
787
|
model: 'scatterplot',
|
|
921
|
-
source: _extends({},
|
|
922
|
-
spatialFiltersResolution,
|
|
923
|
-
spatialFiltersMode,
|
|
788
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
924
789
|
spatialFilter
|
|
925
790
|
}),
|
|
926
791
|
params: {
|
|
@@ -949,9 +814,7 @@ class WidgetBaseSource {
|
|
|
949
814
|
const {
|
|
950
815
|
filterOwner,
|
|
951
816
|
spatialFilter,
|
|
952
|
-
|
|
953
|
-
abortController,
|
|
954
|
-
viewState
|
|
817
|
+
abortController
|
|
955
818
|
} = options,
|
|
956
819
|
params = _objectWithoutPropertiesLoose(options, _excluded7);
|
|
957
820
|
const {
|
|
@@ -961,19 +824,9 @@ class WidgetBaseSource {
|
|
|
961
824
|
offset = 0,
|
|
962
825
|
limit = 10
|
|
963
826
|
} = params;
|
|
964
|
-
const source = this.getModelSource(filterOwner);
|
|
965
|
-
let spatialFiltersResolution;
|
|
966
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
967
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
968
|
-
source,
|
|
969
|
-
viewState
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
827
|
return executeModel({
|
|
973
828
|
model: 'table',
|
|
974
|
-
source: _extends({},
|
|
975
|
-
spatialFiltersResolution,
|
|
976
|
-
spatialFiltersMode,
|
|
829
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
977
830
|
spatialFilter
|
|
978
831
|
}),
|
|
979
832
|
params: {
|
|
@@ -1006,9 +859,7 @@ class WidgetBaseSource {
|
|
|
1006
859
|
const {
|
|
1007
860
|
filterOwner,
|
|
1008
861
|
abortController,
|
|
1009
|
-
spatialFilter
|
|
1010
|
-
spatialFiltersMode,
|
|
1011
|
-
viewState
|
|
862
|
+
spatialFilter
|
|
1012
863
|
} = options,
|
|
1013
864
|
params = _objectWithoutPropertiesLoose(options, _excluded8);
|
|
1014
865
|
const {
|
|
@@ -1022,19 +873,9 @@ class WidgetBaseSource {
|
|
|
1022
873
|
splitByCategoryLimit,
|
|
1023
874
|
splitByCategoryValues
|
|
1024
875
|
} = params;
|
|
1025
|
-
const source = this.getModelSource(filterOwner);
|
|
1026
|
-
let spatialFiltersResolution;
|
|
1027
|
-
if (spatialFilter && source.spatialDataType !== 'geo') {
|
|
1028
|
-
spatialFiltersResolution = getSpatialFiltersResolution({
|
|
1029
|
-
source,
|
|
1030
|
-
viewState
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
876
|
return executeModel({
|
|
1034
877
|
model: 'timeseries',
|
|
1035
|
-
source: _extends({},
|
|
1036
|
-
spatialFiltersResolution,
|
|
1037
|
-
spatialFiltersMode,
|
|
878
|
+
source: _extends({}, this.getModelSource(filterOwner), {
|
|
1038
879
|
spatialFilter
|
|
1039
880
|
}),
|
|
1040
881
|
params: {
|
|
@@ -1065,7 +906,8 @@ WidgetBaseSource.defaultProps = {
|
|
|
1065
906
|
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
1066
907
|
clientId: getClient(),
|
|
1067
908
|
filters: {},
|
|
1068
|
-
filtersLogicalOperator: 'and'
|
|
909
|
+
filtersLogicalOperator: 'and',
|
|
910
|
+
geoColumn: DEFAULT_GEO_COLUMN
|
|
1069
911
|
};
|
|
1070
912
|
|
|
1071
913
|
/**
|
|
@@ -1235,13 +1077,14 @@ const DEFAULT_HEADERS = {
|
|
|
1235
1077
|
Accept: 'application/json',
|
|
1236
1078
|
'Content-Type': 'application/json'
|
|
1237
1079
|
};
|
|
1238
|
-
const
|
|
1080
|
+
const DEFAULT_REQUEST_CACHE = new Map();
|
|
1239
1081
|
async function requestWithParameters({
|
|
1240
1082
|
baseUrl,
|
|
1241
1083
|
parameters = {},
|
|
1242
1084
|
headers: customHeaders = {},
|
|
1243
1085
|
errorContext,
|
|
1244
|
-
maxLengthURL = DEFAULT_MAX_LENGTH_URL
|
|
1086
|
+
maxLengthURL = DEFAULT_MAX_LENGTH_URL,
|
|
1087
|
+
localCache
|
|
1245
1088
|
}) {
|
|
1246
1089
|
// Parameters added to all requests issued with `requestWithParameters()`.
|
|
1247
1090
|
// These parameters override parameters already in the base URL, but not
|
|
@@ -1254,7 +1097,12 @@ async function requestWithParameters({
|
|
|
1254
1097
|
}, parameters);
|
|
1255
1098
|
baseUrl = excludeURLParameters(baseUrl, Object.keys(parameters));
|
|
1256
1099
|
const key = createCacheKey(baseUrl, parameters, customHeaders);
|
|
1257
|
-
|
|
1100
|
+
const {
|
|
1101
|
+
cache: REQUEST_CACHE,
|
|
1102
|
+
canReadCache,
|
|
1103
|
+
canStoreInCache
|
|
1104
|
+
} = getCacheSettings(localCache);
|
|
1105
|
+
if (canReadCache && REQUEST_CACHE.has(key)) {
|
|
1258
1106
|
return REQUEST_CACHE.get(key);
|
|
1259
1107
|
}
|
|
1260
1108
|
const url = createURLWithParameters(baseUrl, parameters);
|
|
@@ -1279,12 +1127,27 @@ async function requestWithParameters({
|
|
|
1279
1127
|
}
|
|
1280
1128
|
return json;
|
|
1281
1129
|
}).catch(error => {
|
|
1282
|
-
|
|
1130
|
+
if (canStoreInCache) {
|
|
1131
|
+
REQUEST_CACHE.delete(key);
|
|
1132
|
+
}
|
|
1283
1133
|
throw new CartoAPIError(error, errorContext, response, responseJson);
|
|
1284
1134
|
});
|
|
1285
|
-
|
|
1135
|
+
if (canStoreInCache) {
|
|
1136
|
+
REQUEST_CACHE.set(key, jsonPromise);
|
|
1137
|
+
}
|
|
1286
1138
|
return jsonPromise;
|
|
1287
1139
|
}
|
|
1140
|
+
function getCacheSettings(localCache) {
|
|
1141
|
+
var _localCache$cacheCont, _localCache$cacheCont2;
|
|
1142
|
+
const canReadCache = localCache != null && (_localCache$cacheCont = localCache.cacheControl) != null && _localCache$cacheCont.includes('no-cache') ? false : true;
|
|
1143
|
+
const canStoreInCache = localCache != null && (_localCache$cacheCont2 = localCache.cacheControl) != null && _localCache$cacheCont2.includes('no-store') ? false : true;
|
|
1144
|
+
const cache = (localCache == null ? void 0 : localCache.cache) || DEFAULT_REQUEST_CACHE;
|
|
1145
|
+
return {
|
|
1146
|
+
cache,
|
|
1147
|
+
canReadCache,
|
|
1148
|
+
canStoreInCache
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1288
1151
|
function createCacheKey(baseUrl, parameters, headers) {
|
|
1289
1152
|
const parameterEntries = Object.entries(parameters).sort(([a], [b]) => a > b ? 1 : -1);
|
|
1290
1153
|
const headerEntries = Object.entries(headers).sort(([a], [b]) => a > b ? 1 : -1);
|
|
@@ -1352,7 +1215,8 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
1352
1215
|
const {
|
|
1353
1216
|
clientId,
|
|
1354
1217
|
maxLengthURL,
|
|
1355
|
-
format
|
|
1218
|
+
format,
|
|
1219
|
+
localCache
|
|
1356
1220
|
} = mergedOptions;
|
|
1357
1221
|
const headers = _extends({
|
|
1358
1222
|
Authorization: `Bearer ${options.accessToken}`
|
|
@@ -1371,7 +1235,8 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
1371
1235
|
parameters,
|
|
1372
1236
|
headers,
|
|
1373
1237
|
errorContext,
|
|
1374
|
-
maxLengthURL
|
|
1238
|
+
maxLengthURL,
|
|
1239
|
+
localCache
|
|
1375
1240
|
});
|
|
1376
1241
|
const dataUrl = mapInstantiation[format].url[0];
|
|
1377
1242
|
if (cache) {
|
|
@@ -1383,7 +1248,8 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
1383
1248
|
baseUrl: dataUrl,
|
|
1384
1249
|
headers,
|
|
1385
1250
|
errorContext,
|
|
1386
|
-
maxLengthURL
|
|
1251
|
+
maxLengthURL,
|
|
1252
|
+
localCache
|
|
1387
1253
|
});
|
|
1388
1254
|
if (accessToken) {
|
|
1389
1255
|
json.accessToken = accessToken;
|
|
@@ -1394,7 +1260,8 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
1394
1260
|
baseUrl: dataUrl,
|
|
1395
1261
|
headers,
|
|
1396
1262
|
errorContext,
|
|
1397
|
-
maxLengthURL
|
|
1263
|
+
maxLengthURL,
|
|
1264
|
+
localCache
|
|
1398
1265
|
});
|
|
1399
1266
|
}
|
|
1400
1267
|
|
|
@@ -1469,11 +1336,7 @@ const h3QuerySource = async function h3QuerySource(options) {
|
|
|
1469
1336
|
urlParameters.filters = filters;
|
|
1470
1337
|
}
|
|
1471
1338
|
return baseSource('query', options, urlParameters).then(result => _extends({}, result, {
|
|
1472
|
-
widgetSource: new WidgetQuerySource(
|
|
1473
|
-
// NOTE: passing redundant spatialDataColumn here to apply the default value 'h3'
|
|
1474
|
-
spatialDataColumn,
|
|
1475
|
-
spatialDataType: 'h3'
|
|
1476
|
-
}))
|
|
1339
|
+
widgetSource: new WidgetQuerySource(options)
|
|
1477
1340
|
}));
|
|
1478
1341
|
};
|
|
1479
1342
|
|
|
@@ -1498,11 +1361,7 @@ const h3TableSource = async function h3TableSource(options) {
|
|
|
1498
1361
|
urlParameters.filters = filters;
|
|
1499
1362
|
}
|
|
1500
1363
|
return baseSource('table', options, urlParameters).then(result => _extends({}, result, {
|
|
1501
|
-
widgetSource: new WidgetTableSource(
|
|
1502
|
-
// NOTE: passing redundant spatialDataColumn here to apply the default value 'h3'
|
|
1503
|
-
spatialDataColumn,
|
|
1504
|
-
spatialDataType: 'h3'
|
|
1505
|
-
}))
|
|
1364
|
+
widgetSource: new WidgetTableSource(options)
|
|
1506
1365
|
}));
|
|
1507
1366
|
};
|
|
1508
1367
|
|
|
@@ -1557,11 +1416,7 @@ const quadbinQuerySource = async function quadbinQuerySource(options) {
|
|
|
1557
1416
|
urlParameters.filters = filters;
|
|
1558
1417
|
}
|
|
1559
1418
|
return baseSource('query', options, urlParameters).then(result => _extends({}, result, {
|
|
1560
|
-
widgetSource: new WidgetQuerySource(
|
|
1561
|
-
// NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
|
|
1562
|
-
spatialDataColumn,
|
|
1563
|
-
spatialDataType: 'quadbin'
|
|
1564
|
-
}))
|
|
1419
|
+
widgetSource: new WidgetQuerySource(options)
|
|
1565
1420
|
}));
|
|
1566
1421
|
};
|
|
1567
1422
|
|
|
@@ -1586,11 +1441,7 @@ const quadbinTableSource = async function quadbinTableSource(options) {
|
|
|
1586
1441
|
urlParameters.filters = filters;
|
|
1587
1442
|
}
|
|
1588
1443
|
return baseSource('table', options, urlParameters).then(result => _extends({}, result, {
|
|
1589
|
-
widgetSource: new WidgetTableSource(
|
|
1590
|
-
// NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
|
|
1591
|
-
spatialDataColumn,
|
|
1592
|
-
spatialDataType: 'quadbin'
|
|
1593
|
-
}))
|
|
1444
|
+
widgetSource: new WidgetTableSource(options)
|
|
1594
1445
|
}));
|
|
1595
1446
|
};
|
|
1596
1447
|
|
|
@@ -1630,9 +1481,7 @@ const vectorQuerySource = async function vectorQuerySource(options) {
|
|
|
1630
1481
|
urlParameters.queryParameters = queryParameters;
|
|
1631
1482
|
}
|
|
1632
1483
|
return baseSource('query', options, urlParameters).then(result => _extends({}, result, {
|
|
1633
|
-
widgetSource: new WidgetQuerySource(
|
|
1634
|
-
spatialDataType: 'geo'
|
|
1635
|
-
}))
|
|
1484
|
+
widgetSource: new WidgetQuerySource(options)
|
|
1636
1485
|
}));
|
|
1637
1486
|
};
|
|
1638
1487
|
|
|
@@ -1657,9 +1506,7 @@ const vectorTableSource = async function vectorTableSource(options) {
|
|
|
1657
1506
|
urlParameters.filters = filters;
|
|
1658
1507
|
}
|
|
1659
1508
|
return baseSource('table', options, urlParameters).then(result => _extends({}, result, {
|
|
1660
|
-
widgetSource: new WidgetTableSource(
|
|
1661
|
-
spatialDataType: 'geo'
|
|
1662
|
-
}))
|
|
1509
|
+
widgetSource: new WidgetTableSource(options)
|
|
1663
1510
|
}));
|
|
1664
1511
|
};
|
|
1665
1512
|
|
|
@@ -1679,6 +1526,7 @@ const query = async function query(options) {
|
|
|
1679
1526
|
apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl,
|
|
1680
1527
|
clientId = SOURCE_DEFAULTS.clientId,
|
|
1681
1528
|
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL,
|
|
1529
|
+
localCache,
|
|
1682
1530
|
connectionName,
|
|
1683
1531
|
sqlQuery,
|
|
1684
1532
|
queryParameters
|
|
@@ -1710,7 +1558,8 @@ const query = async function query(options) {
|
|
|
1710
1558
|
parameters,
|
|
1711
1559
|
headers,
|
|
1712
1560
|
errorContext,
|
|
1713
|
-
maxLengthURL
|
|
1561
|
+
maxLengthURL,
|
|
1562
|
+
localCache
|
|
1714
1563
|
});
|
|
1715
1564
|
};
|
|
1716
1565
|
|