@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.
- package/CHANGELOG.md +7 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/issues/LanguageIssues.d.ts +99 -0
- package/dist/issues/LanguageIssues.d.ts.map +1 -0
- package/dist/issues/LanguageIssues.js +146 -0
- package/dist/issues/LanguageIssues.js.map +1 -0
- package/dist/issues/ReferenceIssues.d.ts +43 -0
- package/dist/issues/ReferenceIssues.d.ts.map +1 -0
- package/dist/issues/ReferenceIssues.js +53 -0
- package/dist/issues/ReferenceIssues.js.map +1 -0
- package/dist/issues/SyntaxIssues.d.ts +53 -0
- package/dist/issues/SyntaxIssues.d.ts.map +1 -0
- package/dist/issues/SyntaxIssues.js +81 -0
- package/dist/issues/SyntaxIssues.js.map +1 -0
- package/dist/issues/ValidationIssue.d.ts +15 -0
- package/dist/issues/ValidationIssue.d.ts.map +1 -0
- package/dist/issues/ValidationIssue.js +17 -0
- package/dist/issues/ValidationIssue.js.map +1 -0
- package/dist/issues/index.d.ts +5 -0
- package/dist/issues/index.d.ts.map +1 -0
- package/dist/issues/index.js +5 -0
- package/dist/issues/index.js.map +1 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.d.ts +24 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.d.ts.map +1 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.js +56 -0
- package/dist/languages/CompositeLionWebLanguageWrapper.js.map +1 -0
- package/dist/languages/LanguageRegistry.d.ts +19 -0
- package/dist/languages/LanguageRegistry.d.ts.map +1 -0
- package/dist/languages/LanguageRegistry.js +37 -0
- package/dist/languages/LanguageRegistry.js.map +1 -0
- package/dist/languages/LanguageUtils.d.ts +35 -0
- package/dist/languages/LanguageUtils.d.ts.map +1 -0
- package/dist/languages/LanguageUtils.js +54 -0
- package/dist/languages/LanguageUtils.js.map +1 -0
- package/dist/languages/LionWebLanguageWrapper.d.ts +31 -0
- package/dist/languages/LionWebLanguageWrapper.d.ts.map +1 -0
- package/dist/languages/LionWebLanguageWrapper.js +69 -0
- package/dist/languages/LionWebLanguageWrapper.js.map +1 -0
- package/dist/languages/MetaPointerMap.d.ts +11 -0
- package/dist/languages/MetaPointerMap.d.ts.map +1 -0
- package/dist/languages/MetaPointerMap.js +39 -0
- package/dist/languages/MetaPointerMap.js.map +1 -0
- package/dist/languages/index.d.ts +3 -0
- package/dist/languages/index.d.ts.map +1 -0
- package/dist/languages/index.js +3 -0
- package/dist/languages/index.js.map +1 -0
- package/dist/runners/FileUtils.d.ts +6 -0
- package/dist/runners/FileUtils.d.ts.map +1 -0
- package/dist/runners/FileUtils.js +53 -0
- package/dist/runners/FileUtils.js.map +1 -0
- package/dist/runners/RunCheckFolder.d.ts +2 -0
- package/dist/runners/RunCheckFolder.d.ts.map +1 -0
- package/dist/runners/RunCheckFolder.js +6 -0
- package/dist/runners/RunCheckFolder.js.map +1 -0
- package/dist/runners/RunCheckFolderWithLanguage.d.ts +2 -0
- package/dist/runners/RunCheckFolderWithLanguage.d.ts.map +1 -0
- package/dist/runners/RunCheckFolderWithLanguage.js +40 -0
- package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -0
- package/dist/runners/RunCheckOneFile.d.ts +2 -0
- package/dist/runners/RunCheckOneFile.d.ts.map +1 -0
- package/dist/runners/RunCheckOneFile.js +6 -0
- package/dist/runners/RunCheckOneFile.js.map +1 -0
- package/dist/runners/RunCheckOneFileWithLanguage.d.ts +2 -0
- package/dist/runners/RunCheckOneFileWithLanguage.d.ts.map +1 -0
- package/dist/runners/RunCheckOneFileWithLanguage.js +31 -0
- package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -0
- package/dist/runners/RunLioncoreDiff.d.ts +2 -0
- package/dist/runners/RunLioncoreDiff.d.ts.map +1 -0
- package/dist/runners/RunLioncoreDiff.js +22 -0
- package/dist/runners/RunLioncoreDiff.js.map +1 -0
- package/dist/runners/Utils.d.ts +7 -0
- package/dist/runners/Utils.d.ts.map +1 -0
- package/dist/runners/Utils.js +48 -0
- package/dist/runners/Utils.js.map +1 -0
- package/dist/runners/index.d.ts +3 -0
- package/dist/runners/index.d.ts.map +1 -0
- package/dist/runners/index.js +3 -0
- package/dist/runners/index.js.map +1 -0
- package/dist/validators/LionWebChunkDefinitions.d.ts +9 -0
- package/dist/validators/LionWebChunkDefinitions.d.ts.map +1 -0
- package/{src/validators/LionWebChunkDefinitions.ts → dist/validators/LionWebChunkDefinitions.js} +10 -14
- package/dist/validators/LionWebChunkDefinitions.js.map +1 -0
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts +21 -0
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -0
- package/{src/validators/LionWebLanguageReferenceValidator.ts → dist/validators/LionWebLanguageReferenceValidator.js} +73 -108
- package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -0
- package/dist/validators/LionWebLanguageValidator.d.ts +23 -0
- package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -0
- package/dist/validators/LionWebLanguageValidator.js +66 -0
- package/dist/validators/LionWebLanguageValidator.js.map +1 -0
- package/dist/validators/LionWebReferenceValidator.d.ts +43 -0
- package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -0
- package/{src/validators/LionWebReferenceValidator.ts → dist/validators/LionWebReferenceValidator.js} +84 -106
- package/dist/validators/LionWebReferenceValidator.js.map +1 -0
- package/dist/validators/LionWebSyntaxValidator.d.ts +9 -0
- package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -0
- package/dist/validators/LionWebSyntaxValidator.js +11 -0
- package/dist/validators/LionWebSyntaxValidator.js.map +1 -0
- package/dist/validators/LionWebValidator.d.ts +24 -0
- package/dist/validators/LionWebValidator.d.ts.map +1 -0
- package/{src/validators/LionWebValidator.ts → dist/validators/LionWebValidator.js} +29 -45
- package/dist/validators/LionWebValidator.js.map +1 -0
- package/dist/validators/ValidationFunctions.d.ts +60 -0
- package/dist/validators/ValidationFunctions.d.ts.map +1 -0
- package/{src/validators/ValidationFunctions.ts → dist/validators/ValidationFunctions.js} +34 -66
- package/dist/validators/ValidationFunctions.js.map +1 -0
- package/dist/validators/generic/SyntaxValidator.d.ts +37 -0
- package/dist/validators/generic/SyntaxValidator.d.ts.map +1 -0
- package/dist/validators/generic/SyntaxValidator.js +152 -0
- package/dist/validators/generic/SyntaxValidator.js.map +1 -0
- package/dist/validators/generic/ValidationResult.d.ts +8 -0
- package/dist/validators/generic/ValidationResult.d.ts.map +1 -0
- package/dist/validators/generic/ValidationResult.js +15 -0
- package/dist/validators/generic/ValidationResult.js.map +1 -0
- package/dist/validators/generic/index.d.ts +4 -0
- package/dist/validators/generic/index.d.ts.map +1 -0
- package/dist/validators/generic/index.js +4 -0
- package/dist/validators/generic/index.js.map +1 -0
- package/dist/validators/generic/schema/DefinitionSchema.d.ts +23 -0
- package/dist/validators/generic/schema/DefinitionSchema.d.ts.map +1 -0
- package/dist/validators/generic/schema/DefinitionSchema.js +43 -0
- package/dist/validators/generic/schema/DefinitionSchema.js.map +1 -0
- package/dist/validators/generic/schema/ValidationTypes.d.ts +101 -0
- package/dist/validators/generic/schema/ValidationTypes.d.ts.map +1 -0
- package/dist/validators/generic/schema/ValidationTypes.js +43 -0
- 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/dist/validators/index.d.ts +9 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +9 -0
- package/dist/validators/index.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +0 -4
- package/src/issues/LanguageIssues.ts +0 -147
- package/src/issues/ReferenceIssues.ts +0 -83
- package/src/issues/SyntaxIssues.ts +0 -84
- package/src/issues/ValidationIssue.ts +0 -29
- package/src/issues/index.ts +0 -4
- package/src/languages/CompositeLionWebLanguageWrapper.ts +0 -57
- package/src/languages/LanguageRegistry.ts +0 -44
- package/src/languages/LanguageUtils.ts +0 -63
- package/src/languages/LionWebLanguageWrapper.ts +0 -91
- package/src/languages/MetaPointerMap.ts +0 -41
- package/src/languages/index.ts +0 -2
- package/src/runners/FileUtils.ts +0 -59
- package/src/runners/RunCheckFolder.ts +0 -7
- package/src/runners/RunCheckFolderWithLanguage.ts +0 -45
- package/src/runners/RunCheckOneFile.ts +0 -7
- package/src/runners/RunCheckOneFileWithLanguage.ts +0 -35
- package/src/runners/RunLioncoreDiff.ts +0 -23
- package/src/runners/Utils.ts +0 -54
- package/src/runners/index.ts +0 -2
- package/src/validators/LionWebLanguageValidator.ts +0 -78
- package/src/validators/LionWebSyntaxValidator.ts +0 -14
- package/src/validators/generic/SyntaxValidator.ts +0 -216
- package/src/validators/generic/ValidationResult.ts +0 -17
- package/src/validators/generic/index.ts +0 -3
- package/src/validators/generic/schema/DefinitionSchema.ts +0 -52
- package/src/validators/generic/schema/ValidationTypes.ts +0 -134
- package/src/validators/generic/schema/index.ts +0 -2
- package/src/validators/index.ts +0 -8
- package/tsconfig.json +0 -8
- /package/{src → dist}/languages/LionCore-M3.json +0 -0
- /package/{src → dist}/languages/LionCore-builtins.json +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { JsonContext } from "@lionweb/json-utils";
|
|
2
|
+
import { ValidationResult } from "../ValidationResult.js";
|
|
3
|
+
export type UnknownObjectType = {
|
|
4
|
+
[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
|
+
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;
|
|
42
|
+
export declare const MAY_BE_NULL = true;
|
|
43
|
+
/**
|
|
44
|
+
* Definition of a primitive type.
|
|
45
|
+
*/
|
|
46
|
+
export type PrimitiveDefinition = {
|
|
47
|
+
name: string;
|
|
48
|
+
/**
|
|
49
|
+
* The expected type of the property value
|
|
50
|
+
*/
|
|
51
|
+
primitiveType: string;
|
|
52
|
+
/**
|
|
53
|
+
* Additional validation function
|
|
54
|
+
*/
|
|
55
|
+
validate?: ValidatorFunction;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
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.
|
|
88
|
+
* @param propDef
|
|
89
|
+
* @constructor
|
|
90
|
+
*/
|
|
91
|
+
export declare function PrimitiveDef(propDef: PrimitiveDefinition): PrimitiveDefinition;
|
|
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;
|
|
101
|
+
//# sourceMappingURL=ValidationTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationTypes.d.ts","sourceRoot":"","sources":["../../../../src/validators/generic/schema/ValidationTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,MAAM,iBAAiB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAA;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,kBAAkB,KAAK,IAAI,CAAA;AAE1H,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAG;AAG7H,eAAO,MAAM,WAAW,OAAO,CAAA;AAE/B;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,aAAa,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,kBAAkB,EAAE,CAAC;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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
export function emptyValidation(object, result, ctx, pdef) { }
|
|
3
|
+
// Make boolean argument more readable.
|
|
4
|
+
export const MAY_BE_NULL = true;
|
|
5
|
+
/**
|
|
6
|
+
* Easy way to create a PrimitiveDefinition typed object with default values.
|
|
7
|
+
* @param propDef
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
export function PrimitiveDef(propDef) {
|
|
11
|
+
const { name, primitiveType, validate = emptyValidation } = propDef;
|
|
12
|
+
return {
|
|
13
|
+
name: name,
|
|
14
|
+
primitiveType: primitiveType,
|
|
15
|
+
validate: validate
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Easy way to create a PropertyDefinition typed object with default values.
|
|
20
|
+
* @param propDef
|
|
21
|
+
* @constructor
|
|
22
|
+
*/
|
|
23
|
+
export function PropertyDef(propDef) {
|
|
24
|
+
const { name, type, mayBeNull = false, isList = false, isOptional = false, validate = emptyValidation } = propDef;
|
|
25
|
+
return {
|
|
26
|
+
name: name,
|
|
27
|
+
type: type,
|
|
28
|
+
isList: isList,
|
|
29
|
+
mayBeNull: mayBeNull,
|
|
30
|
+
isOptional: isOptional,
|
|
31
|
+
validate: validate
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function isObjectDefinition(def) {
|
|
35
|
+
return (def !== undefined) && Array.isArray(def?.properties);
|
|
36
|
+
}
|
|
37
|
+
export function isPrimitiveDefinition(def) {
|
|
38
|
+
return (def !== undefined) && def?.primitiveType !== undefined;
|
|
39
|
+
}
|
|
40
|
+
export function isJavaScriptPrimitive(type) {
|
|
41
|
+
return ["number", "string", "boolean"].includes(type);
|
|
42
|
+
}
|
|
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,CAAI,MAAS,EAAE,MAAwB,EAAE,GAAgB,EAAE,IAAyB,IAAS,CAAC;AAE7H,uCAAuC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAA;AA+C/B;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAA4B;IACrD,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,OAAO,CAAA;IACnE,OAAO;QACH,IAAI,EAAE,IAAI;QACV,aAAa,EAAE,aAAa;QAC5B,QAAQ,EAAE,QAAQ;KACrB,CAAA;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B;IACnD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,OAAO,CAAA;IACjH,OAAO;QACH,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE,UAAU;QACtB,QAAQ,EAAE,QAAQ;KACrB,CAAA;AACL,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAA2B;IAC1D,OAAQ,CAAC,GAAG,KAAK,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,CAAE,GAAwB,EAAE,UAAU,CAAC,CAAA;AACvF,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,GAA2B;IAC7D,OAAO,CAAC,GAAG,KAAK,SAAS,CAAC,IAAK,GAA2B,EAAE,aAAa,KAAK,SAAS,CAAA;AAC3F,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAC9C,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;AACzD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,wCAAwC,CAAA;AACtD,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,wCAAwC,CAAA;AACtD,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,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.12",
|
|
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.12",
|
|
36
|
+
"@lionweb/ts-utils": "0.7.0-beta.12",
|
|
37
|
+
"@lionweb/json-utils": "0.7.0-beta.12"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/index.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
|
|
2
|
-
import { JsonContext } from "@lionweb/json-utils"
|
|
3
|
-
import { ValidationIssue } from "./ValidationIssue.js"
|
|
4
|
-
|
|
5
|
-
export class Language_PropertyValue_Issue extends ValidationIssue {
|
|
6
|
-
readonly issueType = "PropertyValueIncorrect"
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
context: JsonContext,
|
|
10
|
-
public property: string,
|
|
11
|
-
public value: string | null,
|
|
12
|
-
public expectedType: string
|
|
13
|
-
) {
|
|
14
|
-
super(context)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
msg = (): string => `Property "${this.property}" with value "${this.value}" is not of type "${this.expectedType}"`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Incorrect Meta Pointers
|
|
21
|
-
export abstract class Language_IncorrectMetaPointerType_Issue extends ValidationIssue {
|
|
22
|
-
abstract readonly metaType: string
|
|
23
|
-
|
|
24
|
-
constructor(
|
|
25
|
-
context: JsonContext,
|
|
26
|
-
public metaPointer: LionWebJsonMetaPointer,
|
|
27
|
-
public incorrectType: string
|
|
28
|
-
) {
|
|
29
|
-
super(context)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
msg = (): string =>
|
|
33
|
-
`${this.metaType} with key "${this.metaPointer.key}" does not refer to a "${this.metaType}", but to a "${this.incorrectType}"`
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class Language_IncorrectPropertyMetaPointer_Issue extends Language_IncorrectMetaPointerType_Issue {
|
|
37
|
-
readonly issueType = "IncorrectPropertyMetaPointer"
|
|
38
|
-
readonly metaType = "Property"
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export abstract class Language_FeatureMetaPointerNotInClassifier_Issue extends ValidationIssue {
|
|
42
|
-
abstract readonly metaType: string
|
|
43
|
-
constructor(
|
|
44
|
-
context: JsonContext,
|
|
45
|
-
public featureMetaPointer: LionWebJsonMetaPointer,
|
|
46
|
-
public classifierPointer: LionWebJsonNode
|
|
47
|
-
) {
|
|
48
|
-
super(context)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
msg = (): string =>
|
|
52
|
-
`${this.metaType} with key "${this.featureMetaPointer.key}" is not part of classifier "${this.classifierPointer.id}"`
|
|
53
|
-
}
|
|
54
|
-
export class Language_PropertyMetaPointerNotInClass_Issue extends Language_FeatureMetaPointerNotInClassifier_Issue {
|
|
55
|
-
readonly issueType = "PropertyMetaPointerNotInClass"
|
|
56
|
-
readonly metaType = "Property"
|
|
57
|
-
}
|
|
58
|
-
export class Language_ReferenceMetaPointerNotInClass_Issue extends Language_FeatureMetaPointerNotInClassifier_Issue {
|
|
59
|
-
readonly issueType = "ReferenceMetaPointerNotInClass"
|
|
60
|
-
readonly metaType = "Reference"
|
|
61
|
-
}
|
|
62
|
-
export class Language_ContainmentMetaPointerNotInClass_Issue extends Language_FeatureMetaPointerNotInClassifier_Issue {
|
|
63
|
-
readonly issueType = "ContainmentMetaPointerNotInClass"
|
|
64
|
-
readonly metaType = "Containment"
|
|
65
|
-
}
|
|
66
|
-
export class Language_IncorrectConceptMetaPointer_Issue extends Language_IncorrectMetaPointerType_Issue {
|
|
67
|
-
readonly issueType = "IncorrectConceptMetaPointer"
|
|
68
|
-
readonly metaType = "Concept"
|
|
69
|
-
}
|
|
70
|
-
export class Language_IncorrectReferenceMetaPointer_Issue extends Language_IncorrectMetaPointerType_Issue {
|
|
71
|
-
readonly issueType = "IncorrectReferenceMetaPointer"
|
|
72
|
-
readonly metaType = "Reference"
|
|
73
|
-
}
|
|
74
|
-
export class Language_IncorrectContainmentMetaPointer_Issue extends Language_IncorrectMetaPointerType_Issue {
|
|
75
|
-
readonly issueType = "IncorrectContainmentMetaPointer"
|
|
76
|
-
readonly metaType = "Containment"
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Unknown Meta Pointers
|
|
80
|
-
export abstract class Language_UnknownMetaPointer_Issue extends ValidationIssue {
|
|
81
|
-
abstract readonly metaType: string
|
|
82
|
-
|
|
83
|
-
constructor(
|
|
84
|
-
context: JsonContext,
|
|
85
|
-
public metaPointer: LionWebJsonMetaPointer
|
|
86
|
-
) {
|
|
87
|
-
super(context)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
msg = (): string => `${this.metaType} with key ${this.metaPointer.key} is unknown in the language`
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export class Language_UnknownReference_Issue extends Language_UnknownMetaPointer_Issue {
|
|
94
|
-
readonly issueType = "UnknownReference"
|
|
95
|
-
readonly metaType = "Reference"
|
|
96
|
-
}
|
|
97
|
-
export class Language_UnknownContainment_Issue extends Language_UnknownMetaPointer_Issue {
|
|
98
|
-
readonly issueType = "UnknownContainment"
|
|
99
|
-
readonly metaType = "Containment"
|
|
100
|
-
}
|
|
101
|
-
export class Language_UnknownProperty_Issue extends Language_UnknownMetaPointer_Issue {
|
|
102
|
-
readonly issueType = "UnknownProperty"
|
|
103
|
-
readonly metaType = "Property"
|
|
104
|
-
}
|
|
105
|
-
export class Language_UnknownConcept_Issue extends Language_UnknownMetaPointer_Issue {
|
|
106
|
-
readonly issueType = "UnknownConcept"
|
|
107
|
-
readonly metaType = "Concept"
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Actual Language checks on M2
|
|
111
|
-
export class NumberOfLanguagesUsed_Issue extends ValidationIssue {
|
|
112
|
-
readonly issueType = "NumberOfLanguagesUsed"
|
|
113
|
-
constructor(
|
|
114
|
-
context: JsonContext,
|
|
115
|
-
public nrOfLanguages: number
|
|
116
|
-
) {
|
|
117
|
-
super(context)
|
|
118
|
-
}
|
|
119
|
-
msg = () => `Is not a language: number of used languages should be 1, is ${this.nrOfLanguages}`
|
|
120
|
-
}
|
|
121
|
-
export class MissingM3Language_Issue extends ValidationIssue {
|
|
122
|
-
readonly issueType = "MissingM3Language"
|
|
123
|
-
constructor(context: JsonContext) {
|
|
124
|
-
super(context)
|
|
125
|
-
}
|
|
126
|
-
msg = () => `Missing used language LionCore-M3`
|
|
127
|
-
}
|
|
128
|
-
export class NotLionCoreLanguageKey_Issue extends ValidationIssue {
|
|
129
|
-
readonly issueType = "NotLionCoreLanguageKey"
|
|
130
|
-
constructor(
|
|
131
|
-
context: JsonContext,
|
|
132
|
-
public incorrectKey: string
|
|
133
|
-
) {
|
|
134
|
-
super(context)
|
|
135
|
-
}
|
|
136
|
-
msg = () => `Is not a language: the used language key is not LionCore-M3, but ${this.incorrectKey}`
|
|
137
|
-
}
|
|
138
|
-
export class IncorrectLionCoreVersion_Issue extends ValidationIssue {
|
|
139
|
-
readonly issueType = "IncorrectLionCoreVersion"
|
|
140
|
-
constructor(
|
|
141
|
-
context: JsonContext,
|
|
142
|
-
public incorrectVersion: string
|
|
143
|
-
) {
|
|
144
|
-
super(context)
|
|
145
|
-
}
|
|
146
|
-
msg = () => `Is not a language: the used language version is not 1, but ${this.incorrectVersion}`
|
|
147
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
|
|
2
|
-
import { JsonContext } from "@lionweb/json-utils"
|
|
3
|
-
import { ValidationIssue } from "./ValidationIssue.js"
|
|
4
|
-
|
|
5
|
-
export class Reference_DuplicateNodeId_Issue extends ValidationIssue {
|
|
6
|
-
readonly issueType = "DuplicateNodeId"
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
context: JsonContext,
|
|
10
|
-
public nodeId: LionWebId
|
|
11
|
-
) {
|
|
12
|
-
super(context)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
msg = (): string => `Node has duplicate id "${this.nodeId}"`
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class Reference_ChildMissingInParent_Issue extends ValidationIssue {
|
|
19
|
-
readonly issueType = "ChildMissingInParent"
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
context: JsonContext,
|
|
23
|
-
public child: LionWebJsonNode,
|
|
24
|
-
public parent: LionWebJsonNode
|
|
25
|
-
) {
|
|
26
|
-
super(context)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
msg = (): string => `Node with id "${this.child.id}" has parent with id "${this.parent.id}" but parent does not contains it as a child.`
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class Reference_ParentMissingInChild_Issue extends ValidationIssue {
|
|
33
|
-
readonly issueType = "ParentMissingInChild"
|
|
34
|
-
|
|
35
|
-
constructor(
|
|
36
|
-
context: JsonContext,
|
|
37
|
-
public parent: LionWebJsonNode,
|
|
38
|
-
public child: LionWebJsonNode
|
|
39
|
-
) {
|
|
40
|
-
super(context)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
msg = (): string => `Node with id "${this.parent.id}" has child with id "${this.child.id}" but child has parent ${this.child.parent}.`
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export class Reference_CirculairParent_Issue extends ValidationIssue {
|
|
47
|
-
readonly issueType = "CirculairParent"
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
context: JsonContext,
|
|
51
|
-
public node: LionWebJsonNode | undefined,
|
|
52
|
-
public parentPath: string[]
|
|
53
|
-
) {
|
|
54
|
-
super(context)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
msg = (): string => `Node with id "${this.node?.id}" has circulair parent through "${this.parentPath}".`
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export class Reference_LanguageUnknown_Issue extends ValidationIssue {
|
|
61
|
-
readonly issueType = "LanguageUnknown"
|
|
62
|
-
|
|
63
|
-
constructor(
|
|
64
|
-
context: JsonContext,
|
|
65
|
-
public languageRef: LionWebJsonMetaPointer
|
|
66
|
-
) {
|
|
67
|
-
super(context)
|
|
68
|
-
}
|
|
69
|
-
msg = () =>
|
|
70
|
-
`Node uses language { language = ${this.languageRef.language}, version = ${this.languageRef.version} } which is not declared in used languages`
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export class Duplicates_Issue extends ValidationIssue {
|
|
74
|
-
readonly issueType = "Duplicates"
|
|
75
|
-
|
|
76
|
-
constructor(
|
|
77
|
-
context: JsonContext,
|
|
78
|
-
public nodeId: LionWebId
|
|
79
|
-
) {
|
|
80
|
-
super(context)
|
|
81
|
-
}
|
|
82
|
-
msg = () => `Duplicate value "${this.nodeId}"`
|
|
83
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { JsonContext } from "@lionweb/json-utils"
|
|
2
|
-
import { ValidationIssue } from "./ValidationIssue.js"
|
|
3
|
-
|
|
4
|
-
export abstract class Syntax_PropertyIssue extends ValidationIssue {
|
|
5
|
-
constructor(
|
|
6
|
-
public context: JsonContext,
|
|
7
|
-
protected property: string
|
|
8
|
-
) {
|
|
9
|
-
super(context)
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class Syntax_PropertyMissingIssue extends Syntax_PropertyIssue {
|
|
14
|
-
readonly issueType = "PropertyMissing"
|
|
15
|
-
protected msg = () => `Property "${this.property}" is missing`
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class Syntax_PropertyUnknownIssue extends Syntax_PropertyIssue {
|
|
19
|
-
readonly issueType = "PropertyUnknown"
|
|
20
|
-
protected msg = () => `Property "${this.property}" is not defined as a LionWeb property`
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class Syntax_PropertyNullIssue extends Syntax_PropertyIssue {
|
|
24
|
-
readonly issueType = "PropertyNull"
|
|
25
|
-
protected msg = () => `Property "${this.property}" is null, but it should have a value`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class Syntax_PropertyTypeIssue extends Syntax_PropertyIssue {
|
|
29
|
-
readonly issueType = "PropertyTypeIncorrect"
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
context: JsonContext,
|
|
33
|
-
property: string,
|
|
34
|
-
protected expectedType: string,
|
|
35
|
-
protected actualType: string
|
|
36
|
-
) {
|
|
37
|
-
super(context, property)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
protected msg = () => `Property ${this.property} should have type "${this.expectedType}", but has type "${this.actualType}"`
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export class Syntax_ArrayContainsNull_Issue extends Syntax_PropertyIssue {
|
|
44
|
-
readonly issueType = "ArrayContainsNull"
|
|
45
|
-
|
|
46
|
-
constructor(
|
|
47
|
-
context: JsonContext,
|
|
48
|
-
property: string,
|
|
49
|
-
public index: number
|
|
50
|
-
) {
|
|
51
|
-
super(context, property)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
protected msg = () => `Property "${this.property}" of type array contains null at index "${"" + this.index}" `
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export abstract class Syntax_IncorrectFormat_Issue extends ValidationIssue {
|
|
58
|
-
constructor(
|
|
59
|
-
context: JsonContext,
|
|
60
|
-
public value: string
|
|
61
|
-
) {
|
|
62
|
-
super(context)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export class Syntax_SerializationFormatVersion_Issue extends Syntax_IncorrectFormat_Issue {
|
|
67
|
-
readonly issueType = "SerializationFormatVersion"
|
|
68
|
-
protected msg = () => `SerializationFormatVersion "${this.value}" is not a number`
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export class Syntax_VersionFormat_Issue extends Syntax_IncorrectFormat_Issue {
|
|
72
|
-
readonly issueType = "VersionFormat"
|
|
73
|
-
protected msg = () => `Version "${this.value}" is an empty string.`
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export class Syntax_KeyFormat_Issue extends Syntax_IncorrectFormat_Issue {
|
|
77
|
-
readonly issueType = "KeyFormat"
|
|
78
|
-
protected msg = () => `Key "${this.value}" has incorrect format.`
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export class Syntax_IdFormat_Issue extends Syntax_IncorrectFormat_Issue {
|
|
82
|
-
readonly issueType = "IdFormat"
|
|
83
|
-
protected msg = () => `Id "${this.value}" has incorrect format.`
|
|
84
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { JsonContext } from "@lionweb/json-utils"
|
|
2
|
-
|
|
3
|
-
export abstract class ValidationIssue {
|
|
4
|
-
abstract readonly issueType: string
|
|
5
|
-
context: JsonContext | null
|
|
6
|
-
|
|
7
|
-
constructor(context: JsonContext | null) {
|
|
8
|
-
this.context = context
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
protected abstract msg(): string
|
|
12
|
-
|
|
13
|
-
public errorMsg(): string {
|
|
14
|
-
return `${this.issueType}: ${this.msg()} at ${this.context?.toString()} `
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class GenericIssue extends ValidationIssue {
|
|
19
|
-
readonly issueType = "GenericIssue"
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
context: JsonContext | null,
|
|
23
|
-
public text: string
|
|
24
|
-
) {
|
|
25
|
-
super(context)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected msg = () => this.text
|
|
29
|
-
}
|
package/src/issues/index.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
|
|
2
|
-
import { LionWebLanguageWrapper } from "./LionWebLanguageWrapper.js"
|
|
3
|
-
import { MetaPointerMap } from "./MetaPointerMap.js"
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Collection of language definitions
|
|
7
|
-
*/
|
|
8
|
-
export class CompositeLionWebLanguageWrapper extends LionWebLanguageWrapper {
|
|
9
|
-
metaPointerMap: MetaPointerMap = new MetaPointerMap()
|
|
10
|
-
languageMap = new Map<string, Map<string, LionWebLanguageWrapper>>()
|
|
11
|
-
languages: LionWebLanguageWrapper[] = []
|
|
12
|
-
|
|
13
|
-
addLanguage(lionWebLanguage: LionWebLanguageWrapper) {
|
|
14
|
-
let language = this.languageMap.get(lionWebLanguage.key)
|
|
15
|
-
if (language === undefined) {
|
|
16
|
-
language = new Map<string, LionWebLanguageWrapper>()
|
|
17
|
-
this.languageMap.set(lionWebLanguage.key, language)
|
|
18
|
-
}
|
|
19
|
-
const version = language.get(lionWebLanguage.version)
|
|
20
|
-
if (version === undefined) {
|
|
21
|
-
language.set(lionWebLanguage.version, lionWebLanguage)
|
|
22
|
-
} else {
|
|
23
|
-
// console.error("Language already known")
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
this.languages.push(lionWebLanguage)
|
|
27
|
-
lionWebLanguage.jsonChunk.nodes.forEach(node => {
|
|
28
|
-
this.metaPointerMap.add(lionWebLanguage.key, lionWebLanguage.version, node)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getLanguage(pointer: LionWebJsonMetaPointer): LionWebLanguageWrapper | undefined {
|
|
33
|
-
return this.languageMap.get(pointer.language)?.get(pointer.version)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Gets the node with _metaPointer_ in any of the known languages
|
|
38
|
-
* @param metaPointer
|
|
39
|
-
*/
|
|
40
|
-
getNodeByMetaPointer(metaPointer: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
|
|
41
|
-
return this.metaPointerMap.get(metaPointer)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get node in any of the languages.
|
|
46
|
-
* @param nodeId
|
|
47
|
-
*/
|
|
48
|
-
getNode(nodeId: LionWebId) {
|
|
49
|
-
for (const chunk of this.languages) {
|
|
50
|
-
const node = chunk.getNode(nodeId)
|
|
51
|
-
if (node !== undefined) {
|
|
52
|
-
return node
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined
|
|
56
|
-
}
|
|
57
|
-
}
|