@lionweb/validation 0.6.13-beta.7 → 0.7.0-beta.0
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/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/issues/LanguageIssues.d.ts +4 -4
- package/dist/issues/LanguageIssues.d.ts.map +1 -1
- package/dist/issues/LanguageIssues.js +1 -1
- package/dist/issues/LanguageIssues.js.map +1 -1
- package/dist/issues/ReferenceIssues.d.ts +6 -6
- package/dist/issues/ReferenceIssues.d.ts.map +1 -1
- package/dist/issues/ReferenceIssues.js +3 -3
- package/dist/issues/ReferenceIssues.js.map +1 -1
- package/dist/issues/SyntaxIssues.d.ts +1 -1
- package/dist/issues/SyntaxIssues.d.ts.map +1 -1
- package/dist/issues/ValidationIssue.d.ts +1 -1
- package/dist/issues/ValidationIssue.d.ts.map +1 -1
- package/dist/issues/ValidationIssue.js.map +1 -1
- package/dist/issues/index.d.ts +0 -1
- package/dist/issues/index.d.ts.map +1 -1
- package/dist/issues/index.js +0 -1
- package/dist/issues/index.js.map +1 -1
- package/dist/languages/CompositeLionWebLanguageWrapper.d.ts +1 -1
- package/dist/languages/CompositeLionWebLanguageWrapper.d.ts.map +1 -1
- package/dist/languages/LanguageRegistry.d.ts +1 -1
- package/dist/languages/LanguageRegistry.d.ts.map +1 -1
- package/dist/languages/LanguageUtils.d.ts +1 -1
- package/dist/languages/LanguageUtils.d.ts.map +1 -1
- package/dist/languages/LanguageUtils.js +5 -5
- package/dist/languages/LanguageUtils.js.map +1 -1
- package/dist/languages/LionWebLanguageWrapper.d.ts +3 -3
- package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -1
- package/dist/languages/LionWebLanguageWrapper.js +2 -2
- package/dist/languages/LionWebLanguageWrapper.js.map +1 -1
- package/dist/languages/MetaPointerMap.d.ts +2 -2
- package/dist/languages/MetaPointerMap.d.ts.map +1 -1
- package/dist/languages/MetaPointerMap.js +1 -1
- package/dist/languages/MetaPointerMap.js.map +1 -1
- package/dist/runners/FileUtils.d.ts.map +1 -1
- package/dist/runners/FileUtils.js +1 -1
- package/dist/runners/FileUtils.js.map +1 -1
- package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -1
- package/dist/runners/RunLioncoreDiff.js +1 -1
- package/dist/runners/RunLioncoreDiff.js.map +1 -1
- package/dist/validators/LionWebChunkDefinitions.d.ts +2 -2
- package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -1
- package/dist/validators/LionWebChunkDefinitions.js +33 -20
- package/dist/validators/LionWebChunkDefinitions.js.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts +2 -4
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.js +2 -6
- package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebLanguageValidator.d.ts +2 -3
- package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageValidator.js +2 -4
- package/dist/validators/LionWebLanguageValidator.js.map +1 -1
- package/dist/validators/LionWebReferenceValidator.d.ts +3 -4
- package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebReferenceValidator.js +2 -3
- package/dist/validators/LionWebReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +1 -1
- package/dist/validators/LionWebSyntaxValidator.js.map +1 -1
- package/dist/validators/LionWebValidator.d.ts +1 -1
- package/dist/validators/LionWebValidator.d.ts.map +1 -1
- package/dist/validators/LionWebValidator.js +2 -2
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/dist/validators/ValidationFunctions.d.ts +5 -1
- package/dist/validators/ValidationFunctions.d.ts.map +1 -1
- package/dist/validators/ValidationFunctions.js +0 -4
- package/dist/validators/ValidationFunctions.js.map +1 -1
- package/dist/validators/generic/SyntaxValidator.d.ts +9 -9
- package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -1
- package/dist/validators/generic/SyntaxValidator.js +61 -58
- package/dist/validators/generic/SyntaxValidator.js.map +1 -1
- package/dist/validators/generic/ValidationTypes.d.ts +25 -1
- package/dist/validators/generic/ValidationTypes.d.ts.map +1 -1
- package/dist/validators/generic/ValidationTypes.js +20 -1
- package/dist/validators/generic/ValidationTypes.js.map +1 -1
- package/dist/validators/generic/index.d.ts +0 -1
- package/dist/validators/generic/index.d.ts.map +1 -1
- package/dist/validators/generic/index.js +0 -1
- package/dist/validators/generic/index.js.map +1 -1
- package/dist/validators/index.d.ts +0 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +0 -1
- package/dist/validators/index.js.map +1 -1
- package/package.json +9 -4
- package/src/index.ts +0 -3
- package/src/issues/LanguageIssues.ts +12 -14
- package/src/issues/ReferenceIssues.ts +9 -9
- package/src/issues/SyntaxIssues.ts +5 -5
- package/src/issues/ValidationIssue.ts +7 -4
- package/src/issues/index.ts +0 -1
- package/src/languages/CompositeLionWebLanguageWrapper.ts +1 -1
- package/src/languages/LanguageRegistry.ts +1 -1
- package/src/languages/LanguageUtils.ts +6 -6
- package/src/languages/LionWebLanguageWrapper.ts +5 -9
- package/src/languages/MetaPointerMap.ts +7 -6
- package/src/runners/FileUtils.ts +1 -1
- package/src/runners/RunCheckFolderWithLanguage.ts +1 -1
- package/src/runners/RunLioncoreDiff.ts +2 -2
- package/src/validators/LionWebChunkDefinitions.ts +35 -27
- package/src/validators/LionWebLanguageReferenceValidator.ts +18 -20
- package/src/validators/LionWebLanguageValidator.ts +2 -4
- package/src/validators/LionWebReferenceValidator.ts +6 -14
- package/src/validators/LionWebSyntaxValidator.ts +1 -1
- package/src/validators/LionWebValidator.ts +3 -3
- package/src/validators/ValidationFunctions.ts +1 -1
- package/src/validators/generic/SyntaxValidator.ts +98 -91
- package/src/validators/generic/ValidationTypes.ts +41 -4
- package/src/validators/generic/index.ts +0 -1
- package/src/validators/index.ts +0 -1
- package/dist/diff/DiffResult.d.ts +0 -9
- package/dist/diff/DiffResult.d.ts.map +0 -1
- package/dist/diff/DiffResult.js +0 -18
- package/dist/diff/DiffResult.js.map +0 -1
- package/dist/diff/LionWebJsonDiff.d.ts +0 -25
- package/dist/diff/LionWebJsonDiff.d.ts.map +0 -1
- package/dist/diff/LionWebJsonDiff.js +0 -249
- package/dist/diff/LionWebJsonDiff.js.map +0 -1
- package/dist/diff/changes/Change.d.ts +0 -34
- package/dist/diff/changes/Change.d.ts.map +0 -1
- package/dist/diff/changes/Change.js +0 -38
- package/dist/diff/changes/Change.js.map +0 -1
- package/dist/diff/changes/ChunkChange.d.ts +0 -43
- package/dist/diff/changes/ChunkChange.d.ts.map +0 -1
- package/dist/diff/changes/ChunkChange.js +0 -57
- package/dist/diff/changes/ChunkChange.js.map +0 -1
- package/dist/diff/changes/ContainmentChange.d.ts +0 -25
- package/dist/diff/changes/ContainmentChange.d.ts.map +0 -1
- package/dist/diff/changes/ContainmentChange.js +0 -34
- package/dist/diff/changes/ContainmentChange.js.map +0 -1
- package/dist/diff/changes/NodeChange.d.ts +0 -41
- package/dist/diff/changes/NodeChange.d.ts.map +0 -1
- package/dist/diff/changes/NodeChange.js +0 -54
- package/dist/diff/changes/NodeChange.js.map +0 -1
- package/dist/diff/changes/PropertyChange.d.ts +0 -24
- package/dist/diff/changes/PropertyChange.d.ts.map +0 -1
- package/dist/diff/changes/PropertyChange.js +0 -29
- package/dist/diff/changes/PropertyChange.js.map +0 -1
- package/dist/diff/changes/ReferenceChange.d.ts +0 -25
- package/dist/diff/changes/ReferenceChange.d.ts.map +0 -1
- package/dist/diff/changes/ReferenceChange.js +0 -34
- package/dist/diff/changes/ReferenceChange.js.map +0 -1
- package/dist/diff/changes/index.d.ts +0 -7
- package/dist/diff/changes/index.d.ts.map +0 -1
- package/dist/diff/changes/index.js +0 -7
- package/dist/diff/changes/index.js.map +0 -1
- package/dist/diff/index.d.ts +0 -4
- package/dist/diff/index.d.ts.map +0 -1
- package/dist/diff/index.js +0 -4
- package/dist/diff/index.js.map +0 -1
- package/dist/json/ChunkUtils.d.ts +0 -26
- package/dist/json/ChunkUtils.d.ts.map +0 -1
- package/dist/json/ChunkUtils.js +0 -46
- package/dist/json/ChunkUtils.js.map +0 -1
- package/dist/json/JsonContext.d.ts +0 -11
- package/dist/json/JsonContext.d.ts.map +0 -1
- package/dist/json/JsonContext.js +0 -25
- package/dist/json/JsonContext.js.map +0 -1
- package/dist/json/LionWebJson.d.ts +0 -50
- package/dist/json/LionWebJson.d.ts.map +0 -1
- package/dist/json/LionWebJson.js +0 -27
- package/dist/json/LionWebJson.js.map +0 -1
- package/dist/json/LionWebJsonChunkWrapper.d.ts +0 -39
- package/dist/json/LionWebJsonChunkWrapper.d.ts.map +0 -1
- package/dist/json/LionWebJsonChunkWrapper.js +0 -119
- package/dist/json/LionWebJsonChunkWrapper.js.map +0 -1
- package/dist/json/M3definitions.d.ts +0 -176
- package/dist/json/M3definitions.d.ts.map +0 -1
- package/dist/json/M3definitions.js +0 -174
- package/dist/json/M3definitions.js.map +0 -1
- package/dist/json/NodeUtils.d.ts +0 -23
- package/dist/json/NodeUtils.d.ts.map +0 -1
- package/dist/json/NodeUtils.js +0 -57
- package/dist/json/NodeUtils.js.map +0 -1
- package/dist/json/index.d.ts +0 -7
- package/dist/json/index.d.ts.map +0 -1
- package/dist/json/index.js +0 -7
- package/dist/json/index.js.map +0 -1
- package/dist/util/graphs.d.ts +0 -18
- package/dist/util/graphs.d.ts.map +0 -1
- package/dist/util/graphs.js +0 -27
- package/dist/util/graphs.js.map +0 -1
- package/src/diff/DiffResult.ts +0 -21
- package/src/diff/LionWebJsonDiff.ts +0 -309
- package/src/diff/changes/Change.ts +0 -76
- package/src/diff/changes/ChunkChange.ts +0 -68
- package/src/diff/changes/ContainmentChange.ts +0 -32
- package/src/diff/changes/NodeChange.ts +0 -63
- package/src/diff/changes/PropertyChange.ts +0 -31
- package/src/diff/changes/ReferenceChange.ts +0 -34
- package/src/diff/changes/index.ts +0 -6
- package/src/diff/index.ts +0 -3
- package/src/json/ChunkUtils.ts +0 -49
- package/src/json/JsonContext.ts +0 -31
- package/src/json/LionWebJson.ts +0 -80
- package/src/json/LionWebJsonChunkWrapper.ts +0 -136
- package/src/json/M3definitions.ts +0 -177
- package/src/json/NodeUtils.ts +0 -75
- package/src/json/index.ts +0 -6
- package/src/util/graphs.ts +0 -36
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
validateKey,
|
|
4
|
-
validateSerializationFormatVersion,
|
|
5
|
-
validateVersion
|
|
6
|
-
} from "./ValidationFunctions.js"
|
|
7
|
-
import { MAY_BE_NULL, PropertyDef, PropertyDefinition } from "./generic/ValidationTypes.js"
|
|
1
|
+
import { MAY_BE_NULL, PrimitiveDef, PropertyDef, TypeDefinition } from "./generic/ValidationTypes.js"
|
|
2
|
+
import { validateId, validateKey, validateSerializationFormatVersion, validateVersion } from "./ValidationFunctions.js"
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* The structure below defines the structure of a LionWeb Chunk by defining all the properties.
|
|
@@ -12,13 +7,13 @@ import { MAY_BE_NULL, PropertyDef, PropertyDefinition } from "./generic/Validati
|
|
|
12
7
|
* - be fed to the SyntaxValidator to validate an object sat runtime.
|
|
13
8
|
* - used to generate all the types for a LionWebChunk.
|
|
14
9
|
*/
|
|
15
|
-
export const expectedTypes: Map<string,
|
|
10
|
+
export const expectedTypes: Map<string, TypeDefinition> = new Map<string, TypeDefinition>([
|
|
16
11
|
[
|
|
17
12
|
"LionWebMetaPointer",
|
|
18
13
|
[
|
|
19
|
-
PropertyDef({ property: "key", expectedType: "
|
|
20
|
-
PropertyDef({ property: "version", expectedType: "
|
|
21
|
-
PropertyDef({ property: "language", expectedType: "
|
|
14
|
+
PropertyDef({ property: "key", expectedType: "LionWebKey" }),
|
|
15
|
+
PropertyDef({ property: "version", expectedType: "LionWebVersion" }),
|
|
16
|
+
PropertyDef({ property: "language", expectedType: "LionWebKey" })
|
|
22
17
|
]
|
|
23
18
|
],
|
|
24
19
|
[
|
|
@@ -26,13 +21,13 @@ export const expectedTypes: Map<string, PropertyDefinition[]> = new Map([
|
|
|
26
21
|
[
|
|
27
22
|
PropertyDef({ property: "kind", expectedType: "string" }),
|
|
28
23
|
PropertyDef({ property: "message", expectedType: "string" }),
|
|
29
|
-
PropertyDef({ property: "data", expectedType: "object", mayBeNull: true })
|
|
24
|
+
PropertyDef({ property: "data", expectedType: "object", mayBeNull: true, isOptional: true })
|
|
30
25
|
]
|
|
31
26
|
],
|
|
32
27
|
[
|
|
33
28
|
"LionWebChunk",
|
|
34
29
|
[
|
|
35
|
-
PropertyDef({ property: "serializationFormatVersion", expectedType: "
|
|
30
|
+
PropertyDef({ property: "serializationFormatVersion", expectedType: "LionWebSerializationFormatVersion" }),
|
|
36
31
|
PropertyDef({ property: "languages", expectedType: "LionWebUsedLanguage", isList: true }),
|
|
37
32
|
PropertyDef({ property: "nodes", expectedType: "LionWebNode", isList: true })
|
|
38
33
|
]
|
|
@@ -40,20 +35,20 @@ export const expectedTypes: Map<string, PropertyDefinition[]> = new Map([
|
|
|
40
35
|
[
|
|
41
36
|
"LionWebUsedLanguage",
|
|
42
37
|
[
|
|
43
|
-
PropertyDef({ property: "key", expectedType: "
|
|
44
|
-
PropertyDef({ property: "version", expectedType: "
|
|
38
|
+
PropertyDef({ property: "key", expectedType: "LionWebKey" }),
|
|
39
|
+
PropertyDef({ property: "version", expectedType: "LionWebVersion" })
|
|
45
40
|
]
|
|
46
41
|
],
|
|
47
42
|
[
|
|
48
43
|
"LionWebNode",
|
|
49
44
|
[
|
|
50
|
-
PropertyDef({ property: "id", expectedType: "
|
|
45
|
+
PropertyDef({ property: "id", expectedType: "LionWebId" }),
|
|
51
46
|
PropertyDef({ property: "classifier", expectedType: "LionWebMetaPointer" }),
|
|
52
47
|
PropertyDef({ property: "properties", expectedType: "LionWebProperty", isList: true }),
|
|
53
48
|
PropertyDef({ property: "containments", expectedType: "LionWebContainment", isList: true }),
|
|
54
49
|
PropertyDef({ property: "references", expectedType: "LionWebReference", isList: true }),
|
|
55
|
-
PropertyDef({ property: "annotations", expectedType: "
|
|
56
|
-
PropertyDef({ property: "parent", expectedType: "
|
|
50
|
+
PropertyDef({ property: "annotations", expectedType: "LionWebId", isList: true }),
|
|
51
|
+
PropertyDef({ property: "parent", expectedType: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
57
52
|
]
|
|
58
53
|
],
|
|
59
54
|
[
|
|
@@ -67,7 +62,7 @@ export const expectedTypes: Map<string, PropertyDefinition[]> = new Map([
|
|
|
67
62
|
"LionWebContainment",
|
|
68
63
|
[
|
|
69
64
|
PropertyDef({ property: "containment", expectedType: "LionWebMetaPointer" }),
|
|
70
|
-
PropertyDef({ property: "children", expectedType: "
|
|
65
|
+
PropertyDef({ property: "children", expectedType: "LionWebId", isList: true }),
|
|
71
66
|
]
|
|
72
67
|
],
|
|
73
68
|
[
|
|
@@ -81,24 +76,37 @@ export const expectedTypes: Map<string, PropertyDefinition[]> = new Map([
|
|
|
81
76
|
"LionWebReferenceTarget",
|
|
82
77
|
[
|
|
83
78
|
PropertyDef({ property: "resolveInfo", expectedType: "string", mayBeNull: MAY_BE_NULL }),
|
|
84
|
-
PropertyDef({ property: "reference", expectedType: "
|
|
79
|
+
PropertyDef({ property: "reference", expectedType: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
85
80
|
]
|
|
86
81
|
],
|
|
87
82
|
/**
|
|
88
|
-
* Elements without properties are assumed to be JSON/JS primitive values, and tested using `typeof
|
|
83
|
+
* Elements without properties are assumed to be JSON/JS primitive values, and tested using `typeof`
|
|
84
|
+
* and the (optional) validate function.
|
|
89
85
|
*/
|
|
90
86
|
[
|
|
91
|
-
"
|
|
92
|
-
|
|
87
|
+
"LionWebId",
|
|
88
|
+
PrimitiveDef({ primitiveType: "string", validate: validateId }),
|
|
89
|
+
],
|
|
90
|
+
[
|
|
91
|
+
"LionWebKey",
|
|
92
|
+
PrimitiveDef({ primitiveType: "string", validate: validateKey }),
|
|
93
93
|
],
|
|
94
94
|
[
|
|
95
|
-
"
|
|
96
|
-
|
|
95
|
+
"LionWebVersion",
|
|
96
|
+
PrimitiveDef({ primitiveType: "string", validate: validateVersion }),
|
|
97
97
|
],
|
|
98
98
|
[
|
|
99
|
-
"
|
|
100
|
-
|
|
99
|
+
"LionWebSerializationFormatVersion",
|
|
100
|
+
PrimitiveDef({ primitiveType: "string", validate: validateSerializationFormatVersion }),
|
|
101
101
|
],
|
|
102
|
+
[
|
|
103
|
+
"string",
|
|
104
|
+
PrimitiveDef({ primitiveType: "string" }),
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
"object",
|
|
108
|
+
PrimitiveDef({ primitiveType: "object" }),
|
|
109
|
+
]
|
|
102
110
|
])
|
|
103
111
|
|
|
104
112
|
|
|
@@ -1,37 +1,35 @@
|
|
|
1
|
+
import { isEqualMetaPointer, LionWebJsonContainment, LionWebJsonNode, LionWebJsonProperty, LionWebJsonReference } from "@lionweb/json"
|
|
2
|
+
import {
|
|
3
|
+
JsonContext,
|
|
4
|
+
LION_CORE_BUILTINS_INAMED_NAME,
|
|
5
|
+
LIONWEB_BOOLEAN_TYPE, LIONWEB_INTEGER_TYPE, LIONWEB_JSON_TYPE, LIONWEB_STRING_TYPE,
|
|
6
|
+
LionWebJsonChunkWrapper,
|
|
7
|
+
M3_Keys,
|
|
8
|
+
MetaPointers,
|
|
9
|
+
NodeUtils
|
|
10
|
+
} from "@lionweb/json-utils"
|
|
1
11
|
import {
|
|
2
12
|
Language_ContainmentMetaPointerNotInClass_Issue,
|
|
3
|
-
Language_IncorrectPropertyMetaPointer_Issue,
|
|
4
|
-
|
|
13
|
+
Language_IncorrectPropertyMetaPointer_Issue,
|
|
14
|
+
Language_PropertyMetaPointerNotInClass_Issue,
|
|
15
|
+
Language_PropertyValue_Issue,
|
|
16
|
+
Language_ReferenceMetaPointerNotInClass_Issue,
|
|
5
17
|
Language_UnknownConcept_Issue
|
|
6
18
|
} from "../issues/index.js"
|
|
7
19
|
import {
|
|
8
20
|
Language_IncorrectContainmentMetaPointer_Issue,
|
|
9
21
|
Language_IncorrectReferenceMetaPointer_Issue,
|
|
10
|
-
Language_UnknownContainment_Issue,
|
|
22
|
+
Language_UnknownContainment_Issue,
|
|
23
|
+
Language_UnknownProperty_Issue,
|
|
11
24
|
Language_UnknownReference_Issue
|
|
12
25
|
} from "../issues/LanguageIssues.js"
|
|
13
|
-
import { isEqualMetaPointer, LionWebJsonNode, MetaPointers, NodeUtils } from "../json/index.js"
|
|
14
|
-
import { JsonContext } from "../json/JsonContext.js"
|
|
15
|
-
import {
|
|
16
|
-
LionWebJsonContainment,
|
|
17
|
-
LionWebJsonProperty,
|
|
18
|
-
LionWebJsonReference,
|
|
19
|
-
} from "../json/LionWebJson.js"
|
|
20
|
-
import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js"
|
|
21
26
|
// import {
|
|
22
27
|
// KnownLanguages, LanguageRegistry
|
|
23
28
|
// } from "../languages/LanguageRegistry.js"
|
|
24
|
-
import {
|
|
25
|
-
LION_CORE_BUILTINS_INAMED_NAME,
|
|
26
|
-
LIONWEB_BOOLEAN_TYPE,
|
|
27
|
-
LIONWEB_INTEGER_TYPE,
|
|
28
|
-
LIONWEB_JSON_TYPE,
|
|
29
|
-
LIONWEB_STRING_TYPE,
|
|
30
|
-
M3_Keys
|
|
31
|
-
} from "../json/M3definitions.js"
|
|
32
29
|
import { LanguageRegistry } from "../languages/index.js"
|
|
33
|
-
import { validateBoolean, validateInteger, validateJSON } from "./ValidationFunctions.js"
|
|
34
30
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
31
|
+
import { validateBoolean, validateInteger, validateJSON } from "./ValidationFunctions.js"
|
|
32
|
+
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* Check against the language definition
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { isEqualMetaPointer, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
|
|
2
|
+
import { isLionWebM3Language, JsonContext, LionWebJsonChunkWrapper, MetaPointers } from "@lionweb/json-utils"
|
|
1
3
|
import { GenericIssue } from "../issues/index.js"
|
|
2
4
|
import { MissingM3Language_Issue } from "../issues/LanguageIssues.js"
|
|
3
|
-
import { isEqualMetaPointer, LionWebJsonNode, MetaPointers } from "../json/index.js"
|
|
4
|
-
import { JsonContext } from "../json/JsonContext.js"
|
|
5
|
-
import { isLionWebM3Language, LionWebJsonChunk } from "../json/LionWebJson.js"
|
|
6
|
-
import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js"
|
|
7
5
|
import { isConcept, LanguageRegistry } from "../languages/index.js"
|
|
8
6
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
9
7
|
|
|
@@ -1,21 +1,13 @@
|
|
|
1
|
+
import { LionWebId, LionWebJsonChunk, LionWebJsonContainment, LionWebJsonMetaPointer, LionWebJsonNode, LionWebJsonUsedLanguage } from "@lionweb/json"
|
|
2
|
+
import { ChunkUtils, JsonContext, LionWebJsonChunkWrapper } from "@lionweb/json-utils"
|
|
1
3
|
import {
|
|
2
4
|
Duplicates_Issue,
|
|
3
5
|
Reference_ChildMissingInParent_Issue,
|
|
4
6
|
Reference_CirculairParent_Issue,
|
|
5
7
|
Reference_DuplicateNodeId_Issue,
|
|
6
8
|
Reference_LanguageUnknown_Issue,
|
|
7
|
-
Reference_ParentMissingInChild_Issue
|
|
9
|
+
Reference_ParentMissingInChild_Issue
|
|
8
10
|
} from "../issues/ReferenceIssues.js"
|
|
9
|
-
import { JsonContext } from "../json/JsonContext.js"
|
|
10
|
-
import { ChunkUtils } from "../json/ChunkUtils.js"
|
|
11
|
-
import {
|
|
12
|
-
LionWebJsonContainment,
|
|
13
|
-
LionWebJsonChunk,
|
|
14
|
-
LionWebJsonMetaPointer,
|
|
15
|
-
LionWebJsonNode,
|
|
16
|
-
LwJsonUsedLanguage,
|
|
17
|
-
} from "../json/LionWebJson.js"
|
|
18
|
-
import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper.js"
|
|
19
11
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
20
12
|
|
|
21
13
|
/**
|
|
@@ -136,7 +128,7 @@ export class LionWebReferenceValidator {
|
|
|
136
128
|
* @param usedLanguages
|
|
137
129
|
* @param context
|
|
138
130
|
*/
|
|
139
|
-
checkDuplicateUsedLanguage(usedLanguages:
|
|
131
|
+
checkDuplicateUsedLanguage(usedLanguages: LionWebJsonUsedLanguage[], context: JsonContext) {
|
|
140
132
|
if (usedLanguages === null || usedLanguages === undefined) {
|
|
141
133
|
return
|
|
142
134
|
}
|
|
@@ -197,7 +189,7 @@ export class LionWebReferenceValidator {
|
|
|
197
189
|
|
|
198
190
|
validateChildrenHaveCorrectParent(node: LionWebJsonNode, context: JsonContext) {
|
|
199
191
|
node.containments.forEach((child: LionWebJsonContainment) => {
|
|
200
|
-
child.children.forEach((childId:
|
|
192
|
+
child.children.forEach((childId: LionWebId, index: number) => {
|
|
201
193
|
const childNode = this.nodesIdMap.get(childId)
|
|
202
194
|
if (childNode !== undefined) {
|
|
203
195
|
if (childNode.parent !== node.id) {
|
|
@@ -211,7 +203,7 @@ export class LionWebReferenceValidator {
|
|
|
211
203
|
}
|
|
212
204
|
})
|
|
213
205
|
})
|
|
214
|
-
node.annotations.forEach((annotationId:
|
|
206
|
+
node.annotations.forEach((annotationId: LionWebId, annotationIndex: number) => {
|
|
215
207
|
const childNode = this.nodesIdMap.get(annotationId)
|
|
216
208
|
if (childNode !== undefined) {
|
|
217
209
|
if (childNode.parent === null || childNode.parent === undefined) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expectedTypes } from "./LionWebChunkDefinitions.js"
|
|
2
1
|
import { SyntaxValidator } from "./generic/SyntaxValidator.js"
|
|
3
2
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
3
|
+
import { expectedTypes } from "./LionWebChunkDefinitions.js"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* LionWebSyntaxValidator can check whether objects are structurally LionWeb objects.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { LionWebJsonChunk } from "
|
|
2
|
-
import { LionWebJsonChunkWrapper } from "
|
|
1
|
+
import { LionWebJsonChunk } from "@lionweb/json"
|
|
2
|
+
import { LionWebJsonChunkWrapper } from "@lionweb/json-utils"
|
|
3
3
|
import { LanguageRegistry } from "../languages/index.js"
|
|
4
|
+
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
4
5
|
import { LionWebLanguageReferenceValidator } from "./LionWebLanguageReferenceValidator.js"
|
|
5
6
|
import { LionWebReferenceValidator } from "./LionWebReferenceValidator.js"
|
|
6
7
|
import { LionWebSyntaxValidator } from "./LionWebSyntaxValidator.js"
|
|
7
|
-
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Combined validator that calls all available validators.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* A list of functions that are used to validate primitive fields for LionWeb conformance.
|
|
3
3
|
* Used in the LionWebSyntaxValidator.
|
|
4
4
|
*/
|
|
5
|
+
import { JsonContext } from "@lionweb/json-utils"
|
|
5
6
|
import { Language_PropertyValue_Issue } from "../issues/LanguageIssues.js"
|
|
6
7
|
import {
|
|
7
8
|
Syntax_IdFormat_Issue,
|
|
@@ -10,7 +11,6 @@ import {
|
|
|
10
11
|
Syntax_SerializationFormatVersion_Issue,
|
|
11
12
|
Syntax_VersionFormat_Issue
|
|
12
13
|
} from "../issues/SyntaxIssues.js"
|
|
13
|
-
import { JsonContext } from "../json/JsonContext.js"
|
|
14
14
|
import { ValidationResult } from "./generic/ValidationResult.js"
|
|
15
15
|
import { PropertyDefinition } from "./generic/ValidationTypes.js"
|
|
16
16
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonContext } from "@lionweb/json-utils"
|
|
1
2
|
import {
|
|
2
3
|
Syntax_ArrayContainsNull_Issue,
|
|
3
4
|
Syntax_PropertyMissingIssue,
|
|
@@ -5,21 +6,27 @@ import {
|
|
|
5
6
|
Syntax_PropertyTypeIssue,
|
|
6
7
|
Syntax_PropertyUnknownIssue
|
|
7
8
|
} from "../../issues/index.js"
|
|
8
|
-
import { JsonContext } from "../../json/JsonContext.js"
|
|
9
9
|
import { ValidationResult } from "./ValidationResult.js"
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
isObjectDefinition,
|
|
12
|
+
isPrimitiveDefinition,
|
|
13
|
+
ObjectDefinition,
|
|
14
|
+
PrimitiveDefinition,
|
|
15
|
+
TypeDefinition,
|
|
16
|
+
UnknownObjectType
|
|
17
|
+
} from "./ValidationTypes.js"
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* Syntax Validator can check whether objects are structurally conforming to the
|
|
14
|
-
* definitions given in `
|
|
21
|
+
* definitions given in `typeDefinitions`.
|
|
15
22
|
*/
|
|
16
23
|
export class SyntaxValidator {
|
|
17
24
|
validationResult: ValidationResult
|
|
18
|
-
|
|
25
|
+
typeDefinitions: Map<string, TypeDefinition>
|
|
19
26
|
|
|
20
|
-
constructor(validationResult: ValidationResult, expectedTypes: Map<string,
|
|
27
|
+
constructor(validationResult: ValidationResult, expectedTypes: Map<string, TypeDefinition>) {
|
|
21
28
|
this.validationResult = validationResult
|
|
22
|
-
this.
|
|
29
|
+
this.typeDefinitions = expectedTypes
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
/**
|
|
@@ -29,115 +36,119 @@ export class SyntaxValidator {
|
|
|
29
36
|
* @param expectedType The expected type of the object.
|
|
30
37
|
*/
|
|
31
38
|
validate(obj: unknown, expectedType: string) {
|
|
32
|
-
if (typeof obj !== "object") {
|
|
33
|
-
throw new Error(`SyntaxValidator.validate: 'obj' is not an object, expected a '${expectedType}'`)
|
|
34
|
-
}
|
|
35
39
|
const object = obj as UnknownObjectType
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
40
|
+
const typeDef = this.typeDefinitions.get(expectedType)
|
|
41
|
+
if (typeDef === undefined) {
|
|
38
42
|
throw new Error(`SyntaxValidator.validate: cannot find definition for ${expectedType}`)
|
|
39
|
-
} else {
|
|
40
|
-
this.validateObjectProperties(expectedType,
|
|
43
|
+
} else if (isObjectDefinition(typeDef)){
|
|
44
|
+
this.validateObjectProperties(expectedType, typeDef, object, new JsonContext(null, ["$"]))
|
|
45
|
+
} else if( isPrimitiveDefinition(typeDef)) {
|
|
46
|
+
this.validatePrimitiveValue("$", typeDef, object, new JsonContext(null, ["$"]))
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
/**
|
|
45
51
|
* Validate whether `object` is structured conform the properties in `propertyDef`
|
|
46
52
|
* @param originalProperty The property of which `object` it the value
|
|
47
|
-
* @param
|
|
53
|
+
* @param typeDef The property definitions that are being validated
|
|
48
54
|
* @param object The object being validated
|
|
49
55
|
* @param jsonContext The location in the JSON
|
|
50
56
|
* @private
|
|
51
57
|
*/
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
if ((typeof object) !== "object") {
|
|
57
|
-
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, originalProperty, "object", typeof object))
|
|
58
|
+
validateObjectProperties(originalProperty: string, typeDef: ObjectDefinition, object: UnknownObjectType, jsonContext: JsonContext) {
|
|
59
|
+
if (typeDef === null || typeDef === undefined) {
|
|
58
60
|
return
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const propertyValue = object[pdef.property]
|
|
64
|
-
if (propertyValue === undefined) {
|
|
65
|
-
this.validationResult.issue(new Syntax_PropertyMissingIssue(jsonContext, pdef.property + `{ ${typeof object}}{${originalProperty}}`))
|
|
66
|
-
continue
|
|
67
|
-
}
|
|
68
|
-
if (!pdef.mayBeNull && propertyValue === null) {
|
|
69
|
-
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, pdef.property))
|
|
70
|
-
continue
|
|
71
|
-
}
|
|
72
|
-
if (pdef.mayBeNull && propertyValue === null) {
|
|
73
|
-
// Ok, stop checking, continue with next property def
|
|
74
|
-
continue
|
|
62
|
+
if ((typeof object) !== "object") {
|
|
63
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, originalProperty, "object", typeof object))
|
|
64
|
+
return
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
for (const propertyDef of typeDef) {
|
|
67
|
+
const expectedTypeDef = this.typeDefinitions.get(propertyDef.expectedType)
|
|
68
|
+
const validator = propertyDef.validate!
|
|
69
|
+
const propertyValue = object[propertyDef.property]
|
|
70
|
+
if (propertyValue === undefined) {
|
|
71
|
+
if (!propertyDef.isOptional) {
|
|
72
|
+
this.validationResult.issue(new Syntax_PropertyMissingIssue(jsonContext, propertyDef.property))
|
|
73
|
+
}
|
|
74
|
+
continue
|
|
82
75
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
if (!propertyDef.mayBeNull && propertyValue === null) {
|
|
77
|
+
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propertyDef.property))
|
|
78
|
+
continue
|
|
79
|
+
}
|
|
80
|
+
if (propertyDef.mayBeNull && propertyValue === null) {
|
|
81
|
+
// Ok, stop checking, continue with next property def
|
|
82
|
+
continue
|
|
83
|
+
}
|
|
84
|
+
if (propertyDef.isList) {
|
|
85
|
+
// Check whether value is an array
|
|
86
|
+
if (!Array.isArray(propertyValue)) {
|
|
87
|
+
const newContext = jsonContext.concat(propertyDef.property)
|
|
88
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.property, "array", typeof propertyValue))
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
// If an array, validate every item in the array
|
|
92
|
+
(propertyValue as UnknownObjectType[]).forEach((item, index) => {
|
|
93
|
+
const newContext = jsonContext.concat(propertyDef.property, index)
|
|
94
|
+
if (item === null) {
|
|
95
|
+
this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext, propertyDef.property, index))
|
|
96
|
+
} else {
|
|
97
|
+
if (expectedTypeDef !== undefined) {
|
|
98
|
+
if (isPrimitiveDefinition(expectedTypeDef)) {
|
|
99
|
+
// propertyValue should be a primitive as it has no property definitions
|
|
100
|
+
if (this.validatePrimitiveValue(propertyDef.property, expectedTypeDef, item, jsonContext)) {
|
|
101
|
+
validator.apply(null, [item, this.validationResult, newContext, propertyDef])
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
// propertyValue should be an object, validate its properties
|
|
105
|
+
this.validateObjectProperties(propertyDef.property, expectedTypeDef, item as UnknownObjectType, newContext)
|
|
106
|
+
validator.apply(null, [item, this.validationResult, newContext, propertyDef])
|
|
94
107
|
}
|
|
95
108
|
} else {
|
|
96
|
-
|
|
97
|
-
this.validateObjectProperties(pdef.property, expectedPropertyDefs, item as UnknownObjectType, newContext)
|
|
98
|
-
validator.apply(null, [item, this.validationResult, newContext, pdef])
|
|
109
|
+
throw new Error(`Expected type '${propertyDef.expectedType} has neither property defs, nor a validator.`)
|
|
99
110
|
}
|
|
100
|
-
} else {
|
|
101
|
-
throw new Error(`Expected type '${pdef.expectedType} has neither property defs, nor a validator.`)
|
|
102
111
|
}
|
|
112
|
+
})
|
|
113
|
+
} else {
|
|
114
|
+
const newContext = jsonContext.concat(propertyDef.property)
|
|
115
|
+
if (Array.isArray(propertyValue)) {
|
|
116
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.property, propertyDef.expectedType, "array"))
|
|
117
|
+
return
|
|
103
118
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
// Single valued property, validate it
|
|
120
|
+
if (expectedTypeDef !== undefined) {
|
|
121
|
+
if (isPrimitiveDefinition(expectedTypeDef)) {
|
|
122
|
+
// propertyValue should be a primitive as it has no property definitions
|
|
123
|
+
if (this.validatePrimitiveValue(propertyDef.property, expectedTypeDef, propertyValue, jsonContext)) {
|
|
124
|
+
validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef])
|
|
125
|
+
}
|
|
126
|
+
} else if (isObjectDefinition(expectedTypeDef)) {
|
|
127
|
+
// propertyValue should be an object, validate its properties
|
|
128
|
+
this.validateObjectProperties(propertyDef.property, expectedTypeDef, propertyValue as UnknownObjectType, newContext)
|
|
129
|
+
validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef])
|
|
130
|
+
} else {
|
|
131
|
+
throw new Error("EXPECTING ObjectDefinition or PrimitiveDefinition, but got something else")
|
|
117
132
|
}
|
|
118
133
|
} else {
|
|
119
|
-
|
|
120
|
-
this.validateObjectProperties(pdef.property, expectedPropertyDefs, propertyValue as UnknownObjectType, newContext)
|
|
121
|
-
validator.apply(null, [propertyValue, this.validationResult, newContext, pdef])
|
|
134
|
+
throw new Error(`Expected single type '${propertyDef.expectedType}' for '${propertyDef.property}' at ${newContext.toString()} has neither property defs, nor a validator.`)
|
|
122
135
|
}
|
|
123
|
-
} else {
|
|
124
|
-
throw new Error(`Expected single type '${pdef.expectedType}' for '${pdef.property}' at ${newContext.toString()} has neither property defs, nor a validator.`)
|
|
125
136
|
}
|
|
126
137
|
}
|
|
127
|
-
|
|
128
|
-
this.checkStrayProperties(object, propertyDef.map(pdef => pdef.property ), jsonContext)
|
|
138
|
+
this.checkStrayProperties(object, typeDef, jsonContext)
|
|
129
139
|
}
|
|
130
140
|
|
|
131
|
-
validatePrimitiveValue(propDef:
|
|
132
|
-
if (!propDef.mayBeNull && (object === null || object === undefined)) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
141
|
+
validatePrimitiveValue(propertyName: string, propDef: PrimitiveDefinition, object: unknown, jsonContext: JsonContext): boolean {
|
|
142
|
+
// if (!propDef.mayBeNull && (object === null || object === undefined)) {
|
|
143
|
+
// this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propDef.property))
|
|
144
|
+
// return false
|
|
145
|
+
// }
|
|
136
146
|
|
|
137
|
-
if (typeof object !== propDef.
|
|
138
|
-
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext,
|
|
147
|
+
if (typeof object !== propDef.primitiveType) {
|
|
148
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, propertyName, propDef.primitiveType,typeof object))
|
|
139
149
|
return false
|
|
140
150
|
}
|
|
151
|
+
propDef.validate!(object, this.validationResult, jsonContext)
|
|
141
152
|
return true
|
|
142
153
|
}
|
|
143
154
|
|
|
@@ -147,17 +158,13 @@ export class SyntaxValidator {
|
|
|
147
158
|
* @param properties The names of the expected properties
|
|
148
159
|
* @param context Location in JSON
|
|
149
160
|
*/
|
|
150
|
-
checkStrayProperties(obj: UnknownObjectType,
|
|
161
|
+
checkStrayProperties(obj: UnknownObjectType, def: ObjectDefinition, context: JsonContext) {
|
|
151
162
|
const own = Object.getOwnPropertyNames(obj)
|
|
163
|
+
const defined = def.map(pdef => pdef.property)
|
|
152
164
|
own.forEach((ownProp) => {
|
|
153
|
-
if (!
|
|
165
|
+
if (!defined.includes(ownProp)) {
|
|
154
166
|
this.validationResult.issue(new Syntax_PropertyUnknownIssue(context, ownProp))
|
|
155
167
|
}
|
|
156
168
|
})
|
|
157
|
-
properties.forEach((prop) => {
|
|
158
|
-
if (!own.includes(prop)) {
|
|
159
|
-
this.validationResult.issue(new Syntax_PropertyMissingIssue(context, prop))
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
169
|
}
|
|
163
170
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { JsonContext } from "
|
|
1
|
+
import { JsonContext } from "@lionweb/json-utils"
|
|
2
2
|
import { ValidationResult } from "./ValidationResult.js"
|
|
3
3
|
|
|
4
4
|
export type UnknownObjectType = { [key: string]: unknown }
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Definition of a property, used by the SyntaxValidator to validate objects.
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* **Note** that some of the properties are defined as optional.
|
|
10
10
|
* They should not be empty ever!! But being optional allows to leave them out in the `PropertyDef` function.
|
|
11
11
|
* The `PropertyDef` function sets default values for all optional fields.
|
|
@@ -28,6 +28,10 @@ export type PropertyDefinition = {
|
|
|
28
28
|
* IS this a list property?
|
|
29
29
|
*/
|
|
30
30
|
isList?: boolean,
|
|
31
|
+
/**
|
|
32
|
+
* Is this property optional?
|
|
33
|
+
*/
|
|
34
|
+
isOptional?: boolean,
|
|
31
35
|
/**
|
|
32
36
|
* Additional validation function
|
|
33
37
|
*/
|
|
@@ -44,7 +48,7 @@ export type ValidatorFunction = <T>(obj: T, result: ValidationResult, ctx: JsonC
|
|
|
44
48
|
* @param pdef
|
|
45
49
|
*/
|
|
46
50
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
|
-
function emptyValidation<T>(object: T, result: ValidationResult, ctx: JsonContext,
|
|
51
|
+
function emptyValidation<T>(object: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition): void {}
|
|
48
52
|
|
|
49
53
|
// Make boolean argument more readable.
|
|
50
54
|
export const MAY_BE_NULL = true
|
|
@@ -55,13 +59,46 @@ export const MAY_BE_NULL = true
|
|
|
55
59
|
* @constructor
|
|
56
60
|
*/
|
|
57
61
|
export function PropertyDef(propDef: PropertyDefinition): PropertyDefinition {
|
|
58
|
-
const { property, expectedType, mayBeNull = false, isList = false, validate = emptyValidation } = propDef
|
|
62
|
+
const { property, expectedType, mayBeNull = false, isList = false, isOptional = false, validate = emptyValidation } = propDef
|
|
59
63
|
return {
|
|
60
64
|
property: property,
|
|
61
65
|
expectedType: expectedType,
|
|
62
66
|
isList: isList,
|
|
63
67
|
mayBeNull: mayBeNull,
|
|
68
|
+
isOptional: isOptional,
|
|
64
69
|
validate: validate
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
|
|
73
|
+
export type PrimitiveDefinition = {
|
|
74
|
+
/**
|
|
75
|
+
* The expected type of the property value
|
|
76
|
+
*/
|
|
77
|
+
primitiveType: string
|
|
78
|
+
/**
|
|
79
|
+
* Additional validation function
|
|
80
|
+
*/
|
|
81
|
+
validate?: ValidatorFunction
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Easy way to create a PropertyDefinition typed object with default values.
|
|
85
|
+
* @param propDef
|
|
86
|
+
* @constructor
|
|
87
|
+
*/
|
|
88
|
+
export function PrimitiveDef(propDef: PrimitiveDefinition): PrimitiveDefinition {
|
|
89
|
+
const { primitiveType, validate = emptyValidation } = propDef
|
|
90
|
+
return {
|
|
91
|
+
primitiveType: primitiveType,
|
|
92
|
+
validate: validate
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export type ObjectDefinition = PropertyDefinition[]
|
|
96
|
+
export type TypeDefinition = ObjectDefinition | PrimitiveDefinition
|
|
97
|
+
|
|
98
|
+
export function isObjectDefinition(def: TypeDefinition): def is ObjectDefinition {
|
|
99
|
+
return Array.isArray(def)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function isPrimitiveDefinition(def: TypeDefinition): def is PrimitiveDefinition {
|
|
103
|
+
return (def as PrimitiveDefinition)?.primitiveType !== undefined
|
|
104
|
+
}
|