Documentation
¶
Overview ¶
Package gwdkir defines the stable internal representation shared by GOWDK compiler passes after .gwdk AST analysis.
Index ¶
- Constants
- func CachePolicyWithRevalidate(cache string, revalidate string) string
- func CheckInvariants(program Program) error
- func RouteParamsFromPath(route string) []source.RouteParam
- type API
- type Action
- type Asset
- type AssetKind
- type Binding
- type BlockSpans
- type Blocks
- type ClientBehavior
- type Component
- type ComponentSpans
- type ContractBindingStatus
- type ContractKind
- type ContractReference
- type Emit
- type EmitParam
- type Endpoint
- type EndpointKind
- type EndpointSource
- type Export
- type Fragment
- type FragmentEndpoint
- type GeneratedFile
- type GeneratedGoPackage
- type GeneratedOutput
- type GoBlock
- type GoEndpoint
- type GoRef
- type Import
- type Layout
- type Package
- type Page
- type PageMetadata
- type PageSpans
- type Program
- type Prop
- type Route
- type RouteKind
- type SourceFile
- type SourceKind
- type StateContract
- type Store
- type Template
- type Use
- type WASMContract
Constants ¶
const Version = 1
Variables ¶
This section is empty.
Functions ¶
func CachePolicyWithRevalidate ¶ added in v0.2.8
CachePolicyWithRevalidate appends the page revalidation directive to an explicit Cache-Control policy.
func CheckInvariants ¶ added in v0.2.8
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 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 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 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 Endpoint ¶
type Endpoint struct {
Kind EndpointKind
Source EndpointSource
Package string
PageID string
Symbol string
Method string
Path string
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 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 GeneratedGoPackage ¶
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
CachePolicy returns the concrete Cache-Control policy generated for the page.
func (Page) DynamicParams ¶ added in v0.2.8
DynamicParams returns route parameters declared with /path/{param} syntax.
func (Page) HasGoBlock ¶ added in v0.2.8
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 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
Generated GeneratedOutput
}
Program is the normalized compiler IR produced from analyzed .gwdk sources.
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 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
}