Documentation
¶
Overview ¶
Package schema handles schema loading and validation.
Index ¶
- Constants
- Variables
- func BuiltinTypeNames() []string
- func CreateDefault(vaultPath string) (bool, error)
- func IsBuiltinType(typeName string) bool
- func IsValidFieldType(fieldType FieldType) bool
- func ResolveTypeTemplateFile(sch *Schema, typeName, templateID string) (string, error)
- func ValidFieldTypes() string
- func ValidateNameField(typeDef *TypeDefinition) error
- func ValidateSchema(sch *Schema) []string
- func ValidateTraitValue(def *TraitDefinition, value FieldValue) error
- type CoreTypeDefinition
- type FieldDefinition
- type FieldType
- type FieldValue
- func Array(items []FieldValue) FieldValue
- func Bool(b bool) FieldValue
- func Date(s string) FieldValue
- func Datetime(s string) FieldValue
- func NewFieldValue(v interface{}) FieldValue
- func Null() FieldValue
- func Number(n float64) FieldValue
- func Ref(s string) FieldValue
- func String(s string) FieldValue
- func (fv FieldValue) AsArray() ([]FieldValue, bool)
- func (fv FieldValue) AsBool() (bool, bool)
- func (fv FieldValue) AsNumber() (float64, bool)
- func (fv FieldValue) AsRef() (string, bool)
- func (fv FieldValue) AsString() (string, bool)
- func (fv FieldValue) IsDate() bool
- func (fv FieldValue) IsDatetime() bool
- func (fv FieldValue) IsNull() bool
- func (fv FieldValue) IsRef() bool
- func (fv FieldValue) MarshalJSON() ([]byte, error)
- func (fv FieldValue) Raw() interface{}
- type LoadResult
- type Schema
- type SchemaWarning
- type TemplateDefinition
- type TraitDefinition
- type TypeDefinition
- type ValidationError
Constants ¶
const CurrentSchemaVersion = 1
CurrentSchemaVersion is the latest schema format version.
Variables ¶
BuiltinTypes are types that are always present and cannot be modified by users. These types have fixed definitions managed by Raven itself.
Functions ¶
func BuiltinTypeNames ¶
func BuiltinTypeNames() []string
BuiltinTypeNames returns a slice of all built-in type names.
func CreateDefault ¶
CreateDefault creates a default schema.yaml file in the vault. Returns true if a new file was created, false if one already existed.
func IsBuiltinType ¶
IsBuiltinType returns true if the type name is a built-in type that cannot be modified.
func IsValidFieldType ¶
func ResolveTypeTemplateFile ¶
ResolveTypeTemplateFile resolves a template file path for a type.
Selection order: 1) If templateID is provided, resolve that template ID from type.templates. 2) Else, if default_template is set, resolve that template ID. 3) Else, fallback to legacy type.template (if present). 4) Else, no template ("").
func ValidFieldTypes ¶
func ValidFieldTypes() string
func ValidateNameField ¶
func ValidateNameField(typeDef *TypeDefinition) error
ValidateNameField checks that a type's name_field is valid. Returns an error if the name_field references a non-existent field or a non-string field.
func ValidateSchema ¶
ValidateSchema performs comprehensive validation of a schema. Returns a list of issues found.
func ValidateTraitValue ¶
func ValidateTraitValue(def *TraitDefinition, value FieldValue) error
ValidateTraitValue validates a single trait value against the trait definition. It assumes a value is present (non-bare trait usage).
Types ¶
type CoreTypeDefinition ¶
type CoreTypeDefinition struct {
// Templates lists template IDs from the schema-level templates map that this core type can use.
Templates []string `yaml:"templates,omitempty"`
// DefaultTemplate selects the template ID from Templates that is applied by default.
DefaultTemplate string `yaml:"default_template,omitempty"`
}
CoreTypeDefinition defines supported configuration for a core type.
Core types are Raven-managed with fixed field definitions. Only explicitly-supported knobs are configurable via schema.yaml "core:".
type FieldDefinition ¶
type FieldDefinition struct {
Type FieldType `yaml:"type"`
Required bool `yaml:"required,omitempty"`
Default interface{} `yaml:"default,omitempty"`
Values []string `yaml:"values,omitempty"` // For enum types
Target string `yaml:"target,omitempty"` // For ref types
// Description provides optional context for humans/agents about this field.
Description string `yaml:"description,omitempty"`
Min *float64 `yaml:"min,omitempty"` // For number types
Max *float64 `yaml:"max,omitempty"` // For number types
Derived string `yaml:"derived,omitempty"` // How to compute value
Positional bool `yaml:"positional,omitempty"` // For traits: positional argument
}
FieldDefinition defines a field within a type or trait.
type FieldType ¶
type FieldType string
FieldType represents the type of a field.
const ( FieldTypeString FieldType = "string" FieldTypeStringArray FieldType = "string[]" FieldTypeNumber FieldType = "number" FieldTypeNumberArray FieldType = "number[]" FieldTypeURL FieldType = "url" FieldTypeURLArray FieldType = "url[]" FieldTypeDate FieldType = "date" FieldTypeDateArray FieldType = "date[]" FieldTypeDatetime FieldType = "datetime" FieldTypeDatetimeArray FieldType = "datetime[]" FieldTypeEnum FieldType = "enum" FieldTypeEnumArray FieldType = "enum[]" FieldTypeBool FieldType = "bool" FieldTypeBoolArray FieldType = "bool[]" FieldTypeRef FieldType = "ref" FieldTypeRefArray FieldType = "ref[]" )
type FieldValue ¶
type FieldValue struct {
// contains filtered or unexported fields
}
FieldValue represents a parsed field value.
func NewFieldValue ¶
func NewFieldValue(v interface{}) FieldValue
NewFieldValue creates a new FieldValue.
func (FieldValue) AsArray ¶
func (fv FieldValue) AsArray() ([]FieldValue, bool)
AsArray returns the value as an array, if possible.
func (FieldValue) AsBool ¶
func (fv FieldValue) AsBool() (bool, bool)
AsBool returns the value as a boolean, if possible.
func (FieldValue) AsNumber ¶
func (fv FieldValue) AsNumber() (float64, bool)
AsNumber returns the value as a number, if possible.
func (FieldValue) AsRef ¶
func (fv FieldValue) AsRef() (string, bool)
AsRef returns the value as a reference path, if possible.
func (FieldValue) AsString ¶
func (fv FieldValue) AsString() (string, bool)
AsString returns the value as a string, if possible.
func (FieldValue) IsDate ¶
func (fv FieldValue) IsDate() bool
IsDate returns true if this is a date value (YYYY-MM-DD).
func (FieldValue) IsDatetime ¶
func (fv FieldValue) IsDatetime() bool
IsDatetime returns true if this is a datetime value.
func (FieldValue) IsNull ¶
func (fv FieldValue) IsNull() bool
IsNull returns true if the value is null.
func (FieldValue) IsRef ¶
func (fv FieldValue) IsRef() bool
IsRef returns true if this is a reference value.
func (FieldValue) MarshalJSON ¶
func (fv FieldValue) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (FieldValue) Raw ¶
func (fv FieldValue) Raw() interface{}
Raw returns the underlying raw value.
type LoadResult ¶
type LoadResult struct {
Schema *Schema
Warnings []SchemaWarning
}
LoadResult contains the loaded schema and any warnings.
func LoadWithWarnings ¶
func LoadWithWarnings(vaultPath string) (*LoadResult, error)
LoadWithWarnings loads the schema and returns any migration warnings.
type Schema ¶
type Schema struct {
Version int `yaml:"version,omitempty"` // Schema format version
Types map[string]*TypeDefinition `yaml:"types"`
Core map[string]*CoreTypeDefinition `yaml:"core,omitempty"`
Traits map[string]*TraitDefinition `yaml:"traits"`
Templates map[string]*TemplateDefinition `yaml:"templates,omitempty"`
}
Schema represents the complete schema definition loaded from schema.yaml.
type SchemaWarning ¶
type SchemaWarning struct {
Message string
}
SchemaWarning represents a non-fatal schema issue.
type TemplateDefinition ¶
type TemplateDefinition struct {
// File is the template file path under directories.template (e.g., "templates/interview/technical.md").
File string `yaml:"file"`
// Description provides optional context for humans/agents.
Description string `yaml:"description,omitempty"`
}
TemplateDefinition defines a schema-level template that can be bound to one or more types.
type TraitDefinition ¶
type TraitDefinition struct {
// Type is the value type (date, enum, string, boolean, etc.)
// If empty or "boolean", the trait is a marker with no value.
Type FieldType `yaml:"type,omitempty"`
// Values lists valid values for enum types.
Values []string `yaml:"values,omitempty"`
// Default is the default value if none provided.
Default interface{} `yaml:"default,omitempty"`
}
TraitDefinition defines a trait (@due, @priority, @highlight, etc.). Traits are single-valued annotations applied to content.
func (*TraitDefinition) IsBoolean ¶
func (td *TraitDefinition) IsBoolean() bool
IsBoolean returns true if this trait is a boolean/marker trait.
type TypeDefinition ¶
type TypeDefinition struct {
Fields map[string]*FieldDefinition `yaml:"fields"`
DefaultPath string `yaml:"default_path,omitempty"`
// Description provides optional context for humans/agents about this type's purpose.
Description string `yaml:"description,omitempty"`
// NameField specifies which field serves as the display name for this type.
// When set, the title argument to `rvn new` will auto-populate this field.
// The field must be a string type. If the field doesn't exist, it will be
// auto-created as a required string field.
NameField string `yaml:"name_field,omitempty"`
// Template is a path to a template file (e.g., "templates/meeting.md").
// Deprecated: use Schema.Templates + TypeDefinition.Templates + DefaultTemplate.
Template string `yaml:"template,omitempty"`
// Templates lists template IDs from the schema-level templates map that this type can use.
Templates []string `yaml:"templates,omitempty"`
// DefaultTemplate selects the template ID from Templates that is applied by default.
// If empty, object creation proceeds without a template unless explicitly selected.
DefaultTemplate string `yaml:"default_template,omitempty"`
}
TypeDefinition defines a type (person, meeting, project, etc.).
type ValidationError ¶
ValidationError represents a field validation error.
func ValidateFields ¶
func ValidateFields(fields map[string]FieldValue, fieldDefs map[string]*FieldDefinition, schema *Schema) []ValidationError
ValidateFields validates a set of fields against a type's field definitions.
func (ValidationError) Error ¶
func (e ValidationError) Error() string