web

package
v0.3.44 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 17 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 DefaultBrowserClientName = "ApiClient"
View Source
const EndpointCatalogProtocolVersion = 1
View Source
const MaxBodyBytes = 1 << 20

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

View Source
const OpenAPIVersion = "3.1.0"

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 BuildOpenAPI added in v0.3.35

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

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 BrowserClientIssue added in v0.3.39

type BrowserClientIssue struct {
	ModulePath string
	Message    string
	Span       packageextension.SourceSpan
}

BrowserClientIssue is a source-located endpoint contract problem that only prevents browser client generation. It does not make trb check fail.

func BuildBrowserClient added in v0.3.39

BuildBrowserClient generates a checked TypeRB facade over the existing TypeScript browser HttpClient. Endpoint records stay in their authored shared modules; the generated source imports rather than copies them.

type BrowserClientOptions added in v0.3.39

type BrowserClientOptions struct {
	Name string
}

BrowserClientOptions selects application-owned names in the generated TypeRB source. The transport and endpoint surface remain package-owned.

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 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 OpenAPIInfo struct {
	Title   string `json:"title"`
	Version string `json:"version"`
}

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

type OpenAPIOptions struct {
	Title   string
	Version string
}

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

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