usecase

package
v0.0.5-RELEASE Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package usecase holds Sauron's use cases and the actions they compose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFxOptions

func NewFxOptions() fx.Option

NewFxOptions wires the use cases and actions.

Types

type Action

type Action[R, P any] interface {
	Execute(ctx context.Context, in R) (*P, error)
}

Action is a stateless, composable step a use case runs: executed with a context and an input R, it returns a *P product or a classified *Error.

type AddRegistryRequest

type AddRegistryRequest struct {
	Name      string
	URI       string
	Transport string
	Ref       string
	Username  string
	Password  string
	SSHKey    string

	SkipTLSVerify bool
	CACert        string
	ClientCert    string
	ClientKey     string

	Timeout time.Duration
	// contains filtered or unexported fields
}

AddRegistryRequest is the per-invocation input for registering a source.

func NewAddRegistryRequest

func NewAddRegistryRequest(ctx context.Context, out io.Writer) *AddRegistryRequest

NewAddRegistryRequest builds a request bound to ctx and writing to out.

func (AddRegistryRequest) Out

func (r AddRegistryRequest) Out() io.Writer

Out returns the writer the command's output goes to.

type AddRegistryUseCase

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

AddRegistryUseCase registers a validated, reachable source.

func NewAddRegistryUseCase

func NewAddRegistryUseCase(params AddRegistryUseCaseParams) *AddRegistryUseCase

NewAddRegistryUseCase builds the use case from the injected adapters and collaborators.

func (*AddRegistryUseCase) Execute

func (uc *AddRegistryUseCase) Execute(request *AddRegistryRequest) error

Execute runs the ordered registration pipeline, returning a *Error on the first failing step.

type AddRegistryUseCaseParams

type AddRegistryUseCaseParams struct {
	fx.In
	Filesystem extension.Registry `name:"registry.filesystem"`
	Git        extension.Registry `name:"registry.git"`
	HTTP       extension.Registry `name:"registry.http"`
	Open       OpenRegistry
	Registries storage.RegistriesStore
	Logger     *zap.Logger
}

AddRegistryUseCaseParams injects the adapters and collaborators the use case composes.

type CatalogueKind

type CatalogueKind string

CatalogueKind is the kind of artifact a catalogue listing browses; it fixes the source root listed and the projection applied.

const (
	// CatalogueSkill browses the skills a registry offers under .skills.
	CatalogueSkill CatalogueKind = "skill"
	// CatalogueAgent browses the agents a registry offers under .agents.
	CatalogueAgent CatalogueKind = "agent"
	// CataloguePersona browses the personas a registry offers under .personas.
	CataloguePersona CatalogueKind = "persona"
)

The kinds a catalogue listing can browse.

type DeleteArtifactsByRegistryResponse

type DeleteArtifactsByRegistryResponse struct {
	Skills   []string
	Agents   []string
	Personas []string
}

DeleteArtifactsByRegistryResponse is the set of artifacts a cascade uninstall removes, grouped by kind. It is the value both delete-registry and uninstall report.

func (DeleteArtifactsByRegistryResponse) Total

Total is the number of artifacts the plan removes across every kind.

type DeleteRegistryRequest

type DeleteRegistryRequest struct {
	Name   string
	DryRun bool
	// contains filtered or unexported fields
}

DeleteRegistryRequest is the per-invocation input for deleting a source.

func NewDeleteRegistryRequest

func NewDeleteRegistryRequest(ctx context.Context, out io.Writer) *DeleteRegistryRequest

NewDeleteRegistryRequest builds a request bound to ctx and writing to out.

func (DeleteRegistryRequest) Out

func (r DeleteRegistryRequest) Out() io.Writer

Out returns the writer the command's output goes to.

type DeleteRegistryUseCase

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

DeleteRegistryUseCase unregisters a source and cascade-uninstalls its artifacts.

func NewDeleteRegistryUseCase

func NewDeleteRegistryUseCase(params DeleteRegistryUseCaseParams) *DeleteRegistryUseCase

NewDeleteRegistryUseCase builds the use case from the injected collaborators.

func (*DeleteRegistryUseCase) Execute

func (uc *DeleteRegistryUseCase) Execute(request *DeleteRegistryRequest) error

Execute runs the find → cascade → dry-run → remove → report pipeline, returning a *Error on the first failing step. A registry that does not exist is a success.

type DeleteRegistryUseCaseParams

type DeleteRegistryUseCaseParams struct {
	fx.In
	Registries storage.RegistriesStore
	Cascade    *UninstallByRegistryAction
	Logger     *zap.Logger
}

DeleteRegistryUseCaseParams injects the collaborators the use case composes.

type DescribeRegistryRequest

type DescribeRegistryRequest struct {
	Name   string
	Fields []string
	// contains filtered or unexported fields
}

DescribeRegistryRequest is the per-invocation input for describing a registry.

func NewDescribeRegistryRequest

func NewDescribeRegistryRequest(ctx context.Context, out io.Writer) *DescribeRegistryRequest

NewDescribeRegistryRequest builds a request bound to ctx and writing to out.

func (DescribeRegistryRequest) Out

func (r DescribeRegistryRequest) Out() io.Writer

Out returns the writer the command's output goes to.

type DescribeRegistryUseCase

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

DescribeRegistryUseCase reads one registry and renders its full detail.

func NewDescribeRegistryUseCase

func NewDescribeRegistryUseCase(params DescribeRegistryUseCaseParams) *DescribeRegistryUseCase

NewDescribeRegistryUseCase builds the use case from the injected collaborators.

func (*DescribeRegistryUseCase) Execute

Execute runs the find → not-found → project → render pipeline, returning a *Error on the first failing step.

type DescribeRegistryUseCaseParams

type DescribeRegistryUseCaseParams struct {
	fx.In
	Registries storage.RegistriesStore
	Logger     *zap.Logger
}

DescribeRegistryUseCaseParams injects the collaborators the use case composes.

type Error

type Error struct {
	Type   Type
	Reason string
}

Error is a classified use-case failure: Type buckets it, Reason explains it.

func NewConflictError

func NewConflictError(reason string) *Error

NewConflictError reports a collision with existing state.

func NewIOError

func NewIOError(reason string) *Error

NewIOError reports a failure of the underlying storage.

func NewNotFoundError

func NewNotFoundError(reason string) *Error

NewNotFoundError reports a named resource that does not exist.

func NewUnreachableError

func NewUnreachableError(reason string) *Error

NewUnreachableError reports a source that could not be reached or read.

func NewUsageError

func NewUsageError(reason string) *Error

NewUsageError reports a correctable caller mistake.

func (*Error) Error

func (e *Error) Error() string

Error returns the human-readable reason.

type ListCatalogueRequest

type ListCatalogueRequest struct {
	Kind     CatalogueKind
	Registry string
	Search   string
	Sort     string
	Order    string
	Page     int64
	Limit    int64
	// contains filtered or unexported fields
}

ListCatalogueRequest is the per-invocation input for browsing a registry's catalogue of one kind.

func NewListCatalogueRequest

func NewListCatalogueRequest(ctx context.Context, out io.Writer) *ListCatalogueRequest

NewListCatalogueRequest builds a request bound to ctx and writing to out.

func (ListCatalogueRequest) Out

func (r ListCatalogueRequest) Out() io.Writer

Out returns the writer the command's output goes to.

type ListCatalogueUseCase

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

ListCatalogueUseCase resolves a registry, opens its source live, and renders the artifacts of the selected kind followed by a paging line.

func NewListCatalogueUseCase

func NewListCatalogueUseCase(params ListCatalogueUseCaseParams) *ListCatalogueUseCase

NewListCatalogueUseCase builds the use case from the injected collaborators.

func (*ListCatalogueUseCase) Execute

func (uc *ListCatalogueUseCase) Execute(request *ListCatalogueRequest) error

Execute runs the validate → find → open → list → project → render pipeline, returning a classified *Error on the first failing step.

type ListCatalogueUseCaseParams

type ListCatalogueUseCaseParams struct {
	fx.In
	Registries storage.RegistriesStore
	Open       OpenRegistry
	Logger     *zap.Logger
}

ListCatalogueUseCaseParams injects the collaborators the use case composes.

type ListRegistriesRequest

type ListRegistriesRequest struct {
	Search string
	Fields []string
	Sort   string
	Order  string
	// contains filtered or unexported fields
}

ListRegistriesRequest is the per-invocation input for the registry listing.

func NewListRegistriesRequest

func NewListRegistriesRequest(ctx context.Context, out io.Writer) *ListRegistriesRequest

NewListRegistriesRequest builds a request bound to ctx and writing to out.

func (ListRegistriesRequest) Out

func (r ListRegistriesRequest) Out() io.Writer

Out returns the writer the command's output goes to.

type ListRegistriesUseCase

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

ListRegistriesUseCase reads, filters, sorts, and renders the registry listing.

func NewListRegistriesUseCase

func NewListRegistriesUseCase(params ListRegistriesUseCaseParams) *ListRegistriesUseCase

NewListRegistriesUseCase builds the use case from the injected collaborators.

func (*ListRegistriesUseCase) Execute

func (uc *ListRegistriesUseCase) Execute(request *ListRegistriesRequest) error

Execute runs the read → filter → sort → project → render pipeline, returning a *Error on the first failing step.

type ListRegistriesUseCaseParams

type ListRegistriesUseCaseParams struct {
	fx.In
	Registries storage.RegistriesStore
	Logger     *zap.Logger
}

ListRegistriesUseCaseParams injects the collaborators the use case composes.

type MockBasedOpenRegistry

type MockBasedOpenRegistry struct {
	mock.Mock
}

MockBasedOpenRegistry is a testify mock implementing OpenRegistry.

func (*MockBasedOpenRegistry) Execute

Execute records the call and returns the configured values.

type OpenRegistry

type OpenRegistry interface {
	// Execute opens registry's source over its transport, returning the
	// read-only file system, or a classified *Error.
	Execute(ctx context.Context, registry types.Registry) (source.FileSystem, error)
}

OpenRegistry opens a stored registry's source. It is the seam downstream use cases compose and tests mock.

type OpenRegistryAction

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

OpenRegistryAction opens a stored registry's source: it selects the transport adapter, resolves ${env:VAR} credential references, builds the extension option set from the registry spec, and opens the source. It is the shared open-a-stored-registry step the catalogue, install, and listing use cases compose. An open failure classifies as unreachable.

func NewOpenRegistryAction

func NewOpenRegistryAction(params OpenRegistryActionParams) *OpenRegistryAction

NewOpenRegistryAction builds the action from the injected adapters and collaborators.

func (*OpenRegistryAction) Execute

func (a *OpenRegistryAction) Execute(ctx context.Context, registry types.Registry) (source.FileSystem, error)

Execute opens registry's source over its transport, returning the read-only file system. It returns a usage *Error for an unknown transport, an unreachable *Error for an unset credential reference or a failed open.

type OpenRegistryActionParams

type OpenRegistryActionParams struct {
	fx.In
	Filesystem extension.Registry `name:"registry.filesystem"`
	Git        extension.Registry `name:"registry.git"`
	HTTP       extension.Registry `name:"registry.http"`
	Logger     *zap.Logger
}

OpenRegistryActionParams injects the named transport adapters and collaborators the action composes.

type Request

type Request interface {
	context.Context
	// Out returns the writer the command's output goes to.
	Out() io.Writer
}

Request is the per-invocation context object: a context.Context that also exposes the command's output writer.

type Type

type Type string

Type classifies a use-case failure so callers can map it to an exit code or presentation without inspecting the reason text.

const (
	// TypeUsage marks a caller mistake that can be corrected by changing input.
	TypeUsage Type = "usage"
	// TypeConflict marks a request that collides with existing state.
	TypeConflict Type = "conflict"
	// TypeUnreachable marks a source that could not be reached or read.
	TypeUnreachable Type = "unreachable"
	// TypeIO marks a failure of the underlying storage.
	TypeIO Type = "io"
	// TypeNotFound marks a named resource that does not exist.
	TypeNotFound Type = "not_found"
)

The classes a use case attaches to a failure.

type UninstallByRegistryAction

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

UninstallByRegistryAction removes every tracked artifact sourced from a registry. It is the shared cleaning step both delete-registry and uninstall compose.

func NewUninstallByRegistryAction

func NewUninstallByRegistryAction(params UninstallByRegistryActionParams) *UninstallByRegistryAction

NewUninstallByRegistryAction builds the action from the injected collaborators.

func (*UninstallByRegistryAction) Execute

Execute returns the plan of artifacts removed for the registry.

0007 owns the real body: the track store read, the per-artifact provider removal, and the track.yaml rewrite. Until then this is a no-op — it removes nothing and returns an empty plan, so an applied delete reports zero artifacts removed.

type UninstallByRegistryActionParams

type UninstallByRegistryActionParams struct {
	fx.In
	Logger *zap.Logger
}

UninstallByRegistryActionParams injects the collaborators the action composes.

type UseCase

type UseCase[R Request] interface {
	Execute(request R) error
}

UseCase is a command's stateless entrypoint, executed with a Request.

Jump to

Keyboard shortcuts

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