@itwin/ecschema-editing 4.6.0-dev.7 → 4.6.0-dev.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 (156) 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/Constants.js.map +1 -1
  13. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  14. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  15. package/lib/cjs/Editing/Editor.js.map +1 -1
  16. package/lib/cjs/Editing/Entities.js.map +1 -1
  17. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  18. package/lib/cjs/Editing/Formats.js.map +1 -1
  19. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  20. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  21. package/lib/cjs/Editing/Mixins.js.map +1 -1
  22. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
  23. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  24. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  25. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +1 -0
  26. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts.map +1 -1
  27. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  28. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  29. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +1 -0
  30. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts.map +1 -1
  31. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  32. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  33. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  34. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +2 -0
  35. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts.map +1 -1
  36. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  37. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  38. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts +1 -0
  39. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts.map +1 -1
  40. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  41. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
  42. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  43. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +1 -0
  44. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts.map +1 -1
  45. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  46. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  47. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +2 -0
  48. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts.map +1 -1
  49. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  50. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  51. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +1 -0
  52. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts.map +1 -1
  53. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  54. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  55. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  56. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  57. package/lib/cjs/Editing/SchemaItems.js.map +1 -1
  58. package/lib/cjs/Editing/Structs.js.map +1 -1
  59. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  60. package/lib/cjs/Editing/Units.js.map +1 -1
  61. package/lib/cjs/Merging/CAClassMerger.d.ts +4 -7
  62. package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
  63. package/lib/cjs/Merging/CAClassMerger.js +26 -23
  64. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  65. package/lib/cjs/Merging/ClassMerger.d.ts +10 -18
  66. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  67. package/lib/cjs/Merging/ClassMerger.js +148 -155
  68. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  69. package/lib/cjs/Merging/ConstantMerger.d.ts +4 -8
  70. package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
  71. package/lib/cjs/Merging/ConstantMerger.js +59 -40
  72. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  73. package/lib/cjs/Merging/CustomAttributeMerger.d.ts +16 -13
  74. package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
  75. package/lib/cjs/Merging/CustomAttributeMerger.js +66 -34
  76. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  77. package/lib/cjs/Merging/EntityClassMerger.d.ts +10 -7
  78. package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
  79. package/lib/cjs/Merging/EntityClassMerger.js +41 -29
  80. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  81. package/lib/cjs/Merging/EnumerationMerger.d.ts +9 -9
  82. package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
  83. package/lib/cjs/Merging/EnumerationMerger.js +77 -48
  84. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  85. package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +4 -11
  86. package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
  87. package/lib/cjs/Merging/KindOfQuantityMerger.js +57 -53
  88. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  89. package/lib/cjs/Merging/MixinMerger.d.ts +4 -7
  90. package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
  91. package/lib/cjs/Merging/MixinMerger.js +24 -25
  92. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  93. package/lib/cjs/Merging/PhenomenonMerger.d.ts +8 -0
  94. package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -0
  95. package/lib/cjs/Merging/PhenomenonMerger.js +37 -0
  96. package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -0
  97. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts +8 -0
  98. package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -0
  99. package/lib/cjs/Merging/PropertyCategoryMerger.js +34 -0
  100. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -0
  101. package/lib/cjs/Merging/PropertyMerger.d.ts +6 -14
  102. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
  103. package/lib/cjs/Merging/PropertyMerger.js +212 -287
  104. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  105. package/lib/cjs/Merging/RelationshipClassMerger.d.ts +16 -10
  106. package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
  107. package/lib/cjs/Merging/RelationshipClassMerger.js +121 -112
  108. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
  109. package/lib/cjs/Merging/SchemaItemMerger.d.ts +26 -51
  110. package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
  111. package/lib/cjs/Merging/SchemaItemMerger.js +106 -88
  112. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  113. package/lib/cjs/Merging/SchemaMerger.d.ts +21 -9
  114. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  115. package/lib/cjs/Merging/SchemaMerger.js +74 -88
  116. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  117. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts +5 -5
  118. package/lib/cjs/Merging/SchemaReferenceMerger.d.ts.map +1 -1
  119. package/lib/cjs/Merging/SchemaReferenceMerger.js +33 -15
  120. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  121. package/lib/cjs/Merging/UnitSystemMerger.d.ts +8 -0
  122. package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -0
  123. package/lib/cjs/Merging/UnitSystemMerger.js +26 -0
  124. package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -0
  125. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  126. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  127. package/lib/cjs/Validation/ECRules.d.ts +23 -23
  128. package/lib/cjs/Validation/ECRules.d.ts.map +1 -1
  129. package/lib/cjs/Validation/ECRules.js +1 -1
  130. package/lib/cjs/Validation/ECRules.js.map +1 -1
  131. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  132. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  133. package/lib/cjs/Validation/Rules.js.map +1 -1
  134. package/lib/cjs/Validation/SchemaChanges.js +1 -1
  135. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  136. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  137. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  138. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  139. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  140. package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
  141. package/lib/cjs/Validation/SchemaComparer.js +3 -3
  142. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  143. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  144. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  145. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  146. package/lib/cjs/ecschema-editing.js.map +1 -1
  147. package/package.json +9 -9
  148. package/public/locales/en/ECSchemaEditing.json +26 -26
  149. package/lib/cjs/Merging/SchemaItemFactory.d.ts +0 -15
  150. package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +0 -1
  151. package/lib/cjs/Merging/SchemaItemFactory.js +0 -82
  152. package/lib/cjs/Merging/SchemaItemFactory.js.map +0 -1
  153. package/lib/cjs/Merging/StructClassMerger.d.ts +0 -10
  154. package/lib/cjs/Merging/StructClassMerger.d.ts.map +0 -1
  155. package/lib/cjs/Merging/StructClassMerger.js +0 -13
  156. package/lib/cjs/Merging/StructClassMerger.js.map +0 -1
@@ -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":";;;AAAA;;;+FAG+F;AAC/F,gEAAmH;AAInH,yDAAmF;AAInF;;;;;;;GAOG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAAiC;IACvG,IAAI,MAAM,CAAC,UAAU,KAAK,KAAK,EAAE;QAC/B,IAAI,MAAM,CAAC,UAAU,CAAC,SAAS,KAAK,SAAS,EAAE;YAC7C,OAAO,EAAE,YAAY,EAAE,iDAAiD,EAAE,CAAC;SAC5E;QACD,MAAM,aAAa,GAAG,MAAM,IAAA,sCAAmB,EAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAEtF,MAAM,0BAA0B,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,UAAU,CAAuB,aAAa,CAAC,CAAC;QAC9G,IAAI,0BAA0B,KAAK,SAAS,EAAE;YA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,EAAE,2CAA2C,OAAO,CAAC,IAAI,wBAAwB,EAAE,CAAC;aAC1G;YACD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,KAAK,SAAS;gBAC1C,CAAC,CAAC,iBAAiB,CAAC,MAAM;gBAC1B,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC;YAE7B,OAAO,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,8BAA8B,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;SAC5F;QACD,OAAO,EAAE,CAAC;KACX;SAAM;QACL,OAAO,EAAE,YAAY,EAAE,0DAA0D,EAAE,CAAC;KACrF;AACH,CAAC;AA7CD,oDA6CC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CAAC,OAA2B,EAAE,gBAAmC,EAAE,OAA8B;IAC1I,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;QAC9C,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;QAC7E,IAAI,MAAM,CAAC,YAAY,EAAE;YACvB,OAAO,MAAM,CAAC;SACf;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AARD,sDAQC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,eAAgC,EAAE,OAA8B;IACtI,eAAe,CAAC,SAAS,GAAG,MAAM,IAAA,2CAAwB,EAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC;AAClC,CAAC;AAHD,oDAGC","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 { CustomAttribute, CustomAttributeClass, RelationshipClass, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { type SchemaMergeContext } from \"./SchemaMerger\";\nimport { type CustomAttributeDifference } from \"../Differencing/SchemaDifference\";\nimport { type SchemaEditResults } from \"../Editing/Editor\";\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\n\ntype CustomAttributeSetter = (customAttribute: CustomAttribute) => Promise<SchemaEditResults>;\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 context The current schema merging context.\n * @param change The individual custom attribute change.\n * @returns A EditResults object.\n * @internal\n */\nexport async function mergeCustomAttribute(context: SchemaMergeContext, change: CustomAttributeDifference): Promise<SchemaEditResults> {\n if (change.changeType === \"add\") {\n if (change.difference.className === undefined) {\n return { errorMessage: \"CustomAttribute instance must specify className\" };\n }\n const schemaItemKey = await updateSchemaItemKey(context, change.difference.className);\n\n const targetCustomAttributeClass = await context.targetSchema.lookupItem<CustomAttributeClass>(schemaItemKey);\n if (targetCustomAttributeClass === undefined) {\n return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.` };\n }\n\n const caInstance: CustomAttribute = {\n ...change.difference,\n className: schemaItemKey.fullName,\n };\n\n if (change.appliedTo === \"Schema\") {\n return context.editor.addCustomAttribute(context.targetSchemaKey, caInstance);\n }\n if (change.appliedTo === \"SchemaItem\") {\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n return context.editor.entities.addCustomAttribute(itemKey, caInstance);\n }\n if (change.appliedTo === \"Property\") {\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n const [propertyName] = change.path.split(\".\");\n return context.editor.entities.addCustomAttributeToProperty(itemKey, propertyName, caInstance);\n }\n if (change.appliedTo === \"RelationshipConstraint\") {\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n const relationshipClass = await context.targetSchema.lookupItem<RelationshipClass>(itemKey);\n if (relationshipClass === undefined) {\n return { errorMessage: `Unable to locate the relationship class ${itemKey.name} in the merged schema.` };\n }\n const constraint = change.path === \"$source\"\n ? relationshipClass.source\n : relationshipClass.target;\n\n return context.editor.relationships.addCustomAttributeToConstraint(constraint, caInstance);\n }\n return {};\n } else {\n return { errorMessage: `Changes of Custom Attribute on merge is not implemented.` };\n }\n}\n\n/**\n * @internal\n */\nexport async function applyCustomAttributes(context: SchemaMergeContext, customAttributes: CustomAttribute[], handler: CustomAttributeSetter): Promise<SchemaEditResults> {\n for (const customAttribute of customAttributes) {\n const result = await applyCustomAttribute(context, customAttribute, handler);\n if (result.errorMessage) {\n return result;\n }\n }\n return {};\n}\n\n/**\n * @internal\n */\nexport async function applyCustomAttribute(context: SchemaMergeContext, customAttribute: CustomAttribute, handler: CustomAttributeSetter): Promise<SchemaEditResults> {\n customAttribute.className = await updateSchemaItemFullName(context, customAttribute.className);\n return handler(customAttribute);\n}\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,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D,OAAO,EAAE,CAAC;KACX;SAAM;QACL,OAAO,EAAE,YAAY,EAAE,8BAA8B,MAAM,CAAC,QAAQ,4BAA4B,EAAC,CAAC;KACnG;AACH,CAAC;AAdD,4CAcC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { type EntityClassDifference, EntityClassMixinDifference } from \"../Differencing/SchemaDifference\";\nimport { type SchemaItemMergerHandler, updateSchemaItemKey } from \"./SchemaItemMerger\";\nimport { type MutableEntityClass } from \"../Editing/Mutable/MutableEntityClass\";\nimport { modifyClass } from \"./ClassMerger\";\nimport { SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\n\n/**\n * Defines a merge handler to merge Entity Class schema items.\n * @internal\n */\nexport const entityClassMerger: SchemaItemMergerHandler<EntityClassDifference> = {\n async add(context, change) {\n return context.editor.entities.createFromProps(context.targetSchemaKey, {\n name: change.itemName,\n schemaItemType: change.schemaType,\n\n ...change.difference,\n });\n },\n async modify(context, change, itemKey, item: MutableEntityClass) {\n if(change.difference.mixins !== undefined) {\n for(const mixin of change.difference.mixins) {\n const mixinKey = await updateSchemaItemKey(context, mixin);\n const result = await context.editor.entities.addMixin(itemKey, mixinKey);\n if(result.errorMessage) {\n return result;\n }\n }\n }\n\n return modifyClass(context, change, itemKey, item);\n },\n};\n\n/**\n * Merges Mixins to Entity Class schema items.\n * @internal\n */\nexport async function mergeClassMixins(context: SchemaMergeContext, change: EntityClassMixinDifference): Promise<SchemaItemEditResults> {\n if(change.changeType === \"add\") {\n for(const mixinFullName of change.difference) {\n const mixinKey = await updateSchemaItemKey(context, mixinFullName);\n const entityKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n const result = await context.editor.entities.addMixin(entityKey, mixinKey);\n if(result.errorMessage) {\n throw new Error(result.errorMessage);\n }\n }\n return {};\n } else {\n return { errorMessage: `Changing the entity class '${change.itemName}' mixins is not supported.`};\n }\n}\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
@@ -1 +1 @@
1
- {"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;AAK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AAC,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
+ {"version":3,"file":"EnumerationMerger.js","sourceRoot":"","sources":["../../../src/Merging/EnumerationMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAgF;AAKhF;;;GAGG;AACU,QAAA,iBAAiB,GAAmD;IAC/E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,MAA6B;QAC9C,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE;YACxC,OAAO,EAAE,YAAY,EAAE,0CAA0C,EAA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AC,wBAAwB,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;SACjH;QACD,IAAG,MAAM,CAAC,UAAU,CAAC,KAAK,KAAK,SAAS,EAAE;YACxC,MAAM,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;SACrG;QACD,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { primitiveTypeToString, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport type { EnumerationDifference, EnumeratorDifference } from \"../Differencing/SchemaDifference\";\nimport type { SchemaItemMergerHandler } from \"./SchemaItemMerger\";\nimport type { MutableEnumeration } from \"../Editing/Mutable/MutableEnumeration\";\n\n/**\n * Defines a merge handler to merge Enumeration schema items.\n * @internal\n */\nexport const enumerationMerger: SchemaItemMergerHandler<EnumerationDifference> = {\n async add(context, change: EnumerationDifference) {\n if (change.difference.type === undefined) {\n return { errorMessage: \"Enumerations must define a type property\" };\n }\n if (change.difference.isStrict === undefined) {\n return { errorMessage: \"Enumerations must define whether enumeration is strict.\" };\n }\n if (change.difference.enumerators === undefined) {\n return { errorMessage: \"Enumerations must define at least ine enumerator.\" };\n }\n\n return context.editor.enumerations.createFromProps(context.targetSchemaKey, {\n ...change.difference,\n name: change.itemName,\n schemaItemType: change.schemaType,\n type: change.difference.type,\n isStrict: change.difference.isStrict,\n enumerators: change.difference.enumerators,\n });\n },\n async modify(_context, change, itemKey, item: MutableEnumeration) {\n if(change.difference.type !== undefined) {\n return { errorMessage: `The Enumeration ${itemKey.name} has an incompatible type. It must be \"${primitiveTypeToString(item.type!)}\", not \"${change.difference.type}\".` };\n }\n if(change.difference.label !== undefined) {\n item.setDisplayLabel(change.difference.label);\n }\n if(change.difference.description !== undefined) {\n item.setDescription(change.difference.description);\n }\n if(change.difference.isStrict !== undefined) {\n item.setIsStrict(change.difference.isStrict);\n }\n return { itemKey};\n },\n};\n\n/**\n * Defines a merge handler to merge Enumeration schema items.\n * @internal\n */\nexport const enumeratorMerger: SchemaItemMergerHandler<EnumeratorDifference> = {\n async add(context, change) {\n if (change.difference.name === undefined) {\n return { errorMessage: \"Enumerators must define a name\" };\n }\n if (change.difference.value === undefined) {\n return { errorMessage: \"Enumerators must define a value\" };\n }\n\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\n await context.editor.enumerations.addEnumerator(itemKey, {\n name: change.difference.name,\n value: change.difference.value,\n label: change.difference.label,\n description: change.difference.description,\n });\n\n return { itemKey };\n },\n async modify(context, change, itemKey) {\n if(change.difference.value !== undefined) {\n return { errorMessage: `Failed to merge enumerator attribute, Enumerator \"${change.path}\" has different values.` };\n }\n\n if(change.difference.description !== undefined) {\n await context.editor.enumerations.setEnumeratorDescription(itemKey, change.path, change.difference.description);\n }\n if(change.difference.label !== undefined) {\n await context.editor.enumerations.setEnumeratorLabel(itemKey, change.path, change.difference.label);\n }\n return { itemKey };\n },\n};\n"]}
@@ -1,15 +1,8 @@
1
- import { KindOfQuantity, SchemaItemKey } from "@itwin/ecschema-metadata";
2
- import { PropertyValueResolver, SchemaItemMerger } from "./SchemaItemMerger";
3
- import { KindOfQuantityChanges } from "../Validation/SchemaChanges";
1
+ import { type KindOfQuantityDifference } from "../Differencing/SchemaDifference";
2
+ import { type SchemaItemMergerHandler } from "./SchemaItemMerger";
4
3
  /**
4
+ * Defines a merge handler to merge KindOfQuantity schema items.
5
5
  * @internal
6
6
  */
7
- export default class KindOfQuantityMerger extends SchemaItemMerger<KindOfQuantity> {
8
- protected merge(itemKey: SchemaItemKey, source: KindOfQuantity, changes: KindOfQuantityChanges): Promise<void>;
9
- /**
10
- *
11
- * Creates the property value resolver for [[KindOfQuantity]] items.
12
- */
13
- protected createPropertyValueResolver(): Promise<PropertyValueResolver<KindOfQuantity>>;
14
- }
7
+ export declare const kindOfQuantityMerger: SchemaItemMergerHandler<KindOfQuantityDifference>;
15
8
  //# sourceMappingURL=KindOfQuantityMerger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KindOfQuantityMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/KindOfQuantityMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwB,cAAc,EAA8B,aAAa,EAAQ,MAAM,0BAA0B,CAAC;AACjI,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,gBAAgB,CAAC,cAAc,CAAC;cAEvD,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,qBAAqB;IAmC7G;;;OAGG;cACsB,2BAA2B,IAAI,OAAO,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;CAcvG"}
1
+ {"version":3,"file":"KindOfQuantityMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/KindOfQuantityMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,OAAO,EAAE,KAAK,uBAAuB,EAA4B,MAAM,oBAAoB,CAAC;AAI5F;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,uBAAuB,CAAC,wBAAwB,CA4ClF,CAAC"}