schema

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package schema provides the public API for loading and querying YAMMM schemas.

Overview

This package implements the schema layer, which is responsible for:

  • Loading and parsing schema definitions from *.yammm files
  • Building schemas programmatically using the Builder API
  • Providing an immutable, thread-safe schema representation
  • Supporting cross-schema imports and inheritance

Loading Schemas

Schemas are loaded using the schema/load package:

// Load from file
s, result, err := load.Load(ctx, "schema.yammm")

// Load from string
s, result, err := load.LoadString(ctx, source, "schema.yammm")

// Load from multiple sources
s, result, err := load.LoadSources(ctx, sources, moduleRoot)

The triple-return pattern ensures diagnostics are always available via diag.Result, while err signals catastrophic failures (I/O, cancellation). Check result.HasErrors() to determine semantic success.

Immutability

All schema types are immutable after loading. This provides:

  • Thread-safety for concurrent access
  • Predictable behavior (no hidden mutations)
  • Safe sharing across goroutines

Slice accessors return defensive copies. Use iterators (iter.Seq) for zero-allocation traversal when possible.

Completion and Sealing

Schemas undergo a completion phase that resolves all internal references:

  • Import declarations are resolved to their target schemas
  • Type inheritance is computed (LinearizedAncestors)
  • Property collisions are detected across the inheritance hierarchy
  • Alias constraints are resolved to their underlying types

After completion, schemas are sealed to prevent further mutation. The schema/load package handles completion automatically. The schema/build package completes the schema when Build() is called. All types and constraints are immutable and thread-safe after sealing.

Type Identity

Types are identified by TypeID, a tuple of (SourceID, name). This enables cross-schema type resolution and proper handling of imported types. Two types are equal if and only if they have the same TypeID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AliasConstraint

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

AliasConstraint represents a reference to a named DataType. The underlying constraint is resolved for equality comparisons.

func NewAliasConstraint

func NewAliasConstraint(dataTypeName string, resolved Constraint) AliasConstraint

NewAliasConstraint creates an AliasConstraint referencing a DataType.

func (AliasConstraint) DataTypeName

func (c AliasConstraint) DataTypeName() string

DataTypeName returns the name of the referenced DataType.

func (AliasConstraint) Equal

func (c AliasConstraint) Equal(other Constraint) bool

Equal compares the resolved underlying constraints, not the alias names. This enables inheritance deduplication with different alias names but same constraint. For unresolved aliases, compares by datatype name.

This method is cycle-safe: it uses resolveAlias() to unwrap alias chains before delegating to the terminal constraint's Equal method.

func (AliasConstraint) IsResolved

func (c AliasConstraint) IsResolved() bool

IsResolved reports whether the alias has been fully resolved to a terminal constraint.

After successful schema completion, IsResolved() is guaranteed to return true for all constraints. An unresolved alias (IsResolved() == false) indicates either:

  • Pre-completion state during schema loading
  • A schema completion failure (alias target not found)

Instance validation should only operate on fully completed schemas where IsResolved() is always true. Encountering an unresolved constraint during evaluation indicates a schema error.

For alias chains (alias-of-alias), this method uses resolveAlias to unwrap the chain with cycle detection before checking the terminal constraint.

func (AliasConstraint) Kind

func (AliasConstraint) NarrowsTo added in v0.1.2

func (c AliasConstraint) NarrowsTo(child Constraint) bool

NarrowsTo delegates to the resolved underlying constraint's NarrowsTo method. For unresolved aliases, returns false (cannot determine narrowing without resolution).

This method is cycle-safe: it uses resolveAlias() to unwrap alias chains before delegating to the terminal constraint's NarrowsTo method.

func (AliasConstraint) Resolved

func (c AliasConstraint) Resolved() Constraint

Resolved returns the underlying resolved constraint.

func (AliasConstraint) String

func (c AliasConstraint) String() string

type BooleanConstraint

type BooleanConstraint struct{}

BooleanConstraint constrains boolean values. It has no parameters.

func NewBooleanConstraint

func NewBooleanConstraint() BooleanConstraint

NewBooleanConstraint creates a BooleanConstraint.

func (BooleanConstraint) Equal

func (c BooleanConstraint) Equal(other Constraint) bool

func (BooleanConstraint) IsResolved

func (BooleanConstraint) IsResolved() bool

func (BooleanConstraint) Kind

func (BooleanConstraint) NarrowsTo added in v0.1.2

func (c BooleanConstraint) NarrowsTo(child Constraint) bool

func (BooleanConstraint) String

func (BooleanConstraint) String() string

type Constraint

type Constraint interface {
	// Kind returns the constraint kind.
	Kind() ConstraintKind

	// String returns a human-readable representation.
	String() string

	// Equal reports whether two constraints are structurally equal.
	// For AliasConstraint, compares the resolved underlying constraint.
	Equal(other Constraint) bool

	// NarrowsTo reports whether the child constraint is a valid narrowing of
	// this (parent) constraint. Returns true when every value accepted by child
	// would also be accepted by this constraint (child's valid set is a subset
	// of parent's valid set).
	//
	// For bounds-based constraints (String, Integer, Float): child min >= parent min
	// and child max <= parent max.
	// For EnumConstraint: child values must be a subset of parent values.
	// For parameterless or non-narrowable constraints (Boolean, Date, UUID,
	// Timestamp, Pattern, Vector): delegates to Equal (no narrowing supported).
	// For AliasConstraint: resolves alias chain first, then delegates.
	NarrowsTo(child Constraint) bool

	// IsResolved reports whether the constraint references are fully resolved.
	// This method is primarily meaningful for AliasConstraint, which starts
	// unresolved (referencing a DataType by name) and becomes resolved during
	// schema completion when the underlying constraint is wired.
	// All other constraint types always return true (they have no deferred
	// references to resolve).
	IsResolved() bool
	// contains filtered or unexported methods
}

Constraint represents a type constraint for a property value. All constraints are immutable after construction.

type ConstraintKind

type ConstraintKind uint8

ConstraintKind identifies the kind of constraint.

const (
	KindString ConstraintKind = iota
	KindInteger
	KindFloat
	KindBoolean
	KindTimestamp
	KindDate
	KindUUID
	KindEnum
	KindPattern
	KindVector
	KindList  // ordered collection with element constraint
	KindAlias // reference to DataType
)

func (ConstraintKind) String

func (k ConstraintKind) String() string

String returns the name of the constraint kind.

type DataType

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

DataType represents a named data type alias in a schema. Data types provide reusable constraint definitions that can be referenced by name in property declarations.

func NewDataType

func NewDataType(name string, constraint Constraint, span location.Span, doc string) *DataType

NewDataType creates a new DataType.

This is a low-level API primarily for:

  • Internal use during schema parsing
  • Advanced use cases like building schemas programmatically via Builder

Most users should load schemas from .yammm files using the load package.

func (*DataType) Constraint

func (d *DataType) Constraint() Constraint

Constraint returns the constraint this data type defines.

func (*DataType) Documentation

func (d *DataType) Documentation() string

Documentation returns the documentation comment, if any.

func (*DataType) IsSealed

func (d *DataType) IsSealed() bool

IsSealed reports whether the data type has been sealed.

func (*DataType) Name

func (d *DataType) Name() string

Name returns the data type name.

func (*DataType) Seal

func (d *DataType) Seal()

Seal marks the data type as immutable. Called by the loader after schema completion. This is not part of the public API and may be removed in future versions.

func (*DataType) SetConstraint

func (d *DataType) SetConstraint(c Constraint)

SetConstraint sets the constraint (called during alias resolution). Internal use only; called during schema completion. Panics if called after Seal().

func (*DataType) Span

func (d *DataType) Span() location.Span

Span returns the source location of this data type declaration.

type DataTypeRef

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

DataTypeRef is a syntactic reference to a data type alias, similar to TypeRef. It captures the optional import qualifier and data type name.

func LocalDataTypeRef

func LocalDataTypeRef(name string, span location.Span) DataTypeRef

LocalDataTypeRef creates a DataTypeRef for a local (unqualified) data type.

func NewDataTypeRef

func NewDataTypeRef(qualifier, name string, span location.Span) DataTypeRef

NewDataTypeRef creates a DataTypeRef with the given qualifier, name, and span.

func (DataTypeRef) IsQualified

func (r DataTypeRef) IsQualified() bool

IsQualified reports whether this is a qualified (imported) data type reference.

func (DataTypeRef) IsZero

func (r DataTypeRef) IsZero() bool

IsZero reports whether this is the zero value.

func (DataTypeRef) Name

func (r DataTypeRef) Name() string

Name returns the data type name.

func (DataTypeRef) Qualifier

func (r DataTypeRef) Qualifier() string

Qualifier returns the import alias, or empty string for local data types.

func (DataTypeRef) Span

func (r DataTypeRef) Span() location.Span

Span returns the source location of this data type reference.

func (DataTypeRef) String

func (r DataTypeRef) String() string

String returns the fully qualified name (e.g., "common.Money" or "Money").

type DateConstraint

type DateConstraint struct{}

DateConstraint constrains date values. It has no parameters.

func NewDateConstraint

func NewDateConstraint() DateConstraint

NewDateConstraint creates a DateConstraint.

func (DateConstraint) Equal

func (c DateConstraint) Equal(other Constraint) bool

func (DateConstraint) IsResolved

func (DateConstraint) IsResolved() bool

func (DateConstraint) Kind

func (DateConstraint) NarrowsTo added in v0.1.2

func (c DateConstraint) NarrowsTo(child Constraint) bool

func (DateConstraint) String

func (DateConstraint) String() string

type DeclaringScope

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

DeclaringScope identifies where a property was declared. For inherited properties, this identifies the original declaring ancestor.

func RelationScope

func RelationScope(relationName string) DeclaringScope

RelationScope creates a DeclaringScope for an edge property on a relation.

func TypeScope

func TypeScope(typeRef TypeRef) DeclaringScope

TypeScope creates a DeclaringScope for a property declared in a type body.

func (DeclaringScope) IsRelation

func (s DeclaringScope) IsRelation() bool

IsRelation reports whether this is a relation edge property.

func (DeclaringScope) IsType

func (s DeclaringScope) IsType() bool

IsType reports whether this is a type-declared property.

func (DeclaringScope) Kind

Kind returns the scope kind.

func (DeclaringScope) RelationName

func (s DeclaringScope) RelationName() string

RelationName returns the relation name for ScopeRelation declarations. Returns empty string for ScopeType.

func (DeclaringScope) String

func (s DeclaringScope) String() string

String returns a human-readable representation. Returns "unknown" for zero-value DeclaringScope.

func (DeclaringScope) TypeName

func (s DeclaringScope) TypeName() string

TypeName returns the type name for ScopeType declarations. Panics if Kind() != ScopeType.

func (DeclaringScope) TypeRef

func (s DeclaringScope) TypeRef() TypeRef

TypeRef returns the type reference for ScopeType declarations. Returns zero value for ScopeRelation.

type DeclaringScopeKind

type DeclaringScopeKind uint8

DeclaringScopeKind identifies where a property was declared.

const (
	// ScopeType indicates the property was declared in a type body.
	ScopeType DeclaringScopeKind = iota
	// ScopeRelation indicates the property was declared on a relation edge.
	ScopeRelation
)

func (DeclaringScopeKind) String

func (k DeclaringScopeKind) String() string

String returns a human-readable name for the scope kind.

type EnumConstraint

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

EnumConstraint constrains string values to a fixed set of allowed values.

func NewEnumConstraint

func NewEnumConstraint(values []string) EnumConstraint

NewEnumConstraint creates an EnumConstraint with the given allowed values. The values are stored in a defensive copy.

func (EnumConstraint) Equal

func (c EnumConstraint) Equal(other Constraint) bool

Equal compares using set equality (order-insensitive).

func (EnumConstraint) IsResolved

func (EnumConstraint) IsResolved() bool

func (EnumConstraint) Kind

func (EnumConstraint) NarrowsTo added in v0.1.2

func (c EnumConstraint) NarrowsTo(child Constraint) bool

func (EnumConstraint) String

func (c EnumConstraint) String() string

func (EnumConstraint) Values

func (c EnumConstraint) Values() []string

Values returns a defensive copy of the allowed enum values.

type FloatConstraint

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

FloatConstraint constrains float values with optional min/max bounds.

func NewFloatConstraint

func NewFloatConstraint() FloatConstraint

NewFloatConstraint creates a FloatConstraint with no bounds.

func NewFloatConstraintBounded

func NewFloatConstraintBounded(min float64, hasMin bool, max float64, hasMax bool) FloatConstraint

NewFloatConstraintBounded creates a FloatConstraint with the given bounds. Use hasMin=false or hasMax=false to indicate no bound.

func (FloatConstraint) Equal

func (c FloatConstraint) Equal(other Constraint) bool

func (FloatConstraint) IsResolved

func (FloatConstraint) IsResolved() bool

func (FloatConstraint) Kind

func (FloatConstraint) Max

func (c FloatConstraint) Max() (float64, bool)

func (FloatConstraint) Min

func (c FloatConstraint) Min() (float64, bool)

func (FloatConstraint) NarrowsTo added in v0.1.2

func (c FloatConstraint) NarrowsTo(child Constraint) bool

func (FloatConstraint) String

func (c FloatConstraint) String() string

type Import

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

Import represents an import declaration in a schema. Imports allow referencing types from other schema files.

func NewImport

func NewImport(path, alias string, resolvedSourceID location.SourceID, span location.Span) *Import

NewImport creates a new Import. This is primarily for internal use; imports are typically created during schema parsing.

func (*Import) Alias

func (i *Import) Alias() string

Alias returns the import alias used for qualification.

func (*Import) IsSealed

func (i *Import) IsSealed() bool

IsSealed reports whether the import has been sealed.

func (*Import) Path

func (i *Import) Path() string

Path returns the import path as written in the schema.

func (*Import) ResolvedPath

func (i *Import) ResolvedPath() string

ResolvedPath returns the resolved path as a string. Returns empty string if not yet resolved.

func (*Import) ResolvedSourceID

func (i *Import) ResolvedSourceID() location.SourceID

ResolvedSourceID returns the resolved canonical source identity.

func (*Import) Schema

func (i *Import) Schema() *Schema

Schema returns the resolved schema, if available. Returns nil if the schema has not been loaded yet.

func (*Import) Seal

func (i *Import) Seal()

Seal prevents further mutation of the import. Called during loading after resolution is complete.

func (*Import) SetResolvedSourceID

func (i *Import) SetResolvedSourceID(id location.SourceID)

SetResolvedSourceID sets the resolved source identity (called during loading). Panics if called after Seal().

func (*Import) SetSchema

func (i *Import) SetSchema(s *Schema)

SetSchema sets the resolved schema (called during loading). Panics if called after Seal().

func (*Import) Span

func (i *Import) Span() location.Span

Span returns the source location of this import declaration.

type IntegerConstraint

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

IntegerConstraint constrains integer values with optional min/max bounds.

func NewIntegerConstraint

func NewIntegerConstraint() IntegerConstraint

NewIntegerConstraint creates an IntegerConstraint with no bounds.

func NewIntegerConstraintBounded

func NewIntegerConstraintBounded(min int64, hasMin bool, max int64, hasMax bool) IntegerConstraint

NewIntegerConstraintBounded creates an IntegerConstraint with the given bounds. Use hasMin=false or hasMax=false to indicate no bound.

func (IntegerConstraint) Equal

func (c IntegerConstraint) Equal(other Constraint) bool

func (IntegerConstraint) IsResolved

func (IntegerConstraint) IsResolved() bool

func (IntegerConstraint) Kind

func (IntegerConstraint) Max

func (c IntegerConstraint) Max() (int64, bool)

func (IntegerConstraint) Min

func (c IntegerConstraint) Min() (int64, bool)

func (IntegerConstraint) NarrowsTo added in v0.1.2

func (c IntegerConstraint) NarrowsTo(child Constraint) bool

func (IntegerConstraint) String

func (c IntegerConstraint) String() string

type Invariant

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

Invariant represents a constraint expression attached to a type. Invariants are validated at runtime; the expression is compiled at schema load time and evaluated at instance validation time.

func NewInvariant

func NewInvariant(name string, e expr.Expression, span location.Span, doc string) *Invariant

NewInvariant creates a new Invariant.

This is a low-level API primarily for:

  • Internal use during schema parsing
  • Advanced use cases like building schemas programmatically via Builder

Most users should load schemas from .yammm files using the load package.

func (*Invariant) Documentation

func (i *Invariant) Documentation() string

Documentation returns the documentation comment, if any.

func (*Invariant) Expression

func (i *Invariant) Expression() expr.Expression

Expression returns the compiled expression for this invariant.

func (*Invariant) Name

func (i *Invariant) Name() string

Name returns the user-facing message for this invariant. This is displayed when the invariant evaluates to false.

func (*Invariant) Span

func (i *Invariant) Span() location.Span

Span returns the source location of this invariant declaration.

type ListConstraint added in v0.1.2

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

ListConstraint constrains list values with an element type and optional min/max length.

func NewListConstraint added in v0.1.2

func NewListConstraint(element Constraint) ListConstraint

NewListConstraint creates a ListConstraint with no length bounds.

func NewListConstraintBounded added in v0.1.2

func NewListConstraintBounded(element Constraint, minLen, maxLen int64) ListConstraint

NewListConstraintBounded creates a ListConstraint with the given length bounds. Pass -1 for minLen or maxLen to indicate no bound.

func (ListConstraint) Element added in v0.1.2

func (c ListConstraint) Element() Constraint

Element returns the element constraint.

func (ListConstraint) Equal added in v0.1.2

func (c ListConstraint) Equal(other Constraint) bool

func (ListConstraint) IsResolved added in v0.1.2

func (c ListConstraint) IsResolved() bool

func (ListConstraint) Kind added in v0.1.2

func (ListConstraint) MaxLen added in v0.1.2

func (c ListConstraint) MaxLen() (int64, bool)

MaxLen returns the maximum list length and whether a maximum is set.

func (ListConstraint) MinLen added in v0.1.2

func (c ListConstraint) MinLen() (int64, bool)

MinLen returns the minimum list length and whether a minimum is set.

func (ListConstraint) NarrowsTo added in v0.1.2

func (c ListConstraint) NarrowsTo(child Constraint) bool

func (ListConstraint) String added in v0.1.2

func (c ListConstraint) String() string

type LookupStatus

type LookupStatus uint8

LookupStatus indicates the result of a registry lookup.

const (
	// LookupNotFound indicates the item was not found.
	LookupNotFound LookupStatus = iota
	// LookupFound indicates the item was found.
	LookupFound
)

func (LookupStatus) Found

func (s LookupStatus) Found() bool

Found reports whether the lookup succeeded.

type PatternConstraint

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

PatternConstraint constrains string values to match one or more regex patterns. All patterns must match (conjunction semantics). Maximum 2 patterns for performance.

func NewPatternConstraint

func NewPatternConstraint(patterns []*regexp.Regexp) PatternConstraint

NewPatternConstraint creates a PatternConstraint from compiled patterns. Maximum 2 patterns are allowed; extras are silently ignored.

func (PatternConstraint) CompiledPatterns

func (c PatternConstraint) CompiledPatterns() []*regexp.Regexp

CompiledPatterns returns the compiled regex patterns for internal validation use. This method is for internal use by the validation layer (checkers.go). External consumers should use Patterns() which returns strings per the public API spec.

func (PatternConstraint) Equal

func (c PatternConstraint) Equal(other Constraint) bool

Equal compares using order-insensitive pattern string comparison.

func (PatternConstraint) IsResolved

func (PatternConstraint) IsResolved() bool

func (PatternConstraint) Kind

func (PatternConstraint) NarrowsTo added in v0.1.2

func (c PatternConstraint) NarrowsTo(child Constraint) bool

func (PatternConstraint) Pattern

func (c PatternConstraint) Pattern() string

Pattern returns the first (primary) regex pattern. Returns empty string if no patterns exist. For constraints with two patterns, use Patterns() instead.

func (PatternConstraint) PatternCount

func (c PatternConstraint) PatternCount() int

PatternCount returns the number of patterns.

func (PatternConstraint) Patterns

func (c PatternConstraint) Patterns() []string

Patterns returns the regex pattern strings. Returns a defensive copy.

func (PatternConstraint) String

func (c PatternConstraint) String() string

type Property

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

Property represents a property definition on a type. Properties are immutable after schema completion.

func NewProperty

func NewProperty(
	name string,
	span location.Span,
	doc string,
	constraint Constraint,
	dataTypeRef DataTypeRef,
	optional bool,
	isPrimaryKey bool,
	scope DeclaringScope,
) *Property

NewProperty creates a new Property.

This is a low-level API primarily for:

  • Internal use during schema parsing and completion
  • Advanced use cases like building schemas programmatically via Builder

Most users should load schemas from .yammm files using the load package.

The dataTypeRef parameter captures the syntactic reference (with span) when the constraint is an alias to a named DataType. Pass zero-value DataTypeRef for built-in constraints. This enables LSP navigation to DataType definitions.

func (*Property) CanNarrowFrom added in v0.1.2

func (p *Property) CanNarrowFrom(parent *Property) bool

CanNarrowFrom reports whether this (child) property is a valid narrowing of the parent property. A child narrows its parent when:

  • Names match (case-sensitive)
  • PK status is identical (structural, cannot change)
  • Optionality narrows: optional->required is allowed, required->optional is NOT
  • Constraint narrows: child's valid set is a subset of parent's (via NarrowsTo)

Both nil returns true (nil == nil). One nil returns false.

func (*Property) Constraint

func (p *Property) Constraint() Constraint

Constraint returns the typed constraint for this property.

func (*Property) DataTypeRef

func (p *Property) DataTypeRef() DataTypeRef

DataTypeRef returns the syntactic reference to a DataType, if any. Returns a zero-value DataTypeRef for built-in constraints (String, Integer, etc.). Use IsZero() to check if this property references a named DataType.

func (*Property) DeclaringScope

func (p *Property) DeclaringScope() DeclaringScope

DeclaringScope returns where this property was declared. For inherited properties, returns the original declaring ancestor.

func (*Property) Documentation

func (p *Property) Documentation() string

Documentation returns the documentation comment, if any.

func (*Property) Equal

func (p *Property) Equal(other *Property) bool

Equal reports whether two properties are structurally equal. Compares: name (case-sensitive), optionality, PK status, constraint. NOT compared: span, docs, scope. Scope is excluded because properties inherited from different ancestors should be considered equal for deduplication purposes during type completion—two ancestors may define identical properties, and we want to merge them rather than flag a conflict.

func (*Property) IsOptional

func (p *Property) IsOptional() bool

IsOptional reports whether this property is optional.

func (*Property) IsPrimaryKey

func (p *Property) IsPrimaryKey() bool

IsPrimaryKey reports whether this property is a primary key. Primary key properties are implicitly required.

func (*Property) IsRequired

func (p *Property) IsRequired() bool

IsRequired reports whether this property is required (not optional).

func (*Property) Name

func (p *Property) Name() string

Name returns the property name.

func (*Property) SetConstraint

func (p *Property) SetConstraint(c Constraint)

SetConstraint sets the constraint (called during alias resolution). Internal use only; called during schema completion.

func (*Property) Span

func (p *Property) Span() location.Span

Span returns the source location of this property declaration.

type Registry

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

Registry is a thread-safe registry of compiled schemas.

The registry is append-only by design: once a schema is registered, it cannot be removed. This simplifies concurrency guarantees and ensures stable TypeID lookups. For hot-reload or LSP scenarios requiring schema replacement, create a new Registry or use Clone() to create an isolated snapshot.

The registry provides O(1) lookup by SourceID and schema name. It is safe for concurrent use by multiple goroutines.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty Registry.

func (*Registry) All

func (r *Registry) All() []*Schema

All returns all registered schemas in deterministic order (sorted by SourceID). The returned slice is a copy; modifications do not affect the registry.

func (*Registry) Clone

func (r *Registry) Clone() *Registry

Clone creates a shallow copy of the registry. The clone shares the same Schema pointers but has independent maps. This is useful for creating isolated registry views without affecting the original.

func (*Registry) Contains

func (r *Registry) Contains(id location.SourceID) bool

Contains reports whether a schema with the given source ID is registered.

func (*Registry) Len

func (r *Registry) Len() int

Len returns the number of registered schemas.

func (*Registry) LookupByName

func (r *Registry) LookupByName(name string) (*Schema, LookupStatus)

LookupByName returns the schema with the given name.

func (*Registry) LookupBySourceID

func (r *Registry) LookupBySourceID(id location.SourceID) (*Schema, LookupStatus)

LookupBySourceID returns the schema with the given source ID.

func (*Registry) LookupSchema

func (r *Registry) LookupSchema(id TypeID) (*Schema, LookupStatus)

LookupSchema returns the schema containing the type with the given TypeID.

func (*Registry) LookupType

func (r *Registry) LookupType(id TypeID) (*Type, LookupStatus)

LookupType returns the type with the given TypeID. This provides O(1) cross-schema type lookup.

func (*Registry) Register

func (r *Registry) Register(s *Schema) error

Register adds a schema to the registry. Returns an error if the schema has a zero SourceID, empty name, or if a schema with the same SourceID or name is already registered.

type RegistryError

type RegistryError struct {
	Kind    RegistryErrorKind
	Message string
}

RegistryError represents an error from registry operations.

func (*RegistryError) Error

func (e *RegistryError) Error() string

Error implements the error interface.

type RegistryErrorKind

type RegistryErrorKind uint8

RegistryErrorKind identifies the type of registry error.

const (
	// DuplicateSourceID indicates a schema with the same SourceID is already registered.
	DuplicateSourceID RegistryErrorKind = iota
	// DuplicateName indicates a schema with the same name is already registered.
	DuplicateName
	// InvalidSourceID indicates a schema has an invalid (e.g., zero) SourceID.
	InvalidSourceID
	// InvalidName indicates a schema has an invalid (e.g., empty) name.
	InvalidName
)

func (RegistryErrorKind) String

func (k RegistryErrorKind) String() string

String returns a human-readable name for the error kind.

type Relation

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

Relation represents a relationship between types. Relations are immutable after schema completion.

func NewRelation

func NewRelation(
	kind RelationKind,
	name string,
	fieldName string,
	target TypeRef,
	targetID TypeID,
	span location.Span,
	doc string,
	optional, many bool,
	backref string,
	reverseOptional, reverseMany bool,
	owner string,
	properties []*Property,
) *Relation

NewRelation creates a new Relation. This is primarily for internal use; relations are typically created during schema parsing and completion.

func (*Relation) Backref

func (r *Relation) Backref() string

Backref returns the reverse relationship name, if any.

func (*Relation) Documentation

func (r *Relation) Documentation() string

Documentation returns the documentation comment, if any.

func (*Relation) Equal

func (r *Relation) Equal(other *Relation) bool

Equal reports whether two relations are structurally equal. Compares: name, kind, target TypeID (or syntactic target if unresolved), multiplicities, backref, reverse multiplicity, edge properties. NOT compared: span, docs (declaration site-specific). Edge properties are compared by name set (order-independent). Enables deduplication of identical relations from distinct ancestors.

func (*Relation) FieldName

func (r *Relation) FieldName() string

FieldName returns the normalized field name used in instance data. This is lower_snake(Name()), e.g., "WORKS_AT" → "works_at". Cached at schema completion for performance.

func (*Relation) HasProperties

func (r *Relation) HasProperties() bool

HasProperties reports whether this relation has edge properties. Always false for compositions; may be true for associations.

func (*Relation) IsAssociation

func (r *Relation) IsAssociation() bool

IsAssociation reports whether this relation is an association.

func (*Relation) IsComposition

func (r *Relation) IsComposition() bool

IsComposition reports whether this relation is a composition.

func (*Relation) IsMany

func (r *Relation) IsMany() bool

IsMany reports whether the forward direction allows many targets.

func (*Relation) IsOptional

func (r *Relation) IsOptional() bool

IsOptional reports whether the forward direction is optional.

func (*Relation) IsSealed

func (r *Relation) IsSealed() bool

IsSealed reports whether the relation has been sealed.

func (*Relation) Kind

func (r *Relation) Kind() RelationKind

Kind returns the relation kind (association or composition).

func (*Relation) Name

func (r *Relation) Name() string

Name returns the DSL name of the relation (e.g., "OWNER").

func (*Relation) Owner

func (r *Relation) Owner() string

Owner returns the name of the type that declares this relation.

func (*Relation) Properties

func (r *Relation) Properties() iter.Seq[*Property]

Properties returns an iterator over edge properties. For compositions, this returns an empty iterator.

func (*Relation) PropertiesSlice

func (r *Relation) PropertiesSlice() []*Property

PropertiesSlice returns a defensive copy of edge properties. For compositions, this returns an empty slice.

func (*Relation) Property

func (r *Relation) Property(name string) (*Property, bool)

Property returns the edge property with the given name, if it exists.

Uses linear search. Edge properties are typically few (0-3), so O(n) lookup is acceptable and avoids additional memory overhead of an index.

func (*Relation) ReverseMultiplicity

func (r *Relation) ReverseMultiplicity() (optional, many bool)

ReverseMultiplicity returns the reverse direction multiplicity. Returns (optional, many).

func (*Relation) Seal

func (r *Relation) Seal()

Seal prevents further mutation of the relation. Called during schema completion after target resolution.

func (*Relation) SetTargetID

func (r *Relation) SetTargetID(id TypeID)

SetTargetID sets the resolved canonical type identity. Internal use only; called during schema completion. Panics if called after Seal().

func (*Relation) Span

func (r *Relation) Span() location.Span

Span returns the source location of this relation declaration.

func (*Relation) Target

func (r *Relation) Target() TypeRef

Target returns the syntactic type reference for diagnostics.

func (*Relation) TargetID

func (r *Relation) TargetID() TypeID

TargetID returns the resolved canonical type identity.

type RelationKind

type RelationKind uint8

RelationKind identifies the kind of relationship.

const (
	// RelationAssociation represents an association between types.
	// Associations may have edge properties.
	RelationAssociation RelationKind = iota
	// RelationComposition represents a composition (part-of) relationship.
	// Compositions do not have edge properties.
	RelationComposition
)

func (RelationKind) String

func (k RelationKind) String() string

String returns the name of the relation kind.

type ResolvedTypeRef

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

ResolvedTypeRef combines a syntactic TypeRef with its resolved semantic TypeID. This is used when both the original source representation and the resolved identity are needed.

ResolvedTypeRef is used for:

  • SuperTypes() and SubTypes() where both display and identity matter
  • Cross-schema relationships where no import alias exists
  • Tooling that needs to show qualified names while comparing types

func NewResolvedTypeRef

func NewResolvedTypeRef(ref TypeRef, id TypeID) ResolvedTypeRef

NewResolvedTypeRef creates a ResolvedTypeRef from a TypeRef and TypeID.

func ResolvedTypeRefFromType

func ResolvedTypeRefFromType(t *Type, viewingSchemaPath string) ResolvedTypeRef

ResolvedTypeRefFromType creates a ResolvedTypeRef for a *Type, deriving the display qualifier from the schema name when viewed from a different schema.

viewingSchemaPath is the schema from whose perspective this reference is being viewed. If viewingSchemaPath matches t.SourceID().String(), the type is local and no qualifier is shown. Otherwise, a qualifier is derived from the target schema's name.

func (ResolvedTypeRef) Equal

func (r ResolvedTypeRef) Equal(other ResolvedTypeRef) bool

Equal reports whether two ResolvedTypeRefs refer to the same type. Comparison is by TypeID (semantic identity), ignoring syntactic differences in the TypeRef (such as different import qualifiers that resolve to the same type).

func (ResolvedTypeRef) ID

func (r ResolvedTypeRef) ID() TypeID

ID returns the resolved canonical TypeID.

func (ResolvedTypeRef) IsLocal

func (r ResolvedTypeRef) IsLocal() bool

IsLocal reports whether this type reference is local (unqualified). Returns true if there is no import qualifier.

func (ResolvedTypeRef) IsZero

func (r ResolvedTypeRef) IsZero() bool

IsZero reports whether this is the zero value.

func (ResolvedTypeRef) Name

func (r ResolvedTypeRef) Name() string

Name returns the type name (from the syntactic reference).

func (ResolvedTypeRef) Qualifier

func (r ResolvedTypeRef) Qualifier() string

Qualifier returns the import qualifier (from the syntactic reference).

func (ResolvedTypeRef) Ref

func (r ResolvedTypeRef) Ref() TypeRef

Ref returns the original syntactic TypeRef.

func (ResolvedTypeRef) Span

func (r ResolvedTypeRef) Span() location.Span

Span returns the source location (from the syntactic reference).

func (ResolvedTypeRef) String

func (r ResolvedTypeRef) String() string

String returns the display string using the syntactic representation.

type Schema

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

Schema represents a compiled, immutable schema. After loading, schemas are thread-safe for concurrent access.

func NewSchema

func NewSchema(
	name string,
	sourceID location.SourceID,
	span location.Span,
	doc string,
) *Schema

NewSchema creates a new Schema. This is primarily for internal use; schemas are typically created via Load, LoadString, or Builder.

func (*Schema) DataType

func (s *Schema) DataType(name string) (*DataType, bool)

DataType returns the data type with the given name (local only).

func (*Schema) DataTypeNames

func (s *Schema) DataTypeNames() []string

DataTypeNames returns all data type names in lexicographic order.

func (*Schema) DataTypes

func (s *Schema) DataTypes() iter.Seq2[string, *DataType]

DataTypes returns an iterator over all data types in this schema. Iteration order is lexicographic by name.

func (*Schema) DataTypesSlice

func (s *Schema) DataTypesSlice() []*DataType

DataTypesSlice returns a defensive copy of all data types.

func (*Schema) Documentation

func (s *Schema) Documentation() string

Documentation returns the documentation comment, if any.

func (*Schema) FindImportAlias

func (s *Schema) FindImportAlias(path location.SourceID) string

FindImportAlias returns the alias for an imported schema, if it exists. Returns empty string if the path is not imported or if it's this schema's own path.

func (*Schema) HasSourceProvider

func (s *Schema) HasSourceProvider() bool

HasSourceProvider reports whether source content is available for diagnostic rendering. Returns false for schemas built programmatically via Builder without source content.

func (*Schema) ImportByAlias

func (s *Schema) ImportByAlias(alias string) (*Import, bool)

ImportByAlias returns the import with the given alias.

func (*Schema) ImportCount

func (s *Schema) ImportCount() int

ImportCount returns the number of imports in the schema.

func (*Schema) Imports

func (s *Schema) Imports() iter.Seq[*Import]

Imports returns an iterator over import declarations.

func (*Schema) ImportsSlice

func (s *Schema) ImportsSlice() []*Import

ImportsSlice returns a defensive copy of imports.

func (*Schema) IsSealed

func (s *Schema) IsSealed() bool

IsSealed reports whether the schema has been sealed.

func (*Schema) Name

func (s *Schema) Name() string

Name returns the schema name.

func (*Schema) ResolveDataType

func (s *Schema) ResolveDataType(ref DataTypeRef) (*DataType, bool)

ResolveDataType resolves a DataTypeRef to a DataType, handling qualified references to imported data types.

func (*Schema) ResolveType

func (s *Schema) ResolveType(ref TypeRef) (*Type, bool)

ResolveType resolves a TypeRef to a Type, handling qualified references to imported types.

func (*Schema) Seal

func (s *Schema) Seal()

Seal marks the schema as immutable. Called by the loader after all post-completion wiring is done. This is not part of the public API and may be removed in future versions.

func (*Schema) SetDataTypes

func (s *Schema) SetDataTypes(dataTypes []*DataType)

SetDataTypes sets the data types (called during completion).

func (*Schema) SetImports

func (s *Schema) SetImports(imports []*Import)

SetImports sets the imports (called during completion).

func (*Schema) SetSources

func (s *Schema) SetSources(sources *Sources)

SetSources sets the source registry (called during loading).

func (*Schema) SetTypes

func (s *Schema) SetTypes(types []*Type)

SetTypes sets the types (called during completion).

func (*Schema) SourceID

func (s *Schema) SourceID() location.SourceID

SourceID returns the canonical source identity of this schema.

func (*Schema) Sources

func (s *Schema) Sources() *Sources

Sources returns the source content registry for diagnostic rendering. May be nil if source content was not retained.

func (*Schema) Span

func (s *Schema) Span() location.Span

Span returns the source location of this schema declaration.

func (*Schema) Type

func (s *Schema) Type(name string) (*Type, bool)

Type returns the type with the given name (local types only). For imported types, use ResolveType with a qualified TypeRef.

func (*Schema) TypeCount

func (s *Schema) TypeCount() int

TypeCount returns the number of local types in the schema.

func (*Schema) TypeNames

func (s *Schema) TypeNames() []string

TypeNames returns all local type names in lexicographic order. This ensures deterministic iteration for CLI output and tests.

func (*Schema) Types

func (s *Schema) Types() iter.Seq2[string, *Type]

Types returns an iterator over all types in this schema. Iteration order is lexicographic by name.

func (*Schema) TypesSlice

func (s *Schema) TypesSlice() []*Type

TypesSlice returns a defensive copy of all types.

type SourceRegistry

type SourceRegistry interface {
	// ContentBySource returns the source content for the given source ID.
	ContentBySource(id location.SourceID) ([]byte, bool)

	// Content returns the source content for the span's source ID.
	Content(span location.Span) ([]byte, bool)

	// PositionAt converts a byte offset to a Position.
	PositionAt(id location.SourceID, byteOffset int) location.Position

	// LineStartByte returns the byte offset of the start of a line.
	LineStartByte(id location.SourceID, line int) (int, bool)

	// RuneToByteOffset converts a rune index to a byte offset.
	RuneToByteOffset(id location.SourceID, runeIndex int) (int, bool)

	// Keys returns all registered source IDs in sorted order.
	// The returned slice must be sorted by SourceID.String() and must be
	// a defensive copy (callers may modify it freely).
	// Implementations must guarantee deterministic iteration order.
	Keys() []location.SourceID

	// Has reports whether the source ID is registered.
	Has(id location.SourceID) bool

	// Len returns the number of registered sources.
	Len() int
}

SourceRegistry provides the full source content and position lookup interface. This is typically implemented by internal/source.Registry.

type Sources

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

Sources provides read-only access to schema source content. It wraps an underlying source registry for diagnostic rendering.

func NewSources

func NewSources(registry SourceRegistry) *Sources

NewSources creates a Sources wrapper around a source registry.

func (*Sources) Content

func (s *Sources) Content(span location.Span) ([]byte, bool)

Content returns the source content for the span's source ID. Returns nil, false if the source is not found. Implements diag.SourceProvider.

func (*Sources) ContentBySource

func (s *Sources) ContentBySource(id location.SourceID) ([]byte, bool)

ContentBySource returns the source content for the given source ID. Returns nil, false if the source is not found.

func (*Sources) Has

func (s *Sources) Has(id location.SourceID) bool

Has reports whether the given source ID is registered.

func (*Sources) Len

func (s *Sources) Len() int

Len returns the number of registered sources.

func (*Sources) LineStartByte

func (s *Sources) LineStartByte(id location.SourceID, line int) (int, bool)

LineStartByte returns the byte offset of the start of a line. Returns 0, false if the source is not found or line is invalid. Implements diag.LineIndexProvider.

func (*Sources) PositionAt

func (s *Sources) PositionAt(id location.SourceID, byteOffset int) location.Position

PositionAt converts a byte offset to a Position. Returns zero Position if the source is not found or offset is invalid.

func (*Sources) RuneToByteOffset

func (s *Sources) RuneToByteOffset(id location.SourceID, runeIndex int) (int, bool)

RuneToByteOffset converts a rune index to a byte offset. Returns 0, false if the source is not found or rune index is invalid.

func (*Sources) SourceIDs

func (s *Sources) SourceIDs() []location.SourceID

SourceIDs returns all registered source IDs in sorted order. Sources are sorted by SourceID.String(), ensuring deterministic ordering.

func (*Sources) SourceIDsIter

func (s *Sources) SourceIDsIter() iter.Seq[location.SourceID]

SourceIDsIter returns an iterator over all source IDs. The iteration order matches SourceIDs() (sorted by SourceID.String()). This ordering guarantee ensures deterministic iteration across calls.

type StringConstraint

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

StringConstraint constrains string values with optional min/max length.

func NewStringConstraint

func NewStringConstraint() StringConstraint

NewStringConstraint creates a StringConstraint with no bounds.

func NewStringConstraintBounded

func NewStringConstraintBounded(minLen, maxLen int64) StringConstraint

NewStringConstraintBounded creates a StringConstraint with the given bounds. Pass -1 for minLen or maxLen to indicate no bound.

func (StringConstraint) Equal

func (c StringConstraint) Equal(other Constraint) bool

func (StringConstraint) IsResolved

func (StringConstraint) IsResolved() bool

func (StringConstraint) Kind

func (StringConstraint) MaxLen

func (c StringConstraint) MaxLen() (int64, bool)

func (StringConstraint) MinLen

func (c StringConstraint) MinLen() (int64, bool)

func (StringConstraint) NarrowsTo added in v0.1.2

func (c StringConstraint) NarrowsTo(child Constraint) bool

func (StringConstraint) String

func (c StringConstraint) String() string

type TimestampConstraint

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

TimestampConstraint constrains timestamp values with an optional format.

func NewTimestampConstraint

func NewTimestampConstraint() TimestampConstraint

NewTimestampConstraint creates a TimestampConstraint with no format.

func NewTimestampConstraintFormatted

func NewTimestampConstraintFormatted(format string) TimestampConstraint

NewTimestampConstraintFormatted creates a TimestampConstraint with a Go time format.

func (TimestampConstraint) Equal

func (c TimestampConstraint) Equal(other Constraint) bool

func (TimestampConstraint) Format

func (c TimestampConstraint) Format() string

func (TimestampConstraint) IsResolved

func (TimestampConstraint) IsResolved() bool

func (TimestampConstraint) Kind

func (TimestampConstraint) NarrowsTo added in v0.1.2

func (c TimestampConstraint) NarrowsTo(child Constraint) bool

func (TimestampConstraint) String

func (c TimestampConstraint) String() string

type Type

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

Type represents a type definition in a schema. Types are immutable after schema completion.

func NewType

func NewType(
	name string,
	sourceID location.SourceID,
	span location.Span,
	doc string,
	isAbstract, isPart bool,
) *Type

NewType creates a new Type. This is primarily for internal use; types are typically created during schema parsing and completion.

func (*Type) AllAssociations

func (t *Type) AllAssociations() iter.Seq[*Relation]

AllAssociations returns an iterator over all associations (own and inherited).

func (*Type) AllAssociationsSlice

func (t *Type) AllAssociationsSlice() []*Relation

AllAssociationsSlice returns a defensive copy of all associations.

func (*Type) AllCompositions

func (t *Type) AllCompositions() iter.Seq[*Relation]

AllCompositions returns an iterator over all compositions (own and inherited).

func (*Type) AllCompositionsSlice

func (t *Type) AllCompositionsSlice() []*Relation

AllCompositionsSlice returns a defensive copy of all compositions.

func (*Type) AllInvariants added in v0.1.2

func (t *Type) AllInvariants() iter.Seq[*Invariant]

AllInvariants returns an iterator over all invariants (own and inherited).

func (*Type) AllInvariantsSlice added in v0.1.2

func (t *Type) AllInvariantsSlice() []*Invariant

AllInvariantsSlice returns a defensive copy of all invariants (own and inherited).

func (*Type) AllProperties

func (t *Type) AllProperties() iter.Seq[*Property]

AllProperties returns an iterator over all properties (own and inherited). Properties are returned in linearized order: own first, then inherited.

func (*Type) AllPropertiesSlice

func (t *Type) AllPropertiesSlice() []*Property

AllPropertiesSlice returns a defensive copy of all properties (own and inherited).

func (*Type) Associations

func (t *Type) Associations() iter.Seq[*Relation]

Associations returns an iterator over associations declared in this type body.

func (*Type) AssociationsSlice

func (t *Type) AssociationsSlice() []*Relation

AssociationsSlice returns a defensive copy of associations declared in this type.

func (*Type) CanonicalPropertyMap

func (t *Type) CanonicalPropertyMap() map[string]string

CanonicalPropertyMap returns a map from lowercase property names to their canonical schema names. Used for case-insensitive property matching.

The returned map is a defensive copy; callers may modify it freely. This method is O(n) on first call (builds map) and O(n) on subsequent calls (defensive copy). For single lookups, consider iterating AllProperties() directly.

func (*Type) Compositions

func (t *Type) Compositions() iter.Seq[*Relation]

Compositions returns an iterator over compositions declared in this type body.

func (*Type) CompositionsSlice

func (t *Type) CompositionsSlice() []*Relation

CompositionsSlice returns a defensive copy of compositions declared in this type.

func (*Type) Documentation

func (t *Type) Documentation() string

Documentation returns the documentation comment, if any.

func (*Type) HasPrimaryKey

func (t *Type) HasPrimaryKey() bool

HasPrimaryKey reports whether this type has at least one primary key property.

func (*Type) ID

func (t *Type) ID() TypeID

ID returns the canonical TypeID for this type.

func (*Type) Inherits

func (t *Type) Inherits() iter.Seq[TypeRef]

Inherits returns an iterator over the declared extends clause (syntactic refs).

func (*Type) InheritsSlice

func (t *Type) InheritsSlice() []TypeRef

InheritsSlice returns a defensive copy of the extends clause.

func (*Type) Invariants

func (t *Type) Invariants() iter.Seq[*Invariant]

Invariants returns an iterator over invariants declared on this type.

func (*Type) InvariantsSlice

func (t *Type) InvariantsSlice() []*Invariant

InvariantsSlice returns a defensive copy of invariants.

func (*Type) IsAbstract

func (t *Type) IsAbstract() bool

IsAbstract reports whether this type is abstract. Abstract types cannot be directly instantiated.

func (*Type) IsPart

func (t *Type) IsPart() bool

IsPart reports whether this type is a part type. Part types can only be instantiated as compositions.

func (*Type) IsSealed

func (t *Type) IsSealed() bool

IsSealed reports whether the type has been sealed.

func (*Type) IsSubTypeOf

func (t *Type) IsSubTypeOf(id TypeID) bool

IsSubTypeOf reports whether this type is a subtype of the given type. Uses TypeID for cross-schema comparison.

func (*Type) IsSuperTypeOf

func (t *Type) IsSuperTypeOf(id TypeID) bool

IsSuperTypeOf reports whether this type is a supertype of the given type. Uses TypeID for cross-schema comparison.

func (*Type) Name

func (t *Type) Name() string

Name returns the type name.

func (*Type) NameSpan

func (t *Type) NameSpan() location.Span

NameSpan returns the precise source location of just the type name. This is more accurate than Span() for go-to-definition operations. Returns a zero span if not set (e.g., for programmatically-created types).

func (*Type) PrimaryKeys

func (t *Type) PrimaryKeys() iter.Seq[*Property]

PrimaryKeys returns an iterator over primary key properties.

func (*Type) PrimaryKeysSlice

func (t *Type) PrimaryKeysSlice() []*Property

PrimaryKeysSlice returns a defensive copy of primary key properties.

func (*Type) Properties

func (t *Type) Properties() iter.Seq[*Property]

Properties returns an iterator over properties declared in this type body. Does NOT include inherited properties; use AllProperties for that.

func (*Type) PropertiesSlice

func (t *Type) PropertiesSlice() []*Property

PropertiesSlice returns a defensive copy of properties declared in this type.

func (*Type) Property

func (t *Type) Property(name string) (*Property, bool)

Property returns the property with the given name (own or inherited), if it exists. Uses O(1) lookup.

func (*Type) Relation

func (t *Type) Relation(name string) (*Relation, bool)

Relation returns the relation with the given name (own or inherited), if it exists. Uses O(1) lookup.

func (*Type) SchemaName

func (t *Type) SchemaName() string

SchemaName returns the name of the schema containing this type. Used for cross-schema display when no import alias exists.

func (*Type) Seal

func (t *Type) Seal()

Seal marks the type as immutable. Called by the completer after type completion finishes. This is not part of the public API and may be removed in future versions.

func (*Type) SetAllAssociations

func (t *Type) SetAllAssociations(all []*Relation)

SetAllAssociations sets all associations including inherited (called during completion).

func (*Type) SetAllCompositions

func (t *Type) SetAllCompositions(all []*Relation)

SetAllCompositions sets all compositions including inherited (called during completion).

func (*Type) SetAllInvariants added in v0.1.2

func (t *Type) SetAllInvariants(all []*Invariant)

SetAllInvariants sets all invariants including inherited (called during completion).

func (*Type) SetAllProperties

func (t *Type) SetAllProperties(all []*Property)

SetAllProperties sets all properties including inherited (called during completion).

func (*Type) SetAssociations

func (t *Type) SetAssociations(associations []*Relation)

SetAssociations sets the declared associations (called during completion).

func (*Type) SetCompositions

func (t *Type) SetCompositions(compositions []*Relation)

SetCompositions sets the declared compositions (called during completion).

func (*Type) SetInherits

func (t *Type) SetInherits(inherits []TypeRef)

SetInherits sets the declared extends clause (called during completion).

func (*Type) SetInvariants

func (t *Type) SetInvariants(invariants []*Invariant)

SetInvariants sets the invariants (called during completion).

func (*Type) SetNameSpan

func (t *Type) SetNameSpan(span location.Span)

SetNameSpan sets the precise span of the type name. This must be called before the type is sealed.

func (*Type) SetPrimaryKeys

func (t *Type) SetPrimaryKeys(pks []*Property)

SetPrimaryKeys sets the primary key properties (called during completion).

func (*Type) SetProperties

func (t *Type) SetProperties(properties []*Property)

SetProperties sets the declared properties (called during completion).

func (*Type) SetSchemaName

func (t *Type) SetSchemaName(name string)

SetSchemaName sets the owning schema's name (called during completion).

func (*Type) SetSubTypes

func (t *Type) SetSubTypes(subs []ResolvedTypeRef)

SetSubTypes sets the known subtypes (called during completion).

func (*Type) SetSuperTypes

func (t *Type) SetSuperTypes(supers []ResolvedTypeRef)

SetSuperTypes sets the linearized ancestors (called during completion).

func (*Type) SourceID

func (t *Type) SourceID() location.SourceID

SourceID returns the source identity of the schema containing this type.

func (*Type) Span

func (t *Type) Span() location.Span

Span returns the source location of this type declaration.

func (*Type) SubTypes

func (t *Type) SubTypes() iter.Seq[ResolvedTypeRef]

SubTypes returns an iterator over known subtypes (may include cross-schema types).

func (*Type) SubTypesSlice

func (t *Type) SubTypesSlice() []ResolvedTypeRef

SubTypesSlice returns a defensive copy of known subtypes.

func (*Type) SuperTypes

func (t *Type) SuperTypes() iter.Seq[ResolvedTypeRef]

SuperTypes returns an iterator over linearized ancestors. Order is DFS left-to-right with keep-first deduplication.

func (*Type) SuperTypesSlice

func (t *Type) SuperTypesSlice() []ResolvedTypeRef

SuperTypesSlice returns a defensive copy of linearized ancestors.

type TypeID

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

TypeID uniquely identifies a type across all schemas. It is the semantic identity of a type, used for equality comparisons, inheritance deduplication, and cross-schema type resolution.

Two types are equal if and only if they have the same TypeID. This enables:

  • Proper diamond inheritance handling (same ancestor via different paths)
  • Cross-schema type comparison (types from different schemas are distinct)
  • Safe use as map keys

TypeID is a value type with comparable semantics; use == for equality.

func NewTypeID

func NewTypeID(schemaPath location.SourceID, name string) TypeID

NewTypeID creates a TypeID from a schema source ID and type name.

func (TypeID) IsZero

func (id TypeID) IsZero() bool

IsZero reports whether the TypeID is the zero value.

func (TypeID) Name

func (id TypeID) Name() string

Name returns the type name within the schema.

func (TypeID) SchemaPath

func (id TypeID) SchemaPath() location.SourceID

SchemaPath returns the canonical source identity of the schema containing this type. For file-backed schemas, this is the canonicalized file path. For programmatically built schemas, this is a synthetic identifier.

func (TypeID) String

func (id TypeID) String() string

String returns a human-readable representation of the TypeID. Format: "schemaPath:typeName" or just "typeName" for empty schema path.

type TypeRef

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

TypeRef is a syntactic reference to a type, preserving what was written in the schema source. It captures the optional import qualifier and type name.

TypeRef is used for:

  • Parsing and error messages (shows user's original syntax)
  • Preserving import qualification for tooling (go-to-definition)
  • Displaying type references in diagnostics

For semantic equality (comparing types), use TypeID instead.

func LocalTypeRef

func LocalTypeRef(name string, span location.Span) TypeRef

LocalTypeRef creates a TypeRef for a local (unqualified) type.

func NewTypeRef

func NewTypeRef(qualifier, name string, span location.Span) TypeRef

NewTypeRef creates a TypeRef with the given qualifier, name, and span.

func (TypeRef) IsQualified

func (r TypeRef) IsQualified() bool

IsQualified reports whether this is a qualified (imported) type reference.

func (TypeRef) IsZero

func (r TypeRef) IsZero() bool

IsZero reports whether this is the zero value.

func (TypeRef) Name

func (r TypeRef) Name() string

Name returns the type name.

func (TypeRef) Qualifier

func (r TypeRef) Qualifier() string

Qualifier returns the import alias, or empty string for local types.

func (TypeRef) Span

func (r TypeRef) Span() location.Span

Span returns the source location of this type reference.

func (TypeRef) String

func (r TypeRef) String() string

String returns the fully qualified name (e.g., "parts.Wheel" or "Wheel").

type UUIDConstraint

type UUIDConstraint struct{}

UUIDConstraint constrains UUID values. It has no parameters.

func NewUUIDConstraint

func NewUUIDConstraint() UUIDConstraint

NewUUIDConstraint creates a UUIDConstraint.

func (UUIDConstraint) Equal

func (c UUIDConstraint) Equal(other Constraint) bool

func (UUIDConstraint) IsResolved

func (UUIDConstraint) IsResolved() bool

func (UUIDConstraint) Kind

func (UUIDConstraint) NarrowsTo added in v0.1.2

func (c UUIDConstraint) NarrowsTo(child Constraint) bool

func (UUIDConstraint) String

func (UUIDConstraint) String() string

type VectorConstraint

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

VectorConstraint constrains vector values to a fixed dimension.

func NewVectorConstraint

func NewVectorConstraint(dimension int) VectorConstraint

NewVectorConstraint creates a VectorConstraint with the given dimension.

func (VectorConstraint) Dimension

func (c VectorConstraint) Dimension() int

Dimension returns the required vector dimension.

func (VectorConstraint) Equal

func (c VectorConstraint) Equal(other Constraint) bool

func (VectorConstraint) IsResolved

func (VectorConstraint) IsResolved() bool

func (VectorConstraint) Kind

func (VectorConstraint) NarrowsTo added in v0.1.2

func (c VectorConstraint) NarrowsTo(child Constraint) bool

func (VectorConstraint) String

func (c VectorConstraint) String() string

Directories

Path Synopsis
Package build provides a fluent builder API for programmatically constructing schemas.
Package build provides a fluent builder API for programmatically constructing schemas.
Package expr provides expression compilation for YAMMM schema invariants.
Package expr provides expression compilation for YAMMM schema invariants.
internal
alias
Package alias provides import alias validation utilities for the schema layer.
Package alias provides import alias validation utilities for the schema layer.
complete
Package complete implements schema completion - the phase where parsed ASTs are transformed into fully-resolved, validated Schema objects.
Package complete implements schema completion - the phase where parsed ASTs are transformed into fully-resolved, validated Schema objects.
parse
Package parse provides AST types and parsing infrastructure for YAMMM schemas.
Package parse provides AST types and parsing infrastructure for YAMMM schemas.
span
Package span provides utilities for building location.Span values from ANTLR tokens.
Package span provides utilities for building location.Span values from ANTLR tokens.
Package load provides schema loading functionality.
Package load provides schema loading functionality.

Jump to

Keyboard shortcuts

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