specs

package
v0.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registry

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

Registry provides CRUD operations on the specs table.

func New

func New(db *sql.DB) *Registry

New creates a new Registry.

func (*Registry) AcceptRule

func (r *Registry) AcceptRule(ctx context.Context, project, ruleID string) error

AcceptRule sets a proposed rule's status to accepted.

func (*Registry) Delete

func (r *Registry) Delete(ctx context.Context, project, name string) error

Delete removes a spec by project and name.

func (*Registry) DeleteRule

func (r *Registry) DeleteRule(ctx context.Context, project, ruleID string) error

DeleteRule removes a single validation rule.

func (*Registry) ExportRules

func (r *Registry) ExportRules(ctx context.Context, sources []string) ([]Rule, error)

ExportRules returns all rules matching the given sources across all projects.

func (*Registry) Get

func (r *Registry) Get(ctx context.Context, project, name string) (*Spec, error)

Get retrieves a spec by project and name. Returns sql.ErrNoRows if not found.

func (*Registry) GetRule

func (r *Registry) GetRule(ctx context.Context, project, ruleID string) (*Rule, error)

GetRule returns a single rule by project and rule_id.

func (*Registry) ImportRules

func (r *Registry) ImportRules(ctx context.Context, rules []Rule) (int, error)

ImportRules bulk-inserts rules, using UPSERT to avoid conflicts.

func (*Registry) List

func (r *Registry) List(ctx context.Context, project string) ([]Summary, error)

List returns summaries of all specs for a project (no data blobs).

func (*Registry) ListAllRules

func (r *Registry) ListAllRules(ctx context.Context, project, stack, source, status string) ([]Rule, error)

ListAllRules returns rules across all projects with optional filters.

func (*Registry) ListRules

func (r *Registry) ListRules(ctx context.Context, project string) ([]Rule, error)

ListRules returns all validation rules for a project.

func (*Registry) ProposeRule

func (r *Registry) ProposeRule(ctx context.Context, rule Rule) error

ProposeRule inserts a rule with source=learned, status=proposed.

func (*Registry) Put

func (r *Registry) Put(ctx context.Context, project, name string, data []byte) (*Spec, error)

Put creates or updates a spec. Version auto-increments on update.

func (*Registry) PutRules

func (r *Registry) PutRules(ctx context.Context, project string, rules []Rule) error

PutRules replaces all validation rules for a project.

func (*Registry) RejectRule

func (r *Registry) RejectRule(ctx context.Context, project, ruleID string) error

RejectRule sets a proposed rule's status to rejected.

func (*Registry) Validate

func (r *Registry) Validate(ctx context.Context, project string, req ValidateRequest) ([]Violation, error)

Validate runs all rules for a project against the given content. It also includes _global rules (external rules that apply across all projects).

type Rule

type Rule struct {
	Project    string   `json:"project"`
	RuleID     string   `json:"rule_id"`
	Severity   string   `json:"severity"`
	MatchType  string   `json:"match_type"`
	Pattern    string   `json:"pattern"`
	Message    string   `json:"message"`
	Stack      string   `json:"stack"`
	AppliesTo  []string `json:"applies_to"`
	Source     string   `json:"source"`
	Status     string   `json:"status"`
	ProposedBy string   `json:"proposed_by,omitempty"`
	Context    string   `json:"context,omitempty"`
	CreatedAt  string   `json:"created_at,omitempty"`
}

Rule is a validation rule.

type Spec

type Spec struct {
	Project   string    `json:"project"`
	Name      string    `json:"name"`
	Data      []byte    `json:"-"`
	Version   int64     `json:"version"`
	Hash      string    `json:"hash"`
	UpdatedAt time.Time `json:"updated_at"`
}

Spec is a full specification entry including its data.

type Summary

type Summary struct {
	Name      string    `json:"name"`
	Version   int64     `json:"version"`
	UpdatedAt time.Time `json:"updated_at"`
}

Summary is a spec entry without its data, used for listing.

type ValidateRequest

type ValidateRequest struct {
	Filename string `json:"filename"`
	Content  string `json:"content"`
	Stack    string `json:"stack"`
}

ValidateRequest holds the content to validate.

type Violation

type Violation struct {
	RuleID   string `json:"rule_id"`
	Severity string `json:"severity"`
	Message  string `json:"message"`
	Line     int    `json:"line,omitempty"`
	Match    string `json:"match,omitempty"`
}

Violation is a single rule violation found during validation.

Jump to

Keyboard shortcuts

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