graph

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EdgeDependency = "dependency"
	EdgeReference  = "reference"
)

EdgeType distinguishes dependency vs reference relationships.

Variables

This section is empty.

Functions

func RenderDiffTree

func RenderDiffTree(d *GraphDiff) string

RenderDiffTree renders a graph diff as a tree-style string, showing only nodes that have changes in their subtree. Uses the same tree connectors as RenderTree for consistency.

func RenderTree

func RenderTree(r *Result) string

RenderTree renders the dependency graph as a tree-style string similar to the Unix tree command.

func ShortRef

func ShortRef(ref string) string

ShortRef extracts a short display name from an OCI reference. It strips the registry/repository prefix and truncates digests.

Types

type ChangeType

type ChangeType string

ChangeType indicates the kind of dependency graph change.

const (
	AddedNode      ChangeType = "added"
	RemovedNode    ChangeType = "removed"
	VersionChanged ChangeType = "version_changed"
)

type Conflict

type Conflict struct {
	Name     string   `json:"name"`
	Versions []string `json:"versions"`
}

Conflict represents a version conflict where the same service is required at incompatible versions.

type ContractFetcher

type ContractFetcher interface {
	Fetch(ctx context.Context, dep contract.Dependency) (*contract.Bundle, error)
}

ContractFetcher fetches a contract bundle for a dependency. The full Dependency is passed so implementations can use fields like Compatibility for version resolution.

type DependencyRef

type DependencyRef struct {
	Scheme   Scheme
	Location string // Registry ref (OCI) or filesystem path (local)
	Original string // Original unparsed reference
}

DependencyRef is a parsed, normalized dependency reference.

func ParseDependencyRef

func ParseDependencyRef(raw string) DependencyRef

ParseDependencyRef parses a raw dependency reference string into a structured DependencyRef. The scheme is detected as follows:

  • "oci://" prefix → OCI registry reference
  • "file://" prefix → local filesystem reference
  • no scheme → local filesystem reference

func (DependencyRef) IsLocal

func (r DependencyRef) IsLocal() bool

IsLocal reports whether the reference points to the local filesystem.

func (DependencyRef) IsOCI

func (r DependencyRef) IsOCI() bool

IsOCI reports whether the reference points to an OCI registry.

type DiffNode

type DiffNode struct {
	Name     string       `json:"name"`
	Version  string       `json:"version,omitempty"`
	Change   *GraphChange `json:"change,omitempty"`
	Children []DiffNode   `json:"children,omitempty"`
}

DiffNode represents a node in the diff tree, carrying its own change (if any) and the changes in its subtree.

type Edge

type Edge struct {
	Ref           string `json:"ref"`
	Required      bool   `json:"required"`
	Compatibility string `json:"compatibility"`
	Type          string `json:"type"` // EdgeDependency or EdgeReference
	Node          *Node  `json:"node,omitempty"`
	Error         string `json:"error,omitempty"`
	Shared        bool   `json:"shared,omitempty"`
	Local         bool   `json:"local,omitempty"`
}

Edge represents a dependency or reference relationship.

func ExtractReferenceEdges added in v0.22.0

func ExtractReferenceEdges(c *contract.Contract) []Edge

ExtractReferenceEdges creates Edge entries for config/policy references in a contract.

type GraphChange

type GraphChange struct {
	Name       string     `json:"name"`
	ChangeType ChangeType `json:"changeType"`
	OldVersion string     `json:"oldVersion,omitempty"`
	NewVersion string     `json:"newVersion,omitempty"`
}

GraphChange represents a single change in the dependency graph.

type GraphDiff

type GraphDiff struct {
	Root    DiffNode      `json:"root"`
	Changes []GraphChange `json:"changes,omitempty"`
}

GraphDiff holds the result of comparing two dependency graphs.

func DiffGraphs

func DiffGraphs(old, new *Result) *GraphDiff

DiffGraphs compares two resolved dependency graphs by walking the tree structure and detecting added, removed, and version-changed nodes at each level. A node removed as a direct dependency is detected even if it remains transitively reachable through another path.

type Node

type Node struct {
	Name         string             `json:"name"`
	Version      string             `json:"version"`
	Ref          string             `json:"ref,omitempty"`
	Local        bool               `json:"local,omitempty"`
	Dependencies []Edge             `json:"dependencies,omitempty"`
	Contract     *contract.Contract `json:"-"`
	FS           fs.FS              `json:"-"`
}

Node represents a service in the dependency graph.

type ResolveOptions added in v0.22.0

type ResolveOptions struct {
	IncludeReferences bool // include config/policy reference edges
	OnlyReferences    bool // show only reference edges (no dependencies)
}

ResolveOptions controls what edges are included in the graph.

type Result

type Result struct {
	Root      *Node      `json:"root"`
	Cycles    [][]string `json:"cycles,omitempty"`
	Conflicts []Conflict `json:"conflicts,omitempty"`
}

Result holds the output of graph resolution.

func Resolve

func Resolve(ctx context.Context, c *contract.Contract, fetcher ContractFetcher) *Result

Resolve builds the dependency graph starting from the given contract. It recursively fetches dependencies via the fetcher, detects cycles and version conflicts. If fetcher is nil, only direct dependencies are shown without resolution. Sibling dependencies at each level are fetched concurrently.

func ResolveWithOptions added in v0.22.0

func ResolveWithOptions(ctx context.Context, c *contract.Contract, fetcher ContractFetcher, opts ResolveOptions) *Result

ResolveWithOptions builds the dependency graph with the given options.

type Scheme

type Scheme int

Scheme represents the type of a dependency reference.

const (
	// SchemeLocal indicates a local filesystem reference (no scheme or file://).
	SchemeLocal Scheme = iota
	// SchemeOCI indicates an OCI registry reference (oci://).
	SchemeOCI
)

func (Scheme) String

func (s Scheme) String() string

String returns the scheme as a human-readable string.

Jump to

Keyboard shortcuts

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