@carto/api-client 0.4.0-alpha.0 → 0.4.0-alpha.3

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 (58) hide show
  1. package/build/api/carto-api-error.d.ts +9 -1
  2. package/build/api/endpoints.d.ts +3 -1
  3. package/build/api/index.d.ts +5 -4
  4. package/build/api/request-with-parameters.d.ts +1 -1
  5. package/build/api-client.cjs +293 -158
  6. package/build/api-client.cjs.map +1 -1
  7. package/build/api-client.modern.js +243 -126
  8. package/build/api-client.modern.js.map +1 -1
  9. package/build/constants-internal.d.ts +9 -28
  10. package/build/constants.d.ts +24 -10
  11. package/build/index.d.ts +4 -5
  12. package/build/models/model.d.ts +2 -2
  13. package/build/sources/base-source.d.ts +1 -1
  14. package/build/sources/boundary-query-source.d.ts +1 -1
  15. package/build/sources/h3-query-source.d.ts +2 -1
  16. package/build/sources/h3-table-source.d.ts +2 -1
  17. package/build/sources/index.d.ts +1 -1
  18. package/build/sources/quadbin-query-source.d.ts +2 -1
  19. package/build/sources/quadbin-table-source.d.ts +2 -1
  20. package/build/sources/types.d.ts +2 -1
  21. package/build/sources/vector-query-source.d.ts +2 -1
  22. package/build/sources/vector-table-source.d.ts +2 -1
  23. package/build/types-internal.d.ts +46 -1
  24. package/build/types.d.ts +11 -0
  25. package/build/widget-sources/index.d.ts +0 -1
  26. package/build/widget-sources/widget-base-source.d.ts +1 -1
  27. package/build/widget-sources/widget-query-source.d.ts +3 -0
  28. package/build/widget-sources/widget-table-source.d.ts +3 -0
  29. package/package.json +2 -2
  30. package/src/api/carto-api-error.ts +17 -1
  31. package/src/api/endpoints.ts +3 -1
  32. package/src/api/index.ts +9 -12
  33. package/src/api/query.ts +1 -1
  34. package/src/api/request-with-parameters.ts +4 -8
  35. package/src/constants-internal.ts +9 -30
  36. package/src/constants.ts +32 -16
  37. package/src/index.ts +43 -5
  38. package/src/models/model.ts +4 -6
  39. package/src/sources/base-source.ts +2 -1
  40. package/src/sources/boundary-query-source.ts +1 -1
  41. package/src/sources/h3-query-source.ts +9 -7
  42. package/src/sources/h3-table-source.ts +9 -7
  43. package/src/sources/index.ts +6 -1
  44. package/src/sources/quadbin-query-source.ts +9 -7
  45. package/src/sources/quadbin-table-source.ts +9 -7
  46. package/src/sources/types.ts +2 -6
  47. package/src/sources/vector-query-source.ts +12 -7
  48. package/src/sources/vector-table-source.ts +12 -7
  49. package/src/types-internal.ts +54 -1
  50. package/src/types.ts +16 -0
  51. package/src/widget-sources/index.ts +0 -1
  52. package/src/widget-sources/widget-base-source.ts +5 -5
  53. package/src/widget-sources/widget-query-source.ts +3 -2
  54. package/src/widget-sources/widget-table-source.ts +3 -2
  55. package/build/api/types.d.ts +0 -227
  56. package/build/widget-sources/wrappers.d.ts +0 -48
  57. package/src/api/types.ts +0 -301
  58. package/src/widget-sources/wrappers.ts +0 -121
package/build/index.d.ts CHANGED
@@ -4,8 +4,7 @@ export * from './filters.js';
4
4
  export * from './geo.js';
5
5
  export * from './widget-sources/index.js';
6
6
  export * from './types.js';
7
- export { APIErrorContext, Format, // TODO: Move to `types.ts`?
8
- MapType, // TODO: De-duplicate?
9
- RequestType, // TODO: Move to `types.ts`?
10
- QueryParameters, // TODO: Move to `types.ts`?
11
- QueryOptions, } from './api/index.js';
7
+ export { APIErrorContext, APIRequestType, CartoAPIError, QueryOptions, buildPublicMapUrl, // Internal, but required for fetchMap().
8
+ buildStatsUrl, // Internal, but required for fetchMap().
9
+ query, requestWithParameters, } from './api/index.js';
10
+ export { BoundaryQuerySourceOptions, BoundaryTableSourceOptions, GeojsonResult, H3QuerySourceOptions, H3TableSourceOptions, H3TilesetSourceOptions, JsonResult, QuadbinQuerySourceOptions, QuadbinTableSourceOptions, QuadbinTilesetSourceOptions, QueryResult, QuerySourceOptions, RasterSourceOptions, SOURCE_DEFAULTS, SourceOptions, TableSourceOptions, TilejsonResult, TilesetSourceOptions, VectorQuerySourceOptions, VectorTableSourceOptions, VectorTilesetSourceOptions, boundaryQuerySource, boundaryTableSource, h3QuerySource, h3TableSource, h3TilesetSource, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, rasterSource, vectorQuerySource, vectorTableSource, vectorTilesetSource, } from './sources/index.js';
@@ -1,6 +1,6 @@
1
- import { ApiVersion, MapType } from '../constants-internal.js';
2
- import { Filter, FilterLogicalOperator, QueryParameters, SpatialFilter } from '../types.js';
1
+ import { Filter, FilterLogicalOperator, MapType, QueryParameters, SpatialFilter } from '../types.js';
3
2
  import { ModelRequestOptions } from './common.js';
3
+ import { ApiVersion } from '../constants.js';
4
4
  /** @internalRemarks Source: @carto/react-api */
5
5
  declare const AVAILABLE_MODELS: readonly ["category", "histogram", "formula", "timeseries", "range", "scatterplot", "table"];
6
6
  export type Model = (typeof AVAILABLE_MODELS)[number];
@@ -1,4 +1,4 @@
1
- import type { MapType } from '../api/types';
2
1
  import type { GeojsonResult, JsonResult, SourceOptionalOptions, SourceRequiredOptions, TilejsonResult } from './types';
2
+ import { MapType } from '../types';
3
3
  export declare const SOURCE_DEFAULTS: SourceOptionalOptions;
4
4
  export declare function baseSource<UrlParameters extends Record<string, unknown>>(endpoint: MapType, options: Partial<SourceOptionalOptions> & SourceRequiredOptions, urlParameters: UrlParameters): Promise<TilejsonResult | GeojsonResult | JsonResult>;
@@ -1,4 +1,4 @@
1
- import { QueryParameters } from '../api/index';
1
+ import { QueryParameters } from '../types.js';
2
2
  import type { FilterOptions, SourceOptions, TilejsonResult } from './types';
3
3
  export type BoundaryQuerySourceOptions = SourceOptions & FilterOptions & {
4
4
  columns?: string[];
@@ -1,3 +1,4 @@
1
+ import { WidgetQuerySourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, QuerySourceOptions, SourceOptions, TilejsonResult } from './types';
2
3
  export type H3QuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions & FilterOptions;
3
- export declare const h3QuerySource: (options: H3QuerySourceOptions) => Promise<TilejsonResult>;
4
+ export declare const h3QuerySource: (options: H3QuerySourceOptions) => Promise<TilejsonResult & WidgetQuerySourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetTableSourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
2
3
  export type H3TableSourceOptions = SourceOptions & TableSourceOptions & AggregationOptions & FilterOptions;
3
- export declare const h3TableSource: (options: H3TableSourceOptions) => Promise<TilejsonResult>;
4
+ export declare const h3TableSource: (options: H3TableSourceOptions) => Promise<TilejsonResult & WidgetTableSourceResult>;
@@ -1,5 +1,5 @@
1
1
  export { SOURCE_DEFAULTS } from './base-source';
2
- export type { TilejsonResult, GeojsonResult, JsonResult } from './types';
2
+ export type { TilejsonResult, GeojsonResult, JsonResult, QueryResult, } from './types';
3
3
  export { boundaryQuerySource } from './boundary-query-source';
4
4
  export type { BoundaryQuerySourceOptions } from './boundary-query-source';
5
5
  export { boundaryTableSource } from './boundary-table-source';
@@ -1,3 +1,4 @@
1
+ import { WidgetQuerySourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, QuerySourceOptions, SourceOptions, TilejsonResult } from './types';
2
3
  export type QuadbinQuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions & FilterOptions;
3
- export declare const quadbinQuerySource: (options: QuadbinQuerySourceOptions) => Promise<TilejsonResult>;
4
+ export declare const quadbinQuerySource: (options: QuadbinQuerySourceOptions) => Promise<TilejsonResult & WidgetQuerySourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetTableSourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
2
3
  export type QuadbinTableSourceOptions = SourceOptions & TableSourceOptions & AggregationOptions & FilterOptions;
3
- export declare const quadbinTableSource: (options: QuadbinTableSourceOptions) => Promise<TilejsonResult>;
4
+ export declare const quadbinTableSource: (options: QuadbinTableSourceOptions) => Promise<TilejsonResult & WidgetTableSourceResult>;
@@ -1,5 +1,6 @@
1
1
  import type { Feature } from 'geojson';
2
- import type { Filters, Format, MapInstantiation, QueryParameters } from '../api/types';
2
+ import { Filters, Format, QueryParameters } from '../types';
3
+ import { MapInstantiation } from '../types-internal';
3
4
  export type SourceRequiredOptions = {
4
5
  /** Carto platform access token. */
5
6
  accessToken: string;
@@ -1,3 +1,4 @@
1
+ import { WidgetQuerySourceResult } from '../widget-sources/index.js';
1
2
  import type { FilterOptions, SourceOptions, QuerySourceOptions, TilejsonResult, ColumnsOption } from './types';
2
3
  export type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption;
3
- export declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<TilejsonResult>;
4
+ export declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<TilejsonResult & WidgetQuerySourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetTableSourceResult } from '../widget-sources/index.js';
1
2
  import type { FilterOptions, ColumnsOption, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
2
3
  export type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption;
3
- export declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<TilejsonResult>;
4
+ export declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<TilejsonResult & WidgetTableSourceResult>;
@@ -1,7 +1,52 @@
1
1
  /******************************************************************************
2
- * INTERNAL
2
+ * COMMON
3
3
  */
4
+ import { Format } from './types';
4
5
  /** @internal */
5
6
  export type $TODO = any;
6
7
  /** @internal */
7
8
  export type $IntentionalAny = any;
9
+ /******************************************************************************
10
+ * MAP INSTANTIATION
11
+ */
12
+ /**
13
+ * @internalRemarks Source: @deck.gl/carto
14
+ * @internal
15
+ */
16
+ export declare enum SchemaFieldType {
17
+ Number = "number",
18
+ Bigint = "bigint",
19
+ String = "string",
20
+ Geometry = "geometry",
21
+ Timestamp = "timestamp",
22
+ Object = "object",
23
+ Boolean = "boolean",
24
+ Variant = "variant",
25
+ Unknown = "unknown"
26
+ }
27
+ /**
28
+ * @internalRemarks Source: @deck.gl/carto
29
+ * @internal
30
+ */
31
+ export interface SchemaField {
32
+ name: string;
33
+ type: SchemaFieldType;
34
+ }
35
+ /**
36
+ * @internalRemarks Source: @deck.gl/carto
37
+ * @internal
38
+ */
39
+ export interface MapInstantiation extends MapInstantiationFormats {
40
+ nrows: number;
41
+ size?: number;
42
+ schema: SchemaField[];
43
+ }
44
+ /**
45
+ * @internalRemarks Source: @deck.gl/carto
46
+ * @internal
47
+ */
48
+ type MapInstantiationFormats = Record<Format, {
49
+ url: string[];
50
+ error?: any;
51
+ }>;
52
+ export {};
package/build/types.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import type { FilterType } from './constants.js';
2
2
  import type { Polygon, MultiPolygon } from 'geojson';
3
+ /******************************************************************************
4
+ * MAPS AND TILES
5
+ */
6
+ /** @internalRemarks Source: @deck.gl/carto */
7
+ export type Format = 'json' | 'geojson' | 'tilejson';
8
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
9
+ export type MapType = 'boundary' | 'query' | 'table' | 'tileset' | 'raster';
3
10
  /******************************************************************************
4
11
  * AGGREGATION
5
12
  */
@@ -15,6 +22,10 @@ export type AggregationType = 'count' | 'avg' | 'min' | 'max' | 'sum' | 'custom'
15
22
  */
16
23
  /** @internalRemarks Source: @carto/react-api */
17
24
  export type SpatialFilter = Polygon | MultiPolygon;
25
+ /** @internalRemarks Source: @deck.gl/carto */
26
+ export interface Filters {
27
+ [column: string]: Filter;
28
+ }
18
29
  /** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
19
30
  export interface Filter {
20
31
  [FilterType.IN]?: {
@@ -1,5 +1,4 @@
1
1
  export * from './widget-base-source.js';
2
2
  export * from './widget-query-source.js';
3
3
  export * from './widget-table-source.js';
4
- export * from './wrappers.js';
5
4
  export * from './types.js';
@@ -1,8 +1,8 @@
1
1
  import { CategoryRequestOptions, CategoryResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from './types.js';
2
2
  import { FilterLogicalOperator, Filter } from '../types.js';
3
- import { ApiVersion } from '../constants-internal.js';
4
3
  import { ModelSource } from '../models/model.js';
5
4
  import { SourceOptions } from '../sources/index.js';
5
+ import { ApiVersion } from '../constants.js';
6
6
  export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
7
7
  apiVersion?: ApiVersion;
8
8
  geoColumn?: string;
@@ -2,6 +2,9 @@ import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptio
2
2
  import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
3
  import { ModelSource } from '../models/model.js';
4
4
  type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
5
+ export type WidgetQuerySourceResult = {
6
+ widgetSource: WidgetQuerySource;
7
+ };
5
8
  /**
6
9
  * Source for Widget API requests on a data source defined by a SQL query.
7
10
  *
@@ -2,6 +2,9 @@ import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptio
2
2
  import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
3
  import { ModelSource } from '../models/model.js';
4
4
  type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
5
+ export type WidgetTableSourceResult = {
6
+ widgetSource: WidgetTableSource;
7
+ };
5
8
  /**
6
9
  * Source for Widget API requests on a data source defined as a table.
7
10
  *
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "repository": "github:CartoDB/carto-api-client",
5
5
  "author": "Don McCurdy <donmccurdy@carto.com>",
6
6
  "packageManager": "yarn@4.3.1",
7
- "version": "0.4.0-alpha.0",
7
+ "version": "0.4.0-alpha.3",
8
8
  "license": "MIT",
9
9
  "publishConfig": {
10
10
  "access": "public",
@@ -34,7 +34,7 @@
34
34
  "dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
35
35
  "test": "vitest run --typecheck",
36
36
  "test:watch": "vitest watch --typecheck",
37
- "coverage": "vitest run --coverage",
37
+ "coverage": "vitest run --coverage.enabled --coverage.all false",
38
38
  "lint": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --check",
39
39
  "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write",
40
40
  "clean": "rimraf build/*",
@@ -2,7 +2,23 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {APIErrorContext} from './types';
5
+ import {MapType} from '../types';
6
+
7
+ export type APIRequestType =
8
+ | 'Map data'
9
+ | 'Map instantiation'
10
+ | 'Public map'
11
+ | 'Tile stats'
12
+ | 'SQL'
13
+ | 'Basemap style';
14
+
15
+ export type APIErrorContext = {
16
+ requestType: APIRequestType;
17
+ mapId?: string;
18
+ connection?: string;
19
+ source?: string;
20
+ type?: MapType;
21
+ };
6
22
 
7
23
  /**
8
24
  *
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {MapType} from './types';
5
+ import {MapType} from '../types.js';
6
6
 
7
7
  export type V3Endpoint = 'maps' | 'stats' | 'sql';
8
8
 
@@ -21,6 +21,7 @@ function buildV3Path(
21
21
  return joinPath(apiBaseUrl, version, endpoint, ...rest);
22
22
  }
23
23
 
24
+ /** @internal Required by fetchMap(). */
24
25
  export function buildPublicMapUrl({
25
26
  apiBaseUrl,
26
27
  cartoMapId,
@@ -31,6 +32,7 @@ export function buildPublicMapUrl({
31
32
  return buildV3Path(apiBaseUrl, 'v3', 'maps', 'public', cartoMapId);
32
33
  }
33
34
 
35
+ /** @internal Required by fetchMap(). */
34
36
  export function buildStatsUrl({
35
37
  attribute,
36
38
  apiBaseUrl,
package/src/api/index.ts CHANGED
@@ -2,16 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- export {CartoAPIError} from './carto-api-error';
6
- export type {
5
+ export {
6
+ CartoAPIError,
7
7
  APIErrorContext,
8
- Format,
9
- MapType,
10
- RequestType,
11
- QueryParameters,
12
- Basemap,
13
- MapLibreBasemap,
14
- GoogleBasemap,
15
- } from './types';
16
- export {query} from './query';
17
- export type {QueryOptions} from './query';
8
+ APIRequestType,
9
+ } from './carto-api-error.js';
10
+ // Internal, but required for fetchMap().
11
+ export {buildPublicMapUrl, buildStatsUrl} from './endpoints.js';
12
+ export {query} from './query.js';
13
+ export type {QueryOptions} from './query.js';
14
+ export {requestWithParameters} from './request-with-parameters.js';
package/src/api/query.ts CHANGED
@@ -10,7 +10,7 @@ import type {
10
10
  } from '../sources/types';
11
11
  import {buildQueryUrl} from './endpoints';
12
12
  import {requestWithParameters} from './request-with-parameters';
13
- import {APIErrorContext} from './types';
13
+ import {APIErrorContext} from './carto-api-error';
14
14
 
15
15
  export type QueryOptions = SourceOptions &
16
16
  Omit<QuerySourceOptions, 'spatialDataColumn'>;
@@ -3,13 +3,9 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  import {isPureObject} from '../utils';
6
- import {CartoAPIError} from './carto-api-error';
7
- import type {APIErrorContext} from './types';
8
- import {
9
- DEFAULT_CLIENT,
10
- DEFAULT_MAX_LENGTH_URL,
11
- V3_MINOR_VERSION,
12
- } from '../constants';
6
+ import {CartoAPIError, APIErrorContext} from './carto-api-error';
7
+ import {V3_MINOR_VERSION} from '../constants-internal';
8
+ import {DEFAULT_CLIENT, DEFAULT_MAX_LENGTH_URL} from '../constants';
13
9
 
14
10
  const DEFAULT_HEADERS = {
15
11
  Accept: 'application/json',
@@ -36,7 +32,7 @@ export async function requestWithParameters<T = any>({
36
32
  // user-provided parameters.
37
33
  parameters = {
38
34
  v: V3_MINOR_VERSION,
39
- clientId: DEFAULT_CLIENT,
35
+ client: DEFAULT_CLIENT,
40
36
  ...(typeof deck !== 'undefined' &&
41
37
  deck.VERSION && {deckglVersion: deck.VERSION}),
42
38
  ...parameters,
@@ -1,45 +1,24 @@
1
1
  /******************************************************************************
2
- * DEFAULTS
2
+ * VERSIONS
3
3
  */
4
4
 
5
5
  /**
6
- * @internalRemarks Source: @carto/constants
6
+ * Current version of @carto/api-client.
7
7
  * @internal
8
8
  */
9
- export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
9
+ export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
10
10
 
11
- /**
12
- * @internalRemarks Source: @carto/constants
13
- * @internal
14
- */
15
- export const DEFAULT_CLIENT = 'deck-gl-carto';
16
-
17
- /**
18
- * @internalRemarks Source: @carto/react-api
19
- * @internal
20
- */
21
- export const DEFAULT_GEO_COLUMN = 'geom';
22
-
23
- /******************************************************************************
24
- * ENUMS
25
- */
11
+ /** @internal */
12
+ export const V3_MINOR_VERSION = '3.4';
26
13
 
27
14
  /**
15
+ * @internalRemarks Source: @deck.gl/carto
28
16
  * @internal
29
- * @internalRemarks Source: @carto/constants
30
17
  */
31
- export enum MapType {
32
- TABLE = 'table',
33
- QUERY = 'query',
34
- TILESET = 'tileset',
35
- }
18
+ export const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
36
19
 
37
20
  /**
21
+ * @internalRemarks Source: @deck.gl/carto
38
22
  * @internal
39
- * @internalRemarks Source: @carto/constants
40
23
  */
41
- export enum ApiVersion {
42
- V1 = 'v1',
43
- V2 = 'v2',
44
- V3 = 'v3',
45
- }
24
+ export const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
package/src/constants.ts CHANGED
@@ -1,19 +1,3 @@
1
- /** Current version of @carto/api-client. */
2
- export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
3
-
4
- export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
5
- export const DEFAULT_CLIENT = 'deck-gl-carto';
6
- export const V3_MINOR_VERSION = '3.4';
7
-
8
- // Fastly default limit is 8192; leave some padding.
9
- export const DEFAULT_MAX_LENGTH_URL = 7000;
10
-
11
- export const DEFAULT_TILE_SIZE = 512;
12
- export const DEFAULT_TILE_RESOLUTION = 0.5;
13
-
14
- export const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
15
- export const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
16
-
17
1
  /**
18
2
  * Defines a comparator used when matching a column's values against given filter values.
19
3
  *
@@ -37,3 +21,35 @@ export enum FilterType {
37
21
  TIME = 'time',
38
22
  STRING_SEARCH = 'stringSearch',
39
23
  }
24
+
25
+ /** @internalRemarks Source: @carto/constants */
26
+ export enum ApiVersion {
27
+ V1 = 'v1',
28
+ V2 = 'v2',
29
+ V3 = 'v3',
30
+ }
31
+
32
+ /******************************************************************************
33
+ * DEFAULTS
34
+ */
35
+
36
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
37
+ export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
38
+
39
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
40
+ export const DEFAULT_CLIENT = 'deck-gl-carto';
41
+
42
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
43
+ export const DEFAULT_GEO_COLUMN = 'geom';
44
+
45
+ /**
46
+ * Fastly default limit is 8192; leave some padding.
47
+ * @internalRemarks Source: @deck.gl/carto
48
+ */
49
+ export const DEFAULT_MAX_LENGTH_URL = 7000;
50
+
51
+ /** @internalRemarks Source: @deck.gl/carto */
52
+ export const DEFAULT_TILE_SIZE = 512;
53
+
54
+ /** @internalRemarks Source: @deck.gl/carto */
55
+ export const DEFAULT_TILE_RESOLUTION = 0.5;
package/src/index.ts CHANGED
@@ -7,9 +7,47 @@ export * from './types.js';
7
7
 
8
8
  export {
9
9
  APIErrorContext,
10
- Format, // TODO: Move to `types.ts`?
11
- MapType, // TODO: De-duplicate?
12
- RequestType, // TODO: Move to `types.ts`?
13
- QueryParameters, // TODO: Move to `types.ts`?
14
- QueryOptions, // TODO: Move to `types.ts`?
10
+ APIRequestType,
11
+ CartoAPIError,
12
+ QueryOptions,
13
+ buildPublicMapUrl, // Internal, but required for fetchMap().
14
+ buildStatsUrl, // Internal, but required for fetchMap().
15
+ query,
16
+ requestWithParameters,
15
17
  } from './api/index.js';
18
+
19
+ export {
20
+ BoundaryQuerySourceOptions,
21
+ BoundaryTableSourceOptions,
22
+ GeojsonResult,
23
+ H3QuerySourceOptions,
24
+ H3TableSourceOptions,
25
+ H3TilesetSourceOptions,
26
+ JsonResult,
27
+ QuadbinQuerySourceOptions,
28
+ QuadbinTableSourceOptions,
29
+ QuadbinTilesetSourceOptions,
30
+ QueryResult,
31
+ QuerySourceOptions,
32
+ RasterSourceOptions,
33
+ SOURCE_DEFAULTS,
34
+ SourceOptions,
35
+ TableSourceOptions,
36
+ TilejsonResult,
37
+ TilesetSourceOptions,
38
+ VectorQuerySourceOptions,
39
+ VectorTableSourceOptions,
40
+ VectorTilesetSourceOptions,
41
+ boundaryQuerySource,
42
+ boundaryTableSource,
43
+ h3QuerySource,
44
+ h3TableSource,
45
+ h3TilesetSource,
46
+ quadbinQuerySource,
47
+ quadbinTableSource,
48
+ quadbinTilesetSource,
49
+ rasterSource,
50
+ vectorQuerySource,
51
+ vectorTableSource,
52
+ vectorTilesetSource,
53
+ } from './sources/index.js';
@@ -1,17 +1,15 @@
1
- import {
2
- ApiVersion,
3
- DEFAULT_GEO_COLUMN,
4
- MapType,
5
- } from '../constants-internal.js';
1
+ import {DEFAULT_GEO_COLUMN} from '../constants.js';
6
2
  import {
7
3
  Filter,
8
4
  FilterLogicalOperator,
5
+ MapType,
9
6
  QueryParameters,
10
7
  SpatialFilter,
11
8
  } from '../types.js';
12
9
  import {$TODO} from '../types-internal.js';
13
10
  import {assert} from '../utils.js';
14
11
  import {ModelRequestOptions, makeCall} from './common.js';
12
+ import {ApiVersion} from '../constants.js';
15
13
 
16
14
  /** @internalRemarks Source: @carto/react-api */
17
15
  const AVAILABLE_MODELS = [
@@ -72,7 +70,7 @@ export function executeModel(props: {
72
70
  assert(apiBaseUrl, 'executeModel: missing apiBaseUrl');
73
71
  assert(accessToken, 'executeModel: missing accessToken');
74
72
  assert(apiVersion === V3, 'executeModel: SQL Model API requires CARTO 3+');
75
- assert(type !== MapType.TILESET, 'executeModel: Tilesets not supported');
73
+ assert(type !== 'tileset', 'executeModel: Tilesets not supported');
76
74
 
77
75
  let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
78
76
 
@@ -10,7 +10,6 @@ import {
10
10
  } from '../constants';
11
11
  import {buildSourceUrl} from '../api/endpoints';
12
12
  import {requestWithParameters} from '../api/request-with-parameters';
13
- import type {APIErrorContext, MapType} from '../api/types';
14
13
  import type {
15
14
  GeojsonResult,
16
15
  JsonResult,
@@ -19,6 +18,8 @@ import type {
19
18
  TilejsonMapInstantiation,
20
19
  TilejsonResult,
21
20
  } from './types';
21
+ import {MapType} from '../types';
22
+ import {APIErrorContext} from '../api';
22
23
 
23
24
  export const SOURCE_DEFAULTS: SourceOptionalOptions = {
24
25
  apiBaseUrl: DEFAULT_API_BASE_URL,
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {QueryParameters} from '../api/index';
5
+ import {QueryParameters} from '../types.js';
6
6
  import {baseSource} from './base-source';
7
7
  import type {FilterOptions, SourceOptions, TilejsonResult} from './types';
8
8
 
@@ -3,7 +3,8 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants';
6
+ import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants-internal';
7
+ import {WidgetQuerySource, WidgetQuerySourceResult} from '../widget-sources';
7
8
  import {baseSource} from './base-source';
8
9
  import type {
9
10
  AggregationOptions,
@@ -30,7 +31,7 @@ type UrlParameters = {
30
31
 
31
32
  export const h3QuerySource = async function (
32
33
  options: H3QuerySourceOptions
33
- ): Promise<TilejsonResult> {
34
+ ): Promise<TilejsonResult & WidgetQuerySourceResult> {
34
35
  const {
35
36
  aggregationExp,
36
37
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
@@ -55,9 +56,10 @@ export const h3QuerySource = async function (
55
56
  if (filters) {
56
57
  urlParameters.filters = filters;
57
58
  }
58
- return baseSource<UrlParameters>(
59
- 'query',
60
- options,
61
- urlParameters
62
- ) as Promise<TilejsonResult>;
59
+ return baseSource<UrlParameters>('query', options, urlParameters).then(
60
+ (result) => ({
61
+ ...(result as TilejsonResult),
62
+ widgetSource: new WidgetQuerySource(options),
63
+ })
64
+ );
63
65
  };
@@ -3,7 +3,8 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants';
6
+ import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants-internal';
7
+ import {WidgetTableSource, WidgetTableSourceResult} from '../widget-sources';
7
8
  import {baseSource} from './base-source';
8
9
  import type {
9
10
  AggregationOptions,
@@ -30,7 +31,7 @@ type UrlParameters = {
30
31
 
31
32
  export const h3TableSource = async function (
32
33
  options: H3TableSourceOptions
33
- ): Promise<TilejsonResult> {
34
+ ): Promise<TilejsonResult & WidgetTableSourceResult> {
34
35
  const {
35
36
  aggregationExp,
36
37
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
@@ -51,9 +52,10 @@ export const h3TableSource = async function (
51
52
  if (filters) {
52
53
  urlParameters.filters = filters;
53
54
  }
54
- return baseSource<UrlParameters>(
55
- 'table',
56
- options,
57
- urlParameters
58
- ) as Promise<TilejsonResult>;
55
+ return baseSource<UrlParameters>('table', options, urlParameters).then(
56
+ (result) => ({
57
+ ...(result as TilejsonResult),
58
+ widgetSource: new WidgetTableSource(options),
59
+ })
60
+ );
59
61
  };