Documentation
¶
Overview ¶
Package web owns target-independent compilation support for trb/web.
Index ¶
- Constants
- func Analyze(sources []Source, resolutions map[string]resolver.Result, sourceRoot string) (*Manifest, []Issue)
- func BuildEndpointCatalog(input packageextension.ProjectDeclarationInput, routes []Route) (EndpointCatalog, []EndpointContractIssue, error)
- func BuildOpenAPI(catalog EndpointCatalog, input packageextension.ProjectDeclarationInput, ...) (OpenAPIDocument, []OpenAPIIssue, error)
- func Declarations(input packageextension.ProjectDeclarationInput) (*declaration.Catalog, error)
- func Discover(sources []Source, sourceRoot string) ([]Route, []Issue)
- func ValidateEndpointCatalog(catalog EndpointCatalog) error
- type EndpointCatalog
- type EndpointContract
- type EndpointContractIssue
- type EndpointResponse
- type Issue
- type Manifest
- type Middleware
- type OpenAPIComponents
- type OpenAPIDocument
- type OpenAPIInfo
- type OpenAPIIssue
- type OpenAPIMediaType
- type OpenAPIOperation
- type OpenAPIOptions
- type OpenAPIParameter
- type OpenAPIPathItem
- type OpenAPIRequestBody
- type OpenAPIResponse
- type OpenAPISchema
- type Route
- type Source
Constants ¶
const ( PackageName = "trb/web" ModulePath = "trb/web/index" ProjectProvider = "trb.web.routes" )
const EndpointCatalogProtocolVersion = 1
const MaxBodyBytes = 1 << 20
MaxBodyBytes is the portable request body limit enforced by every adapter.
const OpenAPIVersion = "3.1.0"
Variables ¶
This section is empty.
Functions ¶
func BuildEndpointCatalog ¶ added in v0.3.34
func BuildEndpointCatalog(input packageextension.ProjectDeclarationInput, routes []Route) (EndpointCatalog, []EndpointContractIssue, error)
BuildEndpointCatalog validates authored endpoint declarations and binds them to the routes discovered from the same project. Routes without a contract remain valid; a contract must map to exactly one local file-route handler.
func BuildOpenAPI ¶ added in v0.3.35
func BuildOpenAPI(catalog EndpointCatalog, input packageextension.ProjectDeclarationInput, options OpenAPIOptions) (OpenAPIDocument, []OpenAPIIssue, error)
BuildOpenAPI turns package-owned endpoint and declaration protocols into an OpenAPI 3.1 document without reading compiler AST or backend IR.
func Declarations ¶ added in v0.3.34
func Declarations(input packageextension.ProjectDeclarationInput) (*declaration.Catalog, error)
Declarations returns the generic declaration capabilities required by endpoint contract classes. Calls remain ordinary, type-checked trb/web functions; only exact Endpoint subclasses discovered from this data-only project snapshot may treat them as non-runtime declarations.
func ValidateEndpointCatalog ¶ added in v0.3.34
func ValidateEndpointCatalog(catalog EndpointCatalog) error
Types ¶
type EndpointCatalog ¶ added in v0.3.34
type EndpointCatalog struct {
ProtocolVersion int `json:"protocolVersion"`
Package string `json:"package"`
Endpoints []EndpointContract `json:"endpoints,omitempty"`
}
EndpointCatalog is the versioned, target-independent contract exposed by trb/web. It binds authored endpoint declarations to file-based routes while retaining portable TypeRB type uses for downstream tools such as OpenAPI generators. It never contains parser nodes, checked method bodies, or backend-specific data.
type EndpointContract ¶ added in v0.3.34
type EndpointContract struct {
Name string `json:"name"`
ModulePath string `json:"modulePath"`
Handler string `json:"handler"`
Method string `json:"method"`
Path string `json:"path"`
Input *packageextension.ProjectTypeUse `json:"input,omitempty"`
Responses []EndpointResponse `json:"responses"`
Span packageextension.SourceSpan `json:"span"`
}
type EndpointContractIssue ¶ added in v0.3.34
type EndpointContractIssue struct {
ModulePath string
Message string
Span packageextension.SourceSpan
}
type EndpointResponse ¶ added in v0.3.34
type EndpointResponse struct {
Status int `json:"status"`
Type packageextension.ProjectTypeUse `json:"type"`
Span packageextension.SourceSpan `json:"span"`
}
type Manifest ¶
type Manifest struct {
Routes []Route
Middlewares []Middleware
EndpointCatalog EndpointCatalog
}
func ManifestFrom ¶
func (*Manifest) ExtensionName ¶
type Middleware ¶
type Middleware struct {
Filename string
Directory string
ModulePath string
Handler string
TargetHandler string
Span token.Span
}
func NestedMiddlewares ¶ added in v0.2.3
func NestedMiddlewares(middlewares []Middleware) []Middleware
NestedMiddlewares returns middleware that is scoped below the route root. Root middleware is applied once around the complete dispatcher instead.
func RootMiddlewares ¶ added in v0.2.3
func RootMiddlewares(middlewares []Middleware) []Middleware
RootMiddlewares returns the middleware that applies to every request, including responses produced before or after route matching.
type OpenAPIComponents ¶ added in v0.3.35
type OpenAPIComponents struct {
Schemas map[string]OpenAPISchema `json:"schemas"`
}
type OpenAPIDocument ¶ added in v0.3.35
type OpenAPIDocument struct {
OpenAPI string `json:"openapi"`
Info OpenAPIInfo `json:"info"`
Paths map[string]OpenAPIPathItem `json:"paths"`
Components *OpenAPIComponents `json:"components,omitempty"`
}
OpenAPIDocument is the portable OpenAPI representation produced from the trb/web endpoint catalog. The model intentionally covers only fields emitted by TypeRB so additions can remain deliberate and deterministic.
type OpenAPIInfo ¶ added in v0.3.35
type OpenAPIIssue ¶ added in v0.3.35
type OpenAPIIssue struct {
ModulePath string
Message string
Span packageextension.SourceSpan
}
OpenAPIIssue is a source-located application contract problem. OpenAPI-only restrictions are reported when generation is requested and do not make an otherwise portable TypeRB project fail trb check.
type OpenAPIMediaType ¶ added in v0.3.35
type OpenAPIMediaType struct {
Schema OpenAPISchema `json:"schema"`
}
type OpenAPIOperation ¶ added in v0.3.35
type OpenAPIOperation struct {
OperationID string `json:"operationId"`
Parameters []OpenAPIParameter `json:"parameters,omitempty"`
RequestBody *OpenAPIRequestBody `json:"requestBody,omitempty"`
Responses map[string]OpenAPIResponse `json:"responses"`
}
type OpenAPIOptions ¶ added in v0.3.35
OpenAPIOptions contains document metadata owned by the application rather than by an individual endpoint contract.
type OpenAPIParameter ¶ added in v0.3.35
type OpenAPIParameter struct {
Name string `json:"name"`
In string `json:"in"`
Required bool `json:"required,omitempty"`
Schema OpenAPISchema `json:"schema"`
}
type OpenAPIPathItem ¶ added in v0.3.35
type OpenAPIPathItem map[string]OpenAPIOperation
type OpenAPIRequestBody ¶ added in v0.3.35
type OpenAPIRequestBody struct {
Required bool `json:"required,omitempty"`
Content map[string]OpenAPIMediaType `json:"content"`
}
type OpenAPIResponse ¶ added in v0.3.35
type OpenAPIResponse struct {
Description string `json:"description"`
Content map[string]OpenAPIMediaType `json:"content,omitempty"`
}
type OpenAPISchema ¶ added in v0.3.35
type OpenAPISchema struct {
Ref string `json:"$ref,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Pattern string `json:"pattern,omitempty"`
Enum []any `json:"enum,omitempty"`
Properties map[string]OpenAPISchema `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
Items *OpenAPISchema `json:"items,omitempty"`
AdditionalProperties *OpenAPISchema `json:"additionalProperties,omitempty"`
AnyOf []OpenAPISchema `json:"anyOf,omitempty"`
Minimum *int64 `json:"minimum,omitempty"`
Maximum *int64 `json:"maximum,omitempty"`
}
type Route ¶
type Route struct {
Filename string
Directory string
Method string
Path string
ModulePath string
Handler string
TargetHandler string
PathParameters []string
Middlewares []Middleware
Span token.Span
}
func UniquePathRoutes ¶
UniquePathRoutes returns the first route for each path in manifest order. Handlers in one route file share the same path parameters and middleware.