Concept · domain-mode
Use when
You read or change many entities of a Shape in one step, or you build code against a Shape’s types.
Looking for something else?
Designing or changing a Shape (card shape, card shape-draft). One search or one read (card search, card entity). Staging changes by hand with the CLI (card workspace).
For
A domain is a published Shape seen as a set of types and relationships. Domain Mode gives you those types as calls in a program. The program lists entities, reads one, follows relationships, and stages or saves changes. Penumbra checks the program before it runs, and each call acts with your credential. The program is written in a checked subset of JavaScript. It has no network, no files and no clock. A program can only call what the domain offers.Use when
- You must read many entities of one Shape, or follow relationships across them, in one step.
- You stage many changes from a pattern, and a workspace by hand is too slow.
- Your own code must read and write a Shape’s types. Then you generate a typed client.
Not this
- You design or change the Shape itself: use card shape and card shape-draft.
- You need one search or one entity: use card search or card entity.
- You stage a few changes by hand: use card workspace.
Rules
domain-mode.1Read the domain before you write the program. Your job: on the default connection, callgrammarand name the domain withdomainwhen the project has several. In a Kit connection, calldomain_mode_introspect. The answer lists the types, the relationships, the rules and the calls that the program may use. Enforced: with several domains and no choice, the answer isdomain_selection_requiredand names the choices. A domain that does not exist isdomain_not_found.domain-mode.2A program is a checked subset of JavaScript. Enforced: a program with a form that Domain Mode does not accept is refused before it runs, withprogram_syntax_refused. The first line gives that code. Each further line names one form, its place and the form to use instead. A refused program leaves no run behind, so a fixed one may reuse the run id. Your job: useconst,for…ofover arrays,awaiton calls and array methods with one-expression arrows. Do not useletthat is reassigned,while, functions,try,newor regular expressions.domain-mode.3Penumbra repairs a few forms with one safe meaning. Your job: read thehealedlist in the result. It shows each form that Penumbra rewrote and why. Write the repaired form next time.domain-mode.4A program has limits. Enforced: a program over 256 KiB is refused withprogram_too_large. More than 64 calls to the host ends it withhost_call_budget_exceeded. A result over 64 KiB is refused withprogram_result_too_large. A program that runs over its deadline stops withexecution_deadline_exceeded. The default deadline is 10 seconds. Your job: split a large job into several programs, and page reads withlimitand the cursor. A page holds at most 100 entities.domain-mode.5A write has an outcome, and the program must read it. Your job: check each write forapplied,queued,pendingorunknown. A run withstatus: completedmeans that the program returned. It does not mean that every effect finished.pendingwaits for an approval (card approval), andunknownfollows problem reply-lost.domain-mode.6A write that the domain refuses is a value, not an error. Enforced: the call returnsoutcome: "refused"with acode, such asdomain_rules_rejected, and nothing is applied. Later writes in that run are held withrun_effects_held. Reads still work. Your job: test the outcome before the next write. A program has notry, and any other failure ends the program with its error.domain-mode.7Keep the reference of a run and resume it after a lost reply. Your job:executegivesexecution:<id>. Call it again withresumeset to that reference and the same code. Enforced: other code under the same reference is refused withrun_contract_or_program_changed. A run is kept for 24 hours. Callcheck_statuswith no reference to list your recent runs.domain-mode.8A domain runs at its current published version. Enforced: an entity saved under an older version reads when the changes since are non-breaking. Your job: after a breaking change, read problem breaking-shape-change before you run programs on the old entities.domain-mode.9A generated client is a file you keep. Your job: runpenumbra domain generate <shape> --out <file>, review the file, and keep it in source control. Pass--artifact-digestfor an exact version. Enforced: a file that differs is refused withoutput_existsunless you pass--force. With--check, a file that differs is refused withdomain_generation_changed, and nothing is written.domain-mode.10Neither the client nor a program adds authority. Enforced: every call uses the credential, the View and the approval rules of the connection that runs it. Your job: do not use a generated client to read what your credential cannot read.domain-mode.11A Kit can limit Domain Mode to some Shapes. Enforced: a connection at such an address refuses other Shapes withdomain_outside_endpoint_slice. Create the address withpenumbra kits addresses create <kit-id> --domain-mode-shape <shape-id>.
Failure signs
- A program is refused with
program_syntax_refused: rule domain-mode.2. - A call is refused with
domain_selection_required: rule domain-mode.1. - A run reports
completed, and the entities did not change: rules domain-mode.5 and domain-mode.6. - A run does not finish and the reply was lost: rule domain-mode.7 and problem reply-lost.
- An older entity refuses a property that the Shape now has: problem breaking-shape-change.
Doors
penumbra.shapes authors Shapes (card shape-draft).