{"modulePath":"github.com/the-dev-tools/dev-tools/packages/server","version":"v0.0.0-20261108121446-820be1ff163d","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package expression\n\n## Constants\n\n```go\nconst (\n\t// FileRefPrefix is the prefix for file references in expressions.\n\tFileRefPrefix = \"#file:\"\n\t// EnvRefPrefix is the prefix for environment variable references.\n\tEnvRefPrefix = \"#env:\"\n)\n```\n\n```go\nconst TimeLayout = \"2006-01-02T15:04:05.000Z07:00\"\n```\nTimeLayout is how a time value (now(), date(...)) is written into a request: RFC 3339 with milliseconds, e.g. 2026-10-11T15:59:15.978+03:00.\n\n## Variables\n\n```go\nvar (\n\tErrNilEnv          = errors.New(\"cannot evaluate on nil UnifiedEnv\")\n\tErrKeyNotFound     = errors.New(\"key not found\")\n\tErrEmptyPath       = errors.New(\"empty path\")\n\tErrEmptyExpression = errors.New(\"empty expression\")\n)\n```\nCommon errors\n\n## Functions\n\n```go\nfunc ExpressionEvaluateAsIter(ctx context.Context, env Env, expressionString string) (any, error)\n```\nExpressionEvaluateAsIter evaluates the expression and returns an iterator sequence (iter.Seq\\[any] for slices, iter.Seq2\\[string, any] for maps) if the result is iterable. Otherwise, it returns an error.\n\n```go\nfunc ExpressionEvaluateAsIterWithTracking(ctx context.Context, env Env, expressionString string, tracker *tracking.VariableTracker) (any, error)\n```\nExpressionEvaluateAsIterWithTracking evaluates an iterable expression with variable access tracking\n\n```go\nfunc ExpressionEvaluteAsArray(ctx context.Context, env Env, expressionString string) ([]any, error)\n```\n\n```go\nfunc ExpressionEvaluteAsArrayWithTracking(ctx context.Context, env Env, expressionString string, tracker *tracking.VariableTracker) ([]any, error)\n```\nExpressionEvaluteAsArrayWithTracking evaluates an array expression with variable access tracking\n\n```go\nfunc ExpressionEvaluteAsBool(ctx context.Context, env Env, expressionString string) (bool, error)\n```\n\n```go\nfunc ExpressionEvaluteAsBoolWithTracking(ctx context.Context, env Env, expressionString string, tracker *tracking.VariableTracker) (bool, error)\n```\nExpressionEvaluteAsBoolWithTracking evaluates a boolean expression with variable access tracking\n\n```go\nfunc ExtractExprIdentifiers(exprStr string) []string\n```\nExtractExprIdentifiers extracts top-level identifiers from a pure expr-lang expression. It performs a simple lexical scan to find variable references without full AST parsing. Returns identifiers like \"node\", \"env\" from expressions like \"node.response.status == 200\".\n\n```go\nfunc ExtractExprPaths(exprStr string) []string\n```\nExtractExprPaths extracts full dot-notation paths from expr-lang expressions. Uses AST parsing for robust extraction. Example: \"node.response.status == 200\" → \\[\"node.response.status\"]\n\n```go\nfunc ExtractVarKey(s string) string\n```\nExtractVarKey extracts the variable key from a {{ key }} pattern. Returns the key without braces, or empty string if not a valid pattern.\n\n```go\nfunc ExtractVarKeysFromMultiple(strs ...string) []string\n```\nExtractVarKeysFromMultiple extracts all unique variable keys from multiple strings.\n\n```go\nfunc ExtractVarRefs(raw string) []string\n```\nExtractVarRefs extracts all variable references from a string without resolving them. Returns a deduplicated list of variable references (including #env: and #file: refs).\n\n```go\nfunc FormatPath(segments []pathSegment) string\n```\nFormatPath formats path segments back into a string.\n\n```go\nfunc GetEnvVarName(s string) string\n```\nGetEnvVarName extracts the environment variable name from a reference. Returns empty string if not an env reference.\n\n```go\nfunc GetFilePath(s string) string\n```\nGetFilePath extracts the file path from a file reference. Returns empty string if not a file reference.\n\n```go\nfunc HasVars(raw string) bool\n```\nHasVars checks if a string contains any {{ }} variable references.\n\n```go\nfunc IsEnvReference(s string) bool\n```\nIsEnvReference checks if a string is an environment variable reference (#env:VAR).\n\n```go\nfunc IsFileReference(s string) bool\n```\nIsFileReference checks if a string is a file reference (#file:/path).\n\n```go\nfunc IsVarPattern(s string) bool\n```\nIsVarPattern checks if a string is exactly a {{ key }} pattern (no surrounding text).\n\n```go\nfunc NewCompileError(expr string, cause error) error\n```\nNewCompileError creates an error for compilation failures.\n\n```go\nfunc NewResolveError(path string, cause error) error\n```\nNewResolveError creates an error for variable resolution failures.\n\n```go\nfunc NewRunError(expr string, cause error) error\n```\nNewRunError creates an error for runtime evaluation failures.\n\n```go\nfunc NormalizeExpression(ctx context.Context, expressionString string, varsystem varsystem.VarMap) (string, error)\n```\n\n```go\nfunc ReadEnvVar(envRef string) (string, error)\n```\nReadEnvVar reads the value of an environment variable reference. Returns the value and whether it was found.\n\n```go\nfunc ReadFileContent(fileRef string) (string, error)\n```\nReadFileContent reads the content of a file reference. Returns the file content as a string, or an error if the file cannot be read.\n\n```go\nfunc ResolvePath(data map[string]any, path string) (any, bool)\n```\nResolvePath looks up a value in nested maps using dot notation and array indexing. Supports paths like:\n\n  - \"name\" (simple key)\n  - \"node.response.body\" (nested path)\n  - \"items\\[0]\" (array index)\n  - \"items\\[0].id\" (array index with nested path)\n  - \"nodes\\[0].response.headers.Content-Type\" (mixed)\n\nFor backwards compatibility with flat key maps (e.g., from varsystem), this function first checks if the path exists as a direct key in the map before attempting path resolution.\n\n```go\nfunc SetPath(data map[string]any, path string, value any) error\n```\nSetPath sets a value at a dotted path, creating intermediate maps as needed. Array indices must reference existing arrays - this function won't create arrays.\n\n## Types\n\n```go\ntype Env struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewEnv(varMap map[string]any) Env\n```\n\n```go\nfunc NewEnvFromStruct(s any) (Env, error)\n```\n\n```go\nfunc (e Env) GetVarMap() map[string]any\n```\nGetVarMap returns the internal varMap for debugging purposes\n\n```go\ntype EnvReferenceError struct {\n\tVarName string\n\tCause   error\n}\n```\nEnvReferenceError represents an error when reading a #env: reference.\n\n```go\nfunc (e *EnvReferenceError) Error() string\n```\n\n```go\nfunc (e *EnvReferenceError) Unwrap() error\n```\n\n```go\ntype ExpressionError struct {\n\tExpression string // The expression that failed\n\tPhase      string // \"compile\", \"run\", or \"resolve\"\n\tCause      error  // The underlying error\n}\n```\nExpressionError represents a structured error from expression evaluation.\n\n```go\nfunc (e *ExpressionError) Error() string\n```\n\n```go\nfunc (e *ExpressionError) Unwrap() error\n```\n\n```go\ntype FileReferenceError struct {\n\tPath  string\n\tCause error\n}\n```\nFileReferenceError represents an error when reading a #file: reference.\n\n```go\nfunc (e *FileReferenceError) Error() string\n```\n\n```go\nfunc (e *FileReferenceError) Unwrap() error\n```\n\n```go\ntype InterpolationError struct {\n\tInput  string // The original input string\n\tVarRef string // The variable reference that failed\n\tCause  error  // The underlying error\n}\n```\nInterpolationError represents an error during {{ }} interpolation.\n\n```go\nfunc (e *InterpolationError) Error() string\n```\n\n```go\nfunc (e *InterpolationError) Unwrap() error\n```\n\n```go\ntype InterpolationResult struct {\n\tValue    string         // The interpolated string\n\tReadVars map[string]any // Variables that were read during interpolation\n}\n```\nInterpolationResult holds the result of interpolation along with tracked reads.\n\n```go\ntype UnifiedEnv struct {\n\t// contains filtered or unexported fields\n}\n```\nUnifiedEnv provides a unified interface for variable resolution, expression evaluation, and string interpolation. It operates on hierarchical (non-flattened) data.\n\n```go\nfunc NewUnifiedEnv(data map[string]any) *UnifiedEnv\n```\nNewUnifiedEnv creates a new UnifiedEnv with the given hierarchical data.\n\n```go\nfunc (e *UnifiedEnv) Clone() *UnifiedEnv\n```\nClone creates a deep copy of the UnifiedEnv.\n\n```go\nfunc (e *UnifiedEnv) DescribeValues(exprStr string) []string\n```\nDescribeValues lists each variable path the expression reads with its current value, in the order the paths appear, e.g. \\`response.duration = 5120\\`. It reads without tracking. Objects and arrays are summarised, values under sensitive names are redacted, and long strings are truncated.\n\n```go\nfunc (e *UnifiedEnv) Eval(ctx context.Context, exprStr string) (any, error)\n```\nEval evaluates a pure expr-lang expression and returns the result. This is the fast path for condition fields - NO {{ }} interpolation. Use Interpolate() for text fields that need {{ }} support.\n\n```go\nfunc (e *UnifiedEnv) EvalBool(ctx context.Context, exprStr string) (bool, error)\n```\nEvalBool evaluates a pure expr-lang expression and returns the result as a boolean. This is the fast path for condition fields (if node) - NO {{ }} interpolation.\n\n```go\nfunc (e *UnifiedEnv) EvalInterpolated(ctx context.Context, exprStr string) (any, error)\n```\nEvalInterpolated first interpolates {{ }} patterns, then evaluates the result. Use this when you need both interpolation AND expression evaluation.\n\nFor single {{ expr }} patterns, typed values (arrays, maps, numbers, bools) are preserved without stringification. For multi-expression strings like \"{{ a }} + {{ b }}\", interpolation produces a string which is then evaluated as an expression.\n\n```go\nfunc (e *UnifiedEnv) EvalIter(ctx context.Context, exprStr string) (any, error)\n```\nEvalIter evaluates a pure expr-lang expression and returns an iterator. Returns iter.Seq\\[any] for slices/arrays, or iter.Seq2\\[string, any] for maps. This is the fast path for loop fields (for/foreach node) - NO {{ }} interpolation.\n\n```go\nfunc (e *UnifiedEnv) EvalString(ctx context.Context, exprStr string) (string, error)\n```\nEvalString evaluates an expression and returns the result as a string.\n\n```go\nfunc (e *UnifiedEnv) Get(path string) (any, bool)\n```\nGet retrieves a value at the given path and optionally tracks the read. The path can use dot notation (e.g., \"node.response.body\") and array indexing (e.g., \"items\\[0].id\").\n\n```go\nfunc (e *UnifiedEnv) GetData() map[string]any\n```\nGetData returns the underlying hierarchical data map.\n\n```go\nfunc (e *UnifiedEnv) GetTracker() *tracking.VariableTracker\n```\nGetTracker returns the variable tracker (may be nil).\n\n```go\nfunc (e *UnifiedEnv) Has(path string) bool\n```\nHas returns true if a value exists at the given path.\n\n```go\nfunc (e *UnifiedEnv) Interpolate(raw string) (string, error)\n```\nInterpolate replaces {{ varKey }} patterns with resolved values from the environment. Supports:\n\n  - {{ path.to.value }} - Nested path resolution\n  - {{ #env:VAR\\_NAME }} - Environment variables\n  - {{ #file:/path/to/file }} - File contents\n  - {{ items\\[0].id }} - Array access\n\nThe context parameter is reserved for future use (cancellation, timeouts).\n\n```go\nfunc (e *UnifiedEnv) InterpolateCtx(ctx context.Context, raw string) (string, error)\n```\nInterpolateCtx is like Interpolate but accepts a context for cancellation.\n\n```go\nfunc (e *UnifiedEnv) InterpolateWithResult(raw string) (InterpolationResult, error)\n```\nInterpolateWithResult replaces {{ varKey }} patterns and returns both the result and a map of all variables that were read during interpolation.\n\n```go\nfunc (e *UnifiedEnv) Merge(other *UnifiedEnv) *UnifiedEnv\n```\nMerge combines another UnifiedEnv's data into this one. Values from other take precedence in case of conflicts.\n\n```go\nfunc (e *UnifiedEnv) ResolveValue(raw string) (any, error)\n```\nResolveValue resolves an input that may contain {{ expr }} patterns. - If input is exactly \"{{ expr }}\", returns the typed value (bool, int, etc.) - If input has text around {{ }}, returns interpolated string - If input has no {{ }}, returns the input string as-is\n\n```go\nfunc (e *UnifiedEnv) Set(path string, value any) error\n```\nSet sets a value at the given path, creating intermediate maps as needed.\n\n```go\nfunc (e *UnifiedEnv) WithFunc(name string, fn any) *UnifiedEnv\n```\nWithFunc returns a copy of the UnifiedEnv with a custom function added. Custom functions are available in expr-lang expressions.\n\n```go\nfunc (e *UnifiedEnv) WithTracking(t *tracking.VariableTracker) *UnifiedEnv\n```\nWithTracking returns a copy of the UnifiedEnv with tracking enabled. Variable reads will be recorded in the provided tracker.\n\n","path":"github.com/the-dev-tools/dev-tools/packages/server/pkg/expression","name":"expression","synopsis":"","isRedistributable":true}
