nodestore

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 22 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.

README

nodestore

Domain model and persistence for flow-based (Node-RED-style) workflows. Everything crosses interfaces — consumers depend on the contracts, never on the concrete Store or entity structs.

What it provides

  • StoreInterface — persistence contract for the whole domain, backed by dracory/entitystore (multi-database via dracory/neat: SQLite, Postgres, MySQL, …).
  • WorkflowInterface — a workflow (flow) with its nodes, edges, view metadata, and deployed flag.
  • NodeInterface — a node as a first-class entity: own ID and timestamps, workflow_id link, type, name, position, and a Data payload — never a JSON blob on the workflow.
  • EdgeInterface — an edge as a first-class entity with its own ID, linking source node/port to target node.
  • MessageInterface — the message envelope exchanged between nodes.
  • ContextStore — node/flow/global context persistence.

Query builders (WorkflowQuery, NodeQuery, EdgeQuery, MessageQuery) follow the same shape as taskstore/cmsstore: Interface

  • implementation + Query.

Also included:

  • Node-RED flow JSON import/export (type-name mapping both ways)
  • Subflow/module composition helpers
  • Key/value config store (global env, editor settings)

Usage

store, err := nodestore.NewStore(nodestore.NewStoreOptions{
    EntityStore: entityStore, // entitystore.StoreInterface (required)
})

wf := nodestore.NewWorkflow("my flow")
err = store.WorkflowCreate(ctx, wf)

Ecosystem

Repo Role
nodebase Engine-agnostic node executors + the NodeHost contract
noderun The reference workflow engine; implements NodeHost
nodeadmin Mountable admin HTTP/UI

Node executors embed nodestore.NodeInterface — identity, type and Data live on the node entity, not on a parallel base struct.

Rules

  • Timestamps come from the entitystore entity (created_at, updated_at) — no duplicate timestamp fields or attributes.
  • Import direction: engine (noderun) and admin (nodeadmin) may import nodestore, never the reverse.

Documentation

Index

Constants

View Source
const ASC = "asc"
View Source
const ATTRIBUTE_ACTOR = "actor"

Attribute keys (persisted in the entity store attributes table)

View Source
const ATTRIBUTE_DATA = "data"
View Source
const ATTRIBUTE_DEPLOYED = "deployed"
View Source
const ATTRIBUTE_DESCRIPTION = "description"
View Source
const ATTRIBUTE_EDGES = "edges" // legacy: JSON blob on workflow entities

Legacy attribute keys — never written anymore, only read as a fallback when loading pre-migration records and cleaned up by entityAttributesReplace (they are in each type's managed key set).

View Source
const ATTRIBUTE_ERROR = "error"
View Source
const ATTRIBUTE_FLOW = "flow"
View Source
const ATTRIBUTE_GROUP_ID = "group_id"
View Source
const ATTRIBUTE_METADATA = "metadata"
View Source
const ATTRIBUTE_NAME = "name"
View Source
const ATTRIBUTE_NODES = "nodes" // legacy: JSON blob on workflow entities
View Source
const ATTRIBUTE_NODE_ID = "node_id"
View Source
const ATTRIBUTE_PARENT_ID = "parent_id"
View Source
const ATTRIBUTE_PAYLOAD = "payload"
View Source
const ATTRIBUTE_POSITION = "position"
View Source
const ATTRIBUTE_SOURCE = "source"
View Source
const ATTRIBUTE_SOURCE_KEY = "source_key"
View Source
const ATTRIBUTE_TARGET = "target"
View Source
const ATTRIBUTE_TARGET_KEY = "target_key"
View Source
const ATTRIBUTE_TIMESTAMP = "timestamp" // legacy: duplicated entity created_at on messages
View Source
const ATTRIBUTE_TYPE = "type"
View Source
const ATTRIBUTE_VALUE = "value"
View Source
const ATTRIBUTE_VIEW = "view"
View Source
const ATTRIBUTE_WORKFLOWS = "workflows"
View Source
const ATTRIBUTE_WORKFLOW_ID = "workflow_id"
View Source
const AttributeConfigValue = "value"

AttributeConfigValue holds a config entry's raw string payload

View Source
const CredentialSentinel = "__PWRD__"

CredentialSentinel is the marker stored in node.Data in place of a real credential value (the same convention Node-RED's editor uses, "__PWRD__"). Stored workflows and editor payloads carry the sentinel where a secret exists; the actual value lives in server-side credential storage and is merged back into node.Data at deploy time. Exports must strip sentinel values and credential keys entirely.

View Source
const DESC = "desc"
View Source
const DeployRecordRetention = 20

DeployRecordRetention caps the deploy history kept per workflow — the last N records survive, older ones are pruned on append (same cap flowadmin used).

View Source
const EntityTypeConfig = "config"

EntityTypeConfig is the entity type for module-level key/value config

View Source
const EntityTypeCredential = "credential"

Entity types stored in the underlying entity store

View Source
const EntityTypeDeployRecord = "deploy_record"
View Source
const EntityTypeEdge = "edge"
View Source
const EntityTypeMessage = "message"
View Source
const EntityTypeNode = "node"
View Source
const EntityTypeNodeGroup = "node_group"
View Source
const EntityTypeWorkflow = "workflow"
View Source
const EntityTypeWorkflowGroup = "workflow_group"

Variables

This section is empty.

Functions

func ApplyWorkflowCredentials

func ApplyWorkflowCredentials(w WorkflowInterface, creds map[string]map[string]string)

ApplyWorkflowCredentials merges stored credentials into node.Data so a deploy hands executors the real values while storage keeps only sentinel markers. Mutates the workflow in place — callers deploy a clone (the engine deploy path clones before expansion, so stored entities are never tainted).

func CredentialKeys

func CredentialKeys(nodeType string) []string

CredentialKeys returns the config keys of a node type that are treated as credentials (masked in the editor, stored outside the exported flow document, stripped from exports).

func ExportNodeRED

func ExportNodeRED(w WorkflowInterface) ([]byte, error)

ExportNodeRED converts a workflow into the Node-RED flow JSON array shape. Subflow definitions unfold: the type:"subflow" object is followed by its internal nodes as flat objects with z = <defId>.

func ExtractWorkflowCredentials

func ExtractWorkflowCredentials(w WorkflowInterface, existing map[string]map[string]string) map[string]map[string]string

ExtractWorkflowCredentials moves credential values out of every node in the workflow into a nodeID → key → value map, leaving sentinel markers in node.Data. existing is the previously stored credential map (nil on create) used to preserve values the editor sent back as sentinels or omitted entirely. Persist the result via CredentialReplaceForWorkflow.

func ImportModule

func ImportModule(w WorkflowInterface, raw []byte) ([]string, error)

ImportModule merges a module envelope into w as a NEW module. All ids are re-minted (module, nodes, edges, groups, definitions and their internal graphs) and every intra-payload reference is rewritten; references pointing outside the payload are kept verbatim and reported in the returned warnings when they do not resolve against the target workflow. Returns the list of warnings.

func IsCredentialKey

func IsCredentialKey(nodeType, key string) bool

IsCredentialKey reports whether key is a credential field on the given node type.

func IsCredentialSentinel

func IsCredentialSentinel(v any) bool

IsCredentialSentinel reports whether v is the sentinel string left in place of a stored credential value.

func IsSubflowInstance

func IsSubflowInstance(nodeType string) bool

IsSubflowInstance reports whether nodeType names a subflow instance ("subflow:<defId>").

func RegisterCredentialKeys

func RegisterCredentialKeys(typeID string, keys []string)

RegisterCredentialKeys marks config keys of a node type as credentials — the same treatment built-in types get: the editor masks them, storage moves them out of the flow document behind the CredentialSentinel marker, and exports strip them. Re-calling replaces the key list for the type.

Types

type CredentialCipher added in v0.2.0

type CredentialCipher interface {
	// Encrypt returns the sealed (self-describing) form of plaintext.
	Encrypt(plaintext []byte) (string, error)
	// Decrypt opens a sealed value. Implementations must pass
	// through values that are not in their sealed format so legacy
	// plaintext rows still decode.
	Decrypt(sealed string) ([]byte, error)
}

CredentialCipher seals the credential value map before it is persisted into the entity attribute (encryption at rest) and opens it on read. The Node-RED analogue is flows_cred.json's credentialSecret.

func NewAESCredentialCipher added in v0.2.0

func NewAESCredentialCipher(key []byte) (CredentialCipher, error)

NewAESCredentialCipher returns a CredentialCipher using AES-256-GCM with the given 32-byte key. The key is copied — callers may zero their buffer afterwards.

type CredentialInterface

type CredentialInterface interface {
	GetID() string
	SetID(id string) CredentialInterface

	GetWorkflowID() string
	SetWorkflowID(workflowID string) CredentialInterface

	GetNodeID() string
	SetNodeID(nodeID string) CredentialInterface

	// GetValues returns the stored key→value credential map.
	GetValues() map[string]string
	SetValues(values map[string]string) CredentialInterface
	// GetValue returns one stored credential value ("" when unset).
	GetValue(key string) string
	// SetValue upserts one credential key; an empty value removes it.
	SetValue(key, value string) CredentialInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) CredentialInterface

	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) CredentialInterface
}

CredentialInterface is the entity form of a node's stored secrets — one entity per (workflow, node) pair carrying a key→value map. The workflow document keeps only CredentialSentinel markers; the real values live here and are merged back into node.Data at deploy time (Node-RED flows_cred.json convention).

func NewCredential

func NewCredential(workflowID, nodeID string) CredentialInterface

NewCredential creates a new credential entity for a node. The ID may be left empty (entitystore assigns one); callers that need a deterministic handle (workflowID:nodeID) can SetID themselves.

type CredentialQueryInterface

type CredentialQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) CredentialQueryInterface

	HasWorkflowID() bool
	GetWorkflowID() string
	WithWorkflowID(workflowID string) CredentialQueryInterface

	HasNodeID() bool
	GetNodeID() string
	WithNodeID(nodeID string) CredentialQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) CredentialQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) CredentialQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) CredentialQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) CredentialQueryInterface
}

CredentialQueryInterface is the fluent query builder for listing and counting credential entities.

func CredentialQuery

func CredentialQuery() CredentialQueryInterface

CredentialQuery creates a new credential query builder

type DeployRecordInterface

type DeployRecordInterface interface {
	GetID() string
	SetID(id string) DeployRecordInterface

	GetWorkflowID() string
	SetWorkflowID(workflowID string) DeployRecordInterface

	GetActor() string
	SetActor(actor string) DeployRecordInterface

	// GetFlow returns the deployed flow document as raw JSON.
	GetFlow() string
	SetFlow(flow string) DeployRecordInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) DeployRecordInterface
}

DeployRecordInterface is one immutable entry in a workflow's deploy history: who deployed (actor) and the exact flow document deployed (flow, raw JSON — credential fields carry sentinel markers, never secrets). The deploy timestamp comes from the entity's created_at — per the GOD ruling no duplicated time attributes exist.

func NewDeployRecord

func NewDeployRecord(workflowID, actor, flow string) DeployRecordInterface

NewDeployRecord creates a new deploy record entity

type DeployRecordQueryInterface

type DeployRecordQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) DeployRecordQueryInterface

	HasWorkflowID() bool
	GetWorkflowID() string
	WithWorkflowID(workflowID string) DeployRecordQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) DeployRecordQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) DeployRecordQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) DeployRecordQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) DeployRecordQueryInterface
}

DeployRecordQueryInterface is the fluent query builder for listing and counting deploy record entities.

func DeployRecordQuery

func DeployRecordQuery() DeployRecordQueryInterface

DeployRecordQuery creates a new deploy record query builder. Deploy history reads newest-first, so DESC is the default here (unlike the other entity queries).

type EdgeInterface

type EdgeInterface interface {
	GetID() string
	SetID(id string) EdgeInterface

	GetWorkflowID() string
	SetWorkflowID(workflowID string) EdgeInterface

	GetSource() string
	SetSource(source string) EdgeInterface
	GetSourceKey() string
	SetSourceKey(sourceKey string) EdgeInterface

	GetTarget() string
	SetTarget(target string) EdgeInterface
	GetTargetKey() string
	SetTargetKey(targetKey string) EdgeInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) EdgeInterface

	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) EdgeInterface
}

EdgeInterface is the interface form of flowrunner.Edge — a connection between two nodes. The edge IS an entitystore entity: its entity ID is the edge ID and created/updated timestamps come from the entity.

func NewEdge

func NewEdge(id, source, target string) EdgeInterface

NewEdge creates a new workflow edge. Edge ids are never referenced by other entities (edges resolve via their source/target attributes), so an over-length id is deterministically shortened at the boundary.

type EdgeQueryInterface

type EdgeQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) EdgeQueryInterface

	HasWorkflowID() bool
	GetWorkflowID() string
	WithWorkflowID(workflowID string) EdgeQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) EdgeQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) EdgeQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) EdgeQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) EdgeQueryInterface
}

EdgeQueryInterface is the fluent query builder for listing and counting edge entities.

func EdgeQuery

func EdgeQuery() EdgeQueryInterface

EdgeQuery creates a new edge query builder

type MessageInterface

type MessageInterface interface {
	GetID() string
	SetID(id string) MessageInterface

	// GetPayload returns the message payload (typically
	// map[string]any or []byte after JSON round-trip)
	GetPayload() any
	SetPayload(payload any) MessageInterface

	// GetMetadata returns the message metadata
	GetMetadata() map[string]any
	SetMetadata(metadata map[string]any) MessageInterface

	// GetError returns the error message if an upstream node failed
	GetError() *string
	SetError(err string) MessageInterface
	ClearError() MessageInterface

	// GetTimestamp returns the timestamp when the message was created/last modified
	GetTimestamp() time.Time
	SetTimestamp(timestamp time.Time) MessageInterface

	// GetCreatedAt returns the creation timestamp
	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) MessageInterface

	// GetUpdatedAt returns the last update timestamp
	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) MessageInterface
}

MessageInterface is the interface form of flowrunner.Message — the standardized envelope for data flowing between nodes, persisted as an entity (type EntityTypeMessage) so the runner has durable messages.

func NewMessage

func NewMessage() MessageInterface

NewMessage creates a new message

type MessageQueryInterface

type MessageQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) MessageQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) MessageQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) MessageQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) MessageQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) MessageQueryInterface
}

MessageQueryInterface is the fluent query builder for listing and counting messages.

func MessageQuery

func MessageQuery() MessageQueryInterface

MessageQuery creates a new message query builder

type ModuleExport

type ModuleExport struct {
	// Format identifies the envelope kind; always "module".
	Format string `json:"nodestore"`
	// Version is the envelope schema version.
	Version int `json:"version"`
	// Module carries the meta entity {id,label,role,enabled,env}.
	Module map[string]any `json:"module"`
	// Nodes are the module's nodes (backend shape; data.module is
	// implied by the envelope and omitted).
	Nodes []NodeInterface `json:"nodes"`
	// Edges are the edges whose endpoints both live in the module.
	Edges []EdgeInterface `json:"edges"`
	// Groups are the view.groups entries belonging to the module.
	Groups []any `json:"groups,omitempty"`
	// Defs are the type:"subflow" definition nodes the module's
	// subflow:<id> instances reference, resolved transitively
	// (a definition may itself instantiate another definition).
	Defs []NodeInterface `json:"defs,omitempty"`
	// Warnings lists references that point outside the payload —
	// kept verbatim in the export, so they only resolve when the
	// target workflow already contains the referenced nodes.
	Warnings []string `json:"warnings,omitempty"`
}

ModuleExport is the portable single-module payload.

func ExportModule

func ExportModule(w WorkflowInterface, moduleRef string) (*ModuleExport, error)

ExportModule builds the portable envelope for one module of w. moduleRef is a module id or label. Nodes are the workflow nodes whose data.module resolves to the module; edges are those fully inside the set; groups and subflow definitions follow. References pointing at nodes outside the module are kept verbatim and listed in Warnings.

func ExportSubflowDef

func ExportSubflowDef(w WorkflowInterface, defID string) (*ModuleExport, error)

ExportSubflowDef builds a module envelope carrying a single subflow definition (plus any definitions it nests). The envelope's module entity is a role:"subflow" template named after the definition, so importing it produces a navigable module plus a working definition.

func (ModuleExport) MarshalJSON

func (e ModuleExport) MarshalJSON() ([]byte, error)

MarshalJSON serializes the interface-typed node/edge slices through their persisted JSON shapes.

func (*ModuleExport) UnmarshalJSON

func (e *ModuleExport) UnmarshalJSON(raw []byte) error

UnmarshalJSON decodes the wire form back into interface-typed domain objects.

type NewStoreOptions

type NewStoreOptions struct {
	// EntityStore is the underlying storage (required)
	EntityStore entitystore.StoreInterface
	// DebugEnabled enables debug logging
	DebugEnabled bool
	// CredentialCipher seals credential values at rest. When nil,
	// credentials are stored as plaintext JSON (legacy behavior —
	// prefer NewAESCredentialCipher for real secrets).
	CredentialCipher CredentialCipher
}

NewStoreOptions define the options for creating a new node store

type NodeGroupInterface

type NodeGroupInterface interface {
	GetID() string
	SetID(id string) NodeGroupInterface

	GetWorkflowID() string
	SetWorkflowID(workflowID string) NodeGroupInterface

	GetName() string
	SetName(name string) NodeGroupInterface

	// GetData returns the group's freeform view payload (x, y, w, h,
	// disabled, module, env) — the view.groups entry minus id/name/
	// nodeIds.
	GetData() map[string]any
	SetData(data map[string]any) NodeGroupInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) NodeGroupInterface

	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) NodeGroupInterface
}

NodeGroupInterface is the entity form of an editor view group (one of the view.groups entries: {id, name, x, y, w, h, disabled, module, nodeIds}). Membership is NOT stored here — it lives as group_id on the member node entities (GOD ruling 2026-11-24); the geometry and flags ride in the data attribute so the wire shape round-trips.

func NewNodeGroup

func NewNodeGroup(workflowID, name string) NodeGroupInterface

NewNodeGroup creates a new node group entity

type NodeGroupQueryInterface

type NodeGroupQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) NodeGroupQueryInterface

	HasWorkflowID() bool
	GetWorkflowID() string
	WithWorkflowID(workflowID string) NodeGroupQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) NodeGroupQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) NodeGroupQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) NodeGroupQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) NodeGroupQueryInterface
}

NodeGroupQueryInterface is the fluent query builder for listing and counting node group entities.

func NodeGroupQuery

func NodeGroupQuery() NodeGroupQueryInterface

NodeGroupQuery creates a new node group query builder

type NodeInterface

type NodeInterface interface {
	GetID() string
	SetID(id string) NodeInterface

	GetWorkflowID() string
	SetWorkflowID(workflowID string) NodeInterface

	// GetGroupID returns the node_group entity this node belongs to
	// ("" = ungrouped) — group membership lives on the node, not on
	// the group (GOD ruling 2026-11-24).
	GetGroupID() string
	SetGroupID(groupID string) NodeInterface

	GetType() string
	SetType(nodeType string) NodeInterface

	GetPositionX() float64
	SetPositionX(x float64) NodeInterface
	GetPositionY() float64
	SetPositionY(y float64) NodeInterface
	SetPosition(x, y float64) NodeInterface

	GetData() map[string]any
	SetData(data map[string]any) NodeInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) NodeInterface

	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) NodeInterface
}

NodeInterface is the interface form of flowrunner.Node — a single node in a workflow graph. The node IS an entitystore entity: its entity ID is the node ID and created/updated timestamps come from the entity.

func NewNode

func NewNode(id, nodeType string) NodeInterface

NewNode creates a new workflow node

type NodeQueryInterface

type NodeQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) NodeQueryInterface

	HasWorkflowID() bool
	GetWorkflowID() string
	WithWorkflowID(workflowID string) NodeQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) NodeQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) NodeQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) NodeQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) NodeQueryInterface
}

NodeQueryInterface is the fluent query builder for listing and counting node entities.

func NodeQuery

func NodeQuery() NodeQueryInterface

NodeQuery creates a new node query builder

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is the nodestore implementation backed by an entity store

func NewStore

func NewStore(opts NewStoreOptions) (*Store, error)

NewStore creates a new node store on top of an entity store

func (*Store) ConfigGet

func (st *Store) ConfigGet(ctx context.Context, key string) (string, error)

ConfigGet returns the raw value stored under a config key, or the empty string when the key does not exist.

func (*Store) ConfigSet

func (st *Store) ConfigSet(ctx context.Context, key string, value string) error

ConfigSet upserts a raw value under a config key.

func (*Store) CredentialCount

func (st *Store) CredentialCount(ctx context.Context, query CredentialQueryInterface) (int64, error)

func (*Store) CredentialCreate

func (st *Store) CredentialCreate(ctx context.Context, credential CredentialInterface) error

func (*Store) CredentialDeleteByID

func (st *Store) CredentialDeleteByID(ctx context.Context, id string) error

func (*Store) CredentialDeleteByWorkflowID

func (st *Store) CredentialDeleteByWorkflowID(ctx context.Context, workflowID string) error

CredentialDeleteByWorkflowID drops every credential entity owned by the workflow (called when the workflow is deleted).

func (*Store) CredentialFindByID

func (st *Store) CredentialFindByID(ctx context.Context, id string) (CredentialInterface, error)

func (*Store) CredentialFindByNode

func (st *Store) CredentialFindByNode(ctx context.Context, workflowID, nodeID string) (CredentialInterface, error)

CredentialFindByNode returns the single credential entity for a (workflow, node) pair, or nil when none is stored.

func (*Store) CredentialList

func (st *Store) CredentialList(ctx context.Context, query CredentialQueryInterface) ([]CredentialInterface, error)

CredentialList lists credential entities. WithWorkflowID uses EntityListByAttribute (the single attribute-value lookup the store offers — see NodeList); node filtering, limit/offset and sort are applied in memory.

func (*Store) CredentialMapForWorkflow

func (st *Store) CredentialMapForWorkflow(ctx context.Context, workflowID string) (map[string]map[string]string, error)

CredentialMapForWorkflow returns the workflow's stored credentials in the deploy-time shape nodeID → key → value — the single read the engine's credential provider needs.

func (*Store) CredentialReplaceForWorkflow

func (st *Store) CredentialReplaceForWorkflow(ctx context.Context, workflowID string, creds map[string]map[string]string) error

CredentialReplaceForWorkflow bulk-replaces a workflow's credential entities from a nodeID → key → value map: entities not present in the map are deleted, changed ones updated, new ones created. Used by the workflow save path after extractWorkflowCredentials moves the secrets out of node.Data.

func (*Store) CredentialUpdate

func (st *Store) CredentialUpdate(ctx context.Context, credential CredentialInterface) error

func (*Store) DeployRecordCount

func (st *Store) DeployRecordCount(ctx context.Context, query DeployRecordQueryInterface) (int64, error)

func (*Store) DeployRecordCreate

func (st *Store) DeployRecordCreate(ctx context.Context, record DeployRecordInterface) error

DeployRecordCreate appends an immutable deploy record and prunes the workflow's history beyond DeployRecordRetention (oldest first — deploy records are append-only, never updated, so there is no DeployRecordUpdate on the contract).

func (*Store) DeployRecordDeleteByID

func (st *Store) DeployRecordDeleteByID(ctx context.Context, id string) error

func (*Store) DeployRecordDeleteByWorkflowID

func (st *Store) DeployRecordDeleteByWorkflowID(ctx context.Context, workflowID string) error

DeployRecordDeleteByWorkflowID drops the workflow's whole deploy history (called when the workflow is deleted).

func (*Store) DeployRecordFindByID

func (st *Store) DeployRecordFindByID(ctx context.Context, id string) (DeployRecordInterface, error)

func (*Store) DeployRecordList

func (st *Store) DeployRecordList(ctx context.Context, query DeployRecordQueryInterface) ([]DeployRecordInterface, error)

DeployRecordList lists deploy record entities; WithWorkflowID uses EntityListByAttribute like the other per-workflow listings. Sort order applies to the entity created_at (the deploy timestamp).

func (*Store) EdgeCount

func (st *Store) EdgeCount(ctx context.Context, query EdgeQueryInterface) (int64, error)

func (*Store) EdgeCreate

func (st *Store) EdgeCreate(ctx context.Context, edge EdgeInterface) error

func (*Store) EdgeDeleteByID

func (st *Store) EdgeDeleteByID(ctx context.Context, id string) error

func (*Store) EdgeFindByID

func (st *Store) EdgeFindByID(ctx context.Context, id string) (EdgeInterface, error)

func (*Store) EdgeList

func (st *Store) EdgeList(ctx context.Context, query EdgeQueryInterface) ([]EdgeInterface, error)

EdgeList mirrors NodeList — WithWorkflowID goes through EntityListByAttribute (entities×attributes JOIN on workflow_id).

func (*Store) EdgeUpdate

func (st *Store) EdgeUpdate(ctx context.Context, edge EdgeInterface) error

func (*Store) EnableDebug

func (st *Store) EnableDebug(debugEnabled bool) StoreInterface

func (*Store) GetDB

func (st *Store) GetDB() *sql.DB

func (*Store) GetEntityStore

func (st *Store) GetEntityStore() entitystore.StoreInterface

func (*Store) MessageCount

func (st *Store) MessageCount(ctx context.Context, query MessageQueryInterface) (int64, error)

func (*Store) MessageCreate

func (st *Store) MessageCreate(ctx context.Context, message MessageInterface) error

func (*Store) MessageDeleteByID

func (st *Store) MessageDeleteByID(ctx context.Context, id string) error

func (*Store) MessageFindByID

func (st *Store) MessageFindByID(ctx context.Context, id string) (MessageInterface, error)

func (*Store) MessageList

func (st *Store) MessageList(ctx context.Context, query MessageQueryInterface) ([]MessageInterface, error)

func (*Store) MessageUpdate

func (st *Store) MessageUpdate(ctx context.Context, message MessageInterface) error

func (*Store) MigrateViewGroups

func (st *Store) MigrateViewGroups(ctx context.Context) (int, error)

MigrateViewGroups converts each workflow's view.groups array into node_group entities and stamps group_id on the member node entities. Once converted, the "groups" key is stripped from the stored view attribute — since P5 the node_group entities are the authoritative read path (loadWorkflowGroups re-synthesizes the wire shape), so a lingering blob could only go stale. Returns the number of node groups upserted. Idempotent: group entities keep the entry ID, memberships are rewritten, and re-runs see a view attribute with no "groups" key.

func (*Store) MigrateWorkflowBlobAttributes

func (st *Store) MigrateWorkflowBlobAttributes(ctx context.Context) (int, error)

MigrateWorkflowBlobAttributes is a one-shot migration for pre-change nodestore.db files: workflows that still carry the legacy ATTRIBUTE_NODES/ATTRIBUTE_EDGES JSON blobs get real node/edge child entities created (entity type node/edge, workflow_id link), and the blob attributes are removed afterwards.

It is idempotent — workflows already migrated have no blob keys and are skipped (children loaded by loadWorkflowChildren take precedence anyway). Callers invoke it explicitly, e.g. once at startup:

migrated, err := store.MigrateWorkflowBlobAttributes(ctx)

Returns the number of workflows migrated.

func (*Store) MigrateWorkflowGroupsConfig

func (st *Store) MigrateWorkflowGroupsConfig(ctx context.Context, configKey string) (int, error)

MigrateWorkflowGroupsConfig converts the "workflowGroups" section of the named config blob into workflow_group entities, then removes the section so the config store no longer carries structured domain data. Returns the number of groups upserted. Idempotent: groups are keyed by their original ID and updated in place on re-run.

func (*Store) NodeCount

func (st *Store) NodeCount(ctx context.Context, query NodeQueryInterface) (int64, error)

func (*Store) NodeCreate

func (st *Store) NodeCreate(ctx context.Context, node NodeInterface) error

func (*Store) NodeDeleteByID

func (st *Store) NodeDeleteByID(ctx context.Context, id string) error

func (*Store) NodeFindByID

func (st *Store) NodeFindByID(ctx context.Context, id string) (NodeInterface, error)

func (*Store) NodeGroupCount

func (st *Store) NodeGroupCount(ctx context.Context, query NodeGroupQueryInterface) (int64, error)

func (*Store) NodeGroupCreate

func (st *Store) NodeGroupCreate(ctx context.Context, group NodeGroupInterface) error

func (*Store) NodeGroupDeleteByID

func (st *Store) NodeGroupDeleteByID(ctx context.Context, id string) error

func (*Store) NodeGroupFindByID

func (st *Store) NodeGroupFindByID(ctx context.Context, id string) (NodeGroupInterface, error)

func (*Store) NodeGroupList

func (st *Store) NodeGroupList(ctx context.Context, query NodeGroupQueryInterface) ([]NodeGroupInterface, error)

func (*Store) NodeGroupUpdate

func (st *Store) NodeGroupUpdate(ctx context.Context, group NodeGroupInterface) error

func (*Store) NodeList

func (st *Store) NodeList(ctx context.Context, query NodeQueryInterface) ([]NodeInterface, error)

NodeList lists node entities. WithWorkflowID uses entitystore.EntityListByAttribute — a single entities×attributes JOIN on entity type + workflow_id attribute (AttributeQuery has no value filter, so this is the only attribute-value lookup the store offers). Limit/offset/sort are applied in memory, consistent with WorkflowList.

func (*Store) NodeUpdate

func (st *Store) NodeUpdate(ctx context.Context, node NodeInterface) error

func (*Store) WorkflowCount

func (st *Store) WorkflowCount(ctx context.Context, query WorkflowQueryInterface) (int64, error)

func (*Store) WorkflowCreate

func (st *Store) WorkflowCreate(ctx context.Context, workflow WorkflowInterface) error

func (*Store) WorkflowDeleteByID

func (st *Store) WorkflowDeleteByID(ctx context.Context, id string) error

WorkflowDeleteByID deletes the workflow AND its child node/edge entities (cascade — documented behavior; children are never orphaned).

func (*Store) WorkflowFindByID

func (st *Store) WorkflowFindByID(ctx context.Context, id string) (WorkflowInterface, error)

func (*Store) WorkflowFindByName

func (st *Store) WorkflowFindByName(ctx context.Context, name string) (WorkflowInterface, error)

func (*Store) WorkflowGroupCount

func (st *Store) WorkflowGroupCount(ctx context.Context, query WorkflowGroupQueryInterface) (int64, error)

func (*Store) WorkflowGroupCreate

func (st *Store) WorkflowGroupCreate(ctx context.Context, group WorkflowGroupInterface) error

func (*Store) WorkflowGroupDeleteByID

func (st *Store) WorkflowGroupDeleteByID(ctx context.Context, id string) error

func (*Store) WorkflowGroupFindByID

func (st *Store) WorkflowGroupFindByID(ctx context.Context, id string) (WorkflowGroupInterface, error)

func (*Store) WorkflowGroupList

func (st *Store) WorkflowGroupList(ctx context.Context, query WorkflowGroupQueryInterface) ([]WorkflowGroupInterface, error)

func (*Store) WorkflowGroupUpdate

func (st *Store) WorkflowGroupUpdate(ctx context.Context, group WorkflowGroupInterface) error

func (*Store) WorkflowList

func (st *Store) WorkflowList(ctx context.Context, query WorkflowQueryInterface) ([]WorkflowInterface, error)

WorkflowList lists workflows. entitystore can only filter on entity columns (type/handle/dates), so attribute criteria are applied in memory, then offset/limit. Children (nodes/edges) are loaded eagerly per workflow — see workflowFromEntity.

func (*Store) WorkflowTrashByID

func (st *Store) WorkflowTrashByID(ctx context.Context, id string) error

WorkflowTrashByID soft-deletes a workflow into the entitystore trash (children are left in place — restore semantics, same as before)

func (*Store) WorkflowUpdate

func (st *Store) WorkflowUpdate(ctx context.Context, workflow WorkflowInterface) error

type StoreInterface

type StoreInterface interface {
	// GetEntityStore returns the underlying entity store
	GetEntityStore() entitystore.StoreInterface

	// EnableDebug enables debug mode
	EnableDebug(debugEnabled bool) StoreInterface

	WorkflowCount(ctx context.Context, query WorkflowQueryInterface) (int64, error)
	WorkflowCreate(ctx context.Context, workflow WorkflowInterface) error
	WorkflowDeleteByID(ctx context.Context, id string) error
	WorkflowFindByID(ctx context.Context, id string) (WorkflowInterface, error)
	WorkflowFindByName(ctx context.Context, name string) (WorkflowInterface, error)
	WorkflowList(ctx context.Context, query WorkflowQueryInterface) ([]WorkflowInterface, error)
	WorkflowTrashByID(ctx context.Context, id string) error
	WorkflowUpdate(ctx context.Context, workflow WorkflowInterface) error

	NodeCount(ctx context.Context, query NodeQueryInterface) (int64, error)
	NodeCreate(ctx context.Context, node NodeInterface) error
	NodeDeleteByID(ctx context.Context, id string) error
	NodeFindByID(ctx context.Context, id string) (NodeInterface, error)
	NodeList(ctx context.Context, query NodeQueryInterface) ([]NodeInterface, error)
	NodeUpdate(ctx context.Context, node NodeInterface) error

	EdgeCount(ctx context.Context, query EdgeQueryInterface) (int64, error)
	EdgeCreate(ctx context.Context, edge EdgeInterface) error
	EdgeDeleteByID(ctx context.Context, id string) error
	EdgeFindByID(ctx context.Context, id string) (EdgeInterface, error)
	EdgeList(ctx context.Context, query EdgeQueryInterface) ([]EdgeInterface, error)
	EdgeUpdate(ctx context.Context, edge EdgeInterface) error

	MessageCount(ctx context.Context, query MessageQueryInterface) (int64, error)
	MessageCreate(ctx context.Context, message MessageInterface) error
	MessageDeleteByID(ctx context.Context, id string) error
	MessageFindByID(ctx context.Context, id string) (MessageInterface, error)
	MessageList(ctx context.Context, query MessageQueryInterface) ([]MessageInterface, error)
	MessageUpdate(ctx context.Context, message MessageInterface) error

	CredentialCount(ctx context.Context, query CredentialQueryInterface) (int64, error)
	CredentialCreate(ctx context.Context, credential CredentialInterface) error
	CredentialDeleteByID(ctx context.Context, id string) error
	CredentialDeleteByWorkflowID(ctx context.Context, workflowID string) error
	CredentialFindByID(ctx context.Context, id string) (CredentialInterface, error)
	CredentialFindByNode(ctx context.Context, workflowID, nodeID string) (CredentialInterface, error)
	CredentialList(ctx context.Context, query CredentialQueryInterface) ([]CredentialInterface, error)
	CredentialUpdate(ctx context.Context, credential CredentialInterface) error
	// CredentialMapForWorkflow returns nodeID → key → value — the
	// deploy-time credential injection map.
	CredentialMapForWorkflow(ctx context.Context, workflowID string) (map[string]map[string]string, error)
	// CredentialReplaceForWorkflow bulk-replaces a workflow's stored
	// credentials (save path, after extraction).
	CredentialReplaceForWorkflow(ctx context.Context, workflowID string, creds map[string]map[string]string) error

	DeployRecordCount(ctx context.Context, query DeployRecordQueryInterface) (int64, error)
	// DeployRecordCreate appends an immutable record and prunes the
	// workflow's history beyond DeployRecordRetention.
	DeployRecordCreate(ctx context.Context, record DeployRecordInterface) error
	DeployRecordDeleteByID(ctx context.Context, id string) error
	DeployRecordDeleteByWorkflowID(ctx context.Context, workflowID string) error
	DeployRecordFindByID(ctx context.Context, id string) (DeployRecordInterface, error)
	DeployRecordList(ctx context.Context, query DeployRecordQueryInterface) ([]DeployRecordInterface, error)

	NodeGroupCount(ctx context.Context, query NodeGroupQueryInterface) (int64, error)
	NodeGroupCreate(ctx context.Context, group NodeGroupInterface) error
	NodeGroupDeleteByID(ctx context.Context, id string) error
	NodeGroupFindByID(ctx context.Context, id string) (NodeGroupInterface, error)
	NodeGroupList(ctx context.Context, query NodeGroupQueryInterface) ([]NodeGroupInterface, error)
	NodeGroupUpdate(ctx context.Context, group NodeGroupInterface) error

	WorkflowGroupCount(ctx context.Context, query WorkflowGroupQueryInterface) (int64, error)
	WorkflowGroupCreate(ctx context.Context, group WorkflowGroupInterface) error
	WorkflowGroupDeleteByID(ctx context.Context, id string) error
	WorkflowGroupFindByID(ctx context.Context, id string) (WorkflowGroupInterface, error)
	WorkflowGroupList(ctx context.Context, query WorkflowGroupQueryInterface) ([]WorkflowGroupInterface, error)
	WorkflowGroupUpdate(ctx context.Context, group WorkflowGroupInterface) error

	ConfigGet(ctx context.Context, key string) (string, error)
	ConfigSet(ctx context.Context, key string, value string) error
}

StoreInterface is the nodestore contract — entitystore-backed persistence for the flowrunner domain: workflows (with nodes and edges) and messages.

type WorkflowGroupInterface

type WorkflowGroupInterface interface {
	GetID() string
	SetID(id string) WorkflowGroupInterface

	GetName() string
	SetName(name string) WorkflowGroupInterface

	// GetParentID returns the parent group ID ("" = top level).
	GetParentID() string
	SetParentID(parentID string) WorkflowGroupInterface

	// GetWorkflowIDs returns the member workflow IDs.
	GetWorkflowIDs() []string
	SetWorkflowIDs(ids []string) WorkflowGroupInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) WorkflowGroupInterface

	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) WorkflowGroupInterface
}

WorkflowGroupInterface is the entity form of a sidebar workflow grouping entry — previously the global-config "workflowGroups" JSON section shaped {id, name, parentId, workflows:[id]}. Members are the workflow IDs listed in the group.

func NewWorkflowGroup

func NewWorkflowGroup(name string) WorkflowGroupInterface

NewWorkflowGroup creates a new workflow group entity

type WorkflowGroupQueryInterface

type WorkflowGroupQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) WorkflowGroupQueryInterface

	HasParentID() bool
	GetParentID() string
	WithParentID(parentID string) WorkflowGroupQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) WorkflowGroupQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) WorkflowGroupQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) WorkflowGroupQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) WorkflowGroupQueryInterface
}

WorkflowGroupQueryInterface is the fluent query builder for listing and counting workflow group entities.

func WorkflowGroupQuery

func WorkflowGroupQuery() WorkflowGroupQueryInterface

WorkflowGroupQuery creates a new workflow group query builder

type WorkflowInterface

type WorkflowInterface interface {
	GetID() string
	SetID(id string) WorkflowInterface

	GetName() string
	SetName(name string) WorkflowInterface

	GetDescription() string
	SetDescription(description string) WorkflowInterface

	GetNodes() []NodeInterface
	SetNodes(nodes []NodeInterface) WorkflowInterface
	AddNode(node NodeInterface) WorkflowInterface
	FindNodeByID(id string) NodeInterface

	GetEdges() []EdgeInterface
	SetEdges(edges []EdgeInterface) WorkflowInterface
	AddEdge(edge EdgeInterface) WorkflowInterface

	GetView() map[string]any
	SetView(view map[string]any) WorkflowInterface

	GetDeployed() bool
	SetDeployed(deployed bool) WorkflowInterface

	GetCreatedAt() time.Time
	SetCreatedAt(createdAt time.Time) WorkflowInterface

	GetUpdatedAt() time.Time
	SetUpdatedAt(updatedAt time.Time) WorkflowInterface
}

WorkflowInterface is the interface form of flowrunner.Workflow — a complete workflow definition persisted in the entity store.

func DeepCloneWorkflow

func DeepCloneWorkflow(w WorkflowInterface) WorkflowInterface

DeepCloneWorkflow returns a workflow carrying fresh node objects with deep-copied data maps (JSON round-trip — node data is always JSON-typed). The deploy path clones before credential injection so real secrets never land in the caller's stored document — the engine's own cloneWorkflow is shallow (nodes shared).

func ImportNodeRED

func ImportNodeRED(data []byte) (WorkflowInterface, error)

ImportNodeRED converts a Node-RED flow JSON array into a workflow. Regular nodes keep their config keys verbatim in Data (engine node configs use the Node-RED field names); tab membership becomes Data["module"]; wires become edges. Subflow definitions and their internal nodes fold into a single type:"subflow" node.

func NewWorkflow

func NewWorkflow(name string) WorkflowInterface

NewWorkflow creates a new workflow

type WorkflowQueryInterface

type WorkflowQueryInterface interface {
	Validate() error

	HasID() bool
	GetID() string
	WithID(id string) WorkflowQueryInterface

	HasName() bool
	GetName() string
	WithName(name string) WorkflowQueryInterface

	HasDeployed() bool
	GetDeployed() bool
	WithDeployed(deployed bool) WorkflowQueryInterface

	HasLimit() bool
	GetLimit() uint64
	WithLimit(limit uint64) WorkflowQueryInterface

	HasOffset() bool
	GetOffset() uint64
	WithOffset(offset uint64) WorkflowQueryInterface

	GetSortOrder() string
	WithSortOrder(sortOrder string) WorkflowQueryInterface

	IsCountOnly() bool
	WithCountOnly(countOnly bool) WorkflowQueryInterface
}

WorkflowQueryInterface is the fluent query builder for listing and counting workflows.

func WorkflowQuery

func WorkflowQuery() WorkflowQueryInterface

WorkflowQuery creates a new workflow query builder

Jump to

Keyboard shortcuts

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