mapping

package
v0.6.3-kompitech1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const KeyRefNamespace = `_idx`

KeyRefNamespace namespace for uniq indexes

Variables

View Source
var (
	// ErrEntryTypeNotSupported entry type has no appropriate mapper type
	ErrEntryTypeNotSupported = errors.New(`entry type not supported for mapping`)

	// ErrStateMappingNotFound  occurs when mapping for state entry is not defined
	ErrStateMappingNotFound = errors.New(`state mapping not found`)

	// ErrEventMappingNotFound occurs when mapping for event is not defined
	ErrEventMappingNotFound = errors.New(`event mapping not found`)

	// ErrFieldTypeNotSupportedForKeyExtraction key cannot extracted from field
	ErrFieldTypeNotSupportedForKeyExtraction = errors.New(`field type not supported for key extraction`)

	ErrMappingUniqKeyExists = errors.New(`mapping uniq key exists`)

	ErrFieldNotExists         = errors.New(`field is not exists`)
	ErrPrimaryKeyerNotDefined = errors.New(`primary keyer is not defined`)
)
View Source
var KeyRefIDKeyer = attrsPKeyer([]string{`Schema`, `Idx`, `RefKey`})

KeyRefIDKeyer keyer for KeyRef entity

View Source
var KeyRefIDMapper = &StateMapping{
	schema:       &schema.KeyRefId{},
	namespace:    state.Key{KeyRefNamespace},
	primaryKeyer: KeyRefIDKeyer,
}
View Source
var KeyRefMapper = &StateMapping{
	schema:       &schema.KeyRef{},
	namespace:    state.Key{KeyRefNamespace},
	primaryKeyer: KeyRefIDKeyer,
}

Functions

func MapEvents

func MapEvents(eventMappings EventMappings) router.MiddlewareFunc

func MapStates

func MapStates(stateMappings StateMappings) router.MiddlewareFunc

func NewKeyRef

func NewKeyRef(target interface{}, idx string, refKey, pKey state.Key) *schema.KeyRef

func NewKeyRefID

func NewKeyRefID(target interface{}, idx string, refKey state.Key) *schema.KeyRefId

func SchemaNamespace

func SchemaNamespace(schema interface{}) state.Key

Types

type EventImpl

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

func NewEvent

func NewEvent(stub shim.ChaincodeStubInterface, mappings EventMappings) *EventImpl

func WrapEvent

func WrapEvent(event state.Event, mappings EventMappings) *EventImpl

func (*EventImpl) Set

func (e *EventImpl) Set(entry interface{}, value ...interface{}) error

func (*EventImpl) UseNameTransformer

func (e *EventImpl) UseNameTransformer(nt state.StringTransformer) state.Event

func (*EventImpl) UseSetTransformer

func (e *EventImpl) UseSetTransformer(tb state.ToBytesTransformer) state.Event

type EventMapped

type EventMapped interface {
	state.NameValue
}

type EventMapper

type EventMapper interface {
	Schema() interface{}
	Name(instance interface{}) (string, error)
}

type EventMappers

type EventMappers interface {
	Exists(schema interface{}) (exists bool)
	Map(schema interface{}) (keyValue state.KeyValue, err error)
	Get(schema interface{}) (eventMapper EventMapper, err error)
}

type EventMapping

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

func (EventMapping) Name

func (em EventMapping) Name(instance interface{}) (string, error)

func (EventMapping) Schema

func (em EventMapping) Schema() interface{}

type EventMappingOpt

type EventMappingOpt func(*EventMapping)

type EventMappings

type EventMappings map[string]*EventMapping

func (EventMappings) Add

func (emm EventMappings) Add(schema interface{}, opts ...EventMappingOpt) EventMappings

func (EventMappings) Exists

func (emm EventMappings) Exists(entry interface{}) bool

func (EventMappings) Get

func (emm EventMappings) Get(entry interface{}) (EventMapper, error)

func (EventMappings) Map

func (emm EventMappings) Map(entry interface{}) (mapped EventMapped, err error)

type Impl

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

func WrapState

func WrapState(s state.State, mappings StateMappings) *Impl

func (*Impl) Delete

func (s *Impl) Delete(entry interface{}) error

func (*Impl) DeletePrivate

func (s *Impl) DeletePrivate(collection string, entry interface{}) (err error)

func (*Impl) Exists

func (s *Impl) Exists(entry interface{}) (bool, error)

func (*Impl) ExistsPrivate

func (s *Impl) ExistsPrivate(collection string, entry interface{}) (exists bool, err error)

func (*Impl) Get

func (s *Impl) Get(entry interface{}, target ...interface{}) (interface{}, error)

func (*Impl) GetByUniqKey

func (s *Impl) GetByUniqKey(
	entry interface{}, idx string, idxVal []string, target ...interface{}) (result interface{}, err error)

func (*Impl) GetHistory

func (s *Impl) GetHistory(entry interface{}, target interface{}) (state.HistoryEntryList, error)

func (*Impl) GetInt

func (s *Impl) GetInt(entry interface{}, defaultValue int) (int, error)

func (*Impl) GetPrivate

func (s *Impl) GetPrivate(collection string, entry interface{}, target ...interface{}) (result interface{}, err error)

func (*Impl) Insert

func (s *Impl) Insert(entry interface{}, value ...interface{}) error

func (*Impl) InsertPrivate

func (s *Impl) InsertPrivate(collection string, entry interface{}, value ...interface{}) (err error)

func (*Impl) List

func (s *Impl) List(entry interface{}, target ...interface{}) (interface{}, error)

func (*Impl) ListPrivate

func (s *Impl) ListPrivate(collection string, usePrivateDataIterator bool, namespace interface{}, target ...interface{}) (result interface{}, err error)

func (*Impl) ListWith

func (s *Impl) ListWith(entry interface{}, key state.Key) (result interface{}, err error)

func (*Impl) Logger

func (s *Impl) Logger() *shim.ChaincodeLogger

func (*Impl) MappingNamespace

func (s *Impl) MappingNamespace(schema interface{}) (state.Key, error)

func (*Impl) Put

func (s *Impl) Put(entry interface{}, value ...interface{}) error

func (*Impl) PutPrivate

func (s *Impl) PutPrivate(collection string, entry interface{}, value ...interface{}) (err error)

func (*Impl) UseKeyTransformer

func (s *Impl) UseKeyTransformer(kt state.KeyTransformer) state.State

func (*Impl) UseStateGetTransformer

func (s *Impl) UseStateGetTransformer(fb state.FromBytesTransformer) state.State

func (*Impl) UseStatePutTransformer

func (s *Impl) UseStatePutTransformer(tb state.ToBytesTransformer) state.State

type InstanceKeyer

type InstanceKeyer func(instance interface{}) (key state.Key, err error)

InstanceKeyer returns key of an state entry instance

type MappedState

type MappedState interface {
	state.State

	// ListWith allows to refine search criteria by adding to namespace key parts
	ListWith(schema interface{}, key state.Key) (result interface{}, err error)

	// GetByUniqKey return one entry
	GetByUniqKey(schema interface{}, idx string, idxVal []string, target ...interface{}) (result interface{}, err error)
}

type Namer

type Namer func(entity interface{}) string

type ProtoEventMapped

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

func NewProtoEventMapped

func NewProtoEventMapped(instance interface{}, eventMapper EventMapper) (*ProtoEventMapped, error)

func (*ProtoEventMapped) Name

func (em *ProtoEventMapped) Name() (string, error)

func (*ProtoEventMapped) ToBytes

func (em *ProtoEventMapped) ToBytes() ([]byte, error)

type ProtoStateMapped

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

func NewKeyRefIDMapped

func NewKeyRefIDMapped(target interface{}, idx string, refKey state.Key) *ProtoStateMapped

func NewKeyRefMapped

func NewKeyRefMapped(target interface{}, idx string, refKey, pKey state.Key) *ProtoStateMapped

func NewProtoStateMapped

func NewProtoStateMapped(instance interface{}, stateMapper StateMapper) *ProtoStateMapped

func (*ProtoStateMapped) Key

func (pm *ProtoStateMapped) Key() (state.Key, error)

func (*ProtoStateMapped) Keys

func (pm *ProtoStateMapped) Keys() ([]state.KeyValue, error)

func (*ProtoStateMapped) Mapper

func (pm *ProtoStateMapped) Mapper() StateMapper

func (*ProtoStateMapped) ToBytes

func (pm *ProtoStateMapped) ToBytes() ([]byte, error)

type StateKeyDefinition

type StateKeyDefinition struct {
	Name  string
	Attrs []string
}

StateKeyDefinition

type StateMapped

type StateMapped interface {
	state.KeyValue // entry key and value
	Mapper() StateMapper
	Keys() ([]state.KeyValue, error)
}

type StateMapper

type StateMapper interface {
	Schema() interface{}
	List() interface{}
	Namespace() state.Key
	PrimaryKey(instance interface{}) (key state.Key, err error)
	Keys(instance interface{}) (key []state.KeyValue, err error)
	KeyerFor() interface{}
}

StateMapper

type StateMappers

type StateMappers interface {
	Exists(schema interface{}) (exists bool)
	Map(schema interface{}) (keyValue state.KeyValue, err error)
	Get(schema interface{}) (stateMapper StateMapper, err error)
	PrimaryKey(schema interface{}) (key state.Key, err error)
}

StateMappers interface for mappers collection

type StateMapping

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

StateMapping defines metadata for mapping from schema to state keys/values

func (*StateMapping) KeyerFor

func (sm *StateMapping) KeyerFor() interface{}

func (*StateMapping) Keys

func (sm *StateMapping) Keys(entity interface{}) (kv []state.KeyValue, err error)

func (*StateMapping) List

func (sm *StateMapping) List() interface{}

func (*StateMapping) Namespace

func (sm *StateMapping) Namespace() state.Key

func (*StateMapping) PrimaryKey

func (sm *StateMapping) PrimaryKey(entity interface{}) (state.Key, error)

func (*StateMapping) Schema

func (sm *StateMapping) Schema() interface{}

type StateMappingOpt

type StateMappingOpt func(*StateMapping, StateMappings)

func KeyerFor

func KeyerFor(schema interface{}) StateMappingOpt

func List

func List(list proto.Message) StateMappingOpt

List defined list container, it must have `Items` attr

func PKeyAttr

func PKeyAttr(attrs ...string) StateMappingOpt

func PKeyComplexId

func PKeyComplexId(pkeySchema interface{}) StateMappingOpt

PKeyComplexId sets Id as key field, also adds mapping for pkeySchema with namespace from mapping schema

func PKeyConst

func PKeyConst(key state.Key) StateMappingOpt

PKeyConst use constant as state entry key

func PKeyId

func PKeyId() StateMappingOpt

PKeyId use Id attr as source for mapped state entry key

func PKeySchema

func PKeySchema(pkeySchema interface{}) StateMappingOpt

PKeySchema registers all fields from pkeySchema as part of primary key also register keyer for pkeySchema with with namespace from current schema

func PKeyer

func PKeyer(pkeyer InstanceKeyer) StateMappingOpt

func StateNamespace

func StateNamespace(namespace state.Key) StateMappingOpt

StateNamespace sets namespace for mapping

func UniqKey

func UniqKey(name string, attrs ...[]string) StateMappingOpt

type StateMappings

type StateMappings map[string]*StateMapping

func (StateMappings) Add

func (smm StateMappings) Add(schema interface{}, opts ...StateMappingOpt) StateMappings

func (StateMappings) Exists

func (smm StateMappings) Exists(entry interface{}) bool

func (StateMappings) Get

func (smm StateMappings) Get(entry interface{}) (StateMapper, error)

Get mapper for mapped entry

func (StateMappings) GetByNamespace

func (smm StateMappings) GetByNamespace(namespace state.Key) (StateMapper, error)

Get mapper by string namespace. It can be used in block explorer: we know state key, but don't know type actually mapped to state

func (*StateMappings) IdxKey

func (smm *StateMappings) IdxKey(entity interface{}, idx string, idxVal state.Key) (state.Key, error)

func (StateMappings) Map

func (smm StateMappings) Map(entry interface{}) (mapped StateMapped, err error)

func (StateMappings) PrimaryKey

func (smm StateMappings) PrimaryKey(entry interface{}) (pkey state.Key, err error)

Jump to

Keyboard shortcuts

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