typestore

package
v0.19.0 Latest Latest
Warning

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

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

Documentation

Overview

Package typestore runs the type store's steps over the statements any database engine lends it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldsByGroup

func FieldsByGroup(declared []FieldRow) map[int][]content.Field

FieldsByGroup returns the stored field rows as trees, keyed by the group holding them.

func GroupFromRow

func GroupFromRow(engine dbkit.Engine, row GroupRow) (content.Group, error)

GroupFromRow returns the group a stored row holds, naming the engine when its location does not read.

func Serves

func Serves(g content.Group, typeKey string) bool

Serves reports whether the group is active and its location matches the type.

Types

type Backend

type Backend struct {
	Engine    dbkit.Engine
	Pool      Queries
	InTx      Transactor
	Rules     []Rule
	ReadError func(err error) (code, name string, found bool)
}

Backend holds what one database engine lends the type store.

type Constraint

type Constraint int

Constraint names a stored rule a statement broke, whatever the engine calls that rule.

const (
	NoConstraint Constraint = iota
	GroupKeyUnique
	FieldKeyUnique
	FieldTargetExists
	FieldGroupExists
	TypeKeyUnique
	RouteWordUnique
	TypeHeldByContent
	ContentPathUnique
)

The stored rules the steps tell apart.

type FieldQueries

type FieldQueries interface {
	ListContentFields(ctx context.Context) ([]FieldRow, error)
	FieldByID(ctx context.Context, id int) (FieldRow, error)
	CreateContentField(ctx context.Context, f FieldRow) (FieldRow, error)
	CreateSubContentField(ctx context.Context, f FieldRow) (FieldRow, error)
	UpdateContentField(ctx context.Context, f FieldRow, expected time.Time) (FieldRow, error)
	UpdateSubContentField(ctx context.Context, f FieldRow, expected time.Time) (FieldRow, error)
	ReorderContentFields(ctx context.Context, groupID int, keys []string) (int64, error)
	ReorderSubContentFields(ctx context.Context, parentID int, keys []string) (int64, error)
	ReparentContentField(ctx context.Context, id, toGroup, toParent int, at time.Time) (FieldRow, error)
	RecountContentFieldDepth(ctx context.Context, id, toGroup, depth int) error
	DeleteContentField(ctx context.Context, groupID int, key string) (int64, error)
	DeleteFieldByID(ctx context.Context, id int) (int64, error)
	ClearContentFieldValues(ctx context.Context, key string, types []string) error
	ClearRevisionFieldValues(ctx context.Context, key string, types []string) error
	StripContentFieldPath(ctx context.Context, s Strip) error
	StripRevisionFieldPath(ctx context.Context, s Strip) error
	StripContentLayout(ctx context.Context, s Strip) error
	StripRevisionLayout(ctx context.Context, s Strip) error
	DeleteRelationsOfFields(ctx context.Context, types []string, fields []int) error
}

FieldQueries sends the statements that read, write and sweep field definitions.

type FieldRow

type FieldRow struct {
	ID, GroupID, ParentID, Depth        int
	Key, Label, Kind, RelatesTo, Origin string
	Many, Required                      bool
	Settings                            []byte
	CreatedAt, UpdatedAt                time.Time
}

FieldRow is one stored field definition with its depth, its settings still encoded as JSON.

type GroupQueries

type GroupQueries interface {
	LockFieldGroups(ctx context.Context) error
	ListFieldGroups(ctx context.Context) ([]GroupRow, error)
	FieldGroupKeys(ctx context.Context) ([]string, error)
	CreateFieldGroup(ctx context.Context, g GroupRow) (GroupRow, error)
	UpdateFieldGroup(ctx context.Context, g GroupRow) (GroupRow, error)
	ReorderFieldGroups(ctx context.Context, ids []int) error
	CarryStrayFieldsOfGroup(ctx context.Context, groupID int) error
	DeleteFieldGroup(ctx context.Context, id int) (int64, error)
	AdoptFieldGroup(ctx context.Context, key string, at time.Time) (int64, error)
	AdoptFieldsInGroup(ctx context.Context, key string, at time.Time) error
}

GroupQueries sends the statements that read and write field groups.

type GroupRow

type GroupRow struct {
	ID, Position         int
	Key, Title, Origin   string
	Location             []byte
	Active               bool
	CreatedAt, UpdatedAt time.Time
}

GroupRow is one stored field group, its location still encoded as JSON.

type Queries

type Queries interface {
	TypeQueries
	GroupQueries
	FieldQueries
}

Queries sends every statement the type store is built from, one call per statement.

type Rule

type Rule struct {
	Code, Name string
	Broken     Constraint
}

Rule names the stored rule an engine's error code and rule name stand for, an empty one matching any.

type Store

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

Store keeps the content type registry and its field groups through one backend.

func New

func New(backend Backend) *Store

New returns a Store that runs its steps on the backend.

func (*Store) AdoptGroup

func (s *Store) AdoptGroup(ctx context.Context, key string) error

AdoptGroup clears the plugin origin from the group and every field inside it, or reports the site holding none.

func (*Store) AdoptType

func (s *Store) AdoptType(ctx context.Context, key string) error

AdoptType clears the plugin origin from the type, or reports the site holding none under the key.

func (*Store) ByKey

func (s *Store) ByKey(ctx context.Context, key string) (content.Type, error)

ByKey returns the type carrying the key with its flattened fields, or content.ErrTypeNotFound.

func (*Store) Create

func (s *Store) Create(ctx context.Context, t content.Type) (content.Type, error)

Create stores a new content type, or reports the key or route word already in use.

func (*Store) CreateFieldInGroup

func (s *Store) CreateFieldInGroup(
	ctx context.Context, groupID int, f content.Field, recheck content.Recheck,
) (content.Field, error)

CreateFieldInGroup declares the field inside the group.

func (*Store) CreateGroup

func (s *Store) CreateGroup(ctx context.Context, g content.Group) (content.Group, error)

CreateGroup stores a new field group at the end of the order.

func (*Store) CreateSubField

func (s *Store) CreateSubField(
	ctx context.Context, parentID int, f content.Field, limit int,
) (content.Field, error)

CreateSubField declares the field inside the container the parent names, within the limit.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete removes the type, or reports it missing or still in use.

func (*Store) DeleteFieldInGroup

func (s *Store) DeleteFieldInGroup(ctx context.Context, groupID int, key string, recheck content.Recheck) error

DeleteFieldInGroup removes the field, sweeping its values as a group delete does.

func (*Store) DeleteFieldsOfGroup

func (s *Store) DeleteFieldsOfGroup(
	ctx context.Context, groupID int, keys []string, recheck content.Recheck,
) error

DeleteFieldsOfGroup removes the group's named top level fields, sweeping their values as a group delete does.

func (*Store) DeleteGroup

func (s *Store) DeleteGroup(ctx context.Context, id int, recheck content.Recheck) error

DeleteGroup removes the group, its fields and their stored values in one transaction, once the check passes.

func (*Store) DeleteSubField

func (s *Store) DeleteSubField(ctx context.Context, id int, recheck content.Recheck) error

DeleteSubField removes the sub field, and its values where no other active group serves its path.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]content.Type, error)

List returns every registered type in registration order with its flattened fields attached.

func (*Store) ListGroups

func (s *Store) ListGroups(ctx context.Context) ([]content.Group, error)

ListGroups returns every field group in position order with its fields attached.

func (*Store) MoveField

func (s *Store) MoveField(
	ctx context.Context, id, toGroup, toParent, limit int, recheck content.Recheck,
) (content.Field, error)

MoveField carries the field to a group's top or into a container within the limit, sweeping what it leaves.

func (*Store) Nested

func (s *Store) Nested(ctx context.Context, key string) (int, error)

Nested returns how many items of the type sit inside another, the ones in the trash included.

func (*Store) ReorderFieldsInGroup

func (s *Store) ReorderFieldsInGroup(ctx context.Context, groupID int, keys []string) error

ReorderFieldsInGroup stores the declaration order of a group's fields.

func (*Store) ReorderGroups

func (s *Store) ReorderGroups(ctx context.Context, ids []int) error

ReorderGroups stores the given order on the groups.

func (*Store) ReorderSubFields

func (s *Store) ReorderSubFields(ctx context.Context, parentID int, keys []string) error

ReorderSubFields stands the sub fields of the container in the order the keys name.

func (*Store) Update

func (s *Store) Update(ctx context.Context, t content.Type) (content.Type, error)

Update stores the type's edits and carries its content to the route word, or reports content.ErrTypeNotFound.

func (*Store) UpdateFieldInGroup

func (s *Store) UpdateFieldInGroup(
	ctx context.Context, groupID int, f content.Field, expectedUpdatedAt time.Time, recheck content.Recheck,
) (content.Field, error)

UpdateFieldInGroup stores the field's label, required flag and settings when the expectation and the check hold.

func (*Store) UpdateGroup

func (s *Store) UpdateGroup(
	ctx context.Context, g content.Group, repointed []content.Field, recheck content.Recheck,
) (content.Group, error)

UpdateGroup stores the group's title, location and active flag with the settings of the fields it points anew.

func (*Store) UpdateSubField

func (s *Store) UpdateSubField(
	ctx context.Context, id int, f content.Field, expectedUpdatedAt time.Time,
) (content.Field, error)

UpdateSubField carries the edit onto the sub field the identity names.

type Strip

type Strip struct {
	Key         string
	Path, Types []string
}

Strip names a path to remove from the stored values of the swept types.

type Transactor

type Transactor func(ctx context.Context, write func(Queries) error) error

Transactor runs write on statements bound to one transaction, committing when write returns nil.

type TypeQueries

type TypeQueries interface {
	ListContentTypes(ctx context.Context) ([]TypeRow, error)
	GetContentType(ctx context.Context, key string) (TypeRow, error)
	CreateContentType(ctx context.Context, t TypeRow) (TypeRow, error)
	LockContentType(ctx context.Context, key string) (TypeRow, error)
	LockDefaultContentType(ctx context.Context) (TypeRow, error)
	UpdateContentType(ctx context.Context, t TypeRow) (TypeRow, error)
	DeferAddressCheck(ctx context.Context) error
	RetypeContentPaths(ctx context.Context, t TypeRow, was string) error
	CountNestedContent(ctx context.Context, key string) (int64, error)
	DeleteContentType(ctx context.Context, key string) (int64, error)
	AdoptContentType(ctx context.Context, key string, at time.Time) (int64, error)
	TypeKeys(ctx context.Context) ([]string, error)
}

TypeQueries sends the statements that read and write content types.

type TypeRow

type TypeRow struct {
	Key, SingularLabel, PluralLabel, Description, RouteWord, PageKind, Origin string
	Hierarchical, Revisions, IsDefault, Active                                bool
	RevisionCap                                                               int
	CreatedAt, UpdatedAt                                                      time.Time
}

TypeRow is one stored content type as every engine reads and writes it.

Jump to

Keyboard shortcuts

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