@itwin/presentation-common 4.0.0-dev.8 → 4.0.0-dev.80
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.
- package/CHANGELOG.md +51 -1
- package/Ruleset.schema.json +11 -0
- package/lib/cjs/assets/locales/en/Presentation.json +15 -0
- package/lib/cjs/assets/locales/en-PSEUDO/Presentation.json +15 -0
- package/lib/cjs/presentation-common/AsyncTasks.d.ts +22 -22
- package/lib/cjs/presentation-common/AsyncTasks.js +38 -38
- package/lib/cjs/presentation-common/CommonLoggerCategory.d.ts +12 -12
- package/lib/cjs/presentation-common/CommonLoggerCategory.js +20 -20
- package/lib/cjs/presentation-common/Diagnostics.d.ts +125 -125
- package/lib/cjs/presentation-common/Diagnostics.d.ts.map +1 -1
- package/lib/cjs/presentation-common/Diagnostics.js +72 -72
- package/lib/cjs/presentation-common/EC.d.ts +347 -350
- package/lib/cjs/presentation-common/EC.d.ts.map +1 -1
- package/lib/cjs/presentation-common/EC.js +290 -290
- package/lib/cjs/presentation-common/EC.js.map +1 -1
- package/lib/cjs/presentation-common/ElementProperties.d.ts +123 -123
- package/lib/cjs/presentation-common/ElementProperties.d.ts.map +1 -1
- package/lib/cjs/presentation-common/ElementProperties.js +9 -9
- package/lib/cjs/presentation-common/Error.d.ts +47 -45
- package/lib/cjs/presentation-common/Error.d.ts.map +1 -1
- package/lib/cjs/presentation-common/Error.js +64 -62
- package/lib/cjs/presentation-common/Error.js.map +1 -1
- package/lib/cjs/presentation-common/InstanceFilterDefinition.d.ts +93 -93
- package/lib/cjs/presentation-common/InstanceFilterDefinition.d.ts.map +1 -1
- package/lib/cjs/presentation-common/InstanceFilterDefinition.js +9 -9
- package/lib/cjs/presentation-common/KeySet.d.ts +146 -146
- package/lib/cjs/presentation-common/KeySet.d.ts.map +1 -1
- package/lib/cjs/presentation-common/KeySet.js +428 -428
- package/lib/cjs/presentation-common/LabelDefinition.d.ts +93 -87
- package/lib/cjs/presentation-common/LabelDefinition.d.ts.map +1 -1
- package/lib/cjs/presentation-common/LabelDefinition.js +78 -73
- package/lib/cjs/presentation-common/LabelDefinition.js.map +1 -1
- package/lib/cjs/presentation-common/LocalizationHelper.d.ts +29 -29
- package/lib/cjs/presentation-common/LocalizationHelper.js +110 -110
- package/lib/cjs/presentation-common/PresentationIpcInterface.d.ts +40 -40
- package/lib/cjs/presentation-common/PresentationIpcInterface.js +12 -12
- package/lib/cjs/presentation-common/PresentationManagerOptions.d.ts +273 -261
- package/lib/cjs/presentation-common/PresentationManagerOptions.d.ts.map +1 -1
- package/lib/cjs/presentation-common/PresentationManagerOptions.js +23 -23
- package/lib/cjs/presentation-common/PresentationManagerOptions.js.map +1 -1
- package/lib/cjs/presentation-common/PresentationRpcInterface.d.ts +186 -186
- package/lib/cjs/presentation-common/PresentationRpcInterface.d.ts.map +1 -1
- package/lib/cjs/presentation-common/PresentationRpcInterface.js +108 -104
- package/lib/cjs/presentation-common/PresentationRpcInterface.js.map +1 -1
- package/lib/cjs/presentation-common/PropertyFormatter.d.ts +31 -0
- package/lib/cjs/presentation-common/PropertyFormatter.d.ts.map +1 -0
- package/lib/cjs/presentation-common/PropertyFormatter.js +199 -0
- package/lib/cjs/presentation-common/PropertyFormatter.js.map +1 -0
- package/lib/cjs/presentation-common/RegisteredRuleset.d.ts +26 -26
- package/lib/cjs/presentation-common/RegisteredRuleset.js +33 -33
- package/lib/cjs/presentation-common/RpcRequestsHandler.d.ts +82 -83
- package/lib/cjs/presentation-common/RpcRequestsHandler.d.ts.map +1 -1
- package/lib/cjs/presentation-common/RpcRequestsHandler.js +166 -171
- package/lib/cjs/presentation-common/RpcRequestsHandler.js.map +1 -1
- package/lib/cjs/presentation-common/RulesetVariables.d.ts +171 -171
- package/lib/cjs/presentation-common/RulesetVariables.d.ts.map +1 -1
- package/lib/cjs/presentation-common/RulesetVariables.js +55 -55
- package/lib/cjs/presentation-common/RulesetsFactory.d.ts +44 -44
- package/lib/cjs/presentation-common/RulesetsFactory.d.ts.map +1 -1
- package/lib/cjs/presentation-common/RulesetsFactory.js +223 -223
- package/lib/cjs/presentation-common/RulesetsFactory.js.map +1 -1
- package/lib/cjs/presentation-common/Update.d.ts +213 -213
- package/lib/cjs/presentation-common/Update.d.ts.map +1 -1
- package/lib/cjs/presentation-common/Update.js +226 -226
- package/lib/cjs/presentation-common/Utils.d.ts +62 -62
- package/lib/cjs/presentation-common/Utils.d.ts.map +1 -1
- package/lib/cjs/presentation-common/Utils.js +43 -43
- package/lib/cjs/presentation-common/content/Category.d.ts +49 -49
- package/lib/cjs/presentation-common/content/Category.js +48 -48
- package/lib/cjs/presentation-common/content/Content.d.ts +38 -38
- package/lib/cjs/presentation-common/content/Content.js +56 -56
- package/lib/cjs/presentation-common/content/ContentTraverser.d.ts +271 -271
- package/lib/cjs/presentation-common/content/ContentTraverser.js +437 -439
- package/lib/cjs/presentation-common/content/ContentTraverser.js.map +1 -1
- package/lib/cjs/presentation-common/content/Descriptor.d.ts +328 -328
- package/lib/cjs/presentation-common/content/Descriptor.js +191 -193
- package/lib/cjs/presentation-common/content/Descriptor.js.map +1 -1
- package/lib/cjs/presentation-common/content/DisplayTypes.d.ts +21 -21
- package/lib/cjs/presentation-common/content/DisplayTypes.js +29 -29
- package/lib/cjs/presentation-common/content/Editor.d.ts +15 -15
- package/lib/cjs/presentation-common/content/Editor.js +9 -9
- package/lib/cjs/presentation-common/content/Fields.d.ts +298 -301
- package/lib/cjs/presentation-common/content/Fields.d.ts.map +1 -1
- package/lib/cjs/presentation-common/content/Fields.js +393 -397
- package/lib/cjs/presentation-common/content/Fields.js.map +1 -1
- package/lib/cjs/presentation-common/content/Item.d.ts +85 -85
- package/lib/cjs/presentation-common/content/Item.d.ts.map +1 -1
- package/lib/cjs/presentation-common/content/Item.js +84 -84
- package/lib/cjs/presentation-common/content/Item.js.map +1 -1
- package/lib/cjs/presentation-common/content/Property.d.ts +57 -57
- package/lib/cjs/presentation-common/content/Property.d.ts.map +1 -1
- package/lib/cjs/presentation-common/content/Property.js +40 -40
- package/lib/cjs/presentation-common/content/Renderer.d.ts +11 -11
- package/lib/cjs/presentation-common/content/Renderer.js +9 -9
- package/lib/cjs/presentation-common/content/TypeDescription.d.ts +72 -72
- package/lib/cjs/presentation-common/content/TypeDescription.d.ts.map +1 -1
- package/lib/cjs/presentation-common/content/TypeDescription.js +23 -23
- package/lib/cjs/presentation-common/content/Value.d.ts +189 -189
- package/lib/cjs/presentation-common/content/Value.d.ts.map +1 -1
- package/lib/cjs/presentation-common/content/Value.js +273 -273
- package/lib/cjs/presentation-common/hierarchy/HierarchyLevel.d.ts +37 -37
- package/lib/cjs/presentation-common/hierarchy/HierarchyLevel.js +31 -31
- package/lib/cjs/presentation-common/hierarchy/Key.d.ts +246 -246
- package/lib/cjs/presentation-common/hierarchy/Key.d.ts.map +1 -1
- package/lib/cjs/presentation-common/hierarchy/Key.js +121 -121
- package/lib/cjs/presentation-common/hierarchy/Key.js.map +1 -1
- package/lib/cjs/presentation-common/hierarchy/Node.d.ts +154 -154
- package/lib/cjs/presentation-common/hierarchy/Node.d.ts.map +1 -1
- package/lib/cjs/presentation-common/hierarchy/Node.js +106 -106
- package/lib/cjs/presentation-common/hierarchy/Node.js.map +1 -1
- package/lib/cjs/presentation-common/hierarchy/NodePathElement.d.ts +96 -96
- package/lib/cjs/presentation-common/hierarchy/NodePathElement.js +122 -122
- package/lib/cjs/presentation-common/rules/ClassSpecifications.d.ts +45 -45
- package/lib/cjs/presentation-common/rules/ClassSpecifications.js +9 -9
- package/lib/cjs/presentation-common/rules/RelatedInstanceSpecification.d.ts +31 -31
- package/lib/cjs/presentation-common/rules/RelatedInstanceSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/RelationshipDirection.d.ts +13 -13
- package/lib/cjs/presentation-common/rules/RelationshipDirection.js +21 -21
- package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.d.ts +56 -56
- package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.d.ts.map +1 -1
- package/lib/cjs/presentation-common/rules/RelationshipPathSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/Rule.d.ts +76 -76
- package/lib/cjs/presentation-common/rules/Rule.js +35 -35
- package/lib/cjs/presentation-common/rules/Ruleset.d.ts +65 -65
- package/lib/cjs/presentation-common/rules/Ruleset.js +9 -9
- package/lib/cjs/presentation-common/rules/SchemasSpecification.d.ts +41 -41
- package/lib/cjs/presentation-common/rules/SchemasSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/Variables.d.ts +58 -58
- package/lib/cjs/presentation-common/rules/Variables.js +25 -25
- package/lib/cjs/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.d.ts +41 -41
- package/lib/cjs/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/ContentRelatedInstancesSpecification.d.ts +25 -25
- package/lib/cjs/presentation-common/rules/content/ContentRelatedInstancesSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/ContentRule.d.ts +30 -30
- package/lib/cjs/presentation-common/rules/content/ContentRule.js +9 -9
- package/lib/cjs/presentation-common/rules/content/ContentSpecification.d.ts +58 -58
- package/lib/cjs/presentation-common/rules/content/ContentSpecification.js +20 -20
- package/lib/cjs/presentation-common/rules/content/DefaultPropertyCategoryOverride.d.ts +19 -19
- package/lib/cjs/presentation-common/rules/content/DefaultPropertyCategoryOverride.js +9 -9
- package/lib/cjs/presentation-common/rules/content/PropertySpecification.d.ts +86 -86
- package/lib/cjs/presentation-common/rules/content/PropertySpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/SelectedNodeInstancesSpecification.d.ts +28 -28
- package/lib/cjs/presentation-common/rules/content/SelectedNodeInstancesSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.d.ts +25 -25
- package/lib/cjs/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/modifiers/ContentModifier.d.ts +57 -57
- package/lib/cjs/presentation-common/rules/content/modifiers/ContentModifier.js +9 -9
- package/lib/cjs/presentation-common/rules/content/modifiers/CustomRendererSpecification.d.ts +17 -17
- package/lib/cjs/presentation-common/rules/content/modifiers/CustomRendererSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.d.ts +107 -107
- package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.d.ts.map +1 -1
- package/lib/cjs/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.d.ts +108 -108
- package/lib/cjs/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js +21 -21
- package/lib/cjs/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.d.ts +96 -96
- package/lib/cjs/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js +43 -43
- package/lib/cjs/presentation-common/rules/customization/CheckBoxRule.d.ts +44 -44
- package/lib/cjs/presentation-common/rules/customization/CheckBoxRule.js +9 -9
- package/lib/cjs/presentation-common/rules/customization/CustomizationRule.d.ts +36 -36
- package/lib/cjs/presentation-common/rules/customization/CustomizationRule.js +9 -9
- package/lib/cjs/presentation-common/rules/customization/ExtendedDataRule.d.ts +27 -27
- package/lib/cjs/presentation-common/rules/customization/ExtendedDataRule.js +9 -9
- package/lib/cjs/presentation-common/rules/customization/GroupingRule.d.ts +207 -207
- package/lib/cjs/presentation-common/rules/customization/GroupingRule.js +51 -51
- package/lib/cjs/presentation-common/rules/customization/ImageIdOverride.d.ts +29 -29
- package/lib/cjs/presentation-common/rules/customization/ImageIdOverride.js +9 -9
- package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.d.ts +158 -158
- package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.d.ts.map +1 -1
- package/lib/cjs/presentation-common/rules/customization/InstanceLabelOverride.js +25 -25
- package/lib/cjs/presentation-common/rules/customization/LabelOverride.d.ts +40 -40
- package/lib/cjs/presentation-common/rules/customization/LabelOverride.js +9 -9
- package/lib/cjs/presentation-common/rules/customization/SortingRule.d.ts +58 -58
- package/lib/cjs/presentation-common/rules/customization/SortingRule.d.ts.map +1 -1
- package/lib/cjs/presentation-common/rules/customization/SortingRule.js +9 -9
- package/lib/cjs/presentation-common/rules/customization/StyleOverride.d.ts +48 -48
- package/lib/cjs/presentation-common/rules/customization/StyleOverride.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeRule.d.ts +14 -14
- package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeRule.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.d.ts +98 -98
- package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.d.ts.map +1 -1
- package/lib/cjs/presentation-common/rules/hierarchy/ChildNodeSpecification.js +21 -21
- package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.d.ts +31 -31
- package/lib/cjs/presentation-common/rules/hierarchy/CustomNodeSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.d.ts +79 -79
- package/lib/cjs/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js +19 -19
- package/lib/cjs/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.d.ts +39 -39
- package/lib/cjs/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.d.ts +50 -50
- package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.d.ts.map +1 -1
- package/lib/cjs/presentation-common/rules/hierarchy/NavigationRule.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/NodeArtifactsRule.d.ts +27 -27
- package/lib/cjs/presentation-common/rules/hierarchy/NodeArtifactsRule.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.d.ts +27 -27
- package/lib/cjs/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/RootNodeRule.d.ts +16 -16
- package/lib/cjs/presentation-common/rules/hierarchy/RootNodeRule.js +9 -9
- package/lib/cjs/presentation-common/rules/hierarchy/SubCondition.d.ts +35 -35
- package/lib/cjs/presentation-common/rules/hierarchy/SubCondition.js +9 -9
- package/lib/cjs/presentation-common/selection/SelectionScope.d.ts +38 -38
- package/lib/cjs/presentation-common/selection/SelectionScope.d.ts.map +1 -1
- package/lib/cjs/presentation-common/selection/SelectionScope.js +9 -9
- package/lib/cjs/presentation-common.d.ts +113 -112
- package/lib/cjs/presentation-common.d.ts.map +1 -1
- package/lib/cjs/presentation-common.js +133 -128
- package/lib/cjs/presentation-common.js.map +1 -1
- package/lib/esm/presentation-common/AsyncTasks.d.ts +22 -22
- package/lib/esm/presentation-common/AsyncTasks.js +34 -34
- package/lib/esm/presentation-common/CommonLoggerCategory.d.ts +12 -12
- package/lib/esm/presentation-common/CommonLoggerCategory.js +17 -17
- package/lib/esm/presentation-common/Diagnostics.d.ts +125 -125
- package/lib/esm/presentation-common/Diagnostics.d.ts.map +1 -1
- package/lib/esm/presentation-common/Diagnostics.js +67 -67
- package/lib/esm/presentation-common/EC.d.ts +347 -350
- package/lib/esm/presentation-common/EC.d.ts.map +1 -1
- package/lib/esm/presentation-common/EC.js +287 -287
- package/lib/esm/presentation-common/EC.js.map +1 -1
- package/lib/esm/presentation-common/ElementProperties.d.ts +123 -123
- package/lib/esm/presentation-common/ElementProperties.d.ts.map +1 -1
- package/lib/esm/presentation-common/ElementProperties.js +8 -8
- package/lib/esm/presentation-common/Error.d.ts +47 -45
- package/lib/esm/presentation-common/Error.d.ts.map +1 -1
- package/lib/esm/presentation-common/Error.js +60 -58
- package/lib/esm/presentation-common/Error.js.map +1 -1
- package/lib/esm/presentation-common/InstanceFilterDefinition.d.ts +93 -93
- package/lib/esm/presentation-common/InstanceFilterDefinition.d.ts.map +1 -1
- package/lib/esm/presentation-common/InstanceFilterDefinition.js +8 -8
- package/lib/esm/presentation-common/KeySet.d.ts +146 -146
- package/lib/esm/presentation-common/KeySet.d.ts.map +1 -1
- package/lib/esm/presentation-common/KeySet.js +424 -424
- package/lib/esm/presentation-common/LabelDefinition.d.ts +93 -87
- package/lib/esm/presentation-common/LabelDefinition.d.ts.map +1 -1
- package/lib/esm/presentation-common/LabelDefinition.js +75 -70
- package/lib/esm/presentation-common/LabelDefinition.js.map +1 -1
- package/lib/esm/presentation-common/LocalizationHelper.d.ts +29 -29
- package/lib/esm/presentation-common/LocalizationHelper.js +106 -106
- package/lib/esm/presentation-common/PresentationIpcInterface.d.ts +40 -40
- package/lib/esm/presentation-common/PresentationIpcInterface.js +9 -9
- package/lib/esm/presentation-common/PresentationManagerOptions.d.ts +273 -261
- package/lib/esm/presentation-common/PresentationManagerOptions.d.ts.map +1 -1
- package/lib/esm/presentation-common/PresentationManagerOptions.js +18 -18
- package/lib/esm/presentation-common/PresentationManagerOptions.js.map +1 -1
- package/lib/esm/presentation-common/PresentationRpcInterface.d.ts +186 -186
- package/lib/esm/presentation-common/PresentationRpcInterface.d.ts.map +1 -1
- package/lib/esm/presentation-common/PresentationRpcInterface.js +105 -100
- package/lib/esm/presentation-common/PresentationRpcInterface.js.map +1 -1
- package/lib/esm/presentation-common/PropertyFormatter.d.ts +31 -0
- package/lib/esm/presentation-common/PropertyFormatter.d.ts.map +1 -0
- package/lib/esm/presentation-common/PropertyFormatter.js +194 -0
- package/lib/esm/presentation-common/PropertyFormatter.js.map +1 -0
- package/lib/esm/presentation-common/RegisteredRuleset.d.ts +26 -26
- package/lib/esm/presentation-common/RegisteredRuleset.js +29 -29
- package/lib/esm/presentation-common/RpcRequestsHandler.d.ts +82 -83
- package/lib/esm/presentation-common/RpcRequestsHandler.d.ts.map +1 -1
- package/lib/esm/presentation-common/RpcRequestsHandler.js +162 -167
- package/lib/esm/presentation-common/RpcRequestsHandler.js.map +1 -1
- package/lib/esm/presentation-common/RulesetVariables.d.ts +171 -171
- package/lib/esm/presentation-common/RulesetVariables.d.ts.map +1 -1
- package/lib/esm/presentation-common/RulesetVariables.js +52 -52
- package/lib/esm/presentation-common/RulesetsFactory.d.ts +44 -44
- package/lib/esm/presentation-common/RulesetsFactory.d.ts.map +1 -1
- package/lib/esm/presentation-common/RulesetsFactory.js +219 -219
- package/lib/esm/presentation-common/RulesetsFactory.js.map +1 -1
- package/lib/esm/presentation-common/Update.d.ts +213 -213
- package/lib/esm/presentation-common/Update.d.ts.map +1 -1
- package/lib/esm/presentation-common/Update.js +223 -223
- package/lib/esm/presentation-common/Utils.d.ts +62 -62
- package/lib/esm/presentation-common/Utils.d.ts.map +1 -1
- package/lib/esm/presentation-common/Utils.js +39 -39
- package/lib/esm/presentation-common/content/Category.d.ts +49 -49
- package/lib/esm/presentation-common/content/Category.js +45 -45
- package/lib/esm/presentation-common/content/Content.d.ts +38 -38
- package/lib/esm/presentation-common/content/Content.js +52 -52
- package/lib/esm/presentation-common/content/ContentTraverser.d.ts +271 -271
- package/lib/esm/presentation-common/content/ContentTraverser.js +427 -429
- package/lib/esm/presentation-common/content/ContentTraverser.js.map +1 -1
- package/lib/esm/presentation-common/content/Descriptor.d.ts +328 -328
- package/lib/esm/presentation-common/content/Descriptor.js +187 -189
- package/lib/esm/presentation-common/content/Descriptor.js.map +1 -1
- package/lib/esm/presentation-common/content/DisplayTypes.d.ts +21 -21
- package/lib/esm/presentation-common/content/DisplayTypes.js +26 -26
- package/lib/esm/presentation-common/content/Editor.d.ts +15 -15
- package/lib/esm/presentation-common/content/Editor.js +8 -8
- package/lib/esm/presentation-common/content/Fields.d.ts +298 -301
- package/lib/esm/presentation-common/content/Fields.d.ts.map +1 -1
- package/lib/esm/presentation-common/content/Fields.js +386 -390
- package/lib/esm/presentation-common/content/Fields.js.map +1 -1
- package/lib/esm/presentation-common/content/Item.d.ts +85 -85
- package/lib/esm/presentation-common/content/Item.d.ts.map +1 -1
- package/lib/esm/presentation-common/content/Item.js +80 -80
- package/lib/esm/presentation-common/content/Item.js.map +1 -1
- package/lib/esm/presentation-common/content/Property.d.ts +57 -57
- package/lib/esm/presentation-common/content/Property.d.ts.map +1 -1
- package/lib/esm/presentation-common/content/Property.js +37 -37
- package/lib/esm/presentation-common/content/Renderer.d.ts +11 -11
- package/lib/esm/presentation-common/content/Renderer.js +8 -8
- package/lib/esm/presentation-common/content/TypeDescription.d.ts +72 -72
- package/lib/esm/presentation-common/content/TypeDescription.d.ts.map +1 -1
- package/lib/esm/presentation-common/content/TypeDescription.js +20 -20
- package/lib/esm/presentation-common/content/Value.d.ts +189 -189
- package/lib/esm/presentation-common/content/Value.d.ts.map +1 -1
- package/lib/esm/presentation-common/content/Value.js +270 -270
- package/lib/esm/presentation-common/hierarchy/HierarchyLevel.d.ts +37 -37
- package/lib/esm/presentation-common/hierarchy/HierarchyLevel.js +28 -28
- package/lib/esm/presentation-common/hierarchy/Key.d.ts +246 -246
- package/lib/esm/presentation-common/hierarchy/Key.d.ts.map +1 -1
- package/lib/esm/presentation-common/hierarchy/Key.js +118 -118
- package/lib/esm/presentation-common/hierarchy/Key.js.map +1 -1
- package/lib/esm/presentation-common/hierarchy/Node.d.ts +154 -154
- package/lib/esm/presentation-common/hierarchy/Node.d.ts.map +1 -1
- package/lib/esm/presentation-common/hierarchy/Node.js +103 -103
- package/lib/esm/presentation-common/hierarchy/Node.js.map +1 -1
- package/lib/esm/presentation-common/hierarchy/NodePathElement.d.ts +96 -96
- package/lib/esm/presentation-common/hierarchy/NodePathElement.js +119 -119
- package/lib/esm/presentation-common/rules/ClassSpecifications.d.ts +45 -45
- package/lib/esm/presentation-common/rules/ClassSpecifications.js +8 -8
- package/lib/esm/presentation-common/rules/RelatedInstanceSpecification.d.ts +31 -31
- package/lib/esm/presentation-common/rules/RelatedInstanceSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/RelationshipDirection.d.ts +13 -13
- package/lib/esm/presentation-common/rules/RelationshipDirection.js +18 -18
- package/lib/esm/presentation-common/rules/RelationshipPathSpecification.d.ts +56 -56
- package/lib/esm/presentation-common/rules/RelationshipPathSpecification.d.ts.map +1 -1
- package/lib/esm/presentation-common/rules/RelationshipPathSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/Rule.d.ts +76 -76
- package/lib/esm/presentation-common/rules/Rule.js +32 -32
- package/lib/esm/presentation-common/rules/Ruleset.d.ts +65 -65
- package/lib/esm/presentation-common/rules/Ruleset.js +8 -8
- package/lib/esm/presentation-common/rules/SchemasSpecification.d.ts +41 -41
- package/lib/esm/presentation-common/rules/SchemasSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/Variables.d.ts +58 -58
- package/lib/esm/presentation-common/rules/Variables.js +22 -22
- package/lib/esm/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.d.ts +41 -41
- package/lib/esm/presentation-common/rules/content/ContentInstancesOfSpecificClassesSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/ContentRelatedInstancesSpecification.d.ts +25 -25
- package/lib/esm/presentation-common/rules/content/ContentRelatedInstancesSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/ContentRule.d.ts +30 -30
- package/lib/esm/presentation-common/rules/content/ContentRule.js +8 -8
- package/lib/esm/presentation-common/rules/content/ContentSpecification.d.ts +58 -58
- package/lib/esm/presentation-common/rules/content/ContentSpecification.js +17 -17
- package/lib/esm/presentation-common/rules/content/DefaultPropertyCategoryOverride.d.ts +19 -19
- package/lib/esm/presentation-common/rules/content/DefaultPropertyCategoryOverride.js +8 -8
- package/lib/esm/presentation-common/rules/content/PropertySpecification.d.ts +86 -86
- package/lib/esm/presentation-common/rules/content/PropertySpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/SelectedNodeInstancesSpecification.d.ts +28 -28
- package/lib/esm/presentation-common/rules/content/SelectedNodeInstancesSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.d.ts +25 -25
- package/lib/esm/presentation-common/rules/content/modifiers/CalculatedPropertiesSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/modifiers/ContentModifier.d.ts +57 -57
- package/lib/esm/presentation-common/rules/content/modifiers/ContentModifier.js +8 -8
- package/lib/esm/presentation-common/rules/content/modifiers/CustomRendererSpecification.d.ts +17 -17
- package/lib/esm/presentation-common/rules/content/modifiers/CustomRendererSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.d.ts +107 -107
- package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.d.ts.map +1 -1
- package/lib/esm/presentation-common/rules/content/modifiers/PropertyCategorySpecification.js +8 -8
- package/lib/esm/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.d.ts +108 -108
- package/lib/esm/presentation-common/rules/content/modifiers/PropertyEditorsSpecification.js +18 -18
- package/lib/esm/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.d.ts +96 -96
- package/lib/esm/presentation-common/rules/content/modifiers/RelatedPropertiesSpecification.js +40 -40
- package/lib/esm/presentation-common/rules/customization/CheckBoxRule.d.ts +44 -44
- package/lib/esm/presentation-common/rules/customization/CheckBoxRule.js +8 -8
- package/lib/esm/presentation-common/rules/customization/CustomizationRule.d.ts +36 -36
- package/lib/esm/presentation-common/rules/customization/CustomizationRule.js +8 -8
- package/lib/esm/presentation-common/rules/customization/ExtendedDataRule.d.ts +27 -27
- package/lib/esm/presentation-common/rules/customization/ExtendedDataRule.js +8 -8
- package/lib/esm/presentation-common/rules/customization/GroupingRule.d.ts +207 -207
- package/lib/esm/presentation-common/rules/customization/GroupingRule.js +48 -48
- package/lib/esm/presentation-common/rules/customization/ImageIdOverride.d.ts +29 -29
- package/lib/esm/presentation-common/rules/customization/ImageIdOverride.js +8 -8
- package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.d.ts +158 -158
- package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.d.ts.map +1 -1
- package/lib/esm/presentation-common/rules/customization/InstanceLabelOverride.js +22 -22
- package/lib/esm/presentation-common/rules/customization/LabelOverride.d.ts +40 -40
- package/lib/esm/presentation-common/rules/customization/LabelOverride.js +8 -8
- package/lib/esm/presentation-common/rules/customization/SortingRule.d.ts +58 -58
- package/lib/esm/presentation-common/rules/customization/SortingRule.d.ts.map +1 -1
- package/lib/esm/presentation-common/rules/customization/SortingRule.js +8 -8
- package/lib/esm/presentation-common/rules/customization/StyleOverride.d.ts +48 -48
- package/lib/esm/presentation-common/rules/customization/StyleOverride.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/ChildNodeRule.d.ts +14 -14
- package/lib/esm/presentation-common/rules/hierarchy/ChildNodeRule.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.d.ts +98 -98
- package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.d.ts.map +1 -1
- package/lib/esm/presentation-common/rules/hierarchy/ChildNodeSpecification.js +18 -18
- package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.d.ts +31 -31
- package/lib/esm/presentation-common/rules/hierarchy/CustomNodeSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.d.ts +79 -79
- package/lib/esm/presentation-common/rules/hierarchy/CustomQueryInstanceNodesSpecification.js +16 -16
- package/lib/esm/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.d.ts +39 -39
- package/lib/esm/presentation-common/rules/hierarchy/InstanceNodesOfSpecificClassesSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.d.ts +50 -50
- package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.d.ts.map +1 -1
- package/lib/esm/presentation-common/rules/hierarchy/NavigationRule.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/NodeArtifactsRule.d.ts +27 -27
- package/lib/esm/presentation-common/rules/hierarchy/NodeArtifactsRule.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.d.ts +27 -27
- package/lib/esm/presentation-common/rules/hierarchy/RelatedInstanceNodesSpecification.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/RootNodeRule.d.ts +16 -16
- package/lib/esm/presentation-common/rules/hierarchy/RootNodeRule.js +8 -8
- package/lib/esm/presentation-common/rules/hierarchy/SubCondition.d.ts +35 -35
- package/lib/esm/presentation-common/rules/hierarchy/SubCondition.js +8 -8
- package/lib/esm/presentation-common/selection/SelectionScope.d.ts +38 -38
- package/lib/esm/presentation-common/selection/SelectionScope.d.ts.map +1 -1
- package/lib/esm/presentation-common/selection/SelectionScope.js +8 -8
- package/lib/esm/presentation-common.d.ts +113 -112
- package/lib/esm/presentation-common.d.ts.map +1 -1
- package/lib/esm/presentation-common.js +117 -116
- package/lib/esm/presentation-common.js.map +1 -1
- package/lib/public/locales/en/Presentation.json +15 -0
- package/package.json +17 -15
- package/lib/cjs/assets/locales/en/BisCore.json +0 -18
- package/lib/cjs/assets/locales/en/ECPresentation.json +0 -9
- package/lib/cjs/assets/locales/en/RulesEngine.json +0 -6
- package/lib/cjs/assets/locales/en-PSEUDO/BisCore.json +0 -18
- package/lib/cjs/assets/locales/en-PSEUDO/ECPresentation.json +0 -9
- package/lib/cjs/assets/locales/en-PSEUDO/RulesEngine.json +0 -6
- package/lib/public/locales/en/BisCore.json +0 -18
- package/lib/public/locales/en/ECPresentation.json +0 -9
- package/lib/public/locales/en/RulesEngine.json +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RulesetsFactory.d.ts","sourceRoot":"","sources":["../../../src/presentation-common/RulesetsFactory.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,KAAK,EAAmB,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EAAa,WAAW,EAAoB,MAAM,MAAM,CAAC;AAMhE,OAAO,EAAE,OAAO,EAAE,M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MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -1,220 +1,220 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Core
|
|
7
|
-
*/
|
|
8
|
-
import { Guid, Id64 } from "@itwin/core-bentley";
|
|
9
|
-
import { PropertyValueFormat } from "./content/TypeDescription";
|
|
10
|
-
import { Value } from "./content/Value";
|
|
11
|
-
import { RelationshipPath } from "./EC";
|
|
12
|
-
import { ContentSpecificationTypes } from "./rules/content/ContentSpecification";
|
|
13
|
-
import { RelationshipDirection } from "./rules/RelationshipDirection";
|
|
14
|
-
import { RuleTypes } from "./rules/Rule";
|
|
15
|
-
/**
|
|
16
|
-
* A factory class that can be used to create presentation rulesets targeted towards
|
|
17
|
-
* specific use cases.
|
|
18
|
-
*
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
export class RulesetsFactory {
|
|
22
|
-
createSimilarInstancesRulesetInfo(field, record) {
|
|
23
|
-
if (!field.isPropertiesField())
|
|
24
|
-
throw new Error("Can only create 'similar instances' ruleset for properties-based records");
|
|
25
|
-
if (field.type.valueFormat !== PropertyValueFormat.Primitive)
|
|
26
|
-
throw new Error("Can only create 'similar instances' ruleset for primitive properties");
|
|
27
|
-
if (field.properties.length === 0)
|
|
28
|
-
throw new Error("Invalid properties' field with no properties");
|
|
29
|
-
if (record.isFieldMerged(field.name))
|
|
30
|
-
throw new Error("Can't create 'similar instances' ruleset for merged values");
|
|
31
|
-
if (!record.classInfo)
|
|
32
|
-
throw new Error("Can't create 'similar instances' for records based on multiple different ECClass instances");
|
|
33
|
-
const propertyName = getPropertyName(field);
|
|
34
|
-
const propertyValue = getPropertyValue(record, field);
|
|
35
|
-
const relatedInstanceInfo = createRelatedInstanceSpecInfo(field);
|
|
36
|
-
const relatedClass = relatedInstanceInfo
|
|
37
|
-
const ruleset = {
|
|
38
|
-
id: `SimilarInstances/${propertyName}/${Guid.createValue()}`,
|
|
39
|
-
rules: [],
|
|
40
|
-
};
|
|
41
|
-
ruleset.rules.push({
|
|
42
|
-
ruleType: RuleTypes.Content,
|
|
43
|
-
specifications: [{
|
|
44
|
-
specType: ContentSpecificationTypes.ContentInstancesOfSpecificClasses,
|
|
45
|
-
classes: createMultiClassSpecification(record.classInfo),
|
|
46
|
-
handleInstancesPolymorphically: true,
|
|
47
|
-
relatedInstances: relatedInstanceInfo ? [relatedInstanceInfo.spec] : [],
|
|
48
|
-
instanceFilter: createInstanceFilter(relatedInstanceInfo
|
|
49
|
-
}],
|
|
50
|
-
});
|
|
51
|
-
return { ruleset, relatedClass, propertyName, propertyValue };
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a ruleset with content rules for getting instances are of the
|
|
55
|
-
* same ECClass and have the same property value as the provided `record`.
|
|
56
|
-
* @param field A field identifying which property of the record we should use
|
|
57
|
-
* @param record A record whose similar instances should be found
|
|
58
|
-
* @param computeDisplayValue Optional callback function to calculate display value that's
|
|
59
|
-
* used in ruleset's description. If not provided, display value from record is used instead.
|
|
60
|
-
*/
|
|
61
|
-
async createSimilarInstancesRuleset(field, record, computeDisplayValue) {
|
|
62
|
-
const info = this.createSimilarInstancesRulesetInfo(field, record);
|
|
63
|
-
const description = await createDescriptionAsync(record, info.relatedClass, field, info.propertyValue, computeDisplayValue);
|
|
64
|
-
return { ruleset: info.ruleset, description };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const toString = (displayValue) => {
|
|
68
|
-
if (!displayValue)
|
|
69
|
-
return "NULL";
|
|
70
|
-
return displayValue.toString();
|
|
71
|
-
};
|
|
72
|
-
const createDescription = (record, relatedClass, field, value) => {
|
|
73
|
-
const classInfo = relatedClass
|
|
74
|
-
return `[${classInfo.label}].[${field.label}] = ${value}`;
|
|
75
|
-
};
|
|
76
|
-
const createDescriptionAsync = async (record, relatedClass, field, value, computeDisplayValue) => {
|
|
77
|
-
const displayValue = computeDisplayValue ? await computeDisplayValue(field.type.typeName, value.raw, value.display) : toString(value.display);
|
|
78
|
-
return createDescription(record, relatedClass, field, displayValue);
|
|
79
|
-
};
|
|
80
|
-
const getPropertyName = (field) => {
|
|
81
|
-
let name = field.properties[0].property.name;
|
|
82
|
-
if (field.type.typeName === "navigation")
|
|
83
|
-
name += ".Id";
|
|
84
|
-
return name;
|
|
85
|
-
};
|
|
86
|
-
const isPrimitivePropertyValue = (value) => {
|
|
87
|
-
if (Value.isPrimitive(value)) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
if (Value.isMap(value)) {
|
|
91
|
-
if (typeof value.x === "number"
|
|
92
|
-
&& typeof value.y === "number"
|
|
93
|
-
&& (value.z === undefined || typeof value.z === "number")) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
if (typeof value.className === "string" && typeof value.id === "string") {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
};
|
|
102
|
-
const getPropertyValue = (record, field) => {
|
|
103
|
-
const fieldNamesStack = [];
|
|
104
|
-
let currField = field;
|
|
105
|
-
while (currField) {
|
|
106
|
-
fieldNamesStack.push(currField.name);
|
|
107
|
-
currField = currField.parent;
|
|
108
|
-
}
|
|
109
|
-
let currFieldName = fieldNamesStack.pop();
|
|
110
|
-
let displayValue = record.displayValues[currFieldName];
|
|
111
|
-
let value = record.values[currFieldName];
|
|
112
|
-
currFieldName = fieldNamesStack.pop();
|
|
113
|
-
while (currFieldName) {
|
|
114
|
-
if (!Value.isNestedContent(value) || value.length === 0)
|
|
115
|
-
throw new Error("Invalid record value");
|
|
116
|
-
if (value.length > 1)
|
|
117
|
-
throw new Error("Can't create 'similar instances' for records related through many part of *-to-many relationship");
|
|
118
|
-
if (value[0].mergedFieldNames.indexOf(currFieldName) !== -1)
|
|
119
|
-
throw new Error("Can't create 'similar instances' ruleset for merged values");
|
|
120
|
-
displayValue = value[0].displayValues[currFieldName];
|
|
121
|
-
value = value[0].values[currFieldName];
|
|
122
|
-
currFieldName = fieldNamesStack.pop();
|
|
123
|
-
}
|
|
124
|
-
if (!isPrimitivePropertyValue(value))
|
|
125
|
-
throw new Error("Can only create 'similar instances' ruleset for primitive values");
|
|
126
|
-
return { raw: value, display: toString(displayValue) };
|
|
127
|
-
};
|
|
128
|
-
const createInstanceFilter = (relatedInstanceSpec, propertyType, propertyName, propertyValue) => {
|
|
129
|
-
const alias = relatedInstanceSpec ? relatedInstanceSpec.alias : "this";
|
|
130
|
-
return createComparison(propertyType, `${alias}.${propertyName}`, "=", propertyValue);
|
|
131
|
-
};
|
|
132
|
-
const createComparison = (type, name, operator, value) => {
|
|
133
|
-
let compareValue = "";
|
|
134
|
-
switch (typeof value) {
|
|
135
|
-
case "undefined":
|
|
136
|
-
compareValue = "NULL";
|
|
137
|
-
break;
|
|
138
|
-
case "string":
|
|
139
|
-
compareValue = `"${value.replace(/"/g, `""`)}"`;
|
|
140
|
-
break;
|
|
141
|
-
case "boolean":
|
|
142
|
-
compareValue = value ? "TRUE" : "FALSE";
|
|
143
|
-
break;
|
|
144
|
-
case "number":
|
|
145
|
-
compareValue = value.toString();
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
if (type.typeName === "navigation" && typeof value === "object" && Id64.isId64(value.id))
|
|
149
|
-
// note: this is temporary until we support hex ids in instance filters
|
|
150
|
-
compareValue = hexToDec(value.id);
|
|
151
|
-
if (type.typeName === "point2d" || type.typeName === "point3d") {
|
|
152
|
-
if (typeof value !== "object")
|
|
153
|
-
throw new Error("Expecting point values to be supplied as objects");
|
|
154
|
-
const dimensionType = {
|
|
155
|
-
valueFormat: PropertyValueFormat.Primitive,
|
|
156
|
-
typeName: "double",
|
|
157
|
-
};
|
|
158
|
-
const pointValue = value;
|
|
159
|
-
let comparison = `${createComparison(dimensionType, `${name}.x`, operator, pointValue.x)}`;
|
|
160
|
-
comparison += ` AND ${createComparison(dimensionType, `${name}.y`, operator, pointValue.y)}`;
|
|
161
|
-
if (type.typeName === "point3d" && pointValue.z !== undefined)
|
|
162
|
-
comparison += ` AND ${createComparison(dimensionType, `${name}.z`, operator, pointValue.z)}`;
|
|
163
|
-
return comparison;
|
|
164
|
-
}
|
|
165
|
-
if (type.typeName === "double")
|
|
166
|
-
return `CompareDoubles(${name}, ${compareValue}) ${operator} 0`;
|
|
167
|
-
if (type.typeName === "dateTime")
|
|
168
|
-
return `CompareDateTimes(${name}, ${compareValue}) ${operator} 0`;
|
|
169
|
-
return `${name} ${operator} ${compareValue}`;
|
|
170
|
-
};
|
|
171
|
-
const createMultiClassSpecification = (classInfo) => {
|
|
172
|
-
const [schemaName, className] = classInfo.name.split(":");
|
|
173
|
-
return { schemaName, classNames: [className] };
|
|
174
|
-
};
|
|
175
|
-
const createSingleClassSpecification = (classInfo) => {
|
|
176
|
-
const [schemaName, className] = classInfo.name.split(":");
|
|
177
|
-
return { schemaName, className };
|
|
178
|
-
};
|
|
179
|
-
const createRelatedInstanceSpec = (pathFromSelectToPropertyClass, index) => ({
|
|
180
|
-
spec: {
|
|
181
|
-
relationshipPath: pathFromSelectToPropertyClass.map((step) => ({
|
|
182
|
-
relationship: createSingleClassSpecification(step.relationshipInfo),
|
|
183
|
-
direction: step.isForwardRelationship ? RelationshipDirection.Forward : RelationshipDirection.Backward,
|
|
184
|
-
targetClass: createSingleClassSpecification(step.targetClassInfo),
|
|
185
|
-
})),
|
|
186
|
-
isRequired: true,
|
|
187
|
-
alias: `related_${index}`,
|
|
188
|
-
},
|
|
189
|
-
class: pathFromSelectToPropertyClass[pathFromSelectToPropertyClass.length - 1].targetClassInfo,
|
|
190
|
-
});
|
|
191
|
-
const createPathFromSelectToPropertyClass = (field) => {
|
|
192
|
-
let currField = field;
|
|
193
|
-
const pathFromPropertyToSelectClass = [];
|
|
194
|
-
while (currField.parent) {
|
|
195
|
-
pathFromPropertyToSelectClass.push(...currField.parent.pathToPrimaryClass);
|
|
196
|
-
currField = currField.parent;
|
|
197
|
-
}
|
|
198
|
-
return RelationshipPath.reverse(pathFromPropertyToSelectClass);
|
|
199
|
-
};
|
|
200
|
-
const createRelatedInstanceSpecInfo = (field) => {
|
|
201
|
-
const path = createPathFromSelectToPropertyClass(field);
|
|
202
|
-
return path.length ? createRelatedInstanceSpec(path, 0) : undefined;
|
|
203
|
-
};
|
|
204
|
-
const hexToDec = (id) => {
|
|
205
|
-
const digits = [0];
|
|
206
|
-
for (let i = 2; i < id.length; ++i) {
|
|
207
|
-
let carry = parseInt(id.charAt(i), 16);
|
|
208
|
-
for (let j = 0; j < digits.length; ++j) {
|
|
209
|
-
digits[j] = digits[j] * 16 + carry;
|
|
210
|
-
carry = digits[j] / 10 | 0;
|
|
211
|
-
digits[j] %= 10;
|
|
212
|
-
}
|
|
213
|
-
while (carry > 0) {
|
|
214
|
-
digits.push(carry % 10);
|
|
215
|
-
carry = carry / 10 | 0;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return digits.reverse().join("");
|
|
219
|
-
};
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Core
|
|
7
|
+
*/
|
|
8
|
+
import { Guid, Id64 } from "@itwin/core-bentley";
|
|
9
|
+
import { PropertyValueFormat } from "./content/TypeDescription";
|
|
10
|
+
import { Value } from "./content/Value";
|
|
11
|
+
import { RelationshipPath } from "./EC";
|
|
12
|
+
import { ContentSpecificationTypes } from "./rules/content/ContentSpecification";
|
|
13
|
+
import { RelationshipDirection } from "./rules/RelationshipDirection";
|
|
14
|
+
import { RuleTypes } from "./rules/Rule";
|
|
15
|
+
/**
|
|
16
|
+
* A factory class that can be used to create presentation rulesets targeted towards
|
|
17
|
+
* specific use cases.
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export class RulesetsFactory {
|
|
22
|
+
createSimilarInstancesRulesetInfo(field, record) {
|
|
23
|
+
if (!field.isPropertiesField())
|
|
24
|
+
throw new Error("Can only create 'similar instances' ruleset for properties-based records");
|
|
25
|
+
if (field.type.valueFormat !== PropertyValueFormat.Primitive)
|
|
26
|
+
throw new Error("Can only create 'similar instances' ruleset for primitive properties");
|
|
27
|
+
if (field.properties.length === 0)
|
|
28
|
+
throw new Error("Invalid properties' field with no properties");
|
|
29
|
+
if (record.isFieldMerged(field.name))
|
|
30
|
+
throw new Error("Can't create 'similar instances' ruleset for merged values");
|
|
31
|
+
if (!record.classInfo)
|
|
32
|
+
throw new Error("Can't create 'similar instances' for records based on multiple different ECClass instances");
|
|
33
|
+
const propertyName = getPropertyName(field);
|
|
34
|
+
const propertyValue = getPropertyValue(record, field);
|
|
35
|
+
const relatedInstanceInfo = createRelatedInstanceSpecInfo(field);
|
|
36
|
+
const relatedClass = relatedInstanceInfo?.class;
|
|
37
|
+
const ruleset = {
|
|
38
|
+
id: `SimilarInstances/${propertyName}/${Guid.createValue()}`,
|
|
39
|
+
rules: [],
|
|
40
|
+
};
|
|
41
|
+
ruleset.rules.push({
|
|
42
|
+
ruleType: RuleTypes.Content,
|
|
43
|
+
specifications: [{
|
|
44
|
+
specType: ContentSpecificationTypes.ContentInstancesOfSpecificClasses,
|
|
45
|
+
classes: createMultiClassSpecification(record.classInfo),
|
|
46
|
+
handleInstancesPolymorphically: true,
|
|
47
|
+
relatedInstances: relatedInstanceInfo ? [relatedInstanceInfo.spec] : [],
|
|
48
|
+
instanceFilter: createInstanceFilter(relatedInstanceInfo?.spec, field.type, propertyName, propertyValue.raw),
|
|
49
|
+
}],
|
|
50
|
+
});
|
|
51
|
+
return { ruleset, relatedClass, propertyName, propertyValue };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a ruleset with content rules for getting instances are of the
|
|
55
|
+
* same ECClass and have the same property value as the provided `record`.
|
|
56
|
+
* @param field A field identifying which property of the record we should use
|
|
57
|
+
* @param record A record whose similar instances should be found
|
|
58
|
+
* @param computeDisplayValue Optional callback function to calculate display value that's
|
|
59
|
+
* used in ruleset's description. If not provided, display value from record is used instead.
|
|
60
|
+
*/
|
|
61
|
+
async createSimilarInstancesRuleset(field, record, computeDisplayValue) {
|
|
62
|
+
const info = this.createSimilarInstancesRulesetInfo(field, record);
|
|
63
|
+
const description = await createDescriptionAsync(record, info.relatedClass, field, info.propertyValue, computeDisplayValue);
|
|
64
|
+
return { ruleset: info.ruleset, description };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const toString = (displayValue) => {
|
|
68
|
+
if (!displayValue)
|
|
69
|
+
return "NULL";
|
|
70
|
+
return displayValue.toString();
|
|
71
|
+
};
|
|
72
|
+
const createDescription = (record, relatedClass, field, value) => {
|
|
73
|
+
const classInfo = relatedClass ?? record.classInfo;
|
|
74
|
+
return `[${classInfo.label}].[${field.label}] = ${value}`;
|
|
75
|
+
};
|
|
76
|
+
const createDescriptionAsync = async (record, relatedClass, field, value, computeDisplayValue) => {
|
|
77
|
+
const displayValue = computeDisplayValue ? await computeDisplayValue(field.type.typeName, value.raw, value.display) : toString(value.display);
|
|
78
|
+
return createDescription(record, relatedClass, field, displayValue);
|
|
79
|
+
};
|
|
80
|
+
const getPropertyName = (field) => {
|
|
81
|
+
let name = field.properties[0].property.name;
|
|
82
|
+
if (field.type.typeName === "navigation")
|
|
83
|
+
name += ".Id";
|
|
84
|
+
return name;
|
|
85
|
+
};
|
|
86
|
+
const isPrimitivePropertyValue = (value) => {
|
|
87
|
+
if (Value.isPrimitive(value)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (Value.isMap(value)) {
|
|
91
|
+
if (typeof value.x === "number"
|
|
92
|
+
&& typeof value.y === "number"
|
|
93
|
+
&& (value.z === undefined || typeof value.z === "number")) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (typeof value.className === "string" && typeof value.id === "string") {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
const getPropertyValue = (record, field) => {
|
|
103
|
+
const fieldNamesStack = [];
|
|
104
|
+
let currField = field;
|
|
105
|
+
while (currField) {
|
|
106
|
+
fieldNamesStack.push(currField.name);
|
|
107
|
+
currField = currField.parent;
|
|
108
|
+
}
|
|
109
|
+
let currFieldName = fieldNamesStack.pop();
|
|
110
|
+
let displayValue = record.displayValues[currFieldName];
|
|
111
|
+
let value = record.values[currFieldName];
|
|
112
|
+
currFieldName = fieldNamesStack.pop();
|
|
113
|
+
while (currFieldName) {
|
|
114
|
+
if (!Value.isNestedContent(value) || value.length === 0)
|
|
115
|
+
throw new Error("Invalid record value");
|
|
116
|
+
if (value.length > 1)
|
|
117
|
+
throw new Error("Can't create 'similar instances' for records related through many part of *-to-many relationship");
|
|
118
|
+
if (value[0].mergedFieldNames.indexOf(currFieldName) !== -1)
|
|
119
|
+
throw new Error("Can't create 'similar instances' ruleset for merged values");
|
|
120
|
+
displayValue = value[0].displayValues[currFieldName];
|
|
121
|
+
value = value[0].values[currFieldName];
|
|
122
|
+
currFieldName = fieldNamesStack.pop();
|
|
123
|
+
}
|
|
124
|
+
if (!isPrimitivePropertyValue(value))
|
|
125
|
+
throw new Error("Can only create 'similar instances' ruleset for primitive values");
|
|
126
|
+
return { raw: value, display: toString(displayValue) };
|
|
127
|
+
};
|
|
128
|
+
const createInstanceFilter = (relatedInstanceSpec, propertyType, propertyName, propertyValue) => {
|
|
129
|
+
const alias = relatedInstanceSpec ? relatedInstanceSpec.alias : "this";
|
|
130
|
+
return createComparison(propertyType, `${alias}.${propertyName}`, "=", propertyValue);
|
|
131
|
+
};
|
|
132
|
+
const createComparison = (type, name, operator, value) => {
|
|
133
|
+
let compareValue = "";
|
|
134
|
+
switch (typeof value) {
|
|
135
|
+
case "undefined":
|
|
136
|
+
compareValue = "NULL";
|
|
137
|
+
break;
|
|
138
|
+
case "string":
|
|
139
|
+
compareValue = `"${value.replace(/"/g, `""`)}"`;
|
|
140
|
+
break;
|
|
141
|
+
case "boolean":
|
|
142
|
+
compareValue = value ? "TRUE" : "FALSE";
|
|
143
|
+
break;
|
|
144
|
+
case "number":
|
|
145
|
+
compareValue = value.toString();
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
if (type.typeName === "navigation" && typeof value === "object" && Id64.isId64(value.id))
|
|
149
|
+
// note: this is temporary until we support hex ids in instance filters
|
|
150
|
+
compareValue = hexToDec(value.id);
|
|
151
|
+
if (type.typeName === "point2d" || type.typeName === "point3d") {
|
|
152
|
+
if (typeof value !== "object")
|
|
153
|
+
throw new Error("Expecting point values to be supplied as objects");
|
|
154
|
+
const dimensionType = {
|
|
155
|
+
valueFormat: PropertyValueFormat.Primitive,
|
|
156
|
+
typeName: "double",
|
|
157
|
+
};
|
|
158
|
+
const pointValue = value;
|
|
159
|
+
let comparison = `${createComparison(dimensionType, `${name}.x`, operator, pointValue.x)}`;
|
|
160
|
+
comparison += ` AND ${createComparison(dimensionType, `${name}.y`, operator, pointValue.y)}`;
|
|
161
|
+
if (type.typeName === "point3d" && pointValue.z !== undefined)
|
|
162
|
+
comparison += ` AND ${createComparison(dimensionType, `${name}.z`, operator, pointValue.z)}`;
|
|
163
|
+
return comparison;
|
|
164
|
+
}
|
|
165
|
+
if (type.typeName === "double")
|
|
166
|
+
return `CompareDoubles(${name}, ${compareValue}) ${operator} 0`;
|
|
167
|
+
if (type.typeName === "dateTime")
|
|
168
|
+
return `CompareDateTimes(${name}, ${compareValue}) ${operator} 0`;
|
|
169
|
+
return `${name} ${operator} ${compareValue}`;
|
|
170
|
+
};
|
|
171
|
+
const createMultiClassSpecification = (classInfo) => {
|
|
172
|
+
const [schemaName, className] = classInfo.name.split(":");
|
|
173
|
+
return { schemaName, classNames: [className] };
|
|
174
|
+
};
|
|
175
|
+
const createSingleClassSpecification = (classInfo) => {
|
|
176
|
+
const [schemaName, className] = classInfo.name.split(":");
|
|
177
|
+
return { schemaName, className };
|
|
178
|
+
};
|
|
179
|
+
const createRelatedInstanceSpec = (pathFromSelectToPropertyClass, index) => ({
|
|
180
|
+
spec: {
|
|
181
|
+
relationshipPath: pathFromSelectToPropertyClass.map((step) => ({
|
|
182
|
+
relationship: createSingleClassSpecification(step.relationshipInfo),
|
|
183
|
+
direction: step.isForwardRelationship ? RelationshipDirection.Forward : RelationshipDirection.Backward,
|
|
184
|
+
targetClass: createSingleClassSpecification(step.targetClassInfo),
|
|
185
|
+
})),
|
|
186
|
+
isRequired: true,
|
|
187
|
+
alias: `related_${index}`,
|
|
188
|
+
},
|
|
189
|
+
class: pathFromSelectToPropertyClass[pathFromSelectToPropertyClass.length - 1].targetClassInfo,
|
|
190
|
+
});
|
|
191
|
+
const createPathFromSelectToPropertyClass = (field) => {
|
|
192
|
+
let currField = field;
|
|
193
|
+
const pathFromPropertyToSelectClass = [];
|
|
194
|
+
while (currField.parent) {
|
|
195
|
+
pathFromPropertyToSelectClass.push(...currField.parent.pathToPrimaryClass);
|
|
196
|
+
currField = currField.parent;
|
|
197
|
+
}
|
|
198
|
+
return RelationshipPath.reverse(pathFromPropertyToSelectClass);
|
|
199
|
+
};
|
|
200
|
+
const createRelatedInstanceSpecInfo = (field) => {
|
|
201
|
+
const path = createPathFromSelectToPropertyClass(field);
|
|
202
|
+
return path.length ? createRelatedInstanceSpec(path, 0) : undefined;
|
|
203
|
+
};
|
|
204
|
+
const hexToDec = (id) => {
|
|
205
|
+
const digits = [0];
|
|
206
|
+
for (let i = 2; i < id.length; ++i) {
|
|
207
|
+
let carry = parseInt(id.charAt(i), 16);
|
|
208
|
+
for (let j = 0; j < digits.length; ++j) {
|
|
209
|
+
digits[j] = digits[j] * 16 + carry;
|
|
210
|
+
carry = digits[j] / 10 | 0;
|
|
211
|
+
digits[j] %= 10;
|
|
212
|
+
}
|
|
213
|
+
while (carry > 0) {
|
|
214
|
+
digits.push(carry % 10);
|
|
215
|
+
carry = carry / 10 | 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return digits.reverse().join("");
|
|
219
|
+
};
|
|
220
220
|
//# 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,OAAO,EAAE,IAAI,EAAE,IAAI,EAAc,MAAM,qBAAqB,CAAC;AAG7D,OAAO,EAA4B,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAgB,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAA0B,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAEhE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC;;;;;GAKG;AACH,MAAM,OAAO,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,mBAAmB,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,8CA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C,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QAClC,IAAI,KAAK,GAAG,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,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":["/*---------------------------------------------------------------------------------------------\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"]}
|
|
1
|
+
{"version":3,"file":"RulesetsFactory.js","sourceRoot":"","sources":["../../../src/presentation-common/RulesetsFactory.ts"],"names":[],"mappings":"AAAA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I,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"]}
|