@itwin/presentation-hierarchies 0.7.0 → 0.7.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"Grouping.js","sourceRoot":"","sources":["../../../../../src/hierarchies/imodel/operators/Grouping.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AA8BhG,wDAiEC;AAmGD,wDAqCC;AArOD,+BAAiJ;AACjJ,sDAAwD;AAExD,uDAAyE;AACzE,kDAK+B;AAC/B,8DAAyD;AACzD,kFAA2F;AAC3F,8DAA2D;AAE3D,sDAAyD;AACzD,oEAA+E;AAC/E,4DAA6D;AAC7D,wDAAgE;AAChE,4DAA6D;AAC7D,sEAAqH;AAErH,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,gBAAgB;AACH,QAAA,iBAAiB,GAAG,IAAA,uCAA8B,EAAC,aAAa,CAAC,CAAC;AAC/E,MAAM,6BAA6B,GAAG,IAAA,uCAA8B,EAAC,aAAa,EAAE,sCAAkC,CAAC,CAAC;AACxH,MAAM,sCAAsC,GAAG,IAAA,uCAA8B,EAAC,aAAa,EAAE,+CAA2C,CAAC,CAAC;AAE1I,gBAAgB;AAChB,SAAgB,sBAAsB,CACpC,YAA0D,EAC1D,UAA2C,EAC3C,cAAwC,EACxC,gBAAoD,EACpD,qBAA8E,EAC9E,gBAAoC;IAEpC,OAAO,UAAU,KAAyC;QACxD,OAAO,KAAK,CAAC,IAAI,CACf,IAAA,kBAAG,EAAC,EAAE,QAAQ,EAAE,yBAAiB,EAAE,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,IAAA,uCAA8B,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAC3H,IAAA,iBAAO,EAAC,GAAG,EAAE;YACX,IAAA,oBAAK,EAAC;gBACJ,QAAQ,EAAE,6BAA6B;gBACvC,OAAO,EAAE,0BAA0B,CAAC,GAAG,EAAE,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AAI,CAAC,EAAE,CAAC;QACpD,OAAO,aAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;IACD,OAAO,aAAa,CAAC,IAAI,CAAC;AAC5B,CAAC;AAED,IAAK,aAKJ;AALD,WAAK,aAAa;IAChB,iDAAQ,CAAA;IACR,mDAAS,CAAA;IACT,yDAAY,CAAA;IACZ,mDAAS,CAAA;AACX,CAAC,EALI,aAAa,KAAb,aAAa,QAKjB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { concat, concatAll, delay, EMPTY, expand, finalize, from, last, map, merge, mergeMap, Observable, of, reduce, tap, toArray } from \"rxjs\";\nimport { assert, StopWatch } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, ECSchemaProvider, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { HierarchyNode, ParentHierarchyNode } from \"../../HierarchyNode\";\nimport {\n LOGGING_NAMESPACE_PERFORMANCE as BASE_LOGGING_NAMESPACE_PERFORMANCE,\n LOGGING_NAMESPACE_PERFORMANCE_INTERNAL as BASE_LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n createNodeIdentifierForLogging,\n createOperatorLoggingNamespace,\n} from \"../../internal/Common\";\nimport { doLog, log } from \"../../internal/LoggingUtils\";\nimport { releaseMainThreadOnItemsCount } from \"../../internal/operators/ReleaseMainThread\";\nimport { tapOnce } from \"../../internal/operators/TapOnce\";\nimport { ProcessedGroupingHierarchyNode, ProcessedHierarchyNode, ProcessedInstanceHierarchyNode } from \"../IModelHierarchyNode\";\nimport { assignAutoExpand } from \"./grouping/AutoExpand\";\nimport { createBaseClassGroupingHandlers } from \"./grouping/BaseClassGrouping\";\nimport { createClassGroups } from \"./grouping/ClassGrouping\";\nimport { applyGroupHidingParams } from \"./grouping/GroupHiding\";\nimport { createLabelGroups } from \"./grouping/LabelGrouping\";\nimport { createPropertiesGroupingHandlers, PropertiesGroupingLocalizedStrings } from \"./grouping/PropertiesGrouping\";\n\nconst OPERATOR_NAME = \"Grouping\";\n/** @internal */\nexport const LOGGING_NAMESPACE = createOperatorLoggingNamespace(OPERATOR_NAME);\nconst LOGGING_NAMESPACE_PERFORMANCE = createOperatorLoggingNamespace(OPERATOR_NAME, BASE_LOGGING_NAMESPACE_PERFORMANCE);\nconst LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = createOperatorLoggingNamespace(OPERATOR_NAME, BASE_LOGGING_NAMESPACE_PERFORMANCE_INTERNAL);\n\n/** @internal */\nexport function createGroupingOperator(\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector,\n parentNode: ParentHierarchyNode | undefined,\n valueFormatter: IPrimitiveValueFormatter,\n localizedStrings: PropertiesGroupingLocalizedStrings,\n onGroupingNodeCreated?: (groupingNode: ProcessedGroupingHierarchyNode) => void,\n groupingHandlers?: GroupingHandler[],\n) {\n return function (nodes: Observable<ProcessedHierarchyNode>): Observable<ProcessedHierarchyNode> {\n return nodes.pipe(\n log({ category: LOGGING_NAMESPACE, message: /* istanbul ignore next */ (n) => `in: ${createNodeIdentifierForLogging(n)}` }),\n tapOnce(() => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE,\n message: /* istanbul ignore next */ () => `Starting grouping (parent: ${createNodeIdentifierForLogging(parentNode)})`,\n });\n }),\n reduce<ProcessedHierarchyNode, { instanceNodes: ProcessedInstanceHierarchyNode[]; restNodes: ProcessedHierarchyNode[] }>(\n (resolvedNodes, node) => {\n if (HierarchyNode.isInstancesNode(node)) {\n resolvedNodes.instanceNodes.push(node);\n } else {\n resolvedNodes.restNodes.push(node);\n }\n return resolvedNodes;\n },\n { instanceNodes: [], restNodes: [] },\n ),\n tap(({ instanceNodes, restNodes }) => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Nodes partitioned. Got ${instanceNodes.length} instance nodes and ${restNodes.length} rest nodes.`,\n });\n }),\n mergeMap((res) => {\n const out = of(res);\n const totalNodes = res.instanceNodes.length + res.restNodes.length;\n // istanbul ignore next\n return totalNodes <= 1000 ? out : out.pipe(delay(0));\n }),\n mergeMap(({ instanceNodes, restNodes }): Observable<ProcessedHierarchyNode> => {\n const timer = new StopWatch(undefined, true);\n const groupingHandlersObs: Observable<GroupingHandler> = groupingHandlers\n ? from(groupingHandlers)\n : createGroupingHandlers(imodelAccess, parentNode, instanceNodes, valueFormatter, localizedStrings);\n return merge(\n groupingHandlersObs.pipe(\n toArray(),\n mergeMap((createdGroupingHandlers) =>\n groupInstanceNodes(instanceNodes, restNodes.length, createdGroupingHandlers, parentNode, onGroupingNodeCreated),\n ),\n finalize(() => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE,\n message: /* istanbul ignore next */ () => `Grouping ${instanceNodes.length} nodes took ${timer.elapsedSeconds.toFixed(3)} s`,\n });\n }),\n ),\n from(restNodes),\n );\n }),\n releaseMainThreadOnItemsCount(500),\n log({ category: LOGGING_NAMESPACE, message: /* istanbul ignore next */ (n) => `out: ${createNodeIdentifierForLogging(n)}` }),\n );\n };\n}\n\n/** @internal */\nexport type ProcessedInstancesGroupingHierarchyNode = Omit<ProcessedGroupingHierarchyNode, \"children\"> & { children: ProcessedInstanceHierarchyNode[] };\n\n/** @internal */\nexport interface GroupingHandlerResult {\n /** Expected to be sorted by label. */\n grouped: Array<ProcessedInstancesGroupingHierarchyNode>;\n /** Expected to be sorted by label. */\n ungrouped: ProcessedInstanceHierarchyNode[];\n groupingType: GroupingType;\n}\n\n/** @internal */\nexport type GroupingType = \"label\" | \"class\" | \"base-class\" | \"property\";\n\n/** @internal */\nexport type GroupingHandler = (\n nodesToGroup: ProcessedInstanceHierarchyNode[],\n nodesAlreadyGrouped: ProcessedInstancesGroupingHierarchyNode[],\n) => Promise<GroupingHandlerResult>;\n\nfunction groupInstanceNodes(\n nodes: ProcessedInstanceHierarchyNode[],\n extraSiblings: number,\n groupingHandlers: GroupingHandler[],\n parentNode: ParentHierarchyNode | undefined,\n onGroupingNodeCreated?: (groupingNode: ProcessedGroupingHierarchyNode) => void,\n): Observable<ProcessedGroupingHierarchyNode | ProcessedInstanceHierarchyNode> {\n if (groupingHandlers.length === 0) {\n return from(nodes);\n }\n return of<{ handlerIndex: number; result?: GroupingHandlerResult | undefined }>({ handlerIndex: 0 }).pipe(\n expand(({ handlerIndex, result: curr }) => {\n if (handlerIndex >= groupingHandlers.length) {\n return EMPTY;\n }\n const timer = new StopWatch(undefined, true);\n const currentHandler = groupingHandlers[handlerIndex];\n return from(currentHandler(curr?.ungrouped ?? nodes, curr?.grouped ?? [])).pipe(\n log({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Grouping handler ${handlerIndex} exclusively took ${timer.elapsedSeconds.toFixed(3)} s.`,\n }),\n mergeMap((result) => {\n if (result.grouped.length === 0) {\n return of({ handlerIndex: handlerIndex + 1, result: { ...result, grouped: curr?.grouped ?? [] } });\n }\n const groupingPostProcessingTimer = new StopWatch(undefined, true);\n return of(result).pipe(\n map((r) => applyGroupHidingParams(r, extraSiblings)),\n map((r) => assignAutoExpand(r)),\n map((r) => ({ handlerIndex: handlerIndex + 1, result: { ...r, grouped: mergeInPlace(curr?.grouped, r.grouped) } })),\n log({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () =>\n `Post-processing grouping handler ${handlerIndex} exclusively took ${groupingPostProcessingTimer.elapsedSeconds.toFixed(3)} s.`,\n }),\n delay(0),\n );\n }),\n log({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Total time for grouping handler ${handlerIndex}: ${timer.elapsedSeconds.toFixed(3)} s.`,\n }),\n );\n }),\n last(),\n mergeMap(({ result }) => {\n result.grouped.forEach((groupingNode) => {\n onGroupingNodeCreated?.(groupingNode);\n if (!parentNode) {\n return;\n }\n if (HierarchyNode.isGroupingNode(parentNode)) {\n groupingNode.nonGroupingAncestor = parentNode.nonGroupingAncestor;\n return;\n }\n // not sure why type checker doesn't pick this up\n assert(HierarchyNode.isGeneric(parentNode) || HierarchyNode.isInstancesNode(parentNode));\n groupingNode.nonGroupingAncestor = parentNode;\n });\n return mergeInPlace<ProcessedGroupingHierarchyNode | ProcessedInstanceHierarchyNode>(result.grouped, result.ungrouped);\n }),\n );\n}\n\nfunction mergeInPlace<T>(target: T[] | undefined, source: T[]) {\n if (!target || target.length === 0) {\n return source;\n }\n for (const item of source) {\n target.push(item);\n }\n return target;\n}\n\n/** @internal */\nexport function createGroupingHandlers(\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector,\n parentNode: ParentHierarchyNode | undefined,\n processedInstanceNodes: ProcessedInstanceHierarchyNode[],\n valueFormatter: IPrimitiveValueFormatter,\n localizedStrings: PropertiesGroupingLocalizedStrings,\n): Observable<GroupingHandler> {\n const timer = new StopWatch();\n const groupingLevel = getNodeGroupingLevel(parentNode);\n return concat(\n groupingLevel <= GroupingLevel.Class\n ? concat(\n from(createBaseClassGroupingHandlers(imodelAccess, parentNode, processedInstanceNodes)).pipe(concatAll()),\n of<GroupingHandler>(async (allNodes) => createClassGroups(imodelAccess, parentNode, allNodes)),\n )\n : EMPTY,\n groupingLevel <= GroupingLevel.Property\n ? from(createPropertiesGroupingHandlers(imodelAccess, parentNode, processedInstanceNodes, valueFormatter, localizedStrings)).pipe(concatAll())\n : EMPTY,\n groupingLevel < GroupingLevel.Label ? of<GroupingHandler>(async (allNodes) => createLabelGroups(allNodes)) : EMPTY,\n ).pipe(\n tap({\n subscribe: () => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Start creating grouping handlers`,\n });\n timer.start();\n },\n }),\n finalize(() => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Creating grouping handlers took ${timer.elapsedSeconds.toFixed(3)} s`,\n });\n }),\n );\n}\n\nfunction getNodeGroupingLevel(node: ParentHierarchyNode | undefined): GroupingLevel {\n if (node && HierarchyNode.isClassGroupingNode(node)) {\n return GroupingLevel.Class;\n }\n if (node && HierarchyNode.isPropertyGroupingNode(node)) {\n return GroupingLevel.Property;\n }\n if (node && HierarchyNode.isLabelGroupingNode(node)) {\n return GroupingLevel.Label;\n }\n return GroupingLevel.None;\n}\n\nenum GroupingLevel {\n None = 0,\n Class = 2,\n Property = 3,\n Label = 4,\n}\n"]}
1
+ {"version":3,"file":"Grouping.js","sourceRoot":"","sources":["../../../../../src/hierarchies/imodel/operators/Grouping.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AA+BhG,wDAiEC;AAmGD,wDAqCC;AAtOD,+BAAiJ;AACjJ,sDAAwD;AAExD,uDAAyE;AACzE,kDAM+B;AAC/B,8DAAyD;AACzD,kFAA2F;AAC3F,8DAA2D;AAE3D,sDAAyD;AACzD,oEAA+E;AAC/E,4DAA6D;AAC7D,wDAAgE;AAChE,4DAA6D;AAC7D,sEAAqH;AAErH,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,gBAAgB;AACH,QAAA,iBAAiB,GAAG,IAAA,uCAA8B,EAAC,aAAa,EAAE,mCAA0B,CAAC,CAAC;AAC3G,MAAM,6BAA6B,GAAG,IAAA,uCAA8B,EAAC,aAAa,EAAE,sCAAkC,CAAC,CAAC;AACxH,MAAM,sCAAsC,GAAG,IAAA,uCAA8B,EAAC,aAAa,EAAE,+CAA2C,CAAC,CAAC;AAE1I,gBAAgB;AAChB,SAAgB,sBAAsB,CACpC,YAA0D,EAC1D,UAA2C,EAC3C,cAAwC,EACxC,gBAAoD,EACpD,qBAA8E,EAC9E,gBAAoC;IAEpC,OAAO,UAAU,KAAyC;QACxD,OAAO,KAAK,CAAC,IAAI,CACf,IAAA,kBAAG,EAAC,EAAE,QAAQ,EAAE,yBAAiB,EAAE,OAAO,EAAE,0B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AAE,CAAC;QACpD,OAAO,aAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;IACD,IAAI,IAAI,IAAI,6BAAa,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,CAAC;QACvD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IACD,IAAI,IAAI,IAAI,6BAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QACpD,OAAO,aAAa,CAAC,KAAK,CAAC;IAC7B,CAAC;IACD,OAAO,aAAa,CAAC,IAAI,CAAC;AAC5B,CAAC;AAED,IAAK,aAKJ;AALD,WAAK,aAAa;IAChB,iDAAQ,CAAA;IACR,mDAAS,CAAA;IACT,yDAAY,CAAA;IACZ,mDAAS,CAAA;AACX,CAAC,EALI,aAAa,KAAb,aAAa,QAKjB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { concat, concatAll, delay, EMPTY, expand, finalize, from, last, map, merge, mergeMap, Observable, of, reduce, tap, toArray } from \"rxjs\";\nimport { assert, StopWatch } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, ECSchemaProvider, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { HierarchyNode, ParentHierarchyNode } from \"../../HierarchyNode\";\nimport {\n LOGGING_NAMESPACE_PERFORMANCE as BASE_LOGGING_NAMESPACE_PERFORMANCE,\n LOGGING_NAMESPACE_PERFORMANCE_INTERNAL as BASE_LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n createNodeIdentifierForLogging,\n createOperatorLoggingNamespace,\n LOGGING_NAMESPACE_INTERNAL,\n} from \"../../internal/Common\";\nimport { doLog, log } from \"../../internal/LoggingUtils\";\nimport { releaseMainThreadOnItemsCount } from \"../../internal/operators/ReleaseMainThread\";\nimport { tapOnce } from \"../../internal/operators/TapOnce\";\nimport { ProcessedGroupingHierarchyNode, ProcessedHierarchyNode, ProcessedInstanceHierarchyNode } from \"../IModelHierarchyNode\";\nimport { assignAutoExpand } from \"./grouping/AutoExpand\";\nimport { createBaseClassGroupingHandlers } from \"./grouping/BaseClassGrouping\";\nimport { createClassGroups } from \"./grouping/ClassGrouping\";\nimport { applyGroupHidingParams } from \"./grouping/GroupHiding\";\nimport { createLabelGroups } from \"./grouping/LabelGrouping\";\nimport { createPropertiesGroupingHandlers, PropertiesGroupingLocalizedStrings } from \"./grouping/PropertiesGrouping\";\n\nconst OPERATOR_NAME = \"Grouping\";\n/** @internal */\nexport const LOGGING_NAMESPACE = createOperatorLoggingNamespace(OPERATOR_NAME, LOGGING_NAMESPACE_INTERNAL);\nconst LOGGING_NAMESPACE_PERFORMANCE = createOperatorLoggingNamespace(OPERATOR_NAME, BASE_LOGGING_NAMESPACE_PERFORMANCE);\nconst LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = createOperatorLoggingNamespace(OPERATOR_NAME, BASE_LOGGING_NAMESPACE_PERFORMANCE_INTERNAL);\n\n/** @internal */\nexport function createGroupingOperator(\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector,\n parentNode: ParentHierarchyNode | undefined,\n valueFormatter: IPrimitiveValueFormatter,\n localizedStrings: PropertiesGroupingLocalizedStrings,\n onGroupingNodeCreated?: (groupingNode: ProcessedGroupingHierarchyNode) => void,\n groupingHandlers?: GroupingHandler[],\n) {\n return function (nodes: Observable<ProcessedHierarchyNode>): Observable<ProcessedHierarchyNode> {\n return nodes.pipe(\n log({ category: LOGGING_NAMESPACE, message: /* istanbul ignore next */ (n) => `in: ${createNodeIdentifierForLogging(n)}` }),\n tapOnce(() => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE,\n message: /* istanbul ignore next */ () => `Starting grouping (parent: ${createNodeIdentifierForLogging(parentNode)})`,\n });\n }),\n reduce<ProcessedHierarchyNode, { instanceNodes: ProcessedInstanceHierarchyNode[]; restNodes: ProcessedHierarchyNode[] }>(\n (resolvedNodes, node) => {\n if (HierarchyNode.isInstancesNode(node)) {\n resolvedNodes.instanceNodes.push(node);\n } else {\n resolvedNodes.restNodes.push(node);\n }\n return resolvedNodes;\n },\n { instanceNodes: [], restNodes: [] },\n ),\n tap(({ instanceNodes, restNodes }) => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Nodes partitioned. Got ${instanceNodes.length} instance nodes and ${restNodes.length} rest nodes.`,\n });\n }),\n mergeMap((res) => {\n const out = of(res);\n const totalNodes = res.instanceNodes.length + res.restNodes.length;\n // istanbul ignore next\n return totalNodes <= 1000 ? out : out.pipe(delay(0));\n }),\n mergeMap(({ instanceNodes, restNodes }): Observable<ProcessedHierarchyNode> => {\n const timer = new StopWatch(undefined, true);\n const groupingHandlersObs: Observable<GroupingHandler> = groupingHandlers\n ? from(groupingHandlers)\n : createGroupingHandlers(imodelAccess, parentNode, instanceNodes, valueFormatter, localizedStrings);\n return merge(\n groupingHandlersObs.pipe(\n toArray(),\n mergeMap((createdGroupingHandlers) =>\n groupInstanceNodes(instanceNodes, restNodes.length, createdGroupingHandlers, parentNode, onGroupingNodeCreated),\n ),\n finalize(() => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE,\n message: /* istanbul ignore next */ () => `Grouping ${instanceNodes.length} nodes took ${timer.elapsedSeconds.toFixed(3)} s`,\n });\n }),\n ),\n from(restNodes),\n );\n }),\n releaseMainThreadOnItemsCount(500),\n log({ category: LOGGING_NAMESPACE, message: /* istanbul ignore next */ (n) => `out: ${createNodeIdentifierForLogging(n)}` }),\n );\n };\n}\n\n/** @internal */\nexport type ProcessedInstancesGroupingHierarchyNode = Omit<ProcessedGroupingHierarchyNode, \"children\"> & { children: ProcessedInstanceHierarchyNode[] };\n\n/** @internal */\nexport interface GroupingHandlerResult {\n /** Expected to be sorted by label. */\n grouped: Array<ProcessedInstancesGroupingHierarchyNode>;\n /** Expected to be sorted by label. */\n ungrouped: ProcessedInstanceHierarchyNode[];\n groupingType: GroupingType;\n}\n\n/** @internal */\nexport type GroupingType = \"label\" | \"class\" | \"base-class\" | \"property\";\n\n/** @internal */\nexport type GroupingHandler = (\n nodesToGroup: ProcessedInstanceHierarchyNode[],\n nodesAlreadyGrouped: ProcessedInstancesGroupingHierarchyNode[],\n) => Promise<GroupingHandlerResult>;\n\nfunction groupInstanceNodes(\n nodes: ProcessedInstanceHierarchyNode[],\n extraSiblings: number,\n groupingHandlers: GroupingHandler[],\n parentNode: ParentHierarchyNode | undefined,\n onGroupingNodeCreated?: (groupingNode: ProcessedGroupingHierarchyNode) => void,\n): Observable<ProcessedGroupingHierarchyNode | ProcessedInstanceHierarchyNode> {\n if (groupingHandlers.length === 0) {\n return from(nodes);\n }\n return of<{ handlerIndex: number; result?: GroupingHandlerResult | undefined }>({ handlerIndex: 0 }).pipe(\n expand(({ handlerIndex, result: curr }) => {\n if (handlerIndex >= groupingHandlers.length) {\n return EMPTY;\n }\n const timer = new StopWatch(undefined, true);\n const currentHandler = groupingHandlers[handlerIndex];\n return from(currentHandler(curr?.ungrouped ?? nodes, curr?.grouped ?? [])).pipe(\n log({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Grouping handler ${handlerIndex} exclusively took ${timer.elapsedSeconds.toFixed(3)} s.`,\n }),\n mergeMap((result) => {\n if (result.grouped.length === 0) {\n return of({ handlerIndex: handlerIndex + 1, result: { ...result, grouped: curr?.grouped ?? [] } });\n }\n const groupingPostProcessingTimer = new StopWatch(undefined, true);\n return of(result).pipe(\n map((r) => applyGroupHidingParams(r, extraSiblings)),\n map((r) => assignAutoExpand(r)),\n map((r) => ({ handlerIndex: handlerIndex + 1, result: { ...r, grouped: mergeInPlace(curr?.grouped, r.grouped) } })),\n log({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () =>\n `Post-processing grouping handler ${handlerIndex} exclusively took ${groupingPostProcessingTimer.elapsedSeconds.toFixed(3)} s.`,\n }),\n delay(0),\n );\n }),\n log({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Total time for grouping handler ${handlerIndex}: ${timer.elapsedSeconds.toFixed(3)} s.`,\n }),\n );\n }),\n last(),\n mergeMap(({ result }) => {\n result.grouped.forEach((groupingNode) => {\n onGroupingNodeCreated?.(groupingNode);\n if (!parentNode) {\n return;\n }\n if (HierarchyNode.isGroupingNode(parentNode)) {\n groupingNode.nonGroupingAncestor = parentNode.nonGroupingAncestor;\n return;\n }\n // not sure why type checker doesn't pick this up\n assert(HierarchyNode.isGeneric(parentNode) || HierarchyNode.isInstancesNode(parentNode));\n groupingNode.nonGroupingAncestor = parentNode;\n });\n return mergeInPlace<ProcessedGroupingHierarchyNode | ProcessedInstanceHierarchyNode>(result.grouped, result.ungrouped);\n }),\n );\n}\n\nfunction mergeInPlace<T>(target: T[] | undefined, source: T[]) {\n if (!target || target.length === 0) {\n return source;\n }\n for (const item of source) {\n target.push(item);\n }\n return target;\n}\n\n/** @internal */\nexport function createGroupingHandlers(\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector,\n parentNode: ParentHierarchyNode | undefined,\n processedInstanceNodes: ProcessedInstanceHierarchyNode[],\n valueFormatter: IPrimitiveValueFormatter,\n localizedStrings: PropertiesGroupingLocalizedStrings,\n): Observable<GroupingHandler> {\n const timer = new StopWatch();\n const groupingLevel = getNodeGroupingLevel(parentNode);\n return concat(\n groupingLevel <= GroupingLevel.Class\n ? concat(\n from(createBaseClassGroupingHandlers(imodelAccess, parentNode, processedInstanceNodes)).pipe(concatAll()),\n of<GroupingHandler>(async (allNodes) => createClassGroups(imodelAccess, parentNode, allNodes)),\n )\n : EMPTY,\n groupingLevel <= GroupingLevel.Property\n ? from(createPropertiesGroupingHandlers(imodelAccess, parentNode, processedInstanceNodes, valueFormatter, localizedStrings)).pipe(concatAll())\n : EMPTY,\n groupingLevel < GroupingLevel.Label ? of<GroupingHandler>(async (allNodes) => createLabelGroups(allNodes)) : EMPTY,\n ).pipe(\n tap({\n subscribe: () => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Start creating grouping handlers`,\n });\n timer.start();\n },\n }),\n finalize(() => {\n doLog({\n category: LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n message: /* istanbul ignore next */ () => `Creating grouping handlers took ${timer.elapsedSeconds.toFixed(3)} s`,\n });\n }),\n );\n}\n\nfunction getNodeGroupingLevel(node: ParentHierarchyNode | undefined): GroupingLevel {\n if (node && HierarchyNode.isClassGroupingNode(node)) {\n return GroupingLevel.Class;\n }\n if (node && HierarchyNode.isPropertyGroupingNode(node)) {\n return GroupingLevel.Property;\n }\n if (node && HierarchyNode.isLabelGroupingNode(node)) {\n return GroupingLevel.Label;\n }\n return GroupingLevel.None;\n}\n\nenum GroupingLevel {\n None = 0,\n Class = 2,\n Property = 3,\n Label = 4,\n}\n"]}
@@ -23,7 +23,7 @@ export declare const LOGGING_NAMESPACE_INTERNAL = "Presentation.HierarchiesInter
23
23
  */
24
24
  export declare const LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = "Presentation.HierarchiesInternal.Performance";
25
25
  /** @internal */
26
- export declare function createOperatorLoggingNamespace(operatorName: string, baseCategory?: typeof LOGGING_NAMESPACE | typeof LOGGING_NAMESPACE_PERFORMANCE | typeof LOGGING_NAMESPACE_INTERNAL | typeof LOGGING_NAMESPACE_PERFORMANCE_INTERNAL): string;
26
+ export declare function createOperatorLoggingNamespace(operatorName: string, baseCategory: typeof LOGGING_NAMESPACE | typeof LOGGING_NAMESPACE_PERFORMANCE | typeof LOGGING_NAMESPACE_INTERNAL | typeof LOGGING_NAMESPACE_PERFORMANCE_INTERNAL): string;
27
27
  /** @internal */
28
28
  export declare function createNodeIdentifierForLogging(node: {
29
29
  label: string | ConcatenatedValue;
@@ -1 +1 @@
1
- {"version":3,"file":"Common.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/internal/Common.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6BAA6B,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,6BAA6B,yCAAqC,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,qCAAqC,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,iDAA8C,CAAC;AAElG,gBAAgB;AAChB,wBAAgB,8BAA8B,CAC5C,YAAY,EAAE,MAAM,EACpB,YAAY,GACR,OAAO,iBAAiB,GACxB,OAAO,6BAA6B,GACpC,OAAO,0BAA0B,GACjC,OAAO,sCAA0D,UAGtE;AAED,gBAAgB;AAEhB,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAAC;IAAC,GAAG,EAAE,gBAAgB,CAAC;IAAC,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAAE,GAAG,SAAS,UAQhH;AAED,gBAAgB;AAChB,wBAAgB,WAAW,CAAC,KAAK,SAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAA;CAAE,EAAE,IAAI,EAAE,KAAK,WAE7F;AAED,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,QAAQ,SAAS;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,SAAS;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAEhJ"}
1
+ {"version":3,"file":"Common.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/internal/Common.ts"],"names":[],"mappings":"AAMA,OA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  /** @internal */
39
- function createOperatorLoggingNamespace(operatorName, baseCategory = exports.LOGGING_NAMESPACE) {
39
+ function createOperatorLoggingNamespace(operatorName, baseCategory) {
40
40
  return `${baseCategory}.Operators.${operatorName}`;
41
41
  }
42
42
  /** @internal */
@@ -1 +1 @@
1
- {"version":3,"file":"Common.js","sourceRoot":"","sources":["../../../../src/hierarchies/internal/Common.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;AAiChG,wEASC;AAID,wEASC;AAGD,kCAEC;AAGD,kDAEC;AA/DD,gFAAkD;AAIlD;;;GAGG;AACU,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAE5D;;;GAGG;AACU,QAAA,6BAA6B,GAAG,GAAG,yBAAiB,cAAc,CAAC;AAEhF;;;;GAIG;AACU,QAAA,0BAA0B,GAAG,kCAAkC,CAAC;AAE7E;;;;GAIG;AACU,QAAA,sCAAsC,GAAG,GAAG,kCAA0B,cAAc,CAAC;AAElG,gBAAgB;AAChB,SAAgB,8BAA8B,CAC5C,YAAoB,EACpB,eAIoD,yBAAiB;IAErE,OAAO,GAAG,YAAY,cAAc,YAAY,EAAE,CAAC;AACrD,CAAC;AAED,gBAAgB;AAChB,uBAAuB;AACvB,SAAgB,8BAA8B,CAC5C,IAA+G;IAE/G,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,MAAM,UAAU,GAAG,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IACxE,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,gBAAgB;AAChB,SAAgB,WAAW,CAAwD,IAAW;IAC5F,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED,gBAAgB;AAChB,SAAgB,mBAAmB,CAAyE,GAAa,EAAE,GAAa;IACtI,OAAO,IAAA,8BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;AACtF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport naturalCompare from \"natural-compare-lite\";\nimport { ConcatenatedValue } from \"@itwin/presentation-shared\";\nimport { HierarchyNodeKey } from \"../HierarchyNodeKey\";\n\n/**\n * This is a logging namespace for public log messages that may be interesting to consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE = \"Presentation.Hierarchies\";\n\n/**\n * This is a logging namespace for public performance-related log messages that may be interesting to consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE_PERFORMANCE = `${LOGGING_NAMESPACE}.Performance`;\n\n/**\n * This is a logging namespace for internal log messages that are only interesting to package contributors,\n * but not the consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE_INTERNAL = \"Presentation.HierarchiesInternal\";\n\n/**\n * This is a logging namespace for internal performance-related log messages that are only interesting\n * to package contributors, but not the consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = `${LOGGING_NAMESPACE_INTERNAL}.Performance`;\n\n/** @internal */\nexport function createOperatorLoggingNamespace(\n operatorName: string,\n baseCategory:\n | typeof LOGGING_NAMESPACE\n | typeof LOGGING_NAMESPACE_PERFORMANCE\n | typeof LOGGING_NAMESPACE_INTERNAL\n | typeof LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = LOGGING_NAMESPACE,\n) {\n return `${baseCategory}.Operators.${operatorName}`;\n}\n\n/** @internal */\n// istanbul ignore next\nexport function createNodeIdentifierForLogging(\n node: { label: string | ConcatenatedValue; key: HierarchyNodeKey; parentKeys?: HierarchyNodeKey[] } | undefined,\n) {\n if (!node) {\n return \"<root>\";\n }\n const { label, key } = node;\n const parentKeys = \"parentKeys\" in node ? node.parentKeys : \"<unknown>\";\n return JSON.stringify({ label, key, parentKeys });\n}\n\n/** @internal */\nexport function hasChildren<TNode extends { children?: boolean | Array<unknown> }>(node: TNode) {\n return node.children === true || (Array.isArray(node.children) && node.children.length > 0);\n}\n\n/** @internal */\nexport function compareNodesByLabel<TLhsNode extends { label: string }, TRhsNode extends { label: string }>(lhs: TLhsNode, rhs: TRhsNode): number {\n return naturalCompare(lhs.label.toLocaleLowerCase(), rhs.label.toLocaleLowerCase());\n}\n"]}
1
+ {"version":3,"file":"Common.js","sourceRoot":"","sources":["../../../../src/hierarchies/internal/Common.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;AAiChG,wEASC;AAID,wEASC;AAGD,kCAEC;AAGD,kDAEC;AA/DD,gFAAkD;AAIlD;;;GAGG;AACU,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAE5D;;;GAGG;AACU,QAAA,6BAA6B,GAAG,GAAG,yBAAiB,cAAc,CAAC;AAEhF;;;;GAIG;AACU,QAAA,0BAA0B,GAAG,kCAAkC,CAAC;AAE7E;;;;GAIG;AACU,QAAA,sCAAsC,GAAG,GAAG,kCAA0B,cAAc,CAAC;AAElG,gBAAgB;AAChB,SAAgB,8BAA8B,CAC5C,YAAoB,EACpB,YAIiD;IAEjD,OAAO,GAAG,YAAY,cAAc,YAAY,EAAE,CAAC;AACrD,CAAC;AAED,gBAAgB;AAChB,uBAAuB;AACvB,SAAgB,8BAA8B,CAC5C,IAA+G;IAE/G,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC5B,MAAM,UAAU,GAAG,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;IACxE,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;AACpD,CAAC;AAED,gBAAgB;AAChB,SAAgB,WAAW,CAAwD,IAAW;IAC5F,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED,gBAAgB;AAChB,SAAgB,mBAAmB,CAAyE,GAAa,EAAE,GAAa;IACtI,OAAO,IAAA,8BAAc,EAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC;AACtF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport naturalCompare from \"natural-compare-lite\";\nimport { ConcatenatedValue } from \"@itwin/presentation-shared\";\nimport { HierarchyNodeKey } from \"../HierarchyNodeKey\";\n\n/**\n * This is a logging namespace for public log messages that may be interesting to consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE = \"Presentation.Hierarchies\";\n\n/**\n * This is a logging namespace for public performance-related log messages that may be interesting to consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE_PERFORMANCE = `${LOGGING_NAMESPACE}.Performance`;\n\n/**\n * This is a logging namespace for internal log messages that are only interesting to package contributors,\n * but not the consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE_INTERNAL = \"Presentation.HierarchiesInternal\";\n\n/**\n * This is a logging namespace for internal performance-related log messages that are only interesting\n * to package contributors, but not the consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE_PERFORMANCE_INTERNAL = `${LOGGING_NAMESPACE_INTERNAL}.Performance`;\n\n/** @internal */\nexport function createOperatorLoggingNamespace(\n operatorName: string,\n baseCategory:\n | typeof LOGGING_NAMESPACE\n | typeof LOGGING_NAMESPACE_PERFORMANCE\n | typeof LOGGING_NAMESPACE_INTERNAL\n | typeof LOGGING_NAMESPACE_PERFORMANCE_INTERNAL,\n) {\n return `${baseCategory}.Operators.${operatorName}`;\n}\n\n/** @internal */\n// istanbul ignore next\nexport function createNodeIdentifierForLogging(\n node: { label: string | ConcatenatedValue; key: HierarchyNodeKey; parentKeys?: HierarchyNodeKey[] } | undefined,\n) {\n if (!node) {\n return \"<root>\";\n }\n const { label, key } = node;\n const parentKeys = \"parentKeys\" in node ? node.parentKeys : \"<unknown>\";\n return JSON.stringify({ label, key, parentKeys });\n}\n\n/** @internal */\nexport function hasChildren<TNode extends { children?: boolean | Array<unknown> }>(node: TNode) {\n return node.children === true || (Array.isArray(node.children) && node.children.length > 0);\n}\n\n/** @internal */\nexport function compareNodesByLabel<TLhsNode extends { label: string }, TRhsNode extends { label: string }>(lhs: TLhsNode, rhs: TRhsNode): number {\n return naturalCompare(lhs.label.toLocaleLowerCase(), rhs.label.toLocaleLowerCase());\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IModelHierarchyProvider.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/IModelHierarchyProvider.ts"],"names":[],"mappings":"AAyBA,OAAO,EAGL,yBAAyB,EACzB,gBAAgB,EAGhB,KAAK,EAGL,wBAAwB,EAEzB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,EAA0B,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAiBjF,OAAO,EAA6B,mBAAmB,EAA4B,MAAM,6BAA6B,CAAC;AASvH,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAe1E;;;GAGG;AACH,UAAU,uCAAuC;IAC/C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,YAAY;AACZ,KAAK,YAAY,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,yBAAyB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtH;;;GAGG;AACH,UAAU,4BAA4B;IACpC;;;;;;OAMG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B,wFAAwF;IACxF,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAElC;;;OAGG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;IAEzC,qGAAqG;IACrG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAC,uCAAuC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,yCAAyC;IACzC,SAAS,CAAC,EAAE;QACV,2DAA2D;QAC3D,KAAK,EAAE,sBAAsB,EAAE,CAAC;KACjC,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,4BAA4B,GAAG,iBAAiB,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAE9H"}
1
+ {"version":3,"file":"IModelHierarchyProvider.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/IModelHierarchyProvider.ts"],"names":[],"mappings":"AA2BA,OAAO,EAGL,yBAAyB,EACzB,gBAAgB,EAGhB,KAAK,EAGL,wBAAwB,EAEzB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,EAA0B,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAiBjF,OAAO,EAA6B,mBAAmB,EAA4B,MAAM,6BAA6B,CAAC;AASvH,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAe1E;;;GAGG;AACH,UAAU,uCAAuC;IAC/C;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,YAAY;AACZ,KAAK,YAAY,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,yBAAyB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtH;;;GAGG;AACH,UAAU,4BAA4B;IACpC;;;;;;OAMG;IACH,YAAY,EAAE,YAAY,CAAC;IAE3B,wFAAwF;IACxF,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;IAElC;;;OAGG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;IAEzC,qGAAqG;IACrG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,OAAO,CAAC,uCAAuC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,yCAAyC;IACzC,SAAS,CAAC,EAAE;QACV,2DAA2D;QAC3D,KAAK,EAAE,sBAAsB,EAAE,CAAC;KACjC,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,4BAA4B,GAAG,iBAAiB,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAE9H"}
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { catchError, concat, defaultIfEmpty, defer, EMPTY, filter, finalize, from, map, merge, mergeAll, mergeMap, of, take, tap, } from "rxjs";
6
- import { assert, BeEvent, StopWatch } from "@itwin/core-bentley";
5
+ import { catchError, concat, defaultIfEmpty, defer, EMPTY, filter, finalize, from, map, merge, mergeAll, mergeMap, of, Subject, take, takeUntil, tap, } from "rxjs";
6
+ import { assert, BeEvent, Guid, StopWatch } from "@itwin/core-bentley";
7
7
  import { createDefaultValueFormatter, formatConcatenatedValue, normalizeFullClassName, } from "@itwin/presentation-shared";
8
8
  import { RowsLimitExceededError } from "../HierarchyErrors";
9
9
  import { HierarchyNode } from "../HierarchyNode";
@@ -49,6 +49,7 @@ class IModelHierarchyProviderImpl {
49
49
  _queryScheduler;
50
50
  _nodesCache;
51
51
  _unsubscribe;
52
+ _dispose = new Subject();
52
53
  constructor(props) {
53
54
  this._imodelAccess = props.imodelAccess;
54
55
  this._imodelChanged = props.imodelChanged ?? new BeEvent();
@@ -64,10 +65,14 @@ class IModelHierarchyProviderImpl {
64
65
  size: Math.ceil(queryCacheSize / 2),
65
66
  variationsCount: 1,
66
67
  });
67
- this._unsubscribe = props.imodelChanged?.addListener(() => this.invalidateHierarchyCache("Data source changed"));
68
+ this._unsubscribe = props.imodelChanged?.addListener(() => {
69
+ this.invalidateHierarchyCache("Data source changed");
70
+ this._dispose.next();
71
+ });
68
72
  }
69
73
  }
70
74
  dispose() {
75
+ this._dispose.next();
71
76
  this._unsubscribe?.();
72
77
  }
73
78
  get hierarchyChanged() {
@@ -101,14 +106,16 @@ class IModelHierarchyProviderImpl {
101
106
  nodeIdentifierPaths: props.paths,
102
107
  });
103
108
  this.invalidateHierarchyCache("Hierarchy filter set");
109
+ this._dispose.next();
104
110
  }
105
111
  onGroupingNodeCreated(groupingNode, props) {
106
112
  this._nodesCache?.set({ ...props, parentNode: groupingNode }, { observable: from(groupingNode.children), processingStatus: "pre-processed" });
107
113
  }
108
114
  createHierarchyLevelDefinitionsObservable(props) {
115
+ const { requestContext, ...defineHierarchyLevelProps } = props;
109
116
  doLog({
110
117
  category: LOGGING_NAMESPACE_PERFORMANCE,
111
- message: /* istanbul ignore next */ () => `Requesting hierarchy level definitions for ${createNodeIdentifierForLogging(props.parentNode)}`,
118
+ message: /* istanbul ignore next */ () => `[${requestContext.requestId}] Requesting hierarchy level definitions for ${createNodeIdentifierForLogging(props.parentNode)}`,
112
119
  });
113
120
  return from(defer(async () => {
114
121
  let parentNode = props.parentNode;
@@ -128,10 +135,10 @@ class IModelHierarchyProviderImpl {
128
135
  return [];
129
136
  }
130
137
  }
131
- return this._activeHierarchyDefinition.defineHierarchyLevel({ ...props, parentNode });
138
+ return this._activeHierarchyDefinition.defineHierarchyLevel({ ...defineHierarchyLevelProps, parentNode });
132
139
  })).pipe(mergeAll(), finalize(() => doLog({
133
140
  category: LOGGING_NAMESPACE_PERFORMANCE,
134
- message: /* istanbul ignore next */ () => `Received all hierarchy level definitions for ${createNodeIdentifierForLogging(props.parentNode)}`,
141
+ message: /* istanbul ignore next */ () => `[${requestContext.requestId}] Received all hierarchy level definitions for ${createNodeIdentifierForLogging(props.parentNode)}`,
135
142
  })));
136
143
  }
137
144
  createSourceNodesObservable(props) {
@@ -146,59 +153,61 @@ class IModelHierarchyProviderImpl {
146
153
  }))));
147
154
  }), finalize(() => doLog({
148
155
  category: LOGGING_NAMESPACE_PERFORMANCE,
149
- message: /* istanbul ignore next */ () => `Read all child nodes ${createNodeIdentifierForLogging(props.parentNode)}`,
156
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Read all child nodes ${createNodeIdentifierForLogging(props.parentNode)}`,
150
157
  })), shareReplayWithErrors());
151
158
  }
152
- createInitializedNodesObservable(nodes, parentNode) {
153
- return nodes.pipe(
159
+ createPreProcessedNodesObservable(queryNodesObservable, props) {
160
+ return queryNodesObservable.pipe(
154
161
  // we're going to be mutating the nodes, but don't want to mutate the original one, so just clone it here once
155
162
  map((node) => ({ ...node })),
156
163
  // set parent node keys on the source node
157
- map((node) => Object.assign(node, { parentKeys: createParentNodeKeysList(parentNode) })),
164
+ map((node) => Object.assign(node, { parentKeys: createParentNodeKeysList(props.parentNode) })),
158
165
  // format `ConcatenatedValue` labels into string labels
159
166
  mergeMap(async (node) => applyLabelsFormatting(node, this._valuesFormatter)),
160
167
  // we have `ProcessedHierarchyNode` from here
161
- preProcessNodes(this._activeHierarchyDefinition), finalize(() => doLog({
162
- category: LOGGING_NAMESPACE_PERFORMANCE,
163
- message: /* istanbul ignore next */ () => `Finished initializing child nodes for ${createNodeIdentifierForLogging(parentNode)}`,
164
- })), shareReplayWithErrors());
165
- }
166
- createPreProcessedNodesObservable(queryNodesObservable, props) {
167
- return this.createInitializedNodesObservable(queryNodesObservable, props.parentNode).pipe(createHideIfNoChildrenOperator((n) => this.getChildNodesObservables({ parentNode: n }).hasNodes), createHideNodesInHierarchyOperator(
168
+ preProcessNodes(this._activeHierarchyDefinition),
169
+ // process hiding
170
+ createHideIfNoChildrenOperator((n) => this.getChildNodesObservables({ parentNode: n, requestContext: props.requestContext }).hasNodes), createHideNodesInHierarchyOperator(
168
171
  // note: for child nodes created because of hidden parent, we want to use parent's request props (instance filter, limit)
169
172
  (n) => this.getChildNodesObservables({ ...props, parentNode: n }).processedNodes, false), finalize(() => doLog({
170
173
  category: LOGGING_NAMESPACE_PERFORMANCE,
171
- message: /* istanbul ignore next */ () => `Finished pre-processing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
174
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Finished pre-processing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
172
175
  })));
173
176
  }
174
177
  createProcessedNodesObservable(preprocessedNodesObservable, props) {
175
178
  return preprocessedNodesObservable.pipe(createGroupingOperator(this._imodelAccess, props.parentNode, this._valuesFormatter, this._localizedStrings, (gn) => this.onGroupingNodeCreated(gn, props)), finalize(() => doLog({
176
179
  category: LOGGING_NAMESPACE_PERFORMANCE,
177
- message: /* istanbul ignore next */ () => `Finished grouping child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
180
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Finished grouping child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
178
181
  })));
179
182
  }
180
183
  createFinalizedNodesObservable(processedNodesObservable, props) {
181
- return processedNodesObservable.pipe(createDetermineChildrenOperator((n) => this.getChildNodesObservables({ parentNode: n }).hasNodes), postProcessNodes(this._activeHierarchyDefinition), sortNodesByLabelOperator, map((n) => {
184
+ return processedNodesObservable.pipe(createDetermineChildrenOperator((n) => this.getChildNodesObservables({ parentNode: n, requestContext: props.requestContext }).hasNodes), postProcessNodes(this._activeHierarchyDefinition), sortNodesByLabelOperator, map((n) => {
182
185
  if ("processingParams" in n) {
183
186
  delete n.processingParams;
184
187
  }
185
188
  return Object.assign(n, {
186
189
  children: hasChildren(n),
187
190
  });
188
- }), finalize(() => doLog({
191
+ }), takeUntil(this._dispose), finalize(() => doLog({
189
192
  category: LOGGING_NAMESPACE_PERFORMANCE,
190
- message: /* istanbul ignore next */ () => `Finished finalizing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
193
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Finished finalizing child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
191
194
  })));
192
195
  }
193
- createHasNodesObservable(preprocessedNodesObservable, possiblyKnownChildrenObservable) {
196
+ createHasNodesObservable(preprocessedNodesObservable, possiblyKnownChildrenObservable, props) {
194
197
  const loggingCategory = `${LOGGING_NAMESPACE_INTERNAL}.HasNodes`;
195
- return concat((possiblyKnownChildrenObservable ?? EMPTY).pipe(filter((n) => hasChildren(n))), preprocessedNodesObservable).pipe(log({ category: loggingCategory, message: /* istanbul ignore next */ (n) => `Node before mapping to 'true': ${createNodeIdentifierForLogging(n)}` }), take(1), map(() => true), defaultIfEmpty(false), catchError((e) => {
196
- doLog({ category: loggingCategory, message: /* istanbul ignore next */ () => `Error while determining children: ${e.message}` });
198
+ return concat((possiblyKnownChildrenObservable ?? EMPTY).pipe(filter((n) => hasChildren(n))), preprocessedNodesObservable).pipe(log({
199
+ category: loggingCategory,
200
+ message: /* istanbul ignore next */ (n) => `[${props.requestContext.requestId}] Node before mapping to 'true': ${createNodeIdentifierForLogging(n)}`,
201
+ }), take(1), map(() => true), defaultIfEmpty(false), catchError((e) => {
202
+ doLog({
203
+ category: loggingCategory,
204
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Error while determining children: ${e.message}`,
205
+ });
197
206
  if (e instanceof RowsLimitExceededError) {
198
207
  return of(true);
199
208
  }
200
209
  throw e;
201
- }), log({ category: loggingCategory, message: /* istanbul ignore next */ (r) => `Result: ${r}` }));
210
+ }), log({ category: loggingCategory, message: /* istanbul ignore next */ (r) => `[${props.requestContext.requestId}] Result: ${r}` }));
202
211
  }
203
212
  getCachedObservableEntry(props) {
204
213
  const loggingCategory = `${LOGGING_NAMESPACE}.QueryResultsCache`;
@@ -208,7 +217,7 @@ class IModelHierarchyProviderImpl {
208
217
  // istanbul ignore next
209
218
  doLog({
210
219
  category: loggingCategory,
211
- message: /* istanbul ignore next */ () => `Found query nodes observable for ${createNodeIdentifierForLogging(parentNode)}`,
220
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Found query nodes observable for ${createNodeIdentifierForLogging(parentNode)}`,
212
221
  });
213
222
  return cached;
214
223
  }
@@ -236,7 +245,7 @@ class IModelHierarchyProviderImpl {
236
245
  this._nodesCache?.set(nonGroupingNodeChildrenRequestProps, value);
237
246
  doLog({
238
247
  category: loggingCategory,
239
- message: /* istanbul ignore next */ () => `Saved query nodes observable for ${createNodeIdentifierForLogging(parentNode)}`,
248
+ message: /* istanbul ignore next */ () => `[${props.requestContext.requestId}] Saved query nodes observable for ${createNodeIdentifierForLogging(parentNode)}`,
240
249
  });
241
250
  return value;
242
251
  }
@@ -248,7 +257,7 @@ class IModelHierarchyProviderImpl {
248
257
  const post = this.createProcessedNodesObservable(pre, props);
249
258
  return {
250
259
  processedNodes: post,
251
- hasNodes: this.createHasNodesObservable(pre, entry.observable),
260
+ hasNodes: this.createHasNodesObservable(pre, entry.observable, props),
252
261
  finalizedNodes: this.createFinalizedNodesObservable(post, props),
253
262
  };
254
263
  }
@@ -256,7 +265,7 @@ class IModelHierarchyProviderImpl {
256
265
  const post = this.createProcessedNodesObservable(entry.observable, props);
257
266
  return {
258
267
  processedNodes: post,
259
- hasNodes: this.createHasNodesObservable(entry.observable),
268
+ hasNodes: this.createHasNodesObservable(entry.observable, undefined, props),
260
269
  finalizedNodes: this.createFinalizedNodesObservable(post, props),
261
270
  };
262
271
  }
@@ -266,33 +275,34 @@ class IModelHierarchyProviderImpl {
266
275
  * Creates and runs a query based on provided props, then processes retrieved nodes and returns them.
267
276
  */
268
277
  getNodes(props) {
278
+ const requestContext = { requestId: Guid.createValue() };
269
279
  const loggingCategory = `${LOGGING_NAMESPACE}.GetNodes`;
270
280
  const timer = new StopWatch(undefined, true);
271
281
  let error;
272
282
  let nodesCount = 0;
273
283
  doLog({
274
284
  category: loggingCategory,
275
- message: /* istanbul ignore next */ () => `Requesting child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
285
+ message: /* istanbul ignore next */ () => `[${requestContext.requestId}] Requesting child nodes for ${createNodeIdentifierForLogging(props.parentNode)}`,
276
286
  });
277
- return eachValueFrom(this.getChildNodesObservables(props).finalizedNodes.pipe(tap(() => ++nodesCount), catchError((e) => {
287
+ return eachValueFrom(this.getChildNodesObservables({ ...props, requestContext }).finalizedNodes.pipe(tap(() => ++nodesCount), catchError((e) => {
278
288
  error = e;
279
289
  throw e;
280
290
  }), finalize(() => {
281
291
  doLog({
282
292
  category: loggingCategory,
283
293
  message: /* istanbul ignore next */ () => error
284
- ? `Error creating child nodes for ${createNodeIdentifierForLogging(props.parentNode)}: ${error instanceof Error ? error.message : error.toString()}`
285
- : `Returned ${nodesCount} child nodes for ${createNodeIdentifierForLogging(props.parentNode)} in ${timer.currentSeconds.toFixed(2)} s.`,
294
+ ? `[${requestContext.requestId}] Error creating child nodes for ${createNodeIdentifierForLogging(props.parentNode)}: ${error instanceof Error ? error.message : error.toString()}`
295
+ : `[${requestContext.requestId}] Returned ${nodesCount} child nodes for ${createNodeIdentifierForLogging(props.parentNode)} in ${timer.currentSeconds.toFixed(2)} s.`,
286
296
  });
287
297
  })));
288
298
  }
289
299
  getNodeInstanceKeysObs(props) {
290
- const { parentNode, instanceFilter, hierarchyLevelSizeLimit = "unbounded" } = props;
300
+ const { parentNode, instanceFilter, hierarchyLevelSizeLimit = "unbounded", requestContext } = props;
291
301
  if (parentNode && HierarchyNode.isGroupingNode(parentNode)) {
292
302
  return from(parentNode.groupedInstanceKeys);
293
303
  }
294
304
  assert(!parentNode || HierarchyNode.isGeneric(parentNode) || HierarchyNode.isInstancesNode(parentNode));
295
- const hierarchyLevelDefinitions = this.createHierarchyLevelDefinitionsObservable({ parentNode, instanceFilter });
305
+ const hierarchyLevelDefinitions = this.createHierarchyLevelDefinitionsObservable({ parentNode, instanceFilter, requestContext });
296
306
  // split the definitions based on whether they're for generic nodes or for instance nodes
297
307
  const [genericDefs, instanceDefs] = partition(hierarchyLevelDefinitions, HierarchyNodesDefinition.isGenericNode);
298
308
  // query instance keys and a flag whether they should be hidden
@@ -338,30 +348,31 @@ class IModelHierarchyProviderImpl {
338
348
  label: "",
339
349
  })));
340
350
  // merge visible instance keys from this level & the ones we get recursively requesting from deeper levels
341
- return merge(visibleNodeInstanceKeys.pipe(map(({ key }) => key)), hiddenParentNodes.pipe(mergeMap((hiddenNode) => this.getNodeInstanceKeysObs({ parentNode: hiddenNode }))));
351
+ return merge(visibleNodeInstanceKeys.pipe(map(({ key }) => key)), hiddenParentNodes.pipe(mergeMap((hiddenNode) => this.getNodeInstanceKeysObs({ parentNode: hiddenNode, requestContext })))).pipe(takeUntil(this._dispose));
342
352
  }
343
353
  /**
344
354
  * Creates an iterator for all child hierarchy level instance keys, taking into account any hidden hierarchy levels
345
355
  * that there may be under the given parent node.
346
356
  */
347
357
  getNodeInstanceKeys(props) {
358
+ const requestContext = { requestId: Guid.createValue() };
348
359
  const loggingCategory = `${LOGGING_NAMESPACE}.GetNodeInstanceKeys`;
349
360
  const timer = new StopWatch(undefined, true);
350
361
  doLog({
351
362
  category: loggingCategory,
352
- message: /* istanbul ignore next */ () => `Requesting keys for ${createNodeIdentifierForLogging(props.parentNode)}`,
363
+ message: /* istanbul ignore next */ () => `[${requestContext.requestId}] Requesting keys for ${createNodeIdentifierForLogging(props.parentNode)}`,
353
364
  });
354
365
  let error;
355
366
  let keysCount = 0;
356
- return eachValueFrom(this.getNodeInstanceKeysObs(props).pipe(tap(() => ++keysCount), catchError((e) => {
367
+ return eachValueFrom(this.getNodeInstanceKeysObs({ ...props, requestContext }).pipe(tap(() => ++keysCount), catchError((e) => {
357
368
  error = e;
358
369
  throw e;
359
370
  }), finalize(() => {
360
371
  doLog({
361
372
  category: loggingCategory,
362
373
  message: /* istanbul ignore next */ () => error
363
- ? `Error creating node instance keys for ${createNodeIdentifierForLogging(props.parentNode)}: ${error instanceof Error ? error.message : error.toString()}`
364
- : `Returned ${keysCount} instance keys for ${createNodeIdentifierForLogging(props.parentNode)} in ${timer.currentSeconds.toFixed(2)} s.`,
374
+ ? `[${requestContext.requestId}] Error creating node instance keys for ${createNodeIdentifierForLogging(props.parentNode)}: ${error instanceof Error ? error.message : error.toString()}`
375
+ : `[${requestContext.requestId}] Returned ${keysCount} instance keys for ${createNodeIdentifierForLogging(props.parentNode)} in ${timer.currentSeconds.toFixed(2)} s.`,
365
376
  });
366
377
  })));
367
378
  }