schema

package
v0.95.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinsSource = `` /* 428-byte string literal not displayed */

BuiltinsSource is the schema source code for built-in types.

Functions

func DataToJSONSchema added in v0.1.1

func DataToJSONSchema(schema *Schema, dataRef DataRef) (*jsonschema.Schema, error)

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 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

func ValidateModule(module *Module) error

ValidateModule performs the subset of semantic validation possible on a single module.

func Visit

func Visit(n Node, visit func(n Node, next func() error) error) error

Visit all nodes in the schema.

Types

type AbstractRef added in v0.93.0

type AbstractRef[Proto RefProto] Ref

AbstractRef is an abstract reference to a function or data type.

func ParseRef

func ParseRef[Proto RefProto](ref string) (*AbstractRef[Proto], error)

func (AbstractRef[Proto]) String added in v0.93.0

func (v AbstractRef[Proto]) String() string

func (*AbstractRef[Proto]) ToProto added in v0.93.0

func (v *AbstractRef[Proto]) ToProto() proto.Message

type Array

type Array struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Element Type `parser:"'[' @@ ']'" protobuf:"2"`
}

func (*Array) String

func (a *Array) String() string

func (*Array) ToProto

func (a *Array) ToProto() proto.Message

type Bool

type Bool struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Bool bool `parser:"@'Bool'" protobuf:"-"`
}

func (*Bool) String

func (*Bool) String() string

func (*Bool) ToProto

func (b *Bool) ToProto() proto.Message

type Bytes added in v0.88.0

type Bytes struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Bytes bool `parser:"@'Bytes'" protobuf:"-"`
}

func (*Bytes) String added in v0.88.0

func (*Bytes) String() string

func (*Bytes) ToProto added in v0.88.0

func (s *Bytes) ToProto() proto.Message

type Data

type Data struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Comments []string   `parser:"@Comment*" protobuf:"5"`
	Name     string     `parser:"'data' @Ident '{'" protobuf:"2"`
	Fields   []*Field   `parser:"@@* '}'" protobuf:"3"`
	Metadata []Metadata `parser:"@@*" protobuf:"4"`
}

A Data structure.

func DataToSchema

func DataToSchema(s *schemapb.Data) *Data

func (*Data) String

func (d *Data) String() string

func (*Data) ToProto

func (d *Data) ToProto() proto.Message

type DataRef

type DataRef = AbstractRef[schemapb.DataRef]

DataRef is a reference to a data structure.

func DataRefFromProto added in v0.93.0

func DataRefFromProto(s *schemapb.DataRef) *DataRef

func ParseDataRef added in v0.93.0

func ParseDataRef(ref string) (*DataRef, error)

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 DatabaseToSchema added in v0.95.0

func DatabaseToSchema(s *schemapb.Database) *Database

func (*Database) String added in v0.95.0

func (d *Database) String() string

func (*Database) ToProto added in v0.95.0

func (d *Database) ToProto() proto.Message

type Decl

type Decl interface {
	Node
	// contains filtered or unexported methods
}

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"`
}

func (*Field) String

func (f *Field) String() string

func (*Field) ToProto

func (f *Field) ToProto() proto.Message

type Float

type Float struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Float bool `parser:"@'Float'" protobuf:"-"`
}

func (*Float) String

func (*Float) String() string

func (*Float) ToProto

func (f *Float) ToProto() proto.Message

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:"@Ident" protobuf:"2"`
}

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) 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 Int struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Int bool `parser:"@'Int'" protobuf:"-"`
}

func (*Int) String

func (*Int) String() string

func (*Int) ToProto

func (i *Int) ToProto() proto.Message

type Map

type Map struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Key   Type `parser:"'{' @@" protobuf:"2"`
	Value Type `parser:"':' @@ '}'" protobuf:"3"`
}

func (*Map) String

func (m *Map) String() string

func (*Map) ToProto

func (m *Map) ToProto() proto.Message

type Metadata

type Metadata interface {
	Node
	// contains filtered or unexported methods
}

type MetadataCalls

type MetadataCalls struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Calls []*VerbRef `parser:"'calls' @@ (',' @@)*" protobuf:"2"`
}

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) 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' | 'ftl')" protobuf:"2"`
	Method string                 `parser:"@('GET' | 'POST' | 'PUT' | 'DELETE')" protobuf:"3"`
	Path   []IngressPathComponent `parser:"('/' @@)+" protobuf:"4"`
}

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 ModuleFromBytes(b []byte) (*Module, error)

func ModuleFromProto

func ModuleFromProto(s *schemapb.Module) (*Module, error)

ModuleFromProto converts a protobuf Module to a Module and validates it.

func ParseModule

func ParseModule(filename string, r io.Reader) (*Module, error)

func ParseModuleString

func ParseModuleString(filename, input string) (*Module, error)

func (*Module) AddData

func (m *Module) AddData(data *Data) int

AddData and return its index.

func (*Module) Data

func (m *Module) Data() []*Data

func (*Module) Imports added in v0.61.0

func (m *Module) Imports() []string

Imports returns the modules imported by this module.

func (*Module) String

func (m *Module) String() string

func (*Module) ToProto

func (m *Module) ToProto() proto.Message

func (*Module) Verbs

func (m *Module) Verbs() []*Verb

type Node

type Node interface {
	String() string
	ToProto() proto.Message
	// 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.

func (*Optional) String added in v0.78.0

func (o *Optional) String() string

func (*Optional) ToProto added in v0.78.0

func (o *Optional) ToProto() proto.Message

type Position

type Position struct {
	Filename string `protobuf:"1"`
	Offset   int    `parser:"" protobuf:"-"`
	Line     int    `protobuf:"2"`
	Column   int    `protobuf:"3"`
}

func (Position) String

func (p Position) String() string

func (Position) ToProto

func (p Position) ToProto() proto.Message

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.

func (*Ref) String

func (b *Ref) String() string

type RefProto added in v0.93.0

type RefProto interface {
	schemapb.VerbRef | schemapb.DataRef | schemapb.SinkRef | schemapb.SourceRef
}

RefProto is a constraint on the type of proto that can be used in a Ref.

type Schema

type Schema struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Modules []*Module `parser:"@@*" protobuf:"2"`
}

func FromProto

func FromProto(s *schemapb.Schema) (*Schema, error)

FromProto converts a protobuf Schema to a Schema and validates it.

func MustValidate added in v0.89.0

func MustValidate(schema *Schema) *Schema

MustValidate panics if a schema is invalid.

This is useful for testing.

func Parse

func Parse(filename string, r io.Reader) (*Schema, error)

func ParseString

func ParseString(filename, input string) (*Schema, error)

func Validate

func Validate(schema *Schema) (*Schema, error)

Validate clones, normalises and semantically valies a schema.

func (*Schema) DataMap added in v0.53.2

func (s *Schema) DataMap() map[DataRef]*Data

func (*Schema) Hash

func (s *Schema) Hash() [sha256.Size]byte

func (*Schema) Module added in v0.89.0

func (s *Schema) Module(name string) types.Option[*Module]

Module returns the named module if it exists.

func (*Schema) ResolveDataRef added in v0.80.0

func (s *Schema) ResolveDataRef(ref *DataRef) *Data

func (*Schema) ResolveVerbRef added in v0.80.0

func (s *Schema) ResolveVerbRef(ref *VerbRef) *Verb

func (*Schema) String

func (s *Schema) String() string

func (*Schema) ToProto

func (s *Schema) ToProto() proto.Message

func (*Schema) Upsert

func (s *Schema) Upsert(module *Module)

Upsert inserts or replaces a module.

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 ParseSinkRef(ref string) (*SinkRef, error)

func SinkRefFromProto added in v0.93.0

func SinkRefFromProto(s *schemapb.SinkRef) *SinkRef

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 ParseSourceRef(ref string) (*SourceRef, error)

func SourceRefFromProto added in v0.93.0

func SourceRefFromProto(s *schemapb.SourceRef) *SourceRef

type String

type String struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Str bool `parser:"@'String'" protobuf:"-"`
}

func (*String) String

func (*String) String() string

func (*String) ToProto

func (s *String) ToProto() proto.Message

type Time

type Time struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Time bool `parser:"@'Time'" protobuf:"-"`
}

func (*Time) String

func (*Time) String() string

func (*Time) ToProto

func (t *Time) ToProto() proto.Message

type Type

type Type interface {
	Node
	// contains filtered or unexported methods
}

Type represents a Type Node in the schema grammar.

type Unit added in v0.94.0

type Unit struct {
	Pos Position `parser:"" protobuf:"1,optional"`

	Unit bool `parser:"@'Unit'" protobuf:"-"`
}

func (*Unit) String added in v0.94.0

func (u *Unit) String() string

func (*Unit) ToProto added in v0.94.0

func (u *Unit) ToProto() protoreflect.ProtoMessage

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 VerbToSchema

func VerbToSchema(s *schemapb.Verb) *Verb

func (*Verb) AddCall

func (v *Verb) AddCall(verb *VerbRef)

AddCall adds a call reference to the Verb.

func (*Verb) GetMetadataIngress added in v0.91.0

func (v *Verb) GetMetadataIngress() types.Option[*MetadataIngress]

func (*Verb) String

func (v *Verb) String() string

func (*Verb) ToProto

func (v *Verb) ToProto() proto.Message

type VerbRef

type VerbRef = AbstractRef[schemapb.VerbRef]

VerbRef is a reference to a Verb.

func ParseVerbRef added in v0.93.0

func ParseVerbRef(ref string) (*VerbRef, error)

func VerbRefFromProto

func VerbRefFromProto(s *schemapb.VerbRef) *VerbRef

Jump to

Keyboard shortcuts

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