@lionweb/json-diff 0.7.0-beta.17 → 0.7.0-beta.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lionweb/json-diff",
3
- "version": "0.7.0-beta.17",
3
+ "version": "0.7.0-beta.19",
4
4
  "description": "Find diff between LionWeb JSON chunks",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "release": "npm publish"
28
28
  },
29
29
  "dependencies": {
30
- "@lionweb/json": "0.7.0-beta.17",
31
- "@lionweb/json-utils": "0.7.0-beta.17",
32
- "@lionweb/ts-utils": "0.7.0-beta.17"
30
+ "@lionweb/json": "0.7.0-beta.19",
31
+ "@lionweb/json-utils": "0.7.0-beta.19",
32
+ "@lionweb/ts-utils": "0.7.0-beta.19"
33
33
  }
34
34
  }
@@ -0,0 +1,21 @@
1
+ import { Change } from "./changes/Change.js"
2
+
3
+ export class DiffResult {
4
+ changes: Change[] = []
5
+
6
+ change(issue: Change) {
7
+ this.changes.push(issue)
8
+ }
9
+
10
+ reset() {
11
+ this.changes = []
12
+ }
13
+
14
+ hasChanges(): boolean {
15
+ return this.changes.length !== 0
16
+ }
17
+
18
+ asStringArray(): string[] {
19
+ return this.changes.map(ch => ch.changeMsg())
20
+ }
21
+ }
@@ -0,0 +1,309 @@
1
+ import {
2
+ isEqualMetaPointer,
3
+ isEqualReferenceTarget,
4
+ LionWebJsonChunk,
5
+ LionWebJsonContainment,
6
+ LionWebJsonNode,
7
+ LionWebJsonProperty,
8
+ LionWebJsonReference,
9
+ LionWebJsonReferenceTarget,
10
+ LionWebJsonUsedLanguage
11
+ } from "@lionweb/json"
12
+ import { ChunkUtils, JsonContext, NodeUtils } from "@lionweb/json-utils"
13
+ import { asMinimalJsonString } from "@lionweb/ts-utils"
14
+ import { Change, GenericChange, Missing } from "./changes/Change.js"
15
+ import { LanguageAdded, LanguageRemoved, NodeAdded, NodeRemoved, SerializationFormatChange } from "./changes/ChunkChange.js"
16
+ import { ChildAdded, ChildOrderChanged, ChildRemoved } from "./changes/ContainmentChange.js"
17
+ import { AnnotationAdded, AnnotationOrderChanged, AnnotationRemoved, TargetAdded, TargetOrderChanged, TargetRemoved } from "./changes/index.js"
18
+ import { NodeClassifierChanged, ParentChanged } from "./changes/NodeChange.js"
19
+ import { PropertyValueChanged } from "./changes/PropertyChange.js"
20
+ import { DiffResult } from "./DiffResult.js"
21
+
22
+ /**
23
+ * Comparing LionWeb JSON chunks and find all differences
24
+ */
25
+ export class LionWebJsonDiff {
26
+ diffResult = new DiffResult()
27
+
28
+ constructor() {}
29
+
30
+ change(change: Change): void {
31
+ this.diffResult.change(change)
32
+ }
33
+
34
+ diff(ctx: JsonContext, msg: string) {
35
+ const change = new GenericChange(ctx, msg)
36
+ this.diffResult.change(change)
37
+ }
38
+
39
+ /**
40
+ * Compare two LwNode objects and return their difference
41
+ * @param beforeNode
42
+ * @param afterNode
43
+ */
44
+ diffLwNode(ctx: JsonContext, beforeNode: LionWebJsonNode, afterNode: LionWebJsonNode): void {
45
+ if (!isEqualMetaPointer(beforeNode.classifier, afterNode.classifier)) {
46
+ this.change(new NodeClassifierChanged(ctx.concat("classifier"), beforeNode, beforeNode.classifier, afterNode.classifier))
47
+ }
48
+ if (beforeNode.parent !== afterNode.parent) {
49
+ this.change(new ParentChanged(ctx, beforeNode, beforeNode.parent, afterNode.parent))
50
+ }
51
+ // Find diff between previous and next properties
52
+ beforeNode.properties.forEach((beforeProperty: LionWebJsonProperty, index: number) => {
53
+ const afterProperty = NodeUtils.findProperty(afterNode, beforeProperty.property)
54
+ if (afterProperty === undefined) {
55
+ this.change(
56
+ new PropertyValueChanged(
57
+ ctx.concat("properties", index),
58
+ beforeNode.id,
59
+ beforeProperty.property,
60
+ beforeProperty.value,
61
+ null,
62
+ Missing.MissingAfter
63
+ ),
64
+ )
65
+ } else {
66
+ this.diffLwProperty(ctx.concat("properties", index), beforeNode, beforeProperty, afterProperty)
67
+ }
68
+ })
69
+ afterNode.properties.forEach((afterProperty: LionWebJsonProperty, index: number) => {
70
+ const beforeProperty = NodeUtils.findProperty(beforeNode, afterProperty.property)
71
+ if (beforeProperty === undefined) {
72
+ this.change(
73
+ new PropertyValueChanged(
74
+ ctx.concat("properties", index),
75
+ beforeNode.id,
76
+ afterProperty.property,
77
+ null,
78
+ afterProperty.value,
79
+ Missing.MissingBefore
80
+ ),
81
+ )
82
+ }
83
+ // no else, if the property exists in both nodes, the diff has been claculated in the loop before this one
84
+ })
85
+ beforeNode.containments.forEach((beforeContainment: LionWebJsonContainment, index: number) => {
86
+ const beforeKey = beforeContainment.containment.key
87
+ const afterContainment = NodeUtils.findChild(afterNode, beforeKey)
88
+ if (afterContainment === undefined) {
89
+ // NB No containment is considered equivalent to a containment with empty _children_
90
+ if (beforeContainment.children.length !== 0) {
91
+ beforeContainment.children.forEach(childId => {
92
+ this.change(new ChildRemoved(ctx.concat("containments", index), beforeNode, beforeContainment.containment, afterContainment, childId, Missing.MissingAfter))
93
+ })
94
+ }
95
+ } else {
96
+ this.diffContainment(ctx.concat("containments", index), beforeNode, beforeContainment, afterContainment)
97
+ }
98
+ })
99
+ afterNode.containments.forEach((afterContainment: LionWebJsonContainment, index: number) => {
100
+ const afterKey = afterContainment.containment.key
101
+ const beforeContainment = NodeUtils.findChild(beforeNode, afterKey)
102
+ if (beforeContainment === undefined) {
103
+ if (afterContainment.children.length !== 0) {
104
+ afterContainment.children.forEach(childId => {
105
+ this.change(new ChildAdded(ctx.concat("containments", index), afterNode, afterContainment.containment, afterContainment, childId, Missing.MissingBefore))
106
+ })
107
+ }
108
+ }
109
+ // No else, has already been done
110
+ })
111
+ beforeNode.references.forEach((beforeReference: LionWebJsonReference, index: number) => {
112
+ const afterReference = NodeUtils.findReference(afterNode, beforeReference.reference)
113
+ if (afterReference === undefined) {
114
+ if (beforeReference.targets.length !== 0) {
115
+ beforeReference.targets.forEach(target => {
116
+ this.change(new TargetRemoved(ctx.concat("references", index), afterNode, beforeReference, afterReference, target, Missing.MissingAfter))
117
+ })
118
+ }
119
+ } else {
120
+ this.diffLwReference(ctx.concat("references", index), beforeNode, beforeReference, afterReference)
121
+ }
122
+ })
123
+ afterNode.references.forEach((afterReference: LionWebJsonReference, index: number) => {
124
+ const beforeReference = NodeUtils.findReference(afterNode, afterReference.reference)
125
+ if (beforeReference === undefined) {
126
+ if (afterReference.targets.length !== 0) {
127
+ afterReference.targets.forEach(target => {
128
+ this.change(new TargetAdded(ctx.concat("references", index), afterNode, beforeReference, afterReference, target, Missing.MissingBefore))
129
+ })
130
+ }
131
+ }
132
+ })
133
+ if (beforeNode.annotations !== undefined && afterNode.annotations !== undefined) {
134
+ let annotationDiffFound = false
135
+ beforeNode.annotations.forEach((beforeAnn: string, index: number) => {
136
+ if (!afterNode.annotations.includes(beforeAnn)) {
137
+ annotationDiffFound = true
138
+ this.change(new AnnotationRemoved(ctx, beforeNode, afterNode, beforeAnn, index))
139
+ }
140
+ })
141
+ afterNode.annotations.forEach((afterAnn: string, index: number) => {
142
+ if (!beforeNode.annotations.includes(afterAnn)) {
143
+ annotationDiffFound = true
144
+ this.change(new AnnotationAdded(ctx, beforeNode, afterNode, afterAnn, index))
145
+ }
146
+ })
147
+ if (!annotationDiffFound) {
148
+ for (let i: number = 0; i < afterNode.annotations.length; i++) {
149
+ if (afterNode.annotations[i] !== beforeNode.annotations[i]) {
150
+ this.change(new AnnotationOrderChanged(ctx.concat("annotations"), beforeNode, afterNode, "", i))
151
+ break
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+
158
+ diffLwChunk(beforeChunk: LionWebJsonChunk, afterChunk: LionWebJsonChunk): void {
159
+ const ctx = new JsonContext(null, ["$"])
160
+ if (beforeChunk.serializationFormatVersion !== afterChunk.serializationFormatVersion) {
161
+ this.change(
162
+ new SerializationFormatChange(
163
+ ctx.concat("serializationFormatVersion"),
164
+ beforeChunk.serializationFormatVersion,
165
+ afterChunk.serializationFormatVersion,
166
+ ),
167
+ )
168
+ }
169
+ beforeChunk.languages.forEach((beforeLanguage: LionWebJsonUsedLanguage, index: number) => {
170
+ const afterLanguage = ChunkUtils.findLwUsedLanguage(afterChunk, beforeLanguage.key)
171
+ if (afterLanguage === null) {
172
+ this.change(new LanguageRemoved(ctx.concat("languages", index), beforeLanguage))
173
+ } else {
174
+ this.diffLwUsedLanguage(ctx.concat("languages", index), beforeLanguage, afterLanguage)
175
+ }
176
+ })
177
+ afterChunk.languages.forEach((afterLanguage: LionWebJsonUsedLanguage, index: number) => {
178
+ const beforeLanguage = ChunkUtils.findLwUsedLanguage(beforeChunk, afterLanguage.key)
179
+ if (beforeLanguage === null) {
180
+ this.change(new LanguageAdded(ctx.concat("languages", index), afterLanguage))
181
+ }
182
+ })
183
+ beforeChunk.nodes.forEach((beforeNode: LionWebJsonNode, index: number) => {
184
+ const beforeId = beforeNode.id
185
+ const afterNode = ChunkUtils.findNode(afterChunk, beforeId)
186
+ const newCtx = ctx.concat("nodes", index)
187
+ if (afterNode === null || afterNode === undefined) {
188
+ this.change(new NodeRemoved(ctx, beforeNode))
189
+ } else {
190
+ this.diffLwNode(newCtx, beforeNode, afterNode)
191
+ }
192
+ })
193
+ afterChunk.nodes.forEach((afterNode: LionWebJsonNode, index: number) => {
194
+ const afterId = afterNode.id
195
+ const beforeNode = ChunkUtils.findNode(beforeChunk, afterId)
196
+ if (beforeNode === null) {
197
+ this.change(new NodeAdded(ctx.concat("nodes", index), afterNode))
198
+ }
199
+ })
200
+ }
201
+
202
+ diffContainment(
203
+ ctx: JsonContext,
204
+ node: LionWebJsonNode,
205
+ beforeContainment: LionWebJsonContainment,
206
+ afterContainment: LionWebJsonContainment,
207
+ ): void {
208
+ if (!isEqualMetaPointer(beforeContainment.containment, afterContainment.containment)) {
209
+ console.error("diffContainment: MetaPointers of containments should be identical")
210
+ this.diff(
211
+ ctx,
212
+ `Containment Object has concept ${asMinimalJsonString(beforeContainment.containment)} vs ${JSON.stringify(
213
+ afterContainment.containment,
214
+ )}`,
215
+ )
216
+ }
217
+ // Check whether children exist in both objects (two for loops)
218
+ // TODO Also check for the order that can be changed!!!
219
+ let changeFound = false
220
+ for (const childId of beforeContainment.children) {
221
+ if (!afterContainment.children.includes(childId)) {
222
+ changeFound = true
223
+ this.change(new ChildRemoved(ctx, node, beforeContainment.containment, afterContainment, childId))
224
+ }
225
+ }
226
+ for (const childId of afterContainment.children) {
227
+ if (!beforeContainment.children.includes(childId)) {
228
+ changeFound = true
229
+ this.change(new ChildAdded(ctx, node, beforeContainment.containment, afterContainment, childId))
230
+ }
231
+ }
232
+ if (!changeFound) {
233
+ for (let i: number = 0; i < afterContainment.children.length; i++) {
234
+ if (afterContainment.children[i] !== beforeContainment.children[i]) {
235
+ this.change(new ChildOrderChanged(ctx.concat("children"), node, afterContainment.containment, afterContainment, ""))
236
+ break
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ diffLwReference(ctx: JsonContext, node: LionWebJsonNode, beforeRef: LionWebJsonReference, afterRef: LionWebJsonReference): void {
243
+ if (!isEqualMetaPointer(beforeRef.reference, afterRef.reference)) {
244
+ console.error("diffContainment: MetaPointers of references should be identical")
245
+ this.diff(ctx, `Reference has concept ${asMinimalJsonString(beforeRef.reference)} vs ${asMinimalJsonString(afterRef.reference)}`)
246
+ }
247
+ let diffFound = false;
248
+ beforeRef.targets.forEach((beforeTarget: LionWebJsonReferenceTarget, index: number) => {
249
+ const afterTarget = NodeUtils.findReferenceTarget(afterRef.targets, beforeTarget)
250
+ if (afterTarget === undefined) {
251
+ this.change(new TargetRemoved(ctx.concat("targets", index), node, beforeRef, afterRef, beforeTarget))
252
+ diffFound = true
253
+ } else {
254
+ if (!isEqualReferenceTarget(beforeTarget, afterTarget)) {
255
+ this.diff(
256
+ ctx.concat("targets", index),
257
+ `ERROR: reference target ${asMinimalJsonString(beforeTarget)} vs ${asMinimalJsonString(afterTarget)}`,
258
+ )
259
+ }
260
+ }
261
+ })
262
+ afterRef.targets.forEach((afterTarget: LionWebJsonReferenceTarget, index: number) => {
263
+ const beforeTarget = NodeUtils.findReferenceTarget(beforeRef.targets, afterTarget)
264
+ if (beforeTarget === undefined) {
265
+ this.change(new TargetAdded(ctx.concat("targets", index), node, beforeRef, afterRef, afterTarget))
266
+ diffFound = true
267
+ } else {
268
+ if (!isEqualReferenceTarget(beforeTarget, afterTarget)) {
269
+ this.diff(
270
+ ctx.concat("targets", index),
271
+ `ERROR: reference target ${asMinimalJsonString(beforeTarget)} vs ${asMinimalJsonString(afterTarget)}`,
272
+ )
273
+ }
274
+ }
275
+ })
276
+ if (!diffFound) {
277
+ for (let i: number = 0; i < beforeRef.targets.length; i++) {
278
+ if (!isEqualReferenceTarget(beforeRef.targets[i], afterRef.targets[i])) {
279
+ this.change(new TargetOrderChanged(ctx.concat("targets"), node, beforeRef, afterRef, beforeRef.targets[i]))
280
+ break
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ private diffLwUsedLanguage(ctx: JsonContext, obj1: LionWebJsonUsedLanguage, obj2: LionWebJsonUsedLanguage) {
287
+ if (obj1.key !== obj2.key || obj1.version !== obj2.version) {
288
+ this.diff(ctx, `Different used languages ${asMinimalJsonString(obj1)} vs ${asMinimalJsonString(obj2)}`)
289
+ }
290
+ }
291
+
292
+ private diffLwProperty(
293
+ ctx: JsonContext,
294
+ node: LionWebJsonNode,
295
+ beforeProperty: LionWebJsonProperty,
296
+ afterProperty: LionWebJsonProperty,
297
+ ) {
298
+ if (!isEqualMetaPointer(beforeProperty.property, afterProperty.property)) {
299
+ console.error("diffContainment: MetaPointers of properties should be identical")
300
+ this.diff(
301
+ ctx,
302
+ `Property Object has concept ${asMinimalJsonString(beforeProperty.property)} vs ${asMinimalJsonString(afterProperty.property)}`,
303
+ )
304
+ }
305
+ if (beforeProperty.value !== afterProperty.value) {
306
+ this.change(new PropertyValueChanged(ctx, node.id, beforeProperty.property, beforeProperty.value, afterProperty.value))
307
+ }
308
+ }
309
+ }
@@ -0,0 +1,76 @@
1
+ import { JsonContext } from "@lionweb/json-utils"
2
+
3
+ export type ChangeType =
4
+ | "GenericChange"
5
+ | "NodeRemoved"
6
+ | "NodeAdded"
7
+ | "ChildRemoved"
8
+ | "ChildAdded"
9
+ | "ParentChanged"
10
+ | "PropertyValueChanged"
11
+ | "SerializationFormatChange"
12
+ | "PropertyRemoved"
13
+ | "PropertyAdded"
14
+ | "NodeClassifierChanged"
15
+ | "ContainmentAdded"
16
+ | "ContainmentRemoved"
17
+ | "LanguageRemoved"
18
+ | "LanguageAdded"
19
+ | "TargetAdded"
20
+ | "TargetRemoved"
21
+ | "ReferenceRemoved"
22
+ | "ReferenceAdded"
23
+ | "AnnotationRemoved"
24
+ | "AnnotationAdded"
25
+ | "ChildOrderChanged"
26
+ | "AnnotationOrderChanged"
27
+ | "TargetOrderChanged"
28
+
29
+ /**
30
+ * Additionbal property in property, contauinment and reference changes to state
31
+ * that the whole property/ containment / reference definition is missing.
32
+ */
33
+ export enum Missing {
34
+ /**
35
+ * Both before and after have a definition for the property / containment / reference
36
+ */
37
+ NotMissing,
38
+ /**
39
+ * The definition is missing _before_ for the property / containment / reference
40
+ */
41
+ MissingBefore,
42
+ /**
43
+ * The definition is missing _after_ for the property / containment / reference
44
+ */
45
+ MissingAfter
46
+ }
47
+
48
+ export abstract class Change {
49
+ abstract readonly changeType: ChangeType
50
+ context: JsonContext
51
+
52
+ constructor(context: JsonContext) {
53
+ this.context = context
54
+ }
55
+
56
+ protected abstract msg(): string
57
+
58
+ public changeMsg(): string {
59
+ return `${this.changeType}: ${this.msg()} at ${this.context.toString()} `
60
+ }
61
+ }
62
+
63
+ export class GenericChange extends Change {
64
+ readonly changeType = "GenericChange"
65
+
66
+ constructor(
67
+ context: JsonContext,
68
+ protected message: string
69
+ ) {
70
+ super(context)
71
+ }
72
+
73
+ protected msg(): string {
74
+ return this.message
75
+ }
76
+ }
@@ -0,0 +1,68 @@
1
+ import { LionWebJsonNode, LionWebJsonUsedLanguage } from "@lionweb/json"
2
+ import { JsonContext } from "@lionweb/json-utils"
3
+ import { Change } from "./Change.js"
4
+
5
+ export abstract class ChunkChange extends Change {
6
+ constructor(public context: JsonContext) {
7
+ super(context)
8
+ }
9
+ }
10
+
11
+ export class SerializationFormatChange extends ChunkChange {
12
+ readonly changeType = "SerializationFormatChange"
13
+
14
+ constructor(
15
+ public context: JsonContext,
16
+ protected original: string,
17
+ protected newValue: string
18
+ ) {
19
+ super(context)
20
+ }
21
+
22
+ protected msg = () => `Serialization versions do not match: ${this.original} vs ${this.newValue}`
23
+ }
24
+
25
+ export class NodeRemoved extends ChunkChange {
26
+ readonly changeType = "NodeRemoved"
27
+
28
+ constructor(
29
+ public context: JsonContext,
30
+ public node: LionWebJsonNode
31
+ ) {
32
+ super(context)
33
+ }
34
+
35
+ protected msg = () => `Node ${this.node.id} is removed`
36
+ }
37
+
38
+ export class NodeAdded extends ChunkChange {
39
+ readonly changeType = "NodeAdded"
40
+
41
+ constructor(
42
+ public context: JsonContext,
43
+ public node: LionWebJsonNode
44
+ ) {
45
+ super(context)
46
+ }
47
+
48
+ protected msg = () => `Node ${this.node.id} is added`
49
+ }
50
+
51
+ export abstract class LanguageChange extends ChunkChange {
52
+ constructor(
53
+ public context: JsonContext,
54
+ public language: LionWebJsonUsedLanguage
55
+ ) {
56
+ super(context)
57
+ }
58
+ }
59
+
60
+ export class LanguageRemoved extends LanguageChange {
61
+ readonly changeType = "LanguageRemoved"
62
+ protected msg = () => `Language with key ${this.language.key} and version ${this.language.version} is removed`
63
+ }
64
+
65
+ export class LanguageAdded extends LanguageChange {
66
+ readonly changeType = "LanguageAdded"
67
+ protected msg = () => `Language with key ${this.language.key} and version ${this.language.version} is added`
68
+ }
@@ -0,0 +1,31 @@
1
+ import { LionWebId, LionWebJsonContainment, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
2
+ import { JsonContext } from "@lionweb/json-utils"
3
+ import { Change, Missing } from "./Change.js"
4
+
5
+ export abstract class ContainmentChange extends Change {
6
+ constructor(
7
+ public context: JsonContext,
8
+ public parentNode: LionWebJsonNode,
9
+ public containment: LionWebJsonMetaPointer,
10
+ public afterContainment: LionWebJsonContainment | undefined,
11
+ public childId: LionWebId,
12
+ public missing = Missing.NotMissing
13
+ ) {
14
+ super(context)
15
+ }
16
+ }
17
+
18
+ export class ChildAdded extends ContainmentChange {
19
+ readonly changeType = "ChildAdded"
20
+ protected msg = () => `Node "${this.parentNode.id}" added child "${this.childId}" to containment ${this.containment.key}`
21
+ }
22
+
23
+ export class ChildRemoved extends ContainmentChange {
24
+ readonly changeType = "ChildRemoved"
25
+ protected msg = () => `Node "${this.parentNode.id}" removed child "${this.childId}" from containment "${this.containment.key}"`
26
+ }
27
+
28
+ export class ChildOrderChanged extends ContainmentChange {
29
+ readonly changeType = "ChildOrderChanged"
30
+ protected msg = () => `Node "${this.parentNode.id}" changed order of children in containment "${this.containment.key}"`
31
+ }
@@ -0,0 +1,62 @@
1
+ import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
2
+ import { JsonContext } from "@lionweb/json-utils"
3
+ import { Change, ChangeType } from "./Change.js"
4
+
5
+ export class NodeClassifierChanged extends Change {
6
+ readonly changeType: ChangeType = "NodeClassifierChanged"
7
+
8
+ constructor(
9
+ public context: JsonContext,
10
+ public node: LionWebJsonNode,
11
+ public oldClassifier: LionWebJsonMetaPointer,
12
+ public newClassifier: LionWebJsonMetaPointer
13
+ ) {
14
+ super(context)
15
+ }
16
+
17
+ protected msg = () => `Object ${this.node.id} has classifier changed from ${this.oldClassifier.key} to ${this.newClassifier.key}`
18
+ }
19
+
20
+ export class ParentChanged extends Change {
21
+ readonly changeType = "ParentChanged"
22
+
23
+ constructor(
24
+ public context: JsonContext,
25
+ public node: LionWebJsonNode,
26
+ public beforeParentId: LionWebId | null,
27
+ public afterParentId: LionWebId | null
28
+ ) {
29
+ super(context)
30
+ }
31
+
32
+ protected msg = () => `Node "${this.node.id}" changed parent from "${this.beforeParentId}" to "${this.afterParentId}`
33
+ }
34
+
35
+ export abstract class AnnotationChange extends Change {
36
+ constructor(
37
+ ctx: JsonContext,
38
+ public nodeBefore: LionWebJsonNode,
39
+ public nodeAfter: LionWebJsonNode,
40
+ public annotationId: LionWebId,
41
+ public index: number
42
+ ) {
43
+ super(ctx)
44
+ }
45
+ }
46
+
47
+ export class AnnotationRemoved extends AnnotationChange {
48
+ readonly changeType = "AnnotationRemoved"
49
+
50
+ protected msg = () => `Node "${this.nodeBefore.id}" removed annotation "${this.annotationId}"`
51
+ }
52
+
53
+ export class AnnotationAdded extends AnnotationChange {
54
+ readonly changeType = "AnnotationAdded"
55
+
56
+ protected msg = () => `Node "${this.nodeAfter.id}" added annotation "${this.annotationId}"`
57
+ }
58
+
59
+ export class AnnotationOrderChanged extends AnnotationChange {
60
+ readonly changeType = "AnnotationOrderChanged"
61
+ protected msg = () => `Node "${this.nodeAfter.id}" changed order of annotations`
62
+ }
@@ -0,0 +1,36 @@
1
+ import { LionWebId, LionWebJsonMetaPointer, LionWebJsonNode } from "@lionweb/json"
2
+ import { JsonContext } from "@lionweb/json-utils"
3
+ import { asMinimalJsonString } from "@lionweb/ts-utils"
4
+ import { Change, Missing } from "./Change.js"
5
+
6
+ export abstract class PropertyChange extends Change {
7
+ constructor(
8
+ public context: JsonContext,
9
+ public nodeId: LionWebId,
10
+ public property: LionWebJsonMetaPointer,
11
+ public oldValue: string | null,
12
+ public newValue: string | null,
13
+ public missing: Missing = Missing.NotMissing
14
+ ) {
15
+ super(context)
16
+ }
17
+ }
18
+
19
+ export class PropertyValueChanged extends PropertyChange {
20
+ readonly changeType = "PropertyValueChanged"
21
+ protected msg = () =>
22
+ `Node "${this.nodeId} changed value of property "${this.property.key}" from "${this.oldValue}" to "${this.newValue}"`
23
+ }
24
+
25
+ export class PropertyAdded extends Change {
26
+ readonly changeType = "PropertyAdded"
27
+ constructor(
28
+ ctx: JsonContext,
29
+ public node: LionWebJsonNode,
30
+ public property: LionWebJsonMetaPointer
31
+ ) {
32
+ super(ctx)
33
+ }
34
+
35
+ protected msg = () => `Node "${this.node.id}" containment added: "${asMinimalJsonString(this.property)}"`
36
+ }
@@ -0,0 +1,33 @@
1
+ import { LionWebJsonNode, LionWebJsonReference, LionWebJsonReferenceTarget } from "@lionweb/json"
2
+ import { JsonContext } from "@lionweb/json-utils"
3
+ import { Change, Missing } from "./Change.js"
4
+
5
+ export abstract class ReferenceChange extends Change {
6
+ constructor(
7
+ public context: JsonContext,
8
+ public node: LionWebJsonNode,
9
+ public beforeReference: LionWebJsonReference | undefined,
10
+ public afterReference: LionWebJsonReference | undefined,
11
+ public target: LionWebJsonReferenceTarget,
12
+ public missing = Missing.NotMissing
13
+ ) {
14
+ super(context)
15
+ }
16
+ }
17
+
18
+ export class TargetAdded extends ReferenceChange {
19
+ readonly changeType = "TargetAdded"
20
+ protected msg = () =>
21
+ `Node "${this.node.id}" added target "${this.target.reference}" to reference "${this?.afterReference?.reference?.key}"`
22
+ }
23
+
24
+ export class TargetRemoved extends ReferenceChange {
25
+ readonly changeType = "TargetRemoved"
26
+ protected msg = () =>
27
+ `Node "${this.node.id}" removed target "${this.target.reference}" from reference "${this?.beforeReference?.reference?.key}"`
28
+ }
29
+
30
+ export class TargetOrderChanged extends ReferenceChange {
31
+ readonly changeType = "TargetOrderChanged"
32
+ protected msg = () => `Node "${this.node.id}" changed order of targets in reference "${this.afterReference?.reference?.key}"`
33
+ }
@@ -0,0 +1,6 @@
1
+ export * from "./Change.js"
2
+ export * from "./ChunkChange.js"
3
+ export * from "./ContainmentChange.js"
4
+ export * from "./NodeChange.js"
5
+ export * from "./PropertyChange.js"
6
+ export * from "./ReferenceChange.js"
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./changes/index.js"
2
+ export * from "./DiffResult.js"
3
+ export * from "./LionWebJsonDiff.js"