Documentation
¶
Overview ¶
Package templating provides shared template evaluation, validation, normalization, and storage-reference handling for BubuStack runtimes.
Index ¶
- Constants
- func ExtractStepReferences(value string) []string
- func ExtractStepReferencesWithError(value string) ([]string, error)
- func HasStorageRefsInStepVars(text string, vars map[string]any) bool
- func ValidateJSONTemplates(raw []byte, scope ExpressionScope) error
- func ValidateTemplateString(value string, scope ExpressionScope) error
- type CacheConfig
- type CachedTemplate
- type Config
- type ErrEvaluationBlocked
- type ErrOffloadedDataUsage
- type Evaluator
- func (e *Evaluator) Close()
- func (e *Evaluator) EvaluateCondition(ctx context.Context, expr string, vars map[string]any) (bool, error)
- func (e *Evaluator) ResolveTemplateString(ctx context.Context, value string, vars map[string]any) (any, error)
- func (e *Evaluator) ResolveValue(ctx context.Context, value any, vars map[string]any) (any, error)
- func (e *Evaluator) ResolveWithInputs(ctx context.Context, with map[string]any, vars map[string]any) (map[string]any, error)
- type ExpressionScope
- type TemplateCache
Constants ¶
const ( // TemplateExprKey marks an object value as a template expression wrapper. TemplateExprKey = "$bubuTemplate" // TemplateVarsKey carries per-expression template variables. TemplateVarsKey = "$bubuTemplateVars" // StorageRefKey marks a value as offloaded storage-backed data. StorageRefKey = "$bubuStorageRef" // StoragePathKey identifies the nested path within an offloaded storage object. StoragePathKey = "$bubuStoragePath" )
const ( // RootInputs is the template root for resolved step inputs. RootInputs = "inputs" // RootSteps is the template root for upstream step outputs. RootSteps = "steps" // RootPacket is the template root for transport packet metadata. RootPacket = "packet" )
Variables ¶
This section is empty.
Functions ¶
func ExtractStepReferences ¶
ExtractStepReferences parses a Go template string and returns the names of steps referenced via `(index .steps "name")` or `.steps.name` patterns. Returns nil if no step references are found.
func ExtractStepReferencesWithError ¶
ExtractStepReferencesWithError returns step references or a parse error.
func HasStorageRefsInStepVars ¶
HasStorageRefsInStepVars parses a template string, extracts referenced step names, and checks whether any of them contain $bubuStorageRef in their output.
func ValidateJSONTemplates ¶
func ValidateJSONTemplates(raw []byte, scope ExpressionScope) error
ValidateJSONTemplates walks a JSON blob and validates any template strings.
func ValidateTemplateString ¶
func ValidateTemplateString(value string, scope ExpressionScope) error
ValidateTemplateString validates a single template string against the scope.
Types ¶
type CacheConfig ¶
CacheConfig controls template caching.
func DefaultCacheConfig ¶
func DefaultCacheConfig() *CacheConfig
DefaultCacheConfig returns the production-oriented cache defaults.
type CachedTemplate ¶
type CachedTemplate struct {
Template *template.Template
CachedAt time.Time
LastUsed time.Time
HitCount int64
Hash string
}
CachedTemplate holds a parsed template and metadata.
type Config ¶
type Config struct {
EvaluationTimeout time.Duration
MaxOutputBytes int
// Deterministic disables non-deterministic helpers (now/rand).
Deterministic bool
}
Config controls template evaluation behavior.
type ErrEvaluationBlocked ¶
type ErrEvaluationBlocked struct {
Reason string
}
ErrEvaluationBlocked indicates evaluation is waiting on upstream data.
func (*ErrEvaluationBlocked) Error ¶
func (e *ErrEvaluationBlocked) Error() string
type ErrOffloadedDataUsage ¶
type ErrOffloadedDataUsage struct {
Reason string
}
ErrOffloadedDataUsage indicates a template requires offloaded payload data.
func (*ErrOffloadedDataUsage) Error ¶
func (e *ErrOffloadedDataUsage) Error() string
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator resolves BubuStack template expressions against JSON-like values.
func (*Evaluator) Close ¶
func (e *Evaluator) Close()
Close releases the evaluator's background resources.
func (*Evaluator) EvaluateCondition ¶
func (e *Evaluator) EvaluateCondition(ctx context.Context, expr string, vars map[string]any) (bool, error)
EvaluateCondition evaluates a boolean template.
func (*Evaluator) ResolveTemplateString ¶
func (e *Evaluator) ResolveTemplateString(ctx context.Context, value string, vars map[string]any) (any, error)
ResolveTemplateString resolves a single template string with the provided vars.
func (*Evaluator) ResolveValue ¶
ResolveValue resolves template expressions within any JSON-like value. This is a general-purpose helper for SDK callers that need to resolve templates outside of an object-only context.
type ExpressionScope ¶
type ExpressionScope struct {
Name string
AllowNow bool
AllowRandom bool
AllowedRoots map[string]struct{}
AllowRange bool
}
ExpressionScope defines allowed template contexts for validation.
func NewExpressionScope ¶
func NewExpressionScope( name string, allowNow bool, allowRandom bool, allowRange bool, roots ...string, ) ExpressionScope
NewExpressionScope builds a scope with provided roots.
type TemplateCache ¶
type TemplateCache struct {
// contains filtered or unexported fields
}
TemplateCache caches parsed templates.
func NewTemplateCache ¶
func NewTemplateCache(cfg *CacheConfig) *TemplateCache
NewTemplateCache builds a cache for parsed templates.
func (*TemplateCache) GetOrParse ¶
func (c *TemplateCache) GetOrParse( ctx context.Context, key string, parseFn func() (*template.Template, error), ) (*template.Template, error)
GetOrParse returns a cached template or parses and stores a new one.
func (*TemplateCache) Stop ¶
func (c *TemplateCache) Stop()
Stop terminates the background cleanup loop.