Documentation
¶
Overview ¶
Package blockgraph describes where a resolved schema places its block definitions. Migration planning compares each definition once and applies a change inside a definition at every placement of it; stored-value rewrites find every occurrence of a definition by walking stored values guided by the graph. Both therefore cost in proportion to definitions and stored data, never to the number of paths through the block graph.
Index ¶
- func EmbeddedPlacements(graph *Graph) map[Key]bool
- func Shared(before, after *Graph, mapping map[schema.StableID]schema.StableID, ...) map[Key]bool
- type Graph
- func (graph *Graph) Closure(keys []Key, embedded bool) map[Key]bool
- func (graph *Graph) Containing(slugs map[string]bool) map[string]bool
- func (graph *Graph) Depths() map[string]int
- func (graph *Graph) Keys() []Key
- func (graph *Graph) Resource(id schema.StableID, global bool) (Resource, bool)
- func (graph *Graph) ResourceOf(resource schema.Collection) (Resource, bool)
- func (graph *Graph) Resources() []Resource
- func (graph *Graph) RootPlaces(root Root, slugs map[string]bool) bool
- func (graph *Graph) Selects(key Key, embedded bool) []Key
- func (graph *Graph) View(key Key) (schema.BlockType, bool)
- func (graph *Graph) Walker(targets map[string]bool) *Walker
- type Key
- type Pair
- type Resource
- type Root
- type Row
- type Walker
- func (walker *Walker) Holds(fields []schema.Field) bool
- func (walker *Walker) Rewrite(fields []schema.Field, values store.Values, locale schema.LocaleCode, ...) (store.Values, bool, error)
- func (walker *Walker) RewriteField(field schema.Field, value store.Value, locale schema.LocaleCode, ...) (store.Value, bool, error)
- func (walker *Walker) Visit(fields []schema.Field, values func(string) (store.Value, bool), ...) error
- func (walker *Walker) VisitField(field schema.Field, value store.Value, locale schema.LocaleCode, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EmbeddedPlacements ¶
EmbeddedPlacements returns the views a graph places inside embedded plugin payloads: those an embedded case selects, and every view beneath them.
func Shared ¶
func Shared(before, after *Graph, mapping map[schema.StableID]schema.StableID, embedded bool) map[Key]bool
Shared returns the views both graphs place ordinarily, or also embedded, beneath a resource that survives the change: only there can blocks stored before the change remain stored after it. mapping renames collection IDs.
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph records the definition views one schema snapshot places and the views each resource field and each view selects. Ordinary selections are Blocks containers, which store blocks as ordinary aggregate values; embedded selections are plugin embedded-tree cases, whose payloads the plugin owns.
func New ¶
New builds the graph of a snapshot. It visits every resource field and every placed definition view once.
func (*Graph) Closure ¶
Closure returns the views reachable from keys, including keys themselves: through ordinary containers only, or also through embedded cases. The result is shared and must not be changed.
func (*Graph) Containing ¶
Containing returns the slugs of the definitions that ordinarily place, at any depth, a definition whose slug is in slugs, together with slugs. A walk of stored values looking for blocks of slugs descends only into these.
func (*Graph) Depths ¶
Depths returns, for each placed definition, the length of the longest chain of definitions placing it, ordinarily or embedded: 0 for a definition only resources place. A definition is deeper than every definition placing it, so ordering by depth visits a container's definition before its contents.
func (*Graph) ResourceOf ¶
func (graph *Graph) ResourceOf(resource schema.Collection) (Resource, bool)
ResourceOf returns the graph's node of a resource of its snapshot.
func (*Graph) RootPlaces ¶
RootPlaces reports whether a root's subtree ordinarily places a definition whose slug is in slugs.
type Key ¶
Key identifies one definition view: a definition and whether its placements lie beneath a localized ancestor. Such an ancestor stores the whole block once per locale, so the view clears the localization of the block's own fields. Every placement of a definition shares one of its two views.
func FieldSelections ¶
FieldSelections lists the views field and its own nested fields select directly, ordinary and embedded, without entering those views. localized reports a localized ancestor of field.
func SortedKeys ¶
SortedKeys returns a key set in key order.
type Pair ¶
Pair is one resource before and after a change.
type Resource ¶
type Resource struct {
Resource schema.Collection
Global bool
Roots []Root
}
Resource is one collection or global and the views its fields select.
type Root ¶
Root is one top-level field of a resource and the views its own subtree selects directly, without entering those views' fields.
type Row ¶
type Row struct {
// Block is the definition view the row's placement shares.
Block schema.BlockType
// Locale is the translation of a localized ancestor that holds the row,
// or empty when no ancestor is localized.
Locale schema.LocaleCode
}
Row is one stored row of a chosen definition.
type Walker ¶
type Walker struct {
// contains filtered or unexported fields
}
Walker finds the stored rows of chosen definitions in stored values. It follows the schema through groups, arrays and Blocks containers, reading each row's blockType to enter its definition view, and enters only the containers whose definitions can hold a chosen row, so its cost follows the stored values it reads. Plugin values are opaque and never entered.
func (*Walker) Rewrite ¶
func (walker *Walker) Rewrite(fields []schema.Field, values store.Values, locale schema.LocaleCode, rewrite func(Row, store.Values) (bool, error)) (store.Values, bool, error)
Rewrite calls rewrite for every chosen row stored in values of fields, before the rows nested in it, which it then finds through the row as rewritten. rewrite may change its private copy of the row and reports whether it did. Rewrite returns values with every changed row, copying only the containers that hold one; values itself is never changed.
func (*Walker) RewriteField ¶
func (walker *Walker) RewriteField(field schema.Field, value store.Value, locale schema.LocaleCode, rewrite func(Row, store.Values) (bool, error)) (store.Value, bool, error)
RewriteField is Rewrite for one field's stored value.
func (*Walker) Visit ¶
func (walker *Walker) Visit(fields []schema.Field, values func(string) (store.Value, bool), locale schema.LocaleCode, visit func(Row, store.Value) error) error
Visit calls visit for every chosen row stored in values of fields, before the rows nested in it. locale is the translation values belong to, or empty.