pagepath

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResolveKindIndex    = "index_out_of_range"
	ResolveKindEditable = "editable_not_found"
	ResolveKindPage     = "page_editable_not_found"
	ResolveKindSlug     = "ambiguous_slug"
	ResolveKindID       = "repeatable_id_not_found"
	ResolveKindDepth    = "depth_exceeded"
)

ResolveError kinds used in CLI JSON details.

View Source
const (
	SelIndex = iota
	SelID
	SelSlug
)

Selector kinds.

View Source
const (
	AnchorOmit = iota
	AnchorNull
	AnchorID
	AnchorNoop
)

Anchor modes distinguish omit / JSON null / id / no-op.

Variables

View Source
var ErrAnchorNoop = errors.New("move is a no-op")

ErrAnchorNoop is returned by AnchorForMove when the item is already at target.

Functions

func EscapeName

func EscapeName(name string) string

EscapeName encodes an editable name for a raw API path. It uses url.PathEscape (%20 for spaces, never +) so Rails CGI.unescape round-trips names including spaces and en-dashes.

func IsPageField added in v0.3.2

func IsPageField(name string) bool

IsPageField reports whether name is a top-level page field. A single-segment human path with this name always parses as the page field, never as an editable, so callers that build paths must fall back to the raw path when an editable name collides with one.

func ParseAnchor

func ParseAnchor(s string, siblings []RepeatableRef) (string, error)

ParseAnchor resolves a 24-hex id or integer index to a sibling id.

func UnescapeName

func UnescapeName(name string) (string, error)

UnescapeName decodes a raw-path name segment.

Types

type Anchor

type Anchor struct {
	Mode int
	ID   string
}

Anchor is a tri-state insert/move cursor.

func AnchorForInsert

func AnchorForInsert(siblings []RepeatableRef, position int) (Anchor, error)

AnchorForInsert returns the batch `after` value for inserting at a 0-based index. 0 → explicit null (beginning); N → id of sibling N-1; N > len → omit (append).

func AnchorForMove

func AnchorForMove(siblings []RepeatableRef, currentIndex, targetIndex int) (Anchor, error)

AnchorForMove returns the batch `after` value for moving currentIndex to targetIndex.

type BlockDef

type BlockDef struct {
	Slug            string                `json:"slug"`
	Label           string                `json:"label"`
	Fields          []FieldDef            `json:"fields"`
	AvailableBlocks map[string][]BlockDef `json:"available_blocks,omitempty"`
}

BlockDef is one available repeatable slug for a canvas.

type FieldDef

type FieldDef struct {
	Slug            string       `json:"slug"`
	Label           string       `json:"label"`
	Type            string       `json:"type"`
	Options         []Option     `json:"options"`
	Reference       string       `json:"reference"`
	AvailableBlocks NestedBlocks `json:"available_blocks,omitempty"`
}

FieldDef is one editable inside a block definition.

type Kind

type Kind string

Kind classifies a resolved path.

const (
	KindField      Kind = "field"
	KindItem       Kind = "item"
	KindCanvas     Kind = "canvas"
	KindRepeatable Kind = "repeatable"
)

type NestedBlocks

type NestedBlocks []BlockDef

NestedBlocks is available_blocks on a canvas field: a live array, or a keyed object.

func (*NestedBlocks) UnmarshalJSON

func (n *NestedBlocks) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts both `[{block}, ...]` and `{"CanvasName":[{block}, ...]}`.

type Option

type Option struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

Option is a select/radio choice.

type ParseError

type ParseError struct {
	Input   string
	Message string
}

ParseError is a structured failure while parsing a human or raw page path.

func (*ParseError) Error

func (e *ParseError) Error() string

type Path

type Path struct {
	Raw      string
	Field    string
	Segments []Segment
}

Path is a parsed human or raw page path.

func Parse

func Parse(input string) (Path, error)

Parse parses a human path or a slash-prefixed raw API path.

func (Path) String

func (p Path) String() string

String renders the canonical human form, quoting names that need it.

type RepeatableRef

type RepeatableRef struct {
	ID    string
	Slug  string
	Index int
}

RepeatableRef is one repeatable in position order.

type ResolveError

type ResolveError struct {
	Path       string
	Kind       string
	Candidates []string
	// contains filtered or unexported fields
}

ResolveError lists candidates so an agent can correct a path in one step.

func (*ResolveError) Error

func (e *ResolveError) Error() string

type Resolved

type Resolved struct {
	RawPath         string
	Kind            Kind
	Type            string
	RepeatableID    string
	RepeatableSlug  string
	Index           int
	ParentCanvasRaw string
	Siblings        []RepeatableRef
	Value           any
}

Resolved is a human path mapped onto a page document.

func Resolve

func Resolve(p Path, page map[string]any, schema *Schema) (Resolved, error)

Resolve walks p against the page document. schema may be nil.

type Schema

type Schema struct {
	Template         Template
	AvailableBlocks  map[string][]BlockDef
	SelectOptions    map[string][]Option
	CurrentStructure json.RawMessage
	// contains filtered or unexported fields
}

Schema mirrors GET /pages/{id}/schema.

func (*Schema) BlockSlugs

func (s *Schema) BlockSlugs(canvas string) []string

BlockSlugs returns available repeatable slugs for a top-level canvas, in schema order.

func (*Schema) BlockSlugsFor

func (s *Schema) BlockSlugsFor(canvas, parentSlug string) []string

BlockSlugsFor returns available slugs for a canvas, optionally nested under parentSlug.

func (*Schema) Blocks

func (s *Schema) Blocks(canvas string) []BlockDef

Blocks returns available block definitions for a top-level canvas, in schema order.

func (*Schema) BlocksFor

func (s *Schema) BlocksFor(canvas, parentSlug string) []BlockDef

BlocksFor returns block definitions for a canvas. parentSlug selects a nested canvas on that parent repeatable (live available_blocks on the canvas field).

func (*Schema) FieldType

func (s *Schema) FieldType(canvas, slug, field string) string

FieldType returns the schema type for a field inside a block, or "".

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

MarshalJSON returns the original API body when it was captured.

func (*Schema) OptionsFor

func (s *Schema) OptionsFor(canvas, repeatableSlug, field string) []Option

OptionsFor returns select options for a field. Top-level fields use canvas="" and repeatableSlug="".

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts the real object-shaped schema and the empty/array stubs.

type Segment

type Segment struct {
	Name     string
	Selector *Selector
}

Segment is one dotted path component, optionally with a selector.

type Selector

type Selector struct {
	Kind  int
	Index int
	ID    string
	Slug  string
}

Selector picks a repeatable by index, id, or slug.

type Template

type Template struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Template identifies the page template.

Jump to

Keyboard shortcuts

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