Documentation
¶
Index ¶
- Constants
- func BuildPrefixTSQuery(query string) string
- func ComputeETag(m ETagResource) (string, error)
- func DeleteAnnotation(resource Annotatable, key string)
- func DeleteLabel(resource Labellable, key string)
- func GetAnnotation(resource Annotatable, key string) (string, bool)
- func GetLabel(resource Labellable, key string) (string, bool)
- func GetUUIDNamespace(msg proto.Message) (uuid.UUID, error)
- func HasAnnotation(resource Annotatable, key string) bool
- func HasLabel(resource Labellable, key string) bool
- func Iterator[T any](ctx context.Context, request, apiCallFunction any, opts ...grpc.CallOption) iter.Seq2[T, error]
- func LabelBool(b bool) string
- func MustGetUUIDNamespace(msg proto.Message) uuid.UUID
- func NamespacedLabels(resource Labellable) iter.Seq2[string, string]
- func NewDeterministicBase32ResourceID(namespace uuid.UUID, name string) string
- func NewFilterDeclarations(tree *Tree, withFQN bool) (declarations, macroDeclarations *filtering.Declarations, ...)
- func NewResourceCreatedEvent[R Resource](resource R) (*aippb.ResourceEvent, error)
- func NewResourceDeletedEvent[R Resource](resource R) (*aippb.ResourceEvent, error)
- func NewResourceUpdatedEvent[R Resource](resource, previousResource R, updateMask *fieldmaskpb.FieldMask) (*aippb.ResourceEvent, error)
- func NewSystemGeneratedBase32ResourceID() string
- func NewSystemGeneratedResourceID() string
- func PageIterator[T any](ctx context.Context, request, apiCallFunction any, opts ...grpc.CallOption) iter.Seq2[[]T, error]
- func Paginate[T any](ctx context.Context, request, apiCallFunction any, opts ...grpc.CallOption) ([]T, error)
- func ParseEventPreviousResource[R proto.Message](event *aippb.ResourceEvent) (R, error)
- func ParseEventResource[R proto.Message](event *aippb.ResourceEvent) (R, error)
- func SetAnnotation(resource Annotatable, key, value string)
- func SetLabel(resource Labellable, key, value string)
- type Annotatable
- type ETagResource
- type Enum
- type EnumMapping
- type FilteringRequest
- type FilteringRequestOpt
- type FilteringRequestParser
- type Labellable
- type ListRequestOpt
- type ListRequestParser
- type Node
- type OrderingRequest
- type OrderingRequestOpt
- type OrderingRequestParser
- type PaginatedRequest
- type PaginationOpt
- type PaginationRequestParser
- type ParsedListRequest
- type ParsedResource
- type ParsedSearchRequest
- type ParsedUpdateRequest
- type Resource
- type SearchRequestParser
- type Tree
- func (t *Tree) Add(n *Node)
- func (t *Tree) Explore(fieldPath string, fieldDesc protoreflect.FieldDescriptor, depth int) error
- func (t *Tree) FilterableNodes() iter.Seq[*Node]
- func (t *Tree) IsPathAllowed(node *Node) bool
- func (t *Tree) OrderableNodes() iter.Seq[*Node]
- func (t *Tree) SortAsc()
- func (t *Tree) UpdatableNodes() iter.Seq[*Node]
- type TreeConfig
- type TreeOption
- type UpdateRequestParser
Constants ¶
const ( LabelValueTrue = "true" LabelValueFalse = "false" )
Variables ¶
This section is empty.
Functions ¶
func BuildPrefixTSQuery ¶
BuildPrefixTSQuery normalizes a free-text query into a postgres tsquery expression (to be passed as a parameter to to_tsquery('simple', $n)). Tokens are lowercased, split on any non-alphanumeric rune — which also decomposes emails and phone numbers the way search documents index them — and AND-ed together with prefix matching, e.g. "John Smi" -> "john:* & smi:*". Returns "" when the query holds no token.
func ComputeETag ¶
func ComputeETag(m ETagResource) (string, error)
ComputeETag computes a deterministic ETag for a resource by hashing its serialized form, excluding update_time and etag fields to ensure the tag reflects only meaningful state changes.
func DeleteAnnotation ¶
func DeleteAnnotation(resource Annotatable, key string)
func DeleteLabel ¶
func DeleteLabel(resource Labellable, key string)
func GetAnnotation ¶
func GetAnnotation(resource Annotatable, key string) (string, bool)
func GetUUIDNamespace ¶
GetUUIDNamespace extracts the UUID namespace from a proto message's options. Returns an error if the namespace is not defined or is empty.
func HasAnnotation ¶
func HasAnnotation(resource Annotatable, key string) bool
func HasLabel ¶
func HasLabel(resource Labellable, key string) bool
func MustGetUUIDNamespace ¶
MustGetUUIDNamespace extracts the UUID namespace from a proto message's options. Panics if the namespace is not defined or is empty.
func NamespacedLabels ¶
func NamespacedLabels(resource Labellable) iter.Seq2[string, string]
func NewDeterministicBase32ResourceID ¶
NewDeterministicBase32ResourceID returns a deterministic base32-encoded resource ID derived from a namespace UUID and a name string using UUIDv5.
func NewFilterDeclarations ¶
func NewFilterDeclarations(tree *Tree, withFQN bool) (declarations, macroDeclarations *filtering.Declarations, macros []filtering.Macro, err error)
NewFilterDeclarations builds the filter declarations of a resource tree: idents matching proto field paths, macro idents matching database column references, and the macros rewriting the former into the latter. withFQN qualifies column references with their table (or join alias).
func NewResourceCreatedEvent ¶
func NewResourceCreatedEvent[R Resource](resource R) (*aippb.ResourceEvent, error)
NewResourceCreatedEvent constructs a ResourceCreatedEvent by marshaling the given resource into an Any.
func NewResourceDeletedEvent ¶
func NewResourceDeletedEvent[R Resource](resource R) (*aippb.ResourceEvent, error)
NewResourceDeletedEvent constructs a ResourceDeletedEvent by marshaling the given resource into an Any.
func NewResourceUpdatedEvent ¶
func NewResourceUpdatedEvent[R Resource](resource, previousResource R, updateMask *fieldmaskpb.FieldMask) (*aippb.ResourceEvent, error)
NewResourceUpdatedEvent constructs a ResourceUpdatedEvent by marshaling the current and previous resource into Any fields, along with the update mask describing which fields were modified.
func NewSystemGeneratedBase32ResourceID ¶
func NewSystemGeneratedBase32ResourceID() string
NewSystemGenerated returns a new system-generated resource ID encoded as base32 lowercase.
func NewSystemGeneratedResourceID ¶
func NewSystemGeneratedResourceID() string
NewSystemGenerated returns a new system-generated resource ID.
func PageIterator ¶
func PageIterator[T any](ctx context.Context, request, apiCallFunction any, opts ...grpc.CallOption) iter.Seq2[[]T, error]
PageIterator returns an iterator that yields slices of T, one per page.
func Paginate ¶
func Paginate[T any](ctx context.Context, request, apiCallFunction any, opts ...grpc.CallOption) ([]T, error)
Paginate abstracts the pagination logic for a given API and assumes that the request object has 'PageToken' and 'PageSize' fields, and the response object has a 'GetNextPageToken' method and an items field with a slice of items.
func ParseEventPreviousResource ¶
func ParseEventPreviousResource[R proto.Message](event *aippb.ResourceEvent) (R, error)
ParseEventPreviousResource extracts and unmarshals the previous resource from a ResourceEvent. Returns an error if the event type is not RESOURCE_EVENT_TYPE_UPDATED.
func ParseEventResource ¶
func ParseEventResource[R proto.Message](event *aippb.ResourceEvent) (R, error)
ParseEventResource extracts and unmarshals the resource from a ResourceEvent.
func SetAnnotation ¶
func SetAnnotation(resource Annotatable, key, value string)
func SetLabel ¶
func SetLabel(resource Labellable, key, value string)
Types ¶
type Annotatable ¶
type ETagResource ¶
type ETagResource interface {
proto.Message
GetEtag() string
GetUpdateTime() *timestamppb.Timestamp
}
A resource that has an etag field.
type Enum ¶
type Enum interface {
~int32
protoreflect.Enum
}
type EnumMapping ¶
type EnumMapping[E Enum] struct { // contains filtered or unexported fields }
func NewEnumMapping ¶
func NewEnumMapping[E Enum]() *EnumMapping[E]
func (*EnumMapping[E]) AllExternal ¶
func (m *EnumMapping[E]) AllExternal() []string
func (*EnumMapping[E]) FromExternal ¶
func (m *EnumMapping[E]) FromExternal(s string) (E, error)
func (*EnumMapping[E]) SliceToExternal ¶
func (m *EnumMapping[E]) SliceToExternal(enums []E) ([]string, error)
func (*EnumMapping[E]) ToExternal ¶
func (m *EnumMapping[E]) ToExternal(e E) (string, error)
type FilteringRequest ¶
type FilteringRequest struct {
// contains filtered or unexported fields
}
func (*FilteringRequest) GetFilter ¶
func (f *FilteringRequest) GetFilter() filtering.Filter
func (*FilteringRequest) GetSQLWhereClause ¶
func (f *FilteringRequest) GetSQLWhereClause() (string, []any)
type FilteringRequestOpt ¶
type FilteringRequestOpt func(*filteringRequestOpts)
func WithFQN ¶
func WithFQN() FilteringRequestOpt
WithFQN prepends table names to column references in generated SQL.
type FilteringRequestParser ¶
type FilteringRequestParser[T filteringRequest, R proto.Message] struct { // contains filtered or unexported fields }
func MustNewFilteringRequestParser ¶
func MustNewFilteringRequestParser[T filteringRequest, R proto.Message](opts ...FilteringRequestOpt) *FilteringRequestParser[T, R]
func NewFilteringRequestParser ¶
func NewFilteringRequestParser[T filteringRequest, R proto.Message](opts ...FilteringRequestOpt) (*FilteringRequestParser[T, R], error)
func (*FilteringRequestParser[T, R]) Parse ¶
func (p *FilteringRequestParser[T, R]) Parse(request T) (*FilteringRequest, error)
type Labellable ¶
type ListRequestOpt ¶
type ListRequestOpt func(*listRequestOpts)
///////////////////// OPTS /////////////////
func WithFilteringOpts ¶
func WithFilteringOpts(opts ...FilteringRequestOpt) ListRequestOpt
func WithOrderingOpts ¶
func WithOrderingOpts(opts ...OrderingRequestOpt) ListRequestOpt
func WithPaginationOpts ¶
func WithPaginationOpts(opts ...PaginationOpt) ListRequestOpt
type ListRequestParser ¶
type ListRequestParser[T listRequest[R], R proto.Message] struct { // contains filtered or unexported fields }
ListRequestParser implements aip parsing using composition of specialized parsers.
func MustNewListRequestParser ¶
func MustNewListRequestParser[T listRequest[R], R proto.Message](opts ...ListRequestOpt) *ListRequestParser[T, R]
MustNewListRequestParser instantiates a new list request parser, panicking on error.
func NewListRequestParser ¶
func NewListRequestParser[T listRequest[R], R proto.Message](opts ...ListRequestOpt) (*ListRequestParser[T, R], error)
NewListRequestParser instantiates a new list request parser composed of filtering, pagination, and ordering sub-parsers.
func (*ListRequestParser[T, R]) Parse ¶
func (p *ListRequestParser[T, R]) Parse(request T) (*ParsedListRequest, error)
Parse parses the given request. Any error should be returned as an InvalidArgument error.
type Node ¶
type Node struct {
Depth int
TableName string
ColumnName string
Path string
Nullable bool
ExprType *v1alpha1.Type
EnumType protoreflect.EnumType
AsJsonBytes bool
AsProtoBytes bool
FieldBehaviorSet map[annotationspb.FieldBehavior]struct{}
IsRepeated bool
IsMap bool
// Canonicalize holds the field's canonicalization rule (email/phone), if any.
Canonicalize *canonicalizepb.Field
// JoinTableName is set for fields populated via a JOIN; it holds the
// table qualifier the join is emitted under: the joined table's name for
// parent joins, the reference field name (join alias) for reference joins.
JoinTableName string
AllowedPath bool
ReplacementPath string
ReplacementPathRegexp *regexp.Regexp
}
Node represents a single field in the resource tree, carrying all metadata needed for SQL generation, filtering declarations, and update parsing.
func (*Node) ApplyReplacement ¶
ApplyReplacement replaces all occurrences of a field path in the clause with its replacement. The field is treated as an atomic unit — it matches only at word boundaries and is NOT followed by a dot (which would make it part of a longer path).
func (*Node) HasFieldBehavior ¶
func (n *Node) HasFieldBehavior(fb annotationspb.FieldBehavior) bool
HasFieldBehavior returns true if the node has the given field behavior annotation.
func (*Node) RootNodePath ¶
RootNodePath returns the top-level field name for a potentially nested path.
type OrderingRequest ¶
type OrderingRequest struct {
// contains filtered or unexported fields
}
////////////////////////////// PARSED REQUEST //////////////////////////
func (*OrderingRequest) GetOrderBy ¶
func (p *OrderingRequest) GetOrderBy() ordering.OrderBy
func (*OrderingRequest) GetSQLOrderByClause ¶
func (p *OrderingRequest) GetSQLOrderByClause() string
type OrderingRequestOpt ¶
type OrderingRequestOpt func(*orderingRequestOpts)
////////////////////////////// OPTS //////////////////////////
func WithOrderingFQN ¶
func WithOrderingFQN() OrderingRequestOpt
WithOrderingFQN prepends table names to column references in ORDER BY SQL.
type OrderingRequestParser ¶
type OrderingRequestParser[T orderingRequest, R proto.Message] struct { // contains filtered or unexported fields }
////////////////////////////// PARSER //////////////////////////
func MustNewOrderingRequestParser ¶
func MustNewOrderingRequestParser[T orderingRequest, R proto.Message](opts ...OrderingRequestOpt) *OrderingRequestParser[T, R]
func NewOrderingRequestParser ¶
func NewOrderingRequestParser[T orderingRequest, R proto.Message](opts ...OrderingRequestOpt) (*OrderingRequestParser[T, R], error)
func (*OrderingRequestParser[T, R]) Parse ¶
func (p *OrderingRequestParser[T, R]) Parse(request T) (*OrderingRequest, error)
type PaginatedRequest ¶
type PaginatedRequest struct {
// contains filtered or unexported fields
}
////////////////////////////// PARSED REQUEST //////////////////////////
func (*PaginatedRequest) GetNextPageToken ¶
func (r *PaginatedRequest) GetNextPageToken(itemsFetched int) string
func (*PaginatedRequest) GetOffset ¶
func (r *PaginatedRequest) GetOffset() int64
func (*PaginatedRequest) GetPageSize ¶
func (p *PaginatedRequest) GetPageSize() int32
func (*PaginatedRequest) GetSQLPaginationClause ¶
func (r *PaginatedRequest) GetSQLPaginationClause() string
type PaginationOpt ¶
type PaginationOpt func(*paginationOpts)
///////////////////// OPTS /////////////////
func WithSkipPageTokenDecoding ¶
func WithSkipPageTokenDecoding() PaginationOpt
type PaginationRequestParser ¶
type PaginationRequestParser[T paginationRequest] struct {
// contains filtered or unexported fields
}
////////////////////////////// PARSER //////////////////////////
func MustNewPaginationRequestParser ¶
func MustNewPaginationRequestParser[T paginationRequest](opts ...PaginationOpt) *PaginationRequestParser[T]
MustNewPaginationRequestParser instantiates a new pagination request parser, panicking on error.
func NewPaginationRequestParser ¶
func NewPaginationRequestParser[T paginationRequest](opts ...PaginationOpt) (*PaginationRequestParser[T], error)
NewPaginationRequestParser instantiates a new pagination request parser.
func (*PaginationRequestParser[T]) Parse ¶
func (p *PaginationRequestParser[T]) Parse(request T) (*PaginatedRequest, error)
type ParsedListRequest ¶
type ParsedListRequest struct {
*FilteringRequest
*PaginatedRequest
*OrderingRequest
}
ParsedListRequest embeds all the specialized parsed request types.
type ParsedResource ¶
type ParsedResource struct {
Desc *annotationspb.ResourceDescriptor
Type string
// Pattern is the first declared pattern.
Pattern string
// Patterns holds all declared patterns.
Patterns []string
Singular string
Plural string
Singleton bool
HasParent bool
// PatternVariables is the union of the variables across all patterns,
// ordered by first appearance, with the resource's own identifier last.
PatternVariables []string
}
func ParseResource ¶
func ParseResource(resourceDescriptor *annotationspb.ResourceDescriptor) (*ParsedResource, error)
ParseResource parses a resource descriptor into a structured ParsedResource. It validates the descriptor and extracts the union of pattern variables across all declared patterns. Multi-pattern singleton resources are not supported.
type ParsedSearchRequest ¶
type ParsedSearchRequest struct {
*FilteringRequest
*PaginatedRequest
// contains filtered or unexported fields
}
ParsedSearchRequest embeds all the specialized parsed request types.
func (*ParsedSearchRequest) GetQuery ¶
func (p *ParsedSearchRequest) GetQuery() string
GetQuery returns the raw search query.
func (*ParsedSearchRequest) GetTSQuery ¶
func (p *ParsedSearchRequest) GetTSQuery() string
GetTSQuery returns the postgres tsquery expression derived from the raw query, with prefix matching on every token. Returns "" when the query holds no indexable token.
type ParsedUpdateRequest ¶
type ParsedUpdateRequest struct {
// contains filtered or unexported fields
}
ParsedUpdateRequest is a request that is parsed.
func (*ParsedUpdateRequest) ApplyFieldMask ¶
func (p *ParsedUpdateRequest) ApplyFieldMask(existingResource, newResource proto.Message)
ApplyFieldMask merges any fields covered by the field mask from newResource into existingResource.
func (*ParsedUpdateRequest) GetSQLColumns ¶
func (p *ParsedUpdateRequest) GetSQLColumns() []string
func (*ParsedUpdateRequest) GetSQLUpdateClause ¶
func (p *ParsedUpdateRequest) GetSQLUpdateClause() string
func (*ParsedUpdateRequest) GetSQLUpsertClause ¶
func (p *ParsedUpdateRequest) GetSQLUpsertClause() string
type SearchRequestParser ¶
type SearchRequestParser[T searchRequest[R], R proto.Message] struct { // contains filtered or unexported fields }
SearchRequestParser implements aip parsing using composition of specialized parsers.
func MustNewSearchRequestParser ¶
func MustNewSearchRequestParser[T searchRequest[R], R proto.Message](opts ...FilteringRequestOpt) *SearchRequestParser[T, R]
func NewSearchRequestParser ¶
func NewSearchRequestParser[T searchRequest[R], R proto.Message](opts ...FilteringRequestOpt) (*SearchRequestParser[T, R], error)
NewSearchRequestParser instantiates and returns a new parser.
func (*SearchRequestParser[T, R]) Parse ¶
func (p *SearchRequestParser[T, R]) Parse(request T) (*ParsedSearchRequest, error)
Parse parses the given request. Any error should be returned as an InvalidArgument error.
type Tree ¶
type Tree struct {
Config *TreeConfig
Resource *ParsedResource
AllowAllPaths bool
AllowedPathSet map[string]struct{}
Nodes []*Node
IDColumnName string
Registry *protoregistry.Files
}
Tree represents the parsed structure of a protobuf resource message, including all its fields as nodes with metadata about types, column mappings, and allowed paths for filtering/ordering/updating.
func BuildResourceTree ¶
func BuildResourceTree[R proto.Message](opts ...TreeOption) (*Tree, error)
BuildResourceTree builds a tree for a concrete protobuf resource type.
func BuildResourceTreeFromDescriptor ¶
func BuildResourceTreeFromDescriptor(msgDesc protoreflect.MessageDescriptor, opts ...TreeOption) (*Tree, error)
BuildResourceTreeFromDescriptor builds a tree from a raw message descriptor without requiring a concrete Go type. Useful for dynamic/codegen scenarios. It parses the resource descriptor, model options, and field options to produce nodes with column name mappings and replacement paths.
func (*Tree) Explore ¶
func (t *Tree) Explore(fieldPath string, fieldDesc protoreflect.FieldDescriptor, depth int) error
Explore recursively walks a field descriptor and adds nodes to the tree. It handles scalars, enums, maps, well-known types, and nested messages.
func (*Tree) FilterableNodes ¶
FilterableNodes returns an iterator over nodes that can be used in filter expressions. Excludes IDENTIFIER and INPUT_ONLY fields.
func (*Tree) IsPathAllowed ¶
IsPathAllowed reports whether the given node's path is permitted by the tree's configured allowed paths. A path is considered allowed if:
- The tree is configured with the wildcard "*" (all paths allowed).
- The path exactly matches a configured allowed path.
- A proper ancestor of the path is a configured allowed path, meaning the allowed path implicitly covers all descendants (e.g. "metadata" allows "metadata.country", "metadata.email_addresses", etc.).
Returns false if no allowed paths are configured.
func (*Tree) OrderableNodes ¶
OrderableNodes returns an iterator over nodes that can be used in ORDER BY clauses.
type TreeConfig ¶
type TreeConfig struct {
// contains filtered or unexported fields
}
TreeConfig holds configuration for building a resource tree.
type TreeOption ¶
type TreeOption func(*TreeConfig)
TreeOption configures how a resource tree is built.
func WithAllowedPaths ¶
func WithAllowedPaths(paths []string) TreeOption
WithAllowedPaths restricts which field paths are considered allowed. Use "*" to allow all paths.
func WithMaxDepth ¶
func WithMaxDepth(maxDepth int) TreeOption
WithMaxDepth sets the maximum depth for exploring nested message fields.
func WithRegistry ¶
func WithRegistry(registry *protoregistry.Files) TreeOption
WithRegistry sets the protobuf file registry used to resolve cross-message references (e.g. join parent resources). Defaults to protoregistry.GlobalFiles.
type UpdateRequestParser ¶
type UpdateRequestParser[T updateRequest, R proto.Message] struct { // contains filtered or unexported fields }
UpdateRequestParser implements update request parsing.
func MustNewUpdateRequestParser ¶
func MustNewUpdateRequestParser[T updateRequest, R proto.Message]() *UpdateRequestParser[T, R]
MustNewUpdateRequestParser instantiates and returns a new update request parser, panicking on error.
func NewUpdateRequestParser ¶
func NewUpdateRequestParser[T updateRequest, R proto.Message]() (*UpdateRequestParser[T, R], error)
NewUpdateRequestParser instantiates and returns a new update request parser.
func (*UpdateRequestParser[T, R]) Parse ¶
func (p *UpdateRequestParser[T, R]) Parse(request T) (*ParsedUpdateRequest, error)