const optMapMacro … const optFlatMapMacro … const hasValueFunc … const optionalNoneFunc … const optionalOfFunc … const optionalOfNonZeroValueFunc … const valueFunc … const unusedIterVar … type Library … type SingletonLibrary … // Lib creates an EnvOption out of a Library, allowing libraries to be provided as functional args, // and to be linked to each other. func Lib(l Library) EnvOption { … } // StdLib returns an EnvOption for the standard library of CEL functions and macros. func StdLib() EnvOption { … } type stdLibrary … // LibraryName implements the SingletonLibrary interface method. func (stdLibrary) LibraryName() string { … } // CompileOptions returns options for the standard CEL function declarations and macros. func (stdLibrary) CompileOptions() []EnvOption { … } // ProgramOptions returns function implementations for the standard CEL functions. func (stdLibrary) ProgramOptions() []ProgramOption { … } // OptionalTypes enable support for optional syntax and types in CEL. // // The optional value type makes it possible to express whether variables have // been provided, whether a result has been computed, and in the future whether // an object field path, map key value, or list index has a value. // // # Syntax Changes // // OptionalTypes are unlike other CEL extensions because they modify the CEL // syntax itself, notably through the use of a `?` preceding a field name or // index value. // // ## Field Selection // // The optional syntax in field selection is denoted as `obj.?field`. In other // words, if a field is set, return `optional.of(obj.field)“, else // `optional.none()`. The optional field selection is viral in the sense that // after the first optional selection all subsequent selections or indices // are treated as optional, i.e. the following expressions are equivalent: // // obj.?field.subfield // obj.?field.?subfield // // ## Indexing // // Similar to field selection, the optional syntax can be used in index // expressions on maps and lists: // // list[?0] // map[?key] // // ## Optional Field Setting // // When creating map or message literals, if a field may be optionally set // based on its presence, then placing a `?` before the field name or key // will ensure the type on the right-hand side must be optional(T) where T // is the type of the field or key-value. // // The following returns a map with the key expression set only if the // subfield is present, otherwise an empty map is created: // // {?key: obj.?field.subfield} // // ## Optional Element Setting // // When creating list literals, an element in the list may be optionally added // when the element expression is preceded by a `?`: // // [a, ?b, ?c] // return a list with either [a], [a, b], [a, b, c], or [a, c] // // # Optional.Of // // Create an optional(T) value of a given value with type T. // // optional.of(10) // // # Optional.OfNonZeroValue // // Create an optional(T) value of a given value with type T if it is not a // zero-value. A zero-value the default empty value for any given CEL type, // including empty protobuf message types. If the value is empty, the result // of this call will be optional.none(). // // optional.ofNonZeroValue([1, 2, 3]) // optional(list(int)) // optional.ofNonZeroValue([]) // optional.none() // optional.ofNonZeroValue(0) // optional.none() // optional.ofNonZeroValue("") // optional.none() // // # Optional.None // // Create an empty optional value. // // # HasValue // // Determine whether the optional contains a value. // // optional.of(b'hello').hasValue() // true // optional.ofNonZeroValue({}).hasValue() // false // // # Value // // Get the value contained by the optional. If the optional does not have a // value, the result will be a CEL error. // // optional.of(b'hello').value() // b'hello' // optional.ofNonZeroValue({}).value() // error // // # Or // // If the value on the left-hand side is optional.none(), the optional value // on the right hand side is returned. If the value on the left-hand set is // valued, then it is returned. This operation is short-circuiting and will // only evaluate as many links in the `or` chain as are needed to return a // non-empty optional value. // // obj.?field.or(m[?key]) // l[?index].or(obj.?field.subfield).or(obj.?other) // // # OrValue // // Either return the value contained within the optional on the left-hand side // or return the alternative value on the right hand side. // // m[?key].orValue("none") // // # OptMap // // Apply a transformation to the optional's underlying value if it is not empty // and return an optional typed result based on the transformation. The // transformation expression type must return a type T which is wrapped into // an optional. // // msg.?elements.optMap(e, e.size()).orValue(0) // // # OptFlatMap // // Introduced in version: 1 // // Apply a transformation to the optional's underlying value if it is not empty // and return the result. The transform expression must return an optional(T) // rather than type T. This can be useful when dealing with zero values and // conditionally generating an empty or non-empty result in ways which cannot // be expressed with `optMap`. // // msg.?elements.optFlatMap(e, e[?0]) // return the first element if present. func OptionalTypes(opts ...OptionalTypesOption) EnvOption { … } type optionalLib … type OptionalTypesOption … // OptionalTypesVersion configures the version of the optional type library. // // The version limits which functions are available. Only functions introduced // below or equal to the given version included in the library. If this option // is not set, all functions are available. // // See the library documentation to determine which version a function was introduced. // If the documentation does not state which version a function was introduced, it can // be assumed to be introduced at version 0, when the library was first created. func OptionalTypesVersion(version uint32) OptionalTypesOption { … } // LibraryName implements the SingletonLibrary interface method. func (lib *optionalLib) LibraryName() string { … } // CompileOptions implements the Library interface method. func (lib *optionalLib) CompileOptions() []EnvOption { … } // ProgramOptions implements the Library interface method. func (lib *optionalLib) ProgramOptions() []ProgramOption { … } func optMap(meh MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Expr, *Error) { … } func optFlatMap(meh MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Expr, *Error) { … } func enableOptionalSyntax() EnvOption { … } // EnableErrorOnBadPresenceTest enables error generation when a presence test or optional field // selection is performed on a primitive type. func EnableErrorOnBadPresenceTest(value bool) EnvOption { … } func decorateOptionalOr(i interpreter.Interpretable) (interpreter.Interpretable, error) { … } type evalOptionalOr … // ID implements the Interpretable interface method. func (opt *evalOptionalOr) ID() int64 { … } // Eval evaluates the left-hand side optional to determine whether it contains a value, else // proceeds with the right-hand side evaluation. func (opt *evalOptionalOr) Eval(ctx interpreter.Activation) ref.Val { … } type evalOptionalOrValue … // ID implements the Interpretable interface method. func (opt *evalOptionalOrValue) ID() int64 { … } // Eval evaluates the left-hand side optional to determine whether it contains a value, else // proceeds with the right-hand side evaluation. func (opt *evalOptionalOrValue) Eval(ctx interpreter.Activation) ref.Val { … } type timeUTCLibrary … func (timeUTCLibrary) CompileOptions() []EnvOption { … } func (timeUTCLibrary) ProgramOptions() []ProgramOption { … } var utcTZ … var timeOverloadDeclarations … func timestampGetFullYear(ts, tz ref.Val) ref.Val { … } func timestampGetMonth(ts, tz ref.Val) ref.Val { … } func timestampGetDayOfYear(ts, tz ref.Val) ref.Val { … } func timestampGetDayOfMonthZeroBased(ts, tz ref.Val) ref.Val { … } func timestampGetDayOfMonthOneBased(ts, tz ref.Val) ref.Val { … } func timestampGetDayOfWeek(ts, tz ref.Val) ref.Val { … } func timestampGetHours(ts, tz ref.Val) ref.Val { … } func timestampGetMinutes(ts, tz ref.Val) ref.Val { … } func timestampGetSeconds(ts, tz ref.Val) ref.Val { … } func timestampGetMilliseconds(ts, tz ref.Val) ref.Val { … } func inTimeZone(ts, tz ref.Val) (time.Time, error) { … }