Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/carto/src/sources/base-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
JsonResult,
SourceOptionalOptions,
SourceRequiredOptions,
Tilejson,
TilejsonMapInstantiation,
TilejsonResult
} from './types';
Expand Down
89 changes: 87 additions & 2 deletions modules/carto/src/sources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,124 @@ import type {Feature} from 'geojson';
import type {Format, MapInstantiation, QueryParameters} from '../api/types';

export type SourceRequiredOptions = {
/** Carto platform access token. */
accessToken: string;

/** Data warehouse connection name in Carto platform. */
connectionName: string;
};

export type SourceOptionalOptions = {
/**
* Base URL of the CARTO Maps API.
*
* Example for account located in EU-west region: `https://gcp-eu-west1.api.carto.com`
*
* @default https://gcp-us-east1.api.carto.com
*/
apiBaseUrl: string;

/**
* Custom HTTP headers added to map instantiation and data requests.
*/
headers: Record<string, string>;

/**
* Cache buster value returned by map instantiation.
*
* Carto source saves `cache` value of map instantiation response in `cache.value`, so it can be used to
* check if underlying map data has changed between distinct source requests.
*/
cache?: {value?: number};

clientId: string;
/** @deprecated use `query` instead **/
format: Format;
headers: Record<string, string>;
};

export type SourceOptions = SourceRequiredOptions & Partial<SourceOptionalOptions>;

export type AggregationOptions = {
/**
* Defines the aggregation expressions that will be calculated from the resulting columns on each grid cell.
*
* Example:
*
* sum(pop) as total_population, avg(rev) as average_revenue
*/
aggregationExp: string;

/**
* Defines the tile aggregation resolution.
*
* @default 6 for quadbin and 4 for h3 sources
*/
aggregationResLevel?: number;
};

export type QuerySourceOptions = {
/**
* The column name and the type of geospatial support.
*
* If not present, defaults to `'geom'` for generic queries, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
*/
spatialDataColumn?: string;

/** SQL query. */
sqlQuery: string;

/**
* Values for named or positional paramteres in the query.
*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*

* The way query parameters are determined by data warehouse.
*
* * BigQuery has named query parameters, specified with a dictionary, and referenced by key (`@key`)
*
* ```
* sqlQuery: "SELECT * FROM carto-demo-data.demo_tables.retail_stores WHERE storetype = ⁣@type AND revenue > ⁣@minRevenue"
* queryParameters: { type: 'Supermarket', minRevenue: 1000000 }
* ```
* * Snowflake supports positional parameters, in the form `:1`, `:2`, etc.
*
* ```
* sqlQuery: "SELECT * FROM demo_db.public.import_retail_stores WHERE storetype = :2 AND revenue > :1
* queryParameters: [100000, "Supermarket"]
* ```
* * Postgres and Redhisft supports positional parameters, but in the form `$1`, `$2`, etc.
*
* ```
* sqlQuery: "SELECT * FROM carto_demo_data.demo_tables.retail_stores WHERE storetype = $2 AND revenue > $1
* queryParameters: [100000, "Supermarket"]
* ```
*/
queryParameters?: QueryParameters;
};

export type TableSourceOptions = {
/**
* Fully qualified name of table.
*/
tableName: string;

/**
* Columns to retrieve from the table.
*
* If not present, all columns are returned.
*/
columns?: string[];

/**
* The column name and the type of geospatial support.
*
* If not present, defaults to `'geom'` for generic tables, `'quadbin'` for Quadbin sources and `'h3'` for H3 sources.
*/
spatialDataColumn?: string;
tableName: string;
};

export type TilesetSourceOptions = {
/**
* Fully qualified name of tileset.
*/
tableName: string;
};

Expand Down