packageDocumentation module import { assert } from "@itwin/core-bentley" ; import { InstanceKey , InstanceKeyJSON } from "../EC" ; public export enum StandardNodeTypes { ECInstancesNode = "ECInstancesNode" , ECClassGroupingNode = "ECClassGroupingNode" , ECPropertyGroupingNode = "ECPropertyGroupingNode" , DisplayLabelGroupingNode = "DisplayLabelGroupingNode" } public export type NodeKey = BaseNodeKey | ECInstancesNodeKey | ECClassGroupingNodeKey | ECPropertyGroupingNodeKey | LabelGroupingNodeKey ; public export namespace NodeKey { /** Serialize given [[NodeKey]] to JSON */ export function toJSON ( key ) { if ( isInstancesNodeKey ( key ) ) return { ... key , instanceKeys : key . instanceKeys . map ( InstanceKey . toJSON ) } ; return { ... key } ; } /** Deserialize node key from JSON */ export function fromJSON ( json ) { if ( isInstancesNodeKey ( json ) ) return { version : 1 , ... json , instanceKeys : json . instanceKeys . map ( InstanceKey . fromJSON ) } ; return { version : 1 , ... json } ; } /** Checks if the supplied key is an [[ECInstancesNodeKey]] */ export function isInstancesNodeKey ( key ) ; /** Checks if the supplied key is an [[ECInstancesNodeKey]] */ export function isInstancesNodeKey ( key ) ; export function isInstancesNodeKey ( key ) { return key . type === StandardNodeTypes . ECInstancesNode ; } /** Checks if the supplied key is an [[ECClassGroupingNodeKey]] */ export function isClassGroupingNodeKey ( key ) ; /** Checks if the supplied key is an [[ECClassGroupingNodeKey]] */ export function isClassGroupingNodeKey ( key ) ; export function isClassGroupingNodeKey ( key ) { return key . type === StandardNodeTypes . ECClassGroupingNode ; } /** Checks if the supplied key is an [[ECPropertyGroupingNodeKey]] */ export function isPropertyGroupingNodeKey ( key ) ; /** Checks if the supplied key is an [[ECPropertyGroupingNodeKey]] */ export function isPropertyGroupingNodeKey ( key ) ; export function isPropertyGroupingNodeKey ( key ) { return key . type === StandardNodeTypes . ECPropertyGroupingNode ; } /** Checks if the supplied key is a [[LabelGroupingNodeKey]] */ export function isLabelGroupingNodeKey ( key ) ; /** Checks if the supplied key is a [[LabelGroupingNodeKey]] */ export function isLabelGroupingNodeKey ( key ) ; export function isLabelGroupingNodeKey ( key ) { return key . type === StandardNodeTypes . DisplayLabelGroupingNode ; } /** Checks if the supplied key is a grouping node key */ export function isGroupingNodeKey ( key ) ; /** Checks if the supplied key is a grouping node key */ export function isGroupingNodeKey ( key ) ; export function isGroupingNodeKey ( key ) { return isClassGroupingNodeKey ( key ) || isPropertyGroupingNodeKey ( key ) || isLabelGroupingNodeKey ( key ) ; } /**
     * Checks if two given node keys are equal, taking their versions into account.
     *
     * When comparing two keys of the same version, the algorithm uses [[NodeKey.pathFromRoot]] array
     * which is the most accurate way of checking equality. However, when version are different,
     * [[NodeKey.pathFromRoot]] array may contain different strings even though keys represent the same node.
     * In that case equality is checked using other key attributes, depending on the type of the node (type,
     * label, grouping class, property name, etc.).
     */ export function equals ( lhs , rhs ) { if ( lhs . type !== rhs . type ) return false ; if ( lhs . pathFromRoot . length !== rhs . pathFromRoot . length ) return false ; if ( lhs . version === rhs . version ) { for ( let i = 0 ; i < lhs . pathFromRoot . length ; ++ i ) { if ( lhs . pathFromRoot [ i ] !== rhs . pathFromRoot [ i ] ) return false ; } return true ; } if ( isInstancesNodeKey ( lhs ) ) { assert ( isInstancesNodeKey ( rhs ) ) ; if ( lhs . instanceKeys . length !== rhs . instanceKeys . length ) return false ; for ( let i = 0 ; i < lhs . instanceKeys . length ; ++ i ) { if ( 0 !== InstanceKey . compare ( lhs . instanceKeys [ i ] , rhs . instanceKeys [ i ] ) ) return false ; } return true ; } if ( isClassGroupingNodeKey ( lhs ) ) { assert ( isClassGroupingNodeKey ( rhs ) ) ; return lhs . className === rhs . className ; } if ( isPropertyGroupingNodeKey ( lhs ) ) { assert ( isPropertyGroupingNodeKey ( rhs ) ) ; return lhs . className === rhs . className && lhs . propertyName === rhs . propertyName ; } if ( isLabelGroupingNodeKey ( lhs ) ) { assert ( isLabelGroupingNodeKey ( rhs ) ) ; return lhs . label === rhs . label ; } return true ; } } public export type NodeKeyPath = NodeKey [ ] ; public export interface BaseNodeKey { /** Node type */ type : string ; /**
     * Version of the key. Different versions suggest that node keys were created by two different
     * versions of the library. In that case, keys representing the same node may be different.
     */ version : number ; /** Node hash path from root to the node whose key this is */ pathFromRoot : string [ ] ; } public export interface BaseNodeKeyJSON { type : string ; version ? : number ; pathFromRoot : string [ ] ; } public export interface ECInstancesNodeKey extends BaseNodeKey { type : StandardNodeTypes . ECInstancesNode ; /** List of [[InstanceKey]] objects of ECInstances represented by the node */ instanceKeys : InstanceKey [ ] ; } public export interface ECInstancesNodeKeyJSON extends BaseNodeKeyJSON { type : StandardNodeTypes . ECInstancesNode ; instanceKeys : InstanceKeyJSON [ ] ; } public export interface GroupingNodeKey extends BaseNodeKey { /**
     * Get the number of instances grouped by the node represented
     * by this key.
     *
     * **Note:** this property is just a helper and is not involved
     * in identifying a node.
     */ groupedInstancesCount : number ; } public export interface GroupingNodeKeyJSON extends BaseNodeKeyJSON { groupedInstancesCount : number ; } public export interface ECClassGroupingNodeKey extends GroupingNodeKey { type : StandardNodeTypes . ECClassGroupingNode ; /** Full name of the grouping ECClass */ className : string ; } public export interface ECClassGroupingNodeKeyJSON extends GroupingNodeKeyJSON { type : StandardNodeTypes . ECClassGroupingNode ; className : string ; } public export interface ECPropertyGroupingNodeKey extends GroupingNodeKey { type : StandardNodeTypes . ECPropertyGroupingNode ; /** Full name of the grouping ECProperty class */ className : string ; /** Name of the ECProperty */ propertyName : string ; /** Raw grouping values */ groupingValues : any [ ] ; } public export interface ECPropertyGroupingNodeKeyJSON extends GroupingNodeKeyJSON { type : StandardNodeTypes . ECPropertyGroupingNode ; className : string ; propertyName : string ; groupingValues : any [ ] ; } public export interface LabelGroupingNodeKey extends GroupingNodeKey { type : StandardNodeTypes . DisplayLabelGroupingNode ; /** Grouping display label */ label : string ; } public export interface LabelGroupingNodeKeyJSON extends GroupingNodeKeyJSON { type : StandardNodeTypes . DisplayLabelGroupingNode ; label : string ; } public export type NodeKeyJSON = BaseNodeKeyJSON | ECInstancesNodeKeyJSON | ECClassGroupingNodeKeyJSON | ECPropertyGroupingNodeKeyJSON | LabelGroupingNodeKeyJSON ;