Documentation ¶
Index ¶
- Constants
- Variables
- func TypeName(typeDef Type) string
- type Argument
- type ArrayType
- type Assignment
- type AssignmentConstraint
- type AssignmentEnvelope
- type AssignmentMethod
- type AssignmentNilCheck
- type AssignmentOpt
- type AssignmentValue
- type Builder
- type BuilderGenerator
- type BuilderVisitor
- func (visitor *BuilderVisitor) TraverseBuilder(schemas Schemas, builder Builder) (Builder, error)
- func (visitor *BuilderVisitor) TraverseConstructor(schemas Schemas, builder Builder, constructor Constructor) (Constructor, error)
- func (visitor *BuilderVisitor) TraverseOption(schemas Schemas, builder Builder, option Option) (Option, error)
- func (visitor *BuilderVisitor) Visit(schemas Schemas, builders Builders) (Builders, error)
- func (visitor *BuilderVisitor) VisitArgument(schemas Schemas, builder Builder, argument Argument) (Argument, error)
- func (visitor *BuilderVisitor) VisitAssignment(schemas Schemas, builder Builder, assignment Assignment) (Assignment, error)
- func (visitor *BuilderVisitor) VisitBuilder(schemas Schemas, builder Builder) (Builder, error)
- func (visitor *BuilderVisitor) VisitConstructor(schemas Schemas, builder Builder, constructor Constructor) (Constructor, error)
- func (visitor *BuilderVisitor) VisitOption(schemas Schemas, builder Builder, option Option) (Option, error)
- func (visitor *BuilderVisitor) VisitProperty(schemas Schemas, builder Builder, property StructField) (StructField, error)
- type Builders
- func (builders Builders) ByPackage(pkg string) Builders
- func (builders Builders) HaveConstantConstructorAssignment() bool
- func (builders Builders) LocateAllByObject(pkg string, name string) Builders
- func (builders Builders) LocateAllByRef(ref RefType) Builders
- func (builders Builders) LocateByObject(pkg string, name string) (Builder, bool)
- type ComposableSlotType
- type Constructor
- type DisjunctionType
- type EnumType
- type EnumValue
- type EnvelopeFieldValue
- type IntersectionType
- type JenniesHints
- type Kind
- type MapType
- type Object
- type Op
- type Option
- type OptionDefault
- type Path
- type PathIndex
- type PathItem
- type RefType
- type ScalarKind
- type ScalarType
- type Schema
- func (schema *Schema) AddObject(object Object)
- func (schema *Schema) AddObjects(objects ...Object)
- func (schema *Schema) DeepCopy() Schema
- func (schema *Schema) HasObject(name string) bool
- func (schema *Schema) IsComposableVariant(variant string) bool
- func (schema *Schema) LocateObject(name string) (Object, bool)
- func (schema *Schema) Merge(other *Schema) error
- func (schema *Schema) Resolve(typeDef Type) (Type, bool)
- type SchemaKind
- type SchemaMeta
- type SchemaVariant
- type Schemas
- func (schemas Schemas) Consolidate() (Schemas, error)
- func (schemas Schemas) DeepCopy() []*Schema
- func (schemas Schemas) Locate(pkg string) (*Schema, bool)
- func (schemas Schemas) LocateObject(pkg string, name string) (Object, bool)
- func (schemas Schemas) LocateObjectByRef(ref RefType) (Object, bool)
- func (schemas Schemas) ResolveToType(def Type) Type
- type StructField
- type StructFieldOption
- type StructType
- type Type
- func Any(opts ...TypeOption) Type
- func Bool(opts ...TypeOption) Type
- func Bytes(opts ...TypeOption) Type
- func NewArray(valueType Type, opts ...TypeOption) Type
- func NewComposableSlot(variant SchemaVariant) Type
- func NewDisjunction(branches Types, opts ...TypeOption) Type
- func NewEnum(values []EnumValue, opts ...TypeOption) Type
- func NewIntersection(branches []Type) Type
- func NewMap(indexType Type, valueType Type, opts ...TypeOption) Type
- func NewRef(referredPkg string, referredTypeName string, opts ...TypeOption) Type
- func NewScalar(kind ScalarKind, opts ...TypeOption) Type
- func NewStruct(fields ...StructField) Type
- func Null() Type
- func String(opts ...TypeOption) Type
- func (t *Type) AcceptsValue(value any) bool
- func (t *Type) AddToPassesTrail(trail string)
- func (t Type) AsArray() ArrayType
- func (t Type) AsComposableSlot() ComposableSlotType
- func (t Type) AsDisjunction() DisjunctionType
- func (t Type) AsEnum() EnumType
- func (t Type) AsIntersection() IntersectionType
- func (t Type) AsMap() MapType
- func (t Type) AsRef() RefType
- func (t Type) AsScalar() ScalarType
- func (t Type) AsStruct() StructType
- func (t Type) DeepCopy() Type
- func (t Type) HasHint(hintName string) bool
- func (t Type) ImplementedVariant() string
- func (t Type) ImplementsVariant() bool
- func (t Type) IsAny() bool
- func (t Type) IsAnyOf(kinds ...Kind) bool
- func (t Type) IsArray() bool
- func (t Type) IsComposableSlot() bool
- func (t Type) IsConcreteScalar() bool
- func (t Type) IsDataqueryComposableSlot() bool
- func (t Type) IsDataqueryVariant() bool
- func (t Type) IsDisjunction() bool
- func (t Type) IsDisjunctionOfRefs() bool
- func (t Type) IsDisjunctionOfScalars() bool
- func (t Type) IsEnum() bool
- func (t Type) IsIntersection() bool
- func (t Type) IsMap() bool
- func (t Type) IsNull() bool
- func (t Type) IsRef() bool
- func (t Type) IsScalar() bool
- func (t Type) IsStruct() bool
- func (t Type) IsStructGeneratedFromDisjunction() bool
- func (t Type) IsStructOrRef() bool
- type TypeConstraint
- type TypeOption
- type Types
- type VisitArgumentFunc
- type VisitAssignmentFunc
- type VisitBuilderFunc
- type VisitConstructorFunc
- type VisitOptionFunc
- type VisitPropertyFunc
Constants ¶
View Source
const ( // HintDisjunctionOfScalars indicates that the struct was previously // represented in the IR by a disjunction of scalars (+ array), the // original definition of which is associated to this hint. HintDisjunctionOfScalars = "disjunction_of_scalars" // HintDiscriminatedDisjunctionOfRefs indicates that the struct was // previously represented in the IR by a disjunction of a fixed list of // references to structs, the original definition of which is associated // to this hint. HintDiscriminatedDisjunctionOfRefs = "disjunction_of_refs" // HintImplementsVariant indicates that a type implements a variant. // ie: dataquery, panelcfg, ... HintImplementsVariant = "implements_variant" // HintSkipVariantPluginRegistration preserves the variant hint on a type, but // tells the jennies to not register it as a plugin. HintSkipVariantPluginRegistration = "skip_variant_plugin_registration" // HintStringFormatDateTime hints refers to a string that should be formatted // as a datetime as defined by RFC 3339, section 5.6 (ex: 2017-07-21T17:32:28Z) HintStringFormatDateTime = "string_format_datetime" )
View Source
const DiscriminatorCatchAll = "cog_discriminator_catch_all"
Variables ¶
View Source
var ErrCannotMergeSchemas = errors.New("can not merge schemas")
Functions ¶
Types ¶
type ArrayType ¶
type ArrayType struct {
ValueType Type `yaml:"value_type"`
}
func (*ArrayType) AcceptsValue ¶ added in v0.0.20
func (ArrayType) IsArrayOfScalars ¶
type Assignment ¶
type Assignment struct { // Where Path Path // What Value AssignmentValue // How Method AssignmentMethod Constraints []AssignmentConstraint `json:",omitempty"` NilChecks []AssignmentNilCheck `json:",omitempty"` }
func ArgumentAssignment ¶
func ArgumentAssignment(path Path, argument Argument, opts ...AssignmentOpt) Assignment
func ConstantAssignment ¶
func ConstantAssignment(path Path, value any, opts ...AssignmentOpt) Assignment
func FieldAssignment ¶
func FieldAssignment(field StructField, opts ...AssignmentOpt) Assignment
func (*Assignment) DeepCopy ¶
func (assignment *Assignment) DeepCopy() Assignment
func (*Assignment) HasConstantValue ¶
func (assignment *Assignment) HasConstantValue() bool
type AssignmentConstraint ¶
func (AssignmentConstraint) DeepCopy ¶
func (constraint AssignmentConstraint) DeepCopy() AssignmentConstraint
type AssignmentEnvelope ¶
type AssignmentEnvelope struct { Type Type // Should be a ref or a struct only Values []EnvelopeFieldValue }
func (*AssignmentEnvelope) DeepCopy ¶
func (envelope *AssignmentEnvelope) DeepCopy() AssignmentEnvelope
type AssignmentMethod ¶
type AssignmentMethod string
const ( DirectAssignment AssignmentMethod = "direct" // `foo = bar` AppendAssignment AssignmentMethod = "append" // `foo = append(foo, bar)` IndexAssignment AssignmentMethod = "index" // `foo[key] = bar` )
type AssignmentNilCheck ¶
func (*AssignmentNilCheck) DeepCopy ¶
func (check *AssignmentNilCheck) DeepCopy() AssignmentNilCheck
type AssignmentOpt ¶
type AssignmentOpt func(assignment *Assignment)
func Method ¶
func Method(method AssignmentMethod) AssignmentOpt
func WithTypeConstraints ¶
func WithTypeConstraints(constraints []TypeConstraint) AssignmentOpt
type AssignmentValue ¶
type AssignmentValue struct { Argument *Argument `json:",omitempty"` Constant any `json:",omitempty"` Envelope *AssignmentEnvelope `json:",omitempty"` }
func (*AssignmentValue) DeepCopy ¶
func (value *AssignmentValue) DeepCopy() AssignmentValue
type Builder ¶
type Builder struct { For Object // The builder itself // These fields are completely derived from the fields above and can be freely manipulated // by veneers. Package string Name string Properties []StructField `json:",omitempty"` Constructor Constructor `json:",omitempty"` Options []Option VeneerTrail []string `json:",omitempty"` }
func (*Builder) AddToVeneerTrail ¶
type BuilderGenerator ¶
type BuilderGenerator struct { }
func (*BuilderGenerator) FromAST ¶
func (generator *BuilderGenerator) FromAST(schemas Schemas) []Builder
type BuilderVisitor ¶
type BuilderVisitor struct { OnBuilder VisitBuilderFunc OnProperty VisitPropertyFunc OnConstructor VisitConstructorFunc OnOption VisitOptionFunc OnArgument VisitArgumentFunc OnAssignment VisitAssignmentFunc }
func (*BuilderVisitor) TraverseBuilder ¶
func (visitor *BuilderVisitor) TraverseBuilder(schemas Schemas, builder Builder) (Builder, error)
func (*BuilderVisitor) TraverseConstructor ¶
func (visitor *BuilderVisitor) TraverseConstructor(schemas Schemas, builder Builder, constructor Constructor) (Constructor, error)
func (*BuilderVisitor) TraverseOption ¶
func (*BuilderVisitor) Visit ¶
func (visitor *BuilderVisitor) Visit(schemas Schemas, builders Builders) (Builders, error)
func (*BuilderVisitor) VisitArgument ¶
func (*BuilderVisitor) VisitAssignment ¶
func (visitor *BuilderVisitor) VisitAssignment(schemas Schemas, builder Builder, assignment Assignment) (Assignment, error)
func (*BuilderVisitor) VisitBuilder ¶
func (visitor *BuilderVisitor) VisitBuilder(schemas Schemas, builder Builder) (Builder, error)
func (*BuilderVisitor) VisitConstructor ¶
func (visitor *BuilderVisitor) VisitConstructor(schemas Schemas, builder Builder, constructor Constructor) (Constructor, error)
func (*BuilderVisitor) VisitOption ¶
func (*BuilderVisitor) VisitProperty ¶
func (visitor *BuilderVisitor) VisitProperty(schemas Schemas, builder Builder, property StructField) (StructField, error)
type Builders ¶
type Builders []Builder
func (Builders) HaveConstantConstructorAssignment ¶
func (Builders) LocateAllByObject ¶
func (Builders) LocateAllByRef ¶ added in v0.0.8
type ComposableSlotType ¶
type ComposableSlotType struct {
Variant SchemaVariant
}
func (ComposableSlotType) DeepCopy ¶
func (slot ComposableSlotType) DeepCopy() ComposableSlotType
type Constructor ¶
type Constructor struct { Args []Argument `json:",omitempty"` Assignments []Assignment `json:",omitempty"` }
func (*Constructor) DeepCopy ¶
func (constructor *Constructor) DeepCopy() Constructor
type DisjunctionType ¶
type DisjunctionType struct { Branches Types // If the branches are references to structs, some languages will need // extra context to be able to distinguish between them. Golang, for // example, doesn't support sum types (disjunctions of fixed types). // To emulate sum types for these languages, we need a way to // discriminate against every possible type. // // To do that, we need two things: // - a discriminator: the name of a field that is present in all types. // The value of which identifies the type being used. // - a mapping: associating a "discriminator value" to a type. Discriminator string `json:",omitempty"` DiscriminatorMapping map[string]string `json:",omitempty" yaml:"discriminator_mapping"` }
func (*DisjunctionType) AcceptsValue ¶ added in v0.0.20
func (t *DisjunctionType) AcceptsValue(value any) bool
func (DisjunctionType) DeepCopy ¶
func (t DisjunctionType) DeepCopy() DisjunctionType
type EnumType ¶
type EnumType struct {
Values []EnumValue // possible values. Value types might be different
}
func (*EnumType) AcceptsValue ¶ added in v0.0.20
type EnvelopeFieldValue ¶
type EnvelopeFieldValue struct { Path Path // where to assign within the struct/ref Value AssignmentValue // what to assign }
func (*EnvelopeFieldValue) DeepCopy ¶
func (value *EnvelopeFieldValue) DeepCopy() EnvelopeFieldValue
type IntersectionType ¶
type IntersectionType struct {
Branches []Type
}
func (IntersectionType) DeepCopy ¶
func (inter IntersectionType) DeepCopy() IntersectionType
type JenniesHints ¶
meant to be used by jennies, to gain a finer control on the codegen from schemas
type MapType ¶
func (*MapType) AcceptsValue ¶ added in v0.0.20
type Object ¶
type Object struct { Name string Comments []string `json:",omitempty"` Type Type SelfRef RefType PassesTrail []string `json:",omitempty"` }
named declaration of a type
func (*Object) AddToPassesTrail ¶
type Option ¶
type Option struct { Name string Comments []string `json:",omitempty"` VeneerTrail []string `json:",omitempty"` Args []Argument Assignments []Assignment Default *OptionDefault `json:",omitempty"` }
func (*Option) AddToVeneerTrail ¶
type OptionDefault ¶
type OptionDefault struct {
ArgsValues []any
}
type Path ¶
type Path []PathItem
func PathFromStructField ¶
func PathFromStructField(field StructField) Path
func (Path) AppendStructField ¶
func (path Path) AppendStructField(field StructField) Path
func (Path) RemoveLast ¶ added in v0.0.20
type PathItem ¶
type PathItem struct { Identifier string Index *PathIndex Type Type // any // useful mostly for composability purposes, when a field Type is "any" // and we're trying to "compose in" something of a known type. TypeHint *Type `json:",omitempty"` // Is this element of the path the root? (ie: a variable, not a member of a struct) Root bool }
type RefType ¶
type ScalarKind ¶
type ScalarKind string
const ( KindNull ScalarKind = "null" KindAny ScalarKind = "any" KindBytes ScalarKind = "bytes" KindString ScalarKind = "string" KindFloat32 ScalarKind = "float32" KindFloat64 ScalarKind = "float64" KindUint8 ScalarKind = "uint8" KindUint16 ScalarKind = "uint16" KindUint32 ScalarKind = "uint32" KindUint64 ScalarKind = "uint64" KindInt8 ScalarKind = "int8" KindInt16 ScalarKind = "int16" KindInt32 ScalarKind = "int32" KindInt64 ScalarKind = "int64" KindBool ScalarKind = "bool" )
type ScalarType ¶
type ScalarType struct { ScalarKind ScalarKind `yaml:"scalar_kind"` // bool, bytes, string, int, float, ... Value any `json:",omitempty"` // if value isn't nil, we're representing a constant scalar Constraints []TypeConstraint `json:",omitempty"` }
func (*ScalarType) AcceptsValue ¶ added in v0.0.20
func (scalarType *ScalarType) AcceptsValue(value any) bool
func (ScalarType) DeepCopy ¶
func (scalarType ScalarType) DeepCopy() ScalarType
func (ScalarType) IsConcrete ¶
func (scalarType ScalarType) IsConcrete() bool
type Schema ¶
type Schema struct { Package string Metadata SchemaMeta `json:",omitempty"` EntryPoint string `json:",omitempty"` EntryPointType Type `json:",omitempty"` Objects *orderedmap.Map[string, Object] }
func NewSchema ¶
func NewSchema(pkg string, metadata SchemaMeta) *Schema
func (*Schema) AddObjects ¶
func (*Schema) IsComposableVariant ¶ added in v0.0.13
type SchemaKind ¶
type SchemaKind string
const ( SchemaKindCore SchemaKind = "core" SchemaKindComposable SchemaKind = "composable" )
type SchemaMeta ¶
type SchemaMeta struct { Kind SchemaKind `json:",omitempty"` Variant SchemaVariant `json:",omitempty"` Identifier string `json:",omitempty"` }
func (SchemaMeta) Equal ¶
func (meta SchemaMeta) Equal(other SchemaMeta) bool
type SchemaVariant ¶
type SchemaVariant string
const ( SchemaVariantPanel SchemaVariant = "panelcfg" SchemaVariantDataQuery SchemaVariant = "dataquery" )
type Schemas ¶
type Schemas []*Schema
func (Schemas) Consolidate ¶
func (Schemas) LocateObject ¶
func (Schemas) LocateObjectByRef ¶
func (Schemas) ResolveToType ¶
type StructField ¶
type StructField struct { Name string Comments []string `json:",omitempty"` Type Type Required bool PassesTrail []string `json:",omitempty"` }
func NewStructField ¶
func NewStructField(name string, fieldType Type, opts ...StructFieldOption) StructField
func (*StructField) AddToPassesTrail ¶
func (structField *StructField) AddToPassesTrail(trail string)
func (StructField) DeepCopy ¶
func (structField StructField) DeepCopy() StructField
type StructFieldOption ¶
type StructFieldOption func(field *StructField)
func Comments ¶
func Comments(comments []string) StructFieldOption
func PassesTrail ¶
func PassesTrail(trail string) StructFieldOption
func Required ¶
func Required() StructFieldOption
type StructType ¶
type StructType struct {
Fields []StructField
}
func (StructType) DeepCopy ¶
func (structType StructType) DeepCopy() StructType
func (StructType) FieldByName ¶
func (structType StructType) FieldByName(name string) (StructField, bool)
type Type ¶
type Type struct { Kind Kind Nullable bool Default any `json:",omitempty"` Disjunction *DisjunctionType `json:",omitempty"` Array *ArrayType `json:",omitempty"` Enum *EnumType `json:",omitempty"` Map *MapType `json:",omitempty"` Struct *StructType `json:",omitempty"` Ref *RefType `json:",omitempty"` Scalar *ScalarType `json:",omitempty"` Intersection *IntersectionType `json:",omitempty"` ComposableSlot *ComposableSlotType `json:",omitempty" yaml:"composable_slot"` Hints JenniesHints `json:",omitempty"` PassesTrail []string `json:",omitempty"` }
Struct representing every type defined by the IR. Bonus: in a way that can be (un)marshaled to/from JSON, which is useful for unit tests.
func Any ¶
func Any(opts ...TypeOption) Type
func Bool ¶
func Bool(opts ...TypeOption) Type
func Bytes ¶
func Bytes(opts ...TypeOption) Type
func NewArray ¶
func NewArray(valueType Type, opts ...TypeOption) Type
func NewComposableSlot ¶
func NewComposableSlot(variant SchemaVariant) Type
func NewDisjunction ¶
func NewDisjunction(branches Types, opts ...TypeOption) Type
func NewEnum ¶
func NewEnum(values []EnumValue, opts ...TypeOption) Type
func NewIntersection ¶
func NewScalar ¶
func NewScalar(kind ScalarKind, opts ...TypeOption) Type
func NewStruct ¶
func NewStruct(fields ...StructField) Type
func String ¶
func String(opts ...TypeOption) Type
func (*Type) AcceptsValue ¶ added in v0.0.20
func (*Type) AddToPassesTrail ¶
func (Type) AsComposableSlot ¶
func (t Type) AsComposableSlot() ComposableSlotType
func (Type) AsDisjunction ¶
func (t Type) AsDisjunction() DisjunctionType
func (Type) AsIntersection ¶
func (t Type) AsIntersection() IntersectionType
func (Type) AsScalar ¶
func (t Type) AsScalar() ScalarType
func (Type) AsStruct ¶
func (t Type) AsStruct() StructType
func (Type) ImplementedVariant ¶
func (Type) ImplementsVariant ¶
func (Type) IsComposableSlot ¶
func (Type) IsConcreteScalar ¶
func (Type) IsDataqueryComposableSlot ¶
func (Type) IsDataqueryVariant ¶
func (Type) IsDisjunction ¶
func (Type) IsDisjunctionOfRefs ¶
func (Type) IsDisjunctionOfScalars ¶
func (Type) IsIntersection ¶
func (Type) IsStructGeneratedFromDisjunction ¶
func (Type) IsStructOrRef ¶
type TypeConstraint ¶
func (TypeConstraint) DeepCopy ¶
func (constraint TypeConstraint) DeepCopy() TypeConstraint
type TypeOption ¶
type TypeOption func(def *Type)
func Default ¶
func Default(value any) TypeOption
func Discriminator ¶
func Discriminator(discriminator string, mapping map[string]string) TypeOption
func Hints ¶
func Hints(hints JenniesHints) TypeOption
func Nullable ¶
func Nullable() TypeOption
func Trail ¶
func Trail(trail string) TypeOption
func Value ¶
func Value(value any) TypeOption
type Types ¶
type Types []Type
func (Types) HasNullType ¶
func (Types) HasOnlyRefs ¶
func (Types) HasOnlyScalarOrArrayOrMap ¶
func (Types) NonNullTypes ¶
type VisitArgumentFunc ¶
type VisitAssignmentFunc ¶
type VisitAssignmentFunc func(visitor *BuilderVisitor, schemas Schemas, builder Builder, assignment Assignment) (Assignment, error)
type VisitBuilderFunc ¶
type VisitBuilderFunc func(visitor *BuilderVisitor, schemas Schemas, builder Builder) (Builder, error)
type VisitConstructorFunc ¶
type VisitConstructorFunc func(visitor *BuilderVisitor, schemas Schemas, builder Builder, constructor Constructor) (Constructor, error)
type VisitOptionFunc ¶
type VisitPropertyFunc ¶
type VisitPropertyFunc func(visitor *BuilderVisitor, schemas Schemas, builder Builder, property StructField) (StructField, error)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.