types

package
v0.19.8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 5 Imported by: ? 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.

Documentation

Overview

Package shared contains graph types and helpers shared by the DbGraph backends: the DbGraph interface, the mirror model types, and GQL model helpers. Implementations: pkg/graph/gql (native, untagged), pkg/graph/gochickpeas (native, untagged), and pkg/graph/frogql (wasm, "frogql" build tag).

Index

Constants

This section is empty.

Variables

View Source
var (
	// RelHas is the (Machine)-[:HAS]->(State) relation.
	RelHas = RelKind{"HAS"}
	// RelHasTag is the (Machine)-[:HAS_TAG]->(Tag) relation.
	RelHasTag = RelKind{"HAS_TAG"}
	// RelChildOf is the (Machine)-[:CHILD_OF]->(Machine) relation.
	RelChildOf = RelKind{"CHILD_OF"}
	// RelConnectedTo is the (Machine)-[:CONNECTED_TO]->(Machine) RPC
	// relation.
	RelConnectedTo = RelKind{"CONNECTED_TO"}
	// RelPipe is the (Machine)-[:PIPE]->(Machine) relation, one per pipe.
	RelPipe = RelKind{"PIPE"}

	// RelRequire is the (State)-[:REQUIRE]->(State) relation.
	RelRequire = RelKind{"REQUIRE"}
	// RelAdd is the (State)-[:ADD]->(State) relation.
	RelAdd = RelKind{"ADD"}
	// RelRemove is the (State)-[:REMOVE]->(State) relation.
	RelRemove = RelKind{"REMOVE"}
	// RelAfter is the (State)-[:AFTER]->(State) relation.
	RelAfter = RelKind{"AFTER"}

	// RelKinds enumerates all graph edge kinds.
	RelKinds = enum.New(RelHas, RelHasTag, RelChildOf, RelConnectedTo, RelPipe,
		RelRequire, RelAdd, RelRemove, RelAfter)
)
View Source
var (
	// EndpointQuery executes raw GQL.
	EndpointQuery = Endpoint{"/query"}
	// EndpointMachine returns a serialized machine.
	EndpointMachine = Endpoint{"/machine"}
	// EndpointHistory executes history API methods.
	EndpointHistory = Endpoint{"/history"}
	// EndpointWS is the WebSocket endpoint.
	EndpointWS = Endpoint{"/ws"}

	// Endpoints enumerates all DB server endpoints.
	Endpoints = enum.New(EndpointQuery, EndpointMachine, EndpointHistory,
		EndpointWS)
)
View Source
var (
	// HistActivatedBetween returns true if a state became active within the
	// passed conditions.
	HistActivatedBetween = HistoryAction{"activated-between"}
	// HistActiveBetween returns true if a state was active at least once
	// within the passed conditions.
	HistActiveBetween = HistoryAction{"active-between"}
	// HistDeactivatedBetween returns true if a state became inactive within
	// the passed conditions.
	HistDeactivatedBetween = HistoryAction{"deactivated-between"}
	// HistInactiveBetween returns true if a state was inactive at least once
	// within the passed conditions.
	HistInactiveBetween = HistoryAction{"inactive-between"}
	// HistLatestActivated returns the most recently activated state.
	HistLatestActivated = HistoryAction{"latest-activated"}
	// HistLatestDeactivated returns the most recently deactivated state.
	HistLatestDeactivated = HistoryAction{"latest-deactivated"}
	// HistFindLatest returns the latest history records.
	HistFindLatest = HistoryAction{"find-latest"}

	// HistActions enumerates all history API methods.
	HistActions = enum.New(HistActivatedBetween, HistActiveBetween,
		HistDeactivatedBetween, HistInactiveBetween, HistLatestActivated,
		HistLatestDeactivated, HistFindLatest)
)

RelLabels maps machine relations to GQL edge labels.

Functions

func RelLabel

func RelLabel(rel am.Relation) string

RelLabel returns the GQL edge label of a machine relation.

func RelStates

func RelStates(state am.State, rel am.Relation) am.S

RelStates returns the related states of a specific relation type. TODO use mach APIs

func TagValue

func TagValue(tag string) string

TagValue returns the value part of a tag, or the tag name when valueless. TODO use amhelp

Types

type DbGraph

type DbGraph interface {
	// UpsertMachine replaces a machine in the database with its current
	// schema, states, relations, tags, and cross-machine edges. Idempotent.
	UpsertMachine(m *Machine) error
	// SyncMachine updates the clocks and tags of an existing machine in the
	// database. Machines not yet upserted should be upserted in full.
	SyncMachine(m *Machine) error
	// Exec executes an arbitrary GQL statement against the database.
	Exec(gql string) (any, error)
	// NodeCount returns the number of nodes in the database.
	NodeCount() int
	// EdgeCount returns the number of edges in the database.
	EdgeCount() int
	// Close closes the underlying connection.
	Close() error
}

DbGraph mirrors graph changes into a graph database. It's optionally composed into NetworkGraph via NetworkGraph.Db.

The embedded frogql implementation lives in pkg/graph/frogql and requires the "frogql" build tag. Its GQL model:

(:Machine {id, parent, schema_hash, mtime_sum, queue_tick, mach_tick})
(:State {mach, name, tick, active})
(:Tag {mach, name, value})
(Machine)-[:HAS]->(State)
(Machine)-[:HAS_TAG]->(Tag)
(Machine)-[:CHILD_OF]->(Machine)
(Machine)-[:CONNECTED_TO]->(Machine) // RPC conns (src-id tags)
(State)-[:REQUIRE|ADD|REMOVE|AFTER]->(State)

type Endpoint

type Endpoint enum.Member[string]

Endpoint is a DB server endpoint.

type HistoryAction

type HistoryAction enum.Member[string]

HistoryAction is a history API method, exposed by EndpointHistory.

type Machine

type Machine struct {
	*am.Serialized

	// Current schema hash.
	SchemaHash string
	// Current machine schema.
	Schema am.Schema
	// Parent is the parent machine ID.
	Parent string
	// Current machine time.
	MTimeSum uint64
	// The last update of tags happened during this machine time.
	TagsMTimeSum uint64
}

Machine represents a single state machine withing the network graph.

func (*Machine) Clone

func (m *Machine) Clone() *Machine

Clone returns a deep copy of the machine, safe for concurrent reads.

type RelKind

type RelKind enum.Member[string]

RelKind is a GQL relationship kind of a graph edge. See DbGraph for the model.

Jump to

Keyboard shortcuts

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