@carto/ps-react-maps 4.4.0 → 4.5.0

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.
@@ -43,7 +43,7 @@ export type { MapProviderProps, MapStore, ViewportRect, } from './providers/map/
43
43
  export { transitionFlyConfig } from './providers/map/const';
44
44
  export { MapProvider, useMapStore } from './providers/map/provider';
45
45
  export { createMapStore } from './providers/map/store';
46
- export type { Source, SourceStore, QuerySource, TableSource, TilesetSource, RasterSource, } from './providers/sources/types';
46
+ export type { Source, SourceStore, QuerySource, TableSource, TilesetSource, RasterSource, GeoJSONSource, AllSources, AllExternalSources, } from './providers/sources/types';
47
47
  export { clientID } from './providers/sources/const';
48
48
  export { useSourceStore, useSource, useFilters, useSourceWithFilters, getFilterValues, } from './providers/sources/store';
49
49
  export { MapsProvider } from './provider';
@@ -1,6 +1,8 @@
1
1
  import { ModelProps } from '../types';
2
- export declare function useCommonModel<TRequestOptions, TResponse>({ accessToken, sourceId, widgetProps, additionalFilter, }: Pick<ModelProps<TRequestOptions, TResponse>, 'accessToken' | 'sourceId' | 'additionalFilter' | 'widgetProps'>): {
2
+ export declare function useCommonModel<TRequestOptions, TResponse>({ queryKeyPrefix, accessToken, sourceId, widgetProps, additionalFilter, }: Pick<ModelProps<TRequestOptions, TResponse>, 'accessToken' | 'sourceId' | 'additionalFilter' | 'widgetProps'> & {
3
+ queryKeyPrefix: string[];
4
+ }): {
3
5
  mergedFilters: {} | undefined;
4
- widgetModel: import('@carto/api-client').WidgetSource<import('@carto/api-client').WidgetSourceProps & (import('../..').QuerySource | import('../..').TilesetSource | import('../..').TableSource | import('../../providers/sources/types').RasterQuadbinTilesetSource)> | null;
6
+ widgetModel: import('@carto/api-client').WidgetQuerySource | import('@carto/api-client').WidgetTilesetSource<import('@carto/api-client').WidgetTilesetSourceProps> | import('@carto/api-client').WidgetTableSource | null;
5
7
  queryKey: unknown[];
6
8
  };
@@ -0,0 +1,4 @@
1
+ import { ModelProps } from '../types';
2
+ export declare function useQueryKey<TRequestOptions, TResponse>({ queryKeyPrefix, accessToken, sourceId, }: Pick<ModelProps<TRequestOptions, TResponse>, 'accessToken' | 'sourceId'> & {
3
+ queryKeyPrefix: string[];
4
+ }): unknown[];
@@ -1 +1 @@
1
- export declare function useWidgetModel(accessToken: string, sourceId: string): import('@carto/api-client').WidgetSource<import('@carto/api-client').WidgetSourceProps & (import('../..').QuerySource | import('../..').TilesetSource | import('../..').TableSource | import('../../providers/sources/types').RasterQuadbinTilesetSource)> | null;
1
+ export declare function useWidgetModel(accessToken: string, sourceId: string): import('@carto/api-client').WidgetQuerySource | import('@carto/api-client').WidgetTilesetSource<import('@carto/api-client').WidgetTilesetSourceProps> | import('@carto/api-client').WidgetTableSource | null;
@@ -1,5 +1,5 @@
1
- import { QuerySource, TableSource, TilesetSource, Source, SourceStore } from './types';
2
- import { Filters, FilterType, SpatialDataType } from '@carto/api-client';
1
+ import { Source, SourceStore, AllExternalSources, AllSources } from './types';
2
+ import { Filters, FilterType } from '@carto/api-client';
3
3
  export declare const useSourceStore: import('zustand').UseBoundStore<Omit<import('zustand').StoreApi<SourceStore>, "setState" | "devtools"> & {
4
4
  setState(partial: SourceStore | Partial<SourceStore> | ((state: SourceStore) => SourceStore | Partial<SourceStore>), replace?: false | undefined, action?: (string | {
5
5
  [x: string]: unknown;
@@ -22,7 +22,7 @@ export declare const useSourceStore: import('zustand').UseBoundStore<Omit<import
22
22
  * @param id - the id of the source you want to grab
23
23
  * @returns source object without filters
24
24
  */
25
- export declare function useSource(id: string): Source<QuerySource | TilesetSource | TableSource | import('./types').RasterQuadbinTilesetSource> | undefined;
25
+ export declare function useSource<T extends AllSources = AllExternalSources>(id: string): Source<T>;
26
26
  /**
27
27
  * Shortcut to grabbing the filters from the filters store object
28
28
  * @param id - the id of the source the filters are applied to
@@ -34,29 +34,10 @@ export declare function useFilters(id: string): Filters | undefined;
34
34
  * @param id - the id of the source
35
35
  * @returns source object as used in `@carto/api-client`
36
36
  */
37
- export declare function useSourceWithFilters(id: string): {
37
+ export declare function useSourceWithFilters<T extends AllSources = AllExternalSources>(id: string): (Omit<T, "filters"> & {
38
38
  filters: Filters;
39
- widgets?: import('@carto/api-client').WidgetSource<import('@carto/api-client').WidgetSourceProps & (QuerySource | TilesetSource | TableSource | import('./types').RasterQuadbinTilesetSource)> | null | undefined;
40
- type: "table" | "query" | "query+h3" | "query+quadbin" | "query+boundary" | "tileset" | "tileset+h3" | "tileset+quadbin" | "table+h3" | "table+quadbin" | "table+boundary" | "raster";
41
- data: string;
42
- apiBaseUrl?: string | undefined;
43
- headers?: Record<string, string> | undefined;
44
- cache?: {
45
- value?: number;
46
- } | undefined;
47
- clientId?: string | undefined;
48
- maxLengthURL?: number | undefined;
49
- spatialDataColumn?: string | undefined;
50
- spatialDataType?: SpatialDataType | undefined;
51
- tileResolution?: import('@carto/api-client').TileResolution | undefined;
52
- localCache?: {
53
- cache?: Map<string, Promise<unknown>>;
54
- cacheControl?: ("no-cache" | "no-store")[];
55
- } | undefined;
56
- tags?: Record<string, string> | undefined;
57
- connectionName: string;
58
- apiVersion?: import('@carto/api-client').ApiVersion | undefined;
59
- } | undefined;
39
+ id: string;
40
+ }) | undefined;
60
41
  export declare function getFilterValues(filters: Filters | undefined, { column, type }: {
61
42
  column: string;
62
43
  type: FilterType;
@@ -1,5 +1,14 @@
1
- import { VectorQuerySourceOptions, VectorTableSourceOptions, VectorTilesetSourceOptions, TileFormat, BoundaryQuerySourceOptions, BoundaryTableSourceOptions, H3QuerySourceOptions, QuadbinQuerySourceOptions, H3TilesetSourceOptions, QuadbinTilesetSourceOptions, H3TableSourceOptions, QuadbinTableSourceOptions, RasterSourceOptions, RasterMetadata, WidgetSource, WidgetSourceProps, Filters, AddFilterOptions, RemoveFilterOptions, ApiVersion } from '@carto/api-client';
2
- import { BBox } from 'geojson';
1
+ import { VectorQuerySourceOptions, VectorTableSourceOptions, VectorTilesetSourceOptions, TileFormat, BoundaryQuerySourceOptions, BoundaryTableSourceOptions, H3QuerySourceOptions, QuadbinQuerySourceOptions, H3TilesetSourceOptions, QuadbinTilesetSourceOptions, H3TableSourceOptions, QuadbinTableSourceOptions, RasterSourceOptions, RasterMetadata, Filters, AddFilterOptions, RemoveFilterOptions, ApiVersion, WidgetQuerySource, WidgetTilesetSource, WidgetTableSource, WidgetRasterSource } from '@carto/api-client';
2
+ import { BBox, Feature } from 'geojson';
3
+ import { WidgetGeoJsonSource } from './widgets/widget-geojson-source';
4
+ interface ExternalData {
5
+ data: string;
6
+ apiVersion?: ApiVersion;
7
+ apiBaseUrl?: string;
8
+ }
9
+ interface WithWidgets<T> {
10
+ widgets?: T | null;
11
+ }
3
12
  type _Omit<T, P extends string = ''> = Omit<T, 'accessToken' | P>;
4
13
  type OmitQuery<T, P extends string = ''> = _Omit<T, 'sqlQuery' | P>;
5
14
  type OmitTable<T, P extends string = ''> = _Omit<T, 'tableName' | P>;
@@ -15,7 +24,7 @@ export type QuadbinQuerySource = {
15
24
  export type BoundaryQuerySource = {
16
25
  type: 'query+boundary';
17
26
  } & _Omit<BoundaryQuerySourceOptions, 'propertiesSqlQuery'>;
18
- export type QuerySource = VectorQuerySource | H3QuerySource | QuadbinQuerySource | BoundaryQuerySource;
27
+ export type QuerySource = (VectorQuerySource | H3QuerySource | QuadbinQuerySource | BoundaryQuerySource) & ExternalData & WithWidgets<WidgetQuerySource>;
19
28
  export type VectorTilesetSource = {
20
29
  type: 'tileset';
21
30
  } & OmitTable<VectorTilesetSourceOptions>;
@@ -25,7 +34,7 @@ export type H3TilesetSource = {
25
34
  export type QuadbinTilesetSource = {
26
35
  type: 'tileset+quadbin';
27
36
  } & OmitTable<QuadbinTilesetSourceOptions>;
28
- export type TilesetSource = (VectorTilesetSource | H3TilesetSource | QuadbinTilesetSource) & {
37
+ export type TilesetSource = (VectorTilesetSource | H3TilesetSource | QuadbinTilesetSource) & ExternalData & WithWidgets<WidgetTilesetSource> & {
29
38
  tileFormat: TileFormat;
30
39
  spatialDataBounds: BBox;
31
40
  };
@@ -41,24 +50,27 @@ export type QuadbinTableSource = {
41
50
  export type BoundaryTableSource = {
42
51
  type: 'table+boundary';
43
52
  } & _Omit<BoundaryTableSourceOptions, 'propertiesTableName'>;
44
- export type TableSource = VectorTableSource | H3TableSource | QuadbinTableSource | BoundaryTableSource;
53
+ export type TableSource = (VectorTableSource | H3TableSource | QuadbinTableSource | BoundaryTableSource) & ExternalData & WithWidgets<WidgetTableSource>;
45
54
  export type RasterQuadbinTilesetSource = {
46
55
  type: 'raster';
47
56
  tileFormat: TileFormat;
48
57
  rasterMetadata?: RasterMetadata;
49
58
  spatialDataBounds: BBox;
50
59
  } & OmitTable<RasterSourceOptions>;
51
- export type RasterSource = RasterQuadbinTilesetSource;
52
- export type Source<T extends QuerySource | TilesetSource | TableSource | RasterSource = QuerySource | TilesetSource | TableSource | RasterSource> = Omit<T & {
53
- data: string;
54
- widgets?: WidgetSource<WidgetSourceProps & T> | null;
55
- apiVersion?: ApiVersion;
56
- apiBaseUrl?: string;
57
- }, 'filters'>;
60
+ export type RasterSource = RasterQuadbinTilesetSource & ExternalData & WithWidgets<WidgetRasterSource>;
61
+ export type GeoJSONSource = {
62
+ type: 'geojson';
63
+ data: Feature[];
64
+ } & WithWidgets<WidgetGeoJsonSource>;
65
+ export type AllExternalSources = QuerySource | TilesetSource | TableSource | RasterSource;
66
+ export type AllSources = AllExternalSources | GeoJSONSource;
67
+ export type Source<T extends AllSources = AllSources> = Omit<T, 'filters'> & {
68
+ id: string;
69
+ };
58
70
  export interface SourceStore {
59
71
  sources: Record<string, Source>;
60
72
  filters: Record<string, Filters>;
61
- setSource: <T extends Source>(id: string, source: Partial<T>) => void;
73
+ setSource: <T extends AllSources>(id: string, source: Partial<Source<T>>) => void;
62
74
  removeSource: (id: string) => void;
63
75
  setFilters: (id: string, filters: AddFilterOptions[]) => void;
64
76
  removeFilters: (id: string, column?: RemoveFilterOptions['column'], owner?: RemoveFilterOptions['owner']) => void;
@@ -0,0 +1,13 @@
1
+ export declare const Method: {
2
+ readonly INIT: "init";
3
+ readonly LOAD_GEOJSON: "loadGeoJSON";
4
+ readonly GET_FORMULA: "getFormula";
5
+ readonly GET_HISTOGRAM: "getHistogram";
6
+ readonly GET_CATEGORIES: "getCategories";
7
+ readonly GET_SCATTER: "getScatter";
8
+ readonly GET_TABLE: "getTable";
9
+ readonly GET_TIME_SERIES: "getTimeSeries";
10
+ readonly GET_RANGE: "getRange";
11
+ readonly GET_AGGREGATIONS: "getAggregations";
12
+ readonly GET_EXTENT: "getExtent";
13
+ };
@@ -0,0 +1,5 @@
1
+ import { FeatureData } from './types';
2
+ export declare function geojsonFeatures({ geojson, uniqueIdProperty, }: {
3
+ geojson: FeatureData[];
4
+ uniqueIdProperty?: string;
5
+ }): FeatureData[];
@@ -0,0 +1,17 @@
1
+ import { Feature, GeoJsonProperties, Geometry } from 'geojson';
2
+ import { Method } from './const';
3
+ export interface WorkerRequest {
4
+ requestId?: number;
5
+ method: (typeof Method)[keyof typeof Method];
6
+ params: unknown[];
7
+ }
8
+ export type WorkerResponse = {
9
+ requestId: number;
10
+ ok: true;
11
+ result: unknown;
12
+ } | {
13
+ requestId: number;
14
+ ok: false;
15
+ error: string;
16
+ };
17
+ export type FeatureData = Feature<Geometry, GeoJsonProperties>;
@@ -0,0 +1,33 @@
1
+ import { WidgetSource, AggregationsRequestOptions, AggregationsResponse, CategoryRequestOptions, CategoryResponse, ExtentResponse, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, SpatialFilter, TableRequestOptions, TableResponse, TimeSeriesRequestOptions, TimeSeriesResponse } from '@carto/api-client';
2
+ import { WidgetGeoJsonSourceProps } from './widget-geojson-source';
3
+ import { FeatureData } from './types';
4
+ /**
5
+ * Local (in-memory) implementation of geojson widget calculations. This class
6
+ * may be instantiated by {@link WidgetGeoJsonSource} in a Web Worker when
7
+ * supported, or on the main thread.
8
+ */
9
+ export declare class WidgetGeoJsonSourceImpl extends WidgetSource<WidgetGeoJsonSourceProps> {
10
+ private features;
11
+ protected _filterFeaturesBySpatial(spatialFilter?: SpatialFilter): FeatureData[];
12
+ /**
13
+ * Loads features as GeoJSON.
14
+ */
15
+ loadGeoJSON({ geojson }: {
16
+ geojson: FeatureData[];
17
+ }): void;
18
+ getFeatures(): Promise<FeaturesResponse>;
19
+ getFormula({ column, operation, joinOperation, filters, filterOwner, spatialFilter, }: FormulaRequestOptions): Promise<FormulaResponse>;
20
+ getHistogram({ operation, ticks, column, joinOperation, filters, filterOwner, spatialFilter, }: HistogramRequestOptions): Promise<HistogramResponse>;
21
+ getCategories({ column, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, othersThreshold, orderBy, rawResult, }: CategoryRequestOptions): Promise<CategoryResponse>;
22
+ getScatter({ xAxisColumn, yAxisColumn, xAxisJoinOperation, yAxisJoinOperation, filters, filterOwner, spatialFilter, }: ScatterRequestOptions): Promise<ScatterResponse>;
23
+ getTable({ columns, searchFilterColumn, searchFilterText, sortBy, sortDirection, sortByColumnType, offset, limit, filters, filterOwner, spatialFilter, }: TableRequestOptions): Promise<TableResponse>;
24
+ getTimeSeries({ column, stepSize, operation, operationColumn, joinOperation, filters, filterOwner, spatialFilter, }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
25
+ getRange({ column, filters, filterOwner, spatialFilter, }: RangeRequestOptions): Promise<RangeResponse>;
26
+ getAggregations({ aggregations, filters, filterOwner, spatialFilter, }: AggregationsRequestOptions): Promise<AggregationsResponse>;
27
+ /** @experimental */
28
+ getExtent(): Promise<ExtentResponse>;
29
+ /****************************************************************************
30
+ * INTERNAL
31
+ */
32
+ private _getFilteredFeatures;
33
+ }
@@ -0,0 +1,49 @@
1
+ import { WidgetSource, AggregationsRequestOptions, AggregationsResponse, CategoryRequestOptions, CategoryResponse, ExtentResponse, FeaturesResponse, FormulaRequestOptions, FormulaResponse, HistogramRequestOptions, HistogramResponse, RangeRequestOptions, RangeResponse, ScatterRequestOptions, ScatterResponse, SpatialFilter, TableRequestOptions, TableResponse, TilesetSourceOptions, TimeSeriesRequestOptions, TimeSeriesResponse, WidgetSourceProps } from '@carto/api-client';
2
+ import { Feature } from 'geojson';
3
+ import { Method } from './const';
4
+ import { WidgetGeoJsonSourceImpl } from './widget-geojson-source-impl';
5
+ import { FeatureData } from './types';
6
+ export type WidgetGeoJsonSourceProps = WidgetSourceProps & Omit<TilesetSourceOptions, 'filters' | 'tableName'> & {
7
+ data: Feature[] | string;
8
+ };
9
+ export interface WidgetGeoJsonSourceResult {
10
+ widgetSource: WidgetGeoJsonSource;
11
+ }
12
+ /**
13
+ * Source for Widget API requests on a data source defined by a geojson.
14
+ */
15
+ export declare class WidgetGeoJsonSource<Props extends WidgetGeoJsonSourceProps = WidgetGeoJsonSourceProps> extends WidgetSource<Props> {
16
+ protected _localImpl: WidgetGeoJsonSourceImpl | null;
17
+ protected _workerImpl: Worker | null;
18
+ protected _workerEnabled: boolean;
19
+ protected _workerNextRequestId: number;
20
+ constructor(props: Props);
21
+ destroy(): void;
22
+ /**
23
+ * Returns an initialized Worker, to be reused for the lifecycle of this
24
+ * source instance.
25
+ */
26
+ protected _getWorker(): Worker;
27
+ /** Executes a given method on the worker. */
28
+ protected _executeWorkerMethod<T>(method: (typeof Method)[keyof typeof Method], params: unknown[], signal?: AbortSignal): Promise<T>;
29
+ /**
30
+ * Loads features as GeoJSON
31
+ */
32
+ loadGeoJSON({ geojson }: {
33
+ geojson: FeatureData[];
34
+ }): void;
35
+ getFeatures(): Promise<FeaturesResponse>;
36
+ getFormula({ signal, ...options }: FormulaRequestOptions): Promise<FormulaResponse>;
37
+ getHistogram({ signal, ...options }: HistogramRequestOptions): Promise<HistogramResponse>;
38
+ getCategories({ signal, ...options }: CategoryRequestOptions): Promise<CategoryResponse>;
39
+ getScatter({ signal, ...options }: ScatterRequestOptions): Promise<ScatterResponse>;
40
+ getTable({ signal, ...options }: TableRequestOptions): Promise<TableResponse>;
41
+ getTimeSeries({ signal, ...options }: TimeSeriesRequestOptions): Promise<TimeSeriesResponse>;
42
+ getRange({ signal, ...options }: RangeRequestOptions): Promise<RangeResponse>;
43
+ getAggregations({ signal, ...options }: AggregationsRequestOptions): Promise<AggregationsResponse>;
44
+ /** @experimental */
45
+ getExtent({ signal, ...options }: {
46
+ signal?: AbortSignal;
47
+ spatialFilter?: SpatialFilter;
48
+ }): Promise<ExtentResponse>;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carto/ps-react-maps",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "CARTO's Professional Service React DeckGL library",
5
5
  "type": "module",
6
6
  "dependencies": {},