@carto/api-client 0.4.7-0 → 0.4.7-alpha.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/build/api/carto-api-error.d.ts +26 -0
  3. package/build/api/endpoints.d.ts +24 -0
  4. package/build/api/index.d.ts +5 -0
  5. package/build/api/query.d.ts +3 -0
  6. package/build/api/request-with-parameters.d.ts +10 -0
  7. package/build/api-client.cjs +2916 -2741
  8. package/build/api-client.cjs.map +1 -1
  9. package/build/api-client.modern.js +3723 -0
  10. package/build/api-client.modern.js.map +1 -0
  11. package/build/client.d.ts +14 -0
  12. package/build/constants-internal.d.ts +26 -0
  13. package/build/constants.d.ts +53 -0
  14. package/build/deck/get-data-filter-extension-props.d.ts +28 -0
  15. package/build/deck/index.d.ts +1 -0
  16. package/build/filters/Filter.d.ts +25 -0
  17. package/build/filters/FilterTypes.d.ts +3 -0
  18. package/build/filters/geosjonFeatures.d.ts +8 -0
  19. package/build/filters/index.d.ts +6 -0
  20. package/build/filters/tileFeatures.d.ts +20 -0
  21. package/build/filters/tileFeaturesGeometries.d.ts +13 -0
  22. package/build/filters/tileFeaturesSpatialIndex.d.ts +10 -0
  23. package/build/filters.d.ts +39 -0
  24. package/build/geo.d.ts +19 -0
  25. package/build/index.d.ts +16 -0
  26. package/build/models/common.d.ts +28 -0
  27. package/build/models/index.d.ts +3 -0
  28. package/build/models/model.d.ts +37 -0
  29. package/build/operations/aggregation.d.ts +8 -0
  30. package/build/operations/applySorting.d.ts +20 -0
  31. package/build/operations/groupBy.d.ts +15 -0
  32. package/build/operations/groupByDate.d.ts +11 -0
  33. package/build/operations/histogram.d.ts +13 -0
  34. package/build/operations/index.d.ts +6 -0
  35. package/build/operations/scatterPlot.d.ts +14 -0
  36. package/build/sources/base-source.d.ts +4 -0
  37. package/build/sources/boundary-query-source.d.ts +10 -0
  38. package/build/sources/boundary-table-source.d.ts +8 -0
  39. package/build/sources/h3-query-source.d.ts +5 -0
  40. package/build/sources/h3-table-source.d.ts +5 -0
  41. package/build/sources/h3-tileset-source.d.ts +4 -0
  42. package/build/sources/index.d.ts +26 -0
  43. package/build/sources/quadbin-query-source.d.ts +5 -0
  44. package/build/sources/quadbin-table-source.d.ts +5 -0
  45. package/build/sources/quadbin-tileset-source.d.ts +4 -0
  46. package/build/sources/raster-source.d.ts +4 -0
  47. package/build/sources/types.d.ts +366 -0
  48. package/build/sources/vector-query-source.d.ts +5 -0
  49. package/build/sources/vector-table-source.d.ts +5 -0
  50. package/build/sources/vector-tileset-source.d.ts +4 -0
  51. package/build/spatial-index.d.ts +14 -0
  52. package/build/types-internal.d.ts +56 -0
  53. package/build/types.d.ts +140 -0
  54. package/build/utils/dateUtils.d.ts +10 -0
  55. package/build/utils/getTileFormat.d.ts +3 -0
  56. package/build/utils/makeIntervalComplete.d.ts +2 -0
  57. package/build/utils/transformTileCoordsToWGS84.d.ts +8 -0
  58. package/build/utils/transformToTileCoords.d.ts +9 -0
  59. package/build/utils.d.ts +32 -0
  60. package/build/widget-sources/index.d.ts +6 -0
  61. package/build/widget-sources/types.d.ts +162 -0
  62. package/build/widget-sources/widget-query-source.d.ts +34 -0
  63. package/build/widget-sources/widget-remote-source.d.ts +18 -0
  64. package/build/widget-sources/widget-source.d.ts +84 -0
  65. package/build/widget-sources/widget-table-source.d.ts +34 -0
  66. package/build/widget-sources/widget-tileset-source.d.ts +75 -0
  67. package/package.json +18 -19
  68. package/src/constants-internal.ts +6 -0
  69. package/src/deck/get-data-filter-extension-props.ts +27 -9
  70. package/src/filters/tileFeatures.ts +0 -1
  71. package/src/global.d.ts +8 -3
  72. package/src/sources/h3-tileset-source.ts +6 -18
  73. package/src/sources/quadbin-tileset-source.ts +6 -18
  74. package/src/sources/types.ts +0 -6
  75. package/src/sources/vector-tileset-source.ts +6 -19
  76. package/src/widget-sources/types.ts +2 -0
  77. package/src/widget-sources/widget-remote-source.ts +16 -42
  78. package/src/widget-sources/widget-source.ts +52 -12
  79. package/src/widget-sources/widget-tileset-source.ts +341 -196
  80. package/build/api-client.d.cts +0 -1389
  81. package/build/api-client.d.ts +0 -1389
  82. package/build/api-client.js +0 -3676
  83. package/build/api-client.js.map +0 -1
  84. package/build/worker.d.ts +0 -2
  85. package/build/worker.js +0 -1949
  86. package/build/worker.js.map +0 -1
  87. package/src/widget-sources/widget-tileset-source-impl.ts +0 -417
  88. package/src/workers/constants.ts +0 -13
  89. package/src/workers/types.ts +0 -19
  90. package/src/workers/widget-tileset-worker.ts +0 -40
@@ -0,0 +1,162 @@
1
+ import { SpatialFilterPolyfillMode, TileResolution } from '../sources/types.js';
2
+ import { Filters, GroupDateType, SortColumnType, SortDirection, SpatialFilter } from '../types.js';
3
+ /******************************************************************************
4
+ * WIDGET API REQUESTS
5
+ */
6
+ export interface ViewState {
7
+ zoom: number;
8
+ latitude: number;
9
+ longitude: number;
10
+ }
11
+ /** Common options for {@link WidgetRemoteSource} requests. */
12
+ interface BaseRequestOptions {
13
+ /** @deprecated */
14
+ abortController?: AbortController;
15
+ signal?: AbortSignal;
16
+ spatialFilter?: SpatialFilter;
17
+ spatialFiltersMode?: SpatialFilterPolyfillMode;
18
+ /** Required for table- and query-based spatial index sources (H3, Quadbin). */
19
+ spatialIndexReferenceViewState?: ViewState;
20
+ /** Overrides source filters, if any. */
21
+ filters?: Filters;
22
+ filterOwner?: string;
23
+ }
24
+ /** Options for {@link WidgetRemoteSource#getCategories}. */
25
+ export interface CategoryRequestOptions extends BaseRequestOptions {
26
+ column: string;
27
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
28
+ operationColumn?: string;
29
+ /** Local only. */
30
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
31
+ }
32
+ /**
33
+ * Options for {@link WidgetRemoteSource#getFeatures}.
34
+ * @experimental
35
+ * @internal
36
+ */
37
+ export interface FeaturesRequestOptions extends BaseRequestOptions {
38
+ /**
39
+ * Feature IDs, as found in `_carto_feature_id`. Feature IDs are a hash
40
+ * of geometry, and features with identical geometry will have the same
41
+ * feature ID. Order is important; features in the result set will be
42
+ * sorted according to the order of IDs in the request.
43
+ */
44
+ featureIds: string[];
45
+ /**
46
+ * Columns to be returned for each picked object. Note that for datasets
47
+ * containing features with identical geometry, more than one result per
48
+ * requested feature ID may be returned. To match results back to the
49
+ * requested feature ID, include `_carto_feature_id` in the columns list.
50
+ */
51
+ columns: string[];
52
+ /** Topology of objects to be picked. */
53
+ dataType: 'points' | 'lines' | 'polygons';
54
+ /** Zoom level, required if using 'points' data type. */
55
+ z?: number;
56
+ /**
57
+ * Maximum number of objects to return in the result set. For datasets
58
+ * containing features with identical geometry, those features will have
59
+ * the same feature IDs, and so more results may be returned than feature IDs
60
+ * given in the request.
61
+ */
62
+ limit?: number;
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
+ /** Options for {@link WidgetRemoteSource#getFormula}. */
70
+ export interface FormulaRequestOptions extends BaseRequestOptions {
71
+ column: string;
72
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom';
73
+ operationExp?: string;
74
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
75
+ }
76
+ /** Options for {@link WidgetRemoteSource#getHistogram}. */
77
+ export interface HistogramRequestOptions extends BaseRequestOptions {
78
+ column: string;
79
+ ticks: number[];
80
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
81
+ /** Local only. */
82
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
83
+ }
84
+ /** Options for {@link WidgetRemoteSource#getRange}. */
85
+ export interface RangeRequestOptions extends BaseRequestOptions {
86
+ column: string;
87
+ }
88
+ /** Options for {@link WidgetRemoteSource#getScatter}. */
89
+ export interface ScatterRequestOptions extends BaseRequestOptions {
90
+ xAxisColumn: string;
91
+ xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
92
+ yAxisColumn: string;
93
+ yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
94
+ }
95
+ /** Options for {@link WidgetRemoteSource#getTable}. */
96
+ export interface TableRequestOptions extends BaseRequestOptions {
97
+ columns: string[];
98
+ sortBy?: string;
99
+ sortDirection?: SortDirection;
100
+ sortByColumnType?: SortColumnType;
101
+ offset?: number;
102
+ limit?: number;
103
+ /** Local only. */
104
+ searchFilterColumn?: string;
105
+ /** Local only. */
106
+ searchFilterText?: string;
107
+ }
108
+ /** Options for {@link WidgetRemoteSource#getTimeSeries}. */
109
+ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
110
+ column: string;
111
+ stepSize: GroupDateType;
112
+ stepMultiplier?: number;
113
+ operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
114
+ operationColumn?: string;
115
+ joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
116
+ splitByCategory?: string;
117
+ splitByCategoryLimit?: number;
118
+ splitByCategoryValues?: string[];
119
+ }
120
+ /******************************************************************************
121
+ * WIDGET API RESPONSES
122
+ */
123
+ /**
124
+ * Response from {@link WidgetRemoteSource#getFeatures}.
125
+ * @experimental
126
+ * @internal
127
+ */
128
+ export type FeaturesResponse = {
129
+ rows: Record<string, unknown>[];
130
+ };
131
+ /** Response from {@link WidgetRemoteSource#getFormula}. */
132
+ export type FormulaResponse = {
133
+ value: number | null;
134
+ };
135
+ /** Response from {@link WidgetRemoteSource#getCategories}. */
136
+ export type CategoryResponse = {
137
+ name: string;
138
+ value: number;
139
+ }[];
140
+ /** Response from {@link WidgetRemoteSource#getRange}. */
141
+ export type RangeResponse = {
142
+ min: number;
143
+ max: number;
144
+ } | null;
145
+ /** Response from {@link WidgetRemoteSource#getTable}. */
146
+ export type TableResponse = {
147
+ totalCount: number;
148
+ rows: Record<string, number | string>[];
149
+ };
150
+ /** Response from {@link WidgetRemoteSource#getScatter}. */
151
+ export type ScatterResponse = [number, number][];
152
+ /** Response from {@link WidgetRemoteSource#getTimeSeries}. */
153
+ export type TimeSeriesResponse = {
154
+ rows: {
155
+ name: string;
156
+ value: number;
157
+ }[];
158
+ categories?: string[];
159
+ };
160
+ /** Response from {@link WidgetRemoteSource#getHistogram}. */
161
+ export type HistogramResponse = number[];
162
+ export {};
@@ -0,0 +1,34 @@
1
+ import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptions } from '../sources/index.js';
2
+ import { WidgetRemoteSource, WidgetRemoteSourceProps } from './widget-remote-source.js';
3
+ import { ModelSource } from '../models/model.js';
4
+ import { Filters } from '../types.js';
5
+ type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
6
+ export type WidgetQuerySourceResult = {
7
+ widgetSource: WidgetQuerySource;
8
+ };
9
+ /**
10
+ * Source for Widget API requests on a data source defined by a SQL query.
11
+ *
12
+ * Generally not intended to be constructed directly. Instead, call
13
+ * {@link vectorQuerySource}, {@link h3QuerySource}, or {@link quadbinQuerySource},
14
+ * which can be shared with map layers. Sources contain a `widgetSource` property,
15
+ * for use by widget implementations.
16
+ *
17
+ * Example:
18
+ *
19
+ * ```javascript
20
+ * import { vectorQuerySource } from '@carto/api-client';
21
+ *
22
+ * const data = vectorQuerySource({
23
+ * accessToken: '••••',
24
+ * connectionName: 'carto_dw',
25
+ * sqlQuery: 'SELECT * FROM carto-demo-data.demo_tables.retail_stores'
26
+ * });
27
+ *
28
+ * const { widgetSource } = await data;
29
+ * ```
30
+ */
31
+ export declare class WidgetQuerySource extends WidgetRemoteSource<LayerQuerySourceOptions & WidgetRemoteSourceProps> {
32
+ protected getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
33
+ }
34
+ export {};
@@ -0,0 +1,18 @@
1
+ import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
2
+ import { WidgetSource, WidgetSourceProps } from './widget-source.js';
3
+ export type WidgetRemoteSourceProps = WidgetSourceProps;
4
+ /**
5
+ * Source for Widget API requests.
6
+ *
7
+ * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
8
+ */
9
+ export declare abstract class WidgetRemoteSource<Props extends WidgetRemoteSourceProps> extends WidgetSource<Props> {
10
+ getCategories(options: CategoryRequestOptions): Promise<CategoryResponse>;
11
+ getFeatures(options: FeaturesRequestOptions): Promise<FeaturesResponse>;
12
+ getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
13
+ getHistogram(options: HistogramRequestOptions): Promise<HistogramResponse>;
14
+ getRange(options: RangeRequestOptions): Promise<RangeResponse>;
15
+ getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
16
+ getTable(options: TableRequestOptions): Promise<TableResponse>;
17
+ getTimeSeries(options: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
18
+ }
@@ -0,0 +1,84 @@
1
+ import { CategoryRequestOptions, CategoryResponse, FeaturesRequestOptions, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse, ViewState } from './types.js';
2
+ import { FilterLogicalOperator, Filter, SpatialFilter, Filters } from '../types.js';
3
+ import { ModelSource } from '../models/model.js';
4
+ import { SourceOptions } from '../sources/index.js';
5
+ import { ApiVersion } from '../constants.js';
6
+ export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
7
+ apiVersion?: ApiVersion;
8
+ filters?: Record<string, Filter>;
9
+ filtersLogicalOperator?: FilterLogicalOperator;
10
+ }
11
+ /**
12
+ * Source for Widget API requests on a data source defined by a SQL query.
13
+ *
14
+ * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
15
+ */
16
+ export declare abstract class WidgetSource<Props extends WidgetSourceProps> {
17
+ readonly props: Props;
18
+ static defaultProps: Partial<WidgetSourceProps>;
19
+ constructor(props: Props);
20
+ /**
21
+ * Subclasses of {@link WidgetRemoteSource} must implement this method, calling
22
+ * {@link WidgetRemoteSource.prototype._getModelSource} for common source
23
+ * properties, and adding additional required properties including 'type' and
24
+ * 'data'.
25
+ */
26
+ protected abstract getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
27
+ protected _getModelSource(filters: Filters | undefined, filterOwner?: string): Omit<ModelSource, 'type' | 'data'>;
28
+ protected _getSpatialFiltersResolution(source: Omit<ModelSource, 'type' | 'data'>, spatialFilter?: SpatialFilter, referenceViewState?: ViewState): number | undefined;
29
+ /**
30
+ * Returns a list of labeled datapoints for categorical data. Suitable for
31
+ * charts including grouped bar charts, pie charts, and tree charts.
32
+ */
33
+ abstract getCategories(options: CategoryRequestOptions): Promise<CategoryResponse>;
34
+ /**
35
+ * Given a list of feature IDs (as found in `_carto_feature_id`) returns all
36
+ * matching features. In datasets containing features with duplicate geometries,
37
+ * feature IDs may be duplicated (IDs are a hash of geometry) and so more
38
+ * results may be returned than IDs in the request.
39
+ * @internal
40
+ * @experimental
41
+ */
42
+ abstract getFeatures(options: FeaturesRequestOptions): Promise<FeaturesResponse>;
43
+ /**
44
+ * Returns a scalar numerical statistic over all matching data. Suitable
45
+ * for 'headline' or 'scorecard' figures such as counts and sums.
46
+ */
47
+ abstract getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
48
+ /**
49
+ * Returns a list of labeled datapoints for 'bins' of data defined as ticks
50
+ * over a numerical range. Suitable for histogram charts.
51
+ */
52
+ abstract getHistogram(options: HistogramRequestOptions): Promise<HistogramResponse>;
53
+ /**
54
+ * Returns a range (min and max) for a numerical column of matching rows.
55
+ * Suitable for displaying certain 'headline' or 'scorecard' statistics,
56
+ * or rendering a range slider UI for filtering.
57
+ */
58
+ abstract getRange(options: RangeRequestOptions): Promise<RangeResponse>;
59
+ /**
60
+ * Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
61
+ * values. Suitable for rendering scatter plots.
62
+ */
63
+ abstract getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
64
+ /**
65
+ * Returns a list of arbitrary data rows, with support for pagination and
66
+ * sorting. Suitable for displaying tables and lists.
67
+ */
68
+ abstract getTable(options: TableRequestOptions): Promise<TableResponse>;
69
+ /**
70
+ * Returns a series of labeled numerical values, grouped into equally-sized
71
+ * time intervals. Suitable for rendering time series charts.
72
+ */
73
+ abstract getTimeSeries(options: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
74
+ }
75
+ /**
76
+ * @todo TODO(v0.5): Remove WidgetBaseSourceProps alias
77
+ * @deprecated Use WidgetSourceProps.
78
+ */
79
+ export type WidgetBaseSourceProps = WidgetSourceProps;
80
+ /**
81
+ * @todo TODO(v0.5): Remove WidgetBaseSource alias.
82
+ * @deprecated Use WidgetSourceP.
83
+ */
84
+ export declare const WidgetBaseSource: typeof WidgetSource;
@@ -0,0 +1,34 @@
1
+ import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptions } from '../sources/index.js';
2
+ import { WidgetRemoteSource, WidgetRemoteSourceProps } from './widget-remote-source.js';
3
+ import { ModelSource } from '../models/model.js';
4
+ import { Filters } from '../types.js';
5
+ type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
6
+ export type WidgetTableSourceResult = {
7
+ widgetSource: WidgetTableSource;
8
+ };
9
+ /**
10
+ * Source for Widget API requests on a data source defined as a table.
11
+ *
12
+ * Generally not intended to be constructed directly. Instead, call
13
+ * {@link vectorTableSource}, {@link h3TableSource}, or {@link quadbinTableSource},
14
+ * which can be shared with map layers. Sources contain a `widgetSource` property,
15
+ * for use by widget implementations.
16
+ *
17
+ * Example:
18
+ *
19
+ * ```javascript
20
+ * import { vectorTableSource } from '@carto/api-client';
21
+ *
22
+ * const data = vectorTableSource({
23
+ * accessToken: '••••',
24
+ * connectionName: 'carto_dw',
25
+ * tableName: 'carto-demo-data.demo_tables.retail_stores'
26
+ * });
27
+ *
28
+ * const { widgetSource } = await data;
29
+ * ```
30
+ */
31
+ export declare class WidgetTableSource extends WidgetRemoteSource<LayerTableSourceOptions & WidgetRemoteSourceProps> {
32
+ protected getModelSource(filters: Filters | undefined, filterOwner?: string): ModelSource;
33
+ }
34
+ export {};
@@ -0,0 +1,75 @@
1
+ import { TilesetSourceOptions } from '../sources/index.js';
2
+ import type { ModelSource } from '../models/index.js';
3
+ import { CategoryRequestOptions, CategoryResponse, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
4
+ import { TileFormat } from '../constants.js';
5
+ import { Filters, SpatialFilter } from '../types.js';
6
+ import { TileFeatureExtractOptions } from '../filters/index.js';
7
+ import { FeatureCollection } from 'geojson';
8
+ import { SpatialDataType } from '../sources/types.js';
9
+ import { WidgetSource, WidgetSourceProps } from './widget-source.js';
10
+ export type WidgetTilesetSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters'> & {
11
+ tileFormat: TileFormat;
12
+ spatialDataType: SpatialDataType;
13
+ };
14
+ export type WidgetTilesetSourceResult = {
15
+ widgetSource: WidgetTilesetSource;
16
+ };
17
+ /**
18
+ * Source for Widget API requests on a data source defined by a tileset.
19
+ *
20
+ * Generally not intended to be constructed directly. Instead, call
21
+ * {@link vectorTilesetSource}, {@link h3TilesetSource}, or {@link quadbinTilesetSource},
22
+ * which can be shared with map layers. Sources contain a `widgetSource`
23
+ * property, for use by widget implementations.
24
+ *
25
+ * Example:
26
+ *
27
+ * ```javascript
28
+ * import { vectorTilesetSource } from '@carto/api-client';
29
+ *
30
+ * const data = vectorTilesetSource({
31
+ * accessToken: '••••',
32
+ * connectionName: 'carto_dw',
33
+ * tableName: 'carto-demo-data.demo_rasters.my_tileset_source'
34
+ * });
35
+ *
36
+ * const { widgetSource } = await data;
37
+ * ```
38
+ */
39
+ export declare class WidgetTilesetSource extends WidgetSource<WidgetTilesetSourceProps> {
40
+ private _tiles;
41
+ private _features;
42
+ private _tileFeatureExtractOptions;
43
+ private _tileFeatureExtractPreviousInputs;
44
+ protected getModelSource(filters: Filters | undefined, filterOwner: string): ModelSource;
45
+ /**
46
+ * Loads features as a list of tiles (typically provided by deck.gl).
47
+ * After tiles are loaded, {@link extractTileFeatures} must be called
48
+ * before computing statistics on the tiles.
49
+ */
50
+ loadTiles(tiles: unknown[]): void;
51
+ /** Configures options used to extract features from tiles. */
52
+ setTileFeatureExtractOptions(options: TileFeatureExtractOptions): void;
53
+ protected _extractTileFeatures(spatialFilter: SpatialFilter): void;
54
+ /**
55
+ * Loads features as GeoJSON (used for testing).
56
+ * @experimental
57
+ * @internal Not for public use. Spatial filters in other method calls will be ignored.
58
+ */
59
+ loadGeoJSON({ geojson, spatialFilter, }: {
60
+ geojson: FeatureCollection;
61
+ spatialFilter: SpatialFilter;
62
+ }): void;
63
+ getFeatures(): Promise<FeaturesResponse>;
64
+ getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
65
+ getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
66
+ getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: CategoryRequestOptions): Promise<CategoryResponse>;
67
+ getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
68
+ getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
69
+ getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
70
+ getRange({ column, filters, filterOwner, spatialFilter, }: RangeRequestOptions): Promise<RangeResponse>;
71
+ /****************************************************************************
72
+ * INTERNAL
73
+ */
74
+ private _getFilteredFeatures;
75
+ }
package/package.json CHANGED
@@ -8,27 +8,22 @@
8
8
  "homepage": "https://github.com/CartoDB/carto-api-client#readme",
9
9
  "author": "Don McCurdy <donmccurdy@carto.com>",
10
10
  "packageManager": "yarn@4.3.1",
11
- "version": "0.4.7-0",
11
+ "version": "0.4.7-alpha.1",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
15
15
  },
16
16
  "type": "module",
17
17
  "sideEffects": false,
18
+ "source": "src/index.ts",
19
+ "types": "./build/index.d.ts",
20
+ "main": "./build/api-client.cjs",
21
+ "module": "./build/api-client.modern.js",
18
22
  "exports": {
19
23
  ".": {
20
- "require": {
21
- "types": "./build/api-client.d.cts",
22
- "default": "./build/api-client.cjs"
23
- },
24
- "default": {
25
- "types": "./build/api-client.d.ts",
26
- "default": "./build/api-client.js"
27
- }
28
- },
29
- "./worker": {
30
- "types": "./build/worker.d.ts",
31
- "default": "./build/worker.js"
24
+ "types": "./build/index.d.ts",
25
+ "require": "./build/api-client.cjs",
26
+ "default": "./build/api-client.modern.js"
32
27
  }
33
28
  },
34
29
  "browserslist": [
@@ -37,8 +32,8 @@
37
32
  "node >= 18"
38
33
  ],
39
34
  "scripts": {
40
- "build": "tsup",
41
- "build:watch": "tsup --watch",
35
+ "build": "microbundle --format cjs,modern --no-compress --define __CARTO_API_CLIENT_VERSION=$npm_package_version",
36
+ "build:watch": "microbundle watch --format cjs,modern --no-compress --define __CARTO_API_CLIENT_VERSION=$npm_package_version",
42
37
  "dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
43
38
  "test": "vitest run --typecheck",
44
39
  "test:watch": "vitest watch --typecheck",
@@ -103,16 +98,20 @@
103
98
  "lit": "^3.2.1",
104
99
  "lit-analyzer": "^2.0.3",
105
100
  "maplibre-gl": "^5.1.0",
101
+ "microbundle": "^0.15.1",
106
102
  "prettier": "^3.4.2",
107
103
  "rimraf": "^6.0.1",
108
104
  "semver": "^7.7.1",
109
105
  "thenby": "^1.3.4",
110
106
  "tinybench": "^3.1.1",
111
- "tsup": "^8.3.6",
112
- "typescript": "~5.7.3",
107
+ "typescript": "~5.8.2",
113
108
  "typescript-eslint": "^8.24.0",
114
109
  "vite": "^6.1.0",
115
- "vitest": "3.0.5"
110
+ "vitest": "3.0.7"
116
111
  },
117
- "stableVersion": "0.4.6"
112
+ "resolutions": {
113
+ "@carto/api-client": "portal:./",
114
+ "rollup": "^4.20.0"
115
+ },
116
+ "stableVersion": "0.4.7"
118
117
  }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Current version of @carto/api-client.
3
+ * @internal
4
+ */
5
+ export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
6
+
1
7
  /** @internal */
2
8
  export const V3_MINOR_VERSION = '3.4';
3
9
 
@@ -8,6 +8,16 @@ type TimeFilter = Filters['string'][FilterType.TIME] & {
8
8
  params?: {offsetBy?: number};
9
9
  };
10
10
 
11
+ /**
12
+ * deck.gl's DataFilterExtension supports GPU filtering with 1–4 values. We
13
+ * allocate filters[0] to generic filters and filters[1] to time filters.
14
+ *
15
+ * getFilterValue() _must_ return an array of the same size as the filterSize
16
+ * used to initialize the DataFilterExtension. We document that users must use
17
+ * filterSize=4 for compatibility with @link {getDataFilterExtensionProps}.
18
+ */
19
+ const DEFAULT_FILTER_SIZE = 4;
20
+
11
21
  /** @experimental Prefer type definition from deck.gl. */
12
22
  export type _DataFilterExtensionProps = {
13
23
  filterRange: number[][];
@@ -17,22 +27,30 @@ export type _DataFilterExtensionProps = {
17
27
 
18
28
  /**
19
29
  * Creates props for DataFilterExtension, from `@deck.gl/extensions`, given
20
- * a set of filters.
30
+ * a set of filters. Requires that DataFilterExtension is initialized with
31
+ * filterSize=4, where the CARTO filters will occupy the first two slots.
32
+ *
33
+ * @example To create a deck.gl layer with GPU data filtering:
34
+ * ```typescript
35
+ * import {DataFilterExtension} from '@deck.gl/extensions';
36
+ * import {VectorTileLayer} from '@deck.gl/layers';
37
+ * import {getDataFilterExtensionProps} from '@carto/api-client';
21
38
  *
22
- * @privateRemarks DataFilterExtension accepts up to 4 values to filter. This
23
- * implementation uses the 1st for all filters except the time filter, and the
24
- * 2nd for the time filter.
39
+ * const layer = new VectorTileLayer({
40
+ * data: data,
41
+ * extensions: [new DataFilterExtension({filterSize: 4})],
42
+ * ...getDataFilterExtensionProps(filters),
43
+ * });
44
+ * ```
25
45
  */
26
46
  export function getDataFilterExtensionProps(
27
47
  filters: Filters,
28
- filtersLogicalOperator?: FilterLogicalOperator,
29
- filterSize?: 0 | 1 | 2 | 3 | 4
48
+ filtersLogicalOperator?: FilterLogicalOperator
30
49
  ): _DataFilterExtensionProps {
31
- filterSize ??= 4;
32
50
  const {filtersWithoutTimeType, timeColumn, timeFilter} =
33
51
  getFiltersByType(filters);
34
52
  return {
35
- filterRange: getFilterRange(timeFilter, filterSize),
53
+ filterRange: getFilterRange(timeFilter, DEFAULT_FILTER_SIZE),
36
54
  updateTriggers: getUpdateTriggers(
37
55
  filtersWithoutTimeType,
38
56
  timeColumn,
@@ -42,7 +60,7 @@ export function getDataFilterExtensionProps(
42
60
  filtersWithoutTimeType,
43
61
  timeColumn,
44
62
  timeFilter,
45
- filterSize,
63
+ DEFAULT_FILTER_SIZE,
46
64
  filtersLogicalOperator
47
65
  ),
48
66
  };
@@ -20,7 +20,6 @@ export type TileFeatures = {
20
20
  /** @privateRemarks Source: @carto/react-core */
21
21
  export type TileFeatureExtractOptions = {
22
22
  storeGeometry?: boolean;
23
- uniqueIdProperty?: string;
24
23
  };
25
24
 
26
25
  /** @privateRemarks Source: @carto/react-core */
package/src/global.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ /**
2
+ * Injected by microbundle, with:
3
+ * ```
4
+ * --define __CARTO_API_CLIENT_VERSION=$npm_package_version
5
+ * ```
6
+ */
7
+ declare const __CARTO_API_CLIENT_VERSION: string;
8
+
1
9
  /** Defined by @deck.gl/core. */
2
10
  declare const deck: {VERSION: string | undefined} | undefined;
3
-
4
- /** Defined by tsup. */
5
- declare const TSUP_FORMAT: 'esm' | 'cjs';
@@ -2,11 +2,6 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {getTileFormat} from '../utils/getTileFormat.js';
6
- import {
7
- WidgetTilesetSource,
8
- WidgetTilesetSourceResult,
9
- } from '../widget-sources/index.js';
10
5
  import {baseSource} from './base-source.js';
11
6
  import type {
12
7
  SourceOptions,
@@ -17,24 +12,17 @@ import type {
17
12
  export type H3TilesetSourceOptions = SourceOptions & TilesetSourceOptions;
18
13
  type UrlParameters = {name: string};
19
14
 
20
- export type H3TilesetSourceResponse = TilejsonResult &
21
- WidgetTilesetSourceResult;
15
+ export type H3TilesetSourceResponse = TilejsonResult;
22
16
 
23
17
  export const h3TilesetSource = async function (
24
18
  options: H3TilesetSourceOptions
25
19
  ): Promise<H3TilesetSourceResponse> {
26
- const {tableName, spatialDataColumn = 'h3'} = options;
20
+ const {tableName} = options;
27
21
  const urlParameters: UrlParameters = {name: tableName};
28
22
 
29
- return baseSource<UrlParameters>('tileset', options, urlParameters).then(
30
- (result) => ({
31
- ...(result as TilejsonResult),
32
- widgetSource: new WidgetTilesetSource({
33
- ...options,
34
- tileFormat: getTileFormat(result as TilejsonResult),
35
- spatialDataColumn,
36
- spatialDataType: 'h3',
37
- }),
38
- })
23
+ return baseSource<UrlParameters>(
24
+ 'tileset',
25
+ options,
26
+ urlParameters
39
27
  ) as Promise<H3TilesetSourceResponse>;
40
28
  };
@@ -2,11 +2,6 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {getTileFormat} from '../utils/getTileFormat.js';
6
- import {
7
- WidgetTilesetSource,
8
- WidgetTilesetSourceResult,
9
- } from '../widget-sources/index.js';
10
5
  import {baseSource} from './base-source.js';
11
6
  import type {
12
7
  SourceOptions,
@@ -17,24 +12,17 @@ import type {
17
12
  export type QuadbinTilesetSourceOptions = SourceOptions & TilesetSourceOptions;
18
13
  type UrlParameters = {name: string};
19
14
 
20
- export type QuadbinTilesetSourceResponse = TilejsonResult &
21
- WidgetTilesetSourceResult;
15
+ export type QuadbinTilesetSourceResponse = TilejsonResult;
22
16
 
23
17
  export const quadbinTilesetSource = async function (
24
18
  options: QuadbinTilesetSourceOptions
25
19
  ): Promise<QuadbinTilesetSourceResponse> {
26
- const {tableName, spatialDataColumn = 'quadbin'} = options;
20
+ const {tableName} = options;
27
21
  const urlParameters: UrlParameters = {name: tableName};
28
22
 
29
- return baseSource<UrlParameters>('tileset', options, urlParameters).then(
30
- (result) => ({
31
- ...(result as TilejsonResult),
32
- widgetSource: new WidgetTilesetSource({
33
- ...options,
34
- tileFormat: getTileFormat(result as TilejsonResult),
35
- spatialDataColumn,
36
- spatialDataType: 'quadbin',
37
- }),
38
- })
23
+ return baseSource<UrlParameters>(
24
+ 'tileset',
25
+ options,
26
+ urlParameters
39
27
  ) as Promise<QuadbinTilesetSourceResponse>;
40
28
  };