AsCELFunction converts the serializable form of the Function into CEL environment declaration.
(tp types.Provider)
| 376 | |
| 377 | // AsCELFunction converts the serializable form of the Function into CEL environment declaration. |
| 378 | func (fn *Function) AsCELFunction(tp types.Provider) (*decls.FunctionDecl, error) { |
| 379 | if err := fn.Validate(); err != nil { |
| 380 | return nil, err |
| 381 | } |
| 382 | opts := make([]decls.FunctionOpt, 0, len(fn.Overloads)+1) |
| 383 | for _, o := range fn.Overloads { |
| 384 | opt, err := o.AsFunctionOption(tp) |
| 385 | opts = append(opts, opt) |
| 386 | if err != nil { |
| 387 | return nil, fmt.Errorf("invalid function %q: %w", fn.Name, err) |
| 388 | } |
| 389 | } |
| 390 | if len(fn.Description) != 0 { |
| 391 | opts = append(opts, decls.FunctionDocs(fn.Description)) |
| 392 | } |
| 393 | return decls.NewFunction(fn.Name, opts...) |
| 394 | } |
| 395 | |
| 396 | // NewOverload returns a new serializable representation of a global overload. |
| 397 | func NewOverload(id string, args []*TypeDesc, ret *TypeDesc, examples ...string) *Overload { |