Documentation
¶
Overview ¶
Document is the central entity of the domain.
Index ¶
- Constants
- type Document
- type Metadata
- type Repository
- type Service
- func (s *Service) Begin(ctx context.Context) (Transaction, error)
- 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) SaveDocument(ctx context.Context, id string, content string, metadata Metadata) error
- func (s *Service) WithTransaction(ctx context.Context, fn func(tx Transaction) error) error
- type Syncable
- type Transaction
- type Transactional
Constants ¶
const ChangeReasonKey contextKey = "change_reason"
Variables ¶
This section is empty.
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 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 (*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) 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) 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 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.