@carto/api-client 0.4.6-0 → 0.4.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.
- package/CHANGELOG.md +4 -0
- package/build/api-client.cjs +208 -2167
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +208 -2040
- package/build/api-client.modern.js.map +1 -1
- package/build/constants.d.ts +0 -22
- package/build/index.d.ts +1 -4
- package/build/models/index.d.ts +1 -1
- package/build/sources/h3-tileset-source.d.ts +1 -2
- package/build/sources/index.d.ts +1 -1
- package/build/sources/quadbin-tileset-source.d.ts +1 -2
- package/build/sources/vector-tileset-source.d.ts +1 -2
- package/build/spatial-index.d.ts +7 -1
- package/build/types-internal.d.ts +0 -4
- package/build/types.d.ts +1 -61
- package/build/widget-sources/index.d.ts +1 -3
- package/build/widget-sources/types.d.ts +22 -31
- package/build/widget-sources/{widget-source.d.ts → widget-base-source.d.ts} +38 -13
- package/build/widget-sources/widget-query-source.d.ts +2 -2
- package/build/widget-sources/widget-table-source.d.ts +2 -2
- package/package.json +11 -14
- package/src/constants.ts +0 -25
- package/src/index.ts +1 -5
- package/src/models/index.ts +1 -1
- package/src/sources/h3-tileset-source.ts +6 -18
- package/src/sources/index.ts +1 -1
- package/src/sources/quadbin-tileset-source.ts +6 -18
- package/src/sources/raster-source.ts +0 -1
- package/src/sources/vector-query-source.ts +2 -5
- package/src/sources/vector-table-source.ts +2 -5
- package/src/sources/vector-tileset-source.ts +6 -19
- package/src/spatial-index.ts +8 -5
- package/src/types-internal.ts +0 -6
- package/src/types.ts +2 -60
- package/src/widget-sources/index.ts +1 -3
- package/src/widget-sources/types.ts +22 -32
- package/src/widget-sources/{widget-remote-source.ts → widget-base-source.ts} +147 -12
- package/src/widget-sources/widget-query-source.ts +3 -6
- package/src/widget-sources/widget-table-source.ts +3 -6
- package/build/filters/Filter.d.ts +0 -13
- package/build/filters/FilterTypes.d.ts +0 -3
- package/build/filters/geosjonFeatures.d.ts +0 -8
- package/build/filters/index.d.ts +0 -6
- package/build/filters/tileFeatures.d.ts +0 -20
- package/build/filters/tileFeaturesGeometries.d.ts +0 -13
- package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
- package/build/operations/aggregation.d.ts +0 -8
- package/build/operations/applySorting.d.ts +0 -20
- package/build/operations/groupBy.d.ts +0 -15
- package/build/operations/groupByDate.d.ts +0 -11
- package/build/operations/histogram.d.ts +0 -13
- package/build/operations/index.d.ts +0 -6
- package/build/operations/scatterPlot.d.ts +0 -14
- package/build/utils/dateUtils.d.ts +0 -10
- package/build/utils/getTileFormat.d.ts +0 -3
- package/build/utils/makeIntervalComplete.d.ts +0 -2
- package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
- package/build/utils/transformToTileCoords.d.ts +0 -9
- package/build/widget-sources/widget-remote-source.d.ts +0 -18
- package/build/widget-sources/widget-tileset-source.d.ts +0 -76
- package/src/filters/Filter.ts +0 -169
- package/src/filters/FilterTypes.ts +0 -109
- package/src/filters/geosjonFeatures.ts +0 -32
- package/src/filters/index.ts +0 -6
- package/src/filters/tileFeatures.ts +0 -56
- package/src/filters/tileFeaturesGeometries.ts +0 -444
- package/src/filters/tileFeaturesSpatialIndex.ts +0 -119
- package/src/operations/aggregation.ts +0 -154
- package/src/operations/applySorting.ts +0 -109
- package/src/operations/groupBy.ts +0 -59
- package/src/operations/groupByDate.ts +0 -98
- package/src/operations/histogram.ts +0 -66
- package/src/operations/index.ts +0 -6
- package/src/operations/scatterPlot.ts +0 -50
- package/src/utils/dateUtils.ts +0 -28
- package/src/utils/getTileFormat.ts +0 -9
- package/src/utils/makeIntervalComplete.ts +0 -17
- package/src/utils/transformTileCoordsToWGS84.ts +0 -77
- package/src/utils/transformToTileCoords.ts +0 -85
- package/src/widget-sources/widget-source.ts +0 -160
- package/src/widget-sources/widget-tileset-source.ts +0 -407
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {getTileFormat} from '../utils/getTileFormat';
|
|
6
|
-
import {
|
|
7
|
-
WidgetTilesetSource,
|
|
8
|
-
WidgetTilesetSourceResult,
|
|
9
|
-
} from '../widget-sources';
|
|
10
5
|
import {baseSource} from './base-source';
|
|
11
6
|
import type {
|
|
12
7
|
SourceOptions,
|
|
@@ -17,24 +12,17 @@ import type {
|
|
|
17
12
|
export type QuadbinTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
|
|
18
13
|
type UrlParameters = {name: string};
|
|
19
14
|
|
|
20
|
-
export type QuadbinTilesetSourceResponse = TilejsonResult
|
|
21
|
-
WidgetTilesetSourceResult;
|
|
15
|
+
export type QuadbinTilesetSourceResponse = TilejsonResult;
|
|
22
16
|
|
|
23
17
|
export const quadbinTilesetSource = async function (
|
|
24
18
|
options: QuadbinTilesetSourceOptions
|
|
25
19
|
): Promise<QuadbinTilesetSourceResponse> {
|
|
26
|
-
const {tableName
|
|
20
|
+
const {tableName} = options;
|
|
27
21
|
const urlParameters: UrlParameters = {name: tableName};
|
|
28
22
|
|
|
29
|
-
return baseSource<UrlParameters>(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...options,
|
|
34
|
-
tileFormat: getTileFormat(result as TilejsonResult),
|
|
35
|
-
spatialDataColumn,
|
|
36
|
-
spatialDataType: 'quadbin',
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
23
|
+
return baseSource<UrlParameters>(
|
|
24
|
+
'tileset',
|
|
25
|
+
options,
|
|
26
|
+
urlParameters
|
|
39
27
|
) as Promise<QuadbinTilesetSourceResponse>;
|
|
40
28
|
};
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_GEO_COLUMN,
|
|
8
|
-
DEFAULT_TILE_RESOLUTION,
|
|
9
|
-
} from '../constants-internal.js';
|
|
6
|
+
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
10
7
|
import {
|
|
11
8
|
WidgetQuerySource,
|
|
12
9
|
WidgetQuerySourceResult,
|
|
@@ -46,7 +43,7 @@ export const vectorQuerySource = async function (
|
|
|
46
43
|
const {
|
|
47
44
|
columns,
|
|
48
45
|
filters,
|
|
49
|
-
spatialDataColumn =
|
|
46
|
+
spatialDataColumn = 'geom',
|
|
50
47
|
sqlQuery,
|
|
51
48
|
tileResolution = DEFAULT_TILE_RESOLUTION,
|
|
52
49
|
queryParameters,
|
|
@@ -3,10 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_GEO_COLUMN,
|
|
8
|
-
DEFAULT_TILE_RESOLUTION,
|
|
9
|
-
} from '../constants-internal.js';
|
|
6
|
+
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
10
7
|
import {
|
|
11
8
|
WidgetTableSource,
|
|
12
9
|
WidgetTableSourceResult,
|
|
@@ -45,7 +42,7 @@ export const vectorTableSource = async function (
|
|
|
45
42
|
const {
|
|
46
43
|
columns,
|
|
47
44
|
filters,
|
|
48
|
-
spatialDataColumn =
|
|
45
|
+
spatialDataColumn = 'geom',
|
|
49
46
|
tableName,
|
|
50
47
|
tileResolution = DEFAULT_TILE_RESOLUTION,
|
|
51
48
|
aggregationExp,
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {DEFAULT_GEO_COLUMN} from '../constants-internal';
|
|
6
|
-
import {getTileFormat} from '../utils/getTileFormat';
|
|
7
|
-
import {
|
|
8
|
-
WidgetTilesetSource,
|
|
9
|
-
WidgetTilesetSourceResult,
|
|
10
|
-
} from '../widget-sources';
|
|
11
5
|
import {baseSource} from './base-source';
|
|
12
6
|
import type {
|
|
13
7
|
SourceOptions,
|
|
@@ -18,24 +12,17 @@ import type {
|
|
|
18
12
|
export type VectorTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
|
|
19
13
|
type UrlParameters = {name: string};
|
|
20
14
|
|
|
21
|
-
export type VectorTilesetSourceResponse = TilejsonResult
|
|
22
|
-
WidgetTilesetSourceResult;
|
|
15
|
+
export type VectorTilesetSourceResponse = TilejsonResult;
|
|
23
16
|
|
|
24
17
|
export const vectorTilesetSource = async function (
|
|
25
18
|
options: VectorTilesetSourceOptions
|
|
26
19
|
): Promise<VectorTilesetSourceResponse> {
|
|
27
|
-
const {tableName
|
|
20
|
+
const {tableName} = options;
|
|
28
21
|
const urlParameters: UrlParameters = {name: tableName};
|
|
29
22
|
|
|
30
|
-
return baseSource<UrlParameters>(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...options,
|
|
35
|
-
tileFormat: getTileFormat(result as TilejsonResult),
|
|
36
|
-
spatialDataColumn,
|
|
37
|
-
spatialDataType: 'geo',
|
|
38
|
-
}),
|
|
39
|
-
})
|
|
23
|
+
return baseSource<UrlParameters>(
|
|
24
|
+
'tileset',
|
|
25
|
+
options,
|
|
26
|
+
urlParameters
|
|
40
27
|
) as Promise<VectorTilesetSourceResponse>;
|
|
41
28
|
};
|
package/src/spatial-index.ts
CHANGED
|
@@ -40,7 +40,7 @@ export function getSpatialFiltersResolution(
|
|
|
40
40
|
: dataResolution;
|
|
41
41
|
|
|
42
42
|
const hexagonResolution =
|
|
43
|
-
|
|
43
|
+
_getHexagonResolution(viewState, tileSize) + aggregationResLevelOffset;
|
|
44
44
|
|
|
45
45
|
return Math.min(hexagonResolution, maxSpatialFiltersResolution);
|
|
46
46
|
}
|
|
@@ -88,10 +88,13 @@ const maxH3SpatialFiltersResolutions = [
|
|
|
88
88
|
// Relative scale factor (0 = no biasing, 2 = a few hexagons cover view)
|
|
89
89
|
const BIAS = 2;
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Resolution conversion function. Takes a WebMercatorViewport and returns
|
|
93
|
+
* a H3 resolution such that the screen space size of the hexagons is
|
|
94
|
+
* "similar" to the given tileSize on screen. Intended for use with deck.gl.
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
export function _getHexagonResolution(
|
|
95
98
|
viewport: {zoom: number; latitude: number},
|
|
96
99
|
tileSize: number
|
|
97
100
|
): number {
|
package/src/types-internal.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {FilterType} from './constants.js';
|
|
2
|
-
import type {Polygon, MultiPolygon
|
|
3
|
-
import type {BinaryFeature, BinaryFeatureCollection} from '@loaders.gl/schema';
|
|
2
|
+
import type {Polygon, MultiPolygon} from 'geojson';
|
|
4
3
|
|
|
5
4
|
/******************************************************************************
|
|
6
5
|
* MAPS AND TILES
|
|
@@ -12,43 +11,6 @@ export type Format = 'json' | 'geojson' | 'tilejson';
|
|
|
12
11
|
/** @internalRemarks Source: @carto/constants, @deck.gl/carto */
|
|
13
12
|
export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
|
|
14
13
|
|
|
15
|
-
/**
|
|
16
|
-
* Alias for GeoJSON 'BBox' type, semantically representing a viewport.
|
|
17
|
-
* Order of values is "west", "south", "east", "north".
|
|
18
|
-
*/
|
|
19
|
-
export type Viewport = [number, number, number, number];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Subset of deck.gl's Tile2DHeader type, containing only the properties
|
|
23
|
-
* required for local widget calculations. Deeper dependencies on deck.gl
|
|
24
|
-
* APIs should be minimized within this library: @deck.gl/carto depends
|
|
25
|
-
* on the API client, not the other way around.
|
|
26
|
-
* @internalRemarks Source: @deck.gl/geo-layers
|
|
27
|
-
*/
|
|
28
|
-
export type Tile = {
|
|
29
|
-
index: {x: number; y: number; z: number};
|
|
30
|
-
id: string;
|
|
31
|
-
content: unknown;
|
|
32
|
-
zoom: number;
|
|
33
|
-
bbox: {west: number; east: number; north: number; south: number};
|
|
34
|
-
isVisible: boolean;
|
|
35
|
-
data?: BinaryFeatureCollection;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/** Subset of deck.gl's Tile2DHeader type, for spatial indexes. */
|
|
39
|
-
export type SpatialIndexTile = Tile & {
|
|
40
|
-
data?: (Feature & {id: bigint})[];
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/** @internalRemarks Source: @deck.gl/carto */
|
|
44
|
-
export type Raster = {
|
|
45
|
-
blockSize: number;
|
|
46
|
-
cells: {
|
|
47
|
-
numericProps: BinaryFeature['numericProps'];
|
|
48
|
-
properties: BinaryFeature['properties'];
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
14
|
/******************************************************************************
|
|
53
15
|
* AGGREGATION
|
|
54
16
|
*/
|
|
@@ -87,32 +49,12 @@ export interface Filter {
|
|
|
87
49
|
/** [a, b) a is included, b is not. */
|
|
88
50
|
[FilterType.CLOSED_OPEN]?: {owner?: string; values: number[][]};
|
|
89
51
|
[FilterType.TIME]?: {owner?: string; values: number[][]};
|
|
90
|
-
[FilterType.STRING_SEARCH]?: {
|
|
91
|
-
owner?: string;
|
|
92
|
-
values: string[];
|
|
93
|
-
params?: StringSearchOptions;
|
|
94
|
-
};
|
|
52
|
+
[FilterType.STRING_SEARCH]?: {owner?: string; values: string[]};
|
|
95
53
|
}
|
|
96
54
|
|
|
97
55
|
/** @internalRemarks Source: @carto/react-core */
|
|
98
56
|
export type FilterLogicalOperator = 'and' | 'or';
|
|
99
57
|
|
|
100
|
-
/**
|
|
101
|
-
* Type for minimum or maximum value of an interval. Values 'null' and
|
|
102
|
-
* 'undefined' are intentionally allowed, and represent an unbounded value.
|
|
103
|
-
*/
|
|
104
|
-
export type FilterIntervalExtremum = number | null | undefined;
|
|
105
|
-
export type FilterInterval = [FilterIntervalExtremum, FilterIntervalExtremum];
|
|
106
|
-
export type FilterIntervalComplete = [number, number];
|
|
107
|
-
|
|
108
|
-
export type StringSearchOptions = {
|
|
109
|
-
useRegExp?: boolean;
|
|
110
|
-
mustStart?: boolean;
|
|
111
|
-
mustEnd?: boolean;
|
|
112
|
-
caseSensitive?: boolean;
|
|
113
|
-
keepSpecialCharacters?: boolean;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
58
|
/******************************************************************************
|
|
117
59
|
* GROUPING
|
|
118
60
|
*/
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export * from './widget-source.js';
|
|
1
|
+
export * from './widget-base-source.js';
|
|
2
2
|
export * from './widget-query-source.js';
|
|
3
|
-
export * from './widget-remote-source.js';
|
|
4
3
|
export * from './widget-table-source.js';
|
|
5
|
-
export * from './widget-tileset-source.js';
|
|
6
4
|
export * from './types.js';
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
SortDirection,
|
|
6
6
|
SpatialFilter,
|
|
7
7
|
} from '../types';
|
|
8
|
-
import type {WidgetRemoteSource} from './widget-remote-source';
|
|
9
8
|
|
|
10
9
|
/******************************************************************************
|
|
11
10
|
* WIDGET API REQUESTS
|
|
@@ -17,7 +16,7 @@ export interface ViewState {
|
|
|
17
16
|
longitude: number;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
/** Common options for {@link
|
|
19
|
+
/** Common options for {@link WidgetBaseSource} requests. */
|
|
21
20
|
interface BaseRequestOptions {
|
|
22
21
|
spatialFilter?: SpatialFilter;
|
|
23
22
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
@@ -27,17 +26,15 @@ interface BaseRequestOptions {
|
|
|
27
26
|
filterOwner?: string;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
/** Options for {@link
|
|
29
|
+
/** Options for {@link WidgetBaseSource#getCategories}. */
|
|
31
30
|
export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
32
31
|
column: string;
|
|
33
32
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
34
33
|
operationColumn?: string;
|
|
35
|
-
/** Local only. */
|
|
36
|
-
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
37
34
|
}
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
|
-
* Options for {@link
|
|
37
|
+
* Options for {@link WidgetBaseSource#getFeatures}.
|
|
41
38
|
* @experimental
|
|
42
39
|
* @internal
|
|
43
40
|
*/
|
|
@@ -79,29 +76,26 @@ export interface FeaturesRequestOptions extends BaseRequestOptions {
|
|
|
79
76
|
tileResolution?: TileResolution;
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
/** Options for {@link
|
|
79
|
+
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
83
80
|
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
84
81
|
column: string;
|
|
85
|
-
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum'
|
|
82
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
86
83
|
operationExp?: string;
|
|
87
|
-
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
88
84
|
}
|
|
89
85
|
|
|
90
|
-
/** Options for {@link
|
|
86
|
+
/** Options for {@link WidgetBaseSource#getHistogram}. */
|
|
91
87
|
export interface HistogramRequestOptions extends BaseRequestOptions {
|
|
92
88
|
column: string;
|
|
93
89
|
ticks: number[];
|
|
94
90
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
95
|
-
/** Local only. */
|
|
96
|
-
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
97
91
|
}
|
|
98
92
|
|
|
99
|
-
/** Options for {@link
|
|
93
|
+
/** Options for {@link WidgetBaseSource#getRange}. */
|
|
100
94
|
export interface RangeRequestOptions extends BaseRequestOptions {
|
|
101
95
|
column: string;
|
|
102
96
|
}
|
|
103
97
|
|
|
104
|
-
/** Options for {@link
|
|
98
|
+
/** Options for {@link WidgetBaseSource#getScatter}. */
|
|
105
99
|
export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
106
100
|
xAxisColumn: string;
|
|
107
101
|
xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
@@ -109,7 +103,7 @@ export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
|
109
103
|
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
110
104
|
}
|
|
111
105
|
|
|
112
|
-
/** Options for {@link
|
|
106
|
+
/** Options for {@link WidgetBaseSource#getTable}. */
|
|
113
107
|
export interface TableRequestOptions extends BaseRequestOptions {
|
|
114
108
|
columns: string[];
|
|
115
109
|
sortBy?: string;
|
|
@@ -117,16 +111,12 @@ export interface TableRequestOptions extends BaseRequestOptions {
|
|
|
117
111
|
sortByColumnType?: SortColumnType;
|
|
118
112
|
offset?: number;
|
|
119
113
|
limit?: number;
|
|
120
|
-
/** Local only. */
|
|
121
|
-
searchFilterColumn?: string;
|
|
122
|
-
/** Local only. */
|
|
123
|
-
searchFilterText?: string;
|
|
124
114
|
}
|
|
125
115
|
|
|
126
|
-
/** Options for {@link
|
|
116
|
+
/** Options for {@link WidgetBaseSource#getTimeSeries}. */
|
|
127
117
|
export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
128
118
|
column: string;
|
|
129
|
-
stepSize
|
|
119
|
+
stepSize?: GroupDateType;
|
|
130
120
|
stepMultiplier?: number;
|
|
131
121
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
132
122
|
operationColumn?: string;
|
|
@@ -141,35 +131,35 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
|
141
131
|
*/
|
|
142
132
|
|
|
143
133
|
/**
|
|
144
|
-
* Response from {@link
|
|
134
|
+
* Response from {@link WidgetBaseSource#getFeatures}.
|
|
145
135
|
* @experimental
|
|
146
136
|
* @internal
|
|
147
137
|
*/
|
|
148
138
|
export type FeaturesResponse = {rows: Record<string, unknown>[]};
|
|
149
139
|
|
|
150
|
-
/** Response from {@link
|
|
151
|
-
export type FormulaResponse = {value: number
|
|
140
|
+
/** Response from {@link WidgetBaseSource#getFormula}. */
|
|
141
|
+
export type FormulaResponse = {value: number};
|
|
152
142
|
|
|
153
|
-
/** Response from {@link
|
|
143
|
+
/** Response from {@link WidgetBaseSource#getCategories}. */
|
|
154
144
|
export type CategoryResponse = {name: string; value: number}[];
|
|
155
145
|
|
|
156
|
-
/** Response from {@link
|
|
157
|
-
export type RangeResponse = {min: number; max: number}
|
|
146
|
+
/** Response from {@link WidgetBaseSource#getRange}. */
|
|
147
|
+
export type RangeResponse = {min: number; max: number};
|
|
158
148
|
|
|
159
|
-
/** Response from {@link
|
|
149
|
+
/** Response from {@link WidgetBaseSource#getTable}. */
|
|
160
150
|
export type TableResponse = {
|
|
161
151
|
totalCount: number;
|
|
162
152
|
rows: Record<string, number | string>[];
|
|
163
153
|
};
|
|
164
154
|
|
|
165
|
-
/** Response from {@link
|
|
155
|
+
/** Response from {@link WidgetBaseSource#getScatter}. */
|
|
166
156
|
export type ScatterResponse = [number, number][];
|
|
167
157
|
|
|
168
|
-
/** Response from {@link
|
|
158
|
+
/** Response from {@link WidgetBaseSource#getTimeSeries}. */
|
|
169
159
|
export type TimeSeriesResponse = {
|
|
170
160
|
rows: {name: string; value: number}[];
|
|
171
|
-
categories
|
|
161
|
+
categories: string[];
|
|
172
162
|
};
|
|
173
163
|
|
|
174
|
-
/** Response from {@link
|
|
164
|
+
/** Response from {@link WidgetBaseSource#getHistogram}. */
|
|
175
165
|
export type HistogramResponse = number[];
|
|
@@ -16,21 +16,99 @@ import {
|
|
|
16
16
|
TableResponse,
|
|
17
17
|
TimeSeriesRequestOptions,
|
|
18
18
|
TimeSeriesResponse,
|
|
19
|
+
ViewState,
|
|
19
20
|
} from './types.js';
|
|
20
|
-
import {
|
|
21
|
+
import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
|
|
22
|
+
import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
|
|
23
|
+
import {getClient} from '../client.js';
|
|
24
|
+
import {ModelSource} from '../models/model.js';
|
|
25
|
+
import {SourceOptions} from '../sources/index.js';
|
|
26
|
+
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
21
27
|
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
22
|
-
import {
|
|
28
|
+
import {getSpatialFiltersResolution} from '../spatial-index.js';
|
|
29
|
+
import {AggregationOptions} from '../sources/types.js';
|
|
23
30
|
|
|
24
|
-
export
|
|
31
|
+
export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
32
|
+
apiVersion?: ApiVersion;
|
|
33
|
+
filters?: Record<string, Filter>;
|
|
34
|
+
filtersLogicalOperator?: FilterLogicalOperator;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type WidgetSource = WidgetBaseSource<WidgetBaseSourceProps>;
|
|
25
38
|
|
|
26
39
|
/**
|
|
27
|
-
* Source for Widget API requests.
|
|
40
|
+
* Source for Widget API requests on a data source defined by a SQL query.
|
|
28
41
|
*
|
|
29
42
|
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
30
43
|
*/
|
|
31
|
-
export abstract class
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
45
|
+
readonly props: Props;
|
|
46
|
+
|
|
47
|
+
static defaultProps: Partial<WidgetBaseSourceProps> = {
|
|
48
|
+
apiVersion: ApiVersion.V3,
|
|
49
|
+
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
50
|
+
clientId: getClient(),
|
|
51
|
+
filters: {},
|
|
52
|
+
filtersLogicalOperator: 'and',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
constructor(props: Props) {
|
|
56
|
+
this.props = {...WidgetBaseSource.defaultProps, ...props};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Subclasses of {@link WidgetBaseSource} must implement this method, calling
|
|
61
|
+
* {@link WidgetBaseSource.prototype._getModelSource} for common source
|
|
62
|
+
* properties, and adding additional required properties including 'type' and
|
|
63
|
+
* 'data'.
|
|
64
|
+
*/
|
|
65
|
+
protected abstract getModelSource(owner: string | undefined): ModelSource;
|
|
66
|
+
|
|
67
|
+
protected _getModelSource(
|
|
68
|
+
owner?: string
|
|
69
|
+
): Omit<ModelSource, 'type' | 'data'> {
|
|
70
|
+
const props = this.props;
|
|
71
|
+
return {
|
|
72
|
+
apiVersion: props.apiVersion as ApiVersion,
|
|
73
|
+
apiBaseUrl: props.apiBaseUrl as string,
|
|
74
|
+
clientId: props.clientId as string,
|
|
75
|
+
accessToken: props.accessToken,
|
|
76
|
+
connectionName: props.connectionName,
|
|
77
|
+
filters: getApplicableFilters(owner, props.filters),
|
|
78
|
+
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
79
|
+
spatialDataType: props.spatialDataType,
|
|
80
|
+
spatialDataColumn: props.spatialDataColumn,
|
|
81
|
+
dataResolution: (props as Partial<AggregationOptions>).dataResolution,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
protected _getSpatialFiltersResolution(
|
|
86
|
+
source: Omit<ModelSource, 'type' | 'data'>,
|
|
87
|
+
spatialFilter?: SpatialFilter,
|
|
88
|
+
referenceViewState?: ViewState
|
|
89
|
+
): number | undefined {
|
|
90
|
+
// spatialFiltersResolution applies only to spatial index sources.
|
|
91
|
+
if (!spatialFilter || source.spatialDataType === 'geo') {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!referenceViewState) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
'Missing required option, "spatialIndexReferenceViewState".'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return getSpatialFiltersResolution(source, referenceViewState);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/****************************************************************************
|
|
105
|
+
* CATEGORIES
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns a list of labeled datapoints for categorical data. Suitable for
|
|
110
|
+
* charts including grouped bar charts, pie charts, and tree charts.
|
|
111
|
+
*/
|
|
34
112
|
async getCategories(
|
|
35
113
|
options: CategoryRequestOptions
|
|
36
114
|
): Promise<CategoryResponse> {
|
|
@@ -69,6 +147,18 @@ export abstract class WidgetRemoteSource<
|
|
|
69
147
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
70
148
|
}
|
|
71
149
|
|
|
150
|
+
/****************************************************************************
|
|
151
|
+
* FEATURES
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
156
|
+
* matching features. In datasets containing features with duplicate geometries,
|
|
157
|
+
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
158
|
+
* results may be returned than IDs in the request.
|
|
159
|
+
* @internal
|
|
160
|
+
* @experimental
|
|
161
|
+
*/
|
|
72
162
|
async getFeatures(
|
|
73
163
|
options: FeaturesRequestOptions
|
|
74
164
|
): Promise<FeaturesResponse> {
|
|
@@ -111,6 +201,14 @@ export abstract class WidgetRemoteSource<
|
|
|
111
201
|
}).then(({rows}: FeaturesModelResponse) => ({rows}));
|
|
112
202
|
}
|
|
113
203
|
|
|
204
|
+
/****************************************************************************
|
|
205
|
+
* FORMULA
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Returns a scalar numerical statistic over all matching data. Suitable
|
|
210
|
+
* for 'headline' or 'scorecard' figures such as counts and sums.
|
|
211
|
+
*/
|
|
114
212
|
async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
|
|
115
213
|
const {
|
|
116
214
|
filterOwner,
|
|
@@ -139,15 +237,19 @@ export abstract class WidgetRemoteSource<
|
|
|
139
237
|
spatialFiltersMode,
|
|
140
238
|
spatialFilter,
|
|
141
239
|
},
|
|
142
|
-
params: {
|
|
143
|
-
column: column ?? '*',
|
|
144
|
-
operation: operation ?? 'count',
|
|
145
|
-
operationExp,
|
|
146
|
-
},
|
|
240
|
+
params: {column: column ?? '*', operation, operationExp},
|
|
147
241
|
opts: {abortController},
|
|
148
242
|
}).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
149
243
|
}
|
|
150
244
|
|
|
245
|
+
/****************************************************************************
|
|
246
|
+
* HISTOGRAM
|
|
247
|
+
*/
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Returns a list of labeled datapoints for 'bins' of data defined as ticks
|
|
251
|
+
* over a numerical range. Suitable for histogram charts.
|
|
252
|
+
*/
|
|
151
253
|
async getHistogram(
|
|
152
254
|
options: HistogramRequestOptions
|
|
153
255
|
): Promise<HistogramResponse> {
|
|
@@ -194,6 +296,15 @@ export abstract class WidgetRemoteSource<
|
|
|
194
296
|
return [];
|
|
195
297
|
}
|
|
196
298
|
|
|
299
|
+
/****************************************************************************
|
|
300
|
+
* RANGE
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Returns a range (min and max) for a numerical column of matching rows.
|
|
305
|
+
* Suitable for displaying certain 'headline' or 'scorecard' statistics,
|
|
306
|
+
* or rendering a range slider UI for filtering.
|
|
307
|
+
*/
|
|
197
308
|
async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
|
|
198
309
|
const {
|
|
199
310
|
filterOwner,
|
|
@@ -226,6 +337,14 @@ export abstract class WidgetRemoteSource<
|
|
|
226
337
|
}).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
227
338
|
}
|
|
228
339
|
|
|
340
|
+
/****************************************************************************
|
|
341
|
+
* SCATTER
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
|
|
346
|
+
* values. Suitable for rendering scatter plots.
|
|
347
|
+
*/
|
|
229
348
|
async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
|
|
230
349
|
const {
|
|
231
350
|
filterOwner,
|
|
@@ -271,6 +390,14 @@ export abstract class WidgetRemoteSource<
|
|
|
271
390
|
.then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
|
|
272
391
|
}
|
|
273
392
|
|
|
393
|
+
/****************************************************************************
|
|
394
|
+
* TABLE
|
|
395
|
+
*/
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Returns a list of arbitrary data rows, with support for pagination and
|
|
399
|
+
* sorting. Suitable for displaying tables and lists.
|
|
400
|
+
*/
|
|
274
401
|
async getTable(options: TableRequestOptions): Promise<TableResponse> {
|
|
275
402
|
const {
|
|
276
403
|
filterOwner,
|
|
@@ -316,6 +443,14 @@ export abstract class WidgetRemoteSource<
|
|
|
316
443
|
}));
|
|
317
444
|
}
|
|
318
445
|
|
|
446
|
+
/****************************************************************************
|
|
447
|
+
* TIME SERIES
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Returns a series of labeled numerical values, grouped into equally-sized
|
|
452
|
+
* time intervals. Suitable for rendering time series charts.
|
|
453
|
+
*/
|
|
319
454
|
async getTimeSeries(
|
|
320
455
|
options: TimeSeriesRequestOptions
|
|
321
456
|
): Promise<TimeSeriesResponse> {
|
|
@@ -3,10 +3,7 @@ import {
|
|
|
3
3
|
QuadbinQuerySourceOptions,
|
|
4
4
|
VectorQuerySourceOptions,
|
|
5
5
|
} from '../sources/index.js';
|
|
6
|
-
import {
|
|
7
|
-
WidgetRemoteSource,
|
|
8
|
-
WidgetRemoteSourceProps,
|
|
9
|
-
} from './widget-remote-source.js';
|
|
6
|
+
import {WidgetBaseSource, WidgetBaseSourceProps} from './widget-base-source.js';
|
|
10
7
|
import {ModelSource} from '../models/model.js';
|
|
11
8
|
|
|
12
9
|
type LayerQuerySourceOptions =
|
|
@@ -38,8 +35,8 @@ export type WidgetQuerySourceResult = {widgetSource: WidgetQuerySource};
|
|
|
38
35
|
* const { widgetSource } = await data;
|
|
39
36
|
* ```
|
|
40
37
|
*/
|
|
41
|
-
export class WidgetQuerySource extends
|
|
42
|
-
LayerQuerySourceOptions &
|
|
38
|
+
export class WidgetQuerySource extends WidgetBaseSource<
|
|
39
|
+
LayerQuerySourceOptions & WidgetBaseSourceProps
|
|
43
40
|
> {
|
|
44
41
|
protected override getModelSource(owner: string): ModelSource {
|
|
45
42
|
return {
|