@carto/api-client 0.5.5 → 0.5.6-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/build/api-client.cjs +29 -6
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +65 -7
- package/build/api-client.d.ts +65 -7
- package/build/api-client.js +29 -6
- package/build/api-client.js.map +1 -1
- package/build/worker.js +4 -0
- package/build/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/sources/types.ts +8 -0
- package/src/widget-sources/types.ts +59 -7
- package/src/widget-sources/widget-remote-source.ts +17 -2
- package/src/widget-sources/widget-tileset-source-impl.ts +4 -0
- package/src/widget-sources/widget-tileset-source.ts +14 -5
package/build/api-client.d.cts
CHANGED
|
@@ -476,6 +476,13 @@ type TilesetSourceOptions = {
|
|
|
476
476
|
* are used by default if the runtime environment supports ES Module Workers.
|
|
477
477
|
*/
|
|
478
478
|
widgetWorker?: boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Script URL used to create Web Workers for local widget calculations. In
|
|
481
|
+
* most cases a custom URL is not needed; bundlers will resolve the worker
|
|
482
|
+
* URL from a `@carto/api-client/worker` import internally. Advanced uses
|
|
483
|
+
* may require deploying the script manually and providing a custom URL.
|
|
484
|
+
*/
|
|
485
|
+
widgetWorkerUrl?: string;
|
|
479
486
|
};
|
|
480
487
|
type ColumnsOption = {
|
|
481
488
|
/**
|
|
@@ -1147,10 +1154,31 @@ interface BaseRequestOptions {
|
|
|
1147
1154
|
filters?: Filters;
|
|
1148
1155
|
filterOwner?: string;
|
|
1149
1156
|
}
|
|
1150
|
-
/**
|
|
1157
|
+
/**
|
|
1158
|
+
* Examples:
|
|
1159
|
+
* * population by state
|
|
1160
|
+
* * column: 'state'
|
|
1161
|
+
* * operation: 'sum'
|
|
1162
|
+
* * operationColumn: 'population'
|
|
1163
|
+
* * average salary by department
|
|
1164
|
+
* * column: 'department'
|
|
1165
|
+
* * operation: 'avg'
|
|
1166
|
+
* * operationColumn: 'salary'
|
|
1167
|
+
* * custom aggregation by storetype
|
|
1168
|
+
* * column: 'storetype'
|
|
1169
|
+
* * operation: 'custom'
|
|
1170
|
+
* * operationExp: 'sum(sales)/sum(area)'
|
|
1171
|
+
*
|
|
1172
|
+
* Options for {@link WidgetRemoteSource#getCategories}.
|
|
1173
|
+
*/
|
|
1151
1174
|
interface CategoryRequestOptions extends BaseRequestOptions {
|
|
1175
|
+
/** The column that to categorize by. */
|
|
1152
1176
|
column: string;
|
|
1153
|
-
|
|
1177
|
+
/** The type of aggregation to apply on data in scope of each category. */
|
|
1178
|
+
operation: AggregationType;
|
|
1179
|
+
/** Remote only. Only valid if operation is 'custom' */
|
|
1180
|
+
operationExp?: string;
|
|
1181
|
+
/** The aggregated column per each category. */
|
|
1154
1182
|
operationColumn?: string;
|
|
1155
1183
|
/** Local only. */
|
|
1156
1184
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
@@ -1192,11 +1220,28 @@ interface FeaturesRequestOptions extends BaseRequestOptions {
|
|
|
1192
1220
|
*/
|
|
1193
1221
|
tileResolution?: TileResolution;
|
|
1194
1222
|
}
|
|
1195
|
-
/**
|
|
1223
|
+
/**
|
|
1224
|
+
* Examples:
|
|
1225
|
+
* * sum of all sales
|
|
1226
|
+
* * column: 'sales'
|
|
1227
|
+
* * operation: 'sum'
|
|
1228
|
+
* * average salary
|
|
1229
|
+
* * column: 'salary'
|
|
1230
|
+
* * operation: 'avg'
|
|
1231
|
+
* * custom aggregation over all rows
|
|
1232
|
+
* * operation: 'custom'
|
|
1233
|
+
* * operationExp: 'sum(sales)/sum(area)'
|
|
1234
|
+
*
|
|
1235
|
+
* Options for {@link WidgetRemoteSource#getFormula}.
|
|
1236
|
+
*/
|
|
1196
1237
|
interface FormulaRequestOptions extends BaseRequestOptions {
|
|
1197
|
-
column
|
|
1198
|
-
|
|
1238
|
+
/** The column to apply the aggregation operation on. Not needed for 'custom' operation. */
|
|
1239
|
+
column?: string;
|
|
1240
|
+
/** The type of aggregation to apply on data. */
|
|
1241
|
+
operation: AggregationType;
|
|
1242
|
+
/** Remote only. Only valid if operation is 'custom' */
|
|
1199
1243
|
operationExp?: string;
|
|
1244
|
+
/** Local only. */
|
|
1200
1245
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
1201
1246
|
}
|
|
1202
1247
|
/** Options for {@link WidgetRemoteSource#getHistogram}. */
|
|
@@ -1231,12 +1276,25 @@ interface TableRequestOptions extends BaseRequestOptions {
|
|
|
1231
1276
|
/** @deprecated Supported for tilesets only. Prefer `filters` (for all sources) instead. */
|
|
1232
1277
|
searchFilterText?: string;
|
|
1233
1278
|
}
|
|
1234
|
-
/**
|
|
1279
|
+
/**
|
|
1280
|
+
* Examples:
|
|
1281
|
+
* * sum of all sales by month
|
|
1282
|
+
* * column: 'sales'
|
|
1283
|
+
* * stepSize: 'month'
|
|
1284
|
+
* * operation: 'sum'
|
|
1285
|
+
* * average salary by year
|
|
1286
|
+
* * column: 'salary'
|
|
1287
|
+
* * stepSize: 'year'
|
|
1288
|
+
* * operation: 'avg'
|
|
1289
|
+
* Options for {@link WidgetRemoteSource#getTimeSeries}.
|
|
1290
|
+
*/
|
|
1235
1291
|
interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
1236
1292
|
column: string;
|
|
1237
1293
|
stepSize: GroupDateType;
|
|
1238
1294
|
stepMultiplier?: number;
|
|
1239
|
-
operation
|
|
1295
|
+
operation: AggregationType;
|
|
1296
|
+
/** Remote only. Only valid if operation is 'custom' */
|
|
1297
|
+
operationExp?: string;
|
|
1240
1298
|
operationColumn?: string;
|
|
1241
1299
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
1242
1300
|
splitByCategory?: string;
|
package/build/api-client.d.ts
CHANGED
|
@@ -476,6 +476,13 @@ type TilesetSourceOptions = {
|
|
|
476
476
|
* are used by default if the runtime environment supports ES Module Workers.
|
|
477
477
|
*/
|
|
478
478
|
widgetWorker?: boolean;
|
|
479
|
+
/**
|
|
480
|
+
* Script URL used to create Web Workers for local widget calculations. In
|
|
481
|
+
* most cases a custom URL is not needed; bundlers will resolve the worker
|
|
482
|
+
* URL from a `@carto/api-client/worker` import internally. Advanced uses
|
|
483
|
+
* may require deploying the script manually and providing a custom URL.
|
|
484
|
+
*/
|
|
485
|
+
widgetWorkerUrl?: string;
|
|
479
486
|
};
|
|
480
487
|
type ColumnsOption = {
|
|
481
488
|
/**
|
|
@@ -1147,10 +1154,31 @@ interface BaseRequestOptions {
|
|
|
1147
1154
|
filters?: Filters;
|
|
1148
1155
|
filterOwner?: string;
|
|
1149
1156
|
}
|
|
1150
|
-
/**
|
|
1157
|
+
/**
|
|
1158
|
+
* Examples:
|
|
1159
|
+
* * population by state
|
|
1160
|
+
* * column: 'state'
|
|
1161
|
+
* * operation: 'sum'
|
|
1162
|
+
* * operationColumn: 'population'
|
|
1163
|
+
* * average salary by department
|
|
1164
|
+
* * column: 'department'
|
|
1165
|
+
* * operation: 'avg'
|
|
1166
|
+
* * operationColumn: 'salary'
|
|
1167
|
+
* * custom aggregation by storetype
|
|
1168
|
+
* * column: 'storetype'
|
|
1169
|
+
* * operation: 'custom'
|
|
1170
|
+
* * operationExp: 'sum(sales)/sum(area)'
|
|
1171
|
+
*
|
|
1172
|
+
* Options for {@link WidgetRemoteSource#getCategories}.
|
|
1173
|
+
*/
|
|
1151
1174
|
interface CategoryRequestOptions extends BaseRequestOptions {
|
|
1175
|
+
/** The column that to categorize by. */
|
|
1152
1176
|
column: string;
|
|
1153
|
-
|
|
1177
|
+
/** The type of aggregation to apply on data in scope of each category. */
|
|
1178
|
+
operation: AggregationType;
|
|
1179
|
+
/** Remote only. Only valid if operation is 'custom' */
|
|
1180
|
+
operationExp?: string;
|
|
1181
|
+
/** The aggregated column per each category. */
|
|
1154
1182
|
operationColumn?: string;
|
|
1155
1183
|
/** Local only. */
|
|
1156
1184
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
@@ -1192,11 +1220,28 @@ interface FeaturesRequestOptions extends BaseRequestOptions {
|
|
|
1192
1220
|
*/
|
|
1193
1221
|
tileResolution?: TileResolution;
|
|
1194
1222
|
}
|
|
1195
|
-
/**
|
|
1223
|
+
/**
|
|
1224
|
+
* Examples:
|
|
1225
|
+
* * sum of all sales
|
|
1226
|
+
* * column: 'sales'
|
|
1227
|
+
* * operation: 'sum'
|
|
1228
|
+
* * average salary
|
|
1229
|
+
* * column: 'salary'
|
|
1230
|
+
* * operation: 'avg'
|
|
1231
|
+
* * custom aggregation over all rows
|
|
1232
|
+
* * operation: 'custom'
|
|
1233
|
+
* * operationExp: 'sum(sales)/sum(area)'
|
|
1234
|
+
*
|
|
1235
|
+
* Options for {@link WidgetRemoteSource#getFormula}.
|
|
1236
|
+
*/
|
|
1196
1237
|
interface FormulaRequestOptions extends BaseRequestOptions {
|
|
1197
|
-
column
|
|
1198
|
-
|
|
1238
|
+
/** The column to apply the aggregation operation on. Not needed for 'custom' operation. */
|
|
1239
|
+
column?: string;
|
|
1240
|
+
/** The type of aggregation to apply on data. */
|
|
1241
|
+
operation: AggregationType;
|
|
1242
|
+
/** Remote only. Only valid if operation is 'custom' */
|
|
1199
1243
|
operationExp?: string;
|
|
1244
|
+
/** Local only. */
|
|
1200
1245
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
1201
1246
|
}
|
|
1202
1247
|
/** Options for {@link WidgetRemoteSource#getHistogram}. */
|
|
@@ -1231,12 +1276,25 @@ interface TableRequestOptions extends BaseRequestOptions {
|
|
|
1231
1276
|
/** @deprecated Supported for tilesets only. Prefer `filters` (for all sources) instead. */
|
|
1232
1277
|
searchFilterText?: string;
|
|
1233
1278
|
}
|
|
1234
|
-
/**
|
|
1279
|
+
/**
|
|
1280
|
+
* Examples:
|
|
1281
|
+
* * sum of all sales by month
|
|
1282
|
+
* * column: 'sales'
|
|
1283
|
+
* * stepSize: 'month'
|
|
1284
|
+
* * operation: 'sum'
|
|
1285
|
+
* * average salary by year
|
|
1286
|
+
* * column: 'salary'
|
|
1287
|
+
* * stepSize: 'year'
|
|
1288
|
+
* * operation: 'avg'
|
|
1289
|
+
* Options for {@link WidgetRemoteSource#getTimeSeries}.
|
|
1290
|
+
*/
|
|
1235
1291
|
interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
1236
1292
|
column: string;
|
|
1237
1293
|
stepSize: GroupDateType;
|
|
1238
1294
|
stepMultiplier?: number;
|
|
1239
|
-
operation
|
|
1295
|
+
operation: AggregationType;
|
|
1296
|
+
/** Remote only. Only valid if operation is 'custom' */
|
|
1297
|
+
operationExp?: string;
|
|
1240
1298
|
operationColumn?: string;
|
|
1241
1299
|
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
1242
1300
|
splitByCategory?: string;
|
package/build/api-client.js
CHANGED
|
@@ -6263,7 +6263,10 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6263
6263
|
spatialFiltersMode,
|
|
6264
6264
|
...params
|
|
6265
6265
|
} = options;
|
|
6266
|
-
const { column, operation: operation2, operationColumn } = params;
|
|
6266
|
+
const { column, operation: operation2, operationColumn, operationExp } = params;
|
|
6267
|
+
if (operation2 === "custom") {
|
|
6268
|
+
assert2(operationExp, "operationExp is required for custom operation");
|
|
6269
|
+
}
|
|
6267
6270
|
return executeModel({
|
|
6268
6271
|
model: "category",
|
|
6269
6272
|
source: {
|
|
@@ -6274,6 +6277,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6274
6277
|
params: {
|
|
6275
6278
|
column,
|
|
6276
6279
|
operation: operation2,
|
|
6280
|
+
operationExp,
|
|
6277
6281
|
operationColumn: operationColumn || column
|
|
6278
6282
|
},
|
|
6279
6283
|
opts: { signal, headers: this.props.headers }
|
|
@@ -6319,6 +6323,9 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6319
6323
|
...params
|
|
6320
6324
|
} = options;
|
|
6321
6325
|
const { column, operation: operation2 } = params;
|
|
6326
|
+
if (operation2 === "custom") {
|
|
6327
|
+
assert2(operationExp, "operationExp is required for custom operation");
|
|
6328
|
+
}
|
|
6322
6329
|
return executeModel({
|
|
6323
6330
|
model: "formula",
|
|
6324
6331
|
source: {
|
|
@@ -6457,12 +6464,16 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6457
6464
|
operationColumn,
|
|
6458
6465
|
joinOperation,
|
|
6459
6466
|
operation: operation2,
|
|
6467
|
+
operationExp,
|
|
6460
6468
|
stepSize,
|
|
6461
6469
|
stepMultiplier,
|
|
6462
6470
|
splitByCategory,
|
|
6463
6471
|
splitByCategoryLimit,
|
|
6464
6472
|
splitByCategoryValues
|
|
6465
6473
|
} = params;
|
|
6474
|
+
if (operation2 === "custom") {
|
|
6475
|
+
assert2(operationExp, "operationExp is required for custom operation");
|
|
6476
|
+
}
|
|
6466
6477
|
return executeModel({
|
|
6467
6478
|
model: "timeseries",
|
|
6468
6479
|
source: {
|
|
@@ -6477,6 +6488,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6477
6488
|
operationColumn: operationColumn || column,
|
|
6478
6489
|
joinOperation,
|
|
6479
6490
|
operation: operation2,
|
|
6491
|
+
operationExp,
|
|
6480
6492
|
splitByCategory,
|
|
6481
6493
|
splitByCategoryLimit,
|
|
6482
6494
|
splitByCategoryValues
|
|
@@ -7362,6 +7374,10 @@ var WidgetTilesetSourceImpl = class extends WidgetSource {
|
|
|
7362
7374
|
return { rows: [] };
|
|
7363
7375
|
}
|
|
7364
7376
|
assertColumn(this._features, column, operationColumn);
|
|
7377
|
+
assert2(
|
|
7378
|
+
operation2 !== "custom",
|
|
7379
|
+
"Custom operation not supported for tilesets"
|
|
7380
|
+
);
|
|
7365
7381
|
const rows = groupValuesByDateColumn({
|
|
7366
7382
|
data: filteredFeatures,
|
|
7367
7383
|
valuesColumns: normalizeColumns(operationColumn || column),
|
|
@@ -7451,13 +7467,20 @@ var WidgetTilesetSource = class extends WidgetSource {
|
|
|
7451
7467
|
if (this._workerImpl) {
|
|
7452
7468
|
return this._workerImpl;
|
|
7453
7469
|
}
|
|
7454
|
-
this.
|
|
7455
|
-
new
|
|
7456
|
-
{
|
|
7470
|
+
if (this.props.widgetWorkerUrl) {
|
|
7471
|
+
this._workerImpl = new Worker(this.props.widgetWorkerUrl, {
|
|
7457
7472
|
type: "module",
|
|
7458
7473
|
name: "cartowidgettileset"
|
|
7459
|
-
}
|
|
7460
|
-
|
|
7474
|
+
});
|
|
7475
|
+
} else {
|
|
7476
|
+
this._workerImpl = new Worker(
|
|
7477
|
+
new URL("@carto/api-client/worker", import.meta.url),
|
|
7478
|
+
{
|
|
7479
|
+
type: "module",
|
|
7480
|
+
name: "cartowidgettileset"
|
|
7481
|
+
}
|
|
7482
|
+
);
|
|
7483
|
+
}
|
|
7461
7484
|
this._workerImpl.postMessage({
|
|
7462
7485
|
method: "init" /* INIT */,
|
|
7463
7486
|
params: [this.props]
|