@lionweb/validation 0.5.0-beta.8
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/LICENSE +201 -0
- package/README.md +31 -0
- package/build.sh +6 -0
- package/package.json +28 -0
- package/src/diff/LionwebDiff.ts +193 -0
- package/src/issues/LanguageIssues.ts +91 -0
- package/src/issues/ReferenceIssues.ts +60 -0
- package/src/issues/SyntaxIssues.ts +68 -0
- package/src/issues/ValidationIssue.ts +46 -0
- package/src/json/ChunkUtils.ts +53 -0
- package/src/json/LanguageUtils.ts +12 -0
- package/src/json/LionWebJson.ts +77 -0
- package/src/json/LionWebJsonChunkWrapper.ts +74 -0
- package/src/json/LionWebLanguageDefinition.ts +141 -0
- package/src/json/NodeUtils.ts +72 -0
- package/src/json/std-builtins-copy.json +369 -0
- package/src/runners/RunCheckFolder.ts +36 -0
- package/src/runners/RunCheckFolderWithLanguage.ts +44 -0
- package/src/runners/RunCheckOneFile.ts +16 -0
- package/src/runners/RunCheckOneFileWithLanguage.ts +28 -0
- package/src/runners/RunLioncoreDiff.ts +23 -0
- package/src/runners/Utils.ts +21 -0
- package/src/validators/LionWebLanguageReferenceValidator.ts +135 -0
- package/src/validators/LionWebLanguageValidator.ts +40 -0
- package/src/validators/LionWebReferenceValidator.ts +213 -0
- package/src/validators/LionWebSyntaxValidator.ts +297 -0
- package/src/validators/LionWebValidator.ts +76 -0
- package/src/validators/SimpleFieldValidator.ts +90 -0
- package/src/validators/ValidationResult.ts +18 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
{
|
|
2
|
+
"serializationFormatVersion": "2023.1",
|
|
3
|
+
"languages": [
|
|
4
|
+
{
|
|
5
|
+
"key": "LionCore-M3",
|
|
6
|
+
"version": "1"
|
|
7
|
+
}
|
|
8
|
+
],
|
|
9
|
+
"nodes": [
|
|
10
|
+
{
|
|
11
|
+
"id": "LionCore-builtins",
|
|
12
|
+
"classifier": {
|
|
13
|
+
"language": "LionCore-M3",
|
|
14
|
+
"version": "1",
|
|
15
|
+
"key": "Language"
|
|
16
|
+
},
|
|
17
|
+
"properties": [
|
|
18
|
+
{
|
|
19
|
+
"property": {
|
|
20
|
+
"language": "LionCore-builtins",
|
|
21
|
+
"version": "1",
|
|
22
|
+
"key": "LionCore-builtins-INamed-name"
|
|
23
|
+
},
|
|
24
|
+
"value": "LionCore.builtins"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"property": {
|
|
28
|
+
"language": "LionCore-M3",
|
|
29
|
+
"version": "1",
|
|
30
|
+
"key": "Language-version"
|
|
31
|
+
},
|
|
32
|
+
"value": "1"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"property": {
|
|
36
|
+
"language": "LionCore-M3",
|
|
37
|
+
"version": "1",
|
|
38
|
+
"key": "IKeyed-key"
|
|
39
|
+
},
|
|
40
|
+
"value": "LionCore-builtins"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"children": [
|
|
44
|
+
{
|
|
45
|
+
"containment": {
|
|
46
|
+
"language": "LionCore-M3",
|
|
47
|
+
"version": "1",
|
|
48
|
+
"key": "Language-entities"
|
|
49
|
+
},
|
|
50
|
+
"children": [
|
|
51
|
+
"LionCore-builtins-String",
|
|
52
|
+
"LionCore-builtins-Boolean",
|
|
53
|
+
"LionCore-builtins-Integer",
|
|
54
|
+
"LionCore-builtins-JSON",
|
|
55
|
+
"LionCore-builtins-Node",
|
|
56
|
+
"LionCore-builtins-INamed"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"references": [
|
|
61
|
+
{
|
|
62
|
+
"reference": {
|
|
63
|
+
"language": "LionCore-M3",
|
|
64
|
+
"version": "1",
|
|
65
|
+
"key": "Language-dependsOn"
|
|
66
|
+
},
|
|
67
|
+
"targets": []
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
"annotations": [],
|
|
71
|
+
"parent": null
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"id": "LionCore-builtins-String",
|
|
75
|
+
"classifier": {
|
|
76
|
+
"language": "LionCore-M3",
|
|
77
|
+
"version": "1",
|
|
78
|
+
"key": "PrimitiveType"
|
|
79
|
+
},
|
|
80
|
+
"properties": [
|
|
81
|
+
{
|
|
82
|
+
"property": {
|
|
83
|
+
"language": "LionCore-builtins",
|
|
84
|
+
"version": "1",
|
|
85
|
+
"key": "LionCore-builtins-INamed-name"
|
|
86
|
+
},
|
|
87
|
+
"value": "String"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"property": {
|
|
91
|
+
"language": "LionCore-M3",
|
|
92
|
+
"version": "1",
|
|
93
|
+
"key": "IKeyed-key"
|
|
94
|
+
},
|
|
95
|
+
"value": "LionCore-builtins-String"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"children": [],
|
|
99
|
+
"references": [],
|
|
100
|
+
"annotations": [],
|
|
101
|
+
"parent": "LionCore-builtins"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "LionCore-builtins-Boolean",
|
|
105
|
+
"classifier": {
|
|
106
|
+
"language": "LionCore-M3",
|
|
107
|
+
"version": "1",
|
|
108
|
+
"key": "PrimitiveType"
|
|
109
|
+
},
|
|
110
|
+
"properties": [
|
|
111
|
+
{
|
|
112
|
+
"property": {
|
|
113
|
+
"language": "LionCore-builtins",
|
|
114
|
+
"version": "1",
|
|
115
|
+
"key": "LionCore-builtins-INamed-name"
|
|
116
|
+
},
|
|
117
|
+
"value": "Boolean"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"property": {
|
|
121
|
+
"language": "LionCore-M3",
|
|
122
|
+
"version": "1",
|
|
123
|
+
"key": "IKeyed-key"
|
|
124
|
+
},
|
|
125
|
+
"value": "LionCore-builtins-Boolean"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"children": [],
|
|
129
|
+
"references": [],
|
|
130
|
+
"annotations": [],
|
|
131
|
+
"parent": "LionCore-builtins"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"id": "LionCore-builtins-Integer",
|
|
135
|
+
"classifier": {
|
|
136
|
+
"language": "LionCore-M3",
|
|
137
|
+
"version": "1",
|
|
138
|
+
"key": "PrimitiveType"
|
|
139
|
+
},
|
|
140
|
+
"properties": [
|
|
141
|
+
{
|
|
142
|
+
"property": {
|
|
143
|
+
"language": "LionCore-builtins",
|
|
144
|
+
"version": "1",
|
|
145
|
+
"key": "LionCore-builtins-INamed-name"
|
|
146
|
+
},
|
|
147
|
+
"value": "Integer"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"property": {
|
|
151
|
+
"language": "LionCore-M3",
|
|
152
|
+
"version": "1",
|
|
153
|
+
"key": "IKeyed-key"
|
|
154
|
+
},
|
|
155
|
+
"value": "LionCore-builtins-Integer"
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"children": [],
|
|
159
|
+
"references": [],
|
|
160
|
+
"annotations": [],
|
|
161
|
+
"parent": "LionCore-builtins"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"id": "LionCore-builtins-JSON",
|
|
165
|
+
"classifier": {
|
|
166
|
+
"language": "LionCore-M3",
|
|
167
|
+
"version": "1",
|
|
168
|
+
"key": "PrimitiveType"
|
|
169
|
+
},
|
|
170
|
+
"properties": [
|
|
171
|
+
{
|
|
172
|
+
"property": {
|
|
173
|
+
"language": "LionCore-builtins",
|
|
174
|
+
"version": "1",
|
|
175
|
+
"key": "LionCore-builtins-INamed-name"
|
|
176
|
+
},
|
|
177
|
+
"value": "JSON"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"property": {
|
|
181
|
+
"language": "LionCore-M3",
|
|
182
|
+
"version": "1",
|
|
183
|
+
"key": "IKeyed-key"
|
|
184
|
+
},
|
|
185
|
+
"value": "LionCore-builtins-JSON"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"children": [],
|
|
189
|
+
"references": [],
|
|
190
|
+
"annotations": [],
|
|
191
|
+
"parent": "LionCore-builtins"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"id": "LionCore-builtins-Node",
|
|
195
|
+
"classifier": {
|
|
196
|
+
"language": "LionCore-M3",
|
|
197
|
+
"version": "1",
|
|
198
|
+
"key": "Concept"
|
|
199
|
+
},
|
|
200
|
+
"properties": [
|
|
201
|
+
{
|
|
202
|
+
"property": {
|
|
203
|
+
"language": "LionCore-M3",
|
|
204
|
+
"version": "1",
|
|
205
|
+
"key": "Concept-abstract"
|
|
206
|
+
},
|
|
207
|
+
"value": "true"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"property": {
|
|
211
|
+
"language": "LionCore-M3",
|
|
212
|
+
"version": "1",
|
|
213
|
+
"key": "Concept-partition"
|
|
214
|
+
},
|
|
215
|
+
"value": "false"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"property": {
|
|
219
|
+
"language": "LionCore-builtins",
|
|
220
|
+
"version": "1",
|
|
221
|
+
"key": "LionCore-builtins-INamed-name"
|
|
222
|
+
},
|
|
223
|
+
"value": "Node"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"property": {
|
|
227
|
+
"language": "LionCore-M3",
|
|
228
|
+
"version": "1",
|
|
229
|
+
"key": "IKeyed-key"
|
|
230
|
+
},
|
|
231
|
+
"value": "LionCore-builtins-Node"
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
"children": [
|
|
235
|
+
{
|
|
236
|
+
"containment": {
|
|
237
|
+
"language": "LionCore-M3",
|
|
238
|
+
"version": "1",
|
|
239
|
+
"key": "Classifier-features"
|
|
240
|
+
},
|
|
241
|
+
"children": []
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
"references": [
|
|
245
|
+
{
|
|
246
|
+
"reference": {
|
|
247
|
+
"language": "LionCore-M3",
|
|
248
|
+
"version": "1",
|
|
249
|
+
"key": "Concept-extends"
|
|
250
|
+
},
|
|
251
|
+
"targets": []
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"reference": {
|
|
255
|
+
"language": "LionCore-M3",
|
|
256
|
+
"version": "1",
|
|
257
|
+
"key": "Concept-implements"
|
|
258
|
+
},
|
|
259
|
+
"targets": []
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
"annotations": [],
|
|
263
|
+
"parent": "LionCore-builtins"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
"id": "LionCore-builtins-INamed",
|
|
267
|
+
"classifier": {
|
|
268
|
+
"language": "LionCore-M3",
|
|
269
|
+
"version": "1",
|
|
270
|
+
"key": "ConceptInterface"
|
|
271
|
+
},
|
|
272
|
+
"properties": [
|
|
273
|
+
{
|
|
274
|
+
"property": {
|
|
275
|
+
"language": "LionCore-builtins",
|
|
276
|
+
"version": "1",
|
|
277
|
+
"key": "LionCore-builtins-INamed-name"
|
|
278
|
+
},
|
|
279
|
+
"value": "INamed"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"property": {
|
|
283
|
+
"language": "LionCore-M3",
|
|
284
|
+
"version": "1",
|
|
285
|
+
"key": "IKeyed-key"
|
|
286
|
+
},
|
|
287
|
+
"value": "LionCore-builtins-INamed"
|
|
288
|
+
}
|
|
289
|
+
],
|
|
290
|
+
"children": [
|
|
291
|
+
{
|
|
292
|
+
"containment": {
|
|
293
|
+
"language": "LionCore-M3",
|
|
294
|
+
"version": "1",
|
|
295
|
+
"key": "Classifier-features"
|
|
296
|
+
},
|
|
297
|
+
"children": [
|
|
298
|
+
"LionCore-builtins-INamed-name"
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
],
|
|
302
|
+
"references": [
|
|
303
|
+
{
|
|
304
|
+
"reference": {
|
|
305
|
+
"language": "LionCore-M3",
|
|
306
|
+
"version": "1",
|
|
307
|
+
"key": "ConceptInterface-extends"
|
|
308
|
+
},
|
|
309
|
+
"targets": []
|
|
310
|
+
}
|
|
311
|
+
],
|
|
312
|
+
"annotations": [],
|
|
313
|
+
"parent": "LionCore-builtins"
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"id": "LionCore-builtins-INamed-name",
|
|
317
|
+
"classifier": {
|
|
318
|
+
"language": "LionCore-M3",
|
|
319
|
+
"version": "1",
|
|
320
|
+
"key": "Property"
|
|
321
|
+
},
|
|
322
|
+
"properties": [
|
|
323
|
+
{
|
|
324
|
+
"property": {
|
|
325
|
+
"language": "LionCore-M3",
|
|
326
|
+
"version": "1",
|
|
327
|
+
"key": "Feature-optional"
|
|
328
|
+
},
|
|
329
|
+
"value": "false"
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
"property": {
|
|
333
|
+
"language": "LionCore-builtins",
|
|
334
|
+
"version": "1",
|
|
335
|
+
"key": "LionCore-builtins-INamed-name"
|
|
336
|
+
},
|
|
337
|
+
"value": "name"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"property": {
|
|
341
|
+
"language": "LionCore-M3",
|
|
342
|
+
"version": "1",
|
|
343
|
+
"key": "IKeyed-key"
|
|
344
|
+
},
|
|
345
|
+
"value": "LionCore-builtins-INamed-name"
|
|
346
|
+
}
|
|
347
|
+
],
|
|
348
|
+
"children": [],
|
|
349
|
+
"references": [
|
|
350
|
+
{
|
|
351
|
+
"reference": {
|
|
352
|
+
"language": "LionCore-M3",
|
|
353
|
+
"version": "1",
|
|
354
|
+
"key": "Property-type"
|
|
355
|
+
},
|
|
356
|
+
"targets": [
|
|
357
|
+
{
|
|
358
|
+
"resolveInfo": "String",
|
|
359
|
+
"reference": "LionCore-builtins-String"
|
|
360
|
+
}
|
|
361
|
+
]
|
|
362
|
+
}
|
|
363
|
+
],
|
|
364
|
+
"annotations": [],
|
|
365
|
+
"parent": "LionCore-builtins-INamed"
|
|
366
|
+
}
|
|
367
|
+
],
|
|
368
|
+
"annotations": []
|
|
369
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { LionWebValidator } from "../validators/LionWebValidator";
|
|
3
|
+
import { getAllFiles, printIssues } from "./Utils";
|
|
4
|
+
|
|
5
|
+
const folder = process.argv[2];
|
|
6
|
+
let totalErrors = 0;
|
|
7
|
+
let totalSucceed = 0;
|
|
8
|
+
let totalFailed = 0;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
for (const f of getAllFiles(folder, [])) {
|
|
12
|
+
const jsonString1 = fs.readFileSync(f, "utf-8");
|
|
13
|
+
const json1 = JSON.parse(jsonString1);
|
|
14
|
+
const validator = new LionWebValidator(json1, null)
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
validator.validateAll();
|
|
18
|
+
|
|
19
|
+
if (!validator.validationResult.hasErrors()) {
|
|
20
|
+
totalSucceed += 1;
|
|
21
|
+
console.log("V PASSED " + f) ;
|
|
22
|
+
printIssues(validator.validationResult, f)
|
|
23
|
+
} else {
|
|
24
|
+
printIssues(validator.validationResult, f)
|
|
25
|
+
totalFailed += 1;
|
|
26
|
+
totalErrors += validator.validationResult.issues.length;
|
|
27
|
+
}
|
|
28
|
+
} catch(e: unknown) {
|
|
29
|
+
console.log("EXCEPTION in file: " + f);
|
|
30
|
+
console.log("EXCEPTION " + (e as Error)?.stack);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
console.log("Total without errors: " + totalSucceed);
|
|
35
|
+
console.log("Total with errors: " + totalFailed);
|
|
36
|
+
console.log("Total number of errors: " + totalErrors);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper";
|
|
3
|
+
import { LionWebLanguageDefinition} from "../json/LionWebLanguageDefinition";
|
|
4
|
+
import { LionWebValidator } from "../validators/LionWebValidator";
|
|
5
|
+
import { getAllFiles, printIssues } from "./Utils";
|
|
6
|
+
|
|
7
|
+
const folder = process.argv[2];
|
|
8
|
+
const language = process.argv[3];
|
|
9
|
+
|
|
10
|
+
let totalSucceed = 0;
|
|
11
|
+
let totalFailed = 0;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const languageString = fs.readFileSync(language, "utf-8");
|
|
15
|
+
const languageJson = JSON.parse(languageString);
|
|
16
|
+
const languageValidator = new LionWebValidator(languageJson, null);
|
|
17
|
+
|
|
18
|
+
languageValidator.validateSyntax();
|
|
19
|
+
languageValidator.validateReferences();
|
|
20
|
+
if (languageValidator.validationResult.hasErrors()) {
|
|
21
|
+
console.log("===== Language errors, ignoring folder ======");
|
|
22
|
+
printIssues(languageValidator.validationResult);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (const modelFile of getAllFiles(folder, [])) {
|
|
27
|
+
const jsonString1 = fs.readFileSync(modelFile, "utf-8");
|
|
28
|
+
const jsonModel = JSON.parse(jsonString1);
|
|
29
|
+
const modelValidator = new LionWebValidator(jsonModel, new LionWebLanguageDefinition(languageValidator.chunk as LionWebJsonChunkWrapper));
|
|
30
|
+
|
|
31
|
+
modelValidator.validateAll();
|
|
32
|
+
if (modelValidator.validationResult.hasErrors()) {
|
|
33
|
+
totalFailed++;
|
|
34
|
+
// console.log("FAILED: " + modelFile)
|
|
35
|
+
printIssues(modelValidator.validationResult, modelFile);
|
|
36
|
+
} else {
|
|
37
|
+
console.log("SUCCEEDED: " + modelFile);
|
|
38
|
+
totalSucceed++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log("Total without errors: " + totalSucceed);
|
|
43
|
+
console.log("Total with errors: " + totalFailed);
|
|
44
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { LionWebValidator } from "../validators/LionWebValidator";
|
|
3
|
+
import { printIssues } from "./Utils";
|
|
4
|
+
|
|
5
|
+
const file1 = process.argv[2];
|
|
6
|
+
|
|
7
|
+
if (file1 !== null) {
|
|
8
|
+
const jsonString1 = fs.readFileSync(file1, "utf-8");
|
|
9
|
+
const json1 = JSON.parse(jsonString1);
|
|
10
|
+
const validator = new LionWebValidator(json1, null);
|
|
11
|
+
|
|
12
|
+
validator.validateSyntax();
|
|
13
|
+
validator.validateReferences();
|
|
14
|
+
validator.validateForLanguage();
|
|
15
|
+
printIssues(validator.validationResult);
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper";
|
|
3
|
+
import { LionWebLanguageDefinition} from "../json/LionWebLanguageDefinition";
|
|
4
|
+
import { LionWebValidator } from "../validators/LionWebValidator";
|
|
5
|
+
import { printIssues } from "./Utils";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const modelFile = process.argv[2];
|
|
9
|
+
const language = process.argv[3];
|
|
10
|
+
|
|
11
|
+
if (modelFile !== null) {
|
|
12
|
+
const jsonString1 = fs.readFileSync(modelFile, "utf-8");
|
|
13
|
+
const jsonModel = JSON.parse(jsonString1);
|
|
14
|
+
const languageString = fs.readFileSync(language, "utf-8");
|
|
15
|
+
const languageJson = JSON.parse(languageString);
|
|
16
|
+
|
|
17
|
+
const languageValidator = new LionWebValidator(languageJson, null);
|
|
18
|
+
|
|
19
|
+
languageValidator.validateSyntax();
|
|
20
|
+
languageValidator.validateReferences();
|
|
21
|
+
console.log("===== Language errors ======")
|
|
22
|
+
printIssues(languageValidator.validationResult);
|
|
23
|
+
|
|
24
|
+
const modelValidator = new LionWebValidator(jsonModel, new LionWebLanguageDefinition(languageValidator.chunk as LionWebJsonChunkWrapper));
|
|
25
|
+
modelValidator.validateAll();
|
|
26
|
+
console.log("===== Model errors ======")
|
|
27
|
+
printIssues(modelValidator.validationResult);
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { LwDiff } from "../diff/LionwebDiff";
|
|
3
|
+
import { LionWebJsonChunk } from "../json/LionWebJson";
|
|
4
|
+
|
|
5
|
+
const file1 = process.argv[2];
|
|
6
|
+
const file2 = process.argv[3];
|
|
7
|
+
|
|
8
|
+
if (file1 !== null && file1 !== undefined) {
|
|
9
|
+
const jsonString1 = fs.readFileSync(file1, "utf-8");
|
|
10
|
+
const json1 = JSON.parse(jsonString1);
|
|
11
|
+
const jsonString2 = fs.readFileSync(file2, "utf-8");
|
|
12
|
+
const json2 = JSON.parse(jsonString2);
|
|
13
|
+
|
|
14
|
+
const lwDiff = new LwDiff();
|
|
15
|
+
lwDiff.diffLwChunk(json1 as LionWebJsonChunk, json2 as LionWebJsonChunk);
|
|
16
|
+
if (lwDiff.errors.length === 0) {
|
|
17
|
+
console.log("LwDiff: equal");
|
|
18
|
+
} else {
|
|
19
|
+
console.log("LwDiff: " + lwDiff.errors);
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
console.log("Error in arguments");
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { ValidationResult } from "../validators/ValidationResult";
|
|
4
|
+
|
|
5
|
+
export function getAllFiles(dirPath: string, arrayOfFiles: string[]) {
|
|
6
|
+
const files = fs.readdirSync(dirPath);
|
|
7
|
+
arrayOfFiles = arrayOfFiles || [];
|
|
8
|
+
|
|
9
|
+
files.forEach(function (file: string) {
|
|
10
|
+
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
|
|
11
|
+
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
|
|
12
|
+
} else {
|
|
13
|
+
arrayOfFiles.push(path.join(dirPath, "/", file));
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return arrayOfFiles;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function printIssues(result: ValidationResult, file?: string): void {
|
|
20
|
+
result.issues.forEach(issue => console.log((file == undefined ? "" : `File ${file}: `) + issue.errorMsg()));
|
|
21
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Language_IncorrectContainmentMetaPointer_Issue,
|
|
3
|
+
Language_IncorrectPropertyMetaPointer_Issue, Language_IncorrectReferenceMetaPointer_Issue,
|
|
4
|
+
Language_UnknownConcept_Issue,
|
|
5
|
+
Language_UnknownContainment_Issue,
|
|
6
|
+
Language_UnknownProperty_Issue,
|
|
7
|
+
Language_UnknownReference_Issue
|
|
8
|
+
} from "../issues/LanguageIssues";
|
|
9
|
+
import { JsonContext } from "../issues/ValidationIssue";
|
|
10
|
+
import {
|
|
11
|
+
LION_CORE_BUILTINS_INAMED_NAME,
|
|
12
|
+
LIONWEB_BOOLEAN_TYPE,
|
|
13
|
+
LIONWEB_INTEGER_TYPE,
|
|
14
|
+
LIONWEB_JSON_TYPE,
|
|
15
|
+
LIONWEB_STRING_TYPE, LionWebJsonChild,
|
|
16
|
+
LionWebJsonProperty, LionWebJsonReference
|
|
17
|
+
} from "../json/LionWebJson";
|
|
18
|
+
import { LionWebJsonChunkWrapper } from "../json/LionWebJsonChunkWrapper";
|
|
19
|
+
import { LIONWEB_M3_CONCEPT_KEY, LIONWEB_M3_PROPERTY_KEY, LIONWEB_M3_PROPERTY_TYPE_KEY, LionWebLanguageDefinition } from "../json/LionWebLanguageDefinition";
|
|
20
|
+
import { SimpleFieldValidator } from "./SimpleFieldValidator";
|
|
21
|
+
import { ValidationResult } from "./ValidationResult";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Check against the language definition
|
|
25
|
+
*/
|
|
26
|
+
export class LionWebLanguageReferenceValidator {
|
|
27
|
+
validationResult: ValidationResult;
|
|
28
|
+
language: LionWebLanguageDefinition;
|
|
29
|
+
simpleFieldValidator: SimpleFieldValidator;
|
|
30
|
+
|
|
31
|
+
constructor(validationResult: ValidationResult, lang: LionWebLanguageDefinition) {
|
|
32
|
+
this.validationResult = validationResult;
|
|
33
|
+
this.language = lang;
|
|
34
|
+
this.simpleFieldValidator = new SimpleFieldValidator(this.validationResult);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// reset() {
|
|
38
|
+
// this.validationResult.reset();
|
|
39
|
+
// }
|
|
40
|
+
|
|
41
|
+
// TODO test reference and children implementation
|
|
42
|
+
validate(obj: LionWebJsonChunkWrapper): void {
|
|
43
|
+
if (this.language === undefined || this.language === null) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
obj.jsonChunk.nodes.forEach((node, nodeIndex) => {
|
|
47
|
+
const nodeContext = new JsonContext(null, ["node", nodeIndex]);
|
|
48
|
+
const jsonConcept = this.language.getNodeByMetaPointer(node.classifier);
|
|
49
|
+
if (jsonConcept === null || jsonConcept === undefined) {
|
|
50
|
+
this.validationResult.issue(new Language_UnknownConcept_Issue(nodeContext, node.classifier));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
node.properties.forEach((property, propIndex) => {
|
|
54
|
+
this.validateProperty(property, nodeContext.concat("properties", propIndex));
|
|
55
|
+
});
|
|
56
|
+
node.containments.forEach((containment, childIndex) => {
|
|
57
|
+
this.validateContainment(containment, nodeContext.concat("containments", childIndex));
|
|
58
|
+
});
|
|
59
|
+
node.references.forEach((reference, refIndex) => {
|
|
60
|
+
this.validateReference(reference, nodeContext.concat("references", refIndex));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private validateContainment(child: LionWebJsonChild, context: JsonContext) {
|
|
66
|
+
const type = this.language.getNodeByMetaPointer(child.containment);
|
|
67
|
+
if (type === null || type === undefined) {
|
|
68
|
+
this.validationResult.issue(new Language_UnknownContainment_Issue(context, child.containment));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (type.classifier.key !== LIONWEB_M3_CONCEPT_KEY) {
|
|
72
|
+
this.validationResult.issue(new Language_IncorrectContainmentMetaPointer_Issue(context, child.containment, type.classifier.key));
|
|
73
|
+
}
|
|
74
|
+
// TODO check type of children
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private validateReference(ref: LionWebJsonReference, context: JsonContext) {
|
|
78
|
+
const type = this.language.getNodeByMetaPointer(ref.reference);
|
|
79
|
+
if (type === null || type === undefined) {
|
|
80
|
+
this.validationResult.issue(new Language_UnknownReference_Issue(context, ref.reference));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (type.classifier.key !== LIONWEB_M3_CONCEPT_KEY) {
|
|
84
|
+
this.validationResult.issue(new Language_IncorrectReferenceMetaPointer_Issue(context, ref.reference, type.classifier.key));
|
|
85
|
+
}
|
|
86
|
+
// TODO Check type of reference (if possible)
|
|
87
|
+
|
|
88
|
+
// TODO Check for duplicate targets?
|
|
89
|
+
// If so, what to check because there can be either or both a `resolveInfo` and a `reference`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Checks wwhether the value of `prop1` is correct in relation with its property definition in the referred language.
|
|
94
|
+
* @param prop
|
|
95
|
+
*/
|
|
96
|
+
validateProperty(prop: LionWebJsonProperty, context: JsonContext): void {
|
|
97
|
+
if (prop.value === null) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const type = this.language.getNodeByMetaPointer(prop.property);
|
|
101
|
+
if (type === null || type === undefined) {
|
|
102
|
+
this.validationResult.issue(new Language_UnknownProperty_Issue(context, prop.property));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (type.classifier.key !== LIONWEB_M3_PROPERTY_KEY) {
|
|
106
|
+
this.validationResult.issue(new Language_IncorrectPropertyMetaPointer_Issue(context, prop.property, type.classifier.key));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// TODO check for property to exist inside the concept in the language
|
|
110
|
+
// Need to find inherited and implemented properties as well: complex!
|
|
111
|
+
|
|
112
|
+
const refType = type.references.find((ref) => (ref.reference.key === LIONWEB_M3_PROPERTY_TYPE_KEY));
|
|
113
|
+
const propertyName = type.properties.find(p => p.property.key === LION_CORE_BUILTINS_INAMED_NAME)?.value;
|
|
114
|
+
// console.log("Fount type should be " + refType.targets[0].reference);
|
|
115
|
+
if (propertyName !== undefined) {
|
|
116
|
+
if (refType !== null && refType !== undefined) {
|
|
117
|
+
switch (refType.targets[0].reference) {
|
|
118
|
+
case LIONWEB_BOOLEAN_TYPE:
|
|
119
|
+
this.simpleFieldValidator.validateBoolean(prop, propertyName, context);
|
|
120
|
+
break;
|
|
121
|
+
case LIONWEB_INTEGER_TYPE:
|
|
122
|
+
this.simpleFieldValidator.validateInteger(prop, propertyName, context);
|
|
123
|
+
break;
|
|
124
|
+
case LIONWEB_STRING_TYPE:
|
|
125
|
+
break;
|
|
126
|
+
case LIONWEB_JSON_TYPE:
|
|
127
|
+
this.simpleFieldValidator.validateJSON(prop, propertyName, context);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
// TODO refType not found, but
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|