@budibase/shared-core 2.32.0 → 2.32.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.
package/dist/index.js CHANGED
@@ -10082,6 +10082,15 @@ var UserGroupSyncEvents = [
10082
10082
  var AsyncEvents = [...UserGroupSyncEvents];
10083
10083
 
10084
10084
  // ../types/src/sdk/search.ts
10085
+ var BasicOperator = /* @__PURE__ */ ((BasicOperator2) => {
10086
+ BasicOperator2["EQUAL"] = "equal";
10087
+ BasicOperator2["NOT_EQUAL"] = "notEqual";
10088
+ BasicOperator2["EMPTY"] = "empty";
10089
+ BasicOperator2["NOT_EMPTY"] = "notEmpty";
10090
+ BasicOperator2["FUZZY"] = "fuzzy";
10091
+ BasicOperator2["STRING"] = "string";
10092
+ return BasicOperator2;
10093
+ })(BasicOperator || {});
10085
10094
  var ArrayOperator = /* @__PURE__ */ ((ArrayOperator2) => {
10086
10095
  ArrayOperator2["CONTAINS"] = "contains";
10087
10096
  ArrayOperator2["NOT_CONTAINS"] = "notContains";
@@ -10089,6 +10098,10 @@ var ArrayOperator = /* @__PURE__ */ ((ArrayOperator2) => {
10089
10098
  ArrayOperator2["ONE_OF"] = "oneOf";
10090
10099
  return ArrayOperator2;
10091
10100
  })(ArrayOperator || {});
10101
+ var RangeOperator = /* @__PURE__ */ ((RangeOperator2) => {
10102
+ RangeOperator2["RANGE"] = "range";
10103
+ return RangeOperator2;
10104
+ })(RangeOperator || {});
10092
10105
  var LogicalOperator = /* @__PURE__ */ ((LogicalOperator2) => {
10093
10106
  LogicalOperator2["AND"] = "$and";
10094
10107
  LogicalOperator2["OR"] = "$or";
@@ -10603,6 +10616,12 @@ function decodeNonAscii(str) {
10603
10616
  // src/filters.ts
10604
10617
  var import_lodash = __toESM(require_lodash());
10605
10618
  var HBS_REGEX = /{{([^{].*?)}}/g;
10619
+ var LOGICAL_OPERATORS = Object.values(LogicalOperator);
10620
+ var SEARCH_OPERATORS = [
10621
+ ...Object.values(BasicOperator),
10622
+ ...Object.values(ArrayOperator),
10623
+ ...Object.values(RangeOperator)
10624
+ ];
10606
10625
  var getValidOperatorsForType = (fieldType, field, datasource) => {
10607
10626
  const Op = OperatorOptions;
10608
10627
  const stringOps = [
@@ -10663,7 +10682,7 @@ var NoEmptyFilterStrings = [
10663
10682
  OperatorOptions.In.value
10664
10683
  ];
10665
10684
  function recurseLogicalOperators(filters, fn) {
10666
- for (const logical of Object.values(LogicalOperator)) {
10685
+ for (const logical of LOGICAL_OPERATORS) {
10667
10686
  if (filters[logical]) {
10668
10687
  filters[logical].conditions = filters[logical].conditions.map(
10669
10688
  (condition) => fn(condition)
@@ -10674,7 +10693,7 @@ function recurseLogicalOperators(filters, fn) {
10674
10693
  }
10675
10694
  function recurseSearchFilters(filters, processFn) {
10676
10695
  filters = processFn(filters);
10677
- for (const logical of Object.values(LogicalOperator)) {
10696
+ for (const logical of LOGICAL_OPERATORS) {
10678
10697
  if (filters[logical]) {
10679
10698
  filters[logical].conditions = filters[logical].conditions.map(
10680
10699
  (condition) => recurseSearchFilters(condition, processFn)
@@ -11137,7 +11156,9 @@ function runQuery(docs, query) {
11137
11156
  ).map(([key]) => {
11138
11157
  return filterFunctions[key]?.(doc) ?? false;
11139
11158
  });
11140
- if (query.allOr) {
11159
+ if (!hasFilters(query)) {
11160
+ return true;
11161
+ } else if (query.allOr) {
11141
11162
  return results.some((result) => result === true);
11142
11163
  } else {
11143
11164
  return results.every((result) => result === true);
@@ -11179,16 +11200,33 @@ var hasFilters = (query) => {
11179
11200
  if (!query) {
11180
11201
  return false;
11181
11202
  }
11182
- const skipped = ["allOr", "onEmptyFilter"];
11183
- for (let [key, value] of Object.entries(query)) {
11184
- if (skipped.includes(key) || typeof value !== "object") {
11185
- continue;
11203
+ const check = (filters) => {
11204
+ for (const logical of LOGICAL_OPERATORS) {
11205
+ if (filters[logical]) {
11206
+ for (const condition of filters[logical]?.conditions || []) {
11207
+ const result = check(condition);
11208
+ if (result) {
11209
+ return result;
11210
+ }
11211
+ }
11212
+ }
11186
11213
  }
11187
- if (Object.keys(value || {}).length !== 0) {
11188
- return true;
11214
+ for (const search2 of SEARCH_OPERATORS) {
11215
+ const searchValue = filters[search2];
11216
+ if (!searchValue || typeof searchValue !== "object") {
11217
+ continue;
11218
+ }
11219
+ const filtered = Object.entries(searchValue).filter((entry) => {
11220
+ const valueDefined = entry[1] !== void 0 || entry[1] !== null || entry[1] !== "";
11221
+ return search2 === "notEmpty" /* NOT_EMPTY */ || valueDefined;
11222
+ });
11223
+ if (filtered.length !== 0) {
11224
+ return true;
11225
+ }
11189
11226
  }
11190
- }
11191
- return false;
11227
+ return false;
11228
+ };
11229
+ return check(query);
11192
11230
  };
11193
11231
 
11194
11232
  // src/utils.ts