@carto/api-client 0.5.2-alpha.0 → 0.5.2-alpha.1

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 (65) hide show
  1. package/build/api-client.cjs +120 -12
  2. package/build/api-client.cjs.map +1 -1
  3. package/build/api-client.d.cts +20 -1
  4. package/build/api-client.d.ts +20 -1
  5. package/build/api-client.js +114 -12
  6. package/build/api-client.js.map +1 -1
  7. package/build/worker.js +28 -19
  8. package/build/worker.js.map +1 -1
  9. package/package.json +3 -2
  10. package/src/api/carto-api-error.ts +1 -1
  11. package/src/api/endpoints.ts +1 -1
  12. package/src/api/index.ts +2 -2
  13. package/src/api/query.ts +1 -1
  14. package/src/api/request-with-parameters.ts +2 -2
  15. package/src/deck/get-data-filter-extension-props.ts +3 -3
  16. package/src/fetch-map/basemap-styles.ts +2 -2
  17. package/src/fetch-map/basemap.ts +2 -2
  18. package/src/fetch-map/fetch-map.ts +3 -3
  19. package/src/fetch-map/layer-map.ts +81 -5
  20. package/src/fetch-map/parse-map.ts +71 -7
  21. package/src/fetch-map/source.ts +10 -10
  22. package/src/fetch-map/types.ts +7 -3
  23. package/src/filters/Filter.ts +4 -4
  24. package/src/filters/FilterTypes.ts +1 -1
  25. package/src/filters/geosjonFeatures.ts +3 -3
  26. package/src/filters/tileFeatures.ts +8 -3
  27. package/src/filters/tileFeaturesGeometries.ts +5 -5
  28. package/src/filters/tileFeaturesRaster.ts +3 -3
  29. package/src/filters/tileFeaturesSpatialIndex.ts +4 -4
  30. package/src/filters.ts +1 -1
  31. package/src/geo.ts +1 -1
  32. package/src/index.ts +3 -3
  33. package/src/models/model.ts +6 -3
  34. package/src/operations/aggregation.ts +14 -4
  35. package/src/operations/applySorting.ts +2 -2
  36. package/src/operations/groupBy.ts +2 -2
  37. package/src/operations/groupByDate.ts +2 -2
  38. package/src/operations/histogram.ts +2 -2
  39. package/src/operations/scatterPlot.ts +2 -2
  40. package/src/sources/base-source.ts +2 -2
  41. package/src/sources/boundary-query-source.ts +1 -1
  42. package/src/sources/h3-query-source.ts +1 -1
  43. package/src/sources/h3-table-source.ts +1 -1
  44. package/src/sources/h3-tileset-source.ts +1 -1
  45. package/src/sources/quadbin-query-source.ts +1 -1
  46. package/src/sources/quadbin-table-source.ts +1 -1
  47. package/src/sources/quadbin-tileset-source.ts +1 -1
  48. package/src/sources/raster-source.ts +1 -1
  49. package/src/sources/types.ts +2 -2
  50. package/src/sources/vector-query-source.ts +1 -1
  51. package/src/sources/vector-table-source.ts +1 -1
  52. package/src/sources/vector-tileset-source.ts +1 -1
  53. package/src/utils/getTileFormat.ts +1 -1
  54. package/src/utils/makeIntervalComplete.ts +1 -1
  55. package/src/utils/transformTileCoordsToWGS84.ts +1 -1
  56. package/src/utils/transformToTileCoords.ts +1 -1
  57. package/src/utils.ts +35 -0
  58. package/src/widget-sources/types.ts +5 -2
  59. package/src/widget-sources/widget-query-source.ts +4 -4
  60. package/src/widget-sources/widget-raster-source.ts +2 -2
  61. package/src/widget-sources/widget-remote-source.ts +4 -4
  62. package/src/widget-sources/widget-source.ts +3 -3
  63. package/src/widget-sources/widget-table-source.ts +4 -4
  64. package/src/widget-sources/widget-tileset-source-impl.ts +6 -5
  65. package/src/widget-sources/widget-tileset-source.ts +7 -7
@@ -1,7 +1,7 @@
1
- import {AggregationType, GroupDateType} from '../types.js';
1
+ import type {AggregationType, GroupDateType} from '../types.js';
2
2
  import {getUTCMonday} from '../utils/dateUtils.js';
3
3
  import {aggregate, aggregationFunctions} from './aggregation.js';
4
- import {GroupByFeature} from './groupBy.js';
4
+ import type {GroupByFeature} from './groupBy.js';
5
5
 
6
6
  const GROUP_KEY_FN_MAPPING: Record<GroupDateType, (date: Date) => number> = {
7
7
  year: (date: Date) => Date.UTC(date.getUTCFullYear()),
@@ -1,6 +1,6 @@
1
1
  import {aggregate, aggregationFunctions} from './aggregation.js';
2
- import {AggregationType} from '../types.js';
3
- import {FeatureData} from '../types-internal.js';
2
+ import type {AggregationType} from '../types.js';
3
+ import type {FeatureData} from '../types-internal.js';
4
4
 
5
5
  /**
6
6
  * Histogram computation.
@@ -1,6 +1,6 @@
1
1
  import {aggregate} from './aggregation.js';
2
- import {FeatureData} from '../types-internal.js';
3
- import {AggregationType} from '../types.js';
2
+ import type {FeatureData} from '../types-internal.js';
3
+ import type {AggregationType} from '../types.js';
4
4
 
5
5
  export type ScatterPlotFeature = [number, number][];
6
6
 
@@ -12,8 +12,8 @@ import type {
12
12
  TilejsonMapInstantiation,
13
13
  TilejsonResult,
14
14
  } from './types.js';
15
- import {MapType} from '../types.js';
16
- import {APIErrorContext} from '../api/index.js';
15
+ import type {MapType} from '../types.js';
16
+ import type {APIErrorContext} from '../api/index.js';
17
17
  import {getClient} from '../client.js';
18
18
 
19
19
  export const SOURCE_DEFAULTS: Omit<SourceOptionalOptions, 'clientId'> = {
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {QueryParameters} from '../types.js';
5
+ import type {QueryParameters} from '../types.js';
6
6
  import {baseSource} from './base-source.js';
7
7
  import type {FilterOptions, SourceOptions, TilejsonResult} from './types.js';
8
8
 
@@ -5,7 +5,7 @@
5
5
  import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants-internal.js';
6
6
  import {
7
7
  WidgetQuerySource,
8
- WidgetQuerySourceResult,
8
+ type WidgetQuerySourceResult,
9
9
  } from '../widget-sources/index.js';
10
10
  import {baseSource} from './base-source.js';
11
11
  import type {
@@ -5,7 +5,7 @@
5
5
  import {DEFAULT_AGGREGATION_RES_LEVEL_H3} from '../constants-internal.js';
6
6
  import {
7
7
  WidgetTableSource,
8
- WidgetTableSourceResult,
8
+ type WidgetTableSourceResult,
9
9
  } from '../widget-sources/index.js';
10
10
  import {baseSource} from './base-source.js';
11
11
  import type {
@@ -6,7 +6,7 @@ import {baseSource} from './base-source.js';
6
6
  import {getTileFormat} from '../utils/getTileFormat.js';
7
7
  import {
8
8
  WidgetTilesetSource,
9
- WidgetTilesetSourceResult,
9
+ type WidgetTilesetSourceResult,
10
10
  } from '../widget-sources/index.js';
11
11
  import type {
12
12
  SourceOptions,
@@ -5,7 +5,7 @@
5
5
  import {DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN} from '../constants-internal.js';
6
6
  import {
7
7
  WidgetQuerySource,
8
- WidgetQuerySourceResult,
8
+ type WidgetQuerySourceResult,
9
9
  } from '../widget-sources/index.js';
10
10
  import {baseSource} from './base-source.js';
11
11
  import type {
@@ -5,7 +5,7 @@
5
5
  import {DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN} from '../constants-internal.js';
6
6
  import {
7
7
  WidgetTableSource,
8
- WidgetTableSourceResult,
8
+ type WidgetTableSourceResult,
9
9
  } from '../widget-sources/index.js';
10
10
  import {baseSource} from './base-source.js';
11
11
  import type {
@@ -6,7 +6,7 @@ import {baseSource} from './base-source.js';
6
6
  import {getTileFormat} from '../utils/getTileFormat.js';
7
7
  import {
8
8
  WidgetTilesetSource,
9
- WidgetTilesetSourceResult,
9
+ type WidgetTilesetSourceResult,
10
10
  } from '../widget-sources/index.js';
11
11
  import type {
12
12
  SourceOptions,
@@ -6,7 +6,7 @@ import {baseSource} from './base-source.js';
6
6
  import {getTileFormat} from '../utils/getTileFormat.js';
7
7
  import {
8
8
  WidgetRasterSource,
9
- WidgetRasterSourceResult,
9
+ type WidgetRasterSourceResult,
10
10
  } from '../widget-sources/index.js';
11
11
 
12
12
  import type {
@@ -2,8 +2,8 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {Filters, QueryParameters} from '../types.js';
6
- import {SchemaField} from '../types-internal.js';
5
+ import type {SchemaField} from '../types-internal.js';
6
+ import type {Filters, QueryParameters} from '../types.js';
7
7
 
8
8
  export type SourceRequiredOptions = {
9
9
  /** Carto platform access token. */
@@ -8,7 +8,7 @@ import {
8
8
  } from '../constants-internal.js';
9
9
  import {
10
10
  WidgetQuerySource,
11
- WidgetQuerySourceResult,
11
+ type WidgetQuerySourceResult,
12
12
  } from '../widget-sources/index.js';
13
13
  import {baseSource} from './base-source.js';
14
14
  import type {
@@ -8,7 +8,7 @@ import {
8
8
  } from '../constants-internal.js';
9
9
  import {
10
10
  WidgetTableSource,
11
- WidgetTableSourceResult,
11
+ type WidgetTableSourceResult,
12
12
  } from '../widget-sources/index.js';
13
13
  import {baseSource} from './base-source.js';
14
14
  import type {
@@ -7,7 +7,7 @@ import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
7
7
  import {getTileFormat} from '../utils/getTileFormat.js';
8
8
  import {
9
9
  WidgetTilesetSource,
10
- WidgetTilesetSourceResult,
10
+ type WidgetTilesetSourceResult,
11
11
  } from '../widget-sources/index.js';
12
12
  import type {
13
13
  SourceOptions,
@@ -1,5 +1,5 @@
1
1
  import {TileFormat} from '../constants.js';
2
- import {Tilejson} from '../sources/types.js';
2
+ import type {Tilejson} from '../sources/types.js';
3
3
 
4
4
  export function getTileFormat(tilejson: Tilejson): TileFormat {
5
5
  const tileParams = new URL(tilejson.tiles[0]).searchParams;
@@ -1,4 +1,4 @@
1
- import {FilterInterval, FilterIntervalComplete} from '../types.js';
1
+ import type {FilterInterval, FilterIntervalComplete} from '../types.js';
2
2
 
3
3
  export function makeIntervalComplete(
4
4
  intervals: FilterInterval[]
@@ -1,6 +1,6 @@
1
1
  import {lerp} from '@math.gl/core';
2
2
  import {lngLatToWorld, worldToLngLat} from '@math.gl/web-mercator';
3
- import {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
3
+ import type {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
4
4
 
5
5
  type TransformFn = (coordinates: any[], bbox: Position[]) => any[];
6
6
 
@@ -1,5 +1,5 @@
1
1
  import {lngLatToWorld} from '@math.gl/web-mercator';
2
- import {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
2
+ import type {BBox, GeoJsonGeometryTypes, Geometry, Position} from 'geojson';
3
3
 
4
4
  type TransformFn = (coordinates: any[], bbox: Position[]) => any[];
5
5
 
package/src/utils.ts CHANGED
@@ -1,3 +1,38 @@
1
+ import type {Filter} from './types.js';
2
+ import {FilterType} from './constants.js';
3
+
4
+ const FILTER_TYPES = new Set(Object.values(FilterType));
5
+ const isFilterType = (type: string): type is FilterType =>
6
+ FILTER_TYPES.has(type as FilterType);
7
+
8
+ /**
9
+ * @privateRemarks Source: @carto/react-widgets
10
+ * @internal
11
+ */
12
+ export function getApplicableFilters(
13
+ owner?: string,
14
+ filters?: Record<string, Filter>
15
+ ): Record<string, Filter> {
16
+ if (!filters) return {};
17
+
18
+ const applicableFilters: Record<string, Filter> = {};
19
+
20
+ for (const column in filters) {
21
+ for (const type in filters[column]) {
22
+ if (!isFilterType(type)) continue;
23
+
24
+ const filter = filters[column][type];
25
+ const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
26
+ if (filter && isApplicable) {
27
+ applicableFilters[column] ||= {};
28
+ (applicableFilters[column][type] as typeof filter) = filter;
29
+ }
30
+ }
31
+ }
32
+
33
+ return applicableFilters;
34
+ }
35
+
1
36
  type Row<T> = Record<string, T> | Record<string, T>[] | T[] | T;
2
37
 
3
38
  /**
@@ -1,5 +1,8 @@
1
- import {SpatialFilterPolyfillMode, TileResolution} from '../sources/types.js';
2
- import {
1
+ import type {
2
+ SpatialFilterPolyfillMode,
3
+ TileResolution,
4
+ } from '../sources/types.js';
5
+ import type {
3
6
  Filters,
4
7
  GroupDateType,
5
8
  SortColumnType,
@@ -1,14 +1,14 @@
1
- import {
1
+ import type {
2
2
  H3QuerySourceOptions,
3
3
  QuadbinQuerySourceOptions,
4
4
  VectorQuerySourceOptions,
5
5
  } from '../sources/index.js';
6
6
  import {
7
7
  WidgetRemoteSource,
8
- WidgetRemoteSourceProps,
8
+ type WidgetRemoteSourceProps,
9
9
  } from './widget-remote-source.js';
10
- import {ModelSource} from '../models/model.js';
11
- import {Filters} from '../types.js';
10
+ import type {ModelSource} from '../models/model.js';
11
+ import type {Filters} from '../types.js';
12
12
 
13
13
  type LayerQuerySourceOptions =
14
14
  | Omit<VectorQuerySourceOptions, 'filters'>
@@ -1,7 +1,7 @@
1
- import {RasterMetadata} from '../sources/index.js';
1
+ import type {RasterMetadata} from '../sources/index.js';
2
2
  import {
3
3
  WidgetTilesetSource,
4
- WidgetTilesetSourceProps,
4
+ type WidgetTilesetSourceProps,
5
5
  } from './widget-tileset-source.js';
6
6
 
7
7
  export type WidgetRasterSourceProps = WidgetTilesetSourceProps & {
@@ -1,5 +1,5 @@
1
- import {executeModel, ModelSource} from '../models/index.js';
2
- import {
1
+ import {executeModel, type ModelSource} from '../models/index.js';
2
+ import type {
3
3
  CategoryRequestOptions,
4
4
  CategoryResponse,
5
5
  FeaturesRequestOptions,
@@ -19,8 +19,8 @@ import {
19
19
  } from './types.js';
20
20
  import {normalizeObjectKeys} from '../utils.js';
21
21
  import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
22
- import {WidgetSource, WidgetSourceProps} from './widget-source.js';
23
- import {Filters} from '../types.js';
22
+ import {WidgetSource, type WidgetSourceProps} from './widget-source.js';
23
+ import type {Filters} from '../types.js';
24
24
  import {ApiVersion} from '../constants.js';
25
25
  import {getApplicableFilters} from '../filters.js';
26
26
 
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  CategoryRequestOptions,
3
3
  CategoryResponse,
4
4
  FeaturesRequestOptions,
@@ -16,9 +16,9 @@ import {
16
16
  TimeSeriesRequestOptions,
17
17
  TimeSeriesResponse,
18
18
  } from './types.js';
19
- import {FilterLogicalOperator, Filter} from '../types.js';
19
+ import type {FilterLogicalOperator, Filter} from '../types.js';
20
20
  import {getClient} from '../client.js';
21
- import {SourceOptions} from '../sources/index.js';
21
+ import type {SourceOptions} from '../sources/index.js';
22
22
  import {ApiVersion, DEFAULT_API_BASE_URL} from '../constants.js';
23
23
 
24
24
  export interface WidgetSourceProps extends Omit<SourceOptions, 'filters'> {
@@ -1,14 +1,14 @@
1
- import {
1
+ import type {
2
2
  H3TableSourceOptions,
3
3
  QuadbinTableSourceOptions,
4
4
  VectorTableSourceOptions,
5
5
  } from '../sources/index.js';
6
6
  import {
7
7
  WidgetRemoteSource,
8
- WidgetRemoteSourceProps,
8
+ type WidgetRemoteSourceProps,
9
9
  } from './widget-remote-source.js';
10
- import {ModelSource} from '../models/model.js';
11
- import {Filters} from '../types.js';
10
+ import type {ModelSource} from '../models/model.js';
11
+ import type {Filters} from '../types.js';
12
12
 
13
13
  type LayerTableSourceOptions =
14
14
  | Omit<VectorTableSourceOptions, 'filters'>
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/require-await */
2
- import {
2
+ import type {
3
3
  CategoryRequestOptions,
4
4
  CategoryResponse,
5
5
  FeaturesResponse,
@@ -17,9 +17,10 @@ import {
17
17
  TimeSeriesResponse,
18
18
  } from './types.js';
19
19
  import {InvalidColumnError, assert, assignOptional} from '../utils.js';
20
- import {Filter, SpatialFilter, Tile} from '../types.js';
20
+ import type {Filter, SpatialFilter, Tile} from '../types.js';
21
+
21
22
  import {
22
- TileFeatureExtractOptions,
23
+ type TileFeatureExtractOptions,
23
24
  applyFilters,
24
25
  geojsonFeatures,
25
26
  tileFeatures,
@@ -32,8 +33,8 @@ import {
32
33
  histogram,
33
34
  scatterPlot,
34
35
  } from '../operations/index.js';
35
- import {FeatureData} from '../types-internal.js';
36
- import {FeatureCollection} from 'geojson';
36
+ import type {FeatureData} from '../types-internal.js';
37
+ import type {FeatureCollection} from 'geojson';
37
38
  import {WidgetSource} from './widget-source.js';
38
39
  import {booleanEqual} from '@turf/boolean-equal';
39
40
  import type {WidgetTilesetSourceProps} from './widget-tileset-source.js';
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  CategoryRequestOptions,
3
3
  CategoryResponse,
4
4
  FeaturesResponse,
@@ -15,13 +15,13 @@ import {
15
15
  TimeSeriesRequestOptions,
16
16
  TimeSeriesResponse,
17
17
  } from './types.js';
18
- import {SpatialFilter, Tile} from '../types.js';
19
- import {TileFeatureExtractOptions} from '../filters/index.js';
20
- import {FeatureCollection} from 'geojson';
21
- import {WidgetSource, WidgetSourceProps} from './widget-source.js';
18
+ import type {SpatialFilter, Tile} from '../types.js';
19
+ import type {TileFeatureExtractOptions} from '../filters/index.js';
20
+ import type {FeatureCollection} from 'geojson';
21
+ import {WidgetSource, type WidgetSourceProps} from './widget-source.js';
22
22
  import {Method} from '../workers/constants.js';
23
- import {WorkerRequest, WorkerResponse} from '../workers/types.js';
24
- import {SpatialDataType, TilesetSourceOptions} from '../sources/types.js';
23
+ import type {WorkerRequest, WorkerResponse} from '../workers/types.js';
24
+ import type {SpatialDataType, TilesetSourceOptions} from '../sources/types.js';
25
25
  import {TileFormat} from '../constants.js';
26
26
  import {WidgetTilesetSourceImpl} from './widget-tileset-source-impl.js';
27
27