@itwin/ecschema-editing 4.5.0-dev.8 → 4.5.0

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 (135) hide show
  1. package/CHANGELOG.md +79 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/Differencing/SchemaConflicts.d.ts +76 -0
  4. package/lib/cjs/Differencing/SchemaConflicts.d.ts.map +1 -0
  5. package/lib/cjs/Differencing/SchemaConflicts.js +56 -0
  6. package/lib/cjs/Differencing/SchemaConflicts.js.map +1 -0
  7. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts +43 -0
  8. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.d.ts.map +1 -0
  9. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js +501 -0
  10. package/lib/cjs/Differencing/SchemaDiagnosticVisitor.js.map +1 -0
  11. package/lib/cjs/Differencing/SchemaDifference.d.ts +150 -0
  12. package/lib/cjs/Differencing/SchemaDifference.d.ts.map +1 -0
  13. package/lib/cjs/Differencing/SchemaDifference.js +54 -0
  14. package/lib/cjs/Differencing/SchemaDifference.js.map +1 -0
  15. package/lib/cjs/Editing/Constants.js.map +1 -1
  16. package/lib/cjs/Editing/CustomAttributes.js.map +1 -1
  17. package/lib/cjs/Editing/ECClasses.d.ts +9 -2
  18. package/lib/cjs/Editing/ECClasses.d.ts.map +1 -1
  19. package/lib/cjs/Editing/ECClasses.js +25 -0
  20. package/lib/cjs/Editing/ECClasses.js.map +1 -1
  21. package/lib/cjs/Editing/Editor.js.map +1 -1
  22. package/lib/cjs/Editing/Entities.d.ts +8 -2
  23. package/lib/cjs/Editing/Entities.d.ts.map +1 -1
  24. package/lib/cjs/Editing/Entities.js +29 -6
  25. package/lib/cjs/Editing/Entities.js.map +1 -1
  26. package/lib/cjs/Editing/Enumerations.js.map +1 -1
  27. package/lib/cjs/Editing/Formats.js.map +1 -1
  28. package/lib/cjs/Editing/InvertedUnits.js.map +1 -1
  29. package/lib/cjs/Editing/KindOfQuantities.js.map +1 -1
  30. package/lib/cjs/Editing/Mixins.d.ts +7 -1
  31. package/lib/cjs/Editing/Mixins.d.ts.map +1 -1
  32. package/lib/cjs/Editing/Mixins.js +15 -0
  33. package/lib/cjs/Editing/Mixins.js.map +1 -1
  34. package/lib/cjs/Editing/Mutable/MutableArrayProperty.js.map +1 -1
  35. package/lib/cjs/Editing/Mutable/MutableCAClass.js.map +1 -1
  36. package/lib/cjs/Editing/Mutable/MutableClass.js.map +1 -1
  37. package/lib/cjs/Editing/Mutable/MutableConstant.js.map +1 -1
  38. package/lib/cjs/Editing/Mutable/MutableEntityClass.js.map +1 -1
  39. package/lib/cjs/Editing/Mutable/MutableEnumeration.js.map +1 -1
  40. package/lib/cjs/Editing/Mutable/MutableFormat.js.map +1 -1
  41. package/lib/cjs/Editing/Mutable/MutableInvertedUnit.js.map +1 -1
  42. package/lib/cjs/Editing/Mutable/MutableKindOfQuantity.js.map +1 -1
  43. package/lib/cjs/Editing/Mutable/MutableMixin.js.map +1 -1
  44. package/lib/cjs/Editing/Mutable/MutablePhenomenon.js.map +1 -1
  45. package/lib/cjs/Editing/Mutable/MutablePrimitiveOrEnumProperty.js.map +1 -1
  46. package/lib/cjs/Editing/Mutable/MutableProperty.js.map +1 -1
  47. package/lib/cjs/Editing/Mutable/MutablePropertyCategory.js.map +1 -1
  48. package/lib/cjs/Editing/Mutable/MutableRelationshipClass.js.map +1 -1
  49. package/lib/cjs/Editing/Mutable/MutableSchema.js.map +1 -1
  50. package/lib/cjs/Editing/Mutable/MutableUnit.js.map +1 -1
  51. package/lib/cjs/Editing/Mutable/MutableUnitSystem.js.map +1 -1
  52. package/lib/cjs/Editing/Phenomena.js.map +1 -1
  53. package/lib/cjs/Editing/PropertyCategories.js.map +1 -1
  54. package/lib/cjs/Editing/RelationshipClasses.d.ts +7 -1
  55. package/lib/cjs/Editing/RelationshipClasses.d.ts.map +1 -1
  56. package/lib/cjs/Editing/RelationshipClasses.js +20 -1
  57. package/lib/cjs/Editing/RelationshipClasses.js.map +1 -1
  58. package/lib/cjs/Editing/SchemaItems.js.map +1 -1
  59. package/lib/cjs/Editing/Structs.js.map +1 -1
  60. package/lib/cjs/Editing/UnitSystems.js.map +1 -1
  61. package/lib/cjs/Editing/Units.js.map +1 -1
  62. package/lib/cjs/Merging/CAClassMerger.d.ts.map +1 -1
  63. package/lib/cjs/Merging/CAClassMerger.js +1 -5
  64. package/lib/cjs/Merging/CAClassMerger.js.map +1 -1
  65. package/lib/cjs/Merging/ClassMerger.d.ts +4 -3
  66. package/lib/cjs/Merging/ClassMerger.d.ts.map +1 -1
  67. package/lib/cjs/Merging/ClassMerger.js +57 -49
  68. package/lib/cjs/Merging/ClassMerger.js.map +1 -1
  69. package/lib/cjs/Merging/ConstantMerger.js.map +1 -1
  70. package/lib/cjs/Merging/CustomAttributeMerger.js.map +1 -1
  71. package/lib/cjs/Merging/EntityClassMerger.d.ts +3 -2
  72. package/lib/cjs/Merging/EntityClassMerger.d.ts.map +1 -1
  73. package/lib/cjs/Merging/EntityClassMerger.js +22 -7
  74. package/lib/cjs/Merging/EntityClassMerger.js.map +1 -1
  75. package/lib/cjs/Merging/EnumerationMerger.js.map +1 -1
  76. package/lib/cjs/Merging/KindOfQuantityMerger.js.map +1 -1
  77. package/lib/cjs/Merging/MixinMerger.d.ts.map +1 -1
  78. package/lib/cjs/Merging/MixinMerger.js +1 -5
  79. package/lib/cjs/Merging/MixinMerger.js.map +1 -1
  80. package/lib/cjs/Merging/PropertyMerger.d.ts +21 -0
  81. package/lib/cjs/Merging/PropertyMerger.d.ts.map +1 -0
  82. package/lib/cjs/Merging/PropertyMerger.js +315 -0
  83. package/lib/cjs/Merging/PropertyMerger.js.map +1 -0
  84. package/lib/cjs/Merging/RelationshipClassMerger.d.ts +15 -0
  85. package/lib/cjs/Merging/RelationshipClassMerger.d.ts.map +1 -0
  86. package/lib/cjs/Merging/RelationshipClassMerger.js +132 -0
  87. package/lib/cjs/Merging/RelationshipClassMerger.js.map +1 -0
  88. package/lib/cjs/Merging/SchemaItemFactory.js.map +1 -1
  89. package/lib/cjs/Merging/SchemaItemMerger.js.map +1 -1
  90. package/lib/cjs/Merging/SchemaMerger.d.ts.map +1 -1
  91. package/lib/cjs/Merging/SchemaMerger.js +7 -3
  92. package/lib/cjs/Merging/SchemaMerger.js.map +1 -1
  93. package/lib/cjs/Merging/SchemaReferenceMerger.js.map +1 -1
  94. package/lib/cjs/Merging/StructClassMerger.js.map +1 -1
  95. package/lib/cjs/Validation/Diagnostic.js.map +1 -1
  96. package/lib/cjs/Validation/DiagnosticReporter.js.map +1 -1
  97. package/lib/cjs/Validation/ECRules.js.map +1 -1
  98. package/lib/cjs/Validation/LoggingDiagnosticReporter.js.map +1 -1
  99. package/lib/cjs/Validation/RuleSuppressionSet.js.map +1 -1
  100. package/lib/cjs/Validation/Rules.js.map +1 -1
  101. package/lib/cjs/Validation/SchemaChanges.js.map +1 -1
  102. package/lib/cjs/Validation/SchemaCompareDiagnostics.js.map +1 -1
  103. package/lib/cjs/Validation/SchemaCompareReporter.js.map +1 -1
  104. package/lib/cjs/Validation/SchemaCompareResultDelegate.js.map +1 -1
  105. package/lib/cjs/Validation/SchemaCompareVisitor.js.map +1 -1
  106. package/lib/cjs/Validation/SchemaComparer.js.map +1 -1
  107. package/lib/cjs/Validation/SchemaValidater.js.map +1 -1
  108. package/lib/cjs/Validation/SchemaValidationVisitor.js.map +1 -1
  109. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  110. package/lib/cjs/ecschema-editing.d.ts +4 -0
  111. package/lib/cjs/ecschema-editing.d.ts.map +1 -1
  112. package/lib/cjs/ecschema-editing.js +4 -0
  113. package/lib/cjs/ecschema-editing.js.map +1 -1
  114. package/package.json +10 -10
  115. package/public/locales/en/ECSchemaEditing.json +26 -26
  116. package/lib/cjs/Merging/AnyPropertyMerger.d.ts +0 -15
  117. package/lib/cjs/Merging/AnyPropertyMerger.d.ts.map +0 -1
  118. package/lib/cjs/Merging/AnyPropertyMerger.js +0 -71
  119. package/lib/cjs/Merging/AnyPropertyMerger.js.map +0 -1
  120. package/lib/cjs/Merging/ArrayPropertyMerger.d.ts +0 -32
  121. package/lib/cjs/Merging/ArrayPropertyMerger.d.ts.map +0 -1
  122. package/lib/cjs/Merging/ArrayPropertyMerger.js +0 -143
  123. package/lib/cjs/Merging/ArrayPropertyMerger.js.map +0 -1
  124. package/lib/cjs/Merging/ClassPropertyMerger.d.ts +0 -16
  125. package/lib/cjs/Merging/ClassPropertyMerger.d.ts.map +0 -1
  126. package/lib/cjs/Merging/ClassPropertyMerger.js +0 -90
  127. package/lib/cjs/Merging/ClassPropertyMerger.js.map +0 -1
  128. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts +0 -24
  129. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.d.ts.map +0 -1
  130. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js +0 -106
  131. package/lib/cjs/Merging/PrimitiveOrEnumPropertyMerger.js.map +0 -1
  132. package/lib/cjs/Merging/StructPropertyMerger.d.ts +0 -11
  133. package/lib/cjs/Merging/StructPropertyMerger.d.ts.map +0 -1
  134. package/lib/cjs/Merging/StructPropertyMerger.js +0 -47
  135. package/lib/cjs/Merging/StructPropertyMerger.js.map +0 -1
@@ -0,0 +1,150 @@
1
+ /** @packageDocumentation
2
+ * @module Differencing
3
+ */
4
+ import { SchemaChanges } from "../Validation/SchemaChanges";
5
+ import { SchemaDifferenceConflict } from "./SchemaConflicts";
6
+ import type { AnyEnumerator, AnyPropertyProps, AnySchemaItemProps, CustomAttribute, RelationshipConstraintProps, Schema, SchemaProps, SchemaReferenceProps } from "@itwin/ecschema-metadata";
7
+ /**
8
+ * Defines the type of the difference operation.
9
+ * @internal
10
+ */
11
+ export type DifferenceType = "add" | "modify";
12
+ /**
13
+ * Defines a set of SchemaItem names.
14
+ * @internal
15
+ */
16
+ export type SchemaItemTypeName = "EntityClass" | "Mixin" | "StructClass" | "CustomAttributeClass" | "RelationshipClass" | "Enumeration" | "KindOfQuantity" | "PropertyCategory" | "Unit" | "InvertedUnit" | "Constant" | "Phenomenon" | "UnitSystem" | "Format";
17
+ /**
18
+ * Defines the possible values SchemaTypes that can occur in SchemaDifferences or Conflicts.
19
+ * @internal
20
+ */
21
+ export type SchemaType = "Schema" | SchemaItemTypeName | "Property" | "RelationshipConstraint";
22
+ /**
23
+ * @internal
24
+ */
25
+ export declare namespace SchemaDifference {
26
+ /**
27
+ * Creates a [[SchemaDifference]] for two given schemas.
28
+ * @param targetSchema The schema the differences gets merged into.
29
+ * @param sourceSchema The schema to get merged in the target.
30
+ * @returns An [[SchemaDifference]] object.
31
+ * @internal
32
+ */
33
+ function fromSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaDifferences>;
34
+ /**
35
+ * Creates a [[SchemaDifference]] for a given [[SchemaChanges]] report.
36
+ * @param targetSchema
37
+ * @param schemaChanges A changes report of two schemas.
38
+ * @returns An [[SchemaDifference]] object.
39
+ * @internal
40
+ */
41
+ function fromSchemaChanges(targetSchema: Schema, schemaChanges: SchemaChanges): Promise<SchemaDifferences>;
42
+ }
43
+ type MutualPartial<T> = {
44
+ -readonly [P in keyof T]?: T[P];
45
+ };
46
+ /**
47
+ * @internal
48
+ */
49
+ export interface SchemaDifferences {
50
+ readonly sourceSchemaName: string;
51
+ readonly targetSchemaName: string;
52
+ readonly changes: AnySchemaDifference[];
53
+ readonly conflicts: SchemaDifferenceConflict[];
54
+ }
55
+ /**
56
+ * @internal
57
+ */
58
+ export type AnySchemaDifference = SchemaDifference | SchemaItemDifference | SchemaPropertyDifference | SchemaReferenceDifference | SchemaEnumeratorDifference | SchemaClassMixinDifference | SchemaRelationshipConstraintDifference | SchemaRelationshipConstraintClassDifference | SchemaCustomAttributeDifference;
59
+ /**
60
+ * @internal
61
+ */
62
+ export interface SchemaDifference {
63
+ changeType: "modify";
64
+ schemaType: "Schema";
65
+ itemName?: undefined;
66
+ path?: undefined;
67
+ json: MutualPartial<SchemaProps>;
68
+ }
69
+ /**
70
+ * @internal
71
+ */
72
+ export interface SchemaItemDifference<T extends AnySchemaItemProps = AnySchemaItemProps> {
73
+ changeType: "add" | "modify" | "remove";
74
+ schemaType: SchemaItemTypeName;
75
+ itemName: string;
76
+ path?: string;
77
+ json: MutualPartial<T>;
78
+ }
79
+ /**
80
+ * @internal
81
+ */
82
+ export interface SchemaPropertyDifference<T extends AnyPropertyProps = AnyPropertyProps> {
83
+ changeType: "add" | "modify" | "remove";
84
+ schemaType: "Property";
85
+ itemName: string;
86
+ path: string;
87
+ json: MutualPartial<T>;
88
+ }
89
+ /**
90
+ * @internal
91
+ */
92
+ export interface SchemaReferenceDifference {
93
+ changeType: "add" | "modify" | "remove";
94
+ schemaType: "Schema";
95
+ itemName?: undefined;
96
+ path: "$references";
97
+ json: MutualPartial<SchemaReferenceProps>;
98
+ }
99
+ /**
100
+ * @internal
101
+ */
102
+ export interface SchemaEnumeratorDifference {
103
+ changeType: "add" | "modify" | "remove";
104
+ schemaType: "Enumeration";
105
+ itemName: string;
106
+ path: string;
107
+ json: MutualPartial<AnyEnumerator>;
108
+ }
109
+ /**
110
+ * @internal
111
+ */
112
+ export interface SchemaClassMixinDifference {
113
+ changeType: "modify";
114
+ schemaType: "EntityClass";
115
+ itemName: string;
116
+ path: "$mixins";
117
+ json: string[];
118
+ }
119
+ /**
120
+ * @internal
121
+ */
122
+ export interface SchemaRelationshipConstraintDifference {
123
+ changeType: "modify";
124
+ schemaType: "RelationshipConstraint";
125
+ itemName: string;
126
+ path: string;
127
+ json: MutualPartial<RelationshipConstraintProps>;
128
+ }
129
+ /**
130
+ * @internal
131
+ */
132
+ export interface SchemaRelationshipConstraintClassDifference {
133
+ changeType: "modify";
134
+ schemaType: "RelationshipClass";
135
+ itemName: string;
136
+ path: string;
137
+ json: string[];
138
+ }
139
+ /**
140
+ * @internal
141
+ */
142
+ export interface SchemaCustomAttributeDifference {
143
+ changeType: "add" | "modify";
144
+ schemaType: "Schema" | "EnitityClass" | "Properties" | "RelationshipConstraint";
145
+ itemName?: string;
146
+ path?: string;
147
+ json: MutualPartial<CustomAttribute>;
148
+ }
149
+ export {};
150
+ //# sourceMappingURL=SchemaDifference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaDifference.d.ts","sourceRoot":"","sources":["../../../src/Differencing/SchemaDifference.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,KAAK,EACV,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,EACzG,WAAW,EAAE,oBAAoB,EAClC,MAAM,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC5B,aAAa,GACb,OAAO,GACP,aAAa,GACb,sBAAsB,GACtB,mBAAmB,GACnB,aAAa,GACb,gBAAgB,GAChB,kBAAkB,GAClB,MAAM,GACN,cAAc,GACd,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,QAAQ,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,kBAAkB,GAAG,UAAU,GAAG,wBAAwB,CAAC;AAE/F;;GAEG;AACH,yBAAiB,gBAAgB,CAAC;IAChC;;;;;;OAMG;IACH,SAAsB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAMxG;IAED;;;;;;OAMG;IACH,SAAsB,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,iBAAiB,CAAC,CActH;CACF;AAED,KAAK,aAAa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MAAM,WAAW,+BAA+B;IAC9C,UAAU,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC7B,UAAU,EAAE,QAAQ,GAAG,cAAc,GAAG,YAAY,GAAG,wBAAwB,CAAC;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;CACtC"}
@@ -0,0 +1,54 @@
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 Differencing
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SchemaDifference = void 0;
11
+ const SchemaComparer_1 = require("../Validation/SchemaComparer");
12
+ const SchemaDiagnosticVisitor_1 = require("./SchemaDiagnosticVisitor");
13
+ /**
14
+ * @internal
15
+ */
16
+ var SchemaDifference;
17
+ (function (SchemaDifference) {
18
+ /**
19
+ * Creates a [[SchemaDifference]] for two given schemas.
20
+ * @param targetSchema The schema the differences gets merged into.
21
+ * @param sourceSchema The schema to get merged in the target.
22
+ * @returns An [[SchemaDifference]] object.
23
+ * @internal
24
+ */
25
+ async function fromSchemas(targetSchema, sourceSchema) {
26
+ const changesList = [];
27
+ const schemaComparer = new SchemaComparer_1.SchemaComparer({ report: changesList.push.bind(changesList) });
28
+ await schemaComparer.compareSchemas(sourceSchema, targetSchema);
29
+ return fromSchemaChanges(targetSchema, changesList[0]);
30
+ }
31
+ SchemaDifference.fromSchemas = fromSchemas;
32
+ /**
33
+ * Creates a [[SchemaDifference]] for a given [[SchemaChanges]] report.
34
+ * @param targetSchema
35
+ * @param schemaChanges A changes report of two schemas.
36
+ * @returns An [[SchemaDifference]] object.
37
+ * @internal
38
+ */
39
+ async function fromSchemaChanges(targetSchema, schemaChanges) {
40
+ const schemaDifference = {
41
+ sourceSchemaName: schemaChanges.schema.schemaKey.toString(),
42
+ targetSchemaName: targetSchema.schemaKey.toString(),
43
+ changes: [],
44
+ conflicts: [],
45
+ };
46
+ const visitor = new SchemaDiagnosticVisitor_1.SchemaDiagnosticVisitor(schemaDifference);
47
+ for (const diagnostic of schemaChanges.allDiagnostics) {
48
+ visitor.visit(diagnostic);
49
+ }
50
+ return schemaDifference;
51
+ }
52
+ SchemaDifference.fromSchemaChanges = fromSchemaChanges;
53
+ })(SchemaDifference = exports.SchemaDifference || (exports.SchemaDifference = {}));
54
+ //# sourceMappingURL=SchemaDifference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaDifference.js","sourceRoot":"","sources":["../../../src/Differencing/SchemaDifference.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,iEAA8D;AAE9D,uEAAoE;AAsCpE;;GAEG;AACH,IAAiB,gBAAgB,CAsChC;AAtCD,WAAiB,gBAAgB;IAC/B;;;;;;OAMG;IACI,KAAK,UAAU,WAAW,CAAC,YAAoB,EAAE,YAAoB;QAC1E,MAAM,WAAW,GAAoB,EAAE,CAAC;QACxC,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC1F,MAAM,cAAc,CAAC,cAAc,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAEhE,OAAO,iBAAiB,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC;IANqB,4BAAW,cAMhC,CAAA;IAED;;;;;;OAMG;IACI,KAAK,UAAU,iBAAiB,CAAC,YAAoB,EAAE,aAA4B;QACxF,MAAM,gBAAgB,GAAsB;YAC1C,gBAAgB,EAAE,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;YAC3D,gBAAgB,EAAE,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE;YACnD,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,EAAE;SACd,CAAC;QAEF,MAAM,OAAO,GAAG,IAAI,iDAAuB,CAAC,gBAAgB,CAAC,CAAC;QAC9D,KAAI,MAAM,UAAU,IAAI,aAAa,CAAC,cAAc,EAAE;YACpD,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;SAC3B;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAdqB,kCAAiB,oBActC,CAAA;AACH,CAAC,EAtCgB,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAsChC","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 Differencing\r\n */\r\n\r\nimport { SchemaChanges } from \"../Validation/SchemaChanges\";\r\nimport { SchemaComparer } from \"../Validation/SchemaComparer\";\r\nimport { SchemaDifferenceConflict } from \"./SchemaConflicts\";\r\nimport { SchemaDiagnosticVisitor } from \"./SchemaDiagnosticVisitor\";\r\nimport type {\r\n AnyEnumerator, AnyPropertyProps, AnySchemaItemProps, CustomAttribute, RelationshipConstraintProps, Schema,\r\n SchemaProps, SchemaReferenceProps,\r\n} from \"@itwin/ecschema-metadata\";\r\n\r\n/**\r\n * Defines the type of the difference operation.\r\n * @internal\r\n */\r\nexport type DifferenceType = \"add\" | \"modify\";\r\n\r\n/**\r\n * Defines a set of SchemaItem names.\r\n * @internal\r\n */\r\nexport type SchemaItemTypeName =\r\n \"EntityClass\" |\r\n \"Mixin\" |\r\n \"StructClass\" |\r\n \"CustomAttributeClass\" |\r\n \"RelationshipClass\" |\r\n \"Enumeration\" |\r\n \"KindOfQuantity\" |\r\n \"PropertyCategory\" |\r\n \"Unit\" |\r\n \"InvertedUnit\" |\r\n \"Constant\" |\r\n \"Phenomenon\" |\r\n \"UnitSystem\" |\r\n \"Format\";\r\n\r\n/**\r\n * Defines the possible values SchemaTypes that can occur in SchemaDifferences or Conflicts.\r\n * @internal\r\n */\r\nexport type SchemaType = \"Schema\" | SchemaItemTypeName | \"Property\" | \"RelationshipConstraint\";\r\n\r\n/**\r\n * @internal\r\n */\r\nexport namespace SchemaDifference {\r\n /**\r\n * Creates a [[SchemaDifference]] for two given schemas.\r\n * @param targetSchema The schema the differences gets merged into.\r\n * @param sourceSchema The schema to get merged in the target.\r\n * @returns An [[SchemaDifference]] object.\r\n * @internal\r\n */\r\n export async function fromSchemas(targetSchema: Schema, sourceSchema: Schema): Promise<SchemaDifferences> {\r\n const changesList: SchemaChanges[] = [];\r\n const schemaComparer = new SchemaComparer({ report: changesList.push.bind(changesList) });\r\n await schemaComparer.compareSchemas(sourceSchema, targetSchema);\r\n\r\n return fromSchemaChanges(targetSchema, changesList[0]);\r\n }\r\n\r\n /**\r\n * Creates a [[SchemaDifference]] for a given [[SchemaChanges]] report.\r\n * @param targetSchema\r\n * @param schemaChanges A changes report of two schemas.\r\n * @returns An [[SchemaDifference]] object.\r\n * @internal\r\n */\r\n export async function fromSchemaChanges(targetSchema: Schema, schemaChanges: SchemaChanges): Promise<SchemaDifferences> {\r\n const schemaDifference: SchemaDifferences = {\r\n sourceSchemaName: schemaChanges.schema.schemaKey.toString(),\r\n targetSchemaName: targetSchema.schemaKey.toString(),\r\n changes: [],\r\n conflicts: [],\r\n };\r\n\r\n const visitor = new SchemaDiagnosticVisitor(schemaDifference);\r\n for(const diagnostic of schemaChanges.allDiagnostics) {\r\n visitor.visit(diagnostic);\r\n }\r\n\r\n return schemaDifference;\r\n }\r\n}\r\n\r\ntype MutualPartial<T> = {\r\n -readonly [P in keyof T]?: T[P];\r\n};\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaDifferences {\r\n\r\n readonly sourceSchemaName: string;\r\n readonly targetSchemaName: string;\r\n\r\n readonly changes: AnySchemaDifference[];\r\n readonly conflicts: SchemaDifferenceConflict[];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport type AnySchemaDifference =\r\n SchemaDifference |\r\n SchemaItemDifference |\r\n SchemaPropertyDifference |\r\n SchemaReferenceDifference |\r\n SchemaEnumeratorDifference |\r\n SchemaClassMixinDifference |\r\n SchemaRelationshipConstraintDifference |\r\n SchemaRelationshipConstraintClassDifference |\r\n SchemaCustomAttributeDifference;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaDifference {\r\n changeType: \"modify\";\r\n schemaType: \"Schema\";\r\n itemName?: undefined;\r\n path?: undefined;\r\n json: MutualPartial<SchemaProps>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaItemDifference<T extends AnySchemaItemProps = AnySchemaItemProps> {\r\n changeType: \"add\" | \"modify\" | \"remove\";\r\n schemaType: SchemaItemTypeName;\r\n itemName: string;\r\n path?: string;\r\n json: MutualPartial<T>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaPropertyDifference<T extends AnyPropertyProps = AnyPropertyProps> {\r\n changeType: \"add\" | \"modify\" | \"remove\";\r\n schemaType: \"Property\";\r\n itemName: string;\r\n path: string;\r\n json: MutualPartial<T>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaReferenceDifference {\r\n changeType: \"add\" | \"modify\" | \"remove\";\r\n schemaType: \"Schema\";\r\n itemName?: undefined;\r\n path: \"$references\";\r\n json: MutualPartial<SchemaReferenceProps>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaEnumeratorDifference {\r\n changeType: \"add\" | \"modify\" | \"remove\";\r\n schemaType: \"Enumeration\";\r\n itemName: string;\r\n path: string;\r\n json: MutualPartial<AnyEnumerator>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaClassMixinDifference {\r\n changeType: \"modify\";\r\n schemaType: \"EntityClass\";\r\n itemName: string;\r\n path: \"$mixins\";\r\n json: string[];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaRelationshipConstraintDifference {\r\n changeType: \"modify\";\r\n schemaType: \"RelationshipConstraint\";\r\n itemName: string;\r\n path: string;\r\n json: MutualPartial<RelationshipConstraintProps>;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaRelationshipConstraintClassDifference {\r\n changeType: \"modify\";\r\n schemaType: \"RelationshipClass\";\r\n itemName: string;\r\n path: string;\r\n json: string[];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface SchemaCustomAttributeDifference {\r\n changeType: \"add\" | \"modify\";\r\n schemaType: \"Schema\" | \"EnitityClass\" | \"Properties\" | \"RelationshipConstraint\";\r\n itemName?: string;\r\n path?: string;\r\n json: MutualPartial<CustomAttribute>;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../../src/Editing/Constants.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAwI;AAIxI;;;GAGG;AACH,MAAa,SAAS;IACpB,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAE7D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,UAAyB,EAAE,UAAkB,EAAE,YAAqB,EAAE,SAAkB,EAAE,WAAoB;QACpK,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,MAAM,WAAW,GAAG,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAoB,CAAC;QAC3E,IAAI,WAAW,KAAK,SAAS,EAAE;YAC7B,OAAO,EAAE,YAAY,E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C,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACtE,IAAI,WAAW,KAAK,SAAS;YAC3B,OAAO,EAAE,YAAY,EAAE,0BAA0B,aAAa,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAEjH,MAAM,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC1C,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC;IACtC,CAAC;CACF;AApDD,8BAoDC","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 { ConstantProps, DelayedPromiseWithProps, Phenomenon, SchemaItemKey, SchemaItemType, SchemaKey } from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { MutableConstant } from \"./Mutable/MutableConstant\";\n\n/**\n * @alpha\n * A class allowing you to create schema items of type Constant.\n */\nexport class Constants {\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\n\n public async create(schemaKey: SchemaKey, name: string, phenomenon: SchemaItemKey, definition: string, displayLabel?: string, numerator?: number, denominator?: number): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n const newConstant = (await schema.createConstant(name)) as MutableConstant;\n if (newConstant === undefined) {\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\n }\n\n const newPhenomenon = (await this._schemaEditor.schemaContext.getSchemaItem<Phenomenon>(phenomenon));\n if (newPhenomenon === undefined || newPhenomenon.schemaItemType !== SchemaItemType.Phenomenon) {\n return { errorMessage: `Unable to locate phenomenon ${phenomenon.name}` };\n }\n newConstant.setPhenomenon(new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(newPhenomenon.key, async () => newPhenomenon));\n newConstant.setDefinition(definition);\n\n if (numerator)\n newConstant.setNumerator(numerator);\n\n if (denominator)\n newConstant.setDenominator(denominator);\n\n if (displayLabel)\n newConstant.setDisplayLabel(displayLabel);\n\n return { itemKey: newConstant.key };\n }\n\n /**\n * Creates a Constant through a ConstantProps.\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, constantProps: ConstantProps): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (constantProps.name === undefined)\n return { errorMessage: `No name was supplied within props.` };\n\n const newConstant = (await schema.createConstant(constantProps.name));\n if (newConstant === undefined)\n return { errorMessage: `Failed to create class ${constantProps.name} in schema ${schemaKey.toString(true)}.` };\n\n await newConstant.fromJSON(constantProps);\n return { itemKey: newConstant.key };\n }\n}\n"]}
1
+ {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../../src/Editing/Constants.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAAwI;AAIxI;;;GAGG;AACH,MAAa,SAAS;IACpB,YAA6B,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAE7D,KAAK,CAAC,MAAM,CAAC,SAAoB,EAAE,IAAY,EAAE,UAAyB,EAAE,UAAkB,EAAE,YAAqB,EAAE,SAAkB,EAAE,WAAoB;QACpK,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC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AEzF,IAAI,aAAa,CAAC,IAAI,KAAK,SAAS;YAClC,OAAO,EAAE,YAAY,EAAE,oCAAoC,EAAE,CAAC;QAEhE,MAAM,WAAW,GAAG,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QACtE,IAAI,WAAW,KAAK,SAAS;YAC3B,OAAO,EAAE,YAAY,EAAE,0BAA0B,aAAa,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAEjH,MAAM,WAAW,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC1C,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC;IACtC,CAAC;CACF;AApDD,8BAoDC","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 { ConstantProps, DelayedPromiseWithProps, Phenomenon, SchemaItemKey, SchemaItemType, SchemaKey } from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableConstant } from \"./Mutable/MutableConstant\";\r\n\r\n/**\r\n * @alpha\r\n * A class allowing you to create schema items of type Constant.\r\n */\r\nexport class Constants {\r\n public constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, phenomenon: SchemaItemKey, definition: string, displayLabel?: string, numerator?: number, denominator?: number): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newConstant = (await schema.createConstant(name)) as MutableConstant;\r\n if (newConstant === undefined) {\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n }\r\n\r\n const newPhenomenon = (await this._schemaEditor.schemaContext.getSchemaItem<Phenomenon>(phenomenon));\r\n if (newPhenomenon === undefined || newPhenomenon.schemaItemType !== SchemaItemType.Phenomenon) {\r\n return { errorMessage: `Unable to locate phenomenon ${phenomenon.name}` };\r\n }\r\n newConstant.setPhenomenon(new DelayedPromiseWithProps<SchemaItemKey, Phenomenon>(newPhenomenon.key, async () => newPhenomenon));\r\n newConstant.setDefinition(definition);\r\n\r\n if (numerator)\r\n newConstant.setNumerator(numerator);\r\n\r\n if (denominator)\r\n newConstant.setDenominator(denominator);\r\n\r\n if (displayLabel)\r\n newConstant.setDisplayLabel(displayLabel);\r\n\r\n return { itemKey: newConstant.key };\r\n }\r\n\r\n /**\r\n * Creates a Constant through a ConstantProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param relationshipProps a json object that will be used to populate the new RelationshipClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, constantProps: ConstantProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (constantProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newConstant = (await schema.createConstant(constantProps.name));\r\n if (newConstant === undefined)\r\n return { errorMessage: `Failed to create class ${constantProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newConstant.fromJSON(constantProps);\r\n return { itemKey: newConstant.key };\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"CustomAttributes.js","sourceRoot":"","sources":["../../../src/Editing/CustomAttributes.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAGkC;AAElC,2CAAwC;AAGxC;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,qBAAS;IAC7C,YAAmB,aAAk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C,GAAG,EAAE,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,eAAe,CAAC,SAAoB,EAAE,OAAkC;QACnF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAC5B,OAAO,EAAE,YAAY,EAAE,oCAAoC,EAAE,CAAC;QAEhE,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,0BAA0B,CAAC,OAAO,CAAC,IAAI,CAAC,CAAmB,CAAC;QAC3F,IAAI,QAAQ,KAAK,SAAS;YACxB,OAAO,EAAE,YAAY,EAAE,0BAA0B,OAAO,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAE3G,MAAM,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEjC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;CACF;AAtDD,4CAsDC","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 CustomAttributeClassProps, CustomAttributeContainerType, DelayedPromiseWithProps, ECClass,\n SchemaItemKey, SchemaItemType, SchemaKey,\n} from \"@itwin/ecschema-metadata\";\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { ECClasses } from \"./ECClasses\";\nimport { MutableCAClass } from \"./Mutable/MutableCAClass\";\n\n/**\n * @alpha\n * A class extending ECClasses allowing you to create schema items of type CustomAttributeClass.\n */\nexport class CustomAttributes extends ECClasses {\n public constructor(_schemaEditor: SchemaContextEditor) {\n super(_schemaEditor);\n }\n\n public async create(schemaKey: SchemaKey, name: string, containerType: CustomAttributeContainerType, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n const newClass = (await schema.createCustomAttributeClass(name)) as MutableCAClass;\n if (newClass === undefined)\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\n\n if (baseClass !== undefined) {\n const baseClassItem = await schema.lookupItem<ECClass>(baseClass);\n if (baseClassItem === undefined)\n return { errorMessage: `Unable to locate base class ${baseClass.fullName} in schema ${schema.fullName}.` };\n\n if (baseClassItem.schemaItemType !== SchemaItemType.CustomAttributeClass)\n return { errorMessage: `${baseClassItem.fullName} is not of type CustomAttribute Class.` };\n\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);\n }\n\n if (displayLabel)\n newClass.setDisplayLabel(displayLabel);\n\n newClass.setContainerType(containerType);\n\n return { itemKey: newClass.key };\n }\n\n /**\n * Creates a CustomAttributeClass through a CustomAttributeClassProps.\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\n * @param caProps a json object that will be used to populate the new CustomAttributeClass. Needs a name value passed in.\n */\n public async createFromProps(schemaKey: SchemaKey, caProps: CustomAttributeClassProps): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\n\n if (caProps.name === undefined)\n return { errorMessage: `No name was supplied within props.` };\n\n const newClass = (await schema.createCustomAttributeClass(caProps.name)) as MutableCAClass;\n if (newClass === undefined)\n return { errorMessage: `Failed to create class ${caProps.name} in schema ${schemaKey.toString(true)}.` };\n\n await newClass.fromJSON(caProps);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,GAAG,IAAI,2CAAuB,CAAyB,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,CAAC;SAChH;QAED,IAAI,YAAY;YACd,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;QAEzC,QAAQ,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAEzC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,eAAe,CAAC,SAAoB,EAAE,OAAkC;QACnF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YACtB,OAAO,EAAE,YAAY,EAAE,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAEzF,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAC5B,OAAO,EAAE,YAAY,EAAE,oCAAoC,EAAE,CAAC;QAEhE,MAAM,QAAQ,GAAG,CAAC,MAAM,MAAM,CAAC,0BAA0B,CAAC,OAAO,CAAC,IAAI,CAAC,CAAmB,CAAC;QAC3F,IAAI,QAAQ,KAAK,SAAS;YACxB,OAAO,EAAE,YAAY,EAAE,0BAA0B,OAAO,CAAC,IAAI,cAAc,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;QAE3G,MAAM,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEjC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACnC,CAAC;CACF;AAtDD,4CAsDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttributeClassProps, CustomAttributeContainerType, DelayedPromiseWithProps, ECClass,\r\n SchemaItemKey, SchemaItemType, SchemaKey,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { ECClasses } from \"./ECClasses\";\r\nimport { MutableCAClass } from \"./Mutable/MutableCAClass\";\r\n\r\n/**\r\n * @alpha\r\n * A class extending ECClasses allowing you to create schema items of type CustomAttributeClass.\r\n */\r\nexport class CustomAttributes extends ECClasses {\r\n public constructor(_schemaEditor: SchemaContextEditor) {\r\n super(_schemaEditor);\r\n }\r\n\r\n public async create(schemaKey: SchemaKey, name: string, containerType: CustomAttributeContainerType, displayLabel?: string, baseClass?: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n const newClass = (await schema.createCustomAttributeClass(name)) as MutableCAClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n if (baseClass !== undefined) {\r\n const baseClassItem = await schema.lookupItem<ECClass>(baseClass);\r\n if (baseClassItem === undefined)\r\n return { errorMessage: `Unable to locate base class ${baseClass.fullName} in schema ${schema.fullName}.` };\r\n\r\n if (baseClassItem.schemaItemType !== SchemaItemType.CustomAttributeClass)\r\n return { errorMessage: `${baseClassItem.fullName} is not of type CustomAttribute Class.` };\r\n\r\n newClass.baseClass = new DelayedPromiseWithProps<SchemaItemKey, ECClass>(baseClass, async () => baseClassItem);\r\n }\r\n\r\n if (displayLabel)\r\n newClass.setDisplayLabel(displayLabel);\r\n\r\n newClass.setContainerType(containerType);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n\r\n /**\r\n * Creates a CustomAttributeClass through a CustomAttributeClassProps.\r\n * @param schemaKey a SchemaKey of the Schema that will house the new object.\r\n * @param caProps a json object that will be used to populate the new CustomAttributeClass. Needs a name value passed in.\r\n */\r\n public async createFromProps(schemaKey: SchemaKey, caProps: CustomAttributeClassProps): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${schemaKey.toString(true)} not found in context` };\r\n\r\n if (caProps.name === undefined)\r\n return { errorMessage: `No name was supplied within props.` };\r\n\r\n const newClass = (await schema.createCustomAttributeClass(caProps.name)) as MutableCAClass;\r\n if (newClass === undefined)\r\n return { errorMessage: `Failed to create class ${caProps.name} in schema ${schemaKey.toString(true)}.` };\r\n\r\n await newClass.fromJSON(caProps);\r\n\r\n return { itemKey: newClass.key };\r\n }\r\n}\r\n"]}
@@ -1,7 +1,7 @@
1
1
  /** @packageDocumentation
2
2
  * @module Editing
3
3
  */
4
- import { CustomAttribute, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps, PrimitivePropertyProps, PrimitiveType, SchemaItemKey, StructArrayPropertyProps, StructClass, StructPropertyProps } from "@itwin/ecschema-metadata";
4
+ import { CustomAttribute, CustomAttributeContainerProps, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps, PrimitivePropertyProps, PrimitiveType, SchemaItemKey, StructArrayPropertyProps, StructClass, StructPropertyProps } from "@itwin/ecschema-metadata";
5
5
  import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
6
  /**
7
7
  * @alpha
@@ -67,8 +67,15 @@ export declare class ECClasses {
67
67
  * @throws ECObjectsError if `name` does not meet the criteria for a valid EC name
68
68
  */
69
69
  setName(classKey: SchemaItemKey, name: string): Promise<SchemaItemEditResults>;
70
+ /**
71
+ * Sets the Category to the Property.
72
+ * @param classKey The SchemaItemKey of the class.
73
+ * @param propertyName The name of the property.
74
+ * @param categoryKey The SchemaItemKey of the PropertyCategory assigned to the property.
75
+ */
76
+ setPropertyCategory(classKey: SchemaItemKey, propertyName: string, categoryKey: SchemaItemKey): Promise<PropertyEditResults>;
70
77
  private getClass;
71
- private removeCustomAttribute;
78
+ protected removeCustomAttribute(container: CustomAttributeContainerProps, customAttribute: CustomAttribute): void;
72
79
  private findDerivedClasses;
73
80
  }
74
81
  //# sourceMappingURL=ECClasses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ECClasses.d.ts","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACL,eAAe,EAEmC,WAAW,EAAE,wBAAwB,EAAE,2BAA2B,EACpH,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAkB,wBAAwB,EAC9F,WAAW,EAAE,mBAAmB,EACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAK3F;;;GAGG;AACH,qBAAa,SAAS;IAEE,SAAS,CAAC,aAAa,EAAE,mBAAmB;IAAlE,SAAS,aAAuB,aAAa,EAAE,mBAAmB;IAElE;;;;;;OAMG;IACU,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAsBrI;;;;;OAKG;IACU,uBAAuB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAYjH,gCAAgC,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,sBAAsB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAalK,yBAAyB,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgBjH,kCAAkC,CAAC,Q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a,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAsB3H,QAAQ;IAuBtB,SAAS,CAAC,qBAAqB,CAAC,SAAS,EAAE,6BAA6B,EAAE,eAAe,EAAE,eAAe;YAM5F,kBAAkB;CAejC"}
@@ -332,6 +332,31 @@ class ECClasses {
332
332
  mutableClass.setName(name);
333
333
  return {};
334
334
  }
335
+ /**
336
+ * Sets the Category to the Property.
337
+ * @param classKey The SchemaItemKey of the class.
338
+ * @param propertyName The name of the property.
339
+ * @param categoryKey The SchemaItemKey of the PropertyCategory assigned to the property.
340
+ */
341
+ async setPropertyCategory(classKey, propertyName, categoryKey) {
342
+ let mutableClass;
343
+ try {
344
+ mutableClass = await this.getClass(classKey);
345
+ }
346
+ catch (e) {
347
+ return { errorMessage: e.message };
348
+ }
349
+ const property = await mutableClass.getProperty(propertyName);
350
+ if (property === undefined) {
351
+ return { errorMessage: `An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };
352
+ }
353
+ const category = await mutableClass.schema.lookupItem(categoryKey);
354
+ if (category === undefined) {
355
+ return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${mutableClass.schema.fullName}.` };
356
+ }
357
+ property.setCategory(new ecschema_metadata_1.DelayedPromiseWithProps(categoryKey, async () => category));
358
+ return { itemKey: classKey, propertyName };
359
+ }
335
360
  async getClass(classKey) {
336
361
  const schema = await this._schemaEditor.getSchema(classKey.schemaKey);
337
362
  if (schema === undefined)
@@ -1 +1 @@
1
- {"version":3,"file":"ECClasses.js","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAMkC;AAClC,sDAA6C;AAG7C,+CAA+C;AAG/C;;;GAGG;AACH,MAAa,SAAS;IAEpB,YAAgC,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAEvE;;;;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,kCAAc,CAAC,KAAK,CAAC;YAC1B,KAAK,kCAAc,CAAC,WAAW,CAAC;YAChC,KAAK,kCAAc,CAAC,oBAAoB,CAAC;YACzC,KAAK,kCAAc,CAAC,iBAAiB;gBACnC,MAAM;YACR;gBACE,MAAM,IAAI,kCAAc,CAAC,mCAAe,CAAC,qBAAqB,EAAE,gCAAgC,CAAC,CAAC;SACrG;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,qBAAqB,CAAC,SAAwC,EAAE,eAAgC;QACtG,IAAA,qBAAM,EAAC,SAAS,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,SAAS,CAAC,gBAAgD,CAAC;QACvE,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,YAA0B;QACzD,MAAM,cAAc,GAAwB,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;QACtE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,CAAC,IAAI,EAAE;YACZ,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE;gBAChC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC5B;aACF;YACD,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;SACxC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAvZD,8BAuZC","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 CustomAttribute,\n CustomAttributeContainerProps,\n ECClass, ECName, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps,\n PrimitivePropertyProps, PrimitiveType, SchemaItemKey, SchemaItemType, StructArrayPropertyProps,\n StructClass, StructPropertyProps,\n} from \"@itwin/ecschema-metadata\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\nimport { MutableClass } from \"./Mutable/MutableClass\";\nimport * as Rules from \"../Validation/ECRules\";\nimport { MutableProperty } from \"./Mutable/MutableProperty\";\n\n/**\n * @alpha\n * Acts as a base class for schema class creation. Enables property creation.\n */\nexport class ECClasses {\n\n protected constructor(protected _schemaEditor: SchemaContextEditor) { }\n\n /**\n * Creates a property on class identified by the given SchemaItemKey. This method restricts the\n * property type to primitives of type Double, String, DateTime and Integer.\n * @param classKey The SchemaItemKey of the class.\n * @param name The name of the new property.\n * @param type The PrimitiveType assigned to the new property.\n */\n public async createProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType, prefix: string): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n\n if (type !== PrimitiveType.Double && type !== PrimitiveType.String && type !== PrimitiveType.DateTime\n && type !== PrimitiveType.Integer)\n throw new Error (\"Property creation is restricted to type Double, String, DateTime, and Integer.\");\n\n if (\"\" === prefix)\n throw new Error(\"The specified property name prefix is invalid\");\n\n const prefixedName = `${prefix}_${name}`;\n\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.createPrimitiveProperty(prefixedName, type);\n return { itemKey: classKey, propertyName: prefixedName };\n }\n\n /**\n * Create a primitive property on class identified by the given SchemaItemKey.\n * @param classKey The SchemaItemKey of the class.\n * @param name The name of the new property.\n * @param type The PrimitiveType assigned to the new property.\n */\n public async createPrimitiveProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.createPrimitiveProperty(name, type);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createPrimitivePropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitivePropertyProps): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\n await newProperty.fromJSON(primitiveProps);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createEnumerationProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const enumSchemaItemKey = mutableClass.schema.getSchemaItemKey(type.fullName);\n if (enumSchemaItemKey === undefined)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${type.fullName}.`);\n\n await mutableClass.createPrimitiveProperty(name, type);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createEnumerationPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, enumProps: EnumerationPropertyProps): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\n await newProperty.fromJSON(enumProps);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createPrimitiveArrayProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.createPrimitiveArrayProperty(name, type);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createPrimitiveArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\n await newProperty.fromJSON(primitiveProps);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createEnumerationArrayProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.createPrimitiveArrayProperty(name, type);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createEnumerationArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, props: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\n await newProperty.fromJSON(props);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createStructProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.createStructProperty(name, type);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createStructPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructPropertyProps): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const newProperty = await mutableClass.createStructProperty(name, type);\n await newProperty.fromJSON(structProps);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createStructArrayProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.createStructArrayProperty(name, type);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async createStructArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructArrayPropertyProps): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const newProperty = await mutableClass.createStructArrayProperty(name, type);\n await newProperty.fromJSON(structProps);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async deleteProperty(classKey: SchemaItemKey, name: string): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n await mutableClass.deleteProperty(name);\n return { itemKey: classKey, propertyName: name };\n }\n\n public async delete(classKey: SchemaItemKey): Promise<SchemaItemEditResults> {\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\n if (schema === undefined)\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\n\n const ecClass = await schema.getItem<ECClass>(classKey.name);\n if (ecClass === undefined)\n return {};\n\n await schema.deleteClass(ecClass.name);\n\n return { itemKey: classKey };\n }\n\n /**\n * Adds a CustomAttribute instance to the Class identified by the given SchemaItemKey\n * @param classKey The SchemaItemKey identifying the schema.\n * @param customAttribute The CustomAttribute instance to add.\n */\n public async addCustomAttribute(classKey: SchemaItemKey, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n mutableClass.addCustomAttribute(customAttribute);\n\n const diagnostics = Rules.validateCustomAttributeInstance(mutableClass, customAttribute);\n\n const result: SchemaItemEditResults = { 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(mutableClass, customAttribute);\n return result;\n }\n\n return {};\n }\n\n /**\n * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.\n * @param classKey The SchemaItemKey identifying the class.\n * @param propertyName The name of the property.\n * @param customAttribute The CustomAttribute instance to add.\n */\n public async addCustomAttributeToProperty(classKey: SchemaItemKey, propertyName: string, customAttribute: CustomAttribute): Promise<PropertyEditResults> {\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const property = await mutableClass.getProperty(propertyName) as MutableProperty;\n if (!property) {\n return { errorMessage: `Property with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };\n }\n\n property.addCustomAttribute(customAttribute);\n\n const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);\n\n const result: SchemaItemEditResults = { 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(property, customAttribute);\n return result;\n }\n\n return {};\n }\n\n /**\n * Renames the property on the specified class. The rename will fail if the new\n * name causes a conflict with a base or derived property. All derived classes\n * containing a property override will be renamed, as well.\n * @param classKey The SchemaItemKey identifying the class.\n * @param existingPropertyName The name of the property.\n * @param newPropertyName The new property name.\n */\n public async setPropertyName(classKey: SchemaItemKey, existingPropertyName: string, newPropertyName: string): Promise<PropertyEditResults> {\n const newName = new ECName(newPropertyName);\n\n let mutableClass: MutableClass;\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n\n const existingProperty = await mutableClass.getProperty(existingPropertyName) as MutableProperty;\n if (!existingProperty) {\n return { errorMessage: `An ECProperty with the name ${existingPropertyName} could not be found in the class ${classKey.fullName}.` };\n }\n\n const baseProperty = await mutableClass.getProperty(newPropertyName, true) as MutableProperty;\n if (baseProperty)\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.` };\n\n // Handle derived classes\n const derivedProperties: Array<MutableProperty> = [];\n const derivedClasses = await this.findDerivedClasses(mutableClass);\n for (const derivedClass of derivedClasses) {\n if (await derivedClass.getProperty(newPropertyName))\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.` };\n\n const propertyOverride = await derivedClass.getProperty(existingPropertyName) as MutableProperty;\n // If found the property is overridden in the derived class.\n if (propertyOverride)\n derivedProperties.push(propertyOverride);\n }\n\n // Re-name the overridden property in all derived classes\n derivedProperties.forEach((prop: MutableProperty) => {\n prop.setName(newName);\n });\n\n existingProperty.setName(newName);\n\n return { itemKey: classKey, propertyName: newName.name };\n }\n\n /**\n * Sets the name of the ECClass.\n * @param classKey The SchemaItemKey of the class.\n * @param name The new name of the class.\n * @throws ECObjectsError if `name` does not meet the criteria for a valid EC name\n */\n public async setName(classKey: SchemaItemKey, name: string): Promise<SchemaItemEditResults> {\n let mutableClass: MutableClass;\n\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\n if (schema === undefined) {\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\n }\n\n const ecClass = await schema.getItem<MutableClass>(name);\n if (ecClass !== undefined)\n return { errorMessage: `An EC Class with the name ${name} already exists within the schema ${schema.name}` };\n\n try {\n mutableClass = await this.getClass(classKey);\n } catch (e: any) {\n return { errorMessage: e.message };\n }\n mutableClass.setName(name);\n\n return {};\n }\n\n private async getClass(classKey: SchemaItemKey): Promise<MutableClass> {\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\n if (schema === undefined)\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${classKey.schemaKey.toString(true)} not found in context`);\n\n const ecClass = await schema.getItem<MutableClass>(classKey.name);\n if (ecClass === undefined)\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);\n\n switch (ecClass.schemaItemType) {\n case SchemaItemType.EntityClass:\n case SchemaItemType.Mixin:\n case SchemaItemType.StructClass:\n case SchemaItemType.CustomAttributeClass:\n case SchemaItemType.RelationshipClass:\n break;\n default:\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);\n }\n\n return ecClass;\n }\n\n private removeCustomAttribute(container: CustomAttributeContainerProps, customAttribute: CustomAttribute) {\n assert(container.customAttributes !== undefined);\n const map = container.customAttributes as Map<string, CustomAttribute>;\n map.delete(customAttribute.className);\n }\n\n private async findDerivedClasses(mutableClass: MutableClass): Promise<Array<MutableClass>>{\n const derivedClasses: Array<MutableClass> = [];\n const schemaItems = this._schemaEditor.schemaContext.getSchemaItems();\n let { value, done } = schemaItems.next();\n while (!done) {\n if (await value.is(mutableClass)) {\n if (!mutableClass.key.matches(value.key)) {\n derivedClasses.push(value);\n }\n }\n ({ value, done } = schemaItems.next());\n }\n\n return derivedClasses;\n }\n}\n\n"]}
1
+ {"version":3,"file":"ECClasses.js","sourceRoot":"","sources":["../../../src/Editing/ECClasses.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gEAOkC;AAClC,sDAA6C;AAG7C,+CAA+C;AAG/C;;;GAGG;AACH,MAAa,SAAS;IAEpB,YAAgC,aAAkC;QAAlC,kBAAa,GAAb,aAAa,CAAqB;IAAI,CAAC;IAEvE;;;;;;OAMG;IACI,KAAK,CAAC,cAAc,CAAC,QAAuB,EAAE,IAAY,EAAE,IAAmB,EAAE,MAAc;QACpG,IAAI,YAA0B,CAAC;QAE/B,IAAI,IAAI,KAAK,iCAAa,CAAC,MAAM,IAAI,IAAI,KAAK,iCAAa,CAAC,MAAM,IAAI,IAAI,KAAK,iCAAa,CAAC,QAAQ;e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,CAAC,YAA0B;QACzD,MAAM,cAAc,GAAwB,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;QACtE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC;QACzC,OAAO,CAAC,IAAI,EAAE;YACZ,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE;gBAChC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;oBACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBAC5B;aACF;YACD,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;SACxC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;CACF;AAnbD,8BAmbC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport {\r\n CustomAttribute,\r\n CustomAttributeContainerProps,\r\n DelayedPromiseWithProps,\r\n ECClass, ECName, ECObjectsError, ECObjectsStatus, Enumeration, EnumerationPropertyProps, PrimitiveArrayPropertyProps,\r\n PrimitivePropertyProps, PrimitiveType, PropertyCategory, SchemaItemKey, SchemaItemType, StructArrayPropertyProps,\r\n StructClass, StructPropertyProps,\r\n} from \"@itwin/ecschema-metadata\";\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from \"./Editor\";\r\nimport { MutableClass } from \"./Mutable/MutableClass\";\r\nimport * as Rules from \"../Validation/ECRules\";\r\nimport { MutableProperty } from \"./Mutable/MutableProperty\";\r\n\r\n/**\r\n * @alpha\r\n * Acts as a base class for schema class creation. Enables property creation.\r\n */\r\nexport class ECClasses {\r\n\r\n protected constructor(protected _schemaEditor: SchemaContextEditor) { }\r\n\r\n /**\r\n * Creates a property on class identified by the given SchemaItemKey. This method restricts the\r\n * property type to primitives of type Double, String, DateTime and Integer.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The name of the new property.\r\n * @param type The PrimitiveType assigned to the new property.\r\n */\r\n public async createProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType, prefix: string): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n\r\n if (type !== PrimitiveType.Double && type !== PrimitiveType.String && type !== PrimitiveType.DateTime\r\n && type !== PrimitiveType.Integer)\r\n throw new Error (\"Property creation is restricted to type Double, String, DateTime, and Integer.\");\r\n\r\n if (\"\" === prefix)\r\n throw new Error(\"The specified property name prefix is invalid\");\r\n\r\n const prefixedName = `${prefix}_${name}`;\r\n\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveProperty(prefixedName, type);\r\n return { itemKey: classKey, propertyName: prefixedName };\r\n }\r\n\r\n /**\r\n * Create a primitive property on class identified by the given SchemaItemKey.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The name of the new property.\r\n * @param type The PrimitiveType assigned to the new property.\r\n */\r\n public async createPrimitiveProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitivePropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitivePropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\r\n await newProperty.fromJSON(primitiveProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const enumSchemaItemKey = mutableClass.schema.getSchemaItemKey(type.fullName);\r\n if (enumSchemaItemKey === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the enumeration ${type.fullName}.`);\r\n\r\n await mutableClass.createPrimitiveProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, enumProps: EnumerationPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveProperty(name, type);\r\n await newProperty.fromJSON(enumProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitiveArrayProperty(classKey: SchemaItemKey, name: string, type: PrimitiveType): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createPrimitiveArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: PrimitiveType, primitiveProps: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\r\n await newProperty.fromJSON(primitiveProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationArrayProperty(classKey: SchemaItemKey, name: string, type: Enumeration): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createPrimitiveArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createEnumerationArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: Enumeration, props: PrimitiveArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createPrimitiveArrayProperty(name, type);\r\n await newProperty.fromJSON(props);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createStructProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createStructProperty(name, type);\r\n await newProperty.fromJSON(structProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructArrayProperty(classKey: SchemaItemKey, name: string, type: StructClass): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.createStructArrayProperty(name, type);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async createStructArrayPropertyFromProps(classKey: SchemaItemKey, name: string, type: StructClass, structProps: StructArrayPropertyProps): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const newProperty = await mutableClass.createStructArrayProperty(name, type);\r\n await newProperty.fromJSON(structProps);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async deleteProperty(classKey: SchemaItemKey, name: string): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n await mutableClass.deleteProperty(name);\r\n return { itemKey: classKey, propertyName: name };\r\n }\r\n\r\n public async delete(classKey: SchemaItemKey): Promise<SchemaItemEditResults> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n if (schema === undefined)\r\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\r\n\r\n const ecClass = await schema.getItem<ECClass>(classKey.name);\r\n if (ecClass === undefined)\r\n return {};\r\n\r\n await schema.deleteClass(ecClass.name);\r\n\r\n return { itemKey: classKey };\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Class identified by the given SchemaItemKey\r\n * @param classKey The SchemaItemKey identifying the schema.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttribute(classKey: SchemaItemKey, customAttribute: CustomAttribute): Promise<SchemaItemEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n mutableClass.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(mutableClass, customAttribute);\r\n\r\n const result: SchemaItemEditResults = { 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(mutableClass, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Adds a CustomAttribute instance to the Property identified by the given SchemaItemKey and property name.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param propertyName The name of the property.\r\n * @param customAttribute The CustomAttribute instance to add.\r\n */\r\n public async addCustomAttributeToProperty(classKey: SchemaItemKey, propertyName: string, customAttribute: CustomAttribute): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const property = await mutableClass.getProperty(propertyName) as MutableProperty;\r\n if (!property) {\r\n return { errorMessage: `Property with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n property.addCustomAttribute(customAttribute);\r\n\r\n const diagnostics = Rules.validateCustomAttributeInstance(property, customAttribute);\r\n\r\n const result: SchemaItemEditResults = { 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(property, customAttribute);\r\n return result;\r\n }\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Renames the property on the specified class. The rename will fail if the new\r\n * name causes a conflict with a base or derived property. All derived classes\r\n * containing a property override will be renamed, as well.\r\n * @param classKey The SchemaItemKey identifying the class.\r\n * @param existingPropertyName The name of the property.\r\n * @param newPropertyName The new property name.\r\n */\r\n public async setPropertyName(classKey: SchemaItemKey, existingPropertyName: string, newPropertyName: string): Promise<PropertyEditResults> {\r\n const newName = new ECName(newPropertyName);\r\n\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const existingProperty = await mutableClass.getProperty(existingPropertyName) as MutableProperty;\r\n if (!existingProperty) {\r\n return { errorMessage: `An ECProperty with the name ${existingPropertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n const baseProperty = await mutableClass.getProperty(newPropertyName, true) as MutableProperty;\r\n if (baseProperty)\r\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${baseProperty.class.name}.` };\r\n\r\n // Handle derived classes\r\n const derivedProperties: Array<MutableProperty> = [];\r\n const derivedClasses = await this.findDerivedClasses(mutableClass);\r\n for (const derivedClass of derivedClasses) {\r\n if (await derivedClass.getProperty(newPropertyName))\r\n return { errorMessage: `An ECProperty with the name ${newPropertyName} already exists in the class ${derivedClass.fullName}.` };\r\n\r\n const propertyOverride = await derivedClass.getProperty(existingPropertyName) as MutableProperty;\r\n // If found the property is overridden in the derived class.\r\n if (propertyOverride)\r\n derivedProperties.push(propertyOverride);\r\n }\r\n\r\n // Re-name the overridden property in all derived classes\r\n derivedProperties.forEach((prop: MutableProperty) => {\r\n prop.setName(newName);\r\n });\r\n\r\n existingProperty.setName(newName);\r\n\r\n return { itemKey: classKey, propertyName: newName.name };\r\n }\r\n\r\n /**\r\n * Sets the name of the ECClass.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param name The new name of the class.\r\n * @throws ECObjectsError if `name` does not meet the criteria for a valid EC name\r\n */\r\n public async setName(classKey: SchemaItemKey, name: string): Promise<SchemaItemEditResults> {\r\n let mutableClass: MutableClass;\r\n\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n if (schema === undefined) {\r\n return { errorMessage: `Schema Key ${classKey.schemaKey.toString(true)} not found in context` };\r\n }\r\n\r\n const ecClass = await schema.getItem<MutableClass>(name);\r\n if (ecClass !== undefined)\r\n return { errorMessage: `An EC Class with the name ${name} already exists within the schema ${schema.name}` };\r\n\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n mutableClass.setName(name);\r\n\r\n return {};\r\n }\r\n\r\n /**\r\n * Sets the Category to the Property.\r\n * @param classKey The SchemaItemKey of the class.\r\n * @param propertyName The name of the property.\r\n * @param categoryKey The SchemaItemKey of the PropertyCategory assigned to the property.\r\n */\r\n public async setPropertyCategory(classKey: SchemaItemKey, propertyName: string, categoryKey: SchemaItemKey): Promise<PropertyEditResults> {\r\n let mutableClass: MutableClass;\r\n try {\r\n mutableClass = await this.getClass(classKey);\r\n } catch (e: any) {\r\n return { errorMessage: e.message };\r\n }\r\n\r\n const property = await mutableClass.getProperty(propertyName) as MutableProperty;\r\n if (property === undefined) {\r\n return { errorMessage: `An ECProperty with the name ${propertyName} could not be found in the class ${classKey.fullName}.` };\r\n }\r\n\r\n const category = await mutableClass.schema.lookupItem<PropertyCategory>(categoryKey);\r\n if (category === undefined) {\r\n return { errorMessage: `Can't locate the Property Category ${categoryKey.fullName} in the schema ${mutableClass.schema.fullName}.` };\r\n }\r\n\r\n property.setCategory(new DelayedPromiseWithProps<SchemaItemKey, PropertyCategory>(categoryKey, async () => category));\r\n return { itemKey: classKey, propertyName };\r\n }\r\n\r\n private async getClass(classKey: SchemaItemKey): Promise<MutableClass> {\r\n const schema = await this._schemaEditor.getSchema(classKey.schemaKey);\r\n if (schema === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.UnableToLocateSchema,`Schema Key ${classKey.schemaKey.toString(true)} not found in context`);\r\n\r\n const ecClass = await schema.getItem<MutableClass>(classKey.name);\r\n if (ecClass === undefined)\r\n throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `Class ${classKey.name} was not found in schema ${classKey.schemaKey.toString(true)}`);\r\n\r\n switch (ecClass.schemaItemType) {\r\n case SchemaItemType.EntityClass:\r\n case SchemaItemType.Mixin:\r\n case SchemaItemType.StructClass:\r\n case SchemaItemType.CustomAttributeClass:\r\n case SchemaItemType.RelationshipClass:\r\n break;\r\n default:\r\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Schema item type not supported`);\r\n }\r\n\r\n return ecClass;\r\n }\r\n\r\n protected removeCustomAttribute(container: CustomAttributeContainerProps, customAttribute: CustomAttribute) {\r\n assert(container.customAttributes !== undefined);\r\n const map = container.customAttributes as Map<string, CustomAttribute>;\r\n map.delete(customAttribute.className);\r\n }\r\n\r\n private async findDerivedClasses(mutableClass: MutableClass): Promise<Array<MutableClass>>{\r\n const derivedClasses: Array<MutableClass> = [];\r\n const schemaItems = this._schemaEditor.schemaContext.getSchemaItems();\r\n let { value, done } = schemaItems.next();\r\n while (!done) {\r\n if (await value.is(mutableClass)) {\r\n if (!mutableClass.key.matches(value.key)) {\r\n derivedClasses.push(value);\r\n }\r\n }\r\n ({ value, done } = schemaItems.next());\r\n }\r\n\r\n return derivedClasses;\r\n }\r\n}\r\n\r\n"]}
@@ -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,gEAA6H;AAE7H,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,+CAA4C;AA6B5C;;;GAGG;AACH,MAAa,mBAAmB;IAoB9B;;;OAGG;IACH,YAAY,aAA4B;QAtBxB,aAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QA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IACxC,CAAC;CACF;AAhKD,kDAgKC","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, 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\";\nimport { SchemaItems } from \"./SchemaItems\";\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 /** @internal */\n public readonly schemaItems = new SchemaItems(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 | undefined> {\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\n if (schema === undefined)\n return undefined;\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"]}
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,gEAA6H;AAE7H,sDAA6C;AAC7C,2CAAwC;AACxC,yDAAsD;AACtD,yCAAsC;AACtC,iDAA8C;AAC9C,uCAAoC;AACpC,mDAAgD;AAChD,yDAAsD;AACtD,qCAAkC;AAClC,2CAAwC;AACxC,6DAA0D;AAC1D,+DAA4D;AAC5D,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,+CAA4C;AA6B5C;;;GAGG;AACH,MAAa,mBAAmB;IAoB9B;;;OAGG;IACH,YAAY,aAA4B;QAtBxB,aAAQ,GAAG,IAAI,mBAAQ,CAAC,IAAI,CAAC,CAAC;QAC9B,WAAM,GAAG,IAAI,eAAM,CAAC,IAAI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":["/*---------------------------------------------------------------------------------------------\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, 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\nimport { SchemaItems } from \"./SchemaItems\";\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 /** @internal */\r\n public readonly schemaItems = new SchemaItems(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 | undefined> {\r\n const schema = (await this.schemaContext.getCachedSchema<MutableSchema>(schemaKey, SchemaMatchType.Latest));\r\n if (schema === undefined)\r\n return undefined;\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,7 +1,7 @@
1
1
  /** @packageDocumentation
2
2
  * @module Editing
3
3
  */
4
- import { ECClassModifier, EntityClassProps, Mixin, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
4
+ import { ECClassModifier, EntityClassProps, Mixin, NavigationPropertyProps, RelationshipClass, SchemaItemKey, SchemaKey, StrengthDirection } from "@itwin/ecschema-metadata";
5
5
  import { PropertyEditResults, SchemaContextEditor, SchemaItemEditResults } from "./Editor";
6
6
  import { ECClasses } from "./ECClasses";
7
7
  /**
@@ -20,8 +20,14 @@ export declare class Entities extends ECClasses {
20
20
  * @param entityProps a json object that will be used to populate the new EntityClass. Needs a name value passed in.
21
21
  */
22
22
  createFromProps(schemaKey: SchemaKey, entityProps: EntityClassProps): Promise<SchemaItemEditResults>;
23
- addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<void>;
23
+ addMixin(entityKey: SchemaItemKey, mixinKey: SchemaItemKey): Promise<SchemaItemEditResults>;
24
24
  createNavigationProperty(entityKey: SchemaItemKey, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<PropertyEditResults>;
25
+ /**
26
+ * Creates a Navigation Property through a NavigationPropertyProps.
27
+ * @param classKey a SchemaItemKey of the Entity Class that will house the new property.
28
+ * @param navigationProps a json object that will be used to populate the new Navigation Property.
29
+ */
30
+ createNavigationPropertyFromProps(classKey: SchemaItemKey, navigationProps: NavigationPropertyProps): Promise<PropertyEditResults>;
25
31
  /**
26
32
  * Sets the base class of an Entity.
27
33
  * @param entityKey The SchemaItemKey of the Entity.