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 ¶
- type AddOutput
- type App
- func (a *App) ChangeStatus(ctx context.Context, req ChangeStatusRequest) error
- func (a *App) CheckProjectionConsistency(ctx context.Context) ([]DoctorIssue, error)
- func (a *App) ClearAllData(ctx context.Context) error
- func (a *App) CreateEntity(ctx context.Context, req CreateEntityRequest) (EntityResult, error)
- func (a *App) FindEntities(ctx context.Context, req FindEntitiesRequest) ([]FindResult, error)
- func (a *App) GetAllEvents(ctx context.Context) ([]ExportResult, error)
- func (a *App) GetChildren(ctx context.Context, parentID string) ([]EntityResult, error)
- func (a *App) GetEntityByID(ctx context.Context, entityID string) (EntityResult, error)
- func (a *App) GetEntityByPath(ctx context.Context, path string) (EntityResult, error)
- func (a *App) GetHistory(ctx context.Context, req GetHistoryRequest) ([]HistoryResult, error)
- func (a *App) HasEvents(ctx context.Context) (bool, error)
- func (a *App) ImportEvents(ctx context.Context, events []ExportResult, opts ImportOptions) (ImportResult, error)
- func (a *App) ListEntities(ctx context.Context) ([]EntityResult, error)
- func (a *App) ListTags(ctx context.Context, req ListTagsRequest) ([]string, error)
- func (a *App) RemoveEntity(ctx context.Context, req RemoveEntityRequest) error
- func (a *App) RenameEntity(ctx context.Context, req RenameEntityRequest) (EntityResult, error)
- func (a *App) ReparentEntity(ctx context.Context, req ReparentEntityRequest) (EntityResult, error)
- func (a *App) RunDoctorChecks(ctx context.Context) ([]DoctorIssue, error)
- func (a *App) TagEntity(ctx context.Context, req TagEntityRequest) error
- func (a *App) TruncateAndReplay(ctx context.Context) (int, error)
- func (a *App) ValidateEventLog(ctx context.Context) ([]DoctorIssue, error)
- type ChangeStatusRequest
- type CreateEntityRequest
- type DoctorIssue
- type DoctorKind
- type EntityResult
- type ExportResult
- type FindEntitiesRequest
- type FindResult
- type GetHistoryRequest
- type HistoryItem
- type HistoryResult
- type ImportOptions
- type ImportResult
- type ListItem
- type ListTagsRequest
- type MoveOutput
- type RemoveEntityRequest
- type RenameEntityRequest
- type ReparentEntityRequest
- type ScryItem
- type StatusOutput
- type TagEntityRequest
- type TagOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddOutput ¶ added in v0.5.2
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 (*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
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 ¶
GetChildren returns direct children of parentID, excluding removed entities.
func (*App) GetEntityByID ¶ added in v0.3.0
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 ¶
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) 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
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
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 ¶
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 ¶
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 ¶
RemoveEntityRequest is the input for removing an entity.
type RenameEntityRequest ¶
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
TagOutput is the --json output shape for the tag command.
func ToTagOutput ¶ added in v0.6.0
ToTagOutput builds a TagOutput from a path and sorted tag slice.