(condition: ConditionExpr)
| 53 | throw new Error(`unexpected type "${String(expr)}"`); |
| 54 | }; |
| 55 | const convertCondition = (condition: ConditionExpr): CELExpr => { |
| 56 | if (isEqualityExpr(condition)) { |
| 57 | const { operator, args } = condition; |
| 58 | const [factor, value] = args; |
| 59 | return wrapCallExpr(operator, [ |
| 60 | wrapIdentExpr(factor), |
| 61 | wrapConstExpr(value), |
| 62 | ]); |
| 63 | } |
| 64 | if (isCompareExpr(condition)) { |
| 65 | const { operator, args } = condition; |
| 66 | const [factor, value] = args; |
| 67 | return wrapCallExpr(operator, [ |
| 68 | wrapIdentExpr(factor), |
| 69 | wrapConstExpr(value), |
| 70 | ]); |
| 71 | } |
| 72 | if (isStringExpr(condition)) { |
| 73 | const { operator, args } = condition; |
| 74 | const [factor, value] = args; |
| 75 | if (operator === "@not_contains") { |
| 76 | return wrapCallExpr("!_", [ |
| 77 | wrapCallExpr( |
| 78 | "contains", |
| 79 | [wrapConstExpr(value)], |
| 80 | wrapIdentExpr(factor) |
| 81 | ), |
| 82 | ]); |
| 83 | } |
| 84 | return wrapCallExpr( |
| 85 | operator, |
| 86 | [wrapConstExpr(value)], |
| 87 | wrapIdentExpr(factor) |
| 88 | ); |
| 89 | } |
| 90 | if (isCollectionExpr(condition)) { |
| 91 | const { operator, args } = condition; |
| 92 | const [factor, values] = args; |
| 93 | if (operator === "@not_in") { |
| 94 | return wrapCallExpr("!_", [ |
| 95 | wrapCallExpr("@in", [wrapIdentExpr(factor), wrapListExpr(values)]), |
| 96 | ]); |
| 97 | } |
| 98 | return wrapCallExpr(operator, [ |
| 99 | wrapIdentExpr(factor), |
| 100 | wrapListExpr(values), |
| 101 | ]); |
| 102 | } |
| 103 | throw new Error(`unsupported condition '${JSON.stringify(condition)}'`); |
| 104 | }; |
| 105 | const convertGroup = async ( |
| 106 | group: ConditionGroupExpr |
| 107 | ): Promise<CELExpr | undefined> => { |
no test coverage detected