@lionweb/validation 0.5.0-beta.8
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/LICENSE +201 -0
- package/README.md +31 -0
- package/build.sh +6 -0
- package/package.json +28 -0
- package/src/diff/LionwebDiff.ts +193 -0
- package/src/issues/LanguageIssues.ts +91 -0
- package/src/issues/ReferenceIssues.ts +60 -0
- package/src/issues/SyntaxIssues.ts +68 -0
- package/src/issues/ValidationIssue.ts +46 -0
- package/src/json/ChunkUtils.ts +53 -0
- package/src/json/LanguageUtils.ts +12 -0
- package/src/json/LionWebJson.ts +77 -0
- package/src/json/LionWebJsonChunkWrapper.ts +74 -0
- package/src/json/LionWebLanguageDefinition.ts +141 -0
- package/src/json/NodeUtils.ts +72 -0
- package/src/json/std-builtins-copy.json +369 -0
- package/src/runners/RunCheckFolder.ts +36 -0
- package/src/runners/RunCheckFolderWithLanguage.ts +44 -0
- package/src/runners/RunCheckOneFile.ts +16 -0
- package/src/runners/RunCheckOneFileWithLanguage.ts +28 -0
- package/src/runners/RunLioncoreDiff.ts +23 -0
- package/src/runners/Utils.ts +21 -0
- package/src/validators/LionWebLanguageReferenceValidator.ts +135 -0
- package/src/validators/LionWebLanguageValidator.ts +40 -0
- package/src/validators/LionWebReferenceValidator.ts +213 -0
- package/src/validators/LionWebSyntaxValidator.ts +297 -0
- package/src/validators/LionWebValidator.ts +76 -0
- package/src/validators/SimpleFieldValidator.ts +90 -0
- package/src/validators/ValidationResult.ts +18 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Language_PropertyValue_Issue } from "../issues/LanguageIssues";
|
|
2
|
+
import { Syntax_IdFormat_Issue, Syntax_KeyFormat_Issue, Syntax_SerializationFormatVersion_Issue, Syntax_VersionFormat_Issue } from "../issues/SyntaxIssues";
|
|
3
|
+
import { JsonContext } from "../issues/ValidationIssue";
|
|
4
|
+
import { LionWebJsonProperty } from "../json/LionWebJson";
|
|
5
|
+
import { ValidationResult } from "./ValidationResult";
|
|
6
|
+
|
|
7
|
+
export type ValidatorFunction = <T>(obj: T, ctx: JsonContext) => void;
|
|
8
|
+
|
|
9
|
+
export class SimpleFieldValidator {
|
|
10
|
+
validationResult: ValidationResult;
|
|
11
|
+
|
|
12
|
+
constructor(validationResult: ValidationResult) {
|
|
13
|
+
this.validationResult = validationResult;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Check whether `id` is a valid LionWeb id.
|
|
18
|
+
* @param id
|
|
19
|
+
* @param context
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
22
|
+
validateId: ValidatorFunction = <String>(id: String, context: JsonContext): void => {
|
|
23
|
+
if (id === null || id === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const idString: string = id.toString();
|
|
27
|
+
const egexp = /^[a-zA-Z0-9$_-][a-zA-Z0-9$_-]*$/;
|
|
28
|
+
if (!egexp.test(idString)) {
|
|
29
|
+
this.validationResult.issue(new Syntax_IdFormat_Issue(context, idString));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param key The `key` to be checked.
|
|
36
|
+
* @param context The context for the error message in errors.
|
|
37
|
+
* @return true if `key` is a correct LionWeb key.
|
|
38
|
+
*/
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
40
|
+
validateKey: ValidatorFunction = <String>(key: String, context: JsonContext): void => {
|
|
41
|
+
if (key === undefined || key === null) {
|
|
42
|
+
this.validationResult.issue(new Syntax_KeyFormat_Issue(context, "null-or-undefined"));
|
|
43
|
+
}
|
|
44
|
+
const keyString: string = "" + key;
|
|
45
|
+
const egexp = /^[a-zA-Z0-9$_-][a-zA-Z$_0-9-]*$/;
|
|
46
|
+
if (!egexp.test(keyString)) {
|
|
47
|
+
this.validationResult.issue(new Syntax_KeyFormat_Issue(context, keyString));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
52
|
+
validateVersion: ValidatorFunction = <String>(version: String, context: JsonContext): void => {
|
|
53
|
+
const versionString: string = "" + version;
|
|
54
|
+
if (versionString.length === 0) {
|
|
55
|
+
this.validationResult.issue(new Syntax_VersionFormat_Issue(context, versionString));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
validateBoolean = (property: LionWebJsonProperty, propName: string, context: JsonContext): void => {
|
|
60
|
+
if (property.value !== "true" && property.value !== "false") {
|
|
61
|
+
this.validationResult.issue(new Language_PropertyValue_Issue(context, propName, property.value, "boolean"));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
validateInteger = (property: LionWebJsonProperty, propName: string, context: JsonContext): void => {
|
|
66
|
+
const regexp = /^[+-]?(0|[1-9][0-9]*)$/;
|
|
67
|
+
if (!regexp.test(property.value)) {
|
|
68
|
+
this.validationResult.issue(new Language_PropertyValue_Issue(context, propName, property.value, "integer"));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
validateJSON = (property: LionWebJsonProperty, propName: string, context: JsonContext): void => {
|
|
73
|
+
try {
|
|
74
|
+
JSON.parse(property.value);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
this.validationResult.issue(new Language_PropertyValue_Issue(context, propName, property.value, "JSON"));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
validateSerializationFormatVersion = (objElement: unknown, context: JsonContext): void => {
|
|
81
|
+
if (typeof objElement !== "string") {
|
|
82
|
+
this.validationResult.issue(new Syntax_SerializationFormatVersion_Issue(context, JSON.stringify(objElement)));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (objElement.length === 0) {
|
|
86
|
+
this.validationResult.issue(new Syntax_SerializationFormatVersion_Issue(context, objElement));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ValidationIssue } from "../issues/ValidationIssue";
|
|
2
|
+
|
|
3
|
+
export class ValidationResult {
|
|
4
|
+
issues: ValidationIssue[] = [];
|
|
5
|
+
|
|
6
|
+
issue(issue: ValidationIssue) {
|
|
7
|
+
this.issues.push(issue);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
reset() {
|
|
11
|
+
this.issues = [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
hasErrors(): boolean {
|
|
15
|
+
return this.issues.length !== 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|