Skip to content

Commit

Permalink
deps(carto): Add @carto/api-client (#9230)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Nov 4, 2024
1 parent 0b70ac2 commit 920cf98
Show file tree
Hide file tree
Showing 53 changed files with 130 additions and 2,188 deletions.
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

0 comments on commit 920cf98

Please sign in to comment.