MCPcopy Create free account
hub / github.com/bytebase/bytebase / dfs

Function dfs

frontend/src/plugins/cel/logic/resolve.ts:80–133  ·  view source on GitHub ↗
(expr: CELExpr, negative: boolean = false)

Source from the content-addressed store, hash-verified

78// Convert common expr to simple expr
79export const resolveCELExpr = (expr: CELExpr): SimpleExpr => {
80 const dfs = (expr: CELExpr, negative: boolean = false): SimpleExpr => {
81 if (expr.exprKind?.case !== "callExpr") {
82 // If no callExpr, we treat it as a raw string.
83 return resolveRawStringExpr(expr);
84 }
85 const callExpr = expr.exprKind.value;
86
87 try {
88 const { args } = callExpr;
89 const operator = callExpr.function as Operator;
90 if (isLogicalOperator(operator)) {
91 const group: ConditionGroupExpr = {
92 type: ExprType.ConditionGroup,
93 operator,
94 args: [],
95 };
96 const [left, right] = args;
97 const sub = (subTree: CELExpr, expand: boolean) => {
98 const subExpr = dfs(subTree);
99 if (
100 expand &&
101 isConditionGroupExpr(subExpr) &&
102 subExpr.operator === operator
103 ) {
104 group.args.push(...subExpr.args);
105 } else {
106 group.args.push(subExpr);
107 }
108 };
109 sub(left, true);
110 sub(right, false);
111 return group;
112 }
113 if (isNegativeOperator(operator)) {
114 return dfs(args[0], true);
115 }
116 if (isEqualityOperator(operator)) {
117 return resolveEqualityExpr(expr);
118 }
119 if (isCompareOperator(operator)) {
120 return resolveCompareExpr(expr);
121 }
122 if (isStringOperator(operator)) {
123 return resolveStringExpr(expr, negative);
124 }
125 if (isCollectionOperator(operator)) {
126 return resolveCollectionExpr(expr, negative);
127 }
128 throw new Error(`unsupported expr "${JSON.stringify(expr)}"`);
129 } catch {
130 // Any error occurs, we treat it as a raw string.
131 return resolveRawStringExpr(expr);
132 }
133 };
134 return dfs(expr);
135};
136

Callers 2

subFunction · 0.85
resolveCELExprFunction · 0.85

Calls 12

isLogicalOperatorFunction · 0.90
isNegativeOperatorFunction · 0.90
isEqualityOperatorFunction · 0.90
isCompareOperatorFunction · 0.90
isStringOperatorFunction · 0.90
isCollectionOperatorFunction · 0.90
resolveRawStringExprFunction · 0.85
subFunction · 0.85
resolveEqualityExprFunction · 0.85
resolveCompareExprFunction · 0.85
resolveStringExprFunction · 0.85
resolveCollectionExprFunction · 0.85

Tested by

no test coverage detected