-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
87 lines (72 loc) · 2.08 KB
/
index.ts
File metadata and controls
87 lines (72 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Entity Codegen & Domain Analyzer
*
* A validation and analysis tool for entity YAML definitions.
* Parses entities, builds a relationship graph, and detects issues.
*/
import { loadEntities, resolveReferences } from './parser';
import { buildDomainGraph, checkConsistency, computeStatistics } from './analyzer';
import type { AnalysisResult, OutputFormat } from './analyzer/types';
/**
* Analyze a domain from entity YAML files in a directory
*/
export async function analyzeDomain(entitiesDir: string): Promise<AnalysisResult> {
// Load and parse all entity files
const { entities, issues: loadIssues } = loadEntities(entitiesDir);
// Resolve cross-entity references
const resolveIssues = resolveReferences(entities);
// Build relationship graph
const graph = buildDomainGraph(entities);
// Check consistency
const consistencyIssues = checkConsistency(graph);
// Compute statistics
const statistics = computeStatistics(graph);
// Combine all issues
const allIssues = [...loadIssues, ...resolveIssues, ...consistencyIssues];
// Determine validity (only errors make it invalid)
const hasErrors = allIssues.some((i) => i.severity === 'error');
return {
isValid: !hasErrors,
entities,
graph,
issues: allIssues,
statistics,
};
}
/**
* Validate entity files without full analysis
* Returns true if all files parse successfully
*/
export function validateEntities(entitiesDir: string): {
valid: boolean;
errors: string[];
} {
const { entities, issues } = loadEntities(entitiesDir);
const errors = issues
.filter((i) => i.severity === 'error')
.map((i) => i.message);
return {
valid: errors.length === 0,
errors,
};
}
// Re-export types
export * from './analyzer/types';
// Re-export parser utilities
export { loadEntities, loadEntityFromYaml } from './parser';
// Re-export analyzer utilities
export {
buildDomainGraph,
getRelatedEntities,
findOrphanEntities,
findCircularDependencies,
checkConsistency,
computeStatistics,
} from './analyzer';
// Re-export formatters
export {
formatConsole,
formatJson,
formatMarkdown,
formatMermaidGraph,
} from './output';