@itwin/ecschema-editing 4.7.0-dev.15 → 4.7.0-dev.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Differencing/Errors.js.map +1 -1
- package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -1
- package/lib/cjs/Differencing/SchemaDifference.js.map +1 -1
- package/lib/cjs/Editing/Constants.d.ts +6 -6
- package/lib/cjs/Editing/Constants.d.ts.map +1 -1
- package/lib/cjs/Editing/Constants.js +26 -31
- package/lib/cjs/Editing/Constants.js.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.d.ts +3 -3
- package/lib/cjs/Editing/CustomAttributes.d.ts.map +1 -1
- package/lib/cjs/Editing/CustomAttributes.js +18 -28
- package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
- package/lib/cjs/Editing/ECClasses.d.ts +24 -23
- package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/ECClasses.js +126 -156
- package/lib/cjs/Editing/ECClasses.js.map +1 -1
- package/lib/cjs/Editing/Editor.d.ts +10 -31
- package/lib/cjs/Editing/Editor.d.ts.map +1 -1
- package/lib/cjs/Editing/Editor.js +59 -43
- package/lib/cjs/Editing/Editor.js.map +1 -1
- package/lib/cjs/Editing/Entities.d.ts +9 -9
- package/lib/cjs/Editing/Entities.d.ts.map +1 -1
- package/lib/cjs/Editing/Entities.js +65 -85
- package/lib/cjs/Editing/Entities.js.map +1 -1
- package/lib/cjs/Editing/Enumerations.d.ts +6 -6
- package/lib/cjs/Editing/Enumerations.d.ts.map +1 -1
- package/lib/cjs/Editing/Enumerations.js +57 -55
- package/lib/cjs/Editing/Enumerations.js.map +1 -1
- package/lib/cjs/Editing/Exception.d.ts +257 -0
- package/lib/cjs/Editing/Exception.d.ts.map +1 -0
- package/lib/cjs/Editing/Exception.js +426 -0
- package/lib/cjs/Editing/Exception.js.map +1 -0
- package/lib/cjs/Editing/Formats.d.ts +6 -6
- package/lib/cjs/Editing/Formats.d.ts.map +1 -1
- package/lib/cjs/Editing/Formats.js +28 -33
- package/lib/cjs/Editing/Formats.js.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.d.ts +6 -6
- package/lib/cjs/Editing/InvertedUnits.d.ts.map +1 -1
- package/lib/cjs/Editing/InvertedUnits.js +41 -56
- package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.d.ts +6 -6
- package/lib/cjs/Editing/KindOfQuantities.d.ts.map +1 -1
- package/lib/cjs/Editing/KindOfQuantities.js +50 -57
- package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
- package/lib/cjs/Editing/Mixins.d.ts +5 -5
- package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
- package/lib/cjs/Editing/Mixins.js +43 -58
- 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.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +1 -5
- package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts.map +1 -1
- package/lib/cjs/Editing/Mutable/MutableEntityClass.js +1 -45
- 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.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/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 +7 -7
- package/lib/cjs/Editing/Phenomena.d.ts.map +1 -1
- package/lib/cjs/Editing/Phenomena.js +23 -23
- package/lib/cjs/Editing/Phenomena.js.map +1 -1
- package/lib/cjs/Editing/Properties.d.ts +7 -6
- package/lib/cjs/Editing/Properties.d.ts.map +1 -1
- package/lib/cjs/Editing/Properties.js +99 -46
- package/lib/cjs/Editing/Properties.js.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.d.ts +6 -6
- package/lib/cjs/Editing/PropertyCategories.d.ts.map +1 -1
- package/lib/cjs/Editing/PropertyCategories.js +29 -27
- package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.d.ts +15 -17
- package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
- package/lib/cjs/Editing/RelationshipClasses.js +97 -101
- package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
- package/lib/cjs/Editing/SchemaItems.d.ts +13 -5
- package/lib/cjs/Editing/SchemaItems.d.ts.map +1 -1
- package/lib/cjs/Editing/SchemaItems.js +58 -6
- package/lib/cjs/Editing/SchemaItems.js.map +1 -1
- package/lib/cjs/Editing/Structs.d.ts +3 -3
- package/lib/cjs/Editing/Structs.d.ts.map +1 -1
- package/lib/cjs/Editing/Structs.js +17 -27
- package/lib/cjs/Editing/Structs.js.map +1 -1
- package/lib/cjs/Editing/UnitSystems.d.ts +7 -7
- package/lib/cjs/Editing/UnitSystems.d.ts.map +1 -1
- package/lib/cjs/Editing/UnitSystems.js +22 -20
- package/lib/cjs/Editing/UnitSystems.js.map +1 -1
- package/lib/cjs/Editing/Units.d.ts +6 -6
- package/lib/cjs/Editing/Units.d.ts.map +1 -1
- package/lib/cjs/Editing/Units.js +26 -35
- package/lib/cjs/Editing/Units.js.map +1 -1
- package/lib/cjs/Merging/CAClassMerger.js +2 -2
- package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ClassMerger.d.ts +1 -2
- package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ClassMerger.js +15 -39
- package/lib/cjs/Merging/ClassMerger.js.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/ConstantMerger.js +2 -3
- package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts +4 -5
- package/lib/cjs/Merging/CustomAttributeMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/CustomAttributeMerger.js +8 -18
- package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.d.ts +1 -2
- package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EntityClassMerger.js +3 -10
- package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/EnumerationMerger.js +8 -10
- package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/KindOfQuantityMerger.js +2 -3
- package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
- package/lib/cjs/Merging/MixinMerger.js +2 -2
- package/lib/cjs/Merging/MixinMerger.js.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PhenomenonMerger.js +1 -2
- package/lib/cjs/Merging/PhenomenonMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyCategoryMerger.js +1 -2
- package/lib/cjs/Merging/PropertyCategoryMerger.js.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.d.ts +2 -3
- package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/PropertyMerger.js +21 -42
- package/lib/cjs/Merging/PropertyMerger.js.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts +5 -3
- package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/RelationshipClassMerger.js +19 -31
- package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.d.ts +3 -4
- package/lib/cjs/Merging/SchemaItemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaItemMerger.js +3 -2
- package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/SchemaMerger.js +2 -8
- package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
- package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.d.ts.map +1 -1
- package/lib/cjs/Merging/UnitSystemMerger.js +1 -2
- package/lib/cjs/Merging/UnitSystemMerger.js.map +1 -1
- package/lib/cjs/Validation/Diagnostic.js.map +1 -1
- package/lib/cjs/Validation/DiagnosticReporter.js.map +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.map +1 -1
- package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
- package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
- package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
- package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
- package/lib/cjs/ecschema-editing.js.map +1 -1
- package/package.json +9 -9
- package/public/locales/en/ECSchemaEditing.json +26 -26
|
@@ -11,6 +11,7 @@ exports.Entities = void 0;
|
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
12
|
const ECClasses_1 = require("./ECClasses");
|
|
13
13
|
const Properties_1 = require("./Properties");
|
|
14
|
+
const Exception_1 = require("./Exception");
|
|
14
15
|
/**
|
|
15
16
|
* @alpha
|
|
16
17
|
* A class extending ECClasses allowing you to create schema items of type EntityClass.
|
|
@@ -21,66 +22,56 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
21
22
|
/**
|
|
22
23
|
* Allows access for editing of NavigationProperty attributes.
|
|
23
24
|
*/
|
|
24
|
-
this.navigationProperties = new Properties_1.NavigationProperties(
|
|
25
|
+
this.navigationProperties = new Properties_1.NavigationProperties(ecschema_metadata_1.SchemaItemType.EntityClass, this.schemaEditor);
|
|
25
26
|
}
|
|
26
27
|
async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
try {
|
|
29
|
+
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
30
|
+
if (!(await baseClass.is("Element", "BisCore"))) {
|
|
31
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElement, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateElement, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
34
36
|
}
|
|
35
37
|
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
36
38
|
}
|
|
37
39
|
async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
try {
|
|
41
|
+
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
42
|
+
if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
|
|
43
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElementUniqueAspect, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateElement, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
45
48
|
}
|
|
46
49
|
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
47
50
|
}
|
|
48
51
|
async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
try {
|
|
53
|
+
const baseClass = await this.getSchemaItem(baseClassKey);
|
|
54
|
+
if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
|
|
55
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.BaseClassIsNotElementMultiAspect, new Exception_1.ClassId(this.schemaItemType, baseClassKey));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateElement, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
56
60
|
}
|
|
57
61
|
return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
|
|
58
62
|
}
|
|
59
63
|
async create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
|
|
73
|
-
if (baseClassItem === undefined)
|
|
74
|
-
return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
|
|
75
|
-
if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
|
|
76
|
-
return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
|
|
77
|
-
newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
|
|
78
|
-
}
|
|
79
|
-
if (mixins !== undefined)
|
|
80
|
-
mixins.forEach((m) => newClass.addMixin(m));
|
|
81
|
-
if (displayLabel)
|
|
82
|
-
newClass.setDisplayLabel(displayLabel);
|
|
83
|
-
return { itemKey: newClass.key };
|
|
64
|
+
try {
|
|
65
|
+
const newClass = await this.createClass(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), name, baseClassKey, modifier);
|
|
66
|
+
if (mixins !== undefined)
|
|
67
|
+
mixins.forEach((m) => newClass.addMixin(m));
|
|
68
|
+
if (displayLabel)
|
|
69
|
+
newClass.setDisplayLabel(displayLabel);
|
|
70
|
+
return newClass.key;
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFailed, new Exception_1.ClassId(this.schemaItemType, name, schemaKey), e);
|
|
74
|
+
}
|
|
84
75
|
}
|
|
85
76
|
/**
|
|
86
77
|
* Creates an EntityClass through an EntityClassProps.
|
|
@@ -88,43 +79,32 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
88
79
|
* @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
|
|
89
80
|
*/
|
|
90
81
|
async createFromProps(schemaKey, entityProps) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return
|
|
94
|
-
if (entityProps.name === undefined)
|
|
95
|
-
return { errorMessage: `No name was supplied within props.` };
|
|
96
|
-
const newClass = (await schema.createEntityClass(entityProps.name));
|
|
97
|
-
if (newClass === undefined)
|
|
98
|
-
return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
99
|
-
await newClass.fromJSON(entityProps);
|
|
100
|
-
return { itemKey: newClass.key };
|
|
101
|
-
}
|
|
102
|
-
async addMixin(entityKey, mixinKey) {
|
|
103
|
-
const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
|
|
104
|
-
if (entity === undefined) {
|
|
105
|
-
return { errorMessage: `Entity Class ${entityKey.fullName} not found in schema context.` };
|
|
82
|
+
try {
|
|
83
|
+
const newClass = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEntityClass.bind(schema), entityProps);
|
|
84
|
+
return newClass.key;
|
|
106
85
|
}
|
|
107
|
-
|
|
108
|
-
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFromProps, new Exception_1.ClassId(this.schemaItemType, entityProps.name, schemaKey), e);
|
|
109
88
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
89
|
+
}
|
|
90
|
+
async addMixin(entityKey, mixinKey) {
|
|
91
|
+
try {
|
|
92
|
+
const entity = await this.getSchemaItem(entityKey);
|
|
93
|
+
const mixin = await this.getSchemaItem(mixinKey, ecschema_metadata_1.SchemaItemType.Mixin);
|
|
94
|
+
entity.addMixin(mixin);
|
|
113
95
|
}
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
catch (e) {
|
|
97
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddMixin, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.EntityClass, entityKey), e);
|
|
116
98
|
}
|
|
117
|
-
entity.addMixin(mixin);
|
|
118
|
-
return { itemKey: entityKey };
|
|
119
99
|
}
|
|
120
100
|
async createNavigationProperty(entityKey, name, relationship, direction) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
101
|
+
try {
|
|
102
|
+
const entity = await this.getSchemaItem(entityKey);
|
|
103
|
+
await entity.createNavigationProperty(name, relationship, direction);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateNavigationProperty, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.RelationshipClass, entityKey), e);
|
|
107
|
+
}
|
|
128
108
|
}
|
|
129
109
|
/**
|
|
130
110
|
* Creates a Navigation Property through a NavigationPropertyProps.
|
|
@@ -132,14 +112,14 @@ class Entities extends ECClasses_1.ECClasses {
|
|
|
132
112
|
* @param navigationProps a json object that will be used to populate the new Navigation Property.
|
|
133
113
|
*/
|
|
134
114
|
async createNavigationPropertyFromProps(classKey, navigationProps) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
115
|
+
try {
|
|
116
|
+
const entity = await this.getSchemaItem(classKey);
|
|
117
|
+
const property = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);
|
|
118
|
+
await property.fromJSON(navigationProps);
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateNavigationPropertyFromProps, new Exception_1.ClassId(ecschema_metadata_1.SchemaItemType.EntityClass, classKey), e);
|
|
122
|
+
}
|
|
143
123
|
}
|
|
144
124
|
}
|
|
145
125
|
exports.Entities = Entities;
|
|
@@ -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;AAEpD;;;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,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IALzG,CAAC;IAOM,KAAK,CAAC,aAAa,CAAC,SAAoB,EAAE,IAAY,EAAE,QAAyB,EAAE,YAA2B,EAAE,YAAqB,EAAE,MAAgB;QAC5J,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QACrF,IAAI,CAAC,SAAS;YACZ,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,0DAA0D,YAAY,CAAC,QAAQ,sBAAsB,CAAC,CAAC;QAE1I,IAAI,SAAS,EAAE,cAAc,KAAK,kCAAc,CAAC,WAAW;YAC1D,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,0DAA0D,YAAY,CAAC,QAAQ,yBAAyB,CAAC,CAAC;QAE7I,IAAI,C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K,SAAS;YACtB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,QAAQ,CAAC,QAAQ,+BAA+B,EAAC,CAAC;QAElJ,IAAI,MAAM,CAAC,cAAc,KAAK,kCAAc,CAAC,WAAW;YACtD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,YAAY,QAAQ,CAAC,QAAQ,6BAA6B,EAAE,CAAC;QAE7I,MAAM,kBAAkB,GAAI,MAAM,MAAM,CAAC,wBAAwB,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,CAAC,gBAAgB,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;QACrJ,MAAM,kBAAkB,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QAEnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe,CAAC,IAAI,EAAE,CAAC;IACnE,CAAC;CACF;AApKD,4BAoKC","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 DelayedPromiseWithProps, ECClassModifier, ECObjectsError, ECObjectsStatus, EntityClass, EntityClassProps,\r\n Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableEntityClass } from \"./Mutable/MutableEntityClass\";\r\nimport { NavigationProperties } from \"./Properties\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type 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(this.schemaItemType, this._schemaEditor);\r\n\r\n public async createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could not be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"Element\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);\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<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could not be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"ElementUniqueAspect\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);\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<SchemaItemEditResults> {\r\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\r\n if (!baseClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);\r\n\r\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\r\n\r\n if (!(await (baseClass as EntityClass).is(\"ElementMultiAspect\", \"BisCore\"))) {\r\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);\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<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newClass = (await schema.createEntityClass(name, modifier)) as MutableEntityClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n // Add a deserializing method.\r\n if (baseClassKey !== undefined) {\r\n const baseClassSchema = !baseClassKey.schemaKey.matches(schema.schemaKey) ? await this._schemaEditor.getSchema(baseClassKey.schemaKey) : schema;\r\n if (baseClassSchema === undefined) {\r\n return { errorMessage: `Schema Key ${baseClassKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const baseClassItem = await baseClassSchema.lookupItem<EntityClass>(baseClassKey);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.EntityClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(baseClassKey, async () => baseClassItem);\r\n }\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 { itemKey: newClass.key };\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<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (entityProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createEntityClass(entityProps.name)) as MutableEntityClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newClass.fromJSON(entityProps);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\r\n if (entity === undefined) {\r\n return { errorMessage: `Entity Class ${entityKey.fullName} not found in schema context.` };\r\n }\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass) {\r\n return { errorMessage: `Expected ${entityKey.fullName} to be of type Entity Class.` };\r\n }\r\n\r\n const mixin = (await this._schemaEditor.schemaContext.getSchemaItem<Mixin>(mixinKey));\r\n if (mixin === undefined) {\r\n return { errorMessage: `Mixin Class ${mixinKey.fullName} not found in schema context.` };\r\n }\r\n if (mixin.schemaItemType !== SchemaItemType.Mixin) {\r\n return { errorMessage: `Expected ${mixinKey.fullName} to be of type Mixin.`};\r\n }\r\n\r\n entity.addMixin(mixin);\r\n return { itemKey: entityKey };\r\n }\r\n\r\n public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\r\n const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey);\r\n\r\n if (entity === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);\r\n\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);\r\n\r\n await entity.createNavigationProperty(name, relationship, direction);\r\n return { itemKey: entityKey, propertyName: name };\r\n }\r\n\r\n /**\r\n * Creates a Navigation Property through a NavigationPropertyProps.\r\n * @param classKey a SchemaItemKey of the 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<PropertyEditResults> {\r\n const entity = await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(classKey);\r\n if (entity === undefined)\r\n return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Entity Class ${classKey.fullName} not found in schema context.`};\r\n\r\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\r\n return { itemKey: classKey, propertyName: navigationProps.name, errorMessage: `Expected ${classKey.fullName} to be of type EntityClass.` };\r\n\r\n const navigationProperty = await entity.createNavigationProperty(navigationProps.name, navigationProps.relationshipName, navigationProps.direction);\r\n await navigationProperty.fromJSON(navigationProps);\r\n\r\n return { itemKey: classKey, propertyName: navigationProps.name };\r\n }\r\n}\r\n"]}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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":["/*---------------------------------------------------------------------------------------------\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 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);\n if (!(await (baseClass as EntityClass).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);\n if (!(await (baseClass as EntityClass).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);\n if (!(await (baseClass as EntityClass).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<MutableEntityClass>(entityKey);\n const mixin = await this.getSchemaItem<Mixin>(mixinKey, SchemaItemType.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<MutableEntityClass>(entityKey);\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<MutableEntityClass>(classKey);\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"]}
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
* @module Editing
|
|
3
3
|
*/
|
|
4
4
|
import { AnyEnumerator, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
|
|
5
|
-
import { SchemaContextEditor
|
|
5
|
+
import { SchemaContextEditor } from "./Editor";
|
|
6
|
+
import { SchemaItems } from "./SchemaItems";
|
|
6
7
|
/**
|
|
7
8
|
* @alpha
|
|
8
9
|
* A class allowing you to create schema items of type Enumeration.
|
|
9
10
|
*/
|
|
10
|
-
export declare class Enumerations {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults>;
|
|
11
|
+
export declare class Enumerations extends SchemaItems {
|
|
12
|
+
constructor(schemaEditor: SchemaContextEditor);
|
|
13
|
+
create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemKey>;
|
|
14
14
|
/**
|
|
15
15
|
* Creates an Enumeration through an EnumeratorProps.
|
|
16
16
|
* @param schemaKey a SchemaKey of the Schema that will house the new object.
|
|
17
17
|
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
18
18
|
*/
|
|
19
|
-
createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<
|
|
19
|
+
createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemKey>;
|
|
20
20
|
addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void>;
|
|
21
21
|
setEnumeratorLabel(enumerationKey: SchemaItemKey, enumeratorName: string, label: string | undefined): Promise<void>;
|
|
22
22
|
setEnumeratorDescription(enumerationKey: SchemaItemKey, enumeratorName: string, description: string | undefined): Promise<void>;
|
|
@@ -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,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;gBACxB,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"}
|
|
@@ -9,29 +9,31 @@
|
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.Enumerations = void 0;
|
|
11
11
|
const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
|
|
12
|
+
const Exception_1 = require("./Exception");
|
|
13
|
+
const SchemaItems_1 = require("./SchemaItems");
|
|
12
14
|
/**
|
|
13
15
|
* @alpha
|
|
14
16
|
* A class allowing you to create schema items of type Enumeration.
|
|
15
17
|
*/
|
|
16
|
-
class Enumerations {
|
|
17
|
-
constructor(
|
|
18
|
-
|
|
18
|
+
class Enumerations extends SchemaItems_1.SchemaItems {
|
|
19
|
+
constructor(schemaEditor) {
|
|
20
|
+
super(ecschema_metadata_1.SchemaItemType.Enumeration, schemaEditor);
|
|
19
21
|
}
|
|
20
22
|
async create(schemaKey, name, type, displayLabel, isStrict, enumerators) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
try {
|
|
24
|
+
const newEnum = await this.createSchemaItem(schemaKey, this.schemaItemType, (schema) => schema.createEnumeration.bind(schema), name, type);
|
|
25
|
+
if (undefined !== isStrict)
|
|
26
|
+
newEnum.setIsStrict(isStrict);
|
|
27
|
+
if (undefined !== enumerators)
|
|
28
|
+
for (const enumerator of enumerators)
|
|
29
|
+
await this.addEnumerator(newEnum.key, enumerator);
|
|
30
|
+
if (displayLabel)
|
|
31
|
+
newEnum.setDisplayLabel(displayLabel);
|
|
32
|
+
return newEnum.key;
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFailed, new Exception_1.SchemaItemId(this.schemaItemType, name, schemaKey), e);
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
37
39
|
* Creates an Enumeration through an EnumeratorProps.
|
|
@@ -39,50 +41,50 @@ class Enumerations {
|
|
|
39
41
|
* @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
|
|
40
42
|
*/
|
|
41
43
|
async createFromProps(schemaKey, enumProps) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };
|
|
50
|
-
await newEnum.fromJSON(enumProps);
|
|
51
|
-
return { itemKey: newEnum.key };
|
|
44
|
+
try {
|
|
45
|
+
const newEnum = await this.createSchemaItemFromProps(schemaKey, this.schemaItemType, (schema) => schema.createEnumeration.bind(schema), enumProps);
|
|
46
|
+
return newEnum.key;
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.CreateSchemaItemFromProps, new Exception_1.SchemaItemId(this.schemaItemType, enumProps.name, schemaKey), e);
|
|
50
|
+
}
|
|
52
51
|
}
|
|
53
52
|
async addEnumerator(enumerationKey, enumerator) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
try {
|
|
54
|
+
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.SchemaItemType.Enumeration);
|
|
55
|
+
if (enumeration.isInt && typeof (enumerator.value) !== "number")
|
|
56
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.InvalidEnumeratorType, new Exception_1.EnumerationId(enumeration, enumerator));
|
|
57
|
+
if (enumeration.isString && typeof (enumerator.value) !== "string")
|
|
58
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.InvalidEnumeratorType, new Exception_1.EnumerationId(enumeration, enumerator));
|
|
59
|
+
enumeration.addEnumerator(enumerator);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.AddEnumerator, new Exception_1.SchemaItemId(this.schemaItemType, enumerationKey), e);
|
|
63
|
+
}
|
|
64
64
|
}
|
|
65
65
|
async setEnumeratorLabel(enumerationKey, enumeratorName, label) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
try {
|
|
67
|
+
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.SchemaItemType.Enumeration);
|
|
68
|
+
const enumerator = enumeration.getEnumeratorByName(enumeratorName);
|
|
69
|
+
if (enumerator === undefined)
|
|
70
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.EnumeratorDoesNotExist, new Exception_1.EnumerationId(enumeration, enumeratorName));
|
|
71
|
+
enumerator.label = label;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetEnumeratorLabel, new Exception_1.SchemaItemId(this.schemaItemType, enumerationKey), e);
|
|
75
|
+
}
|
|
75
76
|
}
|
|
76
77
|
async setEnumeratorDescription(enumerationKey, enumeratorName, description) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
try {
|
|
79
|
+
const enumeration = await this.getSchemaItem(enumerationKey, ecschema_metadata_1.SchemaItemType.Enumeration);
|
|
80
|
+
const enumerator = enumeration.getEnumeratorByName(enumeratorName);
|
|
81
|
+
if (enumerator === undefined)
|
|
82
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.EnumeratorDoesNotExist, new Exception_1.EnumerationId(enumeration, enumeratorName));
|
|
83
|
+
enumerator.description = description;
|
|
84
|
+
}
|
|
85
|
+
catch (e) {
|
|
86
|
+
throw new Exception_1.SchemaEditingError(Exception_1.ECEditingStatus.SetEnumeratorLabel, new Exception_1.SchemaItemId(this.schemaItemType, enumerationKey), e);
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
exports.Enumerations = Enumerations;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Enumerations.js","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkL;AAQlL;;;GAGG;AACH,MAAa,YAAY;IACvB,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAE7D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,IAAkD,EAAE,YAAqB,EAAE,QAAkB,EAAE,WAA6B;QAClL,MAAM,MAAM,GAAG,MAAM,IAAI,CAA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,mCAAe,CAAC,WAAW,EAAE,GAAG,WAAW,CAAC,QAAQ,mCAAmC,CAAC,CAAC;QAEpH,MAAM,UAAU,GAAG,WAAW,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;QACnE,IAAI,UAAU,KAAK,SAAS;YAC1B,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,cAAc,cAAc,mCAAmC,WAAW,CAAC,QAAQ,GAAG,CAAC,CAAC;QAEjJ,UAAgC,CAAC,WAAW,GAAG,WAAW,CAAC;IAC9D,CAAC;CACF;AA/FD,oCA+FC","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 { AnyEnumerator, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaItemType, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableEnumeration } from \"./Mutable/MutableEnumeration\";\r\n\r\ntype MutableEnumerator = {\r\n -readonly [P in keyof AnyEnumerator]: AnyEnumerator[P]\r\n};\r\n\r\n/**\r\n * @alpha\r\n * A class allowing you to create schema items of type Enumeration.\r\n */\r\nexport class Enumerations {\r\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newEnum = (await schema.createEnumeration(name, type));\r\n if (newEnum === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n if (undefined !== isStrict)\r\n (newEnum as MutableEnumeration).setIsStrict(isStrict);\r\n\r\n if (undefined !== enumerators)\r\n for (const enumerator of enumerators)\r\n await this.addEnumerator(newEnum.key, enumerator);\r\n\r\n if (displayLabel)\r\n (newEnum as MutableEnumeration).setDisplayLabel(displayLabel);\r\n\r\n return { itemKey: newEnum.key };\r\n }\r\n\r\n /**\r\n * Creates an Enumeration through an EnumeratorProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (enumProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newEnum = (await schema.createEnumeration(enumProps.name));\r\n if (newEnum === undefined)\r\n return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newEnum.fromJSON(enumProps);\r\n return { itemKey: newEnum.key };\r\n }\r\n\r\n public async addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void> {\r\n const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem<Enumeration>(enumerationKey));\r\n\r\n if (enumeration === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);\r\n\r\n if (enumeration.schemaItemType !== SchemaItemType.Enumeration)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);\r\n\r\n if (enumeration.isInt && typeof (enumerator.value) !== \"number\")\r\n throw new ECObjectsError(ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);\r\n\r\n if (enumeration.isString && typeof (enumerator.value) !== \"string\")\r\n throw new ECObjectsError(ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);\r\n\r\n (enumeration as MutableEnumeration).addEnumerator(enumerator);\r\n }\r\n\r\n public async setEnumeratorLabel(enumerationKey: SchemaItemKey, enumeratorName: string, label: string | undefined): Promise<void> {\r\n const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem<Enumeration>(enumerationKey));\r\n\r\n if (enumeration === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);\r\n\r\n if (enumeration.schemaItemType !== SchemaItemType.Enumeration)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);\r\n\r\n const enumerator = enumeration.getEnumeratorByName(enumeratorName);\r\n if (enumerator === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Enumerator ${enumeratorName} does not exists in Enumeration ${enumeration.fullName}.`);\r\n\r\n (enumerator as MutableEnumerator).label = label;\r\n }\r\n\r\n public async setEnumeratorDescription(enumerationKey: SchemaItemKey, enumeratorName: string, description: string | undefined): Promise<void> {\r\n const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem<Enumeration>(enumerationKey));\r\n\r\n if (enumeration === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);\r\n\r\n if (enumeration.schemaItemType !== SchemaItemType.Enumeration)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);\r\n\r\n const enumerator = enumeration.getEnumeratorByName(enumeratorName);\r\n if (enumerator === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Enumerator ${enumeratorName} does not exists in Enumeration ${enumeration.fullName}.`);\r\n\r\n (enumerator as MutableEnumerator).description = description;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Enumerations.js","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAiJ;AAGjJ,2CAA+F;AAC/F,+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,KAAK,WAAW;gBAC3B,KAAK,MAAM,UAAU,IAAI,WAAW;oBAClC,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;YAEtD,IAAI,YAAY;gBACd,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;YAExC,OAAO,OAAO,CAAC,GAAG,CAAC;QACrB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,sBAAsB,EAAE,IAAI,wBAAY,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;QA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,GAAG,WAAW,CAAC;QAC9D,CAAC;QAAC,OAAM,CAAM,EAAE,CAAC;YACf,MAAM,IAAI,8BAAkB,CAAC,2BAAe,CAAC,kBAAkB,EAAE,IAAI,wBAAY,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7H,CAAC;IACH,CAAC;CACF;AAlFD,oCAkFC","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, EnumerationId, 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 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<Enumeration>(enumerationKey, SchemaItemType.Enumeration);\n\n if (enumeration.isInt && typeof (enumerator.value) !== \"number\")\n throw new SchemaEditingError(ECEditingStatus.InvalidEnumeratorType, new EnumerationId(enumeration, enumerator));\n\n if (enumeration.isString && typeof (enumerator.value) !== \"string\")\n throw new SchemaEditingError(ECEditingStatus.InvalidEnumeratorType, new EnumerationId(enumeration, enumerator));\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<Enumeration>(enumerationKey, SchemaItemType.Enumeration);\n\n const enumerator = enumeration.getEnumeratorByName(enumeratorName);\n if (enumerator === undefined)\n throw new SchemaEditingError(ECEditingStatus.EnumeratorDoesNotExist, new EnumerationId(enumeration, enumeratorName));\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<Enumeration>(enumerationKey, SchemaItemType.Enumeration);\n\n const enumerator = enumeration.getEnumeratorByName(enumeratorName);\n if (enumerator === undefined)\n throw new SchemaEditingError(ECEditingStatus.EnumeratorDoesNotExist, new EnumerationId(enumeration, enumeratorName));\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"]}
|