entity

package
Version: v0.0.0-...-b45a7ae Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package entity contains all logic for entity definition, entity commands, entity events, and manipulation with entities.

Index

Constants

View Source
const (
	CommandUpdateKey = CommandKey("update")
)

Variables

This section is empty.

Functions

func NewTypedCommands

func NewTypedCommands(commands map[TypeCommandKey]interface{})

Types

type Accessor

type Accessor interface {
	Get(id int64) (Instance, error)
	GetAll() ([]Instance, error)

	Find(attributes map[string]values.Value, orderBy []query.OrderClause) ([]Instance, error)
	FindByQuery(q Query) ([]Instance, error)

	Create(attrs interface{}) (Instance, error)
	InvokeCommand(id int64, key CommandKey, input values.Values) (output values.Values, err error)
	Delete(id int64) error

	InvokeTypeCommand(key TypeCommandKey, input interface{}, output interface{}) error
}

type Command

type Command struct {
	Key CommandKey

	Function    CommandFunc
	InputFields field.StructType

	GetDefaultInputValuesFunction func(instance Instance) values.Values
}

func (Command) ProduceCommand

func (c Command) ProduceCommand(spec *Spec) Command

type CommandFunc

type CommandFunc func(instance Instance, input values.Values) (CommandResult, error)

type CommandKey

type CommandKey string

type CommandProducer

type CommandProducer interface {
	ProduceCommand(spec *Spec) Command
}

type CommandResult

type CommandResult struct {
	ReturnValues values.Values
	Events       []interface{}
}

type CommandUpdate

type CommandUpdate struct {
	FieldsToUpdate []string
	ExcludeFields  []string
}

func (CommandUpdate) ProduceCommand

func (c CommandUpdate) ProduceCommand(spec *Spec) Command

type CreatedEvent

type CreatedEvent struct {
	Reference Reference
}

func (CreatedEvent) AffectedEntity

func (e CreatedEvent) AffectedEntity() Reference

type Definition

type Definition struct {

	// TODO: don't export, and don't allow/provide whole map access (mutability issue), provide GetXYZByKey
	TypeCommands  map[TypeCommandKey]TypeCommand
	TypeFunctions map[TypeFuncKey]TypeFuncFunc
	// contains filtered or unexported fields
}

func NewDefinition

func NewDefinition(spec Spec) *Definition

func (*Definition) DisplayName

func (t *Definition) DisplayName() func(Instance) string

func (*Definition) Fields

func (t *Definition) Fields() field.StructType

func (*Definition) GetCommands

func (t *Definition) GetCommands() map[CommandKey]Command

func (*Definition) GetName

func (t *Definition) GetName() string

func (*Definition) GetNamePlural

func (t *Definition) GetNamePlural() string

func (*Definition) Key

func (t *Definition) Key() Key

type Event

type Event interface {
	AffectedEntity() Reference
}

type Executor

type Executor interface {
	SubmitWithCompleteLock(f func())
	SubmitWithInstanceLock(id int64, f func())
	ExecuteSynchronouslyWithCompleteLock(f func())
	ExecuteSynchronouslyWithInstanceLock(id int64, f func())
}

type ExecutorProvider

type ExecutorProvider interface {
	Get(key string) Executor
}

type FuncCommandProducer

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

func NewFuncCommand

func NewFuncCommand(key CommandKey, f CommandFunc) *FuncCommandProducer

func (*FuncCommandProducer) ProduceCommand

func (f *FuncCommandProducer) ProduceCommand(spec *Spec) Command

type Instance

type Instance interface {
	Reference() Reference

	GetId() int64
	SetId(id int64)
	GetRevision() int64
	GetAllAttributes() values.Values
	SetAllAttributes(values values.Values)
	GetAttribute(name string) (value interface{})
	SetAttribute(name string, value interface{})

	DisplayName() string

	// TODO: this is wrong
	GetTableName() string
}

type Key

type Key string

func (Key) Reference

func (key Key) Reference(id int64) Reference

type Query

type Query struct {
	Root Key

	Where query.Expression

	SortBy []query.OrderClause
}

type Reference

type Reference struct {
	EntityName  Key
	ReferenceId int64
}

func (*Reference) UnmarshalJSON

func (e *Reference) UnmarshalJSON(raw []byte) error

type Repository

type Repository interface {
	Store(entity Instance, events []interface{}) error
	Find() ([]Instance, error)
	Get(id int64) (Instance, error)
	Remove(instance Instance) error

	// TODO: query should be DTO with tree structure containing clauses/conditions
	FindByQuery(query string, params []interface{}, orderBy []query.OrderClause) []Instance
}

Repository interface defines contract for entity persistence.

type Spec

type Spec struct {
	Uname Key

	Name        string
	NamePlural  string
	Description string

	DisplayName func(Instance) string

	Fields field.StructType

	Commands []CommandProducer

	TypeCommands  []TypeCommand
	TypeFunctions map[TypeFuncKey]TypeFuncFunc
}

type TypeCommand

type TypeCommand struct {
	Key  TypeCommandKey
	Func TypeCommandFunc
}

func NewTypedEntityTypeCommand

func NewTypedEntityTypeCommand(key TypeCommandKey, function interface{}) TypeCommand

type TypeCommandExecutionContext

type TypeCommandExecutionContext struct {
	EntityFactory func(values values.Values) Instance
	Repository    Repository
}

type TypeCommandFunc

type TypeCommandFunc func(context *TypeCommandExecutionContext, input values.Holder) (output values.Values, err error)

type TypeCommandKey

type TypeCommandKey string

type TypeFuncFunc

type TypeFuncFunc func(repository Accessor, input values.Holder) (output values.Values, err error)

type TypeFuncKey

type TypeFuncKey string

type UpdatedEvent

type UpdatedEvent struct {
	Reference Reference
}

func (UpdatedEvent) AffectedEntity

func (e UpdatedEvent) AffectedEntity() Reference

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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