@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.
- package/dist/payload/command-types.d.ts +4 -4
- package/dist/payload/command-types.d.ts.map +1 -1
- package/dist/payload/event-types.d.ts +7 -7
- package/dist/payload/event-types.d.ts.map +1 -1
- package/dist/payload/query-types.d.ts +11 -0
- package/dist/payload/query-types.d.ts.map +1 -1
- package/dist/payload/query-types.js.map +1 -1
- package/dist/translators/delta-to-command.d.ts +9 -1
- package/dist/translators/delta-to-command.d.ts.map +1 -1
- package/dist/translators/delta-to-command.js +275 -271
- package/dist/translators/delta-to-command.js.map +1 -1
- package/dist/translators/delta-to-event.d.ts +16 -1
- package/dist/translators/delta-to-event.d.ts.map +1 -1
- package/dist/translators/delta-to-event.js +36 -29
- package/dist/translators/delta-to-event.js.map +1 -1
- package/dist/translators/event-to-delta.d.ts +3 -2
- package/dist/translators/event-to-delta.d.ts.map +1 -1
- package/dist/translators/event-to-delta.js +6 -6
- package/dist/translators/event-to-delta.js.map +1 -1
- package/dist/translators/index.d.ts +2 -2
- package/dist/translators/index.d.ts.map +1 -1
- package/dist/translators/index.js +2 -2
- package/dist/translators/index.js.map +1 -1
- package/package.json +5 -5
- package/src/payload/command-types.ts +4 -4
- package/src/payload/event-types.ts +7 -7
- package/src/payload/query-types.ts +15 -0
- package/src/translators/delta-to-command.ts +289 -276
- package/src/translators/delta-to-event.ts +352 -315
- package/src/translators/event-to-delta.ts +19 -10
- 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 {
|
|
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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
.
|
|
399
|
-
.
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
446
|
+
return [translated(delta), sequenceNumber]
|
|
407
447
|
}
|
|
408
448
|
|
|
409
|
-
return [translated(delta), sequenceNumber]
|
|
410
|
-
}
|
|
411
|
-
|