@itwin/ecschema-editing 4.6.0-dev.15 → 4.6.0-dev.16
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/Editing/ECClasses.d.ts +25 -23
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +25 -97
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts +8 -0
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js +16 -0
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts +8 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts.map +1 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.js +16 -0
- package/lib/cjs/Editing/Mutable/MutableStructProperty.js.map +1 -0
- package/lib/cjs/Editing/Properties.d.ts +199 -0
- package/lib/cjs/Editing/Properties.d.ts.map +1 -0
- package/lib/cjs/Editing/Properties.js +345 -0
- package/lib/cjs/Editing/Properties.js.map +1 -0
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +6 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +8 -2
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Properties.d.ts","sourceRoot":"","sources":["../../../src/Editing/Properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAEJ,aAAa,EAAkB,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAE,oBAAoB,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AAS,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAQ/H;AAED;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,yBAAyB;gBAC/C,aAAa,EAAE,mBAAmB;IAIrD;;;;OAIG;cACsB,WAAW,CAAC,CAAC,SAAS,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAQ/H;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;gBAC/B,aAAa,EAAE,mBAAmB;IAIrD;;;;OAIG;cACsB,WAAW,CAAC,CAAC,SAAS,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAQ/H;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;gBAC3B,aAAa,EAAE,mBAAmB;IAIrD;;;;OAIG;cACsB,WAAW,CAAC,CAAC,SAAS,mBAAmB,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAQ/H"}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StructProperties = exports.NavigationProperties = exports.EnumerationProperties = exports.PrimitiveProperties = exports.ArrayProperties = exports.Properties = void 0;
|
|
4
|
+
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
5
|
+
const Rules = require("../Validation/ECRules");
|
|
6
|
+
/**
|
|
7
|
+
* @alpha
|
|
8
|
+
* A class allowing editing of attributes of the base Property class.
|
|
9
|
+
*/
|
|
10
|
+
class Properties {
|
|
11
|
+
constructor(_schemaEditor) {
|
|
12
|
+
this._schemaEditor = _schemaEditor;
|
|
13
|
+
}
|
|
14
|
+
async setName(classKey, propertyName, newPropertyName) {
|
|
15
|
+
const newName = new ecschema_metadata_1.ECName(newPropertyName);
|
|
16
|
+
const existingProperty = await this.getProperty(classKey, propertyName);
|
|
17
|
+
const baseProperty = await existingProperty.class.getProperty(newPropertyName, true);
|
|
18
|
+
if (baseProperty)
|
|
19
|
+
throw new Error(`An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.`);
|
|
20
|
+
// Handle derived classes
|
|
21
|
+
const derivedProperties = [];
|
|
22
|
+
const derivedClasses = await this.findDerivedClasses(existingProperty.class);
|
|
23
|
+
for (const derivedClass of derivedClasses) {
|
|
24
|
+
if (await derivedClass.getProperty(newPropertyName))
|
|
25
|
+
throw new Error(`An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.`);
|
|
26
|
+
const propertyOverride = await derivedClass.getProperty(propertyName);
|
|
27
|
+
// If found the property is overridden in the derived class.
|
|
28
|
+
if (propertyOverride)
|
|
29
|
+
derivedProperties.push(propertyOverride);
|
|
30
|
+
}
|
|
31
|
+
// Re-name the overridden property in all derived classes
|
|
32
|
+
derivedProperties.forEach((prop) => {
|
|
33
|
+
prop.setName(newName);
|
|
34
|
+
});
|
|
35
|
+
existingProperty.setName(newName);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Sets the property description.
|
|
39
|
+
* @param classKey The SchemaItemKey of the class.
|
|
40
|
+
* @param propertyName The name of the property.
|
|
41
|
+
* @param description The new description to set.
|
|
42
|
+
*/
|
|
43
|
+
async setDescription(classKey, propertyName, description) {
|
|
44
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
45
|
+
property.setDescription(description);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the property label.
|
|
49
|
+
* @param classKey The SchemaItemKey of the class.
|
|
50
|
+
* @param propertyName The name of the property.
|
|
51
|
+
* @param label The new label to set.
|
|
52
|
+
*/
|
|
53
|
+
async setLabel(classKey, propertyName, label) {
|
|
54
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
55
|
+
property.setLabel(label);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the property isReadOnly attribute.
|
|
59
|
+
* @param classKey The SchemaItemKey of the class.
|
|
60
|
+
* @param propertyName The name of the property.
|
|
61
|
+
* @param isReadOnly The new isReadOnly value.
|
|
62
|
+
*/
|
|
63
|
+
async setIsReadOnly(classKey, propertyName, isReadOnly) {
|
|
64
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
65
|
+
property.setIsReadOnly(isReadOnly);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sets the property priority.
|
|
69
|
+
* @param classKey The SchemaItemKey of the class.
|
|
70
|
+
* @param propertyName The name of the property.
|
|
71
|
+
* @param priority The new priority.
|
|
72
|
+
*/
|
|
73
|
+
async setPriority(classKey, propertyName, priority) {
|
|
74
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
75
|
+
property.setPriority(priority);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sets the property category.
|
|
79
|
+
* @param classKey The SchemaItemKey of the class.
|
|
80
|
+
* @param propertyName The name of the property.
|
|
81
|
+
* @param categoryKey The SchemaItemKey of the property category.
|
|
82
|
+
*/
|
|
83
|
+
async setCategory(classKey, propertyName, categoryKey) {
|
|
84
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
85
|
+
const category = await property.class.schema.lookupItem(categoryKey);
|
|
86
|
+
if (category === undefined) {
|
|
87
|
+
return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${property.class.schema.fullName}.` };
|
|
88
|
+
}
|
|
89
|
+
property.setCategory(new ecschema_metadata_1.DelayedPromiseWithProps(categoryKey, async () => category));
|
|
90
|
+
return { itemKey: classKey, propertyName };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.
|
|
94
|
+
* @param classKey The SchemaItemKey identifying the class.
|
|
95
|
+
* @param propertyName The name of the property.
|
|
96
|
+
* @param customAttribute The CustomAttribute instance to add.
|
|
97
|
+
*/
|
|
98
|
+
async addCustomAttribute(classKey, propertyName, customAttribute) {
|
|
99
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
100
|
+
property.addCustomAttribute(customAttribute);
|
|
101
|
+
const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);
|
|
102
|
+
// TODO: Update error
|
|
103
|
+
const error = new Error();
|
|
104
|
+
for await (const diagnostic of diagnostics) {
|
|
105
|
+
error.message += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
|
|
106
|
+
}
|
|
107
|
+
if (error.message) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Gets the property with the specified name from the class identified by the given key.
|
|
113
|
+
* @param classKey The SchemaItemKey of the class.
|
|
114
|
+
* @param propertyName The name of the property to retrieve.
|
|
115
|
+
*/
|
|
116
|
+
async getProperty(classKey, propertyName) {
|
|
117
|
+
const mutableClass = await this.getClass(classKey);
|
|
118
|
+
const property = await mutableClass.getProperty(propertyName);
|
|
119
|
+
if (property === undefined) {
|
|
120
|
+
// TODO: Update error
|
|
121
|
+
throw new Error(`An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.`);
|
|
122
|
+
}
|
|
123
|
+
return property;
|
|
124
|
+
}
|
|
125
|
+
async findDerivedClasses(mutableClass) {
|
|
126
|
+
const derivedClasses = [];
|
|
127
|
+
for await (const schemaItem of this._schemaEditor.schemaContext.getSchemaItems()) {
|
|
128
|
+
if (ecschema_metadata_1.ECClass.isECClass(schemaItem) && await schemaItem.is(mutableClass)) {
|
|
129
|
+
if (!mutableClass.key.matches(schemaItem.key)) {
|
|
130
|
+
derivedClasses.push(schemaItem);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return derivedClasses;
|
|
135
|
+
}
|
|
136
|
+
async getClass(classKey) {
|
|
137
|
+
const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
|
|
138
|
+
if (schema === undefined)
|
|
139
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Schema Key ${classKey.schemaKey.toString(true)} not found in context`);
|
|
140
|
+
const ecClass = await schema.getItem(classKey.name);
|
|
141
|
+
if (ecClass === undefined)
|
|
142
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);
|
|
143
|
+
if (!(ecClass instanceof ecschema_metadata_1.ECClass)) {
|
|
144
|
+
throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);
|
|
145
|
+
}
|
|
146
|
+
return ecClass;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.Properties = Properties;
|
|
150
|
+
/**
|
|
151
|
+
* @alpha
|
|
152
|
+
* A class extending Properties allowing editing of attributes of PrimitiveArrayProperty,
|
|
153
|
+
* EnumerationArrayProperty and StructArrayProperty.
|
|
154
|
+
*/
|
|
155
|
+
class ArrayProperties extends Properties {
|
|
156
|
+
constructor(_schemaEditor) {
|
|
157
|
+
super(_schemaEditor);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Sets the array property minOccurs attribute.
|
|
161
|
+
* @param classKey The SchemaItemKey of the class.
|
|
162
|
+
* @param propertyName The name of the property.
|
|
163
|
+
* @param minOccurs The new minOccurs value.
|
|
164
|
+
*/
|
|
165
|
+
async setMinOccurs(classKey, propertyName, minOccurs) {
|
|
166
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
167
|
+
property.setMinOccurs(minOccurs);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Sets the array property maxOccurs attribute.
|
|
171
|
+
* @param classKey The SchemaItemKey of the class.
|
|
172
|
+
* @param propertyName The name of the property.
|
|
173
|
+
* @param maxOccurs The new maxOccurs value.
|
|
174
|
+
*/
|
|
175
|
+
async setMaxOccurs(classKey, propertyName, maxOccurs) {
|
|
176
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
177
|
+
property.setMaxOccurs(maxOccurs);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Override to validate that the found property is an ArrayProperty.
|
|
181
|
+
* @param classKey The SchemaItemKey of the class.
|
|
182
|
+
* @param propertyName The name of the property.
|
|
183
|
+
*/
|
|
184
|
+
async getProperty(classKey, propertyName) {
|
|
185
|
+
const property = await super.getProperty(classKey, propertyName);
|
|
186
|
+
if (!property.isArray()) {
|
|
187
|
+
// TODO: Update error
|
|
188
|
+
throw new Error(`The property ${propertyName} is not an ArrayProperty.`);
|
|
189
|
+
}
|
|
190
|
+
return property;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.ArrayProperties = ArrayProperties;
|
|
194
|
+
/**
|
|
195
|
+
* @alpha
|
|
196
|
+
* A class extending Properties allowing editing of attributes of PrimitiveProperty and EnumerationProperty.
|
|
197
|
+
*/
|
|
198
|
+
class PrimitiveOrEnumProperties extends Properties {
|
|
199
|
+
constructor(_schemaEditor) {
|
|
200
|
+
super(_schemaEditor);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Sets the extendTypeName attribute value.
|
|
204
|
+
* @param classKey The SchemaItemKey of the class.
|
|
205
|
+
* @param propertyName The name of the property.
|
|
206
|
+
* @param extendTypeName The extended type name of the property.
|
|
207
|
+
*/
|
|
208
|
+
async setExtendedTypeName(classKey, propertyName, extendedTypeName) {
|
|
209
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
210
|
+
property.setExtendedTypeName(extendedTypeName);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Sets the minLength attribute value.
|
|
214
|
+
* @param classKey The SchemaItemKey of the class.
|
|
215
|
+
* @param propertyName The name of the property.
|
|
216
|
+
* @param minLength The minimum length of the property.
|
|
217
|
+
*/
|
|
218
|
+
async setMinLength(classKey, propertyName, minLength) {
|
|
219
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
220
|
+
property.setMinLength(minLength);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Sets the maxLength attribute value.
|
|
224
|
+
* @param classKey The SchemaItemKey of the class.
|
|
225
|
+
* @param propertyName The name of the property.
|
|
226
|
+
* @param maxLength The maximum length of the property.
|
|
227
|
+
*/
|
|
228
|
+
async setMaxLength(classKey, propertyName, maxLength) {
|
|
229
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
230
|
+
property.setMaxLength(maxLength);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Sets the minValue attribute value.
|
|
234
|
+
* @param classKey The SchemaItemKey of the class.
|
|
235
|
+
* @param propertyName The name of the property.
|
|
236
|
+
* @param minValue The minimum value of the property.
|
|
237
|
+
*/
|
|
238
|
+
async setMinValue(classKey, propertyName, minValue) {
|
|
239
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
240
|
+
property.setMinValue(minValue);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Sets the maxValue attribute value.
|
|
244
|
+
* @param classKey The SchemaItemKey of the class.
|
|
245
|
+
* @param propertyName The name of the property.
|
|
246
|
+
* @param maxValue The maximum value of the property.
|
|
247
|
+
*/
|
|
248
|
+
async setMaxValue(classKey, propertyName, maxValue) {
|
|
249
|
+
const property = await this.getProperty(classKey, propertyName);
|
|
250
|
+
property.setMaxValue(maxValue);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* @alpha
|
|
255
|
+
* A class extending Properties allowing editing of PrimitiveProperty attributes.
|
|
256
|
+
*/
|
|
257
|
+
class PrimitiveProperties extends PrimitiveOrEnumProperties {
|
|
258
|
+
constructor(_schemaEditor) {
|
|
259
|
+
super(_schemaEditor);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Override to validate that the found property is a PrimitiveProperty.
|
|
263
|
+
* @param classKey The SchemaItemKey of the class.
|
|
264
|
+
* @param propertyName The name of the property.
|
|
265
|
+
*/
|
|
266
|
+
async getProperty(classKey, propertyName) {
|
|
267
|
+
const property = await super.getProperty(classKey, propertyName);
|
|
268
|
+
if (!(property instanceof ecschema_metadata_1.PrimitiveProperty)) {
|
|
269
|
+
// TODO: Update error
|
|
270
|
+
throw new Error(`The property ${propertyName} is not an PrimitiveProperty.`);
|
|
271
|
+
}
|
|
272
|
+
return property;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
exports.PrimitiveProperties = PrimitiveProperties;
|
|
276
|
+
/**
|
|
277
|
+
* @alpha
|
|
278
|
+
* A class extending Properties allowing editing of EnumerationProperty attributes.
|
|
279
|
+
*/
|
|
280
|
+
class EnumerationProperties extends PrimitiveOrEnumProperties {
|
|
281
|
+
constructor(_schemaEditor) {
|
|
282
|
+
super(_schemaEditor);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Override to validate that the found property is a EnumerationProperty.
|
|
286
|
+
* @param classKey The SchemaItemKey of the class.
|
|
287
|
+
* @param propertyName The name of the property.
|
|
288
|
+
*/
|
|
289
|
+
async getProperty(classKey, propertyName) {
|
|
290
|
+
const property = await super.getProperty(classKey, propertyName);
|
|
291
|
+
if (!(property instanceof ecschema_metadata_1.EnumerationProperty)) {
|
|
292
|
+
// TODO: Update error
|
|
293
|
+
throw new Error(`The property ${propertyName} is not an EnumerationProperty.`);
|
|
294
|
+
}
|
|
295
|
+
return property;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.EnumerationProperties = EnumerationProperties;
|
|
299
|
+
/**
|
|
300
|
+
* @alpha
|
|
301
|
+
* A class extending Properties allowing editing of NavigationProperties attributes.
|
|
302
|
+
*/
|
|
303
|
+
class NavigationProperties extends Properties {
|
|
304
|
+
constructor(_schemaEditor) {
|
|
305
|
+
super(_schemaEditor);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Override to validate that the found property is a NavigationProperty.
|
|
309
|
+
* @param classKey The SchemaItemKey of the class.
|
|
310
|
+
* @param propertyName The name of the property.
|
|
311
|
+
*/
|
|
312
|
+
async getProperty(classKey, propertyName) {
|
|
313
|
+
const property = await super.getProperty(classKey, propertyName);
|
|
314
|
+
if (!(property instanceof ecschema_metadata_1.NavigationProperty)) {
|
|
315
|
+
// TODO: Update error
|
|
316
|
+
throw new Error(`The property ${propertyName} is not a NavigationProperty.`);
|
|
317
|
+
}
|
|
318
|
+
return property;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
exports.NavigationProperties = NavigationProperties;
|
|
322
|
+
/**
|
|
323
|
+
* @alpha
|
|
324
|
+
* A class extending Properties allowing editing of StructProperty attributes.
|
|
325
|
+
*/
|
|
326
|
+
class StructProperties extends Properties {
|
|
327
|
+
constructor(_schemaEditor) {
|
|
328
|
+
super(_schemaEditor);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Override to validate that the found property is a StructProperty.
|
|
332
|
+
* @param classKey The SchemaItemKey of the class.
|
|
333
|
+
* @param propertyName The name of the property.
|
|
334
|
+
*/
|
|
335
|
+
async getProperty(classKey, propertyName) {
|
|
336
|
+
const property = await super.getProperty(classKey, propertyName);
|
|
337
|
+
if (!(property instanceof ecschema_metadata_1.StructProperty)) {
|
|
338
|
+
// TODO: Update error
|
|
339
|
+
throw new Error(`The property ${propertyName} is not a StructProperty.`);
|
|
340
|
+
}
|
|
341
|
+
return property;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.StructProperties = StructProperties;
|
|
345
|
+
//# sourceMappingURL=Properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Properties.js","sourceRoot":"","sources":["../../../src/Editing/Properties.ts"],"names":[],"mappings":";;;AAAA,gEAEoF;AAEpF,+CAA+C;AAU/C;;;GAGG;AACH,MAAa,UAAU;IACrB,YAA6B,aAAkC;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,UAAU;IAC9C,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACgB,KAAK,CAAC,WAAW,CAAgC,QAAuB,EAAE,YAAoB;QAC/G,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,WAAW,CAAwB,QAAQ,EAAE,YAAY,CAAM,CAAC;QAC7F,IAAI,CAAC,CAAC,QAAQ,YAAY,kCAAc,CAAC,EAAC;YACxC,qBAAqB;YACrB,MAAM,IAAI,KAAK,CAAC,gBAAgB,YAAY,2BAA2B,CAAC,CAAC;SAC1E;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAlBD,4CAkBC","sourcesContent":["import { CustomAttribute, DelayedPromiseWithProps, ECClass, ECName, ECObjectsError,\r\n ECObjectsStatus, EnumerationProperty, NavigationProperty, PrimitiveProperty,\r\n PropertyCategory, SchemaItemKey, StructProperty } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor } from \"./Editor\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { MutableArrayProperty } from \"./Mutable/MutableArrayProperty\";\r\nimport { MutableProperty } from \"./Mutable/MutableProperty\";\r\nimport { MutablePrimitiveOrEnumPropertyBase } from \"./Mutable/MutablePrimitiveOrEnumProperty\";\r\nimport { MutableClass } from \"./Mutable/MutableClass\";\r\nimport { MutableStructProperty } from \"./Mutable/MutableStructProperty\";\r\nimport { MutableNavigationProperty } from \"./Mutable/MutableNavigationProperty\";\r\n\r\ntype MutablePropertyType = MutableProperty | MutableArrayProperty | MutablePrimitiveOrEnumPropertyBase | MutableNavigationProperty | MutableStructProperty;\r\n\r\n/**\r\n * @alpha\r\n * A class allowing editing of attributes of the base Property class.\r\n */\r\nexport class Properties {\r\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n public async setName(classKey: SchemaItemKey, propertyName: string, newPropertyName: string) {\r\n const newName = new ECName(newPropertyName);\r\n\r\n const existingProperty = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n\r\n const baseProperty = await existingProperty.class.getProperty(newPropertyName, true) as MutableProperty;\r\n if (baseProperty)\r\n throw new Error(`An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.`);\r\n\r\n // Handle derived classes\r\n const derivedProperties: Array<MutableProperty> = [];\r\n const derivedClasses = await this.findDerivedClasses(existingProperty.class as MutableClass);\r\n for (const derivedClass of derivedClasses) {\r\n if (await derivedClass.getProperty(newPropertyName))\r\n throw new Error(`An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.`);\r\n\r\n const propertyOverride = await derivedClass.getProperty(propertyName) as MutableProperty;\r\n // If found the property is overridden in the derived class.\r\n if (propertyOverride)\r\n derivedProperties.push(propertyOverride);\r\n }\r\n\r\n // Re-name the overridden property in all derived classes\r\n derivedProperties.forEach((prop: MutableProperty) => {\r\n prop.setName(newName);\r\n });\r\n\r\n existingProperty.setName(newName);\r\n }\r\n\r\n /**\r\n * Sets the property description.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param description The new description to set.\r\n */\r\n public async setDescription(classKey: SchemaItemKey, propertyName: string, description: string) {\r\n const property = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n property.setDescription(description);\r\n }\r\n\r\n /**\r\n * Sets the property label.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param label The new label to set.\r\n */\r\n public async setLabel(classKey: SchemaItemKey, propertyName: string, label: string) {\r\n const property = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n property.setLabel(label);\r\n }\r\n\r\n /**\r\n * Sets the property isReadOnly attribute.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param isReadOnly The new isReadOnly value.\r\n */\r\n public async setIsReadOnly(classKey: SchemaItemKey, propertyName: string, isReadOnly: boolean) {\r\n const property = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n property.setIsReadOnly(isReadOnly);\r\n }\r\n\r\n /**\r\n * Sets the property priority.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param priority The new priority.\r\n */\r\n public async setPriority(classKey: SchemaItemKey, propertyName: string, priority: number) {\r\n const property = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n property.setPriority(priority);\r\n }\r\n\r\n /**\r\n * Sets the property category.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param categoryKey The SchemaItemKey of the property category.\r\n */\r\n public async setCategory(classKey: SchemaItemKey, propertyName: string, categoryKey: SchemaItemKey) {\r\n const property = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n\r\n const category = await property.class.schema.lookupItem<PropertyCategory>(categoryKey);\r\n if (category === undefined) {\r\n return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${property.class.schema.fullName}.` };\r\n }\r\n\r\n property.setCategory(new DelayedPromiseWithProps<SchemaItemKey, PropertyCategory>(categoryKey, async () => category));\r\n return { itemKey: classKey, propertyName };\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param propertyName The name of the property.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(classKey: SchemaItemKey, propertyName: string, customAttribute: CustomAttribute) {\r\n const property = await this.getProperty<MutableProperty>(classKey, propertyName);\r\n\r\n property.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);\r\n\r\n // TODO: Update error\r\n const error = new Error();\r\n for await (const diagnostic of diagnostics) {\r\n error.message += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (error.message) {\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the property with the specified name from the class identified by the given key.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property to retrieve.\r\n */\r\n protected async getProperty<T extends MutablePropertyType>(classKey: SchemaItemKey, propertyName: string): Promise<T> {\r\n const mutableClass = await this.getClass(classKey);\r\n\r\n const property = await mutableClass.getProperty(propertyName) as T;\r\n if (property === undefined) {\r\n // TODO: Update error\r\n throw new Error(`An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.`);\r\n }\r\n\r\n return property;\r\n }\r\n\r\n private async findDerivedClasses(mutableClass: MutableClass): Promise<Array<MutableClass>>{\r\n const derivedClasses: Array<MutableClass> = [];\r\n\r\n for await (const schemaItem of this._schemaEditor.schemaContext.getSchemaItems()) {\r\n if(ECClass.isECClass(schemaItem) && await schemaItem.is(mutableClass)) {\r\n if (!mutableClass.key.matches(schemaItem.key)) {\r\n derivedClasses.push(schemaItem as MutableClass);\r\n }\r\n }\r\n }\r\n\r\n return derivedClasses;\r\n }\r\n\r\n private async getClass(classKey: SchemaItemKey): Promise<MutableClass> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n if (schema === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${classKey.schemaKey.toString(true)} not found in context`);\r\n\r\n const ecClass = await schema.getItem(classKey.name);\r\n if (ecClass === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);\r\n\r\n if (!(ecClass instanceof ECClass)) {\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);\r\n }\r\n\r\n return ecClass as MutableClass;\r\n }\r\n}\r\n\r\n/**\r\n * @alpha\r\n * A class extending Properties allowing editing of attributes of PrimitiveArrayProperty,\r\n * EnumerationArrayProperty and StructArrayProperty.\r\n */\r\nexport class ArrayProperties extends Properties {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Sets the array property minOccurs attribute.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param minOccurs The new minOccurs value.\r\n */\r\n public async setMinOccurs(classKey: SchemaItemKey, propertyName: string, minOccurs: number) {\r\n const property = await this.getProperty<MutableArrayProperty>(classKey, propertyName);\r\n property.setMinOccurs(minOccurs);\r\n }\r\n\r\n /**\r\n * Sets the array property maxOccurs attribute.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param maxOccurs The new maxOccurs value.\r\n */\r\n public async setMaxOccurs(classKey: SchemaItemKey, propertyName: string, maxOccurs: number) {\r\n const property = await this.getProperty<MutableArrayProperty>(classKey, propertyName);\r\n property.setMaxOccurs(maxOccurs);\r\n }\r\n\r\n /**\r\n * Override to validate that the found property is an ArrayProperty.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n */\r\n protected override async getProperty<T extends MutablePropertyType>(classKey: SchemaItemKey, propertyName: string): Promise<T> {\r\n const property = await super.getProperty<MutableArrayProperty>(classKey, propertyName) as T;\r\n if (!property.isArray()){\r\n // TODO: Update error\r\n throw new Error(`The property ${propertyName} is not an ArrayProperty.`);\r\n }\r\n return property;\r\n }\r\n}\r\n\r\n/**\r\n * @alpha\r\n * A class extending Properties allowing editing of attributes of PrimitiveProperty and EnumerationProperty.\r\n */\r\nclass PrimitiveOrEnumProperties extends Properties {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Sets the extendTypeName attribute value.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param extendTypeName The extended type name of the property.\r\n */\r\n public async setExtendedTypeName(classKey: SchemaItemKey, propertyName: string, extendedTypeName: string) {\r\n const property = await this.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName);\r\n property.setExtendedTypeName(extendedTypeName);\r\n }\r\n\r\n /**\r\n * Sets the minLength attribute value.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param minLength The minimum length of the property.\r\n */\r\n public async setMinLength(classKey: SchemaItemKey, propertyName: string, minLength: number) {\r\n const property = await this.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName);\r\n property.setMinLength(minLength);\r\n }\r\n\r\n /**\r\n * Sets the maxLength attribute value.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param maxLength The maximum length of the property.\r\n */\r\n public async setMaxLength(classKey: SchemaItemKey, propertyName: string, maxLength: number) {\r\n const property = await this.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName);\r\n property.setMaxLength(maxLength);\r\n }\r\n\r\n /**\r\n * Sets the minValue attribute value.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param minValue The minimum value of the property.\r\n */\r\n public async setMinValue(classKey: SchemaItemKey, propertyName: string, minValue: number) {\r\n const property = await this.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName);\r\n property.setMinValue(minValue);\r\n }\r\n\r\n /**\r\n * Sets the maxValue attribute value.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param maxValue The maximum value of the property.\r\n */\r\n public async setMaxValue(classKey: SchemaItemKey, propertyName: string, maxValue: number) {\r\n const property = await this.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName);\r\n property.setMaxValue(maxValue);\r\n }\r\n}\r\n\r\n/**\r\n * @alpha\r\n * A class extending Properties allowing editing of PrimitiveProperty attributes.\r\n */\r\nexport class PrimitiveProperties extends PrimitiveOrEnumProperties {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Override to validate that the found property is a PrimitiveProperty.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n */\r\n protected override async getProperty<T extends MutablePropertyType>(classKey: SchemaItemKey, propertyName: string): Promise<T> {\r\n const property = await super.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName) as T;\r\n if (!(property instanceof PrimitiveProperty)){\r\n // TODO: Update error\r\n throw new Error(`The property ${propertyName} is not an PrimitiveProperty.`);\r\n }\r\n return property;\r\n }\r\n}\r\n\r\n/**\r\n * @alpha\r\n * A class extending Properties allowing editing of EnumerationProperty attributes.\r\n */\r\nexport class EnumerationProperties extends PrimitiveOrEnumProperties {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Override to validate that the found property is a EnumerationProperty.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n */\r\n protected override async getProperty<T extends MutablePropertyType>(classKey: SchemaItemKey, propertyName: string): Promise<T> {\r\n const property = await super.getProperty<MutablePrimitiveOrEnumPropertyBase>(classKey, propertyName) as T;\r\n if (!(property instanceof EnumerationProperty)){\r\n // TODO: Update error\r\n throw new Error(`The property ${propertyName} is not an EnumerationProperty.`);\r\n }\r\n return property;\r\n }\r\n}\r\n\r\n/**\r\n * @alpha\r\n * A class extending Properties allowing editing of NavigationProperties attributes.\r\n */\r\nexport class NavigationProperties extends Properties {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Override to validate that the found property is a NavigationProperty.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n */\r\n protected override async getProperty<T extends MutablePropertyType>(classKey: SchemaItemKey, propertyName: string): Promise<T> {\r\n const property = await super.getProperty<MutableNavigationProperty>(classKey, propertyName) as T;\r\n if (!(property instanceof NavigationProperty)){\r\n // TODO: Update error\r\n throw new Error(`The property ${propertyName} is not a NavigationProperty.`);\r\n }\r\n return property;\r\n }\r\n}\r\n\r\n/**\r\n * @alpha\r\n * A class extending Properties allowing editing of StructProperty attributes.\r\n */\r\nexport class StructProperties extends Properties {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Override to validate that the found property is a StructProperty.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n */\r\n protected override async getProperty<T extends MutablePropertyType>(classKey: SchemaItemKey, propertyName: string): Promise<T> {\r\n const property = await super.getProperty<MutableStructProperty>(classKey, propertyName) as T;\r\n if (!(property instanceof StructProperty)){\r\n // TODO: Update error\r\n throw new Error(`The property ${propertyName} is not a StructProperty.`);\r\n }\r\n return property;\r\n }\r\n}\r\n\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAttributeMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAA0D,MAAM,0BAA0B,CAAC;AACnH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,KAAK,qBAAqB,GAAG,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE9F;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"CustomAttributeMerger.d.ts","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAA0D,MAAM,0BAA0B,CAAC;AACnH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,KAAK,qBAAqB,GAAG,CAAC,eAAe,EAAE,eAAe,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE9F;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAiDrI;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAQxK;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAGpK"}
|
|
@@ -39,7 +39,12 @@ async function mergeCustomAttribute(context, change) {
|
|
|
39
39
|
if (change.appliedTo === "Property") {
|
|
40
40
|
const itemKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
|
|
41
41
|
const [propertyName] = change.path.split(".");
|
|
42
|
-
|
|
42
|
+
try {
|
|
43
|
+
await context.editor.entities.properties.addCustomAttribute(itemKey, propertyName, caInstance);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
return { errorMessage: e.message };
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
if (change.appliedTo === "RelationshipConstraint") {
|
|
45
50
|
const itemKey = new ecschema_metadata_1.SchemaItemKey(change.itemName, context.targetSchemaKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAttributeMerger.js","sourceRoot":"","sources":["../../../src/Merging/CustomAttributeMerger.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,gEAAmH;AAInH,yDAAmF;AAInF;;;;;;;GAOG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,MAAiC;IACvG,IAAI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AAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;QAC9C,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;QAC7E,IAAI,MAAM,CAAC,YAAY,EAAE;YACvB,OAAO,MAAM,CAAC;SACf;KACF;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AARD,sDAQC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,OAA2B,EAAE,eAAgC,EAAE,OAA8B;IACtI,eAAe,CAAC,SAAS,GAAG,MAAM,IAAA,2CAAwB,EAAC,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC;AAClC,CAAC;AAHD,oDAGC","sourcesContent":["/*---------------------------------------------------------------------------------------------\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 { CustomAttribute, CustomAttributeClass, RelationshipClass, SchemaItemKey } from \"@itwin/ecschema-metadata\";\r\nimport { type SchemaMergeContext } from \"./SchemaMerger\";\r\nimport { type CustomAttributeDifference } from \"../Differencing/SchemaDifference\";\r\nimport { type SchemaEditResults } from \"../Editing/Editor\";\r\nimport { updateSchemaItemFullName, updateSchemaItemKey } from \"./SchemaItemMerger\";\r\n\r\ntype CustomAttributeSetter = (customAttribute: CustomAttribute) => Promise<SchemaEditResults>;\r\n\r\n/**\r\n * Merges the custom attributes of the given changes iterable. The third parameter is a callback to pass\r\n * a scope (Class, Property, Schema) specific handler.\r\n * @param context The current schema merging context.\r\n * @param change The individual custom attribute change.\r\n * @returns A EditResults object.\r\n * @internal\r\n */\r\nexport async function mergeCustomAttribute(context: SchemaMergeContext, change: CustomAttributeDifference): Promise<SchemaEditResults> {\r\n if (change.changeType === \"add\") {\r\n if (change.difference.className === undefined) {\r\n return { errorMessage: \"CustomAttribute instance must specify className\" };\r\n }\r\n const schemaItemKey = await updateSchemaItemKey(context, change.difference.className);\r\n\r\n const targetCustomAttributeClass = await context.targetSchema.lookupItem<CustomAttributeClass>(schemaItemKey);\r\n if (targetCustomAttributeClass === undefined) {\r\n return { errorMessage: `Unable to locate the custom attribute class ${schemaItemKey.name} in the merged schema.` };\r\n }\r\n\r\n const caInstance: CustomAttribute = {\r\n ...change.difference,\r\n className: schemaItemKey.fullName,\r\n };\r\n\r\n if (change.appliedTo === \"Schema\") {\r\n return context.editor.addCustomAttribute(context.targetSchemaKey, caInstance);\r\n }\r\n if (change.appliedTo === \"SchemaItem\") {\r\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n return context.editor.entities.addCustomAttribute(itemKey, caInstance);\r\n }\r\n if (change.appliedTo === \"Property\") {\r\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n const [propertyName] = change.path.split(\".\");\r\n try{\r\n await context.editor.entities.properties.addCustomAttribute(itemKey, propertyName, caInstance);\r\n } catch(e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n }\r\n if (change.appliedTo === \"RelationshipConstraint\") {\r\n const itemKey = new SchemaItemKey(change.itemName, context.targetSchemaKey);\r\n const relationshipClass = await context.targetSchema.lookupItem<RelationshipClass>(itemKey);\r\n if (relationshipClass === undefined) {\r\n return { errorMessage: `Unable to locate the relationship class ${itemKey.name} in the merged schema.` };\r\n }\r\n const constraint = change.path === \"$source\"\r\n ? relationshipClass.source\r\n : relationshipClass.target;\r\n\r\n return context.editor.relationships.addCustomAttributeToConstraint(constraint, caInstance);\r\n }\r\n return {};\r\n } else {\r\n return { errorMessage: `Changes of Custom Attribute on merge is not implemented.` };\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function applyCustomAttributes(context: SchemaMergeContext, customAttributes: CustomAttribute[], handler: CustomAttributeSetter): Promise<SchemaEditResults> {\r\n for (const customAttribute of customAttributes) {\r\n const result = await applyCustomAttribute(context, customAttribute, handler);\r\n if (result.errorMessage) {\r\n return result;\r\n }\r\n }\r\n return {};\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport async function applyCustomAttribute(context: SchemaMergeContext, customAttribute: CustomAttribute, handler: CustomAttributeSetter): Promise<SchemaEditResults> {\r\n customAttribute.className = await updateSchemaItemFullName(context, customAttribute.className);\r\n return handler(customAttribute);\r\n}\r\n"]}
|
|
@@ -46,7 +46,13 @@ async function addClassProperty(context, itemKey, property) {
|
|
|
46
46
|
}
|
|
47
47
|
if (property.customAttributes !== undefined) {
|
|
48
48
|
const result = await (0, CustomAttributeMerger_1.applyCustomAttributes)(context, property.customAttributes, async (ca) => {
|
|
49
|
-
|
|
49
|
+
try {
|
|
50
|
+
await context.editor.entities.properties.addCustomAttribute(itemKey, property.name, ca);
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
return { errorMessage: e.message };
|
|
55
|
+
}
|
|
50
56
|
});
|
|
51
57
|
if (result.errorMessage) {
|
|
52
58
|
return result;
|
|
@@ -98,7 +104,7 @@ async function modifyClassProperty(context, itemKey, propertyProps) {
|
|
|
98
104
|
}
|
|
99
105
|
if (propertyProps.category !== undefined) {
|
|
100
106
|
const categoryKey = await (0, SchemaItemMerger_1.updateSchemaItemKey)(context, propertyProps.category);
|
|
101
|
-
await context.editor.entities.
|
|
107
|
+
await context.editor.entities.properties.setCategory(itemKey, property.name, categoryKey);
|
|
102
108
|
}
|
|
103
109
|
if (property.isEnumeration()) {
|
|
104
110
|
return enumerationProperty.merge(context, itemKey, property, propertyProps);
|
|
@@ -1 +1 @@
|
|
|
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,IA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AAA,sCAAmB,EAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACxE,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAc,SAAS,CAAC,CAAC;QAC5F,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B,OAAO,EAAE,YAAY,EAAE,+BAA+B,SAAS,CAAC,IAAI,yBAAyB,EAAE,CAAC;SACjG;QAED,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEvC,OAAO,aAAa,CAAC,EAAE,CAAC,QAAQ,CAAC;YAC/B,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kCAAkC,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC;YAC1G,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC1G,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK;QAC7C,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE;YAC7D,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,QAAQ,iCAAiC,EAAE,CAAC;SACvG;QACD,OAAO,EAAE,CAAC;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"]}
|
|
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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,EAAE,UAAU,EAAE,QAAQ,CAAC;YAC1G,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,6BAA6B,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC1G,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK;QAC7C,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE;YAC7D,OAAO,EAAE,YAAY,EAAE,0BAA0B,QAAQ,CAAC,QAAQ,iCAAiC,EAAE,CAAC;SACvG;QACD,OAAO,EAAE,CAAC;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 try{\r\n await context.editor.entities.properties.addCustomAttribute(itemKey, property.name, ca);\r\n return {};\r\n } catch(e: any) {\r\n return { errorMessage: e.message };\r\n }\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.properties.setCategory(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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/ecschema-editing",
|
|
3
|
-
"version": "4.6.0-dev.
|
|
3
|
+
"version": "4.6.0-dev.16",
|
|
4
4
|
"description": "ECSchema editing and validation API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/ecschema-editing.js",
|
|
@@ -42,16 +42,16 @@
|
|
|
42
42
|
"rimraf": "^3.0.2",
|
|
43
43
|
"sinon": "^17.0.1",
|
|
44
44
|
"typescript": "~5.0.2",
|
|
45
|
-
"@itwin/build-tools": "4.6.0-dev.
|
|
46
|
-
"@itwin/core-
|
|
47
|
-
"@itwin/core-bentley": "4.6.0-dev.
|
|
48
|
-
"@itwin/core-
|
|
49
|
-
"@itwin/ecschema-metadata": "4.6.0-dev.
|
|
45
|
+
"@itwin/build-tools": "4.6.0-dev.16",
|
|
46
|
+
"@itwin/core-quantity": "4.6.0-dev.16",
|
|
47
|
+
"@itwin/core-bentley": "4.6.0-dev.16",
|
|
48
|
+
"@itwin/core-common": "4.6.0-dev.16",
|
|
49
|
+
"@itwin/ecschema-metadata": "4.6.0-dev.16"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@itwin/core-bentley": "^4.6.0-dev.
|
|
53
|
-
"@itwin/core-quantity": "^4.6.0-dev.
|
|
54
|
-
"@itwin/ecschema-metadata": "^4.6.0-dev.
|
|
52
|
+
"@itwin/core-bentley": "^4.6.0-dev.16",
|
|
53
|
+
"@itwin/core-quantity": "^4.6.0-dev.16",
|
|
54
|
+
"@itwin/ecschema-metadata": "^4.6.0-dev.16"
|
|
55
55
|
},
|
|
56
56
|
"nyc": {
|
|
57
57
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|