xgen

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComponentCodegen added in v0.38.0

type ComponentCodegen struct {
	Component    *shapeload.Component
	Resource     *view.Resource
	TypeContext  *typectx.Context
	ProjectDir   string
	PackageDir   string
	PackageName  string
	PackagePath  string
	FileName     string // defaults to <component_name>.go
	WithEmbed    bool   // generate //go:embed and EmbedFS method
	WithContract bool   // generate DefineComponent function
	WithRegister *bool  // generate init() with core.RegisterType (default: true)
}

ComponentCodegen generates Go source code for a complete component package: Input struct, Output struct, entity view structs, init() registration, //go:embed directive, and DefineComponent function.

This is the shape pipeline equivalent of repository.Component.GenerateOutputCode.

func (*ComponentCodegen) Generate added in v0.38.0

func (g *ComponentCodegen) Generate() (*ComponentCodegenResult, error)

Generate produces the component Go source file.

type ComponentCodegenResult added in v0.38.0

type ComponentCodegenResult struct {
	FilePath       string
	PackageDir     string
	PackagePath    string
	PackageName    string
	Types          []string
	GeneratedFiles []string
	InputFilePath  string
	OutputFilePath string
	ViewFilePath   string
	RouterFilePath string
	VeltyFilePath  string
	Embeds         map[string]string // SQL file name → SQL content
}

ComponentCodegenResult captures generation outputs.

type Config

type Config struct {
	// ProjectDir points to target Go project root.
	ProjectDir string
	// PackageDir points to package directory inside the project (relative or absolute).
	PackageDir string
	// PackageName sets generated package name; defaults to basename(PackageDir).
	PackageName string
	// PackagePath sets fully-qualified import path; when empty it's derived from go.mod + PackageDir.
	PackagePath string
	// FileName sets generated filename; defaults to shapes_gen.go.
	FileName string
	// TypePrefix prefixes generated type names.
	TypePrefix string
	// ViewSuffix appends suffix to generated view type names when schema name is absent.
	ViewSuffix string
	// InputSuffix appends suffix to generated route input type names when explicit type name is absent.
	InputSuffix string
	// OutputSuffix appends suffix to generated route output type names when explicit type name is absent.
	OutputSuffix string
	// ViewTypeNamer customizes final view type name.
	ViewTypeNamer func(ctx ViewTypeContext) string
	// InputTypeNamer customizes final input type name.
	InputTypeNamer func(ctx RouteTypeContext) string
	// OutputTypeNamer customizes final output type name.
	OutputTypeNamer func(ctx RouteTypeContext) string
	// Registry allows reusing an external viant/x registry.
	Registry *x.Registry
	// AllowUnsafeRewrite allows overwriting existing generated files even when
	// type provenance indicates unresolved/unsafe origins. Default false.
	AllowUnsafeRewrite bool
	// AllowedProvenanceKinds controls which provenance kinds are trusted for updates.
	// Defaults to builtin, resource_type and ast_type.
	AllowedProvenanceKinds []string
	// AllowedSourceRoots controls additional trusted roots for provenance files.
	// ProjectDir is always implicitly trusted.
	AllowedSourceRoots []string
	// UseGoModuleResolve enables go.mod + replace-based source resolution. Default true.
	UseGoModuleResolve *bool
	// UseGOPATHFallback enables GOPATH/src fallback when go.mod resolution misses. Default true.
	UseGOPATHFallback *bool
	// StrictProvenance blocks updates on policy violations. Default true.
	StrictProvenance *bool
}

Config controls shape->Go generation.

type Result

type Result struct {
	FilePath    string
	PackagePath string
	PackageName string
	Types       []string
}

Result captures generation outputs.

func GenerateFromDQLShape

func GenerateFromDQLShape(doc *shape.Document, cfg *Config) (*Result, error)

GenerateFromDQLShape emits Go structs from DQL shape using viant/x registry.

func GenerateFromResource added in v0.38.0

func GenerateFromResource(resource *view.Resource, typeCtx *typectx.Context, cfg *Config) (*Result, error)

GenerateFromResource produces Go structs directly from an in-memory view.Resource without YAML roundtrip. Uses real columns from DB discovery when available.

type RouteTypeContext

type RouteTypeContext struct {
	RouteName string
	RouteURI  string
	RouteRef  string
	TypeName  string
}

type ViewTypeContext

type ViewTypeContext struct {
	ViewName   string
	SchemaName string
}

Jump to

Keyboard shortcuts

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