Skip to content

Commit 8282e92

Browse files
committed
fix: use local type aliases in sdk/mpr public signatures
1 parent 349b579 commit 8282e92

3 files changed

Lines changed: 31 additions & 33 deletions

File tree

sdk/mpr/parser_misc.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"github.com/mendixlabs/mxcli/mdl/types"
1312
"github.com/mendixlabs/mxcli/model"
1413
"github.com/mendixlabs/mxcli/sdk/javaactions"
1514
"github.com/mendixlabs/mxcli/sdk/pages"
@@ -81,7 +80,7 @@ func (r *Reader) parseSnippet(unitID, containerID string, contents []byte) (*pag
8180
}
8281

8382
// parseJavaAction parses Java action contents from BSON.
84-
func (r *Reader) parseJavaAction(unitID, containerID string, contents []byte) (*types.JavaAction, error) {
83+
func (r *Reader) parseJavaAction(unitID, containerID string, contents []byte) (*JavaAction, error) {
8584
contents, err := r.resolveContents(unitID, contents)
8685
if err != nil {
8786
return nil, err
@@ -92,7 +91,7 @@ func (r *Reader) parseJavaAction(unitID, containerID string, contents []byte) (*
9291
return nil, fmt.Errorf("failed to unmarshal BSON: %w", err)
9392
}
9493

95-
ja := &types.JavaAction{}
94+
ja := &JavaAction{}
9695
ja.ID = model.ID(unitID)
9796
ja.TypeName = "JavaActions$JavaAction"
9897
ja.ContainerID = model.ID(containerID)
@@ -138,7 +137,7 @@ func WriteJSON(element any) ([]byte, error) {
138137
}
139138

140139
// parseJavaScriptAction parses JavaScript action contents from BSON.
141-
func (r *Reader) parseJavaScriptAction(unitID, containerID string, contents []byte) (*types.JavaScriptAction, error) {
140+
func (r *Reader) parseJavaScriptAction(unitID, containerID string, contents []byte) (*JavaScriptAction, error) {
142141
contents, err := r.resolveContents(unitID, contents)
143142
if err != nil {
144143
return nil, err
@@ -149,7 +148,7 @@ func (r *Reader) parseJavaScriptAction(unitID, containerID string, contents []by
149148
return nil, fmt.Errorf("failed to unmarshal BSON: %w", err)
150149
}
151150

152-
jsa := &types.JavaScriptAction{}
151+
jsa := &JavaScriptAction{}
153152
jsa.ID = model.ID(unitID)
154153
jsa.TypeName = "JavaScriptActions$JavaScriptAction"
155154
jsa.ContainerID = model.ID(containerID)
@@ -250,7 +249,7 @@ func (r *Reader) parseJavaScriptAction(unitID, containerID string, contents []by
250249
}
251250

252251
// ReadJavaScriptActionByName reads a JavaScript action by qualified name (Module.ActionName).
253-
func (r *Reader) ReadJavaScriptActionByName(qualifiedName string) (*types.JavaScriptAction, error) {
252+
func (r *Reader) ReadJavaScriptActionByName(qualifiedName string) (*JavaScriptAction, error) {
254253
units, err := r.listUnitsByType("JavaScriptActions$JavaScriptAction")
255254
if err != nil {
256255
return nil, err
@@ -364,7 +363,7 @@ func (r *Reader) parsePageTemplate(unitID, containerID string, contents []byte)
364363
}
365364

366365
// parseNavigationDocument parses navigation document contents from BSON.
367-
func (r *Reader) parseNavigationDocument(unitID, containerID string, contents []byte) (*types.NavigationDocument, error) {
366+
func (r *Reader) parseNavigationDocument(unitID, containerID string, contents []byte) (*NavigationDocument, error) {
368367
contents, err := r.resolveContents(unitID, contents)
369368
if err != nil {
370369
return nil, err
@@ -375,7 +374,7 @@ func (r *Reader) parseNavigationDocument(unitID, containerID string, contents []
375374
return nil, fmt.Errorf("failed to unmarshal BSON: %w", err)
376375
}
377376

378-
nav := &types.NavigationDocument{}
377+
nav := &NavigationDocument{}
379378
nav.ID = model.ID(unitID)
380379
nav.TypeName = "Navigation$NavigationDocument"
381380
nav.ContainerID = model.ID(containerID)
@@ -400,9 +399,9 @@ func (r *Reader) parseNavigationDocument(unitID, containerID string, contents []
400399
}
401400

402401
// parseNavigationProfile parses a single navigation profile from BSON.
403-
func parseNavigationProfile(raw map[string]any) *types.NavigationProfile {
402+
func parseNavigationProfile(raw map[string]any) *NavigationProfile {
404403
typeName := extractString(raw["$Type"])
405-
profile := &types.NavigationProfile{
404+
profile := &NavigationProfile{
406405
Name: extractString(raw["Name"]),
407406
Kind: extractString(raw["Kind"]),
408407
}
@@ -414,13 +413,13 @@ func parseNavigationProfile(raw map[string]any) *types.NavigationProfile {
414413
page := extractString(hp["HomePagePage"])
415414
nanoflow := extractString(hp["HomePageNanoflow"])
416415
if page != "" || nanoflow != "" {
417-
profile.HomePage = &types.NavHomePage{Page: page, Microflow: nanoflow}
416+
profile.HomePage = &NavHomePage{Page: page, Microflow: nanoflow}
418417
}
419418
}
420419
// Native role-based home pages
421420
for _, item := range extractBsonArray(raw["RoleBasedNativeHomePages"]) {
422421
if rbMap, ok := item.(map[string]any); ok {
423-
rbh := &types.NavRoleBasedHome{
422+
rbh := &NavRoleBasedHome{
424423
UserRole: extractString(rbMap["UserRole"]),
425424
Page: extractString(rbMap["HomePagePage"]),
426425
Microflow: extractString(rbMap["HomePageNanoflow"]),
@@ -446,13 +445,13 @@ func parseNavigationProfile(raw map[string]any) *types.NavigationProfile {
446445
page := extractString(hp["Page"])
447446
mf := extractString(hp["Microflow"])
448447
if page != "" || mf != "" {
449-
profile.HomePage = &types.NavHomePage{Page: page, Microflow: mf}
448+
profile.HomePage = &NavHomePage{Page: page, Microflow: mf}
450449
}
451450
}
452451
// Role-based home pages (stored as "HomeItems")
453452
for _, item := range extractBsonArray(raw["HomeItems"]) {
454453
if rbMap, ok := item.(map[string]any); ok {
455-
rbh := &types.NavRoleBasedHome{
454+
rbh := &NavRoleBasedHome{
456455
UserRole: extractString(rbMap["UserRole"]),
457456
Page: extractString(rbMap["Page"]),
458457
Microflow: extractString(rbMap["Microflow"]),
@@ -489,7 +488,7 @@ func parseNavigationProfile(raw map[string]any) *types.NavigationProfile {
489488
// Offline entity configs (both web and native)
490489
for _, item := range extractBsonArray(raw["OfflineEntityConfigs"]) {
491490
if oeMap, ok := item.(map[string]any); ok {
492-
oe := &types.NavOfflineEntity{
491+
oe := &NavOfflineEntity{
493492
Entity: extractString(oeMap["Entity"]),
494493
SyncMode: extractString(oeMap["SyncMode"]),
495494
Constraint: extractString(oeMap["Constraint"]),
@@ -504,8 +503,8 @@ func parseNavigationProfile(raw map[string]any) *types.NavigationProfile {
504503
}
505504

506505
// parseNavMenuItem parses a Menus$MenuItem from BSON.
507-
func parseNavMenuItem(raw map[string]any) *types.NavMenuItem {
508-
mi := &types.NavMenuItem{}
506+
func parseNavMenuItem(raw map[string]any) *NavMenuItem {
507+
mi := &NavMenuItem{}
509508

510509
// Extract caption text (Caption → Items → first Translation → Text)
511510
if caption, ok := raw["Caption"].(map[string]any); ok {
@@ -553,8 +552,8 @@ func parseNavMenuItem(raw map[string]any) *types.NavMenuItem {
553552
}
554553

555554
// parseNavMenuItemFromBottomBar parses a NativePages$BottomBarItem as a NavMenuItem.
556-
func parseNavMenuItemFromBottomBar(raw map[string]any) *types.NavMenuItem {
557-
mi := &types.NavMenuItem{}
555+
func parseNavMenuItemFromBottomBar(raw map[string]any) *NavMenuItem {
556+
mi := &NavMenuItem{}
558557
if caption, ok := raw["Caption"].(map[string]any); ok {
559558
mi.Caption = extractTextFromBson(caption)
560559
}
@@ -590,7 +589,7 @@ func extractTextFromBson(raw map[string]any) string {
590589
}
591590

592591
// parseImageCollection parses image collection contents from BSON.
593-
func (r *Reader) parseImageCollection(unitID, containerID string, contents []byte) (*types.ImageCollection, error) {
592+
func (r *Reader) parseImageCollection(unitID, containerID string, contents []byte) (*ImageCollection, error) {
594593
contents, err := r.resolveContents(unitID, contents)
595594
if err != nil {
596595
return nil, err
@@ -601,7 +600,7 @@ func (r *Reader) parseImageCollection(unitID, containerID string, contents []byt
601600
return nil, fmt.Errorf("failed to unmarshal BSON: %w", err)
602601
}
603602

604-
ic := &types.ImageCollection{}
603+
ic := &ImageCollection{}
605604
ic.ID = model.ID(unitID)
606605
ic.TypeName = "Images$ImageCollection"
607606
ic.ContainerID = model.ID(containerID)
@@ -620,7 +619,7 @@ func (r *Reader) parseImageCollection(unitID, containerID string, contents []byt
620619
if images, ok := raw["Images"].(bson.A); ok {
621620
for _, img := range images {
622621
if imgMap, ok := img.(map[string]any); ok {
623-
image := types.Image{}
622+
image := Image{}
624623
if id := extractID(imgMap["$ID"]); id != "" {
625624
image.ID = model.ID(id)
626625
}
@@ -644,7 +643,7 @@ func (r *Reader) parseImageCollection(unitID, containerID string, contents []byt
644643
}
645644

646645
// parseJsonStructure parses JSON structure contents from BSON.
647-
func (r *Reader) parseJsonStructure(unitID, containerID string, contents []byte) (*types.JsonStructure, error) {
646+
func (r *Reader) parseJsonStructure(unitID, containerID string, contents []byte) (*JsonStructure, error) {
648647
contents, err := r.resolveContents(unitID, contents)
649648
if err != nil {
650649
return nil, err
@@ -655,7 +654,7 @@ func (r *Reader) parseJsonStructure(unitID, containerID string, contents []byte)
655654
return nil, fmt.Errorf("failed to unmarshal BSON: %w", err)
656655
}
657656

658-
js := &types.JsonStructure{}
657+
js := &JsonStructure{}
659658
js.ID = model.ID(unitID)
660659
js.TypeName = "JsonStructures$JsonStructure"
661660
js.ContainerID = model.ID(containerID)
@@ -689,8 +688,8 @@ func (r *Reader) parseJsonStructure(unitID, containerID string, contents []byte)
689688
}
690689

691690
// parseJsonElement recursively parses a JsonStructures$JsonElement from BSON.
692-
func parseJsonElement(raw map[string]any) *types.JsonElement {
693-
elem := &types.JsonElement{
691+
func parseJsonElement(raw map[string]any) *JsonElement {
692+
elem := &JsonElement{
694693
MaxLength: -1,
695694
FractionDigits: -1,
696695
TotalDigits: -1,

sdk/mpr/writer_imagecollection.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
package mpr
44

55
import (
6-
"github.com/mendixlabs/mxcli/mdl/types"
76
"github.com/mendixlabs/mxcli/model"
87
"go.mongodb.org/mongo-driver/bson"
98
"go.mongodb.org/mongo-driver/bson/primitive"
109
)
1110

1211
// CreateImageCollection creates a new empty image collection unit in the MPR.
13-
func (w *Writer) CreateImageCollection(ic *types.ImageCollection) error {
12+
func (w *Writer) CreateImageCollection(ic *ImageCollection) error {
1413
if ic.ID == "" {
1514
ic.ID = model.ID(generateUUID())
1615
}
@@ -32,7 +31,7 @@ func (w *Writer) DeleteImageCollection(id string) error {
3231
return w.deleteUnit(id)
3332
}
3433

35-
func serializeImageCollection(ic *types.ImageCollection) ([]byte, error) {
34+
func serializeImageCollection(ic *ImageCollection) ([]byte, error) {
3635
// Images array always starts with the array marker int32(3)
3736
images := bson.A{int32(3)}
3837
for i := range ic.Images {

sdk/mpr/writer_jsonstructure.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
func PrettyPrintJSON(s string) string { return types.PrettyPrintJSON(s) }
1313

1414
// BuildJsonElementsFromSnippet delegates to types.BuildJsonElementsFromSnippet.
15-
func BuildJsonElementsFromSnippet(snippet string, customNameMap map[string]string) ([]*types.JsonElement, error) {
15+
func BuildJsonElementsFromSnippet(snippet string, customNameMap map[string]string) ([]*JsonElement, error) {
1616
return types.BuildJsonElementsFromSnippet(snippet, customNameMap)
1717
}
1818

1919
// CreateJsonStructure creates a new JSON structure unit in the MPR.
20-
func (w *Writer) CreateJsonStructure(js *types.JsonStructure) error {
20+
func (w *Writer) CreateJsonStructure(js *JsonStructure) error {
2121
if js.ID == "" {
2222
js.ID = model.ID(generateUUID())
2323
}
@@ -39,7 +39,7 @@ func (w *Writer) DeleteJsonStructure(id string) error {
3939
return w.deleteUnit(id)
4040
}
4141

42-
func serializeJsonStructure(js *types.JsonStructure) ([]byte, error) {
42+
func serializeJsonStructure(js *JsonStructure) ([]byte, error) {
4343
elements := bson.A{int32(2)}
4444
for _, elem := range js.Elements {
4545
elements = append(elements, serializeJsonElement(elem))
@@ -62,7 +62,7 @@ func serializeJsonStructure(js *types.JsonStructure) ([]byte, error) {
6262
// serializeJsonElement serializes a single JsonElement to BSON.
6363
// Note: JsonStructures$JsonElement uses int32 for numeric properties (MinOccurs, MaxOccurs, etc.),
6464
// unlike most other Mendix document types which use int64. Verified against Studio Pro-generated BSON.
65-
func serializeJsonElement(elem *types.JsonElement) bson.D {
65+
func serializeJsonElement(elem *JsonElement) bson.D {
6666
children := bson.A{int32(2)}
6767
for _, child := range elem.Children {
6868
children = append(children, serializeJsonElement(child))

0 commit comments

Comments
 (0)