@carto/api-client 0.0.1-0 → 0.0.1-2

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.
@@ -1,25 +1,44 @@
1
+ import { GroupDateType } from '../constants';
1
2
  import { AggregationType, SortColumnType, SortDirection, SpatialFilter } from '../types';
2
3
  /******************************************************************************
3
4
  * WIDGET API REQUESTS
4
5
  */
6
+ /** Common options for {@link WidgetBaseSource} requests. */
5
7
  interface BaseRequestOptions {
6
8
  spatialFilter?: SpatialFilter;
7
9
  abortController?: AbortController;
8
10
  filterOwner?: string;
9
11
  }
12
+ /** Options for {@link WidgetBaseSource#getCategories}. */
13
+ export interface CategoryRequestOptions extends BaseRequestOptions {
14
+ column: string;
15
+ operation?: AggregationType;
16
+ operationColumn?: string;
17
+ }
18
+ /** Options for {@link WidgetBaseSource#getFormula}. */
10
19
  export interface FormulaRequestOptions extends BaseRequestOptions {
11
20
  column: string;
12
21
  operation?: AggregationType;
13
22
  operationExp?: string;
14
23
  }
15
- export interface CategoryRequestOptions extends BaseRequestOptions {
24
+ /** Options for {@link WidgetBaseSource#getHistogram}. */
25
+ export interface HistogramRequestOptions extends BaseRequestOptions {
16
26
  column: string;
27
+ ticks: number[];
17
28
  operation?: AggregationType;
18
- operationColumn?: string;
19
29
  }
30
+ /** Options for {@link WidgetBaseSource#getRange}. */
20
31
  export interface RangeRequestOptions extends BaseRequestOptions {
21
32
  column: string;
22
33
  }
34
+ /** Options for {@link WidgetBaseSource#getScatter}. */
35
+ export interface ScatterRequestOptions extends BaseRequestOptions {
36
+ xAxisColumn: string;
37
+ xAxisJoinOperation?: AggregationType;
38
+ yAxisColumn: string;
39
+ yAxisJoinOperation?: AggregationType;
40
+ }
41
+ /** Options for {@link WidgetBaseSource#getTable}. */
23
42
  export interface TableRequestOptions extends BaseRequestOptions {
24
43
  columns: string[];
25
44
  sortBy?: string;
@@ -28,15 +47,10 @@ export interface TableRequestOptions extends BaseRequestOptions {
28
47
  page?: number;
29
48
  rowsPerPage?: number;
30
49
  }
31
- export interface ScatterRequestOptions extends BaseRequestOptions {
32
- xAxisColumn: string;
33
- xAxisJoinOperation?: AggregationType;
34
- yAxisColumn: string;
35
- yAxisJoinOperation?: AggregationType;
36
- }
50
+ /** Options for {@link WidgetBaseSource#getTimeSeries}. */
37
51
  export interface TimeSeriesRequestOptions extends BaseRequestOptions {
38
52
  column: string;
39
- stepSize?: number;
53
+ stepSize?: GroupDateType;
40
54
  stepMultiplier?: number;
41
55
  operation?: AggregationType;
42
56
  operationColumn?: string;
@@ -45,30 +59,31 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
45
59
  splitByCategoryLimit?: number;
46
60
  splitByCategoryValues?: string[];
47
61
  }
48
- export interface HistogramRequestOptions extends BaseRequestOptions {
49
- column: string;
50
- ticks: number[];
51
- operation?: AggregationType;
52
- }
53
62
  /******************************************************************************
54
63
  * WIDGET API RESPONSES
55
64
  */
65
+ /** Response from {@link WidgetBaseSource#getFormula}. */
56
66
  export type FormulaResponse = {
57
67
  value: number;
58
68
  };
69
+ /** Response from {@link WidgetBaseSource#getCategories}. */
59
70
  export type CategoryResponse = {
60
71
  name: string;
61
72
  value: number;
62
73
  }[];
74
+ /** Response from {@link WidgetBaseSource#getRange}. */
63
75
  export type RangeResponse = {
64
76
  min: number;
65
77
  max: number;
66
78
  };
79
+ /** Response from {@link WidgetBaseSource#getTable}. */
67
80
  export type TableResponse = {
68
81
  totalCount: number;
69
82
  rows: Record<string, number | string>[];
70
83
  };
84
+ /** Response from {@link WidgetBaseSource#getScatter}. */
71
85
  export type ScatterResponse = [number, number][];
86
+ /** Response from {@link WidgetBaseSource#getTimeSeries}. */
72
87
  export type TimeSeriesResponse = {
73
88
  rows: {
74
89
  name: string;
@@ -76,5 +91,6 @@ export type TimeSeriesResponse = {
76
91
  }[];
77
92
  categories: string[];
78
93
  };
94
+ /** Response from {@link WidgetBaseSource#getHistogram}. */
79
95
  export type HistogramResponse = number[];
80
96
  export {};
@@ -1,32 +1,87 @@
1
1
  import { CategoryRequestOptions, CategoryResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
2
- import { Source, FilterLogicalOperator, Credentials, Filter } from '../types.js';
2
+ import { FilterLogicalOperator, Filter } from '../types.js';
3
3
  import { SourceOptions } from '@deck.gl/carto';
4
- import { MapType } from '../constants.js';
5
- /**
6
- * TODO(cleanup): Consolidate {@link SourceOptions} and {@link Source}.
7
- */
8
- export interface WidgetBaseSourceProps extends SourceOptions, Credentials {
9
- type?: MapType;
4
+ import { ApiVersion } from '../constants-internal.js';
5
+ import { ModelSource } from '../models/model.js';
6
+ export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
7
+ apiVersion?: ApiVersion;
8
+ geoColumn?: string;
10
9
  filters?: Record<string, Filter>;
11
10
  filtersLogicalOperator?: FilterLogicalOperator;
12
- queryParameters?: unknown[];
13
- provider?: string;
14
11
  }
15
12
  export type WidgetSource = WidgetBaseSource<WidgetBaseSourceProps>;
16
- export declare class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
13
+ /**
14
+ * Source for Widget API requests on a data source defined by a SQL query.
15
+ *
16
+ * Abstract class. Use {@link WidgetQuerySource} or {@link WidgetTableSource}.
17
+ */
18
+ export declare abstract class WidgetBaseSource<Props extends WidgetBaseSourceProps> {
17
19
  readonly props: Props;
18
- readonly credentials: Required<Credentials> & {
19
- clientId: string;
20
- };
21
- readonly connectionName: string;
22
20
  static defaultProps: Partial<WidgetBaseSourceProps>;
23
21
  constructor(props: Props);
24
- protected getSource(owner?: string): Source;
25
- getFormula(props: FormulaRequestOptions): Promise<FormulaResponse>;
22
+ /**
23
+ * Subclasses of {@link WidgetBaseSource} must implement this method, calling
24
+ * {@link WidgetBaseSource.prototype._getModelSource} for common source
25
+ * properties, and adding additional required properties including 'type' and
26
+ * 'data'.
27
+ */
28
+ protected abstract getModelSource(owner: string | undefined): ModelSource;
29
+ protected _getModelSource(owner?: string): Omit<ModelSource, 'type' | 'data'>;
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
+ */
26
37
  getCategories(props: CategoryRequestOptions): Promise<CategoryResponse>;
38
+ /****************************************************************************
39
+ * FORMULA
40
+ */
41
+ /**
42
+ * Returns a scalar numerical statistic over all matching data. Suitable
43
+ * for 'headline' or 'scorecard' figures such as counts and sums.
44
+ */
45
+ getFormula(props: FormulaRequestOptions): Promise<FormulaResponse>;
46
+ /****************************************************************************
47
+ * HISTOGRAM
48
+ */
49
+ /**
50
+ * Returns a list of labeled datapoints for 'bins' of data defined as ticks
51
+ * over a numerical range. Suitable for histogram charts.
52
+ */
53
+ getHistogram(props: HistogramRequestOptions): Promise<HistogramResponse>;
54
+ /****************************************************************************
55
+ * RANGE
56
+ */
57
+ /**
58
+ * Returns a range (min and max) for a numerical column of matching rows.
59
+ * Suitable for displaying certain 'headline' or 'scorecard' statistics,
60
+ * or rendering a range slider UI for filtering.
61
+ */
27
62
  getRange(props: RangeRequestOptions): Promise<RangeResponse>;
28
- getTable(props: TableRequestOptions): Promise<TableResponse>;
63
+ /****************************************************************************
64
+ * SCATTER
65
+ */
66
+ /**
67
+ * Returns a list of bivariate datapoints defined as numerical 'x' and 'y'
68
+ * values. Suitable for rendering scatter plots.
69
+ */
29
70
  getScatter(props: ScatterRequestOptions): Promise<ScatterResponse>;
71
+ /****************************************************************************
72
+ * TABLE
73
+ */
74
+ /**
75
+ * Returns a list of arbitrary data rows, with support for pagination and
76
+ * sorting. Suitable for displaying tables and lists.
77
+ */
78
+ getTable(props: TableRequestOptions): Promise<TableResponse>;
79
+ /****************************************************************************
80
+ * TIME SERIES
81
+ */
82
+ /**
83
+ * Returns a series of labeled numerical values, grouped into equally-sized
84
+ * time intervals. Suitable for rendering time series charts.
85
+ */
30
86
  getTimeSeries(props: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
31
- getHistogram(props: HistogramRequestOptions): Promise<HistogramResponse>;
32
87
  }
@@ -1,8 +1,30 @@
1
1
  import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptions } from '@deck.gl/carto';
2
2
  import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
- import { Source } from '../types.js';
4
- type LayerQuerySourceOptions = VectorQuerySourceOptions | H3QuerySourceOptions | QuadbinQuerySourceOptions;
3
+ import { ModelSource } from '../models/model.js';
4
+ type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
5
+ /**
6
+ * Source for Widget API requests on a data source defined by a SQL query.
7
+ *
8
+ * Generally not intended to be constructed directly. Instead, call
9
+ * {@link vectorQuerySource}, {@link h3QuerySource}, or {@link quadbinQuerySource},
10
+ * which can be shared with map layers. Sources contain a `widgetSource` property,
11
+ * for use by widget implementations.
12
+ *
13
+ * Example:
14
+ *
15
+ * ```javascript
16
+ * import { vectorQuerySource } from '@carto/api-client';
17
+ *
18
+ * const data = vectorQuerySource({
19
+ * accessToken: '••••',
20
+ * connectionName: 'carto_dw',
21
+ * sqlQuery: 'SELECT * FROM carto-demo-data.demo_tables.retail_stores'
22
+ * });
23
+ *
24
+ * const { widgetSource } = await data;
25
+ * ```
26
+ */
5
27
  export declare class WidgetQuerySource extends WidgetBaseSource<LayerQuerySourceOptions & WidgetBaseSourceProps> {
6
- protected getSource(owner: string): Source;
28
+ protected getModelSource(owner: string): ModelSource;
7
29
  }
8
30
  export {};
@@ -1,8 +1,30 @@
1
1
  import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptions } from '@deck.gl/carto';
2
2
  import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
- import { Source } from '../types.js';
4
- type LayerTableSourceOptions = VectorTableSourceOptions | H3TableSourceOptions | QuadbinTableSourceOptions;
3
+ import { ModelSource } from '../models/model.js';
4
+ type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
5
+ /**
6
+ * Source for Widget API requests on a data source defined as a table.
7
+ *
8
+ * Generally not intended to be constructed directly. Instead, call
9
+ * {@link vectorTableSource}, {@link h3TableSource}, or {@link quadbinTableSource},
10
+ * which can be shared with map layers. Sources contain a `widgetSource` property,
11
+ * for use by widget implementations.
12
+ *
13
+ * Example:
14
+ *
15
+ * ```javascript
16
+ * import { vectorTableSource } from '@carto/api-client';
17
+ *
18
+ * const data = vectorTableSource({
19
+ * accessToken: '••••',
20
+ * connectionName: 'carto_dw',
21
+ * tableName: 'carto-demo-data.demo_tables.retail_stores'
22
+ * });
23
+ *
24
+ * const { widgetSource } = await data;
25
+ * ```
26
+ */
5
27
  export declare class WidgetTableSource extends WidgetBaseSource<LayerTableSourceOptions & WidgetBaseSourceProps> {
6
- protected getSource(owner: string): Source;
28
+ protected getModelSource(owner: string): ModelSource;
7
29
  }
8
30
  export {};
@@ -1,7 +1,8 @@
1
- import { h3TableSource as _h3TableSource, h3QuerySource as _h3QuerySource, vectorTableSource as _vectorTableSource, vectorQuerySource as _vectorQuerySource, quadbinTableSource as _quadbinTableSource, quadbinQuerySource as _quadbinQuerySource, VectorTableSourceOptions, VectorQuerySourceOptions, H3TableSourceOptions, H3QuerySourceOptions, QuadbinQuerySourceOptions, QuadbinTableSourceOptions } from '@deck.gl/carto';
1
+ import { h3TableSource as _h3TableSource, h3QuerySource as _h3QuerySource, vectorTableSource as _vectorTableSource, vectorQuerySource as _vectorQuerySource, quadbinTableSource as _quadbinTableSource, quadbinQuerySource as _quadbinQuerySource, VectorTableSourceOptions as _VectorTableSourceOptions, VectorQuerySourceOptions as _VectorQuerySourceOptions, H3TableSourceOptions as _H3TableSourceOptions, H3QuerySourceOptions as _H3QuerySourceOptions, QuadbinTableSourceOptions as _QuadbinTableSourceOptions, QuadbinQuerySourceOptions as _QuadbinQuerySourceOptions } from '@deck.gl/carto';
2
2
  import { WidgetBaseSourceProps } from './widget-base-source.js';
3
3
  import { WidgetQuerySource } from './widget-query-source.js';
4
4
  import { WidgetTableSource } from './widget-table-source.js';
5
+ type WrappedSourceOptions<T> = Omit<T, 'filters'> & WidgetBaseSourceProps;
5
6
  /******************************************************************************
6
7
  * RESPONSE OBJECTS
7
8
  */
@@ -20,28 +21,34 @@ export type QuadbinQuerySourceResponse = WidgetQuerySourceResponse & Awaited<Ret
20
21
  /******************************************************************************
21
22
  * VECTOR SOURCES
22
23
  */
23
- /** Wrapper adding widget support to {@link _vectorTableSource}. */
24
- export declare function vectorTableSource(props: VectorTableSourceOptions & WidgetBaseSourceProps): Promise<VectorTableSourceResponse>;
25
- /** Wrapper adding widget support to {@link _vectorQuerySource}. */
26
- export declare function vectorQuerySource(props: VectorQuerySourceOptions & WidgetBaseSourceProps): Promise<VectorQuerySourceResponse>;
27
- /** Wrapper adding widget support to {@link _vectorTilesetSource}. */
24
+ export type VectorTableSourceOptions = WrappedSourceOptions<_VectorTableSourceOptions>;
25
+ export type VectorQuerySourceOptions = WrappedSourceOptions<_VectorQuerySourceOptions>;
26
+ /** Wrapper adding Widget API support to [vectorTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
27
+ export declare function vectorTableSource(props: VectorTableSourceOptions): Promise<VectorTableSourceResponse>;
28
+ /** Wrapper adding Widget API support to [vectorQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
29
+ export declare function vectorQuerySource(props: VectorQuerySourceOptions): Promise<VectorQuerySourceResponse>;
30
+ /** Wrapper adding Widget API support to [vectorTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
28
31
  export declare function vectorTilesetSource(): Promise<void>;
29
32
  /******************************************************************************
30
33
  * H3 SOURCES
31
34
  */
32
- /** Wrapper adding widget support to {@link _h3TableSource}. */
33
- export declare function h3TableSource(props: H3TableSourceOptions & WidgetBaseSourceProps): Promise<H3TableSourceResponse>;
34
- /** Wrapper adding widget support to {@link _h3QuerySource}. */
35
- export declare function h3QuerySource(props: H3QuerySourceOptions & WidgetBaseSourceProps): Promise<H3QuerySourceResponse>;
36
- /** Wrapper adding widget support to {@link _h3TilesetSource}. */
35
+ export type H3TableSourceOptions = WrappedSourceOptions<_H3TableSourceOptions>;
36
+ export type H3QuerySourceOptions = WrappedSourceOptions<_H3QuerySourceOptions>;
37
+ /** Wrapper adding Widget API support to [h3TableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
38
+ export declare function h3TableSource(props: H3TableSourceOptions): Promise<H3TableSourceResponse>;
39
+ /** Wrapper adding Widget API support to [h3QuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
40
+ export declare function h3QuerySource(props: H3QuerySourceOptions): Promise<H3QuerySourceResponse>;
41
+ /** Wrapper adding Widget API support to [h3TilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
37
42
  export declare function h3TilesetSource(): Promise<void>;
38
43
  /******************************************************************************
39
44
  * QUADBIN SOURCES
40
45
  */
41
- /** Wrapper adding widget support to {@link _quadbinTableSource}. */
46
+ export type QuadbinTableSourceOptions = WrappedSourceOptions<_QuadbinTableSourceOptions>;
47
+ export type QuadbinQuerySourceOptions = WrappedSourceOptions<_QuadbinQuerySourceOptions>;
48
+ /** Wrapper adding Widget API support to [quadbinTableSource](https://deck.gl/docs/api-reference/carto/data-sources). */
42
49
  export declare function quadbinTableSource(props: QuadbinTableSourceOptions & WidgetBaseSourceProps): Promise<QuadbinTableSourceResponse>;
43
- /** Wrapper adding widget support to {@link _quadbinQuerySource}. */
50
+ /** Wrapper adding Widget API support to [quadbinQuerySource](https://deck.gl/docs/api-reference/carto/data-sources). */
44
51
  export declare function quadbinQuerySource(props: QuadbinQuerySourceOptions & WidgetBaseSourceProps): Promise<QuadbinQuerySourceResponse>;
45
- /** Wrapper adding widget support to {@link _quadbinTilesetSource}. */
52
+ /** Wrapper adding Widget API support to [quadbinTilesetSource](https://deck.gl/docs/api-reference/carto/data-sources). */
46
53
  export declare function quadbinTilesetSource(): Promise<void>;
47
54
  export {};
package/build/types.d.ts CHANGED
@@ -1,35 +1,10 @@
1
- import type { ApiVersion, MapType, FilterType } from './constants';
2
- /******************************************************************************
3
- * AUTHENTICATION
4
- */
5
- /** @internalRemarks Source: @carto/react-api */
6
- export type Credentials = {
7
- apiVersion?: ApiVersion;
8
- apiBaseUrl?: string;
9
- geoColumn?: string;
10
- accessToken: string;
11
- };
12
- /******************************************************************************
13
- * SOURCES
14
- */
15
- /** @internalRemarks Source: @carto/react-api */
16
- export type Source = {
17
- type: MapType;
18
- connection: string;
19
- credentials: Credentials;
20
- data: string;
21
- geoColumn?: string;
22
- queryParameters?: unknown[];
23
- filters?: Record<string, Filter>;
24
- filtersLogicalOperator?: 'and' | 'or';
25
- };
1
+ import type { FilterType } from './constants';
26
2
  /******************************************************************************
27
3
  * AGGREGATION
28
4
  */
29
5
  /**
30
- * Enum for the different types of aggregations available for widgets
31
- * @enum {string}
32
- * @readonly
6
+ * Enum for the different types of aggregations available for widgets.
7
+ *
33
8
  * @internalRemarks Source: @carto/constants
34
9
  * @internalRemarks Converted from enum to type union, for improved declarative API.
35
10
  */
@@ -71,3 +46,14 @@ export type FilterLogicalOperator = 'and' | 'or';
71
46
  */
72
47
  export type SortDirection = 'asc' | 'desc';
73
48
  export type SortColumnType = 'number' | 'string' | 'date';
49
+ /******************************************************************************
50
+ * SQL QUERY PARAMETERS
51
+ */
52
+ /** @internalRemarks Source: @deck.gl/carto */
53
+ export type QueryParameterValue = string | number | boolean | Array<QueryParameterValue> | object;
54
+ /** @internalRemarks Source: @deck.gl/carto */
55
+ export type NamedQueryParameter = Record<string, QueryParameterValue>;
56
+ /** @internalRemarks Source: @deck.gl/carto */
57
+ export type PositionalQueryParameter = QueryParameterValue[];
58
+ /** @internalRemarks Source: @deck.gl/carto */
59
+ export type QueryParameters = NamedQueryParameter | PositionalQueryParameter;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@carto/api-client",
3
- "version": "0.0.1-0",
3
+ "version": "0.0.1-2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "alpha"
7
7
  },
8
- "packageManager": "yarn@4.2.2",
8
+ "packageManager": "yarn@4.3.1",
9
9
  "author": "Don McCurdy <donmccurdy@carto.com>",
10
10
  "license": "UNLICENSED",
11
11
  "type": "module",
@@ -36,10 +36,8 @@
36
36
  "lint": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --check",
37
37
  "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write",
38
38
  "clean": "rimraf build/*",
39
- "version": "git add -u",
40
39
  "prepack": "yarn clean && yarn build",
41
- "prepublish": "yarn lint && yarn test",
42
- "postpublish": "git push && git push --tags"
40
+ "prepublish": "yarn lint && yarn test"
43
41
  },
44
42
  "files": [
45
43
  "build",
@@ -85,5 +83,5 @@
85
83
  "vitest": "1.6.0",
86
84
  "vue": "^3.4.27"
87
85
  },
88
- "stableVersion": "0.0.0"
86
+ "stableVersion": "0.0.1-1"
89
87
  }
package/src/client.ts CHANGED
@@ -1,17 +1,25 @@
1
- import {CLIENT_ID} from './constants.js';
2
-
3
1
  /**
4
- * Default client
2
+ * @internal
5
3
  * @internalRemarks Source: @carto/react-core
6
4
  */
7
- let client = CLIENT_ID;
5
+ let client = 'carto-api-client';
8
6
 
9
- /** @internalRemarks Source: @carto/react-core */
7
+ /**
8
+ * Returns current client ID, used to categorize API requests. For internal use only.
9
+ *
10
+ * @internal
11
+ * @internalRemarks Source: @carto/react-core
12
+ */
10
13
  export function getClient() {
11
14
  return client;
12
15
  }
13
16
 
14
- /** @internalRemarks Source: @carto/react-core */
17
+ /**
18
+ * Sets current client ID, used to categorize API requests. For internal use only.
19
+ *
20
+ * @internal
21
+ * @internalRemarks Source: @carto/react-core
22
+ */
15
23
  export function setClient(c: string) {
16
24
  client = c;
17
25
  }
@@ -1,9 +1,6 @@
1
- /**
2
- * Threshold to use GET requests, vs POST
3
- * @internalRemarks Source: @carto/constants
4
- * @internal
1
+ /******************************************************************************
2
+ * DEFAULTS
5
3
  */
6
- export const REQUEST_GET_MAX_URL_LENGTH = 2048;
7
4
 
8
5
  /**
9
6
  * @internalRemarks Source: @carto/constants
@@ -22,3 +19,27 @@ export const DEFAULT_CLIENT = 'deck-gl-carto';
22
19
  * @internal
23
20
  */
24
21
  export const DEFAULT_GEO_COLUMN = 'geom';
22
+
23
+ /******************************************************************************
24
+ * ENUMS
25
+ */
26
+
27
+ /**
28
+ * @internal
29
+ * @internalRemarks Source: @carto/constants
30
+ */
31
+ export enum MapType {
32
+ TABLE = 'table',
33
+ QUERY = 'query',
34
+ TILESET = 'tileset',
35
+ }
36
+
37
+ /**
38
+ * @internal
39
+ * @internalRemarks Source: @carto/constants
40
+ */
41
+ export enum ApiVersion {
42
+ V1 = 'v1',
43
+ V2 = 'v2',
44
+ V3 = 'v3',
45
+ }
package/src/constants.ts CHANGED
@@ -1,20 +1,8 @@
1
- export const CLIENT_ID = 'carto-api-client';
2
-
3
- /** @internalRemarks Source: @carto/constants */
4
- export enum MapType {
5
- TABLE = 'table',
6
- QUERY = 'query',
7
- TILESET = 'tileset',
8
- }
9
-
10
- /** @internalRemarks Source: @carto/constants */
11
- export enum ApiVersion {
12
- V1 = 'v1',
13
- V2 = 'v2',
14
- V3 = 'v3',
15
- }
16
-
17
- /** @internalRemarks Source: @carto/react-core */
1
+ /**
2
+ * Defines a step size increment for use with {@link TimeSeriesRequestOptions}.
3
+ *
4
+ * @internalRemarks Source: @carto/react-core
5
+ */
18
6
  export enum GroupDateType {
19
7
  YEARS = 'year',
20
8
  MONTHS = 'month',
@@ -25,7 +13,20 @@ export enum GroupDateType {
25
13
  SECONDS = 'second',
26
14
  }
27
15
 
28
- /** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
16
+ /**
17
+ * Defines a comparator used when matching a column's values against given filter values.
18
+ *
19
+ * Example:
20
+ *
21
+ * ```javascript
22
+ * import { FilterType } from '@carto/api-client';
23
+ * const filters = {
24
+ * column_name: { [FilterType.IN]: { values: ['a', 'b', 'c'] } }
25
+ * };
26
+ * ```
27
+ *
28
+ * @internalRemarks Source: @carto/react-api, @deck.gl/carto
29
+ */
29
30
  export enum FilterType {
30
31
  IN = 'in',
31
32
  /** [a, b] both are included. */
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './client.js';
2
2
  export * from './constants.js';
3
- export * from './models/index.js';
4
3
  export * from './sources/index.js';
5
4
  export * from './types.js';
@@ -1,5 +1,4 @@
1
1
  import {$TODO} from '../types-internal.js';
2
- import {Credentials} from '../types.js';
3
2
  import {InvalidColumnError} from '../utils.js';
4
3
 
5
4
  /** @internalRemarks Source: @carto/react-api */
@@ -43,21 +42,14 @@ export function dealWithApiError({
43
42
  }
44
43
  }
45
44
 
46
- /** @internalRemarks Source: @carto/react-api */
47
- export function checkCredentials(credentials: Credentials) {
48
- if (!credentials || !credentials.apiBaseUrl || !credentials.accessToken) {
49
- throw new Error('Missing or bad credentials provided');
50
- }
51
- }
52
-
53
45
  /** @internalRemarks Source: @carto/react-api */
54
46
  export async function makeCall({
55
47
  url,
56
- credentials,
48
+ accessToken,
57
49
  opts,
58
50
  }: {
59
51
  url: string;
60
- credentials: Credentials;
52
+ accessToken: string;
61
53
  opts: ModelRequestOptions;
62
54
  }) {
63
55
  let response;
@@ -66,15 +58,13 @@ export async function makeCall({
66
58
  try {
67
59
  response = await fetch(url.toString(), {
68
60
  headers: {
69
- Authorization: `Bearer ${credentials.accessToken}`,
70
- ...(isPost ? {'Content-Type': 'application/json'} : {}),
61
+ Authorization: `Bearer ${accessToken}`,
62
+ ...(isPost && {'Content-Type': 'application/json'}),
71
63
  },
72
- ...(isPost
73
- ? {
74
- method: opts?.method,
75
- body: opts?.body,
76
- }
77
- : {}),
64
+ ...(isPost && {
65
+ method: opts?.method,
66
+ body: opts?.body,
67
+ }),
78
68
  signal: opts?.abortController?.signal,
79
69
  ...opts?.otherOptions,
80
70
  });