@carto/api-client 0.5.0-alpha.3 → 0.5.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/api-client.cjs +3332 -3100
  3. package/build/api-client.d.cts +1373 -0
  4. package/build/api-client.d.ts +1373 -0
  5. package/build/api-client.js +1712 -0
  6. package/build/chunk-V3E7BKVR.js +2063 -0
  7. package/build/worker.d.ts +2 -0
  8. package/build/worker.js +25 -0
  9. package/package.json +51 -45
  10. package/src/api/carto-api-error.ts +1 -1
  11. package/src/api/query.ts +5 -5
  12. package/src/api/request-with-parameters.ts +6 -6
  13. package/src/client.ts +3 -3
  14. package/src/constants-internal.ts +5 -11
  15. package/src/constants.ts +6 -6
  16. package/src/deck/get-data-filter-extension-props.ts +146 -0
  17. package/src/deck/index.ts +1 -0
  18. package/src/filters/Filter.ts +18 -8
  19. package/src/filters/FilterTypes.ts +2 -2
  20. package/src/filters/geosjonFeatures.ts +2 -2
  21. package/src/filters/tileFeatures.ts +19 -41
  22. package/src/filters.ts +4 -4
  23. package/src/geo.ts +12 -14
  24. package/src/global.d.ts +3 -8
  25. package/src/index.ts +1 -0
  26. package/src/models/common.ts +9 -7
  27. package/src/models/model.ts +3 -4
  28. package/src/operations/aggregation.ts +5 -5
  29. package/src/operations/applySorting.ts +4 -4
  30. package/src/operations/groupBy.ts +4 -4
  31. package/src/operations/groupByDate.ts +1 -1
  32. package/src/operations/histogram.ts +4 -4
  33. package/src/operations/scatterPlot.ts +4 -4
  34. package/src/sources/base-source.ts +8 -8
  35. package/src/sources/boundary-query-source.ts +2 -2
  36. package/src/sources/boundary-table-source.ts +2 -2
  37. package/src/sources/h3-query-source.ts +7 -5
  38. package/src/sources/h3-table-source.ts +7 -5
  39. package/src/sources/h3-tileset-source.ts +12 -5
  40. package/src/sources/index.ts +26 -26
  41. package/src/sources/quadbin-query-source.ts +7 -5
  42. package/src/sources/quadbin-table-source.ts +7 -5
  43. package/src/sources/quadbin-tileset-source.ts +12 -5
  44. package/src/sources/raster-source.ts +7 -16
  45. package/src/sources/types.ts +10 -4
  46. package/src/sources/vector-query-source.ts +2 -3
  47. package/src/sources/vector-table-source.ts +2 -3
  48. package/src/sources/vector-tileset-source.ts +13 -6
  49. package/src/spatial-index.ts +4 -4
  50. package/src/types-internal.ts +5 -5
  51. package/src/types.ts +15 -21
  52. package/src/utils/makeIntervalComplete.ts +1 -1
  53. package/src/utils.ts +3 -3
  54. package/src/widget-sources/index.ts +1 -1
  55. package/src/widget-sources/types.ts +5 -3
  56. package/src/widget-sources/widget-query-source.ts +6 -2
  57. package/src/widget-sources/widget-remote-source.ts +66 -18
  58. package/src/widget-sources/widget-source.ts +0 -28
  59. package/src/widget-sources/widget-table-source.ts +6 -2
  60. package/src/widget-sources/widget-tileset-source.ts +130 -90
  61. package/src/widget-sources/widget-tileset-worker-source.ts +238 -0
  62. package/src/workers/constants.ts +13 -0
  63. package/src/workers/types.ts +20 -0
  64. package/src/workers/utils.ts +33 -0
  65. package/src/workers/widget-tileset-worker.ts +36 -0
  66. package/build/api/carto-api-error.d.ts +0 -26
  67. package/build/api/endpoints.d.ts +0 -24
  68. package/build/api/index.d.ts +0 -5
  69. package/build/api/query.d.ts +0 -3
  70. package/build/api/request-with-parameters.d.ts +0 -10
  71. package/build/api-client.cjs.map +0 -1
  72. package/build/api-client.modern.js +0 -3304
  73. package/build/api-client.modern.js.map +0 -1
  74. package/build/client.d.ts +0 -14
  75. package/build/constants-internal.d.ts +0 -26
  76. package/build/constants.d.ts +0 -53
  77. package/build/filters/Filter.d.ts +0 -13
  78. package/build/filters/FilterTypes.d.ts +0 -3
  79. package/build/filters/geosjonFeatures.d.ts +0 -8
  80. package/build/filters/index.d.ts +0 -6
  81. package/build/filters/tileFeatures.d.ts +0 -21
  82. package/build/filters/tileFeaturesGeometries.d.ts +0 -13
  83. package/build/filters/tileFeaturesRaster.d.ts +0 -16
  84. package/build/filters/tileFeaturesSpatialIndex.d.ts +0 -10
  85. package/build/filters.d.ts +0 -39
  86. package/build/geo.d.ts +0 -19
  87. package/build/index.d.ts +0 -15
  88. package/build/models/common.d.ts +0 -27
  89. package/build/models/index.d.ts +0 -3
  90. package/build/models/model.d.ts +0 -37
  91. package/build/operations/aggregation.d.ts +0 -8
  92. package/build/operations/applySorting.d.ts +0 -20
  93. package/build/operations/groupBy.d.ts +0 -15
  94. package/build/operations/groupByDate.d.ts +0 -11
  95. package/build/operations/histogram.d.ts +0 -13
  96. package/build/operations/index.d.ts +0 -6
  97. package/build/operations/scatterPlot.d.ts +0 -14
  98. package/build/sources/base-source.d.ts +0 -4
  99. package/build/sources/boundary-query-source.d.ts +0 -10
  100. package/build/sources/boundary-table-source.d.ts +0 -8
  101. package/build/sources/h3-query-source.d.ts +0 -5
  102. package/build/sources/h3-table-source.d.ts +0 -5
  103. package/build/sources/h3-tileset-source.d.ts +0 -5
  104. package/build/sources/index.d.ts +0 -26
  105. package/build/sources/quadbin-query-source.d.ts +0 -5
  106. package/build/sources/quadbin-table-source.d.ts +0 -5
  107. package/build/sources/quadbin-tileset-source.d.ts +0 -5
  108. package/build/sources/raster-source.d.ts +0 -5
  109. package/build/sources/types.d.ts +0 -366
  110. package/build/sources/vector-query-source.d.ts +0 -5
  111. package/build/sources/vector-table-source.d.ts +0 -5
  112. package/build/sources/vector-tileset-source.d.ts +0 -5
  113. package/build/spatial-index.d.ts +0 -14
  114. package/build/types-internal.d.ts +0 -56
  115. package/build/types.d.ts +0 -148
  116. package/build/utils/dateUtils.d.ts +0 -10
  117. package/build/utils/getTileFormat.d.ts +0 -3
  118. package/build/utils/makeIntervalComplete.d.ts +0 -2
  119. package/build/utils/transformTileCoordsToWGS84.d.ts +0 -8
  120. package/build/utils/transformToTileCoords.d.ts +0 -9
  121. package/build/utils.d.ts +0 -32
  122. package/build/widget-sources/index.d.ts +0 -7
  123. package/build/widget-sources/types.d.ts +0 -158
  124. package/build/widget-sources/widget-query-source.d.ts +0 -33
  125. package/build/widget-sources/widget-raster-source.d.ts +0 -11
  126. package/build/widget-sources/widget-remote-source.d.ts +0 -18
  127. package/build/widget-sources/widget-source.d.ts +0 -74
  128. package/build/widget-sources/widget-table-source.d.ts +0 -33
  129. package/build/widget-sources/widget-tileset-source.d.ts +0 -77
  130. package/src/filters/tileFeaturesRaster.ts +0 -111
  131. package/src/widget-sources/widget-raster-source.ts +0 -14
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,25 @@
1
+ import {
2
+ WidgetTilesetSource
3
+ } from "./chunk-V3E7BKVR.js";
4
+
5
+ // src/workers/widget-tileset-worker.ts
6
+ var SOURCES_BY_NAME = /* @__PURE__ */ new Map();
7
+ addEventListener("message", (e) => {
8
+ const { tableName, method, params, requestId } = e.data;
9
+ if (method === "init" /* INIT */) {
10
+ const props = params[0];
11
+ SOURCES_BY_NAME.set(tableName, new WidgetTilesetSource(props));
12
+ return;
13
+ }
14
+ const source = SOURCES_BY_NAME.get(tableName);
15
+ if (!source) {
16
+ const error = `Unknown dataset: ${tableName}`;
17
+ postMessage({ ok: false, error, requestId });
18
+ return;
19
+ }
20
+ Promise.resolve(source[method](...params)).then((result) => {
21
+ postMessage({ ok: true, result, requestId });
22
+ }).catch((error) => {
23
+ postMessage({ ok: false, error, requestId });
24
+ });
25
+ });
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.0-alpha.3",
11
+ "version": "0.5.0-alpha.5",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public",
@@ -16,15 +16,20 @@
16
16
  },
17
17
  "type": "module",
18
18
  "sideEffects": false,
19
- "source": "src/index.ts",
20
- "types": "./build/index.d.ts",
21
- "main": "./build/api-client.cjs",
22
- "module": "./build/api-client.modern.js",
23
19
  "exports": {
24
20
  ".": {
25
- "types": "./build/index.d.ts",
26
- "require": "./build/api-client.cjs",
27
- "default": "./build/api-client.modern.js"
21
+ "require": {
22
+ "types": "./build/api-client.d.cts",
23
+ "default": "./build/api-client.cjs"
24
+ },
25
+ "default": {
26
+ "types": "./build/api-client.d.ts",
27
+ "default": "./build/api-client.js"
28
+ }
29
+ },
30
+ "./worker": {
31
+ "types": "./build/worker.d.ts",
32
+ "default": "./build/worker.js"
28
33
  }
29
34
  },
30
35
  "browserslist": [
@@ -33,14 +38,15 @@
33
38
  "node >= 18"
34
39
  ],
35
40
  "scripts": {
36
- "build": "microbundle --format cjs,modern --no-compress --define __CARTO_API_CLIENT_VERSION=$npm_package_version",
37
- "build:watch": "microbundle watch --format cjs,modern --no-compress --define __CARTO_API_CLIENT_VERSION=$npm_package_version",
41
+ "build": "tsup",
42
+ "build:watch": "tsup --watch",
38
43
  "dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
39
44
  "test": "vitest run --typecheck",
40
45
  "test:watch": "vitest watch --typecheck",
41
46
  "coverage": "vitest run --coverage.enabled --coverage.all false",
42
- "lint": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --check",
43
- "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write",
47
+ "lint": "eslint .",
48
+ "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --write",
49
+ "format:check": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --check",
44
50
  "clean": "rimraf build/*",
45
51
  "postversion": "yarn postversion:check && yarn postversion:commit && yarn postversion:push",
46
52
  "postversion:check": "yarn lint && yarn test",
@@ -57,53 +63,53 @@
57
63
  ],
58
64
  "dependencies": {
59
65
  "@loaders.gl/schema": "^4.3.3",
60
- "@turf/bbox-clip": "^7.1.0",
61
- "@turf/bbox-polygon": "^7.1.0",
62
- "@turf/boolean-intersects": "^7.1.0",
63
- "@turf/boolean-within": "^7.1.0",
64
- "@turf/helpers": "^7.1.0",
65
- "@turf/intersect": "^7.1.0",
66
- "@turf/invariant": "^7.1.0",
67
- "@turf/union": "^7.1.0",
68
- "@types/geojson": "^7946.0.15",
69
- "h3-js": "4.1.0",
70
- "quadbin": "^0.4.0-alpha.2"
66
+ "@turf/bbox-clip": "^7.2.0",
67
+ "@turf/bbox-polygon": "^7.2.0",
68
+ "@turf/boolean-equal": "^7.2.0",
69
+ "@turf/boolean-intersects": "^7.2.0",
70
+ "@turf/boolean-within": "^7.2.0",
71
+ "@turf/helpers": "^7.2.0",
72
+ "@turf/intersect": "^7.2.0",
73
+ "@turf/invariant": "^7.2.0",
74
+ "@turf/union": "^7.2.0",
75
+ "@types/geojson": "^7946.0.16",
76
+ "h3-js": "4.1.0"
71
77
  },
72
78
  "devDependencies": {
73
- "@deck.gl/aggregation-layers": "^9.0.38",
74
- "@deck.gl/carto": "^9.0.38",
75
- "@deck.gl/core": "^9.0.38",
76
- "@deck.gl/extensions": "^9.0.38",
77
- "@deck.gl/geo-layers": "^9.0.38",
78
- "@deck.gl/layers": "^9.0.38",
79
- "@deck.gl/mesh-layers": "^9.0.38",
80
- "@lit/react": "^1.0.6",
81
- "@lit/task": "^1.0.1",
79
+ "@deck.gl/aggregation-layers": "~9.1.0",
80
+ "@deck.gl/carto": "~9.1.0",
81
+ "@deck.gl/core": "~9.1.0",
82
+ "@deck.gl/extensions": "~9.1.0",
83
+ "@deck.gl/geo-layers": "~9.1.0",
84
+ "@deck.gl/layers": "~9.1.0",
85
+ "@deck.gl/mesh-layers": "~9.1.0",
86
+ "@eslint/js": "^9.20.0",
87
+ "@lit/react": "^1.0.7",
88
+ "@lit/task": "^1.0.2",
82
89
  "@loaders.gl/core": "^4.3.3",
83
- "@luma.gl/core": "~9.0.27",
84
- "@luma.gl/engine": "~9.0.27",
85
- "@turf/buffer": "^7.2.0",
90
+ "@luma.gl/core": "~9.1.0",
91
+ "@luma.gl/engine": "~9.1.0",
92
+ "@luma.gl/shadertools": "~9.1.0",
86
93
  "@types/json-schema": "^7.0.15",
87
94
  "@types/react": "^18.3.18",
88
95
  "@types/semver": "^7.5.8",
89
- "@vitest/coverage-istanbul": "^3.0.2",
96
+ "@vitest/coverage-istanbul": "^3.0.5",
90
97
  "@webcomponents/webcomponentsjs": "^2.8.0",
91
98
  "concurrently": "^9.1.2",
92
99
  "echarts": "^5.6.0",
100
+ "eslint": "^9.20.1",
93
101
  "lit": "^3.2.1",
94
102
  "lit-analyzer": "^2.0.3",
95
- "maplibre-gl": "^5.0.0",
96
- "microbundle": "^0.15.1",
103
+ "maplibre-gl": "^5.1.0",
97
104
  "prettier": "^3.4.2",
98
105
  "rimraf": "^6.0.1",
99
- "semver": "^7.6.3",
106
+ "semver": "^7.7.1",
100
107
  "thenby": "^1.3.4",
108
+ "tsup": "^8.3.6",
101
109
  "typescript": "~5.7.3",
102
- "vite": "^6.0.7",
103
- "vitest": "2.1.8"
110
+ "typescript-eslint": "^8.24.0",
111
+ "vite": "^6.1.0",
112
+ "vitest": "3.0.5"
104
113
  },
105
- "resolutions": {
106
- "rollup": "^4.20.0"
107
- },
108
- "stableVersion": "0.4.5"
114
+ "stableVersion": "0.4.6"
109
115
  }
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {MapType} from '../types';
5
+ import {MapType} from '../types.js';
6
6
 
7
7
  export type APIRequestType =
8
8
  | 'Map data'
package/src/api/query.ts CHANGED
@@ -2,15 +2,15 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {SOURCE_DEFAULTS} from '../sources/index';
5
+ import {SOURCE_DEFAULTS} from '../sources/index.js';
6
6
  import type {
7
7
  SourceOptions,
8
8
  QuerySourceOptions,
9
9
  QueryResult,
10
- } from '../sources/types';
11
- import {buildQueryUrl} from './endpoints';
12
- import {requestWithParameters} from './request-with-parameters';
13
- import {APIErrorContext} from './carto-api-error';
10
+ } from '../sources/types.js';
11
+ import {buildQueryUrl} from './endpoints.js';
12
+ import {requestWithParameters} from './request-with-parameters.js';
13
+ import {APIErrorContext} from './carto-api-error.js';
14
14
 
15
15
  export type QueryOptions = SourceOptions & QuerySourceOptions;
16
16
  type UrlParameters = {q: string; queryParameters?: string};
@@ -2,12 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import {isPureObject} from '../utils';
6
- import {CartoAPIError, APIErrorContext} from './carto-api-error';
7
- import {V3_MINOR_VERSION} from '../constants-internal';
8
- import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal';
9
- import {getClient} from '../client';
10
- import {LocalCacheOptions} from '../sources/types';
5
+ import {isPureObject} from '../utils.js';
6
+ import {CartoAPIError, APIErrorContext} from './carto-api-error.js';
7
+ import {V3_MINOR_VERSION} from '../constants-internal.js';
8
+ import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal.js';
9
+ import {getClient} from '../client.js';
10
+ import {LocalCacheOptions} from '../sources/types.js';
11
11
 
12
12
  const DEFAULT_HEADERS = {
13
13
  Accept: 'application/json',
package/src/client.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @internal
3
- * @internalRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
3
+ * @privateRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
4
4
  */
5
5
  let client = 'deck-gl-carto';
6
6
 
@@ -8,7 +8,7 @@ let client = 'deck-gl-carto';
8
8
  * Returns current client ID, used to categorize API requests. For internal use only.
9
9
  *
10
10
  * @internal
11
- * @internalRemarks Source: @carto/react-core
11
+ * @privateRemarks Source: @carto/react-core
12
12
  */
13
13
  export function getClient() {
14
14
  return client;
@@ -18,7 +18,7 @@ export function getClient() {
18
18
  * Sets current client ID, used to categorize API requests. For internal use only.
19
19
  *
20
20
  * @internal
21
- * @internalRemarks Source: @carto/react-core
21
+ * @privateRemarks Source: @carto/react-core
22
22
  */
23
23
  export function setClient(c: string) {
24
24
  client = c;
@@ -1,32 +1,26 @@
1
- /**
2
- * Current version of @carto/api-client.
3
- * @internal
4
- */
5
- export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
6
-
7
1
  /** @internal */
8
2
  export const V3_MINOR_VERSION = '3.4';
9
3
 
10
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
4
+ /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
11
5
  export const DEFAULT_GEO_COLUMN = 'geom';
12
6
 
13
7
  /**
14
8
  * Fastly default limit is 8192; leave some padding.
15
- * @internalRemarks Source: @deck.gl/carto
9
+ * @privateRemarks Source: @deck.gl/carto
16
10
  */
17
11
  export const DEFAULT_MAX_LENGTH_URL = 7000;
18
12
 
19
- /** @internalRemarks Source: @deck.gl/carto */
13
+ /** @privateRemarks Source: @deck.gl/carto */
20
14
  export const DEFAULT_TILE_RESOLUTION = 0.5;
21
15
 
22
16
  /**
23
- * @internalRemarks Source: @deck.gl/carto
17
+ * @privateRemarks Source: @deck.gl/carto
24
18
  * @internal
25
19
  */
26
20
  export const DEFAULT_AGGREGATION_RES_LEVEL_H3 = 4;
27
21
 
28
22
  /**
29
- * @internalRemarks Source: @deck.gl/carto
23
+ * @privateRemarks Source: @deck.gl/carto
30
24
  * @internal
31
25
  */
32
26
  export const DEFAULT_AGGREGATION_RES_LEVEL_QUADBIN = 6;
package/src/constants.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * };
11
11
  * ```
12
12
  *
13
- * @internalRemarks Source: @carto/react-api, @deck.gl/carto
13
+ * @privateRemarks Source: @carto/react-api, @deck.gl/carto
14
14
  */
15
15
  export enum FilterType {
16
16
  IN = 'in',
@@ -22,17 +22,17 @@ export enum FilterType {
22
22
  STRING_SEARCH = 'stringSearch',
23
23
  }
24
24
 
25
- /** @internalRemarks Source: @carto/constants */
25
+ /** @privateRemarks Source: @carto/constants */
26
26
  export enum ApiVersion {
27
27
  V1 = 'v1',
28
28
  V2 = 'v2',
29
29
  V3 = 'v3',
30
30
  }
31
31
 
32
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
32
+ /** @privateRemarks Source: @carto/constants, @deck.gl/carto */
33
33
  export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
34
34
 
35
- /** @internalRemarks Source: @carto/react-core */
35
+ /** @privateRemarks Source: @carto/react-core */
36
36
  export enum TileFormat {
37
37
  MVT = 'mvt',
38
38
  JSON = 'json',
@@ -40,14 +40,14 @@ export enum TileFormat {
40
40
  BINARY = 'binary',
41
41
  }
42
42
 
43
- /** @internalRemarks Source: @carto/react-core */
43
+ /** @privateRemarks Source: @carto/react-core */
44
44
  export enum SpatialIndex {
45
45
  H3 = 'h3',
46
46
  S2 = 's2',
47
47
  QUADBIN = 'quadbin',
48
48
  }
49
49
 
50
- /** @internalRemarks Source: @carto/react-core */
50
+ /** @privateRemarks Source: @carto/react-core */
51
51
  export enum Provider {
52
52
  BIGQUERY = 'bigquery',
53
53
  REDSHIFT = 'redshift',
@@ -0,0 +1,146 @@
1
+ import {Feature} from 'geojson';
2
+ import {FilterLogicalOperator, Filters} from '../types.js';
3
+ import {FilterType} from '../constants.js';
4
+ import {_buildFeatureFilter} from '../filters/index.js';
5
+ import {FeatureData} from '../types-internal.js';
6
+
7
+ type TimeFilter = Filters['string'][FilterType.TIME] & {
8
+ params?: {offsetBy?: number};
9
+ };
10
+
11
+ /** @experimental Prefer type definition from deck.gl. */
12
+ export type _DataFilterExtensionProps = {
13
+ filterRange: number[][];
14
+ updateTriggers: Record<string, string>;
15
+ getFilterValue: (feature: Feature | FeatureData) => number[];
16
+ };
17
+
18
+ /**
19
+ * Creates props for DataFilterExtension, from `@deck.gl/extensions`, given
20
+ * a set of filters.
21
+ *
22
+ * @privateRemarks DataFilterExtension accepts up to 4 values to filter. This
23
+ * implementation uses the 1st for all filters except the time filter, and the
24
+ * 2nd for the time filter.
25
+ */
26
+ export function getDataFilterExtensionProps(
27
+ filters: Filters,
28
+ filtersLogicalOperator?: FilterLogicalOperator,
29
+ filterSize?: 0 | 1 | 2 | 3 | 4
30
+ ): _DataFilterExtensionProps {
31
+ filterSize ??= 4;
32
+ const {filtersWithoutTimeType, timeColumn, timeFilter} =
33
+ getFiltersByType(filters);
34
+ return {
35
+ filterRange: getFilterRange(timeFilter, filterSize),
36
+ updateTriggers: getUpdateTriggers(
37
+ filtersWithoutTimeType,
38
+ timeColumn,
39
+ timeFilter
40
+ ),
41
+ getFilterValue: getFilterValue(
42
+ filtersWithoutTimeType,
43
+ timeColumn,
44
+ timeFilter,
45
+ filterSize,
46
+ filtersLogicalOperator
47
+ ),
48
+ };
49
+ }
50
+
51
+ /** @internal */
52
+ function getFiltersByType(filters: Filters) {
53
+ const filtersWithoutTimeType: Filters = {};
54
+
55
+ let timeColumn: string | null = null;
56
+ let timeFilter: TimeFilter | null = null;
57
+
58
+ for (const [column, columnData] of Object.entries(filters)) {
59
+ for (const [type, typeData] of Object.entries(columnData) as [
60
+ FilterType,
61
+ unknown,
62
+ ][]) {
63
+ if (type === FilterType.TIME) {
64
+ timeColumn = column;
65
+ timeFilter = typeData as TimeFilter;
66
+ } else {
67
+ filtersWithoutTimeType[column] = {[type]: typeData};
68
+ }
69
+ }
70
+ }
71
+
72
+ return {
73
+ filtersWithoutTimeType,
74
+ timeColumn,
75
+ timeFilter,
76
+ };
77
+ }
78
+
79
+ /** @internal */
80
+ function getFilterRange(
81
+ timeFilter: TimeFilter | null,
82
+ filterSize: number
83
+ ): number[][] {
84
+ const result = Array(filterSize).fill([0, 0]);
85
+ // According to getFilterValue all filters are resolved as 0 or 1 in the first position of the array
86
+ // except the time filter value that is resolved with the real value of the feature in the second position of the array
87
+ result[0] = [1, 1];
88
+ if (timeFilter) {
89
+ const offsetBy = timeFilter.params?.offsetBy || 0;
90
+ result[1] = timeFilter.values[0].map((v) => v - offsetBy);
91
+ }
92
+ return result;
93
+ }
94
+
95
+ /** @internal */
96
+ function getUpdateTriggers(
97
+ filtersWithoutTimeType: Filters,
98
+ timeColumn: string | null,
99
+ timeFilter: TimeFilter | null
100
+ ) {
101
+ const result: Record<string, object> = {...filtersWithoutTimeType};
102
+
103
+ // We don't want to change the layer UpdateTriggers every time that the time filter changes
104
+ // because this filter is changed by the time series widget during its animation
105
+ // so we remove the time filter value from the `updateTriggers`
106
+ if (timeColumn && timeFilter) {
107
+ result[timeColumn] = {
108
+ ...result[timeColumn],
109
+ offsetBy: timeFilter.params?.offsetBy,
110
+ [FilterType.TIME]: {}, // Allows working with other filters, without an impact on performance.
111
+ };
112
+ }
113
+ return {
114
+ getFilterValue: JSON.stringify(result),
115
+ };
116
+ }
117
+
118
+ /** @internal */
119
+ function getFilterValue(
120
+ filtersWithoutTimeType: Filters,
121
+ timeColumn: string | null,
122
+ timeFilter: TimeFilter | null,
123
+ filterSize: number,
124
+ filtersLogicalOperator?: FilterLogicalOperator
125
+ ) {
126
+ const result = Array(filterSize).fill(0);
127
+ const featureFilter = _buildFeatureFilter({
128
+ filters: filtersWithoutTimeType,
129
+ type: 'number',
130
+ filtersLogicalOperator,
131
+ });
132
+
133
+ // We evaluate all filters except the time filter using _buildFeatureFilter function.
134
+ // For the time filter, we return the value of the feature and we will change the getFilterRange result
135
+ // every time this filter changes
136
+ return (feature: Feature | FeatureData) => {
137
+ result[0] = featureFilter(feature);
138
+
139
+ if (timeColumn && timeFilter) {
140
+ const offsetBy = timeFilter.params?.offsetBy || 0;
141
+ const f = (feature.properties || feature) as Record<string, unknown>;
142
+ result[1] = (f[timeColumn] as number) - offsetBy;
143
+ }
144
+ return result;
145
+ };
146
+ }
@@ -0,0 +1 @@
1
+ export * from './get-data-filter-extension-props.js';
@@ -1,8 +1,8 @@
1
- import {filterFunctions} from './FilterTypes';
2
- import {Filter, FilterLogicalOperator, Filters} from '../types';
1
+ import {filterFunctions} from './FilterTypes.js';
2
+ import {Filter, FilterLogicalOperator, Filters} from '../types.js';
3
3
  import {Feature} from 'geojson';
4
- import {FilterType} from '../constants';
5
- import {FeatureData} from '../types-internal';
4
+ import {FilterType} from '../constants.js';
5
+ import {FeatureData} from '../types-internal.js';
6
6
  import {BinaryFeature} from '@loaders.gl/schema';
7
7
 
8
8
  const LOGICAL_OPERATOR_METHODS: Record<
@@ -44,7 +44,11 @@ function passesFilter(
44
44
  });
45
45
  }
46
46
 
47
- export function buildFeatureFilter({
47
+ /**
48
+ * @internal
49
+ * @privateRemarks Exported for use in @deck.gl/carto's getDataFilterExtensionProps.
50
+ */
51
+ export function _buildFeatureFilter({
48
52
  filters = {},
49
53
  type = 'boolean',
50
54
  filtersLogicalOperator = 'and',
@@ -74,18 +78,24 @@ export function buildFeatureFilter({
74
78
  };
75
79
  }
76
80
 
77
- // Apply certain filters to a collection of features
81
+ /**
82
+ * Apply certain filters to a collection of features.
83
+ * @internal
84
+ */
78
85
  export function applyFilters(
79
86
  features: FeatureData[],
80
87
  filters: Filters,
81
88
  filtersLogicalOperator: FilterLogicalOperator
82
89
  ) {
83
90
  return Object.keys(filters).length
84
- ? features.filter(buildFeatureFilter({filters, filtersLogicalOperator}))
91
+ ? features.filter(_buildFeatureFilter({filters, filtersLogicalOperator}))
85
92
  : features;
86
93
  }
87
94
 
88
- // Binary
95
+ /**
96
+ * Binary.
97
+ * @internal
98
+ */
89
99
  export function buildBinaryFeatureFilter({filters = {}}: {filters: Filters}) {
90
100
  const columns = Object.keys(filters);
91
101
 
@@ -1,5 +1,5 @@
1
- import {FilterType} from '../constants';
2
- import {FilterInterval, StringSearchOptions} from '../types';
1
+ import {FilterType} from '../constants.js';
2
+ import {FilterInterval, StringSearchOptions} from '../types.js';
3
3
  import {makeIntervalComplete} from '../utils/makeIntervalComplete.js';
4
4
 
5
5
  export type FilterFunction = (
@@ -1,7 +1,7 @@
1
1
  import intersects from '@turf/boolean-intersects';
2
2
  import {FeatureCollection} from 'geojson';
3
- import {SpatialFilter} from '..';
4
- import {FeatureData} from '../types-internal';
3
+ import {FeatureData} from '../types-internal.js';
4
+ import {SpatialFilter} from '../types.js';
5
5
 
6
6
  export function geojsonFeatures({
7
7
  geojson,
@@ -1,31 +1,28 @@
1
- import {RasterTile, SpatialFilter, SpatialIndexTile, Tile} from '../types';
2
- import {tileFeaturesGeometries} from './tileFeaturesGeometries';
3
- import {tileFeaturesSpatialIndex} from './tileFeaturesSpatialIndex';
4
- import {TileFormat} from '../constants';
5
- import {DEFAULT_GEO_COLUMN} from '../constants-internal';
6
- import {FeatureData} from '../types-internal';
7
- import {RasterMetadata, SpatialDataType} from '../sources/types';
8
- import {isRasterTile, tileFeaturesRaster} from './tileFeaturesRaster';
9
- import {assert} from '../utils';
1
+ import {SpatialFilter, SpatialIndexTile, Tile} from '../types.js';
2
+ import {tileFeaturesGeometries} from './tileFeaturesGeometries.js';
3
+ import {tileFeaturesSpatialIndex} from './tileFeaturesSpatialIndex.js';
4
+ import {TileFormat} from '../constants.js';
5
+ import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
6
+ import {FeatureData} from '../types-internal.js';
7
+ import {SpatialDataType} from '../sources/types.js';
10
8
 
11
- /** @internalRemarks Source: @carto/react-core */
9
+ /** @privateRemarks Source: @carto/react-core */
12
10
  export type TileFeatures = {
13
11
  tiles: Tile[];
14
12
  tileFormat: TileFormat;
15
13
  spatialDataType: SpatialDataType;
16
14
  spatialDataColumn?: string;
17
- spatialFilter?: SpatialFilter;
15
+ spatialFilter: SpatialFilter;
18
16
  uniqueIdProperty?: string;
19
- rasterMetadata?: RasterMetadata;
20
17
  options?: TileFeatureExtractOptions;
21
18
  };
22
19
 
23
- /** @internalRemarks Source: @carto/react-core */
20
+ /** @privateRemarks Source: @carto/react-core */
24
21
  export type TileFeatureExtractOptions = {
25
22
  storeGeometry?: boolean;
26
23
  };
27
24
 
28
- /** @internalRemarks Source: @carto/react-core */
25
+ /** @privateRemarks Source: @carto/react-core */
29
26
  export function tileFeatures({
30
27
  tiles,
31
28
  spatialFilter,
@@ -33,40 +30,21 @@ export function tileFeatures({
33
30
  tileFormat,
34
31
  spatialDataColumn = DEFAULT_GEO_COLUMN,
35
32
  spatialDataType,
36
- rasterMetadata,
37
33
  options = {},
38
34
  }: TileFeatures): FeatureData[] {
39
- // TODO(cleanup): Is an empty response the expected result when spatialFilter
40
- // is omitted? Why not make the parameter required, or return the full input?
41
- if (!spatialFilter) {
42
- return [];
43
- }
44
-
45
- if (spatialDataType === 'geo') {
46
- return tileFeaturesGeometries({
47
- tiles,
48
- tileFormat,
49
- spatialFilter,
50
- uniqueIdProperty,
51
- options,
52
- });
53
- }
54
-
55
- if (tiles.some(isRasterTile)) {
56
- assert(rasterMetadata, 'Missing raster metadata');
57
- return tileFeaturesRaster({
58
- tiles: tiles as RasterTile[],
35
+ if (spatialDataType !== 'geo') {
36
+ return tileFeaturesSpatialIndex({
37
+ tiles: tiles as SpatialIndexTile[],
59
38
  spatialFilter,
60
39
  spatialDataColumn,
61
40
  spatialDataType,
62
- rasterMetadata,
63
41
  });
64
42
  }
65
-
66
- return tileFeaturesSpatialIndex({
67
- tiles: tiles as SpatialIndexTile[],
43
+ return tileFeaturesGeometries({
44
+ tiles,
45
+ tileFormat,
68
46
  spatialFilter,
69
- spatialDataColumn,
70
- spatialDataType,
47
+ uniqueIdProperty,
48
+ options,
71
49
  });
72
50
  }