@lionweb/delta-protocol-common 0.7.1 → 0.7.2-beta.1
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 +8 -1
- package/dist/payload/event-types.d.ts +1 -1
- package/dist/payload/event-types.d.ts.map +1 -1
- package/dist/payload/event-types.js +1 -1
- package/dist/payload/event-types.js.map +1 -1
- package/dist/translators/delta-to-command.d.ts +5 -2
- package/dist/translators/delta-to-command.d.ts.map +1 -1
- package/dist/translators/delta-to-command.js +7 -3
- package/dist/translators/delta-to-command.js.map +1 -1
- package/dist/translators/delta-to-event.d.ts +3 -3
- package/dist/translators/delta-to-event.d.ts.map +1 -1
- package/dist/translators/delta-to-event.js +317 -314
- package/dist/translators/delta-to-event.js.map +1 -1
- package/dist/translators/event-to-delta.d.ts.map +1 -1
- package/dist/translators/event-to-delta.js +7 -1
- package/dist/translators/event-to-delta.js.map +1 -1
- package/package.json +5 -5
- package/src/payload/event-types.ts +2 -2
- package/src/translators/delta-to-command.ts +285 -279
- package/src/translators/delta-to-event.ts +8 -6
- package/src/translators/event-to-delta.ts +7 -1
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
ReferenceDeletedDelta,
|
|
52
52
|
serializeNodeBases
|
|
53
53
|
} from "@lionweb/class-core"
|
|
54
|
-
import { nodeBaseReader } from "@lionweb/class-core/dist/serializer.js"
|
|
54
|
+
import { nodeBaseReader, propertyValueSerializerWith } from "@lionweb/class-core/dist/serializer.js"
|
|
55
55
|
import { builtinPropertyValueSerializer, metaPointerFor, PropertyValueSerializer, serializedRef } from "@lionweb/core"
|
|
56
56
|
import { LionWebId } from "@lionweb/json"
|
|
57
57
|
import {
|
|
@@ -98,289 +98,295 @@ import {
|
|
|
98
98
|
export type DeltaToCommandTranslator = (delta: IDelta, commandId: LionWebId) => Command | undefined
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
* @return a {@link
|
|
101
|
+
* @return a {@link DeltaToCommandTranslator} function instance
|
|
102
|
+
* that translates a given {@link IDelta `delta`} into a {@link Command command} with the given `commandId`.
|
|
103
|
+
* Serialization of primitively-typed values is governed by the given {@link PropertyValueSerializer `primitiveValueSerializer`},
|
|
104
|
+
* which defaults to the {@link builtinPropertyValueSerializer}.
|
|
102
105
|
*/
|
|
103
|
-
export const deltaToCommandTranslator = (
|
|
106
|
+
export const deltaToCommandTranslator = (
|
|
107
|
+
primitiveValueSerializer: PropertyValueSerializer = builtinPropertyValueSerializer
|
|
108
|
+
) => {
|
|
109
|
+
const propertyValueSerializer = propertyValueSerializerWith({ primitiveValueSerializer })
|
|
104
110
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// in order of the specification (§ 6.5):
|
|
111
|
+
const translated: DeltaToCommandTranslator = (delta, commandId) => {
|
|
112
|
+
const completed = <CT extends Command>(
|
|
113
|
+
commandName: CT["messageKind"],
|
|
114
|
+
partialCommand: Omit<CT, "messageKind" | "commandId" | "protocolMessages">
|
|
115
|
+
) => ({
|
|
116
|
+
messageKind: commandName,
|
|
117
|
+
commandId,
|
|
118
|
+
...partialCommand,
|
|
119
|
+
protocolMessages: []
|
|
120
|
+
})
|
|
117
121
|
|
|
118
|
-
|
|
119
|
-
return completed<AddPartitionCommand>("AddPartition", { // § 6.5.2.1
|
|
120
|
-
newPartition: serializeNodeBases([delta.newPartition])
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
if (delta instanceof PartitionDeletedDelta) {
|
|
124
|
-
return completed<DeletePartitionCommand>("DeletePartition", { // § 6.5.2.2
|
|
125
|
-
deletedPartition: delta.deletedPartition.id
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
if (delta instanceof PropertyAddedDelta) {
|
|
129
|
-
return completed<AddPropertyCommand>("AddProperty", { // § 6.5.4.1
|
|
130
|
-
node: delta.node.id,
|
|
131
|
-
property: metaPointerFor(delta.property),
|
|
132
|
-
newValue: propertyValueSerializer.serializeValue(delta.value, delta.property)!
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
if (delta instanceof PropertyDeletedDelta) {
|
|
136
|
-
return completed<DeletePropertyCommand>("DeleteProperty", { // § 6.5.4.2
|
|
137
|
-
node: delta.node.id,
|
|
138
|
-
property: metaPointerFor(delta.property)
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
if (delta instanceof PropertyChangedDelta) {
|
|
142
|
-
return completed<ChangePropertyCommand>("ChangeProperty", { // § 6.5.4.3
|
|
143
|
-
node: delta.node.id,
|
|
144
|
-
property: metaPointerFor(delta.property),
|
|
145
|
-
newValue: propertyValueSerializer.serializeValue(delta.newValue, delta.property)!
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
if (delta instanceof ChildAddedDelta) {
|
|
149
|
-
return completed<AddChildCommand>("AddChild", { // § 6.5.5.1
|
|
150
|
-
parent: delta.parent.id,
|
|
151
|
-
newChild: serializeNodeBases([delta.newChild]),
|
|
152
|
-
containment: metaPointerFor(delta.containment),
|
|
153
|
-
index: delta.index
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
if (delta instanceof ChildDeletedDelta) {
|
|
157
|
-
return completed<DeleteChildCommand>("DeleteChild", { // § 6.5.5.2
|
|
158
|
-
parent: delta.parent.id,
|
|
159
|
-
containment: metaPointerFor(delta.containment),
|
|
160
|
-
index: delta.index,
|
|
161
|
-
deletedChild: delta.deletedChild.id
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
if (delta instanceof ChildReplacedDelta) {
|
|
165
|
-
return completed<ReplaceChildCommand>("ReplaceChild", { // § 6.5.5.3
|
|
166
|
-
newChild: serializeNodeBases([delta.newChild]),
|
|
167
|
-
parent: delta.parent.id,
|
|
168
|
-
containment: metaPointerFor(delta.containment),
|
|
169
|
-
index: delta.index,
|
|
170
|
-
replacedChild: delta.replacedChild.id
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
if (delta instanceof ChildMovedFromOtherContainmentDelta) {
|
|
174
|
-
return completed<MoveChildFromOtherContainmentCommand>("MoveChildFromOtherContainment", { // § 6.5.5.4
|
|
175
|
-
newParent: delta.newParent.id,
|
|
176
|
-
newContainment: metaPointerFor(delta.newContainment),
|
|
177
|
-
newIndex: delta.newIndex,
|
|
178
|
-
movedChild: delta.movedChild.id
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
if (delta instanceof ChildMovedFromOtherContainmentInSameParentDelta) {
|
|
182
|
-
return completed<MoveChildFromOtherContainmentInSameParentCommand>("MoveChildFromOtherContainmentInSameParent", { // § 6.5.5.5
|
|
183
|
-
newContainment: metaPointerFor(delta.newContainment),
|
|
184
|
-
newIndex: delta.newIndex,
|
|
185
|
-
movedChild: delta.movedChild.id,
|
|
186
|
-
parent: delta.parent.id,
|
|
187
|
-
oldContainment: metaPointerFor(delta.oldContainment),
|
|
188
|
-
oldIndex: delta.oldIndex
|
|
189
|
-
})
|
|
190
|
-
}
|
|
191
|
-
if (delta instanceof ChildMovedInSameContainmentDelta) {
|
|
192
|
-
return completed<MoveChildInSameContainmentCommand>("MoveChildInSameContainment", { // § 6.5.5.6
|
|
193
|
-
newIndex: delta.newIndex,
|
|
194
|
-
movedChild: delta.movedChild.id
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
if (delta instanceof ChildMovedAndReplacedFromOtherContainmentDelta) {
|
|
198
|
-
return completed<MoveAndReplaceChildFromOtherContainmentCommand>("MoveAndReplaceChildFromOtherContainment", { // § 6.5.5.7
|
|
199
|
-
newParent: delta.newParent.id,
|
|
200
|
-
newContainment: metaPointerFor(delta.newContainment),
|
|
201
|
-
newIndex: delta.newIndex,
|
|
202
|
-
replacedChild: delta.replacedChild.id,
|
|
203
|
-
movedChild: delta.movedChild.id
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
if (delta instanceof ChildMovedAndReplacedFromOtherContainmentInSameParentDelta) {
|
|
207
|
-
return completed<MoveAndReplaceChildFromOtherContainmentInSameParentCommand>("MoveAndReplaceChildFromOtherContainmentInSameParent", { // § 6.5.5.8
|
|
208
|
-
newContainment: metaPointerFor(delta.newContainment),
|
|
209
|
-
newIndex: delta.newIndex,
|
|
210
|
-
replacedChild: delta.replacedChild.id,
|
|
211
|
-
movedChild: delta.movedChild.id
|
|
212
|
-
})
|
|
213
|
-
}
|
|
214
|
-
if (delta instanceof ChildMovedAndReplacedInSameContainmentDelta) {
|
|
215
|
-
return completed<MoveAndReplaceChildInSameContainmentCommand>("MoveAndReplaceChildInSameContainment", { // § 6.5.5.9
|
|
216
|
-
newIndex: delta.newIndex,
|
|
217
|
-
replacedChild: delta.replacedChild.id
|
|
218
|
-
})
|
|
219
|
-
}
|
|
220
|
-
if (delta instanceof AnnotationAddedDelta) {
|
|
221
|
-
return completed<AddAnnotationCommand>("AddAnnotation", { // § 6.5.6.1
|
|
222
|
-
parent: delta.parent.id,
|
|
223
|
-
index: delta.index,
|
|
224
|
-
newAnnotation: serializeNodeBases([delta.newAnnotation])
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
if (delta instanceof AnnotationDeletedDelta) {
|
|
228
|
-
return completed<DeleteAnnotationCommand>("DeleteAnnotation", { // § 6.5.6.2
|
|
229
|
-
parent: delta.parent.id,
|
|
230
|
-
deletedAnnotation: delta.deletedAnnotation.id,
|
|
231
|
-
index: delta.index
|
|
232
|
-
})
|
|
233
|
-
}
|
|
234
|
-
if (delta instanceof AnnotationReplacedDelta) {
|
|
235
|
-
return completed<ReplaceAnnotationCommand>("ReplaceAnnotation", { // § 6.5.6.3
|
|
236
|
-
newAnnotation: serializeNodeBases([delta.newAnnotation]),
|
|
237
|
-
parent: delta.parent.id,
|
|
238
|
-
index: delta.index,
|
|
239
|
-
replacedAnnotation: delta.replacedAnnotation.id
|
|
240
|
-
})
|
|
241
|
-
}
|
|
242
|
-
if (delta instanceof AnnotationMovedFromOtherParentDelta) {
|
|
243
|
-
return completed<MoveAnnotationFromOtherParentCommand>("MoveAnnotationFromOtherParent", { // § 6.5.6.4
|
|
244
|
-
newParent: delta.newParent.id,
|
|
245
|
-
newIndex: delta.newIndex,
|
|
246
|
-
movedAnnotation: delta.movedAnnotation.id
|
|
247
|
-
})
|
|
248
|
-
}
|
|
249
|
-
if (delta instanceof AnnotationMovedInSameParentDelta) {
|
|
250
|
-
return completed<MoveAnnotationInSameParentCommand>("MoveAnnotationInSameParent", { // § 6.5.6.5
|
|
251
|
-
newIndex: delta.newIndex,
|
|
252
|
-
movedAnnotation: delta.movedAnnotation.id
|
|
253
|
-
})
|
|
254
|
-
}
|
|
255
|
-
if (delta instanceof AnnotationMovedAndReplacedFromOtherParentDelta) {
|
|
256
|
-
return completed<MoveAndReplaceAnnotationFromOtherParentCommand>("MoveAndReplaceAnnotationFromOtherParent", { // § 6.5.6.6
|
|
257
|
-
newParent: delta.newParent.id,
|
|
258
|
-
newIndex: delta.newIndex,
|
|
259
|
-
replacedAnnotation: delta.replacedAnnotation.id,
|
|
260
|
-
movedAnnotation: delta.movedAnnotation.id
|
|
261
|
-
})
|
|
262
|
-
}
|
|
263
|
-
if (delta instanceof AnnotationMovedAndReplacedInSameParentDelta) {
|
|
264
|
-
return completed<MoveAndReplaceAnnotationInSameParentCommand>("MoveAndReplaceAnnotationInSameParent", { // § 6.5.6.7
|
|
265
|
-
newIndex: delta.newIndex,
|
|
266
|
-
replacedAnnotation: delta.replacedAnnotation.id,
|
|
267
|
-
movedAnnotation: delta.movedAnnotation.id
|
|
268
|
-
})
|
|
269
|
-
}
|
|
270
|
-
if (delta instanceof ReferenceAddedDelta) {
|
|
271
|
-
return completed<AddReferenceCommand>("AddReference", { // § 6.5.7.1
|
|
272
|
-
parent: delta.parent.id,
|
|
273
|
-
reference: metaPointerFor(delta.reference),
|
|
274
|
-
index: delta.index,
|
|
275
|
-
newTarget: serializedRef(delta.newTarget),
|
|
276
|
-
newResolveInfo: nodeBaseReader.resolveInfoFor!(delta.newTarget!)!
|
|
277
|
-
})
|
|
278
|
-
}
|
|
279
|
-
if (delta instanceof ReferenceDeletedDelta) {
|
|
280
|
-
return completed<DeleteReferenceCommand>("DeleteReference", { // § 6.5.7.2
|
|
281
|
-
parent: delta.parent.id,
|
|
282
|
-
reference: metaPointerFor(delta.reference),
|
|
283
|
-
index: delta.index,
|
|
284
|
-
deletedTarget: serializedRef(delta.deletedTarget),
|
|
285
|
-
deletedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.deletedTarget!)!
|
|
286
|
-
})
|
|
287
|
-
}
|
|
288
|
-
if (delta instanceof ReferenceChangedDelta) {
|
|
289
|
-
return completed<ChangeReferenceCommand>("ChangeReference", { // § 6.5.7.3
|
|
290
|
-
parent: delta.parent.id,
|
|
291
|
-
reference: metaPointerFor(delta.reference),
|
|
292
|
-
index: delta.index,
|
|
293
|
-
oldTarget: serializedRef(delta.oldTarget),
|
|
294
|
-
oldResolveInfo: nodeBaseReader.resolveInfoFor!(delta.oldTarget!)!,
|
|
295
|
-
newTarget: serializedRef(delta.newTarget),
|
|
296
|
-
newResolveInfo: nodeBaseReader.resolveInfoFor!(delta.oldTarget!)!
|
|
297
|
-
})
|
|
298
|
-
}
|
|
299
|
-
if (delta instanceof EntryMovedFromOtherReferenceDelta) {
|
|
300
|
-
return completed<MoveEntryFromOtherReferenceCommand>("MoveEntryFromOtherReference", { // § 6.5.7.4
|
|
301
|
-
newParent: delta.newParent.id,
|
|
302
|
-
newReference: metaPointerFor(delta.newReference),
|
|
303
|
-
newIndex: delta.newIndex,
|
|
304
|
-
oldParent: delta.oldParent.id,
|
|
305
|
-
oldReference: metaPointerFor(delta.oldReference),
|
|
306
|
-
oldIndex: delta.oldIndex,
|
|
307
|
-
movedTarget: serializedRef(delta.movedTarget),
|
|
308
|
-
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
309
|
-
})
|
|
310
|
-
}
|
|
311
|
-
if (delta instanceof EntryMovedFromOtherReferenceInSameParentDelta) {
|
|
312
|
-
return completed<MoveEntryFromOtherReferenceInSameParentCommand>("MoveEntryFromOtherReferenceInSameParent", { // § 6.5.7.5
|
|
313
|
-
parent: delta.parent.id,
|
|
314
|
-
newReference: metaPointerFor(delta.newReference),
|
|
315
|
-
newIndex: delta.newIndex,
|
|
316
|
-
oldIndex: delta.oldIndex,
|
|
317
|
-
movedTarget: serializedRef(delta.movedTarget),
|
|
318
|
-
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
319
|
-
})
|
|
320
|
-
}
|
|
321
|
-
if (delta instanceof EntryMovedInSameReferenceDelta) {
|
|
322
|
-
return completed<MoveEntryInSameReferenceCommand>("MoveEntryInSameReference", { // § 6.5.7.6
|
|
323
|
-
parent: delta.parent.id,
|
|
324
|
-
reference: metaPointerFor(delta.reference),
|
|
325
|
-
oldIndex: delta.oldIndex,
|
|
326
|
-
newIndex: delta.newIndex,
|
|
327
|
-
movedTarget: serializedRef(delta.movedTarget),
|
|
328
|
-
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
329
|
-
})
|
|
330
|
-
}
|
|
331
|
-
if (delta instanceof EntryMovedAndReplacedFromOtherReferenceDelta) {
|
|
332
|
-
return completed<MoveAndReplaceEntryFromOtherReferenceCommand>("MoveAndReplaceEntryFromOtherReference", { // § 6.5.7.7
|
|
333
|
-
newParent: delta.newParent.id,
|
|
334
|
-
newReference: metaPointerFor(delta.newReference),
|
|
335
|
-
newIndex: delta.newIndex,
|
|
336
|
-
replacedTarget: serializedRef(delta.replacedTarget),
|
|
337
|
-
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!,
|
|
338
|
-
oldParent: delta.oldParent.id,
|
|
339
|
-
oldReference: metaPointerFor(delta.oldReference),
|
|
340
|
-
oldIndex: delta.oldIndex,
|
|
341
|
-
movedTarget: serializedRef(delta.movedTarget),
|
|
342
|
-
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
343
|
-
})
|
|
344
|
-
}
|
|
345
|
-
if (delta instanceof EntryMovedAndReplacedFromOtherReferenceInSameParentDelta) {
|
|
346
|
-
return completed<MoveAndReplaceEntryFromOtherReferenceInSameParentCommand>("MoveAndReplaceEntryFromOtherReferenceInSameParent", { // § 6.5.7.8
|
|
347
|
-
parent: delta.parent.id,
|
|
348
|
-
newReference: metaPointerFor(delta.newReference),
|
|
349
|
-
newIndex: delta.newIndex,
|
|
350
|
-
replacedTarget: serializedRef(delta.replacedTarget),
|
|
351
|
-
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!,
|
|
352
|
-
oldReference: metaPointerFor(delta.oldReference),
|
|
353
|
-
oldIndex: delta.oldIndex,
|
|
354
|
-
movedTarget: serializedRef(delta.movedTarget),
|
|
355
|
-
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
356
|
-
})
|
|
357
|
-
}
|
|
358
|
-
if (delta instanceof EntryMovedAndReplacedInSameReferenceDelta) {
|
|
359
|
-
return completed<MoveAndReplaceEntryInSameReferenceCommand>("MoveAndReplaceEntryInSameReference", { // § 6.5.7.9
|
|
360
|
-
parent: delta.parent.id,
|
|
361
|
-
reference: metaPointerFor(delta.reference),
|
|
362
|
-
oldIndex: delta.oldIndex,
|
|
363
|
-
movedTarget: serializedRef(delta.movedTarget),
|
|
364
|
-
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!,
|
|
365
|
-
newIndex: delta.newIndex,
|
|
366
|
-
replacedTarget: serializedRef(delta.replacedTarget),
|
|
367
|
-
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!
|
|
368
|
-
})
|
|
369
|
-
}
|
|
370
|
-
if (delta instanceof CompositeDelta) {
|
|
371
|
-
return completed<CompositeCommand>("CompositeCommand", { // § 6.5.8.1
|
|
372
|
-
parts: delta.parts
|
|
373
|
-
.map((part, index) => translated(part, `${commandId}-${index}`)) // TODO inject proper ID generator!
|
|
374
|
-
.filter((command) => command !== undefined) as Command[]
|
|
375
|
-
})
|
|
376
|
-
}
|
|
377
|
-
if (delta instanceof NoOpDelta) {
|
|
378
|
-
return undefined
|
|
379
|
-
}
|
|
122
|
+
// in order of the specification (§ 6.5):
|
|
380
123
|
|
|
381
|
-
|
|
124
|
+
if (delta instanceof PartitionAddedDelta) {
|
|
125
|
+
return completed<AddPartitionCommand>("AddPartition", { // § 6.5.2.1
|
|
126
|
+
newPartition: serializeNodeBases([delta.newPartition])
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
if (delta instanceof PartitionDeletedDelta) {
|
|
130
|
+
return completed<DeletePartitionCommand>("DeletePartition", { // § 6.5.2.2
|
|
131
|
+
deletedPartition: delta.deletedPartition.id
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
if (delta instanceof PropertyAddedDelta) {
|
|
135
|
+
return completed<AddPropertyCommand>("AddProperty", { // § 6.5.4.1
|
|
136
|
+
node: delta.node.id,
|
|
137
|
+
property: metaPointerFor(delta.property),
|
|
138
|
+
newValue: propertyValueSerializer.serializeValue(delta.value, delta.property)!
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
if (delta instanceof PropertyDeletedDelta) {
|
|
142
|
+
return completed<DeletePropertyCommand>("DeleteProperty", { // § 6.5.4.2
|
|
143
|
+
node: delta.node.id,
|
|
144
|
+
property: metaPointerFor(delta.property)
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
if (delta instanceof PropertyChangedDelta) {
|
|
148
|
+
return completed<ChangePropertyCommand>("ChangeProperty", { // § 6.5.4.3
|
|
149
|
+
node: delta.node.id,
|
|
150
|
+
property: metaPointerFor(delta.property),
|
|
151
|
+
newValue: propertyValueSerializer.serializeValue(delta.newValue, delta.property)!
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
if (delta instanceof ChildAddedDelta) {
|
|
155
|
+
return completed<AddChildCommand>("AddChild", { // § 6.5.5.1
|
|
156
|
+
parent: delta.parent.id,
|
|
157
|
+
newChild: serializeNodeBases([delta.newChild]),
|
|
158
|
+
containment: metaPointerFor(delta.containment),
|
|
159
|
+
index: delta.index
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
if (delta instanceof ChildDeletedDelta) {
|
|
163
|
+
return completed<DeleteChildCommand>("DeleteChild", { // § 6.5.5.2
|
|
164
|
+
parent: delta.parent.id,
|
|
165
|
+
containment: metaPointerFor(delta.containment),
|
|
166
|
+
index: delta.index,
|
|
167
|
+
deletedChild: delta.deletedChild.id
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
if (delta instanceof ChildReplacedDelta) {
|
|
171
|
+
return completed<ReplaceChildCommand>("ReplaceChild", { // § 6.5.5.3
|
|
172
|
+
newChild: serializeNodeBases([delta.newChild]),
|
|
173
|
+
parent: delta.parent.id,
|
|
174
|
+
containment: metaPointerFor(delta.containment),
|
|
175
|
+
index: delta.index,
|
|
176
|
+
replacedChild: delta.replacedChild.id
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
if (delta instanceof ChildMovedFromOtherContainmentDelta) {
|
|
180
|
+
return completed<MoveChildFromOtherContainmentCommand>("MoveChildFromOtherContainment", { // § 6.5.5.4
|
|
181
|
+
newParent: delta.newParent.id,
|
|
182
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
183
|
+
newIndex: delta.newIndex,
|
|
184
|
+
movedChild: delta.movedChild.id
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
if (delta instanceof ChildMovedFromOtherContainmentInSameParentDelta) {
|
|
188
|
+
return completed<MoveChildFromOtherContainmentInSameParentCommand>("MoveChildFromOtherContainmentInSameParent", { // § 6.5.5.5
|
|
189
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
190
|
+
newIndex: delta.newIndex,
|
|
191
|
+
movedChild: delta.movedChild.id,
|
|
192
|
+
parent: delta.parent.id,
|
|
193
|
+
oldContainment: metaPointerFor(delta.oldContainment),
|
|
194
|
+
oldIndex: delta.oldIndex
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
if (delta instanceof ChildMovedInSameContainmentDelta) {
|
|
198
|
+
return completed<MoveChildInSameContainmentCommand>("MoveChildInSameContainment", { // § 6.5.5.6
|
|
199
|
+
newIndex: delta.newIndex,
|
|
200
|
+
movedChild: delta.movedChild.id
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
if (delta instanceof ChildMovedAndReplacedFromOtherContainmentDelta) {
|
|
204
|
+
return completed<MoveAndReplaceChildFromOtherContainmentCommand>("MoveAndReplaceChildFromOtherContainment", { // § 6.5.5.7
|
|
205
|
+
newParent: delta.newParent.id,
|
|
206
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
207
|
+
newIndex: delta.newIndex,
|
|
208
|
+
replacedChild: delta.replacedChild.id,
|
|
209
|
+
movedChild: delta.movedChild.id
|
|
210
|
+
})
|
|
211
|
+
}
|
|
212
|
+
if (delta instanceof ChildMovedAndReplacedFromOtherContainmentInSameParentDelta) {
|
|
213
|
+
return completed<MoveAndReplaceChildFromOtherContainmentInSameParentCommand>("MoveAndReplaceChildFromOtherContainmentInSameParent", { // § 6.5.5.8
|
|
214
|
+
newContainment: metaPointerFor(delta.newContainment),
|
|
215
|
+
newIndex: delta.newIndex,
|
|
216
|
+
replacedChild: delta.replacedChild.id,
|
|
217
|
+
movedChild: delta.movedChild.id
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
if (delta instanceof ChildMovedAndReplacedInSameContainmentDelta) {
|
|
221
|
+
return completed<MoveAndReplaceChildInSameContainmentCommand>("MoveAndReplaceChildInSameContainment", { // § 6.5.5.9
|
|
222
|
+
newIndex: delta.newIndex,
|
|
223
|
+
replacedChild: delta.replacedChild.id
|
|
224
|
+
})
|
|
225
|
+
}
|
|
226
|
+
if (delta instanceof AnnotationAddedDelta) {
|
|
227
|
+
return completed<AddAnnotationCommand>("AddAnnotation", { // § 6.5.6.1
|
|
228
|
+
parent: delta.parent.id,
|
|
229
|
+
index: delta.index,
|
|
230
|
+
newAnnotation: serializeNodeBases([delta.newAnnotation])
|
|
231
|
+
})
|
|
232
|
+
}
|
|
233
|
+
if (delta instanceof AnnotationDeletedDelta) {
|
|
234
|
+
return completed<DeleteAnnotationCommand>("DeleteAnnotation", { // § 6.5.6.2
|
|
235
|
+
parent: delta.parent.id,
|
|
236
|
+
deletedAnnotation: delta.deletedAnnotation.id,
|
|
237
|
+
index: delta.index
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
if (delta instanceof AnnotationReplacedDelta) {
|
|
241
|
+
return completed<ReplaceAnnotationCommand>("ReplaceAnnotation", { // § 6.5.6.3
|
|
242
|
+
newAnnotation: serializeNodeBases([delta.newAnnotation]),
|
|
243
|
+
parent: delta.parent.id,
|
|
244
|
+
index: delta.index,
|
|
245
|
+
replacedAnnotation: delta.replacedAnnotation.id
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
if (delta instanceof AnnotationMovedFromOtherParentDelta) {
|
|
249
|
+
return completed<MoveAnnotationFromOtherParentCommand>("MoveAnnotationFromOtherParent", { // § 6.5.6.4
|
|
250
|
+
newParent: delta.newParent.id,
|
|
251
|
+
newIndex: delta.newIndex,
|
|
252
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
if (delta instanceof AnnotationMovedInSameParentDelta) {
|
|
256
|
+
return completed<MoveAnnotationInSameParentCommand>("MoveAnnotationInSameParent", { // § 6.5.6.5
|
|
257
|
+
newIndex: delta.newIndex,
|
|
258
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
if (delta instanceof AnnotationMovedAndReplacedFromOtherParentDelta) {
|
|
262
|
+
return completed<MoveAndReplaceAnnotationFromOtherParentCommand>("MoveAndReplaceAnnotationFromOtherParent", { // § 6.5.6.6
|
|
263
|
+
newParent: delta.newParent.id,
|
|
264
|
+
newIndex: delta.newIndex,
|
|
265
|
+
replacedAnnotation: delta.replacedAnnotation.id,
|
|
266
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
if (delta instanceof AnnotationMovedAndReplacedInSameParentDelta) {
|
|
270
|
+
return completed<MoveAndReplaceAnnotationInSameParentCommand>("MoveAndReplaceAnnotationInSameParent", { // § 6.5.6.7
|
|
271
|
+
newIndex: delta.newIndex,
|
|
272
|
+
replacedAnnotation: delta.replacedAnnotation.id,
|
|
273
|
+
movedAnnotation: delta.movedAnnotation.id
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
if (delta instanceof ReferenceAddedDelta) {
|
|
277
|
+
return completed<AddReferenceCommand>("AddReference", { // § 6.5.7.1
|
|
278
|
+
parent: delta.parent.id,
|
|
279
|
+
reference: metaPointerFor(delta.reference),
|
|
280
|
+
index: delta.index,
|
|
281
|
+
newTarget: serializedRef(delta.newTarget),
|
|
282
|
+
newResolveInfo: nodeBaseReader.resolveInfoFor!(delta.newTarget!)!
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
if (delta instanceof ReferenceDeletedDelta) {
|
|
286
|
+
return completed<DeleteReferenceCommand>("DeleteReference", { // § 6.5.7.2
|
|
287
|
+
parent: delta.parent.id,
|
|
288
|
+
reference: metaPointerFor(delta.reference),
|
|
289
|
+
index: delta.index,
|
|
290
|
+
deletedTarget: serializedRef(delta.deletedTarget),
|
|
291
|
+
deletedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.deletedTarget!)!
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
if (delta instanceof ReferenceChangedDelta) {
|
|
295
|
+
return completed<ChangeReferenceCommand>("ChangeReference", { // § 6.5.7.3
|
|
296
|
+
parent: delta.parent.id,
|
|
297
|
+
reference: metaPointerFor(delta.reference),
|
|
298
|
+
index: delta.index,
|
|
299
|
+
oldTarget: serializedRef(delta.oldTarget),
|
|
300
|
+
oldResolveInfo: nodeBaseReader.resolveInfoFor!(delta.oldTarget!)!,
|
|
301
|
+
newTarget: serializedRef(delta.newTarget),
|
|
302
|
+
newResolveInfo: nodeBaseReader.resolveInfoFor!(delta.oldTarget!)!
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
if (delta instanceof EntryMovedFromOtherReferenceDelta) {
|
|
306
|
+
return completed<MoveEntryFromOtherReferenceCommand>("MoveEntryFromOtherReference", { // § 6.5.7.4
|
|
307
|
+
newParent: delta.newParent.id,
|
|
308
|
+
newReference: metaPointerFor(delta.newReference),
|
|
309
|
+
newIndex: delta.newIndex,
|
|
310
|
+
oldParent: delta.oldParent.id,
|
|
311
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
312
|
+
oldIndex: delta.oldIndex,
|
|
313
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
314
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
if (delta instanceof EntryMovedFromOtherReferenceInSameParentDelta) {
|
|
318
|
+
return completed<MoveEntryFromOtherReferenceInSameParentCommand>("MoveEntryFromOtherReferenceInSameParent", { // § 6.5.7.5
|
|
319
|
+
parent: delta.parent.id,
|
|
320
|
+
newReference: metaPointerFor(delta.newReference),
|
|
321
|
+
newIndex: delta.newIndex,
|
|
322
|
+
oldIndex: delta.oldIndex,
|
|
323
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
324
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
if (delta instanceof EntryMovedInSameReferenceDelta) {
|
|
328
|
+
return completed<MoveEntryInSameReferenceCommand>("MoveEntryInSameReference", { // § 6.5.7.6
|
|
329
|
+
parent: delta.parent.id,
|
|
330
|
+
reference: metaPointerFor(delta.reference),
|
|
331
|
+
oldIndex: delta.oldIndex,
|
|
332
|
+
newIndex: delta.newIndex,
|
|
333
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
334
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
if (delta instanceof EntryMovedAndReplacedFromOtherReferenceDelta) {
|
|
338
|
+
return completed<MoveAndReplaceEntryFromOtherReferenceCommand>("MoveAndReplaceEntryFromOtherReference", { // § 6.5.7.7
|
|
339
|
+
newParent: delta.newParent.id,
|
|
340
|
+
newReference: metaPointerFor(delta.newReference),
|
|
341
|
+
newIndex: delta.newIndex,
|
|
342
|
+
replacedTarget: serializedRef(delta.replacedTarget),
|
|
343
|
+
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!,
|
|
344
|
+
oldParent: delta.oldParent.id,
|
|
345
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
346
|
+
oldIndex: delta.oldIndex,
|
|
347
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
348
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
349
|
+
})
|
|
350
|
+
}
|
|
351
|
+
if (delta instanceof EntryMovedAndReplacedFromOtherReferenceInSameParentDelta) {
|
|
352
|
+
return completed<MoveAndReplaceEntryFromOtherReferenceInSameParentCommand>("MoveAndReplaceEntryFromOtherReferenceInSameParent", { // § 6.5.7.8
|
|
353
|
+
parent: delta.parent.id,
|
|
354
|
+
newReference: metaPointerFor(delta.newReference),
|
|
355
|
+
newIndex: delta.newIndex,
|
|
356
|
+
replacedTarget: serializedRef(delta.replacedTarget),
|
|
357
|
+
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!,
|
|
358
|
+
oldReference: metaPointerFor(delta.oldReference),
|
|
359
|
+
oldIndex: delta.oldIndex,
|
|
360
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
361
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
if (delta instanceof EntryMovedAndReplacedInSameReferenceDelta) {
|
|
365
|
+
return completed<MoveAndReplaceEntryInSameReferenceCommand>("MoveAndReplaceEntryInSameReference", { // § 6.5.7.9
|
|
366
|
+
parent: delta.parent.id,
|
|
367
|
+
reference: metaPointerFor(delta.reference),
|
|
368
|
+
oldIndex: delta.oldIndex,
|
|
369
|
+
movedTarget: serializedRef(delta.movedTarget),
|
|
370
|
+
movedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.movedTarget!)!,
|
|
371
|
+
newIndex: delta.newIndex,
|
|
372
|
+
replacedTarget: serializedRef(delta.replacedTarget),
|
|
373
|
+
replacedResolveInfo: nodeBaseReader.resolveInfoFor!(delta.replacedTarget!)!
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
if (delta instanceof CompositeDelta) {
|
|
377
|
+
return completed<CompositeCommand>("CompositeCommand", { // § 6.5.8.1
|
|
378
|
+
parts: delta.parts
|
|
379
|
+
.map((part, index) => translated(part, `${commandId}-${index}`)) // TODO inject proper ID generator!
|
|
380
|
+
.filter((command) => command !== undefined) as Command[]
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
if (delta instanceof NoOpDelta) {
|
|
384
|
+
return undefined
|
|
382
385
|
}
|
|
383
386
|
|
|
384
|
-
|
|
387
|
+
throw new Error(`can't handle delta of type ${delta.constructor.name}`)
|
|
385
388
|
}
|
|
386
389
|
|
|
390
|
+
return translated
|
|
391
|
+
}
|
|
392
|
+
|
|
@@ -95,7 +95,7 @@ import {
|
|
|
95
95
|
ReferenceChangedEvent,
|
|
96
96
|
ReferenceDeletedEvent
|
|
97
97
|
} from "../payload/index.js"
|
|
98
|
-
import { nodeBaseReader } from "@lionweb/class-core/dist/serializer.js"
|
|
98
|
+
import { nodeBaseReader, propertyValueSerializerWith } from "@lionweb/class-core/dist/serializer.js"
|
|
99
99
|
|
|
100
100
|
|
|
101
101
|
const allIdsOfDescendantsFrom = (node: INodeBase) =>
|
|
@@ -118,13 +118,14 @@ export type DeltaToEventTranslator = (
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
* @return a {@link DeltaToEventTranslator} instance using the given {@link PropertyValueSerializer}
|
|
122
|
-
*
|
|
121
|
+
* @return a {@link DeltaToEventTranslator} instance using the given {@link PropertyValueSerializer},
|
|
122
|
+
* that's solely used to serialize primitive values, and defaults to the {@link builtinPropertyValueSerializer}.
|
|
123
123
|
*/
|
|
124
124
|
export const deltaToEventTranslator = (
|
|
125
|
-
|
|
126
|
-
): DeltaToEventTranslator =>
|
|
127
|
-
|
|
125
|
+
primitiveValueSerializer: PropertyValueSerializer = builtinPropertyValueSerializer
|
|
126
|
+
): DeltaToEventTranslator => {
|
|
127
|
+
const propertyValueSerializer = propertyValueSerializerWith({ primitiveValueSerializer })
|
|
128
|
+
return (delta, lastUsedSequenceNumber) => {
|
|
128
129
|
|
|
129
130
|
let sequenceNumber = lastUsedSequenceNumber
|
|
130
131
|
const completed = <ET extends Event>(
|
|
@@ -445,4 +446,5 @@ export const deltaToEventTranslator = (
|
|
|
445
446
|
|
|
446
447
|
return [translated(delta), sequenceNumber]
|
|
447
448
|
}
|
|
449
|
+
}
|
|
448
450
|
|
|
@@ -128,6 +128,12 @@ export const eventToDeltaTranslator = (
|
|
|
128
128
|
ref === unresolved ? unresolved : idMapping.fromId(ref)
|
|
129
129
|
|
|
130
130
|
switch (event.messageKind) {
|
|
131
|
+
/*
|
|
132
|
+
* Note: `messageKind` is a property of the `Message` type,
|
|
133
|
+
* which is an interface and not a sum type,
|
|
134
|
+
* so the switching on it is *not* type-safe,
|
|
135
|
+
* and you don't get any assist (completion, exhaustive-check) on the message kind.
|
|
136
|
+
*/
|
|
131
137
|
|
|
132
138
|
// in order of the specification (§ 6.6):
|
|
133
139
|
|
|
@@ -378,7 +384,7 @@ export const eventToDeltaTranslator = (
|
|
|
378
384
|
case "NoOp": { // § 6.6.7.2
|
|
379
385
|
return new NoOpDelta()
|
|
380
386
|
}
|
|
381
|
-
case "
|
|
387
|
+
case "ErrorEvent": { // § 6.6.7.3
|
|
382
388
|
return undefined
|
|
383
389
|
}
|
|
384
390
|
|