@carto/api-client 0.4.0-alpha.3 → 0.4.0-alpha.5
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.
- package/build/api-client.cjs +31 -42
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.modern.js +32 -38
- package/build/api-client.modern.js.map +1 -1
- package/build/constants-internal.d.ts +9 -3
- package/build/constants.d.ts +0 -16
- package/build/models/common.d.ts +7 -2
- package/package.json +2 -2
- package/src/api/request-with-parameters.ts +3 -2
- package/src/client.ts +2 -2
- package/src/constants-internal.ts +12 -4
- package/src/constants.ts +0 -22
- package/src/models/common.ts +11 -3
- package/src/models/model.ts +1 -1
- package/src/sources/base-source.ts +4 -7
- package/src/sources/vector-query-source.ts +1 -1
- package/src/sources/vector-table-source.ts +1 -1
- package/src/types.ts +0 -1
- package/src/utils.ts +1 -2
- package/src/widget-sources/widget-base-source.ts +2 -5
package/build/models/common.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { $TODO } from '../types-internal.js';
|
|
2
1
|
/** @internalRemarks Source: @carto/react-api */
|
|
3
2
|
export interface ModelRequestOptions {
|
|
4
3
|
method: 'GET' | 'POST';
|
|
@@ -6,13 +5,18 @@ export interface ModelRequestOptions {
|
|
|
6
5
|
otherOptions?: Record<string, unknown>;
|
|
7
6
|
body?: string;
|
|
8
7
|
}
|
|
8
|
+
interface ModelErrorResponse {
|
|
9
|
+
error?: string | string[];
|
|
10
|
+
hint?: string;
|
|
11
|
+
column_name?: string;
|
|
12
|
+
}
|
|
9
13
|
/**
|
|
10
14
|
* Return more descriptive error from API
|
|
11
15
|
* @internalRemarks Source: @carto/react-api
|
|
12
16
|
*/
|
|
13
17
|
export declare function dealWithApiError({ response, data, }: {
|
|
14
18
|
response: Response;
|
|
15
|
-
data:
|
|
19
|
+
data: ModelErrorResponse;
|
|
16
20
|
}): void;
|
|
17
21
|
/** @internalRemarks Source: @carto/react-api */
|
|
18
22
|
export declare function makeCall({ url, accessToken, opts, }: {
|
|
@@ -20,3 +24,4 @@ export declare function makeCall({ url, accessToken, opts, }: {
|
|
|
20
24
|
accessToken: string;
|
|
21
25
|
opts: ModelRequestOptions;
|
|
22
26
|
}): Promise<any>;
|
|
27
|
+
export {};
|
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.
|
|
7
|
+
"version": "0.4.0-alpha.5",
|
|
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",
|
|
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/*",
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import {isPureObject} from '../utils';
|
|
6
6
|
import {CartoAPIError, APIErrorContext} from './carto-api-error';
|
|
7
7
|
import {V3_MINOR_VERSION} from '../constants-internal';
|
|
8
|
-
import {
|
|
8
|
+
import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal';
|
|
9
|
+
import {getClient} from '../client';
|
|
9
10
|
|
|
10
11
|
const DEFAULT_HEADERS = {
|
|
11
12
|
Accept: 'application/json',
|
|
@@ -32,7 +33,7 @@ export async function requestWithParameters<T = any>({
|
|
|
32
33
|
// user-provided parameters.
|
|
33
34
|
parameters = {
|
|
34
35
|
v: V3_MINOR_VERSION,
|
|
35
|
-
client:
|
|
36
|
+
client: getClient(),
|
|
36
37
|
...(typeof deck !== 'undefined' &&
|
|
37
38
|
deck.VERSION && {deckglVersion: deck.VERSION}),
|
|
38
39
|
...parameters,
|
package/src/client.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @internal
|
|
3
|
-
* @internalRemarks Source: @carto/react-core
|
|
3
|
+
* @internalRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
|
|
4
4
|
*/
|
|
5
|
-
let client = '
|
|
5
|
+
let client = 'deck-gl-carto';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Returns current client ID, used to categorize API requests. For internal use only.
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/******************************************************************************
|
|
2
|
-
* VERSIONS
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Current version of @carto/api-client.
|
|
7
3
|
* @internal
|
|
@@ -11,6 +7,18 @@ export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
|
|
|
11
7
|
/** @internal */
|
|
12
8
|
export const V3_MINOR_VERSION = '3.4';
|
|
13
9
|
|
|
10
|
+
/** @internalRemarks Source: @carto/constants, @deck.gl/carto */
|
|
11
|
+
export const DEFAULT_GEO_COLUMN = 'geom';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fastly default limit is 8192; leave some padding.
|
|
15
|
+
* @internalRemarks Source: @deck.gl/carto
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_MAX_LENGTH_URL = 7000;
|
|
18
|
+
|
|
19
|
+
/** @internalRemarks Source: @deck.gl/carto */
|
|
20
|
+
export const DEFAULT_TILE_RESOLUTION = 0.5;
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* @internalRemarks Source: @deck.gl/carto
|
|
16
24
|
* @internal
|
package/src/constants.ts
CHANGED
|
@@ -29,27 +29,5 @@ export enum ApiVersion {
|
|
|
29
29
|
V3 = 'v3',
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/******************************************************************************
|
|
33
|
-
* DEFAULTS
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
32
|
/** @internalRemarks Source: @carto/constants, @deck.gl/carto */
|
|
37
33
|
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/models/common.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {$TODO} from '../types-internal.js';
|
|
2
1
|
import {InvalidColumnError} from '../utils.js';
|
|
3
2
|
|
|
4
3
|
/** @internalRemarks Source: @carto/react-api */
|
|
@@ -9,6 +8,12 @@ export interface ModelRequestOptions {
|
|
|
9
8
|
body?: string;
|
|
10
9
|
}
|
|
11
10
|
|
|
11
|
+
interface ModelErrorResponse {
|
|
12
|
+
error?: string | string[];
|
|
13
|
+
hint?: string;
|
|
14
|
+
column_name?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* Return more descriptive error from API
|
|
14
19
|
* @internalRemarks Source: @carto/react-api
|
|
@@ -18,13 +23,16 @@ export function dealWithApiError({
|
|
|
18
23
|
data,
|
|
19
24
|
}: {
|
|
20
25
|
response: Response;
|
|
21
|
-
data:
|
|
26
|
+
data: ModelErrorResponse;
|
|
22
27
|
}) {
|
|
23
28
|
if (data.error === 'Column not found') {
|
|
24
29
|
throw new InvalidColumnError(`${data.error} ${data.column_name}`);
|
|
25
30
|
}
|
|
26
31
|
|
|
27
|
-
if (
|
|
32
|
+
if (
|
|
33
|
+
typeof data.error === 'string' &&
|
|
34
|
+
data.error?.includes('Missing columns')
|
|
35
|
+
) {
|
|
28
36
|
throw new InvalidColumnError(data.error);
|
|
29
37
|
}
|
|
30
38
|
|
package/src/models/model.ts
CHANGED
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_API_BASE_URL,
|
|
8
|
-
DEFAULT_CLIENT,
|
|
9
|
-
DEFAULT_MAX_LENGTH_URL,
|
|
10
|
-
} from '../constants';
|
|
5
|
+
import {DEFAULT_API_BASE_URL} from '../constants';
|
|
6
|
+
import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal';
|
|
11
7
|
import {buildSourceUrl} from '../api/endpoints';
|
|
12
8
|
import {requestWithParameters} from '../api/request-with-parameters';
|
|
13
9
|
import type {
|
|
@@ -20,10 +16,11 @@ import type {
|
|
|
20
16
|
} from './types';
|
|
21
17
|
import {MapType} from '../types';
|
|
22
18
|
import {APIErrorContext} from '../api';
|
|
19
|
+
import {getClient} from '../client';
|
|
23
20
|
|
|
24
21
|
export const SOURCE_DEFAULTS: SourceOptionalOptions = {
|
|
25
22
|
apiBaseUrl: DEFAULT_API_BASE_URL,
|
|
26
|
-
clientId:
|
|
23
|
+
clientId: getClient(),
|
|
27
24
|
format: 'tilejson',
|
|
28
25
|
headers: {},
|
|
29
26
|
maxLengthURL: DEFAULT_MAX_LENGTH_URL,
|
package/src/types.ts
CHANGED
|
@@ -41,7 +41,6 @@ export interface Filters {
|
|
|
41
41
|
[column: string]: Filter;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
// TODO: Would `{[FilterType.IN]?: number[] | string[]}` also be valid?
|
|
45
44
|
/** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
|
|
46
45
|
export interface Filter {
|
|
47
46
|
[FilterType.IN]?: {owner?: string; values: number[] | string[]};
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {Filter} from './types.js';
|
|
2
2
|
import {FilterType} from './constants.js';
|
|
3
|
-
import {$TODO} from './types-internal.js';
|
|
4
3
|
|
|
5
4
|
const FILTER_TYPES = new Set(Object.values(FilterType));
|
|
6
5
|
const isFilterType = (type: string): type is FilterType =>
|
|
@@ -26,7 +25,7 @@ export function getApplicableFilters(
|
|
|
26
25
|
const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
|
|
27
26
|
if (filter && isApplicable) {
|
|
28
27
|
applicableFilters[column] ||= {};
|
|
29
|
-
applicableFilters[column][type]
|
|
28
|
+
(applicableFilters[column][type] as typeof filter) = filter;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -20,11 +20,8 @@ import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
|
|
|
20
20
|
import {getClient} from '../client.js';
|
|
21
21
|
import {ModelSource} from '../models/model.js';
|
|
22
22
|
import {SourceOptions} from '../sources/index.js';
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
DEFAULT_API_BASE_URL,
|
|
26
|
-
DEFAULT_GEO_COLUMN,
|
|
27
|
-
} from '../constants.js';
|
|
23
|
+
import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
|
|
24
|
+
import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
|
|
28
25
|
|
|
29
26
|
export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
|
|
30
27
|
apiVersion?: ApiVersion;
|