@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
@@ -51,7 +51,9 @@ import {
51
51
  ReferenceDeletedDelta,
52
52
  serializeNodeBases
53
53
  } from "@lionweb/class-core"
54
- import { metaPointerFor, serializedRef } from "@lionweb/core"
54
+ import { nodeBaseReader } from "@lionweb/class-core/dist/serializer.js"
55
+ import { builtinPropertyValueSerializer, metaPointerFor, PropertyValueSerializer, serializedRef } from "@lionweb/core"
56
+ import { LionWebId } from "@lionweb/json"
55
57
  import {
56
58
  AddAnnotationCommand,
57
59
  AddChildCommand,
@@ -88,286 +90,297 @@ import {
88
90
  } from "../payload/index.js"
89
91
 
90
92
 
93
+ /**
94
+ * Type def. for functions that translate {@link IDelta deltas} into {@link Command commands}.
95
+ * A value of `undefined` is returned for a delta that has no command equivalent.
96
+ * If a command is returned, it has the command ID passed.
97
+ */
98
+ export type DeltaToCommandTranslator = (delta: IDelta, commandId: LionWebId) => Command | undefined
99
+
91
100
  /**
92
101
  * @return a {@link IDelta delta} as a {@link Command command} with the given `commandId`.
93
102
  */
94
- export const deltaAsCommand = (delta: IDelta, commandId: string): Command | undefined => {
103
+ export const deltaToCommandTranslator = (propertyValueSerializer: PropertyValueSerializer = builtinPropertyValueSerializer) => {
95
104
 
96
- const completed = <CT extends Command>(
97
- commandName: CT["messageKind"],
98
- partialCommand: Omit<CT, "messageKind" | "commandId" | "protocolMessages">
99
- ) => ({
100
- messageKind: commandName,
101
- commandId,
102
- ...partialCommand,
103
- protocolMessages: []
104
- })
105
+ const translated: DeltaToCommandTranslator = (delta, commandId) => {
106
+ const completed = <CT extends Command>(
107
+ commandName: CT["messageKind"],
108
+ partialCommand: Omit<CT, "messageKind" | "commandId" | "protocolMessages">
109
+ ) => ({
110
+ messageKind: commandName,
111
+ commandId,
112
+ ...partialCommand,
113
+ protocolMessages: []
114
+ })
105
115
 
106
- // in order of the specification (§ 6.5):
116
+ // in order of the specification (§ 6.5):
107
117
 
108
- if (delta instanceof PartitionAddedDelta) {
109
- return completed<AddPartitionCommand>("AddPartition", { // § 6.5.2.1
110
- newPartition: serializeNodeBases([delta.newPartition])
111
- })
112
- }
113
- if (delta instanceof PartitionDeletedDelta) {
114
- return completed<DeletePartitionCommand>("DeletePartition", { // § 6.5.2.2
115
- deletedPartition: delta.deletedPartition.id
116
- })
117
- }
118
- if (delta instanceof PropertyAddedDelta) {
119
- return completed<AddPropertyCommand<unknown>>("AddProperty", { // § 6.5.4.1
120
- node: delta.node.id,
121
- property: metaPointerFor(delta.property),
122
- newValue: delta.value
123
- })
124
- }
125
- if (delta instanceof PropertyDeletedDelta) {
126
- return completed<DeletePropertyCommand>("DeleteProperty", { // § 6.5.4.2
127
- node: delta.node.id,
128
- property: metaPointerFor(delta.property)
129
- })
130
- }
131
- if (delta instanceof PropertyChangedDelta) {
132
- return completed<ChangePropertyCommand<unknown>>("ChangeProperty", { // § 6.5.4.3
133
- node: delta.node.id,
134
- property: metaPointerFor(delta.property),
135
- newValue: delta.newValue
136
- })
137
- }
138
- if (delta instanceof ChildAddedDelta) {
139
- return completed<AddChildCommand>("AddChild", { // § 6.5.5.1
140
- parent: delta.parent.id,
141
- newChild: serializeNodeBases([delta.newChild]),
142
- containment: metaPointerFor(delta.containment),
143
- index: delta.index
144
- })
145
- }
146
- if (delta instanceof ChildDeletedDelta) {
147
- return completed<DeleteChildCommand>("DeleteChild", { // § 6.5.5.2
148
- parent: delta.parent.id,
149
- containment: metaPointerFor(delta.containment),
150
- index: delta.index,
151
- deletedChild: delta.deletedChild.id
152
- })
153
- }
154
- if (delta instanceof ChildReplacedDelta) {
155
- return completed<ReplaceChildCommand>("ReplaceChild", { // § 6.5.5.3
156
- newChild: serializeNodeBases([delta.newChild]),
157
- parent: delta.parent.id,
158
- containment: metaPointerFor(delta.containment),
159
- index: delta.index,
160
- replacedChild: delta.replacedChild.id
161
- })
162
- }
163
- if (delta instanceof ChildMovedFromOtherContainmentDelta) {
164
- return completed<MoveChildFromOtherContainmentCommand>("MoveChildFromOtherContainment", { // § 6.5.5.4
165
- newParent: delta.newParent.id,
166
- newContainment: metaPointerFor(delta.newContainment),
167
- newIndex: delta.newIndex,
168
- movedChild: delta.movedChild.id
169
- })
170
- }
171
- if (delta instanceof ChildMovedFromOtherContainmentInSameParentDelta) {
172
- return completed<MoveChildFromOtherContainmentInSameParentCommand>("MoveChildFromOtherContainmentInSameParent", { // § 6.5.5.5
173
- newContainment: metaPointerFor(delta.newContainment),
174
- newIndex: delta.newIndex,
175
- movedChild: delta.movedChild.id,
176
- parent: delta.parent.id,
177
- oldContainment: metaPointerFor(delta.oldContainment),
178
- oldIndex: delta.oldIndex
179
- })
180
- }
181
- if (delta instanceof ChildMovedInSameContainmentDelta) {
182
- return completed<MoveChildInSameContainmentCommand>("MoveChildInSameContainment", { // § 6.5.5.6
183
- newIndex: delta.newIndex,
184
- movedChild: delta.movedChild.id
185
- })
186
- }
187
- if (delta instanceof ChildMovedAndReplacedFromOtherContainmentDelta) {
188
- return completed<MoveAndReplaceChildFromOtherContainmentCommand>("MoveAndReplaceChildFromOtherContainment", { // § 6.5.5.7
189
- newParent: delta.newParent.id,
190
- newContainment: metaPointerFor(delta.newContainment),
191
- newIndex: delta.newIndex,
192
- replacedChild: delta.replacedChild.id,
193
- movedChild: delta.movedChild.id
194
- })
195
- }
196
- if (delta instanceof ChildMovedAndReplacedFromOtherContainmentInSameParentDelta) {
197
- return completed<MoveAndReplaceChildFromOtherContainmentInSameParentCommand>("MoveAndReplaceChildFromOtherContainmentInSameParent", { // § 6.5.5.8
198
- newContainment: metaPointerFor(delta.newContainment),
199
- newIndex: delta.newIndex,
200
- replacedChild: delta.replacedChild.id,
201
- movedChild: delta.movedChild.id
202
- })
203
- }
204
- if (delta instanceof ChildMovedAndReplacedInSameContainmentDelta) {
205
- return completed<MoveAndReplaceChildInSameContainmentCommand>("MoveAndReplaceChildInSameContainment", { // § 6.5.5.9
206
- newIndex: delta.newIndex,
207
- replacedChild: delta.replacedChild.id
208
- })
209
- }
210
- if (delta instanceof AnnotationAddedDelta) {
211
- return completed<AddAnnotationCommand>("AddAnnotation", { // § 6.5.6.1
212
- parent: delta.parent.id,
213
- index: delta.index,
214
- newAnnotation: serializeNodeBases([delta.newAnnotation])
215
- })
216
- }
217
- if (delta instanceof AnnotationDeletedDelta) {
218
- return completed<DeleteAnnotationCommand>("DeleteAnnotation", { // § 6.5.6.2
219
- parent: delta.parent.id,
220
- deletedAnnotation: delta.deletedAnnotation.id,
221
- index: delta.index
222
- })
223
- }
224
- if (delta instanceof AnnotationReplacedDelta) {
225
- return completed<ReplaceAnnotationCommand>("ReplaceAnnotation", { // § 6.5.6.3
226
- newAnnotation: serializeNodeBases([delta.newAnnotation]),
227
- parent: delta.parent.id,
228
- index: delta.index,
229
- replacedAnnotation: delta.replacedAnnotation.id
230
- })
231
- }
232
- if (delta instanceof AnnotationMovedFromOtherParentDelta) {
233
- return completed<MoveAnnotationFromOtherParentCommand>("MoveAnnotationFromOtherParent", { // § 6.5.6.4
234
- newParent: delta.newParent.id,
235
- newIndex: delta.newIndex,
236
- movedAnnotation: delta.movedAnnotation.id
237
- })
238
- }
239
- if (delta instanceof AnnotationMovedInSameParentDelta) {
240
- return completed<MoveAnnotationInSameParentCommand>("MoveAnnotationInSameParent", { // § 6.5.6.5
241
- newIndex: delta.newIndex,
242
- movedAnnotation: delta.movedAnnotation.id
243
- })
244
- }
245
- if (delta instanceof AnnotationMovedAndReplacedFromOtherParentDelta) {
246
- return completed<MoveAndReplaceAnnotationFromOtherParentCommand>("MoveAndReplaceAnnotationFromOtherParent", { // § 6.5.6.6
247
- newParent: delta.newParent.id,
248
- newIndex: delta.newIndex,
249
- replacedAnnotation: delta.replacedAnnotation.id,
250
- movedAnnotation: delta.movedAnnotation.id
251
- })
252
- }
253
- if (delta instanceof AnnotationMovedAndReplacedInSameParentDelta) {
254
- return completed<MoveAndReplaceAnnotationInSameParentCommand>("MoveAndReplaceAnnotationInSameParent", { // § 6.5.6.7
255
- newIndex: delta.newIndex,
256
- replacedAnnotation: delta.replacedAnnotation.id,
257
- movedAnnotation: delta.movedAnnotation.id
258
- })
259
- }
260
- if (delta instanceof ReferenceAddedDelta) {
261
- return completed<AddReferenceCommand>("AddReference", { // § 6.5.7.1
262
- parent: delta.parent.id,
263
- reference: metaPointerFor(delta.reference),
264
- index: delta.index,
265
- newTarget: serializedRef(delta.newTarget),
266
- newResolveInfo: null
267
- })
268
- }
269
- if (delta instanceof ReferenceDeletedDelta) {
270
- return completed<DeleteReferenceCommand>("DeleteReference", { // § 6.5.7.2
271
- parent: delta.parent.id,
272
- reference: metaPointerFor(delta.reference),
273
- index: delta.index,
274
- deletedTarget: serializedRef(delta.deletedTarget),
275
- deletedResolveInfo: null
276
- })
277
- }
278
- if (delta instanceof ReferenceChangedDelta) {
279
- return completed<ChangeReferenceCommand>("ChangeReference", { // § 6.5.7.3
280
- parent: delta.parent.id,
281
- reference: metaPointerFor(delta.reference),
282
- index: delta.index,
283
- oldTarget: serializedRef(delta.oldTarget),
284
- oldResolveInfo: null,
285
- newTarget: serializedRef(delta.newTarget),
286
- newResolveInfo: null
287
- })
288
- }
289
- if (delta instanceof EntryMovedFromOtherReferenceDelta) {
290
- return completed<MoveEntryFromOtherReferenceCommand>("MoveEntryFromOtherReference", { // § 6.5.7.4
291
- newParent: delta.newParent.id,
292
- newReference: metaPointerFor(delta.newReference),
293
- newIndex: delta.newIndex,
294
- oldParent: delta.oldParent.id,
295
- oldReference: metaPointerFor(delta.oldReference),
296
- oldIndex: delta.oldIndex,
297
- movedTarget: serializedRef(delta.movedTarget),
298
- movedResolveInfo: null
299
- })
300
- }
301
- if (delta instanceof EntryMovedFromOtherReferenceInSameParentDelta) {
302
- return completed<MoveEntryFromOtherReferenceInSameParentCommand>("MoveEntryFromOtherReferenceInSameParent", { // § 6.5.7.5
303
- parent: delta.parent.id,
304
- newReference: metaPointerFor(delta.newReference),
305
- newIndex: delta.newIndex,
306
- oldIndex: delta.oldIndex,
307
- movedTarget: serializedRef(delta.movedTarget),
308
- movedResolveInfo: null
309
- })
310
- }
311
- if (delta instanceof EntryMovedInSameReferenceDelta) {
312
- return completed<MoveEntryInSameReferenceCommand>("MoveEntryInSameReference", { // § 6.5.7.6
313
- parent: delta.parent.id,
314
- reference: metaPointerFor(delta.reference),
315
- oldIndex: delta.oldIndex,
316
- newIndex: delta.newIndex,
317
- movedTarget: serializedRef(delta.movedTarget),
318
- movedResolveInfo: null
319
- })
320
- }
321
- if (delta instanceof EntryMovedAndReplacedFromOtherReferenceDelta) {
322
- return completed<MoveAndReplaceEntryFromOtherReferenceCommand>("MoveAndReplaceEntryFromOtherReference", { // § 6.5.7.7
323
- newParent: delta.newParent.id,
324
- newReference: metaPointerFor(delta.newReference),
325
- newIndex: delta.newIndex,
326
- replacedTarget: serializedRef(delta.replacedTarget),
327
- replacedResolveInfo: null,
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 EntryMovedAndReplacedFromOtherReferenceInSameParentDelta) {
336
- return completed<MoveAndReplaceEntryFromOtherReferenceInSameParentCommand>("MoveAndReplaceEntryFromOtherReferenceInSameParent", { // § 6.5.7.8
337
- parent: delta.parent.id,
338
- newReference: metaPointerFor(delta.newReference),
339
- newIndex: delta.newIndex,
340
- replacedTarget: serializedRef(delta.replacedTarget),
341
- replacedResolveInfo: null,
342
- oldReference: metaPointerFor(delta.oldReference),
343
- oldIndex: delta.oldIndex,
344
- movedTarget: serializedRef(delta.movedTarget),
345
- movedResolveInfo: null
346
- })
347
- }
348
- if (delta instanceof EntryMovedAndReplacedInSameReferenceDelta) {
349
- return completed<MoveAndReplaceEntryInSameReferenceCommand>("MoveAndReplaceEntryInSameReference", { // § 6.5.7.9
350
- parent: delta.parent.id,
351
- reference: metaPointerFor(delta.reference),
352
- oldIndex: delta.oldIndex,
353
- movedTarget: serializedRef(delta.movedTarget),
354
- movedResolveInfo: null,
355
- newIndex: delta.newIndex,
356
- replacedTarget: serializedRef(delta.replacedTarget),
357
- replacedResolveInfo: null
358
- })
359
- }
360
- if (delta instanceof CompositeDelta) {
361
- return completed<CompositeCommand>("CompositeCommand", { // § 6.5.8.1
362
- parts: delta.parts
363
- .map((part, index) => deltaAsCommand(part, `${commandId}-${index}`)) // TODO inject proper ID generator!
364
- .filter((command) => command !== undefined) as Command[]
365
- })
366
- }
367
- if (delta instanceof NoOpDelta) {
368
- return undefined
369
- }
118
+ if (delta instanceof PartitionAddedDelta) {
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
+ }
370
380
 
371
- throw new Error(`can't handle delta of type ${delta.constructor.name}`)
372
- }
381
+ throw new Error(`can't handle delta of type ${delta.constructor.name}`)
382
+ }
383
+
384
+ return translated
385
+ }
373
386