Documentation
¶
Overview ¶
Package reposync diffs a local model's identity-carrying RDF graph against a repository-side graph of the same project scope, keyed by effective element id, so a rename or a move is an update to the existing element rather than a delete plus a create.
Index ¶
- Variables
- func MintUUID() (string, error)
- func StatePath(modelPath string) string
- func WriteBack(g *rdf.Graph, mints map[string]string) (*rdf.Graph, error)
- type ApplyError
- type ApplyOptions
- type Carrier
- type Change
- type ChangeSet
- type Committer
- type ConflictKind
- type ElementChange
- type Kind
- type NotAppliableError
- type Options
- type PropertyDelta
- type Result
- type Scope
- type State
- type UncarriedProperty
- type UnsupportedKindError
- type UnwritableChangeError
Constants ¶
This section is empty.
Variables ¶
var ErrIncompleteApply = errors.New("the apply did not complete, so the last-seen commit stays where it was")
ErrIncompleteApply refuses to advance the state past an apply that left changes unapplied: no single commit then describes what the branch holds.
var ErrTwoBranches = errors.New("one document cannot sync against two branches at once")
ErrTwoBranches reports elements of one document naming two branches at once: a branch selects one version, so one sync reads from exactly one.
var ErrUnnamedCommit = errors.New("the repository accepted the commit but did not name it")
ErrUnnamedCommit is a commit the repository accepted but did not name, so the sync state cannot advance to it.
Functions ¶
func MintUUID ¶
MintUUID returns a random RFC 4122 version 4 UUID, the id minted for an element that needs addressing but declares none.
func StatePath ¶
StatePath is the default state file for a model: its path with .sync.json appended, so two models beside each other keep separate sync state.
func WriteBack ¶
WriteBack rewrites a local graph so each minted element declares its minted id: subjects and references move to the minted IRI, satellites re-derive, and the declaredId marker is set so converting the graph back to notation re-materializes the @ElementId annotation. It never runs implicitly: the caller asked to write annotations back into the model. Each collection annotation is restated from its minted typed triples, so the two agree.
Types ¶
type ApplyError ¶
type ApplyError struct {
Batch int // 1-based index of the refused batch
Batches int
Result *Result
Err error
}
ApplyError reports a batch the repository refused, with the result so far: what did reach the repository is committed and stays there.
func (*ApplyError) Error ¶
func (e *ApplyError) Error() string
func (*ApplyError) Unwrap ¶
func (e *ApplyError) Unwrap() error
type ApplyOptions ¶
type ApplyOptions struct {
// BatchSize splits a set over several commits; 0 writes one commit.
BatchSize int
// Message is recorded on each commit.
Message string
}
ApplyOptions steer an apply.
type Carrier ¶
type Carrier interface {
// Carry maps a triple onto the form the repository stores: ok false when it
// has no place for the predicate, err when it cannot represent the value.
Carry(triple rdf.Triple) (carried rdf.Triple, ok bool, err error)
}
Carrier is what a repository can hold of a graph; both sides compare under it, so a successful apply leaves nothing to diff.
type Change ¶
type Change struct {
Kind Kind
ID string // effective id: the subject IRI's local name
Subject string // full subject IRI
QualifiedName string
Metaclass string
Declared bool // the id was declared by an @ElementId annotation
Normative bool // the id is the one the norm fixes for a standard-library element
MintedID string // UUID minted for an unannotated create, when minting is on
Deltas []PropertyDelta
Conflict ConflictKind
// RequiresConfirmation marks a delete the options did not confirm.
RequiresConfirmation bool
// Content is the element as the local graph states it, in the repository's
// representation: what a create or an update writes. Nil for a delete.
Content []rdf.Triple
}
Change is one entry of a change set, keyed by the subject's effective id.
type ChangeSet ¶
type ChangeSet struct {
Scope Scope
Changes []Change
Uncarried []UncarriedProperty
}
ChangeSet is what a diff produced for one project scope.
func Diff ¶
Diff compares the local graph against the repository graph of the same project scope and returns the change set keyed by effective element id.
func (*ChangeSet) Appliable ¶
Appliable reports whether the set can be applied as computed: conflicts and unconfirmed deletes refuse an apply, as a *NotAppliableError, until a person decides them.
func (*ChangeSet) Mints ¶
Mints returns the minted ids of a change set, keyed by the derived id each one replaces.
func (*ChangeSet) Text ¶
Text renders the change set for a dry run: one line per entry, deltas indented under updates and conflicts, and a closing summary.
func (*ChangeSet) UnconfirmedDeletes ¶
UnconfirmedDeletes counts the deletes the options did not confirm.
type Committer ¶
type Committer interface {
// Commit writes one batch as a single commit and returns the id the
// repository gave it. A refused batch must leave the branch as it was.
Commit(ctx context.Context, changes []ElementChange, message string) (string, error)
}
Committer is the write side of one live repository branch as an apply sees it: a fake in tests, the Flexo adapter for real.
type ConflictKind ¶
type ConflictKind string
ConflictKind says what a conflict entry disagrees about.
const ( // ConflictMissingID: the annotation names an id the repository branch no // longer has. ConflictMissingID ConflictKind = "missing-id" // ConflictRepositoryChanged: the repository element changed since the // last-seen commit, so writing over it would lose someone else's change. ConflictRepositoryChanged ConflictKind = "repository-changed" )
type ElementChange ¶
type ElementChange struct {
Kind Kind
ID string // id the repository addresses the element by, minted when one was
Content []rdf.Triple // subject, type and carried properties; nil for a delete
}
ElementChange is one element as the repository is to hold it after the commit: whole content for a create or update, nothing for a delete.
type Kind ¶
type Kind string
Kind classifies one entry of a change set.
const ( // KindCreate is an element the repository does not have yet. KindCreate Kind = "create" // KindUpdate is an element both sides have, with differing properties. KindUpdate Kind = "update" // KindDelete is an element only the repository has. Applying it needs // explicit confirmation; the diff reports it either way. KindDelete Kind = "delete" // KindConflict is a disagreement the sync must not resolve on its own. KindConflict Kind = "conflict" )
type NotAppliableError ¶
NotAppliableError refuses an apply: the set holds conflicts, unconfirmed deletes, or both, and a person has to decide them first.
func (*NotAppliableError) Error ¶
func (e *NotAppliableError) Error() string
type Options ¶
type Options struct {
// Base is the repository graph at the last-seen commit. With it, an element
// the repository changed since then surfaces as a conflict rather than
// being written over, and a declared id the branch never had is a create
// rather than a missing-id conflict.
Base *rdf.Graph
// ConfirmDeletes confirms repository-side deletes; off, the diff still
// reports them but Appliable refuses.
ConfirmDeletes bool
// MintIDs mints a UUID for each unannotated element being created, so the
// repository can address it stably.
MintIDs bool
// NewID overrides the UUID source, for deterministic tests.
NewID func() (string, error)
// Representation is the repository's; nil compares the graphs as written.
Representation Carrier
}
Options steer a diff. Deletes and id minting are explicit opt-ins; neither ever happens silently.
type PropertyDelta ¶
PropertyDelta is one property whose values differ between the two sides.
type Result ¶
Result is what an apply did: its commits, and the fate of each change. Failed changes were in a refused batch; Pending ones were never sent.
func Apply ¶
Apply pushes a change set to the repository. An unappliable set is refused before any write; a rejected batch is reported as an *ApplyError.
func (*Result) LastCommit ¶
LastCommit is the newest commit made, the one the sync state advances to.
type Scope ¶
Scope is the project a graph belongs to. Org and project identify it; branch selects the version being synced against, not a different identity space.
func GraphScope ¶
GraphScope reads a graph's provenance triples into the single scope it syncs under. Two projects or two branches in one graph is an error, never a guess.
type State ¶
type State struct {
Org string `json:"org,omitempty"`
ProjectID string `json:"projectId"`
Branch string `json:"branch,omitempty"`
LastSeenCommit string `json:"lastSeenCommit,omitempty"`
}
State is the sync tool's record of what a sync last saw. Commit ids are tool state, never model content: they live in this JSON file — <model>.sync.json beside the model by default — and are never written into the notation.
func LoadState ¶
LoadState reads a state file, returning nil without error when the file does not exist yet: a first sync has no last-seen commit.
func (*State) Advance ¶
Advance records a completed apply's last commit as last seen; an apply that wrote nothing leaves the state as it was.
type UncarriedProperty ¶
UncarriedProperty is a property of the local graph the repository has no place for: left out of the comparison, since no apply could ever settle it.
type UnsupportedKindError ¶
UnsupportedKindError is a change of a kind no repository write exists for, such as a conflict that slipped past Appliable.
func (*UnsupportedKindError) Error ¶
func (e *UnsupportedKindError) Error() string
type UnwritableChangeError ¶
UnwritableChangeError is a create or update the diff carried no content for, so there is nothing the repository could be asked to hold.
func (*UnwritableChangeError) Error ¶
func (e *UnwritableChangeError) Error() string