Documentation
¶
Overview ¶
Package skills owns Skills: tenant-owned bundles with immutable, numbered versions and a default version. It holds their vocabulary, the identifier, version and selector rules, the version deletion rules, and the use cases behind the Skills API. persistence/postgres/skillpg implements its storage.
Index ¶
- Constants
- Variables
- func FormatID(id uuid.UUID) string
- func FormatVersionID(id uuid.UUID) string
- func ParseID(value string) (uuid.UUID, error)
- func ParseVersion(value string) (int64, error)
- func ParseVersionID(value string) (uuid.UUID, error)
- func PathID(value string) uuid.UUID
- func PathVersion(value string) int64
- func SelectVersion(selector string, defaultVersion, latestVersion int64) (int64, error)
- func ValidateSelector(selector string) error
- func VerifyContent(content Content) error
- type Content
- type CreateSkill
- type CreateVersion
- type CursorError
- type DeleteSkill
- type DeleteVersion
- type ListSkills
- type ListVersions
- type NewSkill
- type NewVersion
- type Page
- type ReadDefaultVersion
- type ReadVersion
- type Reader
- type Service
- func (s *Service) CreateSkill(ctx context.Context, c CreateSkill) (Skill, error)
- func (s *Service) CreateVersion(ctx context.Context, c CreateVersion) (Version, error)
- func (s *Service) DeleteSkill(ctx context.Context, c DeleteSkill) error
- func (s *Service) DeleteVersion(ctx context.Context, c DeleteVersion) (Version, error)
- func (s *Service) ListSkills(ctx context.Context, c ListSkills) (Page, error)
- func (s *Service) ListVersions(ctx context.Context, c ListVersions) (VersionPage, error)
- func (s *Service) ReadDefaultVersion(ctx context.Context, c ReadDefaultVersion) (Content, error)
- func (s *Service) ReadVersion(ctx context.Context, c ReadVersion) (Content, error)
- func (s *Service) SetDefaultVersion(ctx context.Context, c SetDefaultVersion) (Skill, error)
- type SetDefaultVersion
- type Skill
- type SkillCursor
- type SkillPageQuery
- type Storage
- type Version
- type VersionDeletion
- type VersionDeletionFacts
- type VersionDeletionTx
- type VersionPage
- type VersionPageQuery
Constants ¶
const MaxPageLimit = 100
MaxPageLimit bounds every Skill and version page. A limit of 0 returns an empty page whose HasMore reports whether anything follows the cursor.
Variables ¶
var ( // ErrNotFound reports a Skill or version that does not exist in the tenant. // Malformed identifiers and other tenants' resources are indistinguishable // from missing ones. ErrNotFound = errors.New("skill not found") // ErrVersionNotFound reports a version number that names no version of an // existing Skill. ErrVersionNotFound = errors.New("skill version not found") // ErrInvalidInput reports an invalid archive, version, page limit or tenant. ErrInvalidInput = errors.New("invalid skill request") // ErrDefaultVersion rejects deleting the default version while other // versions remain. ErrDefaultVersion = errors.New("cannot delete the default skill version") )
var ErrInvalidVersion = errors.New("skill version must be a canonical positive decimal integer")
ErrInvalidVersion reports a version that is not a canonical positive decimal.
Functions ¶
func FormatVersionID ¶
FormatVersionID returns the public ID of the version whose key is id.
func ParseID ¶
ParseID returns the key of a public Skill ID: "skill_" followed by a canonical, nonzero UUID. Any other value names no Skill and is ErrNotFound.
func ParseVersion ¶
ParseVersion accepts only the canonical decimal spelling of a positive version number, so every version has exactly one text form. Selecting "latest" or an omitted version belongs to the caller.
func ParseVersionID ¶
ParseVersionID returns the key of a public version ID ("skillver_").
func PathID ¶
PathID resolves a Skill ID from a request path. A malformed value resolves to the maximum UUID, which Core never assigns, so the request follows exactly the missing-Skill path. Request-body references use ParseID.
func PathVersion ¶
PathVersion resolves a version number from a request path. Versions start at 1, so a malformed value resolves to the never-assigned version 0 and follows the missing-version path. Request-body selectors use ParseVersion.
func SelectVersion ¶
SelectVersion resolves a Skill reference's version selector against the Skill's pointers: empty selects the default version, "latest" the latest, and any other value must be a concrete version.
func ValidateSelector ¶
ValidateSelector checks a version selector without resolving it.
func VerifyContent ¶
VerifyContent checks that a decrypted archive is still the complete bundle its version records, before anything reads or installs it.
Types ¶
type CreateSkill ¶
CreateSkill uploads a new Skill.
type CreateVersion ¶
CreateVersion uploads a new version of a Skill.
type CursorError ¶
type CursorError struct{ Message string }
CursorError reports a version list cursor that does not name a version of the listed Skill. Message is the official message for the case.
func (*CursorError) Error ¶
func (e *CursorError) Error() string
type DeleteSkill ¶
DeleteSkill deletes a Skill and its versions. Session installations frozen from them are independent copies and remain.
type DeleteVersion ¶
DeleteVersion deletes one version of a Skill.
type ListSkills ¶
ListSkills lists the tenant's Skills. After is a Skill ID; a malformed or missing one is ErrNotFound.
type ListVersions ¶
type ListVersions struct {
TenantID string
SkillID uuid.UUID
After string
Limit int
Ascending bool
}
ListVersions lists a Skill's versions. After is a version ID, not a version number.
type NewVersion ¶
type NewVersion struct {
TenantID string
SkillID uuid.UUID
Name string
Description string
Archive []byte
MakeDefault bool
}
NewVersion is a validated upload for an existing Skill. MakeDefault also points the Skill's default at the new version.
type ReadDefaultVersion ¶
ReadDefaultVersion reads the archive of a Skill's default version, selecting the pointer and the content in one read.
type ReadVersion ¶
ReadVersion reads one version's archive.
type Reader ¶
type Reader interface {
Skill(ctx context.Context, tenantID string, id uuid.UUID) (Skill, error)
// Skills lists one page of the tenant's Skills in creation order, then by
// ID; a nil After starts at the first Skill.
Skills(ctx context.Context, tenantID string, page SkillPageQuery) (Page, error)
// VersionByID finds a version anywhere in the tenant, so a list cursor can
// tell another Skill's version from a missing one.
VersionByID(ctx context.Context, tenantID string, id uuid.UUID) (Version, error)
// Versions lists one page of a Skill's versions in version order.
Versions(ctx context.Context, tenantID string, skillID uuid.UUID, page VersionPageQuery) (VersionPage, error)
// VersionContent and DefaultVersionContent decrypt one version's archive.
VersionContent(ctx context.Context, tenantID string, skillID uuid.UUID, version int64) (Content, error)
DefaultVersionContent(ctx context.Context, tenantID string, skillID uuid.UUID) (Content, error)
}
Reader reads Skills. Reads never lock and never decrypt metadata-only results.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service runs the Skill use cases.
func (*Service) CreateSkill ¶
CreateSkill validates the archive and stores it as the new Skill's version 1.
func (*Service) CreateVersion ¶
CreateVersion validates the archive before looking up the Skill, then stores it under the Skill's next version number.
func (*Service) DeleteSkill ¶
func (s *Service) DeleteSkill(ctx context.Context, c DeleteSkill) error
func (*Service) DeleteVersion ¶
DeleteVersion decides under the Skill's lock, so it serializes with uploads and pointer changes, and returns the deleted version.
func (*Service) ListSkills ¶
func (*Service) ListVersions ¶
func (s *Service) ListVersions(ctx context.Context, c ListVersions) (VersionPage, error)
ListVersions resolves the Skill before the cursor. A cursor that is not a version ID is a CursorError; a missing version, including another tenant's, is ErrNotFound; another Skill's version in the tenant is a CursorError. The Skill is looked up again before that last error, so a Skill deleted in between stays not found.
func (*Service) ReadDefaultVersion ¶
func (*Service) ReadVersion ¶
func (*Service) SetDefaultVersion ¶
type SetDefaultVersion ¶
SetDefaultVersion points a Skill's default at one of its versions. Version is the request's selector and must be a concrete version number.
type Skill ¶
type Skill struct {
ID string
Name string
Description string
CreatedAt time.Time
DefaultVersion int64
LatestVersion int64
}
Skill is a tenant-owned Skill. Its name and description are those of its default version.
type SkillCursor ¶
SkillCursor is the position of the Skill a page starts after.
type SkillPageQuery ¶
type SkillPageQuery struct {
After *SkillCursor
Limit int
Ascending bool
}
SkillPageQuery selects one page of Skills. Limit is at most MaxPageLimit.
type Storage ¶
type Storage interface {
// CreateSkill stores a new Skill with the archive as its version 1, which
// is both its default and latest version.
CreateSkill(context.Context, NewSkill) (Skill, error)
// CreateVersion locks the Skill and stores the archive under the Skill's
// next version number. It is ErrNotFound for a missing Skill and
// ErrInvalidInput once the version numbers are exhausted.
CreateVersion(context.Context, NewVersion) (Version, error)
// SetDefaultVersion locks the Skill and points its default at an existing
// version, whose name and description the Skill then takes.
SetDefaultVersion(ctx context.Context, tenantID string, skillID uuid.UUID, version int64) (Skill, error)
// DeleteSkill deletes the Skill and all its versions.
DeleteSkill(ctx context.Context, tenantID string, skillID uuid.UUID) error
// WithVersionDeletion locks the Skill, or is ErrNotFound, and runs apply
// in that transaction. It commits only when apply returns nil.
WithVersionDeletion(ctx context.Context, tenantID string, skillID uuid.UUID, apply func(VersionDeletionTx) error) error
}
Storage persists Skill writes. Each method, and each WithVersionDeletion callback, runs in one transaction that also records the write's audit. Tenant IDs are UUIDs; a malformed one is ErrInvalidInput.
type Version ¶
type Version struct {
ID string
SkillID string
Version int64
Name string
Description string
CreatedAt time.Time
}
Version is one immutable version of a Skill. Version numbers start at 1 and are never reused.
type VersionDeletion ¶
VersionDeletion is a decided version deletion. DeleteSkill deletes the whole Skill, whose only version Target is; otherwise only Target is deleted and RefreshLatest moves the latest pointer to the highest remaining version.
func DecideVersionDeletion ¶
func DecideVersionDeletion(facts VersionDeletionFacts) (VersionDeletion, error)
DecideVersionDeletion applies the deletion rules. The default version can be deleted only as the Skill's sole version, and that deletes the Skill itself; Session installations frozen from it are independent copies.
type VersionDeletionFacts ¶
type VersionDeletionFacts struct {
Skill Skill
Target Version
// OthersRemain reports whether the Skill has a version besides Target.
OthersRemain bool
}
VersionDeletionFacts is what a version deletion decides from, loaded under the Skill's lock.
type VersionDeletionTx ¶
type VersionDeletionTx interface {
// LoadVersionDeletion loads the facts DecideVersionDeletion needs. It is
// ErrNotFound when the Skill has no such version.
LoadVersionDeletion(version int64) (VersionDeletionFacts, error)
// ApplyVersionDeletion carries out a decided deletion.
ApplyVersionDeletion(VersionDeletion) error
}
VersionDeletionTx is one locked Skill during a version deletion.
type VersionPage ¶
VersionPage is one page of a Skill's versions.
type VersionPageQuery ¶
VersionPageQuery selects one page of versions after the version number AfterVersion, or from the first when it is 0.