@carto/api-client 0.5.6-alpha.bundle.4 → 0.5.7-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/build/api-client.cjs +29 -18
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +15 -2
- package/build/api-client.d.ts +15 -2
- package/build/api-client.js +28 -18
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +14 -6
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +14 -6
- package/build/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +12 -0
- package/src/fetch-map/layer-map.ts +2 -1
- package/src/types.ts +1 -1
- package/src/widget-sources/types.ts +2 -0
- package/src/widget-sources/widget-remote-source.ts +7 -6
- package/src/widget-sources/widget-tileset-source-impl.ts +7 -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.7-alpha.1",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
package/src/constants.ts
CHANGED
|
@@ -60,3 +60,15 @@ export const SpatialIndexColumn = Object.freeze({
|
|
|
60
60
|
[SpatialIndex.H3]: ['h3', 'hex', 'h3id', 'hex_id', 'h3hex'],
|
|
61
61
|
[SpatialIndex.QUADBIN]: ['quadbin'],
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Enum like container for all types of aggregations available for widgets.
|
|
66
|
+
*/
|
|
67
|
+
export const AggregationTypes = {
|
|
68
|
+
Count: 'count' as const,
|
|
69
|
+
Avg: 'avg' as const,
|
|
70
|
+
Min: 'min' as const,
|
|
71
|
+
Max: 'max' as const,
|
|
72
|
+
Sum: 'sum' as const,
|
|
73
|
+
Custom: 'custom' as const,
|
|
74
|
+
} as const;
|
|
@@ -37,6 +37,7 @@ import type {
|
|
|
37
37
|
} from './types.js';
|
|
38
38
|
import type {ProviderType, SchemaField} from '../types.js';
|
|
39
39
|
import {DEFAULT_AGGREGATION_EXP_ALIAS} from '../constants-internal.js';
|
|
40
|
+
import {AggregationTypes} from '../constants.js';
|
|
40
41
|
|
|
41
42
|
export type D3Scale = {
|
|
42
43
|
domain: (d?: any) => any[];
|
|
@@ -431,7 +432,7 @@ export function getSizeAccessor(
|
|
|
431
432
|
): {accessor: any; scale: any} {
|
|
432
433
|
const scale = scaleType ? SCALE_FUNCS[scaleType]() : identity;
|
|
433
434
|
if (scaleType) {
|
|
434
|
-
if (aggregation !==
|
|
435
|
+
if (aggregation !== AggregationTypes.Count) {
|
|
435
436
|
(scale as D3Scale).domain(calculateDomain(data, name, scaleType));
|
|
436
437
|
}
|
|
437
438
|
(scale as D3Scale).range(range);
|
package/src/types.ts
CHANGED
|
@@ -95,7 +95,7 @@ export type Raster = {
|
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Enum for the different types of aggregations available for widgets.
|
|
98
|
+
* Enum type for the different types of aggregations available for widgets.
|
|
99
99
|
*
|
|
100
100
|
* @privateRemarks Source: @carto/constants
|
|
101
101
|
* @privateRemarks Converted from enum to type union, for improved declarative API.
|
|
@@ -59,6 +59,8 @@ export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
|
59
59
|
operationColumn?: string;
|
|
60
60
|
/** Local only. */
|
|
61
61
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
62
|
+
/** Maximum number of items to return. Backend calculates also __carto_others category. Remote only. */
|
|
63
|
+
maxItems?: number;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
/**
|
|
@@ -21,7 +21,7 @@ import {assert, normalizeObjectKeys} from '../utils.js';
|
|
|
21
21
|
import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
|
|
22
22
|
import {WidgetSource, type WidgetSourceProps} from './widget-source.js';
|
|
23
23
|
import type {Filters} from '../types.js';
|
|
24
|
-
import {ApiVersion} from '../constants.js';
|
|
24
|
+
import {AggregationTypes, ApiVersion} from '../constants.js';
|
|
25
25
|
import {getApplicableFilters} from '../filters.js';
|
|
26
26
|
|
|
27
27
|
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
@@ -74,9 +74,9 @@ export abstract class WidgetRemoteSource<
|
|
|
74
74
|
spatialFiltersMode,
|
|
75
75
|
...params
|
|
76
76
|
} = options;
|
|
77
|
-
const {column, operation, operationColumn, operationExp} = params;
|
|
77
|
+
const {column, operation, operationColumn, operationExp, maxItems} = params;
|
|
78
78
|
|
|
79
|
-
if (operation ===
|
|
79
|
+
if (operation === AggregationTypes.Custom) {
|
|
80
80
|
assert(operationExp, 'operationExp is required for custom operation');
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -94,6 +94,7 @@ export abstract class WidgetRemoteSource<
|
|
|
94
94
|
operation,
|
|
95
95
|
operationExp,
|
|
96
96
|
operationColumn: operationColumn || column,
|
|
97
|
+
maxItems,
|
|
97
98
|
},
|
|
98
99
|
opts: {signal, headers: this.props.headers},
|
|
99
100
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
@@ -148,7 +149,7 @@ export abstract class WidgetRemoteSource<
|
|
|
148
149
|
|
|
149
150
|
type FormulaModelResponse = {rows: {value: number}[]};
|
|
150
151
|
|
|
151
|
-
if (operation ===
|
|
152
|
+
if (operation === AggregationTypes.Custom) {
|
|
152
153
|
assert(operationExp, 'operationExp is required for custom operation');
|
|
153
154
|
}
|
|
154
155
|
|
|
@@ -161,7 +162,7 @@ export abstract class WidgetRemoteSource<
|
|
|
161
162
|
},
|
|
162
163
|
params: {
|
|
163
164
|
column: column ?? '*',
|
|
164
|
-
operation: operation ??
|
|
165
|
+
operation: operation ?? AggregationTypes.Count,
|
|
165
166
|
operationExp,
|
|
166
167
|
},
|
|
167
168
|
opts: {signal, headers: this.props.headers},
|
|
@@ -331,7 +332,7 @@ export abstract class WidgetRemoteSource<
|
|
|
331
332
|
splitByCategoryValues,
|
|
332
333
|
} = params;
|
|
333
334
|
|
|
334
|
-
if (operation ===
|
|
335
|
+
if (operation === AggregationTypes.Custom) {
|
|
335
336
|
assert(operationExp, 'operationExp is required for custom operation');
|
|
336
337
|
}
|
|
337
338
|
|
|
@@ -39,6 +39,7 @@ import {WidgetSource} from './widget-source.js';
|
|
|
39
39
|
import {booleanEqual} from '@turf/boolean-equal';
|
|
40
40
|
import type {WidgetTilesetSourceProps} from './widget-tileset-source.js';
|
|
41
41
|
import {getApplicableFilters} from '../filters.js';
|
|
42
|
+
import {AggregationTypes} from '../constants.js';
|
|
42
43
|
|
|
43
44
|
// TODO(cleanup): Parameter defaults in source functions and widget API calls are
|
|
44
45
|
// currently duplicated and possibly inconsistent. Consider consolidating and
|
|
@@ -120,7 +121,7 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
|
|
|
120
121
|
|
|
121
122
|
async getFormula({
|
|
122
123
|
column = '*',
|
|
123
|
-
operation =
|
|
124
|
+
operation = AggregationTypes.Count,
|
|
124
125
|
joinOperation,
|
|
125
126
|
filters,
|
|
126
127
|
filterOwner,
|
|
@@ -132,16 +133,16 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
|
|
|
132
133
|
filterOwner
|
|
133
134
|
);
|
|
134
135
|
|
|
135
|
-
if (filteredFeatures.length === 0 && operation !==
|
|
136
|
+
if (filteredFeatures.length === 0 && operation !== AggregationTypes.Count) {
|
|
136
137
|
return {value: null};
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
if (operation ===
|
|
140
|
+
if (operation === AggregationTypes.Custom) {
|
|
140
141
|
throw new Error('Custom aggregation not supported for tilesets');
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
// Column is required except when operation is 'count'.
|
|
144
|
-
if ((column && column !== '*') || operation !==
|
|
145
|
+
if ((column && column !== '*') || operation !== AggregationTypes.Count) {
|
|
145
146
|
assertColumn(this._features, column);
|
|
146
147
|
}
|
|
147
148
|
|
|
@@ -152,7 +153,7 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
|
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
override async getHistogram({
|
|
155
|
-
operation =
|
|
156
|
+
operation = AggregationTypes.Count,
|
|
156
157
|
ticks,
|
|
157
158
|
column,
|
|
158
159
|
joinOperation,
|
|
@@ -183,7 +184,7 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
|
|
|
183
184
|
|
|
184
185
|
override async getCategories({
|
|
185
186
|
column,
|
|
186
|
-
operation =
|
|
187
|
+
operation = AggregationTypes.Count,
|
|
187
188
|
operationColumn,
|
|
188
189
|
joinOperation,
|
|
189
190
|
filters,
|