Documentation
¶
Overview ¶
Package tui holds the `ofga mappings` editors as components. Each one edits a *mapping.Document in place and talks to whatever hosts it only through the messages below. The workspace hosts them.
Index ¶
- func DirItems(dir string, exts []string) ([]uilist.Item, error)
- func FailReason(o mapping.TestOutcome) string
- func Glyph(ic, text string) string
- func MappedCount() int
- func ProblemMark(p mapping.Problem) string
- func SetSample(r *mapping.Rule, label string, event map[string]any)
- func ShowRule(st *Stack, i int)
- type App
- type ApplyTarget
- type Focus
- type Jump
- type Options
- type Outcome
- type Picked
- type Preview
- type RuleAdded
- type RulesRequest
- type Session
- type Stack
- func (st *Stack) Depth() int
- func (st *Stack) Dialog() bool
- func (st *Stack) Filtering() bool
- func (st *Stack) Focus() (Focus, bool)
- func (st *Stack) Heading() (title, subtitle string)
- func (st *Stack) Help() (title, body string, ok bool)
- func (st *Stack) Init() tea.Cmd
- func (st *Stack) Keys() []string
- func (st *Stack) Resume() (tea.Cmd, Outcome)
- func (st *Stack) Titles() []string
- func (st *Stack) Typing() bool
- func (st *Stack) Update(msg tea.Msg) (tea.Cmd, Outcome)
- func (st *Stack) View(width, height int) string
- type TestResults
- type Toast
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DirItems ¶
DirItems lists what is worth opening in dir: the parent, the subdirectories, and the files whose extension is in exts.
Dot-entries are left out. .git alone holds more directories than most of the trees a browser will walk, and burying model.fga under them would make the listing worse at the one thing it is for. A file kept inside one is still reachable by typing its path, which is the other half of the browser.
Names come off the disk, so they are sanitized for display; Item.ID keeps the real path.
func FailReason ¶
func FailReason(o mapping.TestOutcome) string
FailReason is the first reason a test failed: an evaluation error first, since it is why everything else is missing, then the first tuple or filter missing, unexpected or not covered.
func Glyph ¶
Glyph prefixes text with an icon and a space, or leaves it alone when the icon rung has none: under icons = off a decorative icon is empty, and a bare leading space would read as an indent.
func MappedCount ¶
func MappedCount() int
MappedCount reports how many catalog events ship a ready-made mapping. Derived rather than written down: the two places that quoted it by hand had drifted apart, and the wrong number taught the user that an event mapping to nothing meant something was missing from their own setup.
func ProblemMark ¶
ProblemMark is the one place a severity becomes a character. A model warning is not a failure — the mapping saves — but it is not a clean bill either.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the program: the start screen, then the workspace.
func NewApp ¶
NewApp starts on the start screen, or straight in the workspace when opts.Path names a file. A path that does not exist opens a new mapping bound to it, as the start screen's New blank does. An error means that file could not be read, or could not be created where it was named.
type ApplyTarget ¶
type ApplyTarget struct {
StoreID string
Profile string
// Name looks the store's name up. Best effort: "" when it cannot.
Name func(ctx context.Context) string
Reader mapping.TupleReader
Writer mapping.TupleWriter
// Hints explains an apply failure the way the CLI does (clierr.Friendly,
// the condition-conflict hint). It may return nothing.
Hints func(err error) []string
// Resume is the CLI command that resumes applying path's events from event
// from. eventsPath is "" when the events did not come from one file; the
// command then says "EVENTS_FILE". path is the workspace's file, which
// Options.Path does not know when the start screen opened it.
Resume func(path, eventsPath string, from int) string
}
ApplyTarget is the active profile's store.
type Focus ¶
Focus is what the preview follows: the rule a component edits, and whether it edits inside that rule's iterator, where expressions address the item.
type Jump ¶
Jump asks the host to show rule Rule in its Rules pane with the editor Section open ("" opens the rule itself). The Tests pane's e and the Check rows close with it. Section is one of "trigger", "action", "variables", "iterator", "filters", "tuple" or "".
type Options ¶
type Options struct {
// Path opens this file directly, skipping the start screen ("" shows it).
Path string
// Dir is where the start screen looks for mapping files.
Dir string
// RecentFile is mappings-recent.json; "" keeps no recent list.
RecentFile string
// Store names the configured store for the model dialog, e.g.
// "profile prod, store 01ARZ3NDEKTSV4RRFFQ69G5FAV"; "" when none is set,
// and then the store option is not offered.
Store string
// LoadStoreModel reads the store's model: --model-id or the profile's
// model when set, else the latest. Nil when Store is "".
LoadStoreModel func(ctx context.Context) (*openfga.AuthorizationModel, error)
// Version is shown in the sidebar's brand line.
Version string
// Apply is the store the Apply pane writes to; nil when no store is set,
// or when one is set but cannot be used.
Apply *ApplyTarget
// ApplyErr is why the store that is set cannot be used, such as a
// malformed store ID; "" when Apply is set or no store is.
ApplyErr string
}
Options configures `ofga mappings`.
type Outcome ¶
type Outcome struct {
// Changed reports that a component edited the document.
Changed bool
// Toasts are the lines components asked for, in order.
Toasts []Toast
// Requests are what components asked of the host, in order, that leave the
// stack as it is.
Requests []any
// Closed reports that the root asked to close. The stack never pops its
// root: whoever opened the stack decides what closing means.
Closed bool
// Result is what the root closed with.
Result any
}
Outcome is what one Update settled that the host has to act on.
type Picked ¶
type Picked struct {
Label string
Event map[string]any
// Catalog is the catalog event chosen, set only by the add-rule fork's
// pick, which shows the event's recipe before anything is committed.
// Nil for a paste or a file, and for every pick on an existing rule.
Catalog *auth0.Event
}
Picked is what an event pick closes with.
type Preview ¶
type Preview struct {
// contains filtered or unexported fields
}
Preview is the pane beside the editor: the file being built or the sample's payload, over what the sample evaluates to. A host draws it beside its stack, not on it, so its keys reach it whatever editor is on top.
func NewPreview ¶
NewPreview builds the pane. title heads the file section.
func (*Preview) Refresh ¶
Refresh re-evaluates the document against the sample of the rule at points at. Evaluating a mapping-sized document costs microseconds and is capped by mapping.EvalTimeout, so a host calls it after every edit.
func (*Preview) Switch ¶
Switch is what ctrl+t leads to, in the words the section header uses: the file from the payload, the payload from the file, nothing without a sample.
type RuleAdded ¶
type RuleAdded struct{ Index int }
RuleAdded is what a rule fork closes with: the index of the first rule it appended (a recipe can append several).
type RulesRequest ¶
type RulesRequest int
RulesRequest is what the rules hub asks of its host: the actions that leave the editor. The hub closes with one and stays where it is, for the host to come back to.
const ( // RequestAdd asks for a new rule, which the host's add-rule fork creates. RequestAdd RulesRequest = iota // RequestModel asks for the model source. RequestModel // RequestSave asks for the save dialog. RequestSave // RequestQuit asks to leave: outright with no rules, or by way of saving. RequestQuit // RequestTests asks for the tests, which the host shows over the hub. RequestTests )
type Session ¶
type Session struct {
Ctx context.Context
Doc *mapping.Document
Index *mapping.ModelIndex
// ReadOnly makes the components refuse the keys that edit the document and
// drop them from Keys.
ReadOnly bool
// contains filtered or unexported fields
}
Session is what every component on a stack shares: the document they edit in place, the model they check against, the context evaluation runs under, and the messages posted that the stack has not settled yet.
func NewSession ¶
NewSession starts the state the components on one host share.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a host's handle on a pile of components: the top one has the keyboard, and the ones under it are where closing goes back to.
func OpenTests ¶
OpenTests opens the test list on its own, for a host that shows the tests apart from the rules hub. at is the rule the preview follows.
func (*Stack) Filtering ¶
Filtering reports whether the top component's list filter is taking input.
func (*Stack) Init ¶
Init starts the root component's work, such as focusing a text area. A root may open its first child here (see ruleFork), so what it posted is settled too. A root's Init may only open children: anything else it posts (a change, a toast, a request) is dropped with the Outcome.
func (*Stack) Resume ¶
Resume tells the top component it is on top again after the host showed something over the whole stack, so it re-reads the document. It settles and returns like Update.
func (*Stack) Typing ¶
Typing reports whether the top component takes text: a form, a paste box, a typed path, or a list whose filter is being set. The host's single-key bindings must reach it instead.
type TestResults ¶
type TestResults struct {
Compiled bool
Outcomes map[string]mapping.TestOutcome
}
TestResults is how the tests a save writes fare against the document as it is now: each outcome by test name. Compiled is false when the mapping does not compile, and then nothing ran.
func RunSavedTests ¶
func RunSavedTests(ctx context.Context, d *mapping.Document) TestResults
RunSavedTests runs the tests a save writes the way `ofga mappings test` runs the saved file: rendered, loaded and run through mapper, so a verdict here is the verdict there. A mapping-sized run is small and in memory, so the screens run it on every change, each evaluation capped at mapping.EvalTimeout like the preview's rather than at the CLI's longer timeout.
Source Files
¶
- app.go
- apply.go
- check.go
- component.go
- events.go
- filebrowse.go
- filters.go
- fork.go
- found.go
- helpers.go
- iterator.go
- modeldialog.go
- namefile.go
- pathpick.go
- preview.go
- quit.go
- recent.go
- recipe.go
- rows.go
- rule.go
- rules.go
- stack.go
- start.go
- test_editor.go
- tests.go
- trigger.go
- tuple_form.go
- tuples.go
- validators.go
- variables.go
- window.go
- workspace.go
- workspace_apply.go
- workspace_keys.go
- workspace_model.go
- workspace_modes.go
- workspace_save.go
- workspace_tests.go
- workspace_view.go