@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
@@ -1,149 +0,0 @@
1
- import { SpatialFilterPolyfillMode, TileResolution } from '../sources/types';
2
- import { GroupDateType, SortColumnType, SortDirection, SpatialFilter } from '../types';
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 WidgetBaseSource} requests. */
12
- interface BaseRequestOptions {
13
- spatialFilter?: SpatialFilter;
14
- spatialFiltersMode?: SpatialFilterPolyfillMode;
15
- /** Required for table- and query-based spatial index sources (H3, Quadbin). */
16
- spatialIndexReferenceViewState?: ViewState;
17
- abortController?: AbortController;
18
- filterOwner?: string;
19
- }
20
- /** Options for {@link WidgetBaseSource#getCategories}. */
21
- export interface CategoryRequestOptions extends BaseRequestOptions {
22
- column: string;
23
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
24
- operationColumn?: string;
25
- }
26
- /**
27
- * Options for {@link WidgetBaseSource#getFeatures}.
28
- * @experimental
29
- * @internal
30
- */
31
- export interface FeaturesRequestOptions extends BaseRequestOptions {
32
- /**
33
- * Feature IDs, as found in `_carto_feature_id`. Feature IDs are a hash
34
- * of geometry, and features with identical geometry will have the same
35
- * feature ID. Order is important; features in the result set will be
36
- * sorted according to the order of IDs in the request.
37
- */
38
- featureIds: string[];
39
- /**
40
- * Columns to be returned for each picked object. Note that for datasets
41
- * containing features with identical geometry, more than one result per
42
- * requested feature ID may be returned. To match results back to the
43
- * requested feature ID, include `_carto_feature_id` in the columns list.
44
- */
45
- columns: string[];
46
- /** Topology of objects to be picked. */
47
- dataType: 'points' | 'lines' | 'polygons';
48
- /** Zoom level, required if using 'points' data type. */
49
- z?: number;
50
- /**
51
- * Maximum number of objects to return in the result set. For datasets
52
- * containing features with identical geometry, those features will have
53
- * the same feature IDs, and so more results may be returned than feature IDs
54
- * given in the request.
55
- */
56
- limit?: number;
57
- /**
58
- * Must match `tileResolution` used when obtaining the `_carto_feature_id`
59
- * column, typically in a layer's tile requests.
60
- */
61
- tileResolution?: TileResolution;
62
- }
63
- /** Options for {@link WidgetBaseSource#getFormula}. */
64
- export interface FormulaRequestOptions extends BaseRequestOptions {
65
- column: string;
66
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
67
- operationExp?: string;
68
- }
69
- /** Options for {@link WidgetBaseSource#getHistogram}. */
70
- export interface HistogramRequestOptions extends BaseRequestOptions {
71
- column: string;
72
- ticks: number[];
73
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
74
- }
75
- /** Options for {@link WidgetBaseSource#getRange}. */
76
- export interface RangeRequestOptions extends BaseRequestOptions {
77
- column: string;
78
- }
79
- /** Options for {@link WidgetBaseSource#getScatter}. */
80
- export interface ScatterRequestOptions extends BaseRequestOptions {
81
- xAxisColumn: string;
82
- xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
83
- yAxisColumn: string;
84
- yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
85
- }
86
- /** Options for {@link WidgetBaseSource#getTable}. */
87
- export interface TableRequestOptions extends BaseRequestOptions {
88
- columns: string[];
89
- sortBy?: string;
90
- sortDirection?: SortDirection;
91
- sortByColumnType?: SortColumnType;
92
- offset?: number;
93
- limit?: number;
94
- }
95
- /** Options for {@link WidgetBaseSource#getTimeSeries}. */
96
- export interface TimeSeriesRequestOptions extends BaseRequestOptions {
97
- column: string;
98
- stepSize?: GroupDateType;
99
- stepMultiplier?: number;
100
- operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
101
- operationColumn?: string;
102
- joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
103
- splitByCategory?: string;
104
- splitByCategoryLimit?: number;
105
- splitByCategoryValues?: string[];
106
- }
107
- /******************************************************************************
108
- * WIDGET API RESPONSES
109
- */
110
- /**
111
- * Response from {@link WidgetBaseSource#getFeatures}.
112
- * @experimental
113
- * @internal
114
- */
115
- export type FeaturesResponse = {
116
- rows: Record<string, unknown>[];
117
- };
118
- /** Response from {@link WidgetBaseSource#getFormula}. */
119
- export type FormulaResponse = {
120
- value: number;
121
- };
122
- /** Response from {@link WidgetBaseSource#getCategories}. */
123
- export type CategoryResponse = {
124
- name: string;
125
- value: number;
126
- }[];
127
- /** Response from {@link WidgetBaseSource#getRange}. */
128
- export type RangeResponse = {
129
- min: number;
130
- max: number;
131
- };
132
- /** Response from {@link WidgetBaseSource#getTable}. */
133
- export type TableResponse = {
134
- totalCount: number;
135
- rows: Record<string, number | string>[];
136
- };
137
- /** Response from {@link WidgetBaseSource#getScatter}. */
138
- export type ScatterResponse = [number, number][];
139
- /** Response from {@link WidgetBaseSource#getTimeSeries}. */
140
- export type TimeSeriesResponse = {
141
- rows: {
142
- name: string;
143
- value: number;
144
- }[];
145
- categories: string[];
146
- };
147
- /** Response from {@link WidgetBaseSource#getHistogram}. */
148
- export type HistogramResponse = number[];
149
- export {};
@@ -1,99 +0,0 @@
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 } 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 WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
7
- apiVersion?: ApiVersion;
8
- filters?: Record<string, Filter>;
9
- filtersLogicalOperator?: FilterLogicalOperator;
10
- }
11
- export type WidgetSource = WidgetBaseSource<WidgetBaseSourceProps>;
12
- /**
13
- * Source for Widget API requests on a data source defined by a SQL query.
14
- *
15
- * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
16
- */
17
- export declare abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
18
- readonly props: Props;
19
- static defaultProps: Partial<WidgetBaseSourceProps>;
20
- constructor(props: Props);
21
- /**
22
- * Subclasses of {@link WidgetBaseSource} must implement this method, calling
23
- * {@link WidgetBaseSource.prototype._getModelSource} for common source
24
- * properties, and adding additional required properties including 'type' and
25
- * 'data'.
26
- */
27
- protected abstract getModelSource(owner: string | undefined): ModelSource;
28
- protected _getModelSource(owner?: string): Omit<ModelSource, 'type' | 'data'>;
29
- protected _getSpatialFiltersResolution(source: Omit<ModelSource, 'type' | 'data'>, spatialFilter?: SpatialFilter, referenceViewState?: ViewState): number | undefined;
30
- /****************************************************************************
31
- * CATEGORIES
32
- */
33
- /**
34
- * Returns a list of labeled datapoints for categorical data. Suitable for
35
- * charts including grouped bar charts, pie charts, and tree charts.
36
- */
37
- getCategories(options: CategoryRequestOptions): Promise<CategoryResponse>;
38
- /****************************************************************************
39
- * FEATURES
40
- */
41
- /**
42
- * Given a list of feature IDs (as found in `_carto_feature_id`) returns all
43
- * matching features. In datasets containing features with duplicate geometries,
44
- * feature IDs may be duplicated (IDs are a hash of geometry) and so more
45
- * results may be returned than IDs in the request.
46
- * @internal
47
- * @experimental
48
- */
49
- getFeatures(options: FeaturesRequestOptions): Promise<FeaturesResponse>;
50
- /****************************************************************************
51
- * FORMULA
52
- */
53
- /**
54
- * Returns a scalar numerical statistic over all matching data. Suitable
55
- * for 'headline' or 'scorecard' figures such as counts and sums.
56
- */
57
- getFormula(options: FormulaRequestOptions): Promise<FormulaResponse>;
58
- /****************************************************************************
59
- * HISTOGRAM
60
- */
61
- /**
62
- * Returns a list of labeled datapoints for 'bins' of data defined as ticks
63
- * over a numerical range. Suitable for histogram charts.
64
- */
65
- getHistogram(options: HistogramRequestOptions): Promise<HistogramResponse>;
66
- /****************************************************************************
67
- * RANGE
68
- */
69
- /**
70
- * Returns a range (min and max) for a numerical column of matching rows.
71
- * Suitable for displaying certain 'headline' or 'scorecard' statistics,
72
- * or rendering a range slider UI for filtering.
73
- */
74
- getRange(options: RangeRequestOptions): Promise<RangeResponse>;
75
- /****************************************************************************
76
- * SCATTER
77
- */
78
- /**
79
- * Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
80
- * values. Suitable for rendering scatter plots.
81
- */
82
- getScatter(options: ScatterRequestOptions): Promise<ScatterResponse>;
83
- /****************************************************************************
84
- * TABLE
85
- */
86
- /**
87
- * Returns a list of arbitrary data rows, with support for pagination and
88
- * sorting. Suitable for displaying tables and lists.
89
- */
90
- getTable(options: TableRequestOptions): Promise<TableResponse>;
91
- /****************************************************************************
92
- * TIME SERIES
93
- */
94
- /**
95
- * Returns a series of labeled numerical values, grouped into equally-sized
96
- * time intervals. Suitable for rendering time series charts.
97
- */
98
- getTimeSeries(options: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
99
- }
@@ -1,33 +0,0 @@
1
- import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptions } from '../sources/index.js';
2
- import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
- import { ModelSource } from '../models/model.js';
4
- type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
5
- export type WidgetQuerySourceResult = {
6
- widgetSource: WidgetQuerySource;
7
- };
8
- /**
9
- * Source for Widget API requests on a data source defined by a SQL query.
10
- *
11
- * Generally not intended to be constructed directly. Instead, call
12
- * {@link vectorQuerySource}, {@link h3QuerySource}, or {@link quadbinQuerySource},
13
- * which can be shared with map layers. Sources contain a `widgetSource` property,
14
- * for use by widget implementations.
15
- *
16
- * Example:
17
- *
18
- * ```javascript
19
- * import { vectorQuerySource } from '@carto/api-client';
20
- *
21
- * const data = vectorQuerySource({
22
- * accessToken: '••••',
23
- * connectionName: 'carto_dw',
24
- * sqlQuery: 'SELECT * FROM carto-demo-data.demo_tables.retail_stores'
25
- * });
26
- *
27
- * const { widgetSource } = await data;
28
- * ```
29
- */
30
- export declare class WidgetQuerySource extends WidgetBaseSource<LayerQuerySourceOptions & WidgetBaseSourceProps> {
31
- protected getModelSource(owner: string): ModelSource;
32
- }
33
- export {};
@@ -1,33 +0,0 @@
1
- import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptions } from '../sources/index.js';
2
- import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
- import { ModelSource } from '../models/model.js';
4
- type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
5
- export type WidgetTableSourceResult = {
6
- widgetSource: WidgetTableSource;
7
- };
8
- /**
9
- * Source for Widget API requests on a data source defined as a table.
10
- *
11
- * Generally not intended to be constructed directly. Instead, call
12
- * {@link vectorTableSource}, {@link h3TableSource}, or {@link quadbinTableSource},
13
- * which can be shared with map layers. Sources contain a `widgetSource` property,
14
- * for use by widget implementations.
15
- *
16
- * Example:
17
- *
18
- * ```javascript
19
- * import { vectorTableSource } from '@carto/api-client';
20
- *
21
- * const data = vectorTableSource({
22
- * accessToken: '••••',
23
- * connectionName: 'carto_dw',
24
- * tableName: 'carto-demo-data.demo_tables.retail_stores'
25
- * });
26
- *
27
- * const { widgetSource } = await data;
28
- * ```
29
- */
30
- export declare class WidgetTableSource extends WidgetBaseSource<LayerTableSourceOptions & WidgetBaseSourceProps> {
31
- protected getModelSource(owner: string): ModelSource;
32
- }
33
- export {};