1
0
Fork 0
mirror of synced 2024-07-12 17:56:07 +12:00

More progress.

This commit is contained in:
Sam Rose 2024-06-12 18:07:46 +01:00
parent 22bf0d05ad
commit 7e69f85e77
No known key found for this signature in database
2 changed files with 20 additions and 2 deletions

View file

@ -1279,6 +1279,8 @@ describe.each([
{ numbers: ["three"] },
]))
// Not sure if this is correct behaviour but changing it would be a
// breaking change.
it("finds all with empty list", () =>
expectQuery({ notContains: { numbers: [] } }).toContainExactly([
{ numbers: ["one", "two"] },

View file

@ -425,10 +425,26 @@ export const runQuery = (
return testValue[f](item => _valueMatches(docValue, item))
}
const contains = match(SearchFilterOperator.CONTAINS, _contains("every"))
const contains = match(
SearchFilterOperator.CONTAINS,
(docValue: any, testValue: any) => {
if (Array.isArray(testValue) && testValue.length === 0) {
return true
}
return _contains("every")(docValue, testValue)
}
)
const notContains = match(
SearchFilterOperator.NOT_CONTAINS,
not(_contains("every"))
(docValue: any, testValue: any) => {
// Not sure if this is logically correct, but at the time this code was
// written the search endpoint behaved this way and we wanted to make this
// local search match its behaviour, so we had to do this.
if (Array.isArray(testValue) && testValue.length === 0) {
return true
}
return not(_contains("every"))(docValue, testValue)
}
)
const containsAny = match(
SearchFilterOperator.CONTAINS_ANY,