Documentation
¶
Overview ¶
Package workflows provides minimal registry types for workflow ent templates
Index ¶
- Variables
- 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 LoadWorkflowObject(ctx context.Context, client *generated.Client, schemaType string, ...) (any, 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 WorkflowMetadata() []generated.WorkflowObjectTypeInfo
- type AssignmentContextBuilder
- type CELContextBuilder
- type Object
- type ObjectRefQueryBuilder
- type TargetConfig
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") )
Functions ¶
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 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 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 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 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 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.