resourcegen

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package resourcegen implements `gombit make resource`.

It writes a feature-package (model, thin Huma handler, routes; optional service.go / repo.go), React list/form pages that import generated OpenAPI client types, and registers the package from cmd/server/main.go via go/ast. Generators are idempotent and additive; Go source is never patched with regular expressions.

Index

Constants

View Source
const (
	// GeneratedBanner marks files written by this generator. User-owned files
	// without the banner are refused unless --force is set. Identical re-runs
	// rewrite the same bytes (idempotent).
	GeneratedBanner = "Code generated by gombit make resource. DO NOT EDIT."
)

Variables

This section is empty.

Functions

func AddAutoMigrateModel

func AddAutoMigrateModel(src []byte, importPath, pkgName, typeName string) ([]byte, error)

AddAutoMigrateModel adds `&<pkg>.<type>{}` to the AutoMigrate call in internal/platform and ensures importPath is imported. Idempotent.

func AddImportAndRegister

func AddImportAndRegister(src []byte, importPath, pkgName string) ([]byte, error)

AddImportAndRegister adds `importPath` and `<pkg>.Register(app)` next to an existing `*.Register(app)` call (the scaffold's product.Register) or, if none exists, immediately before `framework.Run(app)` — including the `if err := framework.Run(app); err != nil` form used by the app template. The edit is idempotent: a second call does not duplicate the import or the Register invocation.

func CollectAutoMigrateModels

func CollectAutoMigrateModels(src []byte) ([]migrations.Model, error)

CollectAutoMigrateModels returns every `&pkg.Type{}` argument of AutoMigrate calls in src, resolved to import path + type name via the file's imports. Atlas migrate diff treats that slice as the entire desired schema, so callers must pass every registered model — not only the resource being generated.

func CountRegisterCalls

func CountRegisterCalls(src []byte, pkgName string) (int, error)

CountRegisterCalls reports how many `<pkg>.Register(...)` calls appear in src.

func Generate

func Generate(ctx context.Context, opts Options) error

Generate writes a feature-package resource into an existing Gombit app.

Types

type Field

type Field struct {
	Name     string
	JSONName string
	GoName   string
	Type     FieldType
	GoType   string
	Required bool
	Unique   bool
	Index    bool
	Nullable bool

	// Filterable / Sortable / Searchable opt this field into the generated list
	// handler's declared query surface (issue #260): exact-match ?<field>=,
	// ?ordering=<field> (- prefix for DESC), and ?search= respectively — the same
	// spelling as the admin data plane. belongs_to fields are filterable by
	// default (see isFilterable) so the has_many detail-list case —
	// GET /children?<parent>_id=<id> — works without extra declaration.
	Filterable bool
	Sortable   bool
	Searchable bool

	// Aggregatable opts this numeric field into the generated list handler's
	// server-side aggregate surface (issue #272): ?aggregate=sum:<field>,
	// avg:<field>,min:<field>,max:<field>, computed over the same filtered and
	// searched set as the list, before pagination. Only numeric columns (int,
	// int64, uint, decimal) may opt in (see typeAllowsAggregate).
	Aggregatable bool

	// EnumValues holds the allowed values for FieldEnum, in declared order.
	EnumValues []string
	// Precision/Scale set the decimal(p,s) column for FieldDecimal.
	Precision int
	Scale     int

	// Target is the related model type (PascalCase) for a relation field, e.g.
	// "Engine". TargetPkg is its feature-package name (snake), e.g. "engine".
	Target    string
	TargetPkg string
}

Field is one parsed resource field from the CLI grammar name:type[:required][,unique][,index] (design §27 subset).

type FieldType

type FieldType string

FieldType is a supported scalar in the v0.1 subset.

const (
	FieldString  FieldType = "string"
	FieldText    FieldType = "text"
	FieldInt     FieldType = "int"
	FieldInt64   FieldType = "int64"
	FieldBool    FieldType = "bool"
	FieldUint    FieldType = "uint"
	FieldDecimal FieldType = "decimal"
	FieldTime    FieldType = "time"
	FieldEnum    FieldType = "enum"

	FieldBelongsTo  FieldType = "belongs_to"
	FieldHasMany    FieldType = "has_many"
	FieldManyToMany FieldType = "many_to_many"
)

type Options

type Options struct {
	WorkDir  string
	Name     string
	Fields   []string
	Service  bool
	Repo     bool
	DryRun   bool
	Force    bool
	Stdout   io.Writer
	Stderr   io.Writer
	AtlasBin string
	// contains filtered or unexported fields
}

Options configures resource generation inside an existing application.

type ResourceName

type ResourceName struct {
	Input       string
	TypeName    string
	Package     string
	FileBase    string
	PluralSnake string
	HTTPPath    string
	Tag         string
	Kebab       string
}

ResourceName is the derived identifiers for one generated feature-package.

Jump to

Keyboard shortcuts

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