@carto/api-client 0.5.13 → 0.5.14
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 +8 -0
- package/build/api-client.cjs +64 -8
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +19 -1
- package/build/api-client.d.ts +19 -1
- package/build/api-client.js +64 -8
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +4 -0
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +4 -0
- package/build/worker.js.map +1 -1
- package/package.json +3 -3
- package/src/sources/h3-tileset-source.ts +1 -0
- package/src/sources/quadbin-tileset-source.ts +1 -0
- package/src/sources/raster-source.ts +1 -0
- package/src/sources/vector-tileset-source.ts +1 -0
- package/src/widget-sources/types.ts +7 -0
- package/src/widget-sources/widget-remote-source.ts +64 -0
- package/src/widget-sources/widget-source.ts +5 -0
- package/src/widget-sources/widget-tileset-source-impl.ts +6 -0
- package/src/widget-sources/widget-tileset-source.ts +13 -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.
|
|
11
|
+
"version": "0.5.14",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
@@ -125,8 +125,8 @@
|
|
|
125
125
|
"tsup": "^8.3.6",
|
|
126
126
|
"typescript": "~5.8.2",
|
|
127
127
|
"typescript-eslint": "^8.26.1",
|
|
128
|
-
"vite": "^
|
|
129
|
-
"vitest": "3.2.
|
|
128
|
+
"vite": "^7.0.0",
|
|
129
|
+
"vitest": "3.2.4"
|
|
130
130
|
},
|
|
131
131
|
"resolutions": {
|
|
132
132
|
"@carto/api-client": "portal:./",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {BBox} from 'geojson';
|
|
1
2
|
import type {
|
|
2
3
|
SpatialFilterPolyfillMode,
|
|
3
4
|
TileResolution,
|
|
@@ -206,6 +207,9 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
|
206
207
|
splitByCategoryValues?: string[];
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
/** @experimental */
|
|
211
|
+
export type ExtentRequestOptions = BaseRequestOptions;
|
|
212
|
+
|
|
209
213
|
/******************************************************************************
|
|
210
214
|
* WIDGET API RESPONSES
|
|
211
215
|
*/
|
|
@@ -256,3 +260,6 @@ export type TimeSeriesResponse = {
|
|
|
256
260
|
|
|
257
261
|
/** Response from {@link WidgetRemoteSource#getHistogram}. */
|
|
258
262
|
export type HistogramResponse = number[];
|
|
263
|
+
|
|
264
|
+
/** @experimental */
|
|
265
|
+
export type ExtentResponse = {bbox: BBox};
|
|
@@ -2,6 +2,8 @@ import {executeModel, type ModelSource} from '../models/index.js';
|
|
|
2
2
|
import type {
|
|
3
3
|
CategoryRequestOptions,
|
|
4
4
|
CategoryResponse,
|
|
5
|
+
ExtentRequestOptions,
|
|
6
|
+
ExtentResponse,
|
|
5
7
|
FeaturesRequestOptions,
|
|
6
8
|
FeaturesResponse,
|
|
7
9
|
FormulaRequestOptions,
|
|
@@ -24,6 +26,8 @@ import type {Filters} from '../types.js';
|
|
|
24
26
|
import {AggregationTypes, ApiVersion} from '../constants.js';
|
|
25
27
|
import {getApplicableFilters} from '../filters.js';
|
|
26
28
|
import {OTHERS_CATEGORY_NAME} from './constants.js';
|
|
29
|
+
import {requestWithParameters} from '../api/request-with-parameters.js';
|
|
30
|
+
import type {APIErrorContext} from '../api/carto-api-error.js';
|
|
27
31
|
|
|
28
32
|
export type WidgetRemoteSourceProps = WidgetSourceProps;
|
|
29
33
|
|
|
@@ -389,4 +393,64 @@ export abstract class WidgetRemoteSource<
|
|
|
389
393
|
categories: res.metadata?.categories,
|
|
390
394
|
}));
|
|
391
395
|
}
|
|
396
|
+
|
|
397
|
+
/** @experimental */
|
|
398
|
+
async getExtent(options: ExtentRequestOptions = {}): Promise<ExtentResponse> {
|
|
399
|
+
const {signal, filters = this.props.filters, filterOwner} = options;
|
|
400
|
+
|
|
401
|
+
const {
|
|
402
|
+
type,
|
|
403
|
+
data,
|
|
404
|
+
apiBaseUrl,
|
|
405
|
+
apiVersion,
|
|
406
|
+
connectionName,
|
|
407
|
+
spatialDataColumn,
|
|
408
|
+
spatialDataType,
|
|
409
|
+
queryParameters,
|
|
410
|
+
} = this.getModelSource(filters, filterOwner);
|
|
411
|
+
|
|
412
|
+
assert(apiVersion === ApiVersion.V3, 'Stats API requires CARTO 3+');
|
|
413
|
+
|
|
414
|
+
let url: string;
|
|
415
|
+
|
|
416
|
+
const parameters: Record<string, unknown> = {filters, spatialDataType};
|
|
417
|
+
|
|
418
|
+
if (type === 'query') {
|
|
419
|
+
url = `${apiBaseUrl}/${apiVersion}/stats/${connectionName}/${spatialDataColumn}`;
|
|
420
|
+
parameters.q = data;
|
|
421
|
+
parameters.queryParameters = queryParameters;
|
|
422
|
+
} else {
|
|
423
|
+
url = `${apiBaseUrl}/${apiVersion}/stats/${connectionName}/${data}/${spatialDataColumn}`;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const headers = {
|
|
427
|
+
Authorization: `Bearer ${this.props.accessToken}`,
|
|
428
|
+
...this.props.headers,
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const errorContext: APIErrorContext = {
|
|
432
|
+
requestType: 'Tile stats',
|
|
433
|
+
connection: connectionName,
|
|
434
|
+
type: type,
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
type StatsResponse = {
|
|
438
|
+
extent: {
|
|
439
|
+
xmin: number;
|
|
440
|
+
ymin: number;
|
|
441
|
+
xmax: number;
|
|
442
|
+
ymax: number;
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
return requestWithParameters<StatsResponse>({
|
|
447
|
+
baseUrl: url,
|
|
448
|
+
headers,
|
|
449
|
+
signal,
|
|
450
|
+
errorContext,
|
|
451
|
+
parameters,
|
|
452
|
+
}).then(({extent: {xmin, ymin, xmax, ymax}}) => ({
|
|
453
|
+
bbox: [xmin, ymin, xmax, ymax],
|
|
454
|
+
}));
|
|
455
|
+
}
|
|
392
456
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CategoryRequestOptions,
|
|
3
3
|
CategoryResponse,
|
|
4
|
+
ExtentRequestOptions,
|
|
5
|
+
ExtentResponse,
|
|
4
6
|
FeaturesRequestOptions,
|
|
5
7
|
FeaturesResponse,
|
|
6
8
|
FormulaRequestOptions,
|
|
@@ -124,4 +126,7 @@ export abstract class WidgetSource<
|
|
|
124
126
|
abstract getTimeSeries(
|
|
125
127
|
options: TimeSeriesRequestOptions
|
|
126
128
|
): Promise<TimeSeriesResponse>;
|
|
129
|
+
|
|
130
|
+
/** @experimental */
|
|
131
|
+
abstract getExtent(options?: ExtentRequestOptions): Promise<ExtentResponse>;
|
|
127
132
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type {
|
|
3
3
|
CategoryRequestOptions,
|
|
4
4
|
CategoryResponse,
|
|
5
|
+
ExtentResponse,
|
|
5
6
|
FeaturesResponse,
|
|
6
7
|
FormulaRequestOptions,
|
|
7
8
|
FormulaResponse,
|
|
@@ -390,6 +391,11 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
|
|
|
390
391
|
};
|
|
391
392
|
}
|
|
392
393
|
|
|
394
|
+
/** @experimental */
|
|
395
|
+
async getExtent(): Promise<ExtentResponse> {
|
|
396
|
+
return Promise.reject(new Error('not implemented'));
|
|
397
|
+
}
|
|
398
|
+
|
|
393
399
|
/****************************************************************************
|
|
394
400
|
* INTERNAL
|
|
395
401
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CategoryRequestOptions,
|
|
3
3
|
CategoryResponse,
|
|
4
|
+
ExtentResponse,
|
|
4
5
|
FeaturesResponse,
|
|
5
6
|
FormulaRequestOptions,
|
|
6
7
|
FormulaResponse,
|
|
@@ -17,7 +18,7 @@ import type {
|
|
|
17
18
|
} from './types.js';
|
|
18
19
|
import type {SpatialFilter, Tile} from '../types.js';
|
|
19
20
|
import type {TileFeatureExtractOptions} from '../filters/index.js';
|
|
20
|
-
import type {FeatureCollection} from 'geojson';
|
|
21
|
+
import type {BBox, FeatureCollection} from 'geojson';
|
|
21
22
|
import {WidgetSource, type WidgetSourceProps} from './widget-source.js';
|
|
22
23
|
import {Method} from '../workers/constants.js';
|
|
23
24
|
import type {WorkerRequest, WorkerResponse} from '../workers/types.js';
|
|
@@ -29,6 +30,10 @@ export type WidgetTilesetSourceProps = WidgetSourceProps &
|
|
|
29
30
|
Omit<TilesetSourceOptions, 'filters'> & {
|
|
30
31
|
tileFormat: TileFormat;
|
|
31
32
|
spatialDataType: SpatialDataType;
|
|
33
|
+
/**
|
|
34
|
+
* Extent of spatial data, typically from TileJSON. Does not include filters.
|
|
35
|
+
*/
|
|
36
|
+
spatialDataBounds: BBox;
|
|
32
37
|
};
|
|
33
38
|
|
|
34
39
|
export type WidgetTilesetSourceResult = {widgetSource: WidgetTilesetSource};
|
|
@@ -320,4 +325,11 @@ export class WidgetTilesetSource<
|
|
|
320
325
|
}: RangeRequestOptions): Promise<RangeResponse> {
|
|
321
326
|
return this._executeWorkerMethod(Method.GET_RANGE, [options], signal);
|
|
322
327
|
}
|
|
328
|
+
|
|
329
|
+
/** @experimental */
|
|
330
|
+
async getExtent(): Promise<ExtentResponse> {
|
|
331
|
+
return Promise.resolve({
|
|
332
|
+
bbox: this.props.spatialDataBounds,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
323
335
|
}
|