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
- Variables
- func Block(src []byte, name string) ([]byte, error)
- func EnvKey(line string) (string, bool)
- func InsertAfterAnchor(src []byte, anchor, line string) ([]byte, error)
- func OrgsConversion() []byte
- func PresetNames() []string
- func ReplaceBlock(src []byte, name string, block []byte) ([]byte, error)
- func SetManifestKey(src []byte, key, value string) []byte
- func SetRowLevelSecurity(tree map[string][]byte)
- func SupportsTenancy(name string) bool
- func ValidateModuleName(name string) error
- func ValidateResourceName(name string) error
- func WorkerHash(content []byte) string
- type Data
- type EnumValue
- type Field
- func (f Field) A() string
- func (f Field) Constraint() string
- func (f Field) EnumMessage() string
- func (f Field) EnumTag() string
- func (f Field) FirstValue() EnumValue
- func (f Field) GoType() string
- func (f Field) HumanTitle() string
- func (f Field) IsEnum() bool
- func (f Field) LastValue() EnumValue
- func (f Field) MaxLength() int
- func (f Field) MinLength() int
- func (f Field) Sample(qualifier string) string
- func (f Field) ValueIdents() string
- type File
- type JobData
- type JobFile
- func RenderArchitectureTest(module string) (JobFile, error)
- func RenderJob(d JobData) ([]JobFile, error)
- func RenderMiddleware(d MiddlewareData) ([]JobFile, error)
- func RenderMiddlewareDoc() (JobFile, error)
- func RenderModule(d ModuleData) ([]JobFile, error)
- func RenderResource(d ResourceData) ([]JobFile, error)
- type JobMarker
- type MailRecipe
- type MiddlewareData
- func (d MiddlewareData) Check() string
- func (d MiddlewareData) Code() string
- func (d MiddlewareData) Declared() []string
- func (d MiddlewareData) Dir() string
- func (d MiddlewareData) Err() string
- func (d MiddlewareData) ErrorMapping() string
- func (d MiddlewareData) File() string
- func (d MiddlewareData) Package() string
- func (d MiddlewareData) Test() string
- func (d MiddlewareData) Wire() string
- type ModuleData
- func (d ModuleData) BodyChoice() string
- func (d ModuleData) BodyDuplicate() string
- func (d ModuleData) BodyFields(title string) string
- func (d ModuleData) Dir() string
- func (d ModuleData) Guard() string
- func (d ModuleData) ImportPath() string
- func (d ModuleData) MigrationPath() string
- func (d ModuleData) PermRead() string
- func (d ModuleData) PermWrite() string
- func (d ModuleData) PluralVar() string
- func (d ModuleData) RoutePath() string
- func (d ModuleData) SampleFields(title string) string
- func (d ModuleData) Scope() string
- func (d ModuleData) ScopeColumn() string
- func (d ModuleData) ScopeField() string
- func (d ModuleData) ScopeVar() string
- type Preset
- type Release
- type ResourceData
- func (d ResourceData) A() string
- func (d ResourceData) ChangedNames() string
- func (d ResourceData) Columns() string
- func (d ResourceData) EnumPlaceholder(i int) int
- func (d ResourceData) Enums() []Field
- func (d ResourceData) FieldNames() string
- func (d ResourceData) FirstEnum() Field
- func (d ResourceData) FirstUnique() Field
- func (d ResourceData) HasEnums() bool
- func (d ResourceData) HasUniques() bool
- func (d ResourceData) InsertPlaceholders() string
- func (d ResourceData) InvalidFields() string
- func (d ResourceData) JSONChoice() string
- func (d ResourceData) JSONDuplicate() string
- func (d ResourceData) JSONFields(title string) string
- func (d ResourceData) ModulesLine() string
- func (d ResourceData) Pad(name string) string
- func (d ResourceData) PermissionsAnchor() string
- func (d ResourceData) PermissionsLine() string
- func (d ResourceData) PluralTitle() string
- func (d ResourceData) SampleFields(title string) string
- func (d ResourceData) SortFields() []string
- func (d ResourceData) SortList() string
- func (d ResourceData) SortListCode() string
- func (d ResourceData) Strings() []Field
- func (d ResourceData) TakenErrors() string
- func (d ResourceData) TextFields() []Field
- func (d ResourceData) Title() Field
- func (d ResourceData) Uniques() []Field
- func (d ResourceData) UpdateSet() string
- func (d ResourceData) UpdatedAtPlaceholder() int
- func (d ResourceData) VersionPlaceholder() int
- type ResourceOptions
Constants ¶
const ( KindCustom = "custom" KindHTTP = "http" KindSQL = "sql" KindEmail = "email" KindDispatch = "dispatch" )
Kinds of generated jobs.
const ( MailResend = "resend" MailSMTP = "smtp" )
Email providers offered by orb add mail (ADR-0037).
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.
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.
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.
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.
const ( TenancySingle = "single" TenancyMulti = "multi" )
Tenancy values of orb new --tenancy (ADR-0023).
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).
const ( StringMaxLength = 100 TextMaxLength = 2000 MaxFields = 20 )
Limits of generated resources.
const ( ScopeUser = "user" ScopeOrg = "org" )
Resource scopes of orb gen resource --scope.
const ArchitectureTestPath = ModulesDir + "/architecture_test.go"
ArchitectureTestPath is the test that checks every module's layers.
const JobAnchor = "//orb:anchor jobs"
JobAnchor is the anchor in internal/app/jobs.go that orb gen job adds a line after.
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.
const MiddlewareDir = "internal/middleware"
MiddlewareDir is the package orb gen middleware --global writes into.
const MiddlewareDocPath = MiddlewareDir + "/doc.go"
MiddlewareDocPath is the package comment of internal/middleware.
const ModulesAnchor = "//orb:anchor modules"
ModulesAnchor is the anchor in internal/app/modules.go that orb gen resource adds a line after.
const ModulesDir = "internal/modules"
ModulesDir is where an app on gorbital.Main keeps its modules.
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.
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).
const RowLevelSecurityKey = "rls"
RowLevelSecurityKey is the gorbital.yaml key orb add rls sets to true.
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).
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 ¶
var ErrAnchorMissing = errors.New("anchor not found")
ErrAnchorMissing reports a file without the anchor to insert after.
var ErrBlockMissing = errors.New("block not found")
ErrBlockMissing reports a file without the named orb:begin/orb:end block.
var ErrLinePresent = errors.New("line already present")
ErrLinePresent reports a line that is already in the file.
var JobKinds = []string{KindCustom, KindHTTP, KindSQL, KindEmail, KindDispatch}
JobKinds lists the kinds.
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 InsertAfterAnchor ¶
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 ¶
ReplaceBlock returns src with the block named name, marker lines included, replaced by block.
func SetManifestKey ¶
SetManifestKey sets a top-level key in gorbital.yaml, keeping every other line.
func SetRowLevelSecurity ¶
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 ¶
SupportsTenancy reports whether the preset name has a multi-tenant variant, so orb new asks about tenancy.
func ValidateModuleName ¶ added in v0.2.0
ValidateModuleName reports whether name can name a module, before its fields are known.
func ValidateResourceName ¶
ValidateResourceName reports whether name can name a resource, before its fields are known.
func WorkerHash ¶
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.
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 ¶
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
ParseModuleFields parses orb gen module's field specs: those of ParseFields, and optional strings such as nickname:string?.
func (Field) Constraint ¶
Constraint is the column definition after the column's type.
func (Field) EnumMessage ¶
EnumMessage is the validation message for an unknown value.
func (Field) FirstValue ¶
FirstValue is an enum field's default value.
func (Field) HumanTitle ¶
HumanTitle is f.Human starting with a capital letter.
func (Field) Sample ¶
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 ¶
ValueIdents lists the enum's constants, such as StatusActive, StatusArchived.
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) TimeoutExpr ¶
TimeoutExpr is the timeout as a Go expression, such as 5 * time.Minute.
func (JobData) WorkerArgs ¶
WorkerArgs are the arguments the definition passes to NewWorker.
type JobFile ¶
JobFile is one rendered job file.
func RenderArchitectureTest ¶ added in v0.2.0
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 ¶
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
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 ¶
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 ¶
LookupPreset returns the preset orb new --preset name --tenancy tenancy selects.
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 ReleaseFS ¶
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 ¶
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) 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) 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.
Source Files
¶
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). |