app

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package app provides the use-case entry points for wherehouse. It is the single API consumed by cmd/ and tui/ — neither layer imports store or eventbus directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddOutput added in v0.5.2

type AddOutput struct {
	EntityID string `json:"entity_id"`
	Path     string `json:"path"`
}

AddOutput is the `add` command's JSON output shape for a newly created entity.

func ToAddOutput added in v0.5.2

func ToAddOutput(result EntityResult) AddOutput

ToAddOutput projects a created entity result into the `add` output shape.

type App

type App struct {
	// contains filtered or unexported fields
}

App is the top-level application handle. Create one per process via New and share it across all callers.

func New

func New(s *store.Store) *App

New creates an App from an open store.

func (*App) ChangeStatus

func (a *App) ChangeStatus(ctx context.Context, req ChangeStatusRequest) error

ChangeStatus records a status-change event for the entity at the given path.

func (*App) CheckProjectionConsistency added in v0.5.0

func (a *App) CheckProjectionConsistency(ctx context.Context) ([]DoctorIssue, error)

CheckProjectionConsistency performs a logical diff between the event log and the entities_current projection without mutating any state.

func (*App) ClearAllData added in v0.4.0

func (a *App) ClearAllData(ctx context.Context) error

ClearAllData removes all events and entity projections from the database.

func (*App) CreateEntity

func (a *App) CreateEntity(ctx context.Context, req CreateEntityRequest) (EntityResult, error)

CreateEntity creates a new entity, resolving ParentPath to a parent entity ID if provided.

func (*App) FindEntities

func (a *App) FindEntities(ctx context.Context, req FindEntitiesRequest) ([]FindResult, error)

FindEntities searches for non-removed entities whose display name contains the query string. Results are sorted by Levenshtein distance (exact matches first), then alphabetically.

func (*App) GetAllEvents added in v0.4.0

func (a *App) GetAllEvents(ctx context.Context) ([]ExportResult, error)

GetAllEvents returns all events ordered by event_id ASC.

func (*App) GetChildren

func (a *App) GetChildren(ctx context.Context, parentID string) ([]EntityResult, error)

GetChildren returns direct children of parentID, excluding removed entities.

func (*App) GetEntityByID added in v0.3.0

func (a *App) GetEntityByID(ctx context.Context, entityID string) (EntityResult, error)

GetEntityByID retrieves an entity by its stable ID. Returns store.ErrNotFound if the entity does not exist; the returned EntityResult has HasChildren=false (callers needing it should use ListEntities).

func (*App) GetEntityByPath

func (a *App) GetEntityByPath(ctx context.Context, path string) (EntityResult, error)

GetEntityByPath retrieves an entity by its colon-separated display path.

func (*App) GetHistory

func (a *App) GetHistory(ctx context.Context, req GetHistoryRequest) ([]HistoryResult, error)

GetHistory retrieves the event history for an entity identified by path or ID. Results default to newest-first; set OldestFirst to reverse. A positive Limit caps the number of returned events.

func (*App) HasEvents added in v0.4.0

func (a *App) HasEvents(ctx context.Context) (bool, error)

HasEvents reports whether the database contains any events.

func (*App) ImportEvents added in v0.4.0

func (a *App) ImportEvents(ctx context.Context, events []ExportResult, opts ImportOptions) (ImportResult, error)

ImportEvents replays a slice of ExportResult records into the database.

func (*App) ListEntities

func (a *App) ListEntities(ctx context.Context) ([]EntityResult, error)

ListEntities returns all non-removed entities.

func (*App) ListTags added in v0.6.0

func (a *App) ListTags(ctx context.Context, req ListTagsRequest) ([]string, error)

ListTags returns the canonical tags for the entity at req.EntityPath, sorted alphabetically.

func (*App) RemoveEntity

func (a *App) RemoveEntity(ctx context.Context, req RemoveEntityRequest) error

RemoveEntity permanently marks an entity as removed.

func (*App) RenameEntity

func (a *App) RenameEntity(ctx context.Context, req RenameEntityRequest) (EntityResult, error)

RenameEntity renames an entity resolved by its current path.

func (*App) ReparentEntity

func (a *App) ReparentEntity(ctx context.Context, req ReparentEntityRequest) (EntityResult, error)

ReparentEntity moves an entity to a new parent, resolved by paths.

func (*App) RunDoctorChecks added in v0.5.0

func (a *App) RunDoctorChecks(ctx context.Context) ([]DoctorIssue, error)

RunDoctorChecks fetches the event log and projection rows once (concurrently) and runs both validation passes against the shared data.

func (*App) TagEntity added in v0.6.0

func (a *App) TagEntity(ctx context.Context, req TagEntityRequest) error

TagEntity adds and/or removes tags on the entity identified by req.EntityPath. Tags in both Add and Remove cancel each other out (a warning is logged). Adding an existing tag or removing a missing tag are no-ops.

func (*App) TruncateAndReplay added in v0.5.0

func (a *App) TruncateAndReplay(ctx context.Context) (int, error)

TruncateAndReplay rebuilds all projection tables by replaying the event log and returns the number of replayed events.

func (*App) ValidateEventLog added in v0.5.0

func (a *App) ValidateEventLog(ctx context.Context) ([]DoctorIssue, error)

ValidateEventLog reads all events and returns a DoctorIssue for each structural problem found. Returns an empty (non-nil) slice when the log is clean. Never mutates state.

type ChangeStatusRequest

type ChangeStatusRequest struct {
	EntityPath    string
	Status        inventory.EntityStatus
	StatusContext string
	ActorID       string
	Note          string
}

ChangeStatusRequest is the input for changing an entity's status.

type CreateEntityRequest

type CreateEntityRequest struct {
	DisplayName string
	EntityType  inventory.EntityType
	// ParentPath is a colon-separated path, e.g. "Garage:Toolbox". Empty means root-level.
	ParentPath string
	ActorID    string
	Note       string
}

CreateEntityRequest is the input for creating a new entity.

type DoctorIssue added in v0.5.0

type DoctorIssue struct {
	Kind        DoctorKind
	EventID     *int64
	Description string
}

DoctorIssue describes a single structural problem found during a doctor validation.

type DoctorKind added in v0.5.0

type DoctorKind int

DoctorKind classifies which layer a DoctorIssue belongs to.

const (
	DoctorKindConfig     DoctorKind = iota + 1 // config
	DoctorKindEventLog                         // event_log
	DoctorKindProjection                       // projection
)

func (DoctorKind) String added in v0.5.0

func (i DoctorKind) String() string

type EntityResult

type EntityResult struct {
	EntityID        string
	DisplayName     string
	CanonicalName   string
	EntityType      inventory.EntityType
	FullPathDisplay string
	Status          inventory.EntityStatus
	StatusContext   string
	HasChildren     bool
	Tags            []string
}

EntityResult is the output representation of an entity.

type ExportResult added in v0.4.0

type ExportResult struct {
	EventID      int64           `json:"event_id"`
	EventType    string          `json:"event_type"`
	TimestampUTC string          `json:"timestamp_utc"`
	ActorUserID  string          `json:"actor_user_id"`
	EntityID     *string         `json:"entity_id,omitempty"`
	Payload      json.RawMessage `json:"payload"`
	Note         *string         `json:"note,omitempty"`
}

ExportResult is the app-layer representation of a single event for export.

type FindEntitiesRequest

type FindEntitiesRequest struct {
	Query string
	Limit int
}

FindEntitiesRequest is the input for searching entities by name.

type FindResult

type FindResult struct {
	Entity   EntityResult
	Distance int
}

FindResult pairs an EntityResult with its fuzzy-match distance.

type GetHistoryRequest

type GetHistoryRequest struct {
	EntityPath  string
	EntityID    string
	Limit       int
	OldestFirst bool
}

GetHistoryRequest is the input for retrieving an entity's event history.

type HistoryItem added in v0.5.2

type HistoryItem struct {
	EventID   int64               `json:"event_id"`
	EventType inventory.EventType `json:"event_type"`
	Timestamp string              `json:"timestamp"`
	ActorUser string              `json:"actor_user"`
}

HistoryItem is the `history` command's JSON output shape: one row per event. Payload and Note from HistoryResult are intentionally omitted.

func ToHistoryItems added in v0.5.2

func ToHistoryItems(results []HistoryResult) []HistoryItem

ToHistoryItems projects history results into the `history` output shape.

type HistoryResult

type HistoryResult struct {
	EventID      int64
	EventType    inventory.EventType
	TimestampUTC string
	ActorUserID  string
	Payload      []byte
	Note         string
}

HistoryResult is the output representation of a single history event.

type ImportOptions added in v0.4.0

type ImportOptions struct {
	Replace  bool // clear all data before replay (caller must have confirmed)
	Continue bool // accumulate per-event errors instead of aborting
}

ImportOptions controls the behaviour of ImportEvents.

type ImportResult added in v0.4.0

type ImportResult struct {
	Replayed     int
	Failed       int
	WarningCount int
	Warnings     []error
	Errors       []error
}

ImportResult summarises the outcome of an import run.

WarningCount is the number of non-fatal anomalies detected during replay (e.g. orphaned EntityPathChangedEvent records, mismatched path-changed payloads). Warnings holds one descriptive error per increment, in detection order, so callers can render diagnostics rather than only a count. len(Warnings) == WarningCount as an invariant.

type ListItem added in v0.5.2

type ListItem struct {
	EntityID string                 `json:"entity_id"`
	Path     string                 `json:"path"`
	Type     inventory.EntityType   `json:"type"`
	Status   inventory.EntityStatus `json:"status"`
}

ListItem is the `list` command's JSON output shape: one row per entity.

func ToListItems added in v0.5.2

func ToListItems(results []EntityResult) []ListItem

ToListItems projects entity results into the `list` output shape.

type ListTagsRequest added in v0.6.0

type ListTagsRequest struct {
	EntityPath string
}

ListTagsRequest is the input for listing tags on an entity.

type MoveOutput added in v0.5.2

type MoveOutput struct {
	EntityID    string `json:"entity_id"`
	DisplayName string `json:"display_name"`
	Path        string `json:"path"`
}

MoveOutput is the `move` command's JSON output shape. It reports the entity's current location only; the prior location is recorded by the move event and surfaced via the history command (ADR 0014).

func ToMoveOutput added in v0.5.2

func ToMoveOutput(result EntityResult) MoveOutput

ToMoveOutput projects a moved entity result into the `move` output shape.

type RemoveEntityRequest

type RemoveEntityRequest struct {
	EntityPath string
	ActorID    string
	Note       string
}

RemoveEntityRequest is the input for removing an entity.

type RenameEntityRequest

type RenameEntityRequest struct {
	EntityPath string
	NewName    string
	ActorID    string
	Note       string
}

RenameEntityRequest is the input for renaming an entity.

type ReparentEntityRequest

type ReparentEntityRequest struct {
	EntityPath    string
	NewParentPath string // empty means make root-level
	ActorID       string
	Note          string
}

ReparentEntityRequest is the input for moving an entity to a new parent.

type ScryItem added in v0.5.2

type ScryItem struct {
	EntityID string                 `json:"entity_id"`
	Path     string                 `json:"path"`
	Type     inventory.EntityType   `json:"type"`
	Status   inventory.EntityStatus `json:"status"`
	Distance *int                   `json:"distance"`
}

ScryItem is the `scry` command's JSON output shape. It currently coincides with ListItem, but is kept separate because scry is expected to gain a match Distance field (see issue #216) that list does not have.

func ToScryItems added in v0.5.2

func ToScryItems(results []FindResult, searched bool) []ScryItem

ToScryItems projects entity results into the `scry` output shape. Callers flatten []FindResult to []EntityResult first; the match Distance is dropped (see issue #216).

type StatusOutput added in v0.5.2

type StatusOutput struct {
	Path          string                 `json:"path"`
	Status        inventory.EntityStatus `json:"status"`
	StatusContext *string                `json:"status_context,omitempty"`
}

StatusOutput is the `status` command's JSON output shape. Because ChangeStatus returns no result, this is projected from the command's inputs rather than an EntityResult (see issue #214). StatusContext is omitted when there is no note.

func ToStatusOutput added in v0.5.2

func ToStatusOutput(path string, status inventory.EntityStatus, note string) StatusOutput

ToStatusOutput projects a status change into the `status` output shape. An empty note yields a nil StatusContext, which omitempty drops from the JSON.

type TagEntityRequest added in v0.6.0

type TagEntityRequest struct {
	EntityPath string
	ActorID    string
	Add        []string
	Remove     []string
	Note       string
}

TagEntityRequest is the input for adding/removing tags on an entity.

type TagOutput added in v0.6.0

type TagOutput struct {
	Path string   `json:"path"`
	Tags []string `json:"tags"`
}

TagOutput is the --json output shape for the tag command.

func ToTagOutput added in v0.6.0

func ToTagOutput(path string, tags []string) TagOutput

ToTagOutput builds a TagOutput from a path and sorted tag slice.

Jump to

Keyboard shortcuts

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