est

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package est provides the Encore Syntax Tree (EST).

It is an Encore-specific syntax tree that represents the higher-level representation of the application that Encore understands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessType

type AccessType string
const (
	Public  AccessType = "public"
	Private AccessType = "private"
	// Auth is like public but requires authentication.
	Auth AccessType = "auth"
)

type Application

type Application struct {
	ModulePath    string
	Packages      []*Package
	Services      []*Service
	CronJobs      []*CronJob
	PubSubTopics  []*PubSubTopic
	CacheClusters []*CacheCluster
	Decls         []*schema.Decl
	AuthHandler   *AuthHandler
	Middleware    []*Middleware
	Metrics       []*Metric
}

func (*Application) MatchingMiddleware added in v1.5.0

func (a *Application) MatchingMiddleware(rpc *RPC) []*Middleware

MatchingMiddleware reports which middleware applies to the given RPC, and the order they apply in.

func (*Application) SelectorLookup added in v1.9.3

func (a *Application) SelectorLookup() *SelectorLookup

SelectorLookup creates a selector lookup from this application

type AuthHandler

type AuthHandler struct {
	Svc       *Service
	Name      string
	Doc       string
	Func      *ast.FuncDecl
	File      *File
	Params    *schema.Type   // builtin string or named type
	SvcStruct *ServiceStruct // nil if not defined on a service struct

	// AuthData is the custom auth data type the app may specify
	// as part of the returns from the auth handler.
	// It is nil if no such auth data type is specified.
	AuthData *Param
}

type CacheCluster added in v1.7.0

type CacheCluster struct {
	Name           string // The unique name of the cache cluster
	Doc            string // The documentation on the cluster
	DeclFile       *File  // What file the cache is declared in
	DeclCall       *ast.CallExpr
	IdentAST       *ast.Ident // The AST node representing the value this cache cluster is bound against
	EvictionPolicy string

	Keyspaces []*CacheKeyspace
}

func (*CacheCluster) AllowOnlyParsedUsage added in v1.7.0

func (p *CacheCluster) AllowOnlyParsedUsage() bool

func (*CacheCluster) DefNode added in v1.11.0

func (r *CacheCluster) DefNode() ast.Node

func (*CacheCluster) File added in v1.7.0

func (p *CacheCluster) File() *File

func (*CacheCluster) Ident added in v1.7.0

func (p *CacheCluster) Ident() *ast.Ident

func (*CacheCluster) NodeType added in v1.7.0

func (p *CacheCluster) NodeType() NodeType

func (*CacheCluster) Type added in v1.7.0

func (p *CacheCluster) Type() ResourceType

type CacheKeyspace added in v1.7.0

type CacheKeyspace struct {
	Cluster   *CacheCluster
	Svc       *Service
	Doc       string // The documentation on the cluster
	DeclFile  *File  // What file the cache is declared in
	DeclCall  *ast.CallExpr
	IdentAST  *ast.Ident // The AST node representing the value this cache cluster is bound against
	ConfigLit *ast.CompositeLit

	KeyType   *schema.Type // The key type for this keyspace
	ValueType *schema.Type // The value type for this keyspace
	Path      *paths.Path  // The keyspace path
}

func (*CacheKeyspace) AllowOnlyParsedUsage added in v1.7.0

func (p *CacheKeyspace) AllowOnlyParsedUsage() bool

func (*CacheKeyspace) DefNode added in v1.11.0

func (r *CacheKeyspace) DefNode() ast.Node

func (*CacheKeyspace) File added in v1.7.0

func (p *CacheKeyspace) File() *File

func (*CacheKeyspace) Ident added in v1.7.0

func (p *CacheKeyspace) Ident() *ast.Ident

func (*CacheKeyspace) NodeType added in v1.7.0

func (p *CacheKeyspace) NodeType() NodeType

func (*CacheKeyspace) Type added in v1.7.0

func (p *CacheKeyspace) Type() ResourceType

type Config added in v1.8.0

type Config struct {
	Svc          *Service      // The service the config is loaded for
	DeclFile     *File         // The file that the subscriber is defined in
	IdentAST     *ast.Ident    // The AST node representing the value this topic is bound against
	FuncCall     *ast.CallExpr // The AST node representing the call to the config load function (we use this for rewriting)
	ConfigStruct *Param        // The type the config loads in as
}

Config represents a config load statement.

func (*Config) AllowOnlyParsedUsage added in v1.8.0

func (c *Config) AllowOnlyParsedUsage() bool

func (*Config) DefNode added in v1.11.0

func (c *Config) DefNode() ast.Node

func (*Config) File added in v1.8.0

func (c *Config) File() *File

func (*Config) Ident added in v1.8.0

func (c *Config) Ident() *ast.Ident

func (*Config) NodeType added in v1.8.0

func (c *Config) NodeType() NodeType

func (*Config) Type added in v1.8.0

func (c *Config) Type() ResourceType

type CronJob added in v0.19.0

type CronJob struct {
	ID       string
	Title    string
	Doc      string
	Schedule string
	RPC      *RPC
	DeclFile *File
	DeclCall *ast.CallExpr
	AST      *ast.Ident
}

func (*CronJob) AllowOnlyParsedUsage added in v1.3.0

func (cj *CronJob) AllowOnlyParsedUsage() bool

func (*CronJob) DefNode added in v1.11.0

func (cj *CronJob) DefNode() ast.Node

func (*CronJob) File added in v1.3.0

func (cj *CronJob) File() *File

func (*CronJob) Ident added in v1.3.0

func (cj *CronJob) Ident() *ast.Ident

func (*CronJob) IsValid added in v0.19.0

func (cj *CronJob) IsValid() (bool, error)

func (*CronJob) NodeType added in v1.3.0

func (cj *CronJob) NodeType() NodeType

func (*CronJob) Type added in v1.3.0

func (cj *CronJob) Type() ResourceType

type File

type File struct {
	Name       string          // file name ("foo.go")
	Pkg        *Package        // package it belongs to
	Path       string          // filesystem path
	Imports    map[string]bool // imports in the file, keyed by import path
	AST        *ast.File
	Token      *token.File
	Contents   []byte
	References map[ast.Node]*Node
}

type Label added in v1.11.0

type Label struct {
	Key  string
	Type schema.Builtin
	Doc  string
}

func (Label) String added in v1.11.0

func (l Label) String() string

type Metric added in v1.11.0

type Metric struct {
	Name       string         // The metric name
	ValueType  schema.Builtin // The metric type
	Kind       meta.Metric_MetricKind
	Doc        string   // The documentation on the metric
	Svc        *Service // the service this metric is exclusive to, or nil
	DeclFile   *File    // What file the cache is declared in
	DeclCall   *ast.CallExpr
	IdentAST   *ast.Ident // The AST node representing the value this metric is bound against
	ConfigLit  *ast.CompositeLit
	LabelsType *schema.Type // The labels for this keyspace, or nil if no labels.
	LabelsAST  ast.Node
	Labels     []Label
}

func (*Metric) AllowOnlyParsedUsage added in v1.11.0

func (p *Metric) AllowOnlyParsedUsage() bool

func (*Metric) DefNode added in v1.11.0

func (p *Metric) DefNode() ast.Node

func (*Metric) File added in v1.11.0

func (p *Metric) File() *File

func (*Metric) Ident added in v1.11.0

func (p *Metric) Ident() *ast.Ident

func (*Metric) NodeType added in v1.11.0

func (p *Metric) NodeType() NodeType

func (*Metric) Type added in v1.11.0

func (p *Metric) Type() ResourceType

type Middleware added in v1.5.0

type Middleware struct {
	Name   string
	Doc    string
	Global bool
	Target selector.Set

	Func *ast.FuncDecl
	File *File

	Pkg       *Package       // pkg this middleware is defined in
	Svc       *Service       // nil if global
	SvcStruct *ServiceStruct // nil if not defined on a service struct
}

type Node

type Node struct {
	Type NodeType
	// If Type == RPCDefNode or RPCCallNode,
	// RPC is the RPC being defined or called.
	RPC *RPC

	// If Type == SQLDBNode or RLogNode,
	// Func is the func name being called.
	Func string

	// Resource this refers to, if any
	Res Resource
}

type NodeType

type NodeType int
const (
	RPCDefNode NodeType = iota + 1
	RPCRefNode
	SQLDBNode
	RLogNode
	SecretsNode
	CronJobNode
	PubSubTopicDefNode
	PubSubPublisherNode
	PubSubSubscriberNode
	CacheClusterDefNode
	CacheKeyspaceDefNode
	ConfigLoadNode
	MetricDefNode
)

type Package

type Package struct {
	AST        *ast.Package
	Name       string
	Doc        string
	ImportPath string // import path
	RelPath    string // import path relative to app root
	Dir        string // filesystem path
	Files      []*File
	Service    *Service // the service this package belongs to, if any
	Secrets    []string
	Resources  []Resource
	Imports    map[string]bool // union of all imports from files
}

type Param

type Param struct {
	IsPtr bool
	Type  *schema.Type
}

func (*Param) GetWithPointer added in v1.9.3

func (p *Param) GetWithPointer() *schema.Type

GetWithPointer ensures that if the parameter is marked as a pointer you get the pointer schema.type back

func (*Param) IsPointer added in v1.8.0

func (p *Param) IsPointer() bool

IsPointer returns if this parameter is a a pointer or not

type PubSubGuarantee added in v1.3.0

type PubSubGuarantee int
const (
	AtLeastOnce PubSubGuarantee = iota
	ExactlyOnce
)

type PubSubPublisher added in v1.3.0

type PubSubPublisher struct {
	DeclFile *File // The file the publisher is declared in

	// One of
	Service          *Service    // The service the publisher is declared in
	GlobalMiddleware *Middleware // The name of the middleware target
}

type PubSubSubscriber added in v1.3.0

type PubSubSubscriber struct {
	Name     string       // The unique name of the subscriber
	NameAST  ast.Node     // The AST node that defines the name of the subscriber
	Topic    *PubSubTopic // The topic the subscriber is registered against
	CallSite ast.Node     // The AST node representing the creation of the subscriber
	Func     ast.Node     // The function that is the subscriber (either a *ast.FuncLit or a *ast.FuncDecl)
	FuncFile *File        // The file the subscriber function is declared in
	DeclFile *File        // The file that the subscriber is defined in
	DeclCall *ast.CallExpr
	IdentAST *ast.Ident // The AST node representing the value this topic is bound against

	AckDeadline      time.Duration
	MessageRetention time.Duration
	MinRetryBackoff  time.Duration
	MaxRetryBackoff  time.Duration
	MaxRetries       int64 // number of attempts
}

func (*PubSubSubscriber) AllowOnlyParsedUsage added in v1.3.0

func (p *PubSubSubscriber) AllowOnlyParsedUsage() bool

func (*PubSubSubscriber) DefNode added in v1.11.0

func (p *PubSubSubscriber) DefNode() ast.Node

func (*PubSubSubscriber) File added in v1.3.0

func (p *PubSubSubscriber) File() *File

func (*PubSubSubscriber) Ident added in v1.3.0

func (p *PubSubSubscriber) Ident() *ast.Ident

func (*PubSubSubscriber) NodeType added in v1.3.0

func (p *PubSubSubscriber) NodeType() NodeType

func (*PubSubSubscriber) Type added in v1.3.0

func (p *PubSubSubscriber) Type() ResourceType

type PubSubTopic added in v1.3.0

type PubSubTopic struct {
	Name              string          // The unique name of the pub sub topic
	NameAST           ast.Node        // The AST node that defines the name of the pub sub topic
	Doc               string          // The documentation on the pub sub topic
	DeliveryGuarantee PubSubGuarantee // What guarantees does the pub sub topic have?
	OrderingKey       string          // What field in the message type should be used to ensure First-In-First-Out (FIFO) for messages with the same key
	DeclFile          *File           // What file the topic is declared in
	DeclCall          *ast.CallExpr
	MessageType       *Param     // The message type of the pub sub topic
	IdentAST          *ast.Ident // The AST node representing the value this topic is bound against

	Subscribers []*PubSubSubscriber
	Publishers  []*PubSubPublisher
}

func (*PubSubTopic) AllowOnlyParsedUsage added in v1.3.0

func (p *PubSubTopic) AllowOnlyParsedUsage() bool

func (*PubSubTopic) DefNode added in v1.11.0

func (p *PubSubTopic) DefNode() ast.Node

func (*PubSubTopic) File added in v1.3.0

func (p *PubSubTopic) File() *File

func (*PubSubTopic) Ident added in v1.3.0

func (p *PubSubTopic) Ident() *ast.Ident

func (*PubSubTopic) NodeType added in v1.3.0

func (p *PubSubTopic) NodeType() NodeType

func (*PubSubTopic) Type added in v1.3.0

func (p *PubSubTopic) Type() ResourceType

type RPC

type RPC struct {
	Svc         *Service
	Name        string
	Doc         string
	Func        *ast.FuncDecl
	File        *File
	Access      AccessType
	Raw         bool
	Path        *paths.Path
	HTTPMethods []string
	Request     *Param // request data; nil for Raw RPCs
	Response    *Param // response data; nil for Raw RPCs
	Tags        selector.Set

	// SvcStruct is the service struct this RPC is defined on,
	// or nil otherwise. It is always a pointer receiver.
	SvcStruct *ServiceStruct
}

type Resource added in v0.17.2

type Resource interface {
	Type() ResourceType
	File() *File
	Ident() *ast.Ident
	DefNode() ast.Node
	NodeType() NodeType
	AllowOnlyParsedUsage() bool // If true this resource can only be used with registered resource parsers. If false we allow any usage.
}

type ResourceType added in v0.17.2

type ResourceType int
const (
	SQLDBResource ResourceType = iota + 1
	CronJobResource
	PubSubTopicResource
	PubSubSubscriptionResource
	CacheClusterResource
	CacheKeyspaceResource
	ConfigResource
	MetricResource
)

func (ResourceType) String added in v0.17.2

func (i ResourceType) String() string

type SQLDB added in v0.17.2

type SQLDB struct {
	DeclFile *File
	DeclName *ast.Ident // where the resource is declared
	DeclCall *ast.CallExpr
	DBName   string
}

func (*SQLDB) AllowOnlyParsedUsage added in v1.3.0

func (r *SQLDB) AllowOnlyParsedUsage() bool

func (*SQLDB) DefNode added in v1.11.0

func (r *SQLDB) DefNode() ast.Node

func (*SQLDB) File added in v0.17.2

func (r *SQLDB) File() *File

func (*SQLDB) Ident added in v0.17.2

func (r *SQLDB) Ident() *ast.Ident

func (*SQLDB) NodeType added in v1.3.0

func (r *SQLDB) NodeType() NodeType

func (*SQLDB) Type added in v0.17.2

func (r *SQLDB) Type() ResourceType

type SelectorLookup added in v1.9.3

type SelectorLookup struct {
	// contains filtered or unexported fields
}

SelectorLookup is a helper cache for looking up services and RPC's by selector

func (*SelectorLookup) GetRPCs added in v1.9.3

func (sm *SelectorLookup) GetRPCs(targets selector.Set) (rtn []*RPC)

GetRPCs returns all the rpcs which match any of the given selectors

func (*SelectorLookup) GetServices added in v1.9.3

func (sm *SelectorLookup) GetServices(targets selector.Set) (rtn []*Service)

GetServices returns all services which match any of the given selectors

type Service

type Service struct {
	Name        string
	Root        *Package
	Pkgs        []*Package
	RPCs        []*RPC
	Middleware  []*Middleware
	ConfigLoads []*Config

	// Struct is the dependency injection struct, or nil if none exists.
	Struct *ServiceStruct
}

A Service is a Go package that defines one or more RPCs. Its name is defined by the Go package name. A Service may not be a located in a child directory of another service.

type ServiceStruct added in v1.5.0

type ServiceStruct struct {
	Name string
	Svc  *Service
	File *File // where the struct is defined
	Doc  string
	Decl *ast.TypeSpec
	RPCs []*RPC // RPCs defined on the service struct

	// Init is the function for initializing this group.
	// It is nil if there is no initialization function.
	Init     *ast.FuncDecl
	InitFile *File // where the init func is declared
}

ServiceStruct describes a dependency injection struct a particular service defines.

Jump to

Keyboard shortcuts

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