Documentation
¶
Overview ¶
Package recipes renders the project templates used by orb new.
Each tree of templates is generated from a hand-written golden app by `go generate`: minimal/ from examples/minimal; v0.3/, the layout orb new writes (apps on gorbital.Main, ADR-0083), from 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 — except the hand-written part of v0.3/, which lives in gen/tree/ and is copied over the generated one.
One tree serves every shape: manifest.yaml says which features each path belongs to, and Profile.Render writes the ones the app asked for (ADR-0090).
The golden Full apps show what orb new writes, sign-in and organisations included (v0.2.1); the templates hold neither, and orb new copies them in from the library version the app requires (Profile.Copies). go generate takes them out of the golden apps and puts them back from the checkout (./gen).
Index ¶
- Constants
- Variables
- func APIArtefacts() []string
- func Block(src []byte, name string) ([]byte, error)
- func CheckManifest(fsys fs.FS, base string) error
- func DemoFields() []string
- func EnvKey(line string) (string, bool)
- func InsertAfterAnchor(src []byte, anchor, line string) ([]byte, error)
- func ManifestPaths(fsys fs.FS, base string) (map[string][]string, error)
- func OrgsConversion() []byte
- func ParseScope(s string) (string, error)
- func PresetNames() []string
- func ReadModuleScopes(manifest []byte) map[string]string
- func RenderTree(fsys fs.FS, base string, p Profile, d Data) (map[string][]byte, error)
- func ReplaceBlock(src []byte, name string, block []byte) ([]byte, error)
- func SetManifestKey(src []byte, key, value string) []byte
- func SetModuleScope(src []byte, module, scope string) []byte
- func SetRowLevelSecurity(tree map[string][]byte)
- func SupportsTenancy(name string) bool
- func Templates() fs.FS
- func ValidateModuleName(name string) error
- func ValidateResourceName(name string) error
- func Wants(on map[string]bool, needed []string) bool
- func WorkerHash(content []byte) string
- type Data
- type EjectedModule
- 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 Method
- 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) ScopeColumn() string
- func (d ModuleData) ScopeField() string
- func (d ModuleData) ScopeVar() string
- type Preset
- type Profile
- func (p Profile) AllMethods() bool
- func (p Profile) AppFeatures() string
- func (p Profile) AuthMethods() []Method
- func (p Profile) Copies() []EjectedModule
- func (p Profile) CustomScope() bool
- func (p Profile) DeclaresScope() bool
- func (p Profile) DemoMigration() string
- func (p Profile) Features() map[string]bool
- func (p Profile) FullAuth() bool
- func (p Profile) Layout() string
- func (p Profile) Legal() bool
- func (p Profile) MethodList() string
- func (p Profile) MethodNames() []string
- func (p Profile) Migrations() int
- func (p Profile) Named() bool
- func (p Profile) Operations() int
- func (p Profile) Render(root *os.Root, d Data) ([]File, error)
- func (p Profile) ResourceScope() string
- func (p Profile) RoleList() string
- func (p Profile) RolesFile() string
- func (p Profile) SQLRoles() string
- func (p Profile) ScopeMembersTable() string
- func (p Profile) ScopeMigration() string
- func (p Profile) ScopeTable() string
- func (p Profile) ScopeTitle() string
- func (p Profile) Scoped() bool
- func (p Profile) SignsIn() bool
- func (p Profile) String() string
- func (p Profile) Tenancy() string
- func (p Profile) Vocabulary() Vocabulary
- type Release
- type ResourceData
- func (d ResourceData) A() string
- func (d ResourceData) AfterPlaceholder() int
- func (d ResourceData) ChangedNames() string
- func (d ResourceData) Columns() string
- func (d ResourceData) Custom() bool
- func (d ResourceData) EnumPlaceholder(i int) int
- func (d ResourceData) Enums() []Field
- func (d ResourceData) FieldNames() string
- func (d ResourceData) Filtered() bool
- func (d ResourceData) FirstEnum() Field
- func (d ResourceData) FirstUnique() Field
- func (d ResourceData) HasCreatedBy() bool
- func (d ResourceData) HasEnums() bool
- func (d ResourceData) HasUniques() bool
- func (d ResourceData) IndexColumns(cols string) string
- 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) LimitPlaceholder() int
- func (d ResourceData) ListFirstArg() int
- func (d ResourceData) ModulesLine() string
- func (d ResourceData) Owner() string
- func (d ResourceData) OwnerA() string
- func (d ResourceData) OwnerColumnList() string
- func (d ResourceData) OwnerColumns() []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) PolicyFirstArg() int
- func (d ResourceData) PositionIDPlaceholder() int
- func (d ResourceData) PositionPlaceholder() int
- func (d ResourceData) Public() bool
- func (d ResourceData) SampleFields(title string) string
- func (d ResourceData) ScopeA() string
- func (d ResourceData) ScopeColumnOrOwner() string
- func (d ResourceData) ScopeGoRoles() string
- func (d ResourceData) ScopeGuard() string
- func (d ResourceData) ScopeIDExample() string
- func (d ResourceData) ScopeName() string
- func (d ResourceData) ScopeNotFoundCode() string
- func (d ResourceData) ScopeParamField() string
- func (d ResourceData) ScopePathParam() string
- func (d ResourceData) ScopeRoleList() string
- func (d ResourceData) ScopeRolesField() string
- func (d ResourceData) ScopeSegment() string
- func (d ResourceData) ScopeTitle() string
- func (d ResourceData) SortFields() []string
- func (d ResourceData) SortIndex(suffix string) 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) UniqueIndex(field string) string
- func (d ResourceData) Uniques() []Field
- func (d ResourceData) UpdateFirstField() int
- func (d ResourceData) UpdateSet() string
- func (d ResourceData) UpdatedAtPlaceholder() int
- func (d ResourceData) VersionPlaceholder() int
- type ResourceOptions
- type ScopeRole
- type Vocabulary
- func (v Vocabulary) A() string
- func (v Vocabulary) AColumn() string
- func (v Vocabulary) CodeRoles() string
- func (v Vocabulary) GoRoles() string
- func (v Vocabulary) Guard() string
- func (v Vocabulary) IsOrganisations() bool
- func (v Vocabulary) RoleList() string
- func (v Vocabulary) RolesField() string
- func (v Vocabulary) ScopeRoles() []ScopeRole
- func (v Vocabulary) Title() string
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 ( // FeatureAuthLocal: the app has gorbital's sign-in (--auth basic or // --auth full). FeatureAuthLocal = "auth.local" // FeatureAuthFull: the app serves every sign-in method (--auth full). FeatureAuthFull = "auth.full" // FeatureScopeNamed: the app mounts the supplied organisations under // its own vocabulary (--scope <name>). FeatureScopeNamed = "scope.named" // FeatureScopeCustom: the app writes its own membership rules // (--scope custom). FeatureScopeCustom = "scope.custom" // FeatureScopeAny: the app has a tenancy of either kind. FeatureScopeAny = "scope.any" )
The features a manifest entry can require. A path is written when every feature it lists is on, and skipped otherwise.
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 ( // AuthNone: no sign-in at all. The app has no accounts, no sessions and // no auth tables; its routes are public or guarded by middleware it // writes itself. AuthNone = "none" // AuthBasic: an email address, a password and the operators' account // APIs — 29 operations. AuthBasic = "basic" // AuthFull: every sign-in method, which is v0.2's sign-in byte for // byte — 74 operations. AuthFull = "full" )
The sign-in profiles of orb new --auth (ADR-0089, ADR-0090): how much of gorbital's sign-in the app serves.
const ( // ScopeNone: the app has no tenants. Records belong to nobody but the // app. ScopeNone = "none" // ScopeSingle: one implicit scope. Records belong to users. ScopeSingle = "single" )
The app scopes of orb new --scope (ADR-0088, ADR-0090): what a tenant is. A fourth value, a name such as organisation or merchant, mounts the supplied organisations under that vocabulary.
const ( DemoModule = "Project" // DemoMigrationVersion is its migration's version: the first one after // the built-in modules', which run in the same history. A test in the // CLI keeps it in step with them. DemoMigrationVersion = "20260918000071" )
The demonstration module orb new generates into every app it creates (ADR-0090 §5): the module orb gen module writes, at the profile's scope, instead of 25 template files that differ only by their access rule. Its migration version is fixed, so every app of a release has the same one.
const ( OpenAPIPath = "api/openapi.json" OpenAPIBaselinePath = "api/openapi.baseline.json" PostmanPath = "api/postman_collection.json" LLMsPath = "api/llms.txt" )
The API artefacts an app produces rather than orb new writing them (ADR-0090 §5): the app's own openapi command writes the first three, the fourth is the /ops contract it is held to, and the fifth is recorded by its own TestPublicSurface.
const ( MinimalName = "base-minimal" FullName = "base-full" FullMultiName = "base-full-multi" // LibraryVersion is the gorbital library version generated apps require. LibraryVersion = "v0.3.4" )
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: the records belong to the signed-in user, who is the only // one who can read or change them. ScopeUser = "user" // ScopeTenant: the records belong to a tenant — an organisation, a // merchant, a clinic, whatever the app calls it (ADR-0088) — and its // members reach them through their role. ScopeTenant = "tenant" // ScopePublic: the records are world-readable. Reads need no sign-in; // writes are permission-guarded. ScopePublic = "public" // ScopeCustom: the module decides. The generator writes policy.go with // unimplemented stubs and adds no filter of its own. ScopeCustom = "custom" // ScopeOrg is the v0.2 name of [ScopeTenant]. // // Deprecated: use ScopeTenant. orb accepts org silently for all of // v0.x, so every script and documented command keeps working. ScopeOrg = "org" )
The resource access scopes of orb gen resource --scope and orb gen module --scope (ADR-0091): who may read and write the records a module serves. The generator states the rule instead of assuming one.
const ArchitectureTestPath = ModulesDir + "/architecture_test.go"
ArchitectureTestPath is the test that checks every module's layers.
const (
AuthKey = "auth"
)
The gorbital.yaml keys that record the profile (ADR-0090 §8).
const AuthUsage = "none|basic|full"
AuthUsage is how --auth's values are written in help text and errors.
const CustomScopeName = "tenant"
CustomScopeName is what an app with its own membership rules calls its tenant until it renames it: the neutral word, so the generated code and the stub's tables agree from the first commit.
const DefaultScopeName = "organisation"
DefaultScopeName is the scope a named scope has unless --scope names another, and what --tenancy multi means: the supplied organisations.
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 ManifestName = "manifest.yaml"
ManifestName is the file in a template tree that says which features each path needs.
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 ModuleScopesKey = "modules"
ModuleScopesKey is the gorbital.yaml block recording the scope each generated module was created with, so orb routes and orb doctor can read the access rule back (ADR-0091 §2).
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 ScopeKey = "scope"
ScopeKey is the gorbital.yaml key holding the app's tenancy vocabulary.
const ScopeNameUsage = "none|single|custom|<name>"
ScopeNameUsage is how --scope's values are written in help text and errors.
const ScopeUsage = "user|tenant|public|custom"
ScopeUsage is how --scope's values are written in help text and errors.
const TreeV03 = "v0.3"
TreeV03 is the one template tree orb new writes every profile from (ADR-0090 §3). It replaced v0.2/full and v0.2/full-multi: the tree is the union of every shape, and manifest.yaml is the only mapping from a feature to the files it owns.
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 Auths = []string{AuthNone, AuthBasic, AuthFull}
Auths are the values --auth accepts, in the order the help lists them.
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.
var Scopes = []string{ScopeUser, ScopeTenant, ScopePublic, ScopeCustom}
Scopes are the scopes --scope accepts, in the order the help lists them. ScopeOrg is accepted too and means ScopeTenant.
Functions ¶
func APIArtefacts ¶ added in v0.3.0
func APIArtefacts() []string
APIArtefacts are the files orb new produces by running the app, in the order it lists them.
func CheckManifest ¶ added in v0.3.0
CheckManifest reports a template in the tree at base with no manifest entry, and a manifest entry naming a template the tree lacks. Both fail go generate and CI, so a template added without an entry can't silently stop being written for some profile.
func DemoFields ¶ added in v0.3.0
func DemoFields() []string
DemoFields returns the demonstration module's field specifications.
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 ManifestPaths ¶ added in v0.3.0
ManifestPaths returns the tree's manifest entries, for the tests and orb doctor: each template path with the features it needs.
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 ParseScope ¶ added in v0.3.0
ParseScope returns the canonical name of the scope s names: ScopeTenant for both tenant and its deprecated alias org, and s itself for the others. An empty s stays empty, meaning the app's default. Every place that reads --scope calls this, so the four values can't drift apart.
func PresetNames ¶
func PresetNames() []string
PresetNames lists the presets orb new accepts, in the order it offers them.
func ReadModuleScopes ¶ added in v0.3.0
ReadModuleScopes returns the scope each module in the app's gorbital.yaml was generated with, keyed by the module's package. It reads the manifest defensively: a missing block, an unknown scope or a malformed line is no scope rather than an error.
func RenderTree ¶ added in v0.3.0
RenderTree renders the templates under base in fsys that the profile asks for, keyed by the slash-separated path of each file they produce. It is Render without the writing, for the generator and the tests.
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 SetModuleScope ¶ added in v0.3.0
SetModuleScope returns the manifest with module recorded as generated with scope, adding the block when the app has none and 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 Templates ¶ added in v0.3.0
Templates is the embedded template trees, for the tests and the generator.
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 Wants ¶ added in v0.3.0
Wants reports whether an app with these features gets a path needing them, for orb doctor.
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
// Profile is the app's shape, which the v0.3.0 tree's conditional
// templates read (ADR-0090 §6). It is the zero Profile for the v0.1
// trees, which have no conditionals of their own.
Profile Profile
}
Data fills the templates.
type EjectedModule ¶ added in v0.2.1
type EjectedModule struct {
// Name is the module's directory under internal/modules, and what orb
// eject takes, such as auth.
Name string
// Package is the library package it is copied from, such as
// gorbital.dev/gorbital/authhttp.
Package string
}
An EjectedModule is a built-in module of gorbital.dev/gorbital that orb new copies into an app as the app's own code, as orb eject does.
func (EjectedModule) Dir ¶ added in v0.2.1
func (m EjectedModule) Dir() string
Dir returns the module's directory in the app, slash-separated.
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 Method ¶ added in v0.3.0
type Method string
A Method is one way of signing in, named as gorbital.dev/gorbital/authhttp names it (authhttp.Method). The profile records the set; cmd/api/main.go passes it to authhttp.Methods.
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), ScopeTenant, ScopePublic or ScopeCustom (ADR-0091); o.Vocabulary is what the app calls its tenant; o.RLS adds the row-level security policy to a tenant 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: the tenancy's for a tenant module, guard.Permission otherwise. A public module's reads use guard.Public() (delivery/routes.go), never this.
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 a tenant module under the app's own tenancy vocabulary (ADR-0088).
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) 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. A public or custom module has neither.
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.
func (Preset) Ejects ¶ added in v0.2.1
func (p Preset) Ejects() []EjectedModule
Ejects returns the built-in modules orb copies into an app of the preset, in the order it copies them. orb new works from a Profile instead (Profile.Copies); this stays for orb upgrade --layout v0.2 and orb add orgs, which rebuild an app from what its lock records: since v0.2.1 a Full app holds its sign-in, and a multi-tenant one its organisations, in internal/modules (orb new --no-eject keeps them in the library). Organisations come first: the library's orgshttp takes the library's sign-in, so sign-in can only be copied once organisations are. Templates hold neither: the golden apps show them copied, and go generate takes them out again (generate.Uneject).
type Profile ¶ added in v0.3.0
type Profile struct {
// Auth is the value of --auth: AuthNone, AuthBasic or AuthFull.
Auth string
// Scope is the value of --scope: ScopeNone, ScopeSingle, ScopeCustom,
// or the name of a scope.
Scope string
// ScopeName is what the app calls its tenant when Scope is a name:
// "organisation", "merchant", …. It is empty for the other scopes.
ScopeName string
// Methods are the sign-in methods the app serves; empty means the
// Auth profile's own set (AuthMethods).
Methods []Method
}
A Profile is the application orb new creates: how much sign-in, and what a tenant is (ADR-0090).
func LegalProfiles ¶ added in v0.3.0
func LegalProfiles() []Profile
LegalProfiles returns the nine combinations orb new can create, in the order the help and the CI matrix list them: --auth none only with --scope none, and each of basic and full with every scope. The named scope is represented by DefaultScopeName; any other name behaves the same way.
func ParseProfile ¶ added in v0.3.0
ParseProfile returns the profile orb new --auth auth --scope scope creates, or an error saying why that combination isn't one. An empty auth or scope takes the default: full sign-in, and one implicit scope.
func ProfileFromManifest ¶ added in v0.3.0
ProfileFromManifest returns the profile an app's gorbital.yaml records, reading it defensively as ReadVocabulary does: an unknown or missing value is no value rather than an error, because a later release of orb writes the file than the one reading it. The zero Profile means the manifest records none, which is every app up to v0.2.1.
func ProfileFromTenancy ¶ added in v0.3.0
ProfileFromTenancy returns the profile orb new --preset full --tenancy tenancy creates: the deprecated alias of --auth full with --scope single or --scope organisation (ADR-0090 §1).
func (Profile) AllMethods ¶ added in v0.3.0
AllMethods reports a profile serving every sign-in method, which needs no authhttp.Methods call at all.
func (Profile) AppFeatures ¶ added in v0.3.0
AppFeatures is appFeatures as gorbital.yaml writes them.
func (Profile) AuthMethods ¶ added in v0.3.0
AuthMethods are the sign-in methods the app serves: the profile's own Methods, or the Auth profile's set.
func (Profile) Copies ¶ added in v0.3.0
func (p Profile) Copies() []EjectedModule
Copies returns the built-in modules orb new copies into an app of the profile, as the app's own code, in the order it copies them (ADR-0090 §1): none for --auth none with no scope, sign-in for basic and full, and organisations as well for a named scope. Organisations come first: the library's orgshttp takes the library's sign-in, so sign-in can only be copied once organisations are. A custom scope copies neither — its membership rules are the app's from the first commit.
func (Profile) CustomScope ¶ added in v0.3.0
CustomScope reports a profile whose membership rules are the app's own: the tables and a gorbital.Scope stub, and no orgshttp.
func (Profile) DeclaresScope ¶ added in v0.3.0
DeclaresScope reports a profile whose gorbital.yaml records a scope block: one whose tenant has words of its own. A --scope organisation app records none, so orb gen module writes it exactly what v0.2.1 wrote.
func (Profile) DemoMigration ¶ added in v0.3.0
DemoMigration is the demonstration module's migration file name.
func (Profile) FullAuth ¶ added in v0.3.0
FullAuth reports a profile serving every sign-in method gorbital has.
func (Profile) Layout ¶ added in v0.3.0
Layout returns the layout orb new writes for a profile: every profile is an app on gorbital.Main (ADR-0083). Minimal keeps the v0.1 layout and is a Preset, not a Profile.
func (Profile) MethodList ¶ added in v0.3.0
MethodList is the profile's sign-in methods as a gorbital.yaml flow sequence: [password, operators].
func (Profile) MethodNames ¶ added in v0.3.0
MethodNames are the profile's sign-in methods as their names, for gorbital.yaml and the templates.
func (Profile) Migrations ¶ added in v0.3.0
Migrations counts the sign-in migrations the app applies: all of them whichever methods it serves, so adding a method later is one line (ADR-0089).
func (Profile) Named ¶ added in v0.3.0
Named reports a profile whose scope is a name, so the app mounts the supplied organisations under that vocabulary.
func (Profile) Operations ¶ added in v0.3.0
Operations counts the HTTP operations the profile's sign-in registers, for the prompt and the help.
func (Profile) Render ¶ added in v0.3.0
Render writes the profile's app into root and returns the files written, sorted by path. The demonstration module and the API artefacts are not among them: orb new generates the one and produces the other (ADR-0090 §5, §6).
func (Profile) ResourceScope ¶ added in v0.3.0
ResourceScope is the access rule orb gen resource gives the demonstration module in an app of this profile: a tenant's where the app has a tenancy, a user's where it has sign-in and no tenancy, and world-readable where it has neither.
func (Profile) RoleList ¶ added in v0.3.0
RoleList is the scope's roles, comma-separated, for gorbital.yaml.
func (Profile) RolesFile ¶ added in v0.3.0
RolesFile is where an app of this profile changes its scope's roles.
func (Profile) SQLRoles ¶ added in v0.3.0
SQLRoles is the scope's roles as SQL string literals, for a CHECK constraint: 'owner', 'admin', 'member'.
func (Profile) ScopeMembersTable ¶ added in v0.3.0
ScopeMembersTable is the table holding who belongs to a tenant and with which role.
func (Profile) ScopeMigration ¶ added in v0.3.0
ScopeMigration is the migration that creates a custom scope's tables.
func (Profile) ScopeTable ¶ added in v0.3.0
ScopeTable is the table the app's tenants live in: orgs for the supplied organisations, whatever their words, and the scope's plural for an app with its own membership rules.
func (Profile) ScopeTitle ¶ added in v0.3.0
ScopeTitle is the tenant's plural starting with a capital letter, for a heading.
func (Profile) Scoped ¶ added in v0.3.0
Scoped reports a profile with any tenancy at all, named or custom: one whose records belong to a tenant rather than to a user or to nobody.
func (Profile) SignsIn ¶ added in v0.3.0
SignsIn reports a profile with gorbital's sign-in, basic or full.
func (Profile) String ¶ added in v0.3.0
String is the profile as its flags: --auth full --scope organisation.
func (Profile) Tenancy ¶ added in v0.3.0
Tenancy is the profile as the tenancy of v0.1 and v0.2 records it: multi for a named scope, single for everything else. gorbital.yaml, gorbital.lock and orb upgrade keep reading it, so a v0.3.0 app stays readable by v0.2.1's orb.
func (Profile) Vocabulary ¶ added in v0.3.0
func (p Profile) Vocabulary() Vocabulary
Vocabulary is what the app calls its tenant: the scope's name with the words derived from it, "tenant" for a custom scope, and the organisations vocabulary for a profile that names none. An app that never named its tenant gets an undeclared vocabulary, so orb gen module writes it byte for byte what v0.2.1 wrote (ADR-0091 §3).
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/, with v0.2/full/ and v0.2/full-multi/ in v0.2 releases and v0.3/ from v0.3.0 on. 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
// Scope is the access rule the generator states: ScopeUser,
// ScopeTenant, ScopePublic or ScopeCustom (ADR-0091).
Scope string
// Vocabulary is what the app calls its tenant, for a ScopeTenant
// resource (ADR-0088).
Vocabulary Vocabulary
// Org reports records that belong to a tenant (--scope tenant, or its
// old name org) instead of a user.
Org bool
// RLS reports a tenant resource whose migration forces row-level
// security with the tenant 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) AfterPlaceholder ¶ added in v0.3.0
func (d ResourceData) AfterPlaceholder() int
AfterPlaceholder is the list query's placeholder for "the page starts after a position".
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) Custom ¶ added in v0.3.0
func (d ResourceData) Custom() bool
Custom reports a resource whose access rule is the module's own, in policy.go.
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) Filtered ¶ added in v0.3.0
func (d ResourceData) Filtered() bool
Filtered reports a resource the repository filters by an ownership column: the owner for ScopeUser, the tenant for ScopeTenant. ScopePublic and ScopeCustom have none, so their queries carry no filter the developer didn't write.
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) HasCreatedBy ¶ added in v0.3.0
func (d ResourceData) HasCreatedBy() bool
HasCreatedBy reports a resource that records who created each record: a tenant's, where access comes from membership rather than authorship, and a custom one, whose policy usually needs somebody to compare the actor with. It is never an access rule by itself.
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) IndexColumns ¶ added in v0.3.0
func (d ResourceData) IndexColumns(cols string) string
IndexColumns are the columns an index on the list query leads with: the ownership column, when there is one, and then cols.
func (ResourceData) InsertPlaceholders ¶
func (d ResourceData) InsertPlaceholders() string
InsertPlaceholders are the insert's placeholders: id, the owner columns (the tenant and the creator, the owner, or none), 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) LimitPlaceholder ¶ added in v0.3.0
func (d ResourceData) LimitPlaceholder() int
LimitPlaceholder is the list query's placeholder for the page size.
func (ResourceData) ListFirstArg ¶ added in v0.3.0
func (d ResourceData) ListFirstArg() int
ListFirstArg is the first placeholder after the ownership column.
func (ResourceData) ModulesLine ¶
func (d ResourceData) ModulesLine() string
ModulesLine is the line orb gen resource adds after ModulesAnchor.
func (ResourceData) Owner ¶ added in v0.3.0
func (d ResourceData) Owner() string
Owner names who a filtered resource's records belong to, without an article: "organisation", "merchant" or "owner". A public or custom resource has no owner, and the templates that use this don't ask.
func (ResourceData) OwnerA ¶ added in v0.3.0
func (d ResourceData) OwnerA() string
OwnerA is the indefinite article for Owner.
func (ResourceData) OwnerColumnList ¶ added in v0.3.0
func (d ResourceData) OwnerColumnList() string
OwnerColumnList is OwnerColumns as SQL, ending with ", " when there are any: "org_id, created_by, ".
func (ResourceData) OwnerColumns ¶ added in v0.3.0
func (d ResourceData) OwnerColumns() []string
OwnerColumns are the columns identifying who a record belongs to, in the order the table declares them: none for ScopePublic.
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) PolicyFirstArg ¶ added in v0.3.0
func (d ResourceData) PolicyFirstArg() int
PolicyFirstArg is the first placeholder a custom resource's policy conditions are numbered from: everything the store itself passes comes before them.
func (ResourceData) PositionIDPlaceholder ¶ added in v0.3.0
func (d ResourceData) PositionIDPlaceholder() int
PositionIDPlaceholder is the list query's placeholder for the position's ID.
func (ResourceData) PositionPlaceholder ¶ added in v0.3.0
func (d ResourceData) PositionPlaceholder() int
PositionPlaceholder is the list query's placeholder for the position's sort value.
func (ResourceData) Public ¶ added in v0.3.0
func (d ResourceData) Public() bool
Public reports a world-readable resource: reads need no sign-in.
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) ScopeA ¶ added in v0.3.0
func (d ResourceData) ScopeA() string
ScopeA is the indefinite article for the tenant's name.
func (ResourceData) ScopeColumnOrOwner ¶ added in v0.3.0
func (d ResourceData) ScopeColumnOrOwner() string
ScopeColumnOrOwner is the ownership column: the tenant's, or owner_id.
func (ResourceData) ScopeGoRoles ¶ added in v0.3.0
func (d ResourceData) ScopeGoRoles() string
ScopeGoRoles is the tenant's roles as Go string literals.
func (ResourceData) ScopeGuard ¶ added in v0.3.0
func (d ResourceData) ScopeGuard() string
ScopeGuard is the guard a tenant module's routes use.
func (ResourceData) ScopeIDExample ¶ added in v0.3.0
func (d ResourceData) ScopeIDExample() string
ScopeIDExample is an example tenant ID for the OpenAPI document.
func (ResourceData) ScopeName ¶ added in v0.3.0
func (d ResourceData) ScopeName() string
ScopeName is what the app calls its tenant, such as organisation.
func (ResourceData) ScopeNotFoundCode ¶ added in v0.3.0
func (d ResourceData) ScopeNotFoundCode() string
ScopeNotFoundCode refuses a request for a tenant the caller isn't a member of, such as org_not_found.
func (ResourceData) ScopeParamField ¶ added in v0.3.0
func (d ResourceData) ScopeParamField() string
ScopeParamField is ScopePathParam as a Go field, such as OrgID.
func (ResourceData) ScopePathParam ¶ added in v0.3.0
func (d ResourceData) ScopePathParam() string
ScopePathParam is the path parameter carrying the tenant ID, such as orgId.
func (ResourceData) ScopeRoleList ¶ added in v0.3.0
func (d ResourceData) ScopeRoleList() string
ScopeRoleList is the tenant's roles in prose: owner, admin and member.
func (ResourceData) ScopeRolesField ¶ added in v0.3.0
func (d ResourceData) ScopeRolesField() string
ScopeRolesField is the gorbital.Permission field holding a tenant module's roles: ScopeRoles, or its v0.2 name OrgRoles.
func (ResourceData) ScopeSegment ¶ added in v0.3.0
func (d ResourceData) ScopeSegment() string
ScopeSegment is the path segment a tenant's routes live under: the "orgs" of /v1/orgs/{orgId}.
func (ResourceData) ScopeTitle ¶ added in v0.3.0
func (d ResourceData) ScopeTitle() string
ScopeTitle is the tenant's name starting with a capital letter.
func (ResourceData) SortFields ¶
func (d ResourceData) SortFields() []string
SortFields are the fields a list can be sorted by.
func (ResourceData) SortIndex ¶ added in v0.3.0
func (d ResourceData) SortIndex(suffix string) string
SortIndex names an index supporting one sort of the list query: projects_org_created, or projects_created.
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) UniqueIndex ¶ added in v0.3.0
func (d ResourceData) UniqueIndex(field string) string
UniqueIndex names the unique index enforcing a field's uniqueness: projects_org_name, or projects_name when the table has no ownership column.
func (ResourceData) Uniques ¶
func (d ResourceData) Uniques() []Field
Uniques are the unique fields.
func (ResourceData) UpdateFirstField ¶ added in v0.3.0
func (d ResourceData) UpdateFirstField() int
UpdateFirstField is the update's first field placeholder: $1 is the ID, $2 the ownership column a filtered resource matches on, and the fields follow.
func (ResourceData) UpdateSet ¶
func (d ResourceData) UpdateSet() string
UpdateSet assigns each field from UpdateFirstField 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),
// ScopeTenant, ScopePublic or ScopeCustom (ADR-0091). ScopeOrg is
// accepted as the old name of ScopeTenant.
Scope string
// Vocabulary is what the app calls its tenant, for a ScopeTenant
// resource (ADR-0088). The zero value is the organisations one.
Vocabulary Vocabulary
// RLS adds the row-level security policy to a tenant resource's
// migration, for apps that ran orb add rls (ADR-0061).
RLS bool
}
ResourceOptions override the names derived from a resource's name.
type ScopeRole ¶ added in v0.3.0
A ScopeRole is one of the scope's roles with its Go identifier, for the templates that declare them.
type Vocabulary ¶ added in v0.3.0
type Vocabulary struct {
// Name is the concept in lowercase singular, such as "organisation" or
// "merchant".
Name string
// Plural is Name in plural, for prose such as "the merchant's orders".
Plural string
// Segment is the path segment the scope's routes live under, the
// "orgs" of /v1/orgs/{orgId}.
Segment string
// PathParam is the path parameter carrying the scope ID, such as
// "orgId".
PathParam string
// ParamField is PathParam as a Go field name, such as "OrgID".
ParamField string
// Column is the table column holding the scope ID, such as "org_id".
Column string
// Field is Column as a Go field name, such as "OrgID".
Field string
// Var is Column as a Go parameter name, such as "orgID".
Var string
// NotFoundCode refuses a request for a scope the actor is not a member
// of, such as "org_not_found".
NotFoundCode string
// IDPrefix starts a scope ID in examples, such as "org".
IDPrefix string
// Roles are the scope's roles, most privileged first.
Roles []string
// Declared reports a vocabulary the app wrote in gorbital.yaml. Without
// one the generator writes the v0.2 organisation code — guard.OrgMember
// and Permission.OrgRoles — so an app that never named its tenant gets
// byte for byte what v0.2.1 generated (ADR-0091 §3).
Declared bool
}
A Vocabulary is what an app calls its tenant (ADR-0088): the words the code, routes, columns and refusals of a ScopeTenant module use. An app records it in gorbital.yaml; without one the generator falls back to OrganisationVocabulary, the vocabulary of every v0.1 and v0.2 app.
func OrganisationVocabulary ¶ added in v0.3.0
func OrganisationVocabulary() Vocabulary
OrganisationVocabulary is the tenancy of every v0.1 and v0.2 app, and the fallback for an app whose gorbital.yaml names no scope.
func ReadVocabulary ¶ added in v0.3.0
func ReadVocabulary(manifest []byte) Vocabulary
ReadVocabulary returns the tenancy vocabulary recorded in an app's gorbital.yaml, or the organisations one when it records none.
It reads the manifest defensively, by hand: the scope block is written by a later release of orb than the one that may be reading it, so an unknown key, a missing key or a malformed value is ignored rather than refused. A manifest with no scope block — every app up to v0.2.1 — gets OrganisationVocabulary, so the code generated for it is unchanged.
func (Vocabulary) A ¶ added in v0.3.0
func (v Vocabulary) A() string
A is the indefinite article for the tenant's name: "an organisation", "a merchant".
func (Vocabulary) AColumn ¶ added in v0.3.0
func (v Vocabulary) AColumn() string
AColumn is the indefinite article for the tenant's column name: "an org_id", "a merchant_id".
func (Vocabulary) CodeRoles ¶ added in v0.3.0
func (v Vocabulary) CodeRoles() string
CodeRoles is the roles as inline code, for prose: `owner`, `admin` and `member`.
func (Vocabulary) GoRoles ¶ added in v0.3.0
func (v Vocabulary) GoRoles() string
GoRoles is a Go []string literal of the roles' arguments, such as "owner", "admin", "member".
func (Vocabulary) Guard ¶ added in v0.3.0
func (v Vocabulary) Guard() string
Guard is the guard a tenant module's routes use: guard.Scope under the app's own vocabulary, and guard.OrgMember while the app has named no tenant, which is what v0.2 generated.
func (Vocabulary) IsOrganisations ¶ added in v0.3.0
func (v Vocabulary) IsOrganisations() bool
IsOrganisations reports the supplied organisations vocabulary.
func (Vocabulary) RoleList ¶ added in v0.3.0
func (v Vocabulary) RoleList() string
RoleList is the roles in prose: owner, admin and member.
func (Vocabulary) RolesField ¶ added in v0.3.0
func (v Vocabulary) RolesField() string
RolesField is the gorbital.Permission field a tenant module's permissions declare their roles in: ScopeRoles, or its v0.2 name OrgRoles while the app has named no tenant.
func (Vocabulary) ScopeRoles ¶ added in v0.3.0
func (v Vocabulary) ScopeRoles() []ScopeRole
ScopeRoles are the scope's roles with the constant name each one gets, most privileged first.
func (Vocabulary) Title ¶ added in v0.3.0
func (v Vocabulary) Title() string
Title is the tenant's name starting with a capital letter.
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). |