library

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON added in v0.2.0

func JSON(options ...JSONOption) cel.EnvOption

JSON returns a CEL library that provides JSON parsing functions.

Library functions:

json.unmarshal() parses a JSON string and returns the parsed value.

The function takes one argument: - jsonString: a string containing JSON

Returns a dynamic type that can be: - map for JSON objects - list for JSON arrays - string, int, double, bool for JSON primitives - null for JSON null

Example usage:

json.unmarshal('{"name": "test"}').name
json.unmarshal('[1,2,3]')[0]
json.unmarshal(schema.spec.config).enabled

json.marshal() converts a CEL value to a JSON string.

The function takes one argument: - value: any CEL value (map, list, string, number, bool, null)

Returns a JSON string representation of the value.

Example usage:

json.marshal({"name": "test", "count": 42})
json.marshal([1, 2, 3])
json.marshal(schema.spec.config)

func Lists added in v0.2.0

func Lists(options ...ListsOption) cel.EnvOption

Lists returns a CEL library that provides index-mutation functions for lists. All functions are pure — they return a new list and do not modify the input.

SetAtIndex

Returns a new list with the element at index replaced by value. Index must be in [0, size(list)).

lists.setAtIndex(list(T), int, T) -> list(T)

Examples:

lists.setAtIndex([1, 2, 3], 1, 99)          // [1, 99, 3]
lists.setAtIndex(["a", "b", "c"], 0, "z")   // ["z", "b", "c"]

InsertAtIndex

Returns a new list with value inserted before the element at index. Index must be in [0, size(list)]. An index equal to size(list) appends.

lists.insertAtIndex(list(T), int, T) -> list(T)

Examples:

lists.insertAtIndex([1, 2, 3], 1, 99)   // [1, 99, 2, 3]
lists.insertAtIndex([1, 2, 3], 0, 99)   // [99, 1, 2, 3]
lists.insertAtIndex([1, 2, 3], 3, 99)   // [1, 2, 3, 99]

RemoveAtIndex

Returns a new list with the element at index removed. Index must be in [0, size(list)).

lists.removeAtIndex(list(T), int) -> list(T)

Examples:

lists.removeAtIndex([1, 2, 3], 1)   // [1, 3]
lists.removeAtIndex([1, 2, 3], 0)   // [2, 3]
lists.removeAtIndex([1, 2, 3], 2)   // [1, 2]

func Maps added in v0.2.0

func Maps(options ...MapsOption) cel.EnvOption

Maps returns a cel.EnvOption to configure extended functions for map manipulation.

Merge

Merges two maps. Keys from the second map overwrite already available keys in the first map. Keys must be of type string, value types must be identical in the maps merged.

map(string, T).merge(map(string, T)) -> map(string, T)

Examples:

{}.merge({}) == {}
{}.merge({'a': 1}) == {'a': 1}`},
{}.merge({'a': 2.1}) == {'a': 2.1}`},
{}.merge({'a': 'foo'}) == {'a': 'foo'}`},
{'a': 1}.merge({}) == {'a': 1}`},
{'a': 1}.merge({'b': 2}) == {'a': 1, 'b': 2}`},
{'a': 1}.merge({'a': 2, 'b': 2}) == {'a': 2, 'b': 2}`},

func Omit added in v0.2.0

func Omit() cel.EnvOption

Omit returns a cel.EnvOption that registers the omit() function.

omit() is a zero-argument function that returns a sentinel value. When the resolver encounters this sentinel as a field's resolved value, it removes the field (or array element) from the rendered object instead of writing it.

omit() is only valid in standalone template field expressions. It must not be used in includeWhen, readyWhen, forEach, or string template fragments.

Example usage:

policy: ${schema.spec.policy != "" ? schema.spec.policy : omit()}
scaling: ${schema.spec.autoscaling.enabled ? schema.spec.scaling : omit()}

func Random

func Random() cel.EnvOption

Random returns a CEL library that provides deterministic random generation functions.

Library functions:

random.seededString(length: int, seed: string) → string

Generates a deterministic random alphanumeric string of the given length using the seed. Same length and seed always produce the same string.

random.seededString(10, schema.metadata.uid)

random.seededInt(min: int, max: int, seed: string) → int

Generates a deterministic random integer in [min, max) using the seed. Same min, max, and seed always produce the same integer.

random.seededInt(30000, 32768, schema.metadata.uid)

Types

type JSONOption added in v0.2.0

type JSONOption func(*jsonLibrary) *jsonLibrary

JSONOption is a functional option for configuring the json library.

func JSONVersion added in v0.2.0

func JSONVersion(version uint32) JSONOption

JSONVersion configures the version of the json library.

type ListsOption added in v0.2.0

type ListsOption func(*listsLibrary) *listsLibrary

ListsOption is a functional option for configuring the lists library.

func ListsVersion added in v0.2.0

func ListsVersion(version uint32) ListsOption

ListsVersion configures the version of the lists library.

The version limits which functions are available. Only functions introduced below or equal to the given version are 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.

type MapsOption added in v0.2.0

type MapsOption func(*mapsLib) *mapsLib

func MapsVersion added in v0.2.0

func MapsVersion(version uint32) MapsOption

MapsVersion configures the version of the maps 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL