@tanstack/db 0.5.27 → 0.5.29

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.
@@ -87,6 +87,24 @@ function isWhereSubsetInternal(
87
87
  )
88
88
  }
89
89
 
90
+ // Handle OR in subset: (A OR B) ⊆ C only if both A ⊆ C and B ⊆ C.
91
+ // Must be checked before OR superset so that or(A, B) ⊆ or(C, D)
92
+ // decomposes the subset first: A ⊆ or(C, D) AND B ⊆ or(C, D).
93
+ if (subset.type === `func` && subset.name === `or`) {
94
+ return subset.args.every((arg) =>
95
+ isWhereSubsetInternal(arg as BasicExpression<boolean>, superset),
96
+ )
97
+ }
98
+
99
+ // Handle OR in superset: subset ⊆ (A OR B) if subset ⊆ A or subset ⊆ B.
100
+ // Must be checked before decomposing AND subsets so that and(A, B) can
101
+ // match a structurally equal disjunct via areExpressionsEqual.
102
+ if (superset.type === `func` && superset.name === `or`) {
103
+ return superset.args.some((arg) =>
104
+ isWhereSubsetInternal(subset, arg as BasicExpression<boolean>),
105
+ )
106
+ }
107
+
90
108
  // Handle subset being an AND: (A AND B) implies both A and B
91
109
  if (subset.type === `func` && subset.name === `and`) {
92
110
  // For (A AND B) ⊆ C, since (A AND B) implies A, we check if any conjunct implies C
@@ -111,22 +129,6 @@ function isWhereSubsetInternal(
111
129
  }
112
130
  }
113
131
 
114
- // Handle OR in subset: (A OR B) is subset of C only if both A and B are subsets of C
115
- if (subset.type === `func` && subset.name === `or`) {
116
- return subset.args.every((arg) =>
117
- isWhereSubsetInternal(arg as BasicExpression<boolean>, superset),
118
- )
119
- }
120
-
121
- // Handle OR in superset: subset ⊆ (A OR B) if subset ⊆ A or subset ⊆ B
122
- // (A OR B) as superset means data can satisfy A or B
123
- // If subset is contained in any disjunct, it's contained in the union
124
- if (superset.type === `func` && superset.name === `or`) {
125
- return superset.args.some((arg) =>
126
- isWhereSubsetInternal(subset, arg as BasicExpression<boolean>),
127
- )
128
- }
129
-
130
132
  // Handle comparison operators on the same field
131
133
  if (subset.type === `func` && superset.type === `func`) {
132
134
  const subsetFunc = subset as Func