items

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 13 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 items is the items ledger: the only writer of a unit's items.

Index

Constants

View Source
const (
	OutcomeApplied  = "applied"
	OutcomeNoop     = "noop"
	OutcomeProposed = "proposed"
	OutcomeRefused  = "refused"
)

Outcomes of an op in the log.

View Source
const ExtractedLinkLookback = 7 * 24 * time.Hour

ExtractedLinkLookback is how far before its item's creation an extracted link may start: the extractor's window holds older messages, as far back as the Slack backfill.

Variables

View Source
var ErrNoProposal = errors.New("no open proposal")

ErrNoProposal is Decide's error for an id that names no open proposal.

Functions

func DedupeKey

func DedupeKey(o items.Op) string

DedupeKey is the identity of a proposal among the open ones: its op without anchor, reason, basis and evidence.

Types

type Applied

type Applied struct {
	Op      items.Op   `json:"op"`
	Item    items.Item `json:"item"`
	Changed bool       `json:"changed"`
}

type Applier

type Applier interface {
	Apply(ctx context.Context, prov items.Provenance, ops []items.Op) (Result, error)
	Items(ctx context.Context, u unit.Unit) ([]items.Item, error)
}

type Commit

type Commit struct {
	Items     []items.Item
	Log       []LogEntry
	Proposals []Proposal
}

type DisabledError

type DisabledError struct{ Provider unit.ProviderID }

DisabledError is returned, with nothing applied, when an op or a proposal is on a unit of a disabled plugin; the daemon answers it with 409. A link to such a unit is stored.

func (*DisabledError) Error

func (e *DisabledError) Error() string

type Ledger

type Ledger struct {
	Store   Store
	Links   port.LinkStore             // nil refuses link ops
	Enabled func(unit.ProviderID) bool // nil: every provider enabled
	Clock   port.Clock
	Log     func(string, ...any)
	// contains filtered or unexported fields
}

Ledger serializes Apply, Reconcile and Decide; a process keeps one Ledger per store.

func (*Ledger) Apply

func (l *Ledger) Apply(ctx context.Context, prov items.Provenance, ops []items.Op) (Result, error)

Apply applies ops in order, each applied, proposed, refused or a no-op, and commits the outcome of the batch at once.

func (*Ledger) Decide

func (l *Ledger) Decide(ctx context.Context, id int64, accept bool) (Result, error)

Decide settles a proposal; accept applies its Op as user.

func (*Ledger) Items

func (l *Ledger) Items(ctx context.Context, u unit.Unit) ([]items.Item, error)

func (*Ledger) Proposals

func (l *Ledger) Proposals(ctx context.Context, state ProposalState) ([]Proposal, error)

func (*Ledger) Query

func (l *Ledger) Query(ctx context.Context, q Query) ([]items.Item, error)

func (*Ledger) Reconcile

func (l *Ledger) Reconcile(ctx context.Context, u unit.Unit, desired []items.Item, at unit.Anchor, absent items.Resolution) (Result, error)

Reconcile makes the derived items of u equal desired: create or update each, and resolve an open derived item absent from desired with Resolution absent (superseded when "") and evidence {unit_event, at}. Desired items carry their final State and Resolution. A derived change to a confirmed item is logged noop with reason "confirmed" and never proposed. Reconcile on a disabled provider returns DisabledError and writes nothing.

type LogEntry

type LogEntry struct {
	Unit       unit.Unit
	Item       string
	Op         items.Op
	Provenance items.Provenance
	Outcome    string // applied, noop, proposed, refused
	Reason     string
	At         time.Time
}

type Proposal

type Proposal struct {
	ID         int64            `json:"id"`
	Unit       unit.Unit        `json:"unit"`
	Item       string           `json:"item"`
	Op         items.Op         `json:"op"`
	Provenance items.Provenance `json:"provenance"`
	Reason     string           `json:"reason"`
	State      ProposalState    `json:"state"`
	At         time.Time        `json:"at"`
}

type ProposalState

type ProposalState string // "open", "accepted", "rejected"
const (
	ProposalOpen     ProposalState = "open"
	ProposalAccepted ProposalState = "accepted"
	ProposalRejected ProposalState = "rejected"
)

type Query

type Query struct {
	Units     []unit.Unit
	State     items.State
	Providers []unit.ProviderID
}

type Reader

type Reader interface {
	Load(ctx context.Context, units []unit.Unit) (map[unit.Unit][]items.Item, error)
	Query(ctx context.Context, q Query) ([]items.Item, error)
	Proposals(ctx context.Context, state ProposalState) ([]Proposal, error)
	Log(ctx context.Context, u unit.Unit, since time.Time) ([]LogEntry, error) // op outcomes, for history
}

Reader is the read half of Store.

type Reconciler

type Reconciler interface {
	Reconcile(ctx context.Context, u unit.Unit, desired []items.Item, at unit.Anchor, absent items.Resolution) (Result, error)
}

type Refused

type Refused struct {
	Index  int      `json:"index"` // position in the ops passed
	Op     items.Op `json:"op"`
	Reason string   `json:"reason"`
}

type Result

type Result struct {
	Applied  []Applied  `json:"applied"`
	Proposed []Proposal `json:"proposed"`
	Refused  []Refused  `json:"refused"`
}

type Store

type Store interface {
	Reader
	Commit(ctx context.Context, c Commit) error // items, op log, proposals in one transaction; notes TopicItems when anything but log rows changed
	SetProposal(ctx context.Context, id int64, state ProposalState) (Proposal, error)
}

Jump to

Keyboard shortcuts

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