celext

package
v0.0.0-...-7b48451 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package celext provides extensions to ease use of maps in CEL programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lib

func Lib(log *slog.Logger) cel.EnvOption

Lib returns a cel.EnvOption to configure extended functions to ease use of maps and timestamps.

As (Macro)

The as macro is syntactic sugar for [val].map(var, function)[0].

Examples:

{"a":1, "b":2}.as(v, v.a == 1)         // return true
{"a":1, "b":2}.as(v, v)                // return {"a":1, "b":2}
{"a":1, "b":2}.as(v, v.with({"c":3}))  // return {"a":1, "b":2, "c":3}
{"a":1, "b":2}.as(v, [v, v])           // return [{"a":1, "b":2}, {"a":1, "b":2}]

With

Returns the receiver's value with the value of the parameter updating or adding fields:

<map<K,V>>.with(<map<K,V>>) -> <map<K,V>>

Examples:

{"a":1, "b":2}.with({"a":10, "c":3})  // return {"a":10, "b":2, "c":3}

With Replace

Returns the receiver's value with the value of the parameter replacing existing fields:

<map<K,V>>.with_replace(<map<K,V>>) -> <map<K,V>>

Examples:

{"a":1, "b":2}.with_replace({"a":10, "c":3})  // return {"a":10, "b":2}

With Update

Returns the receiver's value with the value of the parameter updating the map without replacing any existing fields:

<map<K,V>>.with_update(<map<K,V>>) -> <map<K,V>>

Examples:

{"a":1, "b":2}.with_update({"a":10, "c":3})  // return {"a":1, "b":2, "c":3}

Is Zero

Returns whether the receiver is the zero time:

<timestamp>.is_zero() -> <bool>

Examples:

timestamp("0001-01-01T00:00:00Z").is_zero()  // return true
timestamp("0001-01-01T00:00:01Z").is_zero()  // return false

Debug

The second parameter is returned unaltered and the value is logged to the lib's logger:

debug(<string>, <dyn>) -> <dyn>

Examples:

debug("tag", expr) // return expr even if it is an error and logs with "tag".

func StateLib

func StateLib(ctx context.Context, uid rpc.UID, conn *jsonrpc2.Connection, log *slog.Logger) cel.EnvOption

StateLib returns a cel.EnvOption to configure extended functions to allow access to the rpc kernel state store get RPC call method over the provided JSON-RPC2.0 connection.

Get State

The parameter is the key to the value stored in the state store for the service configured with the UID:

get_state(<string>) -> <optional<bytes>>

Examples:

get_state("key") -> optional.of(b"value")
get_state("missing key") -> optional.none

Types

This section is empty.

Jump to

Keyboard shortcuts

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