@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,115 +1,114 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Helpers
|
|
7
|
-
*/
|
|
8
|
-
/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
function initializeRpcInterfaces(interfaces) {
|
|
20
|
-
const config = class extends RpcDefaultConfiguration {
|
|
21
|
-
constructor() {
|
|
22
|
-
super(...arguments);
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
props.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await props.frontendApp.startup(props.frontendAppOptions);
|
|
77
|
-
const defaultFrontendProps = {
|
|
78
|
-
presentation: {
|
|
79
|
-
activeLocale: IModelApp.localization.getLanguageList()[0],
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });
|
|
83
|
-
testOutputDir = props.testOutputDir;
|
|
84
|
-
isInitialized = true;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Undoes the setup made by `initialize`.
|
|
88
|
-
* @param frontendApp IModelApp implementation
|
|
89
|
-
*
|
|
90
|
-
* @see `initialize`
|
|
91
|
-
*
|
|
92
|
-
* @public
|
|
93
|
-
*/
|
|
94
|
-
export const terminate = async (frontendApp = IModelApp) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
};
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Helpers
|
|
7
|
+
*/
|
|
8
|
+
/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.
|
|
9
|
+
import { tmpdir } from "os";
|
|
10
|
+
import { join } from "path";
|
|
11
|
+
import * as rimraf from "rimraf";
|
|
12
|
+
import { IModelHost } from "@itwin/core-backend";
|
|
13
|
+
import { Guid } from "@itwin/core-bentley";
|
|
14
|
+
import { IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, SnapshotIModelRpcInterface, } from "@itwin/core-common";
|
|
15
|
+
import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
|
|
16
|
+
import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerMode, } from "@itwin/presentation-backend";
|
|
17
|
+
import { PresentationRpcInterface } from "@itwin/presentation-common";
|
|
18
|
+
import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
|
|
19
|
+
function initializeRpcInterfaces(interfaces) {
|
|
20
|
+
const config = class extends RpcDefaultConfiguration {
|
|
21
|
+
constructor() {
|
|
22
|
+
super(...arguments);
|
|
23
|
+
Object.defineProperty(this, "interfaces", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: () => interfaces
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
for (const definition of interfaces)
|
|
32
|
+
RpcConfiguration.assign(definition, () => config);
|
|
33
|
+
const instance = RpcConfiguration.obtain(config);
|
|
34
|
+
try {
|
|
35
|
+
RpcConfiguration.initializeInterfaces(instance);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// this may fail with "Error: RPC interface "xxx" is already initialized." because
|
|
39
|
+
// multiple different tests want to set up rpc interfaces
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let isInitialized = false;
|
|
43
|
+
const defaultTestOutputDir = tmpdir();
|
|
44
|
+
let testOutputDir;
|
|
45
|
+
/** @internal */
|
|
46
|
+
export const getTestOutputDir = () => {
|
|
47
|
+
return testOutputDir ?? defaultTestOutputDir;
|
|
48
|
+
};
|
|
49
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
50
|
+
export { HierarchyCacheMode, PresentationManagerMode };
|
|
51
|
+
/**
|
|
52
|
+
* Initialize the framework for presentation testing. The function sets up backend,
|
|
53
|
+
* frontend and RPC communication between them.
|
|
54
|
+
*
|
|
55
|
+
* @see `terminate`
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export const initialize = async (props) => {
|
|
60
|
+
if (isInitialized)
|
|
61
|
+
return;
|
|
62
|
+
if (!props)
|
|
63
|
+
props = {};
|
|
64
|
+
// set up rpc interfaces
|
|
65
|
+
initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
|
|
66
|
+
// init backend
|
|
67
|
+
// make sure backend gets assigned an id which puts its resources into a unique directory
|
|
68
|
+
props.backendProps = props.backendProps ?? {};
|
|
69
|
+
if (!props.backendProps.id)
|
|
70
|
+
props.backendProps.id = `test-${Guid.createValue()}`;
|
|
71
|
+
await IModelHost.startup({ cacheDir: join(__dirname, ".cache"), ...props.backendHostProps });
|
|
72
|
+
PresentationBackend.initialize(props.backendProps);
|
|
73
|
+
// init frontend
|
|
74
|
+
if (!props.frontendApp)
|
|
75
|
+
props.frontendApp = NoRenderApp;
|
|
76
|
+
await props.frontendApp.startup(props.frontendAppOptions);
|
|
77
|
+
const defaultFrontendProps = {
|
|
78
|
+
presentation: {
|
|
79
|
+
activeLocale: IModelApp.localization.getLanguageList()[0],
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });
|
|
83
|
+
testOutputDir = props.testOutputDir;
|
|
84
|
+
isInitialized = true;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Undoes the setup made by `initialize`.
|
|
88
|
+
* @param frontendApp IModelApp implementation
|
|
89
|
+
*
|
|
90
|
+
* @see `initialize`
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
export const terminate = async (frontendApp = IModelApp) => {
|
|
95
|
+
if (!isInitialized)
|
|
96
|
+
return;
|
|
97
|
+
// store directory that needs to be cleaned-up
|
|
98
|
+
let hierarchiesCacheDirectory;
|
|
99
|
+
const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;
|
|
100
|
+
if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk)
|
|
101
|
+
hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;
|
|
102
|
+
else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid)
|
|
103
|
+
hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;
|
|
104
|
+
// terminate backend
|
|
105
|
+
PresentationBackend.terminate();
|
|
106
|
+
await IModelHost.shutdown();
|
|
107
|
+
if (hierarchiesCacheDirectory)
|
|
108
|
+
rimraf.sync(hierarchiesCacheDirectory);
|
|
109
|
+
// terminate frontend
|
|
110
|
+
PresentationFrontend.terminate();
|
|
111
|
+
await frontendApp.shutdown();
|
|
112
|
+
isInitialized = false;
|
|
113
|
+
};
|
|
115
114
|
//# sourceMappingURL=Helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;
|
|
1
|
+
{"version":3,"file":"Helpers.js","s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,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;SAC1D;KACF,CAAC;IACF,MAAM,oBAAoB,CAAC,UAAU,CAAC,EAAE,GAAG,oBAAoB,EAAE,GAAG,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC;IAC3F,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;IAEpC,aAAa,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,WAAW,GAAG,SAAS,EAAE,EAAE;IACzD,IAAI,CAAC,aAAa;QAChB,OAAO;IAET,8CAA8C;IAC9C,IAAI,yBAA6C,CAAC;IAClD,MAAM,sBAAsB,GAAG,mBAAmB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC;IACnF,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,IAAI;QAC1D,yBAAyB,GAAG,sBAAsB,EAAE,SAAS,CAAC;SAC3D,IAAI,sBAAsB,EAAE,IAAI,KAAK,kBAAkB,CAAC,MAAM;QACjE,yBAAyB,GAAG,sBAAsB,EAAE,IAAI,EAAE,SAAS,CAAC;IAEtE,oBAAoB;IACpB,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAChC,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;IAC5B,IAAI,yBAAyB;QAC3B,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAEzC,qBAAqB;IACrB,oBAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,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 Helpers\n */\n\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\n\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport {\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\n} from \"@itwin/core-common\";\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\nimport {\n HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode,\n} from \"@itwin/presentation-backend\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\n\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\n const config = class extends RpcDefaultConfiguration {\n public override interfaces: any = () => interfaces;\n };\n\n for (const definition of interfaces)\n RpcConfiguration.assign(definition, () => config);\n\n const instance = RpcConfiguration.obtain(config);\n\n try {\n RpcConfiguration.initializeInterfaces(instance);\n } catch {\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\n // multiple different tests want to set up rpc interfaces\n }\n}\n\nlet isInitialized = false;\n\nconst defaultTestOutputDir = tmpdir();\nlet testOutputDir: string | undefined;\n\n/** @internal */\nexport const getTestOutputDir = (): string => {\n return testOutputDir ?? defaultTestOutputDir;\n};\n\n// eslint-disable-next-line deprecation/deprecation\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\n\n/** @public */\nexport interface PresentationTestingInitProps {\n /** Properties for backend initialization */\n backendProps?: PresentationBackendProps;\n /** Properties for `IModelHost` */\n backendHostProps?: IModelHostOptions;\n /** Properties for frontend initialization */\n frontendProps?: PresentationFrontendProps;\n /** IModelApp implementation */\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\n /** `IModelApp` options */\n frontendAppOptions?: IModelAppOptions;\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\n testOutputDir?: string;\n}\n\n/**\n * Initialize the framework for presentation testing. The function sets up backend,\n * frontend and RPC communication between them.\n *\n * @see `terminate`\n *\n * @public\n */\nexport const initialize = async (props?: PresentationTestingInitProps) => {\n if (isInitialized)\n return;\n\n if (!props)\n props = {};\n\n // set up rpc interfaces\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\n\n // init backend\n // make sure backend gets assigned an id which puts its resources into a unique directory\n props.backendProps = props.backendProps ?? {};\n if (!props.backendProps.id)\n props.backendProps.id = `test-${Guid.createValue()}`;\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\n PresentationBackend.initialize(props.backendProps);\n\n // init frontend\n if (!props.frontendApp)\n props.frontendApp = NoRenderApp;\n await props.frontendApp.startup(props.frontendAppOptions);\n const defaultFrontendProps: PresentationFrontendProps = {\n presentation: {\n activeLocale: IModelApp.localization.getLanguageList()[0],\n },\n };\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\n testOutputDir = props.testOutputDir;\n\n isInitialized = true;\n};\n\n/**\n * Undoes the setup made by `initialize`.\n * @param frontendApp IModelApp implementation\n *\n * @see `initialize`\n *\n * @public\n */\nexport const terminate = async (frontendApp = IModelApp) => {\n if (!isInitialized)\n return;\n\n // store directory that needs to be cleaned-up\n let hierarchiesCacheDirectory: string | undefined;\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk)\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\n else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid)\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\n\n // terminate backend\n PresentationBackend.terminate();\n await IModelHost.shutdown();\n if (hierarchiesCacheDirectory)\n rimraf.sync(hierarchiesCacheDirectory);\n\n // terminate frontend\n PresentationFrontend.terminate();\n await frontendApp.shutdown();\n\n isInitialized = false;\n};\n"]}
|
|
@@ -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,63 +1,74 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Hierarchies
|
|
7
|
-
*/
|
|
8
|
-
import { using } from "@itwin/core-bentley";
|
|
9
|
-
import { PresentationTreeDataProvider } from "@itwin/presentation-components";
|
|
10
|
-
import { Presentation } from "@itwin/presentation-frontend";
|
|
11
|
-
/**
|
|
12
|
-
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
13
|
-
* @public
|
|
14
|
-
*/
|
|
15
|
-
export const defaultNodeMappingFunc = (node) => {
|
|
16
|
-
// Skip properties 'id', 'parentId' as they contain internal stuff
|
|
17
|
-
// that callers are most likely not interested in. Otherwise they can supply
|
|
18
|
-
// a custom `NodeMappingFunc` that does return those properties as well.
|
|
19
|
-
const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
|
-
return resultNode;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* A class that constructs simple node hierarchy from specified
|
|
24
|
-
* imodel and ruleset.
|
|
25
|
-
*
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export class HierarchyBuilder {
|
|
29
|
-
/** Constructor */
|
|
30
|
-
constructor(props) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
async
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Hierarchies
|
|
7
|
+
*/
|
|
8
|
+
import { using } from "@itwin/core-bentley";
|
|
9
|
+
import { PresentationTreeDataProvider } from "@itwin/presentation-components";
|
|
10
|
+
import { Presentation } from "@itwin/presentation-frontend";
|
|
11
|
+
/**
|
|
12
|
+
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const defaultNodeMappingFunc = (node) => {
|
|
16
|
+
// Skip properties 'id', 'parentId' as they contain internal stuff
|
|
17
|
+
// that callers are most likely not interested in. Otherwise they can supply
|
|
18
|
+
// a custom `NodeMappingFunc` that does return those properties as well.
|
|
19
|
+
const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
20
|
+
return resultNode;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A class that constructs simple node hierarchy from specified
|
|
24
|
+
* imodel and ruleset.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class HierarchyBuilder {
|
|
29
|
+
/** Constructor */
|
|
30
|
+
constructor(props) {
|
|
31
|
+
Object.defineProperty(this, "_iModel", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "_nodeMappingFunc", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
this._iModel = props.imodel;
|
|
44
|
+
this._nodeMappingFunc = props.nodeMappingFunc ?? defaultNodeMappingFunc;
|
|
45
|
+
}
|
|
46
|
+
async createSubHierarchy(nodes, dataProvider) {
|
|
47
|
+
const hierarchy = [];
|
|
48
|
+
for (const node of nodes) {
|
|
49
|
+
const { key: _key, ...nodeNoKey } = node;
|
|
50
|
+
const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;
|
|
51
|
+
const childNodes = await dataProvider.getNodes(node);
|
|
52
|
+
if (childNodes.length > 0)
|
|
53
|
+
hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);
|
|
54
|
+
}
|
|
55
|
+
return hierarchy;
|
|
56
|
+
}
|
|
57
|
+
async doCreateHierarchy(rulesetId) {
|
|
58
|
+
const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });
|
|
59
|
+
const rootNodes = await dataProvider.getNodes();
|
|
60
|
+
return this.createSubHierarchy(rootNodes, dataProvider);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a hierarchy using the supplied presentation ruleset.
|
|
64
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
65
|
+
*/
|
|
66
|
+
async createHierarchy(rulesetOrId) {
|
|
67
|
+
if (typeof rulesetOrId === "string")
|
|
68
|
+
return this.doCreateHierarchy(rulesetOrId);
|
|
69
|
+
return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
|
|
70
|
+
return this.doCreateHierarchy(ruleset.id);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
//# sourceMappingURL=HierarchyBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HierarchyBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;
|
|
1
|
+
{"version":3,"file":"HierarchyBuilder.js","sourceRoot":"","sources":["../../../src/presentation-testing/HierarchyBuilder.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EAAE,4BAA4B,EAA4B,MAAM,gCAAgC,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AA8B5D;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAoB,CAAC,IAAkB,EAAE,EAAE;IAC5E,mEAAmE;IACnE,4EAA4E;IAC5E,wEAAwE;IACxE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC,wDAAwD;IACtG,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAiBF;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAI3B,kBAAkB;IAClB,YAAY,KAA4B;QAJxC;;;;;WAA2C;QAC3C;;;;;WAAmD;QAIjD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,eAAe,IAAI,sBAAsB,CAAC;IAC1E,CAA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,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF","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"]}
|