@carto/api-client 0.5.0-alpha.1 → 0.5.0-alpha.11
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 +3163 -3206
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +1389 -0
- package/build/api-client.d.ts +1389 -0
- package/build/api-client.js +3674 -0
- package/build/api-client.js.map +1 -0
- package/build/worker.d.ts +2 -0
- package/build/worker.js +1949 -0
- package/build/worker.js.map +1 -0
- package/package.json +60 -45
- package/src/api/carto-api-error.ts +1 -1
- package/src/api/query.ts +5 -5
- package/src/api/request-with-parameters.ts +6 -6
- package/src/client.ts +3 -3
- package/src/constants-internal.ts +5 -11
- package/src/constants.ts +6 -6
- package/src/deck/get-data-filter-extension-props.ts +146 -0
- package/src/deck/index.ts +1 -0
- package/src/filters/Filter.ts +18 -8
- package/src/filters/FilterTypes.ts +2 -2
- package/src/filters/geosjonFeatures.ts +2 -2
- package/src/filters/tileFeatures.ts +12 -17
- package/src/filters.ts +4 -4
- package/src/geo.ts +12 -14
- package/src/global.d.ts +3 -8
- package/src/index.ts +3 -0
- package/src/models/common.ts +11 -9
- package/src/models/model.ts +3 -4
- package/src/operations/aggregation.ts +5 -5
- package/src/operations/applySorting.ts +4 -4
- package/src/operations/groupBy.ts +4 -4
- package/src/operations/groupByDate.ts +1 -1
- package/src/operations/histogram.ts +4 -4
- package/src/operations/scatterPlot.ts +4 -4
- package/src/sources/base-source.ts +8 -8
- package/src/sources/boundary-query-source.ts +2 -2
- package/src/sources/boundary-table-source.ts +2 -2
- package/src/sources/h3-query-source.ts +7 -5
- package/src/sources/h3-table-source.ts +7 -5
- package/src/sources/h3-tileset-source.ts +4 -4
- package/src/sources/index.ts +26 -26
- package/src/sources/quadbin-query-source.ts +7 -5
- package/src/sources/quadbin-table-source.ts +7 -5
- package/src/sources/quadbin-tileset-source.ts +4 -4
- package/src/sources/raster-source.ts +2 -2
- package/src/sources/types.ts +9 -3
- package/src/sources/vector-query-source.ts +2 -3
- package/src/sources/vector-table-source.ts +2 -3
- package/src/sources/vector-tileset-source.ts +5 -5
- package/src/spatial-index.ts +12 -10
- package/src/types-internal.ts +5 -5
- package/src/types.ts +15 -15
- package/src/utils/makeIntervalComplete.ts +1 -1
- package/src/utils.ts +3 -3
- package/src/widget-sources/index.ts +1 -0
- package/src/widget-sources/types.ts +6 -4
- package/src/widget-sources/widget-query-source.ts +6 -2
- package/src/widget-sources/widget-remote-source.ts +67 -26
- package/src/widget-sources/widget-source.ts +10 -25
- package/src/widget-sources/widget-table-source.ts +6 -2
- package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
- package/src/widget-sources/widget-tileset-source.ts +200 -299
- package/src/workers/constants.ts +13 -0
- package/src/workers/types.ts +19 -0
- package/src/workers/widget-tileset-worker.ts +40 -0
- package/build/api/carto-api-error.d.ts +0 -26
- package/build/api/endpoints.d.ts +0 -24
- package/build/api/index.d.ts +0 -5
- package/build/api/query.d.ts +0 -3
- package/build/api/request-with-parameters.d.ts +0 -10
- package/build/api-client.modern.js +0 -3574
- package/build/api-client.modern.js.map +0 -1
- package/build/client.d.ts +0 -14
- package/build/constants-internal.d.ts +0 -26
- package/build/constants.d.ts +0 -53
- 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/filters.d.ts +0 -39
- package/build/geo.d.ts +0 -19
- package/build/index.d.ts +0 -14
- package/build/models/common.d.ts +0 -27
- package/build/models/index.d.ts +0 -3
- package/build/models/model.d.ts +0 -37
- 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/sources/base-source.d.ts +0 -4
- package/build/sources/boundary-query-source.d.ts +0 -10
- package/build/sources/boundary-table-source.d.ts +0 -8
- package/build/sources/h3-query-source.d.ts +0 -5
- package/build/sources/h3-table-source.d.ts +0 -5
- package/build/sources/h3-tileset-source.d.ts +0 -5
- package/build/sources/index.d.ts +0 -26
- package/build/sources/quadbin-query-source.d.ts +0 -5
- package/build/sources/quadbin-table-source.d.ts +0 -5
- package/build/sources/quadbin-tileset-source.d.ts +0 -5
- package/build/sources/raster-source.d.ts +0 -4
- package/build/sources/types.d.ts +0 -366
- package/build/sources/vector-query-source.d.ts +0 -5
- package/build/sources/vector-table-source.d.ts +0 -5
- package/build/sources/vector-tileset-source.d.ts +0 -5
- package/build/spatial-index.d.ts +0 -8
- package/build/types-internal.d.ts +0 -56
- package/build/types.d.ts +0 -140
- 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/utils.d.ts +0 -32
- package/build/widget-sources/index.d.ts +0 -5
- package/build/widget-sources/types.d.ts +0 -158
- package/build/widget-sources/widget-query-source.d.ts +0 -33
- package/build/widget-sources/widget-remote-source.d.ts +0 -18
- package/build/widget-sources/widget-source.d.ts +0 -74
- package/build/widget-sources/widget-table-source.d.ts +0 -33
- package/build/widget-sources/widget-tileset-source.d.ts +0 -76
package/src/types.ts
CHANGED
|
@@ -6,10 +6,10 @@ import type {BinaryFeature, BinaryFeatureCollection} from '@loaders.gl/schema';
|
|
|
6
6
|
* MAPS AND TILES
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/** @
|
|
9
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
10
10
|
export type Format = 'json' | 'geojson' | 'tilejson';
|
|
11
11
|
|
|
12
|
-
/** @
|
|
12
|
+
/** @privateRemarks Source: @carto/constants, @deck.gl/carto */
|
|
13
13
|
export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -23,7 +23,7 @@ export type Viewport = [number, number, number, number];
|
|
|
23
23
|
* required for local widget calculations. Deeper dependencies on deck.gl
|
|
24
24
|
* APIs should be minimized within this library: @deck.gl/carto depends
|
|
25
25
|
* on the API client, not the other way around.
|
|
26
|
-
* @
|
|
26
|
+
* @privateRemarks Source: @deck.gl/geo-layers
|
|
27
27
|
*/
|
|
28
28
|
export type Tile = {
|
|
29
29
|
index: {x: number; y: number; z: number};
|
|
@@ -40,7 +40,7 @@ export type SpatialIndexTile = Tile & {
|
|
|
40
40
|
data?: (Feature & {id: bigint})[];
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
/** @
|
|
43
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
44
44
|
export type Raster = {
|
|
45
45
|
blockSize: number;
|
|
46
46
|
cells: {
|
|
@@ -56,8 +56,8 @@ export type Raster = {
|
|
|
56
56
|
/**
|
|
57
57
|
* Enum for the different types of aggregations available for widgets.
|
|
58
58
|
*
|
|
59
|
-
* @
|
|
60
|
-
* @
|
|
59
|
+
* @privateRemarks Source: @carto/constants
|
|
60
|
+
* @privateRemarks Converted from enum to type union, for improved declarative API.
|
|
61
61
|
*/
|
|
62
62
|
export type AggregationType =
|
|
63
63
|
| 'count'
|
|
@@ -71,15 +71,15 @@ export type AggregationType =
|
|
|
71
71
|
* FILTERS
|
|
72
72
|
*/
|
|
73
73
|
|
|
74
|
-
/** @
|
|
74
|
+
/** @privateRemarks Source: @carto/react-api */
|
|
75
75
|
export type SpatialFilter = Polygon | MultiPolygon;
|
|
76
76
|
|
|
77
|
-
/** @
|
|
77
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
78
78
|
export interface Filters {
|
|
79
79
|
[column: string]: Filter;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/** @
|
|
82
|
+
/** @privateRemarks Source: @carto/react-api, @deck.gl/carto */
|
|
83
83
|
export interface Filter {
|
|
84
84
|
[FilterType.IN]?: {owner?: string; values: number[] | string[]};
|
|
85
85
|
/** [a, b] both are included. */
|
|
@@ -94,7 +94,7 @@ export interface Filter {
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/** @
|
|
97
|
+
/** @privateRemarks Source: @carto/react-core */
|
|
98
98
|
export type FilterLogicalOperator = 'and' | 'or';
|
|
99
99
|
|
|
100
100
|
/**
|
|
@@ -120,7 +120,7 @@ export type StringSearchOptions = {
|
|
|
120
120
|
/**
|
|
121
121
|
* Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
|
|
122
122
|
*
|
|
123
|
-
* @
|
|
123
|
+
* @privateRemarks Source: @carto/react-core
|
|
124
124
|
*/
|
|
125
125
|
export type GroupDateType =
|
|
126
126
|
| 'year'
|
|
@@ -142,7 +142,7 @@ export type SortColumnType = 'number' | 'string' | 'date';
|
|
|
142
142
|
* SQL QUERY PARAMETERS
|
|
143
143
|
*/
|
|
144
144
|
|
|
145
|
-
/** @
|
|
145
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
146
146
|
export type QueryParameterValue =
|
|
147
147
|
| string
|
|
148
148
|
| number
|
|
@@ -150,11 +150,11 @@ export type QueryParameterValue =
|
|
|
150
150
|
| Array<QueryParameterValue>
|
|
151
151
|
| object;
|
|
152
152
|
|
|
153
|
-
/** @
|
|
153
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
154
154
|
export type NamedQueryParameter = Record<string, QueryParameterValue>;
|
|
155
155
|
|
|
156
|
-
/** @
|
|
156
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
157
157
|
export type PositionalQueryParameter = QueryParameterValue[];
|
|
158
158
|
|
|
159
|
-
/** @
|
|
159
|
+
/** @privateRemarks Source: @deck.gl/carto */
|
|
160
160
|
export type QueryParameters = NamedQueryParameter | PositionalQueryParameter;
|
package/src/utils.ts
CHANGED
|
@@ -39,7 +39,7 @@ type Row<T> = Record<string, T> | Record<string, T>[] | T[] | T;
|
|
|
39
39
|
* Due to each data warehouse having its own behavior with columns,
|
|
40
40
|
* we need to normalize them and transform every key to lowercase.
|
|
41
41
|
*
|
|
42
|
-
* @
|
|
42
|
+
* @privateRemarks Source: @carto/react-widgets
|
|
43
43
|
* @internal
|
|
44
44
|
*/
|
|
45
45
|
export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
|
|
@@ -59,7 +59,7 @@ export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
|
|
|
59
59
|
) as R;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/** @
|
|
62
|
+
/** @privateRemarks Source: @carto/react-core */
|
|
63
63
|
export function assert(condition: unknown, message: string): asserts condition {
|
|
64
64
|
if (!condition) {
|
|
65
65
|
throw new Error(message);
|
|
@@ -67,7 +67,7 @@ export function assert(condition: unknown, message: string): asserts condition {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
|
-
* @
|
|
70
|
+
* @privateRemarks Source: @carto/react-core
|
|
71
71
|
* @internal
|
|
72
72
|
*/
|
|
73
73
|
export class InvalidColumnError extends Error {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types';
|
|
1
|
+
import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types.js';
|
|
2
2
|
import {
|
|
3
|
+
Filters,
|
|
3
4
|
GroupDateType,
|
|
4
5
|
SortColumnType,
|
|
5
6
|
SortDirection,
|
|
6
7
|
SpatialFilter,
|
|
7
|
-
} from '../types';
|
|
8
|
-
import type {WidgetRemoteSource} from './widget-remote-source';
|
|
8
|
+
} from '../types.js';
|
|
9
9
|
|
|
10
10
|
/******************************************************************************
|
|
11
11
|
* WIDGET API REQUESTS
|
|
@@ -19,11 +19,13 @@ export interface ViewState {
|
|
|
19
19
|
|
|
20
20
|
/** Common options for {@link WidgetRemoteSource} requests. */
|
|
21
21
|
interface BaseRequestOptions {
|
|
22
|
+
signal?: AbortSignal;
|
|
22
23
|
spatialFilter?: SpatialFilter;
|
|
23
24
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
24
25
|
/** Required for table- and query-based spatial index sources (H3, Quadbin). */
|
|
25
26
|
spatialIndexReferenceViewState?: ViewState;
|
|
26
|
-
|
|
27
|
+
/** Overrides source filters, if any. */
|
|
28
|
+
filters?: Filters;
|
|
27
29
|
filterOwner?: string;
|
|
28
30
|
}
|
|
29
31
|
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
WidgetRemoteSourceProps,
|
|
9
9
|
} from './widget-remote-source.js';
|
|
10
10
|
import {ModelSource} from '../models/model.js';
|
|
11
|
+
import {Filters} from '../types.js';
|
|
11
12
|
|
|
12
13
|
type LayerQuerySourceOptions =
|
|
13
14
|
| Omit<VectorQuerySourceOptions, 'filters'>
|
|
@@ -41,9 +42,12 @@ export type WidgetQuerySourceResult = {widgetSource: WidgetQuerySource};
|
|
|
41
42
|
export class WidgetQuerySource extends WidgetRemoteSource<
|
|
42
43
|
LayerQuerySourceOptions & WidgetRemoteSourceProps
|
|
43
44
|
> {
|
|
44
|
-
protected override getModelSource(
|
|
45
|
+
protected override getModelSource(
|
|
46
|
+
filters: Filters | undefined,
|
|
47
|
+
filterOwner?: string
|
|
48
|
+
): ModelSource {
|
|
45
49
|
return {
|
|
46
|
-
...super._getModelSource(
|
|
50
|
+
...super._getModelSource(filters, filterOwner),
|
|
47
51
|
type: 'query',
|
|
48
52
|
data: this.props.sqlQuery,
|
|
49
53
|
queryParameters: this.props.queryParameters,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {executeModel} from '../models/index.js';
|
|
1
|
+
import {executeModel, ModelSource} from '../models/index.js';
|
|
2
2
|
import {
|
|
3
3
|
CategoryRequestOptions,
|
|
4
4
|
CategoryResponse,
|
|
@@ -17,9 +17,12 @@ import {
|
|
|
17
17
|
TimeSeriesRequestOptions,
|
|
18
18
|
TimeSeriesResponse,
|
|
19
19
|
} from './types.js';
|
|
20
|
-
import {normalizeObjectKeys} from '../utils.js';
|
|
20
|
+
import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
|
|
21
21
|
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
22
22
|
import {WidgetSource, WidgetSourceProps} from './widget-source.js';
|
|
23
|
+
import {Filters} from '../types.js';
|
|
24
|
+
import {ApiVersion} from '../constants.js';
|
|
25
|
+
import {AggregationOptions} from '../sources/types.js';
|
|
23
26
|
|
|
24
27
|
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
25
28
|
|
|
@@ -31,19 +34,50 @@ export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
|
31
34
|
export abstract class WidgetRemoteSource<
|
|
32
35
|
Props extends WidgetRemoteSourceProps,
|
|
33
36
|
> extends WidgetSource<Props> {
|
|
37
|
+
/**
|
|
38
|
+
* Subclasses of {@link WidgetRemoteSource} must implement this method, calling
|
|
39
|
+
* {@link WidgetRemoteSource.prototype._getModelSource} for common source
|
|
40
|
+
* properties, and adding additional required properties including 'type' and
|
|
41
|
+
* 'data'.
|
|
42
|
+
*/
|
|
43
|
+
protected abstract getModelSource(
|
|
44
|
+
filters: Filters | undefined,
|
|
45
|
+
filterOwner?: string
|
|
46
|
+
): ModelSource;
|
|
47
|
+
|
|
48
|
+
protected _getModelSource(
|
|
49
|
+
filters: Filters | undefined,
|
|
50
|
+
filterOwner?: string
|
|
51
|
+
): Omit<ModelSource, 'type' | 'data'> {
|
|
52
|
+
const props = this.props;
|
|
53
|
+
return {
|
|
54
|
+
apiVersion: props.apiVersion as ApiVersion,
|
|
55
|
+
apiBaseUrl: props.apiBaseUrl as string,
|
|
56
|
+
clientId: props.clientId as string,
|
|
57
|
+
accessToken: props.accessToken,
|
|
58
|
+
connectionName: props.connectionName,
|
|
59
|
+
filters: getApplicableFilters(filterOwner, filters || props.filters),
|
|
60
|
+
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
61
|
+
spatialDataType: props.spatialDataType,
|
|
62
|
+
spatialDataColumn: props.spatialDataColumn,
|
|
63
|
+
dataResolution: (props as Partial<AggregationOptions>).dataResolution,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
34
67
|
async getCategories(
|
|
35
68
|
options: CategoryRequestOptions
|
|
36
69
|
): Promise<CategoryResponse> {
|
|
37
70
|
const {
|
|
71
|
+
signal,
|
|
72
|
+
filters = this.props.filters,
|
|
38
73
|
filterOwner,
|
|
39
74
|
spatialFilter,
|
|
40
75
|
spatialFiltersMode,
|
|
41
76
|
spatialIndexReferenceViewState,
|
|
42
|
-
abortController,
|
|
43
77
|
...params
|
|
44
78
|
} = options;
|
|
45
79
|
const {column, operation, operationColumn} = params;
|
|
46
|
-
const source = this.getModelSource(filterOwner);
|
|
80
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
47
81
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
48
82
|
source,
|
|
49
83
|
spatialFilter,
|
|
@@ -65,7 +99,7 @@ export abstract class WidgetRemoteSource<
|
|
|
65
99
|
operation,
|
|
66
100
|
operationColumn: operationColumn || column,
|
|
67
101
|
},
|
|
68
|
-
opts: {
|
|
102
|
+
opts: {signal, headers: this.props.headers},
|
|
69
103
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
70
104
|
}
|
|
71
105
|
|
|
@@ -73,15 +107,16 @@ export abstract class WidgetRemoteSource<
|
|
|
73
107
|
options: FeaturesRequestOptions
|
|
74
108
|
): Promise<FeaturesResponse> {
|
|
75
109
|
const {
|
|
110
|
+
signal,
|
|
111
|
+
filters = this.props.filters,
|
|
76
112
|
filterOwner,
|
|
77
113
|
spatialFilter,
|
|
78
114
|
spatialFiltersMode,
|
|
79
115
|
spatialIndexReferenceViewState,
|
|
80
|
-
abortController,
|
|
81
116
|
...params
|
|
82
117
|
} = options;
|
|
83
118
|
const {columns, dataType, featureIds, z, limit, tileResolution} = params;
|
|
84
|
-
const source = this.getModelSource(filterOwner);
|
|
119
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
85
120
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
86
121
|
source,
|
|
87
122
|
spatialFilter,
|
|
@@ -106,23 +141,24 @@ export abstract class WidgetRemoteSource<
|
|
|
106
141
|
limit: limit || 1000,
|
|
107
142
|
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
|
|
108
143
|
},
|
|
109
|
-
opts: {
|
|
144
|
+
opts: {signal, headers: this.props.headers},
|
|
110
145
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
111
146
|
}).then(({rows}: FeaturesModelResponse) => ({rows}));
|
|
112
147
|
}
|
|
113
148
|
|
|
114
149
|
async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
|
|
115
150
|
const {
|
|
151
|
+
signal,
|
|
152
|
+
filters = this.props.filters,
|
|
116
153
|
filterOwner,
|
|
117
154
|
spatialFilter,
|
|
118
155
|
spatialFiltersMode,
|
|
119
156
|
spatialIndexReferenceViewState,
|
|
120
|
-
abortController,
|
|
121
157
|
operationExp,
|
|
122
158
|
...params
|
|
123
159
|
} = options;
|
|
124
160
|
const {column, operation} = params;
|
|
125
|
-
const source = this.getModelSource(filterOwner);
|
|
161
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
126
162
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
127
163
|
source,
|
|
128
164
|
spatialFilter,
|
|
@@ -144,7 +180,7 @@ export abstract class WidgetRemoteSource<
|
|
|
144
180
|
operation: operation ?? 'count',
|
|
145
181
|
operationExp,
|
|
146
182
|
},
|
|
147
|
-
opts: {
|
|
183
|
+
opts: {signal, headers: this.props.headers},
|
|
148
184
|
}).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
149
185
|
}
|
|
150
186
|
|
|
@@ -152,15 +188,16 @@ export abstract class WidgetRemoteSource<
|
|
|
152
188
|
options: HistogramRequestOptions
|
|
153
189
|
): Promise<HistogramResponse> {
|
|
154
190
|
const {
|
|
191
|
+
signal,
|
|
192
|
+
filters = this.props.filters,
|
|
155
193
|
filterOwner,
|
|
156
194
|
spatialFilter,
|
|
157
195
|
spatialFiltersMode,
|
|
158
196
|
spatialIndexReferenceViewState,
|
|
159
|
-
abortController,
|
|
160
197
|
...params
|
|
161
198
|
} = options;
|
|
162
199
|
const {column, operation, ticks} = params;
|
|
163
|
-
const source = this.getModelSource(filterOwner);
|
|
200
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
164
201
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
165
202
|
source,
|
|
166
203
|
spatialFilter,
|
|
@@ -178,7 +215,7 @@ export abstract class WidgetRemoteSource<
|
|
|
178
215
|
spatialFilter,
|
|
179
216
|
},
|
|
180
217
|
params: {column, operation, ticks},
|
|
181
|
-
opts: {
|
|
218
|
+
opts: {signal, headers: this.props.headers},
|
|
182
219
|
}).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
|
|
183
220
|
|
|
184
221
|
if (data.length) {
|
|
@@ -196,15 +233,16 @@ export abstract class WidgetRemoteSource<
|
|
|
196
233
|
|
|
197
234
|
async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
|
|
198
235
|
const {
|
|
236
|
+
signal,
|
|
237
|
+
filters = this.props.filters,
|
|
199
238
|
filterOwner,
|
|
200
239
|
spatialFilter,
|
|
201
240
|
spatialFiltersMode,
|
|
202
241
|
spatialIndexReferenceViewState,
|
|
203
|
-
abortController,
|
|
204
242
|
...params
|
|
205
243
|
} = options;
|
|
206
244
|
const {column} = params;
|
|
207
|
-
const source = this.getModelSource(filterOwner);
|
|
245
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
208
246
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
209
247
|
source,
|
|
210
248
|
spatialFilter,
|
|
@@ -222,23 +260,24 @@ export abstract class WidgetRemoteSource<
|
|
|
222
260
|
spatialFilter,
|
|
223
261
|
},
|
|
224
262
|
params: {column},
|
|
225
|
-
opts: {
|
|
263
|
+
opts: {signal, headers: this.props.headers},
|
|
226
264
|
}).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
227
265
|
}
|
|
228
266
|
|
|
229
267
|
async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
|
|
230
268
|
const {
|
|
269
|
+
signal,
|
|
270
|
+
filters = this.props.filters,
|
|
231
271
|
filterOwner,
|
|
232
272
|
spatialFilter,
|
|
233
273
|
spatialFiltersMode,
|
|
234
274
|
spatialIndexReferenceViewState,
|
|
235
|
-
abortController,
|
|
236
275
|
...params
|
|
237
276
|
} = options;
|
|
238
277
|
const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
|
|
239
278
|
params;
|
|
240
279
|
|
|
241
|
-
const source = this.getModelSource(filterOwner);
|
|
280
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
242
281
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
243
282
|
source,
|
|
244
283
|
spatialFilter,
|
|
@@ -265,7 +304,7 @@ export abstract class WidgetRemoteSource<
|
|
|
265
304
|
yAxisJoinOperation,
|
|
266
305
|
limit: HARD_LIMIT,
|
|
267
306
|
},
|
|
268
|
-
opts: {
|
|
307
|
+
opts: {signal, headers: this.props.headers},
|
|
269
308
|
})
|
|
270
309
|
.then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
|
|
271
310
|
.then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
|
|
@@ -273,15 +312,16 @@ export abstract class WidgetRemoteSource<
|
|
|
273
312
|
|
|
274
313
|
async getTable(options: TableRequestOptions): Promise<TableResponse> {
|
|
275
314
|
const {
|
|
315
|
+
signal,
|
|
316
|
+
filters = this.props.filters,
|
|
276
317
|
filterOwner,
|
|
277
318
|
spatialFilter,
|
|
278
319
|
spatialFiltersMode,
|
|
279
320
|
spatialIndexReferenceViewState,
|
|
280
|
-
abortController,
|
|
281
321
|
...params
|
|
282
322
|
} = options;
|
|
283
323
|
const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
|
|
284
|
-
const source = this.getModelSource(filterOwner);
|
|
324
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
285
325
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
286
326
|
source,
|
|
287
327
|
spatialFilter,
|
|
@@ -308,7 +348,7 @@ export abstract class WidgetRemoteSource<
|
|
|
308
348
|
limit,
|
|
309
349
|
offset,
|
|
310
350
|
},
|
|
311
|
-
opts: {
|
|
351
|
+
opts: {signal, headers: this.props.headers},
|
|
312
352
|
}).then((res: TableModelResponse) => ({
|
|
313
353
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
314
354
|
rows: res.rows ?? (res as any).ROWS,
|
|
@@ -320,8 +360,9 @@ export abstract class WidgetRemoteSource<
|
|
|
320
360
|
options: TimeSeriesRequestOptions
|
|
321
361
|
): Promise<TimeSeriesResponse> {
|
|
322
362
|
const {
|
|
363
|
+
signal,
|
|
364
|
+
filters = this.props.filters,
|
|
323
365
|
filterOwner,
|
|
324
|
-
abortController,
|
|
325
366
|
spatialFilter,
|
|
326
367
|
spatialFiltersMode,
|
|
327
368
|
spatialIndexReferenceViewState,
|
|
@@ -339,7 +380,7 @@ export abstract class WidgetRemoteSource<
|
|
|
339
380
|
splitByCategoryValues,
|
|
340
381
|
} = params;
|
|
341
382
|
|
|
342
|
-
const source = this.getModelSource(filterOwner);
|
|
383
|
+
const source = this.getModelSource(filters, filterOwner);
|
|
343
384
|
const spatialFiltersResolution = this._getSpatialFiltersResolution(
|
|
344
385
|
source,
|
|
345
386
|
spatialFilter,
|
|
@@ -370,7 +411,7 @@ export abstract class WidgetRemoteSource<
|
|
|
370
411
|
splitByCategoryLimit,
|
|
371
412
|
splitByCategoryValues,
|
|
372
413
|
},
|
|
373
|
-
opts: {
|
|
414
|
+
opts: {signal, headers: this.props.headers},
|
|
374
415
|
}).then((res: TimeSeriesModelResponse) => ({
|
|
375
416
|
rows: normalizeObjectKeys(res.rows),
|
|
376
417
|
categories: res.metadata?.categories,
|
|
@@ -18,13 +18,11 @@ import {
|
|
|
18
18
|
ViewState,
|
|
19
19
|
} from './types.js';
|
|
20
20
|
import {FilterLogicalOperator, Filter, SpatialFilter} from '../types.js';
|
|
21
|
-
import {getApplicableFilters} from '../utils.js';
|
|
22
21
|
import {getClient} from '../client.js';
|
|
23
22
|
import {ModelSource} from '../models/model.js';
|
|
24
23
|
import {SourceOptions} from '../sources/index.js';
|
|
25
24
|
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
26
25
|
import {getSpatialFiltersResolution} from '../spatial-index.js';
|
|
27
|
-
import {AggregationOptions} from '../sources/types.js';
|
|
28
26
|
|
|
29
27
|
export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
30
28
|
apiVersion?: ApiVersion;
|
|
@@ -37,7 +35,9 @@ export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
|
37
35
|
*
|
|
38
36
|
* Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
|
|
39
37
|
*/
|
|
40
|
-
export abstract class WidgetSource<
|
|
38
|
+
export abstract class WidgetSource<
|
|
39
|
+
Props extends WidgetSourceProps = WidgetSourceProps,
|
|
40
|
+
> {
|
|
41
41
|
readonly props: Props;
|
|
42
42
|
|
|
43
43
|
static defaultProps: Partial<WidgetSourceProps> = {
|
|
@@ -53,29 +53,14 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* Destroys the widget source and releases allocated resources.
|
|
57
|
+
*
|
|
58
|
+
* For remote sources (tables, queries) this has no effect, but for local
|
|
59
|
+
* sources (tilesets, rasters) these resources will affect performance
|
|
60
|
+
* and stability if many (10+) sources are created and not released.
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
protected _getModelSource(
|
|
64
|
-
owner?: string
|
|
65
|
-
): Omit<ModelSource, 'type' | 'data'> {
|
|
66
|
-
const props = this.props;
|
|
67
|
-
return {
|
|
68
|
-
apiVersion: props.apiVersion as ApiVersion,
|
|
69
|
-
apiBaseUrl: props.apiBaseUrl as string,
|
|
70
|
-
clientId: props.clientId as string,
|
|
71
|
-
accessToken: props.accessToken,
|
|
72
|
-
connectionName: props.connectionName,
|
|
73
|
-
filters: getApplicableFilters(owner, props.filters),
|
|
74
|
-
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
75
|
-
spatialDataType: props.spatialDataType,
|
|
76
|
-
spatialDataColumn: props.spatialDataColumn,
|
|
77
|
-
dataResolution: (props as Partial<AggregationOptions>).dataResolution,
|
|
78
|
-
};
|
|
62
|
+
destroy() {
|
|
63
|
+
// no-op in most cases, but required for worker sources.
|
|
79
64
|
}
|
|
80
65
|
|
|
81
66
|
protected _getSpatialFiltersResolution(
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
WidgetRemoteSourceProps,
|
|
9
9
|
} from './widget-remote-source.js';
|
|
10
10
|
import {ModelSource} from '../models/model.js';
|
|
11
|
+
import {Filters} from '../types.js';
|
|
11
12
|
|
|
12
13
|
type LayerTableSourceOptions =
|
|
13
14
|
| Omit<VectorTableSourceOptions, 'filters'>
|
|
@@ -41,9 +42,12 @@ export type WidgetTableSourceResult = {widgetSource: WidgetTableSource};
|
|
|
41
42
|
export class WidgetTableSource extends WidgetRemoteSource<
|
|
42
43
|
LayerTableSourceOptions & WidgetRemoteSourceProps
|
|
43
44
|
> {
|
|
44
|
-
protected override getModelSource(
|
|
45
|
+
protected override getModelSource(
|
|
46
|
+
filters: Filters | undefined,
|
|
47
|
+
filterOwner?: string
|
|
48
|
+
): ModelSource {
|
|
45
49
|
return {
|
|
46
|
-
...super._getModelSource(
|
|
50
|
+
...super._getModelSource(filters, filterOwner),
|
|
47
51
|
type: 'table',
|
|
48
52
|
data: this.props.tableName,
|
|
49
53
|
};
|