@@ -174,21 +174,31 @@ func extractBsonArrayWithMarker(v any) BsonArrayInfo {
174174 }
175175
176176 if len (slice ) > 0 {
177- if marker , ok := slice [0 ].(int32 ); ok && (marker == 2 || marker == 3 ) {
177+ if marker , ok := slice [0 ].(int32 ); ok && (marker == 1 || marker == 2 || marker == 3 ) {
178178 return BsonArrayInfo {Marker : marker , Items : slice [1 :]}
179179 }
180180 }
181181 return BsonArrayInfo {Items : slice }
182182}
183183
184- // inferPropertyKind determines whether a BSON field value represents a primitive,
185- // a by-name reference, or a part (embedded object). This is used by the generic
186- // unknown-element parser to preserve raw fields with semantic context.
184+ // inferPropertyKind determines the Mendix property kind of a BSON field from its key
185+ // and value shape. Returns one of: "id", "type-discriminator", "by-name-reference",
186+ // "primitive", "part", "collection:by-name" (marker=1), "collection:part-secondary"
187+ // (marker=2), "collection:part-primary" (marker=3), "collection".
188+ // Used by UnknownElement to surface diagnostic info when an unimplemented $Type is encountered.
187189func inferPropertyKind (key string , v any ) string {
188190 if v == nil {
189191 return "primitive"
190192 }
191193
194+ // Key-based shortcuts take priority over value shape.
195+ switch key {
196+ case "$ID" , "$ContainerID" :
197+ return "id"
198+ case "$Type" :
199+ return "type-discriminator"
200+ }
201+
192202 switch val := v .(type ) {
193203 case map [string ]any :
194204 if _ , hasType := val ["$Type" ]; hasType {
@@ -219,10 +229,19 @@ func inferPropertyKind(key string, v any) string {
219229 return "primitive"
220230
221231 case primitive.A , []any :
232+ info := extractBsonArrayWithMarker (v )
233+ switch info .Marker {
234+ case 1 :
235+ return "collection:by-name"
236+ case 2 :
237+ return "collection:part-secondary"
238+ case 3 :
239+ return "collection:part-primary"
240+ }
222241 return "collection"
223242
224243 case string :
225- // Heuristic: qualified names like "Module.Entity" are likely by-name references
244+ // Heuristic: qualified names like "Module.Entity" are likely by-name references.
226245 if strings .Contains (val , "." ) && ! strings .Contains (val , " " ) && ! strings .Contains (val , "/" ) {
227246 return "by-name-reference"
228247 }
0 commit comments