@spacelr/sdk 0.10.9 → 0.10.10

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.mjs CHANGED
@@ -697,11 +697,28 @@ function isSupportedInClause(v) {
697
697
  const candidates = v["$in"];
698
698
  return Array.isArray(candidates) && candidates.every(isFiniteScalar);
699
699
  }
700
+ var MAX_WHERE_DEPTH = 10;
700
701
  function isMongoWhereFullySupported(where) {
702
+ return isSupportedWhereObject(where, 0);
703
+ }
704
+ function isSupportedWhereObject(where, depth) {
705
+ if (depth > MAX_WHERE_DEPTH) return false;
701
706
  for (const [key, value] of Object.entries(where)) {
707
+ if (key === "$and" || key === "$or") {
708
+ if (!Array.isArray(value) || value.length === 0) return false;
709
+ for (const clause of value) {
710
+ if (clause === null || typeof clause !== "object" || Array.isArray(clause)) {
711
+ return false;
712
+ }
713
+ if (!isSupportedWhereObject(clause, depth + 1)) {
714
+ return false;
715
+ }
716
+ }
717
+ continue;
718
+ }
719
+ if (key.startsWith("$")) return false;
702
720
  if (key.includes(".")) return false;
703
721
  if (RESERVED_PATH_SEGMENTS.has(key)) return false;
704
- if (key.startsWith("$")) return false;
705
722
  if (isFiniteScalar(value)) continue;
706
723
  if (isSupportedInClause(value)) continue;
707
724
  return false;
@@ -710,6 +727,20 @@ function isMongoWhereFullySupported(where) {
710
727
  }
711
728
  function matchesMongoWhere(document2, where) {
712
729
  for (const [key, value] of Object.entries(where)) {
730
+ if (key === "$and") {
731
+ const clauses = value;
732
+ if (!clauses.every((clause) => matchesMongoWhere(document2, clause))) {
733
+ return false;
734
+ }
735
+ continue;
736
+ }
737
+ if (key === "$or") {
738
+ const clauses = value;
739
+ if (!clauses.some((clause) => matchesMongoWhere(document2, clause))) {
740
+ return false;
741
+ }
742
+ continue;
743
+ }
713
744
  const actual = resolveWherePath(document2, key);
714
745
  if (actual === WHERE_PATH_ABSENT || actual === WHERE_PATH_UNRESOLVABLE) {
715
746
  return false;