@itwin/ecschema-editing 3.0.0-dev.72

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 (197) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +11 -0
  4. package/lib/Editing/Constants.d.ts +21 -0
  5. package/lib/Editing/Constants.d.ts.map +1 -0
  6. package/lib/Editing/Constants.js +65 -0
  7. package/lib/Editing/Constants.js.map +1 -0
  8. package/lib/Editing/CustomAttributes.d.ts +21 -0
  9. package/lib/Editing/CustomAttributes.d.ts.map +1 -0
  10. package/lib/Editing/CustomAttributes.js +59 -0
  11. package/lib/Editing/CustomAttributes.js.map +1 -0
  12. package/lib/Editing/ECClasses.d.ts +33 -0
  13. package/lib/Editing/ECClasses.d.ts.map +1 -0
  14. package/lib/Editing/ECClasses.js +186 -0
  15. package/lib/Editing/ECClasses.js.map +1 -0
  16. package/lib/Editing/Editor.d.ts +105 -0
  17. package/lib/Editing/Editor.d.ts.map +1 -0
  18. package/lib/Editing/Editor.js +175 -0
  19. package/lib/Editing/Editor.js.map +1 -0
  20. package/lib/Editing/Entities.d.ts +23 -0
  21. package/lib/Editing/Entities.d.ts.map +1 -0
  22. package/lib/Editing/Entities.js +89 -0
  23. package/lib/Editing/Entities.js.map +1 -0
  24. package/lib/Editing/Enumerations.d.ts +22 -0
  25. package/lib/Editing/Enumerations.d.ts.map +1 -0
  26. package/lib/Editing/Enumerations.js +71 -0
  27. package/lib/Editing/Enumerations.js.map +1 -0
  28. package/lib/Editing/Formats.d.ts +21 -0
  29. package/lib/Editing/Formats.d.ts.map +1 -0
  30. package/lib/Editing/Formats.js +61 -0
  31. package/lib/Editing/Formats.js.map +1 -0
  32. package/lib/Editing/InvertedUnits.d.ts +18 -0
  33. package/lib/Editing/InvertedUnits.d.ts.map +1 -0
  34. package/lib/Editing/InvertedUnits.js +86 -0
  35. package/lib/Editing/InvertedUnits.js.map +1 -0
  36. package/lib/Editing/KindOfQuantities.d.ts +29 -0
  37. package/lib/Editing/KindOfQuantities.d.ts.map +1 -0
  38. package/lib/Editing/KindOfQuantities.js +80 -0
  39. package/lib/Editing/KindOfQuantities.js.map +1 -0
  40. package/lib/Editing/Mixins.d.ts +23 -0
  41. package/lib/Editing/Mixins.d.ts.map +1 -0
  42. package/lib/Editing/Mixins.js +89 -0
  43. package/lib/Editing/Mixins.js.map +1 -0
  44. package/lib/Editing/Mutable/MutableCAClass.d.ts +10 -0
  45. package/lib/Editing/Mutable/MutableCAClass.d.ts.map +1 -0
  46. package/lib/Editing/Mutable/MutableCAClass.js +16 -0
  47. package/lib/Editing/Mutable/MutableCAClass.js.map +1 -0
  48. package/lib/Editing/Mutable/MutableClass.d.ts +35 -0
  49. package/lib/Editing/Mutable/MutableClass.d.ts.map +1 -0
  50. package/lib/Editing/Mutable/MutableClass.js +23 -0
  51. package/lib/Editing/Mutable/MutableClass.js.map +1 -0
  52. package/lib/Editing/Mutable/MutableConstant.d.ts +13 -0
  53. package/lib/Editing/Mutable/MutableConstant.d.ts.map +1 -0
  54. package/lib/Editing/Mutable/MutableConstant.js +16 -0
  55. package/lib/Editing/Mutable/MutableConstant.js.map +1 -0
  56. package/lib/Editing/Mutable/MutableEntityClass.d.ts +16 -0
  57. package/lib/Editing/Mutable/MutableEntityClass.d.ts.map +1 -0
  58. package/lib/Editing/Mutable/MutableEntityClass.js +60 -0
  59. package/lib/Editing/Mutable/MutableEntityClass.js.map +1 -0
  60. package/lib/Editing/Mutable/MutableEnumeration.d.ts +10 -0
  61. package/lib/Editing/Mutable/MutableEnumeration.d.ts.map +1 -0
  62. package/lib/Editing/Mutable/MutableEnumeration.js +15 -0
  63. package/lib/Editing/Mutable/MutableEnumeration.js.map +1 -0
  64. package/lib/Editing/Mutable/MutableFormat.d.ts +18 -0
  65. package/lib/Editing/Mutable/MutableFormat.d.ts.map +1 -0
  66. package/lib/Editing/Mutable/MutableFormat.js +16 -0
  67. package/lib/Editing/Mutable/MutableFormat.js.map +1 -0
  68. package/lib/Editing/Mutable/MutableInvertedUnit.d.ts +11 -0
  69. package/lib/Editing/Mutable/MutableInvertedUnit.d.ts.map +1 -0
  70. package/lib/Editing/Mutable/MutableInvertedUnit.js +16 -0
  71. package/lib/Editing/Mutable/MutableInvertedUnit.js.map +1 -0
  72. package/lib/Editing/Mutable/MutableKindOfQuantity.d.ts +11 -0
  73. package/lib/Editing/Mutable/MutableKindOfQuantity.d.ts.map +1 -0
  74. package/lib/Editing/Mutable/MutableKindOfQuantity.js +16 -0
  75. package/lib/Editing/Mutable/MutableKindOfQuantity.js.map +1 -0
  76. package/lib/Editing/Mutable/MutableMixin.d.ts +12 -0
  77. package/lib/Editing/Mutable/MutableMixin.d.ts.map +1 -0
  78. package/lib/Editing/Mutable/MutableMixin.js +16 -0
  79. package/lib/Editing/Mutable/MutableMixin.js.map +1 -0
  80. package/lib/Editing/Mutable/MutablePhenomenon.d.ts +10 -0
  81. package/lib/Editing/Mutable/MutablePhenomenon.d.ts.map +1 -0
  82. package/lib/Editing/Mutable/MutablePhenomenon.js +16 -0
  83. package/lib/Editing/Mutable/MutablePhenomenon.js.map +1 -0
  84. package/lib/Editing/Mutable/MutableProperty.d.ts +9 -0
  85. package/lib/Editing/Mutable/MutableProperty.d.ts.map +1 -0
  86. package/lib/Editing/Mutable/MutableProperty.js +16 -0
  87. package/lib/Editing/Mutable/MutableProperty.js.map +1 -0
  88. package/lib/Editing/Mutable/MutablePropertyCategory.d.ts +10 -0
  89. package/lib/Editing/Mutable/MutablePropertyCategory.d.ts.map +1 -0
  90. package/lib/Editing/Mutable/MutablePropertyCategory.js +16 -0
  91. package/lib/Editing/Mutable/MutablePropertyCategory.js.map +1 -0
  92. package/lib/Editing/Mutable/MutableRelationshipClass.d.ts +22 -0
  93. package/lib/Editing/Mutable/MutableRelationshipClass.d.ts.map +1 -0
  94. package/lib/Editing/Mutable/MutableRelationshipClass.js +25 -0
  95. package/lib/Editing/Mutable/MutableRelationshipClass.js.map +1 -0
  96. package/lib/Editing/Mutable/MutableSchema.d.ts +46 -0
  97. package/lib/Editing/Mutable/MutableSchema.d.ts.map +1 -0
  98. package/lib/Editing/Mutable/MutableSchema.js +18 -0
  99. package/lib/Editing/Mutable/MutableSchema.js.map +1 -0
  100. package/lib/Editing/Mutable/MutableUnit.d.ts +12 -0
  101. package/lib/Editing/Mutable/MutableUnit.d.ts.map +1 -0
  102. package/lib/Editing/Mutable/MutableUnit.js +16 -0
  103. package/lib/Editing/Mutable/MutableUnit.js.map +1 -0
  104. package/lib/Editing/Mutable/MutableUnitSystem.d.ts +9 -0
  105. package/lib/Editing/Mutable/MutableUnitSystem.d.ts.map +1 -0
  106. package/lib/Editing/Mutable/MutableUnitSystem.js +16 -0
  107. package/lib/Editing/Mutable/MutableUnitSystem.js.map +1 -0
  108. package/lib/Editing/Phenomena.d.ts +16 -0
  109. package/lib/Editing/Phenomena.d.ts.map +1 -0
  110. package/lib/Editing/Phenomena.js +48 -0
  111. package/lib/Editing/Phenomena.js.map +1 -0
  112. package/lib/Editing/PropertyCategories.d.ts +17 -0
  113. package/lib/Editing/PropertyCategories.d.ts.map +1 -0
  114. package/lib/Editing/PropertyCategories.js +54 -0
  115. package/lib/Editing/PropertyCategories.js.map +1 -0
  116. package/lib/Editing/RelationshipClasses.d.ts +22 -0
  117. package/lib/Editing/RelationshipClasses.d.ts.map +1 -0
  118. package/lib/Editing/RelationshipClasses.js +70 -0
  119. package/lib/Editing/RelationshipClasses.js.map +1 -0
  120. package/lib/Editing/Structs.d.ts +20 -0
  121. package/lib/Editing/Structs.d.ts.map +1 -0
  122. package/lib/Editing/Structs.js +57 -0
  123. package/lib/Editing/Structs.js.map +1 -0
  124. package/lib/Editing/UnitSystems.d.ts +16 -0
  125. package/lib/Editing/UnitSystems.d.ts.map +1 -0
  126. package/lib/Editing/UnitSystems.js +44 -0
  127. package/lib/Editing/UnitSystems.js.map +1 -0
  128. package/lib/Editing/Units.d.ts +16 -0
  129. package/lib/Editing/Units.d.ts.map +1 -0
  130. package/lib/Editing/Units.js +62 -0
  131. package/lib/Editing/Units.js.map +1 -0
  132. package/lib/Validation/Diagnostic.d.ts +322 -0
  133. package/lib/Validation/Diagnostic.d.ts.map +1 -0
  134. package/lib/Validation/Diagnostic.js +311 -0
  135. package/lib/Validation/Diagnostic.js.map +1 -0
  136. package/lib/Validation/DiagnosticReporter.d.ts +97 -0
  137. package/lib/Validation/DiagnosticReporter.d.ts.map +1 -0
  138. package/lib/Validation/DiagnosticReporter.js +107 -0
  139. package/lib/Validation/DiagnosticReporter.js.map +1 -0
  140. package/lib/Validation/ECRules.d.ts +439 -0
  141. package/lib/Validation/ECRules.d.ts.map +1 -0
  142. package/lib/Validation/ECRules.js +679 -0
  143. package/lib/Validation/ECRules.js.map +1 -0
  144. package/lib/Validation/LoggingDiagnosticReporter.d.ts +14 -0
  145. package/lib/Validation/LoggingDiagnosticReporter.d.ts.map +1 -0
  146. package/lib/Validation/LoggingDiagnosticReporter.js +41 -0
  147. package/lib/Validation/LoggingDiagnosticReporter.js.map +1 -0
  148. package/lib/Validation/RuleSuppressionSet.d.ts +59 -0
  149. package/lib/Validation/RuleSuppressionSet.d.ts.map +1 -0
  150. package/lib/Validation/RuleSuppressionSet.js +10 -0
  151. package/lib/Validation/RuleSuppressionSet.js.map +1 -0
  152. package/lib/Validation/Rules.d.ts +65 -0
  153. package/lib/Validation/Rules.d.ts.map +1 -0
  154. package/lib/Validation/Rules.js +10 -0
  155. package/lib/Validation/Rules.js.map +1 -0
  156. package/lib/Validation/SchemaChanges.d.ts +608 -0
  157. package/lib/Validation/SchemaChanges.d.ts.map +1 -0
  158. package/lib/Validation/SchemaChanges.js +1136 -0
  159. package/lib/Validation/SchemaChanges.js.map +1 -0
  160. package/lib/Validation/SchemaCompareDiagnostics.d.ts +423 -0
  161. package/lib/Validation/SchemaCompareDiagnostics.d.ts.map +1 -0
  162. package/lib/Validation/SchemaCompareDiagnostics.js +112 -0
  163. package/lib/Validation/SchemaCompareDiagnostics.js.map +1 -0
  164. package/lib/Validation/SchemaCompareReporter.d.ts +12 -0
  165. package/lib/Validation/SchemaCompareReporter.d.ts.map +1 -0
  166. package/lib/Validation/SchemaCompareReporter.js +10 -0
  167. package/lib/Validation/SchemaCompareReporter.js.map +1 -0
  168. package/lib/Validation/SchemaCompareResultDelegate.d.ts +237 -0
  169. package/lib/Validation/SchemaCompareResultDelegate.d.ts.map +1 -0
  170. package/lib/Validation/SchemaCompareResultDelegate.js +349 -0
  171. package/lib/Validation/SchemaCompareResultDelegate.js.map +1 -0
  172. package/lib/Validation/SchemaCompareVisitor.d.ts +120 -0
  173. package/lib/Validation/SchemaCompareVisitor.d.ts.map +1 -0
  174. package/lib/Validation/SchemaCompareVisitor.js +207 -0
  175. package/lib/Validation/SchemaCompareVisitor.js.map +1 -0
  176. package/lib/Validation/SchemaComparer.d.ts +172 -0
  177. package/lib/Validation/SchemaComparer.d.ts.map +1 -0
  178. package/lib/Validation/SchemaComparer.js +666 -0
  179. package/lib/Validation/SchemaComparer.js.map +1 -0
  180. package/lib/Validation/SchemaValidater.d.ts +20 -0
  181. package/lib/Validation/SchemaValidater.d.ts.map +1 -0
  182. package/lib/Validation/SchemaValidater.js +62 -0
  183. package/lib/Validation/SchemaValidater.js.map +1 -0
  184. package/lib/Validation/SchemaValidationVisitor.d.ts +171 -0
  185. package/lib/Validation/SchemaValidationVisitor.d.ts.map +1 -0
  186. package/lib/Validation/SchemaValidationVisitor.js +729 -0
  187. package/lib/Validation/SchemaValidationVisitor.js.map +1 -0
  188. package/lib/Validation/SchemaWalker.d.ts +23 -0
  189. package/lib/Validation/SchemaWalker.d.ts.map +1 -0
  190. package/lib/Validation/SchemaWalker.js +52 -0
  191. package/lib/Validation/SchemaWalker.js.map +1 -0
  192. package/lib/ecschema-editing.d.ts +34 -0
  193. package/lib/ecschema-editing.d.ts.map +1 -0
  194. package/lib/ecschema-editing.js +55 -0
  195. package/lib/ecschema-editing.js.map +1 -0
  196. package/package.json +85 -0
  197. package/public/locales/en/ECSchemaEditing.json +27 -0
@@ -0,0 +1,105 @@
1
+ /** @packageDocumentation
2
+ * @module Editing
3
+ */
4
+ import { CustomAttribute, Schema, SchemaContext, SchemaItemKey, SchemaKey } from "@itwin/ecschema-metadata";
5
+ import { MutableSchema } from "./Mutable/MutableSchema";
6
+ import { Constants } from "./Constants";
7
+ import { CustomAttributes } from "./CustomAttributes";
8
+ import { Entities } from "./Entities";
9
+ import { Enumerations } from "./Enumerations";
10
+ import { Formats } from "./Formats";
11
+ import { InvertedUnits } from "./InvertedUnits";
12
+ import { KindOfQuantities } from "./KindOfQuantities";
13
+ import { Mixins } from "./Mixins";
14
+ import { Phenomena } from "./Phenomena";
15
+ import { PropertyCategories } from "./PropertyCategories";
16
+ import { RelationshipClasses } from "./RelationshipClasses";
17
+ import { Structs } from "./Structs";
18
+ import { Units } from "./Units";
19
+ import { UnitSystems } from "./UnitSystems";
20
+ /**
21
+ * @alpha
22
+ */
23
+ export interface SchemaEditResults {
24
+ schemaKey?: SchemaKey;
25
+ errorMessage?: string;
26
+ }
27
+ /**
28
+ * @alpha
29
+ */
30
+ export interface SchemaItemEditResults {
31
+ itemKey?: SchemaItemKey;
32
+ errorMessage?: string;
33
+ }
34
+ /**
35
+ * @alpha
36
+ */
37
+ export interface PropertyEditResults {
38
+ itemKey?: SchemaItemKey;
39
+ propertyName?: string;
40
+ errorMessage?: string;
41
+ }
42
+ /**
43
+ * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.
44
+ * @alpha
45
+ */
46
+ export declare class SchemaContextEditor {
47
+ private _schemaContext;
48
+ readonly entities: Entities;
49
+ readonly mixins: Mixins;
50
+ readonly structs: Structs;
51
+ readonly customAttributes: CustomAttributes;
52
+ readonly relationships: RelationshipClasses;
53
+ readonly constants: Constants;
54
+ readonly enumerations: Enumerations;
55
+ readonly formats: Formats;
56
+ readonly kindOfQuantities: KindOfQuantities;
57
+ readonly units: Units;
58
+ readonly phenomenons: Phenomena;
59
+ readonly unitSystems: UnitSystems;
60
+ readonly propertyCategories: PropertyCategories;
61
+ readonly invertedUnits: InvertedUnits;
62
+ /**
63
+ * Creates a new SchemaContextEditor instance.
64
+ * @param schemaContext The SchemaContext the Editor will use to edit in.
65
+ */
66
+ constructor(schemaContext: SchemaContext);
67
+ /** Allows you to get schema classes and items through regular SchemaContext methods. */
68
+ get schemaContext(): SchemaContext;
69
+ finish(): Promise<SchemaContext>;
70
+ /**
71
+ * Helper method for retrieving a schema, previously addeded, from the SchemaContext.
72
+ * @param schemaKey The SchemaKey identifying the schema.
73
+ */
74
+ getSchema(schemaKey: SchemaKey): Promise<MutableSchema>;
75
+ /**
76
+ * Creates a Schema with the given properties and adds it to the current schema context.
77
+ * @param name The name given to the new schema.
78
+ * @param alias The alias of the new schema.
79
+ * @param readVersion The read version number of the schema.
80
+ * @param writeVersion The write version number of the schema.
81
+ * @param minorVersion The minor version number of the schema.
82
+ * @returns Resolves to a SchemaEditResults object.
83
+ */
84
+ createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaEditResults>;
85
+ /**
86
+ * Adds a referenced schema to the schema identified by the given SchemaKey.
87
+ * @param schemaKey The SchemaKey identifying the schema.
88
+ * @param refSchema The referenced schema to add.
89
+ */
90
+ addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<SchemaEditResults>;
91
+ /**
92
+ * Adds a CustomAttribute instance to the schema identified by the given SchemaKey
93
+ * @param schemaKey The SchemaKey identifying the schema.
94
+ * @param customAttribute The CustomAttribute instance to add.
95
+ */
96
+ addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<SchemaEditResults>;
97
+ /**
98
+ * Increments the minor version of a schema.
99
+ * @param schemaKey The SchemaKey identifying the schema.
100
+ */
101
+ incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults>;
102
+ private removeReference;
103
+ private removeCustomAttribute;
104
+ }
105
+ //# sourceMappingURL=Editor.d.ts.map
@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SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQpF,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,qBAAqB;CAK9B"}
@@ -0,0 +1,175 @@
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
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
10
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
11
+ var m = o[Symbol.asyncIterator], i;
12
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
13
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
14
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SchemaContextEditor = void 0;
18
+ const Rules = require("../Validation/ECRules");
19
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
20
+ const core_bentley_1 = require("@itwin/core-bentley");
21
+ const Constants_1 = require("./Constants");
22
+ const CustomAttributes_1 = require("./CustomAttributes");
23
+ const Entities_1 = require("./Entities");
24
+ const Enumerations_1 = require("./Enumerations");
25
+ const Formats_1 = require("./Formats");
26
+ const InvertedUnits_1 = require("./InvertedUnits");
27
+ const KindOfQuantities_1 = require("./KindOfQuantities");
28
+ const Mixins_1 = require("./Mixins");
29
+ const Phenomena_1 = require("./Phenomena");
30
+ const PropertyCategories_1 = require("./PropertyCategories");
31
+ const RelationshipClasses_1 = require("./RelationshipClasses");
32
+ const Structs_1 = require("./Structs");
33
+ const Units_1 = require("./Units");
34
+ const UnitSystems_1 = require("./UnitSystems");
35
+ /**
36
+ * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.
37
+ * @alpha
38
+ */
39
+ class SchemaContextEditor {
40
+ /**
41
+ * Creates a new SchemaContextEditor instance.
42
+ * @param schemaContext The SchemaContext the Editor will use to edit in.
43
+ */
44
+ constructor(schemaContext) {
45
+ this.entities = new Entities_1.Entities(this);
46
+ this.mixins = new Mixins_1.Mixins(this);
47
+ this.structs = new Structs_1.Structs(this);
48
+ this.customAttributes = new CustomAttributes_1.CustomAttributes(this);
49
+ this.relationships = new RelationshipClasses_1.RelationshipClasses(this);
50
+ this.constants = new Constants_1.Constants(this);
51
+ this.enumerations = new Enumerations_1.Enumerations(this);
52
+ this.formats = new Formats_1.Formats(this);
53
+ this.kindOfQuantities = new KindOfQuantities_1.KindOfQuantities(this);
54
+ this.units = new Units_1.Units(this);
55
+ this.phenomenons = new Phenomena_1.Phenomena(this);
56
+ this.unitSystems = new UnitSystems_1.UnitSystems(this);
57
+ this.propertyCategories = new PropertyCategories_1.PropertyCategories(this);
58
+ this.invertedUnits = new InvertedUnits_1.InvertedUnits(this);
59
+ // TODO: Make copy
60
+ this._schemaContext = schemaContext;
61
+ }
62
+ /** Allows you to get schema classes and items through regular SchemaContext methods. */
63
+ get schemaContext() { return this._schemaContext; }
64
+ async finish() {
65
+ return this._schemaContext;
66
+ }
67
+ /**
68
+ * Helper method for retrieving a schema, previously addeded, from the SchemaContext.
69
+ * @param schemaKey The SchemaKey identifying the schema.
70
+ */
71
+ async getSchema(schemaKey) {
72
+ return (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
73
+ }
74
+ /**
75
+ * Creates a Schema with the given properties and adds it to the current schema context.
76
+ * @param name The name given to the new schema.
77
+ * @param alias The alias of the new schema.
78
+ * @param readVersion The read version number of the schema.
79
+ * @param writeVersion The write version number of the schema.
80
+ * @param minorVersion The minor version number of the schema.
81
+ * @returns Resolves to a SchemaEditResults object.
82
+ */
83
+ async createSchema(name, alias, readVersion, writeVersion, minorVersion) {
84
+ const newSchema = new ecschema_metadata_1.Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);
85
+ await this._schemaContext.addSchema(newSchema);
86
+ return { schemaKey: newSchema.schemaKey };
87
+ }
88
+ /**
89
+ * Adds a referenced schema to the schema identified by the given SchemaKey.
90
+ * @param schemaKey The SchemaKey identifying the schema.
91
+ * @param refSchema The referenced schema to add.
92
+ */
93
+ async addSchemaReference(schemaKey, refSchema) {
94
+ var e_1, _a;
95
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Exact));
96
+ await schema.addReference(refSchema);
97
+ const diagnostics = Rules.validateSchemaReferences(schema);
98
+ const result = { errorMessage: "" };
99
+ try {
100
+ for (var diagnostics_1 = __asyncValues(diagnostics), diagnostics_1_1; diagnostics_1_1 = await diagnostics_1.next(), !diagnostics_1_1.done;) {
101
+ const diagnostic = diagnostics_1_1.value;
102
+ result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
103
+ }
104
+ }
105
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
106
+ finally {
107
+ try {
108
+ if (diagnostics_1_1 && !diagnostics_1_1.done && (_a = diagnostics_1.return)) await _a.call(diagnostics_1);
109
+ }
110
+ finally { if (e_1) throw e_1.error; }
111
+ }
112
+ if (result.errorMessage) {
113
+ this.removeReference(schema, refSchema);
114
+ return result;
115
+ }
116
+ if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {
117
+ await this.schemaContext.addSchema(refSchema);
118
+ }
119
+ return {};
120
+ }
121
+ /**
122
+ * Adds a CustomAttribute instance to the schema identified by the given SchemaKey
123
+ * @param schemaKey The SchemaKey identifying the schema.
124
+ * @param customAttribute The CustomAttribute instance to add.
125
+ */
126
+ async addCustomAttribute(schemaKey, customAttribute) {
127
+ var e_2, _a;
128
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
129
+ schema.addCustomAttribute(customAttribute);
130
+ const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);
131
+ const result = { errorMessage: "" };
132
+ try {
133
+ for (var diagnostics_2 = __asyncValues(diagnostics), diagnostics_2_1; diagnostics_2_1 = await diagnostics_2.next(), !diagnostics_2_1.done;) {
134
+ const diagnostic = diagnostics_2_1.value;
135
+ result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
136
+ }
137
+ }
138
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
139
+ finally {
140
+ try {
141
+ if (diagnostics_2_1 && !diagnostics_2_1.done && (_a = diagnostics_2.return)) await _a.call(diagnostics_2);
142
+ }
143
+ finally { if (e_2) throw e_2.error; }
144
+ }
145
+ if (result.errorMessage) {
146
+ this.removeCustomAttribute(schema, customAttribute);
147
+ return result;
148
+ }
149
+ return {};
150
+ }
151
+ /**
152
+ * Increments the minor version of a schema.
153
+ * @param schemaKey The SchemaKey identifying the schema.
154
+ */
155
+ async incrementMinorVersion(schemaKey) {
156
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
157
+ if (schema === undefined)
158
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
159
+ schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);
160
+ return {};
161
+ }
162
+ removeReference(schema, refSchema) {
163
+ const index = schema.references.indexOf(refSchema);
164
+ if (index !== -1) {
165
+ schema.references.splice(index, 1);
166
+ }
167
+ }
168
+ removeCustomAttribute(schema, customAttribute) {
169
+ (0, core_bentley_1.assert)(schema.customAttributes !== undefined);
170
+ const map = schema.customAttributes;
171
+ map.delete(customAttribute.className);
172
+ }
173
+ }
174
+ exports.SchemaContextEditor = SchemaContextEditor;
175
+ //# sourceMappingURL=Editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Editor.js","sourceRo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G,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,SAAS,EAAE,mCAAe,CAAC,MAAM,CAAC,CAAkB,CAAC;QAC9G,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEjH,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;QACpF,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,eAAe,CAAC,MAAc,EAAE,SAAiB;QACvD,MAAM,KAAK,GAAW,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YAChB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;SACpC;IACH,CAAC;IAEO,qBAAqB,CAAC,MAAc,EAAE,eAAgC;QAC5E,IAAA,qBAAM,EAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgD,CAAC;QACpE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;CACF;AAlID,kDAkIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Editing\n */\n\nimport * as Rules from \"../Validation/ECRules\";\n\nimport { CustomAttribute, Schema, SchemaContext, SchemaItemKey, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { Constants } from \"./Constants\";\nimport { CustomAttributes } from \"./CustomAttributes\";\nimport { Entities } from \"./Entities\";\nimport { Enumerations } from \"./Enumerations\";\nimport { Formats } from \"./Formats\";\nimport { InvertedUnits } from \"./InvertedUnits\";\nimport { KindOfQuantities } from \"./KindOfQuantities\";\nimport { Mixins } from \"./Mixins\";\nimport { Phenomena } from \"./Phenomena\";\nimport { PropertyCategories } from \"./PropertyCategories\";\nimport { RelationshipClasses } from \"./RelationshipClasses\";\nimport { Structs } from \"./Structs\";\nimport { Units } from \"./Units\";\nimport { UnitSystems } from \"./UnitSystems\";\n\n// We can either add validation in Editor, or in the protected methods of Schema.\n// TODO: Add an error code so we can do something programmatic with the error.\n/**\n * @alpha\n */\nexport interface SchemaEditResults {\n schemaKey?: SchemaKey;\n errorMessage?: string;\n}\n\n/**\n * @alpha\n */\nexport interface SchemaItemEditResults {\n itemKey?: SchemaItemKey;\n errorMessage?: string;\n}\n\n/**\n * @alpha\n */\nexport interface PropertyEditResults {\n itemKey?: SchemaItemKey;\n propertyName?: string;\n errorMessage?: string;\n}\n\n/**\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\n * @alpha\n */\nexport class SchemaContextEditor {\n private _schemaContext: SchemaContext;\n public readonly entities = new Entities(this);\n public readonly mixins = new Mixins(this);\n public readonly structs = new Structs(this);\n public readonly customAttributes = new CustomAttributes(this);\n public readonly relationships = new RelationshipClasses(this);\n public readonly constants = new Constants(this);\n public readonly enumerations = new Enumerations(this);\n public readonly formats = new Formats(this);\n public readonly kindOfQuantities = new KindOfQuantities(this);\n public readonly units = new Units(this);\n public readonly phenomenons = new Phenomena(this);\n public readonly unitSystems = new UnitSystems(this);\n public readonly propertyCategories = new PropertyCategories(this);\n public readonly invertedUnits = new InvertedUnits(this);\n\n /**\n * Creates a new SchemaContextEditor instance.\n * @param schemaContext The SchemaContext the Editor will use to edit in.\n */\n constructor(schemaContext: SchemaContext) {\n // TODO: Make copy\n this._schemaContext = schemaContext;\n }\n\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\n public get schemaContext(): SchemaContext { return this._schemaContext; }\n\n public async finish(): Promise<SchemaContext> {\n return this._schemaContext;\n }\n\n /**\n * Helper method for retrieving a schema, previously addeded, from the SchemaContext.\n * @param schemaKey The SchemaKey identifying the schema.\n */\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema> {\n return (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest)) as MutableSchema;\n }\n /**\n * Creates a Schema with the given properties and adds it to the current schema context.\n * @param name The name given to the new schema.\n * @param alias The alias of the new schema.\n * @param readVersion The read version number of the schema.\n * @param writeVersion The write version number of the schema.\n * @param minorVersion The minor version number of the schema.\n * @returns Resolves to a SchemaEditResults object.\n */\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaEditResults> {\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\n await this._schemaContext.addSchema(newSchema);\n return { schemaKey: newSchema.schemaKey };\n }\n\n /**\n * Adds a referenced schema to the schema identified by the given SchemaKey.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param refSchema The referenced schema to add.\n */\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<SchemaEditResults> {\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Exact)) as MutableSchema;\n await schema.addReference(refSchema);\n const diagnostics = Rules.validateSchemaReferences(schema);\n\n const result: SchemaEditResults = { errorMessage: \"\" };\n for await (const diagnostic of diagnostics) {\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\n }\n\n if (result.errorMessage) {\n this.removeReference(schema, refSchema);\n return result;\n }\n\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\n await this.schemaContext.addSchema(refSchema);\n }\n\n return {};\n }\n\n /**\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\n * @param schemaKey The SchemaKey identifying the schema.\n * @param customAttribute The CustomAttribute instance to add.\n */\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<SchemaEditResults> {\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest)) as MutableSchema;\n schema.addCustomAttribute(customAttribute);\n\n const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);\n\n const result: SchemaEditResults = { errorMessage: \"\" };\n for await (const diagnostic of diagnostics) {\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\n }\n\n if (result.errorMessage) {\n this.removeCustomAttribute(schema, customAttribute);\n return result;\n }\n\n return {};\n }\n\n /**\n * Increments the minor version of a schema.\n * @param schemaKey The SchemaKey identifying the schema.\n */\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults> {\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest)) as MutableSchema;\n if (schema === undefined) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\n return {};\n }\n\n private removeReference(schema: Schema, refSchema: Schema) {\n const index: number = schema.references.indexOf(refSchema);\n if (index !== -1) {\n schema.references.splice(index, 1);\n }\n }\n\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\n assert(schema.customAttributes !== undefined);\n const map = schema.customAttributes as Map<string, CustomAttribute>;\n map.delete(customAttribute.className);\n }\n}\n\n"]}
@@ -0,0 +1,23 @@
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
+ create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClass?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemEditResults>;
14
+ /**
15
+ * Creates an EntityClass through an EntityClassProps.
16
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
17
+ * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
18
+ */
19
+ createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemEditResults>;
20
+ addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void>;
21
+ createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults>;
22
+ }
23
+ //# sourceMappingURL=Entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../src/Editing/Entities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACoB,eAAe,EAAgD,gBAAgB,EACxG,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAkB,SAAS,EAAE,iBAAiB,EACtF,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC;;;GAGG;AACH,qBAAa,QAAS,SAAQ,SAAS;gBAClB,aAAa,EAAE,mBAAmB;IAGxC,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAyBtL;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAcpG,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAa1E,wBAAwB,CAAC,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAS7L"}
@@ -0,0 +1,89 @@
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 create(schemaKey, name, modifier, displayLabel, baseClass, mixins) {
22
+ const schema = await this._schemaEditor.getSchema(schemaKey);
23
+ if (schema === undefined)
24
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
25
+ const newClass = (await schema.createEntityClass(name, modifier));
26
+ if (newClass === undefined) {
27
+ return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };
28
+ }
29
+ // Add a deserializing method.
30
+ if (baseClass !== undefined) {
31
+ const baseClassItem = await schema.lookupItem(baseClass);
32
+ if (baseClassItem === undefined)
33
+ return { errorMessage: `Unable to locate base class ${baseClass.fullName} in schema ${schema.fullName}.` };
34
+ if (baseClassItem.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
35
+ return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };
36
+ newClass.baseClass = new ecschema_metadata_1.DelayedPromiseWithProps(baseClass, async () => baseClassItem);
37
+ }
38
+ if (mixins !== undefined) {
39
+ mixins.forEach((m) => newClass.addMixin(m));
40
+ }
41
+ if (displayLabel) {
42
+ newClass.setDisplayLabel(displayLabel);
43
+ }
44
+ return { itemKey: newClass.key };
45
+ }
46
+ /**
47
+ * Creates an EntityClass through an EntityClassProps.
48
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
49
+ * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
50
+ */
51
+ async createFromProps(schemaKey, entityProps) {
52
+ const schema = await this._schemaEditor.getSchema(schemaKey);
53
+ if (schema === undefined)
54
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
55
+ if (entityProps.name === undefined)
56
+ return { errorMessage: `No name was supplied within props.` };
57
+ const newClass = (await schema.createEntityClass(entityProps.name));
58
+ if (newClass === undefined) {
59
+ return { errorMessage: `Failed to create class ${entityProps.name} in schema ${schemaKey.toString(true)}.` };
60
+ }
61
+ await newClass.fromJSON(entityProps);
62
+ return { itemKey: newClass.key };
63
+ }
64
+ async addMixin(entityKey, mixinKey) {
65
+ const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
66
+ const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey));
67
+ // TODO: have a helpful returns
68
+ if (entity === undefined)
69
+ return;
70
+ if (mixin === undefined)
71
+ return;
72
+ if (entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
73
+ return;
74
+ if (mixin.schemaItemType !== ecschema_metadata_1.SchemaItemType.Mixin)
75
+ return;
76
+ entity.addMixin(mixin);
77
+ }
78
+ async createNavigationProperty(entityKey, name, relationship, direction) {
79
+ const entity = (await this._schemaEditor.schemaContext.getSchemaItem(entityKey));
80
+ if (entity === undefined)
81
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);
82
+ if (entity.schemaItemType !== ecschema_metadata_1.SchemaItemType.EntityClass)
83
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidSchemaItemType, `Expected ${entityKey.fullName} to be of type Entity Class.`);
84
+ await entity.createNavigationProperty(name, relationship, direction);
85
+ return { itemKey: entityKey, propertyName: name };
86
+ }
87
+ }
88
+ exports.Entities = Entities;
89
+ //# sourceMappingURL=Entities.js.map
@@ -0,0 +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;IACM,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,QAAyB,EAAE,YAAqB,EAAE,SAAyB,EAAE,MAAgB;QACnJ,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEjH,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAuB,CAAC;QACxF,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,OAAO,EAAE,YAAY,EAAE,0BAA0B,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;SAClG;QAED,8BAA8B;QAC9B,IAAI,SAAS,KAAK,SAAS,EAAE;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,WAAW;YAAE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,YAAY,SAAS,CAAC,QAAQ,8BAA8B,CAAC,CAAC;QAExL,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;AAtED,4BAsEC","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 public async create(schemaKey: SchemaKey, name: string, modifier: ECClassModifier, displayLabel?: string, baseClass?: SchemaItemKey, mixins?: Mixin[]): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined) 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\n // Add a deserializing method.\n if (baseClass !== undefined) {\n const baseClassItem = await schema.lookupItem(baseClass) as EntityClass;\n if (baseClassItem === undefined) return { errorMessage: `Unable to locate base class ${baseClass.fullName} in schema ${schema.fullName}.` };\n if (baseClassItem.schemaItemType !== SchemaItemType.EntityClass) return { errorMessage: `${baseClassItem.fullName} is not of type Entity Class.` };\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, EntityClass>(baseClass, async () => baseClassItem);\n }\n\n if (mixins !== undefined) {\n mixins.forEach((m) => newClass.addMixin(m));\n }\n if (displayLabel) { 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) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (entityProps.name === undefined) return { errorMessage: `No name was supplied within props.` };\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\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(entityKey)) as MutableEntityClass;\n const mixin = (await this._schemaEditor.schemaContext.getSchemaItem(mixinKey)) as Mixin;\n\n // TODO: have a helpful returns\n if (entity === undefined) return;\n if (mixin === undefined) return;\n if (entity.schemaItemType !== SchemaItemType.EntityClass) return;\n if (mixin.schemaItemType !== SchemaItemType.Mixin) 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(entityKey)) as MutableEntityClass;\n\n if (entity === undefined) throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Entity Class ${entityKey.fullName} not found in schema context.`);\n if (entity.schemaItemType !== SchemaItemType.EntityClass) 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"]}
@@ -0,0 +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
+ }
22
+ //# sourceMappingURL=Enumerations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Enumerations.d.ts","sourceRoot":"","sources":["../../src/Editing/Enumerations.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAmC,gBAAgB,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGtE;;;GAGG;AACH,qBAAa,YAAY;IACJ,SAAS,CAAC,aAAa,EAAE,mBAAmB;gBAAlC,aAAa,EAAE,mBAAmB;IAElD,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,qBAAqB,CAAC;IAsBrN;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAclG,aAAa,CAAC,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAapG"}
@@ -0,0 +1,71 @@
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
+ }
28
+ if (undefined !== isStrict) {
29
+ newEnum.setIsStrict(isStrict);
30
+ }
31
+ if (undefined !== enumerators) {
32
+ for (const enumerator of enumerators) {
33
+ await this.addEnumerator(newEnum.key, enumerator);
34
+ }
35
+ }
36
+ if (displayLabel) {
37
+ newEnum.setDisplayLabel(displayLabel);
38
+ }
39
+ return { itemKey: newEnum.key };
40
+ }
41
+ /**
42
+ * Creates an Enumeration through an EnumeratorProps.
43
+ * @param schemaKey a SchemaKey of the Schema that will house the new object.
44
+ * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.
45
+ */
46
+ async createFromProps(schemaKey, enumProps) {
47
+ const schema = await this._schemaEditor.getSchema(schemaKey);
48
+ if (schema === undefined)
49
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
50
+ if (enumProps.name === undefined)
51
+ return { errorMessage: `No name was supplied within props.` };
52
+ const newEnum = (await schema.createEnumeration(enumProps.name));
53
+ if (newEnum === undefined) {
54
+ return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };
55
+ }
56
+ await newEnum.fromJSON(enumProps);
57
+ return { itemKey: newEnum.key };
58
+ }
59
+ async addEnumerator(enumerationKey, enumerator) {
60
+ const enumeration = (await this._schemaEditor.schemaContext.getSchemaItem(enumerationKey));
61
+ if (enumeration.isInt && typeof (enumerator.value) === "string") {
62
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type string.`);
63
+ }
64
+ if (!enumeration.isInt && typeof (enumerator.value) === "number") {
65
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type integer.`);
66
+ }
67
+ enumeration.addEnumerator(enumerator);
68
+ }
69
+ }
70
+ exports.Enumerations = Enumerations;
71
+ //# sourceMappingURL=Enumerations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Enumerations.js","sourceRoot":"","sources":["../../src/Editing/Enumerations.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAqJ;AAIrJ;;;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,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEjH,MAAM,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAuB,CAAC;QACnF,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,OAAO,EAAE,YAAY,EAAE,0BAA0B,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;SAClG;QAED,IAAI,SAAS,KAAK,QAAQ,EAAE;YAC1B,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;SAC/B;QACD,IAAI,SAAS,KAAK,WAAW,EAAE;YAC7B,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;gBACpC,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;aACnD;SACF;QACD,IAAI,YAAY,EAAE;YAAE,OAAO,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;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IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE;YAChE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,oBAAoB,EAAE,mBAAmB,WAAW,CAAC,IAAI,2BAA2B,UAAU,CAAC,IAAI,oBAAoB,CAAC,CAAC;SACnK;QAED,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;CACF;AAzDD,oCAyDC","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, EnumerationProps, PrimitiveType, SchemaItemKey, 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) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n const newEnum = (await schema.createEnumeration(name, type)) as MutableEnumeration;\n if (newEnum === undefined) {\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\n }\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 }\n if (displayLabel) { newEnum.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) return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (enumProps.name === undefined) return { errorMessage: `No name was supplied within props.` };\n const newEnum = (await schema.createEnumeration(enumProps.name)) as MutableEnumeration;\n if (newEnum === undefined) {\n return { errorMessage: `Failed to create class ${enumProps.name} in schema ${schemaKey.toString(true)}.` };\n }\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(enumerationKey)) as MutableEnumeration;\n\n if (enumeration.isInt && typeof (enumerator.value) === \"string\") {\n throw new ECObjectsError(ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type integer, while ${enumerator.name} has type string.`);\n }\n\n if (!enumeration.isInt && typeof (enumerator.value) === \"number\") {\n throw new ECObjectsError(ECObjectsStatus.InvalidPrimitiveType, `The Enumeration ${enumeration.name} has type string, while ${enumerator.name} has type integer.`);\n }\n\n enumeration.addEnumerator(enumerator);\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ /** @packageDocumentation
2
+ * @module Editing
3
+ */
4
+ import { FormatProps, FormatType, 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 Format.
9
+ */
10
+ export declare class Formats {
11
+ protected _schemaEditor: SchemaContextEditor;
12
+ constructor(_schemaEditor: SchemaContextEditor);
13
+ create(schemaKey: SchemaKey, name: string, formatType: FormatType, displayLabel?: string, units?: SchemaItemKey[]): Promise<SchemaItemEditResults>;
14
+ /**
15
+ * Creates a format through a FormatProps.
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, formatProps: FormatProps): Promise<SchemaItemEditResults>;
20
+ }
21
+ //# sourceMappingURL=Formats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Formats.d.ts","sourceRoot":"","sources":["../../src/Editing/Formats.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAgB,aAAa,EAAE,SAAS,EAAQ,MAAM,0BAA0B,CAAC;AACjH,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGtE;;;GAGG;AACH,qBAAa,OAAO;IACC,SAAS,CAAC,aAAa,EAAE,mBAAmB;gBAAlC,aAAa,EAAE,mBAAmB;IAClD,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAsB/J;;;;OAIG;IACU,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAa7G"}