core

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

Overview

Document is the central entity of the domain.

Index

Constants

View Source
const ChangeReasonKey contextKey = "change_reason"

Variables

View Source
var (
	ErrReadOnly = errors.New("repository is in read-only mode")
)

Common errors.

Functions

This section is empty.

Types

type Document added in v0.6.0

type Document struct {
	ID       string
	Content  string
	Metadata Metadata
}

Document is the central entity of the domain. It represents a piece of knowledge or data identified by an ID.

type Event added in v0.9.0

type Event struct {
	Type      EventType
	ID        string
	Timestamp int64 // Unix timestamp
}

Event represents a change in the vault.

func (Event) String added in v0.10.7

func (e Event) String() string

type EventType added in v0.9.0

type EventType string

EventType represents the type of change in the vault.

const (
	EventCreate EventType = "CREATE"
	EventModify EventType = "MODIFY"
	EventDelete EventType = "DELETE"
)

type Metadata

type Metadata map[string]any

Metadata represents the flexible key-value pairs associated with a document.

type Option added in v0.9.0

type Option func(*Service)

Option defines a functional option for configuring the Service.

func WithEventBuffer added in v0.9.0

func WithEventBuffer(size int) Option

WithEventBuffer sets the buffer size for the Watch event broker.

type Reconcilable added in v0.9.0

type Reconcilable interface {
	// Reconcile compares the internal index with the actual storage and returns detected changes (diff).
	Reconcile(ctx context.Context) ([]Event, error)
}

Reconcilable defines an interface for repositories that can reconcile their internal state (cache) with valid storage.

type Repository

type Repository interface {
	// Save persists a document. It creates if not exists, or updates if it does.
	Save(ctx context.Context, doc Document) error

	// Get retrieves a document by its ID.
	Get(ctx context.Context, id string) (Document, error)

	// List returns all available documents.
	// TODO: Add pagination or filtering options in the future.
	List(ctx context.Context) ([]Document, error)

	// Delete removes a document by its ID.
	Delete(ctx context.Context, id string) error

	// Initialize ensures the underlying storage is ready (e.g., create directories, git init, schema migration).
	Initialize(ctx context.Context) error
}

Repository defines the contract for storing and retrieving notes. Adhering to this interface allows the core to be independent of the underlying storage mechanism (Filesystem, Git, SQL, S3, etc).

type Service

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

Service handles the business logic for documents.

func NewService

func NewService(repo Repository, opts ...Option) *Service

NewService creates a new Service.

func (*Service) Begin

func (s *Service) Begin(ctx context.Context) (Transaction, error)

Begin initiates a transaction manually. Exposed for power users or custom workflows.

func (*Service) ComponentType added in v0.10.7

func (s *Service) ComponentType() string

ComponentType implements introspection.Component.

func (*Service) DeleteDocument added in v0.6.0

func (s *Service) DeleteDocument(ctx context.Context, id string) error

DeleteDocument removes a document.

func (*Service) GetDocument added in v0.6.0

func (s *Service) GetDocument(ctx context.Context, id string) (Document, error)

GetDocument retrieves a document.

func (*Service) ListDocuments added in v0.6.0

func (s *Service) ListDocuments(ctx context.Context) ([]Document, error)

ListDocuments retrieves all documents.

func (*Service) Reconcile added in v0.9.0

func (s *Service) Reconcile(ctx context.Context) ([]Event, error)

Reconcile synchronizes internal state (cache) with valid storage. Returns a list of events representing detected changes (offline edits). If the repository does not support reconciliation, returns nil, nil.

func (*Service) SaveDocument added in v0.6.0

func (s *Service) SaveDocument(ctx context.Context, id string, content string, metadata Metadata) error

SaveDocument saves a document with business validation.

func (*Service) State added in v0.10.7

func (s *Service) State() any

State implements introspection.Introspectable.

func (*Service) Watch added in v0.9.0

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

Watch observes changes in the repository if supported.

func (*Service) WithTransaction added in v0.6.0

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

WithTransaction executes a function within a transaction.

type ServiceState added in v0.10.7

type ServiceState struct {
	EventBufferSize int    `json:"event_buffer_size"`
	RepositoryType  string `json:"repository_type"`
}

ServiceState exposes internal state for observability.

type Syncable

type Syncable interface {
	// Sync synchronizes the local state with a remote source (e.g. git pull/push).
	Sync(ctx context.Context) error
}

Syncable defines an interface for repositories that support synchronization with a remote.

type Transaction

type Transaction interface {
	// Save stages a document for saving.
	Save(ctx context.Context, doc Document) error
	// Get retrieves a document (including staged changes).
	Get(ctx context.Context, id string) (Document, error)
	// Delete stages a document for deletion.
	Delete(ctx context.Context, id string) error
	// Commit applies the changes.
	Commit(ctx context.Context, msg string) error
	// Rollback discards the changes.
	Rollback(ctx context.Context) error
}

Transaction represents a unit of work (batch of operations).

type Transactional added in v0.6.0

type Transactional interface {
	// Begin starts a new transaction.
	Begin(ctx context.Context) (Transaction, error)
}

Transactional indicates that a repository supports atomic transactions.

type Watchable added in v0.9.0

type Watchable interface {
	// Watch returns a channel of events matching the pattern.
	Watch(ctx context.Context, pattern string) (<-chan Event, error)
}

Watchable defines an interface for repositories that can notify about changes.

Jump to

Keyboard shortcuts

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