@budibase/backend-core 2.29.30 → 2.30.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
@@ -54481,6 +54481,9 @@ var RangeOperator = /* @__PURE__ */ ((RangeOperator2) => {
54481
54481
  RangeOperator2["RANGE"] = "range";
54482
54482
  return RangeOperator2;
54483
54483
  })(RangeOperator || {});
54484
+ function isLogicalSearchOperator(value) {
54485
+ return value === "$and" /* AND */ || value === "$or" /* OR */;
54486
+ }
54484
54487
 
54485
54488
  // ../types/src/sdk/db.ts
54486
54489
  var isDocument = (doc) => {
@@ -55252,6 +55255,7 @@ var buildQuery = (filter) => {
55252
55255
  high: value
55253
55256
  };
55254
55257
  }
55258
+ } else if (isLogicalSearchOperator(queryOperator)) {
55255
55259
  } else if (query[queryOperator] && operator !== "onEmptyFilter") {
55256
55260
  if (type === "boolean") {
55257
55261
  if (queryOperator === "equal" && value === false) {
@@ -55321,14 +55325,15 @@ var runQuery = (docs, query) => {
55321
55325
  }
55322
55326
  const match = (type, test) => (doc) => {
55323
55327
  for (const [key, testValue] of Object.entries(query[type] || {})) {
55324
- const result = test(deepGet(doc, removeKeyNumbering(key)), testValue);
55328
+ const valueToCheck = isLogicalSearchOperator(type) ? doc : deepGet(doc, removeKeyNumbering(key));
55329
+ const result = test(valueToCheck, testValue);
55325
55330
  if (query.allOr && result) {
55326
55331
  return true;
55327
55332
  } else if (!query.allOr && !result) {
55328
55333
  return false;
55329
55334
  }
55330
55335
  }
55331
- return true;
55336
+ return !query.allOr;
55332
55337
  };
55333
55338
  const stringMatch = match(
55334
55339
  "string" /* STRING */,
@@ -55483,6 +55488,39 @@ var runQuery = (docs, query) => {
55483
55488
  }
55484
55489
  );
55485
55490
  const containsAny = match("containsAny" /* CONTAINS_ANY */, _contains("some"));
55491
+ const and = match(
55492
+ "$and" /* AND */,
55493
+ (docValue, conditions) => {
55494
+ if (!conditions.length) {
55495
+ return false;
55496
+ }
55497
+ for (const condition of conditions) {
55498
+ const matchesCondition = runQuery([docValue], condition);
55499
+ if (!matchesCondition.length) {
55500
+ return false;
55501
+ }
55502
+ }
55503
+ return true;
55504
+ }
55505
+ );
55506
+ const or = match(
55507
+ "$or" /* OR */,
55508
+ (docValue, conditions) => {
55509
+ if (!conditions.length) {
55510
+ return false;
55511
+ }
55512
+ for (const condition of conditions) {
55513
+ const matchesCondition = runQuery([docValue], {
55514
+ ...condition,
55515
+ allOr: true
55516
+ });
55517
+ if (matchesCondition.length) {
55518
+ return true;
55519
+ }
55520
+ }
55521
+ return false;
55522
+ }
55523
+ );
55486
55524
  const docMatch = (doc) => {
55487
55525
  const filterFunctions = {
55488
55526
  string: stringMatch,
@@ -55495,7 +55533,9 @@ var runQuery = (docs, query) => {
55495
55533
  oneOf,
55496
55534
  contains,
55497
55535
  containsAny,
55498
- notContains
55536
+ notContains,
55537
+ ["$and" /* AND */]: and,
55538
+ ["$or" /* OR */]: or
55499
55539
  };
55500
55540
  const results = Object.entries(query || {}).filter(
55501
55541
  ([key, value]) => !["allOr", "onEmptyFilter"].includes(key) && value && Object.keys(value).length > 0
@@ -67995,6 +68035,22 @@ var InternalBuilder = class {
67995
68035
  });
67996
68036
  }
67997
68037
  };
68038
+ if (filters.$and) {
68039
+ const { $and } = filters;
68040
+ query = query.where((x) => {
68041
+ for (const condition of $and.conditions) {
68042
+ x = this.addFilters(x, condition, opts);
68043
+ }
68044
+ });
68045
+ }
68046
+ if (filters.$or) {
68047
+ const { $or } = filters;
68048
+ query = query.where((x) => {
68049
+ for (const condition of $or.conditions) {
68050
+ x = this.addFilters(x, { ...condition, allOr: true }, opts);
68051
+ }
68052
+ });
68053
+ }
67998
68054
  if (filters.oneOf) {
67999
68055
  const fnc = allOr ? "orWhereIn" : "whereIn";
68000
68056
  iterate(