@itwin/ecschema-editing 3.5.3 → 3.5.4

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 +448 -448
  105. package/lib/cjs/Validation/ECRules.js +593 -593
  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,113 +1,113 @@
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 added, 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
- * Sets the schema version.
99
- * @param schemaKey The SchemaKey identifying the schema.
100
- * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.
101
- * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.
102
- * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.
103
- */
104
- setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults>;
105
- /**
106
- * Increments the minor version of a schema.
107
- * @param schemaKey The SchemaKey identifying the schema.
108
- */
109
- incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults>;
110
- private removeReference;
111
- private removeCustomAttribute;
112
- }
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 added, 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
+ * Sets the schema version.
99
+ * @param schemaKey The SchemaKey identifying the schema.
100
+ * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.
101
+ * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.
102
+ * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.
103
+ */
104
+ setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults>;
105
+ /**
106
+ * Increments the minor version of a schema.
107
+ * @param schemaKey The SchemaKey identifying the schema.
108
+ */
109
+ incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults>;
110
+ private removeReference;
111
+ private removeCustomAttribute;
112
+ }
113
113
  //# sourceMappingURL=Editor.d.ts.map
@@ -1,167 +1,167 @@
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.SchemaContextEditor = void 0;
11
- const Rules = require("../Validation/ECRules");
12
- const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
13
- const core_bentley_1 = require("@itwin/core-bentley");
14
- const Constants_1 = require("./Constants");
15
- const CustomAttributes_1 = require("./CustomAttributes");
16
- const Entities_1 = require("./Entities");
17
- const Enumerations_1 = require("./Enumerations");
18
- const Formats_1 = require("./Formats");
19
- const InvertedUnits_1 = require("./InvertedUnits");
20
- const KindOfQuantities_1 = require("./KindOfQuantities");
21
- const Mixins_1 = require("./Mixins");
22
- const Phenomena_1 = require("./Phenomena");
23
- const PropertyCategories_1 = require("./PropertyCategories");
24
- const RelationshipClasses_1 = require("./RelationshipClasses");
25
- const Structs_1 = require("./Structs");
26
- const Units_1 = require("./Units");
27
- const UnitSystems_1 = require("./UnitSystems");
28
- /**
29
- * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.
30
- * @alpha
31
- */
32
- class SchemaContextEditor {
33
- /**
34
- * Creates a new SchemaContextEditor instance.
35
- * @param schemaContext The SchemaContext the Editor will use to edit in.
36
- */
37
- constructor(schemaContext) {
38
- this.entities = new Entities_1.Entities(this);
39
- this.mixins = new Mixins_1.Mixins(this);
40
- this.structs = new Structs_1.Structs(this);
41
- this.customAttributes = new CustomAttributes_1.CustomAttributes(this);
42
- this.relationships = new RelationshipClasses_1.RelationshipClasses(this);
43
- this.constants = new Constants_1.Constants(this);
44
- this.enumerations = new Enumerations_1.Enumerations(this);
45
- this.formats = new Formats_1.Formats(this);
46
- this.kindOfQuantities = new KindOfQuantities_1.KindOfQuantities(this);
47
- this.units = new Units_1.Units(this);
48
- this.phenomenons = new Phenomena_1.Phenomena(this);
49
- this.unitSystems = new UnitSystems_1.UnitSystems(this);
50
- this.propertyCategories = new PropertyCategories_1.PropertyCategories(this);
51
- this.invertedUnits = new InvertedUnits_1.InvertedUnits(this);
52
- // TODO: Make copy
53
- this._schemaContext = schemaContext;
54
- }
55
- /** Allows you to get schema classes and items through regular SchemaContext methods. */
56
- get schemaContext() { return this._schemaContext; }
57
- async finish() {
58
- return this._schemaContext;
59
- }
60
- /**
61
- * Helper method for retrieving a schema, previously added, from the SchemaContext.
62
- * @param schemaKey The SchemaKey identifying the schema.
63
- */
64
- async getSchema(schemaKey) {
65
- const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
66
- if (schema === undefined)
67
- throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Schema Key ${schemaKey.toString(true)} not found in context`);
68
- return schema;
69
- }
70
- /**
71
- * Creates a Schema with the given properties and adds it to the current schema context.
72
- * @param name The name given to the new schema.
73
- * @param alias The alias of the new schema.
74
- * @param readVersion The read version number of the schema.
75
- * @param writeVersion The write version number of the schema.
76
- * @param minorVersion The minor version number of the schema.
77
- * @returns Resolves to a SchemaEditResults object.
78
- */
79
- async createSchema(name, alias, readVersion, writeVersion, minorVersion) {
80
- const newSchema = new ecschema_metadata_1.Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);
81
- await this._schemaContext.addSchema(newSchema);
82
- return { schemaKey: newSchema.schemaKey };
83
- }
84
- /**
85
- * Adds a referenced schema to the schema identified by the given SchemaKey.
86
- * @param schemaKey The SchemaKey identifying the schema.
87
- * @param refSchema The referenced schema to add.
88
- */
89
- async addSchemaReference(schemaKey, refSchema) {
90
- const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Exact));
91
- if (schema === undefined)
92
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
93
- await schema.addReference(refSchema);
94
- const diagnostics = Rules.validateSchemaReferences(schema);
95
- const result = { errorMessage: "" };
96
- for await (const diagnostic of diagnostics) {
97
- result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
98
- }
99
- if (result.errorMessage) {
100
- this.removeReference(schema, refSchema);
101
- return result;
102
- }
103
- if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {
104
- await this.schemaContext.addSchema(refSchema);
105
- }
106
- return {};
107
- }
108
- /**
109
- * Adds a CustomAttribute instance to the schema identified by the given SchemaKey
110
- * @param schemaKey The SchemaKey identifying the schema.
111
- * @param customAttribute The CustomAttribute instance to add.
112
- */
113
- async addCustomAttribute(schemaKey, customAttribute) {
114
- const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
115
- if (schema === undefined)
116
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
117
- schema.addCustomAttribute(customAttribute);
118
- const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);
119
- const result = { errorMessage: "" };
120
- for await (const diagnostic of diagnostics) {
121
- result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
122
- }
123
- if (result.errorMessage) {
124
- this.removeCustomAttribute(schema, customAttribute);
125
- return result;
126
- }
127
- return {};
128
- }
129
- /**
130
- * Sets the schema version.
131
- * @param schemaKey The SchemaKey identifying the schema.
132
- * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.
133
- * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.
134
- * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.
135
- */
136
- async setVersion(schemaKey, readVersion, writeVersion, minorVersion) {
137
- const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
138
- if (schema === undefined)
139
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
140
- schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);
141
- return {};
142
- }
143
- /**
144
- * Increments the minor version of a schema.
145
- * @param schemaKey The SchemaKey identifying the schema.
146
- */
147
- async incrementMinorVersion(schemaKey) {
148
- const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
149
- if (schema === undefined)
150
- return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
151
- schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);
152
- return {};
153
- }
154
- removeReference(schema, refSchema) {
155
- const index = schema.references.indexOf(refSchema);
156
- if (index !== -1) {
157
- schema.references.splice(index, 1);
158
- }
159
- }
160
- removeCustomAttribute(schema, customAttribute) {
161
- (0, core_bentley_1.assert)(schema.customAttributes !== undefined);
162
- const map = schema.customAttributes;
163
- map.delete(customAttribute.className);
164
- }
165
- }
166
- exports.SchemaContextEditor = SchemaContextEditor;
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.SchemaContextEditor = void 0;
11
+ const Rules = require("../Validation/ECRules");
12
+ const ecschema_metadata_1 = require("@itwin/ecschema-metadata");
13
+ const core_bentley_1 = require("@itwin/core-bentley");
14
+ const Constants_1 = require("./Constants");
15
+ const CustomAttributes_1 = require("./CustomAttributes");
16
+ const Entities_1 = require("./Entities");
17
+ const Enumerations_1 = require("./Enumerations");
18
+ const Formats_1 = require("./Formats");
19
+ const InvertedUnits_1 = require("./InvertedUnits");
20
+ const KindOfQuantities_1 = require("./KindOfQuantities");
21
+ const Mixins_1 = require("./Mixins");
22
+ const Phenomena_1 = require("./Phenomena");
23
+ const PropertyCategories_1 = require("./PropertyCategories");
24
+ const RelationshipClasses_1 = require("./RelationshipClasses");
25
+ const Structs_1 = require("./Structs");
26
+ const Units_1 = require("./Units");
27
+ const UnitSystems_1 = require("./UnitSystems");
28
+ /**
29
+ * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.
30
+ * @alpha
31
+ */
32
+ class SchemaContextEditor {
33
+ /**
34
+ * Creates a new SchemaContextEditor instance.
35
+ * @param schemaContext The SchemaContext the Editor will use to edit in.
36
+ */
37
+ constructor(schemaContext) {
38
+ this.entities = new Entities_1.Entities(this);
39
+ this.mixins = new Mixins_1.Mixins(this);
40
+ this.structs = new Structs_1.Structs(this);
41
+ this.customAttributes = new CustomAttributes_1.CustomAttributes(this);
42
+ this.relationships = new RelationshipClasses_1.RelationshipClasses(this);
43
+ this.constants = new Constants_1.Constants(this);
44
+ this.enumerations = new Enumerations_1.Enumerations(this);
45
+ this.formats = new Formats_1.Formats(this);
46
+ this.kindOfQuantities = new KindOfQuantities_1.KindOfQuantities(this);
47
+ this.units = new Units_1.Units(this);
48
+ this.phenomenons = new Phenomena_1.Phenomena(this);
49
+ this.unitSystems = new UnitSystems_1.UnitSystems(this);
50
+ this.propertyCategories = new PropertyCategories_1.PropertyCategories(this);
51
+ this.invertedUnits = new InvertedUnits_1.InvertedUnits(this);
52
+ // TODO: Make copy
53
+ this._schemaContext = schemaContext;
54
+ }
55
+ /** Allows you to get schema classes and items through regular SchemaContext methods. */
56
+ get schemaContext() { return this._schemaContext; }
57
+ async finish() {
58
+ return this._schemaContext;
59
+ }
60
+ /**
61
+ * Helper method for retrieving a schema, previously added, from the SchemaContext.
62
+ * @param schemaKey The SchemaKey identifying the schema.
63
+ */
64
+ async getSchema(schemaKey) {
65
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
66
+ if (schema === undefined)
67
+ throw new ecschema_metadata_1.ECObjectsError(ecschema_metadata_1.ECObjectsStatus.UnableToLocateSchema, `Schema Key ${schemaKey.toString(true)} not found in context`);
68
+ return schema;
69
+ }
70
+ /**
71
+ * Creates a Schema with the given properties and adds it to the current schema context.
72
+ * @param name The name given to the new schema.
73
+ * @param alias The alias of the new schema.
74
+ * @param readVersion The read version number of the schema.
75
+ * @param writeVersion The write version number of the schema.
76
+ * @param minorVersion The minor version number of the schema.
77
+ * @returns Resolves to a SchemaEditResults object.
78
+ */
79
+ async createSchema(name, alias, readVersion, writeVersion, minorVersion) {
80
+ const newSchema = new ecschema_metadata_1.Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);
81
+ await this._schemaContext.addSchema(newSchema);
82
+ return { schemaKey: newSchema.schemaKey };
83
+ }
84
+ /**
85
+ * Adds a referenced schema to the schema identified by the given SchemaKey.
86
+ * @param schemaKey The SchemaKey identifying the schema.
87
+ * @param refSchema The referenced schema to add.
88
+ */
89
+ async addSchemaReference(schemaKey, refSchema) {
90
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Exact));
91
+ if (schema === undefined)
92
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
93
+ await schema.addReference(refSchema);
94
+ const diagnostics = Rules.validateSchemaReferences(schema);
95
+ const result = { errorMessage: "" };
96
+ for await (const diagnostic of diagnostics) {
97
+ result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
98
+ }
99
+ if (result.errorMessage) {
100
+ this.removeReference(schema, refSchema);
101
+ return result;
102
+ }
103
+ if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {
104
+ await this.schemaContext.addSchema(refSchema);
105
+ }
106
+ return {};
107
+ }
108
+ /**
109
+ * Adds a CustomAttribute instance to the schema identified by the given SchemaKey
110
+ * @param schemaKey The SchemaKey identifying the schema.
111
+ * @param customAttribute The CustomAttribute instance to add.
112
+ */
113
+ async addCustomAttribute(schemaKey, customAttribute) {
114
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
115
+ if (schema === undefined)
116
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
117
+ schema.addCustomAttribute(customAttribute);
118
+ const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);
119
+ const result = { errorMessage: "" };
120
+ for await (const diagnostic of diagnostics) {
121
+ result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\r\n`;
122
+ }
123
+ if (result.errorMessage) {
124
+ this.removeCustomAttribute(schema, customAttribute);
125
+ return result;
126
+ }
127
+ return {};
128
+ }
129
+ /**
130
+ * Sets the schema version.
131
+ * @param schemaKey The SchemaKey identifying the schema.
132
+ * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.
133
+ * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.
134
+ * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.
135
+ */
136
+ async setVersion(schemaKey, readVersion, writeVersion, minorVersion) {
137
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
138
+ if (schema === undefined)
139
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
140
+ schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);
141
+ return {};
142
+ }
143
+ /**
144
+ * Increments the minor version of a schema.
145
+ * @param schemaKey The SchemaKey identifying the schema.
146
+ */
147
+ async incrementMinorVersion(schemaKey) {
148
+ const schema = (await this.schemaContext.getCachedSchema(schemaKey, ecschema_metadata_1.SchemaMatchType.Latest));
149
+ if (schema === undefined)
150
+ return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };
151
+ schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);
152
+ return {};
153
+ }
154
+ removeReference(schema, refSchema) {
155
+ const index = schema.references.indexOf(refSchema);
156
+ if (index !== -1) {
157
+ schema.references.splice(index, 1);
158
+ }
159
+ }
160
+ removeCustomAttribute(schema, customAttribute) {
161
+ (0, core_bentley_1.assert)(schema.customAttributes !== undefined);
162
+ const map = schema.customAttributes;
163
+ map.delete(customAttribute.className);
164
+ }
165
+ }
166
+ exports.SchemaContextEditor = SchemaContextEditor;
167
167
  //# sourceMappingURL=Editor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA8J;AAE9J,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AA6B5C;;;GAGG;AACH,MAAa,mBAAmB;IAiB9B;;;OAGG;IACH,YAAY,aAA4B;QAnBxB,aAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QAC9B,WAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,YAAO,GAAG,IAAI,iBAAO,CAAC,IAAI,CAAC,CAAC;QAC5B,qBAAgB,GAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,CAAC;QAC9C,kBAAa,GAAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,CAAC;QAC9C,cAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,CAAC;QAChC,iBAAY,GAAG,IAAI,2BAAY,CAAC,IAAI,CAAC,CAAC;QACtC,YAAO,GAAG,IAAI,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BAAqB,CAAC,SAAoB;QACrD,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,SAAS,EAAE,mCAAe,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7F,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,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;AA7JD,kDA6JC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { CustomAttribute, ECObjectsError, ECObjectsStatus, Schema, SchemaContext, SchemaItemKey, SchemaKey, SchemaMatchType } from \"@itwin/ecschema-metadata\";\r\nimport { MutableSchema } from \"./Mutable/MutableSchema\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { Constants } from \"./Constants\";\r\nimport { CustomAttributes } from \"./CustomAttributes\";\r\nimport { Entities } from \"./Entities\";\r\nimport { Enumerations } from \"./Enumerations\";\r\nimport { Formats } from \"./Formats\";\r\nimport { InvertedUnits } from \"./InvertedUnits\";\r\nimport { KindOfQuantities } from \"./KindOfQuantities\";\r\nimport { Mixins } from \"./Mixins\";\r\nimport { Phenomena } from \"./Phenomena\";\r\nimport { PropertyCategories } from \"./PropertyCategories\";\r\nimport { RelationshipClasses } from \"./RelationshipClasses\";\r\nimport { Structs } from \"./Structs\";\r\nimport { Units } from \"./Units\";\r\nimport { UnitSystems } from \"./UnitSystems\";\r\n\r\n// We can either add validation in Editor, or in the protected methods of Schema.\r\n// TODO: Add an error code so we can do something programmatic with the error.\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaEditResults {\r\n schemaKey?: SchemaKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface SchemaItemEditResults {\r\n itemKey?: SchemaItemKey;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * @alpha\r\n */\r\nexport interface PropertyEditResults {\r\n itemKey?: SchemaItemKey;\r\n propertyName?: string;\r\n errorMessage?: string;\r\n}\r\n\r\n/**\r\n * A class that allows you to edit and create schemas, classes, and items from the SchemaContext level.\r\n * @alpha\r\n */\r\nexport class SchemaContextEditor {\r\n private _schemaContext: SchemaContext;\r\n public readonly entities = new Entities(this);\r\n public readonly mixins = new Mixins(this);\r\n public readonly structs = new Structs(this);\r\n public readonly customAttributes = new CustomAttributes(this);\r\n public readonly relationships = new RelationshipClasses(this);\r\n public readonly constants = new Constants(this);\r\n public readonly enumerations = new Enumerations(this);\r\n public readonly formats = new Formats(this);\r\n public readonly kindOfQuantities = new KindOfQuantities(this);\r\n public readonly units = new Units(this);\r\n public readonly phenomenons = new Phenomena(this);\r\n public readonly unitSystems = new UnitSystems(this);\r\n public readonly propertyCategories = new PropertyCategories(this);\r\n public readonly invertedUnits = new InvertedUnits(this);\r\n\r\n /**\r\n * Creates a new SchemaContextEditor instance.\r\n * @param schemaContext The SchemaContext the Editor will use to edit in.\r\n */\r\n constructor(schemaContext: SchemaContext) {\r\n // TODO: Make copy\r\n this._schemaContext = schemaContext;\r\n }\r\n\r\n /** Allows you to get schema classes and items through regular SchemaContext methods. */\r\n public get schemaContext(): SchemaContext { return this._schemaContext; }\r\n\r\n public async finish(): Promise<SchemaContext> {\r\n return this._schemaContext;\r\n }\r\n\r\n /**\r\n * Helper method for retrieving a schema, previously added, from the SchemaContext.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${schemaKey.toString(true)} not found in context`);\r\n\r\n return schema;\r\n }\r\n /**\r\n * Creates a Schema with the given properties and adds it to the current schema context.\r\n * @param name The name given to the new schema.\r\n * @param alias The alias of the new schema.\r\n * @param readVersion The read version number of the schema.\r\n * @param writeVersion The write version number of the schema.\r\n * @param minorVersion The minor version number of the schema.\r\n * @returns Resolves to a SchemaEditResults object.\r\n */\r\n public async createSchema(name: string, alias: string, readVersion: number, writeVersion: number, minorVersion: number): Promise<SchemaEditResults> {\r\n const newSchema = new Schema(this._schemaContext, name, alias, readVersion, writeVersion, minorVersion);\r\n await this._schemaContext.addSchema(newSchema);\r\n return { schemaKey: newSchema.schemaKey };\r\n }\r\n\r\n /**\r\n * Adds a referenced schema to the schema identified by the given SchemaKey.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param refSchema The referenced schema to add.\r\n */\r\n public async addSchemaReference(schemaKey: SchemaKey, refSchema: Schema): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Exact));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n await schema.addReference(refSchema);\r\n const diagnostics = Rules.validateSchemaReferences(schema);\r\n\r\n const result: SchemaEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeReference(schema, refSchema);\r\n return result;\r\n }\r\n\r\n if (!await this.schemaContext.getCachedSchema(refSchema.schemaKey)) {\r\n await this.schemaContext.addSchema(refSchema);\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the schema identified by the given SchemaKey\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(schemaKey: SchemaKey, customAttribute: CustomAttribute): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(schema, customAttribute);\r\n\r\n const result: SchemaEditResults = { errorMessage: \"\" };\r\n for await (const diagnostic of diagnostics) {\r\n result.errorMessage += `${diagnostic.code}: ${diagnostic.messageText}\\r\\n`;\r\n }\r\n\r\n if (result.errorMessage) {\r\n this.removeCustomAttribute(schema, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Sets the schema version.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\r\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\r\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\r\n */\r\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\r\n return {};\r\n }\r\n\r\n /**\r\n * Increments the minor version of a schema.\r\n * @param schemaKey The SchemaKey identifying the schema.\r\n */\r\n public async incrementMinorVersion(schemaKey: SchemaKey): Promise<SchemaEditResults> {\r\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n schema.setVersion(schema.readVersion, schema.writeVersion, schema.minorVersion + 1);\r\n return {};\r\n }\r\n\r\n private removeReference(schema: Schema, refSchema: Schema) {\r\n const index: number = schema.references.indexOf(refSchema);\r\n if (index !== -1) {\r\n schema.references.splice(index, 1);\r\n }\r\n }\r\n\r\n private removeCustomAttribute(schema: Schema, customAttribute: CustomAttribute) {\r\n assert(schema.customAttributes !== undefined);\r\n const map = schema.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"Editor.js","sourceRoot":"","sources":["../../../src/Editing/Editor.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+CAA+C;AAC/C,gEAA8J;AAE9J,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC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A,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;AA7JD,kDA6JC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Editing\n */\n\nimport * as Rules from \"../Validation/ECRules\";\nimport { CustomAttribute, ECObjectsError, ECObjectsStatus, 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 added, from the SchemaContext.\n * @param schemaKey The SchemaKey identifying the schema.\n */\n public async getSchema(schemaKey: SchemaKey): Promise<MutableSchema> {\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\n if (schema === undefined)\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${schemaKey.toString(true)} not found in context`);\n\n return schema;\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<MutableSchema>(schemaKey, SchemaMatchType.Exact));\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\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<MutableSchema>(schemaKey, SchemaMatchType.Latest));\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\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 * Sets the schema version.\n * @param schemaKey The SchemaKey identifying the schema.\n * @param readVersion The read version of the schema. If not specified, the existing read version will be maintained.\n * @param writeVersion The write version of the schema. If not specified, the existing write version will be maintained.\n * @param minorVersion The minor version of the schema. If not specified, the existing minor version will be maintained.\n */\n public async setVersion(schemaKey: SchemaKey, readVersion?: number, writeVersion?: number, minorVersion?: number): Promise<SchemaEditResults> {\n const schema = (await this.schemaContext.getCachedSchema(schemaKey, SchemaMatchType.Latest));\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n schema.setVersion(readVersion || schema.readVersion, writeVersion || schema.writeVersion, minorVersion || schema.minorVersion);\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));\n if (schema === undefined)\n 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"]}