@lionweb/validation 0.7.2-beta.6 → 0.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/validators/LionWebReferenceValidator.d.ts +19 -1
- package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebReferenceValidator.js +20 -2
- package/dist/validators/LionWebReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts +0 -3
- package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +10 -3
- package/dist/validators/LionWebSyntaxValidator.js.map +1 -1
- package/dist/validators/ValidationFunctions.d.ts +1 -1
- package/dist/validators/ValidationFunctions.d.ts.map +1 -1
- package/dist/validators/definitions/ChunksDefinitions.d.ts +3 -0
- package/dist/validators/definitions/ChunksDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/ChunksDefinitions.js +251 -0
- package/dist/validators/definitions/ChunksDefinitions.js.map +1 -0
- package/dist/validators/definitions/CommandDefinitions.d.ts +3 -0
- package/dist/validators/definitions/CommandDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/CommandDefinitions.js +2138 -0
- package/dist/validators/definitions/CommandDefinitions.js.map +1 -0
- package/dist/validators/definitions/DeltaTypesDefinitions.d.ts +3 -0
- package/dist/validators/definitions/DeltaTypesDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/DeltaTypesDefinitions.js +116 -0
- package/dist/validators/definitions/DeltaTypesDefinitions.js.map +1 -0
- package/dist/validators/definitions/EventDefinitions.d.ts +3 -0
- package/dist/validators/definitions/EventDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/EventDefinitions.js +2806 -0
- package/dist/validators/definitions/EventDefinitions.js.map +1 -0
- package/dist/validators/definitions/QueryDefinitions.d.ts +3 -0
- package/dist/validators/definitions/QueryDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/QueryDefinitions.js +145 -0
- package/dist/validators/definitions/QueryDefinitions.js.map +1 -0
- package/dist/validators/definitions/RequestDefinitions.d.ts +3 -0
- package/dist/validators/definitions/RequestDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/RequestDefinitions.js +315 -0
- package/dist/validators/definitions/RequestDefinitions.js.map +1 -0
- package/dist/validators/definitions/ResponseDefinitions.d.ts +3 -0
- package/dist/validators/definitions/ResponseDefinitions.d.ts.map +1 -0
- package/dist/validators/definitions/ResponseDefinitions.js +273 -0
- package/dist/validators/definitions/ResponseDefinitions.js.map +1 -0
- package/dist/validators/definitions/index.d.ts +8 -0
- package/dist/validators/definitions/index.d.ts.map +1 -0
- package/dist/validators/definitions/index.js +8 -0
- package/dist/validators/definitions/index.js.map +1 -0
- package/dist/validators/generic/SyntaxValidator.d.ts +7 -6
- package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -1
- package/dist/validators/generic/SyntaxValidator.js +53 -21
- package/dist/validators/generic/SyntaxValidator.js.map +1 -1
- package/dist/validators/generic/schema/SyntaxDefinition.d.ts +45 -0
- package/dist/validators/generic/schema/SyntaxDefinition.d.ts.map +1 -0
- package/dist/validators/generic/schema/SyntaxDefinition.js +39 -0
- package/dist/validators/generic/schema/SyntaxDefinition.js.map +1 -0
- package/dist/validators/generic/schema/index.d.ts +1 -2
- package/dist/validators/generic/schema/index.d.ts.map +1 -1
- package/dist/validators/generic/schema/index.js +1 -2
- package/dist/validators/generic/schema/index.js.map +1 -1
- package/dist/validators/index.d.ts +1 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +1 -1
- package/dist/validators/index.js.map +1 -1
- package/package.json +4 -4
- package/src/validators/LionWebReferenceValidator.ts +20 -2
- package/src/validators/LionWebSyntaxValidator.ts +10 -3
- package/src/validators/ValidationFunctions.ts +1 -1
- package/src/validators/definitions/ChunksDefinitions.ts +252 -0
- package/src/validators/definitions/CommandDefinitions.ts +2139 -0
- package/src/validators/definitions/DeltaTypesDefinitions.ts +117 -0
- package/src/validators/definitions/EventDefinitions.ts +2807 -0
- package/src/validators/definitions/QueryDefinitions.ts +146 -0
- package/src/validators/definitions/README.md +17 -0
- package/src/validators/definitions/RequestDefinitions.ts +316 -0
- package/src/validators/definitions/ResponseDefinitions.ts +274 -0
- package/src/validators/definitions/index.ts +7 -0
- package/src/validators/generic/SyntaxValidator.ts +60 -29
- package/src/validators/generic/index.ts +1 -0
- package/src/validators/generic/schema/SyntaxDefinition.ts +83 -0
- package/src/validators/generic/schema/index.ts +1 -2
- package/src/validators/index.ts +1 -1
- package/dist/validators/LionWebChunkDefinitions.d.ts +0 -9
- package/dist/validators/LionWebChunkDefinitions.d.ts.map +0 -1
- package/dist/validators/LionWebChunkDefinitions.js +0 -100
- package/dist/validators/LionWebChunkDefinitions.js.map +0 -1
- package/dist/validators/generic/schema/DefinitionSchema.d.ts +0 -23
- package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +0 -1
- package/dist/validators/generic/schema/DefinitionSchema.js +0 -43
- package/dist/validators/generic/schema/DefinitionSchema.js.map +0 -1
- package/dist/validators/generic/schema/ValidationTypes.d.ts +0 -101
- package/dist/validators/generic/schema/ValidationTypes.d.ts.map +0 -1
- package/dist/validators/generic/schema/ValidationTypes.js +0 -43
- package/dist/validators/generic/schema/ValidationTypes.js.map +0 -1
- package/src/validators/LionWebChunkDefinitions.ts +0 -104
- package/src/validators/generic/schema/DefinitionSchema.ts +0 -52
- package/src/validators/generic/schema/ValidationTypes.ts +0 -134
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { MessageGroup } from "../generic/schema/SyntaxDefinition.js";
|
|
2
|
+
|
|
3
|
+
export const ResponseDefinitions: MessageGroup = {
|
|
4
|
+
name: "Response",
|
|
5
|
+
taggedUnionProperty: "messageKind",
|
|
6
|
+
sharedProperties: [
|
|
7
|
+
{
|
|
8
|
+
name: "messageKind",
|
|
9
|
+
type: "String",
|
|
10
|
+
isList: false,
|
|
11
|
+
isOptional: false,
|
|
12
|
+
mayBeNull: false,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "protocolMessages",
|
|
16
|
+
type: "ProtocolMessage",
|
|
17
|
+
isList: true,
|
|
18
|
+
isOptional: false,
|
|
19
|
+
mayBeNull: false,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "queryId",
|
|
23
|
+
type: "QueryId",
|
|
24
|
+
isList: false,
|
|
25
|
+
isOptional: false,
|
|
26
|
+
mayBeNull: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
messages: [
|
|
30
|
+
{
|
|
31
|
+
name: "SubscribeToChangingPartitionsResponse",
|
|
32
|
+
properties: [
|
|
33
|
+
{
|
|
34
|
+
name: "messageKind",
|
|
35
|
+
type: "String",
|
|
36
|
+
isList: false,
|
|
37
|
+
isOptional: false,
|
|
38
|
+
mayBeNull: false,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "protocolMessages",
|
|
42
|
+
type: "ProtocolMessage",
|
|
43
|
+
isList: true,
|
|
44
|
+
isOptional: false,
|
|
45
|
+
mayBeNull: false,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "queryId",
|
|
49
|
+
type: "QueryId",
|
|
50
|
+
isList: false,
|
|
51
|
+
isOptional: false,
|
|
52
|
+
mayBeNull: false,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "SubscribeToPartitionContentsResponse",
|
|
58
|
+
properties: [
|
|
59
|
+
{
|
|
60
|
+
name: "contents",
|
|
61
|
+
type: "LionWebDeltaJsonChunk",
|
|
62
|
+
isList: false,
|
|
63
|
+
isOptional: false,
|
|
64
|
+
mayBeNull: false,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "messageKind",
|
|
68
|
+
type: "String",
|
|
69
|
+
isList: false,
|
|
70
|
+
isOptional: false,
|
|
71
|
+
mayBeNull: false,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "protocolMessages",
|
|
75
|
+
type: "ProtocolMessage",
|
|
76
|
+
isList: true,
|
|
77
|
+
isOptional: false,
|
|
78
|
+
mayBeNull: false,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "queryId",
|
|
82
|
+
type: "QueryId",
|
|
83
|
+
isList: false,
|
|
84
|
+
isOptional: false,
|
|
85
|
+
mayBeNull: false,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "UnsubscribeFromPartitionContentsResponse",
|
|
91
|
+
properties: [
|
|
92
|
+
{
|
|
93
|
+
name: "messageKind",
|
|
94
|
+
type: "String",
|
|
95
|
+
isList: false,
|
|
96
|
+
isOptional: false,
|
|
97
|
+
mayBeNull: false,
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "protocolMessages",
|
|
101
|
+
type: "ProtocolMessage",
|
|
102
|
+
isList: true,
|
|
103
|
+
isOptional: false,
|
|
104
|
+
mayBeNull: false,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "queryId",
|
|
108
|
+
type: "QueryId",
|
|
109
|
+
isList: false,
|
|
110
|
+
isOptional: false,
|
|
111
|
+
mayBeNull: false,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "SignOnResponse",
|
|
117
|
+
properties: [
|
|
118
|
+
{
|
|
119
|
+
name: "participationId",
|
|
120
|
+
type: "ParticipationId",
|
|
121
|
+
isList: false,
|
|
122
|
+
isOptional: false,
|
|
123
|
+
mayBeNull: false,
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "messageKind",
|
|
127
|
+
type: "String",
|
|
128
|
+
isList: false,
|
|
129
|
+
isOptional: false,
|
|
130
|
+
mayBeNull: false,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "protocolMessages",
|
|
134
|
+
type: "ProtocolMessage",
|
|
135
|
+
isList: true,
|
|
136
|
+
isOptional: false,
|
|
137
|
+
mayBeNull: false,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "queryId",
|
|
141
|
+
type: "QueryId",
|
|
142
|
+
isList: false,
|
|
143
|
+
isOptional: false,
|
|
144
|
+
mayBeNull: false,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: "SignOffResponse",
|
|
150
|
+
properties: [
|
|
151
|
+
{
|
|
152
|
+
name: "messageKind",
|
|
153
|
+
type: "String",
|
|
154
|
+
isList: false,
|
|
155
|
+
isOptional: false,
|
|
156
|
+
mayBeNull: false,
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "protocolMessages",
|
|
160
|
+
type: "ProtocolMessage",
|
|
161
|
+
isList: true,
|
|
162
|
+
isOptional: false,
|
|
163
|
+
mayBeNull: false,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "queryId",
|
|
167
|
+
type: "QueryId",
|
|
168
|
+
isList: false,
|
|
169
|
+
isOptional: false,
|
|
170
|
+
mayBeNull: false,
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "ReconnectResponse",
|
|
176
|
+
properties: [
|
|
177
|
+
{
|
|
178
|
+
name: "lastSentSequenceNumber",
|
|
179
|
+
type: "SequenceNumber",
|
|
180
|
+
isList: false,
|
|
181
|
+
isOptional: false,
|
|
182
|
+
mayBeNull: false,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "messageKind",
|
|
186
|
+
type: "String",
|
|
187
|
+
isList: false,
|
|
188
|
+
isOptional: false,
|
|
189
|
+
mayBeNull: false,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "protocolMessages",
|
|
193
|
+
type: "ProtocolMessage",
|
|
194
|
+
isList: true,
|
|
195
|
+
isOptional: false,
|
|
196
|
+
mayBeNull: false,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
name: "queryId",
|
|
200
|
+
type: "QueryId",
|
|
201
|
+
isList: false,
|
|
202
|
+
isOptional: false,
|
|
203
|
+
mayBeNull: false,
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "GetAvailableIdsResponse",
|
|
209
|
+
properties: [
|
|
210
|
+
{
|
|
211
|
+
name: "ids",
|
|
212
|
+
type: "LionWebId",
|
|
213
|
+
isList: true,
|
|
214
|
+
isOptional: false,
|
|
215
|
+
mayBeNull: false,
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: "messageKind",
|
|
219
|
+
type: "String",
|
|
220
|
+
isList: false,
|
|
221
|
+
isOptional: false,
|
|
222
|
+
mayBeNull: false,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "protocolMessages",
|
|
226
|
+
type: "ProtocolMessage",
|
|
227
|
+
isList: true,
|
|
228
|
+
isOptional: false,
|
|
229
|
+
mayBeNull: false,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: "queryId",
|
|
233
|
+
type: "QueryId",
|
|
234
|
+
isList: false,
|
|
235
|
+
isOptional: false,
|
|
236
|
+
mayBeNull: false,
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: "ListPartitionsResponse",
|
|
242
|
+
properties: [
|
|
243
|
+
{
|
|
244
|
+
name: "partitions",
|
|
245
|
+
type: "LionWebDeltaJsonChunk",
|
|
246
|
+
isList: false,
|
|
247
|
+
isOptional: false,
|
|
248
|
+
mayBeNull: false,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: "messageKind",
|
|
252
|
+
type: "String",
|
|
253
|
+
isList: false,
|
|
254
|
+
isOptional: false,
|
|
255
|
+
mayBeNull: false,
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "protocolMessages",
|
|
259
|
+
type: "ProtocolMessage",
|
|
260
|
+
isList: true,
|
|
261
|
+
isOptional: false,
|
|
262
|
+
mayBeNull: false,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: "queryId",
|
|
266
|
+
type: "QueryId",
|
|
267
|
+
isList: false,
|
|
268
|
+
isOptional: false,
|
|
269
|
+
mayBeNull: false,
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./ChunksDefinitions.js"
|
|
2
|
+
export * from "./CommandDefinitions.js"
|
|
3
|
+
export * from "./DeltaTypesDefinitions.js"
|
|
4
|
+
export * from "./EventDefinitions.js"
|
|
5
|
+
export * from "./QueryDefinitions.js"
|
|
6
|
+
export * from "./RequestDefinitions.js"
|
|
7
|
+
export * from "./ResponseDefinitions.js"
|
|
@@ -6,12 +6,9 @@ import {
|
|
|
6
6
|
Syntax_PropertyTypeIssue,
|
|
7
7
|
Syntax_PropertyUnknownIssue
|
|
8
8
|
} from "../../issues/index.js"
|
|
9
|
+
import { SyntaxDefinition, StructuredType, PrimitiveType } from "./schema/SyntaxDefinition.js"
|
|
9
10
|
import { ValidationResult } from "./ValidationResult.js"
|
|
10
|
-
import {
|
|
11
|
-
isObjectDefinition,
|
|
12
|
-
isPrimitiveDefinition, ObjectDefinition, PrimitiveDefinition, DefinitionSchema,
|
|
13
|
-
UnknownObjectType
|
|
14
|
-
} from "./schema/index.js"
|
|
11
|
+
import { UnknownObjectType } from "./schema/index.js"
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* Syntax Validator checks whether objects are structurally conforming to the
|
|
@@ -19,9 +16,9 @@ import {
|
|
|
19
16
|
*/
|
|
20
17
|
export class SyntaxValidator {
|
|
21
18
|
validationResult: ValidationResult
|
|
22
|
-
schema:
|
|
19
|
+
schema: SyntaxDefinition
|
|
23
20
|
|
|
24
|
-
constructor(validationResult: ValidationResult, schema:
|
|
21
|
+
constructor(validationResult: ValidationResult, schema: SyntaxDefinition) {
|
|
25
22
|
this.validationResult = validationResult
|
|
26
23
|
this.schema = schema
|
|
27
24
|
}
|
|
@@ -34,14 +31,19 @@ export class SyntaxValidator {
|
|
|
34
31
|
*/
|
|
35
32
|
validate(obj: unknown, expectedType: string) {
|
|
36
33
|
const object = obj as UnknownObjectType
|
|
37
|
-
const
|
|
34
|
+
const primitiveTypeDef: PrimitiveType | undefined = this.schema.getPrimitiveType(expectedType)
|
|
38
35
|
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
if (primitiveTypeDef === undefined) {
|
|
37
|
+
const objectTypeDef: StructuredType | undefined = this.schema.getStructuredType(expectedType)
|
|
38
|
+
if( objectTypeDef === undefined) {
|
|
39
|
+
throw new Error(`SyntaxValidator.validate: cannot find definition for '${expectedType}'`)
|
|
40
|
+
} else {
|
|
41
|
+
// ObjectType found
|
|
42
|
+
this.validateObjectProperties(expectedType, objectTypeDef, object, new JsonContext(null, ["$"]))
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
// PrimitiveType found
|
|
46
|
+
this.validatePrimitiveValue("$", primitiveTypeDef, object, new JsonContext(null, ["$"]))
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
|
|
@@ -53,7 +55,7 @@ export class SyntaxValidator {
|
|
|
53
55
|
* @param jsonContext The location in the JSON
|
|
54
56
|
* @private
|
|
55
57
|
*/
|
|
56
|
-
validateObjectProperties(originalProperty: string, typeDef:
|
|
58
|
+
validateObjectProperties(originalProperty: string, typeDef: StructuredType, object: UnknownObjectType, jsonContext: JsonContext) {
|
|
57
59
|
if (typeDef === null || typeDef === undefined) {
|
|
58
60
|
return
|
|
59
61
|
}
|
|
@@ -62,8 +64,13 @@ export class SyntaxValidator {
|
|
|
62
64
|
return
|
|
63
65
|
}
|
|
64
66
|
for (const propertyDef of typeDef.properties) {
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
+
const expectedTypeDefPrimitive = this.schema.getPrimitiveType(propertyDef.type)
|
|
68
|
+
const expectedTypeDefStructured = this.schema.getStructuredType(propertyDef.type)
|
|
69
|
+
const expectedMessageGroup = this.schema.getMessageGroup(propertyDef.type)
|
|
70
|
+
const expectedTypeDef = expectedTypeDefPrimitive ?? expectedTypeDefStructured
|
|
71
|
+
|
|
72
|
+
const validator = this.schema.getValidator(propertyDef.name)
|
|
73
|
+
|
|
67
74
|
const propertyValue = object[propertyDef.name]
|
|
68
75
|
if (propertyValue === undefined) {
|
|
69
76
|
if (!propertyDef.isOptional) {
|
|
@@ -93,15 +100,25 @@ export class SyntaxValidator {
|
|
|
93
100
|
this.validationResult.issue(new Syntax_ArrayContainsNull_Issue(newContext, propertyDef.name, index))
|
|
94
101
|
} else {
|
|
95
102
|
if (expectedTypeDef !== undefined) {
|
|
96
|
-
if (
|
|
103
|
+
if (expectedTypeDef === expectedTypeDefPrimitive) {
|
|
97
104
|
if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, item, jsonContext)) {
|
|
98
|
-
validator
|
|
105
|
+
if (validator !== undefined) {
|
|
106
|
+
validator(item, this.validationResult, newContext)
|
|
107
|
+
}
|
|
99
108
|
}
|
|
100
|
-
} else {
|
|
109
|
+
} else if (expectedTypeDef === expectedTypeDefStructured) {
|
|
101
110
|
// propertyValue should be an object, validate its properties
|
|
102
111
|
this.validateObjectProperties(propertyDef.name, expectedTypeDef, item as UnknownObjectType, newContext)
|
|
103
|
-
validator
|
|
112
|
+
if (validator !== undefined) {
|
|
113
|
+
validator(item, this.validationResult, newContext)
|
|
114
|
+
}
|
|
104
115
|
}
|
|
116
|
+
} else if (expectedMessageGroup !== undefined) {
|
|
117
|
+
console.log(`+++++++++++++++++++ ${expectedMessageGroup.name}`)
|
|
118
|
+
const messageKind = item[expectedMessageGroup.taggedUnionProperty] as string
|
|
119
|
+
const groupTypeDef = this.schema.getStructuredType(messageKind)!
|
|
120
|
+
this.validateObjectProperties(originalProperty, groupTypeDef, item as UnknownObjectType, newContext)
|
|
121
|
+
|
|
105
122
|
} else {
|
|
106
123
|
throw new Error(`Expected type '${propertyDef.type} has neither property defs, nor a validator.`)
|
|
107
124
|
}
|
|
@@ -115,21 +132,32 @@ export class SyntaxValidator {
|
|
|
115
132
|
}
|
|
116
133
|
// Single valued property, validate it
|
|
117
134
|
if (expectedTypeDef !== undefined) {
|
|
118
|
-
|
|
135
|
+
// const primitiveType = this.schema.getPrimitiveType(expectedTypeDef.name)
|
|
136
|
+
if (expectedTypeDef === expectedTypeDefPrimitive) {
|
|
119
137
|
// propertyValue should be a primitive as it has no property definitions
|
|
120
138
|
if (this.validatePrimitiveValue(propertyDef.name, expectedTypeDef, propertyValue, jsonContext)) {
|
|
121
|
-
validator
|
|
139
|
+
if (validator !== undefined) {
|
|
140
|
+
validator(propertyValue, this.validationResult, newContext)
|
|
141
|
+
}
|
|
122
142
|
}
|
|
123
|
-
} else if (
|
|
143
|
+
} else if (expectedTypeDef === expectedTypeDefStructured) {
|
|
124
144
|
// propertyValue should be an object, validate its properties
|
|
125
145
|
this.validateObjectProperties(propertyDef.name, expectedTypeDef, propertyValue as UnknownObjectType, newContext)
|
|
126
|
-
validator
|
|
146
|
+
if (validator !== undefined) {
|
|
147
|
+
validator(propertyValue, this.validationResult, newContext)
|
|
148
|
+
}
|
|
149
|
+
} else if (expectedMessageGroup !== undefined) {
|
|
150
|
+
console.log(`+++++++++++++++++++ LIST ${expectedMessageGroup.name}`)
|
|
151
|
+
const messageKind = object[expectedMessageGroup.taggedUnionProperty] as string
|
|
152
|
+
const groupTypeDef = this.schema.getStructuredType(messageKind)!
|
|
153
|
+
this.validateObjectProperties(originalProperty, groupTypeDef, propertyValue as UnknownObjectType, newContext)
|
|
127
154
|
} else {
|
|
128
155
|
throw new Error("EXPECTING ObjectDefinition or PrimitiveDefinition, but got something else")
|
|
129
156
|
}
|
|
130
157
|
} else {
|
|
131
158
|
throw new Error(
|
|
132
|
-
`Expected single type '${propertyDef.type}' for '${propertyDef.name}' at ${newContext.toString()} has neither property defs, nor a validator
|
|
159
|
+
`Op ${originalProperty}: Expected single type '${propertyDef.type}' for '${propertyDef.name}' at ${newContext.toString()} has neither property defs, nor a validator.
|
|
160
|
+
Typedef is ${JSON.stringify(typeDef)}`
|
|
133
161
|
)
|
|
134
162
|
}
|
|
135
163
|
}
|
|
@@ -137,12 +165,15 @@ export class SyntaxValidator {
|
|
|
137
165
|
this.checkStrayProperties(object, typeDef, jsonContext)
|
|
138
166
|
}
|
|
139
167
|
|
|
140
|
-
validatePrimitiveValue(propertyName: string, propDef:
|
|
168
|
+
validatePrimitiveValue(propertyName: string, propDef: PrimitiveType, object: unknown, jsonContext: JsonContext): boolean {
|
|
141
169
|
if (typeof object !== propDef.primitiveType) {
|
|
142
170
|
this.validationResult.issue(new Syntax_PropertyTypeIssue(jsonContext, propertyName, propDef.primitiveType, typeof object))
|
|
143
171
|
return false
|
|
144
172
|
}
|
|
145
|
-
|
|
173
|
+
const validator = this.schema.getValidator(propDef.name)
|
|
174
|
+
if (validator !== undefined) {
|
|
175
|
+
validator(object, this.validationResult, jsonContext)
|
|
176
|
+
}
|
|
146
177
|
return true
|
|
147
178
|
}
|
|
148
179
|
|
|
@@ -152,7 +183,7 @@ export class SyntaxValidator {
|
|
|
152
183
|
* @param properties The names of the expected properties
|
|
153
184
|
* @param context Location in JSON
|
|
154
185
|
*/
|
|
155
|
-
checkStrayProperties(obj: UnknownObjectType, def:
|
|
186
|
+
checkStrayProperties(obj: UnknownObjectType, def: StructuredType, context: JsonContext) {
|
|
156
187
|
const own = Object.getOwnPropertyNames(obj)
|
|
157
188
|
const defined = def.properties.map(pdef => pdef.name)
|
|
158
189
|
own.forEach(ownProp => {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { JsonContext } from "@lionweb/json-utils"
|
|
2
|
+
import { ValidationResult } from "../ValidationResult.js"
|
|
3
|
+
|
|
4
|
+
export type UnknownObjectType = { [key: string]: unknown }
|
|
5
|
+
|
|
6
|
+
export type PrimitiveValidatorFunction = <T>(obj: T, result: ValidationResult, ctx: JsonContext) => void
|
|
7
|
+
|
|
8
|
+
export type MessageGroup = {
|
|
9
|
+
name: string;
|
|
10
|
+
taggedUnionProperty: string; // messageKind
|
|
11
|
+
sharedProperties: PropertyDefinition[];
|
|
12
|
+
messages: StructuredType[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type PropertyDefinition = {
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
isList: boolean,
|
|
19
|
+
isOptional: boolean,
|
|
20
|
+
mayBeNull: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type StructuredType = {
|
|
24
|
+
name: string;
|
|
25
|
+
properties: PropertyDefinition[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type TypeGroup = {
|
|
29
|
+
name: string;
|
|
30
|
+
primitiveTypes: PrimitiveType[];
|
|
31
|
+
structuredTypes: StructuredType[];
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
export type PrimitiveType = {
|
|
35
|
+
name: string
|
|
36
|
+
primitiveType: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class SyntaxDefinition {
|
|
40
|
+
// Maps to make searching easier and faster
|
|
41
|
+
allPrimitiveTypes: Map<string, PrimitiveType> = new Map<string, PrimitiveType>()
|
|
42
|
+
allStructuredTypes: Map<string, StructuredType> = new Map<string, StructuredType>()
|
|
43
|
+
allMessageGroups: Map<string, MessageGroup> = new Map<string, MessageGroup>()
|
|
44
|
+
|
|
45
|
+
validateFunctions: Map<string, PrimitiveValidatorFunction> = new Map<string, PrimitiveValidatorFunction>()
|
|
46
|
+
|
|
47
|
+
constructor(messageGroups: MessageGroup[], typeGroups: TypeGroup[]) {
|
|
48
|
+
typeGroups.forEach(typeGroup => {
|
|
49
|
+
typeGroup.primitiveTypes.forEach(primitiveType => {
|
|
50
|
+
this.allPrimitiveTypes.set(primitiveType.name, primitiveType)
|
|
51
|
+
})
|
|
52
|
+
typeGroup.structuredTypes.forEach(objectType => {
|
|
53
|
+
this.allStructuredTypes.set(objectType.name, objectType)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
messageGroups.forEach(messageGroup => {
|
|
57
|
+
this.allMessageGroups.set(messageGroup.name, messageGroup)
|
|
58
|
+
messageGroup.messages.forEach(msg => {
|
|
59
|
+
this.allStructuredTypes.set(msg.name, msg)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
addValidator(primitiveTypeName: string, validate: PrimitiveValidatorFunction): void {
|
|
65
|
+
this.validateFunctions.set(primitiveTypeName, validate)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getValidator(primitiveTypeName: string): PrimitiveValidatorFunction | undefined {
|
|
69
|
+
return this.validateFunctions.get(primitiveTypeName)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getPrimitiveType(name: string): PrimitiveType | undefined {
|
|
73
|
+
return this.allPrimitiveTypes.get(name)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getStructuredType(name: string): StructuredType | undefined {
|
|
77
|
+
return this.allStructuredTypes.get(name)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getMessageGroup(name: string): MessageGroup | undefined {
|
|
81
|
+
return this.allMessageGroups.get(name)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./DefinitionSchema.js"
|
|
1
|
+
export * from "./SyntaxDefinition.js"
|
package/src/validators/index.ts
CHANGED
|
@@ -4,5 +4,5 @@ export * from "./LionWebReferenceValidator.js"
|
|
|
4
4
|
export * from "./LionWebLanguageValidator.js"
|
|
5
5
|
export * from "./LionWebLanguageReferenceValidator.js"
|
|
6
6
|
export * from "./LionWebValidator.js"
|
|
7
|
+
export * from "./definitions/index.js"
|
|
7
8
|
export * from "./ValidationFunctions.js"
|
|
8
|
-
export * from "./LionWebChunkDefinitions.js"
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DefinitionSchema } from "./generic/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* The structure below defines the structure of a LionWeb Chunk by defining all the properties.
|
|
4
|
-
* It can
|
|
5
|
-
* - be used by the SyntaxValidator to validate an object sat runtime.
|
|
6
|
-
* - used to generate all the TypeScript types for a LionWebChunk.
|
|
7
|
-
*/
|
|
8
|
-
export declare const LionWebSchema: DefinitionSchema;
|
|
9
|
-
//# sourceMappingURL=LionWebChunkDefinitions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LionWebChunkDefinitions.d.ts","sourceRoot":"","sources":["../../src/validators/LionWebChunkDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA2C,MAAM,oBAAoB,CAAA;AAG9F;;;;;GAKG;AACH,eAAO,MAAM,aAAa,EAAE,gBA0F1B,CAAA"}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { DefinitionSchema, MAY_BE_NULL, PropertyDef, PrimitiveDef } from "./generic/index.js";
|
|
2
|
-
import { validateId, validateKey, validateSerializationFormatVersion, validateVersion } from "./ValidationFunctions.js";
|
|
3
|
-
/**
|
|
4
|
-
* The structure below defines the structure of a LionWeb Chunk by defining all the properties.
|
|
5
|
-
* It can
|
|
6
|
-
* - be used by the SyntaxValidator to validate an object sat runtime.
|
|
7
|
-
* - used to generate all the TypeScript types for a LionWebChunk.
|
|
8
|
-
*/
|
|
9
|
-
export const LionWebSchema = new DefinitionSchema([
|
|
10
|
-
{
|
|
11
|
-
name: "LionWebJsonMetaPointer",
|
|
12
|
-
properties: [
|
|
13
|
-
PropertyDef({ name: "key", type: "LionWebKey" }),
|
|
14
|
-
PropertyDef({ name: "version", type: "LionWebVersion" }),
|
|
15
|
-
PropertyDef({ name: "language", type: "LionWebKey" })
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: "LionWebJsonMetaPointer",
|
|
20
|
-
properties: [
|
|
21
|
-
PropertyDef({ name: "key", type: "LionWebKey" }),
|
|
22
|
-
PropertyDef({ name: "version", type: "LionWebVersion" }),
|
|
23
|
-
PropertyDef({ name: "language", type: "LionWebKey" }),
|
|
24
|
-
]
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: "ResponseMessage",
|
|
28
|
-
properties: [
|
|
29
|
-
PropertyDef({ name: "kind", type: "JSstring" }),
|
|
30
|
-
PropertyDef({ name: "message", type: "JSstring" }),
|
|
31
|
-
PropertyDef({ name: "data", type: "JSobject", mayBeNull: true, isOptional: true })
|
|
32
|
-
]
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
name: "LionWebJsonChunk",
|
|
36
|
-
properties: [
|
|
37
|
-
PropertyDef({ name: "serializationFormatVersion", type: "LionWebSerializationFormatVersion" }),
|
|
38
|
-
PropertyDef({ name: "languages", type: "LionWebJsonUsedLanguage", isList: true }),
|
|
39
|
-
PropertyDef({ name: "nodes", type: "LionWebJsonNode", isList: true })
|
|
40
|
-
]
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "LionWebJsonUsedLanguage",
|
|
44
|
-
properties: [
|
|
45
|
-
PropertyDef({ name: "key", type: "LionWebKey" }),
|
|
46
|
-
PropertyDef({ name: "version", type: "LionWebVersion" })
|
|
47
|
-
]
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: "LionWebJsonNode",
|
|
51
|
-
properties: [
|
|
52
|
-
PropertyDef({ name: "id", type: "LionWebId" }),
|
|
53
|
-
PropertyDef({ name: "classifier", type: "LionWebJsonMetaPointer" }),
|
|
54
|
-
PropertyDef({ name: "properties", type: "LionWebJsonProperty", isList: true }),
|
|
55
|
-
PropertyDef({ name: "containments", type: "LionWebJsonContainment", isList: true }),
|
|
56
|
-
PropertyDef({ name: "references", type: "LionWebJsonReference", isList: true }),
|
|
57
|
-
PropertyDef({ name: "annotations", type: "LionWebId", isList: true }),
|
|
58
|
-
PropertyDef({ name: "parent", type: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "LionWebJsonProperty",
|
|
63
|
-
properties: [
|
|
64
|
-
PropertyDef({ name: "property", type: "LionWebJsonMetaPointer" }),
|
|
65
|
-
PropertyDef({ name: "value", type: "JSstring", mayBeNull: MAY_BE_NULL }),
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: "LionWebJsonContainment",
|
|
70
|
-
properties: [
|
|
71
|
-
PropertyDef({ name: "containment", type: "LionWebJsonMetaPointer" }),
|
|
72
|
-
PropertyDef({ name: "children", type: "LionWebId", isList: true }),
|
|
73
|
-
]
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "LionWebJsonReference",
|
|
77
|
-
properties: [
|
|
78
|
-
PropertyDef({ name: "reference", type: "LionWebJsonMetaPointer" }),
|
|
79
|
-
PropertyDef({ name: "targets", type: "LionWebJsonReferenceTarget", isList: true }),
|
|
80
|
-
]
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: "LionWebJsonReferenceTarget",
|
|
84
|
-
properties: [
|
|
85
|
-
PropertyDef({ name: "resolveInfo", type: "JSstring", mayBeNull: MAY_BE_NULL }),
|
|
86
|
-
PropertyDef({ name: "reference", type: "LionWebId", mayBeNull: MAY_BE_NULL }),
|
|
87
|
-
]
|
|
88
|
-
},
|
|
89
|
-
/**
|
|
90
|
-
* Elements without properties are assumed to be JSON/JS primitive values, and tested using `typeof`
|
|
91
|
-
* and the (optional) validate function.
|
|
92
|
-
*/
|
|
93
|
-
PrimitiveDef({ name: "LionWebId", primitiveType: "string", validate: validateId }),
|
|
94
|
-
PrimitiveDef({ name: "LionWebKey", primitiveType: "string", validate: validateKey }),
|
|
95
|
-
PrimitiveDef({ name: "LionWebVersion", primitiveType: "string", validate: validateVersion }),
|
|
96
|
-
PrimitiveDef({ name: "LionWebSerializationFormatVersion", primitiveType: "string", validate: validateSerializationFormatVersion }),
|
|
97
|
-
PrimitiveDef({ name: "JSstring", primitiveType: "string" }),
|
|
98
|
-
PrimitiveDef({ name: "JSobject", primitiveType: "object" }),
|
|
99
|
-
]);
|
|
100
|
-
//# sourceMappingURL=LionWebChunkDefinitions.js.map
|