@itwin/core-quantity 5.9.0-dev.9 → 5.10.0-dev.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 (152) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/lib/cjs/BasicUnitsProvider.d.ts +44 -0
  3. package/lib/cjs/BasicUnitsProvider.d.ts.map +1 -0
  4. package/lib/cjs/BasicUnitsProvider.js +241 -0
  5. package/lib/cjs/BasicUnitsProvider.js.map +1 -0
  6. package/lib/cjs/CompositeUnitsProvider.d.ts +45 -0
  7. package/lib/cjs/CompositeUnitsProvider.d.ts.map +1 -0
  8. package/lib/cjs/CompositeUnitsProvider.js +111 -0
  9. package/lib/cjs/CompositeUnitsProvider.js.map +1 -0
  10. package/lib/cjs/Constants.js.map +1 -1
  11. package/lib/cjs/Exception.js.map +1 -1
  12. package/lib/cjs/FormatSpecHandle.d.ts +56 -0
  13. package/lib/cjs/FormatSpecHandle.d.ts.map +1 -0
  14. package/lib/cjs/FormatSpecHandle.js +87 -0
  15. package/lib/cjs/FormatSpecHandle.js.map +1 -0
  16. package/lib/cjs/Formatter/Format.js.map +1 -1
  17. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  18. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  19. package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
  20. package/lib/cjs/Formatter/FormatterSpec.js +14 -0
  21. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  22. package/lib/cjs/Formatter/FormattingReadyCollector.d.ts +16 -0
  23. package/lib/cjs/Formatter/FormattingReadyCollector.d.ts.map +1 -0
  24. package/lib/cjs/Formatter/FormattingReadyCollector.js +44 -0
  25. package/lib/cjs/Formatter/FormattingReadyCollector.js.map +1 -0
  26. package/lib/cjs/Formatter/Interfaces.d.ts +51 -3
  27. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  28. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  29. package/lib/cjs/Interfaces.d.ts +31 -1
  30. package/lib/cjs/Interfaces.d.ts.map +1 -1
  31. package/lib/cjs/Interfaces.js.map +1 -1
  32. package/lib/cjs/Parser.d.ts.map +1 -1
  33. package/lib/cjs/Parser.js +16 -1
  34. package/lib/cjs/Parser.js.map +1 -1
  35. package/lib/cjs/ParserSpec.d.ts.map +1 -1
  36. package/lib/cjs/ParserSpec.js +15 -2
  37. package/lib/cjs/ParserSpec.js.map +1 -1
  38. package/lib/cjs/Quantity.js.map +1 -1
  39. package/lib/cjs/QuantityLoggerCategory.d.ts +16 -0
  40. package/lib/cjs/QuantityLoggerCategory.d.ts.map +1 -0
  41. package/lib/cjs/QuantityLoggerCategory.js +24 -0
  42. package/lib/cjs/QuantityLoggerCategory.js.map +1 -0
  43. package/lib/cjs/SerializedUnitSchema.d.ts +98 -0
  44. package/lib/cjs/SerializedUnitSchema.d.ts.map +1 -0
  45. package/lib/cjs/SerializedUnitSchema.js +25 -0
  46. package/lib/cjs/SerializedUnitSchema.js.map +1 -0
  47. package/lib/cjs/Unit.js.map +1 -1
  48. package/lib/cjs/UnitConversion/Graph.d.ts +35 -0
  49. package/lib/cjs/UnitConversion/Graph.d.ts.map +1 -0
  50. package/lib/cjs/UnitConversion/Graph.js +87 -0
  51. package/lib/cjs/UnitConversion/Graph.js.map +1 -0
  52. package/lib/cjs/UnitConversion/Parser.d.ts +9 -0
  53. package/lib/cjs/UnitConversion/Parser.d.ts.map +1 -0
  54. package/lib/cjs/UnitConversion/Parser.js +42 -0
  55. package/lib/cjs/UnitConversion/Parser.js.map +1 -0
  56. package/lib/cjs/UnitConversion/UnitConversion.d.ts +56 -0
  57. package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -0
  58. package/lib/cjs/UnitConversion/UnitConversion.js +80 -0
  59. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -0
  60. package/lib/cjs/UnitConversion/UnitDefinitionResolver.d.ts +29 -0
  61. package/lib/cjs/UnitConversion/UnitDefinitionResolver.d.ts.map +1 -0
  62. package/lib/cjs/UnitConversion/UnitDefinitionResolver.js +102 -0
  63. package/lib/cjs/UnitConversion/UnitDefinitionResolver.js.map +1 -0
  64. package/lib/cjs/UnitConversion/nameUtils.d.ts +11 -0
  65. package/lib/cjs/UnitConversion/nameUtils.d.ts.map +1 -0
  66. package/lib/cjs/UnitConversion/nameUtils.js +25 -0
  67. package/lib/cjs/UnitConversion/nameUtils.js.map +1 -0
  68. package/lib/cjs/assets/Units.json +4215 -0
  69. package/lib/cjs/core-quantity.d.ts +22 -1
  70. package/lib/cjs/core-quantity.d.ts.map +1 -1
  71. package/lib/cjs/core-quantity.js +24 -1
  72. package/lib/cjs/core-quantity.js.map +1 -1
  73. package/lib/cjs/internal/cross-package.d.ts +4 -0
  74. package/lib/cjs/internal/cross-package.d.ts.map +1 -0
  75. package/lib/cjs/internal/cross-package.js +13 -0
  76. package/lib/cjs/internal/cross-package.js.map +1 -0
  77. package/lib/esm/BasicUnitsProvider.d.ts +44 -0
  78. package/lib/esm/BasicUnitsProvider.d.ts.map +1 -0
  79. package/lib/esm/BasicUnitsProvider.js +213 -0
  80. package/lib/esm/BasicUnitsProvider.js.map +1 -0
  81. package/lib/esm/CompositeUnitsProvider.d.ts +45 -0
  82. package/lib/esm/CompositeUnitsProvider.d.ts.map +1 -0
  83. package/lib/esm/CompositeUnitsProvider.js +108 -0
  84. package/lib/esm/CompositeUnitsProvider.js.map +1 -0
  85. package/lib/esm/Constants.js.map +1 -1
  86. package/lib/esm/Exception.js.map +1 -1
  87. package/lib/esm/FormatSpecHandle.d.ts +56 -0
  88. package/lib/esm/FormatSpecHandle.d.ts.map +1 -0
  89. package/lib/esm/FormatSpecHandle.js +83 -0
  90. package/lib/esm/FormatSpecHandle.js.map +1 -0
  91. package/lib/esm/Formatter/Format.js.map +1 -1
  92. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  93. package/lib/esm/Formatter/Formatter.js.map +1 -1
  94. package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
  95. package/lib/esm/Formatter/FormatterSpec.js +14 -0
  96. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  97. package/lib/esm/Formatter/FormattingReadyCollector.d.ts +16 -0
  98. package/lib/esm/Formatter/FormattingReadyCollector.d.ts.map +1 -0
  99. package/lib/esm/Formatter/FormattingReadyCollector.js +40 -0
  100. package/lib/esm/Formatter/FormattingReadyCollector.js.map +1 -0
  101. package/lib/esm/Formatter/Interfaces.d.ts +51 -3
  102. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  103. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  104. package/lib/esm/Interfaces.d.ts +31 -1
  105. package/lib/esm/Interfaces.d.ts.map +1 -1
  106. package/lib/esm/Interfaces.js.map +1 -1
  107. package/lib/esm/Parser.d.ts.map +1 -1
  108. package/lib/esm/Parser.js +16 -1
  109. package/lib/esm/Parser.js.map +1 -1
  110. package/lib/esm/ParserSpec.d.ts.map +1 -1
  111. package/lib/esm/ParserSpec.js +15 -2
  112. package/lib/esm/ParserSpec.js.map +1 -1
  113. package/lib/esm/Quantity.js.map +1 -1
  114. package/lib/esm/QuantityLoggerCategory.d.ts +16 -0
  115. package/lib/esm/QuantityLoggerCategory.d.ts.map +1 -0
  116. package/lib/esm/QuantityLoggerCategory.js +21 -0
  117. package/lib/esm/QuantityLoggerCategory.js.map +1 -0
  118. package/lib/esm/SerializedUnitSchema.d.ts +98 -0
  119. package/lib/esm/SerializedUnitSchema.d.ts.map +1 -0
  120. package/lib/esm/SerializedUnitSchema.js +22 -0
  121. package/lib/esm/SerializedUnitSchema.js.map +1 -0
  122. package/lib/esm/Unit.js.map +1 -1
  123. package/lib/esm/UnitConversion/Graph.d.ts +35 -0
  124. package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
  125. package/lib/esm/UnitConversion/Graph.js +83 -0
  126. package/lib/esm/UnitConversion/Graph.js.map +1 -0
  127. package/lib/esm/UnitConversion/Parser.d.ts +9 -0
  128. package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
  129. package/lib/esm/UnitConversion/Parser.js +39 -0
  130. package/lib/esm/UnitConversion/Parser.js.map +1 -0
  131. package/lib/esm/UnitConversion/UnitConversion.d.ts +56 -0
  132. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
  133. package/lib/esm/UnitConversion/UnitConversion.js +76 -0
  134. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
  135. package/lib/esm/UnitConversion/UnitDefinitionResolver.d.ts +29 -0
  136. package/lib/esm/UnitConversion/UnitDefinitionResolver.d.ts.map +1 -0
  137. package/lib/esm/UnitConversion/UnitDefinitionResolver.js +98 -0
  138. package/lib/esm/UnitConversion/UnitDefinitionResolver.js.map +1 -0
  139. package/lib/esm/UnitConversion/nameUtils.d.ts +11 -0
  140. package/lib/esm/UnitConversion/nameUtils.d.ts.map +1 -0
  141. package/lib/esm/UnitConversion/nameUtils.js +21 -0
  142. package/lib/esm/UnitConversion/nameUtils.js.map +1 -0
  143. package/lib/esm/assets/Units.json +4215 -0
  144. package/lib/esm/core-quantity.d.ts +22 -1
  145. package/lib/esm/core-quantity.d.ts.map +1 -1
  146. package/lib/esm/core-quantity.js +22 -1
  147. package/lib/esm/core-quantity.js.map +1 -1
  148. package/lib/esm/internal/cross-package.d.ts +4 -0
  149. package/lib/esm/internal/cross-package.d.ts.map +1 -0
  150. package/lib/esm/internal/cross-package.js +8 -0
  151. package/lib/esm/internal/cross-package.js.map +1 -0
  152. package/package.json +6 -5
@@ -1,5 +1,6 @@
1
1
  export * from "./Constants";
2
2
  export * from "./Exception";
3
+ export * from "./FormatSpecHandle";
3
4
  export * from "./Interfaces";
4
5
  export * from "./Parser";
5
6
  export * from "./ParserSpec";
@@ -9,12 +10,32 @@ export * from "./Formatter/Format";
9
10
  export * from "./Formatter/FormatterSpec";
10
11
  export * from "./Formatter/FormatEnums";
11
12
  export * from "./Formatter/Formatter";
13
+ export * from "./Formatter/FormattingReadyCollector";
12
14
  export * from "./Formatter/Interfaces";
15
+ export * from "./QuantityLoggerCategory";
16
+ export * from "./UnitConversion/UnitConversion";
17
+ export * from "./UnitConversion/UnitDefinitionResolver";
18
+ export * from "./SerializedUnitSchema";
19
+ export { BasicUnitsProvider } from "./BasicUnitsProvider";
20
+ export * from "./CompositeUnitsProvider";
21
+ export * from "./internal/cross-package";
13
22
  /** @docs-package-description
14
- * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.
23
+ * The core-quantity package contains classes, interfaces, and definitions for formatting and parsing quantity values.
15
24
  */
16
25
  /**
17
26
  * @docs-group-description Quantity
18
27
  * Classes, Interfaces, and definitions used to format and parse quantity values.
19
28
  */
29
+ /**
30
+ * @docs-group-description BasicUnitsProvider
31
+ * A UnitsProvider backed by the bundled BIS Units schema JSON asset.
32
+ */
33
+ /**
34
+ * @docs-group-description CompositeUnitsProvider
35
+ * Factory and composition utilities for layering multiple UnitsProviders.
36
+ */
37
+ /**
38
+ * @docs-group-description Logging
39
+ * Logger categories used by this package.
40
+ */
20
41
  //# sourceMappingURL=core-quantity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-quantity.d.ts","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AAEvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC;;GAEG;AAEH;;;GAGG"}
1
+ {"version":3,"file":"core-quantity.d.ts","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sCAAsC,CAAC;AACrD,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AAEzC;;GAEG;AAEH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG"}
@@ -14,12 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.BasicUnitsProvider = void 0;
17
18
  /*---------------------------------------------------------------------------------------------
18
19
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
19
20
  * See LICENSE.md in the project root for license terms and full copyright notice.
20
21
  *--------------------------------------------------------------------------------------------*/
21
22
  __exportStar(require("./Constants"), exports);
22
23
  __exportStar(require("./Exception"), exports);
24
+ __exportStar(require("./FormatSpecHandle"), exports);
23
25
  __exportStar(require("./Interfaces"), exports);
24
26
  __exportStar(require("./Parser"), exports);
25
27
  __exportStar(require("./ParserSpec"), exports);
@@ -29,12 +31,33 @@ __exportStar(require("./Formatter/Format"), exports);
29
31
  __exportStar(require("./Formatter/FormatterSpec"), exports);
30
32
  __exportStar(require("./Formatter/FormatEnums"), exports);
31
33
  __exportStar(require("./Formatter/Formatter"), exports);
34
+ __exportStar(require("./Formatter/FormattingReadyCollector"), exports);
32
35
  __exportStar(require("./Formatter/Interfaces"), exports);
36
+ __exportStar(require("./QuantityLoggerCategory"), exports);
37
+ __exportStar(require("./UnitConversion/UnitConversion"), exports);
38
+ __exportStar(require("./UnitConversion/UnitDefinitionResolver"), exports);
39
+ __exportStar(require("./SerializedUnitSchema"), exports);
40
+ var BasicUnitsProvider_1 = require("./BasicUnitsProvider");
41
+ Object.defineProperty(exports, "BasicUnitsProvider", { enumerable: true, get: function () { return BasicUnitsProvider_1.BasicUnitsProvider; } });
42
+ __exportStar(require("./CompositeUnitsProvider"), exports);
43
+ __exportStar(require("./internal/cross-package"), exports);
33
44
  /** @docs-package-description
34
- * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.
45
+ * The core-quantity package contains classes, interfaces, and definitions for formatting and parsing quantity values.
35
46
  */
36
47
  /**
37
48
  * @docs-group-description Quantity
38
49
  * Classes, Interfaces, and definitions used to format and parse quantity values.
39
50
  */
51
+ /**
52
+ * @docs-group-description BasicUnitsProvider
53
+ * A UnitsProvider backed by the bundled BIS Units schema JSON asset.
54
+ */
55
+ /**
56
+ * @docs-group-description CompositeUnitsProvider
57
+ * Factory and composition utilities for layering multiple UnitsProviders.
58
+ */
59
+ /**
60
+ * @docs-group-description Logging
61
+ * Logger categories used by this package.
62
+ */
40
63
  //# sourceMappingURL=core-quantity.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-quantity.js","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B;AAC7B,2CAAyB;AACzB,+CAA6B;AAC7B,6CAA2B;AAC3B,yCAAuB;AAEvB,qDAAmC;AACnC,4DAA0C;AAC1C,0DAAwC;AACxC,wDAAsC;AACtC,yDAAuC;AAEvC;;GAEG;AAEH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./Constants\";\nexport * from \"./Exception\";\nexport * from \"./Interfaces\";\nexport * from \"./Parser\";\nexport * from \"./ParserSpec\";\nexport * from \"./Quantity\";\nexport * from \"./Unit\";\n\nexport * from \"./Formatter/Format\";\nexport * from \"./Formatter/FormatterSpec\";\nexport * from \"./Formatter/FormatEnums\";\nexport * from \"./Formatter/Formatter\";\nexport * from \"./Formatter/Interfaces\";\n\n/** @docs-package-description\n * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.\n */\n\n/**\n * @docs-group-description Quantity\n * Classes, Interfaces, and definitions used to format and parse quantity values.\n */\n"]}
1
+ {"version":3,"file":"core-quantity.js","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,8CAA4B;AAC5B,8CAA4B;AAC5B,qDAAmC;AACnC,+CAA6B;AAC7B,2CAAyB;AACzB,+CAA6B;AAC7B,6CAA2B;AAC3B,yCAAuB;AACvB,qDAAmC;AACnC,4DAA0C;AAC1C,0DAAwC;AACxC,wDAAsC;AACtC,uEAAqD;AACrD,yDAAuC;AACvC,2DAAyC;AAEzC,kEAAgD;AAChD,0EAAwD;AACxD,yDAAuC;AACvC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,2DAAyC;AACzC,2DAAyC;AAEzC;;GAEG;AAEH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG;AACH;;;GAGG","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\nexport * from \"./Constants\";\r\nexport * from \"./Exception\";\r\nexport * from \"./FormatSpecHandle\";\r\nexport * from \"./Interfaces\";\r\nexport * from \"./Parser\";\r\nexport * from \"./ParserSpec\";\r\nexport * from \"./Quantity\";\r\nexport * from \"./Unit\";\r\nexport * from \"./Formatter/Format\";\r\nexport * from \"./Formatter/FormatterSpec\";\r\nexport * from \"./Formatter/FormatEnums\";\r\nexport * from \"./Formatter/Formatter\";\r\nexport * from \"./Formatter/FormattingReadyCollector\";\r\nexport * from \"./Formatter/Interfaces\";\r\nexport * from \"./QuantityLoggerCategory\";\r\n\r\nexport * from \"./UnitConversion/UnitConversion\";\r\nexport * from \"./UnitConversion/UnitDefinitionResolver\";\r\nexport * from \"./SerializedUnitSchema\";\r\nexport { BasicUnitsProvider } from \"./BasicUnitsProvider\";\r\nexport * from \"./CompositeUnitsProvider\";\r\nexport * from \"./internal/cross-package\";\r\n\r\n/** @docs-package-description\r\n * The core-quantity package contains classes, interfaces, and definitions for formatting and parsing quantity values.\r\n */\r\n\r\n/**\r\n * @docs-group-description Quantity\r\n * Classes, Interfaces, and definitions used to format and parse quantity values.\r\n */\r\n/**\r\n * @docs-group-description BasicUnitsProvider\r\n * A UnitsProvider backed by the bundled BIS Units schema JSON asset.\r\n */\r\n/**\r\n * @docs-group-description CompositeUnitsProvider\r\n * Factory and composition utilities for layering multiple UnitsProviders.\r\n */\r\n/**\r\n * @docs-group-description Logging\r\n * Logger categories used by this package.\r\n */\r\n"]}
@@ -0,0 +1,4 @@
1
+ export { UnitConversionGraph } from "../UnitConversion/Graph";
2
+ export { parseDefinition } from "../UnitConversion/Parser";
3
+ export type { DefinitionFragment } from "../UnitConversion/Parser";
4
+ //# sourceMappingURL=cross-package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-package.d.ts","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,YAAY,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.parseDefinition = exports.UnitConversionGraph = void 0;
8
+ // Used by ecschema-metadata (UnitTree.ts)
9
+ var Graph_1 = require("../UnitConversion/Graph");
10
+ Object.defineProperty(exports, "UnitConversionGraph", { enumerable: true, get: function () { return Graph_1.UnitConversionGraph; } });
11
+ var Parser_1 = require("../UnitConversion/Parser");
12
+ Object.defineProperty(exports, "parseDefinition", { enumerable: true, get: function () { return Parser_1.parseDefinition; } });
13
+ //# sourceMappingURL=cross-package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cross-package.js","sourceRoot":"","sources":["../../../src/internal/cross-package.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,0CAA0C;AAC1C,iDAA8D;AAArD,4GAAA,mBAAmB,OAAA;AAC5B,mDAA2D;AAAlD,yGAAA,eAAe,OAAA","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\n// Used by ecschema-metadata (UnitTree.ts)\r\nexport { UnitConversionGraph } from \"../UnitConversion/Graph\";\r\nexport { parseDefinition } from \"../UnitConversion/Parser\";\r\nexport type { DefinitionFragment } from \"../UnitConversion/Parser\";\r\n"]}
@@ -0,0 +1,44 @@
1
+ import { type UnitConversionProps, type UnitProps, type UnitsProvider } from "./Interfaces";
2
+ /** @internal — test use only. Resets the module-level lazy cache. */
3
+ export declare function _testResetUnitsCache(): void;
4
+ /**
5
+ * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.
6
+ *
7
+ * The ~90 KB bundled JSON is loaded lazily via dynamic `import()` on the first provider method
8
+ * call and cached at module scope — construction is essentially free, and multiple instances
9
+ * share the same immutable lookup indexes.
10
+ *
11
+ * This is the zero-dependency default for backends, tools, and any frontend that doesn't need
12
+ * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.
13
+ *
14
+ * @see createUnitsProvider for layering schema-defined units on top of basic BIS units.
15
+ * @beta
16
+ */
17
+ export declare class BasicUnitsProvider implements UnitsProvider {
18
+ /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.
19
+ * @param unitLabel - The display label to search for (case-insensitive).
20
+ * @param schemaName - Optional schema name filter. Returns `BadUnit` if provided and not `"Units"`.
21
+ * @param phenomenon - Optional phenomenon filter (e.g. `"Units.LENGTH"`).
22
+ * @param unitSystem - Optional unit system filter (e.g. `"Units.METRIC"`).
23
+ * @returns The matching `UnitProps`, or a `BadUnit` if no match is found.
24
+ */
25
+ findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
26
+ /** Return all units belonging to the given phenomenon (unit family).
27
+ * @param phenomenon - The phenomenon full name (e.g. `"Units.LENGTH"`).
28
+ * @returns An array of matching `UnitProps`, or an empty array if none.
29
+ */
30
+ getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;
31
+ /** Find a unit by its fully-qualified name (e.g. `"Units.M"`).
32
+ * @param unitName - The qualified unit name.
33
+ * @returns The matching `UnitProps`, or a `BadUnit` if not found.
34
+ */
35
+ findUnitByName(unitName: string): Promise<UnitProps>;
36
+ /** Compute the conversion factors from `fromUnit` to `toUnit`.
37
+ * Handles normal units, inverted units, and mixed (inverted ↔ non-inverted) conversions.
38
+ * @param fromUnit - The source unit.
39
+ * @param toUnit - The target unit.
40
+ * @returns A `UnitConversionProps` with `factor`, `offset`, and optionally `inversion` and `error`.
41
+ */
42
+ getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;
43
+ }
44
+ //# sourceMappingURL=BasicUnitsProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BasicUnitsProvider.d.ts","sourceRoot":"","sources":["../../src/BasicUnitsProvider.ts"],"names":[],"mappings":"AAIA,OAAO,EAAwB,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAgDlH,qEAAqE;AACrE,wBAAgB,oBAAoB,IAAI,IAAI,CAG3C;AAsFD;;;;;;;;;;;;GAYG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IAItD;;;;;;OAMG;IACU,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAuB3H;;;OAGG;IACU,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAMvE;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMjE;;;;;OAKG;IACU,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAkDjG"}
@@ -0,0 +1,213 @@
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 { UnitConversionInvert } from "./Interfaces";
6
+ import { UnitDefinitionResolver } from "./UnitConversion/UnitDefinitionResolver";
7
+ import { qualifyItemName } from "./UnitConversion/nameUtils";
8
+ import { BadUnit } from "./Unit";
9
+ // Module-level cache: the unit data is derived deterministically from the bundled Units.json
10
+ // asset, so the resolved indexes are effectively an immutable constant. Caching at module
11
+ // scope avoids redundant work when multiple BasicUnitsProvider instances are created (e.g.
12
+ // in tests or when composed inside CompositeUnitsProvider).
13
+ // The JSON is loaded lazily via dynamic import() on first use, keeping the module footprint
14
+ // near-zero until a provider method is actually called.
15
+ let _resolvePromise;
16
+ let _permanentError;
17
+ async function resolveState() {
18
+ if (_permanentError !== undefined) {
19
+ throw _permanentError;
20
+ }
21
+ if (!_resolvePromise) {
22
+ _resolvePromise = _buildState().catch((err) => {
23
+ _permanentError = err instanceof Error ? err : new Error(String(err));
24
+ _resolvePromise = undefined;
25
+ throw _permanentError;
26
+ });
27
+ }
28
+ return _resolvePromise;
29
+ }
30
+ /** @internal — test use only. Resets the module-level lazy cache. */
31
+ export function _testResetUnitsCache() {
32
+ _resolvePromise = undefined;
33
+ _permanentError = undefined;
34
+ }
35
+ async function _buildState() {
36
+ const { default: schema } = await import("./assets/Units.json");
37
+ const nameMap = new Map();
38
+ const labelMap = new Map();
39
+ const phenomenonMap = new Map();
40
+ const invertedUnits = new Map();
41
+ const s = schema;
42
+ const resolver = new UnitDefinitionResolver(s);
43
+ const resolved = resolver.resolveAll();
44
+ for (const [name, entry] of resolved) {
45
+ const item = s.items[name];
46
+ const phenomenon = item.phenomenon;
47
+ const unitSystem = item.unitSystem;
48
+ const fullName = `${s.name}.${name}`;
49
+ const props = {
50
+ name: fullName,
51
+ label: entry.label,
52
+ phenomenon,
53
+ isValid: true,
54
+ system: unitSystem,
55
+ };
56
+ const indexed = { props, resolved: entry };
57
+ nameMap.set(fullName, indexed);
58
+ const lowerLabel = entry.label.toLowerCase();
59
+ const byLabel = labelMap.get(lowerLabel) ?? [];
60
+ byLabel.push(indexed);
61
+ labelMap.set(lowerLabel, byLabel);
62
+ const byPhen = phenomenonMap.get(phenomenon) ?? [];
63
+ byPhen.push(indexed);
64
+ phenomenonMap.set(phenomenon, byPhen);
65
+ }
66
+ // Handle InvertedUnit items — must run after nameMap is fully populated above because
67
+ // invertedSource lookup requires the inverted unit's target to already be in nameMap.
68
+ for (const [name, item] of Object.entries(s.items)) {
69
+ if (item.schemaItemType !== "InvertedUnit") {
70
+ continue;
71
+ }
72
+ const inv = item;
73
+ const fullName = `${s.name}.${name}`;
74
+ const invertsName = qualifyItemName(inv.invertsUnit, s.name);
75
+ const unitSystem = inv.unitSystem;
76
+ const invertedSource = nameMap.get(invertsName);
77
+ const phenomenon = invertedSource?.props.phenomenon ?? "";
78
+ const props = {
79
+ name: fullName,
80
+ label: inv.label ?? name,
81
+ phenomenon,
82
+ isValid: true,
83
+ system: unitSystem,
84
+ };
85
+ invertedUnits.set(fullName, { props, invertsUnitName: invertsName });
86
+ if (invertedSource) {
87
+ const indexed = {
88
+ props,
89
+ resolved: { ...invertedSource.resolved, name: fullName, label: props.label, unitSystem },
90
+ };
91
+ nameMap.set(fullName, indexed);
92
+ const lowerLabel = props.label.toLowerCase();
93
+ const byLabel = labelMap.get(lowerLabel) ?? [];
94
+ byLabel.push(indexed);
95
+ labelMap.set(lowerLabel, byLabel);
96
+ const byPhen = phenomenonMap.get(phenomenon) ?? [];
97
+ byPhen.push(indexed);
98
+ phenomenonMap.set(phenomenon, byPhen);
99
+ }
100
+ }
101
+ return { nameMap, labelMap, phenomenonMap, invertedUnits, schemaName: s.name };
102
+ }
103
+ /**
104
+ * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.
105
+ *
106
+ * The ~90 KB bundled JSON is loaded lazily via dynamic `import()` on the first provider method
107
+ * call and cached at module scope — construction is essentially free, and multiple instances
108
+ * share the same immutable lookup indexes.
109
+ *
110
+ * This is the zero-dependency default for backends, tools, and any frontend that doesn't need
111
+ * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.
112
+ *
113
+ * @see createUnitsProvider for layering schema-defined units on top of basic BIS units.
114
+ * @beta
115
+ */
116
+ export class BasicUnitsProvider {
117
+ // ── UnitsProvider implementation ─────────────────────────────────────
118
+ /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.
119
+ * @param unitLabel - The display label to search for (case-insensitive).
120
+ * @param schemaName - Optional schema name filter. Returns `BadUnit` if provided and not `"Units"`.
121
+ * @param phenomenon - Optional phenomenon filter (e.g. `"Units.LENGTH"`).
122
+ * @param unitSystem - Optional unit system filter (e.g. `"Units.METRIC"`).
123
+ * @returns The matching `UnitProps`, or a `BadUnit` if no match is found.
124
+ */
125
+ async findUnit(unitLabel, schemaName, phenomenon, unitSystem) {
126
+ const state = await resolveState();
127
+ if (schemaName && schemaName !== state.schemaName) {
128
+ return new BadUnit();
129
+ }
130
+ const candidates = state.labelMap.get(unitLabel.toLowerCase());
131
+ if (!candidates || candidates.length === 0) {
132
+ return new BadUnit();
133
+ }
134
+ for (const c of candidates) {
135
+ if (phenomenon && c.props.phenomenon !== phenomenon) {
136
+ continue;
137
+ }
138
+ if (unitSystem && c.props.system !== unitSystem) {
139
+ continue;
140
+ }
141
+ return c.props;
142
+ }
143
+ return new BadUnit();
144
+ }
145
+ /** Return all units belonging to the given phenomenon (unit family).
146
+ * @param phenomenon - The phenomenon full name (e.g. `"Units.LENGTH"`).
147
+ * @returns An array of matching `UnitProps`, or an empty array if none.
148
+ */
149
+ async getUnitsByFamily(phenomenon) {
150
+ const state = await resolveState();
151
+ const entries = state.phenomenonMap.get(phenomenon);
152
+ return entries ? entries.map((e) => e.props) : [];
153
+ }
154
+ /** Find a unit by its fully-qualified name (e.g. `"Units.M"`).
155
+ * @param unitName - The qualified unit name.
156
+ * @returns The matching `UnitProps`, or a `BadUnit` if not found.
157
+ */
158
+ async findUnitByName(unitName) {
159
+ const state = await resolveState();
160
+ const entry = state.nameMap.get(unitName);
161
+ return entry ? entry.props : new BadUnit();
162
+ }
163
+ /** Compute the conversion factors from `fromUnit` to `toUnit`.
164
+ * Handles normal units, inverted units, and mixed (inverted ↔ non-inverted) conversions.
165
+ * @param fromUnit - The source unit.
166
+ * @param toUnit - The target unit.
167
+ * @returns A `UnitConversionProps` with `factor`, `offset`, and optionally `inversion` and `error`.
168
+ */
169
+ async getConversion(fromUnit, toUnit) {
170
+ const state = await resolveState();
171
+ const from = state.nameMap.get(fromUnit.name);
172
+ const to = state.nameMap.get(toUnit.name);
173
+ if (!from || !to) {
174
+ return { factor: 1.0, offset: 0.0, error: true };
175
+ }
176
+ const fromInverted = state.invertedUnits.get(fromUnit.name);
177
+ const toInverted = state.invertedUnits.get(toUnit.name);
178
+ const fromPhenomenon = fromInverted
179
+ ? state.nameMap.get(fromInverted.invertsUnitName)?.props.phenomenon
180
+ : from.props.phenomenon;
181
+ const toPhenomenon = toInverted
182
+ ? state.nameMap.get(toInverted.invertsUnitName)?.props.phenomenon
183
+ : to.props.phenomenon;
184
+ if (fromPhenomenon !== toPhenomenon) {
185
+ return { factor: 1.0, offset: 0.0, error: true };
186
+ }
187
+ if (fromInverted && toInverted) {
188
+ const innerFrom = state.nameMap.get(fromInverted.invertsUnitName);
189
+ const innerTo = state.nameMap.get(toInverted.invertsUnitName);
190
+ if (innerFrom && innerTo) {
191
+ const c = innerFrom.resolved.conversion.inverse().compose(innerTo.resolved.conversion);
192
+ return { factor: c.factor, offset: c.offset };
193
+ }
194
+ }
195
+ if (fromInverted) {
196
+ const innerFrom = state.nameMap.get(fromInverted.invertsUnitName);
197
+ if (innerFrom) {
198
+ const c = innerFrom.resolved.conversion.inverse().compose(to.resolved.conversion);
199
+ return { factor: c.factor, offset: c.offset, inversion: UnitConversionInvert.InvertPreConversion };
200
+ }
201
+ }
202
+ if (toInverted) {
203
+ const innerTo = state.nameMap.get(toInverted.invertsUnitName);
204
+ if (innerTo) {
205
+ const c = from.resolved.conversion.inverse().compose(innerTo.resolved.conversion);
206
+ return { factor: c.factor, offset: c.offset, inversion: UnitConversionInvert.InvertPostConversion };
207
+ }
208
+ }
209
+ const conv = from.resolved.conversion.inverse().compose(to.resolved.conversion);
210
+ return { factor: conv.factor, offset: conv.offset };
211
+ }
212
+ }
213
+ //# sourceMappingURL=BasicUnitsProvider.js.map
@@ -0,0 +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,CAAC;IACtD,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\nimport { UnitConversionInvert, type UnitConversionProps, type UnitProps, type UnitsProvider } from \"./Interfaces\";\r\nimport type { SerializedInvertedUnit, SerializedUnit, SerializedUnitSchema } from \"./SerializedUnitSchema\";\r\nimport { type ResolvedUnit, UnitDefinitionResolver } from \"./UnitConversion/UnitDefinitionResolver\";\r\nimport { qualifyItemName } from \"./UnitConversion/nameUtils\";\r\nimport { BadUnit } from \"./Unit\";\r\n\r\ninterface IndexedUnit {\r\n readonly props: UnitProps;\r\n readonly resolved: ResolvedUnit;\r\n}\r\n\r\ninterface InvertedEntry {\r\n readonly props: UnitProps;\r\n readonly invertsUnitName: string;\r\n}\r\n\r\n/** Immutable lookup indexes resolved from the bundled Units.json. */\r\ninterface ResolvedState {\r\n readonly nameMap: Map<string, IndexedUnit>;\r\n readonly labelMap: Map<string, IndexedUnit[]>;\r\n readonly phenomenonMap: Map<string, IndexedUnit[]>;\r\n readonly invertedUnits: Map<string, InvertedEntry>;\r\n readonly schemaName: string;\r\n}\r\n\r\n// Module-level cache: the unit data is derived deterministically from the bundled Units.json\r\n// asset, so the resolved indexes are effectively an immutable constant. Caching at module\r\n// scope avoids redundant work when multiple BasicUnitsProvider instances are created (e.g.\r\n// in tests or when composed inside CompositeUnitsProvider).\r\n// The JSON is loaded lazily via dynamic import() on first use, keeping the module footprint\r\n// near-zero until a provider method is actually called.\r\nlet _resolvePromise: Promise<ResolvedState> | undefined;\r\nlet _permanentError: Error | undefined;\r\n\r\nasync function resolveState(): Promise<ResolvedState> {\r\n if (_permanentError !== undefined) {\r\n throw _permanentError;\r\n }\r\n if (!_resolvePromise) {\r\n _resolvePromise = _buildState().catch((err) => {\r\n _permanentError = err instanceof Error ? err : new Error(String(err));\r\n _resolvePromise = undefined;\r\n throw _permanentError;\r\n });\r\n }\r\n return _resolvePromise;\r\n}\r\n\r\n/** @internal — test use only. Resets the module-level lazy cache. */\r\nexport function _testResetUnitsCache(): void {\r\n _resolvePromise = undefined;\r\n _permanentError = undefined;\r\n}\r\n\r\nasync function _buildState(): Promise<ResolvedState> {\r\n const { default: schema } = await import(\"./assets/Units.json\");\r\n\r\n const nameMap = new Map<string, IndexedUnit>();\r\n const labelMap = new Map<string, IndexedUnit[]>();\r\n const phenomenonMap = new Map<string, IndexedUnit[]>();\r\n const invertedUnits = new Map<string, InvertedEntry>();\r\n\r\n const s = schema as SerializedUnitSchema;\r\n const resolver = new UnitDefinitionResolver(s);\r\n const resolved = resolver.resolveAll();\r\n\r\n for (const [name, entry] of resolved) {\r\n const item = s.items[name] as SerializedUnit;\r\n const phenomenon = item.phenomenon;\r\n const unitSystem = item.unitSystem;\r\n\r\n const fullName = `${s.name}.${name}`;\r\n const props: UnitProps = {\r\n name: fullName,\r\n label: entry.label,\r\n phenomenon,\r\n isValid: true,\r\n system: unitSystem,\r\n };\r\n\r\n const indexed: IndexedUnit = { props, resolved: entry };\r\n\r\n nameMap.set(fullName, indexed);\r\n const lowerLabel = entry.label.toLowerCase();\r\n const byLabel = labelMap.get(lowerLabel) ?? [];\r\n byLabel.push(indexed);\r\n labelMap.set(lowerLabel, byLabel);\r\n\r\n const byPhen = phenomenonMap.get(phenomenon) ?? [];\r\n byPhen.push(indexed);\r\n phenomenonMap.set(phenomenon, byPhen);\r\n }\r\n\r\n // Handle InvertedUnit items — must run after nameMap is fully populated above because\r\n // invertedSource lookup requires the inverted unit's target to already be in nameMap.\r\n for (const [name, item] of Object.entries(s.items)) {\r\n if (item.schemaItemType !== \"InvertedUnit\") {\r\n continue;\r\n }\r\n const inv: SerializedInvertedUnit = item;\r\n const fullName = `${s.name}.${name}`;\r\n const invertsName = qualifyItemName(inv.invertsUnit, s.name);\r\n const unitSystem = inv.unitSystem;\r\n\r\n const invertedSource = nameMap.get(invertsName);\r\n const phenomenon = invertedSource?.props.phenomenon ?? \"\";\r\n\r\n const props: UnitProps = {\r\n name: fullName,\r\n label: inv.label ?? name,\r\n phenomenon,\r\n isValid: true,\r\n system: unitSystem,\r\n };\r\n\r\n invertedUnits.set(fullName, { props, invertsUnitName: invertsName });\r\n\r\n if (invertedSource) {\r\n const indexed: IndexedUnit = {\r\n props,\r\n resolved: { ...invertedSource.resolved, name: fullName, label: props.label, unitSystem },\r\n };\r\n nameMap.set(fullName, indexed);\r\n\r\n const lowerLabel = props.label.toLowerCase();\r\n const byLabel = labelMap.get(lowerLabel) ?? [];\r\n byLabel.push(indexed);\r\n labelMap.set(lowerLabel, byLabel);\r\n\r\n const byPhen = phenomenonMap.get(phenomenon) ?? [];\r\n byPhen.push(indexed);\r\n phenomenonMap.set(phenomenon, byPhen);\r\n }\r\n }\r\n\r\n return { nameMap, labelMap, phenomenonMap, invertedUnits, schemaName: s.name };\r\n}\r\n\r\n/**\r\n * A `UnitsProvider` backed by the full BIS `Units.ecschema.json` bundled as a JSON asset.\r\n *\r\n * The ~90 KB bundled JSON is loaded lazily via dynamic `import()` on the first provider method\r\n * call and cached at module scope — construction is essentially free, and multiple instances\r\n * share the same immutable lookup indexes.\r\n *\r\n * This is the zero-dependency default for backends, tools, and any frontend that doesn't need\r\n * iModel overrides. Equivalent to calling `createUnitsProvider()` with no arguments.\r\n *\r\n * @see createUnitsProvider for layering schema-defined units on top of basic BIS units.\r\n * @beta\r\n */\r\nexport class BasicUnitsProvider implements UnitsProvider {\r\n\r\n // ── UnitsProvider implementation ─────────────────────────────────────\r\n\r\n /** Find a unit by its display label, optionally filtering by schema name, phenomenon, and unit system.\r\n * @param unitLabel - The display label to search for (case-insensitive).\r\n * @param schemaName - Optional schema name filter. Returns `BadUnit` if provided and not `\"Units\"`.\r\n * @param phenomenon - Optional phenomenon filter (e.g. `\"Units.LENGTH\"`).\r\n * @param unitSystem - Optional unit system filter (e.g. `\"Units.METRIC\"`).\r\n * @returns The matching `UnitProps`, or a `BadUnit` if no match is found.\r\n */\r\n public async findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps> {\r\n const state = await resolveState();\r\n if (schemaName && schemaName !== state.schemaName) {\r\n return new BadUnit();\r\n }\r\n const candidates = state.labelMap.get(unitLabel.toLowerCase());\r\n if (!candidates || candidates.length === 0) {\r\n return new BadUnit();\r\n }\r\n\r\n for (const c of candidates) {\r\n if (phenomenon && c.props.phenomenon !== phenomenon) {\r\n continue;\r\n }\r\n if (unitSystem && c.props.system !== unitSystem) {\r\n continue;\r\n }\r\n return c.props;\r\n }\r\n\r\n return new BadUnit();\r\n }\r\n\r\n /** Return all units belonging to the given phenomenon (unit family).\r\n * @param phenomenon - The phenomenon full name (e.g. `\"Units.LENGTH\"`).\r\n * @returns An array of matching `UnitProps`, or an empty array if none.\r\n */\r\n public async getUnitsByFamily(phenomenon: string): Promise<UnitProps[]> {\r\n const state = await resolveState();\r\n const entries = state.phenomenonMap.get(phenomenon);\r\n return entries ? entries.map((e) => e.props) : [];\r\n }\r\n\r\n /** Find a unit by its fully-qualified name (e.g. `\"Units.M\"`).\r\n * @param unitName - The qualified unit name.\r\n * @returns The matching `UnitProps`, or a `BadUnit` if not found.\r\n */\r\n public async findUnitByName(unitName: string): Promise<UnitProps> {\r\n const state = await resolveState();\r\n const entry = state.nameMap.get(unitName);\r\n return entry ? entry.props : new BadUnit();\r\n }\r\n\r\n /** Compute the conversion factors from `fromUnit` to `toUnit`.\r\n * Handles normal units, inverted units, and mixed (inverted ↔ non-inverted) conversions.\r\n * @param fromUnit - The source unit.\r\n * @param toUnit - The target unit.\r\n * @returns A `UnitConversionProps` with `factor`, `offset`, and optionally `inversion` and `error`.\r\n */\r\n public async getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps> {\r\n const state = await resolveState();\r\n const from = state.nameMap.get(fromUnit.name);\r\n const to = state.nameMap.get(toUnit.name);\r\n\r\n if (!from || !to) {\r\n return { factor: 1.0, offset: 0.0, error: true };\r\n }\r\n\r\n const fromInverted = state.invertedUnits.get(fromUnit.name);\r\n const toInverted = state.invertedUnits.get(toUnit.name);\r\n\r\n const fromPhenomenon = fromInverted\r\n ? state.nameMap.get(fromInverted.invertsUnitName)?.props.phenomenon\r\n : from.props.phenomenon;\r\n const toPhenomenon = toInverted\r\n ? state.nameMap.get(toInverted.invertsUnitName)?.props.phenomenon\r\n : to.props.phenomenon;\r\n if (fromPhenomenon !== toPhenomenon) {\r\n return { factor: 1.0, offset: 0.0, error: true };\r\n }\r\n\r\n if (fromInverted && toInverted) {\r\n const innerFrom = state.nameMap.get(fromInverted.invertsUnitName);\r\n const innerTo = state.nameMap.get(toInverted.invertsUnitName);\r\n if (innerFrom && innerTo) {\r\n const c = innerFrom.resolved.conversion.inverse().compose(innerTo.resolved.conversion);\r\n return { factor: c.factor, offset: c.offset };\r\n }\r\n }\r\n\r\n if (fromInverted) {\r\n const innerFrom = state.nameMap.get(fromInverted.invertsUnitName);\r\n if (innerFrom) {\r\n const c = innerFrom.resolved.conversion.inverse().compose(to.resolved.conversion);\r\n return { factor: c.factor, offset: c.offset, inversion: UnitConversionInvert.InvertPreConversion };\r\n }\r\n }\r\n\r\n if (toInverted) {\r\n const innerTo = state.nameMap.get(toInverted.invertsUnitName);\r\n if (innerTo) {\r\n const c = from.resolved.conversion.inverse().compose(innerTo.resolved.conversion);\r\n return { factor: c.factor, offset: c.offset, inversion: UnitConversionInvert.InvertPostConversion };\r\n }\r\n }\r\n\r\n const conv = from.resolved.conversion.inverse().compose(to.resolved.conversion);\r\n return { factor: conv.factor, offset: conv.offset };\r\n }\r\n}\r\n"]}
@@ -0,0 +1,45 @@
1
+ import type { UnitsProvider } from "./Interfaces";
2
+ /**
3
+ * Options for [[createUnitsProvider]].
4
+ * @beta
5
+ */
6
+ export interface CreateUnitsProviderOptions {
7
+ /**
8
+ * A `UnitsProvider` consulted before the basic BIS units (e.g. a `SchemaUnitProvider`
9
+ * for an open iModel's `SchemaContext`). When omitted, the returned provider behaves
10
+ * exactly like `new BasicUnitsProvider()`.
11
+ */
12
+ primary?: UnitsProvider;
13
+ /**
14
+ * Controls which provider is consulted first and wins ties.
15
+ * - `"preferSchema"` (default): `primary` is authoritative; bundled BIS units are fallback.
16
+ * - `"preferBundled"`: bundled BIS units win; `primary` is consulted only for units not in
17
+ * the bundled set. Use when the iModel's schema may be stale.
18
+ *
19
+ * Affects `findUnit`, `findUnitByName`, and `getConversion` (first-consulted wins or
20
+ * falls through). `getUnitsByFamily` always merges both providers — the first-consulted
21
+ * provider wins name collisions.
22
+ *
23
+ * Has no effect when `primary` is omitted — the returned provider is a plain `BasicUnitsProvider`.
24
+ */
25
+ bisUnitsPolicy?: "preferSchema" | "preferBundled";
26
+ }
27
+ /**
28
+ * Returns a `UnitsProvider` that layers the basic BIS units under (or over) an optional
29
+ * `primary` provider. Typical use: layer an iModel's schema units on top of the bundled
30
+ * defaults from `@itwin/core-quantity`.
31
+ *
32
+ * Precedence rules:
33
+ * - When `primary` is supplied and `bisUnitsPolicy` is `"preferSchema"` (the default): `primary` wins;
34
+ * basic BIS units fill any gaps where `primary` returns an invalid unit or throws.
35
+ * - When `bisUnitsPolicy` is `"preferBundled"`: basic BIS units win; `primary` is consulted only when the
36
+ * basic provider can't answer.
37
+ * - `getUnitsByFamily` always merges results from both providers, deduplicated by
38
+ * `UnitProps.name` (fully-qualified). The first-consulted provider wins ties.
39
+ * - When no `primary` is supplied, the returned provider is exactly `new BasicUnitsProvider()`
40
+ * (no wrapper), preserving `instanceof` checks and keeping the hot path fast.
41
+ *
42
+ * @beta
43
+ */
44
+ export declare function createUnitsProvider(options?: CreateUnitsProviderOptions): UnitsProvider;
45
+ //# sourceMappingURL=CompositeUnitsProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompositeUnitsProvider.d.ts","sourceRoot":"","sources":["../../src/CompositeUnitsProvider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAkC,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlF;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC;CACnD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,0BAA+B,GAAG,aAAa,CAY3F"}
@@ -0,0 +1,108 @@
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 { BasicUnitsProvider } from "./BasicUnitsProvider";
6
+ import { BadUnit } from "./Unit";
7
+ /**
8
+ * Returns a `UnitsProvider` that layers the basic BIS units under (or over) an optional
9
+ * `primary` provider. Typical use: layer an iModel's schema units on top of the bundled
10
+ * defaults from `@itwin/core-quantity`.
11
+ *
12
+ * Precedence rules:
13
+ * - When `primary` is supplied and `bisUnitsPolicy` is `"preferSchema"` (the default): `primary` wins;
14
+ * basic BIS units fill any gaps where `primary` returns an invalid unit or throws.
15
+ * - When `bisUnitsPolicy` is `"preferBundled"`: basic BIS units win; `primary` is consulted only when the
16
+ * basic provider can't answer.
17
+ * - `getUnitsByFamily` always merges results from both providers, deduplicated by
18
+ * `UnitProps.name` (fully-qualified). The first-consulted provider wins ties.
19
+ * - When no `primary` is supplied, the returned provider is exactly `new BasicUnitsProvider()`
20
+ * (no wrapper), preserving `instanceof` checks and keeping the hot path fast.
21
+ *
22
+ * @beta
23
+ */
24
+ export function createUnitsProvider(options = {}) {
25
+ const basic = new BasicUnitsProvider();
26
+ const primary = options.primary;
27
+ // NOTE: returns BasicUnitsProvider directly when no primary is provided.
28
+ // QuantityFormatter.resetToUseInternalUnitsProvider uses instanceof BasicUnitsProvider to detect this.
29
+ // If this fast-path is ever wrapped (e.g. for telemetry), that guard must be updated.
30
+ if (!primary) {
31
+ return basic;
32
+ }
33
+ const providers = options.bisUnitsPolicy === "preferBundled" ? [basic, primary] : [primary, basic];
34
+ return new CompositeUnitsProvider(providers);
35
+ }
36
+ class CompositeUnitsProvider {
37
+ _providers;
38
+ constructor(_providers) {
39
+ this._providers = _providers;
40
+ }
41
+ async findUnit(label, schemaName, phenomenon, unitSystem) {
42
+ for (let i = 0; i < this._providers.length - 1; i++) {
43
+ const hit = await tryFind(async () => this._providers[i].findUnit(label, schemaName, phenomenon, unitSystem));
44
+ if (hit?.isValid) {
45
+ return hit;
46
+ }
47
+ }
48
+ return tryFind(async () => this._providers[this._providers.length - 1].findUnit(label, schemaName, phenomenon, unitSystem)).then((hit) => hit ?? new BadUnit());
49
+ }
50
+ async findUnitByName(name) {
51
+ for (let i = 0; i < this._providers.length - 1; i++) {
52
+ const hit = await tryFind(async () => this._providers[i].findUnitByName(name));
53
+ if (hit?.isValid) {
54
+ return hit;
55
+ }
56
+ }
57
+ return tryFind(async () => this._providers[this._providers.length - 1].findUnitByName(name)).then((hit) => hit ?? new BadUnit());
58
+ }
59
+ async getUnitsByFamily(phenomenon) {
60
+ const seen = new Set();
61
+ const out = [];
62
+ // Query all providers in parallel; process results in declaration order to honour precedence.
63
+ const results = await Promise.all(this._providers.map(async (p) => tryList(async () => p.getUnitsByFamily(phenomenon))));
64
+ for (const units of results) {
65
+ for (const u of units) {
66
+ if (!seen.has(u.name)) {
67
+ seen.add(u.name);
68
+ out.push(u);
69
+ }
70
+ }
71
+ }
72
+ return out;
73
+ }
74
+ async getConversion(from, to) {
75
+ for (let i = 0; i < this._providers.length - 1; i++) {
76
+ try {
77
+ const result = await this._providers[i].getConversion(from, to);
78
+ if (!result.error) {
79
+ return result;
80
+ }
81
+ }
82
+ catch { /* fall through to next provider */ }
83
+ }
84
+ try {
85
+ return await this._providers[this._providers.length - 1].getConversion(from, to);
86
+ }
87
+ catch {
88
+ return { factor: 1.0, offset: 0.0, error: true };
89
+ }
90
+ }
91
+ }
92
+ async function tryFind(fn) {
93
+ try {
94
+ return await fn();
95
+ }
96
+ catch {
97
+ return undefined;
98
+ }
99
+ }
100
+ async function tryList(fn) {
101
+ try {
102
+ return await fn();
103
+ }
104
+ catch {
105
+ return [];
106
+ }
107
+ }
108
+ //# sourceMappingURL=CompositeUnitsProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompositeUnitsProvider.js","sourceRoot":"","sources":["../../src/CompositeUnitsProvider.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AA6BjC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAsC,EAAE;IAC1E,MAAM,KAAK,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAChC,yEAAyE;IACzE,uGAAuG;IACvG,sFAAsF;IACtF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACnG,OAAO,IAAI,sBAAsB,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,sBAAsB;IACG;IAA7B,YAA6B,UAA2B;QAA3B,eAAU,GAAV,UAAU,CAAiB;IAAG,CAAC;IAErD,KAAK,CAAC,QAAQ,CAAC,KAAa,EAAE,UAAmB,EAAE,UAAmB,EAAE,UAAmB;QAChG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAA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AM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACnF,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;CACF;AAED,KAAK,UAAU,OAAO,CAAC,EAA4B;IACjD,IAAI,CAAC;QAAC,OAAO,MAAM,EAAE,EAAE,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,EAA8B;IACnD,IAAI,CAAC;QAAC,OAAO,MAAM,EAAE,EAAE,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC;IAAC,CAAC;AACjD,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 { BasicUnitsProvider } from \"./BasicUnitsProvider\";\r\nimport type { UnitConversionProps, UnitProps, UnitsProvider } from \"./Interfaces\";\r\nimport { BadUnit } from \"./Unit\";\r\n\r\n/**\r\n * Options for [[createUnitsProvider]].\r\n * @beta\r\n */\r\nexport interface CreateUnitsProviderOptions {\r\n /**\r\n * A `UnitsProvider` consulted before the basic BIS units (e.g. a `SchemaUnitProvider`\r\n * for an open iModel's `SchemaContext`). When omitted, the returned provider behaves\r\n * exactly like `new BasicUnitsProvider()`.\r\n */\r\n primary?: UnitsProvider;\r\n\r\n /**\r\n * Controls which provider is consulted first and wins ties.\r\n * - `\"preferSchema\"` (default): `primary` is authoritative; bundled BIS units are fallback.\r\n * - `\"preferBundled\"`: bundled BIS units win; `primary` is consulted only for units not in\r\n * the bundled set. Use when the iModel's schema may be stale.\r\n *\r\n * Affects `findUnit`, `findUnitByName`, and `getConversion` (first-consulted wins or\r\n * falls through). `getUnitsByFamily` always merges both providers — the first-consulted\r\n * provider wins name collisions.\r\n *\r\n * Has no effect when `primary` is omitted — the returned provider is a plain `BasicUnitsProvider`.\r\n */\r\n bisUnitsPolicy?: \"preferSchema\" | \"preferBundled\";\r\n}\r\n\r\n/**\r\n * Returns a `UnitsProvider` that layers the basic BIS units under (or over) an optional\r\n * `primary` provider. Typical use: layer an iModel's schema units on top of the bundled\r\n * defaults from `@itwin/core-quantity`.\r\n *\r\n * Precedence rules:\r\n * - When `primary` is supplied and `bisUnitsPolicy` is `\"preferSchema\"` (the default): `primary` wins;\r\n * basic BIS units fill any gaps where `primary` returns an invalid unit or throws.\r\n * - When `bisUnitsPolicy` is `\"preferBundled\"`: basic BIS units win; `primary` is consulted only when the\r\n * basic provider can't answer.\r\n * - `getUnitsByFamily` always merges results from both providers, deduplicated by\r\n * `UnitProps.name` (fully-qualified). The first-consulted provider wins ties.\r\n * - When no `primary` is supplied, the returned provider is exactly `new BasicUnitsProvider()`\r\n * (no wrapper), preserving `instanceof` checks and keeping the hot path fast.\r\n *\r\n * @beta\r\n */\r\nexport function createUnitsProvider(options: CreateUnitsProviderOptions = {}): UnitsProvider {\r\n const basic = new BasicUnitsProvider();\r\n const primary = options.primary;\r\n // NOTE: returns BasicUnitsProvider directly when no primary is provided.\r\n // QuantityFormatter.resetToUseInternalUnitsProvider uses instanceof BasicUnitsProvider to detect this.\r\n // If this fast-path is ever wrapped (e.g. for telemetry), that guard must be updated.\r\n if (!primary) {\r\n return basic;\r\n }\r\n\r\n const providers = options.bisUnitsPolicy === \"preferBundled\" ? [basic, primary] : [primary, basic];\r\n return new CompositeUnitsProvider(providers);\r\n}\r\n\r\nclass CompositeUnitsProvider implements UnitsProvider {\r\n constructor(private readonly _providers: UnitsProvider[]) {}\r\n\r\n public async findUnit(label: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps> {\r\n for (let i = 0; i < this._providers.length - 1; i++) {\r\n const hit = await tryFind(async () => this._providers[i].findUnit(label, schemaName, phenomenon, unitSystem));\r\n if (hit?.isValid) {\r\n return hit;\r\n }\r\n }\r\n return tryFind(async () => this._providers[this._providers.length - 1].findUnit(label, schemaName, phenomenon, unitSystem)).then((hit) => hit ?? new BadUnit());\r\n }\r\n\r\n public async findUnitByName(name: string): Promise<UnitProps> {\r\n for (let i = 0; i < this._providers.length - 1; i++) {\r\n const hit = await tryFind(async () => this._providers[i].findUnitByName(name));\r\n if (hit?.isValid) {\r\n return hit;\r\n }\r\n }\r\n return tryFind(async () => this._providers[this._providers.length - 1].findUnitByName(name)).then((hit) => hit ?? new BadUnit());\r\n }\r\n\r\n public async getUnitsByFamily(phenomenon: string): Promise<UnitProps[]> {\r\n const seen = new Set<string>();\r\n const out: UnitProps[] = [];\r\n // Query all providers in parallel; process results in declaration order to honour precedence.\r\n const results = await Promise.all(this._providers.map(async (p) => tryList(async () => p.getUnitsByFamily(phenomenon))));\r\n for (const units of results) {\r\n for (const u of units) {\r\n if (!seen.has(u.name)) {\r\n seen.add(u.name);\r\n out.push(u);\r\n }\r\n }\r\n }\r\n return out;\r\n }\r\n\r\n public async getConversion(from: UnitProps, to: UnitProps): Promise<UnitConversionProps> {\r\n for (let i = 0; i < this._providers.length - 1; i++) {\r\n try {\r\n const result = await this._providers[i].getConversion(from, to);\r\n if (!result.error) {\r\n return result;\r\n }\r\n } catch { /* fall through to next provider */ }\r\n }\r\n try {\r\n return await this._providers[this._providers.length - 1].getConversion(from, to);\r\n } catch {\r\n return { factor: 1.0, offset: 0.0, error: true };\r\n }\r\n }\r\n}\r\n\r\nasync function tryFind(fn: () => Promise<UnitProps>): Promise<UnitProps | undefined> {\r\n try { return await fn(); } catch { return undefined; }\r\n}\r\n\r\nasync function tryList(fn: () => Promise<UnitProps[]>): Promise<UnitProps[]> {\r\n try { return await fn(); } catch { return []; }\r\n}\r\n"]}