@itwin/ecschema-metadata 3.6.0-dev.8 → 3.6.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 (142) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/Constants.d.ts +23 -23
  4. package/lib/cjs/Constants.js +33 -33
  5. package/lib/cjs/Constants.js.map +1 -1
  6. package/lib/cjs/Context.d.ts +139 -139
  7. package/lib/cjs/Context.js +204 -204
  8. package/lib/cjs/DelayedPromise.d.ts +88 -88
  9. package/lib/cjs/DelayedPromise.js +91 -91
  10. package/lib/cjs/DelayedPromise.js.map +1 -1
  11. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  12. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  13. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  14. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  15. package/lib/cjs/Deserialization/Helper.js +843 -843
  16. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  17. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  18. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  19. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  20. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  21. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  22. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  23. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  24. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  25. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  26. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  27. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  28. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  29. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  30. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  31. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  32. package/lib/cjs/ECName.d.ts +30 -30
  33. package/lib/cjs/ECName.js +85 -85
  34. package/lib/cjs/ECName.js.map +1 -1
  35. package/lib/cjs/ECObjects.d.ts +162 -162
  36. package/lib/cjs/ECObjects.js +453 -453
  37. package/lib/cjs/ECObjects.js.map +1 -1
  38. package/lib/cjs/Exception.d.ts +43 -43
  39. package/lib/cjs/Exception.js +86 -86
  40. package/lib/cjs/Exception.js.map +1 -1
  41. package/lib/cjs/Interfaces.d.ts +66 -66
  42. package/lib/cjs/Interfaces.js +9 -9
  43. package/lib/cjs/Interfaces.js.map +1 -1
  44. package/lib/cjs/Metadata/Class.d.ts +243 -243
  45. package/lib/cjs/Metadata/Class.js +558 -558
  46. package/lib/cjs/Metadata/Class.js.map +1 -1
  47. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  48. package/lib/cjs/Metadata/Constant.js +123 -123
  49. package/lib/cjs/Metadata/Constant.js.map +1 -1
  50. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  51. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  52. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  53. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  54. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  55. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  56. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  57. package/lib/cjs/Metadata/EntityClass.js +230 -230
  58. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  59. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  60. package/lib/cjs/Metadata/Enumeration.js +159 -159
  61. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  62. package/lib/cjs/Metadata/Format.d.ts +98 -98
  63. package/lib/cjs/Metadata/Format.js +242 -242
  64. package/lib/cjs/Metadata/Format.js.map +1 -1
  65. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  66. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  67. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  68. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  69. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  70. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  71. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  72. package/lib/cjs/Metadata/Mixin.js +113 -113
  73. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  74. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  75. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  76. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  77. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  78. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  79. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  80. package/lib/cjs/Metadata/Property.d.ts +197 -197
  81. package/lib/cjs/Metadata/Property.js +491 -491
  82. package/lib/cjs/Metadata/Property.js.map +1 -1
  83. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  84. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  85. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  86. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  87. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  88. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  89. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  90. package/lib/cjs/Metadata/Schema.js +520 -520
  91. package/lib/cjs/Metadata/Schema.js.map +1 -1
  92. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  93. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  94. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  95. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  96. package/lib/cjs/Metadata/Unit.js +162 -162
  97. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  98. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  99. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  100. package/lib/cjs/PropertyTypes.d.ts +49 -49
  101. package/lib/cjs/PropertyTypes.js +91 -91
  102. package/lib/cjs/PropertyTypes.js.map +1 -1
  103. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  104. package/lib/cjs/SchemaJsonLocater.js +42 -42
  105. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  106. package/lib/cjs/SchemaKey.d.ts +110 -110
  107. package/lib/cjs/SchemaKey.js +219 -219
  108. package/lib/cjs/SchemaKey.js.map +1 -1
  109. package/lib/cjs/SchemaLoader.d.ts +23 -23
  110. package/lib/cjs/SchemaLoader.js +47 -47
  111. package/lib/cjs/SchemaLoader.js.map +1 -1
  112. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  113. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  114. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  115. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  116. package/lib/cjs/UnitConversion/Graph.js +83 -83
  117. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  118. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  119. package/lib/cjs/UnitConversion/Parser.js +42 -42
  120. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  121. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  122. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  123. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  124. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  125. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  126. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  127. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  128. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  129. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  130. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  131. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +236 -236
  132. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  133. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  134. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  135. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  136. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  137. package/lib/cjs/ecschema-metadata.js +96 -96
  138. package/lib/cjs/ecschema-metadata.js.map +1 -1
  139. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  140. package/lib/cjs/utils/SchemaGraph.js +65 -65
  141. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  142. package/package.json +7 -7
@@ -1,231 +1,231 @@
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 Metadata
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.createNavigationPropertySync = exports.createNavigationProperty = exports.MutableEntityClass = exports.EntityClass = void 0;
11
- const DelayedPromise_1 = require("../DelayedPromise");
12
- const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
13
- const ECObjects_1 = require("../ECObjects");
14
- const Exception_1 = require("../Exception");
15
- const Class_1 = require("./Class");
16
- const Property_1 = require("./Property");
17
- /**
18
- * A Typescript class representation of an ECEntityClass.
19
- * @beta
20
- */
21
- class EntityClass extends Class_1.ECClass {
22
- constructor(schema, name, modifier) {
23
- super(schema, name, modifier);
24
- this.schemaItemType = ECObjects_1.SchemaItemType.EntityClass;
25
- }
26
- get mixins() {
27
- if (!this._mixins)
28
- return [];
29
- return this._mixins;
30
- }
31
- *getMixinsSync() {
32
- if (!this._mixins)
33
- return function* () { }(); // empty iterable
34
- for (const mixin of this._mixins) {
35
- const mObj = this.schema.lookupItemSync(mixin);
36
- if (mObj) {
37
- yield mObj;
38
- }
39
- }
40
- }
41
- /**
42
- *
43
- * @param mixin
44
- */
45
- addMixin(mixin) {
46
- if (!this._mixins)
47
- this._mixins = [];
48
- this._mixins.push(new DelayedPromise_1.DelayedPromiseWithProps(mixin.key, async () => mixin));
49
- return;
50
- }
51
- /**
52
- * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.
53
- * @param name The name of the property to find.
54
- */
55
- async getInheritedProperty(name) {
56
- let inheritedProperty = await super.getInheritedProperty(name);
57
- if (!inheritedProperty && this._mixins) {
58
- const mixinProps = await Promise.all(this._mixins.map(async (mixin) => (await mixin).getProperty(name)));
59
- mixinProps.some((prop) => {
60
- inheritedProperty = prop;
61
- return inheritedProperty !== undefined;
62
- });
63
- }
64
- return inheritedProperty;
65
- }
66
- /**
67
- * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.
68
- * @param name The name of the property to find.
69
- */
70
- getInheritedPropertySync(name) {
71
- const inheritedProperty = super.getInheritedPropertySync(name);
72
- if (inheritedProperty)
73
- return inheritedProperty;
74
- if (!this._mixins) {
75
- return undefined;
76
- }
77
- for (const mixin of this._mixins) {
78
- const mObj = this.schema.lookupItemSync(mixin);
79
- if (mObj) {
80
- const result = mObj.getPropertySync(name, true);
81
- if (result) {
82
- return result;
83
- }
84
- }
85
- }
86
- return undefined;
87
- }
88
- async buildPropertyCache(result, existingValues, resetBaseCaches = false) {
89
- if (!existingValues) {
90
- existingValues = new Map();
91
- }
92
- if (this.baseClass) {
93
- Class_1.ECClass.mergeProperties(result, existingValues, await (await this.baseClass).getProperties(resetBaseCaches), false);
94
- }
95
- for (const mixin of this.mixins) {
96
- Class_1.ECClass.mergeProperties(result, existingValues, await (await mixin).getProperties(resetBaseCaches), false);
97
- }
98
- if (!this.properties)
99
- return;
100
- Class_1.ECClass.mergeProperties(result, existingValues, [...this.properties], true);
101
- }
102
- buildPropertyCacheSync(result, existingValues, resetBaseCaches = false) {
103
- if (!existingValues) {
104
- existingValues = new Map();
105
- }
106
- const baseClass = this.getBaseClassSync();
107
- if (baseClass) {
108
- Class_1.ECClass.mergeProperties(result, existingValues, baseClass.getPropertiesSync(resetBaseCaches), false);
109
- }
110
- for (const mixin of this.getMixinsSync()) {
111
- Class_1.ECClass.mergeProperties(result, existingValues, mixin.getPropertiesSync(resetBaseCaches), false);
112
- }
113
- if (!this.properties)
114
- return;
115
- Class_1.ECClass.mergeProperties(result, existingValues, [...this.properties], true);
116
- }
117
- /**
118
- *
119
- * @param name
120
- * @param relationship
121
- * @param direction
122
- */
123
- async createNavigationProperty(name, relationship, direction) {
124
- return this.addProperty(await createNavigationProperty(this, name, relationship, direction));
125
- }
126
- /**
127
- *
128
- * @param name
129
- * @param relationship
130
- * @param direction
131
- */
132
- createNavigationPropertySync(name, relationship, direction) {
133
- return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));
134
- }
135
- /**
136
- * Save this EntityClass' properties to an object for serializing to JSON.
137
- * @param standalone Serialization includes only this object (as opposed to the full schema).
138
- * @param includeSchemaVersion Include the Schema's version information in the serialized object.
139
- */
140
- toJSON(standalone = false, includeSchemaVersion = false) {
141
- const schemaJson = super.toJSON(standalone, includeSchemaVersion);
142
- if (this.mixins.length > 0)
143
- schemaJson.mixins = this.mixins.map((mixin) => mixin.fullName);
144
- return schemaJson;
145
- }
146
- /** @internal */
147
- async toXml(schemaXml) {
148
- const itemElement = await super.toXml(schemaXml);
149
- for (const mixin of this.getMixinsSync()) {
150
- const mixinElement = schemaXml.createElement("BaseClass");
151
- const mixinName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, mixin.schema, mixin.name);
152
- mixinElement.textContent = mixinName;
153
- itemElement.appendChild(mixinElement);
154
- }
155
- return itemElement;
156
- }
157
- async fromJSON(entityClassProps) {
158
- this.fromJSONSync(entityClassProps);
159
- }
160
- fromJSONSync(entityClassProps) {
161
- super.fromJSONSync(entityClassProps);
162
- if (undefined !== entityClassProps.mixins) {
163
- if (!this._mixins)
164
- this._mixins = [];
165
- for (const name of entityClassProps.mixins) {
166
- const mixinSchemaItemKey = this.schema.getSchemaItemKey(name);
167
- if (!mixinSchemaItemKey)
168
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin ("${name}") that cannot be found.`);
169
- this._mixins.push(new DelayedPromise_1.DelayedPromiseWithProps(mixinSchemaItemKey, async () => {
170
- const mixin = await this.schema.lookupItem(mixinSchemaItemKey);
171
- if (undefined === mixin)
172
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin ("${name}") that cannot be found.`);
173
- return mixin;
174
- }));
175
- }
176
- }
177
- }
178
- }
179
- exports.EntityClass = EntityClass;
180
- /**
181
- * Hackish approach that works like a "friend class" so we can access protected members without making them public.
182
- * @internal
183
- */
184
- class MutableEntityClass extends EntityClass {
185
- }
186
- exports.MutableEntityClass = MutableEntityClass;
187
- /** @internal */
188
- async function createNavigationProperty(ecClass, name, relationship, direction) {
189
- if (await ecClass.getProperty(name))
190
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);
191
- let resolvedRelationship;
192
- if (typeof (relationship) === "string") {
193
- resolvedRelationship = await ecClass.schema.lookupItem(relationship);
194
- }
195
- else
196
- resolvedRelationship = relationship;
197
- if (!resolvedRelationship)
198
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);
199
- if (typeof (direction) === "string") {
200
- const tmpDirection = (0, ECObjects_1.parseStrengthDirection)(direction);
201
- if (undefined === tmpDirection)
202
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);
203
- direction = tmpDirection;
204
- }
205
- const lazyRelationship = new DelayedPromise_1.DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship);
206
- return new Property_1.NavigationProperty(ecClass, name, lazyRelationship, direction);
207
- }
208
- exports.createNavigationProperty = createNavigationProperty;
209
- /** @internal */
210
- function createNavigationPropertySync(ecClass, name, relationship, direction) {
211
- if (ecClass.getPropertySync(name))
212
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);
213
- let resolvedRelationship;
214
- if (typeof (relationship) === "string") {
215
- resolvedRelationship = ecClass.schema.lookupItemSync(relationship);
216
- }
217
- else
218
- resolvedRelationship = relationship;
219
- if (!resolvedRelationship)
220
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);
221
- if (typeof (direction) === "string") {
222
- const tmpDirection = (0, ECObjects_1.parseStrengthDirection)(direction);
223
- if (undefined === tmpDirection)
224
- throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);
225
- direction = tmpDirection;
226
- }
227
- const lazyRelationship = new DelayedPromise_1.DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship);
228
- return new Property_1.NavigationProperty(ecClass, name, lazyRelationship, direction);
229
- }
230
- exports.createNavigationPropertySync = createNavigationPropertySync;
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 Metadata
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.createNavigationPropertySync = exports.createNavigationProperty = exports.MutableEntityClass = exports.EntityClass = void 0;
11
+ const DelayedPromise_1 = require("../DelayedPromise");
12
+ const XmlSerializationUtils_1 = require("../Deserialization/XmlSerializationUtils");
13
+ const ECObjects_1 = require("../ECObjects");
14
+ const Exception_1 = require("../Exception");
15
+ const Class_1 = require("./Class");
16
+ const Property_1 = require("./Property");
17
+ /**
18
+ * A Typescript class representation of an ECEntityClass.
19
+ * @beta
20
+ */
21
+ class EntityClass extends Class_1.ECClass {
22
+ constructor(schema, name, modifier) {
23
+ super(schema, name, modifier);
24
+ this.schemaItemType = ECObjects_1.SchemaItemType.EntityClass;
25
+ }
26
+ get mixins() {
27
+ if (!this._mixins)
28
+ return [];
29
+ return this._mixins;
30
+ }
31
+ *getMixinsSync() {
32
+ if (!this._mixins)
33
+ return function* () { }(); // empty iterable
34
+ for (const mixin of this._mixins) {
35
+ const mObj = this.schema.lookupItemSync(mixin);
36
+ if (mObj) {
37
+ yield mObj;
38
+ }
39
+ }
40
+ }
41
+ /**
42
+ *
43
+ * @param mixin
44
+ */
45
+ addMixin(mixin) {
46
+ if (!this._mixins)
47
+ this._mixins = [];
48
+ this._mixins.push(new DelayedPromise_1.DelayedPromiseWithProps(mixin.key, async () => mixin));
49
+ return;
50
+ }
51
+ /**
52
+ * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.
53
+ * @param name The name of the property to find.
54
+ */
55
+ async getInheritedProperty(name) {
56
+ let inheritedProperty = await super.getInheritedProperty(name);
57
+ if (!inheritedProperty && this._mixins) {
58
+ const mixinProps = await Promise.all(this._mixins.map(async (mixin) => (await mixin).getProperty(name)));
59
+ mixinProps.some((prop) => {
60
+ inheritedProperty = prop;
61
+ return inheritedProperty !== undefined;
62
+ });
63
+ }
64
+ return inheritedProperty;
65
+ }
66
+ /**
67
+ * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.
68
+ * @param name The name of the property to find.
69
+ */
70
+ getInheritedPropertySync(name) {
71
+ const inheritedProperty = super.getInheritedPropertySync(name);
72
+ if (inheritedProperty)
73
+ return inheritedProperty;
74
+ if (!this._mixins) {
75
+ return undefined;
76
+ }
77
+ for (const mixin of this._mixins) {
78
+ const mObj = this.schema.lookupItemSync(mixin);
79
+ if (mObj) {
80
+ const result = mObj.getPropertySync(name, true);
81
+ if (result) {
82
+ return result;
83
+ }
84
+ }
85
+ }
86
+ return undefined;
87
+ }
88
+ async buildPropertyCache(result, existingValues, resetBaseCaches = false) {
89
+ if (!existingValues) {
90
+ existingValues = new Map();
91
+ }
92
+ if (this.baseClass) {
93
+ Class_1.ECClass.mergeProperties(result, existingValues, await (await this.baseClass).getProperties(resetBaseCaches), false);
94
+ }
95
+ for (const mixin of this.mixins) {
96
+ Class_1.ECClass.mergeProperties(result, existingValues, await (await mixin).getProperties(resetBaseCaches), false);
97
+ }
98
+ if (!this.properties)
99
+ return;
100
+ Class_1.ECClass.mergeProperties(result, existingValues, [...this.properties], true);
101
+ }
102
+ buildPropertyCacheSync(result, existingValues, resetBaseCaches = false) {
103
+ if (!existingValues) {
104
+ existingValues = new Map();
105
+ }
106
+ const baseClass = this.getBaseClassSync();
107
+ if (baseClass) {
108
+ Class_1.ECClass.mergeProperties(result, existingValues, baseClass.getPropertiesSync(resetBaseCaches), false);
109
+ }
110
+ for (const mixin of this.getMixinsSync()) {
111
+ Class_1.ECClass.mergeProperties(result, existingValues, mixin.getPropertiesSync(resetBaseCaches), false);
112
+ }
113
+ if (!this.properties)
114
+ return;
115
+ Class_1.ECClass.mergeProperties(result, existingValues, [...this.properties], true);
116
+ }
117
+ /**
118
+ *
119
+ * @param name
120
+ * @param relationship
121
+ * @param direction
122
+ */
123
+ async createNavigationProperty(name, relationship, direction) {
124
+ return this.addProperty(await createNavigationProperty(this, name, relationship, direction));
125
+ }
126
+ /**
127
+ *
128
+ * @param name
129
+ * @param relationship
130
+ * @param direction
131
+ */
132
+ createNavigationPropertySync(name, relationship, direction) {
133
+ return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));
134
+ }
135
+ /**
136
+ * Save this EntityClass' properties to an object for serializing to JSON.
137
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
138
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
139
+ */
140
+ toJSON(standalone = false, includeSchemaVersion = false) {
141
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
142
+ if (this.mixins.length > 0)
143
+ schemaJson.mixins = this.mixins.map((mixin) => mixin.fullName);
144
+ return schemaJson;
145
+ }
146
+ /** @internal */
147
+ async toXml(schemaXml) {
148
+ const itemElement = await super.toXml(schemaXml);
149
+ for (const mixin of this.getMixinsSync()) {
150
+ const mixinElement = schemaXml.createElement("BaseClass");
151
+ const mixinName = XmlSerializationUtils_1.XmlSerializationUtils.createXmlTypedName(this.schema, mixin.schema, mixin.name);
152
+ mixinElement.textContent = mixinName;
153
+ itemElement.appendChild(mixinElement);
154
+ }
155
+ return itemElement;
156
+ }
157
+ async fromJSON(entityClassProps) {
158
+ this.fromJSONSync(entityClassProps);
159
+ }
160
+ fromJSONSync(entityClassProps) {
161
+ super.fromJSONSync(entityClassProps);
162
+ if (undefined !== entityClassProps.mixins) {
163
+ if (!this._mixins)
164
+ this._mixins = [];
165
+ for (const name of entityClassProps.mixins) {
166
+ const mixinSchemaItemKey = this.schema.getSchemaItemKey(name);
167
+ if (!mixinSchemaItemKey)
168
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin ("${name}") that cannot be found.`);
169
+ this._mixins.push(new DelayedPromise_1.DelayedPromiseWithProps(mixinSchemaItemKey, async () => {
170
+ const mixin = await this.schema.lookupItem(mixinSchemaItemKey);
171
+ if (undefined === mixin)
172
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin ("${name}") that cannot be found.`);
173
+ return mixin;
174
+ }));
175
+ }
176
+ }
177
+ }
178
+ }
179
+ exports.EntityClass = EntityClass;
180
+ /**
181
+ * Hackish approach that works like a "friend class" so we can access protected members without making them public.
182
+ * @internal
183
+ */
184
+ class MutableEntityClass extends EntityClass {
185
+ }
186
+ exports.MutableEntityClass = MutableEntityClass;
187
+ /** @internal */
188
+ async function createNavigationProperty(ecClass, name, relationship, direction) {
189
+ if (await ecClass.getProperty(name))
190
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);
191
+ let resolvedRelationship;
192
+ if (typeof (relationship) === "string") {
193
+ resolvedRelationship = await ecClass.schema.lookupItem(relationship);
194
+ }
195
+ else
196
+ resolvedRelationship = relationship;
197
+ if (!resolvedRelationship)
198
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);
199
+ if (typeof (direction) === "string") {
200
+ const tmpDirection = (0, ECObjects_1.parseStrengthDirection)(direction);
201
+ if (undefined === tmpDirection)
202
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);
203
+ direction = tmpDirection;
204
+ }
205
+ const lazyRelationship = new DelayedPromise_1.DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship);
206
+ return new Property_1.NavigationProperty(ecClass, name, lazyRelationship, direction);
207
+ }
208
+ exports.createNavigationProperty = createNavigationProperty;
209
+ /** @internal */
210
+ function createNavigationPropertySync(ecClass, name, relationship, direction) {
211
+ if (ecClass.getPropertySync(name))
212
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);
213
+ let resolvedRelationship;
214
+ if (typeof (relationship) === "string") {
215
+ resolvedRelationship = ecClass.schema.lookupItemSync(relationship);
216
+ }
217
+ else
218
+ resolvedRelationship = relationship;
219
+ if (!resolvedRelationship)
220
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);
221
+ if (typeof (direction) === "string") {
222
+ const tmpDirection = (0, ECObjects_1.parseStrengthDirection)(direction);
223
+ if (undefined === tmpDirection)
224
+ throw new Exception_1.ECObjectsError(Exception_1.ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);
225
+ direction = tmpDirection;
226
+ }
227
+ const lazyRelationship = new DelayedPromise_1.DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship);
228
+ return new Property_1.NavigationProperty(ecClass, name, lazyRelationship, direction);
229
+ }
230
+ exports.createNavigationPropertySync = createNavigationPropertySync;
231
231
  //# sourceMappingURL=EntityClass.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityClass.js","sourceRoot":"","sources":["../../../src/Metadata/EntityClass.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA0G;AAC1G,4CAA+D;AAG/D,mCAAkC;AAElC,yCAAuE;AAIvE;;;GAGG;AACH,MAAa,WAAY,SAAQ,eAAO;IAItC,YAAY,MAAc,EAAE,IAAY,EAAE,QAA0B;QAClE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,WAAW,CAAC;IACnD,CAAC;IAED,IAAW,MAAM;QACf,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,OAAO,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,CAAC,aAAa;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,OAAO,QAAQ,CAAC,MAAuB,CAAC,EAAE,CAAC,CAAC,iBAAiB;QAE/D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,IAAI,GAAG,IAAI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AC,oBAAqB,CAAC,CAAC;IAClH,OAAO,IAAI,6BAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC;AAtBD,oEAsBC","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 Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { EntityClassProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { ECClassModifier, parseStrengthDirection, SchemaItemType, StrengthDirection } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedMixin } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { ECClass } from \"./Class\";\r\nimport { Mixin } from \"./Mixin\";\r\nimport { AnyProperty, NavigationProperty, Property } from \"./Property\";\r\nimport { RelationshipClass } from \"./RelationshipClass\";\r\nimport { Schema } from \"./Schema\";\r\n\r\n/**\r\n * A Typescript class representation of an ECEntityClass.\r\n * @beta\r\n */\r\nexport class EntityClass extends ECClass {\r\n public override readonly schemaItemType!: SchemaItemType.EntityClass; // eslint-disable-line\r\n protected _mixins?: LazyLoadedMixin[];\r\n\r\n constructor(schema: Schema, name: string, modifier?: ECClassModifier) {\r\n super(schema, name, modifier);\r\n this.schemaItemType = SchemaItemType.EntityClass;\r\n }\r\n\r\n public get mixins(): LazyLoadedMixin[] {\r\n if (!this._mixins)\r\n return [];\r\n return this._mixins;\r\n }\r\n\r\n public *getMixinsSync(): Iterable<Mixin> {\r\n if (!this._mixins)\r\n return function* (): Iterable<Mixin> { }(); // empty iterable\r\n\r\n for (const mixin of this._mixins) {\r\n const mObj = this.schema.lookupItemSync<Mixin>(mixin);\r\n if (mObj) {\r\n yield mObj;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n *\r\n * @param mixin\r\n */\r\n protected addMixin(mixin: Mixin) {\r\n if (!this._mixins)\r\n this._mixins = [];\r\n\r\n this._mixins.push(new DelayedPromiseWithProps(mixin.key, async () => mixin));\r\n return;\r\n }\r\n\r\n /**\r\n * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.\r\n * @param name The name of the property to find.\r\n */\r\n public override async getInheritedProperty(name: string): Promise<AnyProperty | undefined> {\r\n let inheritedProperty = await super.getInheritedProperty(name);\r\n\r\n if (!inheritedProperty && this._mixins) {\r\n const mixinProps = await Promise.all(this._mixins.map(async (mixin) => (await mixin).getProperty(name)));\r\n mixinProps.some((prop) => {\r\n inheritedProperty = prop as AnyProperty;\r\n return inheritedProperty !== undefined;\r\n });\r\n }\r\n\r\n return inheritedProperty as AnyProperty | undefined;\r\n }\r\n\r\n /**\r\n * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.\r\n * @param name The name of the property to find.\r\n */\r\n public override getInheritedPropertySync(name: string): Property | undefined {\r\n const inheritedProperty = super.getInheritedPropertySync(name);\r\n if (inheritedProperty)\r\n return inheritedProperty;\r\n\r\n if (!this._mixins) {\r\n return undefined;\r\n }\r\n\r\n for (const mixin of this._mixins) {\r\n const mObj = this.schema.lookupItemSync<ECClass>(mixin);\r\n if (mObj) {\r\n const result = mObj.getPropertySync(name, true);\r\n if (result) {\r\n return result;\r\n }\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n protected override async buildPropertyCache(result: Property[], existingValues?: Map<string, number>, resetBaseCaches: boolean = false): Promise<void> {\r\n if (!existingValues) {\r\n existingValues = new Map<string, number>();\r\n }\r\n\r\n if (this.baseClass) {\r\n ECClass.mergeProperties(result, existingValues, await (await this.baseClass).getProperties(resetBaseCaches), false);\r\n }\r\n\r\n for (const mixin of this.mixins) {\r\n ECClass.mergeProperties(result, existingValues, await (await mixin).getProperties(resetBaseCaches), false);\r\n }\r\n\r\n if (!this.properties)\r\n return;\r\n\r\n ECClass.mergeProperties(result, existingValues, [...this.properties], true);\r\n }\r\n\r\n protected override buildPropertyCacheSync(result: Property[], existingValues?: Map<string, number>, resetBaseCaches: boolean = false): void {\r\n if (!existingValues) {\r\n existingValues = new Map<string, number>();\r\n }\r\n\r\n const baseClass = this.getBaseClassSync();\r\n if (baseClass) {\r\n ECClass.mergeProperties(result, existingValues, baseClass.getPropertiesSync(resetBaseCaches), false);\r\n }\r\n\r\n for (const mixin of this.getMixinsSync()) {\r\n ECClass.mergeProperties(result, existingValues, mixin.getPropertiesSync(resetBaseCaches), false);\r\n }\r\n\r\n if (!this.properties)\r\n return;\r\n\r\n ECClass.mergeProperties(result, existingValues, [...this.properties], true);\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param relationship\r\n * @param direction\r\n */\r\n protected async createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\r\n return this.addProperty(await createNavigationProperty(this, name, relationship, direction));\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param relationship\r\n * @param direction\r\n */\r\n protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\r\n return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));\r\n }\r\n\r\n /**\r\n * Save this EntityClass' properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): EntityClassProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n if (this.mixins.length > 0)\r\n schemaJson.mixins = this.mixins.map((mixin) => mixin.fullName);\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n for (const mixin of this.getMixinsSync()) {\r\n const mixinElement = schemaXml.createElement(\"BaseClass\");\r\n const mixinName = XmlSerializationUtils.createXmlTypedName(this.schema, mixin.schema, mixin.name);\r\n mixinElement.textContent = mixinName;\r\n itemElement.appendChild(mixinElement);\r\n }\r\n return itemElement;\r\n }\r\n\r\n public override async fromJSON(entityClassProps: EntityClassProps) {\r\n this.fromJSONSync(entityClassProps);\r\n }\r\n\r\n public override fromJSONSync(entityClassProps: EntityClassProps) {\r\n super.fromJSONSync(entityClassProps);\r\n\r\n if (undefined !== entityClassProps.mixins) {\r\n if (!this._mixins)\r\n this._mixins = [];\r\n for (const name of entityClassProps.mixins) {\r\n const mixinSchemaItemKey = this.schema.getSchemaItemKey(name);\r\n if (!mixinSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin (\"${name}\") that cannot be found.`);\r\n this._mixins.push(new DelayedPromiseWithProps<SchemaItemKey, Mixin>(mixinSchemaItemKey,\r\n async () => {\r\n const mixin = await this.schema.lookupItem<Mixin>(mixinSchemaItemKey);\r\n if (undefined === mixin)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin (\"${name}\") that cannot be found.`);\r\n return mixin;\r\n }));\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Hackish approach that works like a \"friend class\" so we can access protected members without making them public.\r\n * @internal\r\n */\r\nexport abstract class MutableEntityClass extends EntityClass {\r\n public abstract override addMixin(mixin: Mixin): any;\r\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\r\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n\r\n/** @internal */\r\nexport async function createNavigationProperty(ecClass: ECClass, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\r\n if (await ecClass.getProperty(name))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);\r\n\r\n let resolvedRelationship: RelationshipClass | undefined;\r\n if (typeof (relationship) === \"string\") {\r\n resolvedRelationship = await ecClass.schema.lookupItem<RelationshipClass>(relationship);\r\n } else\r\n resolvedRelationship = relationship;\r\n\r\n if (!resolvedRelationship)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);\r\n\r\n if (typeof (direction) === \"string\") {\r\n const tmpDirection = parseStrengthDirection(direction);\r\n if (undefined === tmpDirection)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);\r\n direction = tmpDirection;\r\n }\r\n\r\n const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship!);\r\n return new NavigationProperty(ecClass, name, lazyRelationship, direction);\r\n}\r\n\r\n/** @internal */\r\nexport function createNavigationPropertySync(ecClass: ECClass, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\r\n if (ecClass.getPropertySync(name))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);\r\n\r\n let resolvedRelationship: RelationshipClass | undefined;\r\n if (typeof (relationship) === \"string\") {\r\n resolvedRelationship = ecClass.schema.lookupItemSync<RelationshipClass>(relationship);\r\n } else\r\n resolvedRelationship = relationship;\r\n\r\n if (!resolvedRelationship)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);\r\n\r\n if (typeof (direction) === \"string\") {\r\n const tmpDirection = parseStrengthDirection(direction);\r\n if (undefined === tmpDirection)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);\r\n direction = tmpDirection;\r\n }\r\n\r\n const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship!);\r\n return new NavigationProperty(ecClass, name, lazyRelationship, direction);\r\n}\r\n"]}
1
+ {"version":3,"file":"EntityClass.js","sourceRoot":"","sources":["../../../src/Metadata/EntityClass.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA4D;AAE5D,oFAAiF;AACjF,4CAA0G;AAC1G,4CAA+D;AAG/D,mCAAkC;AAElC,yCAAuE;AAIvE;;;GAGG;AACH,MAAa,WAAY,SAAQ,eAAO;IAItC,YAAY,MAAc,EAAE,IAAY,EAAE,QAA0B;QAClE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,0BAAc,CAAC,WAAW,CAAC;IACnD,CAAC;IAED,IAAW,MAAM;QACf,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,OAAO,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,CAAC,aAAa;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,OAAO,QAAQ,CAAC,MAAuB,CAAC,EAAE,CAAC,CAAC,iBAAiB;QAE/D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAQ,KAAK,CAAC,CAAC;YACtD,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC;aACZ;SACF;IACH,CAAC;IAED;;;OAGG;IACO,QAAQ,CAAC,KAAY;QAC7B,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAEpB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,wCAAuB,CAAC,KAAK,CAAC,G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AA4B,CAAC,OAAgB,EAAE,IAAY,EAAE,YAAwC,EAAE,SAAqC;IAC1J,IAAI,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC;QAC/B,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,iBAAiB,EAAE,+BAA+B,IAAI,gCAAgC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;IAElJ,IAAI,oBAAmD,CAAC;IACxD,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,QAAQ,EAAE;QACtC,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAoB,YAAY,CAAC,CAAC;KACvF;;QACC,oBAAoB,GAAG,YAAY,CAAC;IAEtC,IAAI,CAAC,oBAAoB;QACvB,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,WAAW,EAAE,mCAAmC,YAAY,8CAA8C,CAAC,CAAC;IAEvJ,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,QAAQ,EAAE;QACnC,MAAM,YAAY,GAAG,IAAA,kCAAsB,EAAC,SAAS,CAAC,CAAC;QACvD,IAAI,SAAS,KAAK,YAAY;YAC5B,MAAM,IAAI,0BAAc,CAAC,2BAAe,CAAC,wBAAwB,EAAE,mCAAmC,SAAS,qCAAqC,CAAC,CAAC;QACxJ,SAAS,GAAG,YAAY,CAAC;KAC1B;IAED,MAAM,gBAAgB,GAAG,IAAI,wCAAuB,CAAC,oBAAoB,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,oBAAqB,CAAC,CAAC;IAClH,OAAO,IAAI,6BAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC;AAtBD,oEAsBC","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 Metadata\n */\n\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\nimport { EntityClassProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { ECClassModifier, parseStrengthDirection, SchemaItemType, StrengthDirection } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedMixin } from \"../Interfaces\";\nimport { SchemaItemKey } from \"../SchemaKey\";\nimport { ECClass } from \"./Class\";\nimport { Mixin } from \"./Mixin\";\nimport { AnyProperty, NavigationProperty, Property } from \"./Property\";\nimport { RelationshipClass } from \"./RelationshipClass\";\nimport { Schema } from \"./Schema\";\n\n/**\n * A Typescript class representation of an ECEntityClass.\n * @beta\n */\nexport class EntityClass extends ECClass {\n public override readonly schemaItemType!: SchemaItemType.EntityClass; // eslint-disable-line\n protected _mixins?: LazyLoadedMixin[];\n\n constructor(schema: Schema, name: string, modifier?: ECClassModifier) {\n super(schema, name, modifier);\n this.schemaItemType = SchemaItemType.EntityClass;\n }\n\n public get mixins(): LazyLoadedMixin[] {\n if (!this._mixins)\n return [];\n return this._mixins;\n }\n\n public *getMixinsSync(): Iterable<Mixin> {\n if (!this._mixins)\n return function* (): Iterable<Mixin> { }(); // empty iterable\n\n for (const mixin of this._mixins) {\n const mObj = this.schema.lookupItemSync<Mixin>(mixin);\n if (mObj) {\n yield mObj;\n }\n }\n }\n\n /**\n *\n * @param mixin\n */\n protected addMixin(mixin: Mixin) {\n if (!this._mixins)\n this._mixins = [];\n\n this._mixins.push(new DelayedPromiseWithProps(mixin.key, async () => mixin));\n return;\n }\n\n /**\n * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.\n * @param name The name of the property to find.\n */\n public override async getInheritedProperty(name: string): Promise<AnyProperty | undefined> {\n let inheritedProperty = await super.getInheritedProperty(name);\n\n if (!inheritedProperty && this._mixins) {\n const mixinProps = await Promise.all(this._mixins.map(async (mixin) => (await mixin).getProperty(name)));\n mixinProps.some((prop) => {\n inheritedProperty = prop as AnyProperty;\n return inheritedProperty !== undefined;\n });\n }\n\n return inheritedProperty as AnyProperty | undefined;\n }\n\n /**\n * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.\n * @param name The name of the property to find.\n */\n public override getInheritedPropertySync(name: string): Property | undefined {\n const inheritedProperty = super.getInheritedPropertySync(name);\n if (inheritedProperty)\n return inheritedProperty;\n\n if (!this._mixins) {\n return undefined;\n }\n\n for (const mixin of this._mixins) {\n const mObj = this.schema.lookupItemSync<ECClass>(mixin);\n if (mObj) {\n const result = mObj.getPropertySync(name, true);\n if (result) {\n return result;\n }\n }\n }\n\n return undefined;\n }\n\n protected override async buildPropertyCache(result: Property[], existingValues?: Map<string, number>, resetBaseCaches: boolean = false): Promise<void> {\n if (!existingValues) {\n existingValues = new Map<string, number>();\n }\n\n if (this.baseClass) {\n ECClass.mergeProperties(result, existingValues, await (await this.baseClass).getProperties(resetBaseCaches), false);\n }\n\n for (const mixin of this.mixins) {\n ECClass.mergeProperties(result, existingValues, await (await mixin).getProperties(resetBaseCaches), false);\n }\n\n if (!this.properties)\n return;\n\n ECClass.mergeProperties(result, existingValues, [...this.properties], true);\n }\n\n protected override buildPropertyCacheSync(result: Property[], existingValues?: Map<string, number>, resetBaseCaches: boolean = false): void {\n if (!existingValues) {\n existingValues = new Map<string, number>();\n }\n\n const baseClass = this.getBaseClassSync();\n if (baseClass) {\n ECClass.mergeProperties(result, existingValues, baseClass.getPropertiesSync(resetBaseCaches), false);\n }\n\n for (const mixin of this.getMixinsSync()) {\n ECClass.mergeProperties(result, existingValues, mixin.getPropertiesSync(resetBaseCaches), false);\n }\n\n if (!this.properties)\n return;\n\n ECClass.mergeProperties(result, existingValues, [...this.properties], true);\n }\n\n /**\n *\n * @param name\n * @param relationship\n * @param direction\n */\n protected async createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\n return this.addProperty(await createNavigationProperty(this, name, relationship, direction));\n }\n\n /**\n *\n * @param name\n * @param relationship\n * @param direction\n */\n protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\n return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));\n }\n\n /**\n * Save this EntityClass' properties to an object for serializing to JSON.\n * @param standalone Serialization includes only this object (as opposed to the full schema).\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\n */\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): EntityClassProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n if (this.mixins.length > 0)\n schemaJson.mixins = this.mixins.map((mixin) => mixin.fullName);\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n\n for (const mixin of this.getMixinsSync()) {\n const mixinElement = schemaXml.createElement(\"BaseClass\");\n const mixinName = XmlSerializationUtils.createXmlTypedName(this.schema, mixin.schema, mixin.name);\n mixinElement.textContent = mixinName;\n itemElement.appendChild(mixinElement);\n }\n return itemElement;\n }\n\n public override async fromJSON(entityClassProps: EntityClassProps) {\n this.fromJSONSync(entityClassProps);\n }\n\n public override fromJSONSync(entityClassProps: EntityClassProps) {\n super.fromJSONSync(entityClassProps);\n\n if (undefined !== entityClassProps.mixins) {\n if (!this._mixins)\n this._mixins = [];\n for (const name of entityClassProps.mixins) {\n const mixinSchemaItemKey = this.schema.getSchemaItemKey(name);\n if (!mixinSchemaItemKey)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin (\"${name}\") that cannot be found.`);\n this._mixins.push(new DelayedPromiseWithProps<SchemaItemKey, Mixin>(mixinSchemaItemKey,\n async () => {\n const mixin = await this.schema.lookupItem<Mixin>(mixinSchemaItemKey);\n if (undefined === mixin)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin (\"${name}\") that cannot be found.`);\n return mixin;\n }));\n }\n }\n }\n}\n\n/**\n * Hackish approach that works like a \"friend class\" so we can access protected members without making them public.\n * @internal\n */\nexport abstract class MutableEntityClass extends EntityClass {\n public abstract override addMixin(mixin: Mixin): any;\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n\n/** @internal */\nexport async function createNavigationProperty(ecClass: ECClass, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\n if (await ecClass.getProperty(name))\n throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);\n\n let resolvedRelationship: RelationshipClass | undefined;\n if (typeof (relationship) === \"string\") {\n resolvedRelationship = await ecClass.schema.lookupItem<RelationshipClass>(relationship);\n } else\n resolvedRelationship = relationship;\n\n if (!resolvedRelationship)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);\n\n if (typeof (direction) === \"string\") {\n const tmpDirection = parseStrengthDirection(direction);\n if (undefined === tmpDirection)\n throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);\n direction = tmpDirection;\n }\n\n const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship!);\n return new NavigationProperty(ecClass, name, lazyRelationship, direction);\n}\n\n/** @internal */\nexport function createNavigationPropertySync(ecClass: ECClass, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\n if (ecClass.getPropertySync(name))\n throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);\n\n let resolvedRelationship: RelationshipClass | undefined;\n if (typeof (relationship) === \"string\") {\n resolvedRelationship = ecClass.schema.lookupItemSync<RelationshipClass>(relationship);\n } else\n resolvedRelationship = relationship;\n\n if (!resolvedRelationship)\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`);\n\n if (typeof (direction) === \"string\") {\n const tmpDirection = parseStrengthDirection(direction);\n if (undefined === tmpDirection)\n throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);\n direction = tmpDirection;\n }\n\n const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship!);\n return new NavigationProperty(ecClass, name, lazyRelationship, direction);\n}\n"]}