@itwin/ecschema-editing 5.7.0-dev.4 → 5.7.0-dev.6

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.
@@ -28,55 +28,79 @@ const FormatMerger_1 = require("./FormatMerger");
28
28
  */
29
29
  class SchemaMergingVisitor {
30
30
  _context;
31
+ _reporter;
31
32
  /**
32
33
  * Initializes a new instance of SchemaMergingVisitor class.
33
34
  */
34
35
  constructor(context) {
35
36
  this._context = context;
36
37
  }
38
+ /**
39
+ * Sets the reporter for tracking merge operations.
40
+ * @internal
41
+ */
42
+ setReporter(reporter) {
43
+ this._reporter = reporter;
44
+ }
45
+ /**
46
+ * Method that wraps the visitor with success/failure tracking.
47
+ * @internal
48
+ */
49
+ async trackOperation(entry, operation) {
50
+ if (!this._reporter) {
51
+ return operation();
52
+ }
53
+ try {
54
+ await operation();
55
+ this._reporter.recordSuccess(entry);
56
+ }
57
+ catch (error) {
58
+ this._reporter.recordFailure(entry, error);
59
+ throw error;
60
+ }
61
+ }
37
62
  /**
38
63
  * Shared merging logic for all types of ClassItemDifference union.
39
64
  */
40
65
  async visitClassDifference(entry, index, array, handler) {
41
- return this.visitSchemaItemDifference(entry, {
42
- add: async (context) => {
43
- // To add classes a slightly different approach is done. In fact the class entries gets processed
44
- // two times. The first time, a stub with the bare minimum is added to the schema. The second time,
45
- // the class gets completed with all properties, mixins, etc...
46
- if (entry.changeType === "add" && !await context.targetSchema.getItem(entry.itemName)) {
47
- await handler.add(this._context, {
48
- ...entry,
49
- difference: {
50
- ...entry.difference,
51
- // Remove everything we want to validate before setting, this is done in the second iteration.
52
- baseClass: undefined,
53
- mixins: undefined,
54
- properties: undefined,
55
- customAttributes: undefined,
56
- },
57
- });
58
- // Searches for the last class difference and adds the entry after it. That way,
59
- // the class is completed before class related entries get processed.
60
- const insertIndex = findIndexOf(array, (e) => !(0, Utils_1.isClassDifference)(e), index) || array.length;
61
- array.splice(insertIndex, 0, entry);
62
- return;
63
- }
64
- // Now both a modification change or the second add iteration is a modification of an existing class.
65
- // So, regardless of the actual change type, modify is called.
66
- return handler.modify(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
67
- },
66
+ // To add classes a slightly different approach is done. In fact the class entries gets processed
67
+ // two times. The first time, a stub with the bare minimum is added to the schema. The second time,
68
+ // the class gets completed with all properties, mixins, etc...
69
+ if (entry.changeType === "add" && !await this._context.targetSchema.getItem(entry.itemName)) {
70
+ await handler.add(this._context, {
71
+ ...entry,
72
+ difference: {
73
+ ...entry.difference,
74
+ // Remove everything we want to validate before setting, this is done in the second iteration.
75
+ baseClass: undefined,
76
+ mixins: undefined,
77
+ properties: undefined,
78
+ customAttributes: undefined,
79
+ },
80
+ });
81
+ // Searches for the last class difference and adds the entry after it. That way,
82
+ // the class is completed before class related entries get processed.
83
+ const insertIndex = findIndexOf(array, (e) => !(0, Utils_1.isClassDifference)(e), index) || array.length;
84
+ array.splice(insertIndex, 0, entry);
85
+ return;
86
+ }
87
+ // Now both a modification change or the second add iteration is a modification of an existing class.
88
+ // So, regardless of the actual change type, modify is called.
89
+ // This is tracked because it's the actual operation that completes the class.
90
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
91
+ add: async (context) => handler.modify(context, entry, (0, Utils_2.toItemKey)(context, entry.itemName)),
68
92
  modify: handler.modify,
69
- });
93
+ }));
70
94
  }
71
95
  /**
72
96
  * Visitor implementation for handling ConstantDifference.
73
97
  * @internal
74
98
  */
75
99
  async visitConstantDifference(entry) {
76
- return this.visitSchemaItemDifference(entry, {
100
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
77
101
  add: ConstantMerger_1.addConstant,
78
102
  modify: ConstantMerger_1.modifyConstant,
79
- });
103
+ }));
80
104
  }
81
105
  /**
82
106
  * Visitor implementation for handling CustomAttributeClassDifference.
@@ -93,9 +117,11 @@ class SchemaMergingVisitor {
93
117
  * @internal
94
118
  */
95
119
  async visitCustomAttributeInstanceDifference(entry) {
96
- switch (entry.changeType) {
97
- case "add": return (0, CustomAttributeMerger_1.addCustomAttribute)(this._context, entry);
98
- }
120
+ return this.trackOperation(entry, async () => {
121
+ switch (entry.changeType) {
122
+ case "add": return (0, CustomAttributeMerger_1.addCustomAttribute)(this._context, entry);
123
+ }
124
+ });
99
125
  }
100
126
  /**
101
127
  * Visitor implementation for handling EntityClassDifference.
@@ -112,77 +138,85 @@ class SchemaMergingVisitor {
112
138
  * @internal
113
139
  */
114
140
  async visitEntityClassMixinDifference(entry) {
115
- switch (entry.changeType) {
116
- case "add": return (0, EntityClassMerger_1.addClassMixins)(this._context, entry);
117
- }
141
+ return this.trackOperation(entry, async () => {
142
+ switch (entry.changeType) {
143
+ case "add": return (0, EntityClassMerger_1.addClassMixins)(this._context, entry);
144
+ }
145
+ });
118
146
  }
119
147
  /**
120
148
  * Visitor implementation for handling EnumerationDifference.
121
149
  * @internal
122
150
  */
123
151
  async visitEnumerationDifference(entry) {
124
- return this.visitSchemaItemDifference(entry, {
152
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
125
153
  add: EnumerationMerger_1.addEnumeration,
126
154
  modify: EnumerationMerger_1.modifyEnumeration,
127
- });
155
+ }));
128
156
  }
129
157
  /**
130
158
  * Visitor implementation for handling EnumeratorDifference.
131
159
  * @internal
132
160
  */
133
161
  async visitEnumeratorDifference(entry) {
134
- switch (entry.changeType) {
135
- case "add": return (0, EnumeratorMerger_1.addEnumerator)(this._context, entry);
136
- case "modify": return (0, EnumeratorMerger_1.modifyEnumerator)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
137
- }
162
+ return this.trackOperation(entry, async () => {
163
+ switch (entry.changeType) {
164
+ case "add": return (0, EnumeratorMerger_1.addEnumerator)(this._context, entry);
165
+ case "modify": return (0, EnumeratorMerger_1.modifyEnumerator)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
166
+ }
167
+ });
138
168
  }
139
169
  /**
140
170
  * Visitor implementation for handling FormatDifference.
141
171
  * @internal
142
172
  */
143
173
  async visitFormatDifference(entry) {
144
- return this.visitSchemaItemDifference(entry, {
174
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
145
175
  add: FormatMerger_1.addFormat,
146
176
  modify: FormatMerger_1.modifyFormat,
147
- });
177
+ }));
148
178
  }
149
179
  /**
150
180
  * Visitor implementation for handling FormatUnitDifference.
151
181
  * @internal
152
182
  */
153
183
  async visitFormatUnitDifference(entry) {
154
- switch (entry.changeType) {
155
- case "modify": return (0, FormatMerger_1.modifyFormatUnit)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
156
- }
184
+ return this.trackOperation(entry, async () => {
185
+ switch (entry.changeType) {
186
+ case "modify": return (0, FormatMerger_1.modifyFormatUnit)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
187
+ }
188
+ });
157
189
  }
158
190
  /**
159
191
  * Visitor implementation for handling FormatUnitLabelDifference.
160
192
  * @internal
161
193
  */
162
194
  async visitFormatUnitLabelDifference(entry) {
163
- switch (entry.changeType) {
164
- case "modify": return (0, FormatMerger_1.modifyFormatUnitLabel)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
165
- }
195
+ return this.trackOperation(entry, async () => {
196
+ switch (entry.changeType) {
197
+ case "modify": return (0, FormatMerger_1.modifyFormatUnitLabel)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
198
+ }
199
+ });
166
200
  }
167
201
  /**
168
202
  * Visitor implementation for handling InvertedUnitDifference.
169
203
  * @internal
170
204
  */
171
205
  async visitInvertedUnitDifference(entry) {
172
- return this.visitSchemaItemDifference(entry, {
206
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
173
207
  add: InvertedUnitMerger_1.addInvertedUnit,
174
208
  modify: InvertedUnitMerger_1.modifyInvertedUnit,
175
- });
209
+ }));
176
210
  }
177
211
  /**
178
212
  * Visitor implementation for handling KindOfQuantityDifference.
179
213
  * @internal
180
214
  */
181
215
  async visitKindOfQuantityDifference(entry) {
182
- return this.visitSchemaItemDifference(entry, {
216
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
183
217
  add: KindOfQuantityMerger_1.addKindOfQuantity,
184
218
  modify: KindOfQuantityMerger_1.modifyKindOfQuantity,
185
- });
219
+ }));
186
220
  }
187
221
  /**
188
222
  * Visitor implementation for handling MixinClassDifference.
@@ -199,27 +233,27 @@ class SchemaMergingVisitor {
199
233
  * @internal
200
234
  */
201
235
  async visitPhenomenonDifference(entry) {
202
- return this.visitSchemaItemDifference(entry, {
236
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
203
237
  add: PhenomenonMerger_1.addPhenomenon,
204
238
  modify: PhenomenonMerger_1.modifyPhenomenon,
205
- });
239
+ }));
206
240
  }
207
241
  /**
208
242
  * Visitor implementation for handling PropertyCategoryDifference.
209
243
  * @internal
210
244
  */
211
245
  async visitPropertyCategoryDifference(entry) {
212
- return this.visitSchemaItemDifference(entry, {
246
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
213
247
  add: PropertyCategoryMerger_1.addPropertyCategory,
214
248
  modify: PropertyCategoryMerger_1.modifyPropertyCategory,
215
- });
249
+ }));
216
250
  }
217
251
  /**
218
252
  * Visitor implementation for handling ClassPropertyDifference.
219
253
  * @internal
220
254
  */
221
255
  async visitPropertyDifference(entry) {
222
- await (0, PropertyMerger_1.mergePropertyDifference)(this._context, entry);
256
+ return this.trackOperation(entry, async () => (0, PropertyMerger_1.mergePropertyDifference)(this._context, entry));
223
257
  }
224
258
  /**
225
259
  * Visitor implementation for handling RelationshipClassDifference.
@@ -236,26 +270,31 @@ class SchemaMergingVisitor {
236
270
  * @internal
237
271
  */
238
272
  async visitRelationshipConstraintClassDifference(entry) {
239
- await (0, RelationshipClassMerger_1.mergeRelationshipClassConstraint)(this._context, entry);
273
+ return this.trackOperation(entry, async () => (0, RelationshipClassMerger_1.mergeRelationshipClassConstraint)(this._context, entry));
240
274
  }
241
275
  /**
242
276
  * Visitor implementation for handling RelationshipConstraintDifference.
243
277
  * @internal
244
278
  */
245
279
  async visitRelationshipConstraintDifference(entry) {
246
- await (0, RelationshipClassMerger_1.mergeRelationshipConstraint)(this._context, entry);
280
+ return this.trackOperation(entry, async () => {
281
+ await (0, RelationshipClassMerger_1.mergeRelationshipConstraint)(this._context, entry);
282
+ });
247
283
  }
248
284
  /**
249
285
  * Visitor implementation for handling SchemaDifference.
250
286
  * @internal
251
287
  */
252
- async visitSchemaDifference({ difference }) {
253
- if (difference.label !== undefined) {
254
- await this._context.editor.setDisplayLabel(this._context.targetSchemaKey, difference.label);
255
- }
256
- if (difference.description !== undefined) {
257
- await this._context.editor.setDescription(this._context.targetSchemaKey, difference.description);
258
- }
288
+ async visitSchemaDifference(entry) {
289
+ return this.trackOperation(entry, async () => {
290
+ const { difference } = entry;
291
+ if (difference.label !== undefined) {
292
+ await this._context.editor.setDisplayLabel(this._context.targetSchemaKey, difference.label);
293
+ }
294
+ if (difference.description !== undefined) {
295
+ await this._context.editor.setDescription(this._context.targetSchemaKey, difference.description);
296
+ }
297
+ });
259
298
  }
260
299
  /**
261
300
  * Shared merging logic for all types of AnySchemaItemDifference union.
@@ -280,10 +319,12 @@ class SchemaMergingVisitor {
280
319
  * @internal
281
320
  */
282
321
  async visitSchemaReferenceDifference(entry) {
283
- switch (entry.changeType) {
284
- case "add": return (0, SchemaReferenceMerger_1.addSchemaReferences)(this._context, entry);
285
- case "modify": return (0, SchemaReferenceMerger_1.modifySchemaReferences)(this._context, entry);
286
- }
322
+ return this.trackOperation(entry, async () => {
323
+ switch (entry.changeType) {
324
+ case "add": return (0, SchemaReferenceMerger_1.addSchemaReferences)(this._context, entry);
325
+ case "modify": return (0, SchemaReferenceMerger_1.modifySchemaReferences)(this._context, entry);
326
+ }
327
+ });
287
328
  }
288
329
  /**
289
330
  * Visitor implementation for handling StructClassDifference.
@@ -300,29 +341,31 @@ class SchemaMergingVisitor {
300
341
  * @internal
301
342
  */
302
343
  async visitUnitDifference(entry) {
303
- return this.visitSchemaItemDifference(entry, {
344
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
304
345
  add: UnitMerger_1.addUnit,
305
346
  modify: UnitMerger_1.modifyUnit,
306
- });
347
+ }));
307
348
  }
308
349
  /**
309
350
  * Visitor implementation for handling UnitSystemDifference.
310
351
  * @internal
311
352
  */
312
353
  async visitUnitSystemDifference(entry) {
313
- return this.visitSchemaItemDifference(entry, {
354
+ return this.trackOperation(entry, async () => this.visitSchemaItemDifference(entry, {
314
355
  add: UnitSystemMerger_1.addUnitSystem,
315
356
  modify: UnitSystemMerger_1.modifyUnitSystem,
316
- });
357
+ }));
317
358
  }
318
359
  /**
319
360
  * Visitor implementation for handling KindOfQuantityPresentationFormatDifference.
320
361
  * @internal
321
362
  */
322
363
  async visitKindOfQuantityPresentationFormatDifference(entry) {
323
- switch (entry.changeType) {
324
- case "add": return (0, KindOfQuantityMerger_1.addPresentationFormat)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
325
- }
364
+ return this.trackOperation(entry, async () => {
365
+ switch (entry.changeType) {
366
+ case "add": return (0, KindOfQuantityMerger_1.addPresentationFormat)(this._context, entry, (0, Utils_2.toItemKey)(this._context, entry.itemName));
367
+ }
368
+ });
326
369
  }
327
370
  }
328
371
  exports.SchemaMergingVisitor = SchemaMergingVisitor;
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaMergingVisitor.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingVisitor.ts"],"names":[],"mappings":";;;AAWA,qDAA+D;AAC/D,mEAA6D;AAC7D,6EAAmG;AACnG,2DAAwF;AACxF,2DAAwE;AACxE,yDAAqE;AACrE,iEAAwG;AACxG,+CAAgE;AAChE,yDAAqE;AACrE,qEAAuF;AACvF,uEAAyJ;AACzJ,mEAAsF;AACtF,2DAAwE;AACxE,yDAAqE;AACrE,qDAA2D;AAC3D,iDAA0D;AAI1D,mCAAoC;A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,CAAC,KAA2B;QAChE,OAAO,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE;YAC3C,GAAG,EAAE,gCAAa;YAClB,MAAM,EAAE,mCAAgB;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;;MAGE;IACK,KAAK,CAAC,+CAA+C,CAAC,KAAiD;QAC5G,QAAO,KAAK,CAAC,UAAU,EAAE,CAAC;YACxB,KAAK,KAAK,CAAC,CAAC,OAAO,IAAA,4CAAqB,EAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAA,iBAAS,EAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3G,CAAC;IACH,CAAC;CACF;AAzUD,oDAyUC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAA4B,EAAE,SAAkD,EAAE,SAAiB;IACtH,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,OAAO,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { AnyClassItemDifference, AnySchemaDifference, AnySchemaItemDifference, ClassPropertyDifference, \r\n ConstantDifference, CustomAttributeClassDifference, CustomAttributeDifference, EntityClassDifference, \r\n EntityClassMixinDifference, EnumerationDifference, EnumeratorDifference, FormatDifference, FormatUnitDifference, \r\n FormatUnitLabelDifference, InvertedUnitDifference, KindOfQuantityDifference, KindOfQuantityPresentationFormatDifference, \r\n MixinClassDifference, PhenomenonDifference, PropertyCategoryDifference, RelationshipClassDifference, \r\n RelationshipConstraintClassDifference, RelationshipConstraintDifference, SchemaDifference, SchemaReferenceDifference, \r\n StructClassDifference, UnitDifference, UnitSystemDifference } from \"../Differencing/SchemaDifference\";\r\nimport { addConstant, modifyConstant } from \"./ConstantMerger\";\r\nimport { addCustomAttribute } from \"./CustomAttributeMerger\";\r\nimport { addCustomAttributeClass, modifyCustomAttributeClass } from \"./CustomAttributeClassMerger\";\r\nimport { addClassMixins, addEntityClass, modifyEntityClass } from \"./EntityClassMerger\";\r\nimport { addEnumeration, modifyEnumeration } from \"./EnumerationMerger\";\r\nimport { addEnumerator, modifyEnumerator } from \"./EnumeratorMerger\";\r\nimport { addKindOfQuantity, addPresentationFormat, modifyKindOfQuantity } from \"./KindOfQuantityMerger\";\r\nimport { addMixinClass, modifyMixinClass } from \"./MixinMerger\";\r\nimport { addPhenomenon, modifyPhenomenon } from \"./PhenomenonMerger\";\r\nimport { addPropertyCategory, modifyPropertyCategory } from \"./PropertyCategoryMerger\";\r\nimport { addRelationshipClass, mergeRelationshipClassConstraint, mergeRelationshipConstraint, modifyRelationshipClass } from \"./RelationshipClassMerger\";\r\nimport { addSchemaReferences, modifySchemaReferences } from \"./SchemaReferenceMerger\";\r\nimport { addStructClass, modifyStructClass } from \"./StructClassMerger\";\r\nimport { addUnitSystem, modifyUnitSystem } from \"./UnitSystemMerger\";\r\nimport { mergePropertyDifference } from \"./PropertyMerger\";\r\nimport { isClassDifference } from \"../Differencing/Utils\";\r\nimport { SchemaDifferenceVisitor } from \"../Differencing/SchemaDifferenceVisitor\";\r\nimport { SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { toItemKey } from \"./Utils\";\r\nimport { addUnit, modifyUnit } from \"./UnitMerger\";\r\nimport { addInvertedUnit, modifyInvertedUnit } from \"./InvertedUnitMerger\";\r\nimport { addFormat, modifyFormat, modifyFormatUnit, modifyFormatUnitLabel } from \"./FormatMerger\";\r\n\r\n/** Definition of schema items change type handler array. */\r\ninterface ItemChangeTypeHandler<T extends AnySchemaDifference> {\r\n add: (context: SchemaMergeContext, entry: T) => Promise<void>;\r\n modify: (context: SchemaMergeContext, entry: T, key: SchemaItemKey) => Promise<void>;\r\n}\r\n\r\n/**\r\n * Implementation of ISchemaDifferenceVisitor that can be used to traverse schema\r\n * differences to call the appropriated merger methods.\r\n * @internal\r\n */\r\nexport class SchemaMergingVisitor implements SchemaDifferenceVisitor {\r\n\r\n private readonly _context: SchemaMergeContext;\r\n\r\n /**\r\n * Initializes a new instance of SchemaMergingVisitor class.\r\n */\r\n constructor(context: SchemaMergeContext) {\r\n this._context = context;\r\n }\r\n\r\n /**\r\n * Shared merging logic for all types of ClassItemDifference union.\r\n */\r\n private async visitClassDifference<T extends AnyClassItemDifference>(entry: T, index: number, array: AnySchemaDifference[], handler: ItemChangeTypeHandler<T>) {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: async (context) => {\r\n // To add classes a slightly different approach is done. In fact the class entries gets processed\r\n // two times. The first time, a stub with the bare minimum is added to the schema. The second time,\r\n // the class gets completed with all properties, mixins, etc...\r\n if(entry.changeType === \"add\" && !await context.targetSchema.getItem(entry.itemName)) {\r\n await handler.add(this._context, {\r\n ...entry,\r\n difference: {\r\n ...entry.difference,\r\n // Remove everything we want to validate before setting, this is done in the second iteration.\r\n baseClass: undefined,\r\n mixins: undefined,\r\n properties: undefined,\r\n customAttributes: undefined,\r\n },\r\n });\r\n\r\n // Searches for the last class difference and adds the entry after it. That way,\r\n // the class is completed before class related entries get processed.\r\n const insertIndex = findIndexOf(array, (e) => !isClassDifference(e), index) || array.length;\r\n array.splice(insertIndex, 0, entry);\r\n\r\n return;\r\n }\r\n\r\n // Now both a modification change or the second add iteration is a modification of an existing class.\r\n // So, regardless of the actual change type, modify is called.\r\n return handler.modify(this._context, entry, toItemKey(this._context, entry.itemName));\r\n },\r\n modify: handler.modify,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling ConstantDifference.\r\n * @internal\r\n */\r\n public async visitConstantDifference(entry: ConstantDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addConstant,\r\n modify: modifyConstant,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling CustomAttributeClassDifference.\r\n * @internal\r\n */\r\n public async visitCustomAttributeClassDifference(entry: CustomAttributeClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addCustomAttributeClass,\r\n modify: modifyCustomAttributeClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling CustomAttributeDifference.\r\n * @internal\r\n */\r\n public async visitCustomAttributeInstanceDifference(entry: CustomAttributeDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addCustomAttribute(this._context, entry);\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EntityClassDifference.\r\n * @internal\r\n */\r\n public async visitEntityClassDifference(entry: EntityClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addEntityClass,\r\n modify: modifyEntityClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EntityClassMixinDifference.\r\n * @internal\r\n */\r\n public async visitEntityClassMixinDifference(entry: EntityClassMixinDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addClassMixins(this._context, entry);\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EnumerationDifference.\r\n * @internal\r\n */\r\n public async visitEnumerationDifference(entry: EnumerationDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addEnumeration,\r\n modify: modifyEnumeration,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EnumeratorDifference.\r\n * @internal\r\n */\r\n public async visitEnumeratorDifference(entry: EnumeratorDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addEnumerator(this._context, entry);\r\n case \"modify\": return modifyEnumerator(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatDifference.\r\n * @internal\r\n */\r\n public async visitFormatDifference(entry: FormatDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addFormat,\r\n modify: modifyFormat,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatUnitDifference.\r\n * @internal\r\n */\r\n public async visitFormatUnitDifference(entry: FormatUnitDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"modify\": return modifyFormatUnit(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatUnitLabelDifference.\r\n * @internal\r\n */\r\n public async visitFormatUnitLabelDifference(entry: FormatUnitLabelDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"modify\": return modifyFormatUnitLabel(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling InvertedUnitDifference.\r\n * @internal\r\n */\r\n public async visitInvertedUnitDifference(entry: InvertedUnitDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addInvertedUnit,\r\n modify: modifyInvertedUnit,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling KindOfQuantityDifference.\r\n * @internal\r\n */\r\n public async visitKindOfQuantityDifference(entry: KindOfQuantityDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addKindOfQuantity,\r\n modify: modifyKindOfQuantity,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling MixinClassDifference.\r\n * @internal\r\n */\r\n public async visitMixinDifference(entry: MixinClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addMixinClass,\r\n modify: modifyMixinClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling PhenomenonDifference.\r\n * @internal\r\n */\r\n public async visitPhenomenonDifference(entry: PhenomenonDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addPhenomenon,\r\n modify: modifyPhenomenon,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling PropertyCategoryDifference.\r\n * @internal\r\n */\r\n public async visitPropertyCategoryDifference(entry: PropertyCategoryDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addPropertyCategory,\r\n modify: modifyPropertyCategory,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling ClassPropertyDifference.\r\n * @internal\r\n */\r\n public async visitPropertyDifference(entry: ClassPropertyDifference): Promise<void> {\r\n await mergePropertyDifference(this._context, entry);\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipClassDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipClassDifference(entry: RelationshipClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addRelationshipClass,\r\n modify: modifyRelationshipClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipConstraintClassDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipConstraintClassDifference(entry: RelationshipConstraintClassDifference): Promise<void> {\r\n await mergeRelationshipClassConstraint(this._context, entry);\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipConstraintDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipConstraintDifference(entry: RelationshipConstraintDifference): Promise<void> {\r\n await mergeRelationshipConstraint(this._context, entry);\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling SchemaDifference.\r\n * @internal\r\n */\r\n public async visitSchemaDifference({ difference }: SchemaDifference): Promise<void> {\r\n if (difference.label !== undefined) {\r\n await this._context.editor.setDisplayLabel(this._context.targetSchemaKey, difference.label);\r\n }\r\n if (difference.description !== undefined) {\r\n await this._context.editor.setDescription(this._context.targetSchemaKey, difference.description);\r\n }\r\n }\r\n\r\n /**\r\n * Shared merging logic for all types of AnySchemaItemDifference union.\r\n */\r\n private async visitSchemaItemDifference<T extends AnySchemaItemDifference>(entry: T, handler: ItemChangeTypeHandler<T>) {\r\n switch(entry.changeType) {\r\n case \"add\": {\r\n return handler.add(this._context, entry);\r\n }\r\n case \"modify\": {\r\n if(\"schemaItemType\" in entry.difference && entry.difference.schemaItemType !== entry.schemaType) {\r\n throw new Error(`Changing the type of item '${entry.itemName}' not supported.`);\r\n }\r\n\r\n return handler.modify(this._context, entry, toItemKey(this._context, entry.itemName));\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling SchemaReferenceDifference.\r\n * @internal\r\n */\r\n public async visitSchemaReferenceDifference(entry: SchemaReferenceDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addSchemaReferences(this._context, entry);\r\n case \"modify\": return modifySchemaReferences(this._context, entry);\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling StructClassDifference.\r\n * @internal\r\n */\r\n public async visitStructClassDifference(entry: StructClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addStructClass,\r\n modify: modifyStructClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling UnitDifference.\r\n * @internal\r\n */\r\n public async visitUnitDifference(entry: UnitDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addUnit,\r\n modify: modifyUnit,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling UnitSystemDifference.\r\n * @internal\r\n */\r\n public async visitUnitSystemDifference(entry: UnitSystemDifference): Promise<void> {\r\n return this.visitSchemaItemDifference(entry, {\r\n add: addUnitSystem,\r\n modify: modifyUnitSystem,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling KindOfQuantityPresentationFormatDifference.\r\n * @internal\r\n */\r\n public async visitKindOfQuantityPresentationFormatDifference(entry: KindOfQuantityPresentationFormatDifference): Promise<void> {\r\n switch(entry.changeType) {\r\n case \"add\": return addPresentationFormat(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Helper method to get the index of the first element in the array that satisfies the provided testing function.\r\n * @param array Array to search.\r\n * @param predicate Function to execute on each value in the array.\r\n * @param fromIndex The index to start the search at.\r\n * @returns An index in the array if an element passes the test; otherwise, false.\r\n */\r\nfunction findIndexOf(array: AnySchemaDifference[], predicate: (entry: AnySchemaDifference) => boolean, fromIndex: number) {\r\n for (let i = fromIndex; i < array.length; i++) {\r\n if (predicate(array[i]))\r\n return i;\r\n }\r\n return false;\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaMergingVisitor.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingVisitor.ts"],"names":[],"mappings":";;;AAaA,qDAA+D;AAC/D,mEAA6D;AAC7D,6EAAmG;AACnG,2DAAwF;AACxF,2DAAwE;AACxE,yDAAqE;AACrE,iEAAwG;AACxG,+CAAgE;AAChE,yDAAqE;AACrE,qEAAuF;AACvF,uEAAyJ;AACzJ,mEAAsF;AACtF,2DAAwE;AACxE,yDAAqE;AACrE,qDAA2D;AAC3D,iDAA0D;AAI1D,mCAAoC;AACpC,6CAAmD;AACnD,6DAA2E;AAC3E,iDAAkG;AAQlG;;;;GAIG;AACH,MAAa,oBAAoB;IAEd,QAAQ,CAAqB;IACtC,SAAS,CAAuB;IAExC;;OAEG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,WAAW,CAAC,QAA6B;QAC9C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,cAAc,CAAgC,KAAQ,EAAE,SAA8B;QAClG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO,SAAS,EAAE,CAAC;QACrB,CAAC;QAED,IAAI,CAAC;YACH,MAAM,SAAS,EAAE,CAAC;YAClB,IAAI,CAAC,SAA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AmB,CAAC,KAAqB;QACpD,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAC3C,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE;YACpC,GAAG,EAAE,oBAAO;YACZ,MAAM,EAAE,uBAAU;SACnB,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,yBAAyB,CAAC,KAA2B;QAChE,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAC3C,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE;YACpC,GAAG,EAAE,gCAAa;YAClB,MAAM,EAAE,mCAAgB;SACzB,CAAC,CACH,CAAC;IACJ,CAAC;IAED;;;MAGE;IACK,KAAK,CAAC,+CAA+C,CAAC,KAAiD;QAC5G,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE;YAC3C,QAAQ,KAAK,CAAC,UAAU,EAAE,CAAC;gBACzB,KAAK,KAAK,CAAC,CAAC,OAAO,IAAA,4CAAqB,EAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAA,iBAAS,EAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC3G,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9YD,oDA8YC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAA4B,EAAE,SAAkD,EAAE,SAAiB;IACtH,KAAK,IAAI,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,OAAO,CAAC,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport {\r\n AnyClassItemDifference, AnySchemaDifference, AnySchemaItemDifference, ClassPropertyDifference,\r\n ConstantDifference, CustomAttributeClassDifference, CustomAttributeDifference, EntityClassDifference,\r\n EntityClassMixinDifference, EnumerationDifference, EnumeratorDifference, FormatDifference, FormatUnitDifference,\r\n FormatUnitLabelDifference, InvertedUnitDifference, KindOfQuantityDifference, KindOfQuantityPresentationFormatDifference,\r\n MixinClassDifference, PhenomenonDifference, PropertyCategoryDifference, RelationshipClassDifference,\r\n RelationshipConstraintClassDifference, RelationshipConstraintDifference, SchemaDifference, SchemaReferenceDifference,\r\n StructClassDifference, UnitDifference, UnitSystemDifference\r\n} from \"../Differencing/SchemaDifference\";\r\nimport { addConstant, modifyConstant } from \"./ConstantMerger\";\r\nimport { addCustomAttribute } from \"./CustomAttributeMerger\";\r\nimport { addCustomAttributeClass, modifyCustomAttributeClass } from \"./CustomAttributeClassMerger\";\r\nimport { addClassMixins, addEntityClass, modifyEntityClass } from \"./EntityClassMerger\";\r\nimport { addEnumeration, modifyEnumeration } from \"./EnumerationMerger\";\r\nimport { addEnumerator, modifyEnumerator } from \"./EnumeratorMerger\";\r\nimport { addKindOfQuantity, addPresentationFormat, modifyKindOfQuantity } from \"./KindOfQuantityMerger\";\r\nimport { addMixinClass, modifyMixinClass } from \"./MixinMerger\";\r\nimport { addPhenomenon, modifyPhenomenon } from \"./PhenomenonMerger\";\r\nimport { addPropertyCategory, modifyPropertyCategory } from \"./PropertyCategoryMerger\";\r\nimport { addRelationshipClass, mergeRelationshipClassConstraint, mergeRelationshipConstraint, modifyRelationshipClass } from \"./RelationshipClassMerger\";\r\nimport { addSchemaReferences, modifySchemaReferences } from \"./SchemaReferenceMerger\";\r\nimport { addStructClass, modifyStructClass } from \"./StructClassMerger\";\r\nimport { addUnitSystem, modifyUnitSystem } from \"./UnitSystemMerger\";\r\nimport { mergePropertyDifference } from \"./PropertyMerger\";\r\nimport { isClassDifference } from \"../Differencing/Utils\";\r\nimport { SchemaDifferenceVisitor } from \"../Differencing/SchemaDifferenceVisitor\";\r\nimport { SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext, SchemaMergeReporter } from \"./SchemaMerger\";\r\nimport { toItemKey } from \"./Utils\";\r\nimport { addUnit, modifyUnit } from \"./UnitMerger\";\r\nimport { addInvertedUnit, modifyInvertedUnit } from \"./InvertedUnitMerger\";\r\nimport { addFormat, modifyFormat, modifyFormatUnit, modifyFormatUnitLabel } from \"./FormatMerger\";\r\n\r\n/** Definition of schema items change type handler array. */\r\ninterface ItemChangeTypeHandler<T extends AnySchemaDifference> {\r\n add: (context: SchemaMergeContext, entry: T) => Promise<void>;\r\n modify: (context: SchemaMergeContext, entry: T, key: SchemaItemKey) => Promise<void>;\r\n}\r\n\r\n/**\r\n * Implementation of ISchemaDifferenceVisitor that can be used to traverse schema\r\n * differences to call the appropriated merger methods.\r\n * @internal\r\n */\r\nexport class SchemaMergingVisitor implements SchemaDifferenceVisitor {\r\n\r\n private readonly _context: SchemaMergeContext;\r\n private _reporter?: SchemaMergeReporter;\r\n\r\n /**\r\n * Initializes a new instance of SchemaMergingVisitor class.\r\n */\r\n constructor(context: SchemaMergeContext) {\r\n this._context = context;\r\n }\r\n\r\n /**\r\n * Sets the reporter for tracking merge operations.\r\n * @internal\r\n */\r\n public setReporter(reporter: SchemaMergeReporter): void {\r\n this._reporter = reporter;\r\n }\r\n\r\n /**\r\n * Method that wraps the visitor with success/failure tracking.\r\n * @internal\r\n */\r\n private async trackOperation<T extends AnySchemaDifference>(entry: T, operation: () => Promise<void>): Promise<void> {\r\n if (!this._reporter) {\r\n return operation();\r\n }\r\n\r\n try {\r\n await operation();\r\n this._reporter.recordSuccess(entry);\r\n } catch (error: any) {\r\n this._reporter.recordFailure(entry, error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Shared merging logic for all types of ClassItemDifference union.\r\n */\r\n private async visitClassDifference<T extends AnyClassItemDifference>(entry: T, index: number, array: AnySchemaDifference[], handler: ItemChangeTypeHandler<T>) {\r\n // To add classes a slightly different approach is done. In fact the class entries gets processed\r\n // two times. The first time, a stub with the bare minimum is added to the schema. The second time,\r\n // the class gets completed with all properties, mixins, etc...\r\n if (entry.changeType === \"add\" && !await this._context.targetSchema.getItem(entry.itemName)) {\r\n await handler.add(this._context, {\r\n ...entry,\r\n difference: {\r\n ...entry.difference,\r\n // Remove everything we want to validate before setting, this is done in the second iteration.\r\n baseClass: undefined,\r\n mixins: undefined,\r\n properties: undefined,\r\n customAttributes: undefined,\r\n },\r\n });\r\n\r\n // Searches for the last class difference and adds the entry after it. That way,\r\n // the class is completed before class related entries get processed.\r\n const insertIndex = findIndexOf(array, (e) => !isClassDifference(e), index) || array.length;\r\n array.splice(insertIndex, 0, entry);\r\n\r\n return;\r\n }\r\n\r\n // Now both a modification change or the second add iteration is a modification of an existing class.\r\n // So, regardless of the actual change type, modify is called.\r\n // This is tracked because it's the actual operation that completes the class.\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: async (context) => handler.modify(context, entry, toItemKey(context, entry.itemName)),\r\n modify: handler.modify,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling ConstantDifference.\r\n * @internal\r\n */\r\n public async visitConstantDifference(entry: ConstantDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addConstant,\r\n modify: modifyConstant,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling CustomAttributeClassDifference.\r\n * @internal\r\n */\r\n public async visitCustomAttributeClassDifference(entry: CustomAttributeClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addCustomAttributeClass,\r\n modify: modifyCustomAttributeClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling CustomAttributeDifference.\r\n * @internal\r\n */\r\n public async visitCustomAttributeInstanceDifference(entry: CustomAttributeDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"add\": return addCustomAttribute(this._context, entry);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EntityClassDifference.\r\n * @internal\r\n */\r\n public async visitEntityClassDifference(entry: EntityClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addEntityClass,\r\n modify: modifyEntityClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EntityClassMixinDifference.\r\n * @internal\r\n */\r\n public async visitEntityClassMixinDifference(entry: EntityClassMixinDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"add\": return addClassMixins(this._context, entry);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EnumerationDifference.\r\n * @internal\r\n */\r\n public async visitEnumerationDifference(entry: EnumerationDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addEnumeration,\r\n modify: modifyEnumeration,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling EnumeratorDifference.\r\n * @internal\r\n */\r\n public async visitEnumeratorDifference(entry: EnumeratorDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"add\": return addEnumerator(this._context, entry);\r\n case \"modify\": return modifyEnumerator(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatDifference.\r\n * @internal\r\n */\r\n public async visitFormatDifference(entry: FormatDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addFormat,\r\n modify: modifyFormat,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatUnitDifference.\r\n * @internal\r\n */\r\n public async visitFormatUnitDifference(entry: FormatUnitDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"modify\": return modifyFormatUnit(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling FormatUnitLabelDifference.\r\n * @internal\r\n */\r\n public async visitFormatUnitLabelDifference(entry: FormatUnitLabelDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"modify\": return modifyFormatUnitLabel(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling InvertedUnitDifference.\r\n * @internal\r\n */\r\n public async visitInvertedUnitDifference(entry: InvertedUnitDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addInvertedUnit,\r\n modify: modifyInvertedUnit,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling KindOfQuantityDifference.\r\n * @internal\r\n */\r\n public async visitKindOfQuantityDifference(entry: KindOfQuantityDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addKindOfQuantity,\r\n modify: modifyKindOfQuantity,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling MixinClassDifference.\r\n * @internal\r\n */\r\n public async visitMixinDifference(entry: MixinClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addMixinClass,\r\n modify: modifyMixinClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling PhenomenonDifference.\r\n * @internal\r\n */\r\n public async visitPhenomenonDifference(entry: PhenomenonDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addPhenomenon,\r\n modify: modifyPhenomenon,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling PropertyCategoryDifference.\r\n * @internal\r\n */\r\n public async visitPropertyCategoryDifference(entry: PropertyCategoryDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addPropertyCategory,\r\n modify: modifyPropertyCategory,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling ClassPropertyDifference.\r\n * @internal\r\n */\r\n public async visitPropertyDifference(entry: ClassPropertyDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n mergePropertyDifference(this._context, entry)\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipClassDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipClassDifference(entry: RelationshipClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addRelationshipClass,\r\n modify: modifyRelationshipClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipConstraintClassDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipConstraintClassDifference(entry: RelationshipConstraintClassDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n mergeRelationshipClassConstraint(this._context, entry)\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling RelationshipConstraintDifference.\r\n * @internal\r\n */\r\n public async visitRelationshipConstraintDifference(entry: RelationshipConstraintDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n await mergeRelationshipConstraint(this._context, entry);\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling SchemaDifference.\r\n * @internal\r\n */\r\n public async visitSchemaDifference(entry: SchemaDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n const { difference } = entry;\r\n if (difference.label !== undefined) {\r\n await this._context.editor.setDisplayLabel(this._context.targetSchemaKey, difference.label);\r\n }\r\n if (difference.description !== undefined) {\r\n await this._context.editor.setDescription(this._context.targetSchemaKey, difference.description);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Shared merging logic for all types of AnySchemaItemDifference union.\r\n */\r\n private async visitSchemaItemDifference<T extends AnySchemaItemDifference>(entry: T, handler: ItemChangeTypeHandler<T>) {\r\n switch (entry.changeType) {\r\n case \"add\": {\r\n return handler.add(this._context, entry);\r\n }\r\n case \"modify\": {\r\n if (\"schemaItemType\" in entry.difference && entry.difference.schemaItemType !== entry.schemaType) {\r\n throw new Error(`Changing the type of item '${entry.itemName}' not supported.`);\r\n }\r\n\r\n return handler.modify(this._context, entry, toItemKey(this._context, entry.itemName));\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling SchemaReferenceDifference.\r\n * @internal\r\n */\r\n public async visitSchemaReferenceDifference(entry: SchemaReferenceDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"add\": return addSchemaReferences(this._context, entry);\r\n case \"modify\": return modifySchemaReferences(this._context, entry);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling StructClassDifference.\r\n * @internal\r\n */\r\n public async visitStructClassDifference(entry: StructClassDifference, index: number, array: AnySchemaDifference[]): Promise<void> {\r\n return this.visitClassDifference(entry, index, array, {\r\n add: addStructClass,\r\n modify: modifyStructClass,\r\n });\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling UnitDifference.\r\n * @internal\r\n */\r\n public async visitUnitDifference(entry: UnitDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addUnit,\r\n modify: modifyUnit,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling UnitSystemDifference.\r\n * @internal\r\n */\r\n public async visitUnitSystemDifference(entry: UnitSystemDifference): Promise<void> {\r\n return this.trackOperation(entry, async () =>\r\n this.visitSchemaItemDifference(entry, {\r\n add: addUnitSystem,\r\n modify: modifyUnitSystem,\r\n })\r\n );\r\n }\r\n\r\n /**\r\n * Visitor implementation for handling KindOfQuantityPresentationFormatDifference.\r\n * @internal\r\n */\r\n public async visitKindOfQuantityPresentationFormatDifference(entry: KindOfQuantityPresentationFormatDifference): Promise<void> {\r\n return this.trackOperation(entry, async () => {\r\n switch (entry.changeType) {\r\n case \"add\": return addPresentationFormat(this._context, entry, toItemKey(this._context, entry.itemName));\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Helper method to get the index of the first element in the array that satisfies the provided testing function.\r\n * @param array Array to search.\r\n * @param predicate Function to execute on each value in the array.\r\n * @param fromIndex The index to start the search at.\r\n * @returns An index in the array if an element passes the test; otherwise, false.\r\n */\r\nfunction findIndexOf(array: AnySchemaDifference[], predicate: (entry: AnySchemaDifference) => boolean, fromIndex: number) {\r\n for (let i = fromIndex; i < array.length; i++) {\r\n if (predicate(array[i]))\r\n return i;\r\n }\r\n return false;\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
1
  import { SchemaDifferenceWalker } from "../Differencing/SchemaDifferenceVisitor";
2
2
  import { AnySchemaDifference, DifferenceType } from "../Differencing/SchemaDifference";
3
3
  /**
4
- * A walker that traverses the schema differences in a certain oder and invokes the appropriate
4
+ * A walker that traverses the schema differences in a certain order and invokes the appropriate
5
5
  * visitor method for each kind of schema difference.
6
6
  * @internal
7
7
  */
@@ -9,7 +9,7 @@ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
9
9
  const SchemaDifferenceVisitor_1 = require("../Differencing/SchemaDifferenceVisitor");
10
10
  const SchemaDifference_1 = require("../Differencing/SchemaDifference");
11
11
  /**
12
- * A walker that traverses the schema differences in a certain oder and invokes the appropriate
12
+ * A walker that traverses the schema differences in a certain order and invokes the appropriate
13
13
  * visitor method for each kind of schema difference.
14
14
  * @internal
15
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaMergingWalker.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingWalker.ts"],"names":[],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C;YAE9D,kCAAkC;YAClC,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,uBAAuB,CAAC,CAAC;SAC9E,CAAC,CAAC;IACL,CAAC;CACF;AArDD,kDAqDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { SchemaItemType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaDifferenceWalker } from \"../Differencing/SchemaDifferenceVisitor\";\r\nimport { AnySchemaDifference, DifferenceType, SchemaOtherTypes, SchemaType } from \"../Differencing/SchemaDifference\";\r\n\r\n/**\r\n * A walker that traverses the schema differences in a certain oder and invokes the appropriate\r\n * visitor method for each kind of schema difference.\r\n * @internal\r\n */\r\nexport class SchemaMergingWalker extends SchemaDifferenceWalker {\r\n\r\n /**\r\n * Traverses the schema differences and calls the appropriate method on the visitor.\r\n * This method overrides the derived class method to apply some ordering how the\r\n * differences are traversed.\r\n *\r\n * @param differences The differences to traverse.\r\n * @param changeType Optional type of change to filter by.\r\n */\r\n public override async traverse(differences: Array<AnySchemaDifference>, changeType?: DifferenceType): Promise<void> {\r\n\r\n const filterByType = (schemaType: SchemaType) => {\r\n return (entry: AnySchemaDifference) => {\r\n return entry.schemaType === schemaType && (!changeType || entry.changeType === changeType);\r\n };\r\n };\r\n\r\n return super.traverse([\r\n // First the schema related differences are traversed...\r\n ...differences.filter(filterByType(SchemaOtherTypes.Schema)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.SchemaReference)),\r\n\r\n // Then the schema items (excluding classes)...\r\n ...differences.filter(filterByType(SchemaItemType.UnitSystem)),\r\n ...differences.filter(filterByType(SchemaItemType.PropertyCategory)),\r\n ...differences.filter(filterByType(SchemaItemType.Enumeration)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.Enumerator)),\r\n ...differences.filter(filterByType(SchemaItemType.Phenomenon)),\r\n ...differences.filter(filterByType(SchemaItemType.Unit)),\r\n ...differences.filter(filterByType(SchemaItemType.InvertedUnit)),\r\n ...differences.filter(filterByType(SchemaItemType.Format)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.FormatUnit)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.FormatUnitLabel)),\r\n ...differences.filter(filterByType(SchemaItemType.KindOfQuantity)),\r\n ...differences.filter(filterByType(SchemaItemType.Constant)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.KindOfQuantityPresentationFormat)),\r\n\r\n // Followed by classes and class related differences...\r\n ...differences.filter(filterByType(SchemaItemType.CustomAttributeClass)),\r\n ...differences.filter(filterByType(SchemaItemType.Mixin)),\r\n ...differences.filter(filterByType(SchemaItemType.StructClass)),\r\n ...differences.filter(filterByType(SchemaItemType.EntityClass)),\r\n ...differences.filter(filterByType(SchemaItemType.RelationshipClass)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.EntityClassMixin)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.RelationshipConstraint)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.RelationshipConstraintClass)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.Property)),\r\n\r\n // And then the custom attributes.\r\n ...differences.filter(filterByType(SchemaOtherTypes.CustomAttributeInstance)),\r\n ]);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaMergingWalker.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMergingWalker.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA0D;AAC1D,qFAAiF;AACjF,uEAAqH;AAErH;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,gDAAsB;IAE7D;;;;;;;OAOG;IACa,KAAK,CAAC,QAAQ,CAAC,WAAuC,EAAE,UAA2B;QAEjG,MAAM,YAAY,GAAG,CAAC,UAAsB,EAAE,EAAE;YAC9C,OAAO,CAAC,KAA0B,EAAE,EAAE;gBACpC,OAAO,KAAK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AAc,CAAC,CAAC;YAClE,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,QAAQ,CAAC,CAAC;YAC5D,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,gCAAgC,CAAC,CAAC;YAEtF,uDAAuD;YACvD,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,oBAAoB,CAAC,CAAC;YACxE,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,KAAK,CAAC,CAAC;YACzD,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,WAAW,CAAC,CAAC;YAC/D,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,WAAW,CAAC,CAAC;YAC/D,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,kCAAc,CAAC,iBAAiB,CAAC,CAAC;YACrE,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,gBAAgB,CAAC,CAAC;YACtE,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,sBAAsB,CAAC,CAAC;YAC5E,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,2BAA2B,CAAC,CAAC;YACjF,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,QAAQ,CAAC,CAAC;YAE9D,kCAAkC;YAClC,GAAG,WAAW,CAAC,MAAM,CAAC,YAAY,CAAC,mCAAgB,CAAC,uBAAuB,CAAC,CAAC;SAC9E,CAAC,CAAC;IACL,CAAC;CACF;AArDD,kDAqDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { SchemaItemType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaDifferenceWalker } from \"../Differencing/SchemaDifferenceVisitor\";\r\nimport { AnySchemaDifference, DifferenceType, SchemaOtherTypes, SchemaType } from \"../Differencing/SchemaDifference\";\r\n\r\n/**\r\n * A walker that traverses the schema differences in a certain order and invokes the appropriate\r\n * visitor method for each kind of schema difference.\r\n * @internal\r\n */\r\nexport class SchemaMergingWalker extends SchemaDifferenceWalker {\r\n\r\n /**\r\n * Traverses the schema differences and calls the appropriate method on the visitor.\r\n * This method overrides the derived class method to apply some ordering how the\r\n * differences are traversed.\r\n *\r\n * @param differences The differences to traverse.\r\n * @param changeType Optional type of change to filter by.\r\n */\r\n public override async traverse(differences: Array<AnySchemaDifference>, changeType?: DifferenceType): Promise<void> {\r\n\r\n const filterByType = (schemaType: SchemaType) => {\r\n return (entry: AnySchemaDifference) => {\r\n return entry.schemaType === schemaType && (!changeType || entry.changeType === changeType);\r\n };\r\n };\r\n\r\n return super.traverse([\r\n // First the schema related differences are traversed...\r\n ...differences.filter(filterByType(SchemaOtherTypes.Schema)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.SchemaReference)),\r\n\r\n // Then the schema items (excluding classes)...\r\n ...differences.filter(filterByType(SchemaItemType.UnitSystem)),\r\n ...differences.filter(filterByType(SchemaItemType.PropertyCategory)),\r\n ...differences.filter(filterByType(SchemaItemType.Enumeration)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.Enumerator)),\r\n ...differences.filter(filterByType(SchemaItemType.Phenomenon)),\r\n ...differences.filter(filterByType(SchemaItemType.Unit)),\r\n ...differences.filter(filterByType(SchemaItemType.InvertedUnit)),\r\n ...differences.filter(filterByType(SchemaItemType.Format)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.FormatUnit)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.FormatUnitLabel)),\r\n ...differences.filter(filterByType(SchemaItemType.KindOfQuantity)),\r\n ...differences.filter(filterByType(SchemaItemType.Constant)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.KindOfQuantityPresentationFormat)),\r\n\r\n // Followed by classes and class related differences...\r\n ...differences.filter(filterByType(SchemaItemType.CustomAttributeClass)),\r\n ...differences.filter(filterByType(SchemaItemType.Mixin)),\r\n ...differences.filter(filterByType(SchemaItemType.StructClass)),\r\n ...differences.filter(filterByType(SchemaItemType.EntityClass)),\r\n ...differences.filter(filterByType(SchemaItemType.RelationshipClass)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.EntityClassMixin)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.RelationshipConstraint)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.RelationshipConstraintClass)),\r\n ...differences.filter(filterByType(SchemaOtherTypes.Property)),\r\n\r\n // And then the custom attributes.\r\n ...differences.filter(filterByType(SchemaOtherTypes.CustomAttributeInstance)),\r\n ]);\r\n }\r\n}\r\n"]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { Schema, SchemaContext, SchemaKey } from "@itwin/ecschema-metadata";
5
5
  import { SchemaContextEditor } from "../Editing/Editor";
6
- import { type SchemaDifferenceResult } from "../Differencing/SchemaDifference";
6
+ import { AnySchemaDifference, type SchemaDifferenceResult } from "../Differencing/SchemaDifference";
7
7
  import { SchemaEdits } from "./Edits/SchemaEdits";
8
8
  import { NameMapping } from "./Edits/NameMapping";
9
9
  /**
@@ -17,6 +17,64 @@ export interface SchemaMergeContext {
17
17
  readonly editor: SchemaContextEditor;
18
18
  readonly nameMapping: NameMapping;
19
19
  }
20
+ /**
21
+ * Represents a single merge operation that was executed.
22
+ * @internal
23
+ */
24
+ export interface SchemaMergeOperation {
25
+ readonly change: AnySchemaDifference;
26
+ }
27
+ /**
28
+ * Represents a merge operation that failed with an error.
29
+ * @internal
30
+ */
31
+ export interface SchemaMergeFailure extends SchemaMergeOperation {
32
+ readonly error: string;
33
+ }
34
+ /**
35
+ * Report of a schema merge operation containing success/failure details.
36
+ * @internal
37
+ */
38
+ export interface SchemaMergeReport {
39
+ /** Source schema identifier */
40
+ readonly sourceSchemaKey: SchemaKey;
41
+ /** Target schema identifier */
42
+ readonly targetSchemaKey: SchemaKey;
43
+ /** Array of successfully merged differences */
44
+ readonly successfulOperations: SchemaMergeOperation[];
45
+ /** Array of failed merge operations with their errors */
46
+ readonly failedOperations: SchemaMergeFailure[];
47
+ /** Summary statistics of the merge operation */
48
+ readonly mergeStatistics: {
49
+ readonly total: number;
50
+ readonly succeeded: number;
51
+ readonly failed: number;
52
+ };
53
+ /** Returns true if all operations succeeded */
54
+ readonly success: boolean;
55
+ }
56
+ /**
57
+ * @internal
58
+ */
59
+ export declare class SchemaMergeReporter implements SchemaMergeReport {
60
+ readonly sourceSchemaKey: SchemaKey;
61
+ readonly targetSchemaKey: SchemaKey;
62
+ readonly totalDifferences: number;
63
+ private readonly _succeeded;
64
+ private readonly _failed;
65
+ constructor(sourceSchemaKey: SchemaKey, targetSchemaKey: SchemaKey, totalDifferences: number);
66
+ get successfulOperations(): SchemaMergeOperation[];
67
+ get failedOperations(): SchemaMergeFailure[];
68
+ get mergeStatistics(): {
69
+ total: number;
70
+ succeeded: number;
71
+ failed: number;
72
+ };
73
+ get success(): boolean;
74
+ recordSuccess(change: AnySchemaDifference): void;
75
+ recordFailure(change: AnySchemaDifference, error: Error): void;
76
+ getMergeReport(): SchemaMergeReport;
77
+ }
20
78
  /**
21
79
  * Class to merge two schemas together.
22
80
  * @see [[merge]] or [[mergeSchemas]] to merge two schemas together.
@@ -24,6 +82,7 @@ export interface SchemaMergeContext {
24
82
  */
25
83
  export declare class SchemaMerger {
26
84
  private readonly _editingContext;
85
+ private _mergeReporter;
27
86
  /**
28
87
  * Constructs a new instance of the SchemaMerger object.
29
88
  * @param editingContext The schema contexts that holds the schema to be edited.
@@ -45,5 +104,10 @@ export declare class SchemaMerger {
45
104
  * @alpha
46
105
  */
47
106
  merge(differenceResult: SchemaDifferenceResult, edits?: SchemaEdits): Promise<Schema>;
107
+ /**
108
+ * Gets the merge report for the last merge operation.
109
+ * @alpha
110
+ */
111
+ getMergeReport(): SchemaMergeReport | undefined;
48
112
  }
49
113
  //# sourceMappingURL=SchemaMerger.d.ts.map