@itwin/ecschema-editing 3.7.5 → 3.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/cjs/Editing/Constants.d.ts +20 -20
  3. package/lib/cjs/Editing/Constants.js +60 -60
  4. package/lib/cjs/Editing/Constants.js.map +1 -1
  5. package/lib/cjs/Editing/CustomAttributes.d.ts +20 -20
  6. package/lib/cjs/Editing/CustomAttributes.js +59 -59
  7. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  8. package/lib/cjs/Editing/ECClasses.d.ts +54 -54
  9. package/lib/cjs/Editing/ECClasses.js +269 -269
  10. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  11. package/lib/cjs/Editing/Editor.d.ts +112 -112
  12. package/lib/cjs/Editing/Editor.js +166 -166
  13. package/lib/cjs/Editing/Editor.js.map +1 -1
  14. package/lib/cjs/Editing/Entities.d.ts +25 -25
  15. package/lib/cjs/Editing/Entities.js +116 -116
  16. package/lib/cjs/Editing/Entities.js.map +1 -1
  17. package/lib/cjs/Editing/Enumerations.d.ts +21 -21
  18. package/lib/cjs/Editing/Enumerations.js +66 -66
  19. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  20. package/lib/cjs/Editing/Formats.d.ts +21 -21
  21. package/lib/cjs/Editing/Formats.js +61 -61
  22. package/lib/cjs/Editing/Formats.js.map +1 -1
  23. package/lib/cjs/Editing/InvertedUnits.d.ts +17 -17
  24. package/lib/cjs/Editing/InvertedUnits.js +82 -82
  25. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  26. package/lib/cjs/Editing/KindOfQuantities.d.ts +28 -28
  27. package/lib/cjs/Editing/KindOfQuantities.js +78 -78
  28. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  29. package/lib/cjs/Editing/Mixins.d.ts +22 -22
  30. package/lib/cjs/Editing/Mixins.js +84 -84
  31. package/lib/cjs/Editing/Mixins.js.map +1 -1
  32. package/lib/cjs/Editing/Mutable/MutableCAClass.d.ts +9 -9
  33. package/lib/cjs/Editing/Mutable/MutableCAClass.js +15 -15
  34. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  35. package/lib/cjs/Editing/Mutable/MutableClass.d.ts +34 -34
  36. package/lib/cjs/Editing/Mutable/MutableClass.js +22 -22
  37. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  38. package/lib/cjs/Editing/Mutable/MutableConstant.d.ts +12 -12
  39. package/lib/cjs/Editing/Mutable/MutableConstant.js +15 -15
  40. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  41. package/lib/cjs/Editing/Mutable/MutableEntityClass.d.ts +15 -15
  42. package/lib/cjs/Editing/Mutable/MutableEntityClass.js +59 -59
  43. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  44. package/lib/cjs/Editing/Mutable/MutableEnumeration.d.ts +9 -9
  45. package/lib/cjs/Editing/Mutable/MutableEnumeration.js +14 -14
  46. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  47. package/lib/cjs/Editing/Mutable/MutableFormat.d.ts +18 -18
  48. package/lib/cjs/Editing/Mutable/MutableFormat.js +15 -15
  49. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  50. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.d.ts +10 -10
  51. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js +15 -15
  52. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  53. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.d.ts +10 -10
  54. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js +15 -15
  55. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  56. package/lib/cjs/Editing/Mutable/MutableMixin.d.ts +11 -11
  57. package/lib/cjs/Editing/Mutable/MutableMixin.js +15 -15
  58. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  59. package/lib/cjs/Editing/Mutable/MutablePhenomenon.d.ts +9 -9
  60. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js +15 -15
  61. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  62. package/lib/cjs/Editing/Mutable/MutableProperty.d.ts +8 -8
  63. package/lib/cjs/Editing/Mutable/MutableProperty.js +15 -15
  64. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  65. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.d.ts +9 -9
  66. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js +15 -15
  67. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  68. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.d.ts +21 -21
  69. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js +24 -24
  70. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  71. package/lib/cjs/Editing/Mutable/MutableSchema.d.ts +45 -45
  72. package/lib/cjs/Editing/Mutable/MutableSchema.js +17 -17
  73. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  74. package/lib/cjs/Editing/Mutable/MutableUnit.d.ts +11 -11
  75. package/lib/cjs/Editing/Mutable/MutableUnit.js +15 -15
  76. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  77. package/lib/cjs/Editing/Mutable/MutableUnitSystem.d.ts +8 -8
  78. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js +15 -15
  79. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  80. package/lib/cjs/Editing/Phenomena.d.ts +15 -15
  81. package/lib/cjs/Editing/Phenomena.js +44 -44
  82. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  83. package/lib/cjs/Editing/PropertyCategories.d.ts +16 -16
  84. package/lib/cjs/Editing/PropertyCategories.js +51 -51
  85. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  86. package/lib/cjs/Editing/RelationshipClasses.d.ts +21 -21
  87. package/lib/cjs/Editing/RelationshipClasses.js +68 -68
  88. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  89. package/lib/cjs/Editing/Structs.d.ts +19 -19
  90. package/lib/cjs/Editing/Structs.js +57 -57
  91. package/lib/cjs/Editing/Structs.js.map +1 -1
  92. package/lib/cjs/Editing/UnitSystems.d.ts +15 -15
  93. package/lib/cjs/Editing/UnitSystems.js +41 -41
  94. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  95. package/lib/cjs/Editing/Units.d.ts +15 -15
  96. package/lib/cjs/Editing/Units.js +58 -58
  97. package/lib/cjs/Editing/Units.js.map +1 -1
  98. package/lib/cjs/Validation/Diagnostic.d.ts +321 -321
  99. package/lib/cjs/Validation/Diagnostic.js +310 -310
  100. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  101. package/lib/cjs/Validation/DiagnosticReporter.d.ts +96 -96
  102. package/lib/cjs/Validation/DiagnosticReporter.js +106 -106
  103. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  104. package/lib/cjs/Validation/ECRules.d.ts +443 -443
  105. package/lib/cjs/Validation/ECRules.js +579 -579
  106. package/lib/cjs/Validation/ECRules.js.map +1 -1
  107. package/lib/cjs/Validation/LoggingDiagnosticReporter.d.ts +13 -13
  108. package/lib/cjs/Validation/LoggingDiagnosticReporter.js +40 -40
  109. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  110. package/lib/cjs/Validation/RuleSuppressionSet.d.ts +59 -59
  111. package/lib/cjs/Validation/RuleSuppressionSet.js +9 -9
  112. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  113. package/lib/cjs/Validation/Rules.d.ts +64 -64
  114. package/lib/cjs/Validation/Rules.js +9 -9
  115. package/lib/cjs/Validation/Rules.js.map +1 -1
  116. package/lib/cjs/Validation/SchemaChanges.d.ts +607 -607
  117. package/lib/cjs/Validation/SchemaChanges.js +1135 -1135
  118. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  119. package/lib/cjs/Validation/SchemaCompareDiagnostics.d.ts +422 -422
  120. package/lib/cjs/Validation/SchemaCompareDiagnostics.js +111 -111
  121. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  122. package/lib/cjs/Validation/SchemaCompareReporter.d.ts +11 -11
  123. package/lib/cjs/Validation/SchemaCompareReporter.js +9 -9
  124. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  125. package/lib/cjs/Validation/SchemaCompareResultDelegate.d.ts +236 -236
  126. package/lib/cjs/Validation/SchemaCompareResultDelegate.js +348 -348
  127. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  128. package/lib/cjs/Validation/SchemaCompareVisitor.d.ts +119 -119
  129. package/lib/cjs/Validation/SchemaCompareVisitor.js +206 -206
  130. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  131. package/lib/cjs/Validation/SchemaComparer.d.ts +171 -171
  132. package/lib/cjs/Validation/SchemaComparer.js +666 -666
  133. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  134. package/lib/cjs/Validation/SchemaValidater.d.ts +19 -19
  135. package/lib/cjs/Validation/SchemaValidater.js +61 -61
  136. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  137. package/lib/cjs/Validation/SchemaValidationVisitor.d.ts +170 -170
  138. package/lib/cjs/Validation/SchemaValidationVisitor.js +492 -492
  139. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  140. package/lib/cjs/Validation/SchemaWalker.d.ts +22 -22
  141. package/lib/cjs/Validation/SchemaWalker.js +51 -51
  142. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  143. package/lib/cjs/ecschema-editing.d.ts +33 -33
  144. package/lib/cjs/ecschema-editing.js +54 -54
  145. package/lib/cjs/ecschema-editing.js.map +1 -1
  146. package/package.json +10 -10
  147. package/public/locales/en/ECSchemaEditing.json +26 -26
@@ -1,26 +1,26 @@
1
- /** @packageDocumentation
2
- * @module Editing
3
- */
4
- import { ECClassModifier, EntityClassProps, Mixin, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
5
- import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
- import { ECClasses } from "./ECClasses";
7
- /**
8
- * @alpha
9
- * A class extending ECClasses allowing you to create schema items of type EntityClass.
10
- */
11
- export declare class Entities extends ECClasses {
12
- constructor(_schemaEditor: SchemaContextEditor);
13
- createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
14
- createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
15
- createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
16
- create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
17
- /**
18
- * Creates an EntityClass through an EntityClassProps.
19
- * @param schemaKey a SchemaKey of the Schema that will house the new object.
20
- * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
21
- */
22
- createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemEditResults>;
23
- addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void>;
24
- createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults>;
25
- }
1
+ /** @packageDocumentation
2
+ * @module Editing
3
+ */
4
+ import { ECClassModifier, EntityClassProps, Mixin, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
5
+ import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
+ import { ECClasses } from "./ECClasses";
7
+ /**
8
+ * @alpha
9
+ * A class extending ECClasses allowing you to create schema items of type EntityClass.
10
+ */
11
+ export declare class Entities extends ECClasses {
12
+ constructor(_schemaEditor: SchemaContextEditor);
13
+ createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
14
+ createElementUniqueAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
15
+ createElementMultiAspect(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
16
+ create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClassKey?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
17
+ /**
18
+ * Creates an EntityClass through an EntityClassProps.
19
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
20
+ * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
21
+ */
22
+ createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemEditResults>;
23
+ addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void>;
24
+ createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults>;
25
+ }
26
26
  //# sourceMappingURL=Entities.d.ts.map
@@ -1,117 +1,117 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Editing
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Entities = void 0;
11
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
- const ECClasses_1 = require("./ECClasses");
13
- /**
14
- * @alpha
15
- * A class extending ECClasses allowing you to create schema items of type EntityClass.
16
- */
17
- class Entities extends ECClasses_1.ECClasses {
18
- constructor(_schemaEditor) {
19
- super(_schemaEditor);
20
- }
21
- async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
22
- const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
23
- if (!baseClass)
24
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
25
- if ((baseClass === null || baseClass === void 0 ? void 0 : baseClass.schemaItemType) !== ecschema_metadata_1.SchemaItemType.EntityClass)
26
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
27
- if (!(await baseClass.is("Element", "BisCore"))) {
28
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);
29
- }
30
- return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
31
- }
32
- async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
33
- const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
34
- if (!baseClass)
35
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
36
- if ((baseClass === null || baseClass === void 0 ? void 0 : baseClass.schemaItemType) !== ecschema_metadata_1.SchemaItemType.EntityClass)
37
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
38
- if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
39
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);
40
- }
41
- return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
42
- }
43
- async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
44
- const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
45
- if (!baseClass)
46
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
47
- if ((baseClass === null || baseClass === void 0 ? void 0 : baseClass.schemaItemType) !== ecschema_metadata_1.SchemaItemType.EntityClass)
48
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
49
- if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
50
- throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);
51
- }
52
- return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
53
- }
54
- async create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins) {
55
- const schema = await this._schemaEditor.getSchema(schemaKey);
56
- if (schema === undefined)
57
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
58
- const newClass = (await schema.createEntityClass(name, modifier));
59
- if (newClass === undefined)
60
- return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
61
- // Add a deserializing method.
62
- if (baseClassKey !== undefined) {
63
- let baseClassSchema = schema;
64
- if (!baseClassKey.schemaKey.matches(schema.schemaKey))
65
- baseClassSchema = await this._schemaEditor.getSchema(baseClassKey.schemaKey);
66
- const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
67
- if (baseClassItem === undefined)
68
- return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
69
- if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
70
- return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
71
- newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
72
- }
73
- if (mixins !== undefined)
74
- mixins.forEach((m) => newClass.addMixin(m));
75
- if (displayLabel)
76
- newClass.setDisplayLabel(displayLabel);
77
- return { itemKey: newClass.key };
78
- }
79
- /**
80
- * Creates an EntityClass through an EntityClassProps.
81
- * @param schemaKey a SchemaKey of the Schema that will house the new object.
82
- * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
83
- */
84
- async createFromProps(schemaKey, entityProps) {
85
- const schema = await this._schemaEditor.getSchema(schemaKey);
86
- if (schema === undefined)
87
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
88
- if (entityProps.name === undefined)
89
- return { errorMessage: `No name was supplied within props.` };
90
- const newClass = (await schema.createEntityClass(entityProps.name));
91
- if (newClass === undefined)
92
- return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
93
- await newClass.fromJSON(entityProps);
94
- return { itemKey: newClass.key };
95
- }
96
- async addMixin(entityKey, mixinKey) {
97
- const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
98
- const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey));
99
- // TODO: have a helpful returns
100
- if (!entity || entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
101
- return;
102
- if (!mixin || mixin.schemaItemType !== ecschema_metadata_1.SchemaItemType.Mixin)
103
- return;
104
- entity.addMixin(mixin);
105
- }
106
- async createNavigationProperty(entityKey, name, relationship, direction) {
107
- const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
108
- if (entity === undefined)
109
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
110
- if (entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
111
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);
112
- await entity.createNavigationProperty(name, relationship, direction);
113
- return { itemKey: entityKey, propertyName: name };
114
- }
115
- }
116
- exports.Entities = Entities;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Editing
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Entities = void 0;
11
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
+ const ECClasses_1 = require("./ECClasses");
13
+ /**
14
+ * @alpha
15
+ * A class extending ECClasses allowing you to create schema items of type EntityClass.
16
+ */
17
+ class Entities extends ECClasses_1.ECClasses {
18
+ constructor(_schemaEditor) {
19
+ super(_schemaEditor);
20
+ }
21
+ async createElement(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
22
+ const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
23
+ if (!baseClass)
24
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
25
+ if ((baseClass === null || baseClass === void 0 ? void 0 : baseClass.schemaItemType) !== ecschema_metadata_1.SchemaItemType.EntityClass)
26
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
27
+ if (!(await baseClass.is("Element", "BisCore"))) {
28
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);
29
+ }
30
+ return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
31
+ }
32
+ async createElementUniqueAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
33
+ const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
34
+ if (!baseClass)
35
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
36
+ if ((baseClass === null || baseClass === void 0 ? void 0 : baseClass.schemaItemType) !== ecschema_metadata_1.SchemaItemType.EntityClass)
37
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
38
+ if (!(await baseClass.is("ElementUniqueAspect", "BisCore"))) {
39
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);
40
+ }
41
+ return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
42
+ }
43
+ async createElementMultiAspect(schemaKey, name, modifier, baseClassKey, displayLabel, mixins) {
44
+ const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);
45
+ if (!baseClass)
46
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);
47
+ if ((baseClass === null || baseClass === void 0 ? void 0 : baseClass.schemaItemType) !== ecschema_metadata_1.SchemaItemType.EntityClass)
48
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);
49
+ if (!(await baseClass.is("ElementMultiAspect", "BisCore"))) {
50
+ throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);
51
+ }
52
+ return this.create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins);
53
+ }
54
+ async create(schemaKey, name, modifier, displayLabel, baseClassKey, mixins) {
55
+ const schema = await this._schemaEditor.getSchema(schemaKey);
56
+ if (schema === undefined)
57
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
58
+ const newClass = (await schema.createEntityClass(name, modifier));
59
+ if (newClass === undefined)
60
+ return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
61
+ // Add a deserializing method.
62
+ if (baseClassKey !== undefined) {
63
+ let baseClassSchema = schema;
64
+ if (!baseClassKey.schemaKey.matches(schema.schemaKey))
65
+ baseClassSchema = await this._schemaEditor.getSchema(baseClassKey.schemaKey);
66
+ const baseClassItem = await baseClassSchema.lookupItem(baseClassKey);
67
+ if (baseClassItem === undefined)
68
+ return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };
69
+ if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
70
+ return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
71
+ newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClassKey, async () => baseClassItem);
72
+ }
73
+ if (mixins !== undefined)
74
+ mixins.forEach((m) => newClass.addMixin(m));
75
+ if (displayLabel)
76
+ newClass.setDisplayLabel(displayLabel);
77
+ return { itemKey: newClass.key };
78
+ }
79
+ /**
80
+ * Creates an EntityClass through an EntityClassProps.
81
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
82
+ * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
83
+ */
84
+ async createFromProps(schemaKey, entityProps) {
85
+ const schema = await this._schemaEditor.getSchema(schemaKey);
86
+ if (schema === undefined)
87
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
88
+ if (entityProps.name === undefined)
89
+ return { errorMessage: `No name was supplied within props.` };
90
+ const newClass = (await schema.createEntityClass(entityProps.name));
91
+ if (newClass === undefined)
92
+ return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
93
+ await newClass.fromJSON(entityProps);
94
+ return { itemKey: newClass.key };
95
+ }
96
+ async addMixin(entityKey, mixinKey) {
97
+ const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
98
+ const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey));
99
+ // TODO: have a helpful returns
100
+ if (!entity || entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
101
+ return;
102
+ if (!mixin || mixin.schemaItemType !== ecschema_metadata_1.SchemaItemType.Mixin)
103
+ return;
104
+ entity.addMixin(mixin);
105
+ }
106
+ async createNavigationProperty(entityKey, name, relationship, direction) {
107
+ const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
108
+ if (entity === undefined)
109
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
110
+ if (entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
111
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);
112
+ await entity.createNavigationProperty(name, relationship, direction);
113
+ return { itemKey: entityKey, propertyName: name };
114
+ }
115
+ }
116
+ exports.Entities = Entities;
117
117
  //# sourceMappingURL=Entities.js.map
@@ -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;AAGxC;;;GAGG;AACH,MAAa,QAAS,SAAQ,qBAAS;IACrC,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAEM,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,kBAAkB,CAAC,CAAC;QAEtI,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,cAAc,MAAK,kCAAc,CAAC,WAAW;YAC1D,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,0DAA0D,YAAY,CAAC,QAAQ,yBAAyB,CAAC,CAAC;QAE7I,IAAI,CAAC,CAAC,MAAO,SAAyB,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE;YAChE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,0DAA0D,YAAY,CAAC,QAAQ,qBAAqB,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AI,MAAM,CAAC,cAAc,KAAK,kCAAc,CAAC,WAAW;YACtD,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,YAAY,SAAS,CAAC,QAAQ,8BAA8B,CAAC,CAAC;QAEhI,MAAM,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QACrE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;CACF;AAnID,4BAmIC","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 DelayedPromiseWithProps, ECClassModifier, ECObjectsError, ECObjectsStatus, EntityClass, EntityClassProps,\n Mixin, RelationshipClass, SchemaItemKey, SchemaItemType, SchemaKey, StrengthDirection,\n} from \"@itwin/ecschema-metadata\";\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { ECClasses } from \"./ECClasses\";\nimport { MutableEntityClass } from \"./Mutable/MutableEntityClass\";\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(_schemaEditor);\n }\n\n public async createElement(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, baseClassKey: SchemaItemKey, displayLabel?: string, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\n if (!baseClass)\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);\n\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\n\n if (!(await (baseClass as EntityClass).is(\"Element\", \"BisCore\"))) {\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an Element.`);\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<SchemaItemEditResults> {\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\n if (!baseClass)\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);\n\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\n\n if (!(await (baseClass as EntityClass).is(\"ElementUniqueAspect\", \"BisCore\"))) {\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementUniqueAspect.`);\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<SchemaItemEditResults> {\n const baseClass = await this._schemaEditor.schemaContext.getSchemaItem(baseClassKey);\n if (!baseClass)\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} could be found.`);\n\n if (baseClass?.schemaItemType !== SchemaItemType.EntityClass)\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an EntityClass.`);\n\n if (!(await (baseClass as EntityClass).is(\"ElementMultiAspect\", \"BisCore\"))) {\n throw new Error(`The class ${name} could not be created because the specified base class ${baseClassKey.fullName} is not an ElementMultiAspect.`);\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<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n const newClass = (await schema.createEntityClass(name, modifier)) as MutableEntityClass;\n if (newClass === undefined)\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\n\n // Add a deserializing method.\n if (baseClassKey !== undefined) {\n let baseClassSchema = schema;\n if (!baseClassKey.schemaKey.matches(schema.schemaKey))\n baseClassSchema = await this._schemaEditor.getSchema(baseClassKey.schemaKey);\n\n const baseClassItem = await baseClassSchema.lookupItem<EntityClass>(baseClassKey);\n if (baseClassItem === undefined)\n return { errorMessage: `Unable to locate base class ${baseClassKey.fullName} in schema ${baseClassSchema.fullName}.` };\n\n if (baseClassItem.schemaItemType !== SchemaItemType.EntityClass)\n return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };\n\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(baseClassKey, async () => baseClassItem);\n }\n\n if (mixins !== undefined)\n mixins.forEach((m) => newClass.addMixin(m));\n\n if (displayLabel)\n newClass.setDisplayLabel(displayLabel);\n\n return { itemKey: newClass.key };\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<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (entityProps.name === undefined)\n return { errorMessage: `No name was supplied within props.` };\n\n const newClass = (await schema.createEntityClass(entityProps.name)) as MutableEntityClass;\n if (newClass === undefined)\n return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };\n\n await newClass.fromJSON(entityProps);\n\n return { itemKey: newClass.key };\n }\n public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void> {\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\n const mixin = (await this._schemaEditor.schemaContext.getSchemaItem<Mixin>(mixinKey));\n\n // TODO: have a helpful returns\n if (!entity || entity.schemaItemType !== SchemaItemType.EntityClass)\n return;\n\n if (!mixin || mixin.schemaItemType !== SchemaItemType.Mixin)\n return;\n\n entity.addMixin(mixin);\n }\n\n public async createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults> {\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\n\n if (entity === undefined)\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);\n\n if (entity.schemaItemType !== SchemaItemType.EntityClass)\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);\n\n await entity.createNavigationProperty(name, relationship, direction);\n return { itemKey: entityKey, propertyName: name };\n }\n}\n\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;AAGxC;;;GAGG;AACH,MAAa,QAAS,SAAQ,qBAAS;IACrC,YAAmB,aAAkC;QACnD,KAAK,CAAC,aAAa,CAAC,CAAC;IACvB,CAAC;IAEM,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,IAA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,OAAO;QAET,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,SAAwB,EAAE,IAAY,EAAE,YAAwC,EAAE,SAAqC;QAC3J,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,aAAa,CAAqB,SAAS,CAAC,CAAC,CAAC;QAErG,IAAI,MAAM,KAAK,SAAS;YACtB,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,aAAa,EAAE,gBAAgB,SAAS,CAAC,QAAQ,+BAA+B,CAAC,CAAC;QAE7H,IAAI,MAAM,CAAC,cAAc,KAAK,kCAAc,CAAC,WAAW;YACtD,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,YAAY,SAAS,CAAC,QAAQ,8BAA8B,CAAC,CAAC;QAEhI,MAAM,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;QACrE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACpD,CAAC;CACF;AAnID,4BAmIC","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, 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\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(_schemaEditor);\r\n }\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 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 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 let baseClassSchema = schema;\r\n if (!baseClassKey.schemaKey.matches(schema.schemaKey))\r\n baseClassSchema = await this._schemaEditor.getSchema(baseClassKey.schemaKey);\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 public async addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void> {\r\n const entity = (await this._schemaEditor.schemaContext.getSchemaItem<MutableEntityClass>(entityKey));\r\n const mixin = (await this._schemaEditor.schemaContext.getSchemaItem<Mixin>(mixinKey));\r\n\r\n // TODO: have a helpful returns\r\n if (!entity || entity.schemaItemType !== SchemaItemType.EntityClass)\r\n return;\r\n\r\n if (!mixin || mixin.schemaItemType !== SchemaItemType.Mixin)\r\n return;\r\n\r\n entity.addMixin(mixin);\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"]}
@@ -1,22 +1,22 @@
1
- /** @packageDocumentation
2
- * @module Editing
3
- */
4
- import { AnyEnumerator, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
5
- import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
- /**
7
- * @alpha
8
- * A class allowing you to create schema items of type Enumeration.
9
- */
10
- export declare class Enumerations {
11
- protected _schemaEditor: SchemaContextEditor;
12
- constructor(_schemaEditor: SchemaContextEditor);
13
- create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults>;
14
- /**
15
- * Creates an Enumeration through an EnumeratorProps.
16
- * @param schemaKey a SchemaKey of the Schema that will house the new object.
17
- * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
18
- */
19
- createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemEditResults>;
20
- addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void>;
21
- }
1
+ /** @packageDocumentation
2
+ * @module Editing
3
+ */
4
+ import { AnyEnumerator, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
5
+ import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
+ /**
7
+ * @alpha
8
+ * A class allowing you to create schema items of type Enumeration.
9
+ */
10
+ export declare class Enumerations {
11
+ protected _schemaEditor: SchemaContextEditor;
12
+ constructor(_schemaEditor: SchemaContextEditor);
13
+ create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults>;
14
+ /**
15
+ * Creates an Enumeration through an EnumeratorProps.
16
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
17
+ * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
18
+ */
19
+ createFromProps(schemaKey: SchemaKey, enumProps: EnumerationProps): Promise<SchemaItemEditResults>;
20
+ addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void>;
21
+ }
22
22
  //# sourceMappingURL=Enumerations.d.ts.map
@@ -1,67 +1,67 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Editing
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.Enumerations = void 0;
11
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
- /**
13
- * @alpha
14
- * A class allowing you to create schema items of type Enumeration.
15
- */
16
- class Enumerations {
17
- constructor(_schemaEditor) {
18
- this._schemaEditor = _schemaEditor;
19
- }
20
- async create(schemaKey, name, type, displayLabel, isStrict, enumerators) {
21
- const schema = await this._schemaEditor.getSchema(schemaKey);
22
- if (schema === undefined)
23
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
24
- const newEnum = (await schema.createEnumeration(name, type));
25
- if (newEnum === undefined)
26
- return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
27
- if (undefined !== isStrict)
28
- newEnum.setIsStrict(isStrict);
29
- if (undefined !== enumerators)
30
- for (const enumerator of enumerators)
31
- await this.addEnumerator(newEnum.key, enumerator);
32
- if (displayLabel)
33
- newEnum.setDisplayLabel(displayLabel);
34
- return { itemKey: newEnum.key };
35
- }
36
- /**
37
- * Creates an Enumeration through an EnumeratorProps.
38
- * @param schemaKey a SchemaKey of the Schema that will house the new object.
39
- * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
40
- */
41
- async createFromProps(schemaKey, enumProps) {
42
- const schema = await this._schemaEditor.getSchema(schemaKey);
43
- if (schema === undefined)
44
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
45
- if (enumProps.name === undefined)
46
- return { errorMessage: `No name was supplied within props.` };
47
- const newEnum = (await schema.createEnumeration(enumProps.name));
48
- if (newEnum === undefined)
49
- return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };
50
- await newEnum.fromJSON(enumProps);
51
- return { itemKey: newEnum.key };
52
- }
53
- async addEnumerator(enumerationKey, enumerator) {
54
- const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem(enumerationKey));
55
- if (enumeration === undefined)
56
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);
57
- if (enumeration.schemaItemType !== ecschema_metadata_1.SchemaItemType.Enumeration)
58
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);
59
- if (enumeration.isInt && typeof (enumerator.value) !== "number")
60
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
61
- if (enumeration.isString && typeof (enumerator.value) !== "string")
62
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
63
- enumeration.addEnumerator(enumerator);
64
- }
65
- }
66
- exports.Enumerations = Enumerations;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Editing
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Enumerations = void 0;
11
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
12
+ /**
13
+ * @alpha
14
+ * A class allowing you to create schema items of type Enumeration.
15
+ */
16
+ class Enumerations {
17
+ constructor(_schemaEditor) {
18
+ this._schemaEditor = _schemaEditor;
19
+ }
20
+ async create(schemaKey, name, type, displayLabel, isStrict, enumerators) {
21
+ const schema = await this._schemaEditor.getSchema(schemaKey);
22
+ if (schema === undefined)
23
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
24
+ const newEnum = (await schema.createEnumeration(name, type));
25
+ if (newEnum === undefined)
26
+ return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
27
+ if (undefined !== isStrict)
28
+ newEnum.setIsStrict(isStrict);
29
+ if (undefined !== enumerators)
30
+ for (const enumerator of enumerators)
31
+ await this.addEnumerator(newEnum.key, enumerator);
32
+ if (displayLabel)
33
+ newEnum.setDisplayLabel(displayLabel);
34
+ return { itemKey: newEnum.key };
35
+ }
36
+ /**
37
+ * Creates an Enumeration through an EnumeratorProps.
38
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
39
+ * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
40
+ */
41
+ async createFromProps(schemaKey, enumProps) {
42
+ const schema = await this._schemaEditor.getSchema(schemaKey);
43
+ if (schema === undefined)
44
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
45
+ if (enumProps.name === undefined)
46
+ return { errorMessage: `No name was supplied within props.` };
47
+ const newEnum = (await schema.createEnumeration(enumProps.name));
48
+ if (newEnum === undefined)
49
+ return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };
50
+ await newEnum.fromJSON(enumProps);
51
+ return { itemKey: newEnum.key };
52
+ }
53
+ async addEnumerator(enumerationKey, enumerator) {
54
+ const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem(enumerationKey));
55
+ if (enumeration === undefined)
56
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);
57
+ if (enumeration.schemaItemType !== ecschema_metadata_1.SchemaItemType.Enumeration)
58
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);
59
+ if (enumeration.isInt && typeof (enumerator.value) !== "number")
60
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
61
+ if (enumeration.isString && typeof (enumerator.value) !== "string")
62
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);
63
+ enumeration.addEnumerator(enumerator);
64
+ }
65
+ }
66
+ exports.Enumerations = Enumerations;
67
67
  //# sourceMappingURL=Enumerations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Enumerations.js","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkL;AAIlL;;;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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CAAC,IAAI,aAAa,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAExL,WAAkC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC;CACF;AA/DD,oCA+DC","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, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationProps, PrimitiveType, SchemaItemKey, SchemaItemType, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { MutableEnumeration } from \"./Mutable/MutableEnumeration\";\n\n/**\n * @alpha\n * A class allowing you to create schema items of type Enumeration.\n */\nexport class Enumerations {\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\n\n public async create(schemaKey: SchemaKey, name: string, type: PrimitiveType.Integer | PrimitiveType.String, displayLabel?: string, isStrict?: boolean, enumerators?: AnyEnumerator[]): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n const newEnum = (await schema.createEnumeration(name, type));\n if (newEnum === undefined)\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\n\n if (undefined !== isStrict)\n (newEnum as MutableEnumeration).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 as MutableEnumeration).setDisplayLabel(displayLabel);\n\n return { itemKey: newEnum.key };\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<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (enumProps.name === undefined)\n return { errorMessage: `No name was supplied within props.` };\n\n const newEnum = (await schema.createEnumeration(enumProps.name));\n if (newEnum === undefined)\n return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };\n\n await newEnum.fromJSON(enumProps);\n return { itemKey: newEnum.key };\n }\n\n public async addEnumerator(enumerationKey: SchemaItemKey, enumerator: AnyEnumerator): Promise<void> {\n const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem<Enumeration>(enumerationKey));\n\n if (enumeration === undefined)\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Unable to locate Enumeration class ${enumerationKey.fullName}.`);\n\n if (enumeration.schemaItemType !== SchemaItemType.Enumeration)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `${enumeration.fullName} is not of type Enumerator class.`);\n\n if (enumeration.isInt && typeof (enumerator.value) !== \"number\")\n throw new ECObjectsError(ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);\n\n if (enumeration.isString && typeof (enumerator.value) !== \"string\")\n throw new ECObjectsError(ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type ${typeof (enumerator.value)}.`);\n\n (enumeration as MutableEnumeration).addEnumerator(enumerator);\n }\n}\n"]}
1
+ {"version":3,"file":"Enumerations.js","sourceRoot":"","sources":["../../../src/Editing/Enumerations.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAkL;AAIlL;;;GAGG;AACH,MAAa,YAAY;IACvB,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAE7D,KAAK,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,IAAI,kCAAc,CAAC,mCAAe,CAAC,oBAAoB,EAAE,mBAAmB,WAAW,CAAC,IAAI,2BAA2B,UAAU,CAAC,IAAI,aAAa,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAExL,WAAkC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC;CACF;AA/DD,oCA+DC","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\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"]}
@@ -1,22 +1,22 @@
1
- /** @packageDocumentation
2
- * @module Editing
3
- */
4
- import { FormatProps, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
5
- import { FormatType } from "@itwin/core-quantity";
6
- import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
7
- /**
8
- * @alpha
9
- * A class allowing you to create schema items of type Format.
10
- */
11
- export declare class Formats {
12
- protected _schemaEditor: SchemaContextEditor;
13
- constructor(_schemaEditor: SchemaContextEditor);
14
- create(schemaKey: SchemaKey, name: string, formatType: FormatType, displayLabel?: string, units?: SchemaItemKey[]): Promise<SchemaItemEditResults>;
15
- /**
16
- * Creates a format through a FormatProps.
17
- * @param schemaKey a SchemaKey of the Schema that will house the new object.
18
- * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
19
- */
20
- createFromProps(schemaKey: SchemaKey, formatProps: FormatProps): Promise<SchemaItemEditResults>;
21
- }
1
+ /** @packageDocumentation
2
+ * @module Editing
3
+ */
4
+ import { FormatProps, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
5
+ import { FormatType } from "@itwin/core-quantity";
6
+ import { SchemaContextEditor, SchemaItemEditResults } from "./Editor";
7
+ /**
8
+ * @alpha
9
+ * A class allowing you to create schema items of type Format.
10
+ */
11
+ export declare class Formats {
12
+ protected _schemaEditor: SchemaContextEditor;
13
+ constructor(_schemaEditor: SchemaContextEditor);
14
+ create(schemaKey: SchemaKey, name: string, formatType: FormatType, displayLabel?: string, units?: SchemaItemKey[]): Promise<SchemaItemEditResults>;
15
+ /**
16
+ * Creates a format through a FormatProps.
17
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
18
+ * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
19
+ */
20
+ createFromProps(schemaKey: SchemaKey, formatProps: FormatProps): Promise<SchemaItemEditResults>;
21
+ }
22
22
  //# sourceMappingURL=Formats.d.ts.map