definitions

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package definitions carries the content definitions a plugin declares into the registry.

Index

Constants

View Source
const (
	ActionCreate = "create"
	ActionUpdate = "update"
	ActionDelete = "delete"
)

The actions a planned change stands for.

View Source
const (
	SubjectType  = "type"
	SubjectGroup = "group"
	SubjectField = "field"
)

The definitions a planned change stands over.

View Source
const (
	ReasonRemoved      = "removed"
	ReasonKindChanged  = "kind_changed"
	ReasonShapeChanged = "shape_changed"
	ReasonMoved        = "moved"
)

The reasons a planned change takes a definition away.

View Source
const (
	WarningRootMoved        = "root_moved"
	WarningRouteWordChanged = "route_word_changed"
)

The changes an import reaches beyond the definitions to make.

View Source
const Format = "1.0.0"

Format is the version of the definitions envelope this build writes.

View Source
const ReasonRootKept = "root_kept"

ReasonRootKept names the root an import left where the site already had it.

Variables

View Source
var ErrFormatUnreadable = errors.New("definitions: the format marker is not a plain version")

ErrFormatUnreadable reports an envelope whose format marker is not three plain numbers.

View Source
var ErrFormatUnsupported = errors.New("definitions: the format is not one this release reads")

ErrFormatUnsupported reports an envelope written under a format this release does not read.

View Source
var ErrKindChanged = errors.New("definitions: the kind of a declared field cannot change")

ErrKindChanged reports a plugin declaring a field under a kind other than the stored one.

View Source
var ErrRouteWordChanged = errors.New("definitions: the route word of a declared type cannot change")

ErrRouteWordChanged reports a plugin declaring a type under a route word other than the stored one.

View Source
var ErrShapeChanged = errors.New("definitions: the shape of a declared field cannot change")

ErrShapeChanged reports a plugin declaring a field whose relation target or cardinality is not the stored one.

View Source
var ErrSubjectUnknown = errors.New("definitions: no definition answers to that subject")

ErrSubjectUnknown reports a definition named as something the site does not hold.

Functions

func Adopt

func Adopt(ctx context.Context, registry *content.Registry, held Held) error

Adopt takes the definition the naming points at over as the site's own.

func ReadableFormat

func ReadableFormat(declared string) error

ReadableFormat returns the reason the declared format cannot be read, or nothing when it can.

Types

type Change

type Change struct {
	Action  string `json:"action"`
	Subject string `json:"subject"`
	Key     string `json:"key"`
	Group   string `json:"group,omitempty"`
	Label   string `json:"label"`
	Reason  string `json:"reason,omitempty"`
}

Change is one definition an import would add, carry over, or take away.

type Confirmed

type Confirmed struct {
	Subject string `json:"subject"`
	Key     string `json:"key"`
	Group   string `json:"group,omitempty"`
}

Confirmed names one change an import may take away.

type Drift

type Drift struct {
	Orphans    []Stray `json:"orphans"`
	Collisions []Stray `json:"collisions"`
}

Drift is what the site holds that no plugin declares, and what a plugin declares that the site holds.

func Adrift

func Adrift(ctx context.Context, registry *content.Registry, walked Walked) (Drift, error)

Adrift returns the definitions standing apart from what the plugins declared at the last boot.

type Envelope

type Envelope struct {
	Format string            `json:"format"`
	Types  []TypeDefinition  `json:"types"`
	Groups []GroupDefinition `json:"groups"`
}

Envelope is the site's own content definitions as the admin downloads them.

func Export

func Export(ctx context.Context, registry *content.Registry) (Envelope, error)

Export returns the envelope holding every definition the site owns, plugin declared rows left out.

type FieldDefinition

type FieldDefinition struct {
	Key       string            `json:"key"`
	Label     string            `json:"label"`
	Kind      string            `json:"kind"`
	RelatesTo string            `json:"relates_to,omitempty"`
	Many      bool              `json:"many"`
	Required  bool              `json:"required"`
	Settings  map[string]any    `json:"settings,omitempty"`
	Fields    []FieldDefinition `json:"fields,omitempty"`
}

FieldDefinition is one field as the envelope carries it, its sub fields in stored order.

type GroupDefinition

type GroupDefinition struct {
	Key      string            `json:"key"`
	Title    string            `json:"title"`
	Location content.Rules     `json:"location"`
	Active   bool              `json:"active"`
	Fields   []FieldDefinition `json:"fields"`
}

GroupDefinition is one field group as the envelope carries it, its fields in stored order.

type Held

type Held struct {
	Subject string `json:"subject"`
	Key     string `json:"key"`
}

Held is one definition named by what it is and the key it stands under.

type Import

type Import struct {
	Envelope
	Confirm []Confirmed `json:"confirm"`
}

Import is a definitions file with the changes the admin agreed to have taken away.

type Outcome

type Outcome struct {
	Applied []Change `json:"applied"`
	Skipped []Change `json:"skipped"`
}

Outcome is what an import did and what it left standing.

func Apply

func Apply(ctx context.Context, registry *content.Registry, asked Import) (Outcome, error)

Apply performs what the envelope changes, taking away only what the confirmations name.

type Plan

type Plan struct {
	Changes  []Change  `json:"changes"`
	Warnings []Warning `json:"warnings"`
}

Plan is what an import would change about the site's definitions, with nothing applied.

func Compare

func Compare(ctx context.Context, registry *content.Registry, envelope Envelope) (Plan, error)

Compare returns what the envelope would change about the site's definitions, writing nothing.

type Registrar

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

Registrar carries one plugin's declarations into the content registry, skipping what the site already holds.

func New

func New(registry *content.Registry, origin string) *Registrar

New returns a Registrar declaring on behalf of the plugin named by origin.

func (*Registrar) DeclareField

func (r *Registrar) DeclareField(ctx context.Context, groupKey string, declared sdk.FieldDeclaration) error

DeclareField stores the field inside the plugin's group carrying the key, or carries changes onto a stored one.

func (*Registrar) DeclareGroup

func (r *Registrar) DeclareGroup(ctx context.Context, declared sdk.GroupDeclaration) error

DeclareGroup stores the group with its fields, carries changes onto a stored one, or skips a key it does not own.

func (*Registrar) DeclareType

func (r *Registrar) DeclareType(ctx context.Context, declared sdk.TypeDeclaration) error

DeclareType stores the type, carries its labels onto a stored one, or skips a key the plugin does not own.

func (*Registrar) Declared

func (r *Registrar) Declared() []Held

Declared returns the definitions the plugin declared and holds, in declaration order.

func (*Registrar) Skipped

func (r *Registrar) Skipped() []Held

Skipped returns the definitions the plugin declared that another owner already held, in declaration order.

type Stray

type Stray struct {
	Subject string `json:"subject"`
	Key     string `json:"key"`
	Origin  string `json:"origin"`
	Label   string `json:"label"`
}

Stray is one definition standing apart from what the plugins declare.

type TypeDefinition

type TypeDefinition struct {
	Key           string `json:"key"`
	SingularLabel string `json:"singular_label"`
	PluralLabel   string `json:"plural_label"`
	RouteWord     string `json:"route_word"`
	Hierarchical  bool   `json:"hierarchical"`
	Revisions     bool   `json:"revisions"`
	RevisionCap   int    `json:"revision_cap"`
	PageKind      string `json:"page_kind"`
	Default       bool   `json:"default"`
	Active        bool   `json:"active"`
}

TypeDefinition is one content type as the envelope carries it.

type Walk

type Walk struct {
	Declared []Held
	Skipped  []Held
}

Walk is what one plugin declared at a boot and what another owner already held.

type Walked

type Walked map[string]Walk

Walked is what every plugin declared at a boot, by the plugin that declared it.

type Warning

type Warning struct {
	Code string `json:"code"`
	Key  string `json:"key"`
}

Warning is what an import would change beyond the definitions themselves.

Jump to

Keyboard shortcuts

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