@itwin/presentation-common 3.5.0-dev.14 → 3.5.0-dev.16

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 (458) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/lib/cjs/assets/locales/en/BisCore.json +18 -18
  3. package/lib/cjs/assets/locales/en/ECPresentation.json +9 -9
  4. package/lib/cjs/assets/locales/en/RulesEngine.json +5 -5
  5. package/lib/cjs/presentation-common/AsyncTasks.d.ts +22 -22
  6. package/lib/cjs/presentation-common/AsyncTasks.js +38 -38
  7. package/lib/cjs/presentation-common/AsyncTasks.js.map +1 -1
  8. package/lib/cjs/presentation-common/CommonLoggerCategory.d.ts +12 -12
  9. package/lib/cjs/presentation-common/CommonLoggerCategory.js +20 -20
  10. package/lib/cjs/presentation-common/CommonLoggerCategory.js.map +1 -1
  11. package/lib/cjs/presentation-common/Diagnostics.d.ts +125 -125
  12. package/lib/cjs/presentation-common/Diagnostics.js +72 -72
  13. package/lib/cjs/presentation-common/Diagnostics.js.map +1 -1
  14. package/lib/cjs/presentation-common/EC.d.ts +315 -315
  15. package/lib/cjs/presentation-common/EC.js +270 -270
  16. package/lib/cjs/presentation-common/EC.js.map +1 -1
  17. package/lib/cjs/presentation-common/ElementProperties.d.ts +123 -123
  18. package/lib/cjs/presentation-common/ElementProperties.js +9 -9
  19. package/lib/cjs/presentation-common/ElementProperties.js.map +1 -1
  20. package/lib/cjs/presentation-common/Error.d.ts +45 -45
  21. package/lib/cjs/presentation-common/Error.js +62 -62
  22. package/lib/cjs/presentation-common/Error.js.map +1 -1
  23. package/lib/cjs/presentation-common/KeySet.d.ts +146 -146
  24. package/lib/cjs/presentation-common/KeySet.js +418 -418
  25. package/lib/cjs/presentation-common/KeySet.js.map +1 -1
  26. package/lib/cjs/presentation-common/LabelDefinition.d.ts +79 -79
  27. package/lib/cjs/presentation-common/LabelDefinition.js +76 -76
  28. package/lib/cjs/presentation-common/LabelDefinition.js.map +1 -1
  29. package/lib/cjs/presentation-common/LocalizationHelper.d.ts +29 -29
  30. package/lib/cjs/presentation-common/LocalizationHelper.js +110 -110
  31. package/lib/cjs/presentation-common/LocalizationHelper.js.map +1 -1
  32. package/lib/cjs/presentation-common/PresentationIpcInterface.d.ts +37 -37
  33. package/lib/cjs/presentation-common/PresentationIpcInterface.js +12 -12
  34. package/lib/cjs/presentation-common/PresentationIpcInterface.js.map +1 -1
  35. package/lib/cjs/presentation-common/PresentationManagerOptions.d.ts +242 -242
  36. package/lib/cjs/presentation-common/PresentationManagerOptions.js +23 -23
  37. package/lib/cjs/presentation-common/PresentationManagerOptions.js.map +1 -1
  38. package/lib/cjs/presentation-common/PresentationRpcInterface.d.ts +181 -181
  39. package/lib/cjs/presentation-common/PresentationRpcInterface.js +102 -102
  40. package/lib/cjs/presentation-common/PresentationRpcInterface.js.map +1 -1
  41. package/lib/cjs/presentation-common/RegisteredRuleset.d.ts +26 -26
  42. package/lib/cjs/presentation-common/RegisteredRuleset.js +33 -33
  43. package/lib/cjs/presentation-common/RegisteredRuleset.js.map +1 -1
  44. package/lib/cjs/presentation-common/RpcRequestsHandler.d.ts +82 -82
  45. package/lib/cjs/presentation-common/RpcRequestsHandler.js +155 -155
  46. package/lib/cjs/presentation-common/RpcRequestsHandler.js.map +1 -1
  47. package/lib/cjs/presentation-common/RulesetVariables.d.ts +166 -166
  48. package/lib/cjs/presentation-common/RulesetVariables.js +55 -55
  49. package/lib/cjs/presentation-common/RulesetVariables.js.map +1 -1
  50. package/lib/cjs/presentation-common/RulesetsFactory.d.ts +44 -44
  51. package/lib/cjs/presentation-common/RulesetsFactory.js +223 -223
  52. package/lib/cjs/presentation-common/RulesetsFactory.js.map +1 -1
  53. package/lib/cjs/presentation-common/Update.d.ts +194 -194
  54. package/lib/cjs/presentation-common/Update.js +196 -196
  55. package/lib/cjs/presentation-common/Update.js.map +1 -1
  56. package/lib/cjs/presentation-common/Utils.d.ts +64 -64
  57. package/lib/cjs/presentation-common/Utils.js +45 -45
  58. package/lib/cjs/presentation-common/Utils.js.map +1 -1
  59. package/lib/cjs/presentation-common/content/Category.d.ts +49 -49
  60. package/lib/cjs/presentation-common/content/Category.js +49 -49
  61. package/lib/cjs/presentation-common/content/Category.js.map +1 -1
  62. package/lib/cjs/presentation-common/content/Content.d.ts +38 -38
  63. package/lib/cjs/presentation-common/content/Content.js +56 -56
  64. package/lib/cjs/presentation-common/content/Content.js.map +1 -1
  65. package/lib/cjs/presentation-common/content/ContentTraverser.d.ts +101 -101
  66. package/lib/cjs/presentation-common/content/ContentTraverser.js +420 -420
  67. package/lib/cjs/presentation-common/content/ContentTraverser.js.map +1 -1
  68. package/lib/cjs/presentation-common/content/Descriptor.d.ts +240 -240
  69. package/lib/cjs/presentation-common/content/Descriptor.js +189 -189
  70. package/lib/cjs/presentation-common/content/Descriptor.js.map +1 -1
  71. package/lib/cjs/presentation-common/content/DisplayTypes.d.ts +21 -21
  72. package/lib/cjs/presentation-common/content/DisplayTypes.js +29 -29
  73. package/lib/cjs/presentation-common/content/DisplayTypes.js.map +1 -1
  74. package/lib/cjs/presentation-common/content/Editor.d.ts +15 -15
  75. package/lib/cjs/presentation-common/content/Editor.js +9 -9
  76. package/lib/cjs/presentation-common/content/Editor.js.map +1 -1
  77. package/lib/cjs/presentation-common/content/Fields.d.ts +282 -282
  78. package/lib/cjs/presentation-common/content/Fields.js +394 -394
  79. package/lib/cjs/presentation-common/content/Fields.js.map +1 -1
  80. package/lib/cjs/presentation-common/content/Item.d.ts +87 -87
  81. package/lib/cjs/presentation-common/content/Item.js +86 -86
  82. package/lib/cjs/presentation-common/content/Item.js.map +1 -1
  83. package/lib/cjs/presentation-common/content/Property.d.ts +51 -51
  84. package/lib/cjs/presentation-common/content/Property.js +36 -36
  85. package/lib/cjs/presentation-common/content/Property.js.map +1 -1
  86. package/lib/cjs/presentation-common/content/Renderer.d.ts +11 -11
  87. package/lib/cjs/presentation-common/content/Renderer.js +9 -9
  88. package/lib/cjs/presentation-common/content/Renderer.js.map +1 -1
  89. package/lib/cjs/presentation-common/content/TypeDescription.d.ts +72 -72
  90. package/lib/cjs/presentation-common/content/TypeDescription.js +23 -23
  91. package/lib/cjs/presentation-common/content/TypeDescription.js.map +1 -1
  92. package/lib/cjs/presentation-common/content/Value.d.ts +157 -157
  93. package/lib/cjs/presentation-common/content/Value.js +217 -217
  94. package/lib/cjs/presentation-common/content/Value.js.map +1 -1
  95. package/lib/cjs/presentation-common/hierarchy/Key.d.ts +185 -185
  96. package/lib/cjs/presentation-common/hierarchy/Key.js +112 -112
  97. package/lib/cjs/presentation-common/hierarchy/Key.js.map +1 -1
  98. package/lib/cjs/presentation-common/hierarchy/Node.d.ts +141 -141
  99. package/lib/cjs/presentation-common/hierarchy/Node.js +97 -97
  100. package/lib/cjs/presentation-common/hierarchy/Node.js.map +1 -1
  101. package/lib/cjs/presentation-common/hierarchy/NodePathElement.d.ts +85 -85
  102. package/lib/cjs/presentation-common/hierarchy/NodePathElement.js +98 -98
  103. package/lib/cjs/presentation-common/hierarchy/NodePathElement.js.map +1 -1
  104. package/lib/cjs/presentation-common/rules/ClassSpecifications.d.ts +45 -45
  105. package/lib/cjs/presentation-common/rules/ClassSpecifications.js +9 -9
  106. package/lib/cjs/presentation-common/rules/ClassSpecifications.js.map +1 -1
  107. package/lib/cjs/presentation-common/rules/RelatedInstanceSpecification.d.ts +31 -31
  108. package/lib/cjs/presentation-common/rules/RelatedInstanceSpecification.js +9 -9
  109. package/lib/cjs/presentation-common/rules/RelatedInstanceSpecification.js.map +1 -1
  110. package/lib/cjs/presentation-common/rules/RelationshipDirection.d.ts +13 -13
  111. package/lib/cjs/presentation-common/rules/RelationshipDirection.js +21 -21
  112. package/lib/cjs/presentation-common/rules/RelationshipDirection.js.map +1 -1
  113. package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.d.ts +53 -53
  114. package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.js +9 -9
  115. package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.js.map +1 -1
  116. package/lib/cjs/presentation-common/rules/Rule.d.ts +74 -74
  117. package/lib/cjs/presentation-common/rules/Rule.js +35 -35
  118. package/lib/cjs/presentation-common/rules/Rule.js.map +1 -1
  119. package/lib/cjs/presentation-common/rules/Ruleset.d.ts +66 -66
  120. package/lib/cjs/presentation-common/rules/Ruleset.js +9 -9
  121. package/lib/cjs/presentation-common/rules/Ruleset.js.map +1 -1
  122. package/lib/cjs/presentation-common/rules/SchemasSpecification.d.ts +41 -41
  123. package/lib/cjs/presentation-common/rules/SchemasSpecification.js +9 -9
  124. package/lib/cjs/presentation-common/rules/SchemasSpecification.js.map +1 -1
  125. package/lib/cjs/presentation-common/rules/Variables.d.ts +55 -55
  126. package/lib/cjs/presentation-common/rules/Variables.js +25 -25
  127. package/lib/cjs/presentation-common/rules/Variables.js.map +1 -1
  128. package/lib/cjs/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.d.ts +41 -41
  129. package/lib/cjs/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js +9 -9
  130. package/lib/cjs/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js.map +1 -1
  131. package/lib/cjs/presentation-common/rules/content/ContentRelatedInstancesSpecification.d.ts +25 -25
  132. package/lib/cjs/presentation-common/rules/content/ContentRelatedInstancesSpecification.js +9 -9
  133. package/lib/cjs/presentation-common/rules/content/ContentRelatedInstancesSpecification.js.map +1 -1
  134. package/lib/cjs/presentation-common/rules/content/ContentRule.d.ts +30 -30
  135. package/lib/cjs/presentation-common/rules/content/ContentRule.js +9 -9
  136. package/lib/cjs/presentation-common/rules/content/ContentRule.js.map +1 -1
  137. package/lib/cjs/presentation-common/rules/content/ContentSpecification.d.ts +55 -55
  138. package/lib/cjs/presentation-common/rules/content/ContentSpecification.js +20 -20
  139. package/lib/cjs/presentation-common/rules/content/ContentSpecification.js.map +1 -1
  140. package/lib/cjs/presentation-common/rules/content/DefaultPropertyCategoryOverride.d.ts +19 -19
  141. package/lib/cjs/presentation-common/rules/content/DefaultPropertyCategoryOverride.js +9 -9
  142. package/lib/cjs/presentation-common/rules/content/DefaultPropertyCategoryOverride.js.map +1 -1
  143. package/lib/cjs/presentation-common/rules/content/PropertySpecification.d.ts +86 -86
  144. package/lib/cjs/presentation-common/rules/content/PropertySpecification.js +9 -9
  145. package/lib/cjs/presentation-common/rules/content/PropertySpecification.js.map +1 -1
  146. package/lib/cjs/presentation-common/rules/content/SelectedNodeInstancesSpecification.d.ts +28 -28
  147. package/lib/cjs/presentation-common/rules/content/SelectedNodeInstancesSpecification.js +9 -9
  148. package/lib/cjs/presentation-common/rules/content/SelectedNodeInstancesSpecification.js.map +1 -1
  149. package/lib/cjs/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.d.ts +25 -25
  150. package/lib/cjs/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js +9 -9
  151. package/lib/cjs/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js.map +1 -1
  152. package/lib/cjs/presentation-common/rules/content/modifiers/ContentModifier.d.ts +57 -57
  153. package/lib/cjs/presentation-common/rules/content/modifiers/ContentModifier.js +9 -9
  154. package/lib/cjs/presentation-common/rules/content/modifiers/ContentModifier.js.map +1 -1
  155. package/lib/cjs/presentation-common/rules/content/modifiers/CustomRendererSpecification.d.ts +17 -17
  156. package/lib/cjs/presentation-common/rules/content/modifiers/CustomRendererSpecification.js +9 -9
  157. package/lib/cjs/presentation-common/rules/content/modifiers/CustomRendererSpecification.js.map +1 -1
  158. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.d.ts +107 -107
  159. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js +9 -9
  160. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js.map +1 -1
  161. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.d.ts +105 -105
  162. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js +21 -21
  163. package/lib/cjs/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js.map +1 -1
  164. package/lib/cjs/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.d.ts +93 -93
  165. package/lib/cjs/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js +43 -43
  166. package/lib/cjs/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js.map +1 -1
  167. package/lib/cjs/presentation-common/rules/customization/CheckBoxRule.d.ts +44 -44
  168. package/lib/cjs/presentation-common/rules/customization/CheckBoxRule.js +9 -9
  169. package/lib/cjs/presentation-common/rules/customization/CheckBoxRule.js.map +1 -1
  170. package/lib/cjs/presentation-common/rules/customization/CustomizationRule.d.ts +36 -36
  171. package/lib/cjs/presentation-common/rules/customization/CustomizationRule.js +9 -9
  172. package/lib/cjs/presentation-common/rules/customization/CustomizationRule.js.map +1 -1
  173. package/lib/cjs/presentation-common/rules/customization/ExtendedDataRule.d.ts +27 -27
  174. package/lib/cjs/presentation-common/rules/customization/ExtendedDataRule.js +9 -9
  175. package/lib/cjs/presentation-common/rules/customization/ExtendedDataRule.js.map +1 -1
  176. package/lib/cjs/presentation-common/rules/customization/GroupingRule.d.ts +200 -200
  177. package/lib/cjs/presentation-common/rules/customization/GroupingRule.js +51 -51
  178. package/lib/cjs/presentation-common/rules/customization/GroupingRule.js.map +1 -1
  179. package/lib/cjs/presentation-common/rules/customization/ImageIdOverride.d.ts +29 -29
  180. package/lib/cjs/presentation-common/rules/customization/ImageIdOverride.js +9 -9
  181. package/lib/cjs/presentation-common/rules/customization/ImageIdOverride.js.map +1 -1
  182. package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.d.ts +156 -156
  183. package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.js +25 -25
  184. package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.js.map +1 -1
  185. package/lib/cjs/presentation-common/rules/customization/LabelOverride.d.ts +40 -40
  186. package/lib/cjs/presentation-common/rules/customization/LabelOverride.js +9 -9
  187. package/lib/cjs/presentation-common/rules/customization/LabelOverride.js.map +1 -1
  188. package/lib/cjs/presentation-common/rules/customization/SortingRule.d.ts +58 -58
  189. package/lib/cjs/presentation-common/rules/customization/SortingRule.js +9 -9
  190. package/lib/cjs/presentation-common/rules/customization/SortingRule.js.map +1 -1
  191. package/lib/cjs/presentation-common/rules/customization/StyleOverride.d.ts +48 -48
  192. package/lib/cjs/presentation-common/rules/customization/StyleOverride.js +9 -9
  193. package/lib/cjs/presentation-common/rules/customization/StyleOverride.js.map +1 -1
  194. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeRule.d.ts +15 -15
  195. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeRule.js +9 -9
  196. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeRule.js.map +1 -1
  197. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.d.ts +97 -97
  198. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.js +22 -22
  199. package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.js.map +1 -1
  200. package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.d.ts +31 -31
  201. package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.js +9 -9
  202. package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.js.map +1 -1
  203. package/lib/cjs/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.d.ts +76 -76
  204. package/lib/cjs/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js +19 -19
  205. package/lib/cjs/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js.map +1 -1
  206. package/lib/cjs/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.d.ts +39 -39
  207. package/lib/cjs/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js +9 -9
  208. package/lib/cjs/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js.map +1 -1
  209. package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.d.ts +50 -50
  210. package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.js +9 -9
  211. package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.js.map +1 -1
  212. package/lib/cjs/presentation-common/rules/hierarchy/NodeArtifactsRule.d.ts +27 -27
  213. package/lib/cjs/presentation-common/rules/hierarchy/NodeArtifactsRule.js +9 -9
  214. package/lib/cjs/presentation-common/rules/hierarchy/NodeArtifactsRule.js.map +1 -1
  215. package/lib/cjs/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.d.ts +27 -27
  216. package/lib/cjs/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js +9 -9
  217. package/lib/cjs/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js.map +1 -1
  218. package/lib/cjs/presentation-common/rules/hierarchy/RootNodeRule.d.ts +17 -17
  219. package/lib/cjs/presentation-common/rules/hierarchy/RootNodeRule.js +9 -9
  220. package/lib/cjs/presentation-common/rules/hierarchy/RootNodeRule.js.map +1 -1
  221. package/lib/cjs/presentation-common/rules/hierarchy/SubCondition.d.ts +36 -36
  222. package/lib/cjs/presentation-common/rules/hierarchy/SubCondition.js +9 -9
  223. package/lib/cjs/presentation-common/rules/hierarchy/SubCondition.js.map +1 -1
  224. package/lib/cjs/presentation-common/selection/SelectionScope.d.ts +25 -25
  225. package/lib/cjs/presentation-common/selection/SelectionScope.js +9 -9
  226. package/lib/cjs/presentation-common/selection/SelectionScope.js.map +1 -1
  227. package/lib/cjs/presentation-common.d.ts +110 -110
  228. package/lib/cjs/presentation-common.js +126 -126
  229. package/lib/cjs/presentation-common.js.map +1 -1
  230. package/lib/esm/presentation-common/AsyncTasks.d.ts +22 -22
  231. package/lib/esm/presentation-common/AsyncTasks.js +34 -34
  232. package/lib/esm/presentation-common/AsyncTasks.js.map +1 -1
  233. package/lib/esm/presentation-common/CommonLoggerCategory.d.ts +12 -12
  234. package/lib/esm/presentation-common/CommonLoggerCategory.js +17 -17
  235. package/lib/esm/presentation-common/CommonLoggerCategory.js.map +1 -1
  236. package/lib/esm/presentation-common/Diagnostics.d.ts +125 -125
  237. package/lib/esm/presentation-common/Diagnostics.js +67 -67
  238. package/lib/esm/presentation-common/Diagnostics.js.map +1 -1
  239. package/lib/esm/presentation-common/EC.d.ts +315 -315
  240. package/lib/esm/presentation-common/EC.js +267 -267
  241. package/lib/esm/presentation-common/EC.js.map +1 -1
  242. package/lib/esm/presentation-common/ElementProperties.d.ts +123 -123
  243. package/lib/esm/presentation-common/ElementProperties.js +8 -8
  244. package/lib/esm/presentation-common/ElementProperties.js.map +1 -1
  245. package/lib/esm/presentation-common/Error.d.ts +45 -45
  246. package/lib/esm/presentation-common/Error.js +58 -58
  247. package/lib/esm/presentation-common/Error.js.map +1 -1
  248. package/lib/esm/presentation-common/KeySet.d.ts +146 -146
  249. package/lib/esm/presentation-common/KeySet.js +414 -414
  250. package/lib/esm/presentation-common/KeySet.js.map +1 -1
  251. package/lib/esm/presentation-common/LabelDefinition.d.ts +79 -79
  252. package/lib/esm/presentation-common/LabelDefinition.js +73 -73
  253. package/lib/esm/presentation-common/LabelDefinition.js.map +1 -1
  254. package/lib/esm/presentation-common/LocalizationHelper.d.ts +29 -29
  255. package/lib/esm/presentation-common/LocalizationHelper.js +106 -106
  256. package/lib/esm/presentation-common/LocalizationHelper.js.map +1 -1
  257. package/lib/esm/presentation-common/PresentationIpcInterface.d.ts +37 -37
  258. package/lib/esm/presentation-common/PresentationIpcInterface.js +9 -9
  259. package/lib/esm/presentation-common/PresentationIpcInterface.js.map +1 -1
  260. package/lib/esm/presentation-common/PresentationManagerOptions.d.ts +242 -242
  261. package/lib/esm/presentation-common/PresentationManagerOptions.js +18 -18
  262. package/lib/esm/presentation-common/PresentationManagerOptions.js.map +1 -1
  263. package/lib/esm/presentation-common/PresentationRpcInterface.d.ts +181 -181
  264. package/lib/esm/presentation-common/PresentationRpcInterface.js +98 -98
  265. package/lib/esm/presentation-common/PresentationRpcInterface.js.map +1 -1
  266. package/lib/esm/presentation-common/RegisteredRuleset.d.ts +26 -26
  267. package/lib/esm/presentation-common/RegisteredRuleset.js +29 -29
  268. package/lib/esm/presentation-common/RegisteredRuleset.js.map +1 -1
  269. package/lib/esm/presentation-common/RpcRequestsHandler.d.ts +82 -82
  270. package/lib/esm/presentation-common/RpcRequestsHandler.js +151 -151
  271. package/lib/esm/presentation-common/RpcRequestsHandler.js.map +1 -1
  272. package/lib/esm/presentation-common/RulesetVariables.d.ts +166 -166
  273. package/lib/esm/presentation-common/RulesetVariables.js +52 -52
  274. package/lib/esm/presentation-common/RulesetVariables.js.map +1 -1
  275. package/lib/esm/presentation-common/RulesetsFactory.d.ts +44 -44
  276. package/lib/esm/presentation-common/RulesetsFactory.js +219 -219
  277. package/lib/esm/presentation-common/RulesetsFactory.js.map +1 -1
  278. package/lib/esm/presentation-common/Update.d.ts +194 -194
  279. package/lib/esm/presentation-common/Update.js +193 -193
  280. package/lib/esm/presentation-common/Update.js.map +1 -1
  281. package/lib/esm/presentation-common/Utils.d.ts +64 -64
  282. package/lib/esm/presentation-common/Utils.js +41 -41
  283. package/lib/esm/presentation-common/Utils.js.map +1 -1
  284. package/lib/esm/presentation-common/content/Category.d.ts +49 -49
  285. package/lib/esm/presentation-common/content/Category.js +46 -46
  286. package/lib/esm/presentation-common/content/Category.js.map +1 -1
  287. package/lib/esm/presentation-common/content/Content.d.ts +38 -38
  288. package/lib/esm/presentation-common/content/Content.js +52 -52
  289. package/lib/esm/presentation-common/content/Content.js.map +1 -1
  290. package/lib/esm/presentation-common/content/ContentTraverser.d.ts +101 -101
  291. package/lib/esm/presentation-common/content/ContentTraverser.js +411 -411
  292. package/lib/esm/presentation-common/content/ContentTraverser.js.map +1 -1
  293. package/lib/esm/presentation-common/content/Descriptor.d.ts +240 -240
  294. package/lib/esm/presentation-common/content/Descriptor.js +185 -185
  295. package/lib/esm/presentation-common/content/Descriptor.js.map +1 -1
  296. package/lib/esm/presentation-common/content/DisplayTypes.d.ts +21 -21
  297. package/lib/esm/presentation-common/content/DisplayTypes.js +26 -26
  298. package/lib/esm/presentation-common/content/DisplayTypes.js.map +1 -1
  299. package/lib/esm/presentation-common/content/Editor.d.ts +15 -15
  300. package/lib/esm/presentation-common/content/Editor.js +8 -8
  301. package/lib/esm/presentation-common/content/Editor.js.map +1 -1
  302. package/lib/esm/presentation-common/content/Fields.d.ts +282 -282
  303. package/lib/esm/presentation-common/content/Fields.js +387 -387
  304. package/lib/esm/presentation-common/content/Fields.js.map +1 -1
  305. package/lib/esm/presentation-common/content/Item.d.ts +87 -87
  306. package/lib/esm/presentation-common/content/Item.js +82 -82
  307. package/lib/esm/presentation-common/content/Item.js.map +1 -1
  308. package/lib/esm/presentation-common/content/Property.d.ts +51 -51
  309. package/lib/esm/presentation-common/content/Property.js +33 -33
  310. package/lib/esm/presentation-common/content/Property.js.map +1 -1
  311. package/lib/esm/presentation-common/content/Renderer.d.ts +11 -11
  312. package/lib/esm/presentation-common/content/Renderer.js +8 -8
  313. package/lib/esm/presentation-common/content/Renderer.js.map +1 -1
  314. package/lib/esm/presentation-common/content/TypeDescription.d.ts +72 -72
  315. package/lib/esm/presentation-common/content/TypeDescription.js +20 -20
  316. package/lib/esm/presentation-common/content/TypeDescription.js.map +1 -1
  317. package/lib/esm/presentation-common/content/Value.d.ts +157 -157
  318. package/lib/esm/presentation-common/content/Value.js +214 -214
  319. package/lib/esm/presentation-common/content/Value.js.map +1 -1
  320. package/lib/esm/presentation-common/hierarchy/Key.d.ts +185 -185
  321. package/lib/esm/presentation-common/hierarchy/Key.js +109 -109
  322. package/lib/esm/presentation-common/hierarchy/Key.js.map +1 -1
  323. package/lib/esm/presentation-common/hierarchy/Node.d.ts +141 -141
  324. package/lib/esm/presentation-common/hierarchy/Node.js +94 -94
  325. package/lib/esm/presentation-common/hierarchy/Node.js.map +1 -1
  326. package/lib/esm/presentation-common/hierarchy/NodePathElement.d.ts +85 -85
  327. package/lib/esm/presentation-common/hierarchy/NodePathElement.js +95 -95
  328. package/lib/esm/presentation-common/hierarchy/NodePathElement.js.map +1 -1
  329. package/lib/esm/presentation-common/rules/ClassSpecifications.d.ts +45 -45
  330. package/lib/esm/presentation-common/rules/ClassSpecifications.js +8 -8
  331. package/lib/esm/presentation-common/rules/ClassSpecifications.js.map +1 -1
  332. package/lib/esm/presentation-common/rules/RelatedInstanceSpecification.d.ts +31 -31
  333. package/lib/esm/presentation-common/rules/RelatedInstanceSpecification.js +8 -8
  334. package/lib/esm/presentation-common/rules/RelatedInstanceSpecification.js.map +1 -1
  335. package/lib/esm/presentation-common/rules/RelationshipDirection.d.ts +13 -13
  336. package/lib/esm/presentation-common/rules/RelationshipDirection.js +18 -18
  337. package/lib/esm/presentation-common/rules/RelationshipDirection.js.map +1 -1
  338. package/lib/esm/presentation-common/rules/RelationshipPathSpecification.d.ts +53 -53
  339. package/lib/esm/presentation-common/rules/RelationshipPathSpecification.js +8 -8
  340. package/lib/esm/presentation-common/rules/RelationshipPathSpecification.js.map +1 -1
  341. package/lib/esm/presentation-common/rules/Rule.d.ts +74 -74
  342. package/lib/esm/presentation-common/rules/Rule.js +32 -32
  343. package/lib/esm/presentation-common/rules/Rule.js.map +1 -1
  344. package/lib/esm/presentation-common/rules/Ruleset.d.ts +66 -66
  345. package/lib/esm/presentation-common/rules/Ruleset.js +8 -8
  346. package/lib/esm/presentation-common/rules/Ruleset.js.map +1 -1
  347. package/lib/esm/presentation-common/rules/SchemasSpecification.d.ts +41 -41
  348. package/lib/esm/presentation-common/rules/SchemasSpecification.js +8 -8
  349. package/lib/esm/presentation-common/rules/SchemasSpecification.js.map +1 -1
  350. package/lib/esm/presentation-common/rules/Variables.d.ts +55 -55
  351. package/lib/esm/presentation-common/rules/Variables.js +22 -22
  352. package/lib/esm/presentation-common/rules/Variables.js.map +1 -1
  353. package/lib/esm/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.d.ts +41 -41
  354. package/lib/esm/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js +8 -8
  355. package/lib/esm/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js.map +1 -1
  356. package/lib/esm/presentation-common/rules/content/ContentRelatedInstancesSpecification.d.ts +25 -25
  357. package/lib/esm/presentation-common/rules/content/ContentRelatedInstancesSpecification.js +8 -8
  358. package/lib/esm/presentation-common/rules/content/ContentRelatedInstancesSpecification.js.map +1 -1
  359. package/lib/esm/presentation-common/rules/content/ContentRule.d.ts +30 -30
  360. package/lib/esm/presentation-common/rules/content/ContentRule.js +8 -8
  361. package/lib/esm/presentation-common/rules/content/ContentRule.js.map +1 -1
  362. package/lib/esm/presentation-common/rules/content/ContentSpecification.d.ts +55 -55
  363. package/lib/esm/presentation-common/rules/content/ContentSpecification.js +17 -17
  364. package/lib/esm/presentation-common/rules/content/ContentSpecification.js.map +1 -1
  365. package/lib/esm/presentation-common/rules/content/DefaultPropertyCategoryOverride.d.ts +19 -19
  366. package/lib/esm/presentation-common/rules/content/DefaultPropertyCategoryOverride.js +8 -8
  367. package/lib/esm/presentation-common/rules/content/DefaultPropertyCategoryOverride.js.map +1 -1
  368. package/lib/esm/presentation-common/rules/content/PropertySpecification.d.ts +86 -86
  369. package/lib/esm/presentation-common/rules/content/PropertySpecification.js +8 -8
  370. package/lib/esm/presentation-common/rules/content/PropertySpecification.js.map +1 -1
  371. package/lib/esm/presentation-common/rules/content/SelectedNodeInstancesSpecification.d.ts +28 -28
  372. package/lib/esm/presentation-common/rules/content/SelectedNodeInstancesSpecification.js +8 -8
  373. package/lib/esm/presentation-common/rules/content/SelectedNodeInstancesSpecification.js.map +1 -1
  374. package/lib/esm/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.d.ts +25 -25
  375. package/lib/esm/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js +8 -8
  376. package/lib/esm/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js.map +1 -1
  377. package/lib/esm/presentation-common/rules/content/modifiers/ContentModifier.d.ts +57 -57
  378. package/lib/esm/presentation-common/rules/content/modifiers/ContentModifier.js +8 -8
  379. package/lib/esm/presentation-common/rules/content/modifiers/ContentModifier.js.map +1 -1
  380. package/lib/esm/presentation-common/rules/content/modifiers/CustomRendererSpecification.d.ts +17 -17
  381. package/lib/esm/presentation-common/rules/content/modifiers/CustomRendererSpecification.js +8 -8
  382. package/lib/esm/presentation-common/rules/content/modifiers/CustomRendererSpecification.js.map +1 -1
  383. package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.d.ts +107 -107
  384. package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js +8 -8
  385. package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js.map +1 -1
  386. package/lib/esm/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.d.ts +105 -105
  387. package/lib/esm/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js +18 -18
  388. package/lib/esm/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js.map +1 -1
  389. package/lib/esm/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.d.ts +93 -93
  390. package/lib/esm/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js +40 -40
  391. package/lib/esm/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js.map +1 -1
  392. package/lib/esm/presentation-common/rules/customization/CheckBoxRule.d.ts +44 -44
  393. package/lib/esm/presentation-common/rules/customization/CheckBoxRule.js +8 -8
  394. package/lib/esm/presentation-common/rules/customization/CheckBoxRule.js.map +1 -1
  395. package/lib/esm/presentation-common/rules/customization/CustomizationRule.d.ts +36 -36
  396. package/lib/esm/presentation-common/rules/customization/CustomizationRule.js +8 -8
  397. package/lib/esm/presentation-common/rules/customization/CustomizationRule.js.map +1 -1
  398. package/lib/esm/presentation-common/rules/customization/ExtendedDataRule.d.ts +27 -27
  399. package/lib/esm/presentation-common/rules/customization/ExtendedDataRule.js +8 -8
  400. package/lib/esm/presentation-common/rules/customization/ExtendedDataRule.js.map +1 -1
  401. package/lib/esm/presentation-common/rules/customization/GroupingRule.d.ts +200 -200
  402. package/lib/esm/presentation-common/rules/customization/GroupingRule.js +48 -48
  403. package/lib/esm/presentation-common/rules/customization/GroupingRule.js.map +1 -1
  404. package/lib/esm/presentation-common/rules/customization/ImageIdOverride.d.ts +29 -29
  405. package/lib/esm/presentation-common/rules/customization/ImageIdOverride.js +8 -8
  406. package/lib/esm/presentation-common/rules/customization/ImageIdOverride.js.map +1 -1
  407. package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.d.ts +156 -156
  408. package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.js +22 -22
  409. package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.js.map +1 -1
  410. package/lib/esm/presentation-common/rules/customization/LabelOverride.d.ts +40 -40
  411. package/lib/esm/presentation-common/rules/customization/LabelOverride.js +8 -8
  412. package/lib/esm/presentation-common/rules/customization/LabelOverride.js.map +1 -1
  413. package/lib/esm/presentation-common/rules/customization/SortingRule.d.ts +58 -58
  414. package/lib/esm/presentation-common/rules/customization/SortingRule.js +8 -8
  415. package/lib/esm/presentation-common/rules/customization/SortingRule.js.map +1 -1
  416. package/lib/esm/presentation-common/rules/customization/StyleOverride.d.ts +48 -48
  417. package/lib/esm/presentation-common/rules/customization/StyleOverride.js +8 -8
  418. package/lib/esm/presentation-common/rules/customization/StyleOverride.js.map +1 -1
  419. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeRule.d.ts +15 -15
  420. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeRule.js +8 -8
  421. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeRule.js.map +1 -1
  422. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.d.ts +97 -97
  423. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.js +19 -19
  424. package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.js.map +1 -1
  425. package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.d.ts +31 -31
  426. package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.js +8 -8
  427. package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.js.map +1 -1
  428. package/lib/esm/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.d.ts +76 -76
  429. package/lib/esm/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js +16 -16
  430. package/lib/esm/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js.map +1 -1
  431. package/lib/esm/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.d.ts +39 -39
  432. package/lib/esm/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js +8 -8
  433. package/lib/esm/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js.map +1 -1
  434. package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.d.ts +50 -50
  435. package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.js +8 -8
  436. package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.js.map +1 -1
  437. package/lib/esm/presentation-common/rules/hierarchy/NodeArtifactsRule.d.ts +27 -27
  438. package/lib/esm/presentation-common/rules/hierarchy/NodeArtifactsRule.js +8 -8
  439. package/lib/esm/presentation-common/rules/hierarchy/NodeArtifactsRule.js.map +1 -1
  440. package/lib/esm/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.d.ts +27 -27
  441. package/lib/esm/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js +8 -8
  442. package/lib/esm/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js.map +1 -1
  443. package/lib/esm/presentation-common/rules/hierarchy/RootNodeRule.d.ts +17 -17
  444. package/lib/esm/presentation-common/rules/hierarchy/RootNodeRule.js +8 -8
  445. package/lib/esm/presentation-common/rules/hierarchy/RootNodeRule.js.map +1 -1
  446. package/lib/esm/presentation-common/rules/hierarchy/SubCondition.d.ts +36 -36
  447. package/lib/esm/presentation-common/rules/hierarchy/SubCondition.js +8 -8
  448. package/lib/esm/presentation-common/rules/hierarchy/SubCondition.js.map +1 -1
  449. package/lib/esm/presentation-common/selection/SelectionScope.d.ts +25 -25
  450. package/lib/esm/presentation-common/selection/SelectionScope.js +8 -8
  451. package/lib/esm/presentation-common/selection/SelectionScope.js.map +1 -1
  452. package/lib/esm/presentation-common.d.ts +110 -110
  453. package/lib/esm/presentation-common.js +114 -114
  454. package/lib/esm/presentation-common.js.map +1 -1
  455. package/lib/public/locales/en/BisCore.json +18 -18
  456. package/lib/public/locales/en/ECPresentation.json +9 -9
  457. package/lib/public/locales/en/RulesEngine.json +5 -5
  458. package/package.json +9 -9
@@ -1,224 +1,224 @@
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
- /** @packageDocumentation
7
- * @module Core
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.RulesetsFactory = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const TypeDescription_1 = require("./content/TypeDescription");
13
- const Value_1 = require("./content/Value");
14
- const EC_1 = require("./EC");
15
- const ContentSpecification_1 = require("./rules/content/ContentSpecification");
16
- const RelationshipDirection_1 = require("./rules/RelationshipDirection");
17
- const Rule_1 = require("./rules/Rule");
18
- /**
19
- * A factory class that can be used to create presentation rulesets targeted towards
20
- * specific use cases.
21
- *
22
- * @public
23
- */
24
- class RulesetsFactory {
25
- createSimilarInstancesRulesetInfo(field, record) {
26
- if (!field.isPropertiesField())
27
- throw new Error("Can only create 'similar instances' ruleset for properties-based records");
28
- if (field.type.valueFormat !== TypeDescription_1.PropertyValueFormat.Primitive)
29
- throw new Error("Can only create 'similar instances' ruleset for primitive properties");
30
- if (field.properties.length === 0)
31
- throw new Error("Invalid properties' field with no properties");
32
- if (record.isFieldMerged(field.name))
33
- throw new Error("Can't create 'similar instances' ruleset for merged values");
34
- if (!record.classInfo)
35
- throw new Error("Can't create 'similar instances' for records based on multiple different ECClass instances");
36
- const propertyName = getPropertyName(field);
37
- const propertyValue = getPropertyValue(record, field);
38
- const relatedInstanceInfo = createRelatedInstanceSpecInfo(field);
39
- const relatedClass = relatedInstanceInfo === null || relatedInstanceInfo === void 0 ? void 0 : relatedInstanceInfo.class;
40
- const ruleset = {
41
- id: `SimilarInstances/${propertyName}/${core_bentley_1.Guid.createValue()}`,
42
- rules: [],
43
- };
44
- ruleset.rules.push({
45
- ruleType: Rule_1.RuleTypes.Content,
46
- specifications: [{
47
- specType: ContentSpecification_1.ContentSpecificationTypes.ContentInstancesOfSpecificClasses,
48
- classes: createMultiClassSpecification(record.classInfo),
49
- handleInstancesPolymorphically: true,
50
- relatedInstances: relatedInstanceInfo ? [relatedInstanceInfo.spec] : [],
51
- instanceFilter: createInstanceFilter(relatedInstanceInfo === null || relatedInstanceInfo === void 0 ? void 0 : relatedInstanceInfo.spec, field.type, propertyName, propertyValue.raw),
52
- }],
53
- });
54
- return { ruleset, relatedClass, propertyName, propertyValue };
55
- }
56
- /**
57
- * Create a ruleset with content rules for getting instances are of the
58
- * same ECClass and have the same property value as the provided `record`.
59
- * @param field A field identifying which property of the record we should use
60
- * @param record A record whose similar instances should be found
61
- * @param computeDisplayValue Optional callback function to calculate display value that's
62
- * used in ruleset's description. If not provided, display value from record is used instead.
63
- */
64
- async createSimilarInstancesRuleset(field, record, computeDisplayValue) {
65
- const info = this.createSimilarInstancesRulesetInfo(field, record);
66
- const description = await createDescriptionAsync(record, info.relatedClass, field, info.propertyValue, computeDisplayValue);
67
- return { ruleset: info.ruleset, description };
68
- }
69
- }
70
- exports.RulesetsFactory = RulesetsFactory;
71
- const toString = (displayValue) => {
72
- if (!displayValue)
73
- return "NULL";
74
- return displayValue.toString();
75
- };
76
- const createDescription = (record, relatedClass, field, value) => {
77
- const classInfo = relatedClass !== null && relatedClass !== void 0 ? relatedClass : record.classInfo;
78
- return `[${classInfo.label}].[${field.label}] = ${value}`;
79
- };
80
- const createDescriptionAsync = async (record, relatedClass, field, value, computeDisplayValue) => {
81
- const displayValue = computeDisplayValue ? await computeDisplayValue(field.type.typeName, value.raw, value.display) : toString(value.display);
82
- return createDescription(record, relatedClass, field, displayValue);
83
- };
84
- const getPropertyName = (field) => {
85
- let name = field.properties[0].property.name;
86
- if (field.type.typeName === "navigation")
87
- name += ".Id";
88
- return name;
89
- };
90
- const isPrimitivePropertyValue = (value) => {
91
- if (Value_1.Value.isPrimitive(value)) {
92
- return true;
93
- }
94
- if (Value_1.Value.isMap(value)) {
95
- if (typeof value.x === "number"
96
- && typeof value.y === "number"
97
- && (value.z === undefined || typeof value.z === "number")) {
98
- return true;
99
- }
100
- if (typeof value.className === "string" && typeof value.id === "string") {
101
- return true;
102
- }
103
- }
104
- return false;
105
- };
106
- const getPropertyValue = (record, field) => {
107
- const fieldNamesStack = [];
108
- let currField = field;
109
- while (currField) {
110
- fieldNamesStack.push(currField.name);
111
- currField = currField.parent;
112
- }
113
- let currFieldName = fieldNamesStack.pop();
114
- let displayValue = record.displayValues[currFieldName];
115
- let value = record.values[currFieldName];
116
- currFieldName = fieldNamesStack.pop();
117
- while (currFieldName) {
118
- if (!Value_1.Value.isNestedContent(value) || value.length === 0)
119
- throw new Error("Invalid record value");
120
- if (value.length > 1)
121
- throw new Error("Can't create 'similar instances' for records related through many part of *-to-many relationship");
122
- if (value[0].mergedFieldNames.indexOf(currFieldName) !== -1)
123
- throw new Error("Can't create 'similar instances' ruleset for merged values");
124
- displayValue = value[0].displayValues[currFieldName];
125
- value = value[0].values[currFieldName];
126
- currFieldName = fieldNamesStack.pop();
127
- }
128
- if (!isPrimitivePropertyValue(value))
129
- throw new Error("Can only create 'similar instances' ruleset for primitive values");
130
- return { raw: value, display: toString(displayValue) };
131
- };
132
- const createInstanceFilter = (relatedInstanceSpec, propertyType, propertyName, propertyValue) => {
133
- const alias = relatedInstanceSpec ? relatedInstanceSpec.alias : "this";
134
- return createComparison(propertyType, `${alias}.${propertyName}`, "=", propertyValue);
135
- };
136
- const createComparison = (type, name, operator, value) => {
137
- let compareValue = "";
138
- switch (typeof value) {
139
- case "undefined":
140
- compareValue = "NULL";
141
- break;
142
- case "string":
143
- compareValue = `"${value.replace(/"/g, `""`)}"`;
144
- break;
145
- case "boolean":
146
- compareValue = value ? "TRUE" : "FALSE";
147
- break;
148
- case "number":
149
- compareValue = value.toString();
150
- break;
151
- }
152
- if (type.typeName === "navigation" && typeof value === "object" && core_bentley_1.Id64.isId64(value.id))
153
- // note: this is temporary until we support hex ids in instance filters
154
- compareValue = hexToDec(value.id);
155
- if (type.typeName === "point2d" || type.typeName === "point3d") {
156
- if (typeof value !== "object")
157
- throw new Error("Expecting point values to be supplied as objects");
158
- const dimensionType = {
159
- valueFormat: TypeDescription_1.PropertyValueFormat.Primitive,
160
- typeName: "double",
161
- };
162
- const pointValue = value;
163
- let comparison = `${createComparison(dimensionType, `${name}.x`, operator, pointValue.x)}`;
164
- comparison += ` AND ${createComparison(dimensionType, `${name}.y`, operator, pointValue.y)}`;
165
- if (type.typeName === "point3d" && pointValue.z !== undefined)
166
- comparison += ` AND ${createComparison(dimensionType, `${name}.z`, operator, pointValue.z)}`;
167
- return comparison;
168
- }
169
- if (type.typeName === "double")
170
- return `CompareDoubles(${name}, ${compareValue}) ${operator} 0`;
171
- if (type.typeName === "dateTime")
172
- return `CompareDateTimes(${name}, ${compareValue}) ${operator} 0`;
173
- return `${name} ${operator} ${compareValue}`;
174
- };
175
- const createMultiClassSpecification = (classInfo) => {
176
- const [schemaName, className] = classInfo.name.split(":");
177
- return { schemaName, classNames: [className] };
178
- };
179
- const createSingleClassSpecification = (classInfo) => {
180
- const [schemaName, className] = classInfo.name.split(":");
181
- return { schemaName, className };
182
- };
183
- const createRelatedInstanceSpec = (pathFromSelectToPropertyClass, index) => ({
184
- spec: {
185
- relationshipPath: pathFromSelectToPropertyClass.map((step) => ({
186
- relationship: createSingleClassSpecification(step.relationshipInfo),
187
- direction: step.isForwardRelationship ? RelationshipDirection_1.RelationshipDirection.Forward : RelationshipDirection_1.RelationshipDirection.Backward,
188
- targetClass: createSingleClassSpecification(step.targetClassInfo),
189
- })),
190
- isRequired: true,
191
- alias: `related_${index}`,
192
- },
193
- class: pathFromSelectToPropertyClass[pathFromSelectToPropertyClass.length - 1].targetClassInfo,
194
- });
195
- const createPathFromSelectToPropertyClass = (field) => {
196
- let currField = field;
197
- const pathFromPropertyToSelectClass = [];
198
- while (currField.parent) {
199
- pathFromPropertyToSelectClass.push(...currField.parent.pathToPrimaryClass);
200
- currField = currField.parent;
201
- }
202
- return EC_1.RelationshipPath.reverse(pathFromPropertyToSelectClass);
203
- };
204
- const createRelatedInstanceSpecInfo = (field) => {
205
- const path = createPathFromSelectToPropertyClass(field);
206
- return path.length ? createRelatedInstanceSpec(path, 0) : undefined;
207
- };
208
- const hexToDec = (id) => {
209
- const digits = [0];
210
- for (let i = 2; i < id.length; ++i) {
211
- let carry = parseInt(id.charAt(i), 16);
212
- for (let j = 0; j < digits.length; ++j) {
213
- digits[j] = digits[j] * 16 + carry;
214
- carry = digits[j] / 10 | 0;
215
- digits[j] %= 10;
216
- }
217
- while (carry > 0) {
218
- digits.push(carry % 10);
219
- carry = carry / 10 | 0;
220
- }
221
- }
222
- return digits.reverse().join("");
223
- };
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
+ /** @packageDocumentation
7
+ * @module Core
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.RulesetsFactory = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const TypeDescription_1 = require("./content/TypeDescription");
13
+ const Value_1 = require("./content/Value");
14
+ const EC_1 = require("./EC");
15
+ const ContentSpecification_1 = require("./rules/content/ContentSpecification");
16
+ const RelationshipDirection_1 = require("./rules/RelationshipDirection");
17
+ const Rule_1 = require("./rules/Rule");
18
+ /**
19
+ * A factory class that can be used to create presentation rulesets targeted towards
20
+ * specific use cases.
21
+ *
22
+ * @public
23
+ */
24
+ class RulesetsFactory {
25
+ createSimilarInstancesRulesetInfo(field, record) {
26
+ if (!field.isPropertiesField())
27
+ throw new Error("Can only create 'similar instances' ruleset for properties-based records");
28
+ if (field.type.valueFormat !== TypeDescription_1.PropertyValueFormat.Primitive)
29
+ throw new Error("Can only create 'similar instances' ruleset for primitive properties");
30
+ if (field.properties.length === 0)
31
+ throw new Error("Invalid properties' field with no properties");
32
+ if (record.isFieldMerged(field.name))
33
+ throw new Error("Can't create 'similar instances' ruleset for merged values");
34
+ if (!record.classInfo)
35
+ throw new Error("Can't create 'similar instances' for records based on multiple different ECClass instances");
36
+ const propertyName = getPropertyName(field);
37
+ const propertyValue = getPropertyValue(record, field);
38
+ const relatedInstanceInfo = createRelatedInstanceSpecInfo(field);
39
+ const relatedClass = relatedInstanceInfo === null || relatedInstanceInfo === void 0 ? void 0 : relatedInstanceInfo.class;
40
+ const ruleset = {
41
+ id: `SimilarInstances/${propertyName}/${core_bentley_1.Guid.createValue()}`,
42
+ rules: [],
43
+ };
44
+ ruleset.rules.push({
45
+ ruleType: Rule_1.RuleTypes.Content,
46
+ specifications: [{
47
+ specType: ContentSpecification_1.ContentSpecificationTypes.ContentInstancesOfSpecificClasses,
48
+ classes: createMultiClassSpecification(record.classInfo),
49
+ handleInstancesPolymorphically: true,
50
+ relatedInstances: relatedInstanceInfo ? [relatedInstanceInfo.spec] : [],
51
+ instanceFilter: createInstanceFilter(relatedInstanceInfo === null || relatedInstanceInfo === void 0 ? void 0 : relatedInstanceInfo.spec, field.type, propertyName, propertyValue.raw),
52
+ }],
53
+ });
54
+ return { ruleset, relatedClass, propertyName, propertyValue };
55
+ }
56
+ /**
57
+ * Create a ruleset with content rules for getting instances are of the
58
+ * same ECClass and have the same property value as the provided `record`.
59
+ * @param field A field identifying which property of the record we should use
60
+ * @param record A record whose similar instances should be found
61
+ * @param computeDisplayValue Optional callback function to calculate display value that's
62
+ * used in ruleset's description. If not provided, display value from record is used instead.
63
+ */
64
+ async createSimilarInstancesRuleset(field, record, computeDisplayValue) {
65
+ const info = this.createSimilarInstancesRulesetInfo(field, record);
66
+ const description = await createDescriptionAsync(record, info.relatedClass, field, info.propertyValue, computeDisplayValue);
67
+ return { ruleset: info.ruleset, description };
68
+ }
69
+ }
70
+ exports.RulesetsFactory = RulesetsFactory;
71
+ const toString = (displayValue) => {
72
+ if (!displayValue)
73
+ return "NULL";
74
+ return displayValue.toString();
75
+ };
76
+ const createDescription = (record, relatedClass, field, value) => {
77
+ const classInfo = relatedClass !== null && relatedClass !== void 0 ? relatedClass : record.classInfo;
78
+ return `[${classInfo.label}].[${field.label}] = ${value}`;
79
+ };
80
+ const createDescriptionAsync = async (record, relatedClass, field, value, computeDisplayValue) => {
81
+ const displayValue = computeDisplayValue ? await computeDisplayValue(field.type.typeName, value.raw, value.display) : toString(value.display);
82
+ return createDescription(record, relatedClass, field, displayValue);
83
+ };
84
+ const getPropertyName = (field) => {
85
+ let name = field.properties[0].property.name;
86
+ if (field.type.typeName === "navigation")
87
+ name += ".Id";
88
+ return name;
89
+ };
90
+ const isPrimitivePropertyValue = (value) => {
91
+ if (Value_1.Value.isPrimitive(value)) {
92
+ return true;
93
+ }
94
+ if (Value_1.Value.isMap(value)) {
95
+ if (typeof value.x === "number"
96
+ && typeof value.y === "number"
97
+ && (value.z === undefined || typeof value.z === "number")) {
98
+ return true;
99
+ }
100
+ if (typeof value.className === "string" && typeof value.id === "string") {
101
+ return true;
102
+ }
103
+ }
104
+ return false;
105
+ };
106
+ const getPropertyValue = (record, field) => {
107
+ const fieldNamesStack = [];
108
+ let currField = field;
109
+ while (currField) {
110
+ fieldNamesStack.push(currField.name);
111
+ currField = currField.parent;
112
+ }
113
+ let currFieldName = fieldNamesStack.pop();
114
+ let displayValue = record.displayValues[currFieldName];
115
+ let value = record.values[currFieldName];
116
+ currFieldName = fieldNamesStack.pop();
117
+ while (currFieldName) {
118
+ if (!Value_1.Value.isNestedContent(value) || value.length === 0)
119
+ throw new Error("Invalid record value");
120
+ if (value.length > 1)
121
+ throw new Error("Can't create 'similar instances' for records related through many part of *-to-many relationship");
122
+ if (value[0].mergedFieldNames.indexOf(currFieldName) !== -1)
123
+ throw new Error("Can't create 'similar instances' ruleset for merged values");
124
+ displayValue = value[0].displayValues[currFieldName];
125
+ value = value[0].values[currFieldName];
126
+ currFieldName = fieldNamesStack.pop();
127
+ }
128
+ if (!isPrimitivePropertyValue(value))
129
+ throw new Error("Can only create 'similar instances' ruleset for primitive values");
130
+ return { raw: value, display: toString(displayValue) };
131
+ };
132
+ const createInstanceFilter = (relatedInstanceSpec, propertyType, propertyName, propertyValue) => {
133
+ const alias = relatedInstanceSpec ? relatedInstanceSpec.alias : "this";
134
+ return createComparison(propertyType, `${alias}.${propertyName}`, "=", propertyValue);
135
+ };
136
+ const createComparison = (type, name, operator, value) => {
137
+ let compareValue = "";
138
+ switch (typeof value) {
139
+ case "undefined":
140
+ compareValue = "NULL";
141
+ break;
142
+ case "string":
143
+ compareValue = `"${value.replace(/"/g, `""`)}"`;
144
+ break;
145
+ case "boolean":
146
+ compareValue = value ? "TRUE" : "FALSE";
147
+ break;
148
+ case "number":
149
+ compareValue = value.toString();
150
+ break;
151
+ }
152
+ if (type.typeName === "navigation" && typeof value === "object" && core_bentley_1.Id64.isId64(value.id))
153
+ // note: this is temporary until we support hex ids in instance filters
154
+ compareValue = hexToDec(value.id);
155
+ if (type.typeName === "point2d" || type.typeName === "point3d") {
156
+ if (typeof value !== "object")
157
+ throw new Error("Expecting point values to be supplied as objects");
158
+ const dimensionType = {
159
+ valueFormat: TypeDescription_1.PropertyValueFormat.Primitive,
160
+ typeName: "double",
161
+ };
162
+ const pointValue = value;
163
+ let comparison = `${createComparison(dimensionType, `${name}.x`, operator, pointValue.x)}`;
164
+ comparison += ` AND ${createComparison(dimensionType, `${name}.y`, operator, pointValue.y)}`;
165
+ if (type.typeName === "point3d" && pointValue.z !== undefined)
166
+ comparison += ` AND ${createComparison(dimensionType, `${name}.z`, operator, pointValue.z)}`;
167
+ return comparison;
168
+ }
169
+ if (type.typeName === "double")
170
+ return `CompareDoubles(${name}, ${compareValue}) ${operator} 0`;
171
+ if (type.typeName === "dateTime")
172
+ return `CompareDateTimes(${name}, ${compareValue}) ${operator} 0`;
173
+ return `${name} ${operator} ${compareValue}`;
174
+ };
175
+ const createMultiClassSpecification = (classInfo) => {
176
+ const [schemaName, className] = classInfo.name.split(":");
177
+ return { schemaName, classNames: [className] };
178
+ };
179
+ const createSingleClassSpecification = (classInfo) => {
180
+ const [schemaName, className] = classInfo.name.split(":");
181
+ return { schemaName, className };
182
+ };
183
+ const createRelatedInstanceSpec = (pathFromSelectToPropertyClass, index) => ({
184
+ spec: {
185
+ relationshipPath: pathFromSelectToPropertyClass.map((step) => ({
186
+ relationship: createSingleClassSpecification(step.relationshipInfo),
187
+ direction: step.isForwardRelationship ? RelationshipDirection_1.RelationshipDirection.Forward : RelationshipDirection_1.RelationshipDirection.Backward,
188
+ targetClass: createSingleClassSpecification(step.targetClassInfo),
189
+ })),
190
+ isRequired: true,
191
+ alias: `related_${index}`,
192
+ },
193
+ class: pathFromSelectToPropertyClass[pathFromSelectToPropertyClass.length - 1].targetClassInfo,
194
+ });
195
+ const createPathFromSelectToPropertyClass = (field) => {
196
+ let currField = field;
197
+ const pathFromPropertyToSelectClass = [];
198
+ while (currField.parent) {
199
+ pathFromPropertyToSelectClass.push(...currField.parent.pathToPrimaryClass);
200
+ currField = currField.parent;
201
+ }
202
+ return EC_1.RelationshipPath.reverse(pathFromPropertyToSelectClass);
203
+ };
204
+ const createRelatedInstanceSpecInfo = (field) => {
205
+ const path = createPathFromSelectToPropertyClass(field);
206
+ return path.length ? createRelatedInstanceSpec(path, 0) : undefined;
207
+ };
208
+ const hexToDec = (id) => {
209
+ const digits = [0];
210
+ for (let i = 2; i < id.length; ++i) {
211
+ let carry = parseInt(id.charAt(i), 16);
212
+ for (let j = 0; j < digits.length; ++j) {
213
+ digits[j] = digits[j] * 16 + carry;
214
+ carry = digits[j] / 10 | 0;
215
+ digits[j] %= 10;
216
+ }
217
+ while (carry > 0) {
218
+ digits.push(carry % 10);
219
+ carry = carry / 10 | 0;
220
+ }
221
+ }
222
+ return digits.reverse().join("");
223
+ };
224
224
  //# sourceMappingURL=RulesetsFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RulesetsFactory.js","sourceRoot":"","sources":["../../../src/presentation-common/RulesetsFactory.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6D;AAG7D,+DAA0F;AAC1F,2CAAsD;AACtD,6BAAgE;AAEhE,+EAAiF;AAEjF,yEAAsE;AACtE,uCAAyC;AAGzC;;;;;GAKG;AACH,MAAa,eAAe;IAClB,iCAAiC,CAAC,KAAY,EAAE,MAAY;QAClE,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;QAC9F,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,KAAK,qCAAmB,CAAC,SAAS;YAC1D,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,IAAI,CAAC,MAAM,CAAC,SAAS;YACnB,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;QAChH,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAA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AE,CAAC,EAAE;YACtC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;YACnC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC3B,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACjB;QACD,OAAO,KAAK,GAAG,CAAC,EAAE;YAChB,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;YACxB,KAAK,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;SACxB;KACF;IACD,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC,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/** @packageDocumentation\n * @module Core\n */\n\nimport { Guid, Id64, Id64String } from \"@itwin/core-bentley\";\nimport { Field, PropertiesField } from \"./content/Fields\";\nimport { Item } from \"./content/Item\";\nimport { PrimitiveTypeDescription, PropertyValueFormat } from \"./content/TypeDescription\";\nimport { DisplayValue, Value } from \"./content/Value\";\nimport { ClassInfo, InstanceKey, RelationshipPath } from \"./EC\";\nimport { MultiSchemaClassesSpecification, SingleSchemaClassSpecification } from \"./rules/ClassSpecifications\";\nimport { ContentSpecificationTypes } from \"./rules/content/ContentSpecification\";\nimport { RelatedInstanceSpecification } from \"./rules/RelatedInstanceSpecification\";\nimport { RelationshipDirection } from \"./rules/RelationshipDirection\";\nimport { RuleTypes } from \"./rules/Rule\";\nimport { Ruleset } from \"./rules/Ruleset\";\n\n/**\n * A factory class that can be used to create presentation rulesets targeted towards\n * specific use cases.\n *\n * @public\n */\nexport class RulesetsFactory {\n private createSimilarInstancesRulesetInfo(field: Field, record: Item) {\n if (!field.isPropertiesField())\n throw new Error(\"Can only create 'similar instances' ruleset for properties-based records\");\n if (field.type.valueFormat !== PropertyValueFormat.Primitive)\n throw new Error(\"Can only create 'similar instances' ruleset for primitive properties\");\n if (field.properties.length === 0)\n throw new Error(\"Invalid properties' field with no properties\");\n if (record.isFieldMerged(field.name))\n throw new Error(\"Can't create 'similar instances' ruleset for merged values\");\n if (!record.classInfo)\n throw new Error(\"Can't create 'similar instances' for records based on multiple different ECClass instances\");\n const propertyName = getPropertyName(field);\n const propertyValue = getPropertyValue(record, field);\n const relatedInstanceInfo = createRelatedInstanceSpecInfo(field);\n const relatedClass = relatedInstanceInfo?.class;\n const ruleset: Ruleset = {\n id: `SimilarInstances/${propertyName}/${Guid.createValue()}`,\n rules: [],\n };\n ruleset.rules.push({\n ruleType: RuleTypes.Content,\n specifications: [{\n specType: ContentSpecificationTypes.ContentInstancesOfSpecificClasses,\n classes: createMultiClassSpecification(record.classInfo),\n handleInstancesPolymorphically: true,\n relatedInstances: relatedInstanceInfo ? [relatedInstanceInfo.spec] : [],\n instanceFilter: createInstanceFilter(relatedInstanceInfo?.spec, field.type, propertyName, propertyValue.raw),\n }],\n });\n return { ruleset, relatedClass, propertyName, propertyValue };\n }\n\n /**\n * Create a ruleset with content rules for getting instances are of the\n * same ECClass and have the same property value as the provided `record`.\n * @param field A field identifying which property of the record we should use\n * @param record A record whose similar instances should be found\n * @param computeDisplayValue Optional callback function to calculate display value that's\n * used in ruleset's description. If not provided, display value from record is used instead.\n */\n public async createSimilarInstancesRuleset(field: Field, record: Item, computeDisplayValue?: ComputeDisplayValueCallback): Promise<{ ruleset: Ruleset, description: string }> {\n const info = this.createSimilarInstancesRulesetInfo(field, record);\n const description = await createDescriptionAsync(record, info.relatedClass, field, info.propertyValue, computeDisplayValue);\n return { ruleset: info.ruleset, description };\n }\n}\n\n/**\n * Definition of a function for calculating a display value.\n * @public\n */\nexport type ComputeDisplayValueCallback = (type: string, value: PrimitivePropertyValue, displayValue: string) => Promise<string>;\n\ninterface PrimitiveValueDef {\n raw: PrimitivePropertyValue;\n display: string;\n}\n\n/**\n * Value of a primitive property.\n * @public\n */\nexport type PrimitivePropertyValue = string | number | boolean | Point | InstanceKey | undefined;\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ntype Point = { x: number, y: number, z?: number };\n\nconst toString = (displayValue: Value | DisplayValue): string => {\n if (!displayValue)\n return \"NULL\";\n return displayValue.toString();\n};\n\nconst createDescription = (record: Item, relatedClass: ClassInfo | undefined, field: Field, value: string): string => {\n const classInfo = relatedClass ?? record.classInfo!;\n return `[${classInfo.label}].[${field.label}] = ${value}`;\n};\n\nconst createDescriptionAsync = async (record: Item, relatedClass: ClassInfo | undefined, field: Field, value: PrimitiveValueDef, computeDisplayValue?: ComputeDisplayValueCallback): Promise<string> => {\n const displayValue = computeDisplayValue ? await computeDisplayValue(field.type.typeName, value.raw, value.display) : toString(value.display);\n return createDescription(record, relatedClass, field, displayValue);\n};\n\nconst getPropertyName = (field: PropertiesField) => {\n let name = field.properties[0].property.name;\n if (field.type.typeName === \"navigation\")\n name += \".Id\";\n return name;\n};\n\nconst isPrimitivePropertyValue = (value: Value): value is PrimitivePropertyValue => {\n if (Value.isPrimitive(value)) {\n return true;\n }\n\n if (Value.isMap(value)) {\n if (typeof value.x === \"number\"\n && typeof value.y === \"number\"\n && (value.z === undefined || typeof value.z === \"number\")) {\n return true;\n }\n\n if (typeof value.className === \"string\" && typeof value.id === \"string\") {\n return true;\n }\n }\n\n return false;\n};\n\nconst getPropertyValue = (record: Item, field: Field): PrimitiveValueDef => {\n const fieldNamesStack = [];\n let currField: Field | undefined = field;\n while (currField) {\n fieldNamesStack.push(currField.name);\n currField = currField.parent;\n }\n let currFieldName = fieldNamesStack.pop();\n let displayValue: DisplayValue = record.displayValues[currFieldName!];\n let value: Value = record.values[currFieldName!];\n currFieldName = fieldNamesStack.pop();\n while (currFieldName) {\n if (!Value.isNestedContent(value) || value.length === 0)\n throw new Error(\"Invalid record value\");\n if (value.length > 1)\n throw new Error(\"Can't create 'similar instances' for records related through many part of *-to-many relationship\");\n if (value[0].mergedFieldNames.indexOf(currFieldName) !== -1)\n throw new Error(\"Can't create 'similar instances' ruleset for merged values\");\n displayValue = value[0].displayValues[currFieldName];\n value = value[0].values[currFieldName];\n currFieldName = fieldNamesStack.pop();\n }\n if (!isPrimitivePropertyValue(value))\n throw new Error(\"Can only create 'similar instances' ruleset for primitive values\");\n return { raw: value, display: toString(displayValue) };\n};\n\nconst createInstanceFilter = (\n relatedInstanceSpec: Readonly<RelatedInstanceSpecification> | undefined,\n propertyType: PrimitiveTypeDescription,\n propertyName: string,\n propertyValue: PrimitivePropertyValue,\n): string => {\n const alias = relatedInstanceSpec ? relatedInstanceSpec.alias : \"this\";\n return createComparison(propertyType, `${alias}.${propertyName}`, \"=\", propertyValue);\n};\n\ntype Operator = \"=\" | \"!=\" | \">\" | \">=\" | \"<\" | \"<=\";\nconst createComparison = (type: PrimitiveTypeDescription, name: string, operator: Operator, value: PrimitivePropertyValue): string => {\n let compareValue = \"\";\n switch (typeof value) {\n case \"undefined\":\n compareValue = \"NULL\";\n break;\n case \"string\":\n compareValue = `\"${value.replace(/\"/g, `\"\"`)}\"`;\n break;\n case \"boolean\":\n compareValue = value ? \"TRUE\" : \"FALSE\";\n break;\n case \"number\":\n compareValue = value.toString();\n break;\n }\n\n if (type.typeName === \"navigation\" && typeof value === \"object\" && Id64.isId64((value as InstanceKey).id))\n // note: this is temporary until we support hex ids in instance filters\n compareValue = hexToDec((value as InstanceKey).id);\n\n if (type.typeName === \"point2d\" || type.typeName === \"point3d\") {\n if (typeof value !== \"object\")\n throw new Error(\"Expecting point values to be supplied as objects\");\n\n const dimensionType: PrimitiveTypeDescription = {\n valueFormat: PropertyValueFormat.Primitive,\n typeName: \"double\",\n };\n\n const pointValue = value as Point;\n let comparison = `${createComparison(dimensionType, `${name}.x`, operator, pointValue.x)}`;\n comparison += ` AND ${createComparison(dimensionType, `${name}.y`, operator, pointValue.y)}`;\n if (type.typeName === \"point3d\" && pointValue.z !== undefined)\n comparison += ` AND ${createComparison(dimensionType, `${name}.z`, operator, pointValue.z)}`;\n\n return comparison;\n }\n\n if (type.typeName === \"double\")\n return `CompareDoubles(${name}, ${compareValue}) ${operator} 0`;\n\n if (type.typeName === \"dateTime\")\n return `CompareDateTimes(${name}, ${compareValue}) ${operator} 0`;\n\n return `${name} ${operator} ${compareValue}`;\n};\n\nconst createMultiClassSpecification = (classInfo: Readonly<ClassInfo>): MultiSchemaClassesSpecification => {\n const [schemaName, className] = classInfo.name.split(\":\");\n return { schemaName, classNames: [className] };\n};\n\nconst createSingleClassSpecification = (classInfo: Readonly<ClassInfo>): SingleSchemaClassSpecification => {\n const [schemaName, className] = classInfo.name.split(\":\");\n return { schemaName, className };\n};\n\nconst createRelatedInstanceSpec = (pathFromSelectToPropertyClass: RelationshipPath, index: number): { spec: RelatedInstanceSpecification, class: ClassInfo } => ({\n spec: {\n relationshipPath: pathFromSelectToPropertyClass.map((step) => ({\n relationship: createSingleClassSpecification(step.relationshipInfo),\n direction: step.isForwardRelationship ? RelationshipDirection.Forward : RelationshipDirection.Backward,\n targetClass: createSingleClassSpecification(step.targetClassInfo),\n })),\n isRequired: true,\n alias: `related_${index}`,\n },\n class: pathFromSelectToPropertyClass[pathFromSelectToPropertyClass.length - 1].targetClassInfo,\n});\n\nconst createPathFromSelectToPropertyClass = (field: PropertiesField): RelationshipPath => {\n let currField: Field = field;\n const pathFromPropertyToSelectClass: RelationshipPath = [];\n while (currField.parent) {\n pathFromPropertyToSelectClass.push(...currField.parent.pathToPrimaryClass);\n currField = currField.parent;\n }\n return RelationshipPath.reverse(pathFromPropertyToSelectClass);\n};\n\nconst createRelatedInstanceSpecInfo = (field: PropertiesField): { spec: RelatedInstanceSpecification, class: ClassInfo } | undefined => {\n const path = createPathFromSelectToPropertyClass(field);\n return path.length ? createRelatedInstanceSpec(path, 0) : undefined;\n};\n\nconst hexToDec = (id: Id64String) => {\n const digits = [0];\n for (let i = 2; i < id.length; ++i) {\n let carry = parseInt(id.charAt(i), 16);\n for (let j = 0; j < digits.length; ++j) {\n digits[j] = digits[j] * 16 + carry;\n carry = digits[j] / 10 | 0;\n digits[j] %= 10;\n }\n while (carry > 0) {\n digits.push(carry % 10);\n carry = carry / 10 | 0;\n }\n }\n return digits.reverse().join(\"\");\n};\n"]}
1
+ {"version":3,"file":"RulesetsFactory.js","sourceRoot":"","sources":["../../../src/presentation-common/RulesetsFactory.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6D;AAG7D,+DAA0F;AAC1F,2CAAsD;AACtD,6BAAgE;AAEhE,+EAAiF;AAEjF,yEAAsE;AACtE,uCAAyC;AAGzC;;;;;GAKG;AACH,MAAa,eAAe;IAClB,iCAAiC,CAAC,KAAY,EAAE,MAAY;QAClE,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;QAC9F,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,KAAK,qCAAmB,CAAC,SAAS;YAC1D,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QAC1F,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;YAClC,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;QAChF,IAAI,CAAC,MAAM,CAAC,SAAS;YACnB,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;QAChH,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACtD,MAAM,mBAAmB,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC;QACj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,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAC3B,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACjB;QACD,OAAO,KAAK,GAAG,CAAC,EAAE;YAChB,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;YACxB,KAAK,GAAG,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;SACxB;KACF;IACD,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { Guid, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { Field, PropertiesField } from \"./content/Fields\";\r\nimport { Item } from \"./content/Item\";\r\nimport { PrimitiveTypeDescription, PropertyValueFormat } from \"./content/TypeDescription\";\r\nimport { DisplayValue, Value } from \"./content/Value\";\r\nimport { ClassInfo, InstanceKey, RelationshipPath } from \"./EC\";\r\nimport { MultiSchemaClassesSpecification, SingleSchemaClassSpecification } from \"./rules/ClassSpecifications\";\r\nimport { ContentSpecificationTypes } from \"./rules/content/ContentSpecification\";\r\nimport { RelatedInstanceSpecification } from \"./rules/RelatedInstanceSpecification\";\r\nimport { RelationshipDirection } from \"./rules/RelationshipDirection\";\r\nimport { RuleTypes } from \"./rules/Rule\";\r\nimport { Ruleset } from \"./rules/Ruleset\";\r\n\r\n/**\r\n * A factory class that can be used to create presentation rulesets targeted towards\r\n * specific use cases.\r\n *\r\n * @public\r\n */\r\nexport class RulesetsFactory {\r\n private createSimilarInstancesRulesetInfo(field: Field, record: Item) {\r\n if (!field.isPropertiesField())\r\n throw new Error(\"Can only create 'similar instances' ruleset for properties-based records\");\r\n if (field.type.valueFormat !== PropertyValueFormat.Primitive)\r\n throw new Error(\"Can only create 'similar instances' ruleset for primitive properties\");\r\n if (field.properties.length === 0)\r\n throw new Error(\"Invalid properties' field with no properties\");\r\n if (record.isFieldMerged(field.name))\r\n throw new Error(\"Can't create 'similar instances' ruleset for merged values\");\r\n if (!record.classInfo)\r\n throw new Error(\"Can't create 'similar instances' for records based on multiple different ECClass instances\");\r\n const propertyName = getPropertyName(field);\r\n const propertyValue = getPropertyValue(record, field);\r\n const relatedInstanceInfo = createRelatedInstanceSpecInfo(field);\r\n const relatedClass = relatedInstanceInfo?.class;\r\n const ruleset: Ruleset = {\r\n id: `SimilarInstances/${propertyName}/${Guid.createValue()}`,\r\n rules: [],\r\n };\r\n ruleset.rules.push({\r\n ruleType: RuleTypes.Content,\r\n specifications: [{\r\n specType: ContentSpecificationTypes.ContentInstancesOfSpecificClasses,\r\n classes: createMultiClassSpecification(record.classInfo),\r\n handleInstancesPolymorphically: true,\r\n relatedInstances: relatedInstanceInfo ? [relatedInstanceInfo.spec] : [],\r\n instanceFilter: createInstanceFilter(relatedInstanceInfo?.spec, field.type, propertyName, propertyValue.raw),\r\n }],\r\n });\r\n return { ruleset, relatedClass, propertyName, propertyValue };\r\n }\r\n\r\n /**\r\n * Create a ruleset with content rules for getting instances are of the\r\n * same ECClass and have the same property value as the provided `record`.\r\n * @param field A field identifying which property of the record we should use\r\n * @param record A record whose similar instances should be found\r\n * @param computeDisplayValue Optional callback function to calculate display value that's\r\n * used in ruleset's description. If not provided, display value from record is used instead.\r\n */\r\n public async createSimilarInstancesRuleset(field: Field, record: Item, computeDisplayValue?: ComputeDisplayValueCallback): Promise<{ ruleset: Ruleset, description: string }> {\r\n const info = this.createSimilarInstancesRulesetInfo(field, record);\r\n const description = await createDescriptionAsync(record, info.relatedClass, field, info.propertyValue, computeDisplayValue);\r\n return { ruleset: info.ruleset, description };\r\n }\r\n}\r\n\r\n/**\r\n * Definition of a function for calculating a display value.\r\n * @public\r\n */\r\nexport type ComputeDisplayValueCallback = (type: string, value: PrimitivePropertyValue, displayValue: string) => Promise<string>;\r\n\r\ninterface PrimitiveValueDef {\r\n raw: PrimitivePropertyValue;\r\n display: string;\r\n}\r\n\r\n/**\r\n * Value of a primitive property.\r\n * @public\r\n */\r\nexport type PrimitivePropertyValue = string | number | boolean | Point | InstanceKey | undefined;\r\n\r\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\r\ntype Point = { x: number, y: number, z?: number };\r\n\r\nconst toString = (displayValue: Value | DisplayValue): string => {\r\n if (!displayValue)\r\n return \"NULL\";\r\n return displayValue.toString();\r\n};\r\n\r\nconst createDescription = (record: Item, relatedClass: ClassInfo | undefined, field: Field, value: string): string => {\r\n const classInfo = relatedClass ?? record.classInfo!;\r\n return `[${classInfo.label}].[${field.label}] = ${value}`;\r\n};\r\n\r\nconst createDescriptionAsync = async (record: Item, relatedClass: ClassInfo | undefined, field: Field, value: PrimitiveValueDef, computeDisplayValue?: ComputeDisplayValueCallback): Promise<string> => {\r\n const displayValue = computeDisplayValue ? await computeDisplayValue(field.type.typeName, value.raw, value.display) : toString(value.display);\r\n return createDescription(record, relatedClass, field, displayValue);\r\n};\r\n\r\nconst getPropertyName = (field: PropertiesField) => {\r\n let name = field.properties[0].property.name;\r\n if (field.type.typeName === \"navigation\")\r\n name += \".Id\";\r\n return name;\r\n};\r\n\r\nconst isPrimitivePropertyValue = (value: Value): value is PrimitivePropertyValue => {\r\n if (Value.isPrimitive(value)) {\r\n return true;\r\n }\r\n\r\n if (Value.isMap(value)) {\r\n if (typeof value.x === \"number\"\r\n && typeof value.y === \"number\"\r\n && (value.z === undefined || typeof value.z === \"number\")) {\r\n return true;\r\n }\r\n\r\n if (typeof value.className === \"string\" && typeof value.id === \"string\") {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n};\r\n\r\nconst getPropertyValue = (record: Item, field: Field): PrimitiveValueDef => {\r\n const fieldNamesStack = [];\r\n let currField: Field | undefined = field;\r\n while (currField) {\r\n fieldNamesStack.push(currField.name);\r\n currField = currField.parent;\r\n }\r\n let currFieldName = fieldNamesStack.pop();\r\n let displayValue: DisplayValue = record.displayValues[currFieldName!];\r\n let value: Value = record.values[currFieldName!];\r\n currFieldName = fieldNamesStack.pop();\r\n while (currFieldName) {\r\n if (!Value.isNestedContent(value) || value.length === 0)\r\n throw new Error(\"Invalid record value\");\r\n if (value.length > 1)\r\n throw new Error(\"Can't create 'similar instances' for records related through many part of *-to-many relationship\");\r\n if (value[0].mergedFieldNames.indexOf(currFieldName) !== -1)\r\n throw new Error(\"Can't create 'similar instances' ruleset for merged values\");\r\n displayValue = value[0].displayValues[currFieldName];\r\n value = value[0].values[currFieldName];\r\n currFieldName = fieldNamesStack.pop();\r\n }\r\n if (!isPrimitivePropertyValue(value))\r\n throw new Error(\"Can only create 'similar instances' ruleset for primitive values\");\r\n return { raw: value, display: toString(displayValue) };\r\n};\r\n\r\nconst createInstanceFilter = (\r\n relatedInstanceSpec: Readonly<RelatedInstanceSpecification> | undefined,\r\n propertyType: PrimitiveTypeDescription,\r\n propertyName: string,\r\n propertyValue: PrimitivePropertyValue,\r\n): string => {\r\n const alias = relatedInstanceSpec ? relatedInstanceSpec.alias : \"this\";\r\n return createComparison(propertyType, `${alias}.${propertyName}`, \"=\", propertyValue);\r\n};\r\n\r\ntype Operator = \"=\" | \"!=\" | \">\" | \">=\" | \"<\" | \"<=\";\r\nconst createComparison = (type: PrimitiveTypeDescription, name: string, operator: Operator, value: PrimitivePropertyValue): string => {\r\n let compareValue = \"\";\r\n switch (typeof value) {\r\n case \"undefined\":\r\n compareValue = \"NULL\";\r\n break;\r\n case \"string\":\r\n compareValue = `\"${value.replace(/\"/g, `\"\"`)}\"`;\r\n break;\r\n case \"boolean\":\r\n compareValue = value ? \"TRUE\" : \"FALSE\";\r\n break;\r\n case \"number\":\r\n compareValue = value.toString();\r\n break;\r\n }\r\n\r\n if (type.typeName === \"navigation\" && typeof value === \"object\" && Id64.isId64((value as InstanceKey).id))\r\n // note: this is temporary until we support hex ids in instance filters\r\n compareValue = hexToDec((value as InstanceKey).id);\r\n\r\n if (type.typeName === \"point2d\" || type.typeName === \"point3d\") {\r\n if (typeof value !== \"object\")\r\n throw new Error(\"Expecting point values to be supplied as objects\");\r\n\r\n const dimensionType: PrimitiveTypeDescription = {\r\n valueFormat: PropertyValueFormat.Primitive,\r\n typeName: \"double\",\r\n };\r\n\r\n const pointValue = value as Point;\r\n let comparison = `${createComparison(dimensionType, `${name}.x`, operator, pointValue.x)}`;\r\n comparison += ` AND ${createComparison(dimensionType, `${name}.y`, operator, pointValue.y)}`;\r\n if (type.typeName === \"point3d\" && pointValue.z !== undefined)\r\n comparison += ` AND ${createComparison(dimensionType, `${name}.z`, operator, pointValue.z)}`;\r\n\r\n return comparison;\r\n }\r\n\r\n if (type.typeName === \"double\")\r\n return `CompareDoubles(${name}, ${compareValue}) ${operator} 0`;\r\n\r\n if (type.typeName === \"dateTime\")\r\n return `CompareDateTimes(${name}, ${compareValue}) ${operator} 0`;\r\n\r\n return `${name} ${operator} ${compareValue}`;\r\n};\r\n\r\nconst createMultiClassSpecification = (classInfo: Readonly<ClassInfo>): MultiSchemaClassesSpecification => {\r\n const [schemaName, className] = classInfo.name.split(\":\");\r\n return { schemaName, classNames: [className] };\r\n};\r\n\r\nconst createSingleClassSpecification = (classInfo: Readonly<ClassInfo>): SingleSchemaClassSpecification => {\r\n const [schemaName, className] = classInfo.name.split(\":\");\r\n return { schemaName, className };\r\n};\r\n\r\nconst createRelatedInstanceSpec = (pathFromSelectToPropertyClass: RelationshipPath, index: number): { spec: RelatedInstanceSpecification, class: ClassInfo } => ({\r\n spec: {\r\n relationshipPath: pathFromSelectToPropertyClass.map((step) => ({\r\n relationship: createSingleClassSpecification(step.relationshipInfo),\r\n direction: step.isForwardRelationship ? RelationshipDirection.Forward : RelationshipDirection.Backward,\r\n targetClass: createSingleClassSpecification(step.targetClassInfo),\r\n })),\r\n isRequired: true,\r\n alias: `related_${index}`,\r\n },\r\n class: pathFromSelectToPropertyClass[pathFromSelectToPropertyClass.length - 1].targetClassInfo,\r\n});\r\n\r\nconst createPathFromSelectToPropertyClass = (field: PropertiesField): RelationshipPath => {\r\n let currField: Field = field;\r\n const pathFromPropertyToSelectClass: RelationshipPath = [];\r\n while (currField.parent) {\r\n pathFromPropertyToSelectClass.push(...currField.parent.pathToPrimaryClass);\r\n currField = currField.parent;\r\n }\r\n return RelationshipPath.reverse(pathFromPropertyToSelectClass);\r\n};\r\n\r\nconst createRelatedInstanceSpecInfo = (field: PropertiesField): { spec: RelatedInstanceSpecification, class: ClassInfo } | undefined => {\r\n const path = createPathFromSelectToPropertyClass(field);\r\n return path.length ? createRelatedInstanceSpec(path, 0) : undefined;\r\n};\r\n\r\nconst hexToDec = (id: Id64String) => {\r\n const digits = [0];\r\n for (let i = 2; i < id.length; ++i) {\r\n let carry = parseInt(id.charAt(i), 16);\r\n for (let j = 0; j < digits.length; ++j) {\r\n digits[j] = digits[j] * 16 + carry;\r\n carry = digits[j] / 10 | 0;\r\n digits[j] %= 10;\r\n }\r\n while (carry > 0) {\r\n digits.push(carry % 10);\r\n carry = carry / 10 | 0;\r\n }\r\n }\r\n return digits.reverse().join(\"\");\r\n};\r\n"]}