@budibase/shared-core 2.29.29 → 2.30.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.
package/dist/index.js CHANGED
@@ -10088,6 +10088,9 @@ var ArrayOperator = /* @__PURE__ */ ((ArrayOperator2) => {
10088
10088
  ArrayOperator2["ONE_OF"] = "oneOf";
10089
10089
  return ArrayOperator2;
10090
10090
  })(ArrayOperator || {});
10091
+ function isLogicalSearchOperator(value) {
10092
+ return value === "$and" /* AND */ || value === "$or" /* OR */;
10093
+ }
10091
10094
 
10092
10095
  // ../types/src/sdk/cli/constants.ts
10093
10096
  var AnalyticsEvent = {
@@ -10790,6 +10793,7 @@ var buildQuery = (filter) => {
10790
10793
  high: value
10791
10794
  };
10792
10795
  }
10796
+ } else if (isLogicalSearchOperator(queryOperator)) {
10793
10797
  } else if (query[queryOperator] && operator !== "onEmptyFilter") {
10794
10798
  if (type === "boolean") {
10795
10799
  if (queryOperator === "equal" && value === false) {
@@ -10859,14 +10863,15 @@ var runQuery = (docs, query) => {
10859
10863
  }
10860
10864
  const match = (type, test) => (doc) => {
10861
10865
  for (const [key, testValue] of Object.entries(query[type] || {})) {
10862
- const result = test(deepGet(doc, removeKeyNumbering(key)), testValue);
10866
+ const valueToCheck = isLogicalSearchOperator(type) ? doc : deepGet(doc, removeKeyNumbering(key));
10867
+ const result = test(valueToCheck, testValue);
10863
10868
  if (query.allOr && result) {
10864
10869
  return true;
10865
10870
  } else if (!query.allOr && !result) {
10866
10871
  return false;
10867
10872
  }
10868
10873
  }
10869
- return true;
10874
+ return !query.allOr;
10870
10875
  };
10871
10876
  const stringMatch = match(
10872
10877
  "string" /* STRING */,
@@ -11021,6 +11026,39 @@ var runQuery = (docs, query) => {
11021
11026
  }
11022
11027
  );
11023
11028
  const containsAny = match("containsAny" /* CONTAINS_ANY */, _contains("some"));
11029
+ const and = match(
11030
+ "$and" /* AND */,
11031
+ (docValue, conditions) => {
11032
+ if (!conditions.length) {
11033
+ return false;
11034
+ }
11035
+ for (const condition of conditions) {
11036
+ const matchesCondition = runQuery([docValue], condition);
11037
+ if (!matchesCondition.length) {
11038
+ return false;
11039
+ }
11040
+ }
11041
+ return true;
11042
+ }
11043
+ );
11044
+ const or = match(
11045
+ "$or" /* OR */,
11046
+ (docValue, conditions) => {
11047
+ if (!conditions.length) {
11048
+ return false;
11049
+ }
11050
+ for (const condition of conditions) {
11051
+ const matchesCondition = runQuery([docValue], {
11052
+ ...condition,
11053
+ allOr: true
11054
+ });
11055
+ if (matchesCondition.length) {
11056
+ return true;
11057
+ }
11058
+ }
11059
+ return false;
11060
+ }
11061
+ );
11024
11062
  const docMatch = (doc) => {
11025
11063
  const filterFunctions = {
11026
11064
  string: stringMatch,
@@ -11033,7 +11071,9 @@ var runQuery = (docs, query) => {
11033
11071
  oneOf,
11034
11072
  contains,
11035
11073
  containsAny,
11036
- notContains
11074
+ notContains,
11075
+ ["$and" /* AND */]: and,
11076
+ ["$or" /* OR */]: or
11037
11077
  };
11038
11078
  const results = Object.entries(query || {}).filter(
11039
11079
  ([key, value]) => !["allOr", "onEmptyFilter"].includes(key) && value && Object.keys(value).length > 0