@itwin/ecschema-editing 4.0.0-dev.6 → 4.0.0-dev.61

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 (104) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/Editing/Constants.d.ts +20 -20
  3. package/lib/cjs/Editing/Constants.js +60 -60
  4. package/lib/cjs/Editing/CustomAttributes.d.ts +20 -20
  5. package/lib/cjs/Editing/CustomAttributes.js +59 -59
  6. package/lib/cjs/Editing/ECClasses.d.ts +54 -54
  7. package/lib/cjs/Editing/ECClasses.js +269 -269
  8. package/lib/cjs/Editing/Editor.d.ts +112 -112
  9. package/lib/cjs/Editing/Editor.js +166 -166
  10. package/lib/cjs/Editing/Entities.d.ts +25 -25
  11. package/lib/cjs/Editing/Entities.js +116 -116
  12. package/lib/cjs/Editing/Entities.js.map +1 -1
  13. package/lib/cjs/Editing/Enumerations.d.ts +21 -21
  14. package/lib/cjs/Editing/Enumerations.js +66 -66
  15. package/lib/cjs/Editing/Formats.d.ts +21 -21
  16. package/lib/cjs/Editing/Formats.js +61 -61
  17. package/lib/cjs/Editing/InvertedUnits.d.ts +17 -17
  18. package/lib/cjs/Editing/InvertedUnits.js +82 -82
  19. package/lib/cjs/Editing/KindOfQuantities.d.ts +28 -28
  20. package/lib/cjs/Editing/KindOfQuantities.js +78 -78
  21. package/lib/cjs/Editing/Mixins.d.ts +22 -22
  22. package/lib/cjs/Editing/Mixins.js +84 -84
  23. package/lib/cjs/Editing/Mutable/MutableCAClass.d.ts +9 -9
  24. package/lib/cjs/Editing/Mutable/MutableCAClass.js +15 -15
  25. package/lib/cjs/Editing/Mutable/MutableClass.d.ts +34 -34
  26. package/lib/cjs/Editing/Mutable/MutableClass.js +22 -22
  27. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +12 -12
  28. package/lib/cjs/Editing/Mutable/MutableConstant.js +15 -15
  29. package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +15 -15
  30. package/lib/cjs/Editing/Mutable/MutableEntityClass.js +59 -59
  31. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +9 -9
  32. package/lib/cjs/Editing/Mutable/MutableEnumeration.js +14 -14
  33. package/lib/cjs/Editing/Mutable/MutableFormat.d.ts +18 -18
  34. package/lib/cjs/Editing/Mutable/MutableFormat.js +15 -15
  35. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.d.ts +10 -10
  36. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js +15 -15
  37. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +10 -10
  38. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js +15 -15
  39. package/lib/cjs/Editing/Mutable/MutableMixin.d.ts +11 -11
  40. package/lib/cjs/Editing/Mutable/MutableMixin.js +15 -15
  41. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts +9 -9
  42. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js +15 -15
  43. package/lib/cjs/Editing/Mutable/MutableProperty.d.ts +8 -8
  44. package/lib/cjs/Editing/Mutable/MutableProperty.js +15 -15
  45. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +9 -9
  46. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js +15 -15
  47. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts +21 -21
  48. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js +24 -24
  49. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +45 -45
  50. package/lib/cjs/Editing/Mutable/MutableSchema.js +17 -17
  51. package/lib/cjs/Editing/Mutable/MutableUnit.d.ts +11 -11
  52. package/lib/cjs/Editing/Mutable/MutableUnit.js +15 -15
  53. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +8 -8
  54. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js +15 -15
  55. package/lib/cjs/Editing/Phenomena.d.ts +15 -15
  56. package/lib/cjs/Editing/Phenomena.js +44 -44
  57. package/lib/cjs/Editing/PropertyCategories.d.ts +16 -16
  58. package/lib/cjs/Editing/PropertyCategories.js +51 -51
  59. package/lib/cjs/Editing/RelationshipClasses.d.ts +21 -21
  60. package/lib/cjs/Editing/RelationshipClasses.js +68 -68
  61. package/lib/cjs/Editing/Structs.d.ts +19 -19
  62. package/lib/cjs/Editing/Structs.js +57 -57
  63. package/lib/cjs/Editing/UnitSystems.d.ts +15 -15
  64. package/lib/cjs/Editing/UnitSystems.js +41 -41
  65. package/lib/cjs/Editing/Units.d.ts +15 -15
  66. package/lib/cjs/Editing/Units.js +58 -58
  67. package/lib/cjs/Validation/Diagnostic.d.ts +321 -321
  68. package/lib/cjs/Validation/Diagnostic.d.ts.map +1 -1
  69. package/lib/cjs/Validation/Diagnostic.js +310 -310
  70. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  71. package/lib/cjs/Validation/DiagnosticReporter.d.ts +96 -96
  72. package/lib/cjs/Validation/DiagnosticReporter.js +106 -106
  73. package/lib/cjs/Validation/ECRules.d.ts +448 -448
  74. package/lib/cjs/Validation/ECRules.js +593 -593
  75. package/lib/cjs/Validation/LoggingDiagnosticReporter.d.ts +13 -13
  76. package/lib/cjs/Validation/LoggingDiagnosticReporter.js +40 -40
  77. package/lib/cjs/Validation/RuleSuppressionSet.d.ts +59 -59
  78. package/lib/cjs/Validation/RuleSuppressionSet.d.ts.map +1 -1
  79. package/lib/cjs/Validation/RuleSuppressionSet.js +9 -9
  80. package/lib/cjs/Validation/Rules.d.ts +64 -64
  81. package/lib/cjs/Validation/Rules.d.ts.map +1 -1
  82. package/lib/cjs/Validation/Rules.js +9 -9
  83. package/lib/cjs/Validation/SchemaChanges.d.ts +607 -607
  84. package/lib/cjs/Validation/SchemaChanges.js +1135 -1135
  85. package/lib/cjs/Validation/SchemaCompareDiagnostics.d.ts +422 -422
  86. package/lib/cjs/Validation/SchemaCompareDiagnostics.js +111 -111
  87. package/lib/cjs/Validation/SchemaCompareReporter.d.ts +11 -11
  88. package/lib/cjs/Validation/SchemaCompareReporter.js +9 -9
  89. package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +236 -236
  90. package/lib/cjs/Validation/SchemaCompareResultDelegate.js +348 -348
  91. package/lib/cjs/Validation/SchemaCompareVisitor.d.ts +119 -119
  92. package/lib/cjs/Validation/SchemaCompareVisitor.js +206 -206
  93. package/lib/cjs/Validation/SchemaComparer.d.ts +171 -171
  94. package/lib/cjs/Validation/SchemaComparer.js +666 -666
  95. package/lib/cjs/Validation/SchemaValidater.d.ts +19 -19
  96. package/lib/cjs/Validation/SchemaValidater.js +61 -61
  97. package/lib/cjs/Validation/SchemaValidationVisitor.d.ts +170 -170
  98. package/lib/cjs/Validation/SchemaValidationVisitor.js +492 -492
  99. package/lib/cjs/Validation/SchemaWalker.d.ts +22 -22
  100. package/lib/cjs/Validation/SchemaWalker.js +51 -51
  101. package/lib/cjs/ecschema-editing.d.ts +33 -33
  102. package/lib/cjs/ecschema-editing.js +58 -54
  103. package/lib/cjs/ecschema-editing.js.map +1 -1
  104. package/package.json +12 -12
@@ -1,270 +1,270 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Editing
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ECClasses = void 0;
11
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
- const core_bentley_1 = require("@itwin/core-bentley");
13
- const Rules = require("../Validation/ECRules");
14
- /**
15
- * @alpha
16
- * Acts as a base class for schema class creation. Enables property creation.
17
- */
18
- class ECClasses {
19
- constructor(_schemaEditor) {
20
- this._schemaEditor = _schemaEditor;
21
- }
22
- /**
23
- * Creates a property on class identified by the given SchemaItemKey. This method restricts the
24
- * property type to primitives of type Double, String, DateTime and Integer.
25
- * @param classKey The SchemaItemKey of the class.
26
- * @param name The name of the new property.
27
- * @param type The PrimitiveType assigned to the new property.
28
- */
29
- async createProperty(classKey, name, type, prefix) {
30
- let mutableClass;
31
- if (type !== ecschema_metadata_1.PrimitiveType.Double && type !== ecschema_metadata_1.PrimitiveType.String && type !== ecschema_metadata_1.PrimitiveType.DateTime
32
- && type !== ecschema_metadata_1.PrimitiveType.Integer)
33
- throw new Error("Property creation is restricted to type Double, String, DateTime, and Integer.");
34
- if ("" === prefix)
35
- throw new Error("The specified property name prefix is invalid");
36
- const prefixedName = `${prefix}_${name}`;
37
- try {
38
- mutableClass = await this.getClass(classKey);
39
- }
40
- catch (e) {
41
- return { errorMessage: e.message };
42
- }
43
- await mutableClass.createPrimitiveProperty(prefixedName, type);
44
- return { itemKey: classKey, propertyName: prefixedName };
45
- }
46
- /**
47
- * Create a primitive property on class identified by the given SchemaItemKey.
48
- * @param classKey The SchemaItemKey of the class.
49
- * @param name The name of the new property.
50
- * @param type The PrimitiveType assigned to the new property.
51
- */
52
- async createPrimitiveProperty(classKey, name, type) {
53
- let mutableClass;
54
- try {
55
- mutableClass = await this.getClass(classKey);
56
- }
57
- catch (e) {
58
- return { errorMessage: e.message };
59
- }
60
- await mutableClass.createPrimitiveProperty(name, type);
61
- return { itemKey: classKey, propertyName: name };
62
- }
63
- async createPrimitivePropertyFromProps(classKey, name, type, primitiveProps) {
64
- let mutableClass;
65
- try {
66
- mutableClass = await this.getClass(classKey);
67
- }
68
- catch (e) {
69
- return { errorMessage: e.message };
70
- }
71
- const newProperty = await mutableClass.createPrimitiveProperty(name, type);
72
- await newProperty.fromJSON(primitiveProps);
73
- return { itemKey: classKey, propertyName: name };
74
- }
75
- async createEnumerationProperty(classKey, name, type) {
76
- let mutableClass;
77
- try {
78
- mutableClass = await this.getClass(classKey);
79
- }
80
- catch (e) {
81
- return { errorMessage: e.message };
82
- }
83
- const enumSchemaItemKey = mutableClass.schema.getSchemaItemKey(type.fullName);
84
- if (enumSchemaItemKey === undefined)
85
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${type.fullName}.`);
86
- await mutableClass.createPrimitiveProperty(name, type);
87
- return { itemKey: classKey, propertyName: name };
88
- }
89
- async createEnumerationPropertyFromProps(classKey, name, type, enumProps) {
90
- let mutableClass;
91
- try {
92
- mutableClass = await this.getClass(classKey);
93
- }
94
- catch (e) {
95
- return { errorMessage: e.message };
96
- }
97
- const newProperty = await mutableClass.createPrimitiveProperty(name, type);
98
- await newProperty.fromJSON(enumProps);
99
- return { itemKey: classKey, propertyName: name };
100
- }
101
- async createPrimitiveArrayProperty(classKey, name, type) {
102
- let mutableClass;
103
- try {
104
- mutableClass = await this.getClass(classKey);
105
- }
106
- catch (e) {
107
- return { errorMessage: e.message };
108
- }
109
- await mutableClass.createPrimitiveArrayProperty(name, type);
110
- return { itemKey: classKey, propertyName: name };
111
- }
112
- async createPrimitiveArrayPropertyFromProps(classKey, name, type, primitiveProps) {
113
- let mutableClass;
114
- try {
115
- mutableClass = await this.getClass(classKey);
116
- }
117
- catch (e) {
118
- return { errorMessage: e.message };
119
- }
120
- const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);
121
- await newProperty.fromJSON(primitiveProps);
122
- return { itemKey: classKey, propertyName: name };
123
- }
124
- async createStructProperty(classKey, name, type) {
125
- let mutableClass;
126
- try {
127
- mutableClass = await this.getClass(classKey);
128
- }
129
- catch (e) {
130
- return { errorMessage: e.message };
131
- }
132
- await mutableClass.createStructProperty(name, type);
133
- return { itemKey: classKey, propertyName: name };
134
- }
135
- async createStructPropertyFromProps(classKey, name, type, structProps) {
136
- let mutableClass;
137
- try {
138
- mutableClass = await this.getClass(classKey);
139
- }
140
- catch (e) {
141
- return { errorMessage: e.message };
142
- }
143
- const newProperty = await mutableClass.createStructProperty(name, type);
144
- await newProperty.fromJSON(structProps);
145
- return { itemKey: classKey, propertyName: name };
146
- }
147
- async createStructArrayProperty(classKey, name, type) {
148
- let mutableClass;
149
- try {
150
- mutableClass = await this.getClass(classKey);
151
- }
152
- catch (e) {
153
- return { errorMessage: e.message };
154
- }
155
- await mutableClass.createStructArrayProperty(name, type);
156
- return { itemKey: classKey, propertyName: name };
157
- }
158
- async createStructArrayPropertyFromProps(classKey, name, type, structProps) {
159
- let mutableClass;
160
- try {
161
- mutableClass = await this.getClass(classKey);
162
- }
163
- catch (e) {
164
- return { errorMessage: e.message };
165
- }
166
- const newProperty = await mutableClass.createStructArrayProperty(name, type);
167
- await newProperty.fromJSON(structProps);
168
- return { itemKey: classKey, propertyName: name };
169
- }
170
- async deleteProperty(classKey, name) {
171
- let mutableClass;
172
- try {
173
- mutableClass = await this.getClass(classKey);
174
- }
175
- catch (e) {
176
- return { errorMessage: e.message };
177
- }
178
- await mutableClass.deleteProperty(name);
179
- return { itemKey: classKey, propertyName: name };
180
- }
181
- async delete(classKey) {
182
- const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
183
- if (schema === undefined)
184
- return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };
185
- const ecClass = await schema.getItem(classKey.name);
186
- if (ecClass === undefined)
187
- return {};
188
- await schema.deleteClass(ecClass.name);
189
- return { itemKey: classKey };
190
- }
191
- /**
192
- * Adds a CustomAttribute instance to the Class identified by the given SchemaItemKey
193
- * @param classKey The SchemaItemKey identifying the schema.
194
- * @param customAttribute The CustomAttribute instance to add.
195
- */
196
- async addCustomAttribute(classKey, customAttribute) {
197
- let mutableClass;
198
- try {
199
- mutableClass = await this.getClass(classKey);
200
- }
201
- catch (e) {
202
- return { errorMessage: e.message };
203
- }
204
- mutableClass.addCustomAttribute(customAttribute);
205
- const diagnostics = Rules.validateCustomAttributeInstance(mutableClass, customAttribute);
206
- const result = { errorMessage: "" };
207
- for await (const diagnostic of diagnostics) {
208
- result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
209
- }
210
- if (result.errorMessage) {
211
- this.removeCustomAttribute(mutableClass, customAttribute);
212
- return result;
213
- }
214
- return {};
215
- }
216
- /**
217
- * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.
218
- * @param classKey The SchemaItemKey identifying the class.
219
- * @param propertyName The name of the property.
220
- * @param customAttribute The CustomAttribute instance to add.
221
- */
222
- async addCustomAttributeToProperty(classKey, propertyName, customAttribute) {
223
- let mutableClass;
224
- try {
225
- mutableClass = await this.getClass(classKey);
226
- }
227
- catch (e) {
228
- return { errorMessage: e.message };
229
- }
230
- const property = await mutableClass.getProperty(propertyName);
231
- if (!property) {
232
- return { errorMessage: `Property with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };
233
- }
234
- property.addCustomAttribute(customAttribute);
235
- const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);
236
- const result = { errorMessage: "" };
237
- for await (const diagnostic of diagnostics) {
238
- result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
239
- }
240
- if (result.errorMessage) {
241
- this.removeCustomAttribute(property, customAttribute);
242
- return result;
243
- }
244
- return {};
245
- }
246
- async getClass(classKey) {
247
- const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
248
- const ecClass = await schema.getItem(classKey.name);
249
- if (ecClass === undefined)
250
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);
251
- switch (ecClass.schemaItemType) {
252
- case ecschema_metadata_1.SchemaItemType.EntityClass:
253
- case ecschema_metadata_1.SchemaItemType.Mixin:
254
- case ecschema_metadata_1.SchemaItemType.StructClass:
255
- case ecschema_metadata_1.SchemaItemType.CustomAttributeClass:
256
- case ecschema_metadata_1.SchemaItemType.RelationshipClass:
257
- break;
258
- default:
259
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);
260
- }
261
- return ecClass;
262
- }
263
- removeCustomAttribute(container, customAttribute) {
264
- (0, core_bentley_1.assert)(container.customAttributes !== undefined);
265
- const map = container.customAttributes;
266
- map.delete(customAttribute.className);
267
- }
268
- }
269
- exports.ECClasses = ECClasses;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Editing
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ECClasses = void 0;
11
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const Rules = require("../Validation/ECRules");
14
+ /**
15
+ * @alpha
16
+ * Acts as a base class for schema class creation. Enables property creation.
17
+ */
18
+ class ECClasses {
19
+ constructor(_schemaEditor) {
20
+ this._schemaEditor = _schemaEditor;
21
+ }
22
+ /**
23
+ * Creates a property on class identified by the given SchemaItemKey. This method restricts the
24
+ * property type to primitives of type Double, String, DateTime and Integer.
25
+ * @param classKey The SchemaItemKey of the class.
26
+ * @param name The name of the new property.
27
+ * @param type The PrimitiveType assigned to the new property.
28
+ */
29
+ async createProperty(classKey, name, type, prefix) {
30
+ let mutableClass;
31
+ if (type !== ecschema_metadata_1.PrimitiveType.Double && type !== ecschema_metadata_1.PrimitiveType.String && type !== ecschema_metadata_1.PrimitiveType.DateTime
32
+ && type !== ecschema_metadata_1.PrimitiveType.Integer)
33
+ throw new Error("Property creation is restricted to type Double, String, DateTime, and Integer.");
34
+ if ("" === prefix)
35
+ throw new Error("The specified property name prefix is invalid");
36
+ const prefixedName = `${prefix}_${name}`;
37
+ try {
38
+ mutableClass = await this.getClass(classKey);
39
+ }
40
+ catch (e) {
41
+ return { errorMessage: e.message };
42
+ }
43
+ await mutableClass.createPrimitiveProperty(prefixedName, type);
44
+ return { itemKey: classKey, propertyName: prefixedName };
45
+ }
46
+ /**
47
+ * Create a primitive property on class identified by the given SchemaItemKey.
48
+ * @param classKey The SchemaItemKey of the class.
49
+ * @param name The name of the new property.
50
+ * @param type The PrimitiveType assigned to the new property.
51
+ */
52
+ async createPrimitiveProperty(classKey, name, type) {
53
+ let mutableClass;
54
+ try {
55
+ mutableClass = await this.getClass(classKey);
56
+ }
57
+ catch (e) {
58
+ return { errorMessage: e.message };
59
+ }
60
+ await mutableClass.createPrimitiveProperty(name, type);
61
+ return { itemKey: classKey, propertyName: name };
62
+ }
63
+ async createPrimitivePropertyFromProps(classKey, name, type, primitiveProps) {
64
+ let mutableClass;
65
+ try {
66
+ mutableClass = await this.getClass(classKey);
67
+ }
68
+ catch (e) {
69
+ return { errorMessage: e.message };
70
+ }
71
+ const newProperty = await mutableClass.createPrimitiveProperty(name, type);
72
+ await newProperty.fromJSON(primitiveProps);
73
+ return { itemKey: classKey, propertyName: name };
74
+ }
75
+ async createEnumerationProperty(classKey, name, type) {
76
+ let mutableClass;
77
+ try {
78
+ mutableClass = await this.getClass(classKey);
79
+ }
80
+ catch (e) {
81
+ return { errorMessage: e.message };
82
+ }
83
+ const enumSchemaItemKey = mutableClass.schema.getSchemaItemKey(type.fullName);
84
+ if (enumSchemaItemKey === undefined)
85
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${type.fullName}.`);
86
+ await mutableClass.createPrimitiveProperty(name, type);
87
+ return { itemKey: classKey, propertyName: name };
88
+ }
89
+ async createEnumerationPropertyFromProps(classKey, name, type, enumProps) {
90
+ let mutableClass;
91
+ try {
92
+ mutableClass = await this.getClass(classKey);
93
+ }
94
+ catch (e) {
95
+ return { errorMessage: e.message };
96
+ }
97
+ const newProperty = await mutableClass.createPrimitiveProperty(name, type);
98
+ await newProperty.fromJSON(enumProps);
99
+ return { itemKey: classKey, propertyName: name };
100
+ }
101
+ async createPrimitiveArrayProperty(classKey, name, type) {
102
+ let mutableClass;
103
+ try {
104
+ mutableClass = await this.getClass(classKey);
105
+ }
106
+ catch (e) {
107
+ return { errorMessage: e.message };
108
+ }
109
+ await mutableClass.createPrimitiveArrayProperty(name, type);
110
+ return { itemKey: classKey, propertyName: name };
111
+ }
112
+ async createPrimitiveArrayPropertyFromProps(classKey, name, type, primitiveProps) {
113
+ let mutableClass;
114
+ try {
115
+ mutableClass = await this.getClass(classKey);
116
+ }
117
+ catch (e) {
118
+ return { errorMessage: e.message };
119
+ }
120
+ const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);
121
+ await newProperty.fromJSON(primitiveProps);
122
+ return { itemKey: classKey, propertyName: name };
123
+ }
124
+ async createStructProperty(classKey, name, type) {
125
+ let mutableClass;
126
+ try {
127
+ mutableClass = await this.getClass(classKey);
128
+ }
129
+ catch (e) {
130
+ return { errorMessage: e.message };
131
+ }
132
+ await mutableClass.createStructProperty(name, type);
133
+ return { itemKey: classKey, propertyName: name };
134
+ }
135
+ async createStructPropertyFromProps(classKey, name, type, structProps) {
136
+ let mutableClass;
137
+ try {
138
+ mutableClass = await this.getClass(classKey);
139
+ }
140
+ catch (e) {
141
+ return { errorMessage: e.message };
142
+ }
143
+ const newProperty = await mutableClass.createStructProperty(name, type);
144
+ await newProperty.fromJSON(structProps);
145
+ return { itemKey: classKey, propertyName: name };
146
+ }
147
+ async createStructArrayProperty(classKey, name, type) {
148
+ let mutableClass;
149
+ try {
150
+ mutableClass = await this.getClass(classKey);
151
+ }
152
+ catch (e) {
153
+ return { errorMessage: e.message };
154
+ }
155
+ await mutableClass.createStructArrayProperty(name, type);
156
+ return { itemKey: classKey, propertyName: name };
157
+ }
158
+ async createStructArrayPropertyFromProps(classKey, name, type, structProps) {
159
+ let mutableClass;
160
+ try {
161
+ mutableClass = await this.getClass(classKey);
162
+ }
163
+ catch (e) {
164
+ return { errorMessage: e.message };
165
+ }
166
+ const newProperty = await mutableClass.createStructArrayProperty(name, type);
167
+ await newProperty.fromJSON(structProps);
168
+ return { itemKey: classKey, propertyName: name };
169
+ }
170
+ async deleteProperty(classKey, name) {
171
+ let mutableClass;
172
+ try {
173
+ mutableClass = await this.getClass(classKey);
174
+ }
175
+ catch (e) {
176
+ return { errorMessage: e.message };
177
+ }
178
+ await mutableClass.deleteProperty(name);
179
+ return { itemKey: classKey, propertyName: name };
180
+ }
181
+ async delete(classKey) {
182
+ const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
183
+ if (schema === undefined)
184
+ return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };
185
+ const ecClass = await schema.getItem(classKey.name);
186
+ if (ecClass === undefined)
187
+ return {};
188
+ await schema.deleteClass(ecClass.name);
189
+ return { itemKey: classKey };
190
+ }
191
+ /**
192
+ * Adds a CustomAttribute instance to the Class identified by the given SchemaItemKey
193
+ * @param classKey The SchemaItemKey identifying the schema.
194
+ * @param customAttribute The CustomAttribute instance to add.
195
+ */
196
+ async addCustomAttribute(classKey, customAttribute) {
197
+ let mutableClass;
198
+ try {
199
+ mutableClass = await this.getClass(classKey);
200
+ }
201
+ catch (e) {
202
+ return { errorMessage: e.message };
203
+ }
204
+ mutableClass.addCustomAttribute(customAttribute);
205
+ const diagnostics = Rules.validateCustomAttributeInstance(mutableClass, customAttribute);
206
+ const result = { errorMessage: "" };
207
+ for await (const diagnostic of diagnostics) {
208
+ result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
209
+ }
210
+ if (result.errorMessage) {
211
+ this.removeCustomAttribute(mutableClass, customAttribute);
212
+ return result;
213
+ }
214
+ return {};
215
+ }
216
+ /**
217
+ * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.
218
+ * @param classKey The SchemaItemKey identifying the class.
219
+ * @param propertyName The name of the property.
220
+ * @param customAttribute The CustomAttribute instance to add.
221
+ */
222
+ async addCustomAttributeToProperty(classKey, propertyName, customAttribute) {
223
+ let mutableClass;
224
+ try {
225
+ mutableClass = await this.getClass(classKey);
226
+ }
227
+ catch (e) {
228
+ return { errorMessage: e.message };
229
+ }
230
+ const property = await mutableClass.getProperty(propertyName);
231
+ if (!property) {
232
+ return { errorMessage: `Property with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };
233
+ }
234
+ property.addCustomAttribute(customAttribute);
235
+ const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);
236
+ const result = { errorMessage: "" };
237
+ for await (const diagnostic of diagnostics) {
238
+ result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
239
+ }
240
+ if (result.errorMessage) {
241
+ this.removeCustomAttribute(property, customAttribute);
242
+ return result;
243
+ }
244
+ return {};
245
+ }
246
+ async getClass(classKey) {
247
+ const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
248
+ const ecClass = await schema.getItem(classKey.name);
249
+ if (ecClass === undefined)
250
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);
251
+ switch (ecClass.schemaItemType) {
252
+ case ecschema_metadata_1.SchemaItemType.EntityClass:
253
+ case ecschema_metadata_1.SchemaItemType.Mixin:
254
+ case ecschema_metadata_1.SchemaItemType.StructClass:
255
+ case ecschema_metadata_1.SchemaItemType.CustomAttributeClass:
256
+ case ecschema_metadata_1.SchemaItemType.RelationshipClass:
257
+ break;
258
+ default:
259
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);
260
+ }
261
+ return ecClass;
262
+ }
263
+ removeCustomAttribute(container, customAttribute) {
264
+ (0, core_bentley_1.assert)(container.customAttributes !== undefined);
265
+ const map = container.customAttributes;
266
+ map.delete(customAttribute.className);
267
+ }
268
+ }
269
+ exports.ECClasses = ECClasses;
270
270
  //# sourceMappingURL=ECClasses.js.map