(expr: CELExpr)
| 167 | }; |
| 168 | |
| 169 | const resolveCompareExpr = (expr: CELExpr): CompareExpr => { |
| 170 | const callExpr = |
| 171 | expr.exprKind?.case === "callExpr" ? expr.exprKind.value : null; |
| 172 | if (!callExpr) |
| 173 | throw new Error(`Expected callExpr but got ${expr.exprKind?.case}`); |
| 174 | const operator = callExpr.function as CompareOperator; |
| 175 | const [factorExpr, valueExpr] = callExpr.args; |
| 176 | const factor = getFactorName(factorExpr); |
| 177 | if (isNumberFactor(factor)) { |
| 178 | return { |
| 179 | type: ExprType.Condition, |
| 180 | operator, |
| 181 | args: [factor, getConstantInt64Value(valueExpr)], |
| 182 | }; |
| 183 | } |
| 184 | if (isTimestampFactor(factor)) { |
| 185 | return { |
| 186 | type: ExprType.Condition, |
| 187 | operator, |
| 188 | args: [ |
| 189 | factor, |
| 190 | valueExpr.exprKind?.case === "callExpr" && |
| 191 | valueExpr.exprKind.value.args[0]?.exprKind?.case === "constExpr" |
| 192 | ? new Date(getConstantStringValue(valueExpr.exprKind.value.args[0])) |
| 193 | : new Date(), |
| 194 | ], |
| 195 | }; |
| 196 | } |
| 197 | throw new Error(`cannot resolve expr ${JSON.stringify(expr)}`); |
| 198 | }; |
| 199 | |
| 200 | const resolveStringExpr = ( |
| 201 | expr: CELExpr, |
no test coverage detected