Documentation ¶
Index ¶
- Constants
- Variables
- func AliasKindStrings() []string
- func DataToJSONSchema(schema *Schema, dataRef DataRef) (*jsonschema.Schema, error)
- func ModuleToBytes(m *Module) ([]byte, error)
- func Normalise[T Node](n T) T
- func ProtobufSchema() string
- func TypeName(v any) string
- func ValidateModule(module *Module) error
- func ValidateName(name string) bool
- func Visit(n Node, visit func(n Node, next func() error) error) error
- type AbstractRef
- type AliasKind
- type Any
- type Array
- type Bool
- type Bytes
- type Config
- type ConfigRef
- type Data
- type DataRef
- type Database
- type Decl
- type Enum
- type EnumRef
- type EnumVariant
- type Field
- type Float
- type IngressPathComponent
- type IngressPathLiteral
- type IngressPathParameter
- type Int
- type IntValue
- type Map
- type Metadata
- type MetadataAlias
- type MetadataCalls
- type MetadataDatabases
- type MetadataIngress
- type Module
- func Builtins() *Module
- func ModuleFromBytes(b []byte) (*Module, error)
- func ModuleFromProto(s *schemapb.Module) (*Module, error)
- func ModuleFromProtoFile(filename string) (*Module, error)
- func ParseModule(filename string, r io.Reader) (*Module, error)
- func ParseModuleString(filename, input string) (*Module, error)
- func (m *Module) AddData(data *Data) int
- func (m *Module) Data() []*Data
- func (m *Module) GetName() string
- func (m *Module) Imports() []string
- func (m *Module) Position() Position
- func (m *Module) Resolve(ref Ref) *ModuleDecl
- func (m *Module) Scan(src any) error
- func (m *Module) Scope() Scope
- func (m *Module) String() string
- func (m *Module) ToProto() proto.Message
- func (m *Module) Value() (driver.Value, error)
- func (m *Module) Verbs() []*Verb
- type ModuleDecl
- type Node
- type Optional
- type Position
- type Ref
- type RefProto
- type Resolver
- type Schema
- func (s *Schema) DataMap() map[Ref]*Data
- func (s *Schema) Hash() [sha256.Size]byte
- func (s *Schema) Module(name string) optional.Option[*Module]
- func (s *Schema) Position() Position
- func (s *Schema) ResolveDataRef(ref *DataRef) *Data
- func (s *Schema) ResolveDataRefMonomorphised(ref *DataRef) (*Data, error)
- func (s *Schema) ResolveEnumRef(ref *EnumRef) *Enum
- func (s *Schema) ResolveVerbRef(ref *VerbRef) *Verb
- func (s *Schema) String() string
- func (s *Schema) ToProto() proto.Message
- func (s *Schema) Upsert(module *Module)
- type Scope
- type Scoped
- type Scopes
- type Secret
- type SecretRef
- type SinkRef
- type SourceRef
- type String
- type StringValue
- type Time
- type Type
- type TypeParameter
- type Unit
- type Value
- type Verb
- type VerbRef
Constants ¶
const BuiltinsSource = `` /* 539-byte string literal not displayed */
BuiltinsSource is the schema source code for built-in types.
Variables ¶
var (
Lexer = lexer.MustSimple([]lexer.SimpleRule{
{Name: "Whitespace", Pattern: `\s+`},
{Name: "Ident", Pattern: `\b[a-zA-Z_][a-zA-Z0-9_]*\b`},
{Name: "Comment", Pattern: `//.*`},
{Name: "String", Pattern: `"(?:\\.|[^"])*"`},
{Name: "Number", Pattern: `[0-9]+(?:\.[0-9]+)?`},
{Name: "Punct", Pattern: `[%/\-\_:[\]{}<>()*+?.,\\^$|#~!\'@]`},
})
)
Functions ¶
func AliasKindStrings ¶ added in v0.139.2
func AliasKindStrings() []string
AliasKindStrings returns a slice of all String values of the enum
func DataToJSONSchema ¶ added in v0.1.1
DataToJSONSchema converts the schema for a Data object to a JSON Schema.
It takes in the full schema in order to resolve and define references.
func ModuleToBytes ¶ added in v0.111.2
func Normalise ¶
func Normalise[T Node](n T) T
Normalise clones and normalises (zeroes) positional information in schema Nodes.
func ProtobufSchema ¶
func ProtobufSchema() string
ProtobufSchema returns a string containing the equivalent protobuf schema for the FTL schema.
func ValidateModule ¶
ValidateModule performs the subset of semantic validation possible on a single module.
It ignores references to other modules.
func ValidateName ¶ added in v0.99.0
ValidateName validates an FTL name.
Types ¶
type AbstractRef ¶ added in v0.93.0
AbstractRef is an abstract reference to a function or data type.
func (*AbstractRef[Proto]) Position ¶ added in v0.100.0
func (a *AbstractRef[Proto]) Position() Position
func (*AbstractRef[Proto]) String ¶ added in v0.93.0
func (a *AbstractRef[Proto]) String() string
func (*AbstractRef[Proto]) ToProto ¶ added in v0.93.0
func (a *AbstractRef[Proto]) ToProto() proto.Message
func (*AbstractRef[Proto]) Untyped ¶ added in v0.100.0
func (a *AbstractRef[Proto]) Untyped() Ref
Untyped converts a typed reference to an untyped reference.
type AliasKind ¶ added in v0.139.2
type AliasKind int
AliasKind is the kind of alias.
func AliasKindString ¶ added in v0.139.2
AliasKindString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func AliasKindValues ¶ added in v0.139.2
func AliasKindValues() []AliasKind
AliasKindValues returns all values of the enum
func (AliasKind) IsAAliasKind ¶ added in v0.139.2
IsAAliasKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (AliasKind) MarshalJSON ¶ added in v0.139.2
MarshalJSON implements the json.Marshaler interface for AliasKind
func (AliasKind) MarshalText ¶ added in v0.139.2
MarshalText implements the encoding.TextMarshaler interface for AliasKind
func (*AliasKind) UnmarshalJSON ¶ added in v0.139.2
UnmarshalJSON implements the json.Unmarshaler interface for AliasKind
func (*AliasKind) UnmarshalText ¶ added in v0.139.2
UnmarshalText implements the encoding.TextUnmarshaler interface for AliasKind
type Any ¶ added in v0.100.0
type Array ¶
type Bool ¶
type Bytes ¶ added in v0.88.0
type Config ¶ added in v0.146.0
type Config struct { Pos Position `parser:"" protobuf:"1,optional"` Name string `parser:"'config' @Ident" protobuf:"2"` Type Type `parser:"@@" protobuf:"3"` }
func ConfigFromProto ¶ added in v0.146.3
func (*Config) ToProto ¶ added in v0.146.0
func (s *Config) ToProto() protoreflect.ProtoMessage
type ConfigRef ¶ added in v0.146.0
type ConfigRef = AbstractRef[schemapb.ConfigRef]
ConfigRef is a reference to a Config.
func ConfigRefFromProto ¶ added in v0.146.0
func ParseConfigRef ¶ added in v0.146.0
type Data ¶
type Data struct { Pos Position `parser:"" protobuf:"1,optional"` Comments []string `parser:"@Comment*" protobuf:"2"` Name string `parser:"'data' @Ident" protobuf:"3"` TypeParameters []*TypeParameter `parser:"( '<' @@ (',' @@)* '>' )?" protobuf:"6"` Fields []*Field `parser:"'{' @@* '}'" protobuf:"4"` Metadata []Metadata `parser:"@@*" protobuf:"5"` }
A Data structure.
func DataFromProto ¶ added in v0.136.0
func (*Data) FieldByName ¶ added in v0.122.0
func (*Data) Monomorphise ¶ added in v0.104.0
Monomorphise this data type with the given type arguments.
If this data type has no type parameters, it will be returned as-is.
This will return a new Data structure with all type parameters replaced with the given types.
type DataRef ¶
type DataRef struct { Pos Position `parser:"" protobuf:"1,optional"` Module string `parser:"(@Ident '.')?" protobuf:"3"` Name string `parser:"@Ident" protobuf:"2"` TypeParameters []Type `parser:"[ '<' @@ (',' @@)* '>' ]" protobuf:"4"` }
DataRef is a reference to a data structure.
func DataRefFromProto ¶ added in v0.93.0
func ParseDataRef ¶ added in v0.93.0
func (*DataRef) ToProto ¶
func (d *DataRef) ToProto() protoreflect.ProtoMessage
type Database ¶ added in v0.95.0
type Database struct { Pos Position `parser:"" protobuf:"1,optional"` Comments []string `parser:"@Comment*" protobuf:"3"` Name string `parser:"'database' @Ident" protobuf:"2"` }
func DatabaseFromProto ¶ added in v0.136.0
type Enum ¶ added in v0.136.0
type Enum struct { Pos Position `parser:"" protobuf:"1,optional"` Comments []string `parser:"@Comment*" protobuf:"2"` Name string `parser:"'enum' @Ident" protobuf:"3"` Type Type `parser:"'(' @@ ')'" protobuf:"4"` Variants []*EnumVariant `parser:"'{' @@* '}'" protobuf:"5"` }
func EnumFromProto ¶ added in v0.136.0
type EnumRef ¶ added in v0.136.0
type EnumRef = AbstractRef[schemapb.EnumRef]
EnumRef is a reference to an Enum.
func EnumRefFromProto ¶ added in v0.136.0
func ParseEnumRef ¶ added in v0.136.0
type EnumVariant ¶ added in v0.136.0
type EnumVariant struct { Pos Position `parser:"" protobuf:"1,optional"` Name string `parser:"@Ident" protobuf:"2"` Value Value `parser:"'(' @@ ')'" protobuf:"3"` }
func (*EnumVariant) Position ¶ added in v0.136.0
func (e *EnumVariant) Position() Position
func (*EnumVariant) String ¶ added in v0.136.0
func (e *EnumVariant) String() string
func (*EnumVariant) ToProto ¶ added in v0.136.0
func (e *EnumVariant) ToProto() proto.Message
type Field ¶
type Field struct { Pos Position `parser:"" protobuf:"1,optional"` Comments []string `parser:"@Comment*" protobuf:"3"` Name string `parser:"@Ident" protobuf:"2"` Type Type `parser:"@@" protobuf:"4"` Metadata []Metadata `parser:"@@*" protobuf:"5"` }
type Float ¶
type IngressPathComponent ¶ added in v0.85.5
type IngressPathComponent interface { Node // contains filtered or unexported methods }
type IngressPathLiteral ¶ added in v0.85.5
type IngressPathLiteral struct { Pos Position `parser:"" protobuf:"1,optional"` Text string `parser:"@~(Whitespace | '/' | '{' | '}')+" protobuf:"2"` }
func (*IngressPathLiteral) Position ¶ added in v0.100.0
func (l *IngressPathLiteral) Position() Position
func (*IngressPathLiteral) String ¶ added in v0.85.5
func (l *IngressPathLiteral) String() string
func (*IngressPathLiteral) ToProto ¶ added in v0.85.5
func (l *IngressPathLiteral) ToProto() proto.Message
type IngressPathParameter ¶ added in v0.85.5
type IngressPathParameter struct { Pos Position `parser:"" protobuf:"1,optional"` Name string `parser:"'{' @Ident '}'" protobuf:"2"` }
func (*IngressPathParameter) Position ¶ added in v0.100.0
func (l *IngressPathParameter) Position() Position
func (*IngressPathParameter) String ¶ added in v0.85.5
func (l *IngressPathParameter) String() string
func (*IngressPathParameter) ToProto ¶ added in v0.85.5
func (l *IngressPathParameter) ToProto() proto.Message
type Int ¶
type IntValue ¶ added in v0.136.0
type Map ¶
type Metadata ¶
type Metadata interface { Node // contains filtered or unexported methods }
Metadata represents a metadata Node in the schema grammar.
type MetadataAlias ¶ added in v0.139.2
type MetadataAlias struct { Pos Position `parser:"" protobuf:"1,optional"` Kind AliasKind `parser:"'+' 'alias' @Ident" protobuf:"2"` Alias string `parser:"@String" protobuf:"3"` }
func (*MetadataAlias) Position ¶ added in v0.139.2
func (m *MetadataAlias) Position() Position
func (*MetadataAlias) String ¶ added in v0.139.2
func (m *MetadataAlias) String() string
func (*MetadataAlias) ToProto ¶ added in v0.139.2
func (m *MetadataAlias) ToProto() protoreflect.ProtoMessage
type MetadataCalls ¶
type MetadataCalls struct { Pos Position `parser:"" protobuf:"1,optional"` Calls []*VerbRef `parser:"'+' 'calls' @@ (',' @@)*" protobuf:"2"` }
func (*MetadataCalls) Position ¶ added in v0.100.0
func (m *MetadataCalls) Position() Position
func (*MetadataCalls) String ¶
func (m *MetadataCalls) String() string
func (*MetadataCalls) ToProto ¶
func (m *MetadataCalls) ToProto() proto.Message
type MetadataDatabases ¶ added in v0.95.0
type MetadataDatabases struct { Pos Position `parser:"" protobuf:"1,optional"` Calls []*Database `parser:"'+' 'database' 'calls' @@ (',' @@)*" protobuf:"2"` }
func (*MetadataDatabases) Position ¶ added in v0.100.0
func (m *MetadataDatabases) Position() Position
func (*MetadataDatabases) String ¶ added in v0.95.0
func (m *MetadataDatabases) String() string
func (*MetadataDatabases) ToProto ¶ added in v0.95.0
func (m *MetadataDatabases) ToProto() proto.Message
type MetadataIngress ¶
type MetadataIngress struct { Pos Position `parser:"" protobuf:"1,optional"` Type string `parser:"'+' 'ingress' @('http')?" protobuf:"2"` Method string `parser:"@('GET' | 'POST' | 'PUT' | 'DELETE')" protobuf:"3"` Path []IngressPathComponent `parser:"('/' @@)+" protobuf:"4"` }
func (*MetadataIngress) Position ¶ added in v0.100.0
func (m *MetadataIngress) Position() Position
func (*MetadataIngress) String ¶
func (m *MetadataIngress) String() string
func (*MetadataIngress) ToProto ¶
func (m *MetadataIngress) ToProto() proto.Message
type Module ¶
type Module struct { Pos Position `parser:"" protobuf:"1,optional"` Comments []string `parser:"@Comment*" protobuf:"2"` Builtin bool `parser:"@'builtin'?" protobuf:"3"` Name string `parser:"'module' @Ident '{'" protobuf:"4"` Decls []Decl `parser:"@@* '}'" protobuf:"5"` }
func Builtins ¶ added in v0.89.0
func Builtins() *Module
Builtins returns a Module containing built-in types.
func ModuleFromBytes ¶
func ModuleFromProto ¶
ModuleFromProto converts a protobuf Module to a Module and validates it.
func ModuleFromProtoFile ¶ added in v0.134.1
ModuleFromProtoFile loads a module from the given proto-encoded file.
func ParseModuleString ¶
func (*Module) Resolve ¶ added in v0.100.0
func (m *Module) Resolve(ref Ref) *ModuleDecl
Resolve returns the declaration in this module with the given name, or nil
type ModuleDecl ¶ added in v0.100.0
ModuleDecl is a declaration associated with a module.
type Node ¶
type Node interface { String() string ToProto() proto.Message Position() Position // contains filtered or unexported methods }
A Node in the schema grammar.
type Optional ¶ added in v0.78.0
type Optional struct { Pos Position `parser:"" protobuf:"1,optional"` Type Type `parser:"@@" protobuf:"2,optional"` }
Optional represents a Type whose value may be optional.
type Position ¶
type Ref ¶
type Ref struct { Pos Position `parser:"" protobuf:"1,optional"` Module string `parser:"(@Ident '.')?" protobuf:"3"` Name string `parser:"@Ident" protobuf:"2"` }
Ref is an untyped reference to a symbol.
type RefProto ¶ added in v0.93.0
type RefProto interface { schemapb.VerbRef | schemapb.DataRef | schemapb.SinkRef | schemapb.SourceRef | schemapb.EnumRef | schemapb.SecretRef | schemapb.ConfigRef }
RefProto is a constraint on the type of proto that can be used in a Ref.
type Resolver ¶ added in v0.100.0
type Resolver interface { // Resolve a reference to a symbol declaration or nil. Resolve(ref Ref) *ModuleDecl }
Resolver may be implemented be a node in the AST to resolve references within itself.
type Schema ¶
type Schema struct { Pos Position `parser:"" protobuf:"1,optional"` Modules []*Module `parser:"@@*" protobuf:"2"` }
func MustValidate ¶ added in v0.89.0
MustValidate panics if a schema is invalid.
This is useful for testing.
func ParseString ¶
func (*Schema) ResolveDataRef ¶ added in v0.80.0
func (*Schema) ResolveDataRefMonomorphised ¶ added in v0.113.0
func (*Schema) ResolveEnumRef ¶ added in v0.144.0
func (*Schema) ResolveVerbRef ¶ added in v0.80.0
type Scope ¶ added in v0.100.0
type Scope map[string]ModuleDecl
Scope maps relative names to fully qualified types.
type Scoped ¶ added in v0.101.0
type Scoped interface {
Scope() Scope
}
Scoped is implemented by nodes that wish to introduce a new scope.
type Scopes ¶ added in v0.100.0
type Scopes []Scope
Scopes to search during type resolution.
func NewScopes ¶ added in v0.100.0
func NewScopes() Scopes
NewScopes constructs a new type resolution stack with builtins pre-populated.
func (Scopes) Push ¶ added in v0.100.0
Push a new Scope onto the stack.
This contains references to previous Scopes so that updates are preserved.
func (Scopes) Resolve ¶ added in v0.100.0
func (s Scopes) Resolve(ref Ref) *ModuleDecl
Resolve a reference to a symbol declaration or nil.
type Secret ¶ added in v0.146.0
type Secret struct { Pos Position `parser:"" protobuf:"1,optional"` Name string `parser:"'secret' @Ident" protobuf:"2"` Type Type `parser:"@@" protobuf:"3"` }
func SecretFromProto ¶ added in v0.146.3
func (*Secret) ToProto ¶ added in v0.146.0
func (s *Secret) ToProto() protoreflect.ProtoMessage
type SecretRef ¶ added in v0.146.0
type SecretRef = AbstractRef[schemapb.SecretRef]
SecretRef is a reference to a Secret.
func ParseSecretRef ¶ added in v0.146.0
func SecretRefFromProto ¶ added in v0.146.0
type SinkRef ¶ added in v0.93.0
type SinkRef = AbstractRef[schemapb.SinkRef]
SinkRef is a reference to a Sink.
func ParseSinkRef ¶ added in v0.93.0
func SinkRefFromProto ¶ added in v0.93.0
type SourceRef ¶ added in v0.93.0
type SourceRef = AbstractRef[schemapb.SourceRef]
SourceRef is a reference to a Source.
func ParseSourceRef ¶ added in v0.93.0
func SourceRefFromProto ¶ added in v0.93.0
type String ¶
type StringValue ¶ added in v0.136.0
type StringValue struct { Pos Position `parser:"" protobuf:"1,optional"` Value string `parser:"@String" protobuf:"2"` }
func (*StringValue) Position ¶ added in v0.136.0
func (s *StringValue) Position() Position
func (*StringValue) String ¶ added in v0.136.0
func (s *StringValue) String() string
func (*StringValue) ToProto ¶ added in v0.136.0
func (s *StringValue) ToProto() proto.Message
type Time ¶
type Type ¶
type Type interface { Node // contains filtered or unexported methods }
Type represents a Type Node in the schema grammar.
type TypeParameter ¶ added in v0.101.0
type TypeParameter struct { Pos Position `parser:"" protobuf:"1,optional"` Name string `parser:"@Ident" protobuf:"2"` }
func (*TypeParameter) GetName ¶ added in v0.140.0
func (t *TypeParameter) GetName() string
func (*TypeParameter) Position ¶ added in v0.101.0
func (t *TypeParameter) Position() Position
func (*TypeParameter) String ¶ added in v0.101.0
func (t *TypeParameter) String() string
func (*TypeParameter) ToProto ¶ added in v0.101.0
func (t *TypeParameter) ToProto() protoreflect.ProtoMessage
type Unit ¶ added in v0.94.0
type Unit struct { Pos Position `parser:"" protobuf:"1,optional"` Unit bool `parser:"@'Unit'" protobuf:"-"` }
func (*Unit) ToProto ¶ added in v0.94.0
func (u *Unit) ToProto() protoreflect.ProtoMessage
type Value ¶ added in v0.136.0
type Value interface { Node // contains filtered or unexported methods }
Value represents a value Node in the schema grammar.
type Verb ¶
type Verb struct { Pos Position `parser:"" protobuf:"1,optional"` Comments []string `parser:"@Comment*" protobuf:"3"` Name string `parser:"'verb' @Ident" protobuf:"2"` Request Type `parser:"'(' @@ ')'" protobuf:"4"` Response Type `parser:"@@" protobuf:"5"` Metadata []Metadata `parser:"@@*" protobuf:"6"` }
func VerbFromProto ¶ added in v0.136.0
func (*Verb) GetMetadataIngress ¶ added in v0.91.0
func (v *Verb) GetMetadataIngress() optional.Option[*MetadataIngress]
type VerbRef ¶
type VerbRef = AbstractRef[schemapb.VerbRef]
VerbRef is a reference to a Verb.
func ParseVerbRef ¶ added in v0.93.0
func VerbRefFromProto ¶
Source Files ¶
- aliaskind_enumer.go
- any.go
- array.go
- bool.go
- builtin.go
- bytes.go
- config.go
- configref.go
- data.go
- database.go
- dataref.go
- encoding.go
- enum.go
- enumref.go
- field.go
- float.go
- int.go
- intvalue.go
- jsonschema.go
- map.go
- metadataalias.go
- metadatacalls.go
- metadatadatabases.go
- metadataingress.go
- module.go
- normalise.go
- optional.go
- parser.go
- protobuf.go
- protobuf_dec.go
- protobuf_enc.go
- refs.go
- schema.go
- secret.go
- secretref.go
- sinkref.go
- sourceref.go
- string.go
- stringvalue.go
- time.go
- typeparameter.go
- typeresolver.go
- unit.go
- validate.go
- verb.go
- verbref.go
- visit.go