@lionweb/delta-protocol-common 0.7.0-beta.22 → 0.7.0-beta.24
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/dist/logging/textual-logging.d.ts +0 -4
- package/dist/logging/textual-logging.d.ts.map +1 -1
- package/dist/logging/textual-logging.js +0 -19
- package/dist/logging/textual-logging.js.map +1 -1
- package/dist/payload/command-types.d.ts +4 -4
- package/dist/payload/command-types.d.ts.map +1 -1
- package/dist/payload/event-types.d.ts +7 -7
- package/dist/payload/event-types.d.ts.map +1 -1
- package/dist/translators/delta-to-command.d.ts +10 -2
- package/dist/translators/delta-to-command.d.ts.map +1 -1
- package/dist/translators/delta-to-command.js +275 -274
- package/dist/translators/delta-to-command.js.map +1 -1
- package/dist/translators/delta-to-event.d.ts +18 -1
- package/dist/translators/delta-to-event.d.ts.map +1 -1
- package/dist/translators/delta-to-event.js +321 -2
- package/dist/translators/delta-to-event.js.map +1 -1
- package/dist/translators/event-to-delta.d.ts +3 -2
- package/dist/translators/event-to-delta.d.ts.map +1 -1
- package/dist/translators/event-to-delta.js +7 -10
- package/dist/translators/event-to-delta.js.map +1 -1
- package/dist/translators/index.d.ts +2 -1
- package/dist/translators/index.d.ts.map +1 -1
- package/dist/translators/index.js +2 -1
- package/dist/translators/index.js.map +1 -1
- package/package.json +5 -5
- package/src/logging/textual-logging.ts +0 -22
- package/src/payload/command-types.ts +4 -4
- package/src/payload/event-types.ts +7 -7
- package/src/translators/delta-to-command.ts +289 -281
- package/src/translators/delta-to-event.ts +430 -1
- package/src/translators/event-to-delta.ts +21 -15
- package/src/translators/index.ts +2 -1
|
@@ -15,5 +15,434 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
import {
|
|
19
|
+
allNodesFrom,
|
|
20
|
+
AnnotationAddedDelta,
|
|
21
|
+
AnnotationDeletedDelta,
|
|
22
|
+
AnnotationMovedAndReplacedFromOtherParentDelta,
|
|
23
|
+
AnnotationMovedAndReplacedInSameParentDelta,
|
|
24
|
+
AnnotationMovedFromOtherParentDelta,
|
|
25
|
+
AnnotationMovedInSameParentDelta,
|
|
26
|
+
AnnotationReplacedDelta,
|
|
27
|
+
ChildAddedDelta,
|
|
28
|
+
ChildDeletedDelta,
|
|
29
|
+
ChildMovedAndReplacedFromOtherContainmentDelta,
|
|
30
|
+
ChildMovedAndReplacedFromOtherContainmentInSameParentDelta,
|
|
31
|
+
ChildMovedAndReplacedInSameContainmentDelta,
|
|
32
|
+
ChildMovedFromOtherContainmentDelta,
|
|
33
|
+
ChildMovedFromOtherContainmentInSameParentDelta,
|
|
34
|
+
ChildMovedInSameContainmentDelta,
|
|
35
|
+
ChildReplacedDelta,
|
|
36
|
+
CompositeDelta,
|
|
37
|
+
EntryMovedAndReplacedFromOtherReferenceDelta,
|
|
38
|
+
EntryMovedAndReplacedFromOtherReferenceInSameParentDelta,
|
|
39
|
+
EntryMovedAndReplacedInSameReferenceDelta,
|
|
40
|
+
EntryMovedFromOtherReferenceDelta,
|
|
41
|
+
EntryMovedFromOtherReferenceInSameParentDelta,
|
|
42
|
+
EntryMovedInSameReferenceDelta,
|
|
43
|
+
IDelta,
|
|
44
|
+
INodeBase,
|
|
45
|
+
NoOpDelta,
|
|
46
|
+
PartitionAddedDelta,
|
|
47
|
+
PartitionDeletedDelta,
|
|
48
|
+
PropertyAddedDelta,
|
|
49
|
+
PropertyChangedDelta,
|
|
50
|
+
PropertyDeletedDelta,
|
|
51
|
+
ReferenceAddedDelta,
|
|
52
|
+
ReferenceChangedDelta,
|
|
53
|
+
ReferenceDeletedDelta,
|
|
54
|
+
serializeNodeBases
|
|
55
|
+
} from "@lionweb/class-core"
|
|
56
|
+
import {
|
|
57
|
+
builtinPropertyValueSerializer,
|
|
58
|
+
idOf,
|
|
59
|
+
metaPointerFor,
|
|
60
|
+
PropertyValueSerializer,
|
|
61
|
+
serializedRef
|
|
62
|
+
} from "@lionweb/core"
|
|
63
|
+
import {
|
|
64
|
+
AnnotationAddedEvent,
|
|
65
|
+
AnnotationDeletedEvent,
|
|
66
|
+
AnnotationMovedAndReplacedFromOtherParentEvent,
|
|
67
|
+
AnnotationMovedAndReplacedInSameParentEvent,
|
|
68
|
+
AnnotationMovedFromOtherParentEvent,
|
|
69
|
+
AnnotationMovedInSameParentEvent,
|
|
70
|
+
AnnotationReplacedEvent,
|
|
71
|
+
ChildAddedEvent,
|
|
72
|
+
ChildDeletedEvent,
|
|
73
|
+
ChildMovedAndReplacedFromOtherContainmentEvent,
|
|
74
|
+
ChildMovedAndReplacedFromOtherContainmentInSameParentEvent,
|
|
75
|
+
ChildMovedAndReplacedInSameContainmentEvent,
|
|
76
|
+
ChildMovedFromOtherContainmentEvent,
|
|
77
|
+
ChildMovedFromOtherContainmentInSameParentEvent,
|
|
78
|
+
ChildMovedInSameContainmentEvent,
|
|
79
|
+
ChildReplacedEvent,
|
|
80
|
+
CompositeEvent,
|
|
81
|
+
EntryMovedAndReplacedFromOtherReferenceEvent,
|
|
82
|
+
EntryMovedAndReplacedFromOtherReferenceInSameParentEvent,
|
|
83
|
+
EntryMovedAndReplacedInSameReferenceEvent,
|
|
84
|
+
EntryMovedFromOtherReferenceEvent,
|
|
85
|
+
EntryMovedFromOtherReferenceInSameParentEvent,
|
|
86
|
+
EntryMovedInSameReferenceEvent,
|
|
87
|
+
Event,
|
|
88
|
+
NoOpEvent,
|
|
89
|
+
PartitionAddedEvent,
|
|
90
|
+
PartitionDeletedEvent,
|
|
91
|
+
PropertyAddedEvent,
|
|
92
|
+
PropertyChangedEvent,
|
|
93
|
+
PropertyDeletedEvent,
|
|
94
|
+
ReferenceAddedEvent,
|
|
95
|
+
ReferenceChangedEvent,
|
|
96
|
+
ReferenceDeletedEvent
|
|
97
|
+
} from "../payload/index.js"
|
|
98
|
+
import { nodeBaseReader } from "@lionweb/class-core/dist/serializer.js"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
const allIdsOfDescendantsFrom = (node: INodeBase) =>
|
|
102
|
+
allNodesFrom(node).slice(1).map(idOf)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Type def. for functions that translate {@link IDelta deltas} into {@link Event events},
|
|
107
|
+
* taking care of proper sequence numbers and (implicitly) serialization of property values.
|
|
108
|
+
*
|
|
109
|
+
* More precisely, such a function returns a pair consisting of an {@link Event event}
|
|
110
|
+
* and the last-used sequence number, where the event is the translation of the given {@link IDelta delta}.
|
|
111
|
+
* Sequence numbers start from the given `lastUsedSequenceNumber`.
|
|
112
|
+
* More than one sequence number might be allocated because of composite deltas.
|
|
113
|
+
*/
|
|
114
|
+
export type DeltaToEventTranslator = (
|
|
115
|
+
delta: IDelta,
|
|
116
|
+
lastUsedSequenceNumber: number
|
|
117
|
+
) => [event: Event, lastUsedSequenceNumber: number];
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @return a {@link DeltaToEventTranslator} instance using the given {@link PropertyValueSerializer}
|
|
122
|
+
* (with that defaulting to the {@link builtinPropertyValueSerializer}).
|
|
123
|
+
*/
|
|
124
|
+
export const deltaToEventTranslator = (
|
|
125
|
+
propertyValueSerializer: PropertyValueSerializer = builtinPropertyValueSerializer
|
|
126
|
+
): DeltaToEventTranslator =>
|
|
127
|
+
(delta, lastUsedSequenceNumber) => {
|
|
128
|
+
|
|
129
|
+
let sequenceNumber = lastUsedSequenceNumber
|
|
130
|
+
const completed = <ET extends Event>(
|
|
131
|
+
technicalName: ET["messageKind"],
|
|
132
|
+
partialEvent: Omit<ET, "messageKind" | "sequenceNumber" | "originCommands" | "protocolMessages">
|
|
133
|
+
) => ({
|
|
134
|
+
messageKind: technicalName,
|
|
135
|
+
...partialEvent,
|
|
136
|
+
sequenceNumber: ++sequenceNumber,
|
|
137
|
+
originCommands: [],
|
|
138
|
+
protocolMessages: []
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
// in order of the specification (§ 6.6):
|
|
142
|
+
|
|
143
|
+
const translated = (delta: IDelta): Event => {
|
|
144
|
+
if (delta instanceof PartitionAddedDelta) {
|
|
145
|
+
return completed<PartitionAddedEvent>("PartitionAdded", { // § 6.6.1.1
|
|
146
|
+
newPartition: serializeNodeBases([delta.newPartition])
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
if (delta instanceof PartitionDeletedDelta) {
|
|
150
|
+
return completed<PartitionDeletedEvent>("PartitionDeleted", { // § 6.6.1.2
|
|
151
|
+
deletedPartition: delta.deletedPartition.id
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
if (delta instanceof PropertyAddedDelta) {
|
|
155
|
+
return completed<PropertyAddedEvent>("PropertyAdded", { // § 6.6.3.1
|
|
156
|
+
node: delta.node.id,
|
|
157
|
+
property: metaPointerFor(delta.property),
|
|
158
|
+
newValue: propertyValueSerializer.serializeValue(delta.value, delta.property)!
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
if (delta instanceof PropertyDeletedDelta) {
|
|
162
|
+
return completed<PropertyDeletedEvent>("PropertyDeleted", { // § 6.6.3.2
|
|
163
|
+
node: delta.node.id,
|
|
164
|
+
property: metaPointerFor(delta.property),
|
|
165
|
+
oldValue: propertyValueSerializer.serializeValue(delta.oldValue, delta.property)!
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
if (delta instanceof PropertyChangedDelta) {
|
|
169
|
+
return completed<PropertyChangedEvent>("PropertyChanged", { // § 6.6.3.3
|
|
170
|
+
node: delta.node.id,
|
|
171
|
+
property: metaPointerFor(delta.property),
|
|
172
|
+
newValue: propertyValueSerializer.serializeValue(delta.newValue, delta.property)!,
|
|
173
|
+
oldValue: propertyValueSerializer.serializeValue(delta.oldValue, delta.property)!
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
if (delta instanceof ChildAddedDelta) {
|
|
177
|
+
return completed<ChildAddedEvent>("ChildAdded", { // § 6.6.4.1
|
|
178
|
+
parent: delta.parent.id,
|
|
179
|
+
newChild: serializeNodeBases([delta.newChild]),
|
|
180
|
+
containment: metaPointerFor(delta.containment),
|
|
181
|
+
index: delta.index
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
if (delta instanceof ChildDeletedDelta) {
|
|
185
|
+
return completed<ChildDeletedEvent>("ChildDeleted", { // § 6.6.4.2
|
|
186
|
+
parent: delta.parent.id,
|
|
187
|
+
containment: metaPointerFor(delta.containment),
|
|
188
|
+
index: delta.index,
|
|
189
|
+
deletedChild: delta.deletedChild.id,
|
|
190
|
+
deletedDescendants: allIdsOfDescendantsFrom(delta.deletedChild)
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
if (delta instanceof ChildReplacedDelta) {
|
|
194
|
+
return completed<ChildReplacedEvent>("ChildReplaced", { // § 6.6.4.3
|
|
195
|
+
newChild: serializeNodeBases([delta.newChild]),
|
|
196
|
+
parent: delta.parent.id,
|
|
197
|
+
containment: metaPointerFor(delta.containment),
|
|
198
|
+
index: delta.index,
|
|
199
|
+
replacedChild: delta.replacedChild.id,
|
|
200
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedChild)
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
if (delta instanceof ChildMovedFromOtherContainmentDelta) {
|
|
204
|
+
return completed<ChildMovedFromOtherContainmentEvent>("ChildMovedFromOtherContainment", { // § 6.6.4.4
|
|
205
|
+
newParent: delta.newParent.id,
|
|
206
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
207
|
+
newIndex: delta.newIndex,
|
|
208
|
+
movedChild: delta.movedChild.id,
|
|
209
|
+
oldParent: delta.oldParent.id,
|
|
210
|
+
oldContainment: metaPointerFor(delta.oldContainment),
|
|
211
|
+
oldIndex: delta.oldIndex
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
if (delta instanceof ChildMovedFromOtherContainmentInSameParentDelta) {
|
|
215
|
+
return completed<ChildMovedFromOtherContainmentInSameParentEvent>("ChildMovedFromOtherContainmentInSameParent", { // § 6.6.4.5
|
|
216
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
217
|
+
newIndex: delta.newIndex,
|
|
218
|
+
movedChild: delta.movedChild.id,
|
|
219
|
+
parent: delta.parent.id,
|
|
220
|
+
oldContainment: metaPointerFor(delta.oldContainment),
|
|
221
|
+
oldIndex: delta.oldIndex
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
if (delta instanceof ChildMovedInSameContainmentDelta) {
|
|
225
|
+
return completed<ChildMovedInSameContainmentEvent>("ChildMovedInSameContainment", { // § 6.6.4.6
|
|
226
|
+
parent: delta.parent.id,
|
|
227
|
+
containment: metaPointerFor(delta.containment),
|
|
228
|
+
oldIndex: delta.oldIndex,
|
|
229
|
+
newIndex: delta.newIndex,
|
|
230
|
+
movedChild: delta.movedChild.id
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
if (delta instanceof ChildMovedAndReplacedFromOtherContainmentDelta) {
|
|
234
|
+
return completed<ChildMovedAndReplacedFromOtherContainmentEvent>("ChildMovedAndReplacedFromOtherContainment", { // § 6.6.4.7
|
|
235
|
+
newParent: delta.newParent.id,
|
|
236
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
237
|
+
newIndex: delta.newIndex,
|
|
238
|
+
oldParent: delta.oldParent.id,
|
|
239
|
+
oldContainment: metaPointerFor(delta.oldContainment),
|
|
240
|
+
oldIndex: delta.oldIndex,
|
|
241
|
+
movedChild: delta.movedChild.id,
|
|
242
|
+
replacedChild: delta.replacedChild.id,
|
|
243
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedChild)
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
if (delta instanceof ChildMovedAndReplacedFromOtherContainmentInSameParentDelta) {
|
|
247
|
+
return completed<ChildMovedAndReplacedFromOtherContainmentInSameParentEvent>("ChildMovedAndReplacedFromOtherContainmentInSameParent", { // § 6.6.4.8
|
|
248
|
+
parent: delta.parent.id,
|
|
249
|
+
oldContainment: metaPointerFor(delta.oldContainment),
|
|
250
|
+
oldIndex: delta.oldIndex,
|
|
251
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
252
|
+
newIndex: delta.newIndex,
|
|
253
|
+
replacedChild: delta.replacedChild.id,
|
|
254
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedChild),
|
|
255
|
+
movedChild: delta.movedChild.id
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
if (delta instanceof ChildMovedAndReplacedInSameContainmentDelta) {
|
|
259
|
+
return completed<ChildMovedAndReplacedInSameContainmentEvent>("ChildMovedAndReplacedInSameContainment", { // § 6.6.4.9
|
|
260
|
+
parent: delta.parent.id,
|
|
261
|
+
containment: metaPointerFor(delta.containment),
|
|
262
|
+
oldIndex: delta.oldIndex,
|
|
263
|
+
newIndex: delta.newIndex,
|
|
264
|
+
movedChild: delta.movedChild.id,
|
|
265
|
+
replacedChild: delta.replacedChild.id,
|
|
266
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedChild)
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
if (delta instanceof AnnotationAddedDelta) {
|
|
270
|
+
return completed<AnnotationAddedEvent>("AnnotationAdded", { // § 6.6.5.1
|
|
271
|
+
parent: delta.parent.id,
|
|
272
|
+
index: delta.index,
|
|
273
|
+
newAnnotation: serializeNodeBases([delta.newAnnotation])
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
if (delta instanceof AnnotationDeletedDelta) {
|
|
277
|
+
return completed<AnnotationDeletedEvent>("AnnotationDeleted", { // § 6.6.5.2
|
|
278
|
+
parent: delta.parent.id,
|
|
279
|
+
deletedAnnotation: delta.deletedAnnotation.id,
|
|
280
|
+
index: delta.index,
|
|
281
|
+
deletedDescendants: allIdsOfDescendantsFrom(delta.deletedAnnotation)
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
if (delta instanceof AnnotationReplacedDelta) {
|
|
285
|
+
return completed<AnnotationReplacedEvent>("AnnotationReplaced", { // § 6.6.5.3
|
|
286
|
+
newAnnotation: serializeNodeBases([delta.newAnnotation]),
|
|
287
|
+
parent: delta.parent.id,
|
|
288
|
+
index: delta.index,
|
|
289
|
+
replacedAnnotation: delta.replacedAnnotation.id,
|
|
290
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedAnnotation)
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
if (delta instanceof AnnotationMovedFromOtherParentDelta) {
|
|
294
|
+
return completed<AnnotationMovedFromOtherParentEvent>("AnnotationMovedFromOtherParent", { // § 6.6.5.4
|
|
295
|
+
oldParent: delta.oldParent.id,
|
|
296
|
+
oldIndex: delta.oldIndex,
|
|
297
|
+
newParent: delta.newParent.id,
|
|
298
|
+
newIndex: delta.newIndex,
|
|
299
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
300
|
+
})
|
|
301
|
+
}
|
|
302
|
+
if (delta instanceof AnnotationMovedInSameParentDelta) {
|
|
303
|
+
return completed<AnnotationMovedInSameParentEvent>("AnnotationMovedInSameParent", { // § 6.6.5.5
|
|
304
|
+
parent: delta.parent.id,
|
|
305
|
+
oldIndex: delta.oldIndex,
|
|
306
|
+
newIndex: delta.newIndex,
|
|
307
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
if (delta instanceof AnnotationMovedAndReplacedFromOtherParentDelta) {
|
|
311
|
+
return completed<AnnotationMovedAndReplacedFromOtherParentEvent>("AnnotationMovedAndReplacedFromOtherParent", { // § 6.6.5.6
|
|
312
|
+
oldParent: delta.oldParent.id,
|
|
313
|
+
oldIndex: delta.oldIndex,
|
|
314
|
+
newParent: delta.newParent.id,
|
|
315
|
+
newIndex: delta.newIndex,
|
|
316
|
+
replacedAnnotation: delta.replacedAnnotation.id,
|
|
317
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedAnnotation),
|
|
318
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
if (delta instanceof AnnotationMovedAndReplacedInSameParentDelta) {
|
|
322
|
+
return completed<AnnotationMovedAndReplacedInSameParentEvent>("AnnotationMovedAndReplacedInSameParent", { // § 6.6.5.7
|
|
323
|
+
parent: delta.parent.id,
|
|
324
|
+
oldIndex: delta.oldIndex,
|
|
325
|
+
newIndex: delta.newIndex,
|
|
326
|
+
replacedAnnotation: delta.replacedAnnotation.id,
|
|
327
|
+
replacedDescendants: allIdsOfDescendantsFrom(delta.replacedAnnotation),
|
|
328
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
if (delta instanceof ReferenceAddedDelta) {
|
|
332
|
+
return completed<ReferenceAddedEvent>("ReferenceAdded", { // § 6.6.6.1
|
|
333
|
+
parent: delta.parent.id,
|
|
334
|
+
reference: metaPointerFor(delta.reference),
|
|
335
|
+
index: delta.index,
|
|
336
|
+
newTarget: serializedRef(delta.newTarget),
|
|
337
|
+
newResolveInfo: nodeBaseReader.resolveInfoFor!(delta.newTarget!)!
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
if (delta instanceof ReferenceDeletedDelta) {
|
|
341
|
+
return completed<ReferenceDeletedEvent>("ReferenceDeleted", { // § 6.6.6.2
|
|
342
|
+
parent: delta.parent.id,
|
|
343
|
+
reference: metaPointerFor(delta.reference),
|
|
344
|
+
index: delta.index,
|
|
345
|
+
deletedTarget: serializedRef(delta.deletedTarget),
|
|
346
|
+
deletedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.deletedTarget!)!
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
if (delta instanceof ReferenceChangedDelta) {
|
|
350
|
+
return completed<ReferenceChangedEvent>("ReferenceChanged", { // § 6.6.6.3
|
|
351
|
+
parent: delta.parent.id,
|
|
352
|
+
reference: metaPointerFor(delta.reference),
|
|
353
|
+
index: delta.index,
|
|
354
|
+
oldTarget: serializedRef(delta.oldTarget),
|
|
355
|
+
oldResolveInfo: nodeBaseReader.resolveInfoFor!(delta.oldTarget!)!,
|
|
356
|
+
newTarget: serializedRef(delta.newTarget),
|
|
357
|
+
newResolveInfo: nodeBaseReader.resolveInfoFor!(delta.newTarget!)!
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
if (delta instanceof EntryMovedFromOtherReferenceDelta) {
|
|
361
|
+
return completed<EntryMovedFromOtherReferenceEvent>("EntryMovedFromOtherReference", { // § 6.6.6.4
|
|
362
|
+
newParent: delta.newParent.id,
|
|
363
|
+
newReference: metaPointerFor(delta.newReference),
|
|
364
|
+
newIndex: delta.newIndex,
|
|
365
|
+
oldParent: delta.oldParent.id,
|
|
366
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
367
|
+
oldIndex: delta.oldIndex,
|
|
368
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
369
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
if (delta instanceof EntryMovedFromOtherReferenceInSameParentDelta) {
|
|
373
|
+
return completed<EntryMovedFromOtherReferenceInSameParentEvent>("EntryMovedFromOtherReferenceInSameParent", { // § 6.6.6.5
|
|
374
|
+
parent: delta.parent.id,
|
|
375
|
+
newReference: metaPointerFor(delta.newReference),
|
|
376
|
+
newIndex: delta.newIndex,
|
|
377
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
378
|
+
oldIndex: delta.oldIndex,
|
|
379
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
380
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
if (delta instanceof EntryMovedInSameReferenceDelta) {
|
|
384
|
+
return completed<EntryMovedInSameReferenceEvent>("EntryMovedInSameReference", { // § 6.6.6.6
|
|
385
|
+
parent: delta.parent.id,
|
|
386
|
+
reference: metaPointerFor(delta.reference),
|
|
387
|
+
oldIndex: delta.oldIndex,
|
|
388
|
+
newIndex: delta.newIndex,
|
|
389
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
390
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
if (delta instanceof EntryMovedAndReplacedFromOtherReferenceDelta) {
|
|
394
|
+
return completed<EntryMovedAndReplacedFromOtherReferenceEvent>("EntryMovedAndReplacedFromOtherReference", { // § 6.6.6.7
|
|
395
|
+
newParent: delta.newParent.id,
|
|
396
|
+
newReference: metaPointerFor(delta.newReference),
|
|
397
|
+
newIndex: delta.newIndex,
|
|
398
|
+
replacedTarget: serializedRef(delta.replacedTarget),
|
|
399
|
+
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!,
|
|
400
|
+
oldParent: delta.oldParent.id,
|
|
401
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
402
|
+
oldIndex: delta.oldIndex,
|
|
403
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
404
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
405
|
+
})
|
|
406
|
+
}
|
|
407
|
+
if (delta instanceof EntryMovedAndReplacedFromOtherReferenceInSameParentDelta) {
|
|
408
|
+
return completed<EntryMovedAndReplacedFromOtherReferenceInSameParentEvent>("EntryMovedAndReplacedFromOtherReferenceInSameParent", { // § 6.6.6.8
|
|
409
|
+
parent: delta.parent.id,
|
|
410
|
+
newReference: metaPointerFor(delta.newReference),
|
|
411
|
+
newIndex: delta.newIndex,
|
|
412
|
+
replacedTarget: serializedRef(delta.replacedTarget),
|
|
413
|
+
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!,
|
|
414
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
415
|
+
oldIndex: delta.oldIndex,
|
|
416
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
417
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
if (delta instanceof EntryMovedAndReplacedInSameReferenceDelta) {
|
|
421
|
+
return completed<EntryMovedAndReplacedInSameReferenceEvent>("EntryMovedAndReplacedInSameReference", { // § 6.6.6.9
|
|
422
|
+
parent: delta.parent.id,
|
|
423
|
+
reference: metaPointerFor(delta.reference),
|
|
424
|
+
oldIndex: delta.oldIndex,
|
|
425
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
426
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!,
|
|
427
|
+
newIndex: delta.newIndex,
|
|
428
|
+
replacedTarget: serializedRef(delta.replacedTarget),
|
|
429
|
+
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!
|
|
430
|
+
})
|
|
431
|
+
}
|
|
432
|
+
if (delta instanceof CompositeDelta) {
|
|
433
|
+
return completed<CompositeEvent>("CompositeEvent", { // § 6.6.7.1
|
|
434
|
+
parts: delta.parts
|
|
435
|
+
.map((part) => translated(part))
|
|
436
|
+
.filter((event) => event !== undefined) as Event[]
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
if (delta instanceof NoOpDelta) {
|
|
440
|
+
return completed<NoOpEvent>("NoOp", {})
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
throw new Error(`can't handle delta of type ${delta.constructor.name}`)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return [translated(delta), sequenceNumber]
|
|
447
|
+
}
|
|
19
448
|
|
|
@@ -54,7 +54,12 @@ import {
|
|
|
54
54
|
ReferenceChangedDelta,
|
|
55
55
|
ReferenceDeletedDelta
|
|
56
56
|
} from "@lionweb/class-core"
|
|
57
|
-
import {
|
|
57
|
+
import {
|
|
58
|
+
builtinPropertyValueDeserializer,
|
|
59
|
+
featureResolversFor,
|
|
60
|
+
PropertyValueDeserializer,
|
|
61
|
+
unresolved
|
|
62
|
+
} from "@lionweb/core"
|
|
58
63
|
import { LionWebId, LionWebJsonChunk } from "@lionweb/json"
|
|
59
64
|
import {
|
|
60
65
|
AnnotationAddedEvent,
|
|
@@ -89,7 +94,7 @@ import {
|
|
|
89
94
|
ReferenceAddedEvent,
|
|
90
95
|
ReferenceChangedEvent,
|
|
91
96
|
ReferenceDeletedEvent
|
|
92
|
-
} from "../payload/
|
|
97
|
+
} from "../payload/index.js"
|
|
93
98
|
|
|
94
99
|
/**
|
|
95
100
|
* Type def. for a function that translates {@link Event events} to their corresponding {@link IDelta deltas},
|
|
@@ -101,20 +106,24 @@ export type EventToDeltaTranslator = (event: Event, idMapping: IdMapping) => IDe
|
|
|
101
106
|
* @return a {@link EventToDeltaTranslator} for the languages given as {@link ILanguageBase language bases},
|
|
102
107
|
* with the given {@link IdMapping `idMapping`} and {@link Deserializer `deserialized` deserializer function}.
|
|
103
108
|
*/
|
|
104
|
-
export const eventToDeltaTranslator = (
|
|
109
|
+
export const eventToDeltaTranslator = (
|
|
110
|
+
languageBases: ILanguageBase[],
|
|
111
|
+
deserialized: Deserializer<INodeBase[]>,
|
|
112
|
+
propertyValueDeserializer: PropertyValueDeserializer = builtinPropertyValueDeserializer
|
|
113
|
+
): EventToDeltaTranslator => {
|
|
105
114
|
|
|
106
115
|
const eventAsDelta = (event: Event, idMapping: IdMapping): IDelta | undefined => {
|
|
107
116
|
|
|
108
117
|
const deserializedNodeFrom = (chunk: LionWebJsonChunk): INodeBase => {
|
|
109
|
-
const nodes = deserialized(chunk,
|
|
118
|
+
const nodes = deserialized(chunk, /* dependentNodes: */ [], idMapping) // (deserializer should take care of installing delta receiver)
|
|
110
119
|
if (nodes.length !== 1) {
|
|
111
120
|
throw new Error(`expected exactly 1 root node in deserialization of chunk in event, but got ${nodes.length}`)
|
|
112
121
|
}
|
|
113
122
|
return nodes[0]
|
|
114
123
|
}
|
|
115
124
|
const { resolvedPropertyFrom, resolvedContainmentFrom, resolvedReferenceFrom } = featureResolversFor(languageBases.map(({language}) => language));
|
|
116
|
-
const resolvedRefTo = (ref: LionWebId |
|
|
117
|
-
ref ===
|
|
125
|
+
const resolvedRefTo = (ref: LionWebId | typeof unresolved) =>
|
|
126
|
+
ref === unresolved ? unresolved : idMapping.fromId(ref)
|
|
118
127
|
|
|
119
128
|
switch (event.messageKind) {
|
|
120
129
|
|
|
@@ -132,25 +141,22 @@ export const eventToDeltaTranslator = (languageBases: ILanguageBase[], deseriali
|
|
|
132
141
|
return undefined
|
|
133
142
|
}
|
|
134
143
|
case "PropertyAdded": { // § 6.6.3.1
|
|
135
|
-
|
|
136
|
-
const { node, property, newValue } = event as PropertyAddedEvent<any>
|
|
144
|
+
const { node, property, newValue } = event as PropertyAddedEvent
|
|
137
145
|
const resolvedNode = idMapping.fromId(node)
|
|
138
146
|
const resolvedProperty = resolvedPropertyFrom(property, resolvedNode.classifier)
|
|
139
|
-
return new PropertyAddedDelta(resolvedNode, resolvedProperty, newValue)
|
|
147
|
+
return new PropertyAddedDelta(resolvedNode, resolvedProperty, propertyValueDeserializer.deserializeValue(newValue, resolvedProperty))
|
|
140
148
|
}
|
|
141
149
|
case "PropertyDeleted": { // § 6.6.3.2
|
|
142
|
-
|
|
143
|
-
const { node, property, oldValue } = event as PropertyDeletedEvent<any>
|
|
150
|
+
const { node, property, oldValue } = event as PropertyDeletedEvent
|
|
144
151
|
const resolvedNode = idMapping.fromId(node)
|
|
145
152
|
const resolvedProperty = resolvedPropertyFrom(property, resolvedNode.classifier)
|
|
146
|
-
return new PropertyDeletedDelta(resolvedNode, resolvedProperty, oldValue)
|
|
153
|
+
return new PropertyDeletedDelta(resolvedNode, resolvedProperty, propertyValueDeserializer.deserializeValue(oldValue, resolvedProperty))
|
|
147
154
|
}
|
|
148
155
|
case "PropertyChanged": { // § 6.6.3.3
|
|
149
|
-
|
|
150
|
-
const { node, property, newValue, oldValue } = event as PropertyChangedEvent<any>
|
|
156
|
+
const { node, property, newValue, oldValue } = event as PropertyChangedEvent
|
|
151
157
|
const resolvedNode = idMapping.fromId(node)
|
|
152
158
|
const resolvedProperty = resolvedPropertyFrom(property, resolvedNode.classifier)
|
|
153
|
-
return new PropertyChangedDelta(resolvedNode, resolvedProperty, oldValue, newValue)
|
|
159
|
+
return new PropertyChangedDelta(resolvedNode, resolvedProperty, propertyValueDeserializer.deserializeValue(oldValue, resolvedProperty), propertyValueDeserializer.deserializeValue(newValue, resolvedProperty))
|
|
154
160
|
}
|
|
155
161
|
case "ChildAdded": { // § 6.6.4.1
|
|
156
162
|
const { parent, newChild, containment, index } = event as ChildAddedEvent
|
package/src/translators/index.ts
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
// SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
|
|
16
16
|
// SPDX-License-Identifier: Apache-2.0
|
|
17
17
|
|
|
18
|
-
export {
|
|
18
|
+
export { deltaToCommandTranslator } from "./delta-to-command.js"
|
|
19
|
+
export { deltaToEventTranslator } from "./delta-to-event.js"
|
|
19
20
|
export { eventToDeltaTranslator } from "./event-to-delta.js"
|
|
20
21
|
export type { EventToDeltaTranslator } from "./event-to-delta.js"
|
|
21
22
|
|