Help us shape the future of Go! Take the 2026 Go Developer Survey

nodes

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package nodes implements every flow node type, one file each, and registers them with their parameter specs (Specs). The specs are the single source for the validator's parameter checks and for the generated node reference.

A node only describes its work. Whatever needs the scheduler, the network, the clock or the workspace goes through State.Runtime, which the engine implements; this package never imports the engine.

Index

Constants

This section is empty.

Variables

View Source
var ErrFileName = errors.New("not a plain file name")

ErrFileName is wrapped by Runtime.WriteFile when a name is not a plain file name (FLW-RUN-017).

Functions

func Extract

func Extract(x model.Extraction, resp *Response, jar []httpx.StoredCookie) (any, error)

Extract reads one value from a response (or the cookie jar). It is shared by extract nodes and a request version's extract: block.

func Failed

func Failed(node, check, message string, warn bool, emit Emitter) diag.List

Failed reports a failed assertion: a warning through emit when warn is set, otherwise an error diagnostic. Shared with a version's assert: list.

func ParseDelay

func ParseDelay(text string) (lo, hi time.Duration, err error)

ParseDelay reads "2s" or "lo..hi" (lo ≤ hi); shared with validate.

func Reference

func Reference() []byte

Reference renders the node reference (docs/reference/nodes.md) from Specs: one section per group, one entry per type, in catalogue order.

Types

type Emitter

type Emitter interface {
	Log(node, message string)
	Warn(d diag.Diagnostic)
	Digest(node, format, text string)
}

Emitter receives what nodes report while running. Implementations must be safe for concurrent use: nodes in different lanes call it at once.

type HTTPCall

type HTTPCall struct {
	Method, URL    string
	Headers, Query map[string]string
	Body           any
}

HTTPCall is an ad-hoc HTTP call (fetch, webhook, digest webhook). A string Body is sent as text; any other non-nil value as JSON.

type HTTPResult

type HTTPResult struct {
	Response *Response
	Status   Status
	Diags    diag.List
}

HTTPResult is an ad-hoc call's response (nil when it failed).

type Lane

type Lane struct {
	Label    string // "[3]", "b1", "then"
	Nodes    []model.Node
	OwnVars  bool // writes stay in the lane (batch iterations)
	OwnNodes bool // nodes.<id> stay in the lane (batch, run_till)
	Item     any
	Index    int
	HasItem  bool // item and index are in scope
}

Lane is one node list a container runs.

type LaneOptions

type LaneOptions struct {
	Concurrency int    // lanes in flight; capped by the run-wide limit
	Wait        string // "all" (default), "any" or "first-success"
	LaneJars    bool   // give lanes their own cookie jars per http.cookies
}

LaneOptions say how lanes run.

type LaneResult

type LaneResult struct {
	Status Status
	Vars   map[string]any
	Nodes  map[string]any
	Diags  diag.List
	First  bool
}

LaneResult is one lane's outcome. Vars and Nodes are the lane's own layers (empty unless the lane had them). First marks the lane that settled a wait of any or first-success.

type Masker

type Masker interface{ String(s string) string }

Masker hides secrets in text (vault.Masker, or the engine's live one).

type MutableRequest

type MutableRequest struct {
	Mu        sync.Mutex
	Method    *string
	URL       *string
	Headers   map[string]string
	Query     map[string]string
	Body      *any           // replaces the whole body
	BodyPaths map[string]any // dot paths into a JSON body
	Cookies   map[string]string
}

MutableRequest collects what pre-hook set nodes change. The engine applies it on top of the rendered request, so overrides win. Mu guards every field: set nodes in parallel hook branches write concurrently.

type Outcome

type Outcome struct {
	Outputs map[string]any
	Diags   diag.List
	Status  Status
}

Outcome is what a node produced: Outputs become nodes.<id> (written once). An empty Status means failed when Diags has errors, else passed.

type Param

type Param struct {
	Name     string
	Kind     ParamKind
	Required bool
	Enum     []string
	Min, Max int64 // ParamInt bounds; 0 and 0 mean unbounded
	Doc      string
}

Param describes one node parameter.

type ParamKind

type ParamKind int

ParamKind is what a node parameter holds.

const (
	ParamString   ParamKind = iota + 1 // a literal string (a set target, a var name)
	ParamText                          // a {{…}} template
	ParamExpr                          // a bare expression (check, until)
	ParamDuration                      // a duration literal: 500ms, 2s
	ParamInt
	ParamBool
	ParamEnum
	ParamName // a plain file name (names.Valid)
	ParamAny  // any value; strings inside are templates
	ParamMap  // a mapping of names to templates
)

Parameter kinds.

type Phase

type Phase int

Phase is when a node runs relative to its request.

const (
	PhaseFlow Phase = iota
	PhasePre
	PhasePost
)

Phases. PhaseFlow is a node of a flow, with no request in reach.

type RequestCall

type RequestCall struct {
	Ref     model.Ref
	Version string
	Hooks   model.HookControl
	With    map[string]any
	Headers map[string]string
}

RequestCall is a saved request to run from a request node.

type Response

type Response struct {
	Status int
	Header http.Header
	Body   any    // parsed JSON, or the text
	Text   string // the body as text (for regex extraction)
	Time   time.Duration
}

Response is the response as nodes see it.

func (*Response) Values

func (r *Response) Values() map[string]any

Values is the response scope for templates: status, headers (by lower- case name), body, text, time and cookies (by name).

type Runner

type Runner func(ctx context.Context, n model.Node, s *State) Outcome

Runner runs one node.

func Lookup

func Lookup(t model.NodeType) (Runner, bool)

Lookup returns the runner for a node type.

type Runtime

type Runtime interface {
	// Lanes runs node lists (parallel branches, batch or run_till
	// iterations) under the run's concurrency and branch-error policies.
	// Results are in lane order.
	Lanes(ctx context.Context, lanes []Lane, o LaneOptions) []LaneResult
	Request(ctx context.Context, c RequestCall) Outcome
	Subflow(ctx context.Context, ref model.Ref, inputs map[string]any) Outcome
	HTTP(ctx context.Context, c HTTPCall) HTTPResult
	// Background sends c without waiting (webhook wait: false); failures
	// become FLW-RUN-016 warnings.
	Background(node string, c HTTPCall)
	Sleep(ctx context.Context, d time.Duration) error
	// StopRun ends the run: running steps finish, no step that has not
	// started will (a stop node). Stopped reports it, for loops.
	StopRun()
	Stopped() bool
	Now() time.Time
	RandomDuration(lo, hi time.Duration) time.Duration // seeded by the run
	// Report is the report so far of the whole run ("run") or of a
	// finished node, by id, as seen from the calling node.
	Report(of string) (report.Run, bool)
	// WriteFile writes under the run's data directory ("saved" or
	// "digests"). name is one or more "/"-separated segments, each a
	// plain file name; anything else wraps ErrFileName.
	WriteFile(dir, name string, data []byte, appendTo bool) (string, error)
}

Runtime is what the engine does for nodes: everything that needs the scheduler, the network, the clock or the workspace. Nodes describe the work; they never start goroutines or open connections themselves.

type Spec

type Spec struct {
	Type    model.NodeType
	Group   string // Call, Data, Check, Control, Output
	Summary string
	Params  []Param
	// MapForm means every key that is not a Param is "<var>: template".
	MapForm bool
	// Typed lists the keys the codec reads into typed fields (request,
	// flow, with, body, branches, …); they are not Params.
	Typed []string
	Run   Runner
}

Spec describes a node type: its catalogue entry, parameters and runner.

func Specs

func Specs() []Spec

Specs returns every registered node type in catalogue order.

func (Spec) Param

func (s Spec) Param(name string) (Param, bool)

Param returns the spec's parameter named name.

type State

type State struct {
	Phase    Phase
	Path     string               // the node instance's path, e.g. users[2]/create
	Vars     *Vars                // vars.<name>
	Request  *MutableRequest      // overrides for the request; nil outside pre-hooks
	Response *Response            // nil before the response
	Cookies  []httpx.StoredCookie // the run's cookie jar, for extract from: cookie
	// Scope returns the template scope for the current state (vars,
	// request, response, env, secrets, …); it is rebuilt by the engine on
	// each call so nodes always see the latest values.
	Scope  func() template.Scope
	Emit   Emitter
	Masker Masker
	// Secret registers a value derived from a secret (a template result
	// that read secret.*), so it is masked wherever it appears later. Nil
	// means nothing is registered.
	Secret func(v any)
	// Runtime does what nodes cannot do alone; nil only in contexts
	// that need none of it.
	Runtime Runtime
}

State is what a node can read and change.

type Status

type Status string

Status is a node or lane outcome. The values match engine.Status.

const (
	StatusPassed    Status = "passed"
	StatusFailed    Status = "failed"
	StatusError     Status = "error"
	StatusCancelled Status = "cancelled"
	StatusSkipped   Status = "skipped"
)

Statuses.

type Vars

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

Vars is a layered variable store: writes go to the own layer, reads fall back to the parent's. It is safe for concurrent use; mu guards own.

func NewVars

func NewVars(parent *Vars) *Vars

NewVars returns an empty layer over parent (nil for a root).

func (*Vars) Get

func (v *Vars) Get(name string) (any, bool)

Get returns a variable from this layer or the nearest parent having it.

func (*Vars) Own

func (v *Vars) Own() map[string]any

Own is a copy of this layer alone (a batch iteration's variables).

func (*Vars) Set

func (v *Vars) Set(name string, value any)

Set writes name in this layer.

func (*Vars) Snapshot

func (v *Vars) Snapshot() map[string]any

Snapshot is a merged copy of every layer, nearer layers winning.

Jump to

Keyboard shortcuts

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