@carto/api-client 0.4.1-alpha.0 → 0.4.1
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 +6 -0
- package/build/api/query.d.ts +1 -1
- package/build/api/request-with-parameters.d.ts +3 -1
- package/build/api-client.cjs +71 -231
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +88 -239
- package/build/api-client.modern.js.map +1 -1
- package/build/models/model.d.ts +1 -7
- package/build/sources/index.d.ts +1 -1
- package/build/sources/types.d.ts +175 -34
- package/build/utils.d.ts +1 -1
- package/build/widget-sources/types.d.ts +1 -8
- package/build/widget-sources/widget-base-source.d.ts +1 -0
- package/package.json +1 -1
- package/src/api/query.ts +4 -1
- package/src/api/request-with-parameters.ts +34 -4
- package/src/models/model.ts +24 -47
- package/src/sources/base-source.ts +4 -1
- package/src/sources/h3-query-source.ts +1 -7
- package/src/sources/h3-table-source.ts +1 -6
- package/src/sources/index.ts +5 -0
- package/src/sources/quadbin-query-source.ts +1 -6
- package/src/sources/quadbin-table-source.ts +1 -6
- package/src/sources/types.ts +200 -36
- package/src/sources/vector-query-source.ts +1 -4
- package/src/sources/vector-table-source.ts +1 -5
- package/src/utils.ts +1 -1
- package/src/widget-sources/types.ts +1 -9
- package/src/widget-sources/widget-base-source.ts +19 -185
- package/build/spatial-index.d.ts +0 -11
- package/src/spatial-index.ts +0 -119
|
@@ -56,12 +56,7 @@ export const quadbinTableSource = async function (
|
|
|
56
56
|
return baseSource<UrlParameters>('table', options, urlParameters).then(
|
|
57
57
|
(result) => ({
|
|
58
58
|
...(result as TilejsonResult),
|
|
59
|
-
widgetSource: new WidgetTableSource(
|
|
60
|
-
...options,
|
|
61
|
-
// NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
|
|
62
|
-
spatialDataColumn,
|
|
63
|
-
spatialDataType: 'quadbin',
|
|
64
|
-
}),
|
|
59
|
+
widgetSource: new WidgetTableSource(options),
|
|
65
60
|
})
|
|
66
61
|
);
|
|
67
62
|
};
|
package/src/sources/types.ts
CHANGED
|
@@ -49,31 +49,25 @@ export type SourceOptionalOptions = {
|
|
|
49
49
|
maxLengthURL?: number;
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
|
|
52
|
+
* By default, local in-memory caching is enabled.
|
|
55
53
|
*/
|
|
56
|
-
|
|
54
|
+
localCache?: LocalCacheOptions;
|
|
55
|
+
};
|
|
57
56
|
|
|
57
|
+
export type LocalCacheOptions = {
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Map that stores requests and their responses.
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
cache?: Map<string, Promise<unknown>>;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* Cache control
|
|
65
|
+
* * `no-cache`: If present, the source will always fetch from original source.
|
|
66
|
+
* * `no-store`: If present, source will not store result in cache (for later reuse).
|
|
67
67
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* - 0.25: 256x256
|
|
71
|
-
* - 0.5: 512x512
|
|
72
|
-
* - 1: 1024x1024
|
|
73
|
-
* - 2: 2048x2048
|
|
74
|
-
* - 4: 4096x4096
|
|
68
|
+
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#directives
|
|
75
69
|
*/
|
|
76
|
-
|
|
70
|
+
cacheControl?: ('no-cache' | 'no-store')[];
|
|
77
71
|
};
|
|
78
72
|
|
|
79
73
|
export type SourceOptions = SourceRequiredOptions &
|
|
@@ -95,11 +89,6 @@ export type AggregationOptions = {
|
|
|
95
89
|
* @default 6 for quadbin and 4 for h3 sources
|
|
96
90
|
*/
|
|
97
91
|
aggregationResLevel?: number;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Original resolution of the spatial index data as stored in the DW
|
|
101
|
-
*/
|
|
102
|
-
dataResolution?: number;
|
|
103
92
|
};
|
|
104
93
|
|
|
105
94
|
export type FilterOptions = {
|
|
@@ -110,9 +99,31 @@ export type FilterOptions = {
|
|
|
110
99
|
};
|
|
111
100
|
|
|
112
101
|
export type QuerySourceOptions = {
|
|
113
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* The column name and the type of geospatial support.
|
|
104
|
+
*
|
|
105
|
+
* If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
|
|
106
|
+
*/
|
|
107
|
+
spatialDataColumn?: string;
|
|
108
|
+
|
|
109
|
+
/** SQL query. */
|
|
114
110
|
sqlQuery: string;
|
|
115
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
|
|
114
|
+
* quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
|
|
115
|
+
* the quantization grid proportionately.
|
|
116
|
+
*
|
|
117
|
+
* Supported `tileResolution` values, with corresponding grid sizes:
|
|
118
|
+
*
|
|
119
|
+
* - 0.25: 256x256
|
|
120
|
+
* - 0.5: 512x512
|
|
121
|
+
* - 1: 1024x1024
|
|
122
|
+
* - 2: 2048x2048
|
|
123
|
+
* - 4: 4096x4096
|
|
124
|
+
*/
|
|
125
|
+
tileResolution?: TileResolution;
|
|
126
|
+
|
|
116
127
|
/**
|
|
117
128
|
* Values for named or positional paramteres in the query.
|
|
118
129
|
*
|
|
@@ -145,6 +156,28 @@ export type TableSourceOptions = {
|
|
|
145
156
|
* Fully qualified name of table.
|
|
146
157
|
*/
|
|
147
158
|
tableName: string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The column name and the type of geospatial support.
|
|
162
|
+
*
|
|
163
|
+
* If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
|
|
164
|
+
*/
|
|
165
|
+
spatialDataColumn?: string;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Relative resolution of a tile. Higher values increase density and data size. At `tileResolution = 1`, tile geometry is
|
|
169
|
+
* quantized to a 1024x1024 grid. Increasing or decreasing the resolution will increase or decrease the dimensions of
|
|
170
|
+
* the quantization grid proportionately.
|
|
171
|
+
*
|
|
172
|
+
* Supported `tileResolution` values, with corresponding grid sizes:
|
|
173
|
+
*
|
|
174
|
+
* - 0.25: 256x256
|
|
175
|
+
* - 0.5: 512x512
|
|
176
|
+
* - 1: 1024x1024
|
|
177
|
+
* - 2: 2048x2048
|
|
178
|
+
* - 4: 4096x4096
|
|
179
|
+
*/
|
|
180
|
+
tileResolution?: TileResolution;
|
|
148
181
|
};
|
|
149
182
|
|
|
150
183
|
export type TilesetSourceOptions = {
|
|
@@ -165,14 +198,6 @@ export type ColumnsOption = {
|
|
|
165
198
|
|
|
166
199
|
export type SpatialDataType = 'geo' | 'h3' | 'quadbin';
|
|
167
200
|
|
|
168
|
-
/**
|
|
169
|
-
* Strategy used for covering spatial filter geometry with spatial indexes.
|
|
170
|
-
* See https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/quadbin#quadbin_polyfill_mode
|
|
171
|
-
* or https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/h3#h3_polyfill_mode for more information.
|
|
172
|
-
* @internalRemarks Source: cloud-native maps-api
|
|
173
|
-
* */
|
|
174
|
-
export type SpatialFilterPolyfillMode = 'center' | 'intersects' | 'contains';
|
|
175
|
-
|
|
176
201
|
export type TilejsonMapInstantiation = MapInstantiation & {
|
|
177
202
|
tilejson: {url: string[]};
|
|
178
203
|
};
|
|
@@ -187,16 +212,51 @@ export interface Tilejson {
|
|
|
187
212
|
attribution: string;
|
|
188
213
|
scheme: string;
|
|
189
214
|
tiles: string[];
|
|
190
|
-
properties_tiles: string[];
|
|
191
|
-
minresolution: number;
|
|
192
|
-
maxresolution: number;
|
|
193
215
|
minzoom: number;
|
|
194
216
|
maxzoom: number;
|
|
195
|
-
bounds: [number, number, number, number];
|
|
196
|
-
center: [number, number, number];
|
|
217
|
+
bounds: [left: number, bottom: number, right: number, top: number];
|
|
218
|
+
center: [longitute: number, latitude: number, zoom: number];
|
|
197
219
|
vector_layers: VectorLayer[];
|
|
220
|
+
|
|
221
|
+
//
|
|
222
|
+
// Carto additions over standard Tilejson properties
|
|
223
|
+
//
|
|
224
|
+
|
|
225
|
+
minresolution: number;
|
|
226
|
+
maxresolution: number;
|
|
227
|
+
properties_tiles: string[];
|
|
198
228
|
tilestats: Tilestats;
|
|
199
229
|
tileResolution?: TileResolution;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Resolution of data in spatial-index dataset (e.g. H3, Quadbin).
|
|
233
|
+
*
|
|
234
|
+
* @internal
|
|
235
|
+
*/
|
|
236
|
+
dataresolution?: number;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Array of ratios of dropped features per zoom level.
|
|
240
|
+
*
|
|
241
|
+
* Example: `[0,0,0.5]` - means that 50% of features are dropped at zoom 2 and bigger.
|
|
242
|
+
*
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
fraction_dropped_per_zoom?: number[];
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Names of bands - rasters only.
|
|
249
|
+
*
|
|
250
|
+
* @internal
|
|
251
|
+
*/
|
|
252
|
+
raster_bands?: string[];
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Raster metadata - rasters only.
|
|
256
|
+
*
|
|
257
|
+
* @internal
|
|
258
|
+
*/
|
|
259
|
+
raster_metadata?: RasterMetadata;
|
|
200
260
|
}
|
|
201
261
|
|
|
202
262
|
export interface Tilestats {
|
|
@@ -217,12 +277,116 @@ export interface Attribute {
|
|
|
217
277
|
}
|
|
218
278
|
|
|
219
279
|
export interface VectorLayer {
|
|
280
|
+
// tilejson standard
|
|
220
281
|
id: string;
|
|
221
282
|
minzoom: number;
|
|
222
283
|
maxzoom: number;
|
|
223
284
|
fields: Record<string, string>;
|
|
285
|
+
|
|
286
|
+
// Carto additions over standard Tilejson properties
|
|
287
|
+
geometry_type?: string;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export type RasterMetadataBandStats = {
|
|
291
|
+
approximated_stats?: boolean;
|
|
292
|
+
min: number;
|
|
293
|
+
max: number;
|
|
294
|
+
mean: number;
|
|
295
|
+
stddev: number;
|
|
296
|
+
sum: number;
|
|
297
|
+
sum_squares: number;
|
|
298
|
+
count: number;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Quantiles by number of buckets.
|
|
302
|
+
*
|
|
303
|
+
* Example:
|
|
304
|
+
* ```ts
|
|
305
|
+
* {
|
|
306
|
+
* // for 3 buckets, first 1/3 of items lies in range [min, 20], second 1/3 is in [20, 40], and last 1/3 is in [40, max]
|
|
307
|
+
* 3: [20, 40],
|
|
308
|
+
* 4: [20, 30, 50], for 4 buckets ...
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
quantiles?: Record<number, number[]>;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Top values by number of values.
|
|
316
|
+
*
|
|
317
|
+
* Key of dictionary is value, value is count.
|
|
318
|
+
* Key order is random.
|
|
319
|
+
*
|
|
320
|
+
* Example:
|
|
321
|
+
* ```
|
|
322
|
+
* {
|
|
323
|
+
* 3: 5, // means there are 5 pixels with value 3
|
|
324
|
+
* 11: 222,
|
|
325
|
+
* 12: 333, // means that 12 is most common value with count 333
|
|
326
|
+
* ... // (assuming 333 was largest value in dict)
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
top_values?: Record<number, number>;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Raster loader version.
|
|
334
|
+
*/
|
|
335
|
+
version?: string;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export enum RasterBandColorinterp {
|
|
339
|
+
Gray = 'gray',
|
|
340
|
+
Red = 'red',
|
|
341
|
+
Green = 'green',
|
|
342
|
+
Blue = 'blue',
|
|
343
|
+
Alpha = 'alpha',
|
|
344
|
+
Palette = 'palette',
|
|
224
345
|
}
|
|
225
346
|
|
|
347
|
+
export type RasterMetadataBand = {
|
|
348
|
+
type: string;
|
|
349
|
+
name: string;
|
|
350
|
+
stats: RasterMetadataBandStats;
|
|
351
|
+
/**
|
|
352
|
+
* Known values:
|
|
353
|
+
* * `palette`: use unique value and `colortable` ad default mapping
|
|
354
|
+
* * `red`, `green`, `blue`: use the band as color channel
|
|
355
|
+
* * `gray`: use the band as grayscale
|
|
356
|
+
*/
|
|
357
|
+
colorinterp?: string | RasterBandColorinterp; // use RasterBandColorinterp, but it's external value, so let's use string
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Default color mapping for unique values (or if coloprinterp is `palette`)
|
|
361
|
+
*/
|
|
362
|
+
colortable?: Record<string, number[]>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* No value representation.
|
|
366
|
+
* Observed values:
|
|
367
|
+
* * `'nan'` for `NaN`
|
|
368
|
+
* * `number`: both as string as number, so parsing is needed
|
|
369
|
+
*/
|
|
370
|
+
nodata: string | number; // 255, '0', 'nan'
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
export type RasterMetadata = {
|
|
374
|
+
block_resolution: number;
|
|
375
|
+
minresolution: number;
|
|
376
|
+
maxresolution: number;
|
|
377
|
+
nodata: number | string;
|
|
378
|
+
bands: RasterMetadataBand[];
|
|
379
|
+
bounds: [left: number, bottom: number, right: number, top: number];
|
|
380
|
+
center: [longitute: number, latitude: number, zoom: number];
|
|
381
|
+
width: number;
|
|
382
|
+
height: number;
|
|
383
|
+
block_width: number;
|
|
384
|
+
block_height: number;
|
|
385
|
+
num_blocks: number;
|
|
386
|
+
num_pixels: number;
|
|
387
|
+
pixel_resolution: number;
|
|
388
|
+
};
|
|
389
|
+
|
|
226
390
|
export type TilejsonResult = Tilejson & {accessToken: string};
|
|
227
391
|
export type GeojsonResult = {type: 'FeatureCollection'; features: Feature[]};
|
|
228
392
|
export type JsonResult = any[];
|
|
@@ -64,10 +64,7 @@ export const vectorQuerySource = async function (
|
|
|
64
64
|
return baseSource<UrlParameters>('query', options, urlParameters).then(
|
|
65
65
|
(result) => ({
|
|
66
66
|
...(result as TilejsonResult),
|
|
67
|
-
widgetSource: new WidgetQuerySource(
|
|
68
|
-
...options,
|
|
69
|
-
spatialDataType: 'geo',
|
|
70
|
-
}),
|
|
67
|
+
widgetSource: new WidgetQuerySource(options),
|
|
71
68
|
})
|
|
72
69
|
);
|
|
73
70
|
};
|
|
@@ -22,7 +22,6 @@ export type VectorTableSourceOptions = SourceOptions &
|
|
|
22
22
|
TableSourceOptions &
|
|
23
23
|
FilterOptions &
|
|
24
24
|
ColumnsOption;
|
|
25
|
-
|
|
26
25
|
type UrlParameters = {
|
|
27
26
|
columns?: string;
|
|
28
27
|
filters?: Record<string, unknown>;
|
|
@@ -59,10 +58,7 @@ export const vectorTableSource = async function (
|
|
|
59
58
|
return baseSource<UrlParameters>('table', options, urlParameters).then(
|
|
60
59
|
(result) => ({
|
|
61
60
|
...(result as TilejsonResult),
|
|
62
|
-
widgetSource: new WidgetTableSource(
|
|
63
|
-
...options,
|
|
64
|
-
spatialDataType: 'geo',
|
|
65
|
-
}),
|
|
61
|
+
widgetSource: new WidgetTableSource(options),
|
|
66
62
|
})
|
|
67
63
|
);
|
|
68
64
|
};
|
package/src/utils.ts
CHANGED
|
@@ -57,7 +57,7 @@ export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** @internalRemarks Source: @carto/react-core */
|
|
60
|
-
export function assert(condition: unknown, message: string)
|
|
60
|
+
export function assert(condition: unknown, message: string) {
|
|
61
61
|
if (!condition) {
|
|
62
62
|
throw new Error(message);
|
|
63
63
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {TileResolution} from '../sources/types';
|
|
2
2
|
import {
|
|
3
3
|
GroupDateType,
|
|
4
4
|
SortColumnType,
|
|
@@ -10,19 +10,11 @@ import {
|
|
|
10
10
|
* WIDGET API REQUESTS
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export interface ViewState {
|
|
14
|
-
zoom: number;
|
|
15
|
-
latitude: number;
|
|
16
|
-
longitude: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
/** Common options for {@link WidgetBaseSource} requests. */
|
|
20
14
|
interface BaseRequestOptions {
|
|
21
15
|
spatialFilter?: SpatialFilter;
|
|
22
|
-
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
23
16
|
abortController?: AbortController;
|
|
24
17
|
filterOwner?: string;
|
|
25
|
-
viewState?: ViewState;
|
|
26
18
|
}
|
|
27
19
|
|
|
28
20
|
/** Options for {@link WidgetBaseSource#getCategories}. */
|