@carto/api-client 0.5.1 → 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/build/api-client.cjs +79 -77
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +9 -1
- package/build/api-client.d.ts +9 -1
- package/build/api-client.js +77 -76
- package/build/api-client.js.map +1 -1
- package/build/worker.js +35 -33
- package/build/worker.js.map +1 -1
- package/package.json +3 -2
- package/src/filters.ts +37 -2
- package/src/utils.ts +0 -35
- package/src/widget-sources/widget-remote-source.ts +2 -1
- package/src/widget-sources/widget-tileset-source-impl.ts +2 -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"
|
|
@@ -127,5 +127,6 @@
|
|
|
127
127
|
"resolutions": {
|
|
128
128
|
"@carto/api-client": "portal:./",
|
|
129
129
|
"rollup": "^4.20.0"
|
|
130
|
-
}
|
|
130
|
+
},
|
|
131
|
+
"stableVersion": "0.5.1"
|
|
131
132
|
}
|
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/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
|
/**
|
|
@@ -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
|