@lionweb/validation 0.7.0-beta.7 → 0.7.0-beta.9
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/runners/Utils.js +2 -2
- package/dist/runners/Utils.js.map +1 -1
- package/dist/validators/LionWebChunkDefinitions.d.ts +4 -4
- package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -1
- package/dist/validators/LionWebChunkDefinitions.js +80 -90
- package/dist/validators/LionWebChunkDefinitions.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +2 -2
- package/dist/validators/LionWebValidator.js +1 -1
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/dist/validators/ValidationFunctions.d.ts +1 -1
- package/dist/validators/ValidationFunctions.d.ts.map +1 -1
- package/dist/validators/ValidationFunctions.js +4 -4
- package/dist/validators/ValidationFunctions.js.map +1 -1
- package/dist/validators/generic/SyntaxValidator.d.ts +21 -7
- package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -1
- package/dist/validators/generic/SyntaxValidator.js +78 -34
- package/dist/validators/generic/SyntaxValidator.js.map +1 -1
- package/dist/validators/generic/index.d.ts +1 -1
- package/dist/validators/generic/index.d.ts.map +1 -1
- package/dist/validators/generic/index.js +1 -1
- package/dist/validators/generic/index.js.map +1 -1
- package/dist/validators/generic/schema/DefinitionSchema.d.ts +26 -0
- package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +1 -0
- package/dist/validators/generic/schema/DefinitionSchema.js +75 -0
- package/dist/validators/generic/schema/DefinitionSchema.js.map +1 -0
- package/dist/validators/generic/{ValidationTypes.d.ts → schema/ValidationTypes.d.ts} +45 -12
- package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
- package/dist/validators/generic/{ValidationTypes.js → schema/ValidationTypes.js} +18 -21
- package/dist/validators/generic/schema/ValidationTypes.js.map +1 -0
- package/dist/validators/generic/schema/index.d.ts +3 -0
- package/dist/validators/generic/schema/index.d.ts.map +1 -0
- package/dist/validators/generic/schema/index.js +3 -0
- package/dist/validators/generic/schema/index.js.map +1 -0
- package/package.json +4 -4
- package/src/runners/Utils.ts +2 -2
- package/src/validators/LionWebChunkDefinitions.ts +80 -90
- package/src/validators/LionWebSyntaxValidator.ts +2 -2
- package/src/validators/LionWebValidator.ts +1 -1
- package/src/validators/ValidationFunctions.ts +5 -5
- package/src/validators/generic/SyntaxValidator.ts +134 -87
- package/src/validators/generic/index.ts +1 -1
- package/src/validators/generic/schema/DefinitionSchema.ts +84 -0
- package/src/validators/generic/{ValidationTypes.ts → schema/ValidationTypes.ts} +65 -35
- package/src/validators/generic/schema/index.ts +2 -0
- package/dist/validators/generic/ValidationTypes.d.ts.map +0 -1
- package/dist/validators/generic/ValidationTypes.js.map +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { JsonContext } from "@lionweb/json-utils";
|
|
2
|
-
import { Syntax_ArrayContainsNull_Issue, Syntax_PropertyMissingIssue, Syntax_PropertyNullIssue, Syntax_PropertyTypeIssue, Syntax_PropertyUnknownIssue } from "../../issues/index.js";
|
|
3
|
-
import { isObjectDefinition, isPrimitiveDefinition } from "./
|
|
2
|
+
import { GenericIssue, Syntax_ArrayContainsNull_Issue, Syntax_PropertyMissingIssue, Syntax_PropertyNullIssue, Syntax_PropertyTypeIssue, Syntax_PropertyUnknownIssue } from "../../issues/index.js";
|
|
3
|
+
import { isObjectDefinition, isPrimitiveDefinition } from "./schema/index.js";
|
|
4
4
|
/**
|
|
5
|
-
* Syntax Validator
|
|
6
|
-
* definitions given in `
|
|
5
|
+
* Syntax Validator checks whether objects are structurally conforming to the
|
|
6
|
+
* definitions given in `schema`.
|
|
7
7
|
*/
|
|
8
8
|
export class SyntaxValidator {
|
|
9
|
-
constructor(validationResult,
|
|
9
|
+
constructor(validationResult, schema) {
|
|
10
10
|
this.validationResult = validationResult;
|
|
11
|
-
this.
|
|
11
|
+
this.schema = schema;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Check whether `obj` is a JSON object that conforms to the definition of `expectedType`.
|
|
15
|
-
* All errors found will be
|
|
15
|
+
* All errors found will be added to the `validationResult` object.
|
|
16
16
|
* @param obj The object to validate.
|
|
17
17
|
* @param expectedType The expected type of the object.
|
|
18
18
|
*/
|
|
19
19
|
validate(obj, expectedType) {
|
|
20
20
|
const object = obj;
|
|
21
|
-
const typeDef = this.
|
|
21
|
+
const typeDef = this.schema.getDefinition(expectedType);
|
|
22
22
|
if (typeDef === undefined) {
|
|
23
23
|
throw new Error(`SyntaxValidator.validate: cannot find definition for ${expectedType}`);
|
|
24
24
|
}
|
|
@@ -32,7 +32,7 @@ export class SyntaxValidator {
|
|
|
32
32
|
/**
|
|
33
33
|
* Validate whether `object` is structured conform the properties in `propertyDef`
|
|
34
34
|
* @param originalProperty The property of which `object` it the value
|
|
35
|
-
* @param typeDef
|
|
35
|
+
* @param typeDef The property definitions that are being validated
|
|
36
36
|
* @param object The object being validated
|
|
37
37
|
* @param jsonContext The location in the JSON
|
|
38
38
|
* @private
|
|
@@ -41,22 +41,27 @@ export class SyntaxValidator {
|
|
|
41
41
|
if (typeDef === null || typeDef === undefined) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
if (
|
|
44
|
+
if (typeof object !== "object") {
|
|
45
45
|
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, originalProperty, "object", typeof object));
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
for (const propertyDef of typeDef) {
|
|
49
|
-
const
|
|
48
|
+
for (const propertyDef of typeDef.properties) {
|
|
49
|
+
const taggedUnion = this.schema.getTaggedUnionDefinition(propertyDef.type);
|
|
50
|
+
if (taggedUnion !== undefined) {
|
|
51
|
+
this.validateTaggedUnion(propertyDef, typeDef, object, jsonContext.concat(propertyDef.name));
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const expectedTypeDef = this.schema.getDefinition(propertyDef.type);
|
|
50
55
|
const validator = propertyDef.validate;
|
|
51
|
-
const propertyValue = object[propertyDef.
|
|
56
|
+
const propertyValue = object[propertyDef.name];
|
|
52
57
|
if (propertyValue === undefined) {
|
|
53
58
|
if (!propertyDef.isOptional) {
|
|
54
|
-
this.validationResult.issue(new Syntax_PropertyMissingIssue(jsonContext, propertyDef.
|
|
59
|
+
this.validationResult.issue(new Syntax_PropertyMissingIssue(jsonContext, propertyDef.name));
|
|
55
60
|
}
|
|
56
61
|
continue;
|
|
57
62
|
}
|
|
58
63
|
if (!propertyDef.mayBeNull && propertyValue === null) {
|
|
59
|
-
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propertyDef.
|
|
64
|
+
this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propertyDef.name));
|
|
60
65
|
continue;
|
|
61
66
|
}
|
|
62
67
|
if (propertyDef.mayBeNull && propertyValue === null) {
|
|
@@ -66,53 +71,52 @@ export class SyntaxValidator {
|
|
|
66
71
|
if (propertyDef.isList) {
|
|
67
72
|
// Check whether value is an array
|
|
68
73
|
if (!Array.isArray(propertyValue)) {
|
|
69
|
-
const newContext = jsonContext.concat(propertyDef.
|
|
70
|
-
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.
|
|
74
|
+
const newContext = jsonContext.concat(propertyDef.name);
|
|
75
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.name, "array", typeof propertyValue));
|
|
71
76
|
return;
|
|
72
77
|
}
|
|
73
78
|
// If an array, validate every item in the array
|
|
74
79
|
propertyValue.forEach((item, index) => {
|
|
75
|
-
const newContext = jsonContext.concat(propertyDef.
|
|
80
|
+
const newContext = jsonContext.concat(propertyDef.name, index);
|
|
76
81
|
if (item === null) {
|
|
77
|
-
this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext, propertyDef.
|
|
82
|
+
this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext, propertyDef.name, index));
|
|
78
83
|
}
|
|
79
84
|
else {
|
|
80
85
|
if (expectedTypeDef !== undefined) {
|
|
81
86
|
if (isPrimitiveDefinition(expectedTypeDef)) {
|
|
82
|
-
|
|
83
|
-
if (this.validatePrimitiveValue(propertyDef.property, expectedTypeDef, item, jsonContext)) {
|
|
87
|
+
if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, item, jsonContext)) {
|
|
84
88
|
validator.apply(null, [item, this.validationResult, newContext, propertyDef]);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
else {
|
|
88
92
|
// propertyValue should be an object, validate its properties
|
|
89
|
-
this.validateObjectProperties(propertyDef.
|
|
93
|
+
this.validateObjectProperties(propertyDef.name, expectedTypeDef, item, newContext);
|
|
90
94
|
validator.apply(null, [item, this.validationResult, newContext, propertyDef]);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
else {
|
|
94
|
-
throw new Error(`Expected type '${propertyDef.
|
|
98
|
+
throw new Error(`Expected type '${propertyDef.type} has neither property defs, nor a validator.`);
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
103
|
else {
|
|
100
|
-
const newContext = jsonContext.concat(propertyDef.
|
|
104
|
+
const newContext = jsonContext.concat(propertyDef.name);
|
|
101
105
|
if (Array.isArray(propertyValue)) {
|
|
102
|
-
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.
|
|
106
|
+
this.validationResult.issue(new Syntax_PropertyTypeIssue(newContext, propertyDef.name, propertyDef.type, "array"));
|
|
103
107
|
return;
|
|
104
108
|
}
|
|
105
109
|
// Single valued property, validate it
|
|
106
110
|
if (expectedTypeDef !== undefined) {
|
|
107
111
|
if (isPrimitiveDefinition(expectedTypeDef)) {
|
|
108
112
|
// propertyValue should be a primitive as it has no property definitions
|
|
109
|
-
if (this.validatePrimitiveValue(propertyDef.
|
|
113
|
+
if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, propertyValue, jsonContext)) {
|
|
110
114
|
validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef]);
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
else if (isObjectDefinition(expectedTypeDef)) {
|
|
114
118
|
// propertyValue should be an object, validate its properties
|
|
115
|
-
this.validateObjectProperties(propertyDef.
|
|
119
|
+
this.validateObjectProperties(propertyDef.name, expectedTypeDef, propertyValue, newContext);
|
|
116
120
|
validator.apply(null, [propertyValue, this.validationResult, newContext, propertyDef]);
|
|
117
121
|
}
|
|
118
122
|
else {
|
|
@@ -120,17 +124,13 @@ export class SyntaxValidator {
|
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
else {
|
|
123
|
-
throw new Error(`Expected single type '${propertyDef.
|
|
127
|
+
throw new Error(`Expected single type '${propertyDef.type}' for '${propertyDef.name}' at ${newContext.toString()} has neither property defs, nor a validator.`);
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
this.checkStrayProperties(object, typeDef, jsonContext);
|
|
128
132
|
}
|
|
129
133
|
validatePrimitiveValue(propertyName, propDef, object, jsonContext) {
|
|
130
|
-
// if (!propDef.mayBeNull && (object === null || object === undefined)) {
|
|
131
|
-
// this.validationResult.issue(new Syntax_PropertyNullIssue(jsonContext, propDef.property))
|
|
132
|
-
// return false
|
|
133
|
-
// }
|
|
134
134
|
if (typeof object !== propDef.primitiveType) {
|
|
135
135
|
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, propertyName, propDef.primitiveType, typeof object));
|
|
136
136
|
return false;
|
|
@@ -138,6 +138,50 @@ export class SyntaxValidator {
|
|
|
138
138
|
propDef.validate(object, this.validationResult, jsonContext);
|
|
139
139
|
return true;
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* @param propertyDef the definition of the property that has the TaggedUnionType as its type
|
|
144
|
+
* @param typeDef The object definition containing the `propertyDef`
|
|
145
|
+
* @param object The object of type `typeDef` that should have the property described by `propertyDef`
|
|
146
|
+
* @param jsonContext
|
|
147
|
+
*/
|
|
148
|
+
validateTaggedUnion(propertyDef, typeDef, object, jsonContext) {
|
|
149
|
+
// console.log(`validateTaggedUnion ${JSON.stringify(propertyDef)}, typedef ${typeDef.name} object: ${JSON.stringify(object, null, 3)}`)
|
|
150
|
+
const taggedObject = object[propertyDef.name];
|
|
151
|
+
if (propertyDef.isList) {
|
|
152
|
+
if (!Array.isArray(taggedObject)) {
|
|
153
|
+
this.validationResult.issue(new GenericIssue(jsonContext, `Property value '${propertyDef.name}' expects an array, found '${typeof taggedObject}'`));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
taggedObject.forEach((taggedObjectSingle, index) => {
|
|
157
|
+
this.validateTaggedObject(taggedObjectSingle, jsonContext.concat(index));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
if (!(typeof taggedObject === "object")) {
|
|
163
|
+
this.validationResult.issue(new GenericIssue(jsonContext, `Property value '${propertyDef.name}' expects an object, found '${typeof taggedObject}'`));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.validateTaggedObject(taggedObject, jsonContext);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Validate a single tagged object
|
|
172
|
+
* @param taggedObject
|
|
173
|
+
* @param jsonContext
|
|
174
|
+
*/
|
|
175
|
+
validateTaggedObject(taggedObject, jsonContext) {
|
|
176
|
+
const actualTypeName = taggedObject["messageKind"];
|
|
177
|
+
const actualType = this.schema.getDefinition(actualTypeName);
|
|
178
|
+
if (actualType === undefined || !isObjectDefinition(actualType)) {
|
|
179
|
+
this.validationResult.issue(new GenericIssue(jsonContext, `Expected object type is ${typeof taggedObject}, should be object`));
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this.validateObjectProperties(actualTypeName, actualType, taggedObject, jsonContext);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
141
185
|
/**
|
|
142
186
|
* Check whether there are extra properties that should not be there.
|
|
143
187
|
* @param obj Object to be validated
|
|
@@ -146,8 +190,8 @@ export class SyntaxValidator {
|
|
|
146
190
|
*/
|
|
147
191
|
checkStrayProperties(obj, def, context) {
|
|
148
192
|
const own = Object.getOwnPropertyNames(obj);
|
|
149
|
-
const defined = def.map(pdef => pdef.
|
|
150
|
-
own.forEach(
|
|
193
|
+
const defined = def.properties.map(pdef => pdef.name);
|
|
194
|
+
own.forEach(ownProp => {
|
|
151
195
|
if (!defined.includes(ownProp)) {
|
|
152
196
|
this.validationResult.issue(new Syntax_PropertyUnknownIssue(context, ownProp));
|
|
153
197
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyntaxValidator.js","sourceRoot":"","sources":["../../../src/validators/generic/SyntaxValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EACH,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,2BAA2B,EAC9B,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACH,kBAAkB,EAClB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"SyntaxValidator.js","sourceRoot":"","sources":["../../../src/validators/generic/SyntaxValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EACH,YAAY,EACZ,8BAA8B,EAC9B,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,2BAA2B,EAC9B,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACH,kBAAkB,EAClB,qBAAqB,EAExB,MAAM,mBAAmB,CAAA;AAE1B;;;GAGG;AACH,MAAM,OAAO,eAAe;IAIxB,YAAY,gBAAkC,EAAE,MAAwB;QACpE,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED;;;;;OAKG;IACH,Q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,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7B,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;YAClF,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/generic/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validators/generic/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/generic/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/generic/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Definition, PrimitiveDefinition, TaggedUnionDefinition } from "./ValidationTypes.js";
|
|
2
|
+
/**
|
|
3
|
+
* A collection of object and primitive definitions describing JSON objects.
|
|
4
|
+
* Used to
|
|
5
|
+
* - validate an incoming JSON object
|
|
6
|
+
* - generate the corresponding TypeScript type definitions.
|
|
7
|
+
*/
|
|
8
|
+
export declare class DefinitionSchema {
|
|
9
|
+
unionDefinitions: TaggedUnionDefinition[];
|
|
10
|
+
/**
|
|
11
|
+
* Mapping from extenden object type name to list of extending Object Definitions
|
|
12
|
+
*/
|
|
13
|
+
taggedUnions: Map<string, Definition[]>;
|
|
14
|
+
definitionsMap: Map<string, Definition>;
|
|
15
|
+
constructor(taggedUnions: TaggedUnionDefinition[], definitions: Definition[]);
|
|
16
|
+
getDefinition(name: string): Definition | undefined;
|
|
17
|
+
addTaggedUnion(defs: TaggedUnionDefinition[]): void;
|
|
18
|
+
add(definitions: Definition[] | Definition): void;
|
|
19
|
+
isTagProperty(propertyName: string): boolean;
|
|
20
|
+
definitions(): Definition[];
|
|
21
|
+
getTaggedUnionDefinition(name: string): TaggedUnionDefinition | undefined;
|
|
22
|
+
isUnionDiscriminator(propDef: PrimitiveDefinition): boolean;
|
|
23
|
+
extending(name: string): Definition[];
|
|
24
|
+
static join(...schema: DefinitionSchema[]): DefinitionSchema;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=DefinitionSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefinitionSchema.d.ts","sourceRoot":"","sources":["../../../../src/validators/generic/schema/DefinitionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAEjH;;;;;GAKG;AACH,qBAAa,gBAAgB;IACzB,gBAAgB,EAAE,qBAAqB,EAAE,CAAK;IAC9C;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAkC;IACzE,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAgC;gBAE3D,YAAY,EAAE,qBAAqB,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE;IAK5E,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAInD,cAAc,CAAC,IAAI,EAAE,qBAAqB,EAAE;IAI5C,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU;IAmB1C,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAI5C,WAAW,IAAI,UAAU,EAAE;IAI3B,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAIzE,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO;IAI3D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE;IASrC,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,EAAE,gBAAgB,EAAE,GAAG,gBAAgB;CAU/D"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { isObjectDefinition } from "./ValidationTypes.js";
|
|
2
|
+
/**
|
|
3
|
+
* A collection of object and primitive definitions describing JSON objects.
|
|
4
|
+
* Used to
|
|
5
|
+
* - validate an incoming JSON object
|
|
6
|
+
* - generate the corresponding TypeScript type definitions.
|
|
7
|
+
*/
|
|
8
|
+
export class DefinitionSchema {
|
|
9
|
+
constructor(taggedUnions, definitions) {
|
|
10
|
+
this.unionDefinitions = [];
|
|
11
|
+
/**
|
|
12
|
+
* Mapping from extenden object type name to list of extending Object Definitions
|
|
13
|
+
*/
|
|
14
|
+
this.taggedUnions = new Map();
|
|
15
|
+
this.definitionsMap = new Map();
|
|
16
|
+
this.add(definitions);
|
|
17
|
+
this.addTaggedUnion(taggedUnions);
|
|
18
|
+
}
|
|
19
|
+
getDefinition(name) {
|
|
20
|
+
return this.definitionsMap.get(name);
|
|
21
|
+
}
|
|
22
|
+
addTaggedUnion(defs) {
|
|
23
|
+
this.unionDefinitions.push(...defs);
|
|
24
|
+
}
|
|
25
|
+
add(definitions) {
|
|
26
|
+
if (!Array.isArray(definitions)) {
|
|
27
|
+
definitions = [definitions];
|
|
28
|
+
}
|
|
29
|
+
for (const def of definitions) {
|
|
30
|
+
if (isObjectDefinition(def)) {
|
|
31
|
+
if (def.taggedUnionType !== "") {
|
|
32
|
+
let existingExtends = this.taggedUnions.get(def.taggedUnionType);
|
|
33
|
+
if (existingExtends === undefined) {
|
|
34
|
+
existingExtends = [];
|
|
35
|
+
this.taggedUnions.set(def.taggedUnionType, existingExtends);
|
|
36
|
+
}
|
|
37
|
+
existingExtends.push(def);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
this.definitionsMap.set(def.name, def);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
isTagProperty(propertyName) {
|
|
44
|
+
return this.unionDefinitions.find(def => def.unionProperty === propertyName) !== undefined;
|
|
45
|
+
}
|
|
46
|
+
definitions() {
|
|
47
|
+
return Array.from(this.definitionsMap.values());
|
|
48
|
+
}
|
|
49
|
+
getTaggedUnionDefinition(name) {
|
|
50
|
+
return this.unionDefinitions.find(def => def.unionType === name);
|
|
51
|
+
}
|
|
52
|
+
isUnionDiscriminator(propDef) {
|
|
53
|
+
return this.unionDefinitions.find(def => def.unionDiscriminator === propDef.name) !== undefined;
|
|
54
|
+
}
|
|
55
|
+
extending(name) {
|
|
56
|
+
const result = this.taggedUnions.get(name);
|
|
57
|
+
if (result === undefined) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return Array.from(result.values());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static join(...schema) {
|
|
65
|
+
const result = new DefinitionSchema([], []);
|
|
66
|
+
schema.forEach(sch => {
|
|
67
|
+
sch.definitions().forEach(value => {
|
|
68
|
+
result.add([value]);
|
|
69
|
+
});
|
|
70
|
+
result.addTaggedUnion(sch.unionDefinitions);
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=DefinitionSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefinitionSchema.js","sourceRoot":"","sources":["../../../../src/validators/generic/schema/DefinitionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,kBAAkB,EAA8C,MAAM,sBAAsB,CAAA;AAEjH;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAQzB,YAAY,YAAqC,EAAE,WAAyB;QAP5E,qBAAgB,GAA4B,EAAE,CAAA;QAC9C;;WAEG;QACH,iBAA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,CAAA;IACjB,CAAC;CACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonContext } from "@lionweb/json-utils";
|
|
2
|
-
import { ValidationResult } from "
|
|
2
|
+
import { ValidationResult } from "../ValidationResult.js";
|
|
3
3
|
export type UnknownObjectType = {
|
|
4
4
|
[key: string]: unknown;
|
|
5
5
|
};
|
|
@@ -15,11 +15,11 @@ export type PropertyDefinition = {
|
|
|
15
15
|
/**
|
|
16
16
|
* The property name
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
name: string;
|
|
19
19
|
/**
|
|
20
20
|
* The expected type of the property value
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
type: string;
|
|
23
23
|
/**
|
|
24
24
|
* Whether the property value is allowed to be null
|
|
25
25
|
*/
|
|
@@ -38,14 +38,13 @@ export type PropertyDefinition = {
|
|
|
38
38
|
validate?: ValidatorFunction;
|
|
39
39
|
};
|
|
40
40
|
export type ValidatorFunction = <T>(obj: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition) => void;
|
|
41
|
+
export declare function emptyValidation<T>(object: T, result: ValidationResult, ctx: JsonContext, pdef?: PropertyDefinition): void;
|
|
41
42
|
export declare const MAY_BE_NULL = true;
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param propDef
|
|
45
|
-
* @constructor
|
|
44
|
+
* Definition of a primitive type.
|
|
46
45
|
*/
|
|
47
|
-
export declare function PropertyDef(propDef: PropertyDefinition): PropertyDefinition;
|
|
48
46
|
export type PrimitiveDefinition = {
|
|
47
|
+
name: string;
|
|
49
48
|
/**
|
|
50
49
|
* The expected type of the property value
|
|
51
50
|
*/
|
|
@@ -56,13 +55,47 @@ export type PrimitiveDefinition = {
|
|
|
56
55
|
validate?: ValidatorFunction;
|
|
57
56
|
};
|
|
58
57
|
/**
|
|
59
|
-
*
|
|
58
|
+
* Definition of an object type.
|
|
59
|
+
*/
|
|
60
|
+
export type ObjectDefinition = {
|
|
61
|
+
name: string;
|
|
62
|
+
properties: PropertyDefinition[];
|
|
63
|
+
/**
|
|
64
|
+
* The name of the tagged union that this type belongs to
|
|
65
|
+
*/
|
|
66
|
+
taggedUnionType?: string;
|
|
67
|
+
};
|
|
68
|
+
export type Definition = ObjectDefinition | PrimitiveDefinition;
|
|
69
|
+
/**
|
|
70
|
+
* Defionition of tagged union.
|
|
71
|
+
*/
|
|
72
|
+
export type TaggedUnionDefinition = {
|
|
73
|
+
/**
|
|
74
|
+
* The tagged union "super" type
|
|
75
|
+
*/
|
|
76
|
+
unionType: string;
|
|
77
|
+
/**
|
|
78
|
+
* The primitive property type that is the discriminator or tag
|
|
79
|
+
*/
|
|
80
|
+
unionDiscriminator: string;
|
|
81
|
+
/**
|
|
82
|
+
* The name of the property in an object that contains the discriminator value
|
|
83
|
+
*/
|
|
84
|
+
unionProperty: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Easy way to create a PrimitiveDefinition typed object with default values.
|
|
60
88
|
* @param propDef
|
|
61
89
|
* @constructor
|
|
62
90
|
*/
|
|
63
91
|
export declare function PrimitiveDef(propDef: PrimitiveDefinition): PrimitiveDefinition;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Easy way to create a PropertyDefinition typed object with default values.
|
|
94
|
+
* @param propDef
|
|
95
|
+
* @constructor
|
|
96
|
+
*/
|
|
97
|
+
export declare function PropertyDef(propDef: PropertyDefinition): PropertyDefinition;
|
|
98
|
+
export declare function isObjectDefinition(def: Definition | undefined): def is ObjectDefinition;
|
|
99
|
+
export declare function isPrimitiveDefinition(def: Definition | undefined): def is PrimitiveDefinition;
|
|
100
|
+
export declare function isJavaScriptPrimitive(type: string): boolean;
|
|
68
101
|
//# sourceMappingURL=ValidationTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationTypes.d.ts","sourceRoot":"","sources":["../../../../src/validators/generic/sch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;IACjC;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;AAC/D;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAChC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;CACxB,CAAA;AACD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,mBAAmB,CAO9E;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,CAU3E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,GAAG,GAAG,IAAI,gBAAgB,CAEvF;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,GAAG,GAAG,IAAI,mBAAmB,CAE7F;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default for the `validation` property, does nothing.
|
|
3
|
-
* @param object
|
|
4
|
-
* @param result
|
|
5
|
-
* @param ctx
|
|
6
|
-
* @param pdef
|
|
7
|
-
*/
|
|
8
1
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
function emptyValidation(object, result, ctx, pdef) { }
|
|
2
|
+
export function emptyValidation(object, result, ctx, pdef) { }
|
|
10
3
|
// Make boolean argument more readable.
|
|
11
4
|
export const MAY_BE_NULL = true;
|
|
12
5
|
/**
|
|
13
|
-
* Easy way to create a
|
|
6
|
+
* Easy way to create a PrimitiveDefinition typed object with default values.
|
|
14
7
|
* @param propDef
|
|
15
8
|
* @constructor
|
|
16
9
|
*/
|
|
17
|
-
export function
|
|
18
|
-
const {
|
|
10
|
+
export function PrimitiveDef(propDef) {
|
|
11
|
+
const { name, primitiveType, validate = emptyValidation } = propDef;
|
|
19
12
|
return {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
isList: isList,
|
|
23
|
-
mayBeNull: mayBeNull,
|
|
24
|
-
isOptional: isOptional,
|
|
13
|
+
name: name,
|
|
14
|
+
primitiveType: primitiveType,
|
|
25
15
|
validate: validate
|
|
26
16
|
};
|
|
27
17
|
}
|
|
@@ -30,17 +20,24 @@ export function PropertyDef(propDef) {
|
|
|
30
20
|
* @param propDef
|
|
31
21
|
* @constructor
|
|
32
22
|
*/
|
|
33
|
-
export function
|
|
34
|
-
const {
|
|
23
|
+
export function PropertyDef(propDef) {
|
|
24
|
+
const { name, type, mayBeNull = false, isList = false, isOptional = false, validate = emptyValidation } = propDef;
|
|
35
25
|
return {
|
|
36
|
-
|
|
26
|
+
name: name,
|
|
27
|
+
type: type,
|
|
28
|
+
isList: isList,
|
|
29
|
+
mayBeNull: mayBeNull,
|
|
30
|
+
isOptional: isOptional,
|
|
37
31
|
validate: validate
|
|
38
32
|
};
|
|
39
33
|
}
|
|
40
34
|
export function isObjectDefinition(def) {
|
|
41
|
-
return Array.isArray(def);
|
|
35
|
+
return (def !== undefined) && Array.isArray(def?.properties);
|
|
42
36
|
}
|
|
43
37
|
export function isPrimitiveDefinition(def) {
|
|
44
|
-
return def?.primitiveType !== undefined;
|
|
38
|
+
return (def !== undefined) && def?.primitiveType !== undefined;
|
|
39
|
+
}
|
|
40
|
+
export function isJavaScriptPrimitive(type) {
|
|
41
|
+
return ["number", "string", "boolean"].includes(type);
|
|
45
42
|
}
|
|
46
43
|
//# sourceMappingURL=ValidationTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationTypes.js","sourceRoot":"","sources":["../../../../src/validators/generic/schema/ValidationTypes.ts"],"names":[],"mappings":"AAyCA,6DAA6D;AAC7D,MAAM,UAAU,eAAe,CAA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+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/validators/generic/schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/generic/schema/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lionweb/validation",
|
|
3
|
-
"version": "0.7.0-beta.
|
|
3
|
+
"version": "0.7.0-beta.9",
|
|
4
4
|
"license": "Apache 2.0",
|
|
5
5
|
"description": "LionWeb Serialization validation",
|
|
6
6
|
"author": "jos.warmer@openmodeling.nl",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"republish-local": "yarn unpublish-local && yarn publish-local"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@lionweb/json": "0.7.0-beta.
|
|
36
|
-
"@lionweb/ts-utils": "0.7.0-beta.
|
|
37
|
-
"@lionweb/json-utils": "0.7.0-beta.
|
|
35
|
+
"@lionweb/json": "0.7.0-beta.9",
|
|
36
|
+
"@lionweb/ts-utils": "0.7.0-beta.9",
|
|
37
|
+
"@lionweb/json-utils": "0.7.0-beta.9"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/runners/Utils.ts
CHANGED
|
@@ -48,7 +48,7 @@ export function printIssues(result: ValidationResult, file?: string): void {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function issuestoString(vresult: ValidationResult, file?: string): string {
|
|
51
|
-
let result = ""
|
|
52
|
-
vresult.issues.forEach(issue => (result += (file
|
|
51
|
+
let result = "ISSUES: "
|
|
52
|
+
vresult.issues.forEach(issue => (result += (file === undefined ? "NOFILE" : `File ${file}: `) + issue.errorMsg() + "\n"))
|
|
53
53
|
return result
|
|
54
54
|
}
|