@carto/api-client 0.5.0-alpha.5 → 0.5.0-alpha.7
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 +104 -122
- package/build/api-client.d.cts +24 -13
- package/build/api-client.d.ts +24 -13
- package/build/api-client.js +104 -122
- package/build/worker.js +5 -7
- package/package.json +1 -5
- package/src/models/common.ts +2 -2
- package/src/widget-sources/types.ts +1 -1
- package/src/widget-sources/widget-remote-source.ts +16 -16
- package/src/widget-sources/widget-tileset-source.ts +2 -2
- package/src/widget-sources/widget-tileset-worker-source.ts +123 -121
- package/src/workers/types.ts +0 -1
- package/src/workers/widget-tileset-worker.ts +11 -8
- package/build/{chunk-V3E7BKVR.js → chunk-LEI5PI5X.js} +1 -1
package/build/api-client.js
CHANGED
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
tileFeaturesGeometries,
|
|
42
42
|
tileFeaturesSpatialIndex,
|
|
43
43
|
transformToTileCoords
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-LEI5PI5X.js";
|
|
45
45
|
|
|
46
46
|
// src/deck/get-data-filter-extension-props.ts
|
|
47
47
|
function getDataFilterExtensionProps(filters, filtersLogicalOperator, filterSize) {
|
|
@@ -653,7 +653,7 @@ async function makeCall({
|
|
|
653
653
|
method: opts?.method,
|
|
654
654
|
body: opts?.body
|
|
655
655
|
},
|
|
656
|
-
signal: opts?.
|
|
656
|
+
signal: opts?.signal,
|
|
657
657
|
...opts?.otherOptions
|
|
658
658
|
});
|
|
659
659
|
data = await response.json();
|
|
@@ -788,12 +788,12 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
788
788
|
}
|
|
789
789
|
async getCategories(options) {
|
|
790
790
|
const {
|
|
791
|
+
signal,
|
|
791
792
|
filters = this.props.filters,
|
|
792
793
|
filterOwner,
|
|
793
794
|
spatialFilter,
|
|
794
795
|
spatialFiltersMode,
|
|
795
796
|
spatialIndexReferenceViewState,
|
|
796
|
-
abortController,
|
|
797
797
|
...params
|
|
798
798
|
} = options;
|
|
799
799
|
const { column, operation, operationColumn } = params;
|
|
@@ -816,17 +816,17 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
816
816
|
operation,
|
|
817
817
|
operationColumn: operationColumn || column
|
|
818
818
|
},
|
|
819
|
-
opts: {
|
|
819
|
+
opts: { signal, headers: this._headers }
|
|
820
820
|
}).then((res) => normalizeObjectKeys(res.rows));
|
|
821
821
|
}
|
|
822
822
|
async getFeatures(options) {
|
|
823
823
|
const {
|
|
824
|
+
signal,
|
|
824
825
|
filters = this.props.filters,
|
|
825
826
|
filterOwner,
|
|
826
827
|
spatialFilter,
|
|
827
828
|
spatialFiltersMode,
|
|
828
829
|
spatialIndexReferenceViewState,
|
|
829
|
-
abortController,
|
|
830
830
|
...params
|
|
831
831
|
} = options;
|
|
832
832
|
const { columns, dataType, featureIds, z, limit, tileResolution } = params;
|
|
@@ -852,18 +852,18 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
852
852
|
limit: limit || 1e3,
|
|
853
853
|
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION
|
|
854
854
|
},
|
|
855
|
-
opts: {
|
|
855
|
+
opts: { signal, headers: this._headers }
|
|
856
856
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
857
857
|
}).then(({ rows }) => ({ rows }));
|
|
858
858
|
}
|
|
859
859
|
async getFormula(options) {
|
|
860
860
|
const {
|
|
861
|
+
signal,
|
|
861
862
|
filters = this.props.filters,
|
|
862
863
|
filterOwner,
|
|
863
864
|
spatialFilter,
|
|
864
865
|
spatialFiltersMode,
|
|
865
866
|
spatialIndexReferenceViewState,
|
|
866
|
-
abortController,
|
|
867
867
|
operationExp,
|
|
868
868
|
...params
|
|
869
869
|
} = options;
|
|
@@ -887,17 +887,17 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
887
887
|
operation: operation ?? "count",
|
|
888
888
|
operationExp
|
|
889
889
|
},
|
|
890
|
-
opts: {
|
|
890
|
+
opts: { signal, headers: this._headers }
|
|
891
891
|
}).then((res) => normalizeObjectKeys(res.rows[0]));
|
|
892
892
|
}
|
|
893
893
|
async getHistogram(options) {
|
|
894
894
|
const {
|
|
895
|
+
signal,
|
|
895
896
|
filters = this.props.filters,
|
|
896
897
|
filterOwner,
|
|
897
898
|
spatialFilter,
|
|
898
899
|
spatialFiltersMode,
|
|
899
900
|
spatialIndexReferenceViewState,
|
|
900
|
-
abortController,
|
|
901
901
|
...params
|
|
902
902
|
} = options;
|
|
903
903
|
const { column, operation, ticks } = params;
|
|
@@ -916,7 +916,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
916
916
|
spatialFilter
|
|
917
917
|
},
|
|
918
918
|
params: { column, operation, ticks },
|
|
919
|
-
opts: {
|
|
919
|
+
opts: { signal, headers: this._headers }
|
|
920
920
|
}).then((res) => normalizeObjectKeys(res.rows));
|
|
921
921
|
if (data.length) {
|
|
922
922
|
const result = Array(ticks.length + 1).fill(0);
|
|
@@ -929,12 +929,12 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
929
929
|
}
|
|
930
930
|
async getRange(options) {
|
|
931
931
|
const {
|
|
932
|
+
signal,
|
|
932
933
|
filters = this.props.filters,
|
|
933
934
|
filterOwner,
|
|
934
935
|
spatialFilter,
|
|
935
936
|
spatialFiltersMode,
|
|
936
937
|
spatialIndexReferenceViewState,
|
|
937
|
-
abortController,
|
|
938
938
|
...params
|
|
939
939
|
} = options;
|
|
940
940
|
const { column } = params;
|
|
@@ -953,17 +953,17 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
953
953
|
spatialFilter
|
|
954
954
|
},
|
|
955
955
|
params: { column },
|
|
956
|
-
opts: {
|
|
956
|
+
opts: { signal, headers: this._headers }
|
|
957
957
|
}).then((res) => normalizeObjectKeys(res.rows[0]));
|
|
958
958
|
}
|
|
959
959
|
async getScatter(options) {
|
|
960
960
|
const {
|
|
961
|
+
signal,
|
|
961
962
|
filters = this.props.filters,
|
|
962
963
|
filterOwner,
|
|
963
964
|
spatialFilter,
|
|
964
965
|
spatialFiltersMode,
|
|
965
966
|
spatialIndexReferenceViewState,
|
|
966
|
-
abortController,
|
|
967
967
|
...params
|
|
968
968
|
} = options;
|
|
969
969
|
const { xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation } = params;
|
|
@@ -989,17 +989,17 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
989
989
|
yAxisJoinOperation,
|
|
990
990
|
limit: HARD_LIMIT
|
|
991
991
|
},
|
|
992
|
-
opts: {
|
|
992
|
+
opts: { signal, headers: this._headers }
|
|
993
993
|
}).then((res) => normalizeObjectKeys(res.rows)).then((res) => res.map(({ x, y }) => [x, y]));
|
|
994
994
|
}
|
|
995
995
|
async getTable(options) {
|
|
996
996
|
const {
|
|
997
|
+
signal,
|
|
997
998
|
filters = this.props.filters,
|
|
998
999
|
filterOwner,
|
|
999
1000
|
spatialFilter,
|
|
1000
1001
|
spatialFiltersMode,
|
|
1001
1002
|
spatialIndexReferenceViewState,
|
|
1002
|
-
abortController,
|
|
1003
1003
|
...params
|
|
1004
1004
|
} = options;
|
|
1005
1005
|
const { columns, sortBy, sortDirection, offset = 0, limit = 10 } = params;
|
|
@@ -1024,7 +1024,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
1024
1024
|
limit,
|
|
1025
1025
|
offset
|
|
1026
1026
|
},
|
|
1027
|
-
opts: {
|
|
1027
|
+
opts: { signal, headers: this._headers }
|
|
1028
1028
|
}).then((res) => ({
|
|
1029
1029
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
1030
1030
|
rows: res.rows ?? res.ROWS,
|
|
@@ -1033,9 +1033,9 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
1033
1033
|
}
|
|
1034
1034
|
async getTimeSeries(options) {
|
|
1035
1035
|
const {
|
|
1036
|
+
signal,
|
|
1036
1037
|
filters = this.props.filters,
|
|
1037
1038
|
filterOwner,
|
|
1038
|
-
abortController,
|
|
1039
1039
|
spatialFilter,
|
|
1040
1040
|
spatialFiltersMode,
|
|
1041
1041
|
spatialIndexReferenceViewState,
|
|
@@ -1077,7 +1077,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
1077
1077
|
splitByCategoryLimit,
|
|
1078
1078
|
splitByCategoryValues
|
|
1079
1079
|
},
|
|
1080
|
-
opts: {
|
|
1080
|
+
opts: { signal, headers: this._headers }
|
|
1081
1081
|
}).then((res) => ({
|
|
1082
1082
|
rows: normalizeObjectKeys(res.rows),
|
|
1083
1083
|
categories: res.metadata?.categories
|
|
@@ -1109,16 +1109,79 @@ var WidgetTableSource = class extends WidgetRemoteSource {
|
|
|
1109
1109
|
};
|
|
1110
1110
|
|
|
1111
1111
|
// src/widget-sources/widget-tileset-worker-source.ts
|
|
1112
|
-
var
|
|
1112
|
+
var WidgetTilesetWorkerSource = class extends WidgetSource {
|
|
1113
1113
|
constructor(props) {
|
|
1114
1114
|
super(props);
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1115
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
1116
|
+
// WEB WORKER MANAGEMENT
|
|
1117
|
+
__publicField(this, "_worker", null);
|
|
1118
|
+
__publicField(this, "_workerNextRequestId", 1);
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Returns an initialized Worker, to be reused for the lifecycle of this
|
|
1122
|
+
* source instance.
|
|
1123
|
+
*/
|
|
1124
|
+
_getWorker() {
|
|
1125
|
+
if (this._worker) {
|
|
1126
|
+
return this._worker;
|
|
1127
|
+
}
|
|
1128
|
+
this._worker = new Worker(
|
|
1129
|
+
new URL("@carto/api-client/worker", import.meta.url),
|
|
1130
|
+
{
|
|
1131
|
+
type: "module",
|
|
1132
|
+
name: "cartowidgettileset"
|
|
1133
|
+
}
|
|
1134
|
+
);
|
|
1135
|
+
this._worker.postMessage({
|
|
1118
1136
|
method: "init" /* INIT */,
|
|
1119
1137
|
params: [this.props]
|
|
1120
1138
|
});
|
|
1139
|
+
return this._worker;
|
|
1121
1140
|
}
|
|
1141
|
+
/** Executes a given method on the worker. */
|
|
1142
|
+
_executeWorkerMethod(method, params, signal) {
|
|
1143
|
+
const worker = this._getWorker();
|
|
1144
|
+
const requestId = this._workerNextRequestId++;
|
|
1145
|
+
const options = params[0];
|
|
1146
|
+
if (options?.spatialIndexReferenceViewState) {
|
|
1147
|
+
const { zoom, latitude, longitude } = options.spatialIndexReferenceViewState;
|
|
1148
|
+
options.spatialIndexReferenceViewState = { zoom, latitude, longitude };
|
|
1149
|
+
}
|
|
1150
|
+
let resolve = null;
|
|
1151
|
+
let reject = null;
|
|
1152
|
+
function onMessage(e) {
|
|
1153
|
+
const response = e.data;
|
|
1154
|
+
if (response.requestId !== requestId) return;
|
|
1155
|
+
if (signal?.aborted) {
|
|
1156
|
+
reject(new Error(signal.reason));
|
|
1157
|
+
} else if (response.ok) {
|
|
1158
|
+
resolve(response.result);
|
|
1159
|
+
} else {
|
|
1160
|
+
reject(new Error(response.error));
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
function onAbort() {
|
|
1164
|
+
reject(new Error(signal.reason));
|
|
1165
|
+
}
|
|
1166
|
+
worker.addEventListener("message", onMessage);
|
|
1167
|
+
signal?.addEventListener("abort", onAbort);
|
|
1168
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
1169
|
+
resolve = _resolve;
|
|
1170
|
+
reject = _reject;
|
|
1171
|
+
worker.postMessage({
|
|
1172
|
+
requestId,
|
|
1173
|
+
method,
|
|
1174
|
+
params
|
|
1175
|
+
});
|
|
1176
|
+
});
|
|
1177
|
+
void promise.finally(() => {
|
|
1178
|
+
worker.removeEventListener("message", onMessage);
|
|
1179
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1180
|
+
});
|
|
1181
|
+
return promise;
|
|
1182
|
+
}
|
|
1183
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
1184
|
+
// DATA LOADING
|
|
1122
1185
|
/**
|
|
1123
1186
|
* Loads features as a list of tiles (typically provided by deck.gl).
|
|
1124
1187
|
* After tiles are loaded, {@link extractTileFeatures} must be called
|
|
@@ -1130,16 +1193,14 @@ var _WidgetTilesetWorkerSource = class _WidgetTilesetWorkerSource extends Widget
|
|
|
1130
1193
|
bbox,
|
|
1131
1194
|
data
|
|
1132
1195
|
}));
|
|
1133
|
-
|
|
1134
|
-
tableName: this.props.tableName,
|
|
1196
|
+
this._getWorker().postMessage({
|
|
1135
1197
|
method: "loadTiles" /* LOAD_TILES */,
|
|
1136
1198
|
params: [tiles]
|
|
1137
1199
|
});
|
|
1138
1200
|
}
|
|
1139
1201
|
/** Configures options used to extract features from tiles. */
|
|
1140
1202
|
setTileFeatureExtractOptions(options) {
|
|
1141
|
-
|
|
1142
|
-
tableName: this.props.tableName,
|
|
1203
|
+
this._getWorker().postMessage({
|
|
1143
1204
|
type: "setTileFeatureExtractOptions" /* SET_TILE_FEATURE_EXTRACT_OPTIONS */,
|
|
1144
1205
|
params: [options]
|
|
1145
1206
|
});
|
|
@@ -1153,139 +1214,60 @@ var _WidgetTilesetWorkerSource = class _WidgetTilesetWorkerSource extends Widget
|
|
|
1153
1214
|
geojson,
|
|
1154
1215
|
spatialFilter
|
|
1155
1216
|
}) {
|
|
1156
|
-
|
|
1157
|
-
tableName: this.props.tableName,
|
|
1217
|
+
this._getWorker().postMessage({
|
|
1158
1218
|
method: "loadGeoJSON" /* LOAD_GEOJSON */,
|
|
1159
1219
|
params: [{ geojson, spatialFilter }]
|
|
1160
1220
|
});
|
|
1161
1221
|
}
|
|
1222
|
+
/////////////////////////////////////////////////////////////////////////////
|
|
1223
|
+
// WIDGETS API
|
|
1162
1224
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1163
1225
|
async getFeatures() {
|
|
1164
1226
|
throw new Error("getFeatures not supported for tilesets");
|
|
1165
1227
|
}
|
|
1166
1228
|
async getFormula({
|
|
1167
|
-
|
|
1229
|
+
signal,
|
|
1168
1230
|
...options
|
|
1169
1231
|
}) {
|
|
1170
|
-
return this._executeWorkerMethod(
|
|
1171
|
-
this.props.tableName,
|
|
1172
|
-
"getFormula" /* GET_FORMULA */,
|
|
1173
|
-
[options],
|
|
1174
|
-
abortController?.signal
|
|
1175
|
-
);
|
|
1232
|
+
return this._executeWorkerMethod("getFormula" /* GET_FORMULA */, [options], signal);
|
|
1176
1233
|
}
|
|
1177
1234
|
async getHistogram({
|
|
1178
|
-
|
|
1235
|
+
signal,
|
|
1179
1236
|
...options
|
|
1180
1237
|
}) {
|
|
1181
|
-
return this._executeWorkerMethod(
|
|
1182
|
-
this.props.tableName,
|
|
1183
|
-
"getHistogram" /* GET_HISTOGRAM */,
|
|
1184
|
-
[options],
|
|
1185
|
-
abortController?.signal
|
|
1186
|
-
);
|
|
1238
|
+
return this._executeWorkerMethod("getHistogram" /* GET_HISTOGRAM */, [options], signal);
|
|
1187
1239
|
}
|
|
1188
1240
|
async getCategories({
|
|
1189
|
-
|
|
1241
|
+
signal,
|
|
1190
1242
|
...options
|
|
1191
1243
|
}) {
|
|
1192
|
-
return this._executeWorkerMethod(
|
|
1193
|
-
this.props.tableName,
|
|
1194
|
-
"getCategories" /* GET_CATEGORIES */,
|
|
1195
|
-
[options],
|
|
1196
|
-
abortController?.signal
|
|
1197
|
-
);
|
|
1244
|
+
return this._executeWorkerMethod("getCategories" /* GET_CATEGORIES */, [options], signal);
|
|
1198
1245
|
}
|
|
1199
1246
|
async getScatter({
|
|
1200
|
-
|
|
1247
|
+
signal,
|
|
1201
1248
|
...options
|
|
1202
1249
|
}) {
|
|
1203
|
-
return this._executeWorkerMethod(
|
|
1204
|
-
this.props.tableName,
|
|
1205
|
-
"getScatter" /* GET_SCATTER */,
|
|
1206
|
-
[options],
|
|
1207
|
-
abortController?.signal
|
|
1208
|
-
);
|
|
1250
|
+
return this._executeWorkerMethod("getScatter" /* GET_SCATTER */, [options], signal);
|
|
1209
1251
|
}
|
|
1210
1252
|
async getTable({
|
|
1211
|
-
|
|
1253
|
+
signal,
|
|
1212
1254
|
...options
|
|
1213
1255
|
}) {
|
|
1214
|
-
return this._executeWorkerMethod(
|
|
1215
|
-
this.props.tableName,
|
|
1216
|
-
"getTable" /* GET_TABLE */,
|
|
1217
|
-
[options],
|
|
1218
|
-
abortController?.signal
|
|
1219
|
-
);
|
|
1256
|
+
return this._executeWorkerMethod("getTable" /* GET_TABLE */, [options], signal);
|
|
1220
1257
|
}
|
|
1221
1258
|
async getTimeSeries({
|
|
1222
|
-
|
|
1259
|
+
signal,
|
|
1223
1260
|
...options
|
|
1224
1261
|
}) {
|
|
1225
|
-
return this._executeWorkerMethod(
|
|
1226
|
-
this.props.tableName,
|
|
1227
|
-
"getTimeSeries" /* GET_TIME_SERIES */,
|
|
1228
|
-
[options],
|
|
1229
|
-
abortController?.signal
|
|
1230
|
-
);
|
|
1262
|
+
return this._executeWorkerMethod("getTimeSeries" /* GET_TIME_SERIES */, [options], signal);
|
|
1231
1263
|
}
|
|
1232
1264
|
async getRange({
|
|
1233
|
-
|
|
1265
|
+
signal,
|
|
1234
1266
|
...options
|
|
1235
1267
|
}) {
|
|
1236
|
-
return this._executeWorkerMethod(
|
|
1237
|
-
this.props.tableName,
|
|
1238
|
-
"getRange" /* GET_RANGE */,
|
|
1239
|
-
[options],
|
|
1240
|
-
abortController?.signal
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
static init() {
|
|
1244
|
-
_WidgetTilesetWorkerSource.WORKER = new Worker(
|
|
1245
|
-
new URL("@carto/api-client/worker", import.meta.url),
|
|
1246
|
-
{
|
|
1247
|
-
type: "module",
|
|
1248
|
-
name: "cartowidgettileset"
|
|
1249
|
-
}
|
|
1250
|
-
);
|
|
1251
|
-
}
|
|
1252
|
-
_executeWorkerMethod(tableName, method, params, signal) {
|
|
1253
|
-
const worker = _WidgetTilesetWorkerSource.WORKER;
|
|
1254
|
-
const requestId = _WidgetTilesetWorkerSource._nextRequestID++;
|
|
1255
|
-
const options = params[0];
|
|
1256
|
-
if (options?.spatialIndexReferenceViewState) {
|
|
1257
|
-
const { zoom, latitude, longitude } = options.spatialIndexReferenceViewState;
|
|
1258
|
-
options.spatialIndexReferenceViewState = { zoom, latitude, longitude };
|
|
1259
|
-
}
|
|
1260
|
-
worker.postMessage({
|
|
1261
|
-
requestId,
|
|
1262
|
-
tableName,
|
|
1263
|
-
method,
|
|
1264
|
-
params
|
|
1265
|
-
});
|
|
1266
|
-
return new Promise((resolve, reject) => {
|
|
1267
|
-
function listener(e) {
|
|
1268
|
-
const response = e.data;
|
|
1269
|
-
if (response.requestId !== requestId) return;
|
|
1270
|
-
worker.removeEventListener("message", listener);
|
|
1271
|
-
if (signal?.aborted) {
|
|
1272
|
-
reject(new Error(signal.reason));
|
|
1273
|
-
} else if (response.ok) {
|
|
1274
|
-
resolve(response.result);
|
|
1275
|
-
} else {
|
|
1276
|
-
reject(new Error(response.error));
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
worker.addEventListener("message", listener);
|
|
1280
|
-
});
|
|
1268
|
+
return this._executeWorkerMethod("getRange" /* GET_RANGE */, [options], signal);
|
|
1281
1269
|
}
|
|
1282
1270
|
};
|
|
1283
|
-
/////////////////////////////////////////////////////////////////////////////
|
|
1284
|
-
// WEB WORKER MANAGEMENT
|
|
1285
|
-
// TODO: Singleton? Pool shared among datasets? One per dataset?
|
|
1286
|
-
__publicField(_WidgetTilesetWorkerSource, "WORKER");
|
|
1287
|
-
__publicField(_WidgetTilesetWorkerSource, "_nextRequestID", 1);
|
|
1288
|
-
var WidgetTilesetWorkerSource = _WidgetTilesetWorkerSource;
|
|
1289
1271
|
|
|
1290
1272
|
// src/sources/h3-query-source.ts
|
|
1291
1273
|
var h3QuerySource = async function(options) {
|
package/build/worker.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WidgetTilesetSource
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LEI5PI5X.js";
|
|
4
4
|
|
|
5
5
|
// src/workers/widget-tileset-worker.ts
|
|
6
|
-
var
|
|
6
|
+
var source;
|
|
7
7
|
addEventListener("message", (e) => {
|
|
8
|
-
const {
|
|
8
|
+
const { method, params, requestId } = e.data;
|
|
9
9
|
if (method === "init" /* INIT */) {
|
|
10
|
-
|
|
11
|
-
SOURCES_BY_NAME.set(tableName, new WidgetTilesetSource(props));
|
|
10
|
+
source = new WidgetTilesetSource(params[0]);
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
|
-
const source = SOURCES_BY_NAME.get(tableName);
|
|
15
13
|
if (!source) {
|
|
16
|
-
const error = `
|
|
14
|
+
const error = `Cannot execute "${method}" on uninitialized source.`;
|
|
17
15
|
postMessage({ ok: false, error, requestId });
|
|
18
16
|
return;
|
|
19
17
|
}
|
package/package.json
CHANGED
|
@@ -8,12 +8,8 @@
|
|
|
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.0-alpha.
|
|
11
|
+
"version": "0.5.0-alpha.7",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"access": "public",
|
|
15
|
-
"tag": "alpha"
|
|
16
|
-
},
|
|
17
13
|
"type": "module",
|
|
18
14
|
"sideEffects": false,
|
|
19
15
|
"exports": {
|
package/src/models/common.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {InvalidColumnError} from '../utils.js';
|
|
|
4
4
|
export interface ModelRequestOptions {
|
|
5
5
|
method: 'GET' | 'POST';
|
|
6
6
|
headers?: Record<string, string>;
|
|
7
|
-
|
|
7
|
+
signal?: AbortSignal;
|
|
8
8
|
otherOptions?: Record<string, unknown>;
|
|
9
9
|
body?: string;
|
|
10
10
|
}
|
|
@@ -75,7 +75,7 @@ export async function makeCall({
|
|
|
75
75
|
method: opts?.method,
|
|
76
76
|
body: opts?.body,
|
|
77
77
|
}),
|
|
78
|
-
signal: opts?.
|
|
78
|
+
signal: opts?.signal,
|
|
79
79
|
...opts?.otherOptions,
|
|
80
80
|
});
|
|
81
81
|
data = await response.json();
|
|
@@ -19,11 +19,11 @@ export interface ViewState {
|
|
|
19
19
|
|
|
20
20
|
/** Common options for {@link WidgetRemoteSource} requests. */
|
|
21
21
|
interface BaseRequestOptions {
|
|
22
|
+
signal?: AbortSignal;
|
|
22
23
|
spatialFilter?: SpatialFilter;
|
|
23
24
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
24
25
|
/** Required for table- and query-based spatial index sources (H3, Quadbin). */
|
|
25
26
|
spatialIndexReferenceViewState?: ViewState;
|
|
26
|
-
abortController?: AbortController;
|
|
27
27
|
/** Overrides source filters, if any. */
|
|
28
28
|
filters?: Filters;
|
|
29
29
|
filterOwner?: string;
|
|
@@ -75,12 +75,12 @@ export abstract class WidgetRemoteSource<
|
|
|
75
75
|
options: CategoryRequestOptions
|
|
76
76
|
): Promise<CategoryResponse> {
|
|
77
77
|
const {
|
|
78
|
+
signal,
|
|
78
79
|
filters = this.props.filters,
|
|
79
80
|
filterOwner,
|
|
80
81
|
spatialFilter,
|
|
81
82
|
spatialFiltersMode,
|
|
82
83
|
spatialIndexReferenceViewState,
|
|
83
|
-
abortController,
|
|
84
84
|
...params
|
|
85
85
|
} = options;
|
|
86
86
|
const {column, operation, operationColumn} = params;
|
|
@@ -106,7 +106,7 @@ export abstract class WidgetRemoteSource<
|
|
|
106
106
|
operation,
|
|
107
107
|
operationColumn: operationColumn || column,
|
|
108
108
|
},
|
|
109
|
-
opts: {
|
|
109
|
+
opts: {signal, headers: this._headers},
|
|
110
110
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -114,12 +114,12 @@ export abstract class WidgetRemoteSource<
|
|
|
114
114
|
options: FeaturesRequestOptions
|
|
115
115
|
): Promise<FeaturesResponse> {
|
|
116
116
|
const {
|
|
117
|
+
signal,
|
|
117
118
|
filters = this.props.filters,
|
|
118
119
|
filterOwner,
|
|
119
120
|
spatialFilter,
|
|
120
121
|
spatialFiltersMode,
|
|
121
122
|
spatialIndexReferenceViewState,
|
|
122
|
-
abortController,
|
|
123
123
|
...params
|
|
124
124
|
} = options;
|
|
125
125
|
const {columns, dataType, featureIds, z, limit, tileResolution} = params;
|
|
@@ -148,19 +148,19 @@ export abstract class WidgetRemoteSource<
|
|
|
148
148
|
limit: limit || 1000,
|
|
149
149
|
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
|
|
150
150
|
},
|
|
151
|
-
opts: {
|
|
151
|
+
opts: {signal, headers: this._headers},
|
|
152
152
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
153
153
|
}).then(({rows}: FeaturesModelResponse) => ({rows}));
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
async getFormula(options: FormulaRequestOptions): Promise<FormulaResponse> {
|
|
157
157
|
const {
|
|
158
|
+
signal,
|
|
158
159
|
filters = this.props.filters,
|
|
159
160
|
filterOwner,
|
|
160
161
|
spatialFilter,
|
|
161
162
|
spatialFiltersMode,
|
|
162
163
|
spatialIndexReferenceViewState,
|
|
163
|
-
abortController,
|
|
164
164
|
operationExp,
|
|
165
165
|
...params
|
|
166
166
|
} = options;
|
|
@@ -187,7 +187,7 @@ export abstract class WidgetRemoteSource<
|
|
|
187
187
|
operation: operation ?? 'count',
|
|
188
188
|
operationExp,
|
|
189
189
|
},
|
|
190
|
-
opts: {
|
|
190
|
+
opts: {signal, headers: this._headers},
|
|
191
191
|
}).then((res: FormulaModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -195,12 +195,12 @@ export abstract class WidgetRemoteSource<
|
|
|
195
195
|
options: HistogramRequestOptions
|
|
196
196
|
): Promise<HistogramResponse> {
|
|
197
197
|
const {
|
|
198
|
+
signal,
|
|
198
199
|
filters = this.props.filters,
|
|
199
200
|
filterOwner,
|
|
200
201
|
spatialFilter,
|
|
201
202
|
spatialFiltersMode,
|
|
202
203
|
spatialIndexReferenceViewState,
|
|
203
|
-
abortController,
|
|
204
204
|
...params
|
|
205
205
|
} = options;
|
|
206
206
|
const {column, operation, ticks} = params;
|
|
@@ -222,7 +222,7 @@ export abstract class WidgetRemoteSource<
|
|
|
222
222
|
spatialFilter,
|
|
223
223
|
},
|
|
224
224
|
params: {column, operation, ticks},
|
|
225
|
-
opts: {
|
|
225
|
+
opts: {signal, headers: this._headers},
|
|
226
226
|
}).then((res: HistogramModelResponse) => normalizeObjectKeys(res.rows));
|
|
227
227
|
|
|
228
228
|
if (data.length) {
|
|
@@ -240,12 +240,12 @@ export abstract class WidgetRemoteSource<
|
|
|
240
240
|
|
|
241
241
|
async getRange(options: RangeRequestOptions): Promise<RangeResponse> {
|
|
242
242
|
const {
|
|
243
|
+
signal,
|
|
243
244
|
filters = this.props.filters,
|
|
244
245
|
filterOwner,
|
|
245
246
|
spatialFilter,
|
|
246
247
|
spatialFiltersMode,
|
|
247
248
|
spatialIndexReferenceViewState,
|
|
248
|
-
abortController,
|
|
249
249
|
...params
|
|
250
250
|
} = options;
|
|
251
251
|
const {column} = params;
|
|
@@ -267,18 +267,18 @@ export abstract class WidgetRemoteSource<
|
|
|
267
267
|
spatialFilter,
|
|
268
268
|
},
|
|
269
269
|
params: {column},
|
|
270
|
-
opts: {
|
|
270
|
+
opts: {signal, headers: this._headers},
|
|
271
271
|
}).then((res: RangeModelResponse) => normalizeObjectKeys(res.rows[0]));
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
async getScatter(options: ScatterRequestOptions): Promise<ScatterResponse> {
|
|
275
275
|
const {
|
|
276
|
+
signal,
|
|
276
277
|
filters = this.props.filters,
|
|
277
278
|
filterOwner,
|
|
278
279
|
spatialFilter,
|
|
279
280
|
spatialFiltersMode,
|
|
280
281
|
spatialIndexReferenceViewState,
|
|
281
|
-
abortController,
|
|
282
282
|
...params
|
|
283
283
|
} = options;
|
|
284
284
|
const {xAxisColumn, xAxisJoinOperation, yAxisColumn, yAxisJoinOperation} =
|
|
@@ -311,7 +311,7 @@ export abstract class WidgetRemoteSource<
|
|
|
311
311
|
yAxisJoinOperation,
|
|
312
312
|
limit: HARD_LIMIT,
|
|
313
313
|
},
|
|
314
|
-
opts: {
|
|
314
|
+
opts: {signal, headers: this._headers},
|
|
315
315
|
})
|
|
316
316
|
.then((res: ScatterModelResponse) => normalizeObjectKeys(res.rows))
|
|
317
317
|
.then((res) => res.map(({x, y}: {x: number; y: number}) => [x, y]));
|
|
@@ -319,12 +319,12 @@ export abstract class WidgetRemoteSource<
|
|
|
319
319
|
|
|
320
320
|
async getTable(options: TableRequestOptions): Promise<TableResponse> {
|
|
321
321
|
const {
|
|
322
|
+
signal,
|
|
322
323
|
filters = this.props.filters,
|
|
323
324
|
filterOwner,
|
|
324
325
|
spatialFilter,
|
|
325
326
|
spatialFiltersMode,
|
|
326
327
|
spatialIndexReferenceViewState,
|
|
327
|
-
abortController,
|
|
328
328
|
...params
|
|
329
329
|
} = options;
|
|
330
330
|
const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
|
|
@@ -355,7 +355,7 @@ export abstract class WidgetRemoteSource<
|
|
|
355
355
|
limit,
|
|
356
356
|
offset,
|
|
357
357
|
},
|
|
358
|
-
opts: {
|
|
358
|
+
opts: {signal, headers: this._headers},
|
|
359
359
|
}).then((res: TableModelResponse) => ({
|
|
360
360
|
// Avoid `normalizeObjectKeys()`, which changes column names.
|
|
361
361
|
rows: res.rows ?? (res as any).ROWS,
|
|
@@ -367,9 +367,9 @@ export abstract class WidgetRemoteSource<
|
|
|
367
367
|
options: TimeSeriesRequestOptions
|
|
368
368
|
): Promise<TimeSeriesResponse> {
|
|
369
369
|
const {
|
|
370
|
+
signal,
|
|
370
371
|
filters = this.props.filters,
|
|
371
372
|
filterOwner,
|
|
372
|
-
abortController,
|
|
373
373
|
spatialFilter,
|
|
374
374
|
spatialFiltersMode,
|
|
375
375
|
spatialIndexReferenceViewState,
|
|
@@ -418,7 +418,7 @@ export abstract class WidgetRemoteSource<
|
|
|
418
418
|
splitByCategoryLimit,
|
|
419
419
|
splitByCategoryValues,
|
|
420
420
|
},
|
|
421
|
-
opts: {
|
|
421
|
+
opts: {signal, headers: this._headers},
|
|
422
422
|
}).then((res: TimeSeriesModelResponse) => ({
|
|
423
423
|
rows: normalizeObjectKeys(res.rows),
|
|
424
424
|
categories: res.metadata?.categories,
|