@itwin/ecschema-metadata 5.0.0-dev.98 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/CHANGELOG.md +61 -1
  2. package/lib/cjs/Context.d.ts +4 -4
  3. package/lib/cjs/Context.d.ts.map +1 -1
  4. package/lib/cjs/Context.js +7 -7
  5. package/lib/cjs/Context.js.map +1 -1
  6. package/lib/cjs/DelayedPromise.d.ts +9 -8
  7. package/lib/cjs/DelayedPromise.d.ts.map +1 -1
  8. package/lib/cjs/DelayedPromise.js +2 -2
  9. package/lib/cjs/DelayedPromise.js.map +1 -1
  10. package/lib/cjs/Deserialization/Helper.d.ts.map +1 -1
  11. package/lib/cjs/Deserialization/Helper.js +27 -26
  12. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  13. package/lib/cjs/Deserialization/JsonParser.js +150 -150
  14. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  15. package/lib/cjs/Deserialization/JsonProps.d.ts +34 -34
  16. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  17. package/lib/cjs/Deserialization/JsonProps.js +3 -3
  18. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  19. package/lib/cjs/Deserialization/XmlParser.js +49 -49
  20. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  21. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +0 -5
  22. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
  23. package/lib/cjs/Deserialization/XmlSerializationUtils.js +6 -11
  24. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  25. package/lib/cjs/ECName.d.ts +2 -2
  26. package/lib/cjs/ECName.js +4 -4
  27. package/lib/cjs/ECName.js.map +1 -1
  28. package/lib/cjs/ECObjects.d.ts +24 -12
  29. package/lib/cjs/ECObjects.d.ts.map +1 -1
  30. package/lib/cjs/ECObjects.js +48 -25
  31. package/lib/cjs/ECObjects.js.map +1 -1
  32. package/lib/cjs/Exception.d.ts +4 -4
  33. package/lib/cjs/Exception.d.ts.map +1 -1
  34. package/lib/cjs/Exception.js +60 -60
  35. package/lib/cjs/Exception.js.map +1 -1
  36. package/lib/cjs/Interfaces.d.ts +30 -34
  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 +107 -19
  40. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  41. package/lib/cjs/Metadata/Class.js +127 -47
  42. package/lib/cjs/Metadata/Class.js.map +1 -1
  43. package/lib/cjs/Metadata/Constant.d.ts +12 -9
  44. package/lib/cjs/Metadata/Constant.d.ts.map +1 -1
  45. package/lib/cjs/Metadata/Constant.js +12 -9
  46. package/lib/cjs/Metadata/Constant.js.map +1 -1
  47. package/lib/cjs/Metadata/CustomAttribute.d.ts +2 -2
  48. package/lib/cjs/Metadata/CustomAttribute.d.ts.map +1 -1
  49. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  50. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +6 -4
  51. package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
  52. package/lib/cjs/Metadata/CustomAttributeClass.js +8 -6
  53. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  54. package/lib/cjs/Metadata/EntityClass.d.ts +20 -3
  55. package/lib/cjs/Metadata/EntityClass.d.ts.map +1 -1
  56. package/lib/cjs/Metadata/EntityClass.js +32 -14
  57. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  58. package/lib/cjs/Metadata/Enumeration.d.ts +16 -9
  59. package/lib/cjs/Metadata/Enumeration.d.ts.map +1 -1
  60. package/lib/cjs/Metadata/Enumeration.js +20 -13
  61. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  62. package/lib/cjs/Metadata/Format.d.ts +32 -24
  63. package/lib/cjs/Metadata/Format.d.ts.map +1 -1
  64. package/lib/cjs/Metadata/Format.js +47 -27
  65. package/lib/cjs/Metadata/Format.js.map +1 -1
  66. package/lib/cjs/Metadata/InvertedUnit.d.ts +11 -7
  67. package/lib/cjs/Metadata/InvertedUnit.d.ts.map +1 -1
  68. package/lib/cjs/Metadata/InvertedUnit.js +16 -10
  69. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  70. package/lib/cjs/Metadata/KindOfQuantity.d.ts +24 -15
  71. package/lib/cjs/Metadata/KindOfQuantity.d.ts.map +1 -1
  72. package/lib/cjs/Metadata/KindOfQuantity.js +54 -29
  73. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  74. package/lib/cjs/Metadata/Mixin.d.ts +16 -3
  75. package/lib/cjs/Metadata/Mixin.d.ts.map +1 -1
  76. package/lib/cjs/Metadata/Mixin.js +20 -7
  77. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  78. package/lib/cjs/Metadata/OverrideFormat.d.ts +12 -12
  79. package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
  80. package/lib/cjs/Metadata/OverrideFormat.js +27 -19
  81. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  82. package/lib/cjs/Metadata/Phenomenon.d.ts +10 -2
  83. package/lib/cjs/Metadata/Phenomenon.d.ts.map +1 -1
  84. package/lib/cjs/Metadata/Phenomenon.js +11 -3
  85. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  86. package/lib/cjs/Metadata/Property.d.ts +46 -28
  87. package/lib/cjs/Metadata/Property.d.ts.map +1 -1
  88. package/lib/cjs/Metadata/Property.js +46 -22
  89. package/lib/cjs/Metadata/Property.js.map +1 -1
  90. package/lib/cjs/Metadata/PropertyCategory.d.ts +6 -3
  91. package/lib/cjs/Metadata/PropertyCategory.d.ts.map +1 -1
  92. package/lib/cjs/Metadata/PropertyCategory.js +12 -5
  93. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  94. package/lib/cjs/Metadata/RelationshipClass.d.ts +48 -25
  95. package/lib/cjs/Metadata/RelationshipClass.d.ts.map +1 -1
  96. package/lib/cjs/Metadata/RelationshipClass.js +54 -34
  97. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  98. package/lib/cjs/Metadata/Schema.d.ts +50 -28
  99. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  100. package/lib/cjs/Metadata/Schema.js +64 -42
  101. package/lib/cjs/Metadata/Schema.js.map +1 -1
  102. package/lib/cjs/Metadata/SchemaItem.d.ts +10 -19
  103. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  104. package/lib/cjs/Metadata/SchemaItem.js +12 -20
  105. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  106. package/lib/cjs/Metadata/Unit.d.ts +17 -21
  107. package/lib/cjs/Metadata/Unit.d.ts.map +1 -1
  108. package/lib/cjs/Metadata/Unit.js +20 -22
  109. package/lib/cjs/Metadata/Unit.js.map +1 -1
  110. package/lib/cjs/Metadata/UnitSystem.d.ts +3 -1
  111. package/lib/cjs/Metadata/UnitSystem.d.ts.map +1 -1
  112. package/lib/cjs/Metadata/UnitSystem.js +4 -2
  113. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  114. package/lib/cjs/PropertyTypes.d.ts +11 -11
  115. package/lib/cjs/PropertyTypes.d.ts.map +1 -1
  116. package/lib/cjs/PropertyTypes.js +28 -20
  117. package/lib/cjs/PropertyTypes.js.map +1 -1
  118. package/lib/cjs/SchemaFormatsProvider.d.ts +39 -0
  119. package/lib/cjs/SchemaFormatsProvider.d.ts.map +1 -0
  120. package/lib/cjs/SchemaFormatsProvider.js +172 -0
  121. package/lib/cjs/SchemaFormatsProvider.js.map +1 -0
  122. package/lib/cjs/SchemaJsonLocater.d.ts +5 -5
  123. package/lib/cjs/SchemaJsonLocater.js +4 -4
  124. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  125. package/lib/cjs/SchemaKey.d.ts +6 -6
  126. package/lib/cjs/SchemaKey.d.ts.map +1 -1
  127. package/lib/cjs/SchemaKey.js +9 -9
  128. package/lib/cjs/SchemaKey.js.map +1 -1
  129. package/lib/cjs/SchemaLoader.d.ts +3 -3
  130. package/lib/cjs/SchemaLoader.js +4 -4
  131. package/lib/cjs/SchemaLoader.js.map +1 -1
  132. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +2 -2
  133. package/lib/cjs/SchemaPartVisitorDelegate.js +1 -1
  134. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  135. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  136. package/lib/cjs/ecschema-metadata.d.ts +2 -1
  137. package/lib/cjs/ecschema-metadata.d.ts.map +1 -1
  138. package/lib/cjs/ecschema-metadata.js +1 -0
  139. package/lib/cjs/ecschema-metadata.js.map +1 -1
  140. package/lib/cjs/utils/SchemaGraph.js +3 -3
  141. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  142. package/lib/esm/Context.d.ts +4 -4
  143. package/lib/esm/Context.d.ts.map +1 -1
  144. package/lib/esm/Context.js +8 -8
  145. package/lib/esm/Context.js.map +1 -1
  146. package/lib/esm/DelayedPromise.d.ts +9 -8
  147. package/lib/esm/DelayedPromise.d.ts.map +1 -1
  148. package/lib/esm/DelayedPromise.js +2 -2
  149. package/lib/esm/DelayedPromise.js.map +1 -1
  150. package/lib/esm/Deserialization/Helper.d.ts.map +1 -1
  151. package/lib/esm/Deserialization/Helper.js +28 -27
  152. package/lib/esm/Deserialization/Helper.js.map +1 -1
  153. package/lib/esm/Deserialization/JsonParser.js +151 -151
  154. package/lib/esm/Deserialization/JsonParser.js.map +1 -1
  155. package/lib/esm/Deserialization/JsonProps.d.ts +34 -34
  156. package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -1
  157. package/lib/esm/Deserialization/JsonProps.js +3 -3
  158. package/lib/esm/Deserialization/JsonProps.js.map +1 -1
  159. package/lib/esm/Deserialization/XmlParser.js +50 -50
  160. package/lib/esm/Deserialization/XmlParser.js.map +1 -1
  161. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +0 -5
  162. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -1
  163. package/lib/esm/Deserialization/XmlSerializationUtils.js +7 -12
  164. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -1
  165. package/lib/esm/ECName.d.ts +2 -2
  166. package/lib/esm/ECName.js +5 -5
  167. package/lib/esm/ECName.js.map +1 -1
  168. package/lib/esm/ECObjects.d.ts +24 -12
  169. package/lib/esm/ECObjects.d.ts.map +1 -1
  170. package/lib/esm/ECObjects.js +49 -26
  171. package/lib/esm/ECObjects.js.map +1 -1
  172. package/lib/esm/Exception.d.ts +4 -4
  173. package/lib/esm/Exception.d.ts.map +1 -1
  174. package/lib/esm/Exception.js +58 -58
  175. package/lib/esm/Exception.js.map +1 -1
  176. package/lib/esm/Interfaces.d.ts +30 -34
  177. package/lib/esm/Interfaces.d.ts.map +1 -1
  178. package/lib/esm/Interfaces.js.map +1 -1
  179. package/lib/esm/Metadata/Class.d.ts +107 -19
  180. package/lib/esm/Metadata/Class.d.ts.map +1 -1
  181. package/lib/esm/Metadata/Class.js +128 -48
  182. package/lib/esm/Metadata/Class.js.map +1 -1
  183. package/lib/esm/Metadata/Constant.d.ts +12 -9
  184. package/lib/esm/Metadata/Constant.d.ts.map +1 -1
  185. package/lib/esm/Metadata/Constant.js +13 -10
  186. package/lib/esm/Metadata/Constant.js.map +1 -1
  187. package/lib/esm/Metadata/CustomAttribute.d.ts +2 -2
  188. package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -1
  189. package/lib/esm/Metadata/CustomAttribute.js.map +1 -1
  190. package/lib/esm/Metadata/CustomAttributeClass.d.ts +6 -4
  191. package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -1
  192. package/lib/esm/Metadata/CustomAttributeClass.js +9 -7
  193. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -1
  194. package/lib/esm/Metadata/EntityClass.d.ts +20 -3
  195. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -1
  196. package/lib/esm/Metadata/EntityClass.js +33 -15
  197. package/lib/esm/Metadata/EntityClass.js.map +1 -1
  198. package/lib/esm/Metadata/Enumeration.d.ts +16 -9
  199. package/lib/esm/Metadata/Enumeration.d.ts.map +1 -1
  200. package/lib/esm/Metadata/Enumeration.js +21 -14
  201. package/lib/esm/Metadata/Enumeration.js.map +1 -1
  202. package/lib/esm/Metadata/Format.d.ts +32 -24
  203. package/lib/esm/Metadata/Format.d.ts.map +1 -1
  204. package/lib/esm/Metadata/Format.js +48 -28
  205. package/lib/esm/Metadata/Format.js.map +1 -1
  206. package/lib/esm/Metadata/InvertedUnit.d.ts +11 -7
  207. package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -1
  208. package/lib/esm/Metadata/InvertedUnit.js +17 -11
  209. package/lib/esm/Metadata/InvertedUnit.js.map +1 -1
  210. package/lib/esm/Metadata/KindOfQuantity.d.ts +24 -15
  211. package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -1
  212. package/lib/esm/Metadata/KindOfQuantity.js +55 -30
  213. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -1
  214. package/lib/esm/Metadata/Mixin.d.ts +16 -3
  215. package/lib/esm/Metadata/Mixin.d.ts.map +1 -1
  216. package/lib/esm/Metadata/Mixin.js +21 -8
  217. package/lib/esm/Metadata/Mixin.js.map +1 -1
  218. package/lib/esm/Metadata/OverrideFormat.d.ts +12 -12
  219. package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -1
  220. package/lib/esm/Metadata/OverrideFormat.js +28 -20
  221. package/lib/esm/Metadata/OverrideFormat.js.map +1 -1
  222. package/lib/esm/Metadata/Phenomenon.d.ts +10 -2
  223. package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -1
  224. package/lib/esm/Metadata/Phenomenon.js +12 -4
  225. package/lib/esm/Metadata/Phenomenon.js.map +1 -1
  226. package/lib/esm/Metadata/Property.d.ts +46 -28
  227. package/lib/esm/Metadata/Property.d.ts.map +1 -1
  228. package/lib/esm/Metadata/Property.js +47 -23
  229. package/lib/esm/Metadata/Property.js.map +1 -1
  230. package/lib/esm/Metadata/PropertyCategory.d.ts +6 -3
  231. package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -1
  232. package/lib/esm/Metadata/PropertyCategory.js +13 -6
  233. package/lib/esm/Metadata/PropertyCategory.js.map +1 -1
  234. package/lib/esm/Metadata/RelationshipClass.d.ts +48 -25
  235. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -1
  236. package/lib/esm/Metadata/RelationshipClass.js +55 -35
  237. package/lib/esm/Metadata/RelationshipClass.js.map +1 -1
  238. package/lib/esm/Metadata/Schema.d.ts +50 -28
  239. package/lib/esm/Metadata/Schema.d.ts.map +1 -1
  240. package/lib/esm/Metadata/Schema.js +65 -43
  241. package/lib/esm/Metadata/Schema.js.map +1 -1
  242. package/lib/esm/Metadata/SchemaItem.d.ts +10 -19
  243. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -1
  244. package/lib/esm/Metadata/SchemaItem.js +13 -21
  245. package/lib/esm/Metadata/SchemaItem.js.map +1 -1
  246. package/lib/esm/Metadata/Unit.d.ts +17 -21
  247. package/lib/esm/Metadata/Unit.d.ts.map +1 -1
  248. package/lib/esm/Metadata/Unit.js +21 -23
  249. package/lib/esm/Metadata/Unit.js.map +1 -1
  250. package/lib/esm/Metadata/UnitSystem.d.ts +3 -1
  251. package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -1
  252. package/lib/esm/Metadata/UnitSystem.js +5 -3
  253. package/lib/esm/Metadata/UnitSystem.js.map +1 -1
  254. package/lib/esm/PropertyTypes.d.ts +11 -11
  255. package/lib/esm/PropertyTypes.d.ts.map +1 -1
  256. package/lib/esm/PropertyTypes.js +29 -21
  257. package/lib/esm/PropertyTypes.js.map +1 -1
  258. package/lib/esm/SchemaFormatsProvider.d.ts +39 -0
  259. package/lib/esm/SchemaFormatsProvider.d.ts.map +1 -0
  260. package/lib/esm/SchemaFormatsProvider.js +168 -0
  261. package/lib/esm/SchemaFormatsProvider.js.map +1 -0
  262. package/lib/esm/SchemaJsonLocater.d.ts +5 -5
  263. package/lib/esm/SchemaJsonLocater.js +4 -4
  264. package/lib/esm/SchemaJsonLocater.js.map +1 -1
  265. package/lib/esm/SchemaKey.d.ts +6 -6
  266. package/lib/esm/SchemaKey.d.ts.map +1 -1
  267. package/lib/esm/SchemaKey.js +10 -10
  268. package/lib/esm/SchemaKey.js.map +1 -1
  269. package/lib/esm/SchemaLoader.d.ts +3 -3
  270. package/lib/esm/SchemaLoader.js +5 -5
  271. package/lib/esm/SchemaLoader.js.map +1 -1
  272. package/lib/esm/SchemaPartVisitorDelegate.d.ts +2 -2
  273. package/lib/esm/SchemaPartVisitorDelegate.js +1 -1
  274. package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -1
  275. package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -1
  276. package/lib/esm/ecschema-metadata.d.ts +2 -1
  277. package/lib/esm/ecschema-metadata.d.ts.map +1 -1
  278. package/lib/esm/ecschema-metadata.js +1 -0
  279. package/lib/esm/ecschema-metadata.js.map +1 -1
  280. package/lib/esm/utils/SchemaGraph.js +4 -4
  281. package/lib/esm/utils/SchemaGraph.js.map +1 -1
  282. package/package.json +12 -6
@@ -7,15 +7,16 @@
7
7
  */
8
8
  import { SchemaReadHelper } from "../Deserialization/Helper";
9
9
  import { PrimitiveType, primitiveTypeToString, SchemaItemType } from "../ECObjects";
10
- import { ECObjectsError, ECObjectsStatus } from "../Exception";
10
+ import { ECSchemaError, ECSchemaStatus } from "../Exception";
11
11
  import { ECName } from "../ECName";
12
12
  import { SchemaItem } from "./SchemaItem";
13
13
  /**
14
14
  * A Typescript class representation of an ECEnumeration.
15
- * @beta
15
+ * @public @preview
16
16
  */
17
17
  export class Enumeration extends SchemaItem {
18
18
  schemaItemType = Enumeration.schemaItemType;
19
+ /** @internal */
19
20
  static get schemaItemType() { return SchemaItemType.Enumeration; }
20
21
  _type;
21
22
  _isStrict;
@@ -23,6 +24,7 @@ export class Enumeration extends SchemaItem {
23
24
  get enumerators() { return this._enumerators; }
24
25
  get type() { return this._type; }
25
26
  get isStrict() { return this._isStrict; }
27
+ /** @internal */
26
28
  constructor(schema, name, primitiveType) {
27
29
  super(schema, name);
28
30
  this._type = primitiveType;
@@ -50,9 +52,9 @@ export class Enumeration extends SchemaItem {
50
52
  findDuplicateEnumerators(name, value) {
51
53
  this._enumerators.forEach((element) => {
52
54
  if (element.name.toLowerCase() === name.toLowerCase())
53
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
55
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
54
56
  if (element.value === value)
55
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
57
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
56
58
  });
57
59
  }
58
60
  /**
@@ -62,23 +64,25 @@ export class Enumeration extends SchemaItem {
62
64
  * @param label A localized display label that is used instead of the name in a GUI.
63
65
  * @param description A localized description for the enumerator.
64
66
  * @return AnyEnumerator object
67
+ * @internal
65
68
  */
66
69
  createEnumerator(name, value, label, description) {
67
70
  if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
68
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
71
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
69
72
  if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
70
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
73
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
71
74
  this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
72
75
  if (!ECName.validate(name))
73
- throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
76
+ throw new ECSchemaError(ECSchemaStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
74
77
  return { name, value, label, description };
75
78
  }
76
79
  /**
77
80
  * Adds enumerator to list of enumerators on this Enumeration
78
81
  * @param enumerator The enumerator to add
82
+ * @internal
79
83
  */
80
84
  addEnumerator(enumerator) {
81
- this.enumerators.push(enumerator);
85
+ this._enumerators.push(enumerator);
82
86
  }
83
87
  /**
84
88
  * Save this Enumeration's properties to an object for serializing to JSON.
@@ -131,19 +135,19 @@ export class Enumeration extends SchemaItem {
131
135
  if (SchemaReadHelper.isECSpecVersionNewer({ readVersion: enumerationProps.originalECSpecMajorVersion, writeVersion: enumerationProps.originalECSpecMinorVersion }))
132
136
  this._type = PrimitiveType.String;
133
137
  else
134
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
138
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
135
139
  }
136
140
  }
137
141
  else {
138
142
  const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
139
143
  if (!primitiveTypePattern.test(enumerationProps.type))
140
- 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"}".`);
144
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has an incompatible type. It must be "${(this.isInt) ? "int" : "string"}", not "${(this.isInt) ? "string" : "int"}".`);
141
145
  }
142
146
  this._isStrict = enumerationProps.isStrict;
143
147
  if (undefined !== enumerationProps.enumerators) {
144
148
  enumerationProps.enumerators.forEach((enumerator) => {
145
149
  // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
146
- // Throws ECObjectsError if there are duplicate names or values present in the enumeration
150
+ // Throws ECSchemaError if there are duplicate names or values present in the enumeration
147
151
  this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
148
152
  });
149
153
  }
@@ -152,7 +156,7 @@ export class Enumeration extends SchemaItem {
152
156
  this.fromJSONSync(enumerationProps);
153
157
  }
154
158
  /**
155
- * @alpha Used in schema editing.
159
+ * @internal
156
160
  */
157
161
  setIsStrict(isStrict) {
158
162
  this._isStrict = isStrict;
@@ -169,14 +173,17 @@ export class Enumeration extends SchemaItem {
169
173
  * Type assertion to check if the SchemaItem is of type Enumeration.
170
174
  * @param item The SchemaItem to check.
171
175
  * @returns The item cast to Enumeration if it is an Enumeration, undefined otherwise.
176
+ * @internal
172
177
  */
173
178
  static assertIsEnumeration(item) {
174
179
  if (!this.isEnumeration(item))
175
- throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);
180
+ throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);
176
181
  }
177
182
  }
178
- /** @internal
183
+ /**
179
184
  * An abstract class used for schema editing.
185
+ *
186
+ * @internal
180
187
  */
181
188
  export class MutableEnumeration extends Enumeration {
182
189
  }
@@ -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,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AAC,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"]}
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,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAa1C;;;GAGG;AACH,MAAM,OA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,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;;;;;OAKG;IACI,MAAM,CAAC,mBAAmB,CAAC,IAAiB;QACjD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC;YAC3B,MAAM,IAAI,aAAa,CAAC,cAAc,CAAC,qBAAqB,EAAE,aAAa,cAAc,CAAC,WAAW,iBAAiB,CAAC,CAAC;IAC5H,CAAC;CACF;AAED;;;;GAIG;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 { ECSchemaError, ECSchemaStatus } from \"../Exception\";\nimport { ECName } from \"../ECName\";\nimport { Schema } from \"./Schema\";\nimport { SchemaItem } from \"./SchemaItem\";\n\n/** @public @preview */\nexport interface Enumerator<T> {\n readonly name: string;\n readonly value: T;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** @public @preview */\nexport type AnyEnumerator = Enumerator<string | number>;\n\n/**\n * A Typescript class representation of an ECEnumeration.\n * @public @preview\n */\nexport class Enumeration extends SchemaItem {\n public override readonly schemaItemType = Enumeration.schemaItemType;\n /** @internal */\n public static override get schemaItemType() { return SchemaItemType.Enumeration; }\n private _type?: PrimitiveType.Integer | PrimitiveType.String;\n private _isStrict: boolean;\n private _enumerators: AnyEnumerator[];\n\n public get enumerators(): ReadonlyArray<AnyEnumerator> { return this._enumerators; }\n public get type() { return this._type; }\n public get isStrict() { return this._isStrict; }\n\n /** @internal */\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 ECSchemaError(ECSchemaStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);\n if (element.value === value)\n throw new ECSchemaError(ECSchemaStatus.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 * @internal\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 ECSchemaError(ECSchemaStatus.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 ECSchemaError(ECSchemaStatus.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 ECSchemaError(ECSchemaStatus.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 * @internal\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 ECSchemaError(ECSchemaStatus.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 ECSchemaError(ECSchemaStatus.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 ECSchemaError 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 * @internal\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 * @internal\n */\n public static assertIsEnumeration(item?: SchemaItem): asserts item is Enumeration {\n if (!this.isEnumeration(item))\n throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Enumeration}' (Enumeration)`);\n }\n}\n\n/**\n * An abstract class used for schema editing.\n *\n * @internal\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"]}
@@ -3,19 +3,20 @@
3
3
  */
4
4
  import { SchemaItemFormatProps } from "../Deserialization/JsonProps";
5
5
  import { SchemaItemType } from "../ECObjects";
6
- import { BaseFormat, DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
7
- import { InvertedUnit } from "./InvertedUnit";
6
+ import { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
8
7
  import { Schema } from "./Schema";
9
8
  import { SchemaItem } from "./SchemaItem";
10
- import { Unit } from "./Unit";
9
+ import { LazyLoadedInvertedUnit, LazyLoadedUnit } from "../Interfaces";
11
10
  /**
12
- * @beta
11
+ * @public @preview
13
12
  */
14
13
  export declare class Format extends SchemaItem {
15
14
  readonly schemaItemType: SchemaItemType;
15
+ /** @internal */
16
16
  static get schemaItemType(): SchemaItemType;
17
- protected _base: BaseFormat;
18
- protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;
17
+ private _base;
18
+ private _units?;
19
+ /** @internal */
19
20
  constructor(schema: Schema, name: string);
20
21
  get roundFactor(): number;
21
22
  get type(): FormatType;
@@ -31,15 +32,21 @@ export declare class Format extends SchemaItem {
31
32
  get formatTraits(): FormatTraits;
32
33
  get spacer(): string | undefined;
33
34
  get includeZero(): boolean | undefined;
34
- get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined;
35
+ get units(): ReadonlyArray<[LazyLoadedUnit | LazyLoadedInvertedUnit, string | undefined]> | undefined;
35
36
  private parseFormatTraits;
36
37
  hasFormatTrait(formatTrait: FormatTraits): boolean;
37
38
  /**
38
39
  * Adds a Unit, or InvertedUnit, with an optional label override.
39
40
  * @param unit The Unit, or InvertedUnit, to add to this Format.
40
41
  * @param label A label that overrides the label defined within the Unit when a value is formatted.
42
+ * @internal
43
+ */
44
+ protected addUnit(unit: LazyLoadedUnit | LazyLoadedInvertedUnit, label?: string): void;
45
+ /**
46
+ *
47
+ * @param precision
48
+ * @internal
41
49
  */
42
- protected addUnit(unit: Unit | InvertedUnit, label?: string): void;
43
50
  protected setPrecision(precision: number): void;
44
51
  private typecheck;
45
52
  fromJSONSync(formatProps: SchemaItemFormatProps): void;
@@ -53,61 +60,61 @@ export declare class Format extends SchemaItem {
53
60
  /** @internal */
54
61
  toXml(schemaXml: Document): Promise<Element>;
55
62
  /**
56
- * @alpha Used in schema editing.
63
+ * @internal
57
64
  */
58
65
  protected setFormatType(formatType: FormatType): void;
59
66
  /**
60
- * @alpha Used in schema editing.
67
+ * @internal
61
68
  */
62
69
  protected setRoundFactor(roundFactor: number): void;
63
70
  /**
64
- * @alpha Used in schema editing.
71
+ * @internal
65
72
  */
66
73
  protected setShowSignOption(signOption: ShowSignOption): void;
67
74
  /**
68
- * @alpha Used in schema editing.
75
+ * @internal
69
76
  */
70
77
  protected setDecimalSeparator(separator: string): void;
71
78
  /**
72
- * @alpha Used in schema editing.
79
+ * @internal
73
80
  */
74
81
  protected setThousandSeparator(separator: string): void;
75
82
  /**
76
- * @alpha Used in schema editing.
83
+ * @internal
77
84
  */
78
85
  protected setUomSeparator(separator: string): void;
79
86
  /**
80
- * @alpha Used in schema editing.
87
+ * @internal
81
88
  */
82
89
  protected setStationSeparator(separator: string): void;
83
90
  /**
84
- * @alpha Used in schema editing.
91
+ * @internal
85
92
  */
86
93
  protected setStationOffsetSize(stationOffsetSize: number): void;
87
94
  /**
88
- * @alpha Used in schema editing.
95
+ * @internal
89
96
  */
90
97
  protected setScientificType(scientificType: ScientificType): void;
91
98
  /**
92
- * @alpha Used in schema editing.
99
+ * @internal
93
100
  */
94
101
  protected setMinWidth(minWidth: number): void;
95
102
  /**
96
- * @alpha Used in schema editing.
103
+ * @internal
97
104
  */
98
105
  protected setSpacer(spacer: string): void;
99
106
  /**
100
- * @alpha Used in schema editing.
107
+ * @internal
101
108
  */
102
109
  protected setIncludeZero(includeZero: boolean): void;
103
110
  /**
104
- * @alpha Used in schema editing.
111
+ * @internal
105
112
  */
106
113
  protected setFormatTraits(formatTraits: FormatTraits): void;
107
114
  /**
108
- * @alpha Used in schema editing.
115
+ * @internal
109
116
  */
110
- protected setUnits(units: Array<[Unit | InvertedUnit, string | undefined]>): void;
117
+ protected setUnits(units: Array<[LazyLoadedUnit | LazyLoadedInvertedUnit, string | undefined]>): void;
111
118
  /** Type guard to check if the SchemaItem is of type Format.
112
119
  * @param item The SchemaItem to check.
113
120
  * @returns True if the item is a Format, false otherwise.
@@ -117,6 +124,7 @@ export declare class Format extends SchemaItem {
117
124
  * Type assertion to check if the SchemaItem is of type Format.
118
125
  * @param item The SchemaItem to check.
119
126
  * @returns The item cast to Format if it is a Format, undefined otherwise.
127
+ * @internal
120
128
  */
121
129
  static assertIsFormat(item?: SchemaItem): asserts item is Format;
122
130
  }
@@ -125,7 +133,7 @@ export declare class Format extends SchemaItem {
125
133
  * An abstract class used for schema editing.
126
134
  */
127
135
  export declare abstract class MutableFormat extends Format {
128
- abstract addUnit(unit: Unit | InvertedUnit, label?: string): void;
136
+ abstract addUnit(unit: LazyLoadedUnit | LazyLoadedInvertedUnit, label?: string): void;
129
137
  abstract setPrecision(precision: number): void;
130
138
  abstract setFormatType(formatType: FormatType): void;
131
139
  abstract setRoundFactor(roundFactor: number): void;
@@ -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,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B;;GAEG;AACH,qBAAa,MAAO,SAAQ,UAAU;IACpC,SAAyB,cAAc,iBAAyB;IAChE,WAA2B,cAAc,mBAAoC;IAC7E,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC;IAC5B,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,GAAG,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;gBAExD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAKxC,IAAW,WAAW,IAAI,MAAM,CAAmC;IACnE,IAAW,IAAI,IAAI,UAAU,CAA4B;IACzD,IAAW,SAAS,IAAI,gBAAgB,GAAG,mBAAmB,CAAiC;IAC/F,IAAW,QAAQ,IAAI,MAAM,GAAG,SAAS,CAAgC;IACzE,IAAW,cA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AAC,UAAU,EAAE,cAAc,GAAG,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"}
@@ -7,19 +7,22 @@
7
7
  */
8
8
  import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils";
9
9
  import { SchemaItemType } from "../ECObjects";
10
- import { ECObjectsError, ECObjectsStatus } from "../Exception";
10
+ import { ECSchemaError, ECSchemaStatus } from "../Exception";
11
11
  import { BaseFormat, FormatTraits, formatTraitsToArray, FormatType, ShowSignOption, } from "@itwin/core-quantity";
12
12
  import { InvertedUnit } from "./InvertedUnit";
13
13
  import { SchemaItem } from "./SchemaItem";
14
14
  import { Unit } from "./Unit";
15
+ import { DelayedPromiseWithProps } from "../DelayedPromise";
15
16
  /**
16
- * @beta
17
+ * @public @preview
17
18
  */
18
19
  export class Format extends SchemaItem {
19
20
  schemaItemType = Format.schemaItemType;
21
+ /** @internal */
20
22
  static get schemaItemType() { return SchemaItemType.Format; }
21
23
  _base;
22
24
  _units;
25
+ /** @internal */
23
26
  constructor(schema, name) {
24
27
  super(schema, name);
25
28
  this._base = new BaseFormat(name);
@@ -38,7 +41,9 @@ export class Format extends SchemaItem {
38
41
  get formatTraits() { return this._base.formatTraits; }
39
42
  get spacer() { return this._base.spacer; }
40
43
  get includeZero() { return this._base.includeZero; }
41
- get units() { return this._units; }
44
+ get units() {
45
+ return this._units;
46
+ }
42
47
  parseFormatTraits(formatTraitsFromJson) {
43
48
  return this._base.parseFormatTraits(formatTraitsFromJson);
44
49
  }
@@ -49,6 +54,7 @@ export class Format extends SchemaItem {
49
54
  * Adds a Unit, or InvertedUnit, with an optional label override.
50
55
  * @param unit The Unit, or InvertedUnit, to add to this Format.
51
56
  * @param label A label that overrides the label defined within the Unit when a value is formatted.
57
+ * @internal
52
58
  */
53
59
  addUnit(unit, label) {
54
60
  if (undefined === this._units)
@@ -56,11 +62,16 @@ export class Format extends SchemaItem {
56
62
  else { // Validate that a duplicate is not added.
57
63
  for (const existingUnit of this._units) {
58
64
  if (unit.fullName.toLowerCase() === existingUnit[0].fullName.toLowerCase())
59
- 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.
65
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Format ${this.fullName} has duplicate units, '${unit.fullName}'.`); // TODO: Validation - this should be a validation error not a hard failure.
60
66
  }
61
67
  }
62
68
  this._units.push([unit, label]);
63
69
  }
70
+ /**
71
+ *
72
+ * @param precision
73
+ * @internal
74
+ */
64
75
  setPrecision(precision) { this._base.precision = precision; }
65
76
  typecheck(formatProps) {
66
77
  this._base.loadFormatProperties(formatProps);
@@ -69,12 +80,12 @@ export class Format extends SchemaItem {
69
80
  this._base.includeZero = formatProps.composite.includeZero;
70
81
  if (undefined !== formatProps.composite.spacer) {
71
82
  if (formatProps.composite.spacer.length > 1)
72
- 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.`);
83
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Format ${this.fullName} has a composite with an invalid 'spacer' attribute. It should be an empty or one character string.`);
73
84
  this._base.spacer = formatProps.composite.spacer;
74
85
  }
75
86
  // Composite requires 1-4 units
76
87
  if (formatProps.composite.units.length <= 0 || formatProps.composite.units.length > 4)
77
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);
88
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, `The Format ${this.fullName} has an invalid 'Composite' attribute. It should have 1-4 units.`);
78
89
  }
79
90
  }
80
91
  fromJSONSync(formatProps) {
@@ -86,8 +97,11 @@ export class Format extends SchemaItem {
86
97
  for (const unit of formatProps.composite.units) {
87
98
  const newUnit = this.schema.lookupItemSync(unit.name);
88
99
  if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))
89
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
90
- this.addUnit(newUnit, unit.label);
100
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, ``);
101
+ if (Unit.isUnit(newUnit))
102
+ this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
103
+ else if (InvertedUnit.isInvertedUnit(newUnit))
104
+ this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
91
105
  }
92
106
  }
93
107
  async fromJSON(formatProps) {
@@ -99,8 +113,11 @@ export class Format extends SchemaItem {
99
113
  for (const unit of formatProps.composite.units) {
100
114
  const newUnit = await this.schema.lookupItem(unit.name);
101
115
  if (undefined === newUnit || (!Unit.isUnit(newUnit) && !InvertedUnit.isInvertedUnit(newUnit)))
102
- throw new ECObjectsError(ECObjectsStatus.InvalidECJson, ``);
103
- this.addUnit(newUnit, unit.label);
116
+ throw new ECSchemaError(ECSchemaStatus.InvalidECJson, ``);
117
+ if (Unit.isUnit(newUnit))
118
+ this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
119
+ else if (InvertedUnit.isInvertedUnit(newUnit))
120
+ this.addUnit(new DelayedPromiseWithProps(newUnit.key, async () => newUnit), unit.label);
104
121
  }
105
122
  }
106
123
  /**
@@ -179,98 +196,100 @@ export class Format extends SchemaItem {
179
196
  compositeElement.setAttribute("spacer", this.spacer);
180
197
  if (undefined !== this.includeZero)
181
198
  compositeElement.setAttribute("includeZero", this.includeZero.toString());
182
- this.units.forEach(([unit, label]) => {
199
+ for (const [unit, label] of this.units) {
200
+ const resolvedUnit = await unit;
183
201
  const unitElement = schemaXml.createElement("Unit");
184
202
  if (undefined !== label)
185
203
  unitElement.setAttribute("label", label);
186
- const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, unit.schema, unit.name);
204
+ const unitName = XmlSerializationUtils.createXmlTypedName(this.schema, resolvedUnit.schema, resolvedUnit.name);
187
205
  unitElement.textContent = unitName;
188
206
  compositeElement.appendChild(unitElement);
189
- });
207
+ }
208
+ ;
190
209
  itemElement.appendChild(compositeElement);
191
210
  }
192
211
  return itemElement;
193
212
  }
194
213
  /**
195
- * @alpha Used in schema editing.
214
+ * @internal
196
215
  */
197
216
  setFormatType(formatType) {
198
217
  this._base.type = formatType;
199
218
  }
200
219
  /**
201
- * @alpha Used in schema editing.
220
+ * @internal
202
221
  */
203
222
  setRoundFactor(roundFactor) {
204
223
  this._base.roundFactor = roundFactor;
205
224
  }
206
225
  /**
207
- * @alpha Used in schema editing.
226
+ * @internal
208
227
  */
209
228
  setShowSignOption(signOption) {
210
229
  this._base.showSignOption = signOption;
211
230
  }
212
231
  /**
213
- * @alpha Used in schema editing.
232
+ * @internal
214
233
  */
215
234
  setDecimalSeparator(separator) {
216
235
  this._base.decimalSeparator = separator;
217
236
  }
218
237
  /**
219
- * @alpha Used in schema editing.
238
+ * @internal
220
239
  */
221
240
  setThousandSeparator(separator) {
222
241
  this._base.thousandSeparator = separator;
223
242
  }
224
243
  /**
225
- * @alpha Used in schema editing.
244
+ * @internal
226
245
  */
227
246
  setUomSeparator(separator) {
228
247
  this._base.uomSeparator = separator;
229
248
  }
230
249
  /**
231
- * @alpha Used in schema editing.
250
+ * @internal
232
251
  */
233
252
  setStationSeparator(separator) {
234
253
  this._base.stationSeparator = separator;
235
254
  }
236
255
  /**
237
- * @alpha Used in schema editing.
256
+ * @internal
238
257
  */
239
258
  setStationOffsetSize(stationOffsetSize) {
240
259
  this._base.stationOffsetSize = stationOffsetSize;
241
260
  }
242
261
  /**
243
- * @alpha Used in schema editing.
262
+ * @internal
244
263
  */
245
264
  setScientificType(scientificType) {
246
265
  this._base.scientificType = scientificType;
247
266
  }
248
267
  /**
249
- * @alpha Used in schema editing.
268
+ * @internal
250
269
  */
251
270
  setMinWidth(minWidth) {
252
271
  this._base.minWidth = minWidth;
253
272
  }
254
273
  /**
255
- * @alpha Used in schema editing.
274
+ * @internal
256
275
  */
257
276
  setSpacer(spacer) {
258
277
  this._base.spacer = spacer;
259
278
  }
260
279
  /**
261
- * @alpha Used in schema editing.
280
+ * @internal
262
281
  */
263
282
  setIncludeZero(includeZero) {
264
283
  this._base.includeZero = includeZero;
265
284
  }
266
285
  /**
267
- * @alpha Used in schema editing.
286
+ * @internal
268
287
  */
269
288
  setFormatTraits(formatTraits) {
270
289
  this._base.formatTraits = formatTraits;
271
290
  }
272
291
  /**
273
- * @alpha Used in schema editing.
292
+ * @internal
274
293
  */
275
294
  setUnits(units) {
276
295
  this._units = units;
@@ -288,10 +307,11 @@ export class Format extends SchemaItem {
288
307
  * Type assertion to check if the SchemaItem is of type Format.
289
308
  * @param item The SchemaItem to check.
290
309
  * @returns The item cast to Format if it is a Format, undefined otherwise.
310
+ * @internal
291
311
  */
292
312
  static assertIsFormat(item) {
293
313
  if (!this.isFormat(item))
294
- throw new ECObjectsError(ECObjectsStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Format}' (Format)`);
314
+ throw new ECSchemaError(ECSchemaStatus.InvalidSchemaItemType, `Expected '${SchemaItemType.Format}' (Format)`);
295
315
  }
296
316
  }
297
317
  /**