@lionweb/validation 0.7.0-beta.18 → 0.7.0-beta.19
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 +0 -1
- package/package.json +4 -4
- package/src/index.ts +4 -0
- package/src/issues/LanguageIssues.ts +147 -0
- package/src/issues/ReferenceIssues.ts +83 -0
- package/src/issues/SyntaxIssues.ts +84 -0
- package/src/issues/ValidationIssue.ts +29 -0
- package/src/issues/index.ts +4 -0
- package/src/languages/CompositeLionWebLanguageWrapper.ts +57 -0
- package/src/languages/LanguageRegistry.ts +44 -0
- package/src/languages/LanguageUtils.ts +63 -0
- package/src/languages/LionCore-M3.json +2356 -0
- package/src/languages/LionCore-builtins.json +372 -0
- package/src/languages/LionWebLanguageWrapper.ts +91 -0
- package/src/languages/MetaPointerMap.ts +41 -0
- package/src/languages/index.ts +2 -0
- package/src/runners/FileUtils.ts +59 -0
- package/src/runners/RunCheckFolder.ts +7 -0
- package/src/runners/RunCheckFolderWithLanguage.ts +45 -0
- package/src/runners/RunCheckOneFile.ts +7 -0
- package/src/runners/RunCheckOneFileWithLanguage.ts +35 -0
- package/src/runners/RunLioncoreDiff.ts +23 -0
- package/src/runners/Utils.ts +54 -0
- package/src/runners/index.ts +2 -0
- package/src/validators/LionWebChunkDefinitions.ts +104 -0
- package/src/validators/LionWebLanguageReferenceValidator.ts +201 -0
- package/src/validators/LionWebLanguageValidator.ts +79 -0
- package/src/validators/LionWebReferenceValidator.ts +225 -0
- package/src/validators/LionWebSyntaxValidator.ts +14 -0
- package/src/validators/LionWebValidator.ts +71 -0
- package/src/validators/ValidationFunctions.ts +129 -0
- package/src/validators/generic/SyntaxValidator.ts +164 -0
- package/src/validators/generic/ValidationResult.ts +17 -0
- package/src/validators/generic/index.ts +3 -0
- 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 +8 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./generic/index.js"
|
|
2
|
+
export * from "./LionWebSyntaxValidator.js"
|
|
3
|
+
export * from "./LionWebReferenceValidator.js"
|
|
4
|
+
export * from "./LionWebLanguageValidator.js"
|
|
5
|
+
export * from "./LionWebLanguageReferenceValidator.js"
|
|
6
|
+
export * from "./LionWebValidator.js"
|
|
7
|
+
export * from "./ValidationFunctions.js"
|
|
8
|
+
export * from "./LionWebChunkDefinitions.js"
|