@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,209 @@
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
+ import {Id, IdOrUnresolved, MetaPointer, SerializationChunk} from "@lionweb/core";
22
+
23
+
24
+ export type SerializedDelta =
25
+ | NoOpSerializedDelta
26
+ | PropertyAddedSerializedDelta
27
+ | PropertyDeletedSerializedDelta
28
+ | PropertyChangedSerializedDelta
29
+ | ChildAddedSerializedDelta
30
+ | ChildDeletedSerializedDelta
31
+ | ChildReplacedSerializedDelta
32
+ | ChildMovedSerializedDelta
33
+ | ChildMovedInSameContainmentSerializedDelta
34
+ | ReferenceAddedSerializedDelta
35
+ | ReferenceDeletedSerializedDelta
36
+ | ReferenceReplacedSerializedDelta
37
+ | ReferenceMovedSerializedDelta
38
+ | ReferenceMovedInSameReferenceSerializedDelta
39
+ | AnnotationAddedSerializedDelta
40
+ | AnnotationDeletedSerializedDelta
41
+ | AnnotationReplacedSerializedDelta
42
+ | AnnotationMovedFromOtherParentSerializedDelta
43
+ | AnnotationMovedInSameParentSerializedDelta
44
+ ;
45
+
46
+
47
+ export type NoOpSerializedDelta = {
48
+ kind: "NoOp"
49
+ }
50
+
51
+ export type PropertyAddedSerializedDelta = {
52
+ kind: "PropertyAdded"
53
+ container: Id
54
+ property: MetaPointer
55
+ value: string
56
+ }
57
+
58
+ export type PropertyDeletedSerializedDelta = {
59
+ kind: "PropertyDeleted"
60
+ container: Id
61
+ property: MetaPointer
62
+ oldValue: string
63
+ }
64
+
65
+ export type PropertyChangedSerializedDelta = {
66
+ kind: "PropertyChanged"
67
+ container: Id
68
+ property: MetaPointer
69
+ oldValue: string
70
+ newValue: string
71
+ }
72
+
73
+ export type ChildAddedSerializedDelta = {
74
+ kind: "ChildAdded"
75
+ parent: Id
76
+ containment: MetaPointer
77
+ index: number
78
+ newChild: Id
79
+ newNodes: SerializationChunk
80
+ }
81
+
82
+ export type ChildDeletedSerializedDelta = {
83
+ kind: "ChildDeleted"
84
+ parent: Id
85
+ containment: MetaPointer
86
+ index: number
87
+ deletedChild: Id
88
+ deletedNodes: SerializationChunk
89
+ }
90
+
91
+ export type ChildReplacedSerializedDelta = {
92
+ kind: "ChildReplaced"
93
+ parent: Id
94
+ containment: MetaPointer
95
+ index: number
96
+ replacedChild: Id
97
+ replacedNodes: SerializationChunk
98
+ newChild: Id
99
+ newNodes: SerializationChunk
100
+ }
101
+
102
+ export type ChildMovedSerializedDelta = {
103
+ kind: "ChildMoved"
104
+ oldParent: Id
105
+ oldContainment: MetaPointer
106
+ oldIndex: number
107
+ newParent: Id
108
+ newContainment: MetaPointer
109
+ newIndex: number
110
+ child: Id
111
+ }
112
+
113
+ export type ChildMovedInSameContainmentSerializedDelta = {
114
+ kind: "ChildMovedInSameContainment"
115
+ parent: Id
116
+ containment: MetaPointer
117
+ oldIndex: number
118
+ newIndex: number
119
+ child: Id
120
+ }
121
+
122
+ export type ReferenceAddedSerializedDelta = {
123
+ kind: "ReferenceAdded"
124
+ container: Id
125
+ reference: MetaPointer
126
+ index: number
127
+ newTarget: IdOrUnresolved
128
+ }
129
+
130
+ export type ReferenceDeletedSerializedDelta = {
131
+ kind: "ReferenceDeleted"
132
+ container: Id
133
+ reference: MetaPointer
134
+ index: number
135
+ deletedTarget: IdOrUnresolved
136
+ }
137
+
138
+ export type ReferenceReplacedSerializedDelta = {
139
+ kind: "ReferenceReplaced"
140
+ container: Id
141
+ reference: MetaPointer
142
+ index: number
143
+ replacedTarget: IdOrUnresolved
144
+ newTarget: IdOrUnresolved
145
+ }
146
+
147
+ export type ReferenceMovedSerializedDelta = {
148
+ kind: "ReferenceMoved"
149
+ oldContainer: Id
150
+ oldReference: MetaPointer
151
+ oldIndex: number
152
+ newContainer: Id
153
+ newReference: MetaPointer
154
+ newIndex: number
155
+ target: IdOrUnresolved
156
+ }
157
+
158
+ export type ReferenceMovedInSameReferenceSerializedDelta = {
159
+ kind: "ReferenceMovedInSameReference"
160
+ container: Id
161
+ reference: MetaPointer
162
+ oldIndex: number
163
+ newIndex: number
164
+ target: IdOrUnresolved
165
+ }
166
+
167
+ export type AnnotationAddedSerializedDelta = {
168
+ kind: "AnnotationAdded"
169
+ parent: Id
170
+ index: number
171
+ newAnnotation: Id
172
+ newAnnotationNodes: SerializationChunk
173
+ }
174
+
175
+ export type AnnotationDeletedSerializedDelta = {
176
+ kind: "AnnotationDeleted"
177
+ parent: Id
178
+ index: number
179
+ deletedAnnotation: Id
180
+ deletedAnnotationNodes: SerializationChunk
181
+ }
182
+
183
+ export type AnnotationReplacedSerializedDelta = {
184
+ kind: "AnnotationReplaced"
185
+ parent: Id
186
+ index: number
187
+ replacedAnnotation: Id
188
+ replacedAnnotationNodes: SerializationChunk
189
+ newAnnotation: Id
190
+ newAnnotationNodes: SerializationChunk
191
+ }
192
+
193
+ export type AnnotationMovedFromOtherParentSerializedDelta = {
194
+ kind: "AnnotationMovedFromOtherParent"
195
+ oldParent: Id
196
+ oldIndex: number
197
+ newParent: Id
198
+ newIndex: number
199
+ movedAnnotation: Id
200
+ }
201
+
202
+ export type AnnotationMovedInSameParentSerializedDelta = {
203
+ kind: "AnnotationMovedInSameParent"
204
+ parent: Id
205
+ oldIndex: number
206
+ newIndex: number
207
+ movedAnnotation: Id
208
+ }
209
+
@@ -0,0 +1,231 @@
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
+ import {
22
+ Containment,
23
+ Property,
24
+ Reference,
25
+ SingleRef
26
+ } from "@lionweb/core";
27
+
28
+ import {INodeBase} from "../base-types.js";
29
+ import {IDelta} from "./base.js";
30
+
31
+
32
+ /**
33
+ * Delta that does nothing.
34
+ * Warning: should only be used for development purposes!
35
+ */
36
+ export class NoOpDelta implements IDelta {
37
+ }
38
+
39
+ export class PropertyAddedDelta<T> implements IDelta {
40
+ constructor(
41
+ public readonly container: INodeBase,
42
+ public readonly property: Property,
43
+ public readonly value: T
44
+ ) {
45
+ }
46
+ }
47
+
48
+ export class PropertyDeletedDelta<T> implements IDelta {
49
+ constructor(
50
+ public readonly container: INodeBase,
51
+ public readonly property: Property,
52
+ public readonly oldValue: T
53
+ ) {
54
+ }
55
+ }
56
+
57
+ export class PropertyChangedDelta<T> implements IDelta {
58
+ constructor(
59
+ public readonly container: INodeBase,
60
+ public readonly property: Property,
61
+ public readonly oldValue: T,
62
+ public readonly newValue: T
63
+ ) {
64
+ }
65
+ }
66
+
67
+ export class ChildAddedDelta implements IDelta {
68
+ constructor(
69
+ public readonly parent: INodeBase,
70
+ public readonly containment: Containment,
71
+ public readonly index: number,
72
+ public readonly newChild: INodeBase
73
+ ) {
74
+ }
75
+ }
76
+
77
+ export class ChildDeletedDelta implements IDelta {
78
+ constructor(
79
+ public readonly parent: INodeBase,
80
+ public readonly containment: Containment,
81
+ public readonly index: number,
82
+ public readonly deletedChild: INodeBase
83
+ ) {
84
+ }
85
+ }
86
+
87
+ export class ChildReplacedDelta implements IDelta {
88
+ constructor(
89
+ public readonly parent: INodeBase,
90
+ public readonly containment: Containment,
91
+ public readonly index: number,
92
+ public readonly replacedChild: INodeBase,
93
+ public readonly newChild: INodeBase
94
+ ) {
95
+ }
96
+ }
97
+
98
+ export class ChildMovedDelta implements IDelta {
99
+ constructor(
100
+ public readonly oldParent: INodeBase,
101
+ public readonly oldContainment: Containment,
102
+ public readonly oldIndex: number,
103
+ public readonly newParent: INodeBase,
104
+ public readonly newContainment: Containment,
105
+ public readonly newIndex: number,
106
+ public readonly child: INodeBase
107
+ ) {
108
+ }
109
+ }
110
+
111
+ export class ChildMovedInSameContainmentDelta implements IDelta {
112
+ constructor(
113
+ public readonly parent: INodeBase,
114
+ public readonly containment: Containment,
115
+ public readonly oldIndex: number,
116
+ public readonly newIndex: number,
117
+ public readonly child: INodeBase
118
+ ) {
119
+ }
120
+ }
121
+
122
+ export class ReferenceAddedDelta implements IDelta {
123
+ constructor(
124
+ public readonly container: INodeBase,
125
+ public readonly reference: Reference,
126
+ public readonly index: number,
127
+ public readonly newTarget: SingleRef<INodeBase>
128
+ ) {
129
+ }
130
+ }
131
+
132
+ export class ReferenceDeletedDelta implements IDelta {
133
+ constructor(
134
+ public readonly container: INodeBase,
135
+ public readonly reference: Reference,
136
+ public readonly index: number,
137
+ public readonly deletedTarget: SingleRef<INodeBase>
138
+ ) {
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Note: corresponds to "reference changed" in delta proposal!
144
+ */
145
+ export class ReferenceReplacedDelta implements IDelta {
146
+ constructor(
147
+ public readonly container: INodeBase,
148
+ public readonly reference: Reference,
149
+ public readonly index: number,
150
+ public readonly replacedTarget: SingleRef<INodeBase>,
151
+ public readonly newTarget: SingleRef<INodeBase>
152
+ ) {
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Note: corresponds to "entry moved from other reference" in delta proposal!
158
+ */
159
+ export class ReferenceMovedDelta implements IDelta {
160
+ constructor(
161
+ public readonly oldContainer: INodeBase,
162
+ public readonly oldReference: Reference,
163
+ public readonly oldIndex: number,
164
+ public readonly newContainer: INodeBase,
165
+ public readonly newReference: Reference,
166
+ public readonly newIndex: number,
167
+ public readonly target: SingleRef<INodeBase>
168
+ ) {
169
+ }
170
+ }
171
+
172
+ export class ReferenceMovedInSameReferenceDelta implements IDelta {
173
+ constructor(
174
+ public readonly container: INodeBase,
175
+ public readonly reference: Reference,
176
+ public readonly oldIndex: number,
177
+ public readonly newIndex: number,
178
+ public readonly target: SingleRef<INodeBase>
179
+ ) {
180
+ }
181
+ }
182
+
183
+ export class AnnotationAddedDelta implements IDelta {
184
+ constructor(
185
+ public readonly parent: INodeBase,
186
+ public readonly index: number,
187
+ public readonly newAnnotation: INodeBase
188
+ ) {
189
+ }
190
+ }
191
+
192
+ export class AnnotationDeletedDelta implements IDelta {
193
+ constructor(
194
+ public readonly parent: INodeBase,
195
+ public readonly index: number,
196
+ public readonly deletedAnnotation: INodeBase
197
+ ) {
198
+ }
199
+ }
200
+
201
+ export class AnnotationReplacedDelta implements IDelta {
202
+ constructor(
203
+ public readonly parent: INodeBase,
204
+ public readonly index: number,
205
+ public readonly replacedAnnotation: INodeBase,
206
+ public readonly newAnnotation: INodeBase
207
+ ) {
208
+ }
209
+ }
210
+
211
+ export class AnnotationMovedFromOtherParentDelta implements IDelta {
212
+ constructor(
213
+ public readonly oldParent: INodeBase,
214
+ public readonly oldIndex: number,
215
+ public readonly newParent: INodeBase,
216
+ public readonly newIndex: number,
217
+ public readonly movedAnnotation: INodeBase
218
+ ) {
219
+ }
220
+ }
221
+
222
+ export class AnnotationMovedInSameParentDelta implements IDelta {
223
+ constructor(
224
+ public readonly parent: INodeBase,
225
+ public readonly oldIndex: number,
226
+ public readonly newIndex: number,
227
+ public readonly movedAnnotation: INodeBase
228
+ ) {
229
+ }
230
+ }
231
+
@@ -0,0 +1,234 @@
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
+ byIdMap,
20
+ Classifier,
21
+ Containment,
22
+ DefaultPrimitiveTypeDeserializer,
23
+ defaultSimplisticHandler,
24
+ Enumeration,
25
+ Id,
26
+ Language,
27
+ MemoisingSymbolTable,
28
+ PrimitiveType,
29
+ PrimitiveTypeDeserializer,
30
+ Property,
31
+ Reference,
32
+ SerializationChunk,
33
+ SerializedNode,
34
+ SimplisticHandler,
35
+ unresolved
36
+ } from "@lionweb/core";
37
+
38
+ import {DeltaHandler, IdMapping, ILanguageBase, INodeBase} from "./index.js";
39
+ import {NodesToInstall} from "./linking.js";
40
+
41
+
42
+ /**
43
+ * A type for deserializer functions that are parametrized in their return type.
44
+ */
45
+ export type Deserializer<T> = (
46
+ serializationChunk: SerializationChunk,
47
+ dependentNodes?: INodeBase[],
48
+ primitiveTypeDeserializer?: PrimitiveTypeDeserializer,
49
+ problemHandler?: SimplisticHandler
50
+ ) => T;
51
+
52
+
53
+ const languageBaseLookupFor = (languageBases: ILanguageBase[]) =>
54
+ (language: Language) => {
55
+ const languageBase = languageBases.find((languageBase) => languageBase.language === language);
56
+ if (languageBase === undefined) {
57
+ throw new Error(`language ${language.name} (with key=${language.key} and version=${language.version}) not known`);
58
+ }
59
+ return languageBase;
60
+ };
61
+
62
+ const factoryLookupFor = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler) => {
63
+ const lookup = languageBaseLookupFor(languageBases);
64
+ return (language: Language) => lookup(language).factory(handleDelta);
65
+ }
66
+
67
+
68
+ /**
69
+ * A quasi-tuple of the roots (of type {@link INodeBase}) of a model,
70
+ * and its {@link IdMapping} instance.
71
+ */
72
+ export type RootsWithIdMapping = { roots: INodeBase[], idMapping: IdMapping };
73
+
74
+
75
+ /**
76
+ * @return a {@link Deserializer} function for the given languages (given as {@link ILanguageBase}s) that returns a {@link RootsWithIdMapping}.
77
+ * @param languageBases the {@link ILanguageBase}s for (at least) all the languages used in the {@link SerializationChunk} to deserialize, minus LionCore M3 and built-ins.
78
+ * @param handleDelta an optional {@link DeltaHandler} that will be injected in all {@link INodeBase nodes} created.
79
+ */
80
+ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): Deserializer<RootsWithIdMapping> => {
81
+
82
+ const symbolTable = new MemoisingSymbolTable(languageBases.map(({language}) => language));
83
+ const languageBaseFor = languageBaseLookupFor(languageBases);
84
+ const factoryFor = factoryLookupFor(languageBases, handleDelta);
85
+
86
+ return (
87
+ serializationChunk: SerializationChunk,
88
+ dependentNodes: INodeBase[] = [],
89
+ primitiveTypeDeserializer: PrimitiveTypeDeserializer = new DefaultPrimitiveTypeDeserializer(),
90
+ problemsHandler: SimplisticHandler = defaultSimplisticHandler
91
+ ): RootsWithIdMapping => {
92
+
93
+ const nodesToInstall: NodesToInstall[] = [];
94
+
95
+ const createNode = ({id, classifier: classifierMetaPointer, properties, containments, references, annotations}: SerializedNode) => {
96
+ const languageMessage = `language ${classifierMetaPointer.language} (${classifierMetaPointer.version})`;
97
+ const classifier = symbolTable.entityMatching(classifierMetaPointer);
98
+ if (classifier === undefined || !(classifier instanceof Classifier)) {
99
+ problemsHandler.reportProblem(`can't deserialize node with id=${id}: can't find the classifier with key ${classifierMetaPointer.key} in ${languageMessage} - skipping`);
100
+ return undefined;
101
+ }
102
+
103
+ const node = factoryFor(classifier.language)(classifier, id);
104
+
105
+ properties.forEach(({property: propertyMetaPointer, value}) => {
106
+ const feature = symbolTable.featureMatching(classifierMetaPointer, propertyMetaPointer);
107
+ if (feature === undefined) {
108
+ problemsHandler.reportProblem(`can't deserialize value for feature with key ${propertyMetaPointer.key} in ${languageMessage}: feature not found on classifier ${classifierMetaPointer.key} in language (${classifierMetaPointer.language}, ${classifierMetaPointer.version}) - skipping`);
109
+ } else if (feature instanceof Property) {
110
+ if (feature.type instanceof PrimitiveType) {
111
+ node.getPropertyValueManager(feature).setDirectly(value === null ? undefined : primitiveTypeDeserializer.deserializeValue(value, feature));
112
+ } else if (feature.type instanceof Enumeration) {
113
+ if (value !== undefined) {
114
+ const literal = feature.type.literals.find((literal) => literal.key === value);
115
+ if (literal === undefined) {
116
+ problemsHandler.reportProblem(`can't deserialize literal encoded as: ${value}`);
117
+ } else {
118
+ node.getPropertyValueManager(feature).setDirectly(languageBaseFor(feature.type.language).enumLiteralFrom(literal));
119
+ }
120
+ }
121
+ }
122
+ } else {
123
+ problemsHandler.reportProblem(`can't deserialize value for feature with key ${propertyMetaPointer.key} in ${languageMessage}: feature is not a property - skipping`);
124
+ }
125
+ });
126
+
127
+ containments.forEach(({containment: containmentMetaPointer, children}) => {
128
+ const feature = symbolTable.featureMatching(classifierMetaPointer, containmentMetaPointer);
129
+ if (feature === undefined) {
130
+ problemsHandler.reportProblem(`can't deserialize value for feature with key ${containmentMetaPointer.key} in ${languageMessage}: feature not found on classifier ${classifierMetaPointer.key} in language (${classifierMetaPointer.language}, ${classifierMetaPointer.version}) - skipping`);
131
+ } else if (feature instanceof Containment) {
132
+ nodesToInstall.push([node, feature, children]);
133
+ } else {
134
+ problemsHandler.reportProblem(`can't deserialize value for feature with key ${containmentMetaPointer.key} in ${languageMessage}: feature is not a containment - skipping`);
135
+ }
136
+ });
137
+
138
+ references.forEach(({reference: referenceMetaPointer, targets}) => {
139
+ const feature = symbolTable.featureMatching(classifierMetaPointer, referenceMetaPointer);
140
+ if (feature === undefined) {
141
+ problemsHandler.reportProblem(`can't deserialize value for feature with key ${referenceMetaPointer.key} in ${languageMessage}: feature not found on classifier ${classifierMetaPointer.key} in language (${classifierMetaPointer.language}, ${classifierMetaPointer.version}) - skipping`);
142
+ } else if (feature instanceof Reference) {
143
+ nodesToInstall.push([node, feature, targets.map(({reference}) => reference)]);
144
+ } else {
145
+ problemsHandler.reportProblem(`can't deserialize value for feature with key ${referenceMetaPointer.key} in ${languageMessage}: feature is not a reference - skipping`);
146
+ }
147
+ });
148
+
149
+ if (annotations.length > 0) {
150
+ nodesToInstall.push([node, null, annotations]);
151
+ }
152
+
153
+ return node;
154
+ };
155
+
156
+ const nodesById = byIdMap(
157
+ serializationChunk.nodes
158
+ .map(createNode)
159
+ .filter((nodeOrUndef) => nodeOrUndef !== undefined) as INodeBase[]
160
+ );
161
+
162
+ const dependentNodesById = byIdMap(dependentNodes)
163
+
164
+ const lookupNodeById = (id: Id) =>
165
+ nodesById[id] ?? dependentNodesById[id];
166
+
167
+ nodesToInstall.forEach(([node, feature, ids]) => {
168
+ if (feature instanceof Containment) {
169
+ const valueManager = node.getContainmentValueManager(feature);
170
+ ids.forEach((id) => {
171
+ const nodeToInstall = lookupNodeById(id);
172
+ if (nodeToInstall === undefined) {
173
+ problemsHandler.reportProblem(`couldn't resolve the child with id=${id} of the "${feature.name}" containment feature on the node with id=${node.id}`);
174
+ } else {
175
+ valueManager.addDirectly(nodeToInstall);
176
+ nodeToInstall.attachTo(node, feature);
177
+ }
178
+ });
179
+ return;
180
+ }
181
+ if (feature instanceof Reference) {
182
+ const valueManager = node.getReferenceValueManager(feature);
183
+ ids.forEach((id) => {
184
+ const nodeToInstall = lookupNodeById(id);
185
+ if (nodeToInstall === undefined) {
186
+ problemsHandler.reportProblem(`couldn't resolve the target with id=${id} of the "${feature.name}" reference feature on the node with id=${node.id}`);
187
+ valueManager.addDirectly(unresolved);
188
+ } else {
189
+ valueManager.addDirectly(nodeToInstall);
190
+ }
191
+ });
192
+ return;
193
+ }
194
+ if (feature === null) {
195
+ const valueManager = node.annotationsValueManager;
196
+ ids.forEach((id) => {
197
+ const nodeToInstall = lookupNodeById(id);
198
+ if (nodeToInstall === undefined) {
199
+ problemsHandler.reportProblem(`couldn't resolve the annotation with id=${id} on the node with id=${node.id}`);
200
+ } else {
201
+ valueManager.addDirectly(nodeToInstall);
202
+ nodeToInstall.attachTo(node, feature);
203
+ }
204
+ });
205
+ return;
206
+ }
207
+ });
208
+
209
+ return {
210
+ roots: Object.values(nodesById)
211
+ .filter(({parent}) => parent === undefined),
212
+ idMapping: new IdMapping({ ...nodesById, ...dependentNodesById })
213
+ };
214
+
215
+ };
216
+ };
217
+
218
+
219
+ /**
220
+ * @return a {@link Deserializer} function for the languages (given as {@link ILanguageBase}s) that returns the roots (of type {@link INodeBase}) of the deserialized model.
221
+ * @param languageBases the {@link ILanguageBase}s for (at least) all the languages used in the {@link SerializationChunk} to deserialize, minus LionCore M3 and built-ins.
222
+ * @param handleDelta an optional {@link DeltaHandler} that will be injected in all {@link INodeBase nodes} created.
223
+ */
224
+ export const nodeBaseDeserializer = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): Deserializer<INodeBase[]> => {
225
+ const deserializerWithIdMapping = nodeBaseDeserializerWithIdMapping(languageBases, handleDelta);
226
+ return (
227
+ serializationChunk: SerializationChunk,
228
+ dependentNodes: INodeBase[] = [],
229
+ primitiveTypeDeserializer: PrimitiveTypeDeserializer = new DefaultPrimitiveTypeDeserializer(),
230
+ problemsHandler: SimplisticHandler = defaultSimplisticHandler
231
+ ): INodeBase[] =>
232
+ deserializerWithIdMapping(serializationChunk, dependentNodes, primitiveTypeDeserializer, problemsHandler).roots
233
+ }
234
+