@itwin/presentation-testing 3.7.12 → 3.7.13
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 -1
- package/lib/cjs/presentation-testing/ContentBuilder.d.ts +89 -89
- package/lib/cjs/presentation-testing/ContentBuilder.js +151 -151
- package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.d.ts +42 -42
- package/lib/cjs/presentation-testing/Helpers.js +139 -139
- package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
- package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +66 -66
- package/lib/cjs/presentation-testing/HierarchyBuilder.js +67 -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.js +77 -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.js +44 -44
- package/lib/cjs/presentation-testing.js.map +1 -1
- package/lib/esm/presentation-testing/ContentBuilder.d.ts +89 -89
- package/lib/esm/presentation-testing/ContentBuilder.js +147 -147
- package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/esm/presentation-testing/Helpers.d.ts +42 -42
- package/lib/esm/presentation-testing/Helpers.js +114 -114
- package/lib/esm/presentation-testing/Helpers.js.map +1 -1
- package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +66 -66
- package/lib/esm/presentation-testing/HierarchyBuilder.js +62 -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.js +69 -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.js +32 -32
- package/lib/esm/presentation-testing.js.map +1 -1
- package/package.json +13 -13
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { IModelHostOptions } from "@itwin/core-backend";
|
|
2
|
-
import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
|
|
3
|
-
import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
|
|
4
|
-
import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
|
|
5
|
-
/** @internal */
|
|
6
|
-
export declare const getTestOutputDir: () => string;
|
|
7
|
-
export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
|
|
8
|
-
/** @public */
|
|
9
|
-
export interface PresentationTestingInitProps {
|
|
10
|
-
/** Properties for backend initialization */
|
|
11
|
-
backendProps?: PresentationBackendProps;
|
|
12
|
-
/** Properties for `IModelHost` */
|
|
13
|
-
backendHostProps?: IModelHostOptions;
|
|
14
|
-
/** Properties for frontend initialization */
|
|
15
|
-
frontendProps?: PresentationFrontendProps;
|
|
16
|
-
/** IModelApp implementation */
|
|
17
|
-
frontendApp?: {
|
|
18
|
-
startup: (opts?: IModelAppOptions) => Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
/** `IModelApp` options */
|
|
21
|
-
frontendAppOptions?: IModelAppOptions;
|
|
22
|
-
/** Custom test output directory. Defaults to temporary directory provided by the OS. */
|
|
23
|
-
testOutputDir?: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Initialize the framework for presentation testing. The function sets up backend,
|
|
27
|
-
* frontend and RPC communication between them.
|
|
28
|
-
*
|
|
29
|
-
* @see `terminate`
|
|
30
|
-
*
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export declare const initialize: (props?: PresentationTestingInitProps | undefined) => Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Undoes the setup made by `initialize`.
|
|
36
|
-
* @param frontendApp IModelApp implementation
|
|
37
|
-
*
|
|
38
|
-
* @see `initialize`
|
|
39
|
-
*
|
|
40
|
-
* @public
|
|
41
|
-
*/
|
|
42
|
-
export declare const terminate: (frontendApp?: typeof IModelApp) => Promise<void>;
|
|
1
|
+
import { IModelHostOptions } from "@itwin/core-backend";
|
|
2
|
+
import { IModelApp, IModelAppOptions } from "@itwin/core-frontend";
|
|
3
|
+
import { HierarchyCacheMode, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode } from "@itwin/presentation-backend";
|
|
4
|
+
import { PresentationProps as PresentationFrontendProps } from "@itwin/presentation-frontend";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare const getTestOutputDir: () => string;
|
|
7
|
+
export { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };
|
|
8
|
+
/** @public */
|
|
9
|
+
export interface PresentationTestingInitProps {
|
|
10
|
+
/** Properties for backend initialization */
|
|
11
|
+
backendProps?: PresentationBackendProps;
|
|
12
|
+
/** Properties for `IModelHost` */
|
|
13
|
+
backendHostProps?: IModelHostOptions;
|
|
14
|
+
/** Properties for frontend initialization */
|
|
15
|
+
frontendProps?: PresentationFrontendProps;
|
|
16
|
+
/** IModelApp implementation */
|
|
17
|
+
frontendApp?: {
|
|
18
|
+
startup: (opts?: IModelAppOptions) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
/** `IModelApp` options */
|
|
21
|
+
frontendAppOptions?: IModelAppOptions;
|
|
22
|
+
/** Custom test output directory. Defaults to temporary directory provided by the OS. */
|
|
23
|
+
testOutputDir?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the framework for presentation testing. The function sets up backend,
|
|
27
|
+
* frontend and RPC communication between them.
|
|
28
|
+
*
|
|
29
|
+
* @see `terminate`
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare const initialize: (props?: PresentationTestingInitProps | undefined) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Undoes the setup made by `initialize`.
|
|
36
|
+
* @param frontendApp IModelApp implementation
|
|
37
|
+
*
|
|
38
|
+
* @see `initialize`
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare const terminate: (frontendApp?: typeof IModelApp) => Promise<void>;
|
|
43
43
|
//# sourceMappingURL=Helpers.d.ts.map
|
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.terminate = exports.initialize = exports.PresentationManagerMode = exports.HierarchyCacheMode = exports.getTestOutputDir = void 0;
|
|
23
|
-
/*---------------------------------------------------------------------------------------------
|
|
24
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
|
-
*--------------------------------------------------------------------------------------------*/
|
|
27
|
-
/** @packageDocumentation
|
|
28
|
-
* @module Helpers
|
|
29
|
-
*/
|
|
30
|
-
/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.
|
|
31
|
-
const path_1 = require("path");
|
|
32
|
-
const rimraf = __importStar(require("rimraf"));
|
|
33
|
-
const core_backend_1 = require("@itwin/core-backend");
|
|
34
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
35
|
-
const core_common_1 = require("@itwin/core-common");
|
|
36
|
-
const core_frontend_1 = require("@itwin/core-frontend");
|
|
37
|
-
const presentation_backend_1 = require("@itwin/presentation-backend");
|
|
38
|
-
Object.defineProperty(exports, "HierarchyCacheMode", { enumerable: true, get: function () { return presentation_backend_1.HierarchyCacheMode; } });
|
|
39
|
-
Object.defineProperty(exports, "PresentationManagerMode", { enumerable: true, get: function () { return presentation_backend_1.PresentationManagerMode; } });
|
|
40
|
-
const presentation_common_1 = require("@itwin/presentation-common");
|
|
41
|
-
const presentation_frontend_1 = require("@itwin/presentation-frontend");
|
|
42
|
-
const os_1 = require("os");
|
|
43
|
-
function initializeRpcInterfaces(interfaces) {
|
|
44
|
-
const config = class extends core_common_1.RpcDefaultConfiguration {
|
|
45
|
-
constructor() {
|
|
46
|
-
super(...arguments);
|
|
47
|
-
this.interfaces = () => interfaces;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
for (const definition of interfaces)
|
|
51
|
-
core_common_1.RpcConfiguration.assign(definition, () => config);
|
|
52
|
-
const instance = core_common_1.RpcConfiguration.obtain(config);
|
|
53
|
-
try {
|
|
54
|
-
core_common_1.RpcConfiguration.initializeInterfaces(instance);
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
// this may fail with "Error: RPC interface "xxx" is already initialized." because
|
|
58
|
-
// multiple different tests want to set up rpc interfaces
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
let isInitialized = false;
|
|
62
|
-
const defaultTestOutputDir = (0, os_1.tmpdir)();
|
|
63
|
-
let testOutputDir;
|
|
64
|
-
/** @internal */
|
|
65
|
-
const getTestOutputDir = () => {
|
|
66
|
-
return testOutputDir !== null && testOutputDir !== void 0 ? testOutputDir : defaultTestOutputDir;
|
|
67
|
-
};
|
|
68
|
-
exports.getTestOutputDir = getTestOutputDir;
|
|
69
|
-
/**
|
|
70
|
-
* Initialize the framework for presentation testing. The function sets up backend,
|
|
71
|
-
* frontend and RPC communication between them.
|
|
72
|
-
*
|
|
73
|
-
* @see `terminate`
|
|
74
|
-
*
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
const initialize = async (props) => {
|
|
78
|
-
var _a;
|
|
79
|
-
if (isInitialized)
|
|
80
|
-
return;
|
|
81
|
-
if (!props)
|
|
82
|
-
props = {};
|
|
83
|
-
// set up rpc interfaces
|
|
84
|
-
initializeRpcInterfaces([core_common_1.SnapshotIModelRpcInterface, core_common_1.IModelReadRpcInterface, presentation_common_1.PresentationRpcInterface]);
|
|
85
|
-
// init backend
|
|
86
|
-
// make sure backend gets assigned an id which puts its resources into a unique directory
|
|
87
|
-
props.backendProps = (_a = props.backendProps) !== null && _a !== void 0 ? _a : {};
|
|
88
|
-
if (!props.backendProps.id)
|
|
89
|
-
props.backendProps.id = `test-${core_bentley_1.Guid.createValue()}`;
|
|
90
|
-
await core_backend_1.IModelHost.startup({ cacheDir: (0, path_1.join)(__dirname, ".cache"), ...props.backendHostProps });
|
|
91
|
-
presentation_backend_1.Presentation.initialize(props.backendProps);
|
|
92
|
-
// init frontend
|
|
93
|
-
if (!props.frontendApp)
|
|
94
|
-
props.frontendApp = core_frontend_1.NoRenderApp;
|
|
95
|
-
props.frontendAppOptions = {
|
|
96
|
-
localization: new core_common_1.EmptyLocalization(),
|
|
97
|
-
...props.frontendAppOptions,
|
|
98
|
-
};
|
|
99
|
-
await props.frontendApp.startup(props.frontendAppOptions);
|
|
100
|
-
const defaultFrontendProps = {
|
|
101
|
-
presentation: {
|
|
102
|
-
activeLocale: core_frontend_1.IModelApp.localization.getLanguageList()[0],
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
await presentation_frontend_1.Presentation.initialize({ ...defaultFrontendProps, ...props.frontendProps });
|
|
106
|
-
testOutputDir = props.testOutputDir;
|
|
107
|
-
isInitialized = true;
|
|
108
|
-
};
|
|
109
|
-
exports.initialize = initialize;
|
|
110
|
-
/**
|
|
111
|
-
* Undoes the setup made by `initialize`.
|
|
112
|
-
* @param frontendApp IModelApp implementation
|
|
113
|
-
*
|
|
114
|
-
* @see `initialize`
|
|
115
|
-
*
|
|
116
|
-
* @public
|
|
117
|
-
*/
|
|
118
|
-
const terminate = async (frontendApp = core_frontend_1.IModelApp) => {
|
|
119
|
-
var _a, _b, _c;
|
|
120
|
-
if (!isInitialized)
|
|
121
|
-
return;
|
|
122
|
-
// store directory that needs to be cleaned-up
|
|
123
|
-
let hierarchiesCacheDirectory;
|
|
124
|
-
const hierarchiesCacheConfig = (_b = (_a = presentation_backend_1.Presentation.initProps) === null || _a === void 0 ? void 0 : _a.caching) === null || _b === void 0 ? void 0 : _b.hierarchies;
|
|
125
|
-
if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === presentation_backend_1.HierarchyCacheMode.Disk)
|
|
126
|
-
hierarchiesCacheDirectory = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.directory;
|
|
127
|
-
else if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === presentation_backend_1.HierarchyCacheMode.Hybrid)
|
|
128
|
-
hierarchiesCacheDirectory = (_c = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.disk) === null || _c === void 0 ? void 0 : _c.directory;
|
|
129
|
-
// terminate backend
|
|
130
|
-
presentation_backend_1.Presentation.terminate();
|
|
131
|
-
await core_backend_1.IModelHost.shutdown();
|
|
132
|
-
if (hierarchiesCacheDirectory)
|
|
133
|
-
rimraf.sync(hierarchiesCacheDirectory);
|
|
134
|
-
// terminate frontend
|
|
135
|
-
presentation_frontend_1.Presentation.terminate();
|
|
136
|
-
await frontendApp.shutdown();
|
|
137
|
-
isInitialized = false;
|
|
138
|
-
};
|
|
139
|
-
exports.terminate = terminate;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.terminate = exports.initialize = exports.PresentationManagerMode = exports.HierarchyCacheMode = exports.getTestOutputDir = void 0;
|
|
23
|
+
/*---------------------------------------------------------------------------------------------
|
|
24
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
25
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
26
|
+
*--------------------------------------------------------------------------------------------*/
|
|
27
|
+
/** @packageDocumentation
|
|
28
|
+
* @module Helpers
|
|
29
|
+
*/
|
|
30
|
+
/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.
|
|
31
|
+
const path_1 = require("path");
|
|
32
|
+
const rimraf = __importStar(require("rimraf"));
|
|
33
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
34
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
35
|
+
const core_common_1 = require("@itwin/core-common");
|
|
36
|
+
const core_frontend_1 = require("@itwin/core-frontend");
|
|
37
|
+
const presentation_backend_1 = require("@itwin/presentation-backend");
|
|
38
|
+
Object.defineProperty(exports, "HierarchyCacheMode", { enumerable: true, get: function () { return presentation_backend_1.HierarchyCacheMode; } });
|
|
39
|
+
Object.defineProperty(exports, "PresentationManagerMode", { enumerable: true, get: function () { return presentation_backend_1.PresentationManagerMode; } });
|
|
40
|
+
const presentation_common_1 = require("@itwin/presentation-common");
|
|
41
|
+
const presentation_frontend_1 = require("@itwin/presentation-frontend");
|
|
42
|
+
const os_1 = require("os");
|
|
43
|
+
function initializeRpcInterfaces(interfaces) {
|
|
44
|
+
const config = class extends core_common_1.RpcDefaultConfiguration {
|
|
45
|
+
constructor() {
|
|
46
|
+
super(...arguments);
|
|
47
|
+
this.interfaces = () => interfaces;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
for (const definition of interfaces)
|
|
51
|
+
core_common_1.RpcConfiguration.assign(definition, () => config);
|
|
52
|
+
const instance = core_common_1.RpcConfiguration.obtain(config);
|
|
53
|
+
try {
|
|
54
|
+
core_common_1.RpcConfiguration.initializeInterfaces(instance);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// this may fail with "Error: RPC interface "xxx" is already initialized." because
|
|
58
|
+
// multiple different tests want to set up rpc interfaces
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let isInitialized = false;
|
|
62
|
+
const defaultTestOutputDir = (0, os_1.tmpdir)();
|
|
63
|
+
let testOutputDir;
|
|
64
|
+
/** @internal */
|
|
65
|
+
const getTestOutputDir = () => {
|
|
66
|
+
return testOutputDir !== null && testOutputDir !== void 0 ? testOutputDir : defaultTestOutputDir;
|
|
67
|
+
};
|
|
68
|
+
exports.getTestOutputDir = getTestOutputDir;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize the framework for presentation testing. The function sets up backend,
|
|
71
|
+
* frontend and RPC communication between them.
|
|
72
|
+
*
|
|
73
|
+
* @see `terminate`
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
const initialize = async (props) => {
|
|
78
|
+
var _a;
|
|
79
|
+
if (isInitialized)
|
|
80
|
+
return;
|
|
81
|
+
if (!props)
|
|
82
|
+
props = {};
|
|
83
|
+
// set up rpc interfaces
|
|
84
|
+
initializeRpcInterfaces([core_common_1.SnapshotIModelRpcInterface, core_common_1.IModelReadRpcInterface, presentation_common_1.PresentationRpcInterface]);
|
|
85
|
+
// init backend
|
|
86
|
+
// make sure backend gets assigned an id which puts its resources into a unique directory
|
|
87
|
+
props.backendProps = (_a = props.backendProps) !== null && _a !== void 0 ? _a : {};
|
|
88
|
+
if (!props.backendProps.id)
|
|
89
|
+
props.backendProps.id = `test-${core_bentley_1.Guid.createValue()}`;
|
|
90
|
+
await core_backend_1.IModelHost.startup({ cacheDir: (0, path_1.join)(__dirname, ".cache"), ...props.backendHostProps });
|
|
91
|
+
presentation_backend_1.Presentation.initialize(props.backendProps);
|
|
92
|
+
// init frontend
|
|
93
|
+
if (!props.frontendApp)
|
|
94
|
+
props.frontendApp = core_frontend_1.NoRenderApp;
|
|
95
|
+
props.frontendAppOptions = {
|
|
96
|
+
localization: new core_common_1.EmptyLocalization(),
|
|
97
|
+
...props.frontendAppOptions,
|
|
98
|
+
};
|
|
99
|
+
await props.frontendApp.startup(props.frontendAppOptions);
|
|
100
|
+
const defaultFrontendProps = {
|
|
101
|
+
presentation: {
|
|
102
|
+
activeLocale: core_frontend_1.IModelApp.localization.getLanguageList()[0],
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
await presentation_frontend_1.Presentation.initialize({ ...defaultFrontendProps, ...props.frontendProps });
|
|
106
|
+
testOutputDir = props.testOutputDir;
|
|
107
|
+
isInitialized = true;
|
|
108
|
+
};
|
|
109
|
+
exports.initialize = initialize;
|
|
110
|
+
/**
|
|
111
|
+
* Undoes the setup made by `initialize`.
|
|
112
|
+
* @param frontendApp IModelApp implementation
|
|
113
|
+
*
|
|
114
|
+
* @see `initialize`
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
const terminate = async (frontendApp = core_frontend_1.IModelApp) => {
|
|
119
|
+
var _a, _b, _c;
|
|
120
|
+
if (!isInitialized)
|
|
121
|
+
return;
|
|
122
|
+
// store directory that needs to be cleaned-up
|
|
123
|
+
let hierarchiesCacheDirectory;
|
|
124
|
+
const hierarchiesCacheConfig = (_b = (_a = presentation_backend_1.Presentation.initProps) === null || _a === void 0 ? void 0 : _a.caching) === null || _b === void 0 ? void 0 : _b.hierarchies;
|
|
125
|
+
if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === presentation_backend_1.HierarchyCacheMode.Disk)
|
|
126
|
+
hierarchiesCacheDirectory = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.directory;
|
|
127
|
+
else if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === presentation_backend_1.HierarchyCacheMode.Hybrid)
|
|
128
|
+
hierarchiesCacheDirectory = (_c = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.disk) === null || _c === void 0 ? void 0 : _c.directory;
|
|
129
|
+
// terminate backend
|
|
130
|
+
presentation_backend_1.Presentation.terminate();
|
|
131
|
+
await core_backend_1.IModelHost.shutdown();
|
|
132
|
+
if (hierarchiesCacheDirectory)
|
|
133
|
+
rimraf.sync(hierarchiesCacheDirectory);
|
|
134
|
+
// terminate frontend
|
|
135
|
+
presentation_frontend_1.Presentation.terminate();
|
|
136
|
+
await frontendApp.shutdown();
|
|
137
|
+
isInitialized = false;
|
|
138
|
+
};
|
|
139
|
+
exports.terminate = terminate;
|
|
140
140
|
//# 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;AACH,0BAA0B,CAAE,uGAAuG;AACnI,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAG4B;AAC5B,wDAAgF;AAChF,sEAEqC;AAkC5B,mGAnCP,yCAAkB,OAmCO;AAAE,wGAnCoF,8CAAuB,OAmCpF;AAjCpD,oEAAsE;AACtE,wEAAoI;AACpI,2BAA4B;AAE5B,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAArC;;YACG,eAAU,GAAQ,GAAG,EAAE,CAAC,UAAU,CAAC;QACrD,CAAC;KAAA,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU;QACjC,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI;QACF,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;KACjD;IAAC,MAAM;QACN,kFAAkF;QAClF,yDAAyD;KAC1D;AACH,CAAC;AAED,IAAI,aAAa,GAAG,KAAK,CAAC;AAE1B,MAAM,oBAAoB,GAAG,IAAA,WAAM,GAAE,CAAC;AACtC,IAAI,aAAiC,CAAC;AAEtC,gBAAgB;AACT,MAAM,gB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uBpB","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/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\nimport { join } from \"path\";\nimport * as rimraf from \"rimraf\";\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\nimport { Guid } from \"@itwin/core-bentley\";\nimport {\n EmptyLocalization,\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\";\nimport { tmpdir } from \"os\";\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 props.frontendAppOptions = {\n localization: new EmptyLocalization(), // Use EmptyLocalization if none is provided\n ...props.frontendAppOptions,\n };\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
|
+
{"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,0BAA0B,CAAE,uGAAuG;AACnI,+BAA4B;AAC5B,+CAAiC;AACjC,sDAAoE;AACpE,sDAA2C;AAC3C,oDAG4B;AAC5B,wDAAgF;AAChF,sEAEqC;AAkC5B,mGAnCP,yCAAkB,OAmCO;AAAE,wGAnCoF,8CAAuB,OAmCpF;AAjCpD,oEAAsE;AACtE,wEAAoI;AACpI,2BAA4B;AAE5B,SAAS,uBAAuB,CAAC,UAAoC;IACnE,MAAM,MAAM,GAAG,KAAM,SAAQ,qCAAuB;QAArC;;YACG,eAAU,GAAQ,GAAG,EAAE,CAAC,UAAU,CAAC;QACrD,CAAC;KAAA,CAAC;IAEF,KAAK,MAAM,UAAU,IAAI,UAAU;QACjC,8BAAgB,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;IAEpD,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI;QACF,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;KACjD;IAAC,MAAM;QACN,kFAAkF;QAClF,yDAAyD;KAC1D;AAC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B,oCAAoB,CAAC,SAAS,EAAE,CAAC;IACjC,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;IAE7B,aAAa,GAAG,KAAK,CAAC;AACxB,CAAC,CAAC;AAvBW,QAAA,SAAS,aAuBpB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Helpers\r\n */\r\n/* istanbul ignore file */ // TODO: Remove istanbul ignore file when https://github.com/iTwin/itwinjs-backlog/issues/463 is fixed.\r\nimport { join } from \"path\";\r\nimport * as rimraf from \"rimraf\";\r\nimport { IModelHost, IModelHostOptions } from \"@itwin/core-backend\";\r\nimport { Guid } from \"@itwin/core-bentley\";\r\nimport {\r\n EmptyLocalization,\r\n IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface,\r\n} from \"@itwin/core-common\";\r\nimport { IModelApp, IModelAppOptions, NoRenderApp } from \"@itwin/core-frontend\";\r\nimport {\r\n HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerProps as PresentationBackendProps, PresentationManagerMode,\r\n} from \"@itwin/presentation-backend\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { Presentation as PresentationFrontend, PresentationProps as PresentationFrontendProps } from \"@itwin/presentation-frontend\";\r\nimport { tmpdir } from \"os\";\r\n\r\nfunction initializeRpcInterfaces(interfaces: RpcInterfaceDefinition[]) {\r\n const config = class extends RpcDefaultConfiguration {\r\n public override interfaces: any = () => interfaces;\r\n };\r\n\r\n for (const definition of interfaces)\r\n RpcConfiguration.assign(definition, () => config);\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n\r\n try {\r\n RpcConfiguration.initializeInterfaces(instance);\r\n } catch {\r\n // this may fail with \"Error: RPC interface \"xxx\" is already initialized.\" because\r\n // multiple different tests want to set up rpc interfaces\r\n }\r\n}\r\n\r\nlet isInitialized = false;\r\n\r\nconst defaultTestOutputDir = tmpdir();\r\nlet testOutputDir: string | undefined;\r\n\r\n/** @internal */\r\nexport const getTestOutputDir = (): string => {\r\n return testOutputDir ?? defaultTestOutputDir;\r\n};\r\n\r\n// eslint-disable-next-line deprecation/deprecation\r\nexport { HierarchyCacheMode, PresentationManagerMode, PresentationBackendProps };\r\n\r\n/** @public */\r\nexport interface PresentationTestingInitProps {\r\n /** Properties for backend initialization */\r\n backendProps?: PresentationBackendProps;\r\n /** Properties for `IModelHost` */\r\n backendHostProps?: IModelHostOptions;\r\n /** Properties for frontend initialization */\r\n frontendProps?: PresentationFrontendProps;\r\n /** IModelApp implementation */\r\n frontendApp?: { startup: (opts?: IModelAppOptions) => Promise<void> };\r\n /** `IModelApp` options */\r\n frontendAppOptions?: IModelAppOptions;\r\n /** Custom test output directory. Defaults to temporary directory provided by the OS. */\r\n testOutputDir?: string;\r\n}\r\n\r\n/**\r\n * Initialize the framework for presentation testing. The function sets up backend,\r\n * frontend and RPC communication between them.\r\n *\r\n * @see `terminate`\r\n *\r\n * @public\r\n */\r\nexport const initialize = async (props?: PresentationTestingInitProps) => {\r\n if (isInitialized)\r\n return;\r\n\r\n if (!props)\r\n props = {};\r\n\r\n // set up rpc interfaces\r\n initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);\r\n\r\n // init backend\r\n // make sure backend gets assigned an id which puts its resources into a unique directory\r\n props.backendProps = props.backendProps ?? {};\r\n if (!props.backendProps.id)\r\n props.backendProps.id = `test-${Guid.createValue()}`;\r\n await IModelHost.startup({ cacheDir: join(__dirname, \".cache\"), ...props.backendHostProps });\r\n PresentationBackend.initialize(props.backendProps);\r\n\r\n // init frontend\r\n if (!props.frontendApp)\r\n props.frontendApp = NoRenderApp;\r\n props.frontendAppOptions = {\r\n localization: new EmptyLocalization(), // Use EmptyLocalization if none is provided\r\n ...props.frontendAppOptions,\r\n };\r\n await props.frontendApp.startup(props.frontendAppOptions);\r\n const defaultFrontendProps: PresentationFrontendProps = {\r\n presentation: {\r\n activeLocale: IModelApp.localization.getLanguageList()[0],\r\n },\r\n };\r\n await PresentationFrontend.initialize({ ...defaultFrontendProps, ...props.frontendProps });\r\n testOutputDir = props.testOutputDir;\r\n\r\n isInitialized = true;\r\n};\r\n\r\n/**\r\n * Undoes the setup made by `initialize`.\r\n * @param frontendApp IModelApp implementation\r\n *\r\n * @see `initialize`\r\n *\r\n * @public\r\n */\r\nexport const terminate = async (frontendApp = IModelApp) => {\r\n if (!isInitialized)\r\n return;\r\n\r\n // store directory that needs to be cleaned-up\r\n let hierarchiesCacheDirectory: string | undefined;\r\n const hierarchiesCacheConfig = PresentationBackend.initProps?.caching?.hierarchies;\r\n if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Disk)\r\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.directory;\r\n else if (hierarchiesCacheConfig?.mode === HierarchyCacheMode.Hybrid)\r\n hierarchiesCacheDirectory = hierarchiesCacheConfig?.disk?.directory;\r\n\r\n // terminate backend\r\n PresentationBackend.terminate();\r\n await IModelHost.shutdown();\r\n if (hierarchiesCacheDirectory)\r\n rimraf.sync(hierarchiesCacheDirectory);\r\n\r\n // terminate frontend\r\n PresentationFrontend.terminate();\r\n await frontendApp.shutdown();\r\n\r\n isInitialized = false;\r\n};\r\n"]}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { IModelConnection } from "@itwin/core-frontend";
|
|
2
|
-
import { Omit, Ruleset } from "@itwin/presentation-common";
|
|
3
|
-
import { TreeNodeItem } from "@itwin/components-react";
|
|
4
|
-
/**
|
|
5
|
-
* Structure that describes a Node with any indexed properties
|
|
6
|
-
* except `children`.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export interface MappedNode {
|
|
11
|
-
/** Indexer for all properties in this data structure */
|
|
12
|
-
[index: string]: any;
|
|
13
|
-
/** Prohibited property */
|
|
14
|
-
children?: never;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Node in a hierarchy.
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export interface HierarchyNode extends Omit<MappedNode, "children"> {
|
|
21
|
-
/** Children of this node */
|
|
22
|
-
children?: HierarchyNode[];
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A function that converts `TreeNodeItem` into a new custom object.
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export declare type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;
|
|
29
|
-
/**
|
|
30
|
-
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export declare const defaultNodeMappingFunc: NodeMappingFunc;
|
|
34
|
-
/**
|
|
35
|
-
* Properties for creating a `HierarchyBuilder` instance.
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export interface HierarchyBuilderProps {
|
|
39
|
-
/** The iModel to pull data from */
|
|
40
|
-
imodel: IModelConnection;
|
|
41
|
-
/**
|
|
42
|
-
* A function that maps node to something that the user of
|
|
43
|
-
* this API is interested in. E.g. custom implementation may skip some unimportant
|
|
44
|
-
* node properties to make resulting object smaller and easier to read.
|
|
45
|
-
*/
|
|
46
|
-
nodeMappingFunc?: NodeMappingFunc;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* A class that constructs simple node hierarchy from specified
|
|
50
|
-
* imodel and ruleset.
|
|
51
|
-
*
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export declare class HierarchyBuilder {
|
|
55
|
-
private readonly _iModel;
|
|
56
|
-
private readonly _nodeMappingFunc;
|
|
57
|
-
/** Constructor */
|
|
58
|
-
constructor(props: HierarchyBuilderProps);
|
|
59
|
-
private createSubHierarchy;
|
|
60
|
-
private doCreateHierarchy;
|
|
61
|
-
/**
|
|
62
|
-
* Create a hierarchy using the supplied presentation ruleset.
|
|
63
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
64
|
-
*/
|
|
65
|
-
createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]>;
|
|
66
|
-
}
|
|
1
|
+
import { IModelConnection } from "@itwin/core-frontend";
|
|
2
|
+
import { Omit, Ruleset } from "@itwin/presentation-common";
|
|
3
|
+
import { TreeNodeItem } from "@itwin/components-react";
|
|
4
|
+
/**
|
|
5
|
+
* Structure that describes a Node with any indexed properties
|
|
6
|
+
* except `children`.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface MappedNode {
|
|
11
|
+
/** Indexer for all properties in this data structure */
|
|
12
|
+
[index: string]: any;
|
|
13
|
+
/** Prohibited property */
|
|
14
|
+
children?: never;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Node in a hierarchy.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface HierarchyNode extends Omit<MappedNode, "children"> {
|
|
21
|
+
/** Children of this node */
|
|
22
|
+
children?: HierarchyNode[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A function that converts `TreeNodeItem` into a new custom object.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export declare type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;
|
|
29
|
+
/**
|
|
30
|
+
* Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare const defaultNodeMappingFunc: NodeMappingFunc;
|
|
34
|
+
/**
|
|
35
|
+
* Properties for creating a `HierarchyBuilder` instance.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export interface HierarchyBuilderProps {
|
|
39
|
+
/** The iModel to pull data from */
|
|
40
|
+
imodel: IModelConnection;
|
|
41
|
+
/**
|
|
42
|
+
* A function that maps node to something that the user of
|
|
43
|
+
* this API is interested in. E.g. custom implementation may skip some unimportant
|
|
44
|
+
* node properties to make resulting object smaller and easier to read.
|
|
45
|
+
*/
|
|
46
|
+
nodeMappingFunc?: NodeMappingFunc;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A class that constructs simple node hierarchy from specified
|
|
50
|
+
* imodel and ruleset.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare class HierarchyBuilder {
|
|
55
|
+
private readonly _iModel;
|
|
56
|
+
private readonly _nodeMappingFunc;
|
|
57
|
+
/** Constructor */
|
|
58
|
+
constructor(props: HierarchyBuilderProps);
|
|
59
|
+
private createSubHierarchy;
|
|
60
|
+
private doCreateHierarchy;
|
|
61
|
+
/**
|
|
62
|
+
* Create a hierarchy using the supplied presentation ruleset.
|
|
63
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
64
|
+
*/
|
|
65
|
+
createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]>;
|
|
66
|
+
}
|
|
67
67
|
//# sourceMappingURL=HierarchyBuilder.d.ts.map
|