revisionops

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package revisionops holds the configuration store operations shared by the `store`/`migrate` CLI and the admin API: normalizing payloads, creating drafts, publishing, rolling back and diffing. Entry points parse arguments, check identity and format output; the rules (publishable checks, optimistic concurrency, audit) live here so both behave alike.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(fromName string, from []byte, toName string, to []byte) (string, error)

Diff returns a unified diff of two payloads in the current encoding, so revisions stored by an older encoder differ only where their content does.

func Normalize

func Normalize(cfg *config.Config) ([]byte, error)

Normalize applies the store rules to a loaded configuration and returns its payload in the deterministic encoding.

func RawDiff

func RawDiff(fromName string, from []byte, toName string, to []byte) (string, error)

RawDiff compares stored bytes as they are.

func Reencode

func Reencode(payload []byte) []byte

Reencode returns payload in the current encoding, or unchanged when it no longer decodes.

Types

type ConflictError

type ConflictError struct {
	Expected, Published int64
}

ConflictError reports that another revision was published after the one the caller based its work on. It wraps revision.ErrConflict.

func (*ConflictError) Error

func (e *ConflictError) Error() string

func (*ConflictError) Unwrap

func (e *ConflictError) Unwrap() error

type DraftRequest

type DraftRequest struct {
	Payload []byte
	// Parent is the revision the draft builds on; 0 means the published one.
	Parent          int64
	Author, Comment string
	// SkipIfPublished returns the published revision instead of a new draft
	// when the payload equals it.
	SkipIfPublished bool
}

DraftRequest creates a draft revision from a normalized payload.

type PublishRequest

type PublishRequest struct {
	ID int64
	// RestartRequired allows changes that apply only after a restart.
	RestartRequired bool
	// ExpectedPublished, when set, is the published revision the caller
	// based its work on; another one being published fails with
	// *ConflictError.
	ExpectedPublished *int64
	Author            string
}

PublishRequest publishes a draft.

type RollbackRequest

type RollbackRequest struct {
	// To is the revision to restore; 0 means the newest earlier published
	// content.
	To              int64
	RestartRequired bool
	Author, Comment string
}

RollbackRequest restores earlier published content as a new revision.

type RollbackResult

type RollbackResult struct {
	// Published is the new revision; From was published before it and
	// Target holds the restored content.
	Published    revision.Revision
	From, Target int64
}

RollbackResult describes a rollback.

type Service

type Service struct {
	Store revision.Store
	Via   string
}

Service runs revision operations on a store. Via names the entry point in audit records ("cli", "admin-api").

func (Service) Draft

func (s Service) Draft(ctx context.Context, req DraftRequest) (rev revision.Revision, unchanged bool, err error)

Draft stores a draft. unchanged reports that SkipIfPublished applied and rev is the published revision.

func (Service) Publish

func (s Service) Publish(ctx context.Context, req PublishRequest) (revision.Revision, error)

Publish checks and publishes a draft.

func (Service) Rollback

func (s Service) Rollback(ctx context.Context, req RollbackRequest) (RollbackResult, error)

Rollback checks and publishes the content of an earlier revision.

Jump to

Keyboard shortcuts

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