@carto/api-client 0.0.41 → 0.0.43

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.
@@ -62,43 +62,6 @@ exports.FilterType = void 0;
62
62
  FilterType["STRING_SEARCH"] = "stringSearch";
63
63
  })(exports.FilterType || (exports.FilterType = {}));
64
64
 
65
- /******************************************************************************
66
- * DEFAULTS
67
- */
68
- /**
69
- * @internalRemarks Source: @carto/constants
70
- * @internal
71
- */
72
- const DEFAULT_API_BASE_URL$1 = 'https://gcp-us-east1.api.carto.com';
73
- /**
74
- * @internalRemarks Source: @carto/react-api
75
- * @internal
76
- */
77
- const DEFAULT_GEO_COLUMN = 'geom';
78
- /******************************************************************************
79
- * ENUMS
80
- */
81
- /**
82
- * @internal
83
- * @internalRemarks Source: @carto/constants
84
- */
85
- var MapType;
86
- (function (MapType) {
87
- MapType["TABLE"] = "table";
88
- MapType["QUERY"] = "query";
89
- MapType["TILESET"] = "tileset";
90
- })(MapType || (MapType = {}));
91
- /**
92
- * @internal
93
- * @internalRemarks Source: @carto/constants
94
- */
95
- var ApiVersion;
96
- (function (ApiVersion) {
97
- ApiVersion["V1"] = "v1";
98
- ApiVersion["V2"] = "v2";
99
- ApiVersion["V3"] = "v3";
100
- })(ApiVersion || (ApiVersion = {}));
101
-
102
65
  const FILTER_TYPES = new Set(Object.values(exports.FilterType));
103
66
  const isFilterType = type => FILTER_TYPES.has(type);
104
67
  /**
@@ -112,7 +75,8 @@ function getApplicableFilters(owner, filters) {
112
75
  for (const type in filters[column]) {
113
76
  if (!isFilterType(type)) continue;
114
77
  const filter = filters[column][type];
115
- if (filter && filter.owner !== owner) {
78
+ const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
79
+ if (filter && isApplicable) {
116
80
  applicableFilters[column] ||= {};
117
81
  applicableFilters[column][type] = filter;
118
82
  }
@@ -159,6 +123,107 @@ class InvalidColumnError extends Error {
159
123
  }
160
124
  }
161
125
  InvalidColumnError.NAME = 'InvalidColumnError';
126
+ function isEmptyObject(object) {
127
+ for (const _ in object) {
128
+ return false;
129
+ }
130
+ return true;
131
+ }
132
+
133
+ /**
134
+ * Adds a {@link Filter} to the filter set. Any previous filters with the same
135
+ * `column` and `type` will be replaced.
136
+ */
137
+ function addFilter(filters, _ref) {
138
+ let {
139
+ column,
140
+ type,
141
+ values,
142
+ owner
143
+ } = _ref;
144
+ if (!filters[column]) {
145
+ filters[column] = {};
146
+ }
147
+ const filter = {
148
+ values,
149
+ owner
150
+ };
151
+ filters[column][type] = filter;
152
+ return filters;
153
+ }
154
+ /**
155
+ * Removes one or more {@link Filter filters} from the filter set. If only
156
+ * `column` is specified, then all filters on that column are removed. If both
157
+ * `column` and `owner` are specified, then only filters for that column
158
+ * associated with the owner are removed.
159
+ */
160
+ function removeFilter(filters, _ref2) {
161
+ let {
162
+ column,
163
+ owner
164
+ } = _ref2;
165
+ const filter = filters[column];
166
+ if (!filter) {
167
+ return filters;
168
+ }
169
+ if (owner) {
170
+ for (const type in exports.FilterType) {
171
+ if (owner === filter[type]?.owner) {
172
+ delete filter[type];
173
+ }
174
+ }
175
+ }
176
+ if (!owner || isEmptyObject(filter)) {
177
+ delete filters[column];
178
+ }
179
+ return filters;
180
+ }
181
+ /**
182
+ * Clears all {@link Filter filters} from the filter set.
183
+ */
184
+ function clearFilters(filters) {
185
+ for (const column of Object.keys(filters)) {
186
+ delete filters[column];
187
+ }
188
+ return filters;
189
+ }
190
+
191
+ /******************************************************************************
192
+ * DEFAULTS
193
+ */
194
+ /**
195
+ * @internalRemarks Source: @carto/constants
196
+ * @internal
197
+ */
198
+ const DEFAULT_API_BASE_URL$1 = 'https://gcp-us-east1.api.carto.com';
199
+ /**
200
+ * @internalRemarks Source: @carto/react-api
201
+ * @internal
202
+ */
203
+ const DEFAULT_GEO_COLUMN = 'geom';
204
+ /******************************************************************************
205
+ * ENUMS
206
+ */
207
+ /**
208
+ * @internal
209
+ * @internalRemarks Source: @carto/constants
210
+ */
211
+ var MapType;
212
+ (function (MapType) {
213
+ MapType["TABLE"] = "table";
214
+ MapType["QUERY"] = "query";
215
+ MapType["TILESET"] = "tileset";
216
+ })(MapType || (MapType = {}));
217
+ /**
218
+ * @internal
219
+ * @internalRemarks Source: @carto/constants
220
+ */
221
+ var ApiVersion;
222
+ (function (ApiVersion) {
223
+ ApiVersion["V1"] = "v1";
224
+ ApiVersion["V2"] = "v2";
225
+ ApiVersion["V3"] = "v3";
226
+ })(ApiVersion || (ApiVersion = {}));
162
227
 
163
228
  /**
164
229
  * Return more descriptive error from API
@@ -816,7 +881,7 @@ const V3_MINOR_VERSION = '3.4';
816
881
  const MAX_GET_LENGTH = 8192;
817
882
  const DEFAULT_PARAMETERS = {
818
883
  v: V3_MINOR_VERSION,
819
- deckglVersion: "0.0.41"
884
+ deckglVersion: "0.0.43"
820
885
  };
821
886
  const DEFAULT_HEADERS = {
822
887
  Accept: 'application/json',
@@ -1317,11 +1382,14 @@ function assignDefaultProps(props) {
1317
1382
  exports.WidgetBaseSource = WidgetBaseSource;
1318
1383
  exports.WidgetQuerySource = WidgetQuerySource;
1319
1384
  exports.WidgetTableSource = WidgetTableSource;
1385
+ exports.addFilter = addFilter;
1386
+ exports.clearFilters = clearFilters;
1320
1387
  exports.getClient = getClient;
1321
1388
  exports.h3QuerySource = h3QuerySource;
1322
1389
  exports.h3TableSource = h3TableSource;
1323
1390
  exports.quadbinQuerySource = quadbinQuerySource;
1324
1391
  exports.quadbinTableSource = quadbinTableSource;
1392
+ exports.removeFilter = removeFilter;
1325
1393
  exports.setClient = setClient;
1326
1394
  exports.vectorQuerySource = vectorQuerySource;
1327
1395
  exports.vectorTableSource = vectorTableSource;