Documentation
¶
Overview ¶
Document is the central entity of the domain.
Index ¶
- Constants
- Variables
- type Document
- type Event
- type EventType
- type Metadata
- type Option
- type Reconcilable
- type Repository
- type Service
- func (s *Service) Begin(ctx context.Context) (Transaction, error)
- func (s *Service) ComponentType() string
- func (s *Service) DeleteDocument(ctx context.Context, id string) error
- func (s *Service) GetDocument(ctx context.Context, id string) (Document, error)
- func (s *Service) ListDocuments(ctx context.Context) ([]Document, error)
- func (s *Service) Reconcile(ctx context.Context) ([]Event, error)
- func (s *Service) SaveDocument(ctx context.Context, id string, content string, metadata Metadata) error
- func (s *Service) State() any
- func (s *Service) Watch(ctx context.Context, pattern string) (<-chan Event, error)
- func (s *Service) WithTransaction(ctx context.Context, fn func(tx Transaction) error) error
- type ServiceState
- type Syncable
- type Transaction
- type Transactional
- type Watchable
Constants ¶
const ChangeReasonKey contextKey = "change_reason"
Variables ¶
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
Document is the central entity of the domain. It represents a piece of knowledge or data identified by an ID.
type EventType ¶ added in v0.9.0
type EventType string
EventType represents the type of change in the vault.
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
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
ComponentType implements introspection.Component.
func (*Service) DeleteDocument ¶ added in v0.6.0
DeleteDocument removes a document.
func (*Service) GetDocument ¶ added in v0.6.0
GetDocument retrieves a document.
func (*Service) ListDocuments ¶ added in v0.6.0
ListDocuments retrieves all documents.
func (*Service) Reconcile ¶ added in v0.9.0
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) WithTransaction ¶ added in v0.6.0
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.