Skip to content

Commit b75c848

Browse files
committed
Add MDL
Add export mapping
1 parent c5e33be commit b75c848

21 files changed

Lines changed: 10297 additions & 8002 deletions

CLAUDE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
This file provides guidance for Claude Code when working with this repository.
44

5+
## Canonical Test Project Path
6+
7+
**ALWAYS use:** `/Users/Dennis.Kho/Sandbox/KhodeClaudeLab-main/KhodeClaudeLab.mpr`
8+
9+
A disposable test copy exists at `/tmp/KhodeClaudeLab-test/`**never use it for `mxcli exec` or write operations**. Before running any `mxcli -p <path> exec` command, verify the path starts with `/Users/Dennis.Kho/Sandbox/KhodeClaudeLab-main/`. If the path points to `/tmp/` or any other copy, stop and correct it first.
10+
511
## Project Overview
612

713
**ModelSDK Go** is a Go library for reading and modifying Mendix application projects (`.mpr` files) stored locally on disk. It's a Go-native alternative to the TypeScript-based Mendix Model SDK, enabling programmatic access without cloud connectivity.
@@ -151,6 +157,19 @@ When adding new types, always verify the storage name by:
151157

152158
**IMPORTANT**: When unsure about the correct BSON structure for a new feature, **ask the user to create a working example in Mendix Studio Pro** so you can compare the generated BSON against a known-good reference.
153159

160+
### Generated Metamodel $Type Naming Trap (MappingElements)
161+
162+
**CRITICAL**: The Go struct names in `generated/metamodel/types.go` are NOT reliable sources for BSON `$Type` strings. The generated code embeds the namespace word in element type names, but the real Mendix BSON does NOT.
163+
164+
| Go struct (WRONG as $Type) | Correct BSON $Type |
165+
|----------------------------|--------------------|
166+
| `ImportMappingsImportObjectMappingElement` | `ImportMappings$ObjectMappingElement` |
167+
| `ImportMappingsImportValueMappingElement` | `ImportMappings$ValueMappingElement` |
168+
| `ExportMappingsExportObjectMappingElement` | `ExportMappings$ObjectMappingElement` |
169+
| `ExportMappingsExportValueMappingElement` | `ExportMappings$ValueMappingElement` |
170+
171+
**Rule**: MappingElement `$Type` names follow `Namespace$ElementKind` — the namespace prefix word is never repeated inside the element name. Both mistakes have been encountered in production and caused `TypeCacheUnknownTypeException`. Always verify against the working writer code (`writer_import_mapping.go`, `writer_export_mapping.go`) or a Studio Pro-created MPR before writing a new mapping serializer.
172+
154173
### Pluggable Widget Templates
155174

156175
For pluggable widgets (DataGrid2, ComboBox, Gallery, etc.), templates must include **both** `type` AND `object` fields:

mdl/ast/ast_json_structure.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,44 @@ type ImportMappingElementDef struct {
6464
DataType string // "String", "Integer", "Boolean", "Decimal", "DateTime"
6565
IsKey bool
6666
}
67+
68+
// ============================================================================
69+
// Export Mapping Statements
70+
// ============================================================================
71+
72+
// CreateExportMappingStmt represents:
73+
//
74+
// CREATE EXPORT MAPPING Module.Name
75+
// [TO JSON STRUCTURE Module.JsonStructure | TO XML SCHEMA Module.Schema]
76+
// [NULL VALUES LeaveOutElement | SendAsNil]
77+
// { Module.Entity -> root { ... } }
78+
type CreateExportMappingStmt struct {
79+
Name QualifiedName
80+
SchemaKind string // "JSON_STRUCTURE" or "XML_SCHEMA" or ""
81+
SchemaRef QualifiedName // qualified name of the schema source
82+
NullValueOption string // "LeaveOutElement" or "SendAsNil" (default: "LeaveOutElement")
83+
RootElement *ExportMappingElementDef
84+
}
85+
86+
func (s *CreateExportMappingStmt) isStatement() {}
87+
88+
// DropExportMappingStmt represents: DROP EXPORT MAPPING Module.Name
89+
type DropExportMappingStmt struct {
90+
Name QualifiedName
91+
}
92+
93+
func (s *DropExportMappingStmt) isStatement() {}
94+
95+
// ExportMappingElementDef represents one element in an export mapping tree.
96+
// It may be an object mapping (entity → JSON key) or a value mapping (attribute → JSON key).
97+
type ExportMappingElementDef struct {
98+
// JSON field name (the RHS of ->)
99+
JsonName string
100+
// Object mapping fields (set when mapping from an entity)
101+
Entity string // qualified entity name (e.g. "Module.Customer")
102+
Association string // qualified association name for VIA clause
103+
Children []*ExportMappingElementDef
104+
// Value mapping fields (set when mapping from an attribute)
105+
Attribute string // attribute name (unqualified, e.g. "Name")
106+
DataType string // "String", "Integer", "Boolean", "Decimal", "DateTime"
107+
}

mdl/ast/ast_query.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const (
8686
ShowContractMessages // SHOW CONTRACT MESSAGES FROM Module.Service (AsyncAPI)
8787
ShowJsonStructures // SHOW JSON STRUCTURES [IN module]
8888
ShowImportMappings // SHOW IMPORT MAPPINGS [IN module]
89+
ShowExportMappings // SHOW EXPORT MAPPINGS [IN module]
8990
)
9091

9192
// String returns the human-readable name of the show object type.
@@ -205,6 +206,8 @@ func (t ShowObjectType) String() string {
205206
return "JSON STRUCTURES"
206207
case ShowImportMappings:
207208
return "IMPORT MAPPINGS"
209+
case ShowExportMappings:
210+
return "EXPORT MAPPINGS"
208211
default:
209212
return "UNKNOWN"
210213
}
@@ -262,6 +265,7 @@ const (
262265
DescribeContractMessage // DESCRIBE CONTRACT MESSAGE Service.MessageName
263266
DescribeJsonStructure // DESCRIBE JSON STRUCTURE Module.Name
264267
DescribeImportMapping // DESCRIBE IMPORT MAPPING Module.Name
268+
DescribeExportMapping // DESCRIBE EXPORT MAPPING Module.Name
265269
)
266270

267271
// String returns the human-readable name of the describe object type.
@@ -329,6 +333,8 @@ func (t DescribeObjectType) String() string {
329333
return "JSON STRUCTURE"
330334
case DescribeImportMapping:
331335
return "IMPORT MAPPING"
336+
case DescribeExportMapping:
337+
return "EXPORT MAPPING"
332338
default:
333339
return "UNKNOWN"
334340
}

0 commit comments

Comments
 (0)