@domainlang/language 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +163 -0
  2. package/out/ast-augmentation.d.ts +6 -0
  3. package/out/ast-augmentation.js +2 -0
  4. package/out/ast-augmentation.js.map +1 -0
  5. package/out/domain-lang-module.d.ts +57 -0
  6. package/out/domain-lang-module.js +67 -0
  7. package/out/domain-lang-module.js.map +1 -0
  8. package/out/generated/ast.d.ts +759 -0
  9. package/out/generated/ast.js +556 -0
  10. package/out/generated/ast.js.map +1 -0
  11. package/out/generated/grammar.d.ts +6 -0
  12. package/out/generated/grammar.js +2407 -0
  13. package/out/generated/grammar.js.map +1 -0
  14. package/out/generated/module.d.ts +13 -0
  15. package/out/generated/module.js +21 -0
  16. package/out/generated/module.js.map +1 -0
  17. package/out/index.d.ts +16 -0
  18. package/out/index.js +22 -0
  19. package/out/index.js.map +1 -0
  20. package/out/lsp/domain-lang-code-actions.d.ts +55 -0
  21. package/out/lsp/domain-lang-code-actions.js +143 -0
  22. package/out/lsp/domain-lang-code-actions.js.map +1 -0
  23. package/out/lsp/domain-lang-completion.d.ts +37 -0
  24. package/out/lsp/domain-lang-completion.js +452 -0
  25. package/out/lsp/domain-lang-completion.js.map +1 -0
  26. package/out/lsp/domain-lang-formatter.d.ts +15 -0
  27. package/out/lsp/domain-lang-formatter.js +43 -0
  28. package/out/lsp/domain-lang-formatter.js.map +1 -0
  29. package/out/lsp/domain-lang-naming.d.ts +34 -0
  30. package/out/lsp/domain-lang-naming.js +49 -0
  31. package/out/lsp/domain-lang-naming.js.map +1 -0
  32. package/out/lsp/domain-lang-scope.d.ts +59 -0
  33. package/out/lsp/domain-lang-scope.js +102 -0
  34. package/out/lsp/domain-lang-scope.js.map +1 -0
  35. package/out/lsp/domain-lang-workspace-manager.d.ts +21 -0
  36. package/out/lsp/domain-lang-workspace-manager.js +93 -0
  37. package/out/lsp/domain-lang-workspace-manager.js.map +1 -0
  38. package/out/lsp/hover/ddd-pattern-explanations.d.ts +50 -0
  39. package/out/lsp/hover/ddd-pattern-explanations.js +196 -0
  40. package/out/lsp/hover/ddd-pattern-explanations.js.map +1 -0
  41. package/out/lsp/hover/domain-lang-hover.d.ts +19 -0
  42. package/out/lsp/hover/domain-lang-hover.js +302 -0
  43. package/out/lsp/hover/domain-lang-hover.js.map +1 -0
  44. package/out/lsp/hover/domain-lang-keywords.d.ts +13 -0
  45. package/out/lsp/hover/domain-lang-keywords.js +47 -0
  46. package/out/lsp/hover/domain-lang-keywords.js.map +1 -0
  47. package/out/lsp/manifest-diagnostics.d.ts +82 -0
  48. package/out/lsp/manifest-diagnostics.js +230 -0
  49. package/out/lsp/manifest-diagnostics.js.map +1 -0
  50. package/out/main-browser.d.ts +1 -0
  51. package/out/main-browser.js +11 -0
  52. package/out/main-browser.js.map +1 -0
  53. package/out/main.d.ts +1 -0
  54. package/out/main.js +74 -0
  55. package/out/main.js.map +1 -0
  56. package/out/sdk/ast-augmentation.d.ts +136 -0
  57. package/out/sdk/ast-augmentation.js +62 -0
  58. package/out/sdk/ast-augmentation.js.map +1 -0
  59. package/out/sdk/index.d.ts +94 -0
  60. package/out/sdk/index.js +97 -0
  61. package/out/sdk/index.js.map +1 -0
  62. package/out/sdk/indexes.d.ts +16 -0
  63. package/out/sdk/indexes.js +97 -0
  64. package/out/sdk/indexes.js.map +1 -0
  65. package/out/sdk/loader-node.d.ts +51 -0
  66. package/out/sdk/loader-node.js +119 -0
  67. package/out/sdk/loader-node.js.map +1 -0
  68. package/out/sdk/loader.d.ts +49 -0
  69. package/out/sdk/loader.js +85 -0
  70. package/out/sdk/loader.js.map +1 -0
  71. package/out/sdk/patterns.d.ts +93 -0
  72. package/out/sdk/patterns.js +123 -0
  73. package/out/sdk/patterns.js.map +1 -0
  74. package/out/sdk/query.d.ts +90 -0
  75. package/out/sdk/query.js +679 -0
  76. package/out/sdk/query.js.map +1 -0
  77. package/out/sdk/resolution.d.ts +52 -0
  78. package/out/sdk/resolution.js +68 -0
  79. package/out/sdk/resolution.js.map +1 -0
  80. package/out/sdk/types.d.ts +280 -0
  81. package/out/sdk/types.js +8 -0
  82. package/out/sdk/types.js.map +1 -0
  83. package/out/services/dependency-analyzer.d.ts +58 -0
  84. package/out/services/dependency-analyzer.js +254 -0
  85. package/out/services/dependency-analyzer.js.map +1 -0
  86. package/out/services/dependency-resolver.d.ts +146 -0
  87. package/out/services/dependency-resolver.js +452 -0
  88. package/out/services/dependency-resolver.js.map +1 -0
  89. package/out/services/git-url-resolver.browser.d.ts +10 -0
  90. package/out/services/git-url-resolver.browser.js +19 -0
  91. package/out/services/git-url-resolver.browser.js.map +1 -0
  92. package/out/services/git-url-resolver.d.ts +158 -0
  93. package/out/services/git-url-resolver.js +416 -0
  94. package/out/services/git-url-resolver.js.map +1 -0
  95. package/out/services/governance-validator.d.ts +44 -0
  96. package/out/services/governance-validator.js +153 -0
  97. package/out/services/governance-validator.js.map +1 -0
  98. package/out/services/import-resolver.d.ts +77 -0
  99. package/out/services/import-resolver.js +240 -0
  100. package/out/services/import-resolver.js.map +1 -0
  101. package/out/services/performance-optimizer.d.ts +60 -0
  102. package/out/services/performance-optimizer.js +140 -0
  103. package/out/services/performance-optimizer.js.map +1 -0
  104. package/out/services/relationship-inference.d.ts +11 -0
  105. package/out/services/relationship-inference.js +98 -0
  106. package/out/services/relationship-inference.js.map +1 -0
  107. package/out/services/semver.d.ts +98 -0
  108. package/out/services/semver.js +195 -0
  109. package/out/services/semver.js.map +1 -0
  110. package/out/services/types.d.ts +340 -0
  111. package/out/services/types.js +46 -0
  112. package/out/services/types.js.map +1 -0
  113. package/out/services/workspace-manager.d.ts +123 -0
  114. package/out/services/workspace-manager.js +489 -0
  115. package/out/services/workspace-manager.js.map +1 -0
  116. package/out/syntaxes/domain-lang.monarch.d.ts +76 -0
  117. package/out/syntaxes/domain-lang.monarch.js +29 -0
  118. package/out/syntaxes/domain-lang.monarch.js.map +1 -0
  119. package/out/utils/import-utils.d.ts +49 -0
  120. package/out/utils/import-utils.js +128 -0
  121. package/out/utils/import-utils.js.map +1 -0
  122. package/out/validation/bounded-context.d.ts +11 -0
  123. package/out/validation/bounded-context.js +79 -0
  124. package/out/validation/bounded-context.js.map +1 -0
  125. package/out/validation/classification.d.ts +3 -0
  126. package/out/validation/classification.js +3 -0
  127. package/out/validation/classification.js.map +1 -0
  128. package/out/validation/constants.d.ts +180 -0
  129. package/out/validation/constants.js +235 -0
  130. package/out/validation/constants.js.map +1 -0
  131. package/out/validation/domain-lang-validator.d.ts +2 -0
  132. package/out/validation/domain-lang-validator.js +27 -0
  133. package/out/validation/domain-lang-validator.js.map +1 -0
  134. package/out/validation/domain.d.ts +11 -0
  135. package/out/validation/domain.js +63 -0
  136. package/out/validation/domain.js.map +1 -0
  137. package/out/validation/import.d.ts +68 -0
  138. package/out/validation/import.js +237 -0
  139. package/out/validation/import.js.map +1 -0
  140. package/out/validation/manifest.d.ts +144 -0
  141. package/out/validation/manifest.js +327 -0
  142. package/out/validation/manifest.js.map +1 -0
  143. package/out/validation/maps.d.ts +21 -0
  144. package/out/validation/maps.js +60 -0
  145. package/out/validation/maps.js.map +1 -0
  146. package/out/validation/metadata.d.ts +7 -0
  147. package/out/validation/metadata.js +16 -0
  148. package/out/validation/metadata.js.map +1 -0
  149. package/out/validation/model.d.ts +12 -0
  150. package/out/validation/model.js +29 -0
  151. package/out/validation/model.js.map +1 -0
  152. package/out/validation/relationships.d.ts +12 -0
  153. package/out/validation/relationships.js +94 -0
  154. package/out/validation/relationships.js.map +1 -0
  155. package/out/validation/shared.d.ts +6 -0
  156. package/out/validation/shared.js +12 -0
  157. package/out/validation/shared.js.map +1 -0
  158. package/package.json +110 -0
  159. package/src/ast-augmentation.ts +5 -0
  160. package/src/domain-lang-module.ts +112 -0
  161. package/src/domain-lang.langium +351 -0
  162. package/src/generated/ast.ts +986 -0
  163. package/src/generated/grammar.ts +2409 -0
  164. package/src/generated/module.ts +25 -0
  165. package/src/index.ts +24 -0
  166. package/src/lsp/domain-lang-code-actions.ts +189 -0
  167. package/src/lsp/domain-lang-completion.ts +514 -0
  168. package/src/lsp/domain-lang-formatter.ts +51 -0
  169. package/src/lsp/domain-lang-naming.ts +56 -0
  170. package/src/lsp/domain-lang-scope.ts +137 -0
  171. package/src/lsp/domain-lang-workspace-manager.ts +104 -0
  172. package/src/lsp/hover/ddd-pattern-explanations.ts +237 -0
  173. package/src/lsp/hover/domain-lang-hover.ts +338 -0
  174. package/src/lsp/hover/domain-lang-keywords.ts +50 -0
  175. package/src/lsp/manifest-diagnostics.ts +290 -0
  176. package/src/main-browser.ts +15 -0
  177. package/src/main.ts +85 -0
  178. package/src/sdk/README.md +297 -0
  179. package/src/sdk/ast-augmentation.ts +157 -0
  180. package/src/sdk/index.ts +126 -0
  181. package/src/sdk/indexes.ts +155 -0
  182. package/src/sdk/loader-node.ts +146 -0
  183. package/src/sdk/loader.ts +99 -0
  184. package/src/sdk/patterns.ts +147 -0
  185. package/src/sdk/query.ts +802 -0
  186. package/src/sdk/resolution.ts +78 -0
  187. package/src/sdk/types.ts +323 -0
  188. package/src/services/dependency-analyzer.ts +321 -0
  189. package/src/services/dependency-resolver.ts +551 -0
  190. package/src/services/git-url-resolver.browser.ts +26 -0
  191. package/src/services/git-url-resolver.ts +517 -0
  192. package/src/services/governance-validator.ts +177 -0
  193. package/src/services/import-resolver.ts +292 -0
  194. package/src/services/performance-optimizer.ts +170 -0
  195. package/src/services/relationship-inference.ts +121 -0
  196. package/src/services/semver.ts +213 -0
  197. package/src/services/types.ts +415 -0
  198. package/src/services/workspace-manager.ts +607 -0
  199. package/src/syntaxes/domain-lang.monarch.ts +29 -0
  200. package/src/utils/import-utils.ts +152 -0
  201. package/src/validation/bounded-context.ts +99 -0
  202. package/src/validation/classification.ts +5 -0
  203. package/src/validation/constants.ts +304 -0
  204. package/src/validation/domain-lang-validator.ts +33 -0
  205. package/src/validation/domain.ts +77 -0
  206. package/src/validation/import.ts +295 -0
  207. package/src/validation/manifest.ts +439 -0
  208. package/src/validation/maps.ts +76 -0
  209. package/src/validation/metadata.ts +18 -0
  210. package/src/validation/model.ts +37 -0
  211. package/src/validation/relationships.ts +154 -0
  212. package/src/validation/shared.ts +14 -0
@@ -0,0 +1,439 @@
1
+ /**
2
+ * Manifest Validation for DomainLang.
3
+ *
4
+ * Provides schema validation and issue detection for model.yaml files.
5
+ * This validation is triggered by the workspace manager when manifests are loaded.
6
+ *
7
+ * Validation includes:
8
+ * - Required fields for publishable packages
9
+ * - Dependency configuration correctness
10
+ * - Path alias validation
11
+ * - Version format validation
12
+ *
13
+ * @module
14
+ */
15
+
16
+ import type { ModelManifest, DependencySpec, ExtendedDependencySpec } from '../services/types.js';
17
+ import { IssueCodes } from './constants.js';
18
+
19
+ // ============================================================================
20
+ // Manifest Validation Types
21
+ // ============================================================================
22
+
23
+ /**
24
+ * Severity levels for manifest diagnostics.
25
+ */
26
+ export type ManifestSeverity = 'error' | 'warning' | 'info';
27
+
28
+ /**
29
+ * A diagnostic issue found in model.yaml.
30
+ */
31
+ export interface ManifestDiagnostic {
32
+ /** Issue code for code action mapping */
33
+ readonly code: string;
34
+ /** Error severity */
35
+ readonly severity: ManifestSeverity;
36
+ /** Human-readable message */
37
+ readonly message: string;
38
+ /** YAML path to the issue (e.g., "dependencies.core.version") */
39
+ readonly path: string;
40
+ /** Optional hint for resolution */
41
+ readonly hint?: string;
42
+ }
43
+
44
+ /**
45
+ * Result of manifest validation.
46
+ */
47
+ export interface ManifestValidationResult {
48
+ /** Whether the manifest is valid (no errors) */
49
+ readonly valid: boolean;
50
+ /** All diagnostics found */
51
+ readonly diagnostics: ManifestDiagnostic[];
52
+ /** Count of errors only */
53
+ readonly errorCount: number;
54
+ /** Count of warnings only */
55
+ readonly warningCount: number;
56
+ }
57
+
58
+ // ============================================================================
59
+ // Issue Code Mapping for Manifest Validation
60
+ // ============================================================================
61
+
62
+ /**
63
+ * Issue codes specific to manifest validation.
64
+ * These extend the general IssueCodes for manifest-specific issues.
65
+ */
66
+ export const ManifestIssueCodes = {
67
+ // Model section issues
68
+ ModelMissingName: 'manifest-model-missing-name',
69
+ ModelMissingVersion: 'manifest-model-missing-version',
70
+ ModelInvalidVersion: 'manifest-model-invalid-version',
71
+
72
+ // Dependency section issues
73
+ DependencyMissingRef: 'manifest-dependency-missing-ref',
74
+ DependencyInvalidRef: 'manifest-dependency-invalid-ref',
75
+ DependencyConflictingSourcePath: 'manifest-dependency-conflicting-source-path',
76
+ DependencyMissingSourceOrPath: 'manifest-dependency-missing-source-or-path',
77
+ DependencyInvalidSource: 'manifest-dependency-invalid-source',
78
+ DependencyAbsolutePath: 'manifest-dependency-absolute-path',
79
+
80
+ // Path alias issues
81
+ PathAliasMissingAtPrefix: 'manifest-path-alias-missing-at-prefix',
82
+ PathAliasAbsolutePath: 'manifest-path-alias-absolute-path'
83
+ } as const;
84
+
85
+ type ManifestIssueCode = typeof ManifestIssueCodes[keyof typeof ManifestIssueCodes] | typeof IssueCodes[keyof typeof IssueCodes];
86
+
87
+ // ============================================================================
88
+ // Manifest Validator
89
+ // ============================================================================
90
+
91
+ /**
92
+ * Validates model.yaml manifests and reports issues.
93
+ *
94
+ * Usage:
95
+ * ```typescript
96
+ * const validator = new ManifestValidator();
97
+ * const result = validator.validate(manifest);
98
+ * if (!result.valid) {
99
+ * console.log(result.diagnostics);
100
+ * }
101
+ * ```
102
+ */
103
+ export class ManifestValidator {
104
+
105
+ /**
106
+ * Validates a parsed model.yaml manifest.
107
+ *
108
+ * @param manifest - The parsed manifest object
109
+ * @param options - Optional validation options
110
+ * @returns Validation result with diagnostics
111
+ */
112
+ validate(
113
+ manifest: ModelManifest,
114
+ options: { requirePublishable?: boolean } = {}
115
+ ): ManifestValidationResult {
116
+ const diagnostics: ManifestDiagnostic[] = [];
117
+
118
+ // Validate model section
119
+ this.validateModelSection(manifest, diagnostics, options.requirePublishable ?? false);
120
+
121
+ // Validate dependencies section
122
+ this.validateDependenciesSection(manifest, diagnostics);
123
+
124
+ // Validate paths section
125
+ this.validatePathsSection(manifest, diagnostics);
126
+
127
+ // Calculate counts
128
+ const errorCount = diagnostics.filter(d => d.severity === 'error').length;
129
+ const warningCount = diagnostics.filter(d => d.severity === 'warning').length;
130
+
131
+ return {
132
+ valid: errorCount === 0,
133
+ diagnostics,
134
+ errorCount,
135
+ warningCount
136
+ };
137
+ }
138
+
139
+ /**
140
+ * Validates the model section of the manifest.
141
+ */
142
+ private validateModelSection(
143
+ manifest: ModelManifest,
144
+ diagnostics: ManifestDiagnostic[],
145
+ requirePublishable: boolean
146
+ ): void {
147
+ const model = manifest.model;
148
+
149
+ // If no model section and not requiring publishable, that's OK
150
+ if (!model && !requirePublishable) {
151
+ return;
152
+ }
153
+
154
+ // If requiring publishable package, name and version are required
155
+ if (requirePublishable) {
156
+ if (!model?.name) {
157
+ diagnostics.push({
158
+ code: ManifestIssueCodes.ModelMissingName as ManifestIssueCode,
159
+ severity: 'error',
160
+ message: 'Publishable packages require a model.name field.',
161
+ path: 'model.name',
162
+ hint: 'Add "name: my-package" under the model section.'
163
+ });
164
+ }
165
+
166
+ if (!model?.version) {
167
+ diagnostics.push({
168
+ code: ManifestIssueCodes.ModelMissingVersion as ManifestIssueCode,
169
+ severity: 'error',
170
+ message: 'Publishable packages require a model.version field.',
171
+ path: 'model.version',
172
+ hint: 'Add "version: 1.0.0" under the model section.'
173
+ });
174
+ }
175
+ }
176
+
177
+ // Validate version format if present
178
+ if (model?.version && !this.isValidSemVer(model.version)) {
179
+ diagnostics.push({
180
+ code: ManifestIssueCodes.ModelInvalidVersion as ManifestIssueCode,
181
+ severity: 'warning',
182
+ message: `Version '${model.version}' is not valid SemVer format.`,
183
+ path: 'model.version',
184
+ hint: 'Use SemVer format like "1.0.0" or "1.2.3-beta".'
185
+ });
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Validates the dependencies section of the manifest.
191
+ */
192
+ private validateDependenciesSection(
193
+ manifest: ModelManifest,
194
+ diagnostics: ManifestDiagnostic[]
195
+ ): void {
196
+ const dependencies = manifest.dependencies;
197
+ if (!dependencies) {
198
+ return;
199
+ }
200
+
201
+ for (const [key, dep] of Object.entries(dependencies)) {
202
+ this.validateDependency(key, dep, diagnostics);
203
+ }
204
+ }
205
+
206
+ /**
207
+ * Validates a single dependency entry.
208
+ */
209
+ private validateDependency(
210
+ key: string,
211
+ dep: DependencySpec,
212
+ diagnostics: ManifestDiagnostic[]
213
+ ): void {
214
+ const normalized = this.normalizeDependency(key, dep);
215
+ const basePath = `dependencies.${key}`;
216
+
217
+ // Check for conflicting source and path
218
+ if (normalized.source && normalized.path) {
219
+ diagnostics.push({
220
+ code: IssueCodes.ImportConflictingSourcePath,
221
+ severity: 'error',
222
+ message: `Dependency '${key}' cannot have both 'source' and 'path'.`,
223
+ path: basePath,
224
+ hint: `Use 'source' for git packages or 'path' for local workspace packages.`
225
+ });
226
+ return; // Don't validate further if this fundamental issue exists
227
+ }
228
+
229
+ // Check that at least one of source or path is present
230
+ if (!normalized.source && !normalized.path) {
231
+ diagnostics.push({
232
+ code: IssueCodes.ImportMissingSourceOrPath,
233
+ severity: 'error',
234
+ message: `Dependency '${key}' must have either 'source' or 'path'.`,
235
+ path: basePath,
236
+ hint: `Add 'source: owner/repo' for git packages or 'path: ./local' for local packages.`
237
+ });
238
+ return;
239
+ }
240
+
241
+ // Validate source-based dependencies
242
+ if (normalized.source) {
243
+ this.validateSourceDependency(key, normalized, basePath, diagnostics);
244
+ }
245
+
246
+ // Validate path-based dependencies
247
+ if (normalized.path) {
248
+ this.validatePathDependency(key, normalized, basePath, diagnostics);
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Validates a git-source based dependency.
254
+ */
255
+ private validateSourceDependency(
256
+ key: string,
257
+ dep: ExtendedDependencySpec,
258
+ basePath: string,
259
+ diagnostics: ManifestDiagnostic[]
260
+ ): void {
261
+ // Source dependencies require a ref (tag, branch, or commit)
262
+ if (!dep.ref) {
263
+ diagnostics.push({
264
+ code: IssueCodes.ImportMissingRef,
265
+ severity: 'error',
266
+ message: `Git dependency '${key}' requires a ref.`,
267
+ path: `${basePath}.ref`,
268
+ hint: `Add a git ref: 'ref: v1.0.0' (tag), 'ref: main' (branch), or a commit SHA.`
269
+ });
270
+ }
271
+
272
+ // Validate ref format
273
+ if (dep.ref && !this.isValidRefSpec(dep.ref)) {
274
+ diagnostics.push({
275
+ code: ManifestIssueCodes.DependencyInvalidRef as ManifestIssueCode,
276
+ severity: 'warning',
277
+ message: `Ref '${dep.ref}' for '${key}' may be invalid.`,
278
+ path: `${basePath}.ref`,
279
+ hint: `Use a tag (v1.0.0), branch name (main), or commit SHA.`
280
+ });
281
+ }
282
+
283
+ // Validate source format (should be owner/repo)
284
+ if (dep.source && !this.isValidSourceFormat(dep.source)) {
285
+ diagnostics.push({
286
+ code: ManifestIssueCodes.DependencyInvalidSource as ManifestIssueCode,
287
+ severity: 'error',
288
+ message: `Source '${dep.source}' is not valid owner/repo format.`,
289
+ path: `${basePath}.source`,
290
+ hint: `Use format 'owner/repo' like 'domainlang/core'.`
291
+ });
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Validates a path-based local dependency.
297
+ */
298
+ private validatePathDependency(
299
+ key: string,
300
+ dep: ExtendedDependencySpec,
301
+ basePath: string,
302
+ diagnostics: ManifestDiagnostic[]
303
+ ): void {
304
+ // Path dependencies should use relative paths
305
+ if (dep.path && this.isAbsolutePath(dep.path)) {
306
+ diagnostics.push({
307
+ code: IssueCodes.ImportAbsolutePath,
308
+ severity: 'error',
309
+ message: `Local path '${dep.path}' for '${key}' must be relative.`,
310
+ path: `${basePath}.path`,
311
+ hint: `Use a relative path like './packages/shared'.`
312
+ });
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Validates the paths section of the manifest.
318
+ */
319
+ private validatePathsSection(
320
+ manifest: ModelManifest,
321
+ diagnostics: ManifestDiagnostic[]
322
+ ): void {
323
+ const paths = manifest.paths;
324
+ if (!paths) {
325
+ return;
326
+ }
327
+
328
+ for (const [alias, targetPath] of Object.entries(paths)) {
329
+ // Path aliases should start with @
330
+ if (!alias.startsWith('@')) {
331
+ diagnostics.push({
332
+ code: ManifestIssueCodes.PathAliasMissingAtPrefix as ManifestIssueCode,
333
+ severity: 'warning',
334
+ message: `Path alias '${alias}' should start with '@'.`,
335
+ path: `paths.${alias}`,
336
+ hint: `Rename to '@${alias}' for consistency.`
337
+ });
338
+ }
339
+
340
+ // Target paths should be relative
341
+ if (this.isAbsolutePath(targetPath)) {
342
+ diagnostics.push({
343
+ code: ManifestIssueCodes.PathAliasAbsolutePath as ManifestIssueCode,
344
+ severity: 'error',
345
+ message: `Path alias '${alias}' cannot map to absolute path '${targetPath}'.`,
346
+ path: `paths.${alias}`,
347
+ hint: `Use a relative path like './src' or '.'`
348
+ });
349
+ }
350
+ }
351
+ }
352
+
353
+ // ========================================================================
354
+ // Helpers
355
+ // ========================================================================
356
+
357
+ /**
358
+ * Normalizes a dependency to extended form.
359
+ */
360
+ private normalizeDependency(key: string, dep: DependencySpec): ExtendedDependencySpec {
361
+ if (typeof dep === 'string') {
362
+ return { source: key, ref: dep };
363
+ }
364
+ if (dep.source || dep.path) {
365
+ return dep;
366
+ }
367
+ return { ...dep, source: key };
368
+ }
369
+
370
+ /**
371
+ * Checks if a version string is valid SemVer.
372
+ */
373
+ private isValidSemVer(version: string): boolean {
374
+ const semverRegex = /^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/;
375
+ return semverRegex.test(version);
376
+ }
377
+
378
+ /**
379
+ * Checks if a ref spec is valid (tag, branch, or commit SHA).
380
+ */
381
+ private isValidRefSpec(ref: string): boolean {
382
+ // SemVer with optional v prefix (tags)
383
+ if (/^v?\d+\.\d+\.\d+/.test(ref)) {
384
+ return true;
385
+ }
386
+ // Branch names (simple word chars)
387
+ if (/^[\w][\w.-]*$/.test(ref)) {
388
+ return true;
389
+ }
390
+ // Commit SHAs (40 hex chars)
391
+ if (/^[0-9a-f]{40}$/i.test(ref)) {
392
+ return true;
393
+ }
394
+ // Short commit SHAs (7+ hex chars)
395
+ if (/^[0-9a-f]{7,}$/i.test(ref)) {
396
+ return true;
397
+ }
398
+ return false;
399
+ }
400
+
401
+ /**
402
+ * Checks if source is valid owner/repo format.
403
+ */
404
+ private isValidSourceFormat(source: string): boolean {
405
+ return /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(source);
406
+ }
407
+
408
+ /**
409
+ * Checks if a path is absolute.
410
+ */
411
+ private isAbsolutePath(p: string): boolean {
412
+ return p.startsWith('/') || /^[A-Za-z]:/.test(p);
413
+ }
414
+ }
415
+
416
+ // ============================================================================
417
+ // Convenience Functions
418
+ // ============================================================================
419
+
420
+ /**
421
+ * Validates a manifest and returns true if valid, false otherwise.
422
+ * Use this for simple pass/fail checks.
423
+ */
424
+ export function isManifestValid(manifest: ModelManifest): boolean {
425
+ const validator = new ManifestValidator();
426
+ return validator.validate(manifest).valid;
427
+ }
428
+
429
+ /**
430
+ * Validates a manifest and returns all diagnostics.
431
+ * Use this to display validation errors to users.
432
+ */
433
+ export function validateManifest(
434
+ manifest: ModelManifest,
435
+ options?: { requirePublishable?: boolean }
436
+ ): ManifestDiagnostic[] {
437
+ const validator = new ManifestValidator();
438
+ return validator.validate(manifest, options).diagnostics;
439
+ }
@@ -0,0 +1,76 @@
1
+ import type { ValidationAcceptor } from 'langium';
2
+ import type { ContextMap, DomainMap } from '../generated/ast.js';
3
+ import { ValidationMessages, buildCodeDescription } from './constants.js';
4
+
5
+ /**
6
+ * Validates that a context map contains at least one bounded context.
7
+ * Empty context maps are not useful for documentation purposes.
8
+ *
9
+ * @param map - The context map to validate
10
+ * @param accept - The validation acceptor for reporting issues
11
+ */
12
+ function validateContextMapHasContexts(
13
+ map: ContextMap,
14
+ accept: ValidationAcceptor
15
+ ): void {
16
+ if (!map.boundedContexts || map.boundedContexts.length === 0) {
17
+ accept('warning', ValidationMessages.CONTEXT_MAP_NO_CONTEXTS(map.name), {
18
+ node: map,
19
+ keyword: 'contains',
20
+ codeDescription: buildCodeDescription('language.md', 'context-maps')
21
+ });
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Validates that a context map has at least one relationship if it contains multiple contexts.
27
+ * Multiple unrelated contexts should have documented relationships.
28
+ *
29
+ * @param map - The context map to validate
30
+ * @param accept - The validation acceptor for reporting issues
31
+ */
32
+ function validateContextMapHasRelationships(
33
+ map: ContextMap,
34
+ accept: ValidationAcceptor
35
+ ): void {
36
+ const contextCount = map.boundedContexts?.length ?? 0;
37
+ const relationshipCount = map.relationships?.length ?? 0;
38
+
39
+ // Only warn if multiple contexts exist without relationships
40
+ if (contextCount > 1 && relationshipCount === 0) {
41
+ accept('info', ValidationMessages.CONTEXT_MAP_NO_RELATIONSHIPS(map.name, contextCount), {
42
+ node: map,
43
+ keyword: 'ContextMap',
44
+ codeDescription: buildCodeDescription('language.md', 'context-maps')
45
+ });
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Validates that a domain map contains at least one domain.
51
+ * Empty domain maps are not useful for documentation purposes.
52
+ *
53
+ * @param map - The domain map to validate
54
+ * @param accept - The validation acceptor for reporting issues
55
+ */
56
+ function validateDomainMapHasDomains(
57
+ map: DomainMap,
58
+ accept: ValidationAcceptor
59
+ ): void {
60
+ if (!map.domains || map.domains.length === 0) {
61
+ accept('warning', ValidationMessages.DOMAIN_MAP_NO_DOMAINS(map.name), {
62
+ node: map,
63
+ keyword: 'contains',
64
+ codeDescription: buildCodeDescription('language.md', 'domain-maps')
65
+ });
66
+ }
67
+ }
68
+
69
+ export const contextMapChecks = [
70
+ validateContextMapHasContexts,
71
+ validateContextMapHasRelationships
72
+ ];
73
+
74
+ export const domainMapChecks = [
75
+ validateDomainMapHasDomains
76
+ ];
@@ -0,0 +1,18 @@
1
+ import type { ValidationChecks } from 'langium';
2
+ import type { Metadata, DomainLangAstType } from '../generated/ast.js';
3
+ import { ValidationMessages, buildCodeDescription } from './constants.js';
4
+
5
+ /**
6
+ * Validation checks for Metadata elements.
7
+ * - Ensures metadata keys are defined before use
8
+ */
9
+ export const metadataChecks: ValidationChecks<DomainLangAstType> = {
10
+ Metadata(metadata: Metadata, accept) {
11
+ if (!metadata.name) {
12
+ accept('error', ValidationMessages.METADATA_MISSING_NAME(), {
13
+ node: metadata,
14
+ codeDescription: buildCodeDescription('language.md', 'metadata')
15
+ });
16
+ }
17
+ },
18
+ };
@@ -0,0 +1,37 @@
1
+ import { setInferredRelationshipTypes } from '../services/relationship-inference.js';
2
+ import { extractNames } from './shared.js';
3
+ import type { ValidationAcceptor } from 'langium';
4
+ import type { Model } from '../generated/ast.js';
5
+ import { ValidationMessages, buildCodeDescription } from './constants.js';
6
+
7
+ /**
8
+ * Validates that all elements in the model have unique fully qualified names.
9
+ * Also triggers relationship type inference.
10
+ *
11
+ * @param model - The model to validate
12
+ * @param accept - The validation acceptor for reporting issues
13
+ */
14
+ function validateModelUniqueNames(
15
+ model: Model,
16
+ accept: ValidationAcceptor
17
+ ): void {
18
+ const uniqueNames = new Set<string>();
19
+ const names = extractNames(model);
20
+
21
+ for (const {fqn, node} of names) {
22
+ const oldSize = uniqueNames.size;
23
+ uniqueNames.add(fqn);
24
+ if (uniqueNames.size === oldSize) {
25
+ accept('error', ValidationMessages.DUPLICATE_ELEMENT(fqn), {
26
+ node: node,
27
+ property: 'name',
28
+ codeDescription: buildCodeDescription('language.md', 'naming')
29
+ });
30
+ }
31
+ }
32
+
33
+ // Enrich relationships with inferred types
34
+ setInferredRelationshipTypes(model);
35
+ }
36
+
37
+ export const modelChecks = [validateModelUniqueNames];