@itwin/presentation-testing 4.0.0-dev.6 → 4.0.0-dev.8
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 +927 -959
- package/LICENSE.md +9 -9
- package/README.md +7 -7
- package/lib/cjs/presentation-testing/ContentBuilder.d.ts +92 -89
- package/lib/cjs/presentation-testing/ContentBuilder.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/ContentBuilder.js +178 -149
- package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.d.ts +45 -42
- package/lib/cjs/presentation-testing/Helpers.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.js +138 -139
- package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
- package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +69 -66
- package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/HierarchyBuilder.js +78 -67
- package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts +46 -46
- package/lib/cjs/presentation-testing/IModelUtilities.d.ts.map +1 -1
- package/lib/cjs/presentation-testing/IModelUtilities.js +83 -77
- package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -1
- package/lib/cjs/presentation-testing.d.ts +28 -28
- package/lib/cjs/presentation-testing.d.ts.map +1 -1
- package/lib/cjs/presentation-testing.js +44 -44
- package/lib/cjs/presentation-testing.js.map +1 -1
- package/lib/esm/presentation-testing/ContentBuilder.d.ts +92 -89
- package/lib/esm/presentation-testing/ContentBuilder.d.ts.map +1 -1
- package/lib/esm/presentation-testing/ContentBuilder.js +174 -145
- package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/esm/presentation-testing/Helpers.d.ts +45 -42
- package/lib/esm/presentation-testing/Helpers.d.ts.map +1 -1
- package/lib/esm/presentation-testing/Helpers.js +113 -114
- package/lib/esm/presentation-testing/Helpers.js.map +1 -1
- package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +69 -66
- package/lib/esm/presentation-testing/HierarchyBuilder.d.ts.map +1 -1
- package/lib/esm/presentation-testing/HierarchyBuilder.js +73 -62
- package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.d.ts +46 -46
- package/lib/esm/presentation-testing/IModelUtilities.d.ts.map +1 -1
- package/lib/esm/presentation-testing/IModelUtilities.js +75 -69
- package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -1
- package/lib/esm/presentation-testing.d.ts +28 -28
- package/lib/esm/presentation-testing.d.ts.map +1 -1
- package/lib/esm/presentation-testing.js +32 -32
- package/lib/esm/presentation-testing.js.map +1 -1
- package/package.json +53 -53
|
@@ -1,67 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
private
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Hierarchies
|
|
3
|
+
*/
|
|
4
|
+
import { TreeNodeItem } from "@itwin/components-react";
|
|
5
|
+
import { IModelConnection } from "@itwin/core-frontend";
|
|
6
|
+
import { Omit, Ruleset } from "@itwin/presentation-common";
|
|
7
|
+
/**
|
|
8
|
+
* Structure that describes a Node with any indexed properties
|
|
9
|
+
* except `children`.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface MappedNode {
|
|
14
|
+
/** Indexer for all properties in this data structure */
|
|
15
|
+
[index: string]: any;
|
|
16
|
+
/** Prohibited property */
|
|
17
|
+
children?: never;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Node in a hierarchy.
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface HierarchyNode extends Omit<MappedNode, "children"> {
|
|
24
|
+
/** Children of this node */
|
|
25
|
+
children?: HierarchyNode[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A function that converts `TreeNodeItem` into a new custom object.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;
|
|
32
|
+
/**
|
|
33
|
+
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare const defaultNodeMappingFunc: NodeMappingFunc;
|
|
37
|
+
/**
|
|
38
|
+
* Properties for creating a `HierarchyBuilder` instance.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export interface HierarchyBuilderProps {
|
|
42
|
+
/** The iModel to pull data from */
|
|
43
|
+
imodel: IModelConnection;
|
|
44
|
+
/**
|
|
45
|
+
* A function that maps node to something that the user of
|
|
46
|
+
* this API is interested in. E.g. custom implementation may skip some unimportant
|
|
47
|
+
* node properties to make resulting object smaller and easier to read.
|
|
48
|
+
*/
|
|
49
|
+
nodeMappingFunc?: NodeMappingFunc;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A class that constructs simple node hierarchy from specified
|
|
53
|
+
* imodel and ruleset.
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export declare class HierarchyBuilder {
|
|
58
|
+
private readonly _iModel;
|
|
59
|
+
private readonly _nodeMappingFunc;
|
|
60
|
+
/** Constructor */
|
|
61
|
+
constructor(props: HierarchyBuilderProps);
|
|
62
|
+
private createSubHierarchy;
|
|
63
|
+
private doCreateHierarchy;
|
|
64
|
+
/**
|
|
65
|
+
* Create a hierarchy using the supplied presentation ruleset.
|
|
66
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
67
|
+
*/
|
|
68
|
+
createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]>;
|
|
69
|
+
}
|
|
67
70
|
//# sourceMappingURL=HierarchyBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HierarchyBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HierarchyBuilder.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAqB,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAI9E;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wDAAwD;IACxD,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC;IACjE,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,aAAa,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,oBAAY,eAAe,GAAG,CAAC,IAAI,EAAE,YAAY,KAAK,UAAU,CAAC;AAEjE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAMpC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mCAAmC;IACnC,MAAM,EAAE,gBAAgB,CAAC;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;;GAKG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IAEnD,kBAAkB;gBACN,KAAK,EAAE,qBAAqB;YAK1B,kBAAkB;YAYlB,iBAAiB;IAM/B;;;OAGG;IACU,eAAe,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAQtF"}
|
|
@@ -1,68 +1,79 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const presentation_components_1 = require("@itwin/presentation-components");
|
|
13
|
-
const presentation_frontend_1 = require("@itwin/presentation-frontend");
|
|
14
|
-
/**
|
|
15
|
-
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
16
|
-
* @public
|
|
17
|
-
*/
|
|
18
|
-
const defaultNodeMappingFunc = (node) => {
|
|
19
|
-
// Skip properties 'id', 'parentId' as they contain internal stuff
|
|
20
|
-
// that callers are most likely not interested in. Otherwise they can supply
|
|
21
|
-
// a custom `NodeMappingFunc` that does return those properties as well.
|
|
22
|
-
const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
23
|
-
return resultNode;
|
|
24
|
-
};
|
|
25
|
-
exports.defaultNodeMappingFunc = defaultNodeMappingFunc;
|
|
26
|
-
/**
|
|
27
|
-
* A class that constructs simple node hierarchy from specified
|
|
28
|
-
* imodel and ruleset.
|
|
29
|
-
*
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
class HierarchyBuilder {
|
|
33
|
-
/** Constructor */
|
|
34
|
-
constructor(props) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
async
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Hierarchies
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.HierarchyBuilder = exports.defaultNodeMappingFunc = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const presentation_components_1 = require("@itwin/presentation-components");
|
|
13
|
+
const presentation_frontend_1 = require("@itwin/presentation-frontend");
|
|
14
|
+
/**
|
|
15
|
+
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
const defaultNodeMappingFunc = (node) => {
|
|
19
|
+
// Skip properties 'id', 'parentId' as they contain internal stuff
|
|
20
|
+
// that callers are most likely not interested in. Otherwise they can supply
|
|
21
|
+
// a custom `NodeMappingFunc` that does return those properties as well.
|
|
22
|
+
const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
23
|
+
return resultNode;
|
|
24
|
+
};
|
|
25
|
+
exports.defaultNodeMappingFunc = defaultNodeMappingFunc;
|
|
26
|
+
/**
|
|
27
|
+
* A class that constructs simple node hierarchy from specified
|
|
28
|
+
* imodel and ruleset.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class HierarchyBuilder {
|
|
33
|
+
/** Constructor */
|
|
34
|
+
constructor(props) {
|
|
35
|
+
Object.defineProperty(this, "_iModel", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "_nodeMappingFunc", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
this._iModel = props.imodel;
|
|
48
|
+
this._nodeMappingFunc = props.nodeMappingFunc ?? exports.defaultNodeMappingFunc;
|
|
49
|
+
}
|
|
50
|
+
async createSubHierarchy(nodes, dataProvider) {
|
|
51
|
+
const hierarchy = [];
|
|
52
|
+
for (const node of nodes) {
|
|
53
|
+
const { key: _key, ...nodeNoKey } = node;
|
|
54
|
+
const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;
|
|
55
|
+
const childNodes = await dataProvider.getNodes(node);
|
|
56
|
+
if (childNodes.length > 0)
|
|
57
|
+
hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);
|
|
58
|
+
}
|
|
59
|
+
return hierarchy;
|
|
60
|
+
}
|
|
61
|
+
async doCreateHierarchy(rulesetId) {
|
|
62
|
+
const dataProvider = new presentation_components_1.PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });
|
|
63
|
+
const rootNodes = await dataProvider.getNodes();
|
|
64
|
+
return this.createSubHierarchy(rootNodes, dataProvider);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a hierarchy using the supplied presentation ruleset.
|
|
68
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
69
|
+
*/
|
|
70
|
+
async createHierarchy(rulesetOrId) {
|
|
71
|
+
if (typeof rulesetOrId === "string")
|
|
72
|
+
return this.doCreateHierarchy(rulesetOrId);
|
|
73
|
+
return (0, core_bentley_1.using)(await presentation_frontend_1.Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
|
|
74
|
+
return this.doCreateHierarchy(ruleset.id);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.HierarchyBuilder = HierarchyBuilder;
|
|
68
79
|
//# sourceMappingURL=HierarchyBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HierarchyBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HierarchyBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,sDAA4C;AAG5C,4EAAwG;AACxG,wEAA4D;AA8B5D;;;GAGG;AACI,MAAM,sBAAsB,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EAAE,CAAC,CAAC;QACpG,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAC,WAA6B;QACxD,IAAI,OAAO,WAAW,KAAK,QAAQ;YACjC,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAE7C,OAAO,IAAA,oBAAK,EAAC,MAAM,oCAAY,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAA0B,EAAE,EAAE;YAC7G,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAxCD,4CAwCC","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/** @packageDocumentation\n * @module Hierarchies\n */\n\nimport { TreeNodeItem } from \"@itwin/components-react\";\nimport { using } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"@itwin/core-frontend\";\nimport { Omit, RegisteredRuleset, Ruleset } from \"@itwin/presentation-common\";\nimport { PresentationTreeDataProvider, PresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\n\n/**\n * Structure that describes a Node with any indexed properties\n * except `children`.\n *\n * @public\n */\nexport interface MappedNode {\n /** Indexer for all properties in this data structure */\n [index: string]: any;\n /** Prohibited property */\n children?: never;\n}\n\n/**\n * Node in a hierarchy.\n * @public\n */\nexport interface HierarchyNode extends Omit<MappedNode, \"children\"> {\n /** Children of this node */\n children?: HierarchyNode[];\n}\n\n/**\n * A function that converts `TreeNodeItem` into a new custom object.\n * @public\n */\nexport type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;\n\n/**\n * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.\n * @public\n */\nexport const defaultNodeMappingFunc: NodeMappingFunc = (node: TreeNodeItem) => {\n // Skip properties 'id', 'parentId' as they contain internal stuff\n // that callers are most likely not interested in. Otherwise they can supply\n // a custom `NodeMappingFunc` that does return those properties as well.\n const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars\n return resultNode;\n};\n\n/**\n * Properties for creating a `HierarchyBuilder` instance.\n * @public\n */\nexport interface HierarchyBuilderProps {\n /** The iModel to pull data from */\n imodel: IModelConnection;\n /**\n * A function that maps node to something that the user of\n * this API is interested in. E.g. custom implementation may skip some unimportant\n * node properties to make resulting object smaller and easier to read.\n */\n nodeMappingFunc?: NodeMappingFunc;\n}\n\n/**\n * A class that constructs simple node hierarchy from specified\n * imodel and ruleset.\n *\n * @public\n */\nexport class HierarchyBuilder {\n private readonly _iModel: IModelConnection;\n private readonly _nodeMappingFunc: NodeMappingFunc;\n\n /** Constructor */\n constructor(props: HierarchyBuilderProps) {\n this._iModel = props.imodel;\n this._nodeMappingFunc = props.nodeMappingFunc ?? defaultNodeMappingFunc;\n }\n\n private async createSubHierarchy(nodes: TreeNodeItem[], dataProvider: PresentationTreeDataProvider) {\n const hierarchy: HierarchyNode[] = [];\n for (const node of nodes) {\n const { key: _key, ...nodeNoKey } = (node as PresentationTreeNodeItem);\n const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;\n const childNodes = await dataProvider.getNodes(node);\n if (childNodes.length > 0)\n hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);\n }\n return hierarchy;\n }\n\n private async doCreateHierarchy(rulesetId: string): Promise<HierarchyNode[]> {\n const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });\n const rootNodes = await dataProvider.getNodes();\n return this.createSubHierarchy(rootNodes, dataProvider);\n }\n\n /**\n * Create a hierarchy using the supplied presentation ruleset.\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\n */\n public async createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]> {\n if (typeof rulesetOrId === \"string\")\n return this.doCreateHierarchy(rulesetOrId);\n\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\n return this.doCreateHierarchy(ruleset.id);\n });\n }\n}\n"]}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module IModel
|
|
3
|
-
*/
|
|
4
|
-
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
-
import { Id64String } from "@itwin/core-bentley";
|
|
6
|
-
import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps } from "@itwin/core-common";
|
|
7
|
-
import { IModelConnection } from "@itwin/core-frontend";
|
|
8
|
-
/**
|
|
9
|
-
* Interface for IModel builder pattern. Used for building IModels to test rulesets.
|
|
10
|
-
*
|
|
11
|
-
* @beta
|
|
12
|
-
*/
|
|
13
|
-
export interface TestIModelBuilder {
|
|
14
|
-
/** Insert a model into the builder's iModel */
|
|
15
|
-
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
16
|
-
/** Insert an element into the builder's iModel */
|
|
17
|
-
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
18
|
-
/** Insert an element aspect into the specified element */
|
|
19
|
-
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
20
|
-
/**
|
|
21
|
-
* Create code for specified element.
|
|
22
|
-
* Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).
|
|
23
|
-
*/
|
|
24
|
-
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Function that creates an iModel and returns a connection to it.
|
|
28
|
-
* @param name Name of test IModel
|
|
29
|
-
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
30
|
-
*
|
|
31
|
-
* @beta
|
|
32
|
-
*/
|
|
33
|
-
export declare function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
34
|
-
/**
|
|
35
|
-
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
36
|
-
*
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
export declare class IModelBuilder implements TestIModelBuilder {
|
|
40
|
-
private _iModel;
|
|
41
|
-
constructor(iModel: IModelDb);
|
|
42
|
-
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
43
|
-
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
44
|
-
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
45
|
-
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
46
|
-
}
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module IModel
|
|
3
|
+
*/
|
|
4
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
5
|
+
import { Id64String } from "@itwin/core-bentley";
|
|
6
|
+
import { BisCodeSpec, Code, CodeScopeProps, ElementAspectProps, ElementProps, ModelProps } from "@itwin/core-common";
|
|
7
|
+
import { IModelConnection } from "@itwin/core-frontend";
|
|
8
|
+
/**
|
|
9
|
+
* Interface for IModel builder pattern. Used for building IModels to test rulesets.
|
|
10
|
+
*
|
|
11
|
+
* @beta
|
|
12
|
+
*/
|
|
13
|
+
export interface TestIModelBuilder {
|
|
14
|
+
/** Insert a model into the builder's iModel */
|
|
15
|
+
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
16
|
+
/** Insert an element into the builder's iModel */
|
|
17
|
+
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
18
|
+
/** Insert an element aspect into the specified element */
|
|
19
|
+
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
20
|
+
/**
|
|
21
|
+
* Create code for specified element.
|
|
22
|
+
* Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).
|
|
23
|
+
*/
|
|
24
|
+
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Function that creates an iModel and returns a connection to it.
|
|
28
|
+
* @param name Name of test IModel
|
|
29
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
30
|
+
*
|
|
31
|
+
* @beta
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection>;
|
|
34
|
+
/**
|
|
35
|
+
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare class IModelBuilder implements TestIModelBuilder {
|
|
40
|
+
private _iModel;
|
|
41
|
+
constructor(iModel: IModelDb);
|
|
42
|
+
insertModel<TProps extends ModelProps>(props: TProps): Id64String;
|
|
43
|
+
insertElement<TProps extends ElementProps>(props: TProps): Id64String;
|
|
44
|
+
insertAspect<TProps extends ElementAspectProps>(props: TProps): void;
|
|
45
|
+
createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;
|
|
46
|
+
}
|
|
47
47
|
//# sourceMappingURL=IModelUtilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"IModelUtilities.d.ts","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAA0B,MAAM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,SAAS,EAAE,MAAM,GAAG,IAAI;CAIpG"}
|
|
@@ -1,78 +1,84 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module IModel
|
|
8
|
-
*/
|
|
9
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.IModelBuilder = exports.buildTestIModel = void 0;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const Helpers_1 = require("./Helpers");
|
|
19
|
-
/**
|
|
20
|
-
* Function that creates an iModel and returns a connection to it.
|
|
21
|
-
* @param name Name of test IModel
|
|
22
|
-
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
23
|
-
*
|
|
24
|
-
* @beta
|
|
25
|
-
*/
|
|
26
|
-
async function buildTestIModel(name, cb) {
|
|
27
|
-
const outputFile = setupOutputFileLocation(name);
|
|
28
|
-
const db = core_backend_1.SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
|
|
29
|
-
const builder = new IModelBuilder(db);
|
|
30
|
-
try {
|
|
31
|
-
cb(builder);
|
|
32
|
-
}
|
|
33
|
-
finally {
|
|
34
|
-
db.saveChanges("Created test IModel");
|
|
35
|
-
db.close();
|
|
36
|
-
}
|
|
37
|
-
return core_frontend_1.SnapshotConnection.openFile(outputFile);
|
|
38
|
-
}
|
|
39
|
-
exports.buildTestIModel = buildTestIModel;
|
|
40
|
-
/**
|
|
41
|
-
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
42
|
-
*
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
class IModelBuilder {
|
|
46
|
-
constructor(iModel) {
|
|
47
|
-
this
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this._iModel.
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module IModel
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.IModelBuilder = exports.buildTestIModel = void 0;
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
16
|
+
const core_common_1 = require("@itwin/core-common");
|
|
17
|
+
const core_frontend_1 = require("@itwin/core-frontend");
|
|
18
|
+
const Helpers_1 = require("./Helpers");
|
|
19
|
+
/**
|
|
20
|
+
* Function that creates an iModel and returns a connection to it.
|
|
21
|
+
* @param name Name of test IModel
|
|
22
|
+
* @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data
|
|
23
|
+
*
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
async function buildTestIModel(name, cb) {
|
|
27
|
+
const outputFile = setupOutputFileLocation(name);
|
|
28
|
+
const db = core_backend_1.SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });
|
|
29
|
+
const builder = new IModelBuilder(db);
|
|
30
|
+
try {
|
|
31
|
+
cb(builder);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
db.saveChanges("Created test IModel");
|
|
35
|
+
db.close();
|
|
36
|
+
}
|
|
37
|
+
return core_frontend_1.SnapshotConnection.openFile(outputFile);
|
|
38
|
+
}
|
|
39
|
+
exports.buildTestIModel = buildTestIModel;
|
|
40
|
+
/**
|
|
41
|
+
* Default implementation of IModel builder pattern. Used for building IModels to test rulesets.
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
class IModelBuilder {
|
|
46
|
+
constructor(iModel) {
|
|
47
|
+
Object.defineProperty(this, "_iModel", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
this._iModel = iModel;
|
|
54
|
+
}
|
|
55
|
+
insertModel(props) {
|
|
56
|
+
return this._iModel.models.insertModel(props);
|
|
57
|
+
}
|
|
58
|
+
insertElement(props) {
|
|
59
|
+
return this._iModel.elements.insertElement(props);
|
|
60
|
+
}
|
|
61
|
+
insertAspect(props) {
|
|
62
|
+
this._iModel.elements.insertAspect(props);
|
|
63
|
+
}
|
|
64
|
+
createCode(scopeModelId, codeSpecName, codeValue) {
|
|
65
|
+
const codeSpec = this._iModel.codeSpecs.getByName(codeSpecName);
|
|
66
|
+
return new core_common_1.Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.IModelBuilder = IModelBuilder;
|
|
70
|
+
/**
|
|
71
|
+
* Prepare for an output file by:
|
|
72
|
+
* - Resolving the output file name under the known test output directory
|
|
73
|
+
* - Making directories as necessary
|
|
74
|
+
* - Removing a previous copy of the output file
|
|
75
|
+
* @param fileName Name of output file
|
|
76
|
+
*/
|
|
77
|
+
function setupOutputFileLocation(fileName) {
|
|
78
|
+
const testOutputDir = (0, Helpers_1.getTestOutputDir)();
|
|
79
|
+
!core_backend_1.IModelJsFs.existsSync(testOutputDir) && core_backend_1.IModelJsFs.mkdirSync(testOutputDir);
|
|
80
|
+
const outputFile = path_1.default.join(testOutputDir, `${fileName}.bim`);
|
|
81
|
+
core_backend_1.IModelJsFs.existsSync(outputFile) && core_backend_1.IModelJsFs.unlinkSync(outputFile);
|
|
82
|
+
return outputFile;
|
|
83
|
+
}
|
|
78
84
|
//# sourceMappingURL=IModelUtilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,sDAAuE;AAEvE,oDAA8I;AAC9I,wDAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"IModelUtilities.js","sourceRoot":"","sources":["../../../src/presentation-testing/IModelUtilities.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,gDAAwB;AACxB,sDAAuE;AAEvE,oDAA8I;AAC9I,wDAA4E;AAC5E,uCAA6C;AAqB7C;;;;;;GAMG;AACI,KAAK,UAAU,eAAe,CAAC,IAAY,EAAE,EAAwC;IAC1F,MAAM,UAAU,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;IACjD,MAAM,EAAE,GAAG,yBAAU,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACzE,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;IACtC,IAAI;QACF,E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C,IAAI,CAAC,aAAa,EAAE,GAAG,QAAQ,MAAM,CAAC,CAAC;IAC/D,yBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,yBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACvE,OAAO,UAAU,CAAC;AACpB,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/** @packageDocumentation\n * @module IModel\n */\n\nimport path from \"path\";\nimport { IModelDb, IModelJsFs, SnapshotDb } from \"@itwin/core-backend\";\nimport { Id64String } from \"@itwin/core-bentley\";\nimport { BisCodeSpec, Code, CodeScopeProps, CodeSpec, ElementAspectProps, ElementProps, LocalFileName, ModelProps } from \"@itwin/core-common\";\nimport { IModelConnection, SnapshotConnection } from \"@itwin/core-frontend\";\nimport { getTestOutputDir } from \"./Helpers\";\n\n/**\n * Interface for IModel builder pattern. Used for building IModels to test rulesets.\n *\n * @beta\n */\nexport interface TestIModelBuilder {\n /** Insert a model into the builder's iModel */\n insertModel<TProps extends ModelProps>(props: TProps): Id64String;\n /** Insert an element into the builder's iModel */\n insertElement<TProps extends ElementProps>(props: TProps): Id64String;\n /** Insert an element aspect into the specified element */\n insertAspect<TProps extends ElementAspectProps>(props: TProps): void;\n /**\n * Create code for specified element.\n * Code value has to be unique within its scope (see [Codes documentation page]($docs/bis/guide/fundamentals/codes.md)).\n */\n createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code;\n}\n\n/**\n * Function that creates an iModel and returns a connection to it.\n * @param name Name of test IModel\n * @param cb Callback function that receives an [[TestIModelBuilder]] to fill the iModel with data\n *\n * @beta\n */\nexport async function buildTestIModel(name: string, cb: (builder: TestIModelBuilder) => void): Promise<IModelConnection> {\n const outputFile = setupOutputFileLocation(name);\n const db = SnapshotDb.createEmpty(outputFile, { rootSubject: { name } });\n const builder = new IModelBuilder(db);\n try {\n cb(builder);\n } finally {\n db.saveChanges(\"Created test IModel\");\n db.close();\n }\n return SnapshotConnection.openFile(outputFile);\n}\n\n/**\n * Default implementation of IModel builder pattern. Used for building IModels to test rulesets.\n *\n * @internal\n */\nexport class IModelBuilder implements TestIModelBuilder {\n private _iModel: IModelDb;\n\n constructor(iModel: IModelDb) {\n this._iModel = iModel;\n }\n\n public insertModel<TProps extends ModelProps>(props: TProps): Id64String {\n return this._iModel.models.insertModel(props);\n }\n\n public insertElement<TProps extends ElementProps>(props: TProps): Id64String {\n return this._iModel.elements.insertElement(props);\n }\n\n public insertAspect<TProps extends ElementAspectProps>(props: TProps): void {\n this._iModel.elements.insertAspect(props);\n }\n\n public createCode(scopeModelId: CodeScopeProps, codeSpecName: BisCodeSpec, codeValue: string): Code {\n const codeSpec: CodeSpec = this._iModel.codeSpecs.getByName(codeSpecName);\n return new Code({ spec: codeSpec.id, scope: scopeModelId, value: codeValue });\n }\n}\n\n/**\n * Prepare for an output file by:\n * - Resolving the output file name under the known test output directory\n * - Making directories as necessary\n * - Removing a previous copy of the output file\n * @param fileName Name of output file\n */\nfunction setupOutputFileLocation(fileName: string): LocalFileName {\n const testOutputDir = getTestOutputDir();\n !IModelJsFs.existsSync(testOutputDir) && IModelJsFs.mkdirSync(testOutputDir);\n\n const outputFile = path.join(testOutputDir, `${fileName}.bim`);\n IModelJsFs.existsSync(outputFile) && IModelJsFs.unlinkSync(outputFile);\n return outputFile;\n}\n"]}
|