@lionweb/validation 0.7.0-beta.10 → 0.7.0-beta.12

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 (170) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/index.d.ts +5 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +5 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/issues/LanguageIssues.d.ts +99 -0
  7. package/dist/issues/LanguageIssues.d.ts.map +1 -0
  8. package/dist/issues/LanguageIssues.js +146 -0
  9. package/dist/issues/LanguageIssues.js.map +1 -0
  10. package/dist/issues/ReferenceIssues.d.ts +43 -0
  11. package/dist/issues/ReferenceIssues.d.ts.map +1 -0
  12. package/dist/issues/ReferenceIssues.js +53 -0
  13. package/dist/issues/ReferenceIssues.js.map +1 -0
  14. package/dist/issues/SyntaxIssues.d.ts +53 -0
  15. package/dist/issues/SyntaxIssues.d.ts.map +1 -0
  16. package/dist/issues/SyntaxIssues.js +81 -0
  17. package/dist/issues/SyntaxIssues.js.map +1 -0
  18. package/dist/issues/ValidationIssue.d.ts +15 -0
  19. package/dist/issues/ValidationIssue.d.ts.map +1 -0
  20. package/dist/issues/ValidationIssue.js +17 -0
  21. package/dist/issues/ValidationIssue.js.map +1 -0
  22. package/dist/issues/index.d.ts +5 -0
  23. package/dist/issues/index.d.ts.map +1 -0
  24. package/dist/issues/index.js +5 -0
  25. package/dist/issues/index.js.map +1 -0
  26. package/dist/languages/CompositeLionWebLanguageWrapper.d.ts +24 -0
  27. package/dist/languages/CompositeLionWebLanguageWrapper.d.ts.map +1 -0
  28. package/dist/languages/CompositeLionWebLanguageWrapper.js +56 -0
  29. package/dist/languages/CompositeLionWebLanguageWrapper.js.map +1 -0
  30. package/dist/languages/LanguageRegistry.d.ts +19 -0
  31. package/dist/languages/LanguageRegistry.d.ts.map +1 -0
  32. package/dist/languages/LanguageRegistry.js +37 -0
  33. package/dist/languages/LanguageRegistry.js.map +1 -0
  34. package/dist/languages/LanguageUtils.d.ts +35 -0
  35. package/dist/languages/LanguageUtils.d.ts.map +1 -0
  36. package/dist/languages/LanguageUtils.js +54 -0
  37. package/dist/languages/LanguageUtils.js.map +1 -0
  38. package/dist/languages/LionWebLanguageWrapper.d.ts +31 -0
  39. package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -0
  40. package/dist/languages/LionWebLanguageWrapper.js +69 -0
  41. package/dist/languages/LionWebLanguageWrapper.js.map +1 -0
  42. package/dist/languages/MetaPointerMap.d.ts +11 -0
  43. package/dist/languages/MetaPointerMap.d.ts.map +1 -0
  44. package/dist/languages/MetaPointerMap.js +39 -0
  45. package/dist/languages/MetaPointerMap.js.map +1 -0
  46. package/dist/languages/index.d.ts +3 -0
  47. package/dist/languages/index.d.ts.map +1 -0
  48. package/dist/languages/index.js +3 -0
  49. package/dist/languages/index.js.map +1 -0
  50. package/dist/runners/FileUtils.d.ts +6 -0
  51. package/dist/runners/FileUtils.d.ts.map +1 -0
  52. package/dist/runners/FileUtils.js +53 -0
  53. package/dist/runners/FileUtils.js.map +1 -0
  54. package/dist/runners/RunCheckFolder.d.ts +2 -0
  55. package/dist/runners/RunCheckFolder.d.ts.map +1 -0
  56. package/dist/runners/RunCheckFolder.js +6 -0
  57. package/dist/runners/RunCheckFolder.js.map +1 -0
  58. package/dist/runners/RunCheckFolderWithLanguage.d.ts +2 -0
  59. package/dist/runners/RunCheckFolderWithLanguage.d.ts.map +1 -0
  60. package/dist/runners/RunCheckFolderWithLanguage.js +40 -0
  61. package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -0
  62. package/dist/runners/RunCheckOneFile.d.ts +2 -0
  63. package/dist/runners/RunCheckOneFile.d.ts.map +1 -0
  64. package/dist/runners/RunCheckOneFile.js +6 -0
  65. package/dist/runners/RunCheckOneFile.js.map +1 -0
  66. package/dist/runners/RunCheckOneFileWithLanguage.d.ts +2 -0
  67. package/dist/runners/RunCheckOneFileWithLanguage.d.ts.map +1 -0
  68. package/dist/runners/RunCheckOneFileWithLanguage.js +31 -0
  69. package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -0
  70. package/dist/runners/RunLioncoreDiff.d.ts +2 -0
  71. package/dist/runners/RunLioncoreDiff.d.ts.map +1 -0
  72. package/dist/runners/RunLioncoreDiff.js +22 -0
  73. package/dist/runners/RunLioncoreDiff.js.map +1 -0
  74. package/dist/runners/Utils.d.ts +7 -0
  75. package/dist/runners/Utils.d.ts.map +1 -0
  76. package/dist/runners/Utils.js +48 -0
  77. package/dist/runners/Utils.js.map +1 -0
  78. package/dist/runners/index.d.ts +3 -0
  79. package/dist/runners/index.d.ts.map +1 -0
  80. package/dist/runners/index.js +3 -0
  81. package/dist/runners/index.js.map +1 -0
  82. package/dist/validators/LionWebChunkDefinitions.d.ts +9 -0
  83. package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -0
  84. package/{src/validators/LionWebChunkDefinitions.ts → dist/validators/LionWebChunkDefinitions.js} +10 -14
  85. package/dist/validators/LionWebChunkDefinitions.js.map +1 -0
  86. package/dist/validators/LionWebLanguageReferenceValidator.d.ts +21 -0
  87. package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -0
  88. package/{src/validators/LionWebLanguageReferenceValidator.ts → dist/validators/LionWebLanguageReferenceValidator.js} +73 -108
  89. package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -0
  90. package/dist/validators/LionWebLanguageValidator.d.ts +23 -0
  91. package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -0
  92. package/dist/validators/LionWebLanguageValidator.js +66 -0
  93. package/dist/validators/LionWebLanguageValidator.js.map +1 -0
  94. package/dist/validators/LionWebReferenceValidator.d.ts +43 -0
  95. package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -0
  96. package/{src/validators/LionWebReferenceValidator.ts → dist/validators/LionWebReferenceValidator.js} +84 -106
  97. package/dist/validators/LionWebReferenceValidator.js.map +1 -0
  98. package/dist/validators/LionWebSyntaxValidator.d.ts +9 -0
  99. package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -0
  100. package/dist/validators/LionWebSyntaxValidator.js +11 -0
  101. package/dist/validators/LionWebSyntaxValidator.js.map +1 -0
  102. package/dist/validators/LionWebValidator.d.ts +24 -0
  103. package/dist/validators/LionWebValidator.d.ts.map +1 -0
  104. package/{src/validators/LionWebValidator.ts → dist/validators/LionWebValidator.js} +29 -45
  105. package/dist/validators/LionWebValidator.js.map +1 -0
  106. package/dist/validators/ValidationFunctions.d.ts +60 -0
  107. package/dist/validators/ValidationFunctions.d.ts.map +1 -0
  108. package/{src/validators/ValidationFunctions.ts → dist/validators/ValidationFunctions.js} +34 -66
  109. package/dist/validators/ValidationFunctions.js.map +1 -0
  110. package/dist/validators/generic/SyntaxValidator.d.ts +37 -0
  111. package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -0
  112. package/dist/validators/generic/SyntaxValidator.js +152 -0
  113. package/dist/validators/generic/SyntaxValidator.js.map +1 -0
  114. package/dist/validators/generic/ValidationResult.d.ts +8 -0
  115. package/dist/validators/generic/ValidationResult.d.ts.map +1 -0
  116. package/dist/validators/generic/ValidationResult.js +15 -0
  117. package/dist/validators/generic/ValidationResult.js.map +1 -0
  118. package/dist/validators/generic/index.d.ts +4 -0
  119. package/dist/validators/generic/index.d.ts.map +1 -0
  120. package/dist/validators/generic/index.js +4 -0
  121. package/dist/validators/generic/index.js.map +1 -0
  122. package/dist/validators/generic/schema/DefinitionSchema.d.ts +23 -0
  123. package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +1 -0
  124. package/dist/validators/generic/schema/DefinitionSchema.js +43 -0
  125. package/dist/validators/generic/schema/DefinitionSchema.js.map +1 -0
  126. package/dist/validators/generic/schema/ValidationTypes.d.ts +101 -0
  127. package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
  128. package/dist/validators/generic/schema/ValidationTypes.js +43 -0
  129. package/dist/validators/generic/schema/ValidationTypes.js.map +1 -0
  130. package/dist/validators/generic/schema/index.d.ts +3 -0
  131. package/dist/validators/generic/schema/index.d.ts.map +1 -0
  132. package/dist/validators/generic/schema/index.js +3 -0
  133. package/dist/validators/generic/schema/index.js.map +1 -0
  134. package/dist/validators/index.d.ts +9 -0
  135. package/dist/validators/index.d.ts.map +1 -0
  136. package/dist/validators/index.js +9 -0
  137. package/dist/validators/index.js.map +1 -0
  138. package/package.json +4 -4
  139. package/src/index.ts +0 -4
  140. package/src/issues/LanguageIssues.ts +0 -147
  141. package/src/issues/ReferenceIssues.ts +0 -83
  142. package/src/issues/SyntaxIssues.ts +0 -84
  143. package/src/issues/ValidationIssue.ts +0 -29
  144. package/src/issues/index.ts +0 -4
  145. package/src/languages/CompositeLionWebLanguageWrapper.ts +0 -57
  146. package/src/languages/LanguageRegistry.ts +0 -44
  147. package/src/languages/LanguageUtils.ts +0 -63
  148. package/src/languages/LionWebLanguageWrapper.ts +0 -91
  149. package/src/languages/MetaPointerMap.ts +0 -41
  150. package/src/languages/index.ts +0 -2
  151. package/src/runners/FileUtils.ts +0 -59
  152. package/src/runners/RunCheckFolder.ts +0 -7
  153. package/src/runners/RunCheckFolderWithLanguage.ts +0 -45
  154. package/src/runners/RunCheckOneFile.ts +0 -7
  155. package/src/runners/RunCheckOneFileWithLanguage.ts +0 -35
  156. package/src/runners/RunLioncoreDiff.ts +0 -23
  157. package/src/runners/Utils.ts +0 -54
  158. package/src/runners/index.ts +0 -2
  159. package/src/validators/LionWebLanguageValidator.ts +0 -78
  160. package/src/validators/LionWebSyntaxValidator.ts +0 -14
  161. package/src/validators/generic/SyntaxValidator.ts +0 -216
  162. package/src/validators/generic/ValidationResult.ts +0 -17
  163. package/src/validators/generic/index.ts +0 -3
  164. package/src/validators/generic/schema/DefinitionSchema.ts +0 -52
  165. package/src/validators/generic/schema/ValidationTypes.ts +0 -134
  166. package/src/validators/generic/schema/index.ts +0 -2
  167. package/src/validators/index.ts +0 -8
  168. package/tsconfig.json +0 -8
  169. /package/{src → dist}/languages/LionCore-M3.json +0 -0
  170. /package/{src → dist}/languages/LionCore-builtins.json +0 -0
@@ -1,44 +0,0 @@
1
- import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
2
- import { CompositeLionWebLanguageWrapper } from "./CompositeLionWebLanguageWrapper.js"
3
- import { LionWebLanguageWrapper } from "./LionWebLanguageWrapper.js"
4
-
5
- /**
6
- * Collection of language definitions
7
- */
8
- export class LanguageRegistry {
9
- languages: CompositeLionWebLanguageWrapper = new CompositeLionWebLanguageWrapper({nodes: [], languages: [], serializationFormatVersion: "2023.1"})
10
-
11
- addLanguage(lionWebLanguage: LionWebLanguageWrapper) {
12
- // console.log("LanguageRegistry.add: " + lionWebLanguage.name + " " + lionWebLanguage.jsonChunk.nodes.length)
13
-
14
- this.languages.addLanguage(lionWebLanguage)
15
- }
16
-
17
- clear(): void {
18
- this.languages = new CompositeLionWebLanguageWrapper({nodes: [], languages: [], serializationFormatVersion: "2023.1"})
19
- }
20
-
21
- getLanguage(pointer: LionWebJsonMetaPointer): LionWebLanguageWrapper | undefined {
22
- return this.languages.languageMap.get(pointer.language)?.get(pointer.version)
23
- }
24
-
25
- /**
26
- * Gets the node with _metaPointer_ in any of the known languages
27
- * @param metaPointer
28
- */
29
- getNodeByMetaPointer(metaPointer: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
30
- return this.languages.getNodeByMetaPointer(metaPointer)
31
- }
32
-
33
- findNode(nodeId: LionWebId) {
34
- for (const chunk of this.languages.languages) {
35
- const node = chunk.getNode(nodeId)
36
- if (node !== undefined) {
37
- return node
38
- }
39
- }
40
- return undefined
41
- }
42
- }
43
-
44
- // export const KnownLanguages = new LanguageRegistry()
@@ -1,63 +0,0 @@
1
- import { isEqualMetaPointer, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
2
- import { LION_CORE_M3_KEY, MetaPointers } from "@lionweb/json-utils"
3
-
4
- import { createRequire } from "module"
5
-
6
- const require = createRequire(import.meta.url)
7
- const LionCore_M3 = require("./LionCore-M3.json")
8
- const LionCore_builtins = require("./LionCore-builtins.json")
9
-
10
- export const LionCore_M3_Json = LionCore_M3 as LionWebJsonChunk
11
- export const LionCore_builtins_Json = LionCore_builtins as LionWebJsonChunk
12
-
13
- export function isLionCoreLanguage(node: LionWebJsonNode) {
14
- return node.classifier.language === LION_CORE_M3_KEY && node.classifier.version === "2023.1"
15
- }
16
-
17
- /**
18
- * Does _node_ represent a language concept?
19
- * @param node
20
- */
21
- export const isConcept = (node: LionWebJsonNode): boolean => {
22
- return isEqualMetaPointer(node.classifier, MetaPointers.Concept)
23
- }
24
-
25
- /**
26
- * Does _node_ represent a language annotation?
27
- * @param node
28
- */
29
- export const isAnnotation = (node: LionWebJsonNode): boolean => {
30
- return isEqualMetaPointer(node.classifier, MetaPointers.Annotation)
31
- }
32
-
33
- /**
34
- * Does _node_ represent a language interface?
35
- * @param node
36
- */
37
- export const isInterface = (node: LionWebJsonNode): boolean => {
38
- return isEqualMetaPointer(node.classifier, MetaPointers.Interface)
39
- }
40
-
41
- /**
42
- * Does _node_ represent a language property?
43
- * @param node
44
- */
45
- export const isProperty = (node: LionWebJsonNode): boolean => {
46
- return isEqualMetaPointer(node.classifier, MetaPointers.Property)
47
- }
48
-
49
- /**
50
- * Does _node_ represent a language containment?
51
- * @param node
52
- */
53
- export const isContainment = (node: LionWebJsonNode): boolean => {
54
- return isEqualMetaPointer(node.classifier, MetaPointers.Containment)
55
- }
56
-
57
- /**
58
- * Does _node_ represent a language reference?
59
- * @param node
60
- */
61
- export const isReference = (node: LionWebJsonNode): boolean => {
62
- return isEqualMetaPointer(node.classifier, MetaPointers.Reference)
63
- }
@@ -1,91 +0,0 @@
1
- import { LionWebJsonChunk, LionWebJsonNode, LionWebKey } from "@lionweb/json"
2
- import { LionWebJsonChunkWrapper, MetaPointers, NodeUtils } from "@lionweb/json-utils"
3
- import { visitAndMap } from "@lionweb/ts-utils"
4
- import { isAnnotation, isConcept, isContainment, isInterface, isProperty, isReference } from "./LanguageUtils.js"
5
-
6
- interface LionWebLanguageWrapperInterface {
7
- superClassifiers: (classifier: LionWebJsonNode) => LionWebJsonNode[]
8
- allClassifiers: (classifier: LionWebJsonNode) => LionWebJsonNode[]
9
- propertyDefinitions: (classifier: LionWebJsonNode) => LionWebJsonNode[]
10
- allProperties: (classifier: LionWebJsonNode) => LionWebJsonNode[]
11
- referenceDefinitions: (classifier: LionWebJsonNode) => LionWebJsonNode[]
12
- allReferenceDefinitions: (classifier: LionWebJsonNode) => LionWebJsonNode[]
13
- containmentDefinitions: (classifier: LionWebJsonNode) => LionWebJsonNode[]
14
- allContainments: (classifier: LionWebJsonNode) => LionWebJsonNode[]
15
- }
16
-
17
- /**
18
- * Class encapsulating a chunk that represent a language.
19
- */
20
- export class LionWebLanguageWrapper extends LionWebJsonChunkWrapper implements LionWebLanguageWrapperInterface {
21
- name: string
22
- version: string
23
- key: LionWebKey
24
-
25
- constructor(chunk: LionWebJsonChunk) {
26
- super(chunk)
27
- const languageNode: LionWebJsonNode = this.findNodesOfClassifier(MetaPointers.Language)[0]
28
- const versionProp = NodeUtils.findProperty(languageNode, MetaPointers.LanguageVersion)
29
- const keyProp = NodeUtils.findProperty(languageNode, MetaPointers.IKeyedKey)
30
- const nameProp = NodeUtils.findProperty(languageNode, MetaPointers.INamedName)
31
- this.version = versionProp?.value || "unknown"
32
- this.key = keyProp?.value || "unknown"
33
- this.name = nameProp?.value || "unknown"
34
- }
35
-
36
- superClassifiers = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
37
- const result: LionWebJsonNode[] = []
38
-
39
- if (isConcept(classifier)) {
40
- const extnds = NodeUtils.findReference(classifier, MetaPointers.ConceptExtends)
41
- const implments = NodeUtils.findReference(classifier, MetaPointers.ConceptImplements)
42
- result.push(...this.getReferredNodes(extnds))
43
- result.push(...this.getReferredNodes(implments))
44
- } else if (isAnnotation(classifier)) {
45
- const extnds = NodeUtils.findReference(classifier, MetaPointers.AnnotationExtends)
46
- const implments = NodeUtils.findReference(classifier, MetaPointers.AnnotationImplements)
47
- result.push(...this.getReferredNodes(extnds))
48
- result.push(...this.getReferredNodes(implments))
49
- } else if (isInterface(classifier)) {
50
- const extnds = NodeUtils.findReference(classifier, MetaPointers.InterfaceExtends)
51
- result.push(...this.getReferredNodes(extnds))
52
- } else {
53
- throw new Error(`concept type ${typeof classifier} not handled`)
54
- }
55
- return result
56
- }
57
-
58
- allClassifiers = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
59
- return visitAndMap(this.superClassifiers, this.superClassifiers)(classifier)
60
- }
61
-
62
- propertyDefinitions = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
63
- const features = NodeUtils.findContainment(classifier, MetaPointers.ClassifierFeatures)
64
- const properties = this.getChildrenAsNodes(features).filter(f => isProperty(f))
65
- return properties
66
- }
67
-
68
- allProperties = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
69
- return visitAndMap(this.propertyDefinitions, this.superClassifiers)(classifier)
70
- }
71
-
72
- referenceDefinitions = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
73
- const features = NodeUtils.findContainment(classifier, MetaPointers.ClassifierFeatures)
74
- const references = this.getChildrenAsNodes(features).filter(f => isReference(f))
75
- return references
76
- }
77
-
78
- allReferenceDefinitions = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
79
- return visitAndMap(this.referenceDefinitions, this.superClassifiers)(classifier)
80
- }
81
-
82
- containmentDefinitions = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
83
- const features = NodeUtils.findContainment(classifier, MetaPointers.ClassifierFeatures)
84
- const properties = this.getChildrenAsNodes(features).filter(f => isContainment(f))
85
- return properties
86
- }
87
-
88
- allContainments = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
89
- return visitAndMap(this.containmentDefinitions, this.superClassifiers)(classifier)
90
- }
91
- }
@@ -1,41 +0,0 @@
1
- import { LionWebJsonMetaPointer, LionWebJsonNode, LionWebKey } from "@lionweb/json"
2
- import { MetaPointers, NodeUtils } from "@lionweb/json-utils"
3
-
4
- export class MetaPointerMap {
5
- /**
6
- * Map from languageKey => languageVersion => key => LionWebJsonNode
7
- */
8
- map: Map<string, Map<string, Map<string, LionWebJsonNode>>> = new Map<string, Map<string, Map<string, LionWebJsonNode>>>()
9
-
10
- add(languageKey: LionWebKey, languageVersion: string, node: LionWebJsonNode): void {
11
- const keyProperty = NodeUtils.findProperty(node, MetaPointers.IKeyedKey)
12
- if (keyProperty === undefined) {
13
- console.log("MetaPointerMap.add: trying to add node without key property.")
14
- return
15
- }
16
- const key = keyProperty.value
17
- if (key === undefined || key == null || key === "") {
18
- console.log("MetaPointerMap.add: trying to add node without key property being empty or null.")
19
- return
20
- }
21
- this.set({ language: languageKey, version: languageVersion, key: key }, node)
22
- }
23
-
24
- set(mp: LionWebJsonMetaPointer, node: LionWebJsonNode): void {
25
- let language = this.map.get(mp.language)
26
- if (language === undefined) {
27
- language = new Map<string, Map<string, LionWebJsonNode>>()
28
- this.map.set(mp.language, language)
29
- }
30
- let version = language.get(mp.version)
31
- if (version === undefined) {
32
- version = new Map<string, LionWebJsonNode>()
33
- language.set(mp.version, version)
34
- }
35
- version.set(mp.key, node)
36
- }
37
-
38
- get(mp: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
39
- return this.map.get(mp.language)?.get(mp.version)?.get(mp.key)
40
- }
41
- }
@@ -1,2 +0,0 @@
1
- export * from "./LanguageRegistry.js"
2
- export * from "../languages/LanguageUtils.js"
@@ -1,59 +0,0 @@
1
- import fs from "fs"
2
- import { LanguageRegistry } from "../languages/index.js"
3
- import { ValidationResult } from "../validators/generic/ValidationResult.js"
4
- import { LionWebValidator } from "../validators/LionWebValidator.js"
5
- import { getFilesRecursive, printIssues } from "./Utils.js"
6
-
7
- export function validateFile(file: string, registry: LanguageRegistry): void {
8
- const result = validateFileResult(file, false, registry)
9
- printIssues(result)
10
- }
11
-
12
- export function validateFileResult(file: string, validateAgainstLanguage: boolean, registry: LanguageRegistry): ValidationResult {
13
- if (file !== null) {
14
- const jsonString1 = fs.readFileSync(file, "utf-8")
15
- const json1 = JSON.parse(jsonString1)
16
- const validator = new LionWebValidator(json1, registry)
17
-
18
- validator.validateSyntax()
19
- validator.validateReferences()
20
- if (validateAgainstLanguage) {
21
- validator.validateForLanguage()
22
- }
23
- return validator.validationResult
24
- }
25
- return new ValidationResult()
26
- }
27
-
28
- export function validateFolder(folder: string, registry: LanguageRegistry): void {
29
- let totalErrors = 0
30
- let totalSucceed = 0
31
- let totalFailed = 0
32
-
33
- for (const f of getFilesRecursive(folder, [])) {
34
- const jsonString1 = fs.readFileSync(f, "utf-8")
35
- const json1 = JSON.parse(jsonString1)
36
- const validator = new LionWebValidator(json1, registry)
37
-
38
- try {
39
- validator.validateAll()
40
-
41
- if (!validator.validationResult.hasErrors()) {
42
- totalSucceed += 1
43
- console.log("V PASSED " + f)
44
- printIssues(validator.validationResult, f)
45
- } else {
46
- printIssues(validator.validationResult, f)
47
- totalFailed += 1
48
- totalErrors += validator.validationResult.issues.length
49
- }
50
- } catch (e: unknown) {
51
- console.log("EXCEPTION in file: " + f)
52
- console.log("EXCEPTION " + (e as Error)?.stack)
53
- }
54
- }
55
-
56
- console.log("Total without errors: " + totalSucceed)
57
- console.log("Total with errors: " + totalFailed)
58
- console.log("Total number of errors: " + totalErrors)
59
- }
@@ -1,7 +0,0 @@
1
- import { LanguageRegistry } from "../languages/index.js"
2
- import { validateFolder } from "./FileUtils.js"
3
-
4
- const folder = process.argv[2]
5
-
6
- const registry = new LanguageRegistry()
7
- validateFolder(folder, registry)
@@ -1,45 +0,0 @@
1
- import fs from "fs"
2
- import { LanguageRegistry } from "../languages/index.js"
3
- import { LionWebLanguageWrapper } from "../languages/LionWebLanguageWrapper.js"
4
- import { LionWebValidator } from "../validators/LionWebValidator.js"
5
- import { getFilesRecursive, printIssues } from "./Utils.js"
6
-
7
- const folder = process.argv[2]
8
- const language = process.argv[3]
9
-
10
- let totalSucceed = 0
11
- let totalFailed = 0
12
-
13
- const registry = new LanguageRegistry()
14
- const languageString = fs.readFileSync(language, "utf-8")
15
- const languageJson = JSON.parse(languageString)
16
- const languageValidator = new LionWebValidator(languageJson, registry)
17
- registry.addLanguage(new LionWebLanguageWrapper(languageJson))
18
-
19
- console.log("Language is " + language)
20
- languageValidator.validateSyntax()
21
- languageValidator.validateReferences()
22
- if (languageValidator.validationResult.hasErrors()) {
23
- console.log("===== Language errors, ignoring folder ======")
24
- printIssues(languageValidator.validationResult)
25
- process.exit(1)
26
- }
27
-
28
- for (const modelFile of getFilesRecursive(folder, [])) {
29
- const jsonString1 = fs.readFileSync(modelFile, "utf-8")
30
- const jsonModel = JSON.parse(jsonString1)
31
- const modelValidator = new LionWebValidator(jsonModel, registry)
32
-
33
- modelValidator.validateAll()
34
- if (modelValidator.validationResult.hasErrors()) {
35
- totalFailed++
36
- // console.log("FAILED: " + modelFile)
37
- printIssues(modelValidator.validationResult, modelFile)
38
- } else {
39
- console.log("SUCCEEDED: " + modelFile)
40
- totalSucceed++
41
- }
42
- }
43
-
44
- console.log("Total without errors: " + totalSucceed)
45
- console.log("Total with errors: " + totalFailed)
@@ -1,7 +0,0 @@
1
- import { LanguageRegistry } from "../languages/index.js"
2
- import { validateFile } from "./FileUtils.js"
3
-
4
- const file1 = process.argv[2]
5
-
6
- const registry = new LanguageRegistry()
7
- validateFile(file1, registry)
@@ -1,35 +0,0 @@
1
- import fs from "fs"
2
- import { LanguageRegistry } from "../languages/index.js"
3
- import { LionWebLanguageWrapper } from "../languages/LionWebLanguageWrapper.js"
4
- import { LionWebValidator } from "../validators/LionWebValidator.js"
5
- import { printIssues } from "./Utils.js"
6
-
7
- const modelFile = process.argv[2]
8
- const language = process.argv[3]
9
-
10
- if (modelFile !== null) {
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)
15
- const m3String = fs.readFileSync("src/json/LionCore_M3.json", "utf-8")
16
- const m3Json = JSON.parse(m3String)
17
- const builtinString = fs.readFileSync("src/json/LionCore_builtins.json", "utf-8")
18
- const builtinJson = JSON.parse(builtinString)
19
- const registry = new LanguageRegistry()
20
- registry.addLanguage(new LionWebLanguageWrapper(m3Json))
21
- registry.addLanguage(new LionWebLanguageWrapper(builtinJson))
22
- registry.addLanguage(new LionWebLanguageWrapper(languageJson))
23
-
24
- const languageValidator = new LionWebValidator(languageJson, registry)
25
-
26
- languageValidator.validateSyntax()
27
- languageValidator.validateReferences()
28
- console.log("===== Language errors ======")
29
- printIssues(languageValidator.validationResult)
30
-
31
- const modelValidator = new LionWebValidator(jsonModel, registry)
32
- modelValidator.validateAll()
33
- console.log("===== Model errors ======")
34
- printIssues(modelValidator.validationResult)
35
- }
@@ -1,23 +0,0 @@
1
- import { LionWebJsonChunk } from "@lionweb/json"
2
- import { LionWebJsonDiff } from "@lionweb/json-diff"
3
- import fs from "fs"
4
-
5
- const file1 = process.argv[2]
6
- const file2 = process.argv[3]
7
-
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)
13
-
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
- } else {
19
- console.log("LionWebJsonDiff: " + lwDiff.diff)
20
- }
21
- } else {
22
- console.log("Error in arguments")
23
- }
@@ -1,54 +0,0 @@
1
- import fs from "fs"
2
- import path from "path"
3
- import { ValidationResult } from "../validators/generic/ValidationResult.js"
4
-
5
- export function getFilesRecursive(dirPath: string, arrayOfFiles: string[]) {
6
- const files = fs.readdirSync(dirPath)
7
- arrayOfFiles = arrayOfFiles || []
8
-
9
- files.forEach(function (file: string) {
10
- if (fs.statSync(dirPath + "/" + file).isDirectory()) {
11
- arrayOfFiles = getFilesRecursive(dirPath + "/" + file, arrayOfFiles)
12
- } else {
13
- arrayOfFiles.push(path.join(dirPath, "/", file))
14
- }
15
- })
16
- return arrayOfFiles
17
- }
18
-
19
- export function getFilesDirect(dirPath: string, arrayOfFiles: string[]) {
20
- const files = fs.readdirSync(dirPath)
21
- arrayOfFiles = arrayOfFiles || []
22
-
23
- files.forEach(function (file: string) {
24
- if (fs.statSync(dirPath + "/" + file).isFile()) {
25
- arrayOfFiles.push(file)
26
- }
27
- })
28
- return arrayOfFiles
29
- }
30
-
31
- export function getAllDirectories(dirPath: string, arrayOfDirs: string[]) {
32
- const files = fs.readdirSync(dirPath, { withFileTypes: true })
33
- arrayOfDirs = arrayOfDirs || []
34
-
35
- files.forEach(function (file: fs.Dirent) {
36
- if (file.isDirectory()) {
37
- arrayOfDirs = getAllDirectories(dirPath + "/" + file.name, arrayOfDirs)
38
- arrayOfDirs.push(path.join(dirPath, "/", file.name))
39
- } else {
40
- // ignore files
41
- }
42
- })
43
- return arrayOfDirs
44
- }
45
-
46
- export function printIssues(result: ValidationResult, file?: string): void {
47
- result.issues.forEach(issue => console.log((file == undefined ? "" : `File ${file}: `) + issue.errorMsg()))
48
- }
49
-
50
- export function issuestoString(vresult: ValidationResult, file?: string): string {
51
- let result = "ISSUES: "
52
- vresult.issues.forEach(issue => (result += (file === undefined ? "NOFILE" : `File ${file}: `) + issue.errorMsg() + "\n"))
53
- return result
54
- }
@@ -1,2 +0,0 @@
1
- export * from "./FileUtils.js"
2
- export * from "./Utils.js"
@@ -1,78 +0,0 @@
1
- import { isEqualMetaPointer, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
2
- import { isLionWebM3Language, JsonContext, LionWebJsonChunkWrapper, MetaPointers } from "@lionweb/json-utils"
3
- import { GenericIssue } from "../issues/index.js"
4
- import { MissingM3Language_Issue } from "../issues/LanguageIssues.js"
5
- import { isConcept, LanguageRegistry } from "../languages/index.js"
6
- import { ValidationResult } from "./generic/ValidationResult.js"
7
-
8
- /**
9
- * Validates whether a chunk is a valid language definition
10
- */
11
- export class LionWebLanguageValidator {
12
- validationResult: ValidationResult
13
- chunkWrapper: LionWebJsonChunkWrapper | undefined
14
- // availableLanguages: LionWebLanguageDefinition[] = []
15
-
16
- constructor(validationResult: ValidationResult, private registry: LanguageRegistry) {
17
- this.validationResult = validationResult
18
- this.chunkWrapper = undefined
19
- }
20
-
21
- /**
22
- * Check whether the metamodel is a Language.
23
- * Assumption is that _chunk_ is already validated as a correct :LionWebJsonChunk
24
- * @param chunk
25
- */
26
- validateLanguage(chunk: LionWebJsonChunk) {
27
- this.chunkWrapper = new LionWebJsonChunkWrapper(chunk)
28
- const usedM3Language = chunk.languages.find(lang => isLionWebM3Language(lang))
29
- if (usedM3Language === undefined) {
30
- this.validationResult.issue(new MissingM3Language_Issue(new JsonContext(null, ["languages"])))
31
- }
32
-
33
- const languageNodes = this.chunkWrapper.findNodesOfClassifier(MetaPointers.Language)
34
- if (languageNodes.length !== 1) {
35
- // TODO Better error handling.
36
- console.error("Error: xpected exactly one Language node, found " + languageNodes.length + " => " + JSON.stringify(languageNodes))
37
- }
38
- chunk.nodes.forEach((node, index) => {
39
- if (!isConcept(node)) {
40
- this.validationResult.issue(new GenericIssue(new JsonContext(null, ["nodes", index]), `node ${node.id} is not a concept`))
41
- } else {
42
- this.validateConcept(node)
43
- }
44
- })
45
- }
46
-
47
- validateConcept(node: LionWebJsonNode): void {
48
- node.properties.forEach(prop => {
49
- const properties = this.chunkWrapper?.findNodesOfClassifier(MetaPointers.Property)
50
- const matchedProperty = properties?.find(p => isEqualMetaPointer(p.classifier, prop.property))
51
- // DUMMY
52
- return matchedProperty !== undefined
53
- })
54
- }
55
-
56
- validateNode(node: LionWebJsonNode): void {
57
- const classifier = this.registry.getNodeByMetaPointer(node.classifier)
58
- if (classifier === undefined) {
59
- this.validationResult.issue(
60
- new GenericIssue(new JsonContext(null, ["nodes"]), `Classifier ${node.classifier.key} not found for node ${node.id}`)
61
- )
62
- return
63
- }
64
- this.validateProperties(node, classifier)
65
- }
66
-
67
- validateProperties(node: LionWebJsonNode, classifier: LionWebJsonNode): void {
68
- node.properties.forEach(actualProp => {
69
- const propClassifier = this.registry.getNodeByMetaPointer(actualProp.property)
70
- if (propClassifier === undefined) {
71
- this.validationResult.issue(
72
- new GenericIssue(new JsonContext(null, ["nodes", "properties"]),
73
- `Property ${actualProp.property.key} not found for classifier ${classifier.id}`)
74
- )
75
- }
76
- })
77
- }
78
- }
@@ -1,14 +0,0 @@
1
- import { SyntaxValidator } from "./generic/SyntaxValidator.js"
2
- import { ValidationResult } from "./generic/ValidationResult.js"
3
- import { LionWebSchema } from "./LionWebChunkDefinitions.js"
4
-
5
- /**
6
- * LionWebSyntaxValidator can check whether objects are structurally LionWeb objects.
7
- */
8
- export class LionWebSyntaxValidator extends SyntaxValidator {
9
-
10
- constructor(validationResult: ValidationResult) {
11
- super(validationResult, LionWebSchema)
12
- }
13
- }
14
-