@lionweb/delta-protocol-common 0.7.0-beta.23 → 0.7.0-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/payload/command-types.d.ts +4 -4
  2. package/dist/payload/command-types.d.ts.map +1 -1
  3. package/dist/payload/event-types.d.ts +7 -7
  4. package/dist/payload/event-types.d.ts.map +1 -1
  5. package/dist/payload/query-types.d.ts +11 -0
  6. package/dist/payload/query-types.d.ts.map +1 -1
  7. package/dist/payload/query-types.js.map +1 -1
  8. package/dist/translators/delta-to-command.d.ts +9 -1
  9. package/dist/translators/delta-to-command.d.ts.map +1 -1
  10. package/dist/translators/delta-to-command.js +275 -271
  11. package/dist/translators/delta-to-command.js.map +1 -1
  12. package/dist/translators/delta-to-event.d.ts +16 -1
  13. package/dist/translators/delta-to-event.d.ts.map +1 -1
  14. package/dist/translators/delta-to-event.js +36 -29
  15. package/dist/translators/delta-to-event.js.map +1 -1
  16. package/dist/translators/event-to-delta.d.ts +3 -2
  17. package/dist/translators/event-to-delta.d.ts.map +1 -1
  18. package/dist/translators/event-to-delta.js +6 -6
  19. package/dist/translators/event-to-delta.js.map +1 -1
  20. package/dist/translators/index.d.ts +2 -2
  21. package/dist/translators/index.d.ts.map +1 -1
  22. package/dist/translators/index.js +2 -2
  23. package/dist/translators/index.js.map +1 -1
  24. package/package.json +5 -5
  25. package/src/payload/command-types.ts +4 -4
  26. package/src/payload/event-types.ts +7 -7
  27. package/src/payload/query-types.ts +15 -0
  28. package/src/translators/delta-to-command.ts +289 -276
  29. package/src/translators/delta-to-event.ts +352 -315
  30. package/src/translators/event-to-delta.ts +19 -10
  31. package/src/translators/index.ts +2 -2
@@ -16,6 +16,7 @@
16
16
  // SPDX-License-Identifier: Apache-2.0
17
17
 
18
18
  import {
19
+ allNodesFrom,
19
20
  AnnotationAddedDelta,
20
21
  AnnotationDeletedDelta,
21
22
  AnnotationMovedAndReplacedFromOtherParentDelta,
@@ -40,6 +41,7 @@ import {
40
41
  EntryMovedFromOtherReferenceInSameParentDelta,
41
42
  EntryMovedInSameReferenceDelta,
42
43
  IDelta,
44
+ INodeBase,
43
45
  NoOpDelta,
44
46
  PartitionAddedDelta,
45
47
  PartitionDeletedDelta,
@@ -51,7 +53,13 @@ import {
51
53
  ReferenceDeletedDelta,
52
54
  serializeNodeBases
53
55
  } from "@lionweb/class-core"
54
- import { metaPointerFor, serializedRef } from "@lionweb/core"
56
+ import {
57
+ builtinPropertyValueSerializer,
58
+ idOf,
59
+ metaPointerFor,
60
+ PropertyValueSerializer,
61
+ serializedRef
62
+ } from "@lionweb/core"
55
63
  import {
56
64
  AnnotationAddedEvent,
57
65
  AnnotationDeletedEvent,
@@ -87,325 +95,354 @@ import {
87
95
  ReferenceChangedEvent,
88
96
  ReferenceDeletedEvent
89
97
  } from "../payload/index.js"
98
+ import { nodeBaseReader } from "@lionweb/class-core/dist/serializer.js"
90
99
 
91
100
 
92
- export const deltaAsEvent = (delta: IDelta, lastUsedSequenceNumber: number): [event: Event, lastUsedSequenceNumber: number] => {
101
+ const allIdsOfDescendantsFrom = (node: INodeBase) =>
102
+ allNodesFrom(node).slice(1).map(idOf)
93
103
 
94
- let sequenceNumber = lastUsedSequenceNumber
95
- const completed = <ET extends Event>(
96
- technicalName: ET["messageKind"],
97
- partialEvent: Omit<ET, "messageKind" | "sequenceNumber" | "originCommands" | "protocolMessages">
98
- ) => ({
99
- messageKind: technicalName,
100
- ...partialEvent,
101
- sequenceNumber: ++sequenceNumber,
102
- originCommands: [],
103
- protocolMessages: []
104
- })
105
104
 
106
- const translated = (delta: IDelta): Event => {
107
- if (delta instanceof PartitionAddedDelta) {
108
- return completed<PartitionAddedEvent>("PartitionAdded", { // § 6.6.1.1
109
- newPartition: serializeNodeBases([delta.newPartition])
110
- })
111
- }
112
- if (delta instanceof PartitionDeletedDelta) {
113
- return completed<PartitionDeletedEvent>("PartitionDeleted", { // § 6.6.1.2
114
- deletedPartition: delta.deletedPartition.id
115
- })
116
- }
117
- if (delta instanceof PropertyAddedDelta) {
118
- return completed<PropertyAddedEvent<unknown>>("PropertyAdded", { // § 6.6.3.1
119
- node: delta.node.id,
120
- property: metaPointerFor(delta.property),
121
- newValue: delta.value
122
- })
123
- }
124
- if (delta instanceof PropertyDeletedDelta) {
125
- return completed<PropertyDeletedEvent<unknown>>("PropertyDeleted", { // § 6.6.3.2
126
- node: delta.node.id,
127
- property: metaPointerFor(delta.property),
128
- oldValue: delta.oldValue
129
- })
130
- }
131
- if (delta instanceof PropertyChangedDelta) {
132
- return completed<PropertyChangedEvent<unknown>>("PropertyChanged", { // § 6.6.3.3
133
- node: delta.node.id,
134
- property: metaPointerFor(delta.property),
135
- newValue: delta.newValue,
136
- oldValue: delta.oldValue
137
- })
138
- }
139
- if (delta instanceof ChildAddedDelta) {
140
- return completed<ChildAddedEvent>("ChildAdded", { // § 6.6.4.1
141
- parent: delta.parent.id,
142
- newChild: serializeNodeBases([delta.newChild]),
143
- containment: metaPointerFor(delta.containment),
144
- index: delta.index
145
- })
146
- }
147
- if (delta instanceof ChildDeletedDelta) {
148
- return completed<ChildDeletedEvent>("ChildDeleted", { // § 6.6.4.2
149
- parent: delta.parent.id,
150
- containment: metaPointerFor(delta.containment),
151
- index: delta.index,
152
- deletedChild: delta.deletedChild.id,
153
- deletedDescendants: [] // FIXME implement
154
- })
155
- }
156
- if (delta instanceof ChildReplacedDelta) {
157
- return completed<ChildReplacedEvent>("ChildReplaced", { // § 6.6.4.3
158
- newChild: serializeNodeBases([delta.newChild]),
159
- parent: delta.parent.id,
160
- containment: metaPointerFor(delta.containment),
161
- index: delta.index,
162
- replacedChild: delta.replacedChild.id,
163
- replacedDescendants: [] // FIXME implement
164
- })
165
- }
166
- if (delta instanceof ChildMovedFromOtherContainmentDelta) {
167
- return completed<ChildMovedFromOtherContainmentEvent>("ChildMovedFromOtherContainment", { // § 6.6.4.4
168
- newParent: delta.newParent.id,
169
- newContainment: metaPointerFor(delta.newContainment),
170
- newIndex: delta.newIndex,
171
- movedChild: delta.movedChild.id,
172
- oldParent: delta.oldParent.id,
173
- oldContainment: metaPointerFor(delta.oldContainment),
174
- oldIndex: delta.oldIndex
175
- })
176
- }
177
- if (delta instanceof ChildMovedFromOtherContainmentInSameParentDelta) {
178
- return completed<ChildMovedFromOtherContainmentInSameParentEvent>("ChildMovedFromOtherContainmentInSameParent", { // § 6.6.4.5
179
- newContainment: metaPointerFor(delta.newContainment),
180
- newIndex: delta.newIndex,
181
- movedChild: delta.movedChild.id,
182
- parent: delta.parent.id,
183
- oldContainment: metaPointerFor(delta.oldContainment),
184
- oldIndex: delta.oldIndex
185
- })
186
- }
187
- if (delta instanceof ChildMovedInSameContainmentDelta) {
188
- return completed<ChildMovedInSameContainmentEvent>("ChildMovedInSameContainment", { // § 6.6.4.6
189
- parent: delta.parent.id,
190
- containment: metaPointerFor(delta.containment),
191
- oldIndex: delta.oldIndex,
192
- newIndex: delta.newIndex,
193
- movedChild: delta.movedChild.id
194
- })
195
- }
196
- if (delta instanceof ChildMovedAndReplacedFromOtherContainmentDelta) {
197
- return completed<ChildMovedAndReplacedFromOtherContainmentEvent>("ChildMovedAndReplacedFromOtherContainment", { // § 6.6.4.7
198
- newParent: delta.newParent.id,
199
- newContainment: metaPointerFor(delta.newContainment),
200
- newIndex: delta.newIndex,
201
- oldParent: delta.oldParent.id,
202
- oldContainment: metaPointerFor(delta.oldContainment),
203
- oldIndex: delta.oldIndex,
204
- movedChild: delta.movedChild.id,
205
- replacedChild: delta.replacedChild.id,
206
- replacedDescendants: [] // FIXME implement
207
- })
208
- }
209
- if (delta instanceof ChildMovedAndReplacedFromOtherContainmentInSameParentDelta) {
210
- return completed<ChildMovedAndReplacedFromOtherContainmentInSameParentEvent>("ChildMovedAndReplacedFromOtherContainmentInSameParent", { // § 6.6.4.8
211
- parent: delta.parent.id,
212
- oldContainment: metaPointerFor(delta.oldContainment),
213
- oldIndex: delta.oldIndex,
214
- newContainment: metaPointerFor(delta.newContainment),
215
- newIndex: delta.newIndex,
216
- replacedChild: delta.replacedChild.id,
217
- replacedDescendants: [], // FIXME implement
218
- movedChild: delta.movedChild.id
219
- })
220
- }
221
- if (delta instanceof ChildMovedAndReplacedInSameContainmentDelta) {
222
- return completed<ChildMovedAndReplacedInSameContainmentEvent>("ChildMovedAndReplacedInSameContainment", { // § 6.6.4.9
223
- parent: delta.parent.id,
224
- containment: metaPointerFor(delta.containment),
225
- oldIndex: delta.oldIndex,
226
- newIndex: delta.newIndex,
227
- movedChild: delta.movedChild.id,
228
- replacedChild: delta.replacedChild.id,
229
- replacedDescendants: [] // FIXME implement
230
- })
231
- }
232
- if (delta instanceof AnnotationAddedDelta) {
233
- return completed<AnnotationAddedEvent>("AnnotationAdded", { // § 6.6.5.1
234
- parent: delta.parent.id,
235
- index: delta.index,
236
- newAnnotation: serializeNodeBases([delta.newAnnotation])
237
- })
238
- }
239
- if (delta instanceof AnnotationDeletedDelta) {
240
- return completed<AnnotationDeletedEvent>("AnnotationDeleted", { // § 6.6.5.2
241
- parent: delta.parent.id,
242
- deletedAnnotation: delta.deletedAnnotation.id,
243
- index: delta.index,
244
- deletedDescendants: [] // FIXME implement
245
- })
246
- }
247
- if (delta instanceof AnnotationReplacedDelta) {
248
- return completed<AnnotationReplacedEvent>("AnnotationReplaced", { // § 6.6.5.3
249
- newAnnotation: serializeNodeBases([delta.newAnnotation]),
250
- parent: delta.parent.id,
251
- index: delta.index,
252
- replacedAnnotation: delta.replacedAnnotation.id,
253
- replacedDescendants: [] // FIXME implement
254
- })
255
- }
256
- if (delta instanceof AnnotationMovedFromOtherParentDelta) {
257
- return completed<AnnotationMovedFromOtherParentEvent>("AnnotationMovedFromOtherParent", { // § 6.6.5.4
258
- oldParent: delta.oldParent.id,
259
- oldIndex: delta.oldIndex,
260
- newParent: delta.newParent.id,
261
- newIndex: delta.newIndex,
262
- movedAnnotation: delta.movedAnnotation.id
263
- })
264
- }
265
- if (delta instanceof AnnotationMovedInSameParentDelta) {
266
- return completed<AnnotationMovedInSameParentEvent>("AnnotationMovedInSameParent", { // § 6.6.5.5
267
- parent: delta.parent.id,
268
- oldIndex: delta.oldIndex,
269
- newIndex: delta.newIndex,
270
- movedAnnotation: delta.movedAnnotation.id
271
- })
272
- }
273
- if (delta instanceof AnnotationMovedAndReplacedFromOtherParentDelta) {
274
- return completed<AnnotationMovedAndReplacedFromOtherParentEvent>("AnnotationMovedAndReplacedFromOtherParent", { // § 6.6.5.6
275
- oldParent: delta.oldParent.id,
276
- oldIndex: delta.oldIndex,
277
- newParent: delta.newParent.id,
278
- newIndex: delta.newIndex,
279
- replacedAnnotation: delta.replacedAnnotation.id,
280
- replacedDescendants: [], // FIXME implement
281
- movedAnnotation: delta.movedAnnotation.id
282
- })
283
- }
284
- if (delta instanceof AnnotationMovedAndReplacedInSameParentDelta) {
285
- return completed<AnnotationMovedAndReplacedInSameParentEvent>("AnnotationMovedAndReplacedInSameParent", { // § 6.6.5.7
286
- parent: delta.parent.id,
287
- oldIndex: delta.oldIndex,
288
- newIndex: delta.newIndex,
289
- replacedAnnotation: delta.replacedAnnotation.id,
290
- replacedDescendants: [], // FIXME implement
291
- movedAnnotation: delta.movedAnnotation.id
292
- })
293
- }
294
- if (delta instanceof ReferenceAddedDelta) {
295
- return completed<ReferenceAddedEvent>("ReferenceAdded", { // § 6.6.6.1
296
- parent: delta.parent.id,
297
- reference: metaPointerFor(delta.reference),
298
- index: delta.index,
299
- newTarget: serializedRef(delta.newTarget),
300
- newResolveInfo: null
301
- })
302
- }
303
- if (delta instanceof ReferenceDeletedDelta) {
304
- return completed<ReferenceDeletedEvent>("ReferenceDeleted", { // § 6.6.6.2
305
- parent: delta.parent.id,
306
- reference: metaPointerFor(delta.reference),
307
- index: delta.index,
308
- deletedTarget: serializedRef(delta.deletedTarget),
309
- deletedResolveInfo: null
310
- })
311
- }
312
- if (delta instanceof ReferenceChangedDelta) {
313
- return completed<ReferenceChangedEvent>("ReferenceChanged", { // § 6.6.6.3
314
- parent: delta.parent.id,
315
- reference: metaPointerFor(delta.reference),
316
- index: delta.index,
317
- oldTarget: serializedRef(delta.oldTarget),
318
- oldResolveInfo: null,
319
- newTarget: serializedRef(delta.newTarget),
320
- newResolveInfo: null
321
- })
322
- }
323
- if (delta instanceof EntryMovedFromOtherReferenceDelta) {
324
- return completed<EntryMovedFromOtherReferenceEvent>("EntryMovedFromOtherReference", { // § 6.6.6.4
325
- newParent: delta.newParent.id,
326
- newReference: metaPointerFor(delta.newReference),
327
- newIndex: delta.newIndex,
328
- oldParent: delta.oldParent.id,
329
- oldReference: metaPointerFor(delta.oldReference),
330
- oldIndex: delta.oldIndex,
331
- movedTarget: serializedRef(delta.movedTarget),
332
- movedResolveInfo: null
333
- })
334
- }
335
- if (delta instanceof EntryMovedFromOtherReferenceInSameParentDelta) {
336
- return completed<EntryMovedFromOtherReferenceInSameParentEvent>("EntryMovedFromOtherReferenceInSameParent", { // § 6.6.6.5
337
- parent: delta.parent.id,
338
- newReference: metaPointerFor(delta.newReference),
339
- newIndex: delta.newIndex,
340
- oldReference: metaPointerFor(delta.oldReference),
341
- oldIndex: delta.oldIndex,
342
- movedTarget: serializedRef(delta.movedTarget),
343
- movedResolveInfo: null
344
- })
345
- }
346
- if (delta instanceof EntryMovedInSameReferenceDelta) {
347
- return completed<EntryMovedInSameReferenceEvent>("EntryMovedInSameReference", { // § 6.6.6.6
348
- parent: delta.parent.id,
349
- reference: metaPointerFor(delta.reference),
350
- oldIndex: delta.oldIndex,
351
- newIndex: delta.newIndex,
352
- movedTarget: serializedRef(delta.movedTarget),
353
- movedResolveInfo: null
354
- })
355
- }
356
- if (delta instanceof EntryMovedAndReplacedFromOtherReferenceDelta) {
357
- return completed<EntryMovedAndReplacedFromOtherReferenceEvent>("EntryMovedAndReplacedFromOtherReference", { // § 6.6.6.7
358
- newParent: delta.newParent.id,
359
- newReference: metaPointerFor(delta.newReference),
360
- newIndex: delta.newIndex,
361
- replacedTarget: serializedRef(delta.replacedTarget),
362
- replacedResolveInfo: null,
363
- oldParent: delta.oldParent.id,
364
- oldReference: metaPointerFor(delta.oldReference),
365
- oldIndex: delta.oldIndex,
366
- movedTarget: serializedRef(delta.movedTarget),
367
- movedResolveInfo: null
368
- })
369
- }
370
- if (delta instanceof EntryMovedAndReplacedFromOtherReferenceInSameParentDelta) {
371
- return completed<EntryMovedAndReplacedFromOtherReferenceInSameParentEvent>("EntryMovedAndReplacedFromOtherReferenceInSameParent", { // § 6.6.6.8
372
- parent: delta.parent.id,
373
- newReference: metaPointerFor(delta.newReference),
374
- newIndex: delta.newIndex,
375
- replacedTarget: serializedRef(delta.replacedTarget),
376
- replacedResolveInfo: null,
377
- oldReference: metaPointerFor(delta.oldReference),
378
- oldIndex: delta.oldIndex,
379
- movedTarget: serializedRef(delta.movedTarget),
380
- movedResolveInfo: null
381
- })
382
- }
383
- if (delta instanceof EntryMovedAndReplacedInSameReferenceDelta) {
384
- return completed<EntryMovedAndReplacedInSameReferenceEvent>("EntryMovedAndReplacedInSameReference", { // § 6.6.6.9
385
- parent: delta.parent.id,
386
- reference: metaPointerFor(delta.reference),
387
- oldIndex: delta.oldIndex,
388
- movedTarget: serializedRef(delta.movedTarget),
389
- movedResolveInfo: null,
390
- newIndex: delta.newIndex,
391
- replacedTarget: serializedRef(delta.replacedTarget),
392
- replacedResolveInfo: null
393
- })
394
- }
395
- if (delta instanceof CompositeDelta) {
396
- return completed<CompositeEvent>("CompositeEvent", { // § 6.6.7.1
397
- parts: delta.parts
398
- .map((part) => translated(part))
399
- .filter((event) => event !== undefined) as Event[]
400
- })
401
- }
402
- if (delta instanceof NoOpDelta) {
403
- return completed<NoOpEvent>("NoOp", {})
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}`)
404
444
  }
405
445
 
406
- throw new Error(`can't handle delta of type ${delta.constructor.name}`)
446
+ return [translated(delta), sequenceNumber]
407
447
  }
408
448
 
409
- return [translated(delta), sequenceNumber]
410
- }
411
-