@itwin/ecschema-editing 4.5.0-dev.2 → 4.5.0-dev.20

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 (120) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/Editing/Constants.js.map +1 -1
  4. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  5. package/lib/cjs/Editing/ECClasses.d.ts +9 -2
  6. package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
  7. package/lib/cjs/Editing/ECClasses.js +25 -0
  8. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  9. package/lib/cjs/Editing/Editor.js.map +1 -1
  10. package/lib/cjs/Editing/Entities.d.ts +8 -2
  11. package/lib/cjs/Editing/Entities.d.ts.map +1 -1
  12. package/lib/cjs/Editing/Entities.js +29 -6
  13. package/lib/cjs/Editing/Entities.js.map +1 -1
  14. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  15. package/lib/cjs/Editing/Formats.js.map +1 -1
  16. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  17. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  18. package/lib/cjs/Editing/Mixins.d.ts +8 -1
  19. package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
  20. package/lib/cjs/Editing/Mixins.js +35 -0
  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.js.map +1 -1
  26. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  27. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  28. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  29. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  30. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  31. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  32. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  33. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
  34. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  35. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  36. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  37. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  38. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  39. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  40. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  41. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  42. package/lib/cjs/Editing/RelationshipClasses.d.ts +7 -1
  43. package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
  44. package/lib/cjs/Editing/RelationshipClasses.js +20 -1
  45. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  46. package/lib/cjs/Editing/SchemaItems.js.map +1 -1
  47. package/lib/cjs/Editing/Structs.js.map +1 -1
  48. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  49. package/lib/cjs/Editing/Units.js.map +1 -1
  50. package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
  51. package/lib/cjs/Merging/CAClassMerger.js +1 -5
  52. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  53. package/lib/cjs/Merging/ClassMerger.d.ts +6 -4
  54. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  55. package/lib/cjs/Merging/ClassMerger.js +80 -53
  56. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  57. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  58. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  59. package/lib/cjs/Merging/EntityClassMerger.d.ts +3 -2
  60. package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
  61. package/lib/cjs/Merging/EntityClassMerger.js +22 -7
  62. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  63. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  64. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  65. package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
  66. package/lib/cjs/Merging/MixinMerger.js +1 -5
  67. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  68. package/lib/cjs/Merging/PropertyMerger.d.ts +21 -0
  69. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -0
  70. package/lib/cjs/Merging/PropertyMerger.js +315 -0
  71. package/lib/cjs/Merging/PropertyMerger.js.map +1 -0
  72. package/lib/cjs/Merging/RelationshipClassMerger.d.ts +15 -0
  73. package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -0
  74. package/lib/cjs/Merging/RelationshipClassMerger.js +132 -0
  75. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -0
  76. package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
  77. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  78. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  79. package/lib/cjs/Merging/SchemaMerger.js +16 -7
  80. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  81. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  82. package/lib/cjs/Merging/StructClassMerger.js.map +1 -1
  83. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  84. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  85. package/lib/cjs/Validation/ECRules.js.map +1 -1
  86. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  87. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  88. package/lib/cjs/Validation/Rules.js.map +1 -1
  89. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  90. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  91. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  92. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  93. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  94. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  95. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  96. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  97. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  98. package/lib/cjs/ecschema-editing.js.map +1 -1
  99. package/package.json +9 -9
  100. package/public/locales/en/ECSchemaEditing.json +26 -26
  101. package/lib/cjs/Merging/AnyPropertyMerger.d.ts +0 -15
  102. package/lib/cjs/Merging/AnyPropertyMerger.d.ts.map +0 -1
  103. package/lib/cjs/Merging/AnyPropertyMerger.js +0 -71
  104. package/lib/cjs/Merging/AnyPropertyMerger.js.map +0 -1
  105. package/lib/cjs/Merging/ArrayPropertyMerger.d.ts +0 -32
  106. package/lib/cjs/Merging/ArrayPropertyMerger.d.ts.map +0 -1
  107. package/lib/cjs/Merging/ArrayPropertyMerger.js +0 -143
  108. package/lib/cjs/Merging/ArrayPropertyMerger.js.map +0 -1
  109. package/lib/cjs/Merging/ClassPropertyMerger.d.ts +0 -16
  110. package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +0 -1
  111. package/lib/cjs/Merging/ClassPropertyMerger.js +0 -90
  112. package/lib/cjs/Merging/ClassPropertyMerger.js.map +0 -1
  113. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts +0 -24
  114. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts.map +0 -1
  115. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js +0 -106
  116. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +0 -1
  117. package/lib/cjs/Merging/StructPropertyMerger.d.ts +0 -11
  118. package/lib/cjs/Merging/StructPropertyMerger.d.ts.map +0 -1
  119. package/lib/cjs/Merging/StructPropertyMerger.js +0 -47
  120. package/lib/cjs/Merging/StructPropertyMerger.js.map +0 -1
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPropertyFromProps = exports.mergePropertyAttributeValueChanges = 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");
9
+ async function mergePropertyAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
10
+ if (property.isEnumeration()) {
11
+ return EnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
12
+ }
13
+ if (property.isPrimitive()) {
14
+ return PrimitivePropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
15
+ }
16
+ if (property.isStruct()) {
17
+ return StructPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
18
+ }
19
+ if (property.isNavigation()) {
20
+ return NavigationPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
21
+ }
22
+ return false;
23
+ }
24
+ /**
25
+ * Updates property with attribute value changes.
26
+ * @param context The current merging context.
27
+ * @param property The Property object to be changed.
28
+ * @param propertyValueChanges The changes to be applied to the property.
29
+ * @internal
30
+ */
31
+ async function mergePropertyAttributeValueChanges(context, property, propertyValueChanges) {
32
+ for (const change of propertyValueChanges) {
33
+ const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs;
34
+ const results = await mergePropertyAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
35
+ if (!results) {
36
+ return { errorMessage: `Property ${property.fullName} attribute ${attributeName} change is not implemented.` };
37
+ }
38
+ if (typeof results === "object" && "errorMessage" in results && results.errorMessage !== undefined) {
39
+ return results;
40
+ }
41
+ }
42
+ return { itemKey: property.class.key, propertyName: property.name };
43
+ }
44
+ exports.mergePropertyAttributeValueChanges = mergePropertyAttributeValueChanges;
45
+ /**
46
+ * Creates a Property through a PropertyProps.
47
+ * @param context The current merging context.
48
+ * @param classKey The SchemaItemKey of the class.
49
+ * @param property The Property object to be cloned.
50
+ * @internal
51
+ */
52
+ async function createPropertyFromProps(context, classKey, property) {
53
+ let props = {};
54
+ if (property.category !== undefined) {
55
+ const sourceCategory = await property.category;
56
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(sourceCategory.name, context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)
57
+ ? context.targetSchema.schemaKey
58
+ : sourceCategory.schema.schemaKey);
59
+ const targetCategory = await context.targetSchema.lookupItem(itemKey);
60
+ if (targetCategory === undefined) {
61
+ return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the context schema.` };
62
+ }
63
+ props = { ...props, category: targetCategory.fullName };
64
+ }
65
+ if (property.kindOfQuantity !== undefined) {
66
+ const sourceKoq = await property.kindOfQuantity;
67
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(sourceKoq.name, context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)
68
+ ? context.targetSchema.schemaKey
69
+ : sourceKoq.schema.schemaKey);
70
+ const targetKoq = await context.targetSchema.lookupItem(itemKey);
71
+ if (targetKoq === undefined) {
72
+ return { errorMessage: `Unable to locate the property kind of quantity class ${sourceKoq.name} in the context schema.` };
73
+ }
74
+ props = { ...props, kindOfQuantity: targetKoq.fullName };
75
+ }
76
+ if (property.isEnumeration())
77
+ return EnumPropertyMerger.createFromProps(context, classKey, property, props);
78
+ if (property.isPrimitive())
79
+ return PrimitivePropertyMerger.createFromProps(context, classKey, property, props);
80
+ if (property.isStruct())
81
+ return StructPropertyMerger.createFromProps(context, classKey, property, props);
82
+ if (property.isNavigation())
83
+ return NavigationPropertyMerger.createFromProps(context, classKey, property, props);
84
+ return { errorMessage: `Unsupported Property Type: ${(0, ecschema_metadata_1.propertyTypeToString)(property.propertyType)}` };
85
+ }
86
+ exports.createPropertyFromProps = createPropertyFromProps;
87
+ /**
88
+ * @internal
89
+ */
90
+ var PropertyMerger;
91
+ (function (PropertyMerger) {
92
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, _attributeOldValue) {
93
+ const mutableProperty = property;
94
+ switch (attributeName) {
95
+ case "type":
96
+ return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };
97
+ case "description":
98
+ mutableProperty.setDescription(attributeNewValue);
99
+ return true;
100
+ case "label":
101
+ mutableProperty.setLabel(attributeNewValue);
102
+ return true;
103
+ case "isReadOnly":
104
+ mutableProperty.setIsReadOnly(attributeNewValue);
105
+ return true;
106
+ case "priority":
107
+ mutableProperty.setPriority(attributeNewValue);
108
+ return true;
109
+ case "category":
110
+ const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(attributeNewValue);
111
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(itemName, context.sourceSchema.schemaKey.compareByName(schemaName)
112
+ ? context.targetSchema.schemaKey
113
+ : new ecschema_metadata_1.SchemaKey(schemaName));
114
+ return context.editor.entities.setPropertyCategory(property.class.key, property.name, itemKey);
115
+ case "kindOfQuantity":
116
+ return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };
117
+ }
118
+ return false;
119
+ }
120
+ PropertyMerger.mergeAttributes = mergeAttributes;
121
+ })(PropertyMerger || (PropertyMerger = {}));
122
+ /**
123
+ * @internal
124
+ */
125
+ var ArrayPropertyMerger;
126
+ (function (ArrayPropertyMerger) {
127
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
128
+ const mutableProperty = property;
129
+ switch (attributeName) {
130
+ case "minOccurs":
131
+ mutableProperty.setMinOccurs(attributeNewValue);
132
+ return true;
133
+ case "maxOccurs":
134
+ mutableProperty.setMaxOccurs(attributeNewValue);
135
+ return true;
136
+ }
137
+ return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
138
+ }
139
+ ArrayPropertyMerger.mergeAttributes = mergeAttributes;
140
+ })(ArrayPropertyMerger || (ArrayPropertyMerger = {}));
141
+ /**
142
+ * @internal
143
+ */
144
+ var PrimitiveOrEnumPropertyMerger;
145
+ (function (PrimitiveOrEnumPropertyMerger) {
146
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
147
+ const mutableProperty = property;
148
+ switch (attributeName) {
149
+ case "extendedTypeName": {
150
+ mutableProperty.setExtendedTypeName(attributeNewValue);
151
+ return true;
152
+ }
153
+ case "minLength": {
154
+ mutableProperty.setMinLength(attributeNewValue);
155
+ return true;
156
+ }
157
+ case "maxLength": {
158
+ mutableProperty.setMaxLength(attributeNewValue);
159
+ return true;
160
+ }
161
+ case "minValue": {
162
+ mutableProperty.setMinValue(attributeNewValue);
163
+ return true;
164
+ }
165
+ case "maxValue": {
166
+ mutableProperty.setMaxValue(attributeNewValue);
167
+ return true;
168
+ }
169
+ }
170
+ if (property.isArray()) {
171
+ return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
172
+ }
173
+ return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
174
+ }
175
+ PrimitiveOrEnumPropertyMerger.mergeAttributes = mergeAttributes;
176
+ })(PrimitiveOrEnumPropertyMerger || (PrimitiveOrEnumPropertyMerger = {}));
177
+ /**
178
+ * @internal
179
+ */
180
+ var EnumPropertyMerger;
181
+ (function (EnumPropertyMerger) {
182
+ async function createFromProps(context, classKey, property, props) {
183
+ if (property.enumeration === undefined) {
184
+ return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };
185
+ }
186
+ const enumeration = await property.enumeration;
187
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(enumeration.name, context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)
188
+ ? context.targetSchema.schemaKey
189
+ : enumeration.schema.schemaKey);
190
+ const type = await context.targetSchema.lookupItem(itemKey);
191
+ if (type === undefined) {
192
+ return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the context schema.` };
193
+ }
194
+ const enumProps = {
195
+ ...property.toJSON(),
196
+ ...props,
197
+ typeName: type.fullName,
198
+ };
199
+ if (property.isArray()) {
200
+ return context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, enumProps);
201
+ }
202
+ return context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, enumProps);
203
+ }
204
+ EnumPropertyMerger.createFromProps = createFromProps;
205
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
206
+ switch (attributeName) {
207
+ case "enumeration":
208
+ return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };
209
+ }
210
+ return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
211
+ }
212
+ EnumPropertyMerger.mergeAttributes = mergeAttributes;
213
+ })(EnumPropertyMerger || (EnumPropertyMerger = {}));
214
+ /**
215
+ * @internal
216
+ */
217
+ var PrimitivePropertyMerger;
218
+ (function (PrimitivePropertyMerger) {
219
+ async function createFromProps(context, classKey, property, props) {
220
+ const primitiveProps = {
221
+ ...property.toJSON(),
222
+ ...props,
223
+ };
224
+ if (property.isArray()) {
225
+ return context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);
226
+ }
227
+ return context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);
228
+ }
229
+ PrimitivePropertyMerger.createFromProps = createFromProps;
230
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
231
+ switch (attributeName) {
232
+ case "primitiveType":
233
+ return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };
234
+ }
235
+ return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
236
+ }
237
+ PrimitivePropertyMerger.mergeAttributes = mergeAttributes;
238
+ })(PrimitivePropertyMerger || (PrimitivePropertyMerger = {}));
239
+ /**
240
+ * @internal
241
+ */
242
+ var StructPropertyMerger;
243
+ (function (StructPropertyMerger) {
244
+ async function createFromProps(context, classKey, property, props) {
245
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(property.structClass.name, context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)
246
+ ? context.targetSchema.schemaKey
247
+ : property.structClass.schema.schemaKey);
248
+ const type = await context.targetSchema.lookupItem(itemKey);
249
+ if (type === undefined) {
250
+ return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the context schema.` };
251
+ }
252
+ const structProps = {
253
+ ...property.toJSON(),
254
+ ...props,
255
+ typeName: type.fullName,
256
+ };
257
+ if (property.isArray()) {
258
+ return context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, structProps);
259
+ }
260
+ return context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, structProps);
261
+ }
262
+ StructPropertyMerger.createFromProps = createFromProps;
263
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
264
+ switch (attributeName) {
265
+ case "structClass":
266
+ return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };
267
+ }
268
+ if (property.isArray()) {
269
+ return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
270
+ }
271
+ return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
272
+ }
273
+ StructPropertyMerger.mergeAttributes = mergeAttributes;
274
+ })(StructPropertyMerger || (StructPropertyMerger = {}));
275
+ /**
276
+ * @internal
277
+ */
278
+ var NavigationPropertyMerger;
279
+ (function (NavigationPropertyMerger) {
280
+ async function createFromProps(context, classKey, property, props) {
281
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(property.relationshipClass.name, context.sourceSchema.schemaKey.matches(property.relationshipClass.schemaKey)
282
+ ? context.targetSchema.schemaKey
283
+ : property.relationshipClass.schemaKey);
284
+ const type = await context.targetSchema.lookupItem(itemKey);
285
+ if (type === undefined) {
286
+ return { errorMessage: `Unable to locate the relationship class ${property.relationshipClass.name} in the context schema.` };
287
+ }
288
+ const navigationProps = {
289
+ ...property.toJSON(),
290
+ ...props,
291
+ relationshipName: type.fullName,
292
+ };
293
+ if (property.class.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass)
294
+ return context.editor.entities.createNavigationPropertyFromProps(classKey, navigationProps);
295
+ if (property.class.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin)
296
+ return context.editor.mixins.createNavigationPropertyFromProps(classKey, navigationProps);
297
+ if (property.class.schemaItemType === ecschema_metadata_1.SchemaItemType.RelationshipClass)
298
+ return context.editor.relationships.createNavigationPropertyFromProps(classKey, navigationProps);
299
+ return { errorMessage: `Navigation property can't be added to ${(0, ecschema_metadata_1.schemaItemTypeToString)(property.class.schemaItemType)}.` };
300
+ }
301
+ NavigationPropertyMerger.createFromProps = createFromProps;
302
+ async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
303
+ switch (attributeName) {
304
+ case "direction": {
305
+ return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };
306
+ }
307
+ case "relationshipClass": {
308
+ return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };
309
+ }
310
+ }
311
+ return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
312
+ }
313
+ NavigationPropertyMerger.mergeAttributes = mergeAttributes;
314
+ })(NavigationPropertyMerger || (NavigationPropertyMerger = {}));
315
+ //# sourceMappingURL=PropertyMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA8V;AAQ9V,KAAK,UA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C,KAAK,CAAC,cAAc,KAAK,kCAAc,CAAC,iBAAiB;YACpE,OAAO,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,iCAAiC,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;QACnG,OAAO,EAAE,YAAY,EAAE,yCAAyC,IAAA,0CAAsB,EAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IAC7H,CAAC;IAvBqB,wCAAe,kBAuBpC,CAAA;IAEM,KAAK,UAAU,eAAe,CAAC,OAA2B,EAAE,QAA4B,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACpK,QAAQ,aAAa,EAAE;YACrB,KAAK,WAAW,CAAC,CAAC;gBAChB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,QAAQ,+BAA+B,EAAE,CAAC;aACrG;YACD,KAAK,mBAAmB,CAAC,CAAC;gBACxB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,QAAQ,wCAAwC,EAAE,CAAC;aAC9G;SACF;QACD,OAAO,cAAc,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;IAChH,CAAC;IAVqB,wCAAe,kBAUpC,CAAA;AACH,CAAC,EArCS,wBAAwB,KAAxB,wBAAwB,QAqCjC","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 { AnyArrayProperty, AnyEnumerationProperty, AnyPrimitiveProperty, AnyStructProperty, Enumeration, KindOfQuantity, NavigationProperty, Property, PropertyCategory, PropertyProps, propertyTypeToString, RelationshipClass, SchemaItem, SchemaItemKey, SchemaItemType, schemaItemTypeToString, SchemaKey, StructClass } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { PropertyEditResults } from \"../Editing/Editor\";\r\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\r\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\r\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\r\nimport { PropertyValueChange } from \"../Validation/SchemaChanges\";\r\n\r\nasync function mergePropertyAttributes(context: SchemaMergeContext, property: Property, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n if (property.isEnumeration()) {\r\n return EnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n if (property.isPrimitive()) {\r\n return PrimitivePropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n if (property.isStruct()) {\r\n return StructPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n if (property.isNavigation()) {\r\n return NavigationPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Updates property with attribute value changes.\r\n * @param context The current merging context.\r\n * @param property The Property object to be changed.\r\n * @param propertyValueChanges The changes to be applied to the property.\r\n * @internal\r\n */\r\nexport async function mergePropertyAttributeValueChanges(context: SchemaMergeContext, property: Property, propertyValueChanges: PropertyValueChange[]): Promise<PropertyEditResults> {\r\n for (const change of propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\r\n const results = await mergePropertyAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n if (!results) {\r\n return { errorMessage: `Property ${property.fullName} attribute ${attributeName} change is not implemented.` };\r\n }\r\n if (typeof results === \"object\" && \"errorMessage\" in results && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n }\r\n return { itemKey: property.class.key, propertyName: property.name };\r\n}\r\n\r\n/**\r\n * Creates a Property through a PropertyProps.\r\n * @param context The current merging context.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param property The Property object to be cloned.\r\n * @internal\r\n */\r\nexport async function createPropertyFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: Property): Promise<PropertyEditResults> {\r\n let props = {} as PropertyProps;\r\n\r\n if (property.category !== undefined) {\r\n const sourceCategory = await property.category;\r\n const itemKey = new SchemaItemKey(sourceCategory.name, context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)\r\n ? context.targetSchema.schemaKey\r\n : sourceCategory.schema.schemaKey,\r\n );\r\n const targetCategory = await context.targetSchema.lookupItem<PropertyCategory>(itemKey);\r\n if (targetCategory === undefined) {\r\n return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the context schema.` };\r\n }\r\n props = {...props, category: targetCategory.fullName};\r\n }\r\n\r\n if (property.kindOfQuantity !== undefined) {\r\n const sourceKoq = await property.kindOfQuantity;\r\n const itemKey = new SchemaItemKey(sourceKoq.name, context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)\r\n ? context.targetSchema.schemaKey\r\n : sourceKoq.schema.schemaKey,\r\n );\r\n const targetKoq = await context.targetSchema.lookupItem<KindOfQuantity>(itemKey);\r\n if (targetKoq === undefined) {\r\n return { errorMessage: `Unable to locate the property kind of quantity class ${sourceKoq.name} in the context schema.` };\r\n }\r\n props = {...props, kindOfQuantity: targetKoq.fullName};\r\n }\r\n if (property.isEnumeration())\r\n return EnumPropertyMerger.createFromProps(context, classKey, property, props);\r\n if (property.isPrimitive())\r\n return PrimitivePropertyMerger.createFromProps(context, classKey, property, props);\r\n if (property.isStruct())\r\n return StructPropertyMerger.createFromProps(context, classKey, property, props);\r\n if (property.isNavigation())\r\n return NavigationPropertyMerger.createFromProps(context, classKey, property, props);\r\n\r\n return { errorMessage: `Unsupported Property Type: ${propertyTypeToString(property.propertyType)}` };\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace PropertyMerger {\r\n export async function mergeAttributes(context: SchemaMergeContext, property: Property, attributeName: string, attributeNewValue: any, _attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const mutableProperty = property as unknown as MutableProperty;\r\n switch(attributeName) {\r\n case \"type\":\r\n return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };\r\n case \"description\":\r\n mutableProperty.setDescription(attributeNewValue);\r\n return true;\r\n case \"label\":\r\n mutableProperty.setLabel(attributeNewValue);\r\n return true;\r\n case \"isReadOnly\":\r\n mutableProperty.setIsReadOnly(attributeNewValue);\r\n return true;\r\n case \"priority\":\r\n mutableProperty.setPriority(attributeNewValue);\r\n return true;\r\n case \"category\":\r\n const [schemaName, itemName] = SchemaItem.parseFullName(attributeNewValue);\r\n const itemKey = new SchemaItemKey(itemName, context.sourceSchema.schemaKey.compareByName(schemaName)\r\n ? context.targetSchema.schemaKey\r\n : new SchemaKey(schemaName),\r\n );\r\n return context.editor.entities.setPropertyCategory(property.class.key, property.name, itemKey);\r\n case \"kindOfQuantity\":\r\n return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };\r\n }\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace ArrayPropertyMerger {\r\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const mutableProperty = property as unknown as MutableArrayProperty;\r\n switch (attributeName) {\r\n case \"minOccurs\":\r\n mutableProperty.setMinOccurs(attributeNewValue);\r\n return true;\r\n\r\n case \"maxOccurs\":\r\n mutableProperty.setMaxOccurs(attributeNewValue);\r\n return true;\r\n }\r\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace PrimitiveOrEnumPropertyMerger {\r\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyPrimitiveProperty | AnyEnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n const mutableProperty = property as unknown as MutablePrimitiveOrEnumPropertyBase;\r\n switch (attributeName) {\r\n case \"extendedTypeName\": {\r\n mutableProperty.setExtendedTypeName(attributeNewValue);\r\n return true;\r\n }\r\n case \"minLength\": {\r\n mutableProperty.setMinLength(attributeNewValue);\r\n return true;\r\n }\r\n case \"maxLength\": {\r\n mutableProperty.setMaxLength(attributeNewValue);\r\n return true;\r\n }\r\n case \"minValue\": {\r\n mutableProperty.setMinValue(attributeNewValue);\r\n return true;\r\n }\r\n case \"maxValue\": {\r\n mutableProperty.setMaxValue(attributeNewValue);\r\n return true;\r\n }\r\n }\r\n if (property.isArray()) {\r\n return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace EnumPropertyMerger {\r\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: AnyEnumerationProperty, props: PropertyProps): Promise<PropertyEditResults> {\r\n if (property.enumeration === undefined) {\r\n return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };\r\n }\r\n\r\n const enumeration = await property.enumeration;\r\n const itemKey = new SchemaItemKey(enumeration.name, context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\r\n ? context.targetSchema.schemaKey\r\n : enumeration.schema.schemaKey,\r\n );\r\n const type = await context.targetSchema.lookupItem<Enumeration>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the context schema.` };\r\n }\r\n\r\n const enumProps = {\r\n ...property.toJSON(),\r\n ...props,\r\n typeName: type.fullName,\r\n };\r\n\r\n if (property.isArray()) {\r\n return context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, enumProps);\r\n }\r\n return context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, enumProps);\r\n }\r\n\r\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyEnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n switch (attributeName) {\r\n case \"enumeration\":\r\n return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };\r\n }\r\n return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace PrimitivePropertyMerger {\r\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: AnyPrimitiveProperty, props: PropertyProps): Promise<PropertyEditResults> {\r\n const primitiveProps = {\r\n ...property.toJSON(),\r\n ...props,\r\n };\r\n\r\n if (property.isArray()) {\r\n return context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);\r\n }\r\n return context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);\r\n }\r\n\r\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyPrimitiveProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n switch (attributeName) {\r\n case \"primitiveType\":\r\n return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };\r\n }\r\n return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace StructPropertyMerger {\r\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: AnyStructProperty, props: PropertyProps): Promise<PropertyEditResults> {\r\n const itemKey = new SchemaItemKey(property.structClass.name, context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\r\n ? context.targetSchema.schemaKey\r\n : property.structClass.schema.schemaKey,\r\n );\r\n const type = await context.targetSchema.lookupItem<StructClass>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the context schema.` };\r\n }\r\n\r\n const structProps = {\r\n ...property.toJSON(),\r\n ...props,\r\n typeName: type.fullName,\r\n };\r\n\r\n if (property.isArray()) {\r\n return context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, structProps);\r\n }\r\n return context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, structProps);\r\n }\r\n\r\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyStructProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n switch (attributeName) {\r\n case \"structClass\":\r\n return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };\r\n }\r\n if (property.isArray()) {\r\n return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nnamespace NavigationPropertyMerger {\r\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: NavigationProperty, props: PropertyProps): Promise<PropertyEditResults> {\r\n const itemKey = new SchemaItemKey(property.relationshipClass.name, context.sourceSchema.schemaKey.matches(property.relationshipClass.schemaKey)\r\n ? context.targetSchema.schemaKey\r\n : property.relationshipClass.schemaKey,\r\n );\r\n const type = await context.targetSchema.lookupItem<RelationshipClass>(itemKey);\r\n if (type === undefined) {\r\n return { errorMessage: `Unable to locate the relationship class ${property.relationshipClass.name} in the context schema.` };\r\n }\r\n\r\n const navigationProps = {\r\n ...property.toJSON(),\r\n ...props,\r\n relationshipName: type.fullName,\r\n };\r\n\r\n if (property.class.schemaItemType === SchemaItemType.EntityClass)\r\n return context.editor.entities.createNavigationPropertyFromProps(classKey, navigationProps);\r\n if (property.class.schemaItemType === SchemaItemType.Mixin)\r\n return context.editor.mixins.createNavigationPropertyFromProps(classKey, navigationProps);\r\n if (property.class.schemaItemType === SchemaItemType.RelationshipClass)\r\n return context.editor.relationships.createNavigationPropertyFromProps(classKey, navigationProps);\r\n return { errorMessage: `Navigation property can't be added to ${schemaItemTypeToString(property.class.schemaItemType)}.` };\r\n }\r\n\r\n export async function mergeAttributes(context: SchemaMergeContext, property: NavigationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\r\n switch (attributeName) {\r\n case \"direction\": {\r\n return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };\r\n }\r\n case \"relationshipClass\": {\r\n return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };\r\n }\r\n }\r\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,15 @@
1
+ import { RelationshipClass, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
2
+ import { ClassMerger } from "./ClassMerger";
3
+ import { SchemaItemEditResults } from "../Editing/Editor";
4
+ import { ClassChanges } from "../Validation/SchemaChanges";
5
+ /**
6
+ * @internal
7
+ */
8
+ export default class RelationshipClassMerger extends ClassMerger<RelationshipClass> {
9
+ protected create(schemaKey: SchemaKey, ecClass: RelationshipClass): Promise<SchemaItemEditResults>;
10
+ protected mergeAttributes(ecClass: RelationshipClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean>;
11
+ private mergeConstraintAttributes;
12
+ private mergeConstraintChanges;
13
+ protected merge(itemKey: SchemaItemKey, changes: ClassChanges): Promise<SchemaItemEditResults>;
14
+ }
15
+ //# sourceMappingURL=RelationshipClassMerger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationshipClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAA6D,iBAAiB,EAAgE,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAChN,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAiC,MAAM,6BAA6B,CAAC;AAK1F;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;cAExD,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAIxF,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,GAAG,OAAO,CAAC;YA4BvK,yBAAyB;YAqCzB,sBAAsB;cAwCX,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAyB9G"}
@@ -0,0 +1,132 @@
1
+ "use strict";
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");
8
+ const ClassMerger_1 = require("./ClassMerger");
9
+ const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
10
+ /**
11
+ * @internal
12
+ */
13
+ class RelationshipClassMerger extends ClassMerger_1.ClassMerger {
14
+ async create(schemaKey, ecClass) {
15
+ return this.context.editor.relationships.create(schemaKey, ecClass.name, ecClass.modifier, ecClass.strength, ecClass.strengthDirection);
16
+ }
17
+ async mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue) {
18
+ const mutableRelationship = ecClass;
19
+ switch (attributeName) {
20
+ case "strength":
21
+ if (attributeOldValue === undefined) {
22
+ const strength = (0, ecschema_metadata_1.parseStrength)(attributeNewValue);
23
+ if (strength === undefined) {
24
+ return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strength value '${attributeNewValue}' has been provided.` };
25
+ }
26
+ mutableRelationship.setStrength(strength);
27
+ return true;
28
+ }
29
+ return { errorMessage: `Changing the relationship '${ecClass.name}' strength is not supported.` };
30
+ case "strengthDirection":
31
+ if (attributeOldValue === undefined) {
32
+ const strengthDirection = (0, ecschema_metadata_1.parseStrengthDirection)(attributeNewValue);
33
+ if (strengthDirection === undefined) {
34
+ return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strengthDirection value '${attributeNewValue}' has been provided.` };
35
+ }
36
+ mutableRelationship.setStrengthDirection(strengthDirection);
37
+ return true;
38
+ }
39
+ return { errorMessage: `Changing the relationship '${ecClass.name}' strengthDirection is not supported.` };
40
+ }
41
+ return super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);
42
+ }
43
+ async mergeConstraintAttributes(constraint, attributeName, attributeNewValue, attributeOldValue) {
44
+ switch (attributeName) {
45
+ case "multiplicity":
46
+ if (attributeOldValue === undefined) {
47
+ const multiplicity = ecschema_metadata_1.RelationshipMultiplicity.fromString(attributeNewValue);
48
+ if (multiplicity === undefined) {
49
+ return { errorMessage: `An invalid relationship constraint multiplicity value '${attributeNewValue}' has been provided.` };
50
+ }
51
+ return this.context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);
52
+ }
53
+ return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.` };
54
+ case "polymorphic":
55
+ if (attributeOldValue === undefined || attributeNewValue === true) {
56
+ return this.context.editor.relationships.setConstraintPolymorphic(constraint, attributeNewValue);
57
+ }
58
+ return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' polymorphic is not supported.` };
59
+ case "roleLabel":
60
+ constraint.roleLabel = attributeNewValue;
61
+ return true;
62
+ case "abstractConstraint":
63
+ const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(attributeNewValue);
64
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(itemName, this.context.sourceSchema.schemaKey.compareByName(schemaName)
65
+ ? this.context.targetSchema.schemaKey
66
+ : new ecschema_metadata_1.SchemaKey(schemaName));
67
+ const abstractConstraint = await this.context.targetSchema.lookupItem(itemKey);
68
+ if (abstractConstraint === undefined) {
69
+ return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the abstract constraint class ${attributeNewValue} in the context schema.` };
70
+ }
71
+ return this.context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);
72
+ }
73
+ return false;
74
+ }
75
+ async mergeConstraintChanges(constraint, constraintChanges) {
76
+ for (const change of constraintChanges) {
77
+ for (const constraintClassChange of change.constraintClassChanges) {
78
+ const ecClass = constraintClassChange.diagnostic.messageArgs[0];
79
+ const itemKey = new ecschema_metadata_1.SchemaItemKey(ecClass.name, this.context.sourceSchema.schemaKey.matches(ecClass.schema.schemaKey)
80
+ ? this.context.targetSchema.schemaKey
81
+ : ecClass.schema.schemaKey);
82
+ const constaintClass = await this.context.targetSchema.lookupItem(itemKey);
83
+ if (constaintClass === undefined) {
84
+ return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the constraint class ${itemKey.fullName} in the context schema.` };
85
+ }
86
+ const results = await this.context.editor.relationships.addConstraintClass(constraint, constaintClass);
87
+ if (results.errorMessage !== undefined) {
88
+ return results;
89
+ }
90
+ }
91
+ for (const propertyValueChange of change.propertyValueChanges) {
92
+ const [attributeName, attributeNewValue, attributeOldValue] = propertyValueChange.diagnostic.messageArgs;
93
+ const results = await this.mergeConstraintAttributes(constraint, attributeName, attributeNewValue, attributeOldValue);
94
+ if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {
95
+ return results;
96
+ }
97
+ }
98
+ if (change.customAttributeChanges.size > 0) {
99
+ const results = await (0, CustomAttributeMerger_1.mergeCustomAttributes)(this.context, change.customAttributeChanges.values(), async (ca) => {
100
+ return this.context.editor.relationships.addCustomAttributeToConstraint(constraint, ca);
101
+ });
102
+ if (results.errorMessage !== undefined) {
103
+ return results;
104
+ }
105
+ }
106
+ }
107
+ return { itemKey: constraint.relationshipClass.key };
108
+ }
109
+ async merge(itemKey, changes) {
110
+ if (changes.sourceConstraintChanges.size > 0 || changes.targetConstraintChanges.size > 0) {
111
+ const relationshipClass = await this.context.targetSchema.lookupItem(itemKey);
112
+ if (relationshipClass === undefined) {
113
+ return { itemKey, errorMessage: `Unable to locate the relationship class ${itemKey.name} in the context schema.` };
114
+ }
115
+ if (changes.sourceConstraintChanges.size > 0) {
116
+ const result = await this.mergeConstraintChanges(relationshipClass.source, changes.sourceConstraintChanges.values());
117
+ if (result.errorMessage !== undefined) {
118
+ return result;
119
+ }
120
+ }
121
+ if (changes.targetConstraintChanges.size > 0) {
122
+ const result = await this.mergeConstraintChanges(relationshipClass.target, changes.targetConstraintChanges.values());
123
+ if (result.errorMessage !== undefined) {
124
+ return result;
125
+ }
126
+ }
127
+ }
128
+ return { itemKey };
129
+ }
130
+ }
131
+ exports.default = RelationshipClassMerger;
132
+ //# sourceMappingURL=RelationshipClassMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelationshipClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAgN;AAChN,+CAA4C;AAK5C,mEAAgE;AAEhE;;GAEG;AACH,MAAqB,uBAAwB,SAAQ,yBAA8B;IAE9D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAA0B;QAC9E,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1I,CAAC;IAEkB,KAAK,CAAC,eAAe,CAAC,OAA0B,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MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAoB,OAAO,CAAC,CAAC;YACjG,IAAI,iBAAiB,KAAK,SAAS,EAAE;gBACnC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,2CAA2C,OAAO,CAAC,IAAI,yBAAyB,EAAE,CAAC;aACpH;YAED,IAAI,OAAO,CAAC,uBAAuB,CAAC,IAAI,GAAG,CAAC,EAAE;gBAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC;gBACrH,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE;oBACrC,OAAO,MAAM,CAAC;iBACf;aACF;YAED,IAAI,OAAO,CAAC,uBAAuB,CAAC,IAAI,GAAG,CAAC,EAAE;gBAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC;gBACrH,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE;oBACrC,OAAO,MAAM,CAAC;iBACf;aACF;SACF;QAED,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF;AAxID,0CAwIC","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, parseStrength, parseStrengthDirection, RelationshipClass, RelationshipConstraint, RelationshipMultiplicity, SchemaItem, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { ClassMerger } from \"./ClassMerger\";\r\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { ClassChanges, RelationshipConstraintChanges } from \"../Validation/SchemaChanges\";\r\nimport { MutableRelationshipClass } from \"@itwin/ecschema-metadata/src/Metadata/RelationshipClass\";\r\nimport { MutableRelationshipConstraint } from \"../Editing/Mutable/MutableRelationshipClass\";\r\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport default class RelationshipClassMerger extends ClassMerger<RelationshipClass> {\r\n\r\n protected override async create(schemaKey: SchemaKey, ecClass: RelationshipClass): Promise<SchemaItemEditResults> {\r\n return this.context.editor.relationships.create(schemaKey, ecClass.name, ecClass.modifier, ecClass.strength, ecClass.strengthDirection);\r\n }\r\n\r\n protected override async mergeAttributes(ecClass: RelationshipClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n const mutableRelationship = ecClass as unknown as MutableRelationshipClass;\r\n switch(attributeName) {\r\n case \"strength\":\r\n if (attributeOldValue === undefined) {\r\n const strength = parseStrength(attributeNewValue);\r\n if (strength === undefined) {\r\n return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strength value '${attributeNewValue}' has been provided.` };\r\n }\r\n mutableRelationship.setStrength(strength);\r\n return true;\r\n }\r\n return { errorMessage: `Changing the relationship '${ecClass.name}' strength is not supported.` };\r\n\r\n case \"strengthDirection\":\r\n if (attributeOldValue === undefined) {\r\n const strengthDirection = parseStrengthDirection(attributeNewValue);\r\n if (strengthDirection === undefined) {\r\n return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strengthDirection value '${attributeNewValue}' has been provided.` };\r\n }\r\n mutableRelationship.setStrengthDirection(strengthDirection);\r\n return true;\r\n }\r\n return { errorMessage: `Changing the relationship '${ecClass.name}' strengthDirection is not supported.` };\r\n }\r\n return super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);\r\n }\r\n\r\n private async mergeConstraintAttributes(constraint: RelationshipConstraint, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\r\n switch(attributeName) {\r\n case \"multiplicity\":\r\n if (attributeOldValue === undefined) {\r\n const multiplicity = RelationshipMultiplicity.fromString(attributeNewValue);\r\n if (multiplicity === undefined) {\r\n return { errorMessage: `An invalid relationship constraint multiplicity value '${attributeNewValue}' has been provided.` };\r\n }\r\n return this.context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);\r\n }\r\n return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.` };\r\n\r\n case \"polymorphic\":\r\n if (attributeOldValue === undefined || attributeNewValue === true) {\r\n return this.context.editor.relationships.setConstraintPolymorphic(constraint, attributeNewValue);\r\n }\r\n return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' polymorphic is not supported.` };\r\n\r\n case \"roleLabel\":\r\n (constraint as MutableRelationshipConstraint).roleLabel = attributeNewValue;\r\n return true;\r\n\r\n case \"abstractConstraint\":\r\n const [schemaName, itemName] = SchemaItem.parseFullName(attributeNewValue);\r\n const itemKey = new SchemaItemKey(itemName, this.context.sourceSchema.schemaKey.compareByName(schemaName)\r\n ? this.context.targetSchema.schemaKey\r\n : new SchemaKey(schemaName));\r\n\r\n const abstractConstraint = await this.context.targetSchema.lookupItem<Mixin | EntityClass | RelationshipClass>(itemKey);\r\n if (abstractConstraint === undefined) {\r\n return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the abstract constraint class ${attributeNewValue} in the context schema.`};\r\n }\r\n return this.context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);\r\n }\r\n return false;\r\n }\r\n\r\n private async mergeConstraintChanges(constraint: RelationshipConstraint, constraintChanges: IterableIterator<RelationshipConstraintChanges>): Promise<SchemaItemEditResults> {\r\n for (const change of constraintChanges) {\r\n\r\n for (const constraintClassChange of change.constraintClassChanges) {\r\n const ecClass = constraintClassChange.diagnostic.messageArgs![0];\r\n const itemKey = new SchemaItemKey(ecClass.name, this.context.sourceSchema.schemaKey.matches(ecClass.schema.schemaKey)\r\n ? this.context.targetSchema.schemaKey\r\n : ecClass.schema.schemaKey);\r\n\r\n const constaintClass = await this.context.targetSchema.lookupItem<Mixin | EntityClass | RelationshipClass>(itemKey);\r\n if (constaintClass === undefined) {\r\n return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the constraint class ${itemKey.fullName} in the context schema.` };\r\n }\r\n const results = await this.context.editor.relationships.addConstraintClass(constraint, constaintClass);\r\n if (results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n }\r\n\r\n for (const propertyValueChange of change.propertyValueChanges) {\r\n const [attributeName, attributeNewValue, attributeOldValue] = propertyValueChange.diagnostic.messageArgs!;\r\n const results = await this.mergeConstraintAttributes(constraint, attributeName, attributeNewValue, attributeOldValue);\r\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n }\r\n\r\n if (change.customAttributeChanges.size > 0) {\r\n const results = await mergeCustomAttributes(this.context, change.customAttributeChanges.values(), async (ca) => {\r\n return this.context.editor.relationships.addCustomAttributeToConstraint(constraint, ca);\r\n });\r\n if (results.errorMessage !== undefined) {\r\n return results;\r\n }\r\n }\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n protected override async merge(itemKey: SchemaItemKey, changes: ClassChanges): Promise<SchemaItemEditResults> {\r\n if (changes.sourceConstraintChanges.size > 0 || changes.targetConstraintChanges.size > 0) {\r\n\r\n const relationshipClass = await this.context.targetSchema.lookupItem<RelationshipClass>(itemKey);\r\n if (relationshipClass === undefined) {\r\n return { itemKey, errorMessage: `Unable to locate the relationship class ${itemKey.name} in the context schema.` };\r\n }\r\n\r\n if (changes.sourceConstraintChanges.size > 0) {\r\n const result = await this.mergeConstraintChanges(relationshipClass.source, changes.sourceConstraintChanges.values());\r\n if (result.errorMessage !== undefined) {\r\n return result;\r\n }\r\n }\r\n\r\n if (changes.targetConstraintChanges.size > 0) {\r\n const result = await this.mergeConstraintChanges(relationshipClass.target, changes.targetConstraintChanges.values());\r\n if (result.errorMessage !== undefined) {\r\n return result;\r\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AAQ,EAAE,kCAAc,CAAC,EAAE;YAChC,IAAG,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE;gBACzC,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,CAAC,IAAI,iCAAiC,CAAC,CAAC;aAC3F;YACD,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC;YACvD,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC;gBAC3E,CAAC,CAAC,IAAI,iCAAa,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC;gBAC1D,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC;YACxB,OAAO,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;SAChF;QACD,IAAI,EAAE,CAAC,QAAQ,EAAE,8BAAU,CAAC;YAC1B,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEnE,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACH,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EAxEgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAwEjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Constant, CustomAttributeClass, EntityClass, Enumeration, KindOfQuantity, Phenomenon, PrimitiveType, PropertyCategory, SchemaItem, SchemaItemKey, SchemaKey, StructClass, UnitSystem } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor, SchemaItemEditResults } from \"../Editing/Editor\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * @internal\n */\nexport namespace SchemaItemFactory {\n\n /**\n * Creates a new Schema Item based on the given template instance.\n * @param context The current merging context.\n * @param template The Schema Items Template\n * @returns The SchemaItemKey of the created item.\n */\n export async function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey> {\n const result = await createItem(context.editor, context.targetSchema.schemaKey, template);\n if(result.errorMessage) {\n throw new Error(result.errorMessage);\n }\n return result.itemKey!;\n }\n\n /**\n * Creates a new Schema Item in the SchemaContextEditor.\n * @param editor The SchemaContextEditor\n * @param targetSchemaKey The key of the target schema the item shall be created in.\n * @param template The Schema Items Template\n * @returns A SchemaItemEditResults with a schema key if the item could be created.\n */\n async function createItem(editor: SchemaContextEditor, targetSchemaKey: SchemaKey, template: SchemaItem): Promise<SchemaItemEditResults> {\n if (is(template, Enumeration))\n return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? PrimitiveType.Integer : PrimitiveType.String, template.label, template.isStrict);\n if (is(template, EntityClass))\n return editor.entities.create(targetSchemaKey, template.name, template.modifier);\n if (is(template, StructClass))\n return editor.structs.create(targetSchemaKey, template.name);\n if (is(template, CustomAttributeClass))\n return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);\n if(is(template, PropertyCategory))\n return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);\n if (is(template, Phenomenon))\n return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);\n if (is(template, Constant)) {\n if(template.phenomenon === undefined) {\n throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);\n }\n const phenomenon = await template.phenomenon;\n const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)\n ? new SchemaItemKey(phenomenon.name, targetSchemaKey)\n : phenomenon.key;\n\n return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);\n }\n if (is(template, KindOfQuantity)) {\n if(template.persistenceUnit === undefined) {\n throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);\n }\n const persistenceUnit = await template.persistenceUnit;\n const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)\n ? new SchemaItemKey(persistenceUnit.name, targetSchemaKey)\n : persistenceUnit.key;\n return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);\n }\n if (is(template, UnitSystem))\n return editor.unitSystems.create(targetSchemaKey, template.name);\n\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\n }\n\n /**\n * Type Guard to \"cast\" a given schema item into an implementation\n * @param item Item to be checked\n * @param type The desired implementation.\n * @returns true if the item could be casted, otherwise false.\n */\n function is<T extends SchemaItem>(item: SchemaItem, type: new (...args: any) => T ): item is T {\n return item instanceof type;\n }\n}\n"]}
1
+ {"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAgO;AAIhO;;GAEG;AACH,IAAiB,iBAAiB,CAwEjC;AAxED,WAAiB,iBAAiB;IAEhC;;;;;OAKG;IACI,KAAK,UAAU,MAAM,CAAC,OAA2B,EAAE,QAAoB;QAC5E,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC1F,IAAG,MAAM,CAAC,YAAY,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SACtC;QACD,OAAO,MAAM,CAAC,OAAQ,CAAC;IACzB,CAAC;IANqB,wBAAM,SAM3B,CAAA;IAED;;;;;;OAMG;IACH,KAAK,UAAU,UAAU,CAAC,MAA2B,EAAE,eAA0B,EAAE,QAAoB;QACrG,IAAI,EAAE,CAAC,QAAQ,EAAE,+BAAW,CAAC;YAC3B,OAAO,MAAM,CAAC,YAAY,C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C,CAAC;IAChF,CAAC;IAED;;;;;OAKG;IACH,SAAS,EAAE,CAAuB,IAAgB,EAAE,IAA6B;QAC/E,OAAO,IAAI,YAAY,IAAI,CAAC;IAC9B,CAAC;AACH,CAAC,EAxEgB,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAwEjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { Constant, CustomAttributeClass, EntityClass, Enumeration, KindOfQuantity, Phenomenon, PrimitiveType, PropertyCategory, SchemaItem, SchemaItemKey, SchemaKey, StructClass, UnitSystem } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"../Editing/Editor\";\r\nimport { SchemaMergeContext } from \"./SchemaMerger\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport namespace SchemaItemFactory {\r\n\r\n /**\r\n * Creates a new Schema Item based on the given template instance.\r\n * @param context The current merging context.\r\n * @param template The Schema Items Template\r\n * @returns The SchemaItemKey of the created item.\r\n */\r\n export async function create(context: SchemaMergeContext, template: SchemaItem): Promise<SchemaItemKey> {\r\n const result = await createItem(context.editor, context.targetSchema.schemaKey, template);\r\n if(result.errorMessage) {\r\n throw new Error(result.errorMessage);\r\n }\r\n return result.itemKey!;\r\n }\r\n\r\n /**\r\n * Creates a new Schema Item in the SchemaContextEditor.\r\n * @param editor The SchemaContextEditor\r\n * @param targetSchemaKey The key of the target schema the item shall be created in.\r\n * @param template The Schema Items Template\r\n * @returns A SchemaItemEditResults with a schema key if the item could be created.\r\n */\r\n async function createItem(editor: SchemaContextEditor, targetSchemaKey: SchemaKey, template: SchemaItem): Promise<SchemaItemEditResults> {\r\n if (is(template, Enumeration))\r\n return editor.enumerations.create(targetSchemaKey, template.name, template.isInt ? PrimitiveType.Integer : PrimitiveType.String, template.label, template.isStrict);\r\n if (is(template, EntityClass))\r\n return editor.entities.create(targetSchemaKey, template.name, template.modifier);\r\n if (is(template, StructClass))\r\n return editor.structs.create(targetSchemaKey, template.name);\r\n if (is(template, CustomAttributeClass))\r\n return editor.customAttributes.create(targetSchemaKey, template.name, template.containerType);\r\n if(is(template, PropertyCategory))\r\n return editor.propertyCategories.create(targetSchemaKey, template.name, template.priority);\r\n if (is(template, Phenomenon))\r\n return editor.phenomenons.create(targetSchemaKey, template.name, template.definition);\r\n if (is(template, Constant)) {\r\n if(template.phenomenon === undefined) {\r\n throw new Error(`Invalid Constant ${template.name} has no phenomenon defined`);\r\n }\r\n const phenomenon = await template.phenomenon;\r\n const itemKey = phenomenon.key.schemaKey.matches(template.key.schemaKey)\r\n ? new SchemaItemKey(phenomenon.name, targetSchemaKey)\r\n : phenomenon.key;\r\n\r\n return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);\r\n }\r\n if (is(template, KindOfQuantity)) {\r\n if(template.persistenceUnit === undefined) {\r\n throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);\r\n }\r\n const persistenceUnit = await template.persistenceUnit;\r\n const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)\r\n ? new SchemaItemKey(persistenceUnit.name, targetSchemaKey)\r\n : persistenceUnit.key;\r\n return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);\r\n }\r\n if (is(template, UnitSystem))\r\n return editor.unitSystems.create(targetSchemaKey, template.name);\r\n\r\n throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);\r\n }\r\n\r\n /**\r\n * Type Guard to \"cast\" a given schema item into an implementation\r\n * @param item Item to be checked\r\n * @param type The desired implementation.\r\n * @returns true if the item could be casted, otherwise false.\r\n */\r\n function is<T extends SchemaItem>(item: SchemaItem, type: new (...args: any) => T ): item is T {\r\n return item instanceof type;\r\n }\r\n}\r\n"]}