@itwin/ecschema-metadata 4.8.0-dev.3 → 4.8.0-dev.32

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 (215) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/Deserialization/JsonProps.d.ts +4 -0
  3. package/lib/cjs/Deserialization/JsonProps.d.ts.map +1 -1
  4. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  5. package/lib/cjs/Metadata/Class.d.ts +0 -6
  6. package/lib/cjs/Metadata/Class.d.ts.map +1 -1
  7. package/lib/cjs/Metadata/Class.js +0 -8
  8. package/lib/cjs/Metadata/Class.js.map +1 -1
  9. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +7 -3
  10. package/lib/cjs/Metadata/CustomAttributeClass.d.ts.map +1 -1
  11. package/lib/cjs/Metadata/CustomAttributeClass.js +16 -10
  12. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  13. package/lib/cjs/Metadata/OverrideFormat.d.ts.map +1 -1
  14. package/lib/cjs/Metadata/OverrideFormat.js +3 -1
  15. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  16. package/lib/cjs/Metadata/Schema.d.ts +14 -0
  17. package/lib/cjs/Metadata/Schema.d.ts.map +1 -1
  18. package/lib/cjs/Metadata/Schema.js +21 -0
  19. package/lib/cjs/Metadata/Schema.js.map +1 -1
  20. package/lib/cjs/Metadata/SchemaItem.d.ts +5 -0
  21. package/lib/cjs/Metadata/SchemaItem.d.ts.map +1 -1
  22. package/lib/cjs/Metadata/SchemaItem.js +7 -0
  23. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  24. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +1 -1
  25. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +1 -1
  26. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  27. package/lib/esm/Constants.d.ts +24 -0
  28. package/lib/esm/Constants.d.ts.map +1 -0
  29. package/lib/esm/Constants.js +30 -0
  30. package/lib/esm/Constants.js.map +1 -0
  31. package/lib/esm/Context.d.ts +219 -0
  32. package/lib/esm/Context.d.ts.map +1 -0
  33. package/lib/esm/Context.js +321 -0
  34. package/lib/esm/Context.js.map +1 -0
  35. package/lib/esm/DelayedPromise.d.ts +89 -0
  36. package/lib/esm/DelayedPromise.d.ts.map +1 -0
  37. package/lib/esm/DelayedPromise.js +88 -0
  38. package/lib/esm/DelayedPromise.js.map +1 -0
  39. package/lib/esm/Deserialization/AbstractParser.d.ts +46 -0
  40. package/lib/esm/Deserialization/AbstractParser.d.ts.map +1 -0
  41. package/lib/esm/Deserialization/AbstractParser.js +8 -0
  42. package/lib/esm/Deserialization/AbstractParser.js.map +1 -0
  43. package/lib/esm/Deserialization/Helper.d.ts +263 -0
  44. package/lib/esm/Deserialization/Helper.d.ts.map +1 -0
  45. package/lib/esm/Deserialization/Helper.js +871 -0
  46. package/lib/esm/Deserialization/Helper.js.map +1 -0
  47. package/lib/esm/Deserialization/JsonParser.d.ts +166 -0
  48. package/lib/esm/Deserialization/JsonParser.d.ts.map +1 -0
  49. package/lib/esm/Deserialization/JsonParser.js +677 -0
  50. package/lib/esm/Deserialization/JsonParser.js.map +1 -0
  51. package/lib/esm/Deserialization/JsonProps.d.ts +273 -0
  52. package/lib/esm/Deserialization/JsonProps.d.ts.map +1 -0
  53. package/lib/esm/Deserialization/JsonProps.js +9 -0
  54. package/lib/esm/Deserialization/JsonProps.js.map +1 -0
  55. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts +35 -0
  56. package/lib/esm/Deserialization/SchemaGraphUtil.d.ts.map +1 -0
  57. package/lib/esm/Deserialization/SchemaGraphUtil.js +74 -0
  58. package/lib/esm/Deserialization/SchemaGraphUtil.js.map +1 -0
  59. package/lib/esm/Deserialization/XmlParser.d.ts +86 -0
  60. package/lib/esm/Deserialization/XmlParser.d.ts.map +1 -0
  61. package/lib/esm/Deserialization/XmlParser.js +970 -0
  62. package/lib/esm/Deserialization/XmlParser.js.map +1 -0
  63. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts +55 -0
  64. package/lib/esm/Deserialization/XmlSerializationUtils.d.ts.map +1 -0
  65. package/lib/esm/Deserialization/XmlSerializationUtils.js +172 -0
  66. package/lib/esm/Deserialization/XmlSerializationUtils.js.map +1 -0
  67. package/lib/esm/ECName.d.ts +31 -0
  68. package/lib/esm/ECName.d.ts.map +1 -0
  69. package/lib/esm/ECName.js +82 -0
  70. package/lib/esm/ECName.js.map +1 -0
  71. package/lib/esm/ECObjects.d.ts +166 -0
  72. package/lib/esm/ECObjects.d.ts.map +1 -0
  73. package/lib/esm/ECObjects.js +422 -0
  74. package/lib/esm/ECObjects.js.map +1 -0
  75. package/lib/esm/Exception.d.ts +45 -0
  76. package/lib/esm/Exception.d.ts.map +1 -0
  77. package/lib/esm/Exception.js +82 -0
  78. package/lib/esm/Exception.js.map +1 -0
  79. package/lib/esm/Interfaces.d.ts +79 -0
  80. package/lib/esm/Interfaces.d.ts.map +1 -0
  81. package/lib/esm/Interfaces.js +9 -0
  82. package/lib/esm/Interfaces.js.map +1 -0
  83. package/lib/esm/Metadata/Class.d.ts +245 -0
  84. package/lib/esm/Metadata/Class.d.ts.map +1 -0
  85. package/lib/esm/Metadata/Class.js +552 -0
  86. package/lib/esm/Metadata/Class.js.map +1 -0
  87. package/lib/esm/Metadata/Constant.d.ts +65 -0
  88. package/lib/esm/Metadata/Constant.d.ts.map +1 -0
  89. package/lib/esm/Metadata/Constant.js +119 -0
  90. package/lib/esm/Metadata/Constant.js.map +1 -0
  91. package/lib/esm/Metadata/CustomAttribute.d.ts +24 -0
  92. package/lib/esm/Metadata/CustomAttribute.d.ts.map +1 -0
  93. package/lib/esm/Metadata/CustomAttribute.js +24 -0
  94. package/lib/esm/Metadata/CustomAttribute.js.map +1 -0
  95. package/lib/esm/Metadata/CustomAttributeClass.d.ts +44 -0
  96. package/lib/esm/Metadata/CustomAttributeClass.d.ts.map +1 -0
  97. package/lib/esm/Metadata/CustomAttributeClass.js +70 -0
  98. package/lib/esm/Metadata/CustomAttributeClass.js.map +1 -0
  99. package/lib/esm/Metadata/EntityClass.d.ts +78 -0
  100. package/lib/esm/Metadata/EntityClass.d.ts.map +1 -0
  101. package/lib/esm/Metadata/EntityClass.js +224 -0
  102. package/lib/esm/Metadata/EntityClass.js.map +1 -0
  103. package/lib/esm/Metadata/Enumeration.d.ts +87 -0
  104. package/lib/esm/Metadata/Enumeration.d.ts.map +1 -0
  105. package/lib/esm/Metadata/Enumeration.js +155 -0
  106. package/lib/esm/Metadata/Enumeration.js.map +1 -0
  107. package/lib/esm/Metadata/Format.d.ts +99 -0
  108. package/lib/esm/Metadata/Format.d.ts.map +1 -0
  109. package/lib/esm/Metadata/Format.js +238 -0
  110. package/lib/esm/Metadata/Format.js.map +1 -0
  111. package/lib/esm/Metadata/InvertedUnit.d.ts +50 -0
  112. package/lib/esm/Metadata/InvertedUnit.d.ts.map +1 -0
  113. package/lib/esm/Metadata/InvertedUnit.js +93 -0
  114. package/lib/esm/Metadata/InvertedUnit.js.map +1 -0
  115. package/lib/esm/Metadata/KindOfQuantity.d.ts +72 -0
  116. package/lib/esm/Metadata/KindOfQuantity.d.ts.map +1 -0
  117. package/lib/esm/Metadata/KindOfQuantity.js +229 -0
  118. package/lib/esm/Metadata/KindOfQuantity.js.map +1 -0
  119. package/lib/esm/Metadata/Mixin.d.ts +55 -0
  120. package/lib/esm/Metadata/Mixin.d.ts.map +1 -0
  121. package/lib/esm/Metadata/Mixin.js +109 -0
  122. package/lib/esm/Metadata/Mixin.js.map +1 -0
  123. package/lib/esm/Metadata/OverrideFormat.d.ts +68 -0
  124. package/lib/esm/Metadata/OverrideFormat.d.ts.map +1 -0
  125. package/lib/esm/Metadata/OverrideFormat.js +124 -0
  126. package/lib/esm/Metadata/OverrideFormat.js.map +1 -0
  127. package/lib/esm/Metadata/Phenomenon.d.ts +34 -0
  128. package/lib/esm/Metadata/Phenomenon.d.ts.map +1 -0
  129. package/lib/esm/Metadata/Phenomenon.js +55 -0
  130. package/lib/esm/Metadata/Phenomenon.js.map +1 -0
  131. package/lib/esm/Metadata/Property.d.ts +247 -0
  132. package/lib/esm/Metadata/Property.d.ts.map +1 -0
  133. package/lib/esm/Metadata/Property.js +565 -0
  134. package/lib/esm/Metadata/Property.js.map +1 -0
  135. package/lib/esm/Metadata/PropertyCategory.d.ts +40 -0
  136. package/lib/esm/Metadata/PropertyCategory.d.ts.map +1 -0
  137. package/lib/esm/Metadata/PropertyCategory.js +57 -0
  138. package/lib/esm/Metadata/PropertyCategory.js.map +1 -0
  139. package/lib/esm/Metadata/RelationshipClass.d.ts +170 -0
  140. package/lib/esm/Metadata/RelationshipClass.d.ts.map +1 -0
  141. package/lib/esm/Metadata/RelationshipClass.js +380 -0
  142. package/lib/esm/Metadata/RelationshipClass.js.map +1 -0
  143. package/lib/esm/Metadata/Schema.d.ts +330 -0
  144. package/lib/esm/Metadata/Schema.d.ts.map +1 -0
  145. package/lib/esm/Metadata/Schema.js +570 -0
  146. package/lib/esm/Metadata/Schema.js.map +1 -0
  147. package/lib/esm/Metadata/SchemaItem.d.ts +67 -0
  148. package/lib/esm/Metadata/SchemaItem.d.ts.map +1 -0
  149. package/lib/esm/Metadata/SchemaItem.js +140 -0
  150. package/lib/esm/Metadata/SchemaItem.js.map +1 -0
  151. package/lib/esm/Metadata/Unit.d.ts +77 -0
  152. package/lib/esm/Metadata/Unit.d.ts.map +1 -0
  153. package/lib/esm/Metadata/Unit.js +158 -0
  154. package/lib/esm/Metadata/Unit.js.map +1 -0
  155. package/lib/esm/Metadata/UnitSystem.d.ts +21 -0
  156. package/lib/esm/Metadata/UnitSystem.d.ts.map +1 -0
  157. package/lib/esm/Metadata/UnitSystem.js +25 -0
  158. package/lib/esm/Metadata/UnitSystem.js.map +1 -0
  159. package/lib/esm/PropertyTypes.d.ts +50 -0
  160. package/lib/esm/PropertyTypes.d.ts.map +1 -0
  161. package/lib/esm/PropertyTypes.js +88 -0
  162. package/lib/esm/PropertyTypes.js.map +1 -0
  163. package/lib/esm/SchemaJsonLocater.d.ts +42 -0
  164. package/lib/esm/SchemaJsonLocater.d.ts.map +1 -0
  165. package/lib/esm/SchemaJsonLocater.js +54 -0
  166. package/lib/esm/SchemaJsonLocater.js.map +1 -0
  167. package/lib/esm/SchemaKey.d.ts +111 -0
  168. package/lib/esm/SchemaKey.d.ts.map +1 -0
  169. package/lib/esm/SchemaKey.js +214 -0
  170. package/lib/esm/SchemaKey.js.map +1 -0
  171. package/lib/esm/SchemaLoader.d.ts +32 -0
  172. package/lib/esm/SchemaLoader.d.ts.map +1 -0
  173. package/lib/esm/SchemaLoader.js +53 -0
  174. package/lib/esm/SchemaLoader.js.map +1 -0
  175. package/lib/esm/SchemaPartVisitorDelegate.d.ts +275 -0
  176. package/lib/esm/SchemaPartVisitorDelegate.d.ts.map +1 -0
  177. package/lib/esm/SchemaPartVisitorDelegate.js +209 -0
  178. package/lib/esm/SchemaPartVisitorDelegate.js.map +1 -0
  179. package/lib/esm/UnitConversion/Graph.d.ts +35 -0
  180. package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
  181. package/lib/esm/UnitConversion/Graph.js +80 -0
  182. package/lib/esm/UnitConversion/Graph.js.map +1 -0
  183. package/lib/esm/UnitConversion/Parser.d.ts +9 -0
  184. package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
  185. package/lib/esm/UnitConversion/Parser.js +39 -0
  186. package/lib/esm/UnitConversion/Parser.js.map +1 -0
  187. package/lib/esm/UnitConversion/UnitConversion.d.ts +46 -0
  188. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
  189. package/lib/esm/UnitConversion/UnitConversion.js +74 -0
  190. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
  191. package/lib/esm/UnitConversion/UnitConverter.d.ts +40 -0
  192. package/lib/esm/UnitConversion/UnitConverter.d.ts.map +1 -0
  193. package/lib/esm/UnitConversion/UnitConverter.js +113 -0
  194. package/lib/esm/UnitConversion/UnitConverter.js.map +1 -0
  195. package/lib/esm/UnitConversion/UnitTree.d.ts +44 -0
  196. package/lib/esm/UnitConversion/UnitTree.d.ts.map +1 -0
  197. package/lib/esm/UnitConversion/UnitTree.js +165 -0
  198. package/lib/esm/UnitConversion/UnitTree.js.map +1 -0
  199. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts +78 -0
  200. package/lib/esm/UnitProvider/SchemaUnitProvider.d.ts.map +1 -0
  201. package/lib/esm/UnitProvider/SchemaUnitProvider.js +231 -0
  202. package/lib/esm/UnitProvider/SchemaUnitProvider.js.map +1 -0
  203. package/lib/esm/Validation/SchemaWalker.d.ts +24 -0
  204. package/lib/esm/Validation/SchemaWalker.d.ts.map +1 -0
  205. package/lib/esm/Validation/SchemaWalker.js +50 -0
  206. package/lib/esm/Validation/SchemaWalker.js.map +1 -0
  207. package/lib/esm/ecschema-metadata.d.ts +52 -0
  208. package/lib/esm/ecschema-metadata.d.ts.map +1 -0
  209. package/lib/esm/ecschema-metadata.js +55 -0
  210. package/lib/esm/ecschema-metadata.js.map +1 -0
  211. package/lib/esm/utils/SchemaGraph.d.ts +44 -0
  212. package/lib/esm/utils/SchemaGraph.d.ts.map +1 -0
  213. package/lib/esm/utils/SchemaGraph.js +111 -0
  214. package/lib/esm/utils/SchemaGraph.js.map +1 -0
  215. package/package.json +9 -7
@@ -0,0 +1,209 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { SchemaItemType } from "./ECObjects";
6
+ import { ECClass } from "./Metadata/Class";
7
+ import { Property } from "./Metadata/Property";
8
+ import { RelationshipConstraint } from "./Metadata/RelationshipClass";
9
+ import { SchemaItem } from "./Metadata/SchemaItem";
10
+ function isCustomAttributeContainer(object) {
11
+ return "customAttributes" in object;
12
+ }
13
+ /**
14
+ * A helper class to call methods on the provided [[ISchemaPartVisitor]].
15
+ * @beta
16
+ */
17
+ export class SchemaPartVisitorDelegate {
18
+ constructor(visitor) {
19
+ this._visitor = visitor;
20
+ }
21
+ /**
22
+ * Calls (async) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].
23
+ * @param schema The schema to pass to the visitor.
24
+ * @param fullSchema Indicates if the schema is partially or fully-loaded.
25
+ */
26
+ async visitSchema(schema, fullSchema = true) {
27
+ if (!fullSchema && this._visitor.visitEmptySchema)
28
+ await this._visitor.visitEmptySchema(schema);
29
+ if (fullSchema && this._visitor.visitFullSchema)
30
+ await this._visitor.visitFullSchema(schema);
31
+ }
32
+ /**
33
+ * Calls (synchronously) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].
34
+ * @param schema The schema to pass to the visitor.
35
+ * @param fullSchema Indicates if the schema is partially or fully-loaded.
36
+ */
37
+ visitSchemaSync(schema, fullSchema = true) {
38
+ if (!fullSchema && this._visitor.visitEmptySchemaSync)
39
+ this._visitor.visitEmptySchemaSync(schema);
40
+ if (fullSchema && this._visitor.visitFullSchemaSync)
41
+ this._visitor.visitFullSchemaSync(schema);
42
+ }
43
+ /**
44
+ * Calls (async) the appropriate visit methods on the configured [[ISchemaPartVisitor]]
45
+ * based on the type of the part specified.
46
+ * @param schemaPart The schema part to pass to the visitor methods.
47
+ */
48
+ async visitSchemaPart(schemaPart) {
49
+ if (SchemaItem.isSchemaItem(schemaPart)) {
50
+ await this.visitSchemaItem(schemaPart);
51
+ }
52
+ else if (Property.isProperty(schemaPart) && this._visitor.visitProperty) {
53
+ await this._visitor.visitProperty(schemaPart);
54
+ }
55
+ else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraint) {
56
+ await this._visitor.visitRelationshipConstraint(schemaPart);
57
+ }
58
+ if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainer) {
59
+ await this._visitor.visitCustomAttributeContainer(schemaPart);
60
+ }
61
+ }
62
+ /**
63
+ * Calls (synchronously) the appropriate visit methods on the configured [[ISchemaPartVisitor]]
64
+ * based on the type of the part specified.
65
+ * @param schemaPart The schema part to pass to the visitor methods.
66
+ */
67
+ visitSchemaPartSync(schemaPart) {
68
+ if (SchemaItem.isSchemaItem(schemaPart)) {
69
+ this.visitSchemaItemSync(schemaPart);
70
+ }
71
+ else if (Property.isProperty(schemaPart) && this._visitor.visitPropertySync) {
72
+ this._visitor.visitPropertySync(schemaPart);
73
+ }
74
+ else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraintSync) {
75
+ this._visitor.visitRelationshipConstraintSync(schemaPart);
76
+ }
77
+ if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainerSync)
78
+ this._visitor.visitCustomAttributeContainerSync(schemaPart);
79
+ }
80
+ async visitSchemaItem(schemaItem) {
81
+ if (this._visitor.visitSchemaItem)
82
+ await this._visitor.visitSchemaItem(schemaItem);
83
+ if (ECClass.isECClass(schemaItem) && this._visitor.visitClass)
84
+ await this._visitor.visitClass(schemaItem);
85
+ switch (schemaItem.schemaItemType) {
86
+ case SchemaItemType.Constant:
87
+ if (this._visitor.visitConstant)
88
+ await this._visitor.visitConstant(schemaItem);
89
+ break;
90
+ case SchemaItemType.CustomAttributeClass:
91
+ if (this._visitor.visitCustomAttributeClass)
92
+ await this._visitor.visitCustomAttributeClass(schemaItem);
93
+ break;
94
+ case SchemaItemType.EntityClass:
95
+ if (this._visitor.visitEntityClass)
96
+ await this._visitor.visitEntityClass(schemaItem);
97
+ break;
98
+ case SchemaItemType.Enumeration:
99
+ if (this._visitor.visitEnumeration)
100
+ await this._visitor.visitEnumeration(schemaItem);
101
+ break;
102
+ case SchemaItemType.Format:
103
+ if (this._visitor.visitFormat)
104
+ await this._visitor.visitFormat(schemaItem);
105
+ break;
106
+ case SchemaItemType.InvertedUnit:
107
+ if (this._visitor.visitInvertedUnit)
108
+ await this._visitor.visitInvertedUnit(schemaItem);
109
+ break;
110
+ case SchemaItemType.KindOfQuantity:
111
+ if (this._visitor.visitKindOfQuantity)
112
+ await this._visitor.visitKindOfQuantity(schemaItem);
113
+ break;
114
+ case SchemaItemType.Mixin:
115
+ if (this._visitor.visitMixin)
116
+ await this._visitor.visitMixin(schemaItem);
117
+ break;
118
+ case SchemaItemType.Phenomenon:
119
+ if (this._visitor.visitPhenomenon)
120
+ await this._visitor.visitPhenomenon(schemaItem);
121
+ break;
122
+ case SchemaItemType.PropertyCategory:
123
+ if (this._visitor.visitPropertyCategory)
124
+ await this._visitor.visitPropertyCategory(schemaItem);
125
+ break;
126
+ case SchemaItemType.RelationshipClass:
127
+ if (this._visitor.visitRelationshipClass)
128
+ await this._visitor.visitRelationshipClass(schemaItem);
129
+ break;
130
+ case SchemaItemType.StructClass:
131
+ if (this._visitor.visitStructClass)
132
+ await this._visitor.visitStructClass(schemaItem);
133
+ break;
134
+ case SchemaItemType.Unit:
135
+ if (this._visitor.visitUnit)
136
+ await this._visitor.visitUnit(schemaItem);
137
+ break;
138
+ case SchemaItemType.UnitSystem:
139
+ if (this._visitor.visitUnitSystem)
140
+ await this._visitor.visitUnitSystem(schemaItem);
141
+ break;
142
+ }
143
+ }
144
+ visitSchemaItemSync(schemaItem) {
145
+ if (this._visitor.visitSchemaItemSync)
146
+ this._visitor.visitSchemaItemSync(schemaItem);
147
+ if (ECClass.isECClass(schemaItem) && this._visitor.visitClassSync)
148
+ this._visitor.visitClassSync(schemaItem);
149
+ switch (schemaItem.schemaItemType) {
150
+ case SchemaItemType.Constant:
151
+ if (this._visitor.visitConstantSync)
152
+ this._visitor.visitConstantSync(schemaItem);
153
+ break;
154
+ case SchemaItemType.CustomAttributeClass:
155
+ if (this._visitor.visitCustomAttributeClassSync)
156
+ this._visitor.visitCustomAttributeClassSync(schemaItem);
157
+ break;
158
+ case SchemaItemType.EntityClass:
159
+ if (this._visitor.visitEntityClassSync)
160
+ this._visitor.visitEntityClassSync(schemaItem);
161
+ break;
162
+ case SchemaItemType.Enumeration:
163
+ if (this._visitor.visitEnumerationSync)
164
+ this._visitor.visitEnumerationSync(schemaItem);
165
+ break;
166
+ case SchemaItemType.Format:
167
+ if (this._visitor.visitFormatSync)
168
+ this._visitor.visitFormatSync(schemaItem);
169
+ break;
170
+ case SchemaItemType.InvertedUnit:
171
+ if (this._visitor.visitInvertedUnitSync)
172
+ this._visitor.visitInvertedUnitSync(schemaItem);
173
+ break;
174
+ case SchemaItemType.KindOfQuantity:
175
+ if (this._visitor.visitKindOfQuantitySync)
176
+ this._visitor.visitKindOfQuantitySync(schemaItem);
177
+ break;
178
+ case SchemaItemType.Mixin:
179
+ if (this._visitor.visitMixinSync)
180
+ this._visitor.visitMixinSync(schemaItem);
181
+ break;
182
+ case SchemaItemType.Phenomenon:
183
+ if (this._visitor.visitPhenomenonSync)
184
+ this._visitor.visitPhenomenonSync(schemaItem);
185
+ break;
186
+ case SchemaItemType.PropertyCategory:
187
+ if (this._visitor.visitPropertyCategorySync)
188
+ this._visitor.visitPropertyCategorySync(schemaItem);
189
+ break;
190
+ case SchemaItemType.RelationshipClass:
191
+ if (this._visitor.visitRelationshipClassSync)
192
+ this._visitor.visitRelationshipClassSync(schemaItem);
193
+ break;
194
+ case SchemaItemType.StructClass:
195
+ if (this._visitor.visitStructClassSync)
196
+ this._visitor.visitStructClassSync(schemaItem);
197
+ break;
198
+ case SchemaItemType.Unit:
199
+ if (this._visitor.visitUnitSync)
200
+ this._visitor.visitUnitSync(schemaItem);
201
+ break;
202
+ case SchemaItemType.UnitSystem:
203
+ if (this._visitor.visitUnitSystemSync)
204
+ this._visitor.visitUnitSystemSync(schemaItem);
205
+ break;
206
+ }
207
+ }
208
+ }
209
+ //# sourceMappingURL=SchemaPartVisitorDelegate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaPartVisitorDelegate.js","sourceRoot":"","sources":["../../src/SchemaPartVisitorDelegate.ts"],"names":[],"mappings":"AAAA;;;+FAG+F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,IAAI;gBACtB,IAAI,IAAI,CAAC,QAAQ,CAAC,aAAa;oBAC7B,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAkB,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,cAAc,CAAC,UAAU;gBAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB;oBACnC,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,UAAwB,CAAC,CAAC;gBAC9D,MAAM;QACV,CAAC;IACH,CAAC;CACF","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\r\nimport { SchemaItemType } from \"./ECObjects\";\r\nimport { AnyClass, AnyECType } from \"./Interfaces\";\r\nimport { ECClass, StructClass } from \"./Metadata/Class\";\r\nimport { Constant } from \"./Metadata/Constant\";\r\nimport { CustomAttributeContainerProps } from \"./Metadata/CustomAttribute\";\r\nimport { CustomAttributeClass } from \"./Metadata/CustomAttributeClass\";\r\nimport { EntityClass } from \"./Metadata/EntityClass\";\r\nimport { Enumeration } from \"./Metadata/Enumeration\";\r\nimport { Format } from \"./Metadata/Format\";\r\nimport { InvertedUnit } from \"./Metadata/InvertedUnit\";\r\nimport { KindOfQuantity } from \"./Metadata/KindOfQuantity\";\r\nimport { Mixin } from \"./Metadata/Mixin\";\r\nimport { Phenomenon } from \"./Metadata/Phenomenon\";\r\nimport { AnyProperty, Property } from \"./Metadata/Property\";\r\nimport { PropertyCategory } from \"./Metadata/PropertyCategory\";\r\nimport { RelationshipClass, RelationshipConstraint } from \"./Metadata/RelationshipClass\";\r\nimport { Schema } from \"./Metadata/Schema\";\r\nimport { SchemaItem } from \"./Metadata/SchemaItem\";\r\nimport { Unit } from \"./Metadata/Unit\";\r\nimport { UnitSystem } from \"./Metadata/UnitSystem\";\r\n\r\n/**\r\n * Interface to allow schema traversal/deserialization workflows to visit\r\n * each part, item, class, etc. that exists in a given schema.\r\n * @beta\r\n */\r\nexport interface ISchemaPartVisitor {\r\n /**\r\n * Called for a partially loaded schema. During deserialization, this would\r\n * be after a schema and all its references are deserialized, but _before_\r\n * any of its items or custom attributes have been deserialized.\r\n * @param schema A partially-loaded Schema.\r\n */\r\n /* async */ visitEmptySchema?: (schema: Schema) => Promise<void>;\r\n\r\n /**\r\n * Called for a partially loaded schema. During deserialization, this would\r\n * be after a schema and all its references are deserialized, but _before_\r\n * any of its items or custom attributes have been deserialized.\r\n * @param schema A partially-loaded Schema.\r\n */\r\n visitEmptySchemaSync?: (schema: Schema) => void;\r\n\r\n /**\r\n * Called for a fully loaded schema.\r\n * @param schema A fully-loaded Schema.\r\n */\r\n /* async */ visitFullSchema?: (schema: Schema) => Promise<void>;\r\n\r\n /**\r\n * Called for a fully loaded schema.\r\n * @param schema A fully-loaded Schema.\r\n */\r\n visitFullSchemaSync?: (schema: Schema) => void;\r\n\r\n /**\r\n * Called for each [[SchemaItem]] instance.\r\n * @param schemaItem a SchemaItem object.\r\n */\r\n /* async */ visitSchemaItem?: (schemaItem: SchemaItem) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[SchemaItem]] instance.\r\n * @param schemaItem a SchemaItem object.\r\n */\r\n visitSchemaItemSync?: (schemaItem: SchemaItem) => void;\r\n\r\n /**\r\n * Called for each [[AnyClass]] instance.\r\n * @param ecClass an ECClass object.\r\n */\r\n /* async */ visitClass?: (ecClass: AnyClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[AnyClass]] instance.\r\n * @param ecClass an ECClass object.\r\n */\r\n visitClassSync?: (ecClass: AnyClass) => void;\r\n\r\n /**\r\n * Called for each [[AnyProperty]] instance of an ECClass.\r\n * @param property an AnyProperty object.\r\n */\r\n /* async */ visitProperty?: (property: AnyProperty) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[AnyProperty]] instance of an ECClass.\r\n * @param property an AnyProperty object.\r\n */\r\n visitPropertySync?: (property: AnyProperty) => void;\r\n\r\n /**\r\n * Called for each [[EntityClass]] instance.\r\n * @param entityClass an EntityClass object.\r\n */\r\n /* async */ visitEntityClass?: (entityClass: EntityClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[EntityClass]] instance.\r\n * @param entityClass an EntityClass object.\r\n */\r\n visitEntityClassSync?: (entityClass: EntityClass) => void;\r\n\r\n /**\r\n * Called for each [[StructClass]] instance.\r\n * @param structClass a StructClass object.\r\n */\r\n /* async */ visitStructClass?: (structClass: StructClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[StructClass]] instance.\r\n * @param structClass a StructClass object.\r\n */\r\n visitStructClassSync?: (structClass: StructClass) => void;\r\n\r\n /**\r\n * Called for each [[Mixin]] instance.\r\n * @param mixin a Mixin object.\r\n */\r\n /* async */ visitMixin?: (mixin: Mixin) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Mixin]] instance.\r\n * @param mixin a Mixin object.\r\n */\r\n visitMixinSync?: (mixin: Mixin) => void;\r\n\r\n /**\r\n * Called for each [[RelationshipClass]] instance.\r\n * @param relationshipClass a RelationshipClass object.\r\n */\r\n /* async */ visitRelationshipClass?: (relationshipClass: RelationshipClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[RelationshipClass]] instance.\r\n * @param relationshipClass a RelationshipClass object.\r\n */\r\n visitRelationshipClassSync?: (relationshipClass: RelationshipClass) => void;\r\n\r\n /**\r\n * Called for each [[RelationshipConstraint]] of each RelationshipClass.\r\n * @param relationshipConstraint a RelationshipConstraint object.\r\n */\r\n /* async */ visitRelationshipConstraint?: (relationshipConstraint: RelationshipConstraint) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[RelationshipConstraint]] of each RelationshipClass.\r\n * @param relationshipConstraint a RelationshipConstraint object.\r\n */\r\n visitRelationshipConstraintSync?: (relationshipConstraint: RelationshipConstraint) => void;\r\n\r\n /**\r\n * Called for each [[CustomAttributeClass]] instance.\r\n * @param customAttributeClass a CustomAttributeClass object.\r\n */\r\n /* async */ visitCustomAttributeClass?: (customAttributeClass: CustomAttributeClass) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[CustomAttributeClass]] instance.\r\n * @param customAttributeClass a CustomAttributeClass object.\r\n */\r\n visitCustomAttributeClassSync?: (customAttributeClass: CustomAttributeClass) => void;\r\n\r\n /**\r\n * Called for each CustomAttribute container in the schema.\r\n * @param customAttributeContainer a CustomAttributeContainerProps object.\r\n */\r\n /* async */ visitCustomAttributeContainer?: (customAttributeContainer: CustomAttributeContainerProps) => Promise<void>;\r\n\r\n /**\r\n * Called for each CustomAttribute container in the schema.\r\n * @param customAttributeContainer a CustomAttributeContainerProps object.\r\n */\r\n visitCustomAttributeContainerSync?: (customAttributeContainer: CustomAttributeContainerProps) => void;\r\n\r\n /**\r\n * Called for each [[Enumeration]] instance.\r\n * @param enumeration an Enumeration object.\r\n */\r\n /* async */ visitEnumeration?: (enumeration: Enumeration) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Enumeration]] instance.\r\n * @param enumeration an Enumeration object.\r\n */\r\n visitEnumerationSync?: (enumeration: Enumeration) => void;\r\n\r\n /**\r\n * Called for each [[KindOfQuantity]] instance.\r\n * @param koq a KindOfQuantity object.\r\n */\r\n /* async */ visitKindOfQuantity?: (koq: KindOfQuantity) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[KindOfQuantity]] instance.\r\n * @param koq a KindOfQuantity object.\r\n */\r\n visitKindOfQuantitySync?: (koq: KindOfQuantity) => void;\r\n\r\n /**\r\n * Called for each [[PropertyCategory]] instance.\r\n * @param category a PropertyCategory object.\r\n */\r\n /* async */ visitPropertyCategory?: (category: PropertyCategory) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[PropertyCategory]] instance.\r\n * @param category a PropertyCategory object.\r\n */\r\n visitPropertyCategorySync?: (category: PropertyCategory) => void;\r\n\r\n /**\r\n * Called for each [[Format]] instance.\r\n * @param format a Format object.\r\n */\r\n /* async */ visitFormat?: (format: Format) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Format]] instance.\r\n * @param format a Format object.\r\n */\r\n visitFormatSync?: (format: Format) => void;\r\n\r\n /**\r\n * Called for each [[Unit]] instance.\r\n * @param unit a Unit object.\r\n */\r\n /* async */ visitUnit?: (unit: Unit) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Unit]] instance.\r\n * @param unit a Unit object.\r\n */\r\n visitUnitSync?: (unit: Unit) => void;\r\n\r\n /**\r\n * Called for each [[InvertedUnit]] instance.\r\n * @param invertedUnit an InvertedUnit object.\r\n */\r\n /* async */ visitInvertedUnit?: (invertedUnit: InvertedUnit) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[InvertedUnit]] instance.\r\n * @param invertedUnit an InvertedUnit object.\r\n */\r\n visitInvertedUnitSync?: (invertedUnit: InvertedUnit) => void;\r\n\r\n /**\r\n * Called for each [[UnitSystem]] instance.\r\n * @param unitSystem a UnitSystem object.\r\n */\r\n /* async */ visitUnitSystem?: (unitSystem: UnitSystem) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[UnitSystem]] instance.\r\n * @param unitSystem a UnitSystem object.\r\n */\r\n visitUnitSystemSync?: (unitSystem: UnitSystem) => void;\r\n\r\n /**\r\n * Called for each [[Phenomenon]] instance.\r\n * @param phenomena a Phenomenon object.\r\n */\r\n /* async */ visitPhenomenon?: (phenomena: Phenomenon) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Phenomenon]] instance.\r\n * @param phenomena a Phenomenon object.\r\n */\r\n visitPhenomenonSync?: (phenomena: Phenomenon) => void;\r\n\r\n /**\r\n * Called for each [[Constant]] instance.\r\n * @param constant a Constant object.\r\n */\r\n /* async */ visitConstant?: (constant: Constant) => Promise<void>;\r\n\r\n /**\r\n * Called for each [[Constant]] instance.\r\n * @param constant a Constant object.\r\n */\r\n visitConstantSync?: (constant: Constant) => void;\r\n}\r\n\r\nfunction isCustomAttributeContainer(object: any): object is CustomAttributeContainerProps {\r\n return \"customAttributes\" in object;\r\n}\r\n\r\n/**\r\n * A helper class to call methods on the provided [[ISchemaPartVisitor]].\r\n * @beta\r\n */\r\nexport class SchemaPartVisitorDelegate {\r\n private _visitor: ISchemaPartVisitor;\r\n\r\n constructor(visitor: ISchemaPartVisitor) {\r\n this._visitor = visitor;\r\n }\r\n\r\n /**\r\n * Calls (async) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].\r\n * @param schema The schema to pass to the visitor.\r\n * @param fullSchema Indicates if the schema is partially or fully-loaded.\r\n */\r\n public async visitSchema(schema: Schema, fullSchema: boolean = true): Promise<void> {\r\n if (!fullSchema && this._visitor.visitEmptySchema)\r\n await this._visitor.visitEmptySchema(schema);\r\n\r\n if (fullSchema && this._visitor.visitFullSchema)\r\n await this._visitor.visitFullSchema(schema);\r\n }\r\n\r\n /**\r\n * Calls (synchronously) visitEmptySchema or visitFullSchema on the configured [[ISchemaPartVisitor]].\r\n * @param schema The schema to pass to the visitor.\r\n * @param fullSchema Indicates if the schema is partially or fully-loaded.\r\n */\r\n public visitSchemaSync(schema: Schema, fullSchema: boolean = true): void {\r\n if (!fullSchema && this._visitor.visitEmptySchemaSync)\r\n this._visitor.visitEmptySchemaSync(schema);\r\n\r\n if (fullSchema && this._visitor.visitFullSchemaSync)\r\n this._visitor.visitFullSchemaSync(schema);\r\n }\r\n\r\n /**\r\n * Calls (async) the appropriate visit methods on the configured [[ISchemaPartVisitor]]\r\n * based on the type of the part specified.\r\n * @param schemaPart The schema part to pass to the visitor methods.\r\n */\r\n public async visitSchemaPart(schemaPart: AnyECType): Promise<void> {\r\n if (SchemaItem.isSchemaItem(schemaPart)) {\r\n await this.visitSchemaItem(schemaPart);\r\n } else if (Property.isProperty(schemaPart) && this._visitor.visitProperty) {\r\n await this._visitor.visitProperty(schemaPart);\r\n } else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraint) {\r\n await this._visitor.visitRelationshipConstraint(schemaPart);\r\n }\r\n\r\n if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainer) {\r\n await this._visitor.visitCustomAttributeContainer(schemaPart);\r\n }\r\n }\r\n\r\n /**\r\n * Calls (synchronously) the appropriate visit methods on the configured [[ISchemaPartVisitor]]\r\n * based on the type of the part specified.\r\n * @param schemaPart The schema part to pass to the visitor methods.\r\n */\r\n public visitSchemaPartSync(schemaPart: AnyECType): void {\r\n if (SchemaItem.isSchemaItem(schemaPart)) {\r\n this.visitSchemaItemSync(schemaPart);\r\n } else if (Property.isProperty(schemaPart) && this._visitor.visitPropertySync) {\r\n this._visitor.visitPropertySync(schemaPart);\r\n } else if (RelationshipConstraint.isRelationshipConstraint(schemaPart) && this._visitor.visitRelationshipConstraintSync) {\r\n this._visitor.visitRelationshipConstraintSync(schemaPart);\r\n }\r\n\r\n if (isCustomAttributeContainer(schemaPart) && this._visitor.visitCustomAttributeContainerSync)\r\n this._visitor.visitCustomAttributeContainerSync(schemaPart);\r\n }\r\n\r\n private async visitSchemaItem(schemaItem: SchemaItem) {\r\n if (this._visitor.visitSchemaItem)\r\n await this._visitor.visitSchemaItem(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem) && this._visitor.visitClass)\r\n await this._visitor.visitClass(schemaItem as AnyClass);\r\n\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.Constant:\r\n if (this._visitor.visitConstant)\r\n await this._visitor.visitConstant(schemaItem as Constant);\r\n break;\r\n case SchemaItemType.CustomAttributeClass:\r\n if (this._visitor.visitCustomAttributeClass)\r\n await this._visitor.visitCustomAttributeClass(schemaItem as CustomAttributeClass);\r\n break;\r\n case SchemaItemType.EntityClass:\r\n if (this._visitor.visitEntityClass)\r\n await this._visitor.visitEntityClass(schemaItem as EntityClass);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n if (this._visitor.visitEnumeration)\r\n await this._visitor.visitEnumeration(schemaItem as Enumeration);\r\n break;\r\n case SchemaItemType.Format:\r\n if (this._visitor.visitFormat)\r\n await this._visitor.visitFormat(schemaItem as Format);\r\n break;\r\n case SchemaItemType.InvertedUnit:\r\n if (this._visitor.visitInvertedUnit)\r\n await this._visitor.visitInvertedUnit(schemaItem as InvertedUnit);\r\n break;\r\n case SchemaItemType.KindOfQuantity:\r\n if (this._visitor.visitKindOfQuantity)\r\n await this._visitor.visitKindOfQuantity(schemaItem as KindOfQuantity);\r\n break;\r\n case SchemaItemType.Mixin:\r\n if (this._visitor.visitMixin)\r\n await this._visitor.visitMixin(schemaItem as Mixin);\r\n break;\r\n case SchemaItemType.Phenomenon:\r\n if (this._visitor.visitPhenomenon)\r\n await this._visitor.visitPhenomenon(schemaItem as Phenomenon);\r\n break;\r\n case SchemaItemType.PropertyCategory:\r\n if (this._visitor.visitPropertyCategory)\r\n await this._visitor.visitPropertyCategory(schemaItem as PropertyCategory);\r\n break;\r\n case SchemaItemType.RelationshipClass:\r\n if (this._visitor.visitRelationshipClass)\r\n await this._visitor.visitRelationshipClass(schemaItem as RelationshipClass);\r\n break;\r\n case SchemaItemType.StructClass:\r\n if (this._visitor.visitStructClass)\r\n await this._visitor.visitStructClass(schemaItem as StructClass);\r\n break;\r\n case SchemaItemType.Unit:\r\n if (this._visitor.visitUnit)\r\n await this._visitor.visitUnit(schemaItem as Unit);\r\n break;\r\n case SchemaItemType.UnitSystem:\r\n if (this._visitor.visitUnitSystem)\r\n await this._visitor.visitUnitSystem(schemaItem as UnitSystem);\r\n break;\r\n }\r\n }\r\n\r\n private visitSchemaItemSync(schemaItem: SchemaItem) {\r\n if (this._visitor.visitSchemaItemSync)\r\n this._visitor.visitSchemaItemSync(schemaItem);\r\n\r\n if (ECClass.isECClass(schemaItem) && this._visitor.visitClassSync)\r\n this._visitor.visitClassSync(schemaItem as AnyClass);\r\n\r\n switch (schemaItem.schemaItemType) {\r\n case SchemaItemType.Constant:\r\n if (this._visitor.visitConstantSync)\r\n this._visitor.visitConstantSync(schemaItem as Constant);\r\n break;\r\n case SchemaItemType.CustomAttributeClass:\r\n if (this._visitor.visitCustomAttributeClassSync)\r\n this._visitor.visitCustomAttributeClassSync(schemaItem as CustomAttributeClass);\r\n break;\r\n case SchemaItemType.EntityClass:\r\n if (this._visitor.visitEntityClassSync)\r\n this._visitor.visitEntityClassSync(schemaItem as EntityClass);\r\n break;\r\n case SchemaItemType.Enumeration:\r\n if (this._visitor.visitEnumerationSync)\r\n this._visitor.visitEnumerationSync(schemaItem as Enumeration);\r\n break;\r\n case SchemaItemType.Format:\r\n if (this._visitor.visitFormatSync)\r\n this._visitor.visitFormatSync(schemaItem as Format);\r\n break;\r\n case SchemaItemType.InvertedUnit:\r\n if (this._visitor.visitInvertedUnitSync)\r\n this._visitor.visitInvertedUnitSync(schemaItem as InvertedUnit);\r\n break;\r\n case SchemaItemType.KindOfQuantity:\r\n if (this._visitor.visitKindOfQuantitySync)\r\n this._visitor.visitKindOfQuantitySync(schemaItem as KindOfQuantity);\r\n break;\r\n case SchemaItemType.Mixin:\r\n if (this._visitor.visitMixinSync)\r\n this._visitor.visitMixinSync(schemaItem as Mixin);\r\n break;\r\n case SchemaItemType.Phenomenon:\r\n if (this._visitor.visitPhenomenonSync)\r\n this._visitor.visitPhenomenonSync(schemaItem as Phenomenon);\r\n break;\r\n case SchemaItemType.PropertyCategory:\r\n if (this._visitor.visitPropertyCategorySync)\r\n this._visitor.visitPropertyCategorySync(schemaItem as PropertyCategory);\r\n break;\r\n case SchemaItemType.RelationshipClass:\r\n if (this._visitor.visitRelationshipClassSync)\r\n this._visitor.visitRelationshipClassSync(schemaItem as RelationshipClass);\r\n break;\r\n case SchemaItemType.StructClass:\r\n if (this._visitor.visitStructClassSync)\r\n this._visitor.visitStructClassSync(schemaItem as StructClass);\r\n break;\r\n case SchemaItemType.Unit:\r\n if (this._visitor.visitUnitSync)\r\n this._visitor.visitUnitSync(schemaItem as Unit);\r\n break;\r\n case SchemaItemType.UnitSystem:\r\n if (this._visitor.visitUnitSystemSync)\r\n this._visitor.visitUnitSystemSync(schemaItem as UnitSystem);\r\n break;\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,35 @@
1
+ /** @internal */
2
+ export declare class Graph<T> {
3
+ private _edgeKeyDelim;
4
+ private _label;
5
+ private _nodeCount;
6
+ private _edgeCount;
7
+ private _nodes;
8
+ private _edgeObjs;
9
+ private _edgeLabels;
10
+ private _outEdges;
11
+ constructor();
12
+ setGraph: (label: string) => Graph<T>;
13
+ graph: () => string;
14
+ nodeCount: () => number;
15
+ nodes: () => string[];
16
+ setNode: (nodeKey: string, nodeValue: T) => void;
17
+ node: (nodeKey: string) => T;
18
+ hasNode: (nodeKey: string) => boolean;
19
+ edgeCount: () => number;
20
+ edges: () => {
21
+ v: string;
22
+ w: string;
23
+ }[];
24
+ setEdge: (v: string, w: string, value: {
25
+ exponent: number;
26
+ }) => void;
27
+ edge: (v: string, w: string) => {
28
+ exponent: number;
29
+ };
30
+ outEdges: (v: string) => {
31
+ v: string;
32
+ w: string;
33
+ }[];
34
+ }
35
+ //# sourceMappingURL=Graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/Graph.ts"],"names":[],"mappings":"AA8CA,gBAAgB;AAChB,qBAAa,KAAK,CAAC,CAAC;IAClB,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,SAAS,CAAc;;IASxB,QAAQ,UAAW,MAAM,KAAG,MAAM,CAAC,CAAC,CAGzC;IAEK,KAAK,eAEV;IAEK,SAAS,eAEd;IAEK,KAAK,iBAEV;IAEK,OAAO,YAAa,MAAM,aAAa,CAAC,UAQ7C;IAEK,IAAI,YAAa,MAAM,OAE5B;IAEK,OAAO,YAAa,MAAM,aAE/B;IAEK,SAAS,eAEd;IAEK,KAAK;;;QAEV;IAEK,OAAO,MAAO,MAAM,KAAK,MAAM,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,UAkBjE;IAEK,IAAI,MAAO,MAAM,KAAK,MAAM;;MAGjC;IAEK,QAAQ,MAAO,MAAM;;;QAI1B;CACH"}
@@ -0,0 +1,80 @@
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
+ // Following https://github.com/dagrejs/graphlib/blob/master/lib/graph.js
6
+ /** @internal */
7
+ export class Graph {
8
+ constructor() {
9
+ this._edgeKeyDelim = "\x01";
10
+ this._label = "";
11
+ this._nodeCount = 0;
12
+ this._edgeCount = 0;
13
+ this.setGraph = (label) => {
14
+ this._label = label;
15
+ return this;
16
+ };
17
+ this.graph = () => {
18
+ return this._label;
19
+ };
20
+ this.nodeCount = () => {
21
+ return this._nodeCount;
22
+ };
23
+ this.nodes = () => {
24
+ return Object.keys(this._nodes);
25
+ };
26
+ this.setNode = (nodeKey, nodeValue) => {
27
+ if (nodeKey in this._nodes) {
28
+ this._nodes[nodeKey] = nodeValue;
29
+ return;
30
+ }
31
+ this._nodes[nodeKey] = nodeValue;
32
+ this._outEdges[nodeKey] = {};
33
+ ++this._nodeCount;
34
+ };
35
+ this.node = (nodeKey) => {
36
+ return this._nodes[nodeKey];
37
+ };
38
+ this.hasNode = (nodeKey) => {
39
+ return nodeKey in this._nodes;
40
+ };
41
+ this.edgeCount = () => {
42
+ return this._edgeCount;
43
+ };
44
+ this.edges = () => {
45
+ return Object.values(this._edgeObjs);
46
+ };
47
+ this.setEdge = (v, w, value) => {
48
+ const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;
49
+ if (edgeId in this._edgeLabels) {
50
+ // this._edgeLabels[edgeId] = value;
51
+ // Update exponent, specific to this graph's use case
52
+ this._edgeLabels[edgeId].exponent += value.exponent;
53
+ return;
54
+ }
55
+ this._edgeLabels[edgeId] = value;
56
+ const edgeObj = {
57
+ v,
58
+ w,
59
+ };
60
+ this._edgeObjs[edgeId] = edgeObj;
61
+ // setNode should have ran first, so this.outEdges[v] shouldn't be undefined
62
+ this._outEdges[v][edgeId] = edgeObj;
63
+ this._edgeCount++;
64
+ };
65
+ this.edge = (v, w) => {
66
+ const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;
67
+ return this._edgeLabels[edgeId];
68
+ };
69
+ this.outEdges = (v) => {
70
+ const outV = this._outEdges[v];
71
+ const edges = Object.values(outV);
72
+ return edges;
73
+ };
74
+ this._nodes = {};
75
+ this._edgeObjs = {};
76
+ this._edgeLabels = {};
77
+ this._outEdges = {};
78
+ }
79
+ }
80
+ //# sourceMappingURL=Graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../../src/UnitConversion/Graph.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,yEAAyE;AA0CzE,gBAAgB;AAChB,MAAM,OAAO,KAAK;IAUhB;QATQ,kBAAa,GAAG,MAAM,CAAC;QACvB,WAAM,GAAG,EAAE,CAAC;QACZ,eAAU,GAAG,CAAC,CAAC;QACf,eAAU,GAAG,CAAC,CAAC;QAahB,aAAQ,GAAG,CAAC,KAAa,EAAY,EAAE;YAC5C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;YACpB,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;QAEK,UAAK,GAAG,GAAG,EAAE;YAClB,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC,CAAC;QAEK,cAAS,GAAG,GAAG,EAAE;YACtB,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC,CAAC;QAEK,UAAK,GAAG,GAAG,EAAE;YAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC,CAAC;QA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AG;gBACd,CAAC;gBACD,CAAC;aACF,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;YACjC,4EAA4E;YAC5E,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;YACpC,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC,CAAC;QAEK,SAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;YACrC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC;YAC/D,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC,CAAC;QAEK,aAAQ,GAAG,CAAC,CAAS,EAAE,EAAE;YAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QA9EA,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;CA2EF","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// Following https://github.com/dagrejs/graphlib/blob/master/lib/graph.js\r\n\r\n/**\r\n * Using generics for nodes - T represents Unit | Constant in our use case\r\n * @internal\r\n */\r\ninterface NodesMap<T> {\r\n [node: string]: T;\r\n}\r\n\r\n/**\r\n * Describe edges based on its node endpoints (v, w)\r\n * @internal\r\n */\r\ninterface EdgeObjsMap {\r\n [edge: string]: {\r\n v: string;\r\n w: string;\r\n };\r\n}\r\n\r\n/**\r\n * Describe edges based on the exponent they carry\r\n * @internal\r\n */\r\ninterface EdgeLabelsMap {\r\n [edge: string]: { exponent: number };\r\n}\r\n\r\n/**\r\n * List each node with outgoing edges in outer map; describe each node's outgoing edges in inner map\r\n * @internal\r\n */\r\ninterface OutEdgesMap {\r\n [node: string]: {\r\n [edges: string]: {\r\n v: string;\r\n w: string;\r\n };\r\n };\r\n}\r\n\r\n/** @internal */\r\nexport class Graph<T> {\r\n private _edgeKeyDelim = \"\\x01\";\r\n private _label = \"\";\r\n private _nodeCount = 0;\r\n private _edgeCount = 0;\r\n private _nodes: NodesMap<T>;\r\n private _edgeObjs: EdgeObjsMap;\r\n private _edgeLabels: EdgeLabelsMap;\r\n private _outEdges: OutEdgesMap;\r\n\r\n constructor() {\r\n this._nodes = {};\r\n this._edgeObjs = {};\r\n this._edgeLabels = {};\r\n this._outEdges = {};\r\n }\r\n\r\n public setGraph = (label: string): Graph<T> => {\r\n this._label = label;\r\n return this;\r\n };\r\n\r\n public graph = () => {\r\n return this._label;\r\n };\r\n\r\n public nodeCount = () => {\r\n return this._nodeCount;\r\n };\r\n\r\n public nodes = () => {\r\n return Object.keys(this._nodes);\r\n };\r\n\r\n public setNode = (nodeKey: string, nodeValue: T) => {\r\n if (nodeKey in this._nodes) {\r\n this._nodes[nodeKey] = nodeValue;\r\n return;\r\n }\r\n this._nodes[nodeKey] = nodeValue;\r\n this._outEdges[nodeKey] = {};\r\n ++this._nodeCount;\r\n };\r\n\r\n public node = (nodeKey: string) => {\r\n return this._nodes[nodeKey];\r\n };\r\n\r\n public hasNode = (nodeKey: string) => {\r\n return nodeKey in this._nodes;\r\n };\r\n\r\n public edgeCount = () => {\r\n return this._edgeCount;\r\n };\r\n\r\n public edges = () => {\r\n return Object.values(this._edgeObjs);\r\n };\r\n\r\n public setEdge = (v: string, w: string, value: { exponent: number }) => {\r\n const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;\r\n if (edgeId in this._edgeLabels) {\r\n // this._edgeLabels[edgeId] = value;\r\n // Update exponent, specific to this graph's use case\r\n this._edgeLabels[edgeId].exponent += value.exponent;\r\n return;\r\n }\r\n\r\n this._edgeLabels[edgeId] = value;\r\n const edgeObj = {\r\n v,\r\n w,\r\n };\r\n this._edgeObjs[edgeId] = edgeObj;\r\n // setNode should have ran first, so this.outEdges[v] shouldn't be undefined\r\n this._outEdges[v][edgeId] = edgeObj;\r\n this._edgeCount++;\r\n };\r\n\r\n public edge = (v: string, w: string) => {\r\n const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;\r\n return this._edgeLabels[edgeId];\r\n };\r\n\r\n public outEdges = (v: string) => {\r\n const outV = this._outEdges[v];\r\n const edges = Object.values(outV);\r\n return edges;\r\n };\r\n}\r\n"]}
@@ -0,0 +1,9 @@
1
+ /** @internal */
2
+ export interface DefinitionFragment {
3
+ name: string;
4
+ exponent: number;
5
+ constant: boolean;
6
+ }
7
+ /** @internal */
8
+ export declare function parseDefinition(definition: string): Map<string, DefinitionFragment>;
9
+ //# sourceMappingURL=Parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":"AAeA,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAsBnF"}
@@ -0,0 +1,39 @@
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
+ const expressionRgx = /^(([A-Z]\w*:)?([A-Z]\w*|\[([A-Z]\w*:)?[A-Z]\w*\])(\(-?\d+\))?(\*(?!$)|$))+$/i;
6
+ const tokenRgx = /(?:(\[)?((?:[A-Z]\w*:)?[A-Z]\w*)\]?)(?:\((-?\d+)\))?/i;
7
+ const sp = "*";
8
+ /** @internal */
9
+ var Tokens;
10
+ (function (Tokens) {
11
+ Tokens[Tokens["Bracket"] = 1] = "Bracket";
12
+ Tokens[Tokens["Word"] = 2] = "Word";
13
+ Tokens[Tokens["Exponent"] = 3] = "Exponent";
14
+ })(Tokens || (Tokens = {}));
15
+ /** @internal */
16
+ export function parseDefinition(definition) {
17
+ const unitMap = new Map();
18
+ if (expressionRgx.test(definition)) {
19
+ for (const unit of definition.split(sp)) {
20
+ const tokens = unit.split(tokenRgx);
21
+ const name = tokens[Tokens.Word];
22
+ const exponent = tokens[Tokens.Exponent] ? Number(tokens[Tokens.Exponent]) : 1;
23
+ const constant = tokens[Tokens.Bracket] !== undefined;
24
+ if (unitMap.has(name)) {
25
+ const currentDefinition = unitMap.get(name);
26
+ currentDefinition.exponent += exponent;
27
+ unitMap.set(name, currentDefinition);
28
+ }
29
+ else {
30
+ unitMap.set(name, { name, exponent, constant });
31
+ }
32
+ }
33
+ return unitMap;
34
+ }
35
+ else {
36
+ throw new Error("Invalid definition expression.");
37
+ }
38
+ }
39
+ //# sourceMappingURL=Parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,MAAM,aAAa,GAAG,8EAA8E,CAAC;AACrG,MAAM,QAAQ,GAAG,uDAAuD,CAAC;AACzE,MAAM,EAAE,GAAG,GAAG,CAAC;AAEf,gBAAgB;AAChB,IAAK,MAIJ;AAJD,WAAK,MAAM;IACT,yCAAW,CAAA;IACX,mCAAQ,CAAA;IACR,2CAAY,CAAA;AACd,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;AASD,gBAAgB;AAChB,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,MAAM,OAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;IAE3D,IAAI,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;YACtD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;gBAC7C,iBAAiB,CAAC,QAAQ,IAAI,QAAQ,CAAC;gBACvC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,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\nconst expressionRgx = /^(([A-Z]\\w*:)?([A-Z]\\w*|\\[([A-Z]\\w*:)?[A-Z]\\w*\\])(\\(-?\\d+\\))?(\\*(?!$)|$))+$/i;\r\nconst tokenRgx = /(?:(\\[)?((?:[A-Z]\\w*:)?[A-Z]\\w*)\\]?)(?:\\((-?\\d+)\\))?/i;\r\nconst sp = \"*\";\r\n\r\n/** @internal */\r\nenum Tokens {\r\n Bracket = 1,\r\n Word = 2,\r\n Exponent = 3,\r\n}\r\n\r\n/** @internal */\r\nexport interface DefinitionFragment {\r\n name: string;\r\n exponent: number;\r\n constant: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport function parseDefinition(definition: string): Map<string, DefinitionFragment> {\r\n const unitMap: Map<string, DefinitionFragment> = new Map();\r\n\r\n if (expressionRgx.test(definition)) {\r\n for (const unit of definition.split(sp)) {\r\n const tokens = unit.split(tokenRgx);\r\n const name = tokens[Tokens.Word];\r\n const exponent = tokens[Tokens.Exponent] ? Number(tokens[Tokens.Exponent]) : 1;\r\n const constant = tokens[Tokens.Bracket] !== undefined;\r\n if (unitMap.has(name)) {\r\n const currentDefinition = unitMap.get(name)!;\r\n currentDefinition.exponent += exponent;\r\n unitMap.set(name, currentDefinition);\r\n } else {\r\n unitMap.set(name, { name, exponent, constant });\r\n }\r\n }\r\n\r\n return unitMap;\r\n } else {\r\n throw new Error(\"Invalid definition expression.\");\r\n }\r\n}\r\n"]}
@@ -0,0 +1,46 @@
1
+ import { Constant } from "../Metadata/Constant";
2
+ import { Unit } from "../Metadata/Unit";
3
+ /**
4
+ * Class used for storing calculated conversion between two Units [[UnitConverter.calculateConversion]] and converting values from one Unit to another [[UnitConverter.evaluate]]
5
+ * @internal
6
+ */
7
+ export declare class UnitConversion {
8
+ readonly factor: number;
9
+ readonly offset: number;
10
+ constructor(factor?: number, offset?: number);
11
+ /**
12
+ * Converts x using UnitConversion
13
+ * @param x Input magnitude to be converted
14
+ * @returns Output magnitude after conversion
15
+ */
16
+ evaluate(x: number): number;
17
+ /**
18
+ * Used to invert source's UnitConversion so that it can be composed with target's UnitConversion cleanly
19
+ * @internal
20
+ */
21
+ inverse(): UnitConversion;
22
+ /**
23
+ * Combines two UnitConversions
24
+ * Used to combine source's UnitConversion and target's UnitConversion for a final UnitConversion that can be evaluated
25
+ * @internal
26
+ */
27
+ compose(conversion: UnitConversion): UnitConversion;
28
+ /**
29
+ * Multiples two UnitConversions together to calculate factor during reducing
30
+ * @internal
31
+ */
32
+ multiply(conversion: UnitConversion): UnitConversion;
33
+ /**
34
+ * Raise UnitConversion's factor with power exponent to calculate factor during reducing
35
+ * @internal
36
+ */
37
+ raise(power: number): UnitConversion;
38
+ /** @internal */
39
+ static identity: UnitConversion;
40
+ /**
41
+ * Returns UnitConversion with unit's numerator and denominator in factor and unit's offset in offset for reducing
42
+ * @internal
43
+ */
44
+ static from(unit: Unit | Constant): UnitConversion;
45
+ }
46
+ //# sourceMappingURL=UnitConversion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnitConversion.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC;;;GAGG;AACH,qBAAa,cAAc;aACG,MAAM,EAAE,MAAM;aAAwB,MAAM,EAAE,MAAM;gBAApD,MAAM,GAAE,MAAY,EAAkB,MAAM,GAAE,MAAY;IAEtF;;;;OAIG;IACI,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAIlC;;;OAGG;IACI,OAAO,IAAI,cAAc;IAKhC;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc;IAO1D;;;OAGG;IACI,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc;IAO3D;;;OAGG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc;IAY3C,gBAAgB;IAChB,OAAc,QAAQ,iBAAwB;IAE9C;;;OAGG;WACW,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ,GAAG,cAAc;CAM1D"}
@@ -0,0 +1,74 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import * as almostEqual from "almost-equal";
6
+ import { SchemaItemType } from "../ECObjects";
7
+ /**
8
+ * Class used for storing calculated conversion between two Units [[UnitConverter.calculateConversion]] and converting values from one Unit to another [[UnitConverter.evaluate]]
9
+ * @internal
10
+ */
11
+ export class UnitConversion {
12
+ constructor(factor = 1.0, offset = 0.0) {
13
+ this.factor = factor;
14
+ this.offset = offset;
15
+ }
16
+ /**
17
+ * Converts x using UnitConversion
18
+ * @param x Input magnitude to be converted
19
+ * @returns Output magnitude after conversion
20
+ */
21
+ evaluate(x) {
22
+ return this.factor * x + this.offset;
23
+ }
24
+ /**
25
+ * Used to invert source's UnitConversion so that it can be composed with target's UnitConversion cleanly
26
+ * @internal
27
+ */
28
+ inverse() {
29
+ const inverseFactor = 1.0 / this.factor;
30
+ return new UnitConversion(inverseFactor, -this.offset * inverseFactor);
31
+ }
32
+ /**
33
+ * Combines two UnitConversions
34
+ * Used to combine source's UnitConversion and target's UnitConversion for a final UnitConversion that can be evaluated
35
+ * @internal
36
+ */
37
+ compose(conversion) {
38
+ return new UnitConversion(this.factor * conversion.factor, conversion.factor * this.offset + conversion.offset);
39
+ }
40
+ /**
41
+ * Multiples two UnitConversions together to calculate factor during reducing
42
+ * @internal
43
+ */
44
+ multiply(conversion) {
45
+ if (almostEqual(conversion.offset, 0.0) && almostEqual(this.offset, 0.0))
46
+ return new UnitConversion(this.factor * conversion.factor, 0.0);
47
+ throw new Error("Cannot multiply two maps with non-zero offsets");
48
+ }
49
+ /**
50
+ * Raise UnitConversion's factor with power exponent to calculate factor during reducing
51
+ * @internal
52
+ */
53
+ raise(power) {
54
+ if (almostEqual(power, 1.0))
55
+ return new UnitConversion(this.factor, this.offset);
56
+ else if (almostEqual(power, 0.0))
57
+ return new UnitConversion(1.0, 0.0);
58
+ if (almostEqual(this.offset, 0.0))
59
+ return new UnitConversion(this.factor ** power, 0.0);
60
+ throw new Error("Cannot raise map with non-zero offset");
61
+ }
62
+ /**
63
+ * Returns UnitConversion with unit's numerator and denominator in factor and unit's offset in offset for reducing
64
+ * @internal
65
+ */
66
+ static from(unit) {
67
+ if (unit.schemaItemType === SchemaItemType.Unit)
68
+ return new UnitConversion(unit.denominator / unit.numerator, -unit.offset);
69
+ return new UnitConversion(unit.denominator / unit.numerator, 0.0);
70
+ }
71
+ }
72
+ /** @internal */
73
+ UnitConversion.identity = new UnitConversion();
74
+ //# sourceMappingURL=UnitConversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnitConversion.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAG5C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB,YAA4B,SAAiB,GAAG,EAAkB,SAAiB,GAAG;QAA1D,WAAM,GAAN,MAAM,CAAc;QAAkB,WAAM,GAAN,MAAM,CAAc;IAAG,CAAC;IAE1F;;;;OAIG;IACI,QAAQ,CAAC,CAAS;QACvB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IACvC,CAAC;IAED;;;OAGG;IACI,OAAO;QACZ,MAAM,aAAa,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;QACxC,OAAO,IAAI,cAAc,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG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AAI,CAAC,MAAM,CAAC,CAAC;QAE7E,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC;;AAZD,gBAAgB;AACF,uBAAQ,GAAG,IAAI,cAAc,EAAE,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\nimport * as almostEqual from \"almost-equal\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\n\r\n/**\r\n * Class used for storing calculated conversion between two Units [[UnitConverter.calculateConversion]] and converting values from one Unit to another [[UnitConverter.evaluate]]\r\n * @internal\r\n */\r\nexport class UnitConversion {\r\n constructor(public readonly factor: number = 1.0, public readonly offset: number = 0.0) {}\r\n\r\n /**\r\n * Converts x using UnitConversion\r\n * @param x Input magnitude to be converted\r\n * @returns Output magnitude after conversion\r\n */\r\n public evaluate(x: number): number {\r\n return this.factor * x + this.offset;\r\n }\r\n\r\n /**\r\n * Used to invert source's UnitConversion so that it can be composed with target's UnitConversion cleanly\r\n * @internal\r\n */\r\n public inverse(): UnitConversion {\r\n const inverseFactor = 1.0 / this.factor;\r\n return new UnitConversion(inverseFactor, -this.offset * inverseFactor);\r\n }\r\n\r\n /**\r\n * Combines two UnitConversions\r\n * Used to combine source's UnitConversion and target's UnitConversion for a final UnitConversion that can be evaluated\r\n * @internal\r\n */\r\n public compose(conversion: UnitConversion): UnitConversion {\r\n return new UnitConversion(\r\n this.factor * conversion.factor,\r\n conversion.factor * this.offset + conversion.offset,\r\n );\r\n }\r\n\r\n /**\r\n * Multiples two UnitConversions together to calculate factor during reducing\r\n * @internal\r\n */\r\n public multiply(conversion: UnitConversion): UnitConversion {\r\n if (almostEqual(conversion.offset, 0.0) && almostEqual(this.offset, 0.0))\r\n return new UnitConversion(this.factor * conversion.factor, 0.0);\r\n\r\n throw new Error(\"Cannot multiply two maps with non-zero offsets\");\r\n }\r\n\r\n /**\r\n * Raise UnitConversion's factor with power exponent to calculate factor during reducing\r\n * @internal\r\n */\r\n public raise(power: number): UnitConversion {\r\n if (almostEqual(power, 1.0))\r\n return new UnitConversion(this.factor, this.offset);\r\n else if (almostEqual(power, 0.0))\r\n return new UnitConversion(1.0, 0.0);\r\n\r\n if (almostEqual(this.offset, 0.0))\r\n return new UnitConversion(this.factor ** power, 0.0);\r\n\r\n throw new Error(\"Cannot raise map with non-zero offset\");\r\n }\r\n\r\n /** @internal */\r\n public static identity = new UnitConversion();\r\n\r\n /**\r\n * Returns UnitConversion with unit's numerator and denominator in factor and unit's offset in offset for reducing\r\n * @internal\r\n */\r\n public static from(unit: Unit | Constant): UnitConversion {\r\n if (unit.schemaItemType === SchemaItemType.Unit)\r\n return new UnitConversion(unit.denominator / unit.numerator, -unit.offset);\r\n\r\n return new UnitConversion(unit.denominator / unit.numerator, 0.0);\r\n }\r\n}\r\n"]}