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;
} else if (
typeof compareValue === 'object' &&
compareValue !== null
) {
// 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