@itwin/presentation-hierarchies-react 0.5.1 → 0.5.2
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 +6 -0
- package/lib/cjs/presentation-hierarchies-react/internal/TreeLoader.js +5 -2
- package/lib/cjs/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +5 -2
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.TreeLoader = void 0;
|
|
8
8
|
const rxjs_1 = require("rxjs");
|
|
9
|
-
const presentation_hierarchies_1 = require("@itwin/presentation-hierarchies");
|
|
10
9
|
const TreeModel_1 = require("./TreeModel");
|
|
11
10
|
const Utils_1 = require("./Utils");
|
|
12
11
|
/** @internal */
|
|
@@ -31,7 +30,7 @@ class TreeLoader {
|
|
|
31
30
|
id: `${infoNodeIdBase}-${err.message}`,
|
|
32
31
|
parentId: parent.id,
|
|
33
32
|
};
|
|
34
|
-
if (err
|
|
33
|
+
if (isRowsLimitError(err)) {
|
|
35
34
|
this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });
|
|
36
35
|
return (0, rxjs_1.of)([{ ...nodeProps, type: "ResultSetTooLarge", resultSetSizeLimit: err.limit }]);
|
|
37
36
|
}
|
|
@@ -71,4 +70,8 @@ function createTreeModelNodesFactory(buildNode) {
|
|
|
71
70
|
function isHierarchyNode(node) {
|
|
72
71
|
return "key" in node && node.key !== undefined;
|
|
73
72
|
}
|
|
73
|
+
function isRowsLimitError(error) {
|
|
74
|
+
const asRowsError = error;
|
|
75
|
+
return asRowsError.limit !== undefined && asRowsError.message.includes("Query rows limit of");
|
|
76
|
+
}
|
|
74
77
|
//# sourceMappingURL=TreeLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,+BAAwF;
|
|
1
|
+
{"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,+BAAwF;AAExF,2CAAoI;AACpI,mCAAuC;AA4BvC,gBAAgB;AAChB,MAAa,UAAU;IAEX;IACA;IAFV,YACU,kBAAqC,EACrC,yBAA+H;QAD/H,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,8BAAyB,GAAzB,yBAAyB,CAAsG;IACtI,CAAC;IAEI,YAAY,CAAC,EAAE,MAAM,EAAE,wBAAwB,EAAE,SAAS,EAAE,WAAW,EAAgD;QAC7H,MAAM,EAAE,cAAc,EAAE,uBAAuB,EAAE,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;QACrF,MAAM,cAAc,GAAG,GAAG,MAAM,CAAC,EAAE,IAAI,QAAQ,EAAE,CAAC;QAClD,MAAM,qBAAqB,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;QACrE,OAAO,IAAA,WAAI,EACT,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC;YAC/B,UAAU,EAAE,MAAM,CAAC,QAAQ;YAC3B,uBAAuB;YACvB,cAAc;YACd,WAAW;SACZ,CAAC,CACH,CAAC,IAAI,CACJ,IAAA,cAAO,GAAE,EACT,IAAA,iBAAU,EAAC,CAAC,GAAG,EAAE,EAAE;YACjB,MAAM,SAAS,GAAG;gBAChB,EAAE,EAAE,GAAG,cAAc,IAAI,GAAG,CAAC,OAAO,EAAE;gBACtC,QAAQ,EAAE,MAAM,CAAC,EAAE;aACpB,CAAC;YACF,IAAI,gBAAgB,CAAC,GAAG,CAAC,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IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CACpE,CACF,CACF,CAAC;IACJ,CAAC;CACF;AAzDD,gCAyDC;AAED,SAAS,2BAA2B,CAClC,SAAoE;IAEpE,OAAO,CAAC,IAAuC,EAAE,EAAE;QACjD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,SAAS,GAA2B;YACxC,EAAE,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC;YACtB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAuC;IAC9D,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAY;IACpC,MAAM,WAAW,GAAG,KAA+B,CAAC;IACpD,OAAO,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAChG,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 { catchError, expand, from, map, mergeMap, Observable, of, toArray } from \"rxjs\";\nimport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelInfoNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel\";\nimport { createNodeId } from \"./Utils\";\n\n/** @internal */\nexport interface LoadedTreePart {\n parentId: string | undefined;\n loadedNodes: TreeModelNode[];\n}\n\n/** @internal */\nexport interface HierarchyLevelOptions {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n}\n\n/** @internal */\nexport interface LoadNodesOptions {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n getHierarchyLevelOptions: (node: TreeModelRootNode | TreeModelHierarchyNode) => HierarchyLevelOptions;\n shouldLoadChildren: (node: TreeModelHierarchyNode) => boolean;\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n ignoreCache?: boolean;\n}\n\n/** @internal */\nexport interface ITreeLoader {\n loadNodes(options: LoadNodesOptions): Observable<LoadedTreePart>;\n}\n\n/** @internal */\nexport class TreeLoader implements ITreeLoader {\n constructor(\n private _hierarchyProvider: HierarchyProvider,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n ) {}\n\n private loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory(buildNode);\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n catchError((err) => {\n const nodeProps = {\n id: `${infoNodeIdBase}-${err.message}`,\n parentId: parent.id,\n };\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });\n return of([{ ...nodeProps, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit }]);\n }\n return of([{ ...nodeProps, type: \"Unknown\" as const, message: \"Failed to create hierarchy level\" }]);\n }),\n map(\n (childNodes): LoadedTreePart => ({\n parentId: parent.id,\n loadedNodes:\n instanceFilter && childNodes.length === 0\n ? [\n {\n id: `${infoNodeIdBase}-no-filter-matches`,\n parentId: parent.id,\n type: \"NoFilterMatches\" as const,\n },\n ]\n : childNodes.map(treeModelNodesFactory),\n }),\n ),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n from(loadedPart.loadedNodes.filter((node): node is TreeModelHierarchyNode => isTreeModelHierarchyNode(node) && shouldLoadChildren(node))).pipe(\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n ),\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory(\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode,\n): (node: TreeModelInfoNode | HierarchyNode) => TreeModelNode {\n return (node: TreeModelInfoNode | HierarchyNode) => {\n if (!isHierarchyNode(node)) {\n return node;\n }\n\n const modelNode: TreeModelHierarchyNode = {\n id: createNodeId(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isHierarchyNode(node: TreeModelInfoNode | HierarchyNode): node is HierarchyNode {\n return \"key\" in node && node.key !== undefined;\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n const asRowsError = error as RowsLimitExceededError;\n return asRowsError.limit !== undefined && asRowsError.message.includes(\"Query rows limit of\");\n}\n"]}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { catchError, expand, from, map, mergeMap, of, toArray } from "rxjs";
|
|
6
|
-
import { RowsLimitExceededError } from "@itwin/presentation-hierarchies";
|
|
7
6
|
import { isTreeModelHierarchyNode } from "./TreeModel";
|
|
8
7
|
import { createNodeId } from "./Utils";
|
|
9
8
|
/** @internal */
|
|
@@ -28,7 +27,7 @@ export class TreeLoader {
|
|
|
28
27
|
id: `${infoNodeIdBase}-${err.message}`,
|
|
29
28
|
parentId: parent.id,
|
|
30
29
|
};
|
|
31
|
-
if (err
|
|
30
|
+
if (isRowsLimitError(err)) {
|
|
32
31
|
this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });
|
|
33
32
|
return of([{ ...nodeProps, type: "ResultSetTooLarge", resultSetSizeLimit: err.limit }]);
|
|
34
33
|
}
|
|
@@ -67,4 +66,8 @@ function createTreeModelNodesFactory(buildNode) {
|
|
|
67
66
|
function isHierarchyNode(node) {
|
|
68
67
|
return "key" in node && node.key !== undefined;
|
|
69
68
|
}
|
|
69
|
+
function isRowsLimitError(error) {
|
|
70
|
+
const asRowsError = error;
|
|
71
|
+
return asRowsError.limit !== undefined && asRowsError.message.includes("Query rows limit of");
|
|
72
|
+
}
|
|
70
73
|
//# sourceMappingURL=TreeLoader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeLoader.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAA+E,MAAM,aAAa,CAAC;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C,IAAI,CAAC;YACtB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI;SACf,CAAC;QACF,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,IAAuC;IAC9D,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAY;IACpC,MAAM,WAAW,GAAG,KAA+B,CAAC;IACpD,OAAO,WAAW,CAAC,KAAK,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAChG,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 { catchError, expand, from, map, mergeMap, Observable, of, toArray } from \"rxjs\";\nimport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelInfoNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel\";\nimport { createNodeId } from \"./Utils\";\n\n/** @internal */\nexport interface LoadedTreePart {\n parentId: string | undefined;\n loadedNodes: TreeModelNode[];\n}\n\n/** @internal */\nexport interface HierarchyLevelOptions {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n}\n\n/** @internal */\nexport interface LoadNodesOptions {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n getHierarchyLevelOptions: (node: TreeModelRootNode | TreeModelHierarchyNode) => HierarchyLevelOptions;\n shouldLoadChildren: (node: TreeModelHierarchyNode) => boolean;\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n ignoreCache?: boolean;\n}\n\n/** @internal */\nexport interface ITreeLoader {\n loadNodes(options: LoadNodesOptions): Observable<LoadedTreePart>;\n}\n\n/** @internal */\nexport class TreeLoader implements ITreeLoader {\n constructor(\n private _hierarchyProvider: HierarchyProvider,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n ) {}\n\n private loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory(buildNode);\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n catchError((err) => {\n const nodeProps = {\n id: `${infoNodeIdBase}-${err.message}`,\n parentId: parent.id,\n };\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: hierarchyLevelSizeLimit });\n return of([{ ...nodeProps, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit }]);\n }\n return of([{ ...nodeProps, type: \"Unknown\" as const, message: \"Failed to create hierarchy level\" }]);\n }),\n map(\n (childNodes): LoadedTreePart => ({\n parentId: parent.id,\n loadedNodes:\n instanceFilter && childNodes.length === 0\n ? [\n {\n id: `${infoNodeIdBase}-no-filter-matches`,\n parentId: parent.id,\n type: \"NoFilterMatches\" as const,\n },\n ]\n : childNodes.map(treeModelNodesFactory),\n }),\n ),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n from(loadedPart.loadedNodes.filter((node): node is TreeModelHierarchyNode => isTreeModelHierarchyNode(node) && shouldLoadChildren(node))).pipe(\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n ),\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory(\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode,\n): (node: TreeModelInfoNode | HierarchyNode) => TreeModelNode {\n return (node: TreeModelInfoNode | HierarchyNode) => {\n if (!isHierarchyNode(node)) {\n return node;\n }\n\n const modelNode: TreeModelHierarchyNode = {\n id: createNodeId(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isHierarchyNode(node: TreeModelInfoNode | HierarchyNode): node is HierarchyNode {\n return \"key\" in node && node.key !== undefined;\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n const asRowsError = error as RowsLimitExceededError;\n return asRowsError.limit !== undefined && asRowsError.message.includes(\"Query rows limit of\");\n}\n"]}
|