memorywrite

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package memorywrite holds shared list-mode helpers used by the memory write components (addMemory, updateMemory, upsertMemory).

When list mode is enabled, the component evaluates a list expression at execute time and writes one memory row per element, exposing each element as a configurable iteration variable for the per-item value expressions.

Index

Constants

View Source
const DefaultItemVariable = "item"

Variables

This section is empty.

Functions

func AppendUniqueRecords

func AppendUniqueRecords(
	records []core.CanvasMemoryRecord,
	positions map[uuid.UUID]int,
	next []core.CanvasMemoryRecord,
) []core.CanvasMemoryRecord

AppendUniqueRecords appends records by physical memory ID. If a record is seen again, its latest values replace the previous entry without increasing the reported count.

func FieldNames

func FieldNames(pairs []NameValuePair) []string

FieldNames returns the trimmed, deduplicated field names from a list of pairs in declaration order. Pairs with empty names are skipped.

func RecordValues

func RecordValues(records []core.CanvasMemoryRecord) []any

RecordValues returns the value payloads used by component outputs while keeping record IDs internal to the execution context.

func ResolveAllItemValues

func ResolveAllItemValues(
	items []any,
	mode ListMode,
	pairs []NameValuePair,
	expressions core.ExpressionContext,
) ([]map[string]any, error)

ResolveAllItemValues evaluates valueList for every list element before any memory writes run, so expression failures do not leave partial writes.

func ResolvePairs

func ResolvePairs(pairs []NameValuePair, variables map[string]any, expressions core.ExpressionContext) (map[string]any, error)

ResolvePairs evaluates each pair's value with the provided variables and returns a map keyed by trimmed name. Pairs with empty names are skipped.

func ResolveValue

func ResolveValue(value any, variables map[string]any, expressions core.ExpressionContext) (any, error)

ResolveValue evaluates a single value field for a per-item iteration.

String values are evaluated as bare expr expressions with the iteration variables merged in. Anything else (already resolved at Build time, for example via a {{ }} template) is returned unchanged so that the same resolved value is written for every list element.

Types

type ListMode

type ListMode struct {
	IterateList  bool   `mapstructure:"iterateList" json:"iterateList,omitempty"`
	ListSource   string `mapstructure:"listSource" json:"listSource,omitempty"`
	ItemVariable string `mapstructure:"itemVariable" json:"itemVariable,omitempty"`
}

ListMode captures the optional list-mode configuration shared by every memory write component.

func (ListMode) EvaluateList

func (m ListMode) EvaluateList(expressions core.ExpressionContext) ([]any, error)

EvaluateList resolves the configured list expression to a slice of items. It accepts []any directly or coerces common slice/array shapes.

func (ListMode) Normalize

func (m ListMode) Normalize() ListMode

Normalize trims whitespace and applies the default iteration variable.

func (ListMode) Validate

func (m ListMode) Validate() error

Validate ensures list-mode configuration is internally consistent. It only validates when IterateList is true.

func (ListMode) Variables

func (m ListMode) Variables(item any) map[string]any

Variables builds the per-item set of extra expression variables (just the iteration variable for now; future enhancements can add index/totalCount).

type NameValuePair

type NameValuePair struct {
	Name  string `json:"name"`
	Value any    `json:"value"`
}

NameValuePair is the common shape for configured name/value field lists.

Jump to

Keyboard shortcuts

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