@itwin/ecschema-editing 4.6.0-dev.7 → 4.6.0-dev.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/lib/cjs/Differencing/SchemaConflicts.d.ts +2 -2
  2. package/lib/cjs/Differencing/SchemaConflicts.js +1 -1
  3. package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
  4. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +9 -6
  5. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
  6. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +213 -161
  7. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
  8. package/lib/cjs/Differencing/SchemaDifference.d.ts +354 -78
  9. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
  10. package/lib/cjs/Differencing/SchemaDifference.js +184 -11
  11. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
  12. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +1 -0
  13. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts.map +1 -1
  14. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  15. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +1 -0
  16. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts.map +1 -1
  17. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  18. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +2 -0
  19. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts.map +1 -1
  20. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  21. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts +1 -0
  22. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts.map +1 -1
  23. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  24. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +1 -0
  25. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts.map +1 -1
  26. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  27. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +2 -0
  28. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts.map +1 -1
  29. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  30. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +1 -0
  31. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts.map +1 -1
  32. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  33. package/lib/cjs/Merging/CAClassMerger.d.ts +4 -7
  34. package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
  35. package/lib/cjs/Merging/CAClassMerger.js +26 -23
  36. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  37. package/lib/cjs/Merging/ClassMerger.d.ts +10 -18
  38. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  39. package/lib/cjs/Merging/ClassMerger.js +148 -155
  40. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  41. package/lib/cjs/Merging/ConstantMerger.d.ts +4 -8
  42. package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
  43. package/lib/cjs/Merging/ConstantMerger.js +59 -40
  44. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  45. package/lib/cjs/Merging/CustomAttributeMerger.d.ts +16 -13
  46. package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
  47. package/lib/cjs/Merging/CustomAttributeMerger.js +66 -34
  48. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  49. package/lib/cjs/Merging/EntityClassMerger.d.ts +10 -7
  50. package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
  51. package/lib/cjs/Merging/EntityClassMerger.js +41 -29
  52. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  53. package/lib/cjs/Merging/EnumerationMerger.d.ts +9 -9
  54. package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
  55. package/lib/cjs/Merging/EnumerationMerger.js +77 -48
  56. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  57. package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +4 -11
  58. package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
  59. package/lib/cjs/Merging/KindOfQuantityMerger.js +57 -53
  60. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  61. package/lib/cjs/Merging/MixinMerger.d.ts +4 -7
  62. package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
  63. package/lib/cjs/Merging/MixinMerger.js +24 -25
  64. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  65. package/lib/cjs/Merging/PhenomenonMerger.d.ts +8 -0
  66. package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -0
  67. package/lib/cjs/Merging/PhenomenonMerger.js +37 -0
  68. package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -0
  69. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts +8 -0
  70. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -0
  71. package/lib/cjs/Merging/PropertyCategoryMerger.js +34 -0
  72. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -0
  73. package/lib/cjs/Merging/PropertyMerger.d.ts +6 -14
  74. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
  75. package/lib/cjs/Merging/PropertyMerger.js +212 -287
  76. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  77. package/lib/cjs/Merging/RelationshipClassMerger.d.ts +16 -10
  78. package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
  79. package/lib/cjs/Merging/RelationshipClassMerger.js +121 -112
  80. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
  81. package/lib/cjs/Merging/SchemaItemMerger.d.ts +26 -51
  82. package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
  83. package/lib/cjs/Merging/SchemaItemMerger.js +106 -88
  84. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  85. package/lib/cjs/Merging/SchemaMerger.d.ts +21 -9
  86. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  87. package/lib/cjs/Merging/SchemaMerger.js +74 -88
  88. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  89. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts +5 -5
  90. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts.map +1 -1
  91. package/lib/cjs/Merging/SchemaReferenceMerger.js +33 -15
  92. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  93. package/lib/cjs/Merging/UnitSystemMerger.d.ts +8 -0
  94. package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -0
  95. package/lib/cjs/Merging/UnitSystemMerger.js +26 -0
  96. package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -0
  97. package/lib/cjs/Validation/ECRules.js +1 -1
  98. package/lib/cjs/Validation/ECRules.js.map +1 -1
  99. package/lib/cjs/Validation/SchemaChanges.js +1 -1
  100. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  101. package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
  102. package/lib/cjs/Validation/SchemaComparer.js +3 -3
  103. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  104. package/package.json +9 -9
  105. package/lib/cjs/Merging/SchemaItemFactory.d.ts +0 -15
  106. package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +0 -1
  107. package/lib/cjs/Merging/SchemaItemFactory.js +0 -82
  108. package/lib/cjs/Merging/SchemaItemFactory.js.map +0 -1
  109. package/lib/cjs/Merging/StructClassMerger.d.ts +0 -10
  110. package/lib/cjs/Merging/StructClassMerger.d.ts.map +0 -1
  111. package/lib/cjs/Merging/StructClassMerger.js +0 -13
  112. package/lib/cjs/Merging/StructClassMerger.js.map +0 -1
@@ -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":["// /*---------------------------------------------------------------------------------------------\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
+ {"version":3,"file":"ConstantMerger.js","sourceRoot":"","sources":["../../../src/Merging/ConstantMerger.ts"],"names":[],"mappings":"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","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { type ConstantDifference } from \"../Differencing/SchemaDifference\";\r\nimport { type SchemaItemMergerHandler, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\nimport { type MutableConstant } from \"../Editing/Mutable/MutableConstant\";\r\nimport { DelayedPromiseWithProps, ECObjectsError, ECObjectsStatus, Phenomenon } from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * Defines a merge handler to merge Constant schema items.\r\n * @internal\r\n */\r\nexport const constantMerger: SchemaItemMergerHandler<ConstantDifference> = {\r\n async add(context, change) {\r\n if (change.difference.phenomenon === undefined) {\r\n return { errorMessage: \"Constant must define phenomenon\" };\r\n }\r\n if (change.difference.definition === undefined) {\r\n return { errorMessage: \"Constant must define definition\" };\r\n }\r\n\r\n // Needs to update the reference from source to target schema.\r\n const phenomenonKey = await updateSchemaItemKey(context, change.difference.phenomenon);\r\n change.difference.phenomenon = phenomenonKey.fullName;\r\n\r\n return context.editor.constants.createFromProps(context.targetSchemaKey, {\r\n ...change.difference,\r\n name: change.itemName,\r\n schemaItemType: change.schemaType,\r\n phenomenon: change.difference.phenomenon,\r\n definition: change.difference.definition,\r\n });\r\n },\r\n async modify(context, change, itemKey, item: MutableConstant) {\r\n if (change.difference.label !== undefined) {\r\n item.setDisplayLabel(change.difference.label);\r\n }\r\n if (change.difference.description !== undefined) {\r\n item.setDescription(change.difference.description);\r\n }\r\n\r\n // Note: There are no editor methods to modify a constant.\r\n if (change.difference.definition !== undefined) {\r\n if (change.difference.definition !== \"\" && item.definition.toLowerCase() !== change.difference.definition.toLowerCase()) {\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Constant ${itemKey.name} has an invalid 'definition' attribute.`);\r\n }\r\n item.setDefinition(change.difference.definition);\r\n }\r\n if (change.difference.denominator !== undefined) {\r\n if (item.hasDenominator && item.denominator !== change.difference.denominator) {\r\n throw new Error(`Failed to merged, constant denominator conflict: ${change.difference.denominator} -> ${item.denominator}`);\r\n }\r\n item.setDenominator(change.difference.denominator);\r\n }\r\n if (change.difference.numerator !== undefined) {\r\n if (item.hasNumerator && item.numerator !== change.difference.numerator) {\r\n throw new Error(`Failed to merged, constant numerator conflict: ${change.difference.numerator} -> ${item.numerator}`);\r\n }\r\n item.setNumerator(change.difference.numerator);\r\n }\r\n if (change.difference.phenomenon !== undefined) {\r\n const lookupKey = await updateSchemaItemKey(context, change.difference.phenomenon);\r\n const phenomenon = await context.editor.schemaContext.getSchemaItem<Phenomenon>(lookupKey);\r\n if (phenomenon === undefined) {\r\n throw new Error(`Could not find phenomenon ${lookupKey.fullName} in the current context`);\r\n }\r\n\r\n item.setPhenomenon(new DelayedPromiseWithProps(phenomenon.key, async () => phenomenon));\r\n }\r\n return { itemKey };\r\n },\r\n};\r\n"]}
@@ -1,21 +1,24 @@
1
- /** @packageDocumentation
2
- * @module Merging
3
- */
4
1
  import { CustomAttribute } from "@itwin/ecschema-metadata";
5
- import { CustomAttributeContainerChanges } from "../Validation/SchemaChanges";
6
- import { SchemaMergeContext } from "./SchemaMerger";
7
- interface EditResults {
8
- errorMessage?: string;
9
- }
2
+ import { type SchemaMergeContext } from "./SchemaMerger";
3
+ import { type CustomAttributeDifference } from "../Differencing/SchemaDifference";
4
+ import { type SchemaEditResults } from "../Editing/Editor";
5
+ type CustomAttributeSetter = (customAttribute: CustomAttribute) => Promise<SchemaEditResults>;
10
6
  /**
11
7
  * Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass
12
8
  * a scope (Class, Property, Schema) specific handler.
13
- * @param mergeContext The current schema merging context.
14
- * @param changes An iterable with custom attribute changes.
15
- * @param callback The callback to add the custom attribute with a scope specific editor.
16
- * @returns A EditResults object.
9
+ * @param context The current schema merging context.
10
+ * @param change The individual custom attribute change.
11
+ * @returns A EditResults object.
12
+ * @internal
13
+ */
14
+ export declare function mergeCustomAttribute(context: SchemaMergeContext, change: CustomAttributeDifference): Promise<SchemaEditResults>;
15
+ /**
16
+ * @internal
17
+ */
18
+ export declare function applyCustomAttributes(context: SchemaMergeContext, customAttributes: CustomAttribute[], handler: CustomAttributeSetter): Promise<SchemaEditResults>;
19
+ /**
17
20
  * @internal
18
21
  */
19
- export declare function mergeCustomAttributes(mergeContext: SchemaMergeContext, changes: Iterable<CustomAttributeContainerChanges>, callback: (customAttribute: CustomAttribute) => Promise<EditResults>): Promise<EditResults>;
22
+ export declare function applyCustomAttribute(context: SchemaMergeContext, customAttribute: CustomAttribute, handler: CustomAttributeSetter): Promise<SchemaEditResults>;
20
23
  export {};
21
24
  //# sourceMappingURL=CustomAttributeMerger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomAttributeMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAA8D,MAAM,0BAA0B,CAAC;AACvH,OAAO,EAAc,+BAA+B,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,UAAU,WAAW;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,YAAY,EAAE,kBAAkB,EAAE,OAAO,EAAE,QAAQ,CAAC,+BAA+B,CAAC,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CA6B5N"}
1
+ {"version":3,"file":"CustomAttributeMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAA0D,MAAM,0BAA0B,CAAC;AACnH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,KAAK,qBAAqB,GAAG,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE9F;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA6CrI;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAQxK;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAGpK"}
@@ -1,51 +1,83 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyCustomAttribute = exports.applyCustomAttributes = exports.mergeCustomAttribute = void 0;
2
4
  /*---------------------------------------------------------------------------------------------
3
5
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
6
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
7
  *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Merging
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.mergeCustomAttributes = void 0;
11
8
  const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
- const SchemaChanges_1 = require("../Validation/SchemaChanges");
9
+ const SchemaItemMerger_1 = require("./SchemaItemMerger");
13
10
  /**
14
11
  * Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass
15
12
  * a scope (Class, Property, Schema) specific handler.
16
- * @param mergeContext The current schema merging context.
17
- * @param changes An iterable with custom attribute changes.
18
- * @param callback The callback to add the custom attribute with a scope specific editor.
19
- * @returns A EditResults object.
13
+ * @param context The current schema merging context.
14
+ * @param change The individual custom attribute change.
15
+ * @returns A EditResults object.
20
16
  * @internal
21
17
  */
22
- async function mergeCustomAttributes(mergeContext, changes, callback) {
23
- for (const customAttributeContainerChange of changes) {
24
- for (const change of customAttributeContainerChange.customAttributeChanges) {
25
- if (change.changeType === SchemaChanges_1.ChangeType.Missing) {
26
- const [sourceCustomAttribute] = change.diagnostic.messageArgs;
27
- const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(sourceCustomAttribute.className);
28
- const schemaItemKey = new ecschema_metadata_1.SchemaItemKey(itemName, mergeContext.sourceSchema.schemaKey.compareByName(schemaName)
29
- ? mergeContext.targetSchema.schemaKey
30
- : new ecschema_metadata_1.SchemaKey(schemaName));
31
- const targetCustomAttribute = await mergeContext.targetSchema.lookupItem(schemaItemKey);
32
- if (targetCustomAttribute === undefined) {
33
- return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.` };
34
- }
35
- const results = await callback({
36
- ...sourceCustomAttribute,
37
- className: targetCustomAttribute.fullName,
38
- });
39
- if (results.errorMessage !== undefined) {
40
- return { errorMessage: results.errorMessage };
41
- }
42
- }
43
- else {
44
- return { errorMessage: `Changes of Custom Attribute ${customAttributeContainerChange.ecTypeName} on ${mergeContext.targetSchema.name} merge is not implemented.` };
18
+ async function mergeCustomAttribute(context, change) {
19
+ if (change.changeType === "add") {
20
+ if (change.difference.className === undefined) {
21
+ return { errorMessage: "CustomAttribute instance must specify className" };
22
+ }
23
+ const schemaItemKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, change.difference.className);
24
+ const targetCustomAttributeClass = await context.targetSchema.lookupItem(schemaItemKey);
25
+ if (targetCustomAttributeClass === undefined) {
26
+ return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.` };
27
+ }
28
+ const caInstance = {
29
+ ...change.difference,
30
+ className: schemaItemKey.fullName,
31
+ };
32
+ if (change.appliedTo === "Schema") {
33
+ return context.editor.addCustomAttribute(context.targetSchemaKey, caInstance);
34
+ }
35
+ if (change.appliedTo === "SchemaItem") {
36
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
37
+ return context.editor.entities.addCustomAttribute(itemKey, caInstance);
38
+ }
39
+ if (change.appliedTo === "Property") {
40
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
41
+ const [propertyName] = change.path.split(".");
42
+ return context.editor.entities.addCustomAttributeToProperty(itemKey, propertyName, caInstance);
43
+ }
44
+ if (change.appliedTo === "RelationshipConstraint") {
45
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
46
+ const relationshipClass = await context.targetSchema.lookupItem(itemKey);
47
+ if (relationshipClass === undefined) {
48
+ return { errorMessage: `Unable to locate the relationship class ${itemKey.name} in the merged schema.` };
45
49
  }
50
+ const constraint = change.path === "$source"
51
+ ? relationshipClass.source
52
+ : relationshipClass.target;
53
+ return context.editor.relationships.addCustomAttributeToConstraint(constraint, caInstance);
54
+ }
55
+ return {};
56
+ }
57
+ else {
58
+ return { errorMessage: `Changes of Custom Attribute on merge is not implemented.` };
59
+ }
60
+ }
61
+ exports.mergeCustomAttribute = mergeCustomAttribute;
62
+ /**
63
+ * @internal
64
+ */
65
+ async function applyCustomAttributes(context, customAttributes, handler) {
66
+ for (const customAttribute of customAttributes) {
67
+ const result = await applyCustomAttribute(context, customAttribute, handler);
68
+ if (result.errorMessage) {
69
+ return result;
46
70
  }
47
71
  }
48
72
  return {};
49
73
  }
50
- exports.mergeCustomAttributes = mergeCustomAttributes;
74
+ exports.applyCustomAttributes = applyCustomAttributes;
75
+ /**
76
+ * @internal
77
+ */
78
+ async function applyCustomAttribute(context, customAttribute, handler) {
79
+ customAttribute.className = await (0, SchemaItemMerger_1.updateSchemaItemFullName)(context, customAttribute.className);
80
+ return handler(customAttribute);
81
+ }
82
+ exports.applyCustomAttribute = applyCustomAttribute;
51
83
  //# sourceMappingURL=CustomAttributeMerger.js.map
@@ -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":["/*---------------------------------------------------------------------------------------------\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
+ {"version":3,"file":"CustomAttributeMerger.js","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":"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","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 { CustomAttribute, CustomAttributeClass, RelationshipClass, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { type SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { type CustomAttributeDifference } from \"../Differencing/SchemaDifference\";\r\nimport { type SchemaEditResults } from \"../Editing/Editor\";\r\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\n\r\ntype CustomAttributeSetter = (customAttribute: CustomAttribute) => Promise<SchemaEditResults>;\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 context The current schema merging context.\r\n * @param change The individual custom attribute change.\r\n * @returns A EditResults object.\r\n * @internal\r\n */\r\nexport async function mergeCustomAttribute(context: SchemaMergeContext, change: CustomAttributeDifference): Promise<SchemaEditResults> {\r\n if (change.changeType === \"add\") {\r\n if (change.difference.className === undefined) {\r\n return { errorMessage: \"CustomAttribute instance must specify className\" };\r\n }\r\n const schemaItemKey = await updateSchemaItemKey(context, change.difference.className);\r\n\r\n const targetCustomAttributeClass = await context.targetSchema.lookupItem<CustomAttributeClass>(schemaItemKey);\r\n if (targetCustomAttributeClass === 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 caInstance: CustomAttribute = {\r\n ...change.difference,\r\n className: schemaItemKey.fullName,\r\n };\r\n\r\n if (change.appliedTo === \"Schema\") {\r\n return context.editor.addCustomAttribute(context.targetSchemaKey, caInstance);\r\n }\r\n if (change.appliedTo === \"SchemaItem\") {\r\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n return context.editor.entities.addCustomAttribute(itemKey, caInstance);\r\n }\r\n if (change.appliedTo === \"Property\") {\r\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n const [propertyName] = change.path.split(\".\");\r\n return context.editor.entities.addCustomAttributeToProperty(itemKey, propertyName, caInstance);\r\n }\r\n if (change.appliedTo === \"RelationshipConstraint\") {\r\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n const relationshipClass = await context.targetSchema.lookupItem<RelationshipClass>(itemKey);\r\n if (relationshipClass === undefined) {\r\n return { errorMessage: `Unable to locate the relationship class ${itemKey.name} in the merged schema.` };\r\n }\r\n const constraint = change.path === \"$source\"\r\n ? relationshipClass.source\r\n : relationshipClass.target;\r\n\r\n return context.editor.relationships.addCustomAttributeToConstraint(constraint, caInstance);\r\n }\r\n return {};\r\n } else {\r\n return { errorMessage: `Changes of Custom Attribute on merge is not implemented.` };\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function applyCustomAttributes(context: SchemaMergeContext, customAttributes: CustomAttribute[], handler: CustomAttributeSetter): Promise<SchemaEditResults> {\r\n for (const customAttribute of customAttributes) {\r\n const result = await applyCustomAttribute(context, customAttribute, handler);\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n return {};\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function applyCustomAttribute(context: SchemaMergeContext, customAttribute: CustomAttribute, handler: CustomAttributeSetter): Promise<SchemaEditResults> {\r\n customAttribute.className = await updateSchemaItemFullName(context, customAttribute.className);\r\n return handler(customAttribute);\r\n}\r\n"]}
@@ -1,12 +1,15 @@
1
- import { EntityClass, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
2
- import { ClassMerger } from "./ClassMerger";
1
+ import { type EntityClassDifference, EntityClassMixinDifference } from "../Differencing/SchemaDifference";
2
+ import { type SchemaItemMergerHandler } from "./SchemaItemMerger";
3
+ import { SchemaMergeContext } from "./SchemaMerger";
3
4
  import { SchemaItemEditResults } from "../Editing/Editor";
4
- import { ClassChanges } from "../Validation/SchemaChanges";
5
5
  /**
6
+ * Defines a merge handler to merge Entity Class schema items.
6
7
  * @internal
7
8
  */
8
- export default class EntityClassMerger extends ClassMerger<EntityClass> {
9
- protected create(schemaKey: SchemaKey, ecClass: EntityClass): Promise<SchemaItemEditResults>;
10
- protected merge(itemKey: SchemaItemKey, changes: ClassChanges): Promise<SchemaItemEditResults>;
11
- }
9
+ export declare const entityClassMerger: SchemaItemMergerHandler<EntityClassDifference>;
10
+ /**
11
+ * Merges Mixins to Entity Class schema items.
12
+ * @internal
13
+ */
14
+ export declare function mergeClassMixins(context: SchemaMergeContext, change: EntityClassMixinDifference): Promise<SchemaItemEditResults>;
12
15
  //# sourceMappingURL=EntityClassMerger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EntityClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAS,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAc,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,WAAW,CAAC,WAAW,CAAC;cAC5C,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAIlF,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAuB9G"}
1
+ {"version":3,"file":"EntityClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EntityClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AAC1G,OAAO,EAAE,KAAK,uBAAuB,EAAuB,MAAM,oBAAoB,CAAC;AAIvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,uBAAuB,CAAC,qBAAqB,CAsB5E,CAAC;AAEF;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,0BAA0B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CActI"}
@@ -1,41 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /*---------------------------------------------------------------------------------------------
4
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
- * See LICENSE.md in the project root for license terms and full copyright notice.
6
- *--------------------------------------------------------------------------------------------*/
7
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
3
+ exports.mergeClassMixins = exports.entityClassMerger = void 0;
4
+ const SchemaItemMerger_1 = require("./SchemaItemMerger");
8
5
  const ClassMerger_1 = require("./ClassMerger");
9
- const SchemaChanges_1 = require("../Validation/SchemaChanges");
6
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
10
7
  /**
8
+ * Defines a merge handler to merge Entity Class schema items.
11
9
  * @internal
12
10
  */
13
- class EntityClassMerger extends ClassMerger_1.ClassMerger {
14
- async create(schemaKey, ecClass) {
15
- return this.context.editor.entities.create(schemaKey, ecClass.name, ecClass.modifier);
16
- }
17
- async merge(itemKey, changes) {
18
- if (changes.entityMixinChanges.size > 0) {
19
- if (changes.schemaItemMissing?.changeType !== SchemaChanges_1.ChangeType.Missing) {
20
- return { errorMessage: `Changing the entity class '${itemKey.name}' mixins is not supported.` };
21
- }
22
- for (const change of changes.entityMixinChanges.values()) {
23
- for (const entityMixinChange of change.entityMixinChange) {
24
- const mixins = entityMixinChange.diagnostic.messageArgs;
25
- for (const mixin of mixins) {
26
- const mixinKey = new ecschema_metadata_1.SchemaItemKey(mixin.name, mixin.schema.schemaKey.matches(this.context.sourceSchema.schemaKey)
27
- ? this.context.targetSchema.schemaKey
28
- : mixin.schema.schemaKey);
29
- const result = await this.context.editor.entities.addMixin(itemKey, mixinKey);
30
- if (result.errorMessage !== undefined) {
31
- return result;
32
- }
33
- }
11
+ exports.entityClassMerger = {
12
+ async add(context, change) {
13
+ return context.editor.entities.createFromProps(context.targetSchemaKey, {
14
+ name: change.itemName,
15
+ schemaItemType: change.schemaType,
16
+ ...change.difference,
17
+ });
18
+ },
19
+ async modify(context, change, itemKey, item) {
20
+ if (change.difference.mixins !== undefined) {
21
+ for (const mixin of change.difference.mixins) {
22
+ const mixinKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, mixin);
23
+ const result = await context.editor.entities.addMixin(itemKey, mixinKey);
24
+ if (result.errorMessage) {
25
+ return result;
34
26
  }
35
27
  }
36
28
  }
37
- return { itemKey };
29
+ return (0, ClassMerger_1.modifyClass)(context, change, itemKey, item);
30
+ },
31
+ };
32
+ /**
33
+ * Merges Mixins to Entity Class schema items.
34
+ * @internal
35
+ */
36
+ async function mergeClassMixins(context, change) {
37
+ if (change.changeType === "add") {
38
+ for (const mixinFullName of change.difference) {
39
+ const mixinKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, mixinFullName);
40
+ const entityKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
41
+ const result = await context.editor.entities.addMixin(entityKey, mixinKey);
42
+ if (result.errorMessage) {
43
+ throw new Error(result.errorMessage);
44
+ }
45
+ }
46
+ return {};
47
+ }
48
+ else {
49
+ return { errorMessage: `Changing the entity class '${change.itemName}' mixins is not supported.` };
38
50
  }
39
51
  }
40
- exports.default = EntityClassMerger;
52
+ exports.mergeClassMixins = mergeClassMixins;
41
53
  //# sourceMappingURL=EntityClassMerger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/EntityClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAwF;AACxF,+CAA4C;AAE5C,+DAAuE;AAEvE;;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,KAAK,CAAC,OAAsB,EAAE,OAAqB;QAC1E,IAAI,OAAO,CAAC,kBAAkB,CAAC,IAAI,GAAG,CAAC,EAAE;YACvC,IAAI,OAAO,CAAC,iBAAiB,EAAE,UAAU,KAAK,0BAAU,CAAC,OAAO,EAAE;gBAChE,OAAO,EAAE,YAAY,EAAE,8BAA8B,OAAO,CAAC,IAAI,4BAA4B,EAAC,CAAC;aAChG;YAED,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE;gBACxD,KAAK,MAAM,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,EAAE;oBACxD,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,WAAkC,CAAC;oBAC/E,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;wBAC1B,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;4BAChH,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;4BACrC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;wBAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;wBAC9E,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE;4BACrC,OAAO,MAAM,CAAC;yBACf;qBACF;iBACF;aACF;SACF;QACD,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF;AA5BD,oCA4BC","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\nimport { ChangeType, ClassChanges } from \"../Validation/SchemaChanges\";\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 merge(itemKey: SchemaItemKey, changes: ClassChanges): Promise<SchemaItemEditResults> {\r\n if (changes.entityMixinChanges.size > 0) {\r\n if (changes.schemaItemMissing?.changeType !== ChangeType.Missing) {\r\n return { errorMessage: `Changing the entity class '${itemKey.name}' mixins is not supported.`};\r\n }\r\n\r\n for (const change of changes.entityMixinChanges.values()) {\r\n for (const entityMixinChange of change.entityMixinChange) {\r\n const mixins = entityMixinChange.diagnostic.messageArgs! as unknown as [Mixin];\r\n for (const mixin of mixins) {\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 const result = await this.context.editor.entities.addMixin(itemKey, mixinKey);\r\n if (result.errorMessage !== undefined) {\r\n return result;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n return { itemKey };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"EntityClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/EntityClassMerger.ts"],"names":[],"mappings":";;;AAKA,yDAAuF;AAEvF,+CAA4C;AAC5C,gEAAyD;AAIzD;;;GAGG;AACU,QAAA,iBAAiB,GAAmD;IAC/E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM;QACvB,OAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,eAAe,EAAE;YACtE,IAAI,EAAE,MAAM,CAAC,QAAQ;YACrB,cAAc,EAAE,MAAM,CAAC,UAAU;YAEjC,GAAG,MAAM,CAAC,UAAU;SACrB,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAwB;QAC7D,IAAG,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,SAAS,EAAE;YACzC,KAAI,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE;gBAC3C,MAAM,QAAQ,GAAG,MAAM,IAAA,sCAAmB,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC3D,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBACzE,IAAG,MAAM,CAAC,YAAY,EAAE;oBACtB,OAAO,MAAM,CAAC;iBACf;aACF;SACF;QAED,OAAO,IAAA,yBAAW,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;CACF,CAAC;AAEF;;;GAGG;AACI,KAAK,UAAU,gBAAgB,CAAC,OAA2B,EAAE,MAAkC;IACpG,IAAG,MAAM,CAAC,UAAU,KAAK,KAAK,EAAE;QAC9B,KAAI,MAAM,aAAa,IAAI,MAAM,CAAC,UAAU,EAAE;YAC5C,MAAM,QAAQ,GAAG,MAAM,IAAA,sCAAmB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YACnE,MAAM,SAAS,GAAG,IAAI,iCAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;YAC9E,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YAC3E,IAAG,MAAM,CAAC,YAAY,EAAE;gBACtB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;aACtC;SACF;QACD,OAAO,EAAE,CAAC;KACX;SAAM;QACL,OAAO,EAAE,YAAY,EAAE,8BAA8B,MAAM,CAAC,QAAQ,4BAA4B,EAAC,CAAC;KACnG;AACH,CAAC;AAdD,4CAcC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { type EntityClassDifference, EntityClassMixinDifference } from \"../Differencing/SchemaDifference\";\r\nimport { type SchemaItemMergerHandler, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\nimport { type MutableEntityClass } from \"../Editing/Mutable/MutableEntityClass\";\r\nimport { modifyClass } from \"./ClassMerger\";\r\nimport { SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\n\r\n/**\r\n * Defines a merge handler to merge Entity Class schema items.\r\n * @internal\r\n */\r\nexport const entityClassMerger: SchemaItemMergerHandler<EntityClassDifference> = {\r\n async add(context, change) {\r\n return context.editor.entities.createFromProps(context.targetSchemaKey, {\r\n name: change.itemName,\r\n schemaItemType: change.schemaType,\r\n\r\n ...change.difference,\r\n });\r\n },\r\n async modify(context, change, itemKey, item: MutableEntityClass) {\r\n if(change.difference.mixins !== undefined) {\r\n for(const mixin of change.difference.mixins) {\r\n const mixinKey = await updateSchemaItemKey(context, mixin);\r\n const result = await context.editor.entities.addMixin(itemKey, mixinKey);\r\n if(result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n }\r\n\r\n return modifyClass(context, change, itemKey, item);\r\n },\r\n};\r\n\r\n/**\r\n * Merges Mixins to Entity Class schema items.\r\n * @internal\r\n */\r\nexport async function mergeClassMixins(context: SchemaMergeContext, change: EntityClassMixinDifference): Promise<SchemaItemEditResults> {\r\n if(change.changeType === \"add\") {\r\n for(const mixinFullName of change.difference) {\r\n const mixinKey = await updateSchemaItemKey(context, mixinFullName);\r\n const entityKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n const result = await context.editor.entities.addMixin(entityKey, mixinKey);\r\n if(result.errorMessage) {\r\n throw new Error(result.errorMessage);\r\n }\r\n }\r\n return {};\r\n } else {\r\n return { errorMessage: `Changing the entity class '${change.itemName}' mixins is not supported.`};\r\n }\r\n}\r\n"]}
@@ -1,13 +1,13 @@
1
- import { Enumeration, SchemaItemKey } from "@itwin/ecschema-metadata";
2
- import { EnumerationChanges } from "../Validation/SchemaChanges";
3
- import { SchemaItemMerger } from "./SchemaItemMerger";
1
+ import type { EnumerationDifference, EnumeratorDifference } from "../Differencing/SchemaDifference";
2
+ import type { SchemaItemMergerHandler } from "./SchemaItemMerger";
4
3
  /**
4
+ * Defines a merge handler to merge Enumeration schema items.
5
5
  * @internal
6
6
  */
7
- export default class EnumerationMerger extends SchemaItemMerger<Enumeration> {
8
- /** Shorthand property to the enumerations editor. */
9
- private get _editor();
10
- protected merge(itemKey: SchemaItemKey, source: Enumeration, changes: EnumerationChanges): Promise<void>;
11
- private mergeEnumeratorChanges;
12
- }
7
+ export declare const enumerationMerger: SchemaItemMergerHandler<EnumerationDifference>;
8
+ /**
9
+ * Defines a merge handler to merge Enumeration schema items.
10
+ * @internal
11
+ */
12
+ export declare const enumeratorMerger: SchemaItemMergerHandler<EnumeratorDifference>;
13
13
  //# sourceMappingURL=EnumerationMerger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,WAAW,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAc,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,gBAAgB,CAAC,WAAW,CAAC;IAE1E,qDAAqD;IACrD,OAAO,KAAK,OAAO,GAElB;cAEwB,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB;YA6BzF,sBAAsB;CAgBrC"}
1
+ {"version":3,"file":"EnumerationMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACpG,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAGlE;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,uBAAuB,CAAC,qBAAqB,CAoC5E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,uBAAuB,CAAC,oBAAoB,CAgC1E,CAAC"}
@@ -1,54 +1,83 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const SchemaChanges_1 = require("../Validation/SchemaChanges");
4
- const SchemaItemMerger_1 = require("./SchemaItemMerger");
3
+ exports.enumeratorMerger = exports.enumerationMerger = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
5
9
  /**
10
+ * Defines a merge handler to merge Enumeration schema items.
6
11
  * @internal
7
12
  */
8
- class EnumerationMerger extends SchemaItemMerger_1.SchemaItemMerger {
9
- /** Shorthand property to the enumerations editor. */
10
- get _editor() {
11
- return this.context.editor.enumerations;
12
- }
13
- async merge(itemKey, source, changes) {
14
- for (const enumeratorChange of changes.enumeratorChanges.values()) {
15
- // In case the enumerator entry does not exist in the target enumeration the
16
- // enumeratorMissing property is set and
17
- if (enumeratorChange.enumeratorMissing?.changeType === SchemaChanges_1.ChangeType.Missing) {
18
- const enumerator = source.getEnumeratorByName(enumeratorChange.ecTypeName);
19
- if (enumerator === undefined) {
20
- throw Error(`Enumerator '${enumeratorChange.ecTypeName}' not found in class ${source.fullName}`);
21
- }
22
- // Enumerators are plain javascript objects with out any references to other
23
- // instances or a schema. That allows to simply copy them over.
24
- await this._editor.addEnumerator(itemKey, enumerator);
25
- // Since every missing enumerator has delta changes for ech property, the loop
26
- // must call continue here to avoid having all properties checked and set again.
27
- continue;
28
- }
29
- // For changes where the enumerators differ, the enumeratorDeltas property is
30
- // filled. This allows to change individual enumerator entries. This is only
31
- // allowed for labels and descriptions, all other deltas would throw an error.
32
- for (const enumeratorDelta of enumeratorChange.enumeratorDeltas) {
33
- await this.mergeEnumeratorChanges(itemKey, enumeratorDelta.diagnostic.messageArgs);
34
- }
35
- }
36
- }
37
- async mergeEnumeratorChanges(itemKey, [enumerator, propertyName, value]) {
38
- // In case an enumerator has the same name but different value, the enumerator
39
- // cannot be merged to keep integrity for the existing schema users.
40
- if (propertyName === "value") {
41
- throw new Error(`Failed to merge enumerator attribute, Enumerator "${enumerator.name}" has different values.`);
42
- }
43
- // For the other two properties they shall only be merged if the source value is
44
- // set. In case they'd be undefined, the current enumerators value shall be kept.
45
- if (propertyName === "label" && value !== undefined) {
46
- await this._editor.setEnumeratorLabel(itemKey, enumerator.name, value);
47
- }
48
- if (propertyName === "description" && value !== undefined) {
49
- await this._editor.setEnumeratorDescription(itemKey, enumerator.name, value);
50
- }
51
- }
52
- }
53
- exports.default = EnumerationMerger;
13
+ exports.enumerationMerger = {
14
+ async add(context, change) {
15
+ if (change.difference.type === undefined) {
16
+ return { errorMessage: "Enumerations must define a type property" };
17
+ }
18
+ if (change.difference.isStrict === undefined) {
19
+ return { errorMessage: "Enumerations must define whether enumeration is strict." };
20
+ }
21
+ if (change.difference.enumerators === undefined) {
22
+ return { errorMessage: "Enumerations must define at least ine enumerator." };
23
+ }
24
+ return context.editor.enumerations.createFromProps(context.targetSchemaKey, {
25
+ ...change.difference,
26
+ name: change.itemName,
27
+ schemaItemType: change.schemaType,
28
+ type: change.difference.type,
29
+ isStrict: change.difference.isStrict,
30
+ enumerators: change.difference.enumerators,
31
+ });
32
+ },
33
+ async modify(_context, change, itemKey, item) {
34
+ if (change.difference.type !== undefined) {
35
+ return { errorMessage: `The Enumeration ${itemKey.name} has an incompatible type. It must be "${(0, ecschema_metadata_1.primitiveTypeToString)(item.type)}", not "${change.difference.type}".` };
36
+ }
37
+ if (change.difference.label !== undefined) {
38
+ item.setDisplayLabel(change.difference.label);
39
+ }
40
+ if (change.difference.description !== undefined) {
41
+ item.setDescription(change.difference.description);
42
+ }
43
+ if (change.difference.isStrict !== undefined) {
44
+ item.setIsStrict(change.difference.isStrict);
45
+ }
46
+ return { itemKey };
47
+ },
48
+ };
49
+ /**
50
+ * Defines a merge handler to merge Enumeration schema items.
51
+ * @internal
52
+ */
53
+ exports.enumeratorMerger = {
54
+ async add(context, change) {
55
+ if (change.difference.name === undefined) {
56
+ return { errorMessage: "Enumerators must define a name" };
57
+ }
58
+ if (change.difference.value === undefined) {
59
+ return { errorMessage: "Enumerators must define a value" };
60
+ }
61
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
62
+ await context.editor.enumerations.addEnumerator(itemKey, {
63
+ name: change.difference.name,
64
+ value: change.difference.value,
65
+ label: change.difference.label,
66
+ description: change.difference.description,
67
+ });
68
+ return { itemKey };
69
+ },
70
+ async modify(context, change, itemKey) {
71
+ if (change.difference.value !== undefined) {
72
+ return { errorMessage: `Failed to merge enumerator attribute, Enumerator "${change.path}" has different values.` };
73
+ }
74
+ if (change.difference.description !== undefined) {
75
+ await context.editor.enumerations.setEnumeratorDescription(itemKey, change.path, change.difference.description);
76
+ }
77
+ if (change.difference.label !== undefined) {
78
+ await context.editor.enumerations.setEnumeratorLabel(itemKey, change.path, change.difference.label);
79
+ }
80
+ return { itemKey };
81
+ },
82
+ };
54
83
  //# sourceMappingURL=EnumerationMerger.js.map