@carto/api-client 0.5.10-alpha.PR193.4 → 0.5.10
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/CHANGELOG.md +4 -0
- package/build/api-client.cjs +23 -34
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +3 -16
- package/build/api-client.d.ts +3 -16
- package/build/api-client.js +23 -34
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +9 -6
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +9 -6
- package/build/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/api/query.ts +2 -19
- package/src/api/request-with-parameters.ts +5 -10
- package/src/models/model.ts +0 -3
- package/src/operations/groupBy.ts +14 -6
- package/src/sources/base-source.ts +1 -1
- package/src/sources/types.ts +0 -3
- package/src/widget-sources/types.ts +5 -1
- package/src/widget-sources/widget-remote-source.ts +0 -1
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
9
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
10
10
|
"packageManager": "yarn@4.3.1",
|
|
11
|
-
"version": "0.5.10
|
|
11
|
+
"version": "0.5.10",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
package/src/api/query.ts
CHANGED
|
@@ -13,17 +13,7 @@ import {requestWithParameters} from './request-with-parameters.js';
|
|
|
13
13
|
import type {APIErrorContext} from './carto-api-error.js';
|
|
14
14
|
import {getClient} from '../client.js';
|
|
15
15
|
|
|
16
|
-
export type QueryOptions = SourceOptions &
|
|
17
|
-
QuerySourceOptions & {
|
|
18
|
-
/**
|
|
19
|
-
* @internal
|
|
20
|
-
* @experimental
|
|
21
|
-
* Used to append additional parameters to the SQL API request for features specific to providers or integrations.
|
|
22
|
-
*/
|
|
23
|
-
internalParameters?: Record<string, string | boolean | number>;
|
|
24
|
-
/** Used to abort the request. */
|
|
25
|
-
signal?: AbortSignal;
|
|
26
|
-
};
|
|
16
|
+
export type QueryOptions = SourceOptions & QuerySourceOptions;
|
|
27
17
|
type UrlParameters = {q: string; queryParameters?: string};
|
|
28
18
|
|
|
29
19
|
export const query = async function (
|
|
@@ -37,7 +27,6 @@ export const query = async function (
|
|
|
37
27
|
connectionName,
|
|
38
28
|
sqlQuery,
|
|
39
29
|
queryParameters,
|
|
40
|
-
internalParameters,
|
|
41
30
|
} = options;
|
|
42
31
|
const urlParameters: UrlParameters = {q: sqlQuery};
|
|
43
32
|
|
|
@@ -50,12 +39,7 @@ export const query = async function (
|
|
|
50
39
|
Authorization: `Bearer ${options.accessToken}`,
|
|
51
40
|
...options.headers,
|
|
52
41
|
};
|
|
53
|
-
const parameters = {
|
|
54
|
-
client: clientId,
|
|
55
|
-
...options.tags,
|
|
56
|
-
...internalParameters,
|
|
57
|
-
...urlParameters,
|
|
58
|
-
};
|
|
42
|
+
const parameters = {client: clientId, ...urlParameters};
|
|
59
43
|
|
|
60
44
|
const errorContext: APIErrorContext = {
|
|
61
45
|
requestType: 'SQL',
|
|
@@ -70,6 +54,5 @@ export const query = async function (
|
|
|
70
54
|
errorContext,
|
|
71
55
|
maxLengthURL,
|
|
72
56
|
localCache,
|
|
73
|
-
signal: options.signal,
|
|
74
57
|
});
|
|
75
58
|
};
|
|
@@ -23,7 +23,6 @@ export async function requestWithParameters<T = any>({
|
|
|
23
23
|
errorContext,
|
|
24
24
|
maxLengthURL = DEFAULT_MAX_LENGTH_URL,
|
|
25
25
|
localCache,
|
|
26
|
-
signal,
|
|
27
26
|
}: {
|
|
28
27
|
baseUrl: string;
|
|
29
28
|
parameters?: Record<string, unknown>;
|
|
@@ -31,7 +30,6 @@ export async function requestWithParameters<T = any>({
|
|
|
31
30
|
errorContext: APIErrorContext;
|
|
32
31
|
maxLengthURL?: number;
|
|
33
32
|
localCache?: LocalCacheOptions;
|
|
34
|
-
signal?: AbortSignal;
|
|
35
33
|
}): Promise<T> {
|
|
36
34
|
// Parameters added to all requests issued with `requestWithParameters()`.
|
|
37
35
|
// These parameters override parameters already in the base URL, but not
|
|
@@ -67,9 +65,8 @@ export async function requestWithParameters<T = any>({
|
|
|
67
65
|
method: 'POST',
|
|
68
66
|
body: JSON.stringify(parameters),
|
|
69
67
|
headers,
|
|
70
|
-
signal,
|
|
71
68
|
})
|
|
72
|
-
: fetch(url, {headers
|
|
69
|
+
: fetch(url, {headers});
|
|
73
70
|
|
|
74
71
|
let response: Response | undefined;
|
|
75
72
|
let responseJson: unknown;
|
|
@@ -146,12 +143,10 @@ function createURLWithParameters(
|
|
|
146
143
|
if (isPureObject(value) || Array.isArray(value)) {
|
|
147
144
|
baseUrl.searchParams.set(key, JSON.stringify(value));
|
|
148
145
|
} else {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
);
|
|
154
|
-
}
|
|
146
|
+
baseUrl.searchParams.set(
|
|
147
|
+
key,
|
|
148
|
+
(value as string | boolean | number).toString()
|
|
149
|
+
);
|
|
155
150
|
}
|
|
156
151
|
}
|
|
157
152
|
return baseUrl.toString();
|
package/src/models/model.ts
CHANGED
|
@@ -43,7 +43,6 @@ export interface ModelSource {
|
|
|
43
43
|
spatialDataColumn?: string;
|
|
44
44
|
spatialDataType?: SpatialDataType;
|
|
45
45
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
46
|
-
tags?: Record<string, string>;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
const {V3} = ApiVersion;
|
|
@@ -88,7 +87,6 @@ export function executeModel(props: {
|
|
|
88
87
|
spatialDataType = 'geo',
|
|
89
88
|
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
90
89
|
spatialFiltersMode = 'intersects',
|
|
91
|
-
tags,
|
|
92
90
|
} = source;
|
|
93
91
|
|
|
94
92
|
const queryParams: Record<string, unknown> = {
|
|
@@ -99,7 +97,6 @@ export function executeModel(props: {
|
|
|
99
97
|
queryParameters: source.queryParameters || '',
|
|
100
98
|
filters,
|
|
101
99
|
filtersLogicalOperator,
|
|
102
|
-
...(tags ?? {}),
|
|
103
100
|
};
|
|
104
101
|
|
|
105
102
|
queryParams.spatialDataType = spatialDataType;
|
|
@@ -85,19 +85,27 @@ export function getSorter(
|
|
|
85
85
|
switch (orderBy) {
|
|
86
86
|
case 'frequency_asc':
|
|
87
87
|
// 'value ASC, name ASC'
|
|
88
|
-
return (a, b) => a.value - b.value ||
|
|
88
|
+
return (a, b) => a.value - b.value || nameCompare(a.name, b.name);
|
|
89
89
|
case 'frequency_desc':
|
|
90
90
|
// 'value DESC, name ASC'
|
|
91
|
-
return (a, b) => b.value - a.value ||
|
|
91
|
+
return (a, b) => b.value - a.value || nameCompare(a.name, b.name);
|
|
92
92
|
case 'alphabetical_asc':
|
|
93
93
|
// 'name ASC, value DESC'
|
|
94
|
-
return (a, b) =>
|
|
94
|
+
return (a, b) => nameCompare(a.name, b.name) || b.value - a.value;
|
|
95
95
|
case 'alphabetical_desc':
|
|
96
96
|
// 'name DESC, value DESC'
|
|
97
|
-
return (a, b) =>
|
|
97
|
+
return (a, b) => nameCompare(b.name, a.name) || b.value - a.value;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function
|
|
102
|
-
|
|
101
|
+
function nameCompare(
|
|
102
|
+
a?: CategoryResponseEntry['name'],
|
|
103
|
+
b?: CategoryResponseEntry['name']
|
|
104
|
+
) {
|
|
105
|
+
// Despite the naming of 'alphabetical_*' sort options, we still want to
|
|
106
|
+
// sort numeric category names (usually raster datasets) numerically.
|
|
107
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
108
|
+
return a - b;
|
|
109
|
+
}
|
|
110
|
+
return String(a ?? 'null').localeCompare(String(b ?? 'null'));
|
|
103
111
|
}
|
|
@@ -47,7 +47,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
47
47
|
Authorization: `Bearer ${options.accessToken}`,
|
|
48
48
|
...options.headers,
|
|
49
49
|
};
|
|
50
|
-
const parameters = {client: clientId, ...
|
|
50
|
+
const parameters = {client: clientId, ...urlParameters};
|
|
51
51
|
|
|
52
52
|
const errorContext: APIErrorContext = {
|
|
53
53
|
requestType: 'Map instantiation',
|
package/src/sources/types.ts
CHANGED
|
@@ -75,9 +75,6 @@ export type SourceOptionalOptions = {
|
|
|
75
75
|
* By default, local in-memory caching is enabled.
|
|
76
76
|
*/
|
|
77
77
|
localCache?: LocalCacheOptions;
|
|
78
|
-
|
|
79
|
-
/** Additional tags appended to HTTP requests, available for analytics and audits. */
|
|
80
|
-
tags?: Record<string, string>;
|
|
81
78
|
};
|
|
82
79
|
|
|
83
80
|
export type LocalCacheOptions = {
|
|
@@ -221,7 +221,11 @@ export type FeaturesResponse = {rows: Record<string, unknown>[]};
|
|
|
221
221
|
export type FormulaResponse = {value: number | null};
|
|
222
222
|
|
|
223
223
|
/** Entry in the category widget response, see {@link WidgetRemoteSource#getCategories}. */
|
|
224
|
-
export type CategoryResponseEntry = {
|
|
224
|
+
export type CategoryResponseEntry = {
|
|
225
|
+
name: string | number | null;
|
|
226
|
+
value: number;
|
|
227
|
+
};
|
|
228
|
+
|
|
225
229
|
/** Response from {@link WidgetRemoteSource#getCategories}. */
|
|
226
230
|
export type CategoryResponse = CategoryResponseEntry[];
|
|
227
231
|
|