-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add optional params when there is a presence check #331
base: main
Are you sure you want to change the base?
Conversation
@@ -405,6 +415,12 @@ func translateRuleTS(rule *rulesv1beta3.Rule, usedVariables map[string]string) s | |||
case rulesv1beta3.ComparisonOperator_COMPARISON_OPERATOR_ENDS_WITH: | |||
usedVariables[v.Atom.ContextKey] = structpbValueToKindString(v.Atom.ComparisonValue) | |||
return fmt.Sprintf("(%s.endsWith(%s))", v.Atom.ContextKey, try.To1(marshalOptions.Marshal(v.Atom.ComparisonValue))) | |||
case rulesv1beta3.ComparisonOperator_COMPARISON_OPERATOR_PRESENT: |
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.
Is this sufficient?
Like what if I have:
if a.contains("foo")
return false
if a !== undefined
return true
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.
So you are saying we should always move the undefined check first? Or that logic above should not be allowed?
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.
I'm saying that in that particular situation, "a" should not be optional
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.
Let's merge this
Adds presence ts code gen
Makes params optional if there is a check for presence. Will use "string | boolean | number" type if there are no comparison values or grab the type from the usedVariables if it ever was compared to a value.
If there are any presence checks, we'll use optional value safe methods on strings