@carto/api-client 0.4.0-alpha.1 → 0.4.0-alpha.4

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.
Files changed (40) hide show
  1. package/build/api-client.cjs +106 -184
  2. package/build/api-client.cjs.map +1 -1
  3. package/build/api-client.modern.js +97 -144
  4. package/build/api-client.modern.js.map +1 -1
  5. package/build/constants-internal.d.ts +11 -3
  6. package/build/constants.d.ts +0 -18
  7. package/build/index.d.ts +1 -1
  8. package/build/models/common.d.ts +7 -2
  9. package/build/sources/h3-query-source.d.ts +2 -1
  10. package/build/sources/h3-table-source.d.ts +2 -1
  11. package/build/sources/quadbin-query-source.d.ts +2 -1
  12. package/build/sources/quadbin-table-source.d.ts +2 -1
  13. package/build/sources/vector-query-source.d.ts +2 -1
  14. package/build/sources/vector-table-source.d.ts +2 -1
  15. package/build/widget-sources/index.d.ts +0 -1
  16. package/build/widget-sources/widget-query-source.d.ts +3 -0
  17. package/build/widget-sources/widget-table-source.d.ts +3 -0
  18. package/package.json +1 -1
  19. package/src/api/request-with-parameters.ts +3 -2
  20. package/src/client.ts +2 -2
  21. package/src/constants-internal.ts +14 -3
  22. package/src/constants.ts +0 -25
  23. package/src/index.ts +17 -7
  24. package/src/models/common.ts +11 -3
  25. package/src/models/model.ts +1 -1
  26. package/src/sources/base-source.ts +3 -3
  27. package/src/sources/h3-query-source.ts +8 -6
  28. package/src/sources/h3-table-source.ts +8 -6
  29. package/src/sources/quadbin-query-source.ts +8 -6
  30. package/src/sources/quadbin-table-source.ts +8 -6
  31. package/src/sources/vector-query-source.ts +12 -7
  32. package/src/sources/vector-table-source.ts +12 -7
  33. package/src/types.ts +0 -1
  34. package/src/utils.ts +1 -2
  35. package/src/widget-sources/index.ts +0 -1
  36. package/src/widget-sources/widget-base-source.ts +2 -2
  37. package/src/widget-sources/widget-query-source.ts +2 -0
  38. package/src/widget-sources/widget-table-source.ts +2 -0
  39. package/build/widget-sources/wrappers.d.ts +0 -48
  40. package/src/widget-sources/wrappers.ts +0 -120
package/build/index.d.ts CHANGED
@@ -7,4 +7,4 @@ export * from './types.js';
7
7
  export { APIErrorContext, APIRequestType, CartoAPIError, QueryOptions, buildPublicMapUrl, // Internal, but required for fetchMap().
8
8
  buildStatsUrl, // Internal, but required for fetchMap().
9
9
  query, requestWithParameters, } from './api/index.js';
10
- export { GeojsonResult, JsonResult, QueryResult, QuerySourceOptions, SOURCE_DEFAULTS, SourceOptions, TableSourceOptions, TilejsonResult, TilesetSourceOptions, BoundaryQuerySourceOptions, BoundaryTableSourceOptions, H3TilesetSourceOptions, QuadbinTilesetSourceOptions, RasterSourceOptions, VectorTilesetSourceOptions, boundaryQuerySource, boundaryTableSource, h3TilesetSource, quadbinTilesetSource, rasterSource, vectorTilesetSource, } from './sources/index.js';
10
+ export { BoundaryQuerySourceOptions, BoundaryTableSourceOptions, GeojsonResult, H3QuerySourceOptions, H3TableSourceOptions, H3TilesetSourceOptions, JsonResult, QuadbinQuerySourceOptions, QuadbinTableSourceOptions, QuadbinTilesetSourceOptions, QueryResult, QuerySourceOptions, RasterSourceOptions, SOURCE_DEFAULTS, SourceOptions, TableSourceOptions, TilejsonResult, TilesetSourceOptions, VectorQuerySourceOptions, VectorTableSourceOptions, VectorTilesetSourceOptions, boundaryQuerySource, boundaryTableSource, h3QuerySource, h3TableSource, h3TilesetSource, quadbinQuerySource, quadbinTableSource, quadbinTilesetSource, rasterSource, vectorQuerySource, vectorTableSource, vectorTilesetSource, } from './sources/index.js';
@@ -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: $TODO;
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 {};
@@ -1,3 +1,4 @@
1
+ import { WidgetQuerySourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, QuerySourceOptions, SourceOptions, TilejsonResult } from './types';
2
3
  export type H3QuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions & FilterOptions;
3
- export declare const h3QuerySource: (options: H3QuerySourceOptions) => Promise<TilejsonResult>;
4
+ export declare const h3QuerySource: (options: H3QuerySourceOptions) => Promise<TilejsonResult & WidgetQuerySourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetTableSourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
2
3
  export type H3TableSourceOptions = SourceOptions & TableSourceOptions & AggregationOptions & FilterOptions;
3
- export declare const h3TableSource: (options: H3TableSourceOptions) => Promise<TilejsonResult>;
4
+ export declare const h3TableSource: (options: H3TableSourceOptions) => Promise<TilejsonResult & WidgetTableSourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetQuerySourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, QuerySourceOptions, SourceOptions, TilejsonResult } from './types';
2
3
  export type QuadbinQuerySourceOptions = SourceOptions & QuerySourceOptions & AggregationOptions & FilterOptions;
3
- export declare const quadbinQuerySource: (options: QuadbinQuerySourceOptions) => Promise<TilejsonResult>;
4
+ export declare const quadbinQuerySource: (options: QuadbinQuerySourceOptions) => Promise<TilejsonResult & WidgetQuerySourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetTableSourceResult } from '../widget-sources';
1
2
  import type { AggregationOptions, FilterOptions, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
2
3
  export type QuadbinTableSourceOptions = SourceOptions & TableSourceOptions & AggregationOptions & FilterOptions;
3
- export declare const quadbinTableSource: (options: QuadbinTableSourceOptions) => Promise<TilejsonResult>;
4
+ export declare const quadbinTableSource: (options: QuadbinTableSourceOptions) => Promise<TilejsonResult & WidgetTableSourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetQuerySourceResult } from '../widget-sources/index.js';
1
2
  import type { FilterOptions, SourceOptions, QuerySourceOptions, TilejsonResult, ColumnsOption } from './types';
2
3
  export type VectorQuerySourceOptions = SourceOptions & QuerySourceOptions & FilterOptions & ColumnsOption;
3
- export declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<TilejsonResult>;
4
+ export declare const vectorQuerySource: (options: VectorQuerySourceOptions) => Promise<TilejsonResult & WidgetQuerySourceResult>;
@@ -1,3 +1,4 @@
1
+ import { WidgetTableSourceResult } from '../widget-sources/index.js';
1
2
  import type { FilterOptions, ColumnsOption, SourceOptions, TableSourceOptions, TilejsonResult } from './types';
2
3
  export type VectorTableSourceOptions = SourceOptions & TableSourceOptions & FilterOptions & ColumnsOption;
3
- export declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<TilejsonResult>;
4
+ export declare const vectorTableSource: (options: VectorTableSourceOptions) => Promise<TilejsonResult & WidgetTableSourceResult>;
@@ -1,5 +1,4 @@
1
1
  export * from './widget-base-source.js';
2
2
  export * from './widget-query-source.js';
3
3
  export * from './widget-table-source.js';
4
- export * from './wrappers.js';
5
4
  export * from './types.js';
@@ -2,6 +2,9 @@ import { H3QuerySourceOptions, QuadbinQuerySourceOptions, VectorQuerySourceOptio
2
2
  import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
3
  import { ModelSource } from '../models/model.js';
4
4
  type LayerQuerySourceOptions = Omit<VectorQuerySourceOptions, 'filters'> | Omit<H3QuerySourceOptions, 'filters'> | Omit<QuadbinQuerySourceOptions, 'filters'>;
5
+ export type WidgetQuerySourceResult = {
6
+ widgetSource: WidgetQuerySource;
7
+ };
5
8
  /**
6
9
  * Source for Widget API requests on a data source defined by a SQL query.
7
10
  *
@@ -2,6 +2,9 @@ import { H3TableSourceOptions, QuadbinTableSourceOptions, VectorTableSourceOptio
2
2
  import { WidgetBaseSource, WidgetBaseSourceProps } from './widget-base-source.js';
3
3
  import { ModelSource } from '../models/model.js';
4
4
  type LayerTableSourceOptions = Omit<VectorTableSourceOptions, 'filters'> | Omit<H3TableSourceOptions, 'filters'> | Omit<QuadbinTableSourceOptions, 'filters'>;
5
+ export type WidgetTableSourceResult = {
6
+ widgetSource: WidgetTableSource;
7
+ };
5
8
  /**
6
9
  * Source for Widget API requests on a data source defined as a table.
7
10
  *
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.1",
7
+ "version": "0.4.0-alpha.4",
8
8
  "license": "MIT",
9
9
  "publishConfig": {
10
10
  "access": "public",
@@ -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 {DEFAULT_CLIENT, DEFAULT_MAX_LENGTH_URL} from '../constants';
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
- clientId: DEFAULT_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 = 'carto-api-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,6 +1,5 @@
1
- /******************************************************************************
2
- * VERSIONS
3
- */
1
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
2
+ export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
4
3
 
5
4
  /**
6
5
  * Current version of @carto/api-client.
@@ -11,6 +10,18 @@ export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
11
10
  /** @internal */
12
11
  export const V3_MINOR_VERSION = '3.4';
13
12
 
13
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
14
+ export const DEFAULT_GEO_COLUMN = 'geom';
15
+
16
+ /**
17
+ * Fastly default limit is 8192; leave some padding.
18
+ * @internalRemarks Source: @deck.gl/carto
19
+ */
20
+ export const DEFAULT_MAX_LENGTH_URL = 7000;
21
+
22
+ /** @internalRemarks Source: @deck.gl/carto */
23
+ export const DEFAULT_TILE_RESOLUTION = 0.5;
24
+
14
25
  /**
15
26
  * @internalRemarks Source: @deck.gl/carto
16
27
  * @internal
package/src/constants.ts CHANGED
@@ -28,28 +28,3 @@ export enum ApiVersion {
28
28
  V2 = 'v2',
29
29
  V3 = 'v3',
30
30
  }
31
-
32
- /******************************************************************************
33
- * DEFAULTS
34
- */
35
-
36
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
37
- 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/index.ts CHANGED
@@ -17,27 +17,37 @@ export {
17
17
  } from './api/index.js';
18
18
 
19
19
  export {
20
+ BoundaryQuerySourceOptions,
21
+ BoundaryTableSourceOptions,
20
22
  GeojsonResult,
23
+ H3QuerySourceOptions,
24
+ H3TableSourceOptions,
25
+ H3TilesetSourceOptions,
21
26
  JsonResult,
27
+ QuadbinQuerySourceOptions,
28
+ QuadbinTableSourceOptions,
29
+ QuadbinTilesetSourceOptions,
22
30
  QueryResult,
23
31
  QuerySourceOptions,
32
+ RasterSourceOptions,
24
33
  SOURCE_DEFAULTS,
25
34
  SourceOptions,
26
35
  TableSourceOptions,
27
36
  TilejsonResult,
28
37
  TilesetSourceOptions,
29
-
30
- // Sources not wrapped in './widget-sources/index.js';
31
- BoundaryQuerySourceOptions,
32
- BoundaryTableSourceOptions,
33
- H3TilesetSourceOptions,
34
- QuadbinTilesetSourceOptions,
35
- RasterSourceOptions,
38
+ VectorQuerySourceOptions,
39
+ VectorTableSourceOptions,
36
40
  VectorTilesetSourceOptions,
37
41
  boundaryQuerySource,
38
42
  boundaryTableSource,
43
+ h3QuerySource,
44
+ h3TableSource,
39
45
  h3TilesetSource,
46
+ quadbinQuerySource,
47
+ quadbinTableSource,
40
48
  quadbinTilesetSource,
41
49
  rasterSource,
50
+ vectorQuerySource,
51
+ vectorTableSource,
42
52
  vectorTilesetSource,
43
53
  } from './sources/index.js';
@@ -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: $TODO;
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 (data.error?.includes('Missing columns')) {
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
 
@@ -1,4 +1,4 @@
1
- import {DEFAULT_GEO_COLUMN} from '../constants.js';
1
+ import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
2
2
  import {
3
3
  Filter,
4
4
  FilterLogicalOperator,
@@ -5,9 +5,8 @@
5
5
  /* eslint-disable camelcase */
6
6
  import {
7
7
  DEFAULT_API_BASE_URL,
8
- DEFAULT_CLIENT,
9
8
  DEFAULT_MAX_LENGTH_URL,
10
- } from '../constants';
9
+ } from '../constants-internal';
11
10
  import {buildSourceUrl} from '../api/endpoints';
12
11
  import {requestWithParameters} from '../api/request-with-parameters';
13
12
  import type {
@@ -20,10 +19,11 @@ import type {
20
19
  } from './types';
21
20
  import {MapType} from '../types';
22
21
  import {APIErrorContext} from '../api';
22
+ import {getClient} from '../client';
23
23
 
24
24
  export const SOURCE_DEFAULTS: SourceOptionalOptions = {
25
25
  apiBaseUrl: DEFAULT_API_BASE_URL,
26
- clientId: DEFAULT_CLIENT,
26
+ clientId: getClient(),
27
27
  format: 'tilejson',
28
28
  headers: {},
29
29
  maxLengthURL: DEFAULT_MAX_LENGTH_URL,
@@ -4,6 +4,7 @@
4
4
 
5
5
  /* eslint-disable camelcase */
6
6
  import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants-internal';
7
+ import {WidgetQuerySource, WidgetQuerySourceResult} from '../widget-sources';
7
8
  import {baseSource} from './base-source';
8
9
  import type {
9
10
  AggregationOptions,
@@ -30,7 +31,7 @@ type UrlParameters = {
30
31
 
31
32
  export const h3QuerySource = async function (
32
33
  options: H3QuerySourceOptions
33
- ): Promise<TilejsonResult> {
34
+ ): Promise<TilejsonResult & WidgetQuerySourceResult> {
34
35
  const {
35
36
  aggregationExp,
36
37
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
@@ -55,9 +56,10 @@ export const h3QuerySource = async function (
55
56
  if (filters) {
56
57
  urlParameters.filters = filters;
57
58
  }
58
- return baseSource<UrlParameters>(
59
- 'query',
60
- options,
61
- urlParameters
62
- ) as Promise<TilejsonResult>;
59
+ return baseSource<UrlParameters>('query', options, urlParameters).then(
60
+ (result) => ({
61
+ ...(result as TilejsonResult),
62
+ widgetSource: new WidgetQuerySource(options),
63
+ })
64
+ );
63
65
  };
@@ -4,6 +4,7 @@
4
4
 
5
5
  /* eslint-disable camelcase */
6
6
  import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants-internal';
7
+ import {WidgetTableSource, WidgetTableSourceResult} from '../widget-sources';
7
8
  import {baseSource} from './base-source';
8
9
  import type {
9
10
  AggregationOptions,
@@ -30,7 +31,7 @@ type UrlParameters = {
30
31
 
31
32
  export const h3TableSource = async function (
32
33
  options: H3TableSourceOptions
33
- ): Promise<TilejsonResult> {
34
+ ): Promise<TilejsonResult & WidgetTableSourceResult> {
34
35
  const {
35
36
  aggregationExp,
36
37
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_H3,
@@ -51,9 +52,10 @@ export const h3TableSource = async function (
51
52
  if (filters) {
52
53
  urlParameters.filters = filters;
53
54
  }
54
- return baseSource<UrlParameters>(
55
- 'table',
56
- options,
57
- urlParameters
58
- ) as Promise<TilejsonResult>;
55
+ return baseSource<UrlParameters>('table', options, urlParameters).then(
56
+ (result) => ({
57
+ ...(result as TilejsonResult),
58
+ widgetSource: new WidgetTableSource(options),
59
+ })
60
+ );
59
61
  };
@@ -4,6 +4,7 @@
4
4
 
5
5
  /* eslint-disable camelcase */
6
6
  import {DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN} from '../constants-internal';
7
+ import {WidgetQuerySource, WidgetQuerySourceResult} from '../widget-sources';
7
8
  import {baseSource} from './base-source';
8
9
  import type {
9
10
  AggregationOptions,
@@ -31,7 +32,7 @@ type UrlParameters = {
31
32
 
32
33
  export const quadbinQuerySource = async function (
33
34
  options: QuadbinQuerySourceOptions
34
- ): Promise<TilejsonResult> {
35
+ ): Promise<TilejsonResult & WidgetQuerySourceResult> {
35
36
  const {
36
37
  aggregationExp,
37
38
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
@@ -56,9 +57,10 @@ export const quadbinQuerySource = async function (
56
57
  if (filters) {
57
58
  urlParameters.filters = filters;
58
59
  }
59
- return baseSource<UrlParameters>(
60
- 'query',
61
- options,
62
- urlParameters
63
- ) as Promise<TilejsonResult>;
60
+ return baseSource<UrlParameters>('query', options, urlParameters).then(
61
+ (result) => ({
62
+ ...(result as TilejsonResult),
63
+ widgetSource: new WidgetQuerySource(options),
64
+ })
65
+ );
64
66
  };
@@ -4,6 +4,7 @@
4
4
 
5
5
  /* eslint-disable camelcase */
6
6
  import {DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN} from '../constants-internal';
7
+ import {WidgetTableSource, WidgetTableSourceResult} from '../widget-sources';
7
8
  import {baseSource} from './base-source';
8
9
  import type {
9
10
  AggregationOptions,
@@ -30,7 +31,7 @@ type UrlParameters = {
30
31
 
31
32
  export const quadbinTableSource = async function (
32
33
  options: QuadbinTableSourceOptions
33
- ): Promise<TilejsonResult> {
34
+ ): Promise<TilejsonResult & WidgetTableSourceResult> {
34
35
  const {
35
36
  aggregationExp,
36
37
  aggregationResLevel = DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN,
@@ -52,9 +53,10 @@ export const quadbinTableSource = async function (
52
53
  if (filters) {
53
54
  urlParameters.filters = filters;
54
55
  }
55
- return baseSource<UrlParameters>(
56
- 'table',
57
- options,
58
- urlParameters
59
- ) as Promise<TilejsonResult>;
56
+ return baseSource<UrlParameters>('table', options, urlParameters).then(
57
+ (result) => ({
58
+ ...(result as TilejsonResult),
59
+ widgetSource: new WidgetTableSource(options),
60
+ })
61
+ );
60
62
  };
@@ -3,7 +3,11 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {DEFAULT_TILE_RESOLUTION} from '../constants.js';
6
+ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
7
+ import {
8
+ WidgetQuerySource,
9
+ WidgetQuerySourceResult,
10
+ } from '../widget-sources/index.js';
7
11
  import {baseSource} from './base-source';
8
12
  import type {
9
13
  FilterOptions,
@@ -31,7 +35,7 @@ type UrlParameters = {
31
35
 
32
36
  export const vectorQuerySource = async function (
33
37
  options: VectorQuerySourceOptions
34
- ): Promise<TilejsonResult> {
38
+ ): Promise<TilejsonResult & WidgetQuerySourceResult> {
35
39
  const {
36
40
  columns,
37
41
  filters,
@@ -57,9 +61,10 @@ export const vectorQuerySource = async function (
57
61
  if (queryParameters) {
58
62
  urlParameters.queryParameters = queryParameters;
59
63
  }
60
- return baseSource<UrlParameters>(
61
- 'query',
62
- options,
63
- urlParameters
64
- ) as Promise<TilejsonResult>;
64
+ return baseSource<UrlParameters>('query', options, urlParameters).then(
65
+ (result) => ({
66
+ ...(result as TilejsonResult),
67
+ widgetSource: new WidgetQuerySource(options),
68
+ })
69
+ );
65
70
  };
@@ -3,7 +3,11 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {DEFAULT_TILE_RESOLUTION} from '../constants.js';
6
+ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
7
+ import {
8
+ WidgetTableSource,
9
+ WidgetTableSourceResult,
10
+ } from '../widget-sources/index.js';
7
11
  import {baseSource} from './base-source';
8
12
  import type {
9
13
  FilterOptions,
@@ -29,7 +33,7 @@ type UrlParameters = {
29
33
 
30
34
  export const vectorTableSource = async function (
31
35
  options: VectorTableSourceOptions
32
- ): Promise<TilejsonResult> {
36
+ ): Promise<TilejsonResult & WidgetTableSourceResult> {
33
37
  const {
34
38
  columns,
35
39
  filters,
@@ -51,9 +55,10 @@ export const vectorTableSource = async function (
51
55
  if (filters) {
52
56
  urlParameters.filters = filters;
53
57
  }
54
- return baseSource<UrlParameters>(
55
- 'table',
56
- options,
57
- urlParameters
58
- ) as Promise<TilejsonResult>;
58
+ return baseSource<UrlParameters>('table', options, urlParameters).then(
59
+ (result) => ({
60
+ ...(result as TilejsonResult),
61
+ widgetSource: new WidgetTableSource(options),
62
+ })
63
+ );
59
64
  };
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] = filter as $TODO;
28
+ (applicableFilters[column][type] as typeof filter) = filter;
30
29
  }
31
30
  }
32
31
  }
@@ -1,5 +1,4 @@
1
1
  export * from './widget-base-source.js';
2
2
  export * from './widget-query-source.js';
3
3
  export * from './widget-table-source.js';
4
- export * from './wrappers.js';
5
4
  export * from './types.js';
@@ -20,11 +20,11 @@ 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 {ApiVersion} from '../constants.js';
23
24
  import {
24
- ApiVersion,
25
25
  DEFAULT_API_BASE_URL,
26
26
  DEFAULT_GEO_COLUMN,
27
- } from '../constants.js';
27
+ } from '../constants-internal.js';
28
28
 
29
29
  export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
30
30
  apiVersion?: ApiVersion;
@@ -11,6 +11,8 @@ type LayerQuerySourceOptions =
11
11
  | Omit<H3QuerySourceOptions, 'filters'>
12
12
  | Omit<QuadbinQuerySourceOptions, 'filters'>;
13
13
 
14
+ export type WidgetQuerySourceResult = {widgetSource: WidgetQuerySource};
15
+
14
16
  /**
15
17
  * Source for Widget API requests on a data source defined by a SQL query.
16
18
  *
@@ -11,6 +11,8 @@ type LayerTableSourceOptions =
11
11
  | Omit<H3TableSourceOptions, 'filters'>
12
12
  | Omit<QuadbinTableSourceOptions, 'filters'>;
13
13
 
14
+ export type WidgetTableSourceResult = {widgetSource: WidgetTableSource};
15
+
14
16
  /**
15
17
  * Source for Widget API requests on a data source defined as a table.
16
18
  *