@@ -4,6 +4,7 @@ package executor
44
55import (
66 "fmt"
7+ "io"
78 "strings"
89
910 "go.mongodb.org/mongo-driver/bson"
@@ -21,7 +22,6 @@ const bsonArrayMarker = int32(3)
2122
2223// execAlterWorkflow handles ALTER WORKFLOW Module.Name { operations }.
2324func execAlterWorkflow (ctx * ExecContext , s * ast.AlterWorkflowStmt ) error {
24- e := ctx .executor
2525 if ! ctx .Connected () {
2626 return mdlerrors .NewNotConnected ()
2727 }
@@ -82,47 +82,47 @@ func execAlterWorkflow(ctx *ExecContext, s *ast.AlterWorkflowStmt) error {
8282 return mdlerrors .NewBackend ("SET ACTIVITY" , err )
8383 }
8484 case * ast.InsertAfterOp :
85- if err := applyInsertAfterActivity (e , rawData , o ); err != nil {
85+ if err := applyInsertAfterActivity (ctx , rawData , o ); err != nil {
8686 return mdlerrors .NewBackend ("INSERT AFTER" , err )
8787 }
8888 case * ast.DropActivityOp :
8989 if err := applyDropActivity (rawData , o ); err != nil {
9090 return mdlerrors .NewBackend ("DROP ACTIVITY" , err )
9191 }
9292 case * ast.ReplaceActivityOp :
93- if err := applyReplaceActivity (e , rawData , o ); err != nil {
93+ if err := applyReplaceActivity (ctx , rawData , o ); err != nil {
9494 return mdlerrors .NewBackend ("REPLACE ACTIVITY" , err )
9595 }
9696 case * ast.InsertOutcomeOp :
97- if err := applyInsertOutcome (e , rawData , o ); err != nil {
97+ if err := applyInsertOutcome (ctx , rawData , o ); err != nil {
9898 return mdlerrors .NewBackend ("INSERT OUTCOME" , err )
9999 }
100100 case * ast.DropOutcomeOp :
101101 if err := applyDropOutcome (rawData , o ); err != nil {
102102 return mdlerrors .NewBackend ("DROP OUTCOME" , err )
103103 }
104104 case * ast.InsertPathOp :
105- if err := applyInsertPath (e , rawData , o ); err != nil {
105+ if err := applyInsertPath (ctx , rawData , o ); err != nil {
106106 return mdlerrors .NewBackend ("INSERT PATH" , err )
107107 }
108108 case * ast.DropPathOp :
109109 if err := applyDropPath (rawData , o ); err != nil {
110110 return mdlerrors .NewBackend ("DROP PATH" , err )
111111 }
112112 case * ast.InsertBranchOp :
113- if err := applyInsertBranch (e , rawData , o ); err != nil {
113+ if err := applyInsertBranch (ctx , rawData , o ); err != nil {
114114 return mdlerrors .NewBackend ("INSERT BRANCH" , err )
115115 }
116116 case * ast.DropBranchOp :
117117 if err := applyDropBranch (rawData , o ); err != nil {
118118 return mdlerrors .NewBackend ("DROP BRANCH" , err )
119119 }
120120 case * ast.InsertBoundaryEventOp :
121- if err := applyInsertBoundaryEvent (e , rawData , o ); err != nil {
121+ if err := applyInsertBoundaryEvent (ctx , rawData , o ); err != nil {
122122 return mdlerrors .NewBackend ("INSERT BOUNDARY EVENT" , err )
123123 }
124124 case * ast.DropBoundaryEventOp :
125- if err := applyDropBoundaryEvent (rawData , o ); err != nil {
125+ if err := applyDropBoundaryEvent (ctx . Output , rawData , o ); err != nil {
126126 return mdlerrors .NewBackend ("DROP BOUNDARY EVENT" , err )
127127 }
128128 default :
@@ -484,9 +484,9 @@ func deduplicateNewActivityName(act workflows.WorkflowActivity, existingNames ma
484484
485485// buildSubFlowBson builds a Workflows$Flow BSON document from AST activity nodes,
486486// with auto-binding and name deduplication against existing workflow activities.
487- func buildSubFlowBson (e * Executor , doc bson.D , activities []ast.WorkflowActivityNode ) bson.D {
487+ func buildSubFlowBson (ctx * ExecContext , doc bson.D , activities []ast.WorkflowActivityNode ) bson.D {
488488 subActs := buildWorkflowActivities (activities )
489- autoBindActivitiesInFlow (e , subActs )
489+ autoBindActivitiesInFlow (ctx , subActs )
490490 existingNames := collectAllActivityNames (doc )
491491 for _ , act := range subActs {
492492 deduplicateNewActivityName (act , existingNames )
@@ -507,7 +507,7 @@ func buildSubFlowBson(e *Executor, doc bson.D, activities []ast.WorkflowActivity
507507}
508508
509509// applyInsertAfterActivity inserts a new activity after a named activity.
510- func applyInsertAfterActivity (e * Executor , doc bson.D , op * ast.InsertAfterOp ) error {
510+ func applyInsertAfterActivity (ctx * ExecContext , doc bson.D , op * ast.InsertAfterOp ) error {
511511 idx , activities , containingFlow , err := findActivityIndex (doc , op .ActivityRef , op .AtPosition )
512512 if err != nil {
513513 return err
@@ -519,7 +519,7 @@ func applyInsertAfterActivity(e *Executor, doc bson.D, op *ast.InsertAfterOp) er
519519 }
520520
521521 // Auto-bind parameters and deduplicate against existing workflow names
522- autoBindActivitiesInFlow (e , newActs )
522+ autoBindActivitiesInFlow (ctx , newActs )
523523 existingNames := collectAllActivityNames (doc )
524524 for _ , act := range newActs {
525525 deduplicateNewActivityName (act , existingNames )
@@ -559,7 +559,7 @@ func applyDropActivity(doc bson.D, op *ast.DropActivityOp) error {
559559}
560560
561561// applyReplaceActivity replaces an activity in place.
562- func applyReplaceActivity (e * Executor , doc bson.D , op * ast.ReplaceActivityOp ) error {
562+ func applyReplaceActivity (ctx * ExecContext , doc bson.D , op * ast.ReplaceActivityOp ) error {
563563 idx , activities , containingFlow , err := findActivityIndex (doc , op .ActivityRef , op .AtPosition )
564564 if err != nil {
565565 return err
@@ -570,7 +570,7 @@ func applyReplaceActivity(e *Executor, doc bson.D, op *ast.ReplaceActivityOp) er
570570 return mdlerrors .NewValidation ("failed to build replacement activity" )
571571 }
572572
573- autoBindActivitiesInFlow (e , newActs )
573+ autoBindActivitiesInFlow (ctx , newActs )
574574 existingNames := collectAllActivityNames (doc )
575575 for _ , act := range newActs {
576576 deduplicateNewActivityName (act , existingNames )
@@ -594,7 +594,7 @@ func applyReplaceActivity(e *Executor, doc bson.D, op *ast.ReplaceActivityOp) er
594594}
595595
596596// applyInsertOutcome adds a new outcome to a user task.
597- func applyInsertOutcome (e * Executor , doc bson.D , op * ast.InsertOutcomeOp ) error {
597+ func applyInsertOutcome (ctx * ExecContext , doc bson.D , op * ast.InsertOutcomeOp ) error {
598598 actDoc , err := findActivityByCaption (doc , op .ActivityRef , op .AtPosition )
599599 if err != nil {
600600 return err
@@ -608,7 +608,7 @@ func applyInsertOutcome(e *Executor, doc bson.D, op *ast.InsertOutcomeOp) error
608608
609609 // Build sub-flow if activities provided
610610 if len (op .Activities ) > 0 {
611- outcomeDoc = append (outcomeDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (e , doc , op .Activities )})
611+ outcomeDoc = append (outcomeDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (ctx , doc , op .Activities )})
612612 }
613613
614614 outcomeDoc = append (outcomeDoc ,
@@ -660,7 +660,7 @@ func applyDropOutcome(doc bson.D, op *ast.DropOutcomeOp) error {
660660}
661661
662662// applyInsertPath adds a new path to a parallel split.
663- func applyInsertPath (e * Executor , doc bson.D , op * ast.InsertPathOp ) error {
663+ func applyInsertPath (ctx * ExecContext , doc bson.D , op * ast.InsertPathOp ) error {
664664 actDoc , err := findActivityByCaption (doc , op .ActivityRef , op .AtPosition )
665665 if err != nil {
666666 return err
@@ -672,7 +672,7 @@ func applyInsertPath(e *Executor, doc bson.D, op *ast.InsertPathOp) error {
672672 }
673673
674674 if len (op .Activities ) > 0 {
675- pathDoc = append (pathDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (e , doc , op .Activities )})
675+ pathDoc = append (pathDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (ctx , doc , op .Activities )})
676676 }
677677
678678 pathDoc = append (pathDoc , bson.E {Key : "PersistentId" , Value : mpr .IDToBsonBinary (mpr .GenerateID ())})
@@ -719,7 +719,7 @@ func applyDropPath(doc bson.D, op *ast.DropPathOp) error {
719719}
720720
721721// applyInsertBranch adds a new branch to a decision.
722- func applyInsertBranch (e * Executor , doc bson.D , op * ast.InsertBranchOp ) error {
722+ func applyInsertBranch (ctx * ExecContext , doc bson.D , op * ast.InsertBranchOp ) error {
723723 actDoc , err := findActivityByCaption (doc , op .ActivityRef , op .AtPosition )
724724 if err != nil {
725725 return err
@@ -754,7 +754,7 @@ func applyInsertBranch(e *Executor, doc bson.D, op *ast.InsertBranchOp) error {
754754 }
755755
756756 if len (op .Activities ) > 0 {
757- outcomeDoc = append (outcomeDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (e , doc , op .Activities )})
757+ outcomeDoc = append (outcomeDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (ctx , doc , op .Activities )})
758758 }
759759
760760 outcomes := dGetArrayElements (dGet (actDoc , "Outcomes" ))
@@ -820,7 +820,7 @@ func applyDropBranch(doc bson.D, op *ast.DropBranchOp) error {
820820}
821821
822822// applyInsertBoundaryEvent adds a boundary event to an activity.
823- func applyInsertBoundaryEvent (e * Executor , doc bson.D , op * ast.InsertBoundaryEventOp ) error {
823+ func applyInsertBoundaryEvent (ctx * ExecContext , doc bson.D , op * ast.InsertBoundaryEventOp ) error {
824824 actDoc , err := findActivityByCaption (doc , op .ActivityRef , op .AtPosition )
825825 if err != nil {
826826 return err
@@ -845,7 +845,7 @@ func applyInsertBoundaryEvent(e *Executor, doc bson.D, op *ast.InsertBoundaryEve
845845 }
846846
847847 if len (op .Activities ) > 0 {
848- eventDoc = append (eventDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (e , doc , op .Activities )})
848+ eventDoc = append (eventDoc , bson.E {Key : "Flow" , Value : buildSubFlowBson (ctx , doc , op .Activities )})
849849 }
850850
851851 eventDoc = append (eventDoc , bson.E {Key : "PersistentId" , Value : mpr .IDToBsonBinary (mpr .GenerateID ())})
@@ -865,7 +865,7 @@ func applyInsertBoundaryEvent(e *Executor, doc bson.D, op *ast.InsertBoundaryEve
865865//
866866// Limitation: this always removes events[0]. There is currently no syntax to
867867// target a specific boundary event by name or type when multiple exist.
868- func applyDropBoundaryEvent (doc bson.D , op * ast.DropBoundaryEventOp ) error {
868+ func applyDropBoundaryEvent (w io. Writer , doc bson.D , op * ast.DropBoundaryEventOp ) error {
869869 actDoc , err := findActivityByCaption (doc , op .ActivityRef , op .AtPosition )
870870 if err != nil {
871871 return err
@@ -877,7 +877,7 @@ func applyDropBoundaryEvent(doc bson.D, op *ast.DropBoundaryEventOp) error {
877877 }
878878
879879 if len (events ) > 1 {
880- fmt .Printf ( "warning: activity %q has %d boundary events; dropping the first one\n " , op .ActivityRef , len (events ))
880+ fmt .Fprintf ( w , "warning: activity %q has %d boundary events; dropping the first one\n " , op .ActivityRef , len (events ))
881881 }
882882
883883 // Drop the first boundary event
0 commit comments