@itwin/ecschema-editing 4.6.0-dev.9 → 4.7.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/Differencing/SchemaConflicts.d.ts +14 -0
  3. package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -1
  4. package/lib/cjs/Differencing/SchemaConflicts.js +15 -2
  5. package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
  6. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
  7. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +0 -52
  8. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
  9. package/lib/cjs/Differencing/SchemaDifference.d.ts +2 -2
  10. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
  11. package/lib/cjs/Differencing/SchemaDifference.js +3 -3
  12. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
  13. package/lib/cjs/Editing/Constants.js.map +1 -1
  14. package/lib/cjs/Editing/CustomAttributes.d.ts +1 -1
  15. package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
  16. package/lib/cjs/Editing/CustomAttributes.js +2 -2
  17. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  18. package/lib/cjs/Editing/ECClasses.d.ts +29 -23
  19. package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
  20. package/lib/cjs/Editing/ECClasses.js +51 -95
  21. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  22. package/lib/cjs/Editing/Editor.js.map +1 -1
  23. package/lib/cjs/Editing/Entities.d.ts +6 -7
  24. package/lib/cjs/Editing/Entities.d.ts.map +1 -1
  25. package/lib/cjs/Editing/Entities.js +7 -27
  26. package/lib/cjs/Editing/Entities.js.map +1 -1
  27. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  28. package/lib/cjs/Editing/Formats.js.map +1 -1
  29. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  30. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  31. package/lib/cjs/Editing/Mixins.d.ts +6 -2
  32. package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
  33. package/lib/cjs/Editing/Mixins.js +7 -22
  34. package/lib/cjs/Editing/Mixins.js.map +1 -1
  35. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
  36. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  37. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  38. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  39. package/lib/cjs/Editing/Mutable/MutableEntityClass.js +2 -2
  40. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  41. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  42. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  43. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  44. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  45. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  46. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts +8 -0
  47. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts.map +1 -0
  48. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js +16 -0
  49. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js.map +1 -0
  50. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  51. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
  52. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  53. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  54. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  55. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  56. package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts +8 -0
  57. package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts.map +1 -0
  58. package/lib/cjs/Editing/Mutable/MutableStructProperty.js +16 -0
  59. package/lib/cjs/Editing/Mutable/MutableStructProperty.js.map +1 -0
  60. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  61. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  62. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  63. package/lib/cjs/Editing/Properties.d.ts +201 -0
  64. package/lib/cjs/Editing/Properties.d.ts.map +1 -0
  65. package/lib/cjs/Editing/Properties.js +349 -0
  66. package/lib/cjs/Editing/Properties.js.map +1 -0
  67. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  68. package/lib/cjs/Editing/RelationshipClasses.d.ts +12 -1
  69. package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
  70. package/lib/cjs/Editing/RelationshipClasses.js +26 -3
  71. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  72. package/lib/cjs/Editing/SchemaItems.js.map +1 -1
  73. package/lib/cjs/Editing/Structs.d.ts +1 -1
  74. package/lib/cjs/Editing/Structs.d.ts.map +1 -1
  75. package/lib/cjs/Editing/Structs.js +2 -2
  76. package/lib/cjs/Editing/Structs.js.map +1 -1
  77. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  78. package/lib/cjs/Editing/Units.js.map +1 -1
  79. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  80. package/lib/cjs/Merging/ClassMerger.js +7 -16
  81. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  82. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  83. package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
  84. package/lib/cjs/Merging/CustomAttributeMerger.js +6 -1
  85. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  86. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  87. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  88. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  89. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  90. package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
  91. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
  92. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
  93. package/lib/cjs/Merging/PropertyMerger.js +54 -23
  94. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  95. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
  96. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  97. package/lib/cjs/Merging/SchemaMerger.d.ts +1 -1
  98. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  99. package/lib/cjs/Merging/SchemaMerger.js +12 -8
  100. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  101. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  102. package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
  103. package/lib/cjs/Validation/Diagnostic.d.ts +2 -2
  104. package/lib/cjs/Validation/Diagnostic.d.ts.map +1 -1
  105. package/lib/cjs/Validation/Diagnostic.js +4 -4
  106. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  107. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  108. package/lib/cjs/Validation/ECRules.d.ts +35 -35
  109. package/lib/cjs/Validation/ECRules.d.ts.map +1 -1
  110. package/lib/cjs/Validation/ECRules.js.map +1 -1
  111. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  112. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  113. package/lib/cjs/Validation/Rules.js.map +1 -1
  114. package/lib/cjs/Validation/SchemaChanges.d.ts +38 -6
  115. package/lib/cjs/Validation/SchemaChanges.d.ts.map +1 -1
  116. package/lib/cjs/Validation/SchemaChanges.js +97 -27
  117. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  118. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  119. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  120. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  121. package/lib/cjs/Validation/SchemaCompareVisitor.js +4 -3
  122. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  123. package/lib/cjs/Validation/SchemaComparer.d.ts +1 -0
  124. package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
  125. package/lib/cjs/Validation/SchemaComparer.js +238 -260
  126. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  127. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  128. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  129. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  130. package/lib/cjs/ecschema-editing.d.ts +2 -0
  131. package/lib/cjs/ecschema-editing.d.ts.map +1 -1
  132. package/lib/cjs/ecschema-editing.js +2 -0
  133. package/lib/cjs/ecschema-editing.js.map +1 -1
  134. package/package.json +11 -11
  135. package/public/locales/en/ECSchemaEditing.json +26 -26
@@ -22,7 +22,7 @@ var SchemaCompareDirection;
22
22
  (function (SchemaCompareDirection) {
23
23
  SchemaCompareDirection[SchemaCompareDirection["Forward"] = 0] = "Forward";
24
24
  SchemaCompareDirection[SchemaCompareDirection["Backward"] = 1] = "Backward";
25
- })(SchemaCompareDirection = exports.SchemaCompareDirection || (exports.SchemaCompareDirection = {}));
25
+ })(SchemaCompareDirection || (exports.SchemaCompareDirection = SchemaCompareDirection = {}));
26
26
  function labelsMatch(label1, label2) {
27
27
  label1 = label1 === undefined ? "" : label1;
28
28
  label2 = label2 === undefined ? "" : label2;
@@ -94,9 +94,6 @@ class SchemaComparer {
94
94
  const promises = [];
95
95
  if (!schemaItemB) {
96
96
  promises.push(this._reporter.reportSchemaItemMissing(schemaItemA, this._compareDirection));
97
- promises.push(this._reporter.reportSchemaItemDelta(schemaItemA, "description", schemaItemA.description, undefined, this._compareDirection));
98
- promises.push(this._reporter.reportSchemaItemDelta(schemaItemA, "label", schemaItemA.label, undefined, this._compareDirection));
99
- promises.push(this._reporter.reportSchemaItemDelta(schemaItemA, "schemaItemType", schemaItemA.schemaItemType, undefined, this._compareDirection));
100
97
  await Promise.all(promises);
101
98
  return;
102
99
  }
@@ -119,25 +116,22 @@ class SchemaComparer {
119
116
  * @param classB The second ECClass.
120
117
  */
121
118
  async compareClasses(classA, classB) {
122
- if (this._compareDirection === SchemaCompareDirection.Backward && classB)
119
+ if (this._compareDirection === SchemaCompareDirection.Backward || !classB)
123
120
  return;
124
121
  const promises = [];
125
- const modifierB = classB ? classB.modifier : undefined;
126
- if (classA.modifier !== modifierB) {
122
+ if (classA.modifier !== classB.modifier) {
127
123
  const aMod = (0, ecschema_metadata_1.classModifierToString)(classA.modifier);
128
- const bMod = modifierB !== undefined ? (0, ecschema_metadata_1.classModifierToString)(modifierB) : undefined;
124
+ const bMod = (0, ecschema_metadata_1.classModifierToString)(classB.modifier);
129
125
  promises.push(this._reporter.reportClassDelta(classA, "modifier", aMod, bMod, this._compareDirection));
130
126
  }
131
- const baseClassA = classA.baseClass;
132
- const baseClassB = classB ? classB.baseClass : undefined;
133
- if (baseClassA || baseClassB) {
134
- const fullNameA = baseClassA ? baseClassA.fullName : undefined;
135
- const fullNameB = baseClassB ? baseClassB.fullName : undefined;
127
+ if (classA.baseClass || classB.baseClass) {
128
+ const fullNameA = classA.baseClass?.fullName;
129
+ const fullNameB = classB.baseClass?.fullName;
136
130
  if (fullNameA !== fullNameB) {
137
- const areSameByName = this.areItemsSameByName(baseClassA, baseClassB, classA.schema.name, classB?.schema.name);
131
+ const areSameByName = this.areItemsSameByName(classA.baseClass, classB.baseClass, classA.schema.name, classB.schema.name);
138
132
  if (!areSameByName) {
139
- const baseA = await baseClassA;
140
- const baseB = baseClassB ? await baseClassB : undefined;
133
+ const baseA = await classA.baseClass;
134
+ const baseB = await classB.baseClass;
141
135
  promises.push(this._reporter.reportBaseClassDelta(classA, baseA, baseB, this._compareDirection));
142
136
  }
143
137
  }
@@ -153,21 +147,6 @@ class SchemaComparer {
153
147
  const promises = [];
154
148
  if (!propertyB) {
155
149
  promises.push(this._reporter.reportPropertyMissing(propertyA, this._compareDirection));
156
- if (undefined !== propertyA.label)
157
- promises.push(this._reporter.reportPropertyDelta(propertyA, "label", propertyA.label, undefined, this._compareDirection));
158
- if (undefined !== propertyA.description)
159
- promises.push(this._reporter.reportPropertyDelta(propertyA, "description", propertyA.description, undefined, this._compareDirection));
160
- promises.push(this._reporter.reportPropertyDelta(propertyA, "priority", propertyA.priority, undefined, this._compareDirection));
161
- promises.push(this._reporter.reportPropertyDelta(propertyA, "isReadOnly", propertyA.isReadOnly, undefined, this._compareDirection));
162
- const catKeyA = propertyA.category ? (await propertyA.category).key : undefined;
163
- const catKeyAText = catKeyA ? catKeyA.fullName : undefined;
164
- if (undefined !== catKeyAText)
165
- promises.push(this._reporter.reportPropertyDelta(propertyA, "category", catKeyAText, undefined, this._compareDirection));
166
- const koqKeyA = propertyA.kindOfQuantity ? (await propertyA.kindOfQuantity).key : undefined;
167
- const koqKeyAText = koqKeyA ? koqKeyA.fullName : undefined;
168
- if (undefined !== koqKeyAText)
169
- promises.push(this._reporter.reportPropertyDelta(propertyA, "kindOfQuantity", koqKeyAText, undefined, this._compareDirection));
170
- await this.comparePropertyType(propertyA, undefined);
171
150
  await Promise.all(promises);
172
151
  return;
173
152
  }
@@ -182,25 +161,21 @@ class SchemaComparer {
182
161
  if (propertyA.priority !== propertyB.priority)
183
162
  promises.push(this._reporter.reportPropertyDelta(propertyA, "priority", propertyA.priority, propertyB.priority, this._compareDirection));
184
163
  if (propertyA.category || propertyB.category) {
185
- const catKeyA = propertyA.category ? (await propertyA.category).key : undefined;
186
- const catKeyB = propertyB.category ? (await propertyB.category).key : undefined;
187
- const catKeyAText = catKeyA ? catKeyA.fullName : undefined;
188
- const catKeyBText = catKeyB ? catKeyB.fullName : undefined;
189
- if (catKeyAText !== catKeyBText) {
164
+ const catKeyA = propertyA.category?.fullName;
165
+ const catKeyB = propertyB.category?.fullName;
166
+ if (catKeyA !== catKeyB) {
190
167
  const areSameByName = this.areItemsSameByName(propertyA.category, propertyB.category, propertyA.schema.name, propertyB.schema.name);
191
168
  if (!areSameByName)
192
- promises.push(this._reporter.reportPropertyDelta(propertyA, "category", catKeyAText, catKeyBText, this._compareDirection));
169
+ promises.push(this._reporter.reportPropertyDelta(propertyA, "category", catKeyA, catKeyB, this._compareDirection));
193
170
  }
194
171
  }
195
172
  if (propertyA.kindOfQuantity || propertyB.kindOfQuantity) {
196
- const koqKeyA = propertyA.kindOfQuantity ? (await propertyA.kindOfQuantity).key : undefined;
197
- const koqKeyB = propertyB.kindOfQuantity ? (await propertyB.kindOfQuantity).key : undefined;
198
- const koqKeyAText = koqKeyA ? koqKeyA.fullName : undefined;
199
- const koqKeyBText = koqKeyB ? koqKeyB.fullName : undefined;
200
- if (koqKeyAText !== koqKeyBText) {
173
+ const koqKeyA = propertyA.kindOfQuantity?.fullName;
174
+ const koqKeyB = propertyB.kindOfQuantity?.fullName;
175
+ if (koqKeyA !== koqKeyB) {
201
176
  const areSameByName = this.areItemsSameByName(propertyA.kindOfQuantity, propertyB.kindOfQuantity, propertyA.schema.name, propertyB.schema.name);
202
177
  if (!areSameByName)
203
- promises.push(this._reporter.reportPropertyDelta(propertyA, "kindOfQuantity", koqKeyAText, koqKeyBText, this._compareDirection));
178
+ promises.push(this._reporter.reportPropertyDelta(propertyA, "kindOfQuantity", koqKeyA, koqKeyB, this._compareDirection));
204
179
  }
205
180
  }
206
181
  promises.push(this.comparePropertyType(propertyA, propertyB));
@@ -213,9 +188,11 @@ class SchemaComparer {
213
188
  */
214
189
  async compareEntityClasses(entityA, entityB) {
215
190
  const promises = [];
216
- for (const mixinA of entityA.mixins) {
217
- if (!entityB || -1 === entityB.mixins.findIndex((mixinB) => this.areItemsSameByName(mixinA, mixinB, entityA.schema.name, entityB.schema.name)))
218
- promises.push(this._reporter.reportEntityMixinMissing(entityA, await mixinA, this._compareDirection));
191
+ if (entityB) {
192
+ for (const mixinA of entityA.mixins) {
193
+ if (-1 === entityB.mixins.findIndex((mixinB) => this.areItemsSameByName(mixinA, mixinB, entityA.schema.name, entityB.schema.name)))
194
+ promises.push(this._reporter.reportEntityMixinMissing(entityA, await mixinA, this._compareDirection));
195
+ }
219
196
  }
220
197
  await Promise.all(promises);
221
198
  }
@@ -225,13 +202,13 @@ class SchemaComparer {
225
202
  * @param mixinB
226
203
  */
227
204
  async compareMixins(mixinA, mixinB) {
228
- if (this._compareDirection === SchemaCompareDirection.Backward && mixinB)
205
+ if (this._compareDirection === SchemaCompareDirection.Backward || !mixinB)
229
206
  return;
230
- if (mixinA.appliesTo) {
231
- const appliesToA = mixinA.appliesTo.fullName;
232
- const appliesToB = mixinB ? mixinB.appliesTo ? mixinB.appliesTo.fullName : undefined : undefined;
207
+ if (mixinA.appliesTo || mixinB.appliesTo) {
208
+ const appliesToA = mixinA.appliesTo?.fullName;
209
+ const appliesToB = mixinB.appliesTo?.fullName;
233
210
  if (appliesToA !== appliesToB) {
234
- const areSameByName = this.areItemsSameByName(mixinA.appliesTo, mixinB?.appliesTo, mixinA.schema.name, mixinB?.schema.name);
211
+ const areSameByName = this.areItemsSameByName(mixinA.appliesTo, mixinB.appliesTo, mixinA.schema.name, mixinB.schema.name);
235
212
  if (!areSameByName)
236
213
  await this._reporter.reportMixinDelta(mixinA, "appliesTo", appliesToA, appliesToB, this._compareDirection);
237
214
  }
@@ -243,19 +220,17 @@ class SchemaComparer {
243
220
  * @param relationshipB
244
221
  */
245
222
  async compareRelationshipClasses(relationshipA, relationshipB) {
246
- if (this._compareDirection === SchemaCompareDirection.Backward && relationshipB)
223
+ if (this._compareDirection === SchemaCompareDirection.Backward || !relationshipB)
247
224
  return;
248
225
  const promises = [];
249
- const strengthB = relationshipB ? relationshipB.strength : undefined;
250
- if (relationshipA.strength !== strengthB) {
226
+ if (relationshipA.strength !== relationshipB.strength) {
251
227
  const strengthAString = (0, ecschema_metadata_1.strengthToString)(relationshipA.strength);
252
- const strengthBString = strengthB !== undefined ? (0, ecschema_metadata_1.strengthToString)(strengthB) : undefined;
228
+ const strengthBString = (0, ecschema_metadata_1.strengthToString)(relationshipB.strength);
253
229
  promises.push(this._reporter.reportRelationshipClassDelta(relationshipA, "strength", strengthAString, strengthBString, this._compareDirection));
254
230
  }
255
- const directionB = relationshipB ? relationshipB.strengthDirection : undefined;
256
- if (relationshipA.strengthDirection !== directionB) {
231
+ if (relationshipA.strengthDirection !== relationshipB.strengthDirection) {
257
232
  const directionAString = (0, ecschema_metadata_1.strengthDirectionToString)(relationshipA.strengthDirection);
258
- const directionBString = directionB !== undefined ? (0, ecschema_metadata_1.strengthDirectionToString)(directionB) : undefined;
233
+ const directionBString = (0, ecschema_metadata_1.strengthDirectionToString)(relationshipB.strengthDirection);
259
234
  promises.push(this._reporter.reportRelationshipClassDelta(relationshipA, "strengthDirection", directionAString, directionBString, this._compareDirection));
260
235
  }
261
236
  await Promise.all(promises);
@@ -267,36 +242,31 @@ class SchemaComparer {
267
242
  */
268
243
  async compareRelationshipConstraints(constraintA, constraintB) {
269
244
  const promises = [];
270
- if (constraintA.constraintClasses) {
245
+ if (constraintB && constraintA.constraintClasses) {
271
246
  for (const classA of constraintA.constraintClasses) {
272
- if (!constraintB || !constraintB.constraintClasses ||
273
- -1 === constraintB.constraintClasses.findIndex((classB) => this.areItemsSameByName(classA, classB, constraintA.schema.name, constraintB.schema.name)))
247
+ if (!constraintB.constraintClasses || -1 === constraintB.constraintClasses.findIndex((classB) => this.areItemsSameByName(classA, classB, constraintA.schema.name, constraintB.schema.name)))
274
248
  promises.push(this._reporter.reportRelationshipConstraintClassMissing(constraintA, await classA, this._compareDirection));
275
249
  }
276
250
  }
277
- if (this._compareDirection === SchemaCompareDirection.Backward && constraintB) {
251
+ if (this._compareDirection === SchemaCompareDirection.Backward || !constraintB) {
278
252
  await Promise.all(promises);
279
253
  return;
280
254
  }
281
- const constraintBMultiplicity = constraintB ? constraintB.multiplicity : undefined;
282
- if (constraintA.multiplicity || constraintBMultiplicity) {
283
- const multiplicityA = constraintA.multiplicity ? constraintA.multiplicity.toString() : undefined;
284
- const multiplicityB = constraintBMultiplicity ? constraintBMultiplicity.toString() : undefined;
255
+ if (constraintA.multiplicity || constraintB.multiplicity) {
256
+ const multiplicityA = constraintA.multiplicity.toString();
257
+ const multiplicityB = constraintB.multiplicity.toString();
285
258
  if (multiplicityA !== multiplicityB)
286
259
  promises.push(this._reporter.reportRelationshipConstraintDelta(constraintA, "multiplicity", multiplicityA, multiplicityB, this._compareDirection));
287
260
  }
288
- const constraintBRoleLabel = constraintB ? constraintB.roleLabel : undefined;
289
- if (constraintA.roleLabel !== constraintBRoleLabel)
290
- promises.push(this._reporter.reportRelationshipConstraintDelta(constraintA, "roleLabel", constraintA.roleLabel, constraintBRoleLabel, this._compareDirection));
291
- const constraintBPolymorphic = constraintB ? constraintB.polymorphic : undefined;
292
- if (constraintA.polymorphic !== constraintBPolymorphic)
293
- promises.push(this._reporter.reportRelationshipConstraintDelta(constraintA, "polymorphic", constraintA.polymorphic, constraintBPolymorphic, this._compareDirection));
294
- const constraintBAbstractConstraint = constraintB ? constraintB.abstractConstraint : undefined;
295
- if (constraintA.abstractConstraint || constraintBAbstractConstraint) {
296
- const abstractA = constraintA.abstractConstraint ? constraintA.abstractConstraint.fullName : undefined;
297
- const abstractB = constraintBAbstractConstraint ? constraintBAbstractConstraint.fullName : undefined;
261
+ if (constraintA.roleLabel !== constraintB.roleLabel)
262
+ promises.push(this._reporter.reportRelationshipConstraintDelta(constraintA, "roleLabel", constraintA.roleLabel, constraintB.roleLabel, this._compareDirection));
263
+ if (constraintA.polymorphic !== constraintB.polymorphic)
264
+ promises.push(this._reporter.reportRelationshipConstraintDelta(constraintA, "polymorphic", constraintA.polymorphic, constraintB.polymorphic, this._compareDirection));
265
+ if (constraintA.abstractConstraint || constraintB.abstractConstraint) {
266
+ const abstractA = constraintA.abstractConstraint?.fullName;
267
+ const abstractB = constraintB.abstractConstraint?.fullName;
298
268
  if (abstractA !== abstractB) {
299
- const areSameByName = this.areItemsSameByName(constraintA.abstractConstraint, constraintBAbstractConstraint, constraintA.schema.name, constraintB?.schema.name);
269
+ const areSameByName = this.areItemsSameByName(constraintA.abstractConstraint, constraintB.abstractConstraint, constraintA.schema.name, constraintB.schema.name);
300
270
  if (!areSameByName) {
301
271
  promises.push(this._reporter.reportRelationshipConstraintDelta(constraintA, "abstractConstraint", abstractA, abstractB, this._compareDirection));
302
272
  }
@@ -310,12 +280,11 @@ class SchemaComparer {
310
280
  * @param customAttributeClassB
311
281
  */
312
282
  async compareCustomAttributeClasses(customAttributeClassA, customAttributeClassB) {
313
- if (this._compareDirection === SchemaCompareDirection.Backward && customAttributeClassB)
283
+ if (this._compareDirection === SchemaCompareDirection.Backward || !customAttributeClassB)
314
284
  return;
315
- const containerTypeB = customAttributeClassB ? customAttributeClassB.containerType : undefined;
316
- if (customAttributeClassA.containerType !== containerTypeB) {
285
+ if (customAttributeClassA.containerType !== customAttributeClassB.containerType) {
317
286
  const typeA = (0, ecschema_metadata_1.containerTypeToString)(customAttributeClassA.containerType);
318
- const typeB = containerTypeB !== undefined ? (0, ecschema_metadata_1.containerTypeToString)(containerTypeB) : undefined;
287
+ const typeB = (0, ecschema_metadata_1.containerTypeToString)(customAttributeClassB.containerType);
319
288
  await this._reporter.reportCustomAttributeClassDelta(customAttributeClassA, "appliesTo", typeA, typeB, this._compareDirection);
320
289
  }
321
290
  }
@@ -326,10 +295,9 @@ class SchemaComparer {
326
295
  */
327
296
  async compareCustomAttributeContainers(containerA, containerB) {
328
297
  const promises = [];
329
- if (containerA.customAttributes) {
298
+ if (containerB && containerA.customAttributes) {
330
299
  for (const ca of containerA.customAttributes) {
331
- const caClassName = ca[0];
332
- if (!containerB || !containerB.customAttributes || !this.containerHasClass(caClassName, containerA, containerB))
300
+ if (!containerB.customAttributes || !this.containerHasClass(ca[1], containerA, containerB))
333
301
  promises.push(this._reporter.reportCustomAttributeInstanceClassMissing(containerA, ca[1], this._compareDirection));
334
302
  }
335
303
  }
@@ -342,29 +310,28 @@ class SchemaComparer {
342
310
  */
343
311
  async compareEnumerations(enumA, enumB) {
344
312
  const promises = [];
345
- for (const enumeratorA of enumA.enumerators) {
346
- const enumeratorB = enumB ? enumB.enumerators.find((e) => e.name === enumeratorA.name) : undefined;
347
- if (!enumeratorB) {
348
- promises.push(this._reporter.reportEnumeratorMissing(enumA, enumeratorA, this._compareDirection));
349
- promises.push(this.compareEnumerators(enumeratorA, enumeratorB, enumA, enumB));
350
- }
351
- else if (this._compareDirection === SchemaCompareDirection.Forward) {
352
- promises.push(this.compareEnumerators(enumeratorA, enumeratorB, enumA, enumB));
313
+ if (enumB) {
314
+ for (const enumeratorA of enumA.enumerators) {
315
+ const enumeratorB = enumB.enumerators.find((e) => e.name === enumeratorA.name);
316
+ if (!enumeratorB) {
317
+ promises.push(this._reporter.reportEnumeratorMissing(enumA, enumeratorA, this._compareDirection));
318
+ }
319
+ else if (this._compareDirection === SchemaCompareDirection.Forward) {
320
+ promises.push(this.compareEnumerators(enumeratorA, enumeratorB, enumA, enumB));
321
+ }
353
322
  }
354
323
  }
355
- if (this._compareDirection === SchemaCompareDirection.Backward && enumB) {
324
+ if (this._compareDirection === SchemaCompareDirection.Backward || !enumB) {
356
325
  await Promise.all(promises);
357
326
  return;
358
327
  }
359
- const typeB = enumB ? enumB.type : undefined;
360
- if (enumA.type !== typeB) {
328
+ if (enumA.type !== enumB.type) {
361
329
  const typeAString = enumA.type ? (0, ecschema_metadata_1.primitiveTypeToString)(enumA.type) : undefined;
362
- const typeBString = typeB !== undefined ? (0, ecschema_metadata_1.primitiveTypeToString)(typeB) : undefined;
330
+ const typeBString = enumB.type ? (0, ecschema_metadata_1.primitiveTypeToString)(enumB.type) : undefined;
363
331
  promises.push(this._reporter.reportEnumerationDelta(enumA, "type", typeAString, typeBString, this._compareDirection));
364
332
  }
365
- const isStrictB = enumB ? enumB.isStrict : undefined;
366
- if (enumA.isStrict !== isStrictB)
367
- promises.push(this._reporter.reportEnumerationDelta(enumA, "isStrict", enumA.isStrict, isStrictB, this._compareDirection));
333
+ if (enumA.isStrict !== enumB.isStrict)
334
+ promises.push(this._reporter.reportEnumerationDelta(enumA, "isStrict", enumA.isStrict, enumB.isStrict, this._compareDirection));
368
335
  await Promise.all(promises);
369
336
  }
370
337
  /**
@@ -374,26 +341,26 @@ class SchemaComparer {
374
341
  */
375
342
  async compareKindOfQuantities(koqA, koqB) {
376
343
  const promises = [];
377
- if (koqA.presentationFormats) {
378
- for (const unit of koqA.presentationFormats) {
379
- if (!koqB || !koqB.presentationFormats || -1 === koqB.presentationFormats.findIndex((u) => u.fullName === unit.fullName))
380
- promises.push(this._reporter.reportPresentationUnitMissing(koqA, unit, this._compareDirection));
344
+ if (koqB && koqA.presentationFormats) {
345
+ for (const unitA of koqA.presentationFormats) {
346
+ if (-1 === koqB.presentationFormats.findIndex((unitB) => this.areOverrideFormatsSameByName(unitA, unitB, koqA.schema.name, koqB.schema.name)))
347
+ promises.push(this._reporter.reportPresentationUnitMissing(koqA, unitA, this._compareDirection));
381
348
  }
382
349
  }
383
- if (this._compareDirection === SchemaCompareDirection.Backward && koqB) {
350
+ if (this._compareDirection === SchemaCompareDirection.Backward || !koqB) {
384
351
  await Promise.all(promises);
385
352
  return;
386
353
  }
387
- const errorB = koqB ? koqB.relativeError : undefined;
388
- if (koqA.relativeError !== errorB) {
389
- promises.push(this._reporter.reportKoqDelta(koqA, "relativeError", koqA.relativeError, errorB, this._compareDirection));
354
+ if (koqA.relativeError !== koqB.relativeError) {
355
+ promises.push(this._reporter.reportKoqDelta(koqA, "relativeError", koqA.relativeError, koqB.relativeError, this._compareDirection));
390
356
  }
391
- const unitB = koqB ? koqB.persistenceUnit : undefined;
392
- if (koqA.persistenceUnit || unitB) {
393
- const unitNameA = koqA.persistenceUnit ? koqA.persistenceUnit.fullName : undefined;
394
- const unitNameB = unitB ? unitB.fullName : undefined;
357
+ if (koqA.persistenceUnit || koqB.persistenceUnit) {
358
+ const unitNameA = koqA.persistenceUnit?.fullName;
359
+ const unitNameB = koqB.persistenceUnit?.fullName;
395
360
  if (unitNameA !== unitNameB) {
396
- promises.push(this._reporter.reportKoqDelta(koqA, "persistenceUnit", unitNameA, unitNameB, this._compareDirection));
361
+ const eqByName = this.areItemsSameByName(koqA.persistenceUnit, koqB.persistenceUnit, koqA.schema.name, koqB.schema.name);
362
+ if (!eqByName)
363
+ promises.push(this._reporter.reportKoqDelta(koqA, "persistenceUnit", unitNameA, unitNameB, this._compareDirection));
397
364
  }
398
365
  }
399
366
  await Promise.all(promises);
@@ -404,11 +371,10 @@ class SchemaComparer {
404
371
  * @param categoryB
405
372
  */
406
373
  async comparePropertyCategories(categoryA, categoryB) {
407
- if (this._compareDirection === SchemaCompareDirection.Backward && categoryB)
374
+ if (this._compareDirection === SchemaCompareDirection.Backward || !categoryB)
408
375
  return;
409
- const priorityB = categoryB ? categoryB.priority : undefined;
410
- if (categoryA.priority !== priorityB)
411
- await this._reporter.reportPropertyCategoryDelta(categoryA, "priority", categoryA.priority, priorityB, this._compareDirection);
376
+ if (categoryA.priority !== categoryB.priority)
377
+ await this._reporter.reportPropertyCategoryDelta(categoryA, "priority", categoryA.priority, categoryB.priority, this._compareDirection);
412
378
  }
413
379
  /**
414
380
  * Compares two Format objects to identify differences between property values.
@@ -418,64 +384,50 @@ class SchemaComparer {
418
384
  async compareFormats(formatA, formatB) {
419
385
  const promises = [];
420
386
  promises.push(this.compareFormatUnits(formatA, formatB));
421
- if (this._compareDirection === SchemaCompareDirection.Backward && formatB) {
387
+ if (this._compareDirection === SchemaCompareDirection.Backward || !formatB) {
422
388
  await Promise.all(promises);
423
389
  return;
424
390
  }
425
- const roundFactorB = formatB ? formatB.roundFactor : undefined;
426
- if (formatA.roundFactor !== roundFactorB)
427
- promises.push(this._reporter.reportFormatDelta(formatA, "roundFactor", formatA.roundFactor, roundFactorB, this._compareDirection));
428
- const typeB = formatB ? formatB.type : undefined;
429
- if (formatA.type !== typeB) {
391
+ if (formatA.roundFactor !== formatB.roundFactor)
392
+ promises.push(this._reporter.reportFormatDelta(formatA, "roundFactor", formatA.roundFactor, formatB.roundFactor, this._compareDirection));
393
+ if (formatA.type !== formatB.type) {
430
394
  const typeAString = (0, core_quantity_1.formatTypeToString)(formatA.type);
431
- const typeBString = typeB !== undefined ? (0, core_quantity_1.formatTypeToString)(typeB) : undefined;
395
+ const typeBString = (0, core_quantity_1.formatTypeToString)(formatB.type);
432
396
  promises.push(this._reporter.reportFormatDelta(formatA, "type", typeAString, typeBString, this._compareDirection));
433
397
  }
434
- const precisionB = formatB ? formatB.precision : undefined;
435
- if (formatA.precision !== precisionB)
436
- promises.push(this._reporter.reportFormatDelta(formatA, "precision", formatA.precision, precisionB, this._compareDirection));
437
- const minWidthB = formatB ? formatB.minWidth : undefined;
438
- if (formatA.minWidth !== minWidthB)
439
- promises.push(this._reporter.reportFormatDelta(formatA, "minWidth", formatA.minWidth, minWidthB, this._compareDirection));
440
- const scientificTypeB = formatB ? formatB.scientificType : undefined;
441
- if (formatA.scientificType !== scientificTypeB) {
398
+ if (formatA.precision !== formatB.precision)
399
+ promises.push(this._reporter.reportFormatDelta(formatA, "precision", formatA.precision, formatB.precision, this._compareDirection));
400
+ if (formatA.minWidth !== formatB.minWidth)
401
+ promises.push(this._reporter.reportFormatDelta(formatA, "minWidth", formatA.minWidth, formatB.minWidth, this._compareDirection));
402
+ if (formatA.scientificType !== formatB.scientificType) {
442
403
  const typeAString = formatA.scientificType !== undefined ? (0, core_quantity_1.scientificTypeToString)(formatA.scientificType) : undefined;
443
- const typeBString = scientificTypeB !== undefined ? (0, core_quantity_1.scientificTypeToString)(scientificTypeB) : undefined;
404
+ const typeBString = formatB.scientificType !== undefined ? (0, core_quantity_1.scientificTypeToString)(formatB.scientificType) : undefined;
444
405
  promises.push(this._reporter.reportFormatDelta(formatA, "scientificType", typeAString, typeBString, this._compareDirection));
445
406
  }
446
- const showSignOptionB = formatB ? formatB.showSignOption : undefined;
447
- if (formatA.showSignOption !== showSignOptionB) {
407
+ if (formatA.showSignOption !== formatB.showSignOption) {
448
408
  const optionA = (0, core_quantity_1.showSignOptionToString)(formatA.showSignOption);
449
- const optionB = showSignOptionB !== undefined ? (0, core_quantity_1.showSignOptionToString)(showSignOptionB) : undefined;
409
+ const optionB = (0, core_quantity_1.showSignOptionToString)(formatB.showSignOption);
450
410
  promises.push(this._reporter.reportFormatDelta(formatA, "showSignOption", optionA, optionB, this._compareDirection));
451
411
  }
452
- const decimalSeparatorB = formatB ? formatB.decimalSeparator : undefined;
453
- if (formatA.decimalSeparator !== decimalSeparatorB)
454
- promises.push(this._reporter.reportFormatDelta(formatA, "decimalSeparator", formatA.decimalSeparator, decimalSeparatorB, this._compareDirection));
455
- const thousandSeparatorB = formatB ? formatB.thousandSeparator : undefined;
456
- if (formatA.thousandSeparator !== thousandSeparatorB)
457
- promises.push(this._reporter.reportFormatDelta(formatA, "thousandSeparator", formatA.thousandSeparator, thousandSeparatorB, this._compareDirection));
458
- const uomSeparatorB = formatB ? formatB.uomSeparator : undefined;
459
- if (formatA.uomSeparator !== uomSeparatorB)
460
- promises.push(this._reporter.reportFormatDelta(formatA, "uomSeparator", formatA.uomSeparator, uomSeparatorB, this._compareDirection));
461
- const stationSeparatorB = formatB ? formatB.stationSeparator : undefined;
462
- if (formatA.stationSeparator !== stationSeparatorB)
463
- promises.push(this._reporter.reportFormatDelta(formatA, "stationSeparator", formatA.stationSeparator, stationSeparatorB, this._compareDirection));
464
- const stationOffsetSizeB = formatB ? formatB.stationOffsetSize : undefined;
465
- if (formatA.stationOffsetSize !== stationOffsetSizeB)
466
- promises.push(this._reporter.reportFormatDelta(formatA, "stationOffsetSize", formatA.stationOffsetSize, stationOffsetSizeB, this._compareDirection));
467
- const formatTraitsB = formatB ? formatB.formatTraits : undefined;
468
- if (formatA.formatTraits !== formatTraitsB) {
412
+ if (formatA.decimalSeparator !== formatB.decimalSeparator)
413
+ promises.push(this._reporter.reportFormatDelta(formatA, "decimalSeparator", formatA.decimalSeparator, formatB.decimalSeparator, this._compareDirection));
414
+ if (formatA.thousandSeparator !== formatB.thousandSeparator)
415
+ promises.push(this._reporter.reportFormatDelta(formatA, "thousandSeparator", formatA.thousandSeparator, formatB.thousandSeparator, this._compareDirection));
416
+ if (formatA.uomSeparator !== formatB.uomSeparator)
417
+ promises.push(this._reporter.reportFormatDelta(formatA, "uomSeparator", formatA.uomSeparator, formatB.uomSeparator, this._compareDirection));
418
+ if (formatA.stationSeparator !== formatB.stationSeparator)
419
+ promises.push(this._reporter.reportFormatDelta(formatA, "stationSeparator", formatA.stationSeparator, formatB.stationSeparator, this._compareDirection));
420
+ if (formatA.stationOffsetSize !== formatB.stationOffsetSize)
421
+ promises.push(this._reporter.reportFormatDelta(formatA, "stationOffsetSize", formatA.stationOffsetSize, formatB.stationOffsetSize, this._compareDirection));
422
+ if (formatA.formatTraits !== formatB.formatTraits) {
469
423
  const traitsA = (0, core_quantity_1.formatTraitsToArray)(formatA.formatTraits);
470
- const traitsB = formatTraitsB !== undefined ? (0, core_quantity_1.formatTraitsToArray)(formatTraitsB) : undefined;
471
- promises.push(this._reporter.reportFormatDelta(formatA, "formatTraits", traitsA.toString(), traitsB ? traitsB.toString() : undefined, this._compareDirection));
472
- }
473
- const spacerB = formatB ? formatB.spacer : undefined;
474
- if (formatA.spacer !== spacerB)
475
- promises.push(this._reporter.reportFormatDelta(formatA, "spacer", formatA.spacer, spacerB, this._compareDirection));
476
- const includeZeroB = formatB ? formatB.includeZero : undefined;
477
- if (formatA.includeZero !== includeZeroB)
478
- promises.push(this._reporter.reportFormatDelta(formatA, "includeZero", formatA.includeZero, includeZeroB, this._compareDirection));
424
+ const traitsB = (0, core_quantity_1.formatTraitsToArray)(formatB.formatTraits);
425
+ promises.push(this._reporter.reportFormatDelta(formatA, "formatTraits", traitsA.toString(), traitsB.toString(), this._compareDirection));
426
+ }
427
+ if (formatA.spacer !== formatB.spacer)
428
+ promises.push(this._reporter.reportFormatDelta(formatA, "spacer", formatA.spacer, formatB.spacer, this._compareDirection));
429
+ if (formatA.includeZero !== formatB.includeZero)
430
+ promises.push(this._reporter.reportFormatDelta(formatA, "includeZero", formatA.includeZero, formatB.includeZero, this._compareDirection));
479
431
  await Promise.all(promises);
480
432
  }
481
433
  /**
@@ -484,35 +436,35 @@ class SchemaComparer {
484
436
  * @param unitB
485
437
  */
486
438
  async compareUnits(unitA, unitB) {
487
- if (this._compareDirection === SchemaCompareDirection.Backward && unitB)
439
+ if (this._compareDirection === SchemaCompareDirection.Backward || !unitB)
488
440
  return;
489
441
  const promises = [];
490
- const phenomenonB = unitB ? unitB.phenomenon : undefined;
491
- if (unitA.phenomenon || phenomenonB) {
492
- const fullNameA = unitA.phenomenon ? unitA.phenomenon.fullName : undefined;
493
- const fullNameB = phenomenonB ? phenomenonB.fullName : undefined;
494
- if (fullNameA !== fullNameB)
495
- promises.push(this._reporter.reportUnitDelta(unitA, "phenomenon", fullNameA, fullNameB, this._compareDirection));
496
- }
497
- const unitSystemB = unitB ? unitB.unitSystem : undefined;
498
- if (unitA.unitSystem || unitSystemB) {
499
- const fullNameA = unitA.unitSystem ? unitA.unitSystem.fullName : undefined;
500
- const fullNameB = unitSystemB ? unitSystemB.fullName : undefined;
501
- if (fullNameA !== fullNameB)
502
- promises.push(this._reporter.reportUnitDelta(unitA, "unitSystem", fullNameA, fullNameB, this._compareDirection));
503
- }
504
- const definitionB = unitB ? unitB.definition : undefined;
505
- if (unitA.definition !== definitionB)
506
- promises.push(this._reporter.reportUnitDelta(unitA, "definition", unitA.definition, definitionB, this._compareDirection));
507
- const numeratorB = unitB ? unitB.numerator : undefined;
508
- if (unitA.numerator !== numeratorB)
509
- promises.push(this._reporter.reportUnitDelta(unitA, "numerator", unitA.numerator, numeratorB, this._compareDirection));
510
- const denominatorB = unitB ? unitB.denominator : undefined;
511
- if (unitA.denominator !== denominatorB)
512
- promises.push(this._reporter.reportUnitDelta(unitA, "denominator", unitA.denominator, denominatorB, this._compareDirection));
513
- const offsetB = unitB ? unitB.offset : undefined;
514
- if (unitA.offset !== offsetB)
515
- promises.push(this._reporter.reportUnitDelta(unitA, "offset", unitA.offset, offsetB, this._compareDirection));
442
+ if (unitA.phenomenon || unitB.phenomenon) {
443
+ const fullNameA = unitA.phenomenon?.fullName;
444
+ const fullNameB = unitB.phenomenon?.fullName;
445
+ if (fullNameA !== fullNameB) {
446
+ const eqByName = this.areItemsSameByName(unitA.phenomenon, unitB.phenomenon, unitA.schema.name, unitB.schema.name);
447
+ if (!eqByName)
448
+ promises.push(this._reporter.reportUnitDelta(unitA, "phenomenon", fullNameA, fullNameB, this._compareDirection));
449
+ }
450
+ }
451
+ if (unitA.unitSystem || unitB.unitSystem) {
452
+ const fullNameA = unitA.unitSystem?.fullName;
453
+ const fullNameB = unitB.unitSystem?.fullName;
454
+ if (fullNameA !== fullNameB) {
455
+ const eqByName = this.areItemsSameByName(unitA.unitSystem, unitB.unitSystem, unitA.schema.name, unitB.schema.name);
456
+ if (!eqByName)
457
+ promises.push(this._reporter.reportUnitDelta(unitA, "unitSystem", fullNameA, fullNameB, this._compareDirection));
458
+ }
459
+ }
460
+ if (unitA.definition !== unitB.definition)
461
+ promises.push(this._reporter.reportUnitDelta(unitA, "definition", unitA.definition, unitB.definition, this._compareDirection));
462
+ if (unitA.numerator !== unitB.numerator)
463
+ promises.push(this._reporter.reportUnitDelta(unitA, "numerator", unitA.numerator, unitB.numerator, this._compareDirection));
464
+ if (unitA.denominator !== unitB.denominator)
465
+ promises.push(this._reporter.reportUnitDelta(unitA, "denominator", unitA.denominator, unitB.denominator, this._compareDirection));
466
+ if (unitA.offset !== unitB.offset)
467
+ promises.push(this._reporter.reportUnitDelta(unitA, "offset", unitA.offset, unitB.offset, this._compareDirection));
516
468
  await Promise.all(promises);
517
469
  }
518
470
  /**
@@ -521,22 +473,26 @@ class SchemaComparer {
521
473
  * @param invertedUnitB
522
474
  */
523
475
  async compareInvertedUnits(invertedUnitA, invertedUnitB) {
524
- if (this._compareDirection === SchemaCompareDirection.Backward && invertedUnitB)
476
+ if (this._compareDirection === SchemaCompareDirection.Backward || !invertedUnitB)
525
477
  return;
526
478
  const promises = [];
527
- const invertsUnitB = invertedUnitB ? invertedUnitB.invertsUnit : undefined;
528
- if (invertedUnitA.invertsUnit || invertsUnitB) {
529
- const fullNameA = invertedUnitA.invertsUnit ? invertedUnitA.invertsUnit.fullName : undefined;
530
- const fullNameB = invertsUnitB ? invertsUnitB.fullName : undefined;
531
- if (fullNameA !== fullNameB)
532
- promises.push(this._reporter.reportInvertedUnitDelta(invertedUnitA, "invertsUnit", fullNameA, fullNameB, this._compareDirection));
533
- }
534
- const unitSystemB = invertedUnitB ? invertedUnitB.unitSystem : undefined;
535
- if (invertedUnitA.unitSystem || unitSystemB) {
536
- const fullNameA = invertedUnitA.unitSystem ? invertedUnitA.unitSystem.fullName : undefined;
537
- const fullNameB = unitSystemB ? unitSystemB.fullName : undefined;
538
- if (fullNameA !== fullNameB)
539
- promises.push(this._reporter.reportInvertedUnitDelta(invertedUnitA, "unitSystem", fullNameA, fullNameB, this._compareDirection));
479
+ if (invertedUnitA.invertsUnit || invertedUnitB.invertsUnit) {
480
+ const fullNameA = invertedUnitA.invertsUnit?.fullName;
481
+ const fullNameB = invertedUnitB.invertsUnit?.fullName;
482
+ if (fullNameA !== fullNameB) {
483
+ const eqByName = this.areItemsSameByName(invertedUnitA.invertsUnit, invertedUnitB.invertsUnit, invertedUnitA.schema.name, invertedUnitB.schema.name);
484
+ if (!eqByName)
485
+ promises.push(this._reporter.reportInvertedUnitDelta(invertedUnitA, "invertsUnit", fullNameA, fullNameB, this._compareDirection));
486
+ }
487
+ }
488
+ if (invertedUnitA.unitSystem || invertedUnitB.unitSystem) {
489
+ const fullNameA = invertedUnitA.unitSystem?.fullName;
490
+ const fullNameB = invertedUnitB.unitSystem?.fullName;
491
+ if (fullNameA !== fullNameB) {
492
+ const eqByName = this.areItemsSameByName(invertedUnitA.unitSystem, invertedUnitB.unitSystem, invertedUnitA.schema.name, invertedUnitB.schema.name);
493
+ if (!eqByName)
494
+ promises.push(this._reporter.reportInvertedUnitDelta(invertedUnitA, "unitSystem", fullNameA, fullNameB, this._compareDirection));
495
+ }
540
496
  }
541
497
  await Promise.all(promises);
542
498
  }
@@ -546,11 +502,10 @@ class SchemaComparer {
546
502
  * @param phenomenonB
547
503
  */
548
504
  async comparePhenomenons(phenomenonA, phenomenonB) {
549
- if (this._compareDirection === SchemaCompareDirection.Backward && phenomenonB)
505
+ if (this._compareDirection === SchemaCompareDirection.Backward || !phenomenonB)
550
506
  return;
551
- const definitionB = phenomenonB ? phenomenonB.definition : undefined;
552
- if (phenomenonA.definition !== definitionB)
553
- await this._reporter.reportPhenomenonDelta(phenomenonA, "definition", phenomenonA.definition, definitionB, this._compareDirection);
507
+ if (phenomenonA.definition !== phenomenonB.definition)
508
+ await this._reporter.reportPhenomenonDelta(phenomenonA, "definition", phenomenonA.definition, phenomenonB.definition, this._compareDirection);
554
509
  }
555
510
  /**
556
511
  * Compares two Constant objects to identify differences between property values.
@@ -558,51 +513,50 @@ class SchemaComparer {
558
513
  * @param constantB
559
514
  */
560
515
  async compareConstants(constantA, constantB) {
561
- if (this._compareDirection === SchemaCompareDirection.Backward && constantB)
516
+ if (this._compareDirection === SchemaCompareDirection.Backward || !constantB)
562
517
  return;
563
518
  const promises = [];
564
- const phenomenonB = constantB ? constantB.phenomenon : undefined;
565
- if (constantA.phenomenon || phenomenonB) {
566
- const fullNameA = constantA.phenomenon ? constantA.phenomenon.fullName : undefined;
567
- const fullNameB = phenomenonB ? phenomenonB.fullName : undefined;
568
- if (fullNameA !== fullNameB)
569
- promises.push(this._reporter.reportConstantDelta(constantA, "phenomenon", fullNameA, fullNameB, this._compareDirection));
570
- }
571
- const definitionB = constantB ? constantB.definition : undefined;
572
- if (constantA.definition !== definitionB)
573
- promises.push(this._reporter.reportConstantDelta(constantA, "definition", constantA.definition, definitionB, this._compareDirection));
574
- const numeratorB = constantB ? constantB.numerator : undefined;
575
- if (constantA.numerator !== numeratorB)
576
- promises.push(this._reporter.reportConstantDelta(constantA, "numerator", constantA.numerator, numeratorB, this._compareDirection));
577
- const denominatorB = constantB ? constantB.denominator : undefined;
578
- if (constantA.denominator !== denominatorB)
579
- promises.push(this._reporter.reportConstantDelta(constantA, "denominator", constantA.denominator, denominatorB, this._compareDirection));
519
+ if (constantA.phenomenon || constantB.phenomenon) {
520
+ const fullNameA = constantA.phenomenon?.fullName;
521
+ const fullNameB = constantB.phenomenon?.fullName;
522
+ if (fullNameA !== fullNameB) {
523
+ const eqByName = this.areItemsSameByName(constantA.phenomenon, constantB.phenomenon, constantA.schema.name, constantB.schema.name);
524
+ if (!eqByName)
525
+ promises.push(this._reporter.reportConstantDelta(constantA, "phenomenon", fullNameA, fullNameB, this._compareDirection));
526
+ }
527
+ }
528
+ if (constantA.definition !== constantB.definition)
529
+ promises.push(this._reporter.reportConstantDelta(constantA, "definition", constantA.definition, constantB.definition, this._compareDirection));
530
+ if (constantA.numerator !== constantB.numerator)
531
+ promises.push(this._reporter.reportConstantDelta(constantA, "numerator", constantA.numerator, constantB.numerator, this._compareDirection));
532
+ if (constantA.denominator !== constantB.denominator)
533
+ promises.push(this._reporter.reportConstantDelta(constantA, "denominator", constantA.denominator, constantB.denominator, this._compareDirection));
580
534
  await Promise.all(promises);
581
535
  }
582
536
  async comparePropertyType(propertyA, propertyB) {
583
537
  const promises = [];
584
538
  const propertyTypeA = (0, ecschema_metadata_1.propertyTypeToString)(propertyA.propertyType);
585
- const propertyTypeB = propertyB !== undefined ? (0, ecschema_metadata_1.propertyTypeToString)(propertyB.propertyType) : undefined;
539
+ const propertyTypeB = (0, ecschema_metadata_1.propertyTypeToString)(propertyB.propertyType);
586
540
  if (propertyTypeA !== propertyTypeB) {
587
541
  promises.push(this._reporter.reportPropertyDelta(propertyA, "type", propertyTypeA, propertyTypeB, this._compareDirection));
588
542
  }
589
543
  if (propertyA.isArray()) {
590
- const minOccursB = propertyB && propertyB.isArray() ? propertyB.minOccurs : undefined;
544
+ const minOccursB = propertyB.isArray() ? propertyB.minOccurs : undefined;
591
545
  if (propertyA.minOccurs !== minOccursB) {
592
546
  promises.push(this._reporter.reportPropertyDelta(propertyA, "minOccurs", propertyA.minOccurs, minOccursB, this._compareDirection));
593
547
  }
594
- const maxOccursB = propertyB && propertyB.isArray() ? propertyB.maxOccurs : undefined;
548
+ const maxOccursB = propertyB.isArray() ? propertyB.maxOccurs : undefined;
595
549
  if (propertyA.maxOccurs !== maxOccursB) {
596
550
  promises.push(this._reporter.reportPropertyDelta(propertyA, "maxOccurs", propertyA.maxOccurs, maxOccursB, this._compareDirection));
597
551
  }
598
552
  }
599
553
  if (propertyA.isEnumeration()) {
600
- const enumerationB = propertyB && propertyB.isEnumeration() ? propertyB.enumeration : undefined;
554
+ const enumerationB = propertyB.isEnumeration() ? propertyB.enumeration : undefined;
601
555
  if (propertyA.enumeration || enumerationB) {
602
- const enumA = propertyA.enumeration ? propertyA.enumeration.fullName : undefined;
603
- const enumB = enumerationB ? enumerationB.fullName : undefined;
556
+ const enumA = propertyA.enumeration?.fullName;
557
+ const enumB = enumerationB?.fullName;
604
558
  if (enumA !== enumB) {
605
- const areSameByName = this.areItemsSameByName(propertyA.enumeration, enumerationB, propertyA.schema.name, propertyB?.schema.name);
559
+ const areSameByName = this.areItemsSameByName(propertyA.enumeration, enumerationB, propertyA.schema.name, propertyB.schema.name);
606
560
  if (!areSameByName) {
607
561
  promises.push(this._reporter.reportPropertyDelta(propertyA, "enumeration", enumA, enumB, this._compareDirection));
608
562
  }
@@ -610,60 +564,60 @@ class SchemaComparer {
610
564
  }
611
565
  }
612
566
  if (propertyA.isNavigation()) {
613
- const strengthDirectionB = propertyB && propertyB.isNavigation() ? propertyB.direction : undefined;
567
+ const strengthDirectionB = propertyB.isNavigation() ? propertyB.direction : undefined;
614
568
  if (propertyA.direction !== strengthDirectionB) {
615
569
  const dirA = (0, ecschema_metadata_1.strengthDirectionToString)(propertyA.direction);
616
570
  const dirB = strengthDirectionB !== undefined ? (0, ecschema_metadata_1.strengthDirectionToString)(strengthDirectionB) : undefined;
617
571
  promises.push(this._reporter.reportPropertyDelta(propertyA, "direction", dirA, dirB, this._compareDirection));
618
572
  }
619
573
  if (propertyA.relationshipClass) { // eslint-disable-line @typescript-eslint/no-misused-promises
620
- const relationshipClassB = propertyB && propertyB.isNavigation() ? propertyB.relationshipClass : undefined;
574
+ const relationshipClassB = propertyB.isNavigation() ? propertyB.relationshipClass : undefined;
621
575
  const relA = propertyA.relationshipClass.fullName;
622
576
  const relB = relationshipClassB ? relationshipClassB.fullName : undefined;
623
577
  if (relA !== relB) {
624
- const areSameByName = this.areItemsSameByName(propertyA.relationshipClass, relationshipClassB, propertyA.schema.name, propertyB?.schema.name);
578
+ const areSameByName = this.areItemsSameByName(propertyA.relationshipClass, relationshipClassB, propertyA.schema.name, propertyB.schema.name);
625
579
  if (!areSameByName)
626
580
  promises.push(this._reporter.reportPropertyDelta(propertyA, "relationshipClass", relA, relB, this._compareDirection));
627
581
  }
628
582
  }
629
583
  }
630
584
  if (propertyA.isPrimitive()) {
631
- const primitiveTypeB = propertyB && propertyB.isPrimitive() ? propertyB.primitiveType : undefined;
585
+ const primitiveTypeB = propertyB.isPrimitive() ? propertyB.primitiveType : undefined;
632
586
  if (propertyA.primitiveType !== primitiveTypeB) {
633
587
  const aType = (0, ecschema_metadata_1.primitiveTypeToString)(propertyA.primitiveType);
634
588
  const bType = primitiveTypeB !== undefined ? (0, ecschema_metadata_1.primitiveTypeToString)(primitiveTypeB) : undefined;
635
589
  promises.push(this._reporter.reportPropertyDelta(propertyA, "primitiveType", aType, bType, this._compareDirection));
636
590
  }
637
- const minLengthB = propertyB && propertyB.isPrimitive() ? propertyB.minLength : undefined;
591
+ const minLengthB = propertyB.isPrimitive() ? propertyB.minLength : undefined;
638
592
  if (propertyA.minLength !== minLengthB) {
639
593
  promises.push(this._reporter.reportPropertyDelta(propertyA, "minLength", propertyA.minLength, minLengthB, this._compareDirection));
640
594
  }
641
595
  // valid for primitive and enumeration properties
642
- const maxLengthB = propertyB && propertyB.isPrimitive() ? propertyB.maxLength : undefined;
596
+ const maxLengthB = propertyB.isPrimitive() ? propertyB.maxLength : undefined;
643
597
  if (propertyA.maxLength !== maxLengthB) {
644
598
  promises.push(this._reporter.reportPropertyDelta(propertyA, "maxLength", propertyA.maxLength, maxLengthB, this._compareDirection));
645
599
  }
646
- const minValueB = propertyB && propertyB.isPrimitive() ? propertyB.minValue : undefined;
600
+ const minValueB = propertyB.isPrimitive() ? propertyB.minValue : undefined;
647
601
  if (propertyA.minValue !== minValueB) {
648
602
  promises.push(this._reporter.reportPropertyDelta(propertyA, "minValue", propertyA.minValue, minValueB, this._compareDirection));
649
603
  }
650
- const maxValueB = propertyB && propertyB.isPrimitive() ? propertyB.maxValue : undefined;
604
+ const maxValueB = propertyB.isPrimitive() ? propertyB.maxValue : undefined;
651
605
  if (propertyA.maxValue !== maxValueB) {
652
606
  promises.push(this._reporter.reportPropertyDelta(propertyA, "maxValue", propertyA.maxValue, maxValueB, this._compareDirection));
653
607
  }
654
- const extendedTypeNameB = propertyB && propertyB.isPrimitive() ? propertyB.extendedTypeName : undefined;
608
+ const extendedTypeNameB = propertyB.isPrimitive() ? propertyB.extendedTypeName : undefined;
655
609
  if (propertyA.extendedTypeName !== extendedTypeNameB) {
656
610
  promises.push(this._reporter.reportPropertyDelta(propertyA, "extendedTypeName", propertyA.extendedTypeName, extendedTypeNameB, this._compareDirection));
657
611
  }
658
612
  }
659
613
  if (propertyA.isStruct()) {
660
614
  const structA = propertyA.structClass;
661
- const structB = propertyB && propertyB.isStruct() ? propertyB.structClass : undefined;
615
+ const structB = propertyB.isStruct() ? propertyB.structClass : undefined;
662
616
  if (structA || structB) {
663
- const structNameA = structA ? structA.fullName : undefined;
664
- const structNameB = structB ? structB.fullName : undefined;
617
+ const structNameA = structA.fullName;
618
+ const structNameB = structB?.fullName;
665
619
  if (structNameA !== structNameB) {
666
- const areSameByName = this.areItemsSameByName(structA.key, structB?.key, propertyA.schema.name, propertyB?.schema.name);
620
+ const areSameByName = this.areItemsSameByName(structA.key, structB?.key, propertyA.schema.name, propertyB.schema.name);
667
621
  if (!areSameByName) {
668
622
  promises.push(this._reporter.reportPropertyDelta(propertyA, "structClass", structNameA, structNameB, this._compareDirection));
669
623
  }
@@ -674,13 +628,6 @@ class SchemaComparer {
674
628
  }
675
629
  async compareEnumerators(enumeratorA, enumeratorB, enumA, enumB) {
676
630
  const promises = [];
677
- if (!enumB || !enumeratorB) {
678
- promises.push(this._reporter.reportEnumeratorDelta(enumA, enumeratorA, "description", enumeratorA.description, undefined, this._compareDirection));
679
- promises.push(this._reporter.reportEnumeratorDelta(enumA, enumeratorA, "label", enumeratorA.label, undefined, this._compareDirection));
680
- promises.push(this._reporter.reportEnumeratorDelta(enumA, enumeratorA, "value", enumeratorA.value, undefined, this._compareDirection));
681
- await Promise.all(promises);
682
- return;
683
- }
684
631
  if (enumeratorA.description !== enumeratorB.description)
685
632
  promises.push(this._reporter.reportEnumeratorDelta(enumA, enumeratorA, "description", enumeratorA.description, enumeratorB.description, this._compareDirection));
686
633
  if (!labelsMatch(enumeratorA.label, enumeratorB.label))
@@ -691,16 +638,16 @@ class SchemaComparer {
691
638
  await Promise.all(promises);
692
639
  }
693
640
  async compareFormatUnits(formatA, formatB) {
694
- if (!formatA.units)
641
+ if (!formatA.units || !formatB)
695
642
  return;
696
643
  const promises = [];
697
644
  for (const unitA of formatA.units) {
698
- const unitB = formatB && formatB.units ? formatB.units.find((u) => u[0].fullName === unitA[0].fullName) : undefined;
645
+ const unitB = formatB.units ? formatB.units.find((u) => this.areItemsSameByName(unitA[0], u[0], formatA.schema.name, formatB.schema.name)) : undefined;
699
646
  if (!unitB) {
700
647
  promises.push(this._reporter.reportFormatUnitMissing(formatA, unitA[0], this._compareDirection));
701
648
  continue;
702
649
  }
703
- if (this._compareDirection === SchemaCompareDirection.Backward && formatB)
650
+ if (this._compareDirection === SchemaCompareDirection.Backward)
704
651
  continue;
705
652
  if (unitA[1] !== unitB[1]) {
706
653
  const labelA = unitA[1];
@@ -710,6 +657,19 @@ class SchemaComparer {
710
657
  }
711
658
  await Promise.all(promises);
712
659
  }
660
+ areOverrideFormatsSameByName(itemKeyA, itemKeyB, topLevelSchemaNameA, topLevelSchemaNameB) {
661
+ if (itemKeyA.units) {
662
+ for (const unitA of itemKeyA.units) {
663
+ if (!itemKeyB.units
664
+ || -1 === itemKeyB.units.findIndex((unitB) => this.areItemsSameByName(unitA[0], unitB[0], topLevelSchemaNameA, topLevelSchemaNameB)
665
+ && unitA[1] === unitB[1]))
666
+ return false;
667
+ }
668
+ }
669
+ const itemA = ecschema_metadata_1.OverrideFormat.isOverrideFormat(itemKeyA) ? itemKeyA.parent : itemKeyA;
670
+ const itemB = ecschema_metadata_1.OverrideFormat.isOverrideFormat(itemKeyB) ? itemKeyB.parent : itemKeyB;
671
+ return itemKeyA.precision === itemKeyB.precision && this.areItemsSameByName(itemA, itemB, topLevelSchemaNameA, topLevelSchemaNameB);
672
+ }
713
673
  /**
714
674
  * Compares two item keys.
715
675
  * @param itemKeyA item key A to compare to.
@@ -721,8 +681,16 @@ class SchemaComparer {
721
681
  areItemsSameByName(itemKeyA, itemKeyB, topLevelSchemaNameA, topLevelSchemaNameB) {
722
682
  const nameA = itemKeyA ? itemKeyA.name : undefined;
723
683
  const nameB = itemKeyB ? itemKeyB.name : undefined;
724
- const schemaNameA = itemKeyA ? itemKeyA.schemaName : undefined;
725
- const schemaNameB = itemKeyB ? itemKeyB.schemaName : undefined;
684
+ const schemaNameA = itemKeyA
685
+ ? ecschema_metadata_1.SchemaItem.isSchemaItem(itemKeyA)
686
+ ? itemKeyA.schema.name
687
+ : itemKeyA.schemaName
688
+ : undefined;
689
+ const schemaNameB = itemKeyB
690
+ ? ecschema_metadata_1.SchemaItem.isSchemaItem(itemKeyB)
691
+ ? itemKeyB.schema.name
692
+ : itemKeyB.schemaName
693
+ : undefined;
726
694
  return (nameA === nameB && schemaNameA === topLevelSchemaNameA && schemaNameB === topLevelSchemaNameB) || (nameA === nameB && schemaNameA === schemaNameB);
727
695
  }
728
696
  /**
@@ -732,13 +700,23 @@ class SchemaComparer {
732
700
  * @param containerB container in which to look for classNameA.
733
701
  * @returns true if a same classA is in containerB, otherwise false.
734
702
  */
735
- containerHasClass(classNameA, containerA, containerB) {
703
+ containerHasClass(attributeA, containerA, containerB) {
736
704
  if (containerB && containerB.customAttributes) {
737
705
  for (const caB of containerB.customAttributes) {
738
- const classNameB = caB[0];
739
- const classItemKeyA = containerA.schema.getSchemaItemKey(classNameA);
740
- const classItemKeyB = containerB.schema.getSchemaItemKey(classNameB);
741
- return this.areItemsSameByName(classItemKeyA, classItemKeyB, containerA.schema.name, containerB.schema.name);
706
+ const attributeB = caB[1];
707
+ const classItemKeyA = containerA.schema.getSchemaItemKey(attributeA.className);
708
+ const classItemKeyB = containerB.schema.getSchemaItemKey(attributeB.className);
709
+ if (this.areItemsSameByName(classItemKeyA, classItemKeyB, containerA.schema.name, containerB.schema.name)) {
710
+ return Object.keys(attributeA).every((property) => {
711
+ const propertyName = property.toString();
712
+ const valueA = attributeA[propertyName];
713
+ const valueB = attributeB[propertyName];
714
+ return propertyName === "className"
715
+ || valueA === valueB
716
+ || Array.isArray(valueA) && Array.isArray(valueB) && valueA.length === valueB.length
717
+ && valueA.every((val, idx) => val === valueB[idx]);
718
+ });
719
+ }
742
720
  }
743
721
  }
744
722
  return false;