Documentation
¶
Overview ¶
Package resource is a generated GoMock package.
Package resource provides a set of types and functions for working with resources.
Index ¶
- Variables
- func AddResources[Resource Resourcer](c *Collection, scope accesstypes.PermissionScope, rSet *Set[Resource]) error
- func CloneRequest(r *http.Request) (*http.Request, error)
- func CommitTimestamp(_ context.Context, _ ReadWriteTransaction) (any, error)
- func CommitTimestampPtr(_ context.Context, _ ReadWriteTransaction) (any, error)
- func DefaultFalse(_ context.Context, _ ReadWriteTransaction) (any, error)
- func DefaultTrue(_ context.Context, _ ReadWriteTransaction) (any, error)
- func MockIterSeq2[Resource Resourcer](err error, resource ...*Resource) iter.Seq2[*Resource, error]
- func Operations(r *http.Request, pattern string, opts ...Option) iter.Seq2[*Operation, error]
- func PatchSetDiff(opts ...cmp.Option) func(a, b PatchSetComparer) string
- func ProcessEvent(processName string) string
- func QuerySetDiff(opts ...cmp.Option) func(a, b QuerySetComparer) string
- func UserEvent(ctx context.Context) string
- func UserProcessEvent(ctx context.Context, processName string) string
- type Buffer
- type Client
- type Collection
- func (s *Collection) AddMethodResource(scope accesstypes.PermissionScope, permission accesstypes.Permission, ...) error
- func (s *Collection) AddResource(scope accesstypes.PermissionScope, permission accesstypes.Permission, ...) error
- func (s *Collection) IsResourceImmutable(scope accesstypes.PermissionScope, res accesstypes.Resource) bool
- func (s *Collection) List() map[accesstypes.Permission][]accesstypes.Resource
- func (s *Collection) ResourceExists(r accesstypes.Resource) bool
- func (s *Collection) Resources() []accesstypes.Resource
- func (s *Collection) Scope(resource accesstypes.Resource) accesstypes.PermissionScope
- func (s *Collection) TypescriptData() *TypescriptData
- type Columns
- type Condition
- type ConditionNode
- type Config
- type DBType
- type DataChangeEvent
- type Decoder
- func (d *Decoder[Resource, Request]) Decode(request *http.Request, userPermissions UserPermissions, ...) (*PatchSet[Resource], error)
- func (d *Decoder[Resource, Request]) DecodeOperation(oper *Operation, userPermissions UserPermissions) (*PatchSet[Resource], error)
- func (d *Decoder[Resource, Request]) DecodeOperationWithoutPermissions(oper *Operation) (*PatchSet[Resource], error)
- func (d *Decoder[Resource, Request]) DecodeWithoutPermissions(request *http.Request) (*PatchSet[Resource], error)
- func (d *Decoder[Resource, Request]) WithValidator(v ValidatorFunc) *Decoder[Resource, Request]
- type DefaultsFunc
- type DiffElem
- type DomainFromCtx
- type DomainFromReq
- type Executor
- type ExpressionNode
- type FieldDefaultFunc
- type FilterFieldInfo
- type FilterLexer
- type FilterParser
- type GroupNode
- type Ident
- func (i Ident[T]) Equal(v ...T) QueryClause
- func (i Ident[T]) GreaterThan(v T) QueryClause
- func (i Ident[T]) GreaterThanEq(v T) QueryClause
- func (i Ident[T]) IsNotNull() QueryClause
- func (i Ident[T]) IsNull() QueryClause
- func (i Ident[T]) LessThan(v T) QueryClause
- func (i Ident[T]) LessThanEq(v T) QueryClause
- func (i Ident[T]) NotEqual(v ...T) QueryClause
- type KeyPart
- type KeySet
- type Link
- type LogicalOpNode
- type LogicalOperator
- type Metadata
- type MockClient
- func (c *MockClient) Close()
- func (c *MockClient) ExecuteFunc(ctx context.Context, ...) error
- func (c *MockClient) PostgresReadOnlyTransaction() any
- func (c *MockClient) ReadOnlyMocks() []any
- func (c *MockClient) ReadOnlyTransaction() ReadOnlyTransactionCloser
- func (c *MockClient) SpannerReadOnlyTransaction() spxscan.Querier
- type MockReadWriteTransaction
- func (c *MockReadWriteTransaction) BufferMap(r PatchSetMetadata, p map[string]any) error
- func (c *MockReadWriteTransaction) BufferStruct(p PatchSetMetadata) error
- func (c *MockReadWriteTransaction) DBType() DBType
- func (c *MockReadWriteTransaction) DataChangeEventIndex(res accesstypes.Resource, rowID string) int
- func (c *MockReadWriteTransaction) PostgresReadOnlyTransaction() any
- func (c *MockReadWriteTransaction) SpannerReadOnlyTransaction() spxscan.Querier
- func (c *MockReadWriteTransaction) TxnReadMocks() []any
- type MockReader
- func (m *MockReader[Resource]) DBType() DBType
- func (m *MockReader[Resource]) EXPECT() *MockReaderMockRecorder[Resource]
- func (m *MockReader[Resource]) List(ctx context.Context, stmt *Statement) iter.Seq2[*Resource, error]
- func (m *MockReader[Resource]) Read(ctx context.Context, stmt *Statement) (*Resource, error)
- type MockReaderMockRecorder
- type NullLink
- type Operation
- type OperationType
- type Option
- type PartialQueryClause
- type PatchSet
- func (p *PatchSet[Resource]) Apply(ctx context.Context, client Client, eventSource ...string) error
- func (p *PatchSet[Resource]) Buffer(ctx context.Context, txn ReadWriteTransaction, eventSource ...string) error
- func (p *PatchSet[Resource]) Data() map[accesstypes.Field]any
- func (p *PatchSet[Resource]) Diff(old any) (map[accesstypes.Field]DiffElem, error)
- func (p *PatchSet[Resource]) EnableUserPermissionEnforcement(rSet *Set[Resource], userPermissions UserPermissions, ...) *PatchSet[Resource]
- func (p *PatchSet[Resource]) Fields() []accesstypes.Field
- func (p *PatchSet[Resource]) FromStruct(input any, skip ...string) error
- func (p *PatchSet[Resource]) Get(field accesstypes.Field) any
- func (p *PatchSet[Resource]) HasKey() bool
- func (p *PatchSet[Resource]) IsSet(field accesstypes.Field) bool
- func (p *PatchSet[Resource]) Key(field accesstypes.Field) any
- func (p *PatchSet[Resource]) Len() int
- func (p *PatchSet[Resource]) PatchType() PatchType
- func (p *PatchSet[Resource]) PrimaryKey() KeySet
- func (p *PatchSet[Resource]) RegisterDefaultCreateFunc(field accesstypes.Field, fn FieldDefaultFunc)
- func (p *PatchSet[Resource]) RegisterDefaultUpdateFunc(field accesstypes.Field, fn FieldDefaultFunc)deprecated
- func (p *PatchSet[Resource]) RegisterDefaultsCreateFunc(fn DefaultsFunc)
- func (p *PatchSet[Resource]) RegisterDefaultsUpdateFunc(fn DefaultsFunc)
- func (p *PatchSet[Resource]) RegisterOutputOnlyUpdateFunc(field accesstypes.Field, fn FieldDefaultFunc)
- func (p *PatchSet[Resource]) RegisterValidateCreateFunc(fn ValidateFunc)
- func (p *PatchSet[Resource]) RegisterValidateUpdateFunc(fn ValidateFunc)
- func (p *PatchSet[Resource]) Resolve(dbType DBType) (map[string]any, error)
- func (p *PatchSet[Resource]) Resource() accesstypes.Resource
- func (p *PatchSet[Resource]) Set(field accesstypes.Field, value any) *PatchSet[Resource]
- func (p *PatchSet[Resource]) SetKey(field accesstypes.Field, value any) *PatchSet[Resource]
- func (p *PatchSet[Resource]) SetPatchType(t PatchType) *PatchSet[Resource]
- func (p *PatchSet[Resource]) ToStruct() *Resource
- type PatchSetComparer
- type PatchSetMetadata
- type PatchType
- type PostgreSQLGenerator
- type PostgresClient
- func (c *PostgresClient) Close()
- func (c *PostgresClient) ExecuteFunc(_ context.Context, _ func(ctx context.Context, _ ReadWriteTransaction) error) error
- func (c *PostgresClient) PostgresReadOnlyTransaction() any
- func (c *PostgresClient) ReadOnlyTransaction() ReadOnlyTransactionCloser
- func (c *PostgresClient) SpannerReadOnlyTransaction() spxscan.Querier
- type PostgresReadOnlyTransaction
- type PostgresReadWriteTransaction
- func (c *PostgresReadWriteTransaction) BufferMap(_ PatchSetMetadata, _ map[string]any) error
- func (c *PostgresReadWriteTransaction) BufferStruct(_ PatchSetMetadata) error
- func (c *PostgresReadWriteTransaction) DBType() DBType
- func (c *PostgresReadWriteTransaction) DataChangeEventIndex(res accesstypes.Resource, rowID string) int
- func (c *PostgresReadWriteTransaction) List(_ context.Context, _ Resourcer, _ []any, _ *Statement) error
- func (c *PostgresReadWriteTransaction) PostgresReadOnlyTransaction() any
- func (c *PostgresReadWriteTransaction) Read(_ context.Context, _ Resourcer, _ any, _ *Statement) error
- func (c *PostgresReadWriteTransaction) SpannerReadOnlyTransaction() spxscan.Querier
- type QueryClause
- type QueryDecoder
- type QueryParam
- type QuerySet
- func (q *QuerySet[Resource]) AddField(field accesstypes.Field) *QuerySet[Resource]
- func (q *QuerySet[Resource]) BatchList(ctx context.Context, client Client, size int) iter.Seq[iter.Seq2[*Resource, error]]
- func (q *QuerySet[Resource]) EnableUserPermissionEnforcement(rSet *Set[Resource], userPermissions UserPermissions, ...) *QuerySet[Resource]
- func (q *QuerySet[Resource]) Fields() []accesstypes.Field
- func (q *QuerySet[Resource]) FilterAst(dbType DBType) (ExpressionNode, error)
- func (q *QuerySet[Resource]) Key(field accesstypes.Field) any
- func (q *QuerySet[Resource]) KeySet() KeySet
- func (q *QuerySet[Resource]) Len() int
- func (q *QuerySet[Resource]) List(ctx context.Context, txn ReadOnlyTransaction) iter.Seq2[*Resource, error]
- func (q *QuerySet[Resource]) Read(ctx context.Context, txn ReadOnlyTransaction) (*Resource, error)
- func (q *QuerySet[Resource]) RequiredPermission() accesstypes.Permission
- func (q *QuerySet[Resource]) Resource() accesstypes.Resource
- func (q *QuerySet[Resource]) ReturnAccessibleFields(b bool) *QuerySet[Resource]
- func (q *QuerySet[Resource]) SetFilterAst(ast ExpressionNode)
- func (q *QuerySet[Resource]) SetFilterParser(parser func(DBType) (ExpressionNode, error))
- func (q *QuerySet[Resource]) SetKey(field accesstypes.Field, value any)
- func (q *QuerySet[Resource]) SetLimit(limit *uint64)
- func (q *QuerySet[Resource]) SetOffset(offset *uint64)
- func (q *QuerySet[Resource]) SetSortFields(sortFields []SortField)
- func (q *QuerySet[Resource]) SetWhereClause(qc QueryClause)
- type QuerySetComparer
- type RPCDecoder
- type ReadOnlyTransaction
- type ReadOnlyTransactionCloser
- type ReadWriteTransaction
- type Reader
- type RequestFieldMapper
- type Resourcer
- type SQLDialect
- type Set
- func (r *Set[Resource]) BaseResource() accesstypes.Resource
- func (r *Set[Resource]) ImmutableFields() map[accesstypes.Tag]struct{}
- func (r *Set[Resource]) PermissionRequired(fieldName accesstypes.Field, perm accesstypes.Permission) bool
- func (r *Set[Resource]) Permissions() []accesstypes.Permission
- func (r *Set[Resource]) Resource(fieldName accesstypes.Field) accesstypes.Resource
- func (r *Set[Resource]) ResourceMetadata() *Metadata[Resource]
- func (r *Set[Resource]) TagPermissions() accesstypes.TagPermissions
- type SortDirection
- type SortField
- type SpannerClient
- type SpannerGenerator
- type SpannerReadOnlyTransaction
- type SpannerReadWriteTransaction
- func (c *SpannerReadWriteTransaction) BufferMap(r PatchSetMetadata, patch map[string]any) error
- func (c *SpannerReadWriteTransaction) BufferStruct(patch PatchSetMetadata) error
- func (c *SpannerReadWriteTransaction) DBType() DBType
- func (c *SpannerReadWriteTransaction) DataChangeEventIndex(res accesstypes.Resource, rowID string) int
- func (c *SpannerReadWriteTransaction) PostgresReadOnlyTransaction() any
- func (c *SpannerReadWriteTransaction) SpannerReadOnlyTransaction() spxscan.Querier
- type Statement
- type StructDecoder
- type Token
- type TokenType
- type TypescriptData
- type UserFromCtx
- type UserFromReq
- type UserPermissions
- type ValidateFunc
- type ValidatorFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedNodeType = errors.New("unsupported AST node type for SQL generation")
ErrUnsupportedNodeType indicates an AST node type that the SQL generator cannot handle.
var ErrUnsupportedOperator = errors.New("unsupported operator for SQL generation")
ErrUnsupportedOperator indicates a condition operator that the SQL generator cannot handle.
Functions ¶
func AddResources ¶ added in v0.0.3
func AddResources[Resource Resourcer](c *Collection, scope accesstypes.PermissionScope, rSet *Set[Resource]) error
AddResources adds all the resources and permissions from a ResourceSet to the collection. It is a no-op if collectResourcePermissions is false.
func CloneRequest ¶ added in v0.0.18
CloneRequest creates a deep copy of an http.Request, including its body. This is useful when the request body needs to be read multiple times, as the original body can only be read once. The cloned request gets a new body that can be read and seeked independently.
func CommitTimestamp ¶ added in v0.1.10
func CommitTimestamp(_ context.Context, _ ReadWriteTransaction) (any, error)
CommitTimestamp is a FieldDefaultFunc that returns the Spanner commit timestamp.
func CommitTimestampPtr ¶ added in v0.1.10
func CommitTimestampPtr(_ context.Context, _ ReadWriteTransaction) (any, error)
CommitTimestampPtr is a FieldDefaultFunc that returns a pointer to the Spanner commit timestamp.
func DefaultFalse ¶ added in v0.1.16
func DefaultFalse(_ context.Context, _ ReadWriteTransaction) (any, error)
DefaultFalse is a FieldDefaultFunc that returns false.
func DefaultTrue ¶ added in v0.1.16
func DefaultTrue(_ context.Context, _ ReadWriteTransaction) (any, error)
DefaultTrue is a FieldDefaultFunc that returns true.
func MockIterSeq2 ¶ added in v0.7.0
MockIterSeq2 is used for mocking iter.Seq2[Resourcer, error] type. If both err and resource are provided, it will yield all elements in resource first and then err
func Operations ¶ added in v0.0.3
Operations parses a batch JSON patch request and yields an iterator of individual Operation objects.
func PatchSetDiff ¶ added in v0.9.0
func PatchSetDiff(opts ...cmp.Option) func(a, b PatchSetComparer) string
PatchSetDiff compares two PatchSetComparer objects for equality. It checks resource, patch type, data, fields, and primary keys.
func ProcessEvent ¶ added in v0.0.3
ProcessEvent generates a standard event source string for a system process.
func QuerySetDiff ¶ added in v0.9.0
func QuerySetDiff(opts ...cmp.Option) func(a, b QuerySetComparer) string
QuerySetDiff compares two QuerySetComparer objects for equality. It checks patch type, data, fields, and primary keys.
Types ¶
type Buffer ¶ added in v0.6.0
type Buffer interface {
Buffer(ctx context.Context, txn ReadWriteTransaction, eventSource ...string) error
}
Buffer is an interface for types that can buffer their mutations into a transaction. This is used for batching operations.
type Client ¶ added in v0.7.0
type Client interface {
ReadOnlyTransaction() ReadOnlyTransactionCloser
ReadOnlyTransaction
Executor
}
Client is an interface for the supported database Client's to implement. It is not intended for mocking since each database requires an implementation in this package.
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection stores information about resources, their permissions, and tags. It is used during code generation to create TypeScript definitions and Go handlers.
func NewCollection ¶
func NewCollection() *Collection
NewCollection creates and initializes a new Collection.
func (*Collection) AddMethodResource ¶ added in v0.1.0
func (s *Collection) AddMethodResource(scope accesstypes.PermissionScope, permission accesstypes.Permission, res accesstypes.Resource) error
AddMethodResource adds a resource associated with a method, allowing duplicate permission registrations. It is a no-op if collectResourcePermissions is false.
func (*Collection) AddResource ¶
func (s *Collection) AddResource(scope accesstypes.PermissionScope, permission accesstypes.Permission, res accesstypes.Resource) error
AddResource adds a resource with a specific permission to the collection. It is a no-op if collectResourcePermissions is false.
func (*Collection) IsResourceImmutable ¶
func (s *Collection) IsResourceImmutable(scope accesstypes.PermissionScope, res accesstypes.Resource) bool
IsResourceImmutable checks if a resource is marked as immutable within a given scope. It always returns false if collectResourcePermissions is false.
func (*Collection) List ¶
func (s *Collection) List() map[accesstypes.Permission][]accesstypes.Resource
List returns a map of permissions to the resources that have them. It returns an empty map if collectResourcePermissions is false.
func (*Collection) ResourceExists ¶ added in v0.1.7
func (s *Collection) ResourceExists(r accesstypes.Resource) bool
ResourceExists checks if a resource exists in the collection. It always returns false if collectResourcePermissions is false.
func (*Collection) Resources ¶ added in v0.0.10
func (s *Collection) Resources() []accesstypes.Resource
Resources returns a sorted list of all unique base resource names in the collection. It returns an empty slice if collectResourcePermissions is false.
func (*Collection) Scope ¶
func (s *Collection) Scope(resource accesstypes.Resource) accesstypes.PermissionScope
Scope returns the permission scope for a given resource. It returns an empty scope if the resource is not found or if collectResourcePermissions is false.
func (*Collection) TypescriptData ¶ added in v0.0.10
func (s *Collection) TypescriptData() *TypescriptData
TypescriptData returns a struct containing all the data needed for TypeScript code generation.
type Columns ¶ added in v0.0.3
type Columns string
Columns is a string representing a comma-separated list of database column names.
type Condition ¶ added in v0.1.12
type Condition struct {
Field string
Operator string
Value any // For eq, ne, gt, lt, gte, lte
Values []any // For in, notin
IsNullOp bool // For isnull, isnotnull
}
Condition represents a single condition (e.g., name:eq:John).
type ConditionNode ¶ added in v0.1.12
type ConditionNode struct {
Condition Condition
}
ConditionNode represents a simple condition in the AST.
func (*ConditionNode) String ¶ added in v0.1.12
func (cn *ConditionNode) String() string
String returns a string representation of the ConditionNode.
type Config ¶ added in v0.0.3
Config holds database-specific configuration for a resource.
func (Config) SetChangeTrackingTable ¶ added in v0.0.3
SetChangeTrackingTable returns a new Config with the change tracking table name set.
func (Config) SetTrackChanges ¶ added in v0.0.3
SetTrackChanges returns a new Config with the change tracking flag set.
type DBType ¶ added in v0.0.3
type DBType string
DBType represents the type of database, such as Spanner or PostgreSQL.
type DataChangeEvent ¶ added in v0.0.3
type DataChangeEvent struct {
TableName accesstypes.Resource `spanner:"TableName"`
RowID string `spanner:"RowId"`
Sequence int `spanner:"Sequence"`
EventTime time.Time `spanner:"EventTime"`
EventSource string `spanner:"EventSource"`
ChangeSet spanner.NullJSON `spanner:"ChangeSet"`
}
DataChangeEvent represents a record of a change made to a database table.
func (DataChangeEvent) PatchType ¶ added in v0.7.0
func (DataChangeEvent) PatchType() PatchType
PatchType returns the PatchType for DataChangeEvent
func (*DataChangeEvent) PrimaryKey ¶ added in v0.7.0
func (d *DataChangeEvent) PrimaryKey() KeySet
PrimaryKey returns an empty key sent since this resource is only used for inserts, not deletes.
func (DataChangeEvent) Resource ¶ added in v0.7.0
func (DataChangeEvent) Resource() accesstypes.Resource
Resource returns the Resource name for DataChangeEvent
type Decoder ¶ added in v0.0.3
Decoder is a struct that can be used for decoding http requests and validating those requests
func NewDecoder ¶ added in v0.0.3
func NewDecoder[Resource Resourcer, Request any](rSet *Set[Resource]) (*Decoder[Resource, Request], error)
NewDecoder creates a new Decoder for a given Resource and Request type.
func (*Decoder[Resource, Request]) Decode ¶ added in v0.0.3
func (d *Decoder[Resource, Request]) Decode(request *http.Request, userPermissions UserPermissions, requiredPermission accesstypes.Permission) (*PatchSet[Resource], error)
Decode decodes an http.Request into a PatchSet and enables user permission enforcement.
func (*Decoder[Resource, Request]) DecodeOperation ¶ added in v0.0.17
func (d *Decoder[Resource, Request]) DecodeOperation(oper *Operation, userPermissions UserPermissions) (*PatchSet[Resource], error)
DecodeOperation decodes an Operation into a PatchSet and enables user permission enforcement.
func (*Decoder[Resource, Request]) DecodeOperationWithoutPermissions ¶ added in v0.0.17
func (d *Decoder[Resource, Request]) DecodeOperationWithoutPermissions(oper *Operation) (*PatchSet[Resource], error)
DecodeOperationWithoutPermissions decodes an Operation into a PatchSet without enforcing user permissions.
func (*Decoder[Resource, Request]) DecodeWithoutPermissions ¶ added in v0.0.17
func (d *Decoder[Resource, Request]) DecodeWithoutPermissions(request *http.Request) (*PatchSet[Resource], error)
DecodeWithoutPermissions decodes an http.Request into a PatchSet without enforcing any user permissions.
func (*Decoder[Resource, Request]) WithValidator ¶ added in v0.0.3
func (d *Decoder[Resource, Request]) WithValidator(v ValidatorFunc) *Decoder[Resource, Request]
WithValidator sets the validator function for the Decoder.
type DefaultsFunc ¶ added in v0.3.1
type DefaultsFunc func(ctx context.Context, txn ReadWriteTransaction) error
DefaultsFunc is the signature for a function that applies default values to a PatchSet.
type DiffElem ¶ added in v0.0.3
DiffElem represents the old and new values of a field that has been changed.
type DomainFromCtx ¶ added in v0.0.3
type DomainFromCtx func(context.Context) accesstypes.Domain
DomainFromCtx is a function that extracts a domain from a context.
type DomainFromReq ¶ added in v0.0.3
type DomainFromReq func(*http.Request) accesstypes.Domain
DomainFromReq is a function that extracts a domain from an http.Request.
type Executor ¶ added in v0.7.0
type Executor interface {
ExecuteFunc(ctx context.Context, f func(ctx context.Context, txn ReadWriteTransaction) error) error
}
Executor interface exposes ability to run a function inside a transaction.
type ExpressionNode ¶ added in v0.1.12
type ExpressionNode interface {
// String returns a string representation of the node (for debugging/testing).
String() string
}
ExpressionNode represents a node in the filter AST.
type FieldDefaultFunc ¶ added in v0.1.5
type FieldDefaultFunc func(ctx context.Context, txn ReadWriteTransaction) (any, error)
FieldDefaultFunc is the signature for a function that applies a default value to one field of a PatchSet.
func DefaultString ¶ added in v0.1.18
func DefaultString(v string) FieldDefaultFunc
DefaultString returns a FieldDefaultFunc that provides the given string value.
type FilterFieldInfo ¶ added in v0.5.0
type FilterFieldInfo struct {
JSONFieldName string
GOFieldName string
Kind reflect.Kind
FieldType reflect.Type
Indexed bool
PII bool
// contains filtered or unexported fields
}
FilterFieldInfo holds metadata about a field that can be used in a filter.
func (FilterFieldInfo) ColumnName ¶ added in v0.7.0
func (f FilterFieldInfo) ColumnName(dbType DBType) (string, error)
ColumnName returns the column name for the given DBType.
type FilterLexer ¶ added in v0.5.0
type FilterLexer struct {
// contains filtered or unexported fields
}
FilterLexer parses the filter producing tokens
func NewFilterLexer ¶ added in v0.5.0
func NewFilterLexer(input string) *FilterLexer
NewFilterLexer creates a new lexer for the given input filter string.
func (*FilterLexer) NextToken ¶ added in v0.5.0
func (l *FilterLexer) NextToken() (Token, error)
NextToken returns the next token from the input string.
func (*FilterLexer) Reset ¶ added in v0.7.0
func (l *FilterLexer) Reset()
Reset resets the lexer to its beginning state so it can be used again
type FilterParser ¶ added in v0.5.0
type FilterParser struct {
// contains filtered or unexported fields
}
FilterParser builds an AST from tokens.
func NewFilterParser ¶ added in v0.5.0
func NewFilterParser(lexer *FilterLexer, jsonToFieldInfo map[jsonFieldName]FilterFieldInfo) (*FilterParser, error)
NewFilterParser creates a new parser with the given lexer and field information map.
func (*FilterParser) Parse ¶ added in v0.5.0
func (p *FilterParser) Parse(dbType DBType) (ExpressionNode, error)
Parse is the main entry point for parsing the filter string.
type GroupNode ¶ added in v0.1.12
type GroupNode struct {
Expression ExpressionNode
}
GroupNode represents a parenthesized group of expressions in the AST.
type Ident ¶ added in v0.0.19
type Ident[T comparable] struct { // contains filtered or unexported fields }
Ident represents a database column identifier in a query, typed to ensure compile-time correctness of comparisons.
func NewIdent ¶ added in v0.0.19
func NewIdent[T comparable](column string, px PartialQueryClause, indexed bool) Ident[T]
NewIdent creates a new identifier for a column.
func (Ident[T]) Equal ¶ added in v0.0.19
func (i Ident[T]) Equal(v ...T) QueryClause
Equal creates an equality (`=`) or `IN` condition.
func (Ident[T]) GreaterThan ¶ added in v0.0.19
func (i Ident[T]) GreaterThan(v T) QueryClause
GreaterThan creates a `>` condition.
func (Ident[T]) GreaterThanEq ¶ added in v0.0.19
func (i Ident[T]) GreaterThanEq(v T) QueryClause
GreaterThanEq creates a `>=` condition.
func (Ident[T]) IsNotNull ¶ added in v0.1.12
func (i Ident[T]) IsNotNull() QueryClause
IsNotNull creates an `IS NOT NULL` condition.
func (Ident[T]) IsNull ¶ added in v0.1.12
func (i Ident[T]) IsNull() QueryClause
IsNull creates an `IS NULL` condition.
func (Ident[T]) LessThan ¶ added in v0.0.19
func (i Ident[T]) LessThan(v T) QueryClause
LessThan creates a `<` condition.
func (Ident[T]) LessThanEq ¶ added in v0.0.19
func (i Ident[T]) LessThanEq(v T) QueryClause
LessThanEq creates a `<=` condition.
func (Ident[T]) NotEqual ¶ added in v0.0.19
func (i Ident[T]) NotEqual(v ...T) QueryClause
NotEqual creates a not-equal (`<>`) or `NOT IN` condition.
type KeyPart ¶
type KeyPart struct {
Key accesstypes.Field
Value any
}
KeyPart represents a single component of a primary key, consisting of a field name and its value.
type KeySet ¶
type KeySet struct {
// contains filtered or unexported fields
}
KeySet is an object that represents a single or composite primary key and its value.
func (KeySet) Add ¶
func (p KeySet) Add(key accesstypes.Field, value any) KeySet
Add adds an additional column to the primary key creating a composite primary key
- PrimaryKey is immutable.
- Add returns a new PrimaryKey that should be used for all subsequent operations.
func (KeySet) KeyMap ¶
func (p KeySet) KeyMap() map[accesstypes.Field]any
KeyMap returns a map representation of the key set, with field names as keys and their values as values.
func (KeySet) KeySet ¶
KeySet converts the resource KeySet into a `spanner.KeySet`, which can be used in Spanner read or delete operations.
func (KeySet) Len ¶
Len returns the number of parts in the key set (for composite keys, this will be greater than 1).
type Link ¶ added in v0.0.11
type Link struct {
ID ccc.UUID `json:"id"`
Resource string `json:"resource"`
Text string `json:"text"`
}
Link represents a hyperlink to another resource, containing its ID, type, and display text.
func (*Link) DecodeSpanner ¶ added in v0.0.11
DecodeSpanner implements the spanner.Decoder interface, unmarshaling a JSON string from Spanner into the Link struct.
func (Link) EncodeSpanner ¶ added in v0.0.11
EncodeSpanner implements the spanner.Encoder interface, marshaling the Link to its JSON representation for storage.
func (Link) IsNull ¶ added in v0.0.11
IsNull checks if the Link is considered null (i.e., its ID is nil).
func (Link) MarshalJSON ¶ added in v0.0.11
MarshalJSON implements the json.Marshaler interface.
func (*Link) UnmarshalJSON ¶ added in v0.0.11
UnmarshalJSON implements the json.Unmarshaler interface.
type LogicalOpNode ¶ added in v0.1.12
type LogicalOpNode struct {
Left ExpressionNode
Operator LogicalOperator
Right ExpressionNode
}
LogicalOpNode represents a logical operation (AND/OR) in the AST.
func (*LogicalOpNode) String ¶ added in v0.1.12
func (ln *LogicalOpNode) String() string
String returns a string representation of the LogicalOpNode.
type LogicalOperator ¶ added in v0.1.12
type LogicalOperator string
LogicalOperator defines the type of logical operator (AND, OR).
const ( // OperatorAnd represents a logical AND. OperatorAnd LogicalOperator = "AND" // OperatorOr represents a logical OR. OperatorOr LogicalOperator = "OR" )
type Metadata ¶ added in v0.5.0
type Metadata[Resource Resourcer] struct { // contains filtered or unexported fields }
Metadata contains cached metadata about a resource, such as its database schema mapping and configuration.
func NewMetadata ¶ added in v0.5.0
NewMetadata creates or retrieves cached metadata for a resource.
func (*Metadata[Resource]) DBFieldCount ¶ added in v0.7.0
DBFieldCount returns the number of fields for a given database type.
type MockClient ¶ added in v0.7.0
type MockClient struct {
// contains filtered or unexported fields
}
MockClient is a wrapper around the database.
func NewMockClient ¶ added in v0.7.0
func NewMockClient(txnMock ReadWriteTransaction, readOnlyMocks, txnReadMocks []any) *MockClient
NewMockClient creates a new MockClient for testing resource database interactions.
It uses the following mocks: - txnMock: Mocks Buffer calls. - readOnlyMocks: Mocks Read/List calls outside a transaction. - txnReadMocks: Mocks Read/List calls inside a transaction.
IMPORTANT: For readOnlyMocks and txnReadMocks, provide only one mock per resource type (e.g., Read[MyResource]). Multiple calls for the same Resource must be configured on that single mock.
func (*MockClient) Close ¶ added in v0.7.0
func (c *MockClient) Close()
Close closes the database connection.
func (*MockClient) ExecuteFunc ¶ added in v0.7.0
func (c *MockClient) ExecuteFunc(ctx context.Context, f func(ctx context.Context, txn ReadWriteTransaction) error) error
ExecuteFunc executes a function within a read-write transaction.
func (*MockClient) PostgresReadOnlyTransaction ¶ added in v0.7.0
func (c *MockClient) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the MockClient.
func (*MockClient) ReadOnlyMocks ¶ added in v0.7.0
func (c *MockClient) ReadOnlyMocks() []any
ReadOnlyMocks returns the read-only mocks for the Mock client.
func (*MockClient) ReadOnlyTransaction ¶ added in v0.9.0
func (c *MockClient) ReadOnlyTransaction() ReadOnlyTransactionCloser
ReadOnlyTransaction returns a ReadOnlyTransaction that can be used for multiple reads from the database. You must call Close() when the ReadOnlyTransaction is no longer needed to release resources on the server.
func (*MockClient) SpannerReadOnlyTransaction ¶ added in v0.7.0
func (c *MockClient) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction returns a read-only transaction for the Mock client.
type MockReadWriteTransaction ¶ added in v0.7.0
type MockReadWriteTransaction struct {
// contains filtered or unexported fields
}
MockReadWriteTransaction represents a database transaction that can be used for both reads and writes.
func (*MockReadWriteTransaction) BufferMap ¶ added in v0.7.0
func (c *MockReadWriteTransaction) BufferMap(r PatchSetMetadata, p map[string]any) error
BufferMap buffers a map of changes to be applied to the database.
func (*MockReadWriteTransaction) BufferStruct ¶ added in v0.7.0
func (c *MockReadWriteTransaction) BufferStruct(p PatchSetMetadata) error
BufferStruct buffers a struct of changes to be applied to the database.
func (*MockReadWriteTransaction) DBType ¶ added in v0.7.0
func (c *MockReadWriteTransaction) DBType() DBType
DBType returns the database type.
func (*MockReadWriteTransaction) DataChangeEventIndex ¶ added in v0.7.0
func (c *MockReadWriteTransaction) DataChangeEventIndex(res accesstypes.Resource, rowID string) int
DataChangeEventIndex provides a sequence number for data change events on the same Resource inside the same transaction.
func (*MockReadWriteTransaction) PostgresReadOnlyTransaction ¶ added in v0.7.0
func (c *MockReadWriteTransaction) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the MockReadWriteTransaction.
func (*MockReadWriteTransaction) SpannerReadOnlyTransaction ¶ added in v0.7.0
func (c *MockReadWriteTransaction) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction returns a read-only transaction for the MockReadWriteTransaction.
func (*MockReadWriteTransaction) TxnReadMocks ¶ added in v0.7.0
func (c *MockReadWriteTransaction) TxnReadMocks() []any
TxnReadMocks returns the read mocks inside a transaction for the MockReadWriteTransaction.
type MockReader ¶ added in v0.8.0
type MockReader[Resource Resourcer] struct { // contains filtered or unexported fields }
MockReader is a mock of Reader interface.
func NewMockReader ¶ added in v0.8.0
func NewMockReader[Resource Resourcer](ctrl *gomock.Controller) *MockReader[Resource]
NewMockReader creates a new mock instance.
func (*MockReader[Resource]) DBType ¶ added in v0.8.0
func (m *MockReader[Resource]) DBType() DBType
DBType mocks base method.
func (*MockReader[Resource]) EXPECT ¶ added in v0.8.0
func (m *MockReader[Resource]) EXPECT() *MockReaderMockRecorder[Resource]
EXPECT returns an object that allows the caller to indicate expected use.
type MockReaderMockRecorder ¶ added in v0.8.0
type MockReaderMockRecorder[Resource Resourcer] struct { // contains filtered or unexported fields }
MockReaderMockRecorder is the mock recorder for MockReader.
func (*MockReaderMockRecorder[Resource]) DBType ¶ added in v0.8.0
func (mr *MockReaderMockRecorder[Resource]) DBType() *gomock.Call
DBType indicates an expected call of DBType.
type NullLink ¶ added in v0.0.11
NullLink is a nullable version of Link, supporting JSON and Spanner encoding/decoding of null values.
func (*NullLink) DecodeSpanner ¶ added in v0.0.11
DecodeSpanner implements the spanner.Decoder interface for NullLink.
func (NullLink) EncodeSpanner ¶ added in v0.0.11
EncodeSpanner implements the spanner.Encoder interface for NullLink.
func (NullLink) MarshalJSON ¶ added in v0.0.11
MarshalJSON implements the json.Marshaler interface for NullLink.
func (*NullLink) UnmarshalJSON ¶ added in v0.0.11
UnmarshalJSON implements the json.Unmarshaler interface for NullLink.
type Operation ¶ added in v0.0.3
type Operation struct {
Type OperationType
Req *http.Request
// contains filtered or unexported fields
}
Operation represents a single operation within a batch request, containing its type and a corresponding http.Request.
func (*Operation) ReqWithPattern ¶ added in v0.2.3
ReqWithPattern creates a new http.Request from the operation, applying a new URL pattern to its context. This is useful when a batch operation's path contains more segments than the initial prefix pattern.
type OperationType ¶ added in v0.0.3
type OperationType string
OperationType defines the type of a patch operation (add, patch, remove).
const ( // OperationCreate corresponds to an "add" operation. OperationCreate OperationType = "add" // OperationUpdate corresponds to a "patch" operation. OperationUpdate OperationType = "patch" // OperationDelete corresponds to a "remove" operation. OperationDelete OperationType = "remove" )
type Option ¶ added in v0.0.12
type Option func(opt options) options
Option is a function that configures the behavior of the Operations parser.
func MatchPrefix ¶ added in v0.2.3
func MatchPrefix() Option
MatchPrefix is an option that allows matching only the prefix of an operation's path against the provided pattern.
func RequireCreatePath ¶ added in v0.0.12
func RequireCreatePath() Option
RequireCreatePath is an option that mandates a path for "add" operations.
type PartialQueryClause ¶ added in v0.0.19
type PartialQueryClause struct {
// contains filtered or unexported fields
}
PartialQueryClause represents an incomplete query clause, typically the left-hand side of a logical operation.
func NewPartialQueryClause ¶ added in v0.0.19
func NewPartialQueryClause() PartialQueryClause
NewPartialQueryClause creates an empty PartialQueryClause.
func (PartialQueryClause) Group ¶ added in v0.0.19
func (p PartialQueryClause) Group(qc QueryClause) QueryClause
Group wraps a QueryClause in parentheses.
type PatchSet ¶
type PatchSet[Resource Resourcer] struct { // contains filtered or unexported fields }
PatchSet represents a set of changes to be applied to a resource.
func NewPatchSet ¶
NewPatchSet creates a new, empty PatchSet for a given resource metadata.
func (*PatchSet[Resource]) Apply ¶ added in v0.6.0
Apply applies the patch within a new read-write transaction.
func (*PatchSet[Resource]) Buffer ¶ added in v0.6.0
func (p *PatchSet[Resource]) Buffer(ctx context.Context, txn ReadWriteTransaction, eventSource ...string) error
Buffer buffers the patch's mutations into an existing transaction buffer.
func (*PatchSet[Resource]) Data ¶
func (p *PatchSet[Resource]) Data() map[accesstypes.Field]any
Data returns the underlying map of field-value pairs.
func (*PatchSet[Resource]) Diff ¶ added in v0.0.3
Diff returns a map of fields that have changed between old and patchSet.
func (*PatchSet[Resource]) EnableUserPermissionEnforcement ¶ added in v0.0.17
func (p *PatchSet[Resource]) EnableUserPermissionEnforcement(rSet *Set[Resource], userPermissions UserPermissions, requiredPermission accesstypes.Permission) *PatchSet[Resource]
EnableUserPermissionEnforcement enables the checking of user permissions for the PatchSet.
func (*PatchSet[Resource]) Fields ¶
func (p *PatchSet[Resource]) Fields() []accesstypes.Field
Fields returns a slice of all fields that have been set in the PatchSet.
func (*PatchSet[Resource]) FromStruct ¶ added in v0.9.0
FromStruct populates the PatchSet from a given struct. It reflects on the input struct and sets the fields in the PatchSet. Fields from the input struct that do not exist in the resource and are not in the skip list will result in an error.
func (*PatchSet[Resource]) Get ¶
func (p *PatchSet[Resource]) Get(field accesstypes.Field) any
Get retrieves the value of a field from the PatchSet.
func (*PatchSet[Resource]) IsSet ¶ added in v0.0.3
func (p *PatchSet[Resource]) IsSet(field accesstypes.Field) bool
IsSet checks if a field has been set in the PatchSet.
func (*PatchSet[Resource]) Key ¶
func (p *PatchSet[Resource]) Key(field accesstypes.Field) any
Key retrieves the value of a primary key field.
func (*PatchSet[Resource]) PrimaryKey ¶ added in v0.0.3
PrimaryKey returns the KeySet containing the primary key(s) for the resource.
func (*PatchSet[Resource]) RegisterDefaultCreateFunc ¶ added in v0.1.10
func (p *PatchSet[Resource]) RegisterDefaultCreateFunc(field accesstypes.Field, fn FieldDefaultFunc)
RegisterDefaultCreateFunc registers a function to set a default value for a field during a create operation.
func (*PatchSet[Resource]) RegisterDefaultUpdateFunc
deprecated
added in
v0.1.10
func (p *PatchSet[Resource]) RegisterDefaultUpdateFunc(field accesstypes.Field, fn FieldDefaultFunc)
RegisterDefaultUpdateFunc registers a function to set a default value for a field during an update operation.
Deprecated: Use RegisterOutputOnlyUpdateFunc instead.
func (*PatchSet[Resource]) RegisterDefaultsCreateFunc ¶ added in v0.3.1
func (p *PatchSet[Resource]) RegisterDefaultsCreateFunc(fn DefaultsFunc)
RegisterDefaultsCreateFunc registers a function that will be called on all Create Patches just before the patch is buffered to set necessary default values
func (*PatchSet[Resource]) RegisterDefaultsUpdateFunc ¶ added in v0.3.1
func (p *PatchSet[Resource]) RegisterDefaultsUpdateFunc(fn DefaultsFunc)
RegisterDefaultsUpdateFunc registers a function that will be called on all Update Patches just before the patch is buffered to set necessary default values
func (*PatchSet[Resource]) RegisterOutputOnlyUpdateFunc ¶ added in v0.9.0
func (p *PatchSet[Resource]) RegisterOutputOnlyUpdateFunc(field accesstypes.Field, fn FieldDefaultFunc)
RegisterOutputOnlyUpdateFunc registers a function to set a default value for a field during an update operation.
func (*PatchSet[Resource]) RegisterValidateCreateFunc ¶ added in v0.3.1
func (p *PatchSet[Resource]) RegisterValidateCreateFunc(fn ValidateFunc)
RegisterValidateCreateFunc registers a function that will be called on all Create Patches just before the patch is buffered to validate the patch
func (*PatchSet[Resource]) RegisterValidateUpdateFunc ¶ added in v0.3.1
func (p *PatchSet[Resource]) RegisterValidateUpdateFunc(fn ValidateFunc)
RegisterValidateUpdateFunc registers a function that will be called on all Update Patches just before the patch is buffered to validate the patch
func (*PatchSet[Resource]) Resolve ¶ added in v0.0.3
Resolve returns a map with the keys set to the database struct tags found on databaseType, and the values set to the values in patchSet.
func (*PatchSet[Resource]) Resource ¶ added in v0.0.3
func (p *PatchSet[Resource]) Resource() accesstypes.Resource
Resource returns the name of the resource this PatchSet applies to.
func (*PatchSet[Resource]) Set ¶
func (p *PatchSet[Resource]) Set(field accesstypes.Field, value any) *PatchSet[Resource]
Set adds or updates a field's value in the PatchSet.
func (*PatchSet[Resource]) SetKey ¶
func (p *PatchSet[Resource]) SetKey(field accesstypes.Field, value any) *PatchSet[Resource]
SetKey sets a primary key field and value for the PatchSet.
func (*PatchSet[Resource]) SetPatchType ¶ added in v0.0.3
SetPatchType sets the type of the patch (Create, Update, or Delete).
type PatchSetComparer ¶ added in v0.0.3
type PatchSetComparer interface {
Resource() accesstypes.Resource
Data() map[accesstypes.Field]any
Fields() []accesstypes.Field
PatchType() PatchType
PrimaryKey() KeySet
}
PatchSetComparer is an interface for comparing two PatchSet-like objects.
type PatchSetMetadata ¶ added in v0.7.0
type PatchSetMetadata interface {
PatchType() PatchType
PrimaryKey() KeySet
Resource() accesstypes.Resource
}
PatchSetMetadata is an interface that all PatchSet types must implement to allow their mutations to be buffered
type PatchType ¶ added in v0.0.3
type PatchType string
PatchType defines the type of operation for a PatchSet.
const ( // CreatePatchType indicates an insert operation. CreatePatchType PatchType = "CreatePatchType" // UpdatePatchType indicates an update operation. UpdatePatchType PatchType = "UpdatePatchType" // CreateOrUpdatePatchType indicates an insert or update operation. CreateOrUpdatePatchType PatchType = "CreateOrUpdatePatchType" // DeletePatchType indicates a delete operation. DeletePatchType PatchType = "DeletePatchType" )
type PostgreSQLGenerator ¶ added in v0.1.12
type PostgreSQLGenerator struct {
// contains filtered or unexported fields
}
PostgreSQLGenerator is a SQL generator for PostgreSQL.
func NewPostgreSQLGenerator ¶ added in v0.1.12
func NewPostgreSQLGenerator() *PostgreSQLGenerator
NewPostgreSQLGenerator creates a new PostgreSQLGenerator.
func (*PostgreSQLGenerator) GenerateSQL ¶ added in v0.1.12
func (g *PostgreSQLGenerator) GenerateSQL(node ExpressionNode) (sqlStr string, params map[string]any, err error)
GenerateSQL generates SQL for the given node.
type PostgresClient ¶ added in v0.7.0
type PostgresClient struct {
// contains filtered or unexported fields
}
PostgresClient is a wrapper around the database.
func NewPostgresClient ¶ added in v0.7.0
func NewPostgresClient(db *pgxpool.Pool) *PostgresClient
NewPostgresClient creates a new Client.
func (*PostgresClient) Close ¶ added in v0.7.0
func (c *PostgresClient) Close()
Close closes the database connection.
func (*PostgresClient) ExecuteFunc ¶ added in v0.7.0
func (c *PostgresClient) ExecuteFunc(_ context.Context, _ func(ctx context.Context, _ ReadWriteTransaction) error) error
ExecuteFunc executes a function within a read-write transaction.
func (*PostgresClient) PostgresReadOnlyTransaction ¶ added in v0.7.0
func (c *PostgresClient) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the PostgresClient.
func (*PostgresClient) ReadOnlyTransaction ¶ added in v0.9.0
func (c *PostgresClient) ReadOnlyTransaction() ReadOnlyTransactionCloser
ReadOnlyTransaction returns a ReadOnlyTransaction that can be used for multiple reads from the database. You must call Close() when the ReadOnlyTransaction is no longer needed to release resources on the server.
func (*PostgresClient) SpannerReadOnlyTransaction ¶ added in v0.7.0
func (c *PostgresClient) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction panics because it is not implemented for the PostgresClient.
type PostgresReadOnlyTransaction ¶ added in v0.9.0
type PostgresReadOnlyTransaction struct {
// contains filtered or unexported fields
}
PostgresReadOnlyTransaction represents a database transaction that can be used for both reads and writes.
func (*PostgresReadOnlyTransaction) Close ¶ added in v0.9.0
func (c *PostgresReadOnlyTransaction) Close()
Close closes the readonly transaction
func (*PostgresReadOnlyTransaction) PostgresReadOnlyTransaction ¶ added in v0.9.0
func (c *PostgresReadOnlyTransaction) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction returns a read-only transaction for the Postgres client.
func (*PostgresReadOnlyTransaction) SpannerReadOnlyTransaction ¶ added in v0.9.0
func (c *PostgresReadOnlyTransaction) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction panics because it is not implemented for the PostgresReadOnlyTransaction.
type PostgresReadWriteTransaction ¶ added in v0.7.0
type PostgresReadWriteTransaction struct {
// contains filtered or unexported fields
}
PostgresReadWriteTransaction represents a database transaction that can be used for both reads and writes.
func (*PostgresReadWriteTransaction) BufferMap ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) BufferMap(_ PatchSetMetadata, _ map[string]any) error
BufferMap panics because it is not implemented for the PostgresReadWriteTransaction.
func (*PostgresReadWriteTransaction) BufferStruct ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) BufferStruct(_ PatchSetMetadata) error
BufferStruct panics because it is not implemented for the PostgresReadWriteTransaction.
func (*PostgresReadWriteTransaction) DBType ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) DBType() DBType
DBType returns the database type.
func (*PostgresReadWriteTransaction) DataChangeEventIndex ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) DataChangeEventIndex(res accesstypes.Resource, rowID string) int
DataChangeEventIndex provides a sequence number for data change events on the same Resource inside the same transaction.
func (*PostgresReadWriteTransaction) List ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) List(_ context.Context, _ Resourcer, _ []any, _ *Statement) error
List reads a list of resources from the database.
func (*PostgresReadWriteTransaction) PostgresReadOnlyTransaction ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the PostgresReadWriteTransaction.
func (*PostgresReadWriteTransaction) Read ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) Read(_ context.Context, _ Resourcer, _ any, _ *Statement) error
Read reads a single resource from the database.
func (*PostgresReadWriteTransaction) SpannerReadOnlyTransaction ¶ added in v0.7.0
func (c *PostgresReadWriteTransaction) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction panics because it is not implemented for the PostgresReadWriteTransaction.
type QueryClause ¶ added in v0.0.19
type QueryClause struct {
// contains filtered or unexported fields
}
QueryClause represents a complete, valid query expression that can be part of a WHERE clause.
func (QueryClause) And ¶ added in v0.0.19
func (qc QueryClause) And() PartialQueryClause
And starts a logical AND operation, returning a PartialQueryClause to which the right-hand side can be appended.
func (QueryClause) Or ¶ added in v0.0.19
func (qc QueryClause) Or() PartialQueryClause
Or starts a logical OR operation, returning a PartialQueryClause to which the right-hand side can be appended.
func (QueryClause) Validate ¶ added in v0.1.15
func (qc QueryClause) Validate() error
Validate checks if the query clause has at least one indexed field.
type QueryDecoder ¶ added in v0.0.3
type QueryDecoder[Resource Resourcer, Request any] struct { // contains filtered or unexported fields }
QueryDecoder is a struct that returns columns that a given user has access to view
func NewQueryDecoder ¶ added in v0.0.3
func NewQueryDecoder[Resource Resourcer, Request any](resSet *Set[Resource]) (*QueryDecoder[Resource, Request], error)
NewQueryDecoder creates a new QueryDecoder for a given Resource and Request type.
func (*QueryDecoder[Resource, Request]) Decode ¶ added in v0.0.3
func (d *QueryDecoder[Resource, Request]) Decode(request *http.Request, userPermissions UserPermissions) (*QuerySet[Resource], error)
Decode decodes an http.Request into a QuerySet and enables user permission enforcement.
func (*QueryDecoder[Resource, Request]) DecodeWithoutPermissions ¶ added in v0.0.17
func (d *QueryDecoder[Resource, Request]) DecodeWithoutPermissions(request *http.Request) (*QuerySet[Resource], error)
DecodeWithoutPermissions decodes an http.Request into a QuerySet without enforcing user permissions.
type QueryParam ¶ added in v0.1.12
QueryParam holds a single query parameter's name and value.
type QuerySet ¶
type QuerySet[Resource Resourcer] struct { // contains filtered or unexported fields }
QuerySet represents a query for a resource, including fields, keys, filters, and permissions.
func NewQuerySet ¶
NewQuerySet creates a new, empty QuerySet for a given resource metadata.
func (*QuerySet[Resource]) AddField ¶
func (q *QuerySet[Resource]) AddField(field accesstypes.Field) *QuerySet[Resource]
AddField adds a field to be returned by the query.
func (*QuerySet[Resource]) BatchList ¶ added in v0.7.1
func (q *QuerySet[Resource]) BatchList(ctx context.Context, client Client, size int) iter.Seq[iter.Seq2[*Resource, error]]
BatchList executes the query and returns an iterator for the results in batches.
Example ¶
package main
import (
"context"
iter "iter"
"github.com/cccteam/ccc/accesstypes"
)
type ExampleResource struct{}
func (ExampleResource) Resource() accesstypes.Resource {
return "ExampleResources"
}
func (ExampleResource) DefaultConfig() Config {
return Config{}
}
func main() {
ctx := context.Background()
client := SpannerClient{}
qSet := &QuerySet[ExampleResource]{}
// Each batch iterator must be iterated on at least once before iterating on the next batch.
// If a database iter.Seq2 errors, all following batches are invalid and iteration should halt.
for batch := range qSet.BatchList(ctx, &client, 10) {
if err := processExampleBatch(batch); err != nil {
return
}
}
// It's acceptable to break out of an iterator early and move onto the next batch iterator.
for batch := range qSet.BatchList(ctx, &client, 10) {
for res, err := range batch {
if err != nil {
return
}
if res.Resource() == "" {
break
}
}
}
// BAD: Handing off batched iterators to go routines and progressing to the next batched iterator is illegal behavior.
for batch := range qSet.BatchList(ctx, &client, 10) {
go func() { _ = processExampleBatch(batch) }()
}
}
func processExampleBatch(batch iter.Seq2[*ExampleResource, error]) error {
for res, err := range batch {
if err != nil {
return err
}
_ = res
}
return nil
}
func (*QuerySet[Resource]) EnableUserPermissionEnforcement ¶ added in v0.0.17
func (q *QuerySet[Resource]) EnableUserPermissionEnforcement(rSet *Set[Resource], userPermissions UserPermissions, requiredPermission accesstypes.Permission) *QuerySet[Resource]
EnableUserPermissionEnforcement enables the checking of user permissions for the QuerySet.
func (*QuerySet[Resource]) Fields ¶
func (q *QuerySet[Resource]) Fields() []accesstypes.Field
Fields returns the list of fields to be returned by the query.
func (*QuerySet[Resource]) FilterAst ¶ added in v0.7.0
func (q *QuerySet[Resource]) FilterAst(dbType DBType) (ExpressionNode, error)
FilterAst returns the filter AST for the query.
func (*QuerySet[Resource]) Key ¶ added in v0.0.3
func (q *QuerySet[Resource]) Key(field accesstypes.Field) any
Key retrieves the value of a primary key field.
func (*QuerySet[Resource]) KeySet ¶ added in v0.0.3
KeySet returns the KeySet containing the primary key(s) for the resource.
func (*QuerySet[Resource]) List ¶ added in v0.7.0
func (q *QuerySet[Resource]) List(ctx context.Context, txn ReadOnlyTransaction) iter.Seq2[*Resource, error]
List executes the query and returns an iterator for the results.
func (*QuerySet[Resource]) Read ¶ added in v0.7.0
func (q *QuerySet[Resource]) Read(ctx context.Context, txn ReadOnlyTransaction) (*Resource, error)
Read executes the query and returns a single result.
func (*QuerySet[Resource]) RequiredPermission ¶ added in v0.0.17
func (q *QuerySet[Resource]) RequiredPermission() accesstypes.Permission
RequiredPermission returns the permission required to execute the query.
func (*QuerySet[Resource]) Resource ¶ added in v0.0.3
func (q *QuerySet[Resource]) Resource() accesstypes.Resource
Resource returns the name of the resource this QuerySet applies to.
func (*QuerySet[Resource]) ReturnAccessibleFields ¶ added in v0.9.0
ReturnAccessibleFields configures the QuerySet to automatically include all fields the user has access to if no specific fields are requested.
func (*QuerySet[Resource]) SetFilterAst ¶ added in v0.1.13
func (q *QuerySet[Resource]) SetFilterAst(ast ExpressionNode)
SetFilterAst sets the filter condition for the query using a raw expression tree.
func (*QuerySet[Resource]) SetFilterParser ¶ added in v0.7.0
func (q *QuerySet[Resource]) SetFilterParser(parser func(DBType) (ExpressionNode, error))
SetFilterParser sets the filter parser.
func (*QuerySet[Resource]) SetKey ¶ added in v0.0.3
func (q *QuerySet[Resource]) SetKey(field accesstypes.Field, value any)
SetKey sets a primary key field and value for the query's WHERE clause.
func (*QuerySet[Resource]) SetLimit ¶ added in v0.2.7
SetLimit sets the maximum number of results to return.
func (*QuerySet[Resource]) SetOffset ¶ added in v0.4.4
SetOffset sets the starting point for returning results.
func (*QuerySet[Resource]) SetSortFields ¶ added in v0.1.13
SetSortFields sets the sorting order for the query results.
func (*QuerySet[Resource]) SetWhereClause ¶ added in v0.0.19
func (q *QuerySet[Resource]) SetWhereClause(qc QueryClause)
SetWhereClause sets the filter condition for the query using a QueryClause.
type QuerySetComparer ¶ added in v0.9.0
type QuerySetComparer interface {
Resource() accesstypes.Resource
Fields() []accesstypes.Field
KeySet() KeySet
}
QuerySetComparer is an interface for comparing two QuerySet-like objects.
type RPCDecoder ¶ added in v0.1.0
type RPCDecoder[Request any] struct { // contains filtered or unexported fields }
RPCDecoder decodes an HTTP request for an RPC-style endpoint, validates the request body, and enforces permissions for the RPC method.
func NewRPCDecoder ¶ added in v0.1.0
func NewRPCDecoder[Request any](userPermissions func(*http.Request) UserPermissions, methodName accesstypes.Resource, perm accesstypes.Permission) (*RPCDecoder[Request], error)
NewRPCDecoder creates a new RPCDecoder for a given request type, method name, and required permission.
func (*RPCDecoder[Request]) Decode ¶ added in v0.1.0
func (s *RPCDecoder[Request]) Decode(request *http.Request) (*Request, error)
Decode decodes the HTTP request body into the Request struct and checks user permissions.
func (*RPCDecoder[Request]) WithValidator ¶ added in v0.1.0
func (s *RPCDecoder[Request]) WithValidator(v ValidatorFunc) *RPCDecoder[Request]
WithValidator sets a validator function on the decoder.
type ReadOnlyTransaction ¶ added in v0.7.0
type ReadOnlyTransaction interface {
SpannerReadOnlyTransaction() spxscan.Querier
PostgresReadOnlyTransaction() any
}
ReadOnlyTransaction is an interface that represents a database transaction that can be used for reads only.
type ReadOnlyTransactionCloser ¶ added in v0.9.0
type ReadOnlyTransactionCloser interface {
ReadOnlyTransaction
Close()
}
ReadOnlyTransactionCloser is an interface that represents a database transaction that can be used for reads only and must be closed when it is no longer needed.
type ReadWriteTransaction ¶ added in v0.7.0
type ReadWriteTransaction interface {
DBType() DBType
ReadOnlyTransaction
BufferMap(res PatchSetMetadata, patch map[string]any) error
BufferStruct(res PatchSetMetadata) error
// DataChangeEventIndex provides a sequence number for data change events on the same Resource inside the same transaction
DataChangeEventIndex(res accesstypes.Resource, rowID string) int
}
ReadWriteTransaction is an interface that represents a database transaction that can be used for both reads and writes.
func NewMockReadWriteTransaction ¶ added in v0.7.0
func NewMockReadWriteTransaction(mock ReadWriteTransaction, txnReaderMocks ...any) ReadWriteTransaction
NewMockReadWriteTransaction creates a new MockReadWriteTransaction.
func NewSpannerReadWriteTransaction ¶ added in v0.7.2
func NewSpannerReadWriteTransaction(txn *spanner.ReadWriteTransaction) ReadWriteTransaction
NewSpannerReadWriteTransaction creates a new SpannerReadWriteTransaction from a spanner.ReadWriteTransaction
type Reader ¶ added in v0.7.0
type Reader[Resource Resourcer] interface { DBType() DBType Read(ctx context.Context, stmt *Statement) (*Resource, error) List(ctx context.Context, stmt *Statement) iter.Seq2[*Resource, error] }
Reader is an interface that wraps methods for reading resources from a database.
type RequestFieldMapper ¶ added in v0.0.17
type RequestFieldMapper struct {
// contains filtered or unexported fields
}
RequestFieldMapper provides a mapping between JSON field names (from struct tags) and their corresponding Go struct field names.
func NewRequestFieldMapper ¶ added in v0.0.17
func NewRequestFieldMapper(v any) (*RequestFieldMapper, error)
NewRequestFieldMapper creates a new RequestFieldMapper by inspecting the struct tags of the provided value.
func (*RequestFieldMapper) Fields ¶ added in v0.0.17
func (f *RequestFieldMapper) Fields() []accesstypes.Field
Fields returns a slice of all Go struct field names.
func (*RequestFieldMapper) Len ¶ added in v0.0.17
func (f *RequestFieldMapper) Len() int
Len returns the number of mapped fields.
func (*RequestFieldMapper) StructFieldName ¶ added in v0.0.17
func (f *RequestFieldMapper) StructFieldName(jsonTag string) (accesstypes.Field, bool)
StructFieldName retrieves the Go struct field name for a given JSON tag.
type Resourcer ¶
type Resourcer interface {
Resource() accesstypes.Resource
}
Resourcer is an interface that all resource structs must implement.
type SQLDialect ¶ added in v0.1.12
type SQLDialect int
SQLDialect defines the type of SQL dialect to generate.
const ( // PostgreSQL dialect. PostgreSQL SQLDialect = iota // Spanner dialect. Spanner )
type Set ¶ added in v0.5.0
type Set[Resource Resourcer] struct { // contains filtered or unexported fields }
Set holds metadata about a resource, including its permissions and field-to-tag mappings.
func NewSet ¶ added in v0.5.0
func NewSet[Resource Resourcer, Request any](permissions ...accesstypes.Permission) (*Set[Resource], error)
NewSet creates a new Set for a given Resource and Request type, parsing permissions from struct tags.
func (*Set[Resource]) BaseResource ¶ added in v0.5.0
func (r *Set[Resource]) BaseResource() accesstypes.Resource
BaseResource returns the base name of the resource (without any tags).
func (*Set[Resource]) ImmutableFields ¶ added in v0.5.0
func (r *Set[Resource]) ImmutableFields() map[accesstypes.Tag]struct{}
ImmutableFields returns a map of tags for fields that are marked as immutable.
func (*Set[Resource]) PermissionRequired ¶ added in v0.5.0
func (r *Set[Resource]) PermissionRequired(fieldName accesstypes.Field, perm accesstypes.Permission) bool
PermissionRequired checks if a specific permission is required for a given field.
func (*Set[Resource]) Permissions ¶ added in v0.5.0
func (r *Set[Resource]) Permissions() []accesstypes.Permission
Permissions returns all permissions associated with the resource set.
func (*Set[Resource]) Resource ¶ added in v0.5.0
func (r *Set[Resource]) Resource(fieldName accesstypes.Field) accesstypes.Resource
Resource returns the full resource name for a field, including its tag (e.g., "myresource.myfield").
func (*Set[Resource]) ResourceMetadata ¶ added in v0.5.0
ResourceMetadata returns the metadata for the resource.
func (*Set[Resource]) TagPermissions ¶ added in v0.5.0
func (r *Set[Resource]) TagPermissions() accesstypes.TagPermissions
TagPermissions returns the mapping of tags to their required permissions.
type SortDirection ¶ added in v0.1.13
type SortDirection string
SortDirection defines the sort direction for a field.
const ( // SortAscending specifies sorting in ascending order. SortAscending SortDirection = "asc" // SortDescending specifies sorting in descending order. SortDescending SortDirection = "desc" )
type SortField ¶ added in v0.1.13
type SortField struct {
Field string
Direction SortDirection
}
SortField represents a field to sort by, including the field name and sort direction.
type SpannerClient ¶ added in v0.7.0
type SpannerClient struct {
// contains filtered or unexported fields
}
SpannerClient is a wrapper around the database.
func NewSpannerClient ¶ added in v0.7.0
func NewSpannerClient(db *spanner.Client) *SpannerClient
NewSpannerClient creates a new Client.
func (*SpannerClient) ExecuteFunc ¶ added in v0.7.0
func (c *SpannerClient) ExecuteFunc(ctx context.Context, f func(ctx context.Context, txn ReadWriteTransaction) error) error
ExecuteFunc executes a function within a read-write transaction.
func (*SpannerClient) PostgresReadOnlyTransaction ¶ added in v0.7.0
func (c *SpannerClient) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the SpannerClient.
func (*SpannerClient) ReadOnlyTransaction ¶ added in v0.9.0
func (c *SpannerClient) ReadOnlyTransaction() ReadOnlyTransactionCloser
ReadOnlyTransaction returns a read-only transaction that can be used for multiple reads from the database. You must call Close() when the ReadOnlyTransaction is no longer needed to release resources on the server.
func (*SpannerClient) SpannerReadOnlyTransaction ¶ added in v0.7.0
func (c *SpannerClient) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction returns a read-only transaction for the Spanner client.
type SpannerGenerator ¶ added in v0.1.12
type SpannerGenerator struct {
// contains filtered or unexported fields
}
SpannerGenerator is a SQL generator for Spanner.
func NewSpannerGenerator ¶ added in v0.1.12
func NewSpannerGenerator() *SpannerGenerator
NewSpannerGenerator creates a new SpannerGenerator.
func (*SpannerGenerator) GenerateSQL ¶ added in v0.1.12
func (g *SpannerGenerator) GenerateSQL(node ExpressionNode) (sqlStr string, params map[string]any, err error)
GenerateSQL generates SQL for the given node and returns named parameters.
type SpannerReadOnlyTransaction ¶ added in v0.9.0
type SpannerReadOnlyTransaction struct {
// contains filtered or unexported fields
}
SpannerReadOnlyTransaction represents a database transaction that can be used for both reads and writes.
func (*SpannerReadOnlyTransaction) Close ¶ added in v0.9.0
func (c *SpannerReadOnlyTransaction) Close()
Close closes the readonly transaction
func (*SpannerReadOnlyTransaction) PostgresReadOnlyTransaction ¶ added in v0.9.0
func (c *SpannerReadOnlyTransaction) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the SpannerReadOnlyTransaction.
func (*SpannerReadOnlyTransaction) SpannerReadOnlyTransaction ¶ added in v0.9.0
func (c *SpannerReadOnlyTransaction) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction returns a read-only transaction for the Spanner client.
type SpannerReadWriteTransaction ¶ added in v0.7.0
type SpannerReadWriteTransaction struct {
// contains filtered or unexported fields
}
SpannerReadWriteTransaction represents a database transaction that can be used for both reads and writes.
func (*SpannerReadWriteTransaction) BufferMap ¶ added in v0.7.0
func (c *SpannerReadWriteTransaction) BufferMap(r PatchSetMetadata, patch map[string]any) error
BufferMap buffers a map of changes to be applied to the database.
func (*SpannerReadWriteTransaction) BufferStruct ¶ added in v0.7.0
func (c *SpannerReadWriteTransaction) BufferStruct(patch PatchSetMetadata) error
BufferStruct buffers a struct of changes to be applied to the database.
func (*SpannerReadWriteTransaction) DBType ¶ added in v0.7.0
func (c *SpannerReadWriteTransaction) DBType() DBType
DBType returns the database type.
func (*SpannerReadWriteTransaction) DataChangeEventIndex ¶ added in v0.7.0
func (c *SpannerReadWriteTransaction) DataChangeEventIndex(res accesstypes.Resource, rowID string) int
DataChangeEventIndex provides a sequence number for data change events on the same Resource inside the same transaction.
func (*SpannerReadWriteTransaction) PostgresReadOnlyTransaction ¶ added in v0.7.0
func (c *SpannerReadWriteTransaction) PostgresReadOnlyTransaction() any
PostgresReadOnlyTransaction panics because it is not implemented for the SpannerReadWriteTransaction.
func (*SpannerReadWriteTransaction) SpannerReadOnlyTransaction ¶ added in v0.7.0
func (c *SpannerReadWriteTransaction) SpannerReadOnlyTransaction() spxscan.Querier
SpannerReadOnlyTransaction returns a read-only transaction for the Spanner client.
type Statement ¶ added in v0.0.13
type Statement struct {
SQL string
Params map[string]any
// contains filtered or unexported fields
}
Statement is a generic container for a SQL statement and its parameters, supporting both Spanner and PostgreSQL.
func (*Statement) SpannerStatement ¶ added in v0.7.0
SpannerStatement converts the generic Statement into a Spanner-specific Statement.
type StructDecoder ¶ added in v0.0.3
type StructDecoder[Request any] struct { // contains filtered or unexported fields }
StructDecoder is a struct that can be used for decoding http requests and validating those requests
func NewStructDecoder ¶ added in v0.0.3
func NewStructDecoder[Request any]() (*StructDecoder[Request], error)
NewStructDecoder creates a new StructDecoder for a given request type.
func (*StructDecoder[Request]) Decode ¶ added in v0.0.3
func (s *StructDecoder[Request]) Decode(request *http.Request) (*Request, error)
Decode decodes the HTTP request body into the target Request struct.
func (*StructDecoder[Request]) WithValidator ¶ added in v0.0.3
func (s *StructDecoder[Request]) WithValidator(v ValidatorFunc) *StructDecoder[Request]
WithValidator sets a validator function on the decoder.
type TokenType ¶ added in v0.1.12
type TokenType int
TokenType defines the types of tokens in the filter string.
const ( // TokenEOF represents the end of the input string. TokenEOF TokenType = iota // TokenLParen represents '(' TokenLParen // TokenRParen represents ')' TokenRParen // TokenComma represents ',' TokenComma // TokenPipe represents '|' TokenPipe // TokenCondition represents 'field:operator:value' or 'field:operator:(value1,value2,...)' or 'field:operator' TokenCondition )
type TypescriptData ¶ added in v0.0.10
type TypescriptData struct {
Permissions []accesstypes.Permission
ResourcePermissions []accesstypes.Permission
Resources []accesstypes.Resource
ResourceTags map[accesstypes.Resource][]accesstypes.Tag
ResourcePermissionMap permissionMap
Domains []accesstypes.PermissionScope
}
TypescriptData holds all the collected resource and permission information needed for TypeScript code generation.
type UserFromCtx ¶ added in v0.0.3
type UserFromCtx func(context.Context) accesstypes.User
UserFromCtx is a function that extracts a user from a context.
type UserFromReq ¶ added in v0.0.3
type UserFromReq func(*http.Request) accesstypes.User
UserFromReq is a function that extracts a user from an http.Request.
type UserPermissions ¶ added in v0.0.17
type UserPermissions interface {
Check(ctx context.Context, perm accesstypes.Permission, resources ...accesstypes.Resource) (ok bool, missing []accesstypes.Resource, err error)
Domain() accesstypes.Domain
User() accesstypes.User
}
UserPermissions is an interface that provides methods to check user permissions and retrieve user information, and is used in the PatchSet and QuerySet types to enforce user permissions on resources.
type ValidateFunc ¶ added in v0.3.1
type ValidateFunc func(ctx context.Context, txn ReadWriteTransaction) error
ValidateFunc is the signature for a function that validates a PatchSet prior to committing it.
type ValidatorFunc ¶ added in v0.0.3
type ValidatorFunc interface {
Struct(s interface{}) error
StructPartial(s interface{}, fields ...string) error
}
ValidatorFunc is a function that validates s It returns an error if the validation fails
Source Files
¶
- clone.go
- collection.go
- config.go
- decoder.go
- dml.go
- eventsource.go
- fieldmapper.go
- fieldset.go
- filterparser.go
- keyset.go
- link.go
- mock_resource_iface.go
- operations.go
- patchset.go
- query_decoder.go
- querybuilder.go
- queryset.go
- resource.go
- resource_iface.go
- resource_mock.go
- resource_postgres.go
- resource_spanner.go
- resourceset.go
- rpc_decoder.go
- sqlgenerator.go
- struct_decoder.go
- tokentype_string.go
- types.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package generation provides tools for generating resource-driven API boilerplate in Go & TypeScript based on Go structures and a Spanner DB schema.
|
Package generation provides tools for generating resource-driven API boilerplate in Go & TypeScript based on Go structures and a Spanner DB schema. |
|
parser
Package parser is a simplified abstraction over go/parser, tailored for the go:generate resource/generation tool.
|
Package parser is a simplified abstraction over go/parser, tailored for the go:generate resource/generation tool. |
|
parser/genlang
Package genlang provides parsing for godoc comment annotations
|
Package genlang provides parsing for godoc comment annotations |