Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/services/conditionalRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum Operator {
In = '$in',
NotIn = '$nin',
Regex = '$regex',
Length = '$length',

// Logical Operators
And = '$and',
Expand Down Expand Up @@ -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;
Copy link

Copilot AI Nov 21, 2025

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.

Suggested change
if (value.length !== compareValue) return false;
if (!this.evaluateOperator({ [Operator.Equal]: compareValue }, value.length)) return false;

Copilot uses AI. Check for mistakes.
} else if (
typeof compareValue === 'object' &&
compareValue !== null
) {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition checks if compareValue is an object and not null, but doesn't validate that it contains valid operator keys. Consider adding validation to ensure compareValue is a valid operator object before recursively evaluating, or handle the case where it might be an unexpected object type.

Suggested change
) {
) {
// 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;
}

Copilot uses AI. Check for mistakes.
// Recursively evaluate the length with other operators
if (!this.evaluateOperator(compareValue, value.length))
return false;
}
break;
default:
throw new Error(
`Unsupported operator used in the query router: ${op}`
Expand Down
Loading