Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
481 changes: 481 additions & 0 deletions cmd/modelsdk-codegen/audit.go

Large diffs are not rendered by default.

415 changes: 415 additions & 0 deletions cmd/modelsdk-codegen/main.go

Large diffs are not rendered by default.

755 changes: 755 additions & 0 deletions internal/codegen/dtsparser/jsparser.go

Large diffs are not rendered by default.

452 changes: 452 additions & 0 deletions internal/codegen/dtsparser/jsparser_test.go

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions internal/codegen/dtsparser/poc_all_domains_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dtsparser

import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
)

func TestParseAllDomains(t *testing.T) {
genDir := "../../../reference/mendixmodelsdk/src/gen"
if _, err := os.Stat(genDir); os.IsNotExist(err) {
t.Skip("reference/mendixmodelsdk not available")
}

// Collect all enums across modules
allEnums := collectCrossModuleEnums(genDir)
t.Logf("Cross-module enums collected: %d", len(allEnums))

entries, err := os.ReadDir(genDir)
if err != nil {
t.Fatalf("cannot read gen dir: %v", err)
}

totalClasses := 0
totalEnums := 0
totalProps := 0
totalStructTypeNames := 0
kindCounts := map[PropertyKind]int{}
domainSummary := []string{}

for _, entry := range entries {
if !strings.HasSuffix(entry.Name(), ".d.ts") {
continue
}
domain := strings.TrimSuffix(entry.Name(), ".d.ts")
if domain == "base-model" || domain == "all-model-classes" {
continue // meta files, not domain files
}

dtsData, err := os.ReadFile(filepath.Join(genDir, entry.Name()))
if err != nil {
t.Errorf("cannot read %s: %v", entry.Name(), err)
continue
}

classes, enums := parseDtsFileWithEnums(string(dtsData), allEnums)

// Also parse .js for structureTypeNames
jsFile := strings.TrimSuffix(entry.Name(), ".d.ts") + ".js"
jsData, _ := os.ReadFile(filepath.Join(genDir, jsFile))
stns := parseStructureTypeNames(string(jsData))

domainClasses := len(classes)
domainEnums := len(enums)
domainProps := 0
for _, c := range classes {
domainProps += len(c.Properties)
for _, p := range c.Properties {
kindCounts[p.Kind]++
}
}

totalClasses += domainClasses
totalEnums += domainEnums
totalProps += domainProps
totalStructTypeNames += len(stns)

domainSummary = append(domainSummary,
fmt.Sprintf("%-30s classes=%3d enums=%2d props=%4d $Types=%3d",
domain, domainClasses, domainEnums, domainProps, len(stns)))
}

t.Log("=== Per-Domain Summary ===")
for _, s := range domainSummary {
t.Log(s)
}

t.Log("=== Totals ===")
t.Logf("Domains: %d", len(domainSummary))
t.Logf("Total classes: %d", totalClasses)
t.Logf("Total enums: %d", totalEnums)
t.Logf("Total properties: %d", totalProps)
t.Logf("Total $Type names: %d", totalStructTypeNames)

t.Log("=== Property Kind Distribution ===")
for k, v := range kindCounts {
t.Logf(" %-10s: %4d (%.1f%%)", k, v, float64(v)/float64(totalProps)*100)
}

// Classification rate
unknownPct := float64(kindCounts[KindUnknown]) / float64(totalProps) * 100
classRate := 100 - unknownPct
t.Logf("Classification rate: %.1f%%", classRate)

// Assertions
if len(domainSummary) < 40 {
t.Errorf("expected at least 40 domains, got %d", len(domainSummary))
}
if totalClasses < 200 {
t.Errorf("expected at least 200 classes, got %d", totalClasses)
}
if classRate < 80 {
t.Errorf("classification rate %.1f%% too low, expected >= 80%%", classRate)
}
}
Loading
Loading