blockreferences

package
v0.18.0 Latest Latest
Warning

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

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

Documentation

Overview

Package blockreferences supplies paired inline/reference authoring fixtures.

Index

Constants

View Source
const (
	CardSlug = "registry-card"
	NoteSlug = "registry-note"
)

CardSlug and NoteSlug are the stored discriminators of Card and its nested note.

Variables

View Source
var Card = func() field.Block {
	access := func(c operation.Context) (bool, error) {
		tenant, _ := c.Root.String("tenant")
		visible, _ := c.Siblings.String("visibility")
		return tenant == "open" && visible == "visible", nil
	}
	return field.Block{Slug: CardSlug, TypeName: "RegistryCard", Labels: field.BlockLabels{Singular: "Card", Plural: "Cards"}, Fields: field.Fields{
		field.Text("visibility"),
		field.Text("secret").Access(field.Access{Read: access, Update: access}),
		field.Group("details", field.Fields{field.Text("caption")}),
		field.Blocks("children", field.Block{Slug: NoteSlug, TypeName: "RegistryNote", Labels: field.BlockLabels{Singular: "Note", Plural: "Notes"}, Fields: field.Fields{field.Text("text")}}),
		field.Text("controlled").Access(field.Access{Update: access}).Validate(
			func(_ operation.Context, value operation.Value[string]) ([]operation.Issue, error) {
				if text, _ := value.Get(); text == "invalid" {
					return []operation.Issue{{Code: "controlled_value", Message: "Choose a valid controlled value"}}, nil
				}
				return nil, nil
			},
		),
	}}
}()

Card is declared once, so the inline and registered forms of the fixture select the same definition: a slug names one definition per application, and callbacks are identical only when shared from one value. Its slug is distinct from the plain "card" blocks of other contracts that share the browser fixture.

Functions

func Config

func Config(references bool) ridu.Config

func CountBlocks added in v0.15.0

func CountBlocks(value store.Value, key string) int

CountBlocks counts the stored hero blocks beneath a value that hold key.

func LayeredConfig added in v0.15.0

func LayeredConfig(layers, width int) ridu.Config

LayeredConfig registers width leaf blocks and layers of width container blocks, each referencing every block of the layer below, used by a pages layout that references the top layer. Definitions grow linearly with layers while placements, the paths through the reference graph, grow exponentially: LayeredConfig(7, 3) has 24 definitions and about 62,000 field placements. Block processing that follows definitions stays small for it.

func PlacementsConfig added in v0.15.0

func PlacementsConfig(heading, label field.Node) ridu.Config

PlacementsConfig places one hero definition along eight paths: at the top of a layout, inside sections and cards at several depths, beneath a localized container, in a second collection and in a global, each with versions. heading and label become hero's heading and cta.label fields.

func RunDefinitionMigrations added in v0.15.0

func RunDefinitionMigrations(t *testing.T, harness MigrationHarness)

RunDefinitionMigrations renames a shared definition's field and makes one of its nested fields required, each as one definition-level change, and proves the migration reaches every stored block at every placement: in current documents, versions, a second collection and a global.

Types

type MigrationHarness added in v0.15.0

type MigrationHarness struct {
	// Begin applies the initial migration of before and returns the store.
	Begin func(t *testing.T, before schema.Manifest) store.Store
	// Migrate creates and applies a migration from the current head to
	// after, confirming candidates. A refused migration leaves no artifact.
	Migrate func(t *testing.T, after schema.Manifest, candidates []schemadiff.RenameCandidate) error
	// Rollback undoes the last applied migration; nil when the adapter
	// recovers forward instead.
	Rollback func(t *testing.T) error
}

MigrationHarness drives one adapter's immutable migrations for RunDefinitionMigrations. Each test starts from a fresh database.

type PlanningChange added in v0.15.0

type PlanningChange struct {
	Name   string
	Before ridu.Config
	After  ridu.Config
}

PlanningChange is a block-definition schema change that migration planning applies at every placement of the definitions it touches.

func PlanningChanges added in v0.15.0

func PlanningChanges(layers, width int) []PlanningChange

PlanningChanges returns the block-definition changes that cost tests plan on LayeredConfig(layers, width), whose placements grow exponentially with layers while its definitions grow linearly: a text field added to every block, a leaf's field renamed, a leaf's array field made required, and a new block with a relationship added to the lowest container layer.

Jump to

Keyboard shortcuts

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