@carto/api-client 0.0.43 → 0.1.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.
- package/build/api-client.cjs +42 -21
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +41 -22
- package/build/api-client.modern.js.map +1 -1
- package/build/constants.d.ts +0 -14
- package/build/filters.d.ts +11 -0
- package/build/sources/types.d.ts +10 -11
- package/build/types.d.ts +10 -1
- package/package.json +1 -1
- package/src/constants.ts +0 -15
- package/src/filters.ts +50 -1
- package/src/sources/types.ts +10 -11
- package/src/sources/widget-base-source.ts +3 -3
- package/src/types.ts +19 -1
package/build/sources/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { GroupDateType } from '../
|
|
2
|
-
import { AggregationType, SortColumnType, SortDirection, SpatialFilter } from '../types';
|
|
1
|
+
import { GroupDateType, SortColumnType, SortDirection, SpatialFilter } from '../types';
|
|
3
2
|
/******************************************************************************
|
|
4
3
|
* WIDGET API REQUESTS
|
|
5
4
|
*/
|
|
@@ -12,20 +11,20 @@ interface BaseRequestOptions {
|
|
|
12
11
|
/** Options for {@link WidgetBaseSource#getCategories}. */
|
|
13
12
|
export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
14
13
|
column: string;
|
|
15
|
-
operation?:
|
|
14
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
16
15
|
operationColumn?: string;
|
|
17
16
|
}
|
|
18
17
|
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
19
18
|
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
20
19
|
column: string;
|
|
21
|
-
operation?:
|
|
20
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
22
21
|
operationExp?: string;
|
|
23
22
|
}
|
|
24
23
|
/** Options for {@link WidgetBaseSource#getHistogram}. */
|
|
25
24
|
export interface HistogramRequestOptions extends BaseRequestOptions {
|
|
26
25
|
column: string;
|
|
27
26
|
ticks: number[];
|
|
28
|
-
operation?:
|
|
27
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
29
28
|
}
|
|
30
29
|
/** Options for {@link WidgetBaseSource#getRange}. */
|
|
31
30
|
export interface RangeRequestOptions extends BaseRequestOptions {
|
|
@@ -34,9 +33,9 @@ export interface RangeRequestOptions extends BaseRequestOptions {
|
|
|
34
33
|
/** Options for {@link WidgetBaseSource#getScatter}. */
|
|
35
34
|
export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
36
35
|
xAxisColumn: string;
|
|
37
|
-
xAxisJoinOperation?:
|
|
36
|
+
xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
38
37
|
yAxisColumn: string;
|
|
39
|
-
yAxisJoinOperation?:
|
|
38
|
+
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
40
39
|
}
|
|
41
40
|
/** Options for {@link WidgetBaseSource#getTable}. */
|
|
42
41
|
export interface TableRequestOptions extends BaseRequestOptions {
|
|
@@ -44,17 +43,17 @@ export interface TableRequestOptions extends BaseRequestOptions {
|
|
|
44
43
|
sortBy?: string;
|
|
45
44
|
sortDirection?: SortDirection;
|
|
46
45
|
sortByColumnType?: SortColumnType;
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
offset?: number;
|
|
47
|
+
limit?: number;
|
|
49
48
|
}
|
|
50
49
|
/** Options for {@link WidgetBaseSource#getTimeSeries}. */
|
|
51
50
|
export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
52
51
|
column: string;
|
|
53
52
|
stepSize?: GroupDateType;
|
|
54
53
|
stepMultiplier?: number;
|
|
55
|
-
operation?:
|
|
54
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
56
55
|
operationColumn?: string;
|
|
57
|
-
joinOperation?:
|
|
56
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
58
57
|
splitByCategory?: string;
|
|
59
58
|
splitByCategoryLimit?: number;
|
|
60
59
|
splitByCategoryValues?: string[];
|
package/build/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FilterType } from './constants';
|
|
1
|
+
import type { FilterType } from './constants.js';
|
|
2
2
|
/******************************************************************************
|
|
3
3
|
* AGGREGATION
|
|
4
4
|
*/
|
|
@@ -41,6 +41,15 @@ export interface Filter {
|
|
|
41
41
|
}
|
|
42
42
|
/** @internalRemarks Source: @carto/react-core */
|
|
43
43
|
export type FilterLogicalOperator = 'and' | 'or';
|
|
44
|
+
/******************************************************************************
|
|
45
|
+
* GROUPING
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
|
|
49
|
+
*
|
|
50
|
+
* @internalRemarks Source: @carto/react-core
|
|
51
|
+
*/
|
|
52
|
+
export type GroupDateType = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
44
53
|
/******************************************************************************
|
|
45
54
|
* SORTING
|
|
46
55
|
*/
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
|
|
3
|
-
*
|
|
4
|
-
* @internalRemarks Source: @carto/react-core
|
|
5
|
-
*/
|
|
6
|
-
export enum GroupDateType {
|
|
7
|
-
YEARS = 'year',
|
|
8
|
-
MONTHS = 'month',
|
|
9
|
-
WEEKS = 'week',
|
|
10
|
-
DAYS = 'day',
|
|
11
|
-
HOURS = 'hour',
|
|
12
|
-
MINUTES = 'minute',
|
|
13
|
-
SECONDS = 'second',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
1
|
/**
|
|
17
2
|
* Defines a comparator used when matching a column's values against given filter values.
|
|
18
3
|
*
|
package/src/filters.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function removeFilter(
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if (owner) {
|
|
56
|
-
for (const type
|
|
56
|
+
for (const type of Object.values(FilterType)) {
|
|
57
57
|
if (owner === filter[type as FilterType]?.owner) {
|
|
58
58
|
delete filter[type as FilterType];
|
|
59
59
|
}
|
|
@@ -78,3 +78,52 @@ export function clearFilters(
|
|
|
78
78
|
}
|
|
79
79
|
return filters;
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
export type HasFilterOptions = {
|
|
83
|
+
column: string;
|
|
84
|
+
owner?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export function hasFilter(
|
|
88
|
+
filters: Record<string, Filter>,
|
|
89
|
+
{column, owner}: HasFilterOptions
|
|
90
|
+
): boolean {
|
|
91
|
+
const filter = filters[column];
|
|
92
|
+
if (!filter) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!owner) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (const type of Object.values(FilterType)) {
|
|
101
|
+
if (owner === filter[type as FilterType]?.owner) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type GetFilterOptions<T extends FilterType> = {
|
|
110
|
+
column: string;
|
|
111
|
+
type: T;
|
|
112
|
+
owner?: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export function getFilter<T extends FilterType>(
|
|
116
|
+
filters: Record<string, Filter>,
|
|
117
|
+
{column, type, owner}: GetFilterOptions<T>
|
|
118
|
+
): Filter[T] | null {
|
|
119
|
+
const filter = filters[column];
|
|
120
|
+
if (!filter) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!owner || owner === filter[type as FilterType]?.owner) {
|
|
125
|
+
return filter[type] || null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return null;
|
|
129
|
+
}
|
package/src/sources/types.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {GroupDateType} from '../constants';
|
|
2
1
|
import {
|
|
3
|
-
|
|
2
|
+
GroupDateType,
|
|
4
3
|
SortColumnType,
|
|
5
4
|
SortDirection,
|
|
6
5
|
SpatialFilter,
|
|
@@ -20,14 +19,14 @@ interface BaseRequestOptions {
|
|
|
20
19
|
/** Options for {@link WidgetBaseSource#getCategories}. */
|
|
21
20
|
export interface CategoryRequestOptions extends BaseRequestOptions {
|
|
22
21
|
column: string;
|
|
23
|
-
operation?:
|
|
22
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
24
23
|
operationColumn?: string;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/** Options for {@link WidgetBaseSource#getFormula}. */
|
|
28
27
|
export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
29
28
|
column: string;
|
|
30
|
-
operation?:
|
|
29
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
31
30
|
operationExp?: string;
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -35,7 +34,7 @@ export interface FormulaRequestOptions extends BaseRequestOptions {
|
|
|
35
34
|
export interface HistogramRequestOptions extends BaseRequestOptions {
|
|
36
35
|
column: string;
|
|
37
36
|
ticks: number[];
|
|
38
|
-
operation?:
|
|
37
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
/** Options for {@link WidgetBaseSource#getRange}. */
|
|
@@ -46,9 +45,9 @@ export interface RangeRequestOptions extends BaseRequestOptions {
|
|
|
46
45
|
/** Options for {@link WidgetBaseSource#getScatter}. */
|
|
47
46
|
export interface ScatterRequestOptions extends BaseRequestOptions {
|
|
48
47
|
xAxisColumn: string;
|
|
49
|
-
xAxisJoinOperation?:
|
|
48
|
+
xAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
50
49
|
yAxisColumn: string;
|
|
51
|
-
yAxisJoinOperation?:
|
|
50
|
+
yAxisJoinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
/** Options for {@link WidgetBaseSource#getTable}. */
|
|
@@ -57,8 +56,8 @@ export interface TableRequestOptions extends BaseRequestOptions {
|
|
|
57
56
|
sortBy?: string;
|
|
58
57
|
sortDirection?: SortDirection;
|
|
59
58
|
sortByColumnType?: SortColumnType;
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
offset?: number;
|
|
60
|
+
limit?: number;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
/** Options for {@link WidgetBaseSource#getTimeSeries}. */
|
|
@@ -66,9 +65,9 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
|
|
|
66
65
|
column: string;
|
|
67
66
|
stepSize?: GroupDateType;
|
|
68
67
|
stepMultiplier?: number;
|
|
69
|
-
operation?:
|
|
68
|
+
operation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
70
69
|
operationColumn?: string;
|
|
71
|
-
joinOperation?:
|
|
70
|
+
joinOperation?: 'count' | 'avg' | 'min' | 'max' | 'sum';
|
|
72
71
|
splitByCategory?: string;
|
|
73
72
|
splitByCategoryLimit?: number;
|
|
74
73
|
splitByCategoryValues?: string[];
|
|
@@ -239,7 +239,7 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
239
239
|
*/
|
|
240
240
|
async getTable(options: TableRequestOptions): Promise<TableResponse> {
|
|
241
241
|
const {filterOwner, spatialFilter, abortController, ...params} = options;
|
|
242
|
-
const {columns, sortBy, sortDirection,
|
|
242
|
+
const {columns, sortBy, sortDirection, offset = 0, limit = 10} = params;
|
|
243
243
|
|
|
244
244
|
type TableModelResponse = {
|
|
245
245
|
rows: Record<string, number | string>[];
|
|
@@ -253,8 +253,8 @@ export abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
|
|
|
253
253
|
column: columns,
|
|
254
254
|
sortBy,
|
|
255
255
|
sortDirection,
|
|
256
|
-
limit
|
|
257
|
-
offset
|
|
256
|
+
limit,
|
|
257
|
+
offset,
|
|
258
258
|
},
|
|
259
259
|
opts: {abortController},
|
|
260
260
|
}).then((res: TableModelResponse) => ({
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {FilterType} from './constants';
|
|
1
|
+
import type {FilterType} from './constants.js';
|
|
2
2
|
|
|
3
3
|
/******************************************************************************
|
|
4
4
|
* AGGREGATION
|
|
@@ -39,6 +39,24 @@ export interface Filter {
|
|
|
39
39
|
/** @internalRemarks Source: @carto/react-core */
|
|
40
40
|
export type FilterLogicalOperator = 'and' | 'or';
|
|
41
41
|
|
|
42
|
+
/******************************************************************************
|
|
43
|
+
* GROUPING
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
|
|
48
|
+
*
|
|
49
|
+
* @internalRemarks Source: @carto/react-core
|
|
50
|
+
*/
|
|
51
|
+
export type GroupDateType =
|
|
52
|
+
| 'year'
|
|
53
|
+
| 'month'
|
|
54
|
+
| 'week'
|
|
55
|
+
| 'day'
|
|
56
|
+
| 'hour'
|
|
57
|
+
| 'minute'
|
|
58
|
+
| 'second';
|
|
59
|
+
|
|
42
60
|
/******************************************************************************
|
|
43
61
|
* SORTING
|
|
44
62
|
*/
|