@carto/api-client 0.3.1 → 0.4.0-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.
- package/build/api/carto-api-error.d.ts +26 -0
- package/build/api/endpoints.d.ts +24 -0
- package/build/api/index.d.ts +5 -0
- package/build/api/query.d.ts +3 -0
- package/build/api/request-with-parameters.d.ts +8 -0
- package/build/api-client.cjs +724 -65
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +607 -59
- package/build/api-client.modern.js.map +1 -1
- package/build/constants-internal.d.ts +9 -28
- package/build/constants.d.ts +24 -2
- package/build/index.d.ts +5 -1
- package/build/models/model.d.ts +2 -2
- package/build/sources/base-source.d.ts +4 -0
- package/build/sources/boundary-query-source.d.ts +9 -0
- package/build/sources/boundary-table-source.d.ts +7 -0
- package/build/sources/h3-query-source.d.ts +3 -0
- package/build/sources/h3-table-source.d.ts +3 -0
- package/build/sources/h3-tileset-source.d.ts +3 -0
- package/build/sources/index.d.ts +27 -5
- package/build/sources/quadbin-query-source.d.ts +3 -0
- package/build/sources/quadbin-table-source.d.ts +3 -0
- package/build/sources/quadbin-tileset-source.d.ts +3 -0
- package/build/sources/raster-source.d.ts +3 -0
- package/build/sources/types.d.ts +209 -85
- package/build/sources/vector-query-source.d.ts +3 -0
- package/build/sources/vector-table-source.d.ts +3 -0
- package/build/sources/vector-tileset-source.d.ts +3 -0
- package/build/types-internal.d.ts +46 -1
- package/build/types.d.ts +11 -0
- package/build/utils.d.ts +4 -0
- package/build/widget-sources/index.d.ts +5 -0
- package/build/widget-sources/types.d.ts +95 -0
- package/build/{sources → widget-sources}/widget-base-source.d.ts +2 -2
- package/build/{sources → widget-sources}/widget-query-source.d.ts +1 -1
- package/build/{sources → widget-sources}/widget-table-source.d.ts +1 -1
- package/build/{sources → widget-sources}/wrappers.d.ts +1 -1
- package/package.json +4 -3
- package/src/api/carto-api-error.ts +88 -0
- package/src/api/endpoints.ts +84 -0
- package/src/api/index.ts +14 -0
- package/src/api/query.ts +56 -0
- package/src/api/request-with-parameters.ts +135 -0
- package/src/constants-internal.ts +9 -30
- package/src/constants.ts +32 -3
- package/src/global.d.ts +3 -0
- package/src/index.ts +38 -1
- package/src/models/model.ts +4 -6
- package/src/sources/base-source.ts +101 -0
- package/src/sources/boundary-query-source.ts +53 -0
- package/src/sources/boundary-table-source.ts +41 -0
- package/src/sources/h3-query-source.ts +63 -0
- package/src/sources/h3-table-source.ts +59 -0
- package/src/sources/h3-tileset-source.ts +26 -0
- package/src/sources/index.ts +54 -5
- package/src/sources/quadbin-query-source.ts +64 -0
- package/src/sources/quadbin-table-source.ts +60 -0
- package/src/sources/quadbin-tileset-source.ts +26 -0
- package/src/sources/raster-source.ts +34 -0
- package/src/sources/types.ts +221 -89
- package/src/sources/vector-query-source.ts +65 -0
- package/src/sources/vector-table-source.ts +59 -0
- package/src/sources/vector-tileset-source.ts +26 -0
- package/src/types-internal.ts +54 -1
- package/src/types.ts +16 -0
- package/src/utils.ts +8 -0
- package/src/widget-sources/index.ts +5 -0
- package/src/widget-sources/types.ts +105 -0
- package/src/{sources → widget-sources}/widget-base-source.ts +5 -5
- package/src/{sources → widget-sources}/widget-query-source.ts +2 -3
- package/src/{sources → widget-sources}/widget-table-source.ts +2 -3
- package/src/{sources → widget-sources}/wrappers.ts +1 -22
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GroupDateType,
|
|
3
|
+
SortColumnType,
|
|
4
|
+
SortDirection,
|
|
5
|
+
SpatialFilter,
|
|
6
|
+
} from '../types';
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
* WIDGET API REQUESTS
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Common options for {@link WidgetBaseSource} requests. */
|
|
13
|
+
interface BaseRequestOptions {
|
|
14
|
+
spatialFilter?: SpatialFilter;
|
|
15
|
+
abortController?: AbortController;
|
|
16
|
+
filterOwner?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Options for {@link WidgetBaseSource#getCategories}. */
|
|
20
|
+
export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
21
|
+
column: string;
|
|
22
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
23
|
+
operationColumn?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
27
|
+
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
28
|
+
column: string;
|
|
29
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
30
|
+
operationExp?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Options for {@link WidgetBaseSource#getHistogram}. */
|
|
34
|
+
export interface HistogramRequestOptions extends BaseRequestOptions {
|
|
35
|
+
column: string;
|
|
36
|
+
ticks: number[];
|
|
37
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Options for {@link WidgetBaseSource#getRange}. */
|
|
41
|
+
export interface RangeRequestOptions extends BaseRequestOptions {
|
|
42
|
+
column: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Options for {@link WidgetBaseSource#getScatter}. */
|
|
46
|
+
export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
47
|
+
xAxisColumn: string;
|
|
48
|
+
xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
49
|
+
yAxisColumn: string;
|
|
50
|
+
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Options for {@link WidgetBaseSource#getTable}. */
|
|
54
|
+
export interface TableRequestOptions extends BaseRequestOptions {
|
|
55
|
+
columns: string[];
|
|
56
|
+
sortBy?: string;
|
|
57
|
+
sortDirection?: SortDirection;
|
|
58
|
+
sortByColumnType?: SortColumnType;
|
|
59
|
+
offset?: number;
|
|
60
|
+
limit?: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Options for {@link WidgetBaseSource#getTimeSeries}. */
|
|
64
|
+
export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
65
|
+
column: string;
|
|
66
|
+
stepSize?: GroupDateType;
|
|
67
|
+
stepMultiplier?: number;
|
|
68
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
69
|
+
operationColumn?: string;
|
|
70
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
71
|
+
splitByCategory?: string;
|
|
72
|
+
splitByCategoryLimit?: number;
|
|
73
|
+
splitByCategoryValues?: string[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/******************************************************************************
|
|
77
|
+
* WIDGET API RESPONSES
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/** Response from {@link WidgetBaseSource#getFormula}. */
|
|
81
|
+
export type FormulaResponse = {value: number};
|
|
82
|
+
|
|
83
|
+
/** Response from {@link WidgetBaseSource#getCategories}. */
|
|
84
|
+
export type CategoryResponse = {name: string; value: number}[];
|
|
85
|
+
|
|
86
|
+
/** Response from {@link WidgetBaseSource#getRange}. */
|
|
87
|
+
export type RangeResponse = {min: number; max: number};
|
|
88
|
+
|
|
89
|
+
/** Response from {@link WidgetBaseSource#getTable}. */
|
|
90
|
+
export type TableResponse = {
|
|
91
|
+
totalCount: number;
|
|
92
|
+
rows: Record<string, number | string>[];
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** Response from {@link WidgetBaseSource#getScatter}. */
|
|
96
|
+
export type ScatterResponse = [number, number][];
|
|
97
|
+
|
|
98
|
+
/** Response from {@link WidgetBaseSource#getTimeSeries}. */
|
|
99
|
+
export type TimeSeriesResponse = {
|
|
100
|
+
rows: {name: string; value: number}[];
|
|
101
|
+
categories: string[];
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Response from {@link WidgetBaseSource#getHistogram}. */
|
|
105
|
+
export type HistogramResponse = number[];
|
|
@@ -16,15 +16,15 @@ import {
|
|
|
16
16
|
TimeSeriesResponse,
|
|
17
17
|
} from './types.js';
|
|
18
18
|
import {FilterLogicalOperator, Filter} from '../types.js';
|
|
19
|
-
import {SourceOptions} from '@deck.gl/carto';
|
|
20
19
|
import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
|
|
20
|
+
import {getClient} from '../client.js';
|
|
21
|
+
import {ModelSource} from '../models/model.js';
|
|
22
|
+
import {SourceOptions} from '../sources/index.js';
|
|
21
23
|
import {
|
|
24
|
+
ApiVersion,
|
|
22
25
|
DEFAULT_API_BASE_URL,
|
|
23
26
|
DEFAULT_GEO_COLUMN,
|
|
24
|
-
|
|
25
|
-
} from '../constants-internal.js';
|
|
26
|
-
import {getClient} from '../client.js';
|
|
27
|
-
import {ModelSource} from '../models/model.js';
|
|
27
|
+
} from '../constants.js';
|
|
28
28
|
|
|
29
29
|
export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
30
30
|
apiVersion?: ApiVersion;
|
|
@@ -2,8 +2,7 @@ import {
|
|
|
2
2
|
H3QuerySourceOptions,
|
|
3
3
|
QuadbinQuerySourceOptions,
|
|
4
4
|
VectorQuerySourceOptions,
|
|
5
|
-
} from '
|
|
6
|
-
import {MapType} from '../constants-internal.js';
|
|
5
|
+
} from '../sources/index.js';
|
|
7
6
|
import {WidgetBaseSource, WidgetBaseSourceProps} from './widget-base-source.js';
|
|
8
7
|
import {ModelSource} from '../models/model.js';
|
|
9
8
|
|
|
@@ -40,7 +39,7 @@ export class WidgetQuerySource extends WidgetBaseSource<
|
|
|
40
39
|
protected override getModelSource(owner: string): ModelSource {
|
|
41
40
|
return {
|
|
42
41
|
...super._getModelSource(owner),
|
|
43
|
-
type:
|
|
42
|
+
type: 'query',
|
|
44
43
|
data: this.props.sqlQuery,
|
|
45
44
|
queryParameters: this.props.queryParameters,
|
|
46
45
|
};
|
|
@@ -2,9 +2,8 @@ import {
|
|
|
2
2
|
H3TableSourceOptions,
|
|
3
3
|
QuadbinTableSourceOptions,
|
|
4
4
|
VectorTableSourceOptions,
|
|
5
|
-
} from '
|
|
5
|
+
} from '../sources/index.js';
|
|
6
6
|
import {WidgetBaseSource, WidgetBaseSourceProps} from './widget-base-source.js';
|
|
7
|
-
import {MapType} from '../constants-internal.js';
|
|
8
7
|
import {ModelSource} from '../models/model.js';
|
|
9
8
|
|
|
10
9
|
type LayerTableSourceOptions =
|
|
@@ -40,7 +39,7 @@ export class WidgetTableSource extends WidgetBaseSource<
|
|
|
40
39
|
protected override getModelSource(owner: string): ModelSource {
|
|
41
40
|
return {
|
|
42
41
|
...super._getModelSource(owner),
|
|
43
|
-
type:
|
|
42
|
+
type: 'table',
|
|
44
43
|
data: this.props.tableName,
|
|
45
44
|
};
|
|
46
45
|
}
|
|
@@ -11,8 +11,7 @@ import {
|
|
|
11
11
|
H3QuerySourceOptions as _H3QuerySourceOptions,
|
|
12
12
|
QuadbinTableSourceOptions as _QuadbinTableSourceOptions,
|
|
13
13
|
QuadbinQuerySourceOptions as _QuadbinQuerySourceOptions,
|
|
14
|
-
|
|
15
|
-
} from '@deck.gl/carto';
|
|
14
|
+
} from '../sources/index.js';
|
|
16
15
|
import {WidgetBaseSourceProps} from './widget-base-source.js';
|
|
17
16
|
import {WidgetQuerySource} from './widget-query-source.js';
|
|
18
17
|
import {WidgetTableSource} from './widget-table-source.js';
|
|
@@ -55,7 +54,6 @@ export type VectorQuerySourceOptions =
|
|
|
55
54
|
export async function vectorTableSource(
|
|
56
55
|
props: VectorTableSourceOptions
|
|
57
56
|
): Promise<VectorTableSourceResponse> {
|
|
58
|
-
assignDefaultProps(props);
|
|
59
57
|
const response = await _vectorTableSource(props as _VectorTableSourceOptions);
|
|
60
58
|
return {...response, widgetSource: new WidgetTableSource(props)};
|
|
61
59
|
}
|
|
@@ -64,7 +62,6 @@ export async function vectorTableSource(
|
|
|
64
62
|
export async function vectorQuerySource(
|
|
65
63
|
props: VectorQuerySourceOptions
|
|
66
64
|
): Promise<VectorQuerySourceResponse> {
|
|
67
|
-
assignDefaultProps(props);
|
|
68
65
|
const response = await _vectorQuerySource(props as _VectorQuerySourceOptions);
|
|
69
66
|
return {...response, widgetSource: new WidgetQuerySource(props)};
|
|
70
67
|
}
|
|
@@ -80,7 +77,6 @@ export type H3QuerySourceOptions = WrappedSourceOptions<_H3QuerySourceOptions>;
|
|
|
80
77
|
export async function h3TableSource(
|
|
81
78
|
props: H3TableSourceOptions
|
|
82
79
|
): Promise<H3TableSourceResponse> {
|
|
83
|
-
assignDefaultProps(props);
|
|
84
80
|
const response = await _h3TableSource(props as _H3TableSourceOptions);
|
|
85
81
|
return {...response, widgetSource: new WidgetTableSource(props)};
|
|
86
82
|
}
|
|
@@ -89,7 +85,6 @@ export async function h3TableSource(
|
|
|
89
85
|
export async function h3QuerySource(
|
|
90
86
|
props: H3QuerySourceOptions
|
|
91
87
|
): Promise<H3QuerySourceResponse> {
|
|
92
|
-
assignDefaultProps(props);
|
|
93
88
|
const response = await _h3QuerySource(props as _H3QuerySourceOptions);
|
|
94
89
|
return {...response, widgetSource: new WidgetQuerySource(props)};
|
|
95
90
|
}
|
|
@@ -108,7 +103,6 @@ export type QuadbinQuerySourceOptions =
|
|
|
108
103
|
export async function quadbinTableSource(
|
|
109
104
|
props: QuadbinTableSourceOptions & WidgetBaseSourceProps
|
|
110
105
|
): Promise<QuadbinTableSourceResponse> {
|
|
111
|
-
assignDefaultProps(props);
|
|
112
106
|
const response = await _quadbinTableSource(
|
|
113
107
|
props as _QuadbinTableSourceOptions
|
|
114
108
|
);
|
|
@@ -119,23 +113,8 @@ export async function quadbinTableSource(
|
|
|
119
113
|
export async function quadbinQuerySource(
|
|
120
114
|
props: QuadbinQuerySourceOptions & WidgetBaseSourceProps
|
|
121
115
|
): Promise<QuadbinQuerySourceResponse> {
|
|
122
|
-
assignDefaultProps(props);
|
|
123
116
|
const response = await _quadbinQuerySource(
|
|
124
117
|
props as _QuadbinQuerySourceOptions
|
|
125
118
|
);
|
|
126
119
|
return {...response, widgetSource: new WidgetQuerySource(props)};
|
|
127
120
|
}
|
|
128
|
-
|
|
129
|
-
/******************************************************************************
|
|
130
|
-
* DEFAULT PROPS
|
|
131
|
-
*/
|
|
132
|
-
|
|
133
|
-
declare const deck: {VERSION?: string} | undefined;
|
|
134
|
-
function assignDefaultProps<T extends SourceOptions>(props: T): void {
|
|
135
|
-
if (typeof deck !== 'undefined' && deck && deck.VERSION) {
|
|
136
|
-
props.clientId ||= 'deck-gl-carto';
|
|
137
|
-
// TODO: Uncomment if/when `@deck.gl/carto` devDependency is removed,
|
|
138
|
-
// and source functions are moved here rather than wrapped.
|
|
139
|
-
// props.deckglVersion ||= deck.VERSION;
|
|
140
|
-
}
|
|
141
|
-
}
|