@carto/api-client 0.3.0 → 0.4.0-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.
- package/build/api/carto-api-error.d.ts +18 -0
- package/build/api/endpoints.d.ts +22 -0
- package/build/api/index.d.ts +4 -0
- package/build/api/query.d.ts +3 -0
- package/build/api/request-with-parameters.d.ts +8 -0
- package/build/api/types.d.ts +227 -0
- package/build/api-client.cjs +487 -24
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +423 -25
- package/build/api-client.modern.js.map +1 -1
- package/build/constants.d.ts +8 -0
- package/build/index.d.ts +6 -1
- package/build/sources/base-source.d.ts +4 -0
- package/build/sources/boundary-query-source.d.ts +9 -0
- package/build/sources/boundary-table-source.d.ts +7 -0
- package/build/sources/h3-query-source.d.ts +3 -0
- package/build/sources/h3-table-source.d.ts +3 -0
- package/build/sources/h3-tileset-source.d.ts +3 -0
- package/build/sources/index.d.ts +27 -5
- package/build/sources/quadbin-query-source.d.ts +3 -0
- package/build/sources/quadbin-table-source.d.ts +3 -0
- package/build/sources/quadbin-tileset-source.d.ts +3 -0
- package/build/sources/raster-source.d.ts +3 -0
- package/build/sources/types.d.ts +208 -85
- package/build/sources/vector-query-source.d.ts +3 -0
- package/build/sources/vector-table-source.d.ts +3 -0
- package/build/sources/vector-tileset-source.d.ts +3 -0
- package/build/utils.d.ts +4 -0
- package/build/widget-sources/index.d.ts +5 -0
- package/build/widget-sources/types.d.ts +95 -0
- package/build/{sources → widget-sources}/widget-base-source.d.ts +1 -1
- package/build/{sources → widget-sources}/widget-query-source.d.ts +1 -1
- package/build/{sources → widget-sources}/widget-table-source.d.ts +1 -1
- package/build/{sources → widget-sources}/wrappers.d.ts +1 -1
- package/package.json +4 -3
- package/src/api/carto-api-error.ts +72 -0
- package/src/api/endpoints.ts +82 -0
- package/src/api/index.ts +17 -0
- package/src/api/query.ts +56 -0
- package/src/api/request-with-parameters.ts +139 -0
- package/src/api/types.ts +301 -0
- package/src/constants.ts +13 -0
- package/src/global.d.ts +3 -0
- package/src/index.ts +10 -1
- package/src/sources/base-source.ts +100 -0
- package/src/sources/boundary-query-source.ts +53 -0
- package/src/sources/boundary-table-source.ts +41 -0
- package/src/sources/h3-query-source.ts +63 -0
- package/src/sources/h3-table-source.ts +59 -0
- package/src/sources/h3-tileset-source.ts +26 -0
- package/src/sources/index.ts +49 -5
- package/src/sources/quadbin-query-source.ts +64 -0
- package/src/sources/quadbin-table-source.ts +60 -0
- package/src/sources/quadbin-tileset-source.ts +26 -0
- package/src/sources/raster-source.ts +34 -0
- package/src/sources/types.ts +226 -90
- package/src/sources/vector-query-source.ts +65 -0
- package/src/sources/vector-table-source.ts +59 -0
- package/src/sources/vector-tileset-source.ts +26 -0
- package/src/utils.ts +8 -0
- package/src/widget-sources/index.ts +5 -0
- package/src/widget-sources/types.ts +105 -0
- package/src/{sources → widget-sources}/widget-base-source.ts +4 -3
- package/src/{sources → widget-sources}/widget-query-source.ts +1 -1
- package/src/{sources → widget-sources}/widget-table-source.ts +1 -1
- package/src/{sources → widget-sources}/wrappers.ts +1 -21
package/build/sources/types.d.ts
CHANGED
|
@@ -1,95 +1,218 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import type { Feature } from 'geojson';
|
|
2
|
+
import type { Filters, Format, MapInstantiation, QueryParameters } from '../api/types';
|
|
3
|
+
export type SourceRequiredOptions = {
|
|
4
|
+
/** Carto platform access token. */
|
|
5
|
+
accessToken: string;
|
|
6
|
+
/** Data warehouse connection name in Carto platform. */
|
|
7
|
+
connectionName: string;
|
|
8
|
+
};
|
|
9
|
+
export type SourceOptionalOptions = {
|
|
10
|
+
/**
|
|
11
|
+
* Base URL of the CARTO Maps API.
|
|
12
|
+
*
|
|
13
|
+
* Example for account located in EU-west region: `https://gcp-eu-west1.api.carto.com`
|
|
14
|
+
*
|
|
15
|
+
* @default https://gcp-us-east1.api.carto.com
|
|
16
|
+
*/
|
|
17
|
+
apiBaseUrl: string;
|
|
18
|
+
/**
|
|
19
|
+
* Custom HTTP headers added to map instantiation and data requests.
|
|
20
|
+
*/
|
|
21
|
+
headers: Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Cache buster value returned by map instantiation.
|
|
24
|
+
*
|
|
25
|
+
* Carto source saves `cache` value of map instantiation response in `cache.value`, so it can be used to
|
|
26
|
+
* check if underlying map data has changed between distinct source requests.
|
|
27
|
+
*/
|
|
28
|
+
cache?: {
|
|
29
|
+
value?: number;
|
|
30
|
+
};
|
|
31
|
+
clientId: string;
|
|
32
|
+
/** @deprecated use `query` instead **/
|
|
33
|
+
format: Format;
|
|
34
|
+
/**
|
|
35
|
+
* Maximum URL character length. Above this limit, requests use POST.
|
|
36
|
+
* Used to avoid browser and CDN limits.
|
|
37
|
+
* @default {@link DEFAULT_MAX_LENGTH_URL}
|
|
38
|
+
*/
|
|
39
|
+
maxLengthURL?: number;
|
|
40
|
+
};
|
|
41
|
+
export type SourceOptions = SourceRequiredOptions & Partial<SourceOptionalOptions>;
|
|
42
|
+
export type AggregationOptions = {
|
|
43
|
+
/**
|
|
44
|
+
* Defines the aggregation expressions that will be calculated from the resulting columns on each grid cell.
|
|
45
|
+
*
|
|
46
|
+
* Example:
|
|
47
|
+
*
|
|
48
|
+
* sum(pop) as total_population, avg(rev) as average_revenue
|
|
49
|
+
*/
|
|
50
|
+
aggregationExp: string;
|
|
51
|
+
/**
|
|
52
|
+
* Defines the tile aggregation resolution.
|
|
53
|
+
*
|
|
54
|
+
* @default 6 for quadbin and 4 for h3 sources
|
|
55
|
+
*/
|
|
56
|
+
aggregationResLevel?: number;
|
|
57
|
+
};
|
|
58
|
+
export type FilterOptions = {
|
|
59
|
+
/**
|
|
60
|
+
* Filters to apply to the data source on the server
|
|
61
|
+
*/
|
|
62
|
+
filters?: Filters;
|
|
63
|
+
};
|
|
64
|
+
export type QuerySourceOptions = {
|
|
65
|
+
/**
|
|
66
|
+
* The column name and the type of geospatial support.
|
|
67
|
+
*
|
|
68
|
+
* If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
|
|
69
|
+
*/
|
|
70
|
+
spatialDataColumn?: string;
|
|
71
|
+
/** SQL query. */
|
|
72
|
+
sqlQuery: string;
|
|
73
|
+
/**
|
|
74
|
+
* Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
|
|
75
|
+
* quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
|
|
76
|
+
* the quantization grid proportionately.
|
|
77
|
+
*
|
|
78
|
+
* Supported `tileResolution` values, with corresponding grid sizes:
|
|
79
|
+
*
|
|
80
|
+
* - 0.25: 256x256
|
|
81
|
+
* - 0.5: 512x512
|
|
82
|
+
* - 1: 1024x1024
|
|
83
|
+
* - 2: 2048x2048
|
|
84
|
+
* - 4: 4096x4096
|
|
85
|
+
*/
|
|
86
|
+
tileResolution?: TileResolution;
|
|
87
|
+
/**
|
|
88
|
+
* Values for named or positional paramteres in the query.
|
|
89
|
+
*
|
|
90
|
+
* The way query parameters are determined by data warehouse.
|
|
91
|
+
*
|
|
92
|
+
* * BigQuery has named query parameters, specified with a dictionary, and referenced by key (`@key`)
|
|
93
|
+
*
|
|
94
|
+
* ```
|
|
95
|
+
* sqlQuery: "SELECT * FROM carto-demo-data.demo_tables.retail_stores WHERE storetype = @type AND revenue > @minRevenue"
|
|
96
|
+
* queryParameters: { type: 'Supermarket', minRevenue: 1000000 }
|
|
97
|
+
* ```
|
|
98
|
+
* * Snowflake supports positional parameters, in the form `:1`, `:2`, etc.
|
|
99
|
+
*
|
|
100
|
+
* ```
|
|
101
|
+
* sqlQuery: "SELECT * FROM demo_db.public.import_retail_stores WHERE storetype = :2 AND revenue > :1
|
|
102
|
+
* queryParameters: [100000, "Supermarket"]
|
|
103
|
+
* ```
|
|
104
|
+
* * Postgres and Redhisft supports positional parameters, but in the form `$1`, `$2`, etc.
|
|
105
|
+
*
|
|
106
|
+
* ```
|
|
107
|
+
* sqlQuery: "SELECT * FROM carto_demo_data.demo_tables.retail_stores WHERE storetype = $2 AND revenue > $1
|
|
108
|
+
* queryParameters: [100000, "Supermarket"]
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
queryParameters?: QueryParameters;
|
|
112
|
+
};
|
|
113
|
+
export type TableSourceOptions = {
|
|
114
|
+
/**
|
|
115
|
+
* Fully qualified name of table.
|
|
116
|
+
*/
|
|
117
|
+
tableName: string;
|
|
118
|
+
/**
|
|
119
|
+
* The column name and the type of geospatial support.
|
|
120
|
+
*
|
|
121
|
+
* If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
|
|
122
|
+
*/
|
|
123
|
+
spatialDataColumn?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
|
|
126
|
+
* quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
|
|
127
|
+
* the quantization grid proportionately.
|
|
128
|
+
*
|
|
129
|
+
* Supported `tileResolution` values, with corresponding grid sizes:
|
|
130
|
+
*
|
|
131
|
+
* - 0.25: 256x256
|
|
132
|
+
* - 0.5: 512x512
|
|
133
|
+
* - 1: 1024x1024
|
|
134
|
+
* - 2: 2048x2048
|
|
135
|
+
* - 4: 4096x4096
|
|
136
|
+
*/
|
|
137
|
+
tileResolution?: TileResolution;
|
|
138
|
+
};
|
|
139
|
+
export type TilesetSourceOptions = {
|
|
140
|
+
/**
|
|
141
|
+
* Fully qualified name of tileset.
|
|
142
|
+
*/
|
|
143
|
+
tableName: string;
|
|
144
|
+
};
|
|
145
|
+
export type ColumnsOption = {
|
|
146
|
+
/**
|
|
147
|
+
* Columns to retrieve from the table.
|
|
148
|
+
*
|
|
149
|
+
* If not present, all columns are returned.
|
|
150
|
+
*/
|
|
151
|
+
columns?: string[];
|
|
152
|
+
};
|
|
153
|
+
export type SpatialDataType = 'geo' | 'h3' | 'quadbin';
|
|
154
|
+
export type TilejsonMapInstantiation = MapInstantiation & {
|
|
155
|
+
tilejson: {
|
|
156
|
+
url: string[];
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
export type TileResolution = 0.25 | 0.5 | 1 | 2 | 4;
|
|
160
|
+
export interface Tilejson {
|
|
161
|
+
tilejson: string;
|
|
162
|
+
name: string;
|
|
163
|
+
description: string;
|
|
164
|
+
version: string;
|
|
165
|
+
attribution: string;
|
|
166
|
+
scheme: string;
|
|
167
|
+
tiles: string[];
|
|
168
|
+
properties_tiles: string[];
|
|
169
|
+
minresolution: number;
|
|
170
|
+
maxresolution: number;
|
|
171
|
+
minzoom: number;
|
|
172
|
+
maxzoom: number;
|
|
173
|
+
bounds: [number, number, number, number];
|
|
174
|
+
center: [number, number, number];
|
|
175
|
+
vector_layers: VectorLayer[];
|
|
176
|
+
tilestats: Tilestats;
|
|
177
|
+
tileResolution?: TileResolution;
|
|
28
178
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
179
|
+
export interface Tilestats {
|
|
180
|
+
layerCount: number;
|
|
181
|
+
layers: Layer[];
|
|
32
182
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
183
|
+
export interface Layer {
|
|
184
|
+
layer: string;
|
|
185
|
+
count: number;
|
|
186
|
+
attributeCount: number;
|
|
187
|
+
attributes: Attribute[];
|
|
39
188
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sortBy?: string;
|
|
44
|
-
sortDirection?: SortDirection;
|
|
45
|
-
sortByColumnType?: SortColumnType;
|
|
46
|
-
offset?: number;
|
|
47
|
-
limit?: number;
|
|
189
|
+
export interface Attribute {
|
|
190
|
+
attribute: string;
|
|
191
|
+
type: string;
|
|
48
192
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
55
|
-
operationColumn?: string;
|
|
56
|
-
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
57
|
-
splitByCategory?: string;
|
|
58
|
-
splitByCategoryLimit?: number;
|
|
59
|
-
splitByCategoryValues?: string[];
|
|
193
|
+
export interface VectorLayer {
|
|
194
|
+
id: string;
|
|
195
|
+
minzoom: number;
|
|
196
|
+
maxzoom: number;
|
|
197
|
+
fields: Record<string, string>;
|
|
60
198
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*/
|
|
64
|
-
/** Response from {@link WidgetBaseSource#getFormula}. */
|
|
65
|
-
export type FormulaResponse = {
|
|
66
|
-
value: number;
|
|
67
|
-
};
|
|
68
|
-
/** Response from {@link WidgetBaseSource#getCategories}. */
|
|
69
|
-
export type CategoryResponse = {
|
|
70
|
-
name: string;
|
|
71
|
-
value: number;
|
|
72
|
-
}[];
|
|
73
|
-
/** Response from {@link WidgetBaseSource#getRange}. */
|
|
74
|
-
export type RangeResponse = {
|
|
75
|
-
min: number;
|
|
76
|
-
max: number;
|
|
199
|
+
export type TilejsonResult = Tilejson & {
|
|
200
|
+
accessToken: string;
|
|
77
201
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
rows: Record<string, number | string>[];
|
|
202
|
+
export type GeojsonResult = {
|
|
203
|
+
type: 'FeatureCollection';
|
|
204
|
+
features: Feature[];
|
|
82
205
|
};
|
|
83
|
-
|
|
84
|
-
export type
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
206
|
+
export type JsonResult = any[];
|
|
207
|
+
export type QueryResult = {
|
|
208
|
+
meta: {
|
|
209
|
+
cacheHit: boolean;
|
|
210
|
+
location: string;
|
|
211
|
+
totalBytesProcessed: string;
|
|
212
|
+
};
|
|
213
|
+
rows: Record<string, any>[];
|
|
214
|
+
schema: {
|
|
88
215
|
name: string;
|
|
89
|
-
|
|
216
|
+
type: string;
|
|
90
217
|
}[];
|
|
91
|
-
categories: string[];
|
|
92
218
|
};
|
|
93
|
-
/** Response from {@link WidgetBaseSource#getHistogram}. */
|
|
94
|
-
export type HistogramResponse = number[];
|
|
95
|
-
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FilterOptions, SourceOptions, QuerySourceOptions, TilejsonResult, ColumnsOption } from './types';
|
|
2
|
+
export type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption;
|
|
3
|
+
export declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<TilejsonResult>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FilterOptions, ColumnsOption, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
|
|
2
|
+
export type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption;
|
|
3
|
+
export declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<TilejsonResult>;
|
package/build/utils.d.ts
CHANGED
|
@@ -25,4 +25,8 @@ export declare class InvalidColumnError extends Error {
|
|
|
25
25
|
static is(error: unknown): boolean;
|
|
26
26
|
}
|
|
27
27
|
export declare function isEmptyObject(object: object): boolean;
|
|
28
|
+
/** @internal */
|
|
29
|
+
export declare const isObject: (x: unknown) => boolean;
|
|
30
|
+
/** @internal */
|
|
31
|
+
export declare const isPureObject: (x: any) => boolean;
|
|
28
32
|
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { GroupDateType, SortColumnType, SortDirection, SpatialFilter } from '../types';
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
* WIDGET API REQUESTS
|
|
4
|
+
*/
|
|
5
|
+
/** Common options for {@link WidgetBaseSource} requests. */
|
|
6
|
+
interface BaseRequestOptions {
|
|
7
|
+
spatialFilter?: SpatialFilter;
|
|
8
|
+
abortController?: AbortController;
|
|
9
|
+
filterOwner?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Options for {@link WidgetBaseSource#getCategories}. */
|
|
12
|
+
export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
13
|
+
column: string;
|
|
14
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
15
|
+
operationColumn?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
18
|
+
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
19
|
+
column: string;
|
|
20
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
21
|
+
operationExp?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Options for {@link WidgetBaseSource#getHistogram}. */
|
|
24
|
+
export interface HistogramRequestOptions extends BaseRequestOptions {
|
|
25
|
+
column: string;
|
|
26
|
+
ticks: number[];
|
|
27
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
28
|
+
}
|
|
29
|
+
/** Options for {@link WidgetBaseSource#getRange}. */
|
|
30
|
+
export interface RangeRequestOptions extends BaseRequestOptions {
|
|
31
|
+
column: string;
|
|
32
|
+
}
|
|
33
|
+
/** Options for {@link WidgetBaseSource#getScatter}. */
|
|
34
|
+
export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
35
|
+
xAxisColumn: string;
|
|
36
|
+
xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
37
|
+
yAxisColumn: string;
|
|
38
|
+
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
39
|
+
}
|
|
40
|
+
/** Options for {@link WidgetBaseSource#getTable}. */
|
|
41
|
+
export interface TableRequestOptions extends BaseRequestOptions {
|
|
42
|
+
columns: string[];
|
|
43
|
+
sortBy?: string;
|
|
44
|
+
sortDirection?: SortDirection;
|
|
45
|
+
sortByColumnType?: SortColumnType;
|
|
46
|
+
offset?: number;
|
|
47
|
+
limit?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Options for {@link WidgetBaseSource#getTimeSeries}. */
|
|
50
|
+
export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
51
|
+
column: string;
|
|
52
|
+
stepSize?: GroupDateType;
|
|
53
|
+
stepMultiplier?: number;
|
|
54
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
55
|
+
operationColumn?: string;
|
|
56
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
57
|
+
splitByCategory?: string;
|
|
58
|
+
splitByCategoryLimit?: number;
|
|
59
|
+
splitByCategoryValues?: string[];
|
|
60
|
+
}
|
|
61
|
+
/******************************************************************************
|
|
62
|
+
* WIDGET API RESPONSES
|
|
63
|
+
*/
|
|
64
|
+
/** Response from {@link WidgetBaseSource#getFormula}. */
|
|
65
|
+
export type FormulaResponse = {
|
|
66
|
+
value: number;
|
|
67
|
+
};
|
|
68
|
+
/** Response from {@link WidgetBaseSource#getCategories}. */
|
|
69
|
+
export type CategoryResponse = {
|
|
70
|
+
name: string;
|
|
71
|
+
value: number;
|
|
72
|
+
}[];
|
|
73
|
+
/** Response from {@link WidgetBaseSource#getRange}. */
|
|
74
|
+
export type RangeResponse = {
|
|
75
|
+
min: number;
|
|
76
|
+
max: number;
|
|
77
|
+
};
|
|
78
|
+
/** Response from {@link WidgetBaseSource#getTable}. */
|
|
79
|
+
export type TableResponse = {
|
|
80
|
+
totalCount: number;
|
|
81
|
+
rows: Record<string, number | string>[];
|
|
82
|
+
};
|
|
83
|
+
/** Response from {@link WidgetBaseSource#getScatter}. */
|
|
84
|
+
export type ScatterResponse = [number, number][];
|
|
85
|
+
/** Response from {@link WidgetBaseSource#getTimeSeries}. */
|
|
86
|
+
export type TimeSeriesResponse = {
|
|
87
|
+
rows: {
|
|
88
|
+
name: string;
|
|
89
|
+
value: number;
|
|
90
|
+
}[];
|
|
91
|
+
categories: string[];
|
|
92
|
+
};
|
|
93
|
+
/** Response from {@link WidgetBaseSource#getHistogram}. */
|
|
94
|
+
export type HistogramResponse = number[];
|
|
95
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CategoryRequestOptions, CategoryResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
|
|
2
2
|
import { FilterLogicalOperator, Filter } from '../types.js';
|
|
3
|
-
import { SourceOptions } from '@deck.gl/carto';
|
|
4
3
|
import { ApiVersion } from '../constants-internal.js';
|
|
5
4
|
import { ModelSource } from '../models/model.js';
|
|
5
|
+
import { SourceOptions } from '../sources/index.js';
|
|
6
6
|
export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
7
7
|
apiVersion?: ApiVersion;
|
|
8
8
|
geoColumn?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptions } from '
|
|
1
|
+
import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptions } from '../sources/index.js';
|
|
2
2
|
import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
|
|
3
3
|
import { ModelSource } from '../models/model.js';
|
|
4
4
|
type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptions } from '
|
|
1
|
+
import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptions } from '../sources/index.js';
|
|
2
2
|
import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
|
|
3
3
|
import { ModelSource } from '../models/model.js';
|
|
4
4
|
type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h3TableSource as _h3TableSource, h3QuerySource as _h3QuerySource, vectorTableSource as _vectorTableSource, vectorQuerySource as _vectorQuerySource, quadbinTableSource as _quadbinTableSource, quadbinQuerySource as _quadbinQuerySource, VectorTableSourceOptions as _VectorTableSourceOptions, VectorQuerySourceOptions as _VectorQuerySourceOptions, H3TableSourceOptions as _H3TableSourceOptions, H3QuerySourceOptions as _H3QuerySourceOptions, QuadbinTableSourceOptions as _QuadbinTableSourceOptions, QuadbinQuerySourceOptions as _QuadbinQuerySourceOptions } from '
|
|
1
|
+
import { h3TableSource as _h3TableSource, h3QuerySource as _h3QuerySource, vectorTableSource as _vectorTableSource, vectorQuerySource as _vectorQuerySource, quadbinTableSource as _quadbinTableSource, quadbinQuerySource as _quadbinQuerySource, VectorTableSourceOptions as _VectorTableSourceOptions, VectorQuerySourceOptions as _VectorQuerySourceOptions, H3TableSourceOptions as _H3TableSourceOptions, H3QuerySourceOptions as _H3QuerySourceOptions, QuadbinTableSourceOptions as _QuadbinTableSourceOptions, QuadbinQuerySourceOptions as _QuadbinQuerySourceOptions } from '../sources/index.js';
|
|
2
2
|
import { WidgetBaseSourceProps } from './widget-base-source.js';
|
|
3
3
|
import { WidgetQuerySource } from './widget-query-source.js';
|
|
4
4
|
import { WidgetTableSource } from './widget-table-source.js';
|
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.
|
|
7
|
+
"version": "0.4.0-alpha.0",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"LICENSE.md"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@deck.gl/carto": "^9.0.30",
|
|
56
55
|
"@turf/bbox-clip": "^7.1.0",
|
|
57
56
|
"@turf/bbox-polygon": "^7.1.0",
|
|
58
57
|
"@turf/helpers": "^7.1.0",
|
|
@@ -62,6 +61,7 @@
|
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
63
|
"@deck.gl/aggregation-layers": "^9.0.30",
|
|
64
|
+
"@deck.gl/carto": "^9.0.30",
|
|
65
65
|
"@deck.gl/core": "^9.0.30",
|
|
66
66
|
"@deck.gl/extensions": "^9.0.30",
|
|
67
67
|
"@deck.gl/geo-layers": "^9.0.30",
|
|
@@ -98,5 +98,6 @@
|
|
|
98
98
|
"vite": "^5.2.10",
|
|
99
99
|
"vitest": "1.6.0",
|
|
100
100
|
"vue": "^3.4.27"
|
|
101
|
-
}
|
|
101
|
+
},
|
|
102
|
+
"stableVersion": "0.3.1"
|
|
102
103
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// deck.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {APIErrorContext} from './types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* Custom error for reported errors in CARTO Maps API.
|
|
10
|
+
* Provides useful debugging information in console and context for applications.
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export class CartoAPIError extends Error {
|
|
14
|
+
/** Source error from server */
|
|
15
|
+
error: Error;
|
|
16
|
+
|
|
17
|
+
/** Context (API call & parameters) in which error occured */
|
|
18
|
+
errorContext: APIErrorContext;
|
|
19
|
+
|
|
20
|
+
/** Response from server */
|
|
21
|
+
response?: Response;
|
|
22
|
+
|
|
23
|
+
/** JSON Response from server */
|
|
24
|
+
responseJson?: any;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
error: Error,
|
|
28
|
+
errorContext: APIErrorContext,
|
|
29
|
+
response?: Response,
|
|
30
|
+
responseJson?: any
|
|
31
|
+
) {
|
|
32
|
+
let responseString = 'Failed to connect';
|
|
33
|
+
if (response) {
|
|
34
|
+
responseString = 'Server returned: ';
|
|
35
|
+
if (response.status === 400) {
|
|
36
|
+
responseString += 'Bad request';
|
|
37
|
+
} else if (response.status === 401 || response.status === 403) {
|
|
38
|
+
responseString += 'Unauthorized access';
|
|
39
|
+
} else if (response.status === 404) {
|
|
40
|
+
responseString += 'Not found';
|
|
41
|
+
} else {
|
|
42
|
+
responseString += 'Error';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
responseString += ` (${response.status}):`;
|
|
46
|
+
}
|
|
47
|
+
responseString += ` ${error.message || error}`;
|
|
48
|
+
|
|
49
|
+
let message = `${errorContext.requestType} API request failed`;
|
|
50
|
+
message += `\n${responseString}`;
|
|
51
|
+
for (const key of Object.keys(errorContext)) {
|
|
52
|
+
if (key === 'requestType') continue;
|
|
53
|
+
message += `\n${formatErrorKey(key)}: ${(errorContext as any)[key]}`;
|
|
54
|
+
}
|
|
55
|
+
message += '\n';
|
|
56
|
+
|
|
57
|
+
super(message);
|
|
58
|
+
|
|
59
|
+
this.name = 'CartoAPIError';
|
|
60
|
+
this.response = response;
|
|
61
|
+
this.responseJson = responseJson;
|
|
62
|
+
this.error = error;
|
|
63
|
+
this.errorContext = errorContext;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Converts camelCase to Camel Case
|
|
69
|
+
*/
|
|
70
|
+
function formatErrorKey(key: string) {
|
|
71
|
+
return key.replace(/([A-Z])/g, ' $1').replace(/^./, (s) => s.toUpperCase());
|
|
72
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// deck.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {MapType} from './types';
|
|
6
|
+
|
|
7
|
+
export type V3Endpoint = 'maps' | 'stats' | 'sql';
|
|
8
|
+
|
|
9
|
+
function joinPath(...args: string[]): string {
|
|
10
|
+
return args
|
|
11
|
+
.map((part) => (part.endsWith('/') ? part.slice(0, -1) : part))
|
|
12
|
+
.join('/');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function buildV3Path(
|
|
16
|
+
apiBaseUrl: string,
|
|
17
|
+
version: 'v3',
|
|
18
|
+
endpoint: V3Endpoint,
|
|
19
|
+
...rest: string[]
|
|
20
|
+
): string {
|
|
21
|
+
return joinPath(apiBaseUrl, version, endpoint, ...rest);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function buildPublicMapUrl({
|
|
25
|
+
apiBaseUrl,
|
|
26
|
+
cartoMapId,
|
|
27
|
+
}: {
|
|
28
|
+
apiBaseUrl: string;
|
|
29
|
+
cartoMapId: string;
|
|
30
|
+
}): string {
|
|
31
|
+
return buildV3Path(apiBaseUrl, 'v3', 'maps', 'public', cartoMapId);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function buildStatsUrl({
|
|
35
|
+
attribute,
|
|
36
|
+
apiBaseUrl,
|
|
37
|
+
connectionName,
|
|
38
|
+
source,
|
|
39
|
+
type,
|
|
40
|
+
}: {
|
|
41
|
+
attribute: string;
|
|
42
|
+
apiBaseUrl: string;
|
|
43
|
+
connectionName: string;
|
|
44
|
+
source: string;
|
|
45
|
+
type: MapType;
|
|
46
|
+
}): string {
|
|
47
|
+
if (type === 'query') {
|
|
48
|
+
return buildV3Path(apiBaseUrl, 'v3', 'stats', connectionName, attribute);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// type === 'table'
|
|
52
|
+
return buildV3Path(
|
|
53
|
+
apiBaseUrl,
|
|
54
|
+
'v3',
|
|
55
|
+
'stats',
|
|
56
|
+
connectionName,
|
|
57
|
+
source,
|
|
58
|
+
attribute
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function buildSourceUrl({
|
|
63
|
+
apiBaseUrl,
|
|
64
|
+
connectionName,
|
|
65
|
+
endpoint,
|
|
66
|
+
}: {
|
|
67
|
+
apiBaseUrl: string;
|
|
68
|
+
connectionName: string;
|
|
69
|
+
endpoint: MapType;
|
|
70
|
+
}): string {
|
|
71
|
+
return buildV3Path(apiBaseUrl, 'v3', 'maps', connectionName, endpoint);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function buildQueryUrl({
|
|
75
|
+
apiBaseUrl,
|
|
76
|
+
connectionName,
|
|
77
|
+
}: {
|
|
78
|
+
apiBaseUrl: string;
|
|
79
|
+
connectionName: string;
|
|
80
|
+
}): string {
|
|
81
|
+
return buildV3Path(apiBaseUrl, 'v3', 'sql', connectionName, 'query');
|
|
82
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// deck.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export {CartoAPIError} from './carto-api-error';
|
|
6
|
+
export type {
|
|
7
|
+
APIErrorContext,
|
|
8
|
+
Format,
|
|
9
|
+
MapType,
|
|
10
|
+
RequestType,
|
|
11
|
+
QueryParameters,
|
|
12
|
+
Basemap,
|
|
13
|
+
MapLibreBasemap,
|
|
14
|
+
GoogleBasemap,
|
|
15
|
+
} from './types';
|
|
16
|
+
export {query} from './query';
|
|
17
|
+
export type {QueryOptions} from './query';
|