core

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ChangeReasonKey contextKey = "change_reason"

ChangeReasonKey is the context key for passing specific change reasons (commit messages) during Save/Delete operations.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metadata

type Metadata map[string]any

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

type Note

type Note struct {
	ID       string
	Content  string
	Metadata Metadata
}

Note is the central entity of the domain. It represents a piece of knowledge identified by an ID. It is agnostic to storage format (Markdown, JSON, SQL).

type Repository

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

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

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

	// Delete removes a note 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 encapsulates the business logic for managing notes.

func NewService

func NewService(r Repository, l *slog.Logger) *Service

NewService creates a new Service instance.

func (*Service) Begin

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

Begin starts a new unit of work (transaction). It returns an error if the underlying repository does not support transactions.

func (*Service) DeleteNote

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

DeleteNote deletes a note by ID.

func (*Service) GetNote

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

GetNote retrieves a note by ID.

func (*Service) ListNotes

func (s *Service) ListNotes(ctx context.Context) ([]Note, error)

ListNotes lists all notes.

func (*Service) SaveNote

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

SaveNote creates or updates a note.

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 note for persistence.
	Save(ctx context.Context, n Note) error

	// Get retrieves a note, preferring the staged version if it exists in the transaction.
	Get(ctx context.Context, id string) (Note, error)

	// List returns all available notes, including staged ones.
	List(ctx context.Context) ([]Note, error)

	// Delete stages a note for removal.
	Delete(ctx context.Context, id string) error

	// Commit applies all staged changes atomically.
	Commit(ctx context.Context, changeReason string) error

	// Rollback discards all staged changes.
	Rollback(ctx context.Context) error
}

Transaction defines the contract for a unit of work. Changes made within a transaction are atomic and isolated (depending on implementation).

type TransactionalRepository

type TransactionalRepository interface {
	Repository

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

TransactionalRepository extends Repository to support transactions.

Jump to

Keyboard shortcuts

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