@itwin/presentation-hierarchies 1.2.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +4 -3
  3. package/lib/cjs/hierarchies/HierarchyFiltering.d.ts +48 -3
  4. package/lib/cjs/hierarchies/HierarchyFiltering.d.ts.map +1 -1
  5. package/lib/cjs/hierarchies/HierarchyFiltering.js +137 -2
  6. package/lib/cjs/hierarchies/HierarchyFiltering.js.map +1 -1
  7. package/lib/cjs/hierarchies/HierarchyNode.d.ts +1 -0
  8. package/lib/cjs/hierarchies/HierarchyNode.d.ts.map +1 -1
  9. package/lib/cjs/hierarchies/HierarchyNode.js +3 -0
  10. package/lib/cjs/hierarchies/HierarchyNode.js.map +1 -1
  11. package/lib/cjs/hierarchies/HierarchyProvider.d.ts +45 -8
  12. package/lib/cjs/hierarchies/HierarchyProvider.d.ts.map +1 -1
  13. package/lib/cjs/hierarchies/HierarchyProvider.js +7 -6
  14. package/lib/cjs/hierarchies/HierarchyProvider.js.map +1 -1
  15. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.d.ts +3 -6
  16. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.d.ts.map +1 -1
  17. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.js +134 -181
  18. package/lib/cjs/hierarchies/imodel/FilteringHierarchyDefinition.js.map +1 -1
  19. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.d.ts +2 -0
  20. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  21. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js +16 -8
  22. package/lib/cjs/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  23. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.d.ts.map +1 -1
  24. package/lib/cjs/hierarchies/imodel/NodeSelectQueryFactory.js.map +1 -1
  25. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts +1 -1
  26. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts.map +1 -1
  27. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.js +12 -0
  28. package/lib/cjs/hierarchies/imodel/PredicateBasedHierarchyDefinition.js.map +1 -1
  29. package/lib/cjs/hierarchies/internal/Common.d.ts +14 -0
  30. package/lib/cjs/hierarchies/internal/Common.d.ts.map +1 -1
  31. package/lib/cjs/hierarchies/internal/Common.js +18 -0
  32. package/lib/cjs/hierarchies/internal/Common.js.map +1 -1
  33. package/lib/cjs/presentation-hierarchies.d.ts +1 -1
  34. package/lib/cjs/presentation-hierarchies.d.ts.map +1 -1
  35. package/lib/cjs/presentation-hierarchies.js +3 -2
  36. package/lib/cjs/presentation-hierarchies.js.map +1 -1
  37. package/lib/esm/hierarchies/HierarchyFiltering.d.ts +48 -3
  38. package/lib/esm/hierarchies/HierarchyFiltering.d.ts.map +1 -1
  39. package/lib/esm/hierarchies/HierarchyFiltering.js +136 -2
  40. package/lib/esm/hierarchies/HierarchyFiltering.js.map +1 -1
  41. package/lib/esm/hierarchies/HierarchyNode.d.ts +1 -0
  42. package/lib/esm/hierarchies/HierarchyNode.d.ts.map +1 -1
  43. package/lib/esm/hierarchies/HierarchyNode.js +3 -0
  44. package/lib/esm/hierarchies/HierarchyNode.js.map +1 -1
  45. package/lib/esm/hierarchies/HierarchyProvider.d.ts +45 -8
  46. package/lib/esm/hierarchies/HierarchyProvider.d.ts.map +1 -1
  47. package/lib/esm/hierarchies/HierarchyProvider.js +8 -7
  48. package/lib/esm/hierarchies/HierarchyProvider.js.map +1 -1
  49. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.d.ts +3 -6
  50. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.d.ts.map +1 -1
  51. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.js +132 -180
  52. package/lib/esm/hierarchies/imodel/FilteringHierarchyDefinition.js.map +1 -1
  53. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.d.ts +2 -0
  54. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.d.ts.map +1 -1
  55. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js +16 -8
  56. package/lib/esm/hierarchies/imodel/IModelHierarchyProvider.js.map +1 -1
  57. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.d.ts.map +1 -1
  58. package/lib/esm/hierarchies/imodel/NodeSelectQueryFactory.js.map +1 -1
  59. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts +1 -1
  60. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.d.ts.map +1 -1
  61. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.js +12 -0
  62. package/lib/esm/hierarchies/imodel/PredicateBasedHierarchyDefinition.js.map +1 -1
  63. package/lib/esm/hierarchies/internal/Common.d.ts +14 -0
  64. package/lib/esm/hierarchies/internal/Common.d.ts.map +1 -1
  65. package/lib/esm/hierarchies/internal/Common.js +17 -0
  66. package/lib/esm/hierarchies/internal/Common.js.map +1 -1
  67. package/lib/esm/presentation-hierarchies.d.ts +1 -1
  68. package/lib/esm/presentation-hierarchies.d.ts.map +1 -1
  69. package/lib/esm/presentation-hierarchies.js +1 -1
  70. package/lib/esm/presentation-hierarchies.js.map +1 -1
  71. package/package.json +6 -6
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.mergeProviders = mergeProviders;
8
8
  const rxjs_1 = require("rxjs");
9
9
  const core_bentley_1 = require("@itwin/core-bentley");
10
+ const Common_js_1 = require("./internal/Common.js");
10
11
  const EachValueFrom_js_1 = require("./internal/EachValueFrom.js");
11
12
  const Sorting_js_1 = require("./internal/operators/Sorting.js");
12
13
  /**
@@ -18,6 +19,10 @@ function mergeProviders({ providers }) {
18
19
  providers.forEach((p) => {
19
20
  p.hierarchyChanged.addListener(() => hierarchyChanged.raiseEvent());
20
21
  });
22
+ const dispose = () => {
23
+ hierarchyChanged.clear();
24
+ providers.forEach((p) => (0, Common_js_1.safeDispose)(p));
25
+ };
21
26
  return {
22
27
  hierarchyChanged,
23
28
  getNodes: (props) => (0, EachValueFrom_js_1.eachValueFrom)((0, rxjs_1.from)(providers).pipe((0, rxjs_1.mergeMap)((provider) => (0, rxjs_1.from)(provider.getNodes(props)).pipe((0, rxjs_1.mergeMap)((node) => {
@@ -31,12 +36,8 @@ function mergeProviders({ providers }) {
31
36
  getNodeInstanceKeys: (props) => (0, EachValueFrom_js_1.eachValueFrom)((0, rxjs_1.from)(providers).pipe((0, rxjs_1.mergeMap)((p) => p.getNodeInstanceKeys(props)))),
32
37
  setFormatter: (formatter) => providers.forEach((p) => p.setFormatter(formatter)),
33
38
  setHierarchyFilter: (props) => providers.forEach((p) => p.setHierarchyFilter(props)),
34
- dispose: () => {
35
- hierarchyChanged.clear();
36
- providers.forEach((p) => {
37
- (0, core_bentley_1.isIDisposable)(p) && p.dispose();
38
- });
39
- },
39
+ [Symbol.dispose]: dispose,
40
+ dispose,
40
41
  };
41
42
  }
42
43
  //# sourceMappingURL=HierarchyProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyProvider.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAuFhG,wCA2CC;AAhID,+BAA8D;AAC9D,sDAA6D;AAK7D,kEAA4D;AAC5D,gEAA2E;AA0E3E;;;GAGG;AACH,SAAgB,cAAc,CAAC,EAAE,SAAS,EAAgC;IACxE,MAAM,gBAAgB,GAAG,IAAI,sBAAO,EAAc,CAAC;IACnD,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACtB,CAAC,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,CAAC;IACtE,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AAC;QAClH,YAAY,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAChF,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACpF,OAAO,EAAE,GAAG,EAAE;YACZ,gBAAgB,CAAC,KAAK,EAAE,CAAC;YACzB,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACtB,IAAA,4BAAa,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { filter, first, from, map, mergeMap, of } from \"rxjs\";\nimport { BeEvent, isIDisposable } from \"@itwin/core-bentley\";\nimport { GenericInstanceFilter } from \"@itwin/core-common\";\nimport { Event, InstanceKey, IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { HierarchyFilteringPath } from \"./HierarchyFiltering.js\";\nimport { HierarchyNode, ParentHierarchyNode } from \"./HierarchyNode.js\";\nimport { eachValueFrom } from \"./internal/EachValueFrom.js\";\nimport { sortNodesByLabelOperator } from \"./internal/operators/Sorting.js\";\n\n/**\n * Props for the `HierarchyProvider.getNodes` call.\n * @public\n */\nexport interface GetHierarchyNodesProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: ParentHierarchyNode | undefined;\n\n /** Optional hierarchy level filter. Has no effect if `parentNode` is a `GroupingNode`. */\n instanceFilter?: GenericInstanceFilter;\n\n /**\n * Optional hierarchy level size limit override. This value is passed to `LimitingECSqlQueryExecutor` used\n * by this provider to override query rows limit per hierarchy level. If not provided, defaults to whatever\n * is used by the limiting query executor.\n *\n * Has no effect if `parentNode` is a `GroupingNode`.\n */\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n\n /** When set to true ignores the cache and fetches the nodes again. */\n ignoreCache?: boolean;\n}\n\n/**\n * An interface for a hierarchy provider that knows how to create child nodes for a given parent node.\n * @public\n */\nexport interface HierarchyProvider {\n /**\n * An event that provider raises when the internal data source changes, resulting in a\n * hierarchy change.\n *\n * Consumers are expected to subscribe to this event and reload the hierarchy when it's raised.\n */\n readonly hierarchyChanged: Event<() => void>;\n\n /** Gets nodes for the specified parent node. */\n getNodes(props: GetHierarchyNodesProps): AsyncIterableIterator<HierarchyNode>;\n\n /** Gets instance keys for the specified parent node. */\n getNodeInstanceKeys(props: Omit<GetHierarchyNodesProps, \"ignoreCache\">): AsyncIterableIterator<InstanceKey>;\n\n /**\n * Overrides the property value formatter used by the hierarchy provider. Setting to `undefined`\n * resets the formatter to the result of `createDefaultValueFormatter` called with default parameters.\n */\n setFormatter(formatter: IPrimitiveValueFormatter | undefined): void;\n\n /**\n * Sets the hierarchy filter used by this hierarchy provider. Setting to `undefined`\n * removes the filter.\n */\n setHierarchyFilter(\n props:\n | {\n /** A list of node identifiers from root to target node. */\n paths: HierarchyFilteringPath[];\n }\n | undefined,\n ): void;\n}\n\n/**\n * Props for `mergeProviders` function.\n * @public\n */\ninterface MergeHierarchyProvidersProps {\n /** List of providers to merge. */\n providers: HierarchyProvider[];\n}\n\n/**\n * Creates a single, merged, hierarchy provider from multiple given providers.\n * @public\n */\nexport function mergeProviders({ providers }: MergeHierarchyProvidersProps): HierarchyProvider & { dispose: () => void } {\n const hierarchyChanged = new BeEvent<() => void>();\n providers.forEach((p) => {\n p.hierarchyChanged.addListener(() => hierarchyChanged.raiseEvent());\n });\n\n return {\n hierarchyChanged,\n getNodes: (props) =>\n eachValueFrom(\n from(providers).pipe(\n mergeMap((provider) =>\n from(provider.getNodes(props)).pipe(\n mergeMap((node) => {\n if (node.children) {\n return of(node);\n }\n // each provider only considers its own data when determining node's children - in case it says\n // the node has no children, we have to check against the other providers too\n return from(providers).pipe(\n filter((p) => p !== provider),\n mergeMap((p) => p.getNodes({ parentNode: node })),\n map(() => true),\n first(undefined, false),\n map((hasChildren) => ({ ...node, children: hasChildren })),\n );\n }),\n ),\n ),\n sortNodesByLabelOperator,\n // TODO: consider merging similar nodes\n ),\n ),\n getNodeInstanceKeys: (props) => eachValueFrom(from(providers).pipe(mergeMap((p) => p.getNodeInstanceKeys(props)))),\n setFormatter: (formatter) => providers.forEach((p) => p.setFormatter(formatter)),\n setHierarchyFilter: (props) => providers.forEach((p) => p.setHierarchyFilter(props)),\n dispose: () => {\n hierarchyChanged.clear();\n providers.forEach((p) => {\n isIDisposable(p) && p.dispose();\n });\n },\n };\n}\n"]}
1
+ {"version":3,"file":"HierarchyProvider.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AA6HhG,wCA+CC;AA1KD,+BAA8D;AAC9D,sDAA8C;AAK9C,oDAAmD;AACnD,kEAA4D;AAC5D,gEAA2E;AA+G3E;;;GAGG;AACH,SAAgB,cAAc,CAAC,EAAE,SAAS,EAAgC;IAKxE,MAAM,gBAAgB,GAAG,IAAI,sBAAO,EAAc,CAAC;IACnD,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACtB,CAAC,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,gBAAgB,CAAC,KAAK,EAAE,CAAC;QACzB,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,uBAAW,EAAC,CAAC,CAAC,C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AAC,CAAC,CAAC;QAClH,YAAY,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAChF,kBAAkB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACpF,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO;QACzB,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { filter, first, from, map, mergeMap, of } from \"rxjs\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { GenericInstanceFilter } from \"@itwin/core-common\";\nimport { Event, InstanceKey, IPrimitiveValueFormatter, Props } from \"@itwin/presentation-shared\";\nimport { HierarchyFilteringPath } from \"./HierarchyFiltering.js\";\nimport { HierarchyNode, ParentHierarchyNode } from \"./HierarchyNode.js\";\nimport { safeDispose } from \"./internal/Common.js\";\nimport { eachValueFrom } from \"./internal/EachValueFrom.js\";\nimport { sortNodesByLabelOperator } from \"./internal/operators/Sorting.js\";\n\n/**\n * Props for the `HierarchyProvider.getNodes` call.\n * @public\n */\nexport interface GetHierarchyNodesProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: ParentHierarchyNode | undefined;\n\n /** Optional hierarchy level filter. Has no effect if `parentNode` is a `GroupingNode`. */\n instanceFilter?: GenericInstanceFilter;\n\n /**\n * Optional hierarchy level size limit override. This value is passed to `LimitingECSqlQueryExecutor` used\n * by this provider to override query rows limit per hierarchy level. If not provided, defaults to whatever\n * is used by the limiting query executor.\n *\n * Has no effect if `parentNode` is a `GroupingNode`.\n */\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n\n /** When set to `true` ignores the cache and fetches the nodes again. */\n ignoreCache?: boolean;\n}\n\n/**\n * Event arguments for `HierarchyProvider.hierarchyChanged` event.\n * @public\n */\ninterface HierarchyChangedEventArgs {\n /** Set when the hierarchy change was caused by a formatter change. */\n formatterChange?: {\n newFormatter: IPrimitiveValueFormatter | undefined;\n };\n\n /** Set when the hierarchy change was caused by a hierarchy filter change. */\n filterChange?: {\n newFilter: Props<HierarchyProvider[\"setHierarchyFilter\"]>;\n };\n}\n\n/**\n * An interface for a hierarchy provider that knows how to create child nodes for a given parent node.\n * @public\n */\nexport interface HierarchyProvider {\n /**\n * An event that provider raises due to a hierarchy change, that requires a reload. Provider may\n * set additional event arguments to provide extra information about what caused the change.\n *\n * Consumers are expected to subscribe to this event and reload the hierarchy when it's raised.\n * Implementations may provide additional details on what caused the change through the optional\n * event arguments.\n */\n readonly hierarchyChanged: Event<(args?: HierarchyChangedEventArgs) => void>;\n\n /**\n * Gets nodes for the specified parent node. This is **the method to implement**, otherwise\n * the provider doesn't return any nodes.\n */\n getNodes(props: GetHierarchyNodesProps): AsyncIterableIterator<HierarchyNode>;\n\n /**\n * Gets instance keys for the specified parent node.\n *\n * The result of this method may be used to determine instances whose nodes would be displayed as children\n * of the specified parent node. For such use cases calling this method should be more efficient compared\n * to calling `getNodes`.\n */\n getNodeInstanceKeys(props: Omit<GetHierarchyNodesProps, \"ignoreCache\">): AsyncIterableIterator<InstanceKey>;\n\n /**\n * Overrides the property value formatter used by the hierarchy provider. Setting to `undefined`\n * resets the formatter, but what that means depends on the provider implementation - it could just\n * use unformatted values, or use some default formatter, e.g. the on created by `createDefaultValueFormatter`\n * from `@itwin/presentation-shared` package.\n *\n * @note Changing formatter is expected to trigger the `hierarchyChanged` event with `formatterChange` arg.\n */\n setFormatter(formatter: IPrimitiveValueFormatter | undefined): void;\n\n /**\n * Sets the hierarchy filter used by this hierarchy provider. Setting to `undefined`\n * removes the filter.\n *\n * @note There's a difference between `undefined` filter and filter with empty paths list. The\n * former means no filter is applied, while the latter means the filter is applied and it filters-out\n * all hierarchy.\n *\n * @note Changing filter is expected to trigger the `hierarchyChanged` event with `filterChange` arg.\n */\n setHierarchyFilter(\n props:\n | {\n /** A list of node identifiers from root to target node. */\n paths: HierarchyFilteringPath[];\n }\n | undefined,\n ): void;\n}\n\n/**\n * Props for `mergeProviders` function.\n * @public\n */\ninterface MergeHierarchyProvidersProps {\n /** List of providers to merge. */\n providers: HierarchyProvider[];\n}\n\n/**\n * Creates a single, merged, hierarchy provider from multiple given providers.\n * @public\n */\nexport function mergeProviders({ providers }: MergeHierarchyProvidersProps): HierarchyProvider & {\n /** @deprecated in 1.4. Use `[Symbol.dispose]` instead. */\n dispose: () => void;\n [Symbol.dispose]: () => void;\n} {\n const hierarchyChanged = new BeEvent<() => void>();\n providers.forEach((p) => {\n p.hierarchyChanged.addListener(() => hierarchyChanged.raiseEvent());\n });\n const dispose = () => {\n hierarchyChanged.clear();\n providers.forEach((p) => safeDispose(p));\n };\n\n return {\n hierarchyChanged,\n getNodes: (props) =>\n eachValueFrom(\n from(providers).pipe(\n mergeMap((provider) =>\n from(provider.getNodes(props)).pipe(\n mergeMap((node) => {\n if (node.children) {\n return of(node);\n }\n // each provider only considers its own data when determining node's children - in case it says\n // the node has no children, we have to check against the other providers too\n return from(providers).pipe(\n filter((p) => p !== provider),\n mergeMap((p) => p.getNodes({ parentNode: node })),\n map(() => true),\n first(undefined, false),\n map((hasChildren) => ({ ...node, children: hasChildren })),\n );\n }),\n ),\n ),\n sortNodesByLabelOperator,\n // TODO: consider merging similar nodes\n ),\n ),\n getNodeInstanceKeys: (props) => eachValueFrom(from(providers).pipe(mergeMap((p) => p.getNodeInstanceKeys(props)))),\n setFormatter: (formatter) => providers.forEach((p) => p.setFormatter(formatter)),\n setHierarchyFilter: (props) => providers.forEach((p) => p.setHierarchyFilter(props)),\n [Symbol.dispose]: dispose,\n dispose,\n };\n}\n"]}
@@ -18,18 +18,15 @@ export declare class FilteringHierarchyDefinition implements HierarchyDefinition
18
18
  private shouldExpandGroupingNode;
19
19
  get postProcessNode(): NodePostProcessor;
20
20
  get parseNode(): NodeParser;
21
- private getChildrenIdentifierPaths;
22
21
  defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;
23
22
  }
24
23
  /** @internal */
25
- export declare const ECSQL_COLUMN_NAME_HasFilterTargetAncestor = "HasFilterTargetAncestor";
26
- /** @internal */
27
24
  export declare const ECSQL_COLUMN_NAME_FilterECInstanceId = "FilterECInstanceId";
28
25
  /** @internal */
29
26
  export declare const ECSQL_COLUMN_NAME_FilterClassName = "FilterClassName";
30
27
  /** @internal */
31
- export declare function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, matchingFilters: Array<{
32
- id: InstanceKey;
33
- }>, hasFilterTargetAncestor: boolean): InstanceNodesQueryDefinition;
28
+ export declare function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, filteredInstanceKeys: InstanceKey[]): InstanceNodesQueryDefinition;
29
+ /** @internal */
30
+ export declare function applyECInstanceIdsSelector(def: InstanceNodesQueryDefinition): InstanceNodesQueryDefinition;
34
31
  export {};
35
32
  //# sourceMappingURL=FilteringHierarchyDefinition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAyB,sBAAsB,EAAiC,MAAM,0BAA0B,CAAC;AAIxH,OAAO,EACL,yBAAyB,EAEzB,mBAAmB,EAEnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAIxC,UAAU,iCAAiC;IACzC,YAAY,EAAE,yBAAyB,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;gBAEpC,KAAK,EAAE,iCAAiC;IAM3D,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,OAAO,CAAC,wBAAwB;IA2ChC,IAAW,eAAe,IAAI,iBAAiB,CAS9C;IAED,IAAW,SAAS,IAAI,UAAU,CAqBjC;YAEa,0BAA0B;IA8C3B,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CA+DvG;AA4GD,gBAAgB;AAEhB,eAAO,MAAM,yCAAyC,4BAA4B,CAAC;AAEnF,gBAAgB;AAEhB,eAAO,MAAM,oCAAoC,uBAAuB,CAAC;AAEzE,gBAAgB;AAEhB,eAAO,MAAM,iCAAiC,oBAAoB,CAAC;AAenE,gBAAgB;AAChB,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,4BAA4B,EACjC,eAAe,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,WAAW,CAAA;CAAE,CAAC,EAC3C,uBAAuB,EAAE,OAAO,GAC/B,4BAA4B,CAoC9B"}
1
+ {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAkC,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAIlG,OAAO,EACL,yBAAyB,EAEzB,mBAAmB,EAEnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAKxC,UAAU,iCAAiC;IACzC,YAAY,EAAE,yBAAyB,GAAG;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;gBAEpC,KAAK,EAAE,iCAAiC;IAM3D,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,OAAO,CAAC,wBAAwB;IA2ChC,IAAW,eAAe,IAAI,iBAAiB,CAS9C;IAED,IAAW,SAAS,IAAI,UAAU,CAwCjC;IAEY,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAsGvG;AAED,gBAAgB;AAEhB,eAAO,MAAM,oCAAoC,uBAAuB,CAAC;AAEzE,gBAAgB;AAEhB,eAAO,MAAM,iCAAiC,oBAAoB,CAAC;AAenE,gBAAgB;AAChB,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,WAAW,EAAE,GAAG,4BAA4B,CAgC7I;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,4BAA4B,GAAG,4BAA4B,CAc1G"}
@@ -4,13 +4,16 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ECSQL_COLUMN_NAME_FilterClassName = exports.ECSQL_COLUMN_NAME_FilterECInstanceId = exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = exports.FilteringHierarchyDefinition = void 0;
7
+ exports.ECSQL_COLUMN_NAME_FilterClassName = exports.ECSQL_COLUMN_NAME_FilterECInstanceId = exports.FilteringHierarchyDefinition = void 0;
8
8
  exports.applyECInstanceIdsFilter = applyECInstanceIdsFilter;
9
+ exports.applyECInstanceIdsSelector = applyECInstanceIdsSelector;
10
+ const rxjs_1 = require("rxjs");
9
11
  const HierarchyFiltering_js_1 = require("../HierarchyFiltering.js");
10
- const HierarchyNode_js_1 = require("../HierarchyNode.js");
11
12
  const HierarchyNodeIdentifier_js_1 = require("../HierarchyNodeIdentifier.js");
13
+ const Partition_js_1 = require("../internal/operators/Partition.js");
12
14
  const IModelHierarchyDefinition_js_1 = require("./IModelHierarchyDefinition.js");
13
15
  const IModelHierarchyNode_js_1 = require("./IModelHierarchyNode.js");
16
+ const NodeSelectQueryFactory_js_1 = require("./NodeSelectQueryFactory.js");
14
17
  const TreeNodesReader_js_1 = require("./TreeNodesReader.js");
15
18
  /** @internal */
16
19
  class FilteringHierarchyDefinition {
@@ -80,208 +83,143 @@ class FilteringHierarchyDefinition {
80
83
  }
81
84
  get parseNode() {
82
85
  return async (row, parentNode) => {
83
- const hasFilterTargetAncestor = !!row[exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor];
84
- const { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget } = row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId] && row[exports.ECSQL_COLUMN_NAME_FilterClassName]
85
- ? await this.getChildrenIdentifierPaths(parentNode?.filtering?.filteredChildrenIdentifierPaths ?? this._nodeIdentifierPaths, {
86
- className: row[exports.ECSQL_COLUMN_NAME_FilterClassName],
87
- id: row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId],
88
- })
89
- : { filteredChildrenIdentifierPaths: [], filterTargetOptions: undefined, isFilterTarget: false };
90
- const defaultNode = await (this._source.parseNode ?? TreeNodesReader_js_1.defaultNodesParser)(row);
91
- return applyFilterAttributes({
92
- node: defaultNode,
93
- filteredChildrenIdentifierPaths,
94
- isFilterTarget,
95
- filterTargetOptions,
96
- hasFilterTargetAncestor,
97
- });
98
- };
99
- }
100
- async getChildrenIdentifierPaths(filteredChildrenNodeIdentifierPaths, providedIdentifier) {
101
- const { id, className } = providedIdentifier;
102
- let filteredChildrenIdentifierPaths;
103
- let isFilterTarget = false;
104
- let filterTargetOptions;
105
- for (const filteredChildrenNodeIdentifierPath of filteredChildrenNodeIdentifierPaths) {
106
- const { path, options } = HierarchyFiltering_js_1.HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);
107
- /* c8 ignore next 3 */
108
- if (path.length === 0) {
109
- continue;
110
- }
111
- // We need to check if identifiers have the same id and imodelKey and are
112
- // of the same class / derived class / is derived from class
113
- const identifier = path[0];
114
- if (identifier.id !== id) {
115
- continue;
116
- }
117
- if (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {
118
- if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {
119
- continue;
120
- }
121
- if (identifier.className !== className &&
122
- !(await this._imodelAccess.classDerivesFrom(identifier.className, className)) &&
123
- !(await this._imodelAccess.classDerivesFrom(className, identifier.className))) {
124
- continue;
125
- }
126
- }
127
- if (!filteredChildrenIdentifierPaths) {
128
- filteredChildrenIdentifierPaths = [];
129
- }
130
- if (path.length > 1) {
131
- filteredChildrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));
132
- }
133
- else if (isFilterTarget) {
134
- filterTargetOptions = HierarchyFiltering_js_1.HierarchyFilteringPath.mergeOptions(filterTargetOptions, options);
86
+ const parsedNode = await (this._source.parseNode ?? TreeNodesReader_js_1.defaultNodesParser)(row);
87
+ const filteringHelper = (0, HierarchyFiltering_js_1.createHierarchyFilteringHelper)(this._nodeIdentifierPaths, parentNode);
88
+ const nodeExtraProps = row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId] && row[exports.ECSQL_COLUMN_NAME_FilterClassName]
89
+ ? await (async () => {
90
+ const rowInstanceKey = { className: row[exports.ECSQL_COLUMN_NAME_FilterClassName], id: row[exports.ECSQL_COLUMN_NAME_FilterECInstanceId] };
91
+ return filteringHelper.createChildNodePropsAsync({
92
+ pathMatcher: (identifier) => {
93
+ if (identifier.id !== rowInstanceKey.id) {
94
+ return false;
95
+ }
96
+ if (!HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {
97
+ return false;
98
+ }
99
+ if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {
100
+ return false;
101
+ }
102
+ if (identifier.className === rowInstanceKey.className) {
103
+ return true;
104
+ }
105
+ return Promise.all([
106
+ this._imodelAccess.classDerivesFrom(identifier.className, rowInstanceKey.className),
107
+ this._imodelAccess.classDerivesFrom(rowInstanceKey.className, identifier.className),
108
+ ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo);
109
+ },
110
+ });
111
+ })()
112
+ : undefined;
113
+ if (nodeExtraProps?.autoExpand) {
114
+ parsedNode.autoExpand = true;
135
115
  }
136
- else {
137
- isFilterTarget = true;
138
- filterTargetOptions = options;
116
+ if (nodeExtraProps?.filtering) {
117
+ parsedNode.filtering = nodeExtraProps.filtering;
139
118
  }
140
- }
141
- return { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget };
119
+ return parsedNode;
120
+ };
142
121
  }
143
122
  async defineHierarchyLevel(props) {
144
123
  const sourceDefinitions = await this._source.defineHierarchyLevel(props);
145
- const filteringProps = (0, HierarchyFiltering_js_1.extractFilteringProps)(this._nodeIdentifierPaths, props.parentNode);
146
- if (!filteringProps) {
124
+ const filteringHelper = (0, HierarchyFiltering_js_1.createHierarchyFilteringHelper)(this._nodeIdentifierPaths, props.parentNode);
125
+ const childNodeFilteringIdentifiers = filteringHelper.getChildNodeFilteringIdentifiers();
126
+ if (!childNodeFilteringIdentifiers) {
147
127
  return sourceDefinitions;
148
128
  }
149
- const filteredDefinitions = [];
150
- await Promise.all(sourceDefinitions.map(async (definition) => {
151
- let matchedDefinition;
152
- if (IModelHierarchyDefinition_js_1.HierarchyNodesDefinition.isGenericNode(definition)) {
153
- matchedDefinition = await matchFilters(definition, filteringProps, async (id) => {
154
- return (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isGenericNodeIdentifier(id) &&
155
- (!id.source || id.source === this._imodelAccess.imodelKey) &&
156
- id.id === definition.node.key);
157
- }, this._imodelAccess, (def, matchingFilters) => {
158
- const filteredChildrenIdentifierPaths = matchingFilters.reduce((r, c) => [...r, ...c.childrenIdentifierPaths], new Array());
159
- return {
160
- ...def,
161
- node: applyFilterAttributes({
162
- node: def.node,
163
- filteredChildrenIdentifierPaths,
164
- isFilterTarget: matchingFilters.some((mc) => mc.isFilterTarget),
165
- filterTargetOptions: matchingFilters.find((mc) => mc.isFilterTarget)?.filterTargetOptions,
166
- hasFilterTargetAncestor: filteringProps.hasFilterTargetAncestor,
167
- }),
168
- };
169
- });
170
- }
171
- else {
172
- matchedDefinition = await matchFilters(definition, filteringProps, async (id) => {
173
- return (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(id) &&
174
- (!id.imodelKey || id.imodelKey === this._imodelAccess.imodelKey) &&
175
- (await this._imodelAccess.classDerivesFrom(id.className, definition.fullClassName)));
176
- }, this._imodelAccess, (def, matchingFilters) => applyECInstanceIdsFilter(def, matchingFilters, !!filteringProps.hasFilterTargetAncestor), false);
177
- }
178
- if (matchedDefinition) {
179
- filteredDefinitions.push(matchedDefinition);
180
- }
181
- }));
182
- return filteredDefinitions;
183
- }
184
- }
185
- exports.FilteringHierarchyDefinition = FilteringHierarchyDefinition;
186
- async function matchFilters(definition, filteringProps, predicate, classHierarchy, matchedDefinitionProcessor, extractPathsAndOptions = true) {
187
- const { filteredNodePaths, hasFilterTargetAncestor } = filteringProps;
188
- const matchingFilters = [];
189
- for (const filteredNodePath of filteredNodePaths) {
190
- const { path, options } = HierarchyFiltering_js_1.HierarchyFilteringPath.normalize(filteredNodePath);
191
- if (path.length === 0) {
192
- continue;
193
- }
194
- const nodeId = path[0];
195
- if (await predicate(nodeId)) {
196
- let entry = await findMatchingFilterEntry(matchingFilters, nodeId, classHierarchy);
197
- if (!entry) {
198
- entry = {
199
- // ideally, `predicate` would act as a type guard to guarantee that `id` is `TIdentifier`, but at the moment
200
- // async type guards aren't supported
201
- id: nodeId,
202
- childrenIdentifierPaths: [],
203
- isFilterTarget: false,
129
+ const [genericNodeDefinitions, instanceNodeDefinitions] = (0, Partition_js_1.partition)(sourceDefinitions, IModelHierarchyDefinition_js_1.HierarchyNodesDefinition.isGenericNode);
130
+ return (0, rxjs_1.firstValueFrom)((0, rxjs_1.merge)(genericNodeDefinitions.pipe((0, rxjs_1.map)((definition) => {
131
+ if (filteringHelper.hasFilterTargetAncestor ||
132
+ childNodeFilteringIdentifiers.some((identifier) => HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isGenericNodeIdentifier(identifier) &&
133
+ (!identifier.source || identifier.source === this._imodelAccess.imodelKey) &&
134
+ identifier.id === definition.node.key)) {
135
+ return {
136
+ ...definition,
137
+ node: {
138
+ ...definition.node,
139
+ ...filteringHelper.createChildNodeProps({ pathMatcher: ({ id }) => id === definition.node.key }),
140
+ },
204
141
  };
205
- matchingFilters.push(entry);
206
- }
207
- if (!extractPathsAndOptions) {
208
- continue;
209
- }
210
- if (path.length > 1) {
211
- entry.childrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));
212
- }
213
- else if (entry.isFilterTarget) {
214
- entry.filterTargetOptions = HierarchyFiltering_js_1.HierarchyFilteringPath.mergeOptions(entry.filterTargetOptions, options);
215
142
  }
216
- else {
217
- Object.assign(entry, { isFilterTarget: true, filterTargetOptions: options });
143
+ return undefined;
144
+ }), (0, rxjs_1.filter)((def) => !!def)), instanceNodeDefinitions.pipe((0, rxjs_1.mergeMap)((definition) => {
145
+ if (filteringHelper.hasFilterTargetAncestor) {
146
+ // if we have a filter target ancestor, we don't need to filter the definitions - we use all of them
147
+ return (0, rxjs_1.of)(applyECInstanceIdsSelector(definition));
218
148
  }
219
- }
220
- }
221
- if (hasFilterTargetAncestor || matchingFilters.length > 0) {
222
- return matchedDefinitionProcessor(definition, matchingFilters);
223
- }
224
- return undefined;
225
- }
226
- async function findMatchingFilterEntry(filters, nodeId, classHierarchy) {
227
- for (const filter of filters) {
228
- if (await identifiersEqual(filter.id, nodeId, classHierarchy)) {
229
- return filter;
230
- }
231
- }
232
- return undefined;
233
- }
234
- async function identifiersEqual(lhs, rhs, classHierarchy) {
235
- if (HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(lhs) && HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(rhs)) {
236
- return (lhs.id === rhs.id &&
237
- (lhs.className === rhs.className ||
238
- (await classHierarchy.classDerivesFrom(lhs.className, rhs.className)) ||
239
- (await classHierarchy.classDerivesFrom(rhs.className, lhs.className))));
240
- }
241
- return HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.equal(lhs, rhs);
242
- }
243
- function applyFilterAttributes(props) {
244
- const { node, filteredChildrenIdentifierPaths } = props;
245
- const result = { ...node };
246
- const shouldAutoExpand = !!filteredChildrenIdentifierPaths?.some((childPath) => {
247
- return !!HierarchyFiltering_js_1.HierarchyFilteringPath.normalize(childPath).options?.autoExpand;
248
- });
249
- if (shouldAutoExpand) {
250
- result.autoExpand = true;
251
- }
252
- const filteringProps = HierarchyNode_js_1.HierarchyNodeFilteringProps.create(props);
253
- if (filteringProps) {
254
- result.filtering = filteringProps;
149
+ return (0, rxjs_1.defer)(async () => {
150
+ const imodelAccess = this._imodelAccess;
151
+ const matches = new Map();
152
+ async function getEntries(x) {
153
+ let entries = matches.get(x.id);
154
+ if (!entries) {
155
+ entries = [];
156
+ matches.set(x.id, entries);
157
+ }
158
+ // make sure that we don't have path identifiers that only differ by class name, where
159
+ // class names are in the same class hierarchy, e.g.:
160
+ // [{ className: "bis.Element", id: "0x1" }, { className: "bis.Subject", id: "0x1" }]
161
+ // are actually the same instance, so we only need to keep one of them, or otherwise the query will
162
+ // duplicate it
163
+ for (const entry of entries) {
164
+ if (entry.className === x.className ||
165
+ (await imodelAccess.classDerivesFrom(entry.className, x.className)) ||
166
+ (await imodelAccess.classDerivesFrom(x.className, entry.className))) {
167
+ return undefined;
168
+ }
169
+ }
170
+ return entries;
171
+ }
172
+ for (const id of childNodeFilteringIdentifiers) {
173
+ // take only identifiers that match the definition by type, source and class
174
+ if (!HierarchyNodeIdentifier_js_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(id)) {
175
+ continue;
176
+ }
177
+ if (id.imodelKey && id.imodelKey !== imodelAccess.imodelKey) {
178
+ continue;
179
+ }
180
+ if (id.className !== definition.fullClassName &&
181
+ !(await Promise.all([
182
+ imodelAccess.classDerivesFrom(id.className, definition.fullClassName),
183
+ imodelAccess.classDerivesFrom(definition.fullClassName, id.className),
184
+ ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo))) {
185
+ continue;
186
+ }
187
+ const entriesTargetForPathIdentifier = await getEntries(id);
188
+ if (entriesTargetForPathIdentifier) {
189
+ entriesTargetForPathIdentifier.push(id);
190
+ }
191
+ }
192
+ return Array.from(matches.values()).flat();
193
+ }).pipe(
194
+ // only take definitions that have matching path identifiers
195
+ (0, rxjs_1.filter)((pathIdentifiers) => pathIdentifiers.length > 0),
196
+ // for each definition that we're going to use, apply query-level filter
197
+ (0, rxjs_1.map)((pathIdentifiers) => applyECInstanceIdsFilter(definition, pathIdentifiers)));
198
+ }))).pipe((0, rxjs_1.toArray)()));
255
199
  }
256
- return result;
257
200
  }
258
- /** @internal */
259
- // eslint-disable-next-line @typescript-eslint/naming-convention
260
- exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = "HasFilterTargetAncestor";
201
+ exports.FilteringHierarchyDefinition = FilteringHierarchyDefinition;
261
202
  /** @internal */
262
203
  // eslint-disable-next-line @typescript-eslint/naming-convention
263
204
  exports.ECSQL_COLUMN_NAME_FilterECInstanceId = "FilterECInstanceId";
264
205
  /** @internal */
265
206
  // eslint-disable-next-line @typescript-eslint/naming-convention
266
207
  exports.ECSQL_COLUMN_NAME_FilterClassName = "FilterClassName";
267
- function getClassECInstanceIds(matchingFilters) {
208
+ function getClassECInstanceIds(filteredInstanceKeys) {
268
209
  const classNameECInstanceIds = new Map();
269
- for (const matchingFilter of matchingFilters) {
270
- const entry = classNameECInstanceIds.get(matchingFilter.id.className);
210
+ for (const key of filteredInstanceKeys) {
211
+ const entry = classNameECInstanceIds.get(key.className);
271
212
  if (entry === undefined) {
272
- classNameECInstanceIds.set(matchingFilter.id.className, [matchingFilter.id.id]);
213
+ classNameECInstanceIds.set(key.className, [key.id]);
273
214
  continue;
274
215
  }
275
- entry.push(matchingFilter.id.id);
216
+ entry.push(key.id);
276
217
  }
277
218
  return classNameECInstanceIds;
278
219
  }
279
220
  /** @internal */
280
- function applyECInstanceIdsFilter(def, matchingFilters, hasFilterTargetAncestor) {
281
- if (matchingFilters.length === 0) {
282
- return def;
283
- }
284
- const matchingFiltersToUse = getClassECInstanceIds(matchingFilters);
221
+ function applyECInstanceIdsFilter(def, filteredInstanceKeys) {
222
+ const instanceIdsByClass = getClassECInstanceIds(filteredInstanceKeys);
285
223
  return {
286
224
  ...def,
287
225
  query: {
@@ -289,7 +227,7 @@ function applyECInstanceIdsFilter(def, matchingFilters, hasFilterTargetAncestor)
289
227
  ctes: [
290
228
  ...(def.query.ctes ?? []),
291
229
  `FilteringInfo(ECInstanceId, FilterClassName) AS (
292
- ${Array.from(matchingFiltersToUse)
230
+ ${Array.from(instanceIdsByClass)
293
231
  .map(([className, ecInstanceIds]) => `
294
232
  SELECT ECInstanceId, '${className}' AS FilterClassName
295
233
  FROM ${className}
@@ -301,13 +239,28 @@ function applyECInstanceIdsFilter(def, matchingFilters, hasFilterTargetAncestor)
301
239
  ecsql: `
302
240
  SELECT
303
241
  [q].*,
304
- ${hasFilterTargetAncestor ? "1" : "0"} AS [${exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor}],
305
242
  IdToHex([f].[ECInstanceId]) AS [${exports.ECSQL_COLUMN_NAME_FilterECInstanceId}],
306
243
  [f].[FilterClassName] AS [${exports.ECSQL_COLUMN_NAME_FilterClassName}]
307
244
  FROM (
308
245
  ${def.query.ecsql}
309
246
  ) [q]
310
- ${hasFilterTargetAncestor ? "LEFT " : ""} JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]
247
+ JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]
248
+ `,
249
+ },
250
+ };
251
+ }
252
+ /** @internal */
253
+ function applyECInstanceIdsSelector(def) {
254
+ return {
255
+ ...def,
256
+ query: {
257
+ ...def.query,
258
+ ecsql: `
259
+ SELECT
260
+ [q].*,
261
+ IdToHex([q].[ECInstanceId]) AS [${exports.ECSQL_COLUMN_NAME_FilterECInstanceId}],
262
+ [q].[${NodeSelectQueryFactory_js_1.NodeSelectClauseColumnNames.FullClassName}] AS [${exports.ECSQL_COLUMN_NAME_FilterClassName}]
263
+ FROM (${def.query.ecsql}) [q]
311
264
  `,
312
265
  },
313
266
  };
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.js","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAoXhG,4DAwCC;AAxZD,oEAAwH;AACxH,0DAAkE;AAClE,8EAAwE;AAExE,iFAWwC;AACxC,qEAAoJ;AACpJ,6DAA0D;AAQ1D,gBAAgB;AAChB,MAAa,4BAA4B;IAC/B,aAAa,CAAoD;IACjE,OAAO,CAAsB;IAC7B,oBAAoB,CAA2B;IAEvD,YAAmB,KAAwC;QACzD,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,oBAAoB,GAAG,KAA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I,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,GAAG,CAAC;IACb,CAAC;IACD,MAAM,oBAAoB,GAAG,qBAAqB,CAAC,eAAe,CAAC,CAAC;IACpE,OAAO;QACL,GAAG,GAAG;QACN,KAAK,EAAE;YACL,GAAG,GAAG,CAAC,KAAK;YACZ,IAAI,EAAE;gBACJ,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;gBACzB;YACI,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC;qBAC/B,GAAG,CACF,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC;wCACN,SAAS;uBAC1B,SAAS;yCACS,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;eAClD,CACF;qBACA,IAAI,CAAC,aAAa,CAAC;UACtB;aACH;YACD,KAAK,EAAE;;;YAGD,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,iDAAyC;4CACpD,4CAAoC;sCAC1C,yCAAiC;;YAE3D,GAAG,CAAC,KAAK,CAAC,KAAK;;UAEjB,uBAAuB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;OACzC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport { extractFilteringProps, HierarchyFilteringPath, HierarchyFilteringPathOptions } from \"../HierarchyFiltering.js\";\nimport { HierarchyNodeFilteringProps } from \"../HierarchyNode.js\";\nimport { HierarchyNodeIdentifier } from \"../HierarchyNodeIdentifier.js\";\nimport { GenericNodeKey } from \"../HierarchyNodeKey.js\";\nimport {\n DefineHierarchyLevelProps,\n GenericHierarchyNodeDefinition,\n HierarchyDefinition,\n HierarchyDefinitionParentNode,\n HierarchyLevelDefinition,\n HierarchyNodesDefinition,\n InstanceNodesQueryDefinition,\n NodeParser,\n NodePostProcessor,\n NodePreProcessor,\n} from \"./IModelHierarchyDefinition.js\";\nimport { ProcessedGroupingHierarchyNode, ProcessedHierarchyNode, SourceHierarchyNode, SourceInstanceHierarchyNode } from \"./IModelHierarchyNode.js\";\nimport { defaultNodesParser } from \"./TreeNodesReader.js\";\n\ninterface FilteringHierarchyDefinitionProps {\n imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n source: HierarchyDefinition;\n nodeIdentifierPaths: HierarchyFilteringPath[];\n}\n\n/** @internal */\nexport class FilteringHierarchyDefinition implements HierarchyDefinition {\n private _imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n private _source: HierarchyDefinition;\n private _nodeIdentifierPaths: HierarchyFilteringPath[];\n\n public constructor(props: FilteringHierarchyDefinitionProps) {\n this._imodelAccess = props.imodelAccess;\n this._source = props.source;\n this._nodeIdentifierPaths = props.nodeIdentifierPaths;\n }\n\n public get preProcessNode(): NodePreProcessor {\n return async (node) => {\n const processedNode = this._source.preProcessNode ? await this._source.preProcessNode(node) : node;\n if (processedNode?.processingParams?.hideInHierarchy && processedNode.filtering?.isFilterTarget && !processedNode.filtering.hasFilterTargetAncestor) {\n // we want to hide target nodes if they have `hideInHierarchy` param, but only if they're not under another filter target\n return undefined;\n }\n return processedNode;\n };\n }\n\n private shouldExpandGroupingNode(node: ProcessedGroupingHierarchyNode) {\n for (const child of node.children) {\n /* c8 ignore next 3 */\n if (!child.filtering) {\n continue;\n }\n\n if (child.filtering.isFilterTarget) {\n const childAutoExpand = child.filtering.filterTargetOptions?.autoExpand;\n\n // If child is a filter target and is has no `autoExpand` flag, then it's always to be expanded.\n if (childAutoExpand === true) {\n return true;\n }\n\n // If it's not an object and not `true`, then it's falsy - continue looking\n if (typeof childAutoExpand !== \"object\") {\n continue;\n }\n\n // If grouping node's child has `autoExpandUntil` flag,\n // auto-expand the grouping node only if it's depth is lower than that of the grouping node in associated with the target.\n const nodeDepth = node.parentKeys.length;\n const filterTargetDepth = childAutoExpand.depth;\n if (nodeDepth < filterTargetDepth) {\n return true;\n }\n }\n\n if (!child.filtering.filteredChildrenIdentifierPaths) {\n /* c8 ignore next */\n continue;\n }\n\n for (const path of child.filtering.filteredChildrenIdentifierPaths) {\n if (\"path\" in path && path.options?.autoExpand) {\n return true;\n }\n }\n }\n return false;\n }\n\n public get postProcessNode(): NodePostProcessor {\n return async (node: ProcessedHierarchyNode) => {\n const processedNode = this._source.postProcessNode ? await this._source.postProcessNode(node) : node;\n // instance nodes get the auto-expand flag in `parseNode`, but grouping ones need to be handled during post-processing\n if (ProcessedHierarchyNode.isGroupingNode(node) && this.shouldExpandGroupingNode(node)) {\n Object.assign(processedNode, { autoExpand: true });\n }\n return processedNode;\n };\n }\n\n public get parseNode(): NodeParser {\n return async (row: { [columnName: string]: any }, parentNode?: HierarchyDefinitionParentNode): Promise<SourceInstanceHierarchyNode> => {\n const hasFilterTargetAncestor: boolean = !!row[ECSQL_COLUMN_NAME_HasFilterTargetAncestor];\n\n const { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget } =\n row[ECSQL_COLUMN_NAME_FilterECInstanceId] && row[ECSQL_COLUMN_NAME_FilterClassName]\n ? await this.getChildrenIdentifierPaths(parentNode?.filtering?.filteredChildrenIdentifierPaths ?? this._nodeIdentifierPaths, {\n className: row[ECSQL_COLUMN_NAME_FilterClassName],\n id: row[ECSQL_COLUMN_NAME_FilterECInstanceId],\n })\n : { filteredChildrenIdentifierPaths: [], filterTargetOptions: undefined, isFilterTarget: false };\n\n const defaultNode = await (this._source.parseNode ?? defaultNodesParser)(row);\n return applyFilterAttributes({\n node: defaultNode,\n filteredChildrenIdentifierPaths,\n isFilterTarget,\n filterTargetOptions,\n hasFilterTargetAncestor,\n });\n };\n }\n\n private async getChildrenIdentifierPaths(filteredChildrenNodeIdentifierPaths: HierarchyFilteringPath[], providedIdentifier: InstanceKey) {\n const { id, className } = providedIdentifier;\n\n let filteredChildrenIdentifierPaths: HierarchyFilteringPath[] | undefined;\n let isFilterTarget = false;\n let filterTargetOptions: HierarchyFilteringPathOptions | undefined;\n for (const filteredChildrenNodeIdentifierPath of filteredChildrenNodeIdentifierPaths) {\n const { path, options } = HierarchyFilteringPath.normalize(filteredChildrenNodeIdentifierPath);\n /* c8 ignore next 3 */\n if (path.length === 0) {\n continue;\n }\n\n // We need to check if identifiers have the same id and imodelKey and are\n // of the same class / derived class / is derived from class\n const identifier = path[0];\n if (identifier.id !== id) {\n continue;\n }\n if (HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {\n if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {\n continue;\n }\n if (\n identifier.className !== className &&\n !(await this._imodelAccess.classDerivesFrom(identifier.className, className)) &&\n !(await this._imodelAccess.classDerivesFrom(className, identifier.className))\n ) {\n continue;\n }\n }\n if (!filteredChildrenIdentifierPaths) {\n filteredChildrenIdentifierPaths = [];\n }\n if (path.length > 1) {\n filteredChildrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));\n } else if (isFilterTarget) {\n filterTargetOptions = HierarchyFilteringPath.mergeOptions(filterTargetOptions, options);\n } else {\n isFilterTarget = true;\n filterTargetOptions = options;\n }\n }\n return { filteredChildrenIdentifierPaths, filterTargetOptions, isFilterTarget };\n }\n\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const sourceDefinitions = await this._source.defineHierarchyLevel(props);\n const filteringProps = extractFilteringProps(this._nodeIdentifierPaths, props.parentNode);\n if (!filteringProps) {\n return sourceDefinitions;\n }\n\n const filteredDefinitions: HierarchyLevelDefinition = [];\n await Promise.all(\n sourceDefinitions.map(async (definition) => {\n let matchedDefinition: HierarchyNodesDefinition | undefined;\n if (HierarchyNodesDefinition.isGenericNode(definition)) {\n matchedDefinition = await matchFilters<GenericNodeKey>(\n definition,\n filteringProps,\n async (id) => {\n return (\n HierarchyNodeIdentifier.isGenericNodeIdentifier(id) &&\n (!id.source || id.source === this._imodelAccess.imodelKey) &&\n id.id === definition.node.key\n );\n },\n this._imodelAccess,\n (def, matchingFilters) => {\n const filteredChildrenIdentifierPaths = matchingFilters.reduce(\n (r, c) => [...r, ...c.childrenIdentifierPaths],\n new Array<HierarchyFilteringPath>(),\n );\n return {\n ...def,\n node: applyFilterAttributes({\n node: def.node,\n filteredChildrenIdentifierPaths,\n isFilterTarget: matchingFilters.some((mc) => mc.isFilterTarget),\n filterTargetOptions: matchingFilters.find((mc) => mc.isFilterTarget)?.filterTargetOptions,\n hasFilterTargetAncestor: filteringProps.hasFilterTargetAncestor,\n }),\n };\n },\n );\n } else {\n matchedDefinition = await matchFilters<InstanceKey>(\n definition,\n filteringProps,\n async (id) => {\n return (\n HierarchyNodeIdentifier.isInstanceNodeIdentifier(id) &&\n (!id.imodelKey || id.imodelKey === this._imodelAccess.imodelKey) &&\n (await this._imodelAccess.classDerivesFrom(id.className, definition.fullClassName))\n );\n },\n this._imodelAccess,\n (def, matchingFilters) => applyECInstanceIdsFilter(def, matchingFilters, !!filteringProps.hasFilterTargetAncestor),\n false,\n );\n }\n if (matchedDefinition) {\n filteredDefinitions.push(matchedDefinition);\n }\n }),\n );\n return filteredDefinitions;\n }\n}\n\ntype MatchedFilter<TIdentifier extends HierarchyNodeIdentifier> = {\n id: TIdentifier;\n childrenIdentifierPaths: HierarchyFilteringPath[];\n} & ({ isFilterTarget: false } | { isFilterTarget: true; filterTargetOptions?: HierarchyFilteringPathOptions });\n\nasync function matchFilters<\n TIdentifier extends HierarchyNodeIdentifier,\n TDefinition = TIdentifier extends InstanceKey ? InstanceNodesQueryDefinition : GenericHierarchyNodeDefinition,\n>(\n definition: TDefinition,\n filteringProps: { filteredNodePaths: HierarchyFilteringPath[]; hasFilterTargetAncestor?: boolean },\n predicate: (id: HierarchyNodeIdentifier) => Promise<boolean>,\n classHierarchy: ECClassHierarchyInspector,\n matchedDefinitionProcessor: (def: TDefinition, matchingFilters: Array<MatchedFilter<TIdentifier>>) => TDefinition,\n extractPathsAndOptions: boolean = true,\n): Promise<TDefinition | undefined> {\n const { filteredNodePaths, hasFilterTargetAncestor } = filteringProps;\n const matchingFilters: Array<MatchedFilter<TIdentifier>> = [];\n for (const filteredNodePath of filteredNodePaths) {\n const { path, options } = HierarchyFilteringPath.normalize(filteredNodePath);\n if (path.length === 0) {\n continue;\n }\n const nodeId = path[0];\n if (await predicate(nodeId)) {\n let entry = await findMatchingFilterEntry(matchingFilters, nodeId, classHierarchy);\n if (!entry) {\n entry = {\n // ideally, `predicate` would act as a type guard to guarantee that `id` is `TIdentifier`, but at the moment\n // async type guards aren't supported\n id: nodeId as TIdentifier,\n childrenIdentifierPaths: [],\n isFilterTarget: false,\n };\n matchingFilters.push(entry);\n }\n\n if (!extractPathsAndOptions) {\n continue;\n }\n\n if (path.length > 1) {\n entry.childrenIdentifierPaths.push(options ? { path: path.slice(1), options } : path.slice(1));\n } else if (entry.isFilterTarget) {\n entry.filterTargetOptions = HierarchyFilteringPath.mergeOptions(entry.filterTargetOptions, options);\n } else {\n Object.assign(entry, { isFilterTarget: true, filterTargetOptions: options });\n }\n }\n }\n if (hasFilterTargetAncestor || matchingFilters.length > 0) {\n return matchedDefinitionProcessor(definition, matchingFilters);\n }\n return undefined;\n}\n\nasync function findMatchingFilterEntry<TEntry extends { id: TIdentifier }, TIdentifier extends HierarchyNodeIdentifier>(\n filters: TEntry[],\n nodeId: TIdentifier,\n classHierarchy: ECClassHierarchyInspector,\n): Promise<TEntry | undefined> {\n for (const filter of filters) {\n if (await identifiersEqual(filter.id, nodeId, classHierarchy)) {\n return filter;\n }\n }\n return undefined;\n}\n\nasync function identifiersEqual<TIdentifier extends HierarchyNodeIdentifier>(lhs: TIdentifier, rhs: TIdentifier, classHierarchy: ECClassHierarchyInspector) {\n if (HierarchyNodeIdentifier.isInstanceNodeIdentifier(lhs) && HierarchyNodeIdentifier.isInstanceNodeIdentifier(rhs)) {\n return (\n lhs.id === rhs.id &&\n (lhs.className === rhs.className ||\n (await classHierarchy.classDerivesFrom(lhs.className, rhs.className)) ||\n (await classHierarchy.classDerivesFrom(rhs.className, lhs.className)))\n );\n }\n return HierarchyNodeIdentifier.equal(lhs, rhs);\n}\n\nfunction applyFilterAttributes<TNode extends SourceHierarchyNode>(props: {\n node: TNode;\n filteredChildrenIdentifierPaths: HierarchyFilteringPath[] | undefined;\n isFilterTarget?: boolean;\n filterTargetOptions?: HierarchyFilteringPathOptions;\n hasFilterTargetAncestor: boolean;\n}): TNode {\n const { node, filteredChildrenIdentifierPaths } = props;\n const result = { ...node };\n\n const shouldAutoExpand = !!filteredChildrenIdentifierPaths?.some((childPath) => {\n return !!HierarchyFilteringPath.normalize(childPath).options?.autoExpand;\n });\n if (shouldAutoExpand) {\n result.autoExpand = true;\n }\n\n const filteringProps = HierarchyNodeFilteringProps.create(props);\n if (filteringProps) {\n result.filtering = filteringProps;\n }\n\n return result;\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_HasFilterTargetAncestor = \"HasFilterTargetAncestor\";\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterECInstanceId = \"FilterECInstanceId\";\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterClassName = \"FilterClassName\";\n\nfunction getClassECInstanceIds(matchingFilters: Array<{ id: InstanceKey }>) {\n const classNameECInstanceIds = new Map<string, Id64String[]>();\n for (const matchingFilter of matchingFilters) {\n const entry = classNameECInstanceIds.get(matchingFilter.id.className);\n if (entry === undefined) {\n classNameECInstanceIds.set(matchingFilter.id.className, [matchingFilter.id.id]);\n continue;\n }\n entry.push(matchingFilter.id.id);\n }\n return classNameECInstanceIds;\n}\n\n/** @internal */\nexport function applyECInstanceIdsFilter(\n def: InstanceNodesQueryDefinition,\n matchingFilters: Array<{ id: InstanceKey }>,\n hasFilterTargetAncestor: boolean,\n): InstanceNodesQueryDefinition {\n if (matchingFilters.length === 0) {\n return def;\n }\n const matchingFiltersToUse = getClassECInstanceIds(matchingFilters);\n return {\n ...def,\n query: {\n ...def.query,\n ctes: [\n ...(def.query.ctes ?? []),\n `FilteringInfo(ECInstanceId, FilterClassName) AS (\n ${Array.from(matchingFiltersToUse)\n .map(\n ([className, ecInstanceIds]) => `\n SELECT ECInstanceId, '${className}' AS FilterClassName\n FROM ${className}\n WHERE ECInstanceId IN (${ecInstanceIds.join(\", \")})\n `,\n )\n .join(\" UNION ALL \")}\n )`,\n ],\n ecsql: `\n SELECT\n [q].*,\n ${hasFilterTargetAncestor ? \"1\" : \"0\"} AS [${ECSQL_COLUMN_NAME_HasFilterTargetAncestor}],\n IdToHex([f].[ECInstanceId]) AS [${ECSQL_COLUMN_NAME_FilterECInstanceId}],\n [f].[FilterClassName] AS [${ECSQL_COLUMN_NAME_FilterClassName}]\n FROM (\n ${def.query.ecsql}\n ) [q]\n ${hasFilterTargetAncestor ? \"LEFT \" : \"\"} JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]\n `,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"FilteringHierarchyDefinition.js","sourceRoot":"","sources":["../../../../src/hierarchies/imodel/FilteringHierarchyDefinition.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAoRhG,4DAgCC;AAGD,gEAcC;AAnUD,+BAAwF;AAGxF,oEAAkG;AAClG,8EAAwE;AAExE,qEAA+D;AAC/D,iFAWwC;AACxC,qEAA+H;AAC/H,2EAA0E;AAC1E,6DAA0D;AAQ1D,gBAAgB;AAChB,MAAa,4BAA4B;IAC/B,aAAa,CAAoD;IACjE,OAAO,CAAsB;IAC7B,oBAAoB,CAA2B;IAEvD,YAAmB,KAAwC;QACzD,IAAI,CAAC,aAAa,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,IAAI,EAAE,CAAC;gBACzB;YACI,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC;qBAC7B,GAAG,CACF,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC;wCACN,SAAS;uBAC1B,SAAS;yCACS,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;eAClD,CACF;qBACA,IAAI,CAAC,aAAa,CAAC;UACtB;aACH;YACD,KAAK,EAAE;;;4CAG+B,4CAAoC;sCAC1C,yCAAiC;;YAE3D,GAAG,CAAC,KAAK,CAAC,KAAK;;;OAGpB;SACF;KACF,CAAC;AACJ,CAAC;AAED,gBAAgB;AAChB,SAAgB,0BAA0B,CAAC,GAAiC;IAC1E,OAAO;QACL,GAAG,GAAG;QACN,KAAK,EAAE;YACL,GAAG,GAAG,CAAC,KAAK;YACZ,KAAK,EAAE;;;4CAG+B,4CAAoC;iBAC/D,uDAA2B,CAAC,aAAa,SAAS,yCAAiC;gBACpF,GAAG,CAAC,KAAK,CAAC,KAAK;OACxB;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { defer, filter, firstValueFrom, map, merge, mergeMap, of, toArray } from \"rxjs\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport { createHierarchyFilteringHelper, HierarchyFilteringPath } from \"../HierarchyFiltering.js\";\nimport { HierarchyNodeIdentifier } from \"../HierarchyNodeIdentifier.js\";\nimport { IModelInstanceKey } from \"../HierarchyNodeKey.js\";\nimport { partition } from \"../internal/operators/Partition.js\";\nimport {\n DefineHierarchyLevelProps,\n GenericHierarchyNodeDefinition,\n HierarchyDefinition,\n HierarchyDefinitionParentNode,\n HierarchyLevelDefinition,\n HierarchyNodesDefinition,\n InstanceNodesQueryDefinition,\n NodeParser,\n NodePostProcessor,\n NodePreProcessor,\n} from \"./IModelHierarchyDefinition.js\";\nimport { ProcessedGroupingHierarchyNode, ProcessedHierarchyNode, SourceInstanceHierarchyNode } from \"./IModelHierarchyNode.js\";\nimport { NodeSelectClauseColumnNames } from \"./NodeSelectQueryFactory.js\";\nimport { defaultNodesParser } from \"./TreeNodesReader.js\";\n\ninterface FilteringHierarchyDefinitionProps {\n imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n source: HierarchyDefinition;\n nodeIdentifierPaths: HierarchyFilteringPath[];\n}\n\n/** @internal */\nexport class FilteringHierarchyDefinition implements HierarchyDefinition {\n private _imodelAccess: ECClassHierarchyInspector & { imodelKey: string };\n private _source: HierarchyDefinition;\n private _nodeIdentifierPaths: HierarchyFilteringPath[];\n\n public constructor(props: FilteringHierarchyDefinitionProps) {\n this._imodelAccess = props.imodelAccess;\n this._source = props.source;\n this._nodeIdentifierPaths = props.nodeIdentifierPaths;\n }\n\n public get preProcessNode(): NodePreProcessor {\n return async (node) => {\n const processedNode = this._source.preProcessNode ? await this._source.preProcessNode(node) : node;\n if (processedNode?.processingParams?.hideInHierarchy && processedNode.filtering?.isFilterTarget && !processedNode.filtering.hasFilterTargetAncestor) {\n // we want to hide target nodes if they have `hideInHierarchy` param, but only if they're not under another filter target\n return undefined;\n }\n return processedNode;\n };\n }\n\n private shouldExpandGroupingNode(node: ProcessedGroupingHierarchyNode) {\n for (const child of node.children) {\n /* c8 ignore next 3 */\n if (!child.filtering) {\n continue;\n }\n\n if (child.filtering.isFilterTarget) {\n const childAutoExpand = child.filtering.filterTargetOptions?.autoExpand;\n\n // If child is a filter target and is has no `autoExpand` flag, then it's always to be expanded.\n if (childAutoExpand === true) {\n return true;\n }\n\n // If it's not an object and not `true`, then it's falsy - continue looking\n if (typeof childAutoExpand !== \"object\") {\n continue;\n }\n\n // If grouping node's child has `autoExpandUntil` flag,\n // auto-expand the grouping node only if it's depth is lower than that of the grouping node in associated with the target.\n const nodeDepth = node.parentKeys.length;\n const filterTargetDepth = childAutoExpand.depth;\n if (nodeDepth < filterTargetDepth) {\n return true;\n }\n }\n\n if (!child.filtering.filteredChildrenIdentifierPaths) {\n /* c8 ignore next */\n continue;\n }\n\n for (const path of child.filtering.filteredChildrenIdentifierPaths) {\n if (\"path\" in path && path.options?.autoExpand) {\n return true;\n }\n }\n }\n return false;\n }\n\n public get postProcessNode(): NodePostProcessor {\n return async (node: ProcessedHierarchyNode) => {\n const processedNode = this._source.postProcessNode ? await this._source.postProcessNode(node) : node;\n // instance nodes get the auto-expand flag in `parseNode`, but grouping ones need to be handled during post-processing\n if (ProcessedHierarchyNode.isGroupingNode(node) && this.shouldExpandGroupingNode(node)) {\n Object.assign(processedNode, { autoExpand: true });\n }\n return processedNode;\n };\n }\n\n public get parseNode(): NodeParser {\n return async (row: { [columnName: string]: any }, parentNode?: HierarchyDefinitionParentNode): Promise<SourceInstanceHierarchyNode> => {\n const parsedNode = await (this._source.parseNode ?? defaultNodesParser)(row);\n\n const filteringHelper = createHierarchyFilteringHelper(this._nodeIdentifierPaths, parentNode);\n const nodeExtraProps =\n row[ECSQL_COLUMN_NAME_FilterECInstanceId] && row[ECSQL_COLUMN_NAME_FilterClassName]\n ? await (async () => {\n const rowInstanceKey = { className: row[ECSQL_COLUMN_NAME_FilterClassName], id: row[ECSQL_COLUMN_NAME_FilterECInstanceId] };\n return filteringHelper.createChildNodePropsAsync({\n pathMatcher: (identifier): boolean | Promise<boolean> => {\n if (identifier.id !== rowInstanceKey.id) {\n return false;\n }\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {\n return false;\n }\n if (identifier.imodelKey && identifier.imodelKey !== this._imodelAccess.imodelKey) {\n return false;\n }\n if (identifier.className === rowInstanceKey.className) {\n return true;\n }\n return Promise.all([\n this._imodelAccess.classDerivesFrom(identifier.className, rowInstanceKey.className),\n this._imodelAccess.classDerivesFrom(rowInstanceKey.className, identifier.className),\n ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo);\n },\n });\n })()\n : undefined;\n if (nodeExtraProps?.autoExpand) {\n parsedNode.autoExpand = true;\n }\n if (nodeExtraProps?.filtering) {\n parsedNode.filtering = nodeExtraProps.filtering;\n }\n\n return parsedNode;\n };\n }\n\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const sourceDefinitions = await this._source.defineHierarchyLevel(props);\n\n const filteringHelper = createHierarchyFilteringHelper(this._nodeIdentifierPaths, props.parentNode);\n const childNodeFilteringIdentifiers = filteringHelper.getChildNodeFilteringIdentifiers();\n if (!childNodeFilteringIdentifiers) {\n return sourceDefinitions;\n }\n\n const [genericNodeDefinitions, instanceNodeDefinitions] = partition(sourceDefinitions, HierarchyNodesDefinition.isGenericNode);\n return firstValueFrom(\n merge(\n genericNodeDefinitions.pipe(\n map((definition) => {\n if (\n filteringHelper.hasFilterTargetAncestor ||\n childNodeFilteringIdentifiers.some(\n (identifier) =>\n HierarchyNodeIdentifier.isGenericNodeIdentifier(identifier) &&\n (!identifier.source || identifier.source === this._imodelAccess.imodelKey) &&\n identifier.id === definition.node.key,\n )\n ) {\n return {\n ...definition,\n node: {\n ...definition.node,\n ...filteringHelper.createChildNodeProps({ pathMatcher: ({ id }) => id === definition.node.key }),\n },\n };\n }\n return undefined;\n }),\n filter((def): def is GenericHierarchyNodeDefinition => !!def),\n ),\n\n instanceNodeDefinitions.pipe(\n mergeMap((definition) => {\n if (filteringHelper.hasFilterTargetAncestor) {\n // if we have a filter target ancestor, we don't need to filter the definitions - we use all of them\n return of(applyECInstanceIdsSelector(definition));\n }\n return defer(async () => {\n const imodelAccess = this._imodelAccess;\n const matches = new Map<Id64String, IModelInstanceKey[]>();\n async function getEntries(x: IModelInstanceKey) {\n let entries = matches.get(x.id);\n if (!entries) {\n entries = [];\n matches.set(x.id, entries);\n }\n // make sure that we don't have path identifiers that only differ by class name, where\n // class names are in the same class hierarchy, e.g.:\n // [{ className: \"bis.Element\", id: \"0x1\" }, { className: \"bis.Subject\", id: \"0x1\" }]\n // are actually the same instance, so we only need to keep one of them, or otherwise the query will\n // duplicate it\n for (const entry of entries) {\n if (\n entry.className === x.className ||\n (await imodelAccess.classDerivesFrom(entry.className, x.className)) ||\n (await imodelAccess.classDerivesFrom(x.className, entry.className))\n ) {\n return undefined;\n }\n }\n return entries;\n }\n for (const id of childNodeFilteringIdentifiers) {\n // take only identifiers that match the definition by type, source and class\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(id)) {\n continue;\n }\n if (id.imodelKey && id.imodelKey !== imodelAccess.imodelKey) {\n continue;\n }\n if (\n id.className !== definition.fullClassName &&\n !(await Promise.all([\n imodelAccess.classDerivesFrom(id.className, definition.fullClassName),\n imodelAccess.classDerivesFrom(definition.fullClassName, id.className),\n ]).then(([isDerivedFrom, isDerivedTo]) => isDerivedFrom || isDerivedTo))\n ) {\n continue;\n }\n const entriesTargetForPathIdentifier = await getEntries(id);\n if (entriesTargetForPathIdentifier) {\n entriesTargetForPathIdentifier.push(id);\n }\n }\n return Array.from(matches.values()).flat();\n }).pipe(\n // only take definitions that have matching path identifiers\n filter((pathIdentifiers) => pathIdentifiers.length > 0),\n\n // for each definition that we're going to use, apply query-level filter\n map((pathIdentifiers) => applyECInstanceIdsFilter(definition, pathIdentifiers)),\n );\n }),\n ),\n ).pipe(toArray()),\n );\n }\n}\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterECInstanceId = \"FilterECInstanceId\";\n\n/** @internal */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ECSQL_COLUMN_NAME_FilterClassName = \"FilterClassName\";\n\nfunction getClassECInstanceIds(filteredInstanceKeys: InstanceKey[]) {\n const classNameECInstanceIds = new Map<string, Id64String[]>();\n for (const key of filteredInstanceKeys) {\n const entry = classNameECInstanceIds.get(key.className);\n if (entry === undefined) {\n classNameECInstanceIds.set(key.className, [key.id]);\n continue;\n }\n entry.push(key.id);\n }\n return classNameECInstanceIds;\n}\n\n/** @internal */\nexport function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, filteredInstanceKeys: InstanceKey[]): InstanceNodesQueryDefinition {\n const instanceIdsByClass = getClassECInstanceIds(filteredInstanceKeys);\n return {\n ...def,\n query: {\n ...def.query,\n ctes: [\n ...(def.query.ctes ?? []),\n `FilteringInfo(ECInstanceId, FilterClassName) AS (\n ${Array.from(instanceIdsByClass)\n .map(\n ([className, ecInstanceIds]) => `\n SELECT ECInstanceId, '${className}' AS FilterClassName\n FROM ${className}\n WHERE ECInstanceId IN (${ecInstanceIds.join(\", \")})\n `,\n )\n .join(\" UNION ALL \")}\n )`,\n ],\n ecsql: `\n SELECT\n [q].*,\n IdToHex([f].[ECInstanceId]) AS [${ECSQL_COLUMN_NAME_FilterECInstanceId}],\n [f].[FilterClassName] AS [${ECSQL_COLUMN_NAME_FilterClassName}]\n FROM (\n ${def.query.ecsql}\n ) [q]\n JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]\n `,\n },\n };\n}\n\n/** @internal */\nexport function applyECInstanceIdsSelector(def: InstanceNodesQueryDefinition): InstanceNodesQueryDefinition {\n return {\n ...def,\n query: {\n ...def.query,\n ecsql: `\n SELECT\n [q].*,\n IdToHex([q].[ECInstanceId]) AS [${ECSQL_COLUMN_NAME_FilterECInstanceId}],\n [q].[${NodeSelectClauseColumnNames.FullClassName}] AS [${ECSQL_COLUMN_NAME_FilterClassName}]\n FROM (${def.query.ecsql}) [q]\n `,\n },\n };\n}\n"]}