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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/lib/cjs/Constants.js.map +1 -1
  3. package/lib/cjs/DelayedPromise.js.map +1 -1
  4. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  5. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  6. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  7. package/lib/cjs/Deserialization/JsonProps.d.ts +4 -0
  8. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  9. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  10. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  11. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  12. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  13. package/lib/cjs/ECName.js.map +1 -1
  14. package/lib/cjs/ECObjects.js.map +1 -1
  15. package/lib/cjs/Exception.js.map +1 -1
  16. package/lib/cjs/Interfaces.js.map +1 -1
  17. package/lib/cjs/Metadata/Class.d.ts +0 -6
  18. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  19. package/lib/cjs/Metadata/Class.js +0 -8
  20. package/lib/cjs/Metadata/Class.js.map +1 -1
  21. package/lib/cjs/Metadata/Constant.js.map +1 -1
  22. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  23. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +7 -3
  24. package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
  25. package/lib/cjs/Metadata/CustomAttributeClass.js +16 -10
  26. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  27. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  28. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  29. package/lib/cjs/Metadata/Format.js.map +1 -1
  30. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  31. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  32. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  33. package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
  34. package/lib/cjs/Metadata/OverrideFormat.js +3 -1
  35. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  36. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  37. package/lib/cjs/Metadata/Property.js.map +1 -1
  38. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  39. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  40. package/lib/cjs/Metadata/Schema.d.ts +14 -0
  41. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  42. package/lib/cjs/Metadata/Schema.js +21 -0
  43. package/lib/cjs/Metadata/Schema.js.map +1 -1
  44. package/lib/cjs/Metadata/SchemaItem.d.ts +5 -0
  45. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  46. package/lib/cjs/Metadata/SchemaItem.js +7 -0
  47. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  48. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  49. package/lib/cjs/PropertyTypes.js.map +1 -1
  50. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  51. package/lib/cjs/SchemaKey.js.map +1 -1
  52. package/lib/cjs/SchemaLoader.js.map +1 -1
  53. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  54. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  55. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  56. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  57. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  58. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  59. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  60. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  61. package/lib/cjs/ecschema-metadata.js.map +1 -1
  62. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  63. package/lib/esm/Constants.d.ts +24 -0
  64. package/lib/esm/Constants.d.ts.map +1 -0
  65. package/lib/esm/Constants.js +30 -0
  66. package/lib/esm/Constants.js.map +1 -0
  67. package/lib/esm/Context.d.ts +219 -0
  68. package/lib/esm/Context.d.ts.map +1 -0
  69. package/lib/esm/Context.js +321 -0
  70. package/lib/esm/Context.js.map +1 -0
  71. package/lib/esm/DelayedPromise.d.ts +89 -0
  72. package/lib/esm/DelayedPromise.d.ts.map +1 -0
  73. package/lib/esm/DelayedPromise.js +88 -0
  74. package/lib/esm/DelayedPromise.js.map +1 -0
  75. package/lib/esm/Deserialization/AbstractParser.d.ts +46 -0
  76. package/lib/esm/Deserialization/AbstractParser.d.ts.map +1 -0
  77. package/lib/esm/Deserialization/AbstractParser.js +8 -0
  78. package/lib/esm/Deserialization/AbstractParser.js.map +1 -0
  79. package/lib/esm/Deserialization/Helper.d.ts +263 -0
  80. package/lib/esm/Deserialization/Helper.d.ts.map +1 -0
  81. package/lib/esm/Deserialization/Helper.js +871 -0
  82. package/lib/esm/Deserialization/Helper.js.map +1 -0
  83. package/lib/esm/Deserialization/JsonParser.d.ts +166 -0
  84. package/lib/esm/Deserialization/JsonParser.d.ts.map +1 -0
  85. package/lib/esm/Deserialization/JsonParser.js +677 -0
  86. package/lib/esm/Deserialization/JsonParser.js.map +1 -0
  87. package/lib/esm/Deserialization/JsonProps.d.ts +273 -0
  88. package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -0
  89. package/lib/esm/Deserialization/JsonProps.js +9 -0
  90. package/lib/esm/Deserialization/JsonProps.js.map +1 -0
  91. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +35 -0
  92. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -0
  93. package/lib/esm/Deserialization/SchemaGraphUtil.js +74 -0
  94. package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -0
  95. package/lib/esm/Deserialization/XmlParser.d.ts +86 -0
  96. package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -0
  97. package/lib/esm/Deserialization/XmlParser.js +970 -0
  98. package/lib/esm/Deserialization/XmlParser.js.map +1 -0
  99. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +55 -0
  100. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -0
  101. package/lib/esm/Deserialization/XmlSerializationUtils.js +172 -0
  102. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -0
  103. package/lib/esm/ECName.d.ts +31 -0
  104. package/lib/esm/ECName.d.ts.map +1 -0
  105. package/lib/esm/ECName.js +82 -0
  106. package/lib/esm/ECName.js.map +1 -0
  107. package/lib/esm/ECObjects.d.ts +166 -0
  108. package/lib/esm/ECObjects.d.ts.map +1 -0
  109. package/lib/esm/ECObjects.js +422 -0
  110. package/lib/esm/ECObjects.js.map +1 -0
  111. package/lib/esm/Exception.d.ts +45 -0
  112. package/lib/esm/Exception.d.ts.map +1 -0
  113. package/lib/esm/Exception.js +82 -0
  114. package/lib/esm/Exception.js.map +1 -0
  115. package/lib/esm/Interfaces.d.ts +79 -0
  116. package/lib/esm/Interfaces.d.ts.map +1 -0
  117. package/lib/esm/Interfaces.js +9 -0
  118. package/lib/esm/Interfaces.js.map +1 -0
  119. package/lib/esm/Metadata/Class.d.ts +245 -0
  120. package/lib/esm/Metadata/Class.d.ts.map +1 -0
  121. package/lib/esm/Metadata/Class.js +552 -0
  122. package/lib/esm/Metadata/Class.js.map +1 -0
  123. package/lib/esm/Metadata/Constant.d.ts +65 -0
  124. package/lib/esm/Metadata/Constant.d.ts.map +1 -0
  125. package/lib/esm/Metadata/Constant.js +119 -0
  126. package/lib/esm/Metadata/Constant.js.map +1 -0
  127. package/lib/esm/Metadata/CustomAttribute.d.ts +24 -0
  128. package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -0
  129. package/lib/esm/Metadata/CustomAttribute.js +24 -0
  130. package/lib/esm/Metadata/CustomAttribute.js.map +1 -0
  131. package/lib/esm/Metadata/CustomAttributeClass.d.ts +44 -0
  132. package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -0
  133. package/lib/esm/Metadata/CustomAttributeClass.js +70 -0
  134. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -0
  135. package/lib/esm/Metadata/EntityClass.d.ts +78 -0
  136. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -0
  137. package/lib/esm/Metadata/EntityClass.js +224 -0
  138. package/lib/esm/Metadata/EntityClass.js.map +1 -0
  139. package/lib/esm/Metadata/Enumeration.d.ts +87 -0
  140. package/lib/esm/Metadata/Enumeration.d.ts.map +1 -0
  141. package/lib/esm/Metadata/Enumeration.js +155 -0
  142. package/lib/esm/Metadata/Enumeration.js.map +1 -0
  143. package/lib/esm/Metadata/Format.d.ts +99 -0
  144. package/lib/esm/Metadata/Format.d.ts.map +1 -0
  145. package/lib/esm/Metadata/Format.js +238 -0
  146. package/lib/esm/Metadata/Format.js.map +1 -0
  147. package/lib/esm/Metadata/InvertedUnit.d.ts +50 -0
  148. package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -0
  149. package/lib/esm/Metadata/InvertedUnit.js +93 -0
  150. package/lib/esm/Metadata/InvertedUnit.js.map +1 -0
  151. package/lib/esm/Metadata/KindOfQuantity.d.ts +72 -0
  152. package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -0
  153. package/lib/esm/Metadata/KindOfQuantity.js +229 -0
  154. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -0
  155. package/lib/esm/Metadata/Mixin.d.ts +55 -0
  156. package/lib/esm/Metadata/Mixin.d.ts.map +1 -0
  157. package/lib/esm/Metadata/Mixin.js +109 -0
  158. package/lib/esm/Metadata/Mixin.js.map +1 -0
  159. package/lib/esm/Metadata/OverrideFormat.d.ts +68 -0
  160. package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -0
  161. package/lib/esm/Metadata/OverrideFormat.js +124 -0
  162. package/lib/esm/Metadata/OverrideFormat.js.map +1 -0
  163. package/lib/esm/Metadata/Phenomenon.d.ts +34 -0
  164. package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -0
  165. package/lib/esm/Metadata/Phenomenon.js +55 -0
  166. package/lib/esm/Metadata/Phenomenon.js.map +1 -0
  167. package/lib/esm/Metadata/Property.d.ts +247 -0
  168. package/lib/esm/Metadata/Property.d.ts.map +1 -0
  169. package/lib/esm/Metadata/Property.js +565 -0
  170. package/lib/esm/Metadata/Property.js.map +1 -0
  171. package/lib/esm/Metadata/PropertyCategory.d.ts +40 -0
  172. package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -0
  173. package/lib/esm/Metadata/PropertyCategory.js +57 -0
  174. package/lib/esm/Metadata/PropertyCategory.js.map +1 -0
  175. package/lib/esm/Metadata/RelationshipClass.d.ts +170 -0
  176. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -0
  177. package/lib/esm/Metadata/RelationshipClass.js +380 -0
  178. package/lib/esm/Metadata/RelationshipClass.js.map +1 -0
  179. package/lib/esm/Metadata/Schema.d.ts +330 -0
  180. package/lib/esm/Metadata/Schema.d.ts.map +1 -0
  181. package/lib/esm/Metadata/Schema.js +570 -0
  182. package/lib/esm/Metadata/Schema.js.map +1 -0
  183. package/lib/esm/Metadata/SchemaItem.d.ts +67 -0
  184. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -0
  185. package/lib/esm/Metadata/SchemaItem.js +140 -0
  186. package/lib/esm/Metadata/SchemaItem.js.map +1 -0
  187. package/lib/esm/Metadata/Unit.d.ts +77 -0
  188. package/lib/esm/Metadata/Unit.d.ts.map +1 -0
  189. package/lib/esm/Metadata/Unit.js +158 -0
  190. package/lib/esm/Metadata/Unit.js.map +1 -0
  191. package/lib/esm/Metadata/UnitSystem.d.ts +21 -0
  192. package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -0
  193. package/lib/esm/Metadata/UnitSystem.js +25 -0
  194. package/lib/esm/Metadata/UnitSystem.js.map +1 -0
  195. package/lib/esm/PropertyTypes.d.ts +50 -0
  196. package/lib/esm/PropertyTypes.d.ts.map +1 -0
  197. package/lib/esm/PropertyTypes.js +88 -0
  198. package/lib/esm/PropertyTypes.js.map +1 -0
  199. package/lib/esm/SchemaJsonLocater.d.ts +42 -0
  200. package/lib/esm/SchemaJsonLocater.d.ts.map +1 -0
  201. package/lib/esm/SchemaJsonLocater.js +54 -0
  202. package/lib/esm/SchemaJsonLocater.js.map +1 -0
  203. package/lib/esm/SchemaKey.d.ts +111 -0
  204. package/lib/esm/SchemaKey.d.ts.map +1 -0
  205. package/lib/esm/SchemaKey.js +214 -0
  206. package/lib/esm/SchemaKey.js.map +1 -0
  207. package/lib/esm/SchemaLoader.d.ts +32 -0
  208. package/lib/esm/SchemaLoader.d.ts.map +1 -0
  209. package/lib/esm/SchemaLoader.js +53 -0
  210. package/lib/esm/SchemaLoader.js.map +1 -0
  211. package/lib/esm/SchemaPartVisitorDelegate.d.ts +275 -0
  212. package/lib/esm/SchemaPartVisitorDelegate.d.ts.map +1 -0
  213. package/lib/esm/SchemaPartVisitorDelegate.js +209 -0
  214. package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -0
  215. package/lib/esm/UnitConversion/Graph.d.ts +35 -0
  216. package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
  217. package/lib/esm/UnitConversion/Graph.js +80 -0
  218. package/lib/esm/UnitConversion/Graph.js.map +1 -0
  219. package/lib/esm/UnitConversion/Parser.d.ts +9 -0
  220. package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
  221. package/lib/esm/UnitConversion/Parser.js +39 -0
  222. package/lib/esm/UnitConversion/Parser.js.map +1 -0
  223. package/lib/esm/UnitConversion/UnitConversion.d.ts +46 -0
  224. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
  225. package/lib/esm/UnitConversion/UnitConversion.js +74 -0
  226. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
  227. package/lib/esm/UnitConversion/UnitConverter.d.ts +40 -0
  228. package/lib/esm/UnitConversion/UnitConverter.d.ts.map +1 -0
  229. package/lib/esm/UnitConversion/UnitConverter.js +113 -0
  230. package/lib/esm/UnitConversion/UnitConverter.js.map +1 -0
  231. package/lib/esm/UnitConversion/UnitTree.d.ts +44 -0
  232. package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -0
  233. package/lib/esm/UnitConversion/UnitTree.js +165 -0
  234. package/lib/esm/UnitConversion/UnitTree.js.map +1 -0
  235. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts +78 -0
  236. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
  237. package/lib/esm/UnitProvider/SchemaUnitProvider.js +231 -0
  238. package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -0
  239. package/lib/esm/Validation/SchemaWalker.d.ts +24 -0
  240. package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -0
  241. package/lib/esm/Validation/SchemaWalker.js +50 -0
  242. package/lib/esm/Validation/SchemaWalker.js.map +1 -0
  243. package/lib/esm/ecschema-metadata.d.ts +52 -0
  244. package/lib/esm/ecschema-metadata.d.ts.map +1 -0
  245. package/lib/esm/ecschema-metadata.js +55 -0
  246. package/lib/esm/ecschema-metadata.js.map +1 -0
  247. package/lib/esm/utils/SchemaGraph.d.ts +44 -0
  248. package/lib/esm/utils/SchemaGraph.d.ts.map +1 -0
  249. package/lib/esm/utils/SchemaGraph.js +111 -0
  250. package/lib/esm/utils/SchemaGraph.js.map +1 -0
  251. package/package.json +9 -7
@@ -0,0 +1,224 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Metadata
7
+ */
8
+ import { DelayedPromiseWithProps } from "../DelayedPromise";
9
+ import { XmlSerializationUtils } from "../Deserialization/XmlSerializationUtils";
10
+ import { parseStrengthDirection, SchemaItemType } from "../ECObjects";
11
+ import { ECObjectsError, ECObjectsStatus } from "../Exception";
12
+ import { ECClass } from "./Class";
13
+ import { NavigationProperty } from "./Property";
14
+ /**
15
+ * A Typescript class representation of an ECEntityClass.
16
+ * @beta
17
+ */
18
+ export class EntityClass extends ECClass {
19
+ constructor(schema, name, modifier) {
20
+ super(schema, name, modifier);
21
+ this.schemaItemType = SchemaItemType.EntityClass;
22
+ }
23
+ get mixins() {
24
+ if (!this._mixins)
25
+ return [];
26
+ return this._mixins;
27
+ }
28
+ *getMixinsSync() {
29
+ if (!this._mixins)
30
+ return function* () { }(); // empty iterable
31
+ for (const mixin of this._mixins) {
32
+ const mObj = this.schema.lookupItemSync(mixin);
33
+ if (mObj) {
34
+ yield mObj;
35
+ }
36
+ }
37
+ }
38
+ /**
39
+ *
40
+ * @param mixin
41
+ */
42
+ addMixin(mixin) {
43
+ if (!this._mixins)
44
+ this._mixins = [];
45
+ this._mixins.push(new DelayedPromiseWithProps(mixin.key, async () => mixin));
46
+ return;
47
+ }
48
+ /**
49
+ * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.
50
+ * @param name The name of the property to find.
51
+ */
52
+ async getInheritedProperty(name) {
53
+ let inheritedProperty = await super.getInheritedProperty(name);
54
+ if (!inheritedProperty && this._mixins) {
55
+ const mixinProps = await Promise.all(this._mixins.map(async (mixin) => (await mixin).getProperty(name)));
56
+ mixinProps.some((prop) => {
57
+ inheritedProperty = prop;
58
+ return inheritedProperty !== undefined;
59
+ });
60
+ }
61
+ return inheritedProperty;
62
+ }
63
+ /**
64
+ * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.
65
+ * @param name The name of the property to find.
66
+ */
67
+ getInheritedPropertySync(name) {
68
+ const inheritedProperty = super.getInheritedPropertySync(name);
69
+ if (inheritedProperty)
70
+ return inheritedProperty;
71
+ if (!this._mixins) {
72
+ return undefined;
73
+ }
74
+ for (const mixin of this._mixins) {
75
+ const mObj = this.schema.lookupItemSync(mixin);
76
+ if (mObj) {
77
+ const result = mObj.getPropertySync(name, true);
78
+ if (result) {
79
+ return result;
80
+ }
81
+ }
82
+ }
83
+ return undefined;
84
+ }
85
+ async buildPropertyCache(result, existingValues, resetBaseCaches = false) {
86
+ if (!existingValues) {
87
+ existingValues = new Map();
88
+ }
89
+ if (this.baseClass) {
90
+ ECClass.mergeProperties(result, existingValues, await (await this.baseClass).getProperties(resetBaseCaches), false);
91
+ }
92
+ for (const mixin of this.mixins) {
93
+ ECClass.mergeProperties(result, existingValues, await (await mixin).getProperties(resetBaseCaches), false);
94
+ }
95
+ if (!this.properties)
96
+ return;
97
+ ECClass.mergeProperties(result, existingValues, [...this.properties], true);
98
+ }
99
+ buildPropertyCacheSync(result, existingValues, resetBaseCaches = false) {
100
+ if (!existingValues) {
101
+ existingValues = new Map();
102
+ }
103
+ const baseClass = this.getBaseClassSync();
104
+ if (baseClass) {
105
+ ECClass.mergeProperties(result, existingValues, baseClass.getPropertiesSync(resetBaseCaches), false);
106
+ }
107
+ for (const mixin of this.getMixinsSync()) {
108
+ ECClass.mergeProperties(result, existingValues, mixin.getPropertiesSync(resetBaseCaches), false);
109
+ }
110
+ if (!this.properties)
111
+ return;
112
+ ECClass.mergeProperties(result, existingValues, [...this.properties], true);
113
+ }
114
+ /**
115
+ *
116
+ * @param name
117
+ * @param relationship
118
+ * @param direction
119
+ */
120
+ async createNavigationProperty(name, relationship, direction) {
121
+ return this.addProperty(await createNavigationProperty(this, name, relationship, direction));
122
+ }
123
+ /**
124
+ *
125
+ * @param name
126
+ * @param relationship
127
+ * @param direction
128
+ */
129
+ createNavigationPropertySync(name, relationship, direction) {
130
+ return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));
131
+ }
132
+ /**
133
+ * Save this EntityClass' properties to an object for serializing to JSON.
134
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
135
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
136
+ */
137
+ toJSON(standalone = false, includeSchemaVersion = false) {
138
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
139
+ if (this.mixins.length > 0)
140
+ schemaJson.mixins = this.mixins.map((mixin) => mixin.fullName);
141
+ return schemaJson;
142
+ }
143
+ /** @internal */
144
+ async toXml(schemaXml) {
145
+ const itemElement = await super.toXml(schemaXml);
146
+ for (const mixin of this.getMixinsSync()) {
147
+ const mixinElement = schemaXml.createElement("BaseClass");
148
+ const mixinName = XmlSerializationUtils.createXmlTypedName(this.schema, mixin.schema, mixin.name);
149
+ mixinElement.textContent = mixinName;
150
+ itemElement.appendChild(mixinElement);
151
+ }
152
+ return itemElement;
153
+ }
154
+ async fromJSON(entityClassProps) {
155
+ this.fromJSONSync(entityClassProps);
156
+ }
157
+ fromJSONSync(entityClassProps) {
158
+ super.fromJSONSync(entityClassProps);
159
+ if (undefined !== entityClassProps.mixins) {
160
+ if (!this._mixins)
161
+ this._mixins = [];
162
+ for (const name of entityClassProps.mixins) {
163
+ const mixinSchemaItemKey = this.schema.getSchemaItemKey(name);
164
+ if (!mixinSchemaItemKey)
165
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin ("${name}") that cannot be found.`);
166
+ this._mixins.push(new DelayedPromiseWithProps(mixinSchemaItemKey, async () => {
167
+ const mixin = await this.schema.lookupItem(mixinSchemaItemKey);
168
+ if (undefined === mixin)
169
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin ("${name}") that cannot be found.`);
170
+ return mixin;
171
+ }));
172
+ }
173
+ }
174
+ }
175
+ }
176
+ /**
177
+ * Hackish approach that works like a "friend class" so we can access protected members without making them public.
178
+ * @internal
179
+ */
180
+ export class MutableEntityClass extends EntityClass {
181
+ }
182
+ /** @internal */
183
+ export async function createNavigationProperty(ecClass, name, relationship, direction) {
184
+ if (await ecClass.getProperty(name))
185
+ throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);
186
+ let resolvedRelationship;
187
+ if (typeof (relationship) === "string") {
188
+ resolvedRelationship = await ecClass.schema.lookupItem(relationship);
189
+ }
190
+ else
191
+ resolvedRelationship = relationship;
192
+ if (!resolvedRelationship)
193
+ throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`); // eslint-disable-line @typescript-eslint/no-base-to-string
194
+ if (typeof (direction) === "string") {
195
+ const tmpDirection = parseStrengthDirection(direction);
196
+ if (undefined === tmpDirection)
197
+ throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);
198
+ direction = tmpDirection;
199
+ }
200
+ const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship);
201
+ return new NavigationProperty(ecClass, name, lazyRelationship, direction);
202
+ }
203
+ /** @internal */
204
+ export function createNavigationPropertySync(ecClass, name, relationship, direction) {
205
+ if (ecClass.getPropertySync(name))
206
+ throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);
207
+ let resolvedRelationship;
208
+ if (typeof (relationship) === "string") {
209
+ resolvedRelationship = ecClass.schema.lookupItemSync(relationship);
210
+ }
211
+ else
212
+ resolvedRelationship = relationship;
213
+ if (!resolvedRelationship)
214
+ throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`); // eslint-disable-line @typescript-eslint/no-base-to-string
215
+ if (typeof (direction) === "string") {
216
+ const tmpDirection = parseStrengthDirection(direction);
217
+ if (undefined === tmpDirection)
218
+ throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);
219
+ direction = tmpDirection;
220
+ }
221
+ const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship);
222
+ return new NavigationProperty(ecClass, name, lazyRelationship, direction);
223
+ }
224
+ //# sourceMappingURL=EntityClass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityClass.js","sourceRoot":"","sources":["../../../src/Metadata/EntityClass.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,EAAmB,sBAAsB,EAAE,cAAc,EAAqB,MAAM,cAAc,CAAC;AAC1G,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,EAAe,kBAAkB,EAAY,MAAM,YAAY,CAAC;AAIvE;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,OAAO;IAItC,YAAY,MAAc,EAAE,IAAY,EAAE,QAA0B;QAClE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;IACnD,CAAC;IAED,IAAW,MAAM;QACf,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,OAAO,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,CAAC,aAAa;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO;YACf,OAAO,QAAQ,CAAC,MAAuB,CAAC,EAAE,CAAC,CAAC,iBAAiB;QAE/D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAQ,KAAK,CAAC,CAAC;YACtD,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,IAAI,CAAC;YACb,CAAC;QACH,CAAC;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M,gBAAgB,GAAG,IAAI,uBAAuB,CAAC,oBAAoB,CAAC,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,oBAAqB,CAAC,CAAC;IAClH,OAAO,IAAI,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Metadata\r\n */\r\n\r\nimport { DelayedPromiseWithProps } from \"../DelayedPromise\";\r\nimport { EntityClassProps } from \"../Deserialization/JsonProps\";\r\nimport { XmlSerializationUtils } from \"../Deserialization/XmlSerializationUtils\";\r\nimport { ECClassModifier, parseStrengthDirection, SchemaItemType, StrengthDirection } from \"../ECObjects\";\r\nimport { ECObjectsError, ECObjectsStatus } from \"../Exception\";\r\nimport { LazyLoadedMixin } from \"../Interfaces\";\r\nimport { SchemaItemKey } from \"../SchemaKey\";\r\nimport { ECClass } from \"./Class\";\r\nimport { Mixin } from \"./Mixin\";\r\nimport { AnyProperty, NavigationProperty, Property } from \"./Property\";\r\nimport { RelationshipClass } from \"./RelationshipClass\";\r\nimport { Schema } from \"./Schema\";\r\n\r\n/**\r\n * A Typescript class representation of an ECEntityClass.\r\n * @beta\r\n */\r\nexport class EntityClass extends ECClass {\r\n public override readonly schemaItemType!: SchemaItemType.EntityClass; // eslint-disable-line\r\n protected _mixins?: LazyLoadedMixin[];\r\n\r\n constructor(schema: Schema, name: string, modifier?: ECClassModifier) {\r\n super(schema, name, modifier);\r\n this.schemaItemType = SchemaItemType.EntityClass;\r\n }\r\n\r\n public get mixins(): LazyLoadedMixin[] {\r\n if (!this._mixins)\r\n return [];\r\n return this._mixins;\r\n }\r\n\r\n public *getMixinsSync(): Iterable<Mixin> {\r\n if (!this._mixins)\r\n return function* (): Iterable<Mixin> { }(); // empty iterable\r\n\r\n for (const mixin of this._mixins) {\r\n const mObj = this.schema.lookupItemSync<Mixin>(mixin);\r\n if (mObj) {\r\n yield mObj;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n *\r\n * @param mixin\r\n */\r\n protected addMixin(mixin: Mixin) {\r\n if (!this._mixins)\r\n this._mixins = [];\r\n\r\n this._mixins.push(new DelayedPromiseWithProps(mixin.key, async () => mixin));\r\n return;\r\n }\r\n\r\n /**\r\n * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.\r\n * @param name The name of the property to find.\r\n */\r\n public override async getInheritedProperty(name: string): Promise<AnyProperty | undefined> {\r\n let inheritedProperty = await super.getInheritedProperty(name);\r\n\r\n if (!inheritedProperty && this._mixins) {\r\n const mixinProps = await Promise.all(this._mixins.map(async (mixin) => (await mixin).getProperty(name)));\r\n mixinProps.some((prop) => {\r\n inheritedProperty = prop as AnyProperty;\r\n return inheritedProperty !== undefined;\r\n });\r\n }\r\n\r\n return inheritedProperty as AnyProperty | undefined;\r\n }\r\n\r\n /**\r\n * Searches the base class, if one exists, first then any mixins that exist for the property with the name provided.\r\n * @param name The name of the property to find.\r\n */\r\n public override getInheritedPropertySync(name: string): Property | undefined {\r\n const inheritedProperty = super.getInheritedPropertySync(name);\r\n if (inheritedProperty)\r\n return inheritedProperty;\r\n\r\n if (!this._mixins) {\r\n return undefined;\r\n }\r\n\r\n for (const mixin of this._mixins) {\r\n const mObj = this.schema.lookupItemSync<ECClass>(mixin);\r\n if (mObj) {\r\n const result = mObj.getPropertySync(name, true);\r\n if (result) {\r\n return result;\r\n }\r\n }\r\n }\r\n\r\n return undefined;\r\n }\r\n\r\n protected override async buildPropertyCache(result: Property[], existingValues?: Map<string, number>, resetBaseCaches: boolean = false): Promise<void> {\r\n if (!existingValues) {\r\n existingValues = new Map<string, number>();\r\n }\r\n\r\n if (this.baseClass) {\r\n ECClass.mergeProperties(result, existingValues, await (await this.baseClass).getProperties(resetBaseCaches), false);\r\n }\r\n\r\n for (const mixin of this.mixins) {\r\n ECClass.mergeProperties(result, existingValues, await (await mixin).getProperties(resetBaseCaches), false);\r\n }\r\n\r\n if (!this.properties)\r\n return;\r\n\r\n ECClass.mergeProperties(result, existingValues, [...this.properties], true);\r\n }\r\n\r\n protected override buildPropertyCacheSync(result: Property[], existingValues?: Map<string, number>, resetBaseCaches: boolean = false): void {\r\n if (!existingValues) {\r\n existingValues = new Map<string, number>();\r\n }\r\n\r\n const baseClass = this.getBaseClassSync();\r\n if (baseClass) {\r\n ECClass.mergeProperties(result, existingValues, baseClass.getPropertiesSync(resetBaseCaches), false);\r\n }\r\n\r\n for (const mixin of this.getMixinsSync()) {\r\n ECClass.mergeProperties(result, existingValues, mixin.getPropertiesSync(resetBaseCaches), false);\r\n }\r\n\r\n if (!this.properties)\r\n return;\r\n\r\n ECClass.mergeProperties(result, existingValues, [...this.properties], true);\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param relationship\r\n * @param direction\r\n */\r\n protected async createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\r\n return this.addProperty(await createNavigationProperty(this, name, relationship, direction));\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param relationship\r\n * @param direction\r\n */\r\n protected createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\r\n return this.addProperty(createNavigationPropertySync(this, name, relationship, direction));\r\n }\r\n\r\n /**\r\n * Save this EntityClass' properties to an object for serializing to JSON.\r\n * @param standalone Serialization includes only this object (as opposed to the full schema).\r\n * @param includeSchemaVersion Include the Schema's version information in the serialized object.\r\n */\r\n public override toJSON(standalone: boolean = false, includeSchemaVersion: boolean = false): EntityClassProps {\r\n const schemaJson = super.toJSON(standalone, includeSchemaVersion) as any;\r\n if (this.mixins.length > 0)\r\n schemaJson.mixins = this.mixins.map((mixin) => mixin.fullName);\r\n return schemaJson;\r\n }\r\n\r\n /** @internal */\r\n public override async toXml(schemaXml: Document): Promise<Element> {\r\n const itemElement = await super.toXml(schemaXml);\r\n\r\n for (const mixin of this.getMixinsSync()) {\r\n const mixinElement = schemaXml.createElement(\"BaseClass\");\r\n const mixinName = XmlSerializationUtils.createXmlTypedName(this.schema, mixin.schema, mixin.name);\r\n mixinElement.textContent = mixinName;\r\n itemElement.appendChild(mixinElement);\r\n }\r\n return itemElement;\r\n }\r\n\r\n public override async fromJSON(entityClassProps: EntityClassProps) {\r\n this.fromJSONSync(entityClassProps);\r\n }\r\n\r\n public override fromJSONSync(entityClassProps: EntityClassProps) {\r\n super.fromJSONSync(entityClassProps);\r\n\r\n if (undefined !== entityClassProps.mixins) {\r\n if (!this._mixins)\r\n this._mixins = [];\r\n for (const name of entityClassProps.mixins) {\r\n const mixinSchemaItemKey = this.schema.getSchemaItemKey(name);\r\n if (!mixinSchemaItemKey)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin (\"${name}\") that cannot be found.`);\r\n this._mixins.push(new DelayedPromiseWithProps<SchemaItemKey, Mixin>(mixinSchemaItemKey,\r\n async () => {\r\n const mixin = await this.schema.lookupItem<Mixin>(mixinSchemaItemKey);\r\n if (undefined === mixin)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The ECEntityClass ${this.name} has a mixin (\"${name}\") that cannot be found.`);\r\n return mixin;\r\n }));\r\n }\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Hackish approach that works like a \"friend class\" so we can access protected members without making them public.\r\n * @internal\r\n */\r\nexport abstract class MutableEntityClass extends EntityClass {\r\n public abstract override addMixin(mixin: Mixin): any;\r\n public abstract override createNavigationProperty(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty>;\r\n public abstract override createNavigationPropertySync(name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty;\r\n public abstract override setDisplayLabel(displayLabel: string): void;\r\n}\r\n\r\n/** @internal */\r\nexport async function createNavigationProperty(ecClass: ECClass, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): Promise<NavigationProperty> {\r\n if (await ecClass.getProperty(name))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);\r\n\r\n let resolvedRelationship: RelationshipClass | undefined;\r\n if (typeof (relationship) === \"string\") {\r\n resolvedRelationship = await ecClass.schema.lookupItem<RelationshipClass>(relationship);\r\n } else\r\n resolvedRelationship = relationship;\r\n\r\n if (!resolvedRelationship)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`); // eslint-disable-line @typescript-eslint/no-base-to-string\r\n\r\n if (typeof (direction) === \"string\") {\r\n const tmpDirection = parseStrengthDirection(direction);\r\n if (undefined === tmpDirection)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);\r\n direction = tmpDirection;\r\n }\r\n\r\n const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship!);\r\n return new NavigationProperty(ecClass, name, lazyRelationship, direction);\r\n}\r\n\r\n/** @internal */\r\nexport function createNavigationPropertySync(ecClass: ECClass, name: string, relationship: string | RelationshipClass, direction: string | StrengthDirection): NavigationProperty {\r\n if (ecClass.getPropertySync(name))\r\n throw new ECObjectsError(ECObjectsStatus.DuplicateProperty, `An ECProperty with the name ${name} already exists in the class ${ecClass.name}.`);\r\n\r\n let resolvedRelationship: RelationshipClass | undefined;\r\n if (typeof (relationship) === \"string\") {\r\n resolvedRelationship = ecClass.schema.lookupItemSync<RelationshipClass>(relationship);\r\n } else\r\n resolvedRelationship = relationship;\r\n\r\n if (!resolvedRelationship)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidType, `The provided RelationshipClass, ${relationship}, is not a valid RelationshipClassInterface.`); // eslint-disable-line @typescript-eslint/no-base-to-string\r\n\r\n if (typeof (direction) === \"string\") {\r\n const tmpDirection = parseStrengthDirection(direction);\r\n if (undefined === tmpDirection)\r\n throw new ECObjectsError(ECObjectsStatus.InvalidStrengthDirection, `The provided StrengthDirection, ${direction}, is not a valid StrengthDirection.`);\r\n direction = tmpDirection;\r\n }\r\n\r\n const lazyRelationship = new DelayedPromiseWithProps(resolvedRelationship.key, async () => resolvedRelationship!);\r\n return new NavigationProperty(ecClass, name, lazyRelationship, direction);\r\n}\r\n"]}
@@ -0,0 +1,87 @@
1
+ /** @packageDocumentation
2
+ * @module Metadata
3
+ */
4
+ import { EnumerationProps } from "../Deserialization/JsonProps";
5
+ import { PrimitiveType, SchemaItemType } from "../ECObjects";
6
+ import { Schema } from "./Schema";
7
+ import { SchemaItem } from "./SchemaItem";
8
+ /** @beta */
9
+ export interface Enumerator<T> {
10
+ readonly name: string;
11
+ readonly value: T;
12
+ readonly label?: string;
13
+ readonly description?: string;
14
+ }
15
+ /** @beta */
16
+ export type AnyEnumerator = Enumerator<string | number>;
17
+ /**
18
+ * A Typescript class representation of an ECEnumeration.
19
+ * @beta
20
+ */
21
+ export declare class Enumeration extends SchemaItem {
22
+ readonly schemaItemType: SchemaItemType.Enumeration;
23
+ protected _type?: PrimitiveType.Integer | PrimitiveType.String;
24
+ protected _isStrict: boolean;
25
+ protected _enumerators: AnyEnumerator[];
26
+ get enumerators(): AnyEnumerator[];
27
+ get type(): PrimitiveType.Integer | PrimitiveType.String | undefined;
28
+ get isStrict(): boolean;
29
+ constructor(schema: Schema, name: string, primitiveType?: PrimitiveType.Integer | PrimitiveType.String);
30
+ get isInt(): boolean;
31
+ get isString(): boolean;
32
+ /**
33
+ * Gets an enumerator that matches the name provided.
34
+ * @param name The ECName of the Enumerator to find.
35
+ */
36
+ getEnumeratorByName(name: string): AnyEnumerator | undefined;
37
+ /**
38
+ * Gets an enumerator that matches the value provided.
39
+ * @param value The value of the Enumerator to find.
40
+ */
41
+ getEnumerator(value: string): Enumerator<string> | undefined;
42
+ getEnumerator(value: number): Enumerator<number> | undefined;
43
+ /**
44
+ * Checks whether there already exists an enumerator with this name or this value
45
+ * @param name The name of the enumerator we are trying to create
46
+ * @param value The value of the enumerator we are trying to create
47
+ * @internal
48
+ */
49
+ private findDuplicateEnumerators;
50
+ /**
51
+ * Creates an Enumerator with the provided name and value as well as optional parameters label and description
52
+ * @param name The name of the enumerator
53
+ * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
54
+ * @param label A localized display label that is used instead of the name in a GUI.
55
+ * @param description A localized description for the enumerator.
56
+ * @return AnyEnumerator object
57
+ */
58
+ createEnumerator(name: string, value: string | number, label?: string, description?: string): AnyEnumerator;
59
+ /**
60
+ * Adds enumerator to list of enumerators on this Enumeration
61
+ * @param enumerator The enumerator to add
62
+ */
63
+ protected addEnumerator(enumerator: AnyEnumerator): void;
64
+ /**
65
+ * Save this Enumeration's properties to an object for serializing to JSON.
66
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
67
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
68
+ */
69
+ toJSON(standalone?: boolean, includeSchemaVersion?: boolean): EnumerationProps;
70
+ /** @internal */
71
+ toXml(schemaXml: Document): Promise<Element>;
72
+ fromJSONSync(enumerationProps: EnumerationProps): void;
73
+ fromJSON(enumerationProps: EnumerationProps): Promise<void>;
74
+ /**
75
+ * @alpha Used in schema editing.
76
+ */
77
+ protected setIsStrict(isStrict: boolean): void;
78
+ }
79
+ /** @internal
80
+ * An abstract class used for schema editing.
81
+ */
82
+ export declare abstract class MutableEnumeration extends Enumeration {
83
+ abstract addEnumerator(enumerator: AnyEnumerator): void;
84
+ abstract setIsStrict(isStrict: boolean): void;
85
+ abstract setDisplayLabel(displayLabel: string): void;
86
+ }
87
+ //# sourceMappingURL=Enumeration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Enumeration.d.ts","sourceRoot":"","sources":["../../../src/Metadata/Enumeration.ts"],"names":[],"mappings":"AAIA;;GAEG;AA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,CAAC,GAAG,SAAS;IAC5D,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,SAAS;IAKnE;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAShC;;;;;;;OAOG;IACI,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,aAAa;IAWlH;;;OAGG;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;IAyBzC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB;IAIjE;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO;CAIxC;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"}
@@ -0,0 +1,155 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Metadata
7
+ */
8
+ import { PrimitiveType, primitiveTypeToString, SchemaItemType } from "../ECObjects";
9
+ import { ECObjectsError, ECObjectsStatus } from "../Exception";
10
+ import { ECName } from "../ECName";
11
+ import { SchemaItem } from "./SchemaItem";
12
+ /**
13
+ * A Typescript class representation of an ECEnumeration.
14
+ * @beta
15
+ */
16
+ export class Enumeration extends SchemaItem {
17
+ get enumerators() { return this._enumerators; }
18
+ get type() { return this._type; }
19
+ get isStrict() { return this._isStrict; }
20
+ constructor(schema, name, primitiveType) {
21
+ super(schema, name);
22
+ this.schemaItemType = SchemaItemType.Enumeration;
23
+ this._type = primitiveType;
24
+ this._isStrict = true;
25
+ this._enumerators = [];
26
+ }
27
+ get isInt() { return this._type === PrimitiveType.Integer; }
28
+ get isString() { return this._type === PrimitiveType.String; }
29
+ /**
30
+ * Gets an enumerator that matches the name provided.
31
+ * @param name The ECName of the Enumerator to find.
32
+ */
33
+ getEnumeratorByName(name) {
34
+ return this.enumerators.find((item) => item.name.toLowerCase() === name.toLowerCase());
35
+ }
36
+ getEnumerator(value) {
37
+ return this.enumerators.find((item) => item.value === value);
38
+ }
39
+ /**
40
+ * Checks whether there already exists an enumerator with this name or this value
41
+ * @param name The name of the enumerator we are trying to create
42
+ * @param value The value of the enumerator we are trying to create
43
+ * @internal
44
+ */
45
+ findDuplicateEnumerators(name, value) {
46
+ this._enumerators.forEach((element) => {
47
+ if (element.name.toLowerCase() === name.toLowerCase())
48
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with name '${name}'.`);
49
+ if (element.value === value)
50
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a duplicate Enumerator with value '${value}'.`);
51
+ });
52
+ }
53
+ /**
54
+ * Creates an Enumerator with the provided name and value as well as optional parameters label and description
55
+ * @param name The name of the enumerator
56
+ * @param value The value of the enumerator. The type of this value is dependent on the backing type of the this Enumeration.
57
+ * @param label A localized display label that is used instead of the name in a GUI.
58
+ * @param description A localized description for the enumerator.
59
+ * @return AnyEnumerator object
60
+ */
61
+ createEnumerator(name, value, label, description) {
62
+ if (this.isInt && typeof (value) === "string") // throws if backing type is int and value is string
63
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'integer' and an enumerator with value of type 'string'.`);
64
+ if (!this.isInt && typeof (value) === "number") // also throws if backing type is string and value is number
65
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has a backing type 'string' and an enumerator with value of type 'integer'.`);
66
+ this.findDuplicateEnumerators(name, value); // check for duplicates; throw if there are any
67
+ if (!ECName.validate(name))
68
+ throw new ECObjectsError(ECObjectsStatus.InvalidECName, `The Enumeration ${this.name} has an enumerator with an invalid 'name' attribute. ${name} is not a valid ECName.`);
69
+ return { name, value, label, description };
70
+ }
71
+ /**
72
+ * Adds enumerator to list of enumerators on this Enumeration
73
+ * @param enumerator The enumerator to add
74
+ */
75
+ addEnumerator(enumerator) {
76
+ this.enumerators.push(enumerator);
77
+ }
78
+ /**
79
+ * Save this Enumeration's properties to an object for serializing to JSON.
80
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
81
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
82
+ */
83
+ toJSON(standalone = false, includeSchemaVersion = false) {
84
+ const schemaJson = super.toJSON(standalone, includeSchemaVersion);
85
+ schemaJson.type = (this.isInt) ? "int" : "string";
86
+ schemaJson.isStrict = this.isStrict;
87
+ schemaJson.enumerators = this._enumerators.map(({ name, label, value, description }) => {
88
+ const enumJson = { name, value };
89
+ if (undefined !== label)
90
+ enumJson.label = label;
91
+ if (undefined !== description)
92
+ enumJson.description = description;
93
+ return enumJson;
94
+ });
95
+ return schemaJson;
96
+ }
97
+ /** @internal */
98
+ async toXml(schemaXml) {
99
+ const itemElement = await super.toXml(schemaXml);
100
+ if (undefined !== this.type)
101
+ itemElement.setAttribute("backingTypeName", primitiveTypeToString(this.type));
102
+ itemElement.setAttribute("isStrict", String(this.isStrict));
103
+ for (const enumerator of this.enumerators) {
104
+ const enumElement = schemaXml.createElement("ECEnumerator");
105
+ enumElement.setAttribute("name", enumerator.name);
106
+ const enumValue = typeof enumerator.value === "string" ? enumerator.value : enumerator.value.toString();
107
+ enumElement.setAttribute("value", enumValue);
108
+ if (undefined !== enumerator.label)
109
+ enumElement.setAttribute("displayLabel", enumerator.label);
110
+ if (undefined !== enumerator.description)
111
+ enumElement.setAttribute("description", enumerator.description);
112
+ itemElement.appendChild(enumElement);
113
+ }
114
+ return itemElement;
115
+ }
116
+ fromJSONSync(enumerationProps) {
117
+ super.fromJSONSync(enumerationProps);
118
+ if (undefined === this._type) {
119
+ if (/int/i.test(enumerationProps.type))
120
+ this._type = PrimitiveType.Integer;
121
+ else if (/string/i.test(enumerationProps.type))
122
+ this._type = PrimitiveType.String;
123
+ else
124
+ throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either "int" or "string".`);
125
+ }
126
+ else {
127
+ const primitiveTypePattern = (this.isInt) ? /int/i : /string/i;
128
+ if (!primitiveTypePattern.test(enumerationProps.type))
129
+ 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"}".`);
130
+ }
131
+ this._isStrict = enumerationProps.isStrict;
132
+ if (undefined !== enumerationProps.enumerators) {
133
+ enumerationProps.enumerators.forEach((enumerator) => {
134
+ // Creates a new enumerator (with the specified name, value, label and description- label and description are optional) and adds to the list of enumerators.
135
+ // Throws ECObjectsError if there are duplicate names or values present in the enumeration
136
+ this.addEnumerator(this.createEnumerator(enumerator.name, enumerator.value, enumerator.label, enumerator.description));
137
+ });
138
+ }
139
+ }
140
+ async fromJSON(enumerationProps) {
141
+ this.fromJSONSync(enumerationProps);
142
+ }
143
+ /**
144
+ * @alpha Used in schema editing.
145
+ */
146
+ setIsStrict(isStrict) {
147
+ this._isStrict = isStrict;
148
+ }
149
+ }
150
+ /** @internal
151
+ * An abstract class used for schema editing.
152
+ */
153
+ export class MutableEnumeration extends Enumeration {
154
+ }
155
+ //# sourceMappingURL=Enumeration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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 { 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; // eslint-disable-line\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 throw new ECObjectsError(ECObjectsStatus.InvalidECJson, `The Enumeration ${this.name} has an invalid 'type' attribute. It should be either \"int\" or \"string\".`);\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"]}
@@ -0,0 +1,99 @@
1
+ /** @packageDocumentation
2
+ * @module Metadata
3
+ */
4
+ import { SchemaItemFormatProps } from "../Deserialization/JsonProps";
5
+ import { SchemaItemType } from "../ECObjects";
6
+ import { BaseFormat, DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, ScientificType, ShowSignOption } from "@itwin/core-quantity";
7
+ import { InvertedUnit } from "./InvertedUnit";
8
+ import { Schema } from "./Schema";
9
+ import { SchemaItem } from "./SchemaItem";
10
+ import { Unit } from "./Unit";
11
+ /**
12
+ * @beta
13
+ */
14
+ export declare class Format extends SchemaItem {
15
+ readonly schemaItemType: SchemaItemType.Format;
16
+ protected _base: BaseFormat;
17
+ protected _units?: Array<[Unit | InvertedUnit, string | undefined]>;
18
+ constructor(schema: Schema, name: string);
19
+ get roundFactor(): number;
20
+ get type(): FormatType;
21
+ get precision(): DecimalPrecision | FractionalPrecision;
22
+ get minWidth(): number | undefined;
23
+ get scientificType(): ScientificType | undefined;
24
+ get showSignOption(): ShowSignOption;
25
+ get decimalSeparator(): string;
26
+ get thousandSeparator(): string;
27
+ get uomSeparator(): string;
28
+ get stationSeparator(): string;
29
+ get stationOffsetSize(): number | undefined;
30
+ get formatTraits(): FormatTraits;
31
+ get spacer(): string | undefined;
32
+ get includeZero(): boolean | undefined;
33
+ get units(): Array<[Unit | InvertedUnit, string | undefined]> | undefined;
34
+ private parseFormatTraits;
35
+ hasFormatTrait(formatTrait: FormatTraits): boolean;
36
+ /**
37
+ * Adds a Unit, or InvertedUnit, with an optional label override.
38
+ * @param unit The Unit, or InvertedUnit, to add to this Format.
39
+ * @param label A label that overrides the label defined within the Unit when a value is formatted.
40
+ */
41
+ protected addUnit(unit: Unit | InvertedUnit, label?: string): void;
42
+ protected setPrecision(precision: number): void;
43
+ private typecheck;
44
+ fromJSONSync(formatProps: SchemaItemFormatProps): void;
45
+ fromJSON(formatProps: SchemaItemFormatProps): Promise<void>;
46
+ /**
47
+ * Save this Format's properties to an object for serializing to JSON.
48
+ * @param standalone Serialization includes only this object (as opposed to the full schema).
49
+ * @param includeSchemaVersion Include the Schema's version information in the serialized object.
50
+ */
51
+ toJSON(standalone?: boolean, includeSchemaVersion?: boolean): SchemaItemFormatProps;
52
+ /** @internal */
53
+ toXml(schemaXml: Document): Promise<Element>;
54
+ /**
55
+ * @alpha Used in schema editing.
56
+ */
57
+ protected setFormatType(formatType: FormatType): void;
58
+ /**
59
+ * @alpha Used in schema editing.
60
+ */
61
+ protected setRoundFactor(roundFactor: number): void;
62
+ /**
63
+ * @alpha Used in schema editing.
64
+ */
65
+ protected setShowSignOption(signOption: ShowSignOption): void;
66
+ /**
67
+ * @alpha Used in schema editing.
68
+ */
69
+ protected setDecimalSeparator(separator: string): void;
70
+ /**
71
+ * @alpha Used in schema editing.
72
+ */
73
+ protected setThousandSeparator(separator: string): void;
74
+ /**
75
+ * @alpha Used in schema editing.
76
+ */
77
+ protected setUomSeparator(separator: string): void;
78
+ /**
79
+ * @alpha Used in schema editing.
80
+ */
81
+ protected setStationSeparator(separator: string): void;
82
+ }
83
+ /**
84
+ * @internal
85
+ * An abstract class used for schema editing.
86
+ */
87
+ export declare abstract class MutableFormat extends Format {
88
+ abstract addUnit(unit: Unit | InvertedUnit, label?: string): void;
89
+ abstract setPrecision(precision: number): void;
90
+ abstract setFormatType(formatType: FormatType): void;
91
+ abstract setRoundFactor(roundFactor: number): void;
92
+ abstract setShowSignOption(signOption: ShowSignOption): void;
93
+ abstract setDecimalSeparator(separator: string): void;
94
+ abstract setThousandSeparator(separator: string): void;
95
+ abstract setUomSeparator(separator: string): void;
96
+ abstract setStationSeparator(separator: string): void;
97
+ abstract setDisplayLabel(displayLabel: string): void;
98
+ }
99
+ //# sourceMappingURL=Format.d.ts.map