@lionweb/delta-protocol-common 0.7.0-beta.22 → 0.7.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/logging/textual-logging.d.ts +0 -4
  2. package/dist/logging/textual-logging.d.ts.map +1 -1
  3. package/dist/logging/textual-logging.js +0 -19
  4. package/dist/logging/textual-logging.js.map +1 -1
  5. package/dist/payload/command-types.d.ts +4 -4
  6. package/dist/payload/command-types.d.ts.map +1 -1
  7. package/dist/payload/event-types.d.ts +7 -7
  8. package/dist/payload/event-types.d.ts.map +1 -1
  9. package/dist/translators/delta-to-command.d.ts +10 -2
  10. package/dist/translators/delta-to-command.d.ts.map +1 -1
  11. package/dist/translators/delta-to-command.js +275 -274
  12. package/dist/translators/delta-to-command.js.map +1 -1
  13. package/dist/translators/delta-to-event.d.ts +18 -1
  14. package/dist/translators/delta-to-event.d.ts.map +1 -1
  15. package/dist/translators/delta-to-event.js +321 -2
  16. package/dist/translators/delta-to-event.js.map +1 -1
  17. package/dist/translators/event-to-delta.d.ts +3 -2
  18. package/dist/translators/event-to-delta.d.ts.map +1 -1
  19. package/dist/translators/event-to-delta.js +7 -10
  20. package/dist/translators/event-to-delta.js.map +1 -1
  21. package/dist/translators/index.d.ts +2 -1
  22. package/dist/translators/index.d.ts.map +1 -1
  23. package/dist/translators/index.js +2 -1
  24. package/dist/translators/index.js.map +1 -1
  25. package/package.json +5 -5
  26. package/src/logging/textual-logging.ts +0 -22
  27. package/src/payload/command-types.ts +4 -4
  28. package/src/payload/event-types.ts +7 -7
  29. package/src/translators/delta-to-command.ts +289 -281
  30. package/src/translators/delta-to-event.ts +430 -1
  31. package/src/translators/event-to-delta.ts +21 -15
  32. package/src/translators/index.ts +2 -1
@@ -45,11 +45,11 @@ export interface ChangeClassifierCommand extends Command {
45
45
  }
46
46
 
47
47
  /** § 6.5.4.1 */
48
- export interface AddPropertyCommand<T> extends Command {
48
+ export interface AddPropertyCommand extends Command {
49
49
  messageKind: "AddProperty"
50
50
  node: LionWebId
51
51
  property: LionWebJsonMetaPointer
52
- newValue: T
52
+ newValue: string
53
53
  }
54
54
 
55
55
  /** § 6.5.4.2 */
@@ -60,11 +60,11 @@ export interface DeletePropertyCommand extends Command {
60
60
  }
61
61
 
62
62
  /** § 6.5.4.3 */
63
- export interface ChangePropertyCommand<T> extends Command {
63
+ export interface ChangePropertyCommand extends Command {
64
64
  messageKind: "ChangeProperty"
65
65
  node: LionWebId
66
66
  property: LionWebJsonMetaPointer
67
- newValue: T
67
+ newValue: string
68
68
  }
69
69
 
70
70
  /** § 6.5.5.1 */
@@ -53,28 +53,28 @@ export interface ClassifierChangedEvent extends Event {
53
53
  }
54
54
 
55
55
  /** § 6.6.3.1 */
56
- export interface PropertyAddedEvent<T> extends Event {
56
+ export interface PropertyAddedEvent extends Event {
57
57
  messageKind: "PropertyAdded"
58
58
  node: LionWebId
59
59
  property: LionWebJsonMetaPointer
60
- newValue: T
60
+ newValue: string
61
61
  }
62
62
 
63
63
  /** § 6.6.3.2 */
64
- export interface PropertyDeletedEvent<T> extends Event {
64
+ export interface PropertyDeletedEvent extends Event {
65
65
  messageKind: "PropertyDeleted"
66
66
  node: LionWebId
67
67
  property: LionWebJsonMetaPointer
68
- oldValue: T
68
+ oldValue: string
69
69
  }
70
70
 
71
71
  /** § 6.6.3.3 */
72
- export interface PropertyChangedEvent<T> extends Event {
72
+ export interface PropertyChangedEvent extends Event {
73
73
  messageKind: "PropertyChanged"
74
74
  node: LionWebId
75
75
  property: LionWebJsonMetaPointer
76
- oldValue: T
77
- newValue: T
76
+ oldValue: string
77
+ newValue: string
78
78
  }
79
79
 
80
80
  /** § 6.6.4.1 */
@@ -51,7 +51,9 @@ import {
51
51
  ReferenceDeletedDelta,
52
52
  serializeNodeBases
53
53
  } from "@lionweb/class-core"
54
- import { metaPointerFor, Node, SingleRef, unresolved } 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,
@@ -85,294 +87,300 @@ import {
85
87
  MoveEntryInSameReferenceCommand,
86
88
  ReplaceAnnotationCommand,
87
89
  ReplaceChildCommand
88
- } from "../payload/command-types.js"
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
- const serializedRef = <NT extends Node>(ref: SingleRef<NT>): string | null =>
107
- ref === unresolved ? null : ref.id
116
+ // in order of the specification (§ 6.5):
108
117
 
109
- // in order of the specification (§ 6.5):
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
+ }
110
380
 
111
- if (delta instanceof PartitionAddedDelta) {
112
- return completed<AddPartitionCommand>("AddPartition", { // § 6.5.2.1
113
- newPartition: serializeNodeBases([delta.newPartition])
114
- })
115
- }
116
- if (delta instanceof PartitionDeletedDelta) {
117
- return completed<DeletePartitionCommand>("DeletePartition", { // § 6.5.2.2
118
- deletedPartition: delta.deletedPartition.id
119
- })
120
- }
121
- if (delta instanceof PropertyAddedDelta) {
122
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
- return completed<AddPropertyCommand<any>>("AddProperty", { // § 6.5.4.1
124
- node: delta.node.id,
125
- property: metaPointerFor(delta.property),
126
- newValue: delta.value
127
- })
128
- }
129
- if (delta instanceof PropertyDeletedDelta) {
130
- return completed<DeletePropertyCommand>("DeleteProperty", { // § 6.5.4.2
131
- node: delta.node.id,
132
- property: metaPointerFor(delta.property)
133
- })
134
- }
135
- if (delta instanceof PropertyChangedDelta) {
136
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
137
- return completed<ChangePropertyCommand<any>>("ChangeProperty", { // § 6.5.4.3
138
- node: delta.node.id,
139
- property: metaPointerFor(delta.property),
140
- newValue: delta.newValue
141
- })
142
- }
143
- if (delta instanceof ChildAddedDelta) {
144
- return completed<AddChildCommand>("AddChild", { // § 6.5.5.1
145
- parent: delta.parent.id,
146
- newChild: serializeNodeBases([delta.newChild]),
147
- containment: metaPointerFor(delta.containment),
148
- index: delta.index
149
- })
150
- }
151
- if (delta instanceof ChildDeletedDelta) {
152
- return completed<DeleteChildCommand>("DeleteChild", { // § 6.5.5.2
153
- parent: delta.parent.id,
154
- containment: metaPointerFor(delta.containment),
155
- index: delta.index,
156
- deletedChild: delta.deletedChild.id
157
- })
158
- }
159
- if (delta instanceof ChildReplacedDelta) {
160
- return completed<ReplaceChildCommand>("ReplaceChild", { // § 6.5.5.3
161
- newChild: serializeNodeBases([delta.newChild]),
162
- parent: delta.parent.id,
163
- containment: metaPointerFor(delta.containment),
164
- index: delta.index,
165
- replacedChild: delta.replacedChild.id
166
- })
167
- }
168
- if (delta instanceof ChildMovedFromOtherContainmentDelta) {
169
- return completed<MoveChildFromOtherContainmentCommand>("MoveChildFromOtherContainment", { // § 6.5.5.4
170
- newParent: delta.newParent.id,
171
- newContainment: metaPointerFor(delta.newContainment),
172
- newIndex: delta.newIndex,
173
- movedChild: delta.movedChild.id
174
- })
175
- }
176
- if (delta instanceof ChildMovedFromOtherContainmentInSameParentDelta) {
177
- return completed<MoveChildFromOtherContainmentInSameParentCommand>("MoveChildFromOtherContainmentInSameParent", { // § 6.5.5.5
178
- newContainment: metaPointerFor(delta.newContainment),
179
- newIndex: delta.newIndex,
180
- movedChild: delta.movedChild.id,
181
- parent: delta.parent.id,
182
- oldContainment: metaPointerFor(delta.oldContainment),
183
- oldIndex: delta.oldIndex
184
- })
185
- }
186
- if (delta instanceof ChildMovedInSameContainmentDelta) {
187
- return completed<MoveChildInSameContainmentCommand>("MoveChildInSameContainment", { // § 6.5.5.6
188
- newIndex: delta.newIndex,
189
- movedChild: delta.movedChild.id
190
- })
191
- }
192
- if (delta instanceof ChildMovedAndReplacedFromOtherContainmentDelta) {
193
- return completed<MoveAndReplaceChildFromOtherContainmentCommand>("MoveAndReplaceChildFromOtherContainment", { // § 6.5.5.7
194
- newParent: delta.newParent.id,
195
- newContainment: metaPointerFor(delta.newContainment),
196
- newIndex: delta.newIndex,
197
- replacedChild: delta.replacedChild.id,
198
- movedChild: delta.movedChild.id
199
- })
200
- }
201
- if (delta instanceof ChildMovedAndReplacedFromOtherContainmentInSameParentDelta) {
202
- return completed<MoveAndReplaceChildFromOtherContainmentInSameParentCommand>("MoveAndReplaceChildFromOtherContainmentInSameParent", { // § 6.5.5.8
203
- newContainment: metaPointerFor(delta.newContainment),
204
- newIndex: delta.newIndex,
205
- replacedChild: delta.replacedChild.id,
206
- movedChild: delta.movedChild.id
207
- })
208
- }
209
- if (delta instanceof ChildMovedAndReplacedInSameContainmentDelta) {
210
- return completed<MoveAndReplaceChildInSameContainmentCommand>("MoveAndReplaceChildInSameContainment", { // § 6.5.5.9
211
- newIndex: delta.newIndex,
212
- replacedChild: delta.replacedChild.id
213
- })
214
- }
215
- if (delta instanceof AnnotationAddedDelta) {
216
- return completed<AddAnnotationCommand>("AddAnnotation", { // § 6.5.6.1
217
- parent: delta.parent.id,
218
- index: delta.index,
219
- newAnnotation: serializeNodeBases([delta.newAnnotation])
220
- })
221
- }
222
- if (delta instanceof AnnotationDeletedDelta) {
223
- return completed<DeleteAnnotationCommand>("DeleteAnnotation", { // § 6.5.6.2
224
- parent: delta.parent.id,
225
- deletedAnnotation: delta.deletedAnnotation.id,
226
- index: delta.index
227
- })
228
- }
229
- if (delta instanceof AnnotationReplacedDelta) {
230
- return completed<ReplaceAnnotationCommand>("ReplaceAnnotation", { // § 6.5.6.3
231
- newAnnotation: serializeNodeBases([delta.newAnnotation]),
232
- parent: delta.parent.id,
233
- index: delta.index,
234
- replacedAnnotation: delta.replacedAnnotation.id
235
- })
236
- }
237
- if (delta instanceof AnnotationMovedFromOtherParentDelta) {
238
- return completed<MoveAnnotationFromOtherParentCommand>("MoveAnnotationFromOtherParent", { // § 6.5.6.4
239
- newParent: delta.newParent.id,
240
- newIndex: delta.newIndex,
241
- movedAnnotation: delta.movedAnnotation.id
242
- })
243
- }
244
- if (delta instanceof AnnotationMovedInSameParentDelta) {
245
- return completed<MoveAnnotationInSameParentCommand>("MoveAnnotationInSameParent", { // § 6.5.6.5
246
- newIndex: delta.newIndex,
247
- movedAnnotation: delta.movedAnnotation.id
248
- })
249
- }
250
- if (delta instanceof AnnotationMovedAndReplacedFromOtherParentDelta) {
251
- return completed<MoveAndReplaceAnnotationFromOtherParentCommand>("MoveAndReplaceAnnotationFromOtherParent", { // § 6.5.6.6
252
- newParent: delta.newParent.id,
253
- newIndex: delta.newIndex,
254
- replacedAnnotation: delta.replacedAnnotation.id,
255
- movedAnnotation: delta.movedAnnotation.id
256
- })
257
- }
258
- if (delta instanceof AnnotationMovedAndReplacedInSameParentDelta) {
259
- return completed<MoveAndReplaceAnnotationInSameParentCommand>("MoveAndReplaceAnnotationInSameParent", { // § 6.5.6.7
260
- newIndex: delta.newIndex,
261
- replacedAnnotation: delta.replacedAnnotation.id,
262
- movedAnnotation: delta.movedAnnotation.id
263
- })
264
- }
265
- if (delta instanceof ReferenceAddedDelta) {
266
- return completed<AddReferenceCommand>("AddReference", { // § 6.5.7.1
267
- parent: delta.parent.id,
268
- reference: metaPointerFor(delta.reference),
269
- index: delta.index,
270
- newTarget: serializedRef(delta.newTarget),
271
- newResolveInfo: null
272
- })
273
- }
274
- if (delta instanceof ReferenceDeletedDelta) {
275
- return completed<DeleteReferenceCommand>("DeleteReference", { // § 6.5.7.2
276
- parent: delta.parent.id,
277
- reference: metaPointerFor(delta.reference),
278
- index: delta.index,
279
- deletedTarget: serializedRef(delta.deletedTarget),
280
- deletedResolveInfo: null
281
- })
282
- }
283
- if (delta instanceof ReferenceChangedDelta) {
284
- return completed<ChangeReferenceCommand>("ChangeReference", { // § 6.5.7.3
285
- parent: delta.parent.id,
286
- reference: metaPointerFor(delta.reference),
287
- index: delta.index,
288
- oldTarget: serializedRef(delta.oldTarget),
289
- oldResolveInfo: null,
290
- newTarget: serializedRef(delta.newTarget),
291
- newResolveInfo: null
292
- })
293
- }
294
- if (delta instanceof EntryMovedFromOtherReferenceDelta) {
295
- return completed<MoveEntryFromOtherReferenceCommand>("MoveEntryFromOtherReference", { // § 6.5.7.4
296
- newParent: delta.newParent.id,
297
- newReference: metaPointerFor(delta.newReference),
298
- newIndex: delta.newIndex,
299
- oldParent: delta.oldParent.id,
300
- oldReference: metaPointerFor(delta.oldReference),
301
- oldIndex: delta.oldIndex,
302
- movedTarget: serializedRef(delta.movedTarget),
303
- movedResolveInfo: null
304
- })
305
- }
306
- if (delta instanceof EntryMovedFromOtherReferenceInSameParentDelta) {
307
- return completed<MoveEntryFromOtherReferenceInSameParentCommand>("MoveEntryFromOtherReferenceInSameParent", { // § 6.5.7.5
308
- parent: delta.parent.id,
309
- newReference: metaPointerFor(delta.newReference),
310
- newIndex: delta.newIndex,
311
- oldIndex: delta.oldIndex,
312
- movedTarget: serializedRef(delta.movedTarget),
313
- movedResolveInfo: null
314
- })
315
- }
316
- if (delta instanceof EntryMovedInSameReferenceDelta) {
317
- return completed<MoveEntryInSameReferenceCommand>("MoveEntryInSameReference", { // § 6.5.7.6
318
- parent: delta.parent.id,
319
- reference: metaPointerFor(delta.reference),
320
- oldIndex: delta.oldIndex,
321
- newIndex: delta.newIndex,
322
- movedTarget: serializedRef(delta.movedTarget),
323
- movedResolveInfo: null
324
- })
325
- }
326
- if (delta instanceof EntryMovedAndReplacedFromOtherReferenceDelta) {
327
- return completed<MoveAndReplaceEntryFromOtherReferenceCommand>("MoveAndReplaceEntryFromOtherReference", { // § 6.5.7.7
328
- newParent: delta.newParent.id,
329
- newReference: metaPointerFor(delta.newReference),
330
- newIndex: delta.newIndex,
331
- replacedTarget: serializedRef(delta.replacedTarget),
332
- replacedResolveInfo: null,
333
- oldParent: delta.oldParent.id,
334
- oldReference: metaPointerFor(delta.oldReference),
335
- oldIndex: delta.oldIndex,
336
- movedTarget: serializedRef(delta.movedTarget),
337
- movedResolveInfo: null
338
- })
339
- }
340
- if (delta instanceof EntryMovedAndReplacedFromOtherReferenceInSameParentDelta) {
341
- return completed<MoveAndReplaceEntryFromOtherReferenceInSameParentCommand>("MoveAndReplaceEntryFromOtherReferenceInSameParent", { // § 6.5.7.8
342
- parent: delta.parent.id,
343
- newReference: metaPointerFor(delta.newReference),
344
- newIndex: delta.newIndex,
345
- replacedTarget: serializedRef(delta.replacedTarget),
346
- replacedResolveInfo: null,
347
- oldReference: metaPointerFor(delta.oldReference),
348
- oldIndex: delta.oldIndex,
349
- movedTarget: serializedRef(delta.movedTarget),
350
- movedResolveInfo: null
351
- })
352
- }
353
- if (delta instanceof EntryMovedAndReplacedInSameReferenceDelta) {
354
- return completed<MoveAndReplaceEntryInSameReferenceCommand>("MoveAndReplaceEntryInSameReference", { // § 6.5.7.9
355
- parent: delta.parent.id,
356
- reference: metaPointerFor(delta.reference),
357
- oldIndex: delta.oldIndex,
358
- movedTarget: serializedRef(delta.movedTarget),
359
- movedResolveInfo: null,
360
- newIndex: delta.newIndex,
361
- replacedTarget: serializedRef(delta.replacedTarget),
362
- replacedResolveInfo: null
363
- })
364
- }
365
- if (delta instanceof CompositeDelta) {
366
- return completed<CompositeCommand>("CompositeCommand", { // § 6.5.8.1
367
- parts: delta.parts
368
- .map((part, index) => deltaAsCommand(part, `${commandId}-${index}`)) // TODO inject ID generator!
369
- .filter((command) => command !== undefined) as Command[]
370
- })
371
- }
372
- if (delta instanceof NoOpDelta) {
373
- return undefined
374
- }
381
+ throw new Error(`can't handle delta of type ${delta.constructor.name}`)
382
+ }
375
383
 
376
- throw new Error(`can't handle delta of type ${delta.constructor.name}`)
377
- }
384
+ return translated
385
+ }
378
386