@carto/api-client 0.4.6 → 0.4.7-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.
Files changed (114) hide show
  1. package/build/api-client.cjs +3473 -1556
  2. package/build/api-client.cjs.map +1 -1
  3. package/build/api-client.d.cts +1389 -0
  4. package/build/api-client.d.ts +1389 -0
  5. package/build/api-client.js +3676 -0
  6. package/build/api-client.js.map +1 -0
  7. package/build/worker.d.ts +2 -0
  8. package/build/worker.js +1949 -0
  9. package/build/worker.js.map +1 -0
  10. package/package.json +58 -40
  11. package/src/api/carto-api-error.ts +1 -1
  12. package/src/api/query.ts +5 -5
  13. package/src/api/request-with-parameters.ts +6 -6
  14. package/src/client.ts +3 -3
  15. package/src/constants-internal.ts +5 -11
  16. package/src/constants.ts +28 -3
  17. package/src/deck/get-data-filter-extension-props.ts +146 -0
  18. package/src/deck/index.ts +1 -0
  19. package/src/filters/Filter.ts +179 -0
  20. package/src/filters/FilterTypes.ts +109 -0
  21. package/src/filters/geosjonFeatures.ts +32 -0
  22. package/src/filters/index.ts +6 -0
  23. package/src/filters/tileFeatures.ts +51 -0
  24. package/src/filters/tileFeaturesGeometries.ts +444 -0
  25. package/src/filters/tileFeaturesSpatialIndex.ts +119 -0
  26. package/src/filters.ts +4 -4
  27. package/src/geo.ts +12 -14
  28. package/src/global.d.ts +3 -8
  29. package/src/index.ts +7 -0
  30. package/src/models/common.ts +11 -9
  31. package/src/models/index.ts +1 -1
  32. package/src/models/model.ts +3 -4
  33. package/src/operations/aggregation.ts +154 -0
  34. package/src/operations/applySorting.ts +109 -0
  35. package/src/operations/groupBy.ts +59 -0
  36. package/src/operations/groupByDate.ts +98 -0
  37. package/src/operations/histogram.ts +66 -0
  38. package/src/operations/index.ts +6 -0
  39. package/src/operations/scatterPlot.ts +50 -0
  40. package/src/sources/base-source.ts +8 -8
  41. package/src/sources/boundary-query-source.ts +2 -2
  42. package/src/sources/boundary-table-source.ts +2 -2
  43. package/src/sources/h3-query-source.ts +7 -5
  44. package/src/sources/h3-table-source.ts +7 -5
  45. package/src/sources/h3-tileset-source.ts +20 -8
  46. package/src/sources/index.ts +26 -26
  47. package/src/sources/quadbin-query-source.ts +7 -5
  48. package/src/sources/quadbin-table-source.ts +7 -5
  49. package/src/sources/quadbin-tileset-source.ts +20 -8
  50. package/src/sources/raster-source.ts +3 -2
  51. package/src/sources/types.ts +9 -3
  52. package/src/sources/vector-query-source.ts +7 -5
  53. package/src/sources/vector-table-source.ts +7 -5
  54. package/src/sources/vector-tileset-source.ts +21 -8
  55. package/src/spatial-index.ts +4 -5
  56. package/src/types-internal.ts +11 -5
  57. package/src/types.ts +73 -15
  58. package/src/utils/dateUtils.ts +28 -0
  59. package/src/utils/getTileFormat.ts +9 -0
  60. package/src/utils/makeIntervalComplete.ts +17 -0
  61. package/src/utils/transformTileCoordsToWGS84.ts +77 -0
  62. package/src/utils/transformToTileCoords.ts +85 -0
  63. package/src/utils.ts +3 -3
  64. package/src/widget-sources/index.ts +3 -1
  65. package/src/widget-sources/types.ts +37 -25
  66. package/src/widget-sources/widget-query-source.ts +12 -5
  67. package/src/widget-sources/{widget-base-source.ts → widget-remote-source.ts} +55 -149
  68. package/src/widget-sources/widget-source.ts +145 -0
  69. package/src/widget-sources/widget-table-source.ts +12 -5
  70. package/src/widget-sources/widget-tileset-source-impl.ts +417 -0
  71. package/src/widget-sources/widget-tileset-source.ts +311 -0
  72. package/src/workers/constants.ts +13 -0
  73. package/src/workers/types.ts +19 -0
  74. package/src/workers/widget-tileset-worker.ts +40 -0
  75. package/build/api/carto-api-error.d.ts +0 -26
  76. package/build/api/endpoints.d.ts +0 -24
  77. package/build/api/index.d.ts +0 -5
  78. package/build/api/query.d.ts +0 -3
  79. package/build/api/request-with-parameters.d.ts +0 -10
  80. package/build/api-client.modern.js +0 -1742
  81. package/build/api-client.modern.js.map +0 -1
  82. package/build/client.d.ts +0 -14
  83. package/build/constants-internal.d.ts +0 -26
  84. package/build/constants.d.ts +0 -31
  85. package/build/filters.d.ts +0 -39
  86. package/build/geo.d.ts +0 -19
  87. package/build/index.d.ts +0 -11
  88. package/build/models/common.d.ts +0 -27
  89. package/build/models/index.d.ts +0 -3
  90. package/build/models/model.d.ts +0 -37
  91. package/build/sources/base-source.d.ts +0 -4
  92. package/build/sources/boundary-query-source.d.ts +0 -10
  93. package/build/sources/boundary-table-source.d.ts +0 -8
  94. package/build/sources/h3-query-source.d.ts +0 -5
  95. package/build/sources/h3-table-source.d.ts +0 -5
  96. package/build/sources/h3-tileset-source.d.ts +0 -4
  97. package/build/sources/index.d.ts +0 -26
  98. package/build/sources/quadbin-query-source.d.ts +0 -5
  99. package/build/sources/quadbin-table-source.d.ts +0 -5
  100. package/build/sources/quadbin-tileset-source.d.ts +0 -4
  101. package/build/sources/raster-source.d.ts +0 -4
  102. package/build/sources/types.d.ts +0 -366
  103. package/build/sources/vector-query-source.d.ts +0 -5
  104. package/build/sources/vector-table-source.d.ts +0 -5
  105. package/build/sources/vector-tileset-source.d.ts +0 -4
  106. package/build/spatial-index.d.ts +0 -14
  107. package/build/types-internal.d.ts +0 -52
  108. package/build/types.d.ts +0 -80
  109. package/build/utils.d.ts +0 -32
  110. package/build/widget-sources/index.d.ts +0 -4
  111. package/build/widget-sources/types.d.ts +0 -149
  112. package/build/widget-sources/widget-base-source.d.ts +0 -99
  113. package/build/widget-sources/widget-query-source.d.ts +0 -33
  114. package/build/widget-sources/widget-table-source.d.ts +0 -33
package/src/types.ts CHANGED
@@ -1,16 +1,54 @@
1
1
  import type {FilterType} from './constants.js';
2
- import type {Polygon, MultiPolygon} from 'geojson';
2
+ import type {Polygon, MultiPolygon, Feature} from 'geojson';
3
+ import type {BinaryFeature, BinaryFeatureCollection} from '@loaders.gl/schema';
3
4
 
4
5
  /******************************************************************************
5
6
  * MAPS AND TILES
6
7
  */
7
8
 
8
- /** @internalRemarks Source: @deck.gl/carto */
9
+ /** @privateRemarks Source: @deck.gl/carto */
9
10
  export type Format = 'json' | 'geojson' | 'tilejson';
10
11
 
11
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
12
+ /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
12
13
  export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
13
14
 
15
+ /**
16
+ * Alias for GeoJSON 'BBox' type, semantically representing a viewport.
17
+ * Order of values is "west", "south", "east", "north".
18
+ */
19
+ export type Viewport = [number, number, number, number];
20
+
21
+ /**
22
+ * Subset of deck.gl's Tile2DHeader type, containing only the properties
23
+ * required for local widget calculations. Deeper dependencies on deck.gl
24
+ * APIs should be minimized within this library: @deck.gl/carto depends
25
+ * on the API client, not the other way around.
26
+ * @privateRemarks Source: @deck.gl/geo-layers
27
+ */
28
+ export type Tile = {
29
+ index: {x: number; y: number; z: number};
30
+ id: string;
31
+ content: unknown;
32
+ zoom: number;
33
+ bbox: {west: number; east: number; north: number; south: number};
34
+ isVisible: boolean;
35
+ data?: BinaryFeatureCollection;
36
+ };
37
+
38
+ /** Subset of deck.gl's Tile2DHeader type, for spatial indexes. */
39
+ export type SpatialIndexTile = Tile & {
40
+ data?: (Feature & {id: bigint})[];
41
+ };
42
+
43
+ /** @privateRemarks Source: @deck.gl/carto */
44
+ export type Raster = {
45
+ blockSize: number;
46
+ cells: {
47
+ numericProps: BinaryFeature['numericProps'];
48
+ properties: BinaryFeature['properties'];
49
+ };
50
+ };
51
+
14
52
  /******************************************************************************
15
53
  * AGGREGATION
16
54
  */
@@ -18,8 +56,8 @@ export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
18
56
  /**
19
57
  * Enum for the different types of aggregations available for widgets.
20
58
  *
21
- * @internalRemarks Source: @carto/constants
22
- * @internalRemarks Converted from enum to type union, for improved declarative API.
59
+ * @privateRemarks Source: @carto/constants
60
+ * @privateRemarks Converted from enum to type union, for improved declarative API.
23
61
  */
24
62
  export type AggregationType =
25
63
  | 'count'
@@ -33,15 +71,15 @@ export type AggregationType =
33
71
  * FILTERS
34
72
  */
35
73
 
36
- /** @internalRemarks Source: @carto/react-api */
74
+ /** @privateRemarks Source: @carto/react-api */
37
75
  export type SpatialFilter = Polygon | MultiPolygon;
38
76
 
39
- /** @internalRemarks Source: @deck.gl/carto */
77
+ /** @privateRemarks Source: @deck.gl/carto */
40
78
  export interface Filters {
41
79
  [column: string]: Filter;
42
80
  }
43
81
 
44
- /** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
82
+ /** @privateRemarks Source: @carto/react-api, @deck.gl/carto */
45
83
  export interface Filter {
46
84
  [FilterType.IN]?: {owner?: string; values: number[] | string[]};
47
85
  /** [a, b] both are included. */
@@ -49,12 +87,32 @@ export interface Filter {
49
87
  /** [a, b) a is included, b is not. */
50
88
  [FilterType.CLOSED_OPEN]?: {owner?: string; values: number[][]};
51
89
  [FilterType.TIME]?: {owner?: string; values: number[][]};
52
- [FilterType.STRING_SEARCH]?: {owner?: string; values: string[]};
90
+ [FilterType.STRING_SEARCH]?: {
91
+ owner?: string;
92
+ values: string[];
93
+ params?: StringSearchOptions;
94
+ };
53
95
  }
54
96
 
55
- /** @internalRemarks Source: @carto/react-core */
97
+ /** @privateRemarks Source: @carto/react-core */
56
98
  export type FilterLogicalOperator = 'and' | 'or';
57
99
 
100
+ /**
101
+ * Type for minimum or maximum value of an interval. Values 'null' and
102
+ * 'undefined' are intentionally allowed, and represent an unbounded value.
103
+ */
104
+ export type FilterIntervalExtremum = number | null | undefined;
105
+ export type FilterInterval = [FilterIntervalExtremum, FilterIntervalExtremum];
106
+ export type FilterIntervalComplete = [number, number];
107
+
108
+ export type StringSearchOptions = {
109
+ useRegExp?: boolean;
110
+ mustStart?: boolean;
111
+ mustEnd?: boolean;
112
+ caseSensitive?: boolean;
113
+ keepSpecialCharacters?: boolean;
114
+ };
115
+
58
116
  /******************************************************************************
59
117
  * GROUPING
60
118
  */
@@ -62,7 +120,7 @@ export type FilterLogicalOperator = 'and' | 'or';
62
120
  /**
63
121
  * Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
64
122
  *
65
- * @internalRemarks Source: @carto/react-core
123
+ * @privateRemarks Source: @carto/react-core
66
124
  */
67
125
  export type GroupDateType =
68
126
  | 'year'
@@ -84,7 +142,7 @@ export type SortColumnType = 'number' | 'string' | 'date';
84
142
  * SQL QUERY PARAMETERS
85
143
  */
86
144
 
87
- /** @internalRemarks Source: @deck.gl/carto */
145
+ /** @privateRemarks Source: @deck.gl/carto */
88
146
  export type QueryParameterValue =
89
147
  | string
90
148
  | number
@@ -92,11 +150,11 @@ export type QueryParameterValue =
92
150
  | Array<QueryParameterValue>
93
151
  | object;
94
152
 
95
- /** @internalRemarks Source: @deck.gl/carto */
153
+ /** @privateRemarks Source: @deck.gl/carto */
96
154
  export type NamedQueryParameter = Record<string, QueryParameterValue>;
97
155
 
98
- /** @internalRemarks Source: @deck.gl/carto */
156
+ /** @privateRemarks Source: @deck.gl/carto */
99
157
  export type PositionalQueryParameter = QueryParameterValue[];
100
158
 
101
- /** @internalRemarks Source: @deck.gl/carto */
159
+ /** @privateRemarks Source: @deck.gl/carto */
102
160
  export type QueryParameters = NamedQueryParameter | PositionalQueryParameter;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Returns midnight (local time) on the Monday preceeding a given date, in
3
+ * milliseconds since the UNIX epoch.
4
+ */
5
+ export function getMonday(date: number | Date): number {
6
+ const dateCp = new Date(date);
7
+ const day = dateCp.getDay();
8
+ const diff = dateCp.getDate() - day + (day ? 1 : -6); // adjust when day is sunday
9
+ dateCp.setDate(diff);
10
+ dateCp.setHours(0, 0, 0, 0);
11
+ return dateCp.getTime();
12
+ }
13
+
14
+ /**
15
+ * Returns midnight (UTC) on the Monday preceeding a given date, in
16
+ * milliseconds since the UNIX epoch.
17
+ */
18
+ export function getUTCMonday(date: number | Date): number {
19
+ const dateCp = new Date(date);
20
+ const day = dateCp.getUTCDay();
21
+ const diff = dateCp.getUTCDate() - day + (day ? 1 : -6); // adjust when day is sunday
22
+ dateCp.setUTCDate(diff);
23
+ return Date.UTC(
24
+ dateCp.getUTCFullYear(),
25
+ dateCp.getUTCMonth(),
26
+ dateCp.getUTCDate()
27
+ );
28
+ }
@@ -0,0 +1,9 @@
1
+ import {TileFormat} from '../constants.js';
2
+ import {Tilejson} from '../sources/types.js';
3
+
4
+ export function getTileFormat(tilejson: Tilejson): TileFormat {
5
+ const tileParams = new URL(tilejson.tiles[0]).searchParams;
6
+ return tileParams.get('formatTiles') === 'mvt'
7
+ ? TileFormat.MVT
8
+ : TileFormat.BINARY;
9
+ }
@@ -0,0 +1,17 @@
1
+ import {FilterInterval, FilterIntervalComplete} from '../types.js';
2
+
3
+ export function makeIntervalComplete(
4
+ intervals: FilterInterval[]
5
+ ): FilterIntervalComplete[] {
6
+ return intervals.map((val) => {
7
+ if (val[0] === undefined || val[0] === null) {
8
+ return [Number.MIN_SAFE_INTEGER, val[1]];
9
+ }
10
+
11
+ if (val[1] === undefined || val[1] === null) {
12
+ return [val[0], Number.MAX_SAFE_INTEGER];
13
+ }
14
+
15
+ return val;
16
+ }) as FilterIntervalComplete[];
17
+ }
@@ -0,0 +1,77 @@
1
+ import {lerp} from '@math.gl/core';
2
+ import {lngLatToWorld, worldToLngLat} from '@math.gl/web-mercator';
3
+ import {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
4
+
5
+ type TransformFn = (coordinates: any[], bbox: Position[]) => any[];
6
+
7
+ const TRANSFORM_FN: Record<
8
+ Exclude<GeoJsonGeometryTypes, 'GeometryCollection'>,
9
+ TransformFn
10
+ > = {
11
+ Point: transformPoint,
12
+ MultiPoint: transformMultiPoint,
13
+ LineString: transformLineString,
14
+ MultiLineString: transformMultiLineString,
15
+ Polygon: transformPolygon,
16
+ MultiPolygon: transformMultiPolygon,
17
+ };
18
+
19
+ /**
20
+ * Transform tile coords to WGS84 coordinates.
21
+ *
22
+ * @param geometry - any valid geojson geometry
23
+ * @param bbox - geojson bbox
24
+ */
25
+ export function transformTileCoordsToWGS84<T extends Geometry>(
26
+ geometry: T,
27
+ bbox: BBox
28
+ ): T {
29
+ const [west, south, east, north] = bbox;
30
+ const nw = lngLatToWorld([west, north]);
31
+ const se = lngLatToWorld([east, south]);
32
+ const projectedBbox = [nw, se];
33
+
34
+ if (geometry.type === 'GeometryCollection') {
35
+ throw new Error('Unsupported geometry type GeometryCollection');
36
+ }
37
+
38
+ const transformFn = TRANSFORM_FN[geometry.type];
39
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
40
+ return {...geometry, coordinates};
41
+ }
42
+
43
+ function transformPoint([pointX, pointY]: Position, [nw, se]: Position[]) {
44
+ const x = lerp(nw[0], se[0], pointX);
45
+ const y = lerp(nw[1], se[1], pointY);
46
+
47
+ return worldToLngLat([x, y]);
48
+ }
49
+
50
+ function getPoints(geometry: Position[], bbox: Position[]) {
51
+ return geometry.map((g) => transformPoint(g, bbox));
52
+ }
53
+
54
+ function transformMultiPoint(multiPoint: Position[], bbox: Position[]) {
55
+ return getPoints(multiPoint, bbox);
56
+ }
57
+
58
+ function transformLineString(line: Position[], bbox: Position[]) {
59
+ return getPoints(line, bbox);
60
+ }
61
+
62
+ function transformMultiLineString(
63
+ multiLineString: Position[][],
64
+ bbox: Position[]
65
+ ) {
66
+ return multiLineString.map((lineString) =>
67
+ transformLineString(lineString, bbox)
68
+ );
69
+ }
70
+
71
+ function transformPolygon(polygon: Position[][], bbox: Position[]) {
72
+ return polygon.map((polygonRing) => getPoints(polygonRing, bbox));
73
+ }
74
+
75
+ function transformMultiPolygon(multiPolygon: Position[][][], bbox: Position[]) {
76
+ return multiPolygon.map((polygon) => transformPolygon(polygon, bbox));
77
+ }
@@ -0,0 +1,85 @@
1
+ import {lngLatToWorld} from '@math.gl/web-mercator';
2
+ import {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
3
+
4
+ type TransformFn = (coordinates: any[], bbox: Position[]) => any[];
5
+
6
+ const TRANSFORM_FN: Record<
7
+ Exclude<GeoJsonGeometryTypes, 'GeometryCollection'>,
8
+ TransformFn
9
+ > = {
10
+ Point: transformPoint,
11
+ MultiPoint: transformMultiPoint,
12
+ LineString: transformLineString,
13
+ MultiLineString: transformMultiLineString,
14
+ Polygon: transformPolygon,
15
+ MultiPolygon: transformMultiPolygon,
16
+ };
17
+
18
+ /**
19
+ * Transform WGS84 coordinates to tile coords.
20
+ * It's the inverse of deck.gl coordinate-transform (https://github.com/visgl/deck.gl/blob/master/modules/geo-layers/src/mvt-layer/coordinate-transform.js)
21
+ *
22
+ * @param geometry - any valid geojson geometry
23
+ * @param bbox - geojson bbox
24
+ */
25
+ export function transformToTileCoords<T extends Geometry>(
26
+ geometry: T,
27
+ bbox: BBox
28
+ ): T {
29
+ const [west, south, east, north] = bbox;
30
+ const nw = projectFlat([west, north]);
31
+ const se = projectFlat([east, south]);
32
+ const projectedBbox = [nw, se];
33
+
34
+ if (geometry.type === 'GeometryCollection') {
35
+ throw new Error('Unsupported geometry type GeometryCollection');
36
+ }
37
+
38
+ const transformFn = TRANSFORM_FN[geometry.type];
39
+ const coordinates = transformFn(geometry.coordinates, projectedBbox);
40
+ return {...geometry, coordinates};
41
+ }
42
+
43
+ function transformPoint([pointX, pointY]: Position, [nw, se]: Position[]) {
44
+ const x = inverseLerp(nw[0], se[0], pointX);
45
+ const y = inverseLerp(nw[1], se[1], pointY);
46
+
47
+ return [x, y];
48
+ }
49
+
50
+ function getPoints(geometry: Position[], bbox: Position[]) {
51
+ return geometry.map((g) => transformPoint(projectFlat(g), bbox));
52
+ }
53
+
54
+ function transformMultiPoint(multiPoint: Position[], bbox: Position[]) {
55
+ return getPoints(multiPoint, bbox);
56
+ }
57
+
58
+ function transformLineString(line: Position[], bbox: Position[]) {
59
+ return getPoints(line, bbox);
60
+ }
61
+
62
+ function transformMultiLineString(
63
+ multiLineString: Position[][],
64
+ bbox: Position[]
65
+ ) {
66
+ return multiLineString.map((lineString) =>
67
+ transformLineString(lineString, bbox)
68
+ );
69
+ }
70
+
71
+ function transformPolygon(polygon: Position[][], bbox: Position[]) {
72
+ return polygon.map((polygonRing) => getPoints(polygonRing, bbox));
73
+ }
74
+
75
+ function transformMultiPolygon(multiPolygon: Position[][][], bbox: Position[]) {
76
+ return multiPolygon.map((polygon) => transformPolygon(polygon, bbox));
77
+ }
78
+
79
+ function projectFlat(xyz: Position): Position {
80
+ return lngLatToWorld(xyz);
81
+ }
82
+
83
+ function inverseLerp(a: number, b: number, x: number): number {
84
+ return (x - a) / (b - a);
85
+ }
package/src/utils.ts CHANGED
@@ -39,7 +39,7 @@ type Row<T> = Record<string, T> | Record<string, T>[] | T[] | T;
39
39
  * Due to each data warehouse having its own behavior with columns,
40
40
  * we need to normalize them and transform every key to lowercase.
41
41
  *
42
- * @internalRemarks Source: @carto/react-widgets
42
+ * @privateRemarks Source: @carto/react-widgets
43
43
  * @internal
44
44
  */
45
45
  export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
@@ -59,7 +59,7 @@ export function normalizeObjectKeys<T, R extends Row<T>>(el: R): R {
59
59
  ) as R;
60
60
  }
61
61
 
62
- /** @internalRemarks Source: @carto/react-core */
62
+ /** @privateRemarks Source: @carto/react-core */
63
63
  export function assert(condition: unknown, message: string): asserts condition {
64
64
  if (!condition) {
65
65
  throw new Error(message);
@@ -67,7 +67,7 @@ export function assert(condition: unknown, message: string): asserts condition {
67
67
  }
68
68
 
69
69
  /**
70
- * @internalRemarks Source: @carto/react-core
70
+ * @privateRemarks Source: @carto/react-core
71
71
  * @internal
72
72
  */
73
73
  export class InvalidColumnError extends Error {
@@ -1,4 +1,6 @@
1
- export * from './widget-base-source.js';
1
+ export * from './widget-source.js';
2
2
  export * from './widget-query-source.js';
3
+ export * from './widget-remote-source.js';
3
4
  export * from './widget-table-source.js';
5
+ export * from './widget-tileset-source.js';
4
6
  export * from './types.js';
@@ -1,10 +1,11 @@
1
- import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types';
1
+ import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types.js';
2
2
  import {
3
+ Filters,
3
4
  GroupDateType,
4
5
  SortColumnType,
5
6
  SortDirection,
6
7
  SpatialFilter,
7
- } from '../types';
8
+ } from '../types.js';
8
9
 
9
10
  /******************************************************************************
10
11
  * WIDGET API REQUESTS
@@ -16,25 +17,29 @@ export interface ViewState {
16
17
  longitude: number;
17
18
  }
18
19
 
19
- /** Common options for {@link WidgetBaseSource} requests. */
20
+ /** Common options for {@link WidgetRemoteSource} requests. */
20
21
  interface BaseRequestOptions {
22
+ signal?: AbortSignal;
21
23
  spatialFilter?: SpatialFilter;
22
24
  spatialFiltersMode?: SpatialFilterPolyfillMode;
23
25
  /** Required for table- and query-based spatial index sources (H3, Quadbin). */
24
26
  spatialIndexReferenceViewState?: ViewState;
25
- abortController?: AbortController;
27
+ /** Overrides source filters, if any. */
28
+ filters?: Filters;
26
29
  filterOwner?: string;
27
30
  }
28
31
 
29
- /** Options for {@link WidgetBaseSource#getCategories}. */
32
+ /** Options for {@link WidgetRemoteSource#getCategories}. */
30
33
  export interface CategoryRequestOptions extends BaseRequestOptions {
31
34
  column: string;
32
35
  operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
33
36
  operationColumn?: string;
37
+ /** Local only. */
38
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
34
39
  }
35
40
 
36
41
  /**
37
- * Options for {@link WidgetBaseSource#getFeatures}.
42
+ * Options for {@link WidgetRemoteSource#getFeatures}.
38
43
  * @experimental
39
44
  * @internal
40
45
  */
@@ -76,26 +81,29 @@ export interface FeaturesRequestOptions extends BaseRequestOptions {
76
81
  tileResolution?: TileResolution;
77
82
  }
78
83
 
79
- /** Options for {@link WidgetBaseSource#getFormula}. */
84
+ /** Options for {@link WidgetRemoteSource#getFormula}. */
80
85
  export interface FormulaRequestOptions extends BaseRequestOptions {
81
86
  column: string;
82
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
87
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom';
83
88
  operationExp?: string;
89
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
84
90
  }
85
91
 
86
- /** Options for {@link WidgetBaseSource#getHistogram}. */
92
+ /** Options for {@link WidgetRemoteSource#getHistogram}. */
87
93
  export interface HistogramRequestOptions extends BaseRequestOptions {
88
94
  column: string;
89
95
  ticks: number[];
90
96
  operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
97
+ /** Local only. */
98
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
91
99
  }
92
100
 
93
- /** Options for {@link WidgetBaseSource#getRange}. */
101
+ /** Options for {@link WidgetRemoteSource#getRange}. */
94
102
  export interface RangeRequestOptions extends BaseRequestOptions {
95
103
  column: string;
96
104
  }
97
105
 
98
- /** Options for {@link WidgetBaseSource#getScatter}. */
106
+ /** Options for {@link WidgetRemoteSource#getScatter}. */
99
107
  export interface ScatterRequestOptions extends BaseRequestOptions {
100
108
  xAxisColumn: string;
101
109
  xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
@@ -103,7 +111,7 @@ export interface ScatterRequestOptions extends BaseRequestOptions {
103
111
  yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
104
112
  }
105
113
 
106
- /** Options for {@link WidgetBaseSource#getTable}. */
114
+ /** Options for {@link WidgetRemoteSource#getTable}. */
107
115
  export interface TableRequestOptions extends BaseRequestOptions {
108
116
  columns: string[];
109
117
  sortBy?: string;
@@ -111,12 +119,16 @@ export interface TableRequestOptions extends BaseRequestOptions {
111
119
  sortByColumnType?: SortColumnType;
112
120
  offset?: number;
113
121
  limit?: number;
122
+ /** Local only. */
123
+ searchFilterColumn?: string;
124
+ /** Local only. */
125
+ searchFilterText?: string;
114
126
  }
115
127
 
116
- /** Options for {@link WidgetBaseSource#getTimeSeries}. */
128
+ /** Options for {@link WidgetRemoteSource#getTimeSeries}. */
117
129
  export interface TimeSeriesRequestOptions extends BaseRequestOptions {
118
130
  column: string;
119
- stepSize?: GroupDateType;
131
+ stepSize: GroupDateType;
120
132
  stepMultiplier?: number;
121
133
  operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
122
134
  operationColumn?: string;
@@ -131,35 +143,35 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
131
143
  */
132
144
 
133
145
  /**
134
- * Response from {@link WidgetBaseSource#getFeatures}.
146
+ * Response from {@link WidgetRemoteSource#getFeatures}.
135
147
  * @experimental
136
148
  * @internal
137
149
  */
138
150
  export type FeaturesResponse = {rows: Record<string, unknown>[]};
139
151
 
140
- /** Response from {@link WidgetBaseSource#getFormula}. */
141
- export type FormulaResponse = {value: number};
152
+ /** Response from {@link WidgetRemoteSource#getFormula}. */
153
+ export type FormulaResponse = {value: number | null};
142
154
 
143
- /** Response from {@link WidgetBaseSource#getCategories}. */
155
+ /** Response from {@link WidgetRemoteSource#getCategories}. */
144
156
  export type CategoryResponse = {name: string; value: number}[];
145
157
 
146
- /** Response from {@link WidgetBaseSource#getRange}. */
147
- export type RangeResponse = {min: number; max: number};
158
+ /** Response from {@link WidgetRemoteSource#getRange}. */
159
+ export type RangeResponse = {min: number; max: number} | null;
148
160
 
149
- /** Response from {@link WidgetBaseSource#getTable}. */
161
+ /** Response from {@link WidgetRemoteSource#getTable}. */
150
162
  export type TableResponse = {
151
163
  totalCount: number;
152
164
  rows: Record<string, number | string>[];
153
165
  };
154
166
 
155
- /** Response from {@link WidgetBaseSource#getScatter}. */
167
+ /** Response from {@link WidgetRemoteSource#getScatter}. */
156
168
  export type ScatterResponse = [number, number][];
157
169
 
158
- /** Response from {@link WidgetBaseSource#getTimeSeries}. */
170
+ /** Response from {@link WidgetRemoteSource#getTimeSeries}. */
159
171
  export type TimeSeriesResponse = {
160
172
  rows: {name: string; value: number}[];
161
- categories: string[];
173
+ categories?: string[];
162
174
  };
163
175
 
164
- /** Response from {@link WidgetBaseSource#getHistogram}. */
176
+ /** Response from {@link WidgetRemoteSource#getHistogram}. */
165
177
  export type HistogramResponse = number[];
@@ -3,8 +3,12 @@ import {
3
3
  QuadbinQuerySourceOptions,
4
4
  VectorQuerySourceOptions,
5
5
  } from '../sources/index.js';
6
- import {WidgetBaseSource, WidgetBaseSourceProps} from './widget-base-source.js';
6
+ import {
7
+ WidgetRemoteSource,
8
+ WidgetRemoteSourceProps,
9
+ } from './widget-remote-source.js';
7
10
  import {ModelSource} from '../models/model.js';
11
+ import {Filters} from '../types.js';
8
12
 
9
13
  type LayerQuerySourceOptions =
10
14
  | Omit<VectorQuerySourceOptions, 'filters'>
@@ -35,12 +39,15 @@ export type WidgetQuerySourceResult = {widgetSource: WidgetQuerySource};
35
39
  * const { widgetSource } = await data;
36
40
  * ```
37
41
  */
38
- export class WidgetQuerySource extends WidgetBaseSource<
39
- LayerQuerySourceOptions & WidgetBaseSourceProps
42
+ export class WidgetQuerySource extends WidgetRemoteSource<
43
+ LayerQuerySourceOptions & WidgetRemoteSourceProps
40
44
  > {
41
- protected override getModelSource(owner: string): ModelSource {
45
+ protected override getModelSource(
46
+ filters: Filters | undefined,
47
+ filterOwner?: string
48
+ ): ModelSource {
42
49
  return {
43
- ...super._getModelSource(owner),
50
+ ...super._getModelSource(filters, filterOwner),
44
51
  type: 'query',
45
52
  data: this.props.sqlQuery,
46
53
  queryParameters: this.props.queryParameters,