Documentation
¶
Overview ¶
Package ports defines the storage, indexing and codec contracts used by application handlers.
Index ¶
- Variables
- type BookmarkCodec
- type BookmarkRepository
- type HabitCodec
- type HabitRepository
- type IDGenerator
- type InboxCodec
- type InboxRepository
- type Index
- type JournalCodec
- type JournalRepository
- type Note
- type NoteFilter
- type NoteKind
- type NoteStore
- type NoteSummary
- type PageCodec
- type PageRepository
- type PersonCodec
- type PersonRepository
- type RawNoteCodec
- type RawNoteHeader
Constants ¶
This section is empty.
Variables ¶
var ErrHabitNotFound = errors.New("habit not found")
ErrHabitNotFound identifies a missing habit source document.
var ErrJournalAlreadyExists = errors.New("journal already exists")
ErrJournalAlreadyExists identifies a journal date assigned to another UUID.
var ErrNoteNotFound = errors.New("note not found")
ErrNoteNotFound identifies a missing source document.
var ErrPersonNotFound = errors.New("person not found")
ErrPersonNotFound identifies a missing person source document.
Functions ¶
This section is empty.
Types ¶
type BookmarkCodec ¶ added in v0.4.0
type BookmarkCodec interface {
// Encode writes the managed header followed by the entity's content.
Encode(*bookmarks.Bookmark) ([]byte, error)
// Decode requires the expected note kind and retains the original body bytes.
Decode([]byte) (*bookmarks.Bookmark, error)
}
BookmarkCodec maps bookmark entities to managed AsciiDoc documents. Decode validates the header and domain fields; body bytes remain opaque.
type BookmarkRepository ¶ added in v0.3.0
type BookmarkRepository interface {
// Save persists the entity's document and refreshes its searchable projection.
Save(context.Context, *bookmarks.Bookmark) error
// ByID decodes the source document and verifies its kind and requested UUID.
ByID(context.Context, uuid.UUID) (*bookmarks.Bookmark, error)
// Update requires an existing entity and preserves its creation timestamp.
Update(context.Context, *bookmarks.Bookmark) error
}
BookmarkRepository reads source documents and persists bookmark entities with their index projections. An index error can occur after the document is saved.
type HabitCodec ¶ added in v0.3.0
type HabitCodec interface {
// Encode writes the managed header followed by the entity's content.
Encode(*habits.Habit) ([]byte, error)
// Decode requires the expected note kind and retains the original body bytes.
Decode([]byte) (*habits.Habit, error)
}
HabitCodec maps habit entities to managed AsciiDoc documents. Decode validates the header and domain fields; body bytes remain opaque.
type HabitRepository ¶ added in v0.3.0
type HabitRepository interface {
// Save persists the entity's document and refreshes its searchable projection.
Save(context.Context, *habits.Habit) error
// ByID decodes the source document and verifies its kind and requested UUID.
ByID(context.Context, uuid.UUID) (*habits.Habit, error)
// Update requires an existing entity and preserves its creation timestamp.
Update(context.Context, *habits.Habit) error
}
HabitRepository reads source documents and persists habit entities with their index projections. An index error can occur after the document is saved.
type IDGenerator ¶
type IDGenerator interface {
// Generate returns a fresh UUID for a new entity.
Generate() uuid.UUID
}
IDGenerator generates entity identifiers.
type InboxCodec ¶ added in v0.4.0
type InboxCodec interface {
// Encode writes the managed header followed by the entity's content.
Encode(*inbox.Inbox) ([]byte, error)
// Decode requires the expected note kind and retains the original body bytes.
Decode([]byte) (*inbox.Inbox, error)
}
InboxCodec maps inbox entities to managed AsciiDoc documents. Decode validates the header and domain fields; body bytes remain opaque.
type InboxRepository ¶ added in v0.3.0
type InboxRepository interface {
// Save persists the entity's document and refreshes its searchable projection.
Save(context.Context, *inbox.Inbox) error
// ByID decodes the source document and verifies its kind and requested UUID.
ByID(context.Context, uuid.UUID) (*inbox.Inbox, error)
// Update requires an existing entity and preserves its creation timestamp.
Update(context.Context, *inbox.Inbox) error
}
InboxRepository reads source documents and persists inbox entities with their index projections. An index error can occur after the document is saved.
type Index ¶ added in v0.3.0
type Index interface {
// FindNotes applies type/tag filters and pagination, ordered by update time
// descending and UUID ascending. Labels are normalized to a single line.
FindNotes(context.Context, NoteFilter) ([]NoteSummary, error)
// FindGroups returns normalized group names in alphabetical order, including
// only groups currently assigned to at least one person.
FindGroups(context.Context) ([]string, error)
// Delete removes a note's projection and its tag/group associations.
// Deleting an absent UUID succeeds; the source document is left untouched.
Delete(context.Context, uuid.UUID) error
// Project decodes a document's managed header, verifies its UUID and updates
// the appropriate typed projection. RawNoteCodec validates body syntax before
// raw saves; index projection itself does not validate the entire body.
Project(context.Context, Note) error
// Rebuild replaces all projections in one transaction. Callback errors or
// cancellation roll back the replacement, preserving the previous index.
// The callback must use the supplied index and must not retain it afterward.
Rebuild(context.Context, func(Index) error) error
// UpsertPage atomically replaces a page's metadata, title, area and tags.
// The path identifies its already-persisted source document.
UpsertPage(context.Context, *pages.Page, string) error
// UpsertJournal atomically replaces a journal's metadata, date and tags.
// A date already assigned to another UUID returns ErrJournalAlreadyExists.
UpsertJournal(context.Context, *journals.Journal, string) error
// JournalExists reports whether a valid date is already assigned to a journal.
JournalExists(context.Context, calendar.Date) (bool, error)
// UpsertBookmark atomically replaces a bookmark's metadata, URL and tags.
UpsertBookmark(context.Context, *bookmarks.Bookmark, string) error
// UpsertInbox atomically replaces an inbox note's metadata, content and tags.
UpsertInbox(context.Context, *inbox.Inbox, string) error
// UpsertHabit atomically replaces a habit's metadata, title, goal and tags.
UpsertHabit(context.Context, *habits.Habit, string) error
// UpsertPerson atomically replaces a person's metadata, name, groups and tags.
// Unused group definitions may remain stored but are excluded by FindGroups.
UpsertPerson(context.Context, *persons.Person, string) error
}
Index stores searchable projections derived from managed note documents. The vault is authoritative: updating this index never rewrites a document.
type JournalCodec ¶ added in v0.4.0
type JournalCodec interface {
// Encode writes the managed header followed by the entity's content.
Encode(*journals.Journal) ([]byte, error)
// Decode requires the expected note kind and retains the original body bytes.
Decode([]byte) (*journals.Journal, error)
}
JournalCodec maps journal entities to managed AsciiDoc documents. Decode validates the header and domain fields; body bytes remain opaque.
type JournalRepository ¶ added in v0.3.0
type JournalRepository interface {
// Save persists the entity's document and refreshes its searchable projection.
Save(context.Context, *journals.Journal) error
// ByID decodes the source document and verifies its kind and requested UUID.
ByID(context.Context, uuid.UUID) (*journals.Journal, error)
// Update requires an existing entity and preserves its creation timestamp.
Update(context.Context, *journals.Journal) error
}
JournalRepository reads source documents and persists journal entities with their index projections. An index error can occur after the document is saved.
type Note ¶ added in v0.3.0
Note carries the complete source bytes and storage location of a managed document.
type NoteFilter ¶ added in v0.3.0
NoteFilter selects indexed notes. Empty type and tag match all notes.
type NoteKind ¶ added in v0.3.0
type NoteKind string
NoteKind identifies the persisted document format, not an entity property.
const ( // NoteKindPage identifies managed page documents. NoteKindPage NoteKind = "page" // NoteKindJournal identifies managed journal documents. NoteKindJournal NoteKind = "journal" // NoteKindHabit identifies managed habit documents. NoteKindHabit NoteKind = "habit" // NoteKindPerson identifies managed person documents. NoteKindPerson NoteKind = "person" // NoteKindBookmark identifies managed bookmark documents. NoteKindBookmark NoteKind = "bookmark" // NoteKindInbox identifies managed inbox documents. NoteKindInbox NoteKind = "inbox" )
type NoteStore ¶ added in v0.3.0
type NoteStore interface {
// Scan visits managed documents in stable path order without consulting the
// index. Cancellation or a visitor error stops the scan.
Scan(context.Context, func(Note) error) error
// Put atomically creates or replaces the document identified by Note.ID and
// returns its storage path. Updating its index is a separate operation.
Put(context.Context, Note) (string, error)
// Get reads the complete document and its path, or returns ErrNoteNotFound.
Get(context.Context, uuid.UUID) (Note, error)
// Delete removes the source document. Missing documents are treated as already
// deleted; ambiguous UUIDs must be rejected before removing any file.
Delete(context.Context, uuid.UUID) error
}
NoteStore owns source documents independently of their domain model and index. Implementations preserve supplied bytes and do not perform domain validation.
type NoteSummary ¶ added in v0.3.0
NoteSummary is a read projection, independent of the note's domain entity.
type PageCodec ¶ added in v0.4.0
type PageCodec interface {
// Encode writes the managed header followed by the entity's content.
Encode(*pages.Page) ([]byte, error)
// Decode requires the expected note kind and retains the original body bytes.
Decode([]byte) (*pages.Page, error)
}
PageCodec maps page entities to managed AsciiDoc documents. Decode validates the header and domain fields; body bytes remain opaque.
type PageRepository ¶ added in v0.3.0
type PageRepository interface {
// Save persists the entity's document and refreshes its searchable projection.
Save(context.Context, *pages.Page) error
// ByID decodes the source document and verifies its kind and requested UUID.
ByID(context.Context, uuid.UUID) (*pages.Page, error)
// Update requires an existing entity and preserves its creation timestamp.
Update(context.Context, *pages.Page) error
}
PageRepository reads source documents and persists page entities with their index projections. An index error can occur after the document is saved.
type PersonCodec ¶ added in v0.3.0
type PersonCodec interface {
// Encode writes the managed header followed by the entity's content.
Encode(*persons.Person) ([]byte, error)
// Decode requires the expected note kind and retains the original body bytes.
Decode([]byte) (*persons.Person, error)
}
PersonCodec maps person entities to managed AsciiDoc documents. Decode validates the header and domain fields; body bytes remain opaque.
type PersonRepository ¶ added in v0.3.0
type PersonRepository interface {
// Save persists the entity's document and refreshes its searchable projection.
Save(context.Context, *persons.Person) error
// ByID decodes the source document and verifies its kind and requested UUID.
ByID(context.Context, uuid.UUID) (*persons.Person, error)
// Update requires an existing entity and preserves its creation timestamp.
Update(context.Context, *persons.Person) error
}
PersonRepository reads source documents and persists person entities with their index projections. An index error can occur after the document is saved.
type RawNoteCodec ¶ added in v0.4.0
type RawNoteCodec interface {
// Inspect validates identity and metadata using only the header, allowing
// documents with invalid bodies to be opened for repair.
Inspect([]byte) (RawNoteHeader, error)
// Stamp replaces only the effective header update-time value, preserving all
// other bytes. Callers validate the resulting document before persistence.
Stamp([]byte, time.Time) ([]byte, error)
// Decode validates supported AsciiDoc syntax and the typed domain fields. A nonempty
// expected kind must match the header; an empty kind accepts any supported kind.
Decode(NoteKind, []byte) (RawNoteHeader, error)
}
RawNoteCodec validates complete AsciiDoc source without regenerating it.
type RawNoteHeader ¶ added in v0.4.0
type RawNoteHeader struct {
ID uuid.UUID
Kind NoteKind
Metadata shared.EntityMetadata
// Date is the fixed calendar date for journals and empty for other kinds.
Date string
}
RawNoteHeader identifies a note and its protected metadata.