@itwin/ecschema-editing 4.5.0-dev.8 → 4.6.0-dev.0
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 +62 -1
- package/LICENSE.md +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +76 -0
- package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -0
- package/lib/cjs/Differencing/SchemaConflicts.js +56 -0
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +43 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +501 -0
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -0
- package/lib/cjs/Differencing/SchemaDifference.d.ts +150 -0
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -0
- package/lib/cjs/Differencing/SchemaDifference.js +54 -0
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -0
- package/lib/cjs/Editing/ECClasses.d.ts +9 -2
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +25 -0
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +8 -2
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +29 -6
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +7 -1
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +15 -0
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +7 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +20 -1
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +1 -5
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +4 -3
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +57 -49
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.d.ts +3 -2
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +22 -7
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +1 -5
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.d.ts +21 -0
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/PropertyMerger.js +315 -0
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -0
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts +15 -0
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/RelationshipClassMerger.js +132 -0
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -0
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +7 -3
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/ecschema-editing.d.ts +4 -0
- package/lib/cjs/ecschema-editing.d.ts.map +1 -1
- package/lib/cjs/ecschema-editing.js +4 -0
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +10 -10
- package/lib/cjs/Merging/AnyPropertyMerger.d.ts +0 -15
- package/lib/cjs/Merging/AnyPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/AnyPropertyMerger.js +0 -71
- package/lib/cjs/Merging/AnyPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/ArrayPropertyMerger.d.ts +0 -32
- package/lib/cjs/Merging/ArrayPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/ArrayPropertyMerger.js +0 -143
- package/lib/cjs/Merging/ArrayPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts +0 -16
- package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/ClassPropertyMerger.js +0 -90
- package/lib/cjs/Merging/ClassPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts +0 -24
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js +0 -106
- package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +0 -1
- package/lib/cjs/Merging/StructPropertyMerger.d.ts +0 -11
- package/lib/cjs/Merging/StructPropertyMerger.d.ts.map +0 -1
- package/lib/cjs/Merging/StructPropertyMerger.js +0 -47
- package/lib/cjs/Merging/StructPropertyMerger.js.map +0 -1
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPropertyFromProps = exports.mergePropertyAttributeValueChanges = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
9
|
+
async function mergePropertyAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
10
|
+
if (property.isEnumeration()) {
|
|
11
|
+
return EnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
12
|
+
}
|
|
13
|
+
if (property.isPrimitive()) {
|
|
14
|
+
return PrimitivePropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
15
|
+
}
|
|
16
|
+
if (property.isStruct()) {
|
|
17
|
+
return StructPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
18
|
+
}
|
|
19
|
+
if (property.isNavigation()) {
|
|
20
|
+
return NavigationPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Updates property with attribute value changes.
|
|
26
|
+
* @param context The current merging context.
|
|
27
|
+
* @param property The Property object to be changed.
|
|
28
|
+
* @param propertyValueChanges The changes to be applied to the property.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
async function mergePropertyAttributeValueChanges(context, property, propertyValueChanges) {
|
|
32
|
+
for (const change of propertyValueChanges) {
|
|
33
|
+
const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs;
|
|
34
|
+
const results = await mergePropertyAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
35
|
+
if (!results) {
|
|
36
|
+
return { errorMessage: `Property ${property.fullName} attribute ${attributeName} change is not implemented.` };
|
|
37
|
+
}
|
|
38
|
+
if (typeof results === "object" && "errorMessage" in results && results.errorMessage !== undefined) {
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { itemKey: property.class.key, propertyName: property.name };
|
|
43
|
+
}
|
|
44
|
+
exports.mergePropertyAttributeValueChanges = mergePropertyAttributeValueChanges;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Property through a PropertyProps.
|
|
47
|
+
* @param context The current merging context.
|
|
48
|
+
* @param classKey The SchemaItemKey of the class.
|
|
49
|
+
* @param property The Property object to be cloned.
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
async function createPropertyFromProps(context, classKey, property) {
|
|
53
|
+
let props = {};
|
|
54
|
+
if (property.category !== undefined) {
|
|
55
|
+
const sourceCategory = await property.category;
|
|
56
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(sourceCategory.name, context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)
|
|
57
|
+
? context.targetSchema.schemaKey
|
|
58
|
+
: sourceCategory.schema.schemaKey);
|
|
59
|
+
const targetCategory = await context.targetSchema.lookupItem(itemKey);
|
|
60
|
+
if (targetCategory === undefined) {
|
|
61
|
+
return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the context schema.` };
|
|
62
|
+
}
|
|
63
|
+
props = { ...props, category: targetCategory.fullName };
|
|
64
|
+
}
|
|
65
|
+
if (property.kindOfQuantity !== undefined) {
|
|
66
|
+
const sourceKoq = await property.kindOfQuantity;
|
|
67
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(sourceKoq.name, context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)
|
|
68
|
+
? context.targetSchema.schemaKey
|
|
69
|
+
: sourceKoq.schema.schemaKey);
|
|
70
|
+
const targetKoq = await context.targetSchema.lookupItem(itemKey);
|
|
71
|
+
if (targetKoq === undefined) {
|
|
72
|
+
return { errorMessage: `Unable to locate the property kind of quantity class ${sourceKoq.name} in the context schema.` };
|
|
73
|
+
}
|
|
74
|
+
props = { ...props, kindOfQuantity: targetKoq.fullName };
|
|
75
|
+
}
|
|
76
|
+
if (property.isEnumeration())
|
|
77
|
+
return EnumPropertyMerger.createFromProps(context, classKey, property, props);
|
|
78
|
+
if (property.isPrimitive())
|
|
79
|
+
return PrimitivePropertyMerger.createFromProps(context, classKey, property, props);
|
|
80
|
+
if (property.isStruct())
|
|
81
|
+
return StructPropertyMerger.createFromProps(context, classKey, property, props);
|
|
82
|
+
if (property.isNavigation())
|
|
83
|
+
return NavigationPropertyMerger.createFromProps(context, classKey, property, props);
|
|
84
|
+
return { errorMessage: `Unsupported Property Type: ${(0, ecschema_metadata_1.propertyTypeToString)(property.propertyType)}` };
|
|
85
|
+
}
|
|
86
|
+
exports.createPropertyFromProps = createPropertyFromProps;
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
var PropertyMerger;
|
|
91
|
+
(function (PropertyMerger) {
|
|
92
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, _attributeOldValue) {
|
|
93
|
+
const mutableProperty = property;
|
|
94
|
+
switch (attributeName) {
|
|
95
|
+
case "type":
|
|
96
|
+
return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };
|
|
97
|
+
case "description":
|
|
98
|
+
mutableProperty.setDescription(attributeNewValue);
|
|
99
|
+
return true;
|
|
100
|
+
case "label":
|
|
101
|
+
mutableProperty.setLabel(attributeNewValue);
|
|
102
|
+
return true;
|
|
103
|
+
case "isReadOnly":
|
|
104
|
+
mutableProperty.setIsReadOnly(attributeNewValue);
|
|
105
|
+
return true;
|
|
106
|
+
case "priority":
|
|
107
|
+
mutableProperty.setPriority(attributeNewValue);
|
|
108
|
+
return true;
|
|
109
|
+
case "category":
|
|
110
|
+
const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(attributeNewValue);
|
|
111
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(itemName, context.sourceSchema.schemaKey.compareByName(schemaName)
|
|
112
|
+
? context.targetSchema.schemaKey
|
|
113
|
+
: new ecschema_metadata_1.SchemaKey(schemaName));
|
|
114
|
+
return context.editor.entities.setPropertyCategory(property.class.key, property.name, itemKey);
|
|
115
|
+
case "kindOfQuantity":
|
|
116
|
+
return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
PropertyMerger.mergeAttributes = mergeAttributes;
|
|
121
|
+
})(PropertyMerger || (PropertyMerger = {}));
|
|
122
|
+
/**
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
var ArrayPropertyMerger;
|
|
126
|
+
(function (ArrayPropertyMerger) {
|
|
127
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
128
|
+
const mutableProperty = property;
|
|
129
|
+
switch (attributeName) {
|
|
130
|
+
case "minOccurs":
|
|
131
|
+
mutableProperty.setMinOccurs(attributeNewValue);
|
|
132
|
+
return true;
|
|
133
|
+
case "maxOccurs":
|
|
134
|
+
mutableProperty.setMaxOccurs(attributeNewValue);
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
138
|
+
}
|
|
139
|
+
ArrayPropertyMerger.mergeAttributes = mergeAttributes;
|
|
140
|
+
})(ArrayPropertyMerger || (ArrayPropertyMerger = {}));
|
|
141
|
+
/**
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
var PrimitiveOrEnumPropertyMerger;
|
|
145
|
+
(function (PrimitiveOrEnumPropertyMerger) {
|
|
146
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
147
|
+
const mutableProperty = property;
|
|
148
|
+
switch (attributeName) {
|
|
149
|
+
case "extendedTypeName": {
|
|
150
|
+
mutableProperty.setExtendedTypeName(attributeNewValue);
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
case "minLength": {
|
|
154
|
+
mutableProperty.setMinLength(attributeNewValue);
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
case "maxLength": {
|
|
158
|
+
mutableProperty.setMaxLength(attributeNewValue);
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
case "minValue": {
|
|
162
|
+
mutableProperty.setMinValue(attributeNewValue);
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
case "maxValue": {
|
|
166
|
+
mutableProperty.setMaxValue(attributeNewValue);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (property.isArray()) {
|
|
171
|
+
return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
172
|
+
}
|
|
173
|
+
return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
174
|
+
}
|
|
175
|
+
PrimitiveOrEnumPropertyMerger.mergeAttributes = mergeAttributes;
|
|
176
|
+
})(PrimitiveOrEnumPropertyMerger || (PrimitiveOrEnumPropertyMerger = {}));
|
|
177
|
+
/**
|
|
178
|
+
* @internal
|
|
179
|
+
*/
|
|
180
|
+
var EnumPropertyMerger;
|
|
181
|
+
(function (EnumPropertyMerger) {
|
|
182
|
+
async function createFromProps(context, classKey, property, props) {
|
|
183
|
+
if (property.enumeration === undefined) {
|
|
184
|
+
return { errorMessage: `Property ${property.fullName} is missing the required 'enumeration' attribute.` };
|
|
185
|
+
}
|
|
186
|
+
const enumeration = await property.enumeration;
|
|
187
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(enumeration.name, context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)
|
|
188
|
+
? context.targetSchema.schemaKey
|
|
189
|
+
: enumeration.schema.schemaKey);
|
|
190
|
+
const type = await context.targetSchema.lookupItem(itemKey);
|
|
191
|
+
if (type === undefined) {
|
|
192
|
+
return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the context schema.` };
|
|
193
|
+
}
|
|
194
|
+
const enumProps = {
|
|
195
|
+
...property.toJSON(),
|
|
196
|
+
...props,
|
|
197
|
+
typeName: type.fullName,
|
|
198
|
+
};
|
|
199
|
+
if (property.isArray()) {
|
|
200
|
+
return context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, enumProps);
|
|
201
|
+
}
|
|
202
|
+
return context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, enumProps);
|
|
203
|
+
}
|
|
204
|
+
EnumPropertyMerger.createFromProps = createFromProps;
|
|
205
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
206
|
+
switch (attributeName) {
|
|
207
|
+
case "enumeration":
|
|
208
|
+
return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };
|
|
209
|
+
}
|
|
210
|
+
return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
211
|
+
}
|
|
212
|
+
EnumPropertyMerger.mergeAttributes = mergeAttributes;
|
|
213
|
+
})(EnumPropertyMerger || (EnumPropertyMerger = {}));
|
|
214
|
+
/**
|
|
215
|
+
* @internal
|
|
216
|
+
*/
|
|
217
|
+
var PrimitivePropertyMerger;
|
|
218
|
+
(function (PrimitivePropertyMerger) {
|
|
219
|
+
async function createFromProps(context, classKey, property, props) {
|
|
220
|
+
const primitiveProps = {
|
|
221
|
+
...property.toJSON(),
|
|
222
|
+
...props,
|
|
223
|
+
};
|
|
224
|
+
if (property.isArray()) {
|
|
225
|
+
return context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);
|
|
226
|
+
}
|
|
227
|
+
return context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);
|
|
228
|
+
}
|
|
229
|
+
PrimitivePropertyMerger.createFromProps = createFromProps;
|
|
230
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
231
|
+
switch (attributeName) {
|
|
232
|
+
case "primitiveType":
|
|
233
|
+
return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };
|
|
234
|
+
}
|
|
235
|
+
return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
236
|
+
}
|
|
237
|
+
PrimitivePropertyMerger.mergeAttributes = mergeAttributes;
|
|
238
|
+
})(PrimitivePropertyMerger || (PrimitivePropertyMerger = {}));
|
|
239
|
+
/**
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
242
|
+
var StructPropertyMerger;
|
|
243
|
+
(function (StructPropertyMerger) {
|
|
244
|
+
async function createFromProps(context, classKey, property, props) {
|
|
245
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(property.structClass.name, context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)
|
|
246
|
+
? context.targetSchema.schemaKey
|
|
247
|
+
: property.structClass.schema.schemaKey);
|
|
248
|
+
const type = await context.targetSchema.lookupItem(itemKey);
|
|
249
|
+
if (type === undefined) {
|
|
250
|
+
return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the context schema.` };
|
|
251
|
+
}
|
|
252
|
+
const structProps = {
|
|
253
|
+
...property.toJSON(),
|
|
254
|
+
...props,
|
|
255
|
+
typeName: type.fullName,
|
|
256
|
+
};
|
|
257
|
+
if (property.isArray()) {
|
|
258
|
+
return context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, structProps);
|
|
259
|
+
}
|
|
260
|
+
return context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, structProps);
|
|
261
|
+
}
|
|
262
|
+
StructPropertyMerger.createFromProps = createFromProps;
|
|
263
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
264
|
+
switch (attributeName) {
|
|
265
|
+
case "structClass":
|
|
266
|
+
return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };
|
|
267
|
+
}
|
|
268
|
+
if (property.isArray()) {
|
|
269
|
+
return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
270
|
+
}
|
|
271
|
+
return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
272
|
+
}
|
|
273
|
+
StructPropertyMerger.mergeAttributes = mergeAttributes;
|
|
274
|
+
})(StructPropertyMerger || (StructPropertyMerger = {}));
|
|
275
|
+
/**
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
var NavigationPropertyMerger;
|
|
279
|
+
(function (NavigationPropertyMerger) {
|
|
280
|
+
async function createFromProps(context, classKey, property, props) {
|
|
281
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(property.relationshipClass.name, context.sourceSchema.schemaKey.matches(property.relationshipClass.schemaKey)
|
|
282
|
+
? context.targetSchema.schemaKey
|
|
283
|
+
: property.relationshipClass.schemaKey);
|
|
284
|
+
const type = await context.targetSchema.lookupItem(itemKey);
|
|
285
|
+
if (type === undefined) {
|
|
286
|
+
return { errorMessage: `Unable to locate the relationship class ${property.relationshipClass.name} in the context schema.` };
|
|
287
|
+
}
|
|
288
|
+
const navigationProps = {
|
|
289
|
+
...property.toJSON(),
|
|
290
|
+
...props,
|
|
291
|
+
relationshipName: type.fullName,
|
|
292
|
+
};
|
|
293
|
+
if (property.class.schemaItemType === ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
294
|
+
return context.editor.entities.createNavigationPropertyFromProps(classKey, navigationProps);
|
|
295
|
+
if (property.class.schemaItemType === ecschema_metadata_1.SchemaItemType.Mixin)
|
|
296
|
+
return context.editor.mixins.createNavigationPropertyFromProps(classKey, navigationProps);
|
|
297
|
+
if (property.class.schemaItemType === ecschema_metadata_1.SchemaItemType.RelationshipClass)
|
|
298
|
+
return context.editor.relationships.createNavigationPropertyFromProps(classKey, navigationProps);
|
|
299
|
+
return { errorMessage: `Navigation property can't be added to ${(0, ecschema_metadata_1.schemaItemTypeToString)(property.class.schemaItemType)}.` };
|
|
300
|
+
}
|
|
301
|
+
NavigationPropertyMerger.createFromProps = createFromProps;
|
|
302
|
+
async function mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue) {
|
|
303
|
+
switch (attributeName) {
|
|
304
|
+
case "direction": {
|
|
305
|
+
return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };
|
|
306
|
+
}
|
|
307
|
+
case "relationshipClass": {
|
|
308
|
+
return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);
|
|
312
|
+
}
|
|
313
|
+
NavigationPropertyMerger.mergeAttributes = mergeAttributes;
|
|
314
|
+
})(NavigationPropertyMerger || (NavigationPropertyMerger = {}));
|
|
315
|
+
//# sourceMappingURL=PropertyMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropertyMerger.js","sourceRoot":"","sources":["../../../src/Merging/PropertyMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAA8V;AAQ9V,KAAK,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,CAAC,QAAQ,EAAE,EAAE;QACvB,OAAO,oBAAoB,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;KACrH;IACD,IAAI,QAAQ,CAAC,YAAY,EAAE,EAAE;QAC3B,OAAO,wBAAwB,CAAC,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;KACzH;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,kCAAkC,CAAC,OAA2B,EAAE,QAAkB,EAAE,oBAA2C;I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BAAwB,QAqCjC","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 { AnyArrayProperty, AnyEnumerationProperty, AnyPrimitiveProperty, AnyStructProperty, Enumeration, KindOfQuantity, NavigationProperty, Property, PropertyCategory, PropertyProps, propertyTypeToString, RelationshipClass, SchemaItem, SchemaItemKey, SchemaItemType, schemaItemTypeToString, SchemaKey, StructClass } from \"@itwin/ecschema-metadata\";\nimport { SchemaMergeContext } from \"./SchemaMerger\";\nimport { PropertyEditResults } from \"../Editing/Editor\";\nimport { MutableProperty } from \"../Editing/Mutable/MutableProperty\";\nimport { MutableArrayProperty } from \"../Editing/Mutable/MutableArrayProperty\";\nimport { MutablePrimitiveOrEnumPropertyBase } from \"../Editing/Mutable/MutablePrimitiveOrEnumProperty\";\nimport { PropertyValueChange } from \"../Validation/SchemaChanges\";\n\nasync function mergePropertyAttributes(context: SchemaMergeContext, property: Property, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n if (property.isEnumeration()) {\n return EnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n if (property.isPrimitive()) {\n return PrimitivePropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n if (property.isStruct()) {\n return StructPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n if (property.isNavigation()) {\n return NavigationPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n return false;\n}\n\n/**\n * Updates property with attribute value changes.\n * @param context The current merging context.\n * @param property The Property object to be changed.\n * @param propertyValueChanges The changes to be applied to the property.\n * @internal\n */\nexport async function mergePropertyAttributeValueChanges(context: SchemaMergeContext, property: Property, propertyValueChanges: PropertyValueChange[]): Promise<PropertyEditResults> {\n for (const change of propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = change.diagnostic.messageArgs!;\n const results = await mergePropertyAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n if (!results) {\n return { errorMessage: `Property ${property.fullName} attribute ${attributeName} change is not implemented.` };\n }\n if (typeof results === \"object\" && \"errorMessage\" in results && results.errorMessage !== undefined) {\n return results;\n }\n }\n return { itemKey: property.class.key, propertyName: property.name };\n}\n\n/**\n * Creates a Property through a PropertyProps.\n * @param context The current merging context.\n * @param classKey The SchemaItemKey of the class.\n * @param property The Property object to be cloned.\n * @internal\n */\nexport async function createPropertyFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: Property): Promise<PropertyEditResults> {\n let props = {} as PropertyProps;\n\n if (property.category !== undefined) {\n const sourceCategory = await property.category;\n const itemKey = new SchemaItemKey(sourceCategory.name, context.sourceSchema.schemaKey.matches(sourceCategory.schema.schemaKey)\n ? context.targetSchema.schemaKey\n : sourceCategory.schema.schemaKey,\n );\n const targetCategory = await context.targetSchema.lookupItem<PropertyCategory>(itemKey);\n if (targetCategory === undefined) {\n return { errorMessage: `Unable to locate the property category class ${sourceCategory.name} in the context schema.` };\n }\n props = {...props, category: targetCategory.fullName};\n }\n\n if (property.kindOfQuantity !== undefined) {\n const sourceKoq = await property.kindOfQuantity;\n const itemKey = new SchemaItemKey(sourceKoq.name, context.sourceSchema.schemaKey.matches(sourceKoq.schema.schemaKey)\n ? context.targetSchema.schemaKey\n : sourceKoq.schema.schemaKey,\n );\n const targetKoq = await context.targetSchema.lookupItem<KindOfQuantity>(itemKey);\n if (targetKoq === undefined) {\n return { errorMessage: `Unable to locate the property kind of quantity class ${sourceKoq.name} in the context schema.` };\n }\n props = {...props, kindOfQuantity: targetKoq.fullName};\n }\n if (property.isEnumeration())\n return EnumPropertyMerger.createFromProps(context, classKey, property, props);\n if (property.isPrimitive())\n return PrimitivePropertyMerger.createFromProps(context, classKey, property, props);\n if (property.isStruct())\n return StructPropertyMerger.createFromProps(context, classKey, property, props);\n if (property.isNavigation())\n return NavigationPropertyMerger.createFromProps(context, classKey, property, props);\n\n return { errorMessage: `Unsupported Property Type: ${propertyTypeToString(property.propertyType)}` };\n}\n\n/**\n * @internal\n */\nnamespace PropertyMerger {\n export async function mergeAttributes(context: SchemaMergeContext, property: Property, attributeName: string, attributeNewValue: any, _attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const mutableProperty = property as unknown as MutableProperty;\n switch(attributeName) {\n case \"type\":\n return { errorMessage: `Changing the property '${property.fullName}' type is not supported.` };\n case \"description\":\n mutableProperty.setDescription(attributeNewValue);\n return true;\n case \"label\":\n mutableProperty.setLabel(attributeNewValue);\n return true;\n case \"isReadOnly\":\n mutableProperty.setIsReadOnly(attributeNewValue);\n return true;\n case \"priority\":\n mutableProperty.setPriority(attributeNewValue);\n return true;\n case \"category\":\n const [schemaName, itemName] = SchemaItem.parseFullName(attributeNewValue);\n const itemKey = new SchemaItemKey(itemName, context.sourceSchema.schemaKey.compareByName(schemaName)\n ? context.targetSchema.schemaKey\n : new SchemaKey(schemaName),\n );\n return context.editor.entities.setPropertyCategory(property.class.key, property.name, itemKey);\n case \"kindOfQuantity\":\n return { errorMessage: `Changing the property '${property.fullName}' kind of quantity is not supported.` };\n }\n return false;\n }\n}\n\n/**\n * @internal\n */\nnamespace ArrayPropertyMerger {\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyArrayProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n const mutableProperty = property as unknown as MutableArrayProperty;\n switch (attributeName) {\n case \"minOccurs\":\n mutableProperty.setMinOccurs(attributeNewValue);\n return true;\n\n case \"maxOccurs\":\n mutableProperty.setMaxOccurs(attributeNewValue);\n return true;\n }\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n}\n\n/**\n * @internal\n */\nnamespace PrimitiveOrEnumPropertyMerger {\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyPrimitiveProperty | AnyEnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\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 if (property.isArray()) {\n return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n}\n\n/**\n * @internal\n */\nnamespace EnumPropertyMerger {\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: AnyEnumerationProperty, props: PropertyProps): Promise<PropertyEditResults> {\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, context.sourceSchema.schemaKey.matches(enumeration.schema.schemaKey)\n ? context.targetSchema.schemaKey\n : enumeration.schema.schemaKey,\n );\n const type = await context.targetSchema.lookupItem<Enumeration>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the enumeration class ${enumeration.name} in the context schema.` };\n }\n\n const enumProps = {\n ...property.toJSON(),\n ...props,\n typeName: type.fullName,\n };\n\n if (property.isArray()) {\n return context.editor.entities.createEnumerationArrayPropertyFromProps(classKey, property.name, type, enumProps);\n }\n return context.editor.entities.createEnumerationPropertyFromProps(classKey, property.name, type, enumProps);\n }\n\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyEnumerationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n switch (attributeName) {\n case \"enumeration\":\n return { errorMessage: `Changing the property '${property.fullName}' enumeration is not supported.` };\n }\n return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n}\n\n/**\n * @internal\n */\nnamespace PrimitivePropertyMerger {\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: AnyPrimitiveProperty, props: PropertyProps): Promise<PropertyEditResults> {\n const primitiveProps = {\n ...property.toJSON(),\n ...props,\n };\n\n if (property.isArray()) {\n return context.editor.entities.createPrimitiveArrayPropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);\n }\n return context.editor.entities.createPrimitivePropertyFromProps(classKey, property.name, property.primitiveType, primitiveProps);\n }\n\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyPrimitiveProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n switch (attributeName) {\n case \"primitiveType\":\n return { errorMessage: `Changing the property '${property.fullName}' primitiveType is not supported.` };\n }\n return PrimitiveOrEnumPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n}\n\n/**\n * @internal\n */\nnamespace StructPropertyMerger {\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: AnyStructProperty, props: PropertyProps): Promise<PropertyEditResults> {\n const itemKey = new SchemaItemKey(property.structClass.name, context.sourceSchema.schemaKey.matches(property.structClass.schema.schemaKey)\n ? context.targetSchema.schemaKey\n : property.structClass.schema.schemaKey,\n );\n const type = await context.targetSchema.lookupItem<StructClass>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the struct class ${property.structClass.name} in the context schema.` };\n }\n\n const structProps = {\n ...property.toJSON(),\n ...props,\n typeName: type.fullName,\n };\n\n if (property.isArray()) {\n return context.editor.entities.createStructArrayPropertyFromProps(classKey, property.name, type, structProps);\n }\n return context.editor.entities.createStructPropertyFromProps(classKey, property.name, type, structProps);\n }\n\n export async function mergeAttributes(context: SchemaMergeContext, property: AnyStructProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n switch (attributeName) {\n case \"structClass\":\n return { errorMessage: `Changing the property '${property.fullName}' structClass is not supported.` };\n }\n if (property.isArray()) {\n return ArrayPropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n}\n\n/**\n * @internal\n */\nnamespace NavigationPropertyMerger {\n export async function createFromProps(context: SchemaMergeContext, classKey: SchemaItemKey, property: NavigationProperty, props: PropertyProps): Promise<PropertyEditResults> {\n const itemKey = new SchemaItemKey(property.relationshipClass.name, context.sourceSchema.schemaKey.matches(property.relationshipClass.schemaKey)\n ? context.targetSchema.schemaKey\n : property.relationshipClass.schemaKey,\n );\n const type = await context.targetSchema.lookupItem<RelationshipClass>(itemKey);\n if (type === undefined) {\n return { errorMessage: `Unable to locate the relationship class ${property.relationshipClass.name} in the context schema.` };\n }\n\n const navigationProps = {\n ...property.toJSON(),\n ...props,\n relationshipName: type.fullName,\n };\n\n if (property.class.schemaItemType === SchemaItemType.EntityClass)\n return context.editor.entities.createNavigationPropertyFromProps(classKey, navigationProps);\n if (property.class.schemaItemType === SchemaItemType.Mixin)\n return context.editor.mixins.createNavigationPropertyFromProps(classKey, navigationProps);\n if (property.class.schemaItemType === SchemaItemType.RelationshipClass)\n return context.editor.relationships.createNavigationPropertyFromProps(classKey, navigationProps);\n return { errorMessage: `Navigation property can't be added to ${schemaItemTypeToString(property.class.schemaItemType)}.` };\n }\n\n export async function mergeAttributes(context: SchemaMergeContext, property: NavigationProperty, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<PropertyEditResults | boolean> {\n switch (attributeName) {\n case \"direction\": {\n return { errorMessage: `Changing the property '${property.fullName}' direction is not supported.` };\n }\n case \"relationshipClass\": {\n return { errorMessage: `Changing the property '${property.fullName}' relationship class is not supported.` };\n }\n }\n return PropertyMerger.mergeAttributes(context, property, attributeName, attributeNewValue, attributeOldValue);\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RelationshipClass, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
2
|
+
import { ClassMerger } from "./ClassMerger";
|
|
3
|
+
import { SchemaItemEditResults } from "../Editing/Editor";
|
|
4
|
+
import { ClassChanges } from "../Validation/SchemaChanges";
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export default class RelationshipClassMerger extends ClassMerger<RelationshipClass> {
|
|
9
|
+
protected create(schemaKey: SchemaKey, ecClass: RelationshipClass): Promise<SchemaItemEditResults>;
|
|
10
|
+
protected mergeAttributes(ecClass: RelationshipClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean>;
|
|
11
|
+
private mergeConstraintAttributes;
|
|
12
|
+
private mergeConstraintChanges;
|
|
13
|
+
protected merge(itemKey: SchemaItemKey, changes: ClassChanges): Promise<SchemaItemEditResults>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=RelationshipClassMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationshipClassMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAA6D,iBAAiB,EAAgE,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAChN,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAiC,MAAM,6BAA6B,CAAC;AAK1F;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,WAAW,CAAC,iBAAiB,CAAC;cAExD,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAIxF,eAAe,CAAC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAAC,qBAAqB,GAAG,OAAO,CAAC;YA4BvK,yBAAyB;YAqCzB,sBAAsB;cAwCX,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAyB9G"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
5
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
|
7
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
8
|
+
const ClassMerger_1 = require("./ClassMerger");
|
|
9
|
+
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
class RelationshipClassMerger extends ClassMerger_1.ClassMerger {
|
|
14
|
+
async create(schemaKey, ecClass) {
|
|
15
|
+
return this.context.editor.relationships.create(schemaKey, ecClass.name, ecClass.modifier, ecClass.strength, ecClass.strengthDirection);
|
|
16
|
+
}
|
|
17
|
+
async mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue) {
|
|
18
|
+
const mutableRelationship = ecClass;
|
|
19
|
+
switch (attributeName) {
|
|
20
|
+
case "strength":
|
|
21
|
+
if (attributeOldValue === undefined) {
|
|
22
|
+
const strength = (0, ecschema_metadata_1.parseStrength)(attributeNewValue);
|
|
23
|
+
if (strength === undefined) {
|
|
24
|
+
return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strength value '${attributeNewValue}' has been provided.` };
|
|
25
|
+
}
|
|
26
|
+
mutableRelationship.setStrength(strength);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return { errorMessage: `Changing the relationship '${ecClass.name}' strength is not supported.` };
|
|
30
|
+
case "strengthDirection":
|
|
31
|
+
if (attributeOldValue === undefined) {
|
|
32
|
+
const strengthDirection = (0, ecschema_metadata_1.parseStrengthDirection)(attributeNewValue);
|
|
33
|
+
if (strengthDirection === undefined) {
|
|
34
|
+
return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strengthDirection value '${attributeNewValue}' has been provided.` };
|
|
35
|
+
}
|
|
36
|
+
mutableRelationship.setStrengthDirection(strengthDirection);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return { errorMessage: `Changing the relationship '${ecClass.name}' strengthDirection is not supported.` };
|
|
40
|
+
}
|
|
41
|
+
return super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);
|
|
42
|
+
}
|
|
43
|
+
async mergeConstraintAttributes(constraint, attributeName, attributeNewValue, attributeOldValue) {
|
|
44
|
+
switch (attributeName) {
|
|
45
|
+
case "multiplicity":
|
|
46
|
+
if (attributeOldValue === undefined) {
|
|
47
|
+
const multiplicity = ecschema_metadata_1.RelationshipMultiplicity.fromString(attributeNewValue);
|
|
48
|
+
if (multiplicity === undefined) {
|
|
49
|
+
return { errorMessage: `An invalid relationship constraint multiplicity value '${attributeNewValue}' has been provided.` };
|
|
50
|
+
}
|
|
51
|
+
return this.context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);
|
|
52
|
+
}
|
|
53
|
+
return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.` };
|
|
54
|
+
case "polymorphic":
|
|
55
|
+
if (attributeOldValue === undefined || attributeNewValue === true) {
|
|
56
|
+
return this.context.editor.relationships.setConstraintPolymorphic(constraint, attributeNewValue);
|
|
57
|
+
}
|
|
58
|
+
return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' polymorphic is not supported.` };
|
|
59
|
+
case "roleLabel":
|
|
60
|
+
constraint.roleLabel = attributeNewValue;
|
|
61
|
+
return true;
|
|
62
|
+
case "abstractConstraint":
|
|
63
|
+
const [schemaName, itemName] = ecschema_metadata_1.SchemaItem.parseFullName(attributeNewValue);
|
|
64
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(itemName, this.context.sourceSchema.schemaKey.compareByName(schemaName)
|
|
65
|
+
? this.context.targetSchema.schemaKey
|
|
66
|
+
: new ecschema_metadata_1.SchemaKey(schemaName));
|
|
67
|
+
const abstractConstraint = await this.context.targetSchema.lookupItem(itemKey);
|
|
68
|
+
if (abstractConstraint === undefined) {
|
|
69
|
+
return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the abstract constraint class ${attributeNewValue} in the context schema.` };
|
|
70
|
+
}
|
|
71
|
+
return this.context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
async mergeConstraintChanges(constraint, constraintChanges) {
|
|
76
|
+
for (const change of constraintChanges) {
|
|
77
|
+
for (const constraintClassChange of change.constraintClassChanges) {
|
|
78
|
+
const ecClass = constraintClassChange.diagnostic.messageArgs[0];
|
|
79
|
+
const itemKey = new ecschema_metadata_1.SchemaItemKey(ecClass.name, this.context.sourceSchema.schemaKey.matches(ecClass.schema.schemaKey)
|
|
80
|
+
? this.context.targetSchema.schemaKey
|
|
81
|
+
: ecClass.schema.schemaKey);
|
|
82
|
+
const constaintClass = await this.context.targetSchema.lookupItem(itemKey);
|
|
83
|
+
if (constaintClass === undefined) {
|
|
84
|
+
return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the constraint class ${itemKey.fullName} in the context schema.` };
|
|
85
|
+
}
|
|
86
|
+
const results = await this.context.editor.relationships.addConstraintClass(constraint, constaintClass);
|
|
87
|
+
if (results.errorMessage !== undefined) {
|
|
88
|
+
return results;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const propertyValueChange of change.propertyValueChanges) {
|
|
92
|
+
const [attributeName, attributeNewValue, attributeOldValue] = propertyValueChange.diagnostic.messageArgs;
|
|
93
|
+
const results = await this.mergeConstraintAttributes(constraint, attributeName, attributeNewValue, attributeOldValue);
|
|
94
|
+
if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (change.customAttributeChanges.size > 0) {
|
|
99
|
+
const results = await (0, CustomAttributeMerger_1.mergeCustomAttributes)(this.context, change.customAttributeChanges.values(), async (ca) => {
|
|
100
|
+
return this.context.editor.relationships.addCustomAttributeToConstraint(constraint, ca);
|
|
101
|
+
});
|
|
102
|
+
if (results.errorMessage !== undefined) {
|
|
103
|
+
return results;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { itemKey: constraint.relationshipClass.key };
|
|
108
|
+
}
|
|
109
|
+
async merge(itemKey, changes) {
|
|
110
|
+
if (changes.sourceConstraintChanges.size > 0 || changes.targetConstraintChanges.size > 0) {
|
|
111
|
+
const relationshipClass = await this.context.targetSchema.lookupItem(itemKey);
|
|
112
|
+
if (relationshipClass === undefined) {
|
|
113
|
+
return { itemKey, errorMessage: `Unable to locate the relationship class ${itemKey.name} in the context schema.` };
|
|
114
|
+
}
|
|
115
|
+
if (changes.sourceConstraintChanges.size > 0) {
|
|
116
|
+
const result = await this.mergeConstraintChanges(relationshipClass.source, changes.sourceConstraintChanges.values());
|
|
117
|
+
if (result.errorMessage !== undefined) {
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (changes.targetConstraintChanges.size > 0) {
|
|
122
|
+
const result = await this.mergeConstraintChanges(relationshipClass.target, changes.targetConstraintChanges.values());
|
|
123
|
+
if (result.errorMessage !== undefined) {
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { itemKey };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.default = RelationshipClassMerger;
|
|
132
|
+
//# sourceMappingURL=RelationshipClassMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RelationshipClassMerger.js","sourceRoot":"","sources":["../../../src/Merging/RelationshipClassMerger.ts"],"names":[],"mappings":";;AAAA;;;+FAG+F;AAC/F,gEAAgN;AAChN,+CAA4C;AAK5C,mEAAgE;AAEhE;;GAEG;AACH,MAAqB,uBAAwB,SAAQ,yBAA8B;IAE9D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,OAA0B;QAC9E,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC1I,CAAC;IAEkB,KAAK,CAAC,eAAe,CAAC,OAA0B,EAAE,aAAqB,EAAE,iBAAsB,EAAE,iBAAsB;QACxI,MAAM,mBAAmB,GAAG,OAA8C,CAAC;QAC3E,QAAO,aAAa,EAAE;YACpB,KAAK,UAAU;gBACb,IAAI,iBAAiB,KAAK,SAAS,EAAE;oBACnC,MAAM,QAAQ,GAAG,IAAA,iCAAa,EAAC,iBAAiB,CAAC,CAAC;oBAClD,IAAI,QAAQ,KAAK,SAAS,EAAE;wBAC1B,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,YAAY,EAAE,iDAAiD,iBAAiB,sBAAsB,EAAE,CAAC;qBACzI;oBACD,mBAAmB,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;oBAC1C,OAAO,IAAI,CAAC;iBACb;gBACD,OAAO,EAAE,YAAY,EAAE,8BAA8B,OAAO,CAAC,IAAI,8BAA8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CAAC,uBAAuB,CAAC,IAAI,GAAG,CAAC,EAAE;gBAC5C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC;gBACrH,IAAI,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE;oBACrC,OAAO,MAAM,CAAC;iBACf;aACF;SACF;QAED,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF;AAxID,0CAwIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\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 { EntityClass, Mixin, parseStrength, parseStrengthDirection, RelationshipClass, RelationshipConstraint, RelationshipMultiplicity, SchemaItem, SchemaItemKey, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { ClassMerger } from \"./ClassMerger\";\nimport { SchemaItemEditResults } from \"../Editing/Editor\";\nimport { ClassChanges, RelationshipConstraintChanges } from \"../Validation/SchemaChanges\";\nimport { MutableRelationshipClass } from \"@itwin/ecschema-metadata/src/Metadata/RelationshipClass\";\nimport { MutableRelationshipConstraint } from \"../Editing/Mutable/MutableRelationshipClass\";\nimport { mergeCustomAttributes } from \"./CustomAttributeMerger\";\n\n/**\n * @internal\n */\nexport default class RelationshipClassMerger extends ClassMerger<RelationshipClass> {\n\n protected override async create(schemaKey: SchemaKey, ecClass: RelationshipClass): Promise<SchemaItemEditResults> {\n return this.context.editor.relationships.create(schemaKey, ecClass.name, ecClass.modifier, ecClass.strength, ecClass.strengthDirection);\n }\n\n protected override async mergeAttributes(ecClass: RelationshipClass, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n const mutableRelationship = ecClass as unknown as MutableRelationshipClass;\n switch(attributeName) {\n case \"strength\":\n if (attributeOldValue === undefined) {\n const strength = parseStrength(attributeNewValue);\n if (strength === undefined) {\n return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strength value '${attributeNewValue}' has been provided.` };\n }\n mutableRelationship.setStrength(strength);\n return true;\n }\n return { errorMessage: `Changing the relationship '${ecClass.name}' strength is not supported.` };\n\n case \"strengthDirection\":\n if (attributeOldValue === undefined) {\n const strengthDirection = parseStrengthDirection(attributeNewValue);\n if (strengthDirection === undefined) {\n return { itemKey: ecClass.key, errorMessage: `An invalid relationship class strengthDirection value '${attributeNewValue}' has been provided.` };\n }\n mutableRelationship.setStrengthDirection(strengthDirection);\n return true;\n }\n return { errorMessage: `Changing the relationship '${ecClass.name}' strengthDirection is not supported.` };\n }\n return super.mergeAttributes(ecClass, attributeName, attributeNewValue, attributeOldValue);\n }\n\n private async mergeConstraintAttributes(constraint: RelationshipConstraint, attributeName: string, attributeNewValue: any, attributeOldValue: any): Promise<SchemaItemEditResults | boolean> {\n switch(attributeName) {\n case \"multiplicity\":\n if (attributeOldValue === undefined) {\n const multiplicity = RelationshipMultiplicity.fromString(attributeNewValue);\n if (multiplicity === undefined) {\n return { errorMessage: `An invalid relationship constraint multiplicity value '${attributeNewValue}' has been provided.` };\n }\n return this.context.editor.relationships.setConstraintMultiplicity(constraint, multiplicity);\n }\n return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' multiplicity is not supported.` };\n\n case \"polymorphic\":\n if (attributeOldValue === undefined || attributeNewValue === true) {\n return this.context.editor.relationships.setConstraintPolymorphic(constraint, attributeNewValue);\n }\n return { errorMessage: `Changing the relationship constraint '${constraint.fullName}' polymorphic is not supported.` };\n\n case \"roleLabel\":\n (constraint as MutableRelationshipConstraint).roleLabel = attributeNewValue;\n return true;\n\n case \"abstractConstraint\":\n const [schemaName, itemName] = SchemaItem.parseFullName(attributeNewValue);\n const itemKey = new SchemaItemKey(itemName, this.context.sourceSchema.schemaKey.compareByName(schemaName)\n ? this.context.targetSchema.schemaKey\n : new SchemaKey(schemaName));\n\n const abstractConstraint = await this.context.targetSchema.lookupItem<Mixin | EntityClass | RelationshipClass>(itemKey);\n if (abstractConstraint === undefined) {\n return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the abstract constraint class ${attributeNewValue} in the context schema.`};\n }\n return this.context.editor.relationships.setAbstractConstraint(constraint, abstractConstraint);\n }\n return false;\n }\n\n private async mergeConstraintChanges(constraint: RelationshipConstraint, constraintChanges: IterableIterator<RelationshipConstraintChanges>): Promise<SchemaItemEditResults> {\n for (const change of constraintChanges) {\n\n for (const constraintClassChange of change.constraintClassChanges) {\n const ecClass = constraintClassChange.diagnostic.messageArgs![0];\n const itemKey = new SchemaItemKey(ecClass.name, this.context.sourceSchema.schemaKey.matches(ecClass.schema.schemaKey)\n ? this.context.targetSchema.schemaKey\n : ecClass.schema.schemaKey);\n\n const constaintClass = await this.context.targetSchema.lookupItem<Mixin | EntityClass | RelationshipClass>(itemKey);\n if (constaintClass === undefined) {\n return { itemKey: constraint.relationshipClass.key, errorMessage: `Unable to locate the constraint class ${itemKey.fullName} in the context schema.` };\n }\n const results = await this.context.editor.relationships.addConstraintClass(constraint, constaintClass);\n if (results.errorMessage !== undefined) {\n return results;\n }\n }\n\n for (const propertyValueChange of change.propertyValueChanges) {\n const [attributeName, attributeNewValue, attributeOldValue] = propertyValueChange.diagnostic.messageArgs!;\n const results = await this.mergeConstraintAttributes(constraint, attributeName, attributeNewValue, attributeOldValue);\n if (this.isSchemaItemEditResults(results) && results.errorMessage !== undefined) {\n return results;\n }\n }\n\n if (change.customAttributeChanges.size > 0) {\n const results = await mergeCustomAttributes(this.context, change.customAttributeChanges.values(), async (ca) => {\n return this.context.editor.relationships.addCustomAttributeToConstraint(constraint, ca);\n });\n if (results.errorMessage !== undefined) {\n return results;\n }\n }\n }\n\n return { itemKey: constraint.relationshipClass.key };\n }\n\n protected override async merge(itemKey: SchemaItemKey, changes: ClassChanges): Promise<SchemaItemEditResults> {\n if (changes.sourceConstraintChanges.size > 0 || changes.targetConstraintChanges.size > 0) {\n\n const relationshipClass = await this.context.targetSchema.lookupItem<RelationshipClass>(itemKey);\n if (relationshipClass === undefined) {\n return { itemKey, errorMessage: `Unable to locate the relationship class ${itemKey.name} in the context schema.` };\n }\n\n if (changes.sourceConstraintChanges.size > 0) {\n const result = await this.mergeConstraintChanges(relationshipClass.source, changes.sourceConstraintChanges.values());\n if (result.errorMessage !== undefined) {\n return result;\n }\n }\n\n if (changes.targetConstraintChanges.size > 0) {\n const result = await this.mergeConstraintChanges(relationshipClass.target, changes.targetConstraintChanges.values());\n if (result.errorMessage !== undefined) {\n return result;\n }\n }\n }\n\n return { itemKey };\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;AAcxD;;;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;CA0ChF"}
|
|
@@ -21,6 +21,7 @@ const StructClassMerger_1 = require("./StructClassMerger");
|
|
|
21
21
|
const MixinMerger_1 = require("./MixinMerger");
|
|
22
22
|
const CustomAttributeMerger_1 = require("./CustomAttributeMerger");
|
|
23
23
|
const KindOfQuantityMerger_1 = require("./KindOfQuantityMerger");
|
|
24
|
+
const RelationshipClassMerger_1 = require("./RelationshipClassMerger");
|
|
24
25
|
/**
|
|
25
26
|
* Class to merge two schemas together.
|
|
26
27
|
* @see [[merge]] to merge the schemas.
|
|
@@ -70,11 +71,13 @@ class SchemaMerger {
|
|
|
70
71
|
await StructClassMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.structClasses);
|
|
71
72
|
await EntityClassMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.entityClasses);
|
|
72
73
|
await MixinMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.mixins);
|
|
74
|
+
await RelationshipClassMerger_1.default.mergeItemStubChanges(mergeContext, itemChanges.relationships);
|
|
73
75
|
// 2nd pass to complete merge changes such as properties, baseClasses and mixins.
|
|
74
76
|
await CAClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.customAttributeClasses);
|
|
75
77
|
await StructClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.structClasses);
|
|
76
78
|
await EntityClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.entityClasses);
|
|
77
79
|
await MixinMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.mixins);
|
|
80
|
+
await RelationshipClassMerger_1.default.mergeItemContentChanges(mergeContext, itemChanges.relationships);
|
|
78
81
|
await (0, CustomAttributeMerger_1.mergeCustomAttributes)(mergeContext, schemaChanges.customAttributeChanges.values(), async (ca) => {
|
|
79
82
|
return mergeContext.editor.addCustomAttribute(mergeContext.targetSchema.schemaKey, ca);
|
|
80
83
|
});
|
|
@@ -90,16 +93,17 @@ exports.SchemaMerger = SchemaMerger;
|
|
|
90
93
|
*/
|
|
91
94
|
function getSchemaItemChanges(schemaChanges) {
|
|
92
95
|
return {
|
|
93
|
-
get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.EntityClass); },
|
|
94
96
|
get constants() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Constant); },
|
|
95
97
|
get customAttributeClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.CustomAttributeClass); },
|
|
98
|
+
get entityClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.EntityClass); },
|
|
96
99
|
get enumeratations() { return schemaChanges.enumerationChanges.values(); },
|
|
97
100
|
get kindOfQuantities() { return schemaChanges.kindOfQuantityChanges.values(); },
|
|
101
|
+
get mixins() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.Mixin); },
|
|
98
102
|
get phenomenons() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.Phenomenon); },
|
|
99
103
|
get propertyCategories() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.PropertyCategory); },
|
|
100
|
-
get
|
|
104
|
+
get relationships() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.RelationshipClass); },
|
|
101
105
|
get structClasses() { return filterChangesByItemType(schemaChanges.classChanges, ecschema_metadata_1.SchemaItemType.StructClass); },
|
|
102
|
-
get
|
|
106
|
+
get unitSystems() { return filterChangesByItemType(schemaChanges.schemaItemChanges, ecschema_metadata_1.SchemaItemType.UnitSystem); },
|
|
103
107
|
};
|
|
104
108
|
}
|
|
105
109
|
/**
|