@lionweb/validation 0.6.13-beta.7 → 0.7.0-alpha.10
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 +4 -4
- 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/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/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 +82 -79
- 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 +2 -2
- 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 +3 -3
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/dist/validators/ValidationFunctions.d.ts +6 -2
- package/dist/validators/ValidationFunctions.d.ts.map +1 -1
- package/dist/validators/ValidationFunctions.js +4 -8
- package/dist/validators/ValidationFunctions.js.map +1 -1
- package/dist/validators/generic/SyntaxValidator.d.ts +11 -11
- package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -1
- package/dist/validators/generic/SyntaxValidator.js +62 -64
- package/dist/validators/generic/SyntaxValidator.js.map +1 -1
- package/dist/validators/generic/index.d.ts +1 -2
- package/dist/validators/generic/index.d.ts.map +1 -1
- package/dist/validators/generic/index.js +1 -2
- 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/schema/ValidationTypes.d.ts +101 -0
- package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
- package/dist/validators/generic/schema/ValidationTypes.js +43 -0
- 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/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 +10 -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 +10 -7
- 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/runners/Utils.ts +2 -2
- package/src/validators/LionWebChunkDefinitions.ts +83 -85
- 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 +2 -2
- package/src/validators/LionWebValidator.ts +4 -4
- package/src/validators/ValidationFunctions.ts +6 -6
- package/src/validators/generic/SyntaxValidator.ts +70 -69
- package/src/validators/generic/index.ts +1 -2
- package/src/validators/generic/schema/DefinitionSchema.ts +52 -0
- package/src/validators/generic/schema/ValidationTypes.ts +134 -0
- package/src/validators/generic/schema/index.ts +2 -0
- 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/dist/validators/generic/ValidationTypes.d.ts +0 -44
- package/dist/validators/generic/ValidationTypes.d.ts.map +0 -1
- package/dist/validators/generic/ValidationTypes.js +0 -27
- package/dist/validators/generic/ValidationTypes.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
- package/src/validators/generic/ValidationTypes.ts +0 -67
|
@@ -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 { LionWebSchema } from "./LionWebChunkDefinitions.js"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* LionWebSyntaxValidator can check whether objects are structurally LionWeb objects.
|
|
@@ -8,7 +8,7 @@ import { ValidationResult } from "./generic/ValidationResult.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
|
|
|
@@ -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.
|
|
@@ -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)
|
|
@@ -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,9 +11,8 @@ 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
|
-
import { PropertyDefinition } from "./generic/ValidationTypes.js"
|
|
15
|
+
import { PropertyDefinition } from "./generic/schema/ValidationTypes.js"
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Check whether `id` is a valid LionWeb id.
|
|
@@ -72,7 +72,7 @@ export function validateBoolean<String>(value: String, result: ValidationResult,
|
|
|
72
72
|
result.issue(
|
|
73
73
|
new Language_PropertyValue_Issue(
|
|
74
74
|
context,
|
|
75
|
-
propDef ? propDef.
|
|
75
|
+
propDef ? propDef.name : "unknown",
|
|
76
76
|
valueAsPrimitive,
|
|
77
77
|
"boolean " + JSON.stringify(value)
|
|
78
78
|
)
|
|
@@ -92,7 +92,7 @@ export function validateInteger<String>(value: String, result: ValidationResult,
|
|
|
92
92
|
const valueAsPrimitive = "" + value
|
|
93
93
|
const regexp = /^[+-]?(0|[1-9][0-9]*)$/
|
|
94
94
|
if (valueAsPrimitive === null || !regexp.test(valueAsPrimitive)) {
|
|
95
|
-
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.
|
|
95
|
+
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "integer"))
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -107,12 +107,12 @@ export function validateInteger<String>(value: String, result: ValidationResult,
|
|
|
107
107
|
export function validateJSON<String>(value: String, result: ValidationResult, context: JsonContext, propDef?: PropertyDefinition): void {
|
|
108
108
|
const valueAsPrimitive = "" + value
|
|
109
109
|
if (value === null) {
|
|
110
|
-
result.issue(new Syntax_PropertyNullIssue(context, propDef!.
|
|
110
|
+
result.issue(new Syntax_PropertyNullIssue(context, propDef!.name!))
|
|
111
111
|
}
|
|
112
112
|
try {
|
|
113
113
|
JSON.parse(valueAsPrimitive)
|
|
114
114
|
} catch (e) {
|
|
115
|
-
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.
|
|
115
|
+
result.issue(new Language_PropertyValue_Issue(context, propDef ? propDef.name : "unknown", valueAsPrimitive, "JSON"))
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JsonContext } from "@lionweb/json-utils"
|
|
1
2
|
import {
|
|
2
3
|
Syntax_ArrayContainsNull_Issue,
|
|
3
4
|
Syntax_PropertyMissingIssue,
|
|
@@ -5,139 +6,143 @@ 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, ObjectDefinition, PrimitiveDefinition, DefinitionSchema,
|
|
13
|
+
UnknownObjectType
|
|
14
|
+
} from "./schema/index.js"
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
|
-
* Syntax Validator
|
|
14
|
-
* definitions given in `
|
|
17
|
+
* Syntax Validator checks whether objects are structurally conforming to the
|
|
18
|
+
* definitions given in `schema`.
|
|
15
19
|
*/
|
|
16
20
|
export class SyntaxValidator {
|
|
17
21
|
validationResult: ValidationResult
|
|
18
|
-
|
|
22
|
+
schema: DefinitionSchema
|
|
19
23
|
|
|
20
|
-
constructor(validationResult: ValidationResult,
|
|
24
|
+
constructor(validationResult: ValidationResult, schema: DefinitionSchema) {
|
|
21
25
|
this.validationResult = validationResult
|
|
22
|
-
this.
|
|
26
|
+
this.schema = schema
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* Check whether `obj` is a JSON object that conforms to the definition of `expectedType`.
|
|
27
|
-
* All errors found will be
|
|
31
|
+
* All errors found will be added to the `validationResult` object.
|
|
28
32
|
* @param obj The object to validate.
|
|
29
33
|
* @param expectedType The expected type of the object.
|
|
30
34
|
*/
|
|
31
35
|
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
36
|
const object = obj as UnknownObjectType
|
|
36
|
-
const
|
|
37
|
-
|
|
37
|
+
const typeDef = this.schema.getDefinition(expectedType)
|
|
38
|
+
|
|
39
|
+
if (typeDef === undefined) {
|
|
38
40
|
throw new Error(`SyntaxValidator.validate: cannot find definition for ${expectedType}`)
|
|
39
|
-
} else {
|
|
40
|
-
this.validateObjectProperties(expectedType,
|
|
41
|
+
} else if (isObjectDefinition(typeDef)) {
|
|
42
|
+
this.validateObjectProperties(expectedType, typeDef, object, new JsonContext(null, ["$"]))
|
|
43
|
+
} else if (isPrimitiveDefinition(typeDef)) {
|
|
44
|
+
this.validatePrimitiveValue("$", typeDef, object, new JsonContext(null, ["$"]))
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
49
|
* Validate whether `object` is structured conform the properties in `propertyDef`
|
|
46
50
|
* @param originalProperty The property of which `object` it the value
|
|
47
|
-
* @param
|
|
51
|
+
* @param typeDef The property definitions that are being validated
|
|
48
52
|
* @param object The object being validated
|
|
49
53
|
* @param jsonContext The location in the JSON
|
|
50
54
|
* @private
|
|
51
55
|
*/
|
|
52
|
-
|
|
53
|
-
if (
|
|
56
|
+
validateObjectProperties(originalProperty: string, typeDef: ObjectDefinition, object: UnknownObjectType, jsonContext: JsonContext) {
|
|
57
|
+
if (typeDef === null || typeDef === undefined) {
|
|
54
58
|
return
|
|
55
59
|
}
|
|
56
|
-
if (
|
|
60
|
+
if (typeof object !== "object") {
|
|
57
61
|
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, originalProperty, "object", typeof object))
|
|
58
62
|
return
|
|
59
63
|
}
|
|
60
|
-
for (const
|
|
61
|
-
const
|
|
62
|
-
const validator =
|
|
63
|
-
const propertyValue = object[
|
|
64
|
+
for (const propertyDef of typeDef.properties) {
|
|
65
|
+
const expectedTypeDef = this.schema.getDefinition(propertyDef.type)
|
|
66
|
+
const validator = propertyDef.validate!
|
|
67
|
+
const propertyValue = object[propertyDef.name]
|
|
64
68
|
if (propertyValue === undefined) {
|
|
65
|
-
|
|
69
|
+
if (!propertyDef.isOptional) {
|
|
70
|
+
this.validationResult.issue(new Syntax_PropertyMissingIssue(jsonContext, propertyDef.name))
|
|
71
|
+
}
|
|
66
72
|
continue
|
|
67
73
|
}
|
|
68
|
-
if (!
|
|
69
|
-
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext,
|
|
74
|
+
if (!propertyDef.mayBeNull && propertyValue === null) {
|
|
75
|
+
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propertyDef.name))
|
|
70
76
|
continue
|
|
71
77
|
}
|
|
72
|
-
if (
|
|
78
|
+
if (propertyDef.mayBeNull && propertyValue === null) {
|
|
73
79
|
// Ok, stop checking, continue with next property def
|
|
74
80
|
continue
|
|
75
81
|
}
|
|
76
|
-
if (
|
|
82
|
+
if (propertyDef.isList) {
|
|
77
83
|
// Check whether value is an array
|
|
78
84
|
if (!Array.isArray(propertyValue)) {
|
|
79
|
-
const newContext = jsonContext.concat(
|
|
80
|
-
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext,
|
|
85
|
+
const newContext = jsonContext.concat(propertyDef.name)
|
|
86
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.name, "array", typeof propertyValue))
|
|
81
87
|
return
|
|
82
88
|
}
|
|
83
89
|
// If an array, validate every item in the array
|
|
84
|
-
(propertyValue as UnknownObjectType[]).forEach(
|
|
85
|
-
const newContext = jsonContext.concat(
|
|
90
|
+
(propertyValue as UnknownObjectType[]).forEach((item, index) => {
|
|
91
|
+
const newContext = jsonContext.concat(propertyDef.name, index)
|
|
86
92
|
if (item === null) {
|
|
87
|
-
this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext,
|
|
93
|
+
this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext, propertyDef.name, index))
|
|
88
94
|
} else {
|
|
89
|
-
if (
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
validator.apply(null, [item, this.validationResult, newContext, pdef])
|
|
95
|
+
if (expectedTypeDef !== undefined) {
|
|
96
|
+
if (isPrimitiveDefinition(expectedTypeDef)) {
|
|
97
|
+
if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, item, jsonContext)) {
|
|
98
|
+
validator.apply(null, [item, this.validationResult, newContext, propertyDef])
|
|
94
99
|
}
|
|
95
100
|
} else {
|
|
96
101
|
// propertyValue should be an object, validate its properties
|
|
97
|
-
this.validateObjectProperties(
|
|
98
|
-
validator.apply(null, [item, this.validationResult, newContext,
|
|
102
|
+
this.validateObjectProperties(propertyDef.name, expectedTypeDef, item as UnknownObjectType, newContext)
|
|
103
|
+
validator.apply(null, [item, this.validationResult, newContext, propertyDef])
|
|
99
104
|
}
|
|
100
105
|
} else {
|
|
101
|
-
throw new Error(`Expected type '${
|
|
106
|
+
throw new Error(`Expected type '${propertyDef.type} has neither property defs, nor a validator.`)
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
|
-
})
|
|
109
|
+
})
|
|
105
110
|
} else {
|
|
106
|
-
const newContext = jsonContext.concat(
|
|
111
|
+
const newContext = jsonContext.concat(propertyDef.name)
|
|
107
112
|
if (Array.isArray(propertyValue)) {
|
|
108
|
-
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext,
|
|
113
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.name, propertyDef.type, "array"))
|
|
109
114
|
return
|
|
110
115
|
}
|
|
111
116
|
// Single valued property, validate it
|
|
112
|
-
if (
|
|
113
|
-
if (
|
|
117
|
+
if (expectedTypeDef !== undefined) {
|
|
118
|
+
if (isPrimitiveDefinition(expectedTypeDef)) {
|
|
114
119
|
// propertyValue should be a primitive as it has no property definitions
|
|
115
|
-
if (this.validatePrimitiveValue(
|
|
116
|
-
validator.apply(null, [propertyValue, this.validationResult, newContext,
|
|
120
|
+
if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, propertyValue, jsonContext)) {
|
|
121
|
+
validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef])
|
|
117
122
|
}
|
|
118
|
-
} else {
|
|
123
|
+
} else if (isObjectDefinition(expectedTypeDef)) {
|
|
119
124
|
// propertyValue should be an object, validate its properties
|
|
120
|
-
this.validateObjectProperties(
|
|
121
|
-
validator.apply(null, [propertyValue, this.validationResult, newContext,
|
|
125
|
+
this.validateObjectProperties(propertyDef.name, expectedTypeDef, propertyValue as UnknownObjectType, newContext)
|
|
126
|
+
validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef])
|
|
127
|
+
} else {
|
|
128
|
+
throw new Error("EXPECTING ObjectDefinition or PrimitiveDefinition, but got something else")
|
|
122
129
|
}
|
|
123
130
|
} else {
|
|
124
|
-
throw new Error(
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Expected single type '${propertyDef.type}' for '${propertyDef.name}' at ${newContext.toString()} has neither property defs, nor a validator.`
|
|
133
|
+
)
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
}
|
|
128
|
-
this.checkStrayProperties(object,
|
|
137
|
+
this.checkStrayProperties(object, typeDef, jsonContext)
|
|
129
138
|
}
|
|
130
|
-
|
|
131
|
-
validatePrimitiveValue(propDef: PropertyDefinition, object: unknown, jsonContext: JsonContext): boolean {
|
|
132
|
-
if (!propDef.mayBeNull && (object === null || object === undefined)) {
|
|
133
|
-
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propDef.property))
|
|
134
|
-
return false
|
|
135
|
-
}
|
|
136
139
|
|
|
137
|
-
|
|
138
|
-
|
|
140
|
+
validatePrimitiveValue(propertyName: string, propDef: PrimitiveDefinition, object: unknown, jsonContext: JsonContext): boolean {
|
|
141
|
+
if (typeof object !== propDef.primitiveType) {
|
|
142
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, propertyName, propDef.primitiveType, typeof object))
|
|
139
143
|
return false
|
|
140
144
|
}
|
|
145
|
+
propDef.validate!(object, this.validationResult, jsonContext)
|
|
141
146
|
return true
|
|
142
147
|
}
|
|
143
148
|
|
|
@@ -147,17 +152,13 @@ export class SyntaxValidator {
|
|
|
147
152
|
* @param properties The names of the expected properties
|
|
148
153
|
* @param context Location in JSON
|
|
149
154
|
*/
|
|
150
|
-
checkStrayProperties(obj: UnknownObjectType,
|
|
155
|
+
checkStrayProperties(obj: UnknownObjectType, def: ObjectDefinition, context: JsonContext) {
|
|
151
156
|
const own = Object.getOwnPropertyNames(obj)
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
const defined = def.properties.map(pdef => pdef.name)
|
|
158
|
+
own.forEach(ownProp => {
|
|
159
|
+
if (!defined.includes(ownProp)) {
|
|
154
160
|
this.validationResult.issue(new Syntax_PropertyUnknownIssue(context, ownProp))
|
|
155
161
|
}
|
|
156
162
|
})
|
|
157
|
-
properties.forEach((prop) => {
|
|
158
|
-
if (!own.includes(prop)) {
|
|
159
|
-
this.validationResult.issue(new Syntax_PropertyMissingIssue(context, prop))
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
163
|
}
|
|
163
164
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Definition, PrimitiveDefinition, TaggedUnionDefinition } from "./ValidationTypes.js"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A collection of object and primitive definitions describing JSON objects.
|
|
5
|
+
* Used to
|
|
6
|
+
* - validate an incoming JSON object
|
|
7
|
+
* - generate the corresponding TypeScript type definitions
|
|
8
|
+
* - generate handlers for the JSOn objects (in @lionweb/server)
|
|
9
|
+
*/
|
|
10
|
+
export class DefinitionSchema {
|
|
11
|
+
unionDefinition: TaggedUnionDefinition | undefined
|
|
12
|
+
/**
|
|
13
|
+
* Mapping from extenden object type name to list of extending Object Definitions
|
|
14
|
+
*/
|
|
15
|
+
definitionsMap: Map<string, Definition> = new Map<string, Definition>()
|
|
16
|
+
|
|
17
|
+
constructor(definitions: Definition[], taggedUnion?: TaggedUnionDefinition) {
|
|
18
|
+
this.add(definitions)
|
|
19
|
+
this.unionDefinition = taggedUnion
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getDefinition(name: string): Definition | undefined {
|
|
23
|
+
return this.definitionsMap.get(name)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add(definitions :Definition[] | Definition) {
|
|
27
|
+
if (!Array.isArray(definitions)) {
|
|
28
|
+
definitions = [definitions]
|
|
29
|
+
}
|
|
30
|
+
for(const def of definitions) {
|
|
31
|
+
this.definitionsMap.set(def.name, def)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
isTagProperty(propertyName: string): boolean {
|
|
36
|
+
return this.unionDefinition?.unionProperty === propertyName
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
definitions(): Definition[] {
|
|
40
|
+
return Array.from(this.definitionsMap.values())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
isUnionDiscriminator(propDef: PrimitiveDefinition): boolean {
|
|
44
|
+
return this.unionDefinition?.unionDiscriminator === propDef.name
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
joinDefinitions(...schema: DefinitionSchema[]): void {
|
|
48
|
+
schema.forEach(sch => {
|
|
49
|
+
this.add(sch.definitions())
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { JsonContext } from "@lionweb/json-utils"
|
|
2
|
+
import { ValidationResult } from "../ValidationResult.js"
|
|
3
|
+
|
|
4
|
+
export type UnknownObjectType = { [key: string]: unknown }
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Definition of a property, used by the SyntaxValidator to validate objects.
|
|
8
|
+
*
|
|
9
|
+
* **Note** that some of the properties are defined as optional.
|
|
10
|
+
* They should not be empty ever!! But being optional allows to leave them out in the `PropertyDef` function.
|
|
11
|
+
* The `PropertyDef` function sets default values for all optional fields.
|
|
12
|
+
* You should **always** use the `PropertyDef` function to create a `PropertyDefinition`.
|
|
13
|
+
*/
|
|
14
|
+
export type PropertyDefinition = {
|
|
15
|
+
/**
|
|
16
|
+
* The property name
|
|
17
|
+
*/
|
|
18
|
+
name: string
|
|
19
|
+
/**
|
|
20
|
+
* The expected type of the property value
|
|
21
|
+
*/
|
|
22
|
+
type: string
|
|
23
|
+
/**
|
|
24
|
+
* Whether the property value is allowed to be null
|
|
25
|
+
*/
|
|
26
|
+
mayBeNull?: boolean
|
|
27
|
+
/**
|
|
28
|
+
* IS this a list property?
|
|
29
|
+
*/
|
|
30
|
+
isList?: boolean,
|
|
31
|
+
/**
|
|
32
|
+
* Is this property optional?
|
|
33
|
+
*/
|
|
34
|
+
isOptional?: boolean,
|
|
35
|
+
/**
|
|
36
|
+
* Additional validation function
|
|
37
|
+
*/
|
|
38
|
+
validate?: ValidatorFunction
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ValidatorFunction = <T>(obj: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition) => void
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
43
|
+
export function emptyValidation<T>(object: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition): void {}
|
|
44
|
+
|
|
45
|
+
// Make boolean argument more readable.
|
|
46
|
+
export const MAY_BE_NULL = true
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Definition of a primitive type.
|
|
50
|
+
*/
|
|
51
|
+
export type PrimitiveDefinition = {
|
|
52
|
+
name: string,
|
|
53
|
+
/**
|
|
54
|
+
* The expected type of the property value
|
|
55
|
+
*/
|
|
56
|
+
primitiveType: string
|
|
57
|
+
/**
|
|
58
|
+
* Additional validation function
|
|
59
|
+
*/
|
|
60
|
+
validate?: ValidatorFunction
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Definition of an object type.
|
|
65
|
+
*/
|
|
66
|
+
export type ObjectDefinition = {
|
|
67
|
+
name: string,
|
|
68
|
+
properties: PropertyDefinition[],
|
|
69
|
+
/**
|
|
70
|
+
* The name of the tagged union that this type belongs to
|
|
71
|
+
*/
|
|
72
|
+
taggedUnionType?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type Definition = ObjectDefinition | PrimitiveDefinition
|
|
76
|
+
/**
|
|
77
|
+
* Defionition of tagged union.
|
|
78
|
+
*/
|
|
79
|
+
export type TaggedUnionDefinition = {
|
|
80
|
+
/**
|
|
81
|
+
* The tagged union "super" type
|
|
82
|
+
*/
|
|
83
|
+
unionType: string,
|
|
84
|
+
/**
|
|
85
|
+
* The primitive property type that is the discriminator or tag
|
|
86
|
+
*/
|
|
87
|
+
unionDiscriminator: string,
|
|
88
|
+
/**
|
|
89
|
+
* The name of the property in an object that contains the discriminator value
|
|
90
|
+
*/
|
|
91
|
+
unionProperty: string
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Easy way to create a PrimitiveDefinition typed object with default values.
|
|
95
|
+
* @param propDef
|
|
96
|
+
* @constructor
|
|
97
|
+
*/
|
|
98
|
+
export function PrimitiveDef(propDef: PrimitiveDefinition): PrimitiveDefinition {
|
|
99
|
+
const { name, primitiveType, validate = emptyValidation } = propDef
|
|
100
|
+
return {
|
|
101
|
+
name: name,
|
|
102
|
+
primitiveType: primitiveType,
|
|
103
|
+
validate: validate
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Easy way to create a PropertyDefinition typed object with default values.
|
|
109
|
+
* @param propDef
|
|
110
|
+
* @constructor
|
|
111
|
+
*/
|
|
112
|
+
export function PropertyDef(propDef: PropertyDefinition): PropertyDefinition {
|
|
113
|
+
const { name, type, mayBeNull = false, isList = false, isOptional = false, validate = emptyValidation } = propDef
|
|
114
|
+
return {
|
|
115
|
+
name: name,
|
|
116
|
+
type: type,
|
|
117
|
+
isList: isList,
|
|
118
|
+
mayBeNull: mayBeNull,
|
|
119
|
+
isOptional: isOptional,
|
|
120
|
+
validate: validate
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function isObjectDefinition(def: Definition | undefined): def is ObjectDefinition {
|
|
125
|
+
return (def !== undefined) && Array.isArray((def as ObjectDefinition)?.properties)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function isPrimitiveDefinition(def: Definition | undefined): def is PrimitiveDefinition {
|
|
129
|
+
return (def !== undefined) && (def as PrimitiveDefinition)?.primitiveType !== undefined
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function isJavaScriptPrimitive(type: string): boolean {
|
|
133
|
+
return ["number", "string", "boolean"].includes(type)
|
|
134
|
+
}
|