Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(carto): Add @carto/api-client #9230

Merged
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: 1 addition & 0 deletions modules/carto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
},
"dependencies": {
"@carto/api-client": "^0.4.0-alpha.4",
"@loaders.gl/gis": "^4.2.0",
"@loaders.gl/loader-utils": "^4.2.0",
"@loaders.gl/mvt": "^4.2.0",
Expand Down
3 changes: 2 additions & 1 deletion modules/carto/src/api/basemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
getStyleUrl,
someLayerGroupsDisabled
} from '../basemap';
import {APIErrorContext, Basemap, KeplerMapConfig, MapLibreBasemapProps} from './types';
import {Basemap, KeplerMapConfig, MapLibreBasemapProps} from './types';
import {APIErrorContext} from '@carto/api-client';

const CUSTOM_STYLE_ID_PREFIX = 'custom:';
const DEFAULT_CARTO_STYLE = 'positron';
Expand Down
72 changes: 0 additions & 72 deletions modules/carto/src/api/carto-api-error.ts

This file was deleted.

10 changes: 0 additions & 10 deletions modules/carto/src/api/common.ts

This file was deleted.

73 changes: 0 additions & 73 deletions modules/carto/src/api/endpoints.ts

This file was deleted.

34 changes: 19 additions & 15 deletions modules/carto/src/api/fetch-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

/* eslint-disable camelcase */
import {CartoAPIError} from './carto-api-error';
import {DEFAULT_API_BASE_URL, DEFAULT_CLIENT, DEFAULT_MAX_LENGTH_URL} from './common';
import {buildPublicMapUrl, buildStatsUrl} from './endpoints';
import {
SOURCE_DEFAULTS,
APIErrorContext,
CartoAPIError,
GeojsonResult,
JsonResult,
TilejsonResult,
Format,
MapType,
QueryParameters,
buildPublicMapUrl,
buildStatsUrl,
h3QuerySource,
h3TableSource,
quadbinQuerySource,
quadbinTableSource,
vectorQuerySource,
vectorTableSource,
vectorTilesetSource
} from '../sources/index';
vectorTilesetSource,
requestWithParameters
} from '@carto/api-client';
import {ParseMapResult, parseMap} from './parse-map';
import {requestWithParameters} from './request-with-parameters';
import {assert} from '../utils';
import type {APIErrorContext, Basemap, Format, MapType, QueryParameters} from './types';
import type {Basemap} from './types';
import {fetchBasemapProps} from './basemap';

type Dataset = {
Expand All @@ -47,7 +51,7 @@ async function _fetchMapDataset(
apiBaseUrl: string,
clientId?: string,
headers?: Record<string, string>,
maxLengthURL = DEFAULT_MAX_LENGTH_URL
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL
) {
const {
aggregationExp,
Expand Down Expand Up @@ -121,7 +125,7 @@ async function _fetchTilestats(
dataset: Dataset,
accessToken: string,
apiBaseUrl: string,
maxLengthURL = DEFAULT_MAX_LENGTH_URL
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL
) {
const {connectionName, data, id, source, type, queryParameters} = dataset;
const errorContext: APIErrorContext = {
Expand Down Expand Up @@ -167,7 +171,7 @@ async function fillInMapDatasets(
clientId: string,
apiBaseUrl: string,
headers?: Record<string, string>,
maxLengthURL = DEFAULT_MAX_LENGTH_URL
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL
) {
const promises = datasets.map(dataset =>
_fetchMapDataset(dataset, token, apiBaseUrl, clientId, headers, maxLengthURL)
Expand All @@ -178,7 +182,7 @@ async function fillInMapDatasets(
async function fillInTileStats(
{datasets, keplerMapConfig, token}: {datasets: Dataset[]; keplerMapConfig: any; token: string},
apiBaseUrl: string,
maxLengthURL = DEFAULT_MAX_LENGTH_URL
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL
) {
const attributes: {attribute: string; dataset: any}[] = [];
const {layers} = keplerMapConfig.config.visState;
Expand Down Expand Up @@ -267,13 +271,13 @@ export type FetchMapResult = ParseMapResult & {
/* eslint-disable max-statements */
export async function fetchMap({
accessToken,
apiBaseUrl = DEFAULT_API_BASE_URL,
apiBaseUrl = SOURCE_DEFAULTS.apiBaseUrl,
cartoMapId,
clientId = DEFAULT_CLIENT,
clientId = SOURCE_DEFAULTS.clientId,
headers = {},
autoRefresh,
onNewData,
maxLengthURL = DEFAULT_MAX_LENGTH_URL
maxLengthURL = SOURCE_DEFAULTS.maxLengthURL
}: FetchMapOptions): Promise<FetchMapResult> {
assert(cartoMapId, 'Must define CARTO map id: fetchMap({cartoMapId: "XXXX-XXXX-XXXX"})');
assert(apiBaseUrl, 'Must define apiBaseUrl');
Expand Down
14 changes: 1 addition & 13 deletions modules/carto/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

export {CartoAPIError} from './carto-api-error';
export {fetchMap} from './fetch-map';
export type {FetchMapOptions, FetchMapResult} from './fetch-map';
export type {
APIErrorContext,
Format,
MapType,
RequestType,
QueryParameters,
Basemap,
MapLibreBasemap,
GoogleBasemap
} from './types';
export {query} from './query';
export type {QueryOptions} from './query';
export type {Basemap, MapLibreBasemap, GoogleBasemap} from './types';
46 changes: 0 additions & 46 deletions modules/carto/src/api/query.ts

This file was deleted.

Loading
Loading