@budibase/shared-core 2.29.17 → 2.29.18

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.
package/dist/filters.d.ts CHANGED
@@ -17,6 +17,14 @@ export declare const getValidOperatorsForType: (fieldType: {
17
17
  * Operators which do not support empty strings as values
18
18
  */
19
19
  export declare const NoEmptyFilterStrings: (keyof SearchQueryFields)[];
20
+ /**
21
+ * Removes any fields that contain empty strings that would cause inconsistent
22
+ * behaviour with how backend tables are filtered (no value means no filter).
23
+ *
24
+ * don't do a pure falsy check, as 0 is included
25
+ * https://github.com/Budibase/budibase/issues/10118
26
+ */
27
+ export declare const cleanupQuery: (query: SearchFilters) => SearchFilters;
20
28
  /**
21
29
  * Removes a numeric prefix on field names designed to give fields uniqueness
22
30
  */
package/dist/index.js CHANGED
@@ -10389,6 +10389,7 @@ __export(filters_exports, {
10389
10389
  ColumnSplitter: () => ColumnSplitter,
10390
10390
  NoEmptyFilterStrings: () => NoEmptyFilterStrings,
10391
10391
  buildQuery: () => buildQuery,
10392
+ cleanupQuery: () => cleanupQuery,
10392
10393
  fixupFilterArrays: () => fixupFilterArrays,
10393
10394
  getKeyNumbering: () => getKeyNumbering,
10394
10395
  getValidOperatorsForType: () => getValidOperatorsForType,
@@ -10606,25 +10607,37 @@ var NoEmptyFilterStrings = [
10606
10607
  OperatorOptions.Equals.value,
10607
10608
  OperatorOptions.NotEquals.value,
10608
10609
  OperatorOptions.Contains.value,
10609
- OperatorOptions.NotContains.value
10610
+ OperatorOptions.NotContains.value,
10611
+ OperatorOptions.ContainsAny.value,
10612
+ OperatorOptions.In.value
10610
10613
  ];
10611
10614
  var cleanupQuery = (query) => {
10612
10615
  if (!query) {
10613
10616
  return query;
10614
10617
  }
10615
10618
  for (let filterField of NoEmptyFilterStrings) {
10616
- const operator = filterField;
10617
- if (!query[operator]) {
10619
+ if (!query[filterField]) {
10618
10620
  continue;
10619
10621
  }
10620
- for (let [key, value] of Object.entries(query[operator])) {
10621
- if (value == null || value === "") {
10622
- delete query[operator][key];
10622
+ for (let filterType of Object.keys(query)) {
10623
+ if (filterType !== filterField) {
10624
+ continue;
10625
+ }
10626
+ const value = query[filterType];
10627
+ if (typeof value === "object") {
10628
+ for (let [key, value2] of Object.entries(query[filterType])) {
10629
+ if (value2 == null || value2 === "" || isEmptyArray(value2)) {
10630
+ delete query[filterField][key];
10631
+ }
10632
+ }
10623
10633
  }
10624
10634
  }
10625
10635
  }
10626
10636
  return query;
10627
10637
  };
10638
+ function isEmptyArray(value) {
10639
+ return Array.isArray(value) && value.length === 0;
10640
+ }
10628
10641
  var removeKeyNumbering = (key) => {
10629
10642
  return getKeyNumbering(key).key;
10630
10643
  };