@itwin/ecschema-editing 4.4.6 → 4.4.8

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 (72) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/lib/cjs/Editing/Constants.js.map +1 -1
  3. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  4. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  5. package/lib/cjs/Editing/Editor.js.map +1 -1
  6. package/lib/cjs/Editing/Entities.js.map +1 -1
  7. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  8. package/lib/cjs/Editing/Formats.js.map +1 -1
  9. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  10. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  11. package/lib/cjs/Editing/Mixins.js.map +1 -1
  12. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
  13. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  14. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  15. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  16. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  17. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  18. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  19. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  20. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  21. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  22. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  23. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
  24. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  25. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  26. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  27. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  28. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  29. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  30. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  31. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  32. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  33. package/lib/cjs/Editing/SchemaItems.js.map +1 -1
  34. package/lib/cjs/Editing/Structs.js.map +1 -1
  35. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  36. package/lib/cjs/Editing/Units.js.map +1 -1
  37. package/lib/cjs/Merging/AnyPropertyMerger.js.map +1 -1
  38. package/lib/cjs/Merging/ArrayPropertyMerger.js.map +1 -1
  39. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  40. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  41. package/lib/cjs/Merging/ClassPropertyMerger.js.map +1 -1
  42. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  43. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  44. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  45. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  46. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  47. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  48. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +1 -1
  49. package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
  50. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  51. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  52. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  53. package/lib/cjs/Merging/StructClassMerger.js.map +1 -1
  54. package/lib/cjs/Merging/StructPropertyMerger.js.map +1 -1
  55. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  56. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  57. package/lib/cjs/Validation/ECRules.js.map +1 -1
  58. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  59. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  60. package/lib/cjs/Validation/Rules.js.map +1 -1
  61. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  62. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  63. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  64. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  65. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  66. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  67. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  68. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  69. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  70. package/lib/cjs/ecschema-editing.js.map +1 -1
  71. package/package.json +9 -9
  72. package/public/locales/en/ECSchemaEditing.json +26 -26
@@ -1 +1 @@
1
- {"version":3,"file":"AnyPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/AnyPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA0I;AAK1I;;GAEG;AACH,MAAa,iBAAiB;IAG5B,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,SAAwB,EAAE,QAAmB;QACxE,OAAO,EAAE,YAAY,EAAE,iBAAiB,IAAA,wCAAoB,EAAC,QAAQ,CAAC,YAAY,CAAC,sBAAsB,EAAE,CAAC;IAC9G,CAAC;IAES,qBAAqB,CAAC,GAAQ;QACtC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,cAAc,IAAI,GAAG,CAAC;IAC1D,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,QAAmB;QAClD,IAAI,KAAK,GAAG,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AS,EAAE;gBAC3B,OAAO,EAAE,YAAY,EAAE,kDAAkD,SAAS,CAAC,IAAI,wBAAwB,EAAE,CAAC;aACnH;YACD,KAAK,GAAG,EAAC,GAAG,KAAK,EAAE,cAAc,EAAE,SAAS,CAAC,QAAQ,EAAC,CAAC;SACxD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,QAAmB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,kBAAuB;QACtH,MAAM,eAAe,GAAG,QAAsC,CAAC;QAC/D,QAAO,aAAa,EAAE;YACpB,KAAK,aAAa;gBAChB,eAAe,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;gBAClD,OAAO,IAAI,CAAC;YACd,KAAK,OAAO;gBACV,eAAe,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,KAAK,YAAY;gBACf,eAAe,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;gBACjD,OAAO,IAAI,CAAC;YACd,KAAK,UAAU;gBACb,eAAe,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,OAAO,IAAI,CAAC;YACd,KAAK,MAAM,CAAC;YACZ,KAAK,eAAe;gBAClB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,IAAI,KAAK,aAAa,oBAAoB,EAAE,CAAC;SAC1G;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAnED,8CAmEC","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 { KindOfQuantity, Property, PropertyCategory, PropertyProps, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { PropertyEditResults } from \"../Editing/Editor\";\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\n\n/**\n * @internal\n */\nexport class AnyPropertyMerger<TProperty extends Property> {\n protected readonly context: SchemaMergeContext;\n\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n public async createFromProps(_classKey: SchemaItemKey, property: TProperty): Promise<PropertyEditResults> {\n return { errorMessage: `Property Type ${propertyTypeToString(property.propertyType)} is not implemented.` };\n }\n\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\n return typeof obj === \"object\" && \"errorMessage\" in obj;\n }\n\n protected async getPropertyProps(property: TProperty): Promise<PropertyEditResults | PropertyProps> {\n let props = {} as PropertyProps;\n\n if (property.category !== undefined) {\n const sourceCategory = await property.category;\n const itemKey = new SchemaItemKey(sourceCategory.name, this.context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : sourceCategory.schema.schemaKey,\n );\n const targetCategory = await this.context.targetSchema.lookupItem<PropertyCategory>(itemKey);\n if (targetCategory === undefined) {\n return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the merged schema.` };\n }\n props = {...props, category: targetCategory.fullName};\n }\n\n if (property.kindOfQuantity !== undefined) {\n const sourceKoq = await property.kindOfQuantity;\n const itemKey = new SchemaItemKey(sourceKoq.name, this.context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : sourceKoq.schema.schemaKey,\n );\n const targetKoq = await this.context.targetSchema.lookupItem<KindOfQuantity>(itemKey);\n if (targetKoq === undefined) {\n return { errorMessage: `Unable to locate the property kind of quantity ${sourceKoq.name} in the merged schema.` };\n }\n props = {...props, kindOfQuantity: targetKoq.fullName};\n }\n return props;\n }\n\n public async mergeAttributes(property: TProperty, attributeName: string, attributeNewValue: any, _attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const mutableProperty = property as unknown as MutableProperty;\n switch(attributeName) {\n case \"description\":\n mutableProperty.setDescription(attributeNewValue);\n return true;\n case \"label\":\n mutableProperty.setLabel(attributeNewValue);\n return true;\n case \"isReadOnly\":\n mutableProperty.setIsReadOnly(attributeNewValue);\n return true;\n case \"priority\":\n mutableProperty.setPriority(attributeNewValue);\n return true;\n case \"type\":\n case \"primitiveType\":\n return { errorMessage: `Changing the property '${property.name}' ${attributeName} is not supported.` };\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"AnyPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/AnyPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA0I;AAK1I;;GAEG;AACH,MAAa,iBAAiB;IAG5B,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,SAAwB,EAAE,QAAmB;QACxE,OAAO,EAAE,YAAY,EAAE,iBAAiB,IAAA,wCAAoB,EAAC,QAAQ,CAAC,YAAY,CAAC,sBAAsB,EAAE,CAAC;IAC9G,CAAC;IAES,qBAAqB,CAAC,GAAQ;QACtC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,cAAc,IAAI,GAAG,CAAC;IAC1D,CAAC;IAES,KAAK,CAAC,gBAAgB,CAAC,QAAmB;QAClD,IAAI,KAAK,GAAG,EAAoB,CAAC;QAEjC,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS,EAAE;YACnC,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC;YAC/C,MAAM,OAAO,GAAG,IAAI,iCAAa,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC;gBACjI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;gBACrC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAClC,CAAC;YACF,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,OAAO,CA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d,KAAK,OAAO;gBACV,eAAe,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;gBAC5C,OAAO,IAAI,CAAC;YACd,KAAK,YAAY;gBACf,eAAe,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;gBACjD,OAAO,IAAI,CAAC;YACd,KAAK,UAAU;gBACb,eAAe,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,OAAO,IAAI,CAAC;YACd,KAAK,MAAM,CAAC;YACZ,KAAK,eAAe;gBAClB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,IAAI,KAAK,aAAa,oBAAoB,EAAE,CAAC;SAC1G;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAnED,8CAmEC","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 { KindOfQuantity, Property, PropertyCategory, PropertyProps, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class AnyPropertyMerger<TProperty extends Property> {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n public async createFromProps(_classKey: SchemaItemKey, property: TProperty): Promise<PropertyEditResults> {\r\n return { errorMessage: `Property Type ${propertyTypeToString(property.propertyType)} is not implemented.` };\r\n }\r\n\r\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n protected async getPropertyProps(property: TProperty): Promise<PropertyEditResults | PropertyProps> {\r\n let props = {} as PropertyProps;\r\n\r\n if (property.category !== undefined) {\r\n const sourceCategory = await property.category;\r\n const itemKey = new SchemaItemKey(sourceCategory.name, this.context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceCategory.schema.schemaKey,\r\n );\r\n const targetCategory = await this.context.targetSchema.lookupItem<PropertyCategory>(itemKey);\r\n if (targetCategory === undefined) {\r\n return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the merged schema.` };\r\n }\r\n props = {...props, category: targetCategory.fullName};\r\n }\r\n\r\n if (property.kindOfQuantity !== undefined) {\r\n const sourceKoq = await property.kindOfQuantity;\r\n const itemKey = new SchemaItemKey(sourceKoq.name, this.context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceKoq.schema.schemaKey,\r\n );\r\n const targetKoq = await this.context.targetSchema.lookupItem<KindOfQuantity>(itemKey);\r\n if (targetKoq === undefined) {\r\n return { errorMessage: `Unable to locate the property kind of quantity ${sourceKoq.name} in the merged schema.` };\r\n }\r\n props = {...props, kindOfQuantity: targetKoq.fullName};\r\n }\r\n return props;\r\n }\r\n\r\n public async mergeAttributes(property: TProperty, attributeName: string, attributeNewValue: any, _attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const mutableProperty = property as unknown as MutableProperty;\r\n switch(attributeName) {\r\n case \"description\":\r\n mutableProperty.setDescription(attributeNewValue);\r\n return true;\r\n case \"label\":\r\n mutableProperty.setLabel(attributeNewValue);\r\n return true;\r\n case \"isReadOnly\":\r\n mutableProperty.setIsReadOnly(attributeNewValue);\r\n return true;\r\n case \"priority\":\r\n mutableProperty.setPriority(attributeNewValue);\r\n return true;\r\n case \"type\":\r\n case \"primitiveType\":\r\n return { errorMessage: `Changing the property '${property.name}' ${attributeName} is not supported.` };\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ArrayPropertyMerger.js","sourceRoot":"","sources":["../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IACf,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,QAAuB,EAAE,QAAgC;QAC7F,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YAC7E,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,KAAK,GAAgC;YACzC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;SACX,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qCAAqC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACpI,CAAC;CACF;AA3BD,kEA2BC","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 { ArrayProperty, Enumeration, EnumerationArrayProperty, PrimitiveArrayProperty, SchemaItemKey, StructArrayProperty, StructArrayPropertyProps, StructClass } from \"@itwin/ecschema-metadata\";\nimport { PrimitiveArrayPropertyProps } from \"@itwin/ecschema-metadata/src/Deserialization/JsonProps\";\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\nimport { PropertyEditResults } from \"../Editing/Editor\";\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\n\n/**\n * @internal\n */\nclass ArrayPropertyMerger<TArrayProperty extends ArrayProperty> extends AnyPropertyMerger <TArrayProperty> {\n public override async mergeAttributes(property: TArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const mutableProperty = property as unknown as MutableArrayProperty;\n switch (attributeName) {\n case \"minOccurs\":\n mutableProperty.setMinOccurs(attributeNewValue);\n return true;\n\n case \"maxOccurs\":\n mutableProperty.setMaxOccurs(attributeNewValue);\n return true;\n\n }\n return false;\n }\n}\n\n/**\n * @internal\n */\nexport class StructArrayPropertyMerger extends ArrayPropertyMerger <StructArrayProperty> {\n public override async mergeAttributes(property: StructArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch (attributeName) {\n case \"structClass\": {\n if (attributeOldValue !== undefined) {\n return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };\n }\n return true;\n }\n }\n return false;\n }\n\n public override async createFromProps(classKey: SchemaItemKey, property: StructArrayProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const itemKey = new SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : property.structClass.schema.schemaKey,\n );\n const type = await this.context.targetSchema.lookupItem<StructClass>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };\n }\n\n const props: StructArrayPropertyProps = {\n ...property.toJSON(),\n ...results,\n typeName: type.fullName,\n };\n return this.context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, props);\n }\n}\n\n/**\n * @internal\n */\nexport class EnumerationArrayPropertyMerger extends ArrayPropertyMerger <EnumerationArrayProperty> {\n public override async mergeAttributes(property: EnumerationArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch (attributeName) {\n case \"enumeration\": {\n if (attributeOldValue !== undefined) {\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\n }\n return true;\n }\n }\n return false;\n }\n\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationArrayProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n if (property.enumeration === undefined) {\n return { errorMessage: `Property '${property.fullName}' is missing the required 'enumeration' attribute.` };\n }\n\n const enumeration = await property.enumeration;\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : enumeration.schema.schemaKey,\n );\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\n }\n\n const props: PrimitiveArrayPropertyProps = {\n ...property.toJSON(),\n ...results,\n };\n return this.context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, props);\n }\n}\n\n/**\n * @internal\n */\nexport class PrimitiveArraPropertyMerger extends ArrayPropertyMerger <PrimitiveArrayProperty> {\n public override async mergeAttributes(property: PrimitiveArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch (attributeName) {\n case \"primitiveType\": {\n return { errorMessage: `Changing the property '${property.name}' typeName is not supported.`};\n }\n }\n return false;\n }\n\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveArrayProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const props: PrimitiveArrayPropertyProps = {\n ...property.toJSON(),\n ...results,\n };\n return this.context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, props);\n }\n}\n"]}
1
+ {"version":3,"file":"ArrayPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ArrayPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAmM;AAEnM,2DAAwD;AAIxD;;GAEG;AACH,MAAM,mBAA2D,SAAQ,qCAAkC;IACzF,KAAK,CAAC,eAAe,CAAC,QAAwB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACnI,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACjG,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,eAAe,GAAG,QAA2C,CAAC;QACpE,QAAQ,aAAa,EAAE;YACrB,KAAK,WAAW;gBACd,eAAe,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;YAEd,KAAK,WAAW;gBACd,eAAe,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;SAEf;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;GAEG;AACH,MAAa,yBAA0B,SAAQ,mBAAyC;IACtE,KAAK,CAAC,eAAe,CAAC,QAA6B,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACxI,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,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C;SAChB;QAED,QAAQ,aAAa,EAAE;YACrB,KAAK,eAAe,CAAC,CAAC;gBACpB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,IAAI,8BAA8B,EAAC,CAAC;aAC/F;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,QAAuB,EAAE,QAAgC;QAC7F,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YAC7E,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,KAAK,GAAgC;YACzC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;SACX,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qCAAqC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IACpI,CAAC;CACF;AA3BD,kEA2BC","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 { ArrayProperty, Enumeration, EnumerationArrayProperty, PrimitiveArrayProperty, SchemaItemKey, StructArrayProperty, StructArrayPropertyProps, StructClass } from \"@itwin/ecschema-metadata\";\r\nimport { PrimitiveArrayPropertyProps } from \"@itwin/ecschema-metadata/src/Deserialization/JsonProps\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\r\n\r\n/**\r\n * @internal\r\n */\r\nclass ArrayPropertyMerger<TArrayProperty extends ArrayProperty> extends AnyPropertyMerger <TArrayProperty> {\r\n public override async mergeAttributes(property: TArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const mutableProperty = property as unknown as MutableArrayProperty;\r\n switch (attributeName) {\r\n case \"minOccurs\":\r\n mutableProperty.setMinOccurs(attributeNewValue);\r\n return true;\r\n\r\n case \"maxOccurs\":\r\n mutableProperty.setMaxOccurs(attributeNewValue);\r\n return true;\r\n\r\n }\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class StructArrayPropertyMerger extends ArrayPropertyMerger <StructArrayProperty> {\r\n public override async mergeAttributes(property: StructArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"structClass\": {\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: StructArrayProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const itemKey = new SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : property.structClass.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<StructClass>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };\r\n }\r\n\r\n const props: StructArrayPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n typeName: type.fullName,\r\n };\r\n return this.context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class EnumerationArrayPropertyMerger extends ArrayPropertyMerger <EnumerationArrayProperty> {\r\n public override async mergeAttributes(property: EnumerationArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"enumeration\": {\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationArrayProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n if (property.enumeration === undefined) {\r\n return { errorMessage: `Property '${property.fullName}' is missing the required 'enumeration' attribute.` };\r\n }\r\n\r\n const enumeration = await property.enumeration;\r\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : enumeration.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\r\n }\r\n\r\n const props: PrimitiveArrayPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n };\r\n return this.context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class PrimitiveArraPropertyMerger extends ArrayPropertyMerger <PrimitiveArrayProperty> {\r\n public override async mergeAttributes(property: PrimitiveArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"primitiveType\": {\r\n return { errorMessage: `Changing the property '${property.name}' typeName is not supported.`};\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveArrayProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const props: PrimitiveArrayPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n };\r\n return this.context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, props);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CAClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/CAClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAA8G;AAC9G,+CAA4C;AAI5C;;GAEG;AACH,MAAqB,aAAc,SAAQ,yBAAiC;IAEvD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAA6B;QACjF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACrG,CAAC;IAEkB,KAAK,CAAC,eAAe,CAAC,OAA6B,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QAC3I,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC1G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACnG,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,cAAc,GAAG,OAAoC,CAAC;QAC5D,QAAO,aAAa,EAAE;YACpB,KAAK,WAAW;gBACd,IAAI,iBAAiB,KAAK,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,EAAE;oBAC9E,MAAM,aAAa,GAAG,IAAA,qDAAiC,EAAC,GAAG,iBAAiB,KAAK,iBAAiB,EAAE,CAAC,CAAC;oBACtG,IAAI,aAAa,KAAK,SAAS,EAAE;wBAC/B,OAAO,EAAE,YAAY,EAAE,oEAAoE,EAAC,CAAC;qBAC9F;oBACD,cAAc,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;iBAChD;gBACD,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA1BD,gCA0BC","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 { CustomAttributeClass, parseCustomAttributeContainerType, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { ClassMerger } from \"./ClassMerger\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\nimport { MutableCAClass } from \"../Editing/Mutable/MutableCAClass\";\n\n/**\n * @internal\n */\nexport default class CAClassMerger extends ClassMerger<CustomAttributeClass> {\n\n protected override async create(schemaKey: SchemaKey, ecClass: CustomAttributeClass): Promise<SchemaItemEditResults> {\n return this.context.editor.customAttributes.create(schemaKey, ecClass.name, ecClass.containerType);\n }\n\n protected override async mergeAttributes(ecClass: CustomAttributeClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n const results = await super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const mutableCAClass = ecClass as unknown as MutableCAClass;\n switch(attributeName) {\n case \"appliesTo\":\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\n const containerType = parseCustomAttributeContainerType(`${attributeOldValue}, ${attributeNewValue}`);\n if (containerType === undefined) {\n return { errorMessage: \"An invalid custom attribute class containerType has been provided.\"};\n }\n mutableCAClass.setContainerType(containerType);\n }\n return true;\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"CAClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/CAClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAA8G;AAC9G,+CAA4C;AAI5C;;GAEG;AACH,MAAqB,aAAc,SAAQ,yBAAiC;IAEvD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAA6B;QACjF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACrG,CAAC;IAEkB,KAAK,CAAC,eAAe,CAAC,OAA6B,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QAC3I,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC1G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACnG,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,cAAc,GAAG,OAAoC,CAAC;QAC5D,QAAO,aAAa,EAAE;YACpB,KAAK,WAAW;gBACd,IAAI,iBAAiB,KAAK,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,EAAE;oBAC9E,MAAM,aAAa,GAAG,IAAA,qDAAiC,EAAC,GAAG,iBAAiB,KAAK,iBAAiB,EAAE,CAAC,CAAC;oBACtG,IAAI,aAAa,KAAK,SAAS,EAAE;wBAC/B,OAAO,EAAE,YAAY,EAAE,oEAAoE,EAAC,CAAC;qBAC9F;oBACD,cAAc,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;iBAChD;gBACD,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA1BD,gCA0BC","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 { CustomAttributeClass, parseCustomAttributeContainerType, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { ClassMerger } from \"./ClassMerger\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { MutableCAClass } from \"../Editing/Mutable/MutableCAClass\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class CAClassMerger extends ClassMerger<CustomAttributeClass> {\r\n\r\n protected override async create(schemaKey: SchemaKey, ecClass: CustomAttributeClass): Promise<SchemaItemEditResults> {\r\n return this.context.editor.customAttributes.create(schemaKey, ecClass.name, ecClass.containerType);\r\n }\r\n\r\n protected override async mergeAttributes(ecClass: CustomAttributeClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n const results = await super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const mutableCAClass = ecClass as unknown as MutableCAClass;\r\n switch(attributeName) {\r\n case \"appliesTo\":\r\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\r\n const containerType = parseCustomAttributeContainerType(`${attributeOldValue}, ${attributeNewValue}`);\r\n if (containerType === undefined) {\r\n return { errorMessage: \"An invalid custom attribute class containerType has been provided.\"};\r\n }\r\n mutableCAClass.setContainerType(containerType);\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiJ;AAIjJ,+DAAgI;AAChI,+DAA4D;AAC5D,mEAAgE;AAEhE;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,MAAM,CAAC,UAAqB,EAAE,OAAe;QAC3D,OAAO,EAAE,YAAY,EAAE,GAAG,IAAA,0CAAsB,EAAC,OAAO,CAAC,cAAc,CAAC,iCAAiC,EAAC,CAAC;IAC7G,CAAC;IAES,KAAK,CAAC,QAAQ,CAAC,OAAsB,EAAE,KAAY;QAC3D,OAAO,EAAE,YAAY,EAAE,iBAAiB,KAAK,CAAC,IAAI,SAAS,OAAO,CAAC,IAAI,6BAA6B,EAAE,CAAC;IACzG,CAAC;IAES,KAAK,CAAC,eAAe,CAAC,OAAe,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACpH,MAAM,YAAY,GAAG,OAAkC,CAAC;QACxD,QAAO,aAAa,EAAE;YACpB,KAAK,gBAAgB;gBACnB,IAAI,iBAAiB,KAAK,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,EAAE;oBAC9E,OAAO,EAAE,YAAY,EAAE,uBAAuB,OAAO,CAAC,IAAI,0BAA0B,EAAE,CAAC;iBACxF;gBACD,OAAO,IAAI,CAAC;YAEd,KAAK,OAAO;gBACV,YAAY,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;gBAChD,OAAO,IAAI,CAAC;YAEd,KAAK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,EAAE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;YACpH,IAAI,YAAY,CAAC,YAAY,KAAK,SAAS,EAAE;gBAC3C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aAC5C;YAED,0BAA0B;YAC1B,YAAY,GAAG,MAAM,IAAA,6CAAqB,EAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;gBAC9G,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;YAC9E,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,CAAC,YAAY,KAAK,SAAS,EAAE;gBAC3C,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;aAC5C;SACF;IACH,CAAC;CACF;AAnKD,kCAmKC","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 { ECClass, ECClassModifier, Mixin, parseClassModifier, SchemaItemKey, schemaItemTypeToString, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { BaseClassDelta, ChangeType, ClassChanges, EntityMixinChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\nimport { ClassPropertyMerger } from \"./ClassPropertyMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\n\n/**\n * @internal\n */\nexport class ClassMerger<TClass extends ECClass> {\n protected readonly context: SchemaMergeContext;\n\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n protected async create(_schemaKey: SchemaKey, ecClass: TClass): Promise<SchemaItemEditResults> {\n return { errorMessage: `${schemaItemTypeToString(ecClass.schemaItemType)} class type is not implemented.`};\n }\n\n protected async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\n return { errorMessage: `Adding mixin '${mixin.name}' to '${itemKey.name}' class is not implemented.` };\n }\n\n protected async mergeAttributes(ecClass: TClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n const mutableClass = ecClass as unknown as MutableClass;\n switch(attributeName) {\n case \"schemaItemType\":\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\n return { errorMessage: `Changing the class '${ecClass.name}' type is not supported.` };\n }\n return true;\n\n case \"label\":\n mutableClass.setDisplayLabel(attributeNewValue);\n return true;\n\n case \"description\":\n mutableClass.setDescription(attributeNewValue);\n return true;\n\n case \"modifier\":\n const modifier = parseClassModifier(attributeNewValue);\n if (modifier === undefined) {\n return { errorMessage: \"An invalid class modifier has been provided.\" };\n }\n\n if (attributeOldValue === undefined || modifier === ECClassModifier.None) {\n mutableClass.setModifier(modifier);\n return true;\n }\n return { errorMessage: `Changing the class '${ecClass.name}' modifier is not supported.` };\n }\n return false;\n }\n\n protected isSchemaItemEditResults(obj: any): obj is SchemaItemEditResults {\n return typeof obj === \"object\" && \"errorMessage\" in obj;\n }\n\n private async setBaseClass(itemKey: SchemaItemKey, baseClassDelta: BaseClassDelta, changeType?: ChangeType): Promise<SchemaItemEditResults> {\n const [sourceBaseClass, targetBaseClass] = baseClassDelta.diagnostic.messageArgs! as [ECClass, ECClass];\n if (sourceBaseClass !== undefined) {\n const baseClassKey = new SchemaItemKey(sourceBaseClass.name, sourceBaseClass.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : sourceBaseClass.schema.schemaKey);\n\n if (changeType === ChangeType.Missing && targetBaseClass === undefined) {\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\n }\n\n if (targetBaseClass !== undefined) {\n const baseClass = await this.context.targetSchema.lookupItem<ECClass>(baseClassKey);\n if (baseClass === undefined) {\n return { errorMessage: `'${baseClassKey.name}' class could not be located in the merged schema.`};\n }\n if (await baseClass.is(targetBaseClass)) {\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\n }\n }\n }\n return { errorMessage: `Changing the class '${itemKey.name}' baseClass is not supported.`};\n }\n\n private async addMixins(itemKey: SchemaItemKey, entityMixinChanges: Iterable<EntityMixinChanges>, changeType?: ChangeType): Promise<SchemaItemEditResults> {\n if (changeType === ChangeType.Missing) {\n for (const entityMixinChange of entityMixinChanges) {\n for (const change of entityMixinChange.entityMixinChange) {\n const mixins = change.diagnostic.messageArgs! as unknown as [Mixin];\n for (const mixin of mixins) {\n const result = await this.addMixin(itemKey, mixin);\n if (result.errorMessage !== undefined) {\n return result;\n }\n }\n }\n }\n return {};\n }\n return { errorMessage: `Changing the class '${itemKey.name}' mixins is not supported.`};\n }\n\n private async mergeAttributeValueChanges(itemKey: SchemaItemKey, propertyValueChanges: PropertyValueChange[]) {\n if (propertyValueChanges.length === 0) {\n return;\n }\n\n const targetItem = await this.context.targetSchema.lookupItem<TClass>(itemKey);\n if (targetItem === undefined) {\n throw new Error(`'${itemKey.name}' class could not be located in the merged schema.`);\n }\n\n for (const change of propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\n const results = await this.mergeAttributes(targetItem, attributeName, attributeNewValue, attributeOldValue);\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n }\n\n public static async mergeChanges(context: SchemaMergeContext, classChanges: Iterable<ClassChanges>) {\n const merger = new this(context);\n\n for (const change of classChanges) {\n const sourceItem = (await change.schema.getItem<ECClass>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n const changeType = change.schemaItemMissing?.changeType;\n\n if (changeType === ChangeType.Missing) {\n\n if (await context.targetSchema.lookupItem<ECClass>(targetItemKey) !== undefined) {\n throw new Error(`Merged schema already contains a class '${change.ecTypeName}'.`);\n }\n\n const results = await merger.create(context.targetSchema.schemaKey, sourceItem);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n targetItemKey = results.itemKey!;\n }\n\n if (change.baseClassDelta !== undefined) {\n const results = await merger.setBaseClass(targetItemKey, change.baseClassDelta, changeType);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n\n if (change.entityMixinChanges.size > 0) {\n const results = await merger.addMixins(targetItemKey, change.entityMixinChanges.values(), changeType);\n if (results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n\n await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);\n let mergeResults = await ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());\n if (mergeResults.errorMessage !== undefined) {\n throw new Error(mergeResults.errorMessage);\n }\n\n // merge custom attributes\n mergeResults = await mergeCustomAttributes(merger.context, change.customAttributeChanges.values(), async (ca) => {\n return merger.context.editor.entities.addCustomAttribute(targetItemKey, ca);\n });\n\n if (mergeResults.errorMessage !== undefined) {\n throw new Error(mergeResults.errorMessage);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"ClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAiJ;AAIjJ,+DAAgI;AAChI,+DAA4D;AAC5D,mEAAgE;AAEhE;;GAEG;AACH,MAAa,WAAW;IAGtB,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,MAAM,CAAC,UAAqB,EAAE,OAAe;QAC3D,OAAO,EAAE,YAAY,EAAE,GAAG,IAAA,0CAAsB,EAAC,OAAO,CAAC,cAAc,CAAC,iCAAiC,EAAC,CAAC;IAC7G,CAAC;IAES,KA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------------------------------------------------------------------------------------\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 { ECClass, ECClassModifier, Mixin, parseClassModifier, SchemaItemKey, schemaItemTypeToString, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { MutableClass } from \"../Editing/Mutable/MutableClass\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { BaseClassDelta, ChangeType, ClassChanges, EntityMixinChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\r\nimport { ClassPropertyMerger } from \"./ClassPropertyMerger\";\r\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ClassMerger<TClass extends ECClass> {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n protected async create(_schemaKey: SchemaKey, ecClass: TClass): Promise<SchemaItemEditResults> {\r\n return { errorMessage: `${schemaItemTypeToString(ecClass.schemaItemType)} class type is not implemented.`};\r\n }\r\n\r\n protected async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\r\n return { errorMessage: `Adding mixin '${mixin.name}' to '${itemKey.name}' class is not implemented.` };\r\n }\r\n\r\n protected async mergeAttributes(ecClass: TClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n const mutableClass = ecClass as unknown as MutableClass;\r\n switch(attributeName) {\r\n case \"schemaItemType\":\r\n if (attributeOldValue !== undefined && attributeOldValue !== attributeNewValue) {\r\n return { errorMessage: `Changing the class '${ecClass.name}' type is not supported.` };\r\n }\r\n return true;\r\n\r\n case \"label\":\r\n mutableClass.setDisplayLabel(attributeNewValue);\r\n return true;\r\n\r\n case \"description\":\r\n mutableClass.setDescription(attributeNewValue);\r\n return true;\r\n\r\n case \"modifier\":\r\n const modifier = parseClassModifier(attributeNewValue);\r\n if (modifier === undefined) {\r\n return { errorMessage: \"An invalid class modifier has been provided.\" };\r\n }\r\n\r\n if (attributeOldValue === undefined || modifier === ECClassModifier.None) {\r\n mutableClass.setModifier(modifier);\r\n return true;\r\n }\r\n return { errorMessage: `Changing the class '${ecClass.name}' modifier is not supported.` };\r\n }\r\n return false;\r\n }\r\n\r\n protected isSchemaItemEditResults(obj: any): obj is SchemaItemEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n private async setBaseClass(itemKey: SchemaItemKey, baseClassDelta: BaseClassDelta, changeType?: ChangeType): Promise<SchemaItemEditResults> {\r\n const [sourceBaseClass, targetBaseClass] = baseClassDelta.diagnostic.messageArgs! as [ECClass, ECClass];\r\n if (sourceBaseClass !== undefined) {\r\n const baseClassKey = new SchemaItemKey(sourceBaseClass.name, sourceBaseClass.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : sourceBaseClass.schema.schemaKey);\r\n\r\n if (changeType === ChangeType.Missing && targetBaseClass === undefined) {\r\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\r\n }\r\n\r\n if (targetBaseClass !== undefined) {\r\n const baseClass = await this.context.targetSchema.lookupItem<ECClass>(baseClassKey);\r\n if (baseClass === undefined) {\r\n return { errorMessage: `'${baseClassKey.name}' class could not be located in the merged schema.`};\r\n }\r\n if (await baseClass.is(targetBaseClass)) {\r\n return this.context.editor.entities.setBaseClass(itemKey, baseClassKey);\r\n }\r\n }\r\n }\r\n return { errorMessage: `Changing the class '${itemKey.name}' baseClass is not supported.`};\r\n }\r\n\r\n private async addMixins(itemKey: SchemaItemKey, entityMixinChanges: Iterable<EntityMixinChanges>, changeType?: ChangeType): Promise<SchemaItemEditResults> {\r\n if (changeType === ChangeType.Missing) {\r\n for (const entityMixinChange of entityMixinChanges) {\r\n for (const change of entityMixinChange.entityMixinChange) {\r\n const mixins = change.diagnostic.messageArgs! as unknown as [Mixin];\r\n for (const mixin of mixins) {\r\n const result = await this.addMixin(itemKey, mixin);\r\n if (result.errorMessage !== undefined) {\r\n return result;\r\n }\r\n }\r\n }\r\n }\r\n return {};\r\n }\r\n return { errorMessage: `Changing the class '${itemKey.name}' mixins is not supported.`};\r\n }\r\n\r\n private async mergeAttributeValueChanges(itemKey: SchemaItemKey, propertyValueChanges: PropertyValueChange[]) {\r\n if (propertyValueChanges.length === 0) {\r\n return;\r\n }\r\n\r\n const targetItem = await this.context.targetSchema.lookupItem<TClass>(itemKey);\r\n if (targetItem === undefined) {\r\n throw new Error(`'${itemKey.name}' class could not be located in the merged schema.`);\r\n }\r\n\r\n for (const change of propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\r\n const results = await this.mergeAttributes(targetItem, attributeName, attributeNewValue, attributeOldValue);\r\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n }\r\n\r\n public static async mergeChanges(context: SchemaMergeContext, classChanges: Iterable<ClassChanges>) {\r\n const merger = new this(context);\r\n\r\n for (const change of classChanges) {\r\n const sourceItem = (await change.schema.getItem<ECClass>(change.ecTypeName))!;\r\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\r\n const changeType = change.schemaItemMissing?.changeType;\r\n\r\n if (changeType === ChangeType.Missing) {\r\n\r\n if (await context.targetSchema.lookupItem<ECClass>(targetItemKey) !== undefined) {\r\n throw new Error(`Merged schema already contains a class '${change.ecTypeName}'.`);\r\n }\r\n\r\n const results = await merger.create(context.targetSchema.schemaKey, sourceItem);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n targetItemKey = results.itemKey!;\r\n }\r\n\r\n if (change.baseClassDelta !== undefined) {\r\n const results = await merger.setBaseClass(targetItemKey, change.baseClassDelta, changeType);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n\r\n if (change.entityMixinChanges.size > 0) {\r\n const results = await merger.addMixins(targetItemKey, change.entityMixinChanges.values(), changeType);\r\n if (results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n\r\n await merger.mergeAttributeValueChanges(targetItemKey, change.propertyValueChanges);\r\n let mergeResults = await ClassPropertyMerger.mergeChanges(context, targetItemKey, change.propertyChanges.values());\r\n if (mergeResults.errorMessage !== undefined) {\r\n throw new Error(mergeResults.errorMessage);\r\n }\r\n\r\n // merge custom attributes\r\n mergeResults = await mergeCustomAttributes(merger.context, change.customAttributeChanges.values(), async (ca) => {\r\n return merger.context.editor.entities.addCustomAttribute(targetItemKey, ca);\r\n });\r\n\r\n if (mergeResults.errorMessage !== undefined) {\r\n throw new Error(mergeResults.errorMessage);\r\n }\r\n }\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ClassPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAkG;AAElG,+DAA+F;AAE/F,iEAA8D;AAC9D,+DAA+H;AAE/H,mFAAqG;AACrG,mEAAgE;AAEhE;;GAEG;AACH,MAAa,mBAAmB;IAG9B,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEO,iBAAiB,CAAC,QAAkB;QAC1C,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE;YAC5B,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,oDAA8B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACzD;YACD,OAAO,IAAI,yDAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpD;QACD,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE;YAC1B,IAAI,QAAQ,CAA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AAqB,EAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,sBAAsB,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;gBACpH,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,4BAA4B,CAAC,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;YACtG,CAAC,CAAC,CAAC;YAEH,IAAI,YAAY,CAAC,YAAY,KAAK,SAAS,EAAE;gBAC3C,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,YAAY,EAAC,CAAC;aACnD;SACF;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AAnFD,kDAmFC","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 { ECClass, Property, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { PropertyEditResults, SchemaItemEditResults } from \"../Editing/Editor\";\nimport { ChangeType, PropertyChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { StructPropertyMerger } from \"./StructPropertyMerger\";\nimport { EnumerationArrayPropertyMerger, PrimitiveArraPropertyMerger, StructArrayPropertyMerger } from \"./ArrayPropertyMerger\";\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\nimport { EnumerationPropertyMerger, PrimitivePropertyMerger } from \"./PrimitiveOrEnumPropertyMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\n\n/**\n * @internal\n */\nexport class ClassPropertyMerger {\n protected readonly context: SchemaMergeContext;\n\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n private getPropertyMerger(property: Property): AnyPropertyMerger<Property> {\n if (property.isEnumeration()) {\n if (property.isArray()) {\n return new EnumerationArrayPropertyMerger(this.context);\n }\n return new EnumerationPropertyMerger(this.context);\n }\n if (property.isPrimitive()) {\n if (property.isArray()) {\n return new PrimitiveArraPropertyMerger(this.context);\n }\n return new PrimitivePropertyMerger(this.context);\n }\n if (property.isStruct()) {\n if (property.isArray()) {\n return new StructArrayPropertyMerger(this.context);\n }\n return new StructPropertyMerger(this.context);\n }\n throw new Error(`Unsupported Property Type: ${propertyTypeToString(property.propertyType)}`);\n }\n\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\n return typeof obj === \"object\" && \"errorMessage\" in obj;\n }\n\n private async mergeAttributeValueChanges(targetProperty: Property, propertyValueChanges: PropertyValueChange[]) {\n if (propertyValueChanges.length === 0)\n return;\n\n const merger = this.getPropertyMerger(targetProperty);\n\n for (const change of propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\n const results = await merger.mergeAttributes(targetProperty, attributeName, attributeNewValue, attributeOldValue);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n throw new Error(results.errorMessage);\n }\n }\n }\n\n public static async mergeChanges(context: SchemaMergeContext, classKey: SchemaItemKey, propertyChanges: Iterable<PropertyChanges>): Promise<SchemaItemEditResults> {\n const merger = new this(context);\n\n for (const change of propertyChanges) {\n const targetItem = await context.targetSchema.lookupItem<ECClass>(classKey);\n if (targetItem === undefined) {\n return { errorMessage: `'${classKey.name}' class could not be located in the merged schema.`};\n }\n\n if (change.propertyMissing?.changeType === ChangeType.Missing) {\n const sourceProperty = change.propertyMissing.diagnostic.ecDefinition as unknown as Property;\n if (await targetItem.getProperty(change.ecTypeName) !== undefined) {\n return { errorMessage: `Merged schema already contains a class '${classKey.name}' property '${change.ecTypeName}'.`};\n }\n\n const propertyMerger = merger.getPropertyMerger(sourceProperty);\n const results = await propertyMerger.createFromProps(classKey, sourceProperty);\n if (results.errorMessage !== undefined) {\n return { errorMessage: results.errorMessage};\n }\n } else {\n const targetProperty = (await targetItem.getProperty(change.ecTypeName))!;\n await merger.mergeAttributeValueChanges(targetProperty, change.propertyValueChanges);\n }\n\n const mergeResults = await mergeCustomAttributes(merger.context, change.customAttributeChanges.values(), async (ca) => {\n return merger.context.editor.entities.addCustomAttributeToProperty(classKey, change.ecTypeName, ca);\n });\n\n if (mergeResults.errorMessage !== undefined) {\n return { errorMessage: mergeResults.errorMessage};\n }\n }\n return { itemKey: classKey };\n }\n}\n"]}
1
+ {"version":3,"file":"ClassPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/ClassPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAkG;AAElG,+DAA+F;AAE/F,iEAA8D;AAC9D,+DAA+H;AAE/H,mFAAqG;AACrG,mEAAgE;AAEhE;;GAEG;AACH,MAAa,mBAAmB;IAG9B,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAEO,iBAAiB,CAAC,QAAkB;QAC1C,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE;YAC5B,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,oDAA8B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACzD;YACD,OAAO,IAAI,yDAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACpD;QACD,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE;YAC1B,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,iDAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACtD;YACD,OAAO,IAAI,uDAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAClD;QACD,IAAI,QAAQ,CAAC,QAAQ,EAAE,EAAE;YACvB,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;gBACtB,OAAO,IAAI,+CAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACpD;YACD,OAAO,IAAI,2CAAoB,CA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EAAE,YAAY,CAAC,YAAY,EAAC,CAAC;aACnD;SACF;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AAnFD,kDAmFC","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 { ECClass, Property, propertyTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { ChangeType, PropertyChanges, PropertyValueChange } from \"../Validation/SchemaChanges\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { StructPropertyMerger } from \"./StructPropertyMerger\";\r\nimport { EnumerationArrayPropertyMerger, PrimitiveArraPropertyMerger, StructArrayPropertyMerger } from \"./ArrayPropertyMerger\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { EnumerationPropertyMerger, PrimitivePropertyMerger } from \"./PrimitiveOrEnumPropertyMerger\";\r\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class ClassPropertyMerger {\r\n protected readonly context: SchemaMergeContext;\r\n\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n private getPropertyMerger(property: Property): AnyPropertyMerger<Property> {\r\n if (property.isEnumeration()) {\r\n if (property.isArray()) {\r\n return new EnumerationArrayPropertyMerger(this.context);\r\n }\r\n return new EnumerationPropertyMerger(this.context);\r\n }\r\n if (property.isPrimitive()) {\r\n if (property.isArray()) {\r\n return new PrimitiveArraPropertyMerger(this.context);\r\n }\r\n return new PrimitivePropertyMerger(this.context);\r\n }\r\n if (property.isStruct()) {\r\n if (property.isArray()) {\r\n return new StructArrayPropertyMerger(this.context);\r\n }\r\n return new StructPropertyMerger(this.context);\r\n }\r\n throw new Error(`Unsupported Property Type: ${propertyTypeToString(property.propertyType)}`);\r\n }\r\n\r\n protected isPropertyEditResults(obj: any): obj is PropertyEditResults {\r\n return typeof obj === \"object\" && \"errorMessage\" in obj;\r\n }\r\n\r\n private async mergeAttributeValueChanges(targetProperty: Property, propertyValueChanges: PropertyValueChange[]) {\r\n if (propertyValueChanges.length === 0)\r\n return;\r\n\r\n const merger = this.getPropertyMerger(targetProperty);\r\n\r\n for (const change of propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\r\n const results = await merger.mergeAttributes(targetProperty, attributeName, attributeNewValue, attributeOldValue);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n throw new Error(results.errorMessage);\r\n }\r\n }\r\n }\r\n\r\n public static async mergeChanges(context: SchemaMergeContext, classKey: SchemaItemKey, propertyChanges: Iterable<PropertyChanges>): Promise<SchemaItemEditResults> {\r\n const merger = new this(context);\r\n\r\n for (const change of propertyChanges) {\r\n const targetItem = await context.targetSchema.lookupItem<ECClass>(classKey);\r\n if (targetItem === undefined) {\r\n return { errorMessage: `'${classKey.name}' class could not be located in the merged schema.`};\r\n }\r\n\r\n if (change.propertyMissing?.changeType === ChangeType.Missing) {\r\n const sourceProperty = change.propertyMissing.diagnostic.ecDefinition as unknown as Property;\r\n if (await targetItem.getProperty(change.ecTypeName) !== undefined) {\r\n return { errorMessage: `Merged schema already contains a class '${classKey.name}' property '${change.ecTypeName}'.`};\r\n }\r\n\r\n const propertyMerger = merger.getPropertyMerger(sourceProperty);\r\n const results = await propertyMerger.createFromProps(classKey, sourceProperty);\r\n if (results.errorMessage !== undefined) {\r\n return { errorMessage: results.errorMessage};\r\n }\r\n } else {\r\n const targetProperty = (await targetItem.getProperty(change.ecTypeName))!;\r\n await merger.mergeAttributeValueChanges(targetProperty, change.propertyValueChanges);\r\n }\r\n\r\n const mergeResults = await mergeCustomAttributes(merger.context, change.customAttributeChanges.values(), async (ca) => {\r\n return merger.context.editor.entities.addCustomAttributeToProperty(classKey, change.ecTypeName, ca);\r\n });\r\n\r\n if (mergeResults.errorMessage !== undefined) {\r\n return { errorMessage: mergeResults.errorMessage};\r\n }\r\n }\r\n return { itemKey: classKey };\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConstantMerger.js","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":";;AAAA,kGAAkG;AAClG,sEAAsE;AACtE,oFAAoF;AACpF,kGAAkG;AAClG,gEAAgE;AAChE,yDAA6E;AAE7E;;GAEG;AACH,MAAqB,eAAgB,SAAQ,mCAA0B;IACrE;;OAEG;IACgB,KAAK,CAAC,2BAA2B;QAClD,OAAO;YACL,UAAU,EAAE,CAAC,kBAAkB,EAAE,aAAa,EAAE,EAAE;gBAChD,2EAA2E;gBAC3E,2EAA2E;gBAC3E,+EAA+E;gBAC/E,iEAAiE;gBACjE,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,8BAAU,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAClF,IAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;oBACvE,OAAO,GAAG,aAAa,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;iBACxD;gBACD,OAAO,kBAAkB,CAAC;YAC5B,CAAC;YACD,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAW,aAAa,CAAC,CAAC;gBAC/E,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE;oBACtE,MAAM,IAAI,KAAK,CAAC,kDAAkD,KAAK,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;iBACjG;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,WAAW,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBACpC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAW,aAAa,CAAC,CAAC;gBAC/E,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,KAAK,KAAK,EAAE;oBAC1E,MAAM,IAAI,KAAK,CAAC,oDAAoD,KAAK,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;iBACrG;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAjCD,kCAiCC","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 { Constant, SchemaItem } from \"@itwin/ecschema-metadata\";\nimport { PropertyValueResolver, SchemaItemMerger } from \"./SchemaItemMerger\";\n\n/**\n * @internal\n */\nexport default class ConstantsMerger extends SchemaItemMerger<Constant> {\n /**\n * Creates the property value resolver for [[Constant]] items.\n */\n protected override async createPropertyValueResolver(): Promise<PropertyValueResolver<Constant>> {\n return {\n phenomenon: (phenomenonFullName, targetItemKey) => {\n // There are two options, either the phenomenon was referenced from another\n // schema or it is defined in the same schema as the constant to be merged.\n // In the latter case, the changes would report a different property value that\n // refers to the source schema. So that needs to be changed here.\n const [schemaName, phenomenonName] = SchemaItem.parseFullName(phenomenonFullName);\n if(this.context.targetSchema.getReferenceSync(schemaName) === undefined) {\n return `${targetItemKey.schemaName}.${phenomenonName}`;\n }\n return phenomenonFullName;\n },\n numerator: (value, targetItemKey) => {\n const item = this.context.targetSchema.lookupItemSync<Constant>(targetItemKey);\n if(item !== undefined && item.hasNumerator && item.numerator !== value) {\n throw new Error(`Failed to merged, constant numerator conflict: ${value} -> ${item.numerator}`);\n }\n return value;\n },\n denominator: (value, targetItemKey) => {\n const item = this.context.targetSchema.lookupItemSync<Constant>(targetItemKey);\n if(item !== undefined && item.hasDenominator && item.denominator !== value) {\n throw new Error(`Failed to merged, constant denominator conflict: ${value} -> ${item.denominator}`);\n }\n return value;\n },\n };\n }\n}\n\n"]}
1
+ {"version":3,"file":"ConstantMerger.js","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":";;AAAA,kGAAkG;AAClG,sEAAsE;AACtE,oFAAoF;AACpF,kGAAkG;AAClG,gEAAgE;AAChE,yDAA6E;AAE7E;;GAEG;AACH,MAAqB,eAAgB,SAAQ,mCAA0B;IACrE;;OAEG;IACgB,KAAK,CAAC,2BAA2B;QAClD,OAAO;YACL,UAAU,EAAE,CAAC,kBAAkB,EAAE,aAAa,EAAE,EAAE;gBAChD,2EAA2E;gBAC3E,2EAA2E;gBAC3E,+EAA+E;gBAC/E,iEAAiE;gBACjE,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,GAAG,8BAAU,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;gBAClF,IAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;oBACvE,OAAO,GAAG,aAAa,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;iBACxD;gBACD,OAAO,kBAAkB,CAAC;YAC5B,CAAC;YACD,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAW,aAAa,CAAC,CAAC;gBAC/E,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE;oBACtE,MAAM,IAAI,KAAK,CAAC,kDAAkD,KAAK,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;iBACjG;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;YACD,WAAW,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE;gBACpC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAW,aAAa,CAAC,CAAC;gBAC/E,IAAG,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,WAAW,KAAK,KAAK,EAAE;oBAC1E,MAAM,IAAI,KAAK,CAAC,oDAAoD,KAAK,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;iBACrG;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAjCD,kCAiCC","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 { Constant, SchemaItem } from \"@itwin/ecschema-metadata\";\r\nimport { PropertyValueResolver, SchemaItemMerger } from \"./SchemaItemMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class ConstantsMerger extends SchemaItemMerger<Constant> {\r\n /**\r\n * Creates the property value resolver for [[Constant]] items.\r\n */\r\n protected override async createPropertyValueResolver(): Promise<PropertyValueResolver<Constant>> {\r\n return {\r\n phenomenon: (phenomenonFullName, targetItemKey) => {\r\n // There are two options, either the phenomenon was referenced from another\r\n // schema or it is defined in the same schema as the constant to be merged.\r\n // In the latter case, the changes would report a different property value that\r\n // refers to the source schema. So that needs to be changed here.\r\n const [schemaName, phenomenonName] = SchemaItem.parseFullName(phenomenonFullName);\r\n if(this.context.targetSchema.getReferenceSync(schemaName) === undefined) {\r\n return `${targetItemKey.schemaName}.${phenomenonName}`;\r\n }\r\n return phenomenonFullName;\r\n },\r\n numerator: (value, targetItemKey) => {\r\n const item = this.context.targetSchema.lookupItemSync<Constant>(targetItemKey);\r\n if(item !== undefined && item.hasNumerator && item.numerator !== value) {\r\n throw new Error(`Failed to merged, constant numerator conflict: ${value} -> ${item.numerator}`);\r\n }\r\n return value;\r\n },\r\n denominator: (value, targetItemKey) => {\r\n const item = this.context.targetSchema.lookupItemSync<Constant>(targetItemKey);\r\n if(item !== undefined && item.hasDenominator && item.denominator !== value) {\r\n throw new Error(`Failed to merged, constant denominator conflict: ${value} -> ${item.denominator}`);\r\n }\r\n return value;\r\n },\r\n };\r\n }\r\n}\r\n\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CustomAttributeMerger.js","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAuH;AACvH,+DAA0F;AAO1F;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAkD,EAAE,QAAoE;IACpM,KAAK,MAAM,8BAA8B,IAAI,OAAO,EAAE;QACpD,KAAK,MAAM,MAAM,IAAI,8BAA8B,CAAC,sBAAsB,EAAE;YAC1E,IAAI,MAAM,CAAC,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAC5C,MAAM,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAgC,CAAC;gBACnF,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAI,8BAAU,CAAC,aAAa,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;gBAC1F,MAAM,aAAa,GAAG,IAAI,iCAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC;oBAC7G,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS;oBACrC,CAAC,CAAC,IAAI,6BAAS,CAAC,UAAU,CAAC,CAC5B,CAAC;gBACF,MAAM,qBAAqB,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,UAAU,CAAuB,aAAa,CAAC,CAAC;gBAC9G,IAAI,qBAAqB,KAAK,SAAS,EAAE;oBACvC,OAAO,EAAE,YAAY,EAAE,+CAA+C,aAAa,CAAC,IAAI,wBAAwB,EAAC,CAAC;iBACnH;gBAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC;oBAC7B,GAAG,qBAAqB;oBACxB,SAAS,EAAE,qBAAqB,CAAC,QAAQ;iBAC1C,CAAC,CAAC;gBAEH,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,OAAO,EAAG,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;iBAChD;aACF;iBAAM;gBACL,OAAO,EAAE,YAAY,EAAE,+BAA+B,8BAA8B,CAAC,UAAU,OAAO,YAAY,CAAC,YAAY,CAAC,IAAI,4BAA4B,EAAC,CAAC;aACnK;SACF;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AA7BD,sDA6BC","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 { CustomAttribute, CustomAttributeClass, SchemaItem, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { ChangeType, CustomAttributeContainerChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\ninterface EditResults {\n errorMessage?: string;\n}\n\n/**\n * Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass\n * a scope (Class, Property, Schema) specific handler.\n * @param mergeContext The current schema merging context.\n * @param changes An iterable with custom attribute changes.\n * @param callback The callback to add the custom attribute with a scope specific editor.\n * @returns A EditResults object.\n * @internal\n */\nexport async function mergeCustomAttributes(mergeContext: SchemaMergeContext, changes: Iterable<CustomAttributeContainerChanges>, callback: (customAttribute: CustomAttribute) => Promise<EditResults>): Promise<EditResults> {\n for (const customAttributeContainerChange of changes) {\n for (const change of customAttributeContainerChange.customAttributeChanges) {\n if (change.changeType === ChangeType.Missing) {\n const [sourceCustomAttribute] = change.diagnostic.messageArgs as [CustomAttribute];\n const [schemaName, itemName] = SchemaItem.parseFullName(sourceCustomAttribute.className);\n const schemaItemKey = new SchemaItemKey(itemName, mergeContext.sourceSchema.schemaKey.compareByName(schemaName)\n ? mergeContext.targetSchema.schemaKey\n : new SchemaKey(schemaName),\n );\n const targetCustomAttribute = await mergeContext.targetSchema.lookupItem<CustomAttributeClass>(schemaItemKey);\n if (targetCustomAttribute === undefined) {\n return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.`};\n }\n\n const results = await callback({\n ...sourceCustomAttribute,\n className: targetCustomAttribute.fullName,\n });\n\n if (results.errorMessage !== undefined) {\n return { errorMessage: results.errorMessage };\n }\n } else {\n return { errorMessage: `Changes of Custom Attribute ${customAttributeContainerChange.ecTypeName} on ${mergeContext.targetSchema.name} merge is not implemented.`};\n }\n }\n }\n return {};\n}\n"]}
1
+ {"version":3,"file":"CustomAttributeMerger.js","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAuH;AACvH,+DAA0F;AAO1F;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAkD,EAAE,QAAoE;IACpM,KAAK,MAAM,8BAA8B,IAAI,OAAO,EAAE;QACpD,KAAK,MAAM,MAAM,IAAI,8BAA8B,CAAC,sBAAsB,EAAE;YAC1E,IAAI,MAAM,CAAC,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAC5C,MAAM,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAgC,CAAC;gBACnF,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAI,8BAAU,CAAC,aAAa,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;gBAC1F,MAAM,aAAa,GAAG,IAAI,iCAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,UAAU,CAAC;oBAC7G,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS;oBACrC,CAAC,CAAC,IAAI,6BAAS,CAAC,UAAU,CAAC,CAC5B,CAAC;gBACF,MAAM,qBAAqB,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,UAAU,CAAuB,aAAa,CAAC,CAAC;gBAC9G,IAAI,qBAAqB,KAAK,SAAS,EAAE;oBACvC,OAAO,EAAE,YAAY,EAAE,+CAA+C,aAAa,CAAC,IAAI,wBAAwB,EAAC,CAAC;iBACnH;gBAED,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC;oBAC7B,GAAG,qBAAqB;oBACxB,SAAS,EAAE,qBAAqB,CAAC,QAAQ;iBAC1C,CAAC,CAAC;gBAEH,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;oBACtC,OAAO,EAAG,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;iBAChD;aACF;iBAAM;gBACL,OAAO,EAAE,YAAY,EAAE,+BAA+B,8BAA8B,CAAC,UAAU,OAAO,YAAY,CAAC,YAAY,CAAC,IAAI,4BAA4B,EAAC,CAAC;aACnK;SACF;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AA7BD,sDA6BC","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 { CustomAttribute, CustomAttributeClass, SchemaItem, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, CustomAttributeContainerChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\ninterface EditResults {\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass\r\n * a scope (Class, Property, Schema) specific handler.\r\n * @param mergeContext The current schema merging context.\r\n * @param changes An iterable with custom attribute changes.\r\n * @param callback The callback to add the custom attribute with a scope specific editor.\r\n * @returns A EditResults object.\r\n * @internal\r\n */\r\nexport async function mergeCustomAttributes(mergeContext: SchemaMergeContext, changes: Iterable<CustomAttributeContainerChanges>, callback: (customAttribute: CustomAttribute) => Promise<EditResults>): Promise<EditResults> {\r\n for (const customAttributeContainerChange of changes) {\r\n for (const change of customAttributeContainerChange.customAttributeChanges) {\r\n if (change.changeType === ChangeType.Missing) {\r\n const [sourceCustomAttribute] = change.diagnostic.messageArgs as [CustomAttribute];\r\n const [schemaName, itemName] = SchemaItem.parseFullName(sourceCustomAttribute.className);\r\n const schemaItemKey = new SchemaItemKey(itemName, mergeContext.sourceSchema.schemaKey.compareByName(schemaName)\r\n ? mergeContext.targetSchema.schemaKey\r\n : new SchemaKey(schemaName),\r\n );\r\n const targetCustomAttribute = await mergeContext.targetSchema.lookupItem<CustomAttributeClass>(schemaItemKey);\r\n if (targetCustomAttribute === undefined) {\r\n return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.`};\r\n }\r\n\r\n const results = await callback({\r\n ...sourceCustomAttribute,\r\n className: targetCustomAttribute.fullName,\r\n });\r\n\r\n if (results.errorMessage !== undefined) {\r\n return { errorMessage: results.errorMessage };\r\n }\r\n } else {\r\n return { errorMessage: `Changes of Custom Attribute ${customAttributeContainerChange.ecTypeName} on ${mergeContext.targetSchema.name} merge is not implemented.`};\r\n }\r\n }\r\n }\r\n return {};\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"EntityClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/EntityClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAwF;AACxF,+CAA4C;AAG5C;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,yBAAwB;IAClD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAoB;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxF,CAAC;IAEkB,KAAK,CAAC,QAAQ,CAAC,OAAsB,EAAE,KAAY;QACpE,MAAM,QAAQ,GAAG,IAAI,iCAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC;YAChH,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAE5B,+DAA+D;QAC/D,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC/D,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAdD,oCAcC","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 { EntityClass, Mixin, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { ClassMerger } from \"./ClassMerger\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\n\n/**\n * @internal\n */\nexport default class EntityClassMerger extends ClassMerger<EntityClass> {\n protected override async create(schemaKey: SchemaKey, ecClass: EntityClass): Promise<SchemaItemEditResults> {\n return this.context.editor.entities.create(schemaKey, ecClass.name, ecClass.modifier);\n }\n\n protected override async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\n const mixinKey = new SchemaItemKey(mixin.name, mixin.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : mixin.schema.schemaKey);\n\n // addMixin should return results instead of throwing exception\n await this.context.editor.entities.addMixin(itemKey, mixinKey);\n return {};\n }\n}\n"]}
1
+ {"version":3,"file":"EntityClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/EntityClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAwF;AACxF,+CAA4C;AAG5C;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,yBAAwB;IAClD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAoB;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxF,CAAC;IAEkB,KAAK,CAAC,QAAQ,CAAC,OAAsB,EAAE,KAAY;QACpE,MAAM,QAAQ,GAAG,IAAI,iCAAa,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC;YAChH,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAE5B,+DAA+D;QAC/D,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC/D,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAdD,oCAcC","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 { EntityClass, Mixin, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { ClassMerger } from \"./ClassMerger\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class EntityClassMerger extends ClassMerger<EntityClass> {\r\n protected override async create(schemaKey: SchemaKey, ecClass: EntityClass): Promise<SchemaItemEditResults> {\r\n return this.context.editor.entities.create(schemaKey, ecClass.name, ecClass.modifier);\r\n }\r\n\r\n protected override async addMixin(itemKey: SchemaItemKey, mixin: Mixin): Promise<SchemaItemEditResults> {\r\n const mixinKey = new SchemaItemKey(mixin.name, mixin.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : mixin.schema.schemaKey);\r\n\r\n // addMixin should return results instead of throwing exception\r\n await this.context.editor.entities.addMixin(itemKey, mixinKey);\r\n return {};\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAKA,+DAA6E;AAC7E,yDAAsD;AAItD;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,mCAA6B;IAE1E,qDAAqD;IACrD,IAAY,OAAO;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEkB,KAAK,CAAC,KAAK,CAAC,OAAsB,EAAE,MAAmB,EAAE,OAA2B;QACrG,KAAK,MAAM,gBAAgB,IAAI,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,EAAE;YACjE,4EAA4E;YAC5E,wCAAwC;YACxC,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAEzE,MAAM,UAAU,GAAG,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;gBAC3E,IAAI,UAAU,KAAK,SAAS,EAAE;oBAC5B,MAAM,KAAK,CAAC,eAAe,gBAAgB,CAAC,UAAU,wBAAwB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAClG;gBAED,4EAA4E;gBAC5E,+DAA+D;gBAC/D,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAEtD,8EAA8E;gBAC9E,gFAAgF;gBAChF,SAAS;aACV;YAED,6EAA6E;YAC7E,4EAA4E;YAC5E,8EAA8E;YAC9E,KAAI,MAAM,eAAe,IAAI,gBAAgB,CAAC,gBAAgB,EAAE;gBAC9D,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,EAAE,eAAe,CAAC,UAAU,CAAC,WAAmC,CAAC,CAAC;aAC5G;SACF;IACH,CAAC;IAEO,KAAK,CAAC,sBAAsB,CAAC,OAAsB,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAsB;QACjH,8EAA8E;QAC9E,oEAAoE;QACpE,IAAG,YAAY,KAAK,OAAO,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,UAAU,CAAC,IAAI,yBAAyB,CAAC,CAAC;SAChH;QAED,gFAAgF;QAChF,iFAAiF;QACjF,IAAG,YAAY,KAAK,OAAO,IAAI,KAAK,KAAK,SAAS,EAAE;YAClD,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SACxE;QACD,IAAG,YAAY,KAAK,aAAa,IAAI,KAAK,KAAK,SAAS,EAAE;YACxD,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SAC9E;IACH,CAAC;CACF;AApDD,oCAoDC","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 { AnyEnumerator, Enumeration, SchemaItemKey} from \"@itwin/ecschema-metadata\";\nimport { ChangeType, EnumerationChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\n\ntype EnumeratorDeltaArgs = [AnyEnumerator, keyof AnyEnumerator, string | undefined];\n\n/**\n * @internal\n */\nexport default class EnumerationMerger extends SchemaItemMerger<Enumeration> {\n\n /** Shorthand property to the enumerations editor. */\n private get _editor() {\n return this.context.editor.enumerations;\n }\n\n protected override async merge(itemKey: SchemaItemKey, source: Enumeration, changes: EnumerationChanges) {\n for (const enumeratorChange of changes.enumeratorChanges.values()) {\n // In case the enumerator entry does not exist in the target enumeration the\n // enumeratorMissing property is set and\n if (enumeratorChange.enumeratorMissing?.changeType === ChangeType.Missing) {\n\n const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);\n if (enumerator === undefined) {\n throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);\n }\n\n // Enumerators are plain javascript objects with out any references to other\n // instances or a schema. That allows to simply copy them over.\n await this._editor.addEnumerator(itemKey, enumerator);\n\n // Since every missing enumerator has delta changes for ech property, the loop\n // must call continue here to avoid having all properties checked and set again.\n continue;\n }\n\n // For changes where the enumerators differ, the enumeratorDeltas property is\n // filled. This allows to change individual enumerator entries. This is only\n // allowed for labels and descriptions, all other deltas would throw an error.\n for(const enumeratorDelta of enumeratorChange.enumeratorDeltas) {\n await this.mergeEnumeratorChanges(itemKey, enumeratorDelta.diagnostic.messageArgs! as EnumeratorDeltaArgs);\n }\n }\n }\n\n private async mergeEnumeratorChanges(itemKey: SchemaItemKey, [enumerator, propertyName, value]: EnumeratorDeltaArgs) {\n // In case an enumerator has the same name but different value, the enumerator\n // cannot be merged to keep integrity for the existing schema users.\n if(propertyName === \"value\") {\n throw new Error(`Failed to merge enumerator attribute, Enumerator \"${enumerator.name}\" has different values.`);\n }\n\n // For the other two properties they shall only be merged if the source value is\n // set. In case they'd be undefined, the current enumerators value shall be kept.\n if(propertyName === \"label\" && value !== undefined) {\n await this._editor.setEnumeratorLabel(itemKey, enumerator.name, value);\n }\n if(propertyName === \"description\" && value !== undefined) {\n await this._editor.setEnumeratorDescription(itemKey, enumerator.name, value);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAKA,+DAA6E;AAC7E,yDAAsD;AAItD;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,mCAA6B;IAE1E,qDAAqD;IACrD,IAAY,OAAO;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IAC1C,CAAC;IAEkB,KAAK,CAAC,KAAK,CAAC,OAAsB,EAAE,MAAmB,EAAE,OAA2B;QACrG,KAAK,MAAM,gBAAgB,IAAI,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,EAAE;YACjE,4EAA4E;YAC5E,wCAAwC;YACxC,IAAI,gBAAgB,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAEzE,MAAM,UAAU,GAAG,MAAM,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;gBAC3E,IAAI,UAAU,KAAK,SAAS,EAAE;oBAC5B,MAAM,KAAK,CAAC,eAAe,gBAAgB,CAAC,UAAU,wBAAwB,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;iBAClG;gBAED,4EAA4E;gBAC5E,+DAA+D;gBAC/D,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;gBAEtD,8EAA8E;gBAC9E,gFAAgF;gBAChF,SAAS;aACV;YAED,6EAA6E;YAC7E,4EAA4E;YAC5E,8EAA8E;YAC9E,KAAI,MAAM,eAAe,IAAI,gBAAgB,CAAC,gBAAgB,EAAE;gBAC9D,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,EAAE,eAAe,CAAC,UAAU,CAAC,WAAmC,CAAC,CAAC;aAC5G;SACF;IACH,CAAC;IAEO,KAAK,CAAC,sBAAsB,CAAC,OAAsB,EAAE,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,CAAsB;QACjH,8EAA8E;QAC9E,oEAAoE;QACpE,IAAG,YAAY,KAAK,OAAO,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,qDAAqD,UAAU,CAAC,IAAI,yBAAyB,CAAC,CAAC;SAChH;QAED,gFAAgF;QAChF,iFAAiF;QACjF,IAAG,YAAY,KAAK,OAAO,IAAI,KAAK,KAAK,SAAS,EAAE;YAClD,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SACxE;QACD,IAAG,YAAY,KAAK,aAAa,IAAI,KAAK,KAAK,SAAS,EAAE;YACxD,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SAC9E;IACH,CAAC;CACF;AApDD,oCAoDC","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 { AnyEnumerator, Enumeration, SchemaItemKey} from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, EnumerationChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\r\n\r\ntype EnumeratorDeltaArgs = [AnyEnumerator, keyof AnyEnumerator, string | undefined];\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class EnumerationMerger extends SchemaItemMerger<Enumeration> {\r\n\r\n /** Shorthand property to the enumerations editor. */\r\n private get _editor() {\r\n return this.context.editor.enumerations;\r\n }\r\n\r\n protected override async merge(itemKey: SchemaItemKey, source: Enumeration, changes: EnumerationChanges) {\r\n for (const enumeratorChange of changes.enumeratorChanges.values()) {\r\n // In case the enumerator entry does not exist in the target enumeration the\r\n // enumeratorMissing property is set and\r\n if (enumeratorChange.enumeratorMissing?.changeType === ChangeType.Missing) {\r\n\r\n const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);\r\n if (enumerator === undefined) {\r\n throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);\r\n }\r\n\r\n // Enumerators are plain javascript objects with out any references to other\r\n // instances or a schema. That allows to simply copy them over.\r\n await this._editor.addEnumerator(itemKey, enumerator);\r\n\r\n // Since every missing enumerator has delta changes for ech property, the loop\r\n // must call continue here to avoid having all properties checked and set again.\r\n continue;\r\n }\r\n\r\n // For changes where the enumerators differ, the enumeratorDeltas property is\r\n // filled. This allows to change individual enumerator entries. This is only\r\n // allowed for labels and descriptions, all other deltas would throw an error.\r\n for(const enumeratorDelta of enumeratorChange.enumeratorDeltas) {\r\n await this.mergeEnumeratorChanges(itemKey, enumeratorDelta.diagnostic.messageArgs! as EnumeratorDeltaArgs);\r\n }\r\n }\r\n }\r\n\r\n private async mergeEnumeratorChanges(itemKey: SchemaItemKey, [enumerator, propertyName, value]: EnumeratorDeltaArgs) {\r\n // In case an enumerator has the same name but different value, the enumerator\r\n // cannot be merged to keep integrity for the existing schema users.\r\n if(propertyName === \"value\") {\r\n throw new Error(`Failed to merge enumerator attribute, Enumerator \"${enumerator.name}\" has different values.`);\r\n }\r\n\r\n // For the other two properties they shall only be merged if the source value is\r\n // set. In case they'd be undefined, the current enumerators value shall be kept.\r\n if(propertyName === \"label\" && value !== undefined) {\r\n await this._editor.setEnumeratorLabel(itemKey, enumerator.name, value);\r\n }\r\n if(propertyName === \"description\" && value !== undefined) {\r\n await this._editor.setEnumeratorDescription(itemKey, enumerator.name, value);\r\n }\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Kind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Q,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAvDD,uCAuDC","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 { Format, InvertedUnit, KindOfQuantity, OverrideFormat, SchemaItem, SchemaItemKey, Unit } from \"@itwin/ecschema-metadata\";\nimport { PropertyValueResolver, SchemaItemMerger } from \"./SchemaItemMerger\";\nimport { KindOfQuantityChanges } from \"../Validation/SchemaChanges\";\n\n/**\n * @internal\n */\nexport default class KindOfQuantityMerger extends SchemaItemMerger<KindOfQuantity> {\n\n protected override async merge(itemKey: SchemaItemKey, source: KindOfQuantity, changes: KindOfQuantityChanges) {\n for (const presentationUnitChange of changes.presentationUnitChanges.values()) {\n for (const change of presentationUnitChange.presentationUnitChange) {\n const format = change.diagnostic.messageArgs![0];\n const isDefault = source.defaultPresentationFormat === format;\n\n if (OverrideFormat.isOverrideFormat(format)) {\n const parentFormat = await this.lookup<Format>(format.parent);\n if (parentFormat === undefined) {\n throw new Error(`Unable to locate the format class ${format.parent.name} in the merged schema.`);\n }\n\n const unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined = [];\n if (format.units !== undefined) {\n for (const [unit, label] of format.units) {\n const targetUnit = await this.lookup<Unit | InvertedUnit>(unit);\n if (targetUnit === undefined) {\n throw new Error(`Unable to locate the unit class ${unit.name} in the merged schema.`);\n }\n unitAndLabels.push([targetUnit, label]);\n }\n }\n const overrideFormat = await this.context.editor.kindOfQuantities.createFormatOverride(itemKey, parentFormat.key, format.precision, unitAndLabels);\n await this.context.editor.kindOfQuantities.addPresentationOverrideFormat(itemKey, overrideFormat, isDefault);\n } else {\n const targetFormat = await this.lookup<Format>(format);\n if (targetFormat === undefined) {\n throw new Error(`Unable to locate the format class ${format.name} in the merged schema.`);\n }\n await this.context.editor.kindOfQuantities.addPresentationFormat(itemKey, targetFormat.key, isDefault);\n }\n }\n }\n }\n\n /**\n *\n * Creates the property value resolver for [[KindOfQuantity]] items.\n */\n protected override async createPropertyValueResolver(): Promise<PropertyValueResolver<KindOfQuantity>> {\n return {\n persistenceUnit: (newValue, targetItemKey, oldValue) => {\n if (oldValue !== undefined && oldValue !== newValue) {\n throw new Error(`Changing the kind of quantity '${targetItemKey.name}' persistenceUnit is not supported.`);\n }\n const [schemaName, itemName] = SchemaItem.parseFullName(newValue);\n if (this.context.targetSchema.getReferenceSync(schemaName) === undefined) {\n return `${targetItemKey.schemaName}.${itemName}`;\n }\n return newValue;\n },\n };\n }\n}\n"]}
1
+ {"version":3,"file":"KindOfQuantityMerger.js","sourceRoot":"","sources":["../../../src/Merging/KindOfQuantityMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAiI;AACjI,yDAA6E;AAG7E;;GAEG;AACH,MAAqB,oBAAqB,SAAQ,mCAAgC;IAE7D,KAAK,CAAC,KAAK,CAAC,OAAsB,EAAE,MAAsB,EAAE,OAA8B;QAC3G,KAAK,MAAM,sBAAsB,IAAI,OAAO,CAAC,uBAAuB,CAAC,MAAM,EAAE,EAAE;YAC7E,KAAK,MAAM,MAAM,IAAI,sBAAsB,CAAC,sBAAsB,EAAE;gBAClE,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,WAAY,CAAC,CAAC,CAAC,CAAC;gBACjD,MAAM,SAAS,GAAG,MAAM,CAAC,yBAAyB,KAAK,MAAM,CAAC;gBAE9D,IAAI,kCAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE;oBAC3C,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAS,MAAM,CAAC,MAAM,CAAC,CAAC;oBAC9D,IAAI,YAAY,KAAK,SAAS,EAAE;wBAC9B,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,MAAM,CAAC,IAAI,wBAAwB,CAAC,CAAC;qBAClG;oBAED,MAAM,a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AAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,QAAQ,EAAE;oBACnD,MAAM,IAAI,KAAK,CAAC,kCAAkC,aAAa,CAAC,IAAI,qCAAqC,CAAC,CAAC;iBAC5G;gBACD,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,8BAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;gBAClE,IAAI,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE;oBACxE,OAAO,GAAG,aAAa,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC;iBAClD;gBACD,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAvDD,uCAuDC","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 { Format, InvertedUnit, KindOfQuantity, OverrideFormat, SchemaItem, SchemaItemKey, Unit } from \"@itwin/ecschema-metadata\";\r\nimport { PropertyValueResolver, SchemaItemMerger } from \"./SchemaItemMerger\";\r\nimport { KindOfQuantityChanges } from \"../Validation/SchemaChanges\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class KindOfQuantityMerger extends SchemaItemMerger<KindOfQuantity> {\r\n\r\n protected override async merge(itemKey: SchemaItemKey, source: KindOfQuantity, changes: KindOfQuantityChanges) {\r\n for (const presentationUnitChange of changes.presentationUnitChanges.values()) {\r\n for (const change of presentationUnitChange.presentationUnitChange) {\r\n const format = change.diagnostic.messageArgs![0];\r\n const isDefault = source.defaultPresentationFormat === format;\r\n\r\n if (OverrideFormat.isOverrideFormat(format)) {\r\n const parentFormat = await this.lookup<Format>(format.parent);\r\n if (parentFormat === undefined) {\r\n throw new Error(`Unable to locate the format class ${format.parent.name} in the merged schema.`);\r\n }\r\n\r\n const unitAndLabels: Array<[Unit | InvertedUnit, string | undefined]> | undefined = [];\r\n if (format.units !== undefined) {\r\n for (const [unit, label] of format.units) {\r\n const targetUnit = await this.lookup<Unit | InvertedUnit>(unit);\r\n if (targetUnit === undefined) {\r\n throw new Error(`Unable to locate the unit class ${unit.name} in the merged schema.`);\r\n }\r\n unitAndLabels.push([targetUnit, label]);\r\n }\r\n }\r\n const overrideFormat = await this.context.editor.kindOfQuantities.createFormatOverride(itemKey, parentFormat.key, format.precision, unitAndLabels);\r\n await this.context.editor.kindOfQuantities.addPresentationOverrideFormat(itemKey, overrideFormat, isDefault);\r\n } else {\r\n const targetFormat = await this.lookup<Format>(format);\r\n if (targetFormat === undefined) {\r\n throw new Error(`Unable to locate the format class ${format.name} in the merged schema.`);\r\n }\r\n await this.context.editor.kindOfQuantities.addPresentationFormat(itemKey, targetFormat.key, isDefault);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n *\r\n * Creates the property value resolver for [[KindOfQuantity]] items.\r\n */\r\n protected override async createPropertyValueResolver(): Promise<PropertyValueResolver<KindOfQuantity>> {\r\n return {\r\n persistenceUnit: (newValue, targetItemKey, oldValue) => {\r\n if (oldValue !== undefined && oldValue !== newValue) {\r\n throw new Error(`Changing the kind of quantity '${targetItemKey.name}' persistenceUnit is not supported.`);\r\n }\r\n const [schemaName, itemName] = SchemaItem.parseFullName(newValue);\r\n if (this.context.targetSchema.getReferenceSync(schemaName) === undefined) {\r\n return `${targetItemKey.schemaName}.${itemName}`;\r\n }\r\n return newValue;\r\n },\r\n };\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MixinMerger.js","sourceRoot":"","sources":["../../../src/Merging/MixinMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAA2E;AAE3E,+CAA4C;AAE5C;;GAEG;AACH,MAAqB,WAAY,SAAQ,yBAAkB;IAEtC,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAc;QAClE,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE;YACnC,OAAO,EAAE,YAAY,EAAE,aAAa,OAAO,CAAC,QAAQ,iDAAiD,EAAE,CAAC;SACzG;QAED,MAAM,SAAS,GAAG,IAAI,iCAAa,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;YAClI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/E,CAAC;IAEkB,KAAK,CAAC,eAAe,CAAC,OAAc,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QAC5H,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC1G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACnG,OAAO,OAAO,CAAC;SAChB;QAED,QAAO,aAAa,EAAE;YACpB,KAAK,WAAW;gBACd,IAAI,iBAAiB,KAAK,SAAS,EAAE;oBACnC,OAAO,EAAE,YAAY,EAAE,uBAAuB,OAAO,CAAC,IAAI,+BAA+B,EAAE,CAAC;iBAC7F;gBACD,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5BD,8BA4BC","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 { Mixin, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\nimport { ClassMerger } from \"./ClassMerger\";\n\n/**\n * @internal\n */\nexport default class MixinMerger extends ClassMerger<Mixin> {\n\n protected override async create(schemaKey: SchemaKey, ecClass: Mixin): Promise<SchemaItemEditResults> {\n if (ecClass.appliesTo === undefined) {\n return { errorMessage: `The Mixin ${ecClass.fullName} is missing the required 'appliesTo' attribute.` };\n }\n\n const appliesTo = new SchemaItemKey(ecClass.appliesTo.name, this.context.sourceSchema.schemaKey.matches(ecClass.appliesTo.schemaKey)\n ? this.context.targetSchema.schemaKey\n : ecClass.appliesTo.schemaKey);\n return this.context.editor.mixins.create(schemaKey, ecClass.name, appliesTo);\n }\n\n protected override async mergeAttributes(ecClass: Mixin, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n const results = await super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch(attributeName) {\n case \"appliesTo\":\n if (attributeOldValue !== undefined) {\n return { errorMessage: `Changing the mixin '${ecClass.name}' appliesTo is not supported.` };\n }\n return true;\n }\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"MixinMerger.js","sourceRoot":"","sources":["../../../src/Merging/MixinMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAA2E;AAE3E,+CAA4C;AAE5C;;GAEG;AACH,MAAqB,WAAY,SAAQ,yBAAkB;IAEtC,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAc;QAClE,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE;YACnC,OAAO,EAAE,YAAY,EAAE,aAAa,OAAO,CAAC,QAAQ,iDAAiD,EAAE,CAAC;SACzG;QAED,MAAM,SAAS,GAAG,IAAI,iCAAa,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC;YAClI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/E,CAAC;IAEkB,KAAK,CAAC,eAAe,CAAC,OAAc,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QAC5H,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC1G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACnG,OAAO,OAAO,CAAC;SAChB;QAED,QAAO,aAAa,EAAE;YACpB,KAAK,WAAW;gBACd,IAAI,iBAAiB,KAAK,SAAS,EAAE;oBACnC,OAAO,EAAE,YAAY,EAAE,uBAAuB,OAAO,CAAC,IAAI,+BAA+B,EAAE,CAAC;iBAC7F;gBACD,OAAO,IAAI,CAAC;SACf;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5BD,8BA4BC","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 { Mixin, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { ClassMerger } from \"./ClassMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class MixinMerger extends ClassMerger<Mixin> {\r\n\r\n protected override async create(schemaKey: SchemaKey, ecClass: Mixin): Promise<SchemaItemEditResults> {\r\n if (ecClass.appliesTo === undefined) {\r\n return { errorMessage: `The Mixin ${ecClass.fullName} is missing the required 'appliesTo' attribute.` };\r\n }\r\n\r\n const appliesTo = new SchemaItemKey(ecClass.appliesTo.name, this.context.sourceSchema.schemaKey.matches(ecClass.appliesTo.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : ecClass.appliesTo.schemaKey);\r\n return this.context.editor.mixins.create(schemaKey, ecClass.name, appliesTo);\r\n }\r\n\r\n protected override async mergeAttributes(ecClass: Mixin, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n const results = await super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch(attributeName) {\r\n case \"appliesTo\":\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the mixin '${ecClass.name}' appliesTo is not supported.` };\r\n }\r\n return true;\r\n }\r\n return false;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"PrimitiveOrEnumPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PrimitiveOrEnumPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA6L;AAC7L,2DAAwD;AAIxD;;GAEG;AACH,MAAe,6BAAgG,SAAQ,qCAA+C;IACpJ,KAAK,CAAC,eAAe,CAAC,QAAsC,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACjJ,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G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,MAAM,OAAO,GAAG,IAAI,iCAAa,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;YAC3H,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAC/B,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAc,OAAO,CAAC,CAAC;QAC9E,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,EAAE,YAAY,EAAE,0CAA0C,WAAW,CAAC,IAAI,wBAAwB,EAAE,CAAC;SAC7G;QAED,MAAM,KAAK,GAA6B;YACtC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kCAAkC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;CACF;AA7CD,8DA6CC","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 { Enumeration, EnumerationProperty, EnumerationPropertyProps, PrimitiveOrEnumPropertyBase, PrimitiveProperty, PrimitivePropertyProps, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\nimport { PropertyEditResults } from \"../Editing/Editor\";\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\n\n/**\n * @internal\n */\nabstract class PrimitiveOrEnumPropertyMerger<TPrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase> extends AnyPropertyMerger<TPrimitiveOrEnumPropertyBase> {\n public override async mergeAttributes(property: TPrimitiveOrEnumPropertyBase, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const mutableProperty = property as unknown as MutablePrimitiveOrEnumPropertyBase;\n switch (attributeName) {\n case \"extendedTypeName\": {\n mutableProperty.setExtendedTypeName(attributeNewValue);\n return true;\n }\n case \"minLength\": {\n mutableProperty.setMinLength(attributeNewValue);\n return true;\n }\n case \"maxLength\": {\n mutableProperty.setMaxLength(attributeNewValue);\n return true;\n }\n case \"minValue\": {\n mutableProperty.setMinValue(attributeNewValue);\n return true;\n }\n case \"maxValue\": {\n mutableProperty.setMaxValue(attributeNewValue);\n return true;\n }\n }\n return false;\n }\n}\n\n/**\n * @internal\n */\nexport class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger<PrimitiveProperty> {\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const props: PrimitivePropertyProps = {\n ...property.toJSON(),\n ...results,\n };\n return this.context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, props);\n }\n}\n\n/**\n * @internal\n */\nexport class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger<EnumerationProperty> {\n public override async mergeAttributes(property: EnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch (attributeName) {\n case \"enumeration\": {\n if (attributeOldValue !== undefined) {\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\n }\n return true;\n }\n }\n return false;\n }\n\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n if (property.enumeration === undefined) {\n return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };\n }\n\n const enumeration = await property.enumeration;\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : enumeration.schema.schemaKey,\n );\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\n }\n\n const props: EnumerationPropertyProps = {\n ...property.toJSON(),\n ...results,\n typeName: type.fullName,\n };\n return this.context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, props);\n }\n}\n"]}
1
+ {"version":3,"file":"PrimitiveOrEnumPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PrimitiveOrEnumPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA6L;AAC7L,2DAAwD;AAIxD;;GAEG;AACH,MAAe,6BAAgG,SAAQ,qCAA+C;IACpJ,KAAK,CAAC,eAAe,CAAC,QAAsC,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACjJ,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACjG,OAAO,OAAO,CAAC;SAChB;QA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C,SAAS,CAAC;YAC3H,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAC/B,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAc,OAAO,CAAC,CAAC;QAC9E,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,EAAE,YAAY,EAAE,0CAA0C,WAAW,CAAC,IAAI,wBAAwB,EAAE,CAAC;SAC7G;QAED,MAAM,KAAK,GAA6B;YACtC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kCAAkC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;CACF;AA7CD,8DA6CC","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 { Enumeration, EnumerationProperty, EnumerationPropertyProps, PrimitiveOrEnumPropertyBase, PrimitiveProperty, PrimitivePropertyProps, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\r\n\r\n/**\r\n * @internal\r\n */\r\nabstract class PrimitiveOrEnumPropertyMerger<TPrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase> extends AnyPropertyMerger<TPrimitiveOrEnumPropertyBase> {\r\n public override async mergeAttributes(property: TPrimitiveOrEnumPropertyBase, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const mutableProperty = property as unknown as MutablePrimitiveOrEnumPropertyBase;\r\n switch (attributeName) {\r\n case \"extendedTypeName\": {\r\n mutableProperty.setExtendedTypeName(attributeNewValue);\r\n return true;\r\n }\r\n case \"minLength\": {\r\n mutableProperty.setMinLength(attributeNewValue);\r\n return true;\r\n }\r\n case \"maxLength\": {\r\n mutableProperty.setMaxLength(attributeNewValue);\r\n return true;\r\n }\r\n case \"minValue\": {\r\n mutableProperty.setMinValue(attributeNewValue);\r\n return true;\r\n }\r\n case \"maxValue\": {\r\n mutableProperty.setMaxValue(attributeNewValue);\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger<PrimitiveProperty> {\r\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n const props: PrimitivePropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n };\r\n return this.context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, props);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger<EnumerationProperty> {\r\n public override async mergeAttributes(property: EnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\r\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n switch (attributeName) {\r\n case \"enumeration\": {\r\n if (attributeOldValue !== undefined) {\r\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n }\r\n\r\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationProperty): Promise<PropertyEditResults> {\r\n const results = await super.getPropertyProps(property);\r\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n\r\n if (property.enumeration === undefined) {\r\n return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };\r\n }\r\n\r\n const enumeration = await property.enumeration;\r\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : enumeration.schema.schemaKey,\r\n );\r\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\r\n }\r\n\r\n const props: EnumerationPropertyProps = {\r\n ...property.toJSON(),\r\n ...results,\r\n typeName: type.fullName,\r\n };\r\n return this.context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, props);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAgO;AAIhO;;GAEG;AACH,IAAiB,iBAAiB,CAwEjC;AAxED,WAAiB,iBAAiB;IAEhC;;;;;OAKG;IACI,KAAK,UAAU,MAAM,CAAC,OAA2B,EAAE,QAAoB;QAC5E,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC1F,IAAG,MAAM,CAAC,YAAY,EAAE;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,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAChF;QACD,IAAI,EAAE,CAAC,QAAQ,EAAE,8BAAU,CAAC;YAC1B,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEnE,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACH,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EAxEgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAwEjC","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 { Constant, CustomAttributeClass, EntityClass, Enumeration, KindOfQuantity, Phenomenon, PrimitiveType, PropertyCategory, SchemaItem, SchemaItemKey, SchemaKey, StructClass, UnitSystem } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor, SchemaItemEditResults } from \"../Editing/Editor\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * @internal\n */\nexport namespace SchemaItemFactory {\n\n /**\n * Creates a new Schema Item based on the given template instance.\n * @param context The current merging context.\n * @param template The Schema Items Template\n * @returns The SchemaItemKey of the created item.\n */\n export async function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey> {\n const result = await createItem(context.editor, context.targetSchema.schemaKey, template);\n if(result.errorMessage) {\n throw new Error(result.errorMessage);\n }\n return result.itemKey!;\n }\n\n /**\n * Creates a new Schema Item in the SchemaContextEditor.\n * @param editor The SchemaContextEditor\n * @param targetSchemaKey The key of the target schema the item shall be created in.\n * @param template The Schema Items Template\n * @returns A SchemaItemEditResults with a schema key if the item could be created.\n */\n async function createItem(editor: SchemaContextEditor, targetSchemaKey: SchemaKey, template: SchemaItem): Promise<SchemaItemEditResults> {\n if (is(template, Enumeration))\n return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? PrimitiveType.Integer : PrimitiveType.String, template.label, template.isStrict);\n if (is(template, EntityClass))\n return editor.entities.create(targetSchemaKey, template.name, template.modifier);\n if (is(template, StructClass))\n return editor.structs.create(targetSchemaKey, template.name);\n if (is(template, CustomAttributeClass))\n return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);\n if(is(template, PropertyCategory))\n return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);\n if (is(template, Phenomenon))\n return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);\n if (is(template, Constant)) {\n if(template.phenomenon === undefined) {\n throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);\n }\n const phenomenon = await template.phenomenon;\n const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)\n ? new SchemaItemKey(phenomenon.name, targetSchemaKey)\n : phenomenon.key;\n\n return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);\n }\n if (is(template, KindOfQuantity)) {\n if(template.persistenceUnit === undefined) {\n throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);\n }\n const persistenceUnit = await template.persistenceUnit;\n const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)\n ? new SchemaItemKey(persistenceUnit.name, targetSchemaKey)\n : persistenceUnit.key;\n return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);\n }\n if (is(template, UnitSystem))\n return editor.unitSystems.create(targetSchemaKey, template.name);\n\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\n }\n\n /**\n * Type Guard to \"cast\" a given schema item into an implementation\n * @param item Item to be checked\n * @param type The desired implementation.\n * @returns true if the item could be casted, otherwise false.\n */\n function is<T extends SchemaItem>(item: SchemaItem, type: new (...args: any) => T ):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,IAAG,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE;gBACzC,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,IAAI,iCAAiC,CAAC,CAAC;aAC3F;YACD,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC;YACvD,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC;gBAC3E,CAAC,CAAC,IAAI,iCAAa,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC;gBAC1D,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC;YACxB,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAChF;QACD,IAAI,EAAE,CAAC,QAAQ,EAAE,8BAAU,CAAC;YAC1B,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEnE,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACH,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EAxEgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAwEjC","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 { Constant, CustomAttributeClass, EntityClass, Enumeration, KindOfQuantity, Phenomenon, PrimitiveType, PropertyCategory, SchemaItem, SchemaItemKey, SchemaKey, StructClass, UnitSystem } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport namespace SchemaItemFactory {\r\n\r\n /**\r\n * Creates a new Schema Item based on the given template instance.\r\n * @param context The current merging context.\r\n * @param template The Schema Items Template\r\n * @returns The SchemaItemKey of the created item.\r\n */\r\n export async function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey> {\r\n const result = await createItem(context.editor, context.targetSchema.schemaKey, template);\r\n if(result.errorMessage) {\r\n throw new Error(result.errorMessage);\r\n }\r\n return result.itemKey!;\r\n }\r\n\r\n /**\r\n * Creates a new Schema Item in the SchemaContextEditor.\r\n * @param editor The SchemaContextEditor\r\n * @param targetSchemaKey The key of the target schema the item shall be created in.\r\n * @param template The Schema Items Template\r\n * @returns A SchemaItemEditResults with a schema key if the item could be created.\r\n */\r\n async function createItem(editor: SchemaContextEditor, targetSchemaKey: SchemaKey, template: SchemaItem): Promise<SchemaItemEditResults> {\r\n if (is(template, Enumeration))\r\n return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? PrimitiveType.Integer : PrimitiveType.String, template.label, template.isStrict);\r\n if (is(template, EntityClass))\r\n return editor.entities.create(targetSchemaKey, template.name, template.modifier);\r\n if (is(template, StructClass))\r\n return editor.structs.create(targetSchemaKey, template.name);\r\n if (is(template, CustomAttributeClass))\r\n return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);\r\n if(is(template, PropertyCategory))\r\n return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);\r\n if (is(template, Phenomenon))\r\n return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);\r\n if (is(template, Constant)) {\r\n if(template.phenomenon === undefined) {\r\n throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);\r\n }\r\n const phenomenon = await template.phenomenon;\r\n const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)\r\n ? new SchemaItemKey(phenomenon.name, targetSchemaKey)\r\n : phenomenon.key;\r\n\r\n return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);\r\n }\r\n if (is(template, KindOfQuantity)) {\r\n if(template.persistenceUnit === undefined) {\r\n throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);\r\n }\r\n const persistenceUnit = await template.persistenceUnit;\r\n const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)\r\n ? new SchemaItemKey(persistenceUnit.name, targetSchemaKey)\r\n : persistenceUnit.key;\r\n return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);\r\n }\r\n if (is(template, UnitSystem))\r\n return editor.unitSystems.create(targetSchemaKey, template.name);\r\n\r\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\r\n }\r\n\r\n /**\r\n * Type Guard to \"cast\" a given schema item into an implementation\r\n * @param item Item to be checked\r\n * @param type The desired implementation.\r\n * @returns true if the item could be casted, otherwise false.\r\n */\r\n function is<T extends SchemaItem>(item: SchemaItem, type: new (...args: any) => T ): item is T {\r\n return item instanceof type;\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAqE;AACrE,+DAAiG;AACjG,2DAAwD;AAkBxD;;;;;;GAMG;AACH,MAAa,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,2BAA2B;QACzC,sDAAsD;QACtD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,KAAK,CAAC,QAAuB,EAAE,OAAc,EAAE,OAA0B;QACvF,uCAAuC;IACzC,CAAC;IAES,KAAK,CAAC,MAAM,CAAuB,UAAa;QACxD,MAAM,OAAO,GAAG,IAA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,uBAAuB,CAAC,aAAa,EAAE,MAAM,CAAC,oBAAoB,CAAC,CAAC;YACjF,MAAM,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;SACvD;IACH,CAAC;IACD;;;;OAIG;IACK,KAAK,CAAC,uBAAuB,CAAC,aAA4B,EAAE,OAA8B;QAChG,uDAAuD;QACvD,IAAG,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,OAAO;SACR;QAED,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAa,aAAa,CAAC,CAAC,CAAC;QAC3F,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAkC,CAAC;QAChF,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAC;QAElE,KAAI,MAAM,MAAM,IAAI,OAAO,EAAE;YAC3B,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAkD,CAAC;YAChI,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAChD,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,KAAK,SAAS;gBAC9C,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,gBAAgB,CAAC;SACtB;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF;AAjGD,4CAiGC","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 { SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { ChangeType, PropertyValueChange, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaItemFactory } from \"./SchemaItemFactory\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * Defines a type-safe interface of Property Value resolver.\n * @internal\n */\nexport type PropertyValueResolver<T extends SchemaItem, TProps=MutableSchemaItemProps<T>> = {\n [P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;\n};\n\n/**\n * Defines a Mutable Schema Props interface.\n */\ntype MutableSchemaItemProps<T extends SchemaItem> = {\n -readonly [key in keyof ReturnType<T[\"toJSON\"]>]: ReturnType<T[\"toJSON\"]>[key];\n};\n\n/**\n * The SchemaItemMerger is an base class for several other mergers with the actual logic\n * to perform merging for a certain schema item type. The class provides the shared logics\n * that is shared for all schema item mergers and custom logic can be applied by overriding\n * the protected class members.\n * @internal\n */\nexport class SchemaItemMerger<TItem extends SchemaItem> {\n\n protected readonly context: SchemaMergeContext;\n\n /**\n * Constructor of the SchemaItemMerger class. This should not be overriden or extended\n * by sub-implementations.\n * @param context The current merging context.\n */\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n /**\n * This overridable method allows to create a property value resolver that gets defines\n * a handler function for every possible property change. This allows adding complex handing\n * if a property value requires complicated merging.\n * @returns A resolver map with resolvers for the property.\n */\n protected async createPropertyValueResolver(): Promise<PropertyValueResolver<TItem>> {\n // Can be overriden for complex property value merging\n return {};\n }\n\n /**\n * This overridable method gets called for more complex merging.\n * @param _itemKey The key of the current schema item.\n * @param _source The source item that shall gets merged into.\n * @param _change The schema item change to be applied.\n */\n protected async merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges) {\n // Can be overriden for complex merging\n }\n\n protected async lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>{\n const itemKey = new SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : schemaItem.schema.schemaKey,\n );\n return this.context.targetSchema.lookupItem<T>(itemKey);\n }\n\n /**\n * Merges the given schema item changes in the current context.\n * @param context The merging context\n * @param schemaItemChanges An iterable of item changes.\n */\n public static async mergeChanges<TChange extends SchemaItemChanges>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>) {\n const merger = new this(context);\n for(const change of schemaItemChanges) {\n\n // Gets the source and the target item. The target item could be undefined at that point.\n const sourceItem = (await context.sourceSchema.getItem<SchemaItem>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n\n // In case the schema item does not exists in the target schema, an instance for\n // this schema item is created. It's properties get set by the merger then.\n if(change.schemaItemMissing?.changeType === ChangeType.Missing) {\n // Check for name to make sure there is no collision for items with the same name\n // but different type.\n if(await context.targetSchema.lookupItem(targetItemKey) !== undefined) {\n throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);\n }\n\n // TODO: Think about renaming the Schema Item. This could be controlled though a flag.\n targetItemKey = await SchemaItemFactory.create(context, sourceItem);\n }\n\n await merger.mergeItemPropertyValues(targetItemKey, change.propertyValueChanges);\n await merger.merge(targetItemKey, sourceItem, change);\n }\n }\n /**\n * Merges the property values.\n * @param targetItem The current schema item\n * @param changes The property changes.\n */\n private async mergeItemPropertyValues(targetItemKey: SchemaItemKey, changes: PropertyValueChange[]) {\n // No need to process anything if no properties differ.\n if(changes.length === 0) {\n return;\n }\n\n const targetItem = (await this.context.targetSchema.lookupItem<SchemaItem>(targetItemKey));\n const jsonProps = (targetItem?.toJSON() ?? {}) as MutableSchemaItemProps<TItem>;\n const propertyResolver = await this.createPropertyValueResolver();\n\n for(const change of changes) {\n const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs! as [keyof typeof jsonProps, any, any];\n const resolver = propertyResolver[propertyName];\n jsonProps[propertyName] = resolver !== undefined\n ? resolver(propertyNewValue, targetItemKey, propertyOldValue)\n : propertyNewValue;\n }\n\n await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);\n }\n}\n"]}
1
+ {"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAqE;AACrE,+DAAiG;AACjG,2DAAwD;AAkBxD;;;;;;GAMG;AACH,MAAa,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,2BAA2B;QACzC,sDAAsD;QACtD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,KAAK,CAAC,QAAuB,EAAE,OAAc,EAAE,OAA0B;QACvF,uCAAuC;IACzC,CAAC;IAES,KAAK,CAAC,MAAM,CAAuB,UAAa;QACxD,MAAM,OAAO,GAAG,IAAI,iCAAa,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC;YACzH,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAC9B,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAI,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,YAAY,CAAoC,OAA2B,EAAE,iBAAoC;QACnI,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,KAAI,MAAM,MAAM,IAAI,iBAAiB,EAAE;YAErC,yFAAyF;YACzF,MAAM,UAAU,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAa,MAAM,CAAC,UAAU,CAAC,C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BAAgB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAkD,CAAC;YAChI,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAChD,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,KAAK,SAAS;gBAC9C,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,gBAAgB,CAAC;SACtB;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF;AAjGD,4CAiGC","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 { SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { ChangeType, PropertyValueChange, SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaItemFactory } from \"./SchemaItemFactory\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\n/**\r\n * Defines a type-safe interface of Property Value resolver.\r\n * @internal\r\n */\r\nexport type PropertyValueResolver<T extends SchemaItem, TProps=MutableSchemaItemProps<T>> = {\r\n [P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;\r\n};\r\n\r\n/**\r\n * Defines a Mutable Schema Props interface.\r\n */\r\ntype MutableSchemaItemProps<T extends SchemaItem> = {\r\n -readonly [key in keyof ReturnType<T[\"toJSON\"]>]: ReturnType<T[\"toJSON\"]>[key];\r\n};\r\n\r\n/**\r\n * The SchemaItemMerger is an base class for several other mergers with the actual logic\r\n * to perform merging for a certain schema item type. The class provides the shared logics\r\n * that is shared for all schema item mergers and custom logic can be applied by overriding\r\n * the protected class members.\r\n * @internal\r\n */\r\nexport class SchemaItemMerger<TItem extends SchemaItem> {\r\n\r\n protected readonly context: SchemaMergeContext;\r\n\r\n /**\r\n * Constructor of the SchemaItemMerger class. This should not be overriden or extended\r\n * by sub-implementations.\r\n * @param context The current merging context.\r\n */\r\n constructor(context: SchemaMergeContext) {\r\n this.context = context;\r\n }\r\n\r\n /**\r\n * This overridable method allows to create a property value resolver that gets defines\r\n * a handler function for every possible property change. This allows adding complex handing\r\n * if a property value requires complicated merging.\r\n * @returns A resolver map with resolvers for the property.\r\n */\r\n protected async createPropertyValueResolver(): Promise<PropertyValueResolver<TItem>> {\r\n // Can be overriden for complex property value merging\r\n return {};\r\n }\r\n\r\n /**\r\n * This overridable method gets called for more complex merging.\r\n * @param _itemKey The key of the current schema item.\r\n * @param _source The source item that shall gets merged into.\r\n * @param _change The schema item change to be applied.\r\n */\r\n protected async merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges) {\r\n // Can be overriden for complex merging\r\n }\r\n\r\n protected async lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>{\r\n const itemKey = new SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : schemaItem.schema.schemaKey,\r\n );\r\n return this.context.targetSchema.lookupItem<T>(itemKey);\r\n }\r\n\r\n /**\r\n * Merges the given schema item changes in the current context.\r\n * @param context The merging context\r\n * @param schemaItemChanges An iterable of item changes.\r\n */\r\n public static async mergeChanges<TChange extends SchemaItemChanges>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>) {\r\n const merger = new this(context);\r\n for(const change of schemaItemChanges) {\r\n\r\n // Gets the source and the target item. The target item could be undefined at that point.\r\n const sourceItem = (await context.sourceSchema.getItem<SchemaItem>(change.ecTypeName))!;\r\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\r\n\r\n // In case the schema item does not exists in the target schema, an instance for\r\n // this schema item is created. It's properties get set by the merger then.\r\n if(change.schemaItemMissing?.changeType === ChangeType.Missing) {\r\n // Check for name to make sure there is no collision for items with the same name\r\n // but different type.\r\n if(await context.targetSchema.lookupItem(targetItemKey) !== undefined) {\r\n throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);\r\n }\r\n\r\n // TODO: Think about renaming the Schema Item. This could be controlled though a flag.\r\n targetItemKey = await SchemaItemFactory.create(context, sourceItem);\r\n }\r\n\r\n await merger.mergeItemPropertyValues(targetItemKey, change.propertyValueChanges);\r\n await merger.merge(targetItemKey, sourceItem, change);\r\n }\r\n }\r\n /**\r\n * Merges the property values.\r\n * @param targetItem The current schema item\r\n * @param changes The property changes.\r\n */\r\n private async mergeItemPropertyValues(targetItemKey: SchemaItemKey, changes: PropertyValueChange[]) {\r\n // No need to process anything if no properties differ.\r\n if(changes.length === 0) {\r\n return;\r\n }\r\n\r\n const targetItem = (await this.context.targetSchema.lookupItem<SchemaItem>(targetItemKey));\r\n const jsonProps = (targetItem?.toJSON() ?? {}) as MutableSchemaItemProps<TItem>;\r\n const propertyResolver = await this.createPropertyValueResolver();\r\n\r\n for(const change of changes) {\r\n const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs! as [keyof typeof jsonProps, any, any];\r\n const resolver = propertyResolver[propertyName];\r\n jsonProps[propertyName] = resolver !== undefined\r\n ? resolver(propertyNewValue, targetItemKey, propertyOldValue)\r\n : propertyNewValue;\r\n }\r\n\r\n await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;A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AAK,OAAO,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1E,IAAI,gBAAgB,KAAK,OAAO,aAAa,CAAC,qBAAqB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,WAAW,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjH,IAAI,kBAAkB,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC9H,IAAI,WAAW,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjH,IAAI,aAAa,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/G,IAAI,MAAM,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACnG,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,QAAS,CAAC,CAAC,uBAAuB,CAAoC,OAA6B,EAAE,GAAG,KAAuB;IAC7H,KAAI,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,MAAM,CAAC;SACd;KACF;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 { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\n\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\nimport CAClassMerger from \"./CAClassMerger\";\nimport EnumerationMerger from \"./EnumerationMerger\";\nimport ConstantsMerger from \"./ConstantMerger\";\nimport EntityClassMerger from \"./EntityClassMerger\";\nimport StructClassMerger from \"./StructClassMerger\";\nimport MixinMerger from \"./MixinMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\nimport KindOfQuantityMerger from \"./KindOfQuantityMerger\";\n\n/**\n * Defines the context of a Schema merging run.\n * @beta\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly sourceSchema: Schema;\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 * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\n * to the target schema. For example if source contains a class which does not exists in the\n * target one, it would be listed as missing.\n * @param targetSchema The schema the differences gets merged into.\n * @param sourceSchema The schema to compare.\n * @returns An instance of @see SchemaChanges between the two schemas.\n */\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\n const changesList: SchemaChanges[] = [];\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\n\n // It is important to compare the schema items by name, not full name as otherwise\n // we'd often see differences when comparing two different schemas.\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\n\n return changesList[0];\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 merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\n const mergeContext: SchemaMergeContext = {\n editor: new SchemaContextEditor(targetSchema.context),\n targetSchema,\n sourceSchema,\n };\n\n await mergeSchemaReferences(mergeContext, schemaChanges);\n\n const itemChanges = getSchemaItemChanges(schemaChanges);\n await EnumerationMerger.mergeChanges(mergeContext, itemChanges.enumeratations);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.propertyCategories);\n\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);\n await ConstantsMerger.mergeChanges(mergeContext, itemChanges.constants);\n await KindOfQuantityMerger.mergeChanges(mergeContext, itemChanges.kindOfQuantities);\n\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\n // with bases classes or relationships, this might need to get extended.\n await CAClassMerger.mergeChanges(mergeContext, itemChanges.customAttributeClasses);\n await StructClassMerger.mergeChanges(mergeContext, itemChanges.structClasses);\n await EntityClassMerger.mergeChanges(mergeContext, itemChanges.entityClasses);\n await MixinMerger.mergeChanges(mergeContext, itemChanges.mixins);\n\n await mergeCustomAttributes(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {\n return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);\n });\n\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\n // merge into a temporary schema and eventually swap that with the given instance.\n return targetSchema;\n }\n}\n\n/**\n * This helper method composes the different schema change objects to a single easier\n * to use object that should improve readability when the methods get called.\n */\nfunction getSchemaItemChanges(schemaChanges: SchemaChanges) {\n return {\n get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass); },\n get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant); },\n get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass); },\n get enumeratations() { return schemaChanges.enumerationChanges.values(); },\n get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },\n get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon); },\n get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory); },\n get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem); },\n get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.StructClass); },\n get mixins() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.Mixin); },\n };\n}\n\n/**\n * Filters and returns the changed items by its schema item type.\n * @param changes A map of changed schema items.\n * @param types A list of schema item types to filter.\n * @returns An Iterable with the filtered schema items.\n */\nfunction * filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\n for(const change of changes.values()) {\n if (types.includes(change.schemaItemType)) {\n yield change;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;AACpD,+CAAwC;AACxC,mEAAgE;AAChE,iEAA0D;AAY1D;;;;GAIG;AACH,MAAa,YAAY;IACvB;;;;;;;OAOG;IACK,KAAK,CAAC,gBAAgB,CAAC,YAAoB,EAAE,YAAoB;QACvE,MAAM,WAAW,GAAoB,EAAE,CAAC;QACxC,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAE1F,kFAAkF;QAClF,mEAAmE;QACnE,MAAM,cAAc,CAAC,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAEhE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AK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjH,IAAI,aAAa,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/G,IAAI,MAAM,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACnG,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,QAAS,CAAC,CAAC,uBAAuB,CAAoC,OAA6B,EAAE,GAAG,KAAuB;IAC7H,KAAI,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,MAAM,CAAC;SACd;KACF;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 { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\r\nimport { SchemaContextEditor } from \"../Editing/Editor\";\r\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\r\n\r\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\r\nimport CAClassMerger from \"./CAClassMerger\";\r\nimport EnumerationMerger from \"./EnumerationMerger\";\r\nimport ConstantsMerger from \"./ConstantMerger\";\r\nimport EntityClassMerger from \"./EntityClassMerger\";\r\nimport StructClassMerger from \"./StructClassMerger\";\r\nimport MixinMerger from \"./MixinMerger\";\r\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\r\nimport KindOfQuantityMerger from \"./KindOfQuantityMerger\";\r\n\r\n/**\r\n * Defines the context of a Schema merging run.\r\n * @beta\r\n */\r\nexport interface SchemaMergeContext {\r\n readonly targetSchema: Schema;\r\n readonly sourceSchema: Schema;\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 * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\r\n * to the target schema. For example if source contains a class which does not exists in the\r\n * target one, it would be listed as missing.\r\n * @param targetSchema The schema the differences gets merged into.\r\n * @param sourceSchema The schema to compare.\r\n * @returns An instance of @see SchemaChanges between the two schemas.\r\n */\r\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\r\n const changesList: SchemaChanges[] = [];\r\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\r\n\r\n // It is important to compare the schema items by name, not full name as otherwise\r\n // we'd often see differences when comparing two different schemas.\r\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\r\n\r\n return changesList[0];\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 async merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\r\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\r\n const mergeContext: SchemaMergeContext = {\r\n editor: new SchemaContextEditor(targetSchema.context),\r\n targetSchema,\r\n sourceSchema,\r\n };\r\n\r\n await mergeSchemaReferences(mergeContext, schemaChanges);\r\n\r\n const itemChanges = getSchemaItemChanges(schemaChanges);\r\n await EnumerationMerger.mergeChanges(mergeContext, itemChanges.enumeratations);\r\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.propertyCategories);\r\n\r\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);\r\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);\r\n await ConstantsMerger.mergeChanges(mergeContext, itemChanges.constants);\r\n await KindOfQuantityMerger.mergeChanges(mergeContext, itemChanges.kindOfQuantities);\r\n\r\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\r\n // with bases classes or relationships, this might need to get extended.\r\n await CAClassMerger.mergeChanges(mergeContext, itemChanges.customAttributeClasses);\r\n await StructClassMerger.mergeChanges(mergeContext, itemChanges.structClasses);\r\n await EntityClassMerger.mergeChanges(mergeContext, itemChanges.entityClasses);\r\n await MixinMerger.mergeChanges(mergeContext, itemChanges.mixins);\r\n\r\n await mergeCustomAttributes(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {\r\n return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);\r\n });\r\n\r\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\r\n // merge into a temporary schema and eventually swap that with the given instance.\r\n return targetSchema;\r\n }\r\n}\r\n\r\n/**\r\n * This helper method composes the different schema change objects to a single easier\r\n * to use object that should improve readability when the methods get called.\r\n */\r\nfunction getSchemaItemChanges(schemaChanges: SchemaChanges) {\r\n return {\r\n get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass); },\r\n get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant); },\r\n get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass); },\r\n get enumeratations() { return schemaChanges.enumerationChanges.values(); },\r\n get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },\r\n get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon); },\r\n get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory); },\r\n get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem); },\r\n get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.StructClass); },\r\n get mixins() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.Mixin); },\r\n };\r\n}\r\n\r\n/**\r\n * Filters and returns the changed items by its schema item type.\r\n * @param changes A map of changed schema items.\r\n * @param types A list of schema item types to filter.\r\n * @returns An Iterable with the filtered schema items.\r\n */\r\nfunction * filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\r\n for(const change of changes.values()) {\r\n if (types.includes(change.schemaItemType)) {\r\n yield change;\r\n }\r\n }\r\n}\r\n"]}