validator

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 6 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 with one compat-mode coercion (a quoted integer on an INT field parses in place; anything else is rejected 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

View Source
var FreeTextFields = []string{
	"asset_value",
	"hostname",
	"domain",
	"http.title",
	"http.server",
	"product",
	"name",
	"asn_org",
	"tls.cert_subject_cn",
	"tls.cert_issuer_cn",
}

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. FreeTextFields is the fixed field list the bare-keyword form ("wordpress") searches: the stored TEXT surfaces of the index that answer the question "where does this word appear?" - identity, HTTP metadata, product/name, organization and certificate names. Deliberately EXCLUDED: body/header/icon/js content (GSEER is Search-not-Scan: it indexes facts, not fetched page content) and ip (exact-value semantics; use ip *= "10.0.0.*" for patterns).

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)

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

	// RewriteTo/RewriteOp implement the compatibility rewrites
	// (after/before/cert.not_after.*): the comparison is re-targeted to
	// the canonical field with the direction-carrying operator before
	// planning.  An empty RewriteTo is a normal registry entry.
	RewriteTo string
	RewriteOp ast.Op
}

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
	TypeDate                    // date ("2006-01-02") or RFC 3339; ranges allowed
)

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