Documentation
¶
Index ¶
- Constants
- Variables
- func NewIdTool(dp structs.DirectiveProvider) *structs.Tool
- func NewInstance[I Instance[I]](ctx context.Context, sub auth.Subject) (I, gomerr.Gomerr)
- func Register[I Instance[I]](r *Registry, opts ...Option)
- type Action
- type AnyAction
- type BaseInstance
- func (b *BaseInstance[I]) Create(ctx context.Context) (I, gomerr.Gomerr)
- func (b *BaseInstance[I]) Delete(ctx context.Context) (I, gomerr.Gomerr)
- func (b *BaseInstance[I]) Id() string
- func (b *BaseInstance[I]) Ids() []string
- func (b *BaseInstance[I]) NewQueryable() data.Queryable
- func (*BaseInstance[I]) PostCreate(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PostDelete(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PostRead(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PostUpdate(context.Context, I) gomerr.Gomerr
- func (*BaseInstance[I]) PreCreate(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PreDelete(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PreList(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PreRead(context.Context) gomerr.Gomerr
- func (*BaseInstance[I]) PreUpdate(context.Context, I) gomerr.Gomerr
- func (b *BaseInstance[I]) Read(ctx context.Context) (I, gomerr.Gomerr)
- func (*BaseInstance[I]) RetryCreate(_ context.Context, ge gomerr.Gomerr) gomerr.Gomerr
- func (*BaseInstance[I]) RetryDelete(_ context.Context, ge gomerr.Gomerr) gomerr.Gomerr
- func (*BaseInstance[I]) RetryRead(_ context.Context, ge gomerr.Gomerr) gomerr.Gomerr
- func (*BaseInstance[I]) RetryUpdate(_ context.Context, _ I, ge gomerr.Gomerr) gomerr.Gomerr
- func (b *BaseInstance[I]) TypeName() string
- func (b *BaseInstance[I]) Update(ctx context.Context) (I, gomerr.Gomerr)
- type BaseResource
- type Category
- type Collectible
- type Collection
- func (c *Collection[I]) ConsistencyType() dynamodb.ConsistencyType
- func (c *Collection[I]) DoAction(ctx context.Context, action Action[*Collection[I]]) (*Collection[I], gomerr.Gomerr)
- func (c *Collection[I]) ItemTemplate() any
- func (c *Collection[I]) MaximumPageSize() int
- func (c *Collection[I]) NextPageToken() *string
- func (*Collection[I]) PostList(_ context.Context) gomerr.Gomerr
- func (*Collection[I]) PreList(_ context.Context) gomerr.Gomerr
- func (c *Collection[I]) Query(ctx context.Context) gomerr.Gomerr
- func (c *Collection[I]) Results() []any
- func (*Collection[I]) RetryList(_ context.Context, ge gomerr.Gomerr) gomerr.Gomerr
- func (c *Collection[I]) SetConsistencyType(consistencyType dynamodb.ConsistencyType)
- func (c *Collection[I]) SetNextPageToken(token *string)
- func (c *Collection[I]) SetResults(items []any)
- func (c *Collection[I]) Subject() auth.Subject
- func (c *Collection[I]) TypeName() string
- type Instance
- type NoOpAction
- func (NoOpAction[T]) AppliesToCategory() Category
- func (NoOpAction[T]) Do(_ context.Context, _ T) gomerr.Gomerr
- func (NoOpAction[T]) FieldAccessPermissions() auth.AccessPermissions
- func (NoOpAction[T]) Name() string
- func (NoOpAction[T]) OnDoFailure(_ context.Context, _ T, ge gomerr.Gomerr) gomerr.Gomerr
- func (NoOpAction[T]) OnDoSuccess(_ context.Context, r T) (T, gomerr.Gomerr)
- func (NoOpAction[T]) Pre(_ context.Context, _ T) gomerr.Gomerr
- func (NoOpAction[T]) Retry(_ context.Context, ge gomerr.Gomerr) gomerr.Gomerr
- type OnCreateFailer
- type OnDeleteFailer
- type OnListFailer
- type OnReadFailer
- type OnUpdateFailer
- type Option
- type RegisteredType
- type Registry
- type Resource
Constants ¶
const SourceValue = "$_source_value"
Variables ¶
var DefaultIdFieldTool = NewIdTool(structs.StructTagDirectiveProvider{"id"})
var IdTool = DefaultIdFieldTool
IdTool is an alias for DefaultIdFieldTool for backward compatibility.
var RegistryCtxKey = registryCtxKey{}
RegistryCtxKey is the context key for storing/retrieving a Registry.
Functions ¶
func NewIdTool ¶
func NewIdTool(dp structs.DirectiveProvider) *structs.Tool
NewIdTool produces a structs.Applier that will take each of the defined id fields and propagate them to another struct value.
func NewInstance ¶ added in v0.2.0
NewInstance creates a new instance of type I. Retrieves the Registry from context automatically.
Types ¶
type Action ¶
type Action[T any] interface { AnyAction Pre(context.Context, T) gomerr.Gomerr Retry(context.Context, T, gomerr.Gomerr) gomerr.Gomerr Do(context.Context, T) gomerr.Gomerr OnDoSuccess(context.Context, T) (T, gomerr.Gomerr) OnDoFailure(context.Context, T, gomerr.Gomerr) gomerr.Gomerr }
Action defines an operation that can be performed on a resource.
func CreateAction ¶
CreateAction returns an action for creating instances.
func DeleteAction ¶
DeleteAction returns an action for deleting instances.
func ListAction ¶
func ListAction[I Instance[I]]() Action[*Collection[I]]
ListAction returns an action for listing instances via a collection.
func ReadAction ¶
ReadAction returns an action for reading instances.
func UpdateAction ¶
UpdateAction returns an action for updating instances.
type BaseInstance ¶
type BaseInstance[I Instance[I]] struct { BaseResource[I] }
BaseInstance provides the default implementation for Instance[I]. Embed this in concrete instance types.
func (*BaseInstance[I]) Create ¶ added in v0.2.0
func (b *BaseInstance[I]) Create(ctx context.Context) (I, gomerr.Gomerr)
func (*BaseInstance[I]) Delete ¶ added in v0.2.0
func (b *BaseInstance[I]) Delete(ctx context.Context) (I, gomerr.Gomerr)
func (*BaseInstance[I]) Id ¶
func (b *BaseInstance[I]) Id() string
func (*BaseInstance[I]) Ids ¶ added in v0.4.0
func (b *BaseInstance[I]) Ids() []string
func (*BaseInstance[I]) NewQueryable ¶
func (b *BaseInstance[I]) NewQueryable() data.Queryable
NewQueryable creates a Collection for querying instances of this type. Implements data.Persistable.
func (*BaseInstance[I]) PostCreate ¶
func (*BaseInstance[I]) PostCreate(context.Context) gomerr.Gomerr
func (*BaseInstance[I]) PostDelete ¶
func (*BaseInstance[I]) PostDelete(context.Context) gomerr.Gomerr
func (*BaseInstance[I]) PostUpdate ¶
func (*BaseInstance[I]) PostUpdate(context.Context, I) gomerr.Gomerr
func (*BaseInstance[I]) PreCreate ¶
func (*BaseInstance[I]) PreCreate(context.Context) gomerr.Gomerr
func (*BaseInstance[I]) PreDelete ¶
func (*BaseInstance[I]) PreDelete(context.Context) gomerr.Gomerr
func (*BaseInstance[I]) PreList ¶ added in v0.4.0
func (*BaseInstance[I]) PreList(context.Context) gomerr.Gomerr
func (*BaseInstance[I]) PreUpdate ¶
func (*BaseInstance[I]) PreUpdate(context.Context, I) gomerr.Gomerr
func (*BaseInstance[I]) Read ¶ added in v0.2.0
func (b *BaseInstance[I]) Read(ctx context.Context) (I, gomerr.Gomerr)
func (*BaseInstance[I]) RetryCreate ¶ added in v0.3.1
func (*BaseInstance[I]) RetryDelete ¶ added in v0.3.1
func (*BaseInstance[I]) RetryUpdate ¶ added in v0.3.1
func (*BaseInstance[I]) TypeName ¶
func (b *BaseInstance[I]) TypeName() string
type BaseResource ¶
type BaseResource[T Resource[T]] struct { // contains filtered or unexported fields }
BaseResource provides the default implementation for Resource[T]. Embed this in concrete resource types.
func (*BaseResource[T]) RegisteredType ¶ added in v0.4.0
func (b *BaseResource[T]) RegisteredType() RegisteredType
func (*BaseResource[T]) Self ¶ added in v0.4.0
func (b *BaseResource[T]) Self() T
func (*BaseResource[T]) Subject ¶
func (b *BaseResource[T]) Subject() auth.Subject
type Category ¶
type Category string
Category indicates whether a resource is an Instance or Collection.
type Collectible ¶
Collectible is implemented by instances that want to be notified when collected.
type Collection ¶
type Collection[I Instance[I]] struct { Resource[*Collection[I]] Items []I `out:"+,includeempty"` NextToken *string `in:"query.next_token" out:"+"` MaxResults int `in:"query.max_results" validate:"intbetween(1,100)"` // TODO: "intbetween(1,$.MaximumPageSize()) // contains filtered or unexported fields }
Collection holds a set of instances resulting from a query. Unlike Instance, Collection is parameterized only by its item type, delegating resource identity to the instance type.
func NewCollection ¶ added in v0.2.0
func NewCollection[I Instance[I]](proto I) *Collection[I]
func (*Collection[I]) ConsistencyType ¶ added in v0.2.0
func (c *Collection[I]) ConsistencyType() dynamodb.ConsistencyType
func (*Collection[I]) DoAction ¶ added in v0.2.0
func (c *Collection[I]) DoAction(ctx context.Context, action Action[*Collection[I]]) (*Collection[I], gomerr.Gomerr)
func (*Collection[I]) ItemTemplate ¶ added in v0.2.0
func (c *Collection[I]) ItemTemplate() any
func (*Collection[I]) MaximumPageSize ¶ added in v0.2.0
func (c *Collection[I]) MaximumPageSize() int
func (*Collection[I]) NextPageToken ¶ added in v0.2.0
func (c *Collection[I]) NextPageToken() *string
func (*Collection[I]) PostList ¶ added in v0.2.0
func (*Collection[I]) PostList(_ context.Context) gomerr.Gomerr
func (*Collection[I]) PreList ¶ added in v0.2.0
func (*Collection[I]) PreList(_ context.Context) gomerr.Gomerr
func (*Collection[I]) Query ¶ added in v0.2.0
func (c *Collection[I]) Query(ctx context.Context) gomerr.Gomerr
func (*Collection[I]) Results ¶ added in v0.2.0
func (c *Collection[I]) Results() []any
Results implements data.Queryable with []any.
func (*Collection[I]) SetConsistencyType ¶ added in v0.2.0
func (c *Collection[I]) SetConsistencyType(consistencyType dynamodb.ConsistencyType)
func (*Collection[I]) SetNextPageToken ¶ added in v0.2.0
func (c *Collection[I]) SetNextPageToken(token *string)
func (*Collection[I]) SetResults ¶ added in v0.2.0
func (c *Collection[I]) SetResults(items []any)
SetResults implements data.Queryable with []any.
func (*Collection[I]) Subject ¶ added in v0.2.0
func (c *Collection[I]) Subject() auth.Subject
func (*Collection[I]) TypeName ¶ added in v0.2.0
func (c *Collection[I]) TypeName() string
type Instance ¶
type Instance[I Resource[I]] interface { Resource[I] data.Persistable // TypeName() string, NewQueryable() data.Queryable Id() string PreCreate(context.Context) gomerr.Gomerr RetryCreate(context.Context, gomerr.Gomerr) gomerr.Gomerr PostCreate(context.Context) gomerr.Gomerr PreRead(context.Context) gomerr.Gomerr RetryRead(context.Context, gomerr.Gomerr) gomerr.Gomerr PostRead(context.Context) gomerr.Gomerr PreUpdate(context.Context, I) gomerr.Gomerr RetryUpdate(context.Context, I, gomerr.Gomerr) gomerr.Gomerr PostUpdate(context.Context, I) gomerr.Gomerr PreDelete(context.Context) gomerr.Gomerr RetryDelete(context.Context, gomerr.Gomerr) gomerr.Gomerr PostDelete(context.Context) gomerr.Gomerr PreList(context.Context) gomerr.Gomerr }
Instance extends Resource for individual entities. Instances have an identity (Id) and support CRUD operations.
type NoOpAction ¶
type NoOpAction[T any] struct{}
NoOpAction is an action that does nothing.
func (NoOpAction[T]) AppliesToCategory ¶ added in v0.2.0
func (NoOpAction[T]) AppliesToCategory() Category
func (NoOpAction[T]) FieldAccessPermissions ¶
func (NoOpAction[T]) FieldAccessPermissions() auth.AccessPermissions
func (NoOpAction[T]) Name ¶
func (NoOpAction[T]) Name() string
func (NoOpAction[T]) OnDoFailure ¶
func (NoOpAction[T]) OnDoSuccess ¶
func (NoOpAction[T]) OnDoSuccess(_ context.Context, r T) (T, gomerr.Gomerr)
type OnCreateFailer ¶
type OnCreateFailer[I Instance[I]] interface { OnCreateFailure(context.Context, gomerr.Gomerr) gomerr.Gomerr }
OnCreateFailer is implemented by instances that want custom failure handling for create.
type OnDeleteFailer ¶
type OnDeleteFailer[I Instance[I]] interface { OnDeleteFailure(context.Context, gomerr.Gomerr) gomerr.Gomerr }
OnDeleteFailer is implemented by instances that want custom failure handling for delete.
type OnListFailer ¶
type OnListFailer[I Instance[I]] interface { OnListFailure(context.Context, gomerr.Gomerr) gomerr.Gomerr }
OnListFailer is implemented by collections that want custom failure handling for list.
type OnReadFailer ¶
type OnReadFailer[I Instance[I]] interface { OnReadFailure(context.Context, gomerr.Gomerr) gomerr.Gomerr }
OnReadFailer is implemented by instances that want custom failure handling for read.
type OnUpdateFailer ¶
type OnUpdateFailer[I Instance[I]] interface { OnUpdateFailure(context.Context, gomerr.Gomerr) gomerr.Gomerr }
OnUpdateFailer is implemented by instances that want custom failure handling for update.
type Option ¶ added in v0.2.0
type Option func(*registeredType)
func WithActions ¶ added in v0.2.0
WithActions specifies the actions available for this resource.
func WithCollectionName ¶ added in v0.2.0
WithCollectionName overrides the plural/collection path name.
func WithInstanceName ¶ added in v0.2.0
WithInstanceName overrides the singular path name derived from the type name.
func WithParent ¶ added in v0.2.0
WithParent establishes a parent-child relationship with the specified resource type. Parents must be registered before their children.
type RegisteredType ¶ added in v0.2.0
type Registry ¶ added in v0.2.0
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all registered resource types.
func NewRegistry ¶ added in v0.2.0
func NewRegistry() *Registry
NewRegistry creates a new registry for resource registration.
func (*Registry) RootTypes ¶ added in v0.2.0
func (r *Registry) RootTypes() []RegisteredType
RootTypes returns all root-level registered resources.
type Resource ¶
type Resource[T any] interface { Subject() auth.Subject DoAction(context.Context, Action[T]) (T, gomerr.Gomerr) RegisteredType() RegisteredType // contains filtered or unexported methods }
Resource is the base interface for all domain resources. The type parameter T is the concrete type implementing the interface (F-bounded polymorphism).