Documentation ¶
Index ¶
- Constants
- Variables
- func EventNameForPayload(payload interface{}) string
- func KeyRefsDiff(prevKeys []state.KeyValue, newKeys []state.KeyValue) (deleted, inserted []state.KeyValue, err error)
- func MapEvents(eventMappings EventMappings) router.MiddlewareFunc
- func MapStates(stateMappings StateMappings) router.MiddlewareFunc
- func NewKeyRef(target interface{}, idx string, refKey, pKey state.Key) *schema.KeyRef
- func NewKeyRefID(target interface{}, idx string, refKey state.Key) *schema.KeyRefId
- func SchemaNamespace(schema interface{}) state.Key
- type Command
- type CommandInsert
- type CommandPut
- type Commands
- type EntryMapper
- type Event
- type EventImpl
- type EventInstance
- type EventMapper
- type EventMappers
- type EventMapping
- type EventMappingOpt
- type EventMappings
- func (emm EventMappings) Add(schema interface{}, opts ...EventMappingOpt) EventMappings
- func (emm EventMappings) Exists(entry interface{}) bool
- func (emm EventMappings) Get(entry interface{}) (EventMapper, error)
- func (emm EventMappings) Map(entry interface{}) (*EventInstance, error)
- func (emm EventMappings) Resolve(eventName string, payload []byte, ...) (event interface{}, err error)
- type EventResolver
- type Impl
- func (s *Impl) Delete(entry interface{}) error
- func (s *Impl) DeletePrivate(collection string, entry interface{}) (err error)
- func (s *Impl) Exists(entry interface{}) (bool, error)
- func (s *Impl) ExistsPrivate(collection string, entry interface{}) (exists bool, err error)
- func (s *Impl) Get(entry interface{}, target ...interface{}) (interface{}, error)
- func (s *Impl) GetByKey(entry interface{}, idx string, idxVal []string, target ...interface{}) (result interface{}, err error)
- func (s *Impl) GetByUniqKey(entry interface{}, idx string, idxVal []string, target ...interface{}) (result interface{}, err error)
- func (s *Impl) GetHistory(entry interface{}, target interface{}) (state.HistoryEntryList, error)
- func (s *Impl) GetPrivate(collection string, entry interface{}, target ...interface{}) (result interface{}, err error)
- func (s *Impl) Insert(entry interface{}, value ...interface{}) error
- func (s *Impl) InsertPrivate(collection string, entry interface{}, value ...interface{}) (err error)
- func (s *Impl) List(entry interface{}, target ...interface{}) (interface{}, error)
- func (s *Impl) ListPaginated(entry interface{}, pageSize int32, bookmark string, target ...interface{}) (interface{}, *pb.QueryResponseMetadata, error)
- func (s *Impl) ListPaginatedWith(schema interface{}, key state.Key, pageSize int32, bookmark string) (result interface{}, metadata *pb.QueryResponseMetadata, err error)
- func (s *Impl) ListPrivate(collection string, usePrivateDataIterator bool, namespace interface{}, ...) (result interface{}, err error)
- func (s *Impl) ListWith(entry interface{}, key state.Key) (result interface{}, err error)
- func (s *Impl) Logger() *zap.Logger
- func (s *Impl) MappingNamespace(schema interface{}) (state.Key, error)
- func (s *Impl) Put(entry interface{}, value ...interface{}) error
- func (s *Impl) PutPrivate(collection string, entry interface{}, value ...interface{}) (err error)
- func (s *Impl) UseKeyTransformer(kt state.KeyTransformer)
- type InstanceKeyer
- type InstanceMultiKeyer
- type MappedState
- type Namer
- type Query
- type StateIndex
- type StateIndexDef
- type StateInstance
- type StateMapper
- type StateMappers
- type StateMapping
- func (sm *StateMapping) AddIndex(idx *StateIndex) error
- func (sm *StateMapping) DefaultNamespace() state.Key
- func (sm *StateMapping) Index(name string) *StateIndex
- func (sm *StateMapping) Indexes() []*StateIndex
- func (sm *StateMapping) KeyerFor() interface{}
- func (sm *StateMapping) Keys(entity interface{}) ([]state.KeyValue, error)
- func (sm *StateMapping) List() interface{}
- func (sm *StateMapping) Namespace() state.Key
- func (sm *StateMapping) PrimaryKey(entity interface{}) (state.Key, error)
- func (sm *StateMapping) Schema() interface{}
- type StateMappingOpt
- func KeyerFor(schema interface{}) StateMappingOpt
- func List(list proto.Message) StateMappingOpt
- func PKeyAttr(attrs ...string) StateMappingOpt
- func PKeyComplexId(pkeySchema interface{}) StateMappingOpt
- func PKeyId() StateMappingOpt
- func PKeySchema(pkeySchema interface{}) StateMappingOpt
- func PKeyer(pkeyer InstanceKeyer) StateMappingOpt
- func UniqKey(name string, fields ...[]string) StateMappingOpt
- func WithConstPKey(keys ...state.Key) StateMappingOpt
- func WithIndex(idx *StateIndexDef) StateMappingOpt
- func WithNamespace(namespace state.Key) StateMappingOpt
- type StateMappings
- func (smm StateMappings) Add(schema interface{}, opts ...StateMappingOpt) StateMappings
- func (smm StateMappings) Exists(entry interface{}) bool
- func (smm StateMappings) Get(entry interface{}) (StateMapper, error)
- func (smm StateMappings) GetByNamespace(namespace state.Key) (StateMapper, error)
- func (smm StateMappings) GetBySchema(schema interface{}) (StateMapper, error)
- func (smm *StateMappings) IdxKey(entity interface{}, idx string, idxVal state.Key, ...) (state.Key, error)
- func (smm StateMappings) Map(entry interface{}) (*StateInstance, error)
- func (smm StateMappings) PrimaryKey(entry interface{}) (state.Key, error)
- func (smm StateMappings) Resolve(objectType string, value []byte, ...) (entry interface{}, err error)
Constants ¶
const KeyRefNamespace = `_idx`
KeyRefNamespace namespace for uniq indexes
const (
TimestampKeyLayout = `2006-01-02`
)
Variables ¶
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`) // ErrIndexAlreadyExists occurs when when trying to add index to mapping with existent name ErrIndexAlreadyExists = errors.New(`index already exists`) // ErrIndexReferenceNotFound occurs when trying to find entry by index ErrIndexReferenceNotFound = errors.New(`index reference not found`) )
var (
ErrEventNameNotFound = errors.New(`event name not found`)
)
var (
ErrEventPayloadEmpty = errors.New(`event payload empty`)
)
var KeyRefIDKeyer = attrsKeyer([]string{`Schema`, `Idx`, `RefKey`})
KeyRefIDKeyer keyer for KeyRef entity
var KeyRefIDMapper = &StateMapping{ schema: &schema.KeyRefId{}, namespace: state.Key{KeyRefNamespace}, primaryKeyer: KeyRefIDKeyer, }
var KeyRefMapper = &StateMapping{ schema: &schema.KeyRef{}, namespace: state.Key{KeyRefNamespace}, primaryKeyer: KeyRefIDKeyer, }
Functions ¶
func EventNameForPayload ¶
func EventNameForPayload(payload interface{}) string
func KeyRefsDiff ¶
func KeyRefsDiff(prevKeys []state.KeyValue, newKeys []state.KeyValue) (deleted, inserted []state.KeyValue, err error)
KeyRefsDiff calculates diff between key reference set
func MapEvents ¶
func MapEvents(eventMappings EventMappings) router.MiddlewareFunc
func MapStates ¶
func MapStates(stateMappings StateMappings) router.MiddlewareFunc
func NewKeyRefID ¶
func SchemaNamespace ¶
SchemaNamespace produces string representation of Schema type
Types ¶
type CommandInsert ¶
type CommandInsert struct {
Entry interface{}
}
func (*CommandInsert) String ¶
func (ci *CommandInsert) String() string
type CommandPut ¶
type CommandPut struct {
Entry interface{}
}
func (*CommandPut) String ¶
func (ci *CommandPut) String() string
type EntryMapper ¶
func NewEntryMapper ¶
func NewEntryMapper() *EntryMapper
type Event ¶
type Event struct { Name string Payload interface{} }
func EventFromPayload ¶
func EventFromPayload(payload interface{}) *Event
type EventImpl ¶
type EventImpl struct {
// contains filtered or unexported fields
}
func NewEvent ¶
func NewEvent(stub shim.ChaincodeStubInterface, mappings EventMappings) *EventImpl
func (*EventImpl) ToBytesConverter ¶
func (e *EventImpl) ToBytesConverter() serialize.ToBytesConverter
func (*EventImpl) UseNameTransformer ¶
func (e *EventImpl) UseNameTransformer(nt state.StringTransformer) state.Event
func (*EventImpl) UseToBytesConverter ¶
func (e *EventImpl) UseToBytesConverter(tb serialize.ToBytesConverter) state.Event
type EventInstance ¶
type EventInstance struct {
// contains filtered or unexported fields
}
func NewEventInstance ¶
func NewEventInstance(instance interface{}, mapper EventMapper) (*EventInstance, error)
func (*EventInstance) Name ¶
func (ei *EventInstance) Name() (string, error)
func (*EventInstance) ToBytes ¶
func (ei *EventInstance) ToBytes(toBytesConverter serialize.ToBytesConverter) ([]byte, error)
type EventMapper ¶
type EventMappers ¶
type EventMappers interface { Exists(schema interface{}) (exists bool) Get(schema interface{}) (eventMapper EventMapper, err error) Map(instance interface{}) (*EventInstance, 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 MergeEventMappings ¶
func MergeEventMappings(one EventMappings, more ...EventMappings) EventMappings
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{}) (*EventInstance, error)
func (EventMappings) Resolve ¶
func (emm EventMappings) Resolve(eventName string, payload []byte, fromBytesConverter serialize.FromBytesConverter) (event interface{}, err error)
type EventResolver ¶
type EventResolver interface {
Resolve(eventName string, payload []byte, fromBytesConverter serialize.FromBytesConverter) (event interface{}, err error)
}
type Impl ¶
func (*Impl) DeletePrivate ¶
func (*Impl) ExistsPrivate ¶
func (*Impl) GetByUniqKey ¶
func (*Impl) GetHistory ¶
func (s *Impl) GetHistory(entry interface{}, target interface{}) (state.HistoryEntryList, error)
func (*Impl) GetPrivate ¶
func (*Impl) InsertPrivate ¶
func (*Impl) ListPaginated ¶
func (*Impl) ListPaginatedWith ¶
func (*Impl) ListPrivate ¶
func (*Impl) MappingNamespace ¶
func (*Impl) PutPrivate ¶
func (*Impl) UseKeyTransformer ¶
func (s *Impl) UseKeyTransformer(kt state.KeyTransformer)
type InstanceKeyer ¶
InstanceKeyer returns key of an state entry instance
type InstanceMultiKeyer ¶
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) // ListPaginatedWith allows to refine search criteria by adding to namespace key parts with pagination ListPaginatedWith(schema interface{}, key state.Key, pageSize int32, bookmark string) ( result interface{}, metadata *pb.QueryResponseMetadata, err error) // GetByUniqKey return one entry // Deprecated: use GetByKey GetByUniqKey(schema interface{}, idx string, idxVal []string, target ...interface{}) (result interface{}, err error) // GetByKey GetByKey(schema interface{}, idx string, idxVal []string, target ...interface{}) (result interface{}, err error) }
type StateIndex ¶
type StateIndex struct { Name string Uniq bool Required bool Keyer InstanceMultiKeyer // index can have multiple keys }
StateIndex additional index of entity instance
type StateIndexDef ¶
type StateIndexDef struct { Name string Fields []string Required bool Multi bool Keyer InstanceMultiKeyer }
StateIndexDef additional index definition
type StateInstance ¶
type StateInstance struct {
// contains filtered or unexported fields
}
func NewKeyRefIDInstance ¶
func NewKeyRefIDInstance(target interface{}, idx string, refKey state.Key, toBytesConverter serialize.ToBytesConverter) *StateInstance
func NewKeyRefInstance ¶
func NewKeyRefInstance(target interface{}, idx string, refKey, pKey state.Key) *StateInstance
func NewStateInstance ¶
func NewStateInstance(instance interface{}, stateMapper StateMapper) *StateInstance
func (*StateInstance) Mapper ¶
func (si *StateInstance) Mapper() StateMapper
func (*StateInstance) ToBytes ¶
func (si *StateInstance) ToBytes(toBytesConverter serialize.ToBytesConverter) ([]byte, error)
type StateMapper ¶
type StateMapper interface { Schema() interface{} List() interface{} Namespace() state.Key // PrimaryKey returns primary key for entry PrimaryKey(instance interface{}) (state.Key, error) // Keys returns additional keys for Keys(instance interface{}) ([]state.KeyValue, error) //KeyerFor returns target entity if mapper is key mapper KeyerFor() (schema interface{}) Indexes() []*StateIndex }
StateMapper interface for dealing with mapped state
type StateMappers ¶
type StateMappers interface { Exists(schema interface{}) bool Get(schema interface{}) (StateMapper, error) Map(instance interface{}) (*StateInstance, error) PrimaryKey(instance interface{}) (state.Key, 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) AddIndex ¶
func (sm *StateMapping) AddIndex(idx *StateIndex) error
func (*StateMapping) DefaultNamespace ¶
func (sm *StateMapping) DefaultNamespace() state.Key
func (*StateMapping) Index ¶
func (sm *StateMapping) Index(name string) *StateIndex
func (*StateMapping) Indexes ¶
func (sm *StateMapping) Indexes() []*StateIndex
func (*StateMapping) KeyerFor ¶
func (sm *StateMapping) KeyerFor() interface{}
func (*StateMapping) Keys ¶
func (sm *StateMapping) Keys(entity interface{}) ([]state.KeyValue, error)
Keys prepares primary and additional uniq/non-uniq keys for storage
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 PKeySchema ¶
func PKeySchema(pkeySchema interface{}) StateMappingOpt
PKeySchema registers all fields from pkeySchema as part of primary key. Same fields should exists in mapped entity. Also register keyer for pkeySchema with with namespace from current schema.
func PKeyer ¶
func PKeyer(pkeyer InstanceKeyer) StateMappingOpt
func UniqKey ¶
func UniqKey(name string, fields ...[]string) StateMappingOpt
UniqKey defined uniq key in entity
func WithConstPKey ¶
func WithConstPKey(keys ...state.Key) StateMappingOpt
WithConstPKey set static key for all instances of mapped entry
func WithIndex ¶
func WithIndex(idx *StateIndexDef) StateMappingOpt
func WithNamespace ¶
func WithNamespace(namespace state.Key) StateMappingOpt
WithNamespace sets namespace for mapping
type StateMappings ¶
type StateMappings map[string]*StateMapping
func MergeStateMappings ¶
func MergeStateMappings(one StateMappings, more ...StateMappings) StateMappings
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)
GetByNamespace returns 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) GetBySchema ¶
func (smm StateMappings) GetBySchema(schema interface{}) (StateMapper, error)
func (*StateMappings) IdxKey ¶
func (smm *StateMappings) IdxKey(entity interface{}, idx string, idxVal state.Key, toBytesConverter serialize.ToBytesConverter) (state.Key, error)
func (StateMappings) Map ¶
func (smm StateMappings) Map(entry interface{}) (*StateInstance, error)
func (StateMappings) PrimaryKey ¶
func (smm StateMappings) PrimaryKey(entry interface{}) (state.Key, error)
func (StateMappings) Resolve ¶
func (smm StateMappings) Resolve(objectType string, value []byte, fromBytesConverter serialize.FromBytesConverter) (entry interface{}, err error)