-
Notifications
You must be signed in to change notification settings - Fork 793
Add length operator #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add length operator #1439
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ enum Operator { | |||||||||||||||||||||||||||||||||||||||||||||
| In = '$in', | ||||||||||||||||||||||||||||||||||||||||||||||
| NotIn = '$nin', | ||||||||||||||||||||||||||||||||||||||||||||||
| Regex = '$regex', | ||||||||||||||||||||||||||||||||||||||||||||||
| Length = '$length', | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Logical Operators | ||||||||||||||||||||||||||||||||||||||||||||||
| And = '$and', | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -125,6 +126,20 @@ export class ConditionalRouter { | |||||||||||||||||||||||||||||||||||||||||||||
| } catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| case Operator.Length: | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!Array.isArray(value)) return false; | ||||||||||||||||||||||||||||||||||||||||||||||
| // compareValue could be a number or an object like {$gt: 5} | ||||||||||||||||||||||||||||||||||||||||||||||
| if (typeof compareValue === 'number') { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (value.length !== compareValue) return false; | ||||||||||||||||||||||||||||||||||||||||||||||
| } else if ( | ||||||||||||||||||||||||||||||||||||||||||||||
| typeof compareValue === 'object' && | ||||||||||||||||||||||||||||||||||||||||||||||
| compareValue !== null | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| ) { | |
| ) { | |
| // Validate that compareValue contains at least one valid operator key before recursion | |
| const validOperators = [ | |
| Operator.Equal, | |
| Operator.NotEqual, | |
| Operator.GreaterThan, | |
| Operator.GreaterThanOrEqual, | |
| Operator.LessThan, | |
| Operator.LessThanOrEqual, | |
| Operator.In, | |
| Operator.NotIn, | |
| Operator.Regex, | |
| Operator.Length | |
| ]; | |
| const hasValidOperatorKey = Object.keys(compareValue).some((key) => | |
| validOperators.includes(key as Operator) | |
| ); | |
| if (!hasValidOperatorKey) { | |
| // Handle unexpected object type | |
| return false; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The direct numeric comparison using inequality (value.length !== compareValue) could be simplified by leveraging the existing operator evaluation logic. Consider using
!this.evaluateOperator({ [Operator.Eq]: compareValue }, value.length)to maintain consistency with the nested operator path and reduce code duplication.