@dataloop-ai/components 0.19.129 → 0.19.130
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/package.json +1 -1
- package/src/utils/parse-smart-query.ts +26 -17
package/package.json
CHANGED
|
@@ -85,7 +85,7 @@ export const parseSmartQuery = (
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const andQuery: { [key: string]: any } =
|
|
88
|
+
const andQuery: { [key: string]: any }[] = []
|
|
89
89
|
let queryValue: any
|
|
90
90
|
|
|
91
91
|
let key: string
|
|
@@ -106,42 +106,42 @@ export const parseSmartQuery = (
|
|
|
106
106
|
[key, value] = term.split('>=').map((x) => x.trim())
|
|
107
107
|
pureValue = GeneratePureValue(value)
|
|
108
108
|
if (pureValue !== null) {
|
|
109
|
-
andQuery[key]
|
|
109
|
+
andQuery.push({ [key]: { $gte: pureValue } })
|
|
110
110
|
}
|
|
111
111
|
break
|
|
112
112
|
case term.includes('<='):
|
|
113
113
|
[key, value] = term.split('<=').map((x) => x.trim())
|
|
114
114
|
pureValue = GeneratePureValue(value)
|
|
115
115
|
if (pureValue !== null) {
|
|
116
|
-
andQuery[key]
|
|
116
|
+
andQuery.push({ [key]: { $lte: pureValue } })
|
|
117
117
|
}
|
|
118
118
|
break
|
|
119
119
|
case term.includes('>'):
|
|
120
120
|
[key, value] = term.split('>').map((x) => x.trim())
|
|
121
121
|
pureValue = GeneratePureValue(value)
|
|
122
122
|
if (pureValue !== null) {
|
|
123
|
-
andQuery[key]
|
|
123
|
+
andQuery.push({ [key]: { $gt: pureValue } })
|
|
124
124
|
}
|
|
125
125
|
break
|
|
126
126
|
case term.includes('<'):
|
|
127
127
|
[key, value] = term.split('<').map((x) => x.trim())
|
|
128
128
|
pureValue = GeneratePureValue(value)
|
|
129
129
|
if (pureValue !== null) {
|
|
130
|
-
andQuery[key]
|
|
130
|
+
andQuery.push({ [key]: { $lt: pureValue } })
|
|
131
131
|
}
|
|
132
132
|
break
|
|
133
133
|
case term.includes('!='):
|
|
134
134
|
[key, value] = term.split('!=').map((x) => x.trim())
|
|
135
135
|
pureValue = GeneratePureValue(value)
|
|
136
136
|
if (pureValue !== null) {
|
|
137
|
-
andQuery[key]
|
|
137
|
+
andQuery.push({ [key]: { $ne: pureValue } })
|
|
138
138
|
}
|
|
139
139
|
break
|
|
140
140
|
case term.includes('='):
|
|
141
141
|
[key, value] = term.split('=').map((x) => x.trim())
|
|
142
142
|
pureValue = GeneratePureValue(value)
|
|
143
143
|
if (pureValue !== null) {
|
|
144
|
-
andQuery[key]
|
|
144
|
+
andQuery.push({ [key]: pureValue })
|
|
145
145
|
}
|
|
146
146
|
break
|
|
147
147
|
case term.includes('IN'):
|
|
@@ -159,7 +159,7 @@ export const parseSmartQuery = (
|
|
|
159
159
|
|
|
160
160
|
pureValue = GeneratePureValue(queryValue)
|
|
161
161
|
if (pureValue !== null && Array.isArray(pureValue)) {
|
|
162
|
-
andQuery[key]
|
|
162
|
+
andQuery.push({ [key]: { $nin: pureValue } })
|
|
163
163
|
}
|
|
164
164
|
} else {
|
|
165
165
|
queryValue = term
|
|
@@ -171,14 +171,24 @@ export const parseSmartQuery = (
|
|
|
171
171
|
|
|
172
172
|
pureValue = GeneratePureValue(queryValue)
|
|
173
173
|
if (pureValue !== null && Array.isArray(pureValue)) {
|
|
174
|
-
andQuery[key]
|
|
174
|
+
andQuery.push({ [key]: { $in: pureValue } })
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
break
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
const simlifiedAndQuery: { [key: string]: any } = {}
|
|
182
|
+
for (const term of andQuery) {
|
|
183
|
+
const key = Object.keys(term)[0]
|
|
184
|
+
simlifiedAndQuery[key] = term[key]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
orTerms.push(
|
|
188
|
+
andQuery.length > Object.keys(simlifiedAndQuery).length
|
|
189
|
+
? { $and: andQuery }
|
|
190
|
+
: simlifiedAndQuery
|
|
191
|
+
)
|
|
182
192
|
}
|
|
183
193
|
|
|
184
194
|
const builtQuery = orTerms.length > 1 ? { $or: orTerms } : orTerms[0]
|
|
@@ -211,14 +221,13 @@ export const stringifySmartQuery = (query: { [key: string]: any }): string => {
|
|
|
211
221
|
|
|
212
222
|
if (key === '$and') {
|
|
213
223
|
if (Array.isArray(value)) {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
return stringifySmartQuery(andObject)
|
|
224
|
+
const subQueries = value.map(
|
|
225
|
+
(subQuery: { [key: string]: any }) =>
|
|
226
|
+
stringifySmartQuery(subQuery)
|
|
227
|
+
)
|
|
228
|
+
result += subQueries.join(' AND ')
|
|
221
229
|
}
|
|
230
|
+
continue
|
|
222
231
|
}
|
|
223
232
|
|
|
224
233
|
if (result.length) {
|