record

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package record persists Decision, Finding and Artifact records as one file per record under .devsys/{decisions,findings,artifacts}/<id>.yaml (方案 §14.3, 实施计划 M1.5). IDs are decision-<N> / finding-<N> / artifact-<N> with a per-kind sequence; Artifact versions are immutable files chained by previous_id (方案 §5.5).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("record not found")
	ErrBadID    = errors.New("invalid record id")
	ErrBadKind  = errors.New("unknown record kind")
	ErrConflict = storage.ErrConflict
)

Errors reported to callers.

View Source
var ErrSuperseded = errors.New("record: artifact already has a newer version")

ErrSuperseded reports that the artifact already has a newer version: the version chain is linear, so a second append from the same parent is refused instead of forking history. Re-read the head and append from it.

Functions

This section is empty.

Types

type Kind

type Kind string

Kind selects the record family and its directory.

const (
	KindDecision Kind = "decision"
	KindFinding  Kind = "finding"
	KindArtifact Kind = "artifact"
)

func (Kind) ValidID

func (k Kind) ValidID(id string) bool

ValidID reports whether id is well-formed for kind.

type Store

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

Store binds record operations to a project root.

func New

func New(root string) *Store

New binds the record layer to a project root (the directory containing .devsys, which must exist).

func (*Store) AppendArtifactVersion

func (s *Store) AppendArtifactVersion(ctx context.Context, currentID string, expected []byte, mutate func(*domain.Artifact)) (string, error)

AppendArtifactVersion appends a new artifact version: the previous version is read inside the write transaction, the caller's expected bytes (from ReadArtifact) must still match, mutate may patch the copy, and the result is written as a new file (previous_id links back; the old file is never rewritten). It returns the new artifact's ID.

The append is refused with ErrSuperseded when a child of currentID already exists, so concurrent appends cannot fork the chain or duplicate version numbers.

func (*Store) ArtifactHistory

func (s *Store) ArtifactHistory(ctx context.Context, id string) ([]*domain.Artifact, error)

ArtifactHistory walks the previous_id chain backwards from id and returns the versions newest-first; a broken link is reported, not skipped.

func (*Store) CreateArtifact

func (s *Store) CreateArtifact(ctx context.Context, a *domain.Artifact) (string, error)

CreateArtifact stores the first version of an artifact (version 1, no previous link) and returns its assigned ID.

func (*Store) CreateDecision

func (s *Store) CreateDecision(ctx context.Context, d *domain.Decision) (string, error)

CreateDecision stores a decision and returns its assigned ID.

func (*Store) CreateFinding

func (s *Store) CreateFinding(ctx context.Context, f *domain.Finding) (string, error)

CreateFinding stores a finding and returns its assigned ID.

func (*Store) GetArtifact

func (s *Store) GetArtifact(ctx context.Context, id string) (*domain.Artifact, error)

GetArtifact decodes one artifact version.

func (*Store) GetDecision

func (s *Store) GetDecision(ctx context.Context, id string) (*domain.Decision, error)

GetDecision decodes one decision.

func (*Store) GetFinding

func (s *Store) GetFinding(ctx context.Context, id string) (*domain.Finding, error)

GetFinding decodes one finding.

func (*Store) ListArtifacts

func (s *Store) ListArtifacts(ctx context.Context) ([]*domain.Artifact, error)

ListArtifacts returns every artifact version in ascending ID order.

func (*Store) ListDecisions

func (s *Store) ListDecisions(ctx context.Context) ([]*domain.Decision, error)

ListDecisions returns every decision in ascending ID order.

func (*Store) ListFindings

func (s *Store) ListFindings(ctx context.Context) ([]*domain.Finding, error)

ListFindings returns every finding in ascending ID order.

func (*Store) NewArtifactVersion

func (s *Store) NewArtifactVersion(ctx context.Context, currentID string, next *domain.Artifact) (string, error)

NewArtifactVersion appends a new version of an artifact: it reads the current file, copies every field into next, then writes next as a NEW file with version+1 and previous_id pointing at the current ID. Existing files are never modified, so history stays immutable and traversable.

func (*Store) ReadArtifact

func (s *Store) ReadArtifact(ctx context.Context, id string) (*domain.Artifact, []byte, error)

ReadArtifact reads one artifact with its raw bytes.

func (*Store) ReadDecision

func (s *Store) ReadDecision(ctx context.Context, id string) (*domain.Decision, []byte, error)

ReadDecision reads one decision with its raw bytes: the version hash the surfaces report and the guard an update consumes both derive from them.

func (*Store) ReadFinding

func (s *Store) ReadFinding(ctx context.Context, id string) (*domain.Finding, []byte, error)

ReadFinding reads one finding with its raw bytes.

func (*Store) UpdateDecision

func (s *Store) UpdateDecision(ctx context.Context, d *domain.Decision, expected []byte) error

UpdateDecision rewrites a decision under the version guard (the caller's expected bytes come from ReadDecision).

func (*Store) UpdateFinding

func (s *Store) UpdateFinding(ctx context.Context, f *domain.Finding, expected []byte) error

UpdateFinding rewrites a finding under the version guard.

Jump to

Keyboard shortcuts

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