schema

package
v0.394.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRetryCount  = 10
	MinBackoffLimitStr = "1s"
	MinBackoffLimit    = 1 * time.Second
	DefaultMaxBackoff  = 1 * time.Hour
	MaxBackoffLimitStr = "1d"
	MaxBackoffLimit    = 24 * time.Hour
)
View Source
const BuiltinsSource = `` /* 830-byte string literal not displayed */

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

View Source
const PostgresDatabaseType = "postgres"

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var (
	Lexer = lexer.MustSimple([]lexer.SimpleRule{
		{Name: "EOL", Pattern: `[\r\n]`},
		{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

func AliasKindStrings() []string

AliasKindStrings returns a slice of all String values of the enum

func EncodeComments

func EncodeComments(comments []string) string

func ModuleToBytes

func ModuleToBytes(m *Module) ([]byte, error)

func Normalise

func Normalise[T Node](n T) T

Normalise clones and normalises (zeroes) positional information in schema Nodes.

func Redact added in v0.384.0

func Redact[T Node](n T) T

Redact clones n and recursively removes sensitive information from it.

Any node that implements the Redactable interface will have its Redact method called.

func RequestResponseToJSONSchema

func RequestResponseToJSONSchema(sch *Schema, ref Ref) (*jsonschema.Schema, error)

RequestResponseToJSONSchema converts the schema for a Verb request or response object to a JSON Schema.

It takes in the full schema in order to resolve and define references.

func SortModuleDecls

func SortModuleDecls(module *Module)

SortModuleDecls sorts the declarations in a module.

func TransformAliasedFields

func TransformAliasedFields(sch *Schema, t Type, obj any, aliaser func(obj map[string]any, field *Field) string) error

func TransformFromAliasedFields

func TransformFromAliasedFields(ref *Ref, sch *Schema, request map[string]any) (map[string]any, error)

func TransformToAliasedFields

func TransformToAliasedFields(ref *Ref, sch *Schema, request map[string]any) (map[string]any, error)

func TypeName

func TypeName(v any) string

TypeName returns the name of a type as a string, stripping any package prefix and correctly handling Ref aliases.

func TypeToProto

func TypeToProto(t Type) *schemapb.Type

TypeToProto creates a schemapb.Type "sum type" from a concreate Type.

func ValidateJSONValue

func ValidateJSONValue(fieldType Type, path path, value any, sch *Schema, opts ...EncodingOption) error

ValidateJSONValue validates a given JSON value against the provided schema.

func ValidateModule

func ValidateModule(module *Module) error

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

It ignores references to other modules.

func ValidateName

func ValidateName(name string) bool

ValidateName validates an FTL name.

func ValidateRequestMap

func ValidateRequestMap(ref *Ref, path path, request map[string]any, sch *Schema, opts ...EncodingOption) error

ValidateRequestMap validates a given JSON map against the provided schema.

func Visit

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

Visit all nodes in the schema.

func VisitExcludingMetadataChildren

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

VisitExcludingMetadataChildren visits all nodes in the schema except the children of metadata nodes. This is used when generating external modules to avoid adding imports only referenced in the bodies of stubbed verbs.

func VisitWithParent

func VisitWithParent(n Node, parent Node, visit func(n Node, parent Node, next func() error) error) error

VisitWithParent all nodes in the schema providing the parent node when visiting its schema children.

Types

type AliasKind

type AliasKind int

AliasKind is the kind of alias.

const (
	AliasKindJson AliasKind = iota //nolint
)

func AliasKindString

func AliasKindString(s string) (AliasKind, error)

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

func AliasKindValues() []AliasKind

AliasKindValues returns all values of the enum

func (AliasKind) IsAAliasKind

func (i AliasKind) IsAAliasKind() bool

IsAAliasKind returns "true" if the value is listed in the enum definition. "false" otherwise

func (AliasKind) MarshalJSON

func (i AliasKind) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for AliasKind

func (AliasKind) MarshalText

func (i AliasKind) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface for AliasKind

func (AliasKind) String

func (i AliasKind) String() string

func (*AliasKind) UnmarshalJSON

func (i *AliasKind) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for AliasKind

func (*AliasKind) UnmarshalText

func (i *AliasKind) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface for AliasKind

type Any

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

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

func (*Any) Equal

func (*Any) Equal(other Type) bool

func (*Any) GetName

func (*Any) GetName() string

func (*Any) Position

func (a *Any) Position() Position

func (*Any) String

func (*Any) String() string

func (*Any) ToProto

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

type Array

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

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

func (*Array) Equal

func (a *Array) Equal(other Type) bool

func (*Array) Position

func (a *Array) Position() Position

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

func (b *Bool) Equal(other Type) bool

func (*Bool) GetName

func (*Bool) GetName() string

func (*Bool) Position

func (b *Bool) Position() Position

func (*Bool) String

func (*Bool) String() string

func (*Bool) ToProto

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

type Bytes

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

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

func (*Bytes) Equal

func (b *Bytes) Equal(other Type) bool

func (*Bytes) GetName

func (*Bytes) GetName() string

func (*Bytes) Position

func (b *Bytes) Position() Position

func (*Bytes) String

func (*Bytes) String() string

func (*Bytes) ToProto

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

type Config

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

	Comments []string `parser:"@Comment*" protobuf:"2"`
	Name     string   `parser:"'config' @Ident" protobuf:"3"`
	Type     Type     `parser:"@@" protobuf:"4"`
}

func ConfigFromProto

func ConfigFromProto(p *schemapb.Config) *Config

func (*Config) GetName

func (s *Config) GetName() string

func (*Config) IsExported

func (s *Config) IsExported() bool

func (*Config) Position

func (s *Config) Position() Position

func (*Config) String

func (s *Config) String() string

func (*Config) ToProto

func (s *Config) ToProto() protoreflect.ProtoMessage

type Data

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

	Comments       []string         `parser:"@Comment*" protobuf:"2"`
	Export         bool             `parser:"@'export'?" protobuf:"3"`
	Name           string           `parser:"'data' @Ident" protobuf:"4"`
	TypeParameters []*TypeParameter `parser:"( '<' @@ (',' @@)* '>' )?" protobuf:"5"`
	Fields         []*Field         `parser:"'{' @@* '}'" protobuf:"6"`
	Metadata       []Metadata       `parser:"@@*" protobuf:"7"`
}

A Data structure.

func DataFromProto

func DataFromProto(s *schemapb.Data) *Data

func (*Data) FieldByName

func (d *Data) FieldByName(name string) *Field

func (*Data) GetName

func (d *Data) GetName() string

func (*Data) IsExported

func (d *Data) IsExported() bool

func (*Data) Monomorphise

func (d *Data) Monomorphise(ref *Ref) (*Data, error)

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.

func (*Data) Position

func (d *Data) Position() Position

func (*Data) Scope

func (d *Data) Scope() Scope

func (*Data) String

func (d *Data) String() string

func (*Data) ToProto

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

type Database

type Database struct {
	Pos     Position         `parser:"" protobuf:"1,optional"`
	Runtime *DatabaseRuntime `parser:"" protobuf:"31634,optional"`

	Comments []string `parser:"@Comment*" protobuf:"2"`
	Type     string   `parser:"'database' @'postgres'" protobuf:"4"`
	Name     string   `parser:"@Ident" protobuf:"3"`
}

func DatabaseFromProto

func DatabaseFromProto(s *schemapb.Database) *Database

func (*Database) GetName

func (d *Database) GetName() string

func (*Database) IsExported

func (d *Database) IsExported() bool

func (*Database) Position

func (d *Database) Position() Position

func (*Database) Redact added in v0.384.0

func (d *Database) Redact()

func (*Database) String

func (d *Database) String() string

func (*Database) ToProto

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

type DatabaseRuntime added in v0.384.0

type DatabaseRuntime struct {
	DSN string `parser:"" protobuf:"1"`
}

func DatabaseRuntimeFromProto added in v0.384.0

func DatabaseRuntimeFromProto(s *schemapb.DatabaseRuntime) *DatabaseRuntime

func (*DatabaseRuntime) ToProto added in v0.384.0

type Decl

type Decl interface {
	Symbol
	GetName() string
	IsExported() bool
	// contains filtered or unexported methods
}

Decl represents user-defined data types in the schema grammar.

type EncodingOption

type EncodingOption func(option *encodingOptions)

func LenientMode

func LenientMode() EncodingOption

type Enum

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

	Comments []string       `parser:"@Comment*" protobuf:"2"`
	Export   bool           `parser:"@'export'?" protobuf:"3"`
	Name     string         `parser:"'enum' @Ident" protobuf:"4"`
	Type     Type           `parser:"(':' @@)?" protobuf:"5,optional"`
	Variants []*EnumVariant `parser:"'{' @@* '}'" protobuf:"6"`
}

func EnumFromProto

func EnumFromProto(s *schemapb.Enum) *Enum

func (*Enum) GetName

func (e *Enum) GetName() string

func (*Enum) IsExported

func (e *Enum) IsExported() bool

func (*Enum) IsValueEnum

func (e *Enum) IsValueEnum() bool

IsValueEnum determines whether this is a type or value enum using `e.Type` alone because value enums must always have a unified type across all variants, whereas type enums by definition cannot have a unified type.

func (*Enum) Position

func (e *Enum) Position() Position

func (*Enum) String

func (e *Enum) String() string

func (*Enum) ToProto

func (e *Enum) ToProto() proto.Message

func (*Enum) VariantForName

func (e *Enum) VariantForName(name string) optional.Option[*EnumVariant]

type EnumVariant

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

	Comments []string `parser:"@Comment*" protobuf:"2"`
	Name     string   `parser:"@Ident" protobuf:"3"`
	Value    Value    `parser:"(('=' @@) | @@)!" protobuf:"4"`
}

func (*EnumVariant) Position

func (e *EnumVariant) Position() Position

func (*EnumVariant) String

func (e *EnumVariant) String() string

func (*EnumVariant) ToProto

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

func (*Field) Alias

func (f *Field) Alias(kind AliasKind) optional.Option[string]

Alias returns the alias for the given kind.

func (*Field) Position

func (f *Field) Position() Position

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

func (f *Float) Equal(other Type) bool

func (*Float) GetName

func (*Float) GetName() string

func (*Float) Position

func (f *Float) Position() Position

func (*Float) String

func (*Float) String() string

func (*Float) ToProto

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

type IngressPathComponent

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

type IngressPathLiteral

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

	Text string `parser:"@~(Whitespace | '/' | '{' | '}')+" protobuf:"2"`
}

func (*IngressPathLiteral) Position

func (l *IngressPathLiteral) Position() Position

func (*IngressPathLiteral) String

func (l *IngressPathLiteral) String() string

func (*IngressPathLiteral) ToProto

func (l *IngressPathLiteral) ToProto() proto.Message

type IngressPathParameter

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

	Name string `parser:"'{' @Ident '}'" protobuf:"2"`
}

func (*IngressPathParameter) Position

func (l *IngressPathParameter) Position() Position

func (*IngressPathParameter) String

func (l *IngressPathParameter) String() string

func (*IngressPathParameter) ToProto

func (l *IngressPathParameter) ToProto() proto.Message

type Int

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

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

func (*Int) Equal

func (i *Int) Equal(other Type) bool

func (*Int) GetName

func (*Int) GetName() string

func (*Int) Position

func (i *Int) Position() Position

func (*Int) String

func (*Int) String() string

func (*Int) ToProto

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

type IntValue

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

	Value int `parser:"@Number" protobuf:"2"`
}

func (*IntValue) GetValue

func (i *IntValue) GetValue() any

func (*IntValue) Position

func (i *IntValue) Position() Position

func (*IntValue) String

func (i *IntValue) String() string

func (*IntValue) ToProto

func (i *IntValue) 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) Equal

func (m *Map) Equal(other Type) bool

func (*Map) Position

func (m *Map) Position() Position

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
}

Metadata represents a metadata Node in the schema grammar.

type MetadataAlias

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

func (m *MetadataAlias) Position() Position

func (*MetadataAlias) String

func (m *MetadataAlias) String() string

func (*MetadataAlias) ToProto

type MetadataCalls

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

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

MetadataCalls represents a metadata block with a list of calls.

func (*MetadataCalls) Position

func (m *MetadataCalls) Position() Position

func (*MetadataCalls) String

func (m *MetadataCalls) String() string

func (*MetadataCalls) ToProto

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

type MetadataConfig

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

	Config []*Ref `parser:"'+' 'config' @@ (',' @@)*" protobuf:"2"`
}

MetadataConfig represents a metadata block with a list of config items that are used.

func (*MetadataConfig) Position

func (m *MetadataConfig) Position() Position

func (*MetadataConfig) String

func (m *MetadataConfig) String() string

func (*MetadataConfig) ToProto

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

type MetadataCronJob

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

	Cron string `parser:"'+' 'cron' Whitespace @(' ' | ~EOL)+" protobuf:"2"`
}

func (*MetadataCronJob) Position

func (m *MetadataCronJob) Position() Position

func (*MetadataCronJob) String

func (m *MetadataCronJob) String() string

func (*MetadataCronJob) ToProto

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

type MetadataDatabases

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

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

func (*MetadataDatabases) Position

func (m *MetadataDatabases) Position() Position

func (*MetadataDatabases) String

func (m *MetadataDatabases) String() string

func (*MetadataDatabases) ToProto

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

type MetadataEncoding

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

	Type    string `parser:"'+' 'encoding' @'json'" protobuf:"2"`
	Lenient bool   `parser:"@'lenient'?" protobuf:"3"`
}

func (*MetadataEncoding) Position

func (m *MetadataEncoding) Position() Position

func (*MetadataEncoding) String

func (m *MetadataEncoding) String() string

func (*MetadataEncoding) ToProto

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

func (m *MetadataIngress) Position() Position

func (*MetadataIngress) String

func (m *MetadataIngress) String() string

func (*MetadataIngress) ToProto

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

type MetadataRetry

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

	Count      *int   `parser:"'+' 'retry' (@Number Whitespace)?" protobuf:"2,optional"`
	MinBackoff string `parser:"@(Number (?! Whitespace) Ident)?" protobuf:"3"`
	MaxBackoff string `parser:"@(Number (?! Whitespace) Ident)?" protobuf:"4"`
	Catch      *Ref   `parser:"('catch' @@)?" protobuf:"5,optional"`
}

func (*MetadataRetry) Position

func (m *MetadataRetry) Position() Position

func (*MetadataRetry) RetryParams

func (m *MetadataRetry) RetryParams() (RetryParams, error)

func (*MetadataRetry) String

func (m *MetadataRetry) String() string

func (*MetadataRetry) ToProto

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

type MetadataSecrets

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

	Secrets []*Ref `parser:"'+' 'secrets' @@ (',' @@)*" protobuf:"2"`
}

MetadataSecrets represents a metadata block with a list of config items that are used.

func (*MetadataSecrets) Position

func (m *MetadataSecrets) Position() Position

func (*MetadataSecrets) String

func (m *MetadataSecrets) String() string

func (*MetadataSecrets) ToProto

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

type MetadataSubscriber

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

	Name string `parser:"'+' 'subscribe' @Ident" protobuf:"2"`
}

func (*MetadataSubscriber) Position

func (m *MetadataSubscriber) Position() Position

func (*MetadataSubscriber) String

func (m *MetadataSubscriber) String() string

func (*MetadataSubscriber) ToProto

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

type MetadataTypeMap

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

	Runtime    string `parser:"'+' 'typemap' @('go' | 'kotlin' | 'java')" protobuf:"2"`
	NativeName string `parser:"@String" protobuf:"3"`
}

func (*MetadataTypeMap) Position

func (m *MetadataTypeMap) Position() Position

func (*MetadataTypeMap) String

func (m *MetadataTypeMap) String() string

func (*MetadataTypeMap) ToProto

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

	Runtime *ModuleRuntime `protobuf:"31634,optional" parser:""`
}

func Builtins

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 ModuleFromProtoFile

func ModuleFromProtoFile(filename string) (*Module, error)

ModuleFromProtoFile loads a module from the given proto-encoded file.

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.

If data is already in the module, the existing index is returned. If the new data is exported but the existing data is not, it sets it to being exported.

func (*Module) AddDecl

func (m *Module) AddDecl(decl Decl)

AddDecl adds a single decl to the module.

It is only added if not already present or if it changes the visibility of the existing Decl.

func (*Module) AddDecls

func (m *Module) AddDecls(decls []Decl)

AddDecls appends decls to the module.

Decls are only added if they are not already present in the module or if they change the visibility of an existing Decl.

func (*Module) Data

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

func (*Module) GetName

func (m *Module) GetName() string

func (*Module) Imports

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

Imports returns the modules imported by this module.

func (*Module) IsExported

func (m *Module) IsExported() bool

func (*Module) Position

func (m *Module) Position() Position

func (*Module) Resolve

func (m *Module) Resolve(ref Ref) *ModuleDecl

Resolve returns the declaration in this module with the given name, or nil

func (*Module) Scan

func (m *Module) Scan(src any) error

func (*Module) String

func (m *Module) String() string

func (*Module) ToProto

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

func (*Module) Value

func (m *Module) Value() (driver.Value, error)

func (*Module) Verbs

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

type ModuleDecl

type ModuleDecl struct {
	Module optional.Option[*Module]
	Symbol Symbol
}

ModuleDecl is a declaration associated with a module.

func ResolveAs

func ResolveAs[S Symbol](scopes Scopes, ref Ref) (symbol S, decl *ModuleDecl)

ResolveAs resolves a Ref to a concrete symbol and declaration.

[decl] will be non-nil if the symbol is found, regardless of its type. [symbol] will be non-nil if the symbol is of type [S].

func ResolveTypeAs

func ResolveTypeAs[S Symbol](scopes Scopes, t Type) (symbol S, decl *ModuleDecl)

ResolveTypeAs resolves a Type to a concrete symbol and declaration.

type ModuleRuntime

type ModuleRuntime struct {
	CreateTime  time.Time `protobuf:"1"`
	Language    string    `protobuf:"2"`
	MinReplicas int32     `protobuf:"3"`
	OS          string    `protobuf:"4,optional"`
	Arch        string    `protobuf:"5,optional"`
}

type Named

type Named interface {
	Symbol
	GetName() string
}

A Named symbol in the grammar.

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

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

func (o *Optional) Equal(other Type) bool

func (*Optional) Position

func (o *Optional) Position() Position

func (*Optional) String

func (o *Optional) String() string

func (*Optional) ToProto

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 PosFromProto

func PosFromProto(pos *schemapb.Position) Position

func (Position) String

func (p Position) String() string

func (Position) ToErrorPos

func (p Position) ToErrorPos() builderrors.Position

func (Position) ToErrorPosWithEnd

func (p Position) ToErrorPosWithEnd(endColumn int) builderrors.Position

func (Position) ToProto

func (p Position) ToProto() proto.Message

type Redactable added in v0.384.0

type Redactable interface {
	Redact()
}

type Ref

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

	Module string `parser:"(@Ident '.')?" protobuf:"3"`
	Name   string `parser:"@Ident" protobuf:"2"`
	// Only used for data references.
	TypeParameters []Type `parser:"[ '<' @@ (',' @@)* '>' ]" protobuf:"4"`
}

Ref is an untyped reference to a symbol.

func ParseRef

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

func RefFromProto

func RefFromProto(s *schemapb.Ref) *Ref

func (*Ref) Equal

func (r *Ref) Equal(other Type) bool

func (*Ref) Position

func (r *Ref) Position() Position

func (*Ref) Scan

func (r *Ref) Scan(src any) error

func (*Ref) String

func (r *Ref) String() string

func (*Ref) ToProto

func (r *Ref) ToProto() proto.Message

func (Ref) ToRefKey

func (r Ref) ToRefKey() RefKey

func (Ref) Value

func (r Ref) Value() (driver.Value, error)

type RefKey

type RefKey struct {
	Module string `parser:"(@Ident '.')?"`
	Name   string `parser:"@Ident"`
}

RefKey is a map key for a reference.

func (*RefKey) Scan

func (r *RefKey) Scan(src any) error

func (RefKey) String

func (r RefKey) String() string

func (RefKey) ToProto

func (r RefKey) ToProto() *schemapb.Ref

func (RefKey) ToRef

func (r RefKey) ToRef() *Ref

func (RefKey) Value

func (r RefKey) Value() (driver.Value, error)

type Resolver

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 RetryParams

type RetryParams struct {
	Count      int
	MinBackoff time.Duration
	MaxBackoff time.Duration
	Catch      optional.Option[RefKey]
}

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

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 ValidateModuleInSchema

func ValidateModuleInSchema(schema *Schema, m optional.Option[*Module]) (*Schema, error)

ValidateModuleInSchema clones and normalises a schema and semantically validates a single module within it. If no module is provided, all modules in the schema are validated.

func ValidateSchema

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

ValidateSchema clones, normalises and semantically validates a schema.

func (*Schema) Hash

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

func (*Schema) Module

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

Module returns the named module if it exists.

func (*Schema) Position

func (s *Schema) Position() Position

func (*Schema) Resolve

func (s *Schema) Resolve(ref *Ref) optional.Option[Decl]

Resolve a reference to a declaration.

func (*Schema) ResolveMonomorphised

func (s *Schema) ResolveMonomorphised(ref *Ref) (*Data, error)

ResolveMonomorphised resolves a reference to a monomorphised Data type. Also supports resolving the monomorphised Data type underlying a TypeAlias, where applicable.

If a Ref is not found, returns ErrNotFound.

func (*Schema) ResolveRequestResponseType

func (s *Schema) ResolveRequestResponseType(ref *Ref) (Symbol, error)

ResolveRequestResponseType resolves a reference to a supported request/response type, which can be a Data or an Any, or a TypeAlias over either supported type.

func (*Schema) ResolveToType

func (s *Schema) ResolveToType(ref *Ref, out Decl) error

ResolveToType resolves a reference to a declaration of the given type.

The out parameter must be a pointer to a non-nil Decl implementation or this will panic.

data := &Data{}
err := s.ResolveToType(ref, data)

func (*Schema) ResolveWithModule

func (s *Schema) ResolveWithModule(ref *Ref) (optional.Option[Decl], optional.Option[*Module])

ResolveWithModule a reference to a declaration and its module.

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 Scope

type Scope map[string]ModuleDecl

Scope maps relative names to fully qualified types.

func (Scope) String

func (s Scope) String() string

type Scoped

type Scoped interface {
	Scope() Scope
}

Scoped is implemented by nodes that wish to introduce a new scope.

type Scopes

type Scopes []Scope

Scopes to search during type resolution.

func NewScopes

func NewScopes() Scopes

NewScopes constructs a new type resolution stack with builtins pre-populated.

func (*Scopes) Add

func (s *Scopes) Add(owner optional.Option[*Module], name string, symbol Symbol) error

Add a declaration to the current scope.

func (Scopes) Push

func (s Scopes) Push() Scopes

Push a new Scope onto the stack.

This contains references to previous Scopes so that updates are preserved.

func (Scopes) PushScope

func (s Scopes) PushScope(scope Scope) Scopes

func (Scopes) Resolve

func (s Scopes) Resolve(ref Ref) *ModuleDecl

Resolve a reference to a symbol declaration or nil.

func (Scopes) ResolveType

func (s Scopes) ResolveType(t Type) *ModuleDecl

func (Scopes) String

func (s Scopes) String() string

type Secret

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

	Comments []string `parser:"@Comment*" protobuf:"2"`
	Name     string   `parser:"'secret' @Ident" protobuf:"3"`
	Type     Type     `parser:"@@" protobuf:"4"`
}

func SecretFromProto

func SecretFromProto(s *schemapb.Secret) *Secret

func (*Secret) GetName

func (s *Secret) GetName() string

func (*Secret) IsExported

func (s *Secret) IsExported() bool

func (*Secret) Position

func (s *Secret) Position() Position

func (*Secret) String

func (s *Secret) String() string

func (*Secret) ToProto

func (s *Secret) ToProto() protoreflect.ProtoMessage

type String

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

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

func (*String) Equal

func (s *String) Equal(other Type) bool

func (*String) GetName

func (*String) GetName() string

func (*String) Position

func (s *String) Position() Position

func (*String) String

func (*String) String() string

func (*String) ToProto

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

type StringValue

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

	Value string `parser:"@String" protobuf:"2"`
}

func (*StringValue) GetValue

func (s *StringValue) GetValue() any

func (*StringValue) Position

func (s *StringValue) Position() Position

func (*StringValue) String

func (s *StringValue) String() string

func (*StringValue) ToProto

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

type Subscription

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

	Comments []string `parser:"@Comment*" protobuf:"2"`
	Name     string   `parser:"'subscription' @Ident" protobuf:"3"`
	Topic    *Ref     `parser:"@@" protobuf:"4"`
}

func SubscriptionFromProto

func SubscriptionFromProto(s *schemapb.Subscription) *Subscription

func (*Subscription) GetName

func (s *Subscription) GetName() string

func (*Subscription) IsExported

func (s *Subscription) IsExported() bool

func (*Subscription) Position

func (s *Subscription) Position() Position

func (*Subscription) String

func (s *Subscription) String() string

func (*Subscription) ToProto

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

type Symbol

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

Symbol represents a symbol in the schema grammar.

A Symbol is a named type that can be referenced by other types. This includes user defined data types such as data structures and enums, and builtin types.

type Time

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

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

func (*Time) Equal

func (t *Time) Equal(other Type) bool

func (*Time) GetName

func (*Time) GetName() string

func (*Time) Position

func (t *Time) Position() Position

func (*Time) String

func (*Time) String() string

func (*Time) ToProto

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

type Topic

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

	Comments []string `parser:"@Comment*" protobuf:"2"`
	Export   bool     `parser:"@'export'?" protobuf:"3"`
	Name     string   `parser:"'topic' @Ident" protobuf:"4"`
	Event    Type     `parser:"@@" protobuf:"5"`
}

func TopicFromProto

func TopicFromProto(t *schemapb.Topic) *Topic

func (*Topic) GetName

func (t *Topic) GetName() string

func (*Topic) IsExported

func (t *Topic) IsExported() bool

func (*Topic) Position

func (t *Topic) Position() Position

func (*Topic) String

func (t *Topic) String() string

func (*Topic) ToProto

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

type Type

type Type interface {
	Node
	// Equal returns true if this type is equal to another type.
	Equal(other Type) bool
	// contains filtered or unexported methods
}

Type represents a Type Node in the schema grammar.

func ParseType

func ParseType(filename, input string) (Type, error)

ParseType parses the string representation of a type.

func TypeFromProto

func TypeFromProto(s *schemapb.Type) Type

type TypeAlias

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

	Comments []string   `parser:"@Comment*" protobuf:"2"`
	Export   bool       `parser:"@'export'?" protobuf:"3"`
	Name     string     `parser:"'typealias' @Ident" protobuf:"4"`
	Type     Type       `parser:"@@" protobuf:"5"`
	Metadata []Metadata `parser:"@@*" protobuf:"6"`
}

func TypeAliasFromProto

func TypeAliasFromProto(s *schemapb.TypeAlias) *TypeAlias

func (*TypeAlias) GetName

func (t *TypeAlias) GetName() string

func (*TypeAlias) IsExported

func (t *TypeAlias) IsExported() bool

func (*TypeAlias) Position

func (t *TypeAlias) Position() Position

func (*TypeAlias) String

func (t *TypeAlias) String() string

func (*TypeAlias) ToProto

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

type TypeParameter

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

	Name string `parser:"@Ident" protobuf:"2"`
}

func (*TypeParameter) GetName

func (t *TypeParameter) GetName() string

func (*TypeParameter) Position

func (t *TypeParameter) Position() Position

func (*TypeParameter) String

func (t *TypeParameter) String() string

func (*TypeParameter) ToProto

type TypeValue

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

	Value Type `parser:"@@" protobuf:"2"`
}

func (*TypeValue) GetValue

func (t *TypeValue) GetValue() any

func (*TypeValue) Position

func (t *TypeValue) Position() Position

func (*TypeValue) String

func (t *TypeValue) String() string

func (*TypeValue) ToProto

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

type Unit

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

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

func (*Unit) Equal

func (u *Unit) Equal(other Type) bool

func (*Unit) GetName

func (u *Unit) GetName() string

func (*Unit) Position

func (u *Unit) Position() Position

func (*Unit) String

func (u *Unit) String() string

func (*Unit) ToProto

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

type Value

type Value interface {
	Node
	GetValue() any
	// 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:"2"`
	Export   bool       `parser:"@'export'?" protobuf:"3"`
	Name     string     `parser:"'verb' @Ident" protobuf:"4"`
	Request  Type       `parser:"'(' @@ ')'" protobuf:"5"`
	Response Type       `parser:"@@" protobuf:"6"`
	Metadata []Metadata `parser:"@@*" protobuf:"7"`

	Runtime *VerbRuntime `protobuf:"31634,optional" parser:""`
}

func VerbFromProto

func VerbFromProto(s *schemapb.Verb) *Verb

func (*Verb) AddCall

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

AddCall adds a call reference to the Verb.

func (*Verb) AddConfig

func (v *Verb) AddConfig(config *Ref)

AddConfig adds a config reference to the Verb.

func (*Verb) AddDatabase added in v0.393.0

func (v *Verb) AddDatabase(db *Ref)

AddDatabase adds a DB reference to the Verb.

func (*Verb) AddSecret

func (v *Verb) AddSecret(secret *Ref)

AddSecret adds a config reference to the Verb.

func (*Verb) GetMetadataCronJob

func (v *Verb) GetMetadataCronJob() optional.Option[*MetadataCronJob]

func (*Verb) GetMetadataIngress

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

func (*Verb) GetName

func (v *Verb) GetName() string

func (*Verb) IsExported

func (v *Verb) IsExported() bool

func (*Verb) Kind

func (v *Verb) Kind() VerbKind

Kind returns the kind of Verb this is.

func (*Verb) Position

func (v *Verb) Position() Position

func (*Verb) String

func (v *Verb) String() string

func (*Verb) ToProto

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

type VerbKind

type VerbKind string

VerbKind is the kind of Verb: verb, sink, source or empty.

const (
	// VerbKindVerb is a normal verb taking an input and an output of any non-unit type.
	VerbKindVerb VerbKind = "verb"
	// VerbKindSink is a verb that takes an input and returns unit.
	VerbKindSink VerbKind = "sink"
	// VerbKindSource is a verb that returns an output and takes unit.
	VerbKindSource VerbKind = "source"
	// VerbKindEmpty is a verb that takes unit and returns unit.
	VerbKindEmpty VerbKind = "empty"
)

type VerbRuntime

type VerbRuntime struct {
	CreateTime time.Time `protobuf:"1"`
	StartTime  time.Time `protobuf:"2"`
}

Directories

Path Synopsis
Package strcase provides programming case conversion functions for strings.
Package strcase provides programming case conversion functions for strings.

Jump to

Keyboard shortcuts

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