@itwin/ecschema-metadata 4.8.0-dev.9 → 4.9.0-dev.1

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 (251) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/lib/cjs/Constants.js.map +1 -1
  3. package/lib/cjs/DelayedPromise.js.map +1 -1
  4. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  5. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  6. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  7. package/lib/cjs/Deserialization/JsonProps.d.ts +4 -0
  8. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  9. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  10. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  11. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  12. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  13. package/lib/cjs/ECName.js.map +1 -1
  14. package/lib/cjs/ECObjects.js.map +1 -1
  15. package/lib/cjs/Exception.js.map +1 -1
  16. package/lib/cjs/Interfaces.js.map +1 -1
  17. package/lib/cjs/Metadata/Class.d.ts +0 -6
  18. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  19. package/lib/cjs/Metadata/Class.js +0 -8
  20. package/lib/cjs/Metadata/Class.js.map +1 -1
  21. package/lib/cjs/Metadata/Constant.js.map +1 -1
  22. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  23. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +7 -3
  24. package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
  25. package/lib/cjs/Metadata/CustomAttributeClass.js +16 -10
  26. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  27. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  28. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  29. package/lib/cjs/Metadata/Format.js.map +1 -1
  30. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  31. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  32. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  33. package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
  34. package/lib/cjs/Metadata/OverrideFormat.js +3 -1
  35. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  36. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  37. package/lib/cjs/Metadata/Property.js.map +1 -1
  38. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  39. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  40. package/lib/cjs/Metadata/Schema.d.ts +14 -0
  41. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  42. package/lib/cjs/Metadata/Schema.js +21 -0
  43. package/lib/cjs/Metadata/Schema.js.map +1 -1
  44. package/lib/cjs/Metadata/SchemaItem.d.ts +5 -0
  45. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  46. package/lib/cjs/Metadata/SchemaItem.js +7 -0
  47. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  48. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  49. package/lib/cjs/PropertyTypes.js.map +1 -1
  50. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  51. package/lib/cjs/SchemaKey.js.map +1 -1
  52. package/lib/cjs/SchemaLoader.js.map +1 -1
  53. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  54. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  55. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  56. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  57. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  58. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  59. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  60. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  61. package/lib/cjs/ecschema-metadata.js.map +1 -1
  62. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  63. package/lib/esm/Constants.d.ts +24 -0
  64. package/lib/esm/Constants.d.ts.map +1 -0
  65. package/lib/esm/Constants.js +30 -0
  66. package/lib/esm/Constants.js.map +1 -0
  67. package/lib/esm/Context.d.ts +219 -0
  68. package/lib/esm/Context.d.ts.map +1 -0
  69. package/lib/esm/Context.js +321 -0
  70. package/lib/esm/Context.js.map +1 -0
  71. package/lib/esm/DelayedPromise.d.ts +89 -0
  72. package/lib/esm/DelayedPromise.d.ts.map +1 -0
  73. package/lib/esm/DelayedPromise.js +88 -0
  74. package/lib/esm/DelayedPromise.js.map +1 -0
  75. package/lib/esm/Deserialization/AbstractParser.d.ts +46 -0
  76. package/lib/esm/Deserialization/AbstractParser.d.ts.map +1 -0
  77. package/lib/esm/Deserialization/AbstractParser.js +8 -0
  78. package/lib/esm/Deserialization/AbstractParser.js.map +1 -0
  79. package/lib/esm/Deserialization/Helper.d.ts +263 -0
  80. package/lib/esm/Deserialization/Helper.d.ts.map +1 -0
  81. package/lib/esm/Deserialization/Helper.js +871 -0
  82. package/lib/esm/Deserialization/Helper.js.map +1 -0
  83. package/lib/esm/Deserialization/JsonParser.d.ts +166 -0
  84. package/lib/esm/Deserialization/JsonParser.d.ts.map +1 -0
  85. package/lib/esm/Deserialization/JsonParser.js +677 -0
  86. package/lib/esm/Deserialization/JsonParser.js.map +1 -0
  87. package/lib/esm/Deserialization/JsonProps.d.ts +273 -0
  88. package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -0
  89. package/lib/esm/Deserialization/JsonProps.js +9 -0
  90. package/lib/esm/Deserialization/JsonProps.js.map +1 -0
  91. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +35 -0
  92. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -0
  93. package/lib/esm/Deserialization/SchemaGraphUtil.js +74 -0
  94. package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -0
  95. package/lib/esm/Deserialization/XmlParser.d.ts +86 -0
  96. package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -0
  97. package/lib/esm/Deserialization/XmlParser.js +970 -0
  98. package/lib/esm/Deserialization/XmlParser.js.map +1 -0
  99. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +55 -0
  100. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -0
  101. package/lib/esm/Deserialization/XmlSerializationUtils.js +172 -0
  102. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -0
  103. package/lib/esm/ECName.d.ts +31 -0
  104. package/lib/esm/ECName.d.ts.map +1 -0
  105. package/lib/esm/ECName.js +82 -0
  106. package/lib/esm/ECName.js.map +1 -0
  107. package/lib/esm/ECObjects.d.ts +166 -0
  108. package/lib/esm/ECObjects.d.ts.map +1 -0
  109. package/lib/esm/ECObjects.js +422 -0
  110. package/lib/esm/ECObjects.js.map +1 -0
  111. package/lib/esm/Exception.d.ts +45 -0
  112. package/lib/esm/Exception.d.ts.map +1 -0
  113. package/lib/esm/Exception.js +82 -0
  114. package/lib/esm/Exception.js.map +1 -0
  115. package/lib/esm/Interfaces.d.ts +79 -0
  116. package/lib/esm/Interfaces.d.ts.map +1 -0
  117. package/lib/esm/Interfaces.js +9 -0
  118. package/lib/esm/Interfaces.js.map +1 -0
  119. package/lib/esm/Metadata/Class.d.ts +245 -0
  120. package/lib/esm/Metadata/Class.d.ts.map +1 -0
  121. package/lib/esm/Metadata/Class.js +552 -0
  122. package/lib/esm/Metadata/Class.js.map +1 -0
  123. package/lib/esm/Metadata/Constant.d.ts +65 -0
  124. package/lib/esm/Metadata/Constant.d.ts.map +1 -0
  125. package/lib/esm/Metadata/Constant.js +119 -0
  126. package/lib/esm/Metadata/Constant.js.map +1 -0
  127. package/lib/esm/Metadata/CustomAttribute.d.ts +24 -0
  128. package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -0
  129. package/lib/esm/Metadata/CustomAttribute.js +24 -0
  130. package/lib/esm/Metadata/CustomAttribute.js.map +1 -0
  131. package/lib/esm/Metadata/CustomAttributeClass.d.ts +44 -0
  132. package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -0
  133. package/lib/esm/Metadata/CustomAttributeClass.js +70 -0
  134. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -0
  135. package/lib/esm/Metadata/EntityClass.d.ts +78 -0
  136. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -0
  137. package/lib/esm/Metadata/EntityClass.js +224 -0
  138. package/lib/esm/Metadata/EntityClass.js.map +1 -0
  139. package/lib/esm/Metadata/Enumeration.d.ts +87 -0
  140. package/lib/esm/Metadata/Enumeration.d.ts.map +1 -0
  141. package/lib/esm/Metadata/Enumeration.js +155 -0
  142. package/lib/esm/Metadata/Enumeration.js.map +1 -0
  143. package/lib/esm/Metadata/Format.d.ts +99 -0
  144. package/lib/esm/Metadata/Format.d.ts.map +1 -0
  145. package/lib/esm/Metadata/Format.js +238 -0
  146. package/lib/esm/Metadata/Format.js.map +1 -0
  147. package/lib/esm/Metadata/InvertedUnit.d.ts +50 -0
  148. package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -0
  149. package/lib/esm/Metadata/InvertedUnit.js +93 -0
  150. package/lib/esm/Metadata/InvertedUnit.js.map +1 -0
  151. package/lib/esm/Metadata/KindOfQuantity.d.ts +72 -0
  152. package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -0
  153. package/lib/esm/Metadata/KindOfQuantity.js +229 -0
  154. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -0
  155. package/lib/esm/Metadata/Mixin.d.ts +55 -0
  156. package/lib/esm/Metadata/Mixin.d.ts.map +1 -0
  157. package/lib/esm/Metadata/Mixin.js +109 -0
  158. package/lib/esm/Metadata/Mixin.js.map +1 -0
  159. package/lib/esm/Metadata/OverrideFormat.d.ts +68 -0
  160. package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -0
  161. package/lib/esm/Metadata/OverrideFormat.js +124 -0
  162. package/lib/esm/Metadata/OverrideFormat.js.map +1 -0
  163. package/lib/esm/Metadata/Phenomenon.d.ts +34 -0
  164. package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -0
  165. package/lib/esm/Metadata/Phenomenon.js +55 -0
  166. package/lib/esm/Metadata/Phenomenon.js.map +1 -0
  167. package/lib/esm/Metadata/Property.d.ts +247 -0
  168. package/lib/esm/Metadata/Property.d.ts.map +1 -0
  169. package/lib/esm/Metadata/Property.js +565 -0
  170. package/lib/esm/Metadata/Property.js.map +1 -0
  171. package/lib/esm/Metadata/PropertyCategory.d.ts +40 -0
  172. package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -0
  173. package/lib/esm/Metadata/PropertyCategory.js +57 -0
  174. package/lib/esm/Metadata/PropertyCategory.js.map +1 -0
  175. package/lib/esm/Metadata/RelationshipClass.d.ts +170 -0
  176. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -0
  177. package/lib/esm/Metadata/RelationshipClass.js +380 -0
  178. package/lib/esm/Metadata/RelationshipClass.js.map +1 -0
  179. package/lib/esm/Metadata/Schema.d.ts +330 -0
  180. package/lib/esm/Metadata/Schema.d.ts.map +1 -0
  181. package/lib/esm/Metadata/Schema.js +570 -0
  182. package/lib/esm/Metadata/Schema.js.map +1 -0
  183. package/lib/esm/Metadata/SchemaItem.d.ts +67 -0
  184. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -0
  185. package/lib/esm/Metadata/SchemaItem.js +140 -0
  186. package/lib/esm/Metadata/SchemaItem.js.map +1 -0
  187. package/lib/esm/Metadata/Unit.d.ts +77 -0
  188. package/lib/esm/Metadata/Unit.d.ts.map +1 -0
  189. package/lib/esm/Metadata/Unit.js +158 -0
  190. package/lib/esm/Metadata/Unit.js.map +1 -0
  191. package/lib/esm/Metadata/UnitSystem.d.ts +21 -0
  192. package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -0
  193. package/lib/esm/Metadata/UnitSystem.js +25 -0
  194. package/lib/esm/Metadata/UnitSystem.js.map +1 -0
  195. package/lib/esm/PropertyTypes.d.ts +50 -0
  196. package/lib/esm/PropertyTypes.d.ts.map +1 -0
  197. package/lib/esm/PropertyTypes.js +88 -0
  198. package/lib/esm/PropertyTypes.js.map +1 -0
  199. package/lib/esm/SchemaJsonLocater.d.ts +42 -0
  200. package/lib/esm/SchemaJsonLocater.d.ts.map +1 -0
  201. package/lib/esm/SchemaJsonLocater.js +54 -0
  202. package/lib/esm/SchemaJsonLocater.js.map +1 -0
  203. package/lib/esm/SchemaKey.d.ts +111 -0
  204. package/lib/esm/SchemaKey.d.ts.map +1 -0
  205. package/lib/esm/SchemaKey.js +214 -0
  206. package/lib/esm/SchemaKey.js.map +1 -0
  207. package/lib/esm/SchemaLoader.d.ts +32 -0
  208. package/lib/esm/SchemaLoader.d.ts.map +1 -0
  209. package/lib/esm/SchemaLoader.js +53 -0
  210. package/lib/esm/SchemaLoader.js.map +1 -0
  211. package/lib/esm/SchemaPartVisitorDelegate.d.ts +275 -0
  212. package/lib/esm/SchemaPartVisitorDelegate.d.ts.map +1 -0
  213. package/lib/esm/SchemaPartVisitorDelegate.js +209 -0
  214. package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -0
  215. package/lib/esm/UnitConversion/Graph.d.ts +35 -0
  216. package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
  217. package/lib/esm/UnitConversion/Graph.js +80 -0
  218. package/lib/esm/UnitConversion/Graph.js.map +1 -0
  219. package/lib/esm/UnitConversion/Parser.d.ts +9 -0
  220. package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
  221. package/lib/esm/UnitConversion/Parser.js +39 -0
  222. package/lib/esm/UnitConversion/Parser.js.map +1 -0
  223. package/lib/esm/UnitConversion/UnitConversion.d.ts +46 -0
  224. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
  225. package/lib/esm/UnitConversion/UnitConversion.js +74 -0
  226. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
  227. package/lib/esm/UnitConversion/UnitConverter.d.ts +40 -0
  228. package/lib/esm/UnitConversion/UnitConverter.d.ts.map +1 -0
  229. package/lib/esm/UnitConversion/UnitConverter.js +113 -0
  230. package/lib/esm/UnitConversion/UnitConverter.js.map +1 -0
  231. package/lib/esm/UnitConversion/UnitTree.d.ts +44 -0
  232. package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -0
  233. package/lib/esm/UnitConversion/UnitTree.js +165 -0
  234. package/lib/esm/UnitConversion/UnitTree.js.map +1 -0
  235. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts +78 -0
  236. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
  237. package/lib/esm/UnitProvider/SchemaUnitProvider.js +231 -0
  238. package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -0
  239. package/lib/esm/Validation/SchemaWalker.d.ts +24 -0
  240. package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -0
  241. package/lib/esm/Validation/SchemaWalker.js +50 -0
  242. package/lib/esm/Validation/SchemaWalker.js.map +1 -0
  243. package/lib/esm/ecschema-metadata.d.ts +52 -0
  244. package/lib/esm/ecschema-metadata.d.ts.map +1 -0
  245. package/lib/esm/ecschema-metadata.js +55 -0
  246. package/lib/esm/ecschema-metadata.js.map +1 -0
  247. package/lib/esm/utils/SchemaGraph.d.ts +44 -0
  248. package/lib/esm/utils/SchemaGraph.d.ts.map +1 -0
  249. package/lib/esm/utils/SchemaGraph.js +111 -0
  250. package/lib/esm/utils/SchemaGraph.js.map +1 -0
  251. package/package.json +9 -7
@@ -0,0 +1,970 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { assert } from "@itwin/core-bentley";
6
+ import { parsePrimitiveType, PrimitiveType, primitiveTypeToString, StrengthDirection, strengthDirectionToString } from "../ECObjects";
7
+ import { ECObjectsError, ECObjectsStatus } from "../Exception";
8
+ import { ECName } from "../ECName";
9
+ import { AbstractParser } from "./AbstractParser";
10
+ const NON_ITEM_SCHEMA_ELEMENTS = ["ECSchemaReference", "ECCustomAttributes"];
11
+ const ECXML_URI = "http://www\\.bentley\\.com/schemas/Bentley\\.ECXML";
12
+ /** @internal */
13
+ export class XmlParser extends AbstractParser {
14
+ constructor(rawSchema) {
15
+ super();
16
+ this._rawSchema = rawSchema;
17
+ const schemaInfo = rawSchema.documentElement;
18
+ const schemaName = schemaInfo.getAttribute("schemaName");
19
+ if (schemaName)
20
+ this._schemaName = schemaName;
21
+ this._schemaAlias = "";
22
+ const schemaAlias = schemaInfo.getAttribute("alias");
23
+ if (schemaAlias)
24
+ this._schemaAlias = schemaAlias;
25
+ this._schemaReferenceNames = new Map();
26
+ const schemaVersion = schemaInfo.getAttribute("version");
27
+ if (schemaVersion)
28
+ this._schemaVersion = schemaVersion;
29
+ const xmlNamespace = schemaInfo.getAttribute("xmlns");
30
+ if (xmlNamespace) {
31
+ this._xmlNamespace = xmlNamespace;
32
+ this._ecXmlVersion = this.parseXmlNamespace(this._xmlNamespace);
33
+ }
34
+ this._schemaItems = new Map();
35
+ this._mapIsPopulated = false;
36
+ }
37
+ parseSchema() {
38
+ const schemaMetadata = this._rawSchema.documentElement;
39
+ if ("ECSchema" !== schemaMetadata.nodeName)
40
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, "An ECSchema is missing the required metadata.");
41
+ const schemaDefDuplicates = this.getElementChildrenByTagName(schemaMetadata, "ECSchema");
42
+ if (schemaDefDuplicates.length > 1)
43
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, "An ECSchema has more than one ECSchema definition. Only one is allowed.");
44
+ if (this._schemaName === undefined)
45
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `An ECSchema is missing a required 'schemaName' attribute`);
46
+ if (this._schemaVersion === undefined)
47
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ECSchema ${this._schemaName} is missing a required 'version' attribute`);
48
+ if (this._xmlNamespace === undefined)
49
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ECSchema ${this._schemaName} is missing a required 'xmlns' attribute`);
50
+ if (this._ecXmlVersion === undefined)
51
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ECSchema ${this._schemaName} has an invalid 'xmlns' attribute`);
52
+ const alias = this.getRequiredAttribute(schemaMetadata, "alias", `The ECSchema ${this._schemaName} is missing a required 'alias' attribute`);
53
+ const description = this.getOptionalAttribute(schemaMetadata, "description");
54
+ const displayLabel = this.getOptionalAttribute(schemaMetadata, "displayLabel");
55
+ const schemaProps = {
56
+ name: this._schemaName,
57
+ $schema: this._xmlNamespace,
58
+ version: this._schemaVersion,
59
+ alias,
60
+ label: displayLabel,
61
+ description,
62
+ };
63
+ return schemaProps;
64
+ }
65
+ *getReferences() {
66
+ const schemaReferences = this.getElementChildrenByTagName(this._rawSchema.documentElement, "ECSchemaReference");
67
+ for (const ref of schemaReferences) {
68
+ yield this.getSchemaReference(ref);
69
+ }
70
+ }
71
+ *getItems() {
72
+ if (!this._mapIsPopulated) {
73
+ const schemaItems = this.getSchemaChildren();
74
+ for (const item of schemaItems) {
75
+ let rawItemType = item.nodeName;
76
+ if (NON_ITEM_SCHEMA_ELEMENTS.includes(rawItemType))
77
+ continue;
78
+ // Differentiate a Mixin from an EntityClass
79
+ const customAttributesResult = this.getElementChildrenByTagName(item, "ECCustomAttributes");
80
+ if (customAttributesResult.length > 0) {
81
+ const customAttributes = customAttributesResult[0];
82
+ const isMixinResult = this.getElementChildrenByTagName(customAttributes, "IsMixin");
83
+ if (isMixinResult.length > 0)
84
+ rawItemType = "Mixin";
85
+ }
86
+ const itemType = this.getSchemaItemType(rawItemType);
87
+ if (itemType === undefined)
88
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `A SchemaItem in ${this._schemaName} has an invalid type. '${rawItemType}' is not a valid SchemaItem type.`);
89
+ const itemName = this.getRequiredAttribute(item, "typeName", `A SchemaItem in ${this._schemaName} is missing the required 'typeName' attribute.`);
90
+ if (!ECName.validate(itemName))
91
+ throw new ECObjectsError(ECObjectsStatus.InvalidECName, `A SchemaItem in ${this._schemaName} has an invalid 'typeName' attribute. '${itemName}' is not a valid ECName.`);
92
+ this._currentItemFullName = `${this._schemaName}.${itemName}`;
93
+ this._schemaItems.set(itemName, [itemType, item]);
94
+ yield [itemName, itemType, item];
95
+ }
96
+ this._mapIsPopulated = true;
97
+ }
98
+ else {
99
+ for (const [itemName, [itemType, item]] of this._schemaItems) {
100
+ this._currentItemFullName = `${this._schemaName}.${itemName}`;
101
+ yield [itemName, itemType, item];
102
+ }
103
+ }
104
+ }
105
+ findItem(itemName) {
106
+ if (!this._mapIsPopulated) {
107
+ for (const item of this.getItems()) {
108
+ if (item[0] === itemName) {
109
+ this._currentItemFullName = `${this._schemaName}.${itemName}`;
110
+ return item;
111
+ }
112
+ }
113
+ }
114
+ else {
115
+ const values = this._schemaItems.get(itemName);
116
+ if (undefined !== values) {
117
+ const [itemType, item] = values;
118
+ this._currentItemFullName = `${this._schemaName}.${itemName}`;
119
+ return [itemName, itemType, item];
120
+ }
121
+ }
122
+ return undefined;
123
+ }
124
+ parseEntityClass(xmlElement) {
125
+ const classProps = this.getClassProps(xmlElement);
126
+ const baseClasses = this.getElementChildrenByTagName(xmlElement, "BaseClass");
127
+ let mixinElements;
128
+ const mixins = new Array();
129
+ // if it has just one BaseClass we assume it is a 'true' base class not a mixin
130
+ if (baseClasses.length > 1) {
131
+ mixinElements = baseClasses.slice(1);
132
+ for (const mixin of mixinElements) {
133
+ if (mixin.textContent) {
134
+ const typeName = this.getQualifiedTypeName(mixin.textContent);
135
+ mixins.push(typeName);
136
+ }
137
+ }
138
+ }
139
+ const entityClassProps = {
140
+ ...classProps,
141
+ mixins,
142
+ };
143
+ return entityClassProps;
144
+ }
145
+ parseMixin(xmlElement) {
146
+ const classProps = this.getClassProps(xmlElement);
147
+ const baseClasses = this.getElementChildrenByTagName(xmlElement, "BaseClass");
148
+ // Mixins can only have one base class
149
+ if (baseClasses.length > 1)
150
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Mixin ${this._currentItemFullName} has more than one base class which is not allowed.`);
151
+ const customAttributesResult = this.getElementChildrenByTagName(xmlElement, "ECCustomAttributes");
152
+ if (customAttributesResult.length < 1)
153
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Mixin ${this._currentItemFullName} is missing the required 'IsMixin' tag.`);
154
+ const customAttributes = customAttributesResult[0];
155
+ const isMixinResult = this.getElementChildrenByTagName(customAttributes, "IsMixin");
156
+ if (isMixinResult.length < 1)
157
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Mixin ${this._currentItemFullName} is missing the required 'IsMixin' tag.`);
158
+ const mixinAttributes = isMixinResult[0];
159
+ const appliesToResult = this.getElementChildrenByTagName(mixinAttributes, "AppliesToEntityClass");
160
+ if (appliesToResult.length < 1)
161
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Mixin ${this._currentItemFullName} is missing the required 'AppliesToEntityClass' tag.`);
162
+ const appliesToElement = appliesToResult[0];
163
+ let appliesTo = appliesToElement.textContent;
164
+ if (appliesTo === null || appliesTo.length === 0)
165
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Mixin ${this._currentItemFullName} is missing the required 'AppliesToEntityClass' tag.`);
166
+ appliesTo = this.getQualifiedTypeName(appliesTo);
167
+ const mixinProps = {
168
+ ...classProps,
169
+ appliesTo,
170
+ };
171
+ return mixinProps;
172
+ }
173
+ parseStructClass(xmlElement) {
174
+ return this.getClassProps(xmlElement);
175
+ }
176
+ parseCustomAttributeClass(xmlElement) {
177
+ const classProps = this.getClassProps(xmlElement);
178
+ const appliesTo = this.getRequiredAttribute(xmlElement, "appliesTo", `The CustomAttributeClass ${this._currentItemFullName} is missing the required 'appliesTo' attribute.`);
179
+ const customAttributeClassProps = {
180
+ ...classProps,
181
+ appliesTo,
182
+ };
183
+ return customAttributeClassProps;
184
+ }
185
+ parseRelationshipClass(xmlElement) {
186
+ const classProps = this.getClassProps(xmlElement);
187
+ const strength = this.getRequiredAttribute(xmlElement, "strength", `The RelationshipClass ${this._currentItemFullName} is missing the required 'strength' attribute.`);
188
+ let strengthDirection = this.getOptionalAttribute(xmlElement, "strengthDirection");
189
+ if (!strengthDirection)
190
+ strengthDirection = strengthDirectionToString(StrengthDirection.Forward);
191
+ const sourceResult = this.getElementChildrenByTagName(xmlElement, "Source");
192
+ if (sourceResult.length !== 1) {
193
+ if (sourceResult.length === 0)
194
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The RelationshipClass ${this._currentItemFullName} is missing the required Source constraint tag.`);
195
+ else
196
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The RelationshipClass ${this._currentItemFullName} has more than one Source constraint tag. Only one is allowed.`);
197
+ }
198
+ const source = this.getRelationshipConstraintProps(sourceResult[0], true);
199
+ const targetResult = this.getElementChildrenByTagName(xmlElement, "Target");
200
+ if (targetResult.length !== 1) {
201
+ if (targetResult.length === 0)
202
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The RelationshipClass ${this._currentItemFullName} is missing the required Target constraint tag.`);
203
+ else
204
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The RelationshipClass ${this._currentItemFullName} has more than one Target constraint tag. Only one is allowed.`);
205
+ }
206
+ const target = this.getRelationshipConstraintProps(targetResult[0], false);
207
+ return {
208
+ ...classProps,
209
+ strength,
210
+ strengthDirection,
211
+ source,
212
+ target,
213
+ };
214
+ }
215
+ parseEnumeration(xmlElement) {
216
+ const itemProps = this.getSchemaItemProps(xmlElement);
217
+ const enumType = this.getRequiredAttribute(xmlElement, "backingTypeName", `The Enumeration ${this._currentItemFullName} is missing the required 'backingTypeName' attribute.`);
218
+ // TODO: This shouldn't be verified here. It's for the deserialize method to handle. The only reason it's currently done here so that the xml
219
+ // value can be put in the correct type, number or string.
220
+ let tempBackingType;
221
+ if (/int/i.test(enumType))
222
+ tempBackingType = PrimitiveType.Integer;
223
+ else if (/string/i.test(enumType))
224
+ tempBackingType = PrimitiveType.String;
225
+ else
226
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this._currentItemFullName} has an invalid 'backingTypeName' attribute. It should be either "int" or "string".`);
227
+ let isStrictString = this.getOptionalAttribute(xmlElement, "isStrict");
228
+ if (isStrictString === undefined)
229
+ isStrictString = "true";
230
+ const isStrict = this.parseBoolean(isStrictString, `The Enumeration ${this._currentItemFullName} has an invalid 'isStrict' attribute. It should either be "true" or "false".`);
231
+ const enumeratorElements = this.getElementChildrenByTagName(xmlElement, "ECEnumerator");
232
+ const enumerators = new Array();
233
+ for (const element of enumeratorElements) {
234
+ const name = this.getRequiredAttribute(element, "name", `The Enumeration ${this._currentItemFullName} has an enumerator that is missing the required attribute 'name'.`);
235
+ const valueString = this.getRequiredAttribute(element, "value", `The Enumeration ${this._currentItemFullName} has an enumerator that is missing the required attribute 'value'.`);
236
+ let value = valueString;
237
+ if (PrimitiveType.Integer === tempBackingType) {
238
+ const numericValue = parseInt(valueString, 10);
239
+ if (isNaN(numericValue))
240
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Enumeration ${this._currentItemFullName} of type "int" has an enumerator with a non-integer value.`);
241
+ value = numericValue;
242
+ }
243
+ const label = this.getOptionalAttribute(element, "displayLabel");
244
+ const description = this.getOptionalAttribute(element, "description");
245
+ enumerators.push({
246
+ name,
247
+ value,
248
+ label,
249
+ description,
250
+ });
251
+ }
252
+ return {
253
+ ...itemProps,
254
+ type: enumType,
255
+ isStrict,
256
+ enumerators,
257
+ };
258
+ }
259
+ parseKindOfQuantity(xmlElement) {
260
+ const itemProps = this.getSchemaItemProps(xmlElement);
261
+ const relativeErrorString = this.getRequiredAttribute(xmlElement, "relativeError", `The KindOfQuantity ${this._currentItemFullName} is missing the required 'relativeError' attribute.`);
262
+ const relativeError = parseFloat(relativeErrorString);
263
+ if (isNaN(relativeError))
264
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The KindOfQuantity ${this._currentItemFullName} has an invalid 'relativeError' attribute. It should be a numeric value.`);
265
+ const presentationUnitsString = this.getOptionalAttribute(xmlElement, "presentationUnits");
266
+ let presentationUnits;
267
+ if (presentationUnitsString)
268
+ presentationUnits = this.getQualifiedPresentationUnits(presentationUnitsString.split(";"));
269
+ let persistenceUnit = this.getRequiredAttribute(xmlElement, "persistenceUnit", `The KindOfQuantity ${this._currentItemFullName} is missing the required 'persistenceUnit' attribute.`);
270
+ persistenceUnit = this.getQualifiedTypeName(persistenceUnit);
271
+ return {
272
+ ...itemProps,
273
+ relativeError,
274
+ presentationUnits,
275
+ persistenceUnit,
276
+ };
277
+ }
278
+ parsePropertyCategory(xmlElement) {
279
+ const itemProps = this.getSchemaItemProps(xmlElement);
280
+ const priorityString = this.getRequiredAttribute(xmlElement, "priority", `The PropertyCategory ${this._currentItemFullName} is missing the required 'priority' attribute.`);
281
+ const priority = parseInt(priorityString, 10);
282
+ if (isNaN(priority))
283
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The PropertyCategory ${this._currentItemFullName} has an invalid 'priority' attribute. It should be a numeric value.`);
284
+ return {
285
+ ...itemProps,
286
+ priority,
287
+ };
288
+ }
289
+ parseUnit(xmlElement) {
290
+ const itemProps = this.getSchemaItemProps(xmlElement);
291
+ let phenomenon = this.getRequiredAttribute(xmlElement, "phenomenon", `The Unit ${this._currentItemFullName} is missing the required 'phenomenon' attribute.`);
292
+ let unitSystem = this.getRequiredAttribute(xmlElement, "unitSystem", `The Unit ${this._currentItemFullName} is missing the required 'unitSystem' attribute.`);
293
+ const definition = this.getRequiredAttribute(xmlElement, "definition", `The Unit ${this._currentItemFullName} is missing the required 'definition' attribute.`);
294
+ const numerator = this.getOptionalFloatAttribute(xmlElement, "numerator", `The Unit ${this._currentItemFullName} has an invalid 'numerator' attribute. It should be a numeric value.`);
295
+ const denominator = this.getOptionalFloatAttribute(xmlElement, "denominator", `The Unit ${this._currentItemFullName} has an invalid 'denominator' attribute. It should be a numeric value.`);
296
+ const offset = this.getOptionalFloatAttribute(xmlElement, "offset", `The Unit ${this._currentItemFullName} has an invalid 'offset' attribute. It should be a numeric value.`);
297
+ phenomenon = this.getQualifiedTypeName(phenomenon);
298
+ unitSystem = this.getQualifiedTypeName(unitSystem);
299
+ return {
300
+ ...itemProps,
301
+ phenomenon,
302
+ unitSystem,
303
+ definition,
304
+ numerator,
305
+ denominator,
306
+ offset,
307
+ };
308
+ }
309
+ parseInvertedUnit(xmlElement) {
310
+ const itemProps = this.getSchemaItemProps(xmlElement);
311
+ let invertsUnit = this.getRequiredAttribute(xmlElement, "invertsUnit", `The InvertedUnit ${this._currentItemFullName} is missing the required 'invertsUnit' attribute.`);
312
+ let unitSystem = this.getRequiredAttribute(xmlElement, "unitSystem", `The InvertedUnit ${this._currentItemFullName} is missing the required 'unitSystem' attribute.`);
313
+ invertsUnit = this.getQualifiedTypeName(invertsUnit);
314
+ unitSystem = this.getQualifiedTypeName(unitSystem);
315
+ return {
316
+ ...itemProps,
317
+ invertsUnit,
318
+ unitSystem,
319
+ };
320
+ }
321
+ parseConstant(xmlElement) {
322
+ const itemProps = this.getSchemaItemProps(xmlElement);
323
+ let phenomenon = this.getRequiredAttribute(xmlElement, "phenomenon", `The Constant ${this._currentItemFullName} is missing the required 'phenomenon' attribute.`);
324
+ const definition = this.getRequiredAttribute(xmlElement, "definition", `The Constant ${this._currentItemFullName} is missing the required 'definition' attribute.`);
325
+ const numerator = this.getOptionalFloatAttribute(xmlElement, "numerator", `The Constant ${this._currentItemFullName} has an invalid 'numerator' attribute. It should be a numeric value.`);
326
+ const denominator = this.getOptionalFloatAttribute(xmlElement, "denominator", `The Constant ${this._currentItemFullName} has an invalid 'denominator' attribute. It should be a numeric value.`);
327
+ phenomenon = this.getQualifiedTypeName(phenomenon);
328
+ return {
329
+ ...itemProps,
330
+ phenomenon,
331
+ definition,
332
+ numerator,
333
+ denominator,
334
+ };
335
+ }
336
+ parsePhenomenon(xmlElement) {
337
+ const itemProps = this.getSchemaItemProps(xmlElement);
338
+ const definition = this.getRequiredAttribute(xmlElement, "definition", `The Phenomenon ${this._currentItemFullName} is missing the required 'definition' attribute.`);
339
+ return {
340
+ ...itemProps,
341
+ definition,
342
+ };
343
+ }
344
+ parseFormat(xmlElement) {
345
+ const itemProps = this.getSchemaItemProps(xmlElement);
346
+ const formatType = this.getRequiredAttribute(xmlElement, "type", `The Format ${this._currentItemFullName} is missing the required 'type' attribute.`);
347
+ const precision = this.getOptionalIntAttribute(xmlElement, "precision", `The Format ${this._currentItemFullName} has an invalid 'precision' attribute. It should be a numeric value.`);
348
+ const roundFactor = this.getOptionalFloatAttribute(xmlElement, "roundFactor", `The Format ${this._currentItemFullName} has an invalid 'roundFactor' attribute. It should be a numeric value.`);
349
+ const minWidth = this.getOptionalIntAttribute(xmlElement, "minWidth", `The Format ${this._currentItemFullName} has an invalid 'minWidth' attribute. It should be a numeric value.`);
350
+ const showSignOption = this.getOptionalAttribute(xmlElement, "showSignOption");
351
+ const formatTraitsString = this.getRequiredAttribute(xmlElement, "formatTraits", `The Format ${this._currentItemFullName} is missing the required 'formatTraits' attribute.`);
352
+ const formatTraits = formatTraitsString.split("|");
353
+ const decimalSeparator = this.getOptionalAttribute(xmlElement, "decimalSeparator");
354
+ const thousandSeparator = this.getOptionalAttribute(xmlElement, "thousandSeparator");
355
+ const uomSeparator = this.getOptionalAttribute(xmlElement, "uomSeparator");
356
+ const scientificType = this.getOptionalAttribute(xmlElement, "scientificType");
357
+ const stationOffsetSize = this.getOptionalIntAttribute(xmlElement, "stationOffsetSize", `The Format ${this._currentItemFullName} has an invalid 'stationOffsetSize' attribute. It should be a numeric value.`);
358
+ const stationSeparator = this.getOptionalAttribute(xmlElement, "stationSeparator");
359
+ let composite;
360
+ const compositeResult = this.getElementChildrenByTagName(xmlElement, "Composite");
361
+ if (compositeResult.length > 0) {
362
+ const compositeElement = compositeResult[0];
363
+ const spacer = this.getOptionalAttribute(compositeElement, "spacer");
364
+ const includeZeroString = this.getOptionalAttribute(compositeElement, "includeZero");
365
+ let includeZero;
366
+ if (includeZeroString) {
367
+ includeZero = this.parseBoolean(includeZeroString, `The Format ${this._currentItemFullName} has a Composite with an invalid 'includeZero' attribute. It should be either "true" or "false".`);
368
+ }
369
+ const units = new Array();
370
+ const unitsResult = this.getElementChildrenByTagName(compositeElement, "Unit");
371
+ if (unitsResult.length < 1)
372
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Format ${this._currentItemFullName} has an invalid 'Composite' element. It should have 1-4 Unit elements.`);
373
+ for (const unit of unitsResult) {
374
+ let name = unit.textContent;
375
+ if (null === name || 0 === name.length)
376
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The Format ${this._currentItemFullName} has a Composite with an invalid Unit. One of the Units is missing the required 'name' attribute.`);
377
+ const label = this.getOptionalAttribute(unit, "label");
378
+ name = this.getQualifiedTypeName(name);
379
+ units.push({ name, label });
380
+ }
381
+ composite = {
382
+ spacer,
383
+ includeZero,
384
+ units,
385
+ };
386
+ }
387
+ return {
388
+ ...itemProps,
389
+ type: formatType,
390
+ precision,
391
+ roundFactor,
392
+ minWidth,
393
+ showSignOption,
394
+ formatTraits,
395
+ decimalSeparator,
396
+ thousandSeparator,
397
+ uomSeparator,
398
+ scientificType,
399
+ stationOffsetSize,
400
+ stationSeparator,
401
+ composite,
402
+ };
403
+ }
404
+ parseUnitSystem(xmlElement) {
405
+ return this.getClassProps(xmlElement);
406
+ }
407
+ *getProperties(xmlElement, itemName) {
408
+ const propertyTagRegex = /EC((Struct(Array)?)|Array|Navigation)?Property/;
409
+ const children = this.getElementChildrenByTagName(xmlElement, propertyTagRegex);
410
+ for (const child of children) {
411
+ const childType = child.nodeName;
412
+ const propertyName = this.getRequiredAttribute(child, "propertyName", `An ECProperty in ${itemName} is missing the required 'propertyName' attribute.`);
413
+ const propertyType = this.getPropertyType(childType);
414
+ // This may not be needed, just a failsafe if the regex is faulty
415
+ if (propertyType === undefined)
416
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ECProperty ${itemName}.${propertyName} has an invalid type. ${childType} is not a valid ECProperty type.`);
417
+ yield [propertyName, propertyType, child];
418
+ }
419
+ }
420
+ parsePrimitiveProperty(xmlElement) {
421
+ const propertyProps = this.getPrimitiveOrEnumPropertyBaseProps(xmlElement);
422
+ const typeName = this.getPropertyTypeName(xmlElement);
423
+ const primitivePropertyProps = { ...propertyProps, typeName };
424
+ return primitivePropertyProps;
425
+ }
426
+ parseStructProperty(xmlElement) {
427
+ const propertyProps = this.getPropertyProps(xmlElement);
428
+ const typeName = this.getPropertyTypeName(xmlElement);
429
+ const structPropertyProps = { ...propertyProps, typeName };
430
+ return structPropertyProps;
431
+ }
432
+ parsePrimitiveArrayProperty(xmlElement) {
433
+ const typeName = this.getPropertyTypeName(xmlElement);
434
+ const propertyProps = this.getPrimitiveOrEnumPropertyBaseProps(xmlElement);
435
+ const minAndMaxOccurs = this.getPropertyMinAndMaxOccurs(xmlElement);
436
+ return {
437
+ ...propertyProps,
438
+ ...minAndMaxOccurs,
439
+ typeName,
440
+ };
441
+ }
442
+ parseStructArrayProperty(xmlElement) {
443
+ const propertyProps = this.getPropertyProps(xmlElement);
444
+ const typeName = this.getPropertyTypeName(xmlElement);
445
+ const minAndMaxOccurs = this.getPropertyMinAndMaxOccurs(xmlElement);
446
+ return {
447
+ ...propertyProps,
448
+ ...minAndMaxOccurs,
449
+ typeName,
450
+ };
451
+ }
452
+ parseNavigationProperty(xmlElement) {
453
+ const propName = this.getPropertyName(xmlElement);
454
+ const propertyProps = this.getPropertyProps(xmlElement);
455
+ let relationshipName = this.getRequiredAttribute(xmlElement, "relationshipName", `The ECNavigationProperty ${this._currentItemFullName}.${propName} is missing the required 'relationshipName' property.`);
456
+ const direction = this.getRequiredAttribute(xmlElement, "direction", `The ECNavigationProperty ${this._currentItemFullName}.${propName} is missing the required 'direction' property.`);
457
+ relationshipName = this.getQualifiedTypeName(relationshipName);
458
+ return {
459
+ ...propertyProps,
460
+ relationshipName,
461
+ direction,
462
+ };
463
+ }
464
+ getSchemaCustomAttributeProviders() {
465
+ return this.getCustomAttributeProviders(this._rawSchema.documentElement, "Schema", this._schemaName);
466
+ }
467
+ getClassCustomAttributeProviders(xmlElement) {
468
+ return this.getCustomAttributeProviders(xmlElement, "ECClass", this._currentItemFullName);
469
+ }
470
+ getPropertyCustomAttributeProviders(xmlElement) {
471
+ const propName = this.getPropertyName(xmlElement);
472
+ return this.getCustomAttributeProviders(xmlElement, "ECProperty", `${this._currentItemFullName}.${propName}`);
473
+ }
474
+ getRelationshipConstraintCustomAttributeProviders(xmlElement) {
475
+ const sourceResult = this.getElementChildrenByTagName(xmlElement, "Source");
476
+ if (sourceResult.length < 1)
477
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The RelationshipClass ${this._currentItemFullName} is missing the required Source constraint tag.`);
478
+ const sourceElement = sourceResult[0];
479
+ const sourceCustomAttributes = this.getCustomAttributeProviders(sourceElement, "Source Constraint of", this._currentItemFullName);
480
+ const targetResult = this.getElementChildrenByTagName(xmlElement, "Target");
481
+ if (targetResult.length < 1)
482
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The RelationshipClass ${this._currentItemFullName} is missing the required Target constraint tag.`);
483
+ const targetElement = targetResult[0];
484
+ const targetCustomAttributes = this.getCustomAttributeProviders(targetElement, "Source Constraint of", this._currentItemFullName);
485
+ return [sourceCustomAttributes, targetCustomAttributes];
486
+ }
487
+ getElementChildren(xmlElement) {
488
+ // NodeListOf<T> does not define [Symbol.iterator]
489
+ const children = Array.from(xmlElement.childNodes).filter((child) => {
490
+ // (node.nodeType === 1) implies instanceof Element
491
+ // https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/children#Polyfill
492
+ return child.nodeType === 1;
493
+ });
494
+ return children;
495
+ }
496
+ getElementChildrenByTagName(xmlElement, tagName) {
497
+ const children = this.getElementChildren(xmlElement);
498
+ if ("*" === tagName)
499
+ return children;
500
+ let result;
501
+ if (typeof tagName === "string") {
502
+ result = children.filter((child) => {
503
+ return tagName.toLowerCase() === child.nodeName.toLowerCase();
504
+ });
505
+ }
506
+ else {
507
+ result = children.filter((child) => {
508
+ return tagName.test(child.nodeName);
509
+ });
510
+ }
511
+ return result;
512
+ }
513
+ getOptionalAttribute(xmlElement, attributeName) {
514
+ if (!xmlElement.hasAttribute(attributeName))
515
+ return undefined;
516
+ const result = xmlElement.getAttribute(attributeName);
517
+ // The typings for the return value of getAttribute do not match that of xmldom
518
+ // xmldom returns an empty string instead of null
519
+ // However Typescript will still treat result as a union type without this check
520
+ // Hence this is needed for tsc to compile
521
+ if (result === null)
522
+ return undefined;
523
+ return result;
524
+ }
525
+ getOptionalFloatAttribute(xmlElement, attributeName, parseErrorMsg) {
526
+ const resultString = this.getOptionalAttribute(xmlElement, attributeName);
527
+ let result;
528
+ if (resultString) {
529
+ result = parseFloat(resultString);
530
+ if (isNaN(result))
531
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, parseErrorMsg);
532
+ }
533
+ return result;
534
+ }
535
+ getOptionalIntAttribute(xmlElement, attributeName, parseErrorMsg) {
536
+ const resultString = this.getOptionalAttribute(xmlElement, attributeName);
537
+ let result;
538
+ if (resultString) {
539
+ result = parseInt(resultString, 10);
540
+ if (isNaN(result))
541
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, parseErrorMsg);
542
+ }
543
+ return result;
544
+ }
545
+ parseBoolean(text, parseErrorMsg) {
546
+ const textString = text.toLowerCase();
547
+ if ("true" === textString)
548
+ return true;
549
+ else if ("false" === textString)
550
+ return false;
551
+ else
552
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, parseErrorMsg);
553
+ }
554
+ getRequiredAttribute(xmlElement, attributeName, errorMsg) {
555
+ if (!xmlElement.hasAttribute(attributeName))
556
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, errorMsg);
557
+ const result = xmlElement.getAttribute(attributeName);
558
+ if (result === null)
559
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, errorMsg);
560
+ return result;
561
+ }
562
+ getSchemaReference(xmlElement) {
563
+ const alias = this.getRequiredAttribute(xmlElement, "alias", `The schema ${this._schemaName} has an invalid ECSchemaReference attribute. One of the references is missing the required 'alias' attribute.`);
564
+ const name = this.getRequiredAttribute(xmlElement, "name", `The schema ${this._schemaName} has an invalid ECSchemaReference attribute. One of the references is missing the required 'name' attribute.`);
565
+ const version = this.getRequiredAttribute(xmlElement, "version", `The schema ${this._schemaName} has an invalid ECSchemaReference attribute. One of the references is missing the required 'version' attribute.`);
566
+ if (!this._schemaReferenceNames.has(alias.toLowerCase()))
567
+ this._schemaReferenceNames.set(alias.toLowerCase(), name);
568
+ return {
569
+ name,
570
+ version,
571
+ };
572
+ }
573
+ getSchemaItemType(rawType) {
574
+ switch (rawType.toLowerCase()) {
575
+ case "ecentityclass": return "EntityClass";
576
+ case "mixin": return "Mixin";
577
+ case "ecstructclass": return "StructClass";
578
+ case "eccustomattributeclass": return "CustomAttributeClass";
579
+ case "ecrelationshipclass": return "RelationshipClass";
580
+ case "ecenumeration": return "Enumeration";
581
+ case "kindofquantity": return "KindOfQuantity";
582
+ case "propertycategory": return "PropertyCategory";
583
+ case "unit": return "Unit";
584
+ case "invertedunit": return "InvertedUnit";
585
+ case "constant": return "Constant";
586
+ case "phenomenon": return "Phenomenon";
587
+ case "unitsystem": return "UnitSystem";
588
+ case "format": return "Format";
589
+ }
590
+ return undefined;
591
+ }
592
+ getSchemaChildren() {
593
+ const schemaMetadata = this._rawSchema.documentElement;
594
+ return this.getElementChildren(schemaMetadata);
595
+ }
596
+ getSchemaItemProps(xmlElement) {
597
+ const displayLabel = this.getOptionalAttribute(xmlElement, "displayLabel");
598
+ const description = this.getOptionalAttribute(xmlElement, "description");
599
+ return {
600
+ description,
601
+ label: displayLabel,
602
+ };
603
+ }
604
+ getClassProps(xmlElement) {
605
+ const itemProps = this.getSchemaItemProps(xmlElement);
606
+ const modifier = this.getOptionalAttribute(xmlElement, "modifier");
607
+ let baseClass = null;
608
+ const baseClasses = this.getElementChildrenByTagName(xmlElement, "BaseClass");
609
+ if (baseClasses.length > 0) {
610
+ // We are assuming here that the first BaseClass is the 'real' one - the rest are mixins
611
+ // This is not a finalized approach as this could lead to unsupported schemas
612
+ baseClass = baseClasses[0].textContent;
613
+ }
614
+ baseClass = baseClass ? this.getQualifiedTypeName(baseClass) : undefined;
615
+ return {
616
+ ...itemProps,
617
+ modifier,
618
+ baseClass,
619
+ };
620
+ }
621
+ getRelationshipConstraintProps(xmlElement, isSource) {
622
+ const constraintName = `${(isSource) ? "Source" : "Target"} Constraint of ${this._currentItemFullName}`;
623
+ const multiplicity = this.getRequiredAttribute(xmlElement, "multiplicity", `The ${constraintName} is missing the required 'multiplicity' attribute.`);
624
+ const roleLabel = this.getRequiredAttribute(xmlElement, "roleLabel", `The ${constraintName} is missing the required 'roleLabel' attribute.`);
625
+ const polymorphicString = this.getRequiredAttribute(xmlElement, "polymorphic", `The ${constraintName} is missing the required 'polymorphic' attribute.`);
626
+ const polymorphic = this.parseBoolean(polymorphicString, `The ${constraintName} has an invalid 'polymorphic' attribute. It should either be "true" or "false".`);
627
+ let abstractConstraint = this.getOptionalAttribute(xmlElement, "abstractConstraint");
628
+ if (undefined !== abstractConstraint)
629
+ abstractConstraint = this.getQualifiedTypeName(abstractConstraint);
630
+ const constraintClasses = new Array();
631
+ const constraintClassesResult = this.getElementChildrenByTagName(xmlElement, "Class");
632
+ if (constraintClassesResult.length < 1)
633
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ${constraintName} is missing the required Class tags.`);
634
+ for (const constraintClass of constraintClassesResult) {
635
+ let constraintClassId = constraintClass.getAttribute("class");
636
+ if (null === constraintClassId || 0 === constraintClassId.length)
637
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ${constraintName} has a Class that is missing the required 'class' attribute.`);
638
+ constraintClassId = this.getQualifiedTypeName(constraintClassId);
639
+ constraintClasses.push(constraintClassId);
640
+ }
641
+ return {
642
+ multiplicity,
643
+ roleLabel,
644
+ polymorphic,
645
+ abstractConstraint,
646
+ constraintClasses,
647
+ };
648
+ }
649
+ getPropertyType(propType) {
650
+ switch (propType) {
651
+ case "ECNavigationProperty": return "navigationproperty";
652
+ case "ECStructProperty": return "structproperty";
653
+ case "ECArrayProperty": return "primitivearrayproperty";
654
+ case "ECStructArrayProperty": return "structarrayproperty";
655
+ case "ECProperty": return "primitiveproperty";
656
+ default: return undefined;
657
+ }
658
+ }
659
+ getPropertyName(xmlElement) {
660
+ return this.getRequiredAttribute(xmlElement, "propertyName", `An ECProperty in ${this._currentItemFullName} is missing the required 'propertyName' attribute.`);
661
+ }
662
+ getPropertyProps(xmlElement) {
663
+ const propName = this.getPropertyName(xmlElement);
664
+ const propType = this.getPropertyType(xmlElement.nodeName);
665
+ if (propType === undefined)
666
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid type. ${propType} is not a valid ECProperty type.`);
667
+ const label = this.getOptionalAttribute(xmlElement, "displayLabel");
668
+ const description = this.getOptionalAttribute(xmlElement, "description");
669
+ const readOnlyString = this.getOptionalAttribute(xmlElement, "readOnly");
670
+ let isReadOnly;
671
+ if (readOnlyString) {
672
+ isReadOnly = this.parseBoolean(readOnlyString, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'readOnly' attribute. It should be either "true" or "false".`);
673
+ }
674
+ let category = this.getOptionalAttribute(xmlElement, "category");
675
+ const priority = this.getOptionalIntAttribute(xmlElement, "priority", `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'priority' attribute. It should be a numeric value.`);
676
+ const inheritedString = this.getOptionalAttribute(xmlElement, "inherited");
677
+ let inherited;
678
+ if (inheritedString) {
679
+ inherited = this.parseBoolean(inheritedString, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'inherited' attribute. It should be either "true" or "false".`);
680
+ }
681
+ let kindOfQuantity = this.getOptionalAttribute(xmlElement, "kindOfQuantity");
682
+ if (kindOfQuantity)
683
+ kindOfQuantity = this.getQualifiedTypeName(kindOfQuantity);
684
+ if (category)
685
+ category = this.getQualifiedTypeName(category);
686
+ return {
687
+ name: propName,
688
+ type: propType,
689
+ description,
690
+ label,
691
+ isReadOnly,
692
+ category,
693
+ priority,
694
+ inherited,
695
+ kindOfQuantity,
696
+ };
697
+ }
698
+ getPropertyTypeName(xmlElement) {
699
+ const propName = this.getPropertyName(xmlElement);
700
+ const rawTypeName = this.getRequiredAttribute(xmlElement, "typeName", `The ECProperty ${this._currentItemFullName}.${propName} is missing the required 'typeName' attribute.`);
701
+ // If not a primitive type, we must prepend the schema name.
702
+ const primitiveType = parsePrimitiveType(rawTypeName);
703
+ if (primitiveType)
704
+ return rawTypeName;
705
+ return this.getQualifiedTypeName(rawTypeName);
706
+ }
707
+ getPrimitiveOrEnumPropertyBaseProps(xmlElement) {
708
+ const propertyProps = this.getPropertyProps(xmlElement);
709
+ const propName = propertyProps.name;
710
+ const extendedTypeName = this.getOptionalAttribute(xmlElement, "extendedTypeName");
711
+ const minLength = this.getOptionalIntAttribute(xmlElement, "minimumLength", `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'minimumLength' attribute. It should be a numeric value.`);
712
+ const maxLength = this.getOptionalIntAttribute(xmlElement, "maximumLength", `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'maximumLength' attribute. It should be a numeric value.`);
713
+ const minValue = this.getOptionalIntAttribute(xmlElement, "minimumValue", `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'minimumValue' attribute. It should be a numeric value.`);
714
+ const maxValue = this.getOptionalIntAttribute(xmlElement, "maximumValue", `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'maximumValue' attribute. It should be a numeric value.`);
715
+ return {
716
+ ...propertyProps,
717
+ extendedTypeName,
718
+ minLength,
719
+ maxLength,
720
+ minValue,
721
+ maxValue,
722
+ };
723
+ }
724
+ getPropertyMinAndMaxOccurs(xmlElement) {
725
+ const propName = this.getPropertyName(xmlElement);
726
+ const minOccurs = this.getOptionalIntAttribute(xmlElement, "minOccurs", `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'minOccurs' attribute. It should be a numeric value.`);
727
+ const maxOccursStr = this.getOptionalAttribute(xmlElement, "maxOccurs");
728
+ let maxOccurs;
729
+ if ("unbounded" === maxOccursStr)
730
+ maxOccurs = 2147483647; // TODO: This should be using the INT32_MAX variable.
731
+ else if (undefined !== maxOccursStr) {
732
+ maxOccurs = parseInt(maxOccursStr, 10);
733
+ if (isNaN(maxOccurs))
734
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `The ECProperty ${this._currentItemFullName}.${propName} has an invalid 'maxOccurs' attribute. It should be a numeric value.`);
735
+ }
736
+ return { minOccurs, maxOccurs };
737
+ }
738
+ *getCustomAttributeProviders(xmlElement, type, _name) {
739
+ const customAttributesResult = this.getElementChildrenByTagName(xmlElement, "ECCustomAttributes");
740
+ if (customAttributesResult.length < 1)
741
+ return;
742
+ const attributes = this.getElementChildren(customAttributesResult[0]);
743
+ for (const attribute of attributes) {
744
+ if ("ECClass" === type && "IsMixin" === attribute.tagName)
745
+ continue;
746
+ yield this.getCustomAttributeProvider(attribute);
747
+ }
748
+ }
749
+ getCustomAttributeProvider(xmlCustomAttribute) {
750
+ assert(this._ecXmlVersion !== undefined);
751
+ let ns = xmlCustomAttribute.getAttribute("xmlns");
752
+ if (!ns) {
753
+ assert(this._schemaName !== undefined);
754
+ assert(this._schemaVersion !== undefined);
755
+ ns = `${this._schemaName}.${this._schemaVersion}`;
756
+ }
757
+ if (null === ns || !this.isSchemaFullNameValidForVersion(ns, this._ecXmlVersion))
758
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Custom attribute namespaces must contain a valid 3.2 full schema name in the form <schemaName>.RR.ww.mm.`);
759
+ const schemaNameParts = ns.split(".");
760
+ const className = `${schemaNameParts[0]}.${xmlCustomAttribute.tagName}`;
761
+ const properties = this.getElementChildren(xmlCustomAttribute);
762
+ const provider = (caClass) => {
763
+ return this.addCAPropertyValues(caClass, properties);
764
+ };
765
+ return [className, provider];
766
+ }
767
+ addCAPropertyValues(caClass, propertyElements) {
768
+ const instance = { className: caClass.fullName };
769
+ if (!caClass.properties)
770
+ return instance;
771
+ for (const propertyElement of propertyElements) {
772
+ const value = this.readPropertyValue(propertyElement, caClass);
773
+ if (value !== undefined)
774
+ instance[propertyElement.tagName] = value;
775
+ }
776
+ return instance;
777
+ }
778
+ readPropertyValue(propElement, parentClass) {
779
+ const propertyClass = parentClass.getPropertySync(propElement.tagName);
780
+ if (!propertyClass)
781
+ return;
782
+ if (propertyClass.isArray())
783
+ return this.readArrayPropertyValue(propElement, propertyClass);
784
+ let enumeration;
785
+ if (propertyClass.isPrimitive()) {
786
+ if (propertyClass.isEnumeration() && propertyClass.enumeration) {
787
+ enumeration = propertyClass.schema.lookupItemSync(propertyClass.enumeration.fullName);
788
+ if (!enumeration)
789
+ throw new ECObjectsError(ECObjectsStatus.ClassNotFound, `The Enumeration class '${propertyClass.enumeration.fullName}' could not be found.`);
790
+ }
791
+ const primitiveType = enumeration && enumeration.type ? enumeration.type : (propertyClass).primitiveType;
792
+ return this.readPrimitivePropertyValue(propElement, primitiveType);
793
+ }
794
+ if (propertyClass.isStruct())
795
+ return this.readStructPropertyValue(propElement, propertyClass.structClass);
796
+ return undefined;
797
+ }
798
+ readArrayPropertyValue(propElement, propertyClass) {
799
+ if (propertyClass.isPrimitive())
800
+ return this.readPrimitiveArrayValues(propElement, propertyClass.primitiveType);
801
+ if (propertyClass.isStruct())
802
+ return this.readStructArrayValues(propElement, propertyClass);
803
+ return undefined;
804
+ }
805
+ readPrimitiveArrayValues(propElement, primitiveType) {
806
+ const typeName = primitiveTypeToString(primitiveType);
807
+ const children = this.getElementChildrenByTagName(propElement, typeName);
808
+ const values = [];
809
+ for (const child of children) {
810
+ const value = this.readPrimitivePropertyValue(child, primitiveType);
811
+ values.push(value);
812
+ }
813
+ return values;
814
+ }
815
+ readStructArrayValues(propElement, propertyClass) {
816
+ const children = this.getElementChildren(propElement);
817
+ const values = [];
818
+ for (const child of children) {
819
+ const value = this.readStructPropertyValue(child, propertyClass.structClass);
820
+ values.push(value);
821
+ }
822
+ return values;
823
+ }
824
+ readStructPropertyValue(propElement, structClass) {
825
+ const structObj = {};
826
+ const children = this.getElementChildren(propElement);
827
+ for (const child of children) {
828
+ const value = this.readPropertyValue(child, structClass);
829
+ if (value !== undefined)
830
+ structObj[child.tagName] = value;
831
+ }
832
+ return structObj;
833
+ }
834
+ readPrimitivePropertyValue(propElement, primitiveType) {
835
+ if (!propElement.textContent)
836
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Primitive property '${propElement.tagName}' has an invalid property value.`);
837
+ // TODO: Mapping all primitive types to string, number and boolean
838
+ // for now. Need to review with IModelJs.
839
+ switch (primitiveType) {
840
+ case PrimitiveType.String:
841
+ case PrimitiveType.Binary: /** TODO - Currently treated as strings */
842
+ case PrimitiveType.IGeometry: /** TODO - Currently treated as strings */
843
+ return propElement.textContent;
844
+ case PrimitiveType.DateTime:
845
+ return this.getDatePropertyValue(propElement.textContent, propElement.tagName);
846
+ case PrimitiveType.Point2d:
847
+ return this.getPoint2DPropertyValue(propElement.textContent, propElement.tagName);
848
+ case PrimitiveType.Point3d:
849
+ return this.getPoint3DPropertyValue(propElement.textContent, propElement.tagName);
850
+ case PrimitiveType.Boolean:
851
+ return this.getBooleanPropertyValue(propElement.textContent, propElement.tagName);
852
+ case PrimitiveType.Integer:
853
+ case PrimitiveType.Long:
854
+ return this.getIntegerPropertyValue(propElement.textContent, propElement.tagName);
855
+ case PrimitiveType.Double:
856
+ return this.getDoublePropertyValue(propElement.textContent, propElement.tagName);
857
+ default:
858
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Primitive property '${propElement.tagName}' has an invalid primitive type.`);
859
+ }
860
+ }
861
+ getBooleanPropertyValue(propValue, propName) {
862
+ if (propValue.toLowerCase() === "true" ||
863
+ Number.parseInt(propValue, 10) > 0) {
864
+ return true;
865
+ }
866
+ else if (propValue.toLowerCase() === "false" ||
867
+ Number.parseInt(propValue, 10) === 0) {
868
+ return false;
869
+ }
870
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. An boolean value was expected.`);
871
+ }
872
+ getIntegerPropertyValue(propValue, propName) {
873
+ const result = Number.parseFloat(propValue);
874
+ if (isNaN(result) || result % 1 !== 0)
875
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. An integer value was expected.`);
876
+ return result;
877
+ }
878
+ getDatePropertyValue(propValue, propName) {
879
+ const result = Number.parseInt(propValue, 10);
880
+ if (isNaN(result))
881
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. A date in milliseconds was expected.`);
882
+ return new Date(result);
883
+ }
884
+ getDoublePropertyValue(propValue, propName) {
885
+ const result = Number.parseFloat(propValue);
886
+ if (isNaN(result))
887
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. A double value was expected.`);
888
+ return result;
889
+ }
890
+ getPoint2DPropertyValue(propValue, propName) {
891
+ const result = propValue.split(",");
892
+ if (result.length !== 2) {
893
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. A Point 2D value was expected.`);
894
+ }
895
+ const x = Number.parseFloat(result[0]);
896
+ const y = Number.parseFloat(result[1]);
897
+ if (isNaN(x) || isNaN(y))
898
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. A Point 2D value was expected.`);
899
+ return { x, y };
900
+ }
901
+ getPoint3DPropertyValue(propValue, propName) {
902
+ const result = propValue.split(",");
903
+ if (result.length !== 3) {
904
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. A Point 3D value was expected.`);
905
+ }
906
+ const x = Number.parseFloat(result[0]);
907
+ const y = Number.parseFloat(result[1]);
908
+ const z = Number.parseFloat(result[2]);
909
+ if (isNaN(x) || isNaN(y) || isNaN(z))
910
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `Property '${propName}' has an invalid property value. A Point 3D value was expected.`);
911
+ return { x, y, z };
912
+ }
913
+ isSchemaFullNameValidForVersion(schemaFullName, ecXmlVersion) {
914
+ const schemaNameParts = schemaFullName.split(".");
915
+ if ((ecXmlVersion.readVersion >= 3 && ecXmlVersion.writeVersion >= 2) || ecXmlVersion.readVersion > 3) {
916
+ if (schemaNameParts.length < 4)
917
+ return false;
918
+ }
919
+ else {
920
+ if (schemaNameParts.length < 3)
921
+ return false;
922
+ }
923
+ return true;
924
+ }
925
+ parseXmlNamespace(xmlNamespace) {
926
+ const regEx = new RegExp(`^${ECXML_URI}\\.([0-9]+)\\.([0-9]+)$`);
927
+ const match = xmlNamespace.match(regEx);
928
+ if (!match)
929
+ return;
930
+ const readVersion = parseInt(match[1], 10);
931
+ const writeVersion = parseInt(match[2], 10);
932
+ return { readVersion, writeVersion };
933
+ }
934
+ getQualifiedTypeName(rawTypeName) {
935
+ const nameParts = rawTypeName.split(":");
936
+ if (nameParts.length !== 2)
937
+ return `${this._schemaName}.${rawTypeName}`;
938
+ if (nameParts[0].toLowerCase() === this._schemaAlias.toLowerCase())
939
+ return `${this._schemaName}.${nameParts[1]}`;
940
+ if (this._schemaReferenceNames.has(nameParts[0].toLowerCase()))
941
+ return `${this._schemaReferenceNames.get(nameParts[0].toLowerCase())}.${nameParts[1]}`;
942
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaXML, `No valid schema found for alias ${nameParts[0]}`);
943
+ }
944
+ /** The rest of the API uses the full name format of `{SchemaName}.{SchemaItemName}`,
945
+ * meaning all of the references in the format string need to be changed.
946
+ */
947
+ getQualifiedPresentationUnits(presentationUnits) {
948
+ const res = [];
949
+ for (const presentationUnit of presentationUnits) {
950
+ // we split the presentation unit by square parantheses [ ], f:DefaultReal(6)[u:FT|feet] will be splitted into f:DefaultReal(6) and u:FT|feet
951
+ // we format the first one and the next one will be put into [ ] again
952
+ const presentationUnitFormats = presentationUnit.split(/[\[\]]/g);
953
+ let qualifiedPresentation = "";
954
+ qualifiedPresentation = this.getQualifiedTypeName(presentationUnitFormats[0]);
955
+ if (presentationUnitFormats.length > 1) {
956
+ for (let i = 1; i < presentationUnitFormats.length; ++i) {
957
+ if (presentationUnitFormats[i].length === 0)
958
+ continue;
959
+ const verticalSlashIdx = presentationUnitFormats[i].indexOf("|");
960
+ const overrideFormat = this.getQualifiedTypeName(presentationUnitFormats[i].slice(0, verticalSlashIdx));
961
+ const formatLabel = presentationUnitFormats[i].slice(verticalSlashIdx);
962
+ qualifiedPresentation += `[${overrideFormat}${formatLabel}]`;
963
+ }
964
+ }
965
+ res.push(qualifiedPresentation);
966
+ }
967
+ return res;
968
+ }
969
+ }
970
+ //# sourceMappingURL=XmlParser.js.map