@itwin/ecschema-metadata 5.0.0-dev.9 → 5.0.0-dev.90

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 (298) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/lib/cjs/Constants.js +20 -20
  3. package/lib/cjs/Constants.js.map +1 -1
  4. package/lib/cjs/Context.d.ts +83 -34
  5. package/lib/cjs/Context.d.ts.map +1 -1
  6. package/lib/cjs/Context.js +73 -23
  7. package/lib/cjs/Context.js.map +1 -1
  8. package/lib/cjs/DelayedPromise.js +6 -4
  9. package/lib/cjs/DelayedPromise.js.map +1 -1
  10. package/lib/cjs/Deserialization/AbstractParser.js +1 -0
  11. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  12. package/lib/cjs/Deserialization/Helper.d.ts +3 -3
  13. package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
  14. package/lib/cjs/Deserialization/Helper.js +8 -0
  15. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  16. package/lib/cjs/Deserialization/JsonParser.js +3 -0
  17. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  18. package/lib/cjs/Deserialization/JsonProps.d.ts +3 -0
  19. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  20. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  21. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  22. package/lib/cjs/Deserialization/XmlParser.d.ts.map +1 -1
  23. package/lib/cjs/Deserialization/XmlParser.js +11 -3
  24. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  25. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
  26. package/lib/cjs/Deserialization/XmlSerializationUtils.js +2 -6
  27. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  28. package/lib/cjs/ECName.js +1 -0
  29. package/lib/cjs/ECName.js.map +1 -1
  30. package/lib/cjs/ECObjects.d.ts +21 -1
  31. package/lib/cjs/ECObjects.d.ts.map +1 -1
  32. package/lib/cjs/ECObjects.js +33 -2
  33. package/lib/cjs/ECObjects.js.map +1 -1
  34. package/lib/cjs/Exception.js +1 -0
  35. package/lib/cjs/Exception.js.map +1 -1
  36. package/lib/cjs/Interfaces.d.ts +10 -3
  37. package/lib/cjs/Interfaces.d.ts.map +1 -1
  38. package/lib/cjs/Interfaces.js.map +1 -1
  39. package/lib/cjs/Metadata/Class.d.ts +75 -16
  40. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  41. package/lib/cjs/Metadata/Class.js +168 -46
  42. package/lib/cjs/Metadata/Class.js.map +1 -1
  43. package/lib/cjs/Metadata/Constant.d.ts +14 -1
  44. package/lib/cjs/Metadata/Constant.d.ts.map +1 -1
  45. package/lib/cjs/Metadata/Constant.js +27 -2
  46. package/lib/cjs/Metadata/Constant.js.map +1 -1
  47. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  48. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +16 -4
  49. package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
  50. package/lib/cjs/Metadata/CustomAttributeClass.js +22 -4
  51. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  52. package/lib/cjs/Metadata/EntityClass.d.ts +20 -8
  53. package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
  54. package/lib/cjs/Metadata/EntityClass.js +42 -22
  55. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  56. package/lib/cjs/Metadata/Enumeration.d.ts +14 -1
  57. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  58. package/lib/cjs/Metadata/Enumeration.js +22 -1
  59. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  60. package/lib/cjs/Metadata/Format.d.ts +41 -1
  61. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  62. package/lib/cjs/Metadata/Format.js +68 -3
  63. package/lib/cjs/Metadata/Format.js.map +1 -1
  64. package/lib/cjs/Metadata/InvertedUnit.d.ts +8 -3
  65. package/lib/cjs/Metadata/InvertedUnit.d.ts.map +1 -1
  66. package/lib/cjs/Metadata/InvertedUnit.js +17 -6
  67. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  68. package/lib/cjs/Metadata/KindOfQuantity.d.ts +14 -3
  69. package/lib/cjs/Metadata/KindOfQuantity.d.ts.map +1 -1
  70. package/lib/cjs/Metadata/KindOfQuantity.js +43 -18
  71. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  72. package/lib/cjs/Metadata/Mixin.d.ts +15 -1
  73. package/lib/cjs/Metadata/Mixin.d.ts.map +1 -1
  74. package/lib/cjs/Metadata/Mixin.js +23 -2
  75. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  76. package/lib/cjs/Metadata/OverrideFormat.js +9 -0
  77. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  78. package/lib/cjs/Metadata/Phenomenon.d.ts +14 -1
  79. package/lib/cjs/Metadata/Phenomenon.d.ts.map +1 -1
  80. package/lib/cjs/Metadata/Phenomenon.js +22 -1
  81. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  82. package/lib/cjs/Metadata/Property.d.ts +5 -1
  83. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  84. package/lib/cjs/Metadata/Property.js +83 -28
  85. package/lib/cjs/Metadata/Property.js.map +1 -1
  86. package/lib/cjs/Metadata/PropertyCategory.d.ts +14 -1
  87. package/lib/cjs/Metadata/PropertyCategory.d.ts.map +1 -1
  88. package/lib/cjs/Metadata/PropertyCategory.js +21 -1
  89. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  90. package/lib/cjs/Metadata/RelationshipClass.d.ts +15 -2
  91. package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
  92. package/lib/cjs/Metadata/RelationshipClass.js +47 -10
  93. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  94. package/lib/cjs/Metadata/Schema.d.ts +116 -11
  95. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  96. package/lib/cjs/Metadata/Schema.js +135 -33
  97. package/lib/cjs/Metadata/Schema.js.map +1 -1
  98. package/lib/cjs/Metadata/SchemaItem.d.ts +11 -2
  99. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  100. package/lib/cjs/Metadata/SchemaItem.js +10 -0
  101. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  102. package/lib/cjs/Metadata/Unit.d.ts +8 -1
  103. package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
  104. package/lib/cjs/Metadata/Unit.js +21 -3
  105. package/lib/cjs/Metadata/Unit.js.map +1 -1
  106. package/lib/cjs/Metadata/UnitSystem.d.ts +14 -3
  107. package/lib/cjs/Metadata/UnitSystem.d.ts.map +1 -1
  108. package/lib/cjs/Metadata/UnitSystem.js +21 -3
  109. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  110. package/lib/cjs/PropertyTypes.js.map +1 -1
  111. package/lib/cjs/SchemaJsonLocater.d.ts +3 -3
  112. package/lib/cjs/SchemaJsonLocater.d.ts.map +1 -1
  113. package/lib/cjs/SchemaJsonLocater.js +3 -3
  114. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  115. package/lib/cjs/SchemaKey.d.ts +7 -1
  116. package/lib/cjs/SchemaKey.d.ts.map +1 -1
  117. package/lib/cjs/SchemaKey.js +13 -3
  118. package/lib/cjs/SchemaKey.js.map +1 -1
  119. package/lib/cjs/SchemaLoader.d.ts +2 -2
  120. package/lib/cjs/SchemaLoader.d.ts.map +1 -1
  121. package/lib/cjs/SchemaLoader.js +1 -0
  122. package/lib/cjs/SchemaLoader.js.map +1 -1
  123. package/lib/cjs/SchemaPartVisitorDelegate.js +1 -0
  124. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  125. package/lib/cjs/UnitConversion/Graph.js +69 -65
  126. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  127. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  128. package/lib/cjs/UnitConversion/UnitConversion.d.ts +1 -1
  129. package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -1
  130. package/lib/cjs/UnitConversion/UnitConversion.js +9 -7
  131. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  132. package/lib/cjs/UnitConversion/UnitConverter.js +2 -0
  133. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  134. package/lib/cjs/UnitConversion/UnitTree.d.ts +2 -0
  135. package/lib/cjs/UnitConversion/UnitTree.d.ts.map +1 -1
  136. package/lib/cjs/UnitConversion/UnitTree.js +11 -1
  137. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  138. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts.map +1 -1
  139. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +8 -9
  140. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  141. package/lib/cjs/Validation/SchemaWalker.d.ts +1 -1
  142. package/lib/cjs/Validation/SchemaWalker.d.ts.map +1 -1
  143. package/lib/cjs/Validation/SchemaWalker.js +6 -4
  144. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  145. package/lib/cjs/ecschema-metadata.d.ts +1 -1
  146. package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
  147. package/lib/cjs/ecschema-metadata.js.map +1 -1
  148. package/lib/cjs/utils/SchemaGraph.js +2 -3
  149. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  150. package/lib/esm/Constants.js +20 -20
  151. package/lib/esm/Constants.js.map +1 -1
  152. package/lib/esm/Context.d.ts +83 -34
  153. package/lib/esm/Context.d.ts.map +1 -1
  154. package/lib/esm/Context.js +71 -21
  155. package/lib/esm/Context.js.map +1 -1
  156. package/lib/esm/DelayedPromise.js +6 -4
  157. package/lib/esm/DelayedPromise.js.map +1 -1
  158. package/lib/esm/Deserialization/AbstractParser.js +1 -0
  159. package/lib/esm/Deserialization/AbstractParser.js.map +1 -1
  160. package/lib/esm/Deserialization/Helper.d.ts +3 -3
  161. package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
  162. package/lib/esm/Deserialization/Helper.js +8 -0
  163. package/lib/esm/Deserialization/Helper.js.map +1 -1
  164. package/lib/esm/Deserialization/JsonParser.js +3 -0
  165. package/lib/esm/Deserialization/JsonParser.js.map +1 -1
  166. package/lib/esm/Deserialization/JsonProps.d.ts +3 -0
  167. package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -1
  168. package/lib/esm/Deserialization/JsonProps.js.map +1 -1
  169. package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -1
  170. package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -1
  171. package/lib/esm/Deserialization/XmlParser.js +11 -3
  172. package/lib/esm/Deserialization/XmlParser.js.map +1 -1
  173. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
  174. package/lib/esm/Deserialization/XmlSerializationUtils.js +2 -6
  175. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
  176. package/lib/esm/ECName.js +1 -0
  177. package/lib/esm/ECName.js.map +1 -1
  178. package/lib/esm/ECObjects.d.ts +21 -1
  179. package/lib/esm/ECObjects.d.ts.map +1 -1
  180. package/lib/esm/ECObjects.js +31 -1
  181. package/lib/esm/ECObjects.js.map +1 -1
  182. package/lib/esm/Exception.js +1 -0
  183. package/lib/esm/Exception.js.map +1 -1
  184. package/lib/esm/Interfaces.d.ts +10 -3
  185. package/lib/esm/Interfaces.d.ts.map +1 -1
  186. package/lib/esm/Interfaces.js.map +1 -1
  187. package/lib/esm/Metadata/Class.d.ts +75 -16
  188. package/lib/esm/Metadata/Class.d.ts.map +1 -1
  189. package/lib/esm/Metadata/Class.js +169 -47
  190. package/lib/esm/Metadata/Class.js.map +1 -1
  191. package/lib/esm/Metadata/Constant.d.ts +14 -1
  192. package/lib/esm/Metadata/Constant.d.ts.map +1 -1
  193. package/lib/esm/Metadata/Constant.js +27 -2
  194. package/lib/esm/Metadata/Constant.js.map +1 -1
  195. package/lib/esm/Metadata/CustomAttribute.js.map +1 -1
  196. package/lib/esm/Metadata/CustomAttributeClass.d.ts +16 -4
  197. package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -1
  198. package/lib/esm/Metadata/CustomAttributeClass.js +22 -4
  199. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
  200. package/lib/esm/Metadata/EntityClass.d.ts +20 -8
  201. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
  202. package/lib/esm/Metadata/EntityClass.js +42 -22
  203. package/lib/esm/Metadata/EntityClass.js.map +1 -1
  204. package/lib/esm/Metadata/Enumeration.d.ts +14 -1
  205. package/lib/esm/Metadata/Enumeration.d.ts.map +1 -1
  206. package/lib/esm/Metadata/Enumeration.js +22 -1
  207. package/lib/esm/Metadata/Enumeration.js.map +1 -1
  208. package/lib/esm/Metadata/Format.d.ts +41 -1
  209. package/lib/esm/Metadata/Format.d.ts.map +1 -1
  210. package/lib/esm/Metadata/Format.js +68 -3
  211. package/lib/esm/Metadata/Format.js.map +1 -1
  212. package/lib/esm/Metadata/InvertedUnit.d.ts +8 -3
  213. package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -1
  214. package/lib/esm/Metadata/InvertedUnit.js +17 -6
  215. package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
  216. package/lib/esm/Metadata/KindOfQuantity.d.ts +14 -3
  217. package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -1
  218. package/lib/esm/Metadata/KindOfQuantity.js +43 -18
  219. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
  220. package/lib/esm/Metadata/Mixin.d.ts +15 -1
  221. package/lib/esm/Metadata/Mixin.d.ts.map +1 -1
  222. package/lib/esm/Metadata/Mixin.js +24 -3
  223. package/lib/esm/Metadata/Mixin.js.map +1 -1
  224. package/lib/esm/Metadata/OverrideFormat.js +9 -0
  225. package/lib/esm/Metadata/OverrideFormat.js.map +1 -1
  226. package/lib/esm/Metadata/Phenomenon.d.ts +14 -1
  227. package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -1
  228. package/lib/esm/Metadata/Phenomenon.js +22 -1
  229. package/lib/esm/Metadata/Phenomenon.js.map +1 -1
  230. package/lib/esm/Metadata/Property.d.ts +5 -1
  231. package/lib/esm/Metadata/Property.d.ts.map +1 -1
  232. package/lib/esm/Metadata/Property.js +84 -29
  233. package/lib/esm/Metadata/Property.js.map +1 -1
  234. package/lib/esm/Metadata/PropertyCategory.d.ts +14 -1
  235. package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -1
  236. package/lib/esm/Metadata/PropertyCategory.js +21 -1
  237. package/lib/esm/Metadata/PropertyCategory.js.map +1 -1
  238. package/lib/esm/Metadata/RelationshipClass.d.ts +15 -2
  239. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
  240. package/lib/esm/Metadata/RelationshipClass.js +48 -11
  241. package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
  242. package/lib/esm/Metadata/Schema.d.ts +116 -11
  243. package/lib/esm/Metadata/Schema.d.ts.map +1 -1
  244. package/lib/esm/Metadata/Schema.js +135 -33
  245. package/lib/esm/Metadata/Schema.js.map +1 -1
  246. package/lib/esm/Metadata/SchemaItem.d.ts +11 -2
  247. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
  248. package/lib/esm/Metadata/SchemaItem.js +11 -1
  249. package/lib/esm/Metadata/SchemaItem.js.map +1 -1
  250. package/lib/esm/Metadata/Unit.d.ts +8 -1
  251. package/lib/esm/Metadata/Unit.d.ts.map +1 -1
  252. package/lib/esm/Metadata/Unit.js +21 -3
  253. package/lib/esm/Metadata/Unit.js.map +1 -1
  254. package/lib/esm/Metadata/UnitSystem.d.ts +14 -3
  255. package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -1
  256. package/lib/esm/Metadata/UnitSystem.js +21 -3
  257. package/lib/esm/Metadata/UnitSystem.js.map +1 -1
  258. package/lib/esm/PropertyTypes.js.map +1 -1
  259. package/lib/esm/SchemaJsonLocater.d.ts +3 -3
  260. package/lib/esm/SchemaJsonLocater.d.ts.map +1 -1
  261. package/lib/esm/SchemaJsonLocater.js +3 -3
  262. package/lib/esm/SchemaJsonLocater.js.map +1 -1
  263. package/lib/esm/SchemaKey.d.ts +7 -1
  264. package/lib/esm/SchemaKey.d.ts.map +1 -1
  265. package/lib/esm/SchemaKey.js +13 -3
  266. package/lib/esm/SchemaKey.js.map +1 -1
  267. package/lib/esm/SchemaLoader.d.ts +2 -2
  268. package/lib/esm/SchemaLoader.d.ts.map +1 -1
  269. package/lib/esm/SchemaLoader.js +1 -0
  270. package/lib/esm/SchemaLoader.js.map +1 -1
  271. package/lib/esm/SchemaPartVisitorDelegate.js +1 -0
  272. package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -1
  273. package/lib/esm/UnitConversion/Graph.js +69 -65
  274. package/lib/esm/UnitConversion/Graph.js.map +1 -1
  275. package/lib/esm/UnitConversion/Parser.js.map +1 -1
  276. package/lib/esm/UnitConversion/UnitConversion.d.ts +1 -1
  277. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -1
  278. package/lib/esm/UnitConversion/UnitConversion.js +9 -7
  279. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -1
  280. package/lib/esm/UnitConversion/UnitConverter.js +2 -0
  281. package/lib/esm/UnitConversion/UnitConverter.js.map +1 -1
  282. package/lib/esm/UnitConversion/UnitTree.d.ts +2 -0
  283. package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -1
  284. package/lib/esm/UnitConversion/UnitTree.js +11 -1
  285. package/lib/esm/UnitConversion/UnitTree.js.map +1 -1
  286. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -1
  287. package/lib/esm/UnitProvider/SchemaUnitProvider.js +8 -9
  288. package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -1
  289. package/lib/esm/Validation/SchemaWalker.d.ts +1 -1
  290. package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -1
  291. package/lib/esm/Validation/SchemaWalker.js +6 -4
  292. package/lib/esm/Validation/SchemaWalker.js.map +1 -1
  293. package/lib/esm/ecschema-metadata.d.ts +1 -1
  294. package/lib/esm/ecschema-metadata.d.ts.map +1 -1
  295. package/lib/esm/ecschema-metadata.js.map +1 -1
  296. package/lib/esm/utils/SchemaGraph.js +2 -3
  297. package/lib/esm/utils/SchemaGraph.js.map +1 -1
  298. package/package.json +14 -14
@@ -19,7 +19,8 @@ export type AnyEnumerator = Enumerator<string | number>;
19
19
  * @beta
20
20
  */
21
21
  export declare class Enumeration extends SchemaItem {
22
- readonly schemaItemType: SchemaItemType.Enumeration;
22
+ readonly schemaItemType: SchemaItemType;
23
+ static get schemaItemType(): SchemaItemType;
23
24
  protected _type?: PrimitiveType.Integer | PrimitiveType.String;
24
25
  protected _isStrict: boolean;
25
26
  protected _enumerators: AnyEnumerator[];
@@ -75,6 +76,18 @@ export declare class Enumeration extends SchemaItem {
75
76
  * @alpha Used in schema editing.
76
77
  */
77
78
  protected setIsStrict(isStrict: boolean): void;
79
+ /**
80
+ * Type guard to check if the SchemaItem is of type Enumeration.
81
+ * @param item The SchemaItem to check.
82
+ * @returns True if the item is an Enumeration, false otherwise.
83
+ */
84
+ static isEnumeration(item?: SchemaItem): item is Enumeration;
85
+ /**
86
+ * Type assertion to check if the SchemaItem is of type Enumeration.
87
+ * @param item The SchemaItem to check.
88
+ * @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.
89
+ */
90
+ static assertIsEnumeration(item?: SchemaItem): asserts item is Enumeration;
78
91
  }
79
92
  /** @internal
80
93
  * An abstract class used for schema editing.
@@ -1 +1 @@
1
- {"version":3,"file":"Enumeration.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,gBAAgB,EAAmB,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,aAAa,EAAyB,cAAc,EAAE,MAA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IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,aAAa;IAIjD;;;;OAIG;IACa,MAAM,CAAC,UAAU,GAAE,OAAe,EAAE,oBAAoB,GAAE,OAAe,GAAG,gBAAgB;IAe5G,gBAAgB;IACM,KAAK,CAAC,SAAS,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBlD,YAAY,CAAC,gBAAgB,EAAE,gBAAgB;IA6BzC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IAIjE;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO;IAIvC;;;;OAIG;WACW,aAAa,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,IAAI,WAAW;IAInE;;;;OAIG;WACW,mBAAmB,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,IAAI,WAAW;CAIlF;AAED;;GAEG;AACH,8BAAsB,kBAAmB,SAAQ,WAAW;aACjC,aAAa,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI;aAC9C,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI;aACpC,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
@@ -15,12 +15,16 @@ import { SchemaItem } from "./SchemaItem";
15
15
  * @beta
16
16
  */
17
17
  export class Enumeration extends SchemaItem {
18
+ schemaItemType = Enumeration.schemaItemType;
19
+ static get schemaItemType() { return SchemaItemType.Enumeration; }
20
+ _type;
21
+ _isStrict;
22
+ _enumerators;
18
23
  get enumerators() { return this._enumerators; }
19
24
  get type() { return this._type; }
20
25
  get isStrict() { return this._isStrict; }
21
26
  constructor(schema, name, primitiveType) {
22
27
  super(schema, name);
23
- this.schemaItemType = SchemaItemType.Enumeration;
24
28
  this._type = primitiveType;
25
29
  this._isStrict = true;
26
30
  this._enumerators = [];
@@ -153,6 +157,23 @@ export class Enumeration extends SchemaItem {
153
157
  setIsStrict(isStrict) {
154
158
  this._isStrict = isStrict;
155
159
  }
160
+ /**
161
+ * Type guard to check if the SchemaItem is of type Enumeration.
162
+ * @param item The SchemaItem to check.
163
+ * @returns True if the item is an Enumeration, false otherwise.
164
+ */
165
+ static isEnumeration(item) {
166
+ return item?.schemaItemType === SchemaItemType.Enumeration;
167
+ }
168
+ /**
169
+ * Type assertion to check if the SchemaItem is of type Enumeration.
170
+ * @param item The SchemaItem to check.
171
+ * @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.
172
+ */
173
+ static assertIsEnumeration(item) {
174
+ if (!this.isEnumeration(item))
175
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);
176
+ }
156
177
  }
157
178
  /** @internal
158
179
  * An abstract class used for schema editing.
@@ -1 +1 @@
1
- {"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAiB,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE5E,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAa1C;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,UAAU;IAMzC,IAAW,WAAW,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IACtD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACxC,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhD,YAAY,MAAc,EAAE,IAAY,EAAE,aAA4D;QACpG,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC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AAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACnD,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,aAAa,EAAE,mBAAmB,IAAI,CAAC,IAAI,0CAA0C,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;QACjN,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAC,QAAQ,CAAC;QAE3C,IAAI,SAAS,KAAK,gBAAgB,CAAC,WAAW,EAAE,CAAC;YAC/C,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAA2B,EAAE,EAAE;gBACnE,4JAA4J;gBAC5J,0FAA0F;gBAC1F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,gBAAkC;QAC/D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,WAAW,CAAC,QAAiB;QACrC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;CAEF;AAED;;GAEG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;CAI3D","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 { ECSpecVersion, SchemaReadHelper } from \"../Deserialization/Helper\";\r\nimport { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\r\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { ECName } from \"../ECName\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\n\r\n/** @beta */\r\nexport interface Enumerator<T> {\r\n readonly name: string;\r\n readonly value: T;\r\n readonly label?: string;\r\n readonly description?: string;\r\n}\r\n\r\n/** @beta */\r\nexport type AnyEnumerator = Enumerator<string | number>;\r\n\r\n/**\r\n * A Typescript class representation of an ECEnumeration.\r\n * @beta\r\n */\r\nexport class Enumeration extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Enumeration;\r\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\r\n protected _isStrict: boolean;\r\n protected _enumerators: AnyEnumerator[];\r\n\r\n public get enumerators() { return this._enumerators; }\r\n public get type() { return this._type; }\r\n public get isStrict() { return this._isStrict; }\r\n\r\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Enumeration;\r\n this._type = primitiveType;\r\n this._isStrict = true;\r\n this._enumerators = [];\r\n }\r\n\r\n public get isInt(): boolean { return this._type === PrimitiveType.Integer; }\r\n public get isString(): boolean { return this._type === PrimitiveType.String; }\r\n\r\n /**\r\n * Gets an enumerator that matches the name provided.\r\n * @param name The ECName of the Enumerator to find.\r\n */\r\n public getEnumeratorByName(name: string): AnyEnumerator | undefined {\r\n return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());\r\n }\r\n\r\n /**\r\n * Gets an enumerator that matches the value provided.\r\n * @param value The value of the Enumerator to find.\r\n */\r\n public getEnumerator(value: string): Enumerator<string> | undefined;\r\n public getEnumerator(value: number): Enumerator<number> | undefined;\r\n public getEnumerator(value: string | number): AnyEnumerator | undefined {\r\n return this.enumerators.find((item) => item.value === value);\r\n }\r\n\r\n /**\r\n * Checks whether there already exists an enumerator with this name or this value\r\n * @param name The name of the enumerator we are trying to create\r\n * @param value The value of the enumerator we are trying to create\r\n * @internal\r\n */\r\n private findDuplicateEnumerators(name: string, value: string | number) {\r\n this._enumerators.forEach((element: AnyEnumerator) => { // Name and value must be unique within the ECEnumerations\r\n if (element.name.toLowerCase() === name.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\r\n if (element.value === value)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);\r\n });\r\n }\r\n\r\n /**\r\n * Creates an Enumerator with the provided name and value as well as optional parameters label and description\r\n * @param name The name of the enumerator\r\n * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.\r\n * @param label A localized display label that is used instead of the name in a GUI.\r\n * @param description A localized description for the enumerator.\r\n * @return AnyEnumerator object\r\n */\r\n public createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator {\r\n if (this.isInt && typeof (value) === \"string\") // throws if backing type is int and value is string\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);\r\n if (!this.isInt && typeof (value) === \"number\") // also throws if backing type is string and value is number\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);\r\n this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any\r\n if (!ECName.validate(name))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);\r\n return { name, value, label, description };\r\n }\r\n\r\n /**\r\n * Adds enumerator to list of enumerators on this Enumeration\r\n * @param enumerator The enumerator to add\r\n */\r\n protected addEnumerator(enumerator: AnyEnumerator) {\r\n this.enumerators.push(enumerator);\r\n }\r\n\r\n /**\r\n * Save this Enumeration's 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): EnumerationProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.type = (this.isInt) ? \"int\" : \"string\";\r\n schemaJson.isStrict = this.isStrict;\r\n schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {\r\n const enumJson: any = { name, value };\r\n if (undefined !== label)\r\n enumJson.label = label;\r\n if (undefined !== description)\r\n enumJson.description = description;\r\n return enumJson;\r\n });\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 if (undefined !== this.type)\r\n itemElement.setAttribute(\"backingTypeName\", primitiveTypeToString(this.type));\r\n itemElement.setAttribute(\"isStrict\", String(this.isStrict));\r\n\r\n for (const enumerator of this.enumerators) {\r\n const enumElement = schemaXml.createElement(\"ECEnumerator\");\r\n enumElement.setAttribute(\"name\", enumerator.name);\r\n const enumValue = typeof enumerator.value === \"string\" ? enumerator.value : enumerator.value.toString();\r\n enumElement.setAttribute(\"value\", enumValue);\r\n if (undefined !== enumerator.label)\r\n enumElement.setAttribute(\"displayLabel\", enumerator.label);\r\n if (undefined !== enumerator.description)\r\n enumElement.setAttribute(\"description\", enumerator.description);\r\n itemElement.appendChild(enumElement);\r\n }\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(enumerationProps: EnumerationProps) {\r\n super.fromJSONSync(enumerationProps);\r\n if (undefined === this._type) {\r\n if (/int/i.test(enumerationProps.type)) {\r\n this._type = PrimitiveType.Integer;\r\n } else if (/string/i.test(enumerationProps.type)) {\r\n this._type = PrimitiveType.String;\r\n } else {\r\n if (SchemaReadHelper.isECSpecVersionNewer({readVersion: enumerationProps.originalECSpecMajorVersion, writeVersion: enumerationProps.originalECSpecMinorVersion} as ECSpecVersion))\r\n this._type = PrimitiveType.String;\r\n else\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\r\n }\r\n } else {\r\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\r\n if (!primitiveTypePattern.test(enumerationProps.type))\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be \"${(this.isInt) ? \"int\" : \"string\"}\", not \"${(this.isInt) ? \"string\" : \"int\"}\".`);\r\n }\r\n this._isStrict = enumerationProps.isStrict;\r\n\r\n if (undefined !== enumerationProps.enumerators) {\r\n enumerationProps.enumerators.forEach((enumerator: EnumeratorProps) => {\r\n // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.\r\n // Throws ECObjectsError if there are duplicate names or values present in the enumeration\r\n this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));\r\n });\r\n }\r\n }\r\n\r\n public override async fromJSON(enumerationProps: EnumerationProps) {\r\n this.fromJSONSync(enumerationProps);\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setIsStrict(isStrict: boolean) {\r\n this._isStrict = isStrict;\r\n }\r\n\r\n}\r\n\r\n/** @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableEnumeration extends Enumeration {\r\n public abstract override addEnumerator(enumerator: AnyEnumerator): void;\r\n public abstract override setIsStrict(isStrict: boolean): void;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"Enumeration.js","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAiB,g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AAE;gBACnE,4JAA4J;gBAC5J,0FAA0F;gBAC1F,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;YACzH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,gBAAkC;QAC/D,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,WAAW,CAAC,QAAiB;QACrC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,IAAiB;QAC3C,OAAO,IAAI,EAAE,cAAc,KAAK,cAAc,CAAC,WAAW,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAiB;QACjD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YAC3B,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,qBAAqB,EAAE,aAAa,cAAc,CAAC,WAAW,iBAAiB,CAAC,CAAC;IAC9H,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAgB,kBAAmB,SAAQ,WAAW;CAI3D","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 { ECSpecVersion, SchemaReadHelper } from \"../Deserialization/Helper\";\nimport { EnumerationProps, EnumeratorProps } from \"../Deserialization/JsonProps\";\nimport { PrimitiveType, primitiveTypeToString, SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { ECName } from \"../ECName\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\n\n/** @beta */\nexport interface Enumerator<T> {\n readonly name: string;\n readonly value: T;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** @beta */\nexport type AnyEnumerator = Enumerator<string | number>;\n\n/**\n * A Typescript class representation of an ECEnumeration.\n * @beta\n */\nexport class Enumeration extends SchemaItem {\n public override readonly schemaItemType = Enumeration.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.Enumeration; }\n protected _type?: PrimitiveType.Integer | PrimitiveType.String;\n protected _isStrict: boolean;\n protected _enumerators: AnyEnumerator[];\n\n public get enumerators() { return this._enumerators; }\n public get type() { return this._type; }\n public get isStrict() { return this._isStrict; }\n\n constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String) {\n super(schema, name);\n this._type = primitiveType;\n this._isStrict = true;\n this._enumerators = [];\n }\n\n public get isInt(): boolean { return this._type === PrimitiveType.Integer; }\n public get isString(): boolean { return this._type === PrimitiveType.String; }\n\n /**\n * Gets an enumerator that matches the name provided.\n * @param name The ECName of the Enumerator to find.\n */\n public getEnumeratorByName(name: string): AnyEnumerator | undefined {\n return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());\n }\n\n /**\n * Gets an enumerator that matches the value provided.\n * @param value The value of the Enumerator to find.\n */\n public getEnumerator(value: string): Enumerator<string> | undefined;\n public getEnumerator(value: number): Enumerator<number> | undefined;\n public getEnumerator(value: string | number): AnyEnumerator | undefined {\n return this.enumerators.find((item) => item.value === value);\n }\n\n /**\n * Checks whether there already exists an enumerator with this name or this value\n * @param name The name of the enumerator we are trying to create\n * @param value The value of the enumerator we are trying to create\n * @internal\n */\n private findDuplicateEnumerators(name: string, value: string | number) {\n this._enumerators.forEach((element: AnyEnumerator) => { // Name and value must be unique within the ECEnumerations\n if (element.name.toLowerCase() === name.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\n if (element.value === value)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);\n });\n }\n\n /**\n * Creates an Enumerator with the provided name and value as well as optional parameters label and description\n * @param name The name of the enumerator\n * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.\n * @param label A localized display label that is used instead of the name in a GUI.\n * @param description A localized description for the enumerator.\n * @return AnyEnumerator object\n */\n public createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator {\n if (this.isInt && typeof (value) === \"string\") // throws if backing type is int and value is string\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);\n if (!this.isInt && typeof (value) === \"number\") // also throws if backing type is string and value is number\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);\n this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any\n if (!ECName.validate(name))\n throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);\n return { name, value, label, description };\n }\n\n /**\n * Adds enumerator to list of enumerators on this Enumeration\n * @param enumerator The enumerator to add\n */\n protected addEnumerator(enumerator: AnyEnumerator) {\n this.enumerators.push(enumerator);\n }\n\n /**\n * Save this Enumeration's 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): EnumerationProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.type = (this.isInt) ? \"int\" : \"string\";\n schemaJson.isStrict = this.isStrict;\n schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {\n const enumJson: any = { name, value };\n if (undefined !== label)\n enumJson.label = label;\n if (undefined !== description)\n enumJson.description = description;\n return enumJson;\n });\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n if (undefined !== this.type)\n itemElement.setAttribute(\"backingTypeName\", primitiveTypeToString(this.type));\n itemElement.setAttribute(\"isStrict\", String(this.isStrict));\n\n for (const enumerator of this.enumerators) {\n const enumElement = schemaXml.createElement(\"ECEnumerator\");\n enumElement.setAttribute(\"name\", enumerator.name);\n const enumValue = typeof enumerator.value === \"string\" ? enumerator.value : enumerator.value.toString();\n enumElement.setAttribute(\"value\", enumValue);\n if (undefined !== enumerator.label)\n enumElement.setAttribute(\"displayLabel\", enumerator.label);\n if (undefined !== enumerator.description)\n enumElement.setAttribute(\"description\", enumerator.description);\n itemElement.appendChild(enumElement);\n }\n\n return itemElement;\n }\n\n public override fromJSONSync(enumerationProps: EnumerationProps) {\n super.fromJSONSync(enumerationProps);\n if (undefined === this._type) {\n if (/int/i.test(enumerationProps.type)) {\n this._type = PrimitiveType.Integer;\n } else if (/string/i.test(enumerationProps.type)) {\n this._type = PrimitiveType.String;\n } else {\n if (SchemaReadHelper.isECSpecVersionNewer({readVersion: enumerationProps.originalECSpecMajorVersion, writeVersion: enumerationProps.originalECSpecMinorVersion} as ECSpecVersion))\n this._type = PrimitiveType.String;\n else\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\n }\n } else {\n const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;\n if (!primitiveTypePattern.test(enumerationProps.type))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be \"${(this.isInt) ? \"int\" : \"string\"}\", not \"${(this.isInt) ? \"string\" : \"int\"}\".`);\n }\n this._isStrict = enumerationProps.isStrict;\n\n if (undefined !== enumerationProps.enumerators) {\n enumerationProps.enumerators.forEach((enumerator: EnumeratorProps) => {\n // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.\n // Throws ECObjectsError if there are duplicate names or values present in the enumeration\n this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));\n });\n }\n }\n\n public override async fromJSON(enumerationProps: EnumerationProps) {\n this.fromJSONSync(enumerationProps);\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setIsStrict(isStrict: boolean) {\n this._isStrict = isStrict;\n }\n\n /**\n * Type guard to check if the SchemaItem is of type Enumeration.\n * @param item The SchemaItem to check.\n * @returns True if the item is an Enumeration, false otherwise.\n */\n public static isEnumeration(item?: SchemaItem): item is Enumeration {\n return item?.schemaItemType === SchemaItemType.Enumeration;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type Enumeration.\n * @param item The SchemaItem to check.\n * @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.\n */\n public static assertIsEnumeration(item?: SchemaItem): asserts item is Enumeration {\n if (!this.isEnumeration(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);\n }\n}\n\n/** @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableEnumeration extends Enumeration {\n public abstract override addEnumerator(enumerator: AnyEnumerator): void;\n public abstract override setIsStrict(isStrict: boolean): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
@@ -12,7 +12,8 @@ import { Unit } from "./Unit";
12
12
  * @beta
13
13
  */
14
14
  export declare class Format extends SchemaItem {
15
- readonly schemaItemType: SchemaItemType.Format;
15
+ readonly schemaItemType: SchemaItemType;
16
+ static get schemaItemType(): SchemaItemType;
16
17
  protected _base: BaseFormat;
17
18
  protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;
18
19
  constructor(schema: Schema, name: string);
@@ -79,6 +80,45 @@ export declare class Format extends SchemaItem {
79
80
  * @alpha Used in schema editing.
80
81
  */
81
82
  protected setStationSeparator(separator: string): void;
83
+ /**
84
+ * @alpha Used in schema editing.
85
+ */
86
+ protected setStationOffsetSize(stationOffsetSize: number): void;
87
+ /**
88
+ * @alpha Used in schema editing.
89
+ */
90
+ protected setScientificType(scientificType: ScientificType): void;
91
+ /**
92
+ * @alpha Used in schema editing.
93
+ */
94
+ protected setMinWidth(minWidth: number): void;
95
+ /**
96
+ * @alpha Used in schema editing.
97
+ */
98
+ protected setSpacer(spacer: string): void;
99
+ /**
100
+ * @alpha Used in schema editing.
101
+ */
102
+ protected setIncludeZero(includeZero: boolean): void;
103
+ /**
104
+ * @alpha Used in schema editing.
105
+ */
106
+ protected setFormatTraits(formatTraits: FormatTraits): void;
107
+ /**
108
+ * @alpha Used in schema editing.
109
+ */
110
+ protected setUnits(units: Array<[Unit | InvertedUnit, string | undefined]>): void;
111
+ /** Type guard to check if the SchemaItem is of type Format.
112
+ * @param item The SchemaItem to check.
113
+ * @returns True if the item is a Format, false otherwise.
114
+ */
115
+ static isFormat(item?: SchemaItem): item is Format;
116
+ /**
117
+ * Type assertion to check if the SchemaItem is of type Format.
118
+ * @param item The SchemaItem to check.
119
+ * @returns The item cast to Format if it is a Format, undefined otherwise.
120
+ */
121
+ static assertIsFormat(item?: SchemaItem): asserts item is Format;
82
122
  }
83
123
  /**
84
124
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"Format.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EACL,UAAU,EAAE,gBAAgB,EAAE,YAAY,EAAuB,UAAU,EAAE,mBAAmB,EAChG,cAAc,EAAE,cAAc,EAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAA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G,IAAI;aACnD,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aAC5C,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aAC7C,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aACxC,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;aAC5C,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;CACrE"}
@@ -9,14 +9,19 @@ import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils"
9
9
  import { SchemaItemType } from "../ECObjects";
10
10
  import { ECObjectsError, ECObjectsStatus } from "../Exception";
11
11
  import { BaseFormat, FormatTraits, formatTraitsToArray, FormatType, ShowSignOption, } from "@itwin/core-quantity";
12
+ import { InvertedUnit } from "./InvertedUnit";
12
13
  import { SchemaItem } from "./SchemaItem";
14
+ import { Unit } from "./Unit";
13
15
  /**
14
16
  * @beta
15
17
  */
16
18
  export class Format extends SchemaItem {
19
+ schemaItemType = Format.schemaItemType;
20
+ static get schemaItemType() { return SchemaItemType.Format; }
21
+ _base;
22
+ _units;
17
23
  constructor(schema, name) {
18
24
  super(schema, name);
19
- this.schemaItemType = SchemaItemType.Format;
20
25
  this._base = new BaseFormat(name);
21
26
  }
22
27
  get roundFactor() { return this._base.roundFactor; }
@@ -80,7 +85,7 @@ export class Format extends SchemaItem {
80
85
  // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation
81
86
  for (const unit of formatProps.composite.units) {
82
87
  const newUnit = this.schema.lookupItemSync(unit.name);
83
- if (undefined === newUnit)
88
+ if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))
84
89
  throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
85
90
  this.addUnit(newUnit, unit.label);
86
91
  }
@@ -93,7 +98,7 @@ export class Format extends SchemaItem {
93
98
  // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation
94
99
  for (const unit of formatProps.composite.units) {
95
100
  const newUnit = await this.schema.lookupItem(unit.name);
96
- if (undefined === newUnit)
101
+ if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))
97
102
  throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
98
103
  this.addUnit(newUnit, unit.label);
99
104
  }
@@ -228,6 +233,66 @@ export class Format extends SchemaItem {
228
233
  setStationSeparator(separator) {
229
234
  this._base.stationSeparator = separator;
230
235
  }
236
+ /**
237
+ * @alpha Used in schema editing.
238
+ */
239
+ setStationOffsetSize(stationOffsetSize) {
240
+ this._base.stationOffsetSize = stationOffsetSize;
241
+ }
242
+ /**
243
+ * @alpha Used in schema editing.
244
+ */
245
+ setScientificType(scientificType) {
246
+ this._base.scientificType = scientificType;
247
+ }
248
+ /**
249
+ * @alpha Used in schema editing.
250
+ */
251
+ setMinWidth(minWidth) {
252
+ this._base.minWidth = minWidth;
253
+ }
254
+ /**
255
+ * @alpha Used in schema editing.
256
+ */
257
+ setSpacer(spacer) {
258
+ this._base.spacer = spacer;
259
+ }
260
+ /**
261
+ * @alpha Used in schema editing.
262
+ */
263
+ setIncludeZero(includeZero) {
264
+ this._base.includeZero = includeZero;
265
+ }
266
+ /**
267
+ * @alpha Used in schema editing.
268
+ */
269
+ setFormatTraits(formatTraits) {
270
+ this._base.formatTraits = formatTraits;
271
+ }
272
+ /**
273
+ * @alpha Used in schema editing.
274
+ */
275
+ setUnits(units) {
276
+ this._units = units;
277
+ }
278
+ /** Type guard to check if the SchemaItem is of type Format.
279
+ * @param item The SchemaItem to check.
280
+ * @returns True if the item is a Format, false otherwise.
281
+ */
282
+ static isFormat(item) {
283
+ if (item && item.schemaItemType === SchemaItemType.Format)
284
+ return true;
285
+ return false;
286
+ }
287
+ /**
288
+ * Type assertion to check if the SchemaItem is of type Format.
289
+ * @param item The SchemaItem to check.
290
+ * @returns The item cast to Format if it is a Format, undefined otherwise.
291
+ */
292
+ static assertIsFormat(item) {
293
+ if (!this.isFormat(item))
294
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Format}' (Format)`);
295
+ }
231
296
  }
232
297
  /**
233
298
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"Format.js","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EACL,UAAU,EAAoB,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAC3D,cAAc,GAC/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,UAAU;IAKpC,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC;QAE5C,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,IAAW,WAAW,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,IAAW,IAAI,KAAiB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACzD,IAAW,SAAS,KAA6C,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/F,IAAW,QAAQ,KAAyB,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzE,IAAW,cAAc,KAAiC,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;IAC7F,IAAW,cAAc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,GAAG,SAAS,CAAC;IAC1C,CAAC;IAED;;OAEG;IACO,oBAAoB,CAAC,SAAiB;QAC9C,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAC3C,CAAC;IAED;;OAEG;IACO,eAAe,CAAC,SAAiB;QACzC,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC;IACtC,CAAC;IAED;;OAEG;IACO,mBAAmB,CAAC,SAAiB;QAC7C,IAAI,CAAC,KAAK,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAC1C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,aAAc,SAAQ,MAAM;CAWjD","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 { SchemaItemFormatProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport {\r\n BaseFormat, DecimalPrecision, FormatTraits, formatTraitsToArray, FormatType, FractionalPrecision,\r\n ScientificType, ShowSignOption,\r\n} from \"@itwin/core-quantity\";\r\nimport { InvertedUnit } from \"./InvertedUnit\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { Unit } from \"./Unit\";\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class Format extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.Format;\r\n protected _base: BaseFormat;\r\n protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.Format;\r\n\r\n this._base = new BaseFormat(name);\r\n }\r\n\r\n public get roundFactor(): number { return this._base.roundFactor; }\r\n public get type(): FormatType { return this._base.type; }\r\n public get precision(): DecimalPrecision | FractionalPrecision { return this._base.precision; }\r\n public get minWidth(): number | undefined { return this._base.minWidth; }\r\n public get scientificType(): ScientificType | undefined { return this._base.scientificType; }\r\n public get showSignOption(): ShowSignOption { return this._base.showSignOption; }\r\n public get decimalSeparator(): string { return this._base.decimalSeparator; }\r\n public get thousandSeparator(): string { return this._base.thousandSeparator; }\r\n public get uomSeparator(): string { return this._base.uomSeparator; }\r\n public get stationSeparator(): string { return this._base.stationSeparator; }\r\n public get stationOffsetSize(): number | undefined { return this._base.stationOffsetSize; }\r\n public get formatTraits(): FormatTraits { return this._base.formatTraits; }\r\n public get spacer(): string | undefined { return this._base.spacer; }\r\n public get includeZero(): boolean | undefined { return this._base.includeZero; }\r\n public get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined { return this._units; }\r\n\r\n private parseFormatTraits(formatTraitsFromJson: string | string[]) {\r\n return this._base.parseFormatTraits(formatTraitsFromJson);\r\n }\r\n\r\n public hasFormatTrait(formatTrait: FormatTraits) {\r\n return this._base.hasFormatTraitSet(formatTrait);\r\n }\r\n\r\n /**\r\n * Adds a Unit, or InvertedUnit, with an optional label override.\r\n * @param unit The Unit, or InvertedUnit, to add to this Format.\r\n * @param label A label that overrides the label defined within the Unit when a value is formatted.\r\n */\r\n protected addUnit(unit: Unit | InvertedUnit, label?: string) {\r\n if (undefined === this._units)\r\n this._units = [];\r\n else { // Validate that a duplicate is not added.\r\n for (const existingUnit of this._units) {\r\n if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.\r\n }\r\n }\r\n\r\n this._units.push([unit, label]);\r\n }\r\n\r\n protected setPrecision(precision: number) { this._base.precision = precision; }\r\n\r\n private typecheck(formatProps: SchemaItemFormatProps) {\r\n this._base.loadFormatProperties(formatProps);\r\n\r\n if (undefined !== formatProps.composite) { // TODO: This is duplicated below when the units need to be processed...\r\n if (undefined !== formatProps.composite.includeZero)\r\n this._base.includeZero = formatProps.composite.includeZero;\r\n\r\n if (undefined !== formatProps.composite.spacer) {\r\n if (formatProps.composite.spacer.length > 1)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);\r\n this._base.spacer = formatProps.composite.spacer;\r\n }\r\n\r\n // Composite requires 1-4 units\r\n if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);\r\n }\r\n }\r\n\r\n public override fromJSONSync(formatProps: SchemaItemFormatProps) {\r\n super.fromJSONSync(formatProps);\r\n this.typecheck(formatProps);\r\n if (undefined === formatProps.composite)\r\n return;\r\n\r\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\r\n for (const unit of formatProps.composite.units) {\r\n const newUnit = this.schema.lookupItemSync<Unit | InvertedUnit>(unit.name);\r\n if (undefined === newUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n this.addUnit(newUnit, unit.label);\r\n }\r\n }\r\n\r\n public override async fromJSON(formatProps: SchemaItemFormatProps) {\r\n await super.fromJSON(formatProps);\r\n this.typecheck(formatProps);\r\n if (undefined === formatProps.composite)\r\n return;\r\n\r\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\r\n for (const unit of formatProps.composite.units) {\r\n const newUnit = await this.schema.lookupItem<Unit | InvertedUnit>(unit.name);\r\n if (undefined === newUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\r\n this.addUnit(newUnit, unit.label);\r\n }\r\n }\r\n\r\n /**\r\n * Save this Format's 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): SchemaItemFormatProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.type = this.type;\r\n schemaJson.precision = this.precision;\r\n\r\n // this._spacer = \" \";\r\n // this._includeZero = true;\r\n\r\n // Serialize the minimal amount of information needed so anything that is the same as the default, do not serialize.\r\n if (0.0 !== this.roundFactor)\r\n schemaJson.roundFactor = this.roundFactor;\r\n if (ShowSignOption.OnlyNegative !== this.showSignOption)\r\n schemaJson.showSignOption = this.showSignOption;\r\n if (FormatTraits.Uninitialized !== this.formatTraits)\r\n schemaJson.formatTraits = formatTraitsToArray(this.formatTraits);\r\n if (\".\" !== this.decimalSeparator)\r\n schemaJson.decimalSeparator = this.decimalSeparator;\r\n if (\",\" !== this.thousandSeparator)\r\n schemaJson.thousandSeparator = this.thousandSeparator;\r\n if (\" \" !== this.uomSeparator)\r\n schemaJson.uomSeparator = this.uomSeparator;\r\n\r\n if (undefined !== this.minWidth)\r\n schemaJson.minWidth = this.minWidth;\r\n\r\n if (FormatType.Scientific === this.type && undefined !== this.scientificType)\r\n schemaJson.scientificType = this.scientificType;\r\n\r\n if (FormatType.Station === this.type) {\r\n if (undefined !== this.stationOffsetSize)\r\n schemaJson.stationOffsetSize = this.stationOffsetSize;\r\n if (\" \" !== this.stationSeparator)\r\n schemaJson.stationSeparator = this.stationSeparator;\r\n }\r\n\r\n if (undefined === this.units)\r\n return schemaJson;\r\n\r\n schemaJson.composite = {};\r\n\r\n if (\" \" !== this.spacer)\r\n schemaJson.composite.spacer = this.spacer;\r\n\r\n if (true !== this.includeZero)\r\n schemaJson.composite.includeZero = this.includeZero;\r\n\r\n schemaJson.composite.units = [];\r\n for (const unit of this.units) {\r\n schemaJson.composite.units.push({\r\n name: unit[0].fullName,\r\n label: unit[1],\r\n });\r\n }\r\n\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 itemElement.setAttribute(\"type\", this.type.toLowerCase());\r\n itemElement.setAttribute(\"precision\", this.precision.toString());\r\n itemElement.setAttribute(\"roundFactor\", this.roundFactor.toString());\r\n itemElement.setAttribute(\"showSignOption\", this.showSignOption);\r\n itemElement.setAttribute(\"decimalSeparator\", this.decimalSeparator);\r\n itemElement.setAttribute(\"thousandSeparator\", this.thousandSeparator);\r\n itemElement.setAttribute(\"uomSeparator\", this.uomSeparator);\r\n itemElement.setAttribute(\"stationSeparator\", this.stationSeparator);\r\n\r\n if (undefined !== this.minWidth)\r\n itemElement.setAttribute(\"minWidth\", this.minWidth.toString());\r\n if (undefined !== this.scientificType)\r\n itemElement.setAttribute(\"scientificType\", this.scientificType);\r\n if (undefined !== this.stationOffsetSize)\r\n itemElement.setAttribute(\"stationOffsetSize\", this.stationOffsetSize.toString());\r\n\r\n const formatTraits = formatTraitsToArray(this.formatTraits);\r\n if (formatTraits.length > 0)\r\n itemElement.setAttribute(\"formatTraits\", formatTraits.join(\"|\"));\r\n\r\n if (undefined !== this.units) {\r\n const compositeElement = schemaXml.createElement(\"Composite\");\r\n if (undefined !== this.spacer)\r\n compositeElement.setAttribute(\"spacer\", this.spacer);\r\n if (undefined !== this.includeZero)\r\n compositeElement.setAttribute(\"includeZero\", this.includeZero.toString());\r\n\r\n this.units.forEach(([unit, label]) => {\r\n const unitElement = schemaXml.createElement(\"Unit\");\r\n if (undefined !== label)\r\n unitElement.setAttribute(\"label\", label);\r\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);\r\n unitElement.textContent = unitName;\r\n compositeElement.appendChild(unitElement);\r\n });\r\n\r\n itemElement.appendChild(compositeElement);\r\n }\r\n\r\n return itemElement;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setFormatType(formatType: FormatType) {\r\n this._base.type = formatType;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setRoundFactor(roundFactor: number) {\r\n this._base.roundFactor = roundFactor;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setShowSignOption(signOption: ShowSignOption) {\r\n this._base.showSignOption = signOption;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setDecimalSeparator(separator: string) {\r\n this._base.decimalSeparator = separator;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setThousandSeparator(separator: string) {\r\n this._base.thousandSeparator = separator;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setUomSeparator(separator: string) {\r\n this._base.uomSeparator = separator;\r\n }\r\n\r\n /**\r\n * @alpha Used in schema editing.\r\n */\r\n protected setStationSeparator(separator: string) {\r\n this._base.stationSeparator = separator;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableFormat extends Format {\r\n public abstract override addUnit(unit: Unit | InvertedUnit, label?: string): void;\r\n public abstract override setPrecision(precision: number): void;\r\n public abstract override setFormatType(formatType: FormatType): void;\r\n public abstract override setRoundFactor(roundFactor: number): void;\r\n public abstract override setShowSignOption(signOption: ShowSignOption): void;\r\n public abstract override setDecimalSeparator(separator: string): void;\r\n public abstract override setThousandSeparator(separator: string): void;\r\n public abstract override setUomSeparator(separator: string): void;\r\n public abstract override setStationSeparator(separator: string): void;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"Format.js","sourceRoot":"","sources":["../../../src/Metadata/Format.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe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vD,OAAO,IAAI,CAAC;QAEd,OAAO,KAAK,CAAC;IACb,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,IAAiB;QAC5C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YACtB,MAAM,IAAI,cAAc,CAAC,eAAe,CAAC,qBAAqB,EAAE,aAAa,cAAc,CAAC,MAAM,YAAY,CAAC,CAAC;IACpH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,aAAc,SAAQ,MAAM;CAWjD","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 { SchemaItemFormatProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport {\n BaseFormat, DecimalPrecision, FormatTraits, formatTraitsToArray, FormatType, FractionalPrecision,\n ScientificType, ShowSignOption,\n} from \"@itwin/core-quantity\";\nimport { InvertedUnit } from \"./InvertedUnit\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\n\n/**\n * @beta\n */\nexport class Format extends SchemaItem {\n public override readonly schemaItemType = Format.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.Format; }\n protected _base: BaseFormat;\n protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;\n\n constructor(schema: Schema, name: string) {\n super(schema, name);\n this._base = new BaseFormat(name);\n }\n\n public get roundFactor(): number { return this._base.roundFactor; }\n public get type(): FormatType { return this._base.type; }\n public get precision(): DecimalPrecision | FractionalPrecision { return this._base.precision; }\n public get minWidth(): number | undefined { return this._base.minWidth; }\n public get scientificType(): ScientificType | undefined { return this._base.scientificType; }\n public get showSignOption(): ShowSignOption { return this._base.showSignOption; }\n public get decimalSeparator(): string { return this._base.decimalSeparator; }\n public get thousandSeparator(): string { return this._base.thousandSeparator; }\n public get uomSeparator(): string { return this._base.uomSeparator; }\n public get stationSeparator(): string { return this._base.stationSeparator; }\n public get stationOffsetSize(): number | undefined { return this._base.stationOffsetSize; }\n public get formatTraits(): FormatTraits { return this._base.formatTraits; }\n public get spacer(): string | undefined { return this._base.spacer; }\n public get includeZero(): boolean | undefined { return this._base.includeZero; }\n public get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined { return this._units; }\n\n private parseFormatTraits(formatTraitsFromJson: string | string[]) {\n return this._base.parseFormatTraits(formatTraitsFromJson);\n }\n\n public hasFormatTrait(formatTrait: FormatTraits) {\n return this._base.hasFormatTraitSet(formatTrait);\n }\n\n /**\n * Adds a Unit, or InvertedUnit, with an optional label override.\n * @param unit The Unit, or InvertedUnit, to add to this Format.\n * @param label A label that overrides the label defined within the Unit when a value is formatted.\n */\n protected addUnit(unit: Unit | InvertedUnit, label?: string) {\n if (undefined === this._units)\n this._units = [];\n else { // Validate that a duplicate is not added.\n for (const existingUnit of this._units) {\n if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.\n }\n }\n\n this._units.push([unit, label]);\n }\n\n protected setPrecision(precision: number) { this._base.precision = precision; }\n\n private typecheck(formatProps: SchemaItemFormatProps) {\n this._base.loadFormatProperties(formatProps);\n\n if (undefined !== formatProps.composite) { // TODO: This is duplicated below when the units need to be processed...\n if (undefined !== formatProps.composite.includeZero)\n this._base.includeZero = formatProps.composite.includeZero;\n\n if (undefined !== formatProps.composite.spacer) {\n if (formatProps.composite.spacer.length > 1)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);\n this._base.spacer = formatProps.composite.spacer;\n }\n\n // Composite requires 1-4 units\n if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);\n }\n }\n\n public override fromJSONSync(formatProps: SchemaItemFormatProps) {\n super.fromJSONSync(formatProps);\n this.typecheck(formatProps);\n if (undefined === formatProps.composite)\n return;\n\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\n for (const unit of formatProps.composite.units) {\n const newUnit = this.schema.lookupItemSync(unit.name);\n if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n this.addUnit(newUnit, unit.label);\n }\n }\n\n public override async fromJSON(formatProps: SchemaItemFormatProps) {\n await super.fromJSON(formatProps);\n this.typecheck(formatProps);\n if (undefined === formatProps.composite)\n return;\n\n // Units are separated from the rest of the deserialization because of the need to have separate sync and async implementation\n for (const unit of formatProps.composite.units) {\n const newUnit = await this.schema.lookupItem(unit.name);\n if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);\n this.addUnit(newUnit, unit.label);\n }\n }\n\n /**\n * Save this Format's 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): SchemaItemFormatProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.type = this.type;\n schemaJson.precision = this.precision;\n\n // this._spacer = \" \";\n // this._includeZero = true;\n\n // Serialize the minimal amount of information needed so anything that is the same as the default, do not serialize.\n if (0.0 !== this.roundFactor)\n schemaJson.roundFactor = this.roundFactor;\n if (ShowSignOption.OnlyNegative !== this.showSignOption)\n schemaJson.showSignOption = this.showSignOption;\n if (FormatTraits.Uninitialized !== this.formatTraits)\n schemaJson.formatTraits = formatTraitsToArray(this.formatTraits);\n if (\".\" !== this.decimalSeparator)\n schemaJson.decimalSeparator = this.decimalSeparator;\n if (\",\" !== this.thousandSeparator)\n schemaJson.thousandSeparator = this.thousandSeparator;\n if (\" \" !== this.uomSeparator)\n schemaJson.uomSeparator = this.uomSeparator;\n\n if (undefined !== this.minWidth)\n schemaJson.minWidth = this.minWidth;\n\n if (FormatType.Scientific === this.type && undefined !== this.scientificType)\n schemaJson.scientificType = this.scientificType;\n\n if (FormatType.Station === this.type) {\n if (undefined !== this.stationOffsetSize)\n schemaJson.stationOffsetSize = this.stationOffsetSize;\n if (\" \" !== this.stationSeparator)\n schemaJson.stationSeparator = this.stationSeparator;\n }\n\n if (undefined === this.units)\n return schemaJson;\n\n schemaJson.composite = {};\n\n if (\" \" !== this.spacer)\n schemaJson.composite.spacer = this.spacer;\n\n if (true !== this.includeZero)\n schemaJson.composite.includeZero = this.includeZero;\n\n schemaJson.composite.units = [];\n for (const unit of this.units) {\n schemaJson.composite.units.push({\n name: unit[0].fullName,\n label: unit[1],\n });\n }\n\n return schemaJson;\n }\n\n /** @internal */\n public override async toXml(schemaXml: Document): Promise<Element> {\n const itemElement = await super.toXml(schemaXml);\n itemElement.setAttribute(\"type\", this.type.toLowerCase());\n itemElement.setAttribute(\"precision\", this.precision.toString());\n itemElement.setAttribute(\"roundFactor\", this.roundFactor.toString());\n itemElement.setAttribute(\"showSignOption\", this.showSignOption);\n itemElement.setAttribute(\"decimalSeparator\", this.decimalSeparator);\n itemElement.setAttribute(\"thousandSeparator\", this.thousandSeparator);\n itemElement.setAttribute(\"uomSeparator\", this.uomSeparator);\n itemElement.setAttribute(\"stationSeparator\", this.stationSeparator);\n\n if (undefined !== this.minWidth)\n itemElement.setAttribute(\"minWidth\", this.minWidth.toString());\n if (undefined !== this.scientificType)\n itemElement.setAttribute(\"scientificType\", this.scientificType);\n if (undefined !== this.stationOffsetSize)\n itemElement.setAttribute(\"stationOffsetSize\", this.stationOffsetSize.toString());\n\n const formatTraits = formatTraitsToArray(this.formatTraits);\n if (formatTraits.length > 0)\n itemElement.setAttribute(\"formatTraits\", formatTraits.join(\"|\"));\n\n if (undefined !== this.units) {\n const compositeElement = schemaXml.createElement(\"Composite\");\n if (undefined !== this.spacer)\n compositeElement.setAttribute(\"spacer\", this.spacer);\n if (undefined !== this.includeZero)\n compositeElement.setAttribute(\"includeZero\", this.includeZero.toString());\n\n this.units.forEach(([unit, label]) => {\n const unitElement = schemaXml.createElement(\"Unit\");\n if (undefined !== label)\n unitElement.setAttribute(\"label\", label);\n const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);\n unitElement.textContent = unitName;\n compositeElement.appendChild(unitElement);\n });\n\n itemElement.appendChild(compositeElement);\n }\n\n return itemElement;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setFormatType(formatType: FormatType) {\n this._base.type = formatType;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setRoundFactor(roundFactor: number) {\n this._base.roundFactor = roundFactor;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setShowSignOption(signOption: ShowSignOption) {\n this._base.showSignOption = signOption;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setDecimalSeparator(separator: string) {\n this._base.decimalSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setThousandSeparator(separator: string) {\n this._base.thousandSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setUomSeparator(separator: string) {\n this._base.uomSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setStationSeparator(separator: string) {\n this._base.stationSeparator = separator;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setStationOffsetSize(stationOffsetSize: number) {\n this._base.stationOffsetSize = stationOffsetSize;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setScientificType(scientificType: ScientificType) {\n this._base.scientificType = scientificType;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setMinWidth(minWidth: number) {\n this._base.minWidth = minWidth;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setSpacer(spacer: string) {\n this._base.spacer = spacer;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setIncludeZero(includeZero: boolean) {\n this._base.includeZero = includeZero;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setFormatTraits(formatTraits: FormatTraits) {\n this._base.formatTraits = formatTraits;\n }\n\n /**\n * @alpha Used in schema editing.\n */\n protected setUnits(units: Array<[Unit | InvertedUnit, string | undefined]>) {\n this._units = units;\n }\n\n /** Type guard to check if the SchemaItem is of type Format.\n * @param item The SchemaItem to check.\n * @returns True if the item is a Format, false otherwise.\n */\n public static isFormat(item?: SchemaItem): item is Format {\n if (item && item.schemaItemType === SchemaItemType.Format)\n return true;\n\n return false;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type Format.\n * @param item The SchemaItem to check.\n * @returns The item cast to Format if it is a Format, undefined otherwise.\n */\n public static assertIsFormat(item?: SchemaItem): asserts item is Format {\n if (!this.isFormat(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Format}' (Format)`);\n }\n}\n\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableFormat extends Format {\n public abstract override addUnit(unit: Unit | InvertedUnit, label?: string): void;\n public abstract override setPrecision(precision: number): void;\n public abstract override setFormatType(formatType: FormatType): void;\n public abstract override setRoundFactor(roundFactor: number): void;\n public abstract override setShowSignOption(signOption: ShowSignOption): void;\n public abstract override setDecimalSeparator(separator: string): void;\n public abstract override setThousandSeparator(separator: string): void;\n public abstract override setUomSeparator(separator: string): void;\n public abstract override setStationSeparator(separator: string): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}
@@ -4,23 +4,28 @@
4
4
  import { InvertedUnitProps } from "../Deserialization/JsonProps";
5
5
  import { SchemaItemType } from "../ECObjects";
6
6
  import { LazyLoadedUnit, LazyLoadedUnitSystem } from "../Interfaces";
7
- import { Schema } from "./Schema";
8
7
  import { SchemaItem } from "./SchemaItem";
9
8
  /**
10
9
  * An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.
11
10
  * @beta
12
11
  */
13
12
  export declare class InvertedUnit extends SchemaItem {
14
- readonly schemaItemType: SchemaItemType.InvertedUnit;
13
+ readonly schemaItemType: SchemaItemType;
14
+ static get schemaItemType(): SchemaItemType;
15
15
  protected _invertsUnit?: LazyLoadedUnit;
16
16
  protected _unitSystem?: LazyLoadedUnitSystem;
17
- constructor(schema: Schema, name: string);
18
17
  get invertsUnit(): LazyLoadedUnit | undefined;
19
18
  get unitSystem(): LazyLoadedUnitSystem | undefined;
20
19
  /**
21
20
  * @alpha
22
21
  */
23
22
  static isInvertedUnit(object: any): object is InvertedUnit;
23
+ /**
24
+ * Type assertion to check if the SchemaItem is of type InvertedUnit.
25
+ * @param item The SchemaItem to check.
26
+ * @returns The item cast to InvertedUnit if it is an InvertedUnit, undefined otherwise.
27
+ */
28
+ static assertIsInvertedUnit(item?: SchemaItem): asserts item is InvertedUnit;
24
29
  /**
25
30
  * Save this InvertedUnit's properties to an object for serializing to JSON.
26
31
  * @param standalone Serialization includes only this object (as opposed to the full schema).
@@ -1 +1 @@
1
- {"version":3,"file":"InvertedUnit.d.ts","sourceRoot":"","sources":["../../../src/Metadata/InvertedUnit.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,c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ization/XmlSerializationUtils"
10
10
  import { SchemaItemType } from "../ECObjects";
11
11
  import { ECObjectsError, ECObjectsStatus } from "../Exception";
12
12
  import { SchemaItem } from "./SchemaItem";
13
+ import { Unit } from "./Unit";
14
+ import { UnitSystem } from "./UnitSystem";
13
15
  /**
14
16
  * An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.
15
17
  * @beta
16
18
  */
17
19
  export class InvertedUnit extends SchemaItem {
18
- constructor(schema, name) {
19
- super(schema, name);
20
- this.schemaItemType = SchemaItemType.InvertedUnit;
21
- }
20
+ schemaItemType = InvertedUnit.schemaItemType;
21
+ static get schemaItemType() { return SchemaItemType.InvertedUnit; }
22
+ _invertsUnit; // required
23
+ _unitSystem; // required
22
24
  get invertsUnit() { return this._invertsUnit; }
23
25
  get unitSystem() { return this._unitSystem; }
24
26
  /**
@@ -27,6 +29,15 @@ export class InvertedUnit extends SchemaItem {
27
29
  static isInvertedUnit(object) {
28
30
  return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.InvertedUnit;
29
31
  }
32
+ /**
33
+ * Type assertion to check if the SchemaItem is of type InvertedUnit.
34
+ * @param item The SchemaItem to check.
35
+ * @returns The item cast to InvertedUnit if it is an InvertedUnit, undefined otherwise.
36
+ */
37
+ static assertIsInvertedUnit(item) {
38
+ if (!this.isInvertedUnit(item))
39
+ throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.InvertedUnit}' (InvertedUnit)`);
40
+ }
30
41
  /**
31
42
  * Save this InvertedUnit's properties to an object for serializing to JSON.
32
43
  * @param standalone Serialization includes only this object (as opposed to the full schema).
@@ -57,7 +68,7 @@ export class InvertedUnit extends SchemaItem {
57
68
  super.fromJSONSync(invertedUnitProps);
58
69
  const unitSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.invertsUnit);
59
70
  this._invertsUnit = new DelayedPromiseWithProps(unitSchemaItemKey, async () => {
60
- const invertsUnit = await this.schema.lookupItem(unitSchemaItemKey);
71
+ const invertsUnit = await this.schema.lookupItem(unitSchemaItemKey, Unit);
61
72
  if (undefined === invertsUnit)
62
73
  throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the invertsUnit ${invertedUnitProps.invertsUnit}.`);
63
74
  return invertsUnit;
@@ -66,7 +77,7 @@ export class InvertedUnit extends SchemaItem {
66
77
  if (!unitSystemSchemaItemKey)
67
78
  throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);
68
79
  this._unitSystem = new DelayedPromiseWithProps(unitSystemSchemaItemKey, async () => {
69
- const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey);
80
+ const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey, UnitSystem);
70
81
  if (undefined === unitSystem)
71
82
  throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);
72
83
  return unitSystem;
@@ -1 +1 @@
1
- {"version":3,"file":"InvertedUnit.js","sourceRoot":"","sources":["../../../src/Metadata/InvertedUnit.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI/D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,UAAU;IAK1C,YAAY,MAAc,EAAE,IAAY;QACtC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,YAAY,CAAC;IACpD,CAAC;IAED,IAAW,WAAW,KAAi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;IACP,CAAC;IAEe,KAAK,CAAC,QAAQ,CAAC,iBAAoC;QACjE,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;IAED;;;OAGG;IACO,cAAc,CAAC,WAA2B;QAClD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED;;;OAGG;IACO,aAAa,CAAC,UAAgC;QACtD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAgB,mBAAoB,SAAQ,YAAY;CAI7D","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 { InvertedUnitProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedUnit, LazyLoadedUnitSystem } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { Schema } from \"./Schema\";\r\nimport { SchemaItem } from \"./SchemaItem\";\r\nimport { Unit } from \"./Unit\";\r\nimport { UnitSystem } from \"./UnitSystem\";\r\n\r\n/**\r\n * An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.\r\n * @beta\r\n */\r\nexport class InvertedUnit extends SchemaItem {\r\n public override readonly schemaItemType!: SchemaItemType.InvertedUnit;\r\n protected _invertsUnit?: LazyLoadedUnit; // required\r\n protected _unitSystem?: LazyLoadedUnitSystem; // required\r\n\r\n constructor(schema: Schema, name: string) {\r\n super(schema, name);\r\n this.schemaItemType = SchemaItemType.InvertedUnit;\r\n }\r\n\r\n public get invertsUnit(): LazyLoadedUnit | undefined { return this._invertsUnit; }\r\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\r\n\r\n /**\r\n * @alpha\r\n */\r\n public static isInvertedUnit(object: any): object is InvertedUnit {\r\n return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.InvertedUnit;\r\n }\r\n\r\n /**\r\n * Save this InvertedUnit's 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): InvertedUnitProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n schemaJson.invertsUnit = this.invertsUnit!.fullName;\r\n schemaJson.unitSystem = this.unitSystem!.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 const unitSystem = await this.unitSystem;\r\n if (undefined !== unitSystem) {\r\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\r\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\r\n }\r\n\r\n const invertsUnit = await this.invertsUnit;\r\n if (undefined !== invertsUnit) {\r\n const invertsUnitName = XmlSerializationUtils.createXmlTypedName(this.schema, invertsUnit.schema, invertsUnit.name);\r\n itemElement.setAttribute(\"invertsUnit\", invertsUnitName);\r\n }\r\n\r\n return itemElement;\r\n }\r\n\r\n public override fromJSONSync(invertedUnitProps: InvertedUnitProps) {\r\n super.fromJSONSync(invertedUnitProps);\r\n const unitSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.invertsUnit);\r\n this._invertsUnit = new DelayedPromiseWithProps<SchemaItemKey, Unit>(unitSchemaItemKey,\r\n async () => {\r\n const invertsUnit = await this.schema.lookupItem<Unit>(unitSchemaItemKey);\r\n if (undefined === invertsUnit)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the invertsUnit ${invertedUnitProps.invertsUnit}.`);\r\n return invertsUnit;\r\n });\r\n\r\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.unitSystem);\r\n if (!unitSystemSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);\r\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\r\n async () => {\r\n const unitSystem = await this.schema.lookupItem<UnitSystem>(unitSystemSchemaItemKey);\r\n if (undefined === unitSystem)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);\r\n return unitSystem;\r\n });\r\n }\r\n\r\n public override async fromJSON(invertedUnitProps: InvertedUnitProps) {\r\n this.fromJSONSync(invertedUnitProps);\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing\r\n */\r\n protected setInvertsUnit(invertsUnit: LazyLoadedUnit) {\r\n this._invertsUnit = invertsUnit;\r\n }\r\n\r\n /**\r\n * @alpha\r\n * Used for schema editing\r\n */\r\n protected setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\r\n this._unitSystem = unitSystem;\r\n }\r\n}\r\n\r\n/**\r\n * @internal\r\n * An abstract class used for schema editing.\r\n */\r\nexport abstract class MutableInvertedUnit extends InvertedUnit {\r\n public abstract override setInvertsUnit(invertsUnit: LazyLoadedUnit): void;\r\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"InvertedUnit.js","sourceRoot":"","sources":["../../../src/Metadata/InvertedUnit.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,uBAAuB,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------\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 { InvertedUnitProps } from \"../Deserialization/JsonProps\";\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\nimport { LazyLoadedUnit, LazyLoadedUnitSystem } from \"../Interfaces\";\nimport { SchemaItemKey } from \"../SchemaKey\";\nimport { SchemaItem } from \"./SchemaItem\";\nimport { Unit } from \"./Unit\";\nimport { UnitSystem } from \"./UnitSystem\";\n\n/**\n * An InvertedUnit is a specific type of Unit that describes the inverse of a single Unit whose dimensional derivation is unit-less.\n * @beta\n */\nexport class InvertedUnit extends SchemaItem {\n public override readonly schemaItemType = InvertedUnit.schemaItemType;\n public static override get schemaItemType() { return SchemaItemType.InvertedUnit; }\n protected _invertsUnit?: LazyLoadedUnit; // required\n protected _unitSystem?: LazyLoadedUnitSystem; // required\n\n public get invertsUnit(): LazyLoadedUnit | undefined { return this._invertsUnit; }\n public get unitSystem(): LazyLoadedUnitSystem | undefined { return this._unitSystem; }\n\n /**\n * @alpha\n */\n public static isInvertedUnit(object: any): object is InvertedUnit {\n return SchemaItem.isSchemaItem(object) && object.schemaItemType === SchemaItemType.InvertedUnit;\n }\n\n /**\n * Type assertion to check if the SchemaItem is of type InvertedUnit.\n * @param item The SchemaItem to check.\n * @returns The item cast to InvertedUnit if it is an InvertedUnit, undefined otherwise.\n */\n public static assertIsInvertedUnit(item?: SchemaItem): asserts item is InvertedUnit {\n if(!this.isInvertedUnit(item))\n throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.InvertedUnit}' (InvertedUnit)`);\n }\n\n /**\n * Save this InvertedUnit's 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): InvertedUnitProps {\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\n schemaJson.invertsUnit = this.invertsUnit!.fullName;\n schemaJson.unitSystem = this.unitSystem!.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 const unitSystem = await this.unitSystem;\n if (undefined !== unitSystem) {\n const unitSystemName = XmlSerializationUtils.createXmlTypedName(this.schema, unitSystem.schema, unitSystem.name);\n itemElement.setAttribute(\"unitSystem\", unitSystemName);\n }\n\n const invertsUnit = await this.invertsUnit;\n if (undefined !== invertsUnit) {\n const invertsUnitName = XmlSerializationUtils.createXmlTypedName(this.schema, invertsUnit.schema, invertsUnit.name);\n itemElement.setAttribute(\"invertsUnit\", invertsUnitName);\n }\n\n return itemElement;\n }\n\n public override fromJSONSync(invertedUnitProps: InvertedUnitProps) {\n super.fromJSONSync(invertedUnitProps);\n const unitSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.invertsUnit);\n this._invertsUnit = new DelayedPromiseWithProps<SchemaItemKey, Unit>(unitSchemaItemKey,\n async () => {\n const invertsUnit = await this.schema.lookupItem(unitSchemaItemKey, Unit);\n if (undefined === invertsUnit)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the invertsUnit ${invertedUnitProps.invertsUnit}.`);\n return invertsUnit;\n });\n\n const unitSystemSchemaItemKey = this.schema.getSchemaItemKey(invertedUnitProps.unitSystem);\n if (!unitSystemSchemaItemKey)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);\n this._unitSystem = new DelayedPromiseWithProps<SchemaItemKey, UnitSystem>(unitSystemSchemaItemKey,\n async () => {\n const unitSystem = await this.schema.lookupItem(unitSystemSchemaItemKey, UnitSystem);\n if (undefined === unitSystem)\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `Unable to locate the unitSystem ${invertedUnitProps.unitSystem}.`);\n return unitSystem;\n });\n }\n\n public override async fromJSON(invertedUnitProps: InvertedUnitProps) {\n this.fromJSONSync(invertedUnitProps);\n }\n\n /**\n * @alpha\n * Used for schema editing\n */\n protected setInvertsUnit(invertsUnit: LazyLoadedUnit) {\n this._invertsUnit = invertsUnit;\n }\n\n /**\n * @alpha\n * Used for schema editing\n */\n protected setUnitSystem(unitSystem: LazyLoadedUnitSystem) {\n this._unitSystem = unitSystem;\n }\n}\n\n/**\n * @internal\n * An abstract class used for schema editing.\n */\nexport abstract class MutableInvertedUnit extends InvertedUnit {\n public abstract override setInvertsUnit(invertsUnit: LazyLoadedUnit): void;\n public abstract override setUnitSystem(unitSystem: LazyLoadedUnitSystem): void;\n public abstract override setDisplayLabel(displayLabel: string): void;\n}\n"]}