generate

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package generate turns an app's pages/ folder into Go code, assets and live-page scripts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHeld

func CheckHeld(app string, apps map[string]string) ([]string, error)

CheckHeld checks the snapshots that the app named app holds, as CheckSnapshots does for every app of apps.

func CheckSnapshots

func CheckSnapshots(apps map[string]string) ([]string, error)

CheckSnapshots checks every snapshot of a called app that an app of the workspace holds, .aicoded/services/<app>.json, against the called app's current .aicoded/rpc.json. apps maps each app's name to its folder. It fails with E-RPC-013 at the first held snapshot the called app breaks, and returns one warning for each held app that is not in apps.

func Generate

func Generate(dir string) error

Generate turns the app in dir into generated code: its pages/ folder into Go code and assets, its rpc/ package into the method table and codec the app serves other apps with, pinning the field numbers in .aicoded/rpc.json, and the snapshots in .aicoded/services/ into the clients of the apps it calls. It writes the access and services sections of the app's permission list, aicoded.yaml, when the app has one. It writes nothing unless every step succeeds and the permission list can take the sections. It is Run with the apps next to dir as the workspace.

func HeldApps

func HeldApps(dir string) ([]string, error)

HeldApps returns the apps whose snapshots the app in dir holds in .aicoded/services/, by the names of their files, sorted. It never follows a symbolic link out of dir.

func WriteFile

func WriteFile(dir, name string, data []byte) error

WriteFile writes data at name, a slash-separated path in the app folder dir, the way Generate writes a snapshot: atomically, with mode 0644, creating missing folders with mode 0755, and never following a symbolic link out of dir.

Types

type App

type App struct {
	Dir    string
	Module string
	Deps   bool
}

App is an app's source tree: pages/, an optional deps/ package and go.mod.

type Diagnostics

type Diagnostics []*errs.Error

Diagnostics is every coded problem one run found, so all broken templates are reported at once.

func (Diagnostics) Err

func (d Diagnostics) Err() error

Err returns d sorted by position, or nil when it is empty.

func (Diagnostics) Error

func (d Diagnostics) Error() string

func (Diagnostics) Unwrap

func (d Diagnostics) Unwrap() []error

Unwrap returns the diagnostics as errors, so errors.As and errs.Code find the first one.

type FieldInfo

type FieldInfo struct {
	Name     string `json:"name"`
	Kind     string `json:"kind"`
	GoType   string `json:"go_type"`
	Required bool   `json:"required"`
	Multiple bool   `json:"multiple"`
}

FieldInfo is a form field: Kind is "input", "file", "textarea" or "select", and GoType the Go type its value is read into. Radio and checkbox inputs that share a name are one field.

type FormInfo

type FormInfo struct {
	Name   string      `json:"name"`
	Fields []FieldInfo `json:"fields"`
}

FormInfo is an <ssr:form> and its fields, in template order.

type Options

type Options struct {
	// Workspace maps the name of every app of the workspace to its folder. With nil, the
	// workspace is the apps in the folders directly next to dir, and two of them with one name
	// that hold a snapshot of this app are E-DEV-010.
	Workspace map[string]string
	// Frozen writes nothing; every generated file that would change is an E-CHK-001 problem.
	Frozen bool
	// Module is the import path of dir, for an app that lies inside an enclosing module and has
	// no go.mod of its own. With "", the go.mod in dir names it.
	Module string
}

Options says how Run generates an app.

type ParamInfo

type ParamInfo struct {
	Name string `json:"name"`
	Kind string `json:"kind"`
}

ParamInfo is a parameter of a URL: Kind is "number" for an n_ folder and "string" for an s_ folder.

type Result

type Result struct {
	// Changed lists the generated files written, or with Frozen the ones that differ,
	// relative to the app folder, slash-separated and sorted. Removed files are included.
	Changed []string
	// Files lists every file the generator owns in the app: the generated Go and TypeScript
	// files, the built assets and the snapshot of the functions the app serves, relative to the
	// app folder, slash-separated and sorted. Every other file of the app is hand-written.
	Files []string
	// Warnings are the esbuild warnings, each "<file>:<line>: <text>".
	Warnings []string
	// Routes lists every page and layout of the app, sorted by URL pattern.
	Routes []RouteInfo
}

Result is what Run changed and what it warns about.

func Run

func Run(dir string, opts Options) (Result, error)

Run generates the app in dir as Generate describes. Before it writes anything, it checks the new schema of the app's functions against every snapshot of them held by another app of the workspace, and refuses a change that breaks one with E-RPC-013.

type Route

type Route struct {
	Path     string
	Dir      string
	Template *template.Template
	// contains filtered or unexported fields
}

Route is a folder under pages/ with an index.html. Path is its URL pattern, such as /notes/n_id, and Dir its absolute folder.

type RouteInfo

type RouteInfo struct {
	// Path is the URL pattern, as the access section writes it, such as /trips/{id}.
	Path string `json:"path"`
	// Template is the route's template, relative to the app folder.
	Template string `json:"template"`
	// Layout tells a layout with pages below it, which only redirects to one of them and has no
	// entry in the access section.
	Layout bool `json:"layout"`
	// Params are the parameters of the URL, in path order.
	Params []ParamInfo `json:"params"`
	// Require holds the role rules a viewer must meet, as the access section writes them.
	Require []string `json:"require"`
	// Guard tells whether a Guard runs on the path, and GuardAt is the path of the route whose
	// template declares the nearest one, or "".
	Guard   bool   `json:"guard"`
	GuardAt string `json:"guard_at"`
	// Shared tells whether everyone the rules admit may see every record, as the access section
	// says.
	Shared bool `json:"shared"`
	// Live tells whether the route or a layout above it has live values or page calls, so that
	// its page opens a live connection at <path>/__ws.
	Live bool `json:"live"`
	// Calls names the page calls of the routes that render the page.
	Calls []string `json:"calls"`
	// Forms are the forms of the route's own template, in template order.
	Forms []FormInfo `json:"forms"`
}

RouteInfo is one page or layout of an app, as its templates and the access section describe it. The delivery pipeline's simulated attacks are built from it.

Directories

Path Synopsis
Package gobuf builds Go source for generated page code.
Package gobuf builds Go source for generated page code.
Package template parses page templates (index.html) into nodes that write Go code.
Package template parses page templates (index.html) into nodes that write Go code.
htmlutils
Package htmlutils holds element sets of the HTML syntax.
Package htmlutils holds element sets of the HTML syntax.

Jump to

Keyboard shortcuts

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