@carto/api-client 0.5.0-alpha.0 → 0.5.0-alpha.2

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.
@@ -1,5 +1,5 @@
1
1
  export { SOURCE_DEFAULTS } from './base-source';
2
- export type { GeojsonResult, JsonResult, QueryResult, QuerySourceOptions, RasterBandColorinterp, RasterMetadata, RasterMetadataBand, RasterMetadataBandStats, SourceOptions, TableSourceOptions, TilejsonResult, TilesetSourceOptions, VectorLayer, } from './types';
2
+ export type { GeojsonResult, JsonResult, QueryResult, QuerySourceOptions, RasterBandColorinterp, RasterMetadata, RasterMetadataBand, RasterMetadataBandStats, SourceOptions, SpatialFilterPolyfillMode, TableSourceOptions, TilejsonResult, TileResolution, TilesetSourceOptions, VectorLayer, } from './types';
3
3
  export { boundaryQuerySource } from './boundary-query-source';
4
4
  export type { BoundaryQuerySourceOptions, BoundaryQuerySourceResponse, } from './boundary-query-source';
5
5
  export { boundaryTableSource } from './boundary-table-source';
@@ -1,3 +1,4 @@
1
+ export * from './widget-source.js';
1
2
  export * from './widget-query-source.js';
2
3
  export * from './widget-remote-source.js';
3
4
  export * from './widget-table-source.js';
@@ -2,7 +2,7 @@ import { TilesetSourceOptions } from '../sources/index.js';
2
2
  import type { ModelSource } from '../models/index.js';
3
3
  import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
4
4
  import { TileFormat } from '../constants.js';
5
- import { SpatialFilter, Tile } from '../types.js';
5
+ import { SpatialFilter } from '../types.js';
6
6
  import { TileFeatureExtractOptions } from '../filters/index.js';
7
7
  import { FeatureCollection } from 'geojson';
8
8
  import { SpatialDataType } from '../sources/types.js';
@@ -37,11 +37,20 @@ export type WidgetTilesetSourceResult = {
37
37
  * ```
38
38
  */
39
39
  export declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
40
+ private _tiles;
40
41
  private _features;
41
42
  protected getModelSource(owner: string): ModelSource;
42
- /** Loads features as a list of tiles (typically provided by deck.gl). */
43
- loadTiles({ tiles, spatialFilter, uniqueIdProperty, options, }: {
44
- tiles: Tile[];
43
+ /**
44
+ * Loads features as a list of tiles (typically provided by deck.gl).
45
+ * After tiles are loaded, {@link extractTileFeatures} must be called
46
+ * before computing statistics on the tiles.
47
+ */
48
+ loadTiles(tiles: unknown[]): void;
49
+ /**
50
+ * Extracts feature data from tiles previously loaded with {@link loadTiles}.
51
+ * Must be called before computing statistics on tiles.
52
+ */
53
+ extractTileFeatures({ spatialFilter, uniqueIdProperty, options, }: {
45
54
  spatialFilter: SpatialFilter;
46
55
  uniqueIdProperty?: string;
47
56
  options?: TileFeatureExtractOptions;
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.5.0-alpha.0",
7
+ "version": "0.5.0-alpha.2",
8
8
  "license": "MIT",
9
9
  "publishConfig": {
10
10
  "access": "public",
@@ -99,5 +99,5 @@
99
99
  "resolutions": {
100
100
  "rollup": "^4.20.0"
101
101
  },
102
- "stableVersion": "0.4.4"
102
+ "stableVersion": "0.4.5"
103
103
  }
@@ -47,6 +47,7 @@ export const boundaryQuerySource = async function (
47
47
  if (queryParameters) {
48
48
  urlParameters.queryParameters = queryParameters;
49
49
  }
50
+
50
51
  return baseSource<UrlParameters>(
51
52
  'boundary',
52
53
  options,
@@ -35,6 +35,7 @@ export const boundaryTableSource = async function (
35
35
  if (filters) {
36
36
  urlParameters.filters = filters;
37
37
  }
38
+
38
39
  return baseSource<UrlParameters>(
39
40
  'boundary',
40
41
  options,
@@ -43,10 +43,13 @@ export const h3QuerySource = async function (
43
43
  queryParameters,
44
44
  filters,
45
45
  } = options;
46
+
47
+ const spatialDataType = 'h3';
48
+
46
49
  const urlParameters: UrlParameters = {
47
50
  aggregationExp,
48
51
  spatialDataColumn,
49
- spatialDataType: 'h3',
52
+ spatialDataType,
50
53
  q: sqlQuery,
51
54
  };
52
55
 
@@ -59,14 +62,15 @@ export const h3QuerySource = async function (
59
62
  if (filters) {
60
63
  urlParameters.filters = filters;
61
64
  }
65
+
62
66
  return baseSource<UrlParameters>('query', options, urlParameters).then(
63
67
  (result) => ({
64
68
  ...(result as TilejsonResult),
65
69
  widgetSource: new WidgetQuerySource({
66
70
  ...options,
67
- // NOTE: passing redundant spatialDataColumn here to apply the default value 'h3'
71
+ // NOTE: Parameters with default values above must be explicitly passed here.
68
72
  spatialDataColumn,
69
- spatialDataType: 'h3',
73
+ spatialDataType,
70
74
  }),
71
75
  })
72
76
  );
@@ -41,11 +41,14 @@ export const h3TableSource = async function (
41
41
  tableName,
42
42
  filters,
43
43
  } = options;
44
+
45
+ const spatialDataType = 'h3';
46
+
44
47
  const urlParameters: UrlParameters = {
45
48
  aggregationExp,
46
49
  name: tableName,
47
50
  spatialDataColumn,
48
- spatialDataType: 'h3',
51
+ spatialDataType,
49
52
  };
50
53
 
51
54
  if (aggregationResLevel) {
@@ -54,14 +57,15 @@ export const h3TableSource = async function (
54
57
  if (filters) {
55
58
  urlParameters.filters = filters;
56
59
  }
60
+
57
61
  return baseSource<UrlParameters>('table', options, urlParameters).then(
58
62
  (result) => ({
59
63
  ...(result as TilejsonResult),
60
64
  widgetSource: new WidgetTableSource({
61
65
  ...options,
62
- // NOTE: passing redundant spatialDataColumn here to apply the default value 'h3'
66
+ // NOTE: Parameters with default values above must be explicitly passed here.
63
67
  spatialDataColumn,
64
- spatialDataType: 'h3',
68
+ spatialDataType,
65
69
  }),
66
70
  })
67
71
  );
@@ -13,8 +13,10 @@ export type {
13
13
  RasterMetadataBand,
14
14
  RasterMetadataBandStats,
15
15
  SourceOptions,
16
+ SpatialFilterPolyfillMode,
16
17
  TableSourceOptions,
17
18
  TilejsonResult,
19
+ TileResolution,
18
20
  TilesetSourceOptions,
19
21
  VectorLayer,
20
22
  } from './types';
@@ -44,11 +44,14 @@ export const quadbinQuerySource = async function (
44
44
  queryParameters,
45
45
  filters,
46
46
  } = options;
47
+
48
+ const spatialDataType = 'quadbin';
49
+
47
50
  const urlParameters: UrlParameters = {
48
51
  aggregationExp,
49
52
  q: sqlQuery,
50
53
  spatialDataColumn,
51
- spatialDataType: 'quadbin',
54
+ spatialDataType,
52
55
  };
53
56
 
54
57
  if (aggregationResLevel) {
@@ -60,14 +63,15 @@ export const quadbinQuerySource = async function (
60
63
  if (filters) {
61
64
  urlParameters.filters = filters;
62
65
  }
66
+
63
67
  return baseSource<UrlParameters>('query', options, urlParameters).then(
64
68
  (result) => ({
65
69
  ...(result as TilejsonResult),
66
70
  widgetSource: new WidgetQuerySource({
67
71
  ...options,
68
- // NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
72
+ // NOTE: Parameters with default values above must be explicitly passed here.
69
73
  spatialDataColumn,
70
- spatialDataType: 'quadbin',
74
+ spatialDataType,
71
75
  }),
72
76
  })
73
77
  );
@@ -43,11 +43,13 @@ export const quadbinTableSource = async function (
43
43
  filters,
44
44
  } = options;
45
45
 
46
+ const spatialDataType = 'quadbin';
47
+
46
48
  const urlParameters: UrlParameters = {
47
49
  aggregationExp,
48
50
  name: tableName,
49
51
  spatialDataColumn,
50
- spatialDataType: 'quadbin',
52
+ spatialDataType,
51
53
  };
52
54
 
53
55
  if (aggregationResLevel) {
@@ -56,14 +58,15 @@ export const quadbinTableSource = async function (
56
58
  if (filters) {
57
59
  urlParameters.filters = filters;
58
60
  }
61
+
59
62
  return baseSource<UrlParameters>('table', options, urlParameters).then(
60
63
  (result) => ({
61
64
  ...(result as TilejsonResult),
62
65
  widgetSource: new WidgetTableSource({
63
66
  ...options,
64
- // NOTE: passing redundant spatialDataColumn here to apply the default value 'quadbin'
67
+ // NOTE: Parameters with default values above must be explicitly passed here.
65
68
  spatialDataColumn,
66
- spatialDataType: 'quadbin',
69
+ spatialDataType,
67
70
  }),
68
71
  })
69
72
  );
@@ -53,9 +53,11 @@ export const vectorQuerySource = async function (
53
53
  aggregationExp,
54
54
  } = options;
55
55
 
56
+ const spatialDataType = 'geo';
57
+
56
58
  const urlParameters: UrlParameters = {
57
59
  spatialDataColumn,
58
- spatialDataType: 'geo',
60
+ spatialDataType,
59
61
  tileResolution: tileResolution.toString(),
60
62
  q: sqlQuery,
61
63
  };
@@ -72,13 +74,16 @@ export const vectorQuerySource = async function (
72
74
  if (aggregationExp) {
73
75
  urlParameters.aggregationExp = aggregationExp;
74
76
  }
77
+
75
78
  return baseSource<UrlParameters>('query', options, urlParameters).then(
76
79
  (result) => ({
77
80
  ...(result as TilejsonResult),
78
81
  widgetSource: new WidgetQuerySource({
79
82
  ...options,
83
+ // NOTE: Parameters with default values above must be explicitly passed here.
80
84
  spatialDataColumn,
81
- spatialDataType: 'geo',
85
+ spatialDataType,
86
+ tileResolution,
82
87
  }),
83
88
  })
84
89
  );
@@ -51,10 +51,12 @@ export const vectorTableSource = async function (
51
51
  aggregationExp,
52
52
  } = options;
53
53
 
54
+ const spatialDataType = 'geo';
55
+
54
56
  const urlParameters: UrlParameters = {
55
57
  name: tableName,
56
58
  spatialDataColumn,
57
- spatialDataType: 'geo',
59
+ spatialDataType,
58
60
  tileResolution: tileResolution.toString(),
59
61
  };
60
62
 
@@ -67,13 +69,16 @@ export const vectorTableSource = async function (
67
69
  if (aggregationExp) {
68
70
  urlParameters.aggregationExp = aggregationExp;
69
71
  }
72
+
70
73
  return baseSource<UrlParameters>('table', options, urlParameters).then(
71
74
  (result) => ({
72
75
  ...(result as TilejsonResult),
73
76
  widgetSource: new WidgetTableSource({
74
77
  ...options,
78
+ // NOTE: Parameters with default values above must be explicitly passed here.
75
79
  spatialDataColumn,
76
- spatialDataType: 'geo',
80
+ spatialDataType,
81
+ tileResolution,
77
82
  }),
78
83
  })
79
84
  );
@@ -1,3 +1,4 @@
1
+ export * from './widget-source.js';
1
2
  export * from './widget-query-source.js';
2
3
  export * from './widget-remote-source.js';
3
4
  export * from './widget-table-source.js';
@@ -76,6 +76,7 @@ export type WidgetTilesetSourceResult = {widgetSource: WidgetTilesetSource};
76
76
  * ```
77
77
  */
78
78
  export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
79
+ private _tiles: Tile[] = [];
79
80
  private _features: FeatureData[] = [];
80
81
 
81
82
  protected override getModelSource(owner: string): ModelSource {
@@ -86,14 +87,24 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
86
87
  };
87
88
  }
88
89
 
89
- /** Loads features as a list of tiles (typically provided by deck.gl). */
90
- loadTiles({
91
- tiles,
90
+ /**
91
+ * Loads features as a list of tiles (typically provided by deck.gl).
92
+ * After tiles are loaded, {@link extractTileFeatures} must be called
93
+ * before computing statistics on the tiles.
94
+ */
95
+ loadTiles(tiles: unknown[]) {
96
+ this._tiles = tiles as Tile[];
97
+ }
98
+
99
+ /**
100
+ * Extracts feature data from tiles previously loaded with {@link loadTiles}.
101
+ * Must be called before computing statistics on tiles.
102
+ */
103
+ extractTileFeatures({
92
104
  spatialFilter,
93
105
  uniqueIdProperty,
94
106
  options,
95
107
  }: {
96
- tiles: Tile[];
97
108
  spatialFilter: SpatialFilter;
98
109
  // TODO(cleanup): As an optional property, 'uniqueIdProperty' will be easy to forget.
99
110
  // Would it be better to configure it on the source function, rather than separately
@@ -102,7 +113,7 @@ export class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps>
102
113
  options?: TileFeatureExtractOptions;
103
114
  }) {
104
115
  this._features = tileFeatures({
105
- tiles,
116
+ tiles: this._tiles,
106
117
  options,
107
118
  spatialFilter,
108
119
  uniqueIdProperty,