google / cel-go

Fast, portable, non-Turing complete expression evaluation with gradual typing (Go)
https://cel.dev
Apache License 2.0
2.31k stars 225 forks source link

cel.Types and CustomTypeProvider #1053

Closed eddycharly closed 4 weeks ago

eddycharly commented 1 month ago

From the comment in cel.Types env option:

// Note: This option must be specified after the CustomTypeProvider option when used together.

But the implementation assumes the provider is a types.Registry. How can this happen after the CustomTypeProvider option ?

What am i missing here ?

TristonianJones commented 4 weeks ago

The implementation depends on support for registering protobuf types, but it doesn't strictly require the provider must be types.Registry.

If the CustomTypeProvider implements the following methods, then this option will still work:

// customTypeRegistry is an internal-only interface containing the minimum methods
// required to support custom types. It is a subset of methods from ref.TypeRegistry.
type customTypeRegistry interface {
    RegisterDescriptor(protoreflect.FileDescriptor) error
    RegisterType(...ref.Type) error
}

In terms of order of operations, you'd do the following:

cel.NewEnv(
  cel.CustomTypeProvider(<your-provider-here>),
  cel.Types(<your-types-here>),
)
eddycharly commented 4 weeks ago

Thanks but i still don't get why it must be specified after the CustomTypeProvider.

Is this supposed to be invalid ?

cel.NewEnv(
  cel.Types(<your-types-here>),
  cel.CustomTypeProvider(<your-provider-here>),
)