Debian Codegraph @

common/types/ref/provider.go

raw symbols SCIP
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package ref
16
17 import (
18 "google.golang.org/protobuf/proto"
19 "google.golang.org/protobuf/reflect/protoreflect"
20
21 exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
22 )
23
24 // TypeProvider specifies functions for creating new object instances and for
25 // resolving enum values by name.
26 //
27 // Deprecated: use types.Provider
28 type TypeProvider interface {
29 // EnumValue returns the numeric value of the given enum value name.
30 EnumValue(enumName string) Val
31
32 // FindIdent takes a qualified identifier name and returns a Value if one exists.
33 FindIdent(identName string) (Val, bool)
34
35 // FindType looks up the Type given a qualified typeName. Returns false if not found.
36 FindType(typeName string) (*exprpb.Type, bool)
37
38 // FieldFieldType returns the field type for a checked type value. Returns false if
39 // the field could not be found.
40 FindFieldType(messageType, fieldName string) (*FieldType, bool)
41
42 // NewValue creates a new type value from a qualified name and map of field name
43 // to value.
44 //
45 // Note, for each value, the Val.ConvertToNative function will be invoked to convert
46 // the Val to the field's native type. If an error occurs during conversion, the
47 // NewValue will be a types.Err.
48 NewValue(typeName string, fields map[string]Val) Val
49 }
50
51 // TypeAdapter converts native Go values of varying type and complexity to equivalent CEL values.
52 //
53 // Deprecated: use types.Adapter
54 type TypeAdapter interface {
55 // NativeToValue converts the input `value` to a CEL `ref.Val`.
56 NativeToValue(value any) Val
57 }
58
59 // TypeRegistry allows third-parties to add custom types to CEL. Not all `TypeProvider`
60 // implementations support type-customization, so these features are optional. However, a
61 // `TypeRegistry` should be a `TypeProvider` and a `TypeAdapter` to ensure that types
62 // which are registered can be converted to CEL representations.
63 //
64 // Deprecated: use types.Registry
65 type TypeRegistry interface {
66 TypeAdapter
67 TypeProvider
68
69 // RegisterDescriptor registers the contents of a protocol buffer `FileDescriptor`.
70 RegisterDescriptor(fileDesc protoreflect.FileDescriptor) error
71
72 // RegisterMessage registers a protocol buffer message and its dependencies.
73 RegisterMessage(message proto.Message) error
74
75 // RegisterType registers a type value with the provider which ensures the
76 // provider is aware of how to map the type to an identifier.
77 //
78 // If a type is provided more than once with an alternative definition, the
79 // call will result in an error.
80 RegisterType(types ...Type) error
81 }
82
83 // FieldType represents a field's type value and whether that field supports
84 // presence detection.
85 //
86 // Deprecated: use types.FieldType
87 type FieldType struct {
88 // Type of the field as a protobuf type value.
89 Type *exprpb.Type
90
91 // IsSet indicates whether the field is set on an input object.
92 IsSet FieldTester
93
94 // GetFrom retrieves the field value on the input object, if set.
95 GetFrom FieldGetter
96 }
97
98 // FieldTester is used to test field presence on an input object.
99 type FieldTester func(target any) bool
100
101 // FieldGetter is used to get the field value from an input object, if set.
102 type FieldGetter func(target any) (any, error)