web

package
v0.3.34 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package web owns target-independent compilation support for trb/web.

Index

Constants

View Source
const (
	PackageName     = "trb/web"
	ModulePath      = "trb/web/index"
	ProjectProvider = "trb.web.routes"
)
View Source
const EndpointCatalogProtocolVersion = 1
View Source
const MaxBodyBytes = 1 << 20

MaxBodyBytes is the portable request body limit enforced by every adapter.

Variables

This section is empty.

Functions

func Analyze

func Analyze(sources []Source, resolutions map[string]resolver.Result, sourceRoot string) (*Manifest, []Issue)

func BuildEndpointCatalog added in v0.3.34

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 Declarations added in v0.3.34

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 Discover

func Discover(sources []Source, sourceRoot string) ([]Route, []Issue)

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 Issue

type Issue struct {
	Filename string
	Message  string
	Span     token.Span
}

type Manifest

type Manifest struct {
	Routes          []Route
	Middlewares     []Middleware
	EndpointCatalog EndpointCatalog
}

func ManifestFrom

func ManifestFrom(extensions []ir.Extension) *Manifest

func (*Manifest) ExtensionName

func (*Manifest) ExtensionName() string

func (*Manifest) MethodTargets

func (m *Manifest) MethodTargets() map[string]map[string]string

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 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

func UniquePathRoutes(routes []Route) []Route

UniquePathRoutes returns the first route for each path in manifest order. Handlers in one route file share the same path parameters and middleware.

type Source

type Source struct {
	Filename   string
	ModulePath string
	Program    *ast.Program
}

Jump to

Keyboard shortcuts

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