@itwin/presentation-hierarchies 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +178 -0
  4. package/lib/cjs/hierarchies/HierarchyDefinition.d.ts +228 -0
  5. package/lib/cjs/hierarchies/HierarchyDefinition.d.ts.map +1 -0
  6. package/lib/cjs/hierarchies/HierarchyDefinition.js +94 -0
  7. package/lib/cjs/hierarchies/HierarchyDefinition.js.map +1 -0
  8. package/lib/cjs/hierarchies/HierarchyErrors.d.ts +9 -0
  9. package/lib/cjs/hierarchies/HierarchyErrors.d.ts.map +1 -0
  10. package/lib/cjs/hierarchies/HierarchyErrors.js +20 -0
  11. package/lib/cjs/hierarchies/HierarchyErrors.js.map +1 -0
  12. package/lib/cjs/hierarchies/HierarchyNode.d.ts +337 -0
  13. package/lib/cjs/hierarchies/HierarchyNode.d.ts.map +1 -0
  14. package/lib/cjs/hierarchies/HierarchyNode.js +64 -0
  15. package/lib/cjs/hierarchies/HierarchyNode.js.map +1 -0
  16. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.d.ts +33 -0
  17. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.d.ts.map +1 -0
  18. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.js +34 -0
  19. package/lib/cjs/hierarchies/HierarchyNodeIdentifier.js.map +1 -0
  20. package/lib/cjs/hierarchies/HierarchyNodeKey.d.ts +137 -0
  21. package/lib/cjs/hierarchies/HierarchyNodeKey.d.ts.map +1 -0
  22. package/lib/cjs/hierarchies/HierarchyNodeKey.js +163 -0
  23. package/lib/cjs/hierarchies/HierarchyNodeKey.js.map +1 -0
  24. package/lib/cjs/hierarchies/HierarchyProvider.d.ts +104 -0
  25. package/lib/cjs/hierarchies/HierarchyProvider.d.ts.map +1 -0
  26. package/lib/cjs/hierarchies/HierarchyProvider.js +384 -0
  27. package/lib/cjs/hierarchies/HierarchyProvider.js.map +1 -0
  28. package/lib/cjs/hierarchies/LimitingECSqlQueryExecutor.d.ts +21 -0
  29. package/lib/cjs/hierarchies/LimitingECSqlQueryExecutor.d.ts.map +1 -0
  30. package/lib/cjs/hierarchies/LimitingECSqlQueryExecutor.js +100 -0
  31. package/lib/cjs/hierarchies/LimitingECSqlQueryExecutor.js.map +1 -0
  32. package/lib/cjs/hierarchies/Logging.d.ts +13 -0
  33. package/lib/cjs/hierarchies/Logging.d.ts.map +1 -0
  34. package/lib/cjs/hierarchies/Logging.js +28 -0
  35. package/lib/cjs/hierarchies/Logging.js.map +1 -0
  36. package/lib/cjs/hierarchies/NodeSelectQueryFactory.d.ts +205 -0
  37. package/lib/cjs/hierarchies/NodeSelectQueryFactory.d.ts.map +1 -0
  38. package/lib/cjs/hierarchies/NodeSelectQueryFactory.js +467 -0
  39. package/lib/cjs/hierarchies/NodeSelectQueryFactory.js.map +1 -0
  40. package/lib/cjs/hierarchies/internal/ChildNodeObservablesCache.d.ts +40 -0
  41. package/lib/cjs/hierarchies/internal/ChildNodeObservablesCache.d.ts.map +1 -0
  42. package/lib/cjs/hierarchies/internal/ChildNodeObservablesCache.js +84 -0
  43. package/lib/cjs/hierarchies/internal/ChildNodeObservablesCache.js.map +1 -0
  44. package/lib/cjs/hierarchies/internal/Common.d.ts +20 -0
  45. package/lib/cjs/hierarchies/internal/Common.d.ts.map +1 -0
  46. package/lib/cjs/hierarchies/internal/Common.js +106 -0
  47. package/lib/cjs/hierarchies/internal/Common.js.map +1 -0
  48. package/lib/cjs/hierarchies/internal/EachValueFrom.d.ts +12 -0
  49. package/lib/cjs/hierarchies/internal/EachValueFrom.d.ts.map +1 -0
  50. package/lib/cjs/hierarchies/internal/EachValueFrom.js +108 -0
  51. package/lib/cjs/hierarchies/internal/EachValueFrom.js.map +1 -0
  52. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.d.ts +39 -0
  53. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.d.ts.map +1 -0
  54. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.js +181 -0
  55. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.js.map +1 -0
  56. package/lib/cjs/hierarchies/internal/LoggingUtils.d.ts +14 -0
  57. package/lib/cjs/hierarchies/internal/LoggingUtils.d.ts.map +1 -0
  58. package/lib/cjs/hierarchies/internal/LoggingUtils.js +56 -0
  59. package/lib/cjs/hierarchies/internal/LoggingUtils.js.map +1 -0
  60. package/lib/cjs/hierarchies/internal/SubscriptionScheduler.d.ts +17 -0
  61. package/lib/cjs/hierarchies/internal/SubscriptionScheduler.d.ts.map +1 -0
  62. package/lib/cjs/hierarchies/internal/SubscriptionScheduler.js +57 -0
  63. package/lib/cjs/hierarchies/internal/SubscriptionScheduler.js.map +1 -0
  64. package/lib/cjs/hierarchies/internal/TreeNodesReader.d.ts +37 -0
  65. package/lib/cjs/hierarchies/internal/TreeNodesReader.d.ts.map +1 -0
  66. package/lib/cjs/hierarchies/internal/TreeNodesReader.js +46 -0
  67. package/lib/cjs/hierarchies/internal/TreeNodesReader.js.map +1 -0
  68. package/lib/cjs/hierarchies/internal/operators/DetermineChildren.d.ts +11 -0
  69. package/lib/cjs/hierarchies/internal/operators/DetermineChildren.d.ts.map +1 -0
  70. package/lib/cjs/hierarchies/internal/operators/DetermineChildren.js +34 -0
  71. package/lib/cjs/hierarchies/internal/operators/DetermineChildren.js.map +1 -0
  72. package/lib/cjs/hierarchies/internal/operators/Grouping.d.ts +27 -0
  73. package/lib/cjs/hierarchies/internal/operators/Grouping.d.ts.map +1 -0
  74. package/lib/cjs/hierarchies/internal/operators/Grouping.js +161 -0
  75. package/lib/cjs/hierarchies/internal/operators/Grouping.js.map +1 -0
  76. package/lib/cjs/hierarchies/internal/operators/HideIfNoChildren.d.ts +11 -0
  77. package/lib/cjs/hierarchies/internal/operators/HideIfNoChildren.d.ts.map +1 -0
  78. package/lib/cjs/hierarchies/internal/operators/HideIfNoChildren.js +52 -0
  79. package/lib/cjs/hierarchies/internal/operators/HideIfNoChildren.js.map +1 -0
  80. package/lib/cjs/hierarchies/internal/operators/HideNodesInHierarchy.d.ts +11 -0
  81. package/lib/cjs/hierarchies/internal/operators/HideNodesInHierarchy.d.ts.map +1 -0
  82. package/lib/cjs/hierarchies/internal/operators/HideNodesInHierarchy.js +55 -0
  83. package/lib/cjs/hierarchies/internal/operators/HideNodesInHierarchy.js.map +1 -0
  84. package/lib/cjs/hierarchies/internal/operators/Partition.d.ts +6 -0
  85. package/lib/cjs/hierarchies/internal/operators/Partition.d.ts.map +1 -0
  86. package/lib/cjs/hierarchies/internal/operators/Partition.js +61 -0
  87. package/lib/cjs/hierarchies/internal/operators/Partition.js.map +1 -0
  88. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.d.ts +22 -0
  89. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.d.ts.map +1 -0
  90. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.js +51 -0
  91. package/lib/cjs/hierarchies/internal/operators/ReduceToMergeMap.js.map +1 -0
  92. package/lib/cjs/hierarchies/internal/operators/ReleaseMainThread.d.ts +7 -0
  93. package/lib/cjs/hierarchies/internal/operators/ReleaseMainThread.d.ts.map +1 -0
  94. package/lib/cjs/hierarchies/internal/operators/ReleaseMainThread.js +25 -0
  95. package/lib/cjs/hierarchies/internal/operators/ReleaseMainThread.js.map +1 -0
  96. package/lib/cjs/hierarchies/internal/operators/ShareReplayWithErrors.d.ts +9 -0
  97. package/lib/cjs/hierarchies/internal/operators/ShareReplayWithErrors.d.ts.map +1 -0
  98. package/lib/cjs/hierarchies/internal/operators/ShareReplayWithErrors.js +24 -0
  99. package/lib/cjs/hierarchies/internal/operators/ShareReplayWithErrors.js.map +1 -0
  100. package/lib/cjs/hierarchies/internal/operators/Sorting.d.ts +12 -0
  101. package/lib/cjs/hierarchies/internal/operators/Sorting.d.ts.map +1 -0
  102. package/lib/cjs/hierarchies/internal/operators/Sorting.js +26 -0
  103. package/lib/cjs/hierarchies/internal/operators/Sorting.js.map +1 -0
  104. package/lib/cjs/hierarchies/internal/operators/TapOnce.d.ts +4 -0
  105. package/lib/cjs/hierarchies/internal/operators/TapOnce.d.ts.map +1 -0
  106. package/lib/cjs/hierarchies/internal/operators/TapOnce.js +20 -0
  107. package/lib/cjs/hierarchies/internal/operators/TapOnce.js.map +1 -0
  108. package/lib/cjs/hierarchies/internal/operators/grouping/AutoExpand.d.ts +4 -0
  109. package/lib/cjs/hierarchies/internal/operators/grouping/AutoExpand.d.ts.map +1 -0
  110. package/lib/cjs/hierarchies/internal/operators/grouping/AutoExpand.js +27 -0
  111. package/lib/cjs/hierarchies/internal/operators/grouping/AutoExpand.js.map +1 -0
  112. package/lib/cjs/hierarchies/internal/operators/grouping/BaseClassGrouping.d.ts +10 -0
  113. package/lib/cjs/hierarchies/internal/operators/grouping/BaseClassGrouping.d.ts.map +1 -0
  114. package/lib/cjs/hierarchies/internal/operators/grouping/BaseClassGrouping.js +115 -0
  115. package/lib/cjs/hierarchies/internal/operators/grouping/BaseClassGrouping.js.map +1 -0
  116. package/lib/cjs/hierarchies/internal/operators/grouping/ClassGrouping.d.ts +6 -0
  117. package/lib/cjs/hierarchies/internal/operators/grouping/ClassGrouping.d.ts.map +1 -0
  118. package/lib/cjs/hierarchies/internal/operators/grouping/ClassGrouping.js +56 -0
  119. package/lib/cjs/hierarchies/internal/operators/grouping/ClassGrouping.js.map +1 -0
  120. package/lib/cjs/hierarchies/internal/operators/grouping/GroupHiding.d.ts +4 -0
  121. package/lib/cjs/hierarchies/internal/operators/grouping/GroupHiding.d.ts.map +1 -0
  122. package/lib/cjs/hierarchies/internal/operators/grouping/GroupHiding.js +54 -0
  123. package/lib/cjs/hierarchies/internal/operators/grouping/GroupHiding.js.map +1 -0
  124. package/lib/cjs/hierarchies/internal/operators/grouping/LabelGrouping.d.ts +5 -0
  125. package/lib/cjs/hierarchies/internal/operators/grouping/LabelGrouping.d.ts.map +1 -0
  126. package/lib/cjs/hierarchies/internal/operators/grouping/LabelGrouping.js +61 -0
  127. package/lib/cjs/hierarchies/internal/operators/grouping/LabelGrouping.js.map +1 -0
  128. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.d.ts +31 -0
  129. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.d.ts.map +1 -0
  130. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.js +310 -0
  131. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.js.map +1 -0
  132. package/lib/cjs/hierarchies/internal/operators/grouping/Shared.d.ts +5 -0
  133. package/lib/cjs/hierarchies/internal/operators/grouping/Shared.d.ts.map +1 -0
  134. package/lib/cjs/hierarchies/internal/operators/grouping/Shared.js +30 -0
  135. package/lib/cjs/hierarchies/internal/operators/grouping/Shared.js.map +1 -0
  136. package/lib/cjs/presentation-hierarchies.d.ts +11 -0
  137. package/lib/cjs/presentation-hierarchies.d.ts.map +1 -0
  138. package/lib/cjs/presentation-hierarchies.js +31 -0
  139. package/lib/cjs/presentation-hierarchies.js.map +1 -0
  140. package/lib/esm/hierarchies/HierarchyDefinition.d.ts +228 -0
  141. package/lib/esm/hierarchies/HierarchyDefinition.d.ts.map +1 -0
  142. package/lib/esm/hierarchies/HierarchyDefinition.js +90 -0
  143. package/lib/esm/hierarchies/HierarchyDefinition.js.map +1 -0
  144. package/lib/esm/hierarchies/HierarchyErrors.d.ts +9 -0
  145. package/lib/esm/hierarchies/HierarchyErrors.d.ts.map +1 -0
  146. package/lib/esm/hierarchies/HierarchyErrors.js +16 -0
  147. package/lib/esm/hierarchies/HierarchyErrors.js.map +1 -0
  148. package/lib/esm/hierarchies/HierarchyNode.d.ts +337 -0
  149. package/lib/esm/hierarchies/HierarchyNode.d.ts.map +1 -0
  150. package/lib/esm/hierarchies/HierarchyNode.js +61 -0
  151. package/lib/esm/hierarchies/HierarchyNode.js.map +1 -0
  152. package/lib/esm/hierarchies/HierarchyNodeIdentifier.d.ts +33 -0
  153. package/lib/esm/hierarchies/HierarchyNodeIdentifier.d.ts.map +1 -0
  154. package/lib/esm/hierarchies/HierarchyNodeIdentifier.js +31 -0
  155. package/lib/esm/hierarchies/HierarchyNodeIdentifier.js.map +1 -0
  156. package/lib/esm/hierarchies/HierarchyNodeKey.d.ts +137 -0
  157. package/lib/esm/hierarchies/HierarchyNodeKey.d.ts.map +1 -0
  158. package/lib/esm/hierarchies/HierarchyNodeKey.js +160 -0
  159. package/lib/esm/hierarchies/HierarchyNodeKey.js.map +1 -0
  160. package/lib/esm/hierarchies/HierarchyProvider.d.ts +104 -0
  161. package/lib/esm/hierarchies/HierarchyProvider.d.ts.map +1 -0
  162. package/lib/esm/hierarchies/HierarchyProvider.js +380 -0
  163. package/lib/esm/hierarchies/HierarchyProvider.js.map +1 -0
  164. package/lib/esm/hierarchies/LimitingECSqlQueryExecutor.d.ts +21 -0
  165. package/lib/esm/hierarchies/LimitingECSqlQueryExecutor.d.ts.map +1 -0
  166. package/lib/esm/hierarchies/LimitingECSqlQueryExecutor.js +96 -0
  167. package/lib/esm/hierarchies/LimitingECSqlQueryExecutor.js.map +1 -0
  168. package/lib/esm/hierarchies/Logging.d.ts +13 -0
  169. package/lib/esm/hierarchies/Logging.d.ts.map +1 -0
  170. package/lib/esm/hierarchies/Logging.js +23 -0
  171. package/lib/esm/hierarchies/Logging.js.map +1 -0
  172. package/lib/esm/hierarchies/NodeSelectQueryFactory.d.ts +205 -0
  173. package/lib/esm/hierarchies/NodeSelectQueryFactory.d.ts.map +1 -0
  174. package/lib/esm/hierarchies/NodeSelectQueryFactory.js +463 -0
  175. package/lib/esm/hierarchies/NodeSelectQueryFactory.js.map +1 -0
  176. package/lib/esm/hierarchies/internal/ChildNodeObservablesCache.d.ts +40 -0
  177. package/lib/esm/hierarchies/internal/ChildNodeObservablesCache.d.ts.map +1 -0
  178. package/lib/esm/hierarchies/internal/ChildNodeObservablesCache.js +80 -0
  179. package/lib/esm/hierarchies/internal/ChildNodeObservablesCache.js.map +1 -0
  180. package/lib/esm/hierarchies/internal/Common.d.ts +20 -0
  181. package/lib/esm/hierarchies/internal/Common.d.ts.map +1 -0
  182. package/lib/esm/hierarchies/internal/Common.js +95 -0
  183. package/lib/esm/hierarchies/internal/Common.js.map +1 -0
  184. package/lib/esm/hierarchies/internal/EachValueFrom.d.ts +12 -0
  185. package/lib/esm/hierarchies/internal/EachValueFrom.d.ts.map +1 -0
  186. package/lib/esm/hierarchies/internal/EachValueFrom.js +104 -0
  187. package/lib/esm/hierarchies/internal/EachValueFrom.js.map +1 -0
  188. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.d.ts +39 -0
  189. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.d.ts.map +1 -0
  190. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.js +176 -0
  191. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.js.map +1 -0
  192. package/lib/esm/hierarchies/internal/LoggingUtils.d.ts +14 -0
  193. package/lib/esm/hierarchies/internal/LoggingUtils.d.ts.map +1 -0
  194. package/lib/esm/hierarchies/internal/LoggingUtils.js +50 -0
  195. package/lib/esm/hierarchies/internal/LoggingUtils.js.map +1 -0
  196. package/lib/esm/hierarchies/internal/SubscriptionScheduler.d.ts +17 -0
  197. package/lib/esm/hierarchies/internal/SubscriptionScheduler.d.ts.map +1 -0
  198. package/lib/esm/hierarchies/internal/SubscriptionScheduler.js +53 -0
  199. package/lib/esm/hierarchies/internal/SubscriptionScheduler.js.map +1 -0
  200. package/lib/esm/hierarchies/internal/TreeNodesReader.d.ts +37 -0
  201. package/lib/esm/hierarchies/internal/TreeNodesReader.d.ts.map +1 -0
  202. package/lib/esm/hierarchies/internal/TreeNodesReader.js +41 -0
  203. package/lib/esm/hierarchies/internal/TreeNodesReader.js.map +1 -0
  204. package/lib/esm/hierarchies/internal/operators/DetermineChildren.d.ts +11 -0
  205. package/lib/esm/hierarchies/internal/operators/DetermineChildren.d.ts.map +1 -0
  206. package/lib/esm/hierarchies/internal/operators/DetermineChildren.js +30 -0
  207. package/lib/esm/hierarchies/internal/operators/DetermineChildren.js.map +1 -0
  208. package/lib/esm/hierarchies/internal/operators/Grouping.d.ts +27 -0
  209. package/lib/esm/hierarchies/internal/operators/Grouping.d.ts.map +1 -0
  210. package/lib/esm/hierarchies/internal/operators/Grouping.js +156 -0
  211. package/lib/esm/hierarchies/internal/operators/Grouping.js.map +1 -0
  212. package/lib/esm/hierarchies/internal/operators/HideIfNoChildren.d.ts +11 -0
  213. package/lib/esm/hierarchies/internal/operators/HideIfNoChildren.d.ts.map +1 -0
  214. package/lib/esm/hierarchies/internal/operators/HideIfNoChildren.js +48 -0
  215. package/lib/esm/hierarchies/internal/operators/HideIfNoChildren.js.map +1 -0
  216. package/lib/esm/hierarchies/internal/operators/HideNodesInHierarchy.d.ts +11 -0
  217. package/lib/esm/hierarchies/internal/operators/HideNodesInHierarchy.d.ts.map +1 -0
  218. package/lib/esm/hierarchies/internal/operators/HideNodesInHierarchy.js +51 -0
  219. package/lib/esm/hierarchies/internal/operators/HideNodesInHierarchy.js.map +1 -0
  220. package/lib/esm/hierarchies/internal/operators/Partition.d.ts +6 -0
  221. package/lib/esm/hierarchies/internal/operators/Partition.d.ts.map +1 -0
  222. package/lib/esm/hierarchies/internal/operators/Partition.js +57 -0
  223. package/lib/esm/hierarchies/internal/operators/Partition.js.map +1 -0
  224. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.d.ts +22 -0
  225. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.d.ts.map +1 -0
  226. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.js +46 -0
  227. package/lib/esm/hierarchies/internal/operators/ReduceToMergeMap.js.map +1 -0
  228. package/lib/esm/hierarchies/internal/operators/ReleaseMainThread.d.ts +7 -0
  229. package/lib/esm/hierarchies/internal/operators/ReleaseMainThread.d.ts.map +1 -0
  230. package/lib/esm/hierarchies/internal/operators/ReleaseMainThread.js +21 -0
  231. package/lib/esm/hierarchies/internal/operators/ReleaseMainThread.js.map +1 -0
  232. package/lib/esm/hierarchies/internal/operators/ShareReplayWithErrors.d.ts +9 -0
  233. package/lib/esm/hierarchies/internal/operators/ShareReplayWithErrors.d.ts.map +1 -0
  234. package/lib/esm/hierarchies/internal/operators/ShareReplayWithErrors.js +20 -0
  235. package/lib/esm/hierarchies/internal/operators/ShareReplayWithErrors.js.map +1 -0
  236. package/lib/esm/hierarchies/internal/operators/Sorting.d.ts +12 -0
  237. package/lib/esm/hierarchies/internal/operators/Sorting.d.ts.map +1 -0
  238. package/lib/esm/hierarchies/internal/operators/Sorting.js +22 -0
  239. package/lib/esm/hierarchies/internal/operators/Sorting.js.map +1 -0
  240. package/lib/esm/hierarchies/internal/operators/TapOnce.d.ts +4 -0
  241. package/lib/esm/hierarchies/internal/operators/TapOnce.d.ts.map +1 -0
  242. package/lib/esm/hierarchies/internal/operators/TapOnce.js +16 -0
  243. package/lib/esm/hierarchies/internal/operators/TapOnce.js.map +1 -0
  244. package/lib/esm/hierarchies/internal/operators/grouping/AutoExpand.d.ts +4 -0
  245. package/lib/esm/hierarchies/internal/operators/grouping/AutoExpand.d.ts.map +1 -0
  246. package/lib/esm/hierarchies/internal/operators/grouping/AutoExpand.js +23 -0
  247. package/lib/esm/hierarchies/internal/operators/grouping/AutoExpand.js.map +1 -0
  248. package/lib/esm/hierarchies/internal/operators/grouping/BaseClassGrouping.d.ts +10 -0
  249. package/lib/esm/hierarchies/internal/operators/grouping/BaseClassGrouping.d.ts.map +1 -0
  250. package/lib/esm/hierarchies/internal/operators/grouping/BaseClassGrouping.js +109 -0
  251. package/lib/esm/hierarchies/internal/operators/grouping/BaseClassGrouping.js.map +1 -0
  252. package/lib/esm/hierarchies/internal/operators/grouping/ClassGrouping.d.ts +6 -0
  253. package/lib/esm/hierarchies/internal/operators/grouping/ClassGrouping.d.ts.map +1 -0
  254. package/lib/esm/hierarchies/internal/operators/grouping/ClassGrouping.js +52 -0
  255. package/lib/esm/hierarchies/internal/operators/grouping/ClassGrouping.js.map +1 -0
  256. package/lib/esm/hierarchies/internal/operators/grouping/GroupHiding.d.ts +4 -0
  257. package/lib/esm/hierarchies/internal/operators/grouping/GroupHiding.d.ts.map +1 -0
  258. package/lib/esm/hierarchies/internal/operators/grouping/GroupHiding.js +50 -0
  259. package/lib/esm/hierarchies/internal/operators/grouping/GroupHiding.js.map +1 -0
  260. package/lib/esm/hierarchies/internal/operators/grouping/LabelGrouping.d.ts +5 -0
  261. package/lib/esm/hierarchies/internal/operators/grouping/LabelGrouping.d.ts.map +1 -0
  262. package/lib/esm/hierarchies/internal/operators/grouping/LabelGrouping.js +57 -0
  263. package/lib/esm/hierarchies/internal/operators/grouping/LabelGrouping.js.map +1 -0
  264. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.d.ts +31 -0
  265. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.d.ts.map +1 -0
  266. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.js +302 -0
  267. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.js.map +1 -0
  268. package/lib/esm/hierarchies/internal/operators/grouping/Shared.d.ts +5 -0
  269. package/lib/esm/hierarchies/internal/operators/grouping/Shared.d.ts.map +1 -0
  270. package/lib/esm/hierarchies/internal/operators/grouping/Shared.js +26 -0
  271. package/lib/esm/hierarchies/internal/operators/grouping/Shared.js.map +1 -0
  272. package/lib/esm/presentation-hierarchies.d.ts +11 -0
  273. package/lib/esm/presentation-hierarchies.d.ts.map +1 -0
  274. package/lib/esm/presentation-hierarchies.js +15 -0
  275. package/lib/esm/presentation-hierarchies.js.map +1 -0
  276. package/media/sample-hierarchy.png +0 -0
  277. package/package.json +71 -0
@@ -0,0 +1,384 @@
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.createHierarchyProvider = void 0;
8
+ const rxjs_1 = require("rxjs");
9
+ const core_bentley_1 = require("@itwin/core-bentley");
10
+ const presentation_shared_1 = require("@itwin/presentation-shared");
11
+ const HierarchyDefinition_1 = require("./HierarchyDefinition");
12
+ const HierarchyErrors_1 = require("./HierarchyErrors");
13
+ const HierarchyNode_1 = require("./HierarchyNode");
14
+ const ChildNodeObservablesCache_1 = require("./internal/ChildNodeObservablesCache");
15
+ const Common_1 = require("./internal/Common");
16
+ const EachValueFrom_1 = require("./internal/EachValueFrom");
17
+ const FilteringHierarchyDefinition_1 = require("./internal/FilteringHierarchyDefinition");
18
+ const LoggingUtils_1 = require("./internal/LoggingUtils");
19
+ const DetermineChildren_1 = require("./internal/operators/DetermineChildren");
20
+ const Grouping_1 = require("./internal/operators/Grouping");
21
+ const HideIfNoChildren_1 = require("./internal/operators/HideIfNoChildren");
22
+ const HideNodesInHierarchy_1 = require("./internal/operators/HideNodesInHierarchy");
23
+ const Partition_1 = require("./internal/operators/Partition");
24
+ const ReduceToMergeMap_1 = require("./internal/operators/ReduceToMergeMap");
25
+ const ShareReplayWithErrors_1 = require("./internal/operators/ShareReplayWithErrors");
26
+ const Sorting_1 = require("./internal/operators/Sorting");
27
+ const SubscriptionScheduler_1 = require("./internal/SubscriptionScheduler");
28
+ const TreeNodesReader_1 = require("./internal/TreeNodesReader");
29
+ const NodeSelectQueryFactory_1 = require("./NodeSelectQueryFactory");
30
+ const LOGGING_NAMESPACE = `${Common_1.LOGGING_NAMESPACE}.HierarchyProvider`;
31
+ const PERF_LOGGING_NAMESPACE = `${LOGGING_NAMESPACE}.Performance`;
32
+ const DEFAULT_QUERY_CONCURRENCY = 10;
33
+ const DEFAULT_QUERY_CACHE_SIZE = 1;
34
+ /**
35
+ * Creates an instance of `HierarchyProvider` that creates a hierarchy based on given iModel and
36
+ * a hierarchy definition, which defines each hierarchy level through ECSQL queries.
37
+ *
38
+ * @beta
39
+ */
40
+ function createHierarchyProvider(props) {
41
+ return new HierarchyProviderImpl(props);
42
+ }
43
+ exports.createHierarchyProvider = createHierarchyProvider;
44
+ class HierarchyProviderImpl {
45
+ _imodelAccess;
46
+ _valuesFormatter;
47
+ _localizedStrings;
48
+ _queryScheduler;
49
+ _nodesCache;
50
+ /**
51
+ * Hierarchy level definitions factory used by this provider.
52
+ *
53
+ * @note This does not necessarily match the `hierarchyDefinition` passed through props when constructing
54
+ * the provider. For example, it may be a factory that decorates given `hierarchyDefinition` with filtering
55
+ * features.
56
+ */
57
+ hierarchyDefinition;
58
+ /**
59
+ * A limiting ECSQL query executor used by this provider.
60
+ * @see HierarchyProviderProps.queryExecutor
61
+ */
62
+ get queryExecutor() {
63
+ return this._imodelAccess;
64
+ }
65
+ constructor(props) {
66
+ this._imodelAccess = props.imodelAccess;
67
+ this.hierarchyDefinition = props.hierarchyDefinition;
68
+ if (props.filtering) {
69
+ const filteringDefinition = new FilteringHierarchyDefinition_1.FilteringHierarchyDefinition({
70
+ classHierarchy: this._imodelAccess,
71
+ source: this.hierarchyDefinition,
72
+ nodeIdentifierPaths: props.filtering.paths,
73
+ });
74
+ this.hierarchyDefinition = filteringDefinition;
75
+ }
76
+ this._valuesFormatter = props?.formatter ?? (0, presentation_shared_1.createDefaultValueFormatter)();
77
+ this._localizedStrings = { other: "Other", unspecified: "Not specified", ...props?.localizedStrings };
78
+ this._queryScheduler = new SubscriptionScheduler_1.SubscriptionScheduler(props.queryConcurrency ?? DEFAULT_QUERY_CONCURRENCY);
79
+ const queryCacheSize = props.queryCacheSize ?? DEFAULT_QUERY_CACHE_SIZE;
80
+ if (queryCacheSize !== 0) {
81
+ this._nodesCache = new ChildNodeObservablesCache_1.ChildNodeObservablesCache({
82
+ // we divide the size by 2, because each variation also counts as a query that we cache
83
+ size: Math.ceil(queryCacheSize / 2),
84
+ variationsCount: 1,
85
+ });
86
+ }
87
+ }
88
+ /**
89
+ * Sets `HierarchyProvider` values formatter that formats nodes' labels. If provided `undefined`, then defaults to the
90
+ * result of `createDefaultValueFormatter` called with default parameters.
91
+ */
92
+ setFormatter(formatter) {
93
+ this._valuesFormatter = formatter ?? (0, presentation_shared_1.createDefaultValueFormatter)();
94
+ }
95
+ onGroupingNodeCreated(groupingNode, props) {
96
+ this._nodesCache?.set({ ...props, parentNode: groupingNode }, { observable: (0, rxjs_1.from)(groupingNode.children), processingStatus: "pre-processed" });
97
+ }
98
+ createParsedQueryNodesObservable(props) {
99
+ (0, LoggingUtils_1.doLog)({
100
+ category: PERF_LOGGING_NAMESPACE,
101
+ message: /* istanbul ignore next */ () => `Requesting hierarchy level definitions for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
102
+ });
103
+ // stream hierarchy level definitions
104
+ const definitions = (0, rxjs_1.from)((0, rxjs_1.defer)(async () => this.hierarchyDefinition.defineHierarchyLevel(props))).pipe((0, rxjs_1.mergeAll)(), (0, rxjs_1.finalize)(() => (0, LoggingUtils_1.doLog)({
105
+ category: PERF_LOGGING_NAMESPACE,
106
+ message: /* istanbul ignore next */ () => `Received all hierarchy level definitions for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
107
+ })));
108
+ // pipe definitions to nodes and put "share replay" on it
109
+ return definitions.pipe((0, rxjs_1.mergeMap)((def) => {
110
+ if (HierarchyDefinition_1.HierarchyNodesDefinition.isCustomNode(def)) {
111
+ return (0, rxjs_1.of)(def.node);
112
+ }
113
+ return this._queryScheduler.scheduleSubscription((0, rxjs_1.of)(def.query).pipe((0, rxjs_1.map)((query) => filterQueryByInstanceKeys(query, props.filteredInstanceKeys)), (0, LoggingUtils_1.log)({
114
+ category: `${LOGGING_NAMESPACE}.Queries`,
115
+ message: /* istanbul ignore next */ (query) => `Query direct nodes for parent ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}: ${(0, LoggingUtils_1.createQueryLogMessage)(query)}`,
116
+ }), (0, rxjs_1.mergeMap)((query) => (0, TreeNodesReader_1.readNodes)({ queryExecutor: this.queryExecutor, query, limit: props.hierarchyLevelSizeLimit, parser: this.hierarchyDefinition.parseNode }))));
117
+ }), (0, rxjs_1.finalize)(() => (0, LoggingUtils_1.doLog)({
118
+ category: PERF_LOGGING_NAMESPACE,
119
+ message: /* istanbul ignore next */ () => `Read all child nodes ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
120
+ })), (0, ShareReplayWithErrors_1.shareReplayWithErrors)());
121
+ }
122
+ createInitializedNodesObservable(nodes, parentNode) {
123
+ return nodes.pipe(
124
+ // we're going to be mutating the nodes, but don't want to mutate the original one, so just clone it here once
125
+ (0, rxjs_1.map)((node) => ({ ...node })),
126
+ // set parent node keys on the parsed node
127
+ (0, rxjs_1.map)((node) => Object.assign(node, { parentKeys: createParentNodeKeysList(parentNode) })),
128
+ // format `ConcatenatedValue` labels into string labels
129
+ (0, rxjs_1.mergeMap)(async (node) => applyLabelsFormatting(node, this._imodelAccess, this._valuesFormatter)),
130
+ // we have `ProcessedHierarchyNode` from here
131
+ preProcessNodes(this.hierarchyDefinition), (0, rxjs_1.finalize)(() => (0, LoggingUtils_1.doLog)({
132
+ category: PERF_LOGGING_NAMESPACE,
133
+ message: /* istanbul ignore next */ () => `Finished initializing child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(parentNode)}`,
134
+ })), (0, ShareReplayWithErrors_1.shareReplayWithErrors)());
135
+ }
136
+ createPreProcessedNodesObservable(queryNodesObservable, props) {
137
+ return this.createInitializedNodesObservable(queryNodesObservable, props.parentNode).pipe((0, HideIfNoChildren_1.createHideIfNoChildrenOperator)((n) => this.getChildNodesObservables({ parentNode: n }).hasNodes), (0, HideNodesInHierarchy_1.createHideNodesInHierarchyOperator)(
138
+ // note: for child nodes created because of hidden parent, we want to use parent's request props (instance filter, limit)
139
+ (n) => this.getChildNodesObservables({ ...props, parentNode: n }).processedNodes, false), (0, rxjs_1.finalize)(() => (0, LoggingUtils_1.doLog)({
140
+ category: PERF_LOGGING_NAMESPACE,
141
+ message: /* istanbul ignore next */ () => `Finished pre-processing child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
142
+ })));
143
+ }
144
+ createProcessedNodesObservable(preprocessedNodesObservable, props) {
145
+ return preprocessedNodesObservable.pipe((0, Grouping_1.createGroupingOperator)(this._imodelAccess, props.parentNode, this._valuesFormatter, this._localizedStrings, (gn) => this.onGroupingNodeCreated(gn, props)), (0, rxjs_1.finalize)(() => (0, LoggingUtils_1.doLog)({
146
+ category: PERF_LOGGING_NAMESPACE,
147
+ message: /* istanbul ignore next */ () => `Finished processing child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
148
+ })));
149
+ }
150
+ createFinalizedNodesObservable(processedNodesObservable, props) {
151
+ return processedNodesObservable.pipe((0, DetermineChildren_1.createDetermineChildrenOperator)((n) => this.getChildNodesObservables({ parentNode: n }).hasNodes), postProcessNodes(this.hierarchyDefinition), Sorting_1.sortNodesByLabelOperator, (0, rxjs_1.map)((n) => {
152
+ if (HierarchyNode_1.HierarchyNode.isCustom(n) || HierarchyNode_1.HierarchyNode.isInstancesNode(n)) {
153
+ delete n.processingParams;
154
+ }
155
+ return Object.assign(n, {
156
+ children: (0, Common_1.hasChildren)(n),
157
+ });
158
+ }), (0, rxjs_1.finalize)(() => (0, LoggingUtils_1.doLog)({
159
+ category: PERF_LOGGING_NAMESPACE,
160
+ message: /* istanbul ignore next */ () => `Finished finalizing child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
161
+ })));
162
+ }
163
+ createHasNodesObservable(preprocessedNodesObservable, possiblyKnownChildrenObservable) {
164
+ const loggingCategory = `${LOGGING_NAMESPACE}.HasNodes`;
165
+ return (0, rxjs_1.concat)((possiblyKnownChildrenObservable ?? rxjs_1.EMPTY).pipe((0, rxjs_1.filter)((n) => (0, Common_1.hasChildren)(n))), preprocessedNodesObservable).pipe((0, LoggingUtils_1.log)({ category: loggingCategory, message: /* istanbul ignore next */ (n) => `Node before mapping to 'true': ${(0, Common_1.createNodeIdentifierForLogging)(n)}` }), (0, rxjs_1.take)(1), (0, rxjs_1.map)(() => true), (0, rxjs_1.defaultIfEmpty)(false), (0, rxjs_1.catchError)((e) => {
166
+ (0, LoggingUtils_1.doLog)({ category: loggingCategory, message: /* istanbul ignore next */ () => `Error while determining children: ${e.message}` });
167
+ if (e instanceof HierarchyErrors_1.RowsLimitExceededError) {
168
+ return (0, rxjs_1.of)(true);
169
+ }
170
+ throw e;
171
+ }), (0, LoggingUtils_1.log)({ category: loggingCategory, message: /* istanbul ignore next */ (r) => `Result: ${r}` }));
172
+ }
173
+ getCachedObservableEntry(props) {
174
+ const loggingCategory = `${LOGGING_NAMESPACE}.GetCachedObservableEntry`;
175
+ const { parentNode, ...restProps } = props;
176
+ const cached = props.ignoreCache || !this._nodesCache ? undefined : this._nodesCache.get(props);
177
+ if (cached) {
178
+ // istanbul ignore next
179
+ (0, LoggingUtils_1.doLog)({
180
+ category: loggingCategory,
181
+ message: /* istanbul ignore next */ () => `Found query nodes observable for ${(0, Common_1.createNodeIdentifierForLogging)(parentNode)}`,
182
+ });
183
+ return cached;
184
+ }
185
+ // if we don't find an entry for a grouping node, we load its instances by getting a query and applying
186
+ // a filter based on grouped instance keys
187
+ let filteredInstanceKeys;
188
+ let parentNonGroupingNode;
189
+ if (parentNode) {
190
+ if (HierarchyNode_1.HierarchyNode.isGroupingNode(parentNode)) {
191
+ parentNonGroupingNode = parentNode.nonGroupingAncestor;
192
+ filteredInstanceKeys = parentNode.groupedInstanceKeys;
193
+ }
194
+ else {
195
+ // not sure why type checker doesn't pick this up
196
+ (0, core_bentley_1.assert)(HierarchyNode_1.HierarchyNode.isCustom(parentNode) || HierarchyNode_1.HierarchyNode.isInstancesNode(parentNode));
197
+ parentNonGroupingNode = parentNode;
198
+ }
199
+ }
200
+ const nonGroupingNodeChildrenRequestProps = {
201
+ ...restProps,
202
+ parentNode: parentNonGroupingNode,
203
+ ...(filteredInstanceKeys ? { filteredInstanceKeys } : undefined),
204
+ };
205
+ const value = { observable: this.createParsedQueryNodesObservable(nonGroupingNodeChildrenRequestProps), processingStatus: "none" };
206
+ this._nodesCache?.set(nonGroupingNodeChildrenRequestProps, value);
207
+ (0, LoggingUtils_1.doLog)({
208
+ category: loggingCategory,
209
+ message: /* istanbul ignore next */ () => `Saved query nodes observable for ${(0, Common_1.createNodeIdentifierForLogging)(parentNode)}`,
210
+ });
211
+ return value;
212
+ }
213
+ getChildNodesObservables(props) {
214
+ const entry = this.getCachedObservableEntry(props);
215
+ switch (entry.processingStatus) {
216
+ case "none": {
217
+ const pre = this.createPreProcessedNodesObservable(entry.observable, props);
218
+ const post = this.createProcessedNodesObservable(pre, props);
219
+ return {
220
+ processedNodes: post,
221
+ hasNodes: this.createHasNodesObservable(pre, entry.observable),
222
+ finalizedNodes: this.createFinalizedNodesObservable(post, props),
223
+ };
224
+ }
225
+ case "pre-processed": {
226
+ const post = this.createProcessedNodesObservable(entry.observable, props);
227
+ return {
228
+ processedNodes: post,
229
+ hasNodes: this.createHasNodesObservable(entry.observable),
230
+ finalizedNodes: this.createFinalizedNodesObservable(post, props),
231
+ };
232
+ }
233
+ }
234
+ }
235
+ /**
236
+ * Creates and runs a query based on provided props, then processes retrieved nodes and returns them.
237
+ */
238
+ getNodes(props) {
239
+ const loggingCategory = `${LOGGING_NAMESPACE}.GetNodes`;
240
+ const timer = new core_bentley_1.StopWatch(undefined, true);
241
+ let error;
242
+ let nodesCount = 0;
243
+ (0, LoggingUtils_1.doLog)({
244
+ category: loggingCategory,
245
+ message: /* istanbul ignore next */ () => `Requesting child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
246
+ });
247
+ return (0, EachValueFrom_1.eachValueFrom)(this.getChildNodesObservables(props).finalizedNodes.pipe((0, rxjs_1.tap)(() => ++nodesCount), (0, rxjs_1.catchError)((e) => {
248
+ error = e;
249
+ throw e;
250
+ }), (0, rxjs_1.finalize)(() => {
251
+ (0, LoggingUtils_1.doLog)({
252
+ category: loggingCategory,
253
+ message: /* istanbul ignore next */ () => error
254
+ ? `Error creating child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}: ${error instanceof Error ? error.message : error.toString()}`
255
+ : `Returned ${nodesCount} child nodes for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)} in ${timer.currentSeconds.toFixed(2)} s.`,
256
+ });
257
+ })));
258
+ }
259
+ getNodeInstanceKeysObs(props) {
260
+ const { parentNode, instanceFilter, hierarchyLevelSizeLimit = "unbounded" } = props;
261
+ if (parentNode && HierarchyNode_1.HierarchyNode.isGroupingNode(parentNode)) {
262
+ return (0, rxjs_1.from)(parentNode.groupedInstanceKeys);
263
+ }
264
+ (0, core_bentley_1.assert)(!parentNode || HierarchyNode_1.HierarchyNode.isCustom(parentNode) || HierarchyNode_1.HierarchyNode.isInstancesNode(parentNode));
265
+ // split the definitions based on whether they're for custom nodes or for instance nodes
266
+ const [customDefs, instanceDefs] = (0, Partition_1.partition)((0, rxjs_1.from)(this.hierarchyDefinition.defineHierarchyLevel({ parentNode, instanceFilter })).pipe((0, rxjs_1.mergeAll)()), HierarchyDefinition_1.HierarchyNodesDefinition.isCustomNode);
267
+ // query instance keys and a flag whether they should be hidden
268
+ const instanceKeys = instanceDefs.pipe((0, rxjs_1.mergeMap)((def) => this._queryScheduler.scheduleSubscription((0, rxjs_1.of)(def.query).pipe((0, rxjs_1.mergeMap)(async (query) => {
269
+ const ecsql = `
270
+ SELECT
271
+ ${NodeSelectQueryFactory_1.NodeSelectClauseColumnNames.FullClassName},
272
+ ${NodeSelectQueryFactory_1.NodeSelectClauseColumnNames.ECInstanceId},
273
+ ${NodeSelectQueryFactory_1.NodeSelectClauseColumnNames.HideNodeInHierarchy}
274
+ FROM (
275
+ ${query.ecsql}
276
+ )
277
+ `;
278
+ const reader = this.queryExecutor.createQueryReader({ ...query, ecsql }, { rowFormat: "Indexes", limit: hierarchyLevelSizeLimit });
279
+ return (0, rxjs_1.from)(reader).pipe((0, rxjs_1.map)((row) => ({
280
+ key: {
281
+ className: (0, presentation_shared_1.normalizeFullClassName)(row[0]),
282
+ id: row[1],
283
+ },
284
+ hide: !!row[2],
285
+ })));
286
+ }), (0, rxjs_1.mergeAll)()))));
287
+ // split the instance keys observable based on whether they should be hidden or not
288
+ const [visibleNodeInstanceKeys, hiddenNodeInstanceKeys] = (0, Partition_1.partition)(instanceKeys, ({ hide }) => !hide);
289
+ // hidden items' handling:
290
+ // - if a custom node is hidden, we'll want to retrieve instance keys of its children, otherwise we don't care about it,
291
+ // - if an instance key is hidden, we want to create a merged node similar to what we do in `createHideNodesInHierarchyOperator`
292
+ const hiddenParentNodes = (0, rxjs_1.merge)(customDefs.pipe((0, rxjs_1.mergeMap)((def) => (def.node.processingParams?.hideInHierarchy ? this.createInitializedNodesObservable((0, rxjs_1.of)(def.node), parentNode) : rxjs_1.EMPTY))), hiddenNodeInstanceKeys.pipe(
293
+ // first merge all keys by class
294
+ (0, ReduceToMergeMap_1.reduceToMergeMapList)(({ key }) => key.className, ({ key }) => key.id),
295
+ // then, for each class, create a temp node
296
+ (0, rxjs_1.mergeMap)((mergedMap) => [...mergedMap.entries()].map(([className, ids]) => ({
297
+ key: {
298
+ type: "instances",
299
+ instanceKeys: ids.map((id) => ({ className, id })),
300
+ },
301
+ parentKeys: [],
302
+ label: "",
303
+ })))));
304
+ // merge visible instance keys from this level & the ones we get recursively requesting from deeper levels
305
+ return (0, rxjs_1.merge)(visibleNodeInstanceKeys.pipe((0, rxjs_1.map)(({ key }) => key)), hiddenParentNodes.pipe((0, rxjs_1.mergeMap)((hiddenNode) => this.getNodeInstanceKeysObs({ parentNode: hiddenNode }))));
306
+ }
307
+ /**
308
+ * Creates an iterator for all child hierarchy level instance keys, taking into account any hidden hierarchy levels
309
+ * that there may be under the given parent node.
310
+ */
311
+ getNodeInstanceKeys(props) {
312
+ const loggingCategory = `${LOGGING_NAMESPACE}.GetNodeInstanceKeys`;
313
+ (0, LoggingUtils_1.doLog)({
314
+ category: loggingCategory,
315
+ message: /* istanbul ignore next */ () => `Requesting keys for ${(0, Common_1.createNodeIdentifierForLogging)(props.parentNode)}`,
316
+ });
317
+ return (0, EachValueFrom_1.eachValueFrom)(this.getNodeInstanceKeysObs(props));
318
+ }
319
+ /**
320
+ * A function that should be called when the underlying data source, used by `HierarchyProviderProps.schemaProvider`,
321
+ * `HierarchyProviderProps.queryExecutor` or `HierarchyProviderProps.hierarchyDefinition`, changes.
322
+ *
323
+ * Calling the function invalidates internal caches to make sure fresh data is retrieved on new requests.
324
+ */
325
+ notifyDataSourceChanged() {
326
+ this._nodesCache?.clear();
327
+ }
328
+ }
329
+ function preProcessNodes(hierarchyFactory) {
330
+ return hierarchyFactory.preProcessNode
331
+ ? processNodes(hierarchyFactory.preProcessNode)
332
+ : (o) => o;
333
+ }
334
+ function postProcessNodes(hierarchyFactory) {
335
+ return hierarchyFactory.postProcessNode ? processNodes(hierarchyFactory.postProcessNode) : (o) => o;
336
+ }
337
+ function processNodes(processor) {
338
+ return (nodes) => nodes.pipe((0, rxjs_1.mergeMap)(processor), (0, rxjs_1.filter)((n) => !!n));
339
+ }
340
+ async function applyLabelsFormatting(node, schemaProvider, valueFormatter) {
341
+ return {
342
+ ...node,
343
+ label: await (0, presentation_shared_1.formatConcatenatedValue)({
344
+ value: node.label,
345
+ schemaProvider,
346
+ valueFormatter,
347
+ }),
348
+ };
349
+ }
350
+ function createParentNodeKeysList(parentNode) {
351
+ if (!parentNode) {
352
+ return [];
353
+ }
354
+ return [...parentNode.parentKeys, parentNode.key];
355
+ }
356
+ function filterQueryByInstanceKeys(query, filteredInstanceKeys) {
357
+ if (!filteredInstanceKeys || !filteredInstanceKeys.length) {
358
+ return query;
359
+ }
360
+ const MAX_ALLOWED_BINDINGS = 1000;
361
+ // istanbul ignore else
362
+ if (filteredInstanceKeys.length < MAX_ALLOWED_BINDINGS) {
363
+ return {
364
+ ...query,
365
+ ecsql: `
366
+ SELECT *
367
+ FROM (${query.ecsql}) q
368
+ WHERE q.ECInstanceId IN (${filteredInstanceKeys.map(() => "?").join(",")})
369
+ `,
370
+ bindings: [...(query.bindings ?? []), ...filteredInstanceKeys.map((k) => ({ type: "id", value: k.id }))],
371
+ };
372
+ }
373
+ // istanbul ignore next
374
+ return {
375
+ ...query,
376
+ ecsql: `
377
+ SELECT *
378
+ FROM (${query.ecsql}) q
379
+ WHERE InVirtualSet(?, q.ECInstanceId)
380
+ `,
381
+ bindings: [...(query.bindings ?? []), { type: "idset", value: filteredInstanceKeys.map((k) => k.id) }],
382
+ };
383
+ }
384
+ //# sourceMappingURL=HierarchyProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HierarchyProvider.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,+BAkBc;AACd,sDAAwD;AAExD,oEAWoC;AACpC,+DAAiH;AACjH,uDAA2D;AAC3D,mDASyB;AAGzB,oFAAyI;AACzI,8CAA6H;AAC7H,4DAAyD;AACzD,0FAAuF;AACvF,0DAA4E;AAC5E,8EAAyF;AACzF,4DAAuE;AACvE,4EAAuF;AACvF,oFAA+F;AAC/F,8DAA2D;AAC3D,4EAA6E;AAC7E,sFAAmF;AACnF,0DAAwE;AACxE,4EAAyE;AACzE,gEAAuD;AAEvD,qEAAuE;AAEvE,MAAM,iBAAiB,GAAG,GAAG,0BAAsB,oBAAoB,CAAC;AACxE,MAAM,sBAAsB,GAAG,GAAG,iBAAiB,cAAc,CAAC;AAClE,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AA2GnC;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,KAA6B;IACnE,OAAO,IAAI,qBAAqB,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAFD,0DAEC;AAED,MAAM,qBAAqB;IACjB,aAAa,CAA4E;IACz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AAC,MAAM,EAAE,CAAC;QAC1D,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,oBAAoB,GAAG,IAAI,CAAC;IAClC,uBAAuB;IACvB,IAAI,oBAAoB,CAAC,MAAM,GAAG,oBAAoB,EAAE,CAAC;QACvD,OAAO;YACL,GAAG,KAAK;YACR,KAAK,EAAE;;gBAEG,KAAK,CAAC,KAAK;mCACQ,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;OACzE;YACD,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAgB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;SACvH,CAAC;IACJ,CAAC;IACD,uBAAuB;IACvB,OAAO;QACL,GAAG,KAAK;QACR,KAAK,EAAE;;cAEG,KAAK,CAAC,KAAK;;KAEpB;QACD,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;KACvG,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n catchError,\n concat,\n defaultIfEmpty,\n defer,\n EMPTY,\n filter,\n finalize,\n from,\n map,\n merge,\n mergeAll,\n mergeMap,\n Observable,\n ObservableInput,\n of,\n take,\n tap,\n} from \"rxjs\";\nimport { assert, StopWatch } from \"@itwin/core-bentley\";\nimport { GenericInstanceFilter } from \"@itwin/core-common\";\nimport {\n ConcatenatedValue,\n createDefaultValueFormatter,\n ECClassHierarchyInspector,\n ECSchemaProvider,\n ECSqlBinding,\n ECSqlQueryDef,\n formatConcatenatedValue,\n InstanceKey,\n IPrimitiveValueFormatter,\n normalizeFullClassName,\n} from \"@itwin/presentation-shared\";\nimport { DefineHierarchyLevelProps, HierarchyDefinition, HierarchyNodesDefinition } from \"./HierarchyDefinition\";\nimport { RowsLimitExceededError } from \"./HierarchyErrors\";\nimport {\n HierarchyNode,\n NonGroupingHierarchyNode,\n ParentHierarchyNode,\n ParsedHierarchyNode,\n ProcessedCustomHierarchyNode,\n ProcessedGroupingHierarchyNode,\n ProcessedHierarchyNode,\n ProcessedInstanceHierarchyNode,\n} from \"./HierarchyNode\";\nimport { HierarchyNodeIdentifiersPath } from \"./HierarchyNodeIdentifier\";\nimport { InstancesNodeKey } from \"./HierarchyNodeKey\";\nimport { CachedNodesObservableEntry, ChildNodeObservablesCache, ParsedQueryNodesObservable } from \"./internal/ChildNodeObservablesCache\";\nimport { LOGGING_NAMESPACE as CommonLoggingNamespace, createNodeIdentifierForLogging, hasChildren } from \"./internal/Common\";\nimport { eachValueFrom } from \"./internal/EachValueFrom\";\nimport { FilteringHierarchyDefinition } from \"./internal/FilteringHierarchyDefinition\";\nimport { createQueryLogMessage, doLog, log } from \"./internal/LoggingUtils\";\nimport { createDetermineChildrenOperator } from \"./internal/operators/DetermineChildren\";\nimport { createGroupingOperator } from \"./internal/operators/Grouping\";\nimport { createHideIfNoChildrenOperator } from \"./internal/operators/HideIfNoChildren\";\nimport { createHideNodesInHierarchyOperator } from \"./internal/operators/HideNodesInHierarchy\";\nimport { partition } from \"./internal/operators/Partition\";\nimport { reduceToMergeMapList } from \"./internal/operators/ReduceToMergeMap\";\nimport { shareReplayWithErrors } from \"./internal/operators/ShareReplayWithErrors\";\nimport { sortNodesByLabelOperator } from \"./internal/operators/Sorting\";\nimport { SubscriptionScheduler } from \"./internal/SubscriptionScheduler\";\nimport { readNodes } from \"./internal/TreeNodesReader\";\nimport { LimitingECSqlQueryExecutor } from \"./LimitingECSqlQueryExecutor\";\nimport { NodeSelectClauseColumnNames } from \"./NodeSelectQueryFactory\";\n\nconst LOGGING_NAMESPACE = `${CommonLoggingNamespace}.HierarchyProvider`;\nconst PERF_LOGGING_NAMESPACE = `${LOGGING_NAMESPACE}.Performance`;\nconst DEFAULT_QUERY_CONCURRENCY = 10;\nconst DEFAULT_QUERY_CACHE_SIZE = 1;\n\n/**\n * Props for the `HierarchyProvider.getNodes` call.\n * @beta\n */\nexport interface GetHierarchyNodesProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: ParentHierarchyNode | undefined;\n\n /** Optional hierarchy level filter. Has no effect if `parentNode` is a `GroupingNode`. */\n instanceFilter?: GenericInstanceFilter;\n\n /**\n * Optional hierarchy level size limit override. This value is passed to `LimitingECSqlQueryExecutor` used\n * by this provider to override query rows limit per hierarchy level. If not provided, defaults to whatever\n * is used by the limiting query executor.\n *\n * Has no effect if `parentNode` is a `GroupingNode`.\n */\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n\n /** When set to true ignores the cache and fetches the nodes again. */\n ignoreCache?: boolean;\n}\n\n/**\n * An interface for a hierarchy provider knows how to create child nodes for a given parent node.\n * @beta\n */\nexport interface HierarchyProvider {\n /** Gets nodes for the specified parent node. */\n getNodes(props: GetHierarchyNodesProps): AsyncIterableIterator<HierarchyNode>;\n\n /** Gets instance keys for the specified parent node. */\n getNodeInstanceKeys(props: Omit<GetHierarchyNodesProps, \"ignoreCache\">): AsyncIterableIterator<InstanceKey>;\n\n /** Notifies the provider that the underlying data source has changed and caches should be invalidated. */\n notifyDataSourceChanged(): void;\n\n /**\n * Overrides the property value formatter used by the hierarchy provider. Setting to `undefined`\n * resets the formatter to the result of `createDefaultValueFormatter` called with default parameters.\n */\n setFormatter(formatter: IPrimitiveValueFormatter | undefined): void;\n}\n\n/**\n * Defines the strings used by hierarchy provider.\n */\ninterface HierarchyProviderLocalizedStrings {\n /**\n * A string for \"Unspecified\". Used for labels of property grouping nodes\n * that group by an empty value.\n */\n unspecified: string;\n\n /**\n * A string for \"Other\". Used for label of a range property grouping node that\n * groups values which don't fit into any other range.\n */\n other: string;\n}\n\n/**\n * Props for `createHierarchyProvider`.\n */\ninterface HierarchyProviderProps {\n /**\n * An object that provides access to iModel's data and metadata.\n *\n * @see `ECSchemaProvider`\n * @see `LimitingECSqlQueryExecutor`\n * @see `ECClassHierarchyInspector`\n */\n imodelAccess: ECSchemaProvider & LimitingECSqlQueryExecutor & ECClassHierarchyInspector;\n\n /**\n * A function that returns a hierarchy definition, describing how the hierarchy that the provider should be create. The\n * function is called once during the provider's construction.\n */\n hierarchyDefinition: HierarchyDefinition;\n\n /** Maximum number of queries that the provider attempts to execute in parallel. Defaults to `10`. */\n queryConcurrency?: number;\n /**\n * The amount of queries whose results are stored in-memory for quick retrieval. Defaults to `1`,\n * which means only results of the last run query are cached.\n */\n queryCacheSize?: number;\n\n /**\n * A values formatter for formatting node labels. Defaults to the\n * result of `createDefaultValueFormatter` called with default parameters.\n */\n formatter?: IPrimitiveValueFormatter;\n\n /** A set of localized strings to use. Defaults to English strings. */\n localizedStrings?: Partial<HierarchyProviderLocalizedStrings>;\n\n /** Props for filtering the hierarchy. */\n filtering?: {\n /** A list of node identifiers from root to target node. */\n paths: HierarchyNodeIdentifiersPath[];\n };\n}\n\n/**\n * Creates an instance of `HierarchyProvider` that creates a hierarchy based on given iModel and\n * a hierarchy definition, which defines each hierarchy level through ECSQL queries.\n *\n * @beta\n */\nexport function createHierarchyProvider(props: HierarchyProviderProps): HierarchyProvider {\n return new HierarchyProviderImpl(props);\n}\n\nclass HierarchyProviderImpl implements HierarchyProvider {\n private _imodelAccess: ECSchemaProvider & LimitingECSqlQueryExecutor & ECClassHierarchyInspector;\n private _valuesFormatter: IPrimitiveValueFormatter;\n private _localizedStrings: HierarchyProviderLocalizedStrings;\n private _queryScheduler: SubscriptionScheduler;\n private _nodesCache?: ChildNodeObservablesCache;\n\n /**\n * Hierarchy level definitions factory used by this provider.\n *\n * @note This does not necessarily match the `hierarchyDefinition` passed through props when constructing\n * the provider. For example, it may be a factory that decorates given `hierarchyDefinition` with filtering\n * features.\n */\n public readonly hierarchyDefinition: HierarchyDefinition;\n\n /**\n * A limiting ECSQL query executor used by this provider.\n * @see HierarchyProviderProps.queryExecutor\n */\n public get queryExecutor(): LimitingECSqlQueryExecutor {\n return this._imodelAccess;\n }\n\n public constructor(props: HierarchyProviderProps) {\n this._imodelAccess = props.imodelAccess;\n this.hierarchyDefinition = props.hierarchyDefinition;\n if (props.filtering) {\n const filteringDefinition = new FilteringHierarchyDefinition({\n classHierarchy: this._imodelAccess,\n source: this.hierarchyDefinition,\n nodeIdentifierPaths: props.filtering.paths,\n });\n this.hierarchyDefinition = filteringDefinition;\n }\n this._valuesFormatter = props?.formatter ?? createDefaultValueFormatter();\n this._localizedStrings = { other: \"Other\", unspecified: \"Not specified\", ...props?.localizedStrings };\n this._queryScheduler = new SubscriptionScheduler(props.queryConcurrency ?? DEFAULT_QUERY_CONCURRENCY);\n\n const queryCacheSize = props.queryCacheSize ?? DEFAULT_QUERY_CACHE_SIZE;\n if (queryCacheSize !== 0) {\n this._nodesCache = new ChildNodeObservablesCache({\n // we divide the size by 2, because each variation also counts as a query that we cache\n size: Math.ceil(queryCacheSize / 2),\n variationsCount: 1,\n });\n }\n }\n\n /**\n * Sets `HierarchyProvider` values formatter that formats nodes' labels. If provided `undefined`, then defaults to the\n * result of `createDefaultValueFormatter` called with default parameters.\n */\n public setFormatter(formatter: IPrimitiveValueFormatter | undefined) {\n this._valuesFormatter = formatter ?? createDefaultValueFormatter();\n }\n\n private onGroupingNodeCreated(groupingNode: ProcessedGroupingHierarchyNode, props: GetHierarchyNodesProps) {\n this._nodesCache?.set({ ...props, parentNode: groupingNode }, { observable: from(groupingNode.children), processingStatus: \"pre-processed\" });\n }\n\n private createParsedQueryNodesObservable(\n props: DefineHierarchyLevelProps & { hierarchyLevelSizeLimit?: number | \"unbounded\"; filteredInstanceKeys?: InstanceKey[] },\n ): ParsedQueryNodesObservable {\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Requesting hierarchy level definitions for ${createNodeIdentifierForLogging(props.parentNode)}`,\n });\n // stream hierarchy level definitions\n const definitions = from(defer(async () => this.hierarchyDefinition.defineHierarchyLevel(props))).pipe(\n mergeAll(),\n finalize(() =>\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Received all hierarchy level definitions for ${createNodeIdentifierForLogging(props.parentNode)}`,\n }),\n ),\n );\n // pipe definitions to nodes and put \"share replay\" on it\n return definitions.pipe(\n mergeMap((def): ObservableInput<ParsedHierarchyNode> => {\n if (HierarchyNodesDefinition.isCustomNode(def)) {\n return of(def.node);\n }\n return this._queryScheduler.scheduleSubscription(\n of(def.query).pipe(\n map((query) => filterQueryByInstanceKeys(query, props.filteredInstanceKeys)),\n log({\n category: `${LOGGING_NAMESPACE}.Queries`,\n message: /* istanbul ignore next */ (query) =>\n `Query direct nodes for parent ${createNodeIdentifierForLogging(props.parentNode)}: ${createQueryLogMessage(query)}`,\n }),\n mergeMap((query) =>\n readNodes({ queryExecutor: this.queryExecutor, query, limit: props.hierarchyLevelSizeLimit, parser: this.hierarchyDefinition.parseNode }),\n ),\n ),\n );\n }),\n finalize(() =>\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Read all child nodes ${createNodeIdentifierForLogging(props.parentNode)}`,\n }),\n ),\n shareReplayWithErrors(),\n );\n }\n\n private createInitializedNodesObservable(nodes: Observable<ParsedHierarchyNode>, parentNode: ParentHierarchyNode | undefined) {\n return nodes.pipe(\n // we're going to be mutating the nodes, but don't want to mutate the original one, so just clone it here once\n map((node) => ({ ...node })),\n // set parent node keys on the parsed node\n map((node) => Object.assign(node, { parentKeys: createParentNodeKeysList(parentNode) })),\n // format `ConcatenatedValue` labels into string labels\n mergeMap(async (node) => applyLabelsFormatting(node, this._imodelAccess, this._valuesFormatter)),\n // we have `ProcessedHierarchyNode` from here\n preProcessNodes(this.hierarchyDefinition),\n finalize(() =>\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Finished initializing child nodes for ${createNodeIdentifierForLogging(parentNode)}`,\n }),\n ),\n shareReplayWithErrors(),\n );\n }\n\n private createPreProcessedNodesObservable(\n queryNodesObservable: ParsedQueryNodesObservable,\n props: GetHierarchyNodesProps,\n ): Observable<ProcessedHierarchyNode> {\n return this.createInitializedNodesObservable(queryNodesObservable, props.parentNode).pipe(\n createHideIfNoChildrenOperator((n) => this.getChildNodesObservables({ parentNode: n }).hasNodes),\n createHideNodesInHierarchyOperator(\n // note: for child nodes created because of hidden parent, we want to use parent's request props (instance filter, limit)\n (n) => this.getChildNodesObservables({ ...props, parentNode: n }).processedNodes,\n false,\n ),\n finalize(() =>\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Finished pre-processing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,\n }),\n ),\n );\n }\n\n private createProcessedNodesObservable(\n preprocessedNodesObservable: Observable<ProcessedHierarchyNode>,\n props: GetHierarchyNodesProps,\n ): Observable<ProcessedHierarchyNode> {\n return preprocessedNodesObservable.pipe(\n createGroupingOperator(this._imodelAccess, props.parentNode, this._valuesFormatter, this._localizedStrings, (gn) =>\n this.onGroupingNodeCreated(gn, props),\n ),\n finalize(() =>\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Finished processing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,\n }),\n ),\n );\n }\n\n private createFinalizedNodesObservable(\n processedNodesObservable: Observable<ProcessedHierarchyNode>,\n props: GetHierarchyNodesProps,\n ): Observable<HierarchyNode> {\n return processedNodesObservable.pipe(\n createDetermineChildrenOperator((n) => this.getChildNodesObservables({ parentNode: n }).hasNodes),\n postProcessNodes(this.hierarchyDefinition),\n sortNodesByLabelOperator,\n map((n): HierarchyNode => {\n if (HierarchyNode.isCustom(n) || HierarchyNode.isInstancesNode(n)) {\n delete n.processingParams;\n }\n return Object.assign(n, {\n children: hasChildren(n),\n });\n }),\n finalize(() =>\n doLog({\n category: PERF_LOGGING_NAMESPACE,\n message: /* istanbul ignore next */ () => `Finished finalizing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,\n }),\n ),\n );\n }\n\n private createHasNodesObservable(\n preprocessedNodesObservable: Observable<ProcessedHierarchyNode>,\n possiblyKnownChildrenObservable?: ParsedQueryNodesObservable,\n ): Observable<boolean> {\n const loggingCategory = `${LOGGING_NAMESPACE}.HasNodes`;\n return concat((possiblyKnownChildrenObservable ?? EMPTY).pipe(filter((n) => hasChildren(n))), preprocessedNodesObservable).pipe(\n log({ category: loggingCategory, message: /* istanbul ignore next */ (n) => `Node before mapping to 'true': ${createNodeIdentifierForLogging(n)}` }),\n take(1),\n map(() => true),\n defaultIfEmpty(false),\n catchError((e: Error) => {\n doLog({ category: loggingCategory, message: /* istanbul ignore next */ () => `Error while determining children: ${e.message}` });\n if (e instanceof RowsLimitExceededError) {\n return of(true);\n }\n throw e;\n }),\n log({ category: loggingCategory, message: /* istanbul ignore next */ (r) => `Result: ${r}` }),\n );\n }\n\n private getCachedObservableEntry(props: GetHierarchyNodesProps): CachedNodesObservableEntry {\n const loggingCategory = `${LOGGING_NAMESPACE}.GetCachedObservableEntry`;\n const { parentNode, ...restProps } = props;\n const cached = props.ignoreCache || !this._nodesCache ? undefined : this._nodesCache.get(props);\n if (cached) {\n // istanbul ignore next\n doLog({\n category: loggingCategory,\n message: /* istanbul ignore next */ () => `Found query nodes observable for ${createNodeIdentifierForLogging(parentNode)}`,\n });\n return cached;\n }\n\n // if we don't find an entry for a grouping node, we load its instances by getting a query and applying\n // a filter based on grouped instance keys\n let filteredInstanceKeys: InstanceKey[] | undefined;\n let parentNonGroupingNode: ParentHierarchyNode<NonGroupingHierarchyNode> | undefined;\n if (parentNode) {\n if (HierarchyNode.isGroupingNode(parentNode)) {\n parentNonGroupingNode = parentNode.nonGroupingAncestor;\n filteredInstanceKeys = parentNode.groupedInstanceKeys;\n } else {\n // not sure why type checker doesn't pick this up\n assert(HierarchyNode.isCustom(parentNode) || HierarchyNode.isInstancesNode(parentNode));\n parentNonGroupingNode = parentNode;\n }\n }\n\n const nonGroupingNodeChildrenRequestProps = {\n ...restProps,\n parentNode: parentNonGroupingNode,\n ...(filteredInstanceKeys ? { filteredInstanceKeys } : undefined),\n };\n const value = { observable: this.createParsedQueryNodesObservable(nonGroupingNodeChildrenRequestProps), processingStatus: \"none\" as const };\n this._nodesCache?.set(nonGroupingNodeChildrenRequestProps, value);\n doLog({\n category: loggingCategory,\n message: /* istanbul ignore next */ () => `Saved query nodes observable for ${createNodeIdentifierForLogging(parentNode)}`,\n });\n return value;\n }\n\n private getChildNodesObservables(props: GetHierarchyNodesProps & { hierarchyLevelSizeLimit?: number | \"unbounded\" }) {\n const entry = this.getCachedObservableEntry(props);\n switch (entry.processingStatus) {\n case \"none\": {\n const pre = this.createPreProcessedNodesObservable(entry.observable, props);\n const post = this.createProcessedNodesObservable(pre, props);\n return {\n processedNodes: post,\n hasNodes: this.createHasNodesObservable(pre, entry.observable),\n finalizedNodes: this.createFinalizedNodesObservable(post, props),\n };\n }\n case \"pre-processed\": {\n const post = this.createProcessedNodesObservable(entry.observable, props);\n return {\n processedNodes: post,\n hasNodes: this.createHasNodesObservable(entry.observable),\n finalizedNodes: this.createFinalizedNodesObservable(post, props),\n };\n }\n }\n }\n\n /**\n * Creates and runs a query based on provided props, then processes retrieved nodes and returns them.\n */\n public getNodes(props: GetHierarchyNodesProps): AsyncIterableIterator<HierarchyNode> {\n const loggingCategory = `${LOGGING_NAMESPACE}.GetNodes`;\n const timer = new StopWatch(undefined, true);\n let error: any;\n let nodesCount = 0;\n doLog({\n category: loggingCategory,\n message: /* istanbul ignore next */ () => `Requesting child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,\n });\n return eachValueFrom(\n this.getChildNodesObservables(props).finalizedNodes.pipe(\n tap(() => ++nodesCount),\n catchError((e) => {\n error = e;\n throw e;\n }),\n finalize(() => {\n doLog({\n category: loggingCategory,\n message: /* istanbul ignore next */ () =>\n error\n ? `Error creating child nodes for ${createNodeIdentifierForLogging(props.parentNode)}: ${error instanceof Error ? error.message : error.toString()}`\n : `Returned ${nodesCount} child nodes for ${createNodeIdentifierForLogging(props.parentNode)} in ${timer.currentSeconds.toFixed(2)} s.`,\n });\n }),\n ),\n );\n }\n\n private getNodeInstanceKeysObs(props: Omit<GetHierarchyNodesProps, \"ignoreCache\">): Observable<InstanceKey> {\n const { parentNode, instanceFilter, hierarchyLevelSizeLimit = \"unbounded\" } = props;\n\n if (parentNode && HierarchyNode.isGroupingNode(parentNode)) {\n return from(parentNode.groupedInstanceKeys);\n }\n\n assert(!parentNode || HierarchyNode.isCustom(parentNode) || HierarchyNode.isInstancesNode(parentNode));\n\n // split the definitions based on whether they're for custom nodes or for instance nodes\n const [customDefs, instanceDefs] = partition(\n from(this.hierarchyDefinition.defineHierarchyLevel({ parentNode, instanceFilter })).pipe(mergeAll()),\n HierarchyNodesDefinition.isCustomNode,\n );\n\n // query instance keys and a flag whether they should be hidden\n const instanceKeys = instanceDefs.pipe(\n mergeMap((def) =>\n this._queryScheduler.scheduleSubscription(\n of(def.query).pipe(\n mergeMap(async (query) => {\n const ecsql = `\n SELECT\n ${NodeSelectClauseColumnNames.FullClassName},\n ${NodeSelectClauseColumnNames.ECInstanceId},\n ${NodeSelectClauseColumnNames.HideNodeInHierarchy}\n FROM (\n ${query.ecsql}\n )\n `;\n const reader = this.queryExecutor.createQueryReader({ ...query, ecsql }, { rowFormat: \"Indexes\", limit: hierarchyLevelSizeLimit });\n return from(reader).pipe(\n map((row) => ({\n key: {\n className: normalizeFullClassName(row[0]),\n id: row[1],\n },\n hide: !!row[2],\n })),\n );\n }),\n mergeAll(),\n ),\n ),\n ),\n );\n // split the instance keys observable based on whether they should be hidden or not\n const [visibleNodeInstanceKeys, hiddenNodeInstanceKeys] = partition(instanceKeys, ({ hide }) => !hide);\n\n // hidden items' handling:\n // - if a custom node is hidden, we'll want to retrieve instance keys of its children, otherwise we don't care about it,\n // - if an instance key is hidden, we want to create a merged node similar to what we do in `createHideNodesInHierarchyOperator`\n const hiddenParentNodes = merge(\n customDefs.pipe(\n mergeMap((def) => (def.node.processingParams?.hideInHierarchy ? this.createInitializedNodesObservable(of(def.node), parentNode) : EMPTY)),\n ),\n hiddenNodeInstanceKeys.pipe(\n // first merge all keys by class\n reduceToMergeMapList(\n ({ key }) => key.className,\n ({ key }) => key.id,\n ),\n // then, for each class, create a temp node\n mergeMap(\n (mergedMap): Array<ParentHierarchyNode & { key: InstancesNodeKey }> =>\n [...mergedMap.entries()].map(([className, ids]) => ({\n key: {\n type: \"instances\",\n instanceKeys: ids.map((id) => ({ className, id })),\n },\n parentKeys: [],\n label: \"\",\n })),\n ),\n ),\n );\n\n // merge visible instance keys from this level & the ones we get recursively requesting from deeper levels\n return merge(\n visibleNodeInstanceKeys.pipe(map(({ key }) => key)),\n hiddenParentNodes.pipe(mergeMap((hiddenNode) => this.getNodeInstanceKeysObs({ parentNode: hiddenNode }))),\n );\n }\n\n /**\n * Creates an iterator for all child hierarchy level instance keys, taking into account any hidden hierarchy levels\n * that there may be under the given parent node.\n */\n public getNodeInstanceKeys(props: Omit<GetHierarchyNodesProps, \"ignoreCache\">): AsyncIterableIterator<InstanceKey> {\n const loggingCategory = `${LOGGING_NAMESPACE}.GetNodeInstanceKeys`;\n doLog({\n category: loggingCategory,\n message: /* istanbul ignore next */ () => `Requesting keys for ${createNodeIdentifierForLogging(props.parentNode)}`,\n });\n return eachValueFrom(this.getNodeInstanceKeysObs(props));\n }\n\n /**\n * A function that should be called when the underlying data source, used by `HierarchyProviderProps.schemaProvider`,\n * `HierarchyProviderProps.queryExecutor` or `HierarchyProviderProps.hierarchyDefinition`, changes.\n *\n * Calling the function invalidates internal caches to make sure fresh data is retrieved on new requests.\n */\n public notifyDataSourceChanged() {\n this._nodesCache?.clear();\n }\n}\n\nfunction preProcessNodes(hierarchyFactory: HierarchyDefinition) {\n return hierarchyFactory.preProcessNode\n ? processNodes(hierarchyFactory.preProcessNode)\n : (o: Observable<ProcessedCustomHierarchyNode | ProcessedInstanceHierarchyNode>) => o;\n}\n\nfunction postProcessNodes(hierarchyFactory: HierarchyDefinition) {\n return hierarchyFactory.postProcessNode ? processNodes(hierarchyFactory.postProcessNode) : (o: Observable<ProcessedHierarchyNode>) => o;\n}\n\nfunction processNodes<TNode>(processor: (node: TNode) => Promise<TNode | undefined>) {\n return (nodes: Observable<TNode>) =>\n nodes.pipe(\n mergeMap(processor),\n filter((n): n is TNode => !!n),\n );\n}\n\nasync function applyLabelsFormatting<TNode extends { label: string | ConcatenatedValue }>(\n node: TNode,\n schemaProvider: ECSchemaProvider,\n valueFormatter: IPrimitiveValueFormatter,\n): Promise<TNode & { label: string }> {\n return {\n ...node,\n label: await formatConcatenatedValue({\n value: node.label,\n schemaProvider,\n valueFormatter,\n }),\n };\n}\n\nfunction createParentNodeKeysList(parentNode: ParentHierarchyNode | undefined) {\n if (!parentNode) {\n return [];\n }\n return [...parentNode.parentKeys, parentNode.key];\n}\n\nfunction filterQueryByInstanceKeys(query: ECSqlQueryDef, filteredInstanceKeys: InstanceKey[] | undefined): ECSqlQueryDef {\n if (!filteredInstanceKeys || !filteredInstanceKeys.length) {\n return query;\n }\n const MAX_ALLOWED_BINDINGS = 1000;\n // istanbul ignore else\n if (filteredInstanceKeys.length < MAX_ALLOWED_BINDINGS) {\n return {\n ...query,\n ecsql: `\n SELECT *\n FROM (${query.ecsql}) q\n WHERE q.ECInstanceId IN (${filteredInstanceKeys.map(() => \"?\").join(\",\")})\n `,\n bindings: [...(query.bindings ?? []), ...filteredInstanceKeys.map((k): ECSqlBinding => ({ type: \"id\", value: k.id }))],\n };\n }\n // istanbul ignore next\n return {\n ...query,\n ecsql: `\n SELECT *\n FROM (${query.ecsql}) q\n WHERE InVirtualSet(?, q.ECInstanceId)\n `,\n bindings: [...(query.bindings ?? []), { type: \"idset\", value: filteredInstanceKeys.map((k) => k.id) }],\n };\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { ECSqlQueryDef, ECSqlQueryExecutor, ECSqlQueryReaderOptions } from "@itwin/presentation-shared";
2
+ /**
3
+ * An interface for something that knows how to create a limiting ECSQL query reader.
4
+ * @beta
5
+ */
6
+ export interface LimitingECSqlQueryExecutor {
7
+ /**
8
+ * Creates a query reader for given query, but makes sure it doesn't return more than the configured
9
+ * limit of rows.
10
+ * @throws `RowsLimitExceededError` when the query returns more than configured limit of rows.
11
+ */
12
+ createQueryReader(query: ECSqlQueryDef, config?: ECSqlQueryReaderOptions & {
13
+ limit?: number | "unbounded";
14
+ }): ReturnType<ECSqlQueryExecutor["createQueryReader"]>;
15
+ }
16
+ /**
17
+ * Creates an `LimitingECSqlQueryExecutor` that throws `RowsLimitExceededError` if the query exceeds given amount of rows.
18
+ * @beta
19
+ */
20
+ export declare function createLimitingECSqlQueryExecutor(baseExecutor: ECSqlQueryExecutor, defaultLimit: number | "unbounded"): LimitingECSqlQueryExecutor;
21
+ //# sourceMappingURL=LimitingECSqlQueryExecutor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LimitingECSqlQueryExecutor.d.ts","sourceRoot":"","sources":["../../../src/hierarchies/LimitingECSqlQueryExecutor.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EAExB,MAAM,4BAA4B,CAAC;AAKpC;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,iBAAiB,CACf,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,uBAAuB,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;KAAE,GAClE,UAAU,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,GAAG,WAAW,GAAG,0BAA0B,CA4CjJ"}
@@ -0,0 +1,100 @@
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.createLimitingECSqlQueryExecutor = void 0;
8
+ const core_bentley_1 = require("@itwin/core-bentley");
9
+ const presentation_shared_1 = require("@itwin/presentation-shared");
10
+ const HierarchyErrors_1 = require("./HierarchyErrors");
11
+ const Common_1 = require("./internal/Common");
12
+ const LoggingUtils_1 = require("./internal/LoggingUtils");
13
+ /**
14
+ * Creates an `LimitingECSqlQueryExecutor` that throws `RowsLimitExceededError` if the query exceeds given amount of rows.
15
+ * @beta
16
+ */
17
+ function createLimitingECSqlQueryExecutor(baseExecutor, defaultLimit) {
18
+ return {
19
+ async *createQueryReader(query, config) {
20
+ const { limit: configLimit, ...restConfig } = config ?? {};
21
+ const limit = configLimit ?? defaultLimit;
22
+ const perfLogger = createQueryPerformanceLogger();
23
+ const releaseMainThread = (0, presentation_shared_1.createMainThreadReleaseOnTimePassedHandler)();
24
+ // handle "unbounded" case without a buffer
25
+ const reader = baseExecutor.createQueryReader({ ...query, ecsql: addLimit(query.ecsql, limit) }, restConfig);
26
+ if (limit === "unbounded") {
27
+ try {
28
+ for await (const row of reader) {
29
+ await releaseMainThread();
30
+ perfLogger.onStep();
31
+ yield row;
32
+ }
33
+ }
34
+ finally {
35
+ perfLogger.onComplete();
36
+ }
37
+ return;
38
+ }
39
+ // avoid streaming until we know the number of rows is okay
40
+ const buffer = [];
41
+ try {
42
+ for await (const row of reader) {
43
+ await releaseMainThread();
44
+ perfLogger.onStep();
45
+ buffer.push(row);
46
+ if (buffer.length > limit) {
47
+ throw new HierarchyErrors_1.RowsLimitExceededError(limit);
48
+ }
49
+ }
50
+ }
51
+ finally {
52
+ perfLogger.onComplete();
53
+ }
54
+ for (const row of buffer) {
55
+ await releaseMainThread();
56
+ yield row;
57
+ }
58
+ },
59
+ };
60
+ }
61
+ exports.createLimitingECSqlQueryExecutor = createLimitingECSqlQueryExecutor;
62
+ function addLimit(ecsql, limit) {
63
+ if (limit === "unbounded") {
64
+ return ecsql;
65
+ }
66
+ return `
67
+ SELECT *
68
+ FROM (${ecsql})
69
+ LIMIT ${limit + 1}
70
+ `;
71
+ }
72
+ const LOGGING_NAMESPACE = `${Common_1.LOGGING_NAMESPACE}.QueryPerformance`;
73
+ function createQueryPerformanceLogger(firstStepWarningThreshold = 3000, allRowsWarningThreshold = 5000) {
74
+ let firstStep = true;
75
+ let rowsCount = 0;
76
+ const timer = new core_bentley_1.StopWatch(undefined, true);
77
+ return {
78
+ onStep() {
79
+ if (firstStep) {
80
+ // istanbul ignore next
81
+ (0, LoggingUtils_1.doLog)({
82
+ category: LOGGING_NAMESPACE,
83
+ severity: timer.current.milliseconds >= firstStepWarningThreshold ? "warning" : "trace",
84
+ message: () => `First step took ${timer.currentSeconds} s.`,
85
+ });
86
+ firstStep = false;
87
+ }
88
+ ++rowsCount;
89
+ },
90
+ onComplete() {
91
+ // istanbul ignore next
92
+ (0, LoggingUtils_1.doLog)({
93
+ category: LOGGING_NAMESPACE,
94
+ severity: timer.current.milliseconds >= allRowsWarningThreshold ? "warning" : "trace",
95
+ message: () => `Query took ${timer.currentSeconds} s. for ${rowsCount} rows.`,
96
+ });
97
+ },
98
+ };
99
+ }
100
+ //# sourceMappingURL=LimitingECSqlQueryExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LimitingECSqlQueryExecutor.js","sourceRoot":"","sources":["../../../src/hierarchies/LimitingECSqlQueryExecutor.ts"],"names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,EAAE,SAAS,CAAC;QACd,CAAC;QACD,UAAU;YACR,uBAAuB;YACvB,IAAA,oBAAK,EAAC;gBACJ,QAAQ,EAAE,iBAAiB;gBAC3B,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,YAAY,IAAI,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO;gBACrF,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,KAAK,CAAC,cAAc,WAAW,SAAS,QAAQ;aAC9E,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { StopWatch } from \"@itwin/core-bentley\";\nimport {\n createMainThreadReleaseOnTimePassedHandler,\n ECSqlQueryDef,\n ECSqlQueryExecutor,\n ECSqlQueryReaderOptions,\n ECSqlQueryRow,\n} from \"@itwin/presentation-shared\";\nimport { RowsLimitExceededError } from \"./HierarchyErrors\";\nimport { LOGGING_NAMESPACE as CommonLoggingNamespace } from \"./internal/Common\";\nimport { doLog } from \"./internal/LoggingUtils\";\n\n/**\n * An interface for something that knows how to create a limiting ECSQL query reader.\n * @beta\n */\nexport interface LimitingECSqlQueryExecutor {\n /**\n * Creates a query reader for given query, but makes sure it doesn't return more than the configured\n * limit of rows.\n * @throws `RowsLimitExceededError` when the query returns more than configured limit of rows.\n */\n createQueryReader(\n query: ECSqlQueryDef,\n config?: ECSqlQueryReaderOptions & { limit?: number | \"unbounded\" },\n ): ReturnType<ECSqlQueryExecutor[\"createQueryReader\"]>;\n}\n\n/**\n * Creates an `LimitingECSqlQueryExecutor` that throws `RowsLimitExceededError` if the query exceeds given amount of rows.\n * @beta\n */\nexport function createLimitingECSqlQueryExecutor(baseExecutor: ECSqlQueryExecutor, defaultLimit: number | \"unbounded\"): LimitingECSqlQueryExecutor {\n return {\n async *createQueryReader(query: ECSqlQueryDef, config?: ECSqlQueryReaderOptions & { limit?: number | \"unbounded\" }) {\n const { limit: configLimit, ...restConfig } = config ?? {};\n const limit = configLimit ?? defaultLimit;\n const perfLogger = createQueryPerformanceLogger();\n const releaseMainThread = createMainThreadReleaseOnTimePassedHandler();\n\n // handle \"unbounded\" case without a buffer\n const reader = baseExecutor.createQueryReader({ ...query, ecsql: addLimit(query.ecsql, limit) }, restConfig);\n if (limit === \"unbounded\") {\n try {\n for await (const row of reader) {\n await releaseMainThread();\n perfLogger.onStep();\n yield row;\n }\n } finally {\n perfLogger.onComplete();\n }\n return;\n }\n\n // avoid streaming until we know the number of rows is okay\n const buffer: ECSqlQueryRow[] = [];\n try {\n for await (const row of reader) {\n await releaseMainThread();\n perfLogger.onStep();\n buffer.push(row);\n if (buffer.length > limit) {\n throw new RowsLimitExceededError(limit);\n }\n }\n } finally {\n perfLogger.onComplete();\n }\n\n for (const row of buffer) {\n await releaseMainThread();\n yield row;\n }\n },\n };\n}\n\nfunction addLimit(ecsql: string, limit: number | \"unbounded\") {\n if (limit === \"unbounded\") {\n return ecsql;\n }\n return `\n SELECT *\n FROM (${ecsql})\n LIMIT ${limit + 1}\n `;\n}\n\nconst LOGGING_NAMESPACE = `${CommonLoggingNamespace}.QueryPerformance`;\nfunction createQueryPerformanceLogger(firstStepWarningThreshold = 3000, allRowsWarningThreshold = 5000) {\n let firstStep = true;\n let rowsCount = 0;\n const timer = new StopWatch(undefined, true);\n return {\n onStep() {\n if (firstStep) {\n // istanbul ignore next\n doLog({\n category: LOGGING_NAMESPACE,\n severity: timer.current.milliseconds >= firstStepWarningThreshold ? \"warning\" : \"trace\",\n message: () => `First step took ${timer.currentSeconds} s.`,\n });\n firstStep = false;\n }\n ++rowsCount;\n },\n onComplete() {\n // istanbul ignore next\n doLog({\n category: LOGGING_NAMESPACE,\n severity: timer.current.milliseconds >= allRowsWarningThreshold ? \"warning\" : \"trace\",\n message: () => `Query took ${timer.currentSeconds} s. for ${rowsCount} rows.`,\n });\n },\n };\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { ILogger } from "@itwin/presentation-shared";
2
+ /**
3
+ * Set logger to use by this package. By default the package uses a no-op logger.
4
+ * @beta
5
+ */
6
+ export declare function setLogger(logger: ILogger | undefined): void;
7
+ /**
8
+ * Get logger used by this package.
9
+ * @see `setLogger`
10
+ * @beta
11
+ */
12
+ export declare function getLogger(): ILogger;
13
+ //# sourceMappingURL=Logging.d.ts.map