@carto/api-client 0.5.1-alpha.2 → 0.5.2-alpha.0
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 +7 -2
- package/build/api-client.cjs +101 -106
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +46 -15
- package/build/api-client.d.ts +46 -15
- package/build/api-client.js +95 -105
- package/build/api-client.js.map +1 -1
- package/build/worker.js +38 -33
- package/build/worker.js.map +1 -1
- package/package.json +3 -3
- package/src/fetch-map/fetch-map.ts +1 -7
- package/src/fetch-map/parse-map.ts +2 -1
- package/src/fetch-map/source.ts +12 -3
- package/src/fetch-map/types.ts +3 -2
- package/src/filters.ts +37 -2
- package/src/index.ts +1 -0
- package/src/sources/base-source.ts +8 -22
- package/src/sources/boundary-query-source.ts +1 -5
- package/src/sources/boundary-table-source.ts +1 -5
- package/src/sources/h3-query-source.ts +1 -1
- package/src/sources/h3-table-source.ts +1 -1
- package/src/sources/h3-tileset-source.ts +2 -2
- package/src/sources/index.ts +18 -10
- package/src/sources/quadbin-query-source.ts +1 -1
- package/src/sources/quadbin-table-source.ts +1 -1
- package/src/sources/quadbin-tileset-source.ts +2 -2
- package/src/sources/raster-source.ts +3 -3
- package/src/sources/types.ts +6 -8
- package/src/sources/vector-query-source.ts +1 -1
- package/src/sources/vector-table-source.ts +1 -1
- package/src/sources/vector-tileset-source.ts +2 -2
- package/src/types-internal.ts +0 -24
- package/src/utils.ts +0 -35
- package/src/widget-sources/types.ts +2 -2
- package/src/widget-sources/widget-remote-source.ts +2 -1
- package/src/widget-sources/widget-tileset-source-impl.ts +6 -6
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
9
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
10
10
|
"packageManager": "yarn@4.3.1",
|
|
11
|
-
"version": "0.5.
|
|
11
|
+
"version": "0.5.2-alpha.0",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup",
|
|
41
41
|
"build:watch": "tsup --watch",
|
|
42
|
-
"dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
|
|
42
|
+
"dev": "yarn build && concurrently --names tsup,vite \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
|
|
43
43
|
"test": "vitest run --typecheck",
|
|
44
44
|
"test:watch": "vitest watch --typecheck",
|
|
45
45
|
"coverage": "vitest run --coverage.enabled --coverage.all false",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
"@carto/api-client": "portal:./",
|
|
129
129
|
"rollup": "^4.20.0"
|
|
130
130
|
},
|
|
131
|
-
"stableVersion": "0.5.
|
|
131
|
+
"stableVersion": "0.5.1"
|
|
132
132
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import {TilejsonResult} from '../sources/index.js';
|
|
2
|
-
|
|
3
1
|
import {DEFAULT_API_BASE_URL} from '../constants.js';
|
|
4
2
|
|
|
5
3
|
import {
|
|
@@ -119,11 +117,7 @@ async function fillInTileStats(
|
|
|
119
117
|
const attribute = layer.visualChannels[channel]?.name;
|
|
120
118
|
if (attribute) {
|
|
121
119
|
const dataset = datasets.find((d) => d.id === layer.config.dataId);
|
|
122
|
-
if (
|
|
123
|
-
dataset &&
|
|
124
|
-
dataset.type !== 'tileset' &&
|
|
125
|
-
(dataset.data as TilejsonResult).tilestats
|
|
126
|
-
) {
|
|
120
|
+
if (dataset && dataset.type !== 'tileset' && dataset.data.tilestats) {
|
|
127
121
|
// Only fetch stats for QUERY & TABLE map types
|
|
128
122
|
attributes.push({attribute, dataset});
|
|
129
123
|
}
|
|
@@ -57,7 +57,7 @@ export function parseMap(json: any) {
|
|
|
57
57
|
const {keplerMapConfig, datasets, token} = json;
|
|
58
58
|
assert(keplerMapConfig.version === 'v1', 'Only support Kepler v1');
|
|
59
59
|
const config = keplerMapConfig.config as KeplerMapConfig;
|
|
60
|
-
const {filters, mapState, mapStyle, popupSettings} = config;
|
|
60
|
+
const {filters, mapState, mapStyle, popupSettings, legendSettings} = config;
|
|
61
61
|
const {layers, layerBlending, interactionConfig} = config.visState;
|
|
62
62
|
|
|
63
63
|
return {
|
|
@@ -70,6 +70,7 @@ export function parseMap(json: any) {
|
|
|
70
70
|
/** @deprecated Use `basemap`. */
|
|
71
71
|
mapStyle,
|
|
72
72
|
popupSettings,
|
|
73
|
+
legendSettings,
|
|
73
74
|
token,
|
|
74
75
|
layers: layers
|
|
75
76
|
.reverse()
|
package/src/fetch-map/source.ts
CHANGED
|
@@ -201,11 +201,12 @@ function getDynamicTileResolution(
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
|
+
* @internal
|
|
204
205
|
* State of `aggregationResLevel` in the UI and backend config is based on an assumption of
|
|
205
206
|
* 512x512px tiles. Because we may change tile resolution for performance goals, the
|
|
206
207
|
* `aggregationResLevel` passed to the deck.gl layer must be scaled with tile resolution.
|
|
207
208
|
*/
|
|
208
|
-
function scaleAggregationResLevel(
|
|
209
|
+
export function scaleAggregationResLevel(
|
|
209
210
|
aggregationResLevel: number,
|
|
210
211
|
tileResolution: number
|
|
211
212
|
): number | undefined {
|
|
@@ -213,7 +214,12 @@ function scaleAggregationResLevel(
|
|
|
213
214
|
return aggregationResLevel - Math.log2(0.5 / tileResolution);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
|
-
|
|
217
|
+
/**
|
|
218
|
+
* @internal
|
|
219
|
+
*/
|
|
220
|
+
export function getColumnNameFromGeoColumn(
|
|
221
|
+
geoColumn: string | null | undefined
|
|
222
|
+
) {
|
|
217
223
|
if (!geoColumn) {
|
|
218
224
|
return geoColumn;
|
|
219
225
|
}
|
|
@@ -221,7 +227,10 @@ function getColumnNameFromGeoColumn(geoColumn: string | null | undefined) {
|
|
|
221
227
|
return parts.length === 1 ? parts[0] : parts.length === 2 ? parts[1] : null;
|
|
222
228
|
}
|
|
223
229
|
|
|
224
|
-
|
|
230
|
+
/**
|
|
231
|
+
* @internal
|
|
232
|
+
*/
|
|
233
|
+
export function getSpatialIndexFromGeoColumn(geoColumn: string) {
|
|
225
234
|
const spatialIndexToSearch = geoColumn.split(':')[0];
|
|
226
235
|
|
|
227
236
|
for (const index of Object.values(SpatialIndex)) {
|
package/src/fetch-map/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {LayerType, SCALE_TYPE} from './layer-map.js';
|
|
2
2
|
import {Format, MapType, ProviderType, QueryParameters} from '../types.js';
|
|
3
|
-
import {TilejsonResult
|
|
3
|
+
import {TilejsonResult} from '../sources/types.js';
|
|
4
4
|
|
|
5
5
|
export type VisualChannelField = {
|
|
6
6
|
name: string;
|
|
@@ -117,6 +117,7 @@ export type KeplerMapConfig = {
|
|
|
117
117
|
styleType: string;
|
|
118
118
|
visibleLayerGroups: Record<string, boolean>;
|
|
119
119
|
};
|
|
120
|
+
legendSettings?: any;
|
|
120
121
|
popupSettings: any;
|
|
121
122
|
visState: {
|
|
122
123
|
layers: MapConfigLayer[];
|
|
@@ -208,7 +209,7 @@ export type Dataset = {
|
|
|
208
209
|
cache?: number;
|
|
209
210
|
connectionName: string;
|
|
210
211
|
geoColumn: string;
|
|
211
|
-
data: TilejsonResult
|
|
212
|
+
data: TilejsonResult;
|
|
212
213
|
columns: string[];
|
|
213
214
|
format: Format;
|
|
214
215
|
aggregationExp: string;
|
package/src/filters.ts
CHANGED
|
@@ -2,6 +2,10 @@ import {FilterType} from './constants.js';
|
|
|
2
2
|
import {Filter} from './types.js';
|
|
3
3
|
import {isEmptyObject} from './utils.js';
|
|
4
4
|
|
|
5
|
+
const FILTER_TYPES = new Set(Object.values(FilterType));
|
|
6
|
+
const isFilterType = (type: string): type is FilterType =>
|
|
7
|
+
FILTER_TYPES.has(type as FilterType);
|
|
8
|
+
|
|
5
9
|
type FilterTypeOptions<T extends FilterType> = {
|
|
6
10
|
type: T;
|
|
7
11
|
column: string;
|
|
@@ -53,7 +57,7 @@ export function removeFilter(
|
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
if (owner) {
|
|
56
|
-
for (const type of
|
|
60
|
+
for (const type of FILTER_TYPES) {
|
|
57
61
|
if (owner === filter[type as FilterType]?.owner) {
|
|
58
62
|
delete filter[type as FilterType];
|
|
59
63
|
}
|
|
@@ -97,7 +101,7 @@ export function hasFilter(
|
|
|
97
101
|
return true;
|
|
98
102
|
}
|
|
99
103
|
|
|
100
|
-
for (const type of
|
|
104
|
+
for (const type of FILTER_TYPES) {
|
|
101
105
|
if (owner === filter[type as FilterType]?.owner) {
|
|
102
106
|
return true;
|
|
103
107
|
}
|
|
@@ -127,3 +131,34 @@ export function getFilter<T extends FilterType>(
|
|
|
127
131
|
|
|
128
132
|
return null;
|
|
129
133
|
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Given all filters for a dataset, returns the subset of filters that are not
|
|
137
|
+
* attributable to the given owner. Typically used to allow filterable widgets
|
|
138
|
+
* to affect other widgets *without* filtering themselves.
|
|
139
|
+
*
|
|
140
|
+
* @privateRemarks Source: @carto/react-widgets
|
|
141
|
+
*/
|
|
142
|
+
export function getApplicableFilters(
|
|
143
|
+
owner?: string,
|
|
144
|
+
filters?: Record<string, Filter>
|
|
145
|
+
): Record<string, Filter> {
|
|
146
|
+
if (!filters) return {};
|
|
147
|
+
|
|
148
|
+
const applicableFilters: Record<string, Filter> = {};
|
|
149
|
+
|
|
150
|
+
for (const column in filters) {
|
|
151
|
+
for (const type in filters[column]) {
|
|
152
|
+
if (!isFilterType(type)) continue;
|
|
153
|
+
|
|
154
|
+
const filter = filters[column][type];
|
|
155
|
+
const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
|
|
156
|
+
if (filter && isApplicable) {
|
|
157
|
+
applicableFilters[column] ||= {};
|
|
158
|
+
(applicableFilters[column][type] as typeof filter) = filter;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return applicableFilters;
|
|
164
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,8 +7,6 @@ import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal.js';
|
|
|
7
7
|
import {buildSourceUrl} from '../api/endpoints.js';
|
|
8
8
|
import {requestWithParameters} from '../api/request-with-parameters.js';
|
|
9
9
|
import type {
|
|
10
|
-
GeojsonResult,
|
|
11
|
-
JsonResult,
|
|
12
10
|
SourceOptionalOptions,
|
|
13
11
|
SourceRequiredOptions,
|
|
14
12
|
TilejsonMapInstantiation,
|
|
@@ -20,7 +18,6 @@ import {getClient} from '../client.js';
|
|
|
20
18
|
|
|
21
19
|
export const SOURCE_DEFAULTS: Omit<SourceOptionalOptions, 'clientId'> = {
|
|
22
20
|
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
23
|
-
format: 'tilejson',
|
|
24
21
|
headers: {},
|
|
25
22
|
maxLengthURL: DEFAULT_MAX_LENGTH_URL,
|
|
26
23
|
};
|
|
@@ -29,7 +26,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
29
26
|
endpoint: MapType,
|
|
30
27
|
options: Partial<SourceOptionalOptions> & SourceRequiredOptions,
|
|
31
28
|
urlParameters: UrlParameters
|
|
32
|
-
): Promise<TilejsonResult
|
|
29
|
+
): Promise<TilejsonResult> {
|
|
33
30
|
const {accessToken, connectionName, cache, ...optionalOptions} = options;
|
|
34
31
|
const mergedOptions = {
|
|
35
32
|
...SOURCE_DEFAULTS,
|
|
@@ -45,7 +42,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
const baseUrl = buildSourceUrl(mergedOptions);
|
|
48
|
-
const {clientId, maxLengthURL,
|
|
45
|
+
const {clientId, maxLengthURL, localCache} = mergedOptions;
|
|
49
46
|
const headers = {
|
|
50
47
|
Authorization: `Bearer ${options.accessToken}`,
|
|
51
48
|
...options.headers,
|
|
@@ -68,7 +65,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
68
65
|
localCache,
|
|
69
66
|
});
|
|
70
67
|
|
|
71
|
-
const dataUrl = mapInstantiation
|
|
68
|
+
const dataUrl = mapInstantiation.tilejson.url[0];
|
|
72
69
|
if (cache) {
|
|
73
70
|
cache.value = parseInt(
|
|
74
71
|
new URL(dataUrl).searchParams.get('cache') || '',
|
|
@@ -77,22 +74,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
77
74
|
}
|
|
78
75
|
errorContext.requestType = 'Map data';
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
const json = await requestWithParameters<TilejsonResult>({
|
|
82
|
-
baseUrl: dataUrl,
|
|
83
|
-
parameters: {client: clientId},
|
|
84
|
-
headers,
|
|
85
|
-
errorContext,
|
|
86
|
-
maxLengthURL,
|
|
87
|
-
localCache,
|
|
88
|
-
});
|
|
89
|
-
if (accessToken) {
|
|
90
|
-
json.accessToken = accessToken;
|
|
91
|
-
}
|
|
92
|
-
return json;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return await requestWithParameters<GeojsonResult | JsonResult>({
|
|
77
|
+
const json = await requestWithParameters<TilejsonResult>({
|
|
96
78
|
baseUrl: dataUrl,
|
|
97
79
|
parameters: {client: clientId},
|
|
98
80
|
headers,
|
|
@@ -100,4 +82,8 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
100
82
|
maxLengthURL,
|
|
101
83
|
localCache,
|
|
102
84
|
});
|
|
85
|
+
if (accessToken) {
|
|
86
|
+
json.accessToken = accessToken;
|
|
87
|
+
}
|
|
88
|
+
return json;
|
|
103
89
|
}
|
|
@@ -48,9 +48,5 @@ export const boundaryQuerySource = async function (
|
|
|
48
48
|
urlParameters.queryParameters = queryParameters;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
return baseSource<UrlParameters>(
|
|
52
|
-
'boundary',
|
|
53
|
-
options,
|
|
54
|
-
urlParameters
|
|
55
|
-
) as Promise<BoundaryQuerySourceResponse>;
|
|
51
|
+
return baseSource<UrlParameters>('boundary', options, urlParameters);
|
|
56
52
|
};
|
|
@@ -36,9 +36,5 @@ export const boundaryTableSource = async function (
|
|
|
36
36
|
urlParameters.filters = filters;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
return baseSource<UrlParameters>(
|
|
40
|
-
'boundary',
|
|
41
|
-
options,
|
|
42
|
-
urlParameters
|
|
43
|
-
) as Promise<BoundaryTableSourceResponse>;
|
|
39
|
+
return baseSource<UrlParameters>('boundary', options, urlParameters);
|
|
44
40
|
};
|
|
@@ -67,7 +67,7 @@ export const h3QuerySource = async function (
|
|
|
67
67
|
|
|
68
68
|
return baseSource<UrlParameters>('query', options, urlParameters).then(
|
|
69
69
|
(result) => ({
|
|
70
|
-
...
|
|
70
|
+
...result,
|
|
71
71
|
widgetSource: new WidgetQuerySource({
|
|
72
72
|
...options,
|
|
73
73
|
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
@@ -62,7 +62,7 @@ export const h3TableSource = async function (
|
|
|
62
62
|
|
|
63
63
|
return baseSource<UrlParameters>('table', options, urlParameters).then(
|
|
64
64
|
(result) => ({
|
|
65
|
-
...
|
|
65
|
+
...result,
|
|
66
66
|
widgetSource: new WidgetTableSource({
|
|
67
67
|
...options,
|
|
68
68
|
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
@@ -28,10 +28,10 @@ export const h3TilesetSource = async function (
|
|
|
28
28
|
|
|
29
29
|
return baseSource<UrlParameters>('tileset', options, urlParameters).then(
|
|
30
30
|
(result) => ({
|
|
31
|
-
...
|
|
31
|
+
...result,
|
|
32
32
|
widgetSource: new WidgetTilesetSource({
|
|
33
33
|
...options,
|
|
34
|
-
tileFormat: getTileFormat(result
|
|
34
|
+
tileFormat: getTileFormat(result),
|
|
35
35
|
spatialDataColumn,
|
|
36
36
|
spatialDataType: 'h3',
|
|
37
37
|
}),
|
package/src/sources/index.ts
CHANGED
|
@@ -4,21 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
export {SOURCE_DEFAULTS} from './base-source.js';
|
|
6
6
|
export type {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
SourceOptions,
|
|
8
|
+
SourceRequiredOptions,
|
|
9
|
+
SourceOptionalOptions,
|
|
10
|
+
TilejsonResult,
|
|
9
11
|
QueryResult,
|
|
12
|
+
FilterOptions,
|
|
10
13
|
QuerySourceOptions,
|
|
11
|
-
RasterBandColorinterp,
|
|
12
|
-
RasterMetadata,
|
|
13
|
-
RasterMetadataBand,
|
|
14
|
-
RasterMetadataBandStats,
|
|
15
|
-
SourceOptions,
|
|
16
|
-
SpatialFilterPolyfillMode,
|
|
17
14
|
TableSourceOptions,
|
|
18
|
-
TilejsonResult,
|
|
19
|
-
TileResolution,
|
|
20
15
|
TilesetSourceOptions,
|
|
16
|
+
ColumnsOption,
|
|
17
|
+
SpatialDataType,
|
|
18
|
+
SpatialFilterPolyfillMode,
|
|
19
|
+
TileResolution,
|
|
20
|
+
Tilejson,
|
|
21
|
+
Tilestats,
|
|
22
|
+
Layer,
|
|
23
|
+
Attribute,
|
|
21
24
|
VectorLayer,
|
|
25
|
+
RasterMetadata,
|
|
26
|
+
RasterMetadataBand,
|
|
27
|
+
RasterMetadataBandStats,
|
|
28
|
+
RasterBandType,
|
|
29
|
+
RasterBandColorinterp,
|
|
22
30
|
} from './types.js';
|
|
23
31
|
|
|
24
32
|
export {boundaryQuerySource} from './boundary-query-source.js';
|
|
@@ -68,7 +68,7 @@ export const quadbinQuerySource = async function (
|
|
|
68
68
|
|
|
69
69
|
return baseSource<UrlParameters>('query', options, urlParameters).then(
|
|
70
70
|
(result) => ({
|
|
71
|
-
...
|
|
71
|
+
...result,
|
|
72
72
|
widgetSource: new WidgetQuerySource({
|
|
73
73
|
...options,
|
|
74
74
|
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
@@ -63,7 +63,7 @@ export const quadbinTableSource = async function (
|
|
|
63
63
|
|
|
64
64
|
return baseSource<UrlParameters>('table', options, urlParameters).then(
|
|
65
65
|
(result) => ({
|
|
66
|
-
...
|
|
66
|
+
...result,
|
|
67
67
|
widgetSource: new WidgetTableSource({
|
|
68
68
|
...options,
|
|
69
69
|
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
@@ -28,10 +28,10 @@ export const quadbinTilesetSource = async function (
|
|
|
28
28
|
|
|
29
29
|
return baseSource<UrlParameters>('tileset', options, urlParameters).then(
|
|
30
30
|
(result) => ({
|
|
31
|
-
...
|
|
31
|
+
...result,
|
|
32
32
|
widgetSource: new WidgetTilesetSource({
|
|
33
33
|
...options,
|
|
34
|
-
tileFormat: getTileFormat(result
|
|
34
|
+
tileFormat: getTileFormat(result),
|
|
35
35
|
spatialDataColumn,
|
|
36
36
|
spatialDataType: 'quadbin',
|
|
37
37
|
}),
|
|
@@ -37,13 +37,13 @@ export const rasterSource = async function (
|
|
|
37
37
|
|
|
38
38
|
return baseSource<UrlParameters>('raster', options, urlParameters).then(
|
|
39
39
|
(result) => ({
|
|
40
|
-
...
|
|
40
|
+
...result,
|
|
41
41
|
widgetSource: new WidgetRasterSource({
|
|
42
42
|
...options,
|
|
43
|
-
tileFormat: getTileFormat(result
|
|
43
|
+
tileFormat: getTileFormat(result),
|
|
44
44
|
spatialDataColumn: 'quadbin',
|
|
45
45
|
spatialDataType: 'quadbin',
|
|
46
|
-
rasterMetadata:
|
|
46
|
+
rasterMetadata: result.raster_metadata!,
|
|
47
47
|
}),
|
|
48
48
|
})
|
|
49
49
|
) as Promise<RasterSourceResponse>;
|
package/src/sources/types.ts
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {MapInstantiation} from '../types-internal.js';
|
|
5
|
+
import {Filters, QueryParameters} from '../types.js';
|
|
6
|
+
import {SchemaField} from '../types-internal.js';
|
|
8
7
|
|
|
9
8
|
export type SourceRequiredOptions = {
|
|
10
9
|
/** Carto platform access token. */
|
|
@@ -38,8 +37,6 @@ export type SourceOptionalOptions = {
|
|
|
38
37
|
cache?: {value?: number};
|
|
39
38
|
|
|
40
39
|
clientId: string;
|
|
41
|
-
/** @deprecated use `query` instead **/
|
|
42
|
-
format: Format;
|
|
43
40
|
|
|
44
41
|
/**
|
|
45
42
|
* Maximum URL character length. Above this limit, requests use POST.
|
|
@@ -213,7 +210,10 @@ export type SpatialDataType = 'geo' | 'h3' | 'quadbin';
|
|
|
213
210
|
* */
|
|
214
211
|
export type SpatialFilterPolyfillMode = 'center' | 'intersects' | 'contains';
|
|
215
212
|
|
|
216
|
-
export type TilejsonMapInstantiation =
|
|
213
|
+
export type TilejsonMapInstantiation = {
|
|
214
|
+
nrows: number;
|
|
215
|
+
size?: number;
|
|
216
|
+
schema: SchemaField[];
|
|
217
217
|
tilejson: {url: string[]};
|
|
218
218
|
};
|
|
219
219
|
|
|
@@ -415,8 +415,6 @@ export type RasterMetadata = {
|
|
|
415
415
|
};
|
|
416
416
|
|
|
417
417
|
export type TilejsonResult = Tilejson & {accessToken: string};
|
|
418
|
-
export type GeojsonResult = {type: 'FeatureCollection'; features: Feature[]};
|
|
419
|
-
export type JsonResult = any[];
|
|
420
418
|
export type QueryResult = {
|
|
421
419
|
meta: {cacheHit: boolean; location: string; totalBytesProcessed: string};
|
|
422
420
|
rows: Record<string, any>[];
|
|
@@ -76,7 +76,7 @@ export const vectorQuerySource = async function (
|
|
|
76
76
|
|
|
77
77
|
return baseSource<UrlParameters>('query', options, urlParameters).then(
|
|
78
78
|
(result) => ({
|
|
79
|
-
...
|
|
79
|
+
...result,
|
|
80
80
|
widgetSource: new WidgetQuerySource({
|
|
81
81
|
...options,
|
|
82
82
|
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
@@ -71,7 +71,7 @@ export const vectorTableSource = async function (
|
|
|
71
71
|
|
|
72
72
|
return baseSource<UrlParameters>('table', options, urlParameters).then(
|
|
73
73
|
(result) => ({
|
|
74
|
-
...
|
|
74
|
+
...result,
|
|
75
75
|
widgetSource: new WidgetTableSource({
|
|
76
76
|
...options,
|
|
77
77
|
// NOTE: Parameters with default values above must be explicitly passed here.
|
|
@@ -29,10 +29,10 @@ export const vectorTilesetSource = async function (
|
|
|
29
29
|
|
|
30
30
|
return baseSource<UrlParameters>('tileset', options, urlParameters).then(
|
|
31
31
|
(result) => ({
|
|
32
|
-
...
|
|
32
|
+
...result,
|
|
33
33
|
widgetSource: new WidgetTilesetSource({
|
|
34
34
|
...options,
|
|
35
|
-
tileFormat: getTileFormat(result
|
|
35
|
+
tileFormat: getTileFormat(result),
|
|
36
36
|
spatialDataColumn,
|
|
37
37
|
spatialDataType: 'geo',
|
|
38
38
|
}),
|
package/src/types-internal.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* COMMON
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {Format} from './types.js';
|
|
6
|
-
|
|
7
5
|
/** @internal */
|
|
8
6
|
export type $TODO = any;
|
|
9
7
|
|
|
@@ -39,28 +37,6 @@ export interface SchemaField {
|
|
|
39
37
|
type: SchemaFieldType; // Field type in the CARTO stack, common for all providers
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
/**
|
|
43
|
-
* @privateRemarks Source: @deck.gl/carto
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
export interface MapInstantiation extends MapInstantiationFormats {
|
|
47
|
-
nrows: number;
|
|
48
|
-
size?: number;
|
|
49
|
-
schema: SchemaField[];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @privateRemarks Source: @deck.gl/carto
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
56
|
-
type MapInstantiationFormats = Record<
|
|
57
|
-
Format,
|
|
58
|
-
{
|
|
59
|
-
url: string[];
|
|
60
|
-
error?: any;
|
|
61
|
-
}
|
|
62
|
-
>;
|
|
63
|
-
|
|
64
40
|
/******************************************************************************
|
|
65
41
|
* LOCAL CALCULATIONS
|
|
66
42
|
*/
|
package/src/utils.ts
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
import {Filter} from './types.js';
|
|
2
|
-
import {FilterType} from './constants.js';
|
|
3
|
-
|
|
4
|
-
const FILTER_TYPES = new Set(Object.values(FilterType));
|
|
5
|
-
const isFilterType = (type: string): type is FilterType =>
|
|
6
|
-
FILTER_TYPES.has(type as FilterType);
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @privateRemarks Source: @carto/react-widgets
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export function getApplicableFilters(
|
|
13
|
-
owner?: string,
|
|
14
|
-
filters?: Record<string, Filter>
|
|
15
|
-
): Record<string, Filter> {
|
|
16
|
-
if (!filters) return {};
|
|
17
|
-
|
|
18
|
-
const applicableFilters: Record<string, Filter> = {};
|
|
19
|
-
|
|
20
|
-
for (const column in filters) {
|
|
21
|
-
for (const type in filters[column]) {
|
|
22
|
-
if (!isFilterType(type)) continue;
|
|
23
|
-
|
|
24
|
-
const filter = filters[column][type];
|
|
25
|
-
const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
|
|
26
|
-
if (filter && isApplicable) {
|
|
27
|
-
applicableFilters[column] ||= {};
|
|
28
|
-
(applicableFilters[column][type] as typeof filter) = filter;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return applicableFilters;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
1
|
type Row<T> = Record<string, T> | Record<string, T>[] | T[] | T;
|
|
37
2
|
|
|
38
3
|
/**
|
|
@@ -117,9 +117,9 @@ export interface TableRequestOptions extends BaseRequestOptions {
|
|
|
117
117
|
sortByColumnType?: SortColumnType;
|
|
118
118
|
offset?: number;
|
|
119
119
|
limit?: number;
|
|
120
|
-
/**
|
|
120
|
+
/** @deprecated Supported for tilesets only. Prefer `filters` (for all sources) instead. */
|
|
121
121
|
searchFilterColumn?: string;
|
|
122
|
-
/**
|
|
122
|
+
/** @deprecated Supported for tilesets only. Prefer `filters` (for all sources) instead. */
|
|
123
123
|
searchFilterText?: string;
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -17,11 +17,12 @@ import {
|
|
|
17
17
|
TimeSeriesRequestOptions,
|
|
18
18
|
TimeSeriesResponse,
|
|
19
19
|
} from './types.js';
|
|
20
|
-
import {
|
|
20
|
+
import {normalizeObjectKeys} from '../utils.js';
|
|
21
21
|
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
22
22
|
import {WidgetSource, WidgetSourceProps} from './widget-source.js';
|
|
23
23
|
import {Filters} from '../types.js';
|
|
24
24
|
import {ApiVersion} from '../constants.js';
|
|
25
|
+
import {getApplicableFilters} from '../filters.js';
|
|
25
26
|
|
|
26
27
|
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
27
28
|
|
|
@@ -16,12 +16,7 @@ import {
|
|
|
16
16
|
TimeSeriesRequestOptions,
|
|
17
17
|
TimeSeriesResponse,
|
|
18
18
|
} from './types.js';
|
|
19
|
-
import {
|
|
20
|
-
InvalidColumnError,
|
|
21
|
-
assert,
|
|
22
|
-
assignOptional,
|
|
23
|
-
getApplicableFilters,
|
|
24
|
-
} from '../utils.js';
|
|
19
|
+
import {InvalidColumnError, assert, assignOptional} from '../utils.js';
|
|
25
20
|
import {Filter, SpatialFilter, Tile} from '../types.js';
|
|
26
21
|
import {
|
|
27
22
|
TileFeatureExtractOptions,
|
|
@@ -42,6 +37,7 @@ import {FeatureCollection} from 'geojson';
|
|
|
42
37
|
import {WidgetSource} from './widget-source.js';
|
|
43
38
|
import {booleanEqual} from '@turf/boolean-equal';
|
|
44
39
|
import type {WidgetTilesetSourceProps} from './widget-tileset-source.js';
|
|
40
|
+
import {getApplicableFilters} from '../filters.js';
|
|
45
41
|
|
|
46
42
|
// TODO(cleanup): Parameter defaults in source functions and widget API calls are
|
|
47
43
|
// currently duplicated and possibly inconsistent. Consider consolidating and
|
|
@@ -271,7 +267,11 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
|
|
|
271
267
|
}
|
|
272
268
|
|
|
273
269
|
// Search.
|
|
270
|
+
// TODO(v0.6): Remove "searchFilterText" and "searchFilterColumn".
|
|
274
271
|
if (searchFilterColumn && searchFilterText) {
|
|
272
|
+
console.warn(
|
|
273
|
+
'WidgetTilesetSource: "searchFilterText" is deprecated, use "filters" and FilterType.STRING_SEARCH instead.'
|
|
274
|
+
);
|
|
275
275
|
filteredFeatures = filteredFeatures.filter(
|
|
276
276
|
(row) =>
|
|
277
277
|
row[searchFilterColumn] &&
|