@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.
- package/README.md +2 -0
- package/dist/diff/DiffResult.d.ts +9 -0
- package/dist/diff/DiffResult.d.ts.map +1 -0
- package/dist/diff/DiffResult.js +18 -0
- package/dist/diff/DiffResult.js.map +1 -0
- package/dist/diff/LionWebJsonDiff.d.ts +25 -0
- package/dist/diff/LionWebJsonDiff.d.ts.map +1 -0
- package/dist/diff/LionWebJsonDiff.js +205 -0
- package/dist/diff/LionWebJsonDiff.js.map +1 -0
- package/dist/diff/changes/Change.d.ts +16 -0
- package/dist/diff/changes/Change.d.ts.map +1 -0
- package/dist/diff/changes/Change.js +19 -0
- package/dist/diff/changes/Change.js.map +1 -0
- package/dist/diff/changes/ChunkChange.d.ts +43 -0
- package/dist/diff/changes/ChunkChange.d.ts.map +1 -0
- package/dist/diff/changes/ChunkChange.js +57 -0
- package/dist/diff/changes/ChunkChange.js.map +1 -0
- package/dist/diff/changes/ContainmentChange.d.ts +26 -0
- package/dist/diff/changes/ContainmentChange.d.ts.map +1 -0
- package/dist/diff/changes/ContainmentChange.js +34 -0
- package/dist/diff/changes/ContainmentChange.js.map +1 -0
- package/dist/diff/changes/NodeChange.d.ts +22 -0
- package/dist/diff/changes/NodeChange.d.ts.map +1 -0
- package/dist/diff/changes/NodeChange.js +24 -0
- package/dist/diff/changes/NodeChange.js.map +1 -0
- package/dist/diff/changes/PropertyChange.d.ts +23 -0
- package/dist/diff/changes/PropertyChange.d.ts.map +1 -0
- package/dist/diff/changes/PropertyChange.js +28 -0
- package/dist/diff/changes/PropertyChange.js.map +1 -0
- package/dist/diff/changes/ReferenceChange.d.ts +19 -0
- package/dist/diff/changes/ReferenceChange.d.ts.map +1 -0
- package/dist/diff/changes/ReferenceChange.js +25 -0
- package/dist/diff/changes/ReferenceChange.js.map +1 -0
- package/dist/diff/changes/index.d.ts +7 -0
- package/dist/diff/changes/index.d.ts.map +1 -0
- package/dist/diff/changes/index.js +7 -0
- package/dist/diff/changes/index.js.map +1 -0
- package/dist/diff/index.d.ts +4 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +4 -0
- package/dist/diff/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/issues/LanguageIssues.d.ts +1 -1
- package/dist/issues/LanguageIssues.d.ts.map +1 -1
- package/dist/issues/LanguageIssues.js.map +1 -1
- package/dist/issues/ReferenceIssues.d.ts +1 -1
- package/dist/issues/ReferenceIssues.d.ts.map +1 -1
- package/dist/issues/ReferenceIssues.js.map +1 -1
- package/dist/issues/SyntaxIssues.d.ts +1 -1
- package/dist/issues/SyntaxIssues.d.ts.map +1 -1
- package/dist/issues/SyntaxIssues.js +4 -4
- package/dist/issues/SyntaxIssues.js.map +1 -1
- package/dist/issues/ValidationIssue.d.ts +1 -1
- package/dist/issues/ValidationIssue.d.ts.map +1 -1
- package/dist/issues/ValidationIssue.js.map +1 -1
- package/dist/issues/index.d.ts +1 -1
- package/dist/issues/index.d.ts.map +1 -1
- package/dist/issues/index.js +1 -1
- package/dist/issues/index.js.map +1 -1
- package/dist/json/ChunkUtils.d.ts.map +1 -1
- package/dist/json/ChunkUtils.js.map +1 -1
- package/dist/json/JsonContext.d.ts.map +1 -0
- package/dist/json/JsonContext.js.map +1 -0
- package/dist/json/LanguageUtils.d.ts.map +1 -1
- package/dist/json/LanguageUtils.js.map +1 -1
- package/dist/json/LionWebJson.d.ts +10 -9
- package/dist/json/LionWebJson.d.ts.map +1 -1
- package/dist/json/LionWebJson.js +1 -0
- package/dist/json/LionWebJson.js.map +1 -1
- package/dist/json/LionWebJsonChunkWrapper.d.ts +7 -4
- package/dist/json/LionWebJsonChunkWrapper.d.ts.map +1 -1
- package/dist/json/LionWebJsonChunkWrapper.js +48 -10
- package/dist/json/LionWebJsonChunkWrapper.js.map +1 -1
- package/dist/json/LionWebLanguageDefinition.d.ts.map +1 -1
- package/dist/json/LionWebLanguageDefinition.js +3 -3
- package/dist/json/LionWebLanguageDefinition.js.map +1 -1
- package/dist/json/NodeUtils.d.ts +5 -4
- package/dist/json/NodeUtils.d.ts.map +1 -1
- package/dist/json/NodeUtils.js +5 -2
- package/dist/json/NodeUtils.js.map +1 -1
- package/dist/json/index.d.ts +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -0
- package/dist/json/index.js.map +1 -1
- package/dist/runners/FileUtils.d.ts.map +1 -1
- package/dist/runners/FileUtils.js.map +1 -1
- package/dist/runners/RunCheckFolder.js.map +1 -1
- package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -1
- package/dist/runners/RunCheckOneFile.js.map +1 -1
- package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -1
- package/dist/runners/RunLioncoreDiff.js +5 -5
- package/dist/runners/RunLioncoreDiff.js.map +1 -1
- package/dist/runners/Utils.d.ts.map +1 -1
- package/dist/runners/Utils.js +1 -1
- package/dist/runners/Utils.js.map +1 -1
- package/dist/runners/index.d.ts.map +1 -1
- package/dist/runners/index.js.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.js +6 -6
- package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageValidator.js +1 -1
- package/dist/validators/LionWebLanguageValidator.js.map +1 -1
- package/dist/validators/LionWebReferenceValidator.d.ts +1 -1
- package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebReferenceValidator.js +6 -6
- package/dist/validators/LionWebReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +21 -11
- package/dist/validators/LionWebSyntaxValidator.js.map +1 -1
- package/dist/validators/LionWebValidator.d.ts.map +1 -1
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/dist/validators/SimpleFieldValidator.d.ts +1 -1
- package/dist/validators/SimpleFieldValidator.d.ts.map +1 -1
- package/dist/validators/SimpleFieldValidator.js +1 -1
- package/dist/validators/SimpleFieldValidator.js.map +1 -1
- package/dist/validators/ValidationResult.d.ts.map +1 -1
- package/dist/validators/ValidationResult.js.map +1 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js.map +1 -1
- package/package.json +5 -2
- package/src/diff/DiffResult.ts +21 -0
- package/src/diff/LionWebJsonDiff.ts +259 -0
- package/src/diff/changes/Change.ts +52 -0
- package/src/diff/changes/ChunkChange.ts +68 -0
- package/src/diff/changes/ContainmentChange.ts +34 -0
- package/src/diff/changes/NodeChange.ts +32 -0
- package/src/diff/changes/PropertyChange.ts +29 -0
- package/src/diff/changes/ReferenceChange.ts +24 -0
- package/src/diff/changes/index.ts +6 -0
- package/src/diff/index.ts +3 -0
- package/src/index.ts +5 -4
- package/src/issues/LanguageIssues.ts +61 -39
- package/src/issues/ReferenceIssues.ts +51 -29
- package/src/issues/SyntaxIssues.ts +38 -23
- package/src/issues/ValidationIssue.ts +7 -7
- package/src/issues/index.ts +5 -5
- package/src/json/ChunkUtils.ts +7 -11
- package/src/json/JsonContext.ts +31 -0
- package/src/json/LanguageUtils.ts +5 -6
- package/src/json/LionWebJson.ts +44 -43
- package/src/json/LionWebJsonChunkWrapper.ts +76 -29
- package/src/json/LionWebLanguageDefinition.ts +44 -49
- package/src/json/NodeUtils.ts +25 -19
- package/src/json/index.ts +7 -6
- package/src/json/std-builtins-copy.json +347 -349
- package/src/runners/FileUtils.ts +48 -49
- package/src/runners/RunCheckFolder.ts +3 -3
- package/src/runners/RunCheckFolderWithLanguage.ts +31 -30
- package/src/runners/RunCheckOneFile.ts +3 -3
- package/src/runners/RunCheckOneFileWithLanguage.ts +21 -19
- package/src/runners/RunLioncoreDiff.ts +15 -15
- package/src/runners/Utils.ts +24 -24
- package/src/runners/index.ts +2 -2
- package/src/validators/LionWebLanguageReferenceValidator.ts +63 -55
- package/src/validators/LionWebLanguageValidator.ts +11 -12
- package/src/validators/LionWebReferenceValidator.ts +90 -76
- package/src/validators/LionWebSyntaxValidator.ts +108 -99
- package/src/validators/LionWebValidator.ts +33 -33
- package/src/validators/SimpleFieldValidator.ts +33 -28
- package/src/validators/ValidationResult.ts +5 -6
- package/src/validators/index.ts +7 -7
- package/dist/diff/LionwebDiff.d.ts +0 -40
- package/dist/diff/LionwebDiff.d.ts.map +0 -1
- package/dist/diff/LionwebDiff.js +0 -158
- package/dist/diff/LionwebDiff.js.map +0 -1
- package/dist/issues/JsonContext.d.ts.map +0 -1
- package/dist/issues/JsonContext.js.map +0 -1
- package/src/diff/LionwebDiff.ts +0 -193
- package/src/issues/JsonContext.ts +0 -31
- /package/dist/{issues → json}/JsonContext.d.ts +0 -0
- /package/dist/{issues → json}/JsonContext.js +0 -0
package/src/runners/FileUtils.ts
CHANGED
|
@@ -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,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
|
-
|
|
15
|
-
|
|
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(
|
|
30
|
-
|
|
31
|
-
|
|
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,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
|
|
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(
|
|
25
|
-
|
|
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 {
|
|
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
|
|
15
|
-
lwDiff.diffLwChunk(json1 as LionWebJsonChunk, json2 as LionWebJsonChunk)
|
|
16
|
-
if (lwDiff.
|
|
17
|
-
console.log("
|
|
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("
|
|
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
|
}
|
package/src/runners/Utils.ts
CHANGED
|
@@ -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
|
}
|
package/src/runners/index.ts
CHANGED
|
@@ -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,
|
|
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 "
|
|
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,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
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:
|
|
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(
|
|
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
|
}
|