@lionweb/validation 0.7.0-beta.2 → 0.7.0-beta.21
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/CHANGELOG.md +6 -1
- package/dist/issues/ValidationIssue.d.ts +3 -3
- package/dist/issues/ValidationIssue.d.ts.map +1 -1
- package/dist/issues/ValidationIssue.js +1 -1
- package/dist/issues/ValidationIssue.js.map +1 -1
- package/dist/languages/LanguageUtils.d.ts.map +1 -1
- package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -1
- package/dist/runners/Utils.js +2 -2
- package/dist/runners/Utils.js.map +1 -1
- package/dist/validators/LionWebChunkDefinitions.d.ts +4 -4
- package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -1
- package/dist/validators/LionWebChunkDefinitions.js +80 -90
- package/dist/validators/LionWebChunkDefinitions.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 +3 -3
- package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageValidator.js +2 -1
- package/dist/validators/LionWebLanguageValidator.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +2 -2
- package/dist/validators/LionWebValidator.js +1 -1
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/dist/validators/ValidationFunctions.d.ts +1 -1
- package/dist/validators/ValidationFunctions.d.ts.map +1 -1
- package/dist/validators/ValidationFunctions.js +7 -13
- package/dist/validators/ValidationFunctions.js.map +1 -1
- package/dist/validators/generic/SyntaxValidator.d.ts +7 -7
- package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -1
- package/dist/validators/generic/SyntaxValidator.js +28 -33
- package/dist/validators/generic/SyntaxValidator.js.map +1 -1
- package/dist/validators/generic/index.d.ts +1 -1
- package/dist/validators/generic/index.d.ts.map +1 -1
- package/dist/validators/generic/index.js +1 -1
- package/dist/validators/generic/index.js.map +1 -1
- package/dist/validators/generic/schema/DefinitionSchema.d.ts +23 -0
- package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +1 -0
- package/dist/validators/generic/schema/DefinitionSchema.js +43 -0
- package/dist/validators/generic/schema/DefinitionSchema.js.map +1 -0
- package/dist/validators/generic/{ValidationTypes.d.ts → schema/ValidationTypes.d.ts} +45 -12
- package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
- package/dist/validators/generic/{ValidationTypes.js → schema/ValidationTypes.js} +18 -21
- package/dist/validators/generic/schema/ValidationTypes.js.map +1 -0
- package/dist/validators/generic/schema/index.d.ts +3 -0
- package/dist/validators/generic/schema/index.d.ts.map +1 -0
- package/dist/validators/generic/schema/index.js +3 -0
- package/dist/validators/generic/schema/index.js.map +1 -0
- package/package.json +37 -37
- package/src/issues/ValidationIssue.ts +4 -4
- package/src/runners/Utils.ts +2 -2
- package/src/validators/LionWebChunkDefinitions.ts +80 -90
- package/src/validators/LionWebLanguageReferenceValidator.ts +3 -3
- package/src/validators/LionWebLanguageValidator.ts +2 -1
- package/src/validators/LionWebSyntaxValidator.ts +2 -2
- package/src/validators/LionWebValidator.ts +1 -1
- package/src/validators/ValidationFunctions.ts +9 -15
- package/src/validators/generic/SyntaxValidator.ts +81 -87
- package/src/validators/generic/index.ts +1 -1
- package/src/validators/generic/schema/DefinitionSchema.ts +52 -0
- package/src/validators/generic/{ValidationTypes.ts → schema/ValidationTypes.ts} +65 -35
- package/src/validators/generic/schema/index.ts +2 -0
- package/dist/validators/generic/ValidationTypes.d.ts.map +0 -1
- package/dist/validators/generic/ValidationTypes.js.map +0 -1
- package/tsconfig.json +0 -8
|
@@ -2,16 +2,16 @@ import { JsonContext } from "@lionweb/json-utils"
|
|
|
2
2
|
|
|
3
3
|
export abstract class ValidationIssue {
|
|
4
4
|
abstract readonly issueType: string
|
|
5
|
-
context: JsonContext
|
|
5
|
+
context: JsonContext | null
|
|
6
6
|
|
|
7
|
-
constructor(context: JsonContext) {
|
|
7
|
+
constructor(context: JsonContext | null) {
|
|
8
8
|
this.context = context
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
protected abstract msg(): string
|
|
12
12
|
|
|
13
13
|
public errorMsg(): string {
|
|
14
|
-
return `${this.issueType}: ${this.msg()} at ${this.context
|
|
14
|
+
return `${this.issueType}: ${this.msg()} at ${this.context?.toString()} `
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ export class GenericIssue extends ValidationIssue {
|
|
|
19
19
|
readonly issueType = "GenericIssue"
|
|
20
20
|
|
|
21
21
|
constructor(
|
|
22
|
-
context: JsonContext,
|
|
22
|
+
context: JsonContext | null,
|
|
23
23
|
public text: string
|
|
24
24
|
) {
|
|
25
25
|
super(context)
|
package/src/runners/Utils.ts
CHANGED
|
@@ -48,7 +48,7 @@ export function printIssues(result: ValidationResult, file?: string): void {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function issuestoString(vresult: ValidationResult, file?: string): string {
|
|
51
|
-
let result = ""
|
|
52
|
-
vresult.issues.forEach(issue => (result += (file
|
|
51
|
+
let result = "ISSUES: "
|
|
52
|
+
vresult.issues.forEach(issue => (result += (file === undefined ? "NOFILE" : `File ${file}: `) + issue.errorMsg() + "\n"))
|
|
53
53
|
return result
|
|
54
54
|
}
|
|
@@ -1,112 +1,102 @@
|
|
|
1
|
-
import { MAY_BE_NULL,
|
|
1
|
+
import { DefinitionSchema, MAY_BE_NULL, PropertyDef, PrimitiveDef } from "./generic/index.js"
|
|
2
2
|
import { validateId, validateKey, validateSerializationFormatVersion, validateVersion } from "./ValidationFunctions.js"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The structure below defines the structure of a LionWeb Chunk by defining all the properties.
|
|
6
6
|
* It can
|
|
7
|
-
* - be
|
|
8
|
-
* - used to generate all the types for a LionWebChunk.
|
|
7
|
+
* - be used by the SyntaxValidator to validate an object sat runtime.
|
|
8
|
+
* - used to generate all the TypeScript types for a LionWebChunk.
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
[
|
|
14
|
-
PropertyDef({
|
|
15
|
-
PropertyDef({
|
|
16
|
-
PropertyDef({
|
|
10
|
+
export const LionWebSchema: DefinitionSchema = new DefinitionSchema([
|
|
11
|
+
{
|
|
12
|
+
name: "LionWebJsonMetaPointer",
|
|
13
|
+
properties: [
|
|
14
|
+
PropertyDef({ name: "key", type: "LionWebKey" }),
|
|
15
|
+
PropertyDef({ name: "version", type: "LionWebVersion" }),
|
|
16
|
+
PropertyDef({ name: "language", type: "LionWebKey" })
|
|
17
17
|
]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
[
|
|
22
|
-
PropertyDef({
|
|
23
|
-
PropertyDef({
|
|
24
|
-
PropertyDef({
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "LionWebJsonMetaPointer",
|
|
21
|
+
properties: [
|
|
22
|
+
PropertyDef({ name: "key", type: "LionWebKey" }),
|
|
23
|
+
PropertyDef({ name: "version", type: "LionWebVersion" }),
|
|
24
|
+
PropertyDef({ name: "language", type: "LionWebKey" }),
|
|
25
25
|
]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
[
|
|
30
|
-
PropertyDef({
|
|
31
|
-
PropertyDef({
|
|
32
|
-
PropertyDef({
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "ResponseMessage",
|
|
29
|
+
properties: [
|
|
30
|
+
PropertyDef({ name: "kind", type: "JSstring" }),
|
|
31
|
+
PropertyDef({ name: "message", type: "JSstring" }),
|
|
32
|
+
PropertyDef({ name: "data", type: "JSobject", mayBeNull: true, isOptional: true })
|
|
33
33
|
]
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
[
|
|
38
|
-
PropertyDef({
|
|
39
|
-
PropertyDef({
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "LionWebJsonChunk",
|
|
37
|
+
properties: [
|
|
38
|
+
PropertyDef({ name: "serializationFormatVersion", type: "LionWebSerializationFormatVersion" }),
|
|
39
|
+
PropertyDef({ name: "languages", type: "LionWebJsonUsedLanguage", isList: true }),
|
|
40
|
+
PropertyDef({ name: "nodes", type: "LionWebJsonNode", isList: true })
|
|
40
41
|
]
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
[
|
|
45
|
-
PropertyDef({
|
|
46
|
-
PropertyDef({
|
|
47
|
-
PropertyDef({ property: "properties", expectedType: "LionWebProperty", isList: true }),
|
|
48
|
-
PropertyDef({ property: "containments", expectedType: "LionWebContainment", isList: true }),
|
|
49
|
-
PropertyDef({ property: "references", expectedType: "LionWebReference", isList: true }),
|
|
50
|
-
PropertyDef({ property: "annotations", expectedType: "LionWebId", isList: true }),
|
|
51
|
-
PropertyDef({ property: "parent", expectedType: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "LionWebJsonUsedLanguage",
|
|
45
|
+
properties: [
|
|
46
|
+
PropertyDef({ name: "key", type: "LionWebKey" }),
|
|
47
|
+
PropertyDef({ name: "version", type: "LionWebVersion" })
|
|
52
48
|
]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
[
|
|
57
|
-
PropertyDef({
|
|
58
|
-
PropertyDef({
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "LionWebJsonNode",
|
|
52
|
+
properties: [
|
|
53
|
+
PropertyDef({ name: "id", type: "LionWebId" }),
|
|
54
|
+
PropertyDef({ name: "classifier", type: "LionWebJsonMetaPointer" }),
|
|
55
|
+
PropertyDef({ name: "properties", type: "LionWebJsonProperty", isList: true }),
|
|
56
|
+
PropertyDef({ name: "containments", type: "LionWebJsonContainment", isList: true }),
|
|
57
|
+
PropertyDef({ name: "references", type: "LionWebJsonReference", isList: true }),
|
|
58
|
+
PropertyDef({ name: "annotations", type: "LionWebId", isList: true }),
|
|
59
|
+
PropertyDef({ name: "parent", type: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
59
60
|
]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
[
|
|
64
|
-
PropertyDef({
|
|
65
|
-
PropertyDef({
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "LionWebJsonProperty",
|
|
64
|
+
properties: [
|
|
65
|
+
PropertyDef({ name: "property", type: "LionWebJsonMetaPointer" }),
|
|
66
|
+
PropertyDef({ name: "value", type: "JSstring", mayBeNull: MAY_BE_NULL }),
|
|
66
67
|
]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
[
|
|
71
|
-
PropertyDef({
|
|
72
|
-
PropertyDef({
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "LionWebJsonContainment",
|
|
71
|
+
properties: [
|
|
72
|
+
PropertyDef({ name: "containment", type: "LionWebJsonMetaPointer" }),
|
|
73
|
+
PropertyDef({ name: "children", type: "LionWebId", isList: true }),
|
|
73
74
|
]
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
[
|
|
78
|
-
PropertyDef({
|
|
79
|
-
PropertyDef({
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "LionWebJsonReference",
|
|
78
|
+
properties: [
|
|
79
|
+
PropertyDef({ name: "reference", type: "LionWebJsonMetaPointer"}),
|
|
80
|
+
PropertyDef({ name: "targets", type: "LionWebJsonReferenceTarget", isList: true}),
|
|
80
81
|
]
|
|
81
|
-
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "LionWebJsonReferenceTarget",
|
|
85
|
+
properties: [
|
|
86
|
+
PropertyDef({ name: "resolveInfo", type: "JSstring", mayBeNull: MAY_BE_NULL }),
|
|
87
|
+
PropertyDef({ name: "reference", type: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
88
|
+
]
|
|
89
|
+
},
|
|
82
90
|
/**
|
|
83
91
|
* Elements without properties are assumed to be JSON/JS primitive values, and tested using `typeof`
|
|
84
92
|
* and the (optional) validate function.
|
|
85
93
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
PrimitiveDef({ primitiveType: "string", validate: validateKey }),
|
|
93
|
-
],
|
|
94
|
-
[
|
|
95
|
-
"LionWebVersion",
|
|
96
|
-
PrimitiveDef({ primitiveType: "string", validate: validateVersion }),
|
|
97
|
-
],
|
|
98
|
-
[
|
|
99
|
-
"LionWebSerializationFormatVersion",
|
|
100
|
-
PrimitiveDef({ primitiveType: "string", validate: validateSerializationFormatVersion }),
|
|
101
|
-
],
|
|
102
|
-
[
|
|
103
|
-
"string",
|
|
104
|
-
PrimitiveDef({ primitiveType: "string" }),
|
|
105
|
-
],
|
|
106
|
-
[
|
|
107
|
-
"object",
|
|
108
|
-
PrimitiveDef({ primitiveType: "object" }),
|
|
109
|
-
]
|
|
94
|
+
PrimitiveDef({ name: "LionWebId", primitiveType: "string", validate: validateId }),
|
|
95
|
+
PrimitiveDef({ name: "LionWebKey", primitiveType: "string", validate: validateKey }),
|
|
96
|
+
PrimitiveDef({ name: "LionWebVersion",primitiveType: "string", validate: validateVersion }),
|
|
97
|
+
PrimitiveDef({ name: "LionWebSerializationFormatVersion",primitiveType: "string", validate: validateSerializationFormatVersion }),
|
|
98
|
+
PrimitiveDef({ name: "JSstring", primitiveType: "string" }),
|
|
99
|
+
PrimitiveDef({ name: "JSobject",primitiveType: "object" }),
|
|
110
100
|
])
|
|
111
101
|
|
|
112
102
|
|
|
@@ -66,7 +66,7 @@ export class LionWebLanguageReferenceValidator {
|
|
|
66
66
|
})
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
private validateContainment(
|
|
69
|
+
private validateContainment(_node: LionWebJsonNode, nodeConcept: LionWebJsonNode | undefined, containment: LionWebJsonContainment, context: JsonContext) {
|
|
70
70
|
const metaConcept = this.registry.getNodeByMetaPointer(containment.containment)
|
|
71
71
|
if (metaConcept === null || metaConcept === undefined) {
|
|
72
72
|
this.validationResult.issue(new Language_UnknownContainment_Issue(context, containment.containment))
|
|
@@ -85,7 +85,7 @@ export class LionWebLanguageReferenceValidator {
|
|
|
85
85
|
// TODO check type of children
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
private validateReference(
|
|
88
|
+
private validateReference(_node: LionWebJsonNode, nodeConcept: LionWebJsonNode | undefined, ref: LionWebJsonReference, context: JsonContext) {
|
|
89
89
|
const referenceDefinition = this.registry.getNodeByMetaPointer(ref.reference)
|
|
90
90
|
if (referenceDefinition === null || referenceDefinition === undefined) {
|
|
91
91
|
this.validationResult.issue(new Language_UnknownReference_Issue(context, ref.reference))
|
|
@@ -113,7 +113,7 @@ export class LionWebLanguageReferenceValidator {
|
|
|
113
113
|
* Checks wwhether the value of `prop1` is correct in relation with its property definition in the referred language.
|
|
114
114
|
* @param prop
|
|
115
115
|
*/
|
|
116
|
-
validateProperty(
|
|
116
|
+
validateProperty(_node: LionWebJsonNode, nodeConcept: LionWebJsonNode | undefined, prop: LionWebJsonProperty, context: JsonContext): void {
|
|
117
117
|
if (prop.value === null) {
|
|
118
118
|
return
|
|
119
119
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isEqualMetaPointer, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
|
|
2
2
|
import { isLionWebM3Language, JsonContext, LionWebJsonChunkWrapper, MetaPointers } from "@lionweb/json-utils"
|
|
3
|
+
import { asMinimalJsonString } from "@lionweb/ts-utils"
|
|
3
4
|
import { GenericIssue } from "../issues/index.js"
|
|
4
5
|
import { MissingM3Language_Issue } from "../issues/LanguageIssues.js"
|
|
5
6
|
import { isConcept, LanguageRegistry } from "../languages/index.js"
|
|
@@ -33,7 +34,7 @@ export class LionWebLanguageValidator {
|
|
|
33
34
|
const languageNodes = this.chunkWrapper.findNodesOfClassifier(MetaPointers.Language)
|
|
34
35
|
if (languageNodes.length !== 1) {
|
|
35
36
|
// TODO Better error handling.
|
|
36
|
-
console.error("Error: xpected exactly one Language node, found " + languageNodes.length + " => " +
|
|
37
|
+
console.error("Error: xpected exactly one Language node, found " + languageNodes.length + " => " + asMinimalJsonString(languageNodes))
|
|
37
38
|
}
|
|
38
39
|
chunk.nodes.forEach((node, index) => {
|
|
39
40
|
if (!isConcept(node)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SyntaxValidator } from "./generic/SyntaxValidator.js"
|
|
2
2
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
3
|
-
import {
|
|
3
|
+
import { LionWebSchema } from "./LionWebChunkDefinitions.js"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* LionWebSyntaxValidator can check whether objects are structurally LionWeb objects.
|
|
@@ -8,7 +8,7 @@ import { expectedTypes } from "./LionWebChunkDefinitions.js"
|
|
|
8
8
|
export class LionWebSyntaxValidator extends SyntaxValidator {
|
|
9
9
|
|
|
10
10
|
constructor(validationResult: ValidationResult) {
|
|
11
|
-
super(validationResult,
|
|
11
|
+
super(validationResult, LionWebSchema)
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -34,7 +34,7 @@ export class LionWebValidator {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
validateSyntax() {
|
|
37
|
-
this.syntaxValidator.validate(this.object, "
|
|
37
|
+
this.syntaxValidator.validate(this.object, "LionWebJsonChunk")
|
|
38
38
|
this.syntaxCorrect = !this.validationResult.hasErrors()
|
|
39
39
|
if (this.syntaxCorrect) {
|
|
40
40
|
this.chunk = new LionWebJsonChunkWrapper(this.object as LionWebJsonChunk)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Used in the LionWebSyntaxValidator.
|
|
4
4
|
*/
|
|
5
5
|
import { JsonContext } from "@lionweb/json-utils"
|
|
6
|
+
import { asMinimalJsonString } from "@lionweb/ts-utils"
|
|
6
7
|
import { Language_PropertyValue_Issue } from "../issues/LanguageIssues.js"
|
|
7
8
|
import {
|
|
8
9
|
Syntax_IdFormat_Issue,
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
Syntax_VersionFormat_Issue
|
|
13
14
|
} from "../issues/SyntaxIssues.js"
|
|
14
15
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
15
|
-
import { PropertyDefinition } from "./generic/ValidationTypes.js"
|
|
16
|
+
import { PropertyDefinition } from "./generic/schema/ValidationTypes.js"
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Check whether `id` is a valid LionWeb id.
|
|
@@ -20,7 +21,6 @@ import { PropertyDefinition } from "./generic/ValidationTypes.js"
|
|
|
20
21
|
* @param result Any validation issues found will be put into this object.
|
|
21
22
|
* @param context The context for the error message in errors.
|
|
22
23
|
*/
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
24
24
|
export function validateId<String>(value: String, result: ValidationResult, context: JsonContext): void {
|
|
25
25
|
const idString: string = "" + value
|
|
26
26
|
const regexp = /^[a-zA-Z0-9_-][a-zA-Z0-9_-]*$/
|
|
@@ -35,7 +35,6 @@ export function validateId<String>(value: String, result: ValidationResult, cont
|
|
|
35
35
|
* @param result Any validation issues found will be put into this object.
|
|
36
36
|
* @param context The context for the error message in errors.
|
|
37
37
|
*/
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
39
38
|
export function validateKey<String>(value: String, result: ValidationResult, context: JsonContext): void {
|
|
40
39
|
const keyString: string = "" + value
|
|
41
40
|
const regexp = /^[a-zA-Z0-9_-][a-zA-Z0-9_-]*$/
|
|
@@ -50,7 +49,6 @@ export function validateKey<String>(value: String, result: ValidationResult, con
|
|
|
50
49
|
* @param result Any validation issues found will be put into this object.
|
|
51
50
|
* @param context The location in the overall JSON.
|
|
52
51
|
*/
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
54
52
|
export function validateVersion<String>(value: String, result: ValidationResult, context: JsonContext): void {
|
|
55
53
|
const versionString: string = "" + value
|
|
56
54
|
if (versionString.length === 0) {
|
|
@@ -65,16 +63,15 @@ export function validateVersion<String>(value: String, result: ValidationResult,
|
|
|
65
63
|
* @param context The location in the overall JSON.
|
|
66
64
|
* @param propDef The PropertyDefinition for this value
|
|
67
65
|
*/
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
69
66
|
export function validateBoolean<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void {
|
|
70
67
|
const valueAsPrimitive = "" + value
|
|
71
68
|
if (valueAsPrimitive !== "true" && valueAsPrimitive !== "false") {
|
|
72
69
|
result.issue(
|
|
73
70
|
new Language_PropertyValue_Issue(
|
|
74
71
|
context,
|
|
75
|
-
propDef ? propDef.
|
|
72
|
+
propDef ? propDef.name : "unknown",
|
|
76
73
|
valueAsPrimitive,
|
|
77
|
-
"boolean " +
|
|
74
|
+
"boolean " + asMinimalJsonString(value)
|
|
78
75
|
)
|
|
79
76
|
)
|
|
80
77
|
}
|
|
@@ -87,12 +84,11 @@ export function validateBoolean<String>(value: String, result: ValidationResult,
|
|
|
87
84
|
* @param context The location in the overall JSON.
|
|
88
85
|
* @param propDef The PropertyDefinition for this value
|
|
89
86
|
*/
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
91
87
|
export function validateInteger<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void {
|
|
92
88
|
const valueAsPrimitive = "" + value
|
|
93
89
|
const regexp = /^[+-]?(0|[1-9][0-9]*)$/
|
|
94
90
|
if (valueAsPrimitive === null || !regexp.test(valueAsPrimitive)) {
|
|
95
|
-
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.
|
|
91
|
+
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "integer"))
|
|
96
92
|
}
|
|
97
93
|
}
|
|
98
94
|
|
|
@@ -103,16 +99,15 @@ export function validateInteger<String>(value: String, result: ValidationResult,
|
|
|
103
99
|
* @param context The location in the overall JSON.
|
|
104
100
|
* @param propDef The PropertyDefinition for this value
|
|
105
101
|
*/
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
107
102
|
export function validateJSON<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void {
|
|
108
103
|
const valueAsPrimitive = "" + value
|
|
109
104
|
if (value === null) {
|
|
110
|
-
result.issue(new Syntax_PropertyNullIssue(context, propDef!.
|
|
105
|
+
result.issue(new Syntax_PropertyNullIssue(context, propDef!.name!))
|
|
111
106
|
}
|
|
112
107
|
try {
|
|
113
108
|
JSON.parse(valueAsPrimitive)
|
|
114
|
-
} catch (
|
|
115
|
-
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.
|
|
109
|
+
} catch (_) {
|
|
110
|
+
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "JSON"))
|
|
116
111
|
}
|
|
117
112
|
}
|
|
118
113
|
|
|
@@ -122,10 +117,9 @@ export function validateJSON<String>(value: String, result: ValidationResult, co
|
|
|
122
117
|
* @param result
|
|
123
118
|
* @param context
|
|
124
119
|
*/
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
126
120
|
export function validateSerializationFormatVersion<String>(value: String, result: ValidationResult, context: JsonContext): void {
|
|
127
121
|
if (typeof value !== "string") {
|
|
128
|
-
result.issue(new Syntax_SerializationFormatVersion_Issue(context,
|
|
122
|
+
result.issue(new Syntax_SerializationFormatVersion_Issue(context, asMinimalJsonString(value)))
|
|
129
123
|
return
|
|
130
124
|
}
|
|
131
125
|
if (value.length === 0) {
|