@lionweb/validation 0.5.0 → 0.6.0-beta.2
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/README.md +2 -0
- package/dist/diff/DiffResult.d.ts +9 -0
- package/dist/diff/DiffResult.d.ts.map +1 -0
- package/dist/diff/DiffResult.js +18 -0
- package/dist/diff/DiffResult.js.map +1 -0
- package/dist/diff/LionWebJsonDiff.d.ts +25 -0
- package/dist/diff/LionWebJsonDiff.d.ts.map +1 -0
- package/dist/diff/LionWebJsonDiff.js +205 -0
- package/dist/diff/LionWebJsonDiff.js.map +1 -0
- package/dist/diff/changes/Change.d.ts +16 -0
- package/dist/diff/changes/Change.d.ts.map +1 -0
- package/dist/diff/changes/Change.js +19 -0
- package/dist/diff/changes/Change.js.map +1 -0
- package/dist/diff/changes/ChunkChange.d.ts +43 -0
- package/dist/diff/changes/ChunkChange.d.ts.map +1 -0
- package/dist/diff/changes/ChunkChange.js +57 -0
- package/dist/diff/changes/ChunkChange.js.map +1 -0
- package/dist/diff/changes/ContainmentChange.d.ts +26 -0
- package/dist/diff/changes/ContainmentChange.d.ts.map +1 -0
- package/dist/diff/changes/ContainmentChange.js +34 -0
- package/dist/diff/changes/ContainmentChange.js.map +1 -0
- package/dist/diff/changes/NodeChange.d.ts +22 -0
- package/dist/diff/changes/NodeChange.d.ts.map +1 -0
- package/dist/diff/changes/NodeChange.js +24 -0
- package/dist/diff/changes/NodeChange.js.map +1 -0
- package/dist/diff/changes/PropertyChange.d.ts +23 -0
- package/dist/diff/changes/PropertyChange.d.ts.map +1 -0
- package/dist/diff/changes/PropertyChange.js +28 -0
- package/dist/diff/changes/PropertyChange.js.map +1 -0
- package/dist/diff/changes/ReferenceChange.d.ts +19 -0
- package/dist/diff/changes/ReferenceChange.d.ts.map +1 -0
- package/dist/diff/changes/ReferenceChange.js +25 -0
- package/dist/diff/changes/ReferenceChange.js.map +1 -0
- package/dist/diff/changes/index.d.ts +7 -0
- package/dist/diff/changes/index.d.ts.map +1 -0
- package/dist/diff/changes/index.js +7 -0
- package/dist/diff/changes/index.js.map +1 -0
- package/dist/diff/index.d.ts +4 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +4 -0
- package/dist/diff/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/issues/LanguageIssues.d.ts +1 -1
- package/dist/issues/LanguageIssues.d.ts.map +1 -1
- package/dist/issues/LanguageIssues.js.map +1 -1
- package/dist/issues/ReferenceIssues.d.ts +1 -1
- package/dist/issues/ReferenceIssues.d.ts.map +1 -1
- package/dist/issues/ReferenceIssues.js.map +1 -1
- package/dist/issues/SyntaxIssues.d.ts +1 -1
- package/dist/issues/SyntaxIssues.d.ts.map +1 -1
- package/dist/issues/SyntaxIssues.js +4 -4
- package/dist/issues/SyntaxIssues.js.map +1 -1
- package/dist/issues/ValidationIssue.d.ts +1 -1
- package/dist/issues/ValidationIssue.d.ts.map +1 -1
- package/dist/issues/ValidationIssue.js.map +1 -1
- package/dist/issues/index.d.ts +1 -1
- package/dist/issues/index.d.ts.map +1 -1
- package/dist/issues/index.js +1 -1
- package/dist/issues/index.js.map +1 -1
- package/dist/json/ChunkUtils.d.ts.map +1 -1
- package/dist/json/ChunkUtils.js.map +1 -1
- package/dist/json/JsonContext.d.ts.map +1 -0
- package/dist/json/JsonContext.js.map +1 -0
- package/dist/json/LanguageUtils.d.ts.map +1 -1
- package/dist/json/LanguageUtils.js.map +1 -1
- package/dist/json/LionWebJson.d.ts +10 -9
- package/dist/json/LionWebJson.d.ts.map +1 -1
- package/dist/json/LionWebJson.js +1 -0
- package/dist/json/LionWebJson.js.map +1 -1
- package/dist/json/LionWebJsonChunkWrapper.d.ts +7 -4
- package/dist/json/LionWebJsonChunkWrapper.d.ts.map +1 -1
- package/dist/json/LionWebJsonChunkWrapper.js +48 -10
- package/dist/json/LionWebJsonChunkWrapper.js.map +1 -1
- package/dist/json/LionWebLanguageDefinition.d.ts.map +1 -1
- package/dist/json/LionWebLanguageDefinition.js +3 -3
- package/dist/json/LionWebLanguageDefinition.js.map +1 -1
- package/dist/json/NodeUtils.d.ts +5 -4
- package/dist/json/NodeUtils.d.ts.map +1 -1
- package/dist/json/NodeUtils.js +5 -2
- package/dist/json/NodeUtils.js.map +1 -1
- package/dist/json/index.d.ts +1 -0
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -0
- package/dist/json/index.js.map +1 -1
- package/dist/runners/FileUtils.d.ts.map +1 -1
- package/dist/runners/FileUtils.js.map +1 -1
- package/dist/runners/RunCheckFolder.js.map +1 -1
- package/dist/runners/RunCheckFolderWithLanguage.js.map +1 -1
- package/dist/runners/RunCheckOneFile.js.map +1 -1
- package/dist/runners/RunCheckOneFileWithLanguage.js.map +1 -1
- package/dist/runners/RunLioncoreDiff.js +5 -5
- package/dist/runners/RunLioncoreDiff.js.map +1 -1
- package/dist/runners/Utils.d.ts.map +1 -1
- package/dist/runners/Utils.js +1 -1
- package/dist/runners/Utils.js.map +1 -1
- package/dist/runners/index.d.ts.map +1 -1
- package/dist/runners/index.js.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageReferenceValidator.js +6 -6
- package/dist/validators/LionWebLanguageReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebLanguageValidator.d.ts.map +1 -1
- package/dist/validators/LionWebLanguageValidator.js +1 -1
- package/dist/validators/LionWebLanguageValidator.js.map +1 -1
- package/dist/validators/LionWebReferenceValidator.d.ts +1 -1
- package/dist/validators/LionWebReferenceValidator.d.ts.map +1 -1
- package/dist/validators/LionWebReferenceValidator.js +6 -6
- package/dist/validators/LionWebReferenceValidator.js.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts +1 -1
- package/dist/validators/LionWebSyntaxValidator.d.ts.map +1 -1
- package/dist/validators/LionWebSyntaxValidator.js +21 -11
- package/dist/validators/LionWebSyntaxValidator.js.map +1 -1
- package/dist/validators/LionWebValidator.d.ts.map +1 -1
- package/dist/validators/LionWebValidator.js.map +1 -1
- package/dist/validators/SimpleFieldValidator.d.ts +1 -1
- package/dist/validators/SimpleFieldValidator.d.ts.map +1 -1
- package/dist/validators/SimpleFieldValidator.js +1 -1
- package/dist/validators/SimpleFieldValidator.js.map +1 -1
- package/dist/validators/ValidationResult.d.ts.map +1 -1
- package/dist/validators/ValidationResult.js.map +1 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js.map +1 -1
- package/package.json +5 -2
- package/src/diff/DiffResult.ts +21 -0
- package/src/diff/LionWebJsonDiff.ts +259 -0
- package/src/diff/changes/Change.ts +52 -0
- package/src/diff/changes/ChunkChange.ts +68 -0
- package/src/diff/changes/ContainmentChange.ts +34 -0
- package/src/diff/changes/NodeChange.ts +32 -0
- package/src/diff/changes/PropertyChange.ts +29 -0
- package/src/diff/changes/ReferenceChange.ts +24 -0
- package/src/diff/changes/index.ts +6 -0
- package/src/diff/index.ts +3 -0
- package/src/index.ts +5 -4
- package/src/issues/LanguageIssues.ts +61 -39
- package/src/issues/ReferenceIssues.ts +51 -29
- package/src/issues/SyntaxIssues.ts +38 -23
- package/src/issues/ValidationIssue.ts +7 -7
- package/src/issues/index.ts +5 -5
- package/src/json/ChunkUtils.ts +7 -11
- package/src/json/JsonContext.ts +31 -0
- package/src/json/LanguageUtils.ts +5 -6
- package/src/json/LionWebJson.ts +44 -43
- package/src/json/LionWebJsonChunkWrapper.ts +76 -29
- package/src/json/LionWebLanguageDefinition.ts +44 -49
- package/src/json/NodeUtils.ts +25 -19
- package/src/json/index.ts +7 -6
- package/src/json/std-builtins-copy.json +347 -349
- package/src/runners/FileUtils.ts +48 -49
- package/src/runners/RunCheckFolder.ts +3 -3
- package/src/runners/RunCheckFolderWithLanguage.ts +31 -30
- package/src/runners/RunCheckOneFile.ts +3 -3
- package/src/runners/RunCheckOneFileWithLanguage.ts +21 -19
- package/src/runners/RunLioncoreDiff.ts +15 -15
- package/src/runners/Utils.ts +24 -24
- package/src/runners/index.ts +2 -2
- package/src/validators/LionWebLanguageReferenceValidator.ts +63 -55
- package/src/validators/LionWebLanguageValidator.ts +11 -12
- package/src/validators/LionWebReferenceValidator.ts +90 -76
- package/src/validators/LionWebSyntaxValidator.ts +108 -99
- package/src/validators/LionWebValidator.ts +33 -33
- package/src/validators/SimpleFieldValidator.ts +33 -28
- package/src/validators/ValidationResult.ts +5 -6
- package/src/validators/index.ts +7 -7
- package/dist/diff/LionwebDiff.d.ts +0 -40
- package/dist/diff/LionwebDiff.d.ts.map +0 -1
- package/dist/diff/LionwebDiff.js +0 -158
- package/dist/diff/LionwebDiff.js.map +0 -1
- package/dist/issues/JsonContext.d.ts.map +0 -1
- package/dist/issues/JsonContext.js.map +0 -1
- package/src/diff/LionwebDiff.ts +0 -193
- package/src/issues/JsonContext.ts +0 -31
- /package/dist/{issues → json}/JsonContext.d.ts +0 -0
- /package/dist/{issues → json}/JsonContext.js +0 -0
package/src/issues/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "
|
|
2
|
-
export * from "./ValidationIssue.js"
|
|
3
|
-
export * from "./SyntaxIssues.js"
|
|
4
|
-
export * from "./ReferenceIssues.js"
|
|
5
|
-
export * from "./LanguageIssues.js"
|
|
1
|
+
export * from "../json/JsonContext.js"
|
|
2
|
+
export * from "./ValidationIssue.js"
|
|
3
|
+
export * from "./SyntaxIssues.js"
|
|
4
|
+
export * from "./ReferenceIssues.js"
|
|
5
|
+
export * from "./LanguageIssues.js"
|
package/src/json/ChunkUtils.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LionWebJsonChunk,
|
|
3
|
-
LionWebJsonNode,
|
|
4
|
-
LwJsonUsedLanguage
|
|
5
|
-
} from "./LionWebJson.js";
|
|
1
|
+
import { LionWebJsonChunk, LionWebJsonNode, LwJsonUsedLanguage } from "./LionWebJson.js"
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Utility functions for LionWeb chunks
|
|
@@ -16,10 +12,10 @@ export class ChunkUtils {
|
|
|
16
12
|
static findLwUsedLanguage(chunk: LionWebJsonChunk, key: string): LwJsonUsedLanguage | null {
|
|
17
13
|
for (const language of chunk.languages) {
|
|
18
14
|
if (language.key === key) {
|
|
19
|
-
return language
|
|
15
|
+
return language
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
return null
|
|
18
|
+
return null
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
/**
|
|
@@ -31,10 +27,10 @@ export class ChunkUtils {
|
|
|
31
27
|
static findLwUsedLanguageWithVersion(chunk: LionWebJsonChunk, key: string, version: string): LwJsonUsedLanguage | null {
|
|
32
28
|
for (const language of chunk.languages) {
|
|
33
29
|
if (language.key === key && language.version === version) {
|
|
34
|
-
return language
|
|
30
|
+
return language
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
|
-
return null
|
|
33
|
+
return null
|
|
38
34
|
}
|
|
39
35
|
|
|
40
36
|
/**
|
|
@@ -45,9 +41,9 @@ export class ChunkUtils {
|
|
|
45
41
|
static findNode(chunk: LionWebJsonChunk, id: string): LionWebJsonNode | null {
|
|
46
42
|
for (const node of chunk.nodes) {
|
|
47
43
|
if (node.id === id) {
|
|
48
|
-
return node
|
|
44
|
+
return node
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
|
-
return null
|
|
47
|
+
return null
|
|
52
48
|
}
|
|
53
49
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type JsonPath = (string | number)[]
|
|
2
|
+
|
|
3
|
+
export class JsonContext {
|
|
4
|
+
private parent: JsonContext | null
|
|
5
|
+
private local_path: JsonPath
|
|
6
|
+
|
|
7
|
+
concat(...items: JsonPath): JsonContext {
|
|
8
|
+
return new JsonContext(this, items)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
path(): JsonPath {
|
|
12
|
+
return this.parent === null ? this.local_path : this.parent.path().concat(this.local_path)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constructor(parent: JsonContext | null, path: JsonPath) {
|
|
16
|
+
this.parent = parent
|
|
17
|
+
this.local_path = path
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toString(): string {
|
|
21
|
+
let result = ""
|
|
22
|
+
this.path().forEach((part, index) => {
|
|
23
|
+
if (typeof part === "string") {
|
|
24
|
+
result += (index === 0 ? "" : ".") + part
|
|
25
|
+
} else if (typeof part === "number") {
|
|
26
|
+
result += "[" + part + "]"
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
return result
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { LionWebJsonChunk } from "./LionWebJson.js"
|
|
2
|
-
import { LionWebJsonChunkWrapper } from "./LionWebJsonChunkWrapper.js"
|
|
1
|
+
import { LionWebJsonChunk } from "./LionWebJson.js"
|
|
2
|
+
import { LionWebJsonChunkWrapper } from "./LionWebJsonChunkWrapper.js"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Contains methods for getting information from a LionWebJsonChunk representing a language.
|
|
6
6
|
*/
|
|
7
7
|
export class LanguageWrapper extends LionWebJsonChunkWrapper {
|
|
8
|
-
|
|
9
8
|
constructor(languageJson: LionWebJsonChunk) {
|
|
10
|
-
super(languageJson)
|
|
9
|
+
super(languageJson)
|
|
11
10
|
}
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
// inheritsFrom = (classifier: LionWebJsonNode): LionWebJsonNode[] => {
|
|
14
13
|
// if (isConcept(classifier) || isAnnotation(classifier)) {
|
|
15
14
|
// // find the language (have key and version)
|
|
16
15
|
// // find concept or annotation
|
|
17
|
-
// // find extends/inherits property
|
|
16
|
+
// // find extends/inherits property
|
|
18
17
|
// return [
|
|
19
18
|
// ...(
|
|
20
19
|
// isRef(classifier.extends)
|
package/src/json/LionWebJson.ts
CHANGED
|
@@ -3,48 +3,49 @@
|
|
|
3
3
|
* @see https://lionweb-io.github.io/specification/serialization/serialization.html
|
|
4
4
|
* We use types instead of classes, because the purpose is to define the Lionweb JSON to be sent over the line.
|
|
5
5
|
*/
|
|
6
|
-
export const LION_CORE_BUILTINS_KEY = "LionCore-builtins"
|
|
7
|
-
export const LION_CORE_BUILTINS_INAMED_NAME = "LionCore-builtins-INamed-name"
|
|
8
|
-
export const LION_CORE_M3_KEY = "LionCore-M3"
|
|
9
|
-
export const LION_CORE_M3_NAME = "LionCore_M3"
|
|
6
|
+
export const LION_CORE_BUILTINS_KEY = "LionCore-builtins"
|
|
7
|
+
export const LION_CORE_BUILTINS_INAMED_NAME = "LionCore-builtins-INamed-name"
|
|
8
|
+
export const LION_CORE_M3_KEY = "LionCore-M3"
|
|
9
|
+
export const LION_CORE_M3_NAME = "LionCore_M3"
|
|
10
|
+
export const LION_CORE_M3_VERSION = "2023.1"
|
|
10
11
|
|
|
11
|
-
export const LIONWEB_BOOLEAN_TYPE = "LionCore-builtins-Boolean"
|
|
12
|
-
export const LIONWEB_JSON_TYPE = "LionCore-builtins-JSON"
|
|
13
|
-
export const LIONWEB_INTEGER_TYPE = "LionCore-builtins-Integer"
|
|
14
|
-
export const LIONWEB_STRING_TYPE = "LionCore-builtins-String"
|
|
12
|
+
export const LIONWEB_BOOLEAN_TYPE = "LionCore-builtins-Boolean"
|
|
13
|
+
export const LIONWEB_JSON_TYPE = "LionCore-builtins-JSON"
|
|
14
|
+
export const LIONWEB_INTEGER_TYPE = "LionCore-builtins-Integer"
|
|
15
|
+
export const LIONWEB_STRING_TYPE = "LionCore-builtins-String"
|
|
15
16
|
|
|
16
|
-
export type
|
|
17
|
+
export type LionWebId = string
|
|
17
18
|
|
|
18
19
|
export type LionWebJsonMetaPointer = {
|
|
19
|
-
language: string
|
|
20
|
-
version: string
|
|
21
|
-
key: string
|
|
22
|
-
}
|
|
20
|
+
language: string
|
|
21
|
+
version: string
|
|
22
|
+
key: string
|
|
23
|
+
}
|
|
23
24
|
|
|
24
25
|
export function isEqualMetaPointer(p1: LionWebJsonMetaPointer, p2: LionWebJsonMetaPointer): boolean {
|
|
25
|
-
return p1.key === p2.key && p1.version === p2.version && p1.language === p2.language
|
|
26
|
+
return p1.key === p2.key && p1.version === p2.version && p1.language === p2.language
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export type LionWebJsonChunk = {
|
|
29
|
-
serializationFormatVersion: string
|
|
30
|
-
languages: LwJsonUsedLanguage[]
|
|
31
|
-
nodes: LionWebJsonNode[]
|
|
32
|
-
}
|
|
30
|
+
serializationFormatVersion: string
|
|
31
|
+
languages: LwJsonUsedLanguage[]
|
|
32
|
+
nodes: LionWebJsonNode[]
|
|
33
|
+
}
|
|
33
34
|
|
|
34
35
|
export type LwJsonUsedLanguage = {
|
|
35
|
-
key: string
|
|
36
|
-
version: string
|
|
37
|
-
}
|
|
36
|
+
key: string
|
|
37
|
+
version: string
|
|
38
|
+
}
|
|
38
39
|
|
|
39
40
|
export type LionWebJsonNode = {
|
|
40
|
-
id:
|
|
41
|
-
classifier: LionWebJsonMetaPointer
|
|
42
|
-
properties: LionWebJsonProperty[]
|
|
43
|
-
containments:
|
|
44
|
-
references: LionWebJsonReference[]
|
|
45
|
-
annotations:
|
|
46
|
-
parent:
|
|
47
|
-
}
|
|
41
|
+
id: LionWebId
|
|
42
|
+
classifier: LionWebJsonMetaPointer
|
|
43
|
+
properties: LionWebJsonProperty[]
|
|
44
|
+
containments: LionWebJsonContainment[]
|
|
45
|
+
references: LionWebJsonReference[]
|
|
46
|
+
annotations: LionWebId[]
|
|
47
|
+
parent: LionWebId | null
|
|
48
|
+
}
|
|
48
49
|
|
|
49
50
|
export function createLwNode(): LionWebJsonNode {
|
|
50
51
|
return {
|
|
@@ -55,25 +56,25 @@ export function createLwNode(): LionWebJsonNode {
|
|
|
55
56
|
references: [],
|
|
56
57
|
annotations: [],
|
|
57
58
|
parent: null,
|
|
58
|
-
}
|
|
59
|
+
}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
export type LionWebJsonProperty = {
|
|
62
|
-
property: LionWebJsonMetaPointer
|
|
63
|
-
value: string
|
|
64
|
-
}
|
|
63
|
+
property: LionWebJsonMetaPointer
|
|
64
|
+
value: string
|
|
65
|
+
}
|
|
65
66
|
|
|
66
|
-
export type
|
|
67
|
-
containment: LionWebJsonMetaPointer
|
|
68
|
-
children:
|
|
69
|
-
}
|
|
67
|
+
export type LionWebJsonContainment = {
|
|
68
|
+
containment: LionWebJsonMetaPointer
|
|
69
|
+
children: LionWebId[]
|
|
70
|
+
}
|
|
70
71
|
|
|
71
72
|
export type LionWebJsonReference = {
|
|
72
|
-
reference: LionWebJsonMetaPointer
|
|
73
|
-
targets: LionWebJsonReferenceTarget[]
|
|
74
|
-
}
|
|
73
|
+
reference: LionWebJsonMetaPointer
|
|
74
|
+
targets: LionWebJsonReferenceTarget[]
|
|
75
|
+
}
|
|
75
76
|
|
|
76
77
|
export type LionWebJsonReferenceTarget = {
|
|
77
|
-
resolveInfo
|
|
78
|
-
reference:
|
|
79
|
-
}
|
|
78
|
+
resolveInfo?: string
|
|
79
|
+
reference: LionWebId
|
|
80
|
+
}
|
|
@@ -1,56 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import {
|
|
2
|
+
isEqualMetaPointer, LION_CORE_BUILTINS_INAMED_NAME, LION_CORE_BUILTINS_KEY, LION_CORE_M3_VERSION,
|
|
3
|
+
LionWebId,
|
|
4
|
+
LionWebJsonChunk,
|
|
5
|
+
LionWebJsonContainment,
|
|
6
|
+
LionWebJsonMetaPointer,
|
|
7
|
+
LionWebJsonNode,
|
|
8
|
+
LionWebJsonProperty
|
|
9
|
+
} from "./LionWebJson.js"
|
|
10
|
+
import { LionWebLanguageDefinition } from "./LionWebLanguageDefinition.js"
|
|
11
|
+
import { NodeUtils } from "./NodeUtils.js"
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* Wraps around a LionWebJsonChunk, providing access to information inside, using caches to improve performance.
|
|
15
|
+
* NB Make sure that the contents of the chunk are not changed after creating the wrapper!
|
|
9
16
|
*/
|
|
10
17
|
export class LionWebJsonChunkWrapper {
|
|
11
|
-
jsonChunk: LionWebJsonChunk
|
|
12
|
-
language: LionWebLanguageDefinition
|
|
18
|
+
jsonChunk: LionWebJsonChunk
|
|
19
|
+
language: LionWebLanguageDefinition | null = null
|
|
13
20
|
/**
|
|
14
21
|
* Map to get quick access to nodes by id.
|
|
15
22
|
* @protected
|
|
16
23
|
*/
|
|
17
|
-
protected nodesIdMap: Map<
|
|
24
|
+
protected nodesIdMap: Map<LionWebId, LionWebJsonNode> = new Map<LionWebId, LionWebJsonNode>()
|
|
18
25
|
|
|
19
26
|
constructor(chunk: unknown) {
|
|
20
|
-
this.jsonChunk = chunk as LionWebJsonChunk
|
|
21
|
-
|
|
27
|
+
this.jsonChunk = chunk as LionWebJsonChunk
|
|
28
|
+
this.prepareNodeIds()
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
/** Put all nodes in a map, validate that there are no two nodes with the same id.
|
|
25
32
|
* The check should logically be in LionWebReferenceValidator, but the created map is needed here.
|
|
26
33
|
*/
|
|
27
34
|
prepareNodeIds() {
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
35
|
+
this.jsonChunk.nodes.forEach(node => {
|
|
36
|
+
this.nodesIdMap.set(node.id, node)
|
|
37
|
+
})
|
|
32
38
|
}
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.prepareNodeIds();
|
|
37
|
-
}
|
|
38
|
-
return this.nodesIdMap;
|
|
40
|
+
getNode(id: string): LionWebJsonNode | undefined {
|
|
41
|
+
return this.nodesIdMap.get(id)
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
return
|
|
44
|
+
findContainment(node: LionWebJsonNode, containment: LionWebJsonMetaPointer): LionWebJsonContainment | undefined {
|
|
45
|
+
return node.containments.find(
|
|
46
|
+
cont => isEqualMetaPointer(cont.containment, containment)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
findProperty(node: LionWebJsonNode, property: LionWebJsonMetaPointer): LionWebJsonProperty | undefined {
|
|
51
|
+
return node.properties.find(
|
|
52
|
+
prop => isEqualMetaPointer(prop.property, property)
|
|
53
|
+
)
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
findNodesOfConcept(conceptKey: string): LionWebJsonNode[] {
|
|
46
|
-
return this.jsonChunk.nodes.filter(node => node.classifier.key === conceptKey)
|
|
57
|
+
return this.jsonChunk.nodes.filter(node => node.classifier.key === conceptKey)
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
allProperties(conceptNode: LionWebJsonNode): LionWebJsonProperty[] {
|
|
50
|
-
const result: LionWebJsonProperty[] = []
|
|
51
|
-
result.push(...conceptNode.properties)
|
|
52
|
-
const extendsReference = NodeUtils.findLwReference(conceptNode, "Concept-extends")
|
|
53
|
-
if (extendsReference !==null) {
|
|
61
|
+
const result: LionWebJsonProperty[] = []
|
|
62
|
+
result.push(...conceptNode.properties)
|
|
63
|
+
const extendsReference = NodeUtils.findLwReference(conceptNode, "Concept-extends")
|
|
64
|
+
if (extendsReference !== null) {
|
|
54
65
|
// extendsReference.targets.forEach(target => {
|
|
55
66
|
// // Find the extended concept
|
|
56
67
|
// if (this.language !== null) {
|
|
@@ -59,9 +70,45 @@ export class LionWebJsonChunkWrapper {
|
|
|
59
70
|
// }
|
|
60
71
|
// });
|
|
61
72
|
}
|
|
62
|
-
return result
|
|
73
|
+
return result
|
|
63
74
|
}
|
|
64
75
|
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
asString(): string {
|
|
77
|
+
let result = ""
|
|
78
|
+
const partitions = this.jsonChunk.nodes.filter(n => n.parent === null)
|
|
79
|
+
partitions.forEach(partition => {
|
|
80
|
+
const pString = this.recursiveToString(partition, 1)
|
|
81
|
+
result += pString
|
|
82
|
+
})
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
67
85
|
|
|
86
|
+
private recursiveToString(node: LionWebJsonNode | undefined, depth: number): string {
|
|
87
|
+
if (node === undefined) {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
let result: string = ""
|
|
91
|
+
const nameProperty = this.findProperty(node, {
|
|
92
|
+
language: LION_CORE_BUILTINS_KEY,
|
|
93
|
+
version: LION_CORE_M3_VERSION,
|
|
94
|
+
key: LION_CORE_BUILTINS_INAMED_NAME,
|
|
95
|
+
})
|
|
96
|
+
const name = nameProperty === undefined ? "" : " " + nameProperty.value
|
|
97
|
+
result += Array(depth).join(" ") + "(" + node.id + ")" + name + "\n"
|
|
98
|
+
node.properties.filter(p => p !== nameProperty).forEach(property => {
|
|
99
|
+
result += Array(depth + 1).join(" ") + "*" + property.property.key + "*: " + property.value + "\n"
|
|
100
|
+
})
|
|
101
|
+
node.references.forEach(ref => {
|
|
102
|
+
result += Array(depth + 1).join(" ") + "*" + ref.reference.key + "*: " + JSON.stringify(ref.targets) + "\n"
|
|
103
|
+
})
|
|
104
|
+
node.containments.forEach(cont => {
|
|
105
|
+
if (cont.children.length !== 0) {
|
|
106
|
+
result += Array(depth + 1).join(" ") + "*" + cont.containment.key + "*" + "\n"
|
|
107
|
+
cont.children.forEach(ch => {
|
|
108
|
+
result += this.recursiveToString(this.getNode(ch), depth + 1)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
return result
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
LionWebJsonNode,
|
|
5
|
-
} from "./LionWebJson.js";
|
|
6
|
-
import { LionWebJsonChunkWrapper } from "./LionWebJsonChunkWrapper.js";
|
|
7
|
-
import { NodeUtils } from "./NodeUtils.js";
|
|
1
|
+
import { LION_CORE_BUILTINS_INAMED_NAME, LionWebJsonMetaPointer, LionWebJsonNode } from "./LionWebJson.js"
|
|
2
|
+
import { LionWebJsonChunkWrapper } from "./LionWebJsonChunkWrapper.js"
|
|
3
|
+
import { NodeUtils } from "./NodeUtils.js"
|
|
8
4
|
|
|
9
5
|
type LanguageId = {
|
|
10
|
-
name?: string
|
|
11
|
-
version?: string
|
|
12
|
-
key?: string
|
|
13
|
-
}
|
|
6
|
+
name?: string
|
|
7
|
+
version?: string
|
|
8
|
+
key?: string
|
|
9
|
+
}
|
|
14
10
|
|
|
15
|
-
export const LIONWEB_M3_PROPERTY_KEY = "Property"
|
|
16
|
-
export const LIONWEB_M3_CONCEPT_KEY = "Concept"
|
|
17
|
-
export const LIONWEB_M3_INTERFACE_KEY = "Interface"
|
|
18
|
-
export const LIONWEB_M3_ANNOTATION_KEY = "Annotation"
|
|
19
|
-
export const LIONWEB_M3_REFERENCE_KEY = "Reference"
|
|
20
|
-
export const LIONWEB_M3_LANGUAGE_KEY = "Language"
|
|
21
|
-
export const LIONWEB_M3_LANGUAGE_VERSION_KEY = "Language-version"
|
|
22
|
-
export const LIONWEB_M3_IKEYED_KEY_KEY = "IKeyed-key"
|
|
23
|
-
export const LIONWEB_M3_PROPERTY_TYPE_KEY = "Property-type"
|
|
11
|
+
export const LIONWEB_M3_PROPERTY_KEY = "Property"
|
|
12
|
+
export const LIONWEB_M3_CONCEPT_KEY = "Concept"
|
|
13
|
+
export const LIONWEB_M3_INTERFACE_KEY = "Interface"
|
|
14
|
+
export const LIONWEB_M3_ANNOTATION_KEY = "Annotation"
|
|
15
|
+
export const LIONWEB_M3_REFERENCE_KEY = "Reference"
|
|
16
|
+
export const LIONWEB_M3_LANGUAGE_KEY = "Language"
|
|
17
|
+
export const LIONWEB_M3_LANGUAGE_VERSION_KEY = "Language-version"
|
|
18
|
+
export const LIONWEB_M3_IKEYED_KEY_KEY = "IKeyed-key"
|
|
19
|
+
export const LIONWEB_M3_PROPERTY_TYPE_KEY = "Property-type"
|
|
24
20
|
/**
|
|
25
21
|
* Collection of language definitions
|
|
26
22
|
*/
|
|
@@ -57,12 +53,12 @@ export const LIONWEB_M3_PROPERTY_TYPE_KEY = "Property-type";
|
|
|
57
53
|
* Represents a LionWeb serialiation chunk which represents a language definition / metamodel
|
|
58
54
|
*/
|
|
59
55
|
export class LionWebLanguageDefinition {
|
|
60
|
-
languageId: LanguageId | null = null
|
|
56
|
+
languageId: LanguageId | null = null
|
|
61
57
|
/**
|
|
62
58
|
* All nodes in the language
|
|
63
59
|
*/
|
|
64
|
-
nodeKeymap = new Map<string, LionWebJsonNode>()
|
|
65
|
-
languageChunkWrapper: LionWebJsonChunkWrapper
|
|
60
|
+
nodeKeymap = new Map<string, LionWebJsonNode>()
|
|
61
|
+
languageChunkWrapper: LionWebJsonChunkWrapper
|
|
66
62
|
|
|
67
63
|
/**
|
|
68
64
|
* Assume chunk represents a language metamodel according to Lionweb M3.
|
|
@@ -70,27 +66,26 @@ export class LionWebLanguageDefinition {
|
|
|
70
66
|
*/
|
|
71
67
|
constructor(chunk: LionWebJsonChunkWrapper) {
|
|
72
68
|
// console.log("CHUNK " + JSON.stringify(chunk))
|
|
73
|
-
const languageNodes = chunk.findNodesOfConcept(LIONWEB_M3_LANGUAGE_KEY)
|
|
69
|
+
const languageNodes = chunk.findNodesOfConcept(LIONWEB_M3_LANGUAGE_KEY)
|
|
74
70
|
if (languageNodes.length !== 1) {
|
|
75
71
|
// TODO Better error handling.
|
|
76
|
-
console.error("1 Expected exactly one Language node, found " + languageNodes.length + " => " + JSON.stringify(languageNodes))
|
|
72
|
+
console.error("1 Expected exactly one Language node, found " + languageNodes.length + " => " + JSON.stringify(languageNodes))
|
|
77
73
|
} else {
|
|
78
|
-
const languageNode = languageNodes[0]
|
|
79
|
-
this.setLanguage(languageNode)
|
|
74
|
+
const languageNode = languageNodes[0]
|
|
75
|
+
this.setLanguage(languageNode)
|
|
80
76
|
}
|
|
81
|
-
this.languageChunkWrapper = chunk
|
|
82
|
-
|
|
77
|
+
this.languageChunkWrapper = chunk
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
protected setLanguage(languageNode: LionWebJsonNode) {
|
|
86
81
|
// Assume LwNode is a concept of type "Language"
|
|
87
|
-
const nameProp = languageNode.properties.find(prop => prop.property.key === LION_CORE_BUILTINS_INAMED_NAME)
|
|
88
|
-
const versionProp = languageNode.properties.find(prop => prop.property.key === LIONWEB_M3_LANGUAGE_VERSION_KEY)
|
|
89
|
-
const keyProp = languageNode.properties.find(prop => prop.property.key === LIONWEB_M3_IKEYED_KEY_KEY)
|
|
82
|
+
const nameProp = languageNode.properties.find(prop => prop.property.key === LION_CORE_BUILTINS_INAMED_NAME)
|
|
83
|
+
const versionProp = languageNode.properties.find(prop => prop.property.key === LIONWEB_M3_LANGUAGE_VERSION_KEY)
|
|
84
|
+
const keyProp = languageNode.properties.find(prop => prop.property.key === LIONWEB_M3_IKEYED_KEY_KEY)
|
|
90
85
|
this.languageId = {
|
|
91
86
|
name: nameProp?.value,
|
|
92
87
|
version: versionProp?.value,
|
|
93
|
-
key: keyProp?.value
|
|
88
|
+
key: keyProp?.value,
|
|
94
89
|
}
|
|
95
90
|
}
|
|
96
91
|
|
|
@@ -100,26 +95,26 @@ export class LionWebLanguageDefinition {
|
|
|
100
95
|
* @param node
|
|
101
96
|
*/
|
|
102
97
|
setNodeByKey(key: string, node: LionWebJsonNode): void {
|
|
103
|
-
this.nodeKeymap.set(key, node)
|
|
98
|
+
this.nodeKeymap.set(key, node)
|
|
104
99
|
}
|
|
105
100
|
|
|
106
101
|
getNodeByKey(key: string): LionWebJsonNode | undefined {
|
|
107
|
-
return this.nodeKeymap.get(key)
|
|
102
|
+
return this.nodeKeymap.get(key)
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
getNodeByMetaPointer(metaPointer: LionWebJsonMetaPointer): LionWebJsonNode | undefined {
|
|
111
106
|
// console.log("get metapointer " + JSON.stringify(metaPointer))
|
|
112
107
|
const result = this.languageChunkWrapper.jsonChunk.nodes.find(n => {
|
|
113
108
|
// console.log(" looking into " + JSON.stringify(n));
|
|
114
|
-
const keyProp = NodeUtils.findLwProperty(n, LIONWEB_M3_IKEYED_KEY_KEY)
|
|
109
|
+
const keyProp = NodeUtils.findLwProperty(n, LIONWEB_M3_IKEYED_KEY_KEY)
|
|
115
110
|
// const versionProp = NodeUtils.findLwProperty(n, "Language-version");
|
|
116
111
|
|
|
117
112
|
// return ((!!keyProp) && (keyProp.value === metaPointer.key) && (!!versionProp) && (versionProp.value === metaPointer.version));
|
|
118
113
|
|
|
119
114
|
// console.log(" getNodeByMetaPointer.looking into " + node.id + " found " + JSON.stringify(keyProp));
|
|
120
|
-
return
|
|
121
|
-
})
|
|
122
|
-
return result
|
|
115
|
+
return !!keyProp && keyProp.value === metaPointer.key
|
|
116
|
+
})
|
|
117
|
+
return result
|
|
123
118
|
}
|
|
124
119
|
|
|
125
120
|
getPropertyByKey(key: string): LionWebJsonNode | undefined {
|
|
@@ -127,11 +122,11 @@ export class LionWebLanguageDefinition {
|
|
|
127
122
|
const propertyNode = this.languageChunkWrapper.findNodesOfConcept(LIONWEB_M3_PROPERTY_KEY).find(n => {
|
|
128
123
|
// console.log(" looking into " + JSON.stringify(n));
|
|
129
124
|
const keyProp = (n as LionWebJsonNode).properties.find(prop => {
|
|
130
|
-
return prop.property.key === LIONWEB_M3_IKEYED_KEY_KEY && prop.value === key
|
|
131
|
-
})
|
|
132
|
-
return keyProp
|
|
133
|
-
})
|
|
134
|
-
return propertyNode
|
|
125
|
+
return prop.property.key === LIONWEB_M3_IKEYED_KEY_KEY && prop.value === key
|
|
126
|
+
})
|
|
127
|
+
return keyProp
|
|
128
|
+
})
|
|
129
|
+
return propertyNode
|
|
135
130
|
}
|
|
136
131
|
|
|
137
132
|
getConceptByKey(key: string): LionWebJsonNode | undefined {
|
|
@@ -139,10 +134,10 @@ export class LionWebLanguageDefinition {
|
|
|
139
134
|
const conceptNode = this.languageChunkWrapper.findNodesOfConcept(LIONWEB_M3_CONCEPT_KEY).find(n => {
|
|
140
135
|
// console.log(" looking into " + JSON.stringify(n));
|
|
141
136
|
const keyProp = n.properties.find(prop => {
|
|
142
|
-
return prop.property.key === LIONWEB_M3_IKEYED_KEY_KEY && prop.value === key
|
|
143
|
-
})
|
|
144
|
-
return keyProp
|
|
145
|
-
})
|
|
146
|
-
return conceptNode
|
|
137
|
+
return prop.property.key === LIONWEB_M3_IKEYED_KEY_KEY && prop.value === key
|
|
138
|
+
})
|
|
139
|
+
return keyProp
|
|
140
|
+
})
|
|
141
|
+
return conceptNode
|
|
147
142
|
}
|
|
148
143
|
}
|
package/src/json/NodeUtils.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
LionWebJsonContainment,
|
|
3
3
|
LionWebJsonNode,
|
|
4
4
|
LionWebJsonProperty,
|
|
5
5
|
LionWebJsonReference,
|
|
6
|
-
LionWebJsonReferenceTarget
|
|
7
|
-
} from "./LionWebJson.js"
|
|
6
|
+
LionWebJsonReferenceTarget,
|
|
7
|
+
} from "./LionWebJson.js"
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Utility functions for LionWebJsonNode's
|
|
@@ -18,10 +18,10 @@ export class NodeUtils {
|
|
|
18
18
|
static findLwProperty(node: LionWebJsonNode, key: string): LionWebJsonProperty | null {
|
|
19
19
|
for (const property of node.properties) {
|
|
20
20
|
if (property.property.key === key) {
|
|
21
|
-
return property
|
|
21
|
+
return property
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
return null
|
|
24
|
+
return null
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -29,44 +29,50 @@ export class NodeUtils {
|
|
|
29
29
|
* @param node
|
|
30
30
|
* @param key
|
|
31
31
|
*/
|
|
32
|
-
static findLwChild(node: LionWebJsonNode, key: string):
|
|
32
|
+
static findLwChild(node: LionWebJsonNode, key: string): LionWebJsonContainment | null {
|
|
33
33
|
for (const containment of node.containments) {
|
|
34
34
|
if (containment.containment.key === key) {
|
|
35
|
-
return containment
|
|
35
|
+
return containment
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
return null
|
|
38
|
+
return null
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
static findLwReference(node: LionWebJsonNode, key: string): LionWebJsonReference | null {
|
|
42
42
|
for (const reference of node.references) {
|
|
43
43
|
if (reference.reference.key === key) {
|
|
44
|
-
return reference
|
|
44
|
+
return reference
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
return null
|
|
47
|
+
return null
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
static findLwReferenceTarget(
|
|
50
|
+
static findLwReferenceTarget(
|
|
51
|
+
lwReferenceTargets: LionWebJsonReferenceTarget[],
|
|
52
|
+
target: LionWebJsonReferenceTarget,
|
|
53
|
+
): LionWebJsonReferenceTarget | null {
|
|
51
54
|
for (const refTarget of lwReferenceTargets) {
|
|
52
55
|
if (refTarget.reference === target.reference && refTarget.resolveInfo === target.resolveInfo) {
|
|
53
|
-
return refTarget
|
|
56
|
+
return refTarget
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
return null
|
|
59
|
+
return null
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
|
-
* Get all nodes that are children for
|
|
63
|
+
* Get all nodes that are children for _node_: both the containment and annotation children
|
|
61
64
|
* @param node
|
|
62
65
|
*/
|
|
63
|
-
static
|
|
64
|
-
const result: string[] = []
|
|
66
|
+
static allDirectChildren(node: LionWebJsonNode): string[] {
|
|
67
|
+
const result: string[] = []
|
|
65
68
|
for (const containment of node.containments) {
|
|
66
|
-
result.push(...containment.children)
|
|
69
|
+
result.push(...containment.children)
|
|
67
70
|
}
|
|
68
|
-
result.push(...node.annotations)
|
|
69
|
-
return result
|
|
71
|
+
result.push(...node.annotations)
|
|
72
|
+
return result
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
static findContainmentContainingChild(containments: LionWebJsonContainment[], childId: string): LionWebJsonContainment | undefined {
|
|
76
|
+
return containments.find(cont => cont.children.includes(childId))
|
|
77
|
+
}
|
|
72
78
|
}
|
package/src/json/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
1
|
+
export * from "./JsonContext.js"
|
|
2
|
+
export * from "./NodeUtils.js"
|
|
3
|
+
export * from "./ChunkUtils.js"
|
|
4
|
+
export * from "./LionWebJson.js"
|
|
5
|
+
export * from "./LionWebJsonChunkWrapper.js"
|
|
6
|
+
export * from "./LionWebLanguageDefinition.js"
|
|
7
|
+
export * from "./LanguageUtils.js"
|