MCPcopy Create free account
hub / github.com/cel-expr/cel-go / HasMacroExpander

Function HasMacroExpander

cel/macro.go:212–226  ·  view source on GitHub ↗

HasMacroExpander expands the input call arguments into a presence test, e.g. has( .field)

(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr)

Source from the content-addressed store, hash-verified

210
211// HasMacroExpander expands the input call arguments into a presence test, e.g. has(<operand>.field)
212func HasMacroExpander(meh MacroExprHelper, target *exprpb.Expr, args []*exprpb.Expr) (*exprpb.Expr, *Error) {
213 ph, err := toParserHelper(meh)
214 if err != nil {
215 return nil, err
216 }
217 arg, err := adaptToExpr(args[0])
218 if err != nil {
219 return nil, err
220 }
221 if arg.Kind() == ast.SelectKind {
222 s := arg.AsSelect()
223 return adaptToProto(ph.NewPresenceTest(s.Operand(), s.FieldName()))
224 }
225 return nil, ph.NewError(arg.ID(), "invalid argument to has() macro")
226}
227
228// ExistsMacroExpander expands the input call arguments into a comprehension that returns true if any of the
229// elements in the range match the predicate expressions:

Callers 1

TestCustomExistsMacroFunction · 0.85

Calls 10

toParserHelperFunction · 0.85
adaptToExprFunction · 0.85
adaptToProtoFunction · 0.85
KindMethod · 0.65
AsSelectMethod · 0.65
NewPresenceTestMethod · 0.65
OperandMethod · 0.65
FieldNameMethod · 0.65
NewErrorMethod · 0.65
IDMethod · 0.65

Tested by 1

TestCustomExistsMacroFunction · 0.68