@carto/api-client 0.5.5 → 0.5.6-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.
@@ -1147,10 +1147,31 @@ interface BaseRequestOptions {
1147
1147
  filters?: Filters;
1148
1148
  filterOwner?: string;
1149
1149
  }
1150
- /** Options for {@link WidgetRemoteSource#getCategories}. */
1150
+ /**
1151
+ * Examples:
1152
+ * * population by state
1153
+ * * column: 'state'
1154
+ * * operation: 'sum'
1155
+ * * operationColumn: 'population'
1156
+ * * average salary by department
1157
+ * * column: 'department'
1158
+ * * operation: 'avg'
1159
+ * * operationColumn: 'salary'
1160
+ * * custom aggregation by storetype
1161
+ * * column: 'storetype'
1162
+ * * operation: 'custom'
1163
+ * * operationExp: 'sum(sales)/sum(area)'
1164
+ *
1165
+ * Options for {@link WidgetRemoteSource#getCategories}.
1166
+ */
1151
1167
  interface CategoryRequestOptions extends BaseRequestOptions {
1168
+ /** The column that to categorize by. */
1152
1169
  column: string;
1153
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1170
+ /** The type of aggregation to apply on data in scope of each category. */
1171
+ operation: AggregationType;
1172
+ /** Remote only. Only valid if operation is 'custom' */
1173
+ operationExp?: string;
1174
+ /** The aggregated column per each category. */
1154
1175
  operationColumn?: string;
1155
1176
  /** Local only. */
1156
1177
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
@@ -1192,11 +1213,28 @@ interface FeaturesRequestOptions extends BaseRequestOptions {
1192
1213
  */
1193
1214
  tileResolution?: TileResolution;
1194
1215
  }
1195
- /** Options for {@link WidgetRemoteSource#getFormula}. */
1216
+ /**
1217
+ * Examples:
1218
+ * * sum of all sales
1219
+ * * column: 'sales'
1220
+ * * operation: 'sum'
1221
+ * * average salary
1222
+ * * column: 'salary'
1223
+ * * operation: 'avg'
1224
+ * * custom aggregation over all rows
1225
+ * * operation: 'custom'
1226
+ * * operationExp: 'sum(sales)/sum(area)'
1227
+ *
1228
+ * Options for {@link WidgetRemoteSource#getFormula}.
1229
+ */
1196
1230
  interface FormulaRequestOptions extends BaseRequestOptions {
1197
- column: string;
1198
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom';
1231
+ /** The column to apply the aggregation operation on. Not needed for 'custom' operation. */
1232
+ column?: string;
1233
+ /** The type of aggregation to apply on data. */
1234
+ operation: AggregationType;
1235
+ /** Remote only. Only valid if operation is 'custom' */
1199
1236
  operationExp?: string;
1237
+ /** Local only. */
1200
1238
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1201
1239
  }
1202
1240
  /** Options for {@link WidgetRemoteSource#getHistogram}. */
@@ -1231,12 +1269,25 @@ interface TableRequestOptions extends BaseRequestOptions {
1231
1269
  /** @deprecated Supported for tilesets only. Prefer `filters` (for all sources) instead. */
1232
1270
  searchFilterText?: string;
1233
1271
  }
1234
- /** Options for {@link WidgetRemoteSource#getTimeSeries}. */
1272
+ /**
1273
+ * Examples:
1274
+ * * sum of all sales by month
1275
+ * * column: 'sales'
1276
+ * * stepSize: 'month'
1277
+ * * operation: 'sum'
1278
+ * * average salary by year
1279
+ * * column: 'salary'
1280
+ * * stepSize: 'year'
1281
+ * * operation: 'avg'
1282
+ * Options for {@link WidgetRemoteSource#getTimeSeries}.
1283
+ */
1235
1284
  interface TimeSeriesRequestOptions extends BaseRequestOptions {
1236
1285
  column: string;
1237
1286
  stepSize: GroupDateType;
1238
1287
  stepMultiplier?: number;
1239
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1288
+ operation: AggregationType;
1289
+ /** Remote only. Only valid if operation is 'custom' */
1290
+ operationExp?: string;
1240
1291
  operationColumn?: string;
1241
1292
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1242
1293
  splitByCategory?: string;
@@ -1147,10 +1147,31 @@ interface BaseRequestOptions {
1147
1147
  filters?: Filters;
1148
1148
  filterOwner?: string;
1149
1149
  }
1150
- /** Options for {@link WidgetRemoteSource#getCategories}. */
1150
+ /**
1151
+ * Examples:
1152
+ * * population by state
1153
+ * * column: 'state'
1154
+ * * operation: 'sum'
1155
+ * * operationColumn: 'population'
1156
+ * * average salary by department
1157
+ * * column: 'department'
1158
+ * * operation: 'avg'
1159
+ * * operationColumn: 'salary'
1160
+ * * custom aggregation by storetype
1161
+ * * column: 'storetype'
1162
+ * * operation: 'custom'
1163
+ * * operationExp: 'sum(sales)/sum(area)'
1164
+ *
1165
+ * Options for {@link WidgetRemoteSource#getCategories}.
1166
+ */
1151
1167
  interface CategoryRequestOptions extends BaseRequestOptions {
1168
+ /** The column that to categorize by. */
1152
1169
  column: string;
1153
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1170
+ /** The type of aggregation to apply on data in scope of each category. */
1171
+ operation: AggregationType;
1172
+ /** Remote only. Only valid if operation is 'custom' */
1173
+ operationExp?: string;
1174
+ /** The aggregated column per each category. */
1154
1175
  operationColumn?: string;
1155
1176
  /** Local only. */
1156
1177
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
@@ -1192,11 +1213,28 @@ interface FeaturesRequestOptions extends BaseRequestOptions {
1192
1213
  */
1193
1214
  tileResolution?: TileResolution;
1194
1215
  }
1195
- /** Options for {@link WidgetRemoteSource#getFormula}. */
1216
+ /**
1217
+ * Examples:
1218
+ * * sum of all sales
1219
+ * * column: 'sales'
1220
+ * * operation: 'sum'
1221
+ * * average salary
1222
+ * * column: 'salary'
1223
+ * * operation: 'avg'
1224
+ * * custom aggregation over all rows
1225
+ * * operation: 'custom'
1226
+ * * operationExp: 'sum(sales)/sum(area)'
1227
+ *
1228
+ * Options for {@link WidgetRemoteSource#getFormula}.
1229
+ */
1196
1230
  interface FormulaRequestOptions extends BaseRequestOptions {
1197
- column: string;
1198
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom';
1231
+ /** The column to apply the aggregation operation on. Not needed for 'custom' operation. */
1232
+ column?: string;
1233
+ /** The type of aggregation to apply on data. */
1234
+ operation: AggregationType;
1235
+ /** Remote only. Only valid if operation is 'custom' */
1199
1236
  operationExp?: string;
1237
+ /** Local only. */
1200
1238
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1201
1239
  }
1202
1240
  /** Options for {@link WidgetRemoteSource#getHistogram}. */
@@ -1231,12 +1269,25 @@ interface TableRequestOptions extends BaseRequestOptions {
1231
1269
  /** @deprecated Supported for tilesets only. Prefer `filters` (for all sources) instead. */
1232
1270
  searchFilterText?: string;
1233
1271
  }
1234
- /** Options for {@link WidgetRemoteSource#getTimeSeries}. */
1272
+ /**
1273
+ * Examples:
1274
+ * * sum of all sales by month
1275
+ * * column: 'sales'
1276
+ * * stepSize: 'month'
1277
+ * * operation: 'sum'
1278
+ * * average salary by year
1279
+ * * column: 'salary'
1280
+ * * stepSize: 'year'
1281
+ * * operation: 'avg'
1282
+ * Options for {@link WidgetRemoteSource#getTimeSeries}.
1283
+ */
1235
1284
  interface TimeSeriesRequestOptions extends BaseRequestOptions {
1236
1285
  column: string;
1237
1286
  stepSize: GroupDateType;
1238
1287
  stepMultiplier?: number;
1239
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1288
+ operation: AggregationType;
1289
+ /** Remote only. Only valid if operation is 'custom' */
1290
+ operationExp?: string;
1240
1291
  operationColumn?: string;
1241
1292
  joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
1242
1293
  splitByCategory?: string;
@@ -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),