schema

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataToJSONSchema added in v0.1.1

func DataToJSONSchema(schema *Schema, dataRef DataRef) (*js.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 a Node.

func ProtobufSchema

func ProtobufSchema() string

ProtobufSchema returns a string containing the equivalent protobuf schema for the FTL schema.

func Validate

func Validate(schema *Schema) error

Validate performs semantic validation of a 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 Array

type Array struct {
	Pos Position `json:"-" parser:"" protobuf:"-"`

	Element Type `parser:"'[' @@ ']'" json:"element,omitempty" protobuf:"1"`
}

func (*Array) String

func (a *Array) String() string

func (*Array) ToProto

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

type Bool

type Bool struct {
	Pos Position `json:"-" parser:"" protobuf:"-"`

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

func (*Bool) String

func (*Bool) String() string

func (*Bool) ToProto

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

type Data

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

	Comments []string   `parser:"@Comment*" json:"comments,omitempty" protobuf:"5"`
	Name     string     `parser:"'data' @Ident '{'" json:"name,omitempty" protobuf:"2"`
	Fields   []*Field   `parser:"@@* '}'" json:"fields,omitempty" protobuf:"3"`
	Metadata []Metadata `parser:"@@*" json:"metadata,omitempty" protobuf:"4"`
}

A Data structure.

func DataToSchema

func DataToSchema(s *pschema.Data) *Data

func (*Data) String

func (d *Data) String() string

func (*Data) ToProto

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

type DataRef

type DataRef Ref

DataRef is a reference to a data structure.

func (DataRef) String

func (s DataRef) String() string

func (*DataRef) ToProto

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

type Decl

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

type Field

type Field struct {
	Pos Position `json:"pos,omitempty" parser:"" protobuf:"1,optional"`

	Comments []string `parser:"@Comment*" json:"comments,omitempty" protobuf:"3"`
	Name     string   `parser:"@Ident" json:"name,omitempty" protobuf:"2"`
	Type     Type     `parser:"@@" json:"type,omitempty" 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 `json:"-" parser:"" protobuf:"-"`

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

func (*Float) String

func (*Float) String() string

func (*Float) ToProto

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

type Int

type Int struct {
	Pos Position `json:"-" parser:"" protobuf:"-"`

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

func (*Int) String

func (*Int) String() string

func (*Int) ToProto

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

type Map

type Map struct {
	Pos Position `json:"-" parser:"" protobuf:"-"`

	Key   Type `parser:"'{' @@" json:"key,omitempty" protobuf:"1"`
	Value Type `parser:"':' @@ '}'" json:"value,omitempty" protobuf:"2"`
}

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 `json:"pos,omitempty" parser:"" protobuf:"1,optional"`

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

func (*MetadataCalls) String

func (m *MetadataCalls) String() string

func (*MetadataCalls) ToProto

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

type MetadataIngress

type MetadataIngress struct {
	Pos Position `json:"pos,omitempty" parser:"" protobuf:"1,optional"`

	Method string `parser:"'ingress' @('GET' | 'POST')" json:"method,omitempty" protobuf:"2"`
	Path   string `parser:"@('/' @Ident)+" json:"path,omitempty" protobuf:"3"`
}

func (*MetadataIngress) String

func (m *MetadataIngress) String() string

func (*MetadataIngress) ToProto

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

type Module

type Module struct {
	Pos Position `json:"pos,omitempty" parser:"" protobuf:"1,optional"`

	Comments []string `parser:"@Comment*" json:"comments,omitempty" protobuf:"3"`
	Name     string   `parser:"'module' @Ident '{'" json:"name,omitempty" protobuf:"2"`
	Decls    []Decl   `parser:"@@* '}'" json:"decls,omitempty" protobuf:"4"`
}

func ModuleFromBytes

func ModuleFromBytes(b []byte) (*Module, error)

func ModuleFromProto

func ModuleFromProto(s *pschema.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) 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 Position

type Position struct {
	Filename string `json:"filename,omitempty" protobuf:"1"`
	Offset   int    `json:"-" parser:"" protobuf:"-"`
	Line     int    `json:"line,omitempty" protobuf:"2"`
	Column   int    `json:"column,omitempty" 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 `json:"pos,omitempty" parser:"" protobuf:"1,optional"`

	Module string `parser:"(@Ident '.')?" json:"module,omitempty" protobuf:"3"`
	Name   string `parser:"@Ident" json:"name,omitempty" protobuf:"2"`
}

Ref is a reference to another symbol.

func ParseRef

func ParseRef(ref string) (*Ref, error)

func (*Ref) String

func (r *Ref) String() string

type Schema

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

	Modules []*Module `parser:"@@*" json:"modules,omitempty" protobuf:"2"`
}

func FromProto

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

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

func Parse

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

func ParseString

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

func (*Schema) Hash

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

func (*Schema) MarshalJSON

func (s *Schema) MarshalJSON() ([]byte, error)

func (*Schema) String

func (s *Schema) String() string

func (*Schema) ToProto

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

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(data []byte) error

func (*Schema) Upsert

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

Upsert inserts or replaces a module.

type String

type String struct {
	Pos Position `json:"-" parser:"" protobuf:"-"`

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

func (*String) String

func (*String) String() string

func (*String) ToProto

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

type Time

type Time struct {
	Pos Position `json:"-" parser:"" protobuf:"-"`

	Time bool `parser:"@'Time'" json:"-" 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 Verb

type Verb struct {
	Pos Position `json:"pos,omitempty" parser:"" protobuf:"1,optional"`

	Comments []string   `parser:"@Comment*" json:"comments,omitempty" protobuf:"3"`
	Name     string     `parser:"'verb' @Ident" json:"name,omitempty" protobuf:"2"`
	Request  *DataRef   `parser:"'(' @@ ')'" json:"request,omitempty" protobuf:"4"`
	Response *DataRef   `parser:"@@" json:"response,omitempty" protobuf:"5"`
	Metadata []Metadata `parser:"@@*" json:"metadata,omitempty" protobuf:"6"`
}

func VerbToSchema

func VerbToSchema(s *pschema.Verb) *Verb

func (*Verb) AddCall

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

AddCall adds a call reference to the Verb.

func (*Verb) String

func (v *Verb) String() string

func (*Verb) ToProto

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

type VerbRef

type VerbRef Ref

VerbRef is a reference to a Verb.

func VerbRefFromProto

func VerbRefFromProto(s *pschema.VerbRef) *VerbRef

VerbRefFromProto converts a protobuf VerbRef to a VerbRef.

func (VerbRef) String

func (v VerbRef) String() string

func (*VerbRef) ToProto

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

Jump to

Keyboard shortcuts

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