@carto/api-client 0.5.6-alpha.bundle.3 → 0.5.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 +7 -0
- package/build/api-client.cjs +26 -17
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +13 -2
- package/build/api-client.d.ts +13 -2
- package/build/api-client.js +25 -17
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.d.ts +2 -0
- package/build/{worker.global.js → worker-compat.js} +15 -7
- package/build/worker-compat.js.map +1 -0
- package/build/worker.js +14 -6
- package/build/worker.js.map +1 -1
- package/package.json +3 -3
- 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/widget-remote-source.ts +5 -5
- package/src/widget-sources/widget-tileset-source-impl.ts +7 -6
- package/src/widget-sources/widget-tileset-source.ts +2 -3
- package/build/worker.global.js.map +0 -1
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.6
|
|
11
|
+
"version": "0.5.6",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"types": "./build/worker.d.ts",
|
|
32
32
|
"default": "./build/worker.js"
|
|
33
33
|
},
|
|
34
|
-
"./worker
|
|
35
|
-
"default": "./build/worker.
|
|
34
|
+
"./worker-compat": {
|
|
35
|
+
"default": "./build/worker-compat.js"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"browserslist": [
|
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.
|
|
@@ -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;
|
|
@@ -76,7 +76,7 @@ export abstract class WidgetRemoteSource<
|
|
|
76
76
|
} = options;
|
|
77
77
|
const {column, operation, operationColumn, operationExp} = 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
|
|
|
@@ -148,7 +148,7 @@ export abstract class WidgetRemoteSource<
|
|
|
148
148
|
|
|
149
149
|
type FormulaModelResponse = {rows: {value: number}[]};
|
|
150
150
|
|
|
151
|
-
if (operation ===
|
|
151
|
+
if (operation === AggregationTypes.Custom) {
|
|
152
152
|
assert(operationExp, 'operationExp is required for custom operation');
|
|
153
153
|
}
|
|
154
154
|
|
|
@@ -161,7 +161,7 @@ export abstract class WidgetRemoteSource<
|
|
|
161
161
|
},
|
|
162
162
|
params: {
|
|
163
163
|
column: column ?? '*',
|
|
164
|
-
operation: operation ??
|
|
164
|
+
operation: operation ?? AggregationTypes.Count,
|
|
165
165
|
operationExp,
|
|
166
166
|
},
|
|
167
167
|
opts: {signal, headers: this.props.headers},
|
|
@@ -331,7 +331,7 @@ export abstract class WidgetRemoteSource<
|
|
|
331
331
|
splitByCategoryValues,
|
|
332
332
|
} = params;
|
|
333
333
|
|
|
334
|
-
if (operation ===
|
|
334
|
+
if (operation === AggregationTypes.Custom) {
|
|
335
335
|
assert(operationExp, 'operationExp is required for custom operation');
|
|
336
336
|
}
|
|
337
337
|
|
|
@@ -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,
|
|
@@ -99,14 +99,13 @@ export class WidgetTilesetSource<
|
|
|
99
99
|
return this._workerImpl;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
// For Vite (and perhaps other bundlers) to parse WorkerOptions, it
|
|
103
|
-
// must be a static, inline object – duplicated below.
|
|
104
102
|
if (this.props.widgetWorkerUrl) {
|
|
105
103
|
this._workerImpl = new Worker(this.props.widgetWorkerUrl, {
|
|
106
|
-
// type: 'module',
|
|
107
104
|
name: 'cartowidgettileset',
|
|
108
105
|
});
|
|
109
106
|
} else {
|
|
107
|
+
// For Vite (and perhaps other bundlers) to parse WorkerOptions, it
|
|
108
|
+
// must be a static, inline object – duplicated below.
|
|
110
109
|
this._workerImpl = new Worker(
|
|
111
110
|
new URL('@carto/api-client/worker', import.meta.url),
|
|
112
111
|
{
|