Documentation
¶
Overview ¶
Package graph owns resource identity resolution and canonical hashing (GRAPH-001). It is deliberately dependency-light: it imports only the contract package, never orm, api, or configstore, so it can be used by every layer that must address a resource identically.
Index ¶
- Variables
- func CanonicalHash(v any) string
- func DescriptorHash(d contract.ResourceDescriptor) string
- type BoundedAnalyzer
- type CapabilityGraph
- type CapabilityID
- type DependencyGraph
- type DependentPath
- type Edge
- type EdgeKind
- type ErrCycleDetected
- type ErrQueryBudgetExceeded
- type ImpactAnalyzer
- type ImpactPage
- type ImpactQuery
- type ImpactResult
- type Memory
- func (m *Memory) List(namespace string, kind contract.ResourceKind) ([]contract.ResourceDescriptor, error)
- func (m *Memory) Register(ctx context.Context, d contract.ResourceDescriptor) (contract.ResourceRef, error)
- func (m *Memory) Resolve(ref contract.ResourceRef) (contract.ResourceDescriptor, error)
- type MemoryGraph
- type QueryStats
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDepth = errors.New("graph: impact MaxDepth must be 1..20")
ErrInvalidDepth is a typed error for an out-of-range MaxDepth.
Functions ¶
func CanonicalHash ¶
CanonicalHash returns the SHA-256 hex digest of v marshalled to canonical JSON. Map keys are sorted recursively, struct fields follow declared order, and slices keep element order. The result is therefore stable across equivalent inputs that differ only in map key ordering.
func DescriptorHash ¶
func DescriptorHash(d contract.ResourceDescriptor) string
DescriptorHash returns the canonical hash of a resource descriptor's content — namespace, name, version, kind, fields, and dependencies — excluding the Hash field and lifecycle timestamps. This is the value stored on ResourceDescriptor.Hash.
Types ¶
type BoundedAnalyzer ¶
type BoundedAnalyzer interface {
ImpactPage(ctx context.Context, q ImpactQuery, maxNodes int, cursor string) (ImpactPage, error)
}
BoundedAnalyzer is the bounded, paginated impact surface (GRAPH-005). maxNodes caps the total dependent set; cursor resumes from a prior page offset.
func NewBoundedAnalyzer ¶
func NewBoundedAnalyzer(inner ImpactAnalyzer) BoundedAnalyzer
NewBoundedAnalyzer returns a bounded analyzer over inner.
type CapabilityGraph ¶
type CapabilityGraph interface {
DeclareConsumer(consumer contract.ResourceRef, cap CapabilityID) error
ConsumersOf(cap CapabilityID) ([]contract.ResourceRef, error)
DegradeSet(cap CapabilityID) (ImpactResult, error)
}
CapabilityGraph records which resources consume which capabilities and computes the degrade set when a capability is removed or fails.
func NewCapabilityGraph ¶
func NewCapabilityGraph(deps DependencyGraph) CapabilityGraph
NewCapabilityGraph returns a capability graph. deps supplies the resource dependency graph used to compute transitive degradation.
type CapabilityID ¶
CapabilityID is the stable identity of a capability (GRAPH-004). Namespace is the capability category ("sms", "storage", "events"); it is not a tenant.
func (CapabilityID) String ¶
func (c CapabilityID) String() string
type DependencyGraph ¶
type DependencyGraph interface {
AddEdge(ctx context.Context, e Edge) error
EdgesFrom(ref contract.ResourceRef) ([]Edge, error)
EdgesTo(ref contract.ResourceRef) ([]Edge, error)
TopologicalOrder(namespace string) ([]contract.ResourceRef, error)
}
DependencyGraph is the queryable edge store for explainable dependencies (GRAPH-002). Implementations enforce cycle-free registration.
type DependentPath ¶
type DependentPath struct {
Resource contract.ResourceRef
Path []Edge
Depth int
}
DependentPath is one transitive dependent and the edge chain from the target to it. Path[i].From depends on Path[i].To; Path[0].To is the target's direct dependency edge target, so Path reads from the queried resource outward.
type Edge ¶
type Edge struct {
From contract.ResourceRef `json:"from"`
To contract.ResourceRef `json:"to"`
Kind EdgeKind `json:"kind"`
Via string `json:"via,omitempty"`
}
Edge is one explainable dependency: From depends on To (declared via Via).
type EdgeKind ¶
type EdgeKind string
EdgeKind classifies the relationship an edge represents. The value is stable and used for telemetry labels and impact classification.
type ErrCycleDetected ¶
type ErrCycleDetected struct {
Path []contract.ResourceRef
}
ErrCycleDetected is a typed error returned when adding an edge would close a dependency cycle. Path carries the full cycle (From → … → From) so callers can explain the rejection without re-deriving it.
func (*ErrCycleDetected) Error ¶
func (e *ErrCycleDetected) Error() string
type ErrQueryBudgetExceeded ¶
ErrQueryBudgetExceeded is a typed overrun error carrying the limit and the observed node count.
func (*ErrQueryBudgetExceeded) Error ¶
func (e *ErrQueryBudgetExceeded) Error() string
type ImpactAnalyzer ¶
type ImpactAnalyzer interface {
Impact(ctx context.Context, q ImpactQuery) (ImpactResult, error)
}
ImpactAnalyzer computes transitive dependency impact.
func NewImpactAnalyzer ¶
func NewImpactAnalyzer(g DependencyGraph) ImpactAnalyzer
NewImpactAnalyzer returns an analyzer over g.
type ImpactPage ¶
type ImpactPage struct {
Dependents []DependentPath
NextCursor string
Truncated bool
Stats QueryStats
}
ImpactPage is one cursor-paginated page of an impact query.
type ImpactQuery ¶
type ImpactQuery struct {
Target contract.ResourceRef
MaxDepth int // required, 1..20
Kinds []EdgeKind // empty means all kinds
}
ImpactQuery asks "what transitively depends on Target, out to MaxDepth, via these edge kinds". It is the programmatic form of the destructive-change dependency report (GRAPH-003).
type ImpactResult ¶
type ImpactResult struct {
Dependents []DependentPath
Truncated bool // traversal hit MaxDepth with more nodes remaining
}
ImpactResult reports transitive dependents with explanatory paths.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-memory, concurrency-safe ResourceRegistry (GRAPH-001). It enforces namespace isolation and monotonic per-(namespace, name) versioning. It is the reference implementation against which the SQL-backed registry (backed by _kora_resource) is contract-tested.
func (*Memory) List ¶
func (m *Memory) List(namespace string, kind contract.ResourceKind) ([]contract.ResourceDescriptor, error)
List returns all descriptors in namespace, optionally filtered by kind (an empty kind matches all kinds). Results are ordered by (name, version).
func (*Memory) Register ¶
func (m *Memory) Register(ctx context.Context, d contract.ResourceDescriptor) (contract.ResourceRef, error)
Register stores d under its namespaced identity. Re-registering an existing (namespace, name) bumps the version; re-registering the exact same (namespace, name, version) with an identical content hash is idempotent and returns the existing ref unchanged. A version collision with a different hash is a typed conflict.
func (*Memory) Resolve ¶
func (m *Memory) Resolve(ref contract.ResourceRef) (contract.ResourceDescriptor, error)
Resolve returns the descriptor for ref. A Version of 0 resolves the latest registered version for that (namespace, name); otherwise the version must match exactly.
type MemoryGraph ¶
type MemoryGraph struct {
// contains filtered or unexported fields
}
MemoryGraph is an in-memory, concurrency-safe DependencyGraph (GRAPH-002). It rejects self- and mutual-dependency cycles with a path-bearing typed error and provides deterministic topological ordering (dependencies before dependents). It is the reference implementation for the SQL-backed edge store, mirroring Memory (GRAPH-001).
func NewMemoryGraph ¶
func NewMemoryGraph() *MemoryGraph
NewMemoryGraph returns an empty in-memory dependency graph.
func (*MemoryGraph) AddEdge ¶
func (g *MemoryGraph) AddEdge(ctx context.Context, e Edge) error
AddEdge registers e after proving it does not close a cycle. Adding an edge whose To can already reach From would create From → … → To → … → From.
func (*MemoryGraph) EdgesFrom ¶
func (g *MemoryGraph) EdgesFrom(ref contract.ResourceRef) ([]Edge, error)
EdgesFrom returns all outgoing edges for ref (things ref depends on).
func (*MemoryGraph) EdgesTo ¶
func (g *MemoryGraph) EdgesTo(ref contract.ResourceRef) ([]Edge, error)
EdgesTo returns all incoming edges for ref (things that depend on ref).
func (*MemoryGraph) TopologicalOrder ¶
func (g *MemoryGraph) TopologicalOrder(namespace string) ([]contract.ResourceRef, error)
TopologicalOrder returns the resources in namespace in dependency order: dependencies (To) precede dependents (From). Deterministic for a fixed graph; ties break by resource name then version.
type QueryStats ¶
QueryStats reports the cost of an impact query (GRAPH-005).