@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.
Files changed (72) hide show
  1. package/build/api/carto-api-error.d.ts +26 -0
  2. package/build/api/endpoints.d.ts +24 -0
  3. package/build/api/index.d.ts +5 -0
  4. package/build/api/query.d.ts +3 -0
  5. package/build/api/request-with-parameters.d.ts +8 -0
  6. package/build/api-client.cjs +724 -65
  7. package/build/api-client.cjs.map +1 -1
  8. package/build/api-client.modern.js +607 -59
  9. package/build/api-client.modern.js.map +1 -1
  10. package/build/constants-internal.d.ts +9 -28
  11. package/build/constants.d.ts +24 -2
  12. package/build/index.d.ts +5 -1
  13. package/build/models/model.d.ts +2 -2
  14. package/build/sources/base-source.d.ts +4 -0
  15. package/build/sources/boundary-query-source.d.ts +9 -0
  16. package/build/sources/boundary-table-source.d.ts +7 -0
  17. package/build/sources/h3-query-source.d.ts +3 -0
  18. package/build/sources/h3-table-source.d.ts +3 -0
  19. package/build/sources/h3-tileset-source.d.ts +3 -0
  20. package/build/sources/index.d.ts +27 -5
  21. package/build/sources/quadbin-query-source.d.ts +3 -0
  22. package/build/sources/quadbin-table-source.d.ts +3 -0
  23. package/build/sources/quadbin-tileset-source.d.ts +3 -0
  24. package/build/sources/raster-source.d.ts +3 -0
  25. package/build/sources/types.d.ts +209 -85
  26. package/build/sources/vector-query-source.d.ts +3 -0
  27. package/build/sources/vector-table-source.d.ts +3 -0
  28. package/build/sources/vector-tileset-source.d.ts +3 -0
  29. package/build/types-internal.d.ts +46 -1
  30. package/build/types.d.ts +11 -0
  31. package/build/utils.d.ts +4 -0
  32. package/build/widget-sources/index.d.ts +5 -0
  33. package/build/widget-sources/types.d.ts +95 -0
  34. package/build/{sources → widget-sources}/widget-base-source.d.ts +2 -2
  35. package/build/{sources → widget-sources}/widget-query-source.d.ts +1 -1
  36. package/build/{sources → widget-sources}/widget-table-source.d.ts +1 -1
  37. package/build/{sources → widget-sources}/wrappers.d.ts +1 -1
  38. package/package.json +4 -3
  39. package/src/api/carto-api-error.ts +88 -0
  40. package/src/api/endpoints.ts +84 -0
  41. package/src/api/index.ts +14 -0
  42. package/src/api/query.ts +56 -0
  43. package/src/api/request-with-parameters.ts +135 -0
  44. package/src/constants-internal.ts +9 -30
  45. package/src/constants.ts +32 -3
  46. package/src/global.d.ts +3 -0
  47. package/src/index.ts +38 -1
  48. package/src/models/model.ts +4 -6
  49. package/src/sources/base-source.ts +101 -0
  50. package/src/sources/boundary-query-source.ts +53 -0
  51. package/src/sources/boundary-table-source.ts +41 -0
  52. package/src/sources/h3-query-source.ts +63 -0
  53. package/src/sources/h3-table-source.ts +59 -0
  54. package/src/sources/h3-tileset-source.ts +26 -0
  55. package/src/sources/index.ts +54 -5
  56. package/src/sources/quadbin-query-source.ts +64 -0
  57. package/src/sources/quadbin-table-source.ts +60 -0
  58. package/src/sources/quadbin-tileset-source.ts +26 -0
  59. package/src/sources/raster-source.ts +34 -0
  60. package/src/sources/types.ts +221 -89
  61. package/src/sources/vector-query-source.ts +65 -0
  62. package/src/sources/vector-table-source.ts +59 -0
  63. package/src/sources/vector-tileset-source.ts +26 -0
  64. package/src/types-internal.ts +54 -1
  65. package/src/types.ts +16 -0
  66. package/src/utils.ts +8 -0
  67. package/src/widget-sources/index.ts +5 -0
  68. package/src/widget-sources/types.ts +105 -0
  69. package/src/{sources → widget-sources}/widget-base-source.ts +5 -5
  70. package/src/{sources → widget-sources}/widget-query-source.ts +2 -3
  71. package/src/{sources → widget-sources}/widget-table-source.ts +2 -3
  72. 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
- ApiVersion,
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 '@deck.gl/carto';
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: MapType.QUERY,
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 '@deck.gl/carto';
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: MapType.TABLE,
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
- SourceOptions,
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
- }