@lionweb/validation 0.7.0 → 0.7.1

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 (139) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +5 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/issues/LanguageIssues.d.ts +99 -0
  6. package/dist/issues/LanguageIssues.d.ts.map +1 -0
  7. package/dist/issues/LanguageIssues.js +146 -0
  8. package/dist/issues/LanguageIssues.js.map +1 -0
  9. package/dist/issues/ReferenceIssues.d.ts +43 -0
  10. package/dist/issues/ReferenceIssues.d.ts.map +1 -0
  11. package/dist/issues/ReferenceIssues.js +53 -0
  12. package/dist/issues/ReferenceIssues.js.map +1 -0
  13. package/dist/issues/SyntaxIssues.d.ts +53 -0
  14. package/dist/issues/SyntaxIssues.d.ts.map +1 -0
  15. package/dist/issues/SyntaxIssues.js +81 -0
  16. package/dist/issues/SyntaxIssues.js.map +1 -0
  17. package/dist/issues/ValidationIssue.d.ts +15 -0
  18. package/dist/issues/ValidationIssue.d.ts.map +1 -0
  19. package/dist/issues/ValidationIssue.js +17 -0
  20. package/dist/issues/ValidationIssue.js.map +1 -0
  21. package/dist/issues/index.d.ts +5 -0
  22. package/dist/issues/index.d.ts.map +1 -0
  23. package/dist/issues/index.js +5 -0
  24. package/dist/issues/index.js.map +1 -0
  25. package/dist/languages/CompositeLionWebLanguageWrapper.d.ts +24 -0
  26. package/dist/languages/CompositeLionWebLanguageWrapper.d.ts.map +1 -0
  27. package/dist/languages/CompositeLionWebLanguageWrapper.js +56 -0
  28. package/dist/languages/CompositeLionWebLanguageWrapper.js.map +1 -0
  29. package/dist/languages/LanguageRegistry.d.ts +19 -0
  30. package/dist/languages/LanguageRegistry.d.ts.map +1 -0
  31. package/dist/languages/LanguageRegistry.js +37 -0
  32. package/dist/languages/LanguageRegistry.js.map +1 -0
  33. package/dist/languages/LanguageUtils.d.ts +35 -0
  34. package/dist/languages/LanguageUtils.d.ts.map +1 -0
  35. package/dist/languages/LanguageUtils.js +54 -0
  36. package/dist/languages/LanguageUtils.js.map +1 -0
  37. package/dist/languages/LionCore-M3.json +2356 -0
  38. package/dist/languages/LionCore-builtins.json +372 -0
  39. package/dist/languages/LionWebLanguageWrapper.d.ts +31 -0
  40. package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -0
  41. package/dist/languages/LionWebLanguageWrapper.js +69 -0
  42. package/dist/languages/LionWebLanguageWrapper.js.map +1 -0
  43. package/dist/languages/MetaPointerMap.d.ts +11 -0
  44. package/dist/languages/MetaPointerMap.d.ts.map +1 -0
  45. package/dist/languages/MetaPointerMap.js +39 -0
  46. package/dist/languages/MetaPointerMap.js.map +1 -0
  47. package/dist/languages/index.d.ts +3 -0
  48. package/dist/languages/index.d.ts.map +1 -0
  49. package/dist/languages/index.js +3 -0
  50. package/dist/languages/index.js.map +1 -0
  51. package/dist/runners/FileUtils.d.ts +6 -0
  52. package/dist/runners/FileUtils.d.ts.map +1 -0
  53. package/dist/runners/FileUtils.js +53 -0
  54. package/dist/runners/FileUtils.js.map +1 -0
  55. package/dist/runners/RunCheckFolder.d.ts +2 -0
  56. package/dist/runners/RunCheckFolder.d.ts.map +1 -0
  57. package/dist/runners/RunCheckFolder.js +6 -0
  58. package/dist/runners/RunCheckFolder.js.map +1 -0
  59. package/dist/runners/RunCheckFolderWithLanguage.d.ts +2 -0
  60. package/dist/runners/RunCheckFolderWithLanguage.d.ts.map +1 -0
  61. package/dist/runners/RunCheckFolderWithLanguage.js +40 -0
  62. package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -0
  63. package/dist/runners/RunCheckOneFile.d.ts +2 -0
  64. package/dist/runners/RunCheckOneFile.d.ts.map +1 -0
  65. package/dist/runners/RunCheckOneFile.js +6 -0
  66. package/dist/runners/RunCheckOneFile.js.map +1 -0
  67. package/dist/runners/RunCheckOneFileWithLanguage.d.ts +2 -0
  68. package/dist/runners/RunCheckOneFileWithLanguage.d.ts.map +1 -0
  69. package/dist/runners/RunCheckOneFileWithLanguage.js +31 -0
  70. package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -0
  71. package/dist/runners/RunLioncoreDiff.d.ts +2 -0
  72. package/dist/runners/RunLioncoreDiff.d.ts.map +1 -0
  73. package/dist/runners/RunLioncoreDiff.js +22 -0
  74. package/dist/runners/RunLioncoreDiff.js.map +1 -0
  75. package/dist/runners/Utils.d.ts +7 -0
  76. package/dist/runners/Utils.d.ts.map +1 -0
  77. package/dist/runners/Utils.js +48 -0
  78. package/dist/runners/Utils.js.map +1 -0
  79. package/dist/runners/index.d.ts +3 -0
  80. package/dist/runners/index.d.ts.map +1 -0
  81. package/dist/runners/index.js +3 -0
  82. package/dist/runners/index.js.map +1 -0
  83. package/dist/validators/LionWebChunkDefinitions.d.ts +9 -0
  84. package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -0
  85. package/dist/validators/LionWebChunkDefinitions.js +100 -0
  86. package/dist/validators/LionWebChunkDefinitions.js.map +1 -0
  87. package/dist/validators/LionWebLanguageReferenceValidator.d.ts +21 -0
  88. package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -0
  89. package/dist/validators/LionWebLanguageReferenceValidator.js +166 -0
  90. package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -0
  91. package/dist/validators/LionWebLanguageValidator.d.ts +23 -0
  92. package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -0
  93. package/dist/validators/LionWebLanguageValidator.js +67 -0
  94. package/dist/validators/LionWebLanguageValidator.js.map +1 -0
  95. package/dist/validators/LionWebReferenceValidator.d.ts +43 -0
  96. package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -0
  97. package/dist/validators/LionWebReferenceValidator.js +203 -0
  98. package/dist/validators/LionWebReferenceValidator.js.map +1 -0
  99. package/dist/validators/LionWebSyntaxValidator.d.ts +9 -0
  100. package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -0
  101. package/dist/validators/LionWebSyntaxValidator.js +11 -0
  102. package/dist/validators/LionWebSyntaxValidator.js.map +1 -0
  103. package/dist/validators/LionWebValidator.d.ts +24 -0
  104. package/dist/validators/LionWebValidator.d.ts.map +1 -0
  105. package/dist/validators/LionWebValidator.js +55 -0
  106. package/dist/validators/LionWebValidator.js.map +1 -0
  107. package/dist/validators/ValidationFunctions.d.ts +60 -0
  108. package/dist/validators/ValidationFunctions.d.ts.map +1 -0
  109. package/dist/validators/ValidationFunctions.js +104 -0
  110. package/dist/validators/ValidationFunctions.js.map +1 -0
  111. package/dist/validators/generic/SyntaxValidator.d.ts +37 -0
  112. package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -0
  113. package/dist/validators/generic/SyntaxValidator.js +152 -0
  114. package/dist/validators/generic/SyntaxValidator.js.map +1 -0
  115. package/dist/validators/generic/ValidationResult.d.ts +8 -0
  116. package/dist/validators/generic/ValidationResult.d.ts.map +1 -0
  117. package/dist/validators/generic/ValidationResult.js +15 -0
  118. package/dist/validators/generic/ValidationResult.js.map +1 -0
  119. package/dist/validators/generic/index.d.ts +4 -0
  120. package/dist/validators/generic/index.d.ts.map +1 -0
  121. package/dist/validators/generic/index.js +4 -0
  122. package/dist/validators/generic/index.js.map +1 -0
  123. package/dist/validators/generic/schema/DefinitionSchema.d.ts +23 -0
  124. package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +1 -0
  125. package/dist/validators/generic/schema/DefinitionSchema.js +43 -0
  126. package/dist/validators/generic/schema/DefinitionSchema.js.map +1 -0
  127. package/dist/validators/generic/schema/ValidationTypes.d.ts +101 -0
  128. package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
  129. package/dist/validators/generic/schema/ValidationTypes.js +43 -0
  130. package/dist/validators/generic/schema/ValidationTypes.js.map +1 -0
  131. package/dist/validators/generic/schema/index.d.ts +3 -0
  132. package/dist/validators/generic/schema/index.d.ts.map +1 -0
  133. package/dist/validators/generic/schema/index.js +3 -0
  134. package/dist/validators/generic/schema/index.js.map +1 -0
  135. package/dist/validators/index.d.ts +9 -0
  136. package/dist/validators/index.d.ts.map +1 -0
  137. package/dist/validators/index.js +9 -0
  138. package/dist/validators/index.js.map +1 -0
  139. package/package.json +11 -7
@@ -0,0 +1,67 @@
1
+ import { isEqualMetaPointer } from "@lionweb/json";
2
+ import { isLionWebM3Language, JsonContext, LionWebJsonChunkWrapper, MetaPointers } from "@lionweb/json-utils";
3
+ import { asMinimalJsonString } from "@lionweb/ts-utils";
4
+ import { GenericIssue } from "../issues/index.js";
5
+ import { MissingM3Language_Issue } from "../issues/LanguageIssues.js";
6
+ import { isConcept } from "../languages/index.js";
7
+ /**
8
+ * Validates whether a chunk is a valid language definition
9
+ */
10
+ export class LionWebLanguageValidator {
11
+ // availableLanguages: LionWebLanguageDefinition[] = []
12
+ constructor(validationResult, registry) {
13
+ this.registry = registry;
14
+ this.validationResult = validationResult;
15
+ this.chunkWrapper = undefined;
16
+ }
17
+ /**
18
+ * Check whether the metamodel is a Language.
19
+ * Assumption is that _chunk_ is already validated as a correct :LionWebJsonChunk
20
+ * @param chunk
21
+ */
22
+ validateLanguage(chunk) {
23
+ this.chunkWrapper = new LionWebJsonChunkWrapper(chunk);
24
+ const usedM3Language = chunk.languages.find(lang => isLionWebM3Language(lang));
25
+ if (usedM3Language === undefined) {
26
+ this.validationResult.issue(new MissingM3Language_Issue(new JsonContext(null, ["languages"])));
27
+ }
28
+ const languageNodes = this.chunkWrapper.findNodesOfClassifier(MetaPointers.Language);
29
+ if (languageNodes.length !== 1) {
30
+ // TODO Better error handling.
31
+ console.error("Error: xpected exactly one Language node, found " + languageNodes.length + " => " + asMinimalJsonString(languageNodes));
32
+ }
33
+ chunk.nodes.forEach((node, index) => {
34
+ if (!isConcept(node)) {
35
+ this.validationResult.issue(new GenericIssue(new JsonContext(null, ["nodes", index]), `node ${node.id} is not a concept`));
36
+ }
37
+ else {
38
+ this.validateConcept(node);
39
+ }
40
+ });
41
+ }
42
+ validateConcept(node) {
43
+ node.properties.forEach(prop => {
44
+ const properties = this.chunkWrapper?.findNodesOfClassifier(MetaPointers.Property);
45
+ const matchedProperty = properties?.find(p => isEqualMetaPointer(p.classifier, prop.property));
46
+ // DUMMY
47
+ return matchedProperty !== undefined;
48
+ });
49
+ }
50
+ validateNode(node) {
51
+ const classifier = this.registry.getNodeByMetaPointer(node.classifier);
52
+ if (classifier === undefined) {
53
+ this.validationResult.issue(new GenericIssue(new JsonContext(null, ["nodes"]), `Classifier ${node.classifier.key} not found for node ${node.id}`));
54
+ return;
55
+ }
56
+ this.validateProperties(node, classifier);
57
+ }
58
+ validateProperties(node, classifier) {
59
+ node.properties.forEach(actualProp => {
60
+ const propClassifier = this.registry.getNodeByMetaPointer(actualProp.property);
61
+ if (propClassifier === undefined) {
62
+ this.validationResult.issue(new GenericIssue(new JsonContext(null, ["nodes", "properties"]), `Property ${actualProp.property.key} not found for classifier ${classifier.id}`));
63
+ }
64
+ });
65
+ }
66
+ }
67
+ //# sourceMappingURL=LionWebLanguageValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebLanguageValidator.js","sourceRoot":"","sources":["../../src/validators/LionWebLanguageValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAqC,MAAM,eAAe,CAAA;AACrF,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC7G,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACrE,OAAO,EAAE,SAAS,EAAoB,MAAM,uBAAuB,CAAA;AAGnE;;GAEG;AACH,MAAM,OAAO,wBAAwB;IAGjC,uDAAuD;IAEvD,YAAY,gBAAkC,EAAU,QAA0B;QAA1B,aAAQ,GAAR,QAAQ,CAAkB;QAC9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AI,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,EAC3D,YAAY,UAAU,CAAC,QAAQ,CAAC,GAAG,6BAA6B,UAAU,CAAC,EAAE,EAAE,CAAC,CACvF,CAAA;YACL,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ"}
@@ -0,0 +1,43 @@
1
+ import { LionWebJsonChunk, LionWebJsonMetaPointer, LionWebJsonNode, LionWebJsonUsedLanguage } from "@lionweb/json";
2
+ import { JsonContext, LionWebJsonChunkWrapper } from "@lionweb/json-utils";
3
+ import { ValidationResult } from "./generic/ValidationResult.js";
4
+ /**
5
+ * Assuming that the syntax is correct, check whether all LionWeb references are correct,
6
+ * as far as they do not need the used language definition.
7
+ */
8
+ export declare class LionWebReferenceValidator {
9
+ validationResult: ValidationResult;
10
+ nodesIdMap: Map<string, LionWebJsonNode>;
11
+ constructor(validationResult: ValidationResult);
12
+ validateNodeIds(obj: LionWebJsonChunk, ctx: JsonContext): void;
13
+ validate(obj: LionWebJsonChunkWrapper): void;
14
+ /**
15
+ * Check whether the metapointer refers to a language defined in the usedLanguages of chunk.
16
+ * @param chunk
17
+ * @param metaPointer
18
+ * @param context
19
+ */
20
+ validateLanguageReference(chunk: LionWebJsonChunkWrapper, metaPointer: LionWebJsonMetaPointer, context: JsonContext): void;
21
+ /**
22
+ * Check whether there are duplicate values in `strings`.
23
+ * @param strings
24
+ * @param context
25
+ */
26
+ checkDuplicate(strings: string[], context: JsonContext): void;
27
+ /**
28
+ * Checks whether there are duplicate usedLanguages in `usedLanguages`.
29
+ * usedLanguages are considered equal when bith their `key` and `version` are identical.
30
+ * @param usedLanguages
31
+ * @param context
32
+ */
33
+ checkDuplicateUsedLanguage(usedLanguages: LionWebJsonUsedLanguage[], context: JsonContext): void;
34
+ /**
35
+ * Checks whether the parent of node recursively points to `node` itself.
36
+ * @param node The noide being checked
37
+ * @param context The location in the JSON
38
+ */
39
+ checkParentCircular(node: LionWebJsonNode, context: JsonContext): void;
40
+ validateExistsAsChild(context: JsonContext, parent: LionWebJsonNode | undefined, child: LionWebJsonNode): void;
41
+ validateChildrenHaveCorrectParent(node: LionWebJsonNode, context: JsonContext): void;
42
+ }
43
+ //# sourceMappingURL=LionWebReferenceValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebReferenceValidator.d.ts","sourceRoot":"","sources":["../../src/validators/LionWebReferenceValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,gBAAgB,EAA0B,sBAAsB,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAA;AACrJ,OAAO,EAAc,WAAW,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAStF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAEhE;;;GAGG;AACH,qBAAa,yBAAyB;IAClC,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAqC;gBAEjE,gBAAgB,EAAE,gBAAgB;IAI9C,eAAe,CAAC,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI;IAW9D,QAAQ,CAAC,GAAG,EAAE,uBAAuB,GAAG,IAAI;IAqD5C;;;;;OAKG;IACH,yBAAyB,CAAC,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW;IAWnH;;;;OAIG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,WAAW;IActD;;;;;OAKG;IACH,0BAA0B,CAAC,aAAa,EAAE,uBAAuB,EAAE,EAAE,OAAO,EAAE,WAAW;IAiBzF;;;;OAIG;IACH,mBAAmB,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW;IAsB/D,qBAAqB,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,eAAe,GAAG,SAAS,EAAE,KAAK,EAAE,eAAe;IAevG,iCAAiC,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW;CAmChF"}
@@ -0,0 +1,203 @@
1
+ import { ChunkUtils, JsonContext } from "@lionweb/json-utils";
2
+ import { Duplicates_Issue, Reference_ChildMissingInParent_Issue, Reference_CirculairParent_Issue, Reference_DuplicateNodeId_Issue, Reference_LanguageUnknown_Issue, Reference_ParentMissingInChild_Issue } from "../issues/ReferenceIssues.js";
3
+ /**
4
+ * Assuming that the syntax is correct, check whether all LionWeb references are correct,
5
+ * as far as they do not need the used language definition.
6
+ */
7
+ export class LionWebReferenceValidator {
8
+ constructor(validationResult) {
9
+ this.nodesIdMap = new Map();
10
+ this.validationResult = validationResult;
11
+ }
12
+ validateNodeIds(obj, ctx) {
13
+ // put all nodes in a map, validate that there are no two nodes with the same id.
14
+ obj.nodes.forEach((node, index) => {
15
+ // this.validationResult.check(this.nodesIdMap.get(node.id) === undefined, `Node number ${index} has duplicate id "${node.id}"`);
16
+ if (!(this.nodesIdMap.get(node.id) === undefined)) {
17
+ this.validationResult.issue(new Reference_DuplicateNodeId_Issue(ctx.concat("nodes", index), node.id));
18
+ }
19
+ this.nodesIdMap.set(node.id, node);
20
+ });
21
+ }
22
+ validate(obj) {
23
+ const rootCtx = new JsonContext(null, ["$"]);
24
+ this.checkDuplicateUsedLanguage(obj.jsonChunk.languages, rootCtx);
25
+ this.validateNodeIds(obj.jsonChunk, rootCtx);
26
+ obj.jsonChunk.nodes.forEach((node, nodeIndex) => {
27
+ const context = rootCtx.concat(`node`, nodeIndex);
28
+ const parentNode = node.parent;
29
+ if (parentNode !== null) {
30
+ this.validateExistsAsChild(context, this.nodesIdMap.get(parentNode), node);
31
+ }
32
+ this.validateLanguageReference(obj, node.classifier, context);
33
+ this.checkParentCircular(node, context);
34
+ this.checkDuplicate(node.annotations, rootCtx.concat("node", nodeIndex, "annotations"));
35
+ this.validateChildrenHaveCorrectParent(node, rootCtx.concat("node", nodeIndex));
36
+ node.properties.forEach((prop, propertyIndex) => {
37
+ this.validateLanguageReference(obj, prop.property, rootCtx.concat("node", nodeIndex, "property", propertyIndex));
38
+ });
39
+ node.containments.forEach((containment, childIndex) => {
40
+ this.validateLanguageReference(obj, containment.containment, rootCtx.concat("node", nodeIndex, "containments", childIndex));
41
+ this.checkDuplicate(containment.children, rootCtx.concat("node", nodeIndex, "containments", childIndex));
42
+ containment.children.forEach(childId => {
43
+ const childNode = this.nodesIdMap.get(childId);
44
+ if (childNode !== undefined) {
45
+ if (childNode.parent !== null && childNode.parent !== undefined && childNode.parent !== node.id) {
46
+ this.validationResult.issue(new Reference_ParentMissingInChild_Issue(context, node, childNode));
47
+ // TODO this.validationResult.error(`Child "${childId}" with parent "${childNode.parent}" is defined as child in node "${node.id}"`);
48
+ }
49
+ if (childNode.parent === null || childNode.parent === undefined) {
50
+ // TODO this.validationResult.error(`Child "${childId}" of node "${node.id}" has different parent "${childNode.parent}"`);
51
+ }
52
+ }
53
+ });
54
+ });
55
+ node.annotations.forEach(annotationId => {
56
+ const annotation = this.nodesIdMap.get(annotationId);
57
+ if (annotation !== undefined) {
58
+ if (annotation.parent !== null && annotation.parent !== undefined && annotation.parent !== node.id) {
59
+ this.validationResult.issue(new Reference_ParentMissingInChild_Issue(context, node, annotation));
60
+ // TODO this.validationResult.error(`Child "${annotationId}" with parent "${childNode.parent}" is defined as child in node "${node.id}"`);
61
+ }
62
+ if (annotation.parent === null || annotation.parent === undefined) {
63
+ // TODO this.validationResult.error(`Child "${annotationId}" of node "${node.id}" has different parent "${childNode.parent}"`);
64
+ }
65
+ }
66
+ });
67
+ node.references.forEach((ref, refIndex) => {
68
+ this.validateLanguageReference(obj, ref.reference, rootCtx.concat("node", nodeIndex, "references", refIndex));
69
+ // TODO Check for duplicate targets?
70
+ // If so, what to check because there can be either or both a `resolveInfo` and a `reference`
71
+ });
72
+ });
73
+ }
74
+ /**
75
+ * Check whether the metapointer refers to a language defined in the usedLanguages of chunk.
76
+ * @param chunk
77
+ * @param metaPointer
78
+ * @param context
79
+ */
80
+ validateLanguageReference(chunk, metaPointer, context) {
81
+ const lang = ChunkUtils.findLwUsedLanguageWithVersion(chunk.jsonChunk, metaPointer.language, metaPointer.version);
82
+ if (lang === undefined || lang === null) {
83
+ this.validationResult.issue(new Reference_LanguageUnknown_Issue(context, metaPointer));
84
+ }
85
+ else {
86
+ if (lang.version !== metaPointer.version) {
87
+ this.validationResult.issue(new Reference_LanguageUnknown_Issue(context, metaPointer));
88
+ }
89
+ }
90
+ }
91
+ /**
92
+ * Check whether there are duplicate values in `strings`.
93
+ * @param strings
94
+ * @param context
95
+ */
96
+ checkDuplicate(strings, context) {
97
+ if (strings === null || strings === undefined) {
98
+ return;
99
+ }
100
+ const alreadySeen = {};
101
+ strings.forEach(str => {
102
+ if (alreadySeen[str]) {
103
+ this.validationResult.issue(new Duplicates_Issue(context, str));
104
+ }
105
+ else {
106
+ alreadySeen[str] = true;
107
+ }
108
+ });
109
+ }
110
+ /**
111
+ * Checks whether there are duplicate usedLanguages in `usedLanguages`.
112
+ * usedLanguages are considered equal when bith their `key` and `version` are identical.
113
+ * @param usedLanguages
114
+ * @param context
115
+ */
116
+ checkDuplicateUsedLanguage(usedLanguages, context) {
117
+ if (usedLanguages === null || usedLanguages === undefined) {
118
+ return;
119
+ }
120
+ const alreadySeen = new Map();
121
+ usedLanguages.forEach((usedLanguage, index) => {
122
+ const seenKeys = alreadySeen.get(usedLanguage.key);
123
+ if (seenKeys !== null && seenKeys !== undefined) {
124
+ if (seenKeys.includes(usedLanguage.version)) {
125
+ this.validationResult.issue(new Duplicates_Issue(context.concat("language", index, "version"), usedLanguage.version));
126
+ }
127
+ }
128
+ else {
129
+ alreadySeen.set(usedLanguage.key, [usedLanguage.version]);
130
+ }
131
+ });
132
+ }
133
+ /**
134
+ * Checks whether the parent of node recursively points to `node` itself.
135
+ * @param node The noide being checked
136
+ * @param context The location in the JSON
137
+ */
138
+ checkParentCircular(node, context) {
139
+ if (node === null || node === undefined) {
140
+ return;
141
+ }
142
+ if (node.parent === null || node.parent === undefined) {
143
+ return;
144
+ }
145
+ let current = node;
146
+ const seenParents = [node.id];
147
+ while (current !== null && current !== undefined && current.parent !== null && current.parent !== undefined) {
148
+ const nextParent = current.parent;
149
+ if (nextParent !== null && nextParent !== undefined && seenParents.includes(nextParent)) {
150
+ this.validationResult.issue(new Reference_CirculairParent_Issue(context.concat("???"), this.nodesIdMap.get(nextParent), seenParents));
151
+ return;
152
+ }
153
+ seenParents.push(nextParent);
154
+ current = this.nodesIdMap.get(nextParent);
155
+ }
156
+ }
157
+ validateExistsAsChild(context, parent, child) {
158
+ if (parent === undefined || parent === null) {
159
+ return;
160
+ }
161
+ for (const containment of parent.containments) {
162
+ if (containment.children.includes(child.id)) {
163
+ return;
164
+ }
165
+ }
166
+ if (parent.annotations.includes(child.id)) {
167
+ return;
168
+ }
169
+ this.validationResult.issue(new Reference_ChildMissingInParent_Issue(context, child, parent));
170
+ }
171
+ validateChildrenHaveCorrectParent(node, context) {
172
+ node.containments.forEach((child) => {
173
+ child.children.forEach((childId, index) => {
174
+ const childNode = this.nodesIdMap.get(childId);
175
+ if (childNode !== undefined) {
176
+ if (childNode.parent !== node.id) {
177
+ // TODO Check that this is already tested from the child in vaidateExistsAsChild().
178
+ }
179
+ if (childNode.parent === null || childNode.parent === undefined) {
180
+ this.validationResult.issue(new Reference_ParentMissingInChild_Issue(context.concat("child", "containment", "key", index), node, childNode));
181
+ }
182
+ }
183
+ });
184
+ });
185
+ node.annotations.forEach((annotationId, annotationIndex) => {
186
+ const childNode = this.nodesIdMap.get(annotationId);
187
+ if (childNode !== undefined) {
188
+ if (childNode.parent === null || childNode.parent === undefined) {
189
+ this.validationResult.issue(new Reference_ParentMissingInChild_Issue(context.concat("annotations", annotationIndex), node, childNode));
190
+ }
191
+ }
192
+ });
193
+ // for (const childId of NodeUtils.allChildren(node)) {
194
+ // const childNode = this.nodesIdMap.get(childId);
195
+ // if (childNode !== undefined) {
196
+ // if (childNode.parent !== node.id) {
197
+ // this.validationResult.error(`QQ Parent of child "${childId}" is "${childNode.parent}", but should be "${node.id}" in ${context}`);
198
+ // }
199
+ // }
200
+ // }
201
+ }
202
+ }
203
+ //# sourceMappingURL=LionWebReferenceValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebReferenceValidator.js","sourceRoot":"","sources":["../../src/validators/LionWebReferenceValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,WAAW,EAA2B,MAAM,qBAAqB,CAAA;AACtF,OAAO,EACH,gBAAgB,EAChB,oCAAoC,EACpC,+BAA+B,EAC/B,+BAA+B,EAC/B,+BAA+B,EAC/B,oCAAoC,EACvC,MAAM,8BAA8B,CAAA;AAGrC;;;GAGG;AACH,MAAM,OAAO,yBAAyB;IAIlC,YAAY,gBAAkC;QAF9C,eAAU,GAAiC,IAAI,GAAG,EAA2B,CAAA;QAGzE,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC5C,CAAC;IAED,eAAe,CAAC,GAAqB,EAAE,GAAgB;QACnD,iFAAiF;QACjF,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC9B,iIAAiI;YACjI,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,SAAS,CAAC,EAAE,CAAC;gBAChD,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,+BAA+B,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YACzG,CAAC;YACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QACtC,CAAC,CAAC,CAAA;IACN,CAAC;IAED,QAAQ,CAAC,GAA4B;QACjC,MAAM,OAAO,GAAG,IAAI,WAAW,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BACL,CAAC;gBACL,CAAC;YACL,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,YAAuB,EAAE,eAAuB,EAAE,EAAE;YAC1E,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;YACnD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,SAAS,CAAC,MAAM,KAAK,IAAI,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;oBAC9D,IAAI,CAAC,gBAAgB,CAAC,KAAK,CACvB,IAAI,oCAAoC,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAC5G,CAAA;gBACL,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAA;QACF,uDAAuD;QACvD,sDAAsD;QACtD,qCAAqC;QACrC,8CAA8C;QAC9C,iJAAiJ;QACjJ,YAAY;QACZ,QAAQ;QACR,IAAI;IACR,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import { SyntaxValidator } from "./generic/SyntaxValidator.js";
2
+ import { ValidationResult } from "./generic/ValidationResult.js";
3
+ /**
4
+ * LionWebSyntaxValidator can check whether objects are structurally LionWeb objects.
5
+ */
6
+ export declare class LionWebSyntaxValidator extends SyntaxValidator {
7
+ constructor(validationResult: ValidationResult);
8
+ }
9
+ //# sourceMappingURL=LionWebSyntaxValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebSyntaxValidator.d.ts","sourceRoot":"","sources":["../../src/validators/LionWebSyntaxValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAGhE;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,eAAe;gBAE3C,gBAAgB,EAAE,gBAAgB;CAGjD"}
@@ -0,0 +1,11 @@
1
+ import { SyntaxValidator } from "./generic/SyntaxValidator.js";
2
+ import { LionWebSchema } from "./LionWebChunkDefinitions.js";
3
+ /**
4
+ * LionWebSyntaxValidator can check whether objects are structurally LionWeb objects.
5
+ */
6
+ export class LionWebSyntaxValidator extends SyntaxValidator {
7
+ constructor(validationResult) {
8
+ super(validationResult, LionWebSchema);
9
+ }
10
+ }
11
+ //# sourceMappingURL=LionWebSyntaxValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebSyntaxValidator.js","sourceRoot":"","sources":["../../src/validators/LionWebSyntaxValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,eAAe;IAEvD,YAAY,gBAAkC;QAC1C,KAAK,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA;IAC1C,CAAC;CACJ"}
@@ -0,0 +1,24 @@
1
+ import { LanguageRegistry } from "../languages/index.js";
2
+ import { ValidationResult } from "./generic/ValidationResult.js";
3
+ import { LionWebReferenceValidator } from "./LionWebReferenceValidator.js";
4
+ import { LionWebSyntaxValidator } from "./LionWebSyntaxValidator.js";
5
+ /**
6
+ * Combined validator that calls all available validators.
7
+ * Will stop when one validator fails.
8
+ */
9
+ export declare class LionWebValidator {
10
+ private registry;
11
+ object: unknown;
12
+ chunk: unknown;
13
+ validationResult: ValidationResult;
14
+ syntaxValidator: LionWebSyntaxValidator;
15
+ referenceValidator: LionWebReferenceValidator;
16
+ syntaxCorrect: boolean;
17
+ referencesCorrect: boolean;
18
+ constructor(json: unknown, registry: LanguageRegistry);
19
+ validateAll(): void;
20
+ validateSyntax(): void;
21
+ validateReferences(): void;
22
+ validateForLanguage(): void;
23
+ }
24
+ //# sourceMappingURL=LionWebValidator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebValidator.d.ts","sourceRoot":"","sources":["../../src/validators/LionWebValidator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAEpE;;;GAGG;AACH,qBAAa,gBAAgB;IAUE,OAAO,CAAC,QAAQ;IAT3C,MAAM,EAAE,OAAO,CAAA;IAEf,KAAK,EAAE,OAAO,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,eAAe,EAAE,sBAAsB,CAAA;IACvC,kBAAkB,EAAE,yBAAyB,CAAA;IAC7C,aAAa,EAAE,OAAO,CAAQ;IAC9B,iBAAiB,EAAE,OAAO,CAAQ;gBAEtB,IAAI,EAAE,OAAO,EAAU,QAAQ,EAAE,gBAAgB;IAO7D,WAAW;IAMX,cAAc;IAQd,kBAAkB,IAAI,IAAI;IAU1B,mBAAmB,IAAI,IAAI;CAiB9B"}
@@ -0,0 +1,55 @@
1
+ import { LionWebJsonChunkWrapper } from "@lionweb/json-utils";
2
+ import { ValidationResult } from "./generic/ValidationResult.js";
3
+ import { LionWebLanguageReferenceValidator } from "./LionWebLanguageReferenceValidator.js";
4
+ import { LionWebReferenceValidator } from "./LionWebReferenceValidator.js";
5
+ import { LionWebSyntaxValidator } from "./LionWebSyntaxValidator.js";
6
+ /**
7
+ * Combined validator that calls all available validators.
8
+ * Will stop when one validator fails.
9
+ */
10
+ export class LionWebValidator {
11
+ constructor(json, registry) {
12
+ this.registry = registry;
13
+ this.syntaxCorrect = false;
14
+ this.referencesCorrect = false;
15
+ this.object = json;
16
+ this.validationResult = new ValidationResult();
17
+ this.syntaxValidator = new LionWebSyntaxValidator(this.validationResult);
18
+ this.referenceValidator = new LionWebReferenceValidator(this.validationResult);
19
+ }
20
+ validateAll() {
21
+ this.validateSyntax();
22
+ this.validateReferences();
23
+ this.validateForLanguage();
24
+ }
25
+ validateSyntax() {
26
+ this.syntaxValidator.validate(this.object, "LionWebJsonChunk");
27
+ this.syntaxCorrect = !this.validationResult.hasErrors();
28
+ if (this.syntaxCorrect) {
29
+ this.chunk = new LionWebJsonChunkWrapper(this.object);
30
+ }
31
+ }
32
+ validateReferences() {
33
+ if (!this.syntaxCorrect) {
34
+ // console.log("validateReferences not executed because there are syntax errors.")
35
+ return;
36
+ }
37
+ // when syntax is correct we know the chunk is actually a chunk!
38
+ this.referenceValidator.validate(this.chunk);
39
+ this.referencesCorrect = !this.validationResult.hasErrors();
40
+ }
41
+ validateForLanguage() {
42
+ if (!this.syntaxCorrect) {
43
+ // console.log("validateForLanguage not executed because there are syntax errors.")
44
+ return;
45
+ }
46
+ if (!this.referencesCorrect) {
47
+ // console.log("validateForLanguage not executed because there are reference errors.")
48
+ return;
49
+ }
50
+ const languageReferenceValidator = new LionWebLanguageReferenceValidator(this.validationResult, this.registry);
51
+ // when syntax is correct we know the chunk is actually a chunk!
52
+ languageReferenceValidator.validate(this.chunk);
53
+ }
54
+ }
55
+ //# sourceMappingURL=LionWebValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LionWebValidator.js","sourceRoot":"","sources":["../../src/validators/LionWebValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAA;AAC1F,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAA;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAEpE;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAUzB,YAAY,IA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AM;QACV,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC1B,sFAAsF;YACtF,OAAM;QACV,CAAC;QACD,MAAM,0BAA0B,GAAG,IAAI,iCAAiC,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC9G,gEAAgE;QAChE,0BAA0B,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAA;IAC9E,CAAC;CAKJ"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * A list of functions that are used to validate primitive fields for LionWeb conformance.
3
+ * Used in the LionWebSyntaxValidator.
4
+ */
5
+ import { JsonContext } from "@lionweb/json-utils";
6
+ import { ValidationResult } from "./generic/ValidationResult.js";
7
+ import { PropertyDefinition } from "./generic/schema/ValidationTypes.js";
8
+ /**
9
+ * Check whether `id` is a valid LionWeb id.
10
+ * @param value The `value` to be checked.
11
+ * @param result Any validation issues found will be put into this object.
12
+ * @param context The context for the error message in errors.
13
+ */
14
+ export declare function validateId<String>(value: String, result: ValidationResult, context: JsonContext): void;
15
+ /**
16
+ * Check whether `key` is a valid LionWeb key.
17
+ * @param value The `key` to be checked.
18
+ * @param result Any validation issues found will be put into this object.
19
+ * @param context The context for the error message in errors.
20
+ */
21
+ export declare function validateKey<String>(value: String, result: ValidationResult, context: JsonContext): void;
22
+ /**
23
+ * Check whether `version` is a valid LionWeb version.
24
+ * @param value The version to be checked
25
+ * @param result Any validation issues found will be put into this object.
26
+ * @param context The location in the overall JSON.
27
+ */
28
+ export declare function validateVersion<String>(value: String, result: ValidationResult, context: JsonContext): void;
29
+ /**
30
+ * Check whether the string `value` represents a LionWeb boolean, its value should be "true" or "false".
31
+ * @param value The value to be checked
32
+ * @param result Any validation issues found will be put into this object.
33
+ * @param context The location in the overall JSON.
34
+ * @param propDef The PropertyDefinition for this value
35
+ */
36
+ export declare function validateBoolean<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void;
37
+ /**
38
+ * Check whether the string `value` represents a LionWeb integer
39
+ * @param value The value to be checked
40
+ * @param result Any validation issues found will be put into this object.
41
+ * @param context The location in the overall JSON.
42
+ * @param propDef The PropertyDefinition for this value
43
+ */
44
+ export declare function validateInteger<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void;
45
+ /**
46
+ * Check whether the string `value` represents a LionWeb Json.
47
+ * @param value The value to be checked
48
+ * @param result Any validation issues found will be put into this object.
49
+ * @param context The location in the overall JSON.
50
+ * @param propDef The PropertyDefinition for this value
51
+ */
52
+ export declare function validateJSON<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void;
53
+ /**
54
+ * Check whether the string `value` is a correct LionWeb serializationFormatVersion.
55
+ * @param value
56
+ * @param result
57
+ * @param context
58
+ */
59
+ export declare function validateSerializationFormatVersion<String>(value: String, result: ValidationResult, context: JsonContext): void;
60
+ //# sourceMappingURL=ValidationFunctions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationFunctions.d.ts","sourceRoot":"","sources":["../../src/validators/ValidationFunctions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAUjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AAExE;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAMtG;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAMvG;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAK3G;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAYzI;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAMzI;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAUtI;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,CAS9H"}
@@ -0,0 +1,104 @@
1
+ import { asMinimalJsonString } from "@lionweb/ts-utils";
2
+ import { Language_PropertyValue_Issue } from "../issues/LanguageIssues.js";
3
+ import { Syntax_IdFormat_Issue, Syntax_KeyFormat_Issue, Syntax_PropertyNullIssue, Syntax_SerializationFormatVersion_Issue, Syntax_VersionFormat_Issue } from "../issues/SyntaxIssues.js";
4
+ /**
5
+ * Check whether `id` is a valid LionWeb id.
6
+ * @param value The `value` to be checked.
7
+ * @param result Any validation issues found will be put into this object.
8
+ * @param context The context for the error message in errors.
9
+ */
10
+ export function validateId(value, result, context) {
11
+ const idString = "" + value;
12
+ const regexp = /^[a-zA-Z0-9_-][a-zA-Z0-9_-]*$/;
13
+ if (!regexp.test(idString)) {
14
+ result.issue(new Syntax_IdFormat_Issue(context, idString));
15
+ }
16
+ }
17
+ /**
18
+ * Check whether `key` is a valid LionWeb key.
19
+ * @param value The `key` to be checked.
20
+ * @param result Any validation issues found will be put into this object.
21
+ * @param context The context for the error message in errors.
22
+ */
23
+ export function validateKey(value, result, context) {
24
+ const keyString = "" + value;
25
+ const regexp = /^[a-zA-Z0-9_-][a-zA-Z0-9_-]*$/;
26
+ if (!regexp.test(keyString)) {
27
+ result.issue(new Syntax_KeyFormat_Issue(context, keyString));
28
+ }
29
+ }
30
+ /**
31
+ * Check whether `version` is a valid LionWeb version.
32
+ * @param value The version to be checked
33
+ * @param result Any validation issues found will be put into this object.
34
+ * @param context The location in the overall JSON.
35
+ */
36
+ export function validateVersion(value, result, context) {
37
+ const versionString = "" + value;
38
+ if (versionString.length === 0) {
39
+ result.issue(new Syntax_VersionFormat_Issue(context, versionString));
40
+ }
41
+ }
42
+ /**
43
+ * Check whether the string `value` represents a LionWeb boolean, its value should be "true" or "false".
44
+ * @param value The value to be checked
45
+ * @param result Any validation issues found will be put into this object.
46
+ * @param context The location in the overall JSON.
47
+ * @param propDef The PropertyDefinition for this value
48
+ */
49
+ export function validateBoolean(value, result, context, propDef) {
50
+ const valueAsPrimitive = "" + value;
51
+ if (valueAsPrimitive !== "true" && valueAsPrimitive !== "false") {
52
+ result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "boolean " + asMinimalJsonString(value)));
53
+ }
54
+ }
55
+ /**
56
+ * Check whether the string `value` represents a LionWeb integer
57
+ * @param value The value to be checked
58
+ * @param result Any validation issues found will be put into this object.
59
+ * @param context The location in the overall JSON.
60
+ * @param propDef The PropertyDefinition for this value
61
+ */
62
+ export function validateInteger(value, result, context, propDef) {
63
+ const valueAsPrimitive = "" + value;
64
+ const regexp = /^[+-]?(0|[1-9][0-9]*)$/;
65
+ if (valueAsPrimitive === null || !regexp.test(valueAsPrimitive)) {
66
+ result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "integer"));
67
+ }
68
+ }
69
+ /**
70
+ * Check whether the string `value` represents a LionWeb Json.
71
+ * @param value The value to be checked
72
+ * @param result Any validation issues found will be put into this object.
73
+ * @param context The location in the overall JSON.
74
+ * @param propDef The PropertyDefinition for this value
75
+ */
76
+ export function validateJSON(value, result, context, propDef) {
77
+ const valueAsPrimitive = "" + value;
78
+ if (value === null) {
79
+ result.issue(new Syntax_PropertyNullIssue(context, propDef.name));
80
+ }
81
+ try {
82
+ JSON.parse(valueAsPrimitive);
83
+ }
84
+ catch (_) {
85
+ result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "JSON"));
86
+ }
87
+ }
88
+ /**
89
+ * Check whether the string `value` is a correct LionWeb serializationFormatVersion.
90
+ * @param value
91
+ * @param result
92
+ * @param context
93
+ */
94
+ export function validateSerializationFormatVersion(value, result, context) {
95
+ if (typeof value !== "string") {
96
+ result.issue(new Syntax_SerializationFormatVersion_Issue(context, asMinimalJsonString(value)));
97
+ return;
98
+ }
99
+ if (value.length === 0) {
100
+ result.issue(new Syntax_SerializationFormatVersion_Issue(context, value));
101
+ return;
102
+ }
103
+ }
104
+ //# sourceMappingURL=ValidationFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidationFunctions.js","sourceRoot":"","sources":["../../src/validators/ValidationFunctions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AAC1E,OAAO,EACH,qBAAqB,EACrB,sBAAsB,EACtB,wBAAwB,EACxB,uCAAuC,EACvC,0BAA0B,EAC7B,MAAM,2BAA2B,CAAA;AAIlC;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAS,KAAa,EAAE,MAAwB,EAAE,OAAoB;IAC5F,MAAM,QAAQ,GAAW,EAAE,GAAG,KAAK,CAAA;IACnC,MAAM,MAAM,GAAG,+B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