core

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Document is the central entity of the domain.

Index

Constants

View Source
const ChangeReasonKey contextKey = "change_reason"

Variables

This section is empty.

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 Metadata

type Metadata map[string]any

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

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) *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) 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) 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

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

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.

Jump to

Keyboard shortcuts

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