@itwin/ecschema-editing 5.0.0-dev.6 → 5.0.0-dev.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -1
- package/lib/cjs/Differencing/Errors.js +6 -0
- package/lib/cjs/Differencing/Errors.js.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts +3 -1
- package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.js +2 -0
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +4 -3
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +57 -11
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.d.ts +33 -4
- package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.js +55 -5
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceValidator.d.ts +2 -1
- package/lib/cjs/Differencing/SchemaDifferenceValidator.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceValidator.js +78 -19
- package/lib/cjs/Differencing/SchemaDifferenceValidator.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceVisitor.d.ts.map +1 -1
- package/lib/cjs/Differencing/SchemaDifferenceVisitor.js +5 -0
- package/lib/cjs/Differencing/SchemaDifferenceVisitor.js.map +1 -1
- package/lib/cjs/Differencing/Utils.js.map +1 -1
- package/lib/cjs/Editing/Constants.d.ts +2 -1
- package/lib/cjs/Editing/Constants.d.ts.map +1 -1
- package/lib/cjs/Editing/Constants.js +4 -1
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts +2 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js +3 -0
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +6 -0
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +48 -35
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +2 -2
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +32 -21
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +2 -1
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +18 -14
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.d.ts +2 -1
- package/lib/cjs/Editing/Enumerations.d.ts.map +1 -1
- package/lib/cjs/Editing/Enumerations.js +6 -3
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Exception.js +35 -6
- package/lib/cjs/Editing/Exception.js.map +1 -1
- package/lib/cjs/Editing/Formats.d.ts +2 -1
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +5 -1
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts +2 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js +10 -6
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +2 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +11 -7
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +2 -1
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +13 -9
- package/lib/cjs/Editing/Mixins.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts +2 -1
- package/lib/cjs/Editing/Mutable/MutableClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.d.ts +8 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableNavigationProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableSchemaItem.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableStructProperty.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
- package/lib/cjs/Editing/Phenomena.d.ts +2 -1
- package/lib/cjs/Editing/Phenomena.d.ts.map +1 -1
- package/lib/cjs/Editing/Phenomena.js +3 -0
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/Properties.d.ts +2 -2
- package/lib/cjs/Editing/Properties.d.ts.map +1 -1
- package/lib/cjs/Editing/Properties.js +6 -4
- package/lib/cjs/Editing/Properties.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts +2 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js +5 -1
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +1 -0
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +17 -10
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +2 -2
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js +8 -11
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.d.ts +2 -1
- package/lib/cjs/Editing/Structs.d.ts.map +1 -1
- package/lib/cjs/Editing/Structs.js +3 -0
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.d.ts +2 -1
- package/lib/cjs/Editing/UnitSystems.d.ts.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js +3 -0
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.d.ts +2 -1
- package/lib/cjs/Editing/Units.d.ts.map +1 -1
- package/lib/cjs/Editing/Units.js +5 -2
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +4 -4
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeClassMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +7 -6
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/Edits/NameMapping.d.ts +22 -0
- package/lib/cjs/Merging/Edits/NameMapping.d.ts.map +1 -0
- package/lib/cjs/Merging/Edits/NameMapping.js +54 -0
- package/lib/cjs/Merging/Edits/NameMapping.js.map +1 -0
- package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts +1 -1
- package/lib/cjs/Merging/Edits/RenameEditHandler.d.ts.map +1 -1
- package/lib/cjs/Merging/Edits/RenameEditHandler.js +1 -260
- package/lib/cjs/Merging/Edits/RenameEditHandler.js.map +1 -1
- package/lib/cjs/Merging/Edits/SchemaEdits.d.ts +9 -6
- package/lib/cjs/Merging/Edits/SchemaEdits.d.ts.map +1 -1
- package/lib/cjs/Merging/Edits/SchemaEdits.js +19 -14
- package/lib/cjs/Merging/Edits/SchemaEdits.js.map +1 -1
- package/lib/cjs/Merging/Edits/SkipEditHandler.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +1 -2
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumeratorMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumeratorMerger.js +2 -2
- package/lib/cjs/Merging/EnumeratorMerger.js.map +1 -1
- package/lib/cjs/Merging/FormatMerger.d.ts +24 -0
- package/lib/cjs/Merging/FormatMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/FormatMerger.js +143 -0
- package/lib/cjs/Merging/FormatMerger.js.map +1 -0
- package/lib/cjs/Merging/InvertedUnitMerger.d.ts +14 -0
- package/lib/cjs/Merging/InvertedUnitMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/InvertedUnitMerger.js +45 -0
- package/lib/cjs/Merging/InvertedUnitMerger.js.map +1 -0
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js +4 -5
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +1 -1
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +28 -26
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js +4 -4
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts +5 -3
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +40 -5
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMergingVisitor.d.ts +14 -8
- package/lib/cjs/Merging/SchemaMergingVisitor.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMergingVisitor.js +42 -17
- package/lib/cjs/Merging/SchemaMergingVisitor.js.map +1 -1
- package/lib/cjs/Merging/SchemaMergingWalker.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMergingWalker.js +2 -0
- package/lib/cjs/Merging/SchemaMergingWalker.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/lib/cjs/Merging/StructClassMerger.js.map +1 -1
- package/lib/cjs/Merging/UnitMerger.d.ts +14 -0
- package/lib/cjs/Merging/UnitMerger.d.ts.map +1 -0
- package/lib/cjs/Merging/UnitMerger.js +62 -0
- package/lib/cjs/Merging/UnitMerger.js.map +1 -0
- package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
- package/lib/cjs/Merging/Utils.d.ts +11 -0
- package/lib/cjs/Merging/Utils.d.ts.map +1 -1
- package/lib/cjs/Merging/Utils.js +23 -3
- package/lib/cjs/Merging/Utils.js.map +1 -1
- package/lib/cjs/Validation/Diagnostic.js +18 -16
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.js +3 -0
- package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/ECRules.js +1 -1
- package/lib/cjs/Validation/ECRules.js.map +1 -1
- package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
- package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
- package/lib/cjs/Validation/Rules.js.map +1 -1
- package/lib/cjs/Validation/SchemaChanges.js +39 -69
- package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareDiagnostics.d.ts +2 -2
- package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js +4 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.js +23 -23
- package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.d.ts +22 -1
- package/lib/cjs/Validation/SchemaComparer.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js +30 -5
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidater.js +1 -4
- package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidationVisitor.js +3 -4
- package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts +1 -1
- package/lib/cjs/Validation/SchemaWalker.d.ts.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js +4 -0
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +10 -10
- package/public/locales/en/ECSchemaEditing.json +26 -26
|
@@ -31,30 +31,33 @@ const Exception_1 = require("./Exception");
|
|
|
31
31
|
* @alpha
|
|
32
32
|
*/
|
|
33
33
|
class SchemaContextEditor {
|
|
34
|
+
_schemaContext;
|
|
35
|
+
entities = new Entities_1.Entities(this);
|
|
36
|
+
mixins = new Mixins_1.Mixins(this);
|
|
37
|
+
structs = new Structs_1.Structs(this);
|
|
38
|
+
customAttributes = new CustomAttributes_1.CustomAttributes(this);
|
|
39
|
+
relationships = new RelationshipClasses_1.RelationshipClasses(this);
|
|
40
|
+
constants = new Constants_1.Constants(this);
|
|
41
|
+
enumerations = new Enumerations_1.Enumerations(this);
|
|
42
|
+
formats = new Formats_1.Formats(this);
|
|
43
|
+
kindOfQuantities = new KindOfQuantities_1.KindOfQuantities(this);
|
|
44
|
+
units = new Units_1.Units(this);
|
|
45
|
+
phenomenons = new Phenomena_1.Phenomena(this);
|
|
46
|
+
unitSystems = new UnitSystems_1.UnitSystems(this);
|
|
47
|
+
propertyCategories = new PropertyCategories_1.PropertyCategories(this);
|
|
48
|
+
invertedUnits = new InvertedUnits_1.InvertedUnits(this);
|
|
34
49
|
/**
|
|
35
50
|
* Creates a new SchemaContextEditor instance.
|
|
36
51
|
* @param schemaContext The SchemaContext the Editor will use to edit in.
|
|
37
52
|
*/
|
|
38
53
|
constructor(schemaContext) {
|
|
39
|
-
this.entities = new Entities_1.Entities(this);
|
|
40
|
-
this.mixins = new Mixins_1.Mixins(this);
|
|
41
|
-
this.structs = new Structs_1.Structs(this);
|
|
42
|
-
this.customAttributes = new CustomAttributes_1.CustomAttributes(this);
|
|
43
|
-
this.relationships = new RelationshipClasses_1.RelationshipClasses(this);
|
|
44
|
-
this.constants = new Constants_1.Constants(this);
|
|
45
|
-
this.enumerations = new Enumerations_1.Enumerations(this);
|
|
46
|
-
this.formats = new Formats_1.Formats(this);
|
|
47
|
-
this.kindOfQuantities = new KindOfQuantities_1.KindOfQuantities(this);
|
|
48
|
-
this.units = new Units_1.Units(this);
|
|
49
|
-
this.phenomenons = new Phenomena_1.Phenomena(this);
|
|
50
|
-
this.unitSystems = new UnitSystems_1.UnitSystems(this);
|
|
51
|
-
this.propertyCategories = new PropertyCategories_1.PropertyCategories(this);
|
|
52
|
-
this.invertedUnits = new InvertedUnits_1.InvertedUnits(this);
|
|
53
54
|
// TODO: Make copy
|
|
54
55
|
this._schemaContext = schemaContext;
|
|
55
56
|
}
|
|
56
57
|
/** Allows you to get schema classes and items through regular SchemaContext methods. */
|
|
57
|
-
get schemaContext() {
|
|
58
|
+
get schemaContext() {
|
|
59
|
+
return this._schemaContext;
|
|
60
|
+
}
|
|
58
61
|
async finish() {
|
|
59
62
|
return this._schemaContext;
|
|
60
63
|
}
|
|
@@ -165,10 +168,10 @@ class SchemaContextEditor {
|
|
|
165
168
|
}
|
|
166
169
|
/** @internal */
|
|
167
170
|
async lookupSchemaItem(schemaOrKey, schemaItemKey, schemaItemType) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const schemaItem = await
|
|
171
|
+
if (ecschema_metadata_1.Schema.isSchema(schemaOrKey)) {
|
|
172
|
+
schemaOrKey = schemaOrKey.schemaKey;
|
|
173
|
+
}
|
|
174
|
+
const schemaItem = await this.schemaContext.getSchemaItem(schemaItemKey);
|
|
172
175
|
if (schemaItem === undefined)
|
|
173
176
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SchemaItemNotFound, new Exception_1.SchemaItemId(schemaItemType, schemaItemKey));
|
|
174
177
|
if (schemaItemType !== schemaItem.schemaItemType)
|
|
@@ -176,12 +179,17 @@ class SchemaContextEditor {
|
|
|
176
179
|
return schemaItem;
|
|
177
180
|
}
|
|
178
181
|
/** @internal */
|
|
179
|
-
async getSchemaItem(schemaItemKey,
|
|
182
|
+
async getSchemaItem(schemaItemKey, itemConstructor) {
|
|
180
183
|
const schemaItem = await this.schemaContext.getSchemaItem(schemaItemKey);
|
|
184
|
+
const schemaItemType = itemConstructor.schemaItemType;
|
|
185
|
+
if (!isSchemaItemType(schemaItemType)) {
|
|
186
|
+
// This block should never be hit, as the editor components always pass in the itemConstructor with a valid schemaItemType.
|
|
187
|
+
throw new Error(`Invalid schema item lookup for: ${schemaItemType}`);
|
|
188
|
+
}
|
|
181
189
|
if (!schemaItem) {
|
|
182
190
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SchemaItemNotFoundInContext, new Exception_1.SchemaItemId(schemaItemType, schemaItemKey));
|
|
183
191
|
}
|
|
184
|
-
if (
|
|
192
|
+
if (!(0, ecschema_metadata_1.isSupportedSchemaItemType)(schemaItem.schemaItemType, itemConstructor.schemaItemType))
|
|
185
193
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.InvalidSchemaItemType, new Exception_1.SchemaItemId(schemaItemType, schemaItemKey));
|
|
186
194
|
return schemaItem;
|
|
187
195
|
}
|
|
@@ -254,4 +262,7 @@ class SchemaContextEditor {
|
|
|
254
262
|
}
|
|
255
263
|
}
|
|
256
264
|
exports.SchemaContextEditor = SchemaContextEditor;
|
|
265
|
+
function isSchemaItemType(type) {
|
|
266
|
+
return Object.values(ecschema_metadata_1.SchemaItemType).includes(type);
|
|
267
|
+
}
|
|
257
268
|
//# sourceMappingURL=Editor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mapp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f,IAAI,CAAC,YAAY,kCAAc,IAAI,CAAC,CAAC,WAAW,KAAK,mCAAe,CAAC,aAAa,EAAE,CAAC;gBACnF,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,cAAc,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC,EAClF,IAAI,8BAAkB,CAAC,2BAAe,CAAC,kBAAkB,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;YAED,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,cAAc,EAAG,IAAI,oBAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;CACF;AA7PD,kDA6PC","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 * as Rules from \"../Validation/ECRules\";\r\nimport { CustomAttribute, ECObjectsError, ECObjectsStatus, Schema, SchemaContext, SchemaItem, SchemaItemKey, SchemaItemType, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Constants } from \"./Constants\";\r\nimport { CustomAttributes } from \"./CustomAttributes\";\r\nimport { Entities } from \"./Entities\";\r\nimport { Enumerations } from \"./Enumerations\";\r\nimport { Formats } from \"./Formats\";\r\nimport { InvertedUnits } from \"./InvertedUnits\";\r\nimport { KindOfQuantities } from \"./KindOfQuantities\";\r\nimport { Mixins } from \"./Mixins\";\r\nimport { Phenomena } from \"./Phenomena\";\r\nimport { PropertyCategories } from \"./PropertyCategories\";\r\nimport { RelationshipClasses } from \"./RelationshipClasses\";\r\nimport { Structs } from \"./Structs\";\r\nimport { Units } from \"./Units\";\r\nimport { UnitSystems } from \"./UnitSystems\";\r\nimport { CustomAttributeId, ECEditingStatus, SchemaEditingError, SchemaId, SchemaItemId } from \"./Exception\";\r\nimport { AnyDiagnostic } from \"../Validation/Diagnostic\";\r\n\r\n/**\r\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\r\n * @alpha\r\n */\r\nexport class SchemaContextEditor {\r\n private _schemaContext: SchemaContext;\r\n public readonly entities = new Entities(this);\r\n public readonly mixins = new Mixins(this);\r\n public readonly structs = new Structs(this);\r\n public readonly customAttributes = new CustomAttributes(this);\r\n public readonly relationships = new RelationshipClasses(this);\r\n public readonly constants = new Constants(this);\r\n public readonly enumerations = new Enumerations(this);\r\n public readonly formats = new Formats(this);\r\n public readonly kindOfQuantities = new KindOfQuantities(this);\r\n public readonly units = new Units(this);\r\n public readonly phenomenons = new Phenomena(this);\r\n public readonly unitSystems = new UnitSystems(this);\r\n public readonly propertyCategories = new PropertyCategories(this);\r\n public readonly invertedUnits = new InvertedUnits(this);\r\n\r\n /**\r\n * Creates a new SchemaContextEditor instance.\r\n * @param schemaContext The SchemaContext the Editor will use to edit in.\r\n */\r\n constructor(schemaContext: SchemaContext) {\r\n // TODO: Make copy\r\n this._schemaContext = schemaContext;\r\n }\r\n\r\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\r\n public get schemaContext(): SchemaContext { return this._schemaContext; }\r\n\r\n public async finish(): Promise<SchemaContext> {\r\n return this._schemaContext;\r\n }\r\n\r\n /**\r\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @internal\r\n */\r\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema> {\r\n const schema = await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest);\r\n if (schema === undefined)\r\n throw new SchemaEditingError(ECEditingStatus.SchemaNotFound, new SchemaId(schemaKey));\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Creates a Schema with the given properties and adds it to the current schema context.\r\n * @param name The name given to the new schema.\r\n * @param alias The alias of the new schema.\r\n * @param readVersion The read version number of the schema.\r\n * @param writeVersion The write version number of the schema.\r\n * @param minorVersion The minor version number of the schema.\r\n * @returns Resolves to the SchemaKey of created schema.\r\n */\r\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaKey> {\r\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\r\n await this._schemaContext.addSchema(newSchema);\r\n return newSchema.schemaKey;\r\n }\r\n\r\n /**\r\n * Adds a referenced schema to the schema identified by the given SchemaKey.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param refSchema The referenced schema to add.\r\n */\r\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<void> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey, SchemaMatchType.Exact);\r\n await schema.addReference(refSchema);\r\n\r\n const diagnostics: AnyDiagnostic[] = [];\r\n for await (const diagnostic of Rules.validateSchemaReferences(schema)) {\r\n diagnostics.push(diagnostic);\r\n }\r\n\r\n if (diagnostics.length > 0) {\r\n this.removeReference(schema, refSchema);\r\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new SchemaId(schemaKey), undefined, diagnostics);\r\n }\r\n\r\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\r\n await this.schemaContext.addSchema(refSchema);\r\n }\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.AddSchemaReference, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<void> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey);\r\n schema.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics: AnyDiagnostic[] = [];\r\n for await (const diagnostic of Rules.validateCustomAttributeInstance(schema, customAttribute)) {\r\n diagnostics.push(diagnostic);\r\n }\r\n\r\n if (diagnostics.length > 0) {\r\n this.removeCustomAttribute(schema, customAttribute);\r\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new CustomAttributeId(customAttribute.className, schema), undefined, diagnostics);\r\n }\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.AddCustomAttributeToClass, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the schema version.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\r\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\r\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\r\n * @returns Resolves to the new SchemaKey containing version updates.\r\n */\r\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaKey> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey);\r\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\r\n\r\n return schema.schemaKey;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.SetSchemaVersion, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Increments the minor version of a schema.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @returns Resolves to the new SchemaKey containing version updates.\r\n */\r\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaKey> {\r\n try {\r\n const schema = await this.lookupSchema(schemaKey);\r\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\r\n\r\n return schema.schemaKey;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.IncrementSchemaMinorVersion, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n\r\n /** @internal */\r\n public async lookupSchemaItem<T extends SchemaItem>(schemaOrKey: Schema | SchemaKey, schemaItemKey: SchemaItemKey, schemaItemType: SchemaItemType): Promise<T> {\r\n const schema = Schema.isSchema(schemaOrKey)\r\n ? schemaOrKey\r\n : await this.getSchema(schemaOrKey);\r\n\r\n const schemaItem = await schema.lookupItem<T>(schemaItemKey);\r\n if (schemaItem === undefined)\r\n throw new SchemaEditingError(ECEditingStatus.SchemaItemNotFound, new SchemaItemId(schemaItemType, schemaItemKey));\r\n\r\n if (schemaItemType !== schemaItem.schemaItemType)\r\n throw new SchemaEditingError(ECEditingStatus.InvalidSchemaItemType, new SchemaItemId(schemaItemType, schemaItemKey));\r\n\r\n return schemaItem;\r\n }\r\n\r\n /** @internal */\r\n public async getSchemaItem<T extends SchemaItem>(schemaItemKey: SchemaItemKey, schemaItemType: SchemaItemType): Promise<T> {\r\n const schemaItem = await this.schemaContext.getSchemaItem<T>(schemaItemKey);\r\n if (!schemaItem) {\r\n throw new SchemaEditingError(ECEditingStatus.SchemaItemNotFoundInContext, new SchemaItemId(schemaItemType, schemaItemKey));\r\n }\r\n\r\n if (schemaItemType !== schemaItem.schemaItemType)\r\n throw new SchemaEditingError(ECEditingStatus.InvalidSchemaItemType, new SchemaItemId(schemaItemType, schemaItemKey));\r\n\r\n return schemaItem;\r\n }\r\n\r\n private removeReference(schema: Schema, refSchema: Schema) {\r\n const index: number = schema.references.indexOf(refSchema);\r\n if (index !== -1) {\r\n schema.references.splice(index, 1);\r\n }\r\n }\r\n\r\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\r\n assert(schema.customAttributes !== undefined);\r\n const map = schema.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n\r\n private async lookupSchema(schemaKey: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<MutableSchema> {\r\n const schema = await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, matchType);\r\n if (schema === undefined)\r\n throw new SchemaEditingError(ECEditingStatus.SchemaNotFound, new SchemaId(schemaKey));\r\n\r\n return schema;\r\n }\r\n\r\n /**\r\n * Sets the Schemas description.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param description The new description to set.\r\n */\r\n public async setDescription(schemaKey: SchemaKey, description: string) {\r\n const schema = await this.lookupSchema(schemaKey)\r\n .catch((e: any) => {\r\n throw new SchemaEditingError(ECEditingStatus.SetDescription, new SchemaId(schemaKey), e);\r\n });\r\n schema.setDescription(description);\r\n }\r\n\r\n /**\r\n * Sets the Schemas display label.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param label The new label to set.\r\n */\r\n public async setDisplayLabel(schemaKey: SchemaKey, label: string) {\r\n const schema = await this.lookupSchema(schemaKey)\r\n .catch((e: any) => {\r\n throw new SchemaEditingError(ECEditingStatus.SetLabel, new SchemaId(schemaKey), e);\r\n });\r\n schema.setDisplayLabel(label);\r\n }\r\n\r\n /**\r\n * Sets the Schemas alias.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param alias The new alias to set.\r\n */\r\n public async setAlias(schemaKey: SchemaKey, alias: string) {\r\n const schema = await this.lookupSchema(schemaKey)\r\n .catch((e: any) => {\r\n throw new SchemaEditingError(ECEditingStatus.SetSchemaAlias, new SchemaId(schemaKey), e);\r\n });\r\n\r\n try {\r\n for (const currentSchema of this.schemaContext.getKnownSchemas()) {\r\n if (currentSchema.schemaKey.matches(schemaKey))\r\n continue;\r\n\r\n if (currentSchema.alias.toLowerCase() === alias.toLowerCase())\r\n throw new SchemaEditingError(ECEditingStatus.SchemaAliasAlreadyExists, new SchemaId(schemaKey), undefined, undefined, `Schema ${currentSchema.name} already uses the alias '${alias}'.`);\r\n }\r\n schema.setAlias(alias);\r\n } catch(e: any) {\r\n if (e instanceof ECObjectsError && e.errorNumber === ECObjectsStatus.InvalidECName) {\r\n throw new SchemaEditingError(ECEditingStatus.SetSchemaAlias, new SchemaId(schemaKey),\r\n new SchemaEditingError(ECEditingStatus.InvalidSchemaAlias, new SchemaId(schemaKey)));\r\n }\r\n\r\n throw new SchemaEditingError(ECEditingStatus.SetSchemaAlias, new SchemaId(schemaKey), e);\r\n }\r\n }\r\n}\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA8O;AAE9O,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,2CAA6G;AAG7G;;;GAGG;AACH,MAAa,mBAAmB;IACtB,cAAc,CAAgB;IACtB,QAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,gBAAgB,GAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,CAAC;IAC9C,aAAa,GAAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,CAAC;IAC9C,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;IAChC,YAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,CAAC;IACtC,OAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,gBAAgB,GAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,CAAC;IAC9C,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,CAAC;IACxB,WAAW,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;IAClC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAC;IACpC,kBAAkB,GA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,CAAC;oBAC5C,SAAS;gBAEX,IAAI,aAAa,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE;oBAC3D,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,wBAAwB,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,aAAa,CAAC,IAAI,4BAA4B,KAAK,IAAI,CAAC,CAAC;YAC7L,CAAC;YACD,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,IAAI,CAAC,YAAY,kCAAc,IAAI,CAAC,CAAC,WAAW,KAAK,mCAAe,CAAC,aAAa,EAAE,CAAC;gBACnF,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,cAAc,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC,EAClF,IAAI,8BAAkB,CAAC,2BAAe,CAAC,kBAAkB,EAAE,IAAI,oBAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;YAED,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,cAAc,EAAG,IAAI,oBAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;CACF;AArQD,kDAqQC;AAED,SAAS,gBAAgB,CAAC,IAA6B;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,kCAAc,CAAC,CAAC,QAAQ,CAAC,IAAsB,CAAC,CAAC;AACxE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Editing\n */\n\nimport * as Rules from \"../Validation/ECRules\";\nimport { CustomAttribute, ECObjectsError, ECObjectsStatus, isSupportedSchemaItemType, Schema, SchemaContext, SchemaItem, SchemaItemKey, SchemaItemType, SchemaKey, SchemaMatchType, SupportedSchemaItemType } from \"@itwin/ecschema-metadata\";\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { Constants } from \"./Constants\";\nimport { CustomAttributes } from \"./CustomAttributes\";\nimport { Entities } from \"./Entities\";\nimport { Enumerations } from \"./Enumerations\";\nimport { Formats } from \"./Formats\";\nimport { InvertedUnits } from \"./InvertedUnits\";\nimport { KindOfQuantities } from \"./KindOfQuantities\";\nimport { Mixins } from \"./Mixins\";\nimport { Phenomena } from \"./Phenomena\";\nimport { PropertyCategories } from \"./PropertyCategories\";\nimport { RelationshipClasses } from \"./RelationshipClasses\";\nimport { Structs } from \"./Structs\";\nimport { Units } from \"./Units\";\nimport { UnitSystems } from \"./UnitSystems\";\nimport { CustomAttributeId, ECEditingStatus, SchemaEditingError, SchemaId, SchemaItemId } from \"./Exception\";\nimport { AnyDiagnostic } from \"../Validation/Diagnostic\";\n\n/**\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\n * @alpha\n */\nexport class SchemaContextEditor {\n private _schemaContext: SchemaContext;\n public readonly entities = new Entities(this);\n public readonly mixins = new Mixins(this);\n public readonly structs = new Structs(this);\n public readonly customAttributes = new CustomAttributes(this);\n public readonly relationships = new RelationshipClasses(this);\n public readonly constants = new Constants(this);\n public readonly enumerations = new Enumerations(this);\n public readonly formats = new Formats(this);\n public readonly kindOfQuantities = new KindOfQuantities(this);\n public readonly units = new Units(this);\n public readonly phenomenons = new Phenomena(this);\n public readonly unitSystems = new UnitSystems(this);\n public readonly propertyCategories = new PropertyCategories(this);\n public readonly invertedUnits = new InvertedUnits(this);\n\n /**\n * Creates a new SchemaContextEditor instance.\n * @param schemaContext The SchemaContext the Editor will use to edit in.\n */\n constructor(schemaContext: SchemaContext) {\n // TODO: Make copy\n this._schemaContext = schemaContext;\n }\n\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\n public get schemaContext(): SchemaContext {\n return this._schemaContext;\n }\n\n public async finish(): Promise<SchemaContext> {\n return this._schemaContext;\n }\n\n /**\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\n * @param schemaKey The SchemaKey identifying the schema.\n * @internal\n */\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema> {\n const schema = await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest);\n if (schema === undefined)\n throw new SchemaEditingError(ECEditingStatus.SchemaNotFound, new SchemaId(schemaKey));\n\n return schema as MutableSchema;\n }\n\n /**\n * Creates a Schema with the given properties and adds it to the current schema context.\n * @param name The name given to the new schema.\n * @param alias The alias of the new schema.\n * @param readVersion The read version number of the schema.\n * @param writeVersion The write version number of the schema.\n * @param minorVersion The minor version number of the schema.\n * @returns Resolves to the SchemaKey of created schema.\n */\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaKey> {\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\n await this._schemaContext.addSchema(newSchema);\n return newSchema.schemaKey;\n }\n\n /**\n * Adds a referenced schema to the schema identified by the given SchemaKey.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param refSchema The referenced schema to add.\n */\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<void> {\n try {\n const schema = await this.lookupSchema(schemaKey, SchemaMatchType.Exact);\n await schema.addReference(refSchema);\n\n const diagnostics: AnyDiagnostic[] = [];\n for await (const diagnostic of Rules.validateSchemaReferences(schema)) {\n diagnostics.push(diagnostic);\n }\n\n if (diagnostics.length > 0) {\n this.removeReference(schema, refSchema);\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new SchemaId(schemaKey), undefined, diagnostics);\n }\n\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\n await this.schemaContext.addSchema(refSchema);\n }\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.AddSchemaReference, new SchemaId(schemaKey), e);\n }\n }\n\n /**\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\n * @param schemaKey The SchemaKey identifying the schema.\n * @param customAttribute The CustomAttribute instance to add.\n */\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<void> {\n try {\n const schema = await this.lookupSchema(schemaKey);\n schema.addCustomAttribute(customAttribute);\n\n const diagnostics: AnyDiagnostic[] = [];\n for await (const diagnostic of Rules.validateCustomAttributeInstance(schema, customAttribute)) {\n diagnostics.push(diagnostic);\n }\n\n if (diagnostics.length > 0) {\n this.removeCustomAttribute(schema, customAttribute);\n throw new SchemaEditingError(ECEditingStatus.RuleViolation, new CustomAttributeId(customAttribute.className, schema), undefined, diagnostics);\n }\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.AddCustomAttributeToClass, new SchemaId(schemaKey), e);\n }\n }\n\n /**\n * Sets the schema version.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\n * @returns Resolves to the new SchemaKey containing version updates.\n */\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaKey> {\n try {\n const schema = await this.lookupSchema(schemaKey);\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\n\n return schema.schemaKey;\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.SetSchemaVersion, new SchemaId(schemaKey), e);\n }\n }\n\n /**\n * Increments the minor version of a schema.\n * @param schemaKey The SchemaKey identifying the schema.\n * @returns Resolves to the new SchemaKey containing version updates.\n */\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaKey> {\n try {\n const schema = await this.lookupSchema(schemaKey);\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\n\n return schema.schemaKey;\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.IncrementSchemaMinorVersion, new SchemaId(schemaKey), e);\n }\n }\n\n /** @internal */\n public async lookupSchemaItem(schemaOrKey: Schema | SchemaKey, schemaItemKey: SchemaItemKey, schemaItemType: SchemaItemType): Promise<SchemaItem> {\n if(Schema.isSchema(schemaOrKey)) {\n schemaOrKey = schemaOrKey.schemaKey;\n }\n\n const schemaItem = await this.schemaContext.getSchemaItem(schemaItemKey);\n if (schemaItem === undefined)\n throw new SchemaEditingError(ECEditingStatus.SchemaItemNotFound, new SchemaItemId(schemaItemType, schemaItemKey));\n\n if (schemaItemType !== schemaItem.schemaItemType)\n throw new SchemaEditingError(ECEditingStatus.InvalidSchemaItemType, new SchemaItemId(schemaItemType, schemaItemKey));\n\n return schemaItem;\n }\n\n /** @internal */\n public async getSchemaItem<T extends typeof SchemaItem>(schemaItemKey: SchemaItemKey, itemConstructor: T): Promise<InstanceType<T>> {\n const schemaItem = await this.schemaContext.getSchemaItem(schemaItemKey);\n const schemaItemType = itemConstructor.schemaItemType;\n if(!isSchemaItemType(schemaItemType)) {\n // This block should never be hit, as the editor components always pass in the itemConstructor with a valid schemaItemType.\n throw new Error(`Invalid schema item lookup for: ${schemaItemType}`);\n }\n\n if (!schemaItem) {\n throw new SchemaEditingError(ECEditingStatus.SchemaItemNotFoundInContext, new SchemaItemId(schemaItemType, schemaItemKey));\n }\n\n if (!isSupportedSchemaItemType(schemaItem.schemaItemType, itemConstructor.schemaItemType))\n throw new SchemaEditingError(ECEditingStatus.InvalidSchemaItemType, new SchemaItemId(schemaItemType, schemaItemKey));\n\n return schemaItem as InstanceType<T>;\n }\n\n private removeReference(schema: Schema, refSchema: Schema) {\n const index: number = schema.references.indexOf(refSchema);\n if (index !== -1) {\n schema.references.splice(index, 1);\n }\n }\n\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\n assert(schema.customAttributes !== undefined);\n const map = schema.customAttributes as Map<string, CustomAttribute>;\n map.delete(customAttribute.className);\n }\n\n private async lookupSchema(schemaKey: SchemaKey, matchType: SchemaMatchType = SchemaMatchType.Latest): Promise<MutableSchema> {\n const schema = await this.schemaContext.getCachedSchema(schemaKey, matchType);\n if (schema === undefined)\n throw new SchemaEditingError(ECEditingStatus.SchemaNotFound, new SchemaId(schemaKey));\n\n return schema as MutableSchema;\n }\n\n /**\n * Sets the Schemas description.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param description The new description to set.\n */\n public async setDescription(schemaKey: SchemaKey, description: string) {\n const schema = await this.lookupSchema(schemaKey)\n .catch((e: any) => {\n throw new SchemaEditingError(ECEditingStatus.SetDescription, new SchemaId(schemaKey), e);\n });\n schema.setDescription(description);\n }\n\n /**\n * Sets the Schemas display label.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param label The new label to set.\n */\n public async setDisplayLabel(schemaKey: SchemaKey, label: string) {\n const schema = await this.lookupSchema(schemaKey)\n .catch((e: any) => {\n throw new SchemaEditingError(ECEditingStatus.SetLabel, new SchemaId(schemaKey), e);\n });\n schema.setDisplayLabel(label);\n }\n\n /**\n * Sets the Schemas alias.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param alias The new alias to set.\n */\n public async setAlias(schemaKey: SchemaKey, alias: string) {\n const schema = await this.lookupSchema(schemaKey)\n .catch((e: any) => {\n throw new SchemaEditingError(ECEditingStatus.SetSchemaAlias, new SchemaId(schemaKey), e);\n });\n\n try {\n for (const currentSchema of this.schemaContext.getKnownSchemas()) {\n if (currentSchema.schemaKey.matches(schemaKey))\n continue;\n\n if (currentSchema.alias.toLowerCase() === alias.toLowerCase())\n throw new SchemaEditingError(ECEditingStatus.SchemaAliasAlreadyExists, new SchemaId(schemaKey), undefined, undefined, `Schema ${currentSchema.name} already uses the alias '${alias}'.`);\n }\n schema.setAlias(alias);\n } catch(e: any) {\n if (e instanceof ECObjectsError && e.errorNumber === ECObjectsStatus.InvalidECName) {\n throw new SchemaEditingError(ECEditingStatus.SetSchemaAlias, new SchemaId(schemaKey),\n new SchemaEditingError(ECEditingStatus.InvalidSchemaAlias, new SchemaId(schemaKey)));\n }\n\n throw new SchemaEditingError(ECEditingStatus.SetSchemaAlias, new SchemaId(schemaKey), e);\n }\n }\n}\n\nfunction isSchemaItemType(type: SupportedSchemaItemType): type is SchemaItemType {\n return Object.values(SchemaItemType).includes(type as SchemaItemType);\n}"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
|
-
import { ECClassModifier, EntityClassProps, Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
|
|
4
|
+
import { ECClassModifier, EntityClass, EntityClassProps, Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { SchemaContextEditor } from "./Editor";
|
|
6
6
|
import { ECClasses } from "./ECClasses";
|
|
7
7
|
import { NavigationProperties } from "./Properties";
|
|
@@ -10,6 +10,7 @@ import { NavigationProperties } from "./Properties";
|
|
|
10
10
|
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
11
11
|
*/
|
|
12
12
|
export declare class Entities extends ECClasses {
|
|
13
|
+
protected get itemTypeClass(): typeof EntityClass;
|
|
13
14
|
constructor(schemaEditor: SchemaContextEditor);
|
|
14
15
|
/**
|
|
15
16
|
* Allows access for editing of NavigationProperty attributes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,eAAe,
|
|
1
|
+
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAC9C,KAAK,EAAE,uBAAuB,EAAE,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;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAS5F,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAU1E,wBAAwB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7K;;;;OAIG;IACU,iCAAiC,CAAC,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CASjI"}
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.Entities = void 0;
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
|
+
const MutableEntityClass_1 = require("./Mutable/MutableEntityClass");
|
|
13
14
|
const Properties_1 = require("./Properties");
|
|
14
15
|
const Exception_1 = require("./Exception");
|
|
15
16
|
/**
|
|
@@ -17,17 +18,20 @@ const Exception_1 = require("./Exception");
|
|
|
17
18
|
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
18
19
|
*/
|
|
19
20
|
class Entities extends ECClasses_1.ECClasses {
|
|
21
|
+
get itemTypeClass() {
|
|
22
|
+
return ecschema_metadata_1.EntityClass;
|
|
23
|
+
}
|
|
20
24
|
constructor(schemaEditor) {
|
|
21
25
|
super(ecschema_metadata_1.SchemaItemType.EntityClass, schemaEditor);
|
|
22
|
-
/**
|
|
23
|
-
* Allows access for editing of NavigationProperty attributes.
|
|
24
|
-
*/
|
|
25
|
-
this.navigationProperties = new Properties_1.NavigationProperties(ecschema_metadata_1.SchemaItemType.EntityClass, this.schemaEditor);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Allows access for editing of NavigationProperty attributes.
|
|
29
|
+
*/
|
|
30
|
+
navigationProperties = new Properties_1.NavigationProperties(ecschema_metadata_1.SchemaItemType.EntityClass, this.schemaEditor);
|
|
27
31
|
async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
28
32
|
try {
|
|
29
|
-
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
30
|
-
if (!(await baseClass.is("Element", "BisCore"))) {
|
|
33
|
+
const baseClass = await this.getSchemaItem(baseClassKey, ecschema_metadata_1.EntityClass);
|
|
34
|
+
if (!(await (baseClass).is("Element", "BisCore"))) {
|
|
31
35
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElement, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
32
36
|
}
|
|
33
37
|
}
|
|
@@ -38,8 +42,8 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
38
42
|
}
|
|
39
43
|
async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
40
44
|
try {
|
|
41
|
-
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
42
|
-
if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
|
|
45
|
+
const baseClass = await this.getSchemaItem(baseClassKey, ecschema_metadata_1.EntityClass);
|
|
46
|
+
if (!(await (baseClass).is("ElementUniqueAspect", "BisCore"))) {
|
|
43
47
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElementUniqueAspect, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
44
48
|
}
|
|
45
49
|
}
|
|
@@ -50,8 +54,8 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
50
54
|
}
|
|
51
55
|
async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
52
56
|
try {
|
|
53
|
-
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
54
|
-
if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
|
|
57
|
+
const baseClass = await this.getSchemaItem(baseClassKey, ecschema_metadata_1.EntityClass);
|
|
58
|
+
if (!(await (baseClass).is("ElementMultiAspect", "BisCore"))) {
|
|
55
59
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElementMultiAspect, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
56
60
|
}
|
|
57
61
|
}
|
|
@@ -89,8 +93,8 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
89
93
|
}
|
|
90
94
|
async addMixin(entityKey, mixinKey) {
|
|
91
95
|
try {
|
|
92
|
-
const entity = await this.getSchemaItem(entityKey);
|
|
93
|
-
const mixin = await this.getSchemaItem(mixinKey, ecschema_metadata_1.
|
|
96
|
+
const entity = await this.getSchemaItem(entityKey, MutableEntityClass_1.MutableEntityClass);
|
|
97
|
+
const mixin = await this.getSchemaItem(mixinKey, ecschema_metadata_1.Mixin);
|
|
94
98
|
entity.addMixin(mixin);
|
|
95
99
|
}
|
|
96
100
|
catch (e) {
|
|
@@ -99,7 +103,7 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
99
103
|
}
|
|
100
104
|
async createNavigationProperty(entityKey, name, relationship, direction) {
|
|
101
105
|
try {
|
|
102
|
-
const entity = await this.getSchemaItem(entityKey);
|
|
106
|
+
const entity = await this.getSchemaItem(entityKey, MutableEntityClass_1.MutableEntityClass);
|
|
103
107
|
await entity.createNavigationProperty(name, relationship, direction);
|
|
104
108
|
}
|
|
105
109
|
catch (e) {
|
|
@@ -113,7 +117,7 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
113
117
|
*/
|
|
114
118
|
async createNavigationPropertyFromProps(classKey, navigationProps) {
|
|
115
119
|
try {
|
|
116
|
-
const entity = await this.getSchemaItem(classKey);
|
|
120
|
+
const entity = await this.getSchemaItem(classKey, MutableEntityClass_1.MutableEntityClass);
|
|
117
121
|
const property = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
|
|
118
122
|
await property.fromJSON(navigationProps);
|
|
119
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entities.js","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAGkC;AAElC,2CAAwC;AAExC,6CAAoD;AACpD,2CAA2E;AAE3E;;;GAGG;AACH,MAAa,QAAS,SAAQ,qBAAS;IACrC,YAAmB,YAAiC;QAClD,KAAK,CAAC,kCAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAGlD;;WAEG;QACa,yBAAoB,GAAG,IAAI,iCAAoB,CAAC,kCAAc,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAL/G,CAAC;IAOM,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,IAAY,EAAE,QAAyB,EAAE,YAA2B,EAAE,YAAqB,EAAE,MAAgB;QAC5J,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;YACzD,IAAI,CAAC,CAAC,MAAO,SAAyB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;gBACjE,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,qBAAqB,EAAE,IAAI,mBAAO,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;YACtH,CAAC;QACH,CAAC;QAAC,OAAM,CAAM,EAAC,CAAC;YACd,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,aAAa,EAAE,IAAI,mBAAO,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QACpH,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,EAA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AAC;QACvE,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,wBAAwB,EAAE,IAAI,mBAAO,CAAC,kCAAc,CAAC,iBAAiB,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QACtI,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,iCAAiC,CAAC,QAAuB,EAAE,eAAwC;QAC9G,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAqB,QAAQ,CAAC,CAAC;YACtE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,gBAAgB,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;YAC1I,MAAM,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,iCAAiC,EAAE,IAAI,mBAAO,CAAC,kCAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QACxI,CAAC;IACH,CAAC;CACF;AAhHD,4BAgHC","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 ECClassModifier, EntityClass, EntityClassProps,\r\n Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableEntityClass } from \"./Mutable/MutableEntityClass\";\r\nimport { NavigationProperties } from \"./Properties\";\r\nimport { ClassId, ECEditingStatus, SchemaEditingError } from \"./Exception\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type EntityClass.\r\n */\r\nexport class Entities extends ECClasses {\r\n public constructor(schemaEditor: SchemaContextEditor) {\r\n super(SchemaItemType.EntityClass, 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(SchemaItemType.EntityClass, this.schemaEditor);\r\n\r\n public async createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey> {\r\n try {\r\n const baseClass = await this.getSchemaItem(baseClassKey);\r\n if (!(await (baseClass as EntityClass).is(\"Element\", \"BisCore\"))) {\r\n throw new SchemaEditingError(ECEditingStatus.BaseClassIsNotElement, new ClassId(this.schemaItemType, baseClassKey));\r\n }\r\n } catch(e: any){\r\n throw new SchemaEditingError(ECEditingStatus.CreateElement, new ClassId(this.schemaItemType, name, schemaKey), e);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey> {\r\n try {\r\n const baseClass = await this.getSchemaItem(baseClassKey);\r\n if (!(await (baseClass as EntityClass).is(\"ElementUniqueAspect\", \"BisCore\"))) {\r\n throw new SchemaEditingError(ECEditingStatus.BaseClassIsNotElementUniqueAspect, new ClassId(this.schemaItemType, baseClassKey));\r\n }\r\n } catch(e: any){\r\n throw new SchemaEditingError(ECEditingStatus.CreateElement, new ClassId(this.schemaItemType, name, schemaKey), e);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey> {\r\n try {\r\n const baseClass = await this.getSchemaItem(baseClassKey);\r\n if (!(await (baseClass as EntityClass).is(\"ElementMultiAspect\", \"BisCore\"))) {\r\n throw new SchemaEditingError(ECEditingStatus.BaseClassIsNotElementMultiAspect, new ClassId(this.schemaItemType, baseClassKey));\r\n }\r\n } catch(e: any){\r\n throw new SchemaEditingError(ECEditingStatus.CreateElement, new ClassId(this.schemaItemType, name, schemaKey), e);\r\n }\r\n\r\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\r\n }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemKey> {\r\n try {\r\n const newClass = await this.createClass<EntityClass>(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), name, baseClassKey, modifier) as MutableEntityClass;\r\n\r\n if (mixins !== undefined)\r\n mixins.forEach((m) => newClass.addMixin(m));\r\n\r\n if (displayLabel)\r\n newClass.setDisplayLabel(displayLabel);\r\n\r\n return newClass.key;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFailed, new ClassId(this.schemaItemType, name, schemaKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Creates an EntityClass through an EntityClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemKey> {\r\n try {\r\n const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), entityProps);\r\n return newClass.key;\r\n } catch (e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, entityProps.name!, schemaKey), e);\r\n }\r\n }\r\n\r\n public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void> {\r\n try {\r\n const entity = await this.getSchemaItem<MutableEntityClass>(entityKey);\r\n const mixin = await this.getSchemaItem<Mixin>(mixinKey, SchemaItemType.Mixin);\r\n entity.addMixin(mixin);\r\n } catch(e: any){\r\n throw new SchemaEditingError(ECEditingStatus.AddMixin, new ClassId(SchemaItemType.EntityClass, entityKey), e);\r\n }\r\n }\r\n\r\n public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<void> {\r\n try {\r\n const entity = await this.getSchemaItem<MutableEntityClass>(entityKey);\r\n await entity.createNavigationProperty(name, relationship, direction);\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateNavigationProperty, new ClassId(SchemaItemType.RelationshipClass, entityKey), e);\r\n }\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the Entity 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(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<void> {\r\n try {\r\n const entity = await this.getSchemaItem<MutableEntityClass>(classKey);\r\n const property = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await property.fromJSON(navigationProps);\r\n } catch(e: any) {\r\n throw new SchemaEditingError(ECEditingStatus.CreateNavigationPropertyFromProps, new ClassId(SchemaItemType.EntityClass, classKey), e);\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Entities.js","sourceRoot":"","sources":["../../../src/Editing/Entities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAGkC;AAElC,2CAAwC;AACxC,qEAAkE;AAClE,6CAAoD;AACpD,2CAA2E;AAE3E;;;GAGG;AACH,MAAa,QAA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C;QACtI,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,iCAAiC,CAAC,QAAuB,EAAE,eAAwC;QAC9G,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,uCAAkB,CAAC,CAAC;YACtE,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,gBAAgB,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;YAC1I,MAAM,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,iCAAiC,EAAE,IAAI,mBAAO,CAAC,kCAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;QACxI,CAAC;IACH,CAAC;CACF;AApHD,4BAoHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Editing\n */\n\nimport {\n ECClassModifier, EntityClass, EntityClassProps,\n Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,\n} from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor } from \"./Editor\";\nimport { ECClasses } from \"./ECClasses\";\nimport { MutableEntityClass } from \"./Mutable/MutableEntityClass\";\nimport { NavigationProperties } from \"./Properties\";\nimport { ClassId, ECEditingStatus, SchemaEditingError } from \"./Exception\";\n\n/**\n * @alpha\n * A class extending ECClasses allowing you to create schema items of type EntityClass.\n */\nexport class Entities extends ECClasses {\n protected override get itemTypeClass(): typeof EntityClass {\n return EntityClass;\n }\n\n public constructor(schemaEditor: SchemaContextEditor) {\n super(SchemaItemType.EntityClass, schemaEditor);\n }\n\n /**\n * Allows access for editing of NavigationProperty attributes.\n */\n public readonly navigationProperties = new NavigationProperties(SchemaItemType.EntityClass, this.schemaEditor);\n\n public async createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey> {\n try {\n const baseClass = await this.getSchemaItem(baseClassKey, EntityClass);\n if (!(await (baseClass).is(\"Element\", \"BisCore\"))) {\n throw new SchemaEditingError(ECEditingStatus.BaseClassIsNotElement, new ClassId(this.schemaItemType, baseClassKey));\n }\n } catch(e: any){\n throw new SchemaEditingError(ECEditingStatus.CreateElement, new ClassId(this.schemaItemType, name, schemaKey), e);\n }\n\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\n }\n\n public async createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey> {\n try {\n const baseClass = await this.getSchemaItem(baseClassKey, EntityClass);\n if (!(await (baseClass).is(\"ElementUniqueAspect\", \"BisCore\"))) {\n throw new SchemaEditingError(ECEditingStatus.BaseClassIsNotElementUniqueAspect, new ClassId(this.schemaItemType, baseClassKey));\n }\n } catch(e: any){\n throw new SchemaEditingError(ECEditingStatus.CreateElement, new ClassId(this.schemaItemType, name, schemaKey), e);\n }\n\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\n }\n\n public async createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemKey> {\n try {\n const baseClass = await this.getSchemaItem(baseClassKey, EntityClass);\n if (!(await (baseClass).is(\"ElementMultiAspect\", \"BisCore\"))) {\n throw new SchemaEditingError(ECEditingStatus.BaseClassIsNotElementMultiAspect, new ClassId(this.schemaItemType, baseClassKey));\n }\n } catch(e: any){\n throw new SchemaEditingError(ECEditingStatus.CreateElement, new ClassId(this.schemaItemType, name, schemaKey), e);\n }\n\n return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);\n }\n\n public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemKey> {\n try {\n const newClass = await this.createClass<EntityClass>(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), name, baseClassKey, modifier) as MutableEntityClass;\n\n if (mixins !== undefined)\n mixins.forEach((m) => newClass.addMixin(m));\n\n if (displayLabel)\n newClass.setDisplayLabel(displayLabel);\n\n return newClass.key;\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFailed, new ClassId(this.schemaItemType, name, schemaKey), e);\n }\n }\n\n /**\n * Creates an EntityClass through an EntityClassProps.\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\n * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.\n */\n public async createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemKey> {\n try {\n const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), entityProps);\n return newClass.key;\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new ClassId(this.schemaItemType, entityProps.name!, schemaKey), e);\n }\n }\n\n public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void> {\n try {\n const entity = await this.getSchemaItem(entityKey, MutableEntityClass);\n const mixin = await this.getSchemaItem(mixinKey, Mixin);\n entity.addMixin(mixin);\n } catch(e: any){\n throw new SchemaEditingError(ECEditingStatus.AddMixin, new ClassId(SchemaItemType.EntityClass, entityKey), e);\n }\n }\n\n public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<void> {\n try {\n const entity = await this.getSchemaItem(entityKey, MutableEntityClass);\n await entity.createNavigationProperty(name, relationship, direction);\n } catch(e: any) {\n throw new SchemaEditingError(ECEditingStatus.CreateNavigationProperty, new ClassId(SchemaItemType.RelationshipClass, entityKey), e);\n }\n }\n\n /**\n * Creates a Navigation Property through a NavigationPropertyProps.\n * @param classKey a SchemaItemKey of the Entity Class that will house the new property.\n * @param navigationProps a json object that will be used to populate the new Navigation Property.\n */\n public async createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<void> {\n try {\n const entity = await this.getSchemaItem(classKey, MutableEntityClass);\n const property = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\n await property.fromJSON(navigationProps);\n } catch(e: any) {\n throw new SchemaEditingError(ECEditingStatus.CreateNavigationPropertyFromProps, new ClassId(SchemaItemType.EntityClass, classKey), e);\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
|
-
import { AnyEnumerator, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
4
|
+
import { AnyEnumerator, Enumeration, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
5
|
import { SchemaContextEditor } from "./Editor";
|
|
6
6
|
import { SchemaItems } from "./SchemaItems";
|
|
7
7
|
/**
|
|
@@ -9,6 +9,7 @@ import { SchemaItems } from "./SchemaItems";
|
|
|
9
9
|
* A class allowing you to create schema items of type Enumeration.
|
|
10
10
|
*/
|
|
11
11
|
export declare class Enumerations extends SchemaItems {
|
|
12
|
+
protected get itemTypeClass(): typeof Enumeration;
|
|
12
13
|
constructor(schemaEditor: SchemaContextEditor);
|
|
13
14
|
create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemKey>;
|
|
14
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Enumerations.d.ts","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"Enumerations.d.ts","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAkB,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACjJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM5C;;;GAGG;AACH,qBAAa,YAAa,SAAQ,WAAW;IAC3C,cAAuB,aAAa,IAAI,OAAO,WAAW,CAEzD;gBAEkB,YAAY,EAAE,mBAAmB;IAIvC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC,OAAO,GAAG,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAoB7M;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC;IAS1F,aAAa,CAAC,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBtF,kBAAkB,CAAC,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnH,wBAAwB,CAAC,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAa7I"}
|
|
@@ -16,6 +16,9 @@ const SchemaItems_1 = require("./SchemaItems");
|
|
|
16
16
|
* A class allowing you to create schema items of type Enumeration.
|
|
17
17
|
*/
|
|
18
18
|
class Enumerations extends SchemaItems_1.SchemaItems {
|
|
19
|
+
get itemTypeClass() {
|
|
20
|
+
return ecschema_metadata_1.Enumeration;
|
|
21
|
+
}
|
|
19
22
|
constructor(schemaEditor) {
|
|
20
23
|
super(ecschema_metadata_1.SchemaItemType.Enumeration, schemaEditor);
|
|
21
24
|
}
|
|
@@ -51,7 +54,7 @@ class Enumerations extends SchemaItems_1.SchemaItems {
|
|
|
51
54
|
}
|
|
52
55
|
async addEnumerator(enumerationKey, enumerator) {
|
|
53
56
|
try {
|
|
54
|
-
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.
|
|
57
|
+
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.Enumeration);
|
|
55
58
|
if (enumeration.isInt && typeof (enumerator.value) !== "number")
|
|
56
59
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.InvalidEnumeratorType, new Exception_1.EnumeratorId(enumerator, enumeration));
|
|
57
60
|
if (enumeration.isString && typeof (enumerator.value) !== "string")
|
|
@@ -64,7 +67,7 @@ class Enumerations extends SchemaItems_1.SchemaItems {
|
|
|
64
67
|
}
|
|
65
68
|
async setEnumeratorLabel(enumerationKey, enumeratorName, label) {
|
|
66
69
|
try {
|
|
67
|
-
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.
|
|
70
|
+
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.Enumeration);
|
|
68
71
|
const enumerator = enumeration.getEnumeratorByName(enumeratorName);
|
|
69
72
|
if (enumerator === undefined)
|
|
70
73
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.EnumeratorDoesNotExist, new Exception_1.EnumeratorId(enumeratorName, enumeration));
|
|
@@ -76,7 +79,7 @@ class Enumerations extends SchemaItems_1.SchemaItems {
|
|
|
76
79
|
}
|
|
77
80
|
async setEnumeratorDescription(enumerationKey, enumeratorName, description) {
|
|
78
81
|
try {
|
|
79
|
-
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.
|
|
82
|
+
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.Enumeration);
|
|
80
83
|
const enumerator = enumeration.getEnumeratorByName(enumeratorName);
|
|
81
84
|
if (enumerator === undefined)
|
|
82
85
|
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.EnumeratorDoesNotExist, new Exception_1.EnumeratorId(enumeratorName, enumeration));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Enumerations.js","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAiJ;AAGjJ,2CAA8F;AAC9F,+CAA4C;AAM5C;;;GAGG;AACH,MAAa,YAAa,SAAQ,yBAAW;IAC3C,YAAmB,YAAiC;QAClD,KAAK,CAAC,kCAAc,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,IAAkD,EAAE,YAAqB,EAAE,QAAkB,EAAE,WAA6B;QAClL,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAc,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAuB,CAAC;YAE9K,IAAI,SAAS,KAAK,QAAQ;gBACxB,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;YAEhC,IAAI,SAAS,K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,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7H,CAAC;IACH,CAAC;CACF;AAtFD,oCAsFC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Editing\n */\n\nimport { AnyEnumerator, Enumeration, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaItemType, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor } from \"./Editor\";\nimport { MutableEnumeration } from \"./Mutable/MutableEnumeration\";\nimport { ECEditingStatus, EnumeratorId, SchemaEditingError, SchemaItemId } from \"./Exception\";\nimport { SchemaItems } from \"./SchemaItems\";\n\ntype MutableEnumerator = {\n -readonly [P in keyof AnyEnumerator]: AnyEnumerator[P]\n};\n\n/**\n * @alpha\n * A class allowing you to create schema items of type Enumeration.\n */\nexport class Enumerations extends SchemaItems {\n protected override get itemTypeClass(): typeof Enumeration {\n return Enumeration;\n }\n\n public constructor(schemaEditor: SchemaContextEditor) {\n super(SchemaItemType.Enumeration, schemaEditor);\n }\n\n public async create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemKey> {\n try {\n const newEnum = await this.createSchemaItem<Enumeration>(schemaKey, this.schemaItemType, (schema) => schema.createEnumeration.bind(schema), name, type) as MutableEnumeration;\n\n if (undefined !== isStrict)\n newEnum.setIsStrict(isStrict);\n\n if (undefined !== enumerators)\n for (const enumerator of enumerators)\n await this.addEnumerator(newEnum.key, enumerator);\n\n if (displayLabel)\n newEnum.setDisplayLabel(displayLabel);\n\n return newEnum.key;\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFailed, new SchemaItemId(this.schemaItemType, name, schemaKey), e);\n }\n }\n\n /**\n * Creates an Enumeration through an EnumeratorProps.\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\n */\n public async createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemKey> {\n try {\n const newEnum = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEnumeration.bind(schema), enumProps);\n return newEnum.key;\n } catch (e: any) {\n throw new SchemaEditingError(ECEditingStatus.CreateSchemaItemFromProps, new SchemaItemId(this.schemaItemType, enumProps.name!, schemaKey), e);\n }\n }\n\n public async addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void> {\n try {\n const enumeration = await this.getSchemaItem(enumerationKey, Enumeration);\n\n if (enumeration.isInt && typeof (enumerator.value) !== \"number\")\n throw new SchemaEditingError(ECEditingStatus.InvalidEnumeratorType, new EnumeratorId(enumerator, enumeration));\n\n if (enumeration.isString && typeof (enumerator.value) !== \"string\")\n throw new SchemaEditingError(ECEditingStatus.InvalidEnumeratorType, new EnumeratorId(enumerator, enumeration));\n\n (enumeration as MutableEnumeration).addEnumerator(enumerator);\n } catch(e: any) {\n throw new SchemaEditingError(ECEditingStatus.AddEnumerator, new SchemaItemId(this.schemaItemType, enumerationKey), e);\n }\n }\n\n public async setEnumeratorLabel(enumerationKey: SchemaItemKey, enumeratorName: string, label: string | undefined): Promise<void> {\n try {\n const enumeration = await this.getSchemaItem(enumerationKey, Enumeration);\n\n const enumerator = enumeration.getEnumeratorByName(enumeratorName);\n if (enumerator === undefined)\n throw new SchemaEditingError(ECEditingStatus.EnumeratorDoesNotExist, new EnumeratorId(enumeratorName, enumeration));\n\n (enumerator as MutableEnumerator).label = label;\n } catch(e: any) {\n throw new SchemaEditingError(ECEditingStatus.SetEnumeratorLabel, new SchemaItemId(this.schemaItemType, enumerationKey), e);\n }\n }\n\n public async setEnumeratorDescription(enumerationKey: SchemaItemKey, enumeratorName: string, description: string | undefined): Promise<void> {\n try {\n const enumeration = await this.getSchemaItem(enumerationKey, Enumeration);\n\n const enumerator = enumeration.getEnumeratorByName(enumeratorName);\n if (enumerator === undefined)\n throw new SchemaEditingError(ECEditingStatus.EnumeratorDoesNotExist, new EnumeratorId(enumeratorName, enumeration));\n\n (enumerator as MutableEnumerator).description = description;\n } catch(e: any) {\n throw new SchemaEditingError(ECEditingStatus.SetEnumeratorLabel, new SchemaItemId(this.schemaItemType, enumerationKey), e);\n }\n }\n}\n"]}
|
|
@@ -126,8 +126,10 @@ var SchemaTypeIdentifiers;
|
|
|
126
126
|
* @alpha
|
|
127
127
|
*/
|
|
128
128
|
class SchemaId {
|
|
129
|
+
typeIdentifier = SchemaTypeIdentifiers.SchemaIdentifier;
|
|
130
|
+
name;
|
|
131
|
+
schemaKey;
|
|
129
132
|
constructor(schemaKey) {
|
|
130
|
-
this.typeIdentifier = SchemaTypeIdentifiers.SchemaIdentifier;
|
|
131
133
|
this.name = schemaKey.name;
|
|
132
134
|
this.schemaKey = schemaKey;
|
|
133
135
|
}
|
|
@@ -138,6 +140,11 @@ exports.SchemaId = SchemaId;
|
|
|
138
140
|
* @alpha
|
|
139
141
|
*/
|
|
140
142
|
class SchemaItemId {
|
|
143
|
+
typeIdentifier;
|
|
144
|
+
name;
|
|
145
|
+
schemaKey;
|
|
146
|
+
schemaItemType;
|
|
147
|
+
schemaItemKey;
|
|
141
148
|
constructor(schemaItemType, schemaItemKeyOrName, schemaKey) {
|
|
142
149
|
if (typeof (schemaItemKeyOrName) === "string") {
|
|
143
150
|
if (!schemaKey)
|
|
@@ -160,9 +167,10 @@ exports.SchemaItemId = SchemaItemId;
|
|
|
160
167
|
* @alpha
|
|
161
168
|
*/
|
|
162
169
|
class ClassId extends SchemaItemId {
|
|
170
|
+
typeIdentifier = SchemaTypeIdentifiers.ClassIdentifier;
|
|
171
|
+
schemaItemType;
|
|
163
172
|
constructor(schemaItemType, schemaItemKeyOrName, schemaKey) {
|
|
164
173
|
super(schemaItemType, schemaItemKeyOrName, schemaKey);
|
|
165
|
-
this.typeIdentifier = SchemaTypeIdentifiers.ClassIdentifier;
|
|
166
174
|
this.schemaItemType = schemaItemType;
|
|
167
175
|
}
|
|
168
176
|
}
|
|
@@ -172,8 +180,13 @@ exports.ClassId = ClassId;
|
|
|
172
180
|
* @alpha
|
|
173
181
|
*/
|
|
174
182
|
class PropertyId {
|
|
183
|
+
typeIdentifier = SchemaTypeIdentifiers.PropertyIdentifier;
|
|
184
|
+
name;
|
|
185
|
+
fullName;
|
|
186
|
+
ecClass;
|
|
187
|
+
schemaKey;
|
|
188
|
+
typeName;
|
|
175
189
|
constructor(schemaItemType, classKey, property, typeName) {
|
|
176
|
-
this.typeIdentifier = SchemaTypeIdentifiers.PropertyIdentifier;
|
|
177
190
|
this.name = property instanceof ecschema_metadata_1.Property ? property.name : property;
|
|
178
191
|
this.fullName = property instanceof ecschema_metadata_1.Property ? property.fullName : `${classKey.name}.${property}`;
|
|
179
192
|
this.ecClass = new ClassId(schemaItemType, classKey);
|
|
@@ -187,8 +200,13 @@ exports.PropertyId = PropertyId;
|
|
|
187
200
|
* @alpha
|
|
188
201
|
*/
|
|
189
202
|
class EnumeratorId {
|
|
203
|
+
typeIdentifier = SchemaTypeIdentifiers.EnumeratorIdentifier;
|
|
204
|
+
enumeration;
|
|
205
|
+
enumerationType;
|
|
206
|
+
enumeratorType;
|
|
207
|
+
name;
|
|
208
|
+
schemaKey;
|
|
190
209
|
constructor(enumerator, enumeration) {
|
|
191
|
-
this.typeIdentifier = SchemaTypeIdentifiers.EnumeratorIdentifier;
|
|
192
210
|
this.enumeration = enumeration.key;
|
|
193
211
|
this.enumerationType = enumeration.type ? (0, ecschema_metadata_1.primitiveTypeToString)(enumeration.type) : "string";
|
|
194
212
|
this.enumeratorType = getEnumeratorType(enumeration ?? ecschema_metadata_1.PrimitiveType.String, enumerator);
|
|
@@ -202,8 +220,11 @@ exports.EnumeratorId = EnumeratorId;
|
|
|
202
220
|
* @alpha
|
|
203
221
|
*/
|
|
204
222
|
class CustomAttributeId {
|
|
223
|
+
typeIdentifier = SchemaTypeIdentifiers.CustomAttributeIdentifier;
|
|
224
|
+
name;
|
|
225
|
+
schemaKey;
|
|
226
|
+
containerFullName;
|
|
205
227
|
constructor(name, container) {
|
|
206
|
-
this.typeIdentifier = SchemaTypeIdentifiers.CustomAttributeIdentifier;
|
|
207
228
|
this.name = name;
|
|
208
229
|
this.schemaKey = container.schema.schemaKey;
|
|
209
230
|
this.containerFullName = container.fullName;
|
|
@@ -215,8 +236,11 @@ exports.CustomAttributeId = CustomAttributeId;
|
|
|
215
236
|
* @alpha
|
|
216
237
|
*/
|
|
217
238
|
class RelationshipConstraintId {
|
|
239
|
+
typeIdentifier = SchemaTypeIdentifiers.RelationshipConstraintIdentifier;
|
|
240
|
+
name;
|
|
241
|
+
relationshipKey;
|
|
242
|
+
schemaKey;
|
|
218
243
|
constructor(constraint) {
|
|
219
|
-
this.typeIdentifier = SchemaTypeIdentifiers.RelationshipConstraintIdentifier;
|
|
220
244
|
this.name = constraint.isSource ? "Source" : "Target";
|
|
221
245
|
this.relationshipKey = constraint.relationshipClass.key;
|
|
222
246
|
this.schemaKey = this.relationshipKey.schemaKey;
|
|
@@ -232,6 +256,11 @@ exports.RelationshipConstraintId = RelationshipConstraintId;
|
|
|
232
256
|
* @alpha
|
|
233
257
|
*/
|
|
234
258
|
class SchemaEditingError extends Error {
|
|
259
|
+
errorNumber;
|
|
260
|
+
identifier;
|
|
261
|
+
innerError;
|
|
262
|
+
_ruleViolations;
|
|
263
|
+
_schemaKey;
|
|
235
264
|
/**
|
|
236
265
|
* Constructs a new SchemaEditingError instance.
|
|
237
266
|
* @param errorNumber The unique ECEditingStatus code identifying the error.
|