Skip to content

Commit 68abbf1

Browse files
Copilothotlong
andcommitted
fix: Improve filter translation logic and documentation
- Fix multiple operators on same field (always AND them together) - Remove $not from type documentation - Clarify range operators use $gte/$lte not $between - All 290 tests passing Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 7f218bd commit 68abbf1

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/foundation/core/src/repository.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ export class ObjectRepository {
109109
if (value === null || value === undefined) {
110110
nodes.push([field, '=', value]);
111111
} else if (typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
112-
// Explicit operators
113-
for (const [op, opValue] of Object.entries(value)) {
114-
if (nodes.length > 0 && nodes[nodes.length - 1] !== 'and') {
112+
// Explicit operators - multiple operators on same field are AND-ed together
113+
const entries = Object.entries(value);
114+
for (let i = 0; i < entries.length; i++) {
115+
const [op, opValue] = entries[i];
116+
117+
// Add 'and' before each operator (except the very first node)
118+
if (nodes.length > 0 || i > 0) {
115119
nodes.push('and');
116120
}
117121

packages/foundation/types/src/query.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import type { FilterCondition } from '@objectstack/spec';
1414
* Supports MongoDB/Prisma-style object-based syntax:
1515
* - Implicit equality: { field: value }
1616
* - Explicit operators: { field: { $eq: value, $gt: 10 } }
17-
* - Logical operators: { $and: [...], $or: [...], $not: {...} }
17+
* - Logical operators: { $and: [...], $or: [...] }
1818
* - String operators: { name: { $contains: "text" } }
19-
* - Range operators: { age: { $between: [18, 65] } }
19+
* - Range operators: { age: { $gte: 18, $lte: 65 } }
2020
* - Set operators: { status: { $in: ["active", "pending"] } }
2121
* - Null checks: { field: { $null: true } }
22+
*
23+
* Note: $not operator is not supported. Use $ne for field-level negation.
2224
*/
2325
export type Filter = FilterCondition;
2426

0 commit comments

Comments
 (0)