@lionweb/validation 0.5.0 → 0.6.0-beta.2

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 (177) hide show
  1. package/README.md +2 -0
  2. package/dist/diff/DiffResult.d.ts +9 -0
  3. package/dist/diff/DiffResult.d.ts.map +1 -0
  4. package/dist/diff/DiffResult.js +18 -0
  5. package/dist/diff/DiffResult.js.map +1 -0
  6. package/dist/diff/LionWebJsonDiff.d.ts +25 -0
  7. package/dist/diff/LionWebJsonDiff.d.ts.map +1 -0
  8. package/dist/diff/LionWebJsonDiff.js +205 -0
  9. package/dist/diff/LionWebJsonDiff.js.map +1 -0
  10. package/dist/diff/changes/Change.d.ts +16 -0
  11. package/dist/diff/changes/Change.d.ts.map +1 -0
  12. package/dist/diff/changes/Change.js +19 -0
  13. package/dist/diff/changes/Change.js.map +1 -0
  14. package/dist/diff/changes/ChunkChange.d.ts +43 -0
  15. package/dist/diff/changes/ChunkChange.d.ts.map +1 -0
  16. package/dist/diff/changes/ChunkChange.js +57 -0
  17. package/dist/diff/changes/ChunkChange.js.map +1 -0
  18. package/dist/diff/changes/ContainmentChange.d.ts +26 -0
  19. package/dist/diff/changes/ContainmentChange.d.ts.map +1 -0
  20. package/dist/diff/changes/ContainmentChange.js +34 -0
  21. package/dist/diff/changes/ContainmentChange.js.map +1 -0
  22. package/dist/diff/changes/NodeChange.d.ts +22 -0
  23. package/dist/diff/changes/NodeChange.d.ts.map +1 -0
  24. package/dist/diff/changes/NodeChange.js +24 -0
  25. package/dist/diff/changes/NodeChange.js.map +1 -0
  26. package/dist/diff/changes/PropertyChange.d.ts +23 -0
  27. package/dist/diff/changes/PropertyChange.d.ts.map +1 -0
  28. package/dist/diff/changes/PropertyChange.js +28 -0
  29. package/dist/diff/changes/PropertyChange.js.map +1 -0
  30. package/dist/diff/changes/ReferenceChange.d.ts +19 -0
  31. package/dist/diff/changes/ReferenceChange.d.ts.map +1 -0
  32. package/dist/diff/changes/ReferenceChange.js +25 -0
  33. package/dist/diff/changes/ReferenceChange.js.map +1 -0
  34. package/dist/diff/changes/index.d.ts +7 -0
  35. package/dist/diff/changes/index.d.ts.map +1 -0
  36. package/dist/diff/changes/index.js +7 -0
  37. package/dist/diff/changes/index.js.map +1 -0
  38. package/dist/diff/index.d.ts +4 -0
  39. package/dist/diff/index.d.ts.map +1 -0
  40. package/dist/diff/index.js +4 -0
  41. package/dist/diff/index.js.map +1 -0
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +1 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/issues/LanguageIssues.d.ts +1 -1
  47. package/dist/issues/LanguageIssues.d.ts.map +1 -1
  48. package/dist/issues/LanguageIssues.js.map +1 -1
  49. package/dist/issues/ReferenceIssues.d.ts +1 -1
  50. package/dist/issues/ReferenceIssues.d.ts.map +1 -1
  51. package/dist/issues/ReferenceIssues.js.map +1 -1
  52. package/dist/issues/SyntaxIssues.d.ts +1 -1
  53. package/dist/issues/SyntaxIssues.d.ts.map +1 -1
  54. package/dist/issues/SyntaxIssues.js +4 -4
  55. package/dist/issues/SyntaxIssues.js.map +1 -1
  56. package/dist/issues/ValidationIssue.d.ts +1 -1
  57. package/dist/issues/ValidationIssue.d.ts.map +1 -1
  58. package/dist/issues/ValidationIssue.js.map +1 -1
  59. package/dist/issues/index.d.ts +1 -1
  60. package/dist/issues/index.d.ts.map +1 -1
  61. package/dist/issues/index.js +1 -1
  62. package/dist/issues/index.js.map +1 -1
  63. package/dist/json/ChunkUtils.d.ts.map +1 -1
  64. package/dist/json/ChunkUtils.js.map +1 -1
  65. package/dist/json/JsonContext.d.ts.map +1 -0
  66. package/dist/json/JsonContext.js.map +1 -0
  67. package/dist/json/LanguageUtils.d.ts.map +1 -1
  68. package/dist/json/LanguageUtils.js.map +1 -1
  69. package/dist/json/LionWebJson.d.ts +10 -9
  70. package/dist/json/LionWebJson.d.ts.map +1 -1
  71. package/dist/json/LionWebJson.js +1 -0
  72. package/dist/json/LionWebJson.js.map +1 -1
  73. package/dist/json/LionWebJsonChunkWrapper.d.ts +7 -4
  74. package/dist/json/LionWebJsonChunkWrapper.d.ts.map +1 -1
  75. package/dist/json/LionWebJsonChunkWrapper.js +48 -10
  76. package/dist/json/LionWebJsonChunkWrapper.js.map +1 -1
  77. package/dist/json/LionWebLanguageDefinition.d.ts.map +1 -1
  78. package/dist/json/LionWebLanguageDefinition.js +3 -3
  79. package/dist/json/LionWebLanguageDefinition.js.map +1 -1
  80. package/dist/json/NodeUtils.d.ts +5 -4
  81. package/dist/json/NodeUtils.d.ts.map +1 -1
  82. package/dist/json/NodeUtils.js +5 -2
  83. package/dist/json/NodeUtils.js.map +1 -1
  84. package/dist/json/index.d.ts +1 -0
  85. package/dist/json/index.d.ts.map +1 -1
  86. package/dist/json/index.js +1 -0
  87. package/dist/json/index.js.map +1 -1
  88. package/dist/runners/FileUtils.d.ts.map +1 -1
  89. package/dist/runners/FileUtils.js.map +1 -1
  90. package/dist/runners/RunCheckFolder.js.map +1 -1
  91. package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -1
  92. package/dist/runners/RunCheckOneFile.js.map +1 -1
  93. package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -1
  94. package/dist/runners/RunLioncoreDiff.js +5 -5
  95. package/dist/runners/RunLioncoreDiff.js.map +1 -1
  96. package/dist/runners/Utils.d.ts.map +1 -1
  97. package/dist/runners/Utils.js +1 -1
  98. package/dist/runners/Utils.js.map +1 -1
  99. package/dist/runners/index.d.ts.map +1 -1
  100. package/dist/runners/index.js.map +1 -1
  101. package/dist/validators/LionWebLanguageReferenceValidator.d.ts +1 -1
  102. package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -1
  103. package/dist/validators/LionWebLanguageReferenceValidator.js +6 -6
  104. package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -1
  105. package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -1
  106. package/dist/validators/LionWebLanguageValidator.js +1 -1
  107. package/dist/validators/LionWebLanguageValidator.js.map +1 -1
  108. package/dist/validators/LionWebReferenceValidator.d.ts +1 -1
  109. package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
  110. package/dist/validators/LionWebReferenceValidator.js +6 -6
  111. package/dist/validators/LionWebReferenceValidator.js.map +1 -1
  112. package/dist/validators/LionWebSyntaxValidator.d.ts +1 -1
  113. package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -1
  114. package/dist/validators/LionWebSyntaxValidator.js +21 -11
  115. package/dist/validators/LionWebSyntaxValidator.js.map +1 -1
  116. package/dist/validators/LionWebValidator.d.ts.map +1 -1
  117. package/dist/validators/LionWebValidator.js.map +1 -1
  118. package/dist/validators/SimpleFieldValidator.d.ts +1 -1
  119. package/dist/validators/SimpleFieldValidator.d.ts.map +1 -1
  120. package/dist/validators/SimpleFieldValidator.js +1 -1
  121. package/dist/validators/SimpleFieldValidator.js.map +1 -1
  122. package/dist/validators/ValidationResult.d.ts.map +1 -1
  123. package/dist/validators/ValidationResult.js.map +1 -1
  124. package/dist/validators/index.d.ts.map +1 -1
  125. package/dist/validators/index.js.map +1 -1
  126. package/package.json +5 -2
  127. package/src/diff/DiffResult.ts +21 -0
  128. package/src/diff/LionWebJsonDiff.ts +259 -0
  129. package/src/diff/changes/Change.ts +52 -0
  130. package/src/diff/changes/ChunkChange.ts +68 -0
  131. package/src/diff/changes/ContainmentChange.ts +34 -0
  132. package/src/diff/changes/NodeChange.ts +32 -0
  133. package/src/diff/changes/PropertyChange.ts +29 -0
  134. package/src/diff/changes/ReferenceChange.ts +24 -0
  135. package/src/diff/changes/index.ts +6 -0
  136. package/src/diff/index.ts +3 -0
  137. package/src/index.ts +5 -4
  138. package/src/issues/LanguageIssues.ts +61 -39
  139. package/src/issues/ReferenceIssues.ts +51 -29
  140. package/src/issues/SyntaxIssues.ts +38 -23
  141. package/src/issues/ValidationIssue.ts +7 -7
  142. package/src/issues/index.ts +5 -5
  143. package/src/json/ChunkUtils.ts +7 -11
  144. package/src/json/JsonContext.ts +31 -0
  145. package/src/json/LanguageUtils.ts +5 -6
  146. package/src/json/LionWebJson.ts +44 -43
  147. package/src/json/LionWebJsonChunkWrapper.ts +76 -29
  148. package/src/json/LionWebLanguageDefinition.ts +44 -49
  149. package/src/json/NodeUtils.ts +25 -19
  150. package/src/json/index.ts +7 -6
  151. package/src/json/std-builtins-copy.json +347 -349
  152. package/src/runners/FileUtils.ts +48 -49
  153. package/src/runners/RunCheckFolder.ts +3 -3
  154. package/src/runners/RunCheckFolderWithLanguage.ts +31 -30
  155. package/src/runners/RunCheckOneFile.ts +3 -3
  156. package/src/runners/RunCheckOneFileWithLanguage.ts +21 -19
  157. package/src/runners/RunLioncoreDiff.ts +15 -15
  158. package/src/runners/Utils.ts +24 -24
  159. package/src/runners/index.ts +2 -2
  160. package/src/validators/LionWebLanguageReferenceValidator.ts +63 -55
  161. package/src/validators/LionWebLanguageValidator.ts +11 -12
  162. package/src/validators/LionWebReferenceValidator.ts +90 -76
  163. package/src/validators/LionWebSyntaxValidator.ts +108 -99
  164. package/src/validators/LionWebValidator.ts +33 -33
  165. package/src/validators/SimpleFieldValidator.ts +33 -28
  166. package/src/validators/ValidationResult.ts +5 -6
  167. package/src/validators/index.ts +7 -7
  168. package/dist/diff/LionwebDiff.d.ts +0 -40
  169. package/dist/diff/LionwebDiff.d.ts.map +0 -1
  170. package/dist/diff/LionwebDiff.js +0 -158
  171. package/dist/diff/LionwebDiff.js.map +0 -1
  172. package/dist/issues/JsonContext.d.ts.map +0 -1
  173. package/dist/issues/JsonContext.js.map +0 -1
  174. package/src/diff/LionwebDiff.ts +0 -193
  175. package/src/issues/JsonContext.ts +0 -31
  176. /package/dist/{issues → json}/JsonContext.d.ts +0 -0
  177. /package/dist/{issues → json}/JsonContext.js +0 -0
@@ -1,87 +1,86 @@
1
- import fs from "fs";
2
- import { LionWebJsonChunkWrapper, LionWebLanguageDefinition } from "../json/index.js";
3
- import { LionWebValidator } from "../validators/LionWebValidator.js";
4
- import { ValidationResult } from "../validators/ValidationResult.js";
5
- import { getFilesRecursive, printIssues } from "./Utils.js";
1
+ import fs from "fs"
2
+ import { LionWebJsonChunkWrapper, LionWebLanguageDefinition } from "../json/index.js"
3
+ import { LionWebValidator } from "../validators/LionWebValidator.js"
4
+ import { ValidationResult } from "../validators/ValidationResult.js"
5
+ import { getFilesRecursive, printIssues } from "./Utils.js"
6
6
 
7
7
  export function validateFile(file: string): void {
8
- const result = validateFileResult(file);
9
- printIssues(result);
8
+ const result = validateFileResult(file)
9
+ printIssues(result)
10
10
  }
11
11
 
12
12
  export function validateFileResult(file: string): ValidationResult {
13
13
  if (file !== null) {
14
- const jsonString1 = fs.readFileSync(file, "utf-8");
15
- const json1 = JSON.parse(jsonString1);
16
- const validator = new LionWebValidator(json1, null);
14
+ const jsonString1 = fs.readFileSync(file, "utf-8")
15
+ const json1 = JSON.parse(jsonString1)
16
+ const validator = new LionWebValidator(json1, null)
17
17
 
18
- validator.validateSyntax();
19
- validator.validateReferences();
20
- validator.validateForLanguage();
21
- return validator.validationResult;
18
+ validator.validateSyntax()
19
+ validator.validateReferences()
20
+ validator.validateForLanguage()
21
+ return validator.validationResult
22
22
  }
23
- return new ValidationResult();
23
+ return new ValidationResult()
24
24
  }
25
25
 
26
26
  export function validateFileResultWithLanguage(file: string, languageFile?: string | null): ValidationResult {
27
- let langDef: LionWebLanguageDefinition | null = null;
28
-
27
+ let langDef: LionWebLanguageDefinition | null = null
28
+
29
29
  if (languageFile !== undefined && languageFile !== null) {
30
- const jsonString1 = fs.readFileSync(file, "utf-8");
31
- const languageJson = JSON.parse(jsonString1);
32
- const validator = new LionWebValidator(languageJson, null);
30
+ const jsonString1 = fs.readFileSync(file, "utf-8")
31
+ const languageJson = JSON.parse(jsonString1)
32
+ const validator = new LionWebValidator(languageJson, null)
33
33
 
34
- validator.validateSyntax();
35
- validator.validateReferences();
36
- validator.validateForLanguage();
34
+ validator.validateSyntax()
35
+ validator.validateReferences()
36
+ validator.validateForLanguage()
37
37
  if (validator.validationResult.hasErrors()) {
38
- return validator.validationResult;
38
+ return validator.validationResult
39
39
  }
40
- langDef = new LionWebLanguageDefinition(new LionWebJsonChunkWrapper(languageJson));
40
+ langDef = new LionWebLanguageDefinition(new LionWebJsonChunkWrapper(languageJson))
41
41
  }
42
42
 
43
43
  if (file !== null) {
44
- const fileString = fs.readFileSync(file, "utf-8");
45
- const fileJson = JSON.parse(fileString);
46
- const validator = new LionWebValidator(fileJson, langDef);
47
- validator.validateSyntax();
48
- validator.validateReferences();
49
- validator.validateForLanguage();
50
- return validator.validationResult;
44
+ const fileString = fs.readFileSync(file, "utf-8")
45
+ const fileJson = JSON.parse(fileString)
46
+ const validator = new LionWebValidator(fileJson, langDef)
47
+ validator.validateSyntax()
48
+ validator.validateReferences()
49
+ validator.validateForLanguage()
50
+ return validator.validationResult
51
51
  }
52
- return new ValidationResult();
52
+ return new ValidationResult()
53
53
  }
54
54
 
55
55
  export function validateFolder(folder: string): void {
56
- let totalErrors = 0;
57
- let totalSucceed = 0;
58
- let totalFailed = 0;
59
-
56
+ let totalErrors = 0
57
+ let totalSucceed = 0
58
+ let totalFailed = 0
60
59
 
61
60
  for (const f of getFilesRecursive(folder, [])) {
62
- const jsonString1 = fs.readFileSync(f, "utf-8");
63
- const json1 = JSON.parse(jsonString1);
61
+ const jsonString1 = fs.readFileSync(f, "utf-8")
62
+ const json1 = JSON.parse(jsonString1)
64
63
  const validator = new LionWebValidator(json1, null)
65
64
 
66
65
  try {
67
- validator.validateAll();
66
+ validator.validateAll()
68
67
 
69
68
  if (!validator.validationResult.hasErrors()) {
70
- totalSucceed += 1;
71
- console.log("V PASSED " + f);
69
+ totalSucceed += 1
70
+ console.log("V PASSED " + f)
72
71
  printIssues(validator.validationResult, f)
73
72
  } else {
74
73
  printIssues(validator.validationResult, f)
75
- totalFailed += 1;
76
- totalErrors += validator.validationResult.issues.length;
74
+ totalFailed += 1
75
+ totalErrors += validator.validationResult.issues.length
77
76
  }
78
77
  } catch (e: unknown) {
79
- console.log("EXCEPTION in file: " + f);
80
- console.log("EXCEPTION " + (e as Error)?.stack);
78
+ console.log("EXCEPTION in file: " + f)
79
+ console.log("EXCEPTION " + (e as Error)?.stack)
81
80
  }
82
81
  }
83
82
 
84
- console.log("Total without errors: " + totalSucceed);
85
- console.log("Total with errors: " + totalFailed);
86
- console.log("Total number of errors: " + totalErrors);
83
+ console.log("Total without errors: " + totalSucceed)
84
+ console.log("Total with errors: " + totalFailed)
85
+ console.log("Total number of errors: " + totalErrors)
87
86
  }
@@ -1,5 +1,5 @@
1
- import { validateFolder } from "./FileUtils.js";
1
+ import { validateFolder } from "./FileUtils.js"
2
2
 
3
- const folder = process.argv[2];
3
+ const folder = process.argv[2]
4
4
 
5
- validateFolder(folder);
5
+ validateFolder(folder)
@@ -1,44 +1,45 @@
1
- import fs from "fs";
2
- import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js";
3
- import { LionWebLanguageDefinition} from "../json/LionWebLanguageDefinition.js";
4
- import { LionWebValidator } from "../validators/LionWebValidator.js";
5
- import { getFilesRecursive, printIssues } from "./Utils.js";
1
+ import fs from "fs"
2
+ import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js"
3
+ import { LionWebLanguageDefinition } from "../json/LionWebLanguageDefinition.js"
4
+ import { LionWebValidator } from "../validators/LionWebValidator.js"
5
+ import { getFilesRecursive, printIssues } from "./Utils.js"
6
6
 
7
- const folder = process.argv[2];
8
- const language = process.argv[3];
7
+ const folder = process.argv[2]
8
+ const language = process.argv[3]
9
9
 
10
- let totalSucceed = 0;
11
- let totalFailed = 0;
10
+ let totalSucceed = 0
11
+ let totalFailed = 0
12
12
 
13
+ const languageString = fs.readFileSync(language, "utf-8")
14
+ const languageJson = JSON.parse(languageString)
15
+ const languageValidator = new LionWebValidator(languageJson, null)
13
16
 
14
- const languageString = fs.readFileSync(language, "utf-8");
15
- const languageJson = JSON.parse(languageString);
16
- const languageValidator = new LionWebValidator(languageJson, null);
17
-
18
- languageValidator.validateSyntax();
19
- languageValidator.validateReferences();
17
+ languageValidator.validateSyntax()
18
+ languageValidator.validateReferences()
20
19
  if (languageValidator.validationResult.hasErrors()) {
21
- console.log("===== Language errors, ignoring folder ======");
22
- printIssues(languageValidator.validationResult);
23
- process.exit(1);
20
+ console.log("===== Language errors, ignoring folder ======")
21
+ printIssues(languageValidator.validationResult)
22
+ process.exit(1)
24
23
  }
25
24
 
26
25
  for (const modelFile of getFilesRecursive(folder, [])) {
27
- const jsonString1 = fs.readFileSync(modelFile, "utf-8");
28
- const jsonModel = JSON.parse(jsonString1);
29
- const modelValidator = new LionWebValidator(jsonModel, new LionWebLanguageDefinition(languageValidator.chunk as LionWebJsonChunkWrapper));
30
-
31
- modelValidator.validateAll();
26
+ const jsonString1 = fs.readFileSync(modelFile, "utf-8")
27
+ const jsonModel = JSON.parse(jsonString1)
28
+ const modelValidator = new LionWebValidator(
29
+ jsonModel,
30
+ new LionWebLanguageDefinition(languageValidator.chunk as LionWebJsonChunkWrapper),
31
+ )
32
+
33
+ modelValidator.validateAll()
32
34
  if (modelValidator.validationResult.hasErrors()) {
33
- totalFailed++;
35
+ totalFailed++
34
36
  // console.log("FAILED: " + modelFile)
35
- printIssues(modelValidator.validationResult, modelFile);
37
+ printIssues(modelValidator.validationResult, modelFile)
36
38
  } else {
37
- console.log("SUCCEEDED: " + modelFile);
38
- totalSucceed++;
39
+ console.log("SUCCEEDED: " + modelFile)
40
+ totalSucceed++
39
41
  }
40
42
  }
41
43
 
42
- console.log("Total without errors: " + totalSucceed);
43
- console.log("Total with errors: " + totalFailed);
44
-
44
+ console.log("Total without errors: " + totalSucceed)
45
+ console.log("Total with errors: " + totalFailed)
@@ -1,5 +1,5 @@
1
- import { validateFile } from "./FileUtils.js";
1
+ import { validateFile } from "./FileUtils.js"
2
2
 
3
- const file1 = process.argv[2];
3
+ const file1 = process.argv[2]
4
4
 
5
- validateFile(file1);
5
+ validateFile(file1)
@@ -1,28 +1,30 @@
1
- import fs from "fs";
2
- import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js";
3
- import { LionWebLanguageDefinition} from "../json/LionWebLanguageDefinition.js";
4
- import { LionWebValidator } from "../validators/LionWebValidator.js";
5
- import { printIssues } from "./Utils.js";
1
+ import fs from "fs"
2
+ import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js"
3
+ import { LionWebLanguageDefinition } from "../json/LionWebLanguageDefinition.js"
4
+ import { LionWebValidator } from "../validators/LionWebValidator.js"
5
+ import { printIssues } from "./Utils.js"
6
6
 
7
-
8
- const modelFile = process.argv[2];
9
- const language = process.argv[3];
7
+ const modelFile = process.argv[2]
8
+ const language = process.argv[3]
10
9
 
11
10
  if (modelFile !== null) {
12
- const jsonString1 = fs.readFileSync(modelFile, "utf-8");
13
- const jsonModel = JSON.parse(jsonString1);
14
- const languageString = fs.readFileSync(language, "utf-8");
15
- const languageJson = JSON.parse(languageString);
11
+ const jsonString1 = fs.readFileSync(modelFile, "utf-8")
12
+ const jsonModel = JSON.parse(jsonString1)
13
+ const languageString = fs.readFileSync(language, "utf-8")
14
+ const languageJson = JSON.parse(languageString)
16
15
 
17
- const languageValidator = new LionWebValidator(languageJson, null);
16
+ const languageValidator = new LionWebValidator(languageJson, null)
18
17
 
19
- languageValidator.validateSyntax();
20
- languageValidator.validateReferences();
18
+ languageValidator.validateSyntax()
19
+ languageValidator.validateReferences()
21
20
  console.log("===== Language errors ======")
22
- printIssues(languageValidator.validationResult);
21
+ printIssues(languageValidator.validationResult)
23
22
 
24
- const modelValidator = new LionWebValidator(jsonModel, new LionWebLanguageDefinition(languageValidator.chunk as LionWebJsonChunkWrapper));
25
- modelValidator.validateAll();
23
+ const modelValidator = new LionWebValidator(
24
+ jsonModel,
25
+ new LionWebLanguageDefinition(languageValidator.chunk as LionWebJsonChunkWrapper),
26
+ )
27
+ modelValidator.validateAll()
26
28
  console.log("===== Model errors ======")
27
- printIssues(modelValidator.validationResult);
29
+ printIssues(modelValidator.validationResult)
28
30
  }
@@ -1,23 +1,23 @@
1
- import fs from "fs";
2
- import { LwDiff } from "../diff/LionwebDiff.js";
3
- import { LionWebJsonChunk } from "../json/LionWebJson.js";
1
+ import fs from "fs"
2
+ import { LionWebJsonDiff } from "../diff/index.js"
3
+ import { LionWebJsonChunk } from "../json/LionWebJson.js"
4
4
 
5
- const file1 = process.argv[2];
6
- const file2 = process.argv[3];
5
+ const file1 = process.argv[2]
6
+ const file2 = process.argv[3]
7
7
 
8
8
  if (file1 !== null && file1 !== undefined) {
9
- const jsonString1 = fs.readFileSync(file1, "utf-8");
10
- const json1 = JSON.parse(jsonString1);
11
- const jsonString2 = fs.readFileSync(file2, "utf-8");
12
- const json2 = JSON.parse(jsonString2);
9
+ const jsonString1 = fs.readFileSync(file1, "utf-8")
10
+ const json1 = JSON.parse(jsonString1)
11
+ const jsonString2 = fs.readFileSync(file2, "utf-8")
12
+ const json2 = JSON.parse(jsonString2)
13
13
 
14
- const lwDiff = new LwDiff();
15
- lwDiff.diffLwChunk(json1 as LionWebJsonChunk, json2 as LionWebJsonChunk);
16
- if (lwDiff.errors.length === 0) {
17
- console.log("LwDiff: equal");
14
+ const lwDiff = new LionWebJsonDiff()
15
+ lwDiff.diffLwChunk(json1 as LionWebJsonChunk, json2 as LionWebJsonChunk)
16
+ if (lwDiff.diffResult.changes.length === 0) {
17
+ console.log("LionWebJsonDiff: equal")
18
18
  } else {
19
- console.log("LwDiff: " + lwDiff.errors);
19
+ console.log("LionWebJsonDiff: " + lwDiff.diff)
20
20
  }
21
21
  } else {
22
- console.log("Error in arguments");
22
+ console.log("Error in arguments")
23
23
  }
@@ -1,55 +1,55 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { ValidationResult } from "../validators/ValidationResult.js";
1
+ import fs from "fs"
2
+ import path from "path"
3
+ import { ValidationResult } from "../validators/ValidationResult.js"
4
4
 
5
5
  export function getFilesRecursive(dirPath: string, arrayOfFiles: string[]) {
6
- const files = fs.readdirSync(dirPath);
7
- arrayOfFiles = arrayOfFiles || [];
6
+ const files = fs.readdirSync(dirPath)
7
+ arrayOfFiles = arrayOfFiles || []
8
8
 
9
9
  files.forEach(function (file: string) {
10
10
  if (fs.statSync(dirPath + "/" + file).isDirectory()) {
11
- arrayOfFiles = getFilesRecursive(dirPath + "/" + file, arrayOfFiles);
11
+ arrayOfFiles = getFilesRecursive(dirPath + "/" + file, arrayOfFiles)
12
12
  // arrayOfFiles.push(path.join(dirPath, "/", file));
13
13
  } else {
14
- arrayOfFiles.push(path.join(dirPath, "/", file));
14
+ arrayOfFiles.push(path.join(dirPath, "/", file))
15
15
  }
16
- });
17
- return arrayOfFiles;
16
+ })
17
+ return arrayOfFiles
18
18
  }
19
19
 
20
20
  export function getFilesDirect(dirPath: string, arrayOfFiles: string[]) {
21
- const files = fs.readdirSync(dirPath);
22
- arrayOfFiles = arrayOfFiles || [];
21
+ const files = fs.readdirSync(dirPath)
22
+ arrayOfFiles = arrayOfFiles || []
23
23
 
24
24
  files.forEach(function (file: string) {
25
25
  if (fs.statSync(dirPath + "/" + file).isFile()) {
26
- arrayOfFiles.push(file);
26
+ arrayOfFiles.push(file)
27
27
  }
28
- });
29
- return arrayOfFiles;
28
+ })
29
+ return arrayOfFiles
30
30
  }
31
31
 
32
32
  export function getAllDirectories(dirPath: string, arrayOfDirs: string[]) {
33
- const files = fs.readdirSync(dirPath, {withFileTypes: true});
34
- arrayOfDirs = arrayOfDirs || [];
33
+ const files = fs.readdirSync(dirPath, { withFileTypes: true })
34
+ arrayOfDirs = arrayOfDirs || []
35
35
 
36
36
  files.forEach(function (file: fs.Dirent) {
37
37
  if (file.isDirectory()) {
38
- arrayOfDirs = getAllDirectories(dirPath + "/" + file.name, arrayOfDirs);
39
- arrayOfDirs.push(path.join(dirPath, "/", file.name));
38
+ arrayOfDirs = getAllDirectories(dirPath + "/" + file.name, arrayOfDirs)
39
+ arrayOfDirs.push(path.join(dirPath, "/", file.name))
40
40
  } else {
41
41
  // ignore files
42
42
  }
43
- });
44
- return arrayOfDirs;
43
+ })
44
+ return arrayOfDirs
45
45
  }
46
46
 
47
47
  export function printIssues(result: ValidationResult, file?: string): void {
48
- result.issues.forEach(issue => console.log((file == undefined ? "" : `File ${file}: `) + issue.errorMsg()));
48
+ result.issues.forEach(issue => console.log((file == undefined ? "" : `File ${file}: `) + issue.errorMsg()))
49
49
  }
50
50
 
51
51
  export function issuestoString(vresult: ValidationResult, file?: string): string {
52
- let result = "";
53
- vresult.issues.forEach(issue => result += (file == undefined ? "" : `File ${file}: `) + issue.errorMsg() + "\n");
54
- return result;
52
+ let result = ""
53
+ vresult.issues.forEach(issue => (result += (file == undefined ? "" : `File ${file}: `) + issue.errorMsg() + "\n"))
54
+ return result
55
55
  }
@@ -1,2 +1,2 @@
1
- export * from "./FileUtils.js";
2
- export * from "./Utils.js";
1
+ export * from "./FileUtils.js"
2
+ export * from "./Utils.js"
@@ -1,37 +1,45 @@
1
1
  import {
2
2
  Language_IncorrectContainmentMetaPointer_Issue,
3
- Language_IncorrectPropertyMetaPointer_Issue, Language_IncorrectReferenceMetaPointer_Issue,
3
+ Language_IncorrectPropertyMetaPointer_Issue,
4
+ Language_IncorrectReferenceMetaPointer_Issue,
4
5
  Language_UnknownConcept_Issue,
5
6
  Language_UnknownContainment_Issue,
6
7
  Language_UnknownProperty_Issue,
7
- Language_UnknownReference_Issue
8
- } from "../issues/LanguageIssues.js";
9
- import { JsonContext } from "./../issues/JsonContext.js";
8
+ Language_UnknownReference_Issue,
9
+ } from "../issues/LanguageIssues.js"
10
+ import { JsonContext } from "../json/JsonContext.js"
10
11
  import {
11
12
  LION_CORE_BUILTINS_INAMED_NAME,
12
13
  LIONWEB_BOOLEAN_TYPE,
13
14
  LIONWEB_INTEGER_TYPE,
14
15
  LIONWEB_JSON_TYPE,
15
- LIONWEB_STRING_TYPE, LionWebJsonChild,
16
- LionWebJsonProperty, LionWebJsonReference
17
- } from "../json/LionWebJson.js";
18
- import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js";
19
- import { LIONWEB_M3_CONCEPT_KEY, LIONWEB_M3_PROPERTY_KEY, LIONWEB_M3_PROPERTY_TYPE_KEY, LionWebLanguageDefinition } from "../json/LionWebLanguageDefinition.js";
20
- import { SimpleFieldValidator } from "./SimpleFieldValidator.js";
21
- import { ValidationResult } from "./ValidationResult.js";
16
+ LIONWEB_STRING_TYPE,
17
+ LionWebJsonContainment,
18
+ LionWebJsonProperty,
19
+ LionWebJsonReference,
20
+ } from "../json/LionWebJson.js"
21
+ import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js"
22
+ import {
23
+ LIONWEB_M3_CONCEPT_KEY,
24
+ LIONWEB_M3_PROPERTY_KEY,
25
+ LIONWEB_M3_PROPERTY_TYPE_KEY,
26
+ LionWebLanguageDefinition,
27
+ } from "../json/LionWebLanguageDefinition.js"
28
+ import { SimpleFieldValidator } from "./SimpleFieldValidator.js"
29
+ import { ValidationResult } from "./ValidationResult.js"
22
30
 
23
31
  /**
24
32
  * Check against the language definition
25
33
  */
26
34
  export class LionWebLanguageReferenceValidator {
27
- validationResult: ValidationResult;
28
- language: LionWebLanguageDefinition;
29
- simpleFieldValidator: SimpleFieldValidator;
35
+ validationResult: ValidationResult
36
+ language: LionWebLanguageDefinition
37
+ simpleFieldValidator: SimpleFieldValidator
30
38
 
31
39
  constructor(validationResult: ValidationResult, lang: LionWebLanguageDefinition) {
32
- this.validationResult = validationResult;
33
- this.language = lang;
34
- this.simpleFieldValidator = new SimpleFieldValidator(this.validationResult);
40
+ this.validationResult = validationResult
41
+ this.language = lang
42
+ this.simpleFieldValidator = new SimpleFieldValidator(this.validationResult)
35
43
  }
36
44
 
37
45
  // reset() {
@@ -41,94 +49,94 @@ export class LionWebLanguageReferenceValidator {
41
49
  // TODO test reference and children implementation
42
50
  validate(obj: LionWebJsonChunkWrapper): void {
43
51
  if (this.language === undefined || this.language === null) {
44
- return;
52
+ return
45
53
  }
46
54
  obj.jsonChunk.nodes.forEach((node, nodeIndex) => {
47
- const nodeContext = new JsonContext(null, ["node", nodeIndex]);
48
- const jsonConcept = this.language.getNodeByMetaPointer(node.classifier);
55
+ const nodeContext = new JsonContext(null, ["node", nodeIndex])
56
+ const jsonConcept = this.language.getNodeByMetaPointer(node.classifier)
49
57
  if (jsonConcept === null || jsonConcept === undefined) {
50
- this.validationResult.issue(new Language_UnknownConcept_Issue(nodeContext, node.classifier));
51
- return;
58
+ this.validationResult.issue(new Language_UnknownConcept_Issue(nodeContext, node.classifier))
59
+ return
52
60
  }
53
61
  node.properties.forEach((property, propIndex) => {
54
- this.validateProperty(property, nodeContext.concat("properties", propIndex));
55
- });
62
+ this.validateProperty(property, nodeContext.concat("properties", propIndex))
63
+ })
56
64
  node.containments.forEach((containment, childIndex) => {
57
- this.validateContainment(containment, nodeContext.concat("containments", childIndex));
58
- });
65
+ this.validateContainment(containment, nodeContext.concat("containments", childIndex))
66
+ })
59
67
  node.references.forEach((reference, refIndex) => {
60
- this.validateReference(reference, nodeContext.concat("references", refIndex));
61
- });
62
- });
68
+ this.validateReference(reference, nodeContext.concat("references", refIndex))
69
+ })
70
+ })
63
71
  }
64
72
 
65
- private validateContainment(child: LionWebJsonChild, context: JsonContext) {
66
- const type = this.language.getNodeByMetaPointer(child.containment);
73
+ private validateContainment(child: LionWebJsonContainment, context: JsonContext) {
74
+ const type = this.language.getNodeByMetaPointer(child.containment)
67
75
  if (type === null || type === undefined) {
68
- this.validationResult.issue(new Language_UnknownContainment_Issue(context, child.containment));
69
- return;
76
+ this.validationResult.issue(new Language_UnknownContainment_Issue(context, child.containment))
77
+ return
70
78
  }
71
79
  if (type.classifier.key !== LIONWEB_M3_CONCEPT_KEY) {
72
- this.validationResult.issue(new Language_IncorrectContainmentMetaPointer_Issue(context, child.containment, type.classifier.key));
80
+ this.validationResult.issue(new Language_IncorrectContainmentMetaPointer_Issue(context, child.containment, type.classifier.key))
73
81
  }
74
82
  // TODO check type of children
75
83
  }
76
84
 
77
85
  private validateReference(ref: LionWebJsonReference, context: JsonContext) {
78
- const type = this.language.getNodeByMetaPointer(ref.reference);
86
+ const type = this.language.getNodeByMetaPointer(ref.reference)
79
87
  if (type === null || type === undefined) {
80
- this.validationResult.issue(new Language_UnknownReference_Issue(context, ref.reference));
81
- return;
88
+ this.validationResult.issue(new Language_UnknownReference_Issue(context, ref.reference))
89
+ return
82
90
  }
83
91
  if (type.classifier.key !== LIONWEB_M3_CONCEPT_KEY) {
84
- this.validationResult.issue(new Language_IncorrectReferenceMetaPointer_Issue(context, ref.reference, type.classifier.key));
92
+ this.validationResult.issue(new Language_IncorrectReferenceMetaPointer_Issue(context, ref.reference, type.classifier.key))
85
93
  }
86
94
  // TODO Check type of reference (if possible)
87
95
 
88
96
  // TODO Check for duplicate targets?
89
97
  // If so, what to check because there can be either or both a `resolveInfo` and a `reference`
90
98
  }
91
-
99
+
92
100
  /**
93
101
  * Checks wwhether the value of `prop1` is correct in relation with its property definition in the referred language.
94
102
  * @param prop
95
103
  */
96
104
  validateProperty(prop: LionWebJsonProperty, context: JsonContext): void {
97
105
  if (prop.value === null) {
98
- return;
106
+ return
99
107
  }
100
- const type = this.language.getNodeByMetaPointer(prop.property);
108
+ const type = this.language.getNodeByMetaPointer(prop.property)
101
109
  if (type === null || type === undefined) {
102
- this.validationResult.issue(new Language_UnknownProperty_Issue(context, prop.property));
103
- return;
110
+ this.validationResult.issue(new Language_UnknownProperty_Issue(context, prop.property))
111
+ return
104
112
  }
105
113
  if (type.classifier.key !== LIONWEB_M3_PROPERTY_KEY) {
106
- this.validationResult.issue(new Language_IncorrectPropertyMetaPointer_Issue(context, prop.property, type.classifier.key));
107
- return;
114
+ this.validationResult.issue(new Language_IncorrectPropertyMetaPointer_Issue(context, prop.property, type.classifier.key))
115
+ return
108
116
  }
109
117
  // TODO check for property to exist inside the concept in the language
110
118
  // Need to find inherited and implemented properties as well: complex!
111
119
 
112
- const refType = type.references.find((ref) => (ref.reference.key === LIONWEB_M3_PROPERTY_TYPE_KEY));
113
- const propertyName = type.properties.find(p => p.property.key === LION_CORE_BUILTINS_INAMED_NAME)?.value;
120
+ const refType = type.references.find(ref => ref.reference.key === LIONWEB_M3_PROPERTY_TYPE_KEY)
121
+ const propertyName = type.properties.find(p => p.property.key === LION_CORE_BUILTINS_INAMED_NAME)?.value
114
122
  // console.log("Fount type should be " + refType.targets[0].reference);
115
123
  if (propertyName !== undefined) {
116
124
  if (refType !== null && refType !== undefined) {
117
125
  switch (refType.targets[0].reference) {
118
126
  case LIONWEB_BOOLEAN_TYPE:
119
- this.simpleFieldValidator.validateBoolean(prop, propertyName, context);
120
- break;
127
+ this.simpleFieldValidator.validateBoolean(prop, propertyName, context)
128
+ break
121
129
  case LIONWEB_INTEGER_TYPE:
122
- this.simpleFieldValidator.validateInteger(prop, propertyName, context);
123
- break;
130
+ this.simpleFieldValidator.validateInteger(prop, propertyName, context)
131
+ break
124
132
  case LIONWEB_STRING_TYPE:
125
- break;
133
+ break
126
134
  case LIONWEB_JSON_TYPE:
127
- this.simpleFieldValidator.validateJSON(prop, propertyName, context);
128
- break;
135
+ this.simpleFieldValidator.validateJSON(prop, propertyName, context)
136
+ break
129
137
  }
130
138
  } else {
131
- // TODO refType not found, but
139
+ // TODO refType not found, but
132
140
  }
133
141
  }
134
142
  }