Skip to content

Commit 2d82a45

Browse files
authored
Merge pull request #235 from retran/feature/extract-shared-types
refactor: extract shared types and utility functions to mdl/types
2 parents 6e6f5cc + a807b77 commit 2d82a45

File tree

87 files changed

+3806
-2021
lines changed

Some content is hidden

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

87 files changed

+3806
-2021
lines changed

cmd/mxcli/project_tree.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sort"
1010

1111
"github.com/mendixlabs/mxcli/mdl/executor"
12+
"github.com/mendixlabs/mxcli/mdl/types"
1213
"github.com/mendixlabs/mxcli/model"
1314
"github.com/mendixlabs/mxcli/sdk/mpr"
1415
"github.com/spf13/cobra"
@@ -951,7 +952,7 @@ func buildDatabaseConnectionChildren(dbc *model.DatabaseConnection) []*TreeNode
951952
}
952953

953954
// buildMenuTreeNodes recursively builds tree nodes from navigation menu items.
954-
func buildMenuTreeNodes(parent *TreeNode, items []*mpr.NavMenuItem) {
955+
func buildMenuTreeNodes(parent *TreeNode, items []*types.NavMenuItem) {
955956
for _, item := range items {
956957
label := item.Caption
957958
if label == "" {

mdl/backend/connection.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
package backend
44

55
import (
6+
"github.com/mendixlabs/mxcli/mdl/types"
67
"github.com/mendixlabs/mxcli/model"
7-
"github.com/mendixlabs/mxcli/sdk/mpr"
8-
"github.com/mendixlabs/mxcli/sdk/mpr/version"
98
)
109

1110
// ConnectionBackend manages the lifecycle of a backend connection.
@@ -22,9 +21,9 @@ type ConnectionBackend interface {
2221
// Path returns the path of the connected project, or "" if not connected.
2322
Path() string
2423
// Version returns the MPR format version.
25-
Version() mpr.MPRVersion
24+
Version() types.MPRVersion
2625
// ProjectVersion returns the Mendix project version.
27-
ProjectVersion() *version.ProjectVersion
26+
ProjectVersion() *types.ProjectVersion
2827
// GetMendixVersion returns the Mendix version string.
2928
GetMendixVersion() (string, error)
3029
}
@@ -42,7 +41,7 @@ type ModuleBackend interface {
4241

4342
// FolderBackend provides folder operations.
4443
type FolderBackend interface {
45-
ListFolders() ([]*mpr.FolderInfo, error)
44+
ListFolders() ([]*types.FolderInfo, error)
4645
CreateFolder(folder *model.Folder) error
4746
DeleteFolder(id model.ID) error
4847
MoveFolder(id model.ID, newContainerID model.ID) error

mdl/backend/doc.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
// executor from concrete storage (e.g. .mpr files). Each interface
55
// groups related read/write operations by domain concept.
66
//
7-
// Several method signatures currently reference types from sdk/mpr
8-
// (e.g. NavigationDocument, FolderInfo, ImageCollection, JsonStructure,
9-
// JavaAction, EntityMemberAccess, RenameHit). These should eventually be
10-
// extracted into a shared types package to remove the mpr dependency.
7+
// Shared value types live in mdl/types to keep this package free of
8+
// sdk/mpr dependencies. Conversion between types.* and sdk/mpr.*
9+
// structs is handled inside mdl/backend/mpr (MprBackend).
1110
package backend

mdl/backend/infrastructure.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
package backend
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/sdk/mpr"
99
)
1010

1111
// RenameBackend provides cross-cutting rename and reference-update operations.
1212
type RenameBackend interface {
1313
UpdateQualifiedNameInAllUnits(oldName, newName string) (int, error)
14-
RenameReferences(oldName, newName string, dryRun bool) ([]mpr.RenameHit, error)
14+
RenameReferences(oldName, newName string, dryRun bool) ([]types.RenameHit, error)
1515
RenameDocumentByName(moduleName, oldName, newName string) error
1616
}
1717

@@ -20,17 +20,17 @@ type RenameBackend interface {
2020
type RawUnitBackend interface {
2121
GetRawUnit(id model.ID) (map[string]any, error)
2222
GetRawUnitBytes(id model.ID) ([]byte, error)
23-
ListRawUnitsByType(typePrefix string) ([]*mpr.RawUnit, error)
24-
ListRawUnits(objectType string) ([]*mpr.RawUnitInfo, error)
25-
GetRawUnitByName(objectType, qualifiedName string) (*mpr.RawUnitInfo, error)
23+
ListRawUnitsByType(typePrefix string) ([]*types.RawUnit, error)
24+
ListRawUnits(objectType string) ([]*types.RawUnitInfo, error)
25+
GetRawUnitByName(objectType, qualifiedName string) (*types.RawUnitInfo, error)
2626
GetRawMicroflowByName(qualifiedName string) ([]byte, error)
2727
UpdateRawUnit(unitID string, contents []byte) error
2828
}
2929

3030
// MetadataBackend provides project-level metadata and introspection.
3131
type MetadataBackend interface {
3232
ListAllUnitIDs() ([]string, error)
33-
ListUnits() ([]*mpr.UnitInfo, error)
33+
ListUnits() ([]*types.UnitInfo, error)
3434
GetUnitTypes() (map[string]int, error)
3535
GetProjectRootID() (string, error)
3636
ContentsDir() string
@@ -40,8 +40,8 @@ type MetadataBackend interface {
4040

4141
// WidgetBackend provides widget introspection operations.
4242
type WidgetBackend interface {
43-
FindCustomWidgetType(widgetID string) (*mpr.RawCustomWidgetType, error)
44-
FindAllCustomWidgetTypes(widgetID string) ([]*mpr.RawCustomWidgetType, error)
43+
FindCustomWidgetType(widgetID string) (*types.RawCustomWidgetType, error)
44+
FindAllCustomWidgetTypes(widgetID string) ([]*types.RawCustomWidgetType, error)
4545
}
4646

4747
// AgentEditorBackend provides agent editor document operations.

mdl/backend/java.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
package backend
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/sdk/mpr"
99
)
1010

1111
// JavaBackend provides Java and JavaScript action operations.
1212
type JavaBackend interface {
13-
ListJavaActions() ([]*mpr.JavaAction, error)
13+
ListJavaActions() ([]*types.JavaAction, error)
1414
ListJavaActionsFull() ([]*javaactions.JavaAction, error)
15-
ListJavaScriptActions() ([]*mpr.JavaScriptAction, error)
15+
ListJavaScriptActions() ([]*types.JavaScriptAction, error)
1616
ReadJavaActionByName(qualifiedName string) (*javaactions.JavaAction, error)
17-
ReadJavaScriptActionByName(qualifiedName string) (*mpr.JavaScriptAction, error)
17+
ReadJavaScriptActionByName(qualifiedName string) (*types.JavaScriptAction, error)
1818
CreateJavaAction(ja *javaactions.JavaAction) error
1919
UpdateJavaAction(ja *javaactions.JavaAction) error
2020
DeleteJavaAction(id model.ID) error

mdl/backend/mapping.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
package backend
44

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

1010
// MappingBackend provides import/export mapping and JSON structure operations.
@@ -23,8 +23,8 @@ type MappingBackend interface {
2323
DeleteExportMapping(id model.ID) error
2424
MoveExportMapping(em *model.ExportMapping) error
2525

26-
ListJsonStructures() ([]*mpr.JsonStructure, error)
27-
GetJsonStructureByQualifiedName(moduleName, name string) (*mpr.JsonStructure, error)
28-
CreateJsonStructure(js *mpr.JsonStructure) error
26+
ListJsonStructures() ([]*types.JsonStructure, error)
27+
GetJsonStructureByQualifiedName(moduleName, name string) (*types.JsonStructure, error)
28+
CreateJsonStructure(js *types.JsonStructure) error
2929
DeleteJsonStructure(id string) error
3030
}

mdl/backend/mock/backend.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212
"github.com/mendixlabs/mxcli/sdk/domainmodel"
1313
"github.com/mendixlabs/mxcli/sdk/javaactions"
1414
"github.com/mendixlabs/mxcli/sdk/microflows"
15-
"github.com/mendixlabs/mxcli/sdk/mpr"
16-
"github.com/mendixlabs/mxcli/sdk/mpr/version"
15+
"github.com/mendixlabs/mxcli/mdl/types"
1716
"github.com/mendixlabs/mxcli/sdk/pages"
1817
"github.com/mendixlabs/mxcli/sdk/security"
1918
"github.com/mendixlabs/mxcli/sdk/workflows"
@@ -31,8 +30,8 @@ type MockBackend struct {
3130
CommitFunc func() error
3231
IsConnectedFunc func() bool
3332
PathFunc func() string
34-
VersionFunc func() mpr.MPRVersion
35-
ProjectVersionFunc func() *version.ProjectVersion
33+
VersionFunc func() types.MPRVersion
34+
ProjectVersionFunc func() *types.ProjectVersion
3635
GetMendixVersionFunc func() (string, error)
3736

3837
// ModuleBackend
@@ -45,7 +44,7 @@ type MockBackend struct {
4544
DeleteModuleWithCleanupFunc func(id model.ID, moduleName string) error
4645

4746
// FolderBackend
48-
ListFoldersFunc func() ([]*mpr.FolderInfo, error)
47+
ListFoldersFunc func() ([]*types.FolderInfo, error)
4948
CreateFolderFunc func(folder *model.Folder) error
5049
DeleteFolderFunc func(id model.ID) error
5150
MoveFolderFunc func(id model.ID, newContainerID model.ID) error
@@ -144,14 +143,14 @@ type MockBackend struct {
144143
RemoveFromAllowedRolesFunc func(unitID model.ID, roleName string) (bool, error)
145144
AddEntityAccessRuleFunc func(params backend.EntityAccessRuleParams) error
146145
RemoveEntityAccessRuleFunc func(unitID model.ID, entityName string, roleNames []string) (int, error)
147-
RevokeEntityMemberAccessFunc func(unitID model.ID, entityName string, roleNames []string, revocation mpr.EntityAccessRevocation) (int, error)
146+
RevokeEntityMemberAccessFunc func(unitID model.ID, entityName string, roleNames []string, revocation types.EntityAccessRevocation) (int, error)
148147
RemoveRoleFromAllEntitiesFunc func(unitID model.ID, roleName string) (int, error)
149148
ReconcileMemberAccessesFunc func(unitID model.ID, moduleName string) (int, error)
150149

151150
// NavigationBackend
152-
ListNavigationDocumentsFunc func() ([]*mpr.NavigationDocument, error)
153-
GetNavigationFunc func() (*mpr.NavigationDocument, error)
154-
UpdateNavigationProfileFunc func(navDocID model.ID, profileName string, spec mpr.NavigationProfileSpec) error
151+
ListNavigationDocumentsFunc func() ([]*types.NavigationDocument, error)
152+
GetNavigationFunc func() (*types.NavigationDocument, error)
153+
UpdateNavigationProfileFunc func(navDocID model.ID, profileName string, spec types.NavigationProfileSpec) error
155154

156155
// ServiceBackend
157156
ListConsumedODataServicesFunc func() ([]*model.ConsumedODataService, error)
@@ -196,17 +195,17 @@ type MockBackend struct {
196195
UpdateExportMappingFunc func(em *model.ExportMapping) error
197196
DeleteExportMappingFunc func(id model.ID) error
198197
MoveExportMappingFunc func(em *model.ExportMapping) error
199-
ListJsonStructuresFunc func() ([]*mpr.JsonStructure, error)
200-
GetJsonStructureByQualifiedNameFunc func(moduleName, name string) (*mpr.JsonStructure, error)
201-
CreateJsonStructureFunc func(js *mpr.JsonStructure) error
198+
ListJsonStructuresFunc func() ([]*types.JsonStructure, error)
199+
GetJsonStructureByQualifiedNameFunc func(moduleName, name string) (*types.JsonStructure, error)
200+
CreateJsonStructureFunc func(js *types.JsonStructure) error
202201
DeleteJsonStructureFunc func(id string) error
203202

204203
// JavaBackend
205-
ListJavaActionsFunc func() ([]*mpr.JavaAction, error)
204+
ListJavaActionsFunc func() ([]*types.JavaAction, error)
206205
ListJavaActionsFullFunc func() ([]*javaactions.JavaAction, error)
207-
ListJavaScriptActionsFunc func() ([]*mpr.JavaScriptAction, error)
206+
ListJavaScriptActionsFunc func() ([]*types.JavaScriptAction, error)
208207
ReadJavaActionByNameFunc func(qualifiedName string) (*javaactions.JavaAction, error)
209-
ReadJavaScriptActionByNameFunc func(qualifiedName string) (*mpr.JavaScriptAction, error)
208+
ReadJavaScriptActionByNameFunc func(qualifiedName string) (*types.JavaScriptAction, error)
210209
CreateJavaActionFunc func(ja *javaactions.JavaAction) error
211210
UpdateJavaActionFunc func(ja *javaactions.JavaAction) error
212211
DeleteJavaActionFunc func(id model.ID) error
@@ -224,8 +223,8 @@ type MockBackend struct {
224223
UpdateProjectSettingsFunc func(ps *model.ProjectSettings) error
225224

226225
// ImageBackend
227-
ListImageCollectionsFunc func() ([]*mpr.ImageCollection, error)
228-
CreateImageCollectionFunc func(ic *mpr.ImageCollection) error
226+
ListImageCollectionsFunc func() ([]*types.ImageCollection, error)
227+
CreateImageCollectionFunc func(ic *types.ImageCollection) error
229228
DeleteImageCollectionFunc func(id string) error
230229

231230
// ScheduledEventBackend
@@ -234,30 +233,30 @@ type MockBackend struct {
234233

235234
// RenameBackend
236235
UpdateQualifiedNameInAllUnitsFunc func(oldName, newName string) (int, error)
237-
RenameReferencesFunc func(oldName, newName string, dryRun bool) ([]mpr.RenameHit, error)
236+
RenameReferencesFunc func(oldName, newName string, dryRun bool) ([]types.RenameHit, error)
238237
RenameDocumentByNameFunc func(moduleName, oldName, newName string) error
239238

240239
// RawUnitBackend
241240
GetRawUnitFunc func(id model.ID) (map[string]any, error)
242241
GetRawUnitBytesFunc func(id model.ID) ([]byte, error)
243-
ListRawUnitsByTypeFunc func(typePrefix string) ([]*mpr.RawUnit, error)
244-
ListRawUnitsFunc func(objectType string) ([]*mpr.RawUnitInfo, error)
245-
GetRawUnitByNameFunc func(objectType, qualifiedName string) (*mpr.RawUnitInfo, error)
242+
ListRawUnitsByTypeFunc func(typePrefix string) ([]*types.RawUnit, error)
243+
ListRawUnitsFunc func(objectType string) ([]*types.RawUnitInfo, error)
244+
GetRawUnitByNameFunc func(objectType, qualifiedName string) (*types.RawUnitInfo, error)
246245
GetRawMicroflowByNameFunc func(qualifiedName string) ([]byte, error)
247246
UpdateRawUnitFunc func(unitID string, contents []byte) error
248247

249248
// MetadataBackend
250249
ListAllUnitIDsFunc func() ([]string, error)
251-
ListUnitsFunc func() ([]*mpr.UnitInfo, error)
250+
ListUnitsFunc func() ([]*types.UnitInfo, error)
252251
GetUnitTypesFunc func() (map[string]int, error)
253252
GetProjectRootIDFunc func() (string, error)
254253
ContentsDirFunc func() string
255254
ExportJSONFunc func() ([]byte, error)
256255
InvalidateCacheFunc func()
257256

258257
// WidgetBackend
259-
FindCustomWidgetTypeFunc func(widgetID string) (*mpr.RawCustomWidgetType, error)
260-
FindAllCustomWidgetTypesFunc func(widgetID string) ([]*mpr.RawCustomWidgetType, error)
258+
FindCustomWidgetTypeFunc func(widgetID string) (*types.RawCustomWidgetType, error)
259+
FindAllCustomWidgetTypesFunc func(widgetID string) ([]*types.RawCustomWidgetType, error)
261260

262261
// AgentEditorBackend
263262
ListAgentEditorModelsFunc func() ([]*agenteditor.Model, error)

mdl/backend/mock/mock_connection.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
package mock
44

55
import (
6-
"github.com/mendixlabs/mxcli/sdk/mpr"
7-
"github.com/mendixlabs/mxcli/sdk/mpr/version"
6+
"github.com/mendixlabs/mxcli/mdl/types"
87
)
98

109
func (m *MockBackend) Connect(path string) error {
@@ -42,15 +41,15 @@ func (m *MockBackend) Path() string {
4241
return ""
4342
}
4443

45-
func (m *MockBackend) Version() mpr.MPRVersion {
44+
func (m *MockBackend) Version() types.MPRVersion {
4645
if m.VersionFunc != nil {
4746
return m.VersionFunc()
4847
}
49-
var zero mpr.MPRVersion
48+
var zero types.MPRVersion
5049
return zero
5150
}
5251

53-
func (m *MockBackend) ProjectVersion() *version.ProjectVersion {
52+
func (m *MockBackend) ProjectVersion() *types.ProjectVersion {
5453
if m.ProjectVersionFunc != nil {
5554
return m.ProjectVersionFunc()
5655
}

mdl/backend/mock/mock_infrastructure.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package mock
55
import (
66
"github.com/mendixlabs/mxcli/model"
77
"github.com/mendixlabs/mxcli/sdk/agenteditor"
8-
"github.com/mendixlabs/mxcli/sdk/mpr"
8+
"github.com/mendixlabs/mxcli/mdl/types"
99
)
1010

1111
// ---------------------------------------------------------------------------
@@ -19,7 +19,7 @@ func (m *MockBackend) UpdateQualifiedNameInAllUnits(oldName, newName string) (in
1919
return 0, nil
2020
}
2121

22-
func (m *MockBackend) RenameReferences(oldName, newName string, dryRun bool) ([]mpr.RenameHit, error) {
22+
func (m *MockBackend) RenameReferences(oldName, newName string, dryRun bool) ([]types.RenameHit, error) {
2323
if m.RenameReferencesFunc != nil {
2424
return m.RenameReferencesFunc(oldName, newName, dryRun)
2525
}
@@ -51,21 +51,21 @@ func (m *MockBackend) GetRawUnitBytes(id model.ID) ([]byte, error) {
5151
return nil, nil
5252
}
5353

54-
func (m *MockBackend) ListRawUnitsByType(typePrefix string) ([]*mpr.RawUnit, error) {
54+
func (m *MockBackend) ListRawUnitsByType(typePrefix string) ([]*types.RawUnit, error) {
5555
if m.ListRawUnitsByTypeFunc != nil {
5656
return m.ListRawUnitsByTypeFunc(typePrefix)
5757
}
5858
return nil, nil
5959
}
6060

61-
func (m *MockBackend) ListRawUnits(objectType string) ([]*mpr.RawUnitInfo, error) {
61+
func (m *MockBackend) ListRawUnits(objectType string) ([]*types.RawUnitInfo, error) {
6262
if m.ListRawUnitsFunc != nil {
6363
return m.ListRawUnitsFunc(objectType)
6464
}
6565
return nil, nil
6666
}
6767

68-
func (m *MockBackend) GetRawUnitByName(objectType, qualifiedName string) (*mpr.RawUnitInfo, error) {
68+
func (m *MockBackend) GetRawUnitByName(objectType, qualifiedName string) (*types.RawUnitInfo, error) {
6969
if m.GetRawUnitByNameFunc != nil {
7070
return m.GetRawUnitByNameFunc(objectType, qualifiedName)
7171
}
@@ -97,7 +97,7 @@ func (m *MockBackend) ListAllUnitIDs() ([]string, error) {
9797
return nil, nil
9898
}
9999

100-
func (m *MockBackend) ListUnits() ([]*mpr.UnitInfo, error) {
100+
func (m *MockBackend) ListUnits() ([]*types.UnitInfo, error) {
101101
if m.ListUnitsFunc != nil {
102102
return m.ListUnitsFunc()
103103
}
@@ -142,14 +142,14 @@ func (m *MockBackend) InvalidateCache() {
142142
// WidgetBackend
143143
// ---------------------------------------------------------------------------
144144

145-
func (m *MockBackend) FindCustomWidgetType(widgetID string) (*mpr.RawCustomWidgetType, error) {
145+
func (m *MockBackend) FindCustomWidgetType(widgetID string) (*types.RawCustomWidgetType, error) {
146146
if m.FindCustomWidgetTypeFunc != nil {
147147
return m.FindCustomWidgetTypeFunc(widgetID)
148148
}
149149
return nil, nil
150150
}
151151

152-
func (m *MockBackend) FindAllCustomWidgetTypes(widgetID string) ([]*mpr.RawCustomWidgetType, error) {
152+
func (m *MockBackend) FindAllCustomWidgetTypes(widgetID string) ([]*types.RawCustomWidgetType, error) {
153153
if m.FindAllCustomWidgetTypesFunc != nil {
154154
return m.FindAllCustomWidgetTypesFunc(widgetID)
155155
}

0 commit comments

Comments
 (0)