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

Method CompileOptions

ext/encoders.go:183–288  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

181}
182
183func (lib *encoderLib) CompileOptions() []cel.EnvOption {
184 opts := []cel.EnvOption{
185 cel.Function("base64.decode",
186 cel.Overload("base64_decode_string", []*cel.Type{cel.StringType}, cel.BytesType,
187 cel.UnaryBinding(func(str ref.Val) ref.Val {
188 s := str.(types.String)
189 return bytesOrError(base64DecodeString(string(s)))
190 }))),
191 cel.Function("base64.encode",
192 cel.Overload("base64_encode_bytes", []*cel.Type{cel.BytesType}, cel.StringType,
193 cel.UnaryBinding(func(bytes ref.Val) ref.Val {
194 b := bytes.(types.Bytes)
195 return stringOrError(base64EncodeBytes([]byte(b)))
196 }))),
197 }
198 if lib.version >= 1 {
199 opts = append(opts,
200 cel.CostModel(
201 base64DecodeCostModel("base64_decode_string"),
202 base64EncodeCostModel("base64_encode_bytes"),
203 unboundedCostModel("json_encode_dyn"),
204 ),
205 cel.Function("json.encode",
206 cel.Overload("json_encode_dyn", []*cel.Type{cel.DynType}, cel.StringType,
207 cel.UnaryBinding(func(val ref.Val) ref.Val {
208 return stringOrError(jsonEncodeValue(val))
209 }))),
210 )
211 }
212 if lib.version >= 2 {
213 var adapt types.Adapter = types.DefaultTypeAdapter
214 var prov types.Provider
215 opts = append(opts,
216 cel.CostModel(
217 base64DecodeCostModel("base64_decode_url_string"),
218 base64EncodeCostModel("base64_encode_url_bytes"),
219 unboundedCostModel("json_parse_string"),
220 unboundedCostModel("json_parse_string_type"),
221 unboundedCostModel("yaml_encode_dyn"),
222 unboundedCostModel("yaml_parse_string"),
223 unboundedCostModel("yaml_parse_string_type"),
224 ),
225 func(e *cel.Env) (*cel.Env, error) {
226 adapt = e.CELTypeAdapter()
227 prov = e.CELTypeProvider()
228 return e, nil
229 },
230 cel.Function("base64.decodeUrl",
231 cel.Overload("base64_decode_url_string", []*cel.Type{cel.StringType}, cel.BytesType,
232 cel.UnaryBinding(func(str ref.Val) ref.Val {
233 s := str.(types.String)
234 return bytesOrError(base64DecodeURLString(string(s)))
235 }))),
236 cel.Function("base64.encodeUrl",
237 cel.Overload("base64_encode_url_bytes", []*cel.Type{cel.BytesType}, cel.StringType,
238 cel.UnaryBinding(func(bytes ref.Val) ref.Val {
239 b := bytes.(types.Bytes)
240 return stringOrError(base64EncodeURLBytes([]byte(b)))

Callers 1

Calls 15

FunctionFunction · 0.92
OverloadFunction · 0.92
UnaryBindingFunction · 0.92
CostModelFunction · 0.92
NewTypeTypeWithParamFunction · 0.92
BinaryBindingFunction · 0.92
bytesOrErrorFunction · 0.85
base64DecodeStringFunction · 0.85
stringOrErrorFunction · 0.85
base64EncodeBytesFunction · 0.85
base64DecodeCostModelFunction · 0.85
base64EncodeCostModelFunction · 0.85

Tested by 1