gwdkir

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package gwdkir defines the stable internal representation shared by GOWDK compiler passes after .gwdk AST analysis.

Index

Constants

View Source
const Version = 1

Variables

This section is empty.

Functions

func CachePolicyWithRevalidate added in v0.2.8

func CachePolicyWithRevalidate(cache string, revalidate string) string

CachePolicyWithRevalidate appends the page revalidation directive to an explicit Cache-Control policy.

func CheckInvariants added in v0.2.8

func CheckInvariants(program Program) error

CheckInvariants reports structural defects in a Program that indicate a compiler bug rather than an authoring error. The checks only assert what IR construction guarantees regardless of source validity: version stamping, deterministic ordering, closed enum values, and cross-slice references that the builder creates together (routes to pages, templates and assets to their owners). Authoring problems such as duplicate page IDs or conflicting routes are user-facing diagnostics owned by the compiler validators, not invariants.

func RouteParamsFromPath added in v0.2.8

func RouteParamsFromPath(route string) []source.RouteParam

RouteParamsFromPath parses dynamic route parameters from a route pattern of the form /path/{name}, /path/{name:type}, or /path/{name...}. Rest params are always string-typed.

Types

type API

type API struct {
	Name          string
	Method        string
	Route         string
	ErrorPage     string
	Span          source.SourceSpan
	RouteSpan     source.SourceSpan
	RouteParams   []source.NamedSpan
	ErrorPageSpan source.SourceSpan
}

type Action

type Action struct {
	Name           string
	Method         string
	Route          string
	Body           string
	InputName      string
	InputType      string
	ValidatesInput bool
	Redirect       string
	Fragments      []Fragment
	ErrorPage      string
	Span           source.SourceSpan
	RouteSpan      source.SourceSpan
	RouteParams    []source.NamedSpan
	InputSpan      source.SourceSpan
	ValidationSpan source.SourceSpan
	RedirectSpan   source.SourceSpan
	ErrorPageSpan  source.SourceSpan
}

type Asset

type Asset struct {
	Kind       AssetKind
	OwnerID    string
	Package    string
	Source     string
	Path       string
	Inline     string
	Name       string
	UseAlias   string
	UsePackage string
	ScopeID    string
	HashKey    string
	Span       source.SourceSpan
}

Asset records source-selected assets and future generated assets.

type AssetKind

type AssetKind string
const (
	AssetCSS  AssetKind = "css"
	AssetJS   AssetKind = "js"
	AssetFile AssetKind = "asset"
	AssetWASM AssetKind = "wasm"
)

type Binding

type Binding struct {
	Status       source.BackendBindingStatus
	Message      string
	ImportPath   string
	PackageName  string
	FunctionName string
	Signature    source.BackendSignatureKind
	InputType    string
	InputPointer bool
	InputFields  []source.BackendInputField
}

Binding describes the selected Go backend handler when one is known.

type BlockSpans

type BlockSpans struct {
	Paths         source.SourceSpan
	Build         source.SourceSpan
	Load          source.SourceSpan
	Client        source.SourceSpan
	GoBlocks      []source.NamedSpan
	View          source.SourceSpan
	ViewBodyStart source.SourcePosition
	Actions       []source.NamedSpan
	APIs          []source.NamedSpan
	Fragments     []source.NamedSpan
	Exports       source.SourceSpan
	Emits         source.SourceSpan
}

type Blocks

type Blocks struct {
	Paths      bool
	PathsBody  string
	Build      bool
	BuildBody  string
	Load       bool
	LoadBody   string
	Client     bool
	ClientBody string
	GoBlocks   []GoBlock
	View       bool
	ViewBody   string
	Style      bool
	StyleBody  string
	Actions    []Action
	APIs       []API
	Fragments  []FragmentEndpoint
	Spans      BlockSpans
}

type ClientBehavior

type ClientBehavior struct {
	Component string
	Package   string
	Source    string
	Body      string
	Span      source.SourceSpan
}

ClientBehavior records a compiler-owned client block. The body is retained until the client language has a dedicated full AST.

type Component

type Component struct {
	Source      string
	Package     string
	Name        string
	Imports     []Import
	Uses        []Use
	CSS         []string
	JS          []string
	InlineJS    []source.InlineScript
	Assets      []string
	Props       []Prop
	PropsType   GoRef
	State       StateContract
	WASM        WASMContract
	Exports     []Export
	Emits       []Emit
	Blocks      Blocks
	Span        source.SourceSpan
	PackageSpan source.SourceSpan
	Spans       ComponentSpans
}

Component is the normalized IR for one component source.

type ComponentSpans

type ComponentSpans struct {
	CSS      []source.NamedSpan
	JS       []source.NamedSpan
	InlineJS []source.NamedSpan
	Assets   []source.NamedSpan
}

type ContractBindingStatus

type ContractBindingStatus string
const (
	ContractBindingUnknown ContractBindingStatus = "unknown"
	ContractBindingBound   ContractBindingStatus = "bound"
	ContractBindingMissing ContractBindingStatus = "missing"
	ContractBindingInvalid ContractBindingStatus = "invalid"
)

type ContractKind

type ContractKind string
const (
	ContractCommand ContractKind = "command"
	ContractQuery   ContractKind = "query"
)

type ContractReference

type ContractReference struct {
	Kind        ContractKind
	Name        string
	ImportAlias string
	ImportPath  string
	Type        string
	Result      string
	Roles       []string
	Guards      []string
	InputFields []source.BackendInputField
	Method      string
	Path        string
	Status      ContractBindingStatus
	Handler     string
	Register    string
	Message     string
	OwnerKind   SourceKind
	OwnerID     string
	Package     string
	Source      string
	Span        source.SourceSpan
}

ContractReference records a source-level reference to a backend contract. Binding to Go contract metadata is a later analyzer step.

type Diagnostic added in v0.3.0

type Diagnostic struct {
	Code    string
	Source  string
	Span    source.SourceSpan
	Message string
}

Diagnostic records an author-facing problem found while assembling IR.

type Emit

type Emit struct {
	Name   string
	Params []EmitParam
	Span   source.SourceSpan
}

type EmitParam

type EmitParam struct {
	Name string
	Type string
	Span source.SourceSpan
}

type Endpoint

type Endpoint struct {
	Kind          EndpointKind
	Source        EndpointSource
	Package       string
	PageID        string
	Symbol        string
	Method        string
	Path          string
	Cache         string
	Guards        []string
	CSRF          bool
	ErrorPage     string
	DynamicParams []string
	SourceFile    string
	Span          source.SourceSpan
	Binding       Binding
}

Endpoint is framework-neutral backend endpoint metadata.

type EndpointKind

type EndpointKind string
const (
	EndpointAction   EndpointKind = "action"
	EndpointAPI      EndpointKind = "api"
	EndpointFragment EndpointKind = "fragment"
)

type EndpointSource

type EndpointSource string
const (
	EndpointSourceGOWDK EndpointSource = "gwdk"
	EndpointSourceGo    EndpointSource = "go"
)

type Export

type Export struct {
	Name string
	Type string
	Span source.SourceSpan
}

type Fragment

type Fragment struct {
	Target string
	Body   string
	Span   source.SourceSpan
}

type FragmentEndpoint

type FragmentEndpoint struct {
	Name        string
	Method      string
	Route       string
	Target      string
	Body        string
	Span        source.SourceSpan
	RouteSpan   source.SourceSpan
	TargetSpan  source.SourceSpan
	RouteParams []source.NamedSpan
}

type GeneratedFile

type GeneratedFile struct {
	Path    string
	Kind    string
	OwnerID string
}

type GeneratedGoPackage

type GeneratedGoPackage struct {
	Name    string
	Path    string
	Purpose string
	Imports []Import
}

type GeneratedOutput

type GeneratedOutput struct {
	GoPackages []GeneratedGoPackage
	Files      []GeneratedFile
}

GeneratedOutput is the stable planning shape for generated artifacts.

type GoBlock

type GoBlock struct {
	Target string
	Body   string
	Span   source.SourceSpan
}

GoBlock records one optional inline Go authoring block preserved for the extraction pipeline.

type GoEndpoint added in v0.2.8

type GoEndpoint struct {
	Kind          string
	SourceKind    EndpointSource
	Package       string
	Source        string
	Name          string
	Method        string
	Route         string
	ErrorPage     string
	Span          source.SourceSpan
	RouteSpan     source.SourceSpan
	RouteParams   []source.NamedSpan
	ErrorPageSpan source.SourceSpan
}

GoEndpoint preserves a standalone Go endpoint declaration (discovered from `//gowdk:` comments) in its raw source-level form. Program.Endpoints holds the normalized, codegen-ready endpoints with bindings attached, which is lossy for validation (it collapses the raw kind, normalizes the method, and drops the route/error-page spans). Keeping the raw declaration here lets validation read the exact kind, method, and spans the author wrote with no information loss. Fields mirror the parser/discovery output one-to-one.

type GoRef

type GoRef struct {
	Alias string
	Name  string
	Span  source.SourceSpan
}

GoRef points at an imported Go package symbol.

type Import

type Import struct {
	Alias string
	Path  string
	Span  source.SourceSpan
}

Import records a Go package import used by analyzed source.

type Layout

type Layout struct {
	Source      string
	Package     string
	ID          string
	Layouts     []string
	Uses        []Use
	Blocks      Blocks
	Span        source.SourceSpan
	LayoutSpans []source.NamedSpan
	PackageSpan source.SourceSpan
}

Layout is the normalized IR for one layout source.

type Package

type Package struct {
	Name       string
	SourceDirs []string
	Files      []SourceFile
	Imports    []Import
	Uses       []Use
	Stores     []Store
}

Package groups analyzed GOWDK source files by declared package.

type Page

type Page struct {
	Source      string
	Package     string
	ID          string
	Route       string
	RouteParams []source.RouteParam
	Render      gowdk.RenderMode
	Cache       string
	Revalidate  string
	ErrorPage   string
	Metadata    PageMetadata
	Layouts     []string
	Guards      []string
	CSS         []string
	JS          []string
	InlineJS    []source.InlineScript
	Imports     []Import
	Uses        []Use
	Stores      []Store
	Blocks      Blocks
	LoadBinding Binding
	Spans       PageSpans
}

Page is the normalized IR for one page source.

func (Page) CachePolicy added in v0.2.8

func (page Page) CachePolicy() string

CachePolicy returns the concrete Cache-Control policy generated for the page.

func (Page) DynamicParams added in v0.2.8

func (page Page) DynamicParams() []string

DynamicParams returns route parameters declared with /path/{param} syntax.

func (Page) HasGoBlock added in v0.2.8

func (page Page) HasGoBlock(target string) bool

HasGoBlock reports whether the page declares a go block for target.

func (Page) RenderMode added in v0.2.8

func (page Page) RenderMode(defaultMode gowdk.RenderMode) gowdk.RenderMode

RenderMode resolves the effective render mode for the page, defaulting to SSR when the page declares request-time behavior and otherwise to defaultMode (SPA when unset).

func (Page) TypedRouteParams added in v0.2.8

func (page Page) TypedRouteParams() []source.RouteParam

TypedRouteParams returns route params with explicit type metadata. Untyped params are reported as string. Declared params are merged with params parsed from the route path so trailing rest params such as {path...}, which lowering does not extract, are still reported.

type PageMetadata

type PageMetadata struct {
	Title       string
	Description string
	Canonical   string
	Image       string
}

type PageSpans

type PageSpans struct {
	Package     source.SourceSpan
	Page        source.SourceSpan
	Route       source.SourceSpan
	Render      source.SourceSpan
	Cache       source.SourceSpan
	Revalidate  source.SourceSpan
	ErrorPage   source.SourceSpan
	Title       source.SourceSpan
	Description source.SourceSpan
	Canonical   source.SourceSpan
	Image       source.SourceSpan
	Layouts     []source.NamedSpan
	Guard       []source.NamedSpan
	CSS         []source.NamedSpan
	JS          []source.NamedSpan
	InlineJS    []source.NamedSpan
	RouteParams []source.NamedSpan
}

type Program

type Program struct {
	Version         int
	Packages        []Package
	Pages           []Page
	Components      []Component
	Layouts         []Layout
	Routes          []Route
	Endpoints       []Endpoint
	GoEndpoints     []GoEndpoint
	Templates       []Template
	ContractRefs    []ContractReference
	ClientBehaviors []ClientBehavior
	Assets          []Asset
	Diagnostics     []Diagnostic
	Generated       GeneratedOutput
}

Program is the normalized compiler IR produced from analyzed .gwdk sources.

type Prop

type Prop struct {
	Name string
	Type string
	Span source.SourceSpan
}

type Route

type Route struct {
	Kind          RouteKind
	Method        string
	Path          string
	PageID        string
	Package       string
	Render        gowdk.RenderMode
	Cache         string
	DynamicParams []string
	RouteParams   []source.RouteParam
	Layouts       []string
	Guards        []string
	Source        string
	Span          source.SourceSpan
}

Route is page/file route metadata. Endpoint behavior is represented by Endpoint, not by route kinds.

type RouteKind

type RouteKind string
const (
	RouteStatic RouteKind = "static"
	RouteSPA    RouteKind = "spa"
	RouteSSR    RouteKind = "ssr"
	RouteHybrid RouteKind = "hybrid"
)

type SourceFile

type SourceFile struct {
	Path    string
	Kind    SourceKind
	Package string
	Name    string
	Span    source.SourceSpan
}

SourceFile records one analyzed source file.

type SourceKind

type SourceKind string
const (
	SourcePage      SourceKind = "page"
	SourceComponent SourceKind = "component"
	SourceLayout    SourceKind = "layout"
)

type StateContract

type StateContract struct {
	Type GoRef
	Init GoRef
	Span source.SourceSpan
}

type Store

type Store struct {
	Name string
	Type GoRef
	Init GoRef
	Span source.SourceSpan
}

Store records one shared state declaration.

type Template

type Template struct {
	OwnerKind SourceKind
	OwnerID   string
	Package   string
	Source    string
	Route     string
	Guards    []string
	Imports   []Import
	Body      string
	Span      source.SourceSpan
	BodyStart source.SourcePosition
}

Template records a renderable view block.

type Use

type Use struct {
	Alias   string
	Package string
	Span    source.SourceSpan
}

Use records an explicit GOWDK package import.

type WASMContract

type WASMContract struct {
	Package string
	Span    source.SourceSpan
}

Jump to

Keyboard shortcuts

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