@itwin/presentation-hierarchies 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +25 -4
  3. package/lib/cjs/hierarchies/HierarchyNode.d.ts +17 -7
  4. package/lib/cjs/hierarchies/HierarchyNode.d.ts.map +1 -1
  5. package/lib/cjs/hierarchies/HierarchyNode.js.map +1 -1
  6. package/lib/cjs/hierarchies/HierarchyProvider.d.ts +23 -3
  7. package/lib/cjs/hierarchies/HierarchyProvider.d.ts.map +1 -1
  8. package/lib/cjs/hierarchies/HierarchyProvider.js +2 -3
  9. package/lib/cjs/hierarchies/HierarchyProvider.js.map +1 -1
  10. package/lib/cjs/hierarchies/NodeSelectQueryFactory.d.ts +3 -2
  11. package/lib/cjs/hierarchies/NodeSelectQueryFactory.d.ts.map +1 -1
  12. package/lib/cjs/hierarchies/NodeSelectQueryFactory.js +37 -11
  13. package/lib/cjs/hierarchies/NodeSelectQueryFactory.js.map +1 -1
  14. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.d.ts +16 -6
  15. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.d.ts.map +1 -1
  16. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.js +96 -15
  17. package/lib/cjs/hierarchies/internal/FilteringHierarchyDefinition.js.map +1 -1
  18. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.d.ts.map +1 -1
  19. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.js +10 -5
  20. package/lib/cjs/hierarchies/internal/operators/grouping/PropertiesGrouping.js.map +1 -1
  21. package/lib/cjs/presentation-hierarchies.d.ts +1 -1
  22. package/lib/cjs/presentation-hierarchies.d.ts.map +1 -1
  23. package/lib/cjs/presentation-hierarchies.js.map +1 -1
  24. package/lib/esm/hierarchies/HierarchyNode.d.ts +17 -7
  25. package/lib/esm/hierarchies/HierarchyNode.d.ts.map +1 -1
  26. package/lib/esm/hierarchies/HierarchyNode.js.map +1 -1
  27. package/lib/esm/hierarchies/HierarchyProvider.d.ts +23 -3
  28. package/lib/esm/hierarchies/HierarchyProvider.d.ts.map +1 -1
  29. package/lib/esm/hierarchies/HierarchyProvider.js +2 -3
  30. package/lib/esm/hierarchies/HierarchyProvider.js.map +1 -1
  31. package/lib/esm/hierarchies/NodeSelectQueryFactory.d.ts +3 -2
  32. package/lib/esm/hierarchies/NodeSelectQueryFactory.d.ts.map +1 -1
  33. package/lib/esm/hierarchies/NodeSelectQueryFactory.js +38 -12
  34. package/lib/esm/hierarchies/NodeSelectQueryFactory.js.map +1 -1
  35. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.d.ts +16 -6
  36. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.d.ts.map +1 -1
  37. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.js +95 -14
  38. package/lib/esm/hierarchies/internal/FilteringHierarchyDefinition.js.map +1 -1
  39. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.d.ts.map +1 -1
  40. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.js +11 -6
  41. package/lib/esm/hierarchies/internal/operators/grouping/PropertiesGrouping.js.map +1 -1
  42. package/lib/esm/presentation-hierarchies.d.ts +1 -1
  43. package/lib/esm/presentation-hierarchies.d.ts.map +1 -1
  44. package/lib/esm/presentation-hierarchies.js +1 -1
  45. package/lib/esm/presentation-hierarchies.js.map +1 -1
  46. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSelectQueryFactory.d.ts","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":"AAKA,OAAO,EAAU,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EACL,qBAAqB,EAOtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAM,yBAAyB,EAAE,gBAAgB,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IACxF,kBAAkB,EAAE,MAAM,CAAC;IAC3B,8FAA8F;IAC9F,MAAM,CAAC,EAAE,mCAAmC,EAAE,CAAC;CAChD;AAED;;;GAGG;AACH,UAAU,mCAAmC;IAC3C,4CAA4C;IAC5C,SAAS,EAAE,MAAM,GAAG,kBAAkB,CAAC;IACvC,4CAA4C;IAC5C,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAAC;IACrC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAAC;CAC1C;AAED;;;GAGG;AACH,UAAU,wCAAyC,SAAQ,mCAAmC;IAC5F,cAAc,EAAE,MAAM,EAAE,GAAG,kBAAkB,EAAE,CAAC;CACjD;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,uGAAuG;IACvG,kBAAkB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAElE;;;;;;;;;;;OAWG;IACH,mBAAmB,CAAC,KAAK,EAAE;QACzB,YAAY,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QAClD,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAAC;KAC3C,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7D;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE;IACnD,YAAY,EAAE,gBAAgB,GAAG,yBAAyB,CAAC;IAC3D,gCAAgC,EAAE,iCAAiC,CAAC;CACrE,GAAG,uBAAuB,CAE1B"}
@@ -44,7 +44,7 @@ var NodeSelectClauseColumnNames;
44
44
  NodeSelectClauseColumnNames["SupportsFiltering"] = "SupportsFiltering";
45
45
  })(NodeSelectClauseColumnNames || (exports.NodeSelectClauseColumnNames = NodeSelectClauseColumnNames = {}));
46
46
  /**
47
- * Creates an instance of `NodeSelectQueryFactory` that .
47
+ * Creates an instance of `NodeSelectQueryFactory`.
48
48
  * @beta
49
49
  */
50
50
  function createNodesQueryClauseFactory(props) {
@@ -53,8 +53,10 @@ function createNodesQueryClauseFactory(props) {
53
53
  /** A factory for creating a nodes' select ECSQL query. */
54
54
  class NodeSelectQueryFactory {
55
55
  _imodelAccess;
56
+ _instanceLabelSelectClauseFactory;
56
57
  constructor(props) {
57
58
  this._imodelAccess = props.imodelAccess;
59
+ this._instanceLabelSelectClauseFactory = props.instanceLabelSelectClauseFactory;
58
60
  }
59
61
  /** Create a SELECT clause in a format understood by results reader of the library. */
60
62
  async createSelectClause(props) {
@@ -66,7 +68,7 @@ class NodeSelectQueryFactory {
66
68
  CAST(${createECSqlValueSelector(props.hasChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HasChildren},
67
69
  CAST(${createECSqlValueSelector(props.hideIfNoChildren)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideIfNoChildren},
68
70
  CAST(${createECSqlValueSelector(props.hideNodeInHierarchy)} AS BOOLEAN) AS ${NodeSelectClauseColumnNames.HideNodeInHierarchy},
69
- ${props.grouping ? createGroupingSelector(props.grouping) : "CAST(NULL AS TEXT)"} AS ${NodeSelectClauseColumnNames.Grouping},
71
+ ${props.grouping ? await createGroupingSelector(props.grouping, this._imodelAccess, this._instanceLabelSelectClauseFactory) : "CAST(NULL AS TEXT)"} AS ${NodeSelectClauseColumnNames.Grouping},
70
72
  ${props.extendedData
71
73
  ? `json_object(${Object.entries(props.extendedData)
72
74
  .map(([key, value]) => `'${key}', ${createECSqlValueSelector(value)}`)
@@ -157,7 +159,7 @@ function createECSqlValueSelector(input) {
157
159
  function isSelector(x) {
158
160
  return !!x.selector;
159
161
  }
160
- function createGroupingSelector(grouping) {
162
+ async function createGroupingSelector(grouping, imodelAccess, instanceLabelSelectClauseFactory) {
161
163
  const groupingSelectors = new Array();
162
164
  grouping.byLabel &&
163
165
  groupingSelectors.push({
@@ -184,7 +186,8 @@ function createGroupingSelector(grouping) {
184
186
  ...createBaseGroupingParamSelectors(grouping.byBaseClasses),
185
187
  ]),
186
188
  });
187
- grouping.byProperties &&
189
+ if (grouping.byProperties) {
190
+ const propertyClass = await (0, presentation_shared_1.getClass)(imodelAccess, grouping.byProperties.propertiesClassName);
188
191
  groupingSelectors.push({
189
192
  key: "byProperties",
190
193
  selector: serializeJsonObject([
@@ -194,9 +197,7 @@ function createGroupingSelector(grouping) {
194
197
  },
195
198
  {
196
199
  key: "propertyGroups",
197
- selector: `json_array(${grouping.byProperties.propertyGroups
198
- .map((propertyGroup) => serializeJsonObject(createPropertyGroupSelectors(propertyGroup)))
199
- .join(", ")})`,
200
+ selector: `json_array(${(await Promise.all(grouping.byProperties.propertyGroups.map(async (propertyGroup) => serializeJsonObject(await createPropertyGroupSelectors(propertyGroup, propertyClass, instanceLabelSelectClauseFactory))))).join(", ")})`,
200
201
  },
201
202
  ...(grouping.byProperties.createGroupForOutOfRangeValues !== undefined
202
203
  ? [
@@ -217,6 +218,7 @@ function createGroupingSelector(grouping) {
217
218
  ...createBaseGroupingParamSelectors(grouping.byProperties),
218
219
  ]),
219
220
  });
221
+ }
220
222
  return serializeJsonObject(groupingSelectors);
221
223
  }
222
224
  function createLabelGroupingBaseParamsSelectors(byLabel) {
@@ -238,15 +240,39 @@ function createLabelGroupingBaseParamsSelectors(byLabel) {
238
240
  }
239
241
  return selectors;
240
242
  }
241
- function createPropertyGroupSelectors(propertyGroup) {
243
+ async function createPropertyGroupSelectors(propertyGroup, propertyClass, instanceLabelSelectClauseFactory) {
242
244
  const selectors = new Array();
243
245
  selectors.push({
244
246
  key: "propertyName",
245
247
  selector: `${createECSqlValueSelector(propertyGroup.propertyName)}`,
246
- }, {
247
- key: "propertyValue",
248
- selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,
249
248
  });
249
+ const property = await propertyClass.getProperty(propertyGroup.propertyName);
250
+ if (!property) {
251
+ throw new Error(`Property "${propertyGroup.propertyName}" not found in ECClass "${propertyClass.fullName}".`);
252
+ }
253
+ if (property.isNavigation()) {
254
+ const relationshipClass = await property.relationshipClass;
255
+ const abstractConstraint = property.direction === "Forward" ? await relationshipClass.target.abstractConstraint : await relationshipClass.source.abstractConstraint;
256
+ if (!abstractConstraint) {
257
+ throw new Error(`Could not determine class name for navigation property with direction "${property.direction}".`);
258
+ }
259
+ const fullName = abstractConstraint.fullName;
260
+ const targetAlias = "target";
261
+ selectors.push({
262
+ key: "propertyValue",
263
+ selector: `(
264
+ SELECT ${await instanceLabelSelectClauseFactory.createSelectClause({ className: fullName, classAlias: targetAlias })}
265
+ FROM ${fullName} AS ${targetAlias}
266
+ WHERE [${targetAlias}].[ECInstanceId] = [${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}].[Id]
267
+ )`,
268
+ });
269
+ }
270
+ else {
271
+ selectors.push({
272
+ key: "propertyValue",
273
+ selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,
274
+ });
275
+ }
250
276
  if (propertyGroup.ranges) {
251
277
  selectors.push(createRangeParamSelectors(propertyGroup.ranges));
252
278
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NodeSelectQueryFactory.js","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAuPhG,sEAEC;AAvPD,sDAAyD;AACzD,oDAQ4B;AAC5B,oEAAkJ;AAGlJ;;;;;GAKG;AACH,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,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AC;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\";\nimport { HierarchyNodeAutoExpandProp } from \"./HierarchyNode\";\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 * @beta\n */\ninterface ECSqlValueSelector {\n selector: string;\n}\n\n/**\n * Props for `NodeSelectClauseFactory.createSelectClause`.\n * @beta\n */\ninterface NodeSelectClauseProps {\n ecClassId: ECSqlValueSelector;\n ecInstanceId: 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 * @beta\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 * @beta\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 * @beta\n */\ninterface ECSqlSelectClauseLabelGroupingMergeParams extends ECSqlSelectClauseLabelGroupingBaseParams {\n action: \"merge\";\n}\n\n/**\n * A data structure for defining label grouping.\n * @beta\n */\ninterface ECSqlSelectClauseLabelGroupingGroupParams extends ECSqlSelectClauseLabelGroupingBaseParams, ECSqlSelectClauseGroupingParamsBase {\n action?: \"group\";\n}\n\n/**\n * A data structure for defining possible label grouping types.\n * @beta\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 * @beta\n */\ninterface ECSqlSelectClauseGroupingParamsBase {\n hideIfNoSiblings?: boolean | ECSqlValueSelector;\n hideIfOneGroupedNode?: boolean | ECSqlValueSelector;\n autoExpand?: HierarchyNodeAutoExpandProp | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining properties grouping.\n * @beta\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 * @beta\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 * @beta\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 * @beta\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 /**\n * Creates the necessary ECSQL snippets to create an instance filter described by the given `GenericInstanceFilter` argument.\n * - `from` is set to either the `contentClass.fullName` or one of `filter.propertyClassNames`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `filter.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `filter.filterClassNames` and by properties as described by `filter.rules`.\n *\n * Special cases:\n * - If `filter` 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 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(${props.ecClassId.selector}) AS ${NodeSelectClauseColumnNames.FullClassName},\n ${props.ecInstanceId.selector} 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 `filter` argument.\n * - `from` is set to either the `contentClass.fullName` or one of `filter.propertyClassNames`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `filter.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `filter.filterClassNames` and by properties as described by `filter.rules`.\n *\n * Special cases:\n * - If `filter` 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"]}
1
+ {"version":3,"file":"NodeSelectQueryFactory.js","sourceRoot":"","sources":["../../../src/hierarchies/NodeSelectQueryFactory.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAgQhG,sEAKC;AAnQD,sDAAyD;AACzD,oDAQ4B;AAC5B,oEASoC;AAGpC;;;;;GAKG;AACH,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,2EAA2E;IAC3E,wDAAyB,CAAA;IACzB,2EAA2E;IAC3E,sEAAuC,CAAA;AACzC,CAAC,EA1BW,2BAA2B,2CAA3B,2BAA2B,QA0BtC;AAoMD;;;GAGG;AACH,SAAgB,6BAA6B,CAAC,KAG7C;IACC,OAAO,IAAI,sBAAsB,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED,0DAA0D;AAC1D,MAAM,sBAAsB;IAClB,aAAa,CAA+C;IAC5D,iCAAiC,CAAoC;IAE7E,YAAmB,KAGlB;QACC,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,iCAAiC,GAAG,KAAK,CAAC,gCAAgC,CAAC;IAClF,CAAC;IAED,sFAAsF;IAC/E,KAAK,CAAC,kBAAkB,CAAC,KAA4B;QAC1D,gFAAgF;QAChF,OAAO;qBACU,KAAK,CAAC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,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 {\n EC,\n ECClassHierarchyInspector,\n ECSchemaProvider,\n ECSql,\n getClass,\n IInstanceLabelSelectClauseFactory,\n parseFullClassName,\n PrimitiveValue,\n} from \"@itwin/presentation-shared\";\nimport { HierarchyNodeAutoExpandProp } from \"./HierarchyNode\";\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 * @beta\n */\ninterface ECSqlValueSelector {\n selector: string;\n}\n\n/**\n * Props for `NodeSelectClauseFactory.createSelectClause`.\n * @beta\n */\ninterface NodeSelectClauseProps {\n ecClassId: ECSqlValueSelector;\n ecInstanceId: 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 * @beta\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 * @beta\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 * @beta\n */\ninterface ECSqlSelectClauseLabelGroupingMergeParams extends ECSqlSelectClauseLabelGroupingBaseParams {\n action: \"merge\";\n}\n\n/**\n * A data structure for defining label grouping.\n * @beta\n */\ninterface ECSqlSelectClauseLabelGroupingGroupParams extends ECSqlSelectClauseLabelGroupingBaseParams, ECSqlSelectClauseGroupingParamsBase {\n action?: \"group\";\n}\n\n/**\n * A data structure for defining possible label grouping types.\n * @beta\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 * @beta\n */\ninterface ECSqlSelectClauseGroupingParamsBase {\n hideIfNoSiblings?: boolean | ECSqlValueSelector;\n hideIfOneGroupedNode?: boolean | ECSqlValueSelector;\n autoExpand?: HierarchyNodeAutoExpandProp | ECSqlValueSelector;\n}\n\n/**\n * A data structure for defining properties grouping.\n * @beta\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 * @beta\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 * @beta\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 * @beta\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 /**\n * Creates the necessary ECSQL snippets to create an instance filter described by the given `GenericInstanceFilter` argument.\n * - `from` is set to either the `contentClass.fullName` or one of `filter.propertyClassNames`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `filter.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `filter.filterClassNames` and by properties as described by `filter.rules`.\n *\n * Special cases:\n * - If `filter` 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 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`.\n * @beta\n */\nexport function createNodesQueryClauseFactory(props: {\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector;\n instanceLabelSelectClauseFactory: IInstanceLabelSelectClauseFactory;\n}): 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 private _instanceLabelSelectClauseFactory: IInstanceLabelSelectClauseFactory;\n\n public constructor(props: {\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector;\n instanceLabelSelectClauseFactory: IInstanceLabelSelectClauseFactory;\n }) {\n this._imodelAccess = props.imodelAccess;\n this._instanceLabelSelectClauseFactory = props.instanceLabelSelectClauseFactory;\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(${props.ecClassId.selector}) AS ${NodeSelectClauseColumnNames.FullClassName},\n ${props.ecInstanceId.selector} 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 ? await createGroupingSelector(props.grouping, this._imodelAccess, this._instanceLabelSelectClauseFactory) : \"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 `filter` argument.\n * - `from` is set to either the `contentClass.fullName` or one of `filter.propertyClassNames`, depending on which is more specific.\n * - `joins` is set to a number of `JOIN` clauses required to join all relationships described by `filter.relatedInstances`.\n * - `where` is set to a `WHERE` clause (without the `WHERE` keyword) that filters instances by classes on\n * `filter.filterClassNames` and by properties as described by `filter.rules`.\n *\n * Special cases:\n * - If `filter` 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\nasync function createGroupingSelector(\n grouping: ECSqlSelectClauseGroupingParams,\n imodelAccess: ECSchemaProvider & ECClassHierarchyInspector,\n instanceLabelSelectClauseFactory: IInstanceLabelSelectClauseFactory,\n): Promise<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 if (grouping.byProperties) {\n const propertyClass = await getClass(imodelAccess, grouping.byProperties.propertiesClassName);\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(${(\n await Promise.all(\n grouping.byProperties.propertyGroups.map(async (propertyGroup) =>\n serializeJsonObject(await createPropertyGroupSelectors(propertyGroup, propertyClass, instanceLabelSelectClauseFactory)),\n ),\n )\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\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\nasync function createPropertyGroupSelectors(\n propertyGroup: ECSqlSelectClausePropertyGroup,\n propertyClass: EC.Class,\n instanceLabelSelectClauseFactory: IInstanceLabelSelectClauseFactory,\n) {\n const selectors = new Array<{ key: string; selector: string }>();\n selectors.push({\n key: \"propertyName\",\n selector: `${createECSqlValueSelector(propertyGroup.propertyName)}`,\n });\n\n const property = await propertyClass.getProperty(propertyGroup.propertyName);\n if (!property) {\n throw new Error(`Property \"${propertyGroup.propertyName}\" not found in ECClass \"${propertyClass.fullName}\".`);\n }\n\n if (property.isNavigation()) {\n const relationshipClass = await property.relationshipClass;\n const abstractConstraint =\n property.direction === \"Forward\" ? await relationshipClass.target.abstractConstraint : await relationshipClass.source.abstractConstraint;\n if (!abstractConstraint) {\n throw new Error(`Could not determine class name for navigation property with direction \"${property.direction}\".`);\n }\n\n const fullName = abstractConstraint.fullName;\n const targetAlias = \"target\";\n selectors.push({\n key: \"propertyValue\",\n selector: `(\n SELECT ${await instanceLabelSelectClauseFactory.createSelectClause({ className: fullName, classAlias: targetAlias })}\n FROM ${fullName} AS ${targetAlias}\n WHERE [${targetAlias}].[ECInstanceId] = [${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}].[Id]\n )`,\n });\n } else {\n selectors.push({\n key: \"propertyValue\",\n selector: `[${propertyGroup.propertyClassAlias}].[${propertyGroup.propertyName}]`,\n });\n }\n\n if (propertyGroup.ranges) {\n selectors.push(createRangeParamSelectors(propertyGroup.ranges));\n }\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"]}
@@ -1,6 +1,7 @@
1
1
  import { ECClassHierarchyInspector, InstanceKey } from "@itwin/presentation-shared";
2
2
  import { DefineHierarchyLevelProps, HierarchyDefinition, HierarchyLevelDefinition, InstanceNodesQueryDefinition, NodeParser, NodePostProcessor, NodePreProcessor } from "../HierarchyDefinition";
3
- import { HierarchyFilteringPath } from "../HierarchyProvider";
3
+ import { HierarchyNodeIdentifier } from "../HierarchyNodeIdentifier";
4
+ import { HierarchyFilteringPath, HierarchyFilteringPathOptions } from "../HierarchyProvider";
4
5
  /** @internal */
5
6
  export interface FilteringQueryBuilderProps {
6
7
  classHierarchy: ECClassHierarchyInspector;
@@ -14,21 +15,30 @@ export declare class FilteringHierarchyDefinition implements HierarchyDefinition
14
15
  private _nodeIdentifierPaths;
15
16
  constructor(props: FilteringQueryBuilderProps);
16
17
  get preProcessNode(): NodePreProcessor;
18
+ private shouldExpandGroupingNode;
17
19
  get postProcessNode(): NodePostProcessor;
18
20
  get parseNode(): NodeParser;
19
21
  defineHierarchyLevel(props: DefineHierarchyLevelProps): Promise<HierarchyLevelDefinition>;
20
22
  private getFilteringProps;
21
23
  }
24
+ type MatchedFilter<TIdentifier extends HierarchyNodeIdentifier> = {
25
+ id: TIdentifier;
26
+ childrenIdentifierPaths: HierarchyFilteringPath[];
27
+ } & ({
28
+ isFilterTarget: false;
29
+ } | {
30
+ isFilterTarget: true;
31
+ filterTargetOptions?: HierarchyFilteringPathOptions;
32
+ });
22
33
  /** @internal */
23
34
  export declare const ECSQL_COLUMN_NAME_FilteredChildrenPaths = "FilteredChildrenPaths";
24
35
  /** @internal */
25
36
  export declare const ECSQL_COLUMN_NAME_IsFilterTarget = "IsFilterTarget";
26
37
  /** @internal */
38
+ export declare const ECSQL_COLUMN_NAME_FilterTargetOptions = "FilterTargetOptions";
39
+ /** @internal */
27
40
  export declare const ECSQL_COLUMN_NAME_HasFilterTargetAncestor = "HasFilterTargetAncestor";
28
41
  /** @internal */
29
- export declare function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, matchingFilters: Array<{
30
- id: InstanceKey;
31
- isFilterTarget: boolean;
32
- childrenIdentifierPaths: HierarchyFilteringPath[];
33
- }>, isParentFilterTarget: boolean, hasFilterTargetAncestor: boolean): InstanceNodesQueryDefinition;
42
+ export declare function applyECInstanceIdsFilter(def: InstanceNodesQueryDefinition, matchingFilters: Array<MatchedFilter<InstanceKey>>, isParentFilterTarget: boolean, hasFilterTargetAncestor: boolean): InstanceNodesQueryDefinition;
43
+ export {};
34
44
  //# sourceMappingURL=FilteringHierarchyDefinition.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/internal/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAEL,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,gBAAgB;AAChB,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,yBAAyB,CAAC;IAC1C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;gBAEpC,KAAK,EAAE,0BAA0B;IAMpD,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,IAAW,eAAe,IAAI,iBAAiB,CAgB9C;IAED,IAAW,SAAS,IAAI,UAAU,CAUjC;IAEY,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA4DtG,OAAO,CAAC,iBAAiB;CAU1B;AAmGD,gBAAgB;AAEhB,eAAO,MAAM,uCAAuC,0BAA0B,CAAC;AAE/E,gBAAgB;AAEhB,eAAO,MAAM,gCAAgC,mBAAmB,CAAC;AAEjE,gBAAgB;AAEhB,eAAO,MAAM,yCAAyC,4BAA4B,CAAC;AAEnF,gBAAgB;AAChB,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,4BAA4B,EACjC,eAAe,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,WAAW,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC;IAAC,uBAAuB,EAAE,sBAAsB,EAAE,CAAA;CAAE,CAAC,EACvH,oBAAoB,EAAE,OAAO,EAC7B,uBAAuB,EAAE,OAAO,GAC/B,4BAA4B,CAkC9B"}
1
+ {"version":3,"file":"FilteringHierarchyDefinition.d.ts","sourceRoot":"","sources":["../../../../src/hierarchies/internal/FilteringHierarchyDefinition.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAEL,yBAAyB,EACzB,mBAAmB,EACnB,wBAAwB,EAExB,4BAA4B,EAC5B,UAAU,EACV,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAG7F,gBAAgB;AAChB,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,yBAAyB,CAAC;IAC1C,MAAM,EAAE,mBAAmB,CAAC;IAC5B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;CAC/C;AAED,gBAAgB;AAChB,qBAAa,4BAA6B,YAAW,mBAAmB;IACtE,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,OAAO,CAAsB;IACrC,OAAO,CAAC,oBAAoB,CAA2B;gBAEpC,KAAK,EAAE,0BAA0B;IAMpD,IAAW,cAAc,IAAI,gBAAgB,CAS5C;IAED,OAAO,CAAC,wBAAwB;IA2ChC,IAAW,eAAe,IAAI,iBAAiB,CAS9C;IAED,IAAW,SAAS,IAAI,UAAU,CAmBjC;IAEY,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IA4DtG,OAAO,CAAC,iBAAiB;CAU1B;AAED,KAAK,aAAa,CAAC,WAAW,SAAS,uBAAuB,IAAI;IAChE,EAAE,EAAE,WAAW,CAAC;IAChB,uBAAuB,EAAE,sBAAsB,EAAE,CAAC;CACnD,GAAG,CAAC;IAAE,cAAc,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,cAAc,EAAE,IAAI,CAAC;IAAC,mBAAmB,CAAC,EAAE,6BAA6B,CAAA;CAAE,CAAC,CAAC;AAkIhH,gBAAgB;AAEhB,eAAO,MAAM,uCAAuC,0BAA0B,CAAC;AAE/E,gBAAgB;AAEhB,eAAO,MAAM,gCAAgC,mBAAmB,CAAC;AAEjE,gBAAgB;AAEhB,eAAO,MAAM,qCAAqC,wBAAwB,CAAC;AAE3E,gBAAgB;AAEhB,eAAO,MAAM,yCAAyC,4BAA4B,CAAC;AAEnF,gBAAgB;AAChB,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,4BAA4B,EACjC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,EAClD,oBAAoB,EAAE,OAAO,EAC7B,uBAAuB,EAAE,OAAO,GAC/B,4BAA4B,CAoC9B"}
@@ -4,7 +4,7 @@
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = exports.ECSQL_COLUMN_NAME_IsFilterTarget = exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths = exports.FilteringHierarchyDefinition = void 0;
7
+ exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = exports.ECSQL_COLUMN_NAME_FilterTargetOptions = exports.ECSQL_COLUMN_NAME_IsFilterTarget = exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths = exports.FilteringHierarchyDefinition = void 0;
8
8
  exports.applyECInstanceIdsFilter = applyECInstanceIdsFilter;
9
9
  const HierarchyDefinition_1 = require("../HierarchyDefinition");
10
10
  const HierarchyNode_1 = require("../HierarchyNode");
@@ -30,28 +30,70 @@ class FilteringHierarchyDefinition {
30
30
  return processedNode;
31
31
  };
32
32
  }
33
+ shouldExpandGroupingNode(node) {
34
+ for (const child of node.children) {
35
+ // istanbul ignore next
36
+ if (!child.filtering) {
37
+ continue;
38
+ }
39
+ if (child.filtering.isFilterTarget) {
40
+ const childAutoExpand = child.filtering.filterTargetOptions?.autoExpand;
41
+ // If child is a filter target and is has no `autoExpand` flag, then it's always to be expanded.
42
+ if (childAutoExpand === true) {
43
+ return true;
44
+ }
45
+ // If it's not an object and not `true`, then it's falsy - continue looking
46
+ if (typeof childAutoExpand !== "object") {
47
+ continue;
48
+ }
49
+ // If grouping node's child has `autoExpandUntil` flag,
50
+ // auto-expand the grouping node only if it's depth is lower than that of the grouping node in associated with the target.
51
+ const nodeDepth = node.parentKeys.length;
52
+ const filterTargetDepth = childAutoExpand.depth;
53
+ if (nodeDepth < filterTargetDepth) {
54
+ return true;
55
+ }
56
+ }
57
+ if (!child.filtering.filteredChildrenIdentifierPaths) {
58
+ // istanbul ignore next
59
+ continue;
60
+ }
61
+ for (const path of child.filtering.filteredChildrenIdentifierPaths) {
62
+ if ("path" in path && path.options?.autoExpand) {
63
+ return true;
64
+ }
65
+ }
66
+ }
67
+ return false;
68
+ }
33
69
  get postProcessNode() {
34
70
  return async (node) => {
35
71
  const processedNode = this._source.postProcessNode ? await this._source.postProcessNode(node) : node;
36
- if (
37
72
  // instance nodes get the auto-expand flag in `parseNode`, but grouping ones need to be handled during post-processing
38
- HierarchyNode_1.HierarchyNode.isClassGroupingNode(node) &&
39
- node.children.some((child) => child.filtering &&
40
- (child.filtering.isFilterTarget || child.filtering.filteredChildrenIdentifierPaths?.some((path) => "path" in path && path.options?.autoExpand)))) {
41
- return Object.assign(processedNode, { autoExpand: true });
73
+ if (HierarchyNode_1.HierarchyNode.isGroupingNode(node) && this.shouldExpandGroupingNode(node)) {
74
+ Object.assign(processedNode, { autoExpand: true });
42
75
  }
43
76
  return processedNode;
44
77
  };
45
78
  }
46
79
  get parseNode() {
47
80
  return (row) => {
48
- const isFilterTarget = !!row[exports.ECSQL_COLUMN_NAME_IsFilterTarget];
49
81
  const hasFilterTargetAncestor = !!row[exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor];
50
- const parsedFilteredChildrenIdentifierPaths = row[exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths]
82
+ const isFilterTarget = !!row[exports.ECSQL_COLUMN_NAME_IsFilterTarget];
83
+ const filterTargetOptions = row[exports.ECSQL_COLUMN_NAME_FilterTargetOptions]
84
+ ? JSON.parse(row[exports.ECSQL_COLUMN_NAME_FilterTargetOptions])
85
+ : undefined;
86
+ const filteredChildrenIdentifierPaths = row[exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths]
51
87
  ? JSON.parse(row[exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths])
52
88
  : undefined;
53
89
  const defaultNode = (this._source.parseNode ?? TreeNodesReader_1.defaultNodesParser)(row);
54
- return applyFilterAttributes(defaultNode, parsedFilteredChildrenIdentifierPaths, isFilterTarget, hasFilterTargetAncestor);
90
+ return applyFilterAttributes({
91
+ node: defaultNode,
92
+ filteredChildrenIdentifierPaths,
93
+ isFilterTarget,
94
+ filterTargetOptions,
95
+ hasFilterTargetAncestor,
96
+ });
55
97
  };
56
98
  }
57
99
  async defineHierarchyLevel(props) {
@@ -73,7 +115,12 @@ class FilteringHierarchyDefinition {
73
115
  const filteredChildrenIdentifierPaths = matchingFilters.reduce((r, c) => [...r, ...c.childrenIdentifierPaths], new Array());
74
116
  return {
75
117
  ...def,
76
- node: applyFilterAttributes(def.node, filteredChildrenIdentifierPaths, matchingFilters.some((mc) => mc.isFilterTarget), !!hasFilterTargetAncestor),
118
+ node: applyFilterAttributes({
119
+ node: def.node,
120
+ filteredChildrenIdentifierPaths,
121
+ isFilterTarget: matchingFilters.some((mc) => mc.isFilterTarget),
122
+ hasFilterTargetAncestor,
123
+ }),
77
124
  };
78
125
  });
79
126
  }
@@ -129,8 +176,11 @@ async function matchFilters(definition, filteringProps, predicate, classHierarch
129
176
  const remainingPathWithOptions = options ? { path: remainingPath, options } : remainingPath;
130
177
  entry.childrenIdentifierPaths.push(remainingPathWithOptions);
131
178
  }
179
+ else if (entry.isFilterTarget) {
180
+ entry.filterTargetOptions = mergeFilterTargetOptions(entry.filterTargetOptions, options);
181
+ }
132
182
  else {
133
- entry.isFilterTarget = true;
183
+ Object.assign(entry, { isFilterTarget: true, filterTargetOptions: options });
134
184
  }
135
185
  }
136
186
  }
@@ -139,6 +189,31 @@ async function matchFilters(definition, filteringProps, predicate, classHierarch
139
189
  }
140
190
  return undefined;
141
191
  }
192
+ function mergeFilterTargetOptions(target, source) {
193
+ // istanbul ignore next
194
+ if (!target && !source) {
195
+ return undefined;
196
+ }
197
+ // istanbul ignore next
198
+ if (!target) {
199
+ return source;
200
+ }
201
+ // istanbul ignore next
202
+ if (!source) {
203
+ return target;
204
+ }
205
+ return {
206
+ autoExpand: (() => {
207
+ if (source.autoExpand === true) {
208
+ return source.autoExpand;
209
+ }
210
+ if (typeof target.autoExpand === "object" && typeof source.autoExpand === "object" && source.autoExpand.depth > target.autoExpand.depth) {
211
+ return source.autoExpand;
212
+ }
213
+ return target.autoExpand;
214
+ })(),
215
+ };
216
+ }
142
217
  async function findMatchingFilterEntry(filters, nodeId, classHierarchy) {
143
218
  for (const filter of filters) {
144
219
  if (await identifiersEqual(filter.id, nodeId, classHierarchy)) {
@@ -156,7 +231,7 @@ async function identifiersEqual(lhs, rhs, classHierarchy) {
156
231
  }
157
232
  return HierarchyNodeIdentifier_1.HierarchyNodeIdentifier.equal(lhs, rhs);
158
233
  }
159
- function applyFilterAttributes(node, filteredChildrenIdentifierPaths, isFilterTarget, hasFilterTargetAncestor) {
234
+ function applyFilterAttributes({ node, filteredChildrenIdentifierPaths, isFilterTarget, filterTargetOptions, hasFilterTargetAncestor, }) {
160
235
  const shouldAutoExpand = !!filteredChildrenIdentifierPaths?.some((childPath) => {
161
236
  return "path" in childPath && childPath.path.length && childPath.options?.autoExpand;
162
237
  });
@@ -166,7 +241,7 @@ function applyFilterAttributes(node, filteredChildrenIdentifierPaths, isFilterTa
166
241
  }
167
242
  if (isFilterTarget || hasFilterTargetAncestor || filteredChildrenIdentifierPaths?.length) {
168
243
  result.filtering = {
169
- ...(isFilterTarget ? { isFilterTarget } : undefined),
244
+ ...(isFilterTarget ? { isFilterTarget, filterTargetOptions } : undefined),
170
245
  ...(hasFilterTargetAncestor ? { hasFilterTargetAncestor } : undefined),
171
246
  ...(!!filteredChildrenIdentifierPaths?.length ? { filteredChildrenIdentifierPaths } : undefined),
172
247
  };
@@ -181,6 +256,9 @@ exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths = "FilteredChildrenPaths";
181
256
  exports.ECSQL_COLUMN_NAME_IsFilterTarget = "IsFilterTarget";
182
257
  /** @internal */
183
258
  // eslint-disable-next-line @typescript-eslint/naming-convention
259
+ exports.ECSQL_COLUMN_NAME_FilterTargetOptions = "FilterTargetOptions";
260
+ /** @internal */
261
+ // eslint-disable-next-line @typescript-eslint/naming-convention
184
262
  exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor = "HasFilterTargetAncestor";
185
263
  /** @internal */
186
264
  function applyECInstanceIdsFilter(def, matchingFilters, isParentFilterTarget, hasFilterTargetAncestor) {
@@ -195,9 +273,11 @@ function applyECInstanceIdsFilter(def, matchingFilters, isParentFilterTarget, ha
195
273
  ...(def.query.ctes ?? []),
196
274
  // note: generally we'd use `VALUES (1,1),(2,2)`, but that doesn't work in ECSQL (https://github.com/iTwin/itwinjs-backlog/issues/865),
197
275
  // so using UNION as a workaround
198
- `FilteringInfo(ECInstanceId, IsFilterTarget, FilteredChildrenPaths) AS (
276
+ `FilteringInfo(ECInstanceId, IsFilterTarget, FilterTargetOptions, FilteredChildrenPaths) AS (
199
277
  ${matchingFilters
200
- .map(({ id: key, isFilterTarget, childrenIdentifierPaths }) => `VALUES (${key.id}, CAST(${isFilterTarget ? "1" : "0"} AS BOOLEAN), '${JSON.stringify(childrenIdentifierPaths)}')`)
278
+ .map((mc) => mc.isFilterTarget
279
+ ? `VALUES (${mc.id.id}, 1, ${mc.filterTargetOptions ? `'${JSON.stringify(mc.filterTargetOptions)}'` : "CAST(NULL AS TEXT)"}, '${JSON.stringify(mc.childrenIdentifierPaths)}')`
280
+ : `VALUES (${mc.id.id}, 0, CAST(NULL AS TEXT), '${JSON.stringify(mc.childrenIdentifierPaths)}')`)
201
281
  .join(" UNION ALL ")}
202
282
  )`,
203
283
  ],
@@ -205,6 +285,7 @@ function applyECInstanceIdsFilter(def, matchingFilters, isParentFilterTarget, ha
205
285
  SELECT
206
286
  [q].*,
207
287
  [f].[IsFilterTarget] AS [${exports.ECSQL_COLUMN_NAME_IsFilterTarget}],
288
+ [f].[FilterTargetOptions] AS [${exports.ECSQL_COLUMN_NAME_FilterTargetOptions}],
208
289
  ${hasFilterTargetAncestor || isParentFilterTarget ? "1" : "0"} AS [${exports.ECSQL_COLUMN_NAME_HasFilterTargetAncestor}],
209
290
  [f].[FilteredChildrenPaths] AS [${exports.ECSQL_COLUMN_NAME_FilteredChildrenPaths}]
210
291
  FROM (