pdcli

package
v0.0.0-...-6810df5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 53 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pdcli is what `pd` does, kept out of `main` so that it can be tested by calling it rather than by running a binary and reading its output.

Index

Constants

View Source
const (
	Added  = "not generated"
	Stale  = "out of date"
	Orphan = "no longer generated"
)
View Source
const (
	DirProto = "proto"     // one directory: the schema, yours and generated
	DirExt   = "proto/ext" // overlays: what the app adds to what is generated
	DirEnt   = "internal/ent"
	DirBare  = "server/bare"
	DirPd_   = "server/pd"

	// DirTs is the app's TypeScript package, and DirTsGen is the part of it
	// `pd gen --ts` writes.
	//
	// Generated TypeScript lives inside the package rather than beside it
	// because it is imported by hand-written TypeScript in the same package,
	// and a `..` import across a package boundary is a thing every bundler has
	// its own opinion about.
	DirTs    = "ts"
	DirTsGen = "ts/gen"
)

The names under Layout.Root. They are constants rather than fields for the reason in Layout: an app that moved `proto/` somewhere else would be an app whose every instruction needs a footnote.

There is **one** proto directory, and what is in it says which half it belongs to:

  • `proto/<pkg>/thing.proto` is yours. So is anything else you write there.

  • `proto/<pkg>/thing_svc.g.proto` is generated from it -- the same `.g.` that marks generated Go.

  • `proto/<pkg>/payday/` is payday's own entities, copied in whole. Every file there is generated, which is why they do not need the suffix, and a README written beside them says so. It is a file and not a comment at the top of each: a comment there is a comment on the .proto, and protoc hands those to every generator, so it came out at the top of the Go and the TypeScript as well.

    **Inside** the app's package and not beside it, which is Layout.DirPd and is what lets two payday apps be linked into one process.

  • `proto/ext/` is yours again: the overlays. It is excluded from the buf module, because an overlay is a fragment rather than a file that compiles.

What used to be `proto.svc/` and `proto.pd/` is gone. Both were inputs to the merge and nothing else read them, so they are written to a temporary directory the way the generated Go already was.

View Source
const (
	NodeFloor = "22.12.0"
	NodeWhy   = "Vite 7 and 8 run on Node 20.19 or 22.12 and later; payday builds its floor on Node 22 and its target on 24"
)

NodeFloor is the oldest Node a page is built with, and why. Nothing here installs one: it is the machine's, so it is told rather than moved.

View Source
const BufEnv = "PD_BUF"

BufEnv names a buf to run instead of the one below.

It is the whole of the configuration, and it is for the two cases the download cannot serve: a machine with no route to GitHub, and somebody bisecting buf itself. Everything else gets the pinned one without being asked anything.

View Source
const BufVersion = "1.72.0"

BufVersion is the buf every generation runs, and it is a constant here rather than a thing an app is asked to configure.

**Which buf ran is part of what a generation produced.** buf compiles the schema, so its version decides what the descriptors every plugin reads carry: two of them disagree about whether a file's leading comment reaches the generated code, and about where the formatter breaks an option -- which moves files nothing in an app has touched. `pd gen --check` is a CI gate on exactly that output, so a buf that differs between two machines is a red build nobody caused.

It is payday's to pin because the rest of the generation is: `pd` writes the buf template, so the version of the thing that reads it is the same decision. An app that has to be told is an app that can be told wrong.

View Source
const DirWasm = "wasm"

DirWasm is the second entry point: the app, built for a platform with no file system, no listener and no network.

View Source
const LockFile = "past.lock"

LockFile is the past's lock, beside the copies of payday's entities in Layout.DirPd: the record of every kind of event the app ever declared, and of the message its rows hold (payday#151). See pdgen.Lock for why it exists and what it records.

Beside the copies, because what it is about is payday's Event, and because `pd gen --check` hashes that directory already: a lock left behind a schema is a file not in step like any other.

View Source
const PaydaysFromTop = pdgen.AppDomainMax + 1

PaydaysFromTop is the lowest of the domains payday numbers its own entities down from the top with: the ones it added after apps were numbering theirs up from 7. An app's entity takes a number below it, and so does its past.

View Source
const ProtoPkgDefault = "app"

ProtoPkgDefault is where payday's entities go in an app that has declared no entity of its own yet, and is what `pd new` writes.

Variables

View Source
var ErrBelowFloor = errors.New("the page's generator is older than payday builds with")

ErrBelowFloor is a page whose generator, or the runtime its code imports, is older than the oldest this payday builds with (see Floors).

View Source
var ErrNoApp = errors.New("no payday app here")

ErrNoApp is a directory that is not one payday generates for.

View Source
var ErrNoTsPlugin = errors.New("protoc-gen-es is not installed")

ErrNoTsPlugin is a working copy with no protobuf-es to generate with.

View Source
var ErrPaydayLacks = errors.New("an import of a payday package this payday does not have")

ErrPaydayLacks is an app that imports, itself or through a dependency, a package of payday's that the payday it is moving to does not have.

View Source
var ErrPaydayMoved = errors.New("go mod tidy moved payday off the version it was moved to")

ErrPaydayMoved is `go mod tidy` moving an app off the payday `go get` put it on.

View Source
var ErrPaydayRetracted = errors.New("that payday is retracted")

ErrPaydayRetracted is a payday its own module retracts.

View Source
var Floors = []Floor{{
	Name:    "@bufbuild/protobuf",
	Minimum: "2.12.1",
	With:    []string{"@bufbuild/protoc-gen-es"},
	Gen:     true,
	Why:     "the runtime the code `pd gen --ts` writes imports, of the generator's release",
}, {
	Name:    "@bufbuild/protoc-gen-es",
	Minimum: "2.12.1",
	With:    []string{"@bufbuild/protobuf"},
	Gen:     true,
	Why:     "what `pd gen --ts` writes the messages and services with",
}, {
	Name:    "@connectrpc/connect",
	Minimum: "2.1.2",
	With:    []string{"@connectrpc/connect-web"},
	Why:     "@lesomnus/payday's peer: the client a page makes of the services `pd gen --ts` writes",
}, {
	Name:    "@connectrpc/connect-web",
	Minimum: "2.1.2",
	With:    []string{"@connectrpc/connect"},
	Why:     "the browser's transport for that client, of connect's release",
}, {
	Name:    "@lesomnus/payday",
	Minimum: "0.1.2",
	Why:     "payday's half of the page, which the template's src is written against: its store.ts deletes other callers' mirrors with deleteOtherDisks, which 0.1.2 brought",
}, {
	Name:    "typescript",
	Minimum: "5.9.3",
	Why:     "what payday's declarations and the template's tsconfig are compiled with",
}, {
	Name:    "vite",
	Minimum: "7.2.0",
	With:    []string{"@vitejs/plugin-react"},
	Why:     "the vite.config.ts `pd new` and `pd sandbox init` write is written for it",
}, {
	Name:    "@vitejs/plugin-react",
	Minimum: "5.0.4",
	With:    []string{"vite"},
	Why:     "the React plugin that vite.config.ts loads, whose majors follow Vite's",
}}

Floors is every package payday holds an app's page to.

View Source
var Tools = tools

Tools is what an app's go.mod declares, in the order they are added.

Functions

func Buf

func Buf(ctx context.Context) (string, error)

Buf is the buf to run, fetched into a cache the first time and found there after.

BufEnv wins outright and is not verified against anything: somebody who named a buf has said which one they want, and a checksum on it would be this refusing the answer it asked for.

func CheckOverlayFile

func CheckOverlayFile(p string) error

CheckOverlayFile refuses an overlay that changes the file's features.

It is the one thing an overlay can say that is not about what it adds. The merge unions the options, so a `features.field_presence = IMPLICIT` copied from the entity file lands on the **whole contract** -- every field of every message in it, including the ones the generator wrote and the app has never read.

What it costs is not obvious, which is why it is refused rather than documented. Here it happened to take `HasId` off an Add request and stop the build, which is the lucky version; on a field nothing calls `Has` on it would change only what "not set" means on the wire, and nothing would say so.

An overlay adds messages and Rpcs. What the file is is the contract's, and the contract is generated.

func Domains

func Domains(l Layout) (map[int]string, error)

Domains is every domain this schema has taken, for a reader who wants to know.

func EntitleDir added in v0.1.1

func EntitleDir() (string, error)

EntitleDir is where payday's copy of entitlements is, beside SchemaDir, in the same module.

func Main

func Main()

Main is `pd`, for a `main` that is one line.

func NewCmdBuf added in v0.1.1

func NewCmdBuf() *xli.Command

NewCmdBuf is `pd buf`: the buf every generation runs, for what an app does with buf itself -- an API module of its own that it lints, formats and checks for breaks.

That work wants the buf a generation runs for the reason that one is pinned (BufVersion): two bufs disagree about what a schema compiles to and where the formatter breaks a line, so a check made with another is a check of something no generation made. And finding one is how an app got it wrong: a script took the highest version in `pd`'s cache, which on a machine that has run more than one payday is the newest one's buf, whichever the app is on.

So it asks what `pd gen` asks -- Buf: the cache, a fetch checked against its digest, BufEnv -- and then hands buf the rest of the line as it was written, its flags and its `--help` included (see [line]). The streams and the exit status are buf's too: `buf lint` and `buf breaking` answer 100 for what they found, and a script tells that from a buf that never ran by the number. It needs no app, and runs in the directory it is run in.

func NewCmdDoctor

func NewCmdDoctor() *xli.Command

NewCmdDoctor is `pd doctor`.

func NewCmdEntity

func NewCmdEntity() *xli.Command

NewCmdEntity is `pd entity`.

func NewCmdEntityAdd

func NewCmdEntityAdd() *xli.Command

NewCmdEntityAdd is `pd entity add`.

It saves almost no typing, and that is not what it is for. What it does is the two things a person adding the fourth entity gets wrong -- picking a domain nothing else has, and saying which side of the wall it is on -- and both of those fail in ways that are cheap here and expensive later.

func NewCmdEntityList

func NewCmdEntityList() *xli.Command

NewCmdEntityList is `pd entity list`: what this schema has, by domain.

It is the reading half of the same problem. A domain is one byte inside every identifier this app hands out, and it is not written anywhere a person browses -- so "what is domain 9" is a question with no easy answer and a bad one is an identifier that names the wrong kind of thing.

func NewCmdGen

func NewCmdGen() *xli.Command

NewCmdGen is `pd gen`.

func NewCmdNew

func NewCmdNew() *xli.Command

NewCmdNew is `pd new`: an app to start from.

What it writes is what a person writes, and nothing generated -- `pd gen` fills the rest in. That is not laziness: a template with generated code in it is a template carrying the output of one version of the generators, and the first thing anybody does with it is regenerate.

func NewCmdRoot

func NewCmdRoot() *xli.Command

NewCmdRoot is `pd`.

func NewCmdSandbox

func NewCmdSandbox() *xli.Command

NewCmdSandbox is `pd sandbox`.

func NewCmdSandboxInit

func NewCmdSandboxInit() *xli.Command

NewCmdSandboxInit is `pd sandbox init`.

It is not part of `pd new`, and that is a decision rather than an omission. The sandbox is only worth having to somebody building the page as well, and it is not free to everybody else: `wasm/main.go` makes `github.com/lesomnus/grpc-dgram` a direct requirement of the app, which is a module payday itself does not depend on. `pd new` writing `ts/` to everybody is not the same imposition -- an unused directory costs nothing, and an unused module requirement is in `go.mod`, in the sums, and in every audit of what this app depends on.

So there is one path to a sandbox and it is this, which also means it cannot rot the way a second one would: an app that started without a page and grew one runs exactly what a new app would have run.

func NewCmdUpgrade

func NewCmdUpgrade() *xli.Command

NewCmdUpgrade is `pd upgrade`: what this payday needs of an app, met by the tools that own it.

func NewCmdVersions

func NewCmdVersions() *xli.Command

NewCmdVersions is `pd versions`: the floors and targets this payday holds a page to, and what the app has of each.

func NodeVersion

func NodeVersion(ctx context.Context) string

NodeVersion is the Node on PATH, as npm writes a version, and empty with no Node there.

func NotifyDir

func NotifyDir() (string, error)

NotifyDir is beside the required entity sources, in the same payday module.

func Page

func Page(l Layout) (map[string]Have, bool, error)

Page reads the app's page: what its package.json declares, and what is installed of each. It answers false for an app with no page, which is a backend that `pd gen` serves on its own.

func PastDir

func PastDir() (string, error)

PastDir is where payday's past is, for the copy a generation of an app that declares one makes: beside SchemaDir, in the same module.

func PaydayVersion

func PaydayVersion(l Layout) string

SchemaDir is where payday's own entities are, for the copy that begins a generation.

It is asked of the module graph rather than being a path written down, so an app generating against payday v2 copies v2's entities without anybody having edited a script. An app inside payday's own module is the one case where the answer is here. PaydayVersion is the payday an app generates with, as a version string.

It is what gets stamped into the one generated Go file payday writes, so that a runtime linking a different payday can refuse; see `payday/version.Same`.

"(devel)" is the honest answer more often than it looks: payday's own repository under a `go.work`, an app with a `replace` to a checkout, and payday building itself all report nothing usable. Every one of those is a build somebody is working in, and the comparison is written to say nothing about them rather than to refuse them.

func PluginVersion

func PluginVersion(plugin string) (string, error)

PluginVersion is the version of the protoc-gen-es a plugin path runs: that of the package it is part of. The path is a `.bin` entry, which npm makes a link into the package and pnpm a script that calls it, so the link is followed to the package when there is one, and otherwise the package is the one of that name in the same node_modules -- which is where every package manager puts the package whose bin it is.

func SchemaDir

func SchemaDir() (string, error)

func SortedDomains

func SortedDomains(vs map[int]string) []int

SortedDomains is Domains in order, for printing.

func Targets

func Targets() (map[string]Target, error)

Targets reads them off the template this payday writes, so that what an upgrade moves to and what a new app starts with are one list -- which Renovate keeps current and CI's `new` job builds.

func Templates

func Templates(l Layout, out string) []string

Templates is every buf template one generation runs, in order.

It is exported so that what is claimed about them above can be tested by reading them, which is the only way to test most of it: a `strategy` left at the default does not fail, it generates less.

func TsPlugin

func TsPlugin(l Layout) (string, error)

TsPlugin finds the protobuf-es plugin.

It looks in the app's own TypeScript package first and then in the workspace's, which is the order an npm workspace resolves in, and refuses rather than falling back to `npx`: `npx` with nothing installed downloads whatever is newest, so a generation would silently use a different version of the plugin from the one the app's lockfile pins -- and the way that is found out is generated code that changed for no reason in somebody else's checkout.

Types

type AppDomains

type AppDomains struct {
	Archived uint32
	Access   uint32

	// At is the file that declared it, as a person would type it.
	At string
}

AppDomains is what an app declared of the domains of payday's `Archived` and `Access` (payday#163): the numbers it gives them, because its own entities already hold the ones payday does.

option (payday.app) = {domains: {archived: 240, access: 241}};

It is read off the schema before anything is compiled, for the reason Past is: it decides what `pd gen` writes for buf to compile -- the two copies, numbered. `pdgen.Read` reads the same option again off the compiled schema, and holds the copies to it. A number is zero where the declaration leaves that entity at the one payday gives it.

func (*AppDomains) Domain

func (d *AppDomains) Domain(own pdpb.Own) (uint32, bool)

Domain is the number the declaration gives the entity of that marker, and false for one it leaves where payday puts it.

type Changed

type Changed struct {
	// Path is relative to the app.
	Path string

	// How is what happened to it: written, rewritten, or left behind by an
	// entity that is no longer in the schema.
	How string
}

Changed is one file a generation was not in step with.

type Entitlements added in v0.1.1

type Entitlements struct {
	Domain uint32

	// At is the file that declared it, as a person would type it.
	At string
}

Entitlements is what an app declared of its copy of its tenants' entitlements (payday#185): that payday's `Entitlement` is among its entities, and the domain it takes.

option (payday.app) = {entitlements: {domain: 43}};

Read off the schema before anything is compiled, for the reason Past is: it decides what `pd gen` writes for buf to compile.

type Entity

type Entity struct {
	Layout Layout

	// Name is the message, in the case a proto message is written in: `Robot`.
	Name string

	// File is the .proto it goes in, relative to the schema directory. Empty is
	// one named after the entity.
	File string

	// Tenanted and Global are the two an app chooses between, and saying
	// neither is Tenanted: see [Entity.Add].
	Tenanted bool
	Global   bool

	// Tenant is the third tenancy the schema has and the one no app writes,
	// because payday ships the tenant. It is carried here rather than dropped
	// at the command line so that somebody who asked for it is told why;
	// [Entity.Add] refuses it.
	Tenant bool

	// Watch adds a `watch:` and the version field it needs.
	Watch bool
}

Entity writes a new entity into the app's schema.

Why this is a command rather than a paragraph in a README

Almost nothing here saves typing. What it saves is the two things a person adding the fourth entity to a schema gets wrong, and both of them fail in the way payday exists to prevent:

  • **A domain that is already taken.** Two entities sharing one makes an identifier lie about what it names, and it is caught at generation -- but only after the schema is written and only if the generation is run. Picking a free one is a thing a machine should do.
  • **Tenancy left unsaid.** Generation refuses it, which is the point, but a scaffold that emitted the option without it would be a scaffold whose first output does not build.

So what it writes is the shape that is hard to get right, and it leaves the fields -- which are the app's whole reason for existing and which nothing can guess -- as a `TODO`.

func (Entity) Add

func (e Entity) Add() (string, error)

Add writes the entity and answers with the file it went in.

type ErrSandbox

type ErrSandbox struct {
	// What is wrong, and Fix is what to do about it when there is such a thing.
	What string
	Fix  string
}

ErrSandbox is a working copy this cannot be written into.

func (ErrSandbox) Error

func (e ErrSandbox) Error() string

type Finding

type Finding struct {
	// What is the thing that is wrong, in one line.
	What string

	// Fix is what to type, or what to add, when there is such a thing.
	Fix string

	// Fatal says a generation cannot run at all, as against a generation that
	// runs and produces something quietly worse.
	Fatal bool
}

Finding is one thing about a working copy that will not do.

func Doctor

func Doctor(ctx context.Context, l Layout) []Finding

Doctor looks at a working copy and says what would go wrong.

Everything it reports is something that fails **later and further away** than where it was caused: a missing tool directive is a buf error about an executable, a missing buf dependency is a compile error about an unknown option, and a `strategy` left at the default is a wall with a hole in it and no error at all. Each of those is cheap to find here and expensive to find where it surfaces.

An empty answer means a generation will run and mean what it says.

func (Finding) String

func (f Finding) String() string

type Floor

type Floor struct {
	// Name is the npm package.
	Name string

	// Minimum is the oldest version, as npm writes one.
	Minimum string

	// Why is the reason it is that one: what a person reads when they are held
	// to it, and what somebody raising it checks next.
	Why string

	// With are the packages that move with this one. A major of one is a
	// major of the others, and npm refuses the half of the pair that moved
	// alone -- which is how @vitejs/plugin-react 6 failed on its own.
	With []string

	// Gen says `pd gen --ts` refuses below it. The code it writes is the
	// generator's and imports the runtime's, so an older one writes code the
	// rest of the page was not made with.
	Gen bool
}

Floor is the oldest version of a package an app's page may have and still be built against what this payday generates and ships.

A floor is a version payday has built a page with: CI's `floor` job makes an app with `pd new`, puts every package here at exactly its floor and builds it, on Node at NodeFloor. An upgrade moves a package below its floor to the floor, in the major it is in, and to its Target -- the version the page `pd new` writes declares, which the `new` job builds -- only when the floor is a later major (see Upgrades). So a floor is raised when payday comes to need something newer, and never because something newer exists: keeping current is Renovate's, and an app above its floors is left alone.

type Gen

type Gen struct {
	Layout Layout

	// Log is where the steps are said, and may be nil for a silent run.
	Log io.Writer

	// Out is where the generated Go lands, and is [Layout.Root] for a real
	// generation. `--check` points it at a directory nobody is looking at, and
	// that is the whole of how the check differs from the thing it checks --
	// there is no second implementation to drift.
	Out string
}

Gen is one run of the generator.

func (Gen) Check

func (g Gen) Check(ctx context.Context) ([]Changed, error)

Check generates and answers with what was not already there.

It runs the same generation the real one does rather than a second implementation of it, and that is the only way a check is worth anything: one that reimplemented the pipeline would drift from it, and the day it drifted is the day it stops catching what it exists to catch.

So it **writes**. A tree that was out of step is in step afterwards, which is what somebody running this wanted either way -- in CI it is the failure that matters, and at a desk it is the fix. What it answers with is what moved, taken by hashing before and after rather than by asking git, so it works in a tree that was never a repository.

func (Gen) CheckTs

func (g Gen) CheckTs(ctx context.Context) ([]Changed, error)

CheckTs is Gen.Check for the TypeScript half.

func (Gen) Run

func (g Gen) Run(ctx context.Context) error

Run generates everything an app has, in the order the pieces depend on one another.

The order is the part worth reading and the reason this is not four commands in a README. A `List` is an RPC: it has to be in the service contract before the messages, the stubs, the ent schema and the servers are generated from that contract. So the declarations are read twice -- once to write the contract, once to write the code -- and a generation that ran the second pass without the first would produce a stack that compiles and has no List in it.

func (Gen) Ts

func (g Gen) Ts(ctx context.Context) error

Ts writes the TypeScript half: the messages and the service descriptors, as protobuf-es emits them.

It is a step of its own and not part of Gen.Run, because the two have different audiences. A backend-only app runs `pd gen`, has no node_modules, and must not have its generation fail over a plugin it was never going to use; an app with a page in front of it asks for this as well.

What it does **not** generate is a client. protobuf-es v2 emits the service descriptors, and `@connectrpc/connect`'s `createClient` takes those directly -- so the client is a runtime function of a descriptor rather than a file per service, and there is nothing to keep in step. That is the same discipline §10.5 asks of the local store: generate the declaration, implement it once.

type Have

type Have struct {
	// Section is where its package.json declares it, and Range what it asks.
	Section string
	Range   string

	// Installed is the version a lockfile or node_modules says is there, and
	// empty when neither does.
	Installed string
}

Have is what an app's page says of one package.

func (Have) Version

func (h Have) Version() string

Version is the version to hold to a floor: the one installed, or, with nothing installed, the lowest the range admits -- which is what a fresh install could pick. Empty when neither can be read.

type Layout

type Layout struct {
	// Root is the directory the app's generated code lands in -- the one with
	// `proto/` in it.
	Root string

	// Module is the Go import path of [Layout.Root]. It is where the ent
	// runtime, the generated servers and `go.mod` are, and everything named in
	// this file is relative to it.
	Module string

	// Pkg is the Go import path of the generated messages: the `go_package`
	// the app's own entities declare.
	//
	// It is read rather than decided, because it is already written down. An
	// app that wants its generated Go somewhere other than the module root --
	// `<module>/api`, say, so that `ls` at the top is the app rather than a
	// hundred `.pb.go` -- says so once in its schema, and everything follows
	// from that one line.
	//
	// **One** `go_package` for the whole app, and an app whose entities
	// disagree is refused rather than generated: two Go packages is two sets of
	// ent schemas, an ent schema cannot have an edge to one in another package,
	// and the tenant wall is an edge. The failure without the refusal is a wall
	// that is not there.
	//
	// It is [Layout.Module] when nothing says otherwise, which is what `pd new`
	// writes and what nearly every app will keep.
	Pkg string

	// PkgName is what the messages' Go package is called, when the schema said
	// so rather than leaving it to be the last segment of [Layout.Pkg].
	//
	// `option go_package = "<module>/api;thingpb"` is the form, and it is the
	// one way the directory and the name are different things -- files in
	// `api/`, written `thingpb.Thing`. Empty when nothing said.
	PkgName string

	// ProtoPkg is the proto package the app's own entities declare, and the one
	// payday's are copied into.
	//
	// Read rather than decided, the same way [Layout.Pkg] is, and for a reason
	// worth writing down: **payday's entities go into the app's namespace, not
	// the other way round.** A Tenant and a Holder are the app's own concepts --
	// its customers and its people -- and a caller of the app should not have to
	// learn the name of the framework it was built with to say who they are.
	//
	// So there is no setting to turn on. Whatever the app calls its package is
	// where these land, and `payday.` survives on the wire only on the services
	// that are transports rather than domain concepts --
	// `payday.ResourceService` and `payday.TokenService`, which have nothing
	// per-app in them and which a generic client finds by those names.
	//
	// **One** package, and an app that declares two is refused, for the same
	// reason as `go_package`: the copies have to say something, and there is no
	// answer to "which one" that is not a guess.
	//
	// Unless the app answers it. `option (payday.app) = {};` on a file says that
	// file's package is the app's, and then the others are its business -- a
	// service that wants one shared word for the thing several services are
	// about, `fleet.Robot`, keeps the rest to itself. See [pdpb.App].
	//
	// # Two apps that share a boundary
	//
	// Setting this to the same package in both is how a family of apps says its
	// tenants and holders are the same concept -- and it is a claim about the
	// **schema**, not just the name. Two apps whose overlays differ and whose
	// packages agree publish two different messages under one name, which is the
	// one thing a fully-qualified name exists to prevent.
	//
	// What is shared without any of this is the **identifier**: a tenant is
	// domain 1 in every payday app and a `pdid` is unique without coordination,
	// so a row minted by one app is nameable by the other already.
	ProtoPkg string

	// Work is the directory holding `buf.yaml`, which is where buf is run from
	// and what every path in a template is relative to. It is [Layout.Root] for
	// an app that is one module, and above it for a workspace of several.
	Work string

	// Past is what the app declared of its past, and nil for an app that
	// declared none: whether payday's `Event` and `Fact` are written into it,
	// and at which domains (payday#151). Read off the file that says
	// `option (payday.app)`, like [Layout.ProtoPkg] -- see [Past].
	Past *Past

	// Notify is the optional notification records and their app-chosen domains.
	Notify *Notify

	// Domains is what the app declared of the domains of payday's Archived and
	// Access, and nil for an app that declared none: whether the two are
	// copied in at numbers of the app's own rather than payday's (payday#163).
	// Read off the same file as [Layout.Past] -- see [AppDomains].
	Domains *AppDomains

	// Entitlements is what the app declared of its copy of its tenants'
	// entitlements, and nil for an app that declared none: whether payday's
	// `Entitlement` is written into it, and at which domain (payday#185). See
	// [Entitlements].
	Entitlements *Entitlements
}

Layout is where an app's parts are.

Almost all of it is convention rather than configuration, and that is the point: a generator whose layout is configurable is one where two apps are laid out differently, and every piece of advice about either of them then has to begin by asking which.

Nothing here is a flag. What is not convention is read from a file that already exists and that the app owns anyway -- the module path from `go.mod`, the workspace from `buf.yaml`, and where the messages go from the `go_package` the schema declares. So an app can move its generated Go without payday growing a way to be configured, and there is still one place that says where it is.

func Discover

func Discover(dir string) (Layout, error)

Discover works out the layout from `dir`.

It walks up for the two files that cannot be guessed -- `go.mod` for the module path and `buf.yaml` for the workspace -- and refuses rather than guessing when either is missing. A `pd gen` that invented a module path would write it into every generated file, and the way that is found out is an import cycle three commands later.

func (Layout) DirPd

func (l Layout) DirPd() string

DirPd is where payday's own entities are copied to, **inside** the app's proto package rather than beside it.

It is derived and not a constant, and that is the whole of what lets two payday apps be linked into one process. A protobuf registry is per process and keys files by their path, so two apps that both copied `payday/holder.proto` panic on the second one to register -- before `main`, with no way to catch it. Which is not a hypothetical: it is what happened the first time an app tried to call another one's API.

Layout.ProtoPkg already says payday's entities go into the app's namespace rather than the other way round, and this is that sentence applied to the **file** as well as to the package. `directory/payday/holder.proto` is the identity store's copy; `app/payday/holder.proto` is whoever kept the default name.

The rule it leaves is one sentence: two payday apps can share a process when their proto packages differ. Two that both took `app` cannot, and could not have anyway -- their messages would both be `app.Holder`.

func (Layout) GoPackage

func (l Layout) GoPackage() string

GoPackage is what the copied entities are made to declare: Layout.Pkg, with the name after it when the app's own schema said one.

They have to say exactly what the app's entities say. Two files in one directory declaring two different Go packages is a build failure, and the copies are the ones that would be wrong.

func (Layout) Path

func (l Layout) Path(parts ...string) string

Path is a path under the app, absolute, for everything that is not a buf template.

func (Layout) PkgDir

func (l Layout) PkgDir() string

PkgDir is where the messages land under the app, and "." when that is the app itself.

func (Layout) Rel

func (l Layout) Rel(parts ...string) string

Rel is a path under the app, written the way a buf template has to have it: relative to the workspace, with forward slashes.

func (Layout) Up

func (l Layout) Up() string

Up is the way back to the module root from the message package, as a path prefix: "" when they are the same, and "../" for each directory between.

Everything except the messages is named relative to the module root, and every generator names its output relative to `go_package` -- so this is what the two are joined with. The generators join rather than concatenate, which is what makes a `..` in a plugin option a path and not nonsense.

type New

type New struct {
	// Dir is where it goes. It has to be empty or not there.
	Dir string

	// Module is the Go module path: "github.com/acme/thing".
	Module string

	// Name is what the app is called, and is the last segment of the module
	// when nothing said. Everything about where configuration comes from is
	// derived from it -- the files that are read, the prefix of every
	// environment variable -- which is why it is written once.
	Name string
}

New is one app being written out.

func (New) Called

func (n New) Called() string

Called is the app's name: the one given, or the last segment of the module.

It is a method because every use of New takes a value, so the defaults a call applies are gone when it returns -- and a caller that filled them in again for itself is a fourth copy of this rule that can disagree with the three above it. `pd new` was such a caller, and told a person their app was in "" because it looked at New.Dir and New.Name rather than at this.

func (New) Setup

func (n New) Setup(ctx context.Context, log io.Writer) error

Setup makes the app ready to generate: the tools, then buf's dependencies.

It is a flag rather than the default because it is minutes on a cold module cache and needs the network, and `pd new` should be able to write a tree without either. What it saves is not typing -- New.Steps prints the commands -- it is the order, which is not guessable: `go mod tidy` cannot run until the generated packages exist, and they cannot be generated until the tools are there.

func (New) Steps

func (n New) Steps() []string

Steps is what to type, for a `new` that did not set the app up itself.

func (New) Where

func (n New) Where() string

Where is the directory the app is written into.

Answering for a New nobody filled in is the whole of what it is for, and New.Setup is why that is worth more than a printed line: an `exec.Cmd` with an empty `Dir` runs where the process is standing, so a `pd new --setup` told only a module fetched the app's tools into whichever module the person happened to be in -- writing tool directives into somebody else's go.mod and leaving the app it had just written with none of them.

func (New) Write

func (n New) Write() error

Write puts the app there.

type Notify

type Notify struct {
	Notification uint32
	Receipt      uint32
	Global       bool
	At           string

	// KeepDays is how many days a notification is kept, zero for forever,
	// which Forever says why of; RetryDays how long its producers retry, when
	// the declaration says (payday#194).
	KeepDays  uint32
	RetryDays uint32
	Forever   string

	// Accounts is whether the app has an account namespace, which an account
	// reads as itself through NotificationAccountService (payday#195).
	Accounts bool
}

Notify is read before compilation because it decides which notification sources are copied into the app, and which domains their records carry.

func (*Notify) Domain

func (n *Notify) Domain(own pdpb.Own) uint32

type Past

type Past struct {
	Event uint32
	Fact  uint32

	// At is the file that declared it, as a person would type it.
	At string
}

Past is what an app declared of its past (payday#151): that payday's `Event` and `Fact` are among its entities, and the domain each takes.

option (payday.app) = {past: {event: 17, fact: 16}};

It is read off the schema before anything is compiled, for the reason Layout.ProtoPkg is: it decides what `pd gen` writes for buf to compile -- the two copies, numbered -- so it cannot wait for a compile. `pdgen.Read` reads the same option again off the compiled schema, and holds the copies to it.

func (*Past) Domain

func (p *Past) Domain(own pdpb.Own) uint32

Domain is the number the declaration gives the entity of that marker.

type Sandbox

type Sandbox struct {
	Layout Layout
}

Sandbox is `pd sandbox init` -- the files an app needs to run itself in a page, written once and then the app's.

Why it is `init` and not `add`

There is one of these. `pd entity add` is `add` because an app has many entities and each is a separate thing to name; a second sandbox is not a thing to have, and a verb that suggested otherwise would be inviting a question with no answer.

func (Sandbox) Init

func (s Sandbox) Init() ([]string, error)

Init writes the sandbox and answers with what is left to type.

What it will not do is edit a file somebody else wrote. `ts/vite.config.ts` is the one file here that already exists, and it is replaced only when it is still byte-for-byte what `pd new` left -- otherwise the two settings are reported for the app to add, which is the same rule `pd gen` holds to about hand-written Go.

type Step

type Step struct {
	Name    string
	Section string

	// From is what it is now, and To the range it is moved to.
	From string
	To   string

	// Floor is what it was held to, and Why is why. Partner is set for a
	// package that was not below its own floor and moves with one that was.
	Floor   string
	Why     string
	Partner bool
}

Step is one package an upgrade moves.

func Below

func Below(l Layout, plugin string) ([]Step, error)

Below is the generator's half of Upgrades: what `pd gen --ts` refuses to write with, given the plugin TsPlugin found.

The generator is held to its floor by the version of the plugin that runs -- its own package's, PluginVersion -- and not by what a lockfile says: a lockfile is what the next install makes, and a node_modules an install has not caught up with writes with what it has. The runtime its code imports is read as any other package is.

func Upgrades

func Upgrades(l Layout) ([]Step, error)

Upgrades are the packages of the app's page below their floors, and the packages they move with. A package the page does not have is not added, and one whose version cannot be read is not guessed at.

A package below its floor moves to the floor and no further than the major it is in, `^` the floor: what payday needs of it, and nothing an app has not asked for -- a later major is a migration, and Renovate's to propose. Only a package whose floor is itself a later major has a major to cross anyway, and that one moves to what `pd new` writes, its Target, with every package it moves with that the page has: a major of one is a major of the others.

type Target

type Target struct {
	Range   string
	Section string
}

Target is the range the page `pd new` writes declares for a package, in the section it declares it in: what an upgrade moves a package to when its floor is a later major than the one the page has.

type Upgrade

type Upgrade struct {
	Layout Layout

	// Log is where each step is said, and where the tools say what they did.
	Log io.Writer

	// DryRun says what would run and runs none of it.
	DryRun bool

	// Payday is a version `go get` takes -- `v0.2.0`, a commit, `latest` --
	// to move the app to before anything else. Empty is the payday running.
	Payday string
}

Upgrade brings an app up to what this payday needs, by running the tools that own each half rather than by editing what they write: npm for the page, and `go` for payday itself. It commits nothing; what changed is in the working tree for whoever ran it to read.

func (Upgrade) Run

func (u Upgrade) Run(ctx context.Context) error

Run is one upgrade.

Jump to

Keyboard shortcuts

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