graphcontract

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package graphcontract defines Spool's canonical graph object contract.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPropertyValue reports a property value with an unknown kind or a
	// non-finite floating-point value.
	ErrInvalidPropertyValue = errors.New("invalid property value")
	// ErrInvalidCanonicalCBOR reports CBOR that does not encode a normalized
	// graph contract value in its canonical representation.
	ErrInvalidCanonicalCBOR = errors.New("invalid canonical CBOR")
)

Functions

func MarshalEdge

func MarshalEdge(e Edge) ([]byte, error)

MarshalEdge returns the normalized, canonical CBOR encoding of e.

func MarshalNode

func MarshalNode(n Node) ([]byte, error)

MarshalNode returns the normalized, canonical CBOR encoding of n.

func MarshalPropertyValue

func MarshalPropertyValue(v PropertyValue) ([]byte, error)

MarshalPropertyValue returns the normalized, canonical CBOR encoding of v.

Types

type Edge

type Edge struct {
	// ID uniquely identifies the edge within a graph snapshot.
	ID string `json:"id" cbor:"1,keyasint"`
	// Source identifies the edge's originating node.
	Source string `json:"source" cbor:"2,keyasint"`
	// Target identifies the edge's destination node.
	Target string `json:"target" cbor:"3,keyasint"`
	// Type identifies the edge's relationship type.
	Type string `json:"type,omitempty" cbor:"4,keyasint,omitempty"`
	// Properties holds typed, recursively composable edge properties.
	Properties map[string]PropertyValue `json:"properties" cbor:"5,keyasint"`
}

Edge is the immutable edge representation stored in a graph snapshot.

func NewEdge

func NewEdge(id, source, target, edgeType string, properties map[string]PropertyValue) (Edge, error)

NewEdge constructs a normalized edge.

func UnmarshalEdge

func UnmarshalEdge(data []byte) (Edge, error)

UnmarshalEdge decodes and verifies canonical CBOR for an edge.

func (Edge) Clone

func (e Edge) Clone() Edge

Clone returns a deep copy of e.

func (Edge) Equal

func (e Edge) Equal(other Edge) bool

Equal reports semantic equality after canonical normalization.

func (Edge) MarshalCBOR

func (e Edge) MarshalCBOR() ([]byte, error)

MarshalCBOR returns the normalized, canonical CBOR encoding of e. Omitted and explicitly empty properties have one encoding.

func (Edge) Normalize

func (e Edge) Normalize() (Edge, error)

Normalize returns a canonical edge with normalized property values.

type Node

type Node struct {
	// ID uniquely identifies the node within a graph snapshot.
	ID string `json:"id" cbor:"1,keyasint"`
	// Title is the node's display value and compatibility field.
	Title string `json:"title" cbor:"2,keyasint"`
	// Labels identifies the node's sorted, unique type labels.
	Labels []string `json:"labels" cbor:"3,keyasint"`
	// Properties holds typed, recursively composable node properties.
	Properties map[string]PropertyValue `json:"properties" cbor:"4,keyasint"`
}

Node is the immutable node representation stored in a graph snapshot.

func NewNode

func NewNode(id, title string, labels []string, properties map[string]PropertyValue) (Node, error)

NewNode constructs a normalized node.

func UnmarshalNode

func UnmarshalNode(data []byte) (Node, error)

UnmarshalNode decodes and verifies canonical CBOR for a node.

func (Node) Clone

func (n Node) Clone() Node

Clone returns a deep copy of n.

func (Node) Equal

func (n Node) Equal(other Node) bool

Equal reports semantic equality after canonical normalization.

func (Node) MarshalCBOR

func (n Node) MarshalCBOR() ([]byte, error)

MarshalCBOR returns the normalized, canonical CBOR encoding of n. Omitted and explicitly empty collections have one encoding.

func (Node) Normalize

func (n Node) Normalize() (Node, error)

Normalize returns a canonical node with sorted, deduplicated labels and normalized property values.

type PropertyKind

type PropertyKind string

PropertyKind identifies the concrete value carried by a PropertyValue.

const (
	PropertyNull    PropertyKind = "null"
	PropertyBool    PropertyKind = "bool"
	PropertyInteger PropertyKind = "integer"
	PropertyFloat   PropertyKind = "float"
	PropertyString  PropertyKind = "string"
	PropertyList    PropertyKind = "list"
	PropertyMap     PropertyKind = "map"
)

type PropertyValue

type PropertyValue struct {
	Kind    PropertyKind             `json:"kind" cbor:"1,keyasint"`
	Bool    bool                     `json:"bool,omitempty" cbor:"2,keyasint,omitempty"`
	Integer int64                    `json:"integer,omitempty" cbor:"3,keyasint,omitempty"`
	Float   float64                  `json:"float,omitempty" cbor:"4,keyasint,omitempty"`
	String  string                   `json:"string,omitempty" cbor:"5,keyasint,omitempty"`
	List    []PropertyValue          `json:"list,omitempty" cbor:"6,keyasint,omitempty"`
	Map     map[string]PropertyValue `json:"map,omitempty" cbor:"7,keyasint,omitempty"`
}

PropertyValue is a tagged, recursively composable graph property value. Only the field associated with Kind is significant.

func BoolPropertyValue

func BoolPropertyValue(value bool) PropertyValue

BoolPropertyValue returns a boolean property value.

func FloatPropertyValue

func FloatPropertyValue(value float64) PropertyValue

FloatPropertyValue returns a floating-point property value.

func IntegerPropertyValue

func IntegerPropertyValue(value int64) PropertyValue

IntegerPropertyValue returns an integer property value.

func ListPropertyValue

func ListPropertyValue(value []PropertyValue) PropertyValue

ListPropertyValue returns a list property value.

func MapPropertyValue

func MapPropertyValue(value map[string]PropertyValue) PropertyValue

MapPropertyValue returns a string-keyed map property value.

func NullPropertyValue

func NullPropertyValue() PropertyValue

NullPropertyValue returns the canonical null property value.

func StringPropertyValue

func StringPropertyValue(value string) PropertyValue

StringPropertyValue returns a string property value.

func UnmarshalPropertyValue

func UnmarshalPropertyValue(data []byte) (PropertyValue, error)

UnmarshalPropertyValue decodes and verifies canonical CBOR for a property value.

func (PropertyValue) Clone

func (v PropertyValue) Clone() PropertyValue

Clone returns a deep copy of v.

func (PropertyValue) Equal

func (v PropertyValue) Equal(other PropertyValue) bool

Equal reports semantic equality after canonical normalization.

func (PropertyValue) MarshalCBOR

func (v PropertyValue) MarshalCBOR() ([]byte, error)

MarshalCBOR returns the normalized, canonical CBOR encoding of v.

func (PropertyValue) Normalize

func (v PropertyValue) Normalize() (PropertyValue, error)

Normalize returns the canonical representation of v. It clears fields that do not belong to v.Kind, recursively normalizes values, and normalizes negative zero to zero. CBOR canonical encoding deterministically orders the resulting string-keyed maps.

type PropertyValueKind

type PropertyValueKind = PropertyKind

PropertyValueKind is an alias retained for callers that prefer the explicit type name.

Jump to

Keyboard shortcuts

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