@lionweb/validation 0.7.0-beta.10 → 0.7.0-beta.12

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.
Files changed (170) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/dist/index.d.ts +5 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +5 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/issues/LanguageIssues.d.ts +99 -0
  7. package/dist/issues/LanguageIssues.d.ts.map +1 -0
  8. package/dist/issues/LanguageIssues.js +146 -0
  9. package/dist/issues/LanguageIssues.js.map +1 -0
  10. package/dist/issues/ReferenceIssues.d.ts +43 -0
  11. package/dist/issues/ReferenceIssues.d.ts.map +1 -0
  12. package/dist/issues/ReferenceIssues.js +53 -0
  13. package/dist/issues/ReferenceIssues.js.map +1 -0
  14. package/dist/issues/SyntaxIssues.d.ts +53 -0
  15. package/dist/issues/SyntaxIssues.d.ts.map +1 -0
  16. package/dist/issues/SyntaxIssues.js +81 -0
  17. package/dist/issues/SyntaxIssues.js.map +1 -0
  18. package/dist/issues/ValidationIssue.d.ts +15 -0
  19. package/dist/issues/ValidationIssue.d.ts.map +1 -0
  20. package/dist/issues/ValidationIssue.js +17 -0
  21. package/dist/issues/ValidationIssue.js.map +1 -0
  22. package/dist/issues/index.d.ts +5 -0
  23. package/dist/issues/index.d.ts.map +1 -0
  24. package/dist/issues/index.js +5 -0
  25. package/dist/issues/index.js.map +1 -0
  26. package/dist/languages/CompositeLionWebLanguageWrapper.d.ts +24 -0
  27. package/dist/languages/CompositeLionWebLanguageWrapper.d.ts.map +1 -0
  28. package/dist/languages/CompositeLionWebLanguageWrapper.js +56 -0
  29. package/dist/languages/CompositeLionWebLanguageWrapper.js.map +1 -0
  30. package/dist/languages/LanguageRegistry.d.ts +19 -0
  31. package/dist/languages/LanguageRegistry.d.ts.map +1 -0
  32. package/dist/languages/LanguageRegistry.js +37 -0
  33. package/dist/languages/LanguageRegistry.js.map +1 -0
  34. package/dist/languages/LanguageUtils.d.ts +35 -0
  35. package/dist/languages/LanguageUtils.d.ts.map +1 -0
  36. package/dist/languages/LanguageUtils.js +54 -0
  37. package/dist/languages/LanguageUtils.js.map +1 -0
  38. package/dist/languages/LionWebLanguageWrapper.d.ts +31 -0
  39. package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -0
  40. package/dist/languages/LionWebLanguageWrapper.js +69 -0
  41. package/dist/languages/LionWebLanguageWrapper.js.map +1 -0
  42. package/dist/languages/MetaPointerMap.d.ts +11 -0
  43. package/dist/languages/MetaPointerMap.d.ts.map +1 -0
  44. package/dist/languages/MetaPointerMap.js +39 -0
  45. package/dist/languages/MetaPointerMap.js.map +1 -0
  46. package/dist/languages/index.d.ts +3 -0
  47. package/dist/languages/index.d.ts.map +1 -0
  48. package/dist/languages/index.js +3 -0
  49. package/dist/languages/index.js.map +1 -0
  50. package/dist/runners/FileUtils.d.ts +6 -0
  51. package/dist/runners/FileUtils.d.ts.map +1 -0
  52. package/dist/runners/FileUtils.js +53 -0
  53. package/dist/runners/FileUtils.js.map +1 -0
  54. package/dist/runners/RunCheckFolder.d.ts +2 -0
  55. package/dist/runners/RunCheckFolder.d.ts.map +1 -0
  56. package/dist/runners/RunCheckFolder.js +6 -0
  57. package/dist/runners/RunCheckFolder.js.map +1 -0
  58. package/dist/runners/RunCheckFolderWithLanguage.d.ts +2 -0
  59. package/dist/runners/RunCheckFolderWithLanguage.d.ts.map +1 -0
  60. package/dist/runners/RunCheckFolderWithLanguage.js +40 -0
  61. package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -0
  62. package/dist/runners/RunCheckOneFile.d.ts +2 -0
  63. package/dist/runners/RunCheckOneFile.d.ts.map +1 -0
  64. package/dist/runners/RunCheckOneFile.js +6 -0
  65. package/dist/runners/RunCheckOneFile.js.map +1 -0
  66. package/dist/runners/RunCheckOneFileWithLanguage.d.ts +2 -0
  67. package/dist/runners/RunCheckOneFileWithLanguage.d.ts.map +1 -0
  68. package/dist/runners/RunCheckOneFileWithLanguage.js +31 -0
  69. package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -0
  70. package/dist/runners/RunLioncoreDiff.d.ts +2 -0
  71. package/dist/runners/RunLioncoreDiff.d.ts.map +1 -0
  72. package/dist/runners/RunLioncoreDiff.js +22 -0
  73. package/dist/runners/RunLioncoreDiff.js.map +1 -0
  74. package/dist/runners/Utils.d.ts +7 -0
  75. package/dist/runners/Utils.d.ts.map +1 -0
  76. package/dist/runners/Utils.js +48 -0
  77. package/dist/runners/Utils.js.map +1 -0
  78. package/dist/runners/index.d.ts +3 -0
  79. package/dist/runners/index.d.ts.map +1 -0
  80. package/dist/runners/index.js +3 -0
  81. package/dist/runners/index.js.map +1 -0
  82. package/dist/validators/LionWebChunkDefinitions.d.ts +9 -0
  83. package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -0
  84. package/{src/validators/LionWebChunkDefinitions.ts → dist/validators/LionWebChunkDefinitions.js} +10 -14
  85. package/dist/validators/LionWebChunkDefinitions.js.map +1 -0
  86. package/dist/validators/LionWebLanguageReferenceValidator.d.ts +21 -0
  87. package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -0
  88. package/{src/validators/LionWebLanguageReferenceValidator.ts → dist/validators/LionWebLanguageReferenceValidator.js} +73 -108
  89. package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -0
  90. package/dist/validators/LionWebLanguageValidator.d.ts +23 -0
  91. package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -0
  92. package/dist/validators/LionWebLanguageValidator.js +66 -0
  93. package/dist/validators/LionWebLanguageValidator.js.map +1 -0
  94. package/dist/validators/LionWebReferenceValidator.d.ts +43 -0
  95. package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -0
  96. package/{src/validators/LionWebReferenceValidator.ts → dist/validators/LionWebReferenceValidator.js} +84 -106
  97. package/dist/validators/LionWebReferenceValidator.js.map +1 -0
  98. package/dist/validators/LionWebSyntaxValidator.d.ts +9 -0
  99. package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -0
  100. package/dist/validators/LionWebSyntaxValidator.js +11 -0
  101. package/dist/validators/LionWebSyntaxValidator.js.map +1 -0
  102. package/dist/validators/LionWebValidator.d.ts +24 -0
  103. package/dist/validators/LionWebValidator.d.ts.map +1 -0
  104. package/{src/validators/LionWebValidator.ts → dist/validators/LionWebValidator.js} +29 -45
  105. package/dist/validators/LionWebValidator.js.map +1 -0
  106. package/dist/validators/ValidationFunctions.d.ts +60 -0
  107. package/dist/validators/ValidationFunctions.d.ts.map +1 -0
  108. package/{src/validators/ValidationFunctions.ts → dist/validators/ValidationFunctions.js} +34 -66
  109. package/dist/validators/ValidationFunctions.js.map +1 -0
  110. package/dist/validators/generic/SyntaxValidator.d.ts +37 -0
  111. package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -0
  112. package/dist/validators/generic/SyntaxValidator.js +152 -0
  113. package/dist/validators/generic/SyntaxValidator.js.map +1 -0
  114. package/dist/validators/generic/ValidationResult.d.ts +8 -0
  115. package/dist/validators/generic/ValidationResult.d.ts.map +1 -0
  116. package/dist/validators/generic/ValidationResult.js +15 -0
  117. package/dist/validators/generic/ValidationResult.js.map +1 -0
  118. package/dist/validators/generic/index.d.ts +4 -0
  119. package/dist/validators/generic/index.d.ts.map +1 -0
  120. package/dist/validators/generic/index.js +4 -0
  121. package/dist/validators/generic/index.js.map +1 -0
  122. package/dist/validators/generic/schema/DefinitionSchema.d.ts +23 -0
  123. package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +1 -0
  124. package/dist/validators/generic/schema/DefinitionSchema.js +43 -0
  125. package/dist/validators/generic/schema/DefinitionSchema.js.map +1 -0
  126. package/dist/validators/generic/schema/ValidationTypes.d.ts +101 -0
  127. package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
  128. package/dist/validators/generic/schema/ValidationTypes.js +43 -0
  129. package/dist/validators/generic/schema/ValidationTypes.js.map +1 -0
  130. package/dist/validators/generic/schema/index.d.ts +3 -0
  131. package/dist/validators/generic/schema/index.d.ts.map +1 -0
  132. package/dist/validators/generic/schema/index.js +3 -0
  133. package/dist/validators/generic/schema/index.js.map +1 -0
  134. package/dist/validators/index.d.ts +9 -0
  135. package/dist/validators/index.d.ts.map +1 -0
  136. package/dist/validators/index.js +9 -0
  137. package/dist/validators/index.js.map +1 -0
  138. package/package.json +4 -4
  139. package/src/index.ts +0 -4
  140. package/src/issues/LanguageIssues.ts +0 -147
  141. package/src/issues/ReferenceIssues.ts +0 -83
  142. package/src/issues/SyntaxIssues.ts +0 -84
  143. package/src/issues/ValidationIssue.ts +0 -29
  144. package/src/issues/index.ts +0 -4
  145. package/src/languages/CompositeLionWebLanguageWrapper.ts +0 -57
  146. package/src/languages/LanguageRegistry.ts +0 -44
  147. package/src/languages/LanguageUtils.ts +0 -63
  148. package/src/languages/LionWebLanguageWrapper.ts +0 -91
  149. package/src/languages/MetaPointerMap.ts +0 -41
  150. package/src/languages/index.ts +0 -2
  151. package/src/runners/FileUtils.ts +0 -59
  152. package/src/runners/RunCheckFolder.ts +0 -7
  153. package/src/runners/RunCheckFolderWithLanguage.ts +0 -45
  154. package/src/runners/RunCheckOneFile.ts +0 -7
  155. package/src/runners/RunCheckOneFileWithLanguage.ts +0 -35
  156. package/src/runners/RunLioncoreDiff.ts +0 -23
  157. package/src/runners/Utils.ts +0 -54
  158. package/src/runners/index.ts +0 -2
  159. package/src/validators/LionWebLanguageValidator.ts +0 -78
  160. package/src/validators/LionWebSyntaxValidator.ts +0 -14
  161. package/src/validators/generic/SyntaxValidator.ts +0 -216
  162. package/src/validators/generic/ValidationResult.ts +0 -17
  163. package/src/validators/generic/index.ts +0 -3
  164. package/src/validators/generic/schema/DefinitionSchema.ts +0 -52
  165. package/src/validators/generic/schema/ValidationTypes.ts +0 -134
  166. package/src/validators/generic/schema/index.ts +0 -2
  167. package/src/validators/index.ts +0 -8
  168. package/tsconfig.json +0 -8
  169. /package/{src → dist}/languages/LionCore-M3.json +0 -0
  170. /package/{src → dist}/languages/LionCore-builtins.json +0 -0
@@ -1,216 +0,0 @@
1
- import { JsonContext } from "@lionweb/json-utils"
2
- import {
3
- Syntax_ArrayContainsNull_Issue,
4
- Syntax_PropertyMissingIssue,
5
- Syntax_PropertyNullIssue,
6
- Syntax_PropertyTypeIssue,
7
- Syntax_PropertyUnknownIssue
8
- } from "../../issues/index.js"
9
- import { ValidationResult } from "./ValidationResult.js"
10
- import {
11
- isObjectDefinition,
12
- isPrimitiveDefinition, ObjectDefinition, PrimitiveDefinition, DefinitionSchema,
13
- UnknownObjectType
14
- } from "./schema/index.js"
15
-
16
- /**
17
- * Syntax Validator checks whether objects are structurally conforming to the
18
- * definitions given in `schema`.
19
- */
20
- export class SyntaxValidator {
21
- validationResult: ValidationResult
22
- schema: DefinitionSchema
23
-
24
- constructor(validationResult: ValidationResult, schema: DefinitionSchema) {
25
- this.validationResult = validationResult
26
- this.schema = schema
27
- }
28
-
29
- /**
30
- * Check whether `obj` is a JSON object that conforms to the definition of `expectedType`.
31
- * All errors found will be added to the `validationResult` object.
32
- * @param obj The object to validate.
33
- * @param expectedType The expected type of the object.
34
- */
35
- validate(obj: unknown, expectedType: string) {
36
- const object = obj as UnknownObjectType
37
- const typeDef = this.schema.getDefinition(expectedType)
38
-
39
- if (typeDef === undefined) {
40
- throw new Error(`SyntaxValidator.validate: cannot find definition for ${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, ["$"]))
45
- }
46
- }
47
-
48
- /**
49
- * Validate whether `object` is structured conform the properties in `propertyDef`
50
- * @param originalProperty The property of which `object` it the value
51
- * @param typeDef The property definitions that are being validated
52
- * @param object The object being validated
53
- * @param jsonContext The location in the JSON
54
- * @private
55
- */
56
- validateObjectProperties(originalProperty: string, typeDef: ObjectDefinition, object: UnknownObjectType, jsonContext: JsonContext) {
57
- if (typeDef === null || typeDef === undefined) {
58
- return
59
- }
60
- if (typeof object !== "object") {
61
- this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, originalProperty, "object", typeof object))
62
- return
63
- }
64
- for (const propertyDef of typeDef.properties) {
65
- // const taggedUnion = this.schema.getTaggedUnionDefinition(propertyDef.type)
66
- // if (taggedUnion !== undefined) {
67
- // this.validateTaggedUnion(propertyDef, typeDef, object, jsonContext.concat(propertyDef.name))
68
- // continue
69
- // }
70
- const expectedTypeDef = this.schema.getDefinition(propertyDef.type)
71
- const validator = propertyDef.validate!
72
- const propertyValue = object[propertyDef.name]
73
- if (propertyValue === undefined) {
74
- if (!propertyDef.isOptional) {
75
- this.validationResult.issue(new Syntax_PropertyMissingIssue(jsonContext, propertyDef.name))
76
- }
77
- continue
78
- }
79
- if (!propertyDef.mayBeNull && propertyValue === null) {
80
- this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propertyDef.name))
81
- continue
82
- }
83
- if (propertyDef.mayBeNull && propertyValue === null) {
84
- // Ok, stop checking, continue with next property def
85
- continue
86
- }
87
- if (propertyDef.isList) {
88
- // Check whether value is an array
89
- if (!Array.isArray(propertyValue)) {
90
- const newContext = jsonContext.concat(propertyDef.name)
91
- this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.name, "array", typeof propertyValue))
92
- return
93
- }
94
- // If an array, validate every item in the array
95
- (propertyValue as UnknownObjectType[]).forEach((item, index) => {
96
- const newContext = jsonContext.concat(propertyDef.name, index)
97
- if (item === null) {
98
- this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext, propertyDef.name, index))
99
- } else {
100
- if (expectedTypeDef !== undefined) {
101
- if (isPrimitiveDefinition(expectedTypeDef)) {
102
- if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, item, jsonContext)) {
103
- validator.apply(null, [item, this.validationResult, newContext, propertyDef])
104
- }
105
- } else {
106
- // propertyValue should be an object, validate its properties
107
- this.validateObjectProperties(propertyDef.name, expectedTypeDef, item as UnknownObjectType, newContext)
108
- validator.apply(null, [item, this.validationResult, newContext, propertyDef])
109
- }
110
- } else {
111
- throw new Error(`Expected type '${propertyDef.type} has neither property defs, nor a validator.`)
112
- }
113
- }
114
- })
115
- } else {
116
- const newContext = jsonContext.concat(propertyDef.name)
117
- if (Array.isArray(propertyValue)) {
118
- this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.name, propertyDef.type, "array"))
119
- return
120
- }
121
- // Single valued property, validate it
122
- if (expectedTypeDef !== undefined) {
123
- if (isPrimitiveDefinition(expectedTypeDef)) {
124
- // propertyValue should be a primitive as it has no property definitions
125
- if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, propertyValue, jsonContext)) {
126
- validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef])
127
- }
128
- } else if (isObjectDefinition(expectedTypeDef)) {
129
- // propertyValue should be an object, validate its properties
130
- this.validateObjectProperties(propertyDef.name, expectedTypeDef, propertyValue as UnknownObjectType, newContext)
131
- validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef])
132
- } else {
133
- throw new Error("EXPECTING ObjectDefinition or PrimitiveDefinition, but got something else")
134
- }
135
- } else {
136
- throw new Error(
137
- `Expected single type '${propertyDef.type}' for '${propertyDef.name}' at ${newContext.toString()} has neither property defs, nor a validator.`
138
- )
139
- }
140
- }
141
- }
142
- this.checkStrayProperties(object, typeDef, jsonContext)
143
- }
144
-
145
- validatePrimitiveValue(propertyName: string, propDef: PrimitiveDefinition, object: unknown, jsonContext: JsonContext): boolean {
146
- if (typeof object !== propDef.primitiveType) {
147
- this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, propertyName, propDef.primitiveType, typeof object))
148
- return false
149
- }
150
- propDef.validate!(object, this.validationResult, jsonContext)
151
- return true
152
- }
153
-
154
- /**
155
- *
156
- * @param propertyDef the definition of the property that has the TaggedUnionType as its type
157
- * @param typeDef The object definition containing the `propertyDef`
158
- * @param object The object of type `typeDef` that should have the property described by `propertyDef`
159
- * @param jsonContext
160
- */
161
- // validateTaggedUnion(
162
- // propertyDef: PropertyDefinition,
163
- // typeDef: ObjectDefinition,
164
- // object: UnknownObjectType,
165
- // jsonContext: JsonContext
166
- // ): void {
167
- // // console.log(`validateTaggedUnion ${JSON.stringify(propertyDef)}, typedef ${typeDef.name} object: ${JSON.stringify(object, null, 3)}`)
168
- // const taggedObject = object[propertyDef.name]
169
- // if (propertyDef.isList) {
170
- // if (!Array.isArray(taggedObject)) {
171
- // this.validationResult.issue(new GenericIssue(jsonContext, `Property value '${propertyDef.name}' expects an array, found '${typeof taggedObject}'`))
172
- // } else {
173
- // taggedObject.forEach((taggedObjectSingle, index) => {
174
- // this.validateTaggedObject(taggedObjectSingle, jsonContext.concat(index))
175
- // })
176
- // }
177
- // } else {
178
- // if (!(typeof taggedObject === "object")) {
179
- // this.validationResult.issue(new GenericIssue(jsonContext, `Property value '${propertyDef.name}' expects an object, found '${typeof taggedObject}'`))
180
- // } else {
181
- // this.validateTaggedObject(taggedObject as UnknownObjectType, jsonContext)
182
- // }
183
- // }
184
- // }
185
-
186
- /**
187
- * Validate a single tagged object
188
- * @param taggedObject
189
- * @param jsonContext
190
- */
191
- // validateTaggedObject(taggedObject: UnknownObjectType, jsonContext: JsonContext): void {
192
- // const actualTypeName = taggedObject["messageKind"] as string
193
- // const actualType = this.schema.getDefinition(actualTypeName)
194
- // if (actualType === undefined || !isObjectDefinition(actualType)) {
195
- // this.validationResult.issue(new GenericIssue(jsonContext, `Expected object type is ${typeof taggedObject}, should be object`))
196
- // } else {
197
- // this.validateObjectProperties(actualTypeName, actualType, taggedObject, jsonContext)
198
- // }
199
- // }
200
-
201
- /**
202
- * Check whether there are extra properties that should not be there.
203
- * @param obj Object to be validated
204
- * @param properties The names of the expected properties
205
- * @param context Location in JSON
206
- */
207
- checkStrayProperties(obj: UnknownObjectType, def: ObjectDefinition, context: JsonContext) {
208
- const own = Object.getOwnPropertyNames(obj)
209
- const defined = def.properties.map(pdef => pdef.name)
210
- own.forEach(ownProp => {
211
- if (!defined.includes(ownProp)) {
212
- this.validationResult.issue(new Syntax_PropertyUnknownIssue(context, ownProp))
213
- }
214
- })
215
- }
216
- }
@@ -1,17 +0,0 @@
1
- import { ValidationIssue } from "../../issues/ValidationIssue.js"
2
-
3
- export class ValidationResult {
4
- issues: ValidationIssue[] = []
5
-
6
- issue(issue: ValidationIssue) {
7
- this.issues.push(issue)
8
- }
9
-
10
- reset() {
11
- this.issues = []
12
- }
13
-
14
- hasErrors(): boolean {
15
- return this.issues.length !== 0
16
- }
17
- }
@@ -1,3 +0,0 @@
1
- export * from "./schema/index.js"
2
- export * from "./ValidationResult.js"
3
- export * from "./SyntaxValidator.js"
@@ -1,52 +0,0 @@
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
- }
@@ -1,134 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- export * from "./ValidationTypes.js"
2
- export * from "./DefinitionSchema.js"
@@ -1,8 +0,0 @@
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"
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "dist/",
6
- "resolveJsonModule": true, /* Enable importing .json files */
7
- }
8
- }
File without changes
File without changes