contentstore

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package contentstore runs the content store's steps over the statements any database engine lends it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorCount

type AuthorCount struct {
	AuthorID uuid.UUID
	Total    int64
}

AuthorCount is how many listed items one author wrote.

type Backend

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

Backend holds what one database engine lends the content store.

type ContentRow

type ContentRow struct {
	ID, AuthorID                                      uuid.UUID
	ParentID                                          *uuid.UUID
	Type, Status, Slug, Title, Content, Excerpt, Path string
	Fields                                            content.Values
	PublishedAt                                       *time.Time
	CreatedAt, UpdatedAt                              time.Time
}

ContentRow is one stored content item as every engine reads and writes it.

type DefinitionQueries

type DefinitionQueries interface {
	ListFieldGroups(ctx context.Context) ([]typestore.GroupRow, error)
	ListContentFields(ctx context.Context) ([]typestore.FieldRow, error)
}

DefinitionQueries sends the field definition reads a content write checks its values against.

type ItemQueries

type ItemQueries interface {
	CreateContent(ctx context.Context, c ContentRow) (ContentRow, error)
	GetContent(ctx context.Context, id uuid.UUID) (ContentRow, error)
	GetPublishedContentByPath(ctx context.Context, path string) (ContentRow, error)
	UpdateContent(ctx context.Context, c ContentRow, expected time.Time) (ContentRow, error)
	SiblingSlugTaken(ctx context.Context, s SiblingSlug) (bool, error)
	CountChildren(ctx context.Context, id uuid.UUID) (int64, error)
	ContentDepth(ctx context.Context, id uuid.UUID) (int64, error)
	ValuesOfContent(ctx context.Context, id uuid.UUID) (content.Values, error)
	TrashContent(ctx context.Context, id uuid.UUID, suffix string, at time.Time) (ContentRow, error)
	RestoreContent(ctx context.Context, id uuid.UUID, at time.Time) (ContentRow, error)
	RestoreContentKeepingSlug(ctx context.Context, id uuid.UUID, at time.Time) (ContentRow, error)
	DeleteContent(ctx context.Context, id uuid.UUID) (int64, error)
	DeleteTrash(ctx context.Context, typeKey string, author *uuid.UUID) (int64, error)
	CountTrash(ctx context.Context, typeKey string) (int64, error)
	CountContentByAuthor(ctx context.Context, typeKey string) ([]AuthorCount, error)
}

ItemQueries sends the statements that read and write one content item.

type ListQueries

type ListQueries interface {
	CountContent(ctx context.Context, n Narrowing) (int64, error)
	ListContent(ctx context.Context, p Page) ([]ListedRow, error)
	ListNestedContent(ctx context.Context, p Page) ([]ListedRow, error)
}

ListQueries sends the statements that count and page a narrowed listing.

type ListedRow

type ListedRow struct {
	ContentRow
	AuthorName, ParentTitle string
}

ListedRow is one listed item beside its author's name and its parent's title.

type LockQueries

type LockQueries interface {
	LockContent(ctx context.Context, id uuid.UUID) (ContentRow, error)
	LockTypeNesting(ctx context.Context, typeKey string) (bool, error)
	LockTypeForMove(ctx context.Context, typeKey string) (bool, error)
	LockAncestors(ctx context.Context, id uuid.UUID) error
	LockParent(ctx context.Context, id, child uuid.UUID) (ParentRow, error)
	LockDescendants(ctx context.Context, id uuid.UUID) error
	MoveDescendants(ctx context.Context, id uuid.UUID, path string, at time.Time) ([]string, error)
	LockDeclaredFieldKeys(ctx context.Context) ([]string, error)
	DeferAddressCheck(ctx context.Context) error
}

LockQueries sends the statements that hold rows, walk the tree and settle addresses.

type Narrowing

type Narrowing struct {
	Type, Search             string
	FieldFilter              []byte
	Statuses                 []string
	Authors, ExcludedAuthors []uuid.UUID
	Before, After            *time.Time
}

Narrowing holds what the list and count statements narrow by, its field terms already encoded as JSON.

type Page

type Page struct {
	Narrowing
	OrderBy, OrderDir string
	Limit, Offset     int
}

Page is one page of a narrowed listing in the order asked.

type ParentRow

type ParentRow struct {
	Status, Path string
	HoldsChild   bool
}

ParentRow is the parent an item files under, and whether the item already stands above it.

type Pointing

type Pointing struct {
	Target                 uuid.UUID
	FieldID, Limit, Offset int
}

Pointing is one page of the items pointing at a target through a field.

type Queries

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

type RelationQueries

type RelationQueries interface {
	TypesOfContent(ctx context.Context, ids []uuid.UUID) ([]TypedItem, error)
	ClearRelationsOfField(ctx context.Context, from uuid.UUID, fieldID int) error
	AddRelation(ctx context.Context, r RelationRow) error
	RefreshRelationVisibility(ctx context.Context, id uuid.UUID) error
	CountRelatedContent(ctx context.Context, target uuid.UUID) (int64, error)
	ListRelatedContent(ctx context.Context, target uuid.UUID, limit, offset int) ([]ContentRow, error)
	CountPointingAt(ctx context.Context, target uuid.UUID, fieldID int) (int64, error)
	PointingAt(ctx context.Context, p Pointing) ([]content.Pointer, error)
	SummariesOfTargets(ctx context.Context, ids []uuid.UUID) ([]content.Target, error)
}

RelationQueries sends the statements that check, index and read what relation fields point at.

type RelationRow

type RelationRow struct {
	FromID, ToID      uuid.UUID
	FieldID, Position int
}

RelationRow is one row of the index a relation field writes.

type RevisionQueries

type RevisionQueries interface {
	CreateRevision(ctx context.Context, r RevisionRow) error
	ListRevisions(ctx context.Context, contentID uuid.UUID) ([]RevisionRow, error)
	GetRevision(ctx context.Context, contentID, id uuid.UUID) (RevisionRow, error)
	DeleteRevision(ctx context.Context, contentID, id uuid.UUID) (int64, error)
	PruneRevisions(ctx context.Context, contentID uuid.UUID, keep int) error
	UpsertAutosave(ctx context.Context, r RevisionRow) (RevisionRow, error)
	GetAutosave(ctx context.Context, contentID, authorID uuid.UUID) (RevisionRow, error)
	DeleteAutosave(ctx context.Context, contentID, authorID uuid.UUID) error
	DeleteAutosavesOfContent(ctx context.Context, contentID uuid.UUID) error
}

RevisionQueries sends the statements that read and write revisions and autosaves.

type RevisionRow

type RevisionRow struct {
	ID, ContentID, AuthorID       uuid.UUID
	Kind, Title, Content, Excerpt string
	Fields                        content.Values
	CreatedAt                     time.Time
}

RevisionRow is one stored revision or autosave.

type SiblingSlug

type SiblingSlug struct {
	ID         uuid.UUID
	ParentID   *uuid.UUID
	Type, Slug string
}

SiblingSlug names the slug an item would carry beside its siblings.

type Store

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

Store keeps content items, their revisions and their relations through one backend.

func New

func New(backend Backend) *Store

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

func (*Store) Autosave

func (s *Store) Autosave(ctx context.Context, contentID, authorID uuid.UUID) (content.Revision, error)

Autosave returns the author's autosave of the item, or content.ErrRevisionNotFound.

func (*Store) ByID

func (s *Store) ByID(ctx context.Context, id uuid.UUID) (content.Content, error)

ByID returns the content item with the given id, or content.ErrNotFound.

func (*Store) Children

func (s *Store) Children(ctx context.Context, id uuid.UUID) (int, error)

Children returns how many items nest directly under the item.

func (*Store) CountsByAuthor

func (s *Store) CountsByAuthor(ctx context.Context, contentType string) (map[uuid.UUID]int, error)

CountsByAuthor returns how many published and private items of the type each author wrote.

func (*Store) Create

func (s *Store) Create(ctx context.Context, c content.Content) (content.Content, error)

Create stores a new content item, suffixing its slug until its address is free.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id uuid.UUID) error

Delete removes the content item, or reports content.ErrNotFound.

func (*Store) DeleteAutosave

func (s *Store) DeleteAutosave(ctx context.Context, contentID, authorID uuid.UUID) error

DeleteAutosave removes the author's autosave of the item.

func (*Store) DeleteRevision

func (s *Store) DeleteRevision(ctx context.Context, contentID, revisionID uuid.UUID) error

DeleteRevision removes the item's revision, reporting content.ErrRevisionNotFound or content.ErrTrashed.

func (*Store) Depth

func (s *Store) Depth(ctx context.Context, id uuid.UUID) (int, error)

Depth returns how many levels of content nest below the item.

func (*Store) EmptyTrash

func (s *Store) EmptyTrash(ctx context.Context, contentType string, author *uuid.UUID) (int, int, error)

EmptyTrash deletes the type's trash, only the author's when one is named, and counts what it deleted and left.

func (*Store) List

func (s *Store) List(ctx context.Context, f content.Filter) ([]content.ListedItem, int, error)

List returns the items matching the filter without content, with author names and parent titles, and their total.

func (*Store) PointingAt

func (s *Store) PointingAt(
	ctx context.Context, target uuid.UUID, field, page, perPage int,
) ([]content.Pointer, int, error)

PointingAt returns the published items pointing at the target through the field, and how many there are.

func (*Store) PublishedByPath

func (s *Store) PublishedByPath(ctx context.Context, path string) (content.Content, error)

PublishedByPath returns the published item at the address, or content.ErrNotFound.

func (*Store) RelatedTo

func (s *Store) RelatedTo(
	ctx context.Context, target uuid.UUID, page, perPage int,
) ([]content.Content, int, error)

RelatedTo returns the published content of active types pointing at the target, newest first.

func (*Store) Restore

func (s *Store) Restore(ctx context.Context, id uuid.UUID, updatedAt time.Time) (content.Content, error)

Restore returns a trashed item to draft under its original slug when free, and refuses one out of the trash.

func (*Store) RevisionByID

func (s *Store) RevisionByID(ctx context.Context, contentID, revisionID uuid.UUID) (content.Revision, error)

RevisionByID returns the item's revision, or content.ErrRevisionNotFound.

func (*Store) Revisions

func (s *Store) Revisions(ctx context.Context, contentID uuid.UUID) ([]content.Revision, error)

Revisions returns the item's revisions newest first, without their content.

func (*Store) SaveAutosave

func (s *Store) SaveAutosave(ctx context.Context, autosave content.Revision) (content.Revision, error)

SaveAutosave stores the author's autosave of the item, replacing any earlier one, unless the item is in the trash.

func (*Store) TargetsByIDs

func (s *Store) TargetsByIDs(ctx context.Context, ids []uuid.UUID) ([]content.Target, error)

TargetsByIDs returns the published items of active types the identities name.

func (*Store) Trash

func (s *Store) Trash(ctx context.Context, id uuid.UUID, updatedAt time.Time) (content.Content, error)

Trash marks the content item trashed, frees its address for reuse and drops its parked words.

func (*Store) Update

func (s *Store) Update(
	ctx context.Context, c content.Content, expectedUpdatedAt time.Time, snapshot *content.Revision,
	revisionCap int,
) (content.Content, error)

Update stores the item's editable fields and any snapshot, settling its address among its siblings.

type Transactor

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

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

type Tx

type Tx interface {
	Queries
	Savepoint(ctx context.Context, attempt func(Queries) error) error
}

Tx sends the statements of one write transaction and runs an attempt it can undo.

type TypedItem

type TypedItem struct {
	ID   uuid.UUID
	Type string
}

TypedItem is the type one item belongs to.

Jump to

Keyboard shortcuts

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