Skip to content

Commit f0939a1

Browse files
Copilothotlong
andcommitted
Address code review comments: add documentation and fix 'in' operator
- Added JSDoc comments to matchesFilter and evaluateCondition methods - Fixed 'in' operator to return false when value is not an array - All tests still passing Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent f8bf528 commit f0939a1

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

packages/runtime/server/test/rest.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ class MockDriver implements Driver {
4545
return items;
4646
}
4747

48+
/**
49+
* Matches an item against a filter condition
50+
* @param item - The data item to test
51+
* @param filter - The filter in FilterNode array format or simple object format
52+
* FilterNode format: [field, op, value] for single condition
53+
* Complex filters: [[field, op, value], 'and', [field2, op2, value2]]
54+
* Simple format: { field: value }
55+
* @returns true if item matches the filter
56+
*/
4857
private matchesFilter(item: any, filter: any): boolean {
4958
if (!filter) return true;
5059

@@ -88,6 +97,14 @@ class MockDriver implements Driver {
8897
return true;
8998
}
9099

100+
/**
101+
* Evaluates a single filter condition
102+
* @param item - The data item to test
103+
* @param field - The field name
104+
* @param op - The operator: '=', '!=', '>', '>=', '<', '<=', 'in'
105+
* @param value - The value to compare against
106+
* @returns true if the condition is satisfied
107+
*/
91108
private evaluateCondition(item: any, field: string, op: string, value: any): boolean {
92109
const fieldValue = item[field];
93110
switch (op) {
@@ -97,7 +114,7 @@ class MockDriver implements Driver {
97114
case '>=': return fieldValue >= value;
98115
case '<': return fieldValue < value;
99116
case '<=': return fieldValue <= value;
100-
case 'in': return Array.isArray(value) && value.includes(fieldValue);
117+
case 'in': return Array.isArray(value) ? value.includes(fieldValue) : false;
101118
default: return true;
102119
}
103120
}

0 commit comments

Comments
 (0)