validator

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package validator is the GQL semantic validator (SPEC-04 §5, §7).

M7 (landed): the field registry derived from the search_index union view (migration 0003) with dotted canonical paths and user-facing aliases (title→http.title, country→geo_country, status→http.status, server→http.server, tech→technologies, …), alias rewrite to canonical paths in place, strict typing (port=="443" → GQL_E_TYPE with the unquoted rewrite; timestamps RFC 3339; booleans "true"/"false"; IN lists type-check element-wise), operator/field compatibility via ast.OpSet (IN_CIDR only on ip, CONTAINS on text/list fields, range ops on ordered fields), quantifier scope validation (host|service), and the v0.0.1 feature gate: ALL(...) → GQL_E_NOT_SUPPORTED_IN_VERSION with the ANY rewrite suggestion. Unknown fields fail with GQL_E_FIELD and a did-you-mean hint over the registry names (edit distance < 3).

The registry table in validator.go is the single reconciliation point if SPEC-04 §7's normative field list differs from the in-repo derivation.

Consumes internal/gql/ast; the planner (M9) consumes the validated, canonically-rewritten tree. Never imports any collector or egress package (ADR-0010; AC-3.1).

Package validator is the GQL semantic validator (SPEC-04 §5, §7).

M7 (landed): the field registry over the search_index contract (migration 0003 defines the planneable columns — the registry is derived from that schema, with dotted canonical paths and the user-facing aliases), alias rewrite to canonical paths in place, strict typing (an INT field rejecting a quoted value with a concrete hint), operator/field compatibility (IN_CIDR only on ip, IN lists on listable fields, range ops only on ordered fields), scope/binding validation for quantified blocks, the v0.0.1 feature gate (ALL → GQL_E_NOT_SUPPORTED_IN_VERSION with the !ANY suggestion), and the error codes GQL_E_FIELD (unknown field + did-you-mean), GQL_E_TYPE, GQL_E_OP, GQL_E_SCOPE, GQL_E_UNSUPPORTED.

The exact registry membership is the search_index column set plus its aliases; if SPEC-04 §7's normative 37-entry list differs, the registry table below is the single point to reconcile.

The validator never imports any collector, egress, or P2 package (ADR-0010; AC-3.1).

Index

Constants

View Source
const (
	CodeField       = "GQL_E_FIELD"                    // unknown field
	CodeType        = "GQL_E_TYPE"                     // strict-typing violation
	CodeOp          = "GQL_E_OP"                       // operator not valid for the field
	CodeScope       = "GQL_E_SCOPE"                    // unknown quantifier scope
	CodeUnsupported = "GQL_E_NOT_SUPPORTED_IN_VERSION" // parses, rejected in v0.0.1
)

Stable GQL semantic error codes (SPEC-04 §5).

Variables

This section is empty.

Functions

func FieldNames

func FieldNames() []string

FieldNames returns the registry's user-facing names (canonical paths plus aliases), sorted — used by did-you-mean and by help surfaces.

func Validate

func Validate(n ast.Node) (ast.Node, error)

Validate walks the tree, rewriting field aliases to canonical paths in place and enforcing the semantic contract. It returns the SAME tree (rewritten) on success. The first semantic error aborts.

Types

type Error

type Error struct {
	Code   string // one of the GQL_E_* constants above
	Detail string // what failed, including "line L, column C"
	Why    string // likely why
	Next   string // concrete Try: hint
	Line   int    // 1-based line
	Col    int    // 1-based (rune) column
}

Error is a GQL semantic validation error with its source position.

func (*Error) Error

func (e *Error) Error() string

Error renders per the SPEC-03 §7 style guide.

type Field

type Field struct {
	Canonical string    // dotted canonical path (planner target)
	Aliases   []string  // user-facing spellings (lowercase)
	Type      FieldType // value grammar
	Ops       ast.OpSet // operators this field accepts
}

Field is one registry entry.

type FieldType

type FieldType int

FieldType classifies a registry field for strict typing.

const (
	TypeString FieldType = iota // string values ("…"); no ranges
	TypeInt                     // integer values; ranges allowed
	TypeTime                    // RFC 3339 string values; ranges allowed
	TypeBool                    // "true"/"false" string values
	TypeList                    // text[] columns: CONTAINS matches elements
)

Field types (the value grammar each field accepts).

func (FieldType) String

func (t FieldType) String() string

String renders the type name for error messages.

Jump to

Keyboard shortcuts

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