ast

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ast defines the target-neutral semantic tree used to generate Go and Velty handlers. It contains no canonical-metadata compiler or target syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action identifies one DML decision in a write policy.

const (
	ActionInsert Action = "insert"
	ActionUpdate Action = "update"
	ActionDelete Action = "delete"
)

type ContractRef

type ContractRef struct {
	ParamIdentity string
	Path          FieldPath
	Cardinality   spec.Cardinality
}

ContractRef identifies one canonical parameter and its generated field.

type CurrentField

type CurrentField struct {
	Current    FieldRef
	Entity     FieldRef
	Conversion LinkConversion
}

CurrentField describes one typed assignment from a database current row into the entity-shaped Previous value. Dereference requires a non-nil source; consumers must not silently turn a loaded SQL NULL into a scalar zero.

type CurrentPlan

type CurrentPlan struct {
	Lookup        *LookupProjection
	ParamIdentity string
	ViewIdentity  string
	InputPath     FieldPath
	Keys          []KeyPart
	// Fields is the declared current-to-entity projection, not evidence that a
	// particular read selected these fields. PreviousFields requires read provenance.
	Fields []CurrentField
	// Self names the actual read row's self-reference holders, not entity edges.
	Self []FieldRef
}

type EntityField

type EntityField struct {
	Name             string
	Path             FieldPath
	Type             spec.TypeRef
	Identity         bool
	Relation         bool
	Self             bool
	Writable         bool
	Invariant        string
	DeleteMarker     bool
	ConcurrencyToken bool
}

EntityField describes a canonical field whose presence is owned by the mutable entity contract. Identity presence does not authorize an UPDATE SET.

type EntityPlan

type EntityPlan struct {
	Type          spec.TypeRef
	MarkerField   string
	MarkerPointer bool
	Owned         bool
	MarkerType    spec.TypeRef
	Fields        []EntityField
	Keys          []KeyPart
	Invariants    []InvariantGroup
	Hooks         spec.TypeRef
	// HooksScaffold marks an explicit unresolved local lifecycle declaration.
	HooksScaffold bool
	HooksBind     bool
	LateWrite     LateWriteEffects
}

EntityPlan carries immutable generation facts for typed setters and original presence capture. Hook invocation phases are separate handler semantics.

func (*EntityPlan) Clone

func (p *EntityPlan) Clone() *EntityPlan

type FieldPath

type FieldPath []string

FieldPath is a prevalidated generated-contract selector path.

type FieldRef

type FieldRef struct {
	Field  string
	Source string
	Type   spec.TypeRef
}

FieldRef describes a canonical scalar field without assigning key semantics.

type InvariantGroup

type InvariantGroup struct {
	Name   string
	Fields []string
}

InvariantGroup is a normalized group of business fields whose omitted values may be hydrated from the matched database projection before validation.

type KeyLink struct {
	Parent          KeyPart
	Child           KeyPart
	ParentNamespace string
	ChildNamespace  string
	Conversion      LinkConversion
}

KeyLink describes one ordered parent-to-child relation key assignment.

type KeyPart

type KeyPart struct {
	Field  string
	Source string
	Type   spec.TypeRef
}

KeyPart describes one ordered canonical record key.

type LateWriteEffects

type LateWriteEffects struct {
	Unresolved    string
	InsertHook    bool
	UpdateHook    bool
	DefaultFields []string
}

LateWriteEffects describes native row behavior executed during write flush, after generic mutation business validation has already completed.

type LinkConversion

type LinkConversion string

LinkConversion identifies the typed assignment needed for relation keys and current-to-entity field projections. Velty dereferences transparently; the Go target consumes this explicitly.

const (
	LinkDirect      LinkConversion = "direct"
	LinkAddress     LinkConversion = "address"
	LinkDereference LinkConversion = "dereference"
)

type LookupProjection

type LookupProjection struct {
	// ParentOnly projects the already scoped Previous parent, without request fallback.
	ParentOnly bool
	Name       string
	Columns    []string
}

CurrentPlan describes the ordinary input datapoint used for PATCH lookup. LookupProjection names a pure typed projection for a generated auxiliary read. The enclosing relation supplies identity and value-link semantics.

func (*LookupProjection) Clone

func (p *LookupProjection) Clone() *LookupProjection

type Operation

type Operation string

Operation identifies generated write-handler behavior.

const (
	OperationPost  Operation = "post"
	OperationPut   Operation = "put"
	OperationPatch Operation = "patch"
)

type Plan

type Plan struct {
	ReadCollections []ReadCollection
	Operation       Operation
	Input           ContractRef
	Output          *ContractRef
	Root            *RecordPlan
}

Plan is the immutable target-neutral input to handler target lowering.

func (*Plan) Clone

func (p *Plan) Clone() *Plan

Clone returns a detached semantic tree suitable for build-stage refinement.

type ReadCollection

type ReadCollection struct {
	Name      string
	InputPath FieldPath
	Type      spec.TypeRef
	Fields    []FieldRef
	Keys      []KeyPart
	// Groups are exact canonical relationship tuples prepared automatically.
	Groups []ReadGroup
}

ReadCollection describes an ordinary bound read for application lookup. It grants no write permission; CurrentPlan owns mutation matching scope.

type ReadGroup

type ReadGroup struct{ Parts []KeyPart }

ReadGroup is a typed relationship-key tuple, not an inferred naming convention.

type RecordPlan

type RecordPlan struct {
	Identity string
	// Auxiliary records remain available to business reads/indexes, but are
	// excluded from generated sequencing and mutation traversal.
	Auxiliary   bool
	InputPath   FieldPath
	Current     *CurrentPlan
	Table       string
	Cardinality spec.Cardinality
	Keys        []KeyPart
	// PresenceFields are generated-view fields whose programmatic assignments
	// must be exposed to SQLX PATCH updates through the generated Has marker.
	// Package-linked record authority leaves this empty.
	PresenceFields []string
	Entity         *EntityPlan
	Sequence       *SequencePlan
	Write          WritePolicy
	Relations      []*RelationPlan
	SelfRelations  []SelfRelationPlan
}

RecordPlan describes one canonical record write and its ordered children.

func (*RecordPlan) IdentityKeys

func (r *RecordPlan) IdentityKeys() []KeyPart

IdentityKeys returns the final entity identity when refined, otherwise the source-view identity. Callers must treat the returned metadata as immutable.

func (*RecordPlan) TracksPresence

func (r *RecordPlan) TracksPresence(field string) bool

TracksPresence reports whether generated business logic owns the presence bit for field. The slice keeps the semantic plan deterministic and portable across target lowerers.

type RelationPlan

type RelationPlan struct {
	// AllowReparent is explicit permission to change non-identity parent links.
	AllowReparent bool
	Identity      string
	FieldPath     FieldPath
	Cardinality   spec.Cardinality
	Links         []KeyLink
	Child         *RecordPlan
}

RelationPlan describes one typed child traversal from a parent record.

func (*RelationPlan) WriteHookName

func (r *RelationPlan) WriteHookName() (string, error)

WriteHookName is the canonical optional typed relation hook name used by both generated targets.

type SelfRelationPlan

type SelfRelationPlan struct {
	AllowReparent bool
	FieldPath     FieldPath
	Links         []KeyLink
}

SelfRelationPlan describes holder-specific linking within the same row type. It has no child plan: the existing record role owns recursive traversal.

type SequencePlan

type SequencePlan struct {
	Destination FieldPath
	Selector    FieldPath
	// Field is the canonical local row field, independent of root traversal syntax.
	Field FieldRef
}

SequencePlan describes identifier allocation through the injected sequencer.

type WritePolicy

type WritePolicy struct {
	DeleteMarker     FieldRef
	ConcurrencyToken FieldRef
	ValuePath        FieldPath
	Existing         Action
	Missing          Action
	Allowed          []Action
	Order            int
}

WritePolicy makes every root DML decision explicit for target lowering.

Jump to

Keyboard shortcuts

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