Documentation ¶
Index ¶
- Variables
- func CopyEdgeProps(p graph.EdgeProperties) func(*graph.EdgeProperties)
- func CopyVertexProps(p graph.VertexProperties) func(*graph.VertexProperties)
- func DontSkipEdges(_ Edge) bool
- func GraphToDOT(g Graph, out io.Writer) error
- func GraphToSVG(g Graph, prefix string) error
- func Hash(g Graph) ([]byte, error)
- func Neighbors(g Graph, r ResourceId) (upstream, downstream set.Set[ResourceId], err error)
- func PropagateUpdatedId(g Graph, old ResourceId) error
- func RemoveResource(g Graph, id ResourceId) error
- func ReplaceResource(g Graph, oldId ResourceId, newRes *Resource) error
- func ResourceIdLess(a, b ResourceId) bool
- func String(g Graph) (string, error)
- func WalkGraph(g Graph, fn WalkGraphFunc) error
- func WalkGraphReverse(g Graph, fn WalkGraphFunc) error
- type Dependencies
- type Edge
- type EdgeData
- type Graph
- type GraphBatch
- type IdResolutionError
- type Output
- type Path
- type Properties
- type PropertyKVItem
- type PropertyPath
- type PropertyPathError
- type PropertyPathItem
- type PropertyRef
- func (v *PropertyRef) Equals(ref interface{}) bool
- func (v *PropertyRef) IsZero() bool
- func (v PropertyRef) MarshalText() ([]byte, error)
- func (v *PropertyRef) Parse(s string) error
- func (v PropertyRef) String() string
- func (v *PropertyRef) UnmarshalText(b []byte) error
- func (v *PropertyRef) Validate() error
- type Resource
- func (r *Resource) AppendProperty(pathStr string, value any) error
- func (r Resource) Equals(other any) bool
- func (r *Resource) GetProperty(pathStr string) (any, error)
- func (r *Resource) PropertyPath(pathStr string) (PropertyPath, error)
- func (r *Resource) RemoveProperty(pathStr string, value any) error
- func (r *Resource) SetProperty(pathStr string, value any) error
- func (r *Resource) WalkProperties(fn WalkPropertiesFunc) error
- type ResourceEdge
- type ResourceId
- func AllDownstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
- func AllUpstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
- func DirectDownstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
- func DirectUpstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
- func ResourceHasher(r *Resource) ResourceId
- func ReverseTopologicalSort[T any](g graph.Graph[ResourceId, T]) ([]ResourceId, error)
- func SelectIds(ids []ResourceId, selector ResourceId) []ResourceId
- func TopologicalSort[T any](g graph.Graph[ResourceId, T]) ([]ResourceId, error)
- func (id ResourceId) IsAbstractResource() bool
- func (id ResourceId) IsZero() bool
- func (id ResourceId) MarshalTOML() ([]byte, error)
- func (id ResourceId) MarshalText() ([]byte, error)
- func (id ResourceId) Matches(other ResourceId) bool
- func (id *ResourceId) Parse(s string) error
- func (id ResourceId) QualifiedTypeName() string
- func (id ResourceId) String() string
- func (id *ResourceId) UnmarshalTOML(data []byte) error
- func (id *ResourceId) UnmarshalText(data []byte) error
- func (id *ResourceId) Validate() error
- type ResourceIdChangeResults
- type ResourceList
- type ShortestPather
- type SimpleEdge
- func (e SimpleEdge) Less(other SimpleEdge) bool
- func (e SimpleEdge) MarshalText() (string, error)
- func (e *SimpleEdge) Parse(s string) error
- func (e SimpleEdge) String() string
- func (e SimpleEdge) ToEdge() Edge
- func (e *SimpleEdge) UnmarshalText(data []byte) error
- func (e *SimpleEdge) Validate() error
- type SortedIds
- type WalkGraphFunc
- type WalkPropertiesFunc
- type YamlGraph
Constants ¶
This section is empty.
Variables ¶
var SkipProperty = fmt.Errorf("skip property")
var StopWalk = errors.New("stop walking")
StopWalk is a special error that can be returned from WalkGraphFunc to stop walking the graph. The resulting error from WalkGraph will be whatever was previously passed into the walk function.
Functions ¶
func CopyEdgeProps ¶
func CopyEdgeProps(p graph.EdgeProperties) func(*graph.EdgeProperties)
func CopyVertexProps ¶
func CopyVertexProps(p graph.VertexProperties) func(*graph.VertexProperties)
func DontSkipEdges ¶
func GraphToSVG ¶
func Neighbors ¶
func Neighbors(g Graph, r ResourceId) (upstream, downstream set.Set[ResourceId], err error)
func PropagateUpdatedId ¶
func PropagateUpdatedId(g Graph, old ResourceId) error
UpdateResourceId is used when a resource's ID changes. It updates the graph in-place, using the resource currently referenced by `old`. No-op if the resource ID hasn't changed. Also updates any property references (as ResourceId or PropertyRef) of the old ID to the new ID in any resource that depends on or is depended on by the resource.
func RemoveResource ¶
func RemoveResource(g Graph, id ResourceId) error
RemoveResource removes all edges from the resource. any property references (as ResourceId or PropertyRef) to the resource, and finally the resource itself.
func ReplaceResource ¶
func ReplaceResource(g Graph, oldId ResourceId, newRes *Resource) error
ReplaceResource replaces the resources identified by `oldId` with `newRes` in the graph and in any property references (as ResourceId or PropertyRef) of the old ID to the new ID in any resource that depends on or is depended on by the resource.
func ResourceIdLess ¶
func ResourceIdLess(a, b ResourceId) bool
func WalkGraph ¶
func WalkGraph(g Graph, fn WalkGraphFunc) error
func WalkGraphReverse ¶
func WalkGraphReverse(g Graph, fn WalkGraphFunc) error
Types ¶
type Dependencies ¶
type Dependencies struct { Resource ResourceId Paths []Path All set.Set[ResourceId] }
func DownstreamDependencies ¶
func DownstreamDependencies(g Graph, start ResourceId, skipEdge func(Edge) bool) (*Dependencies, error)
func UpstreamDependencies ¶
func UpstreamDependencies(g Graph, start ResourceId, skipEdge func(Edge) bool) (*Dependencies, error)
func (*Dependencies) Add ¶
func (d *Dependencies) Add(p Path)
type Edge ¶
type Edge = graph.Edge[ResourceId]
func ResourceEdgeToKeyEdge ¶
func ResourceEdgeToKeyEdge(re ResourceEdge) Edge
type EdgeData ¶
type EdgeData struct {
ConnectionType string `yaml:"connection_type,omitempty" json:"connection_type,omitempty"`
}
type Graph ¶
type Graph = graph.Graph[ResourceId, *Resource]
func NewAcyclicGraph ¶
func NewGraphWithOptions ¶
type GraphBatch ¶
GraphBatch can be used to batch adding vertices and edges to the graph, collecting errors in the [Err] field.
func NewGraphBatch ¶
func NewGraphBatch(g Graph) *GraphBatch
func (*GraphBatch) AddEdges ¶
func (b *GraphBatch) AddEdges(es ...Edge)
func (*GraphBatch) AddVertices ¶
func (b *GraphBatch) AddVertices(rs ...*Resource)
type IdResolutionError ¶
type IdResolutionError map[ResourceId]error
func (IdResolutionError) Error ¶
func (e IdResolutionError) Error() string
type Output ¶
type Output struct { Ref PropertyRef `json:"ref,omitempty" yaml:"ref,omitempty"` Value any `json:"value,omitempty" yaml:"value,omitempty"` }
type Path ¶
type Path graph_addons.Path[ResourceId]
func (Path) Contains ¶
func (p Path) Contains(id ResourceId) bool
func (Path) MarshalText ¶
func (*Path) UnmarshalText ¶
type Properties ¶
func (Properties) Equals ¶
func (p Properties) Equals(other any) (equal bool)
func (Properties) MarshalYAML ¶
func (p Properties) MarshalYAML() (interface{}, error)
func (Properties) PropertyPath ¶
func (p Properties) PropertyPath(pathStr string) (PropertyPath, error)
PropertyPath interprets a string path to index (potentially deeply) into [Resource.Properties] which can be used to get, set, append, or remove values.
func (Properties) WalkProperties ¶
func (p Properties) WalkProperties(fn WalkPropertiesFunc) error
WalkProperties walks the properties of the resource, calling fn for each property. If fn returns SkipProperty, the property and its decendants (if a map or array type) is skipped. If fn returns StopWalk, the walk is stopped. NOTE: does not walk over the _keys_ of any maps, only values.
type PropertyKVItem ¶
type PropertyKVItem interface {
Key() PropertyPathItem
}
type PropertyPath ¶
type PropertyPath []PropertyPathItem
PropertyPath represents a path into a resource's properties. See Resource.PropertyPath for more information.
func (PropertyPath) Append ¶
func (i PropertyPath) Append(value any) error
Append appends a value to the item. Only supported on array items.
func (PropertyPath) Last ¶
func (i PropertyPath) Last() PropertyPathItem
func (PropertyPath) Parts ¶
func (i PropertyPath) Parts() []string
func (PropertyPath) Remove ¶
func (i PropertyPath) Remove(value any) error
Remove removes the value at this path item. If value is nil, it is interpreted to remove the item itself. Non-nil value'd remove is only supported on array items, to remove a value from the array.
func (PropertyPath) Set ¶
func (i PropertyPath) Set(value any) error
Set sets the value at this path item.
func (PropertyPath) String ¶
func (i PropertyPath) String() string
type PropertyPathError ¶
func (PropertyPathError) Error ¶
func (e PropertyPathError) Error() string
func (PropertyPathError) Unwrap ¶
func (e PropertyPathError) Unwrap() error
type PropertyPathItem ¶
type PropertyRef ¶
type PropertyRef struct { Resource ResourceId Property string }
func (*PropertyRef) Equals ¶
func (v *PropertyRef) Equals(ref interface{}) bool
func (*PropertyRef) IsZero ¶
func (v *PropertyRef) IsZero() bool
func (PropertyRef) MarshalText ¶
func (v PropertyRef) MarshalText() ([]byte, error)
func (*PropertyRef) Parse ¶
func (v *PropertyRef) Parse(s string) error
func (PropertyRef) String ¶
func (v PropertyRef) String() string
func (*PropertyRef) UnmarshalText ¶
func (v *PropertyRef) UnmarshalText(b []byte) error
func (*PropertyRef) Validate ¶
func (v *PropertyRef) Validate() error
type Resource ¶
type Resource struct { ID ResourceId Properties Properties Imported bool }
func ResolveIds ¶
func ResolveIds(g Graph, ids []ResourceId) ([]*Resource, error)
func (*Resource) AppendProperty ¶
AppendProperty is a wrapper around PropertyPath.Append for convenience.
func (*Resource) GetProperty ¶
GetProperty is a wrapper around PropertyPath.Get for convenience.
func (*Resource) PropertyPath ¶
func (r *Resource) PropertyPath(pathStr string) (PropertyPath, error)
func (*Resource) RemoveProperty ¶
RemoveProperty is a wrapper around PropertyPath.Remove for convenience.
func (*Resource) SetProperty ¶
SetProperty is a wrapper around PropertyPath.Set for convenience.
func (*Resource) WalkProperties ¶
func (r *Resource) WalkProperties(fn WalkPropertiesFunc) error
type ResourceEdge ¶
type ResourceId ¶
type ResourceId struct { Provider string `yaml:"provider" toml:"provider"` Type string `yaml:"type" toml:"type"` // Namespace is optional and is used to disambiguate resources that might have // the same name. It can also be used to associate an imported resource with // a specific namespace such as a subnet to a VPC. Namespace string `yaml:"namespace" toml:"namespace"` Name string `yaml:"name" toml:"name"` }
func AllDownstreamDependencies ¶
func AllDownstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
AllDownstreamDependencies returns all downstream dependencies of the given resource. Downstream means that for A -> B -> C -> D the downstream dependencies of B are [C, D].
func AllUpstreamDependencies ¶
func AllUpstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
AllUpstreamDependencies returns all upstream dependencies of the given resource. Upstream means that for A -> B -> C -> D the upstream dependencies of C are [B, A] (in that order).
func DirectDownstreamDependencies ¶
func DirectDownstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
DirectDownstreamDependencies returns the direct downstream dependencies of the given resource. Direct means that for A -> B -> C -> D the direct downstream dependencies of B are [C].
func DirectUpstreamDependencies ¶
func DirectUpstreamDependencies(g Graph, r ResourceId) ([]ResourceId, error)
DirectUpstreamDependencies returns the direct upstream dependencies of the given resource. Direct means that for A -> B -> C -> D the direct upstream dependencies of C are [B].
func ResourceHasher ¶
func ResourceHasher(r *Resource) ResourceId
func ReverseTopologicalSort ¶
func ReverseTopologicalSort[T any](g graph.Graph[ResourceId, T]) ([]ResourceId, error)
ReverseTopologicalSort is like TopologicalSort, but returns the reverse order. This is primarily useful for IaC graphs to determine the order in which resources should be created.
func SelectIds ¶
func SelectIds(ids []ResourceId, selector ResourceId) []ResourceId
func TopologicalSort ¶
func TopologicalSort[T any](g graph.Graph[ResourceId, T]) ([]ResourceId, error)
TopologicalSort provides a stable topological ordering of resource IDs. This is a modified implementation of graph.StableTopologicalSort with the primary difference being any uses of the internal function `enqueueArbitrary`.
func (ResourceId) IsAbstractResource ¶
func (id ResourceId) IsAbstractResource() bool
IsAbstractResource returns true if the resource is an abstract resource
func (ResourceId) IsZero ¶
func (id ResourceId) IsZero() bool
func (ResourceId) MarshalTOML ¶
func (id ResourceId) MarshalTOML() ([]byte, error)
func (ResourceId) MarshalText ¶
func (id ResourceId) MarshalText() ([]byte, error)
func (ResourceId) Matches ¶
func (id ResourceId) Matches(other ResourceId) bool
Matches uses `id` (the receiver) as a filter for `other` (the argument) and returns true if all the non-empty fields from `id` match the corresponding fields in `other`.
func (*ResourceId) Parse ¶
func (id *ResourceId) Parse(s string) error
func (ResourceId) QualifiedTypeName ¶
func (id ResourceId) QualifiedTypeName() string
func (ResourceId) String ¶
func (id ResourceId) String() string
func (*ResourceId) UnmarshalTOML ¶
func (id *ResourceId) UnmarshalTOML(data []byte) error
func (*ResourceId) UnmarshalText ¶
func (id *ResourceId) UnmarshalText(data []byte) error
func (*ResourceId) Validate ¶
func (id *ResourceId) Validate() error
type ResourceIdChangeResults ¶
type ResourceIdChangeResults map[ResourceId]ResourceId
ResourceIdChangeResults is a map of old ResourceIds to new ResourceIds
func (*ResourceIdChangeResults) Merge ¶
func (m *ResourceIdChangeResults) Merge(other ResourceIdChangeResults)
func (ResourceIdChangeResults) RemoveNoop ¶
func (m ResourceIdChangeResults) RemoveNoop()
type ResourceList ¶
type ResourceList []ResourceId
func (ResourceList) MatchesAny ¶
func (l ResourceList) MatchesAny(id ResourceId) bool
func (ResourceList) String ¶
func (l ResourceList) String() string
func (*ResourceList) UnmarshalText ¶
func (l *ResourceList) UnmarshalText(b []byte) error
type ShortestPather ¶
type ShortestPather interface {
ShortestPath(target ResourceId) (Path, error)
}
func ShortestPaths ¶
func ShortestPaths( g Graph, source ResourceId, skipEdge func(Edge) bool, ) (ShortestPather, error)
type SimpleEdge ¶
type SimpleEdge struct { Source ResourceId Target ResourceId }
func EdgeKeys ¶
func EdgeKeys[V any](m map[SimpleEdge]V) []SimpleEdge
func ToSimpleEdge ¶
func ToSimpleEdge(e Edge) SimpleEdge
func (SimpleEdge) Less ¶
func (e SimpleEdge) Less(other SimpleEdge) bool
func (SimpleEdge) MarshalText ¶
func (e SimpleEdge) MarshalText() (string, error)
func (*SimpleEdge) Parse ¶
func (e *SimpleEdge) Parse(s string) error
func (SimpleEdge) String ¶
func (e SimpleEdge) String() string
func (SimpleEdge) ToEdge ¶
func (e SimpleEdge) ToEdge() Edge
func (*SimpleEdge) UnmarshalText ¶
func (e *SimpleEdge) UnmarshalText(data []byte) error
func (*SimpleEdge) Validate ¶
func (e *SimpleEdge) Validate() error
type SortedIds ¶
type SortedIds []ResourceId
SortedIds is a helper type for sorting ResourceIds by purely their content, for use when deterministic ordering is desired (when no other sources of ordering are available).
type WalkGraphFunc ¶
type WalkGraphFunc func(id ResourceId, resource *Resource, nerr error) error
WalkGraphFunc is much like `fs.WalkDirFunc` and is used in `WalkGraph` and `WalkGraphReverse` for the callback during graph traversal. Return `StopWalk` to end the walk.
type WalkPropertiesFunc ¶
type WalkPropertiesFunc func(path PropertyPath, err error) error