Skip to content

Commit 7b93cef

Browse files
committed
refactor: improve code quality — deterministic output, doc comments, naming consistency
Ensure deterministic map iteration order for serialization output. Add doc comments on all exported backend interfaces. Deduplicate IDToBsonBinary into single mdl/bsonutil implementation. Rename reader references to backend across executor. Guard float64-to-int64 cast with safe precision bounds. Apply go fmt formatting.
1 parent 07c9ad9 commit 7b93cef

64 files changed

Lines changed: 387 additions & 643 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

mdl/ast/ast_agenteditor.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ package ast
1616
// [, DeepLinkURL: '...']
1717
// );
1818
type CreateModelStmt struct {
19-
Name QualifiedName
20-
Documentation string
21-
Provider string // "MxCloudGenAI" by default
22-
Key *QualifiedName // qualified name of the String constant holding the Portal key
23-
DisplayName string // optional Portal-populated metadata
24-
KeyName string // optional Portal-populated metadata
25-
KeyID string // optional Portal-populated metadata
26-
Environment string // optional Portal-populated metadata
27-
ResourceName string // optional Portal-populated metadata
28-
DeepLinkURL string // optional Portal-populated metadata
19+
Name QualifiedName
20+
Documentation string
21+
Provider string // "MxCloudGenAI" by default
22+
Key *QualifiedName // qualified name of the String constant holding the Portal key
23+
DisplayName string // optional Portal-populated metadata
24+
KeyName string // optional Portal-populated metadata
25+
KeyID string // optional Portal-populated metadata
26+
Environment string // optional Portal-populated metadata
27+
ResourceName string // optional Portal-populated metadata
28+
DeepLinkURL string // optional Portal-populated metadata
2929
}
3030

3131
func (s *CreateModelStmt) isStatement() {}
@@ -93,21 +93,21 @@ func (s *DropKnowledgeBaseStmt) isStatement() {}
9393

9494
// CreateAgentStmt represents CREATE AGENT Module.Name (...) [{ body }].
9595
type CreateAgentStmt struct {
96-
Name QualifiedName
96+
Name QualifiedName
9797
Documentation string
98-
UsageType string // "Task" or "Conversational"
99-
Description string
100-
Model *QualifiedName // reference to a Model document
101-
Entity *QualifiedName // reference to a domain entity
102-
MaxTokens *int
103-
ToolChoice string
104-
Temperature *float64
105-
TopP *float64
106-
SystemPrompt string
107-
UserPrompt string
108-
Variables []AgentVarDef
109-
Tools []AgentToolDef
110-
KBTools []AgentKBToolDef
98+
UsageType string // "Task" or "Conversational"
99+
Description string
100+
Model *QualifiedName // reference to a Model document
101+
Entity *QualifiedName // reference to a domain entity
102+
MaxTokens *int
103+
ToolChoice string
104+
Temperature *float64
105+
TopP *float64
106+
SystemPrompt string
107+
UserPrompt string
108+
Variables []AgentVarDef
109+
Tools []AgentToolDef
110+
KBTools []AgentKBToolDef
111111
}
112112

113113
func (s *CreateAgentStmt) isStatement() {}
@@ -136,10 +136,10 @@ type AgentToolDef struct {
136136

137137
// AgentKBToolDef represents a KNOWLEDGE BASE block in CREATE AGENT body.
138138
type AgentKBToolDef struct {
139-
Name string // per-agent identifier
140-
Source *QualifiedName
141-
Collection string
142-
MaxResults int
143-
Description string
144-
Enabled bool
139+
Name string // per-agent identifier
140+
Source *QualifiedName
141+
Collection string
142+
MaxResults int
143+
Description string
144+
Enabled bool
145145
}

mdl/backend/connection.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,36 @@ type ConnectionBackend interface {
2525
// ProjectVersion returns the Mendix project version.
2626
ProjectVersion() *types.ProjectVersion
2727
// GetMendixVersion returns the Mendix version string.
28+
// NOTE: uses Get prefix unlike Version()/ProjectVersion() for historical SDK compatibility.
2829
GetMendixVersion() (string, error)
2930
}
3031

3132
// ModuleBackend provides module-level operations.
3233
type ModuleBackend interface {
34+
// ListModules returns all modules in the project.
3335
ListModules() ([]*model.Module, error)
36+
// GetModule returns a module by ID.
3437
GetModule(id model.ID) (*model.Module, error)
38+
// GetModuleByName returns a module by name.
3539
GetModuleByName(name string) (*model.Module, error)
40+
// CreateModule adds a new module to the project.
3641
CreateModule(module *model.Module) error
42+
// UpdateModule persists changes to an existing module.
3743
UpdateModule(module *model.Module) error
44+
// DeleteModule removes a module by ID.
3845
DeleteModule(id model.ID) error
46+
// DeleteModuleWithCleanup removes a module and cleans up associated documents.
3947
DeleteModuleWithCleanup(id model.ID, moduleName string) error
4048
}
4149

4250
// FolderBackend provides folder operations.
4351
type FolderBackend interface {
52+
// ListFolders returns all folders in the project.
4453
ListFolders() ([]*types.FolderInfo, error)
54+
// CreateFolder adds a new folder.
4555
CreateFolder(folder *model.Folder) error
56+
// DeleteFolder removes a folder by ID.
4657
DeleteFolder(id model.ID) error
58+
// MoveFolder moves a folder to a new container.
4759
MoveFolder(id model.ID, newContainerID model.ID) error
4860
}

mdl/backend/infrastructure.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ type RenameBackend interface {
1616
}
1717

1818
// RawUnitBackend provides low-level unit access for operations that
19-
// manipulate raw BSON (e.g. widget patching, alter page/workflow).
19+
// manipulate raw unit contents (e.g. widget patching, alter page/workflow).
2020
type RawUnitBackend interface {
2121
GetRawUnit(id model.ID) (map[string]any, error)
2222
GetRawUnitBytes(id model.ID) ([]byte, error)
2323
ListRawUnitsByType(typePrefix string) ([]*types.RawUnit, error)
2424
ListRawUnits(objectType string) ([]*types.RawUnitInfo, error)
2525
GetRawUnitByName(objectType, qualifiedName string) (*types.RawUnitInfo, error)
2626
GetRawMicroflowByName(qualifiedName string) ([]byte, error)
27+
// UpdateRawUnit replaces the contents of a unit by ID.
28+
// Takes string (not model.ID) to match the SDK writer layer convention.
2729
UpdateRawUnit(unitID string, contents []byte) error
2830
}
2931

@@ -45,6 +47,7 @@ type WidgetBackend interface {
4547
}
4648

4749
// AgentEditorBackend provides agent editor document operations.
50+
// Delete methods take string IDs to match the SDK writer layer convention.
4851
type AgentEditorBackend interface {
4952
ListAgentEditorModels() ([]*agenteditor.Model, error)
5053
ListAgentEditorKnowledgeBases() ([]*agenteditor.KnowledgeBase, error)
@@ -59,3 +62,22 @@ type AgentEditorBackend interface {
5962
CreateAgentEditorAgent(a *agenteditor.Agent) error
6063
DeleteAgentEditorAgent(id string) error
6164
}
65+
66+
// SettingsBackend provides project settings operations.
67+
type SettingsBackend interface {
68+
GetProjectSettings() (*model.ProjectSettings, error)
69+
UpdateProjectSettings(ps *model.ProjectSettings) error
70+
}
71+
72+
// ImageBackend provides image collection operations.
73+
type ImageBackend interface {
74+
ListImageCollections() ([]*types.ImageCollection, error)
75+
CreateImageCollection(ic *types.ImageCollection) error
76+
DeleteImageCollection(id string) error
77+
}
78+
79+
// ScheduledEventBackend provides scheduled event operations.
80+
type ScheduledEventBackend interface {
81+
ListScheduledEvents() ([]*model.ScheduledEvent, error)
82+
GetScheduledEvent(id model.ID) (*model.ScheduledEvent, error)
83+
}

mdl/backend/mapping.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ type MappingBackend interface {
2626
ListJsonStructures() ([]*types.JsonStructure, error)
2727
GetJsonStructureByQualifiedName(moduleName, name string) (*types.JsonStructure, error)
2828
CreateJsonStructure(js *types.JsonStructure) error
29+
// DeleteJsonStructure removes a JSON structure by ID.
30+
// Takes string (not model.ID) to match the SDK writer layer convention.
2931
DeleteJsonStructure(id string) error
3032
}

mdl/backend/microflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type MicroflowBackend interface {
1717
MoveMicroflow(mf *microflows.Microflow) error
1818

1919
// ParseMicroflowFromRaw builds a Microflow from an already-unmarshalled
20-
// BSON map. Used by diff-local and other callers that have raw map data.
20+
// map. Used by diff-local and other callers that have raw map data.
2121
ParseMicroflowFromRaw(raw map[string]any, unitID, containerID model.ID) *microflows.Microflow
2222

2323
ListNanoflows() ([]*microflows.Nanoflow, error)

mdl/backend/mock/backend.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ package mock
77

88
import (
99
"github.com/mendixlabs/mxcli/mdl/backend"
10+
"github.com/mendixlabs/mxcli/mdl/types"
1011
"github.com/mendixlabs/mxcli/model"
1112
"github.com/mendixlabs/mxcli/sdk/agenteditor"
1213
"github.com/mendixlabs/mxcli/sdk/domainmodel"
1314
"github.com/mendixlabs/mxcli/sdk/javaactions"
1415
"github.com/mendixlabs/mxcli/sdk/microflows"
15-
"github.com/mendixlabs/mxcli/mdl/types"
1616
"github.com/mendixlabs/mxcli/sdk/pages"
1717
"github.com/mendixlabs/mxcli/sdk/security"
1818
"github.com/mendixlabs/mxcli/sdk/workflows"
@@ -75,19 +75,19 @@ type MockBackend struct {
7575
UpdateEnumerationRefsInAllDomainModelsFunc func(oldQualifiedName, newQualifiedName string) error
7676

7777
// MicroflowBackend
78-
ListMicroflowsFunc func() ([]*microflows.Microflow, error)
79-
GetMicroflowFunc func(id model.ID) (*microflows.Microflow, error)
80-
CreateMicroflowFunc func(mf *microflows.Microflow) error
81-
UpdateMicroflowFunc func(mf *microflows.Microflow) error
82-
DeleteMicroflowFunc func(id model.ID) error
83-
MoveMicroflowFunc func(mf *microflows.Microflow) error
84-
ParseMicroflowFromRawFunc func(raw map[string]any, unitID, containerID model.ID) *microflows.Microflow
85-
ListNanoflowsFunc func() ([]*microflows.Nanoflow, error)
86-
GetNanoflowFunc func(id model.ID) (*microflows.Nanoflow, error)
87-
CreateNanoflowFunc func(nf *microflows.Nanoflow) error
88-
UpdateNanoflowFunc func(nf *microflows.Nanoflow) error
89-
DeleteNanoflowFunc func(id model.ID) error
90-
MoveNanoflowFunc func(nf *microflows.Nanoflow) error
78+
ListMicroflowsFunc func() ([]*microflows.Microflow, error)
79+
GetMicroflowFunc func(id model.ID) (*microflows.Microflow, error)
80+
CreateMicroflowFunc func(mf *microflows.Microflow) error
81+
UpdateMicroflowFunc func(mf *microflows.Microflow) error
82+
DeleteMicroflowFunc func(id model.ID) error
83+
MoveMicroflowFunc func(mf *microflows.Microflow) error
84+
ParseMicroflowFromRawFunc func(raw map[string]any, unitID, containerID model.ID) *microflows.Microflow
85+
ListNanoflowsFunc func() ([]*microflows.Nanoflow, error)
86+
GetNanoflowFunc func(id model.ID) (*microflows.Nanoflow, error)
87+
CreateNanoflowFunc func(nf *microflows.Nanoflow) error
88+
UpdateNanoflowFunc func(nf *microflows.Nanoflow) error
89+
DeleteNanoflowFunc func(id model.ID) error
90+
MoveNanoflowFunc func(nf *microflows.Nanoflow) error
9191

9292
// PageBackend
9393
ListPagesFunc func() ([]*pages.Page, error)

mdl/backend/mock/mock_infrastructure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package mock
44

55
import (
6+
"github.com/mendixlabs/mxcli/mdl/types"
67
"github.com/mendixlabs/mxcli/model"
78
"github.com/mendixlabs/mxcli/sdk/agenteditor"
8-
"github.com/mendixlabs/mxcli/mdl/types"
99
)
1010

1111
// ---------------------------------------------------------------------------

mdl/backend/mock/mock_java.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
package mock
44

55
import (
6+
"github.com/mendixlabs/mxcli/mdl/types"
67
"github.com/mendixlabs/mxcli/model"
78
"github.com/mendixlabs/mxcli/sdk/javaactions"
8-
"github.com/mendixlabs/mxcli/mdl/types"
99
)
1010

1111
func (m *MockBackend) ListJavaActions() ([]*types.JavaAction, error) {

mdl/backend/mock/mock_mapping.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package mock
44

55
import (
6-
"github.com/mendixlabs/mxcli/model"
76
"github.com/mendixlabs/mxcli/mdl/types"
7+
"github.com/mendixlabs/mxcli/model"
88
)
99

1010
func (m *MockBackend) ListImportMappings() ([]*model.ImportMapping, error) {

mdl/backend/mock/mock_navigation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package mock
44

55
import (
6-
"github.com/mendixlabs/mxcli/model"
76
"github.com/mendixlabs/mxcli/mdl/types"
7+
"github.com/mendixlabs/mxcli/model"
88
)
99

1010
func (m *MockBackend) ListNavigationDocuments() ([]*types.NavigationDocument, error) {

0 commit comments

Comments
 (0)