@itwin/ecschema-editing 4.4.0-dev.3 → 4.4.0-dev.31
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.
- package/CHANGELOG.md +16 -1
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +2 -0
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +28 -0
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +1 -1
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +1 -1
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +8 -6
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +2 -0
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +1 -0
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +20 -0
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableArrayProperty.d.ts +10 -0
- package/lib/cjs/Editing/Mutable/MutableArrayProperty.d.ts.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableArrayProperty.js +16 -0
- package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts +2 -0
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +2 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.d.ts +13 -0
- package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.d.ts.map +1 -0
- package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js +16 -0
- package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableProperty.d.ts +6 -1
- package/lib/cjs/Editing/Mutable/MutableProperty.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts +9 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +33 -2
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +148 -22
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/AnyPropertyMerger.d.ts +15 -0
- package/lib/cjs/Merging/AnyPropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/AnyPropertyMerger.js +71 -0
- package/lib/cjs/Merging/AnyPropertyMerger.js.map +1 -0
- package/lib/cjs/Merging/ArrayPropertyMerger.d.ts +32 -0
- package/lib/cjs/Merging/ArrayPropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/ArrayPropertyMerger.js +143 -0
- package/lib/cjs/Merging/ArrayPropertyMerger.js.map +1 -0
- package/lib/cjs/Merging/CAClassMerger.d.ts +6 -8
- package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +27 -10
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +14 -6
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +133 -35
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts +16 -0
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/ClassPropertyMerger.js +90 -0
- package/lib/cjs/Merging/ClassPropertyMerger.js.map +1 -0
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts +21 -0
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/CustomAttributeMerger.js +51 -0
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -0
- package/lib/cjs/Merging/EntityClassMerger.d.ts +11 -0
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/EntityClassMerger.js +26 -0
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -0
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +15 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.js +66 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -0
- package/lib/cjs/Merging/MixinMerger.d.ts +11 -0
- package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/MixinMerger.js +38 -0
- package/lib/cjs/Merging/MixinMerger.js.map +1 -0
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts +24 -0
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js +106 -0
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +1 -0
- package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemFactory.js +10 -0
- package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +2 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +11 -4
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +16 -3
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/lib/cjs/Merging/StructClassMerger.d.ts +10 -0
- package/lib/cjs/Merging/StructClassMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/StructClassMerger.js +13 -0
- package/lib/cjs/Merging/StructClassMerger.js.map +1 -0
- package/lib/cjs/Merging/StructPropertyMerger.d.ts +11 -0
- package/lib/cjs/Merging/StructPropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/StructPropertyMerger.js +47 -0
- package/lib/cjs/Merging/StructPropertyMerger.js.map +1 -0
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/ECRules.d.ts +13 -3
- package/lib/cjs/Validation/ECRules.d.ts.map +1 -1
- package/lib/cjs/Validation/ECRules.js +30 -11
- package/lib/cjs/Validation/ECRules.js.map +1 -1
- package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
- package/lib/cjs/Validation/Rules.js.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js +2 -4
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +15 -15
- package/public/locales/en/ECSchemaEditing.json +26 -26
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnumerationPropertyMerger = exports.PrimitivePropertyMerger = 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
|
+
const AnyPropertyMerger_1 = require("./AnyPropertyMerger");
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
class PrimitiveOrEnumPropertyMerger extends AnyPropertyMerger_1.AnyPropertyMerger {
|
|
14
|
+
async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
|
|
15
|
+
const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
|
|
16
|
+
if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
const mutableProperty = property;
|
|
20
|
+
switch (attributeName) {
|
|
21
|
+
case "extendedTypeName": {
|
|
22
|
+
mutableProperty.setExtendedTypeName(attributeNewValue);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
case "minLength": {
|
|
26
|
+
mutableProperty.setMinLength(attributeNewValue);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
case "maxLength": {
|
|
30
|
+
mutableProperty.setMaxLength(attributeNewValue);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
case "minValue": {
|
|
34
|
+
mutableProperty.setMinValue(attributeNewValue);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
case "maxValue": {
|
|
38
|
+
mutableProperty.setMaxValue(attributeNewValue);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger {
|
|
49
|
+
async createFromProps(classKey, property) {
|
|
50
|
+
const results = await super.getPropertyProps(property);
|
|
51
|
+
if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
|
|
52
|
+
return results;
|
|
53
|
+
}
|
|
54
|
+
const props = {
|
|
55
|
+
...property.toJSON(),
|
|
56
|
+
...results,
|
|
57
|
+
};
|
|
58
|
+
return this.context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, props);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.PrimitivePropertyMerger = PrimitivePropertyMerger;
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger {
|
|
66
|
+
async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
|
|
67
|
+
const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
|
|
68
|
+
if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
|
|
69
|
+
return results;
|
|
70
|
+
}
|
|
71
|
+
switch (attributeName) {
|
|
72
|
+
case "enumeration": {
|
|
73
|
+
if (attributeOldValue !== undefined) {
|
|
74
|
+
return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
async createFromProps(classKey, property) {
|
|
82
|
+
const results = await super.getPropertyProps(property);
|
|
83
|
+
if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
if (property.enumeration === undefined) {
|
|
87
|
+
return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };
|
|
88
|
+
}
|
|
89
|
+
const enumeration = await property.enumeration;
|
|
90
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)
|
|
91
|
+
? this.context.targetSchema.schemaKey
|
|
92
|
+
: enumeration.schema.schemaKey);
|
|
93
|
+
const type = await this.context.targetSchema.lookupItem(itemKey);
|
|
94
|
+
if (type === undefined) {
|
|
95
|
+
return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };
|
|
96
|
+
}
|
|
97
|
+
const props = {
|
|
98
|
+
...property.toJSON(),
|
|
99
|
+
...results,
|
|
100
|
+
typeName: type.fullName,
|
|
101
|
+
};
|
|
102
|
+
return this.context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, props);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.EnumerationPropertyMerger = EnumerationPropertyMerger;
|
|
106
|
+
//# sourceMappingURL=PrimitiveOrEnumPropertyMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrimitiveOrEnumPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PrimitiveOrEnumPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA6L;AAC7L,2DAAwD;AAIxD;;GAEG;AACH,MAAe,6BAAgG,SAAQ,qCAA+C;IACpJ,KAAK,CAAC,eAAe,CAAC,QAAsC,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACjJ,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,O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AO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;YAC3H,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAC/B,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAc,OAAO,CAAC,CAAC;QAC9E,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,EAAE,YAAY,EAAE,0CAA0C,WAAW,CAAC,IAAI,wBAAwB,EAAE,CAAC;SAC7G;QAED,MAAM,KAAK,GAA6B;YACtC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kCAAkC,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;CACF;AA7CD,8DA6CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Enumeration, EnumerationProperty, EnumerationPropertyProps, PrimitiveOrEnumPropertyBase, PrimitiveProperty, PrimitivePropertyProps, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\nimport { PropertyEditResults } from \"../Editing/Editor\";\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\n\n/**\n * @internal\n */\nabstract class PrimitiveOrEnumPropertyMerger<TPrimitiveOrEnumPropertyBase extends PrimitiveOrEnumPropertyBase> extends AnyPropertyMerger<TPrimitiveOrEnumPropertyBase> {\n public override async mergeAttributes(property: TPrimitiveOrEnumPropertyBase, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const mutableProperty = property as unknown as MutablePrimitiveOrEnumPropertyBase;\n switch (attributeName) {\n case \"extendedTypeName\": {\n mutableProperty.setExtendedTypeName(attributeNewValue);\n return true;\n }\n case \"minLength\": {\n mutableProperty.setMinLength(attributeNewValue);\n return true;\n }\n case \"maxLength\": {\n mutableProperty.setMaxLength(attributeNewValue);\n return true;\n }\n case \"minValue\": {\n mutableProperty.setMinValue(attributeNewValue);\n return true;\n }\n case \"maxValue\": {\n mutableProperty.setMaxValue(attributeNewValue);\n return true;\n }\n }\n return false;\n }\n}\n\n/**\n * @internal\n */\nexport class PrimitivePropertyMerger extends PrimitiveOrEnumPropertyMerger<PrimitiveProperty> {\n public override async createFromProps(classKey: SchemaItemKey, property: PrimitiveProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const props: PrimitivePropertyProps = {\n ...property.toJSON(),\n ...results,\n };\n return this.context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, props);\n }\n}\n\n/**\n * @internal\n */\nexport class EnumerationPropertyMerger extends PrimitiveOrEnumPropertyMerger<EnumerationProperty> {\n public override async mergeAttributes(property: EnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch (attributeName) {\n case \"enumeration\": {\n if (attributeOldValue !== undefined) {\n return { errorMessage: `Changing the property '${property.name}' enumeration is not supported.` };\n }\n return true;\n }\n }\n return false;\n }\n\n public override async createFromProps(classKey: SchemaItemKey, property: EnumerationProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n if (property.enumeration === undefined) {\n return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };\n }\n\n const enumeration = await property.enumeration;\n const itemKey = new SchemaItemKey(enumeration.name, this.context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : enumeration.schema.schemaKey,\n );\n const type = await this.context.targetSchema.lookupItem<Enumeration>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the merged schema.` };\n }\n\n const props: EnumerationPropertyProps = {\n ...property.toJSON(),\n ...results,\n typeName: type.fullName,\n };\n return this.context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, props);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemFactory.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"SchemaItemFactory.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAyH,UAAU,EAAE,aAAa,EAAsC,MAAM,0BAA0B,CAAC;AAEhO,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;GAEG;AACH,yBAAiB,iBAAiB,CAAC;IAEjC;;;;;OAKG;IACH,SAAsB,MAAM,CAAC,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAMtG;CA0DF"}
|
|
@@ -55,6 +55,16 @@ var SchemaItemFactory;
|
|
|
55
55
|
: phenomenon.key;
|
|
56
56
|
return editor.constants.create(targetSchemaKey, template.name, itemKey, template.definition);
|
|
57
57
|
}
|
|
58
|
+
if (is(template, ecschema_metadata_1.KindOfQuantity)) {
|
|
59
|
+
if (template.persistenceUnit === undefined) {
|
|
60
|
+
throw new Error(`Invalid KindOfQuantity ${template.name} has no persistenceUnit defined`);
|
|
61
|
+
}
|
|
62
|
+
const persistenceUnit = await template.persistenceUnit;
|
|
63
|
+
const itemKey = persistenceUnit.key.schemaKey.matches(template.key.schemaKey)
|
|
64
|
+
? new ecschema_metadata_1.SchemaItemKey(persistenceUnit.name, targetSchemaKey)
|
|
65
|
+
: persistenceUnit.key;
|
|
66
|
+
return editor.kindOfQuantities.create(targetSchemaKey, template.name, itemKey);
|
|
67
|
+
}
|
|
58
68
|
if (is(template, ecschema_metadata_1.UnitSystem))
|
|
59
69
|
return editor.unitSystems.create(targetSchemaKey, template.name);
|
|
60
70
|
throw new Error(`Unsupported Schema Item Type: ${template.constructor.name}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemFactory.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemFactory.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,
|
|
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,CA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AAC,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"]}
|
|
@@ -6,7 +6,7 @@ import { SchemaMergeContext } from "./SchemaMerger";
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
export type PropertyValueResolver<T extends SchemaItem, TProps = MutableSchemaItemProps<T>> = {
|
|
9
|
-
[P in keyof TProps]?: (
|
|
9
|
+
[P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
12
|
* Defines a Mutable Schema Props interface.
|
|
@@ -43,6 +43,7 @@ export declare class SchemaItemMerger<TItem extends SchemaItem> {
|
|
|
43
43
|
* @param _change The schema item change to be applied.
|
|
44
44
|
*/
|
|
45
45
|
protected merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges): Promise<void>;
|
|
46
|
+
protected lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>;
|
|
46
47
|
/**
|
|
47
48
|
* Merges the given schema item changes in the current context.
|
|
48
49
|
* @param context The merging context
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAmC,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,GAAC,sBAAsB,CAAC,CAAC,CAAC,IAAI;KACzF,CAAC,IAAI,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"SchemaItemMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAmC,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEjG,O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) {
|
|
44
44
|
// Can be overriden for complex merging
|
|
45
45
|
}
|
|
46
|
+
async lookup(schemaItem) {
|
|
47
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)
|
|
48
|
+
? this.context.targetSchema.schemaKey
|
|
49
|
+
: schemaItem.schema.schemaKey);
|
|
50
|
+
return this.context.targetSchema.lookupItem(itemKey);
|
|
51
|
+
}
|
|
46
52
|
/**
|
|
47
53
|
* Merges the given schema item changes in the current context.
|
|
48
54
|
* @param context The merging context
|
|
@@ -79,14 +85,15 @@ class SchemaItemMerger {
|
|
|
79
85
|
if (changes.length === 0) {
|
|
80
86
|
return;
|
|
81
87
|
}
|
|
82
|
-
const
|
|
88
|
+
const targetItem = (await this.context.targetSchema.lookupItem(targetItemKey));
|
|
89
|
+
const jsonProps = (targetItem?.toJSON() ?? {});
|
|
83
90
|
const propertyResolver = await this.createPropertyValueResolver();
|
|
84
91
|
for (const change of changes) {
|
|
85
|
-
const [propertyName,
|
|
92
|
+
const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs;
|
|
86
93
|
const resolver = propertyResolver[propertyName];
|
|
87
94
|
jsonProps[propertyName] = resolver !== undefined
|
|
88
|
-
? resolver(
|
|
89
|
-
:
|
|
95
|
+
? resolver(propertyNewValue, targetItemKey, propertyOldValue)
|
|
96
|
+
: propertyNewValue;
|
|
90
97
|
}
|
|
91
98
|
await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);
|
|
92
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaItemMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaItemMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAqE;AACrE,+DAAiG;AACjG,2DAAwD;AAkBxD;;;;;;GAMG;AACH,MAAa,gBAAgB;IAI3B;;;;OAIG;IACH,YAAY,OAA2B;QACrC,IAAI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AAE,CAAkC,CAAC;QAChF,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAC;QAElE,KAAI,MAAM,MAAM,IAAI,OAAO,EAAE;YAC3B,MAAM,CAAC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,WAAkD,CAAC;YAChI,MAAM,QAAQ,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;YAChD,SAAS,CAAC,YAAY,CAAC,GAAG,QAAQ,KAAK,SAAS;gBAC9C,CAAC,CAAC,QAAQ,CAAC,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,CAAC;gBAC7D,CAAC,CAAC,gBAAgB,CAAC;SACtB;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CACF;AAjGD,4CAiGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { SchemaItem, SchemaItemKey } from \"@itwin/ecschema-metadata\";\nimport { ChangeType, PropertyValueChange, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaItemFactory } from \"./SchemaItemFactory\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * Defines a type-safe interface of Property Value resolver.\n * @internal\n */\nexport type PropertyValueResolver<T extends SchemaItem, TProps=MutableSchemaItemProps<T>> = {\n [P in keyof TProps]?: (newValue: any, item: SchemaItemKey, oldValue?: any) => any;\n};\n\n/**\n * Defines a Mutable Schema Props interface.\n */\ntype MutableSchemaItemProps<T extends SchemaItem> = {\n -readonly [key in keyof ReturnType<T[\"toJSON\"]>]: ReturnType<T[\"toJSON\"]>[key];\n};\n\n/**\n * The SchemaItemMerger is an base class for several other mergers with the actual logic\n * to perform merging for a certain schema item type. The class provides the shared logics\n * that is shared for all schema item mergers and custom logic can be applied by overriding\n * the protected class members.\n * @internal\n */\nexport class SchemaItemMerger<TItem extends SchemaItem> {\n\n protected readonly context: SchemaMergeContext;\n\n /**\n * Constructor of the SchemaItemMerger class. This should not be overriden or extended\n * by sub-implementations.\n * @param context The current merging context.\n */\n constructor(context: SchemaMergeContext) {\n this.context = context;\n }\n\n /**\n * This overridable method allows to create a property value resolver that gets defines\n * a handler function for every possible property change. This allows adding complex handing\n * if a property value requires complicated merging.\n * @returns A resolver map with resolvers for the property.\n */\n protected async createPropertyValueResolver(): Promise<PropertyValueResolver<TItem>> {\n // Can be overriden for complex property value merging\n return {};\n }\n\n /**\n * This overridable method gets called for more complex merging.\n * @param _itemKey The key of the current schema item.\n * @param _source The source item that shall gets merged into.\n * @param _change The schema item change to be applied.\n */\n protected async merge(_itemKey: SchemaItemKey, _source: TItem, _change: SchemaItemChanges) {\n // Can be overriden for complex merging\n }\n\n protected async lookup<T extends SchemaItem>(schemaItem: T): Promise<T | undefined>{\n const itemKey = new SchemaItemKey(schemaItem.name, this.context.sourceSchema.schemaKey.matches(schemaItem.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : schemaItem.schema.schemaKey,\n );\n return this.context.targetSchema.lookupItem<T>(itemKey);\n }\n\n /**\n * Merges the given schema item changes in the current context.\n * @param context The merging context\n * @param schemaItemChanges An iterable of item changes.\n */\n public static async mergeChanges<TChange extends SchemaItemChanges>(context: SchemaMergeContext, schemaItemChanges: Iterable<TChange>) {\n const merger = new this(context);\n for(const change of schemaItemChanges) {\n\n // Gets the source and the target item. The target item could be undefined at that point.\n const sourceItem = (await context.sourceSchema.getItem<SchemaItem>(change.ecTypeName))!;\n let targetItemKey = new SchemaItemKey(change.ecTypeName, context.targetSchema.schemaKey);\n\n // In case the schema item does not exists in the target schema, an instance for\n // this schema item is created. It's properties get set by the merger then.\n if(change.schemaItemMissing?.changeType === ChangeType.Missing) {\n // Check for name to make sure there is no collision for items with the same name\n // but different type.\n if(await context.targetSchema.lookupItem(targetItemKey) !== undefined) {\n throw new Error(`Schema ${context.targetSchema.name} already contains a Schema Item ${change.ecTypeName}.`);\n }\n\n // TODO: Think about renaming the Schema Item. This could be controlled though a flag.\n targetItemKey = await SchemaItemFactory.create(context, sourceItem);\n }\n\n await merger.mergeItemPropertyValues(targetItemKey, change.propertyValueChanges);\n await merger.merge(targetItemKey, sourceItem, change);\n }\n }\n /**\n * Merges the property values.\n * @param targetItem The current schema item\n * @param changes The property changes.\n */\n private async mergeItemPropertyValues(targetItemKey: SchemaItemKey, changes: PropertyValueChange[]) {\n // No need to process anything if no properties differ.\n if(changes.length === 0) {\n return;\n }\n\n const targetItem = (await this.context.targetSchema.lookupItem<SchemaItem>(targetItemKey));\n const jsonProps = (targetItem?.toJSON() ?? {}) as MutableSchemaItemProps<TItem>;\n const propertyResolver = await this.createPropertyValueResolver();\n\n for(const change of changes) {\n const [propertyName, propertyNewValue, propertyOldValue] = change.diagnostic.messageArgs! as [keyof typeof jsonProps, any, any];\n const resolver = propertyResolver[propertyName];\n jsonProps[propertyName] = resolver !== undefined\n ? resolver(propertyNewValue, targetItemKey, propertyOldValue)\n : propertyNewValue;\n }\n\n await this.context.editor.schemaItems.applyProps(targetItemKey, jsonProps);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAkB,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"SchemaMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAkB,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAaxD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB;;;;;;;OAOG;YACW,gBAAgB;IAW9B;;;;;OAKG;IACU,KAAK,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkChF"}
|
|
@@ -13,10 +13,14 @@ const SchemaComparer_1 = require("../Validation/SchemaComparer");
|
|
|
13
13
|
const Editor_1 = require("../Editing/Editor");
|
|
14
14
|
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
15
15
|
const SchemaReferenceMerger_1 = require("./SchemaReferenceMerger");
|
|
16
|
-
const ClassMerger_1 = require("./ClassMerger");
|
|
17
16
|
const CAClassMerger_1 = require("./CAClassMerger");
|
|
18
17
|
const EnumerationMerger_1 = require("./EnumerationMerger");
|
|
19
18
|
const ConstantMerger_1 = require("./ConstantMerger");
|
|
19
|
+
const EntityClassMerger_1 = require("./EntityClassMerger");
|
|
20
|
+
const StructClassMerger_1 = require("./StructClassMerger");
|
|
21
|
+
const MixinMerger_1 = require("./MixinMerger");
|
|
22
|
+
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
23
|
+
const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
|
|
20
24
|
/**
|
|
21
25
|
* Class to merge two schemas together.
|
|
22
26
|
* @see [[merge]] to merge the schemas.
|
|
@@ -59,10 +63,16 @@ class SchemaMerger {
|
|
|
59
63
|
await SchemaItemMerger_1.SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);
|
|
60
64
|
await SchemaItemMerger_1.SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);
|
|
61
65
|
await ConstantMerger_1.default.mergeChanges(mergeContext, itemChanges.constants);
|
|
66
|
+
await KindOfQuantityMerger_1.default.mergeChanges(mergeContext, itemChanges.kindOfQuantities);
|
|
62
67
|
// TODO: For now we just do simple copy and merging of properties and classes. For more complex types
|
|
63
68
|
// with bases classes or relationships, this might need to get extended.
|
|
64
69
|
await CAClassMerger_1.default.mergeChanges(mergeContext, itemChanges.customAttributeClasses);
|
|
65
|
-
await
|
|
70
|
+
await StructClassMerger_1.default.mergeChanges(mergeContext, itemChanges.structClasses);
|
|
71
|
+
await EntityClassMerger_1.default.mergeChanges(mergeContext, itemChanges.entityClasses);
|
|
72
|
+
await MixinMerger_1.default.mergeChanges(mergeContext, itemChanges.mixins);
|
|
73
|
+
await (0, CustomAttributeMerger_1.mergeCustomAttributes)(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {
|
|
74
|
+
return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);
|
|
75
|
+
});
|
|
66
76
|
// TODO: For now we directly manipulate the target schema. For error handing purposes, we should first
|
|
67
77
|
// merge into a temporary schema and eventually swap that with the given instance.
|
|
68
78
|
return targetSchema;
|
|
@@ -75,13 +85,16 @@ exports.SchemaMerger = SchemaMerger;
|
|
|
75
85
|
*/
|
|
76
86
|
function getSchemaItemChanges(schemaChanges) {
|
|
77
87
|
return {
|
|
78
|
-
get
|
|
88
|
+
get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.EntityClass); },
|
|
79
89
|
get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Constant); },
|
|
80
90
|
get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.CustomAttributeClass); },
|
|
81
91
|
get enumeratations() { return schemaChanges.enumerationChanges.values(); },
|
|
92
|
+
get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },
|
|
82
93
|
get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Phenomenon); },
|
|
83
94
|
get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.PropertyCategory); },
|
|
84
95
|
get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.UnitSystem); },
|
|
96
|
+
get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.StructClass); },
|
|
97
|
+
get mixins() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.Mixin); },
|
|
85
98
|
};
|
|
86
99
|
}
|
|
87
100
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D
|
|
1
|
+
{"version":3,"file":"SchemaMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaMerger.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkE;AAElE,iEAA8D;AAC9D,8CAAwD;AACxD,yDAAsD;AAEtD,mEAA4D;AAC5D,mDAA4C;AAC5C,2DAAoD;AACpD,qDAA+C;AAC/C,2DAAoD;AACpD,2DAAoD;AACpD,+CAAwC;AACxC,mEAAgE;AAChE,iEAA0D;AAY1D;;;;GAIG;AACH,MAAa,YAAY;IACvB;;;;;;;OAOG;IACK,KAAK,CAAC,gBAAgB,CAAC,YAAoB,EAAE,YAAoB;QACvE,MAAM,WAAW,GAAoB,EAAE,CAAC;QACxC,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CA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,IAAI,kBAAkB,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC9H,IAAI,WAAW,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,iBAAiB,EAAE,kCAAc,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjH,IAAI,aAAa,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/G,IAAI,MAAM,KAAK,OAAO,uBAAuB,CAAC,aAAa,CAAC,YAAY,EAAE,kCAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KACnG,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,QAAS,CAAC,CAAC,uBAAuB,CAAoC,OAA6B,EAAE,GAAG,KAAuB;IAC7H,KAAI,MAAM,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE;YACzC,MAAM,MAAM,CAAC;SACd;KACF;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Merging\n */\n\nimport { Schema, SchemaItemType } from \"@itwin/ecschema-metadata\";\nimport { SchemaChanges, SchemaItemChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\nimport { SchemaContextEditor } from \"../Editing/Editor\";\nimport { SchemaItemMerger } from \"./SchemaItemMerger\";\n\nimport mergeSchemaReferences from \"./SchemaReferenceMerger\";\nimport CAClassMerger from \"./CAClassMerger\";\nimport EnumerationMerger from \"./EnumerationMerger\";\nimport ConstantsMerger from \"./ConstantMerger\";\nimport EntityClassMerger from \"./EntityClassMerger\";\nimport StructClassMerger from \"./StructClassMerger\";\nimport MixinMerger from \"./MixinMerger\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\nimport KindOfQuantityMerger from \"./KindOfQuantityMerger\";\n\n/**\n * Defines the context of a Schema merging run.\n * @beta\n */\nexport interface SchemaMergeContext {\n readonly targetSchema: Schema;\n readonly sourceSchema: Schema;\n readonly editor: SchemaContextEditor;\n}\n\n/**\n * Class to merge two schemas together.\n * @see [[merge]] to merge the schemas.\n * @beta\n */\nexport class SchemaMerger {\n /**\n * Gets the @see SchemaChanges between the two given Schemas from perspective of the source\n * to the target schema. For example if source contains a class which does not exists in the\n * target one, it would be listed as missing.\n * @param targetSchema The schema the differences gets merged into.\n * @param sourceSchema The schema to compare.\n * @returns An instance of @see SchemaChanges between the two schemas.\n */\n private async getSchemaChanges(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaChanges> {\n const changesList: SchemaChanges[] = [];\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\n\n // It is important to compare the schema items by name, not full name as otherwise\n // we'd often see differences when comparing two different schemas.\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\n\n return changesList[0];\n }\n\n /**\n * Copy the SchemaItems of the source schemas to the target schema.\n * @param targetSchema The schema the SchemaItems gets merged to.\n * @param sourceSchema The schema the SchemaItems gets copied from.\n * @returns The merged target schema.\n */\n public async merge(targetSchema: Schema, sourceSchema: Schema): Promise<Schema> {\n const schemaChanges = await this.getSchemaChanges(targetSchema, sourceSchema);\n const mergeContext: SchemaMergeContext = {\n editor: new SchemaContextEditor(targetSchema.context),\n targetSchema,\n sourceSchema,\n };\n\n await mergeSchemaReferences(mergeContext, schemaChanges);\n\n const itemChanges = getSchemaItemChanges(schemaChanges);\n await EnumerationMerger.mergeChanges(mergeContext, itemChanges.enumeratations);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.propertyCategories);\n\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.unitSystems);\n await SchemaItemMerger.mergeChanges(mergeContext, itemChanges.phenomenons);\n await ConstantsMerger.mergeChanges(mergeContext, itemChanges.constants);\n await KindOfQuantityMerger.mergeChanges(mergeContext, itemChanges.kindOfQuantities);\n\n // TODO: For now we just do simple copy and merging of properties and classes. For more complex types\n // with bases classes or relationships, this might need to get extended.\n await CAClassMerger.mergeChanges(mergeContext, itemChanges.customAttributeClasses);\n await StructClassMerger.mergeChanges(mergeContext, itemChanges.structClasses);\n await EntityClassMerger.mergeChanges(mergeContext, itemChanges.entityClasses);\n await MixinMerger.mergeChanges(mergeContext, itemChanges.mixins);\n\n await mergeCustomAttributes(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {\n return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);\n });\n\n // TODO: For now we directly manipulate the target schema. For error handing purposes, we should first\n // merge into a temporary schema and eventually swap that with the given instance.\n return targetSchema;\n }\n}\n\n/**\n * This helper method composes the different schema change objects to a single easier\n * to use object that should improve readability when the methods get called.\n */\nfunction getSchemaItemChanges(schemaChanges: SchemaChanges) {\n return {\n get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.EntityClass); },\n get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Constant); },\n get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.CustomAttributeClass); },\n get enumeratations() { return schemaChanges.enumerationChanges.values(); },\n get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },\n get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.Phenomenon); },\n get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.PropertyCategory); },\n get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, SchemaItemType.UnitSystem); },\n get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.StructClass); },\n get mixins() { return filterChangesByItemType(schemaChanges.classChanges, SchemaItemType.Mixin); },\n };\n}\n\n/**\n * Filters and returns the changed items by its schema item type.\n * @param changes A map of changed schema items.\n * @param types A list of schema item types to filter.\n * @returns An Iterable with the filtered schema items.\n */\nfunction * filterChangesByItemType<TChange extends SchemaItemChanges>(changes: Map<string, TChange>, ...types: SchemaItemType[]): Iterable<TChange> {\n for(const change of changes.values()) {\n if (types.includes(change.schemaItemType)) {\n yield change;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaReferenceMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAmE;AAInE;;;;;GAKG;AACY,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAsB;IAC1G,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;IAE/C,kFAAkF;IAClF,4FAA4F;IAC5F,KAAI,MAAM,sBAAsB,IAAI,OAAO,CAAC,uBAAuB,EAAE;QACnE,MAAM,CAAC,gBAAgB,CAAC,GAAG,sBAAsB,CAAC,UAAU,CAAC,WAAwB,CAAC;QACtF,MAAM,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;KACxF;IAED,iFAAiF;IACjF,qFAAqF;IACrF,qFAAqF;IACrF,8BAA8B;IAC9B,KAAI,MAAM,wBAAwB,IAAI,OAAO,CAAC,qBAAqB,EAAE;QACnE,MAAM,CAAC,gBAAgB,CAAC,GAAG,wBAAwB,CAAC,UAAU,CAAC,WAAwB,CAAC;QACxF,MAAM,cAAc,GAAG,CAAC,MAAM,YAAY,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAE,CAAC;QAEjF,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,cAAc,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACzE,IAAG,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,mCAAe,CAAC,qBAAqB,CAAC,EAAE;YACpF,MAAM,IAAI,KAAK,CAAC,yBAAyB,gBAAgB,CAAC,IAAI,gCAAgC,KAAK,CAAC,SAAS,CAAC,OAAO,QAAQ,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC;SAC1J;QACD,IAAG,MAAM,KAAK,cAAc,EAAE;YAC5B,SAAS;SACV;QAED,MAAM,KAAK,GAAG,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,cAAc,CAAC,CAAC;QAC7F,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAEzC,MAAM,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,YAAY,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;KACxF;AACH,CAAC;AA/BD,wCA+BC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC;QACf,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"SchemaReferenceMerger.js","sourceRoot":"","sources":["../../../src/Merging/SchemaReferenceMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAmE;AAInE;;;;;GAKG;AACY,KAAK,UAAU,qBAAqB,CAAC,YAAgC,EAAE,OAAsB;IAC1G,MAAM,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;IAE/C,kFAAkF;IAClF,4FAA4F;IAC5F,KAAI,MAAM,sBAAsB,IAAI,OAAO,CAAC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;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAY,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC;QACf,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Schema, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { SchemaChanges } from \"../Validation/SchemaChanges\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\n\n/**\n * Merges the schema references of two schemas.\n * @param mergeContext current merge context\n * @param changes schema changes.\n * @internal\n */\nexport default async function mergeSchemaReferences(mergeContext: SchemaMergeContext, changes: SchemaChanges) {\n const targetSchema = mergeContext.targetSchema;\n\n // If the target schema does not have a reference to a schema yet, it can be added\n // but should be checked if it's schema references have collisions with existing references.\n for(const missingSchemaReference of changes.missingSchemaReferences) {\n const [referencedSchema] = missingSchemaReference.diagnostic.messageArgs! as [Schema];\n await mergeContext.editor.addSchemaReference(targetSchema.schemaKey, referencedSchema);\n }\n\n // If the source schema referenced a schema that is also referenced by the target\n // schema but in a different version, it is marked as delta. Here we need to check if\n // the source schema is compatible to the existing one. This is not be checked by the\n // schema instance when added.\n for(const differentSchemaReference of changes.schemaReferenceDeltas) {\n const [referencedSchema] = differentSchemaReference.diagnostic.messageArgs! as [Schema];\n const existingSchema = (await targetSchema.getReference(referencedSchema.name))!;\n\n const [older, latest] = compareSchemas(existingSchema, referencedSchema);\n if(!latest.schemaKey.matches(older.schemaKey, SchemaMatchType.LatestWriteCompatible)) {\n throw new Error(`Schemas references of ${referencedSchema.name} have incompatible versions: ${older.schemaKey.version} and ${latest.schemaKey.version}`);\n }\n if(latest === existingSchema) {\n continue;\n }\n\n const index = targetSchema.references.findIndex((reference) => reference === existingSchema);\n targetSchema.references.splice(index, 1);\n\n await mergeContext.editor.addSchemaReference(targetSchema.schemaKey, referencedSchema);\n }\n}\n\n/**\n * Compares the schemas and return them in order of their versions [older, latest].\n * @param left The first schema to be added.\n * @param right The second schema to be added.\n * @returns The schemas in order.\n */\nfunction compareSchemas(left: Schema, right: Schema): [Schema, Schema] {\n return left.schemaKey.compareByVersion(right.schemaKey) < 0\n ? [left, right]\n : [right, left];\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SchemaKey, StructClass } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { ClassMerger } from "./ClassMerger";
|
|
3
|
+
import { SchemaItemEditResults } from "../Editing/Editor";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export default class StructClassMerger extends ClassMerger<StructClass> {
|
|
8
|
+
protected create(schemaKey: SchemaKey, ecClass: StructClass): Promise<SchemaItemEditResults>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=StructClassMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StructClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/StructClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,WAAW,CAAC,WAAW,CAAC;cAE5C,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAG5G"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ClassMerger_1 = require("./ClassMerger");
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
class StructClassMerger extends ClassMerger_1.ClassMerger {
|
|
8
|
+
async create(schemaKey, ecClass) {
|
|
9
|
+
return this.context.editor.structs.create(schemaKey, ecClass.name);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.default = StructClassMerger;
|
|
13
|
+
//# sourceMappingURL=StructClassMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StructClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/StructClassMerger.ts"],"names":[],"mappings":";;AAKA,+CAA4C;AAG5C;;GAEG;AACH,MAAqB,iBAAkB,SAAQ,yBAAwB;IAElD,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAAoB;QACxE,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;CACF;AALD,oCAKC","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 { SchemaKey, StructClass } from \"@itwin/ecschema-metadata\";\nimport { ClassMerger } from \"./ClassMerger\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\n\n/**\n * @internal\n */\nexport default class StructClassMerger extends ClassMerger<StructClass> {\n\n protected override async create(schemaKey: SchemaKey, ecClass: StructClass): Promise<SchemaItemEditResults> {\n return this.context.editor.structs.create(schemaKey, ecClass.name);\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SchemaItemKey, StructProperty } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { AnyPropertyMerger } from "./AnyPropertyMerger";
|
|
3
|
+
import { PropertyEditResults } from "../Editing/Editor";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare class StructPropertyMerger extends AnyPropertyMerger<StructProperty> {
|
|
8
|
+
mergeAttributes(property: StructProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean>;
|
|
9
|
+
createFromProps(classKey: SchemaItemKey, property: StructProperty): Promise<PropertyEditResults>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=StructPropertyMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StructPropertyMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/StructPropertyMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAe,cAAc,EAAuB,MAAM,0BAA0B,CAAC;AAC3G,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB,CAAC,cAAc,CAAC;IACnD,eAAe,CAAC,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC;IAcxJ,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAsBvH"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StructPropertyMerger = 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
|
+
const AnyPropertyMerger_1 = require("./AnyPropertyMerger");
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
class StructPropertyMerger extends AnyPropertyMerger_1.AnyPropertyMerger {
|
|
14
|
+
async mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue) {
|
|
15
|
+
const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);
|
|
16
|
+
if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
switch (attributeName) {
|
|
20
|
+
case "structClass": {
|
|
21
|
+
return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
async createFromProps(classKey, property) {
|
|
27
|
+
const results = await super.getPropertyProps(property);
|
|
28
|
+
if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {
|
|
29
|
+
return results;
|
|
30
|
+
}
|
|
31
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)
|
|
32
|
+
? this.context.targetSchema.schemaKey
|
|
33
|
+
: property.structClass.schema.schemaKey);
|
|
34
|
+
const type = await this.context.targetSchema.lookupItem(itemKey);
|
|
35
|
+
if (type === undefined) {
|
|
36
|
+
return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };
|
|
37
|
+
}
|
|
38
|
+
const props = {
|
|
39
|
+
...property.toJSON(),
|
|
40
|
+
...results,
|
|
41
|
+
typeName: type.fullName,
|
|
42
|
+
};
|
|
43
|
+
return this.context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, props);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.StructPropertyMerger = StructPropertyMerger;
|
|
47
|
+
//# sourceMappingURL=StructPropertyMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StructPropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/StructPropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA2G;AAC3G,2DAAwD;AAGxD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,qCAAiC;IACzD,KAAK,CAAC,eAAe,CAAC,QAAwB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACnI,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;QAC3G,IAAI,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YACjG,OAAO,OAAO,CAAC;SAChB;QAED,QAAQ,aAAa,EAAE;YACrB,KAAK,aAAa,CAAC,CAAC;gBAClB,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,IAAI,iCAAiC,EAAE,CAAC;aACnG;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,QAAuB,EAAE,QAAwB;QACrF,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;YAC7E,OAAO,OAAO,CAAC;SAChB;QAED,MAAM,OAAO,GAAG,IAAI,iCAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;YAC7I,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS;YACrC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CACxC,CAAC;QACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAc,OAAO,CAAC,CAAC;QAC9E,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,OAAO,EAAE,YAAY,EAAE,qCAAqC,QAAQ,CAAC,WAAW,CAAC,IAAI,wBAAwB,EAAE,CAAC;SACjH;QAED,MAAM,KAAK,GAAwB;YACjC,GAAG,QAAQ,CAAC,MAAM,EAAE;YACpB,GAAG,OAAO;YACV,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1G,CAAC;CACF;AArCD,oDAqCC","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 { SchemaItemKey, StructClass, StructProperty, StructPropertyProps } from \"@itwin/ecschema-metadata\";\nimport { AnyPropertyMerger } from \"./AnyPropertyMerger\";\nimport { PropertyEditResults } from \"../Editing/Editor\";\n\n/**\n * @internal\n */\nexport class StructPropertyMerger extends AnyPropertyMerger<StructProperty> {\n public override async mergeAttributes(property: StructProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const results = await super.mergeAttributes(property, attributeName, attributeNewValue, attributeOldValue);\n if (results === true || this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n switch (attributeName) {\n case \"structClass\": {\n return { errorMessage: `Changing the property '${property.name}' structClass is not supported.` };\n }\n }\n return false;\n }\n\n public override async createFromProps(classKey: SchemaItemKey, property: StructProperty): Promise<PropertyEditResults> {\n const results = await super.getPropertyProps(property);\n if (this.isPropertyEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n\n const itemKey = new SchemaItemKey(property.structClass.name, this.context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : property.structClass.schema.schemaKey,\n );\n const type = await this.context.targetSchema.lookupItem<StructClass>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the merged schema.` };\n }\n\n const props: StructPropertyProps = {\n ...property.toJSON(),\n ...results,\n typeName: type.fullName,\n };\n return this.context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, props);\n }\n}\n"]}
|