@lionweb/validation 0.7.0-beta.18 → 0.7.0-beta.19
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 +0 -1
- package/package.json +4 -4
- package/src/index.ts +4 -0
- package/src/issues/LanguageIssues.ts +147 -0
- package/src/issues/ReferenceIssues.ts +83 -0
- package/src/issues/SyntaxIssues.ts +84 -0
- package/src/issues/ValidationIssue.ts +29 -0
- package/src/issues/index.ts +4 -0
- package/src/languages/CompositeLionWebLanguageWrapper.ts +57 -0
- package/src/languages/LanguageRegistry.ts +44 -0
- package/src/languages/LanguageUtils.ts +63 -0
- package/src/languages/LionCore-M3.json +2356 -0
- package/src/languages/LionCore-builtins.json +372 -0
- package/src/languages/LionWebLanguageWrapper.ts +91 -0
- package/src/languages/MetaPointerMap.ts +41 -0
- package/src/languages/index.ts +2 -0
- package/src/runners/FileUtils.ts +59 -0
- package/src/runners/RunCheckFolder.ts +7 -0
- package/src/runners/RunCheckFolderWithLanguage.ts +45 -0
- package/src/runners/RunCheckOneFile.ts +7 -0
- package/src/runners/RunCheckOneFileWithLanguage.ts +35 -0
- package/src/runners/RunLioncoreDiff.ts +23 -0
- package/src/runners/Utils.ts +54 -0
- package/src/runners/index.ts +2 -0
- package/src/validators/LionWebChunkDefinitions.ts +104 -0
- package/src/validators/LionWebLanguageReferenceValidator.ts +201 -0
- package/src/validators/LionWebLanguageValidator.ts +79 -0
- package/src/validators/LionWebReferenceValidator.ts +225 -0
- package/src/validators/LionWebSyntaxValidator.ts +14 -0
- package/src/validators/LionWebValidator.ts +71 -0
- package/src/validators/ValidationFunctions.ts +129 -0
- package/src/validators/generic/SyntaxValidator.ts +164 -0
- package/src/validators/generic/ValidationResult.ts +17 -0
- package/src/validators/generic/index.ts +3 -0
- package/src/validators/generic/schema/DefinitionSchema.ts +52 -0
- package/src/validators/generic/schema/ValidationTypes.ts +134 -0
- package/src/validators/generic/schema/index.ts +2 -0
- package/src/validators/index.ts +8 -0
package/CHANGELOG.md
CHANGED
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.19",
|
|
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.19",
|
|
36
|
+
"@lionweb/ts-utils": "0.7.0-beta.19",
|
|
37
|
+
"@lionweb/json-utils": "0.7.0-beta.19"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
|
|
2
|
+
import { CompositeLionWebLanguageWrapper } from "./CompositeLionWebLanguageWrapper.js"
|
|
3
|
+
import { LionWebLanguageWrapper } from "./LionWebLanguageWrapper.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Collection of language definitions
|
|
7
|
+
*/
|
|
8
|
+
export class LanguageRegistry {
|
|
9
|
+
languages: CompositeLionWebLanguageWrapper = new CompositeLionWebLanguageWrapper({nodes: [], languages: [], serializationFormatVersion: "2023.1"})
|
|
10
|
+
|
|
11
|
+
addLanguage(lionWebLanguage: LionWebLanguageWrapper) {
|
|
12
|
+
// console.log("LanguageRegistry.add: " + lionWebLanguage.name + " " + lionWebLanguage.jsonChunk.nodes.length)
|
|
13
|
+
|
|
14
|
+
this.languages.addLanguage(lionWebLanguage)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
clear(): void {
|
|
18
|
+
this.languages = new CompositeLionWebLanguageWrapper({nodes: [], languages: [], serializationFormatVersion: "2023.1"})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getLanguage(pointer: LionWebJsonMetaPointer): LionWebLanguageWrapper | undefined {
|
|
22
|
+
return this.languages.languageMap.get(pointer.language)?.get(pointer.version)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets the node with _metaPointer_ in any of the known languages
|
|
27
|
+
* @param metaPointer
|
|
28
|
+
*/
|
|
29
|
+
getNodeByMetaPointer(metaPointer: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
|
|
30
|
+
return this.languages.getNodeByMetaPointer(metaPointer)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
findNode(nodeId: LionWebId) {
|
|
34
|
+
for (const chunk of this.languages.languages) {
|
|
35
|
+
const node = chunk.getNode(nodeId)
|
|
36
|
+
if (node !== undefined) {
|
|
37
|
+
return node
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return undefined
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// export const KnownLanguages = new LanguageRegistry()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isEqualMetaPointer, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
|
|
2
|
+
import { LION_CORE_M3_KEY, MetaPointers } from "@lionweb/json-utils"
|
|
3
|
+
|
|
4
|
+
import { createRequire } from "module"
|
|
5
|
+
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
7
|
+
const LionCore_M3 = require("./LionCore-M3.json")
|
|
8
|
+
const LionCore_builtins = require("./LionCore-builtins.json")
|
|
9
|
+
|
|
10
|
+
export const LionCore_M3_Json = LionCore_M3 as LionWebJsonChunk
|
|
11
|
+
export const LionCore_builtins_Json = LionCore_builtins as LionWebJsonChunk
|
|
12
|
+
|
|
13
|
+
export function isLionCoreLanguage(node: LionWebJsonNode) {
|
|
14
|
+
return node.classifier.language === LION_CORE_M3_KEY && node.classifier.version === "2023.1"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Does _node_ represent a language concept?
|
|
19
|
+
* @param node
|
|
20
|
+
*/
|
|
21
|
+
export const isConcept = (node: LionWebJsonNode): boolean => {
|
|
22
|
+
return isEqualMetaPointer(node.classifier, MetaPointers.Concept)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Does _node_ represent a language annotation?
|
|
27
|
+
* @param node
|
|
28
|
+
*/
|
|
29
|
+
export const isAnnotation = (node: LionWebJsonNode): boolean => {
|
|
30
|
+
return isEqualMetaPointer(node.classifier, MetaPointers.Annotation)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Does _node_ represent a language interface?
|
|
35
|
+
* @param node
|
|
36
|
+
*/
|
|
37
|
+
export const isInterface = (node: LionWebJsonNode): boolean => {
|
|
38
|
+
return isEqualMetaPointer(node.classifier, MetaPointers.Interface)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Does _node_ represent a language property?
|
|
43
|
+
* @param node
|
|
44
|
+
*/
|
|
45
|
+
export const isProperty = (node: LionWebJsonNode): boolean => {
|
|
46
|
+
return isEqualMetaPointer(node.classifier, MetaPointers.Property)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Does _node_ represent a language containment?
|
|
51
|
+
* @param node
|
|
52
|
+
*/
|
|
53
|
+
export const isContainment = (node: LionWebJsonNode): boolean => {
|
|
54
|
+
return isEqualMetaPointer(node.classifier, MetaPointers.Containment)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Does _node_ represent a language reference?
|
|
59
|
+
* @param node
|
|
60
|
+
*/
|
|
61
|
+
export const isReference = (node: LionWebJsonNode): boolean => {
|
|
62
|
+
return isEqualMetaPointer(node.classifier, MetaPointers.Reference)
|
|
63
|
+
}
|