@carto/api-client 0.5.0-alpha.6 → 0.5.0-alpha.8
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 +97 -111
- package/build/api-client.d.cts +69 -62
- package/build/api-client.d.ts +69 -62
- package/build/api-client.js +2130 -170
- package/build/worker.js +2119 -4
- package/package.json +5 -5
- package/src/models/common.ts +2 -2
- package/src/sources/h3-tileset-source.ts +1 -8
- package/src/sources/quadbin-tileset-source.ts +1 -8
- package/src/sources/vector-tileset-source.ts +1 -8
- package/src/widget-sources/index.ts +0 -1
- package/src/widget-sources/types.ts +1 -1
- package/src/widget-sources/widget-remote-source.ts +16 -16
- package/src/widget-sources/widget-source.ts +11 -0
- package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
- package/src/widget-sources/widget-tileset-source.ts +192 -331
- package/src/workers/widget-tileset-worker.ts +6 -3
- package/build/chunk-LEI5PI5X.js +0 -2063
- package/src/widget-sources/widget-tileset-worker-source.ts +0 -268
- package/src/workers/utils.ts +0 -33
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.8",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"access": "public",
|
|
15
|
-
"tag": "alpha"
|
|
16
|
-
},
|
|
17
13
|
"type": "module",
|
|
18
14
|
"sideEffects": false,
|
|
19
15
|
"exports": {
|
|
@@ -44,6 +40,7 @@
|
|
|
44
40
|
"test": "vitest run --typecheck",
|
|
45
41
|
"test:watch": "vitest watch --typecheck",
|
|
46
42
|
"coverage": "vitest run --coverage.enabled --coverage.all false",
|
|
43
|
+
"benchmark": "node scripts/benchmark.js",
|
|
47
44
|
"lint": "eslint .",
|
|
48
45
|
"format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --write",
|
|
49
46
|
"format:check": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --check",
|
|
@@ -90,6 +87,8 @@
|
|
|
90
87
|
"@luma.gl/core": "~9.1.0",
|
|
91
88
|
"@luma.gl/engine": "~9.1.0",
|
|
92
89
|
"@luma.gl/shadertools": "~9.1.0",
|
|
90
|
+
"@turf/buffer": "^7.2.0",
|
|
91
|
+
"@turf/random": "^7.2.0",
|
|
93
92
|
"@types/json-schema": "^7.0.15",
|
|
94
93
|
"@types/react": "^18.3.18",
|
|
95
94
|
"@types/semver": "^7.5.8",
|
|
@@ -105,6 +104,7 @@
|
|
|
105
104
|
"rimraf": "^6.0.1",
|
|
106
105
|
"semver": "^7.7.1",
|
|
107
106
|
"thenby": "^1.3.4",
|
|
107
|
+
"tinybench": "^3.1.1",
|
|
108
108
|
"tsup": "^8.3.6",
|
|
109
109
|
"typescript": "~5.7.3",
|
|
110
110
|
"typescript-eslint": "^8.24.0",
|
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();
|
|
@@ -6,9 +6,7 @@ import {getTileFormat} from '../utils/getTileFormat.js';
|
|
|
6
6
|
import {
|
|
7
7
|
WidgetTilesetSource,
|
|
8
8
|
WidgetTilesetSourceResult,
|
|
9
|
-
WidgetTilesetWorkerSource,
|
|
10
9
|
} from '../widget-sources/index.js';
|
|
11
|
-
import {isModuleWorkerSupported} from '../workers/utils.js';
|
|
12
10
|
import {baseSource} from './base-source.js';
|
|
13
11
|
import type {
|
|
14
12
|
SourceOptions,
|
|
@@ -28,15 +26,10 @@ export const h3TilesetSource = async function (
|
|
|
28
26
|
const {tableName, spatialDataColumn = 'h3'} = options;
|
|
29
27
|
const urlParameters: UrlParameters = {name: tableName};
|
|
30
28
|
|
|
31
|
-
const WidgetSourceClass =
|
|
32
|
-
options.widgetSourceWorker !== false && isModuleWorkerSupported()
|
|
33
|
-
? WidgetTilesetWorkerSource
|
|
34
|
-
: WidgetTilesetSource;
|
|
35
|
-
|
|
36
29
|
return baseSource<UrlParameters>('tileset', options, urlParameters).then(
|
|
37
30
|
(result) => ({
|
|
38
31
|
...(result as TilejsonResult),
|
|
39
|
-
widgetSource: new
|
|
32
|
+
widgetSource: new WidgetTilesetSource({
|
|
40
33
|
...options,
|
|
41
34
|
tileFormat: getTileFormat(result as TilejsonResult),
|
|
42
35
|
spatialDataColumn,
|
|
@@ -6,9 +6,7 @@ import {getTileFormat} from '../utils/getTileFormat.js';
|
|
|
6
6
|
import {
|
|
7
7
|
WidgetTilesetSource,
|
|
8
8
|
WidgetTilesetSourceResult,
|
|
9
|
-
WidgetTilesetWorkerSource,
|
|
10
9
|
} from '../widget-sources/index.js';
|
|
11
|
-
import {isModuleWorkerSupported} from '../workers/utils.js';
|
|
12
10
|
import {baseSource} from './base-source.js';
|
|
13
11
|
import type {
|
|
14
12
|
SourceOptions,
|
|
@@ -28,15 +26,10 @@ export const quadbinTilesetSource = async function (
|
|
|
28
26
|
const {tableName, spatialDataColumn = 'quadbin'} = options;
|
|
29
27
|
const urlParameters: UrlParameters = {name: tableName};
|
|
30
28
|
|
|
31
|
-
const WidgetSourceClass =
|
|
32
|
-
options.widgetSourceWorker !== false && isModuleWorkerSupported()
|
|
33
|
-
? WidgetTilesetWorkerSource
|
|
34
|
-
: WidgetTilesetSource;
|
|
35
|
-
|
|
36
29
|
return baseSource<UrlParameters>('tileset', options, urlParameters).then(
|
|
37
30
|
(result) => ({
|
|
38
31
|
...(result as TilejsonResult),
|
|
39
|
-
widgetSource: new
|
|
32
|
+
widgetSource: new WidgetTilesetSource({
|
|
40
33
|
...options,
|
|
41
34
|
tileFormat: getTileFormat(result as TilejsonResult),
|
|
42
35
|
spatialDataColumn,
|
|
@@ -7,9 +7,7 @@ import {getTileFormat} from '../utils/getTileFormat.js';
|
|
|
7
7
|
import {
|
|
8
8
|
WidgetTilesetSource,
|
|
9
9
|
WidgetTilesetSourceResult,
|
|
10
|
-
WidgetTilesetWorkerSource,
|
|
11
10
|
} from '../widget-sources/index.js';
|
|
12
|
-
import {isModuleWorkerSupported} from '../workers/utils.js';
|
|
13
11
|
import {baseSource} from './base-source.js';
|
|
14
12
|
import type {
|
|
15
13
|
SourceOptions,
|
|
@@ -29,15 +27,10 @@ export const vectorTilesetSource = async function (
|
|
|
29
27
|
const {tableName, spatialDataColumn = DEFAULT_GEO_COLUMN} = options;
|
|
30
28
|
const urlParameters: UrlParameters = {name: tableName};
|
|
31
29
|
|
|
32
|
-
const WidgetSourceClass =
|
|
33
|
-
options.widgetSourceWorker !== false && isModuleWorkerSupported()
|
|
34
|
-
? WidgetTilesetWorkerSource
|
|
35
|
-
: WidgetTilesetSource;
|
|
36
|
-
|
|
37
30
|
return baseSource<UrlParameters>('tileset', options, urlParameters).then(
|
|
38
31
|
(result) => ({
|
|
39
32
|
...(result as TilejsonResult),
|
|
40
|
-
widgetSource: new
|
|
33
|
+
widgetSource: new WidgetTilesetSource({
|
|
41
34
|
...options,
|
|
42
35
|
tileFormat: getTileFormat(result as TilejsonResult),
|
|
43
36
|
spatialDataColumn,
|
|
@@ -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,
|
|
@@ -50,6 +50,17 @@ export abstract class WidgetSource<Props extends WidgetSourceProps> {
|
|
|
50
50
|
this.props = {...WidgetSource.defaultProps, ...props};
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Destroys the widget source and releases allocated resources.
|
|
55
|
+
*
|
|
56
|
+
* For remote sources (tables, queries) this has no effect, but for local
|
|
57
|
+
* sources (tilesets, rasters) these resources will affect performance
|
|
58
|
+
* and stability if many (10+) sources are created and not released.
|
|
59
|
+
*/
|
|
60
|
+
destroy() {
|
|
61
|
+
// no-op in most cases, but required for worker sources.
|
|
62
|
+
}
|
|
63
|
+
|
|
53
64
|
protected _getSpatialFiltersResolution(
|
|
54
65
|
source: Omit<ModelSource, 'type' | 'data'>,
|
|
55
66
|
spatialFilter?: SpatialFilter,
|