@carto/api-client 0.4.0-alpha.5 → 0.4.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.
- package/CHANGELOG.md +8 -0
- package/build/api-client.cjs +72 -15
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +64 -12
- package/build/api-client.modern.js.map +1 -1
- package/build/models/model.d.ts +1 -1
- package/build/widget-sources/types.d.ts +46 -0
- package/build/widget-sources/widget-base-source.d.ts +13 -1
- package/package.json +3 -4
- package/src/models/model.ts +14 -5
- package/src/widget-sources/types.ts +51 -0
- package/src/widget-sources/widget-base-source.ts +43 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TileResolution } from '../sources/types';
|
|
1
2
|
import { GroupDateType, SortColumnType, SortDirection, SpatialFilter } from '../types';
|
|
2
3
|
/******************************************************************************
|
|
3
4
|
* WIDGET API REQUESTS
|
|
@@ -14,6 +15,43 @@ export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
|
14
15
|
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
15
16
|
operationColumn?: string;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for {@link WidgetBaseSource#getFeatures}.
|
|
20
|
+
* @experimental
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export interface FeaturesRequestOptions extends BaseRequestOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Feature IDs, as found in `_carto_feature_id`. Feature IDs are a hash
|
|
26
|
+
* of geometry, and features with identical geometry will have the same
|
|
27
|
+
* feature ID. Order is important; features in the result set will be
|
|
28
|
+
* sorted according to the order of IDs in the request.
|
|
29
|
+
*/
|
|
30
|
+
featureIds: string[];
|
|
31
|
+
/**
|
|
32
|
+
* Columns to be returned for each picked object. Note that for datasets
|
|
33
|
+
* containing features with identical geometry, more than one result per
|
|
34
|
+
* requested feature ID may be returned. To match results back to the
|
|
35
|
+
* requested feature ID, include `_carto_feature_id` in the columns list.
|
|
36
|
+
*/
|
|
37
|
+
columns: string[];
|
|
38
|
+
/** Topology of objects to be picked. */
|
|
39
|
+
dataType: 'points' | 'lines' | 'polygons';
|
|
40
|
+
/** Zoom level, required if using 'points' data type. */
|
|
41
|
+
z?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Maximum number of objects to return in the result set. For datasets
|
|
44
|
+
* containing features with identical geometry, those features will have
|
|
45
|
+
* the same feature IDs, and so more results may be returned than feature IDs
|
|
46
|
+
* given in the request.
|
|
47
|
+
*/
|
|
48
|
+
limit?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Must match `tileResolution` used when obtaining the `_carto_feature_id`
|
|
51
|
+
* column, typically in a layer's tile requests.
|
|
52
|
+
*/
|
|
53
|
+
tileResolution?: TileResolution;
|
|
54
|
+
}
|
|
17
55
|
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
18
56
|
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
19
57
|
column: string;
|
|
@@ -61,6 +99,14 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
|
61
99
|
/******************************************************************************
|
|
62
100
|
* WIDGET API RESPONSES
|
|
63
101
|
*/
|
|
102
|
+
/**
|
|
103
|
+
* Response from {@link WidgetBaseSource#getFeatures}.
|
|
104
|
+
* @experimental
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export type FeaturesResponse = {
|
|
108
|
+
rows: Record<string, unknown>[];
|
|
109
|
+
};
|
|
64
110
|
/** Response from {@link WidgetBaseSource#getFormula}. */
|
|
65
111
|
export type FormulaResponse = {
|
|
66
112
|
value: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CategoryRequestOptions, CategoryResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
|
|
1
|
+
import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
|
|
2
2
|
import { FilterLogicalOperator, Filter } from '../types.js';
|
|
3
3
|
import { ModelSource } from '../models/model.js';
|
|
4
4
|
import { SourceOptions } from '../sources/index.js';
|
|
@@ -35,6 +35,18 @@ export declare abstract class WidgetBaseSource<Props extends WidgetBaseSourcePro
|
|
|
35
35
|
* charts including grouped bar charts, pie charts, and tree charts.
|
|
36
36
|
*/
|
|
37
37
|
getCategories(options: CategoryRequestOptions): Promise<CategoryResponse>;
|
|
38
|
+
/****************************************************************************
|
|
39
|
+
* FEATURES
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
43
|
+
* matching features. In datasets containing features with duplicate geometries,
|
|
44
|
+
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
45
|
+
* results may be returned than IDs in the request.
|
|
46
|
+
* @internal
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
|
+
getFeatures(options: FeaturesRequestOptions): Promise<FeaturesResponse>;
|
|
38
50
|
/****************************************************************************
|
|
39
51
|
* FORMULA
|
|
40
52
|
*/
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"repository": "github:CartoDB/carto-api-client",
|
|
5
5
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
6
6
|
"packageManager": "yarn@4.3.1",
|
|
7
|
-
"version": "0.4.0
|
|
7
|
+
"version": "0.4.0",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
|
|
35
35
|
"test": "vitest run --typecheck",
|
|
36
36
|
"test:watch": "vitest watch --typecheck",
|
|
37
|
-
"coverage": "vitest run --coverage",
|
|
37
|
+
"coverage": "vitest run --coverage.enabled --coverage.all false",
|
|
38
38
|
"lint": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --check",
|
|
39
39
|
"format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write",
|
|
40
40
|
"clean": "rimraf build/*",
|
|
@@ -98,6 +98,5 @@
|
|
|
98
98
|
"vite": "^5.2.10",
|
|
99
99
|
"vitest": "1.6.0",
|
|
100
100
|
"vue": "^3.4.27"
|
|
101
|
-
}
|
|
102
|
-
"stableVersion": "0.3.1"
|
|
101
|
+
}
|
|
103
102
|
}
|
package/src/models/model.ts
CHANGED
|
@@ -16,6 +16,7 @@ const AVAILABLE_MODELS = [
|
|
|
16
16
|
'category',
|
|
17
17
|
'histogram',
|
|
18
18
|
'formula',
|
|
19
|
+
'pick',
|
|
19
20
|
'timeseries',
|
|
20
21
|
'range',
|
|
21
22
|
'scatterplot',
|
|
@@ -74,7 +75,13 @@ export function executeModel(props: {
|
|
|
74
75
|
|
|
75
76
|
let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
|
|
76
77
|
|
|
77
|
-
const {
|
|
78
|
+
const {
|
|
79
|
+
data,
|
|
80
|
+
filters,
|
|
81
|
+
filtersLogicalOperator = 'and',
|
|
82
|
+
geoColumn = DEFAULT_GEO_COLUMN,
|
|
83
|
+
} = source;
|
|
84
|
+
|
|
78
85
|
const queryParameters = source.queryParameters
|
|
79
86
|
? JSON.stringify(source.queryParameters)
|
|
80
87
|
: '';
|
|
@@ -89,12 +96,14 @@ export function executeModel(props: {
|
|
|
89
96
|
filtersLogicalOperator,
|
|
90
97
|
};
|
|
91
98
|
|
|
99
|
+
// Picking Model API requires 'spatialDataColumn'.
|
|
100
|
+
if (model === 'pick') {
|
|
101
|
+
queryParams.spatialDataColumn = geoColumn;
|
|
102
|
+
}
|
|
103
|
+
|
|
92
104
|
// API supports multiple filters, we apply it only to geoColumn
|
|
93
105
|
const spatialFilters = source.spatialFilter
|
|
94
|
-
? {
|
|
95
|
-
[source.geoColumn ? source.geoColumn : DEFAULT_GEO_COLUMN]:
|
|
96
|
-
source.spatialFilter,
|
|
97
|
-
}
|
|
106
|
+
? {[geoColumn]: source.spatialFilter}
|
|
98
107
|
: undefined;
|
|
99
108
|
|
|
100
109
|
if (spatialFilters) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {TileResolution} from '../sources/types';
|
|
1
2
|
import {
|
|
2
3
|
GroupDateType,
|
|
3
4
|
SortColumnType,
|
|
@@ -23,6 +24,49 @@ export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
|
23
24
|
operationColumn?: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Options for {@link WidgetBaseSource#getFeatures}.
|
|
29
|
+
* @experimental
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export interface FeaturesRequestOptions extends BaseRequestOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Feature IDs, as found in `_carto_feature_id`. Feature IDs are a hash
|
|
35
|
+
* of geometry, and features with identical geometry will have the same
|
|
36
|
+
* feature ID. Order is important; features in the result set will be
|
|
37
|
+
* sorted according to the order of IDs in the request.
|
|
38
|
+
*/
|
|
39
|
+
featureIds: string[];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Columns to be returned for each picked object. Note that for datasets
|
|
43
|
+
* containing features with identical geometry, more than one result per
|
|
44
|
+
* requested feature ID may be returned. To match results back to the
|
|
45
|
+
* requested feature ID, include `_carto_feature_id` in the columns list.
|
|
46
|
+
*/
|
|
47
|
+
columns: string[];
|
|
48
|
+
|
|
49
|
+
/** Topology of objects to be picked. */
|
|
50
|
+
dataType: 'points' | 'lines' | 'polygons';
|
|
51
|
+
|
|
52
|
+
/** Zoom level, required if using 'points' data type. */
|
|
53
|
+
z?: number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Maximum number of objects to return in the result set. For datasets
|
|
57
|
+
* containing features with identical geometry, those features will have
|
|
58
|
+
* the same feature IDs, and so more results may be returned than feature IDs
|
|
59
|
+
* given in the request.
|
|
60
|
+
*/
|
|
61
|
+
limit?: number;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Must match `tileResolution` used when obtaining the `_carto_feature_id`
|
|
65
|
+
* column, typically in a layer's tile requests.
|
|
66
|
+
*/
|
|
67
|
+
tileResolution?: TileResolution;
|
|
68
|
+
}
|
|
69
|
+
|
|
26
70
|
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
27
71
|
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
28
72
|
column: string;
|
|
@@ -77,6 +121,13 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
|
77
121
|
* WIDGET API RESPONSES
|
|
78
122
|
*/
|
|
79
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Response from {@link WidgetBaseSource#getFeatures}.
|
|
126
|
+
* @experimental
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export type FeaturesResponse = {rows: Record<string, unknown>[]};
|
|
130
|
+
|
|
80
131
|
/** Response from {@link WidgetBaseSource#getFormula}. */
|
|
81
132
|
export type FormulaResponse = {value: number};
|
|
82
133
|
|
|
@@ -2,6 +2,8 @@ import {executeModel} from '../models/index.js';
|
|
|
2
2
|
import {
|
|
3
3
|
CategoryRequestOptions,
|
|
4
4
|
CategoryResponse,
|
|
5
|
+
FeaturesRequestOptions,
|
|
6
|
+
FeaturesResponse,
|
|
5
7
|
FormulaRequestOptions,
|
|
6
8
|
FormulaResponse,
|
|
7
9
|
HistogramRequestOptions,
|
|
@@ -21,7 +23,10 @@ import {getClient} from '../client.js';
|
|
|
21
23
|
import {ModelSource} from '../models/model.js';
|
|
22
24
|
import {SourceOptions} from '../sources/index.js';
|
|
23
25
|
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
24
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_GEO_COLUMN,
|
|
28
|
+
DEFAULT_TILE_RESOLUTION,
|
|
29
|
+
} from '../constants-internal.js';
|
|
25
30
|
|
|
26
31
|
export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
27
32
|
apiVersion?: ApiVersion;
|
|
@@ -105,6 +110,43 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
105
110
|
}).then((res: CategoriesModelResponse) => normalizeObjectKeys(res.rows));
|
|
106
111
|
}
|
|
107
112
|
|
|
113
|
+
/****************************************************************************
|
|
114
|
+
* FEATURES
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Given a list of feature IDs (as found in `_carto_feature_id`) returns all
|
|
119
|
+
* matching features. In datasets containing features with duplicate geometries,
|
|
120
|
+
* feature IDs may be duplicated (IDs are a hash of geometry) and so more
|
|
121
|
+
* results may be returned than IDs in the request.
|
|
122
|
+
* @internal
|
|
123
|
+
* @experimental
|
|
124
|
+
*/
|
|
125
|
+
async getFeatures(
|
|
126
|
+
options: FeaturesRequestOptions
|
|
127
|
+
): Promise<FeaturesResponse> {
|
|
128
|
+
const {filterOwner, spatialFilter, abortController, ...params} = options;
|
|
129
|
+
const {columns, dataType, featureIds, z, limit, tileResolution} = params;
|
|
130
|
+
|
|
131
|
+
type FeaturesModelResponse = {rows: Record<string, unknown>[]};
|
|
132
|
+
|
|
133
|
+
return executeModel({
|
|
134
|
+
model: 'pick',
|
|
135
|
+
source: {...this.getModelSource(filterOwner), spatialFilter},
|
|
136
|
+
params: {
|
|
137
|
+
columns,
|
|
138
|
+
dataType,
|
|
139
|
+
featureIds,
|
|
140
|
+
z,
|
|
141
|
+
limit: limit || 1000,
|
|
142
|
+
tileResolution: tileResolution || DEFAULT_TILE_RESOLUTION,
|
|
143
|
+
},
|
|
144
|
+
opts: {abortController},
|
|
145
|
+
}).then((res: FeaturesModelResponse) => ({
|
|
146
|
+
rows: normalizeObjectKeys(res.rows),
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
|
|
108
150
|
/****************************************************************************
|
|
109
151
|
* FORMULA
|
|
110
152
|
*/
|