artifact

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package artifact is the snapshot/artifact pipeline (roadmap E4): it turns a product-rendered dataset into an IMMUTABLE, versioned artifact — content plus its sha256, a structured sidecar, and the template version/effective date it was produced under. The framework owns immutability (append-only grants), per-(tenant,kind) versioning, hashing, and tamper-verification; the product supplies the rendered bytes (e.g. a PDF/A from its own renderer), so no document-format library enters the kernel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact struct {
	ID              uuid.UUID
	Kind            string
	Version         int
	ContentHash     string
	ContentType     string
	Sidecar         map[string]any
	TemplateVersion string
	Content         []byte
}

Artifact is a stored artifact's metadata (Content is included only by Get).

type Input

type Input struct {
	Kind            string // 'receipt', 'certificate', …
	Content         []byte
	ContentType     string // default application/pdf
	Sidecar         map[string]any
	TemplateVersion string
	EffectiveDate   time.Time // zero → NULL
}

Input describes one artifact to generate. Content is the product-rendered bytes (the framework hashes and stores them verbatim — it never re-encodes them).

type Pipeline

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

Pipeline generates and reads artifacts.

func New

func New(idgen model.IDGen) *Pipeline

New builds the pipeline.

func (*Pipeline) Generate

func (p *Pipeline) Generate(ctx context.Context, db database.TenantDB, in Input) (Artifact, error)

Generate hashes and stores an immutable artifact in the caller's tenant tx, assigning the next per-(tenant,kind) version. Content is required. A concurrent generate of the same kind that collides on version returns KindConflict (retry).

func (*Pipeline) Get

func (p *Pipeline) Get(ctx context.Context, db database.TenantDB, id uuid.UUID) (Artifact, error)

Get returns an artifact including its content.

func (*Pipeline) List

func (p *Pipeline) List(ctx context.Context, db database.TenantDB, kind string) ([]Artifact, error)

List returns a kind's artifacts newest-version first (metadata only, no content).

func (*Pipeline) Verify

func (p *Pipeline) Verify(ctx context.Context, db database.TenantDB, id uuid.UUID) (bool, error)

Verify re-hashes the stored content and reports whether it still matches the recorded content_hash — detecting any out-of-band mutation of an artifact (app_rt cannot UPDATE/DELETE, but this catches a DBA/owner tamper).

type TemplateVersion

type TemplateVersion struct {
	Version       string
	EffectiveFrom time.Time
}

TemplateVersion identifies a template revision and the instant from which it takes effect. Artifacts record which version they were produced under, so a document can always be regenerated or explained against the rules that applied on its effective date (roadmap E4: "templates versioned by effective date").

type Templates

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

Templates resolves which template version applies at a given date. It is an in-memory registry populated at boot (the versions themselves — the actual rendering assets — live wherever the product keeps them).

func NewTemplates

func NewTemplates() *Templates

NewTemplates builds an empty registry.

func (*Templates) Register

func (t *Templates) Register(kind, version string, effectiveFrom time.Time)

Register adds a template version for a kind, effective from the given instant. Registering the same version again updates its effective date.

func (*Templates) Resolve

func (t *Templates) Resolve(kind string, at time.Time) (TemplateVersion, bool)

Resolve returns the template version in effect for kind at instant `at` — the one with the latest EffectiveFrom not after `at`. ok is false when the kind is unknown or every version begins after `at`.

Jump to

Keyboard shortcuts

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