recipes

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package recipes renders the project templates used by orb new.

Each preset's templates are generated from a hand-written golden app by `go generate`: minimal/ from examples/minimal; v0.2/full/ and v0.2/full-multi/, the layout orb new writes (apps on gorbital.Main, ADR-0083), from examples/full-single and examples/full-multi; and full/ and full-multi/, the v0.1 layout that v0.1 apps keep, from examples/v0.1/full-single and examples/v0.1/full-multi (ADR-0041, ADR-0048). Never edit them by hand.

Index

Constants

View Source
const (
	KindCustom   = "custom"
	KindHTTP     = "http"
	KindSQL      = "sql"
	KindEmail    = "email"
	KindDispatch = "dispatch"
)

Kinds of generated jobs.

View Source
const (
	MailResend = "resend"
	MailSMTP   = "smtp"
)

Email providers offered by orb add mail (ADR-0037).

View Source
const (
	// InfraMailPath is the provider file orb add mail replaces.
	InfraMailPath = "internal/app/infra_mail.go"
	// InfraMailTestPath holds the provider's side of the app's tests, so the
	// rest of them pass with any provider. orb add mail replaces it too.
	InfraMailTestPath = "internal/app/infra_mail_test.go"
	// MainMailPath is the provider file orb add mail replaces in apps on
	// gorbital.Main (the v0.2 layout): the function main.go passes to
	// gorbital.WithMailerFunc.
	MainMailPath = "cmd/api/mail.go"
	// MailBlock names the block of .env.example holding the provider's
	// variables: from "# orb:begin mail" to "# orb:end mail".
	MailBlock = "mail"
)

Paths and names orb add mail works with.

View Source
const (
	// MiddlewareModule is middleware in a module's delivery package, added
	// with gorbital.Use or Module.Middleware.
	MiddlewareModule = "module"
	// MiddlewareGlobal is middleware in internal/middleware, added to every
	// route with gorbital.WithMiddleware.
	MiddlewareGlobal = "global"
	// MiddlewareGuard is a guard.New guard in a module's delivery package,
	// with the error it refuses requests with.
	MiddlewareGuard = "guard"
)

Kinds of orb gen middleware.

View Source
const (
	MinimalName   = "base-minimal"
	FullName      = "base-full"
	FullMultiName = "base-full-multi"
	// LibraryVersion is the gorbital library version generated apps require.
	LibraryVersion = "v0.2.0"
)

Recipe identities: the names of the preset template trees.

View Source
const (
	// LayoutV01 is the layout of v0.1: a composition root in internal/app
	// wiring generated modules, with cmd/migrate and cmd/seed. Minimal apps
	// keep it (roadmap decision D17). gorbital.lock records it as no layout.
	LayoutV01 = "v0.1"
	// LayoutV02 is the layout of v0.2: cmd/api/main.go on gorbital.Main, the
	// app's modules in internal/modules and its migrations in db/migrations
	// (ADR-0083). orb new writes it for the Full preset.
	LayoutV02 = "v0.2"
)

App layouts. A layout is how an app's code is organised, and which templates wrote it: orb upgrade and orb add rebuild and merge an app from the templates of its own layout.

View Source
const (
	TenancySingle = "single"
	TenancyMulti  = "multi"
)

Tenancy values of orb new --tenancy (ADR-0023).

View Source
const (
	KindString = "string" // 1 to StringMaxLength characters; required, sortable, can be unique
	KindText   = "text"   // up to TextMaxLength characters; optional
	KindEnum   = "enum"   // one of a fixed list, the first by default; filterable
)

Field kinds of orb gen resource (ADR-0039).

View Source
const (
	StringMaxLength = 100
	TextMaxLength   = 2000
	MaxFields       = 20
)

Limits of generated resources.

View Source
const (
	ScopeUser = "user"
	ScopeOrg  = "org"
)

Resource scopes of orb gen resource --scope.

View Source
const ArchitectureTestPath = ModulesDir + "/architecture_test.go"

ArchitectureTestPath is the test that checks every module's layers.

View Source
const JobAnchor = "//orb:anchor jobs"

JobAnchor is the anchor in internal/app/jobs.go that orb gen job adds a line after.

View Source
const LegacyMarker = "aps"

LegacyMarker is the marker prefix apps generated before the rename to gorbital carry in .env.example. Blocks are found under either prefix and always written back with the current one.

View Source
const MiddlewareDir = "internal/middleware"

MiddlewareDir is the package orb gen middleware --global writes into.

View Source
const MiddlewareDocPath = MiddlewareDir + "/doc.go"

MiddlewareDocPath is the package comment of internal/middleware.

View Source
const ModulesAnchor = "//orb:anchor modules"

ModulesAnchor is the anchor in internal/app/modules.go that orb gen resource adds a line after.

View Source
const ModulesDir = "internal/modules"

ModulesDir is where an app on gorbital.Main keeps its modules.

View Source
const OrgPermissionsAnchor = "//orb:anchor org-permissions"

OrgPermissionsAnchor is the anchor in internal/app/permissions.go that orb gen resource --scope org adds a line after, so the organisation roles get the new resource's permissions.

View Source
const OrgsMigrationPath = "db/migrations/20260916000001_orgs.sql"

OrgsMigrationPath is the organisations migration in the multi-tenant tree. orb add orgs copies its content under a new version (ADR-0050).

View Source
const RowLevelSecurityKey = "rls"

RowLevelSecurityKey is the gorbital.yaml key orb add rls sets to true.

View Source
const RowLevelSecurityPath = "db/row_level_security.sql"

RowLevelSecurityPath is the row-level security migration in the multi-tenant tree. orb add rls copies the app's copy of it into db/migrations under a new version; until then it isn't applied, so every multi-tenant app renders the same tree (ADR-0061).

View Source
const UserPermissionsAnchor = "//orb:anchor user-permissions"

UserPermissionsAnchor is the anchor in internal/app/permissions.go that orb gen resource --scope user adds a line after, so the user role every user holds gets the new resource's permissions and API keys can be scoped to them (ADR-0058).

Variables

View Source
var ErrAnchorMissing = errors.New("anchor not found")

ErrAnchorMissing reports a file without the anchor to insert after.

View Source
var ErrBlockMissing = errors.New("block not found")

ErrBlockMissing reports a file without the named orb:begin/orb:end block.

View Source
var ErrLinePresent = errors.New("line already present")

ErrLinePresent reports a line that is already in the file.

JobKinds lists the kinds.

View Source
var OrgsLaterMigrationPaths = []string{
	"db/migrations/20260918000002_settings_org_purge.sql",
}

OrgsLaterMigrationPaths are multi-tenant migrations added after organisations shipped that only apply to an app with organisations. orb add orgs copies them, in order, after the conversion; apps that already have organisations get them through orb upgrade.

Functions

func Block

func Block(src []byte, name string) ([]byte, error)

Block returns the block named name from src, marker lines included.

func EnvKey

func EnvKey(line string) (string, bool)

EnvKey returns the variable a .env line assigns, if it assigns one.

func InsertAfterAnchor

func InsertAfterAnchor(src []byte, anchor, line string) ([]byte, error)

InsertAfterAnchor returns src with line inserted after the line holding anchor, indented like the anchor. It fails if the anchor is missing or the line already exists, and validates the result with gofmt.

func OrgsConversion

func OrgsConversion() []byte

OrgsConversion returns the migration orb add orgs writes after the organisations migration: a personal workspace for every account, and each project moved to its owner's workspace. It changes projects in place, so columns developers added are kept.

func PresetNames

func PresetNames() []string

PresetNames lists the presets orb new accepts, in the order it offers them.

func ReplaceBlock

func ReplaceBlock(src []byte, name string, block []byte) ([]byte, error)

ReplaceBlock returns src with the block named name, marker lines included, replaced by block.

func SetManifestKey

func SetManifestKey(src []byte, key, value string) []byte

SetManifestKey sets a top-level key in gorbital.yaml, keeping every other line.

func SetRowLevelSecurity

func SetRowLevelSecurity(tree map[string][]byte)

SetRowLevelSecurity records row-level security in tree's gorbital.yaml, as orb add rls writes it, so a rebuilt tree matches the app's lock.

func SupportsTenancy

func SupportsTenancy(name string) bool

SupportsTenancy reports whether the preset name has a multi-tenant variant, so orb new asks about tenancy.

func ValidateModuleName added in v0.2.0

func ValidateModuleName(name string) error

ValidateModuleName reports whether name can name a module, before its fields are known.

func ValidateResourceName

func ValidateResourceName(name string) error

ValidateResourceName reports whether name can name a resource, before its fields are known.

func WorkerHash

func WorkerHash(content []byte) string

WorkerHash is the hash the marker records for a worker file.

Types

type Data

type Data struct {
	Name           string // app name, for example "my-api"
	Module         string // Go module path
	LibraryVersion string
	// Local, when set, is a path to a gorbital checkout used through
	// replace directives (development before a release is published).
	Local string
}

Data fills the templates.

func (Data) LocalDir

func (d Data) LocalDir(dir string) string

LocalDir is the directory of a library module in the local checkout, as a go.mod path: dir is "" for the core module or "/modules/<name>". Paths go.mod can't hold bare, such as ones with spaces, are quoted.

type EnumValue

type EnumValue struct {
	Value string // such as on_hold
	Ident string // such as OnHold
}

EnumValue is one allowed value of an enum field.

type Field

type Field struct {
	Name   string // snake_case column and JSON name, such as due_date
	Ident  string // Go identifier, such as DueDate
	Human  string // words, such as due date
	Kind   string
	Unique bool
	// Optional marks a string field written name:string? (orb gen module
	// only): 0 to StringMaxLength characters, and never the title.
	Optional bool
	Values   []EnumValue // enum fields only
}

Field is one field of a generated resource.

func ParseFields

func ParseFields(specs []string) ([]Field, error)

ParseFields parses orb gen resource's field specs, such as name:string:unique, notes:text and status:enum(active,archived).

func ParseModuleFields added in v0.2.0

func ParseModuleFields(specs []string) ([]Field, error)

ParseModuleFields parses orb gen module's field specs: those of ParseFields, and optional strings such as nickname:string?.

func (Field) A

func (f Field) A() string

A is the indefinite article for f.Human.

func (Field) Constraint

func (f Field) Constraint() string

Constraint is the column definition after the column's type.

func (Field) EnumMessage

func (f Field) EnumMessage() string

EnumMessage is the validation message for an unknown value.

func (Field) EnumTag

func (f Field) EnumTag() string

EnumTag is the value of Huma's enum tag, such as active,archived.

func (Field) FirstValue

func (f Field) FirstValue() EnumValue

FirstValue is an enum field's default value.

func (Field) GoType

func (f Field) GoType() string

GoType is f's type inside the domain package.

func (Field) HumanTitle

func (f Field) HumanTitle() string

HumanTitle is f.Human starting with a capital letter.

func (Field) IsEnum

func (f Field) IsEnum() bool

IsEnum reports whether f is an enum field.

func (Field) LastValue

func (f Field) LastValue() EnumValue

LastValue is an enum field's last value.

func (Field) MaxLength

func (f Field) MaxLength() int

MaxLength is the most characters a text field accepts.

func (Field) MinLength

func (f Field) MinLength() int

MinLength is the fewest characters a text field accepts.

func (Field) Sample

func (f Field) Sample(qualifier string) string

Sample is a Go expression for a valid value; enum constants are qualified with qualifier, the domain package's name and a dot.

func (Field) ValueIdents

func (f Field) ValueIdents() string

ValueIdents lists the enum's constants, such as StatusActive, StatusArchived.

type File

type File struct {
	Path   string `json:"path"`
	SHA256 string `json:"sha256"`
}

A File is one rendered file.

type JobData

type JobData struct {
	Module      string // app module path, for example example.com/acme-api
	Ident       string // Go identifier, for example CleanupSessions
	Name        string // definition name, for example cleanup_sessions
	Package     string // package name, for example cleanupsessions
	Description string
	Enabled     bool
	Schedule    string // cron, descriptor, "@every 15m", or empty
	Timeout     time.Duration
	MaxAttempts int
	Queue       string
	Priority    int

	// Kind is what the job does (ADR-0071): custom (a Work method to
	// write), http (a request), sql (a statement), email (a message) or
	// dispatch (starts another job). Each kind's fields follow.
	Kind           string
	HTTPMethod     string
	HTTPURL        string
	HTTPBody       string
	SQL            string
	EmailTo        string
	EmailSubject   string
	EmailText      string
	DispatchTarget string
	// contains filtered or unexported fields
}

JobData fills the job templates (ADR-0035).

func (JobData) Marker

func (d JobData) Marker() string

Marker renders the //orb:job line's JSON.

func (JobData) TimeoutExpr

func (d JobData) TimeoutExpr() string

TimeoutExpr is the timeout as a Go expression, such as 5 * time.Minute.

func (JobData) WorkerArgs

func (d JobData) WorkerArgs() string

WorkerArgs are the arguments the definition passes to NewWorker.

type JobFile

type JobFile struct {
	Path    string
	Content []byte
}

JobFile is one rendered job file.

func RenderArchitectureTest added in v0.2.0

func RenderArchitectureTest(module string) (JobFile, error)

RenderArchitectureTest renders internal/modules/architecture_test.go for the app whose module path is module: the layer rules of every module (ADR-0039, ADR-0083). orb gen module writes it when the app has none.

func RenderJob

func RenderJob(d JobData) ([]JobFile, error)

RenderJob renders the job package, its test and its definition file, in that order. Go output is validated with gofmt. The definition's marker records the worker file's hash.

func RenderMiddleware added in v0.2.0

func RenderMiddleware(d MiddlewareData) ([]JobFile, error)

RenderMiddleware renders the middleware or guard and its table-driven test.

func RenderMiddlewareDoc added in v0.2.0

func RenderMiddlewareDoc() (JobFile, error)

RenderMiddlewareDoc renders internal/middleware/doc.go, which orb gen middleware --global writes with the package's first middleware.

func RenderModule added in v0.2.0

func RenderModule(d ModuleData) ([]JobFile, error)

RenderModule renders a module's files and its migration, in the order orb gen module lists them. Go output is formatted with gofmt.

func RenderResource

func RenderResource(d ResourceData) ([]JobFile, error)

RenderResource renders a resource's module, app wiring, tests and migration (ADR-0039). Go output is formatted with gofmt.

type JobMarker

type JobMarker struct {
	Kind           string `json:"kind"`
	HTTPMethod     string `json:"http_method,omitempty"`
	HTTPURL        string `json:"http_url,omitempty"`
	HTTPBody       string `json:"http_body,omitempty"`
	SQL            string `json:"sql,omitempty"`
	EmailTo        string `json:"email_to,omitempty"`
	EmailSubject   string `json:"email_subject,omitempty"`
	EmailText      string `json:"email_text,omitempty"`
	DispatchTarget string `json:"dispatch_target,omitempty"`
	// Worker is the SHA-256 of the generated worker file: while the file
	// still hashes to it, the portal shows the form; once edited by hand,
	// the job is ejected and edited in code.
	Worker string `json:"worker"`
}

JobMarker is what the Dev Portal reads back from a generated job's definition file (the //orb:job line) to show it as a form again.

func ParseJobMarker

func ParseJobMarker(src []byte) (JobMarker, bool)

ParseJobMarker returns the marker in a definition file, or false when the file has none (a hand-written job).

type MailRecipe

type MailRecipe struct {
	Provider string
	// Label is the provider's display name.
	Label string
	// InfraMail is the content of internal/app/infra_mail.go.
	InfraMail []byte
	// InfraMailTest is the content of internal/app/infra_mail_test.go.
	InfraMailTest []byte
	// MainMail is the content of cmd/api/mail.go in the v0.2 layout; nil in
	// releases before it.
	MainMail []byte
	// EnvBlock is the provider's block of .env.example, markers included.
	EnvBlock []byte
	// EnvKeys are the variables EnvBlock assigns, in order.
	EnvKeys []string
	// Modules are the gorbital modules the app needs with this provider.
	Modules []string
}

MailRecipe is what one email provider adds to a Full preset app.

func RenderMail

func RenderMail(provider, module string) (MailRecipe, error)

RenderMail returns this orb's recipe for provider in the app with Go module path module. Go output is validated with gofmt.

type MiddlewareData added in v0.2.0

type MiddlewareData struct {
	// AppModule is the app's module path.
	AppModule string
	// Kind is MiddlewareModule, MiddlewareGlobal or MiddlewareGuard.
	Kind string
	// ModuleName is the module whose delivery package holds it; empty for
	// global middleware.
	ModuleName string
	Ident      string // RequireClientVersion
	Snake      string // require_client_version: file, guard and code names
	Human      string // require client version
}

MiddlewareData fills the middleware and guard templates.

func NewMiddlewareData added in v0.2.0

func NewMiddlewareData(appModule, name, kind, moduleName string) (MiddlewareData, error)

NewMiddlewareData validates orb gen middleware's name and kind.

func (MiddlewareData) Check added in v0.2.0

func (d MiddlewareData) Check() string

Check is the unexported function holding the rule.

func (MiddlewareData) Code added in v0.2.0

func (d MiddlewareData) Code() string

Code is a guard's problem code.

func (MiddlewareData) Declared added in v0.2.0

func (d MiddlewareData) Declared() []string

Declared are the package-level names the files declare, which must be free in the package.

func (MiddlewareData) Dir added in v0.2.0

func (d MiddlewareData) Dir() string

Dir is the package's directory, relative to the app.

func (MiddlewareData) Err added in v0.2.0

func (d MiddlewareData) Err() string

Err is a guard's refusal error.

func (MiddlewareData) ErrorMapping added in v0.2.0

func (d MiddlewareData) ErrorMapping() string

ErrorMapping is the line mapping a guard's error, for module.go's Errors.

func (MiddlewareData) File added in v0.2.0

func (d MiddlewareData) File() string

File is the middleware's file; Test is its test.

func (MiddlewareData) Package added in v0.2.0

func (d MiddlewareData) Package() string

Package is the Go package the files go in.

func (MiddlewareData) Test added in v0.2.0

func (d MiddlewareData) Test() string

Test is the middleware's test file.

func (MiddlewareData) Wire added in v0.2.0

func (d MiddlewareData) Wire() string

Wire is the Go code that puts the middleware to use, for the developer to add: orb gen middleware never edits routes.go, module.go or main.go.

type ModuleData added in v0.2.0

type ModuleData struct {
	ResourceData
}

ModuleData fills the module templates: a resource's names and fields (ResourceData), owned by a user or, with Org, by an organisation, with the generated code's own helpers.

func NewModuleData added in v0.2.0

func NewModuleData(module, name string, fields []Field, o ResourceOptions) (ModuleData, error)

NewModuleData validates a module and derives every name. fields come from ParseModuleFields. o.Scope is ScopeUser (the default) or ScopeOrg; o.RLS adds the row-level security policy to an organisation module's migration.

func (ModuleData) BodyChoice added in v0.2.0

func (d ModuleData) BodyChoice() string

BodyChoice is a body member setting the first enum field to its last value, starting with a comma, or "".

func (ModuleData) BodyDuplicate added in v0.2.0

func (d ModuleData) BodyDuplicate() string

BodyDuplicate are body members that reuse, in capitals, the first unique field of the tests' "Website" and differ in every other unique field.

func (ModuleData) BodyFields added in v0.2.0

func (d ModuleData) BodyFields(title string) string

BodyFields are the members of a map[string]any request body in the HTTP tests, with title as the title and other unique fields made from it, so bodies with different titles don't clash; enum fields are left out, so they take their defaults.

func (ModuleData) Dir added in v0.2.0

func (d ModuleData) Dir() string

Dir is the module's directory, such as internal/modules/shelves.

func (ModuleData) Guard added in v0.2.0

func (d ModuleData) Guard() string

Guard is the guard the routes check their permission with: guard.OrgMember in an organisation, guard.Permission otherwise.

func (ModuleData) ImportPath added in v0.2.0

func (d ModuleData) ImportPath() string

ImportPath is the module package's import path.

func (ModuleData) MigrationPath added in v0.2.0

func (d ModuleData) MigrationPath() string

MigrationPath is the module's migration.

func (ModuleData) PermRead added in v0.2.0

func (d ModuleData) PermRead() string

PermRead and PermWrite are the module's permission names.

func (ModuleData) PermWrite added in v0.2.0

func (d ModuleData) PermWrite() string

PermWrite is the permission the module's writes need.

func (ModuleData) PluralVar added in v0.2.0

func (d ModuleData) PluralVar() string

PluralVar is the plural as a Go variable, such as orderItems.

func (ModuleData) RoutePath added in v0.2.0

func (d ModuleData) RoutePath() string

RoutePath is the collection's path, such as /v1/shelves, or /v1/orgs/{orgId}/club-books for an organisation module.

func (ModuleData) SampleFields added in v0.2.0

func (d ModuleData) SampleFields(title string) string

SampleFields is ResourceData.SampleFields for the domain package's own name.

func (ModuleData) Scope added in v0.2.0

func (d ModuleData) Scope() string

Scope is ScopeOrg or ScopeUser.

func (ModuleData) ScopeColumn added in v0.2.0

func (d ModuleData) ScopeColumn() string

ScopeColumn is the column holding ScopeVar: org_id or owner_id.

func (ModuleData) ScopeField added in v0.2.0

func (d ModuleData) ScopeField() string

ScopeField is the domain field holding ScopeVar: OrgID or OwnerID.

func (ModuleData) ScopeVar added in v0.2.0

func (d ModuleData) ScopeVar() string

ScopeVar is the Go parameter naming whose records an operation reaches: orgID or ownerID.

type Preset

type Preset struct {
	// Name is the value of orb new --preset.
	Name string
	// Tenancy is the value of orb new --tenancy: single, or multi for
	// organisations.
	Tenancy string
	// Recipe names the preset's template tree.
	Recipe string
	// contains filtered or unexported fields
}

A Preset is an app orb new can create.

func LookupPreset

func LookupPreset(name, tenancy string) (Preset, bool)

LookupPreset returns the preset orb new --preset name --tenancy tenancy selects.

func (Preset) Layout added in v0.2.0

func (p Preset) Layout() string

Layout returns the layout orb new writes for the preset: LayoutV02 for the Full preset, LayoutV01 for Minimal, which keeps composing core packages directly.

func (Preset) Render

func (p Preset) Render(root *os.Root, d Data) ([]File, error)

Render writes the preset, in the layout orb new writes (Layout), into root and returns the files written, sorted by path. Go files are validated with gofmt before writing.

type Release

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

A Release is the templates of one orb release, laid out like this package's directory: minimal/, full/, full-multi/ and mail/, and from v0.2 on v0.2/full/ and v0.2/full-multi/. Every release uses the same template format, and keeps each directory for the layout it has always held (ADR-0050).

func Embedded

func Embedded() Release

Embedded returns this orb's own templates.

func ReleaseFS

func ReleaseFS(fsys fs.FS) Release

ReleaseFS returns the templates of a release whose cli/internal/recipes directory is fsys, such as an older release fetched by orb upgrade. They are read and rendered as text; nothing in them is compiled or run.

func (Release) Mail

func (r Release) Mail(provider, module string) (MailRecipe, error)

Mail returns the release's recipe for provider in the app with Go module path module.

func (Release) Tree

func (r Release) Tree(preset, tenancy, layout, mail string, d Data) (map[string][]byte, error)

Tree renders every file orb writes for an app of preset and tenancy in layout (LayoutV01 or LayoutV02) that sends email with mail ("" for presets without email), keyed by slash-separated path: the preset's templates, then the provider's files, exactly as orb new and orb add mail write them.

type ResourceData

type ResourceData struct {
	Module      string // app module path, such as example.com/acme-api
	Ident       string // Project
	Var         string // project
	Snake       string // project: audit actions, error codes, file names
	Human       string // project
	Plural      string // Projects
	PluralHuman string // projects
	Package     string // projects
	Table       string // projects
	Route       string // projects, as in /v1/projects
	IDPrefix    string // prj
	Migration   string // 20260915000002
	// Org reports records that belong to an organisation (--scope org)
	// instead of a user.
	Org bool
	// RLS reports an organisation resource whose migration forces
	// row-level security with the organisation policy (ADR-0061).
	RLS    bool
	Fields []Field
}

ResourceData fills the resource templates (ADR-0039).

func NewResourceData

func NewResourceData(module, name string, fields []Field, o ResourceOptions) (ResourceData, error)

NewResourceData validates a resource and derives every name.

func (ResourceData) A

func (d ResourceData) A() string

A is the indefinite article for d.Human.

func (ResourceData) ChangedNames

func (d ResourceData) ChangedNames() string

ChangedNames is a Go []string literal of the fields the tests change: the title and the first enum field, in field order.

func (ResourceData) Columns

func (d ResourceData) Columns() string

Columns lists the field columns: name, description, status.

func (ResourceData) EnumPlaceholder

func (d ResourceData) EnumPlaceholder(i int) int

EnumPlaceholder is the list query's placeholder for the i-th enum filter.

func (ResourceData) Enums

func (d ResourceData) Enums() []Field

Enums are the enum fields.

func (ResourceData) FieldNames

func (d ResourceData) FieldNames() string

FieldNames is a Go []string literal of every field name.

func (ResourceData) FirstEnum

func (d ResourceData) FirstEnum() Field

FirstEnum is the first enum field, or the zero Field.

func (ResourceData) FirstUnique

func (d ResourceData) FirstUnique() Field

FirstUnique is the first unique field, or the zero Field.

func (ResourceData) HasEnums

func (d ResourceData) HasEnums() bool

HasEnums reports whether the resource has an enum field.

func (ResourceData) HasUniques

func (d ResourceData) HasUniques() bool

HasUniques reports whether the resource has a unique field.

func (ResourceData) InsertPlaceholders

func (d ResourceData) InsertPlaceholders() string

InsertPlaceholders are the insert's placeholders: id, the owner (or the organisation and creator), the fields, version and the two times.

func (ResourceData) InvalidFields

func (d ResourceData) InvalidFields() string

InvalidFields are Go composite literal members that make every field invalid.

func (ResourceData) JSONChoice

func (d ResourceData) JSONChoice() string

JSONChoice is a JSON member setting the first enum field to its last value, starting with a comma, or "".

func (ResourceData) JSONDuplicate

func (d ResourceData) JSONDuplicate() string

JSONDuplicate are JSON members that reuse, in capitals, the first unique field of the end-to-end test's "Website" and differ in every other unique field.

func (ResourceData) JSONFields

func (d ResourceData) JSONFields(title string) string

JSONFields are JSON members of a request body in the end-to-end test, made the same way as SampleFields. Enum fields are left out, so they take their defaults.

func (ResourceData) ModulesLine

func (d ResourceData) ModulesLine() string

ModulesLine is the line orb gen resource adds after ModulesAnchor.

func (ResourceData) Pad

func (d ResourceData) Pad(name string) string

Pad pads a column name to align the migration's column types.

func (ResourceData) PermissionsAnchor

func (d ResourceData) PermissionsAnchor() string

PermissionsAnchor is the anchor PermissionsLine goes after: OrgPermissionsAnchor or UserPermissionsAnchor.

func (ResourceData) PermissionsLine

func (d ResourceData) PermissionsLine() string

PermissionsLine is the line orb gen resource adds after PermissionsAnchor: the permissions its app wiring file declares.

func (ResourceData) PluralTitle

func (d ResourceData) PluralTitle() string

PluralTitle is d.PluralHuman starting with a capital letter.

func (ResourceData) SampleFields

func (d ResourceData) SampleFields(title string) string

SampleFields are Go composite literal members of valid fields. With a title expression, the title field is set to it and other unique fields are made from it, so samples with different titles don't clash.

func (ResourceData) SortFields

func (d ResourceData) SortFields() []string

SortFields are the fields a list can be sorted by.

func (ResourceData) SortList

func (d ResourceData) SortList() string

SortList is the sortable fields in words: created_at, updated_at or name.

func (ResourceData) SortListCode

func (d ResourceData) SortListCode() string

SortListCode is SortList with each field in Markdown code.

func (ResourceData) Strings

func (d ResourceData) Strings() []Field

Strings are the string fields; the first is the title.

func (ResourceData) TakenErrors

func (d ResourceData) TakenErrors() string

TakenErrors names the unique fields' errors, such as ErrProjectNameTaken.

func (ResourceData) TextFields

func (d ResourceData) TextFields() []Field

TextFields are the string and text fields.

func (ResourceData) Title

func (d ResourceData) Title() Field

Title is the first required string field, which lists sort by in the tests.

func (ResourceData) Uniques

func (d ResourceData) Uniques() []Field

Uniques are the unique fields.

func (ResourceData) UpdateSet

func (d ResourceData) UpdateSet() string

UpdateSet assigns each field from placeholders $3 onwards.

func (ResourceData) UpdatedAtPlaceholder

func (d ResourceData) UpdatedAtPlaceholder() int

UpdatedAtPlaceholder is the update's placeholder for updated_at.

func (ResourceData) VersionPlaceholder

func (d ResourceData) VersionPlaceholder() int

VersionPlaceholder is the update's placeholder for the expected version.

type ResourceOptions

type ResourceOptions struct {
	// Plural is a Go-style plural name, such as People. The default adds the
	// English plural ending to the last word.
	Plural string
	// IDPrefix starts every ID, such as prj for Project. The default takes
	// the first letter and the next consonants.
	IDPrefix string
	// Migration is the migration's version: a UTC timestamp such as
	// 20260915093000.
	Migration string
	// Scope is who the records belong to: ScopeUser (the default) or
	// ScopeOrg, for multi-tenant apps (ADR-0048).
	Scope string
	// RLS adds the row-level security policy to an organisation resource's
	// migration, for apps that ran orb add rls (ADR-0061).
	RLS bool
}

ResourceOptions override the names derived from a resource's name.

Directories

Path Synopsis
Command gen regenerates every preset's recipe templates from its golden app.
Command gen regenerates every preset's recipe templates from its golden app.
Package generate converts a hand-written golden app into recipe templates: it replaces the placeholder module path and name, and derives the go.mod template from the golden go.mod (ADR-0041).
Package generate converts a hand-written golden app into recipe templates: it replaces the placeholder module path and name, and derives the go.mod template from the golden go.mod (ADR-0041).

Jump to

Keyboard shortcuts

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