@lionweb/class-core 0.6.13-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +157 -0
  3. package/dist/base-types.d.ts +167 -0
  4. package/dist/base-types.d.ts.map +1 -0
  5. package/dist/base-types.js +147 -0
  6. package/dist/base-types.js.map +1 -0
  7. package/dist/convenience.d.ts +49 -0
  8. package/dist/convenience.d.ts.map +1 -0
  9. package/dist/convenience.js +75 -0
  10. package/dist/convenience.js.map +1 -0
  11. package/dist/deltas/appliers.d.ts +42 -0
  12. package/dist/deltas/appliers.d.ts.map +1 -0
  13. package/dist/deltas/appliers.js +274 -0
  14. package/dist/deltas/appliers.js.map +1 -0
  15. package/dist/deltas/base.d.ts +6 -0
  16. package/dist/deltas/base.d.ts.map +1 -0
  17. package/dist/deltas/base.js +18 -0
  18. package/dist/deltas/base.js.map +1 -0
  19. package/dist/deltas/handlers.d.ts +17 -0
  20. package/dist/deltas/handlers.d.ts.map +1 -0
  21. package/dist/deltas/handlers.js +43 -0
  22. package/dist/deltas/handlers.js.map +1 -0
  23. package/dist/deltas/index.d.ts +7 -0
  24. package/dist/deltas/index.d.ts.map +1 -0
  25. package/dist/deltas/index.js +23 -0
  26. package/dist/deltas/index.js.map +1 -0
  27. package/dist/deltas/inverters.d.ts +7 -0
  28. package/dist/deltas/inverters.d.ts.map +1 -0
  29. package/dist/deltas/inverters.js +82 -0
  30. package/dist/deltas/inverters.js.map +1 -0
  31. package/dist/deltas/serialization/base.d.ts +7 -0
  32. package/dist/deltas/serialization/base.d.ts.map +1 -0
  33. package/dist/deltas/serialization/base.js +18 -0
  34. package/dist/deltas/serialization/base.js.map +1 -0
  35. package/dist/deltas/serialization/deserializer.g.d.ts +5 -0
  36. package/dist/deltas/serialization/deserializer.g.d.ts.map +1 -0
  37. package/dist/deltas/serialization/deserializer.g.js +164 -0
  38. package/dist/deltas/serialization/deserializer.g.js.map +1 -0
  39. package/dist/deltas/serialization/index.d.ts +5 -0
  40. package/dist/deltas/serialization/index.d.ts.map +1 -0
  41. package/dist/deltas/serialization/index.js +21 -0
  42. package/dist/deltas/serialization/index.js.map +1 -0
  43. package/dist/deltas/serialization/serializer-helpers.d.ts +12 -0
  44. package/dist/deltas/serialization/serializer-helpers.d.ts.map +1 -0
  45. package/dist/deltas/serialization/serializer-helpers.js +28 -0
  46. package/dist/deltas/serialization/serializer-helpers.js.map +1 -0
  47. package/dist/deltas/serialization/serializer.g.d.ts +4 -0
  48. package/dist/deltas/serialization/serializer.g.d.ts.map +1 -0
  49. package/dist/deltas/serialization/serializer.g.js +208 -0
  50. package/dist/deltas/serialization/serializer.g.js.map +1 -0
  51. package/dist/deltas/serialization/types.g.d.ts +147 -0
  52. package/dist/deltas/serialization/types.g.d.ts.map +1 -0
  53. package/dist/deltas/serialization/types.g.js +18 -0
  54. package/dist/deltas/serialization/types.g.js.map +1 -0
  55. package/dist/deltas/types.g.d.ts +149 -0
  56. package/dist/deltas/types.g.d.ts.map +1 -0
  57. package/dist/deltas/types.g.js +180 -0
  58. package/dist/deltas/types.g.js.map +1 -0
  59. package/dist/deserializer.d.ts +27 -0
  60. package/dist/deserializer.d.ts.map +1 -0
  61. package/dist/deserializer.js +168 -0
  62. package/dist/deserializer.js.map +1 -0
  63. package/dist/duplicator.d.ts +19 -0
  64. package/dist/duplicator.d.ts.map +1 -0
  65. package/dist/duplicator.js +87 -0
  66. package/dist/duplicator.js.map +1 -0
  67. package/dist/id-mapping.d.ts +19 -0
  68. package/dist/id-mapping.d.ts.map +1 -0
  69. package/dist/id-mapping.js +44 -0
  70. package/dist/id-mapping.js.map +1 -0
  71. package/dist/index.d.ts +11 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +28 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/linking.d.ts +20 -0
  76. package/dist/linking.d.ts.map +1 -0
  77. package/dist/linking.js +18 -0
  78. package/dist/linking.js.map +1 -0
  79. package/dist/lionCore_builtins.g.d.ts +35 -0
  80. package/dist/lionCore_builtins.g.d.ts.map +1 -0
  81. package/dist/lionCore_builtins.g.js +96 -0
  82. package/dist/lionCore_builtins.g.js.map +1 -0
  83. package/dist/serializer.d.ts +17 -0
  84. package/dist/serializer.d.ts.map +1 -0
  85. package/dist/serializer.js +70 -0
  86. package/dist/serializer.js.map +1 -0
  87. package/dist/textualizer.d.ts +7 -0
  88. package/dist/textualizer.d.ts.map +1 -0
  89. package/dist/textualizer.js +82 -0
  90. package/dist/textualizer.js.map +1 -0
  91. package/dist/value-managers/annotations.d.ts +33 -0
  92. package/dist/value-managers/annotations.d.ts.map +1 -0
  93. package/dist/value-managers/annotations.js +192 -0
  94. package/dist/value-managers/annotations.js.map +1 -0
  95. package/dist/value-managers/base.d.ts +53 -0
  96. package/dist/value-managers/base.d.ts.map +1 -0
  97. package/dist/value-managers/base.js +102 -0
  98. package/dist/value-managers/base.js.map +1 -0
  99. package/dist/value-managers/containments.d.ts +58 -0
  100. package/dist/value-managers/containments.d.ts.map +1 -0
  101. package/dist/value-managers/containments.js +408 -0
  102. package/dist/value-managers/containments.js.map +1 -0
  103. package/dist/value-managers/index.d.ts +6 -0
  104. package/dist/value-managers/index.d.ts.map +1 -0
  105. package/dist/value-managers/index.js +22 -0
  106. package/dist/value-managers/index.js.map +1 -0
  107. package/dist/value-managers/properties.d.ts +24 -0
  108. package/dist/value-managers/properties.d.ts.map +1 -0
  109. package/dist/value-managers/properties.js +191 -0
  110. package/dist/value-managers/properties.js.map +1 -0
  111. package/dist/value-managers/references.d.ts +58 -0
  112. package/dist/value-managers/references.d.ts.map +1 -0
  113. package/dist/value-managers/references.js +346 -0
  114. package/dist/value-managers/references.js.map +1 -0
  115. package/package.json +35 -0
  116. package/src/base-types.ts +353 -0
  117. package/src/convenience.ts +101 -0
  118. package/src/deltas/appliers.ts +317 -0
  119. package/src/deltas/base.ts +23 -0
  120. package/src/deltas/handlers.ts +64 -0
  121. package/src/deltas/index.ts +23 -0
  122. package/src/deltas/inverters.ts +111 -0
  123. package/src/deltas/serialization/base.ts +26 -0
  124. package/src/deltas/serialization/deserializer.g.ts +193 -0
  125. package/src/deltas/serialization/index.ts +22 -0
  126. package/src/deltas/serialization/serializer-helpers.ts +36 -0
  127. package/src/deltas/serialization/serializer.g.ts +272 -0
  128. package/src/deltas/serialization/types.g.ts +209 -0
  129. package/src/deltas/types.g.ts +231 -0
  130. package/src/deserializer.ts +234 -0
  131. package/src/duplicator.ts +111 -0
  132. package/src/id-mapping.ts +58 -0
  133. package/src/index.ts +29 -0
  134. package/src/linking.ts +39 -0
  135. package/src/lionCore_builtins.g.ts +141 -0
  136. package/src/serializer.ts +86 -0
  137. package/src/textualizer.ts +104 -0
  138. package/src/value-managers/annotations.ts +139 -0
  139. package/src/value-managers/base.ts +123 -0
  140. package/src/value-managers/containments.ts +323 -0
  141. package/src/value-managers/index.ts +22 -0
  142. package/src/value-managers/properties.ts +127 -0
  143. package/src/value-managers/references.ts +268 -0
@@ -0,0 +1,111 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {asArray, Containment, Feature, Id, idOf, Link, Property, Reference, SingleRef, unresolved} from "@lionweb/core";
19
+
20
+ import {INodeBase} from "./base-types.js";
21
+ import {NodesToInstall} from "./linking.js";
22
+ import {getFeatureValue} from "./serializer.js";
23
+ import {allNodesFrom} from "./convenience.js";
24
+
25
+
26
+ /**
27
+ * Type definition for functions that duplicate a node.
28
+ */
29
+ export type NodeDuplicator = (originalNode: INodeBase) => [duplicatedNode: INodeBase, featuresToDuplicate: Feature[]];
30
+
31
+ /**
32
+ * Type definition for functions that duplicate the (variadically) given nodes.
33
+ */
34
+ export type Duplicator = (...nodes: INodeBase[]) => INodeBase[];
35
+
36
+ /**
37
+ * @return a function that deep-duplicates a given forest of {@link INodeBase nodes}.
38
+ * The result is an array of the deep-duplicated versions of the given nodes *in the same order*.
39
+ *
40
+ * @param duplicateNode a function that returns a – possibly transformed – duplicate of the passed `originalNode`.
41
+ * ***Note***: it's assumed that the classifiers of the original and duplicated nodes coincide exactly!
42
+ */
43
+ export const deepDuplicateWith = (duplicateNode: NodeDuplicator): Duplicator =>
44
+ (...nodes) => {
45
+
46
+ const nodesToInstall: NodesToInstall[] = [];
47
+
48
+ const visit = (node: INodeBase): [id: Id, duplicatedNode: INodeBase] => {
49
+ const [duplicatedNode, featuresToDuplicate] = duplicateNode(node);
50
+ const duplicateFeatureValue = (feature: Feature) => {
51
+ const value = getFeatureValue(node, feature);
52
+ if (feature instanceof Property) {
53
+ duplicatedNode.getPropertyValueManager(feature).setDirectly(value);
54
+ } else if (feature instanceof Link) {
55
+ const values = asArray(value as (SingleRef<INodeBase> | SingleRef<INodeBase>[]));
56
+ const resolvedValues = values.filter((value) => value !== unresolved) as INodeBase[];
57
+ if (resolvedValues.length > 0) {
58
+ nodesToInstall.push([
59
+ duplicatedNode,
60
+ feature,
61
+ resolvedValues.map(idOf),
62
+ feature instanceof Reference
63
+ ? resolvedValues
64
+ : undefined
65
+ ]);
66
+ }
67
+ }
68
+ };
69
+ featuresToDuplicate.forEach(duplicateFeatureValue);
70
+ if (node.annotations.length > 0) {
71
+ nodesToInstall.push([duplicatedNode, null, node.annotations.map(idOf)]);
72
+ }
73
+ return [node.id, duplicatedNode];
74
+ }
75
+
76
+ const duplicatedNodesByOriginalId = Object.fromEntries(
77
+ nodes.flatMap(allNodesFrom).map(visit)
78
+ );
79
+
80
+ nodesToInstall.forEach(([copiedNode, feature, ids, originalReferenceTargets]) => {
81
+ if (feature instanceof Containment) {
82
+ const valueManager = copiedNode.getContainmentValueManager(feature);
83
+ ids.forEach((id) => {
84
+ const nodeToInstall = duplicatedNodesByOriginalId[id];
85
+ valueManager.addDirectly(nodeToInstall);
86
+ nodeToInstall.attachTo(copiedNode, feature);
87
+ });
88
+ return;
89
+ }
90
+ if (feature instanceof Reference) {
91
+ const valueManager = copiedNode.getReferenceValueManager(feature);
92
+ ids.forEach((id, index) => {
93
+ const nodeToInstall = duplicatedNodesByOriginalId[id] ?? originalReferenceTargets![index];
94
+ valueManager.addDirectly(nodeToInstall);
95
+ });
96
+ return;
97
+ }
98
+ if (feature === null) {
99
+ const valueManager = copiedNode.annotationsValueManager;
100
+ ids.forEach((id) => {
101
+ const nodeToInstall = duplicatedNodesByOriginalId[id];
102
+ valueManager.addDirectly(nodeToInstall);
103
+ })
104
+ return;
105
+ }
106
+ });
107
+
108
+ return nodes.map(({id}) => duplicatedNodesByOriginalId[id]);
109
+
110
+ };
111
+
@@ -0,0 +1,58 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {Id, IdOrUnresolved, SingleRef, unresolved} from "@lionweb/core";
19
+
20
+ import {INodeBase} from "./index.js";
21
+
22
+
23
+ type NodesById = { [id: Id]: INodeBase};
24
+
25
+
26
+ /**
27
+ * Maintains a mapping ID &rarr; node,
28
+ * which is primarily used for efficiently applying {@link IDelta deltas}.
29
+ * Instances are produced by the {@link nodeBaseDeserializerWithIdMapping} function.
30
+ */
31
+ export class IdMapping {
32
+
33
+ nodesById: NodesById;
34
+ constructor(nodesById: NodesById) {
35
+ this.nodesById = {...nodesById};
36
+ }
37
+
38
+ fromId(id: Id): INodeBase {
39
+ if (!(id in this.nodesById)) {
40
+ throw new Error(`node with id=${id} not in ID mapping`);
41
+ }
42
+ return this.nodesById[id];
43
+ }
44
+
45
+ fromRefId(idOrUnresolved: IdOrUnresolved): SingleRef<INodeBase> {
46
+ return idOrUnresolved === null
47
+ ? null
48
+ : (this.nodesById[idOrUnresolved] ?? unresolved);
49
+ }
50
+
51
+ updateWith(node: INodeBase) {
52
+ this.nodesById[node.id] = node;
53
+ node.children // recurse into all children
54
+ .forEach((child) => this.updateWith(child));
55
+ }
56
+
57
+ }
58
+
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ export * from "./base-types.js";
19
+ export * from "./convenience.js";
20
+ export * from "./deltas/index.js";
21
+ export * from "./deserializer.js";
22
+ export {deepDuplicateWith} from "./duplicator.js";
23
+ export * from "./id-mapping.js";
24
+ // skip linking.js: see comment there
25
+ export * from "./lionCore_builtins.g.js";
26
+ export {serializeNodeBases} from "./serializer.js";
27
+ export * from "./value-managers/index.js";
28
+ export {asTreeTextWith} from "./textualizer.js";
29
+
package/src/linking.ts ADDED
@@ -0,0 +1,39 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {Id, Link} from "@lionweb/core";
19
+ import {INodeBase} from "./index.js";
20
+
21
+
22
+ /**
23
+ * A tuple type for (data concerning) link and annotation values that are involved with deserialization and deep-duplication
24
+ * — more specifically: nodes that have to be installed on other (deserialized/deep-duplicated) nodes in specific features (or as annotations).
25
+ *
26
+ * The elements are:
27
+ *
28
+ * 1. `parent` — the {@link INodeBase} instance to install on.
29
+ * 2. `feature` — the {@link Link link} feature to install on, or `null` to indicate that it's an annotation.
30
+ * 3. `nodesIds` — are the IDs of the nodes to install.
31
+ * 4. *optional* `originalReferenceTargets` — are the original reference targets of a {@link Reference reference} feature.
32
+ * This element is only present when the feature is a {@link Reference reference} feature.
33
+ * The `nodesIds` and `originalReferenceTargets` match up per index.
34
+ *
35
+ * Note: **DON'T** export this types from the package,
36
+ * as these are only used to align the deserializer and deep-cloner.
37
+ */
38
+ export type NodesToInstall = [ container: INodeBase, feature: Link | null, nodesIds: Id[], originalReferenceTargets?: INodeBase[] ];
39
+
@@ -0,0 +1,141 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ // Warning: this file is generated!
19
+ // Modifying it by hand is useless at best, and sabotage at worst.
20
+
21
+ /*
22
+ * language's metadata:
23
+ * name: LionCore_builtins
24
+ * version: 2023.1
25
+ * key: LionCore-builtins
26
+ * id: LionCore-builtins
27
+ */
28
+
29
+
30
+ import {
31
+ Classifier,
32
+ Concept,
33
+ EnumerationLiteral,
34
+ Id,
35
+ Interface,
36
+ Language,
37
+ PrimitiveType,
38
+ Property
39
+ } from "@lionweb/core";
40
+
41
+ import {
42
+ DeltaHandler,
43
+ ILanguageBase,
44
+ INodeBase,
45
+ NodeBase,
46
+ NodeBaseFactory
47
+ } from "./index.js";
48
+
49
+
50
+ export class LionCore_builtinsBase implements ILanguageBase {
51
+
52
+ private readonly _language: Language = new Language("LionCore_builtins", "2023.1", "LionCore-builtins", "LionCore-builtins");
53
+ get language(): Language {
54
+ this.ensureWiredUp();
55
+ return this._language;
56
+ }
57
+
58
+ public readonly _String = new PrimitiveType(this._language, "String", "LionCore-builtins-String", "LionCore-builtins-String");
59
+ get String(): PrimitiveType {
60
+ this.ensureWiredUp();
61
+ return this._String;
62
+ }
63
+
64
+ public readonly _Boolean = new PrimitiveType(this._language, "Boolean", "LionCore-builtins-Boolean", "LionCore-builtins-Boolean");
65
+ get Boolean(): PrimitiveType {
66
+ this.ensureWiredUp();
67
+ return this._Boolean;
68
+ }
69
+
70
+ public readonly _Integer = new PrimitiveType(this._language, "Integer", "LionCore-builtins-Integer", "LionCore-builtins-Integer");
71
+ get Integer(): PrimitiveType {
72
+ this.ensureWiredUp();
73
+ return this._Integer;
74
+ }
75
+
76
+ public readonly _JSON = new PrimitiveType(this._language, "JSON", "LionCore-builtins-JSON", "LionCore-builtins-JSON");
77
+ get JSON(): PrimitiveType {
78
+ this.ensureWiredUp();
79
+ return this._JSON;
80
+ }
81
+
82
+ public readonly _Node = new Concept(this._language, "Node", "LionCore-builtins-Node", "LionCore-builtins-Node", true);
83
+ get Node(): Concept {
84
+ this.ensureWiredUp();
85
+ return this._Node;
86
+ }
87
+
88
+ public readonly _INamed = new Interface(this._language, "INamed", "LionCore-builtins-INamed", "LionCore-builtins-INamed");
89
+ get INamed(): Interface {
90
+ this.ensureWiredUp();
91
+ return this._INamed;
92
+ }
93
+ private readonly _INamed_name = new Property(this._INamed, "name", "LionCore-builtins-INamed-name", "LionCore-builtins-INamed-name");
94
+ get INamed_name(): Property {
95
+ this.ensureWiredUp();
96
+ return this._INamed_name;
97
+ }
98
+
99
+ private _wiredUp: boolean = false;
100
+ private ensureWiredUp() {
101
+ if (this._wiredUp) {
102
+ return;
103
+ }
104
+ this._language.havingEntities(this._String, this._Boolean, this._Integer, this._JSON, this._Node, this._INamed);
105
+ this._INamed.havingFeatures(this._INamed_name);
106
+ this._INamed_name.ofType(this._String);
107
+ this._wiredUp = true;
108
+ }
109
+
110
+ factory(_handleDelta?: DeltaHandler): NodeBaseFactory {
111
+ return (classifier: Classifier, _id: Id) => {
112
+ const {language} = classifier;
113
+ throw new Error(`can't instantiate ${classifier.name} (key=${classifier.key}): classifier is not known in language ${language.name} (key=${language.key}, version=${language.version})`);
114
+ }
115
+ }
116
+
117
+ enumLiteralFrom<EnumType>(enumerationLiteral: EnumerationLiteral): EnumType {
118
+ const {enumeration} = enumerationLiteral;
119
+ const {language} = enumeration;
120
+ throw new Error(`enumeration with key ${enumeration.key} is not known in language ${language.name} (key=${language.key}, version=${language.version})`);
121
+ }
122
+
123
+ public static readonly INSTANCE = new LionCore_builtinsBase();
124
+ }
125
+
126
+
127
+ export type String = string;
128
+
129
+ export type Boolean = boolean;
130
+
131
+ export type Integer = number;
132
+
133
+ export type JSON = unknown;
134
+
135
+ export abstract class Node extends NodeBase {
136
+ }
137
+
138
+ export interface INamed extends INodeBase {
139
+ name: string;
140
+ }
141
+
@@ -0,0 +1,86 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {
19
+ allSuperTypesOf,
20
+ builtinClassifiers,
21
+ builtinFeatures,
22
+ Containment,
23
+ ExtractionFacade,
24
+ Feature,
25
+ Property,
26
+ Reference,
27
+ serializeNodes
28
+ } from "@lionweb/core";
29
+
30
+ import {INodeBase, LionCore_builtinsBase} from "./index.js";
31
+
32
+
33
+ /**
34
+ * @return the value of the given {@link Feature feature} (2nd argument) on the given node (of type {@link INodeBase}; 1st argument).
35
+ * **Note** that this function is for internal use only!
36
+ */
37
+ export const getFeatureValue = (node: INodeBase, feature: Feature) => {
38
+ if (feature instanceof Property) {
39
+ return node.getPropertyValueManager(feature).getDirectly();
40
+ }
41
+ if (feature instanceof Containment) {
42
+ return node.getContainmentValueManager(feature).getDirectly();
43
+ }
44
+ if (feature instanceof Reference) {
45
+ return node.getReferenceValueManager(feature).getDirectly();
46
+ }
47
+ throw new Error(`unhandled Feature sub type ${feature.constructor.name}`)
48
+ };
49
+
50
+ /**
51
+ * An {@link ExtractionFacade} that works on/for {@link INodeBase}s specifically.
52
+ * **Note** that this function is for internal use only!
53
+ */
54
+ export const nodeBaseReader: ExtractionFacade<INodeBase> = {
55
+ classifierOf: (node) => node.classifier,
56
+ getFeatureValue,
57
+ enumerationLiteralFrom: (encoding, enumeration) => {
58
+ return enumeration.literals.find((literal) => literal.key === encoding)!;
59
+ },
60
+ resolveInfoFor: (node: INodeBase) => {
61
+ if ("name" in node) {
62
+ // evaluating `node.name` might cause an error through FeatureValueManager.throwOnReadOfUnset:
63
+ try {
64
+ const value = node.name;
65
+ return typeof value === "string" ? value : undefined;
66
+ } catch (_) {
67
+ return undefined;
68
+ }
69
+ }
70
+ const allSupertypes = allSuperTypesOf(node.classifier);
71
+ if (allSupertypes.indexOf(builtinClassifiers.inamed) > -1) {
72
+ return node.getPropertyValueManager(builtinFeatures.inamed_name).getDirectly() as (string | undefined);
73
+ }
74
+ if (allSupertypes.indexOf(LionCore_builtinsBase.INSTANCE.INamed) > -1) {
75
+ return node.getPropertyValueManager(LionCore_builtinsBase.INSTANCE.INamed_name).getDirectly() as (string | undefined);
76
+ }
77
+ return undefined;
78
+ }
79
+ };
80
+
81
+ /**
82
+ * @return a serialization of the given nodes (of type {@link INodeBase}) as a {@link SerializationChunk}.
83
+ */
84
+ export const serializeNodeBases = (nodes: INodeBase[]) =>
85
+ serializeNodes(nodes, nodeBaseReader, { serializeEmptyFeatures: false });
86
+
@@ -0,0 +1,104 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import {asString, indentWith, Template} from "littoral-templates"
19
+ import {allFeaturesOf, Containment, Feature, Property, Reference, unresolved} from "@lionweb/core"
20
+
21
+ import {INodeBase} from "./base-types.js";
22
+ import {LionCore_builtinsBase} from "./lionCore_builtins.g.js";
23
+
24
+
25
+ const indent = indentWith(" ")(1)
26
+
27
+ const prependWith = (template: Template, prefix: string): Template =>
28
+ prefix + asString(template)
29
+
30
+
31
+ type INodeBaseOrNotThere = INodeBase | typeof unresolved | undefined
32
+
33
+ const asINodeBases = (value: INodeBaseOrNotThere | INodeBaseOrNotThere[]): INodeBase[] => {
34
+ const isINodeBase = (value: INodeBaseOrNotThere): value is INodeBase =>
35
+ !(value === unresolved || value === undefined)
36
+
37
+ if (Array.isArray(value)) {
38
+ return value
39
+ .filter((subValue) => isINodeBase(subValue))
40
+ .map((subValue) => subValue as INodeBase)
41
+ }
42
+ return isINodeBase(value) ? [value] : []
43
+ }
44
+
45
+
46
+ /**
47
+ * @return a function that renders the roots of a given forest of {@link INodeBase nodes} in a textual tree-representation.
48
+ * @param identificationFor a function that renders an identification for the given {@link INodeBase node} — typically its name or its ID.
49
+ */
50
+ export const asTreeTextWith = (identificationFor: (node: INodeBase) => string): ((nodes: INodeBase[]) => string) => {
51
+
52
+ const asText = (node: INodeBase): Template => {
53
+ const featureValueAsText = (feature: Feature) => {
54
+ if (feature instanceof Property) {
55
+ const valueManager = node.getPropertyValueManager(feature)
56
+ const displayValue = (() => {
57
+ if (!valueManager.isSet()) {
58
+ return `$<not set>`
59
+ }
60
+ const value = valueManager.getDirectly()
61
+ if (feature.type === LionCore_builtinsBase.INSTANCE.String) {
62
+ return `"${value}"`
63
+ }
64
+ return value
65
+ })()
66
+ return `${feature.name} = ${displayValue}`
67
+ }
68
+ if (feature instanceof Containment) {
69
+ const valueManager = node.getContainmentValueManager(feature)
70
+ const children = asINodeBases(valueManager.getDirectly())
71
+ return [
72
+ `${feature.name}:${children.length === 0 ? " <nothing>" : ""}`,
73
+ indent(children.map(asText))
74
+ ]
75
+ }
76
+ if (feature instanceof Reference) {
77
+ const valueManager= node.getReferenceValueManager(feature)
78
+ const references = asINodeBases(valueManager.getDirectly())
79
+ return [
80
+ `${feature.name} -> ${references.length === 0 ? "<none>" : references.map(identificationFor).join(", ")}`
81
+ ]
82
+ }
83
+ return `!!! can't handle feature ${feature.name} (of meta type ${feature.metaType()})`
84
+ }
85
+
86
+ const annotationAsText = (annotation: INodeBase) =>
87
+ prependWith(asText(annotation), "@ ")
88
+
89
+ return [
90
+ `${node.classifier.name} (id: ${node.id})`,
91
+ indent([
92
+ allFeaturesOf(node.classifier).map(featureValueAsText),
93
+ node.annotations.map(annotationAsText)
94
+ ])
95
+ ]
96
+ }
97
+
98
+ return (nodes: INodeBase[]) => asString(
99
+ nodes
100
+ .filter((node) => node.parent === undefined) // root nodes
101
+ .map(asText)
102
+ )
103
+ }
104
+