generator

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtensionGo  = "go"
	ExtensionCSS = "css"
	ExtensionJS  = "js"
)

Artifact extensions, without a leading dot.

View Source
const (
	// DynamoPage issues one request and returns a page.
	DynamoPage = dynamobind.Page
	// DynamoMany iterates every page.
	DynamoMany = dynamobind.Many
)
View Source
const (
	DynamoEqual          = dynamobind.OpEqual
	DynamoLess           = dynamobind.OpLess
	DynamoLessOrEqual    = dynamobind.OpLessOrEqual
	DynamoGreater        = dynamobind.OpGreater
	DynamoGreaterOrEqual = dynamobind.OpGreaterOrEqual
	DynamoBetween        = dynamobind.OpBetween
	DynamoBeginsWith     = dynamobind.OpBeginsWith
)
View Source
const (
	// FirestoreBatch issues one request and returns a page.
	FirestoreBatch = firestorebind.Batch
	// FirestoreMany iterates every batch.
	FirestoreMany = firestorebind.Many
	// FirestoreCount runs an aggregation query.
	FirestoreCount = firestorebind.Count
	// FirestoreKeys runs a keys-only query.
	FirestoreKeys = firestorebind.Keys
)
View Source
const (
	FirestoreEqual          = firestorebind.OpEqual
	FirestoreNotEqual       = firestorebind.OpNotEqual
	FirestoreLess           = firestorebind.OpLess
	FirestoreLessOrEqual    = firestorebind.OpLessOrEqual
	FirestoreGreater        = firestorebind.OpGreater
	FirestoreGreaterOrEqual = firestorebind.OpGreaterOrEqual
	FirestoreIn             = firestorebind.OpIn
	FirestoreNotIn          = firestorebind.OpNotIn
)
View Source
const (
	FirestoreAscending  = firestorebind.Ascending
	FirestoreDescending = firestorebind.Descending
)
View Source
const (
	FirestoreAnd = firestorebind.JunctionAnd
	FirestoreOr  = firestorebind.JunctionOr
)
View Source
const (
	// DefaultPublicDir receives extracted static assets when a project
	// configures no directory. Extraction always happens, so a
	// zero-configuration project still gets working asset URLs.
	DefaultPublicDir = "public/generated"
	// DefaultPublicURLBase serves those files when a project configures no URL
	// base.
	DefaultPublicURLBase = htmlbind.DefaultPublicURLBase
)
View Source
const (
	KindRestAny = "rest_any" // map[string]any with payload:"*"
	KindRestRaw = "rest_raw" // map[string]json.RawMessage with payload:"*"
	KindStruct  = "struct"
	KindSlice   = "slice"
	KindMap     = "map"
)

Composite and special field kinds.

View Source
const (
	DefaultTemplatesName       = "tinybind_templates_gen.go"
	DefaultHTMLTemplatePattern = "*.tb.html"
	DefaultSQLTemplatePattern  = "*.tb.sql"
)
View Source
const DefaultDynamoTemplatePattern = dynamobind.DefaultTemplatePattern

DefaultDynamoTemplatePattern is the base-name glob for query declarations, beside the HTML and SQL template patterns.

View Source
const DefaultFirestoreTemplatePattern = firestorebind.DefaultTemplatePattern

DefaultFirestoreTemplatePattern is the base-name glob for query declarations.

Variables

View Source
var ErrDerivedAssetDir = errors.New(
	"generator: a reference hook produced a file but DerivedAssetDir is not set; " +
		"it is not derived from PublicDir, because a transform chooses the URL it rewrites to " +
		"and only the caller knows which directory is served there")

ErrDerivedAssetDir reports a hook that produced a file with nowhere to put it. Discarding it silently would leave the rewritten reference dangling, which is the one property this seam exists to guarantee.

View Source
var ErrFeatureDisabled = errors.New("generator: feature disabled")

ErrFeatureDisabled is returned when a disabled generator artifact is invoked directly.

View Source
var ErrNothingToGenerate = errors.New("generator: nothing to generate")

ErrNothingToGenerate reports a package with no enabled artifacts.

View Source
var ErrPublicAssetPairing = errors.New(
	"generator: PublicDir and PublicURLBase must be set together; " +
		"neither is derived from the other, so configure both or leave both empty for " +
		DefaultPublicDir + " and " + DefaultPublicURLBase)

ErrPublicAssetPairing reports a public asset configuration that sets only one of the two independent options.

Functions

func AnalyzeConfigBind added in v0.1.5

func AnalyzeConfigBind(dir string) (pkgName string, specs []cbcg.Spec, err error)

AnalyzeConfigBind discovers default Bind[T](prefix) registrations.

func AnalyzeConfigBindWithOptions added in v0.1.12

func AnalyzeConfigBindWithOptions(dir string, options Options) (pkgName string, specs []cbcg.Spec, err error)

AnalyzeConfigBindWithOptions discovers configured config-bind calls.

func Emit

func Emit(plan *PackagePlan) ([]byte, error)

Emit generates Go source for type-specific binders, writers, and JSON codecs. The output does not import "reflect".

func EmitDynamoItems added in v0.2.8

func EmitDynamoItems(plan *DynamoPackagePlan, emitTable bool) ([]byte, error)

EmitDynamoItems generates the item codec for every plan in the package.

func EmitDynamoQueries added in v0.2.9

func EmitDynamoQueries(pkg string, plans []DynamoQueryPlan) ([]byte, error)

EmitDynamoQueries generates one function per checked declaration, in the Context form.

func EmitDynamoQueriesWithOptions added in v0.3.7

func EmitDynamoQueriesWithOptions(pkg string, plans []DynamoQueryPlan, opts DynamoQueryOptions) ([]byte, error)

EmitDynamoQueriesWithOptions is EmitDynamoQueries in the mode opts selects.

func EmitFirestoreEntities added in v0.3.6

func EmitFirestoreEntities(plan *FirestorePackagePlan) ([]byte, error)

EmitFirestoreEntities generates the entity codec for every plan in the package.

func EmitFirestoreQueries added in v0.3.6

func EmitFirestoreQueries(pkg string, plans []FirestoreQueryPlan) ([]byte, error)

EmitFirestoreQueries generates one function per checked declaration, in the Context form.

func EmitFirestoreQueriesWithOptions added in v0.3.7

func EmitFirestoreQueriesWithOptions(pkg string, plans []FirestoreQueryPlan, opts FirestoreQueryOptions) ([]byte, error)

EmitFirestoreQueriesWithOptions is EmitFirestoreQueries in the mode opts selects.

func EmitOpenAPI

func EmitOpenAPI(pkg string, doc Document) ([]byte, error)

EmitOpenAPI produces Go source for a package-named fragment. Prefer EmitOpenAPIFragment when the package import path is available.

func EmitOpenAPIFragment added in v0.1.11

func EmitOpenAPIFragment(pkg, packagePath string, doc Document) ([]byte, error)

EmitOpenAPIFragment produces Go source embedding and registering one package-local OpenAPI fragment.

func Generate

func Generate(dir, outDir, outName string) (string, error)

Generate analyzes dir and writes <outName> (default: tinybind_gen.go) into outDir (default: dir). Returns the absolute path of the written file.

func GenerateOpenAPI

func GenerateOpenAPI(dir, outDir, outName string) (string, error)

GenerateOpenAPI builds OpenAPI 3.1 from Go sources in dir and writes a generated file that embeds the document and registers it with httpbind for serving.

func Main

func Main(set CommandSet)

Main owns only the outer process boundary.

func TemplateFiles added in v0.1.5

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

TemplateFiles returns the .tb.html and .tb.sql files directly contained in dir. A generator invocation targets one Go package and therefore does not descend into child package directories.

func TemplateFilesWithPatterns added in v0.1.13

func TemplateFilesWithPatterns(dir, htmlPattern, sqlPattern string) ([]string, error)

TemplateFilesWithPatterns returns files directly contained in dir whose base names match the filepath.Match patterns for HTML and SQL templates.

Types

type Artifact added in v0.1.13

type Artifact struct {
	// SourcePath is the real on-disk path of the owning source. It is empty for
	// package-wide artifacts.
	SourcePath  string
	Kind        ArtifactKind
	Destination ArtifactDestination
	// OutputBase is the suggested output base name, without directory,
	// extension, or generated-file suffix.
	OutputBase string
	// Extension is the output file extension without a dot.
	Extension string
	// PackageName is meaningful for a go_package destination only.
	PackageName string
	Content     []byte
	// PublicPath is the URL a public asset is referenced by. It is empty for a
	// go_package destination.
	PublicPath string
}

Artifact is one generated output unit and the source file that owns it. The caller maps OutputBase to its own generated file name; nothing is written to disk by the API that produces Artifacts.

Go formatting and import correctness apply to a go_package destination only; a public asset is written verbatim.

type ArtifactDestination added in v0.2.9

type ArtifactDestination string

ArtifactDestination says where an artifact is written, because a stylesheet is served, not compiled.

const (
	DestinationGoPackage   ArtifactDestination = "go_package"
	DestinationPublicAsset ArtifactDestination = "public_asset"
)

type ArtifactKind added in v0.1.13

type ArtifactKind string

ArtifactKind classifies one generated output unit.

const (
	ArtifactHTMLTemplate ArtifactKind = "html_template"
	ArtifactSQLTemplate  ArtifactKind = "sql_template"
	ArtifactBinding      ArtifactKind = "binding"
	ArtifactConfigBind   ArtifactKind = "configbind"
	ArtifactDynamoItem   ArtifactKind = "dynamo_item"
	ArtifactDynamoQuery  ArtifactKind = "dynamo_query"

	ArtifactFirestoreEntity ArtifactKind = "firestore_entity"
	ArtifactFirestoreQuery  ArtifactKind = "firestore_query"
	ArtifactOpenAPI         ArtifactKind = "openapi"
	// ArtifactStylesheet is the component CSS extracted from one template.
	ArtifactStylesheet ArtifactKind = "stylesheet"
	// ArtifactScript is the component JavaScript extracted from one template.
	ArtifactScript ArtifactKind = "script"
	// ArtifactDerivedAsset is a file a reference hook transform produced from an
	// authored source the template points at.
	ArtifactDerivedAsset ArtifactKind = "derived_asset"
)

type CallOperation added in v0.1.12

type CallOperation string

CallOperation identifies the generator meaning of a configured wrapper call.

const (
	OperationRequestBind         CallOperation = "request_bind"
	OperationResponseWrite       CallOperation = "response_write"
	OperationResponseWriteStatus CallOperation = "response_write_status"
	OperationStreamCreate        CallOperation = "stream_create"
	OperationJSONDecode          CallOperation = "json_decode"
	OperationJSONEncode          CallOperation = "json_encode"
	OperationRowsScan            CallOperation = "rows_scan"
	OperationItemEncode          CallOperation = "item_encode"
	OperationItemDecode          CallOperation = "item_decode"
	OperationItemKey             CallOperation = "item_key"
	// OperationItemEncodeDecode is a write that reads back what it replaced, and
	// OperationItemKeyDecode a delete that does. One call needs two generated
	// methods, and a call target carries exactly one operation, so the pair gets
	// its own operation rather than two patterns for one function.
	OperationItemEncodeDecode CallOperation = "item_encode_decode"
	OperationItemKeyDecode    CallOperation = "item_key_decode"
	// The Firestore entity operations. They are separate from the DynamoDB item
	// ones rather than shared, because the two runtimes emit different methods
	// onto the same struct and a call has to say which.
	OperationEntityEncode     CallOperation = "entity_encode"
	OperationEntityDecode     CallOperation = "entity_decode"
	OperationEntityKey        CallOperation = "entity_key"
	OperationConfigBind       CallOperation = "config_bind"
	OperationConfigSubCommand CallOperation = "config_subcommand"
	OperationRouteRegister    CallOperation = "route_register"
	OperationErrorResponse    CallOperation = "error_response"
)

type CallPattern added in v0.1.12

type CallPattern struct {
	Target        CallTarget
	Operation     CallOperation
	TypeRoles     map[string]TypeSource
	ArgumentRoles map[string]ValueSource
}

CallPattern maps a framework call identity onto one generator operation.

func Call added in v0.1.12

func Call(operation CallOperation, target CallTarget, options ...CallPatternOption) CallPattern

Call constructs a semantic wrapper call pattern.

func ConfigBindCall added in v0.1.12

func ConfigBindCall(target CallTarget, options ...CallPatternOption) CallPattern

ConfigBindCall declares a configbind registration wrapper.

func ConfigSubCommandCall added in v0.1.12

func ConfigSubCommandCall(target CallTarget, options ...CallPatternOption) CallPattern

ConfigSubCommandCall declares a configbind subcommand registration wrapper.

func EntityDecodeCall added in v0.3.6

func EntityDecodeCall(target CallTarget, options ...CallPatternOption) CallPattern

EntityDecodeCall declares a Firestore entity reader wrapper.

func EntityEncodeCall added in v0.3.6

func EntityEncodeCall(target CallTarget, options ...CallPatternOption) CallPattern

EntityEncodeCall declares a Firestore entity writer wrapper.

func EntityKeyCall added in v0.3.6

func EntityKeyCall(target CallTarget, options ...CallPatternOption) CallPattern

EntityKeyCall declares a wrapper that needs only a type's key.

func ErrorResponseCall added in v0.1.12

func ErrorResponseCall(target CallTarget, options ...CallPatternOption) CallPattern

ErrorResponseCall declares an error constructor with a fixed HTTP status.

func ItemDecodeCall added in v0.2.8

func ItemDecodeCall(target CallTarget, options ...CallPatternOption) CallPattern

ItemDecodeCall declares a DynamoDB item reader wrapper.

func ItemEncodeCall added in v0.2.8

func ItemEncodeCall(target CallTarget, options ...CallPatternOption) CallPattern

ItemEncodeCall declares a DynamoDB item writer wrapper.

func ItemEncodeDecodeCall added in v0.2.8

func ItemEncodeDecodeCall(target CallTarget, options ...CallPatternOption) CallPattern

ItemEncodeDecodeCall declares a wrapper that writes an item and decodes the item it replaced.

func ItemKeyCall added in v0.2.8

func ItemKeyCall(target CallTarget, options ...CallPatternOption) CallPattern

ItemKeyCall declares a wrapper that needs only a type's primary key.

func ItemKeyDecodeCall added in v0.2.8

func ItemKeyDecodeCall(target CallTarget, options ...CallPatternOption) CallPattern

ItemKeyDecodeCall declares a wrapper that deletes by key and decodes the item it deleted.

func JSONDecodeCall added in v0.1.12

func JSONDecodeCall(target CallTarget, options ...CallPatternOption) CallPattern

JSONDecodeCall declares a standalone JSON decoder wrapper.

func JSONEncodeCall added in v0.1.12

func JSONEncodeCall(target CallTarget, options ...CallPatternOption) CallPattern

JSONEncodeCall declares a standalone JSON encoder wrapper.

func RequestBindCall added in v0.1.12

func RequestBindCall(target CallTarget, options ...CallPatternOption) CallPattern

RequestBindCall declares a request-model binding wrapper.

func ResponseWriteCall added in v0.1.12

func ResponseWriteCall(target CallTarget, options ...CallPatternOption) CallPattern

ResponseWriteCall declares a default-status response writer wrapper.

func ResponseWriteStatusCall added in v0.1.12

func ResponseWriteStatusCall(target CallTarget, options ...CallPatternOption) CallPattern

ResponseWriteStatusCall declares a response writer wrapper with a status role.

func RouteRegisterCall added in v0.1.12

func RouteRegisterCall(target CallTarget, options ...CallPatternOption) CallPattern

RouteRegisterCall declares an HTTP route registration wrapper.

func RowsScanCall added in v0.1.12

func RowsScanCall(target CallTarget, options ...CallPatternOption) CallPattern

RowsScanCall declares a SQL row scanner wrapper.

func StreamCreateCall added in v0.1.12

func StreamCreateCall(target CallTarget, options ...CallPatternOption) CallPattern

StreamCreateCall declares a streaming response constructor wrapper.

type CallPatternOption added in v0.1.12

type CallPatternOption func(*CallPattern)

CallPatternOption adds one semantic role source to a CallPattern.

func Argument added in v0.1.12

func Argument(role string, index int) CallPatternOption

Argument reads a value role from a zero-based value argument index.

func ArgumentType added in v0.1.12

func ArgumentType(role string, index int) CallPatternOption

ArgumentType reads a type role from a zero-based value argument index.

func Constant added in v0.1.12

func Constant(role string, value any) CallPatternOption

Constant provides a fixed semantic value hidden by a wrapper.

func GenericType added in v0.1.12

func GenericType(role string, index int) CallPatternOption

GenericType reads a type role from a zero-based generic argument index.

type CallRegistry added in v0.1.12

type CallRegistry struct {
	// contains filtered or unexported fields
}

CallRegistry accumulates framework wrapper declarations without global state.

func NewCallRegistry added in v0.1.12

func NewCallRegistry() *CallRegistry

NewCallRegistry creates an empty framework-local call registry.

func (*CallRegistry) Options added in v0.1.12

func (registry *CallRegistry) Options(base Options) (Options, error)

Options returns an immutable options snapshot containing defaults and wrappers.

func (*CallRegistry) Register added in v0.1.12

func (registry *CallRegistry) Register(patterns ...CallPattern) error

Register validates and adds call patterns.

type CallTarget added in v0.1.12

type CallTarget struct {
	Function *SymbolPattern
	Method   *MethodPattern
}

CallTarget identifies either a package function or a named-receiver method.

func Function added in v0.1.12

func Function(packagePath, name string) CallTarget

Function identifies a package function used as a generator call target.

func Method added in v0.1.12

func Method(packagePath, name, receiverPackagePath, receiverType string) CallTarget

Method identifies a method used as a generator call target.

type CheckRules

type CheckRules struct {
	Required bool
	Min      *float64
	Max      *float64
	MinLen   *int
	MaxLen   *int
	Len      *int
	Pattern  string
	Email    bool
	UUID     bool
	Date     bool
	Time     bool
	DateTime bool
}

CheckRules is the structured form of a field's check tag (codegen only).

func ParseCheckTag

func ParseCheckTag(raw, kind string) (CheckRules, error)

ParseCheckTag parses a check tag value for a field of the given Go kind. Invalid syntax, unknown rules, type mismatches, and invalid patterns fail here.

func (CheckRules) HasValidation added in v0.1.6

func (c CheckRules) HasValidation() bool

HasValidation reports whether the check rules can reject a bound value. Every check rule can; defaults live in DefaultRule precisely because they cannot. Enums can too, but are their own tag: see FieldPlan.HasValidation.

type Command added in v0.1.12

type Command struct {
	Name    string
	Summary string
	Run     func(context.Context, []string, CommandIO) int
}

Command is one independently testable subcommand.

func FormatCommand added in v0.3.1

func FormatCommand(options Options) Command

FormatCommand creates the tinybind fmt subcommand, per api:template-format-command. Everything it does is available as a library through templatefmt; this is the process boundary around it.

func GenerateCommand added in v0.1.12

func GenerateCommand(options Options) Command

GenerateCommand creates the tinybind generate subcommand.

type CommandIO added in v0.1.12

type CommandIO struct {
	Stdin            io.Reader
	Stdout           io.Writer
	Stderr           io.Writer
	WorkingDirectory string
	Environment      []string
}

CommandIO contains process state injected into a command execution.

type CommandSet added in v0.1.12

type CommandSet struct {
	// contains filtered or unexported fields
}

CommandSet is an immutable command dispatcher.

func MustCommandSet added in v0.1.12

func MustCommandSet(commands ...Command) CommandSet

MustCommandSet is NewCommandSet for process setup code and panics on invalid commands.

func NewCommandSet added in v0.1.12

func NewCommandSet(commands ...Command) (CommandSet, error)

NewCommandSet validates commands and constructs an immutable dispatcher.

func (CommandSet) Run added in v0.1.12

func (set CommandSet) Run(ctx context.Context, args []string, streams CommandIO) int

Run dispatches one command without reading process globals or terminating the process.

type ConfigBindBinding added in v0.1.5

type ConfigBindBinding struct {
	TypeName   string
	Prefix     string
	SubCommand bool
	Name       string
	Help       string
	// SourcePath is the Go file containing the discovered call.
	SourcePath string
}

ConfigBindBinding is one discovered configbind.Bind[T](prefix) call.

type ConfigBindSpec added in v0.1.13

type ConfigBindSpec struct {
	SourcePath string
	Spec       cbcg.Spec
}

ConfigBindSpec pairs one generated config definition with the source file whose call declared it.

func AnalyzeConfigBindSources added in v0.1.13

func AnalyzeConfigBindSources(dir string, options Options) (pkgName string, specs []ConfigBindSpec, err error)

AnalyzeConfigBindSources is AnalyzeConfigBindWithOptions with the owning source file retained for every discovered definition.

type DefaultRule added in v0.2.0

type DefaultRule struct {
	Value string
	Set   bool
}

DefaultRule is the parsed default tag of a field (codegen only). A default is not a constraint: it never rejects a value, it only fills in one that never arrived, which is why it lives outside the check tag.

func ParseDefaultTag added in v0.2.0

func ParseDefaultTag(raw, kind string) (DefaultRule, error)

ParseDefaultTag parses a default tag value for a field of the given Go kind. Callers pass only tags that are actually present, so default:"" stays distinguishable from a missing tag. Unsupported kinds and values that cannot be converted to the field type fail here.

type DiscoverySymbol

type DiscoverySymbol struct {
	PackagePath         string
	Name                string
	ReceiverPackagePath string
	ReceiverType        string
	Usage               Usage
	TypeArgument        int
	ArgumentType        *int
}

DiscoverySymbol identifies a generic function and the entry point it needs. PackagePath is matched by go/types identity, so import aliases are supported.

type Document

type Document map[string]any

Document is an OpenAPI 3.1 document represented as ordered JSON-friendly maps. Keys under paths/operations/components are sorted for deterministic output.

func BuildOpenAPI

func BuildOpenAPI(dir string) (Document, error)

BuildOpenAPI analyzes dir with the route parser and field planner and returns an OpenAPI 3.1 document derived only from Go source (not from handwritten YAML).

func (Document) JSON

func (d Document) JSON() ([]byte, error)

JSON is an alias for MarshalJSON bytes for callers.

func (Document) MarshalJSON

func (d Document) MarshalJSON() ([]byte, error)

MarshalJSON returns deterministic indented OpenAPI JSON.

type DynamoFieldPlan added in v0.2.8

type DynamoFieldPlan struct {
	Name      string
	Attribute string
	OmitEmpty bool
	// Key is "", "partition" or "sort".
	Key  string
	Type DynamoType
}

DynamoFieldPlan is one struct field and the attribute it maps to.

type DynamoItemPlan added in v0.2.8

type DynamoItemPlan struct {
	Name       string
	SourcePath string
	Doc        string
	Fields     []DynamoFieldPlan
	Usage      DynamoUsage
}

DynamoItemPlan is the item codec plan for one struct type.

func (DynamoItemPlan) PartitionKey added in v0.2.8

func (p DynamoItemPlan) PartitionKey() (DynamoFieldPlan, bool)

PartitionKey returns the partition key field, if the type declares one.

func (DynamoItemPlan) SortKey added in v0.2.8

func (p DynamoItemPlan) SortKey() (DynamoFieldPlan, bool)

SortKey returns the sort key field, if the type declares one.

type DynamoKind added in v0.2.8

type DynamoKind string

DynamoKind is how one Go type maps onto a DynamoDB attribute.

const (
	DynamoString    DynamoKind = "S"
	DynamoInt       DynamoKind = "N.int"
	DynamoUint      DynamoKind = "N.uint"
	DynamoFloat     DynamoKind = "N.float"
	DynamoBool      DynamoKind = "BOOL"
	DynamoBytes     DynamoKind = "B"
	DynamoTime      DynamoKind = "S.time"
	DynamoUnixTime  DynamoKind = "N.time"
	DynamoList      DynamoKind = "L"
	DynamoMap       DynamoKind = "M"
	DynamoStruct    DynamoKind = "M.struct"
	DynamoPointer   DynamoKind = "ptr"
	DynamoStringSet DynamoKind = "SS"
	DynamoNumberSet DynamoKind = "NS"
	DynamoBinarySet DynamoKind = "BS"
	// DynamoRaw is a dynamodb.AttributeValue field, stored as it stands. It is
	// the escape hatch for what the table above cannot express.
	DynamoRaw DynamoKind = "AV"
)

type DynamoOp added in v0.2.9

type DynamoOp = dynamobind.Op

DynamoOp is a key condition operator.

type DynamoPackagePlan added in v0.2.8

type DynamoPackagePlan struct {
	Package     string
	PackagePath string
	Items       []DynamoItemPlan
}

DynamoPackagePlan is every item plan in one package.

func AnalyzeDynamoItems added in v0.2.8

func AnalyzeDynamoItems(dir string) (*DynamoPackagePlan, error)

AnalyzeDynamoItems builds item plans for the types a package binds to DynamoDB, discovered from dynamobind call sites.

func AnalyzeDynamoItemsWithOptions added in v0.2.8

func AnalyzeDynamoItemsWithOptions(dir string, opts Options) (*DynamoPackagePlan, error)

AnalyzeDynamoItemsWithOptions is AnalyzeDynamoItems with custom discovery.

type DynamoPredicate added in v0.2.9

type DynamoPredicate = dynamobind.Predicate

DynamoPredicate is one comparison in a key clause.

type DynamoQueryDecl added in v0.2.9

type DynamoQueryDecl = dynamobind.QueryDecl

DynamoQueryDecl is one declared access pattern.

type DynamoQueryOptions added in v0.3.7

type DynamoQueryOptions struct {
	// ParameterAPI gives each function a leading dynamobind.Handle parameter.
	ParameterAPI bool
	// HandleResolver names a framework function answering a dynamobind.Handle
	// for one Context. ParameterAPI takes precedence over it.
	HandleResolver *SymbolPattern
}

DynamoQueryOptions selects which of the three client-supply modes the generated functions use. The zero value is the Context form, which is the default and what every run that sets nothing generates.

type DynamoQueryParam added in v0.2.9

type DynamoQueryParam = dynamobind.QueryParam

DynamoQueryParam is one declared parameter of a query function.

type DynamoQueryPlan added in v0.2.9

type DynamoQueryPlan struct {
	Decl DynamoQueryDecl
	// Item is the type the query decodes into.
	Item DynamoItemPlan
	// Expression is the KeyConditionExpression, written with aliases.
	Expression string
	// Names maps each alias to the attribute it stands for.
	Names map[string]string
	// Values pairs each ":v" placeholder with the parameter and attribute that
	// fill it, in emission order.
	Values []DynamoQueryValue
}

DynamoQueryPlan is one checked declaration, ready to emit. Every name in it has been matched against the bound type's tags, so the emitter looks nothing up.

type DynamoQueryValue added in v0.2.9

type DynamoQueryValue struct {
	Placeholder string
	Param       DynamoQueryParam
	Attribute   DynamoFieldPlan
}

DynamoQueryValue is one bound placeholder.

type DynamoResultShape added in v0.2.9

type DynamoResultShape = dynamobind.ResultShape

DynamoResultShape is what a declaration asks the generated function to return.

type DynamoType added in v0.2.8

type DynamoType struct {
	Kind DynamoKind
	// Go is the type as it must be written inside the generated package.
	Go string
	// Elem is the element of a slice, map or pointer.
	Elem *DynamoType
	// MapKey is the key type of a map attribute, written as the generated
	// package must spell it. DynamoDB map keys are strings, so it is always a
	// string-kinded type.
	MapKey string
	// Struct is the named struct type of a nested item, always declared in the
	// same package as its parent.
	Struct string
	// Bits is the width a number is parsed at: 8, 16, 32 or 64, and 0 for int
	// and uint, which strconv reads as the platform width. Parsing at the
	// field's own width turns a value it cannot hold into an error instead of a
	// silent wrap.
	Bits int
}

DynamoType describes one Go type in attribute terms.

type DynamoUsage added in v0.2.8

type DynamoUsage uint8

DynamoUsage selects which generated item methods a type needs.

const (
	// DynamoEncode emits EncodeItem.
	DynamoEncode DynamoUsage = 1 << iota
	// DynamoDecode emits DecodeItem.
	DynamoDecode
	// DynamoKey emits ItemKey and the table definition.
	DynamoKey
)

type EnumRule added in v0.2.0

type EnumRule struct {
	Values []string
	Set    bool
}

EnumRule is the parsed enum tag of a field (codegen only). Unlike a default, an enum can reject a value, so it counts as validation; it lives outside the check tag only because config structs already spell it this way.

func ParseEnumTag added in v0.2.0

func ParseEnumTag(raw, kind string) (EnumRule, error)

ParseEnumTag parses an enum tag value for a field of the given Go kind. Values are comma-separated, which means a value cannot contain a comma — the same limit the check tag had, where commas separated rules.

type Feature

type Feature string

Feature identifies a generator capability that can be permanently disabled.

const (
	FeatureRouteDiscovery Feature = "route-discovery"
	FeatureOpenAPI        Feature = "openapi"
	FeatureBind           Feature = "bind"
	FeatureWrite          Feature = "write"
	FeatureWriteStatus    Feature = "write-status"
	FeatureDecodeJSON     Feature = "decode-json"
	FeatureEncodeJSON     Feature = "encode-json"
	FeatureStreaming      Feature = "streaming"
	FeatureScanRows       Feature = "scan-rows"
	FeatureMultipartFile  Feature = "multipart-file"
	// FeatureItemCodec turns off DynamoDB item codec generation entirely.
	FeatureItemCodec Feature = "item-codec"
	// FeatureItemTable turns off only the generated table definition, leaving
	// the codec and the key builder in place. Emitting it is the default,
	// because it is what makes a key name single-source; a project that manages
	// tables with IaC and never creates one in Go can drop it.
	FeatureItemTable Feature = "item-table"
	// FeatureEntityCodec turns off Firestore entity codec generation entirely.
	FeatureEntityCodec Feature = "entity-codec"
	// FeatureHelpBackfill writes help tags derived from godoc into config
	// structs. Disable it to keep hand-written sources untouched.
	FeatureHelpBackfill Feature = "help-backfill"
)

type FieldPlan

type FieldPlan struct {
	Name     string      // Go field name
	Wire     string      // wire / tag name ("*" for payload rest)
	Source   FieldSource // input|query|payload|path|header|cookie|method
	Kind     string      // string|int|int64|bool|float64|file|rest_*|struct|slice|map
	JSON     string      // json name for encode/document keys
	Check    CheckRules  // from check:"" tag; empty if absent
	Enum     EnumRule    // from enum:"" tag; unset if absent
	Default  DefaultRule // from default:"" tag; unset if absent
	TypeName string      // KindStruct name, or element struct name for slice/map of struct
	ElemKind string      // for slice/map: string|int|int64|bool|float64|struct
	DB       string      // SQL result column (db tag or snake_case field name)
	GroupKey bool        // groupkey tag presence
	Doc      string      // godoc of the field (doc or line comment)
}

FieldPlan is one struct field mapping plan (compile-time).

func (FieldPlan) GoType

func (f FieldPlan) GoType() string

GoType returns a Go type string for generated code (e.g. NestedCustomer, []string).

func (FieldPlan) HasValidation added in v0.2.0

func (f FieldPlan) HasValidation() bool

HasValidation reports whether anything about the field can reject a bound value, across every tag that carries a constraint.

func (FieldPlan) IsComposite

func (f FieldPlan) IsComposite() bool

IsComposite reports nested struct/slice/map kinds.

func (FieldPlan) IsRest

func (f FieldPlan) IsRest() bool

IsRest reports whether f is a payload rest map field.

func (FieldPlan) NeedsPresence added in v0.2.0

func (f FieldPlan) NeedsPresence() bool

NeedsPresence is true when codegen must track whether the field was present: validation has to skip absent optional values, and a default only applies to a field nobody supplied.

type FieldSource

type FieldSource string

FieldSource is where a request field is read from.

const (
	SourceInput   FieldSource = "input"
	SourceQuery   FieldSource = "query"
	SourcePayload FieldSource = "payload"
	SourcePath    FieldSource = "path"
	SourceHeader  FieldSource = "header"
	SourceCookie  FieldSource = "cookie"
	SourceMethod  FieldSource = "method"
)

type FirestoreBound added in v0.3.6

type FirestoreBound = firestorebind.Bound

FirestoreBound is a limit or an offset.

type FirestoreCondition added in v0.3.6

type FirestoreCondition = firestorebind.Condition

FirestoreCondition is one node of a where clause.

type FirestoreDirection added in v0.3.6

type FirestoreDirection = firestorebind.Direction

FirestoreDirection is a sort direction.

type FirestoreEntityPlan added in v0.3.6

type FirestoreEntityPlan struct {
	Name       string
	Kind       string
	SourcePath string
	Fields     []FirestoreFieldPlan
	Usage      FirestoreUsage
}

FirestoreEntityPlan is the entity codec plan for one struct type.

func (FirestoreEntityPlan) Expiry added in v0.3.6

Expiry returns the field a TTL policy is meant to expire this kind by. It changes nothing about how the property is written; it is declared so a deployment can be told which property to point a policy at.

func (FirestoreEntityPlan) Identity added in v0.3.6

Identity returns the field that supplies the key's name or id.

func (FirestoreEntityPlan) Parent added in v0.3.6

Parent returns the field that supplies the ancestor path.

func (FirestoreEntityPlan) Properties added in v0.3.6

func (p FirestoreEntityPlan) Properties() []FirestoreFieldPlan

Properties returns the fields that become entity properties, which excludes the identity fields the key carries instead.

func (FirestoreEntityPlan) Version added in v0.3.6

Version returns the field that receives Entity.Version.

type FirestoreFieldPlan added in v0.3.6

type FirestoreFieldPlan struct {
	Name     string
	Property string
	// Role is "", "name", "id", "parent", "version" or "ttl". A field with a
	// role other than "", "version" and "ttl" carries identity rather than a
	// property; a ttl field is an ordinary property that a policy also reads.
	Role      string
	OmitEmpty bool
	NoIndex   bool
	// Stored reports whether the field also becomes a property. It is false for
	// an identity field unless the tag gave it a real property name.
	Stored bool
	Type   FirestoreType
}

FirestoreFieldPlan is one struct field and the property it maps to.

type FirestoreIndexProperty added in v0.3.6

type FirestoreIndexProperty = firestorebind.IndexProperty

FirestoreIndexProperty is one property of a declared composite index.

type FirestoreJunction added in v0.3.6

type FirestoreJunction = firestorebind.Junction

FirestoreJunction is how a condition joins its operands.

type FirestoreKind added in v0.3.6

type FirestoreKind string

FirestoreKind is how one Go type maps onto a Datastore property value.

const (
	FirestoreString  FirestoreKind = "string"
	FirestoreInt     FirestoreKind = "integer.int"
	FirestoreUint    FirestoreKind = "integer.uint"
	FirestoreDouble  FirestoreKind = "double"
	FirestoreBool    FirestoreKind = "boolean"
	FirestoreBlob    FirestoreKind = "blob"
	FirestoreTime    FirestoreKind = "timestamp"
	FirestoreKeyRef  FirestoreKind = "key"
	FirestoreGeo     FirestoreKind = "geoPoint"
	FirestoreArray   FirestoreKind = "array"
	FirestoreStruct  FirestoreKind = "entity"
	FirestorePointer FirestoreKind = "ptr"
	// FirestoreRaw is a datastore.Value field, stored as it stands. It is the
	// escape hatch for what the table above cannot express, including the
	// dynamic property names a map would have needed.
	FirestoreRaw FirestoreKind = "value"
)

type FirestoreOp added in v0.3.6

type FirestoreOp = firestorebind.Op

FirestoreOp is a property filter comparison.

type FirestoreOrder added in v0.3.6

type FirestoreOrder = firestorebind.Order

FirestoreOrder is one sort key of an order clause.

type FirestorePackagePlan added in v0.3.6

type FirestorePackagePlan struct {
	Package     string
	PackagePath string
	Entities    []FirestoreEntityPlan
}

FirestorePackagePlan is every entity plan in one package.

func AnalyzeFirestoreEntities added in v0.3.6

func AnalyzeFirestoreEntities(dir string) (*FirestorePackagePlan, error)

AnalyzeFirestoreEntities builds entity plans for the types a package binds to Firestore, discovered from firestorebind call sites.

func AnalyzeFirestoreEntitiesWithOptions added in v0.3.6

func AnalyzeFirestoreEntitiesWithOptions(dir string, opts Options) (*FirestorePackagePlan, error)

AnalyzeFirestoreEntitiesWithOptions is AnalyzeFirestoreEntities with custom discovery.

type FirestorePredicate added in v0.3.6

type FirestorePredicate = firestorebind.Predicate

FirestorePredicate is one comparison in a where clause.

type FirestoreProjection added in v0.3.6

type FirestoreProjection = firestorebind.Projection

FirestoreProjection is one property a select or distinct clause names.

type FirestoreQueryDecl added in v0.3.6

type FirestoreQueryDecl = firestorebind.QueryDecl

FirestoreQueryDecl is one declared access pattern.

type FirestoreQueryFilter added in v0.3.6

type FirestoreQueryFilter struct {
	Predicate FirestorePredicate
	Field     FirestoreFieldPlan
	Param     FirestoreQueryParam
}

FirestoreQueryFilter is one checked predicate.

type FirestoreQueryOptions added in v0.3.7

type FirestoreQueryOptions struct {
	// ParameterAPI gives each function a leading firestorebind.Handle parameter.
	ParameterAPI bool
	// HandleResolver names a framework function answering a firestorebind.Handle
	// for one Context. ParameterAPI takes precedence over it.
	HandleResolver *SymbolPattern
}

FirestoreQueryOptions selects which of the three client-supply modes the generated functions use. The zero value is the Context form, which is the default and what every run that sets nothing generates.

The transactional twin takes a *firestorebind.Tx, which already carries the client and the tenancy, so no mode changes it.

type FirestoreQueryOrder added in v0.3.6

type FirestoreQueryOrder struct {
	Order FirestoreOrder
	Field FirestoreFieldPlan
}

FirestoreQueryOrder is one checked sort key.

type FirestoreQueryParam added in v0.3.6

type FirestoreQueryParam = firestorebind.QueryParam

FirestoreQueryParam is one declared parameter of a query function.

type FirestoreQueryPlan added in v0.3.6

type FirestoreQueryPlan struct {
	Decl FirestoreQueryDecl
	// Entity is the type the query decodes into, and whose Kind the query runs
	// against.
	Entity FirestoreEntityPlan
	// Filters pairs each predicate with the field it names and the parameter
	// that fills it, in the order the source wrote them.
	Filters []FirestoreQueryFilter
	// Where is the checked filter tree, or nil when there is no where clause.
	// Filters is its leaves; the tree is what the emitter walks when the
	// declaration uses or.
	Where *FirestoreCondition
	// HasOr reports whether the tree needs datastore.Where at all. Without it
	// the emitter keeps to the per-predicate Filter calls it always wrote.
	HasOr bool
	// Orders are the checked sort keys.
	Orders []FirestoreQueryOrder
	// Ancestor is the parameter holding the ancestor key, or "".
	Ancestor string
	// Select and Distinct are the checked property names, resolved to what the
	// tags call them.
	Select   []string
	Distinct []string
	// ProjectsAnArray reports whether any projected property is a slice, which
	// makes the service return one result per element rather than one per
	// entity. The godoc says so; nothing here can prevent it.
	ProjectsAnArray bool
	// Start and End are the parameters holding the cursors.
	Start string
	End   string
}

FirestoreQueryPlan is one checked declaration, ready to emit. Every name in it has been matched against the bound type's tags, so the emitter looks nothing up.

type FirestoreResultShape added in v0.3.6

type FirestoreResultShape = firestorebind.ResultShape

FirestoreResultShape is what a declaration asks the generated function to return.

type FirestoreType added in v0.3.6

type FirestoreType struct {
	Kind FirestoreKind
	// Go is the type as it must be written inside the generated package.
	Go string
	// Elem is the element of a slice or pointer.
	Elem *FirestoreType
	// Struct is the named struct type of a nested entity, always declared in the
	// same package as its parent.
	Struct string
	// Bits is the width a number is parsed at: 8, 16, 32 or 64, and 0 for int
	// and uint, which strconv reads as the platform width.
	Bits int
}

FirestoreType describes one Go type in property terms.

type FirestoreUsage added in v0.3.6

type FirestoreUsage uint8

FirestoreUsage selects which generated entity methods a type needs.

const (
	// FirestoreEncode emits EncodeEntity.
	FirestoreEncode FirestoreUsage = 1 << iota
	// FirestoreDecode emits DecodeEntity.
	FirestoreDecode
	// FirestoreKey emits EntityKey.
	FirestoreKey
)

type GenerateRequest added in v0.1.12

type GenerateRequest struct {
	Dir           string
	Out           string
	Name          string
	OpenAPI       bool
	OpenAPIName   string
	TemplatesName string
	// HTMLTemplatePattern and SQLTemplatePattern override template discovery
	// globs. Empty values retain the generator options.
	HTMLTemplatePattern string
	SQLTemplatePattern  string
	// SQLDialect overrides the generator option for this run. An empty value
	// retains it.
	SQLDialect     string
	ConfigBindName string
	// DynamoName is the DynamoDB item codec output file.
	DynamoName string
	// DynamoQueryName is the generated DynamoDB query output file.
	DynamoQueryName string
	// FirestoreName is the Firestore entity codec output file.
	FirestoreName string
	// FirestoreQueryName is the generated Firestore query output file.
	FirestoreQueryName string
	// PublicDir and PublicURLBase override where extracted static assets are
	// written and how they are referenced. Empty values retain the generator
	// options; setting one requires setting the other.
	PublicDir     string
	PublicURLBase string
	Check         bool
	GenerateAll   bool
	// Force regenerates even when the generated files record the current input
	// hash. Use it after a change the hash does not cover, such as an edit in
	// another package of the module.
	Force         bool
	SQLContextAPI bool
	// SQLContextOnlyAPI enables the context-only SQL API for this run. It can
	// turn the option on, never off.
	SQLContextOnlyAPI bool
	// DynamoParameterAPI and FirestoreParameterAPI put the runtime Handle in
	// each generated query's signature for this run. Like the SQL switches they
	// can turn the option on, never off.
	DynamoParameterAPI    bool
	FirestoreParameterAPI bool
}

GenerateRequest configures one package-local generation execution.

type GenerateResult added in v0.1.12

type GenerateResult struct {
	BinderPath         string
	ConfigBindPath     string
	DynamoPath         string
	DynamoQueryPath    string
	FirestorePath      string
	FirestoreQueryPath string
	OpenAPIPath        string
	TemplatesPath      string
	// AssetPaths holds the static files extracted from component style and
	// script blocks, then the files reference hook conversions produced, in
	// generation order.
	AssetPaths []string
	// Rewrites reports what the reference hooks did, including what they
	// declined and why. An author cannot see a build-time rewrite by reading
	// the template, so the build is the only place it is visible.
	//
	// It reports rather than interprets: whether a converted file is small
	// enough is the caller's judgment, and a caller measuring sizes owns its
	// own transform and can measure inside it.
	Rewrites []htmlbind.Rewrite
	// ReadSet holds every authored file the run depended on through a hook: the
	// sources each cache key named, plus whatever each transform reported
	// reading beyond them, sorted. A transform that under-reports produces a
	// stale output on the next run, which is the one correctness property this
	// package cannot verify for the caller.
	ReadSet []string
	// DynamicReferences are the attributes a hook was registered for whose
	// value is a template expression, and so could not be rewritten.
	DynamicReferences []htmlbind.DynamicReference
	// DepsPath is the recorded read set, written only when a transform reported
	// reading something. The next run verifies it before trusting its own skip,
	// because a file read by a transform is not otherwise a hashed input.
	DepsPath    string
	Diagnostics []parser.Diagnostic
	// Cached reports that the paths were left untouched because the generated
	// files already record the current input hash.
	Cached bool
}

GenerateResult records generated artifacts or check diagnostics.

func (GenerateResult) Paths added in v0.1.12

func (result GenerateResult) Paths() []string

Paths returns non-empty artifact paths in generation order.

type Generator

type Generator struct{ Options Options }

Generator is a reusable, configurable code generator.

func New

func New(opts Options) *Generator

New constructs a usage-directed generator. Set GenerateAll for legacy output.

func (*Generator) Analyze

func (g *Generator) Analyze(dir string) (*PackagePlan, error)

Analyze analyzes a package using this generator's discovery symbols.

func (*Generator) BuildOpenAPI

func (g *Generator) BuildOpenAPI(dir string) (Document, error)

BuildOpenAPI builds a document using this generator's discovery identities.

func (*Generator) EmitDynamoQueriesFor added in v0.2.9

func (g *Generator) EmitDynamoQueriesFor(dir string) ([]byte, error)

EmitDynamoQueriesFor analyzes dir and returns the generated query source without writing it, which is what a check needs.

func (*Generator) EmitFirestoreQueriesFor added in v0.3.6

func (g *Generator) EmitFirestoreQueriesFor(dir string) ([]byte, error)

EmitFirestoreQueriesFor analyzes dir and returns the generated query source without writing it, which is what a check needs.

func (*Generator) Generate

func (g *Generator) Generate(dir, outDir, outName string) (string, error)

Generate analyzes dir and writes generated source.

func (*Generator) GenerateArtifacts added in v0.1.13

func (g *Generator) GenerateArtifacts(ctx context.Context, request GenerateRequest) ([]Artifact, error)

GenerateArtifacts runs every enabled generation phase and returns the result as per-source artifacts. It writes no file, so the same call serves both generation and --check.

func (*Generator) GenerateConfigBind added in v0.1.5

func (g *Generator) GenerateConfigBind(dir, outDir, outName string) (string, error)

GenerateConfigBind analyzes dir for configbind.Bind usage and writes configbind_gen.go. Returns the absolute path written, or "" if no Bind calls found.

func (*Generator) GenerateDynamoItems added in v0.2.8

func (g *Generator) GenerateDynamoItems(dir, outDir, outName string) (string, error)

GenerateDynamoItems analyzes dir and writes the DynamoDB item codec. It returns "" when the package binds no type to DynamoDB.

func (*Generator) GenerateDynamoQueries added in v0.2.9

func (g *Generator) GenerateDynamoQueries(dir, outDir, outName string) (string, error)

GenerateDynamoQueries analyzes dir and writes the generated query functions. It returns "" when the package declares none.

func (*Generator) GenerateFirestoreEntities added in v0.3.6

func (g *Generator) GenerateFirestoreEntities(dir, outDir, outName string) (string, error)

GenerateFirestoreEntities analyzes dir and writes the Firestore entity codec. It returns "" when the package binds no type to Firestore.

func (*Generator) GenerateFirestoreQueries added in v0.3.6

func (g *Generator) GenerateFirestoreQueries(dir, outDir, outName string) (string, error)

GenerateFirestoreQueries analyzes dir and writes the generated query functions. It returns "" when the package declares none.

func (*Generator) GenerateOpenAPI

func (g *Generator) GenerateOpenAPI(dir, outDir, outName string) (string, error)

GenerateOpenAPI writes OpenAPI generated with this generator's identities.

func (*Generator) GeneratePackage added in v0.1.12

func (g *Generator) GeneratePackage(ctx context.Context, request GenerateRequest) (GenerateResult, error)

GeneratePackage executes every enabled generator phase without CLI or process ownership.

func (*Generator) GenerateTemplates added in v0.1.5

func (g *Generator) GenerateTemplates(dir, outDir, outName string) (string, error)

GenerateTemplates discovers files using the configured template patterns and writes one Go file containing all generated declarations, plus the static files extracted from component style and script blocks. It returns an empty path when no templates exist.

type MethodPattern

type MethodPattern struct {
	PackagePath         string
	Name                string
	ReceiverPackagePath string
	ReceiverType        string
}

MethodPattern identifies a method and its receiver type.

type Options

type Options struct {
	ServeMuxes      PatternSet[TypePattern]
	RouteMethods    PatternSet[MethodPattern]
	RouteFunctions  PatternSet[SymbolPattern]
	RuntimePackages PatternSet[string]
	Calls           PatternSet[CallPattern]
	FileTypes       PatternSet[TypePattern]
	// HTMLTemplatePattern and SQLTemplatePattern are filepath.Match patterns
	// applied to file base names. Empty values use the standard patterns.
	HTMLTemplatePattern string
	SQLTemplatePattern  string
	// DynamoTemplatePattern is the base-name glob for DynamoDB query
	// declarations. An empty value uses DefaultDynamoTemplatePattern.
	DynamoTemplatePattern string
	// FirestoreTemplatePattern is the base-name glob for Firestore query
	// declarations. An empty value uses DefaultFirestoreTemplatePattern.
	FirestoreTemplatePattern string
	// SQLDialect names the target database for SQL templates: "postgresql",
	// "mysql", or "sqlite". A run that discovers a SQL template must set it.
	// There is no default, because an assumed dialect emits placeholders the
	// target engine rejects, and nothing about the templates reveals the
	// mistake.
	SQLDialect string
	// SQLContextAPI adds Context-resolved wrappers for exported SQL templates.
	SQLContextAPI bool
	// SQLContextOnlyAPI publishes only the Context-resolved SQL surface under
	// the name declared in the template. The executor-taking function becomes
	// unexported and no <Component>Context wrapper is generated. It implies
	// SQLContextAPI.
	SQLContextOnlyAPI bool
	// SQLExecutorResolver selects a framework-specific Context resolver and
	// implies SQLContextAPI. Nil uses sqlbind.SQLExecutorFromContext.
	SQLExecutorResolver *SymbolPattern
	// DynamoParameterAPI gives every generated DynamoDB query a leading
	// dynamobind.Handle parameter instead of resolving one from the Context.
	// The declared name is unchanged; only the signature moves. False keeps the
	// Context form, which is the default and what every existing run generates.
	DynamoParameterAPI bool
	// DynamoHandleResolver selects a framework function that answers a
	// dynamobind.Handle for one Context, so generated code reads the
	// framework's own Context value instead of the one dynamobind installs.
	// It is how a framework carrying every value it manages in one struct
	// serves generated queries with a single lookup.
	//
	// The signature is func(context.Context) (dynamobind.Handle, error). Nil
	// uses dynamobind's own Context key. DynamoParameterAPI takes precedence:
	// a signature that already carries the Handle resolves nothing.
	DynamoHandleResolver *SymbolPattern
	// FirestoreParameterAPI is DynamoParameterAPI for Firestore queries,
	// giving each a leading firestorebind.Handle parameter.
	FirestoreParameterAPI bool
	// FirestoreHandleResolver is DynamoHandleResolver for Firestore queries.
	// The signature is func(context.Context) (firestorebind.Handle, error).
	FirestoreHandleResolver *SymbolPattern
	// DataAttributePrefix names the data attributes generated HTML uses for
	// partial update boundaries. Empty uses the standard prefix. A project
	// overriding it must use a browser runtime built for the same prefix,
	// because the runtime hardcodes it rather than discovering it.
	DataAttributePrefix string
	// GeneratedHeaders names header prefixes, beside this module's own, whose
	// files every discovery pass must skip. A framework generating with tinybind
	// and branding its output writes a header nothing here recognizes on its own,
	// and an unrecognized generated registry is analyzed as if a user had written
	// it: its page registrations become routes, and an HTML page enters an OpenAPI
	// document. Each entry still requires the conventional "DO NOT EDIT." ending.
	GeneratedHeaders []string
	// PreserveTemplateWhitespace keeps the authoring indentation and newlines of
	// HTML templates in generated static output instead of collapsing each run
	// to one space. The default collapses, which renders identically and drops
	// every indentation byte from the generated source and the binary.
	PreserveTemplateWhitespace bool

	// PublicDir is the filesystem directory receiving the static files
	// extracted from component style and script blocks. Empty uses
	// DefaultPublicDir.
	PublicDir string
	// PublicURLBase is the URL prefix under which those files are served. It is
	// either an absolute URL path or a full URL, and is used verbatim either
	// way, so a CDN base changes the reference and nothing else. Empty uses
	// DefaultPublicURLBase.
	//
	// Neither option is derived from the other, and setting one explicitly
	// requires setting the other.
	PublicURLBase string

	// ReferenceHooks rewrite the static values of the attributes they are
	// registered for, at generation time, and declare the conversions those
	// rewrites depend on. They are how a build converts a file a template points
	// at, such as an image to a modern format or a TypeScript entry point to
	// JavaScript.
	//
	// A hook converts and returns the bytes, so the rewrite may depend on how
	// the conversion turned out; an encode larger than its source is worth
	// declining, and only the converted bytes can say so.
	ReferenceHooks []htmlbind.ReferenceHook
	// ConversionCacheDir stores the outcome of each conversion, keyed by what
	// the hook's CacheKey declared it depends on. An unchanged asset then costs
	// a digest instead of an encode, and a source that once lost a size
	// comparison is never re-encoded to rediscover it.
	//
	// Empty converts every build, which is correct and slow. It is a plain
	// directory of generated data: deleting it costs time and nothing else.
	ConversionCacheDir string
	// DerivedAssetDir receives the files those conversions produce. It is
	// deliberately not derived from PublicDir: a hook chooses the URL it rewrites
	// to, and only the caller knows which directory is served there.
	//
	// A produced file with no directory configured is a configuration error
	// rather than a silent discard.
	DerivedAssetDir string
	// ConversionWorkers converts what the compile is about to ask for ahead of
	// it, on this many goroutines, instead of one encode at a time inside a
	// sequential compile. It changes wall clock and nothing else: the same
	// bytes, the same produced files, and the same diagnostics in the same
	// order.
	//
	// Zero or one keeps every transform on one goroutine, which is the default
	// because concurrency is a promise about the caller's transform that only
	// the caller can make. Being a pure function of what it reads is necessary
	// and not sufficient: a transform holding a shared scratch buffer is pure by
	// that definition and unsafe by this one. Set this only once Transform is
	// safe for concurrent use.
	//
	// A warm cache converts nothing and starts nothing whatever this says.
	//
	// It is excluded from the hashed options deliberately. Every other field
	// here can change what is generated, and this one cannot: it says how many
	// goroutines do the same work. Hashing it would stamp the machine that ran
	// the build into the output, so a four-core laptop and a sixteen-core runner
	// would disagree on bytes that are identical in every way that matters, and
	// `--check` would fail on the difference between two correct builds.
	ConversionWorkers int `json:"-"`

	DisableFeatures []Feature
	GenerateAll     bool
}

Options configures discovery identities and generated template APIs. A zero Options value intentionally discovers nothing and disables optional wrappers; use DefaultOptions for standard behavior.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the standard tinybind runtime setup.

type PackagePlan

type PackagePlan struct {
	Package     string
	PackagePath string
	Types       []TypePlan
	// Discovered lists type names referenced by configured generic call sites.
	Discovered []string
}

PackagePlan is all type plans in a package.

func AnalyzePackage

func AnalyzePackage(dir string) (*PackagePlan, error)

AnalyzePackage builds field plans for all package-level structs with exported fields. Generic call discovery (Bind/Write/DecodeJSON/EncodeJSON) uses go/types symbol identity.

func AnalyzePackageWithOptions

func AnalyzePackageWithOptions(dir string, opts Options) (*PackagePlan, error)

AnalyzePackageWithOptions is AnalyzePackage with customizable call targets.

type PatternSet

type PatternSet[T any] struct {
	Set      []T
	Disabled bool
}

PatternSet is an authoritative set of discovery identities. Set replaces, rather than extends, any defaults. Disabled suppresses the feature entirely.

type SymbolPattern

type SymbolPattern struct{ PackagePath, Name string }

SymbolPattern identifies a package-level declaration by go/types identity.

type TypePattern

type TypePattern struct{ PackagePath, Name string }

TypePattern identifies a named type by go/types identity.

type TypePlan

type TypePlan struct {
	Name string
	// SourcePath is the Go file that declares the type. It is the owning source
	// of every artifact generated for this type.
	SourcePath string
	Fields     []FieldPlan
	// Doc is the godoc of the type declaration.
	Doc string
	// Usage records which generated entry points are referenced by source code.
	// Zero means the type is unused and emits no mapping paths.
	Usage Usage
	// DirectUsage excludes usage inherited from containing structs.
	DirectUsage Usage
}

TypePlan is the mapping plan for one struct type.

type TypeSource added in v0.1.12

type TypeSource struct {
	GenericArgument *int
	ArgumentType    *int
}

TypeSource selects a semantic type from a generic argument or value argument.

type Usage

type Usage uint32

Usage selects generated mapping entry points.

const (
	UsageBind Usage = 1 << iota
	UsageWrite
	UsageDecodeJSON
	UsageEncodeJSON
	UsageScanRows
	UsageEncodeItem
	UsageDecodeItem
	UsageItemKey
	UsageEncodeEntity
	UsageDecodeEntity
	UsageEntityKey
	UsageAll = UsageBind | UsageWrite | UsageDecodeJSON | UsageEncodeJSON
	// UsageItem is every DynamoDB item entry point. It stays out of UsageAll:
	// the item codec has its own generate-all rule, which requires a dynamo tag,
	// so an unrelated request struct never acquires one.
	UsageItem = UsageEncodeItem | UsageDecodeItem | UsageItemKey
	// UsageEntity is every Firestore entity entry point, and stays out of
	// UsageAll for the same reason, requiring a firestore tag instead.
	UsageEntity = UsageEncodeEntity | UsageDecodeEntity | UsageEntityKey
)

type ValueSource added in v0.1.12

type ValueSource struct {
	Argument   *int
	Constant   any
	IsConstant bool
}

ValueSource selects a semantic value from a value argument or a fixed constant.

Jump to

Keyboard shortcuts

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