Documentation
¶
Overview ¶
Package workflows provides minimal registry types for workflow ent templates
Index ¶
- Variables
- func AllowBypassContext(ctx context.Context) context.Context
- func AllowBypassContextWithOrg(ctx context.Context) (context.Context, string, error)
- func AllowContext(ctx context.Context) context.Context
- func AllowContextWithOrg(ctx context.Context) (context.Context, string, error)
- func ApplyObjectFieldUpdates(ctx context.Context, client *generated.Client, ...) error
- func BuildAssignmentContext(ctx context.Context, client *generated.Client, instanceID string) (map[string]any, error)
- func BuildCELVars(obj *Object, changedFields []string, changedEdges []string, ...) map[string]any
- func IsWorkflowBypass(ctx context.Context) bool
- func LoadWorkflowObject(ctx context.Context, client *generated.Client, schemaType string, ...) (any, error)
- func NewCELEnvWithConfig(cfg *Config) (*cel.Env, error)
- func NewCelEnv(opts ...ConfigOpts) (*cel.Env, error)
- func ObjectOwnerID(ctx context.Context, client *generated.Client, ...) (string, error)
- func OrganizationOwnerIDs(ctx context.Context, client *generated.Client, orgID string) ([]string, error)
- func RegisterAssignmentContextBuilder(builder AssignmentContextBuilder)
- func RegisterCELContextBuilder(builder CELContextBuilder)
- func RegisterObjectRefQueryBuilder(builder ObjectRefQueryBuilder)
- func RegisterObjectRefResolver(resolver func(*generated.WorkflowObjectRef) (*Object, bool))
- func StringField(node any, field string) string
- func WithContext(ctx context.Context) context.Context
- func WorkflowMetadata() []generated.WorkflowObjectTypeInfo
- type AssignmentContextBuilder
- type CELConfig
- type CELContextBuilder
- type Config
- type ConfigOpts
- func WithCELComprehensionNestingLimit(limit int) ConfigOpts
- func WithCELCostLimit(limit uint64) ConfigOpts
- func WithCELCrossTypeNumericComparisons(enabled bool) ConfigOpts
- func WithCELEvalOptimize(enabled bool) ConfigOpts
- func WithCELExtendedValidations(enabled bool) ConfigOpts
- func WithCELIdentifierEscapeSyntax(enabled bool) ConfigOpts
- func WithCELInterruptCheckFrequency(freq uint) ConfigOpts
- func WithCELMacroCallTracking(enabled bool) ConfigOpts
- func WithCELOptionalTypes(enabled bool) ConfigOpts
- func WithCELParserExpressionSizeLimit(limit int) ConfigOpts
- func WithCELParserRecursionLimit(limit int) ConfigOpts
- func WithCELTimeout(timeout time.Duration) ConfigOpts
- func WithCELTrackState(enabled bool) ConfigOpts
- func WithConfig(cfg Config) ConfigOpts
- func WithEnabled(enabled bool) ConfigOpts
- type Object
- type ObjectRefQueryBuilder
- type TargetConfig
- type WorkflowBypassContextKey
Constants ¶
This section is empty.
Variables ¶
var ( // ErrWorkflowNotFound is returned when a workflow instance cannot be found ErrWorkflowNotFound = errors.New("workflow instance not found") // ErrNoProposedChanges is returned when attempting to apply changes but none exist ErrNoProposedChanges = errors.New("no proposed changes to apply") // ErrWorkflowAlreadyActive is returned when trying to start a workflow on an object that already has one ErrWorkflowAlreadyActive = errors.New("workflow already active for this object") // ErrInvalidWorkflowState is returned when a workflow operation is attempted on an instance in an invalid state ErrInvalidWorkflowState = errors.New("invalid workflow state for this operation") // ErrInsufficientApprovals is returned when trying to complete a workflow without required approvals ErrInsufficientApprovals = errors.New("insufficient approvals to complete workflow") ErrUnauthorizedApproval = errors.New("user not authorized to approve this workflow") // ErrFieldNotWorkflowEligible is returned when proposed changes include non-eligible fields ErrFieldNotWorkflowEligible = errors.New("field is not eligible for workflow modification") // ErrUnsupportedObjectType is returned when a workflow is triggered for an unsupported object type ErrUnsupportedObjectType = errors.New("object type does not support workflows") // ErrMissingObjectID is returned when a workflow object is missing an ID ErrMissingObjectID = errors.New("workflow object is missing an ID") // ErrFailedToBuildCELEnv is returned when the CEL environment cannot be built ErrFailedToBuildCELEnv = errors.New("failed to build CEL environment") )
Functions ¶
func AllowBypassContext ¶ added in v1.4.0
AllowBypassContext sets workflow bypass and allow decision for internal workflow operations.
func AllowBypassContextWithOrg ¶ added in v1.4.0
AllowBypassContextWithOrg returns an allow/bypass context plus the organization ID.
func AllowContext ¶ added in v1.4.0
AllowContext sets the ent privacy decision to allow for internal workflow operations.
func AllowContextWithOrg ¶ added in v1.4.0
AllowContextWithOrg returns an allow context plus the organization ID.
func ApplyObjectFieldUpdates ¶ added in v1.3.3
func ApplyObjectFieldUpdates(ctx context.Context, client *generated.Client, objectType enums.WorkflowObjectType, objectID string, updates map[string]any) error
ApplyObjectFieldUpdates applies updates to a workflow object via generated helpers.
func BuildAssignmentContext ¶ added in v1.3.3
func BuildAssignmentContext(ctx context.Context, client *generated.Client, instanceID string) (map[string]any, error)
BuildAssignmentContext calls the registered assignment context builder to get workflow runtime state. Returns nil if no builder is registered or instanceID is empty.
func BuildCELVars ¶ added in v1.3.3
func BuildCELVars(obj *Object, changedFields []string, changedEdges []string, addedIDs, removedIDs map[string][]string, eventType, userID string) map[string]any
BuildCELVars constructs the activation map for CEL evaluation, allowing generated builders to provide typed contexts instead of ad-hoc maps
func IsWorkflowBypass ¶ added in v1.4.0
IsWorkflowBypass checks if the context has workflow bypass enabled Used by workflow interceptors to skip approval routing for system operations
func LoadWorkflowObject ¶ added in v1.3.3
func LoadWorkflowObject(ctx context.Context, client *generated.Client, schemaType string, objectID string) (any, error)
LoadWorkflowObject loads an ent object that participates in workflows.
func NewCELEnvWithConfig ¶ added in v1.4.0
NewCELEnv builds the workflow CEL environment using the provided config
func NewCelEnv ¶ added in v1.4.0
func NewCelEnv(opts ...ConfigOpts) (*cel.Env, error)
NewCelEnv builds the workflow CEL environment using the provided options parameters
func ObjectOwnerID ¶ added in v1.3.3
func ObjectOwnerID(ctx context.Context, client *generated.Client, objectType enums.WorkflowObjectType, objectID string) (string, error)
ObjectOwnerID resolves the owner ID for a workflow object via generated helpers.
func OrganizationOwnerIDs ¶ added in v1.3.3
func OrganizationOwnerIDs(ctx context.Context, client *generated.Client, orgID string) ([]string, error)
OrganizationOwnerIDs returns user IDs for owners of an organization.
func RegisterAssignmentContextBuilder ¶
func RegisterAssignmentContextBuilder(builder AssignmentContextBuilder)
RegisterAssignmentContextBuilder sets the assignment context builder for CEL evaluation. Only one builder is needed since the generated code provides a comprehensive implementation.
func RegisterCELContextBuilder ¶
func RegisterCELContextBuilder(builder CELContextBuilder)
RegisterCELContextBuilder adds a CEL context builder. Last registered wins.
func RegisterObjectRefQueryBuilder ¶
func RegisterObjectRefQueryBuilder(builder ObjectRefQueryBuilder)
RegisterObjectRefQueryBuilder adds a WorkflowObjectRef query builder to the registry.
func RegisterObjectRefResolver ¶
func RegisterObjectRefResolver(resolver func(*generated.WorkflowObjectRef) (*Object, bool))
RegisterObjectRefResolver adds a resolver to the registry.
func StringField ¶ added in v1.3.3
StringField extracts a string field by name from a struct or pointer to struct
func WithContext ¶ added in v1.4.0
WithContext sets the workflow bypass context Operations with this context will skip workflow approval interceptors
func WorkflowMetadata ¶ added in v1.3.3
func WorkflowMetadata() []generated.WorkflowObjectTypeInfo
WorkflowMetadata returns generated workflow-eligible schema metadata.
Types ¶
type AssignmentContextBuilder ¶
type AssignmentContextBuilder func(ctx context.Context, client *generated.Client, instanceID string) (map[string]any, error)
AssignmentContextBuilder builds workflow runtime context (assignments, instance, initiator) for CEL evaluation. Generated code registers this to provide assignment state when evaluating NOTIFY action When expressions.
type CELConfig ¶ added in v1.4.0
type CELConfig struct {
// Timeout is the maximum duration allowed for evaluating a CEL expression
Timeout time.Duration `json:"timeout" koanf:"timeout" default:"100ms"`
// CostLimit caps the runtime cost of CEL evaluation, 0 disables the limit
CostLimit uint64 `json:"costlimit" koanf:"costlimit" default:"0"`
// InterruptCheckFrequency controls how often CEL checks for interrupts during comprehensions
InterruptCheckFrequency uint `json:"interruptcheckfrequency" koanf:"interruptcheckfrequency" default:"100"`
// ParserRecursionLimit caps the parser recursion depth, 0 uses CEL defaults
ParserRecursionLimit int `json:"parserrecursionlimit" koanf:"parserrecursionlimit" default:"250"`
// ParserExpressionSizeLimit caps expression size (code points), 0 uses CEL defaults
ParserExpressionSizeLimit int `json:"parserexpressionsizelimit" koanf:"parserexpressionsizelimit" default:"100000"`
// ComprehensionNestingLimit caps nested comprehensions, 0 disables the check
ComprehensionNestingLimit int `json:"comprehensionnestinglimit" koanf:"comprehensionnestinglimit" default:"0"`
// ExtendedValidations enables extra AST validations (regex, duration, timestamps, homogeneous aggregates)
ExtendedValidations bool `json:"extendedvalidations" koanf:"extendedvalidations" default:"true"`
// OptionalTypes enables CEL optional types and optional field syntax
OptionalTypes bool `json:"optionaltypes" koanf:"optionaltypes" default:"false"`
// IdentifierEscapeSyntax enables backtick escaped identifiers
IdentifierEscapeSyntax bool `json:"identifierescapesyntax" koanf:"identifierescapesyntax" default:"false"`
// CrossTypeNumericComparisons enables comparisons across numeric types
CrossTypeNumericComparisons bool `json:"crosstypenumericcomparisons" koanf:"crosstypenumericcomparisons" default:"false"`
// MacroCallTracking records macro calls in AST source info for debugging
MacroCallTracking bool `json:"macrocalltracking" koanf:"macrocalltracking" default:"false"`
// EvalOptimize enables evaluation-time optimizations for repeated program runs
EvalOptimize bool `json:"evaloptimize" koanf:"evaloptimize" default:"true"`
// TrackState enables evaluation state tracking for debugging
TrackState bool `json:"trackstate" koanf:"trackstate" default:"false"`
}
CELConfig contains CEL evaluation and validation settings for workflows
type CELContextBuilder ¶
type CELContextBuilder func(obj *Object, changedFields []string, changedEdges []string, addedIDs, removedIDs map[string][]string, eventType, userID string) map[string]any
CELContextBuilder can override how CEL activation variables are built per object type. Codegen can register specialized builders (e.g., to expose typed fields) by calling RegisterCELContextBuilder in an init() function.
type Config ¶ added in v1.4.0
type Config struct {
// Enabled determines if the workflows engine is enabled
Enabled bool `json:"enabled" koanf:"enabled" default:"false"`
// CEL contains configuration for CEL evaluation and validation
CEL CELConfig `json:"cel" koanf:"cel"`
}
Config contains the configuration for the workflows engine
func NewDefaultConfig ¶ added in v1.4.0
func NewDefaultConfig(opts ...ConfigOpts) *Config
NewDefaultConfig creates a new workflows config with default values applied.
type ConfigOpts ¶ added in v1.4.0
type ConfigOpts func(*Config)
ConfigOpts configures the Config
func WithCELComprehensionNestingLimit ¶ added in v1.4.0
func WithCELComprehensionNestingLimit(limit int) ConfigOpts
WithCELComprehensionNestingLimit sets the CEL comprehension nesting limit
func WithCELCostLimit ¶ added in v1.4.0
func WithCELCostLimit(limit uint64) ConfigOpts
WithCELCostLimit sets the CEL cost limit
func WithCELCrossTypeNumericComparisons ¶ added in v1.4.0
func WithCELCrossTypeNumericComparisons(enabled bool) ConfigOpts
WithCELCrossTypeNumericComparisons toggles CEL cross-type numeric comparisons
func WithCELEvalOptimize ¶ added in v1.4.0
func WithCELEvalOptimize(enabled bool) ConfigOpts
WithCELEvalOptimize toggles CEL evaluation optimizations
func WithCELExtendedValidations ¶ added in v1.4.0
func WithCELExtendedValidations(enabled bool) ConfigOpts
WithCELExtendedValidations toggles CEL extended validations
func WithCELIdentifierEscapeSyntax ¶ added in v1.4.0
func WithCELIdentifierEscapeSyntax(enabled bool) ConfigOpts
WithCELIdentifierEscapeSyntax toggles CEL identifier escape syntax
func WithCELInterruptCheckFrequency ¶ added in v1.4.0
func WithCELInterruptCheckFrequency(freq uint) ConfigOpts
WithCELInterruptCheckFrequency sets the CEL interrupt check frequency
func WithCELMacroCallTracking ¶ added in v1.4.0
func WithCELMacroCallTracking(enabled bool) ConfigOpts
WithCELMacroCallTracking toggles CEL macro call tracking
func WithCELOptionalTypes ¶ added in v1.4.0
func WithCELOptionalTypes(enabled bool) ConfigOpts
WithCELOptionalTypes toggles CEL optional types
func WithCELParserExpressionSizeLimit ¶ added in v1.4.0
func WithCELParserExpressionSizeLimit(limit int) ConfigOpts
WithCELParserExpressionSizeLimit sets the CEL parser expression size limit
func WithCELParserRecursionLimit ¶ added in v1.4.0
func WithCELParserRecursionLimit(limit int) ConfigOpts
WithCELParserRecursionLimit sets the CEL parser recursion limit
func WithCELTimeout ¶ added in v1.4.0
func WithCELTimeout(timeout time.Duration) ConfigOpts
WithCELTimeout sets the CEL evaluation timeout
func WithCELTrackState ¶ added in v1.4.0
func WithCELTrackState(enabled bool) ConfigOpts
WithCELTrackState toggles CEL evaluation state tracking
func WithConfig ¶ added in v1.4.0
func WithConfig(cfg Config) ConfigOpts
WithConfig applies all settings from a Config struct
func WithEnabled ¶ added in v1.4.0
func WithEnabled(enabled bool) ConfigOpts
WithEnabled sets the enabled field
type Object ¶
type Object struct {
// ID is the workflow object identifier.
ID string
// Type is the workflow object type.
Type enums.WorkflowObjectType
// Node is the concrete ent entity when available.
Node any
}
Object captures the workflow target along with its concrete ent entity when available.
func ObjectFromRef ¶ added in v1.3.3
func ObjectFromRef(ref *generated.WorkflowObjectRef) (*Object, error)
ObjectFromRef builds an Object from a WorkflowObjectRef record.
type ObjectRefQueryBuilder ¶
type ObjectRefQueryBuilder func(*generated.WorkflowObjectRefQuery, *Object) (*generated.WorkflowObjectRefQuery, bool)
ObjectRefQueryBuilder allows generated code to register WorkflowObjectRef predicates per object type.
type TargetConfig ¶ added in v1.3.3
type TargetConfig struct {
// Type selects how targets are resolved.
Type enums.WorkflowTargetType `json:"type"`
// ID identifies the target resource for static targets.
ID string `json:"id,omitempty"`
// ResolverKey names the resolver used for dynamic targets.
ResolverKey string `json:"resolver_key,omitempty"`
}
TargetConfig defines who should receive workflow actions.
type WorkflowBypassContextKey ¶ added in v1.4.0
type WorkflowBypassContextKey struct{}
WorkflowBypassContextKey is the context key for workflow bypass operations Used to bypass workflow approval checks during system operations (e.g., applying approved changes)
func FromContext ¶ added in v1.4.0
func FromContext(ctx context.Context) (WorkflowBypassContextKey, bool)
FromContext retrieves the workflow bypass context
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package engine is the workflow engine for orchestrating workflow execution
|
Package engine is the workflow engine for orchestrating workflow execution |
|
Package observability provides logging and metrics wrappers and consistency for workflows there are several functions in this package that are geared towards reducing boilerplate overhead with the main callers by pre-setting common fields such as operation origin and trigger event so that inline within the workflow package we don't have crazy verbose log and metric statements making the code harder to read
|
Package observability provides logging and metrics wrappers and consistency for workflows there are several functions in this package that are geared towards reducing boilerplate overhead with the main callers by pre-setting common fields such as operation origin and trigger event so that inline within the workflow package we don't have crazy verbose log and metric statements making the code harder to read |
|
Package resolvers provides a registry for workflow target resolution functions
|
Package resolvers provides a registry for workflow target resolution functions |