datavalidator

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectionForRecordFile added in v1.29.0

func CollectionForRecordFile(def *ingitdb.Definition, absPath string) (string, *ingitdb.CollectionDef)

CollectionForRecordFile returns the collection (and its ID) that owns absPath as a record file, or ("", nil) when no collection's record-file layout matches. It mirrors how the full validator enumerates record files, so the incremental validator, change-set resolver, and `diff` all agree on which files are records.

func ValidateRecordData added in v1.24.2

func ValidateRecordData(colDef *ingitdb.CollectionDef, recordKey string, data map[string]any) []ingitdb.ValidationError

ValidateRecordData validates a single in-memory record's field values against the collection's schema: declared column types, required fields, and the rule that computed-column values must not be stored. It returns the schema violations found (empty when the record is valid). Use it to check records that are not yet persisted to a file, e.g. an auto-merge result before it is staged.

Types

type AffectedRecord

type AffectedRecord struct {
	CollectionID string
	FilePath     string
	RecordKey    string // empty if entire file changed (list/map format)
	ChangeKind   ingitdb.ChangeKind
}

AffectedRecord identifies which record was touched by a file change.

type ChangeSetResolver

type ChangeSetResolver interface {
	Resolve(dbPath string, def *ingitdb.Definition, changedFiles []ingitdb.ChangedFile) ([]AffectedRecord, error)
}

ChangeSetResolver maps changed files → (collectionID, recordKey) pairs. Handles all three RecordType layouts.

func NewChangeSetResolver added in v1.25.0

func NewChangeSetResolver() ChangeSetResolver

NewChangeSetResolver returns the default ChangeSetResolver, which maps changed files to the collection records they belong to. It assumes the database directory is the git repository root (changed-file paths are joined onto it).

type DataValidator

type DataValidator interface {
	Validate(ctx context.Context, dbPath string, def *ingitdb.Definition) (*ingitdb.ValidationResult, error)
}

DataValidator runs a full validation pass over all records.

func NewValidator added in v0.29.0

func NewValidator() DataValidator

NewValidator creates a data validator that parses records and checks basic schema constraints.

type ForeignKeyIndex

type ForeignKeyIndex interface {
	Contains(collectionID, key string) bool
}

ForeignKeyIndex is a pre-built read-only lookup for FK validation. Built once before validation begins; shared read-only across goroutines.

type IncrementalValidator

type IncrementalValidator interface {
	ValidateChanges(
		ctx context.Context,
		dbPath string,
		def *ingitdb.Definition,
		fromCommit, toCommit string,
	) (*ingitdb.ValidationResult, error)
}

IncrementalValidator validates only records changed between two git refs.

func NewIncrementalValidator added in v1.25.0

func NewIncrementalValidator(differ gitdiff.GitDiffer, resolver ChangeSetResolver, full DataValidator) IncrementalValidator

NewIncrementalValidator returns an IncrementalValidator that validates only the records whose files changed between two git refs. differ lists changed files, resolver maps them to collection records, and full is used as a fall-back when a definition file changed (the schema itself moved).

type RecordValidator

type RecordValidator interface {
	ValidateRecord(
		col *ingitdb.CollectionDef,
		entry ingitdb.IRecordEntry,
		result *ingitdb.ValidationResult,
	) int
}

RecordValidator validates one record against its collection schema. Goroutine-safe. Appends findings to result; returns count of errors appended.

Jump to

Keyboard shortcuts

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