@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +927 -959
  2. package/LICENSE.md +9 -9
  3. package/README.md +7 -7
  4. package/lib/cjs/presentation-testing/ContentBuilder.d.ts +92 -89
  5. package/lib/cjs/presentation-testing/ContentBuilder.d.ts.map +1 -1
  6. package/lib/cjs/presentation-testing/ContentBuilder.js +178 -149
  7. package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
  8. package/lib/cjs/presentation-testing/Helpers.d.ts +45 -42
  9. package/lib/cjs/presentation-testing/Helpers.d.ts.map +1 -1
  10. package/lib/cjs/presentation-testing/Helpers.js +138 -139
  11. package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
  12. package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +69 -66
  13. package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts.map +1 -1
  14. package/lib/cjs/presentation-testing/HierarchyBuilder.js +78 -67
  15. package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -1
  16. package/lib/cjs/presentation-testing/IModelUtilities.d.ts +46 -46
  17. package/lib/cjs/presentation-testing/IModelUtilities.d.ts.map +1 -1
  18. package/lib/cjs/presentation-testing/IModelUtilities.js +83 -77
  19. package/lib/cjs/presentation-testing/IModelUtilities.js.map +1 -1
  20. package/lib/cjs/presentation-testing.d.ts +28 -28
  21. package/lib/cjs/presentation-testing.d.ts.map +1 -1
  22. package/lib/cjs/presentation-testing.js +44 -44
  23. package/lib/cjs/presentation-testing.js.map +1 -1
  24. package/lib/esm/presentation-testing/ContentBuilder.d.ts +92 -89
  25. package/lib/esm/presentation-testing/ContentBuilder.d.ts.map +1 -1
  26. package/lib/esm/presentation-testing/ContentBuilder.js +174 -145
  27. package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
  28. package/lib/esm/presentation-testing/Helpers.d.ts +45 -42
  29. package/lib/esm/presentation-testing/Helpers.d.ts.map +1 -1
  30. package/lib/esm/presentation-testing/Helpers.js +113 -114
  31. package/lib/esm/presentation-testing/Helpers.js.map +1 -1
  32. package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +69 -66
  33. package/lib/esm/presentation-testing/HierarchyBuilder.d.ts.map +1 -1
  34. package/lib/esm/presentation-testing/HierarchyBuilder.js +73 -62
  35. package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -1
  36. package/lib/esm/presentation-testing/IModelUtilities.d.ts +46 -46
  37. package/lib/esm/presentation-testing/IModelUtilities.d.ts.map +1 -1
  38. package/lib/esm/presentation-testing/IModelUtilities.js +75 -69
  39. package/lib/esm/presentation-testing/IModelUtilities.js.map +1 -1
  40. package/lib/esm/presentation-testing.d.ts +28 -28
  41. package/lib/esm/presentation-testing.d.ts.map +1 -1
  42. package/lib/esm/presentation-testing.js +32 -32
  43. package/lib/esm/presentation-testing.js.map +1 -1
  44. 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 { join } from "path";
10
- import * as rimraf from "rimraf";
11
- import { IModelHost } from "@itwin/core-backend";
12
- import { Guid } from "@itwin/core-bentley";
13
- import { EmptyLocalization, IModelReadRpcInterface, RpcConfiguration, RpcDefaultConfiguration, SnapshotIModelRpcInterface, } from "@itwin/core-common";
14
- import { IModelApp, NoRenderApp } from "@itwin/core-frontend";
15
- import { HierarchyCacheMode, Presentation as PresentationBackend, PresentationManagerMode, } from "@itwin/presentation-backend";
16
- import { PresentationRpcInterface } from "@itwin/presentation-common";
17
- import { Presentation as PresentationFrontend } from "@itwin/presentation-frontend";
18
- import { tmpdir } from "os";
19
- function initializeRpcInterfaces(interfaces) {
20
- const config = class extends RpcDefaultConfiguration {
21
- constructor() {
22
- super(...arguments);
23
- this.interfaces = () => interfaces;
24
- }
25
- };
26
- for (const definition of interfaces)
27
- RpcConfiguration.assign(definition, () => config);
28
- const instance = RpcConfiguration.obtain(config);
29
- try {
30
- RpcConfiguration.initializeInterfaces(instance);
31
- }
32
- catch {
33
- // this may fail with "Error: RPC interface "xxx" is already initialized." because
34
- // multiple different tests want to set up rpc interfaces
35
- }
36
- }
37
- let isInitialized = false;
38
- const defaultTestOutputDir = tmpdir();
39
- let testOutputDir;
40
- /** @internal */
41
- export const getTestOutputDir = () => {
42
- return testOutputDir !== null && testOutputDir !== void 0 ? testOutputDir : defaultTestOutputDir;
43
- };
44
- // eslint-disable-next-line deprecation/deprecation
45
- export { HierarchyCacheMode, PresentationManagerMode };
46
- /**
47
- * Initialize the framework for presentation testing. The function sets up backend,
48
- * frontend and RPC communication between them.
49
- *
50
- * @see `terminate`
51
- *
52
- * @public
53
- */
54
- export const initialize = async (props) => {
55
- var _a;
56
- if (isInitialized)
57
- return;
58
- if (!props)
59
- props = {};
60
- // set up rpc interfaces
61
- initializeRpcInterfaces([SnapshotIModelRpcInterface, IModelReadRpcInterface, PresentationRpcInterface]);
62
- // init backend
63
- // make sure backend gets assigned an id which puts its resources into a unique directory
64
- props.backendProps = (_a = props.backendProps) !== null && _a !== void 0 ? _a : {};
65
- if (!props.backendProps.id)
66
- props.backendProps.id = `test-${Guid.createValue()}`;
67
- await IModelHost.startup({ cacheDir: join(__dirname, ".cache"), ...props.backendHostProps });
68
- PresentationBackend.initialize(props.backendProps);
69
- // init frontend
70
- if (!props.frontendApp)
71
- props.frontendApp = NoRenderApp;
72
- props.frontendAppOptions = {
73
- localization: new EmptyLocalization(),
74
- ...props.frontendAppOptions,
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
- var _a, _b, _c;
96
- if (!isInitialized)
97
- return;
98
- // store directory that needs to be cleaned-up
99
- let hierarchiesCacheDirectory;
100
- const hierarchiesCacheConfig = (_b = (_a = PresentationBackend.initProps) === null || _a === void 0 ? void 0 : _a.caching) === null || _b === void 0 ? void 0 : _b.hierarchies;
101
- if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Disk)
102
- hierarchiesCacheDirectory = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.directory;
103
- else if ((hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.mode) === HierarchyCacheMode.Hybrid)
104
- hierarchiesCacheDirectory = (_c = hierarchiesCacheConfig === null || hierarchiesCacheConfig === void 0 ? void 0 : hierarchiesCacheConfig.disk) === null || _c === void 0 ? void 0 : _c.directory;
105
- // terminate backend
106
- PresentationBackend.terminate();
107
- await IModelHost.shutdown();
108
- if (hierarchiesCacheDirectory)
109
- rimraf.sync(hierarchiesCacheDirectory);
110
- // terminate frontend
111
- PresentationFrontend.terminate();
112
- await frontendApp.shutdown();
113
- isInitialized = false;
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
  //# sourceM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AC3B,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":["/*---------------------------------------------------------------------------------------------\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
+ {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../../../src/presentation-testing/Helpers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,0BAA0B,CAAE,uGAAuG;AAEnI,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,UAAU,E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M,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
- 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
+ /** @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":"AAQA,OAAO,EAAE,g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AAgB,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
- var _a;
32
- this._iModel = props.imodel;
33
- this._nodeMappingFunc = (_a = props.nodeMappingFunc) !== null && _a !== void 0 ? _a : defaultNodeMappingFunc;
34
- }
35
- async createSubHierarchy(nodes, dataProvider) {
36
- const hierarchy = [];
37
- for (const node of nodes) {
38
- const { key: _key, ...nodeNoKey } = node;
39
- const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;
40
- const childNodes = await dataProvider.getNodes(node);
41
- if (childNodes.length > 0)
42
- hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);
43
- }
44
- return hierarchy;
45
- }
46
- async doCreateHierarchy(rulesetId) {
47
- const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });
48
- const rootNodes = await dataProvider.getNodes();
49
- return this.createSubHierarchy(rootNodes, dataProvider);
50
- }
51
- /**
52
- * Create a hierarchy using the supplied presentation ruleset.
53
- * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
54
- */
55
- async createHierarchy(rulesetOrId) {
56
- if (typeof rulesetOrId === "string")
57
- return this.doCreateHierarchy(rulesetOrId);
58
- return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
59
- return this.doCreateHierarchy(ruleset.id);
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;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EAAE,4BAA4B,EAA4B,MAAM,gCAAgC,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AA+B5D;;;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;;QACtC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,MAAA,KAAK,CAAC,eAAe,mCAAI,sBAAsB,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CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;CACF","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 Hierarchies\r\n */\r\nimport { using } from \"@itwin/core-bentley\";\r\nimport { IModelConnection } from \"@itwin/core-frontend\";\r\nimport { Omit, RegisteredRuleset, Ruleset } from \"@itwin/presentation-common\";\r\nimport { PresentationTreeDataProvider, PresentationTreeNodeItem } from \"@itwin/presentation-components\";\r\nimport { Presentation } from \"@itwin/presentation-frontend\";\r\nimport { TreeNodeItem } from \"@itwin/components-react\";\r\n\r\n/**\r\n * Structure that describes a Node with any indexed properties\r\n * except `children`.\r\n *\r\n * @public\r\n */\r\nexport interface MappedNode {\r\n /** Indexer for all properties in this data structure */\r\n [index: string]: any;\r\n /** Prohibited property */\r\n children?: never;\r\n}\r\n\r\n/**\r\n * Node in a hierarchy.\r\n * @public\r\n */\r\nexport interface HierarchyNode extends Omit<MappedNode, \"children\"> {\r\n /** Children of this node */\r\n children?: HierarchyNode[];\r\n}\r\n\r\n/**\r\n * A function that converts `TreeNodeItem` into a new custom object.\r\n * @public\r\n */\r\nexport type NodeMappingFunc = (node: TreeNodeItem) => MappedNode;\r\n\r\n/**\r\n * Default [[NodeMappingFunc]] implementation that outputs the whole `TreeNodeItem` object.\r\n * @public\r\n */\r\nexport const defaultNodeMappingFunc: NodeMappingFunc = (node: TreeNodeItem) => {\r\n // Skip properties 'id', 'parentId' as they contain internal stuff\r\n // that callers are most likely not interested in. Otherwise they can supply\r\n // a custom `NodeMappingFunc` that does return those properties as well.\r\n const { id, parentId, ...resultNode } = node; // eslint-disable-line @typescript-eslint/no-unused-vars\r\n return resultNode;\r\n};\r\n\r\n/**\r\n * Properties for creating a `HierarchyBuilder` instance.\r\n * @public\r\n */\r\nexport interface HierarchyBuilderProps {\r\n /** The iModel to pull data from */\r\n imodel: IModelConnection;\r\n /**\r\n * A function that maps node to something that the user of\r\n * this API is interested in. E.g. custom implementation may skip some unimportant\r\n * node properties to make resulting object smaller and easier to read.\r\n */\r\n nodeMappingFunc?: NodeMappingFunc;\r\n}\r\n\r\n/**\r\n * A class that constructs simple node hierarchy from specified\r\n * imodel and ruleset.\r\n *\r\n * @public\r\n */\r\nexport class HierarchyBuilder {\r\n private readonly _iModel: IModelConnection;\r\n private readonly _nodeMappingFunc: NodeMappingFunc;\r\n\r\n /** Constructor */\r\n constructor(props: HierarchyBuilderProps) {\r\n this._iModel = props.imodel;\r\n this._nodeMappingFunc = props.nodeMappingFunc ?? defaultNodeMappingFunc;\r\n }\r\n\r\n private async createSubHierarchy(nodes: TreeNodeItem[], dataProvider: PresentationTreeDataProvider) {\r\n const hierarchy: HierarchyNode[] = [];\r\n for (const node of nodes) {\r\n const { key: _key, ...nodeNoKey } = (node as PresentationTreeNodeItem);\r\n const nodeIndex = hierarchy.push(this._nodeMappingFunc(nodeNoKey)) - 1;\r\n const childNodes = await dataProvider.getNodes(node);\r\n if (childNodes.length > 0)\r\n hierarchy[nodeIndex].children = await this.createSubHierarchy(childNodes, dataProvider);\r\n }\r\n return hierarchy;\r\n }\r\n\r\n private async doCreateHierarchy(rulesetId: string): Promise<HierarchyNode[]> {\r\n const dataProvider = new PresentationTreeDataProvider({ imodel: this._iModel, ruleset: rulesetId });\r\n const rootNodes = await dataProvider.getNodes();\r\n return this.createSubHierarchy(rootNodes, dataProvider);\r\n }\r\n\r\n /**\r\n * Create a hierarchy using the supplied presentation ruleset.\r\n * @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.\r\n */\r\n public async createHierarchy(rulesetOrId: Ruleset | string): Promise<HierarchyNode[]> {\r\n if (typeof rulesetOrId === \"string\")\r\n return this.doCreateHierarchy(rulesetOrId);\r\n\r\n return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset: RegisteredRuleset) => {\r\n return this.doCreateHierarchy(ruleset.id);\r\n });\r\n }\r\n}\r\n"]}
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,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,KAAqB,EAAE,YAA0C;QAChG,MAAM,SAAS,GAAoB,EAAE,CAAC;QACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,SAAS,EAAE,GAAI,IAAiC,CAAC;YACvE,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;gBACvB,SAAS,CAAC,SAAS,CAAC,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;SAC3F;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,SAAiB;QAC/C,MAAM,YAAY,GAAG,IAAI,4BAA4B,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,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,KAAK,CAAC,MAAM,YAAY,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","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"]}