@itwin/presentation-hierarchies 0.1.5 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,85 @@
1
1
  # @itwin/presentation-hierarchies
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#642](https://github.com/iTwin/presentation/pull/642): Added `onlyIfNotHandled` flag to hierarchy level definitions that are passed to `createClassBasedHierarchyDefinition`.
8
+ This flag allows to skip instance node hierarchy level definitions if previous ones have defined hierarchy levels for a more specific class.
9
+ This can help to reduce repetition having to check if class doesn't match those of the more specific definitions.
10
+
11
+ Before:
12
+
13
+ ```ts
14
+ createClassBasedHierarchyDefinition({
15
+ classHierarchyInspector: inspector,
16
+ hierarchy: {
17
+ childNodes: [
18
+ {
19
+ parentNodeClassName: "BisCore.PhysicalElement",
20
+ definitions: async ({ parentNode }) => getPhysicalElementChildren(parentNode),
21
+ },
22
+ {
23
+ parentNodeClassName: "BisCore.SpatialElement",
24
+ definitions: async ({ parentNode, parentNodeClassName }) => {
25
+ if (await inspector.classDerivesFrom(parentNodeClassName, "BisCore.PhysicalElement")) {
26
+ return [];
27
+ }
28
+
29
+ return getSpatialElementChildren(parentNode);
30
+ },
31
+ },
32
+ {
33
+ parentNodeClassName: "BisCore.GeometricElement3d",
34
+ definitions: async ({ parentNode, parentNodeClassName }) => {
35
+ if (await inspector.classDerivesFrom(parentNodeClassName, "BisCore.PhysicalElement")) {
36
+ return [];
37
+ }
38
+
39
+ if (await inspector.classDerivesFrom(parentNodeClassName, "BisCore.SpatialElement")) {
40
+ return [];
41
+ }
42
+
43
+ return getGeometricElement3dChildren(parentNode);
44
+ },
45
+ },
46
+ ],
47
+ },
48
+ });
49
+ ```
50
+
51
+ After:
52
+
53
+ ```ts
54
+ createClassBasedHierarchyDefinition({
55
+ classHierarchyInspector,
56
+ hierarchy: {
57
+ childNodes: [
58
+ {
59
+ parentNodeClassName: "BisCore.PhysicalElement",
60
+ definitions: async ({ parentNode }) => getPhysicalElementChildren(parentNode),
61
+ },
62
+ {
63
+ parentNodeClassName: "BisCore.SpatialElement",
64
+ onlyIfNotHandled: true,
65
+ definitions: async ({ parentNode }) => getSpatialElementChildren(parentNode),
66
+ },
67
+ {
68
+ parentNodeClassName: "BisCore.GeometricElement3d",
69
+ onlyIfNotHandled: true,
70
+ definitions: async ({ parentNode }) => getGeometricElement3dChildren(parentNode),
71
+ },
72
+ ],
73
+ },
74
+ });
75
+ ```
76
+
77
+ ## 0.1.6
78
+
79
+ ### Patch Changes
80
+
81
+ - [#634](https://github.com/iTwin/presentation/pull/634): `NodeSelectQueryFactory.createWhereClause`: Fixed `like` operator not matching substrings.
82
+
3
83
  ## 0.1.5
4
84
 
5
85
  ### Patch Changes
@@ -157,6 +157,24 @@ interface InstancesNodeChildHierarchyLevelDefinition {
157
157
  * Called to create a hierarchy level definition when the class check passes (see `parentNodeClassName`).
158
158
  */
159
159
  definitions: (requestProps: DefineInstanceNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;
160
+ /**
161
+ * If set to true, and node matches at least one of the previous definitions, this definition will not be applied.
162
+ *
163
+ * For example:
164
+ * ```ts
165
+ * {
166
+ * parentNodeClassName: "BisCore.GeometricElement3d",
167
+ * definitions: () => ...,
168
+ * },
169
+ * // This will apply to all elements, that are not BisCore.GeometricElement3d
170
+ * {
171
+ * parentNodeClassName: "BisCore.Element",
172
+ * onlyIfNotHandled: true,
173
+ * definitions: () => ...,
174
+ * }
175
+ * ```
176
+ */
177
+ onlyIfNotHandled?: boolean;
160
178
  }
161
179
  /**
162
180
  * Props for defining child hierarchy level for specific parent custom node.
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyDefinition.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,E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EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,CAAC,YAAY,EAAE,wCAAwC,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC5G;AAED;;;GAGG;AACH,KAAK,kCAAkC,GAAG,0CAA0C,GAAG,uCAAuC,CAAC;AAE/H;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAAC,yBAAyB,EAAE,YAAY,CAAC,CAAC;AAE1F;;GAEG;AACH,UAAU,kCAAkC;IAC1C,gDAAgD;IAChD,uBAAuB,EAAE,yBAAyB,CAAC;IAEnD,8FAA8F;IAC9F,SAAS,EAAE;QACT,4DAA4D;QAC5D,SAAS,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;QAEvF;;;WAGG;QACH,UAAU,EAAE,kCAAkC,EAAE,CAAC;KAClD,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,kCAAkC,GAAG,mBAAmB,CAElH"}
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.createClassBasedHierarchyDefinition = exports.HierarchyNodesDefinition = void 0;
8
8
  const HierarchyNode_1 = require("./HierarchyNode");
9
+ const rxjs_1 = require("rxjs");
9
10
  /** @beta */
10
11
  // eslint-disable-next-line @typescript-eslint/no-redeclare
11
12
  var HierarchyNodesDefinition;
@@ -66,12 +67,13 @@ class ClassBasedHierarchyDefinition {
66
67
  }
67
68
  }
68
69
  async function createHierarchyLevelDefinitions(classHierarchy, defs, requestProps) {
69
- return (await Promise.all(defs.map(async (def) => {
70
+ const obs = (0, rxjs_1.from)(defs).pipe((0, rxjs_1.mergeMap)(async (def, idx) => {
70
71
  if (await classHierarchy.classDerivesFrom(requestProps.parentNodeClassName, def.parentNodeClassName)) {
71
- return def.definitions(requestProps);
72
+ return { def, idx };
72
73
  }
73
- return [];
74
- }))).flat();
74
+ return undefined;
75
+ }), (0, rxjs_1.filter)((x) => !!x), (0, rxjs_1.toArray)(), (0, rxjs_1.concatMap)((x) => x.sort((a, b) => a.idx - b.idx).map(({ def }) => def)), (0, rxjs_1.filter)((def, idx) => !def.onlyIfNotHandled || idx === 0), (0, rxjs_1.mergeMap)(async (def) => def.definitions(requestProps)), (0, rxjs_1.mergeAll)());
76
+ return (0, rxjs_1.firstValueFrom)(obs.pipe((0, rxjs_1.toArray)()));
75
77
  }
76
78
  function groupInstanceIdsByClass(instanceKeys) {
77
79
  const instanceIdsByClass = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyDefinition.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyDefinition.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAKhG,mDAQyB;AA6BzB,YAAY;AACZ,2DAA2D;AAC3D,IAAiB,wBAAwB,CAOxC;AAPD,WAAiB,wBAAwB;IACvC,SAAgB,YAAY,CAAC,GAA6B;QACxD,OAAO,CAAC,CAAE,GAAqC,CAAC,IAAI,CAAC;IACvD,CAAC;IAFe,qCAAY,eAE3B,CAAA;IACD,SAAgB,oBAAoB,CAAC,GAA6B;QAChE,OAAO,CAAC,CAAE,GAAoC,CAAC,KAAK,CAAC;IACvD,CAAC;IAFe,6CAAoB,uBAEnC,CAAA;AACH,CAAC,EAPgB,wBAAwB,wCAAxB,wBAAwB,QAOxC;AAsMD;;;;;;GAMG;AACH,SAAgB,mCAAmC,CAAC,KAAyC;IAC3F,OAAO,IAAI,6BAA6B,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAFD,kFAEC;AAED,MAAM,6BAA6B;IACN;IAA3B,YAA2B,MAA0C;QAA1C,WAAM,GAAN,MAAM,CAAoC;IAAG,CAAC;IAEzE;;;OAGG;IACI,KAAK,CAAC,oBAAoB,CAAC,KAAgC;QAChE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,O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OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAED,KAAK,UAAU,+BAA+B,CAC5C,cAAyC,EACzC,IAAkD,EAClD,YAAwD;IAExD,OAAO,CACL,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACrB,IAAI,MAAM,cAAc,CAAC,gBAAgB,CAAC,YAAY,CAAC,mBAAmB,EAAE,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC;YACrG,OAAO,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CACH,CACF,CAAC,IAAI,EAAE,CAAC;AACX,CAAC;AAED,SAAS,uBAAuB,CAAC,YAA2B;IAC1D,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC3D,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,IAAI,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,WAAW,GAAG,EAAE,CAAC;YACjB,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;QACD,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,yCAAyC,CAAC,GAAuC;IACxF,OAAO,CAAC,CAAE,GAA+C,CAAC,mBAAmB,CAAC;AAChF,CAAC;AAED,SAAS,4CAA4C,CAAC,GAAuC;IAC3F,OAAO,CAAC,CAAE,GAAkD,CAAC,mBAAmB,CAAC;AACnF,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 { GenericInstanceFilter } from \"@itwin/core-common\";\nimport { ECClassHierarchyInspector, ECSqlQueryDef, InstanceKey } from \"@itwin/presentation-shared\";\nimport {\n HierarchyNode,\n NonGroupingHierarchyNode,\n ParsedCustomHierarchyNode,\n ParsedInstanceHierarchyNode,\n ProcessedCustomHierarchyNode,\n ProcessedHierarchyNode,\n ProcessedInstanceHierarchyNode,\n} from \"./HierarchyNode\";\nimport { InstancesNodeKey } from \"./HierarchyNodeKey\";\n\n/** A nodes definition that returns a single custom defined node. */\nexport interface CustomHierarchyNodeDefinition {\n /** The node to be created in the hierarchy level */\n node: ParsedCustomHierarchyNode;\n}\n\n/** A nodes definition that returns an ECSQL query for selecting nodes from an iModel. */\nexport interface InstanceNodesQueryDefinition {\n /**\n * Full name of the class whose instances are going to be returned. It's okay if the attribute\n * points to a base class of multiple different classes of instances returned by the query, however\n * the more specific this class is, the more efficient hierarchy building process is.\n */\n fullClassName: string;\n /**\n * An ECSQL query that selects nodes from an iModel. `SELECT` clause of the query is expected\n * to be built using `NodeSelectQueryFactory.createSelectClause`.\n */\n query: ECSqlQueryDef;\n}\n\n/**\n * A definition of nodes included in a hierarchy level.\n * @beta\n */\nexport type HierarchyNodesDefinition = CustomHierarchyNodeDefinition | InstanceNodesQueryDefinition;\n/** @beta */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace HierarchyNodesDefinition {\n export function isCustomNode(def: HierarchyNodesDefinition): def is CustomHierarchyNodeDefinition {\n return !!(def as CustomHierarchyNodeDefinition).node;\n }\n export function isInstanceNodesQuery(def: HierarchyNodesDefinition): def is InstanceNodesQueryDefinition {\n return !!(def as InstanceNodesQueryDefinition).query;\n }\n}\n\n/**\n * A definition of a hierarchy level, which may consist of multiple node definitions.\n * @beta\n */\nexport type HierarchyLevelDefinition = HierarchyNodesDefinition[];\n\n/**\n * A type for a function that parses a `ParsedInstanceHierarchyNode` from provided ECSQL `row` object.\n * @beta\n */\nexport type NodeParser = (row: { [columnName: string]: any }) => ParsedInstanceHierarchyNode;\n\n/**\n * A type for a function that pre-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one. Returning `undefined` omits the node\n * from the hierarchy.\n *\n * @beta\n */\nexport type NodePreProcessor = <TNode extends ProcessedCustomHierarchyNode | ProcessedInstanceHierarchyNode>(node: TNode) => Promise<TNode | undefined>;\n\n/**\n * A type for a function that post-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one.\n *\n * @beta\n */\nexport type NodePostProcessor = (node: ProcessedHierarchyNode) => Promise<ProcessedHierarchyNode>;\n\n/**\n * A type of node that can be passed to `HierarchyDefinition.defineHierarchyLevel`. This basically means\n * a `HierarchyNode` that:\n * - knows nothing about its children,\n * - is either an instances node (key is of `InstancesNodeKey` type) or a custom node (key is of `string` type).\n */\ntype HierarchyDefinitionParentNode = Omit<NonGroupingHierarchyNode, \"children\">;\n\n/**\n * Props for `HierarchyDefinition.defineHierarchyLevel`.\n * @beta\n */\nexport interface DefineHierarchyLevelProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: HierarchyDefinitionParentNode | undefined;\n\n /** Optional hierarchy level filter. */\n instanceFilter?: GenericInstanceFilter;\n}\n\n/**\n * An interface for a factory that knows how define a hierarchy based on a given parent node.\n * @beta\n */\nexport interface HierarchyDefinition {\n /**\n * An optional function for parsing ECInstance node from ECSQL row.\n *\n * Should be used in situations when the `HierarchyDefinition` implementation\n * introduces additional ECSQL columns into the select clause and wants to assign additional\n * data to the nodes it produces.\n *\n * Defaults to a function that parses all `HierarchyNode` attributes from a query, whose SELECT\n * clause is created using `NodeSelectQueryFactory.createSelectClause`.\n */\n parseNode?: NodeParser;\n\n /**\n * An optional function for pre-processing nodes.\n *\n * Pre-processing happens immediately after the nodes are loaded based on `HierarchyLevelDefinition`\n * returned by this `HierarchyDefinition` and before their processing (hiding, grouping, sorting, etc.) starts.\n * The step allows assigning nodes additional data or excluding them from the hierarchy based on some attributes.\n */\n preProcessNode?: NodePreProcessor;\n\n /**\n * An optional function for post-processing nodes.\n *\n * Post-processing happens after the loaded nodes go through all the merging, hiding and grouping\n * steps, but before sorting them. This step allows `HierarchyDefinition` implementations to assign additional data\n * to nodes after they're processed. This is especially true for grouping nodes as they're only created during\n * processing.\n */\n postProcessNode?: NodePostProcessor;\n\n /** A function to create a hierarchy level definition for given parent node. */\n defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent instance node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineInstanceNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent instance node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: InstancesNodeKey };\n\n /**\n * Full name of the parent instance node class.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeClassName: string;\n\n /**\n * ECInstanceIds of the parent instance node.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeInstanceIds: Id64String[];\n};\n\n/**\n * A definition of a hierarchy level that should be used for specific class of parent instance nodes.\n */\ninterface InstancesNodeChildHierarchyLevelDefinition {\n /**\n * Full name of the parent instance node's class to match against when checking if this hierarchy\n * level should be used for specific parent instance node.\n *\n * The check is polymorphic, so `BisCore.Element` class would match `BisCore.GeometricElement`, `BisCore.Category` and\n * all other element classes.\n */\n parentNodeClassName: string;\n\n /**\n * Called to create a hierarchy level definition when the class check passes (see `parentNodeClassName`).\n */\n definitions: (requestProps: DefineInstanceNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent custom node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineCustomNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent custom node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: string };\n};\n\n/**\n * A definition of a hierarchy level for that should be used for specific custom parent nodes.\n */\ninterface CustomNodeChildHierarchyLevelDefinition {\n /**\n * `HierarchyNode.key` of the custom node that this child hierarchy level definition should be used for.\n */\n customParentNodeKey: string;\n\n /**\n * Called to create a hierarchy level definition when the node key check passes (see `customParentNodeKey`).\n */\n definitions: (requestProps: DefineCustomNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * A hierarchy level definition associated with either parent instance node's class or custom\n * node's key.\n */\ntype ClassBasedHierarchyLevelDefinition = InstancesNodeChildHierarchyLevelDefinition | CustomNodeChildHierarchyLevelDefinition;\n\n/**\n * Props for defining root hierarchy level.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineRootHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\">;\n\n/**\n * Props for `createClassBasedHierarchyDefinition`.\n */\ninterface ClassBasedHierarchyDefinitionProps {\n /** Access to ECClass hierarchy in the iModel */\n classHierarchyInspector: ECClassHierarchyInspector;\n\n /** Hierarchy level definitions based on parent instance node's class or custom node's key. */\n hierarchy: {\n /** Called to create the root hierarchy level definition. */\n rootNodes: (props: DefineRootHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n\n /**\n * Called to get child hierarchy level definitions based on parent instance node's class\n * or custom node's key.\n */\n childNodes: ClassBasedHierarchyLevelDefinition[];\n };\n}\n\n/**\n * Creates an instance of `HierarchyDefinition` that uses a somewhat declarative approach to define the\n * hierarchy - each hierarchy level is assigned either an instance node's class or custom node's\n * key and they're used to assign hierarchy level definitions based on parent node.\n *\n * @beta\n */\nexport function createClassBasedHierarchyDefinition(props: ClassBasedHierarchyDefinitionProps): HierarchyDefinition {\n return new ClassBasedHierarchyDefinition(props);\n}\n\nclass ClassBasedHierarchyDefinition implements HierarchyDefinition {\n public constructor(private _props: ClassBasedHierarchyDefinitionProps) {}\n\n /**\n * Create hierarchy level definitions for specific hierarchy level.\n * @param parentNode Parent node to create children definitions for.\n */\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const { parentNode } = props;\n if (!parentNode) {\n return this._props.hierarchy.rootNodes(props);\n }\n\n if (HierarchyNode.isCustom(parentNode)) {\n const defs = this._props.hierarchy.childNodes\n .filter(isCustomNodeChildHierarchyLevelDefinition)\n .filter((def) => def.customParentNodeKey === parentNode.key);\n return (await Promise.all(defs.map(async (def) => def.definitions({ ...props, parentNode })))).flat();\n }\n\n // istanbul ignore else\n if (HierarchyNode.isInstancesNode(parentNode)) {\n const instanceIdsByClass = groupInstanceIdsByClass(parentNode.key.instanceKeys);\n const instancesParentNodeDefs = this._props.hierarchy.childNodes.filter(isInstancesNodeChildHierarchyLevelDefinition);\n return (\n await Promise.all(\n [...instanceIdsByClass.entries()].map(async ([parentNodeClassName, parentNodeInstanceIds]) =>\n createHierarchyLevelDefinitions(this._props.classHierarchyInspector, instancesParentNodeDefs, {\n ...props,\n parentNodeClassName,\n parentNodeInstanceIds,\n parentNode,\n }),\n ),\n )\n ).flat();\n }\n\n // istanbul ignore next\n return [];\n }\n}\n\nasync function createHierarchyLevelDefinitions(\n classHierarchy: ECClassHierarchyInspector,\n defs: InstancesNodeChildHierarchyLevelDefinition[],\n requestProps: DefineInstanceNodeChildHierarchyLevelProps,\n) {\n return (\n await Promise.all(\n defs.map(async (def) => {\n if (await classHierarchy.classDerivesFrom(requestProps.parentNodeClassName, def.parentNodeClassName)) {\n return def.definitions(requestProps);\n }\n return [];\n }),\n )\n ).flat();\n}\n\nfunction groupInstanceIdsByClass(instanceKeys: InstanceKey[]) {\n const instanceIdsByClass = new Map<string, Id64String[]>();\n instanceKeys.forEach((key) => {\n let instanceIds = instanceIdsByClass.get(key.className);\n if (!instanceIds) {\n instanceIds = [];\n instanceIdsByClass.set(key.className, instanceIds);\n }\n instanceIds.push(key.id);\n });\n return instanceIdsByClass;\n}\n\nfunction isCustomNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is CustomNodeChildHierarchyLevelDefinition {\n return !!(def as CustomNodeChildHierarchyLevelDefinition).customParentNodeKey;\n}\n\nfunction isInstancesNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is InstancesNodeChildHierarchyLevelDefinition {\n return !!(def as InstancesNodeChildHierarchyLevelDefinition).parentNodeClassName;\n}\n"]}
1
+ {"version":3,"file":"HierarchyDefinition.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyDefinition.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAKhG,mDAQyB;AAEzB,+BAA4F;AA4B5F,YAAY;AACZ,2DAA2D;AAC3D,IAAiB,wBAAwB,CAOxC;AAPD,WAAiB,wBAAwB;IACvC,SAAgB,YAAY,CAAC,GAA6B;QACxD,OAAO,CAAC,CAAE,GAAqC,CAAC,IAAI,CAAC;IACvD,CAAC;IAFe,qCAAY,eAE3B,CAAA;IACD,SAAgB,oBAAoB,CAAC,GAA6B;QAChE,OAAO,CAAC,CAAE,GAAoC,CAAC,KAAK,CAAC;IACvD,CAAC;IAFe,6CAAoB,uBAEnC,CAAA;AACH,CAAC,EAPgB,wBAAwB,wCAAxB,wBAAwB,QAOxC;AAyND;;;;;;GAMG;AACH,SAAgB,mCAAmC,CAAC,KAAyC;IAC3F,OAAO,IAAI,6BAA6B,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAFD,kFAEC;AAED,MAAM,6BAA6B;IACN;IAA3B,YAA2B,MAA0C;QAA1C,WAAM,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AC;IACF,OAAO,IAAA,qBAAc,EAAC,GAAG,CAAC,IAAI,CAAC,IAAA,cAAO,GAAE,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,uBAAuB,CAAC,YAA2B;IAC1D,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAwB,CAAC;IAC3D,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,IAAI,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,WAAW,GAAG,EAAE,CAAC;YACjB,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;QACD,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,yCAAyC,CAAC,GAAuC;IACxF,OAAO,CAAC,CAAE,GAA+C,CAAC,mBAAmB,CAAC;AAChF,CAAC;AAED,SAAS,4CAA4C,CAAC,GAAuC;IAC3F,OAAO,CAAC,CAAE,GAAkD,CAAC,mBAAmB,CAAC;AACnF,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 { GenericInstanceFilter } from \"@itwin/core-common\";\nimport { ECClassHierarchyInspector, ECSqlQueryDef, InstanceKey } from \"@itwin/presentation-shared\";\nimport {\n HierarchyNode,\n NonGroupingHierarchyNode,\n ParsedCustomHierarchyNode,\n ParsedInstanceHierarchyNode,\n ProcessedCustomHierarchyNode,\n ProcessedHierarchyNode,\n ProcessedInstanceHierarchyNode,\n} from \"./HierarchyNode\";\nimport { InstancesNodeKey } from \"./HierarchyNodeKey\";\nimport { concatMap, filter, firstValueFrom, from, mergeAll, mergeMap, toArray } from \"rxjs\";\n\n/** A nodes definition that returns a single custom defined node. */\nexport interface CustomHierarchyNodeDefinition {\n /** The node to be created in the hierarchy level */\n node: ParsedCustomHierarchyNode;\n}\n\n/** A nodes definition that returns an ECSQL query for selecting nodes from an iModel. */\nexport interface InstanceNodesQueryDefinition {\n /**\n * Full name of the class whose instances are going to be returned. It's okay if the attribute\n * points to a base class of multiple different classes of instances returned by the query, however\n * the more specific this class is, the more efficient hierarchy building process is.\n */\n fullClassName: string;\n /**\n * An ECSQL query that selects nodes from an iModel. `SELECT` clause of the query is expected\n * to be built using `NodeSelectQueryFactory.createSelectClause`.\n */\n query: ECSqlQueryDef;\n}\n\n/**\n * A definition of nodes included in a hierarchy level.\n * @beta\n */\nexport type HierarchyNodesDefinition = CustomHierarchyNodeDefinition | InstanceNodesQueryDefinition;\n/** @beta */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace HierarchyNodesDefinition {\n export function isCustomNode(def: HierarchyNodesDefinition): def is CustomHierarchyNodeDefinition {\n return !!(def as CustomHierarchyNodeDefinition).node;\n }\n export function isInstanceNodesQuery(def: HierarchyNodesDefinition): def is InstanceNodesQueryDefinition {\n return !!(def as InstanceNodesQueryDefinition).query;\n }\n}\n\n/**\n * A definition of a hierarchy level, which may consist of multiple node definitions.\n * @beta\n */\nexport type HierarchyLevelDefinition = HierarchyNodesDefinition[];\n\n/**\n * A type for a function that parses a `ParsedInstanceHierarchyNode` from provided ECSQL `row` object.\n * @beta\n */\nexport type NodeParser = (row: { [columnName: string]: any }) => ParsedInstanceHierarchyNode;\n\n/**\n * A type for a function that pre-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one. Returning `undefined` omits the node\n * from the hierarchy.\n *\n * @beta\n */\nexport type NodePreProcessor = <TNode extends ProcessedCustomHierarchyNode | ProcessedInstanceHierarchyNode>(node: TNode) => Promise<TNode | undefined>;\n\n/**\n * A type for a function that post-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one.\n *\n * @beta\n */\nexport type NodePostProcessor = (node: ProcessedHierarchyNode) => Promise<ProcessedHierarchyNode>;\n\n/**\n * A type of node that can be passed to `HierarchyDefinition.defineHierarchyLevel`. This basically means\n * a `HierarchyNode` that:\n * - knows nothing about its children,\n * - is either an instances node (key is of `InstancesNodeKey` type) or a custom node (key is of `string` type).\n */\ntype HierarchyDefinitionParentNode = Omit<NonGroupingHierarchyNode, \"children\">;\n\n/**\n * Props for `HierarchyDefinition.defineHierarchyLevel`.\n * @beta\n */\nexport interface DefineHierarchyLevelProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: HierarchyDefinitionParentNode | undefined;\n\n /** Optional hierarchy level filter. */\n instanceFilter?: GenericInstanceFilter;\n}\n\n/**\n * An interface for a factory that knows how define a hierarchy based on a given parent node.\n * @beta\n */\nexport interface HierarchyDefinition {\n /**\n * An optional function for parsing ECInstance node from ECSQL row.\n *\n * Should be used in situations when the `HierarchyDefinition` implementation\n * introduces additional ECSQL columns into the select clause and wants to assign additional\n * data to the nodes it produces.\n *\n * Defaults to a function that parses all `HierarchyNode` attributes from a query, whose SELECT\n * clause is created using `NodeSelectQueryFactory.createSelectClause`.\n */\n parseNode?: NodeParser;\n\n /**\n * An optional function for pre-processing nodes.\n *\n * Pre-processing happens immediately after the nodes are loaded based on `HierarchyLevelDefinition`\n * returned by this `HierarchyDefinition` and before their processing (hiding, grouping, sorting, etc.) starts.\n * The step allows assigning nodes additional data or excluding them from the hierarchy based on some attributes.\n */\n preProcessNode?: NodePreProcessor;\n\n /**\n * An optional function for post-processing nodes.\n *\n * Post-processing happens after the loaded nodes go through all the merging, hiding and grouping\n * steps, but before sorting them. This step allows `HierarchyDefinition` implementations to assign additional data\n * to nodes after they're processed. This is especially true for grouping nodes as they're only created during\n * processing.\n */\n postProcessNode?: NodePostProcessor;\n\n /** A function to create a hierarchy level definition for given parent node. */\n defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent instance node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineInstanceNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent instance node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: InstancesNodeKey };\n\n /**\n * Full name of the parent instance node class.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeClassName: string;\n\n /**\n * ECInstanceIds of the parent instance node.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeInstanceIds: Id64String[];\n};\n\n/**\n * A definition of a hierarchy level that should be used for specific class of parent instance nodes.\n */\ninterface InstancesNodeChildHierarchyLevelDefinition {\n /**\n * Full name of the parent instance node's class to match against when checking if this hierarchy\n * level should be used for specific parent instance node.\n *\n * The check is polymorphic, so `BisCore.Element` class would match `BisCore.GeometricElement`, `BisCore.Category` and\n * all other element classes.\n */\n parentNodeClassName: string;\n\n /**\n * Called to create a hierarchy level definition when the class check passes (see `parentNodeClassName`).\n */\n definitions: (requestProps: DefineInstanceNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n\n /**\n * If set to true, and node matches at least one of the previous definitions, this definition will not be applied.\n *\n * For example:\n * ```ts\n * {\n * parentNodeClassName: \"BisCore.GeometricElement3d\",\n * definitions: () => ...,\n * },\n * // This will apply to all elements, that are not BisCore.GeometricElement3d\n * {\n * parentNodeClassName: \"BisCore.Element\",\n * onlyIfNotHandled: true,\n * definitions: () => ...,\n * }\n * ```\n */\n onlyIfNotHandled?: boolean;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent custom node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineCustomNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent custom node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: string };\n};\n\n/**\n * A definition of a hierarchy level for that should be used for specific custom parent nodes.\n */\ninterface CustomNodeChildHierarchyLevelDefinition {\n /**\n * `HierarchyNode.key` of the custom node that this child hierarchy level definition should be used for.\n */\n customParentNodeKey: string;\n\n /**\n * Called to create a hierarchy level definition when the node key check passes (see `customParentNodeKey`).\n */\n definitions: (requestProps: DefineCustomNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * A hierarchy level definition associated with either parent instance node's class or custom\n * node's key.\n */\ntype ClassBasedHierarchyLevelDefinition = InstancesNodeChildHierarchyLevelDefinition | CustomNodeChildHierarchyLevelDefinition;\n\n/**\n * Props for defining root hierarchy level.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineRootHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\">;\n\n/**\n * Props for `createClassBasedHierarchyDefinition`.\n */\ninterface ClassBasedHierarchyDefinitionProps {\n /** Access to ECClass hierarchy in the iModel */\n classHierarchyInspector: ECClassHierarchyInspector;\n\n /** Hierarchy level definitions based on parent instance node's class or custom node's key. */\n hierarchy: {\n /** Called to create the root hierarchy level definition. */\n rootNodes: (props: DefineRootHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n\n /**\n * Called to get child hierarchy level definitions based on parent instance node's class\n * or custom node's key.\n */\n childNodes: ClassBasedHierarchyLevelDefinition[];\n };\n}\n\n/**\n * Creates an instance of `HierarchyDefinition` that uses a somewhat declarative approach to define the\n * hierarchy - each hierarchy level is assigned either an instance node's class or custom node's\n * key and they're used to assign hierarchy level definitions based on parent node.\n *\n * @beta\n */\nexport function createClassBasedHierarchyDefinition(props: ClassBasedHierarchyDefinitionProps): HierarchyDefinition {\n return new ClassBasedHierarchyDefinition(props);\n}\n\nclass ClassBasedHierarchyDefinition implements HierarchyDefinition {\n public constructor(private _props: ClassBasedHierarchyDefinitionProps) {}\n\n /**\n * Create hierarchy level definitions for specific hierarchy level.\n * @param parentNode Parent node to create children definitions for.\n */\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const { parentNode } = props;\n if (!parentNode) {\n return this._props.hierarchy.rootNodes(props);\n }\n\n if (HierarchyNode.isCustom(parentNode)) {\n const defs = this._props.hierarchy.childNodes\n .filter(isCustomNodeChildHierarchyLevelDefinition)\n .filter((def) => def.customParentNodeKey === parentNode.key);\n return (await Promise.all(defs.map(async (def) => def.definitions({ ...props, parentNode })))).flat();\n }\n\n // istanbul ignore else\n if (HierarchyNode.isInstancesNode(parentNode)) {\n const instanceIdsByClass = groupInstanceIdsByClass(parentNode.key.instanceKeys);\n const instancesParentNodeDefs = this._props.hierarchy.childNodes.filter(isInstancesNodeChildHierarchyLevelDefinition);\n return (\n await Promise.all(\n [...instanceIdsByClass.entries()].map(async ([parentNodeClassName, parentNodeInstanceIds]) =>\n createHierarchyLevelDefinitions(this._props.classHierarchyInspector, instancesParentNodeDefs, {\n ...props,\n parentNodeClassName,\n parentNodeInstanceIds,\n parentNode,\n }),\n ),\n )\n ).flat();\n }\n\n // istanbul ignore next\n return [];\n }\n}\n\nasync function createHierarchyLevelDefinitions(\n classHierarchy: ECClassHierarchyInspector,\n defs: InstancesNodeChildHierarchyLevelDefinition[],\n requestProps: DefineInstanceNodeChildHierarchyLevelProps,\n) {\n const obs = from(defs).pipe(\n mergeMap(async (def, idx) => {\n if (await classHierarchy.classDerivesFrom(requestProps.parentNodeClassName, def.parentNodeClassName)) {\n return { def, idx };\n }\n return undefined;\n }),\n filter((x): x is Exclude<typeof x, undefined> => !!x),\n toArray(),\n concatMap((x) => x.sort((a, b) => a.idx - b.idx).map(({ def }) => def)),\n filter((def, idx) => !def.onlyIfNotHandled || idx === 0),\n mergeMap(async (def) => def.definitions(requestProps)),\n mergeAll(),\n );\n return firstValueFrom(obs.pipe(toArray()));\n}\n\nfunction groupInstanceIdsByClass(instanceKeys: InstanceKey[]) {\n const instanceIdsByClass = new Map<string, Id64String[]>();\n instanceKeys.forEach((key) => {\n let instanceIds = instanceIdsByClass.get(key.className);\n if (!instanceIds) {\n instanceIds = [];\n instanceIdsByClass.set(key.className, instanceIds);\n }\n instanceIds.push(key.id);\n });\n return instanceIdsByClass;\n}\n\nfunction isCustomNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is CustomNodeChildHierarchyLevelDefinition {\n return !!(def as CustomNodeChildHierarchyLevelDefinition).customParentNodeKey;\n}\n\nfunction isInstancesNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is InstancesNodeChildHierarchyLevelDefinition {\n return !!(def as InstancesNodeChildHierarchyLevelDefinition).parentNodeClassName;\n}\n"]}
@@ -329,7 +329,8 @@ async function createWhereClause(contentClassAlias, classLoader, rule) {
329
329
  }
330
330
  const value = rule.value.rawValue;
331
331
  if (rule.operator === "like" && typeof value === "string") {
332
- return `${propertyValueSelector} ${ecsqlOperator} '${value}' ESCAPE '\\'`;
332
+ const escapedValue = value.replace(/[%_\\]/g, "\\$&");
333
+ return `${propertyValueSelector} ${ecsqlOperator} '%${escapedValue}%' ESCAPE '\\'`;
333
334
  }
334
335
  const propertyClass = await classLoader(sourceAlias);
335
336
  if (!propertyClass) {
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSelectQueryFactory.js","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,sDAAyD;AACzD,oDAQ4B;AAC5B,oEAAkJ;AAElJ;;;;;GAKG;AACH,IAAY,2BA0BX;AA1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AC;IACtC,KAAK,MAAM,aAAa,IAAI,WAAW,EAAE,CAAC;QACxC,IAAI,MAAM,uBAAuB,CAAC,gBAAgB,CAAC,aAAa,EAAE,iBAAiB,CAAC,EAAE,CAAC;YACrF,iBAAiB,GAAG,aAAa,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,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 { assert, Id64String } from \"@itwin/core-bentley\";\nimport {\n GenericInstanceFilter,\n GenericInstanceFilterRelationshipStep,\n GenericInstanceFilterRule,\n GenericInstanceFilterRuleGroup,\n GenericInstanceFilterRuleGroupOperator,\n GenericInstanceFilterRuleOperator,\n GenericInstanceFilterRuleValue,\n} from \"@itwin/core-common\";\nimport { EC, ECClassHierarchyInspector, ECSchemaProvider, ECSql, getClass, parseFullClassName, PrimitiveValue } from \"@itwin/presentation-shared\";\n\n/**\n * Column names of the SELECT clause created by `NodeSelectClauseFactory`. Order of the names matches the order of columns\n * created by the factory.\n *\n * @beta\n */\nexport enum NodeSelectClauseColumnNames {\n /** Full class name of the instance the node represents. Type: `string` in format `{schema name}:{class name}`. */\n FullClassName = \"FullClassName\",\n /** ECInstance ID of the instance the node represents. Type: `Id64String`. */\n ECInstanceId = \"ECInstanceId\",\n /** Display label. Type: `string`. */\n DisplayLabel = \"DisplayLabel\",\n /**\n * A flag indicating if the node has children. Type: `boolean`. Values:\n * - `false` - node never has children.\n * - `true` - node always has children.\n * - NULL - unknown, needs to be determined by requesting children for the node.\n */\n HasChildren = \"HasChildren\",\n /** A flag indicating that a node should be hidden if it has no children. Type: `boolean`. */\n HideIfNoChildren = \"HideIfNoChildren\",\n /** A flag indicating that a node should be hidden and its children should be displayed instead. Type: `boolean`. */\n HideNodeInHierarchy = \"HideNodeInHierarchy\",\n /** A serialized JSON object for providing grouping information. */\n Grouping = \"Grouping\",\n /** A serialized JSON object for associating a node with additional data. */\n ExtendedData = \"ExtendedData\",\n /** A flag indicating the node should be auto-expanded when it's loaded. */\n AutoExpand = \"AutoExpand\",\n /** A flag indicating the node supports child hierarchy level filtering. */\n SupportsFiltering = \"SupportsFiltering\",\n}\n\n/**\n * A data structure for defining an ECSQL value selector.\n */\ninterface ECSqlValueSelector {\n selector: string;\n}\n\n/**\n * Props for `NodeSelectClauseFactory.createSelectClause`.\n */\ninterface NodeSelectClauseProps {\n ecClassId: Id64String | ECSqlValueSelector;\n ecInstanceId: Id64String | ECSqlValueSelector;\n nodeLabel: string | ECSqlValueSelector;\n extendedData?: {\n [key: string]: Id64String | string | number | boolean | ECSqlValueSelector;\n };\n autoExpand?: boolean | ECSqlValueSelector;\n supportsFiltering?: boolean | ECSqlValueSelector;\n hasChildren?: boolean | ECSqlValueSelector;\n hideNodeInHierarchy?: boolean | ECSqlValueSelector;\n hideIfNoChildren?: boolean | ECSqlValueSelector;\n grouping?: ECSqlSelectClauseGroupingParams;\n}\n\n/**\n * A data structure for defining nodes' grouping requirements.\n */\ninterface ECSqlSelectClauseGroupingParams {\n byLabel?: ECSqlSelectClauseLabelGroupingParams;\n byClass?: boolean | ECSqlSelectClauseGroupingParamsBase | ECSqlValueSelector;\n byBaseClasses?: ECSqlSelectClauseBaseClassGroupingParams;\n byProperties?: ECSqlSelectClausePropertiesGroupingParams;\n}\n\n/**\n * A data structure for defining label grouping params.\n */\ninterface ECSqlSelectClauseLabelGroupingBaseParams {\n /** Label grouping option that determines whether to group nodes or to merge them. Defaults to \"group\".*/\n action?: \"group\" | \"merge\";\n /** Id that needs to match for nodes to be grouped or merged.*/\n groupId?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining label merging.\n */\ninterface ECSqlSelectClauseLabelGroupingMergeParams extends ECSqlSelectClauseLabelGroupingBaseParams {\n action: \"merge\";\n}\n\n/**\n * A data structure for defining label grouping.\n */\ninterface ECSqlSelectClauseLabelGroupingGroupParams extends ECSqlSelectClauseLabelGroupingBaseParams, ECSqlSelectClauseGroupingParamsBase {\n action?: \"group\";\n}\n\n/**\n * A data structure for defining possible label grouping types.\n */\ntype ECSqlSelectClauseLabelGroupingParams =\n | boolean\n | ECSqlValueSelector\n | ECSqlSelectClauseLabelGroupingMergeParams\n | ECSqlSelectClauseLabelGroupingGroupParams;\n\n/**\n * A data structure for defining base grouping parameters shared across all types of grouping.\n */\ninterface ECSqlSelectClauseGroupingParamsBase {\n hideIfNoSiblings?: boolean | ECSqlValueSelector;\n hideIfOneGroupedNode?: boolean | ECSqlValueSelector;\n autoExpand?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining properties grouping.\n */\ninterface ECSqlSelectClausePropertiesGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n /**\n * Full name of a class whose properties are used to group the node. Only has effect if the node\n * represents an instance of that class.\n *\n * Full class name format: `SchemaName.ClassName`.\n */\n propertiesClassName: string;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value is not set or is set to an empty string.\n *\n * Label of the created grouping node will be `Not Specified`.\n */\n createGroupForUnspecifiedValues?: boolean | ECSqlValueSelector;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value doesn't fit within any of the provided\n * ranges, or is not a numeric value.\n *\n * Label of the created grouping node will be `Other`.\n */\n createGroupForOutOfRangeValues?: boolean | ECSqlValueSelector;\n /**\n * Properties of the specified class, by which the nodes should be grouped.\n *\n * Example usage:\n * ```ts\n * propertyGroups: [\n * {\n * propertyName: \"type\",\n * propertyClassAlias: \"this\"\n * },\n * {\n * propertyName: \"length\",\n * propertyClassAlias: \"x\",\n * ranges: [\n * { fromValue: 1, toValue: 10, rangeLabel: \"Small\" },\n * { fromValue: 11, toValue: 20, rangeLabel: \"Medium\" }\n * ]\n * },\n * ]\n * ```\n */\n propertyGroups: ECSqlSelectClausePropertyGroup[];\n}\n\n/**\n * A data structure for defining specific properties' grouping params.\n */\ninterface ECSqlSelectClausePropertyGroup {\n /** A string indicating the name of the property to group by. */\n propertyName: string;\n /** Alias to of the class containing the property. Used to select the property value. */\n propertyClassAlias: string;\n /** Ranges are used to group nodes by numeric properties which are within specified bounds. */\n ranges?: ECSqlSelectClausePropertyValueRange[];\n}\n\n/**\n * A data structure for defining boundaries for a value.\n */\ninterface ECSqlSelectClausePropertyValueRange {\n /** Defines the lower bound of the range. */\n fromValue: number | ECSqlValueSelector;\n /** Defines the upper bound of the range. */\n toValue: number | ECSqlValueSelector;\n /** Defines the range label. Will be used as grouping node's display label. */\n rangeLabel?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining base class grouping.\n */\ninterface ECSqlSelectClauseBaseClassGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n fullClassNames: string[] | ECSqlValueSelector[];\n}\n\n/**\n * An interface of a factory that knows how to create nodes' select ECSQL query.\n * @beta\n */\nexport interface NodesQueryClauseFactory {\n /** Create a SELECT clause in a format understood by nodes query parser used by `HierarchyProvider`. */\n createSelectClause(props: NodeSelectClauseProps): Promise<string>;\n\n /** Create FROM, JOIN and WHERE clauses whose combination results in an ECSQL filter defined by given `GenericInstanceFilter`. */\n createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }>;\n}\n\n/**\n * Creates an instance of `NodeSelectQueryFactory` that .\n * @beta\n */\nexport function createNodesQueryClauseFactory(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }): NodesQueryClauseFactory {\n return new NodeSelectQueryFactory(props);\n}\n\n/** A factory for creating a nodes' select ECSQL query. */\nclass NodeSelectQueryFactory {\n private _imodelAccess: ECSchemaProvider & ECClassHierarchyInspector;\n\n public constructor(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }) {\n this._imodelAccess = props.imodelAccess;\n }\n\n /** Create a SELECT clause in a format understood by results reader of the library. */\n public async createSelectClause(props: NodeSelectClauseProps) {\n // note: the columns order must match the order in `NodeSelectClauseColumnNames`\n return `\n ec_ClassName(${createECSqlValueSelector(props.ecClassId)}) AS ${NodeSelectClauseColumnNames.FullClassName},\n ${createECSqlValueSelector(props.ecInstanceId)} AS ${NodeSelectClauseColumnNames.ECInstanceId},\n ${createECSqlValueSelector(props.nodeLabel)} AS ${NodeSelectClauseColumnNames.DisplayLabel},\n CAST(${createECSqlValueSelector(props.hasChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HasChildren},\n CAST(${createECSqlValueSelector(props.hideIfNoChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideIfNoChildren},\n CAST(${createECSqlValueSelector(props.hideNodeInHierarchy)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideNodeInHierarchy},\n ${props.grouping ? createGroupingSelector(props.grouping) : \"CAST(NULL AS TEXT)\"} AS ${NodeSelectClauseColumnNames.Grouping},\n ${\n props.extendedData\n ? `json_object(${Object.entries(props.extendedData)\n .map(([key, value]) => `'${key}', ${createECSqlValueSelector(value)}`)\n .join(\", \")})`\n : \"CAST(NULL AS TEXT)\"\n } AS ${NodeSelectClauseColumnNames.ExtendedData},\n CAST(${createECSqlValueSelector(props.autoExpand)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.AutoExpand},\n CAST(${createECSqlValueSelector(props.supportsFiltering)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.SupportsFiltering}\n `;\n }\n\n /**\n * Creates the necessary ECSQL snippets to create an instance filter described by the `def` argument.\n * - `from` is set to either the `contentClass.fullName` or `def.propertyClassName`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `def.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `def.filterClassNames` and by properties as described by `def.rules`.\n *\n * Special cases:\n * - If `def` is `undefined`, `joins` and `where` are set to empty strings and `from` is set to `contentClass.fullName`.\n * - If the provided content class doesn't intersect with the property class in provided filter, a special result\n * is returned to make sure the resulting query is valid and doesn't return anything.\n */\n public async createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }> {\n const { contentClass, filter } = props;\n if (!filter) {\n // undefined filter means we don't want any filtering to be applied\n return { from: contentClass.fullName, joins: \"\", where: \"\" };\n }\n\n const from = await specializeContentClass({\n classHierarchyInspector: this._imodelAccess,\n contentClassName: contentClass.fullName,\n filterClassNames: filter.propertyClassNames,\n });\n if (!from) {\n // filter class doesn't intersect with content class - make sure the query returns nothing by returning a `FALSE` WHERE clause\n return { from: contentClass.fullName, joins: \"\", where: \"FALSE\" };\n }\n\n /**\n * TODO:\n * There may be similar related instance paths, e.g.:\n * - A -> B -> C,\n * - A -> B -> D.\n * At this moment we're handling each path individually which means A and B would get joined twice. We could look into\n * creating a join tree first, e.g.\n * C\n * /\n * A -> B\n * \\\n * D\n */\n const joins = await Promise.all(\n filter.relatedInstances.map(async (rel, i) =>\n ECSql.createRelationshipPathJoinClause({\n schemaProvider: this._imodelAccess,\n path: assignRelationshipPathAliases(rel.path, i, contentClass.alias, rel.alias),\n }),\n ),\n );\n\n const whereConditions = new Array<string>();\n if (filter.filteredClassNames && filter.filteredClassNames.length > 0) {\n whereConditions.push(\n `${ECSql.createRawPropertyValueSelector(contentClass.alias, \"ECClassId\")} IS (\n ${filter.filteredClassNames\n .map(parseFullClassName)\n .map(({ schemaName, className }) => `[${schemaName}].[${className}]`)\n .join(\", \")}\n )`,\n );\n }\n const classAliasMap = new Map<string, string>([[contentClass.alias, from]]);\n filter.relatedInstances.forEach(({ path, alias }) => path.length > 0 && classAliasMap.set(alias, path[path.length - 1].targetClassName));\n const propertiesFilter = await createWhereClause(\n contentClass.alias,\n async (alias) => {\n const aliasClassName = classAliasMap.get(alias);\n return aliasClassName ? getClass(this._imodelAccess, aliasClassName) : undefined;\n },\n filter.rules,\n );\n if (propertiesFilter) {\n whereConditions.push(propertiesFilter);\n }\n\n return {\n from,\n joins: joins.join(\"\\n\"),\n where: whereConditions.join(\" AND \"),\n };\n }\n}\n\nfunction createECSqlValueSelector(input: undefined | PrimitiveValue | ECSqlValueSelector) {\n if (input === undefined) {\n return \"NULL\";\n }\n if (isSelector(input)) {\n return input.selector;\n }\n return ECSql.createRawPrimitiveValueSelector(input);\n}\n\nfunction isSelector(x: any): x is ECSqlValueSelector {\n return !!x.selector;\n}\n\nfunction createGroupingSelector(grouping: ECSqlSelectClauseGroupingParams): string {\n const groupingSelectors = new Array<{ key: string; selector: string }>();\n\n grouping.byLabel &&\n groupingSelectors.push({\n key: \"byLabel\",\n selector:\n typeof grouping.byLabel === \"boolean\" || isSelector(grouping.byLabel)\n ? createECSqlValueSelector(grouping.byLabel)\n : serializeJsonObject(createLabelGroupingBaseParamsSelectors(grouping.byLabel)),\n });\n\n grouping.byClass &&\n groupingSelectors.push({\n key: \"byClass\",\n selector:\n typeof grouping.byClass === \"boolean\" || isSelector(grouping.byClass)\n ? createECSqlValueSelector(grouping.byClass)\n : serializeJsonObject(createBaseGroupingParamSelectors(grouping.byClass)),\n });\n\n grouping.byBaseClasses &&\n groupingSelectors.push({\n key: \"byBaseClasses\",\n selector: serializeJsonObject([\n {\n key: \"fullClassNames\",\n selector: `json_array(${grouping.byBaseClasses.fullClassNames.map((className) => createECSqlValueSelector(className)).join(\", \")})`,\n },\n ...createBaseGroupingParamSelectors(grouping.byBaseClasses),\n ]),\n });\n\n grouping.byProperties &&\n groupingSelectors.push({\n key: \"byProperties\",\n selector: serializeJsonObject([\n {\n key: \"propertiesClassName\",\n selector: `${createECSqlValueSelector(grouping.byProperties.propertiesClassName)}`,\n },\n {\n key: \"propertyGroups\",\n selector: `json_array(${grouping.byProperties.propertyGroups\n .map((propertyGroup) => serializeJsonObject(createPropertyGroupSelectors(propertyGroup)))\n .join(\", \")})`,\n },\n ...(grouping.byProperties.createGroupForOutOfRangeValues !== undefined\n ? [\n {\n key: \"createGroupForOutOfRangeValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForOutOfRangeValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...(grouping.byProperties.createGroupForUnspecifiedValues !== undefined\n ? [\n {\n key: \"createGroupForUnspecifiedValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForUnspecifiedValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...createBaseGroupingParamSelectors(grouping.byProperties),\n ]),\n });\n\n return serializeJsonObject(groupingSelectors);\n}\n\nfunction createLabelGroupingBaseParamsSelectors(byLabel: ECSqlSelectClauseLabelGroupingMergeParams | ECSqlSelectClauseLabelGroupingGroupParams) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (byLabel.action !== undefined) {\n selectors.push({\n key: \"action\",\n selector: `${createECSqlValueSelector(byLabel.action)}`,\n });\n }\n if (byLabel.groupId !== undefined) {\n selectors.push({\n key: \"groupId\",\n selector: createECSqlValueSelector(byLabel.groupId),\n });\n }\n if (byLabel.action !== \"merge\") {\n selectors.push(...createBaseGroupingParamSelectors(byLabel));\n }\n\n return selectors;\n}\n\nfunction createPropertyGroupSelectors(propertyGroup: ECSqlSelectClausePropertyGroup) {\n const selectors = new Array<{ key: string; selector: string }>();\n selectors.push(\n {\n key: \"propertyName\",\n selector: `${createECSqlValueSelector(propertyGroup.propertyName)}`,\n },\n {\n key: \"propertyValue\",\n selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,\n },\n );\n if (propertyGroup.ranges) {\n selectors.push(createRangeParamSelectors(propertyGroup.ranges));\n }\n return selectors;\n}\n\nfunction createRangeParamSelectors(ranges: ECSqlSelectClausePropertyValueRange[]) {\n return {\n key: \"ranges\",\n selector: `json_array(${ranges\n .map((range) =>\n serializeJsonObject([\n {\n key: \"fromValue\",\n selector: createECSqlValueSelector(range.fromValue),\n },\n {\n key: \"toValue\",\n selector: createECSqlValueSelector(range.toValue),\n },\n ...(range.rangeLabel\n ? [\n {\n key: \"rangeLabel\",\n selector: `${createECSqlValueSelector(range.rangeLabel)}`,\n },\n ]\n : []),\n ]),\n )\n .join(\", \")})`,\n };\n}\n\nfunction createBaseGroupingParamSelectors(params: ECSqlSelectClauseGroupingParamsBase) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (params.hideIfNoSiblings !== undefined) {\n selectors.push({\n key: \"hideIfNoSiblings\",\n selector: createECSqlValueSelector(params.hideIfNoSiblings),\n });\n }\n if (params.hideIfOneGroupedNode !== undefined) {\n selectors.push({\n key: \"hideIfOneGroupedNode\",\n selector: createECSqlValueSelector(params.hideIfOneGroupedNode),\n });\n }\n if (params.autoExpand !== undefined) {\n selectors.push({\n key: \"autoExpand\",\n selector: createECSqlValueSelector(params.autoExpand),\n });\n }\n return selectors;\n}\n\nfunction serializeJsonObject(selectors: Array<{ key: string; selector: string }>): string {\n return `json_object(${selectors.map(({ key, selector }) => `'${key}', ${selector}`).join(\", \")})`;\n}\n\nasync function createWhereClause(\n contentClassAlias: string,\n classLoader: (alias: string) => Promise<EC.Class | undefined>,\n rule: GenericInstanceFilterRule | GenericInstanceFilterRuleGroup,\n): Promise<string | undefined> {\n if (GenericInstanceFilter.isFilterRuleGroup(rule)) {\n const clause = (await Promise.all(rule.rules.map(async (r) => createWhereClause(contentClassAlias, classLoader, r))))\n .filter((c) => !!c)\n .join(` ${getECSqlLogicalOperator(rule.operator)} `);\n return clause ? (rule.operator === \"or\" ? `(${clause})` : clause) : undefined;\n }\n const sourceAlias = rule.sourceAlias ? rule.sourceAlias : contentClassAlias;\n const propertyValueSelector = ECSql.createRawPropertyValueSelector(sourceAlias, rule.propertyName);\n if (isUnaryRuleOperator(rule.operator)) {\n switch (rule.operator) {\n case \"is-true\":\n return propertyValueSelector;\n case \"is-false\":\n return `NOT ${propertyValueSelector}`;\n case \"is-null\":\n return `${propertyValueSelector} IS NULL`;\n case \"is-not-null\":\n return `${propertyValueSelector} IS NOT NULL`;\n }\n }\n const ecsqlOperator = getECSqlComparisonOperator(rule.operator);\n if (rule.value === undefined) {\n throw new Error(`Rule \"${rule.propertyName}\" ${ecsqlOperator} is missing value.`);\n }\n\n const value = rule.value.rawValue;\n\n if (rule.operator === \"like\" && typeof value === \"string\") {\n return `${propertyValueSelector} ${ecsqlOperator} '${value}' ESCAPE '\\\\'`;\n }\n const propertyClass = await classLoader(sourceAlias);\n if (!propertyClass) {\n throw new Error(`Class with alias \"${sourceAlias}\" not found.`);\n }\n const property = await propertyClass.getProperty(rule.propertyName);\n if (!property) {\n throw new Error(`Property \"${rule.propertyName}\" not found in ECClass \"${propertyClass.fullName}\".`);\n }\n if (property.isNavigation()) {\n assert(rule.value !== undefined && GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector}.[Id] ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value.id)}`;\n }\n if (property.isEnumeration()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n if (property.isPrimitive()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n switch (property.primitiveType) {\n case \"Point2d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint2d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Point3d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint3d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[z]`, \"is-equal\", value.z)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Double\": {\n assert(typeof value === \"number\");\n if (rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\") {\n return `${createFloatingPointEqualityClause(propertyValueSelector, rule.operator, value)}`;\n }\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n default: {\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n }\n }\n throw new Error(\"Struct and array properties are not supported for filtering\");\n}\n\nfunction createFloatingPointEqualityClause(valueSelector: string, operator: \"is-equal\" | \"is-not-equal\", value: number) {\n const [from, to] = getFloatingPointValueRange(value);\n return `${valueSelector} ${operator === \"is-not-equal\" ? \"NOT \" : \"\"} BETWEEN ${from} AND ${to}`;\n}\n\nfunction getFloatingPointValueRange(value: number): [number, number] {\n return [value - Number.EPSILON, value + Number.EPSILON];\n}\n\nfunction getECSqlLogicalOperator(op: GenericInstanceFilterRuleGroupOperator) {\n switch (op) {\n case \"and\":\n return \"AND\";\n case \"or\":\n return \"OR\";\n }\n}\n\nfunction isUnaryRuleOperator(\n op: GenericInstanceFilterRuleOperator,\n): op is Extract<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\"> {\n return op === \"is-true\" || op === \"is-false\" || op === \"is-null\" || op === \"is-not-null\";\n}\n\nfunction getECSqlComparisonOperator(op: Exclude<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\">) {\n switch (op) {\n case \"is-equal\":\n return `=`;\n case \"is-not-equal\":\n return `<>`;\n case \"greater\":\n return `>`;\n case \"greater-or-equal\":\n return `>=`;\n case \"less\":\n return `<`;\n case \"less-or-equal\":\n return `<=`;\n case \"like\":\n return `LIKE`;\n }\n}\n\ntype JoinRelationshipPath = Parameters<typeof ECSql.createRelationshipPathJoinClause>[0][\"path\"];\nfunction assignRelationshipPathAliases(\n path: GenericInstanceFilterRelationshipStep[],\n pathIndex: number,\n sourceAlias: string,\n targetAlias: string,\n): JoinRelationshipPath {\n function createAlias(fullClassName: string, index: number) {\n return `rel_${pathIndex}_${fullClassName.replaceAll(/[\\.:]/g, \"_\")}_${index}`;\n }\n const result: JoinRelationshipPath = [];\n path.forEach((step, i) => {\n result.push({\n targetClassName: step.targetClassName,\n relationshipName: step.relationshipClassName,\n sourceClassName: step.sourceClassName,\n relationshipReverse: !step.isForwardRelationship,\n sourceAlias: i === 0 ? sourceAlias : result[i - 1].targetAlias,\n relationshipAlias: createAlias(step.relationshipClassName, i),\n targetAlias: i === path.length - 1 ? targetAlias : createAlias(step.targetClassName, i),\n joinType: \"inner\",\n });\n });\n return result;\n}\n\ninterface SpecializeContentClassProps {\n classHierarchyInspector: ECClassHierarchyInspector;\n contentClassName: string;\n filterClassNames: string[];\n}\nasync function specializeContentClass(props: SpecializeContentClassProps): Promise<string | undefined> {\n const filterClass = await getSpecializedPropertyClass(props.classHierarchyInspector, props.filterClassNames);\n if (!filterClass) {\n return props.contentClassName;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(filterClass, props.contentClassName)) {\n return filterClass;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(props.contentClassName, filterClass)) {\n return props.contentClassName;\n }\n return undefined;\n}\n\nasync function getSpecializedPropertyClass(classHierarchyInspector: ECClassHierarchyInspector, classes: string[]): Promise<string | undefined> {\n if (classes.length === 0) {\n return undefined;\n }\n const [currClassName, ...restClasses] = classes;\n let resolvedClassName = currClassName;\n for (const propClassName of restClasses) {\n if (await classHierarchyInspector.classDerivesFrom(propClassName, resolvedClassName)) {\n resolvedClassName = propClassName;\n }\n }\n return resolvedClassName;\n}\n"]}
1
+ {"version":3,"file":"NodeSelectQueryFactory.js","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,sDAAyD;AACzD,oDAQ4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AC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,aAAa,EAAE,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;IAChD,IAAI,iBAAiB,GAAG,aAAa,CAAC;IACtC,KAAK,MAAM,aAAa,IAAI,WAAW,EAAE,CAAC;QACxC,IAAI,MAAM,uBAAuB,CAAC,gBAAgB,CAAC,aAAa,EAAE,iBAAiB,CAAC,EAAE,CAAC;YACrF,iBAAiB,GAAG,aAAa,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,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 { assert, Id64String } from \"@itwin/core-bentley\";\nimport {\n GenericInstanceFilter,\n GenericInstanceFilterRelationshipStep,\n GenericInstanceFilterRule,\n GenericInstanceFilterRuleGroup,\n GenericInstanceFilterRuleGroupOperator,\n GenericInstanceFilterRuleOperator,\n GenericInstanceFilterRuleValue,\n} from \"@itwin/core-common\";\nimport { EC, ECClassHierarchyInspector, ECSchemaProvider, ECSql, getClass, parseFullClassName, PrimitiveValue } from \"@itwin/presentation-shared\";\n\n/**\n * Column names of the SELECT clause created by `NodeSelectClauseFactory`. Order of the names matches the order of columns\n * created by the factory.\n *\n * @beta\n */\nexport enum NodeSelectClauseColumnNames {\n /** Full class name of the instance the node represents. Type: `string` in format `{schema name}:{class name}`. */\n FullClassName = \"FullClassName\",\n /** ECInstance ID of the instance the node represents. Type: `Id64String`. */\n ECInstanceId = \"ECInstanceId\",\n /** Display label. Type: `string`. */\n DisplayLabel = \"DisplayLabel\",\n /**\n * A flag indicating if the node has children. Type: `boolean`. Values:\n * - `false` - node never has children.\n * - `true` - node always has children.\n * - NULL - unknown, needs to be determined by requesting children for the node.\n */\n HasChildren = \"HasChildren\",\n /** A flag indicating that a node should be hidden if it has no children. Type: `boolean`. */\n HideIfNoChildren = \"HideIfNoChildren\",\n /** A flag indicating that a node should be hidden and its children should be displayed instead. Type: `boolean`. */\n HideNodeInHierarchy = \"HideNodeInHierarchy\",\n /** A serialized JSON object for providing grouping information. */\n Grouping = \"Grouping\",\n /** A serialized JSON object for associating a node with additional data. */\n ExtendedData = \"ExtendedData\",\n /** A flag indicating the node should be auto-expanded when it's loaded. */\n AutoExpand = \"AutoExpand\",\n /** A flag indicating the node supports child hierarchy level filtering. */\n SupportsFiltering = \"SupportsFiltering\",\n}\n\n/**\n * A data structure for defining an ECSQL value selector.\n */\ninterface ECSqlValueSelector {\n selector: string;\n}\n\n/**\n * Props for `NodeSelectClauseFactory.createSelectClause`.\n */\ninterface NodeSelectClauseProps {\n ecClassId: Id64String | ECSqlValueSelector;\n ecInstanceId: Id64String | ECSqlValueSelector;\n nodeLabel: string | ECSqlValueSelector;\n extendedData?: {\n [key: string]: Id64String | string | number | boolean | ECSqlValueSelector;\n };\n autoExpand?: boolean | ECSqlValueSelector;\n supportsFiltering?: boolean | ECSqlValueSelector;\n hasChildren?: boolean | ECSqlValueSelector;\n hideNodeInHierarchy?: boolean | ECSqlValueSelector;\n hideIfNoChildren?: boolean | ECSqlValueSelector;\n grouping?: ECSqlSelectClauseGroupingParams;\n}\n\n/**\n * A data structure for defining nodes' grouping requirements.\n */\ninterface ECSqlSelectClauseGroupingParams {\n byLabel?: ECSqlSelectClauseLabelGroupingParams;\n byClass?: boolean | ECSqlSelectClauseGroupingParamsBase | ECSqlValueSelector;\n byBaseClasses?: ECSqlSelectClauseBaseClassGroupingParams;\n byProperties?: ECSqlSelectClausePropertiesGroupingParams;\n}\n\n/**\n * A data structure for defining label grouping params.\n */\ninterface ECSqlSelectClauseLabelGroupingBaseParams {\n /** Label grouping option that determines whether to group nodes or to merge them. Defaults to \"group\".*/\n action?: \"group\" | \"merge\";\n /** Id that needs to match for nodes to be grouped or merged.*/\n groupId?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining label merging.\n */\ninterface ECSqlSelectClauseLabelGroupingMergeParams extends ECSqlSelectClauseLabelGroupingBaseParams {\n action: \"merge\";\n}\n\n/**\n * A data structure for defining label grouping.\n */\ninterface ECSqlSelectClauseLabelGroupingGroupParams extends ECSqlSelectClauseLabelGroupingBaseParams, ECSqlSelectClauseGroupingParamsBase {\n action?: \"group\";\n}\n\n/**\n * A data structure for defining possible label grouping types.\n */\ntype ECSqlSelectClauseLabelGroupingParams =\n | boolean\n | ECSqlValueSelector\n | ECSqlSelectClauseLabelGroupingMergeParams\n | ECSqlSelectClauseLabelGroupingGroupParams;\n\n/**\n * A data structure for defining base grouping parameters shared across all types of grouping.\n */\ninterface ECSqlSelectClauseGroupingParamsBase {\n hideIfNoSiblings?: boolean | ECSqlValueSelector;\n hideIfOneGroupedNode?: boolean | ECSqlValueSelector;\n autoExpand?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining properties grouping.\n */\ninterface ECSqlSelectClausePropertiesGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n /**\n * Full name of a class whose properties are used to group the node. Only has effect if the node\n * represents an instance of that class.\n *\n * Full class name format: `SchemaName.ClassName`.\n */\n propertiesClassName: string;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value is not set or is set to an empty string.\n *\n * Label of the created grouping node will be `Not Specified`.\n */\n createGroupForUnspecifiedValues?: boolean | ECSqlValueSelector;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value doesn't fit within any of the provided\n * ranges, or is not a numeric value.\n *\n * Label of the created grouping node will be `Other`.\n */\n createGroupForOutOfRangeValues?: boolean | ECSqlValueSelector;\n /**\n * Properties of the specified class, by which the nodes should be grouped.\n *\n * Example usage:\n * ```ts\n * propertyGroups: [\n * {\n * propertyName: \"type\",\n * propertyClassAlias: \"this\"\n * },\n * {\n * propertyName: \"length\",\n * propertyClassAlias: \"x\",\n * ranges: [\n * { fromValue: 1, toValue: 10, rangeLabel: \"Small\" },\n * { fromValue: 11, toValue: 20, rangeLabel: \"Medium\" }\n * ]\n * },\n * ]\n * ```\n */\n propertyGroups: ECSqlSelectClausePropertyGroup[];\n}\n\n/**\n * A data structure for defining specific properties' grouping params.\n */\ninterface ECSqlSelectClausePropertyGroup {\n /** A string indicating the name of the property to group by. */\n propertyName: string;\n /** Alias to of the class containing the property. Used to select the property value. */\n propertyClassAlias: string;\n /** Ranges are used to group nodes by numeric properties which are within specified bounds. */\n ranges?: ECSqlSelectClausePropertyValueRange[];\n}\n\n/**\n * A data structure for defining boundaries for a value.\n */\ninterface ECSqlSelectClausePropertyValueRange {\n /** Defines the lower bound of the range. */\n fromValue: number | ECSqlValueSelector;\n /** Defines the upper bound of the range. */\n toValue: number | ECSqlValueSelector;\n /** Defines the range label. Will be used as grouping node's display label. */\n rangeLabel?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining base class grouping.\n */\ninterface ECSqlSelectClauseBaseClassGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n fullClassNames: string[] | ECSqlValueSelector[];\n}\n\n/**\n * An interface of a factory that knows how to create nodes' select ECSQL query.\n * @beta\n */\nexport interface NodesQueryClauseFactory {\n /** Create a SELECT clause in a format understood by nodes query parser used by `HierarchyProvider`. */\n createSelectClause(props: NodeSelectClauseProps): Promise<string>;\n\n /** Create FROM, JOIN and WHERE clauses whose combination results in an ECSQL filter defined by given `GenericInstanceFilter`. */\n createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }>;\n}\n\n/**\n * Creates an instance of `NodeSelectQueryFactory` that .\n * @beta\n */\nexport function createNodesQueryClauseFactory(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }): NodesQueryClauseFactory {\n return new NodeSelectQueryFactory(props);\n}\n\n/** A factory for creating a nodes' select ECSQL query. */\nclass NodeSelectQueryFactory {\n private _imodelAccess: ECSchemaProvider & ECClassHierarchyInspector;\n\n public constructor(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }) {\n this._imodelAccess = props.imodelAccess;\n }\n\n /** Create a SELECT clause in a format understood by results reader of the library. */\n public async createSelectClause(props: NodeSelectClauseProps) {\n // note: the columns order must match the order in `NodeSelectClauseColumnNames`\n return `\n ec_ClassName(${createECSqlValueSelector(props.ecClassId)}) AS ${NodeSelectClauseColumnNames.FullClassName},\n ${createECSqlValueSelector(props.ecInstanceId)} AS ${NodeSelectClauseColumnNames.ECInstanceId},\n ${createECSqlValueSelector(props.nodeLabel)} AS ${NodeSelectClauseColumnNames.DisplayLabel},\n CAST(${createECSqlValueSelector(props.hasChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HasChildren},\n CAST(${createECSqlValueSelector(props.hideIfNoChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideIfNoChildren},\n CAST(${createECSqlValueSelector(props.hideNodeInHierarchy)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideNodeInHierarchy},\n ${props.grouping ? createGroupingSelector(props.grouping) : \"CAST(NULL AS TEXT)\"} AS ${NodeSelectClauseColumnNames.Grouping},\n ${\n props.extendedData\n ? `json_object(${Object.entries(props.extendedData)\n .map(([key, value]) => `'${key}', ${createECSqlValueSelector(value)}`)\n .join(\", \")})`\n : \"CAST(NULL AS TEXT)\"\n } AS ${NodeSelectClauseColumnNames.ExtendedData},\n CAST(${createECSqlValueSelector(props.autoExpand)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.AutoExpand},\n CAST(${createECSqlValueSelector(props.supportsFiltering)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.SupportsFiltering}\n `;\n }\n\n /**\n * Creates the necessary ECSQL snippets to create an instance filter described by the `def` argument.\n * - `from` is set to either the `contentClass.fullName` or `def.propertyClassName`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `def.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `def.filterClassNames` and by properties as described by `def.rules`.\n *\n * Special cases:\n * - If `def` is `undefined`, `joins` and `where` are set to empty strings and `from` is set to `contentClass.fullName`.\n * - If the provided content class doesn't intersect with the property class in provided filter, a special result\n * is returned to make sure the resulting query is valid and doesn't return anything.\n */\n public async createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }> {\n const { contentClass, filter } = props;\n if (!filter) {\n // undefined filter means we don't want any filtering to be applied\n return { from: contentClass.fullName, joins: \"\", where: \"\" };\n }\n\n const from = await specializeContentClass({\n classHierarchyInspector: this._imodelAccess,\n contentClassName: contentClass.fullName,\n filterClassNames: filter.propertyClassNames,\n });\n if (!from) {\n // filter class doesn't intersect with content class - make sure the query returns nothing by returning a `FALSE` WHERE clause\n return { from: contentClass.fullName, joins: \"\", where: \"FALSE\" };\n }\n\n /**\n * TODO:\n * There may be similar related instance paths, e.g.:\n * - A -> B -> C,\n * - A -> B -> D.\n * At this moment we're handling each path individually which means A and B would get joined twice. We could look into\n * creating a join tree first, e.g.\n * C\n * /\n * A -> B\n * \\\n * D\n */\n const joins = await Promise.all(\n filter.relatedInstances.map(async (rel, i) =>\n ECSql.createRelationshipPathJoinClause({\n schemaProvider: this._imodelAccess,\n path: assignRelationshipPathAliases(rel.path, i, contentClass.alias, rel.alias),\n }),\n ),\n );\n\n const whereConditions = new Array<string>();\n if (filter.filteredClassNames && filter.filteredClassNames.length > 0) {\n whereConditions.push(\n `${ECSql.createRawPropertyValueSelector(contentClass.alias, \"ECClassId\")} IS (\n ${filter.filteredClassNames\n .map(parseFullClassName)\n .map(({ schemaName, className }) => `[${schemaName}].[${className}]`)\n .join(\", \")}\n )`,\n );\n }\n const classAliasMap = new Map<string, string>([[contentClass.alias, from]]);\n filter.relatedInstances.forEach(({ path, alias }) => path.length > 0 && classAliasMap.set(alias, path[path.length - 1].targetClassName));\n const propertiesFilter = await createWhereClause(\n contentClass.alias,\n async (alias) => {\n const aliasClassName = classAliasMap.get(alias);\n return aliasClassName ? getClass(this._imodelAccess, aliasClassName) : undefined;\n },\n filter.rules,\n );\n if (propertiesFilter) {\n whereConditions.push(propertiesFilter);\n }\n\n return {\n from,\n joins: joins.join(\"\\n\"),\n where: whereConditions.join(\" AND \"),\n };\n }\n}\n\nfunction createECSqlValueSelector(input: undefined | PrimitiveValue | ECSqlValueSelector) {\n if (input === undefined) {\n return \"NULL\";\n }\n if (isSelector(input)) {\n return input.selector;\n }\n return ECSql.createRawPrimitiveValueSelector(input);\n}\n\nfunction isSelector(x: any): x is ECSqlValueSelector {\n return !!x.selector;\n}\n\nfunction createGroupingSelector(grouping: ECSqlSelectClauseGroupingParams): string {\n const groupingSelectors = new Array<{ key: string; selector: string }>();\n\n grouping.byLabel &&\n groupingSelectors.push({\n key: \"byLabel\",\n selector:\n typeof grouping.byLabel === \"boolean\" || isSelector(grouping.byLabel)\n ? createECSqlValueSelector(grouping.byLabel)\n : serializeJsonObject(createLabelGroupingBaseParamsSelectors(grouping.byLabel)),\n });\n\n grouping.byClass &&\n groupingSelectors.push({\n key: \"byClass\",\n selector:\n typeof grouping.byClass === \"boolean\" || isSelector(grouping.byClass)\n ? createECSqlValueSelector(grouping.byClass)\n : serializeJsonObject(createBaseGroupingParamSelectors(grouping.byClass)),\n });\n\n grouping.byBaseClasses &&\n groupingSelectors.push({\n key: \"byBaseClasses\",\n selector: serializeJsonObject([\n {\n key: \"fullClassNames\",\n selector: `json_array(${grouping.byBaseClasses.fullClassNames.map((className) => createECSqlValueSelector(className)).join(\", \")})`,\n },\n ...createBaseGroupingParamSelectors(grouping.byBaseClasses),\n ]),\n });\n\n grouping.byProperties &&\n groupingSelectors.push({\n key: \"byProperties\",\n selector: serializeJsonObject([\n {\n key: \"propertiesClassName\",\n selector: `${createECSqlValueSelector(grouping.byProperties.propertiesClassName)}`,\n },\n {\n key: \"propertyGroups\",\n selector: `json_array(${grouping.byProperties.propertyGroups\n .map((propertyGroup) => serializeJsonObject(createPropertyGroupSelectors(propertyGroup)))\n .join(\", \")})`,\n },\n ...(grouping.byProperties.createGroupForOutOfRangeValues !== undefined\n ? [\n {\n key: \"createGroupForOutOfRangeValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForOutOfRangeValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...(grouping.byProperties.createGroupForUnspecifiedValues !== undefined\n ? [\n {\n key: \"createGroupForUnspecifiedValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForUnspecifiedValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...createBaseGroupingParamSelectors(grouping.byProperties),\n ]),\n });\n\n return serializeJsonObject(groupingSelectors);\n}\n\nfunction createLabelGroupingBaseParamsSelectors(byLabel: ECSqlSelectClauseLabelGroupingMergeParams | ECSqlSelectClauseLabelGroupingGroupParams) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (byLabel.action !== undefined) {\n selectors.push({\n key: \"action\",\n selector: `${createECSqlValueSelector(byLabel.action)}`,\n });\n }\n if (byLabel.groupId !== undefined) {\n selectors.push({\n key: \"groupId\",\n selector: createECSqlValueSelector(byLabel.groupId),\n });\n }\n if (byLabel.action !== \"merge\") {\n selectors.push(...createBaseGroupingParamSelectors(byLabel));\n }\n\n return selectors;\n}\n\nfunction createPropertyGroupSelectors(propertyGroup: ECSqlSelectClausePropertyGroup) {\n const selectors = new Array<{ key: string; selector: string }>();\n selectors.push(\n {\n key: \"propertyName\",\n selector: `${createECSqlValueSelector(propertyGroup.propertyName)}`,\n },\n {\n key: \"propertyValue\",\n selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,\n },\n );\n if (propertyGroup.ranges) {\n selectors.push(createRangeParamSelectors(propertyGroup.ranges));\n }\n return selectors;\n}\n\nfunction createRangeParamSelectors(ranges: ECSqlSelectClausePropertyValueRange[]) {\n return {\n key: \"ranges\",\n selector: `json_array(${ranges\n .map((range) =>\n serializeJsonObject([\n {\n key: \"fromValue\",\n selector: createECSqlValueSelector(range.fromValue),\n },\n {\n key: \"toValue\",\n selector: createECSqlValueSelector(range.toValue),\n },\n ...(range.rangeLabel\n ? [\n {\n key: \"rangeLabel\",\n selector: `${createECSqlValueSelector(range.rangeLabel)}`,\n },\n ]\n : []),\n ]),\n )\n .join(\", \")})`,\n };\n}\n\nfunction createBaseGroupingParamSelectors(params: ECSqlSelectClauseGroupingParamsBase) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (params.hideIfNoSiblings !== undefined) {\n selectors.push({\n key: \"hideIfNoSiblings\",\n selector: createECSqlValueSelector(params.hideIfNoSiblings),\n });\n }\n if (params.hideIfOneGroupedNode !== undefined) {\n selectors.push({\n key: \"hideIfOneGroupedNode\",\n selector: createECSqlValueSelector(params.hideIfOneGroupedNode),\n });\n }\n if (params.autoExpand !== undefined) {\n selectors.push({\n key: \"autoExpand\",\n selector: createECSqlValueSelector(params.autoExpand),\n });\n }\n return selectors;\n}\n\nfunction serializeJsonObject(selectors: Array<{ key: string; selector: string }>): string {\n return `json_object(${selectors.map(({ key, selector }) => `'${key}', ${selector}`).join(\", \")})`;\n}\n\nasync function createWhereClause(\n contentClassAlias: string,\n classLoader: (alias: string) => Promise<EC.Class | undefined>,\n rule: GenericInstanceFilterRule | GenericInstanceFilterRuleGroup,\n): Promise<string | undefined> {\n if (GenericInstanceFilter.isFilterRuleGroup(rule)) {\n const clause = (await Promise.all(rule.rules.map(async (r) => createWhereClause(contentClassAlias, classLoader, r))))\n .filter((c) => !!c)\n .join(` ${getECSqlLogicalOperator(rule.operator)} `);\n return clause ? (rule.operator === \"or\" ? `(${clause})` : clause) : undefined;\n }\n const sourceAlias = rule.sourceAlias ? rule.sourceAlias : contentClassAlias;\n const propertyValueSelector = ECSql.createRawPropertyValueSelector(sourceAlias, rule.propertyName);\n if (isUnaryRuleOperator(rule.operator)) {\n switch (rule.operator) {\n case \"is-true\":\n return propertyValueSelector;\n case \"is-false\":\n return `NOT ${propertyValueSelector}`;\n case \"is-null\":\n return `${propertyValueSelector} IS NULL`;\n case \"is-not-null\":\n return `${propertyValueSelector} IS NOT NULL`;\n }\n }\n const ecsqlOperator = getECSqlComparisonOperator(rule.operator);\n if (rule.value === undefined) {\n throw new Error(`Rule \"${rule.propertyName}\" ${ecsqlOperator} is missing value.`);\n }\n\n const value = rule.value.rawValue;\n\n if (rule.operator === \"like\" && typeof value === \"string\") {\n const escapedValue = value.replace(/[%_\\\\]/g, \"\\\\$&\");\n return `${propertyValueSelector} ${ecsqlOperator} '%${escapedValue}%' ESCAPE '\\\\'`;\n }\n const propertyClass = await classLoader(sourceAlias);\n if (!propertyClass) {\n throw new Error(`Class with alias \"${sourceAlias}\" not found.`);\n }\n const property = await propertyClass.getProperty(rule.propertyName);\n if (!property) {\n throw new Error(`Property \"${rule.propertyName}\" not found in ECClass \"${propertyClass.fullName}\".`);\n }\n if (property.isNavigation()) {\n assert(rule.value !== undefined && GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector}.[Id] ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value.id)}`;\n }\n if (property.isEnumeration()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n if (property.isPrimitive()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n switch (property.primitiveType) {\n case \"Point2d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint2d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Point3d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint3d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[z]`, \"is-equal\", value.z)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Double\": {\n assert(typeof value === \"number\");\n if (rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\") {\n return `${createFloatingPointEqualityClause(propertyValueSelector, rule.operator, value)}`;\n }\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n default: {\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n }\n }\n throw new Error(\"Struct and array properties are not supported for filtering\");\n}\n\nfunction createFloatingPointEqualityClause(valueSelector: string, operator: \"is-equal\" | \"is-not-equal\", value: number) {\n const [from, to] = getFloatingPointValueRange(value);\n return `${valueSelector} ${operator === \"is-not-equal\" ? \"NOT \" : \"\"} BETWEEN ${from} AND ${to}`;\n}\n\nfunction getFloatingPointValueRange(value: number): [number, number] {\n return [value - Number.EPSILON, value + Number.EPSILON];\n}\n\nfunction getECSqlLogicalOperator(op: GenericInstanceFilterRuleGroupOperator) {\n switch (op) {\n case \"and\":\n return \"AND\";\n case \"or\":\n return \"OR\";\n }\n}\n\nfunction isUnaryRuleOperator(\n op: GenericInstanceFilterRuleOperator,\n): op is Extract<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\"> {\n return op === \"is-true\" || op === \"is-false\" || op === \"is-null\" || op === \"is-not-null\";\n}\n\nfunction getECSqlComparisonOperator(op: Exclude<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\">) {\n switch (op) {\n case \"is-equal\":\n return `=`;\n case \"is-not-equal\":\n return `<>`;\n case \"greater\":\n return `>`;\n case \"greater-or-equal\":\n return `>=`;\n case \"less\":\n return `<`;\n case \"less-or-equal\":\n return `<=`;\n case \"like\":\n return `LIKE`;\n }\n}\n\ntype JoinRelationshipPath = Parameters<typeof ECSql.createRelationshipPathJoinClause>[0][\"path\"];\nfunction assignRelationshipPathAliases(\n path: GenericInstanceFilterRelationshipStep[],\n pathIndex: number,\n sourceAlias: string,\n targetAlias: string,\n): JoinRelationshipPath {\n function createAlias(fullClassName: string, index: number) {\n return `rel_${pathIndex}_${fullClassName.replaceAll(/[\\.:]/g, \"_\")}_${index}`;\n }\n const result: JoinRelationshipPath = [];\n path.forEach((step, i) => {\n result.push({\n targetClassName: step.targetClassName,\n relationshipName: step.relationshipClassName,\n sourceClassName: step.sourceClassName,\n relationshipReverse: !step.isForwardRelationship,\n sourceAlias: i === 0 ? sourceAlias : result[i - 1].targetAlias,\n relationshipAlias: createAlias(step.relationshipClassName, i),\n targetAlias: i === path.length - 1 ? targetAlias : createAlias(step.targetClassName, i),\n joinType: \"inner\",\n });\n });\n return result;\n}\n\ninterface SpecializeContentClassProps {\n classHierarchyInspector: ECClassHierarchyInspector;\n contentClassName: string;\n filterClassNames: string[];\n}\nasync function specializeContentClass(props: SpecializeContentClassProps): Promise<string | undefined> {\n const filterClass = await getSpecializedPropertyClass(props.classHierarchyInspector, props.filterClassNames);\n if (!filterClass) {\n return props.contentClassName;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(filterClass, props.contentClassName)) {\n return filterClass;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(props.contentClassName, filterClass)) {\n return props.contentClassName;\n }\n return undefined;\n}\n\nasync function getSpecializedPropertyClass(classHierarchyInspector: ECClassHierarchyInspector, classes: string[]): Promise<string | undefined> {\n if (classes.length === 0) {\n return undefined;\n }\n const [currClassName, ...restClasses] = classes;\n let resolvedClassName = currClassName;\n for (const propClassName of restClasses) {\n if (await classHierarchyInspector.classDerivesFrom(propClassName, resolvedClassName)) {\n resolvedClassName = propClassName;\n }\n }\n return resolvedClassName;\n}\n"]}
@@ -157,6 +157,24 @@ interface InstancesNodeChildHierarchyLevelDefinition {
157
157
  * Called to create a hierarchy level definition when the class check passes (see `parentNodeClassName`).
158
158
  */
159
159
  definitions: (requestProps: DefineInstanceNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;
160
+ /**
161
+ * If set to true, and node matches at least one of the previous definitions, this definition will not be applied.
162
+ *
163
+ * For example:
164
+ * ```ts
165
+ * {
166
+ * parentNodeClassName: "BisCore.GeometricElement3d",
167
+ * definitions: () => ...,
168
+ * },
169
+ * // This will apply to all elements, that are not BisCore.GeometricElement3d
170
+ * {
171
+ * parentNodeClassName: "BisCore.Element",
172
+ * onlyIfNotHandled: true,
173
+ * definitions: () => ...,
174
+ * }
175
+ * ```
176
+ */
177
+ onlyIfNotHandled?: boolean;
160
178
  }
161
179
  /**
162
180
  * Props for defining child hierarchy level for specific parent custom node.
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyDefinition.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAe,MAAM,4BAA4B,CAAC;AACnG,OAAO,EAEL,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,oEAAoE;AACpE,MAAM,WAAW,6BAA6B;IAC5C,oDAAoD;IACpD,IAAI,EAAE,yBAAyB,CAAC;CACjC;AAED,yFAAyF;AACzF,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,aAAa,EAAE,MAAM,CAAC;IAC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CAAC,wBAAwB,CAAC,CAAC;QAEvF;;;WAGG;QACH,UAAU,EAAE,kCAAkC,EAAE,CAAC;KAClD,CAAC;CACH;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,kCAAkC,GAAG,mBAAmB,CAElH"}
@@ -3,6 +3,7 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { HierarchyNode, } from "./HierarchyNode";
6
+ import { concatMap, filter, firstValueFrom, from, mergeAll, mergeMap, toArray } from "rxjs";
6
7
  /** @beta */
7
8
  // eslint-disable-next-line @typescript-eslint/no-redeclare
8
9
  export var HierarchyNodesDefinition;
@@ -62,12 +63,13 @@ class ClassBasedHierarchyDefinition {
62
63
  }
63
64
  }
64
65
  async function createHierarchyLevelDefinitions(classHierarchy, defs, requestProps) {
65
- return (await Promise.all(defs.map(async (def) => {
66
+ const obs = from(defs).pipe(mergeMap(async (def, idx) => {
66
67
  if (await classHierarchy.classDerivesFrom(requestProps.parentNodeClassName, def.parentNodeClassName)) {
67
- return def.definitions(requestProps);
68
+ return { def, idx };
68
69
  }
69
- return [];
70
- }))).flat();
70
+ return undefined;
71
+ }), filter((x) => !!x), toArray(), concatMap((x) => x.sort((a, b) => a.idx - b.idx).map(({ def }) => def)), filter((def, idx) => !def.onlyIfNotHandled || idx === 0), mergeMap(async (def) => def.definitions(requestProps)), mergeAll());
72
+ return firstValueFrom(obs.pipe(toArray()));
71
73
  }
72
74
  function groupInstanceIdsByClass(instanceKeys) {
73
75
  const instanceIdsByClass = new Map();
@@ -1 +1 @@
1
- {"version":3,"file":"HierarchyDefinition.js","sourceRoot":"","sources":["../../../src/hierarchies/HierarchyDefinition.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAKhG,OAAO,EACL,aAAa,GAOd,MAAM,iBAAiB,CAAC;AA6BzB,YAAY;AACZ,2DAA2D;AAC3D,MAAM,KAAW,wBAAwB,CAOxC;AAPD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,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAC3B,IAAI,WAAW,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,WAAW,GAAG,EAAE,CAAC;YACjB,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;QACD,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,yCAAyC,CAAC,GAAuC;IACxF,OAAO,CAAC,CAAE,GAA+C,CAAC,mBAAmB,CAAC;AAChF,CAAC;AAED,SAAS,4CAA4C,CAAC,GAAuC;IAC3F,OAAO,CAAC,CAAE,GAAkD,CAAC,mBAAmB,CAAC;AACnF,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 { GenericInstanceFilter } from \"@itwin/core-common\";\nimport { ECClassHierarchyInspector, ECSqlQueryDef, InstanceKey } from \"@itwin/presentation-shared\";\nimport {\n HierarchyNode,\n NonGroupingHierarchyNode,\n ParsedCustomHierarchyNode,\n ParsedInstanceHierarchyNode,\n ProcessedCustomHierarchyNode,\n ProcessedHierarchyNode,\n ProcessedInstanceHierarchyNode,\n} from \"./HierarchyNode\";\nimport { InstancesNodeKey } from \"./HierarchyNodeKey\";\n\n/** A nodes definition that returns a single custom defined node. */\nexport interface CustomHierarchyNodeDefinition {\n /** The node to be created in the hierarchy level */\n node: ParsedCustomHierarchyNode;\n}\n\n/** A nodes definition that returns an ECSQL query for selecting nodes from an iModel. */\nexport interface InstanceNodesQueryDefinition {\n /**\n * Full name of the class whose instances are going to be returned. It's okay if the attribute\n * points to a base class of multiple different classes of instances returned by the query, however\n * the more specific this class is, the more efficient hierarchy building process is.\n */\n fullClassName: string;\n /**\n * An ECSQL query that selects nodes from an iModel. `SELECT` clause of the query is expected\n * to be built using `NodeSelectQueryFactory.createSelectClause`.\n */\n query: ECSqlQueryDef;\n}\n\n/**\n * A definition of nodes included in a hierarchy level.\n * @beta\n */\nexport type HierarchyNodesDefinition = CustomHierarchyNodeDefinition | InstanceNodesQueryDefinition;\n/** @beta */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace HierarchyNodesDefinition {\n export function isCustomNode(def: HierarchyNodesDefinition): def is CustomHierarchyNodeDefinition {\n return !!(def as CustomHierarchyNodeDefinition).node;\n }\n export function isInstanceNodesQuery(def: HierarchyNodesDefinition): def is InstanceNodesQueryDefinition {\n return !!(def as InstanceNodesQueryDefinition).query;\n }\n}\n\n/**\n * A definition of a hierarchy level, which may consist of multiple node definitions.\n * @beta\n */\nexport type HierarchyLevelDefinition = HierarchyNodesDefinition[];\n\n/**\n * A type for a function that parses a `ParsedInstanceHierarchyNode` from provided ECSQL `row` object.\n * @beta\n */\nexport type NodeParser = (row: { [columnName: string]: any }) => ParsedInstanceHierarchyNode;\n\n/**\n * A type for a function that pre-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one. Returning `undefined` omits the node\n * from the hierarchy.\n *\n * @beta\n */\nexport type NodePreProcessor = <TNode extends ProcessedCustomHierarchyNode | ProcessedInstanceHierarchyNode>(node: TNode) => Promise<TNode | undefined>;\n\n/**\n * A type for a function that post-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one.\n *\n * @beta\n */\nexport type NodePostProcessor = (node: ProcessedHierarchyNode) => Promise<ProcessedHierarchyNode>;\n\n/**\n * A type of node that can be passed to `HierarchyDefinition.defineHierarchyLevel`. This basically means\n * a `HierarchyNode` that:\n * - knows nothing about its children,\n * - is either an instances node (key is of `InstancesNodeKey` type) or a custom node (key is of `string` type).\n */\ntype HierarchyDefinitionParentNode = Omit<NonGroupingHierarchyNode, \"children\">;\n\n/**\n * Props for `HierarchyDefinition.defineHierarchyLevel`.\n * @beta\n */\nexport interface DefineHierarchyLevelProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: HierarchyDefinitionParentNode | undefined;\n\n /** Optional hierarchy level filter. */\n instanceFilter?: GenericInstanceFilter;\n}\n\n/**\n * An interface for a factory that knows how define a hierarchy based on a given parent node.\n * @beta\n */\nexport interface HierarchyDefinition {\n /**\n * An optional function for parsing ECInstance node from ECSQL row.\n *\n * Should be used in situations when the `HierarchyDefinition` implementation\n * introduces additional ECSQL columns into the select clause and wants to assign additional\n * data to the nodes it produces.\n *\n * Defaults to a function that parses all `HierarchyNode` attributes from a query, whose SELECT\n * clause is created using `NodeSelectQueryFactory.createSelectClause`.\n */\n parseNode?: NodeParser;\n\n /**\n * An optional function for pre-processing nodes.\n *\n * Pre-processing happens immediately after the nodes are loaded based on `HierarchyLevelDefinition`\n * returned by this `HierarchyDefinition` and before their processing (hiding, grouping, sorting, etc.) starts.\n * The step allows assigning nodes additional data or excluding them from the hierarchy based on some attributes.\n */\n preProcessNode?: NodePreProcessor;\n\n /**\n * An optional function for post-processing nodes.\n *\n * Post-processing happens after the loaded nodes go through all the merging, hiding and grouping\n * steps, but before sorting them. This step allows `HierarchyDefinition` implementations to assign additional data\n * to nodes after they're processed. This is especially true for grouping nodes as they're only created during\n * processing.\n */\n postProcessNode?: NodePostProcessor;\n\n /** A function to create a hierarchy level definition for given parent node. */\n defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent instance node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineInstanceNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent instance node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: InstancesNodeKey };\n\n /**\n * Full name of the parent instance node class.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeClassName: string;\n\n /**\n * ECInstanceIds of the parent instance node.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeInstanceIds: Id64String[];\n};\n\n/**\n * A definition of a hierarchy level that should be used for specific class of parent instance nodes.\n */\ninterface InstancesNodeChildHierarchyLevelDefinition {\n /**\n * Full name of the parent instance node's class to match against when checking if this hierarchy\n * level should be used for specific parent instance node.\n *\n * The check is polymorphic, so `BisCore.Element` class would match `BisCore.GeometricElement`, `BisCore.Category` and\n * all other element classes.\n */\n parentNodeClassName: string;\n\n /**\n * Called to create a hierarchy level definition when the class check passes (see `parentNodeClassName`).\n */\n definitions: (requestProps: DefineInstanceNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent custom node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineCustomNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent custom node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: string };\n};\n\n/**\n * A definition of a hierarchy level for that should be used for specific custom parent nodes.\n */\ninterface CustomNodeChildHierarchyLevelDefinition {\n /**\n * `HierarchyNode.key` of the custom node that this child hierarchy level definition should be used for.\n */\n customParentNodeKey: string;\n\n /**\n * Called to create a hierarchy level definition when the node key check passes (see `customParentNodeKey`).\n */\n definitions: (requestProps: DefineCustomNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * A hierarchy level definition associated with either parent instance node's class or custom\n * node's key.\n */\ntype ClassBasedHierarchyLevelDefinition = InstancesNodeChildHierarchyLevelDefinition | CustomNodeChildHierarchyLevelDefinition;\n\n/**\n * Props for defining root hierarchy level.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineRootHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\">;\n\n/**\n * Props for `createClassBasedHierarchyDefinition`.\n */\ninterface ClassBasedHierarchyDefinitionProps {\n /** Access to ECClass hierarchy in the iModel */\n classHierarchyInspector: ECClassHierarchyInspector;\n\n /** Hierarchy level definitions based on parent instance node's class or custom node's key. */\n hierarchy: {\n /** Called to create the root hierarchy level definition. */\n rootNodes: (props: DefineRootHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n\n /**\n * Called to get child hierarchy level definitions based on parent instance node's class\n * or custom node's key.\n */\n childNodes: ClassBasedHierarchyLevelDefinition[];\n };\n}\n\n/**\n * Creates an instance of `HierarchyDefinition` that uses a somewhat declarative approach to define the\n * hierarchy - each hierarchy level is assigned either an instance node's class or custom node's\n * key and they're used to assign hierarchy level definitions based on parent node.\n *\n * @beta\n */\nexport function createClassBasedHierarchyDefinition(props: ClassBasedHierarchyDefinitionProps): HierarchyDefinition {\n return new ClassBasedHierarchyDefinition(props);\n}\n\nclass ClassBasedHierarchyDefinition implements HierarchyDefinition {\n public constructor(private _props: ClassBasedHierarchyDefinitionProps) {}\n\n /**\n * Create hierarchy level definitions for specific hierarchy level.\n * @param parentNode Parent node to create children definitions for.\n */\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const { parentNode } = props;\n if (!parentNode) {\n return this._props.hierarchy.rootNodes(props);\n }\n\n if (HierarchyNode.isCustom(parentNode)) {\n const defs = this._props.hierarchy.childNodes\n .filter(isCustomNodeChildHierarchyLevelDefinition)\n .filter((def) => def.customParentNodeKey === parentNode.key);\n return (await Promise.all(defs.map(async (def) => def.definitions({ ...props, parentNode })))).flat();\n }\n\n // istanbul ignore else\n if (HierarchyNode.isInstancesNode(parentNode)) {\n const instanceIdsByClass = groupInstanceIdsByClass(parentNode.key.instanceKeys);\n const instancesParentNodeDefs = this._props.hierarchy.childNodes.filter(isInstancesNodeChildHierarchyLevelDefinition);\n return (\n await Promise.all(\n [...instanceIdsByClass.entries()].map(async ([parentNodeClassName, parentNodeInstanceIds]) =>\n createHierarchyLevelDefinitions(this._props.classHierarchyInspector, instancesParentNodeDefs, {\n ...props,\n parentNodeClassName,\n parentNodeInstanceIds,\n parentNode,\n }),\n ),\n )\n ).flat();\n }\n\n // istanbul ignore next\n return [];\n }\n}\n\nasync function createHierarchyLevelDefinitions(\n classHierarchy: ECClassHierarchyInspector,\n defs: InstancesNodeChildHierarchyLevelDefinition[],\n requestProps: DefineInstanceNodeChildHierarchyLevelProps,\n) {\n return (\n await Promise.all(\n defs.map(async (def) => {\n if (await classHierarchy.classDerivesFrom(requestProps.parentNodeClassName, def.parentNodeClassName)) {\n return def.definitions(requestProps);\n }\n return [];\n }),\n )\n ).flat();\n}\n\nfunction groupInstanceIdsByClass(instanceKeys: InstanceKey[]) {\n const instanceIdsByClass = new Map<string, Id64String[]>();\n instanceKeys.forEach((key) => {\n let instanceIds = instanceIdsByClass.get(key.className);\n if (!instanceIds) {\n instanceIds = [];\n instanceIdsByClass.set(key.className, instanceIds);\n }\n instanceIds.push(key.id);\n });\n return instanceIdsByClass;\n}\n\nfunction isCustomNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is CustomNodeChildHierarchyLevelDefinition {\n return !!(def as CustomNodeChildHierarchyLevelDefinition).customParentNodeKey;\n}\n\nfunction isInstancesNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is InstancesNodeChildHierarchyLevelDefinition {\n return !!(def as InstancesNodeChildHierarchyLevelDefinition).parentNodeClassName;\n}\n"]}
1
+ {"version":3,"file":"HierarchyDefinition.js","sourceRo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AAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAED,SAAS,yCAAyC,CAAC,GAAuC;IACxF,OAAO,CAAC,CAAE,GAA+C,CAAC,mBAAmB,CAAC;AAChF,CAAC;AAED,SAAS,4CAA4C,CAAC,GAAuC;IAC3F,OAAO,CAAC,CAAE,GAAkD,CAAC,mBAAmB,CAAC;AACnF,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 { GenericInstanceFilter } from \"@itwin/core-common\";\nimport { ECClassHierarchyInspector, ECSqlQueryDef, InstanceKey } from \"@itwin/presentation-shared\";\nimport {\n HierarchyNode,\n NonGroupingHierarchyNode,\n ParsedCustomHierarchyNode,\n ParsedInstanceHierarchyNode,\n ProcessedCustomHierarchyNode,\n ProcessedHierarchyNode,\n ProcessedInstanceHierarchyNode,\n} from \"./HierarchyNode\";\nimport { InstancesNodeKey } from \"./HierarchyNodeKey\";\nimport { concatMap, filter, firstValueFrom, from, mergeAll, mergeMap, toArray } from \"rxjs\";\n\n/** A nodes definition that returns a single custom defined node. */\nexport interface CustomHierarchyNodeDefinition {\n /** The node to be created in the hierarchy level */\n node: ParsedCustomHierarchyNode;\n}\n\n/** A nodes definition that returns an ECSQL query for selecting nodes from an iModel. */\nexport interface InstanceNodesQueryDefinition {\n /**\n * Full name of the class whose instances are going to be returned. It's okay if the attribute\n * points to a base class of multiple different classes of instances returned by the query, however\n * the more specific this class is, the more efficient hierarchy building process is.\n */\n fullClassName: string;\n /**\n * An ECSQL query that selects nodes from an iModel. `SELECT` clause of the query is expected\n * to be built using `NodeSelectQueryFactory.createSelectClause`.\n */\n query: ECSqlQueryDef;\n}\n\n/**\n * A definition of nodes included in a hierarchy level.\n * @beta\n */\nexport type HierarchyNodesDefinition = CustomHierarchyNodeDefinition | InstanceNodesQueryDefinition;\n/** @beta */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport namespace HierarchyNodesDefinition {\n export function isCustomNode(def: HierarchyNodesDefinition): def is CustomHierarchyNodeDefinition {\n return !!(def as CustomHierarchyNodeDefinition).node;\n }\n export function isInstanceNodesQuery(def: HierarchyNodesDefinition): def is InstanceNodesQueryDefinition {\n return !!(def as InstanceNodesQueryDefinition).query;\n }\n}\n\n/**\n * A definition of a hierarchy level, which may consist of multiple node definitions.\n * @beta\n */\nexport type HierarchyLevelDefinition = HierarchyNodesDefinition[];\n\n/**\n * A type for a function that parses a `ParsedInstanceHierarchyNode` from provided ECSQL `row` object.\n * @beta\n */\nexport type NodeParser = (row: { [columnName: string]: any }) => ParsedInstanceHierarchyNode;\n\n/**\n * A type for a function that pre-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one. Returning `undefined` omits the node\n * from the hierarchy.\n *\n * @beta\n */\nexport type NodePreProcessor = <TNode extends ProcessedCustomHierarchyNode | ProcessedInstanceHierarchyNode>(node: TNode) => Promise<TNode | undefined>;\n\n/**\n * A type for a function that post-processes given node. Unless the function decides not to make any modifications,\n * it should return a new - modified - node, rather than modifying the given one.\n *\n * @beta\n */\nexport type NodePostProcessor = (node: ProcessedHierarchyNode) => Promise<ProcessedHierarchyNode>;\n\n/**\n * A type of node that can be passed to `HierarchyDefinition.defineHierarchyLevel`. This basically means\n * a `HierarchyNode` that:\n * - knows nothing about its children,\n * - is either an instances node (key is of `InstancesNodeKey` type) or a custom node (key is of `string` type).\n */\ntype HierarchyDefinitionParentNode = Omit<NonGroupingHierarchyNode, \"children\">;\n\n/**\n * Props for `HierarchyDefinition.defineHierarchyLevel`.\n * @beta\n */\nexport interface DefineHierarchyLevelProps {\n /** Parent node to get children for. Pass `undefined` to get root nodes. */\n parentNode: HierarchyDefinitionParentNode | undefined;\n\n /** Optional hierarchy level filter. */\n instanceFilter?: GenericInstanceFilter;\n}\n\n/**\n * An interface for a factory that knows how define a hierarchy based on a given parent node.\n * @beta\n */\nexport interface HierarchyDefinition {\n /**\n * An optional function for parsing ECInstance node from ECSQL row.\n *\n * Should be used in situations when the `HierarchyDefinition` implementation\n * introduces additional ECSQL columns into the select clause and wants to assign additional\n * data to the nodes it produces.\n *\n * Defaults to a function that parses all `HierarchyNode` attributes from a query, whose SELECT\n * clause is created using `NodeSelectQueryFactory.createSelectClause`.\n */\n parseNode?: NodeParser;\n\n /**\n * An optional function for pre-processing nodes.\n *\n * Pre-processing happens immediately after the nodes are loaded based on `HierarchyLevelDefinition`\n * returned by this `HierarchyDefinition` and before their processing (hiding, grouping, sorting, etc.) starts.\n * The step allows assigning nodes additional data or excluding them from the hierarchy based on some attributes.\n */\n preProcessNode?: NodePreProcessor;\n\n /**\n * An optional function for post-processing nodes.\n *\n * Post-processing happens after the loaded nodes go through all the merging, hiding and grouping\n * steps, but before sorting them. This step allows `HierarchyDefinition` implementations to assign additional data\n * to nodes after they're processed. This is especially true for grouping nodes as they're only created during\n * processing.\n */\n postProcessNode?: NodePostProcessor;\n\n /** A function to create a hierarchy level definition for given parent node. */\n defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent instance node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineInstanceNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent instance node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: InstancesNodeKey };\n\n /**\n * Full name of the parent instance node class.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeClassName: string;\n\n /**\n * ECInstanceIds of the parent instance node.\n *\n * The `parentNode.key` also contains information about the instances the parent node is based on. However,\n * an instance node may be based on instances of multiple classes. In case that happens, parent node's instance\n * keys are grouped by class and a hierarchy level definition is requested for each combination of class and\n * instance IDs (with the same `parentNode`).\n */\n parentNodeInstanceIds: Id64String[];\n};\n\n/**\n * A definition of a hierarchy level that should be used for specific class of parent instance nodes.\n */\ninterface InstancesNodeChildHierarchyLevelDefinition {\n /**\n * Full name of the parent instance node's class to match against when checking if this hierarchy\n * level should be used for specific parent instance node.\n *\n * The check is polymorphic, so `BisCore.Element` class would match `BisCore.GeometricElement`, `BisCore.Category` and\n * all other element classes.\n */\n parentNodeClassName: string;\n\n /**\n * Called to create a hierarchy level definition when the class check passes (see `parentNodeClassName`).\n */\n definitions: (requestProps: DefineInstanceNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n\n /**\n * If set to true, and node matches at least one of the previous definitions, this definition will not be applied.\n *\n * For example:\n * ```ts\n * {\n * parentNodeClassName: \"BisCore.GeometricElement3d\",\n * definitions: () => ...,\n * },\n * // This will apply to all elements, that are not BisCore.GeometricElement3d\n * {\n * parentNodeClassName: \"BisCore.Element\",\n * onlyIfNotHandled: true,\n * definitions: () => ...,\n * }\n * ```\n */\n onlyIfNotHandled?: boolean;\n}\n\n/**\n * Props for defining child hierarchy level for specific parent custom node.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineCustomNodeChildHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\"> & {\n /** The parent custom node. */\n parentNode: Omit<HierarchyDefinitionParentNode, \"key\"> & { key: string };\n};\n\n/**\n * A definition of a hierarchy level for that should be used for specific custom parent nodes.\n */\ninterface CustomNodeChildHierarchyLevelDefinition {\n /**\n * `HierarchyNode.key` of the custom node that this child hierarchy level definition should be used for.\n */\n customParentNodeKey: string;\n\n /**\n * Called to create a hierarchy level definition when the node key check passes (see `customParentNodeKey`).\n */\n definitions: (requestProps: DefineCustomNodeChildHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n}\n\n/**\n * A hierarchy level definition associated with either parent instance node's class or custom\n * node's key.\n */\ntype ClassBasedHierarchyLevelDefinition = InstancesNodeChildHierarchyLevelDefinition | CustomNodeChildHierarchyLevelDefinition;\n\n/**\n * Props for defining root hierarchy level.\n * @see `createClassBasedHierarchyDefinition`\n * @beta\n */\nexport type DefineRootHierarchyLevelProps = Omit<DefineHierarchyLevelProps, \"parentNode\">;\n\n/**\n * Props for `createClassBasedHierarchyDefinition`.\n */\ninterface ClassBasedHierarchyDefinitionProps {\n /** Access to ECClass hierarchy in the iModel */\n classHierarchyInspector: ECClassHierarchyInspector;\n\n /** Hierarchy level definitions based on parent instance node's class or custom node's key. */\n hierarchy: {\n /** Called to create the root hierarchy level definition. */\n rootNodes: (props: DefineRootHierarchyLevelProps) => Promise<HierarchyLevelDefinition>;\n\n /**\n * Called to get child hierarchy level definitions based on parent instance node's class\n * or custom node's key.\n */\n childNodes: ClassBasedHierarchyLevelDefinition[];\n };\n}\n\n/**\n * Creates an instance of `HierarchyDefinition` that uses a somewhat declarative approach to define the\n * hierarchy - each hierarchy level is assigned either an instance node's class or custom node's\n * key and they're used to assign hierarchy level definitions based on parent node.\n *\n * @beta\n */\nexport function createClassBasedHierarchyDefinition(props: ClassBasedHierarchyDefinitionProps): HierarchyDefinition {\n return new ClassBasedHierarchyDefinition(props);\n}\n\nclass ClassBasedHierarchyDefinition implements HierarchyDefinition {\n public constructor(private _props: ClassBasedHierarchyDefinitionProps) {}\n\n /**\n * Create hierarchy level definitions for specific hierarchy level.\n * @param parentNode Parent node to create children definitions for.\n */\n public async defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition> {\n const { parentNode } = props;\n if (!parentNode) {\n return this._props.hierarchy.rootNodes(props);\n }\n\n if (HierarchyNode.isCustom(parentNode)) {\n const defs = this._props.hierarchy.childNodes\n .filter(isCustomNodeChildHierarchyLevelDefinition)\n .filter((def) => def.customParentNodeKey === parentNode.key);\n return (await Promise.all(defs.map(async (def) => def.definitions({ ...props, parentNode })))).flat();\n }\n\n // istanbul ignore else\n if (HierarchyNode.isInstancesNode(parentNode)) {\n const instanceIdsByClass = groupInstanceIdsByClass(parentNode.key.instanceKeys);\n const instancesParentNodeDefs = this._props.hierarchy.childNodes.filter(isInstancesNodeChildHierarchyLevelDefinition);\n return (\n await Promise.all(\n [...instanceIdsByClass.entries()].map(async ([parentNodeClassName, parentNodeInstanceIds]) =>\n createHierarchyLevelDefinitions(this._props.classHierarchyInspector, instancesParentNodeDefs, {\n ...props,\n parentNodeClassName,\n parentNodeInstanceIds,\n parentNode,\n }),\n ),\n )\n ).flat();\n }\n\n // istanbul ignore next\n return [];\n }\n}\n\nasync function createHierarchyLevelDefinitions(\n classHierarchy: ECClassHierarchyInspector,\n defs: InstancesNodeChildHierarchyLevelDefinition[],\n requestProps: DefineInstanceNodeChildHierarchyLevelProps,\n) {\n const obs = from(defs).pipe(\n mergeMap(async (def, idx) => {\n if (await classHierarchy.classDerivesFrom(requestProps.parentNodeClassName, def.parentNodeClassName)) {\n return { def, idx };\n }\n return undefined;\n }),\n filter((x): x is Exclude<typeof x, undefined> => !!x),\n toArray(),\n concatMap((x) => x.sort((a, b) => a.idx - b.idx).map(({ def }) => def)),\n filter((def, idx) => !def.onlyIfNotHandled || idx === 0),\n mergeMap(async (def) => def.definitions(requestProps)),\n mergeAll(),\n );\n return firstValueFrom(obs.pipe(toArray()));\n}\n\nfunction groupInstanceIdsByClass(instanceKeys: InstanceKey[]) {\n const instanceIdsByClass = new Map<string, Id64String[]>();\n instanceKeys.forEach((key) => {\n let instanceIds = instanceIdsByClass.get(key.className);\n if (!instanceIds) {\n instanceIds = [];\n instanceIdsByClass.set(key.className, instanceIds);\n }\n instanceIds.push(key.id);\n });\n return instanceIdsByClass;\n}\n\nfunction isCustomNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is CustomNodeChildHierarchyLevelDefinition {\n return !!(def as CustomNodeChildHierarchyLevelDefinition).customParentNodeKey;\n}\n\nfunction isInstancesNodeChildHierarchyLevelDefinition(def: ClassBasedHierarchyLevelDefinition): def is InstancesNodeChildHierarchyLevelDefinition {\n return !!(def as InstancesNodeChildHierarchyLevelDefinition).parentNodeClassName;\n}\n"]}
@@ -325,7 +325,8 @@ async function createWhereClause(contentClassAlias, classLoader, rule) {
325
325
  }
326
326
  const value = rule.value.rawValue;
327
327
  if (rule.operator === "like" && typeof value === "string") {
328
- return `${propertyValueSelector} ${ecsqlOperator} '${value}' ESCAPE '\\'`;
328
+ const escapedValue = value.replace(/[%_\\]/g, "\\$&");
329
+ return `${propertyValueSelector} ${ecsqlOperator} '%${escapedValue}%' ESCAPE '\\'`;
329
330
  }
330
331
  const propertyClass = await classLoader(sourceAlias);
331
332
  if (!propertyClass) {
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSelectQueryFactory.js","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,qBAAqB,EAMrB,8BAA8B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAmD,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAElJ;;;;;GAKG;AACH,MAAM,CAAN,IAAY,2BA0BX;AA1BD,WAAY,2BAA2B;IACrC,kHAAkH;IAClH,8DAA+B,CAAA;IAC/B,6EAA6E;IAC7E,4DAA6B,CAAA;IAC7B,qCAAqC;IACrC,4DAA6B,CAAA;IAC7B;;;;;OAKG;IACH,0DAA2B,CAAA;IAC3B,6FAA6F;IAC7F,oEAAqC,CAAA;IACrC,oHAAoH;IACpH,0EAA2C,CAAA;IAC3C,mEAAmE;IACnE,oDAAqB,CAAA;IACrB,4EAA4E;IAC5E,4DAA6B,CAAA;IAC7B,2EAA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ChB,CAAC;AAOD,KAAK,UAAU,sBAAsB,CAAC,KAAkC;IACtE,MAAM,WAAW,GAAG,MAAM,2BAA2B,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC7G,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC,gBAAgB,CAAC;IAChC,CAAC;IACD,IAAI,MAAM,KAAK,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,WAAW,EAAE,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC9F,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,IAAI,MAAM,KAAK,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,KAAK,CAAC,gBAAgB,EAAE,WAAW,CAAC,EAAE,CAAC;QAC9F,OAAO,KAAK,CAAC,gBAAgB,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,KAAK,UAAU,2BAA2B,CAAC,uBAAkD,EAAE,OAAiB;IAC9G,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,CAAC,aAAa,EAAE,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;IAChD,IAAI,iBAAiB,GAAG,aAAa,CAAC;IACtC,KAAK,MAAM,aAAa,IAAI,WAAW,EAAE,CAAC;QACxC,IAAI,MAAM,uBAAuB,CAAC,gBAAgB,CAAC,aAAa,EAAE,iBAAiB,CAAC,EAAE,CAAC;YACrF,iBAAiB,GAAG,aAAa,CAAC;QACpC,CAAC;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,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 { assert, Id64String } from \"@itwin/core-bentley\";\nimport {\n GenericInstanceFilter,\n GenericInstanceFilterRelationshipStep,\n GenericInstanceFilterRule,\n GenericInstanceFilterRuleGroup,\n GenericInstanceFilterRuleGroupOperator,\n GenericInstanceFilterRuleOperator,\n GenericInstanceFilterRuleValue,\n} from \"@itwin/core-common\";\nimport { EC, ECClassHierarchyInspector, ECSchemaProvider, ECSql, getClass, parseFullClassName, PrimitiveValue } from \"@itwin/presentation-shared\";\n\n/**\n * Column names of the SELECT clause created by `NodeSelectClauseFactory`. Order of the names matches the order of columns\n * created by the factory.\n *\n * @beta\n */\nexport enum NodeSelectClauseColumnNames {\n /** Full class name of the instance the node represents. Type: `string` in format `{schema name}:{class name}`. */\n FullClassName = \"FullClassName\",\n /** ECInstance ID of the instance the node represents. Type: `Id64String`. */\n ECInstanceId = \"ECInstanceId\",\n /** Display label. Type: `string`. */\n DisplayLabel = \"DisplayLabel\",\n /**\n * A flag indicating if the node has children. Type: `boolean`. Values:\n * - `false` - node never has children.\n * - `true` - node always has children.\n * - NULL - unknown, needs to be determined by requesting children for the node.\n */\n HasChildren = \"HasChildren\",\n /** A flag indicating that a node should be hidden if it has no children. Type: `boolean`. */\n HideIfNoChildren = \"HideIfNoChildren\",\n /** A flag indicating that a node should be hidden and its children should be displayed instead. Type: `boolean`. */\n HideNodeInHierarchy = \"HideNodeInHierarchy\",\n /** A serialized JSON object for providing grouping information. */\n Grouping = \"Grouping\",\n /** A serialized JSON object for associating a node with additional data. */\n ExtendedData = \"ExtendedData\",\n /** A flag indicating the node should be auto-expanded when it's loaded. */\n AutoExpand = \"AutoExpand\",\n /** A flag indicating the node supports child hierarchy level filtering. */\n SupportsFiltering = \"SupportsFiltering\",\n}\n\n/**\n * A data structure for defining an ECSQL value selector.\n */\ninterface ECSqlValueSelector {\n selector: string;\n}\n\n/**\n * Props for `NodeSelectClauseFactory.createSelectClause`.\n */\ninterface NodeSelectClauseProps {\n ecClassId: Id64String | ECSqlValueSelector;\n ecInstanceId: Id64String | ECSqlValueSelector;\n nodeLabel: string | ECSqlValueSelector;\n extendedData?: {\n [key: string]: Id64String | string | number | boolean | ECSqlValueSelector;\n };\n autoExpand?: boolean | ECSqlValueSelector;\n supportsFiltering?: boolean | ECSqlValueSelector;\n hasChildren?: boolean | ECSqlValueSelector;\n hideNodeInHierarchy?: boolean | ECSqlValueSelector;\n hideIfNoChildren?: boolean | ECSqlValueSelector;\n grouping?: ECSqlSelectClauseGroupingParams;\n}\n\n/**\n * A data structure for defining nodes' grouping requirements.\n */\ninterface ECSqlSelectClauseGroupingParams {\n byLabel?: ECSqlSelectClauseLabelGroupingParams;\n byClass?: boolean | ECSqlSelectClauseGroupingParamsBase | ECSqlValueSelector;\n byBaseClasses?: ECSqlSelectClauseBaseClassGroupingParams;\n byProperties?: ECSqlSelectClausePropertiesGroupingParams;\n}\n\n/**\n * A data structure for defining label grouping params.\n */\ninterface ECSqlSelectClauseLabelGroupingBaseParams {\n /** Label grouping option that determines whether to group nodes or to merge them. Defaults to \"group\".*/\n action?: \"group\" | \"merge\";\n /** Id that needs to match for nodes to be grouped or merged.*/\n groupId?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining label merging.\n */\ninterface ECSqlSelectClauseLabelGroupingMergeParams extends ECSqlSelectClauseLabelGroupingBaseParams {\n action: \"merge\";\n}\n\n/**\n * A data structure for defining label grouping.\n */\ninterface ECSqlSelectClauseLabelGroupingGroupParams extends ECSqlSelectClauseLabelGroupingBaseParams, ECSqlSelectClauseGroupingParamsBase {\n action?: \"group\";\n}\n\n/**\n * A data structure for defining possible label grouping types.\n */\ntype ECSqlSelectClauseLabelGroupingParams =\n | boolean\n | ECSqlValueSelector\n | ECSqlSelectClauseLabelGroupingMergeParams\n | ECSqlSelectClauseLabelGroupingGroupParams;\n\n/**\n * A data structure for defining base grouping parameters shared across all types of grouping.\n */\ninterface ECSqlSelectClauseGroupingParamsBase {\n hideIfNoSiblings?: boolean | ECSqlValueSelector;\n hideIfOneGroupedNode?: boolean | ECSqlValueSelector;\n autoExpand?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining properties grouping.\n */\ninterface ECSqlSelectClausePropertiesGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n /**\n * Full name of a class whose properties are used to group the node. Only has effect if the node\n * represents an instance of that class.\n *\n * Full class name format: `SchemaName.ClassName`.\n */\n propertiesClassName: string;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value is not set or is set to an empty string.\n *\n * Label of the created grouping node will be `Not Specified`.\n */\n createGroupForUnspecifiedValues?: boolean | ECSqlValueSelector;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value doesn't fit within any of the provided\n * ranges, or is not a numeric value.\n *\n * Label of the created grouping node will be `Other`.\n */\n createGroupForOutOfRangeValues?: boolean | ECSqlValueSelector;\n /**\n * Properties of the specified class, by which the nodes should be grouped.\n *\n * Example usage:\n * ```ts\n * propertyGroups: [\n * {\n * propertyName: \"type\",\n * propertyClassAlias: \"this\"\n * },\n * {\n * propertyName: \"length\",\n * propertyClassAlias: \"x\",\n * ranges: [\n * { fromValue: 1, toValue: 10, rangeLabel: \"Small\" },\n * { fromValue: 11, toValue: 20, rangeLabel: \"Medium\" }\n * ]\n * },\n * ]\n * ```\n */\n propertyGroups: ECSqlSelectClausePropertyGroup[];\n}\n\n/**\n * A data structure for defining specific properties' grouping params.\n */\ninterface ECSqlSelectClausePropertyGroup {\n /** A string indicating the name of the property to group by. */\n propertyName: string;\n /** Alias to of the class containing the property. Used to select the property value. */\n propertyClassAlias: string;\n /** Ranges are used to group nodes by numeric properties which are within specified bounds. */\n ranges?: ECSqlSelectClausePropertyValueRange[];\n}\n\n/**\n * A data structure for defining boundaries for a value.\n */\ninterface ECSqlSelectClausePropertyValueRange {\n /** Defines the lower bound of the range. */\n fromValue: number | ECSqlValueSelector;\n /** Defines the upper bound of the range. */\n toValue: number | ECSqlValueSelector;\n /** Defines the range label. Will be used as grouping node's display label. */\n rangeLabel?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining base class grouping.\n */\ninterface ECSqlSelectClauseBaseClassGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n fullClassNames: string[] | ECSqlValueSelector[];\n}\n\n/**\n * An interface of a factory that knows how to create nodes' select ECSQL query.\n * @beta\n */\nexport interface NodesQueryClauseFactory {\n /** Create a SELECT clause in a format understood by nodes query parser used by `HierarchyProvider`. */\n createSelectClause(props: NodeSelectClauseProps): Promise<string>;\n\n /** Create FROM, JOIN and WHERE clauses whose combination results in an ECSQL filter defined by given `GenericInstanceFilter`. */\n createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }>;\n}\n\n/**\n * Creates an instance of `NodeSelectQueryFactory` that .\n * @beta\n */\nexport function createNodesQueryClauseFactory(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }): NodesQueryClauseFactory {\n return new NodeSelectQueryFactory(props);\n}\n\n/** A factory for creating a nodes' select ECSQL query. */\nclass NodeSelectQueryFactory {\n private _imodelAccess: ECSchemaProvider & ECClassHierarchyInspector;\n\n public constructor(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }) {\n this._imodelAccess = props.imodelAccess;\n }\n\n /** Create a SELECT clause in a format understood by results reader of the library. */\n public async createSelectClause(props: NodeSelectClauseProps) {\n // note: the columns order must match the order in `NodeSelectClauseColumnNames`\n return `\n ec_ClassName(${createECSqlValueSelector(props.ecClassId)}) AS ${NodeSelectClauseColumnNames.FullClassName},\n ${createECSqlValueSelector(props.ecInstanceId)} AS ${NodeSelectClauseColumnNames.ECInstanceId},\n ${createECSqlValueSelector(props.nodeLabel)} AS ${NodeSelectClauseColumnNames.DisplayLabel},\n CAST(${createECSqlValueSelector(props.hasChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HasChildren},\n CAST(${createECSqlValueSelector(props.hideIfNoChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideIfNoChildren},\n CAST(${createECSqlValueSelector(props.hideNodeInHierarchy)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideNodeInHierarchy},\n ${props.grouping ? createGroupingSelector(props.grouping) : \"CAST(NULL AS TEXT)\"} AS ${NodeSelectClauseColumnNames.Grouping},\n ${\n props.extendedData\n ? `json_object(${Object.entries(props.extendedData)\n .map(([key, value]) => `'${key}', ${createECSqlValueSelector(value)}`)\n .join(\", \")})`\n : \"CAST(NULL AS TEXT)\"\n } AS ${NodeSelectClauseColumnNames.ExtendedData},\n CAST(${createECSqlValueSelector(props.autoExpand)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.AutoExpand},\n CAST(${createECSqlValueSelector(props.supportsFiltering)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.SupportsFiltering}\n `;\n }\n\n /**\n * Creates the necessary ECSQL snippets to create an instance filter described by the `def` argument.\n * - `from` is set to either the `contentClass.fullName` or `def.propertyClassName`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `def.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `def.filterClassNames` and by properties as described by `def.rules`.\n *\n * Special cases:\n * - If `def` is `undefined`, `joins` and `where` are set to empty strings and `from` is set to `contentClass.fullName`.\n * - If the provided content class doesn't intersect with the property class in provided filter, a special result\n * is returned to make sure the resulting query is valid and doesn't return anything.\n */\n public async createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }> {\n const { contentClass, filter } = props;\n if (!filter) {\n // undefined filter means we don't want any filtering to be applied\n return { from: contentClass.fullName, joins: \"\", where: \"\" };\n }\n\n const from = await specializeContentClass({\n classHierarchyInspector: this._imodelAccess,\n contentClassName: contentClass.fullName,\n filterClassNames: filter.propertyClassNames,\n });\n if (!from) {\n // filter class doesn't intersect with content class - make sure the query returns nothing by returning a `FALSE` WHERE clause\n return { from: contentClass.fullName, joins: \"\", where: \"FALSE\" };\n }\n\n /**\n * TODO:\n * There may be similar related instance paths, e.g.:\n * - A -> B -> C,\n * - A -> B -> D.\n * At this moment we're handling each path individually which means A and B would get joined twice. We could look into\n * creating a join tree first, e.g.\n * C\n * /\n * A -> B\n * \\\n * D\n */\n const joins = await Promise.all(\n filter.relatedInstances.map(async (rel, i) =>\n ECSql.createRelationshipPathJoinClause({\n schemaProvider: this._imodelAccess,\n path: assignRelationshipPathAliases(rel.path, i, contentClass.alias, rel.alias),\n }),\n ),\n );\n\n const whereConditions = new Array<string>();\n if (filter.filteredClassNames && filter.filteredClassNames.length > 0) {\n whereConditions.push(\n `${ECSql.createRawPropertyValueSelector(contentClass.alias, \"ECClassId\")} IS (\n ${filter.filteredClassNames\n .map(parseFullClassName)\n .map(({ schemaName, className }) => `[${schemaName}].[${className}]`)\n .join(\", \")}\n )`,\n );\n }\n const classAliasMap = new Map<string, string>([[contentClass.alias, from]]);\n filter.relatedInstances.forEach(({ path, alias }) => path.length > 0 && classAliasMap.set(alias, path[path.length - 1].targetClassName));\n const propertiesFilter = await createWhereClause(\n contentClass.alias,\n async (alias) => {\n const aliasClassName = classAliasMap.get(alias);\n return aliasClassName ? getClass(this._imodelAccess, aliasClassName) : undefined;\n },\n filter.rules,\n );\n if (propertiesFilter) {\n whereConditions.push(propertiesFilter);\n }\n\n return {\n from,\n joins: joins.join(\"\\n\"),\n where: whereConditions.join(\" AND \"),\n };\n }\n}\n\nfunction createECSqlValueSelector(input: undefined | PrimitiveValue | ECSqlValueSelector) {\n if (input === undefined) {\n return \"NULL\";\n }\n if (isSelector(input)) {\n return input.selector;\n }\n return ECSql.createRawPrimitiveValueSelector(input);\n}\n\nfunction isSelector(x: any): x is ECSqlValueSelector {\n return !!x.selector;\n}\n\nfunction createGroupingSelector(grouping: ECSqlSelectClauseGroupingParams): string {\n const groupingSelectors = new Array<{ key: string; selector: string }>();\n\n grouping.byLabel &&\n groupingSelectors.push({\n key: \"byLabel\",\n selector:\n typeof grouping.byLabel === \"boolean\" || isSelector(grouping.byLabel)\n ? createECSqlValueSelector(grouping.byLabel)\n : serializeJsonObject(createLabelGroupingBaseParamsSelectors(grouping.byLabel)),\n });\n\n grouping.byClass &&\n groupingSelectors.push({\n key: \"byClass\",\n selector:\n typeof grouping.byClass === \"boolean\" || isSelector(grouping.byClass)\n ? createECSqlValueSelector(grouping.byClass)\n : serializeJsonObject(createBaseGroupingParamSelectors(grouping.byClass)),\n });\n\n grouping.byBaseClasses &&\n groupingSelectors.push({\n key: \"byBaseClasses\",\n selector: serializeJsonObject([\n {\n key: \"fullClassNames\",\n selector: `json_array(${grouping.byBaseClasses.fullClassNames.map((className) => createECSqlValueSelector(className)).join(\", \")})`,\n },\n ...createBaseGroupingParamSelectors(grouping.byBaseClasses),\n ]),\n });\n\n grouping.byProperties &&\n groupingSelectors.push({\n key: \"byProperties\",\n selector: serializeJsonObject([\n {\n key: \"propertiesClassName\",\n selector: `${createECSqlValueSelector(grouping.byProperties.propertiesClassName)}`,\n },\n {\n key: \"propertyGroups\",\n selector: `json_array(${grouping.byProperties.propertyGroups\n .map((propertyGroup) => serializeJsonObject(createPropertyGroupSelectors(propertyGroup)))\n .join(\", \")})`,\n },\n ...(grouping.byProperties.createGroupForOutOfRangeValues !== undefined\n ? [\n {\n key: \"createGroupForOutOfRangeValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForOutOfRangeValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...(grouping.byProperties.createGroupForUnspecifiedValues !== undefined\n ? [\n {\n key: \"createGroupForUnspecifiedValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForUnspecifiedValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...createBaseGroupingParamSelectors(grouping.byProperties),\n ]),\n });\n\n return serializeJsonObject(groupingSelectors);\n}\n\nfunction createLabelGroupingBaseParamsSelectors(byLabel: ECSqlSelectClauseLabelGroupingMergeParams | ECSqlSelectClauseLabelGroupingGroupParams) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (byLabel.action !== undefined) {\n selectors.push({\n key: \"action\",\n selector: `${createECSqlValueSelector(byLabel.action)}`,\n });\n }\n if (byLabel.groupId !== undefined) {\n selectors.push({\n key: \"groupId\",\n selector: createECSqlValueSelector(byLabel.groupId),\n });\n }\n if (byLabel.action !== \"merge\") {\n selectors.push(...createBaseGroupingParamSelectors(byLabel));\n }\n\n return selectors;\n}\n\nfunction createPropertyGroupSelectors(propertyGroup: ECSqlSelectClausePropertyGroup) {\n const selectors = new Array<{ key: string; selector: string }>();\n selectors.push(\n {\n key: \"propertyName\",\n selector: `${createECSqlValueSelector(propertyGroup.propertyName)}`,\n },\n {\n key: \"propertyValue\",\n selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,\n },\n );\n if (propertyGroup.ranges) {\n selectors.push(createRangeParamSelectors(propertyGroup.ranges));\n }\n return selectors;\n}\n\nfunction createRangeParamSelectors(ranges: ECSqlSelectClausePropertyValueRange[]) {\n return {\n key: \"ranges\",\n selector: `json_array(${ranges\n .map((range) =>\n serializeJsonObject([\n {\n key: \"fromValue\",\n selector: createECSqlValueSelector(range.fromValue),\n },\n {\n key: \"toValue\",\n selector: createECSqlValueSelector(range.toValue),\n },\n ...(range.rangeLabel\n ? [\n {\n key: \"rangeLabel\",\n selector: `${createECSqlValueSelector(range.rangeLabel)}`,\n },\n ]\n : []),\n ]),\n )\n .join(\", \")})`,\n };\n}\n\nfunction createBaseGroupingParamSelectors(params: ECSqlSelectClauseGroupingParamsBase) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (params.hideIfNoSiblings !== undefined) {\n selectors.push({\n key: \"hideIfNoSiblings\",\n selector: createECSqlValueSelector(params.hideIfNoSiblings),\n });\n }\n if (params.hideIfOneGroupedNode !== undefined) {\n selectors.push({\n key: \"hideIfOneGroupedNode\",\n selector: createECSqlValueSelector(params.hideIfOneGroupedNode),\n });\n }\n if (params.autoExpand !== undefined) {\n selectors.push({\n key: \"autoExpand\",\n selector: createECSqlValueSelector(params.autoExpand),\n });\n }\n return selectors;\n}\n\nfunction serializeJsonObject(selectors: Array<{ key: string; selector: string }>): string {\n return `json_object(${selectors.map(({ key, selector }) => `'${key}', ${selector}`).join(\", \")})`;\n}\n\nasync function createWhereClause(\n contentClassAlias: string,\n classLoader: (alias: string) => Promise<EC.Class | undefined>,\n rule: GenericInstanceFilterRule | GenericInstanceFilterRuleGroup,\n): Promise<string | undefined> {\n if (GenericInstanceFilter.isFilterRuleGroup(rule)) {\n const clause = (await Promise.all(rule.rules.map(async (r) => createWhereClause(contentClassAlias, classLoader, r))))\n .filter((c) => !!c)\n .join(` ${getECSqlLogicalOperator(rule.operator)} `);\n return clause ? (rule.operator === \"or\" ? `(${clause})` : clause) : undefined;\n }\n const sourceAlias = rule.sourceAlias ? rule.sourceAlias : contentClassAlias;\n const propertyValueSelector = ECSql.createRawPropertyValueSelector(sourceAlias, rule.propertyName);\n if (isUnaryRuleOperator(rule.operator)) {\n switch (rule.operator) {\n case \"is-true\":\n return propertyValueSelector;\n case \"is-false\":\n return `NOT ${propertyValueSelector}`;\n case \"is-null\":\n return `${propertyValueSelector} IS NULL`;\n case \"is-not-null\":\n return `${propertyValueSelector} IS NOT NULL`;\n }\n }\n const ecsqlOperator = getECSqlComparisonOperator(rule.operator);\n if (rule.value === undefined) {\n throw new Error(`Rule \"${rule.propertyName}\" ${ecsqlOperator} is missing value.`);\n }\n\n const value = rule.value.rawValue;\n\n if (rule.operator === \"like\" && typeof value === \"string\") {\n return `${propertyValueSelector} ${ecsqlOperator} '${value}' ESCAPE '\\\\'`;\n }\n const propertyClass = await classLoader(sourceAlias);\n if (!propertyClass) {\n throw new Error(`Class with alias \"${sourceAlias}\" not found.`);\n }\n const property = await propertyClass.getProperty(rule.propertyName);\n if (!property) {\n throw new Error(`Property \"${rule.propertyName}\" not found in ECClass \"${propertyClass.fullName}\".`);\n }\n if (property.isNavigation()) {\n assert(rule.value !== undefined && GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector}.[Id] ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value.id)}`;\n }\n if (property.isEnumeration()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n if (property.isPrimitive()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n switch (property.primitiveType) {\n case \"Point2d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint2d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Point3d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint3d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[z]`, \"is-equal\", value.z)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Double\": {\n assert(typeof value === \"number\");\n if (rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\") {\n return `${createFloatingPointEqualityClause(propertyValueSelector, rule.operator, value)}`;\n }\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n default: {\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n }\n }\n throw new Error(\"Struct and array properties are not supported for filtering\");\n}\n\nfunction createFloatingPointEqualityClause(valueSelector: string, operator: \"is-equal\" | \"is-not-equal\", value: number) {\n const [from, to] = getFloatingPointValueRange(value);\n return `${valueSelector} ${operator === \"is-not-equal\" ? \"NOT \" : \"\"} BETWEEN ${from} AND ${to}`;\n}\n\nfunction getFloatingPointValueRange(value: number): [number, number] {\n return [value - Number.EPSILON, value + Number.EPSILON];\n}\n\nfunction getECSqlLogicalOperator(op: GenericInstanceFilterRuleGroupOperator) {\n switch (op) {\n case \"and\":\n return \"AND\";\n case \"or\":\n return \"OR\";\n }\n}\n\nfunction isUnaryRuleOperator(\n op: GenericInstanceFilterRuleOperator,\n): op is Extract<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\"> {\n return op === \"is-true\" || op === \"is-false\" || op === \"is-null\" || op === \"is-not-null\";\n}\n\nfunction getECSqlComparisonOperator(op: Exclude<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\">) {\n switch (op) {\n case \"is-equal\":\n return `=`;\n case \"is-not-equal\":\n return `<>`;\n case \"greater\":\n return `>`;\n case \"greater-or-equal\":\n return `>=`;\n case \"less\":\n return `<`;\n case \"less-or-equal\":\n return `<=`;\n case \"like\":\n return `LIKE`;\n }\n}\n\ntype JoinRelationshipPath = Parameters<typeof ECSql.createRelationshipPathJoinClause>[0][\"path\"];\nfunction assignRelationshipPathAliases(\n path: GenericInstanceFilterRelationshipStep[],\n pathIndex: number,\n sourceAlias: string,\n targetAlias: string,\n): JoinRelationshipPath {\n function createAlias(fullClassName: string, index: number) {\n return `rel_${pathIndex}_${fullClassName.replaceAll(/[\\.:]/g, \"_\")}_${index}`;\n }\n const result: JoinRelationshipPath = [];\n path.forEach((step, i) => {\n result.push({\n targetClassName: step.targetClassName,\n relationshipName: step.relationshipClassName,\n sourceClassName: step.sourceClassName,\n relationshipReverse: !step.isForwardRelationship,\n sourceAlias: i === 0 ? sourceAlias : result[i - 1].targetAlias,\n relationshipAlias: createAlias(step.relationshipClassName, i),\n targetAlias: i === path.length - 1 ? targetAlias : createAlias(step.targetClassName, i),\n joinType: \"inner\",\n });\n });\n return result;\n}\n\ninterface SpecializeContentClassProps {\n classHierarchyInspector: ECClassHierarchyInspector;\n contentClassName: string;\n filterClassNames: string[];\n}\nasync function specializeContentClass(props: SpecializeContentClassProps): Promise<string | undefined> {\n const filterClass = await getSpecializedPropertyClass(props.classHierarchyInspector, props.filterClassNames);\n if (!filterClass) {\n return props.contentClassName;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(filterClass, props.contentClassName)) {\n return filterClass;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(props.contentClassName, filterClass)) {\n return props.contentClassName;\n }\n return undefined;\n}\n\nasync function getSpecializedPropertyClass(classHierarchyInspector: ECClassHierarchyInspector, classes: string[]): Promise<string | undefined> {\n if (classes.length === 0) {\n return undefined;\n }\n const [currClassName, ...restClasses] = classes;\n let resolvedClassName = currClassName;\n for (const propClassName of restClasses) {\n if (await classHierarchyInspector.classDerivesFrom(propClassName, resolvedClassName)) {\n resolvedClassName = propClassName;\n }\n }\n return resolvedClassName;\n}\n"]}
1
+ {"version":3,"file":"NodeSelectQueryFactory.js","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAc,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,qBAAqB,EAMrB,8BAA8B,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAmD,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAElJ;;;;;GAKG;AACH,MAAM,CAAN,IAAY,2BA0BX;AA1BD,WAAY,2BAA2B;IACrC,kHAAkH;IAClH,8DAA+B,CAAA;IAC/B,6EAA6E;IAC7E,4DAA6B,CAAA;IAC7B,qCAAqC;IACrC,4DAA6B,CAAA;IAC7B;;;;;OAKG;IACH,0DAA2B,CAAA;IAC3B,6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C;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,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 { assert, Id64String } from \"@itwin/core-bentley\";\nimport {\n GenericInstanceFilter,\n GenericInstanceFilterRelationshipStep,\n GenericInstanceFilterRule,\n GenericInstanceFilterRuleGroup,\n GenericInstanceFilterRuleGroupOperator,\n GenericInstanceFilterRuleOperator,\n GenericInstanceFilterRuleValue,\n} from \"@itwin/core-common\";\nimport { EC, ECClassHierarchyInspector, ECSchemaProvider, ECSql, getClass, parseFullClassName, PrimitiveValue } from \"@itwin/presentation-shared\";\n\n/**\n * Column names of the SELECT clause created by `NodeSelectClauseFactory`. Order of the names matches the order of columns\n * created by the factory.\n *\n * @beta\n */\nexport enum NodeSelectClauseColumnNames {\n /** Full class name of the instance the node represents. Type: `string` in format `{schema name}:{class name}`. */\n FullClassName = \"FullClassName\",\n /** ECInstance ID of the instance the node represents. Type: `Id64String`. */\n ECInstanceId = \"ECInstanceId\",\n /** Display label. Type: `string`. */\n DisplayLabel = \"DisplayLabel\",\n /**\n * A flag indicating if the node has children. Type: `boolean`. Values:\n * - `false` - node never has children.\n * - `true` - node always has children.\n * - NULL - unknown, needs to be determined by requesting children for the node.\n */\n HasChildren = \"HasChildren\",\n /** A flag indicating that a node should be hidden if it has no children. Type: `boolean`. */\n HideIfNoChildren = \"HideIfNoChildren\",\n /** A flag indicating that a node should be hidden and its children should be displayed instead. Type: `boolean`. */\n HideNodeInHierarchy = \"HideNodeInHierarchy\",\n /** A serialized JSON object for providing grouping information. */\n Grouping = \"Grouping\",\n /** A serialized JSON object for associating a node with additional data. */\n ExtendedData = \"ExtendedData\",\n /** A flag indicating the node should be auto-expanded when it's loaded. */\n AutoExpand = \"AutoExpand\",\n /** A flag indicating the node supports child hierarchy level filtering. */\n SupportsFiltering = \"SupportsFiltering\",\n}\n\n/**\n * A data structure for defining an ECSQL value selector.\n */\ninterface ECSqlValueSelector {\n selector: string;\n}\n\n/**\n * Props for `NodeSelectClauseFactory.createSelectClause`.\n */\ninterface NodeSelectClauseProps {\n ecClassId: Id64String | ECSqlValueSelector;\n ecInstanceId: Id64String | ECSqlValueSelector;\n nodeLabel: string | ECSqlValueSelector;\n extendedData?: {\n [key: string]: Id64String | string | number | boolean | ECSqlValueSelector;\n };\n autoExpand?: boolean | ECSqlValueSelector;\n supportsFiltering?: boolean | ECSqlValueSelector;\n hasChildren?: boolean | ECSqlValueSelector;\n hideNodeInHierarchy?: boolean | ECSqlValueSelector;\n hideIfNoChildren?: boolean | ECSqlValueSelector;\n grouping?: ECSqlSelectClauseGroupingParams;\n}\n\n/**\n * A data structure for defining nodes' grouping requirements.\n */\ninterface ECSqlSelectClauseGroupingParams {\n byLabel?: ECSqlSelectClauseLabelGroupingParams;\n byClass?: boolean | ECSqlSelectClauseGroupingParamsBase | ECSqlValueSelector;\n byBaseClasses?: ECSqlSelectClauseBaseClassGroupingParams;\n byProperties?: ECSqlSelectClausePropertiesGroupingParams;\n}\n\n/**\n * A data structure for defining label grouping params.\n */\ninterface ECSqlSelectClauseLabelGroupingBaseParams {\n /** Label grouping option that determines whether to group nodes or to merge them. Defaults to \"group\".*/\n action?: \"group\" | \"merge\";\n /** Id that needs to match for nodes to be grouped or merged.*/\n groupId?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining label merging.\n */\ninterface ECSqlSelectClauseLabelGroupingMergeParams extends ECSqlSelectClauseLabelGroupingBaseParams {\n action: \"merge\";\n}\n\n/**\n * A data structure for defining label grouping.\n */\ninterface ECSqlSelectClauseLabelGroupingGroupParams extends ECSqlSelectClauseLabelGroupingBaseParams, ECSqlSelectClauseGroupingParamsBase {\n action?: \"group\";\n}\n\n/**\n * A data structure for defining possible label grouping types.\n */\ntype ECSqlSelectClauseLabelGroupingParams =\n | boolean\n | ECSqlValueSelector\n | ECSqlSelectClauseLabelGroupingMergeParams\n | ECSqlSelectClauseLabelGroupingGroupParams;\n\n/**\n * A data structure for defining base grouping parameters shared across all types of grouping.\n */\ninterface ECSqlSelectClauseGroupingParamsBase {\n hideIfNoSiblings?: boolean | ECSqlValueSelector;\n hideIfOneGroupedNode?: boolean | ECSqlValueSelector;\n autoExpand?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining properties grouping.\n */\ninterface ECSqlSelectClausePropertiesGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n /**\n * Full name of a class whose properties are used to group the node. Only has effect if the node\n * represents an instance of that class.\n *\n * Full class name format: `SchemaName.ClassName`.\n */\n propertiesClassName: string;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value is not set or is set to an empty string.\n *\n * Label of the created grouping node will be `Not Specified`.\n */\n createGroupForUnspecifiedValues?: boolean | ECSqlValueSelector;\n /**\n * Property grouping option that determines whether to group nodes whose grouping value doesn't fit within any of the provided\n * ranges, or is not a numeric value.\n *\n * Label of the created grouping node will be `Other`.\n */\n createGroupForOutOfRangeValues?: boolean | ECSqlValueSelector;\n /**\n * Properties of the specified class, by which the nodes should be grouped.\n *\n * Example usage:\n * ```ts\n * propertyGroups: [\n * {\n * propertyName: \"type\",\n * propertyClassAlias: \"this\"\n * },\n * {\n * propertyName: \"length\",\n * propertyClassAlias: \"x\",\n * ranges: [\n * { fromValue: 1, toValue: 10, rangeLabel: \"Small\" },\n * { fromValue: 11, toValue: 20, rangeLabel: \"Medium\" }\n * ]\n * },\n * ]\n * ```\n */\n propertyGroups: ECSqlSelectClausePropertyGroup[];\n}\n\n/**\n * A data structure for defining specific properties' grouping params.\n */\ninterface ECSqlSelectClausePropertyGroup {\n /** A string indicating the name of the property to group by. */\n propertyName: string;\n /** Alias to of the class containing the property. Used to select the property value. */\n propertyClassAlias: string;\n /** Ranges are used to group nodes by numeric properties which are within specified bounds. */\n ranges?: ECSqlSelectClausePropertyValueRange[];\n}\n\n/**\n * A data structure for defining boundaries for a value.\n */\ninterface ECSqlSelectClausePropertyValueRange {\n /** Defines the lower bound of the range. */\n fromValue: number | ECSqlValueSelector;\n /** Defines the upper bound of the range. */\n toValue: number | ECSqlValueSelector;\n /** Defines the range label. Will be used as grouping node's display label. */\n rangeLabel?: string | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining base class grouping.\n */\ninterface ECSqlSelectClauseBaseClassGroupingParams extends ECSqlSelectClauseGroupingParamsBase {\n fullClassNames: string[] | ECSqlValueSelector[];\n}\n\n/**\n * An interface of a factory that knows how to create nodes' select ECSQL query.\n * @beta\n */\nexport interface NodesQueryClauseFactory {\n /** Create a SELECT clause in a format understood by nodes query parser used by `HierarchyProvider`. */\n createSelectClause(props: NodeSelectClauseProps): Promise<string>;\n\n /** Create FROM, JOIN and WHERE clauses whose combination results in an ECSQL filter defined by given `GenericInstanceFilter`. */\n createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }>;\n}\n\n/**\n * Creates an instance of `NodeSelectQueryFactory` that .\n * @beta\n */\nexport function createNodesQueryClauseFactory(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }): NodesQueryClauseFactory {\n return new NodeSelectQueryFactory(props);\n}\n\n/** A factory for creating a nodes' select ECSQL query. */\nclass NodeSelectQueryFactory {\n private _imodelAccess: ECSchemaProvider & ECClassHierarchyInspector;\n\n public constructor(props: { imodelAccess: ECSchemaProvider & ECClassHierarchyInspector }) {\n this._imodelAccess = props.imodelAccess;\n }\n\n /** Create a SELECT clause in a format understood by results reader of the library. */\n public async createSelectClause(props: NodeSelectClauseProps) {\n // note: the columns order must match the order in `NodeSelectClauseColumnNames`\n return `\n ec_ClassName(${createECSqlValueSelector(props.ecClassId)}) AS ${NodeSelectClauseColumnNames.FullClassName},\n ${createECSqlValueSelector(props.ecInstanceId)} AS ${NodeSelectClauseColumnNames.ECInstanceId},\n ${createECSqlValueSelector(props.nodeLabel)} AS ${NodeSelectClauseColumnNames.DisplayLabel},\n CAST(${createECSqlValueSelector(props.hasChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HasChildren},\n CAST(${createECSqlValueSelector(props.hideIfNoChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideIfNoChildren},\n CAST(${createECSqlValueSelector(props.hideNodeInHierarchy)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideNodeInHierarchy},\n ${props.grouping ? createGroupingSelector(props.grouping) : \"CAST(NULL AS TEXT)\"} AS ${NodeSelectClauseColumnNames.Grouping},\n ${\n props.extendedData\n ? `json_object(${Object.entries(props.extendedData)\n .map(([key, value]) => `'${key}', ${createECSqlValueSelector(value)}`)\n .join(\", \")})`\n : \"CAST(NULL AS TEXT)\"\n } AS ${NodeSelectClauseColumnNames.ExtendedData},\n CAST(${createECSqlValueSelector(props.autoExpand)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.AutoExpand},\n CAST(${createECSqlValueSelector(props.supportsFiltering)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.SupportsFiltering}\n `;\n }\n\n /**\n * Creates the necessary ECSQL snippets to create an instance filter described by the `def` argument.\n * - `from` is set to either the `contentClass.fullName` or `def.propertyClassName`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `def.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `def.filterClassNames` and by properties as described by `def.rules`.\n *\n * Special cases:\n * - If `def` is `undefined`, `joins` and `where` are set to empty strings and `from` is set to `contentClass.fullName`.\n * - If the provided content class doesn't intersect with the property class in provided filter, a special result\n * is returned to make sure the resulting query is valid and doesn't return anything.\n */\n public async createFilterClauses(props: {\n contentClass: { fullName: string; alias: string };\n filter: GenericInstanceFilter | undefined;\n }): Promise<{ from: string; where: string; joins: string }> {\n const { contentClass, filter } = props;\n if (!filter) {\n // undefined filter means we don't want any filtering to be applied\n return { from: contentClass.fullName, joins: \"\", where: \"\" };\n }\n\n const from = await specializeContentClass({\n classHierarchyInspector: this._imodelAccess,\n contentClassName: contentClass.fullName,\n filterClassNames: filter.propertyClassNames,\n });\n if (!from) {\n // filter class doesn't intersect with content class - make sure the query returns nothing by returning a `FALSE` WHERE clause\n return { from: contentClass.fullName, joins: \"\", where: \"FALSE\" };\n }\n\n /**\n * TODO:\n * There may be similar related instance paths, e.g.:\n * - A -> B -> C,\n * - A -> B -> D.\n * At this moment we're handling each path individually which means A and B would get joined twice. We could look into\n * creating a join tree first, e.g.\n * C\n * /\n * A -> B\n * \\\n * D\n */\n const joins = await Promise.all(\n filter.relatedInstances.map(async (rel, i) =>\n ECSql.createRelationshipPathJoinClause({\n schemaProvider: this._imodelAccess,\n path: assignRelationshipPathAliases(rel.path, i, contentClass.alias, rel.alias),\n }),\n ),\n );\n\n const whereConditions = new Array<string>();\n if (filter.filteredClassNames && filter.filteredClassNames.length > 0) {\n whereConditions.push(\n `${ECSql.createRawPropertyValueSelector(contentClass.alias, \"ECClassId\")} IS (\n ${filter.filteredClassNames\n .map(parseFullClassName)\n .map(({ schemaName, className }) => `[${schemaName}].[${className}]`)\n .join(\", \")}\n )`,\n );\n }\n const classAliasMap = new Map<string, string>([[contentClass.alias, from]]);\n filter.relatedInstances.forEach(({ path, alias }) => path.length > 0 && classAliasMap.set(alias, path[path.length - 1].targetClassName));\n const propertiesFilter = await createWhereClause(\n contentClass.alias,\n async (alias) => {\n const aliasClassName = classAliasMap.get(alias);\n return aliasClassName ? getClass(this._imodelAccess, aliasClassName) : undefined;\n },\n filter.rules,\n );\n if (propertiesFilter) {\n whereConditions.push(propertiesFilter);\n }\n\n return {\n from,\n joins: joins.join(\"\\n\"),\n where: whereConditions.join(\" AND \"),\n };\n }\n}\n\nfunction createECSqlValueSelector(input: undefined | PrimitiveValue | ECSqlValueSelector) {\n if (input === undefined) {\n return \"NULL\";\n }\n if (isSelector(input)) {\n return input.selector;\n }\n return ECSql.createRawPrimitiveValueSelector(input);\n}\n\nfunction isSelector(x: any): x is ECSqlValueSelector {\n return !!x.selector;\n}\n\nfunction createGroupingSelector(grouping: ECSqlSelectClauseGroupingParams): string {\n const groupingSelectors = new Array<{ key: string; selector: string }>();\n\n grouping.byLabel &&\n groupingSelectors.push({\n key: \"byLabel\",\n selector:\n typeof grouping.byLabel === \"boolean\" || isSelector(grouping.byLabel)\n ? createECSqlValueSelector(grouping.byLabel)\n : serializeJsonObject(createLabelGroupingBaseParamsSelectors(grouping.byLabel)),\n });\n\n grouping.byClass &&\n groupingSelectors.push({\n key: \"byClass\",\n selector:\n typeof grouping.byClass === \"boolean\" || isSelector(grouping.byClass)\n ? createECSqlValueSelector(grouping.byClass)\n : serializeJsonObject(createBaseGroupingParamSelectors(grouping.byClass)),\n });\n\n grouping.byBaseClasses &&\n groupingSelectors.push({\n key: \"byBaseClasses\",\n selector: serializeJsonObject([\n {\n key: \"fullClassNames\",\n selector: `json_array(${grouping.byBaseClasses.fullClassNames.map((className) => createECSqlValueSelector(className)).join(\", \")})`,\n },\n ...createBaseGroupingParamSelectors(grouping.byBaseClasses),\n ]),\n });\n\n grouping.byProperties &&\n groupingSelectors.push({\n key: \"byProperties\",\n selector: serializeJsonObject([\n {\n key: \"propertiesClassName\",\n selector: `${createECSqlValueSelector(grouping.byProperties.propertiesClassName)}`,\n },\n {\n key: \"propertyGroups\",\n selector: `json_array(${grouping.byProperties.propertyGroups\n .map((propertyGroup) => serializeJsonObject(createPropertyGroupSelectors(propertyGroup)))\n .join(\", \")})`,\n },\n ...(grouping.byProperties.createGroupForOutOfRangeValues !== undefined\n ? [\n {\n key: \"createGroupForOutOfRangeValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForOutOfRangeValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...(grouping.byProperties.createGroupForUnspecifiedValues !== undefined\n ? [\n {\n key: \"createGroupForUnspecifiedValues\",\n selector: `CAST(${createECSqlValueSelector(grouping.byProperties.createGroupForUnspecifiedValues)} AS BOOLEAN)`,\n },\n ]\n : []),\n ...createBaseGroupingParamSelectors(grouping.byProperties),\n ]),\n });\n\n return serializeJsonObject(groupingSelectors);\n}\n\nfunction createLabelGroupingBaseParamsSelectors(byLabel: ECSqlSelectClauseLabelGroupingMergeParams | ECSqlSelectClauseLabelGroupingGroupParams) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (byLabel.action !== undefined) {\n selectors.push({\n key: \"action\",\n selector: `${createECSqlValueSelector(byLabel.action)}`,\n });\n }\n if (byLabel.groupId !== undefined) {\n selectors.push({\n key: \"groupId\",\n selector: createECSqlValueSelector(byLabel.groupId),\n });\n }\n if (byLabel.action !== \"merge\") {\n selectors.push(...createBaseGroupingParamSelectors(byLabel));\n }\n\n return selectors;\n}\n\nfunction createPropertyGroupSelectors(propertyGroup: ECSqlSelectClausePropertyGroup) {\n const selectors = new Array<{ key: string; selector: string }>();\n selectors.push(\n {\n key: \"propertyName\",\n selector: `${createECSqlValueSelector(propertyGroup.propertyName)}`,\n },\n {\n key: \"propertyValue\",\n selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,\n },\n );\n if (propertyGroup.ranges) {\n selectors.push(createRangeParamSelectors(propertyGroup.ranges));\n }\n return selectors;\n}\n\nfunction createRangeParamSelectors(ranges: ECSqlSelectClausePropertyValueRange[]) {\n return {\n key: \"ranges\",\n selector: `json_array(${ranges\n .map((range) =>\n serializeJsonObject([\n {\n key: \"fromValue\",\n selector: createECSqlValueSelector(range.fromValue),\n },\n {\n key: \"toValue\",\n selector: createECSqlValueSelector(range.toValue),\n },\n ...(range.rangeLabel\n ? [\n {\n key: \"rangeLabel\",\n selector: `${createECSqlValueSelector(range.rangeLabel)}`,\n },\n ]\n : []),\n ]),\n )\n .join(\", \")})`,\n };\n}\n\nfunction createBaseGroupingParamSelectors(params: ECSqlSelectClauseGroupingParamsBase) {\n const selectors = new Array<{ key: string; selector: string }>();\n if (params.hideIfNoSiblings !== undefined) {\n selectors.push({\n key: \"hideIfNoSiblings\",\n selector: createECSqlValueSelector(params.hideIfNoSiblings),\n });\n }\n if (params.hideIfOneGroupedNode !== undefined) {\n selectors.push({\n key: \"hideIfOneGroupedNode\",\n selector: createECSqlValueSelector(params.hideIfOneGroupedNode),\n });\n }\n if (params.autoExpand !== undefined) {\n selectors.push({\n key: \"autoExpand\",\n selector: createECSqlValueSelector(params.autoExpand),\n });\n }\n return selectors;\n}\n\nfunction serializeJsonObject(selectors: Array<{ key: string; selector: string }>): string {\n return `json_object(${selectors.map(({ key, selector }) => `'${key}', ${selector}`).join(\", \")})`;\n}\n\nasync function createWhereClause(\n contentClassAlias: string,\n classLoader: (alias: string) => Promise<EC.Class | undefined>,\n rule: GenericInstanceFilterRule | GenericInstanceFilterRuleGroup,\n): Promise<string | undefined> {\n if (GenericInstanceFilter.isFilterRuleGroup(rule)) {\n const clause = (await Promise.all(rule.rules.map(async (r) => createWhereClause(contentClassAlias, classLoader, r))))\n .filter((c) => !!c)\n .join(` ${getECSqlLogicalOperator(rule.operator)} `);\n return clause ? (rule.operator === \"or\" ? `(${clause})` : clause) : undefined;\n }\n const sourceAlias = rule.sourceAlias ? rule.sourceAlias : contentClassAlias;\n const propertyValueSelector = ECSql.createRawPropertyValueSelector(sourceAlias, rule.propertyName);\n if (isUnaryRuleOperator(rule.operator)) {\n switch (rule.operator) {\n case \"is-true\":\n return propertyValueSelector;\n case \"is-false\":\n return `NOT ${propertyValueSelector}`;\n case \"is-null\":\n return `${propertyValueSelector} IS NULL`;\n case \"is-not-null\":\n return `${propertyValueSelector} IS NOT NULL`;\n }\n }\n const ecsqlOperator = getECSqlComparisonOperator(rule.operator);\n if (rule.value === undefined) {\n throw new Error(`Rule \"${rule.propertyName}\" ${ecsqlOperator} is missing value.`);\n }\n\n const value = rule.value.rawValue;\n\n if (rule.operator === \"like\" && typeof value === \"string\") {\n const escapedValue = value.replace(/[%_\\\\]/g, \"\\\\$&\");\n return `${propertyValueSelector} ${ecsqlOperator} '%${escapedValue}%' ESCAPE '\\\\'`;\n }\n const propertyClass = await classLoader(sourceAlias);\n if (!propertyClass) {\n throw new Error(`Class with alias \"${sourceAlias}\" not found.`);\n }\n const property = await propertyClass.getProperty(rule.propertyName);\n if (!property) {\n throw new Error(`Property \"${rule.propertyName}\" not found in ECClass \"${propertyClass.fullName}\".`);\n }\n if (property.isNavigation()) {\n assert(rule.value !== undefined && GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector}.[Id] ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value.id)}`;\n }\n if (property.isEnumeration()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n if (property.isPrimitive()) {\n assert(rule.value !== undefined && !GenericInstanceFilterRuleValue.isInstanceKey(value));\n switch (property.primitiveType) {\n case \"Point2d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint2d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Point3d\": {\n assert(rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\");\n assert(PrimitiveValue.isPoint3d(value));\n const condition = `\n ${createFloatingPointEqualityClause(`${propertyValueSelector}.[x]`, \"is-equal\", value.x)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[y]`, \"is-equal\", value.y)}\n AND ${createFloatingPointEqualityClause(`${propertyValueSelector}.[z]`, \"is-equal\", value.z)}\n `;\n return rule.operator === \"is-equal\" ? condition : `NOT (${condition})`;\n }\n case \"Double\": {\n assert(typeof value === \"number\");\n if (rule.operator === \"is-equal\" || rule.operator === \"is-not-equal\") {\n return `${createFloatingPointEqualityClause(propertyValueSelector, rule.operator, value)}`;\n }\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n default: {\n return `${propertyValueSelector} ${ecsqlOperator} ${ECSql.createRawPrimitiveValueSelector(value)}`;\n }\n }\n }\n throw new Error(\"Struct and array properties are not supported for filtering\");\n}\n\nfunction createFloatingPointEqualityClause(valueSelector: string, operator: \"is-equal\" | \"is-not-equal\", value: number) {\n const [from, to] = getFloatingPointValueRange(value);\n return `${valueSelector} ${operator === \"is-not-equal\" ? \"NOT \" : \"\"} BETWEEN ${from} AND ${to}`;\n}\n\nfunction getFloatingPointValueRange(value: number): [number, number] {\n return [value - Number.EPSILON, value + Number.EPSILON];\n}\n\nfunction getECSqlLogicalOperator(op: GenericInstanceFilterRuleGroupOperator) {\n switch (op) {\n case \"and\":\n return \"AND\";\n case \"or\":\n return \"OR\";\n }\n}\n\nfunction isUnaryRuleOperator(\n op: GenericInstanceFilterRuleOperator,\n): op is Extract<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\"> {\n return op === \"is-true\" || op === \"is-false\" || op === \"is-null\" || op === \"is-not-null\";\n}\n\nfunction getECSqlComparisonOperator(op: Exclude<GenericInstanceFilterRuleOperator, \"is-true\" | \"is-false\" | \"is-null\" | \"is-not-null\">) {\n switch (op) {\n case \"is-equal\":\n return `=`;\n case \"is-not-equal\":\n return `<>`;\n case \"greater\":\n return `>`;\n case \"greater-or-equal\":\n return `>=`;\n case \"less\":\n return `<`;\n case \"less-or-equal\":\n return `<=`;\n case \"like\":\n return `LIKE`;\n }\n}\n\ntype JoinRelationshipPath = Parameters<typeof ECSql.createRelationshipPathJoinClause>[0][\"path\"];\nfunction assignRelationshipPathAliases(\n path: GenericInstanceFilterRelationshipStep[],\n pathIndex: number,\n sourceAlias: string,\n targetAlias: string,\n): JoinRelationshipPath {\n function createAlias(fullClassName: string, index: number) {\n return `rel_${pathIndex}_${fullClassName.replaceAll(/[\\.:]/g, \"_\")}_${index}`;\n }\n const result: JoinRelationshipPath = [];\n path.forEach((step, i) => {\n result.push({\n targetClassName: step.targetClassName,\n relationshipName: step.relationshipClassName,\n sourceClassName: step.sourceClassName,\n relationshipReverse: !step.isForwardRelationship,\n sourceAlias: i === 0 ? sourceAlias : result[i - 1].targetAlias,\n relationshipAlias: createAlias(step.relationshipClassName, i),\n targetAlias: i === path.length - 1 ? targetAlias : createAlias(step.targetClassName, i),\n joinType: \"inner\",\n });\n });\n return result;\n}\n\ninterface SpecializeContentClassProps {\n classHierarchyInspector: ECClassHierarchyInspector;\n contentClassName: string;\n filterClassNames: string[];\n}\nasync function specializeContentClass(props: SpecializeContentClassProps): Promise<string | undefined> {\n const filterClass = await getSpecializedPropertyClass(props.classHierarchyInspector, props.filterClassNames);\n if (!filterClass) {\n return props.contentClassName;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(filterClass, props.contentClassName)) {\n return filterClass;\n }\n if (await props.classHierarchyInspector.classDerivesFrom(props.contentClassName, filterClass)) {\n return props.contentClassName;\n }\n return undefined;\n}\n\nasync function getSpecializedPropertyClass(classHierarchyInspector: ECClassHierarchyInspector, classes: string[]): Promise<string | undefined> {\n if (classes.length === 0) {\n return undefined;\n }\n const [currClassName, ...restClasses] = classes;\n let resolvedClassName = currClassName;\n for (const propClassName of restClasses) {\n if (await classHierarchyInspector.classDerivesFrom(propClassName, resolvedClassName)) {\n resolvedClassName = propClassName;\n }\n }\n return resolvedClassName;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/presentation-hierarchies",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A package for creating hierarchies based on data in iTwin.js iModels.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "@itwin/presentation-shared": "^0.3.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@itwin/build-tools": "^4.6.0",
36
+ "@itwin/build-tools": "^4.7.1",
37
37
  "@itwin/eslint-plugin": "^4.0.0",
38
38
  "@types/chai": "^4.3.14",
39
39
  "@types/chai-as-promised": "^7.1.8",