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 HTTPMethodRequiresCSRF(method string) bool
- func RouteParamsFromPath(route string) []source.RouteParam
- type API
- type Action
- type Asset
- type AssetKind
- type AuditApply
- type AuditPolicy
- type AuditRule
- type AuditSpec
- type AuditTest
- type Binding
- type BlockSpans
- type Blocks
- type BuildCall
- type ClientBehavior
- type Component
- type ComponentSpans
- type ContractBindingStatus
- type ContractKind
- type ContractReference
- type Diagnostic
- type Emit
- type EmitParam
- type Endpoint
- type EndpointCORS
- type EndpointKind
- type EndpointSource
- type Export
- type Fragment
- type FragmentEndpoint
- type GoBlock
- type GoEndpoint
- type GoRef
- type HeadResource
- type Import
- type Layout
- type LiteralRecord
- type Package
- type Page
- type PageMetadata
- type PageSpans
- type Program
- type Prop
- type QueryInvalidation
- type RealtimeSubscription
- type Route
- type RouteKind
- type SourceFile
- type SourceKind
- type StateContract
- type Store
- type StructuredData
- type Template
- type Use
- type WASMContract
Constants ¶
const ComponentExportActiveFlag = "active"
ComponentExportActiveFlag is reserved in generated exports payloads for the island mount-state flag.
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: 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 HTTPMethodRequiresCSRF ¶ added in v0.5.0
HTTPMethodRequiresCSRF reports whether a browser-reachable HTTP method should require generated CSRF validation by default.
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
CORS EndpointCORS
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 AuditApply ¶ added in v0.5.0
type AuditApply struct {
Selector string
Span source.SourceSpan
}
AuditApply records one selector applied to a declared policy.
type AuditPolicy ¶ added in v0.5.0
type AuditPolicy struct {
Name string
Extends []string
Applies []AuditApply
Rules []AuditRule
Span source.SourceSpan
}
AuditPolicy declares a composable policy that can extend other policies and apply rules to selectors.
type AuditRule ¶ added in v0.5.0
type AuditRule struct {
Kind string
Value string
Code string
Attrs map[string]string `json:"Attrs,omitempty"`
Span source.SourceSpan
}
AuditRule records one declared policy rule. Attrs carries structured arguments for rules that need more than a single value (for example a raw-HTML exception's owner, justification, expiry, and sanitizer contract).
type AuditSpec ¶ added in v0.5.0
type AuditSpec struct {
Source string
Package string
Policies []AuditPolicy
Tests []AuditTest
Span source.SourceSpan
}
AuditSpec is the normalized IR for one *.audit.gwdk source.
type AuditTest ¶ added in v0.5.0
type AuditTest struct {
Name string
Body string
Span source.SourceSpan
}
AuditTest preserves a declared test block for Phase 4 runtime verification.
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
ResultType string
ResultPointer bool
ResultFields []source.BackendResultField
}
Binding describes the selected Go backend handler when one is known.
type BlockSpans ¶
type BlockSpans struct {
Paths source.SourceSpan
Build source.SourceSpan
Server 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
PathsRecords []LiteralRecord `json:"-"`
Build bool
BuildBody string
BuildRecords []LiteralRecord `json:"-"`
BuildCall *BuildCall `json:"-"`
Server bool
ServerBody string
Client bool
ClientBody string
GoBlocks []GoBlock
View bool
ViewBody string
ViewNodes []viewmodel.Node `json:"-"`
Style bool
StyleBody string
Actions []Action
APIs []API
Fragments []FragmentEndpoint
Spans BlockSpans
}
type BuildCall ¶ added in v0.5.0
type BuildCall struct {
Alias string
Function string
Span source.SourceSpan
}
BuildCall is a parsed imported or same-package build data function call.
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
ResultFields []source.BackendInputField
Method string
Path string
Status ContractBindingStatus
Handler string
Register string
Message string
DeclarationSource string
DeclarationSpan source.SourceSpan
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 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
CORS EndpointCORS
DynamicParams []string
RouteParams []source.RouteParam
SourceFile string
Span source.SourceSpan
Binding Binding
}
Endpoint is framework-neutral backend endpoint metadata.
type EndpointCORS ¶ added in v0.12.0
type EndpointCORS struct {
Enabled bool
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
ExposedHeaders []string
AllowCredentials bool
AllowCredentialsSet bool
MaxAgeSeconds int
MaxAgeSet bool
Span source.SourceSpan
}
EndpointCORS is an endpoint-local CORS policy declaration. Empty option fields inherit from Build.CORS when it is enabled.
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 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.
func GoRefFromLiteral ¶ added in v0.5.0
GoRefFromLiteral parses a Go type literal such as "ui.CartState" or "CartState" into a GoRef. A single "pkg.Name" qualifier becomes the alias and name; an unqualified literal sets only the name (same-package type).
type HeadResource ¶ added in v0.7.0
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
ErrorPage string
Uses []Use
Blocks Blocks
Span source.SourceSpan
LayoutSpans []source.NamedSpan
ErrorPageSpan source.SourceSpan
PackageSpan source.SourceSpan
}
Layout is the normalized IR for one layout source.
type LiteralRecord ¶ added in v0.5.0
type LiteralRecord struct {
Fields map[string]string
Expressions map[string]string `json:"-"`
FieldOrder []string `json:"-"`
Span source.SourceSpan
}
LiteralRecord is a parsed literal record from paths {} or build {}.
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 PageMetadata struct {
Title string
Description string
Canonical string
Image string
Robots string
NoIndex bool
Preload []HeadResource
Prefetch []HeadResource
Structured []StructuredData
}
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
Robots source.SourceSpan
NoIndex source.SourceSpan
Preload []source.NamedSpan
Prefetch []source.NamedSpan
Structured []source.NamedSpan
Layouts []source.NamedSpan
Guard []source.NamedSpan
CSS []source.NamedSpan
JS []source.NamedSpan
InlineJS []source.NamedSpan
RouteParams []source.NamedSpan
}
type Program ¶
type Program struct {
Packages []Package
Pages []Page
Components []Component
Layouts []Layout
Routes []Route
Endpoints []Endpoint
GoEndpoints []GoEndpoint
Templates []Template
ContractRefs []ContractReference
RealtimeSubscriptions []RealtimeSubscription
QueryInvalidations []QueryInvalidation
AuditSpecs []AuditSpec
ClientBehaviors []ClientBehavior
Assets []Asset
Diagnostics []Diagnostic
}
Program is the normalized compiler IR produced from analyzed .gwdk sources.
type QueryInvalidation ¶ added in v0.5.0
type QueryInvalidation struct {
Query string
QueryImportAlias string
QueryImportPath string
QueryType string
Event string
EventImportPath string
EventType string
EventCategory string
Guards []string
Status ContractBindingStatus
Message string
OwnerKind SourceKind
OwnerID string
Package string
Source string
Span source.SourceSpan
}
QueryInvalidation records a bound query region that should refresh when a backend event type is emitted by a successful command.
type RealtimeSubscription ¶ added in v0.5.0
type RealtimeSubscription struct {
Query string
QueryImportAlias string
QueryImportPath string
QueryType string
Event string
EventImportAlias string
EventImportPath string
EventType string
EventCategory string
Roles []string
Guards []string
Status ContractBindingStatus
Handler string
Register string
Message string
OwnerKind SourceKind
OwnerID string
Package string
Source string
Span source.SourceSpan
QuerySpan source.SourceSpan
}
RealtimeSubscription records a query-bounded browser subscription to a presentation-event contract. Binding to Go contract metadata is a later analyzer step.
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" SourceAudit SourceKind = "audit" )
type StateContract ¶
type StateContract struct {
Type GoRef
Init GoRef
Span source.SourceSpan
}
type Store ¶
type Store struct {
Name string
Type GoRef
Init GoRef
// Persist is the optional `persist "<scope>"` modifier scope literal
// ("" when not persisted). Validated in the compiler, not the parser.
Persist string
// PersistSet reports whether a `persist` clause was present, so an explicit
// empty scope (`persist ""`) is diagnosed instead of treated as unpersisted.
PersistSet bool
Span source.SourceSpan
}
Store records one shared state declaration.
type StructuredData ¶ added in v0.10.0
type StructuredData struct {
Kind string
}
type Template ¶
type Template struct {
OwnerKind SourceKind
OwnerID string
Package string
Source string
Route string
Guards []string
Imports []Import
Uses []Use
Body string
Nodes []viewmodel.Node `json:"-"`
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
}