Documentation
¶
Overview ¶
Package viewstore binds evt.ViewRepository to JSON values, an entity type, and optional decode factories. Codec accepts keys per call; Single binds a primary-key function.
List methods skip invalid payloads and report them to an optional DecodeErrorHandler. Use evt.ListJSONViewsByPK or evt.ListJSONViewsByEntityType for strict decoding.
Index ¶
- type Codec
- func (c *Codec[T]) EntityType() evt.EntityType
- func (c *Codec[T]) Get(ctx context.Context, pk string) (T, bool, error)
- func (c *Codec[T]) ListAll(ctx context.Context, onDecodeError DecodeErrorHandler) ([]T, error)
- func (c *Codec[T]) ListByPK(ctx context.Context, pk string, onDecodeError DecodeErrorHandler) ([]T, error)
- func (c *Codec[T]) Put(ctx context.Context, pk, sk string, entityID evt.EntityID, value T) error
- func (c *Codec[T]) PutAt(ctx context.Context, pk string, entityID evt.EntityID, value T) error
- func (c *Codec[T]) Repo() evt.ViewRepository
- type DecodeErrorHandler
- type Single
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec[T any] struct { // contains filtered or unexported fields }
Codec binds an evt.ViewRepository to a JSON-encoded value type T plus an EntityType. Callers supply pk/sk/entityID per call.
func New ¶
func New[T any](repo evt.ViewRepository, entityType evt.EntityType) *Codec[T]
New constructs a Codec for value-type T. Use NewWithFactory when T is a pointer-backed entity that needs constructor-injected dependencies.
func NewWithFactory ¶
func NewWithFactory[T any](repo evt.ViewRepository, entityType evt.EntityType, factory func() T) *Codec[T]
NewWithFactory constructs a Codec that uses factory to produce decode destinations. This is required when T is a pointer to an aggregate that needs projector wiring before json.Unmarshal runs.
func (*Codec[T]) EntityType ¶
func (c *Codec[T]) EntityType() evt.EntityType
EntityType returns the entity type bound to this codec.
func (*Codec[T]) Get ¶
Get retrieves and decodes the view at pk. Returns (zero, false, nil) when no view exists.
func (*Codec[T]) ListAll ¶
func (c *Codec[T]) ListAll(ctx context.Context, onDecodeError DecodeErrorHandler) ([]T, error)
ListAll returns all valid views for the bound entity type, skipping payloads that fail to decode. onDecodeError, if non-nil, is invoked for each skipped payload.
func (*Codec[T]) ListByPK ¶
func (c *Codec[T]) ListByPK(ctx context.Context, pk string, onDecodeError DecodeErrorHandler) ([]T, error)
ListByPK returns valid views matching pk, skipping payloads that fail to decode. onDecodeError, if non-nil, is invoked for each skipped payload.
func (*Codec[T]) Put ¶
Put writes value at the given pk/sk with the supplied entity ID under the bound EntityType.
func (*Codec[T]) Repo ¶
func (c *Codec[T]) Repo() evt.ViewRepository
Repo returns the underlying view repository for callers that need raw access (e.g., existence probes that should not pay decode cost).
type DecodeErrorHandler ¶
type DecodeErrorHandler func(view *evt.SerializedView, err error)
DecodeErrorHandler is invoked for each view skipped during a List call. view may be nil if the view itself was nil; err is the underlying decode error (typically *evt.JSONViewDecodeError).
type Single ¶
Single is a Codec[T] augmented with caller-supplied pkFor / entityIDOf functions, enabling concise Get(id) / Put(value) helpers for the common "one PK per entity ID" view shape.
func NewSingle ¶
func NewSingle[K any, T any]( repo evt.ViewRepository, entityType evt.EntityType, pkFor func(K) string, entityIDOf func(T) evt.EntityID, ) *Single[K, T]
NewSingle constructs a Single store. pkFor must be non-nil; entityIDOf is optional and only required by the value-driven Put method.
func NewSingleWithFactory ¶
func NewSingleWithFactory[K any, T any]( repo evt.ViewRepository, entityType evt.EntityType, pkFor func(K) string, entityIDOf func(T) evt.EntityID, factory func() T, ) *Single[K, T]
NewSingleWithFactory is NewSingle plus a factory for pointer-backed T.
func (*Single[K, T]) Codec ¶
Codec exposes the underlying Codec for callers that need to issue lookups outside the bound pkFor (e.g., legacy-key fallback reads).