readmodel

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 32 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 readmodel keeps every unit's row derived, encoded and revised in memory, rebuilt from one store snapshot when a row input changes.

Index

Constants

View Source
const FacetWaitsOn = "waits-on"

FacetWaitsOn is the facet of whom a row waits on, by login or team.

View Source
const PokeQuiet = 250 * time.Millisecond

PokeQuiet is how long the model waits after a row note before it refreshes, so a burst of notes costs one refresh.

Variables

This section is empty.

Functions

func BuildCatalog

func BuildCatalog(providers ...Provider) api.CatalogResponse

BuildCatalog is the served presentation of the providers that are Presenters, in their order; a view id another provider took first is left out, and a provider's view orders follow the previous providers'.

func CardSignal added in v0.4.0

func CardSignal(s src.CardSignal) card.Signal

CardSignal is a plugin's card signal as a card holds it.

func Login added in v0.3.0

func Login(p unit.ProviderID, id src.Identity) string

Login is the viewer's login in provider p from id; "" when its key is not p's.

func Unmuted added in v0.3.0

func Unmuted(in any) any

Unmuted is in, a reported unit's row input, derived as if the user had not muted it; in as it is for another provider's input.

Types

type Activities added in v0.2.0

type Activities interface {
	Activities(ctx context.Context, provider unit.ProviderID) (map[unit.Unit]turn.Activity, error)
}

Activities reads what the loop spent on a provider's units, those with any.

type Agents

type Agents interface {
	Agents() (agents []turns.AgentObservation, ok bool)
}

Agents is the agents' last known states; ok is false when they are unknown.

type AgentsFunc

type AgentsFunc func() ([]turns.AgentObservation, bool)

AgentsFunc adapts a function to Agents.

func (AgentsFunc) Agents

func (f AgentsFunc) Agents() ([]turns.AgentObservation, bool)

type Base

type Base struct {
	// Viewers and Teams are the viewer's login and teams in each source, as
	// its plugin's Identity says.
	Viewers map[unit.ProviderID]string
	Teams   map[unit.ProviderID][]string
	Specs   []api.ActionSpec
	// SpecsVersion is the version of GET /api/actions the rows' actions follow.
	SpecsVersion string
	// Intents are the loaded intents whose actions a row of a provider other than GitHub offers; nil offers
	// none.
	Intents *intentload.Loaded
	// Plans are the automatic rounds the open plan gates hold, by unit.
	Plans  map[unit.Unit]overlay.Pending
	Agents []turns.AgentObservation
	// AgentsOK is false when the agents are unknown, so no session can be
	// told waiting.
	AgentsOK bool
	// Asked is the action a request asks for; zero for a served row.
	Asked catalog.Asked
}

Base is what every row of a rebuild shares, built once per rebuild.

func (*Base) Identify added in v0.3.0

func (b *Base) Identify(p unit.ProviderID, id src.Identity)

Identify sets the viewer and the teams of provider p from id, the Identity its plugin serves; a viewer whose key is not p's names no login.

type Booker added in v0.3.0

type Booker interface {
	Book(in any) (b turn.Book, has bool)
}

Booker is optional on a Provider: the turn book in, a row input of the provider, holds; has is false for a unit with none.

type Books

type Books interface {
	Books(ctx context.Context, units ...unit.Unit) (map[unit.Unit]turn.Book, error)
}

Books reads turn books.

type Built

type Built struct {
	Entry
	Provider Provider
	In       any
}

Built is a served entry with what its row was derived from.

type Entry

type Entry struct {
	Unit unit.Unit
	Row  api.Row
	JSON []byte
	Rev  uint64
}

Entry is one unit's row as served: JSON is Row encoded, Rev the revision at which JSON last changed.

type EventPresenter added in v0.3.0

type EventPresenter interface {
	Events() []api.EventSpec
	Details() []api.DetailSpec
}

EventPresenter is optional on a Presenter: the words of its event kinds.

type Kept

type Kept struct {
	Base Base
	At   time.Time
	Rows []Built
}

Kept is a snapshot as its keeper sees it: the base, the minute and every row, shared with the snapshot and read-only.

type LensPresenter added in v0.4.0

type LensPresenter interface {
	Lens() api.ProviderWords
}

LensPresenter is optional on a Presenter: its own row words.

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model serves every provider's rows from one immutable snapshot, rebuilt whole when a row input changed or the minute moved.

func New

func New(changes port.Changes, snap Snapshotter, plans Plans, agents Agents, settings Settings, providers ...Provider) *Model

New builds a model over the providers. A nil changes rebuilds on every read; nil plans, agents or settings leave their Base fields zero.

func (*Model) Base

func (m *Model) Base(ctx context.Context) (Base, time.Time, error)

Base is what the current snapshot's rows share, and the minute they were derived at.

func (*Model) Catalog

func (m *Model) Catalog() api.CatalogResponse

Catalog is the served presentation of the model's providers.

func (*Model) Check

func (m *Model) Check(ctx context.Context) []string

Check derives every row from scratch at the snapshot's minute and lists each unit whose served row differs, with the fields that differ; none when the snapshot matches or none was served yet.

func (*Model) Current

func (m *Model) Current(ctx context.Context) (Kept, error)

Current is the snapshot that holds every write noted before the call, as its keeper sees it. Its rows are shared: read them, never change them.

func (*Model) Presentations

func (m *Model) Presentations(units []unit.Unit) map[unit.Unit]Presentation

Presentations are the presentations of the units the snapshot lists, without a sync.

func (*Model) Read

func (m *Model) Read(ctx context.Context, u unit.Unit) (Read, bool, error)

Read is u's entry; ok is false for a unit no provider lists. The row is a copy the caller may change; In is shared and must not be.

func (*Model) ReadMany

func (m *Model) ReadMany(ctx context.Context, units []unit.Unit) (map[unit.Unit]Read, Base, time.Time, error)

ReadMany is the entries of the units any provider lists, from one snapshot, with the base and the minute it holds.

func (*Model) Refresh

func (m *Model) Refresh(ctx context.Context) error

Refresh brings the snapshot up to date and runs the keeper on it if it is new, as Run does on each note and minute.

func (*Model) Row

func (m *Model) Row(ctx context.Context, u unit.Unit, asked catalog.Asked) (api.Row, bool, error)

Row is a copy of u's row, derived for a request that asks for an action; ok is false for a unit no provider lists.

func (*Model) Rows

func (m *Model) Rows(ctx context.Context, since api.Since) (api.RowsPage, error)

Rows are the rows: all of them when since is zero, of another epoch, ahead of Rev or behind the tombstones, else those that changed after since and the units that left. The rows are copies the caller may change.

func (*Model) Run

func (m *Model) Run(ctx context.Context, publish func(api.Change))

Run keeps the snapshot current until ctx ends: it rebuilds on a row input's note, debounced, and on the minute, and publishes a Change each time the revision moved, starting from the model's first snapshot, since a client may have read it before Run started.

func (*Model) Served

func (m *Model) Served() bool

Served tells whether the model has built a snapshot yet.

func (*Model) Since

func (m *Model) Since(ctx context.Context, since api.Since) (api.Change, error)

Since is what a client at since missed: the units whose row changed or left after it, or All when since is of another epoch, ahead of Rev or behind the tombstones. A zero since missed nothing, so its Change only says where the rows are.

func (*Model) UseClock

func (m *Model) UseClock(now func() time.Time)

UseClock sets the clock rows are derived at.

func (*Model) UseKeeper

func (m *Model) UseKeeper(keep func(ctx context.Context, k Kept))

UseKeeper sets the bookkeeping Refresh does once per new snapshot, off the read path: the writes the rows imply.

func (*Model) UseLog

func (m *Model) UseLog(logf func(format string, args ...any))

UseLog sets where Run logs a failed rebuild.

type Mutes added in v0.3.0

type Mutes interface {
	Mutes(ctx context.Context, units []unit.Unit) (map[unit.Unit]overlay.Mute, error)
}

Mutes reads the user's mutes of units; a unit with none is absent.

type Notice added in v0.3.0

type Notice struct {
	// Gate is the kind of the gate the notice stands for, which keys it on
	// the unit's task; "" for one no gate stands for.
	Gate gate.Kind
	// Held says the notice is of a held round; Question of the open
	// question of the turn record Record.
	Held, Question bool
	Record         int64
	// Token lasts as long as what is notified.
	Token string
	// Attention carries no ID and no Category, which the caller keys.
	Attention api.Attention
}

Notice is what a row notifies, as its provider derives it.

type Noticer added in v0.3.0

type Noticer interface {
	Notice(base Base, row api.Row, in any, at time.Time) (Notice, bool)
}

Noticer is optional on a Provider: what row, derived from in at at, notifies; ok is false when it notifies nothing.

type Plans added in v0.3.0

type Plans interface {
	Plans(ctx context.Context) (map[unit.Unit]overlay.Pending, error)
}

Plans are the automatic rounds the open plan gates hold, by unit.

type Presentation

type Presentation struct{ Label, Title, Link string }

Presentation is a unit's label, title and link as its row shows them.

type Presenter

type Presenter interface {
	Views() []api.ViewSpec
	Facets() []api.FacetSpec
	Situations() []api.SituationSpec
}

Presenter is optional on a Provider: its served views, facets and situations, read once per catalog build.

type Provider

type Provider interface {
	Provider() unit.ProviderID
	// Listed are the units the provider serves a row for.
	Listed(ctx context.Context) ([]unit.Unit, error)
	// Load reads what the rows of units derive from; a unit missing from
	// the result has no row.
	Load(ctx context.Context, units []unit.Unit) (map[unit.Unit]any, error)
	// Derive is pure: the row of one unit from base and what Load read,
	// with the Link and Label Load read; the model sets the row's Unit.
	Derive(base Base, in any, at time.Time) (api.Row, error)
}

Provider is one provider's rows.

type Read

type Read struct {
	Row  api.Row
	In   any
	Base Base
	At   time.Time
	// contains filtered or unexported fields
}

Read is one unit's entry of a snapshot: the served row, what it derives from and the base it was derived with.

func (Read) Book added in v0.3.0

func (r Read) Book() (b turn.Book, has, kept bool)

Book is the turn book the read's input holds; kept is false when its provider keeps no book, so the caller reads it.

func (Read) Derive

func (r Read) Derive(base Base, in any) (api.Row, error)

Derive is the unit's row from base and in, at the minute of the snapshot, on the read's unit.

func (Read) Notice added in v0.3.0

func (r Read) Notice() (Notice, bool)

Notice is what the read's row notifies; ok is false when it notifies nothing or its provider notifies no row.

func (Read) Signals added in v0.3.0

func (r Read) Signals() map[string]bool

Signals are the link signals of the read's row, by name; none when its provider reports none.

func (Read) Unmuted added in v0.3.0

func (r Read) Unmuted() any

Unmuted is the read's input as if the user had not muted its unit.

type ReasonPresenter added in v0.4.0

type ReasonPresenter interface {
	Reasons() api.ProviderWords
}

ReasonPresenter is optional on a Presenter: its words of the reasons its rows name.

type Reported added in v0.3.0

type Reported struct {
	// contains filtered or unexported fields
}

Reported serves a source plugin's units as rows: each unit's last snapshot under the host's overlays, with no call to the plugin. The overlays are the run that drives the row, the mute and the pending round; an open intake shows in the row's line.

func NewReported added in v0.3.0

func NewReported(src ReportedSource) *Reported

NewReported is the provider of src's units.

func (*Reported) Card added in v0.3.0

func (p *Reported) Card(ctx context.Context, row api.Row) (card.Card, error)

Card is a reported unit's card: its plugin's, under the overlays its row shows. A row whose situation an overlay set says why and on whom in the card too.

func (*Reported) CardSignals added in v0.4.0

func (p *Reported) CardSignals() []api.SignalSpec

func (*Reported) Derive added in v0.3.0

func (p *Reported) Derive(base Base, in any, at time.Time) (api.Row, error)

Derive is the row of one reported unit at at.

func (*Reported) Details added in v0.3.0

func (p *Reported) Details() []api.DetailSpec

func (*Reported) Events added in v0.3.0

func (p *Reported) Events() []api.EventSpec

func (*Reported) Facets added in v0.3.0

func (p *Reported) Facets() []api.FacetSpec

func (*Reported) Lens added in v0.4.0

func (p *Reported) Lens() api.ProviderWords

func (*Reported) Listed added in v0.3.0

func (p *Reported) Listed(ctx context.Context) ([]unit.Unit, error)

Listed are the units the plugin reported.

func (*Reported) Load added in v0.3.0

func (p *Reported) Load(ctx context.Context, units []unit.Unit) (map[unit.Unit]any, error)

Load reads each unit's last snapshot, its turn book and session, its mute and its open intake. A unit with no snapshot has no row.

func (*Reported) Provider added in v0.3.0

func (p *Reported) Provider() unit.ProviderID

func (*Reported) Reasons added in v0.4.0

func (p *Reported) Reasons() api.ProviderWords

func (*Reported) Signals added in v0.3.0

func (p *Reported) Signals(_ Base, _ api.Row, in any, _ time.Time) map[string]bool

Signals are the link signals the plugin reported of the unit.

func (*Reported) Situations added in v0.3.0

func (p *Reported) Situations() []api.SituationSpec

func (*Reported) Unmuted added in v0.3.0

func (p *Reported) Unmuted(in any) any

Unmuted is in derived as if the user had not muted its unit.

func (*Reported) Views added in v0.3.0

func (p *Reported) Views() []api.ViewSpec

type ReportedSource added in v0.3.0

type ReportedSource struct {
	RowDeps
	ID      unit.ProviderID
	Reports Reports
	Mutes   Mutes
	// Viewer is the user as the plugin's people are keyed, whom a card
	// waiting on the user names; nil names nobody.
	Viewer func(ctx context.Context) items.Person
	// Stale says u's plugin no longer stands behind its last report; nil
	// says none is.
	Stale func(u unit.Unit) bool
	// Catalog is the plugin's views, facets and situations; nil serves none.
	Catalog Presenter
}

ReportedSource is what a source plugin's rows read: its reports and the host's own state. Mutes may be nil: no unit is muted.

type Reports added in v0.3.0

type Reports interface {
	// Units are p's units with a snapshot.
	Units(ctx context.Context, p unit.ProviderID) ([]unit.Unit, error)
	// Reported are units' last snapshots; a unit with none is absent.
	Reported(ctx context.Context, units []unit.Unit) (map[unit.Unit]src.Snapshot, error)
}

Reports reads what source plugins last reported of their units.

type RowDeps

type RowDeps struct {
	Books    Books
	Sessions Sessions
	Activity Activities
	// Intakes are the open intakes, the oldest first.
	Intakes func(ctx context.Context) ([]intake.Intake, error)
	// Intake is a row's view of an open intake, from its unit's brief;
	// attempt is the brief attempt the intake waits on.
	Intake   func(i intake.Intake, b intake.BriefState, attempt func() (int, error)) api.Intake
	Settings func() RowSettings
	Logf     func(format string, args ...any)
}

RowDeps are what the daemon supplies to any provider's rows. Books, Sessions, Activity, Intakes and Intake may be nil: no turns, no sessions, no activity, no intakes.

type RowSettings

type RowSettings struct {
	Cfg    config.Config
	Loaded *intentload.Loaded
	GateOn bool
	// Forceable is the last remove refusal of a unit that force gets past,
	// "" for none.
	Forceable func(unit.Unit) string
}

RowSettings is what every row reads of the configuration, the profile and the daemon, read once per load.

type Sessions

type Sessions interface {
	// Sessions lists the sessions not closed.
	Sessions(ctx context.Context) ([]turn.Session, error)
	Session(ctx context.Context, handle string) (turn.Session, bool, error)
}

Sessions reads the managed sessions.

type Settings

type Settings interface {
	Settings(ctx context.Context) (Base, error)
}

Settings supplies the Base fields no other port does: viewers, teams and action specs.

type SignalPresenter added in v0.4.0

type SignalPresenter interface {
	CardSignals() []api.SignalSpec
}

SignalPresenter is optional on a Presenter: its words of its cards' signals.

type Signaler added in v0.3.0

type Signaler interface {
	Signals(base Base, row api.Row, in any, at time.Time) map[string]bool
}

Signaler is optional on a Provider: the link signals of row, derived from in at at, under the host's overlays, by name.

type Snapshotter

type Snapshotter interface {
	Snapshot(ctx context.Context, fn func(ctx context.Context) error) error
}

Snapshotter runs fn with every store read made with its ctx inside one read transaction.

type Summary

type Summary = api.Summary

Summary is what any provider's row says in generic terms.

type Unmuter added in v0.3.0

type Unmuter interface {
	Unmuted(in any) any
}

Unmuter is optional on a Provider: in, a row input of the provider, derived as if the user had not muted its unit.

type WakeMutes added in v0.3.0

type WakeMutes func(ctx context.Context, units []unit.Unit) (map[unit.Unit]wake.Wake, error)

WakeMutes are Mutes from the wakes of the units' tasks, as wakes reads them by unit.

func (WakeMutes) Mutes added in v0.3.0

func (f WakeMutes) Mutes(ctx context.Context, units []unit.Unit) (map[unit.Unit]overlay.Mute, error)

Mutes are the mutes the wakes hold; a spent wake mutes nothing.

Directories

Path Synopsis
Package cards keeps the units' card snapshots and derived items current with the rows the read model publishes.
Package cards keeps the units' card snapshots and derived items current with the rows the read model publishes.
Package overlay lays the host's own state over a unit's situation as its source derives it: the loop's run on the unit, the user's mute and a pending round.
Package overlay lays the host's own state over a unit's situation as its source derives it: the loop's run on the unit, the user's mute and a pending round.
Package prrow derives the row of a pull request from what the store, the gate and the turns say of it: the github provider of the read model.
Package prrow derives the row of a pull request from what the store, the gate and the turns say of it: the github provider of the read model.
ghreporttest
Package ghreporttest derives the GitHub plugin's snapshot of a pull request the host's tests hold as inventory rows, with the plugin's own code, so a host test renders the rows the running plugin's reports render.
Package ghreporttest derives the GitHub plugin's snapshot of a pull request the host's tests hold as inventory rows, with the plugin's own code, so a host test renders the rows the running plugin's reports render.

Jump to

Keyboard shortcuts

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