@itwin/ecschema-metadata 3.5.2 → 3.5.3

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 (141) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/cjs/Constants.d.ts +23 -23
  3. package/lib/cjs/Constants.js +33 -33
  4. package/lib/cjs/Constants.js.map +1 -1
  5. package/lib/cjs/Context.d.ts +139 -139
  6. package/lib/cjs/Context.js +204 -204
  7. package/lib/cjs/DelayedPromise.d.ts +88 -88
  8. package/lib/cjs/DelayedPromise.js +91 -91
  9. package/lib/cjs/DelayedPromise.js.map +1 -1
  10. package/lib/cjs/Deserialization/AbstractParser.d.ts +45 -45
  11. package/lib/cjs/Deserialization/AbstractParser.js +11 -11
  12. package/lib/cjs/Deserialization/AbstractParser.js.map +1 -1
  13. package/lib/cjs/Deserialization/Helper.d.ts +251 -251
  14. package/lib/cjs/Deserialization/Helper.js +843 -843
  15. package/lib/cjs/Deserialization/Helper.js.map +1 -1
  16. package/lib/cjs/Deserialization/JsonParser.d.ts +165 -165
  17. package/lib/cjs/Deserialization/JsonParser.js +680 -680
  18. package/lib/cjs/Deserialization/JsonParser.js.map +1 -1
  19. package/lib/cjs/Deserialization/JsonProps.d.ts +282 -282
  20. package/lib/cjs/Deserialization/JsonProps.js +9 -9
  21. package/lib/cjs/Deserialization/JsonProps.js.map +1 -1
  22. package/lib/cjs/Deserialization/SchemaGraphUtil.d.ts +34 -34
  23. package/lib/cjs/Deserialization/SchemaGraphUtil.js +77 -77
  24. package/lib/cjs/Deserialization/SchemaGraphUtil.js.map +1 -1
  25. package/lib/cjs/Deserialization/XmlParser.d.ts +85 -85
  26. package/lib/cjs/Deserialization/XmlParser.js +973 -973
  27. package/lib/cjs/Deserialization/XmlParser.js.map +1 -1
  28. package/lib/cjs/Deserialization/XmlSerializationUtils.d.ts +54 -54
  29. package/lib/cjs/Deserialization/XmlSerializationUtils.js +174 -174
  30. package/lib/cjs/Deserialization/XmlSerializationUtils.js.map +1 -1
  31. package/lib/cjs/ECName.d.ts +30 -30
  32. package/lib/cjs/ECName.js +85 -85
  33. package/lib/cjs/ECName.js.map +1 -1
  34. package/lib/cjs/ECObjects.d.ts +162 -162
  35. package/lib/cjs/ECObjects.js +453 -453
  36. package/lib/cjs/ECObjects.js.map +1 -1
  37. package/lib/cjs/Exception.d.ts +43 -43
  38. package/lib/cjs/Exception.js +86 -86
  39. package/lib/cjs/Exception.js.map +1 -1
  40. package/lib/cjs/Interfaces.d.ts +66 -66
  41. package/lib/cjs/Interfaces.js +9 -9
  42. package/lib/cjs/Interfaces.js.map +1 -1
  43. package/lib/cjs/Metadata/Class.d.ts +243 -243
  44. package/lib/cjs/Metadata/Class.js +558 -558
  45. package/lib/cjs/Metadata/Class.js.map +1 -1
  46. package/lib/cjs/Metadata/Constant.d.ts +64 -64
  47. package/lib/cjs/Metadata/Constant.js +123 -123
  48. package/lib/cjs/Metadata/Constant.js.map +1 -1
  49. package/lib/cjs/Metadata/CustomAttribute.d.ts +23 -23
  50. package/lib/cjs/Metadata/CustomAttribute.js +27 -27
  51. package/lib/cjs/Metadata/CustomAttribute.js.map +1 -1
  52. package/lib/cjs/Metadata/CustomAttributeClass.d.ts +39 -39
  53. package/lib/cjs/Metadata/CustomAttributeClass.js +68 -68
  54. package/lib/cjs/Metadata/CustomAttributeClass.js.map +1 -1
  55. package/lib/cjs/Metadata/EntityClass.d.ts +77 -77
  56. package/lib/cjs/Metadata/EntityClass.js +230 -230
  57. package/lib/cjs/Metadata/EntityClass.js.map +1 -1
  58. package/lib/cjs/Metadata/Enumeration.d.ts +86 -86
  59. package/lib/cjs/Metadata/Enumeration.js +159 -159
  60. package/lib/cjs/Metadata/Enumeration.js.map +1 -1
  61. package/lib/cjs/Metadata/Format.d.ts +98 -98
  62. package/lib/cjs/Metadata/Format.js +242 -242
  63. package/lib/cjs/Metadata/Format.js.map +1 -1
  64. package/lib/cjs/Metadata/InvertedUnit.d.ts +49 -49
  65. package/lib/cjs/Metadata/InvertedUnit.js +97 -97
  66. package/lib/cjs/Metadata/InvertedUnit.js.map +1 -1
  67. package/lib/cjs/Metadata/KindOfQuantity.d.ts +65 -65
  68. package/lib/cjs/Metadata/KindOfQuantity.js +225 -225
  69. package/lib/cjs/Metadata/KindOfQuantity.js.map +1 -1
  70. package/lib/cjs/Metadata/Mixin.d.ts +54 -54
  71. package/lib/cjs/Metadata/Mixin.js +113 -113
  72. package/lib/cjs/Metadata/Mixin.js.map +1 -1
  73. package/lib/cjs/Metadata/OverrideFormat.d.ts +55 -55
  74. package/lib/cjs/Metadata/OverrideFormat.js +88 -88
  75. package/lib/cjs/Metadata/OverrideFormat.js.map +1 -1
  76. package/lib/cjs/Metadata/Phenomenon.d.ts +33 -33
  77. package/lib/cjs/Metadata/Phenomenon.js +59 -59
  78. package/lib/cjs/Metadata/Phenomenon.js.map +1 -1
  79. package/lib/cjs/Metadata/Property.d.ts +197 -197
  80. package/lib/cjs/Metadata/Property.js +491 -491
  81. package/lib/cjs/Metadata/Property.js.map +1 -1
  82. package/lib/cjs/Metadata/PropertyCategory.d.ts +39 -39
  83. package/lib/cjs/Metadata/PropertyCategory.js +61 -61
  84. package/lib/cjs/Metadata/PropertyCategory.js.map +1 -1
  85. package/lib/cjs/Metadata/RelationshipClass.d.ts +152 -152
  86. package/lib/cjs/Metadata/RelationshipClass.js +349 -349
  87. package/lib/cjs/Metadata/RelationshipClass.js.map +1 -1
  88. package/lib/cjs/Metadata/Schema.d.ts +291 -291
  89. package/lib/cjs/Metadata/Schema.js +520 -520
  90. package/lib/cjs/Metadata/Schema.js.map +1 -1
  91. package/lib/cjs/Metadata/SchemaItem.d.ts +61 -61
  92. package/lib/cjs/Metadata/SchemaItem.js +136 -136
  93. package/lib/cjs/Metadata/SchemaItem.js.map +1 -1
  94. package/lib/cjs/Metadata/Unit.d.ts +76 -76
  95. package/lib/cjs/Metadata/Unit.js +162 -162
  96. package/lib/cjs/Metadata/UnitSystem.d.ts +20 -20
  97. package/lib/cjs/Metadata/UnitSystem.js +29 -29
  98. package/lib/cjs/Metadata/UnitSystem.js.map +1 -1
  99. package/lib/cjs/PropertyTypes.d.ts +49 -49
  100. package/lib/cjs/PropertyTypes.js +91 -91
  101. package/lib/cjs/PropertyTypes.js.map +1 -1
  102. package/lib/cjs/SchemaJsonLocater.d.ts +34 -34
  103. package/lib/cjs/SchemaJsonLocater.js +42 -42
  104. package/lib/cjs/SchemaJsonLocater.js.map +1 -1
  105. package/lib/cjs/SchemaKey.d.ts +110 -110
  106. package/lib/cjs/SchemaKey.js +219 -219
  107. package/lib/cjs/SchemaKey.js.map +1 -1
  108. package/lib/cjs/SchemaLoader.d.ts +23 -23
  109. package/lib/cjs/SchemaLoader.js +47 -47
  110. package/lib/cjs/SchemaLoader.js.map +1 -1
  111. package/lib/cjs/SchemaPartVisitorDelegate.d.ts +274 -274
  112. package/lib/cjs/SchemaPartVisitorDelegate.js +212 -212
  113. package/lib/cjs/SchemaPartVisitorDelegate.js.map +1 -1
  114. package/lib/cjs/UnitConversion/Graph.d.ts +34 -34
  115. package/lib/cjs/UnitConversion/Graph.js +83 -83
  116. package/lib/cjs/UnitConversion/Graph.js.map +1 -1
  117. package/lib/cjs/UnitConversion/Parser.d.ts +8 -8
  118. package/lib/cjs/UnitConversion/Parser.js +42 -42
  119. package/lib/cjs/UnitConversion/Parser.js.map +1 -1
  120. package/lib/cjs/UnitConversion/UnitConversion.d.ts +45 -45
  121. package/lib/cjs/UnitConversion/UnitConversion.js +77 -77
  122. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -1
  123. package/lib/cjs/UnitConversion/UnitConverter.d.ts +39 -39
  124. package/lib/cjs/UnitConversion/UnitConverter.js +116 -116
  125. package/lib/cjs/UnitConversion/UnitConverter.js.map +1 -1
  126. package/lib/cjs/UnitConversion/UnitTree.d.ts +43 -43
  127. package/lib/cjs/UnitConversion/UnitTree.js +169 -169
  128. package/lib/cjs/UnitConversion/UnitTree.js.map +1 -1
  129. package/lib/cjs/UnitProvider/SchemaUnitProvider.d.ts +77 -77
  130. package/lib/cjs/UnitProvider/SchemaUnitProvider.js +236 -236
  131. package/lib/cjs/UnitProvider/SchemaUnitProvider.js.map +1 -1
  132. package/lib/cjs/Validation/SchemaWalker.d.ts +23 -23
  133. package/lib/cjs/Validation/SchemaWalker.js +53 -53
  134. package/lib/cjs/Validation/SchemaWalker.js.map +1 -1
  135. package/lib/cjs/ecschema-metadata.d.ts +51 -51
  136. package/lib/cjs/ecschema-metadata.js +96 -96
  137. package/lib/cjs/ecschema-metadata.js.map +1 -1
  138. package/lib/cjs/utils/SchemaGraph.d.ts +25 -25
  139. package/lib/cjs/utils/SchemaGraph.js +65 -65
  140. package/lib/cjs/utils/SchemaGraph.js.map +1 -1
  141. package/package.json +7 -7
@@ -1,170 +1,170 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnitGraph = exports.GraphUtils = void 0;
4
- /*---------------------------------------------------------------------------------------------
5
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
- * See LICENSE.md in the project root for license terms and full copyright notice.
7
- *--------------------------------------------------------------------------------------------*/
8
- const core_bentley_1 = require("@itwin/core-bentley");
9
- const SchemaItem_1 = require("../Metadata/SchemaItem");
10
- const SchemaKey_1 = require("../SchemaKey");
11
- const ECObjects_1 = require("../ECObjects");
12
- const UnitConversion_1 = require("./UnitConversion");
13
- const Parser_1 = require("./Parser");
14
- const Graph_1 = require("./Graph");
15
- /** @internal */
16
- class GraphUtils {
17
- /**
18
- * DFS traversal - Post order
19
- * @param _graph Graph to traverse
20
- * @param start Starting node
21
- * @param keyFrom Get key from label
22
- * @param op Reducing function
23
- * @param initial Initial label
24
- */
25
- static dfsReduce(_graph, key, op, initial, baseUnitsMap, accumulatedExponent) {
26
- const outEdges = _graph.outEdges(key);
27
- let t = initial;
28
- if (outEdges.length > 0) {
29
- t = outEdges.reduce((p, edge) => {
30
- const { v, w } = edge;
31
- const edgeExponent = _graph.edge(v, w).exponent;
32
- return GraphUtils.dfsReduce(_graph, edge.w, op, p, baseUnitsMap, accumulatedExponent * edgeExponent);
33
- }, t);
34
- }
35
- else {
36
- if (baseUnitsMap.has(key)) {
37
- const oldExponent = baseUnitsMap.get(key);
38
- baseUnitsMap.set(key, oldExponent + accumulatedExponent);
39
- }
40
- else {
41
- baseUnitsMap.set(key, accumulatedExponent);
42
- }
43
- }
44
- return op(t, key);
45
- }
46
- }
47
- exports.GraphUtils = GraphUtils;
48
- /** @internal */
49
- class UnitGraph {
50
- constructor(_context) {
51
- this._context = _context;
52
- this._graph = new Graph_1.Graph();
53
- this._graph.setGraph("Unit tree processor");
54
- }
55
- /**
56
- * Tries to find the unit/constant given by name in currentSchema
57
- * @param name SchemaItem name or parsed definition to find unit of; Could be {schemaName}:{schemaItemName} or {alias}:{schemaItemName} or {schemaItemName}
58
- * @param currentSchema schema to find name in; name could also be in a referenced schema of current schema
59
- */
60
- async resolveUnit(name, currentSchema) {
61
- let [schemaName] = SchemaItem_1.SchemaItem.parseFullName(name);
62
- const [, schemaItemName] = SchemaItem_1.SchemaItem.parseFullName(name);
63
- if (schemaName !== "") {
64
- // Check if schemaName is schemaName or alias
65
- const ref = currentSchema.getReferenceSync(schemaName);
66
- const refName = currentSchema.getReferenceNameByAlias(schemaName);
67
- if (ref) {
68
- // Got schema by schemaName
69
- schemaName = ref.name;
70
- }
71
- else if (refName) {
72
- // Got schema by alias
73
- schemaName = refName;
74
- }
75
- else {
76
- // Didn't match any referenced schema, check if it is current schemaName or alias
77
- if (schemaName === currentSchema.name || schemaName === currentSchema.alias)
78
- schemaName = currentSchema.name;
79
- }
80
- // Create schema key with schema name
81
- const schemaKey = new SchemaKey_1.SchemaKey(schemaName);
82
- // Get schema with schema key
83
- const schema = await this._context.getSchema(schemaKey);
84
- if (!schema) {
85
- throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema", () => {
86
- return { schema: schemaName };
87
- });
88
- }
89
- else {
90
- // Set currentSchema to look up schemaItem to be whatever is prefixed in name
91
- currentSchema = schema;
92
- }
93
- // Update name to not have prefix
94
- name = schemaItemName;
95
- }
96
- // Create schema item key with name and schema
97
- const itemKey = new SchemaKey_1.SchemaItemKey(name, currentSchema.schemaKey);
98
- // Get schema item with schema item key
99
- const item = await this._context.getSchemaItem(itemKey);
100
- if (!item)
101
- throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema item", () => {
102
- return { item: name };
103
- });
104
- if (item.schemaItemType === ECObjects_1.SchemaItemType.Unit || item.schemaItemType === ECObjects_1.SchemaItemType.Constant)
105
- return item;
106
- throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Item is neither a unit or a constant", () => {
107
- return { itemType: item.key.fullName };
108
- });
109
- }
110
- /**
111
- * Adds unit and corresponding children to graph as well as edges between units
112
- * @param unit Current unit to be added to graph
113
- */
114
- async addUnit(unit) {
115
- if (this._graph.hasNode(unit.key.fullName))
116
- return;
117
- this._graph.setNode(unit.key.fullName, unit);
118
- if (this.isIdentity(unit))
119
- return;
120
- const umap = (0, Parser_1.parseDefinition)(unit.definition);
121
- const promiseArray = [];
122
- for (const [key, value] of umap) {
123
- promiseArray.push(this.resolveUnit(key, unit.schema).then((u) => [u, value]));
124
- }
125
- const resolved = await Promise.all(promiseArray);
126
- const children = resolved.map(async ([u, def]) => {
127
- await this.addUnit(u);
128
- this._graph.setEdge(unit.key.fullName, u.key.fullName, {
129
- exponent: def.exponent,
130
- });
131
- });
132
- await Promise.all(children);
133
- }
134
- isIdentity(unit) {
135
- return unit.definition === unit.name;
136
- }
137
- /**
138
- * Reduce the tree to produce a single map
139
- * @param unit Unit to be processed
140
- * @param stopNodes The tree exploration should stop here
141
- */
142
- reduce(unit, baseUnitsMap) {
143
- const unitFullName = unit.key.fullName;
144
- const innerMapStore = new Map();
145
- const outerMapStore = GraphUtils.dfsReduce(this._graph, unitFullName, (p, c) => this.reducingFunction(p, c), innerMapStore, baseUnitsMap, 1);
146
- return outerMapStore;
147
- }
148
- reducingFunction(innermapStore, unitFullName) {
149
- const outEdges = this._graph.outEdges(unitFullName);
150
- if (outEdges) {
151
- const cmap = outEdges.reduce((pm, e) => {
152
- const { exponent } = this._graph.edge(e.v, e.w);
153
- const stored = innermapStore.get(e.w);
154
- const map = stored ? stored : UnitConversion_1.UnitConversion.identity;
155
- const emap = map.raise(exponent);
156
- return pm ? pm.multiply(emap) : emap;
157
- }, undefined);
158
- const thisMap = this._graph.node(unitFullName) ? UnitConversion_1.UnitConversion.from(this._graph.node(unitFullName)) : UnitConversion_1.UnitConversion.identity;
159
- const other = cmap || UnitConversion_1.UnitConversion.identity;
160
- const result = other.compose(thisMap);
161
- innermapStore.set(unitFullName, result);
162
- }
163
- else {
164
- innermapStore.set(unitFullName, UnitConversion_1.UnitConversion.identity);
165
- }
166
- return innermapStore;
167
- }
168
- }
169
- exports.UnitGraph = UnitGraph;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnitGraph = exports.GraphUtils = void 0;
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
+ * See LICENSE.md in the project root for license terms and full copyright notice.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ const core_bentley_1 = require("@itwin/core-bentley");
9
+ const SchemaItem_1 = require("../Metadata/SchemaItem");
10
+ const SchemaKey_1 = require("../SchemaKey");
11
+ const ECObjects_1 = require("../ECObjects");
12
+ const UnitConversion_1 = require("./UnitConversion");
13
+ const Parser_1 = require("./Parser");
14
+ const Graph_1 = require("./Graph");
15
+ /** @internal */
16
+ class GraphUtils {
17
+ /**
18
+ * DFS traversal - Post order
19
+ * @param _graph Graph to traverse
20
+ * @param start Starting node
21
+ * @param keyFrom Get key from label
22
+ * @param op Reducing function
23
+ * @param initial Initial label
24
+ */
25
+ static dfsReduce(_graph, key, op, initial, baseUnitsMap, accumulatedExponent) {
26
+ const outEdges = _graph.outEdges(key);
27
+ let t = initial;
28
+ if (outEdges.length > 0) {
29
+ t = outEdges.reduce((p, edge) => {
30
+ const { v, w } = edge;
31
+ const edgeExponent = _graph.edge(v, w).exponent;
32
+ return GraphUtils.dfsReduce(_graph, edge.w, op, p, baseUnitsMap, accumulatedExponent * edgeExponent);
33
+ }, t);
34
+ }
35
+ else {
36
+ if (baseUnitsMap.has(key)) {
37
+ const oldExponent = baseUnitsMap.get(key);
38
+ baseUnitsMap.set(key, oldExponent + accumulatedExponent);
39
+ }
40
+ else {
41
+ baseUnitsMap.set(key, accumulatedExponent);
42
+ }
43
+ }
44
+ return op(t, key);
45
+ }
46
+ }
47
+ exports.GraphUtils = GraphUtils;
48
+ /** @internal */
49
+ class UnitGraph {
50
+ constructor(_context) {
51
+ this._context = _context;
52
+ this._graph = new Graph_1.Graph();
53
+ this._graph.setGraph("Unit tree processor");
54
+ }
55
+ /**
56
+ * Tries to find the unit/constant given by name in currentSchema
57
+ * @param name SchemaItem name or parsed definition to find unit of; Could be {schemaName}:{schemaItemName} or {alias}:{schemaItemName} or {schemaItemName}
58
+ * @param currentSchema schema to find name in; name could also be in a referenced schema of current schema
59
+ */
60
+ async resolveUnit(name, currentSchema) {
61
+ let [schemaName] = SchemaItem_1.SchemaItem.parseFullName(name);
62
+ const [, schemaItemName] = SchemaItem_1.SchemaItem.parseFullName(name);
63
+ if (schemaName !== "") {
64
+ // Check if schemaName is schemaName or alias
65
+ const ref = currentSchema.getReferenceSync(schemaName);
66
+ const refName = currentSchema.getReferenceNameByAlias(schemaName);
67
+ if (ref) {
68
+ // Got schema by schemaName
69
+ schemaName = ref.name;
70
+ }
71
+ else if (refName) {
72
+ // Got schema by alias
73
+ schemaName = refName;
74
+ }
75
+ else {
76
+ // Didn't match any referenced schema, check if it is current schemaName or alias
77
+ if (schemaName === currentSchema.name || schemaName === currentSchema.alias)
78
+ schemaName = currentSchema.name;
79
+ }
80
+ // Create schema key with schema name
81
+ const schemaKey = new SchemaKey_1.SchemaKey(schemaName);
82
+ // Get schema with schema key
83
+ const schema = await this._context.getSchema(schemaKey);
84
+ if (!schema) {
85
+ throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema", () => {
86
+ return { schema: schemaName };
87
+ });
88
+ }
89
+ else {
90
+ // Set currentSchema to look up schemaItem to be whatever is prefixed in name
91
+ currentSchema = schema;
92
+ }
93
+ // Update name to not have prefix
94
+ name = schemaItemName;
95
+ }
96
+ // Create schema item key with name and schema
97
+ const itemKey = new SchemaKey_1.SchemaItemKey(name, currentSchema.schemaKey);
98
+ // Get schema item with schema item key
99
+ const item = await this._context.getSchemaItem(itemKey);
100
+ if (!item)
101
+ throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Cannot find schema item", () => {
102
+ return { item: name };
103
+ });
104
+ if (item.schemaItemType === ECObjects_1.SchemaItemType.Unit || item.schemaItemType === ECObjects_1.SchemaItemType.Constant)
105
+ return item;
106
+ throw new core_bentley_1.BentleyError(core_bentley_1.BentleyStatus.ERROR, "Item is neither a unit or a constant", () => {
107
+ return { itemType: item.key.fullName };
108
+ });
109
+ }
110
+ /**
111
+ * Adds unit and corresponding children to graph as well as edges between units
112
+ * @param unit Current unit to be added to graph
113
+ */
114
+ async addUnit(unit) {
115
+ if (this._graph.hasNode(unit.key.fullName))
116
+ return;
117
+ this._graph.setNode(unit.key.fullName, unit);
118
+ if (this.isIdentity(unit))
119
+ return;
120
+ const umap = (0, Parser_1.parseDefinition)(unit.definition);
121
+ const promiseArray = [];
122
+ for (const [key, value] of umap) {
123
+ promiseArray.push(this.resolveUnit(key, unit.schema).then((u) => [u, value]));
124
+ }
125
+ const resolved = await Promise.all(promiseArray);
126
+ const children = resolved.map(async ([u, def]) => {
127
+ await this.addUnit(u);
128
+ this._graph.setEdge(unit.key.fullName, u.key.fullName, {
129
+ exponent: def.exponent,
130
+ });
131
+ });
132
+ await Promise.all(children);
133
+ }
134
+ isIdentity(unit) {
135
+ return unit.definition === unit.name;
136
+ }
137
+ /**
138
+ * Reduce the tree to produce a single map
139
+ * @param unit Unit to be processed
140
+ * @param stopNodes The tree exploration should stop here
141
+ */
142
+ reduce(unit, baseUnitsMap) {
143
+ const unitFullName = unit.key.fullName;
144
+ const innerMapStore = new Map();
145
+ const outerMapStore = GraphUtils.dfsReduce(this._graph, unitFullName, (p, c) => this.reducingFunction(p, c), innerMapStore, baseUnitsMap, 1);
146
+ return outerMapStore;
147
+ }
148
+ reducingFunction(innermapStore, unitFullName) {
149
+ const outEdges = this._graph.outEdges(unitFullName);
150
+ if (outEdges) {
151
+ const cmap = outEdges.reduce((pm, e) => {
152
+ const { exponent } = this._graph.edge(e.v, e.w);
153
+ const stored = innermapStore.get(e.w);
154
+ const map = stored ? stored : UnitConversion_1.UnitConversion.identity;
155
+ const emap = map.raise(exponent);
156
+ return pm ? pm.multiply(emap) : emap;
157
+ }, undefined);
158
+ const thisMap = this._graph.node(unitFullName) ? UnitConversion_1.UnitConversion.from(this._graph.node(unitFullName)) : UnitConversion_1.UnitConversion.identity;
159
+ const other = cmap || UnitConversion_1.UnitConversion.identity;
160
+ const result = other.compose(thisMap);
161
+ innermapStore.set(unitFullName, result);
162
+ }
163
+ else {
164
+ innermapStore.set(unitFullName, UnitConversion_1.UnitConversion.identity);
165
+ }
166
+ return innermapStore;
167
+ }
168
+ }
169
+ exports.UnitGraph = UnitGraph;
170
170
  //# sourceMappingURL=UnitTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UnitTree.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitTree.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAIlE,uDAAoD;AAEpD,4CAAwD;AACxD,4CAA8C;AAC9C,qDAAkD;AAClD,qCAA+D;AAC/D,mCAAgC;AAEhC,gBAAgB;AAChB,MAAa,UAAU;IACrB;;;;;;;OAOG;IACI,MAAM,CAAC,SAAS,CAAI,MAA8B,EAAE,GAA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* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\nimport { SchemaContext } from \"../Context\";\nimport { Constant } from \"../Metadata/Constant\";\nimport { Schema } from \"../Metadata/Schema\";\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\nimport { Unit } from \"../Metadata/Unit\";\nimport { SchemaItemKey, SchemaKey } from \"../SchemaKey\";\nimport { SchemaItemType } from \"../ECObjects\";\nimport { UnitConversion } from \"./UnitConversion\";\nimport { DefinitionFragment, parseDefinition } from \"./Parser\";\nimport { Graph } from \"./Graph\";\n\n/** @internal */\nexport class GraphUtils {\n /**\n * DFS traversal - Post order\n * @param _graph Graph to traverse\n * @param start Starting node\n * @param keyFrom Get key from label\n * @param op Reducing function\n * @param initial Initial label\n */\n public static dfsReduce<T>(_graph: Graph<Unit | Constant>, key: string, op: (previous: T, current: string) => T, initial: T, baseUnitsMap: Map<string, number>, accumulatedExponent: number): T {\n const outEdges = _graph.outEdges(key);\n let t = initial;\n if (outEdges.length > 0) {\n t = outEdges.reduce<T>(\n (p, edge) => {\n const { v, w } = edge;\n const edgeExponent = _graph.edge(v, w).exponent;\n return GraphUtils.dfsReduce(_graph, edge.w, op, p, baseUnitsMap, accumulatedExponent * edgeExponent);\n },\n t\n );\n } else {\n if (baseUnitsMap.has(key)) {\n const oldExponent = baseUnitsMap.get(key)!;\n baseUnitsMap.set(key, oldExponent + accumulatedExponent);\n } else {\n baseUnitsMap.set(key, accumulatedExponent);\n }\n }\n\n return op(t, key);\n }\n}\n\n/** @internal */\nexport class UnitGraph {\n private _graph = new Graph<Unit | Constant>();\n\n constructor(private _context: SchemaContext) {\n this._graph.setGraph(\"Unit tree processor\");\n }\n\n /**\n * Tries to find the unit/constant given by name in currentSchema\n * @param name SchemaItem name or parsed definition to find unit of; Could be {schemaName}:{schemaItemName} or {alias}:{schemaItemName} or {schemaItemName}\n * @param currentSchema schema to find name in; name could also be in a referenced schema of current schema\n */\n public async resolveUnit(name: string, currentSchema: Schema): Promise<Unit | Constant> {\n let [schemaName] = SchemaItem.parseFullName(name);\n const [, schemaItemName] = SchemaItem.parseFullName(name);\n\n if (schemaName !== \"\") {\n // Check if schemaName is schemaName or alias\n const ref = currentSchema.getReferenceSync(schemaName);\n const refName = currentSchema.getReferenceNameByAlias(schemaName);\n if (ref) {\n // Got schema by schemaName\n schemaName = ref.name;\n } else if (refName) {\n // Got schema by alias\n schemaName = refName;\n } else {\n // Didn't match any referenced schema, check if it is current schemaName or alias\n if (schemaName === currentSchema.name || schemaName === currentSchema.alias)\n schemaName = currentSchema.name;\n }\n\n // Create schema key with schema name\n const schemaKey = new SchemaKey(schemaName);\n // Get schema with schema key\n const schema = await this._context.getSchema(schemaKey);\n if (!schema) {\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema\", () => {\n return { schema: schemaName };\n });\n } else {\n // Set currentSchema to look up schemaItem to be whatever is prefixed in name\n currentSchema = schema;\n }\n // Update name to not have prefix\n name = schemaItemName;\n }\n\n // Create schema item key with name and schema\n const itemKey = new SchemaItemKey(name, currentSchema.schemaKey);\n // Get schema item with schema item key\n const item = await this._context.getSchemaItem(itemKey);\n if (!item)\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item\", () => {\n return { item: name };\n });\n\n if (item.schemaItemType === SchemaItemType.Unit || item.schemaItemType === SchemaItemType.Constant)\n return item as Unit | Constant;\n\n throw new BentleyError(BentleyStatus.ERROR, \"Item is neither a unit or a constant\", () => {\n return { itemType: item.key.fullName };\n });\n }\n\n /**\n * Adds unit and corresponding children to graph as well as edges between units\n * @param unit Current unit to be added to graph\n */\n public async addUnit(unit: Unit | Constant): Promise<void> {\n if (this._graph.hasNode(unit.key.fullName))\n return;\n\n this._graph.setNode(unit.key.fullName, unit);\n if (this.isIdentity(unit))\n return;\n\n const umap = parseDefinition(unit.definition);\n\n const promiseArray: Promise<[Unit | Constant, DefinitionFragment]>[] = [];\n for (const [key, value] of umap) {\n promiseArray.push(\n this.resolveUnit(key, unit.schema).then((u) => [u, value])\n );\n }\n const resolved = await Promise.all<[Unit | Constant, DefinitionFragment]>(\n promiseArray\n );\n\n const children = resolved.map(async ([u, def]) => {\n await this.addUnit(u);\n this._graph.setEdge(unit.key.fullName, u.key.fullName, {\n exponent: def.exponent,\n });\n });\n\n await Promise.all(children);\n }\n\n private isIdentity(unit: Unit | Constant) {\n return unit.definition === unit.name;\n }\n\n /**\n * Reduce the tree to produce a single map\n * @param unit Unit to be processed\n * @param stopNodes The tree exploration should stop here\n */\n public reduce(unit: Unit | Constant, baseUnitsMap: Map<string, number>): Map<string, UnitConversion> {\n const unitFullName = unit.key.fullName;\n const innerMapStore = new Map<string, UnitConversion>();\n const outerMapStore = GraphUtils.dfsReduce(this._graph, unitFullName, (p, c) => this.reducingFunction(p, c), innerMapStore, baseUnitsMap, 1);\n return outerMapStore;\n }\n\n private reducingFunction(innermapStore: Map<string, UnitConversion>, unitFullName: string) {\n const outEdges = this._graph.outEdges(unitFullName);\n if (outEdges) {\n const cmap = outEdges.reduce<UnitConversion | undefined>((pm, e) => {\n const { exponent } = this._graph.edge(e.v, e.w);\n const stored = innermapStore.get(e.w);\n const map = stored ? stored : UnitConversion.identity;\n const emap = map.raise(exponent);\n return pm ? pm.multiply(emap) : emap;\n }, undefined);\n const thisMap = this._graph.node(unitFullName) ? UnitConversion.from(this._graph.node(unitFullName)) : UnitConversion.identity;\n const other = cmap || UnitConversion.identity;\n const result = other.compose(thisMap);\n innermapStore.set(unitFullName, result);\n } else {\n innermapStore.set(unitFullName, UnitConversion.identity);\n }\n return innermapStore;\n }\n}\n"]}
1
+ {"version":3,"file":"UnitTree.js","sourceRoot":"","sources":["../../../src/UnitConversion/UnitTree.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAkE;AAIlE,uDAAoD;AAEpD,4CAAwD;AACxD,4CAA8C;AAC9C,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AY,EAAE,+BAAc,CAAC,QAAQ,CAAC,CAAC;SAC1D;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAtID,8BAsIC","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 { BentleyError, BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { SchemaContext } from \"../Context\";\r\nimport { Constant } from \"../Metadata/Constant\";\r\nimport { Schema } from \"../Metadata/Schema\";\r\nimport { SchemaItem } from \"../Metadata/SchemaItem\";\r\nimport { Unit } from \"../Metadata/Unit\";\r\nimport { SchemaItemKey, SchemaKey } from \"../SchemaKey\";\r\nimport { SchemaItemType } from \"../ECObjects\";\r\nimport { UnitConversion } from \"./UnitConversion\";\r\nimport { DefinitionFragment, parseDefinition } from \"./Parser\";\r\nimport { Graph } from \"./Graph\";\r\n\r\n/** @internal */\r\nexport class GraphUtils {\r\n /**\r\n * DFS traversal - Post order\r\n * @param _graph Graph to traverse\r\n * @param start Starting node\r\n * @param keyFrom Get key from label\r\n * @param op Reducing function\r\n * @param initial Initial label\r\n */\r\n public static dfsReduce<T>(_graph: Graph<Unit | Constant>, key: string, op: (previous: T, current: string) => T, initial: T, baseUnitsMap: Map<string, number>, accumulatedExponent: number): T {\r\n const outEdges = _graph.outEdges(key);\r\n let t = initial;\r\n if (outEdges.length > 0) {\r\n t = outEdges.reduce<T>(\r\n (p, edge) => {\r\n const { v, w } = edge;\r\n const edgeExponent = _graph.edge(v, w).exponent;\r\n return GraphUtils.dfsReduce(_graph, edge.w, op, p, baseUnitsMap, accumulatedExponent * edgeExponent);\r\n },\r\n t\r\n );\r\n } else {\r\n if (baseUnitsMap.has(key)) {\r\n const oldExponent = baseUnitsMap.get(key)!;\r\n baseUnitsMap.set(key, oldExponent + accumulatedExponent);\r\n } else {\r\n baseUnitsMap.set(key, accumulatedExponent);\r\n }\r\n }\r\n\r\n return op(t, key);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class UnitGraph {\r\n private _graph = new Graph<Unit | Constant>();\r\n\r\n constructor(private _context: SchemaContext) {\r\n this._graph.setGraph(\"Unit tree processor\");\r\n }\r\n\r\n /**\r\n * Tries to find the unit/constant given by name in currentSchema\r\n * @param name SchemaItem name or parsed definition to find unit of; Could be {schemaName}:{schemaItemName} or {alias}:{schemaItemName} or {schemaItemName}\r\n * @param currentSchema schema to find name in; name could also be in a referenced schema of current schema\r\n */\r\n public async resolveUnit(name: string, currentSchema: Schema): Promise<Unit | Constant> {\r\n let [schemaName] = SchemaItem.parseFullName(name);\r\n const [, schemaItemName] = SchemaItem.parseFullName(name);\r\n\r\n if (schemaName !== \"\") {\r\n // Check if schemaName is schemaName or alias\r\n const ref = currentSchema.getReferenceSync(schemaName);\r\n const refName = currentSchema.getReferenceNameByAlias(schemaName);\r\n if (ref) {\r\n // Got schema by schemaName\r\n schemaName = ref.name;\r\n } else if (refName) {\r\n // Got schema by alias\r\n schemaName = refName;\r\n } else {\r\n // Didn't match any referenced schema, check if it is current schemaName or alias\r\n if (schemaName === currentSchema.name || schemaName === currentSchema.alias)\r\n schemaName = currentSchema.name;\r\n }\r\n\r\n // Create schema key with schema name\r\n const schemaKey = new SchemaKey(schemaName);\r\n // Get schema with schema key\r\n const schema = await this._context.getSchema(schemaKey);\r\n if (!schema) {\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema\", () => {\r\n return { schema: schemaName };\r\n });\r\n } else {\r\n // Set currentSchema to look up schemaItem to be whatever is prefixed in name\r\n currentSchema = schema;\r\n }\r\n // Update name to not have prefix\r\n name = schemaItemName;\r\n }\r\n\r\n // Create schema item key with name and schema\r\n const itemKey = new SchemaItemKey(name, currentSchema.schemaKey);\r\n // Get schema item with schema item key\r\n const item = await this._context.getSchemaItem(itemKey);\r\n if (!item)\r\n throw new BentleyError(BentleyStatus.ERROR, \"Cannot find schema item\", () => {\r\n return { item: name };\r\n });\r\n\r\n if (item.schemaItemType === SchemaItemType.Unit || item.schemaItemType === SchemaItemType.Constant)\r\n return item as Unit | Constant;\r\n\r\n throw new BentleyError(BentleyStatus.ERROR, \"Item is neither a unit or a constant\", () => {\r\n return { itemType: item.key.fullName };\r\n });\r\n }\r\n\r\n /**\r\n * Adds unit and corresponding children to graph as well as edges between units\r\n * @param unit Current unit to be added to graph\r\n */\r\n public async addUnit(unit: Unit | Constant): Promise<void> {\r\n if (this._graph.hasNode(unit.key.fullName))\r\n return;\r\n\r\n this._graph.setNode(unit.key.fullName, unit);\r\n if (this.isIdentity(unit))\r\n return;\r\n\r\n const umap = parseDefinition(unit.definition);\r\n\r\n const promiseArray: Promise<[Unit | Constant, DefinitionFragment]>[] = [];\r\n for (const [key, value] of umap) {\r\n promiseArray.push(\r\n this.resolveUnit(key, unit.schema).then((u) => [u, value])\r\n );\r\n }\r\n const resolved = await Promise.all<[Unit | Constant, DefinitionFragment]>(\r\n promiseArray\r\n );\r\n\r\n const children = resolved.map(async ([u, def]) => {\r\n await this.addUnit(u);\r\n this._graph.setEdge(unit.key.fullName, u.key.fullName, {\r\n exponent: def.exponent,\r\n });\r\n });\r\n\r\n await Promise.all(children);\r\n }\r\n\r\n private isIdentity(unit: Unit | Constant) {\r\n return unit.definition === unit.name;\r\n }\r\n\r\n /**\r\n * Reduce the tree to produce a single map\r\n * @param unit Unit to be processed\r\n * @param stopNodes The tree exploration should stop here\r\n */\r\n public reduce(unit: Unit | Constant, baseUnitsMap: Map<string, number>): Map<string, UnitConversion> {\r\n const unitFullName = unit.key.fullName;\r\n const innerMapStore = new Map<string, UnitConversion>();\r\n const outerMapStore = GraphUtils.dfsReduce(this._graph, unitFullName, (p, c) => this.reducingFunction(p, c), innerMapStore, baseUnitsMap, 1);\r\n return outerMapStore;\r\n }\r\n\r\n private reducingFunction(innermapStore: Map<string, UnitConversion>, unitFullName: string) {\r\n const outEdges = this._graph.outEdges(unitFullName);\r\n if (outEdges) {\r\n const cmap = outEdges.reduce<UnitConversion | undefined>((pm, e) => {\r\n const { exponent } = this._graph.edge(e.v, e.w);\r\n const stored = innermapStore.get(e.w);\r\n const map = stored ? stored : UnitConversion.identity;\r\n const emap = map.raise(exponent);\r\n return pm ? pm.multiply(emap) : emap;\r\n }, undefined);\r\n const thisMap = this._graph.node(unitFullName) ? UnitConversion.from(this._graph.node(unitFullName)) : UnitConversion.identity;\r\n const other = cmap || UnitConversion.identity;\r\n const result = other.compose(thisMap);\r\n innermapStore.set(unitFullName, result);\r\n } else {\r\n innermapStore.set(unitFullName, UnitConversion.identity);\r\n }\r\n return innermapStore;\r\n }\r\n}\r\n"]}
@@ -1,78 +1,78 @@
1
- import { UnitConversion, UnitExtraData, UnitProps, UnitsProvider } from "@itwin/core-quantity";
2
- import { ISchemaLocater } from "../Context";
3
- /**
4
- * Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.
5
- * @alpha
6
- */
7
- export declare class SchemaUnitProvider implements UnitsProvider {
8
- private _unitExtraData;
9
- private _unitConverter;
10
- private _context;
11
- /**
12
- *
13
- * @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext
14
- * class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be
15
- * created and the locater will be added.
16
- * @param _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.
17
- */
18
- constructor(contextOrLocater: ISchemaLocater, _unitExtraData?: UnitExtraData[]);
19
- /**
20
- * Find unit in a schema that has unitName.
21
- * @param unitName Full name of unit.
22
- * @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.
23
- */
24
- findUnitByName(unitName: string): Promise<UnitProps>;
25
- /**
26
- * Find all units in context that belongs to given phenomenon.
27
- * @param phenomenon Full name of phenomenon.
28
- * @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.
29
- */
30
- getUnitsByFamily(phenomenon: string): Promise<Array<UnitProps>>;
31
- /**
32
- * Find alternate display labels associated with unitName, if any.
33
- * @param unitName Full name of Unit.
34
- */
35
- getAlternateDisplayLabels(unitName: string): Array<string>;
36
- /**
37
- * Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in
38
- * this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display
39
- * labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.
40
- *
41
- * @param unitLabel Display label or alternate display label to query unit by.
42
- * @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.
43
- * @param phenomenon Full name of phenomenon that Unit belongs to.
44
- * @param unitSystem Full name of unitSystem that Unit belongs to.
45
- * @returns The UnitProps interface from the @itwin/core-quantity package.
46
- */
47
- findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
48
- /**
49
- * Gets the @itwin/core-quantity UnitConversion for the given fromUnit and toUnit.
50
- * @param fromUnit The UnitProps of the 'from' unit.
51
- * @param toUnit The UnitProps of the 'to' unit.
52
- * @returns The UnitConversion interface from the @itwin/core-quantity package.
53
- */
54
- getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;
55
- /**
56
- * Find unit in a schema that has unitName.
57
- * @param unitName Full name of unit.
58
- * @returns Unit whose full name matches unitName.
59
- */
60
- private findECUnitByName;
61
- /**
62
- * Gets the @itwin/core UnitProps for the given Unit.
63
- * @param unit The Unit to convert.
64
- * @returns UnitProps interface from @itwin/core.
65
- */
66
- private getUnitsProps;
67
- /**
68
- * Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
69
- * @internal
70
- */
71
- private findUnitByDisplayLabel;
72
- /**
73
- * Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
74
- * @internal
75
- */
76
- private findUnitByAltDisplayLabel;
77
- }
1
+ import { UnitConversion, UnitExtraData, UnitProps, UnitsProvider } from "@itwin/core-quantity";
2
+ import { ISchemaLocater } from "../Context";
3
+ /**
4
+ * Class used to find Units in SchemaContext by attributes such as Phenomenon and DisplayLabel.
5
+ * @alpha
6
+ */
7
+ export declare class SchemaUnitProvider implements UnitsProvider {
8
+ private _unitExtraData;
9
+ private _unitConverter;
10
+ private _context;
11
+ /**
12
+ *
13
+ * @param contextOrLocater The SchemaContext or a different ISchemaLocater implementation used to retrieve the schema. The SchemaContext
14
+ * class implements the ISchemaLocater interface. If the provided locater is not a SchemaContext instance a new SchemaContext will be
15
+ * created and the locater will be added.
16
+ * @param _unitExtraData Additional data like alternate display label not found in Units Schema to match with Units; Defaults to empty array.
17
+ */
18
+ constructor(contextOrLocater: ISchemaLocater, _unitExtraData?: UnitExtraData[]);
19
+ /**
20
+ * Find unit in a schema that has unitName.
21
+ * @param unitName Full name of unit.
22
+ * @returns UnitProps interface from @itwin/core-quantity whose name matches unitName.
23
+ */
24
+ findUnitByName(unitName: string): Promise<UnitProps>;
25
+ /**
26
+ * Find all units in context that belongs to given phenomenon.
27
+ * @param phenomenon Full name of phenomenon.
28
+ * @returns Array of UnitProps (from @itwin/core-quantity) interface objects whose name matches phenomenon param.
29
+ */
30
+ getUnitsByFamily(phenomenon: string): Promise<Array<UnitProps>>;
31
+ /**
32
+ * Find alternate display labels associated with unitName, if any.
33
+ * @param unitName Full name of Unit.
34
+ */
35
+ getAlternateDisplayLabels(unitName: string): Array<string>;
36
+ /**
37
+ * Finds Unit by unitLabel, which could be a display label in the schema or alternate an display label defined in
38
+ * this._unitExtraData. If there are duplicates of the same display label in the context or teh same alternate display
39
+ * labels, specify schemaName, phenomenon, or unitSystem to get a specific unit.
40
+ *
41
+ * @param unitLabel Display label or alternate display label to query unit by.
42
+ * @param schemaName Ensure Unit with unitLabel belongs to Schema with schemaName.
43
+ * @param phenomenon Full name of phenomenon that Unit belongs to.
44
+ * @param unitSystem Full name of unitSystem that Unit belongs to.
45
+ * @returns The UnitProps interface from the @itwin/core-quantity package.
46
+ */
47
+ findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
48
+ /**
49
+ * Gets the @itwin/core-quantity UnitConversion for the given fromUnit and toUnit.
50
+ * @param fromUnit The UnitProps of the 'from' unit.
51
+ * @param toUnit The UnitProps of the 'to' unit.
52
+ * @returns The UnitConversion interface from the @itwin/core-quantity package.
53
+ */
54
+ getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;
55
+ /**
56
+ * Find unit in a schema that has unitName.
57
+ * @param unitName Full name of unit.
58
+ * @returns Unit whose full name matches unitName.
59
+ */
60
+ private findECUnitByName;
61
+ /**
62
+ * Gets the @itwin/core UnitProps for the given Unit.
63
+ * @param unit The Unit to convert.
64
+ * @returns UnitProps interface from @itwin/core.
65
+ */
66
+ private getUnitsProps;
67
+ /**
68
+ * Finds Unit by displayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
69
+ * @internal
70
+ */
71
+ private findUnitByDisplayLabel;
72
+ /**
73
+ * Finds Unit by altDisplayLabel and that it belongs to schemaName, phenomenon, and unitSystem if defined.
74
+ * @internal
75
+ */
76
+ private findUnitByAltDisplayLabel;
77
+ }
78
78
  //# sourceMappingURL=SchemaUnitProvider.d.ts.map