graph

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

graph

github.com/webong/ext/res/graph provides a generic, namespaced, directed graph store with transactions, plus graph/system for host, shell, filesystem and webview discovery and process-graph inspection.

The store is domain-neutral: callers own their node and edge vocabulary. CTX and other consumers share this library rather than each implementing their own graph.

Product-specific provider discovery belongs in the owning adapter under adapters/<name>/. graph/system supplies the portable collectors and vocabulary only.

See host discovery and the graph runtime decision record.

Documentation

Overview

Package graph provides a generic, namespaced, directed graph store.

Kinds and relationship types are opaque consumer vocabulary. A store never assigns product meaning or authority to graph records.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("graph record not found")
	ErrConflict      = errors.New("graph revision conflict")
	ErrIdempotency   = errors.New("idempotency key reused with different transaction")
	ErrDanglingEdge  = errors.New("edge endpoint does not exist")
	ErrIncidentEdges = errors.New("vertex has incident edges")
	ErrLimitRequired = errors.New("query limit must be positive")
	ErrSecretValue   = errors.New("secret-like values are not allowed in graph attributes")
	ErrInvalidName   = errors.New("invalid namespace, kind, or relationship name")
	ErrCursorExpired = errors.New("graph change cursor has expired; take a new snapshot")
)

Functions

func ValidateAttributes

func ValidateAttributes(attrs map[string]any) error

ValidateAttributes checks ordinary graph metadata before projection. It applies the same secret-marker and size rules as Store.Apply.

Types

type Change

type Change struct {
	Cursor          uint64    `json:"cursor"`
	Namespace       string    `json:"namespace"`
	Revision        uint64    `json:"revision"`
	Committed       time.Time `json:"committed_at"`
	Vertices        []Vertex  `json:"vertices,omitempty"`
	Edges           []Edge    `json:"edges,omitempty"`
	DeletedVertices []string  `json:"deleted_vertices,omitempty"`
	DeletedEdges    []string  `json:"deleted_edges,omitempty"`
}

type Commit

type Commit struct {
	Namespace string    `json:"namespace"`
	Revision  uint64    `json:"revision"`
	Cursor    uint64    `json:"cursor"`
	Committed time.Time `json:"committed_at"`
	Replayed  bool      `json:"replayed,omitempty"`
}

type Edge

type Edge struct {
	Namespace  string            `json:"namespace"`
	ID         string            `json:"id"`
	From       string            `json:"from"`
	To         string            `json:"to"`
	Type       string            `json:"type"`
	Revision   uint64            `json:"revision"`
	CreatedAt  time.Time         `json:"created_at"`
	UpdatedAt  time.Time         `json:"updated_at"`
	Labels     map[string]string `json:"labels,omitempty"`
	Attributes map[string]any    `json:"attributes,omitempty"`
	Provenance Provenance        `json:"provenance,omitempty"`
}

Edge is a directed relationship from From to To.

type EdgeQuery

type EdgeQuery struct {
	Namespace, Type, From, To string
	Limit                     int
}

type EdgeRef

type EdgeRef struct{ Namespace, ID string }

type Options

type Options struct {
	MaxChanges     int
	MaxChangeBytes int
}

Options controls how much replay history a store retains. Zero values use defaults of 4096 commits and 16 MiB of serialized changes. The latest commit is always kept, even when it alone exceeds MaxChangeBytes. Idempotency records older than the floor expire with their commit.

type Path

type Path struct {
	Vertices []Vertex
	Edges    []Edge
}

type Provenance

type Provenance struct {
	Source    string    `json:"source,omitempty"`
	Operation string    `json:"operation,omitempty"`
	At        time.Time `json:"at,omitempty"`
}

Provenance identifies the system or operation that produced a fact. It is descriptive metadata and grants no authority.

type Schema

type Schema struct {
	Namespace string
	Version   string
	Validate  Validator
}

type Snapshot

type Snapshot struct {
	Namespace string `json:"namespace"`
	Revision  uint64 `json:"revision"`
	Cursor    uint64 `json:"cursor"`
	// HistoryFloor is the newest cursor that is no longer available from Changes or Watch.
	HistoryFloor uint64   `json:"history_floor,omitempty"`
	Vertices     []Vertex `json:"vertices"`
	Edges        []Edge   `json:"edges"`
}

type Store

type Store interface {
	Register(Schema) error
	Apply(context.Context, Transaction) (Commit, error)
	GetVertex(context.Context, string, string) (Vertex, error)
	GetEdge(context.Context, string, string) (Edge, error)
	QueryVertices(context.Context, VertexQuery) ([]Vertex, error)
	QueryEdges(context.Context, EdgeQuery) ([]Edge, error)
	Traverse(context.Context, string, string, int, int) ([]Path, error)
	Snapshot(context.Context, string) (Snapshot, error)
	Changes(context.Context, string, uint64, int) ([]Change, error)
	Watch(context.Context, string, uint64, int) (<-chan Change, error)
	Close() error
}

func NewMemory

func NewMemory() Store

NewMemory creates an in-memory graph store.

func NewMemoryWithOptions

func NewMemoryWithOptions(options Options) Store

func OpenFile

func OpenFile(path string) (Store, error)

OpenFile opens or creates a durable JSON snapshot store. Commits are written through a temporary file and atomically renamed before they become visible.

func OpenFileWithOptions

func OpenFileWithOptions(path string, options Options) (Store, error)

type Transaction

type Transaction struct {
	Namespace           string
	IdempotencyKey      string
	ExpectedRevision    *uint64
	Vertices            []Vertex
	Edges               []Edge
	DeleteVertices      []VertexRef
	DeleteEdges         []EdgeRef
	DeleteIncidentEdges bool
}

Transaction is applied atomically within one namespace. A non-nil ExpectedRevision enables optimistic concurrency. DeleteVertices require DeleteIncidentEdges to explicitly detach incident edges.

type Validator

type Validator func(View, Transaction) error

type Vertex

type Vertex struct {
	Namespace  string            `json:"namespace"`
	ID         string            `json:"id"`
	Kind       string            `json:"kind"`
	Revision   uint64            `json:"revision"`
	CreatedAt  time.Time         `json:"created_at"`
	UpdatedAt  time.Time         `json:"updated_at"`
	Labels     map[string]string `json:"labels,omitempty"`
	Attributes map[string]any    `json:"attributes,omitempty"`
	Provenance Provenance        `json:"provenance,omitempty"`
}

Vertex is a generic typed graph record. ID is supplied by the consumer and should remain stable for the lifetime of the logical object.

type VertexQuery

type VertexQuery struct {
	Namespace, Kind string
	Limit           int
}

type VertexRef

type VertexRef struct{ Namespace, ID string }

type View

type View interface {
	Vertex(namespace, id string) (Vertex, bool)
	Edge(namespace, id string) (Edge, bool)
	Vertices(namespace string, limit int) ([]Vertex, error)
	Edges(namespace string, limit int) ([]Edge, error)
}

View is a transaction-scoped read-only view supplied to validators.

Directories

Path Synopsis
Package supervisor runs generic local component processes and projects their observed lifecycle into a graph.
Package supervisor runs generic local component processes and projects their observed lifecycle into a graph.
Package systemgraph projects CTX machine inventory, shell, and browser observations onto the public generic graph API.
Package systemgraph projects CTX machine inventory, shell, and browser observations onto the public generic graph API.

Jump to

Keyboard shortcuts

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