parser

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveConnectionRef

func ResolveConnectionRef(expr hcl.Expression) (string, error)

ResolveConnectionRef extracts the connection identifier string from an HCL expression. It handles unquoted traversals (e.g. connection.postgres.main) and string literals (e.g. connection: "postgres.main").

func ResolveSchemaRef

func ResolveSchemaRef(expr hcl.Expression) (string, error)

ResolveSchemaRef extracts the schema identifier string from an HCL expression (e.g. schema.user_create -> "user_create").

Types

type ConnectionBlock

type ConnectionBlock struct {
	Driver string               `hcl:"driver,label"`
	Name   string               `hcl:"name,label"`
	URL    string               `hcl:"url,attr"`
	Pool   *ConnectionPoolBlock `hcl:"pool,block"`
	Remain hcl.Body             `hcl:",remain"`
}

ConnectionBlock represents a connection pool configuration block.

func (*ConnectionBlock) ToConnection

func (c *ConnectionBlock) ToConnection() (manifest.Connection, error)

ToConnection maps the AST ConnectionBlock into a pure domain manifest.Connection with defaults applied.

type ConnectionPoolBlock

type ConnectionPoolBlock struct {
	MaxOpenConns    *int     `hcl:"max_open_conns,optional"`
	MaxIdleConns    *int     `hcl:"max_idle_conns,optional"`
	ConnMaxLifetime *string  `hcl:"conn_max_lifetime,optional"`
	IdleTimeout     *string  `hcl:"idle_timeout,optional"`
	Size            *int     `hcl:"size,optional"`
	Remain          hcl.Body `hcl:",remain"`
}

ConnectionPoolBlock represents connection pool tuning parameters.

type EndpointBlock

type EndpointBlock struct {
	MethodAndPath string                `hcl:"name,label"`
	Description   *string               `hcl:"description,attr"`
	Request       *RequestBlock         `hcl:"request,block"`
	Pipeline      *PipelineBlock        `hcl:"pipeline,block"`
	OpenAPI       *EndpointOpenAPIBlock `hcl:"openapi,block"`
	Remain        hcl.Body              `hcl:",remain"`
}

EndpointBlock represents a single HTTP route declaration block.

type EndpointOpenAPIBlock

type EndpointOpenAPIBlock struct {
	UI           *string  `hcl:"ui,optional"`
	Format       *string  `hcl:"format,optional"`
	SpecURL      *string  `hcl:"spec_url,optional"`
	Template     *string  `hcl:"template,optional"`
	TemplateFile *string  `hcl:"template_file,optional"`
	Remain       hcl.Body `hcl:",remain"`
}

EndpointOpenAPIBlock represents the endpoint.openapi {} metadata block in endpoint.

type FieldBlock

type FieldBlock struct {
	Name        string         `hcl:"name,label"`
	Type        hcl.Expression `hcl:"type,attr"`
	Required    bool           `hcl:"required,optional"`
	Default     hcl.Expression `hcl:"default,optional"`
	Description *string        `hcl:"description,optional"`
	Enum        hcl.Expression `hcl:"enum,optional"`
	Format      *string        `hcl:"format,optional"`
	Pattern     *string        `hcl:"pattern,optional"`
	MinLength   *int           `hcl:"min_length,optional"`
	MaxLength   *int           `hcl:"max_length,optional"`
	Min         *float64       `hcl:"min,optional"`
	Max         *float64       `hcl:"max,optional"`
	MinItems    *int           `hcl:"min_items,optional"`
	MaxItems    *int           `hcl:"max_items,optional"`
	UniqueItems bool           `hcl:"unique_items,optional"`
	Remain      hcl.Body       `hcl:",remain"`
}

FieldBlock defines a single field's data type, presence, defaults, and validation constraints.

func (*FieldBlock) ToField

func (f *FieldBlock) ToField(evalCtx *hcl.EvalContext) (manifest.Field, error)

ToField maps the AST FieldBlock into a pure domain manifest.Field with defaults applied.

type FieldGroupBlock

type FieldGroupBlock struct {
	Fields []FieldBlock `hcl:"field,block"`
	Remain hcl.Body     `hcl:",remain"`
}

FieldGroupBlock represents a collection of field validation rules (for path, query, headers, or inline body).

type GoStepBlock

type GoStepBlock struct {
	Use  string         `hcl:"use,attr"`
	Args hcl.Expression `hcl:"args,optional"`
}

GoStepBlock defines invocation settings for a custom Go handler step.

type Manifest

type Manifest struct {
	Server      *ServerBlock      `hcl:"server,block"`
	Connections []ConnectionBlock `hcl:"connection,block"`
	Schemas     []SchemaBlock     `hcl:"schema,block"`
	Endpoints   []EndpointBlock   `hcl:"endpoint,block"`
	Remain      hcl.Body          `hcl:",remain"`
}

Manifest represents the root collection of merged HCL route definitions.

func Parse

func Parse(path string, evalCtx *hcl.EvalContext) (*Manifest, error)

Parse reads a file or directory tree and returns the merged Manifest AST.

type ParsedStep

type ParsedStep struct {
	Type     StepType
	Name     string
	Go       *GoStepBlock
	Starlark *StarlarkStepBlock
	SQL      *SQLStepBlock
	Respond  *RespondStepBlock
}

ParsedStep is an intermediate representation of a sequential step in a pipeline.

func DecodePipelineSteps

func DecodePipelineSteps(pipeline *PipelineBlock) ([]ParsedStep, error)

DecodePipelineSteps decodes steps from a pipeline block preserving declaration order.

type PipelineBlock

type PipelineBlock struct {
	Body hcl.Body `hcl:",remain"`
}

PipelineBlock encapsulates the raw HCL body of pipeline steps to preserve definition order.

type RequestBlock

type RequestBlock struct {
	PathInline    *FieldGroupBlock
	PathExpr      hcl.Expression
	QueryInline   *FieldGroupBlock
	QueryExpr     hcl.Expression
	HeadersInline *FieldGroupBlock
	HeadersExpr   hcl.Expression
	BodyInline    *FieldGroupBlock
	BodyExpr      hcl.Expression
	Remain        hcl.Body `hcl:",remain"`
}

RequestBlock represents parameter and body validation rules for an endpoint.

func (*RequestBlock) Decode

func (r *RequestBlock) Decode(evalCtx *hcl.EvalContext) error

Decode extracts inline field blocks or schema reference expressions for path, query, headers, and body.

type RespondStepBlock

type RespondStepBlock struct {
	Condition hcl.Expression `hcl:"condition,optional"`
	Status    hcl.Expression `hcl:"status,optional"`
	Headers   hcl.Expression `hcl:"headers,optional"`
	Body      hcl.Expression `hcl:"body,optional"`
}

RespondStepBlock defines the parameters for serializing an HTTP response.

type SQLCatchBlock

type SQLCatchBlock struct {
	Code    string         `hcl:"code,label"`
	Status  hcl.Expression `hcl:"status,optional"`
	Headers hcl.Expression `hcl:"headers,optional"`
	Body    hcl.Expression `hcl:"body,optional"`
	Remain  hcl.Body       `hcl:",remain"`
}

SQLCatchBlock defines error code interception and response payload mapping for a SQL step.

type SQLStepBlock

type SQLStepBlock struct {
	Connection hcl.Expression  `hcl:"connection,attr"`
	Query      string          `hcl:"query,attr"`
	Args       hcl.Expression  `hcl:"args,optional"`
	Catches    []SQLCatchBlock `hcl:"catch,block"`
	Remain     hcl.Body        `hcl:",remain"`
}

SQLStepBlock defines the SQL query to execute.

type SchemaBlock

type SchemaBlock struct {
	Name        string       `hcl:"name,label"`
	Description *string      `hcl:"description,optional"`
	Fields      []FieldBlock `hcl:"field,block"`
	Remain      hcl.Body     `hcl:",remain"`
}

SchemaBlock represents a reusable request payload schema definition block.

type ServerBlock

type ServerBlock struct {
	Host         string              `hcl:"host,optional"`
	Port         int                 `hcl:"port,optional"`
	ReadTimeout  *string             `hcl:"read_timeout,optional"`
	WriteTimeout *string             `hcl:"write_timeout,optional"`
	IdleTimeout  *string             `hcl:"idle_timeout,optional"`
	MaxBodySize  *string             `hcl:"max_body_size,optional"`
	Problem      *ServerProblemBlock `hcl:"problem,block"`
	OpenAPI      *ServerOpenAPIBlock `hcl:"openapi,block"`
	Remain       hcl.Body            `hcl:",remain"`
}

ServerBlock represents the raw HCL server syntax block.

func (*ServerBlock) ToServer

func (s *ServerBlock) ToServer() (manifest.Server, error)

ToServer maps the AST ServerBlock into a pure domain manifest.Server with defaults applied.

type ServerContactBlock

type ServerContactBlock struct {
	Name  *string `hcl:"name,optional"`
	Email *string `hcl:"email,optional"`
	URL   *string `hcl:"url,optional"`
}

ServerContactBlock represents the contact {} metadata block in openapi block.

type ServerLicenseBlock

type ServerLicenseBlock struct {
	Name *string `hcl:"name,optional"`
	URL  *string `hcl:"url,optional"`
}

ServerLicenseBlock represents the license {} metadata block in openapi block.

type ServerOpenAPIBlock

type ServerOpenAPIBlock struct {
	Title       *string             `hcl:"title,optional"`
	Version     *string             `hcl:"version,optional"`
	Description *string             `hcl:"description,optional"`
	Servers     hcl.Expression      `hcl:"servers,optional"`
	Tags        hcl.Expression      `hcl:"tags,optional"`
	Contact     *ServerContactBlock `hcl:"contact,block"`
	License     *ServerLicenseBlock `hcl:"license,block"`
	Remain      hcl.Body            `hcl:",remain"`
}

ServerOpenAPIBlock represents the global openapi {} metadata block in server.

type ServerProblemBlock added in v0.1.2

type ServerProblemBlock struct {
	TypePrefix *string `hcl:"type_prefix,optional"`
}

ServerProblemBlock represents the global problem {} metadata block in server.

type StarlarkStepBlock

type StarlarkStepBlock struct {
	Source string `hcl:"source,attr"`
}

StarlarkStepBlock defines the script source for a Starlark step.

type StepType

type StepType string

StepType defines the runner category for a pipeline step.

const (
	StepTypeGo       StepType = "go"
	StepTypeStarlark StepType = "starlark"
	StepTypeSQL      StepType = "sql"
	StepTypeRespond  StepType = "respond"
)

StepType constants represent the runner category for a pipeline step.

Jump to

Keyboard shortcuts

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