|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package backend |
| 4 | + |
| 5 | +import ( |
| 6 | + "github.com/mendixlabs/mxcli/model" |
| 7 | + "github.com/mendixlabs/mxcli/sdk/pages" |
| 8 | + "github.com/mendixlabs/mxcli/sdk/workflows" |
| 9 | +) |
| 10 | + |
| 11 | +// PageMutator provides fine-grained mutation operations on a single |
| 12 | +// page, layout, or snippet unit. Obtain one via PageMutationBackend.OpenPageForMutation. |
| 13 | +// All methods operate on the in-memory representation; call Save to persist. |
| 14 | +type PageMutator interface { |
| 15 | + // ContainerType returns "page", "layout", or "snippet". |
| 16 | + ContainerType() string |
| 17 | + |
| 18 | + // --- Widget property operations --- |
| 19 | + |
| 20 | + // SetWidgetProperty sets a simple property on the named widget. |
| 21 | + // For pluggable widget properties, prop is the Mendix property key |
| 22 | + // and value is the string representation. |
| 23 | + SetWidgetProperty(widgetRef string, prop string, value any) error |
| 24 | + |
| 25 | + // SetWidgetDataSource sets the DataSource on the named widget. |
| 26 | + SetWidgetDataSource(widgetRef string, ds pages.DataSource) error |
| 27 | + |
| 28 | + // SetColumnProperty sets a property on a column within a grid widget. |
| 29 | + SetColumnProperty(gridRef string, columnRef string, prop string, value any) error |
| 30 | + |
| 31 | + // --- Widget tree operations --- |
| 32 | + |
| 33 | + // InsertWidget inserts serialized widgets at the given position |
| 34 | + // relative to the target widget. Position is "before" or "after". |
| 35 | + InsertWidget(targetWidget string, position string, widgets []pages.Widget) error |
| 36 | + |
| 37 | + // DropWidget removes widgets by name from the tree. |
| 38 | + DropWidget(widgetRefs []string) error |
| 39 | + |
| 40 | + // ReplaceWidget replaces the target widget with the given widgets. |
| 41 | + ReplaceWidget(targetWidget string, widgets []pages.Widget) error |
| 42 | + |
| 43 | + // --- Variable operations --- |
| 44 | + |
| 45 | + // AddVariable adds a local variable to the page/snippet. |
| 46 | + AddVariable(name, dataType, defaultValue string) error |
| 47 | + |
| 48 | + // DropVariable removes a local variable by name. |
| 49 | + DropVariable(name string) error |
| 50 | + |
| 51 | + // --- Layout operations --- |
| 52 | + |
| 53 | + // SetLayout changes the layout reference and remaps placeholder parameters. |
| 54 | + SetLayout(newLayout string, paramMappings map[string]string) error |
| 55 | + |
| 56 | + // --- Pluggable widget operations --- |
| 57 | + |
| 58 | + // SetPluggableProperty sets a typed property on a pluggable widget's object. |
| 59 | + // propKey is the Mendix property key, opName is the operation type |
| 60 | + // ("attribute", "association", "primitive", "selection", "datasource", |
| 61 | + // "widgets", "texttemplate", "action", "attributeObjects"). |
| 62 | + // ctx carries the operation-specific values. |
| 63 | + SetPluggableProperty(widgetRef string, propKey string, opName string, ctx PluggablePropertyContext) error |
| 64 | + |
| 65 | + // --- Introspection --- |
| 66 | + |
| 67 | + // EnclosingEntity returns the qualified entity name for the given widget's |
| 68 | + // data context, or "" if none. |
| 69 | + EnclosingEntity(widgetRef string) string |
| 70 | + |
| 71 | + // WidgetScope returns a map of widget name → unit ID for all widgets in the tree. |
| 72 | + WidgetScope() map[string]model.ID |
| 73 | + |
| 74 | + // Save persists the mutations to the backend. |
| 75 | + Save() error |
| 76 | +} |
| 77 | + |
| 78 | +// PluggablePropertyContext carries operation-specific values for |
| 79 | +// SetPluggableProperty. Only fields relevant to the operation are used. |
| 80 | +type PluggablePropertyContext struct { |
| 81 | + AttributePath string // "attribute", "association" |
| 82 | + AttributePaths []string // "attributeObjects" |
| 83 | + AssocPath string // "association" |
| 84 | + EntityName string // "association" |
| 85 | + PrimitiveVal string // "primitive" |
| 86 | + DataSource pages.DataSource // "datasource" |
| 87 | + ChildWidgets []pages.Widget // "widgets" |
| 88 | + Action pages.ClientAction // "action" |
| 89 | + TextTemplate string // "texttemplate" |
| 90 | + Selection string // "selection" |
| 91 | +} |
| 92 | + |
| 93 | +// WorkflowMutator provides fine-grained mutation operations on a single |
| 94 | +// workflow unit. Obtain one via WorkflowMutationBackend.OpenWorkflowForMutation. |
| 95 | +// All methods operate on the in-memory representation; call Save to persist. |
| 96 | +type WorkflowMutator interface { |
| 97 | + // --- Top-level property operations --- |
| 98 | + |
| 99 | + // SetProperty sets a workflow-level property (DisplayName, Description, |
| 100 | + // ExportLevel, DueDate, Parameter, OverviewPage). |
| 101 | + SetProperty(prop string, value string) error |
| 102 | + |
| 103 | + // SetPropertyWithEntity sets a workflow-level property that references |
| 104 | + // an entity (e.g. Parameter). |
| 105 | + SetPropertyWithEntity(prop string, value string, entity string) error |
| 106 | + |
| 107 | + // --- Activity operations --- |
| 108 | + |
| 109 | + // SetActivityProperty sets a property on an activity identified by |
| 110 | + // caption and optional position index. |
| 111 | + SetActivityProperty(activityRef string, atPos int, prop string, value string) error |
| 112 | + |
| 113 | + // InsertAfterActivity inserts new activities after the referenced activity. |
| 114 | + InsertAfterActivity(activityRef string, atPos int, activities []workflows.WorkflowActivity) error |
| 115 | + |
| 116 | + // DropActivity removes the referenced activity. |
| 117 | + DropActivity(activityRef string, atPos int) error |
| 118 | + |
| 119 | + // ReplaceActivity replaces the referenced activity with new ones. |
| 120 | + ReplaceActivity(activityRef string, atPos int, activities []workflows.WorkflowActivity) error |
| 121 | + |
| 122 | + // --- Outcome operations --- |
| 123 | + |
| 124 | + // InsertOutcome adds a new outcome to the referenced activity. |
| 125 | + InsertOutcome(activityRef string, atPos int, outcomeName string, activities []workflows.WorkflowActivity) error |
| 126 | + |
| 127 | + // DropOutcome removes an outcome by name from the referenced activity. |
| 128 | + DropOutcome(activityRef string, atPos int, outcomeName string) error |
| 129 | + |
| 130 | + // --- Path operations (parallel split) --- |
| 131 | + |
| 132 | + InsertPath(activityRef string, atPos int, pathCaption string, activities []workflows.WorkflowActivity) error |
| 133 | + DropPath(activityRef string, atPos int, pathCaption string) error |
| 134 | + |
| 135 | + // --- Branch operations (exclusive split) --- |
| 136 | + |
| 137 | + InsertBranch(activityRef string, atPos int, condition string, activities []workflows.WorkflowActivity) error |
| 138 | + DropBranch(activityRef string, atPos int, branchName string) error |
| 139 | + |
| 140 | + // --- Boundary event operations --- |
| 141 | + |
| 142 | + InsertBoundaryEvent(activityRef string, atPos int, eventType string, delay string, activities []workflows.WorkflowActivity) error |
| 143 | + DropBoundaryEvent(activityRef string, atPos int) error |
| 144 | + |
| 145 | + // Save persists the mutations to the backend. |
| 146 | + Save() error |
| 147 | +} |
| 148 | + |
| 149 | +// PageMutationBackend provides page/layout/snippet mutation capabilities. |
| 150 | +type PageMutationBackend interface { |
| 151 | + // OpenPageForMutation loads a page, layout, or snippet unit and returns |
| 152 | + // a mutator for applying changes. Call Save() on the returned mutator |
| 153 | + // to persist. |
| 154 | + OpenPageForMutation(unitID model.ID) (PageMutator, error) |
| 155 | +} |
| 156 | + |
| 157 | +// WorkflowMutationBackend provides workflow mutation capabilities. |
| 158 | +type WorkflowMutationBackend interface { |
| 159 | + // OpenWorkflowForMutation loads a workflow unit and returns a mutator |
| 160 | + // for applying changes. Call Save() on the returned mutator to persist. |
| 161 | + OpenWorkflowForMutation(unitID model.ID) (WorkflowMutator, error) |
| 162 | +} |
| 163 | + |
| 164 | +// WidgetSerializationBackend provides widget and activity serialization |
| 165 | +// for CREATE paths where the executor builds domain objects that need |
| 166 | +// to be converted to the storage format. |
| 167 | +type WidgetSerializationBackend interface { |
| 168 | + // SerializeWidget converts a domain Widget to its storage representation. |
| 169 | + // The returned value is opaque to the caller; it is only used as input |
| 170 | + // to mutation operations or passed to the backend for persistence. |
| 171 | + SerializeWidget(w pages.Widget) (any, error) |
| 172 | + |
| 173 | + // SerializeClientAction converts a domain ClientAction to storage format. |
| 174 | + SerializeClientAction(a pages.ClientAction) (any, error) |
| 175 | + |
| 176 | + // SerializeDataSource converts a domain DataSource to storage format. |
| 177 | + SerializeDataSource(ds pages.DataSource) (any, error) |
| 178 | + |
| 179 | + // SerializeWorkflowActivity converts a domain WorkflowActivity to storage format. |
| 180 | + SerializeWorkflowActivity(a workflows.WorkflowActivity) (any, error) |
| 181 | +} |
0 commit comments