resource

package module
v0.2.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 32 Imported by: 2

Documentation

Overview

package resource provides a set of types and functions for working with resources.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedNodeType = errors.New("unsupported AST node type for SQL generation")

ErrUnsupportedNodeType indicates an AST node type that the SQL generator cannot handle.

View Source
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 *ResourceSet[Resource]) error

func CloneRequest added in v0.0.18

func CloneRequest(r *http.Request) (*http.Request, error)

func CommitTimestamp added in v0.1.10

func CommitTimestamp(_ context.Context, _ TxnBuffer) (any, error)

func CommitTimestampPtr added in v0.1.10

func CommitTimestampPtr(_ context.Context, _ TxnBuffer) (any, error)

func DefaultFalse added in v0.1.16

func DefaultFalse(_ context.Context, _ TxnBuffer) (any, error)

func DefaultTrue added in v0.1.16

func DefaultTrue(_ context.Context, _ TxnBuffer) (any, error)

func Operations added in v0.0.3

func Operations(r *http.Request, pattern string, opts ...Option) iter.Seq2[*Operation, error]

func PatchsetCompare added in v0.0.3

func PatchsetCompare(a, b PatchSetComparer) bool

func ProcessEvent added in v0.0.3

func ProcessEvent(processName string) string

func UserEvent added in v0.0.3

func UserEvent(ctx context.Context) string

func UserProcessEvent added in v0.0.3

func UserProcessEvent(ctx context.Context, processName string) string

Types

type Collection

type Collection struct {
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection() *Collection

func (*Collection) AddMethodResource added in v0.1.0

func (s *Collection) AddMethodResource(scope accesstypes.PermissionScope, permission accesstypes.Permission, res accesstypes.Resource) error

func (*Collection) AddResource

func (s *Collection) AddResource(scope accesstypes.PermissionScope, permission accesstypes.Permission, res accesstypes.Resource) error

func (*Collection) IsResourceImmutable

func (s *Collection) IsResourceImmutable(scope accesstypes.PermissionScope, res accesstypes.Resource) bool

func (*Collection) List

func (*Collection) ResourceExists added in v0.1.7

func (s *Collection) ResourceExists(r accesstypes.Resource) bool

func (*Collection) Resources added in v0.0.10

func (s *Collection) Resources() []accesstypes.Resource

func (*Collection) Scope

func (*Collection) TypescriptData added in v0.0.10

func (c *Collection) TypescriptData() TypescriptData

type Columns added in v0.0.3

type Columns string

type CommitBuffer added in v0.0.21

type CommitBuffer struct {
	// contains filtered or unexported fields
}

func NewCommitBuffer added in v0.0.21

func NewCommitBuffer(db TxnFuncRunner, eventSource string, autoCommitSize int) *CommitBuffer

NewCommitBuffer returns a CommitBuffer that flushes the buffer when it reaches autoCommitSize, committing the content in a single transaction. A autoCommitSize of 0 means that the buffer will never be flushed automatically. The buffer can be flushed manually by calling Commit(). Commit() must be called before discarding CommitBuffer to ensure all buffered mutations are committed.

func (*CommitBuffer) Buffer added in v0.0.21

func (cb *CommitBuffer) Buffer(ctx context.Context, ps ...SpannerBuffer) error

func (*CommitBuffer) Commit added in v0.0.21

func (cb *CommitBuffer) Commit(ctx context.Context) error

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

type Config struct {
	DBType              DBType
	ChangeTrackingTable string
	TrackChanges        bool
}

func (Config) SetChangeTrackingTable added in v0.0.3

func (c Config) SetChangeTrackingTable(changeTrackingTable string) Config

func (Config) SetDBType added in v0.0.3

func (c Config) SetDBType(dbType DBType) Config

func (Config) SetTrackChanges added in v0.0.3

func (c Config) SetTrackChanges(trackChanges bool) Config

type Configurer added in v0.0.3

type Configurer interface {
	Config() Config
}

type DBType added in v0.0.3

type DBType string
const (
	SpannerDBType  DBType = "spanner"
	PostgresDBType DBType = "postgres"
)

type DataChangeEvent added in v0.0.3

type DataChangeEvent struct {
	TableName   accesstypes.Resource `spanner:"TableName"`
	RowID       string               `spanner:"RowId"`
	EventTime   time.Time            `spanner:"EventTime"`
	EventSource string               `spanner:"EventSource"`
	ChangeSet   spanner.NullJSON     `spanner:"ChangeSet"`
}

type Decoder added in v0.0.3

type Decoder[Resource Resourcer, Request any] struct {
	// contains filtered or unexported fields
}

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 *ResourceSet[Resource]) (*Decoder[Resource, Request], error)

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)

func (*Decoder[Resource, Request]) DecodeOperation added in v0.0.17

func (d *Decoder[Resource, Request]) DecodeOperation(oper *Operation, userPermissions UserPermissions) (*PatchSet[Resource], error)

func (*Decoder[Resource, Request]) DecodeOperationWithoutPermissions added in v0.0.17

func (d *Decoder[Resource, Request]) DecodeOperationWithoutPermissions(oper *Operation) (*PatchSet[Resource], error)

func (*Decoder[Resource, Request]) DecodeWithoutPermissions added in v0.0.17

func (d *Decoder[Resource, Request]) DecodeWithoutPermissions(request *http.Request) (*PatchSet[Resource], error)

func (*Decoder[Resource, Request]) WithValidator added in v0.0.3

func (d *Decoder[Resource, Request]) WithValidator(v ValidatorFunc) *Decoder[Resource, Request]

type DiffElem added in v0.0.3

type DiffElem struct {
	Old any
	New any
}

type DomainFromCtx added in v0.0.3

type DomainFromCtx func(context.Context) accesstypes.Domain

type DomainFromReq added in v0.0.3

type DomainFromReq func(*http.Request) accesstypes.Domain

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 TxnBuffer) (any, error)

func DefaultString added in v0.1.18

func DefaultString(v string) FieldDefaultFunc

type FieldInfo added in v0.1.12

type FieldInfo struct {
	Name      string
	Kind      reflect.Kind
	FieldType reflect.Type
	Indexed   bool
}

type GroupNode added in v0.1.12

type GroupNode struct {
	Expression ExpressionNode
}

GroupNode represents a parenthesized group of expressions in the AST.

func (*GroupNode) String added in v0.1.12

func (gn *GroupNode) String() string

String returns a string representation of the GroupNode.

type Ident added in v0.0.19

type Ident[T comparable] struct {
	// contains filtered or unexported fields
}

func NewIdent added in v0.0.19

func NewIdent[T comparable](column string, px PartialQueryClause, indexed bool) Ident[T]

func (Ident[T]) Equal added in v0.0.19

func (i Ident[T]) Equal(v ...T) QueryClause

func (Ident[T]) GreaterThan added in v0.0.19

func (i Ident[T]) GreaterThan(v T) QueryClause

func (Ident[T]) GreaterThanEq added in v0.0.19

func (i Ident[T]) GreaterThanEq(v T) QueryClause

func (Ident[T]) IsNotNull added in v0.1.12

func (i Ident[T]) IsNotNull() QueryClause

func (Ident[T]) IsNull added in v0.1.12

func (i Ident[T]) IsNull() QueryClause

func (Ident[T]) LessThan added in v0.0.19

func (i Ident[T]) LessThan(v T) QueryClause

func (Ident[T]) LessThanEq added in v0.0.19

func (i Ident[T]) LessThanEq(v T) QueryClause

func (Ident[T]) NotEqual added in v0.0.19

func (i Ident[T]) NotEqual(v ...T) QueryClause

type KeyPart

type KeyPart struct {
	Key   accesstypes.Field
	Value any
}

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

func (KeySet) KeySet

func (p KeySet) KeySet() spanner.KeySet

func (KeySet) Len

func (p KeySet) Len() int

func (KeySet) Parts

func (p KeySet) Parts() []KeyPart

func (KeySet) RowID

func (p KeySet) RowID() string

type Lexer added in v0.1.12

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer parses the filter producing tokens

func NewLexer added in v0.1.12

func NewLexer(input string) *Lexer

func (*Lexer) NextToken added in v0.1.12

func (l *Lexer) NextToken() (Token, error)
type Link struct {
	ID       ccc.UUID `json:"id"`
	Resource string   `json:"resource"`
	Text     string   `json:"text"`
}

func (*Link) DecodeSpanner added in v0.0.11

func (l *Link) DecodeSpanner(val any) error

func (Link) EncodeSpanner added in v0.0.11

func (l Link) EncodeSpanner() (any, error)

func (Link) IsNull added in v0.0.11

func (l Link) IsNull() bool

func (Link) MarshalJSON added in v0.0.11

func (l Link) MarshalJSON() ([]byte, error)

func (*Link) UnmarshalJSON added in v0.0.11

func (l *Link) UnmarshalJSON(data []byte) error

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 LogicalOperator = "AND"
	OperatorOr  LogicalOperator = "OR"
)
type NullLink struct {
	Link  Link
	Valid bool
}

func (*NullLink) DecodeSpanner added in v0.0.11

func (nl *NullLink) DecodeSpanner(val any) error

func (NullLink) EncodeSpanner added in v0.0.11

func (nl NullLink) EncodeSpanner() (any, error)

func (NullLink) MarshalJSON added in v0.0.11

func (nl NullLink) MarshalJSON() ([]byte, error)

func (*NullLink) UnmarshalJSON added in v0.0.11

func (nl *NullLink) UnmarshalJSON(data []byte) error

type Operation added in v0.0.3

type Operation struct {
	Type OperationType
	Req  *http.Request
}

func (*Operation) ReqWithPattern added in v0.2.3

func (o *Operation) ReqWithPattern(pattern string) (*http.Request, error)

type OperationType added in v0.0.3

type OperationType string
const (
	OperationCreate OperationType = "add"
	OperationUpdate OperationType = "patch"
	OperationDelete OperationType = "remove"
)

type Option added in v0.0.12

type Option func(opt options) options

func MatchPrefix added in v0.2.3

func MatchPrefix() Option

func RequireCreatePath added in v0.0.12

func RequireCreatePath() Option

type Parser added in v0.1.12

type Parser struct {
	// contains filtered or unexported fields
}

Parser builds an AST from tokens.

func NewParser added in v0.1.12

func NewParser(lexer *Lexer, jsonToFieldInfo map[string]FieldInfo) (*Parser, error)

func (*Parser) Parse added in v0.1.12

func (p *Parser) Parse() (ExpressionNode, error)

Parse is the main entry point for parsing the filter string.

type PartialQueryClause added in v0.0.19

type PartialQueryClause struct {
	// contains filtered or unexported fields
}

func NewPartialQueryClause added in v0.0.19

func NewPartialQueryClause() PartialQueryClause

func (PartialQueryClause) Group added in v0.0.19

type PatchSet

type PatchSet[Resource Resourcer] struct {
	// contains filtered or unexported fields
}

func NewPatchSet

func NewPatchSet[Resource Resourcer](rMeta *ResourceMetadata[Resource]) *PatchSet[Resource]

func (*PatchSet[Resource]) Data

func (p *PatchSet[Resource]) Data() map[accesstypes.Field]any

func (*PatchSet[Resource]) Diff added in v0.0.3

func (p *PatchSet[Resource]) Diff(old any) (map[accesstypes.Field]DiffElem, error)

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 *ResourceSet[Resource], userPermissions UserPermissions, requiredPermission accesstypes.Permission) *PatchSet[Resource]

func (*PatchSet[Resource]) Fields

func (p *PatchSet[Resource]) Fields() []accesstypes.Field

func (*PatchSet[Resource]) Get

func (p *PatchSet[Resource]) Get(field accesstypes.Field) any

func (*PatchSet[Resource]) HasKey

func (p *PatchSet[Resource]) HasKey() bool

func (*PatchSet[Resource]) IsSet added in v0.0.3

func (p *PatchSet[Resource]) IsSet(field accesstypes.Field) bool

func (*PatchSet[Resource]) Key

func (p *PatchSet[Resource]) Key(field accesstypes.Field) any

func (*PatchSet[Resource]) Len

func (p *PatchSet[Resource]) Len() int

func (*PatchSet[Resource]) PatchType added in v0.0.3

func (p *PatchSet[Resource]) PatchType() PatchType

func (*PatchSet[Resource]) PrimaryKey added in v0.0.3

func (p *PatchSet[Resource]) PrimaryKey() KeySet

func (*PatchSet[Resource]) RegisterDefaultCreateFunc added in v0.1.10

func (p *PatchSet[Resource]) RegisterDefaultCreateFunc(field accesstypes.Field, fn FieldDefaultFunc)

func (*PatchSet[Resource]) RegisterDefaultUpdateFunc added in v0.1.10

func (p *PatchSet[Resource]) RegisterDefaultUpdateFunc(field accesstypes.Field, fn FieldDefaultFunc)

func (*PatchSet[Resource]) Resolve added in v0.0.3

func (p *PatchSet[Resource]) Resolve() (map[string]any, error)

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

func (*PatchSet[Resource]) Set

func (p *PatchSet[Resource]) Set(field accesstypes.Field, value any) *PatchSet[Resource]

func (*PatchSet[Resource]) SetKey

func (p *PatchSet[Resource]) SetKey(field accesstypes.Field, value any) *PatchSet[Resource]

func (*PatchSet[Resource]) SetPatchType added in v0.0.3

func (p *PatchSet[Resource]) SetPatchType(t PatchType) *PatchSet[Resource]

func (*PatchSet[Resource]) SpannerApply added in v0.0.6

func (p *PatchSet[Resource]) SpannerApply(ctx context.Context, committer SpannerCommitter, eventSource ...string) error

func (*PatchSet[Resource]) SpannerBuffer added in v0.0.3

func (p *PatchSet[Resource]) SpannerBuffer(ctx context.Context, txn TxnBuffer, eventSource ...string) error

func (*PatchSet[Resource]) SpannerBufferInsertOrUpdate added in v0.0.3

func (p *PatchSet[Resource]) SpannerBufferInsertOrUpdate(ctx context.Context, txn TxnBuffer, eventSource ...string) error

func (*PatchSet[Resource]) SpannerInsertOrUpdate added in v0.0.3

func (p *PatchSet[Resource]) SpannerInsertOrUpdate(ctx context.Context, s *spanner.Client, eventSource ...string) error

type PatchSetComparer added in v0.0.3

type PatchSetComparer interface {
	Data() map[accesstypes.Field]any
	Fields() []accesstypes.Field
	PatchType() PatchType
	PrimaryKey() KeySet
}

type PatchType added in v0.0.3

type PatchType string
const (
	CreatePatchType PatchType = "CreatePatchType"
	UpdatePatchType PatchType = "UpdatePatchType"
	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 []any, err error)

GenerateSQL generates SQL for the given node.

type PostgresStatement added in v0.1.12

type PostgresStatement struct {
	SQL    string
	Params []any
	// contains filtered or unexported fields
}

type QueryClause added in v0.0.19

type QueryClause struct {
	// contains filtered or unexported fields
}

func (QueryClause) And added in v0.0.19

func (QueryClause) Or added in v0.0.19

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 *ResourceSet[Resource]) (*QueryDecoder[Resource, Request], error)

func (*QueryDecoder[Resource, Request]) Decode added in v0.0.3

func (d *QueryDecoder[Resource, Request]) Decode(request *http.Request, userPermissions UserPermissions) (*QuerySet[Resource], error)

func (*QueryDecoder[Resource, Request]) DecodeWithoutPermissions added in v0.0.17

func (d *QueryDecoder[Resource, Request]) DecodeWithoutPermissions(request *http.Request) (*QuerySet[Resource], error)

type QueryParam added in v0.1.12

type QueryParam struct {
	Name  string
	Value any
}

QueryParam holds a single query parameter's name and value.

type QuerySet

type QuerySet[Resource Resourcer] struct {
	// contains filtered or unexported fields
}

func NewQuerySet

func NewQuerySet[Resource Resourcer](rMeta *ResourceMetadata[Resource]) *QuerySet[Resource]

func (*QuerySet[Resource]) AddField

func (q *QuerySet[Resource]) AddField(field accesstypes.Field) *QuerySet[Resource]

func (*QuerySet[Resource]) Columns added in v0.0.3

func (q *QuerySet[Resource]) Columns() (Columns, error)

Columns returns the database struct tags for the fields in databaseType that the user has access to view.

func (*QuerySet[Resource]) EnableUserPermissionEnforcement added in v0.0.17

func (q *QuerySet[Resource]) EnableUserPermissionEnforcement(rSet *ResourceSet[Resource], userPermissions UserPermissions, requiredPermission accesstypes.Permission) *QuerySet[Resource]

func (*QuerySet[Resource]) Fields

func (q *QuerySet[Resource]) Fields() []accesstypes.Field

func (*QuerySet[Resource]) Key added in v0.0.3

func (q *QuerySet[Resource]) Key(field accesstypes.Field) any

func (*QuerySet[Resource]) KeySet added in v0.0.3

func (q *QuerySet[Resource]) KeySet() KeySet

func (*QuerySet[Resource]) Len

func (q *QuerySet[Resource]) Len() int

func (*QuerySet[Resource]) PostgresStmt added in v0.0.3

func (q *QuerySet[Resource]) PostgresStmt() (*PostgresStatement, error)

func (*QuerySet[Resource]) RequiredPermission added in v0.0.17

func (q *QuerySet[Resource]) RequiredPermission() accesstypes.Permission

func (*QuerySet[Resource]) Resource added in v0.0.3

func (q *QuerySet[Resource]) Resource() accesstypes.Resource

func (*QuerySet[Resource]) ReturnAccessableFields added in v0.0.17

func (q *QuerySet[Resource]) ReturnAccessableFields(b bool) *QuerySet[Resource]

func (*QuerySet[Resource]) SetFilterAst added in v0.1.13

func (q *QuerySet[Resource]) SetFilterAst(ast ExpressionNode)

func (*QuerySet[Resource]) SetKey added in v0.0.3

func (q *QuerySet[Resource]) SetKey(field accesstypes.Field, value any)

func (*QuerySet[Resource]) SetLimit added in v0.2.7

func (q *QuerySet[Resource]) SetLimit(limit *uint64)

func (*QuerySet[Resource]) SetSearchParam added in v0.0.13

func (q *QuerySet[Resource]) SetSearchParam(search *Search)

func (*QuerySet[Resource]) SetSortFields added in v0.1.13

func (q *QuerySet[Resource]) SetSortFields(sortFields []SortField)

func (*QuerySet[Resource]) SetWhereClause added in v0.0.19

func (q *QuerySet[Resource]) SetWhereClause(qc QueryClause)

func (*QuerySet[Resource]) SpannerList added in v0.0.3

func (q *QuerySet[Resource]) SpannerList(ctx context.Context, db spxapi.Querier) iter.Seq2[*Resource, error]

func (*QuerySet[Resource]) SpannerRead added in v0.0.3

func (q *QuerySet[Resource]) SpannerRead(ctx context.Context, db spxapi.Querier) (*Resource, error)

func (*QuerySet[Resource]) SpannerStmt added in v0.0.3

func (q *QuerySet[Resource]) SpannerStmt() (*SpannerStatement, error)

type RPCDecoder added in v0.1.0

type RPCDecoder[Request any] struct {
	// contains filtered or unexported fields
}

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)

func (*RPCDecoder[Request]) Decode added in v0.1.0

func (r *RPCDecoder[Request]) Decode(request *http.Request) (*Request, error)

func (*RPCDecoder[Request]) WithValidator added in v0.1.0

func (s *RPCDecoder[Request]) WithValidator(v ValidatorFunc) *RPCDecoder[Request]

type RequestFieldMapper added in v0.0.17

type RequestFieldMapper struct {
	// contains filtered or unexported fields
}

func NewRequestFieldMapper added in v0.0.17

func NewRequestFieldMapper(v any) (*RequestFieldMapper, error)

func (*RequestFieldMapper) Fields added in v0.0.17

func (f *RequestFieldMapper) Fields() []accesstypes.Field

func (*RequestFieldMapper) Len added in v0.0.17

func (f *RequestFieldMapper) Len() int

func (*RequestFieldMapper) StructFieldName added in v0.0.17

func (f *RequestFieldMapper) StructFieldName(jsonTag string) (accesstypes.Field, bool)

type ResourceMetadata added in v0.0.3

type ResourceMetadata[Resource Resourcer] struct {
	// contains filtered or unexported fields
}

func NewResourceMetadata added in v0.0.3

func NewResourceMetadata[Resource Resourcer]() *ResourceMetadata[Resource]

func (*ResourceMetadata[Resource]) Fields added in v0.0.17

func (r *ResourceMetadata[Resource]) Fields() []accesstypes.Field

func (*ResourceMetadata[Resource]) Len added in v0.0.17

func (r *ResourceMetadata[Resource]) Len() int

type ResourceSet

type ResourceSet[Resource Resourcer] struct {
	// contains filtered or unexported fields
}

func NewResourceSet

func NewResourceSet[Resource Resourcer, Request any](permissions ...accesstypes.Permission) (*ResourceSet[Resource], error)

func (*ResourceSet[Resource]) BaseResource

func (r *ResourceSet[Resource]) BaseResource() accesstypes.Resource

func (*ResourceSet[Resource]) ImmutableFields

func (r *ResourceSet[Resource]) ImmutableFields() map[accesstypes.Tag]struct{}

func (*ResourceSet[Resource]) PermissionRequired

func (r *ResourceSet[Resource]) PermissionRequired(fieldName accesstypes.Field, perm accesstypes.Permission) bool

func (*ResourceSet[Resource]) Permissions

func (r *ResourceSet[Resource]) Permissions() []accesstypes.Permission

func (*ResourceSet[Resource]) Resource

func (r *ResourceSet[Resource]) Resource(fieldName accesstypes.Field) accesstypes.Resource

func (*ResourceSet[Resource]) ResourceMetadata added in v0.0.3

func (r *ResourceSet[Resource]) ResourceMetadata() *ResourceMetadata[Resource]

func (*ResourceSet[Resource]) TagPermissions

func (r *ResourceSet[Resource]) TagPermissions() accesstypes.TagPermissions

type Resourcer

type Resourcer interface {
	Resource() accesstypes.Resource
	DefaultConfig() Config
}

type RunnerFunc added in v0.0.21

type RunnerFunc func(ctx context.Context, txn TxnBuffer) error

RunnerFunc is a function that converts a TxnFuncRunner into a TxnRunner

func (RunnerFunc) Execute added in v0.0.21

func (fn RunnerFunc) Execute(ctx context.Context, txn TxnBuffer) error

type SQLDialect added in v0.1.12

type SQLDialect int

SQLDialect defines the type of SQL dialect to generate.

const (
	PostgreSQL SQLDialect = iota
	Spanner
)
type Search struct {
	// contains filtered or unexported fields
}

func NewSearch added in v0.1.13

func NewSearch(typ SearchType, values map[SearchKey]string) *Search

type SearchKey added in v0.0.13

type SearchKey string

func (SearchKey) String added in v0.1.13

func (f SearchKey) String() string

type SearchKeys added in v0.0.13

type SearchKeys struct {
	// contains filtered or unexported fields
}

func NewSearchKeys added in v0.0.13

func NewSearchKeys[Req any](res Resourcer) *SearchKeys

type SearchType added in v0.0.13

type SearchType string
const (
	SubString SearchType = "substring"
	FullText  SearchType = "fulltext"
	Ngram     SearchType = "ngram"
)

type SortDirection added in v0.1.13

type SortDirection string

SortDirection defines the sort direction for a field.

const (
	SortAscending  SortDirection = "asc"
	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 SpannerBuffer added in v0.0.18

type SpannerBuffer interface {
	SpannerBuffer(ctx context.Context, txn TxnBuffer, eventSource ...string) error
}

SpannerBuffer is an interface implemented by *PatchSet that buffers its mutations in the *spanner.ReadWriteTransaction provided by TxnBuffer

type SpannerCommitter added in v0.0.21

type SpannerCommitter interface {
	ReadWriteTransaction(ctx context.Context, f func(context.Context, *spanner.ReadWriteTransaction) error) (commitTimestamp time.Time, err error)
}

SpannerCommitter is an interface implemented by *spanner.Client and is used by PatchSet to allow mocking of *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 SpannerStatement added in v0.1.12

type SpannerStatement struct {
	spanner.Statement
	// contains filtered or unexported fields
}

type Statement added in v0.0.13

type Statement struct {
	SQL              string
	SpannerParams    map[string]any
	PostgreSQLParams []any
}

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)

func (*StructDecoder[Request]) Decode added in v0.0.3

func (s *StructDecoder[Request]) Decode(request *http.Request) (*Request, error)

func (*StructDecoder[Request]) WithValidator added in v0.0.3

func (s *StructDecoder[Request]) WithValidator(v ValidatorFunc) *StructDecoder[Request]

type Token added in v0.1.12

type Token struct {
	Type  TokenType
	Value string
}

Token represents a single token.

type TokenType added in v0.1.12

type TokenType int

TokenType defines the types of tokens in the filter string.

const (
	TokenEOF       TokenType = iota // End of File
	TokenLParen                     // (
	TokenRParen                     // )
	TokenComma                      // ,
	TokenPipe                       // |
	TokenCondition                  // field:operator:value or field:operator:(value1,value2,...) or field:operator
)

func (TokenType) String added in v0.1.12

func (i TokenType) String() string

type TxnBuffer added in v0.0.21

type TxnBuffer interface {
	BufferWrite(ms []*spanner.Mutation) error
	spxapi.Querier
}

TxnBuffer is an interface implemented by *spanner.ReadWriteTransaction, and is used by PatchSet to allow mocking of *spanner.ReadWriteTransaction

type TxnFuncRunner added in v0.0.21

type TxnFuncRunner interface {
	ExecuteFunc(ctx context.Context, runnerFn func(ctx context.Context, txn TxnBuffer) error) error
}

TxnFuncRunner will have its ExecuteFunc() method called inside the *spanner.ReadWriteTransaction provided by TxnBuffer

type TxnRunner added in v0.0.21

type TxnRunner interface {
	Execute(ctx context.Context, txn TxnBuffer) error
}

TxnRunner will have its Execute() method called inside the *spanner.ReadWriteTransaction provided by TxnBuffer

type TypescriptData added in v0.0.10

type TypescriptData struct {
	Permissions           []accesstypes.Permission
	ResourcePermissions   []accesstypes.Permission
	Resources             []accesstypes.Resource
	RPCMethods            []accesstypes.Resource
	ResourceTags          map[accesstypes.Resource][]accesstypes.Tag
	ResourcePermissionMap permissionMap
	Domains               []accesstypes.PermissionScope
}

type UserFromCtx added in v0.0.3

type UserFromCtx func(context.Context) accesstypes.User

type UserFromReq added in v0.0.3

type UserFromReq func(*http.Request) accesstypes.User

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 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

Directories

Path Synopsis
package generation provides the ability to generate resource, handler, and typescript permissions and metadata code from a resource file.
package generation provides the ability to generate resource, handler, and typescript permissions and metadata code from a resource file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL