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 ¶
- type AliasConstraint
- func (c AliasConstraint) DataTypeName() string
- func (c AliasConstraint) Equal(other Constraint) bool
- func (c AliasConstraint) IsResolved() bool
- func (AliasConstraint) Kind() ConstraintKind
- func (c AliasConstraint) NarrowsTo(child Constraint) bool
- func (c AliasConstraint) Resolved() Constraint
- func (c AliasConstraint) String() string
- type BooleanConstraint
- type Constraint
- type ConstraintKind
- type DataType
- type DataTypeRef
- type DateConstraint
- type DeclaringScope
- type DeclaringScopeKind
- type EnumConstraint
- type FloatConstraint
- func (c FloatConstraint) Equal(other Constraint) bool
- func (FloatConstraint) IsResolved() bool
- func (FloatConstraint) Kind() ConstraintKind
- func (c FloatConstraint) Max() (float64, bool)
- func (c FloatConstraint) Min() (float64, bool)
- func (c FloatConstraint) NarrowsTo(child Constraint) bool
- func (c FloatConstraint) String() string
- type Import
- func (i *Import) Alias() string
- func (i *Import) IsSealed() bool
- func (i *Import) Path() string
- func (i *Import) ResolvedPath() string
- func (i *Import) ResolvedSourceID() location.SourceID
- func (i *Import) Schema() *Schema
- func (i *Import) Seal()
- func (i *Import) SetResolvedSourceID(id location.SourceID)
- func (i *Import) SetSchema(s *Schema)
- func (i *Import) Span() location.Span
- type IntegerConstraint
- func (c IntegerConstraint) Equal(other Constraint) bool
- func (IntegerConstraint) IsResolved() bool
- func (IntegerConstraint) Kind() ConstraintKind
- func (c IntegerConstraint) Max() (int64, bool)
- func (c IntegerConstraint) Min() (int64, bool)
- func (c IntegerConstraint) NarrowsTo(child Constraint) bool
- func (c IntegerConstraint) String() string
- type Invariant
- type ListConstraint
- func (c ListConstraint) Element() Constraint
- func (c ListConstraint) Equal(other Constraint) bool
- func (c ListConstraint) IsResolved() bool
- func (ListConstraint) Kind() ConstraintKind
- func (c ListConstraint) MaxLen() (int64, bool)
- func (c ListConstraint) MinLen() (int64, bool)
- func (c ListConstraint) NarrowsTo(child Constraint) bool
- func (c ListConstraint) String() string
- type LookupStatus
- type PatternConstraint
- func (c PatternConstraint) CompiledPatterns() []*regexp.Regexp
- func (c PatternConstraint) Equal(other Constraint) bool
- func (PatternConstraint) IsResolved() bool
- func (PatternConstraint) Kind() ConstraintKind
- func (c PatternConstraint) NarrowsTo(child Constraint) bool
- func (c PatternConstraint) Pattern() string
- func (c PatternConstraint) PatternCount() int
- func (c PatternConstraint) Patterns() []string
- func (c PatternConstraint) String() string
- type Property
- func (p *Property) CanNarrowFrom(parent *Property) bool
- func (p *Property) Constraint() Constraint
- func (p *Property) DataTypeRef() DataTypeRef
- func (p *Property) DeclaringScope() DeclaringScope
- func (p *Property) Documentation() string
- func (p *Property) Equal(other *Property) bool
- func (p *Property) IsOptional() bool
- func (p *Property) IsPrimaryKey() bool
- func (p *Property) IsRequired() bool
- func (p *Property) Name() string
- func (p *Property) SetConstraint(c Constraint)
- func (p *Property) Span() location.Span
- type Registry
- func (r *Registry) All() []*Schema
- func (r *Registry) Clone() *Registry
- func (r *Registry) Contains(id location.SourceID) bool
- func (r *Registry) Len() int
- func (r *Registry) LookupByName(name string) (*Schema, LookupStatus)
- func (r *Registry) LookupBySourceID(id location.SourceID) (*Schema, LookupStatus)
- func (r *Registry) LookupSchema(id TypeID) (*Schema, LookupStatus)
- func (r *Registry) LookupType(id TypeID) (*Type, LookupStatus)
- func (r *Registry) Register(s *Schema) error
- type RegistryError
- type RegistryErrorKind
- type Relation
- func (r *Relation) Backref() string
- func (r *Relation) Documentation() string
- func (r *Relation) Equal(other *Relation) bool
- func (r *Relation) FieldName() string
- func (r *Relation) HasProperties() bool
- func (r *Relation) IsAssociation() bool
- func (r *Relation) IsComposition() bool
- func (r *Relation) IsMany() bool
- func (r *Relation) IsOptional() bool
- func (r *Relation) IsSealed() bool
- func (r *Relation) Kind() RelationKind
- func (r *Relation) Name() string
- func (r *Relation) Owner() string
- func (r *Relation) Properties() iter.Seq[*Property]
- func (r *Relation) PropertiesSlice() []*Property
- func (r *Relation) Property(name string) (*Property, bool)
- func (r *Relation) ReverseMultiplicity() (optional, many bool)
- func (r *Relation) Seal()
- func (r *Relation) SetTargetID(id TypeID)
- func (r *Relation) Span() location.Span
- func (r *Relation) Target() TypeRef
- func (r *Relation) TargetID() TypeID
- type RelationKind
- type ResolvedTypeRef
- func (r ResolvedTypeRef) Equal(other ResolvedTypeRef) bool
- func (r ResolvedTypeRef) ID() TypeID
- func (r ResolvedTypeRef) IsLocal() bool
- func (r ResolvedTypeRef) IsZero() bool
- func (r ResolvedTypeRef) Name() string
- func (r ResolvedTypeRef) Qualifier() string
- func (r ResolvedTypeRef) Ref() TypeRef
- func (r ResolvedTypeRef) Span() location.Span
- func (r ResolvedTypeRef) String() string
- type Schema
- func (s *Schema) DataType(name string) (*DataType, bool)
- func (s *Schema) DataTypeNames() []string
- func (s *Schema) DataTypes() iter.Seq2[string, *DataType]
- func (s *Schema) DataTypesSlice() []*DataType
- func (s *Schema) Documentation() string
- func (s *Schema) FindImportAlias(path location.SourceID) string
- func (s *Schema) HasSourceProvider() bool
- func (s *Schema) ImportByAlias(alias string) (*Import, bool)
- func (s *Schema) ImportCount() int
- func (s *Schema) Imports() iter.Seq[*Import]
- func (s *Schema) ImportsSlice() []*Import
- func (s *Schema) IsSealed() bool
- func (s *Schema) Name() string
- func (s *Schema) ResolveDataType(ref DataTypeRef) (*DataType, bool)
- func (s *Schema) ResolveType(ref TypeRef) (*Type, bool)
- func (s *Schema) Seal()
- func (s *Schema) SetDataTypes(dataTypes []*DataType)
- func (s *Schema) SetImports(imports []*Import)
- func (s *Schema) SetSources(sources *Sources)
- func (s *Schema) SetTypes(types []*Type)
- func (s *Schema) SourceID() location.SourceID
- func (s *Schema) Sources() *Sources
- func (s *Schema) Span() location.Span
- func (s *Schema) Type(name string) (*Type, bool)
- func (s *Schema) TypeCount() int
- func (s *Schema) TypeNames() []string
- func (s *Schema) Types() iter.Seq2[string, *Type]
- func (s *Schema) TypesSlice() []*Type
- type SourceRegistry
- type Sources
- func (s *Sources) Content(span location.Span) ([]byte, bool)
- func (s *Sources) ContentBySource(id location.SourceID) ([]byte, bool)
- func (s *Sources) Has(id location.SourceID) bool
- func (s *Sources) Len() int
- func (s *Sources) LineStartByte(id location.SourceID, line int) (int, bool)
- func (s *Sources) PositionAt(id location.SourceID, byteOffset int) location.Position
- func (s *Sources) RuneToByteOffset(id location.SourceID, runeIndex int) (int, bool)
- func (s *Sources) SourceIDs() []location.SourceID
- func (s *Sources) SourceIDsIter() iter.Seq[location.SourceID]
- type StringConstraint
- func (c StringConstraint) Equal(other Constraint) bool
- func (StringConstraint) IsResolved() bool
- func (StringConstraint) Kind() ConstraintKind
- func (c StringConstraint) MaxLen() (int64, bool)
- func (c StringConstraint) MinLen() (int64, bool)
- func (c StringConstraint) NarrowsTo(child Constraint) bool
- func (c StringConstraint) String() string
- type TimestampConstraint
- func (c TimestampConstraint) Equal(other Constraint) bool
- func (c TimestampConstraint) Format() string
- func (TimestampConstraint) IsResolved() bool
- func (TimestampConstraint) Kind() ConstraintKind
- func (c TimestampConstraint) NarrowsTo(child Constraint) bool
- func (c TimestampConstraint) String() string
- type Type
- func (t *Type) AllAssociations() iter.Seq[*Relation]
- func (t *Type) AllAssociationsSlice() []*Relation
- func (t *Type) AllCompositions() iter.Seq[*Relation]
- func (t *Type) AllCompositionsSlice() []*Relation
- func (t *Type) AllInvariants() iter.Seq[*Invariant]
- func (t *Type) AllInvariantsSlice() []*Invariant
- func (t *Type) AllProperties() iter.Seq[*Property]
- func (t *Type) AllPropertiesSlice() []*Property
- func (t *Type) Associations() iter.Seq[*Relation]
- func (t *Type) AssociationsSlice() []*Relation
- func (t *Type) CanonicalPropertyMap() map[string]string
- func (t *Type) Compositions() iter.Seq[*Relation]
- func (t *Type) CompositionsSlice() []*Relation
- func (t *Type) Documentation() string
- func (t *Type) HasPrimaryKey() bool
- func (t *Type) ID() TypeID
- func (t *Type) Inherits() iter.Seq[TypeRef]
- func (t *Type) InheritsSlice() []TypeRef
- func (t *Type) Invariants() iter.Seq[*Invariant]
- func (t *Type) InvariantsSlice() []*Invariant
- func (t *Type) IsAbstract() bool
- func (t *Type) IsPart() bool
- func (t *Type) IsSealed() bool
- func (t *Type) IsSubTypeOf(id TypeID) bool
- func (t *Type) IsSuperTypeOf(id TypeID) bool
- func (t *Type) Name() string
- func (t *Type) NameSpan() location.Span
- func (t *Type) PrimaryKeys() iter.Seq[*Property]
- func (t *Type) PrimaryKeysSlice() []*Property
- func (t *Type) Properties() iter.Seq[*Property]
- func (t *Type) PropertiesSlice() []*Property
- func (t *Type) Property(name string) (*Property, bool)
- func (t *Type) Relation(name string) (*Relation, bool)
- func (t *Type) SchemaName() string
- func (t *Type) Seal()
- func (t *Type) SetAllAssociations(all []*Relation)
- func (t *Type) SetAllCompositions(all []*Relation)
- func (t *Type) SetAllInvariants(all []*Invariant)
- func (t *Type) SetAllProperties(all []*Property)
- func (t *Type) SetAssociations(associations []*Relation)
- func (t *Type) SetCompositions(compositions []*Relation)
- func (t *Type) SetInherits(inherits []TypeRef)
- func (t *Type) SetInvariants(invariants []*Invariant)
- func (t *Type) SetNameSpan(span location.Span)
- func (t *Type) SetPrimaryKeys(pks []*Property)
- func (t *Type) SetProperties(properties []*Property)
- func (t *Type) SetSchemaName(name string)
- func (t *Type) SetSubTypes(subs []ResolvedTypeRef)
- func (t *Type) SetSuperTypes(supers []ResolvedTypeRef)
- func (t *Type) SourceID() location.SourceID
- func (t *Type) Span() location.Span
- func (t *Type) SubTypes() iter.Seq[ResolvedTypeRef]
- func (t *Type) SubTypesSlice() []ResolvedTypeRef
- func (t *Type) SuperTypes() iter.Seq[ResolvedTypeRef]
- func (t *Type) SuperTypesSlice() []ResolvedTypeRef
- type TypeID
- type TypeRef
- type UUIDConstraint
- type VectorConstraint
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) Kind() ConstraintKind
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) Kind() ConstraintKind
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 ¶
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 ¶
Documentation returns the documentation comment, if any.
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().
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) 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) Kind() ConstraintKind
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 ¶
func (s DeclaringScope) Kind() DeclaringScopeKind
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) Kind() ConstraintKind
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) Kind() ConstraintKind
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 ¶
NewImport creates a new Import. This is primarily for internal use; imports are typically created during schema parsing.
func (*Import) ResolvedPath ¶
ResolvedPath returns the resolved path as a string. Returns empty string if not yet resolved.
func (*Import) ResolvedSourceID ¶
ResolvedSourceID returns the resolved canonical source identity.
func (*Import) 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 ¶
SetResolvedSourceID sets the resolved source identity (called during loading). Panics if called after Seal().
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) Kind() ConstraintKind
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 ¶
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 ¶
Documentation returns the documentation comment, if any.
func (*Invariant) Expression ¶
func (i *Invariant) Expression() expr.Expression
Expression returns the compiled expression for this invariant.
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) Kind() ConstraintKind
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) Kind() ConstraintKind
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
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 ¶
Documentation returns the documentation comment, if any.
func (*Property) Equal ¶
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 ¶
IsOptional reports whether this property is optional.
func (*Property) IsPrimaryKey ¶
IsPrimaryKey reports whether this property is a primary key. Primary key properties are implicitly required.
func (*Property) IsRequired ¶
IsRequired reports whether this property is required (not optional).
func (*Property) SetConstraint ¶
func (p *Property) SetConstraint(c Constraint)
SetConstraint sets the constraint (called during alias resolution). Internal use only; called during schema completion.
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 (*Registry) All ¶
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 ¶
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 ¶
Contains reports whether a schema with the given source ID is registered.
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.
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) Documentation ¶
Documentation returns the documentation comment, if any.
func (*Relation) Equal ¶
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 ¶
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 ¶
HasProperties reports whether this relation has edge properties. Always false for compositions; may be true for associations.
func (*Relation) IsAssociation ¶
IsAssociation reports whether this relation is an association.
func (*Relation) IsComposition ¶
IsComposition reports whether this relation is a composition.
func (*Relation) IsOptional ¶
IsOptional reports whether the forward direction is optional.
func (*Relation) Kind ¶
func (r *Relation) Kind() RelationKind
Kind returns the relation kind (association or composition).
func (*Relation) Properties ¶
Properties returns an iterator over edge properties. For compositions, this returns an empty iterator.
func (*Relation) PropertiesSlice ¶
PropertiesSlice returns a defensive copy of edge properties. For compositions, this returns an empty slice.
func (*Relation) Property ¶
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 ¶
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 ¶
SetTargetID sets the resolved canonical type identity. Internal use only; called during schema completion. Panics if called after Seal().
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 ¶
NewSchema creates a new Schema. This is primarily for internal use; schemas are typically created via Load, LoadString, or Builder.
func (*Schema) DataTypeNames ¶
DataTypeNames returns all data type names in lexicographic order.
func (*Schema) DataTypes ¶
DataTypes returns an iterator over all data types in this schema. Iteration order is lexicographic by name.
func (*Schema) DataTypesSlice ¶
DataTypesSlice returns a defensive copy of all data types.
func (*Schema) Documentation ¶
Documentation returns the documentation comment, if any.
func (*Schema) FindImportAlias ¶
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 ¶
HasSourceProvider reports whether source content is available for diagnostic rendering. Returns false for schemas built programmatically via Builder without source content.
func (*Schema) ImportByAlias ¶
ImportByAlias returns the import with the given alias.
func (*Schema) ImportCount ¶
ImportCount returns the number of imports in the schema.
func (*Schema) ImportsSlice ¶
ImportsSlice returns a defensive copy of imports.
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 ¶
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 ¶
SetDataTypes sets the data types (called during completion).
func (*Schema) SetImports ¶
SetImports sets the imports (called during completion).
func (*Schema) SetSources ¶
SetSources sets the source registry (called during loading).
func (*Schema) Sources ¶
Sources returns the source content registry for diagnostic rendering. May be nil if source content was not retained.
func (*Schema) Type ¶
Type returns the type with the given name (local types only). For imported types, use ResolveType with a qualified TypeRef.
func (*Schema) TypeNames ¶
TypeNames returns all local type names in lexicographic order. This ensures deterministic iteration for CLI output and tests.
func (*Schema) Types ¶
Types returns an iterator over all types in this schema. Iteration order is lexicographic by name.
func (*Schema) TypesSlice ¶
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 ¶
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 ¶
ContentBySource returns the source content for the given source ID. Returns nil, false if the source is not found.
func (*Sources) LineStartByte ¶
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 ¶
PositionAt converts a byte offset to a Position. Returns zero Position if the source is not found or offset is invalid.
func (*Sources) RuneToByteOffset ¶
RuneToByteOffset converts a rune index to a byte offset. Returns 0, false if the source is not found or rune index is invalid.
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) Kind() ConstraintKind
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) Kind() ConstraintKind
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 ¶
AllAssociations returns an iterator over all associations (own and inherited).
func (*Type) AllAssociationsSlice ¶
AllAssociationsSlice returns a defensive copy of all associations.
func (*Type) AllCompositions ¶
AllCompositions returns an iterator over all compositions (own and inherited).
func (*Type) AllCompositionsSlice ¶
AllCompositionsSlice returns a defensive copy of all compositions.
func (*Type) AllInvariants ¶ added in v0.1.2
AllInvariants returns an iterator over all invariants (own and inherited).
func (*Type) AllInvariantsSlice ¶ added in v0.1.2
AllInvariantsSlice returns a defensive copy of all invariants (own and inherited).
func (*Type) AllProperties ¶
AllProperties returns an iterator over all properties (own and inherited). Properties are returned in linearized order: own first, then inherited.
func (*Type) AllPropertiesSlice ¶
AllPropertiesSlice returns a defensive copy of all properties (own and inherited).
func (*Type) Associations ¶
Associations returns an iterator over associations declared in this type body.
func (*Type) AssociationsSlice ¶
AssociationsSlice returns a defensive copy of associations declared in this type.
func (*Type) CanonicalPropertyMap ¶
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 ¶
Compositions returns an iterator over compositions declared in this type body.
func (*Type) CompositionsSlice ¶
CompositionsSlice returns a defensive copy of compositions declared in this type.
func (*Type) Documentation ¶
Documentation returns the documentation comment, if any.
func (*Type) HasPrimaryKey ¶
HasPrimaryKey reports whether this type has at least one primary key property.
func (*Type) Inherits ¶
Inherits returns an iterator over the declared extends clause (syntactic refs).
func (*Type) InheritsSlice ¶
InheritsSlice returns a defensive copy of the extends clause.
func (*Type) Invariants ¶
Invariants returns an iterator over invariants declared on this type.
func (*Type) InvariantsSlice ¶
InvariantsSlice returns a defensive copy of invariants.
func (*Type) IsAbstract ¶
IsAbstract reports whether this type is abstract. Abstract types cannot be directly instantiated.
func (*Type) IsPart ¶
IsPart reports whether this type is a part type. Part types can only be instantiated as compositions.
func (*Type) IsSubTypeOf ¶
IsSubTypeOf reports whether this type is a subtype of the given type. Uses TypeID for cross-schema comparison.
func (*Type) IsSuperTypeOf ¶
IsSuperTypeOf reports whether this type is a supertype of the given type. Uses TypeID for cross-schema comparison.
func (*Type) NameSpan ¶
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 ¶
PrimaryKeys returns an iterator over primary key properties.
func (*Type) PrimaryKeysSlice ¶
PrimaryKeysSlice returns a defensive copy of primary key properties.
func (*Type) Properties ¶
Properties returns an iterator over properties declared in this type body. Does NOT include inherited properties; use AllProperties for that.
func (*Type) PropertiesSlice ¶
PropertiesSlice returns a defensive copy of properties declared in this type.
func (*Type) Property ¶
Property returns the property with the given name (own or inherited), if it exists. Uses O(1) lookup.
func (*Type) Relation ¶
Relation returns the relation with the given name (own or inherited), if it exists. Uses O(1) lookup.
func (*Type) SchemaName ¶
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 ¶
SetAllAssociations sets all associations including inherited (called during completion).
func (*Type) SetAllCompositions ¶
SetAllCompositions sets all compositions including inherited (called during completion).
func (*Type) SetAllInvariants ¶ added in v0.1.2
SetAllInvariants sets all invariants including inherited (called during completion).
func (*Type) SetAllProperties ¶
SetAllProperties sets all properties including inherited (called during completion).
func (*Type) SetAssociations ¶
SetAssociations sets the declared associations (called during completion).
func (*Type) SetCompositions ¶
SetCompositions sets the declared compositions (called during completion).
func (*Type) SetInherits ¶
SetInherits sets the declared extends clause (called during completion).
func (*Type) SetInvariants ¶
SetInvariants sets the invariants (called during completion).
func (*Type) SetNameSpan ¶
SetNameSpan sets the precise span of the type name. This must be called before the type is sealed.
func (*Type) SetPrimaryKeys ¶
SetPrimaryKeys sets the primary key properties (called during completion).
func (*Type) SetProperties ¶
SetProperties sets the declared properties (called during completion).
func (*Type) SetSchemaName ¶
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) 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 (TypeID) SchemaPath ¶
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.
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 ¶
LocalTypeRef creates a TypeRef for a local (unqualified) type.
func NewTypeRef ¶
NewTypeRef creates a TypeRef with the given qualifier, name, and span.
func (TypeRef) IsQualified ¶
IsQualified reports whether this is a qualified (imported) type reference.
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) Kind() ConstraintKind
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) Kind() ConstraintKind
func (VectorConstraint) NarrowsTo ¶ added in v0.1.2
func (c VectorConstraint) NarrowsTo(child Constraint) bool
func (VectorConstraint) String ¶
func (c VectorConstraint) String() string
Source Files
¶
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. |