@lionweb/class-core 0.6.13-beta.7 → 0.7.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +1 -1
- package/dist/{lionCore_builtins.g.d.ts → LionCore_builtins.g.d.ts} +1 -1
- package/dist/{lionCore_builtins.g.d.ts.map → LionCore_builtins.g.d.ts.map} +1 -1
- package/dist/{lionCore_builtins.g.js → LionCore_builtins.g.js} +1 -1
- package/dist/{lionCore_builtins.g.js.map → LionCore_builtins.g.js.map} +1 -1
- package/dist/base-types.d.ts +5 -4
- package/dist/base-types.d.ts.map +1 -1
- package/dist/base-types.js +1 -1
- package/dist/base-types.js.map +1 -1
- package/dist/convenience.d.ts +4 -3
- package/dist/convenience.d.ts.map +1 -1
- package/dist/convenience.js.map +1 -1
- package/dist/deltas/appliers.d.ts.map +1 -1
- package/dist/deltas/appliers.js.map +1 -1
- package/dist/deltas/handlers.d.ts.map +1 -1
- package/dist/deltas/handlers.js.map +1 -1
- package/dist/deltas/inverters.d.ts.map +1 -1
- package/dist/deltas/inverters.js.map +1 -1
- package/dist/deltas/serialization/base.d.ts +1 -1
- package/dist/deltas/serialization/base.d.ts.map +1 -1
- package/dist/deltas/serialization/deserializer.g.d.ts.map +1 -1
- package/dist/deltas/serialization/deserializer.g.js.map +1 -1
- package/dist/deltas/serialization/serializer-helpers.d.ts +1 -1
- package/dist/deltas/serialization/serializer-helpers.d.ts.map +1 -1
- package/dist/deltas/serialization/serializer-helpers.js +4 -4
- package/dist/deltas/serialization/serializer-helpers.js.map +1 -1
- package/dist/deltas/serialization/serializer.g.d.ts.map +1 -1
- package/dist/deltas/serialization/serializer.g.js.map +1 -1
- package/dist/deltas/serialization/types.g.d.ts +58 -57
- package/dist/deltas/serialization/types.g.d.ts.map +1 -1
- package/dist/deltas/types.g.d.ts.map +1 -1
- package/dist/deserializer.d.ts +5 -4
- package/dist/deserializer.d.ts.map +1 -1
- package/dist/deserializer.js +7 -6
- package/dist/deserializer.js.map +1 -1
- package/dist/duplicator.d.ts.map +1 -1
- package/dist/duplicator.js +3 -2
- package/dist/duplicator.js.map +1 -1
- package/dist/factory.d.ts +7 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +44 -0
- package/dist/factory.js.map +1 -0
- package/dist/id-mapping.d.ts +5 -4
- package/dist/id-mapping.d.ts.map +1 -1
- package/dist/id-mapping.js +2 -3
- package/dist/id-mapping.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/linking.d.ts +3 -2
- package/dist/linking.d.ts.map +1 -1
- package/dist/serializer.d.ts +5 -5
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +4 -4
- package/dist/serializer.js.map +1 -1
- package/dist/textualizer.d.ts.map +1 -1
- package/dist/textualizer.js +2 -2
- package/dist/textualizer.js.map +1 -1
- package/dist/value-managers/annotations.d.ts.map +1 -1
- package/dist/value-managers/annotations.js.map +1 -1
- package/dist/value-managers/base.d.ts.map +1 -1
- package/dist/value-managers/base.js.map +1 -1
- package/dist/value-managers/containments.d.ts.map +1 -1
- package/dist/value-managers/containments.js +1 -1
- package/dist/value-managers/containments.js.map +1 -1
- package/dist/value-managers/properties.d.ts +1 -1
- package/dist/value-managers/properties.d.ts.map +1 -1
- package/dist/value-managers/properties.js +1 -1
- package/dist/value-managers/properties.js.map +1 -1
- package/dist/value-managers/references.d.ts.map +1 -1
- package/dist/value-managers/references.js +1 -1
- package/dist/value-managers/references.js.map +1 -1
- package/package.json +14 -10
- package/src/{lionCore_builtins.g.ts → LionCore_builtins.g.ts} +5 -2
- package/src/base-types.ts +6 -6
- package/src/convenience.ts +6 -9
- package/src/deltas/appliers.ts +6 -6
- package/src/deltas/handlers.ts +2 -2
- package/src/deltas/inverters.ts +2 -2
- package/src/deltas/serialization/base.ts +2 -2
- package/src/deltas/serialization/deserializer.g.ts +5 -5
- package/src/deltas/serialization/serializer-helpers.ts +11 -6
- package/src/deltas/serialization/serializer.g.ts +4 -4
- package/src/deltas/serialization/types.g.ts +58 -57
- package/src/deltas/types.g.ts +2 -2
- package/src/deserializer.ts +19 -21
- package/src/duplicator.ts +8 -6
- package/src/factory.ts +49 -0
- package/src/id-mapping.ts +8 -9
- package/src/index.ts +4 -3
- package/src/linking.ts +4 -3
- package/src/serializer.ts +9 -10
- package/src/textualizer.ts +4 -5
- package/src/value-managers/annotations.ts +4 -4
- package/src/value-managers/base.ts +3 -3
- package/src/value-managers/containments.ts +6 -12
- package/src/value-managers/properties.ts +5 -5
- package/src/value-managers/references.ts +6 -11
- package/dist/utils.d.ts +0 -6
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -22
- package/dist/utils.js.map +0 -1
- package/src/utils.ts +0 -24
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
// Warning: this file is generated!
|
|
19
19
|
// Modifying it by hand is useless at best, and sabotage at worst.
|
|
20
20
|
|
|
21
|
-
import {metaPointerFor} from "@lionweb/core";
|
|
22
|
-
import {IDelta} from "../base.js";
|
|
21
|
+
import { metaPointerFor } from "@lionweb/core";
|
|
22
|
+
import { IDelta } from "../base.js";
|
|
23
23
|
import {
|
|
24
24
|
AnnotationAddedDelta,
|
|
25
25
|
AnnotationDeletedDelta,
|
|
@@ -62,8 +62,8 @@ import {
|
|
|
62
62
|
ReferenceMovedSerializedDelta,
|
|
63
63
|
ReferenceReplacedSerializedDelta
|
|
64
64
|
} from "./types.g.js";
|
|
65
|
-
import {idFrom, serializePropertyValue} from "./serializer-helpers.js";
|
|
66
|
-
import {serializeNodeBases} from "../../serializer.js";
|
|
65
|
+
import { idFrom, serializePropertyValue } from "./serializer-helpers.js";
|
|
66
|
+
import { serializeNodeBases } from "../../serializer.js";
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
export const serializeDelta = (delta: IDelta) => {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
// Warning: this file is generated!
|
|
19
19
|
// Modifying it by hand is useless at best, and sabotage at worst.
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import { IdOrUnresolved } from "@lionweb/core";
|
|
22
|
+
import { LionWebId, LionWebJsonMetaPointer, LionWebJsonChunk } from "@lionweb/json";
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
export type SerializedDelta =
|
|
@@ -50,95 +51,95 @@ export type NoOpSerializedDelta = {
|
|
|
50
51
|
|
|
51
52
|
export type PropertyAddedSerializedDelta = {
|
|
52
53
|
kind: "PropertyAdded"
|
|
53
|
-
container:
|
|
54
|
-
property:
|
|
54
|
+
container: LionWebId
|
|
55
|
+
property: LionWebJsonMetaPointer
|
|
55
56
|
value: string
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
export type PropertyDeletedSerializedDelta = {
|
|
59
60
|
kind: "PropertyDeleted"
|
|
60
|
-
container:
|
|
61
|
-
property:
|
|
61
|
+
container: LionWebId
|
|
62
|
+
property: LionWebJsonMetaPointer
|
|
62
63
|
oldValue: string
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export type PropertyChangedSerializedDelta = {
|
|
66
67
|
kind: "PropertyChanged"
|
|
67
|
-
container:
|
|
68
|
-
property:
|
|
68
|
+
container: LionWebId
|
|
69
|
+
property: LionWebJsonMetaPointer
|
|
69
70
|
oldValue: string
|
|
70
71
|
newValue: string
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
export type ChildAddedSerializedDelta = {
|
|
74
75
|
kind: "ChildAdded"
|
|
75
|
-
parent:
|
|
76
|
-
containment:
|
|
76
|
+
parent: LionWebId
|
|
77
|
+
containment: LionWebJsonMetaPointer
|
|
77
78
|
index: number
|
|
78
|
-
newChild:
|
|
79
|
-
newNodes:
|
|
79
|
+
newChild: LionWebId
|
|
80
|
+
newNodes: LionWebJsonChunk
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
export type ChildDeletedSerializedDelta = {
|
|
83
84
|
kind: "ChildDeleted"
|
|
84
|
-
parent:
|
|
85
|
-
containment:
|
|
85
|
+
parent: LionWebId
|
|
86
|
+
containment: LionWebJsonMetaPointer
|
|
86
87
|
index: number
|
|
87
|
-
deletedChild:
|
|
88
|
-
deletedNodes:
|
|
88
|
+
deletedChild: LionWebId
|
|
89
|
+
deletedNodes: LionWebJsonChunk
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
export type ChildReplacedSerializedDelta = {
|
|
92
93
|
kind: "ChildReplaced"
|
|
93
|
-
parent:
|
|
94
|
-
containment:
|
|
94
|
+
parent: LionWebId
|
|
95
|
+
containment: LionWebJsonMetaPointer
|
|
95
96
|
index: number
|
|
96
|
-
replacedChild:
|
|
97
|
-
replacedNodes:
|
|
98
|
-
newChild:
|
|
99
|
-
newNodes:
|
|
97
|
+
replacedChild: LionWebId
|
|
98
|
+
replacedNodes: LionWebJsonChunk
|
|
99
|
+
newChild: LionWebId
|
|
100
|
+
newNodes: LionWebJsonChunk
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
export type ChildMovedSerializedDelta = {
|
|
103
104
|
kind: "ChildMoved"
|
|
104
|
-
oldParent:
|
|
105
|
-
oldContainment:
|
|
105
|
+
oldParent: LionWebId
|
|
106
|
+
oldContainment: LionWebJsonMetaPointer
|
|
106
107
|
oldIndex: number
|
|
107
|
-
newParent:
|
|
108
|
-
newContainment:
|
|
108
|
+
newParent: LionWebId
|
|
109
|
+
newContainment: LionWebJsonMetaPointer
|
|
109
110
|
newIndex: number
|
|
110
|
-
child:
|
|
111
|
+
child: LionWebId
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
export type ChildMovedInSameContainmentSerializedDelta = {
|
|
114
115
|
kind: "ChildMovedInSameContainment"
|
|
115
|
-
parent:
|
|
116
|
-
containment:
|
|
116
|
+
parent: LionWebId
|
|
117
|
+
containment: LionWebJsonMetaPointer
|
|
117
118
|
oldIndex: number
|
|
118
119
|
newIndex: number
|
|
119
|
-
child:
|
|
120
|
+
child: LionWebId
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
export type ReferenceAddedSerializedDelta = {
|
|
123
124
|
kind: "ReferenceAdded"
|
|
124
|
-
container:
|
|
125
|
-
reference:
|
|
125
|
+
container: LionWebId
|
|
126
|
+
reference: LionWebJsonMetaPointer
|
|
126
127
|
index: number
|
|
127
128
|
newTarget: IdOrUnresolved
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
export type ReferenceDeletedSerializedDelta = {
|
|
131
132
|
kind: "ReferenceDeleted"
|
|
132
|
-
container:
|
|
133
|
-
reference:
|
|
133
|
+
container: LionWebId
|
|
134
|
+
reference: LionWebJsonMetaPointer
|
|
134
135
|
index: number
|
|
135
136
|
deletedTarget: IdOrUnresolved
|
|
136
137
|
}
|
|
137
138
|
|
|
138
139
|
export type ReferenceReplacedSerializedDelta = {
|
|
139
140
|
kind: "ReferenceReplaced"
|
|
140
|
-
container:
|
|
141
|
-
reference:
|
|
141
|
+
container: LionWebId
|
|
142
|
+
reference: LionWebJsonMetaPointer
|
|
142
143
|
index: number
|
|
143
144
|
replacedTarget: IdOrUnresolved
|
|
144
145
|
newTarget: IdOrUnresolved
|
|
@@ -146,19 +147,19 @@ export type ReferenceReplacedSerializedDelta = {
|
|
|
146
147
|
|
|
147
148
|
export type ReferenceMovedSerializedDelta = {
|
|
148
149
|
kind: "ReferenceMoved"
|
|
149
|
-
oldContainer:
|
|
150
|
-
oldReference:
|
|
150
|
+
oldContainer: LionWebId
|
|
151
|
+
oldReference: LionWebJsonMetaPointer
|
|
151
152
|
oldIndex: number
|
|
152
|
-
newContainer:
|
|
153
|
-
newReference:
|
|
153
|
+
newContainer: LionWebId
|
|
154
|
+
newReference: LionWebJsonMetaPointer
|
|
154
155
|
newIndex: number
|
|
155
156
|
target: IdOrUnresolved
|
|
156
157
|
}
|
|
157
158
|
|
|
158
159
|
export type ReferenceMovedInSameReferenceSerializedDelta = {
|
|
159
160
|
kind: "ReferenceMovedInSameReference"
|
|
160
|
-
container:
|
|
161
|
-
reference:
|
|
161
|
+
container: LionWebId
|
|
162
|
+
reference: LionWebJsonMetaPointer
|
|
162
163
|
oldIndex: number
|
|
163
164
|
newIndex: number
|
|
164
165
|
target: IdOrUnresolved
|
|
@@ -166,44 +167,44 @@ export type ReferenceMovedInSameReferenceSerializedDelta = {
|
|
|
166
167
|
|
|
167
168
|
export type AnnotationAddedSerializedDelta = {
|
|
168
169
|
kind: "AnnotationAdded"
|
|
169
|
-
parent:
|
|
170
|
+
parent: LionWebId
|
|
170
171
|
index: number
|
|
171
|
-
newAnnotation:
|
|
172
|
-
newAnnotationNodes:
|
|
172
|
+
newAnnotation: LionWebId
|
|
173
|
+
newAnnotationNodes: LionWebJsonChunk
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
export type AnnotationDeletedSerializedDelta = {
|
|
176
177
|
kind: "AnnotationDeleted"
|
|
177
|
-
parent:
|
|
178
|
+
parent: LionWebId
|
|
178
179
|
index: number
|
|
179
|
-
deletedAnnotation:
|
|
180
|
-
deletedAnnotationNodes:
|
|
180
|
+
deletedAnnotation: LionWebId
|
|
181
|
+
deletedAnnotationNodes: LionWebJsonChunk
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
export type AnnotationReplacedSerializedDelta = {
|
|
184
185
|
kind: "AnnotationReplaced"
|
|
185
|
-
parent:
|
|
186
|
+
parent: LionWebId
|
|
186
187
|
index: number
|
|
187
|
-
replacedAnnotation:
|
|
188
|
-
replacedAnnotationNodes:
|
|
189
|
-
newAnnotation:
|
|
190
|
-
newAnnotationNodes:
|
|
188
|
+
replacedAnnotation: LionWebId
|
|
189
|
+
replacedAnnotationNodes: LionWebJsonChunk
|
|
190
|
+
newAnnotation: LionWebId
|
|
191
|
+
newAnnotationNodes: LionWebJsonChunk
|
|
191
192
|
}
|
|
192
193
|
|
|
193
194
|
export type AnnotationMovedFromOtherParentSerializedDelta = {
|
|
194
195
|
kind: "AnnotationMovedFromOtherParent"
|
|
195
|
-
oldParent:
|
|
196
|
+
oldParent: LionWebId
|
|
196
197
|
oldIndex: number
|
|
197
|
-
newParent:
|
|
198
|
+
newParent: LionWebId
|
|
198
199
|
newIndex: number
|
|
199
|
-
movedAnnotation:
|
|
200
|
+
movedAnnotation: LionWebId
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
export type AnnotationMovedInSameParentSerializedDelta = {
|
|
203
204
|
kind: "AnnotationMovedInSameParent"
|
|
204
|
-
parent:
|
|
205
|
+
parent: LionWebId
|
|
205
206
|
oldIndex: number
|
|
206
207
|
newIndex: number
|
|
207
|
-
movedAnnotation:
|
|
208
|
+
movedAnnotation: LionWebId
|
|
208
209
|
}
|
|
209
210
|
|
package/src/deltas/types.g.ts
CHANGED
package/src/deserializer.ts
CHANGED
|
@@ -16,36 +16,34 @@
|
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
|
-
|
|
19
|
+
BuiltinPropertyValueDeserializer,
|
|
20
20
|
Classifier,
|
|
21
21
|
Containment,
|
|
22
|
-
DefaultPrimitiveTypeDeserializer,
|
|
23
22
|
defaultSimplisticHandler,
|
|
24
23
|
Enumeration,
|
|
25
|
-
Id,
|
|
26
24
|
Language,
|
|
27
25
|
MemoisingSymbolTable,
|
|
28
26
|
PrimitiveType,
|
|
29
|
-
PrimitiveTypeDeserializer,
|
|
30
27
|
Property,
|
|
28
|
+
PropertyValueDeserializer,
|
|
31
29
|
Reference,
|
|
32
|
-
SerializationChunk,
|
|
33
|
-
SerializedNode,
|
|
34
30
|
SimplisticHandler,
|
|
35
31
|
unresolved
|
|
36
|
-
} from "@lionweb/core"
|
|
32
|
+
} from "@lionweb/core"
|
|
33
|
+
import { LionWebId, LionWebJsonChunk, LionWebJsonNode } from "@lionweb/json"
|
|
34
|
+
import { byIdMap } from "@lionweb/ts-utils"
|
|
37
35
|
|
|
38
|
-
import {DeltaHandler, IdMapping, ILanguageBase, INodeBase} from "./index.js"
|
|
39
|
-
import {NodesToInstall} from "./linking.js"
|
|
36
|
+
import { DeltaHandler, IdMapping, ILanguageBase, INodeBase } from "./index.js"
|
|
37
|
+
import { NodesToInstall } from "./linking.js"
|
|
40
38
|
|
|
41
39
|
|
|
42
40
|
/**
|
|
43
41
|
* A type for deserializer functions that are parametrized in their return type.
|
|
44
42
|
*/
|
|
45
43
|
export type Deserializer<T> = (
|
|
46
|
-
serializationChunk:
|
|
44
|
+
serializationChunk: LionWebJsonChunk,
|
|
47
45
|
dependentNodes?: INodeBase[],
|
|
48
|
-
|
|
46
|
+
propertyValueDeserializer?: PropertyValueDeserializer,
|
|
49
47
|
problemHandler?: SimplisticHandler
|
|
50
48
|
) => T;
|
|
51
49
|
|
|
@@ -74,7 +72,7 @@ export type RootsWithIdMapping = { roots: INodeBase[], idMapping: IdMapping };
|
|
|
74
72
|
|
|
75
73
|
/**
|
|
76
74
|
* @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
|
|
75
|
+
* @param languageBases the {@link ILanguageBase}s for (at least) all the languages used in the {@link LionWebJsonChunk} to deserialize, minus LionCore M3 and built-ins.
|
|
78
76
|
* @param handleDelta an optional {@link DeltaHandler} that will be injected in all {@link INodeBase nodes} created.
|
|
79
77
|
*/
|
|
80
78
|
export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): Deserializer<RootsWithIdMapping> => {
|
|
@@ -84,15 +82,15 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
84
82
|
const factoryFor = factoryLookupFor(languageBases, handleDelta);
|
|
85
83
|
|
|
86
84
|
return (
|
|
87
|
-
serializationChunk:
|
|
85
|
+
serializationChunk: LionWebJsonChunk,
|
|
88
86
|
dependentNodes: INodeBase[] = [],
|
|
89
|
-
|
|
87
|
+
propertyValueDeserializer: PropertyValueDeserializer = new BuiltinPropertyValueDeserializer(),
|
|
90
88
|
problemsHandler: SimplisticHandler = defaultSimplisticHandler
|
|
91
89
|
): RootsWithIdMapping => {
|
|
92
90
|
|
|
93
91
|
const nodesToInstall: NodesToInstall[] = [];
|
|
94
92
|
|
|
95
|
-
const createNode = ({id, classifier: classifierMetaPointer, properties, containments, references, annotations}:
|
|
93
|
+
const createNode = ({id, classifier: classifierMetaPointer, properties, containments, references, annotations}: LionWebJsonNode) => {
|
|
96
94
|
const languageMessage = `language ${classifierMetaPointer.language} (${classifierMetaPointer.version})`;
|
|
97
95
|
const classifier = symbolTable.entityMatching(classifierMetaPointer);
|
|
98
96
|
if (classifier === undefined || !(classifier instanceof Classifier)) {
|
|
@@ -108,7 +106,7 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
108
106
|
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
107
|
} else if (feature instanceof Property) {
|
|
110
108
|
if (feature.type instanceof PrimitiveType) {
|
|
111
|
-
node.getPropertyValueManager(feature).setDirectly(value === null ? undefined :
|
|
109
|
+
node.getPropertyValueManager(feature).setDirectly(value === null ? undefined : propertyValueDeserializer.deserializeValue(value, feature));
|
|
112
110
|
} else if (feature.type instanceof Enumeration) {
|
|
113
111
|
if (value !== undefined) {
|
|
114
112
|
const literal = feature.type.literals.find((literal) => literal.key === value);
|
|
@@ -161,7 +159,7 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
161
159
|
|
|
162
160
|
const dependentNodesById = byIdMap(dependentNodes)
|
|
163
161
|
|
|
164
|
-
const lookupNodeById = (id:
|
|
162
|
+
const lookupNodeById = (id: LionWebId) =>
|
|
165
163
|
nodesById[id] ?? dependentNodesById[id];
|
|
166
164
|
|
|
167
165
|
nodesToInstall.forEach(([node, feature, ids]) => {
|
|
@@ -218,17 +216,17 @@ export const nodeBaseDeserializerWithIdMapping = (languageBases: ILanguageBase[]
|
|
|
218
216
|
|
|
219
217
|
/**
|
|
220
218
|
* @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
|
|
219
|
+
* @param languageBases the {@link ILanguageBase}s for (at least) all the languages used in the {@link LionWebJsonChunk} to deserialize, minus LionCore M3 and built-ins.
|
|
222
220
|
* @param handleDelta an optional {@link DeltaHandler} that will be injected in all {@link INodeBase nodes} created.
|
|
223
221
|
*/
|
|
224
222
|
export const nodeBaseDeserializer = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): Deserializer<INodeBase[]> => {
|
|
225
223
|
const deserializerWithIdMapping = nodeBaseDeserializerWithIdMapping(languageBases, handleDelta);
|
|
226
224
|
return (
|
|
227
|
-
serializationChunk:
|
|
225
|
+
serializationChunk: LionWebJsonChunk,
|
|
228
226
|
dependentNodes: INodeBase[] = [],
|
|
229
|
-
|
|
227
|
+
propertyValueDeserializer: PropertyValueDeserializer = new BuiltinPropertyValueDeserializer(),
|
|
230
228
|
problemsHandler: SimplisticHandler = defaultSimplisticHandler
|
|
231
229
|
): INodeBase[] =>
|
|
232
|
-
deserializerWithIdMapping(serializationChunk, dependentNodes,
|
|
230
|
+
deserializerWithIdMapping(serializationChunk, dependentNodes, propertyValueDeserializer, problemsHandler).roots
|
|
233
231
|
}
|
|
234
232
|
|
package/src/duplicator.ts
CHANGED
|
@@ -15,12 +15,14 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { Containment, Feature, idOf, Link, Property, Reference, SingleRef, unresolved } from "@lionweb/core"
|
|
19
|
+
import { LionWebId } from "@lionweb/json"
|
|
20
|
+
import { asArray } from "@lionweb/ts-utils"
|
|
19
21
|
|
|
20
|
-
import {INodeBase} from "./base-types.js"
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
22
|
+
import { INodeBase } from "./base-types.js"
|
|
23
|
+
import { allNodesFrom } from "./convenience.js"
|
|
24
|
+
import { NodesToInstall } from "./linking.js"
|
|
25
|
+
import { getFeatureValue } from "./serializer.js"
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -45,7 +47,7 @@ export const deepDuplicateWith = (duplicateNode: NodeDuplicator): Duplicator =>
|
|
|
45
47
|
|
|
46
48
|
const nodesToInstall: NodesToInstall[] = [];
|
|
47
49
|
|
|
48
|
-
const visit = (node: INodeBase): [id:
|
|
50
|
+
const visit = (node: INodeBase): [id: LionWebId, duplicatedNode: INodeBase] => {
|
|
49
51
|
const [duplicatedNode, featuresToDuplicate] = duplicateNode(node);
|
|
50
52
|
const duplicateFeatureValue = (feature: Feature) => {
|
|
51
53
|
const value = getFeatureValue(node, feature);
|
package/src/factory.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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 { lazyMapGet } from "@lionweb/ts-utils"
|
|
19
|
+
import { ILanguageBase, NodeBaseFactory } from "./base-types.js"
|
|
20
|
+
import { DeltaHandler } from "./deltas/index.js"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @return a {@link NodeBaseFactory factory function} that works for all given {@link ILanguageBase language bases}.
|
|
24
|
+
*/
|
|
25
|
+
export const combinedFactoryFor = (languageBases: ILanguageBase[], handleDelta?: DeltaHandler): NodeBaseFactory => {
|
|
26
|
+
// create lookup map:
|
|
27
|
+
const languageKey2version2factory: { [key: string]: { [version: string]: NodeBaseFactory } } = {}
|
|
28
|
+
languageBases.forEach((languageBase) => {
|
|
29
|
+
const {key, version} = languageBase.language
|
|
30
|
+
const version2factory = lazyMapGet(languageKey2version2factory, key, () => ({}))
|
|
31
|
+
lazyMapGet(version2factory, version, () => languageBase.factory(handleDelta))
|
|
32
|
+
// (Note: don't destructure factory from languageBase, as that will unbind it as "this"!)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return (classifier, id) => {
|
|
36
|
+
const {key, version, name} = classifier.language
|
|
37
|
+
const version2factory = languageKey2version2factory[key]
|
|
38
|
+
if (version2factory === undefined) {
|
|
39
|
+
throw new Error(`language ${name} with key=${key} not known`)
|
|
40
|
+
}
|
|
41
|
+
const factory = version2factory[version]
|
|
42
|
+
if (factory === undefined) {
|
|
43
|
+
const candidateVersions = Object.keys(version2factory)
|
|
44
|
+
throw new Error(`language ${name} with key=${key} and version=${version} not known${candidateVersions.length > 0 ? `- candidate version${candidateVersions.length > 1 ? `s` : ``}: ${candidateVersions.join(", ")}` : ``}`)
|
|
45
|
+
}
|
|
46
|
+
return factory(classifier, id)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
package/src/id-mapping.ts
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { IdOrUnresolved, SingleRef, unresolved } from "@lionweb/core"
|
|
19
|
+
import { LionWebId } from "@lionweb/json"
|
|
19
20
|
|
|
20
|
-
import {INodeBase} from "./index.js"
|
|
21
|
+
import { INodeBase } from "./index.js"
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
type NodesById = { [id: Id]: INodeBase};
|
|
23
|
+
type NodesById = { [id: LionWebId]: INodeBase }
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -34,18 +34,17 @@ export class IdMapping {
|
|
|
34
34
|
constructor(nodesById: NodesById) {
|
|
35
35
|
this.nodesById = {...nodesById};
|
|
36
36
|
}
|
|
37
|
+
// TODO consider using an instance of Map<Id, INodeBase> instead
|
|
37
38
|
|
|
38
|
-
fromId(id:
|
|
39
|
+
fromId(id: LionWebId): INodeBase {
|
|
39
40
|
if (!(id in this.nodesById)) {
|
|
40
41
|
throw new Error(`node with id=${id} not in ID mapping`);
|
|
41
42
|
}
|
|
42
43
|
return this.nodesById[id];
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
tryFromId = (id:
|
|
46
|
-
|
|
47
|
-
? this.nodesById[id]
|
|
48
|
-
: undefined;
|
|
46
|
+
tryFromId = (id: LionWebId): (INodeBase | undefined) =>
|
|
47
|
+
this.nodesById[id];
|
|
49
48
|
|
|
50
49
|
fromRefId = (idOrUnresolved: IdOrUnresolved): SingleRef<INodeBase> =>
|
|
51
50
|
idOrUnresolved === null
|
package/src/index.ts
CHANGED
|
@@ -19,11 +19,12 @@ export * from "./base-types.js";
|
|
|
19
19
|
export * from "./convenience.js";
|
|
20
20
|
export * from "./deltas/index.js";
|
|
21
21
|
export * from "./deserializer.js";
|
|
22
|
-
export {deepDuplicateWith} from "./duplicator.js";
|
|
22
|
+
export { deepDuplicateWith } from "./duplicator.js";
|
|
23
23
|
export * from "./id-mapping.js";
|
|
24
|
+
export { combinedFactoryFor } from "./factory.js";
|
|
24
25
|
// skip linking.js: see comment there
|
|
25
|
-
export * from "./
|
|
26
|
+
export * from "./LionCore_builtins.g.js";
|
|
26
27
|
export {serializeNodeBases} from "./serializer.js";
|
|
28
|
+
export { asTreeTextWith } from "./textualizer.js";
|
|
27
29
|
export * from "./value-managers/index.js";
|
|
28
|
-
export {asTreeTextWith} from "./textualizer.js";
|
|
29
30
|
|
package/src/linking.ts
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { Link } from "@lionweb/core"
|
|
19
|
+
import { LionWebId } from "@lionweb/json"
|
|
20
|
+
import { INodeBase } from "./index.js"
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -35,5 +36,5 @@ import {INodeBase} from "./index.js";
|
|
|
35
36
|
* Note: **DON'T** export this types from the package,
|
|
36
37
|
* as these are only used to align the deserializer and deep-cloner.
|
|
37
38
|
*/
|
|
38
|
-
export type NodesToInstall = [ container: INodeBase, feature: Link | null, nodesIds:
|
|
39
|
+
export type NodesToInstall = [ container: INodeBase, feature: Link | null, nodesIds: LionWebId[], originalReferenceTargets?: INodeBase[] ];
|
|
39
40
|
|
package/src/serializer.ts
CHANGED
|
@@ -20,14 +20,14 @@ import {
|
|
|
20
20
|
builtinClassifiers,
|
|
21
21
|
builtinFeatures,
|
|
22
22
|
Containment,
|
|
23
|
-
ExtractionFacade,
|
|
24
23
|
Feature,
|
|
24
|
+
nodeSerializer,
|
|
25
25
|
Property,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from "@lionweb/core"
|
|
26
|
+
Reader,
|
|
27
|
+
Reference
|
|
28
|
+
} from "@lionweb/core"
|
|
29
29
|
|
|
30
|
-
import {INodeBase, LionCore_builtinsBase} from "./index.js"
|
|
30
|
+
import { INodeBase, LionCore_builtinsBase } from "./index.js"
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -48,10 +48,10 @@ export const getFeatureValue = (node: INodeBase, feature: Feature) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* A {@link Reader} that works on/for {@link INodeBase}s specifically.
|
|
52
52
|
* **Note** that this function is for internal use only!
|
|
53
53
|
*/
|
|
54
|
-
export const nodeBaseReader:
|
|
54
|
+
export const nodeBaseReader: Reader<INodeBase> = {
|
|
55
55
|
classifierOf: (node) => node.classifier,
|
|
56
56
|
getFeatureValue,
|
|
57
57
|
enumerationLiteralFrom: (encoding, enumeration) => {
|
|
@@ -79,8 +79,7 @@ export const nodeBaseReader: ExtractionFacade<INodeBase> = {
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
|
-
* @return a serialization of the given nodes (of type {@link INodeBase}) as a {@link
|
|
82
|
+
* @return a serialization of the given nodes (of type {@link INodeBase}) as a {@link LionWebJsonChunk}.
|
|
83
83
|
*/
|
|
84
|
-
export const serializeNodeBases = (
|
|
85
|
-
serializeNodes(nodes, nodeBaseReader, { serializeEmptyFeatures: false });
|
|
84
|
+
export const serializeNodeBases = nodeSerializer(nodeBaseReader, { serializeEmptyFeatures: false });
|
|
86
85
|
|
package/src/textualizer.ts
CHANGED
|
@@ -15,12 +15,11 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
import {INodeBase} from "./base-types.js";
|
|
22
|
-
import {LionCore_builtinsBase} from "./lionCore_builtins.g.js";
|
|
18
|
+
import { allFeaturesOf, Containment, Feature, Property, Reference, unresolved } from "@lionweb/core"
|
|
19
|
+
import { asString, indentWith, Template } from "littoral-templates"
|
|
23
20
|
|
|
21
|
+
import { INodeBase } from "./base-types.js"
|
|
22
|
+
import { LionCore_builtinsBase } from "./LionCore_builtins.g.js"
|
|
24
23
|
|
|
25
24
|
const indent = indentWith(" ")(1)
|
|
26
25
|
|
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {action, observable} from "mobx"
|
|
18
|
+
import { action, observable } from "mobx"
|
|
19
19
|
|
|
20
|
-
import {INodeBase, removeFromParent} from "../base-types.js"
|
|
21
|
-
import {checkIndex, ValueManager} from "./base.js"
|
|
20
|
+
import { INodeBase, removeFromParent } from "../base-types.js"
|
|
21
|
+
import { checkIndex, ValueManager } from "./base.js"
|
|
22
22
|
import {
|
|
23
23
|
AnnotationAddedDelta,
|
|
24
24
|
AnnotationDeletedDelta,
|
|
25
25
|
AnnotationMovedFromOtherParentDelta,
|
|
26
26
|
AnnotationMovedInSameParentDelta,
|
|
27
27
|
AnnotationReplacedDelta
|
|
28
|
-
} from "../deltas/index.js"
|
|
28
|
+
} from "../deltas/index.js"
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {Feature, featureMetaType, Link} from "@lionweb/core"
|
|
19
|
-
import {INodeBase} from "../base-types.js"
|
|
20
|
-
import {IDelta} from "../deltas/index.js"
|
|
18
|
+
import { Feature, featureMetaType, Link } from "@lionweb/core"
|
|
19
|
+
import { INodeBase } from "../base-types.js"
|
|
20
|
+
import { IDelta } from "../deltas/index.js"
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -15,18 +15,12 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
import {Containment} from "@lionweb/core"
|
|
19
|
-
import {action, observable} from "mobx"
|
|
20
|
-
|
|
21
|
-
import {INodeBase, removeFromParent} from "../base-types.js"
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
ChildAddedDelta,
|
|
25
|
-
ChildDeletedDelta,
|
|
26
|
-
ChildMovedDelta,
|
|
27
|
-
ChildMovedInSameContainmentDelta,
|
|
28
|
-
ChildReplacedDelta
|
|
29
|
-
} from "../deltas/index.js";
|
|
18
|
+
import { Containment } from "@lionweb/core"
|
|
19
|
+
import { action, observable } from "mobx"
|
|
20
|
+
|
|
21
|
+
import { INodeBase, removeFromParent } from "../base-types.js"
|
|
22
|
+
import { ChildAddedDelta, ChildDeletedDelta, ChildMovedDelta, ChildMovedInSameContainmentDelta, ChildReplacedDelta } from "../deltas/index.js"
|
|
23
|
+
import { checkIndex, FeatureValueManager } from "./base.js"
|
|
30
24
|
|
|
31
25
|
|
|
32
26
|
/**
|