@itwin/ecschema-editing 4.8.0-dev.6 → 4.8.0-dev.9

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 (114) hide show
  1. package/lib/cjs/Differencing/Errors.js.map +1 -1
  2. package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
  3. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
  4. package/lib/cjs/Differencing/SchemaDifference.d.ts +10 -119
  5. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
  6. package/lib/cjs/Differencing/SchemaDifference.js +28 -198
  7. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
  8. package/lib/cjs/Differencing/Utils.d.ts +100 -0
  9. package/lib/cjs/Differencing/Utils.d.ts.map +1 -0
  10. package/lib/cjs/Differencing/Utils.js +165 -0
  11. package/lib/cjs/Differencing/Utils.js.map +1 -0
  12. package/lib/cjs/Editing/Constants.js.map +1 -1
  13. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  14. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  15. package/lib/cjs/Editing/Editor.d.ts +7 -2
  16. package/lib/cjs/Editing/Editor.d.ts.map +1 -1
  17. package/lib/cjs/Editing/Editor.js +24 -1
  18. package/lib/cjs/Editing/Editor.js.map +1 -1
  19. package/lib/cjs/Editing/Entities.js.map +1 -1
  20. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  21. package/lib/cjs/Editing/Exception.d.ts +0 -1
  22. package/lib/cjs/Editing/Exception.d.ts.map +1 -1
  23. package/lib/cjs/Editing/Exception.js +0 -1
  24. package/lib/cjs/Editing/Exception.js.map +1 -1
  25. package/lib/cjs/Editing/Formats.d.ts.map +1 -1
  26. package/lib/cjs/Editing/Formats.js +4 -1
  27. package/lib/cjs/Editing/Formats.js.map +1 -1
  28. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  29. package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
  30. package/lib/cjs/Editing/KindOfQuantities.js +3 -1
  31. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  32. package/lib/cjs/Editing/Mixins.js.map +1 -1
  33. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
  34. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  35. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  36. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  37. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  38. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  39. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  40. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  41. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  42. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  43. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js.map +1 -1
  44. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  45. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
  46. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  47. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  48. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  49. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  50. package/lib/cjs/Editing/Mutable/MutableSchemaItem.js.map +1 -1
  51. package/lib/cjs/Editing/Mutable/MutableStructProperty.js.map +1 -1
  52. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  53. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  54. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  55. package/lib/cjs/Editing/Properties.d.ts +1 -4
  56. package/lib/cjs/Editing/Properties.d.ts.map +1 -1
  57. package/lib/cjs/Editing/Properties.js +4 -5
  58. package/lib/cjs/Editing/Properties.js.map +1 -1
  59. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  60. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  61. package/lib/cjs/Editing/SchemaItems.d.ts +2 -2
  62. package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
  63. package/lib/cjs/Editing/SchemaItems.js +4 -24
  64. package/lib/cjs/Editing/SchemaItems.js.map +1 -1
  65. package/lib/cjs/Editing/Structs.js.map +1 -1
  66. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  67. package/lib/cjs/Editing/Units.js.map +1 -1
  68. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  69. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  70. package/lib/cjs/Merging/ClassMerger.js +10 -10
  71. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  72. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  73. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  74. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  75. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  76. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  77. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  78. package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
  79. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
  80. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  81. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
  82. package/lib/cjs/Merging/SchemaItemMerger.d.ts +4 -4
  83. package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
  84. package/lib/cjs/Merging/SchemaItemMerger.js +18 -18
  85. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  86. package/lib/cjs/Merging/SchemaMerger.d.ts +7 -7
  87. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  88. package/lib/cjs/Merging/SchemaMerger.js +32 -31
  89. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  90. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  91. package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
  92. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  93. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  94. package/lib/cjs/Validation/ECRules.js.map +1 -1
  95. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  96. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  97. package/lib/cjs/Validation/Rules.js.map +1 -1
  98. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  99. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  100. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  101. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  102. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  103. package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
  104. package/lib/cjs/Validation/SchemaComparer.js +31 -8
  105. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  106. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  107. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  108. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  109. package/lib/cjs/ecschema-editing.d.ts +2 -1
  110. package/lib/cjs/ecschema-editing.d.ts.map +1 -1
  111. package/lib/cjs/ecschema-editing.js +3 -2
  112. package/lib/cjs/ecschema-editing.js.map +1 -1
  113. package/package.json +9 -9
  114. package/public/locales/en/ECSchemaEditing.json +26 -26
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":";;;AAMA,yDAAmI;AACnI,+CAA4C;AAE5C,gEAA8M;AAI9M;;;G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,cAAc,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC9C,MAAM,kBAAkB,GAAG,MAAM,IAAA,sCAAmB,EAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAC9E,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAuB,kBAAkB,CAAC,CAAC;QACnH,IAAG,eAAe,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,kDAAkD,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,kBAAkB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;IACrF,CAAC;AACH,CAAC;AAhBD,4EAgBC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;QAC/B,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,QAAQ,CAAC;AACf,CAAC;AAED,KAAK,UAAU,+BAA+B,CAAC,OAA2B,EAAE,KAAkC;IAC5G,IAAI,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC;IAClD,IAAI,kBAAkB,KAAK,SAAS;QAClC,kBAAkB,GAAG,MAAM,IAAA,2CAAwB,EAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAEnF,MAAM,iBAAiB,GAAa,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9C,iBAAiB,CAAC,IAAI,CAAC,MAAM,IAAA,2CAAwB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,kBAAkB;QAClB,iBAAiB;KAClB,CAAC;AACJ,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 { type RelationshipClassDifference, type RelationshipConstraintClassDifference, type RelationshipConstraintDifference } from \"../Differencing/SchemaDifference\";\r\nimport { type MutableRelationshipClass } from \"../Editing/Mutable/MutableRelationshipClass\";\r\nimport { locateSchemaItem, type SchemaItemMergerHandler, updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\nimport { modifyClass } from \"./ClassMerger\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { EntityClass, Mixin, parseStrength, parseStrengthDirection, RelationshipClass, RelationshipConstraintProps, RelationshipMultiplicity, SchemaItemKey, SchemaItemType } from \"@itwin/ecschema-metadata\";\r\n\r\ntype ConstraintClassTypes = EntityClass | Mixin | RelationshipClass;\r\n\r\n/**\r\n * Defines a merge handler to merge RelationshipClass schema items.\r\n * @internal\r\n */\r\nexport const relationshipClassMerger: SchemaItemMergerHandler<RelationshipClassDifference> = {\r\n async add(context, change) {\r\n if (change.difference.strength === undefined) {\r\n throw new Error(\"RelationshipClass must define strength\");\r\n }\r\n if (change.difference.strengthDirection === undefined) {\r\n throw new Error(\"RelationshipClass must define strengthDirection\");\r\n }\r\n if (change.difference.source === undefined) {\r\n throw new Error(\"RelationshipClass must define a source constraint\");\r\n }\r\n if (change.difference.target === undefined) {\r\n throw new Error(\"RelationshipClass must define a target constraint\");\r\n }\r\n\r\n return context.editor.relationships.createFromProps(context.targetSchemaKey, {\r\n ...change.difference,\r\n name: change.itemName,\r\n schemaItemType: change.schemaType,\r\n strength: change.difference.strength,\r\n strengthDirection: change.difference.strengthDirection,\r\n source: await updateRelationshipConstraintKey(context, change.difference.source),\r\n target: await updateRelationshipConstraintKey(context, change.difference.target),\r\n });\r\n },\r\n async modify(context, change, itemKey, item: MutableRelationshipClass) {\r\n await modifyRelationshipClass(context, change, itemKey, item);\r\n },\r\n};\r\n\r\nasync function modifyRelationshipClass(context: SchemaMergeContext, change: RelationshipClassDifference, itemKey: SchemaItemKey, item: MutableRelationshipClass) {\r\n // The following modifications will only be applied if the items gets modified\r\n // and not the 2nd pass when adding a RelationshipClass.\r\n if(change.changeType === \"modify\") {\r\n if(change.difference.strength !== undefined) {\r\n if (item.strength === undefined) {\r\n const strength = parseStrength(change.difference.strength);\r\n if (strength === undefined) {\r\n throw new Error(`An invalid relationship class strength value '${change.difference.strength}' has been provided.`);\r\n }\r\n item.setStrength(strength);\r\n }\r\n throw new Error(`Changing the relationship '${itemKey.name}' strength is not supported.`);\r\n }\r\n if(change.difference.strengthDirection !== undefined) {\r\n if (item.strengthDirection === undefined) {\r\n const strengthDirection = parseStrengthDirection(change.difference.strengthDirection);\r\n if (strengthDirection === undefined) {\r\n throw new Error(`An invalid relationship class strengthDirection value '${change.difference.strengthDirection}' has been provided.`);\r\n }\r\n item.setStrengthDirection(strengthDirection);\r\n }\r\n throw new Error(`Changing the relationship '${itemKey.name}' strengthDirection is not supported.`);\r\n }\r\n }\r\n await modifyClass(context, change, itemKey, item);\r\n}\r\n\r\n/**\r\n * Merges differences of a Relationship constraint.\r\n * This only supports modify as the RelationshipConstraints are always set on the Relationship classes.\r\n * @internal\r\n */\r\nexport async function mergeRelationshipConstraint(context: SchemaMergeContext, change: RelationshipConstraintDifference) {\r\n if(change.changeType !== \"modify\") {\r\n throw new Error(\"RelationshipConstraints can only be modified.\");\r\n }\r\n\r\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\r\n const constraint = item[parseConstraint(change.path)];\r\n if(change.difference.roleLabel !== undefined) {\r\n constraint.roleLabel = change.difference.roleLabel;\r\n }\r\n if(change.difference.polymorphic !== undefined) {\r\n await context.editor.relationships.setConstraintPolymorphic(constraint, change.difference.polymorphic);\r\n }\r\n if(change.difference.multiplicity !== undefined) {\r\n if (constraint.multiplicity === undefined) {\r\n const multiplicity = RelationshipMultiplicity.fromString(change.difference.multiplicity);\r\n if (multiplicity === undefined) {\r\n throw new Error(`An invalid relationship constraint multiplicity value '${change.difference.multiplicity}' has been provided.`);\r\n }\r\n await context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);\r\n }\r\n throw new Error(`Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.`);\r\n }\r\n if(change.difference.abstractConstraint !== undefined) {\r\n const itemKey = await updateSchemaItemKey(context, change.difference.abstractConstraint);\r\n const abstractConstraint = await context.editor.schemaContext.getSchemaItem<ConstraintClassTypes>(itemKey);\r\n if (abstractConstraint === undefined) {\r\n throw new Error(`Unable to locate the abstract constraint class ${change.difference.abstractConstraint} in the context schema.`);\r\n }\r\n return context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);\r\n }\r\n return { itemKey: constraint.relationshipClass.key };\r\n}\r\n\r\n/**\r\n * Merges differences of a Relationship constraint classes.\r\n * @internal\r\n */\r\nexport async function mergeRelationshipClassConstraint(context: SchemaMergeContext, change: RelationshipConstraintClassDifference): Promise<void> {\r\n if(change.changeType !== \"add\") {\r\n throw new Error(`Change type ${change.changeType} is not supported for Relationship constraint classes.`);\r\n }\r\n\r\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\r\n const constraint = item[parseConstraint(change.path)];\r\n for(const constraintName of change.difference) {\r\n const constraintClassKey = await updateSchemaItemKey(context, constraintName);\r\n const constraintClass = await context.editor.schemaContext.getSchemaItem<ConstraintClassTypes>(constraintClassKey);\r\n if(constraintClass === undefined) {\r\n throw new Error(`Could not locate relationship constraint class ${constraintClassKey.name}`);\r\n }\r\n\r\n await context.editor.relationships.addConstraintClass(constraint, constraintClass);\r\n }\r\n}\r\n\r\nfunction parseConstraint(path: string): \"source\" | \"target\" {\r\n return path.startsWith(\"$source\")\r\n ? \"source\"\r\n : \"target\";\r\n}\r\n\r\nasync function updateRelationshipConstraintKey(context: SchemaMergeContext, props: RelationshipConstraintProps): Promise<RelationshipConstraintProps> {\r\n let abstractConstraint = props.abstractConstraint;\r\n if (abstractConstraint !== undefined)\r\n abstractConstraint = await updateSchemaItemFullName(context, abstractConstraint);\r\n\r\n const constraintClasses: string[] = [];\r\n for (const ecClass of props.constraintClasses) {\r\n constraintClasses.push(await updateSchemaItemFullName(context, ecClass));\r\n }\r\n\r\n return {\r\n ...props,\r\n abstractConstraint,\r\n constraintClasses,\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"RelationshipClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":";;;AAMA,yDAAmI;AACnI,+CAA4C;AAE5C,gEAA8M;AAI9M;;;GAGG;AACU,QAAA,uBAAuB,GAAyD;IAC3F,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM;QACvB,IAAI,MAAM,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,MAAM,CAAC,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE;YAC3E,GAAG,MAAM,CAAC,UAAU;YACpB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,cAAc,EAAE,MAAM,CAAC,UAAU;YACjC,QAAQ,EAAE,MAAM,CAAC,UAAU,CAAC,QAAQ;YACpC,iBAAiB,EAAE,MAAM,CAAC,U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B,GAAa,EAAE,CAAC;IACvC,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC9C,iBAAiB,CAAC,IAAI,CAAC,MAAM,IAAA,2CAAwB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,GAAG,KAAK;QACR,kBAAkB;QAClB,iBAAiB;KAClB,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { type RelationshipClassDifference, type RelationshipConstraintClassDifference, type RelationshipConstraintDifference } from \"../Differencing/SchemaDifference\";\nimport { type MutableRelationshipClass } from \"../Editing/Mutable/MutableRelationshipClass\";\nimport { locateSchemaItem, type SchemaItemMergerHandler, updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\nimport { modifyClass } from \"./ClassMerger\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { EntityClass, Mixin, parseStrength, parseStrengthDirection, RelationshipClass, RelationshipConstraintProps, RelationshipMultiplicity, SchemaItemKey, SchemaItemType } from \"@itwin/ecschema-metadata\";\n\ntype ConstraintClassTypes = EntityClass | Mixin | RelationshipClass;\n\n/**\n * Defines a merge handler to merge RelationshipClass schema items.\n * @internal\n */\nexport const relationshipClassMerger: SchemaItemMergerHandler<RelationshipClassDifference> = {\n async add(context, change) {\n if (change.difference.strength === undefined) {\n throw new Error(\"RelationshipClass must define strength\");\n }\n if (change.difference.strengthDirection === undefined) {\n throw new Error(\"RelationshipClass must define strengthDirection\");\n }\n if (change.difference.source === undefined) {\n throw new Error(\"RelationshipClass must define a source constraint\");\n }\n if (change.difference.target === undefined) {\n throw new Error(\"RelationshipClass must define a target constraint\");\n }\n\n return context.editor.relationships.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n strength: change.difference.strength,\n strengthDirection: change.difference.strengthDirection,\n source: await updateRelationshipConstraintKey(context, change.difference.source),\n target: await updateRelationshipConstraintKey(context, change.difference.target),\n });\n },\n async modify(context, change, itemKey, item: MutableRelationshipClass) {\n await modifyRelationshipClass(context, change, itemKey, item);\n },\n};\n\nasync function modifyRelationshipClass(context: SchemaMergeContext, change: RelationshipClassDifference, itemKey: SchemaItemKey, item: MutableRelationshipClass) {\n // The following modifications will only be applied if the items gets modified\n // and not the 2nd pass when adding a RelationshipClass.\n if(change.changeType === \"modify\") {\n if(change.difference.strength !== undefined) {\n if (item.strength === undefined) {\n const strength = parseStrength(change.difference.strength);\n if (strength === undefined) {\n throw new Error(`An invalid relationship class strength value '${change.difference.strength}' has been provided.`);\n }\n item.setStrength(strength);\n }\n throw new Error(`Changing the relationship '${itemKey.name}' strength is not supported.`);\n }\n if(change.difference.strengthDirection !== undefined) {\n if (item.strengthDirection === undefined) {\n const strengthDirection = parseStrengthDirection(change.difference.strengthDirection);\n if (strengthDirection === undefined) {\n throw new Error(`An invalid relationship class strengthDirection value '${change.difference.strengthDirection}' has been provided.`);\n }\n item.setStrengthDirection(strengthDirection);\n }\n throw new Error(`Changing the relationship '${itemKey.name}' strengthDirection is not supported.`);\n }\n }\n await modifyClass(context, change, itemKey, item);\n}\n\n/**\n * Merges differences of a Relationship constraint.\n * This only supports modify as the RelationshipConstraints are always set on the Relationship classes.\n * @internal\n */\nexport async function mergeRelationshipConstraint(context: SchemaMergeContext, change: RelationshipConstraintDifference) {\n if(change.changeType !== \"modify\") {\n throw new Error(\"RelationshipConstraints can only be modified.\");\n }\n\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\n const constraint = item[parseConstraint(change.path)];\n if(change.difference.roleLabel !== undefined) {\n constraint.roleLabel = change.difference.roleLabel;\n }\n if(change.difference.polymorphic !== undefined) {\n await context.editor.relationships.setConstraintPolymorphic(constraint, change.difference.polymorphic);\n }\n if(change.difference.multiplicity !== undefined) {\n if (constraint.multiplicity === undefined) {\n const multiplicity = RelationshipMultiplicity.fromString(change.difference.multiplicity);\n if (multiplicity === undefined) {\n throw new Error(`An invalid relationship constraint multiplicity value '${change.difference.multiplicity}' has been provided.`);\n }\n await context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);\n }\n throw new Error(`Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.`);\n }\n if(change.difference.abstractConstraint !== undefined) {\n const itemKey = await updateSchemaItemKey(context, change.difference.abstractConstraint);\n const abstractConstraint = await context.editor.schemaContext.getSchemaItem<ConstraintClassTypes>(itemKey);\n if (abstractConstraint === undefined) {\n throw new Error(`Unable to locate the abstract constraint class ${change.difference.abstractConstraint} in the context schema.`);\n }\n return context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);\n }\n return { itemKey: constraint.relationshipClass.key };\n}\n\n/**\n * Merges differences of a Relationship constraint classes.\n * @internal\n */\nexport async function mergeRelationshipClassConstraint(context: SchemaMergeContext, change: RelationshipConstraintClassDifference): Promise<void> {\n if(change.changeType !== \"add\") {\n throw new Error(`Change type ${change.changeType} is not supported for Relationship constraint classes.`);\n }\n\n const item = await locateSchemaItem(context, change.itemName, SchemaItemType.RelationshipClass) as MutableRelationshipClass;\n const constraint = item[parseConstraint(change.path)];\n for(const constraintName of change.difference) {\n const constraintClassKey = await updateSchemaItemKey(context, constraintName);\n const constraintClass = await context.editor.schemaContext.getSchemaItem<ConstraintClassTypes>(constraintClassKey);\n if(constraintClass === undefined) {\n throw new Error(`Could not locate relationship constraint class ${constraintClassKey.name}`);\n }\n\n await context.editor.relationships.addConstraintClass(constraint, constraintClass);\n }\n}\n\nfunction parseConstraint(path: string): \"source\" | \"target\" {\n return path.startsWith(\"$source\")\n ? \"source\"\n : \"target\";\n}\n\nasync function updateRelationshipConstraintKey(context: SchemaMergeContext, props: RelationshipConstraintProps): Promise<RelationshipConstraintProps> {\n let abstractConstraint = props.abstractConstraint;\n if (abstractConstraint !== undefined)\n abstractConstraint = await updateSchemaItemFullName(context, abstractConstraint);\n\n const constraintClasses: string[] = [];\n for (const ecClass of props.constraintClasses) {\n constraintClasses.push(await updateSchemaItemFullName(context, ecClass));\n }\n\n return {\n ...props,\n abstractConstraint,\n constraintClasses,\n };\n}\n"]}
@@ -5,8 +5,8 @@ import { SchemaItem, SchemaItemKey } from "@itwin/ecschema-metadata";
5
5
  * @internal
6
6
  */
7
7
  export interface SchemaItemMergerHandler<T extends AnySchemaItemDifference | AnySchemaItemPathDifference> {
8
- add: (context: SchemaMergeContext, change: T) => Promise<SchemaItemKey>;
9
- modify: (context: SchemaMergeContext, change: T, itemKey: SchemaItemKey, item: any) => Promise<void>;
8
+ add: (context: SchemaMergeContext, difference: T) => Promise<SchemaItemKey>;
9
+ modify: (context: SchemaMergeContext, difference: T, itemKey: SchemaItemKey, item: any) => Promise<void>;
10
10
  }
11
11
  /**
12
12
  * @internal
@@ -16,11 +16,11 @@ export declare function locateSchemaItem(context: SchemaMergeContext, itemName:
16
16
  * Merges the given set of schema items. As schema items may depend or relate with other
17
17
  * schema items, the list gets filtered to ensure the items get merged in a certain order.
18
18
  * @param context The current merging context.
19
- * @param itemChanges Set of schema item that differed.
19
+ * @param differences Set of schema item that differed.
20
20
  * @returns An async iterable with the merge result for each schema item.
21
21
  * @internal
22
22
  */
23
- export declare function mergeSchemaItems(context: SchemaMergeContext, itemChanges: AnySchemaDifference[]): AsyncGenerator<void, void, unknown>;
23
+ export declare function mergeSchemaItems(context: SchemaMergeContext, differences: AnySchemaDifference[]): AsyncGenerator<void, void, unknown>;
24
24
  /**
25
25
  * Convenience-method around updateSchemaItemKey that returns the full name instead of a SchemaItemKey.
26
26
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACz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AAW,uBAAuB,CAAC,CAAC,SAAS,uBAAuB,GAAG,2BAA2B;IACtG,GAAG,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5E,MAAM,EAAE,CAAC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1G;AAoBD;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,uBAQvG;AAED;;;;;;;GAOG;AACH,wBAAuB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,mBAAmB,EAAE,uCAwCtG;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,mBAG5F;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,0BAYvF"}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateSchemaItemKey = exports.updateSchemaItemFullName = exports.mergeSchemaItems = exports.locateSchemaItem = void 0;
4
- const SchemaDifference_1 = require("../Differencing/SchemaDifference");
5
4
  const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
6
5
  const EnumerationMerger_1 = require("./EnumerationMerger");
7
6
  const PhenomenonMerger_1 = require("./PhenomenonMerger");
@@ -10,20 +9,21 @@ const UnitSystemMerger_1 = require("./UnitSystemMerger");
10
9
  const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
11
10
  const ConstantMerger_1 = require("./ConstantMerger");
12
11
  const ClassMerger_1 = require("./ClassMerger");
12
+ const Utils = require("../Differencing/Utils");
13
13
  /**
14
14
  * Handles the merging logic for everything that is same for all schema items such as labels or descriptions
15
15
  * @internal
16
16
  */
17
- async function mergeSchemaItem(context, change, merger) {
18
- if (change.changeType === "add") {
19
- await merger.add(context, change);
17
+ async function mergeSchemaItem(context, difference, merger) {
18
+ if (difference.changeType === "add") {
19
+ await merger.add(context, difference);
20
20
  return;
21
21
  }
22
- if (change.changeType === "modify") {
23
- const schemaItem = await locateSchemaItem(context, change.itemName, change.schemaType);
24
- return merger.modify(context, change, schemaItem.key, schemaItem);
22
+ if (difference.changeType === "modify") {
23
+ const schemaItem = await locateSchemaItem(context, difference.itemName, difference.schemaType);
24
+ return merger.modify(context, difference, schemaItem.key, schemaItem);
25
25
  }
26
- throw new Error(`The merger does not support ${change.changeType} of ${change.schemaType}.`);
26
+ throw new Error(`The merger does not support ${difference.changeType} of ${difference.schemaType}.`);
27
27
  }
28
28
  /**
29
29
  * @internal
@@ -41,24 +41,24 @@ exports.locateSchemaItem = locateSchemaItem;
41
41
  * Merges the given set of schema items. As schema items may depend or relate with other
42
42
  * schema items, the list gets filtered to ensure the items get merged in a certain order.
43
43
  * @param context The current merging context.
44
- * @param itemChanges Set of schema item that differed.
44
+ * @param differences Set of schema item that differed.
45
45
  * @returns An async iterable with the merge result for each schema item.
46
46
  * @internal
47
47
  */
48
- async function* mergeSchemaItems(context, itemChanges) {
49
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isUnitSystemDifference)) {
48
+ async function* mergeSchemaItems(context, differences) {
49
+ for (const difference of differences.filter(Utils.isUnitSystemDifference)) {
50
50
  yield await mergeSchemaItem(context, difference, UnitSystemMerger_1.unitSystemMerger);
51
51
  }
52
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isPropertyCategoryDifference)) {
52
+ for (const difference of differences.filter(Utils.isPropertyCategoryDifference)) {
53
53
  yield await mergeSchemaItem(context, difference, PropertyCategoryMerger_1.propertyCategoryMerger);
54
54
  }
55
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isEnumerationDifference)) {
55
+ for (const difference of differences.filter(Utils.isEnumerationDifference)) {
56
56
  yield await mergeSchemaItem(context, difference, EnumerationMerger_1.enumerationMerger);
57
57
  }
58
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isEnumeratorDifference)) {
58
+ for (const difference of differences.filter(Utils.isEnumeratorDifference)) {
59
59
  yield await mergeSchemaItem(context, difference, EnumerationMerger_1.enumeratorMerger);
60
60
  }
61
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isPhenomenonDifference)) {
61
+ for (const difference of differences.filter(Utils.isPhenomenonDifference)) {
62
62
  yield await mergeSchemaItem(context, difference, PhenomenonMerger_1.phenomenonMerger);
63
63
  }
64
64
  // TODO:
@@ -66,15 +66,15 @@ async function* mergeSchemaItems(context, itemChanges) {
66
66
  // - Unit
67
67
  // - Inverted Unit
68
68
  // - Format
69
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isKindOfQuantityDifference)) {
69
+ for (const difference of differences.filter(Utils.isKindOfQuantityDifference)) {
70
70
  yield await mergeSchemaItem(context, difference, KindOfQuantityMerger_1.kindOfQuantityMerger);
71
71
  }
72
- for (const difference of itemChanges.filter(SchemaDifference_1.SchemaDifference.isConstantDifference)) {
72
+ for (const difference of differences.filter(Utils.isConstantDifference)) {
73
73
  yield await mergeSchemaItem(context, difference, ConstantMerger_1.constantMerger);
74
74
  }
75
75
  // Classes are slightly differently merged, since they can refer each other the process
76
76
  // uses several stages to merge.
77
- for await (const classMergeResult of (0, ClassMerger_1.mergeClassItems)(context, itemChanges)) {
77
+ for await (const classMergeResult of (0, ClassMerger_1.mergeClassItems)(context, differences)) {
78
78
  yield classMergeResult;
79
79
  }
80
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAKA,uEAA+I;AAC/I,gEAAqH;AACrH,2DAA0E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CAAC;AACvE,CAAC;AAZD,kDAYC;AAED;;;;GAIG;AACH,KAAK,UAAU,oBAAoB,CAAC,aAA4B,EAAE,OAAsB;IACtF,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,mGAAmG;QACnG,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,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 type { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { AnySchemaDifference, AnySchemaItemDifference, AnySchemaItemPathDifference, SchemaDifference } from \"../Differencing/SchemaDifference\";\r\nimport { ECObjectsError, ECObjectsStatus, SchemaContext, SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { enumerationMerger, enumeratorMerger } from \"./EnumerationMerger\";\r\nimport { phenomenonMerger } from \"./PhenomenonMerger\";\r\nimport { propertyCategoryMerger } from \"./PropertyCategoryMerger\";\r\nimport { unitSystemMerger } from \"./UnitSystemMerger\";\r\nimport { kindOfQuantityMerger } from \"./KindOfQuantityMerger\";\r\nimport { constantMerger } from \"./ConstantMerger\";\r\nimport { mergeClassItems } from \"./ClassMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaItemMergerHandler<T extends AnySchemaItemDifference | AnySchemaItemPathDifference> {\r\n add: (context: SchemaMergeContext, change: T) => Promise<SchemaItemKey>;\r\n modify: (context: SchemaMergeContext, change: T, itemKey: SchemaItemKey, item: any) => Promise<void>;\r\n}\r\n\r\n/**\r\n * Handles the merging logic for everything that is same for all schema items such as labels or descriptions\r\n * @internal\r\n */\r\nasync function mergeSchemaItem<T extends AnySchemaItemDifference|AnySchemaItemPathDifference>(context: SchemaMergeContext, change: T, merger: SchemaItemMergerHandler<T>): Promise<void> {\r\n if(change.changeType === \"add\") {\r\n await merger.add(context, change);\r\n return;\r\n }\r\n\r\n if(change.changeType === \"modify\") {\r\n const schemaItem = await locateSchemaItem(context, change.itemName, change.schemaType);\r\n return merger.modify(context, change, schemaItem.key, schemaItem);\r\n }\r\n\r\n throw new Error(`The merger does not support ${change.changeType} of ${change.schemaType}.`);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function locateSchemaItem(context: SchemaMergeContext, itemName: string, schemaType: string) {\r\n const schemaItemKey = new SchemaItemKey(itemName, context.targetSchemaKey);\r\n const schemaItem = await context.editor.schemaContext.getSchemaItem(schemaItemKey);\r\n if (schemaItem === undefined) {\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `${schemaType} ${schemaItemKey.fullName} not found in schema context.`);\r\n }\r\n\r\n return schemaItem;\r\n}\r\n\r\n/**\r\n * Merges the given set of schema items. As schema items may depend or relate with other\r\n * schema items, the list gets filtered to ensure the items get merged in a certain order.\r\n * @param context The current merging context.\r\n * @param itemChanges Set of schema item that differed.\r\n * @returns An async iterable with the merge result for each schema item.\r\n * @internal\r\n */\r\nexport async function* mergeSchemaItems(context: SchemaMergeContext, itemChanges: AnySchemaDifference[]) {\r\n for (const difference of itemChanges.filter(SchemaDifference.isUnitSystemDifference)) {\r\n yield await mergeSchemaItem(context, difference, unitSystemMerger);\r\n }\r\n\r\n for (const difference of itemChanges.filter(SchemaDifference.isPropertyCategoryDifference)) {\r\n yield await mergeSchemaItem(context, difference, propertyCategoryMerger);\r\n }\r\n\r\n for (const difference of itemChanges.filter(SchemaDifference.isEnumerationDifference)) {\r\n yield await mergeSchemaItem(context, difference, enumerationMerger);\r\n }\r\n\r\n for (const difference of itemChanges.filter(SchemaDifference.isEnumeratorDifference)) {\r\n yield await mergeSchemaItem(context, difference, enumeratorMerger);\r\n }\r\n\r\n for (const difference of itemChanges.filter(SchemaDifference.isPhenomenonDifference)) {\r\n yield await mergeSchemaItem(context, difference, phenomenonMerger);\r\n }\r\n\r\n // TODO:\r\n // The following schema items are not supported yet. Mentioned in the processing order:\r\n // - Unit\r\n // - Inverted Unit\r\n // - Format\r\n\r\n for (const difference of itemChanges.filter(SchemaDifference.isKindOfQuantityDifference)) {\r\n yield await mergeSchemaItem(context, difference, kindOfQuantityMerger);\r\n }\r\n\r\n for (const difference of itemChanges.filter(SchemaDifference.isConstantDifference)) {\r\n yield await mergeSchemaItem(context, difference, constantMerger);\r\n }\r\n\r\n // Classes are slightly differently merged, since they can refer each other the process\r\n // uses several stages to merge.\r\n for await (const classMergeResult of mergeClassItems(context, itemChanges)) {\r\n yield classMergeResult;\r\n }\r\n}\r\n\r\n/**\r\n * Convenience-method around updateSchemaItemKey that returns the full name instead of a SchemaItemKey.\r\n * @internal\r\n */\r\nexport async function updateSchemaItemFullName(context: SchemaMergeContext, reference: string) {\r\n const schemaItemKey = await updateSchemaItemKey(context, reference);\r\n return schemaItemKey.fullName;\r\n}\r\n\r\n/**\r\n * Updates the given reference if it refers to a SchemaItem in the source Schema and\r\n * returns a SchemaItemKey. If any other schema is referred the reference is not change.\r\n * @internal\r\n */\r\nexport async function updateSchemaItemKey(context: SchemaMergeContext, reference: string) {\r\n const [schemaName, itemName] = SchemaItem.parseFullName(reference);\r\n if (context.sourceSchemaKey.compareByName(schemaName)) {\r\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, context.targetSchemaKey));\r\n }\r\n\r\n const referencedSchema = await context.targetSchema.getReference(schemaName);\r\n if (referencedSchema !== undefined) {\r\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, referencedSchema.schemaKey));\r\n }\r\n\r\n throw new Error(`Cannot locate referenced schema item ${reference}`);\r\n}\r\n\r\n/**\r\n * To support case insensitivity for schema items, the given key is checked if there\r\n * exists an item for it.\r\n * @internal\r\n */\r\nasync function resolveSchemaItemKey(schemaContext: SchemaContext, itemKey: SchemaItemKey): Promise<SchemaItemKey> {\r\n const item = await schemaContext.getSchemaItem(itemKey);\r\n if (item === undefined) {\r\n // If the schema item hasn't been created yet, we have to trust the given key is correctly spelled.\r\n return itemKey;\r\n }\r\n return item.key;\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAMA,gEAAqH;AACrH,2DAA0E;AAC1E,yDAAsD;AACtD,qEAAkE;AAClE,yDAAsD;AACtD,iEAA8D;AAC9D,qDAAkD;AAClD,+CAAgD;AAChD,+CAA+C;AAU/C;;;GAGG;AACH,KAAK,UAAU,eAAe,CAAkE,OAA2B,EAAE,UAAa,EAAE,MAAkC;IAC5K,IAAI,UAAU,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QACpC,MAAM,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACtC,OAAO;IACT,CAAC;IAED,IAAI,UAAU,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QACvC,MAAM,UAAU,GAAG,MAAM,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QAC/F,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACxE,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+BAA+B,UAAU,CAAC,UAAU,OAAO,UAAU,CAAC,UAAU,GAAG,CAAC,CAAC;AACvG,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,gBAAgB,CAAC,OAA2B,EAAE,QAAgB,EAAE,UAAkB;IACtG,MAAM,aAAa,GAAG,IAAI,iCAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,C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,YAAY,CAAC,UAAU,CAAC,CAAC;IAC7E,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,IAAI,iCAAa,CAAC,QAAQ,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;IACrH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAC;AACvE,CAAC;AAZD,kDAYC;AAED;;;;GAIG;AACH,KAAK,UAAU,oBAAoB,CAAC,aAA4B,EAAE,OAAsB;IACtF,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,mGAAmG;QACnG,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\nimport { AnySchemaDifference, AnySchemaItemDifference, AnySchemaItemPathDifference } from \"../Differencing/SchemaDifference\";\nimport { ECObjectsError, ECObjectsStatus, SchemaContext, SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { enumerationMerger, enumeratorMerger } from \"./EnumerationMerger\";\nimport { phenomenonMerger } from \"./PhenomenonMerger\";\nimport { propertyCategoryMerger } from \"./PropertyCategoryMerger\";\nimport { unitSystemMerger } from \"./UnitSystemMerger\";\nimport { kindOfQuantityMerger } from \"./KindOfQuantityMerger\";\nimport { constantMerger } from \"./ConstantMerger\";\nimport { mergeClassItems } from \"./ClassMerger\";\nimport * as Utils from \"../Differencing/Utils\";\n\n/**\n * @internal\n */\nexport interface SchemaItemMergerHandler<T extends AnySchemaItemDifference | AnySchemaItemPathDifference> {\n add: (context: SchemaMergeContext, difference: T) => Promise<SchemaItemKey>;\n modify: (context: SchemaMergeContext, difference: T, itemKey: SchemaItemKey, item: any) => Promise<void>;\n}\n\n/**\n * Handles the merging logic for everything that is same for all schema items such as labels or descriptions\n * @internal\n */\nasync function mergeSchemaItem<T extends AnySchemaItemDifference | AnySchemaItemPathDifference>(context: SchemaMergeContext, difference: T, merger: SchemaItemMergerHandler<T>): Promise<void> {\n if (difference.changeType === \"add\") {\n await merger.add(context, difference);\n return;\n }\n\n if (difference.changeType === \"modify\") {\n const schemaItem = await locateSchemaItem(context, difference.itemName, difference.schemaType);\n return merger.modify(context, difference, schemaItem.key, schemaItem);\n }\n\n throw new Error(`The merger does not support ${difference.changeType} of ${difference.schemaType}.`);\n}\n\n/**\n * @internal\n */\nexport async function locateSchemaItem(context: SchemaMergeContext, itemName: string, schemaType: string) {\n const schemaItemKey = new SchemaItemKey(itemName, context.targetSchemaKey);\n const schemaItem = await context.editor.schemaContext.getSchemaItem(schemaItemKey);\n if (schemaItem === undefined) {\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `${schemaType} ${schemaItemKey.fullName} not found in schema context.`);\n }\n\n return schemaItem;\n}\n\n/**\n * Merges the given set of schema items. As schema items may depend or relate with other\n * schema items, the list gets filtered to ensure the items get merged in a certain order.\n * @param context The current merging context.\n * @param differences Set of schema item that differed.\n * @returns An async iterable with the merge result for each schema item.\n * @internal\n */\nexport async function* mergeSchemaItems(context: SchemaMergeContext, differences: AnySchemaDifference[]) {\n for (const difference of differences.filter(Utils.isUnitSystemDifference)) {\n yield await mergeSchemaItem(context, difference, unitSystemMerger);\n }\n\n for (const difference of differences.filter(Utils.isPropertyCategoryDifference)) {\n yield await mergeSchemaItem(context, difference, propertyCategoryMerger);\n }\n\n for (const difference of differences.filter(Utils.isEnumerationDifference)) {\n yield await mergeSchemaItem(context, difference, enumerationMerger);\n }\n\n for (const difference of differences.filter(Utils.isEnumeratorDifference)) {\n yield await mergeSchemaItem(context, difference, enumeratorMerger);\n }\n\n for (const difference of differences.filter(Utils.isPhenomenonDifference)) {\n yield await mergeSchemaItem(context, difference, phenomenonMerger);\n }\n\n // TODO:\n // The following schema items are not supported yet. Mentioned in the processing order:\n // - Unit\n // - Inverted Unit\n // - Format\n\n for (const difference of differences.filter(Utils.isKindOfQuantityDifference)) {\n yield await mergeSchemaItem(context, difference, kindOfQuantityMerger);\n }\n\n for (const difference of differences.filter(Utils.isConstantDifference)) {\n yield await mergeSchemaItem(context, difference, constantMerger);\n }\n\n // Classes are slightly differently merged, since they can refer each other the process\n // uses several stages to merge.\n for await (const classMergeResult of mergeClassItems(context, differences)) {\n yield classMergeResult;\n }\n}\n\n/**\n * Convenience-method around updateSchemaItemKey that returns the full name instead of a SchemaItemKey.\n * @internal\n */\nexport async function updateSchemaItemFullName(context: SchemaMergeContext, reference: string) {\n const schemaItemKey = await updateSchemaItemKey(context, reference);\n return schemaItemKey.fullName;\n}\n\n/**\n * Updates the given reference if it refers to a SchemaItem in the source Schema and\n * returns a SchemaItemKey. If any other schema is referred the reference is not change.\n * @internal\n */\nexport async function updateSchemaItemKey(context: SchemaMergeContext, reference: string) {\n const [schemaName, itemName] = SchemaItem.parseFullName(reference);\n if (context.sourceSchemaKey.compareByName(schemaName)) {\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, context.targetSchemaKey));\n }\n\n const referencedSchema = await context.targetSchema.getReference(schemaName);\n if (referencedSchema !== undefined) {\n return resolveSchemaItemKey(context.editor.schemaContext, new SchemaItemKey(itemName, referencedSchema.schemaKey));\n }\n\n throw new Error(`Cannot locate referenced schema item ${reference}`);\n}\n\n/**\n * To support case insensitivity for schema items, the given key is checked if there\n * exists an item for it.\n * @internal\n */\nasync function resolveSchemaItemKey(schemaContext: SchemaContext, itemKey: SchemaItemKey): Promise<SchemaItemKey> {\n const item = await schemaContext.getSchemaItem(itemKey);\n if (item === undefined) {\n // If the schema item hasn't been created yet, we have to trust the given key is correctly spelled.\n return itemKey;\n }\n return item.key;\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { Schema, type SchemaContext, SchemaKey } from "@itwin/ecschema-metadata";
5
5
  import { SchemaContextEditor } from "../Editing/Editor";
6
- import { SchemaDifferences } from "../Differencing/SchemaDifference";
6
+ import { SchemaDifferenceResult } from "../Differencing/SchemaDifference";
7
7
  /**
8
8
  * Defines the context of a Schema merging run.
9
9
  * @internal
@@ -32,19 +32,19 @@ export declare class SchemaMerger {
32
32
  * @param sourceSchema The schema the SchemaItems gets copied from.
33
33
  * @returns The merged target schema.
34
34
  */
35
- merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema>;
35
+ mergeSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<Schema>;
36
36
  /**
37
37
  * Merges the schema differences into the target schema context.
38
- * @param differences The changes that shall be applied to the target schema.
38
+ * @param differenceResult The differences that shall be applied to the target schema.
39
39
  * @alpha
40
40
  */
41
- merge(differences: SchemaDifferences): Promise<Schema>;
41
+ merge(differenceResult: SchemaDifferenceResult): Promise<Schema>;
42
42
  /**
43
43
  * Merges the schema differences in the target schema. The target schema is defined
44
44
  * in the given differences object.
45
- * @param differences The differences between a source schema and the target schema.
46
- * @returns The modified Schema.
45
+ * @param differenceResult The differences between a source schema and the target schema.
46
+ * @returns The modified Schema.
47
47
  */
48
- private mergeSchemas;
48
+ private mergeDifferences;
49
49
  }
50
50
  //# sourceMappingURL=SchemaMerger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAKv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,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAItF;;;;OAIG;IACU,KAAK,CAAC,gBAAgB,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7E;;;;;OAKG;YACW,gBAAgB;CAoD/B"}
@@ -15,6 +15,7 @@ const SchemaDifference_1 = require("../Differencing/SchemaDifference");
15
15
  const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
16
16
  const SchemaItemMerger_1 = require("./SchemaItemMerger");
17
17
  const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
18
+ const Utils = require("../Differencing/Utils");
18
19
  /**
19
20
  * Class to merge two schemas together.
20
21
  * @see [[merge]] to merge the schemas.
@@ -29,40 +30,40 @@ class SchemaMerger {
29
30
  this._editor = new Editor_1.SchemaContextEditor(editingContext);
30
31
  }
31
32
  /**
32
- * Merges the source and the target. If the target is a SchemaDifference, the
33
- * source parameter must not be set. If it's a schema, it'll internally call
34
- * the Differencing api and recall itself with the difference argument overload.
35
- * @param input The methods input either a schema or a SchemaDifferences
36
- * @param source A source schema.
37
- * @returns The merged schema.
33
+ * Copy the SchemaItems of the source schemas to the target schema.
34
+ * @param targetSchema The schema the SchemaItems gets merged to.
35
+ * @param sourceSchema The schema the SchemaItems gets copied from.
36
+ * @returns The merged target schema.
37
+ */
38
+ async mergeSchemas(targetSchema, sourceSchema) {
39
+ return this.merge(await (0, SchemaDifference_1.getSchemaDifferences)(targetSchema, sourceSchema));
40
+ }
41
+ /**
42
+ * Merges the schema differences into the target schema context.
43
+ * @param differenceResult The differences that shall be applied to the target schema.
38
44
  * @alpha
39
45
  */
40
- async merge(input, source) {
41
- if (ecschema_metadata_1.Schema.isSchema(input)) {
42
- if (source === undefined) {
43
- throw new Error("When merging two schemas, source must not be undefined.");
44
- }
45
- return this.merge(await SchemaDifference_1.SchemaDifference.fromSchemas(input, source));
46
- }
47
- return this.mergeSchemas(input);
46
+ async merge(differenceResult) {
47
+ return this.mergeDifferences(differenceResult);
48
48
  }
49
49
  /**
50
50
  * Merges the schema differences in the target schema. The target schema is defined
51
51
  * in the given differences object.
52
- * @param differences The differences between a source schema and the target schema.
53
- * @returns The modified Schema.
52
+ * @param differenceResult The differences between a source schema and the target schema.
53
+ * @returns The modified Schema.
54
54
  */
55
- async mergeSchemas(differences) {
56
- const targetSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differences.targetSchemaName);
57
- const sourceSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differences.sourceSchemaName);
58
- if (differences.conflicts && differences.conflicts.length > 0) {
59
- throw new Errors_1.SchemaConflictsError("Schema's can't be merged if there are unresolved conflicts.", differences.conflicts, sourceSchemaKey, targetSchemaKey);
55
+ async mergeDifferences(differenceResult) {
56
+ const targetSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.targetSchemaName);
57
+ const sourceSchemaKey = ecschema_metadata_1.SchemaKey.parseString(differenceResult.sourceSchemaName);
58
+ if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {
59
+ throw new Errors_1.SchemaConflictsError("Schema's can't be merged if there are unresolved conflicts.", differenceResult.conflicts, sourceSchemaKey, targetSchemaKey);
60
60
  }
61
61
  const schema = await this._editor.getSchema(targetSchemaKey);
62
62
  if (schema === undefined) {
63
63
  throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);
64
64
  }
65
- if (differences.differences === undefined || differences.differences.length === 0) {
65
+ const { differences } = differenceResult;
66
+ if (differences === undefined || differences.length === 0) {
66
67
  return schema;
67
68
  }
68
69
  const context = {
@@ -71,20 +72,20 @@ class SchemaMerger {
71
72
  targetSchemaKey,
72
73
  sourceSchemaKey,
73
74
  };
74
- for (const referenceChange of differences.differences.filter(SchemaDifference_1.SchemaDifference.isSchemaReferenceDifference)) {
75
+ for (const referenceChange of differences.filter(Utils.isSchemaReferenceDifference)) {
75
76
  await (0, SchemaReferenceMerger_1.mergeSchemaReferences)(context, referenceChange);
76
77
  }
77
- const schemaDifference = differences.differences.find(SchemaDifference_1.SchemaDifference.isSchemaDifference);
78
+ const schemaDifference = differences.find(Utils.isSchemaDifference);
78
79
  if (schemaDifference !== undefined) {
79
80
  await mergeSchemaProperties(schema, schemaDifference);
80
81
  }
81
82
  // Filter a list of possible schema item changes. This list gets filtered and order in the
82
83
  // mergeSchemaItems method.
83
- for await (const _mergeResult of (0, SchemaItemMerger_1.mergeSchemaItems)(context, differences.differences)) {
84
+ for await (const _mergeResult of (0, SchemaItemMerger_1.mergeSchemaItems)(context, differences)) {
84
85
  }
85
86
  // At last the custom attributes gets merged because it could be that the CustomAttributes
86
87
  // depend on classes that has to get merged in as items before.
87
- for (const customAttributeChange of differences.differences.filter(SchemaDifference_1.SchemaDifference.isCustomAttributeDifference)) {
88
+ for (const customAttributeChange of differences.filter(Utils.isCustomAttributeDifference)) {
88
89
  await (0, CustomAttributeMerger_1.mergeCustomAttribute)(context, customAttributeChange);
89
90
  }
90
91
  return schema;
@@ -95,12 +96,12 @@ exports.SchemaMerger = SchemaMerger;
95
96
  * Sets the editable properties of a Schema.
96
97
  * @internal
97
98
  */
98
- async function mergeSchemaProperties(schema, changes) {
99
- if (changes.difference.label !== undefined) {
100
- schema.setDisplayLabel(changes.difference.label);
99
+ async function mergeSchemaProperties(schema, { difference }) {
100
+ if (difference.label !== undefined) {
101
+ schema.setDisplayLabel(difference.label);
101
102
  }
102
- if (changes.difference.description !== undefined) {
103
- schema.setDescription(changes.difference.description);
103
+ if (difference.description !== undefined) {
104
+ schema.setDescription(difference.description);
104
105
  }
105
106
  }
106
107
  //# sourceMappingURL=SchemaMerger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,gEAAiF;AACjF,8CAAwD;AACxD,mDAA8D;AAC9D,uEAAuF;AACvF,mEAA+D;AAC/D,yDAAsD;AAC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O,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IACD,IAAG,OAAO,CAAC,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QAChD,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACxD,CAAC;AACH,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\n/** @packageDocumentation\r\n * @module Merging\r\n */\r\n\r\nimport { MutableSchema } from \"../Editing/Mutable/MutableSchema\";\r\nimport { Schema, type SchemaContext, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor } from \"../Editing/Editor\";\r\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\r\nimport { SchemaDifference, SchemaDifferences } from \"../Differencing/SchemaDifference\";\r\nimport { mergeCustomAttribute } from \"./CustomAttributeMerger\";\r\nimport { mergeSchemaItems } from \"./SchemaItemMerger\";\r\nimport { mergeSchemaReferences } from \"./SchemaReferenceMerger\";\r\n\r\n/**\r\n * Defines the context of a Schema merging run.\r\n * @internal\r\n */\r\nexport interface SchemaMergeContext {\r\n readonly targetSchema: Schema;\r\n readonly targetSchemaKey: SchemaKey;\r\n readonly sourceSchemaKey: SchemaKey;\r\n readonly editor: SchemaContextEditor;\r\n}\r\n\r\n/**\r\n * Class to merge two schemas together.\r\n * @see [[merge]] to merge the schemas.\r\n * @beta\r\n */\r\nexport class SchemaMerger {\r\n\r\n private readonly _editor: SchemaContextEditor;\r\n\r\n /**\r\n * Constructs a new instance of the SchemaMerger object.\r\n * @param editingContext The schema contexts that holds the schema to be edited.\r\n */\r\n constructor(editingContext: SchemaContext) {\r\n this._editor = new SchemaContextEditor(editingContext);\r\n }\r\n\r\n /**\r\n * Copy the SchemaItems of the source schemas to the target schema.\r\n * @param targetSchema The schema the SchemaItems gets merged to.\r\n * @param sourceSchema The schema the SchemaItems gets copied from.\r\n * @returns The merged target schema.\r\n */\r\n public merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema>;\r\n\r\n /**\r\n * Merges the schema differences into the target schema context.\r\n * @param differences The changes that shall be applied to the target schema.\r\n * @alpha\r\n */\r\n public merge(differences: SchemaDifferences): Promise<Schema>;\r\n\r\n /**\r\n * Merges the source and the target. If the target is a SchemaDifference, the\r\n * source parameter must not be set. If it's a schema, it'll internally call\r\n * the Differencing api and recall itself with the difference argument overload.\r\n * @param input The methods input either a schema or a SchemaDifferences\r\n * @param source A source schema.\r\n * @returns The merged schema.\r\n * @alpha\r\n */\r\n public async merge(input: SchemaDifferences | Schema, source?: Schema): Promise<Schema> {\r\n if(Schema.isSchema(input)) {\r\n if(source === undefined) {\r\n throw new Error(\"When merging two schemas, source must not be undefined.\");\r\n }\r\n return this.merge(await SchemaDifference.fromSchemas(input, source));\r\n }\r\n\r\n return this.mergeSchemas(input);\r\n }\r\n\r\n /**\r\n * Merges the schema differences in the target schema. The target schema is defined\r\n * in the given differences object.\r\n * @param differences The differences between a source schema and the target schema.\r\n * @returns The modified Schema.\r\n */\r\n private async mergeSchemas(differences: SchemaDifferences): Promise<Schema> {\r\n const targetSchemaKey = SchemaKey.parseString(differences.targetSchemaName);\r\n const sourceSchemaKey = SchemaKey.parseString(differences.sourceSchemaName);\r\n\r\n if(differences.conflicts && differences.conflicts.length > 0) {\r\n throw new SchemaConflictsError(\r\n \"Schema's can't be merged if there are unresolved conflicts.\",\r\n differences.conflicts,\r\n sourceSchemaKey,\r\n targetSchemaKey,\r\n );\r\n }\r\n\r\n const schema = await this._editor.getSchema(targetSchemaKey);\r\n if (schema === undefined) {\r\n throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);\r\n }\r\n\r\n if(differences.differences === undefined || differences.differences.length === 0) {\r\n return schema;\r\n }\r\n\r\n const context: SchemaMergeContext = {\r\n editor: this._editor,\r\n targetSchema: schema,\r\n targetSchemaKey,\r\n sourceSchemaKey,\r\n };\r\n\r\n for (const referenceChange of differences.differences.filter(SchemaDifference.isSchemaReferenceDifference)) {\r\n await mergeSchemaReferences(context, referenceChange);\r\n }\r\n\r\n const schemaDifference = differences.differences.find(SchemaDifference.isSchemaDifference);\r\n if(schemaDifference !== undefined) {\r\n await mergeSchemaProperties(schema, schemaDifference);\r\n }\r\n\r\n // Filter a list of possible schema item changes. This list gets filtered and order in the\r\n // mergeSchemaItems method.\r\n for await (const _mergeResult of mergeSchemaItems(context, differences.differences)) {\r\n }\r\n\r\n // At last the custom attributes gets merged because it could be that the CustomAttributes\r\n // depend on classes that has to get merged in as items before.\r\n for (const customAttributeChange of differences.differences.filter(SchemaDifference.isCustomAttributeDifference)) {\r\n await mergeCustomAttribute(context, customAttributeChange);\r\n }\r\n\r\n return schema;\r\n }\r\n}\r\n\r\n/**\r\n * Sets the editable properties of a Schema.\r\n * @internal\r\n */\r\nasync function mergeSchemaProperties(schema: MutableSchema, changes: SchemaDifference) {\r\n if(changes.difference.label !== undefined) {\r\n schema.setDisplayLabel(changes.difference.label);\r\n }\r\n if(changes.difference.description !== undefined) {\r\n schema.setDescription(changes.difference.description);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,gEAAiF;AACjF,8CAAwD;AACxD,mDAA8D;AAC9D,uEAAkH;AAClH,mEAA+D;AAC/D,yDAAsD;AACtD,mEAAgE;AAChE,+CAA+C;AAa/C;;;;GAIG;AACH,MAAa,YAAY;IAIvB;;;OAGG;IACH,YAAY,cAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,4BAAmB,CAAC,cAAc,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,YAAY,CAAC,YAAoB,EAAE,YAAoB;QAClE,OAAO,I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B,CAAC,EAAE,CAAC;YACpF,MAAM,IAAA,6CAAqB,EAAC,OAAO,EAAE,eAAe,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,gBAAgB,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACpE,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACnC,MAAM,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACxD,CAAC;QAED,0FAA0F;QAC1F,2BAA2B;QAC3B,IAAI,KAAK,EAAE,MAAM,YAAY,IAAI,IAAA,mCAAgB,EAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;QAC1E,CAAC;QAED,0FAA0F;QAC1F,+DAA+D;QAC/D,KAAK,MAAM,qBAAqB,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC;YAC1F,MAAM,IAAA,4CAAoB,EAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;QAC7D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAzFD,oCAyFC;AAED;;;GAGG;AACH,KAAK,UAAU,qBAAqB,CAAC,MAAqB,EAAE,EAAE,UAAU,EAAoB;IAC1F,IAAI,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACzC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Merging\n */\n\nimport { MutableSchema } from \"../Editing/Mutable/MutableSchema\";\nimport { Schema, type SchemaContext, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaConflictsError } from \"../Differencing/Errors\";\nimport { getSchemaDifferences, SchemaDifference, SchemaDifferenceResult } from \"../Differencing/SchemaDifference\";\nimport { mergeCustomAttribute } from \"./CustomAttributeMerger\";\nimport { mergeSchemaItems } from \"./SchemaItemMerger\";\nimport { mergeSchemaReferences } from \"./SchemaReferenceMerger\";\nimport * as Utils from \"../Differencing/Utils\";\n\n/**\n * Defines the context of a Schema merging run.\n * @internal\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly targetSchemaKey: SchemaKey;\n readonly sourceSchemaKey: SchemaKey;\n readonly editor: SchemaContextEditor;\n}\n\n/**\n * Class to merge two schemas together.\n * @see [[merge]] to merge the schemas.\n * @beta\n */\nexport class SchemaMerger {\n\n private readonly _editor: SchemaContextEditor;\n\n /**\n * Constructs a new instance of the SchemaMerger object.\n * @param editingContext The schema contexts that holds the schema to be edited.\n */\n constructor(editingContext: SchemaContext) {\n this._editor = new SchemaContextEditor(editingContext);\n }\n\n /**\n * Copy the SchemaItems of the source schemas to the target schema.\n * @param targetSchema The schema the SchemaItems gets merged to.\n * @param sourceSchema The schema the SchemaItems gets copied from.\n * @returns The merged target schema.\n */\n public async mergeSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\n return this.merge(await getSchemaDifferences(targetSchema, sourceSchema));\n }\n\n /**\n * Merges the schema differences into the target schema context.\n * @param differenceResult The differences that shall be applied to the target schema.\n * @alpha\n */\n public async merge(differenceResult: SchemaDifferenceResult): Promise<Schema> {\n return this.mergeDifferences(differenceResult);\n }\n\n /**\n * Merges the schema differences in the target schema. The target schema is defined\n * in the given differences object.\n * @param differenceResult The differences between a source schema and the target schema.\n * @returns The modified Schema.\n */\n private async mergeDifferences(differenceResult: SchemaDifferenceResult): Promise<Schema> {\n const targetSchemaKey = SchemaKey.parseString(differenceResult.targetSchemaName);\n const sourceSchemaKey = SchemaKey.parseString(differenceResult.sourceSchemaName);\n\n if (differenceResult.conflicts && differenceResult.conflicts.length > 0) {\n throw new SchemaConflictsError(\n \"Schema's can't be merged if there are unresolved conflicts.\",\n differenceResult.conflicts,\n sourceSchemaKey,\n targetSchemaKey,\n );\n }\n\n const schema = await this._editor.getSchema(targetSchemaKey);\n if (schema === undefined) {\n throw new Error(`The target schema '${targetSchemaKey.name}' could not be found in the editing context.`);\n }\n\n const { differences } = differenceResult;\n if (differences === undefined || differences.length === 0) {\n return schema;\n }\n\n const context: SchemaMergeContext = {\n editor: this._editor,\n targetSchema: schema,\n targetSchemaKey,\n sourceSchemaKey,\n };\n\n for (const referenceChange of differences.filter(Utils.isSchemaReferenceDifference)) {\n await mergeSchemaReferences(context, referenceChange);\n }\n\n const schemaDifference = differences.find(Utils.isSchemaDifference);\n if (schemaDifference !== undefined) {\n await mergeSchemaProperties(schema, schemaDifference);\n }\n\n // Filter a list of possible schema item changes. This list gets filtered and order in the\n // mergeSchemaItems method.\n for await (const _mergeResult of mergeSchemaItems(context, differences)) {\n }\n\n // At last the custom attributes gets merged because it could be that the CustomAttributes\n // depend on classes that has to get merged in as items before.\n for (const customAttributeChange of differences.filter(Utils.isCustomAttributeDifference)) {\n await mergeCustomAttribute(context, customAttributeChange);\n }\n\n return schema;\n }\n}\n\n/**\n * Sets the editable properties of a Schema.\n * @internal\n */\nasync function mergeSchemaProperties(schema: MutableSchema, { difference }: SchemaDifference) {\n if (difference.label !== undefined) {\n schema.setDisplayLabel(difference.label);\n }\n if (difference.description !== undefined) {\n schema.setDescription(difference.description);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaReferenceMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAyF;AAKzF;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CAAC,OAA2B,EAAE,MAAiC;IAC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AS,EAAE,EAAE,CAAC,SAAS,KAAK,cAAc,CAAC,CAAC;QACrG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAEjD,MAAM,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC;AA9BD,sDA8BC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,YAAY,CAAC,MAA2B,EAAE,UAAmB,EAAE,OAAgB;IAC5F,IAAG,UAAU,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,6BAAS,CAAC,UAAU,EAAE,6BAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,mCAAe,CAAC,qBAAqB,CAAC,CAAC;IACtG,IAAG,MAAM,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,qBAAqB,SAAS,CAAC,QAAQ,EAAE,uCAAuC,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC;QACf,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpB,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 { ECVersion, Schema, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { type SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { type SchemaReferenceDifference } from \"../Differencing/SchemaDifference\";\r\nimport { type SchemaContextEditor } from \"../Editing/Editor\";\r\n\r\n/**\r\n * Merges the schema references of two schemas.\r\n * @param context current merge context\r\n * @param change schema changes.\r\n * @internal\r\n */\r\nexport async function mergeSchemaReferences(context: SchemaMergeContext, change: SchemaReferenceDifference) {\r\n // If the target schema does not have a reference to a schema yet, it can be added\r\n // but should be checked if it's schema references have collisions with existing references.\r\n if(change.changeType === \"add\") {\r\n const referencedSchema = await locateSchema(context.editor, change.difference.name, change.difference.version);\r\n await context.editor.addSchemaReference(context.targetSchemaKey, referencedSchema);\r\n }\r\n\r\n // If the source schema referenced a schema that is also referenced by the target\r\n // schema but in a different version, it is marked as delta. Here we need to check if\r\n // the source schema is compatible to the existing one. This is not be checked by the\r\n // schema instance when added.\r\n if(change.changeType === \"modify\") {\r\n const referencedSchema = await locateSchema(context.editor, change.difference.name, change.difference.version);\r\n const existingSchema = (await context.targetSchema.getReference(referencedSchema.name))!;\r\n\r\n const [older, latest] = compareSchemas(existingSchema, referencedSchema);\r\n if(!latest.schemaKey.matches(older.schemaKey, SchemaMatchType.LatestWriteCompatible)) {\r\n throw new Error(`Schemas references of ${referencedSchema.name} have incompatible versions: ${older.schemaKey.version} and ${latest.schemaKey.version}`);\r\n }\r\n\r\n if(latest === existingSchema) {\r\n return;\r\n }\r\n\r\n const index = context.targetSchema.references.findIndex((reference) => reference === existingSchema);\r\n context.targetSchema.references.splice(index, 1);\r\n\r\n await context.editor.addSchemaReference(context.targetSchema.schemaKey, referencedSchema);\r\n }\r\n}\r\n\r\n/**\r\n * Tries to locate the Schema in the current Context\r\n * @param editor Current editor context.\r\n * @param schemaName The schema name to be looked up.\r\n * @param version The schemas version to beo looked up.\r\n * @returns The schema found in the context.\r\n */\r\nasync function locateSchema(editor: SchemaContextEditor, schemaName?: string, version?: string): Promise<Schema> {\r\n if(schemaName === undefined || version === undefined) {\r\n throw new Error(\"Schema name and version must not be undefined.\");\r\n }\r\n\r\n const schemaKey = new SchemaKey(schemaName, ECVersion.fromString(version));\r\n const schema = await editor.schemaContext.getSchema(schemaKey, SchemaMatchType.LatestWriteCompatible);\r\n if(schema === undefined) {\r\n throw new Error(`Referenced schema ${schemaKey.toString()} could not be found in target context`);\r\n }\r\n return schema;\r\n}\r\n\r\n/**\r\n * Compares the schemas and return them in order of their versions [older, latest].\r\n * @param left The first schema to be added.\r\n * @param right The second schema to be added.\r\n * @returns The schemas in order.\r\n */\r\nfunction compareSchemas(left: Schema, right: Schema): [Schema, Schema] {\r\n return left.schemaKey.compareByVersion(right.schemaKey) < 0\r\n ? [left, right]\r\n : [right, left];\r\n}\r\n"]}
1
+ {"version":3,"file":"SchemaReferenceMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAyF;AAKzF;;;;;GAKG;AACI,KAAK,UAAU,qBAAqB,CAAC,OAA2B,EAAE,MAAiC;IACxG,kFAAkF;IAClF,4FAA4F;IAC5F,IAAG,MAAM,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;QAC/B,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC/G,MAAM,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;IACrF,CAAC;IAED,iFAAiF;IACjF,qFAAqF;IACrF,qFAAqF;IACrF,8BAA8B;IAC9B,IAAG,MAAM,CAAC,UAAU,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,gBAAg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CAAC,CAAC;IACpE,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,6BAAS,CAAC,UAAU,EAAE,6BAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,mCAAe,CAAC,qBAAqB,CAAC,CAAC;IACtG,IAAG,MAAM,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,qBAAqB,SAAS,CAAC,QAAQ,EAAE,uCAAuC,CAAC,CAAC;IACpG,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC;QACf,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { ECVersion, Schema, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { type SchemaMergeContext } from \"./SchemaMerger\";\nimport { type SchemaReferenceDifference } from \"../Differencing/SchemaDifference\";\nimport { type SchemaContextEditor } from \"../Editing/Editor\";\n\n/**\n * Merges the schema references of two schemas.\n * @param context current merge context\n * @param change schema changes.\n * @internal\n */\nexport async function mergeSchemaReferences(context: SchemaMergeContext, change: SchemaReferenceDifference) {\n // If the target schema does not have a reference to a schema yet, it can be added\n // but should be checked if it's schema references have collisions with existing references.\n if(change.changeType === \"add\") {\n const referencedSchema = await locateSchema(context.editor, change.difference.name, change.difference.version);\n await context.editor.addSchemaReference(context.targetSchemaKey, referencedSchema);\n }\n\n // If the source schema referenced a schema that is also referenced by the target\n // schema but in a different version, it is marked as delta. Here we need to check if\n // the source schema is compatible to the existing one. This is not be checked by the\n // schema instance when added.\n if(change.changeType === \"modify\") {\n const referencedSchema = await locateSchema(context.editor, change.difference.name, change.difference.version);\n const existingSchema = (await context.targetSchema.getReference(referencedSchema.name))!;\n\n const [older, latest] = compareSchemas(existingSchema, referencedSchema);\n if(!latest.schemaKey.matches(older.schemaKey, SchemaMatchType.LatestWriteCompatible)) {\n throw new Error(`Schemas references of ${referencedSchema.name} have incompatible versions: ${older.schemaKey.version} and ${latest.schemaKey.version}`);\n }\n\n if(latest === existingSchema) {\n return;\n }\n\n const index = context.targetSchema.references.findIndex((reference) => reference === existingSchema);\n context.targetSchema.references.splice(index, 1);\n\n await context.editor.addSchemaReference(context.targetSchema.schemaKey, referencedSchema);\n }\n}\n\n/**\n * Tries to locate the Schema in the current Context\n * @param editor Current editor context.\n * @param schemaName The schema name to be looked up.\n * @param version The schemas version to beo looked up.\n * @returns The schema found in the context.\n */\nasync function locateSchema(editor: SchemaContextEditor, schemaName?: string, version?: string): Promise<Schema> {\n if(schemaName === undefined || version === undefined) {\n throw new Error(\"Schema name and version must not be undefined.\");\n }\n\n const schemaKey = new SchemaKey(schemaName, ECVersion.fromString(version));\n const schema = await editor.schemaContext.getSchema(schemaKey, SchemaMatchType.LatestWriteCompatible);\n if(schema === undefined) {\n throw new Error(`Referenced schema ${schemaKey.toString()} could not be found in target context`);\n }\n return schema;\n}\n\n/**\n * Compares the schemas and return them in order of their versions [older, latest].\n * @param left The first schema to be added.\n * @param right The second schema to be added.\n * @returns The schemas in order.\n */\nfunction compareSchemas(left: Schema, right: Schema): [Schema, Schema] {\n return left.schemaKey.compareByVersion(right.schemaKey) < 0\n ? [left, right]\n : [right, left];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"UnitSystemMerger.js","sourceRoot":"","sources":["../../../src/Merging/UnitSystemMerger.ts"],"names":[],"mappings":";;;AAQA;;;GAGG;AACU,QAAA,gBAAgB,GAAkD;IAC7E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM;QACvB,OAAO,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE;YACzE,GAAG,MAAM,CAAC,UAAU;YACpB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,cAAc,EAAE,MAAM,CAAC,UAAU;SAClC,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAuB;QAC9D,IAAG,MAAM,CAAC,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,IAAG,MAAM,CAAC,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF,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 { type MutableUnitSystem } from \"../Editing/Mutable/MutableUnitSystem\";\r\nimport { type SchemaItemMergerHandler } from \"./SchemaItemMerger\";\r\nimport { type UnitSystemDifference } from \"../Differencing/SchemaDifference\";\r\n\r\n/**\r\n * Defines a merge handler to merge UnitSystem schema items.\r\n * @internal\r\n */\r\nexport const unitSystemMerger: SchemaItemMergerHandler<UnitSystemDifference> = {\r\n async add(context, change) {\r\n return context.editor.unitSystems.createFromProps(context.targetSchemaKey, {\r\n ...change.difference,\r\n name: change.itemName,\r\n schemaItemType: change.schemaType,\r\n });\r\n },\r\n async modify(_context, change, _itemKey, item: MutableUnitSystem) {\r\n if(change.difference.label !== undefined) {\r\n item.setDisplayLabel(change.difference.label);\r\n }\r\n if(change.difference.description !== undefined) {\r\n item.setDescription(change.difference.description);\r\n }\r\n },\r\n};\r\n"]}
1
+ {"version":3,"file":"UnitSystemMerger.js","sourceRoot":"","sources":["../../../src/Merging/UnitSystemMerger.ts"],"names":[],"mappings":";;;AAQA;;;GAGG;AACU,QAAA,gBAAgB,GAAkD;IAC7E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM;QACvB,OAAO,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE;YACzE,GAAG,MAAM,CAAC,UAAU;YACpB,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,cAAc,EAAE,MAAM,CAAC,UAAU;SAClC,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAuB;QAC9D,IAAG,MAAM,CAAC,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QACD,IAAG,MAAM,CAAC,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { type MutableUnitSystem } from \"../Editing/Mutable/MutableUnitSystem\";\nimport { type SchemaItemMergerHandler } from \"./SchemaItemMerger\";\nimport { type UnitSystemDifference } from \"../Differencing/SchemaDifference\";\n\n/**\n * Defines a merge handler to merge UnitSystem schema items.\n * @internal\n */\nexport const unitSystemMerger: SchemaItemMergerHandler<UnitSystemDifference> = {\n async add(context, change) {\n return context.editor.unitSystems.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n });\n },\n async modify(_context, change, _itemKey, item: MutableUnitSystem) {\n if(change.difference.label !== undefined) {\n item.setDisplayLabel(change.difference.label);\n }\n if(change.difference.description !== undefined) {\n item.setDescription(change.difference.description);\n }\n },\n};\n"]}