@itwin/ecschema-editing 4.6.0-dev.9 → 4.7.0-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/Differencing/SchemaConflicts.d.ts +14 -0
  3. package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -1
  4. package/lib/cjs/Differencing/SchemaConflicts.js +15 -2
  5. package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
  6. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
  7. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +0 -52
  8. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
  9. package/lib/cjs/Differencing/SchemaDifference.d.ts +2 -2
  10. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
  11. package/lib/cjs/Differencing/SchemaDifference.js +3 -3
  12. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
  13. package/lib/cjs/Editing/Constants.js.map +1 -1
  14. package/lib/cjs/Editing/CustomAttributes.d.ts +1 -1
  15. package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
  16. package/lib/cjs/Editing/CustomAttributes.js +2 -2
  17. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  18. package/lib/cjs/Editing/ECClasses.d.ts +29 -23
  19. package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
  20. package/lib/cjs/Editing/ECClasses.js +51 -95
  21. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  22. package/lib/cjs/Editing/Editor.js.map +1 -1
  23. package/lib/cjs/Editing/Entities.d.ts +6 -7
  24. package/lib/cjs/Editing/Entities.d.ts.map +1 -1
  25. package/lib/cjs/Editing/Entities.js +7 -27
  26. package/lib/cjs/Editing/Entities.js.map +1 -1
  27. package/lib/cjs/Editing/Formats.js.map +1 -1
  28. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  29. package/lib/cjs/Editing/Mixins.d.ts +6 -2
  30. package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
  31. package/lib/cjs/Editing/Mixins.js +7 -22
  32. package/lib/cjs/Editing/Mixins.js.map +1 -1
  33. package/lib/cjs/Editing/Mutable/MutableEntityClass.js +2 -2
  34. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  35. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts +8 -0
  36. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.d.ts.map +1 -0
  37. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js +16 -0
  38. package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js.map +1 -0
  39. package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts +8 -0
  40. package/lib/cjs/Editing/Mutable/MutableStructProperty.d.ts.map +1 -0
  41. package/lib/cjs/Editing/Mutable/MutableStructProperty.js +16 -0
  42. package/lib/cjs/Editing/Mutable/MutableStructProperty.js.map +1 -0
  43. package/lib/cjs/Editing/Properties.d.ts +201 -0
  44. package/lib/cjs/Editing/Properties.d.ts.map +1 -0
  45. package/lib/cjs/Editing/Properties.js +349 -0
  46. package/lib/cjs/Editing/Properties.js.map +1 -0
  47. package/lib/cjs/Editing/RelationshipClasses.d.ts +12 -1
  48. package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
  49. package/lib/cjs/Editing/RelationshipClasses.js +26 -3
  50. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  51. package/lib/cjs/Editing/Structs.d.ts +1 -1
  52. package/lib/cjs/Editing/Structs.d.ts.map +1 -1
  53. package/lib/cjs/Editing/Structs.js +2 -2
  54. package/lib/cjs/Editing/Structs.js.map +1 -1
  55. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  56. package/lib/cjs/Merging/ClassMerger.js +7 -16
  57. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  58. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  59. package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
  60. package/lib/cjs/Merging/CustomAttributeMerger.js +6 -1
  61. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  62. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  63. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  64. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  65. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  66. package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
  67. package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
  68. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
  69. package/lib/cjs/Merging/PropertyMerger.js +54 -23
  70. package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
  71. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
  72. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  73. package/lib/cjs/Merging/SchemaMerger.d.ts +1 -1
  74. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  75. package/lib/cjs/Merging/SchemaMerger.js +12 -8
  76. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  77. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  78. package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
  79. package/lib/cjs/Validation/Diagnostic.d.ts +2 -2
  80. package/lib/cjs/Validation/Diagnostic.d.ts.map +1 -1
  81. package/lib/cjs/Validation/Diagnostic.js +4 -4
  82. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  83. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  84. package/lib/cjs/Validation/ECRules.d.ts +35 -35
  85. package/lib/cjs/Validation/ECRules.d.ts.map +1 -1
  86. package/lib/cjs/Validation/ECRules.js.map +1 -1
  87. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  88. package/lib/cjs/Validation/SchemaChanges.d.ts +38 -6
  89. package/lib/cjs/Validation/SchemaChanges.d.ts.map +1 -1
  90. package/lib/cjs/Validation/SchemaChanges.js +97 -27
  91. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  92. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  93. package/lib/cjs/Validation/SchemaCompareVisitor.js +4 -3
  94. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  95. package/lib/cjs/Validation/SchemaComparer.d.ts +1 -0
  96. package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
  97. package/lib/cjs/Validation/SchemaComparer.js +238 -260
  98. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  99. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  100. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  101. package/lib/cjs/ecschema-editing.d.ts +2 -0
  102. package/lib/cjs/ecschema-editing.d.ts.map +1 -1
  103. package/lib/cjs/ecschema-editing.js +2 -0
  104. package/lib/cjs/ecschema-editing.js.map +1 -1
  105. package/package.json +11 -11
@@ -0,0 +1,349 @@
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(ecClassType, _schemaEditor) {
12
+ this.ecClassType = ecClassType;
13
+ this._schemaEditor = _schemaEditor;
14
+ }
15
+ async setName(classKey, propertyName, newPropertyName) {
16
+ const newName = new ecschema_metadata_1.ECName(newPropertyName);
17
+ const existingProperty = await this.getProperty(classKey, propertyName);
18
+ const baseProperty = await existingProperty.class.getProperty(newPropertyName, true);
19
+ if (baseProperty)
20
+ throw new Error(`An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.`);
21
+ // Handle derived classes
22
+ const derivedProperties = [];
23
+ const derivedClasses = await this.findDerivedClasses(existingProperty.class);
24
+ for (const derivedClass of derivedClasses) {
25
+ if (await derivedClass.getProperty(newPropertyName))
26
+ throw new Error(`An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.`);
27
+ const propertyOverride = await derivedClass.getProperty(propertyName);
28
+ // If found the property is overridden in the derived class.
29
+ if (propertyOverride)
30
+ derivedProperties.push(propertyOverride);
31
+ }
32
+ // Re-name the overridden property in all derived classes
33
+ derivedProperties.forEach((prop) => {
34
+ prop.setName(newName);
35
+ });
36
+ existingProperty.setName(newName);
37
+ }
38
+ /**
39
+ * Sets the property description.
40
+ * @param classKey The SchemaItemKey of the class.
41
+ * @param propertyName The name of the property.
42
+ * @param description The new description to set.
43
+ */
44
+ async setDescription(classKey, propertyName, description) {
45
+ const property = await this.getProperty(classKey, propertyName);
46
+ property.setDescription(description);
47
+ }
48
+ /**
49
+ * Sets the property label.
50
+ * @param classKey The SchemaItemKey of the class.
51
+ * @param propertyName The name of the property.
52
+ * @param label The new label to set.
53
+ */
54
+ async setLabel(classKey, propertyName, label) {
55
+ const property = await this.getProperty(classKey, propertyName);
56
+ property.setLabel(label);
57
+ }
58
+ /**
59
+ * Sets the property isReadOnly attribute.
60
+ * @param classKey The SchemaItemKey of the class.
61
+ * @param propertyName The name of the property.
62
+ * @param isReadOnly The new isReadOnly value.
63
+ */
64
+ async setIsReadOnly(classKey, propertyName, isReadOnly) {
65
+ const property = await this.getProperty(classKey, propertyName);
66
+ property.setIsReadOnly(isReadOnly);
67
+ }
68
+ /**
69
+ * Sets the property priority.
70
+ * @param classKey The SchemaItemKey of the class.
71
+ * @param propertyName The name of the property.
72
+ * @param priority The new priority.
73
+ */
74
+ async setPriority(classKey, propertyName, priority) {
75
+ const property = await this.getProperty(classKey, propertyName);
76
+ property.setPriority(priority);
77
+ }
78
+ /**
79
+ * Sets the property category.
80
+ * @param classKey The SchemaItemKey of the class.
81
+ * @param propertyName The name of the property.
82
+ * @param categoryKey The SchemaItemKey of the property category.
83
+ */
84
+ async setCategory(classKey, propertyName, categoryKey) {
85
+ const property = await this.getProperty(classKey, propertyName);
86
+ const category = await property.class.schema.lookupItem(categoryKey);
87
+ if (category === undefined) {
88
+ return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${property.class.schema.fullName}.` };
89
+ }
90
+ property.setCategory(new ecschema_metadata_1.DelayedPromiseWithProps(categoryKey, async () => category));
91
+ return { itemKey: classKey, propertyName };
92
+ }
93
+ /**
94
+ * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.
95
+ * @param classKey The SchemaItemKey identifying the class.
96
+ * @param propertyName The name of the property.
97
+ * @param customAttribute The CustomAttribute instance to add.
98
+ */
99
+ async addCustomAttribute(classKey, propertyName, customAttribute) {
100
+ const property = await this.getProperty(classKey, propertyName);
101
+ property.addCustomAttribute(customAttribute);
102
+ const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);
103
+ // TODO: Update error
104
+ const error = new Error();
105
+ for await (const diagnostic of diagnostics) {
106
+ error.message += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
107
+ }
108
+ if (error.message) {
109
+ throw error;
110
+ }
111
+ }
112
+ /**
113
+ * Gets the property with the specified name from the class identified by the given key.
114
+ * @param classKey The SchemaItemKey of the class.
115
+ * @param propertyName The name of the property to retrieve.
116
+ */
117
+ async getProperty(classKey, propertyName) {
118
+ const mutableClass = await this.getClass(classKey);
119
+ if (mutableClass.schemaItemType !== this.ecClassType) {
120
+ throw new Error(`The class ${classKey.fullName} is not an ${ecschema_metadata_1.SchemaItemType[this.ecClassType]}.`);
121
+ }
122
+ const property = await mutableClass.getProperty(propertyName);
123
+ if (property === undefined) {
124
+ // TODO: Update error
125
+ throw new Error(`An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.`);
126
+ }
127
+ return property;
128
+ }
129
+ async findDerivedClasses(mutableClass) {
130
+ const derivedClasses = [];
131
+ for await (const schemaItem of this._schemaEditor.schemaContext.getSchemaItems()) {
132
+ if (ecschema_metadata_1.ECClass.isECClass(schemaItem) && await schemaItem.is(mutableClass)) {
133
+ if (!mutableClass.key.matches(schemaItem.key)) {
134
+ derivedClasses.push(schemaItem);
135
+ }
136
+ }
137
+ }
138
+ return derivedClasses;
139
+ }
140
+ async getClass(classKey) {
141
+ const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
142
+ if (schema === undefined)
143
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Schema Key ${classKey.schemaKey.toString(true)} not found in context`);
144
+ const ecClass = await schema.getItem(classKey.name);
145
+ if (ecClass === undefined)
146
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);
147
+ if (!(ecClass instanceof ecschema_metadata_1.ECClass)) {
148
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);
149
+ }
150
+ return ecClass;
151
+ }
152
+ }
153
+ exports.Properties = Properties;
154
+ /**
155
+ * @alpha
156
+ * A class extending Properties allowing editing of attributes of PrimitiveArrayProperty,
157
+ * EnumerationArrayProperty and StructArrayProperty.
158
+ */
159
+ class ArrayProperties extends Properties {
160
+ constructor(ecClassType, _schemaEditor) {
161
+ super(ecClassType, _schemaEditor);
162
+ }
163
+ /**
164
+ * Sets the array property minOccurs attribute.
165
+ * @param classKey The SchemaItemKey of the class.
166
+ * @param propertyName The name of the property.
167
+ * @param minOccurs The new minOccurs value.
168
+ */
169
+ async setMinOccurs(classKey, propertyName, minOccurs) {
170
+ const property = await this.getProperty(classKey, propertyName);
171
+ property.setMinOccurs(minOccurs);
172
+ }
173
+ /**
174
+ * Sets the array property maxOccurs attribute.
175
+ * @param classKey The SchemaItemKey of the class.
176
+ * @param propertyName The name of the property.
177
+ * @param maxOccurs The new maxOccurs value.
178
+ */
179
+ async setMaxOccurs(classKey, propertyName, maxOccurs) {
180
+ const property = await this.getProperty(classKey, propertyName);
181
+ property.setMaxOccurs(maxOccurs);
182
+ }
183
+ /**
184
+ * Override to validate that the found property is an ArrayProperty.
185
+ * @param classKey The SchemaItemKey of the class.
186
+ * @param propertyName The name of the property.
187
+ */
188
+ async getProperty(classKey, propertyName) {
189
+ const property = await super.getProperty(classKey, propertyName);
190
+ if (!property.isArray()) {
191
+ // TODO: Update error
192
+ throw new Error(`The property ${propertyName} is not an ArrayProperty.`);
193
+ }
194
+ return property;
195
+ }
196
+ }
197
+ exports.ArrayProperties = ArrayProperties;
198
+ /**
199
+ * @alpha
200
+ * A class extending Properties allowing editing of attributes of PrimitiveProperty and EnumerationProperty.
201
+ */
202
+ class PrimitiveOrEnumProperties extends Properties {
203
+ constructor(ecClassType, _schemaEditor) {
204
+ super(ecClassType, _schemaEditor);
205
+ }
206
+ /**
207
+ * Sets the extendTypeName attribute value.
208
+ * @param classKey The SchemaItemKey of the class.
209
+ * @param propertyName The name of the property.
210
+ * @param extendTypeName The extended type name of the property.
211
+ */
212
+ async setExtendedTypeName(classKey, propertyName, extendedTypeName) {
213
+ const property = await this.getProperty(classKey, propertyName);
214
+ property.setExtendedTypeName(extendedTypeName);
215
+ }
216
+ /**
217
+ * Sets the minLength attribute value.
218
+ * @param classKey The SchemaItemKey of the class.
219
+ * @param propertyName The name of the property.
220
+ * @param minLength The minimum length of the property.
221
+ */
222
+ async setMinLength(classKey, propertyName, minLength) {
223
+ const property = await this.getProperty(classKey, propertyName);
224
+ property.setMinLength(minLength);
225
+ }
226
+ /**
227
+ * Sets the maxLength attribute value.
228
+ * @param classKey The SchemaItemKey of the class.
229
+ * @param propertyName The name of the property.
230
+ * @param maxLength The maximum length of the property.
231
+ */
232
+ async setMaxLength(classKey, propertyName, maxLength) {
233
+ const property = await this.getProperty(classKey, propertyName);
234
+ property.setMaxLength(maxLength);
235
+ }
236
+ /**
237
+ * Sets the minValue attribute value.
238
+ * @param classKey The SchemaItemKey of the class.
239
+ * @param propertyName The name of the property.
240
+ * @param minValue The minimum value of the property.
241
+ */
242
+ async setMinValue(classKey, propertyName, minValue) {
243
+ const property = await this.getProperty(classKey, propertyName);
244
+ property.setMinValue(minValue);
245
+ }
246
+ /**
247
+ * Sets the maxValue attribute value.
248
+ * @param classKey The SchemaItemKey of the class.
249
+ * @param propertyName The name of the property.
250
+ * @param maxValue The maximum value of the property.
251
+ */
252
+ async setMaxValue(classKey, propertyName, maxValue) {
253
+ const property = await this.getProperty(classKey, propertyName);
254
+ property.setMaxValue(maxValue);
255
+ }
256
+ }
257
+ /**
258
+ * @alpha
259
+ * A class extending Properties allowing editing of PrimitiveProperty attributes.
260
+ */
261
+ class PrimitiveProperties extends PrimitiveOrEnumProperties {
262
+ constructor(ecClassType, _schemaEditor) {
263
+ super(ecClassType, _schemaEditor);
264
+ }
265
+ /**
266
+ * Override to validate that the found property is a PrimitiveProperty.
267
+ * @param classKey The SchemaItemKey of the class.
268
+ * @param propertyName The name of the property.
269
+ */
270
+ async getProperty(classKey, propertyName) {
271
+ const property = await super.getProperty(classKey, propertyName);
272
+ if (!(property instanceof ecschema_metadata_1.PrimitiveProperty)) {
273
+ // TODO: Update error
274
+ throw new Error(`The property ${propertyName} is not an PrimitiveProperty.`);
275
+ }
276
+ return property;
277
+ }
278
+ }
279
+ exports.PrimitiveProperties = PrimitiveProperties;
280
+ /**
281
+ * @alpha
282
+ * A class extending Properties allowing editing of EnumerationProperty attributes.
283
+ */
284
+ class EnumerationProperties extends PrimitiveOrEnumProperties {
285
+ constructor(ecClassType, _schemaEditor) {
286
+ super(ecClassType, _schemaEditor);
287
+ }
288
+ /**
289
+ * Override to validate that the found property is a EnumerationProperty.
290
+ * @param classKey The SchemaItemKey of the class.
291
+ * @param propertyName The name of the property.
292
+ */
293
+ async getProperty(classKey, propertyName) {
294
+ const property = await super.getProperty(classKey, propertyName);
295
+ if (!(property instanceof ecschema_metadata_1.EnumerationProperty)) {
296
+ // TODO: Update error
297
+ throw new Error(`The property ${propertyName} is not an EnumerationProperty.`);
298
+ }
299
+ return property;
300
+ }
301
+ }
302
+ exports.EnumerationProperties = EnumerationProperties;
303
+ /**
304
+ * @alpha
305
+ * A class extending Properties allowing editing of NavigationProperties attributes.
306
+ */
307
+ class NavigationProperties extends Properties {
308
+ constructor(ecClassType, _schemaEditor) {
309
+ super(ecClassType, _schemaEditor);
310
+ }
311
+ /**
312
+ * Override to validate that the found property is a NavigationProperty.
313
+ * @param classKey The SchemaItemKey of the class.
314
+ * @param propertyName The name of the property.
315
+ */
316
+ async getProperty(classKey, propertyName) {
317
+ const property = await super.getProperty(classKey, propertyName);
318
+ if (!(property instanceof ecschema_metadata_1.NavigationProperty)) {
319
+ // TODO: Update error
320
+ throw new Error(`The property ${propertyName} is not a NavigationProperty.`);
321
+ }
322
+ return property;
323
+ }
324
+ }
325
+ exports.NavigationProperties = NavigationProperties;
326
+ /**
327
+ * @alpha
328
+ * A class extending Properties allowing editing of StructProperty attributes.
329
+ */
330
+ class StructProperties extends Properties {
331
+ constructor(ecClassType, _schemaEditor) {
332
+ super(ecClassType, _schemaEditor);
333
+ }
334
+ /**
335
+ * Override to validate that the found property is a StructProperty.
336
+ * @param classKey The SchemaItemKey of the class.
337
+ * @param propertyName The name of the property.
338
+ */
339
+ async getProperty(classKey, propertyName) {
340
+ const property = await super.getProperty(classKey, propertyName);
341
+ if (!(property instanceof ecschema_metadata_1.StructProperty)) {
342
+ // TODO: Update error
343
+ throw new Error(`The property ${propertyName} is not a StructProperty.`);
344
+ }
345
+ return property;
346
+ }
347
+ }
348
+ exports.StructProperties = StructProperties;
349
+ //# sourceMappingURL=Properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Properties.js","sourceRoot":"","sources":["../../../src/Editing/Properties.ts"],"names":[],"mappings":";;;AAAA,gEAEo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O,QAAQ,CAAC;IAClB,CAAC;CACF;AAlBD,sDAkBC;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,UAAU;IAClD,YAAmB,WAA+B,EAAE,aAAkC;QACpF,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACgB,KAAK,CAAC,WAAW,CAAgC,QAAuB,EAAE,YAAoB;QAC/G,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,WAAW,CAA4B,QAAQ,EAAE,YAAY,CAAM,CAAC;QACjG,IAAI,CAAC,CAAC,QAAQ,YAAY,sCAAkB,CAAC,EAAC,CAAC;YAC7C,qBAAqB;YACrB,MAAM,IAAI,KAAK,CAAC,gBAAgB,YAAY,+BAA+B,CAAC,CAAC;QAC/E,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAlBD,oDAkBC;AAED;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,UAAU;IAC9C,YAAmB,WAA+B,EAAE,aAAkC;QACpF,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACpC,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,CAAC;YACzC,qBAAqB;YACrB,MAAM,IAAI,KAAK,CAAC,gBAAgB,YAAY,2BAA2B,CAAC,CAAC;QAC3E,CAAC;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, SchemaItemType, 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\nimport { ECClassSchemaItems } from \"./ECClasses\";\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 ecClassType: ECClassSchemaItems, 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 if (mutableClass.schemaItemType !== this.ecClassType){\r\n throw new Error(`The class ${classKey.fullName} is not an ${SchemaItemType[this.ecClassType]}.`);\r\n }\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(ecClassType: ECClassSchemaItems, _schemaEditor: SchemaContextEditor) {\r\n super(ecClassType, _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(ecClassType: ECClassSchemaItems, _schemaEditor: SchemaContextEditor) {\r\n super(ecClassType, _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(ecClassType: ECClassSchemaItems, _schemaEditor: SchemaContextEditor) {\r\n super(ecClassType, _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(ecClassType: ECClassSchemaItems, _schemaEditor: SchemaContextEditor) {\r\n super(ecClassType, _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(ecClassType: ECClassSchemaItems, _schemaEditor: SchemaContextEditor) {\r\n super(ecClassType, _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(ecClassType: ECClassSchemaItems, _schemaEditor: SchemaContextEditor) {\r\n super(ecClassType, _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"]}
@@ -4,12 +4,17 @@
4
4
  import { CustomAttribute, ECClassModifier, EntityClass, Mixin, NavigationPropertyProps, RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaKey, StrengthDirection, StrengthType } from "@itwin/ecschema-metadata";
5
5
  import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
6
  import { ECClasses } from "./ECClasses";
7
+ import { NavigationProperties } from "./Properties";
7
8
  /**
8
9
  * @alpha
9
10
  * A class extending ECClasses allowing you to create schema items of type RelationshipClass.
10
11
  */
11
12
  export declare class RelationshipClasses extends ECClasses {
12
- constructor(_schemaEditor: SchemaContextEditor);
13
+ constructor(schemaEditor: SchemaContextEditor);
14
+ /**
15
+ * Allows access for editing of NavigationProperty attributes.
16
+ */
17
+ readonly navigationProperties: NavigationProperties;
13
18
  /**
14
19
  * Creates a RelationshipClass.
15
20
  * @param schemaKey a SchemaKey of the Schema that will house the new object.
@@ -40,6 +45,12 @@ export declare class RelationshipClasses extends ECClasses {
40
45
  * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
41
46
  */
42
47
  createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults>;
48
+ /**
49
+ * Sets the base class of a RelationshipClass.
50
+ * @param relationshipKey The SchemaItemKey of the RelationshipClass.
51
+ * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.
52
+ */
53
+ setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults>;
43
54
  createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults>;
44
55
  /**
45
56
  * Creates a Navigation Property through a NavigationPropertyProps.
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipClasses.d.ts","source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AE,eAAe,EAAE,uBAAuB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAczI,yBAAyB,CAAC,UAAU,EAAE,sBAAsB,EAAE,YAAY,EAAE,wBAAwB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAMrI,wBAAwB,CAAC,UAAU,EAAE,sBAAsB,EAAE,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAMlH,4BAA4B,CAAC,UAAU,EAAE,sBAAsB,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAMlI,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,kBAAkB,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAyBvJ,kBAAkB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAmBxI,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,WAAW,GAAG,KAAK,GAAG,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAa3I,8BAA8B,CAAC,UAAU,EAAE,sBAAsB,EAAE,eAAe,EAAE,eAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC;YAkBnI,QAAQ;CAoBvB"}
@@ -11,13 +11,18 @@ exports.RelationshipClasses = void 0;
11
11
  const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
12
  const ECClasses_1 = require("./ECClasses");
13
13
  const Rules = require("../Validation/ECRules");
14
+ const Properties_1 = require("./Properties");
14
15
  /**
15
16
  * @alpha
16
17
  * A class extending ECClasses allowing you to create schema items of type RelationshipClass.
17
18
  */
18
19
  class RelationshipClasses extends ECClasses_1.ECClasses {
19
- constructor(_schemaEditor) {
20
- super(_schemaEditor);
20
+ constructor(schemaEditor) {
21
+ super(ecschema_metadata_1.SchemaItemType.RelationshipClass, schemaEditor);
22
+ /**
23
+ * Allows access for editing of NavigationProperty attributes.
24
+ */
25
+ this.navigationProperties = new Properties_1.NavigationProperties(this.schemaItemType, this._schemaEditor);
21
26
  }
22
27
  /**
23
28
  * Creates a RelationshipClass.
@@ -70,7 +75,7 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
70
75
  * @returns A promise of type SchemaItemEditResults.
71
76
  */
72
77
  async setTargetConstraint(relationshipKey, target) {
73
- const relationship = (await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey));
78
+ const relationship = await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey);
74
79
  if (relationship === undefined)
75
80
  return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };
76
81
  relationship.setTargetConstraint(target);
@@ -93,6 +98,24 @@ class RelationshipClasses extends ECClasses_1.ECClasses {
93
98
  await newClass.target.fromJSON(relationshipProps.target);
94
99
  return { itemKey: newClass.key };
95
100
  }
101
+ /**
102
+ * Sets the base class of a RelationshipClass.
103
+ * @param relationshipKey The SchemaItemKey of the RelationshipClass.
104
+ * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.
105
+ */
106
+ async setBaseClass(itemKey, baseClassKey) {
107
+ const relClass = await this._schemaEditor.schemaContext.getSchemaItem(itemKey);
108
+ const baseClass = relClass?.baseClass;
109
+ const setResult = await super.setBaseClass(itemKey, baseClassKey);
110
+ if (setResult.errorMessage === undefined) {
111
+ const result = await this.validate(relClass);
112
+ if (result.errorMessage !== undefined) {
113
+ relClass.baseClass = baseClass;
114
+ return { itemKey, errorMessage: result.errorMessage };
115
+ }
116
+ }
117
+ return setResult;
118
+ }
96
119
  async createNavigationProperty(relationshipKey, name, relationship, direction) {
97
120
  const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem(relationshipKey));
98
121
  if (relationshipClass === undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipClasses.js","sourceRoot":"","sources":["../../../src/Editing/R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M,CAAC,EAAE,CAAC;SACrD;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAjPD,kDAiPC","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\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute, DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\r\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection, StrengthType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param name The name of the new class.\r\n * @param modifier The ECClassModifier of the new class.\r\n * @param strength The relationship StrengthType of the class.\r\n * @param StrengthDirection The relationship StrengthDirection of the class.\r\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\r\n */\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<RelationshipClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, RelationshipClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n newClass.setStrength(strength);\r\n newClass.setStrengthDirection(direction);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the source RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param source The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setSourceConstraint(source);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Sets the target RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param target The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setTargetConstraint(target);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass through a RelationshipClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (relationshipProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\r\n await newClass.fromJSON(relationshipProps);\r\n await newClass.source.fromJSON(relationshipProps.source);\r\n await newClass.target.fromJSON(relationshipProps.target);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n await relationshipClass.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: relationshipKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Relationship Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const relationshipClass = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name };\r\n }\r\n\r\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.multiplicity = multiplicity;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.polymorphic = polymorphic;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.relationshipEnd = relationshipEnd;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n\r\n if (undefined === abstractConstraint) {\r\n mutableConstraint.abstractConstraint = undefined;\r\n } else {\r\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\r\n }\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addClass(ecClass);\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.removeClass(ecClass);\r\n\r\n const result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.addClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(constraint, customAttribute);\r\n const result: SchemaItemEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(constraint, customAttribute);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n let diagnostics: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\r\n\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n diagnostics = Rules.validateRelationship(relationshipOrConstraint);\r\n } else {\r\n diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);\r\n }\r\n\r\n const errorMessages = [];\r\n for await (const diagnostic of diagnostics) {\r\n errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);\r\n }\r\n\r\n if (errorMessages.length > 0) {\r\n return { errorMessage: errorMessages.join(\"\\r\\n\") };\r\n }\r\n\r\n return {};\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"RelationshipClasses.js","sourceRoot":"","sources":["../../../src/Editing/RelationshipClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAIkC;AAElC,2CAAwC;AAExC,+CAA+C;AAE/C,6CAAoD;AAEpD;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,qBAAS;IAChD,YAAmB,YAAiC;QAClD,KAAK,CAAC,kCAAc,CAAC,iBAAiB,EAAE,YA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AC,UAAU,EAAE,eAAe,CAAC,CAAC;YACxD,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,EAAE,CAAC;IACvD,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,wBAAoE;QACzF,IAAI,WAAmI,CAAC;QAExI,IAAI,wBAAwB,YAAY,qCAAiB,EAAE,CAAC;YAC1D,WAAW,GAAG,KAAK,CAAC,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;QACrE,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,KAAK,CAAC,8BAA8B,CAAC,wBAAwB,CAAC,CAAC;QAC/E,CAAC;QAED,MAAM,aAAa,GAAG,EAAE,CAAC;QACzB,IAAI,KAAK,EAAE,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YAC3C,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,OAAO,EAAE,YAAY,EAAE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtD,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AA1QD,kDA0QC","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\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute, DelayedPromiseWithProps, ECClassModifier, EntityClass, LazyLoadedRelationshipConstraintClass, Mixin, NavigationPropertyProps,\r\n RelationshipClass, RelationshipClassProps, RelationshipConstraint, RelationshipEnd, RelationshipMultiplicity, SchemaItemKey, SchemaItemType,\r\n SchemaKey, StrengthDirection, StrengthType,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableRelationshipClass, MutableRelationshipConstraint } from \"./Mutable/MutableRelationshipClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { RelationshipConstraintDiagnostic, SchemaItemDiagnostic } from \"../Validation/Diagnostic\";\r\nimport { NavigationProperties } from \"./Properties\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type RelationshipClass.\r\n */\r\nexport class RelationshipClasses extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.RelationshipClass, schemaEditor);\r\n }\r\n\r\n /**\r\n * Allows access for editing of NavigationProperty attributes.\r\n */\r\n public readonly navigationProperties = new NavigationProperties(this.schemaItemType, this._schemaEditor);\r\n\r\n /**\r\n * Creates a RelationshipClass.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param name The name of the new class.\r\n * @param modifier The ECClassModifier of the new class.\r\n * @param strength The relationship StrengthType of the class.\r\n * @param StrengthDirection The relationship StrengthDirection of the class.\r\n * @param baseClassKey An optional SchemaItemKey that specifies the base relationship class.\r\n */\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, strength: StrengthType, direction: StrengthDirection, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const newClass = (await schema.createRelationshipClass(name, modifier)) as MutableRelationshipClass;\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<RelationshipClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Relationship Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, RelationshipClass>(baseClassKey, async () => baseClassItem);\r\n }\r\n\r\n newClass.setStrength(strength);\r\n newClass.setStrengthDirection(direction);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the source RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param source The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setSourceConstraint(relationshipKey: SchemaItemKey, source: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setSourceConstraint(source);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Sets the target RelationshipConstraint on the relationship.\r\n * @param relationshipKey The SchemaItemKey for the relationship.\r\n * @param target The RelationshipConstraint to add.\r\n * @returns A promise of type SchemaItemEditResults.\r\n */\r\n public async setTargetConstraint(relationshipKey: SchemaItemKey, target: RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n const relationship = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationship === undefined)\r\n return { itemKey: relationshipKey, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n relationship.setTargetConstraint(target);\r\n return { itemKey: relationshipKey };\r\n }\r\n\r\n /**\r\n * Creates a RelationshipClass through a RelationshipClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, relationshipProps: RelationshipClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (relationshipProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createRelationshipClass(relationshipProps.name)) as MutableRelationshipClass;\r\n await newClass.fromJSON(relationshipProps);\r\n await newClass.source.fromJSON(relationshipProps.source);\r\n await newClass.target.fromJSON(relationshipProps.target);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Sets the base class of a RelationshipClass.\r\n * @param relationshipKey The SchemaItemKey of the RelationshipClass.\r\n * @param baseClassKey The SchemaItemKey of the base class. Specifying 'undefined' removes the base class.\r\n */\r\n public override async setBaseClass(itemKey: SchemaItemKey, baseClassKey?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const relClass = await this._schemaEditor.schemaContext.getSchemaItem<RelationshipClass>(itemKey);\r\n const baseClass = relClass?.baseClass;\r\n\r\n const setResult = await super.setBaseClass(itemKey, baseClassKey);\r\n if (setResult.errorMessage === undefined) {\r\n const result = await this.validate(relClass!);\r\n if (result.errorMessage !== undefined) {\r\n relClass!.baseClass = baseClass;\r\n return { itemKey, errorMessage: result.errorMessage };\r\n }\r\n }\r\n return setResult;\r\n }\r\n\r\n public async createNavigationProperty(relationshipKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const relationshipClass = (await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey));\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n await relationshipClass.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: relationshipKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Relationship Class that will house the new property.\r\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\r\n */\r\n public async createNavigationPropertyFromProps(relationshipKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults> {\r\n const relationshipClass = await this._schemaEditor.schemaContext.getSchemaItem<MutableRelationshipClass>(relationshipKey);\r\n\r\n if (relationshipClass === undefined)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Relationship Class ${relationshipKey.fullName} not found in schema context.` };\r\n\r\n if (relationshipClass.schemaItemType !== SchemaItemType.RelationshipClass)\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name, errorMessage: `Expected ${relationshipKey.fullName} to be of type Relationship Class.` };\r\n\r\n const property = await relationshipClass.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n return { itemKey: relationshipKey, propertyName: navigationProps.name };\r\n }\r\n\r\n public async setConstraintMultiplicity(constraint: RelationshipConstraint, multiplicity: RelationshipMultiplicity): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.multiplicity = multiplicity;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintPolymorphic(constraint: RelationshipConstraint, polymorphic: boolean): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.polymorphic = polymorphic;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setConstraintRelationshipEnd(constraint: RelationshipConstraint, relationshipEnd: RelationshipEnd): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.relationshipEnd = relationshipEnd;\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async setAbstractConstraint(constraint: RelationshipConstraint, abstractConstraint?: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const existing: LazyLoadedRelationshipConstraintClass | undefined = constraint.abstractConstraint;\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n\r\n if (undefined === abstractConstraint) {\r\n mutableConstraint.abstractConstraint = undefined;\r\n } else {\r\n mutableConstraint.abstractConstraint = new DelayedPromiseWithProps(abstractConstraint.key, async () => abstractConstraint);\r\n }\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.abstractConstraint = existing;\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addClass(ecClass);\r\n\r\n let result = await this.validate(constraint.relationshipClass);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.removeClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async removeConstraintClass(constraint: RelationshipConstraint, ecClass: EntityClass | Mixin | RelationshipClass): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.removeClass(ecClass);\r\n\r\n const result = await this.validate(constraint);\r\n if (result.errorMessage) {\r\n mutableConstraint.addClass(ecClass);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n public async addCustomAttributeToConstraint(constraint: RelationshipConstraint, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n const mutableConstraint = constraint as MutableRelationshipConstraint;\r\n mutableConstraint.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(constraint, customAttribute);\r\n const result: SchemaItemEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(constraint, customAttribute);\r\n return result;\r\n }\r\n\r\n return { itemKey: constraint.relationshipClass.key };\r\n }\r\n\r\n private async validate(relationshipOrConstraint: RelationshipClass | RelationshipConstraint): Promise<SchemaItemEditResults> {\r\n let diagnostics: AsyncIterable<SchemaItemDiagnostic<RelationshipClass, any[]>> | AsyncIterable<RelationshipConstraintDiagnostic<any[]>>;\r\n\r\n if (relationshipOrConstraint instanceof RelationshipClass) {\r\n diagnostics = Rules.validateRelationship(relationshipOrConstraint);\r\n } else {\r\n diagnostics = Rules.validateRelationshipConstraint(relationshipOrConstraint);\r\n }\r\n\r\n const errorMessages = [];\r\n for await (const diagnostic of diagnostics) {\r\n errorMessages.push(`${diagnostic.code}: ${diagnostic.messageText}`);\r\n }\r\n\r\n if (errorMessages.length > 0) {\r\n return { errorMessage: errorMessages.join(\"\\r\\n\") };\r\n }\r\n\r\n return {};\r\n }\r\n}\r\n"]}
@@ -8,7 +8,7 @@ import { ECClasses } from "./ECClasses";
8
8
  * @alpha A class extending ECClasses allowing you to create schema items of type StructClass.
9
9
  */
10
10
  export declare class Structs extends ECClasses {
11
- constructor(_schemaEditor: SchemaContextEditor);
11
+ constructor(schemaEditor: SchemaContextEditor);
12
12
  create(schemaKey: SchemaKey, name: string, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults>;
13
13
  /**
14
14
  * Creates a StructClass through a StructClassProps.
@@ -1 +1 @@
1
- {"version":3,"file":"Structs.d.ts","sourceRoot":"","sources":["../../../src/Editing/Structs.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAoC,aAAa,EAAkB,SAAS,EAAe,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;GAEG;AACH,qBAAa,OAAQ,SAAQ,SAAS;gBACjB,aAAa,EAAE,mBAAmB;IAIxC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0BzI;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAelH"}
1
+ {"version":3,"file":"Structs.d.ts","sourceRoot":"","sources":["../../../src/Editing/Structs.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAoC,aAAa,EAAkB,SAAS,EAAe,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;GAEG;AACH,qBAAa,OAAQ,SAAQ,SAAS;gBACjB,YAAY,EAAE,mBAAmB;IAIvC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0BzI;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAelH"}
@@ -14,8 +14,8 @@ const ECClasses_1 = require("./ECClasses");
14
14
  * @alpha A class extending ECClasses allowing you to create schema items of type StructClass.
15
15
  */
16
16
  class Structs extends ECClasses_1.ECClasses {
17
- constructor(_schemaEditor) {
18
- super(_schemaEditor);
17
+ constructor(schemaEditor) {
18
+ super(ecschema_metadata_1.SchemaItemType.StructClass, schemaEditor);
19
19
  }
20
20
  async create(schemaKey, name, displayLabel, baseClass) {
21
21
  const schema = await this._schemaEditor.getSchema(schemaKey);