@carto/api-client 0.3.0 → 0.4.0-alpha.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 (66) hide show
  1. package/build/api/carto-api-error.d.ts +18 -0
  2. package/build/api/endpoints.d.ts +22 -0
  3. package/build/api/index.d.ts +4 -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/types.d.ts +227 -0
  7. package/build/api-client.cjs +487 -24
  8. package/build/api-client.cjs.map +1 -1
  9. package/build/api-client.modern.js +423 -25
  10. package/build/api-client.modern.js.map +1 -1
  11. package/build/constants.d.ts +8 -0
  12. package/build/index.d.ts +6 -1
  13. package/build/sources/base-source.d.ts +4 -0
  14. package/build/sources/boundary-query-source.d.ts +9 -0
  15. package/build/sources/boundary-table-source.d.ts +7 -0
  16. package/build/sources/h3-query-source.d.ts +3 -0
  17. package/build/sources/h3-table-source.d.ts +3 -0
  18. package/build/sources/h3-tileset-source.d.ts +3 -0
  19. package/build/sources/index.d.ts +27 -5
  20. package/build/sources/quadbin-query-source.d.ts +3 -0
  21. package/build/sources/quadbin-table-source.d.ts +3 -0
  22. package/build/sources/quadbin-tileset-source.d.ts +3 -0
  23. package/build/sources/raster-source.d.ts +3 -0
  24. package/build/sources/types.d.ts +208 -85
  25. package/build/sources/vector-query-source.d.ts +3 -0
  26. package/build/sources/vector-table-source.d.ts +3 -0
  27. package/build/sources/vector-tileset-source.d.ts +3 -0
  28. package/build/utils.d.ts +4 -0
  29. package/build/widget-sources/index.d.ts +5 -0
  30. package/build/widget-sources/types.d.ts +95 -0
  31. package/build/{sources → widget-sources}/widget-base-source.d.ts +1 -1
  32. package/build/{sources → widget-sources}/widget-query-source.d.ts +1 -1
  33. package/build/{sources → widget-sources}/widget-table-source.d.ts +1 -1
  34. package/build/{sources → widget-sources}/wrappers.d.ts +1 -1
  35. package/package.json +4 -3
  36. package/src/api/carto-api-error.ts +72 -0
  37. package/src/api/endpoints.ts +82 -0
  38. package/src/api/index.ts +17 -0
  39. package/src/api/query.ts +56 -0
  40. package/src/api/request-with-parameters.ts +139 -0
  41. package/src/api/types.ts +301 -0
  42. package/src/constants.ts +13 -0
  43. package/src/global.d.ts +3 -0
  44. package/src/index.ts +10 -1
  45. package/src/sources/base-source.ts +100 -0
  46. package/src/sources/boundary-query-source.ts +53 -0
  47. package/src/sources/boundary-table-source.ts +41 -0
  48. package/src/sources/h3-query-source.ts +63 -0
  49. package/src/sources/h3-table-source.ts +59 -0
  50. package/src/sources/h3-tileset-source.ts +26 -0
  51. package/src/sources/index.ts +49 -5
  52. package/src/sources/quadbin-query-source.ts +64 -0
  53. package/src/sources/quadbin-table-source.ts +60 -0
  54. package/src/sources/quadbin-tileset-source.ts +26 -0
  55. package/src/sources/raster-source.ts +34 -0
  56. package/src/sources/types.ts +226 -90
  57. package/src/sources/vector-query-source.ts +65 -0
  58. package/src/sources/vector-table-source.ts +59 -0
  59. package/src/sources/vector-tileset-source.ts +26 -0
  60. package/src/utils.ts +8 -0
  61. package/src/widget-sources/index.ts +5 -0
  62. package/src/widget-sources/types.ts +105 -0
  63. package/src/{sources → widget-sources}/widget-base-source.ts +4 -3
  64. package/src/{sources → widget-sources}/widget-query-source.ts +1 -1
  65. package/src/{sources → widget-sources}/widget-table-source.ts +1 -1
  66. package/src/{sources → widget-sources}/wrappers.ts +1 -21
@@ -0,0 +1,18 @@
1
+ import type { APIErrorContext } from './types';
2
+ /**
3
+ *
4
+ * Custom error for reported errors in CARTO Maps API.
5
+ * Provides useful debugging information in console and context for applications.
6
+ *
7
+ */
8
+ export declare class CartoAPIError extends Error {
9
+ /** Source error from server */
10
+ error: Error;
11
+ /** Context (API call & parameters) in which error occured */
12
+ errorContext: APIErrorContext;
13
+ /** Response from server */
14
+ response?: Response;
15
+ /** JSON Response from server */
16
+ responseJson?: any;
17
+ constructor(error: Error, errorContext: APIErrorContext, response?: Response, responseJson?: any);
18
+ }
@@ -0,0 +1,22 @@
1
+ import { MapType } from './types';
2
+ export type V3Endpoint = 'maps' | 'stats' | 'sql';
3
+ export declare function buildPublicMapUrl({ apiBaseUrl, cartoMapId, }: {
4
+ apiBaseUrl: string;
5
+ cartoMapId: string;
6
+ }): string;
7
+ export declare function buildStatsUrl({ attribute, apiBaseUrl, connectionName, source, type, }: {
8
+ attribute: string;
9
+ apiBaseUrl: string;
10
+ connectionName: string;
11
+ source: string;
12
+ type: MapType;
13
+ }): string;
14
+ export declare function buildSourceUrl({ apiBaseUrl, connectionName, endpoint, }: {
15
+ apiBaseUrl: string;
16
+ connectionName: string;
17
+ endpoint: MapType;
18
+ }): string;
19
+ export declare function buildQueryUrl({ apiBaseUrl, connectionName, }: {
20
+ apiBaseUrl: string;
21
+ connectionName: string;
22
+ }): string;
@@ -0,0 +1,4 @@
1
+ export { CartoAPIError } from './carto-api-error';
2
+ export type { APIErrorContext, Format, MapType, RequestType, QueryParameters, Basemap, MapLibreBasemap, GoogleBasemap, } from './types';
3
+ export { query } from './query';
4
+ export type { QueryOptions } from './query';
@@ -0,0 +1,3 @@
1
+ import type { SourceOptions, QuerySourceOptions, QueryResult } from '../sources/types';
2
+ export type QueryOptions = SourceOptions & Omit<QuerySourceOptions, 'spatialDataColumn'>;
3
+ export declare const query: (options: QueryOptions) => Promise<QueryResult>;
@@ -0,0 +1,8 @@
1
+ import type { APIErrorContext } from './types';
2
+ export declare function requestWithParameters<T = any>({ baseUrl, parameters, headers: customHeaders, errorContext, maxLengthURL, }: {
3
+ baseUrl: string;
4
+ parameters?: Record<string, unknown>;
5
+ headers?: Record<string, string>;
6
+ errorContext: APIErrorContext;
7
+ maxLengthURL?: number;
8
+ }): Promise<T>;
@@ -0,0 +1,227 @@
1
+ export type Format = 'json' | 'geojson' | 'tilejson';
2
+ export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
3
+ export type RequestType = 'Map data' | 'Map instantiation' | 'Public map' | 'Tile stats' | 'SQL' | 'Basemap style';
4
+ export type ScaleType = 'linear' | 'ordinal' | 'log' | 'point' | 'quantile' | 'quantize' | 'sqrt' | 'custom' | 'identity';
5
+ export type APIErrorContext = {
6
+ requestType: RequestType;
7
+ mapId?: string;
8
+ connection?: string;
9
+ source?: string;
10
+ type?: MapType;
11
+ };
12
+ export declare enum SchemaFieldType {
13
+ Number = "number",
14
+ Bigint = "bigint",
15
+ String = "string",
16
+ Geometry = "geometry",
17
+ Timestamp = "timestamp",
18
+ Object = "object",
19
+ Boolean = "boolean",
20
+ Variant = "variant",
21
+ Unknown = "unknown"
22
+ }
23
+ export interface SchemaField {
24
+ name: string;
25
+ type: SchemaFieldType;
26
+ }
27
+ export interface MapInstantiation extends MapInstantiationFormats {
28
+ nrows: number;
29
+ size?: number;
30
+ schema: SchemaField[];
31
+ }
32
+ type MapInstantiationFormats = Record<Format, {
33
+ url: string[];
34
+ error?: any;
35
+ }>;
36
+ export type QueryParameterValue = string | number | boolean | Array<QueryParameterValue> | object;
37
+ export type NamedQueryParameter = Record<string, QueryParameterValue>;
38
+ export type PositionalQueryParameter = QueryParameterValue[];
39
+ export type QueryParameters = NamedQueryParameter | PositionalQueryParameter;
40
+ export type VisualChannelField = {
41
+ name: string;
42
+ type: string;
43
+ colorColumn?: string;
44
+ };
45
+ export interface Filters {
46
+ [column: string]: Filter;
47
+ }
48
+ interface Filter {
49
+ [FilterTypes.In]?: number[];
50
+ [FilterTypes.Between]?: number[][];
51
+ [FilterTypes.ClosedOpen]?: number[][];
52
+ [FilterTypes.Time]?: number[][];
53
+ [FilterTypes.StringSearch]?: string[];
54
+ }
55
+ export declare enum FilterTypes {
56
+ In = "in",
57
+ Between = "between",// [a, b] both are included
58
+ ClosedOpen = "closed_open",// [a, b) a is included, b is not
59
+ Time = "time",
60
+ StringSearch = "stringSearch"
61
+ }
62
+ export type VisualChannels = {
63
+ colorField?: VisualChannelField;
64
+ colorScale?: ScaleType;
65
+ customMarkersField?: VisualChannelField;
66
+ customMarkersScale?: ScaleType;
67
+ radiusField?: VisualChannelField;
68
+ radiusScale?: ScaleType;
69
+ rotationScale?: ScaleType;
70
+ rotationField?: VisualChannelField;
71
+ sizeField?: VisualChannelField;
72
+ sizeScale?: ScaleType;
73
+ strokeColorField?: VisualChannelField;
74
+ strokeColorScale?: ScaleType;
75
+ heightField?: VisualChannelField;
76
+ heightScale?: ScaleType;
77
+ weightField?: VisualChannelField;
78
+ };
79
+ export type ColorRange = {
80
+ category: string;
81
+ colors: string[];
82
+ colorMap: string[][] | undefined;
83
+ name: string;
84
+ type: string;
85
+ };
86
+ export type CustomMarkersRange = {
87
+ markerMap: {
88
+ value: string;
89
+ markerUrl?: string;
90
+ }[];
91
+ othersMarker?: string;
92
+ };
93
+ export type VisConfig = {
94
+ filled?: boolean;
95
+ opacity?: number;
96
+ enable3d?: boolean;
97
+ colorAggregation?: any;
98
+ colorRange: ColorRange;
99
+ customMarkers?: boolean;
100
+ customMarkersRange?: CustomMarkersRange | null;
101
+ customMarkersUrl?: string | null;
102
+ radius: number;
103
+ radiusRange?: number[];
104
+ sizeAggregation?: any;
105
+ sizeRange?: any;
106
+ strokeColorAggregation?: any;
107
+ strokeOpacity?: number;
108
+ strokeColorRange?: ColorRange;
109
+ heightRange?: any;
110
+ heightAggregation?: any;
111
+ weightAggregation?: any;
112
+ };
113
+ export type TextLabel = {
114
+ field: VisualChannelField | null | undefined;
115
+ alignment?: 'center' | 'bottom' | 'top';
116
+ anchor?: 'middle' | 'start' | 'end';
117
+ size: number;
118
+ color?: number[];
119
+ offset?: [number, number];
120
+ outlineColor?: number[];
121
+ };
122
+ export type MapLayerConfig = {
123
+ columns?: Record<string, any>;
124
+ color?: number[];
125
+ label?: string;
126
+ dataId: string;
127
+ textLabel: TextLabel[];
128
+ visConfig: VisConfig;
129
+ };
130
+ export type MapTextSubLayerConfig = Omit<MapLayerConfig, 'textLabel'> & {
131
+ textLabel?: TextLabel;
132
+ };
133
+ export type MapConfigLayer = {
134
+ type: string;
135
+ id: string;
136
+ config: MapLayerConfig;
137
+ visualChannels: VisualChannels;
138
+ };
139
+ export type MapDataset = {
140
+ id: string;
141
+ data: any;
142
+ aggregationExp: string | null;
143
+ aggregationResLevel: number | null;
144
+ geoColumn: string;
145
+ };
146
+ export interface CustomStyle {
147
+ url?: string;
148
+ style?: any;
149
+ customAttribution?: string;
150
+ }
151
+ export type KeplerMapConfig = {
152
+ mapState: any;
153
+ mapStyle: {
154
+ styleType: string;
155
+ visibleLayerGroups: Record<string, boolean>;
156
+ };
157
+ visState: {
158
+ layers: MapConfigLayer[];
159
+ };
160
+ layerBlending: any;
161
+ interactionConfig: any;
162
+ customBaseMaps?: {
163
+ customStyle?: CustomStyle;
164
+ };
165
+ };
166
+ export type BasemapType = 'maplibre' | 'google-maps';
167
+ export type Basemap = MapLibreBasemap | GoogleBasemap;
168
+ export type BasemapCommon = {
169
+ /**
170
+ * Type of basemap.
171
+ */
172
+ type: BasemapType;
173
+ /**
174
+ * Custom attribution for style data if not provided by style definition.
175
+ */
176
+ attribution?: string;
177
+ /**
178
+ * Properties of the basemap. These properties are specific to the basemap type.
179
+ */
180
+ props: Record<string, any>;
181
+ };
182
+ export type MapLibreBasemap = BasemapCommon & {
183
+ type: 'maplibre';
184
+ /**
185
+ * MapLibre map properties.
186
+ *
187
+ * Meant to be passed to directly to `maplibregl.Map` object.
188
+ */
189
+ props: MapLibreBasemapProps;
190
+ /**
191
+ * Layer groups to be displayed in the basemap.
192
+ */
193
+ visibleLayerGroups?: Record<string, boolean>;
194
+ /**
195
+ * If `style` has been filtered by `visibleLayerGroups` then this property contains original style object, so user
196
+ * can use `applyLayerGroupFilters` again with new settings.
197
+ */
198
+ rawStyle?: string | Record<string, any>;
199
+ };
200
+ export type MapLibreBasemapProps = {
201
+ style: string | Record<string, any>;
202
+ center: [number, number];
203
+ zoom: number;
204
+ pitch?: number;
205
+ bearing?: number;
206
+ };
207
+ export type GoogleBasemap = BasemapCommon & {
208
+ type: 'google-maps';
209
+ /**
210
+ * Google map properties.
211
+ *
212
+ * Meant to be passed to directly to `google.maps.Map` object.
213
+ */
214
+ props: GoogleBasemapProps;
215
+ };
216
+ export type GoogleBasemapProps = {
217
+ mapTypeId: string;
218
+ mapId?: string;
219
+ center?: {
220
+ lat: number;
221
+ lng: number;
222
+ };
223
+ zoom?: number;
224
+ tilt?: number;
225
+ heading?: number;
226
+ };
227
+ export {};