@itwin/ecschema-editing 4.6.0-dev.7 → 4.6.0-dev.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +2 -2
- package/lib/cjs/Differencing/SchemaConflicts.js +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +9 -6
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +213 -161
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.d.ts +354 -78
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.js +184 -11
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +1 -0
- package/lib/cjs/Editing/Mutable/MutableConstant.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +1 -0
- package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +2 -0
- 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/MutablePhenomenon.d.ts +1 -0
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +1 -0
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +2 -0
- package/lib/cjs/Editing/Mutable/MutableSchema.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +1 -0
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.d.ts +4 -7
- package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +26 -23
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +10 -18
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +148 -155
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.d.ts +4 -8
- package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +59 -40
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts +16 -13
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +66 -34
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.d.ts +10 -7
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +41 -29
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.d.ts +9 -9
- package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +77 -48
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +4 -11
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js +57 -53
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.d.ts +4 -7
- package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +24 -25
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.d.ts +8 -0
- package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/PhenomenonMerger.js +37 -0
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -0
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts +8 -0
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/PropertyCategoryMerger.js +34 -0
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -0
- package/lib/cjs/Merging/PropertyMerger.d.ts +6 -14
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +212 -287
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts +16 -10
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js +121 -112
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +26 -51
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +106 -88
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts +21 -9
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +74 -88
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.d.ts +5 -5
- package/lib/cjs/Merging/SchemaReferenceMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js +33 -15
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.d.ts +8 -0
- package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/UnitSystemMerger.js +26 -0
- package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -0
- package/lib/cjs/Validation/ECRules.js +1 -1
- package/lib/cjs/Validation/ECRules.js.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.js +1 -1
- package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js +3 -3
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/package.json +9 -9
- package/lib/cjs/Merging/SchemaItemFactory.d.ts +0 -15
- package/lib/cjs/Merging/SchemaItemFactory.d.ts.map +0 -1
- package/lib/cjs/Merging/SchemaItemFactory.js +0 -82
- package/lib/cjs/Merging/SchemaItemFactory.js.map +0 -1
- package/lib/cjs/Merging/StructClassMerger.d.ts +0 -10
- package/lib/cjs/Merging/StructClassMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/StructClassMerger.js +0 -13
- package/lib/cjs/Merging/StructClassMerger.js.map +0 -1
|
@@ -1,315 +1,240 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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
|
-
*--------------------------------------------------------------------------------------------*/
|
|
3
|
+
exports.mergeClassProperties = exports.mergePropertyDifference = void 0;
|
|
8
4
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
}
|
|
5
|
+
const SchemaItemMerger_1 = require("./SchemaItemMerger");
|
|
6
|
+
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
24
7
|
/**
|
|
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
8
|
* @internal
|
|
30
9
|
*/
|
|
31
|
-
async function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 };
|
|
10
|
+
async function mergePropertyDifference(context, change) {
|
|
11
|
+
const classKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
|
|
12
|
+
return mergeClassProperty(context, change, classKey, {
|
|
13
|
+
...change.difference,
|
|
14
|
+
name: change.path,
|
|
15
|
+
});
|
|
43
16
|
}
|
|
44
|
-
exports.
|
|
17
|
+
exports.mergePropertyDifference = mergePropertyDifference;
|
|
45
18
|
/**
|
|
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
19
|
* @internal
|
|
51
20
|
*/
|
|
52
|
-
async function
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.` };
|
|
21
|
+
async function mergeClassProperties(context, change, itemKey) {
|
|
22
|
+
for (const property of change.difference.properties || []) {
|
|
23
|
+
const result = await mergeClassProperty(context, change, itemKey, property);
|
|
24
|
+
if (result.errorMessage) {
|
|
25
|
+
return result;
|
|
62
26
|
}
|
|
63
|
-
|
|
27
|
+
}
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
exports.mergeClassProperties = mergeClassProperties;
|
|
31
|
+
async function mergeClassProperty(context, change, itemKey, property) {
|
|
32
|
+
return change.changeType === "add"
|
|
33
|
+
? addClassProperty(context, itemKey, property)
|
|
34
|
+
: modifyClassProperty(context, itemKey, property);
|
|
35
|
+
}
|
|
36
|
+
async function addClassProperty(context, itemKey, property) {
|
|
37
|
+
if (property.category !== undefined) {
|
|
38
|
+
property.category = await (0, SchemaItemMerger_1.updateSchemaItemFullName)(context, property.category);
|
|
64
39
|
}
|
|
65
40
|
if (property.kindOfQuantity !== undefined) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
41
|
+
property.kindOfQuantity = await (0, SchemaItemMerger_1.updateSchemaItemFullName)(context, property.kindOfQuantity);
|
|
42
|
+
}
|
|
43
|
+
const createResult = await createProperty(context, itemKey, property);
|
|
44
|
+
if (createResult.errorMessage) {
|
|
45
|
+
return createResult;
|
|
46
|
+
}
|
|
47
|
+
if (property.customAttributes !== undefined) {
|
|
48
|
+
const result = await (0, CustomAttributeMerger_1.applyCustomAttributes)(context, property.customAttributes, async (ca) => {
|
|
49
|
+
return context.editor.entities.addCustomAttributeToProperty(itemKey, property.name, ca);
|
|
50
|
+
});
|
|
51
|
+
if (result.errorMessage) {
|
|
52
|
+
return result;
|
|
73
53
|
}
|
|
74
|
-
props = { ...props, kindOfQuantity: targetKoq.fullName };
|
|
75
54
|
}
|
|
76
|
-
|
|
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)}` };
|
|
55
|
+
return {};
|
|
85
56
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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;
|
|
57
|
+
async function createProperty(context, itemKey, property) {
|
|
58
|
+
if (enumerationProperty.is(property)) {
|
|
59
|
+
return enumerationProperty.add(context, itemKey, property);
|
|
119
60
|
}
|
|
120
|
-
|
|
121
|
-
|
|
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);
|
|
61
|
+
if (navigationProperty.is(property)) {
|
|
62
|
+
return navigationProperty.add(context, itemKey, property);
|
|
138
63
|
}
|
|
139
|
-
|
|
140
|
-
|
|
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);
|
|
64
|
+
if (primitiveProperty.is(property)) {
|
|
65
|
+
return primitiveProperty.add(context, itemKey, property);
|
|
174
66
|
}
|
|
175
|
-
|
|
176
|
-
|
|
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);
|
|
67
|
+
if (structProperty.is(property)) {
|
|
68
|
+
return structProperty.add(context, itemKey, property);
|
|
203
69
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
async function modifyClassProperty(context, itemKey, propertyProps) {
|
|
73
|
+
const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey);
|
|
74
|
+
const property = await ecClass.getProperty(propertyProps.name);
|
|
75
|
+
if (property === undefined) {
|
|
76
|
+
return { errorMessage: `Couldn't find property ${propertyProps.name} on class ${itemKey.name}` };
|
|
211
77
|
}
|
|
212
|
-
|
|
213
|
-
|
|
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);
|
|
78
|
+
if (propertyProps.type !== undefined) {
|
|
79
|
+
return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };
|
|
228
80
|
}
|
|
229
|
-
|
|
230
|
-
|
|
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);
|
|
81
|
+
if (propertyProps.kindOfQuantity !== undefined) {
|
|
82
|
+
return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };
|
|
236
83
|
}
|
|
237
|
-
|
|
238
|
-
|
|
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);
|
|
84
|
+
if (propertyProps.description !== undefined) {
|
|
85
|
+
property.setDescription(propertyProps.description);
|
|
261
86
|
}
|
|
262
|
-
|
|
263
|
-
|
|
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);
|
|
87
|
+
if (propertyProps.label !== undefined) {
|
|
88
|
+
property.setLabel(propertyProps.label);
|
|
272
89
|
}
|
|
273
|
-
|
|
274
|
-
|
|
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)}.` };
|
|
90
|
+
if (propertyProps.isReadOnly !== undefined) {
|
|
91
|
+
property.setIsReadOnly(propertyProps.isReadOnly);
|
|
300
92
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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);
|
|
93
|
+
if (propertyProps.priority !== undefined) {
|
|
94
|
+
property.setPriority(propertyProps.priority);
|
|
95
|
+
}
|
|
96
|
+
if (property.isArray()) {
|
|
97
|
+
await arrayProperty.merge(property, propertyProps);
|
|
312
98
|
}
|
|
313
|
-
|
|
314
|
-
|
|
99
|
+
if (propertyProps.category !== undefined) {
|
|
100
|
+
const categoryKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, propertyProps.category);
|
|
101
|
+
await context.editor.entities.setPropertyCategory(itemKey, property.name, categoryKey);
|
|
102
|
+
}
|
|
103
|
+
if (property.isEnumeration()) {
|
|
104
|
+
return enumerationProperty.merge(context, itemKey, property, propertyProps);
|
|
105
|
+
}
|
|
106
|
+
if (property.isNavigation()) {
|
|
107
|
+
return navigationProperty.merge(context, itemKey, property, propertyProps);
|
|
108
|
+
}
|
|
109
|
+
if (property.isPrimitive()) {
|
|
110
|
+
return primitiveProperty.merge(context, itemKey, property, propertyProps);
|
|
111
|
+
}
|
|
112
|
+
if (property.isStruct()) {
|
|
113
|
+
return structProperty.merge(context, itemKey, property, propertyProps);
|
|
114
|
+
}
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
const arrayProperty = {
|
|
118
|
+
is(property) {
|
|
119
|
+
return "minOccurs" in property && "maxOccurs" in property;
|
|
120
|
+
},
|
|
121
|
+
async merge(property, props) {
|
|
122
|
+
if (props.minOccurs !== undefined) {
|
|
123
|
+
property.setMinOccurs(props.minOccurs);
|
|
124
|
+
}
|
|
125
|
+
if (props.maxOccurs !== undefined) {
|
|
126
|
+
property.setMaxOccurs(props.maxOccurs);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
const enumerationProperty = {
|
|
131
|
+
is(property) {
|
|
132
|
+
return primitiveProperty.is(property) && property.typeName.includes(".");
|
|
133
|
+
},
|
|
134
|
+
async add(context, itemKey, property) {
|
|
135
|
+
const enumerationKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, property.typeName);
|
|
136
|
+
const enumerationType = await context.editor.schemaContext.getSchemaItem(enumerationKey);
|
|
137
|
+
if (enumerationType === undefined) {
|
|
138
|
+
return { errorMessage: `Unable to locate the enumeration class ${enumerationKey.name} in the context schema.` };
|
|
139
|
+
}
|
|
140
|
+
property.typeName = enumerationKey.fullName;
|
|
141
|
+
return arrayProperty.is(property)
|
|
142
|
+
? context.editor.entities.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)
|
|
143
|
+
: context.editor.entities.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);
|
|
144
|
+
},
|
|
145
|
+
async merge(context, itemKey, property, props) {
|
|
146
|
+
if ("enumeration" in props && props.enumeration !== undefined) {
|
|
147
|
+
return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };
|
|
148
|
+
}
|
|
149
|
+
return primitiveProperty.merge(context, itemKey, property, props);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
const navigationProperty = {
|
|
153
|
+
is(property) {
|
|
154
|
+
return property.type === "NavigationProperty";
|
|
155
|
+
},
|
|
156
|
+
async add(context, itemKey, property) {
|
|
157
|
+
const relationshipKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, property.relationshipName);
|
|
158
|
+
const relationshipType = await context.editor.schemaContext.getSchemaItem(relationshipKey);
|
|
159
|
+
if (relationshipType === undefined) {
|
|
160
|
+
return { errorMessage: `Unable to locate the relationship class ${relationshipKey.name} in the context schema.` };
|
|
161
|
+
}
|
|
162
|
+
property.relationshipName = relationshipKey.fullName;
|
|
163
|
+
const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey);
|
|
164
|
+
if (ecClass.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
165
|
+
return context.editor.entities.createNavigationPropertyFromProps(itemKey, property);
|
|
166
|
+
if (ecClass.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin)
|
|
167
|
+
return context.editor.mixins.createNavigationPropertyFromProps(itemKey, property);
|
|
168
|
+
if (ecClass.schemaItemType === ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
169
|
+
return context.editor.relationships.createNavigationPropertyFromProps(itemKey, property);
|
|
170
|
+
return { errorMessage: `Navigation property can't be added to ${ecClass.schemaItemType}.` };
|
|
171
|
+
},
|
|
172
|
+
async merge(_context, _itemKey, property, props) {
|
|
173
|
+
if (props.direction !== undefined) {
|
|
174
|
+
return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };
|
|
175
|
+
}
|
|
176
|
+
if ("relationshipClass" in props && props.relationshipClass !== undefined) {
|
|
177
|
+
return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };
|
|
178
|
+
}
|
|
179
|
+
return {};
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
const primitiveProperty = {
|
|
183
|
+
is(property) {
|
|
184
|
+
return property.type === "PrimitiveProperty" || property.type === "PrimitiveArrayProperty";
|
|
185
|
+
},
|
|
186
|
+
async add(context, itemKey, property) {
|
|
187
|
+
const propertyType = (0, ecschema_metadata_1.parsePrimitiveType)(property.typeName);
|
|
188
|
+
if (propertyType === undefined) {
|
|
189
|
+
return { errorMessage: `Invalid property type ${property.typeName} on property ${property.name}` };
|
|
190
|
+
}
|
|
191
|
+
return arrayProperty.is(property)
|
|
192
|
+
? context.editor.entities.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)
|
|
193
|
+
: context.editor.entities.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);
|
|
194
|
+
},
|
|
195
|
+
async merge(_context, _itemKey, property, props) {
|
|
196
|
+
const mutable = property;
|
|
197
|
+
if (props.typeName) {
|
|
198
|
+
return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };
|
|
199
|
+
}
|
|
200
|
+
if (props.extendedTypeName !== undefined) {
|
|
201
|
+
mutable.setExtendedTypeName(props.extendedTypeName);
|
|
202
|
+
}
|
|
203
|
+
if (props.minLength !== undefined) {
|
|
204
|
+
mutable.setMinLength(props.minLength);
|
|
205
|
+
}
|
|
206
|
+
if (props.maxLength !== undefined) {
|
|
207
|
+
mutable.setMaxLength(props.maxLength);
|
|
208
|
+
}
|
|
209
|
+
if (props.minValue !== undefined) {
|
|
210
|
+
mutable.setMinValue(props.minValue);
|
|
211
|
+
}
|
|
212
|
+
if (props.maxValue !== undefined) {
|
|
213
|
+
mutable.setMaxValue(props.maxValue);
|
|
214
|
+
}
|
|
215
|
+
return {};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
const structProperty = {
|
|
219
|
+
is(property) {
|
|
220
|
+
return property.type === "StructProperty" || property.type === "StructArrayProperty";
|
|
221
|
+
},
|
|
222
|
+
async add(context, itemKey, property) {
|
|
223
|
+
const structKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, property.typeName);
|
|
224
|
+
const structType = await context.editor.schemaContext.getSchemaItem(structKey);
|
|
225
|
+
if (structType === undefined) {
|
|
226
|
+
return { errorMessage: `Unable to locate the struct ${structKey.name} in the context schema.` };
|
|
227
|
+
}
|
|
228
|
+
property.typeName = structKey.fullName;
|
|
229
|
+
return arrayProperty.is(property)
|
|
230
|
+
? context.editor.entities.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)
|
|
231
|
+
: context.editor.entities.createStructPropertyFromProps(itemKey, property.name, structType, property);
|
|
232
|
+
},
|
|
233
|
+
async merge(_context, _itemKey, property, props) {
|
|
234
|
+
if ("structClass" in props && props.structClass !== undefined) {
|
|
235
|
+
return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };
|
|
236
|
+
}
|
|
237
|
+
return {};
|
|
238
|
+
},
|
|
239
|
+
};
|
|
315
240
|
//# sourceMappingURL=PropertyMerger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA8V;AAQ9V,KAAK,UAAU,uBAAuB,CAAC,OAA2B,EAAE,QAAkB,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;IAC3J,IAAI,QAAQ,CAAC,aAAa,EAAE,EAAE;QAC5B,OAAO,kBAAkB,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;KACnH;IACD,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE;QAC1B,OAAO,uBAAuB,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;KACxH;IACD,IAAI,QAAQ,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rB,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"]}
|
|
1
|
+
{"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;;AAOA,gEAAuT;AACvT,yDAAmF;AAInF,mEAAgE;AAYhE;;GAEG;AACI,KAAK,UAAU,uBAAuB,CAAC,OAA2B,EAAE,MAA+B;IACxG,MAAM,QAAQ,GAAG,IAAI,iCAAa,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,OAAO,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE;QACnD,GAAG,MAAM,CAAC,UAAU;QACpB,IAAI,EAAE,MAAM,CAAC,IAAI;KACE,CAAC,CAAC;AACzB,CAAC;AAND,0DAMC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAA2B,EAAE,OAAsB;IACzH,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,EAAE;QACzD,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC5E,IAAI,MAAM,CAAC,YAAY,EAAE;YACvB,OAAO,MAAM,CAAC;SACf;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AARD,oDAQC;AAED,KAAK,UAAU,kBAAkB,CAAC,OAA2B,EAAE,MAAsC,EAAE,OAAsB,EAAE,QAA0B;IACvJ,OAAO,MAAM,CAAC,UAAU,KAAK,KAAK;QAChC,CAAC,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC;QAC9C,CAAC,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AACtD,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC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AC;IACZ,CAAC;CACF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport type { SchemaEditResults } from \"../ecschema-editing\";\r\nimport type { SchemaMergeContext } from \"./SchemaMerger\";\r\nimport type { ClassItemDifference, ClassPropertyDifference, DifferenceType } from \"../Differencing/SchemaDifference\";\r\nimport { AnyProperty, AnyPropertyProps, ArrayPropertyProps, CustomAttribute, ECClass, Enumeration, EnumerationPropertyProps, NavigationPropertyProps, parsePrimitiveType, PrimitivePropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, StructClass, StructPropertyProps } from \"@itwin/ecschema-metadata\";\r\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\r\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\r\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\r\nimport { applyCustomAttributes } from \"./CustomAttributeMerger\";\r\n\r\ntype PartialEditable<T> = {\r\n -readonly [P in keyof T]: T[P];\r\n};\r\n\r\ninterface PropertyMerger<T extends AnyPropertyProps> {\r\n is(property: AnyPropertyProps): property is T;\r\n add(context: SchemaMergeContext, itemKey: SchemaItemKey, props: PartialEditable<T>): Promise<SchemaEditResults>;\r\n merge(context: SchemaMergeContext, itemKey: SchemaItemKey, property: AnyProperty, props: T): Promise<SchemaEditResults>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function mergePropertyDifference(context: SchemaMergeContext, change: ClassPropertyDifference): Promise<SchemaEditResults> {\r\n const classKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n return mergeClassProperty(context, change, classKey, {\r\n ...change.difference,\r\n name: change.path,\r\n } as AnyPropertyProps);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function mergeClassProperties(context: SchemaMergeContext, change: ClassItemDifference, itemKey: SchemaItemKey): Promise<SchemaEditResults> {\r\n for (const property of change.difference.properties || []) {\r\n const result = await mergeClassProperty(context, change, itemKey, property);\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n return {};\r\n}\r\n\r\nasync function mergeClassProperty(context: SchemaMergeContext, change: { changeType: DifferenceType }, itemKey: SchemaItemKey, property: AnyPropertyProps) {\r\n return change.changeType === \"add\"\r\n ? addClassProperty(context, itemKey, property)\r\n : modifyClassProperty(context, itemKey, property);\r\n}\r\n\r\nasync function addClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>): Promise<SchemaEditResults> {\r\n\r\n if (property.category !== undefined) {\r\n property.category = await updateSchemaItemFullName(context, property.category);\r\n }\r\n\r\n if (property.kindOfQuantity !== undefined) {\r\n property.kindOfQuantity = await updateSchemaItemFullName(context, property.kindOfQuantity);\r\n }\r\n\r\n const createResult = await createProperty(context, itemKey, property);\r\n if (createResult.errorMessage) {\r\n return createResult;\r\n }\r\n\r\n if (property.customAttributes !== undefined) {\r\n const result = await applyCustomAttributes(context, property.customAttributes as CustomAttribute[], async (ca) => {\r\n return context.editor.entities.addCustomAttributeToProperty(itemKey, property.name, ca);\r\n });\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n\r\n return {};\r\n}\r\n\r\nasync function createProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, property: PartialEditable<AnyPropertyProps>) {\r\n if (enumerationProperty.is(property)) {\r\n return enumerationProperty.add(context, itemKey, property);\r\n }\r\n if (navigationProperty.is(property)) {\r\n return navigationProperty.add(context, itemKey, property);\r\n }\r\n if (primitiveProperty.is(property)) {\r\n return primitiveProperty.add(context, itemKey, property);\r\n }\r\n if (structProperty.is(property)) {\r\n return structProperty.add(context, itemKey, property);\r\n }\r\n return {};\r\n}\r\n\r\nasync function modifyClassProperty(context: SchemaMergeContext, itemKey: SchemaItemKey, propertyProps: AnyPropertyProps): Promise<SchemaEditResults> {\r\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\r\n const property = await ecClass.getProperty(propertyProps.name) as MutableProperty;\r\n if (property === undefined) {\r\n return { errorMessage: `Couldn't find property ${propertyProps.name} on class ${itemKey.name}` };\r\n }\r\n\r\n if (propertyProps.type !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };\r\n }\r\n if (propertyProps.kindOfQuantity !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };\r\n }\r\n\r\n if (propertyProps.description !== undefined) {\r\n property.setDescription(propertyProps.description);\r\n }\r\n if (propertyProps.label !== undefined) {\r\n property.setLabel(propertyProps.label);\r\n }\r\n if (propertyProps.isReadOnly !== undefined) {\r\n property.setIsReadOnly(propertyProps.isReadOnly);\r\n }\r\n if (propertyProps.priority !== undefined) {\r\n property.setPriority(propertyProps.priority);\r\n }\r\n\r\n if (property.isArray()) {\r\n await arrayProperty.merge(property as any, propertyProps);\r\n }\r\n\r\n if (propertyProps.category !== undefined) {\r\n const categoryKey = await updateSchemaItemKey(context, propertyProps.category);\r\n await context.editor.entities.setPropertyCategory(itemKey, property.name, categoryKey);\r\n }\r\n\r\n if (property.isEnumeration()) {\r\n return enumerationProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isNavigation()) {\r\n return navigationProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isPrimitive()) {\r\n return primitiveProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n if (property.isStruct()) {\r\n return structProperty.merge(context, itemKey, property, propertyProps as any);\r\n }\r\n\r\n return {};\r\n}\r\n\r\nconst arrayProperty = {\r\n is(property: AnyPropertyProps): boolean {\r\n return \"minOccurs\" in property && \"maxOccurs\" in property;\r\n },\r\n async merge(property: MutableArrayProperty, props: ArrayPropertyProps) {\r\n if (props.minOccurs !== undefined) {\r\n property.setMinOccurs(props.minOccurs);\r\n }\r\n if (props.maxOccurs !== undefined) {\r\n property.setMaxOccurs(props.maxOccurs);\r\n }\r\n },\r\n};\r\n\r\nconst enumerationProperty: PropertyMerger<EnumerationPropertyProps> = {\r\n is(property): property is EnumerationPropertyProps {\r\n return primitiveProperty.is(property) && property.typeName.includes(\".\");\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const enumerationKey = await updateSchemaItemKey(context, property.typeName);\r\n const enumerationType = await context.editor.schemaContext.getSchemaItem<Enumeration>(enumerationKey);\r\n if (enumerationType === undefined) {\r\n return { errorMessage: `Unable to locate the enumeration class ${enumerationKey.name} in the context schema.` };\r\n }\r\n\r\n property.typeName = enumerationKey.fullName;\r\n\r\n return arrayProperty.is(property)\r\n ? context.editor.entities.createEnumerationArrayPropertyFromProps(itemKey, property.name, enumerationType, property)\r\n : context.editor.entities.createEnumerationPropertyFromProps(itemKey, property.name, enumerationType, property);\r\n },\r\n async merge(context, itemKey, property, props) {\r\n if (\"enumeration\" in props && props.enumeration !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };\r\n }\r\n return primitiveProperty.merge(context, itemKey, property, props);\r\n },\r\n};\r\n\r\nconst navigationProperty: PropertyMerger<NavigationPropertyProps> = {\r\n is(property): property is NavigationPropertyProps {\r\n return property.type === \"NavigationProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const relationshipKey = await updateSchemaItemKey(context, property.relationshipName);\r\n const relationshipType = await context.editor.schemaContext.getSchemaItem<RelationshipClass>(relationshipKey);\r\n if (relationshipType === undefined) {\r\n return { errorMessage: `Unable to locate the relationship class ${relationshipKey.name} in the context schema.` };\r\n }\r\n\r\n property.relationshipName = relationshipKey.fullName;\r\n\r\n const ecClass = await context.editor.schemaContext.getSchemaItem(itemKey) as ECClass;\r\n if (ecClass.schemaItemType === SchemaItemType.EntityClass)\r\n return context.editor.entities.createNavigationPropertyFromProps(itemKey, property);\r\n if (ecClass.schemaItemType === SchemaItemType.Mixin)\r\n return context.editor.mixins.createNavigationPropertyFromProps(itemKey, property);\r\n if (ecClass.schemaItemType === SchemaItemType.RelationshipClass)\r\n return context.editor.relationships.createNavigationPropertyFromProps(itemKey, property);\r\n return { errorMessage: `Navigation property can't be added to ${ecClass.schemaItemType}.` };\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n if (props.direction !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };\r\n }\r\n if (\"relationshipClass\" in props && props.relationshipClass !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };\r\n }\r\n return {};\r\n },\r\n};\r\n\r\nconst primitiveProperty: PropertyMerger<PrimitivePropertyProps> = {\r\n is(property): property is PrimitivePropertyProps {\r\n return property.type === \"PrimitiveProperty\" || property.type === \"PrimitiveArrayProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const propertyType = parsePrimitiveType(property.typeName);\r\n if (propertyType === undefined) {\r\n return { errorMessage: `Invalid property type ${property.typeName} on property ${property.name}` };\r\n }\r\n\r\n return arrayProperty.is(property)\r\n ? context.editor.entities.createPrimitiveArrayPropertyFromProps(itemKey, property.name, propertyType, property)\r\n : context.editor.entities.createPrimitivePropertyFromProps(itemKey, property.name, propertyType, property);\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n const mutable = property as unknown as MutablePrimitiveOrEnumPropertyBase;\r\n if (props.typeName) {\r\n return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };\r\n }\r\n\r\n if (props.extendedTypeName !== undefined) {\r\n mutable.setExtendedTypeName(props.extendedTypeName);\r\n }\r\n if (props.minLength !== undefined) {\r\n mutable.setMinLength(props.minLength);\r\n }\r\n if (props.maxLength !== undefined) {\r\n mutable.setMaxLength(props.maxLength);\r\n }\r\n if (props.minValue !== undefined) {\r\n mutable.setMinValue(props.minValue);\r\n }\r\n if (props.maxValue !== undefined) {\r\n mutable.setMaxValue(props.maxValue);\r\n }\r\n return {};\r\n },\r\n};\r\n\r\nconst structProperty: PropertyMerger<StructPropertyProps> = {\r\n is(property): property is StructPropertyProps {\r\n return property.type === \"StructProperty\" || property.type === \"StructArrayProperty\";\r\n },\r\n async add(context, itemKey, property): Promise<SchemaEditResults> {\r\n const structKey = await updateSchemaItemKey(context, property.typeName);\r\n const structType = await context.editor.schemaContext.getSchemaItem<StructClass>(structKey);\r\n if (structType === undefined) {\r\n return { errorMessage: `Unable to locate the struct ${structKey.name} in the context schema.` };\r\n }\r\n\r\n property.typeName = structKey.fullName;\r\n\r\n return arrayProperty.is(property)\r\n ? context.editor.entities.createStructArrayPropertyFromProps(itemKey, property.name, structType, property)\r\n : context.editor.entities.createStructPropertyFromProps(itemKey, property.name, structType, property);\r\n },\r\n async merge(_context, _itemKey, property, props) {\r\n if (\"structClass\" in props && props.structClass !== undefined) {\r\n return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };\r\n }\r\n return {};\r\n },\r\n};\r\n"]}
|