check

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package check handles vault-wide validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InferConfidence

type InferConfidence int

InferConfidence indicates how confident we are about type inference.

const (
	ConfidenceUnknown  InferConfidence = iota // No type inference possible
	ConfidenceInferred                        // Inferred from path matching default_path
	ConfidenceCertain                         // Certain from typed field
)

func (InferConfidence) String

func (c InferConfidence) String() string

type Issue

type Issue struct {
	Level      IssueLevel
	Type       IssueType
	FilePath   string
	Line       int
	Message    string
	Value      string // The problematic value (type name, trait name, ref, etc.)
	FixCommand string // Suggested command to fix the issue
	FixHint    string // Human-readable fix hint
}

Issue represents a validation issue.

type IssueLevel

type IssueLevel int

IssueLevel indicates the severity of an issue.

const (
	LevelError IssueLevel = iota
	LevelWarning
)

func (IssueLevel) String

func (l IssueLevel) String() string

type IssueType

type IssueType string

IssueType categorizes validation issues for programmatic handling.

const (
	IssueUnknownType             IssueType = "unknown_type"
	IssueMissingReference        IssueType = "missing_reference"
	IssueUndefinedTrait          IssueType = "undefined_trait"
	IssueUnknownFrontmatter      IssueType = "unknown_frontmatter_key"
	IssueDuplicateID             IssueType = "duplicate_object_id"
	IssueMissingRequiredField    IssueType = "missing_required_field"
	IssueInvalidFieldValue       IssueType = "invalid_field_value"
	IssueMissingRequiredTrait    IssueType = "missing_required_trait"
	IssueInvalidEnumValue        IssueType = "invalid_enum_value"
	IssueAmbiguousReference      IssueType = "ambiguous_reference"
	IssueInvalidTraitValue       IssueType = "invalid_trait_value"
	IssueParseError              IssueType = "parse_error"
	IssueWrongTargetType         IssueType = "wrong_target_type"
	IssueInvalidDateFormat       IssueType = "invalid_date_format"
	IssueShortRefCouldBeFullPath IssueType = "short_ref_could_be_full_path"
	IssueStaleIndex              IssueType = "stale_index"
	IssueUnusedType              IssueType = "unused_type"
	IssueUnusedTrait             IssueType = "unused_trait"
	IssueMissingTargetType       IssueType = "missing_target_type"
	IssueSelfReferentialRequired IssueType = "self_referential_required"
	IssueUnknownFieldType        IssueType = "unknown_field_type"
	IssueIDCollision             IssueType = "id_collision"
	IssueDuplicateAlias          IssueType = "duplicate_alias"
	IssueAliasCollision          IssueType = "alias_collision"
	IssueStaleFragment           IssueType = "stale_fragment"
)

type MissingRef

type MissingRef struct {
	TargetPath     string          // The reference path (e.g., "people/baldur")
	SourceFile     string          // File containing the reference
	SourceObjectID string          // Full object ID where ref was found (e.g., "daily/2026-01-01#team-sync")
	Line           int             // Line number
	InferredType   string          // Type inferred from context (empty if unknown)
	Confidence     InferConfidence // How confident we are about the type
	FieldSource    string          // If from a typed field, the field name (e.g., "attendees")
}

MissingRef represents a reference to a non-existent object.

type ObjectInfo

type ObjectInfo struct {
	ID   string
	Type string
}

ObjectInfo contains basic info about an object for validation.

type SchemaIssue

type SchemaIssue struct {
	Level      IssueLevel
	Type       IssueType
	Message    string
	Value      string // The type/trait/field name
	FixCommand string
	FixHint    string
}

SchemaIssue represents a schema-level validation issue (not file-specific).

type UndefinedTrait

type UndefinedTrait struct {
	TraitName  string   // The trait name (without @)
	SourceFile string   // First file where it was found
	Line       int      // First line where it was found
	HasValue   bool     // Whether it was used with a value
	UsageCount int      // Number of times it appears
	Locations  []string // File:line locations (up to 5)
}

UndefinedTrait represents a trait used but not defined in schema.

type Validator

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

Validator validates documents against a schema.

func NewValidator

func NewValidator(s *schema.Schema, objectIDs []string) *Validator

NewValidator creates a new validator.

func NewValidatorWithAliases

func NewValidatorWithAliases(s *schema.Schema, objectIDs []string, aliases map[string]string) *Validator

NewValidatorWithAliases creates a new validator with alias support.

func NewValidatorWithTypes

func NewValidatorWithTypes(s *schema.Schema, objectInfos []ObjectInfo) *Validator

NewValidatorWithTypes creates a new validator with object type information. objectInfos should contain ID and type for each object in the vault.

func NewValidatorWithTypesAliasesAndResolver added in v0.0.4

func NewValidatorWithTypesAliasesAndResolver(
	s *schema.Schema,
	objectInfos []ObjectInfo,
	aliases map[string]string,
	prebuiltResolver *resolver.Resolver,
) *Validator

NewValidatorWithTypesAliasesAndResolver creates a new validator with type info, aliases, and an optional pre-built resolver.

When resolver is nil, a resolver is constructed from objectInfos and aliases. When resolver is provided, it is used as-is (for example: index.Database.Resolver).

func NewValidatorWithTypesAndAliases

func NewValidatorWithTypesAndAliases(s *schema.Schema, objectInfos []ObjectInfo, aliases map[string]string) *Validator

NewValidatorWithTypesAndAliases creates a new validator with type info and aliases.

func (*Validator) MissingRefs

func (v *Validator) MissingRefs() []*MissingRef

MissingRefs returns all missing references collected during validation.

func (*Validator) SetDailyDirectory

func (v *Validator) SetDailyDirectory(dailyDir string)

SetDailyDirectory updates the resolver's daily directory.

func (*Validator) SetDirectoryRoots

func (v *Validator) SetDirectoryRoots(objectsRoot, pagesRoot string)

SetDirectoryRoots sets the directory prefixes for typed objects and pages. When set, suggestions will strip these prefixes for cleaner display.

func (*Validator) SetDuplicateAliases

func (v *Validator) SetDuplicateAliases(duplicates []index.DuplicateAlias)

SetDuplicateAliases sets duplicate alias information for validation. This should be called before ValidateSchema to report duplicate aliases.

func (*Validator) ShortRefs

func (v *Validator) ShortRefs() map[string]string

ShortRefs returns the short refs that could be full paths.

func (*Validator) UndefinedTraits

func (v *Validator) UndefinedTraits() []*UndefinedTrait

UndefinedTraits returns all undefined traits collected during validation.

func (*Validator) ValidateDocument

func (v *Validator) ValidateDocument(doc *parser.ParsedDocument) []Issue

ValidateDocument validates a parsed document.

func (*Validator) ValidateSchema

func (v *Validator) ValidateSchema() []SchemaIssue

ValidateSchema checks the schema for integrity issues. This should be called after all documents have been validated.

Jump to

Keyboard shortcuts

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