typed

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocumentModel

type DocumentModel[T any] struct {
	ID      string
	Content string
	Data    T        // The typed metadata/entities
	Saver   Saver[T] // Active Record reference interface
}

DocumentModel wraps the raw core.Document with a typed Metadata field. It acts as a typed view of a document.

func (*DocumentModel[T]) Save

func (d *DocumentModel[T]) Save(ctx context.Context) error

Save persists the document using the attached saver (Repository or Service).

type Repository

type Repository[T any] struct {
	// contains filtered or unexported fields
}

Repository wraps a core.Repository to provide type-safe access.

func NewRepository

func NewRepository[T any](repo core.Repository) *Repository[T]

NewRepository creates a new type-safe wrapper around an existing repository.

func (*Repository[T]) Delete

func (r *Repository[T]) Delete(ctx context.Context, id string) error

Delete removes a document by ID.

func (*Repository[T]) Get

func (r *Repository[T]) Get(ctx context.Context, id string) (*DocumentModel[T], error)

Get retrieves a document and unmarshals it.

func (*Repository[T]) List

func (r *Repository[T]) List(ctx context.Context) ([]*DocumentModel[T], error)

List returns all documents converted to the typed model.

func (*Repository[T]) Save

func (r *Repository[T]) Save(ctx context.Context, doc *DocumentModel[T]) error

Save persists a typed document.

func (*Repository[T]) Watch added in v0.9.1

func (r *Repository[T]) Watch(ctx context.Context, pattern string) (<-chan core.Event, error)

Watch observes changes in the repository.

type Saver

type Saver[T any] interface {
	Save(ctx context.Context, doc *DocumentModel[T]) error
}

Saver interface avoids circular dependencies or tight coupling with Repository/Service structs.

type Service

type Service[T any] struct {
	// contains filtered or unexported fields
}

Service wraps a core.Service to provide type-safe access and business logic support.

func NewService

func NewService[T any](svc *core.Service) *Service[T]

NewService creates a new typed service wrapper.

func (*Service[T]) Delete

func (s *Service[T]) Delete(ctx context.Context, id string) error

Delete removes a document via Service.

func (*Service[T]) Get

func (s *Service[T]) Get(ctx context.Context, id string) (*DocumentModel[T], error)

Get retrieves a document via Service.

func (*Service[T]) List

func (s *Service[T]) List(ctx context.Context) ([]*DocumentModel[T], error)

List retrieves all documents via Service.

func (*Service[T]) Save

func (s *Service[T]) Save(ctx context.Context, doc *DocumentModel[T]) error

Save persists a typed document using the core Service (including validation/transactions).

func (*Service[T]) Watch added in v0.9.0

func (s *Service[T]) Watch(ctx context.Context, pattern string) (<-chan core.Event, error)

Watch observes changes in the repository.

func (*Service[T]) WithTransaction

func (s *Service[T]) WithTransaction(ctx context.Context, fn func(tx *Transaction[T]) error) error

WithTransaction executes a typed function within a transaction.

type Transaction

type Transaction[T any] struct {
	// contains filtered or unexported fields
}

Transaction wraps a core.Transaction for typed operations.

func (*Transaction[T]) Delete

func (t *Transaction[T]) Delete(ctx context.Context, id string) error

Delete removes a document within the transaction.

func (*Transaction[T]) Get

func (t *Transaction[T]) Get(ctx context.Context, id string) (*DocumentModel[T], error)

Get retrieves a document within the transaction.

func (*Transaction[T]) Save

func (t *Transaction[T]) Save(ctx context.Context, doc *DocumentModel[T]) error

Save persists a typed document within the transaction.

Jump to

Keyboard shortcuts

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